diff --git a/bin/subzero-standalone/cli/src/chain_spec.rs b/bin/subzero-standalone/cli/src/chain_spec.rs index 6c58da447b..3cc4abab76 100644 --- a/bin/subzero-standalone/cli/src/chain_spec.rs +++ b/bin/subzero-standalone/cli/src/chain_spec.rs @@ -373,6 +373,7 @@ pub fn testnet_genesis( min_join_bond: 1 * DOLLARS, ..Default::default() }, + asset_registry: Default::default(), tokens: TokensConfig { balances: Default::default() }, control: ControlConfig { orgs: Default::default() } } diff --git a/bin/subzero-standalone/runtime/Cargo.toml b/bin/subzero-standalone/runtime/Cargo.toml index 2e25d4eaa7..3d52649572 100644 --- a/bin/subzero-standalone/runtime/Cargo.toml +++ b/bin/subzero-standalone/runtime/Cargo.toml @@ -108,11 +108,16 @@ pallet-uniques = { default-features = false, git = "https://github.com/paritytec pallet-vesting = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } pallet-whitelist = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.28", default-features = false } +xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.28", default-features = false } +xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.28", default-features = false } + primitives = { path = "../../../modules/primitives", version = "2.0.0", package = "zero-primitives", default-features = false } -orml-tokens = { path = "../../../modules/orml/tokens", default-features = false } -orml-traits = { path = "../../../modules/orml/traits", default-features = false } -orml-currencies = { path = "../../../modules/orml/currencies", default-features = false } +orml-asset-registry = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } pallet-rmrk-core = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, branch = "polkadot-v0.9.28" } pallet-rmrk-equip = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, branch = "polkadot-v0.9.28" } @@ -209,9 +214,14 @@ std = [ "pallet-child-bounties/std", "pallet-alliance/std", + "xcm/std", + "xcm-executor/std", + "xcm-builder/std", + "orml-tokens/std", "orml-currencies/std", "orml-traits/std", + "orml-asset-registry/std", "pallet-rmrk-core/std", "pallet-rmrk-market/std", diff --git a/bin/subzero-standalone/runtime/src/lib.rs b/bin/subzero-standalone/runtime/src/lib.rs index 8ab0450d17..1a1fdb43a8 100644 --- a/bin/subzero-standalone/runtime/src/lib.rs +++ b/bin/subzero-standalone/runtime/src/lib.rs @@ -33,7 +33,7 @@ use frame_support::{ traits::{ tokens::nonfungibles::*, AsEnsureOriginWithArg, ConstU8, ConstU16, ConstU32, Contains, Currency, EitherOfDiverse, - EnsureOrigin, EnsureOriginWithArg, EqualPrivilegeOnly, Everything, Imbalance, + EnsureOrigin, EnsureOriginWithArg, EqualPrivilegeOnly, Imbalance, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote, }, weights::{ @@ -48,7 +48,7 @@ use frame_system::{ EnsureRoot, EnsureRootWithSuccess, EnsureSigned, }; pub use primitives::{ - currency::{ZERO, PLAY, GAME, CurrencyId}, + currency::{ZERO, PLAY, GAME, CurrencyId, CustomMetadata}, dollar, cent, millicent, AccountId, ReserveIdentifier, Signature, TokenSymbol }; @@ -93,6 +93,7 @@ pub use pallet_sudo::Call as SudoCall; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; +use orml_asset_registry::SequentialId; use orml_traits::parameter_type_with_key; use orml_currencies::BasicCurrencyAdapter; @@ -1637,6 +1638,30 @@ impl pallet_alliance::Config for Runtime { type WeightInfo = pallet_alliance::weights::SubstrateWeight; } +pub struct AssetAuthority; +impl EnsureOriginWithArg> for AssetAuthority { + type Success = (); + + fn try_origin(origin: Origin, _asset_id: &Option) -> Result { + EnsureRoot::try_origin(origin) + } + + #[cfg(feature = "runtime-benchmarks")] + fn successful_origin(_asset_id: &Option) -> Origin { + EnsureRoot::successful_origin() + } +} + +impl orml_asset_registry::Config for Runtime { + type Event = Event; + type Balance = Balance; + type CustomMetadata = (); + type AssetProcessor = SequentialId; + type AssetId = u32; + type AuthorityOrigin = AssetAuthority; + type WeightInfo = (); +} + parameter_type_with_key! { pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance { match currency_id { @@ -1837,6 +1862,7 @@ construct_runtime!( RankedCollective: pallet_ranked_collective, // ORML pallets: + AssetRegistry: orml_asset_registry::{Pallet, Storage, Call, Event, Config}, Tokens: orml_tokens::{Pallet, Storage, Event, Config}, Currencies: orml_currencies::{Pallet, Call}, diff --git a/bin/subzero-standalone/testing/src/genesis.rs b/bin/subzero-standalone/testing/src/genesis.rs index 60ed7491be..9893ae596b 100644 --- a/bin/subzero-standalone/testing/src/genesis.rs +++ b/bin/subzero-standalone/testing/src/genesis.rs @@ -95,6 +95,7 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec) -> Gen alliance: Default::default(), alliance_motion: Default::default(), nomination_pools: Default::default(), + asset_registry: Default::default(), tokens: Default::default(), control: Default::default() } diff --git a/bin/subzero/node/Cargo.toml b/bin/subzero/node/Cargo.toml index 00584281f5..38c320dbab 100644 --- a/bin/subzero/node/Cargo.toml +++ b/bin/subzero/node/Cargo.toml @@ -76,17 +76,17 @@ polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "r xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.28" } # Cumulus -cumulus-client-cli = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-client-collator = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-client-consensus-aura = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-client-consensus-common = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-client-network = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-client-service = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-primitives-core = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-primitives-parachain-inherent = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-relay-chain-inprocess-interface = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-relay-chain-interface = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-relay-chain-rpc-interface = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } +cumulus-client-cli = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-client-collator = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-client-consensus-aura = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-client-consensus-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-client-network = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-client-service = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-relay-chain-inprocess-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-relay-chain-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-relay-chain-rpc-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } primitives = { version = "2.0.0", package = "zero-primitives", default-features = false, path = "../../../modules/primitives" } diff --git a/bin/subzero/runtime/Cargo.toml b/bin/subzero/runtime/Cargo.toml index ad5689178a..95038a9bbc 100644 --- a/bin/subzero/runtime/Cargo.toml +++ b/bin/subzero/runtime/Cargo.toml @@ -75,28 +75,28 @@ xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.28" } # Cumulus -cumulus-pallet-aura-ext = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28', default-features = false } -cumulus-pallet-dmp-queue = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28', default-features = false } -cumulus-pallet-parachain-system = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28', default-features = false } -cumulus-pallet-session-benchmarking = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28', default-features = false} -cumulus-pallet-xcm = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28', default-features = false } -cumulus-pallet-xcmp-queue = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28', default-features = false } -cumulus-primitives-core = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28', default-features = false } -cumulus-primitives-timestamp = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28', default-features = false } -cumulus-primitives-utility = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28', default-features = false } -pallet-collator-selection = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28', default-features = false } -parachain-info = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28', default-features = false } +cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28", default-features = false } +cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28", default-features = false } +cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28", default-features = false } +cumulus-pallet-session-benchmarking = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28", default-features = false} +cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28", default-features = false } +cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28", default-features = false } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28", default-features = false } +cumulus-primitives-timestamp = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28", default-features = false } +cumulus-primitives-utility = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28", default-features = false } +pallet-collator-selection = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28", default-features = false } +parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28", default-features = false } primitives = { version = "2.0.0", package = "zero-primitives", default-features = false, path = "../../../modules/primitives" } -orml-asset-registry = { path = "../../../modules/orml/asset-registry", default-features = false } -orml-currencies = { path = "../../../modules/orml/currencies", default-features = false } -orml-tokens = { path = "../../../modules/orml/tokens", default-features = false } -orml-traits = { path = "../../../modules/orml/traits", default-features = false } -orml-unknown-tokens = { path = "../../../modules/orml/unknown-tokens", default-features = false } -orml-xcm = { path = "../../../modules/orml/xcm", default-features = false } -orml-xcm-support = { path = "../../../modules/orml/xcm-support", default-features = false } -orml-xtokens = { path = "../../../modules/orml/xtokens", default-features = false } +orml-asset-registry = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-unknown-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-xcm = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-xcm-support = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } pallet-rmrk-core = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, branch = "polkadot-v0.9.28" } pallet-rmrk-equip = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, branch = "polkadot-v0.9.28" } diff --git a/bin/zero/node/Cargo.toml b/bin/zero/node/Cargo.toml index 5afc546560..0beeb95b2c 100644 --- a/bin/zero/node/Cargo.toml +++ b/bin/zero/node/Cargo.toml @@ -76,17 +76,17 @@ polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "r xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.28" } # Cumulus -cumulus-client-cli = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-client-collator = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-client-consensus-aura = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-client-consensus-common = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-client-network = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-client-service = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-primitives-core = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-primitives-parachain-inherent = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-relay-chain-inprocess-interface = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-relay-chain-interface = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } -cumulus-relay-chain-rpc-interface = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.28' } +cumulus-client-cli = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-client-collator = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-client-consensus-aura = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-client-consensus-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-client-network = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-client-service = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-relay-chain-inprocess-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-relay-chain-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } +cumulus-relay-chain-rpc-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.28" } primitives = { version = "2.0.0", package = "zero-primitives", default-features = false, path = "../../../modules/primitives" } diff --git a/bin/zero/runtime/Cargo.toml b/bin/zero/runtime/Cargo.toml index 3a6355ae10..925377a2d4 100644 --- a/bin/zero/runtime/Cargo.toml +++ b/bin/zero/runtime/Cargo.toml @@ -90,15 +90,14 @@ parachain-info = { git = "https://github.com/paritytech/cumulus", default-featur primitives = { version = "2.0.0", package = "zero-primitives", default-features = false, path = "../../../modules/primitives" } # ORML -# SBP-M2 review: why you use your copy of orml instead of following main implementation? -orml-asset-registry = { path = "../../../modules/orml/asset-registry", default-features = false } -orml-currencies = { path = "../../../modules/orml/currencies", default-features = false } -orml-tokens = { path = "../../../modules/orml/tokens", default-features = false } -orml-traits = { path = "../../../modules/orml/traits", default-features = false } -orml-unknown-tokens = { path = "../../../modules/orml/unknown-tokens", default-features = false } -orml-xcm = { path = "../../../modules/orml/xcm", default-features = false } -orml-xcm-support = { path = "../../../modules/orml/xcm-support", default-features = false } -orml-xtokens = { path = "../../../modules/orml/xtokens", default-features = false } +orml-asset-registry = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-unknown-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-xcm = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-xcm-support = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } # RMRK pallet-rmrk-core = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, branch = "polkadot-v0.9.28" } diff --git a/modules/asset-registry/Cargo.toml b/modules/asset-registry/Cargo.toml deleted file mode 100644 index 65755ca596..0000000000 --- a/modules/asset-registry/Cargo.toml +++ /dev/null @@ -1,40 +0,0 @@ -[package] -name = "module-asset-registry" -version = "0.1.0" -authors = ["zero.io","gamedao.co"] -edition = "2021" - -[dependencies] -log = { version = "0.4.17", default-features = false } -serde = { version = "1.0.136", optional = true } -scale-info = { version = "2.1", default-features = false, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.25", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.25", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.25", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.25", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.25", default-features = false, optional = true } -primitives = { package = "zero-primitives", path = "../primitives", default-features = false } - -[dev-dependencies] -serde_json = "1.0.68" -hex = "0.4" -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.25" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.25" } -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.25" } - -[features] -default = ["std"] -std = [ - "serde", - "log/std", - "codec/std", - "scale-info/std", - "sp-runtime/std", - "sp-std/std", - "frame-support/std", - "frame-system/std", - "primitives/std", -] -try-runtime = ["frame-support/try-runtime"] -runtime-benchmarks = ["frame-benchmarking"] diff --git a/modules/asset-registry/src/benchmarking.rs b/modules/asset-registry/src/benchmarking.rs deleted file mode 100644 index d28b427dad..0000000000 --- a/modules/asset-registry/src/benchmarking.rs +++ /dev/null @@ -1,37 +0,0 @@ -#![cfg(feature = "runtime-benchmarks")] - -use crate::*; -use crate::Pallet as AssetRegistry; -use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; -use frame_system::RawOrigin; -use sp_runtime::{DispatchError, traits::{SaturatedConversion, Zero}}; -use sp_std::{boxed::Box, vec}; -use primitives::{currency::AssetMetadata, TokenSymbol}; - - -benchmarks! { - - register_native_asset { - let asset_metadata = AssetMetadata { - name: b"Token Name".to_vec(), - symbol: b"TN".to_vec(), - decimals: 12, - minimal_balance: Zero::zero(), - }; - }: _(RawOrigin::Root, CurrencyId::Token(TokenSymbol::DOT), Box::new(asset_metadata)) - - update_native_asset { - let currency_id = CurrencyId::Token(TokenSymbol::DOT); - let asset_metadata = AssetMetadata { - name: b"Token Name".to_vec(), - symbol: b"TN".to_vec(), - decimals: 12, - minimal_balance: Zero::zero(), - }; - - AssetRegistry::::register_native_asset(RawOrigin::Root.into(), currency_id, Box::new(asset_metadata.clone()))?; - }: _(RawOrigin::Root, currency_id, Box::new(asset_metadata)) - -} - -impl_benchmark_test_suite!(AssetRegistry, crate::mock::new_test_ext(), crate::mock::Test); \ No newline at end of file diff --git a/modules/asset-registry/src/lib.rs b/modules/asset-registry/src/lib.rs deleted file mode 100644 index f315864abd..0000000000 --- a/modules/asset-registry/src/lib.rs +++ /dev/null @@ -1,199 +0,0 @@ -//! # Asset Registry Module -//! -//! Local and foreign assets management. The foreign assets can be updated without runtime upgrade. - -#![cfg_attr(not(feature = "std"), no_std)] -#![allow(clippy::unused_unit)] -// SBP-M2 review: #TODO comment -#![allow(deprecated)] // TODO: clean transactional - -use frame_support::{ - assert_ok, - dispatch::DispatchResult, - ensure, - pallet_prelude::*, - traits::{Currency, EnsureOrigin}, - transactional, -}; -use frame_system::pallet_prelude::*; -use primitives::{ - currency::{AssetIds, AssetMetadata, TokenInfo}, - CurrencyId, -}; -use sp_std::{boxed::Box, vec::Vec}; - -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking; -mod mock; -mod tests; -pub mod weights; - -pub use pallet::*; -pub use weights::WeightInfo; - -/// Type alias for currency balance. -pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; - -#[frame_support::pallet] -pub mod pallet { - use super::*; - - #[pallet::config] - pub trait Config: frame_system::Config { - /// The overarching event type. - type Event: From> + IsType<::Event>; - - /// Currency type for withdraw and balance storage. - type Currency: Currency; - - /// Required origin for registering asset. - type RegisterOrigin: EnsureOrigin; - - /// Weight information for the extrinsics in this module. - type WeightInfo: WeightInfo; - } - - #[pallet::error] - pub enum Error { - /// AssetId not exists - AssetIdNotExists, - /// AssetId exists - AssetIdExisted, - } - - // SBP-M2 review: you should not include asset metadata in event while it can contain huge data - // amount - // If someone is interested there should be possibility to query it from chain state - #[pallet::event] - #[pallet::generate_deposit(fn deposit_event)] - pub enum Event { - /// The asset registered. - AssetRegistered { - asset_id: AssetIds, - metadata: AssetMetadata>, - }, - /// The asset updated. - AssetUpdated { - asset_id: AssetIds, - metadata: AssetMetadata>, - }, - } - - /// The storages for AssetMetadatas. - /// - /// AssetMetadatas: map AssetIds => Option - #[pallet::storage] - #[pallet::getter(fn asset_metadatas)] - pub type AssetMetadatas = - StorageMap<_, Twox64Concat, AssetIds, AssetMetadata>, OptionQuery>; - - #[pallet::pallet] - #[pallet::without_storage_info] - pub struct Pallet(_); - - #[pallet::genesis_config] - pub struct GenesisConfig { - pub assets: Vec<(CurrencyId, BalanceOf)>, - } - - #[cfg(feature = "std")] - impl Default for GenesisConfig { - fn default() -> Self { - GenesisConfig { - assets: Default::default(), - } - } - } - - #[pallet::genesis_build] - impl GenesisBuild for GenesisConfig { - fn build(&self) { - self.assets.iter().for_each(|(asset, ed)| { - // SBP-M2 review: consider adding some log when sth go wrong during genesis build - assert_ok!(Pallet::::do_register_native_asset( - *asset, - &AssetMetadata { - name: asset.name().unwrap().as_bytes().to_vec(), - symbol: asset.symbol().unwrap().as_bytes().to_vec(), - decimals: asset.decimals().unwrap(), - minimal_balance: *ed, - } - )); - }); - } - } - - #[pallet::call] - impl Pallet { - #[pallet::weight(T::WeightInfo::register_native_asset())] - #[transactional] - pub fn register_native_asset( - origin: OriginFor, - currency_id: CurrencyId, - metadata: Box>>, - ) -> DispatchResult { - T::RegisterOrigin::ensure_origin(origin)?; - - Self::do_register_native_asset(currency_id, &metadata)?; - - Self::deposit_event(Event::::AssetRegistered { - asset_id: AssetIds::NativeAssetId(currency_id), - metadata: *metadata, - }); - Ok(()) - } - - #[pallet::weight(T::WeightInfo::update_native_asset())] - #[transactional] - pub fn update_native_asset( - origin: OriginFor, - currency_id: CurrencyId, - // SBP-M2 review: why `Box` is used for extrinsic parameters? - metadata: Box>>, - ) -> DispatchResult { - T::RegisterOrigin::ensure_origin(origin)?; - - Self::do_update_native_asset(currency_id, &metadata)?; - - Self::deposit_event(Event::::AssetUpdated { - asset_id: AssetIds::NativeAssetId(currency_id), - metadata: *metadata, - }); - Ok(()) - } - } -} - -impl Pallet { - fn do_register_native_asset(asset: CurrencyId, metadata: &AssetMetadata>) -> DispatchResult { - AssetMetadatas::::try_mutate( - AssetIds::NativeAssetId(asset), - |maybe_asset_metadatas| -> DispatchResult { - ensure!(maybe_asset_metadatas.is_none(), Error::::AssetIdExisted); - - // SBP-M2 review: without adding metadate to event - // You would not need to clone metadata here - *maybe_asset_metadatas = Some(metadata.clone()); - Ok(()) - }, - )?; - - Ok(()) - } - - // SBP-M2 review: these two functions look almost the same - // Think about merging them into single one with possibility to provide appropriate check - // mechanism - fn do_update_native_asset(currency_id: CurrencyId, metadata: &AssetMetadata>) -> DispatchResult { - AssetMetadatas::::try_mutate( - AssetIds::NativeAssetId(currency_id), - |maybe_asset_metadatas| -> DispatchResult { - ensure!(maybe_asset_metadatas.is_some(), Error::::AssetIdNotExists); - - // SBP-M2 review: same as above - *maybe_asset_metadatas = Some(metadata.clone()); - Ok(()) - }, - ) - } -} diff --git a/modules/asset-registry/src/mock.rs b/modules/asset-registry/src/mock.rs deleted file mode 100644 index 4fa162ae42..0000000000 --- a/modules/asset-registry/src/mock.rs +++ /dev/null @@ -1,83 +0,0 @@ -#![cfg(test)] - -use frame_support::{parameter_types, traits::{ConstU128, ConstU32, ConstU64, Everything}}; -use frame_system as system; - -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -type Block = frame_system::mocking::MockBlock; -type Balance = u128; - -frame_support::construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: frame_system::{Pallet, Call, Config, Storage, Event}, - Balances: pallet_balances::{Pallet, Call, Storage, Event}, - AssetRegistry: module_asset_registry::{Pallet, Call, Storage, Event}, - } -); - -mod module_asset_registry { - pub use super::super::*; -} - -parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const SS58Prefix: u8 = 42; - pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max(1024); - pub static ExistentialDeposit: u64 = 0; -} - -impl system::Config for Test { - type BaseCallFilter = Everything; - type Origin = Origin; - type Index = u64; - type BlockNumber = u64; - type Call = Call; - type Hash = sp_runtime::testing::H256; - type Hashing = sp_runtime::traits::BlakeTwo256; - type AccountId = u64; - type Lookup = sp_runtime::traits::IdentityLookup; - type Header = sp_runtime::testing::Header; - type Event = Event; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; -} - -impl pallet_balances::Config for Test { - type Balance = Balance; - type DustRemoval = (); - type Event = Event; - type ExistentialDeposit = ConstU128<1>; - type AccountStore = System; - type MaxLocks = (); - type MaxReserves = ConstU32<50>; - type ReserveIdentifier = [u8; 8]; - type WeightInfo = (); -} - -impl module_asset_registry::Config for Test { - type Event = Event; - type Currency = Balances; - type RegisterOrigin = frame_system::EnsureRoot; - type WeightInfo = (); -} - -// Build genesis storage according to the mock runtime. -pub fn new_test_ext() -> sp_io::TestExternalities { - system::GenesisConfig::default().build_storage::().unwrap().into() -} diff --git a/modules/asset-registry/src/tests.rs b/modules/asset-registry/src/tests.rs deleted file mode 100644 index ed4ccb063a..0000000000 --- a/modules/asset-registry/src/tests.rs +++ /dev/null @@ -1,124 +0,0 @@ -#![cfg(test)] - -use super::*; -use frame_support::{assert_noop, assert_ok}; -use frame_system::RawOrigin; -use mock::{Event, *}; -use primitives::TokenSymbol; - -#[test] -fn register_native_asset_works() { - new_test_ext().execute_with(|| { - System::set_block_number(3); - // SBP-M2 review: you can create metadate once and then compare to copy instead of - // initalization of 2 the same structs. - assert_ok!(AssetRegistry::register_native_asset( - // SBP-M2 review: you should provide entity like council to get rid of sudo calls - RawOrigin::Root.into(), - CurrencyId::Token(TokenSymbol::DOT), - Box::new(AssetMetadata { - name: b"Token Name".to_vec(), - symbol: b"TN".to_vec(), - decimals: 12, - minimal_balance: 1, - }) - )); - System::assert_has_event(Event::AssetRegistry(crate::Event::AssetRegistered { - asset_id: AssetIds::NativeAssetId(CurrencyId::Token(TokenSymbol::DOT)), - metadata: AssetMetadata { - name: b"Token Name".to_vec(), - symbol: b"TN".to_vec(), - decimals: 12, - minimal_balance: 1, - }, - })); - - assert_eq!( - AssetMetadatas::::get(AssetIds::NativeAssetId(CurrencyId::Token(TokenSymbol::DOT))), - Some(AssetMetadata { - name: b"Token Name".to_vec(), - symbol: b"TN".to_vec(), - decimals: 12, - minimal_balance: 1, - }) - ); - // SBP-M2 review: it should be another test case - // Try to follow assumption - 1 test case per simple check - // Can't duplicate - assert_noop!( - AssetRegistry::register_native_asset( - RawOrigin::Root.into(), - CurrencyId::Token(TokenSymbol::DOT), - Box::new(AssetMetadata { - name: b"Token Name".to_vec(), - symbol: b"TN".to_vec(), - decimals: 12, - minimal_balance: 1, - }) - ), - Error::::AssetIdExisted - ); - }); -} - -// SBP-M2 review: above comments should be applied here -#[test] -fn update_native_asset_works() { - new_test_ext().execute_with(|| { - System::set_block_number(3); - assert_noop!( - AssetRegistry::update_native_asset( - RawOrigin::Root.into(), - CurrencyId::Token(TokenSymbol::DOT), - Box::new(AssetMetadata { - name: b"New Token Name".to_vec(), - symbol: b"NTN".to_vec(), - decimals: 13, - minimal_balance: 2, - }) - ), - Error::::AssetIdNotExists - ); - - assert_ok!(AssetRegistry::register_native_asset( - RawOrigin::Root.into(), - CurrencyId::Token(TokenSymbol::DOT), - Box::new(AssetMetadata { - name: b"Token Name".to_vec(), - symbol: b"TN".to_vec(), - decimals: 12, - minimal_balance: 1, - }) - )); - - assert_ok!(AssetRegistry::update_native_asset( - RawOrigin::Root.into(), - CurrencyId::Token(TokenSymbol::DOT), - Box::new(AssetMetadata { - name: b"New Token Name".to_vec(), - symbol: b"NTN".to_vec(), - decimals: 13, - minimal_balance: 2, - }) - )); - System::assert_has_event(Event::AssetRegistry(crate::Event::AssetUpdated { - asset_id: AssetIds::NativeAssetId(CurrencyId::Token(TokenSymbol::DOT)), - metadata: AssetMetadata { - name: b"New Token Name".to_vec(), - symbol: b"NTN".to_vec(), - decimals: 13, - minimal_balance: 2, - }, - })); - - assert_eq!( - AssetMetadatas::::get(AssetIds::NativeAssetId(CurrencyId::Token(TokenSymbol::DOT))), - Some(AssetMetadata { - name: b"New Token Name".to_vec(), - symbol: b"NTN".to_vec(), - decimals: 13, - minimal_balance: 2, - }) - ); - }); -} diff --git a/modules/asset-registry/src/weights.rs b/modules/asset-registry/src/weights.rs deleted file mode 100644 index 46dc3bef65..0000000000 --- a/modules/asset-registry/src/weights.rs +++ /dev/null @@ -1,64 +0,0 @@ -//! Autogenerated weights for module_asset_registry -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-03-24, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 - -// Executed Command: -// target/release/subzero -// benchmark -// --chain=dev -// --steps=50 -// --repeat=20 -// --pallet=module_asset_registry -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=./modules/asset-registry/src/weights.rs -// --template=./templates/module-weight-template.hbs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] - -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use sp_std::marker::PhantomData; - -/// Weight functions needed for module_asset_registry. -pub trait WeightInfo { - fn register_native_asset() -> Weight; - fn update_native_asset() -> Weight; -} - -/// Weights for module_asset_registry using the Acala node and recommended hardware. -pub struct AcalaWeight(PhantomData); -impl WeightInfo for AcalaWeight { - // Storage: AssetRegistry AssetMetadatas (r:1 w:1) - fn register_native_asset() -> Weight { - (13_140_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - // Storage: AssetRegistry AssetMetadatas (r:1 w:1) - fn update_native_asset() -> Weight { - (13_815_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } -} - -// For backwards compatibility and tests -impl WeightInfo for () { - fn register_native_asset() -> Weight { - (13_140_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(1 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) - } - fn update_native_asset() -> Weight { - (13_815_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(1 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) - } -} diff --git a/modules/gamedao-protocol b/modules/gamedao-protocol index aac9b06554..764f40ce77 160000 --- a/modules/gamedao-protocol +++ b/modules/gamedao-protocol @@ -1 +1 @@ -Subproject commit aac9b0655434521d587a5a8952342e886e34d51f +Subproject commit 764f40ce77299f7c3a0c817f35d95f64d5d3fa70 diff --git a/modules/orml b/modules/orml deleted file mode 160000 index 20969f385b..0000000000 --- a/modules/orml +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 20969f385bf77e41386e8d8aa9626b003a306204 diff --git a/modules/primitives/src/currency.rs b/modules/primitives/src/currency.rs index 8bb4f1e79d..aa43334699 100644 --- a/modules/primitives/src/currency.rs +++ b/modules/primitives/src/currency.rs @@ -152,11 +152,9 @@ pub enum AssetIds { } #[derive(Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, TypeInfo)] -pub struct AssetMetadata { - // SBP-M2 review: unbounded vectors are high security issues - // You should have limited length for name&symbol - pub name: Vec, - pub symbol: Vec, +pub struct AssetMetadata { + pub name: BoundedString, + pub symbol: BoundedString, pub decimals: u8, pub minimal_balance: Balance, }