## Description
Merges the two libraries. They were initially separate to separate the
core logic and fuel vm specific functionality, but that separation is no
longer maintained so having a merged library is better.
Closes#6708
## Checklist
- [ ] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: Sophie <47993817+sdankel@users.noreply.github.com>
Co-authored-by: Igor Rončević <ironcev@hotmail.com>
## Description
This PR sets the "new encoding" (from now on will be called "encoding
v1") as the default. We can still disable it using `no_encoding_v1`,
which switches back to "encoding v0".
Actions that needs to be done after this being merged will exist in
https://github.com/FuelLabs/sway/issues/5727
New features
- ABI Super traits;
- AbiEncode buffer dynamic sizing;
Bugs Fixed
- `ContractCall` intrinsic interaction effect was not set correctly;
Fixing warnings and error messages
- Better error message when core-lib is not available for
scripts/contracts/predicates;
- Better error message when main inputs/outputs are unknown or error
types;
- Better error message when main inputs/outputs do not implement
AbiEncode/AbiDecode;
- Don't warn impurity attributes on the "__entry" fn;
- Don't warn CEI on the "__entry" fn. Our CEI analysis, currently, does
not recognize `Never`. This means it does not realize it is impossible
to call two contract functions;
Test Disabled (needs to be enabled again in the future)
- should_pass/language/name_resolution_after_monomorphization
- should_pass/language/shadowing/shadowed_glob_imports
- should_pass/language/name_resolution_inside_intrinsics
- sdk-harness/external_proxy test is not working. I am assuming it is
the LDC bug that is already fixed on version 0.25. What is happening is
that the literal "double_value" has the correct length, but some random
data. Which makes the method selector fails. Only after we call LDC. The
proxy contract is working.
Test generating more warnings than before
- should_pass/dca/contract/superabi_contract_calls
What happens here is that when we implement a trait for `Contract`, we
actually generate two functions: one prefixed `__contract_entry` that is
called by the method selector; and another one normal, that can be
called freely. So, if the trait method is never called manually, it is
marked as dead.
- should_pass/dca/contract/abi_fn_params
I actually think the new warning is correct and nothing here needs to be
done.
Test with fewer warnings than before
- should_pass/dca/unused_fields
auto-impl is making all fields being used. so no dead code warnings are
being generated. We need to fix this.
Changes to std-lib
- Functions that return data about call context changed the semantic.
`first_param` and `second_param` return the value as the VM sees them.
We now have `called_method` and `called_args`. This means that we can
change the protocol later and still keep these four functions always
working and with meaningful names.
-
- predicate_data also was updated to use encoding v1 protocol.
ICE
- increase_buffer_if_needed implementation is a little bit strange
because does not work as a method inside `Buffer`. For some reason, it
is generating an ICE. I need to create an issue so we can fix, and
improve the implementation here.
- `Buffer` used by AbiEncode needs a `push_bytes` so we can be more
efficient when encoding Bytes and others.
## Checklist
- [ ] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
## Description
There are currently multiple functions for the same functionality:
Transfer:
- `transfer()`
- `force_transfer_to_contract()`
- `transfer_to_address()`
Mint:
- `mint()`
- `mint_to()`
- `mint_to_contract()`
- `mint_to_address()`
This be reduced to just `transfer()`, `mint()`, `mint_to()`. Specific
functions for separately minting and transferring to contracts and
addresses are legacy code left over from before the `Identity` type was
introduced and now only adds additional complexity.
## Changes:
- `force_transfer_to_contract()` is now private
- `transfer_to_address()` is now private
- `mint_to_contract()` removed
- `mint_to_address()` removed
- Removed newlines in inline docs for better `forc doc` compatibility
- Updated `burn()` inline docs
## Breaking Changes:
- `force_transfer_to_contract()` is now private
- `transfer_to_address()` is now private
- `mint_to_contract()` removed
- `mint_to_address()` removed
## Closes
- Closes#5773
## Checklist
- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: K1-R1 <77465250+K1-R1@users.noreply.github.com>
## Description
We currently support 2 methods of getting the contract id of a contract
in an internal context:
- `contract_id()`
- `ContractId::this()`
The `this()` associated function is a constructor that returns `Self`
and should be the primary method of getting the contract id. This
idiomatically follows Rust's syntax and `contract_id()` has been
removed.
The same syntax is followed with `AssetId::base()`.
Closes#5834
## Checklist
- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: SwayStar123 <46050679+SwayStar123@users.noreply.github.com>
## Description
Merges the staging branch into master from the following PRs:
https://github.com/FuelLabs/sway/pull/5640https://github.com/FuelLabs/sway/pull/5630https://github.com/FuelLabs/sway/pull/5621https://github.com/FuelLabs/sway/pull/5613
## Checklist
- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: IGI-111 <igi-111@protonmail.com>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
## Description
We currently use the following terminology in the standard library when
discussing native assets on Fuel:
- Asset
- Coin
- Token
This can be incredibly confusing for new developers. A naming convention
that is consistent across the standard library, docs, and examples is
critical for clarity.
In the following PR I formalize the use of the words "Asset" and "Coin".
- An "Asset" is a Native Asset on Fuel and has the associated `AssetId`
type. Assets are distinguishable from one another.
- A "Coin" represents a singular unit of an Asset. Coins of the same
Asset are not distinguishable from one another.
The changes made reflect the distinction that Fuel does not use tokens
like other ecosystems such as Ethereum and uses Native Assets with a
UTXO design instead.
The Asset and Coin terminology is also consistent the fuel-vm's input
and outputs types. This is already seen in the `input.sw` file with the
`Input::Coin` enum and `output.sw`'s `Output::Coin` enum in the standard
library respectively.
## Breaking Changes
Imports using the `token` import should now use the `asset` import.
Before:
```sway
use std::token::mint;
```
After:
```sway
use std::asset::mint;
```
## Checklist
- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
## Description
The following pull request does two things:
1. Introduces the `DEFAULT_SUB_ID` constant. This is equivalent to the
`ZERO_B256` constant. This constant makes the Sway code easier to read
and comprehend improving the developer's UX. The actual value of the
default is something the developer no longer needs to think about.
Before:
```sway
let my_asset = AssetId::new(my_contract, ZERO_B256);
```
Now:
```sway
let my_asset = AssetId::new(my_contract, DEFAULT_SUB_ID);
```
2. Removes the `ContractId` argument from the `AssetId::default()`
function. In 90% of cases `default()` is used within the contract that
issued the token, making this an unnecessary argument. This function now
fetches the contract id of the contract it's called in, thus eliminating
the need to import another function and add additional arguments. In the
case a developer needs the default of another contract, the
`DEFAULT_SUB_ID` can be used instead making the distinction more legible
and apparent.
Before:
```sway
use std::call_frames::contract_id;
fn foo(other_contract: ContractId) {
let other_asset = AssetId::default(other_contract);
let my_asset = AssetId::default(contract_id());
}
```
After:
```sway
fn foo(other_contract: ContractId) {
let other_asset = AssetId::new(other_contract, DEFAULT_SUB_ID);
let my_asset = AssetId::default();
}
```
## Checklist
- [ ] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: SwayStar123 <46050679+SwayStar123@users.noreply.github.com>
## Description
Change AssetId from alias to struct. Allows implementing of methods.
Also moved the helper functions into the struct as methods.
## Checklist
- [ ] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: Cameron Carstens <54727135+bitzoic@users.noreply.github.com>
Co-authored-by: Braqzen <103777923+Braqzen@users.noreply.github.com>
## Description
Implements Hash trait for builtin types and for some std lib types.
This is required to have a proper hashing that does not change in case
the internal memory representation of type changes.
Current hashing functions are hashing the types in memory directly, as
this representation might change in future versions of the VM and
compiler we want to have a more reliable way of getting hashes that
won't change in future versions of the compiler and std lib.
Replaces use of sha256 function with Hasher in storage_map and
storage_vec.
Adds intrinsic __check_str_type.
__check_str_type returns an error at compile time in case the provided
generic type is not a str.
This is used to guarantee that `Hasher` `write_str` is not called with
non str types.
Closes#3835.
## Checklist
- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
This pull request is an upgrade to a `fuel-core 0.20.1` release.
The biggest changes coming from this new release is a rework of how
AssetId is structured to support [granular asset
minting](https://github.com/FuelLabs/fuel-specs/pull/491). This means a
contract can mint and burn multiple AssetId's, and the ContractId !=
AssetId.
---------
Co-authored-by: bitzoic <bitzoic.eth@gmail.com>
Co-authored-by: Cameron Carstens <54727135+bitzoic@users.noreply.github.com>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
Co-authored-by: Brandon Kite <brandonkite92@gmail.com>
Co-authored-by: Sophie <sophiedankel@gmail.com>
## Description
This moves the examples workspace manifest introduced in #4118 into the
`examples/` directory and cleans it up a bit.
We also now integrate the examples workspace into CI, making the old
`examples-checker` script redundant. This old script is also removed as
a part of this PR.
## Checklist
- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
While a final design for the organization of `std` will likely involve
more discussion (& consideration of the proposed `Contract` type with
some of the existing free functions converted to methods on the
`Contract` type), the changes I've made here remove some weirdness.
This is a breaking change, so it might be a good time to clean at least
this up.
I've left the `vm` directory as currently, it seems like the only good
use of a subdirectory in `std`.
If anyone thinks this needs more discussion we can mark this a draft.
ref #1759
Closes#1078
* New trait `From<T>` in a new library called `convert.rs`
* Most changes are trivial
* Added `From` to the prelude
* Had to modify `from()` in `U128`, `U256`, and `B512` to take a tuple
of components instead of multiple arguments to conform to the trait.
This is a breaking change of course.
* Updating lock files for all the examples.
Fixes https://github.com/FuelLabs/sway/issues/1436.
This PR first removes the need for `~` in `~Foo::bar` by first delaying
the interpretation of `Foo::Bar` (associated call, free function call,
or enum variant construction?) until type checking. This is achieved
with `ExprKind::AmbiguousPathExpression`. During type checking, we ask
whether `Foo` (and any prefixes) is a module, or an enum. If it's
neither, we attempt type checking as an associated function call.
Otherwise, we continue as if we had a `ExpressionKind::DelineatedPath`.
Once `~` is made redundant, it's then also removed from the language and
so also from tests, examples, and the standard library.
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Closes#2912
Even though `transfer_to_output` is technically more correct, users
really understand this as transferring to an address. Besides, the name
`transfer_to_address` aligns better with the names of its parameters:
```rust
(amount: u64, asset_id: ContractId, to: Address)
```
And also with other functions in `token.rs` (such as `mint_to_address`).
I also did some minor refactoring of the function.
* Disambiguate `path` dependencies using the parent package ID
Implements and closes#1789.
TODO:
- [x] Disambiguate `path` dependencies using parent package ID.
- [ ] Impl `Display` and `FromStr` for `PinnedId` to convert it to and
from hex for path source string in lock file.
- [ ] Address #1637 now to reduce this PR adding even more noise in the
lock file `dependencies` lists.
- [ ] Refactor `fetch_deps` slightly to better accomodate new `Root`
source variant.
- [ ] Update lock files of all examples and tests in repository.
* Swap `ToString` impls for `Display`. Add `PinnedId` impls.
Also removes the `lock::source_from_str/source_to_string` impls in
favour of implementing `Display` and `FromStr` for `SourcePinned`.
* Only disambiguate pkg lock dependencies if the name requires it
Closes#1637.
* Update new add_deps function for changes applied to pin_pkg
* Fix path dependency disambiguation using a path root rather than parent
Improves path dependency disambiguation by using the ID of the package
that is the root of the subgraph of path dependencies.
* Update `examples` forc lock files for path disambiguation changes
* Update E2E test forc lock files for path disambiguation changes
* Update stdlib test lock files for path dependency disambiguation changes
* Update new lock files introduced since previous rebase
* Format long use stmnts + tests
Update formatting + comments
Cleanup implementation
Update 'use' formatting in examples
Update with prettier formatting
Update implementation
Fix merge conflicts
Fix off indent
Update test with ALREADY_FORMATTED_LINE_PATTERN
Fix line end in get_already_formatted_line_pattern
* Improve deeply nested formatting
Add space between commas
CI updates: formatting and fix examples
Fix clippy issues
Improve formatting
Remove unwrap_or() for unwrap() for possible panic
* Add some clarifying comments
Co-authored-by: Rashad Alston <rashad@Rashads-MacBook-Pro.local>
Co-authored-by: Rashad Alston <rashad@Rashads-MBP.attlocal.net>
* Make build-all-examples also check formatting.
* Install forc-fmt in CI.
* fmt examples
* Remove duplicate CI steps.
* Revert "Remove duplicate CI steps."
This reverts commit 8cbaaf1c43.
* Install forc-fmt prior to all build-all-examples.