diff --git a/.github/workflows/e2e-tests-contracts.yml b/.github/workflows/e2e-tests-contracts.yml index 97895a8c3d..0840531f52 100644 --- a/.github/workflows/e2e-tests-contracts.yml +++ b/.github/workflows/e2e-tests-contracts.yml @@ -58,7 +58,7 @@ jobs: run: | cargo install cargo-dylint dylint-link --force # revision merging Hans's PR changes [fix for node URL parsing ] - cargo install --git https://github.com/paritytech/cargo-contract.git --rev 5e6f941805e3d6032dbfa17771a887a362cb3460 --force + cargo install --git https://github.com/paritytech/cargo-contract.git --rev 2b1758756de59bd81e7bed5f8429d364f281cb9a --force - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 diff --git a/contracts/README.md b/contracts/README.md index 4e77403efb..66d902fc25 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -46,7 +46,7 @@ Game continues in perpetuity (but in practice as long as there are accounts that - Tokens are continuously minted at the end of each iteration - Players are rewarded for playing, with the ultimate goal of being the Pressiah (the last person to click the button) - Reward rules: - - If you’re not ThePressiah, you get _k_ tokens if you pressed the button as the _k-th_ person in a row. + - If you're not ThePressiah, you get _k_ tokens if you pressed the button as the _k-th_ person in a row. - ThePressiah gets 20% of the total reward pool. # Development @@ -54,7 +54,7 @@ Game continues in perpetuity (but in practice as long as there are accounts that ## Prerequisites - Rust nightly -- cargo-contract with bug fixes around URL parsing: `cargo install --git https://github.com/paritytech/cargo-contract.git --rev 5e6f941805e3d6032dbfa17771a887a362cb3460 --force` +- cargo-contract with bug fixes around URL parsing: `cargo install --git https://github.com/paritytech/cargo-contract.git --rev 2b1758756de59bd81e7bed5f8429d364f281cb9a --force` ## Instructions @@ -74,7 +74,7 @@ Specifically it will: - Deploy the contracts. - Set access control on them. -- Make neccessary token transfers. +- Make necessary token transfers. Third `test.sh` script plays the game from two well-known dev addresses. diff --git a/contracts/access_control/roles.rs b/contracts/access_control/roles.rs index ce607a9160..b8019d7e0e 100644 --- a/contracts/access_control/roles.rs +++ b/contracts/access_control/roles.rs @@ -10,10 +10,14 @@ use scale::{Decode, Encode}; pub enum Role { /// Indicates a superuser. Admin(AccountId), - /// Indicates account can terminate a contract. + /// Indicates account that can terminate a contract. Owner(AccountId), - /// Indicates account can initialize a contract from a given code hash. + /// Indicates account that can initialize a contract from a given code hash. Initializer(Hash), - /// Indicates account can add liquidity to a DEX contract (call certain functions) + /// Indicates account that can add liquidity to a DEX contract (call certain functions) LiquidityProvider(AccountId), + /// Indicates account that can mint tokens of a given token contract, + Minter(AccountId), + /// Indicates account that can burn tokens of a given token contract, + Burner(AccountId), } diff --git a/contracts/button/Cargo.lock b/contracts/button/Cargo.lock index 783dec454f..6657041546 100644 --- a/contracts/button/Cargo.lock +++ b/contracts/button/Cargo.lock @@ -558,6 +558,45 @@ dependencies = [ "autocfg", ] +[[package]] +name = "obce" +version = "0.1.0" +source = "git+https://github.com/Supercolony-net/obce?branch=polkadot-v0.9.29#9843e2a3e91e7c29a9b21dde7ead3299e9d3c0fb" +dependencies = [ + "ink_engine", + "ink_env", + "ink_lang", + "ink_metadata", + "ink_prelude", + "ink_primitives", + "ink_storage", + "obce-macro", + "parity-scale-codec", + "scale-info", +] + +[[package]] +name = "obce-codegen" +version = "0.1.0" +source = "git+https://github.com/Supercolony-net/obce?branch=polkadot-v0.9.29#9843e2a3e91e7c29a9b21dde7ead3299e9d3c0fb" +dependencies = [ + "blake2 0.10.4", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "obce-macro" +version = "0.1.0" +source = "git+https://github.com/Supercolony-net/obce?branch=polkadot-v0.9.29#9843e2a3e91e7c29a9b21dde7ead3299e9d3c0fb" +dependencies = [ + "obce-codegen", + "proc-macro2", + "syn", + "synstructure", +] + [[package]] name = "once_cell" version = "1.14.0" @@ -572,8 +611,8 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openbrush" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "ink_env", "ink_lang", @@ -589,8 +628,8 @@ dependencies = [ [[package]] name = "openbrush_contracts" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "ink_env", "ink_lang", @@ -599,19 +638,21 @@ dependencies = [ "ink_primitives", "ink_storage", "openbrush_lang", + "pallet-assets-chain-extension", "parity-scale-codec", "scale-info", ] [[package]] name = "openbrush_lang" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "const_format", "ink_env", "ink_lang", "ink_metadata", + "ink_prelude", "ink_primitives", "ink_storage", "openbrush_lang_macro", @@ -622,8 +663,8 @@ dependencies = [ [[package]] name = "openbrush_lang_codegen" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "blake2 0.9.2", "cargo_metadata", @@ -641,8 +682,8 @@ dependencies = [ [[package]] name = "openbrush_lang_macro" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "openbrush_lang_codegen", "proc-macro2", @@ -650,6 +691,19 @@ dependencies = [ "synstructure", ] +[[package]] +name = "pallet-assets-chain-extension" +version = "0.1.1" +source = "git+https://github.com/Supercolony-net/pallet-assets-chain-extension#83ff37cb0d19d15a881ecab2c922596039c8358d" +dependencies = [ + "ink_metadata", + "ink_primitives", + "ink_storage", + "obce", + "parity-scale-codec", + "scale-info", +] + [[package]] name = "parity-scale-codec" version = "3.2.1" diff --git a/contracts/button/Cargo.toml b/contracts/button/Cargo.toml index b82e32e98d..b8be127954 100644 --- a/contracts/button/Cargo.toml +++ b/contracts/button/Cargo.toml @@ -19,7 +19,7 @@ access_control = { path = "../access_control", default-features = false, feature game_token = { path = "../game_token", default-features = false, features = ["ink-as-dependency"] } ticket_token = { path = "../ticket_token", default-features = false, features = ["ink-as-dependency"] } marketplace = { path = "../marketplace", default-features = false, features = ["ink-as-dependency"] } -openbrush = { git = "https://github.com/Supercolony-net/openbrush-contracts.git", rev = "8a20f95", default-features = false, features = ["psp22"] } +openbrush = { git = "https://github.com/Supercolony-net/openbrush-contracts.git", rev = "15e6366", default-features = false, features = ["psp22"] } [lib] name = "button" diff --git a/contracts/button/lib.rs b/contracts/button/lib.rs index ee1369cb1d..202fc4a248 100644 --- a/contracts/button/lib.rs +++ b/contracts/button/lib.rs @@ -7,7 +7,7 @@ use ink_lang as ink; #[ink::contract] mod button_game { use access_control::{roles::Role, traits::AccessControlled, ACCESS_CONTROL_PUBKEY}; - use game_token::MINT_TO_SELECTOR; + use game_token::MINT_SELECTOR; use ink_env::{ call::{build_call, Call, ExecutionInput, Selector}, CallFlags, DefaultEnvironment, Error as InkEnvError, @@ -336,7 +336,7 @@ mod button_game { ExecutionInput::new(Selector::new(TRANSFER_SELECTOR)) .push_arg(self.marketplace) .push_arg(self.held_tickets()?) - .push_arg(vec![0x0]), + .push_arg::>(vec![]), ) .call_flags(CallFlags::default().set_allow_reentry(true)) .returns::>() @@ -414,7 +414,7 @@ mod button_game { .push_arg(from) .push_arg(to) .push_arg(value) - .push_arg(vec![0x0]), + .push_arg::>(vec![]), ) .call_flags(CallFlags::default().set_allow_reentry(true)) .returns::>() @@ -429,7 +429,7 @@ mod button_game { build_call::() .call_type(Call::new().callee(self.reward_token)) .exec_input( - ExecutionInput::new(Selector::new(MINT_TO_SELECTOR)) + ExecutionInput::new(Selector::new(MINT_SELECTOR)) .push_arg(to) .push_arg(amount), ) diff --git a/contracts/env/dev b/contracts/env/dev index b1fe8364fd..a50c1b38cf 100644 --- a/contracts/env/dev +++ b/contracts/env/dev @@ -8,4 +8,7 @@ export AUTHORITY_SEED=//Alice export LIFETIME=20 # mint this many ticket tokens -export TOTAL_BALANCE=1000 +export TICKET_BALANCE=100 + +# initial price of ticket on the marketplace +export INITIAL_PRICE=69 diff --git a/contracts/game_token/Cargo.lock b/contracts/game_token/Cargo.lock index 1febd0fb6c..3f322fe996 100644 --- a/contracts/game_token/Cargo.lock +++ b/contracts/game_token/Cargo.lock @@ -519,6 +519,45 @@ dependencies = [ "autocfg", ] +[[package]] +name = "obce" +version = "0.1.0" +source = "git+https://github.com/Supercolony-net/obce?branch=polkadot-v0.9.29#9843e2a3e91e7c29a9b21dde7ead3299e9d3c0fb" +dependencies = [ + "ink_engine", + "ink_env", + "ink_lang", + "ink_metadata", + "ink_prelude", + "ink_primitives", + "ink_storage", + "obce-macro", + "parity-scale-codec", + "scale-info", +] + +[[package]] +name = "obce-codegen" +version = "0.1.0" +source = "git+https://github.com/Supercolony-net/obce?branch=polkadot-v0.9.29#9843e2a3e91e7c29a9b21dde7ead3299e9d3c0fb" +dependencies = [ + "blake2 0.10.4", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "obce-macro" +version = "0.1.0" +source = "git+https://github.com/Supercolony-net/obce?branch=polkadot-v0.9.29#9843e2a3e91e7c29a9b21dde7ead3299e9d3c0fb" +dependencies = [ + "obce-codegen", + "proc-macro2", + "syn", + "synstructure", +] + [[package]] name = "opaque-debug" version = "0.3.0" @@ -527,8 +566,8 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openbrush" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "ink_env", "ink_lang", @@ -544,8 +583,8 @@ dependencies = [ [[package]] name = "openbrush_contracts" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "ink_env", "ink_lang", @@ -554,19 +593,21 @@ dependencies = [ "ink_primitives", "ink_storage", "openbrush_lang", + "pallet-assets-chain-extension", "parity-scale-codec", "scale-info", ] [[package]] name = "openbrush_lang" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "const_format", "ink_env", "ink_lang", "ink_metadata", + "ink_prelude", "ink_primitives", "ink_storage", "openbrush_lang_macro", @@ -577,8 +618,8 @@ dependencies = [ [[package]] name = "openbrush_lang_codegen" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "blake2 0.9.2", "cargo_metadata", @@ -596,8 +637,8 @@ dependencies = [ [[package]] name = "openbrush_lang_macro" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "openbrush_lang_codegen", "proc-macro2", @@ -605,6 +646,19 @@ dependencies = [ "synstructure", ] +[[package]] +name = "pallet-assets-chain-extension" +version = "0.1.1" +source = "git+https://github.com/Supercolony-net/pallet-assets-chain-extension#83ff37cb0d19d15a881ecab2c922596039c8358d" +dependencies = [ + "ink_metadata", + "ink_primitives", + "ink_storage", + "obce", + "parity-scale-codec", + "scale-info", +] + [[package]] name = "parity-scale-codec" version = "3.1.5" diff --git a/contracts/game_token/Cargo.toml b/contracts/game_token/Cargo.toml index e5770239c5..a13dbaefc8 100644 --- a/contracts/game_token/Cargo.toml +++ b/contracts/game_token/Cargo.toml @@ -17,7 +17,7 @@ ink_engine = { version = "~3.3.0", default-features = false, optional = true } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2", default-features = false, features = ["derive"], optional = true } -openbrush = { git = "https://github.com/Supercolony-net/openbrush-contracts.git", rev = "8a20f95", default-features = false, features = ["psp22"] } +openbrush = { git = "https://github.com/Supercolony-net/openbrush-contracts.git", rev = "15e6366", default-features = false, features = ["psp22"] } access_control = { path = "../access_control", default-features = false, features = ["ink-as-dependency"] } [lib] diff --git a/contracts/game_token/lib.rs b/contracts/game_token/lib.rs index eeecacacb3..411205961c 100644 --- a/contracts/game_token/lib.rs +++ b/contracts/game_token/lib.rs @@ -2,7 +2,7 @@ #![feature(min_specialization)] pub use crate::game_token::{ - ALLOWANCE_SELECTOR, BALANCE_OF_SELECTOR, MINT_TO_SELECTOR, TRANSFER_FROM_SELECTOR, + ALLOWANCE_SELECTOR, BALANCE_OF_SELECTOR, BURN_SELECTOR, MINT_SELECTOR, TRANSFER_FROM_SELECTOR, TRANSFER_SELECTOR, }; @@ -17,7 +17,10 @@ pub mod game_token { use ink_prelude::{format, string::String}; use ink_storage::traits::SpreadAllocate; use openbrush::{ - contracts::psp22::{extensions::metadata::*, Internal}, + contracts::psp22::{ + extensions::{burnable::*, metadata::*, mintable::*}, + Internal, + }, traits::Storage, }; @@ -25,8 +28,8 @@ pub mod game_token { pub const TRANSFER_SELECTOR: [u8; 4] = [0xdb, 0x20, 0xf9, 0xf5]; pub const TRANSFER_FROM_SELECTOR: [u8; 4] = [0x54, 0xb3, 0xc7, 0x6e]; pub const ALLOWANCE_SELECTOR: [u8; 4] = [0x4d, 0x47, 0xd9, 0x21]; - // TODO : use correct selector when mint/burn is implemented - pub const MINT_TO_SELECTOR: [u8; 4] = [0x0, 0x0, 0x0, 0x0]; + pub const MINT_SELECTOR: [u8; 4] = [0xfc, 0x3c, 0x75, 0xd4]; + pub const BURN_SELECTOR: [u8; 4] = [0x7a, 0x9d, 0xa5, 0x10]; #[ink(storage)] #[derive(Default, SpreadAllocate, Storage)] @@ -43,6 +46,30 @@ pub mod game_token { impl PSP22Metadata for GameToken {} + impl PSP22Mintable for GameToken { + #[ink(message)] + fn mint(&mut self, account: AccountId, amount: Balance) -> Result<()> { + let caller = self.env().caller(); + let this = self.env().account_id(); + let required_role = Role::Minter(this); + + self.check_role(caller, required_role)?; + self._mint_to(account, amount) + } + } + + impl PSP22Burnable for GameToken { + #[ink(message)] + fn burn(&mut self, account: AccountId, amount: Balance) -> Result<()> { + let caller = self.env().caller(); + let this = self.env().account_id(); + let required_role = Role::Burner(this); + + self.check_role(caller, required_role)?; + self._burn_from(account, amount) + } + } + // emit events // https://github.com/w3f/PSPs/blob/master/PSPs/psp-22.md impl Internal for GameToken { @@ -114,7 +141,7 @@ pub mod game_token { /// /// Will revert if called from an account without a proper role #[ink(constructor)] - pub fn new(name: String, symbol: String, total_supply: Balance) -> Self { + pub fn new(name: String, symbol: String) -> Self { let caller = Self::env().caller(); let code_hash = Self::env() .own_code_hash() @@ -126,20 +153,18 @@ pub mod game_token { caller, required_role, |why: InkEnvError| { - PSP22Error::Custom(format!("Calling access control has failed: {:?}", why)) + PSP22Error::Custom( + format!("Calling access control has failed: {:?}", why).into(), + ) }, - |role: Role| PSP22Error::Custom(format!("MissingRole:{:?}", role)), + |role: Role| PSP22Error::Custom(format!("MissingRole:{:?}", role).into()), ); match role_check { Ok(_) => ink_lang::codegen::initialize_contract(|instance: &mut GameToken| { - instance.metadata.name = Some(name); - instance.metadata.symbol = Some(symbol); + instance.metadata.name = Some(name.into()); + instance.metadata.symbol = Some(symbol.into()); instance.metadata.decimals = 12; - instance - ._mint(instance.env().caller(), total_supply) - .expect("Should mint"); - instance.access_control = AccountId::from(ACCESS_CONTROL_PUBKEY); }), Err(why) => panic!("Could not initialize the contract {:?}", why), @@ -175,9 +200,11 @@ pub mod game_token { account, role, |why: InkEnvError| { - PSP22Error::Custom(format!("Calling access control has failed: {:?}", why)) + PSP22Error::Custom( + format!("Calling access control has failed: {:?}", why).into(), + ) }, - |role: Role| PSP22Error::Custom(format!("MissingRole:{:?}", role)), + |role: Role| PSP22Error::Custom(format!("MissingRole:{:?}", role).into()), ) } @@ -199,7 +226,7 @@ pub mod game_token { #[ink(message, selector = 10)] pub fn code_hash(&self) -> Result { Self::env().own_code_hash().map_err(|why| { - PSP22Error::Custom(format!("Can't retrieve own code hash: {:?}", why)) + PSP22Error::Custom(format!("Can't retrieve own code hash: {:?}", why).into()) }) } } diff --git a/contracts/marketplace/Cargo.lock b/contracts/marketplace/Cargo.lock index b268550f02..65dde5f2d6 100644 --- a/contracts/marketplace/Cargo.lock +++ b/contracts/marketplace/Cargo.lock @@ -539,6 +539,45 @@ dependencies = [ "autocfg", ] +[[package]] +name = "obce" +version = "0.1.0" +source = "git+https://github.com/Supercolony-net/obce?branch=polkadot-v0.9.29#9843e2a3e91e7c29a9b21dde7ead3299e9d3c0fb" +dependencies = [ + "ink_engine", + "ink_env", + "ink_lang", + "ink_metadata", + "ink_prelude", + "ink_primitives", + "ink_storage", + "obce-macro", + "parity-scale-codec", + "scale-info", +] + +[[package]] +name = "obce-codegen" +version = "0.1.0" +source = "git+https://github.com/Supercolony-net/obce?branch=polkadot-v0.9.29#9843e2a3e91e7c29a9b21dde7ead3299e9d3c0fb" +dependencies = [ + "blake2 0.10.4", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "obce-macro" +version = "0.1.0" +source = "git+https://github.com/Supercolony-net/obce?branch=polkadot-v0.9.29#9843e2a3e91e7c29a9b21dde7ead3299e9d3c0fb" +dependencies = [ + "obce-codegen", + "proc-macro2", + "syn", + "synstructure", +] + [[package]] name = "opaque-debug" version = "0.3.0" @@ -547,8 +586,8 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openbrush" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "ink_env", "ink_lang", @@ -564,8 +603,8 @@ dependencies = [ [[package]] name = "openbrush_contracts" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "ink_env", "ink_lang", @@ -574,19 +613,21 @@ dependencies = [ "ink_primitives", "ink_storage", "openbrush_lang", + "pallet-assets-chain-extension", "parity-scale-codec", "scale-info", ] [[package]] name = "openbrush_lang" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "const_format", "ink_env", "ink_lang", "ink_metadata", + "ink_prelude", "ink_primitives", "ink_storage", "openbrush_lang_macro", @@ -597,8 +638,8 @@ dependencies = [ [[package]] name = "openbrush_lang_codegen" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "blake2 0.9.2", "cargo_metadata", @@ -616,8 +657,8 @@ dependencies = [ [[package]] name = "openbrush_lang_macro" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "openbrush_lang_codegen", "proc-macro2", @@ -625,6 +666,19 @@ dependencies = [ "synstructure", ] +[[package]] +name = "pallet-assets-chain-extension" +version = "0.1.1" +source = "git+https://github.com/Supercolony-net/pallet-assets-chain-extension#83ff37cb0d19d15a881ecab2c922596039c8358d" +dependencies = [ + "ink_metadata", + "ink_primitives", + "ink_storage", + "obce", + "parity-scale-codec", + "scale-info", +] + [[package]] name = "parity-scale-codec" version = "3.1.5" diff --git a/contracts/marketplace/Cargo.toml b/contracts/marketplace/Cargo.toml index c8c7f8443a..3baab06bc8 100644 --- a/contracts/marketplace/Cargo.toml +++ b/contracts/marketplace/Cargo.toml @@ -17,7 +17,7 @@ ink_engine = { version = "~3.3.0", default-features = false, optional = true } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2", default-features = false, features = ["derive"], optional = true } -openbrush = { git = "https://github.com/Supercolony-net/openbrush-contracts.git", rev = "8a20f95", default-features = false, features = ["psp22"] } +openbrush = { git = "https://github.com/Supercolony-net/openbrush-contracts.git", rev = "15e6366", default-features = false, features = ["psp22"] } access_control = { path = "../access_control", default-features = false, features = ["ink-as-dependency"] } game_token = { path = "../game_token", default-features = false, features = ["ink-as-dependency"] } ticket_token = { path = "../ticket_token", default-features = false, features = ["ink-as-dependency"] } diff --git a/contracts/marketplace/lib.rs b/contracts/marketplace/lib.rs index e3a8d85fbb..0784a646c1 100644 --- a/contracts/marketplace/lib.rs +++ b/contracts/marketplace/lib.rs @@ -26,7 +26,7 @@ pub const RESET_SELECTOR: [u8; 4] = [0x00, 0x00, 0x00, 0x01]; #[ink::contract] pub mod marketplace { use access_control::{roles::Role, traits::AccessControlled, ACCESS_CONTROL_PUBKEY}; - use game_token::TRANSFER_FROM_SELECTOR as TRANSFER_FROM_GAME_TOKEN_SELECTOR; + use game_token::BURN_SELECTOR as REWARD_BURN_SELECTOR; use ink_env::{ call::{build_call, Call, ExecutionInput, Selector}, CallFlags, @@ -267,11 +267,9 @@ pub mod marketplace { build_call::() .call_type(Call::new().callee(self.reward_token)) .exec_input( - ExecutionInput::new(Selector::new(TRANSFER_FROM_GAME_TOKEN_SELECTOR)) + ExecutionInput::new(Selector::new(REWARD_BURN_SELECTOR)) .push_arg(from) - .push_arg(self.env().account_id()) - .push_arg(amount) - .push_arg(DUMMY_DATA), + .push_arg(amount), ) .call_flags(CallFlags::default().set_allow_reentry(true)) .returns::>() diff --git a/contracts/scripts/clean.sh b/contracts/scripts/clean.sh index 1bcdf01f3e..9ff672a429 100755 --- a/contracts/scripts/clean.sh +++ b/contracts/scripts/clean.sh @@ -10,7 +10,7 @@ function terminate_contract { local contract_address=$(get_address $contract_name) cd "$CONTRACTS_PATH"/"$contract_dir" - cargo contract call --url "$NODE" --contract $contract_address --message terminate --suri "$AUTHORITY_SEED" + cargo contract call --url "$NODE" --contract $contract_address --message terminate --suri "$AUTHORITY_SEED" --skip-confirm } function get_address { diff --git a/contracts/scripts/deploy.sh b/contracts/scripts/deploy.sh index 88b16a1641..203cb5f06f 100755 --- a/contracts/scripts/deploy.sh +++ b/contracts/scripts/deploy.sh @@ -24,14 +24,15 @@ function upload_contract { # --- UPLOAD CONTRACT CODE code_hash=$(cargo contract upload --url "$NODE" --suri "$AUTHORITY_SEED") - code_hash=$(echo "$code_hash" | grep hash | tail -1 | cut -c 15-) + echo "$code_hash" + code_hash=$(echo "$code_hash" | grep hash | tail -1 | cut -c 14-) echo "$contract_name code hash: $code_hash" cd "$CONTRACTS_PATH"/access_control # Set the initializer of the contract - cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$AUTHORITY" 'Initializer('"$code_hash"')' --suri "$AUTHORITY_SEED" + cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$AUTHORITY" 'Initializer('"$code_hash"')' --suri "$AUTHORITY_SEED" --skip-confirm eval $__resultvar="'$code_hash'" } @@ -47,8 +48,8 @@ function deploy_ticket_token { cd "$CONTRACTS_PATH"/ticket_token - local contract_address=$(cargo contract instantiate --url "$NODE" --constructor new --args \"$token_name\" \"$token_symbol\" "$TOTAL_BALANCE" --suri "$AUTHORITY_SEED" --salt "$salt") - local contract_address=$(echo "$contract_address" | grep Contract | tail -1 | cut -c 15-) + local contract_address=$(cargo contract instantiate --url "$NODE" --constructor new --args \"$token_name\" \"$token_symbol\" "$TICKET_BALANCE" --suri "$AUTHORITY_SEED" --salt "$salt" --skip-confirm) + local contract_address=$(echo "$contract_address" | grep Contract | tail -1 | cut -c 14-) echo "$token_symbol ticket contract instance address: $contract_address" @@ -57,7 +58,7 @@ function deploy_ticket_token { cd "$CONTRACTS_PATH"/access_control # set the admin and the owner of the contract instance - cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$AUTHORITY" 'Owner('"$contract_address"')' --suri "$AUTHORITY_SEED" + cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$AUTHORITY" 'Owner('"$contract_address"')' --suri "$AUTHORITY_SEED" --skip-confirm eval $__resultvar="'$contract_address'" } @@ -74,9 +75,8 @@ function deploy_game_token { cd "$CONTRACTS_PATH"/game_token - # TODO : remove balance when token is mintable - local contract_address=$(cargo contract instantiate --url "$NODE" --constructor new --args \"$token_name\" \"$token_symbol\" "$TOTAL_BALANCE" --suri "$AUTHORITY_SEED" --salt "$salt") - local contract_address=$(echo "$contract_address" | grep Contract | tail -1 | cut -c 15-) + local contract_address=$(cargo contract instantiate --url "$NODE" --constructor new --args \"$token_name\" \"$token_symbol\" --suri "$AUTHORITY_SEED" --salt "$salt" --skip-confirm) + local contract_address=$(echo "$contract_address" | grep Contract | tail -1 | cut -c 14-) echo "$token_symbol token contract instance address: $contract_address" @@ -85,9 +85,7 @@ function deploy_game_token { cd "$CONTRACTS_PATH"/access_control # set the owner of the contract instance - cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$AUTHORITY" 'Owner('"$contract_address"')' --suri "$AUTHORITY_SEED" - - # TODO : MINTER / BURNER roles + cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$AUTHORITY" 'Owner('"$contract_address"')' --suri "$AUTHORITY_SEED" --skip-confirm eval "$__resultvar='$contract_address'" } @@ -106,8 +104,8 @@ function deploy_button_game { cd "$CONTRACTS_PATH"/button - local contract_address=$(cargo contract instantiate --url "$NODE" --constructor new --args "$ticket_token" "$game_token" "$marketplace" "$LIFETIME" "$game_type" --suri "$AUTHORITY_SEED" --salt "$salt") - local contract_address=$(echo "$contract_address" | grep Contract | tail -1 | cut -c 15-) + local contract_address=$(cargo contract instantiate --url "$NODE" --constructor new --args "$ticket_token" "$game_token" "$marketplace" "$LIFETIME" "$game_type" --suri "$AUTHORITY_SEED" --salt "$salt" --skip-confirm) + local contract_address=$(echo "$contract_address" | grep Contract | tail -1 | cut -c 14-) echo "$game_type contract instance address: $contract_address" @@ -115,8 +113,9 @@ function deploy_button_game { cd "$CONTRACTS_PATH"/access_control - cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$AUTHORITY" 'Owner('"$contract_address"')' --suri "$AUTHORITY_SEED" - cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$contract_address" 'Admin('"$marketplace"')' --suri "$AUTHORITY_SEED" + cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$AUTHORITY" 'Owner('"$contract_address"')' --suri "$AUTHORITY_SEED" --skip-confirm + cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$contract_address" 'Admin('"$marketplace"')' --suri "$AUTHORITY_SEED" --skip-confirm + cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$contract_address" 'Minter('"$game_token"')' --suri "$AUTHORITY_SEED" --skip-confirm eval "$__resultvar='$contract_address'" } @@ -134,15 +133,15 @@ function deploy_marketplace { cd "$CONTRACTS_PATH"/marketplace local blocks_per_hour=3600 - local initial_price="$TOTAL_BALANCE" + local initial_price="$INITIAL_PRICE" local min_price=1 local sale_price_multiplier=2 local contract_address contract_address=$(cargo contract instantiate --url "$NODE" --constructor new \ --args "$ticket_token" "$game_token" "$initial_price" "$min_price" "$sale_price_multiplier" "$blocks_per_hour" \ - --suri "$AUTHORITY_SEED" --salt "$salt") - contract_address=$(echo "$contract_address" | grep Contract | tail -1 | cut -c 15-) + --suri "$AUTHORITY_SEED" --salt "$salt" --skip-confirm) + contract_address=$(echo "$contract_address" | grep Contract | tail -1 | cut -c 14-) echo "Marketplace for $contract_name instance address: $contract_address" @@ -150,8 +149,9 @@ function deploy_marketplace { cd "$CONTRACTS_PATH"/access_control - cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$AUTHORITY" 'Owner('"$contract_address"')' --suri "$AUTHORITY_SEED" - cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$AUTHORITY" 'Admin('"$contract_address"')' --suri "$AUTHORITY_SEED" + cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$AUTHORITY" 'Owner('"$contract_address"')' --suri "$AUTHORITY_SEED" --skip-confirm + cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$AUTHORITY" 'Admin('"$contract_address"')' --suri "$AUTHORITY_SEED" --skip-confirm + cargo contract call --url "$NODE" --contract "$ACCESS_CONTROL" --message grant_role --args "$contract_address" 'Burner('"$game_token"')' --suri "$AUTHORITY_SEED" --skip-confirm eval "$__resultvar='$contract_address'" } @@ -184,7 +184,6 @@ cargo contract build --release cd "$CONTRACTS_PATH"/button cargo contract build --release - cd "$CONTRACTS_PATH"/marketplace cargo contract build --release @@ -193,9 +192,9 @@ cargo contract build --release cd "$CONTRACTS_PATH"/access_control ACCESS_CONTROL_CODE_HASH=$(cargo contract upload --url "$NODE" --suri "$AUTHORITY_SEED") -ACCESS_CONTROL_CODE_HASH=$(echo "$ACCESS_CONTROL_CODE_HASH" | grep hash | tail -1 | cut -c 15-) -ACCESS_CONTROL=$(cargo contract instantiate --url "$NODE" --constructor new --suri "$AUTHORITY_SEED") -ACCESS_CONTROL=$(echo "$ACCESS_CONTROL" | grep Contract | tail -1 | cut -c 15-) +ACCESS_CONTROL_CODE_HASH=$(echo "$ACCESS_CONTROL_CODE_HASH" | grep hash | tail -1 | cut -c 14-) +ACCESS_CONTROL=$(cargo contract instantiate --url "$NODE" --constructor new --suri "$AUTHORITY_SEED" --skip-confirm) +ACCESS_CONTROL=$(echo "$ACCESS_CONTROL" | grep Contract | tail -1 | cut -c 14-) ACCESS_CONTROL_PUBKEY=$(docker run --rm --entrypoint "/bin/sh" "${NODE_IMAGE}" -c "aleph-node key inspect $ACCESS_CONTROL" | grep hex | cut -c 23- | cut -c 3-) echo "access control contract address: $ACCESS_CONTROL" diff --git a/contracts/scripts/test.sh b/contracts/scripts/test.sh index 9e2ea24fc8..0da59d04f2 100755 --- a/contracts/scripts/test.sh +++ b/contracts/scripts/test.sh @@ -16,51 +16,47 @@ function play { echo "sending ticket token" ${contract_name}_ticket "["$ticket_address"]" "to " $PLAYER1 - cargo contract call --url $NODE --contract $ticket_address --message PSP22::transfer --args $PLAYER1 1 "[0]" --suri $AUTHORITY_SEED + cargo contract call --url $NODE --contract $ticket_address --message PSP22::transfer --args $PLAYER1 1 "[0]" --suri $AUTHORITY_SEED --skip-confirm echo "sending ticket token" ${contract_name}_ticket "["$ticket_address"]" "to " $PLAYER2 - cargo contract call --url $NODE --contract $ticket_address --message PSP22::transfer --args $PLAYER2 1 "[0]" --suri $AUTHORITY_SEED + cargo contract call --url $NODE --contract $ticket_address --message PSP22::transfer --args $PLAYER2 1 "[0]" --suri $AUTHORITY_SEED --skip-confirm # give allowance for spending tickets to the game contract - cd "$CONTRACTS_PATH"/ticket_token - - echo "allowing" $contract_name "["$contract_address"]" "to spend up to" $TOTAL_BALANCE "of" ${contract_name}_ticket "["$ticket_address"]" "on behalf of" $PLAYER1 - - cargo contract call --url $NODE --contract $ticket_address --message PSP22::approve --args $contract_address $TOTAL_BALANCE --suri $PLAYER1_SEED - - echo "allowing" $contract_name "["$contract_address"]" "to spend up to" $TOTAL_BALANCE "of" ${contract_name}_ticket "["$ticket_address"]" "on behalf of" $PLAYER2 - - cargo contract call --url $NODE --contract $ticket_address --message PSP22::approve --args $contract_address $TOTAL_BALANCE --suri $PLAYER2_SEED - - # TODO : can't test before mint / burn for game tokens is implemented; uncomment when A0-1236 is done - - # # play the game - - # cd "$CONTRACTS_PATH"/$contract_name - - # echo "calling press for" $contract_name "["$contract_address"]" "by" $PLAYER1_SEED - - # cargo contract call --url $NODE --contract $contract_address --message IButtonGame::press --suri $PLAYER1_SEED - - # sleep 1 - - # echo "calling press for" $contract_name "["$contract_address "]" "by" $PLAYER2_SEED - - # cargo contract call --url $NODE --contract $contract_address --message IButtonGame::press --suri $PLAYER2_SEED - - # # --- WAIT FOR THE BUTTON DEATH - - # sleep $(($LIFETIME + 1)) - - # # --- TRIGGER GAME RESET - - # cd "$CONTRACTS_PATH"/$contract_name - - # cargo contract call --url $NODE --contract $contract_address --message IButtonGame::reset --suri $AUTHORITY_SEED - - # echo "Done playing" $contract_name + echo "allowing" $contract_name "["$contract_address"]" "to spend up to" $TICKET_BALANCE "of" ${contract_name}_ticket "["$ticket_address"]" "on behalf of" $PLAYER1 + + cargo contract call --url $NODE --contract $ticket_address --message PSP22::approve --args $contract_address $TICKET_BALANCE --suri $PLAYER1_SEED --skip-confirm + + echo "allowing" $contract_name "["$contract_address"]" "to spend up to" $TICKET_BALANCE "of" ${contract_name}_ticket "["$ticket_address"]" "on behalf of" $PLAYER2 + + cargo contract call --url $NODE --contract $ticket_address --message PSP22::approve --args $contract_address $TICKET_BALANCE --suri $PLAYER2_SEED --skip-confirm + +# TODO: uncomment when cargo contract doesn't break on parsing "foreign" events +# +# # play the game +# +# cd "$CONTRACTS_PATH"/button +# +# echo "calling press for" $contract_name "["$contract_address"]" "by" $PLAYER1_SEED +# +# cargo contract call --url $NODE --contract $contract_address --message press --suri $PLAYER1_SEED --skip-confirm +# +# sleep 1 +# +# echo "calling press for" $contract_name "["$contract_address "]" "by" $PLAYER2_SEED +# +# cargo contract call --url $NODE --contract $contract_address --message press --suri $PLAYER2_SEED --skip-confirm +# +# # --- WAIT FOR THE BUTTON DEATH +# +# sleep $(($LIFETIME + 1)) +# +# # --- TRIGGER GAME RESET +# +# cargo contract call --url $NODE --contract $contract_address --message reset --suri $AUTHORITY_SEED --skip-confirm +# +# echo "Done playing" $contract_name } # --- ARGUMENTS diff --git a/contracts/simple_dex/Cargo.toml b/contracts/simple_dex/Cargo.toml index 2f141e8076..8318177cca 100644 --- a/contracts/simple_dex/Cargo.toml +++ b/contracts/simple_dex/Cargo.toml @@ -17,7 +17,7 @@ ink_storage = { version = "~3.3.0", default-features = false } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2", default-features = false, features = ["derive"], optional = true } -openbrush = { git = "https://github.com/Supercolony-net/openbrush-contracts.git", rev = "8a20f95", default-features = false, features = ["psp22"] } +openbrush = { git = "https://github.com/Supercolony-net/openbrush-contracts.git", rev = "15e6366", default-features = false, features = ["psp22"] } access_control = { path = "../access_control", default-features = false, features = ["ink-as-dependency"] } game_token = { path = "../game_token", default-features = false, features = ["ink-as-dependency"] } diff --git a/contracts/ticket_token/Cargo.lock b/contracts/ticket_token/Cargo.lock index 05485f2ff7..2005b0aa6d 100644 --- a/contracts/ticket_token/Cargo.lock +++ b/contracts/ticket_token/Cargo.lock @@ -502,6 +502,45 @@ dependencies = [ "autocfg", ] +[[package]] +name = "obce" +version = "0.1.0" +source = "git+https://github.com/Supercolony-net/obce?branch=polkadot-v0.9.29#9843e2a3e91e7c29a9b21dde7ead3299e9d3c0fb" +dependencies = [ + "ink_engine", + "ink_env", + "ink_lang", + "ink_metadata", + "ink_prelude", + "ink_primitives", + "ink_storage", + "obce-macro", + "parity-scale-codec", + "scale-info", +] + +[[package]] +name = "obce-codegen" +version = "0.1.0" +source = "git+https://github.com/Supercolony-net/obce?branch=polkadot-v0.9.29#9843e2a3e91e7c29a9b21dde7ead3299e9d3c0fb" +dependencies = [ + "blake2 0.10.4", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "obce-macro" +version = "0.1.0" +source = "git+https://github.com/Supercolony-net/obce?branch=polkadot-v0.9.29#9843e2a3e91e7c29a9b21dde7ead3299e9d3c0fb" +dependencies = [ + "obce-codegen", + "proc-macro2", + "syn", + "synstructure", +] + [[package]] name = "once_cell" version = "1.13.0" @@ -516,8 +555,8 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openbrush" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "ink_env", "ink_lang", @@ -533,8 +572,8 @@ dependencies = [ [[package]] name = "openbrush_contracts" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "ink_env", "ink_lang", @@ -543,19 +582,21 @@ dependencies = [ "ink_primitives", "ink_storage", "openbrush_lang", + "pallet-assets-chain-extension", "parity-scale-codec", "scale-info", ] [[package]] name = "openbrush_lang" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "const_format", "ink_env", "ink_lang", "ink_metadata", + "ink_prelude", "ink_primitives", "ink_storage", "openbrush_lang_macro", @@ -566,8 +607,8 @@ dependencies = [ [[package]] name = "openbrush_lang_codegen" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "blake2 0.9.2", "cargo_metadata", @@ -585,8 +626,8 @@ dependencies = [ [[package]] name = "openbrush_lang_macro" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "openbrush_lang_codegen", "proc-macro2", @@ -594,6 +635,19 @@ dependencies = [ "synstructure", ] +[[package]] +name = "pallet-assets-chain-extension" +version = "0.1.1" +source = "git+https://github.com/Supercolony-net/pallet-assets-chain-extension#83ff37cb0d19d15a881ecab2c922596039c8358d" +dependencies = [ + "ink_metadata", + "ink_primitives", + "ink_storage", + "obce", + "parity-scale-codec", + "scale-info", +] + [[package]] name = "parity-scale-codec" version = "3.1.5" diff --git a/contracts/ticket_token/Cargo.toml b/contracts/ticket_token/Cargo.toml index 69bb61d1d8..da17e16ccc 100644 --- a/contracts/ticket_token/Cargo.toml +++ b/contracts/ticket_token/Cargo.toml @@ -17,7 +17,7 @@ ink_engine = { version = "~3.3.0", default-features = false, optional = true } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2", default-features = false, features = ["derive"], optional = true } -openbrush = { git = "https://github.com/Supercolony-net/openbrush-contracts.git", rev = "8a20f95", default-features = false, features = ["psp22"] } +openbrush = { git = "https://github.com/Supercolony-net/openbrush-contracts.git", rev = "15e6366", default-features = false, features = ["psp22"] } access_control = { path = "../access_control", default-features = false, features = ["ink-as-dependency"] } [lib] diff --git a/contracts/ticket_token/lib.rs b/contracts/ticket_token/lib.rs index 6442a29e1d..250a2fa620 100644 --- a/contracts/ticket_token/lib.rs +++ b/contracts/ticket_token/lib.rs @@ -115,20 +115,22 @@ pub mod ticket_token { caller, required_role, |why: InkEnvError| { - PSP22Error::Custom(format!("Calling access control has failed: {:?}", why)) + PSP22Error::Custom( + format!("Calling access control has failed: {:?}", why).into(), + ) }, - |role: Role| PSP22Error::Custom(format!("MissingRole:{:?}", role)), + |role: Role| PSP22Error::Custom(format!("MissingRole:{:?}", role).into()), ); match role_check { Ok(_) => ink_lang::codegen::initialize_contract(|instance: &mut TicketToken| { instance.access_control = AccountId::from(ACCESS_CONTROL_PUBKEY); - instance.metadata.name = Some(name); - instance.metadata.symbol = Some(symbol); + instance.metadata.name = Some(name.into()); + instance.metadata.symbol = Some(symbol.into()); instance.metadata.decimals = 0; instance - ._mint(instance.env().caller(), total_supply) + ._mint_to(instance.env().caller(), total_supply) .expect("Should mint"); }), Err(why) => panic!("Could not initialize the contract {:?}", why), @@ -164,9 +166,11 @@ pub mod ticket_token { account, role, |why: InkEnvError| { - PSP22Error::Custom(format!("Calling access control has failed: {:?}", why)) + PSP22Error::Custom( + format!("Calling access control has failed: {:?}", why).into(), + ) }, - |role: Role| PSP22Error::Custom(format!("MissingRole:{:?}", role)), + |role: Role| PSP22Error::Custom(format!("MissingRole:{:?}", role).into()), ) } @@ -188,7 +192,7 @@ pub mod ticket_token { #[ink(message, selector = 10)] pub fn code_hash(&self) -> Result { Self::env().own_code_hash().map_err(|why| { - PSP22Error::Custom(format!("Can't retrieve own code hash: {:?}", why)) + PSP22Error::Custom(format!("Can't retrieve own code hash: {:?}", why).into()) }) } } diff --git a/contracts/wrapped_azero/Cargo.lock b/contracts/wrapped_azero/Cargo.lock index 005cc5779a..49d07f6356 100644 --- a/contracts/wrapped_azero/Cargo.lock +++ b/contracts/wrapped_azero/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "access_control" -version = "1.0.0" +version = "0.2.0" dependencies = [ "ink_env", "ink_lang", @@ -502,6 +502,45 @@ dependencies = [ "autocfg", ] +[[package]] +name = "obce" +version = "0.1.0" +source = "git+https://github.com/Supercolony-net/obce?branch=polkadot-v0.9.29#9843e2a3e91e7c29a9b21dde7ead3299e9d3c0fb" +dependencies = [ + "ink_engine", + "ink_env", + "ink_lang", + "ink_metadata", + "ink_prelude", + "ink_primitives", + "ink_storage", + "obce-macro", + "parity-scale-codec", + "scale-info", +] + +[[package]] +name = "obce-codegen" +version = "0.1.0" +source = "git+https://github.com/Supercolony-net/obce?branch=polkadot-v0.9.29#9843e2a3e91e7c29a9b21dde7ead3299e9d3c0fb" +dependencies = [ + "blake2 0.10.4", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "obce-macro" +version = "0.1.0" +source = "git+https://github.com/Supercolony-net/obce?branch=polkadot-v0.9.29#9843e2a3e91e7c29a9b21dde7ead3299e9d3c0fb" +dependencies = [ + "obce-codegen", + "proc-macro2", + "syn", + "synstructure", +] + [[package]] name = "once_cell" version = "1.14.0" @@ -516,8 +555,8 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openbrush" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "ink_env", "ink_lang", @@ -533,8 +572,8 @@ dependencies = [ [[package]] name = "openbrush_contracts" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "ink_env", "ink_lang", @@ -543,19 +582,21 @@ dependencies = [ "ink_primitives", "ink_storage", "openbrush_lang", + "pallet-assets-chain-extension", "parity-scale-codec", "scale-info", ] [[package]] name = "openbrush_lang" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "const_format", "ink_env", "ink_lang", "ink_metadata", + "ink_prelude", "ink_primitives", "ink_storage", "openbrush_lang_macro", @@ -566,8 +607,8 @@ dependencies = [ [[package]] name = "openbrush_lang_codegen" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "blake2 0.9.2", "cargo_metadata", @@ -585,8 +626,8 @@ dependencies = [ [[package]] name = "openbrush_lang_macro" -version = "2.1.0" -source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=8a20f95#8a20f951feaf8c6ea72c4bf113bf115bad9f158f" +version = "2.2.0" +source = "git+https://github.com/Supercolony-net/openbrush-contracts.git?rev=15e6366#15e63664d87124f4cc0e7ba55b21a71222983677" dependencies = [ "openbrush_lang_codegen", "proc-macro2", @@ -594,6 +635,19 @@ dependencies = [ "synstructure", ] +[[package]] +name = "pallet-assets-chain-extension" +version = "0.1.1" +source = "git+https://github.com/Supercolony-net/pallet-assets-chain-extension#83ff37cb0d19d15a881ecab2c922596039c8358d" +dependencies = [ + "ink_metadata", + "ink_primitives", + "ink_storage", + "obce", + "parity-scale-codec", + "scale-info", +] + [[package]] name = "parity-scale-codec" version = "3.2.1" diff --git a/contracts/wrapped_azero/Cargo.toml b/contracts/wrapped_azero/Cargo.toml index 0894b27252..5ba8900b32 100644 --- a/contracts/wrapped_azero/Cargo.toml +++ b/contracts/wrapped_azero/Cargo.toml @@ -18,7 +18,7 @@ scale = { package = "parity-scale-codec", version = "3", default-features = fals scale-info = { version = "2", default-features = false, features = ["derive"], optional = true } num-traits = { version = "0.2", default-features = false } -openbrush = { git = "https://github.com/Supercolony-net/openbrush-contracts.git", rev = "8a20f95", default-features = false, features = ["psp22"] } +openbrush = { git = "https://github.com/Supercolony-net/openbrush-contracts.git", rev = "15e6366", default-features = false, features = ["psp22"] } access_control = { path = "../access_control", default-features = false, features = ["ink-as-dependency"] } [lib] diff --git a/contracts/wrapped_azero/lib.rs b/contracts/wrapped_azero/lib.rs index 77c490ff8c..256d7eabfb 100644 --- a/contracts/wrapped_azero/lib.rs +++ b/contracts/wrapped_azero/lib.rs @@ -142,8 +142,8 @@ pub mod wrapped_azero { match role_check { Ok(_) => ink_lang::codegen::initialize_contract(|instance: &mut WrappedAzero| { - instance.metadata.name = Some(name); - instance.metadata.symbol = Some(symbol); + instance.metadata.name = Some(name.into()); + instance.metadata.symbol = Some(symbol.into()); instance.metadata.decimals = 12; // same as AZERO instance.access_control = AccountId::from(ACCESS_CONTROL_PUBKEY); @@ -158,7 +158,7 @@ pub mod wrapped_azero { let caller = self.env().caller(); let amount = self.env().transferred_value(); if !amount.eq(&Balance::zero()) { - self._mint(caller, amount)?; + self._mint_to(caller, amount)?; Self::emit_event(self.env(), Event::Wrapped(Wrapped { caller, amount })); } @@ -178,9 +178,9 @@ pub mod wrapped_azero { self._burn_from(caller, amount)?; // return the native token to the caller - self.env() - .transfer(caller, amount) - .map_err(|why| PSP22Error::Custom(format!("Native transfer failed: {:?}", why)))?; + self.env().transfer(caller, amount).map_err(|why| { + PSP22Error::Custom(format!("Native transfer failed: {:?}", why).into()) + })?; Self::emit_event(self.env(), Event::UnWrapped(UnWrapped { caller, amount })); Ok(()) @@ -223,7 +223,7 @@ pub mod wrapped_azero { #[ink(message)] pub fn code_hash(&self) -> Result { Self::env().own_code_hash().map_err(|why| { - PSP22Error::Custom(format!("Can't retrieve own code hash: {:?}", why)) + PSP22Error::Custom(format!("Can't retrieve own code hash: {:?}", why).into()) }) } @@ -232,11 +232,11 @@ pub mod wrapped_azero { } fn access_control_error_handler(role: Role) -> PSP22Error { - PSP22Error::Custom(format!("MissingRole:{:?}", role)) + PSP22Error::Custom(format!("MissingRole:{:?}", role).into()) } fn cross_contract_call_error_handler(why: InkEnvError) -> PSP22Error { - PSP22Error::Custom(format!("Calling access control has failed: {:?}", why)) + PSP22Error::Custom(format!("Calling access control has failed: {:?}", why).into()) } fn check_role(&self, account: AccountId, role: Role) -> Result<()> {