From 792639cdf391565e6e6a02482ea8a46d9604a6f5 Mon Sep 17 00:00:00 2001 From: Cameron Carstens Date: Tue, 10 Sep 2024 12:00:21 +0545 Subject: [PATCH] Release v0.6.1 (#150) * Hotfix: Update Cargo.toml to v0.5.1 (#115) * Hotfix: Update Cargo.toml to v0.5.1 * Udpate CHANGELOG * fix vault reads * add changelog * move changelog to new empty changelog * add "unreleased" to changelog heads * remove date * add v0.5.1 * SRC-6 example contract does not update managed assets (#122) * Update SRC-6 example with decrementation of managed assets * Update CHANGELOG * Fix link on CHANGELOG.md * Update CHANGELOG to resolve markdown error with duplicate headers * Write to storage * Use new namespace syntax for storage (#120) * chore: fix compiler warnings * remove for examples * Update changelog * Prepare master for v0.5.2 release (#126) * Prepare for v0.5.2 release * Update CHANGELOG * Update CHANGELOG formatting * Make the `SubId` an `Option` in SRC-3's `mint()` function (#131) * Update specifications to change SRC-3 mint sub_id to an Option * Update SRC-3 standard for option in mint * Update examples * Udpate CHANGELOG * Run formatter * Fix spelling * Add event logging to SRC-20 and SRC-7 standards (#130) * Add event logging to SRC-20 and SRC-7 specification * Add event logging structs to SRC-20 and SRC-7 * Update CHANGELOG * Add inline docs to SRC-20 events * Fix CI * Require that logs of metadata are emitted even with contants * Update standards with additional log and ordering * Update examples to follow new specs * Add custom word to spell checker * Run formatter * Fix markdown formatting * Resolve warnings in examples * Build CI with release * Store srv7 metadata to storage * Remove cancel in progress from CI * Update name for TotalSupplyEvent * Split examples into seperate workspace projects * Prepare for v0.6.0 release * Update CHANGELOG * Resolve warnings in examples (#137) * Resolve warnings * Update CHANGELOG * Run formatter * Remove cancel in progress from CI * Revert remove cancel in progress from CI * fix max_depositable and max_withdrawable examples --------- Co-authored-by: SwayStar123 * chore: update to forc 0.63.3 (#135) * chore: update to forc 0.63.1 * chore: updated changelog * Update to forc v0.63.3 --------- Co-authored-by: bitzoic * docs: update src14 storage recommendation and general typos (#136) * chore: update to forc 0.63.1 * chore: updated changelog * docs: update src14 and general typos * Apply PR review comments * Fix markdown * Update CHANGELOG * Improve CHANGELOG comment --------- Co-authored-by: bitzoic * Add helper functions to SRC7 standard's `Metadata` (#144) * Add helper functions to SRC7 standard * Update CHANGELOG * Remove metadata functions (#148) * Fix Sway Standards inline docs (#142) * Update sway standards inline docs * Update CHANGELOG * Fix typo * Prepare for Sway-Standards `v0.6.1` release (#147) * Prepare for Sway-Standards v0.6.1 release * Update CHANGELOG * Add helper functions to struct types and `Eq` implementations for all types (#149) * Add helper functions to struct types and Eq implementations * Add checks to enum types * Update CHANGELOG --------- Co-authored-by: SwayStar123 Co-authored-by: SwayStar123 <46050679+SwayStar123@users.noreply.github.com> Co-authored-by: IGI-111 Co-authored-by: Sophie Co-authored-by: K1-R1 <77465250+K1-R1@users.noreply.github.com> --- .github/workflows/ci.yaml | 6 +- CHANGELOG.md | 30 +- Cargo.toml | 2 +- README.md | 12 +- docs/spell-check-custom-words.txt | 4 +- docs/src/index.md | 4 +- docs/src/src-12-contract-factory.md | 2 +- docs/src/src-13-soulbound-address.md | 20 +- docs/src/src-14-simple-upgradeable-proxies.md | 2 +- docs/src/src-2-inline-documentation.md | 2 +- docs/src/src-5-ownership.md | 2 +- docs/src/src-6-vault.md | 2 +- docs/src/src-8-bridged-asset.md | 10 +- docs/src/src-9-metadata-keys.md | 2 +- .../src14-simple-proxy/minimal/src/minimal.sw | 16 +- .../src14-simple-proxy/owned/src/owned.sw | 22 +- .../multi_asset/src/multi_asset.sw | 35 +- .../single_asset/src/single_asset.sw | 29 +- .../multi_asset/src/multi_asset.sw | 40 +- .../single_asset/src/single_asset.sw | 40 +- .../src/initialized_example.sw | 3 +- .../src/uninitialized_example.sw | 2 +- .../src6-vault/multi_asset_vault/src/main.sw | 44 +- .../single_asset_single_sub_vault/src/main.sw | 50 +- .../src6-vault/single_asset_vault/src/main.sw | 64 +- .../multi_asset/src/multi_asset.sw | 76 +- .../single_asset/src/single_asset.sw | 63 +- standards/src/src10.sw | 549 ++++++++++++- standards/src/src11.sw | 725 ++++++++++++++++++ standards/src/src12.sw | 40 +- standards/src/src14.sw | 17 +- standards/src/src20.sw | 494 +++++++++++- standards/src/src3.sw | 8 +- standards/src/src5.sw | 148 +++- standards/src/src6.sw | 496 ++++++++++++ standards/src/src7.sw | 150 +++- 36 files changed, 2825 insertions(+), 386 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a8f67d15..fd3c74e2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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.3 + CORE_VERSION: 0.34.0 PATH_TO_SCRIPTS: .github/scripts jobs: diff --git a/CHANGELOG.md b/CHANGELOG.md index 3488ed6e..b1d3c0dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,26 +9,48 @@ and this project adheres to [Semantic Versioning](http://semver.org/). Description of the upcoming release here. -### Added Unreleased +### Added - Something new here 1 - Something new here 2 -### Changed Unreleased +### Changed - Something changed here 1 - Something changed here 2 -### Fixed Unreleased +### Fixed - Some fix here 1 - Some fix here 2 -#### Breaking Unreleased +#### Breaking - Some breaking change here 1 - Some breaking change here 2 +## [Version 0.6.1] + +Description of the upcoming release here. + +### Added v0.6.1 + +- [#149](https://github.com/FuelLabs/sway-standards/pull/149) Adds struct field getters, `new()`, and `Eq` implementations to SRC-10's `DepositMessage` and `MetadataMessage` types and SRC-11's `SecurityInformation` type. +- [#149](https://github.com/FuelLabs/sway-standards/pull/149) Adds `Eq` implementation to SRC-5's `AccessError` error. +- [#149](https://github.com/FuelLabs/sway-standards/pull/149) Adds check functions and `Eq` implementation to SRC-5's `State` type and SRC-10's `DepositType` type. +- [#149](https://github.com/FuelLabs/sway-standards/pull/149) Adds struct field getters, `new()`, `log()`, and `Eq` implementations to SRC-6's `Deposit`, and `Withdraw` types, SRC-20's `SetNameEvent`, `SetSymbolEvent`, `SetDecimalsEvent`, and `TotalSupplyEvent` events, and SRC-7's `SetMetadataEvent` event. + +### Changed v0.6.1 + +- [#135](https://github.com/FuelLabs/sway-standards/pull/135) Updates standards, examples and CI to latest forc 0.63.3. +- [#147](https://github.com/FuelLabs/sway-standards/pull/147) Prepares for the v0.6.1 release. + +### Fixed v0.6.1 + +- [#137](https://github.com/FuelLabs/sway-standards/pull/137) Resolves warnings for SRC-6, SRC-14, and SRC-5 standard examples. +- [#136](https://github.com/FuelLabs/sway-standards/pull/136) Fixes SRC14 to recommend namespacing all non-standardized storage variables under the SRC14 namespace, fixes typos, and improves markdown in docs and inline documentation. +- [#142](https://github.com/FuelLabs/sway-standards/pull/142) Fixes errors in inline documentation for SRC-10, SRC-12, SRC-14, SRC-20, SRC-3, SRC-5, SRC-7 standards. + ## [Version 0.6.0] ### Added v0.6.0 diff --git a/Cargo.toml b/Cargo.toml index 00b54aa1..28fcf2d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,4 @@ [package] name = "sway-standards" -version = "0.6.0" +version = "0.6.1" edition = "2021" diff --git a/README.md b/README.md index 0848b8db..3d917848 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ - - + + @@ -65,7 +65,7 @@ If you don't find what you're looking for, feel free to create an issue and prop To import a standard the following should be added to the project's `Forc.toml` file under `[dependencies]` with the most recent release: ```toml -standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" } +standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.1" } ``` > **NOTE:** @@ -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) 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. @@ -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.3`. > **Note** diff --git a/docs/spell-check-custom-words.txt b/docs/spell-check-custom-words.txt index e2cb87cd..65384a7b 100644 --- a/docs/spell-check-custom-words.txt +++ b/docs/spell-check-custom-words.txt @@ -259,10 +259,10 @@ WAV OGA glTF GLB -Uninitalized +Uninitialized upgradeability SetMetadataEvent SetNameEvent SetSymbolEvent SetDecimalsEvent -UpdateTotalSupplyEvent \ No newline at end of file +UpdateTotalSupplyEvent diff --git a/docs/src/index.md b/docs/src/index.md index cc260e07..e7d7b5be 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -7,14 +7,14 @@ 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.3`. ## Using a standard To import a standard the following should be added to the project's `Forc.toml` file under `[dependencies]` with the most recent release: ```toml -standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.0" } +standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.1" } ``` > **NOTE:** diff --git a/docs/src/src-12-contract-factory.md b/docs/src/src-12-contract-factory.md index aca899c0..52c062fc 100644 --- a/docs/src/src-12-contract-factory.md +++ b/docs/src/src-12-contract-factory.md @@ -62,7 +62,7 @@ There are no other standards that the SRC-12 requires compatibility. ## Security Considerations -This standard takes into consideration child contracts that are deployed with differentiating configurable values, however individual contract behaviors may be dependent on storage variables. As storage variables may change after the contract has been registered with the SRC-12 compliant contract, the standard suggests to check these values upon registration however it is not enforced. +This standard takes into consideration child contracts that are deployed with differentiating configurable values, however individual contract behaviours may be dependent on storage variables. As storage variables may change after the contract has been registered with the SRC-12 compliant contract, the standard suggests to check these values upon registration however it is not enforced. ## Example ABI diff --git a/docs/src/src-13-soulbound-address.md b/docs/src/src-13-soulbound-address.md index 5a7b89c5..20a2c315 100644 --- a/docs/src/src-13-soulbound-address.md +++ b/docs/src/src-13-soulbound-address.md @@ -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; @@ -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 @@ -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; diff --git a/docs/src/src-14-simple-upgradeable-proxies.md b/docs/src/src-14-simple-upgradeable-proxies.md index a15e5046..21ee8e63 100644 --- a/docs/src/src-14-simple-upgradeable-proxies.md +++ b/docs/src/src-14-simple-upgradeable-proxies.md @@ -25,7 +25,7 @@ The FuelVM provides an `LDC` instruction that is used by Sway's `std::execution: ### Required Behavior 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. diff --git a/docs/src/src-2-inline-documentation.md b/docs/src/src-2-inline-documentation.md index 247bfa3a..80045f34 100644 --- a/docs/src/src-2-inline-documentation.md +++ b/docs/src/src-2-inline-documentation.md @@ -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() { diff --git a/docs/src/src-5-ownership.md b/docs/src/src-5-ownership.md index 3ce9c8dd..2884f65b 100644 --- a/docs/src/src-5-ownership.md +++ b/docs/src/src-5-ownership.md @@ -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. diff --git a/docs/src/src-6-vault.md b/docs/src/src-6-vault.md index 04ac75f0..cd84b7fa 100644 --- a/docs/src/src-6-vault.md +++ b/docs/src/src-6-vault.md @@ -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; diff --git a/docs/src/src-8-bridged-asset.md b/docs/src/src-8-bridged-asset.md index 5409998c..dab11cc1 100644 --- a/docs/src/src-8-bridged-asset.md +++ b/docs/src/src-8-bridged-asset.md @@ -88,31 +88,31 @@ impl SRC7 for Contract { impl SRC20 for Contract { fn total_assets() -> u64 { 1 - } + } fn total_supply(asset: AssetId) -> Option { - match asset { + match asset { AssetId::default() => Option::Some(1), _ => Option::None, } } fn name(asset: AssetId) -> Option { - match asset { + match asset { AssetId::default() => Option::Some(String::from_ascii_str("Name")), _ => Option::None, } } fn symbol(asset: AssetId) -> Option { - match asset { + match asset { AssetId::default() => Option::Some(String::from_ascii_str("Symbol")), _ => Option::None, } } fn decimals(asset: AssetId) -> Option { - match asset { + match asset { AssetId::default() => Option::Some(0u8), _ => Option::None, } diff --git a/docs/src/src-9-metadata-keys.md b/docs/src/src-9-metadata-keys.md index 9558b3cd..cc220ca4 100644 --- a/docs/src/src-9-metadata-keys.md +++ b/docs/src/src-9-metadata-keys.md @@ -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` diff --git a/examples/src14-simple-proxy/minimal/src/minimal.sw b/examples/src14-simple-proxy/minimal/src/minimal.sw index 721dcac7..b23600fe 100644 --- a/examples/src14-simple-proxy/minimal/src/minimal.sw +++ b/examples/src14-simple-proxy/minimal/src/minimal.sw @@ -4,19 +4,25 @@ 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 { - storage.target.try_read() + storage::SRC14.target.try_read() } } @@ -24,5 +30,5 @@ impl SRC14 for Contract { #[storage(read)] fn fallback() { // pass through any other method call to the target - run_external(storage.target.read()) + run_external(storage::SRC14.target.read()) } diff --git a/examples/src14-simple-proxy/owned/src/owned.sw b/examples/src14-simple-proxy/owned/src/owned.sw index 5e5ba6dd..3e6ba399 100644 --- a/examples/src14-simple-proxy/owned/src/owned.sw +++ b/examples/src14-simple-proxy/owned/src/owned.sw @@ -5,33 +5,39 @@ use standards::src5::{AccessError, State}; use standards::src14::{SRC14, SRC14_TARGET_STORAGE, SRC14Extension}; /// The owner of this contract at deployment. +#[allow(dead_code)] 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 { - 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() } } @@ -39,13 +45,13 @@ impl SRC14Extension for Contract { #[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, diff --git a/examples/src20-native-asset/multi_asset/src/multi_asset.sw b/examples/src20-native-asset/multi_asset/src/multi_asset.sw index 62b3ad47..d8540b79 100644 --- a/examples/src20-native-asset/multi_asset/src/multi_asset.sw +++ b/examples/src20-native-asset/multi_asset/src/multi_asset.sw @@ -177,8 +177,8 @@ abi SetSRC20Data { fn set_src20_data( asset: AssetId, total_supply: u64, - name: String, - symbol: String, + name: Option, + symbol: Option, decimals: u8, ); } @@ -188,8 +188,8 @@ impl SetSRC20Data for Contract { fn set_src20_data( asset: AssetId, supply: u64, - name: String, - symbol: String, + name: Option, + symbol: Option, decimals: u8, ) { // NOTE: There are no checks for if the caller has permissions to update the metadata @@ -199,28 +199,9 @@ impl SetSRC20Data for Contract { } let sender = msg_sender().unwrap(); - log(SetNameEvent { - asset, - name: Some(name), - sender, - }); - - log(SetSymbolEvent { - asset, - symbol: Some(symbol), - sender, - }); - - log(SetDecimalsEvent { - asset, - decimals, - sender, - }); - - log(TotalSupplyEvent { - asset, - supply, - sender, - }); + SetNameEvent::new(asset, name, sender).log(); + SetSymbolEvent::new(asset, symbol, sender).log(); + SetDecimalsEvent::new(asset, decimals, sender).log(); + TotalSupplyEvent::new(asset, supply, sender).log(); } } diff --git a/examples/src20-native-asset/single_asset/src/single_asset.sw b/examples/src20-native-asset/single_asset/src/single_asset.sw index 81b0cdf5..f06089a7 100644 --- a/examples/src20-native-asset/single_asset/src/single_asset.sw +++ b/examples/src20-native-asset/single_asset/src/single_asset.sw @@ -175,29 +175,12 @@ impl EmitSRC20Events for Contract { // Metadata that is stored as a configurable should only be emitted once. let asset = AssetId::default(); let sender = msg_sender().unwrap(); + let name = Some(String::from_ascii_str(from_str_array(NAME))); + let symbol = Some(String::from_ascii_str(from_str_array(SYMBOL))); - log(SetNameEvent { - asset, - name: Some(String::from_ascii_str(from_str_array(NAME))), - sender, - }); - - log(SetSymbolEvent { - asset, - symbol: Some(String::from_ascii_str(from_str_array(SYMBOL))), - sender, - }); - - log(SetDecimalsEvent { - asset, - decimals: DECIMALS, - sender, - }); - - log(TotalSupplyEvent { - asset, - supply: TOTAL_SUPPLY, - sender, - }); + SetNameEvent::new(asset, name, sender).log(); + SetSymbolEvent::new(asset, symbol, sender).log(); + SetDecimalsEvent::new(asset, DECIMALS, sender).log(); + TotalSupplyEvent::new(asset, TOTAL_SUPPLY, sender).log(); } } diff --git a/examples/src3-mint-burn/multi_asset/src/multi_asset.sw b/examples/src3-mint-burn/multi_asset/src/multi_asset.sw index 02e19670..32d1a47c 100644 --- a/examples/src3-mint-burn/multi_asset/src/multi_asset.sw +++ b/examples/src3-mint-burn/multi_asset/src/multi_asset.sw @@ -87,13 +87,10 @@ impl SRC3 for Contract { let new_supply = amount + asset_supply.unwrap_or(0); storage.total_supply.insert(asset_id, new_supply); - log(TotalSupplyEvent { - asset: asset_id, - supply: new_supply, - sender: msg_sender().unwrap(), - }); - mint_to(recipient, sub_id, amount); + + TotalSupplyEvent::new(asset_id, new_supply, msg_sender().unwrap()) + .log(); } /// Unconditionally burns assets sent with the `sub_id` sub-identifier. @@ -136,10 +133,13 @@ impl SRC3 for Contract { require(msg_asset_id() == asset_id, "Incorrect asset provided"); // Decrement total supply of the asset and burn. - storage - .total_supply - .insert(asset_id, storage.total_supply.get(asset_id).read() - amount); + let new_supply = storage.total_supply.get(asset_id).read() - amount; + storage.total_supply.insert(asset_id, new_supply); + burn(sub_id, amount); + + TotalSupplyEvent::new(asset_id, new_supply, msg_sender().unwrap()) + .log(); } } @@ -194,23 +194,11 @@ impl SetSRC20Data for Contract { revert(0); } let sender = msg_sender().unwrap(); + let name = Some(String::from_ascii_str(from_str_array(NAME))); + let symbol = Some(String::from_ascii_str(from_str_array(SYMBOL))); - log(SetNameEvent { - asset, - name: Some(String::from_ascii_str(from_str_array(NAME))), - sender, - }); - - log(SetSymbolEvent { - asset, - symbol: Some(String::from_ascii_str(from_str_array(SYMBOL))), - sender, - }); - - log(SetDecimalsEvent { - asset, - decimals: DECIMALS, - sender, - }); + SetNameEvent::new(asset, name, sender).log(); + SetSymbolEvent::new(asset, symbol, sender).log(); + SetDecimalsEvent::new(asset, DECIMALS, sender).log(); } } diff --git a/examples/src3-mint-burn/single_asset/src/single_asset.sw b/examples/src3-mint-burn/single_asset/src/single_asset.sw index 237d0505..6f9ac24e 100644 --- a/examples/src3-mint-burn/single_asset/src/single_asset.sw +++ b/examples/src3-mint-burn/single_asset/src/single_asset.sw @@ -78,13 +78,10 @@ impl SRC3 for Contract { let new_supply = amount + storage.total_supply.read(); storage.total_supply.write(new_supply); - log(TotalSupplyEvent { - asset: AssetId::new(ContractId::this(), DEFAULT_SUB_ID), - supply: new_supply, - sender: msg_sender().unwrap(), - }); - mint_to(recipient, DEFAULT_SUB_ID, amount); + + TotalSupplyEvent::new(AssetId::default(), new_supply, msg_sender().unwrap()) + .log(); } /// Unconditionally burns assets sent with the default SubId. @@ -131,10 +128,13 @@ impl SRC3 for Contract { ); // Decrement total supply of the asset and burn. - storage - .total_supply - .write(storage.total_supply.read() - amount); + let new_supply = storage.total_supply.read() - amount; + storage.total_supply.write(new_supply); + burn(DEFAULT_SUB_ID, amount); + + TotalSupplyEvent::new(AssetId::default(), new_supply, msg_sender().unwrap()) + .log(); } } @@ -191,23 +191,11 @@ impl EmitSRC20Events for Contract { // Metadata that is stored as a configurable should only be emitted once. let asset = AssetId::default(); let sender = msg_sender().unwrap(); + let name = Some(String::from_ascii_str(from_str_array(NAME))); + let symbol = Some(String::from_ascii_str(from_str_array(SYMBOL))); - log(SetNameEvent { - asset, - name: Some(String::from_ascii_str(from_str_array(NAME))), - sender, - }); - - log(SetSymbolEvent { - asset, - symbol: Some(String::from_ascii_str(from_str_array(SYMBOL))), - sender, - }); - - log(SetDecimalsEvent { - asset, - decimals: DECIMALS, - sender, - }); + SetNameEvent::new(asset, name, sender).log(); + SetSymbolEvent::new(asset, symbol, sender).log(); + SetDecimalsEvent::new(asset, DECIMALS, sender).log(); } } diff --git a/examples/src5-ownership/initialized_example/src/initialized_example.sw b/examples/src5-ownership/initialized_example/src/initialized_example.sw index f9cfe608..a87f2225 100644 --- a/examples/src5-ownership/initialized_example/src/initialized_example.sw +++ b/examples/src5-ownership/initialized_example/src/initialized_example.sw @@ -3,6 +3,7 @@ contract; use standards::src5::{SRC5, State}; /// The owner of this contract at deployment. +#[allow(dead_code)] const INITIAL_OWNER: Identity = Identity::Address(Address::zero()); storage { @@ -30,7 +31,7 @@ impl SRC5 for Contract { /// let ownership_abi = abi(contract_id, SRC_5); /// /// match ownership_abi.owner() { - /// State::Initialized(owner) => log("The ownership is initalized"), + /// State::Initialized(owner) => log("The ownership is initialized"), /// _ => log("This example will never reach this statement"), /// } /// } diff --git a/examples/src5-ownership/uninitialized_example/src/uninitialized_example.sw b/examples/src5-ownership/uninitialized_example/src/uninitialized_example.sw index 454f975e..6811305d 100644 --- a/examples/src5-ownership/uninitialized_example/src/uninitialized_example.sw +++ b/examples/src5-ownership/uninitialized_example/src/uninitialized_example.sw @@ -27,7 +27,7 @@ impl SRC5 for Contract { /// let ownership_abi = abi(contract_id, SRC_5); /// /// match ownership_abi.owner() { - /// State::Uninitalized => log("The ownership is uninitalized"), + /// State::Uninitialized => log("The ownership is uninitialized"), /// _ => log("This example will never reach this statement"), /// } /// } diff --git a/examples/src6-vault/multi_asset_vault/src/main.sw b/examples/src6-vault/multi_asset_vault/src/main.sw index b0a8f052..ac964e37 100644 --- a/examples/src6-vault/multi_asset_vault/src/main.sw +++ b/examples/src6-vault/multi_asset_vault/src/main.sw @@ -61,14 +61,16 @@ impl SRC6 for Contract { vault_info.managed_assets = vault_info.managed_assets + asset_amount; storage.vault_info.insert(share_asset, vault_info); - log(Deposit { - caller: msg_sender().unwrap(), + Deposit::new( + msg_sender() + .unwrap(), receiver, underlying_asset, vault_sub_id, - deposited_amount: asset_amount, - minted_shares: shares, - }); + asset_amount, + shares, + ) + .log(); shares } @@ -96,14 +98,16 @@ impl SRC6 for Contract { transfer(receiver, underlying_asset, assets); - log(Withdraw { - caller: msg_sender().unwrap(), + Withdraw::new( + msg_sender() + .unwrap(), receiver, underlying_asset, vault_sub_id, - withdrawn_amount: assets, - burned_shares: shares, - }); + assets, + shares, + ) + .log(); assets } @@ -116,18 +120,26 @@ impl SRC6 for Contract { #[storage(read)] fn max_depositable( - receiver: Identity, + _receiver: Identity, underlying_asset: AssetId, vault_sub_id: SubId, ) -> Option { + let vault_share_asset = vault_asset_id(underlying_asset, vault_sub_id).0; // This is the max value of u64 minus the current managed_assets. Ensures that the sum will always be lower than u64::MAX. - Some(u64::max() - managed_assets(underlying_asset)) + match storage.vault_info.get(vault_share_asset).try_read() { + Some(vault_info) => Some(u64::max() - vault_info.managed_assets), + None => None, + } } #[storage(read)] fn max_withdrawable(underlying_asset: AssetId, vault_sub_id: SubId) -> Option { - // In this implementation total_assets and max_withdrawable are the same. However in case of lending out of assets, total_assets should be greater than max_withdrawable. - Some(managed_assets(underlying_asset)) + let vault_share_asset = vault_asset_id(underlying_asset, vault_sub_id).0; + // In this implementation managed_assets and max_withdrawable are the same. However in case of lending out of assets, total_assets should be greater than max_withdrawable. + match storage.vault_info.get(vault_share_asset).try_read() { + Some(vault_info) => Some(vault_info.managed_assets), + None => None, + } } } @@ -166,8 +178,8 @@ fn vault_asset_id(asset: AssetId, vault_sub_id: SubId) -> (AssetId, SubId) { } #[storage(read)] -fn managed_assets(share_asset: AssetId) -> u64 { - match storage.vault_info.get(share_asset).try_read() { +fn managed_assets(vault_share_asset_id: AssetId) -> u64 { + match storage.vault_info.get(vault_share_asset_id).try_read() { Some(vault_info) => vault_info.managed_assets, None => 0, } diff --git a/examples/src6-vault/single_asset_single_sub_vault/src/main.sw b/examples/src6-vault/single_asset_single_sub_vault/src/main.sw index 51c2c488..32a43b9e 100644 --- a/examples/src6-vault/single_asset_single_sub_vault/src/main.sw +++ b/examples/src6-vault/single_asset_single_sub_vault/src/main.sw @@ -25,8 +25,6 @@ storage { managed_assets: u64 = 0, /// The total amount of shares minted by this vault. total_supply: u64 = 0, - /// Whether the vault shares have been minted. - minted: bool = false, } impl SRC6 for Contract { @@ -48,14 +46,16 @@ impl SRC6 for Contract { .managed_assets .write(storage.managed_assets.read() + asset_amount); - log(Deposit { - caller: msg_sender().unwrap(), + Deposit::new( + msg_sender() + .unwrap(), receiver, underlying_asset, vault_sub_id, - deposited_amount: asset_amount, - minted_shares: shares, - }); + asset_amount, + shares, + ) + .log(); shares } @@ -86,14 +86,16 @@ impl SRC6 for Contract { transfer(receiver, underlying_asset, assets); - log(Withdraw { - caller: msg_sender().unwrap(), + Withdraw::new( + msg_sender() + .unwrap(), receiver, underlying_asset, vault_sub_id, - withdrawn_amount: assets, - burned_shares: shares, - }); + assets, + shares, + ) + .log(); assets } @@ -110,11 +112,11 @@ impl SRC6 for Contract { #[storage(read)] fn max_depositable( - receiver: Identity, + _receiver: Identity, underlying_asset: AssetId, vault_sub_id: SubId, ) -> Option { - if underlying_asset == AssetId::base() { + if underlying_asset == AssetId::base() && vault_sub_id == ACCEPTED_SUB_VAULT { // This is the max value of u64 minus the current managed_assets. Ensures that the sum will always be lower than u64::MAX. Some(u64::max() - storage.managed_assets.read()) } else { @@ -124,7 +126,7 @@ impl SRC6 for Contract { #[storage(read)] fn max_withdrawable(underlying_asset: AssetId, vault_sub_id: SubId) -> Option { - if underlying_asset == AssetId::base() { + if underlying_asset == AssetId::base() && vault_sub_id == ACCEPTED_SUB_VAULT { // In this implementation managed_assets and max_withdrawable are the same. However in case of lending out of assets, managed_assets should be greater than max_withdrawable. Some(storage.managed_assets.read()) } else { @@ -150,17 +152,29 @@ impl SRC20 for Contract { #[storage(read)] fn name(asset: AssetId) -> Option { - Some(String::from_ascii_str("Vault Shares")) + if asset == vault_assetid() { + Some(String::from_ascii_str("Vault Shares")) + } else { + None + } } #[storage(read)] fn symbol(asset: AssetId) -> Option { - Some(String::from_ascii_str("VLTSHR")) + if asset == vault_assetid() { + Some(String::from_ascii_str("VLTSHR")) + } else { + None + } } #[storage(read)] fn decimals(asset: AssetId) -> Option { - Some(9_u8) + if asset == vault_assetid() { + Some(9_u8) + } else { + None + } } } diff --git a/examples/src6-vault/single_asset_vault/src/main.sw b/examples/src6-vault/single_asset_vault/src/main.sw index c1f52e0d..2a282b5f 100644 --- a/examples/src6-vault/single_asset_vault/src/main.sw +++ b/examples/src6-vault/single_asset_vault/src/main.sw @@ -62,14 +62,16 @@ impl SRC6 for Contract { vault_info.managed_assets = vault_info.managed_assets + asset_amount; storage.vault_info.insert(share_asset, vault_info); - log(Deposit { - caller: msg_sender().unwrap(), - receiver: receiver, + Deposit::new( + msg_sender() + .unwrap(), + receiver, underlying_asset, - vault_sub_id: vault_sub_id, - deposited_amount: asset_amount, - minted_shares: shares, - }); + vault_sub_id, + asset_amount, + shares, + ) + .log(); shares } @@ -97,14 +99,16 @@ impl SRC6 for Contract { transfer(receiver, underlying_asset, assets); - log(Withdraw { - caller: msg_sender().unwrap(), - receiver: receiver, + Withdraw::new( + msg_sender() + .unwrap(), + receiver, underlying_asset, - vault_sub_id: vault_sub_id, - withdrawn_amount: assets, - burned_shares: shares, - }); + vault_sub_id, + assets, + shares, + ) + .log(); assets } @@ -122,25 +126,33 @@ impl SRC6 for Contract { #[storage(read)] fn max_depositable( - receiver: Identity, + _receiver: Identity, underlying_asset: AssetId, vault_sub_id: SubId, ) -> Option { - if underlying_asset == AssetId::base() { + let vault_share_asset = vault_asset_id(underlying_asset, vault_sub_id).0; + + match ( + underlying_asset == AssetId::base(), + storage.vault_info.get(vault_share_asset).try_read(), + ) { // This is the max value of u64 minus the current managed_assets. Ensures that the sum will always be lower than u64::MAX. - Some(u64::max() - managed_assets(underlying_asset)) - } else { - None + (true, Some(vault_info)) => Some(u64::max() - vault_info.managed_assets), + _ => None, } } #[storage(read)] fn max_withdrawable(underlying_asset: AssetId, vault_sub_id: SubId) -> Option { - if underlying_asset == AssetId::base() { - // In this implementation total_assets and max_withdrawable are the same. However in case of lending out of assets, total_assets should be greater than max_withdrawable. - Some(managed_assets(underlying_asset)) - } else { - None + let vault_share_asset = vault_asset_id(underlying_asset, vault_sub_id).0; + + match ( + underlying_asset == AssetId::base(), + storage.vault_info.get(vault_share_asset).try_read(), + ) { + // In this implementation managed_assets and max_withdrawable are the same. However in case of lending out of assets, total_assets should be greater than max_withdrawable. + (true, Some(vault_info)) => Some(vault_info.managed_assets), + _ => None, } } } @@ -180,8 +192,8 @@ fn vault_asset_id(underlying_asset: AssetId, vault_sub_id: SubId) -> (AssetId, S } #[storage(read)] -fn managed_assets(share_asset: AssetId) -> u64 { - match storage.vault_info.get(share_asset).try_read() { +fn managed_assets(vault_share_asset_id: AssetId) -> u64 { + match storage.vault_info.get(vault_share_asset_id).try_read() { Some(vault_info) => vault_info.managed_assets, None => 0, } diff --git a/examples/src7-metadata/multi_asset/src/multi_asset.sw b/examples/src7-metadata/multi_asset/src/multi_asset.sw index dfc880d5..7d629f47 100644 --- a/examples/src7-metadata/multi_asset/src/multi_asset.sw +++ b/examples/src7-metadata/multi_asset/src/multi_asset.sw @@ -115,38 +115,29 @@ impl SetSRC7Events for Contract { if storage.total_supply.get(asset).try_read().is_none() { revert(0); } - let sender = msg_sender().unwrap(); - - log(SetMetadataEvent { - asset, - metadata: Some(Metadata::String(String::from_ascii_str(from_str_array(SOCIAL_X)))), - key: String::from_ascii_str("social:x"), - sender, - }); - - log(SetMetadataEvent { - asset, - metadata: Some(Metadata::String(String::from_ascii_str(from_str_array(SITE_FORUM)))), - key: String::from_ascii_str("site:forum"), - sender, - }); storage.svg_images.try_insert(asset, StorageString {}); storage.svg_images.get(asset).write_slice(svg_image); - log(SetMetadataEvent { - asset, - metadata: Some(Metadata::String(svg_image)), - key: String::from_ascii_str("image:svg"), - sender, - }); - storage.health_attributes.insert(asset, health_attribute); - log(SetMetadataEvent { - asset, - metadata: Some(Metadata::Int(health_attribute)), - key: String::from_ascii_str("attr:health"), - sender, - }); + + let sender = msg_sender().unwrap(); + let metadata_1 = Some(Metadata::String(String::from_ascii_str(from_str_array(SOCIAL_X)))); + let metadata_2 = Some(Metadata::String(String::from_ascii_str(from_str_array(SITE_FORUM)))); + let metadata_3 = Some(Metadata::String(svg_image)); + let metadata_4 = Some(Metadata::Int(health_attribute)); + let key_1 = String::from_ascii_str("social:x"); + let key_2 = String::from_ascii_str("site:forum"); + let key_3 = String::from_ascii_str("image:svg"); + let key_4 = String::from_ascii_str("attr:health"); + + SetMetadataEvent::new(asset, metadata_1, key_1, sender) + .log(); + SetMetadataEvent::new(asset, metadata_2, key_2, sender) + .log(); + SetMetadataEvent::new(asset, metadata_3, key_3, sender) + .log(); + SetMetadataEvent::new(asset, metadata_4, key_4, sender) + .log(); } } @@ -195,29 +186,12 @@ impl SetSRC20Data for Contract { fn set_src20_data(asset: AssetId, supply: u64) { // NOTE: There are no checks for if the caller has permissions to update the metadata let sender = msg_sender().unwrap(); + let name = Some(String::from_ascii_str(from_str_array(NAME))); + let symbol = Some(String::from_ascii_str(from_str_array(SYMBOL))); - log(SetNameEvent { - asset, - name: Some(String::from_ascii_str(from_str_array(NAME))), - sender, - }); - - log(SetSymbolEvent { - asset, - symbol: Some(String::from_ascii_str(from_str_array(SYMBOL))), - sender, - }); - - log(SetDecimalsEvent { - asset, - decimals: DECIMALS, - sender, - }); - - log(TotalSupplyEvent { - asset, - supply, - sender, - }); + SetNameEvent::new(asset, name, sender).log(); + SetSymbolEvent::new(asset, symbol, sender).log(); + SetDecimalsEvent::new(asset, DECIMALS, sender).log(); + TotalSupplyEvent::new(asset, supply, sender).log(); } } diff --git a/examples/src7-metadata/single_asset/src/single_asset.sw b/examples/src7-metadata/single_asset/src/single_asset.sw index 9e68bc17..0f68125d 100644 --- a/examples/src7-metadata/single_asset/src/single_asset.sw +++ b/examples/src7-metadata/single_asset/src/single_asset.sw @@ -87,27 +87,19 @@ impl EmitSRC7Events for Contract { fn emit_src7_events() { let asset = AssetId::default(); let sender = msg_sender().unwrap(); - - log(SetMetadataEvent { - asset, - metadata: Some(Metadata::String(String::from_ascii_str(from_str_array(SOCIAL_X)))), - key: String::from_ascii_str("social:x"), - sender, - }); - - log(SetMetadataEvent { - asset, - metadata: Some(Metadata::String(String::from_ascii_str(from_str_array(SITE_FORUM)))), - key: String::from_ascii_str("site:forum"), - sender, - }); - - log(SetMetadataEvent { - asset, - metadata: Some(Metadata::Int(ATTR_HEALTH)), - key: String::from_ascii_str("attr:health"), - sender, - }); + let metadata_1 = Some(Metadata::String(String::from_ascii_str(from_str_array(SOCIAL_X)))); + let metadata_2 = Some(Metadata::String(String::from_ascii_str(from_str_array(SITE_FORUM)))); + let metadata_3 = Some(Metadata::Int(ATTR_HEALTH)); + let key_1 = String::from_ascii_str("social:x"); + let key_2 = String::from_ascii_str("site:forum"); + let key_3 = String::from_ascii_str("attr:health"); + + SetMetadataEvent::new(asset, metadata_1, key_1, sender) + .log(); + SetMetadataEvent::new(asset, metadata_2, key_2, sender) + .log(); + SetMetadataEvent::new(asset, metadata_3, key_3, sender) + .log(); } } @@ -164,29 +156,12 @@ impl EmitSRC20Events for Contract { // Metadata that is stored as a configurable should only be emitted once. let asset = AssetId::default(); let sender = msg_sender().unwrap(); + let name = Some(String::from_ascii_str(from_str_array(NAME))); + let symbol = Some(String::from_ascii_str(from_str_array(SYMBOL))); - log(SetNameEvent { - asset, - name: Some(String::from_ascii_str(from_str_array(NAME))), - sender, - }); - - log(SetSymbolEvent { - asset, - symbol: Some(String::from_ascii_str(from_str_array(SYMBOL))), - sender, - }); - - log(SetDecimalsEvent { - asset, - decimals: DECIMALS, - sender, - }); - - log(TotalSupplyEvent { - asset, - supply: TOTAL_SUPPLY, - sender, - }); + SetNameEvent::new(asset, name, sender).log(); + SetSymbolEvent::new(asset, symbol, sender).log(); + SetDecimalsEvent::new(asset, DECIMALS, sender).log(); + TotalSupplyEvent::new(asset, TOTAL_SUPPLY, sender).log(); } } diff --git a/standards/src/src10.sw b/standards/src/src10.sw index 0ec76353..f6445fc8 100644 --- a/standards/src/src10.sw +++ b/standards/src/src10.sw @@ -13,7 +13,7 @@ pub enum DepositType { } /// Enscapsultes metadata sent between the canonical chain and Fuel when a deposit is made. -struct DepositMessage { +pub struct DepositMessage { /// The number of tokens. #[allow(dead_code)] pub amount: b256, @@ -58,10 +58,10 @@ abi SRC10 { /// # Examples /// /// ```sway - /// use src10::SRC10; + /// use standards::src10::SRC10; /// /// fn foo(message_index: u64, bridge: ContractId) { - /// let bridge_abi = abi(SRC10, bridge.value); + /// let bridge_abi = abi(SRC10, bridge.bits()); /// bridge_abi.process_message(message_index); /// } /// ``` @@ -79,10 +79,10 @@ abi SRC10 { /// # Examples /// /// ```sway - /// use src10::SRC10; + /// use standards::src10::SRC10; /// /// fn foo(to_address: b256, bridge: ContractId, bridged_asset: AssetId) { - /// let bridge_abi = abi(SRC10, bridge.value); + /// let bridge_abi = abi(SRC10, bridge.bits()); /// bridge_abi { /// gas: 10000, /// coins: 100, @@ -105,10 +105,10 @@ abi SRC10 { /// # Examples /// /// ```sway - /// use src10::SRC10; + /// use standards::src10::SRC10; /// /// fn foo(to_address: b256, token_address: b256, token_id: b256, gateway_contract: b256, bridge: ContractId) { - /// let bridge_abi = abi(SRC10, bridge.value); + /// let bridge_abi = abi(SRC10, bridge.bits()); /// bridge_abi.claim_refund(to_address, token_address, token_id, gateway_contract); /// } /// ``` @@ -120,3 +120,538 @@ abi SRC10 { gateway_contract: b256, ); } + +impl core::ops::Eq for DepositType { + fn eq(self, other: Self) -> bool { + match (self, other) { + (Self::Address, Self::Address) => true, + (Self::Contract, Self::Contract) => true, + (Self::ContractWithData, Self::ContractWithData) => true, + _ => false, + } + } +} + +impl core::ops::Eq for DepositMessage { + fn eq(self, other: Self) -> bool { + self.amount == other.amount && self.from == other.from && self.to == other.to && self.token_address == other.token_address && self.token_id == other.token_id && self.decimals == other.decimals && self.deposit_type == other.deposit_type + } +} + +impl core::ops::Eq for MetadataMessage { + fn eq(self, other: Self) -> bool { + self.token_address == other.token_address && self.token_id == other.token_id && self.name == other.name && self.symbol == other.symbol + } +} + +impl DepositMessage { + /// Returns a new `DepositMessage`. + /// + /// # Arguments + /// + /// * `amount`: [b256] - The number of tokens. + /// * `from`: [b256] - The user's address on the canonical chain. + /// * `to`: [Identity] - The bridging target destination on the Fuel chain. + /// * `token_address`: [b256] - The bridged token's address on the canonical chain. + /// * `token_id`: [b256] - The token's ID on the canonical chain. + /// * `decimals`: [u8] - The decimals of the token. + /// * `deposit_type`: [DepositType] - The type of deposit made. + /// + /// # Returns + /// + /// * [DepositMessage] - The newly created `DepositMessage`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src10::DepositMessage; + /// + /// fn foo( + /// amount: b256, + /// from: b256, + /// to: Identity, + /// token_address: b256, + /// token_id: b256, + /// decimals: u8, + /// deposit_type: DepositType + /// ) { + /// let deposit_message = DepositMessage::new( + /// amount, + /// from, + /// to, + /// token_address, + /// token_id, + /// decimals, + /// deposit_type + /// ); + /// assert(deposit_message.amount == amount); + /// assert(deposit_message.from == from); + /// assert(deposit_message.to == to); + /// assert(deposit_message.token_address == token_address); + /// assert(deposit_message.token_id == token_id); + /// assert(deposit_message.decimals == decimals); + /// assert(deposit_message.deposit_type == deposit_type); + /// } + /// ``` + pub fn new( + amount: b256, + from: b256, + to: Identity, + token_address: b256, + token_id: b256, + decimals: u8, + deposit_type: DepositType, + ) -> Self { + Self { + amount, + from, + to, + token_address, + token_id, + decimals, + deposit_type, + } + } + + /// Returns the `amount` of the `DepositMessage`. + /// + /// # Returns + /// + /// * [b256] - The amount for the deposit message. + /// + /// # Examples + /// + /// ```sway + /// use standards::src10::DepositMessage; + /// + /// fn foo( + /// amount: b256, + /// from: b256, + /// to: Identity, + /// token_address: b256, + /// token_id: b256, + /// decimals: u8, + /// deposit_type: DepositType + /// ) { + /// let deposit_message = DepositMessage::new( + /// amount, + /// from, + /// to, + /// token_address, + /// token_id, + /// decimals, + /// deposit_type + /// ); + /// assert(deposit_message.amount() == amount); + /// } + /// ``` + pub fn amount(self) -> b256 { + self.amount + } + + /// Returns the `from` of the `DepositMessage`. + /// + /// # Returns + /// + /// * [b256] - The from address for the deposit message. + /// + /// # Examples + /// + /// ```sway + /// use standards::src10::DepositMessage; + /// + /// fn foo( + /// amount: b256, + /// from: b256, + /// to: Identity, + /// token_address: b256, + /// token_id: b256, + /// decimals: u8, + /// deposit_type: DepositType + /// ) { + /// let deposit_message = DepositMessage::new( + /// amount, + /// from, + /// to, + /// token_address, + /// token_id, + /// decimals, + /// deposit_type + /// ); + /// assert(deposit_message.from() == from); + /// } + /// ``` + pub fn from(self) -> b256 { + self.from + } + + /// Returns the `to` of the `DepositMessage`. + /// + /// # Returns + /// + /// * [Identity] - The to `Identity` for the deposit message. + /// + /// # Examples + /// + /// ```sway + /// use standards::src10::DepositMessage; + /// + /// fn foo( + /// amount: b256, + /// from: b256, + /// to: Identity, + /// token_address: b256, + /// token_id: b256, + /// decimals: u8, + /// deposit_type: DepositType + /// ) { + /// let deposit_message = DepositMessage::new( + /// amount, + /// from, + /// to, + /// token_address, + /// token_id, + /// decimals, + /// deposit_type + /// ); + /// assert(deposit_message.to() == to); + /// } + /// ``` + pub fn to(self) -> Identity { + self.to + } + + /// Returns the `token_address` of the `DepositMessage`. + /// + /// # Returns + /// + /// * [b256] - The token address for the deposit message. + /// + /// # Examples + /// + /// ```sway + /// use standards::src10::DepositMessage; + /// + /// fn foo( + /// amount: b256, + /// from: b256, + /// to: Identity, + /// token_address: b256, + /// token_id: b256, + /// decimals: u8, + /// deposit_type: DepositType + /// ) { + /// let deposit_message = DepositMessage::new( + /// amount, + /// from, + /// to, + /// token_address, + /// token_id, + /// decimals, + /// deposit_type + /// ); + /// assert(deposit_message.token_address() == token_address); + /// } + /// ``` + pub fn token_address(self) -> b256 { + self.token_address + } + + /// Returns the `token_id` of the `DepositMessage`. + /// + /// # Returns + /// + /// * [b256] - The token id for the deposit message. + /// + /// # Examples + /// + /// ```sway + /// use standards::src10::DepositMessage; + /// + /// fn foo( + /// amount: b256, + /// from: b256, + /// to: Identity, + /// token_address: b256, + /// token_id: b256, + /// decimals: u8, + /// deposit_type: DepositType + /// ) { + /// let deposit_message = DepositMessage::new( + /// amount, + /// from, + /// to, + /// token_address, + /// token_id, + /// decimals, + /// deposit_type + /// ); + /// assert(deposit_message.token_id() == token_id); + /// } + /// ``` + pub fn token_id(self) -> b256 { + self.token_id + } + + /// Returns the `decimals` of the `DepositMessage`. + /// + /// # Returns + /// + /// * [u8] - The decimals for the deposit message. + /// + /// # Examples + /// + /// ```sway + /// use standards::src10::DepositMessage; + /// + /// fn foo( + /// amount: b256, + /// from: b256, + /// to: Identity, + /// token_address: b256, + /// token_id: b256, + /// decimals: u8, + /// deposit_type: DepositType + /// ) { + /// let deposit_message = DepositMessage::new( + /// amount, + /// from, + /// to, + /// token_address, + /// token_id, + /// decimals, + /// deposit_type + /// ); + /// assert(deposit_message.decimals() == decimals); + /// } + /// ``` + pub fn decimals(self) -> u8 { + self.decimals + } + + /// Returns the `deposit_type` of the `DepositMessage`. + /// + /// # Returns + /// + /// * [DepositType] - The deposit type for the deposit message. + /// + /// # Examples + /// + /// ```sway + /// use standards::src10::DepositMessage; + /// + /// fn foo( + /// amount: b256, + /// from: b256, + /// to: Identity, + /// token_address: b256, + /// token_id: b256, + /// decimals: u8, + /// deposit_type: DepositType + /// ) { + /// let deposit_message = DepositMessage::new( + /// amount, + /// from, + /// to, + /// token_address, + /// token_id, + /// decimals, + /// deposit_type + /// ); + /// assert(deposit_message.deposit_type() == deposit_type); + /// } + /// ``` + pub fn deposit_type(self) -> DepositType { + self.deposit_type + } +} + +impl MetadataMessage { + /// Returns a new `MetadataMessage`. + /// + /// # Arguments + /// + /// * `token_address`: [b256] - The bridged token's address on the canonical chain. + /// * `token_id`: [b256] - The token's ID on the canonical chain. + /// * `name`: [String] - The bridged token's name on the canonical chain. + /// * `symbol`: [String] - The bridged token's symbol on the canonical chain. + /// + /// # Returns + /// + /// * [MetadataMessage] - The newly created `MetadataMessage`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src10::MetadataMessage; + /// + /// fn foo(token_address: b256, token_id: b256, name: String, symbol: String) { + /// let metadata_message = MetadataMessage::new(token_address, token_id, name, symbol); + /// assert(metadata_message.token_address == token_address); + /// assert(metadata_message.token_id == token_id); + /// assert(deposit_message.name == name); + /// assert(deposit_message.symbol == symbol); + /// } + /// ``` + pub fn new( + token_address: b256, + token_id: b256, + name: String, + symbol: String, + ) -> Self { + Self { + token_address, + token_id, + name, + symbol, + } + } + + /// Returns the `token_address` of the `MetadataMessage`. + /// + /// # Returns + /// + /// * [b256] - The token address for the metdata message. + /// + /// # Examples + /// + /// ```sway + /// use standards::src10::MetadataMessage; + /// + /// fn foo(token_address: b256, token_id: b256, name: String, symbol: String) { + /// let metadata_message = MetadataMessage::new(token_address, token_id, name, symbol); + /// assert(metadata_message.token_address() == token_address); + /// } + /// ``` + pub fn token_address(self) -> b256 { + self.token_address + } + + /// Returns the `token_id` of the `MetadataMessage`. + /// + /// # Returns + /// + /// * [b256] - The token id for the metdata message. + /// + /// # Examples + /// + /// ```sway + /// use standards::src10::MetadataMessage; + /// + /// fn foo(token_address: b256, token_id: b256, name: String, symbol: String) { + /// let metadata_message = MetadataMessage::new(token_address, token_id, name, symbol); + /// assert(metadata_message.token_id() == token_id); + /// } + /// ``` + pub fn token_id(self) -> b256 { + self.token_id + } + + /// Returns the `name` of the `MetadataMessage`. + /// + /// # Returns + /// + /// * [String] - The name for the metdata message. + /// + /// # Examples + /// + /// ```sway + /// use standards::src10::MetadataMessage; + /// + /// fn foo(token_address: b256, token_id: b256, name: String, symbol: String) { + /// let metadata_message = MetadataMessage::new(token_address, token_id, name, symbol); + /// assert(metadata_message.name() == name); + /// } + /// ``` + pub fn name(self) -> String { + self.name + } + + /// Returns the `symbol` of the `MetadataMessage`. + /// + /// # Returns + /// + /// * [String] - The symbol for the metdata message. + /// + /// # Examples + /// + /// ```sway + /// use standards::src10::MetadataMessage; + /// + /// fn foo(token_address: b256, token_id: b256, name: String, symbol: String) { + /// let metadata_message = MetadataMessage::new(token_address, token_id, name, symbol); + /// assert(metadata_message.symbol() == symbol); + /// } + /// ``` + pub fn symbol(self) -> String { + self.symbol + } +} + +impl DepositType { + /// Returns whether the deposit type is an address. + /// + /// # Return Values + /// + /// * [bool] - `true` if the deposit type is an address, otherwise `false`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src10::DepositType; + /// + /// fn foo(deposit_type: DepositType) { + /// assert(DepositType.is_address()); + /// } + /// ``` + pub fn is_address(self) -> bool { + match self { + Self::Address => true, + _ => false, + } + } + + /// Returns whether the deposit type is a contract. + /// + /// # Return Values + /// + /// * [bool] - `true` if the deposit type is a contract, otherwise `false`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src10::DepositType; + /// + /// fn foo(deposit_type: DepositType) { + /// assert(DepositType.is_contract()); + /// } + /// ``` + pub fn is_contract(self) -> bool { + match self { + Self::Contract => true, + _ => false, + } + } + + /// Returns whether the deposit type is a contract with data. + /// + /// # Return Values + /// + /// * [bool] - `true` if the deposit type is a contract with data, otherwise `false`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src10::DepositType; + /// + /// fn foo(deposit_type: DepositType) { + /// assert(DepositType.is_contract_with_data()); + /// } + /// ``` + pub fn is_contract_with_data(self) -> bool { + match self { + Self::ContractWithData => true, + _ => false, + } + } +} diff --git a/standards/src/src11.sw b/standards/src/src11.sw index 3c640a10..6541a90e 100644 --- a/standards/src/src11.sw +++ b/standards/src/src11.sw @@ -46,3 +46,728 @@ abi SRC11 { #[storage(read)] fn security_information() -> SecurityInformation; } + +impl core::ops::Eq for SecurityInformation { + fn eq(self, other: Self) -> bool { + // If both contact info contain data, check each string + let self_contact_information_len = self.contact_information.len(); + let other_contact_information_len = other.contact_information.len(); + if self_contact_information_len > 0 && other_contact_information_len > 0 { + // Check each string matches + let mut iter = 0; + while iter < self_contact_information_len { + if self.contact_information.get(iter) != other.contact_information.get(iter) + { + return false; + } + iter += 1; + } + } else if !(self_contact_information_len == 0 && self_contact_information_len == 0) { // Otherwise both must contain nothing + return false; + } + + // If both prefered languages info contain data, check each string + if self.preferred_languages.is_some() && other.preferred_languages.is_some() { + let self_preferred_languages = self.preferred_languages.unwrap(); + let other_preferred_languages = self.preferred_languages.unwrap(); + + let self_preferred_languages_len = self_preferred_languages.len(); + let other_preferred_languages_len = other_preferred_languages.len(); + // If lengths do not match, we do not need to iterate over the strings + if self_preferred_languages_len != other_preferred_languages_len + { + return false; + } + + // Check each string matches + let mut iter = 0; + while iter < self_preferred_languages_len { + if self_preferred_languages.get(iter) != other_preferred_languages.get(iter) + { + return false; + } + iter += 1; + } + } else if !(self.preferred_languages.is_none() && other.preferred_languages.is_none()) { // Otherwise both must be none + return false; + } + + // If both auditors info contain data, check each string + if self.auditors.is_some() && other.auditors.is_some() { + let self_auditors = self.auditors.unwrap(); + let other_auditors = self.auditors.unwrap(); + + let self_auditors_len = self_auditors.len(); + let other_auditors_len = other_auditors.len(); + // If lengths do not match, we do not need to iterate over the strings + if self_auditors_len != other_auditors_len { + return false; + } + + // Check each string matches + let mut iter = 0; + while iter < self_auditors_len { + if self_auditors.get(iter) != other_auditors.get(iter) { + return false; + } + iter += 1; + } + } else if !(self.auditors.is_none() && other.auditors.is_none()) { // Otherwise both must be none + return false; + } + + self.name == other.name && self.project_url == other.project_url && self.policy == other.policy && self.encryption == other.encryption && self.source_code == other.source_code && self.source_release == other.source_release && self.source_revision == other.source_revision && self.acknowledgments == other.acknowledgments && self.additional_information == other.additional_information + } +} + +impl SecurityInformation { + /// Returns a new `SecurityInformation`. + /// + /// # Arguments + /// + /// * `name`: [String] - Name of the project. + /// * `project_url`: [Option] - Website URL of the project. + /// * `contact_information`: [Vec] - List of contact information to contact developers of the project. + /// * `policy`: [String] - Text describing the project's security policy, or a link to it. + /// * `preferred_languages`: [Option>] - A list of preferred languages (ISO 639-1). + /// * `encryption`: [Option] - A PGP public key block (or similar) or a link to one. + /// * `source_code`: [Option] - A URL to the project's source code. + /// * `source_release`: [Option] - The release identifier of this build, ideally corresponding to a tag on git that can be rebuilt to reproduce the same binary. + /// * `source_revision`: [Option] - The revision identifier of this build, usually a git commit hash that can be rebuilt to reproduce the same binary. + /// * `auditors`: [Option>] - A list of people or entities that audited this smart contract, or links to pages where audit reports are hosted. + /// * `acknowledgments`: [Option] - Text containing acknowledgments to security researchers who have previously found vulnerabilities in the project, or a link to it. + /// * `additional_information`: [Option] - Text containing any additional information you want to provide, or a link to it. + /// + /// # Returns + /// + /// * [SecurityInformation] - The newly created `SecurityInformation`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src11::SecurityInformation; + /// + /// fn foo( + /// name: String, + /// project_url: Option, + /// contact_information: Vec, + /// policy: String, + /// preferred_languages: Option>, + /// encryption: Option, + /// source_code: Option, + /// source_release: Option, + /// source_revision: Option, + /// auditors: Option>, + /// acknowledgments: Option, + /// additional_information: Option, + /// ) { + /// let security_information = SecurityInformation::new( + /// name, + /// project_url, + /// contact_information, + /// policy, + /// preferred_languages, + /// encryption, + /// source_code, + /// source_release, + /// source_revision, + /// auditors, + /// acknowledgments, + /// additional_information, + /// ); + /// assert(security_information.name == name); + /// assert(security_information.project_url == project_url); + /// assert(security_information.contact_information == contact_information); + /// assert(security_information.policy == policy); + /// assert(security_information.preferred_languages == preferred_languages); + /// assert(security_information.encryption == encryption); + /// assert(security_information.source_code == source_code); + /// assert(security_information.source_release == source_release); + /// assert(security_information.source_revision == source_revision); + /// assert(security_information.auditors == auditors); + /// assert(security_information.acknowledgments == acknowledgments); + /// assert(security_information.additional_information == additional_information); + /// } + /// ``` + pub fn new( + name: String, + project_url: Option, + contact_information: Vec, + policy: String, + preferred_languages: Option>, + encryption: Option, + source_code: Option, + source_release: Option, + source_revision: Option, + auditors: Option>, + acknowledgments: Option, + additional_information: Option, + ) -> Self { + Self { + name, + project_url, + contact_information, + policy, + preferred_languages, + encryption, + source_code, + source_release, + source_revision, + auditors, + acknowledgments, + additional_information, + } + } + + /// Returns the `name` of the `SecurityInformation`. + /// + /// # Returns + /// + /// * `name`: [String] - Name of the project. + /// + /// # Examples + /// + /// ```sway + /// use standards::src11::SecurityInformation; + /// + /// fn foo( + /// name: String, + /// project_url: Option, + /// contact_information: Vec, + /// policy: String, + /// preferred_languages: Option>, + /// encryption: Option, + /// source_code: Option, + /// source_release: Option, + /// source_revision: Option, + /// auditors: Option>, + /// acknowledgments: Option, + /// additional_information: Option, + /// ) { + /// let security_information = SecurityInformation::new( + /// name, + /// project_url, + /// contact_information, + /// policy, + /// preferred_languages, + /// encryption, + /// source_code, + /// source_release, + /// source_revision, + /// auditors, + /// acknowledgments, + /// additional_information, + /// ); + /// assert(security_information.name() == name); + /// } + /// ``` + pub fn name(self) -> String { + self.name + } + + /// Returns the `project_url` of the `SecurityInformation`. + /// + /// # Returns + /// + /// * `project_url`: [Option] - Website URL of the project. + /// + /// # Examples + /// + /// ```sway + /// use standards::src11::SecurityInformation; + /// + /// fn foo( + /// name: String, + /// project_url: Option, + /// contact_information: Vec, + /// policy: String, + /// preferred_languages: Option>, + /// encryption: Option, + /// source_code: Option, + /// source_release: Option, + /// source_revision: Option, + /// auditors: Option>, + /// acknowledgments: Option, + /// additional_information: Option, + /// ) { + /// let security_information = SecurityInformation::new( + /// name, + /// project_url, + /// contact_information, + /// policy, + /// preferred_languages, + /// encryption, + /// source_code, + /// source_release, + /// source_revision, + /// auditors, + /// acknowledgments, + /// additional_information, + /// ); + /// assert(security_information.project_url() == project_url); + /// } + /// ``` + pub fn project_url(self) -> Option { + self.project_url + } + + /// Returns the `contact_information` of the `SecurityInformation`. + /// + /// # Returns + /// + /// * `contact_information`: [Vec] - List of contact information to contact developers of the project. + /// + /// # Examples + /// + /// ```sway + /// use standards::src11::SecurityInformation; + /// + /// fn foo( + /// name: String, + /// project_url: Option, + /// contact_information: Vec, + /// policy: String, + /// preferred_languages: Option>, + /// encryption: Option, + /// source_code: Option, + /// source_release: Option, + /// source_revision: Option, + /// auditors: Option>, + /// acknowledgments: Option, + /// additional_information: Option, + /// ) { + /// let security_information = SecurityInformation::new( + /// name, + /// project_url, + /// contact_information, + /// policy, + /// preferred_languages, + /// encryption, + /// source_code, + /// source_release, + /// source_revision, + /// auditors, + /// acknowledgments, + /// additional_information, + /// ); + /// assert(security_information.contact_information() == contact_information); + /// } + /// ``` + pub fn contact_information(self) -> Vec { + self.contact_information + } + + /// Returns the `policy` of the `SecurityInformation`. + /// + /// # Returns + /// + /// * `policy`: [String] - Text describing the project's security policy, or a link to it. + /// + /// # Examples + /// + /// ```sway + /// use standards::src11::SecurityInformation; + /// + /// fn foo( + /// name: String, + /// project_url: Option, + /// contact_information: Vec, + /// policy: String, + /// preferred_languages: Option>, + /// encryption: Option, + /// source_code: Option, + /// source_release: Option, + /// source_revision: Option, + /// auditors: Option>, + /// acknowledgments: Option, + /// additional_information: Option, + /// ) { + /// let security_information = SecurityInformation::new( + /// name, + /// project_url, + /// contact_information, + /// policy, + /// preferred_languages, + /// encryption, + /// source_code, + /// source_release, + /// source_revision, + /// auditors, + /// acknowledgments, + /// additional_information, + /// ); + /// assert(security_information.policy() == policy); + /// } + /// ``` + pub fn policy(self) -> String { + self.policy + } + + /// Returns the `preferred_languages` of the `SecurityInformation`. + /// + /// # Returns + /// + /// * `preferred_languages`: [Option>] - A list of preferred languages (ISO 639-1). + /// + /// # Examples + /// + /// ```sway + /// use standards::src11::SecurityInformation; + /// + /// fn foo( + /// name: String, + /// project_url: Option, + /// contact_information: Vec, + /// policy: String, + /// preferred_languages: Option>, + /// encryption: Option, + /// source_code: Option, + /// source_release: Option, + /// source_revision: Option, + /// auditors: Option>, + /// acknowledgments: Option, + /// additional_information: Option, + /// ) { + /// let security_information = SecurityInformation::new( + /// name, + /// project_url, + /// contact_information, + /// policy, + /// preferred_languages, + /// encryption, + /// source_code, + /// source_release, + /// source_revision, + /// auditors, + /// acknowledgments, + /// additional_information, + /// ); + /// assert(security_information.preferred_languages() == preferred_languages); + /// } + /// ``` + pub fn preferred_languages(self) -> Option> { + self.preferred_languages + } + + /// Returns the `encryption` of the `SecurityInformation`. + /// + /// # Returns + /// + /// * `encryption`: [Option] - A PGP public key block (or similar) or a link to one. + /// + /// # Examples + /// + /// ```sway + /// use standards::src11::SecurityInformation; + /// + /// fn foo( + /// name: String, + /// project_url: Option, + /// contact_information: Vec, + /// policy: String, + /// preferred_languages: Option>, + /// encryption: Option, + /// source_code: Option, + /// source_release: Option, + /// source_revision: Option, + /// auditors: Option>, + /// acknowledgments: Option, + /// additional_information: Option, + /// ) { + /// let security_information = SecurityInformation::new( + /// name, + /// project_url, + /// contact_information, + /// policy, + /// preferred_languages, + /// encryption, + /// source_code, + /// source_release, + /// source_revision, + /// auditors, + /// acknowledgments, + /// additional_information, + /// ); + /// assert(security_information.encryption() == encryption); + /// } + /// ``` + pub fn encryption(self) -> Option { + self.encryption + } + + /// Returns the `source_code` of the `SecurityInformation`. + /// + /// # Returns + /// + /// * `source_code`: [Option] - A URL to the project's source code. + /// + /// # Examples + /// + /// ```sway + /// use standards::src11::SecurityInformation; + /// + /// fn foo( + /// name: String, + /// project_url: Option, + /// contact_information: Vec, + /// policy: String, + /// preferred_languages: Option>, + /// encryption: Option, + /// source_code: Option, + /// source_release: Option, + /// source_revision: Option, + /// auditors: Option>, + /// acknowledgments: Option, + /// additional_information: Option, + /// ) { + /// let security_information = SecurityInformation::new( + /// name, + /// project_url, + /// contact_information, + /// policy, + /// preferred_languages, + /// encryption, + /// source_code, + /// source_release, + /// source_revision, + /// auditors, + /// acknowledgments, + /// additional_information, + /// ); + /// assert(security_information.source_code() == source_code); + /// } + /// ``` + pub fn source_code(self) -> Option { + self.source_code + } + + /// Returns the `source_release` of the `SecurityInformation`. + /// + /// # Returns + /// + /// * `source_release`: [Option] - The release identifier of this build, ideally corresponding to a tag on git that can be rebuilt to reproduce the same binary. + /// + /// # Examples + /// + /// ```sway + /// use standards::src11::SecurityInformation; + /// + /// fn foo( + /// name: String, + /// project_url: Option, + /// contact_information: Vec, + /// policy: String, + /// preferred_languages: Option>, + /// encryption: Option, + /// source_code: Option, + /// source_release: Option, + /// source_revision: Option, + /// auditors: Option>, + /// acknowledgments: Option, + /// additional_information: Option, + /// ) { + /// let security_information = SecurityInformation::new( + /// name, + /// project_url, + /// contact_information, + /// policy, + /// preferred_languages, + /// encryption, + /// source_code, + /// source_release, + /// source_revision, + /// auditors, + /// acknowledgments, + /// additional_information, + /// ); + /// assert(security_information.source_release() == source_release); + /// } + /// ``` + pub fn source_release(self) -> Option { + self.source_release + } + + /// Returns the `source_revision` of the `SecurityInformation`. + /// + /// # Returns + /// + /// * `source_revision`: [Option] - The revision identifier of this build, usually a git commit hash that can be rebuilt to reproduce the same binary. + /// + /// # Examples + /// + /// ```sway + /// use standards::src11::SecurityInformation; + /// + /// fn foo( + /// name: String, + /// project_url: Option, + /// contact_information: Vec, + /// policy: String, + /// preferred_languages: Option>, + /// encryption: Option, + /// source_code: Option, + /// source_release: Option, + /// source_revision: Option, + /// auditors: Option>, + /// acknowledgments: Option, + /// additional_information: Option, + /// ) { + /// let security_information = SecurityInformation::new( + /// name, + /// project_url, + /// contact_information, + /// policy, + /// preferred_languages, + /// encryption, + /// source_code, + /// source_release, + /// source_revision, + /// auditors, + /// acknowledgments, + /// additional_information, + /// ); + /// assert(security_information.source_revision() == source_revision); + /// } + /// ``` + pub fn source_revision(self) -> Option { + self.source_revision + } + + /// Returns the `auditors` of the `SecurityInformation`. + /// + /// # Returns + /// + /// * `auditors`: [Option>] - A list of people or entities that audited this smart contract, or links to pages where audit reports are hosted. + /// + /// # Examples + /// + /// ```sway + /// use standards::src11::SecurityInformation; + /// + /// fn foo( + /// name: String, + /// project_url: Option, + /// contact_information: Vec, + /// policy: String, + /// preferred_languages: Option>, + /// encryption: Option, + /// source_code: Option, + /// source_release: Option, + /// source_revision: Option, + /// auditors: Option>, + /// acknowledgments: Option, + /// additional_information: Option, + /// ) { + /// let security_information = SecurityInformation::new( + /// name, + /// project_url, + /// contact_information, + /// policy, + /// preferred_languages, + /// encryption, + /// source_code, + /// source_release, + /// source_revision, + /// auditors, + /// acknowledgments, + /// additional_information, + /// ); + /// assert(security_information.auditors() == auditors); + /// } + /// ``` + pub fn auditors(self) -> Option> { + self.auditors + } + + /// Returns the `acknowledgments` of the `SecurityInformation`. + /// + /// # Returns + /// + /// * `acknowledgments`: [Option] - Text containing acknowledgments to security researchers who have previously found vulnerabilities in the project, or a link to it. + /// + /// # Examples + /// + /// ```sway + /// use standards::src11::SecurityInformation; + /// + /// fn foo( + /// name: String, + /// project_url: Option, + /// contact_information: Vec, + /// policy: String, + /// preferred_languages: Option>, + /// encryption: Option, + /// source_code: Option, + /// source_release: Option, + /// source_revision: Option, + /// auditors: Option>, + /// acknowledgments: Option, + /// additional_information: Option, + /// ) { + /// let security_information = SecurityInformation::new( + /// name, + /// project_url, + /// contact_information, + /// policy, + /// preferred_languages, + /// encryption, + /// source_code, + /// source_release, + /// source_revision, + /// auditors, + /// acknowledgments, + /// additional_information, + /// ); + /// assert(security_information.acknowledgments() == acknowledgments); + /// } + /// ``` + pub fn acknowledgments(self) -> Option { + self.acknowledgments + } + + /// Returns the `additional_information` of the `SecurityInformation`. + /// + /// # Returns + /// + /// * `additional_information`: [Option] - Text containing any additional information you want to provide, or a link to it. + /// + /// # Examples + /// + /// ```sway + /// use standards::src11::SecurityInformation; + /// + /// fn foo( + /// name: String, + /// project_url: Option, + /// contact_information: Vec, + /// policy: String, + /// preferred_languages: Option>, + /// encryption: Option, + /// source_code: Option, + /// source_release: Option, + /// source_revision: Option, + /// auditors: Option>, + /// acknowledgments: Option, + /// additional_information: Option, + /// ) { + /// let security_information = SecurityInformation::new( + /// name, + /// project_url, + /// contact_information, + /// policy, + /// preferred_languages, + /// encryption, + /// source_code, + /// source_release, + /// source_revision, + /// auditors, + /// acknowledgments, + /// additional_information, + /// ); + /// assert(security_information.additional_information() == additional_information); + /// } + /// ``` + pub fn additional_information(self) -> Option { + self.additional_information + } +} diff --git a/standards/src/src12.sw b/standards/src/src12.sw index 6304599d..e5bca21f 100644 --- a/standards/src/src12.sw +++ b/standards/src/src12.sw @@ -20,11 +20,12 @@ abi SRC12 { /// # Examples /// /// ```sway - /// use src12::SRC12; + /// use standards::src12::SRC12; /// - /// fn foo(my_src_12_contract: ContractId, my_deployed_contract: ContractId, my_configurables: Option) { - /// let src_12_contract_abi = abi(SRC12, my_src_12_contract.bits()); - /// src_12_contract_abi.register_contract(my_deployed_contract, my_configurables); + /// fn foo(src_12_contract: ContractId, my_deployed_contract: ContractId, my_configurables: Option) { + /// let src_12_contract_abi = abi(SRC12, src_12_contract.bits()); + /// let result = src_12_contract_abi.register_contract(my_deployed_contract, my_configurables); + /// assert(result.is_ok()); /// assert(src_12_contract_abi.is_valid(my_deployed_contract)); /// } /// ``` @@ -47,12 +48,14 @@ abi SRC12 { /// # Examples /// /// ```sway - /// use src12::SRC12; + /// use standards::src12::SRC12; /// - /// fn foo(my_src_12_contract: ContractId, my_deployed_contract: ContractId, my_configurables: Option) { - /// let src_12_contract_abi = abi(SRC12, my_src_12_contract.bits()); - /// src_12_contract_abi.register_contract(my_deployed_contract, my_configurables); - /// assert(src_12_contract_abi.is_valid(my_deployed_contract)); + /// fn foo(src_12_contract: ContractId, my_deployed_contract: ContractId, my_configurables: Option) { + /// let src_12_contract_abi = abi(SRC12, src_12_contract.bits()); + /// let _ = src_12_contract_abi.register_contract(my_deployed_contract, my_configurables); + /// + /// let result: bool = src_12_contract_abi.is_valid(my_deployed_contract) + /// assert(result); /// } /// ``` #[storage(read)] @@ -67,11 +70,11 @@ abi SRC12 { /// # Examples /// /// ```sway - /// use src12::SRC12; + /// use standards::src12::SRC12; /// - /// fn foo(my_src_12_contract: ContractId) { - /// let src_12_contract_abi = abi(SRC12, my_src_12_contract.bits()); - /// let root = src_12_contract_abi.factory_bytecode_root(); + /// fn foo(src_12_contract: ContractId) { + /// let src_12_contract_abi = abi(SRC12, src_12_contract.bits()); + /// let root: Option = src_12_contract_abi.factory_bytecode_root(); /// assert(root.unwrap() != b256::zero()); /// } /// ``` @@ -93,12 +96,13 @@ abi SRC12_Extension { /// # Examples /// /// ```sway - /// use src12::SRC12; + /// use standards::src12::SRC12; + /// + /// fn foo(src_12_contract: ContractId, my_deployed_contract: ContractId, my_configurables: Option) { + /// let src_12_contract_abi = abi(SRC12, src_12_contract.bits()); + /// let _ = src_12_contract_abi.register_contract(my_deployed_contract, my_configurables); /// - /// fn foo(my_src_12_contract: ContractId, my_deployed_contract: ContractId, my_configurables: Option) { - /// let src_12_contract_abi = abi(SRC12, my_src_12_contract.bits()); - /// src_12_contract_abi.register_contract(my_deployed_contract, my_configurables); - /// let result_contract_id = src_12_contract_abi.get_contract_id(my_configurables); + /// let result_contract_id: Option = src_12_contract_abi.get_contract_id(my_configurables); /// assert(result_contract_id.unwrap() == my_deployed_contract); /// } /// ``` diff --git a/standards/src/src14.sw b/standards/src/src14.sw index 51d00e56..6bb206fb 100644 --- a/standards/src/src14.sw +++ b/standards/src/src14.sw @@ -12,7 +12,7 @@ abi SRC14 { /// # Examples /// /// ```sway - /// use src14::SRC14; + /// use standards::src14::SRC14; /// /// fn foo(contract_id: ContractId) { /// let contract_abi = abi(SRC14, contract_id.bits()); @@ -32,11 +32,12 @@ abi SRC14 { /// # Examples /// /// ```sway - /// use src14::SRC14; + /// use standards::src14::SRC14; /// /// fn foo(contract_id: ContractId) { /// let contract_abi = abi(SRC14, contract_id.bits()); /// let target_contract: Option = contract_abi.proxy_target(); + /// assert(target_contract.is_some()); /// } /// ``` #[storage(read)] @@ -53,10 +54,14 @@ abi SRC14Extension { /// # Examples /// /// ```sway - /// fn foo() { - /// match owner() { - /// State::Uninitalized => log("The ownership is uninitalized"), - /// State::Initialized(owner) => log("The ownership is initalized"), + /// use standards::{src5::State, src14::{SRC14Extension, proxy_owner}}; + /// + /// fn foo(contract_id: ContractId) { + /// let contract_abi = abi(SRC14Extension, contract_id.bits()); + /// + /// match contract_abi.proxy_owner() { + /// State::Uninitialized => log("The ownership is uninitialized"), + /// State::Initialized(owner) => log("The ownership is initialized"), /// State::Revoked => log("The ownership is revoked"), /// } /// } diff --git a/standards/src/src20.sw b/standards/src/src20.sw index fe093668..72cad675 100644 --- a/standards/src/src20.sw +++ b/standards/src/src20.sw @@ -12,11 +12,11 @@ abi SRC20 { /// # Examples /// /// ```sway - /// use src20::SRC20; + /// use standards::src20::SRC20; /// - /// fn foo(contract: ContractId) { - /// let contract_abi = abi(SRC20, contract); - /// let total_assets = contract_abi.total_assets(); + /// fn foo(contract_id: ContractId) { + /// let contract_abi = abi(SRC20, contract_id.bits()); + /// let total_assets: u64 = contract_abi.total_assets(); /// assert(total_assets != 0); /// } /// ``` @@ -36,11 +36,11 @@ abi SRC20 { /// # Examples /// /// ```sway - /// use src20::SRC20; + /// use standards::src20::SRC20; /// - /// fn foo(contract: ContractId, asset: AssetId) { - /// let contract_abi = abi(SRC20, contract); - /// let total_supply = contract_abi.total_supply(asset); + /// fn foo(contract_id: ContractId, asset: AssetId) { + /// let contract_abi = abi(SRC20, contract_id.bits()); + /// let total_supply: Option = contract_abi.total_supply(asset); /// assert(total_supply.unwrap() != 0); /// } /// ``` @@ -60,12 +60,12 @@ abi SRC20 { /// # Examples /// /// ```sway - /// use src20::SRC20; + /// use standards::src20::SRC20; /// use std::string::String; /// - /// fn foo(contract: ContractId, asset: AssetId) { - /// let contract_abi = abi(SRC20, contract); - /// let name = contract_abi.name(asset); + /// fn foo(contract_id: ContractId, asset: AssetId) { + /// let contract_abi = abi(SRC20, contract_id.bits()); + /// let name: Option = contract_abi.name(asset); /// assert(name.is_some()); /// } /// ``` @@ -84,12 +84,12 @@ abi SRC20 { /// # Examples /// /// ```sway - /// use src20::SRC20; + /// use standards::src20::SRC20; /// use std::string::String; /// - /// fn foo(contract: ContractId, asset: AssetId) { - /// let contract_abi = abi(SRC20, contract); - /// let symbol = contract_abi.symbol(asset); + /// fn foo(contract_id: ContractId, asset: AssetId) { + /// let contract_abi = abi(SRC20, contract_id.bits()); + /// let symbol: Option = contract_abi.symbol(asset); /// assert(symbol.is_some()); /// } /// ``` @@ -112,11 +112,11 @@ abi SRC20 { /// # Examples /// /// ```sway - /// use src20::SRC20; + /// use standards::src20::SRC20; /// - /// fn foo(contract: ContractId, asset: AssedId) { - /// let contract_abi = abi(SRC20, contract); - /// let decimals = contract_abi.decimals(asset); + /// fn foo(contract_id: ContractId, asset: AssedId) { + /// let contract_abi = abi(SRC20, contract_id.bits()); + /// let decimals: Option = contract_abi.decimals(asset); /// assert(decimals.unwrap() == 8u8); /// } /// ``` @@ -163,3 +163,457 @@ pub struct TotalSupplyEvent { /// The caller that updated the supply. pub sender: Identity, } + +impl core::ops::Eq for SetNameEvent { + fn eq(self, other: Self) -> bool { + self.asset == other.asset && self.name == other.name && self.sender == other.sender + } +} + +impl SetNameEvent { + /// Returns a new `SetNameEvent` event. + /// + /// # Arguments + /// + /// * `asset`: [AssetId] - The asset for which name is set. + /// * `name`: [Option] - The name that is set. + /// * `sender`: [Identity] - The caller that set the name. + /// + /// # Returns + /// + /// * [SetNameEvent] - The new `SetNameEvent` event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::SetNameEvent; + /// + /// fn foo(asset: AssetId, name: Option, sender: Identity) { + /// let my_event = SetNameEvent::new(asset, name, sender); + /// assert(my_event.asset == asset); + /// assert(my_event.name == name); + /// assert(my_event.sender == sender); + /// } + pub fn new(asset: AssetId, name: Option, sender: Identity) -> Self { + Self { + asset, + name, + sender, + } + } + + /// Returns the asset of the `SetNameEvent` event. + /// + /// # Returns + /// + /// * [AssetId] - The asset for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::SetNameEvent; + /// + /// fn foo(asset: AssetId, name: Option, sender: Identity) { + /// let my_event = SetNameEvent::new(asset, name, sender); + /// assert(my_event.asset() == asset); + /// } + pub fn asset(self) -> AssetId { + self.asset + } + + /// Returns the name of the `SetNameEvent` event. + /// + /// # Returns + /// + /// * [Option] - The name for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::SetNameEvent; + /// + /// fn foo(asset: AssetId, name: Option, sender: Identity) { + /// let my_event = SetNameEvent::new(asset, name, sender); + /// assert(my_event.name() == name); + /// } + pub fn name(self) -> Option { + self.name + } + + /// Returns the sender of the `SetNameEvent` event. + /// + /// # Returns + /// + /// * [Identity] - The sender of the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::SetNameEvent; + /// + /// fn foo(asset: AssetId, name: Option, sender: Identity) { + /// let my_event = SetNameEvent::new(asset, name, sender); + /// assert(my_event.sender() == sender); + /// } + pub fn sender(self) -> Identity { + self.sender + } + + /// Logs the `SetNameEvent`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::SetNameEvent; + /// + /// fn foo(asset: AssetId, name: Option, sender: Identity) { + /// let my_event = SetNameEvent::new(asset, name, sender); + /// my_event.log(); + /// } + pub fn log(self) { + log(self); + } +} + +impl core::ops::Eq for SetSymbolEvent { + fn eq(self, other: Self) -> bool { + self.asset == other.asset && self.symbol == other.symbol && self.sender == other.sender + } +} + +impl SetSymbolEvent { + /// Returns a new `SetSymbolEvent` event. + /// + /// # Arguments + /// + /// * `asset`: [AssetId] - The asset for which symbol is set. + /// * `symbol`: [Option] - The symbol that is set. + /// * `sender`: [Identity] - The caller that set the symbol. + /// + /// # Returns + /// + /// * [SetSymbolEvent] - The new `SetSymbolEvent` event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::SetSymbolEvent; + /// + /// fn foo(asset: AssetId, symbol: Option, sender: Identity) { + /// let my_event = SetSymbolEvent::new(asset, symbol, sender); + /// assert(my_event.asset == asset); + /// assert(my_event.symbol == symbol); + /// assert(my_event.sender == sender); + /// } + pub fn new(asset: AssetId, symbol: Option, sender: Identity) -> Self { + Self { + asset, + symbol, + sender, + } + } + + /// Returns the asset of the `SetSymbolEvent` event. + /// + /// # Returns + /// + /// * [AssetId] - The asset for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::SetSymbolEvent; + /// + /// fn foo(asset: AssetId, symbol: Option, sender: Identity) { + /// let my_event = SetSymbolEvent::new(asset, symbol, sender); + /// assert(my_event.asset() == asset); + /// } + pub fn asset(self) -> AssetId { + self.asset + } + + /// Returns the symbol of the `SetSymbolEvent` event. + /// + /// # Returns + /// + /// * [Option] - The symbol for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::SetSymbolEvent; + /// + /// fn foo(asset: AssetId, symbol: Option, sender: Identity) { + /// let my_event = SetSymbolEvent::new(asset, symbol, sender); + /// assert(my_event.symbol() == symbol); + /// } + pub fn symbol(self) -> Option { + self.symbol + } + + /// Returns the sender of the `SetSymbolEvent` event. + /// + /// # Returns + /// + /// * [Identity] - The sender of the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::SetSymbolEvent; + /// + /// fn foo(asset: AssetId, symbol: Option, sender: Identity) { + /// let my_event = SetSymbolEvent::new(asset, symbol, sender); + /// assert(my_event.sender() == sender); + /// } + pub fn sender(self) -> Identity { + self.sender + } + + /// Logs the `SetSymbolEvent`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::SetSymbolEvent; + /// + /// fn foo(asset: AssetId, symbol: Option, sender: Identity) { + /// let my_event = SetSymbolEvent::new(asset, symbol, sender); + /// my_event.log(); + /// } + pub fn log(self) { + log(self); + } +} + +impl core::ops::Eq for SetDecimalsEvent { + fn eq(self, other: Self) -> bool { + self.asset == other.asset && self.decimals == other.decimals && self.sender == other.sender + } +} + +impl SetDecimalsEvent { + /// Returns a new `SetDecimalsEvent` event. + /// + /// # Arguments + /// + /// * `asset`: [AssetId] - The asset for which decimals is set. + /// * `decimals`: [u8] - The decimals that is set. + /// * `sender`: [Identity] - The caller that set the decimals. + /// + /// # Returns + /// + /// * [SetDecimalsEvent] - The new `SetDecimalsEvent` event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::SetDecimalsEvent; + /// + /// fn foo(asset: AssetId, decimals: u8, sender: Identity) { + /// let my_event = SetDecimalsEvent::new(asset, decimals, sender); + /// assert(my_event.asset == asset); + /// assert(my_event.decimals == decimals); + /// assert(my_event.sender == sender); + /// } + /// ``` + pub fn new(asset: AssetId, decimals: u8, sender: Identity) -> Self { + Self { + asset, + decimals, + sender, + } + } + + /// Returns the asset of the `SetDecimalsEvent` event. + /// + /// # Returns + /// + /// * [AssetId] - The asset for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::SetDecimalsEvent; + /// + /// fn foo(asset: AssetId, decimals: u8, sender: Identity) { + /// let my_event = SetDecimalsEvent::new(asset, decimals, sender); + /// assert(my_event.asset() == asset); + /// } + /// ``` + pub fn asset(self) -> AssetId { + self.asset + } + + /// Returns the decimals of the `SetDecimalsEvent` event. + /// + /// # Returns + /// + /// * [u8] - The decimals for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::SetDecimalsEvent; + /// + /// fn foo(asset: AssetId, decimals: u8, sender: Identity) { + /// let my_event = SetDecimalsEvent::new(asset, decimals, sender); + /// assert(my_event.decimals() == decimals); + /// } + /// ``` + pub fn decimals(self) -> u8 { + self.decimals + } + + /// Returns the sender of the `SetDecimalsEvent` event. + /// + /// # Returns + /// + /// * [Identity] - The sender of the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::SetDecimalsEvent; + /// + /// fn foo(asset: AssetId, decimals: u8, sender: Identity) { + /// let my_event = SetDecimalsEvent::new(asset, decimals, sender); + /// assert(my_event.sender() == sender); + /// } + /// ``` + pub fn sender(self) -> Identity { + self.sender + } + + /// Logs the `SetDecimalsEvent`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::SetDecimalsEvent; + /// + /// fn foo(asset: AssetId, decimals: u8, sender: Identity) { + /// let my_event = SetDecimalsEvent::new(asset, decimals, sender); + /// my_event.log(); + /// } + /// ``` + pub fn log(self) { + log(self); + } +} + +impl core::ops::Eq for TotalSupplyEvent { + fn eq(self, other: Self) -> bool { + self.asset == other.asset && self.supply == other.supply && self.sender == other.sender + } +} + +impl TotalSupplyEvent { + /// Returns a new `TotalSupplyEvent` event. + /// + /// # Arguments + /// + /// * `asset`: [AssetId] - The asset for which supply is updated. + /// * `supply`: [u64] - The new supply of the asset. + /// * `sender`: [Identity] - The caller that updated the supply. + /// + /// # Returns + /// + /// * [TotalSupplyEvent] - The new `TotalSupplyEvent` event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::TotalSupplyEvent; + /// + /// fn foo(asset: AssetId, supply: u64, sender: Identity) { + /// let my_event = TotalSupplyEvent::new(asset, supply, sender); + /// assert(my_event.asset == asset); + /// assert(my_event.supply == supply); + /// assert(my_event.sender == sender); + /// } + /// ``` + pub fn new(asset: AssetId, supply: u64, sender: Identity) -> Self { + Self { + asset, + supply, + sender, + } + } + + /// Returns the asset of the `TotalSupplyEvent` event. + /// + /// # Returns + /// + /// * [AssetId] - The asset for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::TotalSupplyEvent; + /// + /// fn foo(asset: AssetId, supply: u64, sender: Identity) { + /// let my_event = TotalSupplyEvent::new(asset, supply, sender); + /// assert(my_event.asset() == asset); + /// } + /// ``` + pub fn asset(self) -> AssetId { + self.asset + } + + /// Returns the supply of the `TotalSupplyEvent` event. + /// + /// # Returns + /// + /// * [u64] - The supply for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::TotalSupplyEvent; + /// + /// fn foo(asset: AssetId, supply: u64, sender: Identity) { + /// let my_event = TotalSupplyEvent::new(asset, supply, sender); + /// assert(my_event.supply() == supply); + /// } + /// ``` + pub fn supply(self) -> u64 { + self.supply + } + + /// Returns the sender of the `TotalSupplyEvent` event. + /// + /// # Returns + /// + /// * [Identity] - The sender of the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::TotalSupplyEvent; + /// + /// fn foo(asset: AssetId, supply: u64, sender: Identity) { + /// let my_event = TotalSupplyEvent::new(asset, supply, sender); + /// assert(my_event.sender() == sender); + /// } + /// ``` + pub fn sender(self) -> Identity { + self.sender + } + + /// Logs the `TotalSupplyEvent`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src20::TotalSupplyEvent; + /// + /// fn foo(asset: AssetId, supply: u64, sender: Identity) { + /// let my_event = TotalSupplyEvent::new(asset, supply, sender); + /// my_event.log(); + /// } + /// ``` + pub fn log(self) { + log(self); + } +} diff --git a/standards/src/src3.sw b/standards/src/src3.sw index 8f1b9275..e1d3ee4c 100644 --- a/standards/src/src3.sw +++ b/standards/src/src3.sw @@ -12,10 +12,10 @@ abi SRC3 { /// # Examples /// /// ```sway - /// use src3::SRC3; + /// use standards::src3::SRC3; /// /// fn foo(contract_id: ContractId) { - /// let contract_abi = abi(SRC3, contract); + /// let contract_abi = abi(SRC3, contract_id.bits()); /// contract_abi.mint(Identity::ContractId(contract_id), SubId::zero(), 100); /// } /// ``` @@ -37,10 +37,10 @@ abi SRC3 { /// # Examples /// /// ```sway - /// use src3::SRC3; + /// use standards::src3::SRC3; /// /// fn foo(contract_id: ContractId, asset_id: AssetId) { - /// let contract_abi = abi(SRC3, contract_id); + /// let contract_abi = abi(SRC3, contract_id.bits()); /// contract_abi { /// gas: 10000, /// coins: 100, diff --git a/standards/src/src5.sw b/standards/src/src5.sw index 5e8ce62e..135fbba2 100644 --- a/standards/src/src5.sw +++ b/standards/src/src5.sw @@ -10,19 +10,6 @@ pub enum State { Revoked: (), } -impl core::ops::Eq for State { - fn eq(self, other: Self) -> bool { - match (self, other) { - (State::Initialized(owner1), State::Initialized(owner2)) => { - owner1 == owner2 - }, - (State::Uninitialized, State::Uninitialized) => true, - (State::Revoked, State::Revoked) => true, - _ => false, - } - } -} - /// Error log for when access is denied. pub enum AccessError { /// Emitted when the caller is not the owner of the contract. @@ -39,10 +26,14 @@ abi SRC5 { /// # Examples /// /// ```sway - /// fn foo() { - /// match owner() { - /// State::Uninitalized => log("The ownership is uninitalized"), - /// State::Initialized(owner) => log("The ownership is initalized"), + /// use standards::src5::{SRC5, State}; + /// + /// fn foo(contract_id: ContractId) { + /// let contract_abi = abi(SRC5, contract_id.bits()); + /// + /// match contract_abi.owner() { + /// State::Uninitialized => log("The ownership is uninitialized"), + /// State::Initialized(owner) => log("The ownership is initialized"), /// State::Revoked => log("The ownership is revoked"), /// } /// } @@ -50,3 +41,126 @@ abi SRC5 { #[storage(read)] fn owner() -> State; } + +impl core::ops::Eq for State { + fn eq(self, other: Self) -> bool { + match (self, other) { + (Self::Initialized(owner1), Self::Initialized(owner2)) => { + owner1 == owner2 + }, + (Self::Uninitialized, Self::Uninitialized) => true, + (Self::Revoked, Self::Revoked) => true, + _ => false, + } + } +} + +impl core::ops::Eq for AccessError { + fn eq(self, other: Self) -> bool { + match (self, other) { + (Self::NotOwner, Self::NotOwner) => true, + } + } +} + +impl State { + /// Returns whether the state is uninitialized. + /// + /// # Return Values + /// + /// * [bool] - `true` if the state is uninitialized, otherwise `false`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src5::{SRC5, State}; + /// + /// fn foo(contract_id: ContractId) { + /// let contract_abi = abi(SRC5, contract_id.bits()); + /// + /// let owner_state: State = contract_abi.owner(); + /// assert(owner_state.is_uninitialized()); + /// } + /// ``` + pub fn is_uninitialized(self) -> bool { + match self { + Self::Uninitialized => true, + _ => false, + } + } + + /// Returns whether the state is initialized. + /// + /// # Return Values + /// + /// * [bool] - `true` if the state is initialized, otherwise `false`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src5::{SRC5, State}; + /// + /// fn foo(contract_id: ContractId) { + /// let contract_abi = abi(SRC5, contract_id.bits()); + /// + /// let owner_state: State = contract_abi.owner(); + /// assert(owner_state.is_initialized()); + /// } + /// ``` + pub fn is_initialized(self) -> bool { + match self { + Self::Initialized(_) => true, + _ => false, + } + } + + /// Returns whether the state is revoked. + /// + /// # Return Values + /// + /// * [bool] - `true` if the state is revoked, otherwise `false`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src5::{SRC5, State}; + /// + /// fn foo(contract_id: ContractId) { + /// let contract_abi = abi(SRC5, contract_id.bits()); + /// + /// let owner_state: State = contract_abi.owner(); + /// assert(owner_state.is_revoked()); + /// } + /// ``` + pub fn is_revoked(self) -> bool { + match self { + Self::Revoked => true, + _ => false, + } + } + + /// Returns the underlying owner as a `Identity`. + /// + /// # Returns + /// + /// * [Option] - `Some` if the state is initialized, otherwise `None`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src5::{SRC5, State}; + /// + /// fn foo(contract_id: ContractId) { + /// let contract_abi = abi(SRC5, contract_id.bits()); + /// + /// let owner_state: State = contract_abi.owner(); + /// assert(owner_state.owner().is_some()); + /// } + /// ``` + pub fn owner(self) -> Option { + match self { + Self::Initialized(owner) => Some(owner), + _ => None, + } + } +} diff --git a/standards/src/src6.sw b/standards/src/src6.sw index 4e1b514e..5d5fe4a8 100644 --- a/standards/src/src6.sw +++ b/standards/src/src6.sw @@ -141,3 +141,499 @@ abi SRC6 { #[storage(read)] fn max_withdrawable(underlying_asset: AssetId, vault_sub_id: SubId) -> Option; } + +impl core::ops::Eq for Deposit { + fn eq(self, other: Self) -> bool { + self.caller == other.caller && self.receiver == other.receiver && self.underlying_asset == other.underlying_asset && self.vault_sub_id == other.vault_sub_id && self.deposited_amount == other.deposited_amount && self.minted_shares == other.minted_shares + } +} + +impl core::ops::Eq for Withdraw { + fn eq(self, other: Self) -> bool { + self.caller == other.caller && self.receiver == other.receiver && self.underlying_asset == other.underlying_asset && self.vault_sub_id == other.vault_sub_id && self.withdrawn_amount == other.withdrawn_amount && self.burned_shares == other.burned_shares + } +} + +impl Deposit { + /// Returns a new `Deposit` event. + /// + /// # Arguments + /// + /// * `caller`: [Identity] - The caller of the deposit function. + /// * `receiver`: [Identity] - The receiver of the deposit. + /// * `underlying_asset`: [AssetId] - The asset being deposited. + /// * `vault_sub_id`: [SubId] - The SubId of the vault. + /// * `deposited_amount`: [u64] - The amount of assets being deposited. + /// * `minted_shares`: [u64] - The amount of shares being minted. + /// + /// # Returns + /// + /// * [Deposit] - The new `Deposit` event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src6::Deposit; + /// + /// fn foo( + /// caller: Identity, + /// receiver: Identity, + /// underlying_asset: AssetId, + /// vault_sub_id: SubId, + /// deposited_amount: u64, + /// minted_shares: u64 + /// ) { + /// let my_event = Deposit::new(caller, receiver, underlying_asset, vault_sub_id, deposited_amount, minted_shares); + /// assert(my_event.caller == caller); + /// assert(my_event.receiver == receiver); + /// assert(my_event.underlying_asset == underlying_asset); + /// assert(my_event.vault_sub_id == vault_sub_id); + /// assert(my_event.deposited_amount == deposited_amount); + /// assert(my_event.minted_shares == minted_shares); + /// } + /// ``` + pub fn new( + caller: Identity, + receiver: Identity, + underlying_asset: AssetId, + vault_sub_id: SubId, + deposited_amount: u64, + minted_shares: u64, + ) -> Self { + Self { + caller, + receiver, + underlying_asset, + vault_sub_id, + deposited_amount, + minted_shares, + } + } + + /// Returns the `caller` of the `Deposit` event. + /// + /// # Returns + /// + /// * [Identity] - The caller for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src6::Deposit; + /// + /// fn foo( + /// caller: Identity, + /// receiver: Identity, + /// underlying_asset: AssetId, + /// vault_sub_id: SubId, + /// deposited_amount: u64, + /// minted_shares: u64 + /// ) { + /// let my_event = Deposit::new(caller, receiver, underlying_asset, vault_sub_id, deposited_amount, minted_shares); + /// assert(my_event.caller() == caller); + /// } + /// ``` + pub fn caller(self) -> Identity { + self.caller + } + + /// Returns the `receiver` of the `Deposit` event. + /// + /// # Returns + /// + /// * [Identity] - The receiver for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src6::Deposit; + /// + /// fn foo( + /// caller: Identity, + /// receiver: Identity, + /// underlying_asset: AssetId, + /// vault_sub_id: SubId, + /// deposited_amount: u64, + /// minted_shares: u64 + /// ) { + /// let my_event = Deposit::new(caller, receiver, underlying_asset, vault_sub_id, deposited_amount, minted_shares); + /// assert(my_event.receiver() == receiver); + /// } + /// ``` + pub fn receiver(self) -> Identity { + self.receiver + } + + /// Returns the `underlying_asset` of the `Deposit` event. + /// + /// # Returns + /// + /// * [AssetId] - The underlying asset for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src6::Deposit; + /// + /// fn foo( + /// caller: Identity, + /// receiver: Identity, + /// underlying_asset: AssetId, + /// vault_sub_id: SubId, + /// deposited_amount: u64, + /// minted_shares: u64 + /// ) { + /// let my_event = Deposit::new(caller, receiver, underlying_asset, vault_sub_id, deposited_amount, minted_shares); + /// assert(my_event.underlying_asset() == underlying_asset); + /// } + /// ``` + pub fn underlying_asset(self) -> AssetId { + self.underlying_asset + } + + /// Returns the `vault_sub_id` of the `Deposit` event. + /// + /// # Returns + /// + /// * [SubId] - The vault sub id for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src6::Deposit; + /// + /// fn foo( + /// caller: Identity, + /// receiver: Identity, + /// underlying_asset: AssetId, + /// vault_sub_id: SubId, + /// deposited_amount: u64, + /// minted_shares: u64 + /// ) { + /// let my_event = Deposit::new(caller, receiver, underlying_asset, vault_sub_id, deposited_amount, minted_shares); + /// assert(my_event.vault_sub_id() == vault_sub_id); + /// } + /// ``` + pub fn vault_sub_id(self) -> SubId { + self.vault_sub_id + } + + /// Returns the `deposited_amount` of the `Deposit` event. + /// + /// # Returns + /// + /// * [u64] - The deposited amount for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src6::Deposit; + /// + /// fn foo( + /// caller: Identity, + /// receiver: Identity, + /// underlying_asset: AssetId, + /// vault_sub_id: SubId, + /// deposited_amount: u64, + /// minted_shares: u64 + /// ) { + /// let my_event = Deposit::new(caller, receiver, underlying_asset, vault_sub_id, deposited_amount, minted_shares); + /// assert(my_event.deposited_amount() == deposited_amount); + /// } + /// ``` + pub fn deposited_amount(self) -> u64 { + self.deposited_amount + } + + /// Returns the `minted_shares` of the `Deposit` event. + /// + /// # Returns + /// + /// * [u64] - The minted shares for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src6::Deposit; + /// + /// fn foo( + /// caller: Identity, + /// receiver: Identity, + /// underlying_asset: AssetId, + /// vault_sub_id: SubId, + /// deposited_amount: u64, + /// minted_shares: u64 + /// ) { + /// let my_event = Deposit::new(caller, receiver, underlying_asset, vault_sub_id, deposited_amount, minted_shares); + /// assert(my_event.minted_shares() == minted_shares); + /// } + /// ``` + pub fn minted_shares(self) -> u64 { + self.minted_shares + } + + /// Logs the `Deposit`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src6::Deposit; + /// + /// fn foo( + /// caller: Identity, + /// receiver: Identity, + /// underlying_asset: AssetId, + /// vault_sub_id: SubId, + /// deposited_amount: u64, + /// minted_shares: u64 + /// ) { + /// let my_event = Deposit::new(caller, receiver, underlying_asset, vault_sub_id, deposited_amount, minted_shares); + /// my_event.log(); + /// } + /// ``` + pub fn log(self) { + log(self); + } +} + +impl Withdraw { + /// Returns a new `Withdraw` event. + /// + /// # Arguments + /// + /// * `caller`: [Identity] - The caller of the withdrawal function. + /// * `receiver`: [Identity] - The receiver of the withdrawal. + /// * `underlying_asset`: [AssetId] - The asset being withdrawn. + /// * `vault_sub_id`: [SubId] - The SubId of the vault. + /// * `withdrawn_amount`: [u64] - The amount of assets being withdrawn. + /// * `burned_shares`: [u64] - The amount of shares being burned. + /// + /// # Returns + /// + /// * [Withdraw] - The new `Withdraw` event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src6::Withdraw; + /// + /// fn foo( + /// caller: Identity, + /// receiver: Identity, + /// underlying_asset: AssetId, + /// vault_sub_id: SubId, + /// withdrawn_amount: u64, + /// burned_shares: u64 + /// ) { + /// let my_event = Withdraw::new(caller, receiver, underlying_asset, vault_sub_id, withdrawn_amount, burned_shares); + /// assert(my_event.caller == caller); + /// assert(my_event.receiver == receiver); + /// assert(my_event.underlying_asset == underlying_asset); + /// assert(my_event.vault_sub_id == vault_sub_id); + /// assert(my_event.withdrawn_amount == withdrawn_amount); + /// assert(my_event.burned_shares == burned_shares); + /// } + /// ``` + pub fn new( + caller: Identity, + receiver: Identity, + underlying_asset: AssetId, + vault_sub_id: SubId, + withdrawn_amount: u64, + burned_shares: u64, + ) -> Self { + Self { + caller, + receiver, + underlying_asset, + vault_sub_id, + withdrawn_amount, + burned_shares, + } + } + + /// Returns the `caller` of the `Withdraw` event. + /// + /// # Returns + /// + /// * [Identity] - The caller for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src6::Withdraw; + /// + /// fn foo( + /// caller: Identity, + /// receiver: Identity, + /// underlying_asset: AssetId, + /// vault_sub_id: SubId, + /// withdrawn_amount: u64, + /// burned_shares: u64 + /// ) { + /// let my_event = Withdraw::new(caller, receiver, underlying_asset, vault_sub_id, withdrawn_amount, burned_shares); + /// assert(my_event.caller() == caller); + /// } + /// ``` + pub fn caller(self) -> Identity { + self.caller + } + + /// Returns the `receiver` of the `Withdraw` event. + /// + /// # Returns + /// + /// * [Identity] - The receiver for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src6::Withdraw; + /// + /// fn foo( + /// caller: Identity, + /// receiver: Identity, + /// underlying_asset: AssetId, + /// vault_sub_id: SubId, + /// withdrawn_amount: u64, + /// burned_shares: u64 + /// ) { + /// let my_event = Withdraw::new(caller, receiver, underlying_asset, vault_sub_id, withdrawn_amount, burned_shares); + /// assert(my_event.receiver() == receiver); + /// } + /// ``` + pub fn receiver(self) -> Identity { + self.receiver + } + + /// Returns the `underlying_asset` of the `Withdraw` event. + /// + /// # Returns + /// + /// * [AssetId] - The underlying asset for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src6::Withdraw; + /// + /// fn foo( + /// caller: Identity, + /// receiver: Identity, + /// underlying_asset: AssetId, + /// vault_sub_id: SubId, + /// withdrawn_amount: u64, + /// burned_shares: u64 + /// ) { + /// let my_event = Withdraw::new(caller, receiver, underlying_asset, vault_sub_id, withdrawn_amount, burned_shares); + /// assert(my_event.underlying_asset() == underlying_asset); + /// } + /// ``` + pub fn underlying_asset(self) -> AssetId { + self.underlying_asset + } + + /// Returns the `vault_sub_id` of the `Withdraw` event. + /// + /// # Returns + /// + /// * [SubId] - The vault sub id for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src6::Withdraw; + /// + /// fn foo( + /// caller: Identity, + /// receiver: Identity, + /// underlying_asset: AssetId, + /// vault_sub_id: SubId, + /// withdrawn_amount: u64, + /// burned_shares: u64 + /// ) { + /// let my_event = Withdraw::new(caller, receiver, underlying_asset, vault_sub_id, withdrawn_amount, burned_shares); + /// assert(my_event.vault_sub_id() == vault_sub_id); + /// } + /// ``` + pub fn vault_sub_id(self) -> SubId { + self.vault_sub_id + } + + /// Returns the `withdrawn_amount` of the `Withdraw` event. + /// + /// # Returns + /// + /// * [u64] - The withdrawn amount for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src6::Withdraw; + /// + /// fn foo( + /// caller: Identity, + /// receiver: Identity, + /// underlying_asset: AssetId, + /// vault_sub_id: SubId, + /// withdrawn_amount: u64, + /// burned_shares: u64 + /// ) { + /// let my_event = Withdraw::new(caller, receiver, underlying_asset, vault_sub_id, withdrawn_amount, burned_shares); + /// assert(my_event.withdrawn_amount() == withdrawn_amount); + /// } + /// ``` + pub fn withdrawn_amount(self) -> u64 { + self.withdrawn_amount + } + + /// Returns the `burned_shares` of the `Withdraw` event. + /// + /// # Returns + /// + /// * [u64] - The burned shares for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src6::Withdraw; + /// + /// fn foo( + /// caller: Identity, + /// receiver: Identity, + /// underlying_asset: AssetId, + /// vault_sub_id: SubId, + /// withdrawn_amount: u64, + /// burned_shares: u64 + /// ) { + /// let my_event = Withdraw::new(caller, receiver, underlying_asset, vault_sub_id, withdrawn_amount, burned_shares); + /// assert(my_event.burned_shares() == burned_shares); + /// } + /// ``` + pub fn burned_shares(self) -> u64 { + self.burned_shares + } + + /// Logs the `Withdraw`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src6::Withdraw; + /// + /// fn foo( + /// caller: Identity, + /// receiver: Identity, + /// underlying_asset: AssetId, + /// vault_sub_id: SubId, + /// withdrawn_amount: u64, + /// burned_shares: u64 + /// ) { + /// let my_event = Withdraw::new(caller, receiver, underlying_asset, vault_sub_id, withdrawn_amount, burned_shares); + /// my_event.log(); + /// } + /// ``` + pub fn log(self) { + log(self); + } +} diff --git a/standards/src/src7.sw b/standards/src/src7.sw index 9bd030ed..e8a0dccb 100644 --- a/standards/src/src7.sw +++ b/standards/src/src7.sw @@ -17,13 +17,13 @@ abi SRC7 { /// # Examples /// /// ```sway - /// use src7::{SRC7, Metadata}; + /// use standards::src7::{SRC7, Metadata}; /// use std::string::String; /// /// fn foo(contract_id: ContractId, asset: AssetId) { - /// let contract_abi = abi(SRC7, contract_id); + /// let contract_abi = abi(SRC7, contract_id.bits()); /// let key = String::from_ascii_str("image"); - /// let data = contract_abi.metadata(asset, key); + /// let result_metadata: Option = contract_abi.metadata(asset, key); /// assert(data.is_some()); /// } /// ``` @@ -74,3 +74,147 @@ impl core::ops::Eq for Metadata { } } } + +impl core::ops::Eq for SetMetadataEvent { + fn eq(self, other: Self) -> bool { + self.asset == other.asset && self.metadata == other.metadata && self.key == other.key && self.sender == other.sender + } +} + +impl SetMetadataEvent { + /// Returns a new `SetMetadataEvent` event. + /// + /// # Arguments + /// + /// * `asset`: [AssetId] - The asset for which metadata is set. + /// * `metadata`: [Option] - The Metadata that is set. + /// * `ket`: [String] - The key used for the metadata. + /// * `sender`: [Identity] - The caller that set the metadata. + /// + /// # Returns + /// + /// * [SetMetadataEvent] - The new `SetMetadataEvent` event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src7::SetMetadataEvent; + /// + /// fn foo(asset: AssetId, metadata: Option, key: String, sender: Identity) { + /// let my_set_metadata_event = SetMetadataEvent::new(asset, metadata, key, sender); + /// assert(my_set_metadata_event.asset == asset); + /// assert(my_set_metadata_event.metadata == metadata); + /// assert(my_set_metadata_event.key == key); + /// assert(my_set_metadata_event.sender == sender); + /// } + /// ``` + pub fn new( + asset: AssetId, + metadata: Option, + key: String, + sender: Identity, + ) -> Self { + Self { + asset, + metadata, + key, + sender, + } + } + + /// Returns the asset of the `SetMetadataEvent` event. + /// + /// # Returns + /// + /// * [AssetId] - The asset for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src7::SetMetadataEvent; + /// + /// fn foo(asset: AssetId, metadata: Option, key: String, sender: Identity) { + /// let my_set_metadata_event = SetMetadataEvent::new(asset, metadata, key, sender); + /// assert(my_set_metadata_event.asset() == asset); + /// } + /// ``` + pub fn asset(self) -> AssetId { + self.asset + } + + /// Returns the metadata of the `SetMetadataEvent` event. + /// + /// # Returns + /// + /// * [Option] - The metadata for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src7::SetMetadataEvent; + /// + /// fn foo(asset: AssetId, metadata: Option, key: String, sender: Identity) { + /// let my_set_metadata_event = SetMetadataEvent::new(asset, metadata, key, sender); + /// assert(my_set_metadata_event.metadata() == metadata); + /// } + /// ``` + pub fn metadata(self) -> Option { + self.metadata + } + + /// Returns the key of the `SetMetadataEvent` event. + /// + /// # Returns + /// + /// * [String] - The key for the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src7::SetMetadataEvent; + /// + /// fn foo(asset: AssetId, metadata: Option, key: String, sender: Identity) { + /// let my_set_metadata_event = SetMetadataEvent::new(asset, metadata, key, sender); + /// assert(my_set_metadata_event.key() == key); + /// } + /// ``` + pub fn key(self) -> String { + self.key + } + + /// Returns the sender of the `SetMetadataEvent` event. + /// + /// # Returns + /// + /// * [Identity] - The sender of the event. + /// + /// # Examples + /// + /// ```sway + /// use standards::src7::SetMetadataEvent; + /// + /// fn foo(asset: AssetId, metadata: Option, key: String, sender: Identity) { + /// let my_set_metadata_event = SetMetadataEvent::new(asset, metadata, key, sender); + /// assert(my_set_metadata_event.sender() == sender); + /// } + /// ``` + pub fn sender(self) -> Identity { + self.sender + } + + /// Logs the `SetMetadataEvent`. + /// + /// # Examples + /// + /// ```sway + /// use standards::src7::SetMetadataEvent; + /// + /// fn foo(asset: AssetId, metadata: Option, key: String, sender: Identity) { + /// let my_event = SetMetadataEvent::new(asset, metadata, key, sender); + /// my_event.log(); + /// } + /// ``` + pub fn log(self) { + log(self); + } +}