Skip to content

Commit 348f717

Browse files
bitzoicPaulRBergSwayStar123IGI-111tritao
authored
Release v0.5.0 (#101)
* docs: fix typos in README (#86) * change vault_sub_id back to sub_id * docs: improve SRC-20 (#88) * docs: improve SRC-3 (#85) * Update to latest Sway Transform abusive usage of configurables into constants to support latest version of Sway that uses encoded configurables. * Update README.md * SRC-14 Simple Proxy Standard * Apply suggestions from code review Co-authored-by: Cameron Carstens <[email protected]> * Set standard target address storage location * Apply suggestions from code review Co-authored-by: SwayStar123 <[email protected]> * Update SRCs/src-14.md Co-authored-by: Cameron Carstens <[email protected]> * Correct typo * Apply suggestions from code review Co-authored-by: João Matos <[email protected]> * Add link to UUPS * Update to forc v0.60.0 (#96) * Update to forc v0.60.0 * Run formatter * address PR comments * Update CI * Delete docs.yml and gh-pages.yml * Update pull request template to include checklist (#93) * Fix README for release --------- Co-authored-by: Paul Razvan Berg <[email protected]> Co-authored-by: SwayStar123 <[email protected]> Co-authored-by: Paul Razvan Berg <[email protected]> Co-authored-by: SwayStar123 <[email protected]> Co-authored-by: IGI-111 <[email protected]> Co-authored-by: João Matos <[email protected]> Co-authored-by: K1-R1 <[email protected]>
1 parent a001d3c commit 348f717

File tree

25 files changed

+334
-139
lines changed

25 files changed

+334
-139
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,14 @@ The following changes have been made:
2424
<!--Delete everything after the "#" symbol and replace it with a number. No spaces between hash and number-->
2525

2626
Closes #\<issue number\>
27+
28+
## Checklist
29+
30+
- [ ] I have linked to any relevant issues.
31+
- [ ] I have commented my code, particularly in hard-to-understand areas.
32+
- [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book).
33+
- [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
34+
- [ ] I have added tests that prove my fix is effective or that my feature works.
35+
- [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant.
36+
- [ ] 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).
37+
- [ ] I have requested a review from the relevant team or maintainers.

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ concurrency:
1515
env:
1616
CARGO_TERM_COLOR: always
1717
REGISTRY: ghcr.io
18-
RUST_VERSION: 1.75.0
19-
FORC_VERSION: 0.56.0
20-
CORE_VERSION: 0.24.2
18+
RUST_VERSION: 1.77.0
19+
FORC_VERSION: 0.60.0
20+
CORE_VERSION: 0.26.0
2121
PATH_TO_SCRIPTS: .github/scripts
2222

2323
jobs:

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<a href="https://github.com/FuelLabs/sway-standards/actions/workflows/ci.yml" alt="CI">
1010
<img src="https://github.com/FuelLabs/sway-standards/actions/workflows/ci.yml/badge.svg" />
1111
</a>
12-
<a href="https://crates.io/crates/forc/0.49.1" alt="forc">
13-
<img src="https://img.shields.io/badge/forc-v0.49.1-orange" />
12+
<a href="https://crates.io/crates/forc/0.60.0" alt="forc">
13+
<img src="https://img.shields.io/badge/forc-v0.60.0-orange" />
1414
</a>
1515
<a href="./LICENSE" alt="forc">
1616
<img src="https://img.shields.io/github/license/FuelLabs/sway-standards" />
@@ -22,9 +22,9 @@
2222

2323
## Overview
2424

25-
The purpose of this repository is to contain standards for the Sway Language which users can import and use.
25+
The purpose of this repository is to contain standards for the Sway Language which users can import and use.
2626

27-
Standards in this repository may be in various stages of development. Use of draft standards and feedback on the proposed standards is encouraged. To use a draft, search for a standard using the appropriate GitHub label and implement the standard abi into your contract.
27+
Standards in this repository may be in various stages of development. Use of draft standards and feedback on the proposed standards is encouraged. To use a draft, search for a standard using the appropriate GitHub label and implement the standard abi into your contract.
2828

2929
If you don't find what you're looking for, feel free to create an issue and propose a new standard!
3030

@@ -36,7 +36,7 @@ If you don't find what you're looking for, feel free to create an issue and prop
3636
### Native Assets
3737

3838
- [SRC-20; Native Asset Standard](./SRCs/src-20.md) defines the implementation of a standard API for [Native Assets](https://docs.fuel.network/docs/sway/blockchain-development/native_assets) using the Sway Language.
39-
- [SRC-3; Mint and Burn](./SRCs/src-3.md) is used to enable mint and burn functionality for Native Assets.
39+
- [SRC-3; Mint and Burn](./SRCs/src-3.md) is used to enable mint and burn functionality for fungible assets.
4040
- [SRC-7; Arbitrary Asset Metadata Standard](./SRCs/src-7.md) is used to store metadata for [Native Assets](https://docs.fuel.network/docs/sway/blockchain-development/native_assets).
4141
- [SRC-9; Metadata Keys Standard](./SRCs/src-9.md) is used to store standardized metadata keys for [Native Assets](https://docs.fuel.network/docs/sway/blockchain-development/native_assets) in combination with the SRC-7 standard.
4242
- [SRC-6; Vault Standard](./SRCs/src-6.md) defines the implementation of a standard API for asset vaults developed in Sway.
@@ -66,7 +66,7 @@ To import a standard the following should be added to the project's `Forc.toml`
6666
standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.0" }
6767
```
6868

69-
> **NOTE:**
69+
> **NOTE:**
7070
> Be sure to set the tag to the latest release.
7171
7272
You may then import your desired standard in your Sway Smart Contract as so:
@@ -87,7 +87,7 @@ Minimal example implementations for every standard can be found in the [`example
8787

8888
#### SRC-20; Native Asset Standard Examples
8989

90-
##### - [Single Native Assset](./examples/src20-native-asset/single_asset/src/single_asset.sw)
90+
##### - [Single Native Asset](./examples/src20-native-asset/single_asset/src/single_asset.sw)
9191

9292
Example of the SRC-20 implementation where a contract contains a single asset with one `SubId`. This implementation is recommended for users that intend to deploy a single asset with their contract.
9393

@@ -119,15 +119,15 @@ Example of the SRC-5 implementation where a contract has an owner set at compile
119119

120120
##### [Multi Asset Vault](./examples/src6-vault/multi_asset_vault/)
121121

122-
A basic implementation of the vault standard that supports any number of sub vaults being created for every AssetId.
122+
A basic implementation of the vault standard that supports any number of sub vaults being created for every `AssetId`.
123123

124124
##### [Single Asset Vault](./examples/src6-vault/single_asset_vault/)
125125

126-
A basic implementation of the vault standard demonstrating how to restrict deposits and withdrawals to a single AssetId.
126+
A basic implementation of the vault standard demonstrating how to restrict deposits and withdrawals to a single `AssetId`.
127127

128128
##### [Single Asset Single Sub Vault](./examples/src6-vault/single_asset_single_sub_vault/)
129129

130-
A basic implementation of the vault standard demonstrating how to restrict deposits and withdrawals to a single AssetId, and to a single Sub vault.
130+
A basic implementation of the vault standard demonstrating how to restrict deposits and withdrawals to a single `AssetId`, and to a single Sub vault.
131131

132132
#### SRC-7; Arbitrary Asset Metadata Standard Examples
133133

@@ -147,10 +147,10 @@ Example of the SRC-12 implementation where contract deployments contain configur
147147

148148
##### [Without Configurables](./examples/src12-contract-factory/without_configurables/src/without_configurables.sw)
149149

150-
Example of the SRC-12 implementation where all contract deployments are identitcal and thus have the same bytecode and root.
150+
Example of the SRC-12 implementation where all contract deployments are identical and thus have the same bytecode and root.
151151

152152
> **Note**
153-
> All standards currently use `forc v0.56.0`.
153+
> All standards currently use `forc v0.60.0`.
154154
155155
<!-- TODO:
156156
## Contributing

SRCs/src-10.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ The `token_address` field MUST represent the bridged token's address on the cano
9898

9999
#### - token_id: `b256`
100100

101-
The `token_id` field MUST represent the token's ID on the canonical chain. The `ZERO_B256` MUST be used if this is a fungible token and no token ID exists.
101+
The `token_id` field MUST represent the token's ID on the canonical chain. The `b256::zero()` MUST be used if this is a fungible token and no token ID exists.
102102

103103
#### - decimals: `u8`
104104

@@ -132,7 +132,7 @@ The `token_address` field MUST represent the bridged token's address on the cano
132132

133133
#### token_id: `b256`
134134

135-
The `token_id` field MUST represent the token's ID on the canonical chain. The `ZERO_B256` MUST be used if this is a fungible token and no token ID exists.
135+
The `token_id` field MUST represent the token's ID on the canonical chain. The `b256::zero()` MUST be used if this is a fungible token and no token ID exists.
136136

137137
#### name: `String`
138138

SRCs/src-14.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Simple Upgradable Proxies
2+
3+
## Abstract
4+
5+
The following proposes a standard for simple upgradable proxies.
6+
7+
## Motivation
8+
9+
We seek to standardize proxy implementation to improve developer experience and enable tooling to automatically deploy or update proxies as needed.
10+
11+
## Prior Art
12+
13+
[This OpenZeppelin blog post](https://blog.openzeppelin.com/the-state-of-smart-contract-upgrades#proxies-and-implementations) is a good survey of the state of the art at this time.
14+
15+
Proxy designs fall into three essential categories:
16+
1. Immutable proxies which are lightweight clones of other contracts but can't change targets
17+
2. Upgradable proxies such as [UUPS](https://eips.ethereum.org/EIPS/eip-1822) which store a target in storage and delegate all calls to it
18+
3. [Diamonds](https://eips.ethereum.org/EIPS/eip-2535) which are both upgradable and can point to multiple targets on a per method basis
19+
20+
This document falls in the second category. We want to standardize the implementation of simple upgradable passthrough contracts.
21+
22+
The FuelVM provides an `LDC` instruction that is used by Sway's `std::execution::run_external` to provide a similar behavior to EVM's `delegatecall` and execute instructions from another contract while retaining one's own storage context. This is the intended means of implementation of this standard.
23+
24+
## Specification
25+
26+
### Required Behavior
27+
28+
The proxy contract MUST maintain the address of its target in its storage at slot `0x7bb458adc1d118713319a5baa00a2d049dd64d2916477d2688d76970c898cd55` (equivalent to `sha256("storage_SRC14_0")`).
29+
It SHOULD base other proxy specific storage fields at `sha256("storage_SRC14")` to avoid collisions with target storage.
30+
It MAY have its storage definition overlap with that of its target if necessary.
31+
32+
The proxy contract MUST delegate any method call not part of its interface to the target contract.
33+
34+
This delegation MUST retain the storage context of the proxy contract.
35+
36+
### Required Public Functions
37+
38+
The following functions MUST be implemented by a proxy contract to follow the SRC-14 standard:
39+
40+
#### `fn set_proxy_target(new_target: ContractId);`
41+
42+
If a valid call is made to this function it MUST change the target address of the proxy to `new_target`.
43+
This method SHOULD implement access controls such that the target can only be changed by a user that possesses the right permissions (typically the proxy owner).
44+
45+
## Rationale
46+
47+
This standard is meant to provide simple upgradability, it is deliberately minimalistic and does not provide the level of functionality of diamonds.
48+
49+
Unlike in [UUPS](https://eips.ethereum.org/EIPS/eip-1822), this standard requires that the upgrade function is part of the proxy and not its target.
50+
This prevents irrecoverable updates if a proxy is made to point to another proxy and no longer has access to upgrade logic.
51+
52+
## Backwards Compatibility
53+
54+
SRC-14 is intended to be compatible with SRC-5 and other standards of contract functionality.
55+
56+
As it is the first attempt to standardize proxy implementation, we do not consider interoperability with other proxy standards.
57+
58+
## Security Considerations
59+
60+
Permissioning proxy target changes is the primary consideration here.
61+
This standard is not opinionated about means of achieving this, use of [SRC-5](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-5.md) is recommended.
62+
63+
## Example ABI
64+
65+
```sway
66+
abi SRC14 {
67+
#[storage(write)]
68+
fn set_proxy_target(new_target: ContractId);
69+
}
70+
```
71+
72+
## Example Implementation
73+
74+
### [Minimal Proxy](../examples/examples/src14-simple-proxy/owned/src/minimal.sw)
75+
76+
Example of a minimal SRC-14 implementation with no access control.
77+
78+
### [Owned Proxy](../examples/examples/src14-simple-proxy/owned/src/owned.sw)
79+
80+
Example of a SRC-14 implementation that also implements [SRC-5](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-5.md).

SRCs/src-2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ This standard will improve security by providing developers with relevant inform
331331
/// use ownable::Ownership;
332332
///
333333
/// storage {
334-
/// owner: Ownership = Ownership::initalized(Identity::Address(Address::from(ZERO_B256))),
334+
/// owner: Ownership = Ownership::initalized(Identity::Address(Address::zero())),
335335
/// }
336336
///
337337
/// fn foo() {

SRCs/src-20.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ The following standard allows for the implementation of a standard API for [Nati
1111

1212
# Motivation
1313

14-
A standard interface for [Native Assets](https://docs.fuel.network/docs/sway/blockchain-development/native_assets) on Fuel allows external applications to interact with the native asset, whether that be decentralized exchanges, wallets, or Fuel's [Scripts](https://docs.fuel.network/docs/sway/sway-program-types/scripts/) and [Predicates](https://docs.fuel.network/docs/sway/sway-program-types/predicates/).
14+
A standard interface for [Native Assets](https://docs.fuel.network/docs/sway/blockchain-development/native_assets) on Fuel allows external applications to interact with the native asset, whether that be decentralized exchanges, wallets, or Fuel's [Scripts](https://docs.fuel.network/docs/sway/sway-program-types/scripts/) and [Predicates](https://docs.fuel.network/docs/sway/sway-program-types/predicates/).
1515

1616
# Prior Art
1717

1818
The SRC-20 Native Asset Standard naming pays homage to the [ERC-20 Token Standard](https://eips.ethereum.org/EIPS/eip-20) seen on Ethereum. While there is functionality we may use as a reference, it is noted that Fuel's [Native Assets](https://docs.fuel.network/docs/sway/blockchain-development/native_assets) are fundamentally different than Ethereum's tokens.
1919

20-
There has been a discussion of the Fungile Token Standard on the [Fuel Forum](https://forum.fuel.network/). This discussion can be found [here](https://forum.fuel.network/t/src-20-fungible-token-standard/186).
20+
There has been a discussion of the Fungible Token Standard on the [Fuel Forum](https://forum.fuel.network/). This discussion can be found [here](https://forum.fuel.network/t/src-20-fungible-token-standard/186).
2121

2222
There has also been a Fungible Token Standard and Non-Fungible Token Standard implementations added to the [Sway-Libs](https://github.com/FuelLabs/sway-libs) repository before the creation of the [Sway-Standards](https://github.com/FuelLabs/sway-standards) repository. The introduction of this standard in the [Sway-Standards](https://github.com/FuelLabs/sway-standards) repository will deprecate the Sway-Libs Fungible Token Standard.
2323

@@ -47,7 +47,7 @@ This function must return the symbol of the asset, such as “ETH”. This funct
4747

4848
This function must return the number of decimals the asset uses - e.g. 8, which means to divide the coin amount by 100000000 to get its user representation. This function MUST return `Some` for any assets minted by the contract.
4949

50-
## Non-Fungible Asset Restrictions
50+
## Non-Fungible Asset Restrictions
5151

5252
Non-Fungible Tokens (NFT) or Non-Fungible Assets on Fuel are Native Assets and thus follow the same standard as Fungible Native Assets with some restrictions. For a Native Asset on Fuel to be deemed an NFT, the following must be applied:
5353

@@ -56,9 +56,9 @@ Non-Fungible Tokens (NFT) or Non-Fungible Assets on Fuel are Native Assets and t
5656

5757
# Rationale
5858

59-
As the SRC-20 Native Asset Standard leverages Native Assets on Fuel, we do not require the implementation of certain functions such as transfer or approval. This is done directly within the FuelVM and there is no smart contract that requires updating of balances. As Fuel is UTXO based, any transfer events may be indexed on transaction receipts.
59+
As the SRC-20 Native Asset Standard leverages Native Assets on Fuel, we do not require the implementation of certain functions such as transfer or approval. This is done directly within the FuelVM and there is no smart contract that requires updating of balances. As Fuel is UTXO based, any transfer events may be indexed on transaction receipts.
6060

61-
Following this, we have omitted the inclusion of any transfer functions or events. The provided specification outlines only the required functions and events to implement fully functional native assets on the Fuel Network. Additional functionality and properties may be added as needed.
61+
Following this, we have omitted the inclusion of any transfer functions or events. The provided specification outlines only the functions necessary to implement fully functional native assets on the Fuel Network. Additional functionality and properties may be added as needed.
6262

6363
# Backwards Compatibility
6464

@@ -87,7 +87,7 @@ abi MyAsset {
8787

8888
# Example Implementation
8989

90-
## [Single Native Assset](../examples/src20-native-asset/multi_asset/src/multi_asset.sw)
90+
## [Single Native Asset](../examples/src20-native-asset/multi_asset/src/multi_asset.sw)
9191

9292
Example of the SRC-20 implementation where a contract contains a single asset with one `SubId`. This implementation is recommended for users that intend to deploy a single asset with their contract.
9393

SRCs/src-3.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Abstract
22

3-
The following standard enables the minting and burning of native assets for any fungible assets within the Sway Language. It seeks to define mint and burn functions defined separately from the [SRC-20](./src-20.md) standard. Any contract that implements the SRC-3 standard MUST implement the [SRC-20](./src-20.md) standard.
3+
The following standard enables the minting and burning of native assets for any fungible assets within the Sway Language. It seeks to define mint and burn functions defined separately from the [SRC-20](./src-20.md) standard.
44

55
# Motivation
66

@@ -16,27 +16,27 @@ Minting and burning were initially added to the [SRC-20](./src-20.md) standard.
1616

1717
The following functions MUST be implemented to follow the SRC-3 standard:
1818

19-
### `fn mint(recipient: Identity, vault_sub_id: SubId, amount: u64)`
19+
### `fn mint(recipient: Identity, sub_id: SubId, amount: u64)`
2020

21-
This function MUST mint `amount` coins with sub-identifier `vault_sub_id` and transfer them to the `recipient`.
21+
This function MUST mint `amount` coins with sub-identifier `sub_id` and transfer them to the `recipient`.
2222
This function MAY contain arbitrary conditions for minting, and revert if those conditions are not met.
2323

2424
##### Arguments
2525

2626
* `recipient` - The `Identity` to which the newly minted asset is transferred to.
27-
* `vault_sub_id` - The sub-identifier of the asset to mint.
27+
* `sub_id` - The sub-identifier of the asset to mint.
2828
* `amount` - The quantity of coins to mint.
2929

30-
### `fn burn(vault_sub_id: SubId, amount: u64)`
30+
### `fn burn(sub_id: SubId, amount: u64)`
3131

32-
This function MUST burn `amount` coins with the sub-identifier `vault_sub_id` and MUST ensure the `AssetId` of the asset is the sha-256 hash of `(ContractId, SubId)` for the implementing contract.
32+
This function MUST burn `amount` coins with the sub-identifier `sub_id` and MUST ensure the `AssetId` of the asset is the sha-256 hash of `(ContractId, SubId)` for the implementing contract.
3333
This function MUST ensure at least `amount` coins have been transferred to the implementing contract.
3434
This function MUST update the total supply defined in the [SRC-20](./src-20.md) standard.
3535
This function MAY contain arbitrary conditions for burning, and revert if those conditions are not met.
3636

3737
##### Arguments
3838

39-
* `vault_sub_id` - The sub-identifier of the asset to burn.
39+
* `sub_id` - The sub-identifier of the asset to burn.
4040
* `amount` - The quantity of coins to burn.
4141

4242
# Rationale
@@ -57,10 +57,10 @@ The burn function may also introduce a security consideration if the total suppl
5757
```rust
5858
abi MySRC3Asset {
5959
#[storage(read, write)]
60-
fn mint(recipient: Identity, vault_sub_id: SubId, amount: u64);
60+
fn mint(recipient: Identity, sub_id: SubId, amount: u64);
6161
#[payable]
6262
#[storage(read, write)]
63-
fn burn(vault_sub_id: SubId, amount: u64);
63+
fn burn(sub_id: SubId, amount: u64);
6464
}
6565
```
6666

0 commit comments

Comments
 (0)