Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update src14 storage recommendation and general typos #136

Merged
merged 8 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ concurrency:
env:
CARGO_TERM_COLOR: always
REGISTRY: ghcr.io
RUST_VERSION: 1.77.0
FORC_VERSION: 0.61.0
CORE_VERSION: 0.26.0
RUST_VERSION: 1.80.1
FORC_VERSION: 0.63.1
CORE_VERSION: 0.34.0
PATH_TO_SCRIPTS: .github/scripts

jobs:
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed Unreleased

- Something changed here 1
- [#135](https://github.com/FuelLabs/sway-standards/pull/135) Updates standards, examples and CI to latest forc 0.63.1.
- Something changed here 2

bitzoic marked this conversation as resolved.
Show resolved Hide resolved
### Fixed Unreleased
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<a href="https://github.com/FuelLabs/sway-standards/actions/workflows/ci.yml" alt="CI">
<img src="https://github.com/FuelLabs/sway-standards/actions/workflows/ci.yml/badge.svg" />
</a>
<a href="https://crates.io/crates/forc/0.61.0" alt="forc">
<img src="https://img.shields.io/badge/forc-v0.61.0-orange" />
<a href="https://crates.io/crates/forc/0.63.1" alt="forc">
<img src="https://img.shields.io/badge/forc-v0.63.1-orange" />
</a>
<a href="./LICENSE" alt="forc">
<img src="https://img.shields.io/github/license/FuelLabs/sway-standards" />
Expand Down Expand Up @@ -109,7 +109,7 @@ Example of the SRC-3 implementation where a contract mints multiple assets with

#### SRC-5; Ownership Examples

##### - [Uninitalized](./examples/src5-ownership/uninitialized_example/src/uninitialized_example.sw)
##### - [Uninitialized](./examples/src5-ownership/uninitialized_example/src/uninitialized_example.sw)
bitzoic marked this conversation as resolved.
Show resolved Hide resolved

Example of the SRC-5 implementation where a contract does not have an owner set at compile time with the intent to set it during runtime.

Expand Down Expand Up @@ -162,12 +162,12 @@ Example of a minimal SRC-14 implementation with no access control.
Example of a SRC-14 implementation that also implements [SRC-5](https://docs.fuel.network/docs/sway-standards/src-5-ownership/).

> **Note**
> All standards currently use `forc v0.61.0`.
> All standards currently use `forc v0.63.1`.

<!-- TODO:
## Contributing

Check out the [book](https://fuellabs.github.io/sway-libs/book/index.html) for more info!
Check out the [book](https://fuellabs.github.io/sway-libs/book/index.html) for more info!
-->

> **Note**
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Standards in this repository may be in various stages of development. Use of dra
If you don't find what you're looking for, feel free to create an issue and propose a new standard!

> **Note**
> All standards currently use `forc v0.61.0`.
> All standards currently use `forc v0.63.1`.

## Using a standard

Expand Down
2 changes: 1 addition & 1 deletion docs/src/src-10-native-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A standard interface for bridges intends to provide a safe and efficient bridge

## Prior Art

The standard is centered on Fuel’s [Bridge Architecture](https://github.com/FuelLabs/fuel-bridge/blob/main/docs/ARCHITECTURE.md). Fuel's bridge system is built on a message protocol that allows to send (and receive) messages between entities located in two different blockchains.
The standard is centred on Fuel’s [Bridge Architecture](https://github.com/FuelLabs/fuel-bridge/blob/main/docs/ARCHITECTURE.md). Fuel's bridge system is built on a message protocol that allows to send (and receive) messages between entities located in two different blockchains.
bitzoic marked this conversation as resolved.
Show resolved Hide resolved

The following standard takes reference from the [`FungibleBridge`](https://github.com/FuelLabs/fuel-bridge/blob/3971081850e7961d9b649edda4cad8a848ee248e/packages/fungible-token/bridge-fungible-token/src/interface.sw#L22) ABI defined in the fuel-bridge repository.

Expand Down
20 changes: 10 additions & 10 deletions docs/src/src-13-soulbound-address.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ We must also ensure every `Address` on Fuel has its own Predicate. This can be g
### Definitions

- **Soulbound Address Predicate** - The resulting predicate which owns assets on behalf of an `Address`.
- **Soulbound Address** - The computed `Address` of the *Soulbound Asset Predicate*.
- **Soulbound Asset** - Any [Native Asset](https://docs.fuel.network/docs/sway/blockchain-development/native_assets) sent to the *Soulbound Address*.
- **Soulbound Address** - The computed `Address` of the _Soulbound Asset Predicate_.
- **Soulbound Asset** - Any [Native Asset](https://docs.fuel.network/docs/sway/blockchain-development/native_assets) sent to the _Soulbound Address_.

### Soulbound Address Predicate Specification

- The *Soulbound Address Predicate* SHALL never spend the assets sent to its computed predicate `Address` or *Soulbound Address*.
- The *Soulbound Address Predicate* SHALL encode an `Address` of which it represents the soulbound address.
- The _Soulbound Address Predicate_ SHALL never spend the assets sent to its computed predicate `Address` or _Soulbound Address_.
- The _Soulbound Address Predicate_ SHALL encode an `Address` of which it represents the soulbound address.

Below we define the *Soulbound Address Predicate* where `ADDRESS` MUST be replaced with the `Address` of which the *Soulbound Address Predicate* represents.
Below we define the _Soulbound Address Predicate_ where `ADDRESS` MUST be replaced with the `Address` of which the _Soulbound Address Predicate_ represents.

```sway
predicate;
Expand All @@ -50,9 +50,9 @@ fn main() -> bool {

### Soulbound Address

The *Soulbound Address* is the *Soulbound Address Predicate*'s predicate address. A predicate's address(the bytecode root) is defined [here](https://github.com/FuelLabs/fuel-specs/blob/master/src/identifiers/predicate-id.md).
The _Soulbound Address_ is the _Soulbound Address Predicate_'s predicate address. A predicate's address(the bytecode root) is defined [here](https://github.com/FuelLabs/fuel-specs/blob/master/src/identifiers/predicate-id.md).

The *Soulbound Address* may be computed from the *Soulbound Address Predicate*'s bytecode both on-chain or off-chain. For off-chain computation, please refer to the fuels-rs [predicate docs](https://docs.fuel.network/docs/fuels-rs/predicates/). For on-chain computation, please refer to Sway-Lib's [Bytecode Library](https://docs.fuel.network/docs/sway-libs/bytecode/).
The _Soulbound Address_ may be computed from the _Soulbound Address Predicate_'s bytecode both on-chain or off-chain. For off-chain computation, please refer to the fuels-rs [predicate docs](https://docs.fuel.network/docs/fuels-rs/predicates/). For on-chain computation, please refer to Sway-Lib's [Bytecode Library](https://docs.fuel.network/docs/sway-libs/bytecode/).

## Rationale

Expand All @@ -66,13 +66,13 @@ This standard is compatible with Fuel's [Native Assets](https://docs.fuel.networ

This standard does not introduce any security concerns, as it does not call external contracts, nor does it define any mutations of the contract state.

It should however be noted that any Native Asset on the Fuel Network is not a Soulbound Asset until it is sent to a *Soulbound Address*.
It should however be noted that any Native Asset on the Fuel Network is not a Soulbound Asset until it is sent to a _Soulbound Address_.

## Example

The following example shows the *Soulbound Address Predicate* for the `0xe033369a522e3cd2fc19a5a705a7f119938027e8e287c0ec35b784e68dab2be6` `Address`.
The following example shows the _Soulbound Address Predicate_ for the `0xe033369a522e3cd2fc19a5a705a7f119938027e8e287c0ec35b784e68dab2be6` `Address`.

The resulting *Soulbound Address* is `0x7f28a538d06788a3d98bb72f4b41012d86abc4b0369ee5dedf56cfbaf245d609`. Any Native Assets sent to this address will become Soulbound Assets.
The resulting _Soulbound Address_ is `0x7f28a538d06788a3d98bb72f4b41012d86abc4b0369ee5dedf56cfbaf245d609`. Any Native Assets sent to this address will become Soulbound Assets.

```sway
predicate;
Expand Down
6 changes: 3 additions & 3 deletions docs/src/src-14-simple-upgradeable-proxies.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ Proxy designs fall into three essential categories:

This document falls in the second category. We want to standardize the implementation of simple upgradeable pass-through contracts.

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.
The FuelVM provides an `LDC` instruction that is used by Sway's `std::execution::run_external` to provide a similar behaviour 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.
bitzoic marked this conversation as resolved.
Show resolved Hide resolved

## Specification

### Required Behavior
### Required Behaviour
bitzoic marked this conversation as resolved.
Show resolved Hide resolved

The proxy contract MUST maintain the address of its target in its storage at slot `0x7bb458adc1d118713319a5baa00a2d049dd64d2916477d2688d76970c898cd55` (equivalent to `sha256("storage_SRC14_0")`).
It SHOULD base other proxy specific storage fields at `sha256("storage_SRC14")` to avoid collisions with target storage.
It SHOULD base other proxy specific storage fields in the `SRC14` namespace to avoid collisions with target storage.
It MAY have its storage definition overlap with that of its target if necessary.

The proxy contract MUST delegate any method call not part of its interface to the target contract.
Expand Down
10 changes: 5 additions & 5 deletions docs/src/src-2-inline-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ This section has a `h1` header.
This section provides an example of the use of the function. This section is not required to follow the SRC-2 standard however encouraged for auxiliary and library functions.
Example:

```sway
````sway
bitzoic marked this conversation as resolved.
Show resolved Hide resolved
/// # Examples
///
/// ```sway
/// fn foo(argument_1: b256, argument_2: b256) {
/// let result = my_function(argument_1, argument_2);
/// }
```
````

### Structs

Expand Down Expand Up @@ -300,7 +300,7 @@ This standard will improve security by providing developers with relevant inform

### Function Example

```sway
````sway
bitzoic marked this conversation as resolved.
Show resolved Hide resolved
/// Ensures that the sender is the owner.
///
/// # Arguments
Expand All @@ -325,7 +325,7 @@ This standard will improve security by providing developers with relevant inform
/// use ownable::Ownership;
///
/// storage {
/// owner: Ownership = Ownership::initalized(Identity::Address(Address::zero())),
/// owner: Ownership = Ownership::initialized(Identity::Address(Address::zero())),
/// }
///
/// fn foo() {
Expand All @@ -337,7 +337,7 @@ pub fn only_owner(self, number: u64) -> bool {
require(self.owner() == State::Initialized(msg_sender().unwrap()), AccessError::NotOwner);
number == 5
}
```
````

### Struct Examples

Expand Down
10 changes: 5 additions & 5 deletions docs/src/src-3-minting-and-burning.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ This function MAY contain arbitrary conditions for minting, and revert if those

##### Mint Arguments

* `recipient` - The `Identity` to which the newly minted asset is transferred to.
* `sub_id` - The sub-identifier of the asset to mint.
* `amount` - The quantity of coins to mint.
- `recipient` - The `Identity` to which the newly minted asset is transferred to.
- `sub_id` - The sub-identifier of the asset to mint.
- `amount` - The quantity of coins to mint.

#### `fn burn(sub_id: SubId, amount: u64)`

Expand All @@ -36,8 +36,8 @@ This function MAY contain arbitrary conditions for burning, and revert if those

##### Burn Arguments

* `sub_id` - The sub-identifier of the asset to burn.
* `amount` - The quantity of coins to burn.
- `sub_id` - The sub-identifier of the asset to burn.
- `amount` - The quantity of coins to burn.

## Rationale

Expand Down
2 changes: 1 addition & 1 deletion docs/src/src-5-ownership.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ abi SRC5 {

## Example Implementation

### Uninitalized
### Uninitialized

Example of the SRC-5 implementation where a contract does not have an owner set at compile time with the intent to set it during runtime.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/src-6-vault.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ abi SRC6 {

#[storage(read)]
fn managed_assets(underlying_asset: AssetId, vault_sub_id: SubId) -> u64;

#[storage(read)]
fn max_depositable(receiver: Identity, underlying_asset: AssetId, vault_sub_id: SubId) -> Option<u64>;

Expand Down
10 changes: 5 additions & 5 deletions docs/src/src-8-bridged-asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,31 @@ impl SRC7 for Contract {
impl SRC20 for Contract {
fn total_assets() -> u64 {
1
}
}

fn total_supply(asset: AssetId) -> Option<u64> {
match asset {
match asset {
AssetId::default() => Option::Some(1),
_ => Option::None,
}
}

fn name(asset: AssetId) -> Option<String> {
match asset {
match asset {
AssetId::default() => Option::Some(String::from_ascii_str("Name")),
_ => Option::None,
}
}

fn symbol(asset: AssetId) -> Option<String> {
match asset {
match asset {
AssetId::default() => Option::Some(String::from_ascii_str("Symbol")),
_ => Option::None,
}
}

fn decimals(asset: AssetId) -> Option<u8> {
match asset {
match asset {
AssetId::default() => Option::Some(0u8),
_ => Option::None,
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/src-9-metadata-keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ The key `link:contact` SHALL return a `String` variant of the asset's project co

#### `link:docs`

The key `link:docs` SHALL return a `String` variant of the asset's project documentation webpage.
The key `link:docs` SHALL return a `String` variant of the asset's project documentation webpage.

#### `link:forum`

Expand Down
16 changes: 11 additions & 5 deletions examples/src14-simple-proxy/minimal/src/minimal.sw
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,31 @@ use std::execution::run_external;
use standards::src14::{SRC14, SRC14_TARGET_STORAGE};

storage {
// target is at sha256("storage_SRC14_0")
target: ContractId = ContractId::zero(),
SRC14 {
/// The [ContractId] of the target contract.
///
/// # Additional Information
///
/// `target` is stored at sha256("storage_SRC14_0")
target in 0x7bb458adc1d118713319a5baa00a2d049dd64d2916477d2688d76970c898cd55: ContractId = ContractId::zero(),
},
}

impl SRC14 for Contract {
#[storage(read, write)]
fn set_proxy_target(new_target: ContractId) {
storage.target.write(new_target);
storage::SRC14.target.write(new_target);
}

#[storage(read)]
fn proxy_target() -> Option<ContractId> {
storage.target.try_read()
storage::SRC14.target.try_read()
}
}

#[fallback]
#[storage(read)]
fn fallback() {
// pass through any other method call to the target
run_external(storage.target.read())
run_external(storage::SRC14.target.read())
}
21 changes: 13 additions & 8 deletions examples/src14-simple-proxy/owned/src/owned.sw
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,49 @@ use standards::src14::{SRC14, SRC14_TARGET_STORAGE, SRC14Extension};
const INITIAL_OWNER: Identity = Identity::Address(Address::zero());

storage {
proxy {
// target is at sha256("storage_SRC14_0")
SRC14 {
/// The [ContractId] of the target contract.
///
/// # Additional Information
///
/// `target` is stored at sha256("storage_SRC14_0")
target in 0x7bb458adc1d118713319a5baa00a2d049dd64d2916477d2688d76970c898cd55: ContractId = ContractId::zero(),
/// The [State] of the proxy owner.
owner: State = State::Initialized(INITIAL_OWNER),
},
target: ContractId = ContractId::zero(),
}

impl SRC14 for Contract {
#[storage(read, write)]
fn set_proxy_target(new_target: ContractId) {
only_owner();
storage.target.write(new_target);
storage::SRC14.target.write(new_target);
}

#[storage(read)]
fn proxy_target() -> Option<ContractId> {
storage.target.try_read()
storage::SRC14.target.try_read()
}
}

impl SRC14Extension for Contract {
#[storage(read)]
fn proxy_owner() -> State {
storage::proxy.owner.read()
storage::SRC14.owner.read()
}
}

#[fallback]
#[storage(read)]
fn fallback() {
// pass through any other method call to the target
run_external(storage.target.read())
run_external(storage::SRC14.target.read())
}

#[storage(read)]
fn only_owner() {
require(
storage::proxy
storage::SRC14
.owner
.read() == State::Initialized(msg_sender().unwrap()),
AccessError::NotOwner,
Expand Down
Loading