diff --git a/app/src/features/editor/examples/examples.test.ts b/app/src/features/editor/examples/examples.test.ts index efe7962..21d5db3 100644 --- a/app/src/features/editor/examples/examples.test.ts +++ b/app/src/features/editor/examples/examples.test.ts @@ -55,6 +55,6 @@ describe(`test examples`, () => { expect(bytecode).toBeDefined(); expect(storageSlots).toBeDefined(); expect(forcVersion).toBeDefined(); - }, 10000); + }, 40000); }); }); diff --git a/app/src/features/editor/examples/sway/src20.ts b/app/src/features/editor/examples/sway/src20.ts index ef3c57d..0336552 100644 --- a/app/src/features/editor/examples/sway/src20.ts +++ b/app/src/features/editor/examples/sway/src20.ts @@ -1,8 +1,7 @@ export const EXAMPLE_SWAY_CONTRACT_SRC20 = `contract; -use ownership; use src3::SRC3; -use src5::SRC5; +use src5::{SRC5, State, AccessError}; use src20::SRC20; use std::{ asset::{ @@ -10,6 +9,7 @@ use std::{ mint_to, }, call_frames::{ + contract_id, msg_asset_id, }, constants::DEFAULT_SUB_ID, @@ -17,12 +17,9 @@ use std::{ string::String, }; -abi NativeAsset { +abi Constructor { #[storage(read, write)] fn constructor(owner_: Identity); - - #[storage(read, write)] - fn transferOwnership(owner_: Identity); } configurable { @@ -37,6 +34,9 @@ configurable { storage { /// The total supply of the asset minted by this contract. total_supply: u64 = 0, + + /// Owner. + owner: State = State::Uninitialized, } impl SRC20 for Contract { @@ -82,23 +82,26 @@ impl SRC20 for Contract { } } -impl NativeAsset for Contract { +#[storage(read)] +fn is_owner() { + require( + storage.owner.read() == State::Initialized(msg_sender().unwrap()), + AccessError::NotOwner, + ); +} + +impl Constructor for Contract { #[storage(read, write)] fn constructor(owner_: Identity) { require(storage.owner.read() == State::Uninitialized, "owner-initialized"); - ownership::initialize_ownership(owner_); - } - - #[storage(read, write)] - fn transferOwner(owner_: Identity) { - ownership::transfer_ownership(owner_); + storage.owner.write(State::Initialized(owner_)); } } impl SRC5 for Contract { #[storage(read)] fn owner() -> State { - _owner() + storage.owner.read() } } @@ -106,7 +109,7 @@ impl SRC3 for Contract { #[storage(read, write)] fn mint(recipient: Identity, sub_id: SubId, amount: u64) { require(sub_id == DEFAULT_SUB_ID, "Incorrect Sub Id"); - ownership::only_owner(); + is_owner(); // Increment total supply of the asset and mint to the recipient. storage @@ -123,7 +126,7 @@ impl SRC3 for Contract { msg_asset_id() == AssetId::default(), "Incorrect asset provided", ); - ownership::only_owner(); + is_owner(); // Decrement total supply of the asset and burn. storage diff --git a/projects/swaypad/Forc.lock b/projects/swaypad/Forc.lock index 25a0b03..8e12bdf 100644 --- a/projects/swaypad/Forc.lock +++ b/projects/swaypad/Forc.lock @@ -2,14 +2,6 @@ name = "core" source = "path+from-root-B672DC9E3D340CD2" -[[package]] -name = "ownership" -source = "git+https://github.com/FuelLabs/sway-libs?tag=v0.18.0#8d196e9379463d4596ac582a20a84ed52ff58c69" -dependencies = [ - "src_5", - "std", -] - [[package]] name = "src20" source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.3.3#4198b4b07449ad16104cc8a0501f3013670fdcfd" @@ -25,11 +17,6 @@ name = "src5" source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.3.3#4198b4b07449ad16104cc8a0501f3013670fdcfd" dependencies = ["std"] -[[package]] -name = "src_5" -source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.2.2#6989cf8224b0d8aabea62f3d3c648fc754948705" -dependencies = ["std"] - [[package]] name = "std" source = "git+https://github.com/fuellabs/sway?tag=v0.49.2#a70c746d27b3300beef896ccd1dcce1299836192" @@ -39,7 +26,6 @@ dependencies = ["core"] name = "swaypad" source = "member" dependencies = [ - "ownership", "src20", "src3", "src5", diff --git a/projects/swaypad/Forc.toml b/projects/swaypad/Forc.toml index 5dccd06..0c20011 100644 --- a/projects/swaypad/Forc.toml +++ b/projects/swaypad/Forc.toml @@ -5,7 +5,6 @@ license = "Apache-2.0" name = "swaypad" [dependencies] -ownership = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.18.0" } src3 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.3.3" } src5 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.3.3" } src20 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.3.3" }