From 6488b8530bc0e21cdfeb8e4c764b9e5874b2152e Mon Sep 17 00:00:00 2001 From: tgmichel Date: Wed, 22 Feb 2023 11:53:43 +0100 Subject: [PATCH 01/23] Upgrade polkadot-v0.9.38 --- asset-registry/Cargo.toml | 38 +++++++++++++------------- asset-registry/src/impls.rs | 8 +++--- asset-registry/src/lib.rs | 2 +- auction/Cargo.toml | 12 ++++----- authority/Cargo.toml | 20 +++++++------- bencher/Cargo.toml | 24 ++++++++--------- bencher/test/Cargo.toml | 12 ++++----- benchmarking/Cargo.toml | 18 ++++++------- currencies/Cargo.toml | 14 +++++----- gradually-update/Cargo.toml | 12 ++++----- nft/Cargo.toml | 12 ++++----- oracle/Cargo.toml | 14 +++++----- oracle/rpc/Cargo.toml | 6 ++--- oracle/rpc/runtime-api/Cargo.toml | 4 +-- payments/Cargo.toml | 12 ++++----- rewards/Cargo.toml | 14 +++++----- tokens/Cargo.toml | 16 +++++------ tokens/rpc/Cargo.toml | 12 ++++----- tokens/rpc/runtime-api/Cargo.toml | 6 ++--- traits/Cargo.toml | 12 +++++---- traits/src/location.rs | 11 +++++--- traits/src/multi_asset.rs | 22 ++++++++------- unknown-tokens/Cargo.toml | 14 +++++----- unknown-tokens/src/lib.rs | 4 +-- utilities/Cargo.toml | 10 +++---- vesting/Cargo.toml | 14 +++++----- weight-meter/Cargo.toml | 14 +++++----- xcm-support/Cargo.toml | 10 +++---- xcm-support/src/currency_adapter.rs | 11 +++++--- xcm-support/src/lib.rs | 2 +- xcm-support/src/tests.rs | 6 ++--- xcm/Cargo.toml | 12 ++++----- xcm/src/lib.rs | 2 +- xtokens/Cargo.toml | 40 +++++++++++++-------------- xtokens/src/lib.rs | 42 ++++++++++++++--------------- 35 files changed, 245 insertions(+), 237 deletions(-) diff --git a/asset-registry/Cargo.toml b/asset-registry/Cargo.toml index 48243c0af..77594e928 100644 --- a/asset-registry/Cargo.toml +++ b/asset-registry/Cargo.toml @@ -13,37 +13,37 @@ serde = { version = "1.0.136", optional = true } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] } # substrate -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } # polkadot -pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" } -xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" } -xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" } +pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" } +xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" } +xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" } # orml orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } [dev-dependencies] # substrate -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } # cumulus -cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" } -cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" } -cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" } -cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" } -parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" } +cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" } +cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" } +cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" } +parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" } # polkadot -polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } -polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } -xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } +polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" } +polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" } +xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" } # orml orml-tokens = { path = "../tokens" } diff --git a/asset-registry/src/impls.rs b/asset-registry/src/impls.rs index 9bb8e6678..b2e10ff3e 100644 --- a/asset-registry/src/impls.rs +++ b/asset-registry/src/impls.rs @@ -104,7 +104,7 @@ impl WeightTrader for AssetRegistryTrad continue; } - if let Some(fee_increase) = W::convert_weight_to_fee(location, Weight::from_ref_time(weight)) { + if let Some(fee_increase) = W::convert_weight_to_fee(location, weight) { if fee_increase == 0 { // if the fee is set very low it could lead to zero fees, in which case // constructing the fee asset item to subtract from payment would fail. @@ -120,9 +120,7 @@ impl WeightTrader for AssetRegistryTrad self.bought_weight = Some(BoughtWeight { amount: existing_fee.checked_add(fee_increase).ok_or(XcmError::Overflow)?, - weight: existing_weight - .checked_add(&Weight::from_ref_time(weight)) - .ok_or(XcmError::Overflow)?, + weight: existing_weight.checked_add(&weight).ok_or(XcmError::Overflow)?, asset_location: location.clone(), }); return Ok(unused); @@ -138,7 +136,7 @@ impl WeightTrader for AssetRegistryTrad match self.bought_weight { Some(ref mut bought) => { - let new_weight = bought.weight.saturating_sub(Weight::from_ref_time(weight)); + let new_weight = bought.weight.saturating_sub(weight); let new_amount = W::convert_weight_to_fee(&bought.asset_location, new_weight)?; let refunded_amount = bought.amount.saturating_sub(new_amount); diff --git a/asset-registry/src/lib.rs b/asset-registry/src/lib.rs index b9819566f..dc2ec3669 100644 --- a/asset-registry/src/lib.rs +++ b/asset-registry/src/lib.rs @@ -14,7 +14,7 @@ use sp_runtime::{ DispatchResult, }; use sp_std::prelude::*; -use xcm::{v2::prelude::*, VersionedMultiLocation}; +use xcm::{v3::prelude::*, VersionedMultiLocation}; pub use impls::*; pub use module::*; diff --git a/auction/Cargo.toml b/auction/Cargo.toml index 5d3171089..c114847fb 100644 --- a/auction/Cargo.toml +++ b/auction/Cargo.toml @@ -12,16 +12,16 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } [features] default = ["std"] diff --git a/authority/Cargo.toml b/authority/Cargo.toml index 5545ad373..46fef476d 100644 --- a/authority/Cargo.toml +++ b/authority/Cargo.toml @@ -12,18 +12,18 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.145", optional = true } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } [dev-dependencies] -pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -pallet-root-testing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-root-testing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } [features] default = ["std"] diff --git a/bencher/Cargo.toml b/bencher/Cargo.toml index d71a8a2ba..1a8973e64 100644 --- a/bencher/Cargo.toml +++ b/bencher/Cargo.toml @@ -26,18 +26,18 @@ hash-db = { version = "0.15.2", default-features = false, optional = true } bencher-procedural = { path = "bencher-procedural", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"], default-features = false } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime-interface = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-state-machine = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.37" } -sc-executor = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.37" } -sc-executor-common = { git = "https://github.com/paritytech/substrate", optional = true , branch = "polkadot-v0.9.37" } -sc-client-db = { git = "https://github.com/paritytech/substrate", default-features = false, features = ["rocksdb"], optional = true , branch = "polkadot-v0.9.37" } -sp-maybe-compressed-blob = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.37" } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-externalities = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-storage = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.37" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime-interface = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-state-machine = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.38" } +sc-executor = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.38" } +sc-executor-common = { git = "https://github.com/paritytech/substrate", optional = true , branch = "polkadot-v0.9.38" } +sc-client-db = { git = "https://github.com/paritytech/substrate", default-features = false, features = ["rocksdb"], optional = true , branch = "polkadot-v0.9.38" } +sp-maybe-compressed-blob = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.38" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-externalities = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-storage = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.38" } [features] default = ["std"] diff --git a/bencher/test/Cargo.toml b/bencher/test/Cargo.toml index e40a5f424..9e9c69c0c 100644 --- a/bencher/test/Cargo.toml +++ b/bencher/test/Cargo.toml @@ -15,16 +15,16 @@ required-features = ["bench"] serde = { version = "1.0.136", optional = true } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"], default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } orml-bencher = { path = "..", default-features = false } orml-weight-meter = { path = "../../weight-meter", default-features = false } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } [features] default = ["std"] diff --git a/benchmarking/Cargo.toml b/benchmarking/Cargo.toml index ce887694c..31f220b51 100644 --- a/benchmarking/Cargo.toml +++ b/benchmarking/Cargo.toml @@ -14,19 +14,19 @@ paste = "1.0.7" scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime-interface = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-storage = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime-interface = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-storage = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } [dev-dependencies] hex-literal = "0.3.4" -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } [features] default = [ "std" ] diff --git a/currencies/Cargo.toml b/currencies/Cargo.toml index 78c275980..05e60387b 100644 --- a/currencies/Cargo.toml +++ b/currencies/Cargo.toml @@ -12,18 +12,18 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } orml-utilities = { path = "../utilities", version = "0.4.1-dev", default-features = false } [dev-dependencies] -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } orml_tokens = { package = "orml-tokens", path = "../tokens", version = "0.4.1-dev" } diff --git a/gradually-update/Cargo.toml b/gradually-update/Cargo.toml index 74a8c0534..0ee697ed6 100644 --- a/gradually-update/Cargo.toml +++ b/gradually-update/Cargo.toml @@ -12,12 +12,12 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } [features] default = ["std"] diff --git a/nft/Cargo.toml b/nft/Cargo.toml index 52b785d74..d27bc2a27 100644 --- a/nft/Cargo.toml +++ b/nft/Cargo.toml @@ -12,14 +12,14 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } [features] default = ["std"] diff --git a/oracle/Cargo.toml b/oracle/Cargo.toml index 2387dbe3f..9857f8700 100644 --- a/oracle/Cargo.toml +++ b/oracle/Cargo.toml @@ -12,18 +12,18 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-application-crypto = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-application-crypto = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } orml-utilities = { path = "../utilities", version = "0.4.1-dev", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } [features] default = ["std"] diff --git a/oracle/rpc/Cargo.toml b/oracle/rpc/Cargo.toml index 1a3829205..4dfe9759b 100644 --- a/oracle/rpc/Cargo.toml +++ b/oracle/rpc/Cargo.toml @@ -12,8 +12,8 @@ jsonrpsee = { version = "0.16.2", features = ["client", "server", "macros"] } tracing = { version = "0.1.29" } tracing-core = { version = "0.1.28" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } orml-oracle-rpc-runtime-api = { path = "runtime-api", version = "0.4.1-dev" } diff --git a/oracle/rpc/runtime-api/Cargo.toml b/oracle/rpc/runtime-api/Cargo.toml index e631c46a2..3de1f5a6f 100644 --- a/oracle/rpc/runtime-api/Cargo.toml +++ b/oracle/rpc/runtime-api/Cargo.toml @@ -8,8 +8,8 @@ description = "Runtime API module for orml-oracle-rpc." [dependencies] codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -sp-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +sp-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } [features] default = ["std"] diff --git a/payments/Cargo.toml b/payments/Cargo.toml index 477221b65..42f2bc6d5 100644 --- a/payments/Cargo.toml +++ b/payments/Cargo.toml @@ -14,18 +14,18 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } orml-traits = {path = "../traits", version = "0.4.1-dev", default-features = false } [dev-dependencies] serde = { version = "1.0.136" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } orml-tokens = { path = "../tokens", version = "0.4.1-dev", default-features = false } diff --git a/rewards/Cargo.toml b/rewards/Cargo.toml index cb9e20b4c..000cb9ce2 100644 --- a/rewards/Cargo.toml +++ b/rewards/Cargo.toml @@ -12,17 +12,17 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } [features] default = ["std"] diff --git a/tokens/Cargo.toml b/tokens/Cargo.toml index 4c849f7bc..53705810f 100644 --- a/tokens/Cargo.toml +++ b/tokens/Cargo.toml @@ -12,18 +12,18 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } [dev-dependencies] -pallet-elections-phragmen = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +pallet-elections-phragmen = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } [features] default = ["std"] diff --git a/tokens/rpc/Cargo.toml b/tokens/rpc/Cargo.toml index 24cd93bc3..b27dffe96 100644 --- a/tokens/rpc/Cargo.toml +++ b/tokens/rpc/Cargo.toml @@ -12,11 +12,11 @@ jsonrpsee = { version = "0.16.2", features = ["client", "server", "macros"] } tracing = { version = "0.1.29" } tracing-core = { version = "0.1.28" } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } orml-tokens-rpc-runtime-api = { version = "0.4.1-dev", path = "./runtime-api" } diff --git a/tokens/rpc/runtime-api/Cargo.toml b/tokens/rpc/runtime-api/Cargo.toml index 0bc944de9..b5993eeb2 100644 --- a/tokens/rpc/runtime-api/Cargo.toml +++ b/tokens/rpc/runtime-api/Cargo.toml @@ -8,9 +8,9 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } orml-tokens = { default-features = false, path = "../../../tokens" } [features] diff --git a/traits/Cargo.toml b/traits/Cargo.toml index d498a2546..1eae41bb1 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -14,12 +14,13 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = num-traits = { version = "0.2.14", default-features = false } impl-trait-for-tuples = "0.2.2" -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" } orml-utilities = { path = "../utilities", version = "0.4.1-dev", default-features = false } @@ -30,6 +31,7 @@ std = [ "codec/std", "scale-info/std", "sp-runtime/std", + "sp-core/std", "sp-io/std", "sp-std/std", "num-traits/std", diff --git a/traits/src/location.rs b/traits/src/location.rs index 14a3fe67f..11d11c27d 100644 --- a/traits/src/location.rs +++ b/traits/src/location.rs @@ -1,4 +1,4 @@ -use sp_runtime::{traits::ConstU32, WeakBoundedVec}; +use sp_core::{bounded::BoundedVec, ConstU32}; use sp_std::prelude::*; use xcm::latest::prelude::*; @@ -78,12 +78,15 @@ impl Reserve for RelativeReserveProvider { } pub trait RelativeLocations { - fn sibling_parachain_general_key(para_id: u32, general_key: WeakBoundedVec>) -> MultiLocation; + fn sibling_parachain_general_key(para_id: u32, general_key: BoundedVec>) -> Option; } impl RelativeLocations for MultiLocation { - fn sibling_parachain_general_key(para_id: u32, general_key: WeakBoundedVec>) -> MultiLocation { - MultiLocation::new(1, X2(Parachain(para_id), GeneralKey(general_key))) + fn sibling_parachain_general_key(para_id: u32, general_key: BoundedVec>) -> Option { + if let Some(general_key) = Junction::try_from(general_key).ok() { + return Some(MultiLocation::new(1, X2(Parachain(para_id), general_key))); + } + None } } diff --git a/traits/src/multi_asset.rs b/traits/src/multi_asset.rs index d7c7dd807..e5825bd88 100644 --- a/traits/src/multi_asset.rs +++ b/traits/src/multi_asset.rs @@ -1,25 +1,27 @@ -use sp_runtime::{traits::ConstU32, WeakBoundedVec}; +use sp_core::{bounded::BoundedVec, ConstU32}; use xcm::latest::prelude::*; use crate::location::RelativeLocations; pub trait ConcreteFungibleAsset { - fn sibling_parachain_asset(para_id: u32, general_key: WeakBoundedVec>, amount: u128) - -> MultiAsset; + fn sibling_parachain_asset( + para_id: u32, + general_key: BoundedVec>, + amount: u128, + ) -> Option; fn parent_asset(amount: u128) -> MultiAsset; } impl ConcreteFungibleAsset for MultiAsset { fn sibling_parachain_asset( para_id: u32, - general_key: WeakBoundedVec>, + general_key: BoundedVec>, amount: u128, - ) -> MultiAsset { - ( - MultiLocation::sibling_parachain_general_key(para_id, general_key), - amount, - ) - .into() + ) -> Option { + if let Some(general_key) = MultiLocation::sibling_parachain_general_key(para_id, general_key) { + return Some((general_key, amount).into()); + } + None } fn parent_asset(amount: u128) -> MultiAsset { diff --git a/unknown-tokens/Cargo.toml b/unknown-tokens/Cargo.toml index ba3921aad..263e21c13 100644 --- a/unknown-tokens/Cargo.toml +++ b/unknown-tokens/Cargo.toml @@ -12,18 +12,18 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" } orml-xcm-support = { path = "../xcm-support", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } [features] default = ["std"] diff --git a/unknown-tokens/src/lib.rs b/unknown-tokens/src/lib.rs index be7fee5d2..f0b566161 100644 --- a/unknown-tokens/src/lib.rs +++ b/unknown-tokens/src/lib.rs @@ -83,7 +83,7 @@ impl UnknownAsset for Pallet { MultiAsset { fun: Fungible(amount), id: Abstract(key), - } => AbstractFungibleBalances::::try_mutate(to, key, |b| -> DispatchResult { + } => AbstractFungibleBalances::::try_mutate(to, key.to_vec(), |b| -> DispatchResult { *b = b.checked_add(*amount).ok_or(Error::::BalanceOverflow)?; Ok(()) }), @@ -110,7 +110,7 @@ impl UnknownAsset for Pallet { MultiAsset { fun: Fungible(amount), id: Abstract(key), - } => AbstractFungibleBalances::::try_mutate(from, key, |b| -> DispatchResult { + } => AbstractFungibleBalances::::try_mutate(from, key.to_vec(), |b| -> DispatchResult { *b = b.checked_sub(*amount).ok_or(Error::::BalanceTooLow)?; Ok(()) }), diff --git a/utilities/Cargo.toml b/utilities/Cargo.toml index eca6cbac3..19f93596f 100644 --- a/utilities/Cargo.toml +++ b/utilities/Cargo.toml @@ -12,15 +12,15 @@ scale-info = { version = "2.1.2", default-features = false, features = ["derive" serde = { version = "1.0.136", optional = true, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } [dev-dependencies] serde_json = "1.0.64" -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } [features] default = ["std"] diff --git a/vesting/Cargo.toml b/vesting/Cargo.toml index e316d4102..ff1dec75d 100644 --- a/vesting/Cargo.toml +++ b/vesting/Cargo.toml @@ -12,15 +12,15 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", optional = true } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } [dev-dependencies] -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } [features] default = ["std"] diff --git a/weight-meter/Cargo.toml b/weight-meter/Cargo.toml index c3cf1e656..9d9cb46be 100644 --- a/weight-meter/Cargo.toml +++ b/weight-meter/Cargo.toml @@ -10,19 +10,19 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } weight-meter-procedural = { path = "weight-meter-procedural", default-features = false } [dev-dependencies] serde = { version = "1.0.136" } codec = { package = "parity-scale-codec", version = "3.0.0" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } orml-bencher = { path = "../bencher" } diff --git a/xcm-support/Cargo.toml b/xcm-support/Cargo.toml index 2b85249b0..6198a81f1 100644 --- a/xcm-support/Cargo.toml +++ b/xcm-support/Cargo.toml @@ -10,12 +10,12 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" } -xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" } +xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" } orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } diff --git a/xcm-support/src/currency_adapter.rs b/xcm-support/src/currency_adapter.rs index d81594133..9d61e3984 100644 --- a/xcm-support/src/currency_adapter.rs +++ b/xcm-support/src/currency_adapter.rs @@ -12,7 +12,7 @@ use sp_std::{ result, }; -use xcm::latest::{Error as XcmError, MultiAsset, MultiLocation, Result}; +use xcm::latest::{prelude::*, Error as XcmError, MultiAsset, MultiLocation, Result}; use xcm_executor::{ traits::{Convert as MoreConvert, MatchesFungible, TransactAsset}, Assets, @@ -145,7 +145,7 @@ impl< DepositFailureHandler, > { - fn deposit_asset(asset: &MultiAsset, location: &MultiLocation) -> Result { + fn deposit_asset(asset: &MultiAsset, location: &MultiLocation, _context: &XcmContext) -> Result { match ( AccountIdConvert::convert_ref(location), CurrencyIdConvert::convert(asset.clone()), @@ -160,7 +160,11 @@ impl< } } - fn withdraw_asset(asset: &MultiAsset, location: &MultiLocation) -> result::Result { + fn withdraw_asset( + asset: &MultiAsset, + location: &MultiLocation, + _maybe_context: Option<&XcmContext>, + ) -> result::Result { UnknownAsset::withdraw(asset, location).or_else(|_| { let who = AccountIdConvert::convert_ref(location) .map_err(|_| XcmError::from(Error::AccountIdConversionFailed))?; @@ -179,6 +183,7 @@ impl< asset: &MultiAsset, from: &MultiLocation, to: &MultiLocation, + _context: &XcmContext, ) -> result::Result { let from_account = AccountIdConvert::convert_ref(from).map_err(|_| XcmError::from(Error::AccountIdConversionFailed))?; diff --git a/xcm-support/src/lib.rs b/xcm-support/src/lib.rs index ee98e4882..e2c5140dc 100644 --- a/xcm-support/src/lib.rs +++ b/xcm-support/src/lib.rs @@ -49,7 +49,7 @@ impl FilterAssetLocation for MultiNativeAsset where ReserveProvider: Reserve, { - fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool { + fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool { if let Some(ref reserve) = ReserveProvider::reserve(asset) { if reserve == origin { return true; diff --git a/xcm-support/src/tests.rs b/xcm-support/src/tests.rs index 5189ecd83..5e40ecedc 100644 --- a/xcm-support/src/tests.rs +++ b/xcm-support/src/tests.rs @@ -91,18 +91,18 @@ fn is_native_concrete_does_not_matches_non_native_currencies() { #[test] fn multi_native_asset() { - assert!(MultiNativeAsset::::filter_asset_location( + assert!(MultiNativeAsset::::contains( &MultiAsset { fun: Fungible(10), id: Concrete(MultiLocation::parent()) }, &Parent.into() )); - assert!(MultiNativeAsset::::filter_asset_location( + assert!(MultiNativeAsset::::contains( &MultiAsset::sibling_parachain_asset(1, b"TokenA".to_vec().try_into().unwrap(), 100), &MultiLocation::new(1, X1(Parachain(1))), )); - assert!(!MultiNativeAsset::::filter_asset_location( + assert!(!MultiNativeAsset::::contains( &MultiAsset::sibling_parachain_asset(1, b"TokenA".to_vec().try_into().unwrap(), 100), &MultiLocation::parent(), )); diff --git a/xcm/Cargo.toml b/xcm/Cargo.toml index 40f5a32d3..0b762903a 100644 --- a/xcm/Cargo.toml +++ b/xcm/Cargo.toml @@ -11,15 +11,15 @@ edition = "2021" codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } -pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" } +pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" } [dev-dependencies] -xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } +xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" } [features] default = ["std"] diff --git a/xcm/src/lib.rs b/xcm/src/lib.rs index 40057f889..6e94e6d79 100644 --- a/xcm/src/lib.rs +++ b/xcm/src/lib.rs @@ -62,7 +62,7 @@ pub mod module { let message: Xcm<()> = (*message).try_into().map_err(|()| Error::::BadVersion)?; pallet_xcm::Pallet::::send_xcm(Here, dest.clone(), message.clone()).map_err(|e| match e { - SendError::CannotReachDestination(..) => Error::::Unreachable, + SendError::Unroutable => Error::::Unreachable, _ => Error::::SendFailure, })?; Self::deposit_event(Event::Sent { to: dest, message }); diff --git a/xtokens/Cargo.toml b/xtokens/Cargo.toml index 236a726f8..80648c1da 100644 --- a/xtokens/Cargo.toml +++ b/xtokens/Cargo.toml @@ -13,19 +13,19 @@ scale-info = { version = "2.1.2", default-features = false, features = ["derive" serde = { version = "1.0.136", optional = true } # substrate -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" } # cumulus -cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", default-features = false , branch = "polkadot-v0.9.37" } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", default-features = false , branch = "polkadot-v0.9.38" } # polkadot -pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" } -xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" } +pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" } +xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" } # orml orml-traits = { path = "../traits", default-features = false} @@ -33,21 +33,21 @@ orml-xcm-support = { path = "../xcm-support", default-features = false } [dev-dependencies] # substrate -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } # cumulus -cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" } -cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" } -cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" } -cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" } -parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" } +cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" } +cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" } +cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" } +parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" } # polkadot -polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } -polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } -xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } -xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } +polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" } +polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" } +xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" } +xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" } # orml orml-tokens = { path = "../tokens" } diff --git a/xtokens/src/lib.rs b/xtokens/src/lib.rs index 0af581872..4bad01337 100644 --- a/xtokens/src/lib.rs +++ b/xtokens/src/lib.rs @@ -41,13 +41,13 @@ use frame_support::{ }; use frame_system::{ensure_signed, pallet_prelude::*}; use sp_runtime::{ - traits::{AtLeast32BitUnsigned, Convert, MaybeSerializeDeserialize, Member, Zero}, + traits::{AtLeast32BitUnsigned, Bounded, Convert, MaybeSerializeDeserialize, Member, Zero}, DispatchError, }; use sp_std::{prelude::*, result::Result}; use xcm::{latest::Weight, prelude::*}; -use xcm_executor::traits::{InvertLocation, WeightBounds}; +use xcm_executor::traits::WeightBounds; pub use module::*; use orml_traits::{ @@ -117,8 +117,8 @@ pub mod module { #[pallet::constant] type BaseXcmWeight: Get; - /// Means of inverting a location. - type LocationInverter: InvertLocation; + /// This chain's Universal Location. + type UniversalLocation: Get; /// The maximum number of distinct assets allowed to be transferred in a /// single helper extrinsic. @@ -572,9 +572,9 @@ pub mod module { let mut override_recipient = T::SelfLocation::get(); if override_recipient == MultiLocation::here() { let dest_chain_part = dest.chain_part().ok_or(Error::::InvalidDest)?; - let ancestry = T::LocationInverter::ancestry(); + let ancestry = T::UniversalLocation::get(); let _ = override_recipient - .reanchor(&dest_chain_part, &ancestry) + .reanchor(&dest_chain_part, ancestry) .map_err(|_| Error::::CannotReanchor); } @@ -659,8 +659,10 @@ pub mod module { )?, }; + let hash = msg.using_encoded(sp_io::hashing::blake2_256); + let weight = T::Weigher::weight(&mut msg).map_err(|()| Error::::UnweighableMessage)?; - T::XcmExecutor::execute_xcm_in_credit(origin_location, msg, weight, weight) + T::XcmExecutor::execute_xcm_in_credit(origin_location, msg, hash, weight, weight) .ensure_complete() .map_err(|error| { log::error!("Failed execute transfer message with {:?}", error); @@ -682,7 +684,7 @@ pub mod module { dest: dest.clone(), xcm: Xcm(vec![ Self::buy_execution(fee, &dest, dest_weight_limit)?, - Self::deposit_asset(recipient, assets.len() as u32), + Self::deposit_asset(recipient), ]), }])) } @@ -701,7 +703,7 @@ pub mod module { reserve: reserve.clone(), xcm: Xcm(vec![ Self::buy_execution(fee, &reserve, dest_weight_limit)?, - Self::deposit_asset(recipient, assets.len() as u32), + Self::deposit_asset(recipient), ]), }, ])) @@ -739,11 +741,10 @@ pub mod module { Self::buy_execution(half(&fee), &reserve, dest_weight_limit.clone())?, DepositReserveAsset { assets: All.into(), - max_assets: assets.len() as u32, dest: reanchored_dest, xcm: Xcm(vec![ Self::buy_execution(half(&fee), &dest, dest_weight_limit)?, - Self::deposit_asset(recipient, assets.len() as u32), + Self::deposit_asset(recipient), ]), }, ]), @@ -762,7 +763,7 @@ pub mod module { dest: reanchored_dest, xcm: Xcm(vec![ Self::buy_execution(half(&fee), &dest, dest_weight_limit)?, - Self::deposit_asset(recipient, assets.len() as u32), + Self::deposit_asset(recipient), ]), }, ]), @@ -771,10 +772,9 @@ pub mod module { } } - fn deposit_asset(recipient: MultiLocation, max_assets: u32) -> Instruction<()> { + fn deposit_asset(recipient: MultiLocation) -> Instruction<()> { DepositAsset { assets: All.into(), - max_assets, beneficiary: recipient, } } @@ -784,10 +784,8 @@ pub mod module { at: &MultiLocation, weight_limit: WeightLimit, ) -> Result, DispatchError> { - let ancestry = T::LocationInverter::ancestry(); - let fees = asset - .reanchored(at, &ancestry) - .map_err(|_| Error::::CannotReanchor)?; + let ancestry = T::UniversalLocation::get(); + let fees = asset.reanchored(at, ancestry).map_err(|_| Error::::CannotReanchor)?; Ok(BuyExecution { fees, weight_limit }) } @@ -859,7 +857,7 @@ pub mod module { .map_or(Weight::max_value(), |w| T::BaseXcmWeight::get().saturating_add(w)); } } - 0 + Weight::zero() } /// Returns weight of `transfer` call. @@ -868,7 +866,7 @@ pub mod module { let asset = (location, amount.into()).into(); Self::weight_of_transfer_multiasset(&asset, dest) } else { - 0 + Weight::zero() } } @@ -884,7 +882,7 @@ pub mod module { let asset: MultiAsset = (location.clone(), (*amount).into()).into(); assets.push(asset); } else { - return 0; + return Weight::zero(); } } @@ -922,7 +920,7 @@ pub mod module { .map_or(Weight::max_value(), |w| T::BaseXcmWeight::get().saturating_add(w)); } } - 0 + Weight::zero() } /// Get reserve location by `assets` and `fee_item`. the `assets` From d6132e1842cb109dd1091449d9448f1251220f69 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Wed, 22 Feb 2023 13:36:49 +0100 Subject: [PATCH 02/23] use `as_bounded_slice` --- traits/src/location.rs | 9 +++------ traits/src/multi_asset.rs | 21 +++++++-------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/traits/src/location.rs b/traits/src/location.rs index 11d11c27d..1f92b28a0 100644 --- a/traits/src/location.rs +++ b/traits/src/location.rs @@ -78,15 +78,12 @@ impl Reserve for RelativeReserveProvider { } pub trait RelativeLocations { - fn sibling_parachain_general_key(para_id: u32, general_key: BoundedVec>) -> Option; + fn sibling_parachain_general_key(para_id: u32, general_key: BoundedVec>) -> MultiLocation; } impl RelativeLocations for MultiLocation { - fn sibling_parachain_general_key(para_id: u32, general_key: BoundedVec>) -> Option { - if let Some(general_key) = Junction::try_from(general_key).ok() { - return Some(MultiLocation::new(1, X2(Parachain(para_id), general_key))); - } - None + fn sibling_parachain_general_key(para_id: u32, general_key: BoundedVec>) -> MultiLocation { + return MultiLocation::new(1, X2(Parachain(para_id), general_key.as_bounded_slice().into())); } } diff --git a/traits/src/multi_asset.rs b/traits/src/multi_asset.rs index e5825bd88..e95607386 100644 --- a/traits/src/multi_asset.rs +++ b/traits/src/multi_asset.rs @@ -4,24 +4,17 @@ use xcm::latest::prelude::*; use crate::location::RelativeLocations; pub trait ConcreteFungibleAsset { - fn sibling_parachain_asset( - para_id: u32, - general_key: BoundedVec>, - amount: u128, - ) -> Option; + fn sibling_parachain_asset(para_id: u32, general_key: BoundedVec>, amount: u128) -> MultiAsset; fn parent_asset(amount: u128) -> MultiAsset; } impl ConcreteFungibleAsset for MultiAsset { - fn sibling_parachain_asset( - para_id: u32, - general_key: BoundedVec>, - amount: u128, - ) -> Option { - if let Some(general_key) = MultiLocation::sibling_parachain_general_key(para_id, general_key) { - return Some((general_key, amount).into()); - } - None + fn sibling_parachain_asset(para_id: u32, general_key: BoundedVec>, amount: u128) -> MultiAsset { + ( + MultiLocation::sibling_parachain_general_key(para_id, general_key), + amount, + ) + .into() } fn parent_asset(amount: u128) -> MultiAsset { From a272982b023604abd9eeab9b8b6e480d615fc264 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Wed, 22 Feb 2023 13:38:23 +0100 Subject: [PATCH 03/23] `latest` instead explicit version --- asset-registry/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asset-registry/src/lib.rs b/asset-registry/src/lib.rs index dc2ec3669..fa578718a 100644 --- a/asset-registry/src/lib.rs +++ b/asset-registry/src/lib.rs @@ -14,7 +14,7 @@ use sp_runtime::{ DispatchResult, }; use sp_std::prelude::*; -use xcm::{v3::prelude::*, VersionedMultiLocation}; +use xcm::{latest::prelude::*, VersionedMultiLocation}; pub use impls::*; pub use module::*; From 14ffc083dba549820b3524c05b414f604aa7083b Mon Sep 17 00:00:00 2001 From: tgmichel Date: Wed, 22 Feb 2023 14:11:47 +0100 Subject: [PATCH 04/23] use `AllCounted` for asset deposit --- xtokens/src/lib.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/xtokens/src/lib.rs b/xtokens/src/lib.rs index 4bad01337..1ffe61266 100644 --- a/xtokens/src/lib.rs +++ b/xtokens/src/lib.rs @@ -684,7 +684,7 @@ pub mod module { dest: dest.clone(), xcm: Xcm(vec![ Self::buy_execution(fee, &dest, dest_weight_limit)?, - Self::deposit_asset(recipient), + Self::deposit_asset(recipient, assets.len() as u32), ]), }])) } @@ -703,7 +703,7 @@ pub mod module { reserve: reserve.clone(), xcm: Xcm(vec![ Self::buy_execution(fee, &reserve, dest_weight_limit)?, - Self::deposit_asset(recipient), + Self::deposit_asset(recipient, assets.len() as u32), ]), }, ])) @@ -731,6 +731,7 @@ pub mod module { } } + let max_assets = assets.len() as u32; if !use_teleport { Ok(Xcm(vec![ WithdrawAsset(assets.clone()), @@ -740,11 +741,11 @@ pub mod module { xcm: Xcm(vec![ Self::buy_execution(half(&fee), &reserve, dest_weight_limit.clone())?, DepositReserveAsset { - assets: All.into(), + assets: AllCounted(max_assets).into(), dest: reanchored_dest, xcm: Xcm(vec![ Self::buy_execution(half(&fee), &dest, dest_weight_limit)?, - Self::deposit_asset(recipient), + Self::deposit_asset(recipient, max_assets), ]), }, ]), @@ -763,7 +764,7 @@ pub mod module { dest: reanchored_dest, xcm: Xcm(vec![ Self::buy_execution(half(&fee), &dest, dest_weight_limit)?, - Self::deposit_asset(recipient), + Self::deposit_asset(recipient, max_assets), ]), }, ]), @@ -772,9 +773,9 @@ pub mod module { } } - fn deposit_asset(recipient: MultiLocation) -> Instruction<()> { + fn deposit_asset(recipient: MultiLocation, max_assets: u32) -> Instruction<()> { DepositAsset { - assets: All.into(), + assets: AllCounted(max_assets).into(), beneficiary: recipient, } } From 0b5a5d61ceabac4c5d57c7d7c9b9ba5a53dd2acc Mon Sep 17 00:00:00 2001 From: tgmichel Date: Wed, 22 Feb 2023 16:06:33 +0100 Subject: [PATCH 05/23] Update `asset-registry` tests --- asset-registry/src/mock/mod.rs | 79 ++++++++++++++++++------ asset-registry/src/mock/para.rs | 62 +++++++++++++------ asset-registry/src/mock/relay.rs | 42 ++++++++++--- asset-registry/src/tests.rs | 57 +++++++++++++---- xcm-support/src/lib.rs | 11 ++-- xtokens/src/mock/para.rs | 14 ++--- xtokens/src/mock/para_relative_view.rs | 16 ++--- xtokens/src/mock/para_teleport.rs | 14 ++--- xtokens/src/mock/relay.rs | 8 +-- xtokens/src/tests.rs | 84 +++++++++++++------------- 10 files changed, 258 insertions(+), 129 deletions(-) diff --git a/asset-registry/src/mock/mod.rs b/asset-registry/src/mock/mod.rs index a9eecb939..9e347f54f 100644 --- a/asset-registry/src/mock/mod.rs +++ b/asset-registry/src/mock/mod.rs @@ -5,6 +5,7 @@ use super::*; use mock::para::AssetRegistry; use scale_info::TypeInfo; use serde::{Deserialize, Serialize}; +use sp_core::bounded::BoundedVec; use sp_io::TestExternalities; use sp_runtime::{traits::Convert, AccountId32}; use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain}; @@ -42,12 +43,54 @@ impl Convert> for CurrencyIdConvert { fn convert(id: CurrencyId) -> Option { match id { CurrencyId::R => Some(Parent.into()), - CurrencyId::A => Some((Parent, Parachain(1), GeneralKey(b"A".to_vec().try_into().unwrap())).into()), - CurrencyId::A1 => Some((Parent, Parachain(1), GeneralKey(b"A1".to_vec().try_into().unwrap())).into()), - CurrencyId::B => Some((Parent, Parachain(2), GeneralKey(b"B".to_vec().try_into().unwrap())).into()), - CurrencyId::B1 => Some((Parent, Parachain(2), GeneralKey(b"B1".to_vec().try_into().unwrap())).into()), - CurrencyId::B2 => Some((Parent, Parachain(2), GeneralKey(b"B2".to_vec().try_into().unwrap())).into()), - CurrencyId::D => Some((Parent, Parachain(4), GeneralKey(b"D".to_vec().try_into().unwrap())).into()), + CurrencyId::A => Some( + ( + Parent, + Parachain(1), + Junction::from(BoundedVec::try_from(b"A".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::A1 => Some( + ( + Parent, + Parachain(1), + Junction::from(BoundedVec::try_from(b"A1".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::B => Some( + ( + Parent, + Parachain(2), + Junction::from(BoundedVec::try_from(b"B".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::B1 => Some( + ( + Parent, + Parachain(2), + Junction::from(BoundedVec::try_from(b"B1".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::B2 => Some( + ( + Parent, + Parachain(2), + Junction::from(BoundedVec::try_from(b"B2".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::D => Some( + ( + Parent, + Parachain(4), + Junction::from(BoundedVec::try_from(b"D".to_vec()).unwrap()), + ) + .into(), + ), CurrencyId::RegisteredAsset(id) => AssetRegistry::multilocation(&id).unwrap_or_default(), } } @@ -65,21 +108,21 @@ impl Convert> for CurrencyIdConvert { } let currency_id = match l.clone() { MultiLocation { parents, interior } if parents == 1 => match interior { - X2(Parachain(1), GeneralKey(k)) if k == a => Some(CurrencyId::A), - X2(Parachain(1), GeneralKey(k)) if k == a1 => Some(CurrencyId::A1), - X2(Parachain(2), GeneralKey(k)) if k == b => Some(CurrencyId::B), - X2(Parachain(2), GeneralKey(k)) if k == b1 => Some(CurrencyId::B1), - X2(Parachain(2), GeneralKey(k)) if k == b2 => Some(CurrencyId::B2), - X2(Parachain(4), GeneralKey(k)) if k == d => Some(CurrencyId::D), + X2(Parachain(1), GeneralKey { data, .. }) if data.to_vec() == a => Some(CurrencyId::A), + X2(Parachain(1), GeneralKey { data, .. }) if data.to_vec() == a1 => Some(CurrencyId::A1), + X2(Parachain(2), GeneralKey { data, .. }) if data.to_vec() == b => Some(CurrencyId::B), + X2(Parachain(2), GeneralKey { data, .. }) if data.to_vec() == b1 => Some(CurrencyId::B1), + X2(Parachain(2), GeneralKey { data, .. }) if data.to_vec() == b2 => Some(CurrencyId::B2), + X2(Parachain(4), GeneralKey { data, .. }) if data.to_vec() == d => Some(CurrencyId::D), _ => None, }, MultiLocation { parents, interior } if parents == 0 => match interior { - X1(GeneralKey(k)) if k == a => Some(CurrencyId::A), - X1(GeneralKey(k)) if k == b => Some(CurrencyId::B), - X1(GeneralKey(k)) if k == a1 => Some(CurrencyId::A1), - X1(GeneralKey(k)) if k == b1 => Some(CurrencyId::B1), - X1(GeneralKey(k)) if k == b2 => Some(CurrencyId::B2), - X1(GeneralKey(k)) if k == d => Some(CurrencyId::D), + X1(GeneralKey { data, .. }) if data.to_vec() == a => Some(CurrencyId::A), + X1(GeneralKey { data, .. }) if data.to_vec() == b => Some(CurrencyId::B), + X1(GeneralKey { data, .. }) if data.to_vec() == a1 => Some(CurrencyId::A1), + X1(GeneralKey { data, .. }) if data.to_vec() == b1 => Some(CurrencyId::B1), + X1(GeneralKey { data, .. }) if data.to_vec() == b2 => Some(CurrencyId::B2), + X1(GeneralKey { data, .. }) if data.to_vec() == d => Some(CurrencyId::D), _ => None, }, _ => None, diff --git a/asset-registry/src/mock/para.rs b/asset-registry/src/mock/para.rs index 2e60a6350..06f6109e6 100644 --- a/asset-registry/src/mock/para.rs +++ b/asset-registry/src/mock/para.rs @@ -28,9 +28,9 @@ use sp_runtime::{ }; use xcm::latest::{prelude::*, Weight}; use xcm_builder::{ - AccountId32Aliases, AllowTopLevelPaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds, LocationInverter, - ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit, + AccountId32Aliases, AllowTopLevelPaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds, ParentIsPreset, + RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit, }; use xcm_executor::{Config, XcmExecutor}; @@ -143,8 +143,8 @@ impl orml_asset_registry::Config for Runtime { } parameter_types! { - pub const ReservedXcmpWeight: Weight = WEIGHT_REF_TIME_PER_SECOND / 4; - pub const ReservedDmpWeight: Weight = WEIGHT_REF_TIME_PER_SECOND / 4; + pub const ReservedXcmpWeight: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4)); + pub const ReservedDmpWeight: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4)); } impl parachain_info::Config for Runtime {} @@ -153,7 +153,8 @@ parameter_types! { pub const RelayLocation: MultiLocation = MultiLocation::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); - pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + pub UniversalLocation: InteriorMultiLocation = + X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())); } pub type LocationToAccountId = ( @@ -214,6 +215,13 @@ impl FixedConversionRateProvider for MyFixedConversionRateProvider { } } +parameter_types! { + pub const UnitWeightCost: Weight = Weight::from_parts(10, 10); + pub const BaseXcmWeight: Weight = Weight::from_parts(100_000_000, 100_000_000); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + pub struct XcmConfig; impl Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -222,14 +230,23 @@ impl Config for XcmConfig { type OriginConverter = XcmOriginToCallOrigin; type IsReserve = MultiNativeAsset; type IsTeleporter = (); - type LocationInverter = LocationInverter; + type UniversalLocation = UniversalLocation; type Barrier = Barrier; - type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; + type Weigher = FixedWeightBounds; type Trader = AssetRegistryWeightTrader; type ResponseHandler = (); type AssetTrap = PolkadotXcm; type AssetClaims = PolkadotXcm; type SubscriptionService = PolkadotXcm; + type AssetLocker = PolkadotXcm; + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; } pub struct ChannelInfo; @@ -251,6 +268,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = EnsureRoot; type ControllerOriginConverter = XcmOriginToCallOrigin; type WeightInfo = (); + type PriceForSiblingDelivery = (); } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -266,6 +284,11 @@ impl cumulus_pallet_xcm::Config for Runtime { pub type LocalOriginToLocation = SignedToAccountId32; +parameter_types! { + pub SelfLocation: MultiLocation = MultiLocation::here(); + pub const MaxAssetsForTransfer: usize = 3; +} + impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SendXcmOrigin = EnsureXcmOrigin; @@ -275,30 +298,31 @@ impl pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; type XcmTeleportFilter = Nothing; type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; - type LocationInverter = LocationInverter; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; } pub struct AccountIdToMultiLocation; impl Convert for AccountIdToMultiLocation { fn convert(account: AccountId) -> MultiLocation { X1(Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: account.into(), }) .into() } } -parameter_types! { - pub SelfLocation: MultiLocation = MultiLocation::here(); - pub const MaxAssetsForTransfer: usize = 3; -} - match_types! { pub type ParentOrParachains: impl Contains = { MultiLocation { parents: 0, interior: X1(Junction::AccountId32 { .. }) } | @@ -331,9 +355,9 @@ impl orml_xtokens::Config for Runtime { type MultiLocationsFilter = ParentOrParachains; type MinXcmFee = ParachainMinFee; type XcmExecutor = XcmExecutor; - type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; - type BaseXcmWeight = ConstU64<100_000_000>; - type LocationInverter = LocationInverter; + type Weigher = FixedWeightBounds; + type BaseXcmWeight = BaseXcmWeight; + type UniversalLocation = UniversalLocation; type MaxAssetsForTransfer = MaxAssetsForTransfer; type ReserveProvider = RelativeReserveProvider; } diff --git a/asset-registry/src/mock/relay.rs b/asset-registry/src/mock/relay.rs index f6ec6f367..bcd54bc97 100644 --- a/asset-registry/src/mock/relay.rs +++ b/asset-registry/src/mock/relay.rs @@ -1,7 +1,8 @@ +use crate::Weight; use cumulus_primitives_core::ParaId; use frame_support::{ construct_runtime, parameter_types, - traits::{ConstU128, ConstU32, ConstU64, Everything}, + traits::{ConstU128, ConstU32, ConstU64, Everything, Nothing}, weights::IdentityFee, }; use frame_system::EnsureRoot; @@ -11,7 +12,7 @@ use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative, ChildParachainConvertsVia, - CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsConcrete, LocationInverter, SignedAccountId32AsNative, + CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsConcrete, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, }; use xcm_executor::{Config, XcmExecutor}; @@ -65,9 +66,9 @@ impl configuration::Config for Runtime { } parameter_types! { - pub const KsmLocation: MultiLocation = Here.into(); + pub KsmLocation: MultiLocation = Here.into(); pub const KusamaNetwork: NetworkId = NetworkId::Kusama; - pub Ancestry: MultiLocation = Here.into(); + pub UniversalLocation: InteriorMultiLocation = Here; } pub type SovereignAccountOf = ( @@ -87,6 +88,12 @@ type LocalOriginConverter = ( pub type XcmRouter = super::RelayChainXcmRouter; pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom); +parameter_types! { + pub const BaseXcmWeight: Weight = Weight::from_parts(10, 10); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + pub struct XcmConfig; impl Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -95,18 +102,31 @@ impl Config for XcmConfig { type OriginConverter = LocalOriginConverter; type IsReserve = (); type IsTeleporter = (); - type LocationInverter = LocationInverter; + type UniversalLocation = UniversalLocation; type Barrier = Barrier; - type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; + type Weigher = FixedWeightBounds; type Trader = UsingComponents, KsmLocation, AccountId, Balances, ()>; type ResponseHandler = (); type AssetTrap = (); type AssetClaims = (); type SubscriptionService = XcmPallet; + type AssetLocker = XcmPallet; + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; } pub type LocalOriginToLocation = SignedToAccountId32; +parameter_types! { + pub SelfLocation: MultiLocation = MultiLocation::here(); +} + impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; @@ -117,12 +137,18 @@ impl pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; type XcmTeleportFilter = Everything; type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; - type LocationInverter = LocationInverter; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = IsConcrete; + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; } impl ump::Config for Runtime { diff --git a/asset-registry/src/tests.rs b/asset-registry/src/tests.rs index f204c8c31..f331cf4c9 100644 --- a/asset-registry/src/tests.rs +++ b/asset-registry/src/tests.rs @@ -46,7 +46,13 @@ fn dummy_metadata() -> AssetMetadata<(PhantomData); -impl FilterAssetLocation for MultiNativeAsset +impl ContainsPair for MultiNativeAsset where ReserveProvider: Reserve, { diff --git a/xtokens/src/mock/para.rs b/xtokens/src/mock/para.rs index 19f38d690..1f1e51729 100644 --- a/xtokens/src/mock/para.rs +++ b/xtokens/src/mock/para.rs @@ -19,8 +19,8 @@ use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; use xcm::latest::{prelude::*, Weight}; use xcm_builder::{ - AccountId32Aliases, AllowTopLevelPaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds, LocationInverter, - NativeAsset, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + AccountId32Aliases, AllowTopLevelPaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds, NativeAsset, + ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, }; use xcm_executor::{Config, XcmExecutor}; @@ -101,7 +101,7 @@ parameter_types! { pub const RelayLocation: MultiLocation = MultiLocation::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); - pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); } pub type LocationToAccountId = ( @@ -140,7 +140,7 @@ impl Config for XcmConfig { type OriginConverter = XcmOriginToCallOrigin; type IsReserve = MultiNativeAsset; type IsTeleporter = NativeAsset; - type LocationInverter = LocationInverter; + type UniversalLocation = UniversalLocation; type Barrier = Barrier; type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; type Trader = AllTokensAreCreatedEqualToWeight; @@ -194,7 +194,7 @@ impl pallet_xcm::Config for Runtime { type XcmTeleportFilter = Nothing; type XcmReserveTransferFilter = Everything; type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; - type LocationInverter = LocationInverter; + type UniversalLocation = UniversalLocation; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; @@ -205,7 +205,7 @@ pub struct AccountIdToMultiLocation; impl Convert for AccountIdToMultiLocation { fn convert(account: AccountId) -> MultiLocation { X1(Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: account.into(), }) .into() @@ -251,7 +251,7 @@ impl orml_xtokens::Config for Runtime { type XcmExecutor = XcmExecutor; type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; type BaseXcmWeight = ConstU64<100_000_000>; - type LocationInverter = LocationInverter; + type UniversalLocation = UniversalLocation; type MaxAssetsForTransfer = MaxAssetsForTransfer; type ReserveProvider = AbsoluteReserveProvider; } diff --git a/xtokens/src/mock/para_relative_view.rs b/xtokens/src/mock/para_relative_view.rs index a44283438..42386c916 100644 --- a/xtokens/src/mock/para_relative_view.rs +++ b/xtokens/src/mock/para_relative_view.rs @@ -19,9 +19,9 @@ use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; use xcm::latest::{prelude::*, Weight}; use xcm_builder::{ - AccountId32Aliases, AllowTopLevelPaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds, LocationInverter, - ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + AccountId32Aliases, AllowTopLevelPaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds, ParentIsPreset, + RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, }; use xcm_executor::{Config, XcmExecutor}; @@ -104,7 +104,7 @@ parameter_types! { pub const RelayLocation: MultiLocation = MultiLocation::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); - pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); } pub type LocationToAccountId = ( @@ -143,7 +143,7 @@ impl Config for XcmConfig { type OriginConverter = XcmOriginToCallOrigin; type IsReserve = MultiNativeAsset; type IsTeleporter = (); - type LocationInverter = LocationInverter; + type UniversalLocation = UniversalLocation; type Barrier = Barrier; type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; type Trader = AllTokensAreCreatedEqualToWeight; @@ -197,7 +197,7 @@ impl pallet_xcm::Config for Runtime { type XcmTeleportFilter = Nothing; type XcmReserveTransferFilter = Everything; type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; - type LocationInverter = LocationInverter; + type UniversalLocation = UniversalLocation; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; @@ -208,7 +208,7 @@ pub struct AccountIdToMultiLocation; impl Convert for AccountIdToMultiLocation { fn convert(account: AccountId) -> MultiLocation { X1(Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: account.into(), }) .into() @@ -323,7 +323,7 @@ impl orml_xtokens::Config for Runtime { type XcmExecutor = XcmExecutor; type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; type BaseXcmWeight = ConstU64<100_000_000>; - type LocationInverter = LocationInverter; + type UniversalLocation = UniversalLocation; type MaxAssetsForTransfer = MaxAssetsForTransfer; type ReserveProvider = RelativeReserveProvider; } diff --git a/xtokens/src/mock/para_teleport.rs b/xtokens/src/mock/para_teleport.rs index 75fbd509c..92b5040e6 100644 --- a/xtokens/src/mock/para_teleport.rs +++ b/xtokens/src/mock/para_teleport.rs @@ -19,8 +19,8 @@ use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; use xcm::latest::{prelude::*, Weight}; use xcm_builder::{ - AccountId32Aliases, AllowTopLevelPaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds, LocationInverter, - NativeAsset, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + AccountId32Aliases, AllowTopLevelPaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds, NativeAsset, + ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, }; use xcm_executor::{Config, XcmExecutor}; @@ -102,7 +102,7 @@ parameter_types! { pub const RelayLocation: MultiLocation = MultiLocation::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); - pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); } pub type LocationToAccountId = ( @@ -141,7 +141,7 @@ impl Config for XcmConfig { type OriginConverter = XcmOriginToCallOrigin; type IsReserve = MultiNativeAsset; type IsTeleporter = NativeAsset; - type LocationInverter = LocationInverter; + type UniversalLocation = UniversalLocation; type Barrier = Barrier; type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; type Trader = AllTokensAreCreatedEqualToWeight; @@ -195,7 +195,7 @@ impl pallet_xcm::Config for Runtime { type XcmTeleportFilter = Nothing; type XcmReserveTransferFilter = Everything; type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; - type LocationInverter = LocationInverter; + type UniversalLocation = UniversalLocation; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; @@ -206,7 +206,7 @@ pub struct AccountIdToMultiLocation; impl Convert for AccountIdToMultiLocation { fn convert(account: AccountId) -> MultiLocation { X1(Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: account.into(), }) .into() @@ -242,7 +242,7 @@ impl orml_xtokens::Config for Runtime { type XcmExecutor = XcmExecutor; type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; type BaseXcmWeight = ConstU64<100_000_000>; - type LocationInverter = LocationInverter; + type UniversalLocation = UniversalLocation; type MaxAssetsForTransfer = MaxAssetsForTransfer; type ReserveProvider = AbsoluteReserveProvider; } diff --git a/xtokens/src/mock/relay.rs b/xtokens/src/mock/relay.rs index e0b1e9965..e8bb3b8ca 100644 --- a/xtokens/src/mock/relay.rs +++ b/xtokens/src/mock/relay.rs @@ -12,7 +12,7 @@ use polkadot_runtime_parachains::{configuration, origin, shared, ump}; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative, ChildParachainConvertsVia, - CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsConcrete, LocationInverter, SignedAccountId32AsNative, + CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsConcrete, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, }; use xcm_executor::{Config, XcmExecutor}; @@ -68,7 +68,7 @@ impl configuration::Config for Runtime { parameter_types! { pub const KsmLocation: MultiLocation = Here.into(); pub const KusamaNetwork: NetworkId = NetworkId::Kusama; - pub Ancestry: MultiLocation = Here.into(); + pub UniversalLocation: InteriorMultiLocation = Here; } pub type SovereignAccountOf = ( @@ -104,7 +104,7 @@ impl Config for XcmConfig { type OriginConverter = LocalOriginConverter; type IsReserve = (); type IsTeleporter = TrustedTeleporters; - type LocationInverter = LocationInverter; + type UniversalLocation = UniversalLocation; type Barrier = Barrier; type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; type Trader = UsingComponents, KsmLocation, AccountId, Balances, ()>; @@ -127,7 +127,7 @@ impl pallet_xcm::Config for Runtime { type XcmTeleportFilter = Everything; type XcmReserveTransferFilter = Everything; type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; - type LocationInverter = LocationInverter; + type UniversalLocation = UniversalLocation; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; diff --git a/xtokens/src/tests.rs b/xtokens/src/tests.rs index 79ef3c0b7..af434df15 100644 --- a/xtokens/src/tests.rs +++ b/xtokens/src/tests.rs @@ -65,7 +65,7 @@ fn send_relay_chain_asset_to_relay_chain() { MultiLocation::new( 1, X1(Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }) ) @@ -100,7 +100,7 @@ fn send_relay_chain_asset_to_relay_chain_with_fee() { MultiLocation::new( 1, X1(Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }) ) @@ -134,7 +134,7 @@ fn cannot_lost_fund_on_send_failed() { Parent, Parachain(100), Junction::AccountId32 { - network: NetworkId::Kusama, + network: None, id: BOB.into(), }, ) @@ -168,7 +168,7 @@ fn send_relay_chain_asset_to_sibling() { X2( Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -210,7 +210,7 @@ fn send_relay_chain_asset_to_sibling_with_fee() { X2( Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -258,7 +258,7 @@ fn send_sibling_asset_to_reserve_sibling() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -283,7 +283,7 @@ fn send_sibling_asset_to_reserve_sibling() { Parent, Parachain(1), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: ALICE.into(), }, ) @@ -323,7 +323,7 @@ fn send_sibling_asset_to_reserve_sibling_with_fee() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -366,7 +366,7 @@ fn send_sibling_asset_to_reserve_sibling_with_distinct_fee() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -412,7 +412,7 @@ fn send_sibling_asset_to_reserve_sibling_with_distinct_fee_index_works() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -457,7 +457,7 @@ fn send_sibling_asset_to_non_reserve_sibling() { X2( Parachain(3), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -504,7 +504,7 @@ fn send_sibling_asset_to_non_reserve_sibling_with_fee() { X2( Parachain(3), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -546,7 +546,7 @@ fn send_self_parachain_asset_to_sibling() { X2( Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -583,7 +583,7 @@ fn send_self_parachain_asset_to_sibling_with_fee() { X2( Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -621,7 +621,7 @@ fn send_self_parachain_asset_to_sibling_with_distinct_fee() { X2( Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -675,7 +675,7 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_works() { Parent, Parachain(3), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -735,7 +735,7 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_works_with_relative_s Parent, Parachain(3), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -798,7 +798,7 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_not_enough() { Parent, Parachain(3), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -844,7 +844,7 @@ fn transfer_asset_with_relay_fee_failed() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -868,7 +868,7 @@ fn transfer_asset_with_relay_fee_failed() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -893,7 +893,7 @@ fn transfer_asset_with_relay_fee_failed() { Parent, Parachain(3), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -917,7 +917,7 @@ fn transfer_asset_with_relay_fee_failed() { Parent, Parachain(1), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -944,7 +944,7 @@ fn transfer_no_reserve_assets_fails() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into() } ) @@ -972,7 +972,7 @@ fn transfer_to_self_chain_fails() { X2( Parachain(1), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into() } ) @@ -999,7 +999,7 @@ fn transfer_to_invalid_dest_fails() { MultiLocation::new( 0, X1(Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into() }) ) @@ -1130,7 +1130,7 @@ fn send_with_zero_fee_should_yield_an_error() { X2( Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -1164,7 +1164,7 @@ fn send_with_insufficient_fee_traps_assets() { X2( Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -1207,7 +1207,7 @@ fn send_with_fee_should_handle_overflow() { X2( Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -1258,7 +1258,7 @@ fn specifying_more_than_assets_limit_should_error() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -1299,7 +1299,7 @@ fn sending_non_fee_assets_with_different_reserve_should_fail() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -1335,7 +1335,7 @@ fn specifying_a_non_existent_asset_index_should_fail() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -1363,7 +1363,7 @@ fn send_with_zero_amount() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -1384,7 +1384,7 @@ fn send_with_zero_amount() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -1416,7 +1416,7 @@ fn send_self_parachain_asset_to_sibling_relative_parachain() { X2( Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -1462,7 +1462,7 @@ fn send_sibling_asset_to_reserve_sibling_with_relative_view() { Parent, Parachain(4), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -1490,7 +1490,7 @@ fn send_sibling_asset_to_reserve_sibling_with_relative_view() { Parent, Parachain(1), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: ALICE.into(), }, ) @@ -1530,7 +1530,7 @@ fn send_relative_view_sibling_asset_to_non_reserve_sibling() { X2( Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -1578,7 +1578,7 @@ fn send_relay_chain_asset_to_relative_view_sibling() { X2( Parachain(4), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -1617,7 +1617,7 @@ fn unsupported_multilocation_should_be_filtered() { Parent, Parachain(5), // parachain 4 is not supported list. Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -1638,7 +1638,7 @@ fn unsupported_multilocation_should_be_filtered() { Parent, Parachain(5), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -1668,7 +1668,7 @@ fn send_with_sufficient_weight_limit() { X2( Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -1704,7 +1704,7 @@ fn send_with_insufficient_weight_limit() { X2( Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) From 3be81aee2e4cd0915d1f8269a298674dea50ac3c Mon Sep 17 00:00:00 2001 From: tgmichel Date: Wed, 22 Feb 2023 16:52:29 +0100 Subject: [PATCH 06/23] Update `benchmarking` tests --- benchmarking/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/benchmarking/src/lib.rs b/benchmarking/src/lib.rs index f165cb682..20c42ec52 100644 --- a/benchmarking/src/lib.rs +++ b/benchmarking/src/lib.rs @@ -741,6 +741,9 @@ macro_rules! impl_benchmark { $crate::BenchmarkMetadata { name: benchmark.as_bytes().to_vec(), components, + // TODO: Not supported by V2 syntax as of yet. + // https://github.com/paritytech/substrate/issues/13132 + pov_modes: vec![], } }).collect::<$crate::Vec<_>>() } From dcc9031f3997776da00ee628a02975346a77a507 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Wed, 22 Feb 2023 16:53:24 +0100 Subject: [PATCH 07/23] Update `traits` tests --- traits/src/location.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/traits/src/location.rs b/traits/src/location.rs index 1f92b28a0..fcbaeb4ba 100644 --- a/traits/src/location.rs +++ b/traits/src/location.rs @@ -139,14 +139,14 @@ mod tests { assert_eq!( AbsoluteReserveProvider::reserve(&concrete_fungible(MultiLocation::new( 0, - X1(GeneralKey(b"DOT".to_vec().try_into().unwrap())) + X1(Junction::from(BoundedVec::try_from(b"DOT".to_vec()).unwrap())) ))), None ); assert_eq!( RelativeReserveProvider::reserve(&concrete_fungible(MultiLocation::new( 0, - X1(GeneralKey(b"DOT".to_vec().try_into().unwrap())) + X1(Junction::from(BoundedVec::try_from(b"DOT".to_vec()).unwrap())) ))), Some(MultiLocation::here()) ); From 6b5667e39a12321c337920ce95ad96430a725c14 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Wed, 22 Feb 2023 16:54:26 +0100 Subject: [PATCH 08/23] Update `unknown-tokens` tests --- unknown-tokens/src/tests.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/unknown-tokens/src/tests.rs b/unknown-tokens/src/tests.rs index 236d7f1fe..99b247f4c 100644 --- a/unknown-tokens/src/tests.rs +++ b/unknown-tokens/src/tests.rs @@ -10,8 +10,8 @@ use frame_support::{assert_err, assert_ok}; const MOCK_RECIPIENT: MultiLocation = MultiLocation::parent(); const MOCK_CONCRETE_FUNGIBLE_ID: MultiLocation = MultiLocation::parent(); -fn mock_abstract_fungible_id() -> Vec { - vec![1] +fn mock_abstract_fungible_id() -> [u8; 32] { + [1; 32] } fn concrete_fungible(amount: u128) -> MultiAsset { @@ -51,7 +51,7 @@ fn deposit_abstract_fungible_asset() { let asset = abstract_fungible(3); assert_ok!(UnknownTokens::deposit(&asset, &MOCK_RECIPIENT)); assert_eq!( - UnknownTokens::abstract_fungible_balances(&MOCK_RECIPIENT, &mock_abstract_fungible_id()), + UnknownTokens::abstract_fungible_balances(&MOCK_RECIPIENT, &mock_abstract_fungible_id().to_vec()), 3 ); System::assert_last_event(RuntimeEvent::UnknownTokens(crate::Event::Deposited { @@ -66,7 +66,7 @@ fn deposit_abstract_fungible_asset() { Error::::BalanceOverflow ); assert_eq!( - UnknownTokens::abstract_fungible_balances(&MOCK_RECIPIENT, &mock_abstract_fungible_id()), + UnknownTokens::abstract_fungible_balances(&MOCK_RECIPIENT, &mock_abstract_fungible_id().to_vec()), 3 ); }); @@ -115,12 +115,12 @@ fn withdraw_concrete_fungible_asset_works() { #[test] fn withdraw_abstract_fungible_asset_works() { ExtBuilder.build().execute_with(|| { - AbstractFungibleBalances::::insert(&MOCK_RECIPIENT, &mock_abstract_fungible_id(), 3); + AbstractFungibleBalances::::insert(&MOCK_RECIPIENT, &mock_abstract_fungible_id().to_vec(), 3); let asset = abstract_fungible(3); assert_ok!(UnknownTokens::withdraw(&asset, &MOCK_RECIPIENT)); assert_eq!( - UnknownTokens::abstract_fungible_balances(&MOCK_RECIPIENT, &mock_abstract_fungible_id()), + UnknownTokens::abstract_fungible_balances(&MOCK_RECIPIENT, &mock_abstract_fungible_id().to_vec()), 0 ); System::assert_last_event(RuntimeEvent::UnknownTokens(crate::Event::Withdrawn { From 7871198dd7bd0c2f77cf859d5a73997ec2b38f0c Mon Sep 17 00:00:00 2001 From: tgmichel Date: Wed, 22 Feb 2023 16:55:19 +0100 Subject: [PATCH 09/23] Update `xcm-support` tests --- xcm-support/src/tests.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xcm-support/src/tests.rs b/xcm-support/src/tests.rs index 5e40ecedc..69f8dd159 100644 --- a/xcm-support/src/tests.rs +++ b/xcm-support/src/tests.rs @@ -82,7 +82,9 @@ fn is_native_concrete_does_not_matches_non_native_currencies() { fun: Fungible(100), id: Concrete(MultiLocation::new( 1, - X1(GeneralKey(b"TokenB".to_vec().try_into().unwrap())) + X1(Junction::from( + sp_runtime::BoundedVec::try_from(b"TokenB".to_vec()).unwrap() + )) )), }) .is_none() From 45682691a8c9b0e944cd6a75934af13b99cf7200 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Thu, 23 Feb 2023 14:40:17 +0100 Subject: [PATCH 10/23] Update `xtokens` tests --- xtokens/src/lib.rs | 2 - xtokens/src/mock/mod.rs | 118 ++++++++++---- xtokens/src/mock/para.rs | 38 ++++- xtokens/src/mock/para_relative_view.rs | 147 +++++++++++++----- xtokens/src/mock/para_teleport.rs | 38 ++++- xtokens/src/mock/relay.rs | 39 ++++- xtokens/src/mock/teleport_currency_adapter.rs | 14 +- xtokens/src/tests.rs | 41 +++-- 8 files changed, 324 insertions(+), 113 deletions(-) diff --git a/xtokens/src/lib.rs b/xtokens/src/lib.rs index 1ffe61266..a21146c49 100644 --- a/xtokens/src/lib.rs +++ b/xtokens/src/lib.rs @@ -644,7 +644,6 @@ pub mod module { Some(recipient) => recipient, None => recipient, }; - let mut msg = match transfer_kind { SelfReserveAsset => Self::transfer_self_reserve_asset(assets, fee, dest, recipient, dest_weight_limit)?, ToReserve => Self::transfer_to_reserve(assets, fee, dest, recipient, dest_weight_limit)?, @@ -658,7 +657,6 @@ pub mod module { use_teleport, )?, }; - let hash = msg.using_encoded(sp_io::hashing::blake2_256); let weight = T::Weigher::weight(&mut msg).map_err(|()| Error::::UnweighableMessage)?; diff --git a/xtokens/src/mock/mod.rs b/xtokens/src/mock/mod.rs index 4a128ff11..bac4e881e 100644 --- a/xtokens/src/mock/mod.rs +++ b/xtokens/src/mock/mod.rs @@ -6,7 +6,7 @@ use crate as orml_xtokens; use scale_info::TypeInfo; use serde::{Deserialize, Serialize}; use sp_io::TestExternalities; -use sp_runtime::AccountId32; +use sp_runtime::{AccountId32, BoundedVec}; use xcm_executor::traits::WeightTrader; use xcm_executor::Assets; @@ -47,47 +47,103 @@ impl Convert> for CurrencyIdConvert { fn convert(id: CurrencyId) -> Option { match id { CurrencyId::R => Some(Parent.into()), - CurrencyId::A => Some((Parent, Parachain(1), GeneralKey(b"A".to_vec().try_into().unwrap())).into()), - CurrencyId::A1 => Some((Parent, Parachain(1), GeneralKey(b"A1".to_vec().try_into().unwrap())).into()), - CurrencyId::B => Some((Parent, Parachain(2), GeneralKey(b"B".to_vec().try_into().unwrap())).into()), - CurrencyId::B1 => Some((Parent, Parachain(2), GeneralKey(b"B1".to_vec().try_into().unwrap())).into()), - CurrencyId::B2 => Some((Parent, Parachain(2), GeneralKey(b"B2".to_vec().try_into().unwrap())).into()), - CurrencyId::C => Some((Parent, Parachain(3), GeneralKey(b"C".to_vec().try_into().unwrap())).into()), - CurrencyId::D => Some((Parent, Parachain(4), GeneralKey(b"D".to_vec().try_into().unwrap())).into()), + CurrencyId::A => Some( + ( + Parent, + Parachain(1), + Junction::from(BoundedVec::try_from(b"A".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::A1 => Some( + ( + Parent, + Parachain(1), + Junction::from(BoundedVec::try_from(b"A1".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::B => Some( + ( + Parent, + Parachain(2), + Junction::from(BoundedVec::try_from(b"B".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::B1 => Some( + ( + Parent, + Parachain(2), + Junction::from(BoundedVec::try_from(b"B1".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::B2 => Some( + ( + Parent, + Parachain(2), + Junction::from(BoundedVec::try_from(b"B2".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::C => Some( + ( + Parent, + Parachain(3), + Junction::from(BoundedVec::try_from(b"C".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::D => Some( + ( + Parent, + Parachain(4), + Junction::from(BoundedVec::try_from(b"D".to_vec()).unwrap()), + ) + .into(), + ), } } } impl Convert> for CurrencyIdConvert { fn convert(l: MultiLocation) -> Option { - let a: Vec = "A".into(); - let a1: Vec = "A1".into(); - let b: Vec = "B".into(); - let b1: Vec = "B1".into(); - let b2: Vec = "B2".into(); - let c: Vec = "C".into(); - let d: Vec = "D".into(); + let mut a: Vec = "A".into(); + a.resize(32, 0); + let mut a1: Vec = "A1".into(); + a1.resize(32, 0); + let mut b: Vec = "B".into(); + b.resize(32, 0); + let mut b1: Vec = "B1".into(); + b1.resize(32, 0); + let mut b2: Vec = "B2".into(); + b2.resize(32, 0); + let mut c: Vec = "C".into(); + c.resize(32, 0); + let mut d: Vec = "D".into(); + d.resize(32, 0); if l == MultiLocation::parent() { return Some(CurrencyId::R); } match l { MultiLocation { parents, interior } if parents == 1 => match interior { - X2(Parachain(1), GeneralKey(k)) if k == a => Some(CurrencyId::A), - X2(Parachain(1), GeneralKey(k)) if k == a1 => Some(CurrencyId::A1), - X2(Parachain(2), GeneralKey(k)) if k == b => Some(CurrencyId::B), - X2(Parachain(2), GeneralKey(k)) if k == b1 => Some(CurrencyId::B1), - X2(Parachain(2), GeneralKey(k)) if k == b2 => Some(CurrencyId::B2), - X2(Parachain(3), GeneralKey(k)) if k == c => Some(CurrencyId::C), - X2(Parachain(4), GeneralKey(k)) if k == d => Some(CurrencyId::D), + X2(Parachain(1), GeneralKey { data, .. }) if data.to_vec() == a => Some(CurrencyId::A), + X2(Parachain(1), GeneralKey { data, .. }) if data.to_vec() == a1 => Some(CurrencyId::A1), + X2(Parachain(2), GeneralKey { data, .. }) if data.to_vec() == b => Some(CurrencyId::B), + X2(Parachain(2), GeneralKey { data, .. }) if data.to_vec() == b1 => Some(CurrencyId::B1), + X2(Parachain(2), GeneralKey { data, .. }) if data.to_vec() == b2 => Some(CurrencyId::B2), + X2(Parachain(3), GeneralKey { data, .. }) if data.to_vec() == c => Some(CurrencyId::C), + X2(Parachain(4), GeneralKey { data, .. }) if data.to_vec() == d => Some(CurrencyId::D), _ => None, }, MultiLocation { parents, interior } if parents == 0 => match interior { - X1(GeneralKey(k)) if k == a => Some(CurrencyId::A), - X1(GeneralKey(k)) if k == b => Some(CurrencyId::B), - X1(GeneralKey(k)) if k == a1 => Some(CurrencyId::A1), - X1(GeneralKey(k)) if k == b1 => Some(CurrencyId::B1), - X1(GeneralKey(k)) if k == b2 => Some(CurrencyId::B2), - X1(GeneralKey(k)) if k == c => Some(CurrencyId::C), - X1(GeneralKey(k)) if k == d => Some(CurrencyId::D), + X1(GeneralKey { data, .. }) if data.to_vec() == a => Some(CurrencyId::A), + X1(GeneralKey { data, .. }) if data.to_vec() == b => Some(CurrencyId::B), + X1(GeneralKey { data, .. }) if data.to_vec() == a1 => Some(CurrencyId::A1), + X1(GeneralKey { data, .. }) if data.to_vec() == b1 => Some(CurrencyId::B1), + X1(GeneralKey { data, .. }) if data.to_vec() == b2 => Some(CurrencyId::B2), + X1(GeneralKey { data, .. }) if data.to_vec() == c => Some(CurrencyId::C), + X1(GeneralKey { data, .. }) if data.to_vec() == d => Some(CurrencyId::D), _ => None, }, _ => None, @@ -263,7 +319,7 @@ impl WeightTrader for AllTokensAreCreatedEqualToWeight { .0; let required = MultiAsset { id: asset_id.clone(), - fun: Fungible(weight as u128), + fun: Fungible(weight.ref_time() as u128), }; if let MultiAsset { @@ -282,7 +338,7 @@ impl WeightTrader for AllTokensAreCreatedEqualToWeight { if weight.is_zero() { None } else { - Some((self.0.clone(), weight as u128).into()) + Some((self.0.clone(), weight.ref_time() as u128).into()) } } } diff --git a/xtokens/src/mock/para.rs b/xtokens/src/mock/para.rs index 1f1e51729..af2ba9398 100644 --- a/xtokens/src/mock/para.rs +++ b/xtokens/src/mock/para.rs @@ -91,8 +91,8 @@ impl orml_tokens::Config for Runtime { } parameter_types! { - pub const ReservedXcmpWeight: Weight = WEIGHT_REF_TIME_PER_SECOND / 4; - pub const ReservedDmpWeight: Weight = WEIGHT_REF_TIME_PER_SECOND / 4; + pub const ReservedXcmpWeight: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4)); + pub const ReservedDmpWeight: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4)); } impl parachain_info::Config for Runtime {} @@ -101,7 +101,8 @@ parameter_types! { pub const RelayLocation: MultiLocation = MultiLocation::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); - pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + pub UniversalLocation: InteriorMultiLocation = + X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())); } pub type LocationToAccountId = ( @@ -132,6 +133,13 @@ pub type LocalAssetTransactor = MultiCurrencyAdapter< pub type XcmRouter = ParachainXcmRouter; pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom); +parameter_types! { + pub const UnitWeightCost: Weight = Weight::from_parts(10, 10); + pub const BaseXcmWeight: Weight = Weight::from_parts(100_000_000, 100_000_000); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + pub struct XcmConfig; impl Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -142,12 +150,21 @@ impl Config for XcmConfig { type IsTeleporter = NativeAsset; type UniversalLocation = UniversalLocation; type Barrier = Barrier; - type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; + type Weigher = FixedWeightBounds; type Trader = AllTokensAreCreatedEqualToWeight; type ResponseHandler = (); type AssetTrap = PolkadotXcm; type AssetClaims = PolkadotXcm; type SubscriptionService = PolkadotXcm; + type AssetLocker = PolkadotXcm; + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; } pub struct ChannelInfo; @@ -169,6 +186,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = EnsureRoot; type ControllerOriginConverter = XcmOriginToCallOrigin; type WeightInfo = (); + type PriceForSiblingDelivery = (); } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -193,12 +211,18 @@ impl pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; type XcmTeleportFilter = Nothing; type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; + type Weigher = FixedWeightBounds; type UniversalLocation = UniversalLocation; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; } pub struct AccountIdToMultiLocation; @@ -249,8 +273,8 @@ impl orml_xtokens::Config for Runtime { type MultiLocationsFilter = ParentOrParachains; type MinXcmFee = ParachainMinFee; type XcmExecutor = XcmExecutor; - type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; - type BaseXcmWeight = ConstU64<100_000_000>; + type Weigher = FixedWeightBounds; + type BaseXcmWeight = BaseXcmWeight; type UniversalLocation = UniversalLocation; type MaxAssetsForTransfer = MaxAssetsForTransfer; type ReserveProvider = AbsoluteReserveProvider; diff --git a/xtokens/src/mock/para_relative_view.rs b/xtokens/src/mock/para_relative_view.rs index 42386c916..fb2bf6ba3 100644 --- a/xtokens/src/mock/para_relative_view.rs +++ b/xtokens/src/mock/para_relative_view.rs @@ -11,7 +11,7 @@ use sp_core::H256; use sp_runtime::{ testing::Header, traits::{Convert, IdentityLookup}, - AccountId32, + AccountId32, BoundedVec, }; use cumulus_primitives_core::{ChannelStatus, GetChannelInfo, ParaId}; @@ -94,8 +94,8 @@ impl orml_tokens::Config for Runtime { } parameter_types! { - pub const ReservedXcmpWeight: Weight = WEIGHT_REF_TIME_PER_SECOND / 4; - pub const ReservedDmpWeight: Weight = WEIGHT_REF_TIME_PER_SECOND / 4; + pub const ReservedXcmpWeight: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4)); + pub const ReservedDmpWeight: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4)); } impl parachain_info::Config for Runtime {} @@ -104,7 +104,8 @@ parameter_types! { pub const RelayLocation: MultiLocation = MultiLocation::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); - pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + pub UniversalLocation: InteriorMultiLocation = + X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())); } pub type LocationToAccountId = ( @@ -135,6 +136,13 @@ pub type LocalAssetTransactor = MultiCurrencyAdapter< pub type XcmRouter = ParachainXcmRouter; pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom); +parameter_types! { + pub const UnitWeightCost: Weight = Weight::from_parts(10, 10); + pub const BaseXcmWeight: Weight = Weight::from_parts(100_000_000, 100_000_000); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + pub struct XcmConfig; impl Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -145,12 +153,21 @@ impl Config for XcmConfig { type IsTeleporter = (); type UniversalLocation = UniversalLocation; type Barrier = Barrier; - type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; + type Weigher = FixedWeightBounds; type Trader = AllTokensAreCreatedEqualToWeight; type ResponseHandler = (); type AssetTrap = PolkadotXcm; type AssetClaims = PolkadotXcm; type SubscriptionService = PolkadotXcm; + type AssetLocker = PolkadotXcm; + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; } pub struct ChannelInfo; @@ -172,6 +189,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = EnsureRoot; type ControllerOriginConverter = XcmOriginToCallOrigin; type WeightInfo = (); + type PriceForSiblingDelivery = (); } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -196,12 +214,18 @@ impl pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; type XcmTeleportFilter = Nothing; type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; + type Weigher = FixedWeightBounds; type UniversalLocation = UniversalLocation; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; } pub struct AccountIdToMultiLocation; @@ -220,25 +244,74 @@ impl Convert> for RelativeCurrencyIdConvert { fn convert(id: CurrencyId) -> Option { match id { CurrencyId::R => Some(Parent.into()), - CurrencyId::A => Some((Parent, Parachain(1), GeneralKey(b"A".to_vec().try_into().unwrap())).into()), - CurrencyId::A1 => Some((Parent, Parachain(1), GeneralKey(b"A1".to_vec().try_into().unwrap())).into()), - CurrencyId::B => Some((Parent, Parachain(2), GeneralKey(b"B".to_vec().try_into().unwrap())).into()), - CurrencyId::B1 => Some((Parent, Parachain(2), GeneralKey(b"B1".to_vec().try_into().unwrap())).into()), - CurrencyId::B2 => Some((Parent, Parachain(2), GeneralKey(b"B2".to_vec().try_into().unwrap())).into()), - CurrencyId::C => Some((Parent, Parachain(3), GeneralKey(b"C".to_vec().try_into().unwrap())).into()), - CurrencyId::D => Some(GeneralKey(b"D".to_vec().try_into().unwrap()).into()), + CurrencyId::A => Some( + ( + Parent, + Parachain(1), + Junction::from(BoundedVec::try_from(b"A".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::A1 => Some( + ( + Parent, + Parachain(1), + Junction::from(BoundedVec::try_from(b"A1".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::B => Some( + ( + Parent, + Parachain(2), + Junction::from(BoundedVec::try_from(b"B".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::B1 => Some( + ( + Parent, + Parachain(2), + Junction::from(BoundedVec::try_from(b"B1".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::B2 => Some( + ( + Parent, + Parachain(2), + Junction::from(BoundedVec::try_from(b"B2".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::C => Some( + ( + Parent, + Parachain(3), + Junction::from(BoundedVec::try_from(b"C".to_vec()).unwrap()), + ) + .into(), + ), + CurrencyId::D => Some(Junction::from(BoundedVec::try_from(b"D".to_vec()).unwrap()).into()), } } } impl Convert> for RelativeCurrencyIdConvert { fn convert(l: MultiLocation) -> Option { - let a: Vec = "A".into(); - let a1: Vec = "A1".into(); - let b: Vec = "B".into(); - let b1: Vec = "B1".into(); - let b2: Vec = "B2".into(); - let c: Vec = "C".into(); - let d: Vec = "D".into(); + let mut a: Vec = "A".into(); + a.resize(32, 0); + let mut a1: Vec = "A1".into(); + a1.resize(32, 0); + let mut b: Vec = "B".into(); + b.resize(32, 0); + let mut b1: Vec = "B1".into(); + b1.resize(32, 0); + let mut b2: Vec = "B2".into(); + b2.resize(32, 0); + let mut c: Vec = "C".into(); + c.resize(32, 0); + let mut d: Vec = "D".into(); + d.resize(32, 0); let self_para_id: u32 = ParachainInfo::parachain_id().into(); if l == MultiLocation::parent() { @@ -246,23 +319,25 @@ impl Convert> for RelativeCurrencyIdConvert { } match l { MultiLocation { parents, interior } if parents == 1 => match interior { - X2(Parachain(1), GeneralKey(k)) if k == a => Some(CurrencyId::A), - X2(Parachain(1), GeneralKey(k)) if k == a1 => Some(CurrencyId::A1), - X2(Parachain(2), GeneralKey(k)) if k == b => Some(CurrencyId::B), - X2(Parachain(2), GeneralKey(k)) if k == b1 => Some(CurrencyId::B1), - X2(Parachain(2), GeneralKey(k)) if k == b2 => Some(CurrencyId::B2), - X2(Parachain(3), GeneralKey(k)) if k == c => Some(CurrencyId::C), - X2(Parachain(para_id), GeneralKey(k)) if k == d && para_id == self_para_id => Some(CurrencyId::D), + X2(Parachain(1), GeneralKey { data, .. }) if data.to_vec() == a => Some(CurrencyId::A), + X2(Parachain(1), GeneralKey { data, .. }) if data.to_vec() == a1 => Some(CurrencyId::A1), + X2(Parachain(2), GeneralKey { data, .. }) if data.to_vec() == b => Some(CurrencyId::B), + X2(Parachain(2), GeneralKey { data, .. }) if data.to_vec() == b1 => Some(CurrencyId::B1), + X2(Parachain(2), GeneralKey { data, .. }) if data.to_vec() == b2 => Some(CurrencyId::B2), + X2(Parachain(3), GeneralKey { data, .. }) if data.to_vec() == c => Some(CurrencyId::C), + X2(Parachain(para_id), GeneralKey { data, .. }) if data.to_vec() == d && para_id == self_para_id => { + Some(CurrencyId::D) + } _ => None, }, MultiLocation { parents, interior } if parents == 0 => match interior { - X1(GeneralKey(k)) if k == a => Some(CurrencyId::A), - X1(GeneralKey(k)) if k == b => Some(CurrencyId::B), - X1(GeneralKey(k)) if k == a1 => Some(CurrencyId::A1), - X1(GeneralKey(k)) if k == b1 => Some(CurrencyId::B1), - X1(GeneralKey(k)) if k == b2 => Some(CurrencyId::B2), - X1(GeneralKey(k)) if k == c => Some(CurrencyId::C), - X1(GeneralKey(k)) if k == d => Some(CurrencyId::D), + X1(GeneralKey { data, .. }) if data.to_vec() == a => Some(CurrencyId::A), + X1(GeneralKey { data, .. }) if data.to_vec() == b => Some(CurrencyId::B), + X1(GeneralKey { data, .. }) if data.to_vec() == a1 => Some(CurrencyId::A1), + X1(GeneralKey { data, .. }) if data.to_vec() == b1 => Some(CurrencyId::B1), + X1(GeneralKey { data, .. }) if data.to_vec() == b2 => Some(CurrencyId::B2), + X1(GeneralKey { data, .. }) if data.to_vec() == c => Some(CurrencyId::C), + X1(GeneralKey { data, .. }) if data.to_vec() == d => Some(CurrencyId::D), _ => None, }, _ => None, @@ -321,8 +396,8 @@ impl orml_xtokens::Config for Runtime { type MultiLocationsFilter = ParentOrParachains; type MinXcmFee = ParachainMinFee; type XcmExecutor = XcmExecutor; - type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; - type BaseXcmWeight = ConstU64<100_000_000>; + type Weigher = FixedWeightBounds; + type BaseXcmWeight = BaseXcmWeight; type UniversalLocation = UniversalLocation; type MaxAssetsForTransfer = MaxAssetsForTransfer; type ReserveProvider = RelativeReserveProvider; diff --git a/xtokens/src/mock/para_teleport.rs b/xtokens/src/mock/para_teleport.rs index 92b5040e6..6bb30edca 100644 --- a/xtokens/src/mock/para_teleport.rs +++ b/xtokens/src/mock/para_teleport.rs @@ -92,8 +92,8 @@ impl orml_tokens::Config for Runtime { } parameter_types! { - pub const ReservedXcmpWeight: Weight = WEIGHT_REF_TIME_PER_SECOND / 4; - pub const ReservedDmpWeight: Weight = WEIGHT_REF_TIME_PER_SECOND / 4; + pub const ReservedXcmpWeight: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4)); + pub const ReservedDmpWeight: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4)); } impl parachain_info::Config for Runtime {} @@ -102,7 +102,8 @@ parameter_types! { pub const RelayLocation: MultiLocation = MultiLocation::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); - pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + pub UniversalLocation: InteriorMultiLocation = + X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())); } pub type LocationToAccountId = ( @@ -133,6 +134,13 @@ pub type LocalAssetTransactor = MultiTeleportCurrencyAdapter< pub type XcmRouter = ParachainXcmRouter; pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom); +parameter_types! { + pub const UnitWeightCost: Weight = Weight::from_parts(10, 10); + pub const BaseXcmWeight: Weight = Weight::from_parts(100_000_000, 100_000_000); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + pub struct XcmConfig; impl Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -143,12 +151,21 @@ impl Config for XcmConfig { type IsTeleporter = NativeAsset; type UniversalLocation = UniversalLocation; type Barrier = Barrier; - type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; + type Weigher = FixedWeightBounds; type Trader = AllTokensAreCreatedEqualToWeight; type ResponseHandler = (); type AssetTrap = PolkadotXcm; type AssetClaims = PolkadotXcm; type SubscriptionService = PolkadotXcm; + type AssetLocker = PolkadotXcm; + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; } pub struct ChannelInfo; @@ -170,6 +187,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = EnsureRoot; type ControllerOriginConverter = XcmOriginToCallOrigin; type WeightInfo = (); + type PriceForSiblingDelivery = (); } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -194,12 +212,18 @@ impl pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; type XcmTeleportFilter = Nothing; type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; + type Weigher = FixedWeightBounds; type UniversalLocation = UniversalLocation; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; } pub struct AccountIdToMultiLocation; @@ -240,8 +264,8 @@ impl orml_xtokens::Config for Runtime { type MultiLocationsFilter = ParentOrParachains; type MinXcmFee = DisabledParachainFee; type XcmExecutor = XcmExecutor; - type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; - type BaseXcmWeight = ConstU64<100_000_000>; + type Weigher = FixedWeightBounds; + type BaseXcmWeight = BaseXcmWeight; type UniversalLocation = UniversalLocation; type MaxAssetsForTransfer = MaxAssetsForTransfer; type ReserveProvider = AbsoluteReserveProvider; diff --git a/xtokens/src/mock/relay.rs b/xtokens/src/mock/relay.rs index e8bb3b8ca..54c929e1d 100644 --- a/xtokens/src/mock/relay.rs +++ b/xtokens/src/mock/relay.rs @@ -1,12 +1,13 @@ use frame_support::{ construct_runtime, parameter_types, - traits::{ConstU128, ConstU32, ConstU64, Everything}, + traits::{ConstU128, ConstU32, ConstU64, Everything, Nothing}, weights::IdentityFee, }; use frame_system::EnsureRoot; use sp_core::H256; use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; +use crate::Weight; use cumulus_primitives_core::ParaId; use polkadot_runtime_parachains::{configuration, origin, shared, ump}; use xcm::latest::prelude::*; @@ -66,9 +67,9 @@ impl configuration::Config for Runtime { } parameter_types! { - pub const KsmLocation: MultiLocation = Here.into(); + pub KsmLocation: MultiLocation = Here.into(); pub const KusamaNetwork: NetworkId = NetworkId::Kusama; - pub UniversalLocation: InteriorMultiLocation = Here; + pub UniversalLocation: InteriorMultiLocation = X1(GlobalConsensus(KusamaNetwork::get())); } pub type SovereignAccountOf = ( @@ -89,13 +90,20 @@ pub type XcmRouter = super::RelayChainXcmRouter; pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom); parameter_types! { - pub const Kusama: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(KsmLocation::get()) }); - pub const Statemine: MultiLocation = Parachain(3).into(); - pub const KusamaForStatemine: (MultiAssetFilter, MultiLocation) = (Kusama::get(), Statemine::get()); + pub Kusama: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(KsmLocation::get()) }); + pub Statemine: MultiLocation = Parachain(3).into(); + pub KusamaForStatemine: (MultiAssetFilter, MultiLocation) = (Kusama::get(), Statemine::get()); } pub type TrustedTeleporters = xcm_builder::Case; +parameter_types! { + pub const UnitWeightCost: Weight = Weight::from_parts(10, 10); + pub const BaseXcmWeight: Weight = Weight::from_parts(100_000_000, 100_000_000); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + pub struct XcmConfig; impl Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -106,12 +114,21 @@ impl Config for XcmConfig { type IsTeleporter = TrustedTeleporters; type UniversalLocation = UniversalLocation; type Barrier = Barrier; - type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; + type Weigher = FixedWeightBounds; type Trader = UsingComponents, KsmLocation, AccountId, Balances, ()>; type ResponseHandler = (); type AssetTrap = (); type AssetClaims = (); type SubscriptionService = XcmPallet; + type AssetLocker = XcmPallet; + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; } pub type LocalOriginToLocation = SignedToAccountId32; @@ -126,12 +143,18 @@ impl pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; type XcmTeleportFilter = Everything; type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds, RuntimeCall, ConstU32<100>>; + type Weigher = FixedWeightBounds; type UniversalLocation = UniversalLocation; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; } impl ump::Config for Runtime { diff --git a/xtokens/src/mock/teleport_currency_adapter.rs b/xtokens/src/mock/teleport_currency_adapter.rs index 2056b07cc..9ca6be636 100644 --- a/xtokens/src/mock/teleport_currency_adapter.rs +++ b/xtokens/src/mock/teleport_currency_adapter.rs @@ -9,7 +9,7 @@ use sp_std::{ }; use orml_xcm_support::{OnDepositFail, UnknownAsset as UnknownAssetT}; -use xcm::latest::{Error as XcmError, MultiAsset, MultiLocation, Result}; +use xcm::latest::{prelude::*, Error as XcmError, MultiAsset, MultiLocation, Result}; use xcm_executor::{ traits::{Convert as MoreConvert, MatchesFungible, TransactAsset}, Assets, @@ -87,13 +87,13 @@ impl< DepositFailureHandler, > { - fn can_check_in(_origin: &MultiLocation, _what: &MultiAsset) -> Result { + fn can_check_in(_origin: &MultiLocation, _what: &MultiAsset, _context: &XcmContext) -> Result { Ok(()) } - fn check_in(_origin: &MultiLocation, _what: &MultiAsset) {} + fn check_in(_origin: &MultiLocation, _what: &MultiAsset, _context: &XcmContext) {} - fn deposit_asset(asset: &MultiAsset, location: &MultiLocation) -> Result { + fn deposit_asset(asset: &MultiAsset, location: &MultiLocation, _context: &XcmContext) -> Result { match ( AccountIdConvert::convert_ref(location), CurrencyIdConvert::convert(asset.clone()), @@ -108,7 +108,11 @@ impl< } } - fn withdraw_asset(asset: &MultiAsset, location: &MultiLocation) -> result::Result { + fn withdraw_asset( + asset: &MultiAsset, + location: &MultiLocation, + _maybe_context: Option<&XcmContext>, + ) -> result::Result { UnknownAsset::withdraw(asset, location).or_else(|_| { let who = AccountIdConvert::convert_ref(location) .map_err(|_| XcmError::from(Error::AccountIdConversionFailed))?; diff --git a/xtokens/src/tests.rs b/xtokens/src/tests.rs index af434df15..7e494ec0a 100644 --- a/xtokens/src/tests.rs +++ b/xtokens/src/tests.rs @@ -662,7 +662,9 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_works() { }); let fee_amount: u128 = 200; - let weight: u128 = 50; + // TODO: set the weight limit to 40 until this issue is addressed: + // https://github.com/paritytech/polkadot/issues/6770 + let weight: u128 = 40; let dest_weight: u128 = 40; ParaA::execute_with(|| { @@ -681,7 +683,7 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_works() { ) .into() ), - WeightLimit::Limited(weight as u64), + WeightLimit::Limited((weight as u64).into()), )); assert_eq!(550, ParaTokens::free_balance(CurrencyId::C, &ALICE)); assert_eq!(1000 - fee_amount, ParaTokens::free_balance(CurrencyId::R, &ALICE)); @@ -722,7 +724,9 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_works_with_relative_s }); let fee_amount: u128 = 200; - let weight: u128 = 50; + // TODO: set the weight limit to 40 until this issue is addressed: + // https://github.com/paritytech/polkadot/issues/6770 + let weight: u128 = 40; let dest_weight: u128 = 40; ParaD::execute_with(|| { @@ -741,7 +745,7 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_works_with_relative_s ) .into() ), - WeightLimit::Limited(weight as u64), + WeightLimit::Limited((weight as u64).into()), )); assert_eq!(550, ParaRelativeTokens::free_balance(CurrencyId::C, &ALICE)); assert_eq!( @@ -785,7 +789,9 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_not_enough() { }); let fee_amount: u128 = 159; - let weight: u128 = 50; + // TODO: set the weight limit to 40 until this issue is addressed: + // https://github.com/paritytech/polkadot/issues/6770 + let weight: u128 = 40; let dest_weight: u128 = 40; ParaA::execute_with(|| { @@ -804,7 +810,7 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_not_enough() { ) .into() ), - WeightLimit::Limited(weight as u64), + WeightLimit::Limited((weight as u64).into()), )); assert_eq!(550, ParaTokens::free_balance(CurrencyId::C, &ALICE)); assert_eq!(1000 - fee_amount, ParaTokens::free_balance(CurrencyId::R, &ALICE)); @@ -935,10 +941,11 @@ fn transfer_no_reserve_assets_fails() { TestNet::reset(); ParaA::execute_with(|| { + let asset_id: AssetId = X1(Junction::from(BoundedVec::try_from(b"B".to_vec()).unwrap())).into(); assert_noop!( ParaXTokens::transfer_multiasset( Some(ALICE).into(), - Box::new((X1(GeneralKey(b"B".to_vec().try_into().unwrap())).into(), 100).into()), + Box::new((asset_id, 100).into()), Box::new( ( Parent, @@ -1026,7 +1033,7 @@ fn send_as_sovereign() { let call = relay::RuntimeCall::System(frame_system::Call::::remark_with_event { remark: vec![1, 1, 1], }); - let assets: MultiAsset = (Here, 1_000_000_000_000).into(); + let assets: MultiAsset = (Here, 1_000_000_000_000u128).into(); assert_ok!(para::OrmlXcm::send_as_sovereign( para::RuntimeOrigin::root(), Box::new(Parent.into()), @@ -1034,11 +1041,11 @@ fn send_as_sovereign() { WithdrawAsset(assets.clone().into()), BuyExecution { fees: assets, - weight_limit: Limited(2_000_000_000) + weight_limit: Limited(2_000_000_000.into()) }, Instruction::Transact { - origin_type: SovereignAccount, - require_weight_at_most: 1_000_000_000, + origin_kind: SovereignAccount, + require_weight_at_most: 1_000_000_000.into(), call: call.encode().into(), } ]))) @@ -1069,7 +1076,7 @@ fn send_as_sovereign_fails_if_bad_origin() { let call = relay::RuntimeCall::System(frame_system::Call::::remark_with_event { remark: vec![1, 1, 1], }); - let assets: MultiAsset = (Here, 1_000_000_000_000).into(); + let assets: MultiAsset = (Here, 1_000_000_000_000u128).into(); assert_err!( para::OrmlXcm::send_as_sovereign( para::RuntimeOrigin::signed(ALICE), @@ -1078,11 +1085,11 @@ fn send_as_sovereign_fails_if_bad_origin() { WithdrawAsset(assets.clone().into()), BuyExecution { fees: assets, - weight_limit: Limited(10_000_000) + weight_limit: Limited(10_000_000.into()) }, Instruction::Transact { - origin_type: SovereignAccount, - require_weight_at_most: 1_000_000_000, + origin_kind: SovereignAccount, + require_weight_at_most: 1_000_000_000.into(), call: call.encode().into(), } ]))) @@ -1675,7 +1682,7 @@ fn send_with_sufficient_weight_limit() { ) .into() ), - WeightLimit::Limited(40), + WeightLimit::Limited(40.into()), )); assert_eq!(ParaTokens::free_balance(CurrencyId::A, &ALICE), 500); @@ -1711,7 +1718,7 @@ fn send_with_insufficient_weight_limit() { ) .into() ), - WeightLimit::Limited(1), + WeightLimit::Limited(1.into()), )); assert_eq!(ParaTokens::free_balance(CurrencyId::A, &ALICE), 500); From 4b581ed2b4a7648cb89265d83eebf495d1675c3d Mon Sep 17 00:00:00 2001 From: tgmichel Date: Fri, 24 Feb 2023 09:35:58 +0100 Subject: [PATCH 11/23] Update `Cargo.dev.toml` pin --- Cargo.dev.toml | 128 ++++++++++++++++++++++++------------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/Cargo.dev.toml b/Cargo.dev.toml index bdcd37adf..ebf65b44e 100644 --- a/Cargo.dev.toml +++ b/Cargo.dev.toml @@ -37,71 +37,71 @@ resolver = "2" split-debuginfo = "unpacked" [patch.'https://github.com/paritytech/substrate'] -frame-benchmarking = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -frame-support = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -frame-system = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -pallet-authority-discovery = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -pallet-authorship = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -pallet-babe = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -pallet-balances = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -pallet-elections-phragmen = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -pallet-scheduler = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -pallet-session = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -pallet-staking = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -pallet-timestamp = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -pallet-treasury = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -pallet-vesting = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -pallet-transaction-payment = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sc-client-api = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sc-client-db = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sc-executor = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sc-executor-common = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sc-executor-wasmi = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sc-utils = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-api = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-application-crypto = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-arithmetic = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-authority-discovery = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-authorship = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-blockchain = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-consensus = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-consensus-slots = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-core = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-debug-derive = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-externalities = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-inherents = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-io = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-keystore = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-npos-elections = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-panic-handler = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-runtime = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-runtime-interface = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-session = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-staking = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-state-machine = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-std = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-storage = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-timestamp = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-trie = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-version = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-wasm-interface = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-tracing = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } -sp-maybe-compressed-blob = { git = "https://github.com/paritytech//substrate", rev = "946507ba9ef13e263534176b7b74e26fc56efbd4" } +frame-benchmarking = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +frame-support = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +frame-system = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +pallet-authority-discovery = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +pallet-authorship = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +pallet-babe = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +pallet-balances = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +pallet-elections-phragmen = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +pallet-scheduler = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +pallet-session = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +pallet-staking = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +pallet-timestamp = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +pallet-treasury = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +pallet-vesting = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +pallet-transaction-payment = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sc-client-api = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sc-client-db = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sc-executor = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sc-executor-common = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sc-executor-wasmi = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sc-utils = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-api = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-application-crypto = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-arithmetic = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-authority-discovery = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-authorship = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-blockchain = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-consensus = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-consensus-slots = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-core = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-debug-derive = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-externalities = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-inherents = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-io = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-keystore = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-npos-elections = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-panic-handler = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-runtime = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-runtime-interface = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-session = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-staking = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-state-machine = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-std = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-storage = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-timestamp = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-trie = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-version = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-wasm-interface = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-tracing = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-maybe-compressed-blob = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } [patch.'https://github.com/paritytech/cumulus'] -cumulus-primitives-core = { git = "https://github.com/paritytech//cumulus", rev = "09418fc04c2608b123f36ca80f16df3d2096753b" } -cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech//cumulus", rev = "09418fc04c2608b123f36ca80f16df3d2096753b" } -cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech//cumulus", rev = "09418fc04c2608b123f36ca80f16df3d2096753b" } -cumulus-pallet-xcm = { git = "https://github.com/paritytech//cumulus", rev = "09418fc04c2608b123f36ca80f16df3d2096753b" } -parachain-info = { git = "https://github.com/paritytech//cumulus", rev = "09418fc04c2608b123f36ca80f16df3d2096753b" } +cumulus-primitives-core = { git = "https://github.com/paritytech//cumulus", rev = "1b2003d48f753be96471c5f96c4a2307592db49f" } +cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech//cumulus", rev = "1b2003d48f753be96471c5f96c4a2307592db49f" } +cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech//cumulus", rev = "1b2003d48f753be96471c5f96c4a2307592db49f" } +cumulus-pallet-xcm = { git = "https://github.com/paritytech//cumulus", rev = "1b2003d48f753be96471c5f96c4a2307592db49f" } +parachain-info = { git = "https://github.com/paritytech//cumulus", rev = "1b2003d48f753be96471c5f96c4a2307592db49f" } [patch.'https://github.com/paritytech/polkadot'] -pallet-xcm = { git = "https://github.com/paritytech//polkadot", rev = "645723987cf9662244be8faf4e9b63e8b9a1b3a3" } -polkadot-core-primitives = { git = "https://github.com/paritytech//polkadot", rev = "645723987cf9662244be8faf4e9b63e8b9a1b3a3" } -polkadot-runtime-parachains = { git = "https://github.com/paritytech//polkadot", rev = "645723987cf9662244be8faf4e9b63e8b9a1b3a3" } -polkadot-parachain = { git = "https://github.com/paritytech//polkadot", rev = "645723987cf9662244be8faf4e9b63e8b9a1b3a3" } -polkadot-primitives = { git = "https://github.com/paritytech//polkadot", rev = "645723987cf9662244be8faf4e9b63e8b9a1b3a3" } -xcm = { git = "https://github.com/paritytech//polkadot", rev = "645723987cf9662244be8faf4e9b63e8b9a1b3a3" } -xcm-executor = { git = "https://github.com/paritytech//polkadot", rev = "645723987cf9662244be8faf4e9b63e8b9a1b3a3" } -xcm-builder = { git = "https://github.com/paritytech//polkadot", rev = "645723987cf9662244be8faf4e9b63e8b9a1b3a3" } -xcm-simulator = { git = "https://github.com/paritytech//polkadot", rev = "645723987cf9662244be8faf4e9b63e8b9a1b3a3" } +pallet-xcm = { git = "https://github.com/paritytech//polkadot", rev = "72309a2b2e68413305a56dce1097041309bd29c6" } +polkadot-core-primitives = { git = "https://github.com/paritytech//polkadot", rev = "72309a2b2e68413305a56dce1097041309bd29c6" } +polkadot-runtime-parachains = { git = "https://github.com/paritytech//polkadot", rev = "72309a2b2e68413305a56dce1097041309bd29c6" } +polkadot-parachain = { git = "https://github.com/paritytech//polkadot", rev = "72309a2b2e68413305a56dce1097041309bd29c6" } +polkadot-primitives = { git = "https://github.com/paritytech//polkadot", rev = "72309a2b2e68413305a56dce1097041309bd29c6" } +xcm = { git = "https://github.com/paritytech//polkadot", rev = "72309a2b2e68413305a56dce1097041309bd29c6" } +xcm-executor = { git = "https://github.com/paritytech//polkadot", rev = "72309a2b2e68413305a56dce1097041309bd29c6" } +xcm-builder = { git = "https://github.com/paritytech//polkadot", rev = "72309a2b2e68413305a56dce1097041309bd29c6" } +xcm-simulator = { git = "https://github.com/paritytech//polkadot", rev = "72309a2b2e68413305a56dce1097041309bd29c6" } From ac99514ffa13950f1b1d8901cb9800339e5cf4f7 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Fri, 24 Feb 2023 09:40:03 +0100 Subject: [PATCH 12/23] clippy --- asset-registry/src/impls.rs | 8 ++++---- traits/src/location.rs | 3 +-- unknown-tokens/src/lib.rs | 4 ++-- xcm-support/src/lib.rs | 4 ++-- xcm/src/lib.rs | 2 +- xtokens/src/lib.rs | 28 ++++++++++++++-------------- 6 files changed, 24 insertions(+), 25 deletions(-) diff --git a/asset-registry/src/impls.rs b/asset-registry/src/impls.rs index b2e10ff3e..c620784d9 100644 --- a/asset-registry/src/impls.rs +++ b/asset-registry/src/impls.rs @@ -112,7 +112,7 @@ impl WeightTrader for AssetRegistryTrad return Ok(payment); } - if let Ok(unused) = payment.clone().checked_sub((asset.clone(), fee_increase).into()) { + if let Ok(unused) = payment.clone().checked_sub((*asset, fee_increase).into()) { let (existing_weight, existing_fee) = match self.bought_weight { Some(ref x) => (x.weight, x.amount), None => (Weight::zero(), 0), @@ -121,7 +121,7 @@ impl WeightTrader for AssetRegistryTrad self.bought_weight = Some(BoughtWeight { amount: existing_fee.checked_add(fee_increase).ok_or(XcmError::Overflow)?, weight: existing_weight.checked_add(&weight).ok_or(XcmError::Overflow)?, - asset_location: location.clone(), + asset_location: *location, }); return Ok(unused); } @@ -143,7 +143,7 @@ impl WeightTrader for AssetRegistryTrad bought.weight = new_weight; bought.amount = new_amount; - Some((AssetId::Concrete(bought.asset_location.clone()), refunded_amount).into()) + Some((AssetId::Concrete(bought.asset_location), refunded_amount).into()) } None => None, // nothing to refund } @@ -153,7 +153,7 @@ impl WeightTrader for AssetRegistryTrad impl Drop for AssetRegistryTrader { fn drop(&mut self) { if let Some(ref bought) = self.bought_weight { - R::take_revenue((AssetId::Concrete(bought.asset_location.clone()), bought.amount).into()); + R::take_revenue((AssetId::Concrete(bought.asset_location), bought.amount).into()); } } } diff --git a/traits/src/location.rs b/traits/src/location.rs index fcbaeb4ba..2604b9bf2 100644 --- a/traits/src/location.rs +++ b/traits/src/location.rs @@ -1,5 +1,4 @@ use sp_core::{bounded::BoundedVec, ConstU32}; -use sp_std::prelude::*; use xcm::latest::prelude::*; pub trait Parse { @@ -28,7 +27,7 @@ impl Parse for MultiLocation { } fn non_chain_part(&self) -> Option { - let mut junctions = self.interior().clone(); + let mut junctions = *self.interior(); while is_chain_junction(junctions.first()) { let _ = junctions.take_first(); } diff --git a/unknown-tokens/src/lib.rs b/unknown-tokens/src/lib.rs index f0b566161..acbf8c373 100644 --- a/unknown-tokens/src/lib.rs +++ b/unknown-tokens/src/lib.rs @@ -92,7 +92,7 @@ impl UnknownAsset for Pallet { Self::deposit_event(Event::Deposited { asset: asset.clone(), - who: to.clone(), + who: *to, }); Ok(()) @@ -119,7 +119,7 @@ impl UnknownAsset for Pallet { Self::deposit_event(Event::Withdrawn { asset: asset.clone(), - who: from.clone(), + who: *from, }); Ok(()) diff --git a/xcm-support/src/lib.rs b/xcm-support/src/lib.rs index e5f1d0fbd..bbbe89826 100644 --- a/xcm-support/src/lib.rs +++ b/xcm-support/src/lib.rs @@ -14,7 +14,7 @@ use frame_support::{ traits::ContainsPair, }; use sp_runtime::traits::{CheckedConversion, Convert}; -use sp_std::{marker::PhantomData, prelude::*}; +use sp_std::marker::PhantomData; use xcm::latest::prelude::*; use xcm_executor::traits::MatchesFungible; @@ -37,7 +37,7 @@ where { fn matches_fungible(a: &MultiAsset) -> Option { if let (Fungible(ref amount), Concrete(ref location)) = (&a.fun, &a.id) { - if CurrencyIdConvert::convert(location.clone()).is_some() { + if CurrencyIdConvert::convert(*location).is_some() { return CheckedConversion::checked_from(*amount); } } diff --git a/xcm/src/lib.rs b/xcm/src/lib.rs index 6e94e6d79..29916f0c1 100644 --- a/xcm/src/lib.rs +++ b/xcm/src/lib.rs @@ -61,7 +61,7 @@ pub mod module { let dest = MultiLocation::try_from(*dest).map_err(|()| Error::::BadVersion)?; let message: Xcm<()> = (*message).try_into().map_err(|()| Error::::BadVersion)?; - pallet_xcm::Pallet::::send_xcm(Here, dest.clone(), message.clone()).map_err(|e| match e { + pallet_xcm::Pallet::::send_xcm(Here, dest, message.clone()).map_err(|e| match e { SendError::Unroutable => Error::::Unreachable, _ => Error::::SendFailure, })?; diff --git a/xtokens/src/lib.rs b/xtokens/src/lib.rs index a21146c49..95599a8f0 100644 --- a/xtokens/src/lib.rs +++ b/xtokens/src/lib.rs @@ -425,7 +425,7 @@ pub mod module { Error::::NotSupportedMultiLocation ); - let asset = (location.clone(), amount.into()).into(); + let asset = (location, amount.into()).into(); let fee_asset: MultiAsset = (location, fee.into()).into(); // Push contains saturated addition, so we should be able to use it safely @@ -548,11 +548,11 @@ pub mod module { // like `NonReserve` or `SelfReserve` with relay-chain fee is not support. ensure!(non_fee_reserve == dest.chain_part(), Error::::InvalidAsset); - let reserve_location = non_fee_reserve.clone().ok_or(Error::::AssetHasNoReserve)?; + let reserve_location = non_fee_reserve.ok_or(Error::::AssetHasNoReserve)?; let min_xcm_fee = T::MinXcmFee::get(&reserve_location).ok_or(Error::::MinXcmFeeNotDefined)?; // min xcm fee should less than user fee - let fee_to_dest: MultiAsset = (fee.id.clone(), min_xcm_fee).into(); + let fee_to_dest: MultiAsset = (fee.id, min_xcm_fee).into(); ensure!(fee_to_dest < fee, Error::::FeeNotEnough); let mut assets_to_dest = MultiAssets::new(); @@ -583,7 +583,7 @@ pub mod module { // teleport. But as current there's only one case which is Parachain send back // asset to Statemine/t, So we set `use_teleport` to always `true` in this case. Self::execute_and_send_reserve_kind_xcm( - origin_location.clone(), + origin_location, assets_to_fee_reserve, asset_to_fee_reserve, fee_reserve, @@ -679,7 +679,7 @@ pub mod module { ) -> Result, DispatchError> { Ok(Xcm(vec![TransferReserveAsset { assets: assets.clone(), - dest: dest.clone(), + dest, xcm: Xcm(vec![ Self::buy_execution(fee, &dest, dest_weight_limit)?, Self::deposit_asset(recipient, assets.len() as u32), @@ -698,7 +698,7 @@ pub mod module { WithdrawAsset(assets.clone()), InitiateReserveWithdraw { assets: All.into(), - reserve: reserve.clone(), + reserve, xcm: Xcm(vec![ Self::buy_execution(fee, &reserve, dest_weight_limit)?, Self::deposit_asset(recipient, assets.len() as u32), @@ -716,7 +716,7 @@ pub mod module { dest_weight_limit: WeightLimit, use_teleport: bool, ) -> Result, DispatchError> { - let mut reanchored_dest = dest.clone(); + let mut reanchored_dest = dest; if reserve == MultiLocation::parent() { match dest { MultiLocation { @@ -732,10 +732,10 @@ pub mod module { let max_assets = assets.len() as u32; if !use_teleport { Ok(Xcm(vec![ - WithdrawAsset(assets.clone()), + WithdrawAsset(assets), InitiateReserveWithdraw { assets: All.into(), - reserve: reserve.clone(), + reserve, xcm: Xcm(vec![ Self::buy_execution(half(&fee), &reserve, dest_weight_limit.clone())?, DepositReserveAsset { @@ -751,10 +751,10 @@ pub mod module { ])) } else { Ok(Xcm(vec![ - WithdrawAsset(assets.clone()), + WithdrawAsset(assets), InitiateReserveWithdraw { assets: All.into(), - reserve: reserve.clone(), + reserve, xcm: Xcm(vec![ Self::buy_execution(half(&fee), &reserve, dest_weight_limit.clone())?, InitiateTeleport { @@ -878,7 +878,7 @@ pub mod module { let mut assets: Vec = Vec::new(); for (currency_id, amount) in currencies { if let Some(location) = T::CurrencyIdConvert::convert(currency_id.clone()) { - let asset: MultiAsset = (location.clone(), (*amount).into()).into(); + let asset: MultiAsset = (location, (*amount).into()).into(); assets.push(asset); } else { return Weight::zero(); @@ -986,7 +986,7 @@ fn half(asset: &MultiAsset) -> MultiAsset { .expect("div 2 can't overflow; qed"); MultiAsset { fun: Fungible(half_amount), - id: asset.id.clone(), + id: asset.id, } } @@ -994,6 +994,6 @@ fn subtract_fee(asset: &MultiAsset, amount: u128) -> MultiAsset { let final_amount = fungible_amount(asset).checked_sub(amount).expect("fee too low; qed"); MultiAsset { fun: Fungible(final_amount), - id: asset.id.clone(), + id: asset.id, } } From 908f2ebf51a0946f077a27b7ae954eb473eb1abe Mon Sep 17 00:00:00 2001 From: tgmichel Date: Fri, 24 Feb 2023 10:29:05 +0100 Subject: [PATCH 13/23] Specific version instead `latest` --- asset-registry/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asset-registry/src/lib.rs b/asset-registry/src/lib.rs index fa578718a..dc2ec3669 100644 --- a/asset-registry/src/lib.rs +++ b/asset-registry/src/lib.rs @@ -14,7 +14,7 @@ use sp_runtime::{ DispatchResult, }; use sp_std::prelude::*; -use xcm::{latest::prelude::*, VersionedMultiLocation}; +use xcm::{v3::prelude::*, VersionedMultiLocation}; pub use impls::*; pub use module::*; From b142f569c3d65827859afeb70f5f37eee9c2a68d Mon Sep 17 00:00:00 2001 From: tgmichel Date: Fri, 24 Feb 2023 10:29:38 +0100 Subject: [PATCH 14/23] Add test `MultiLocation` encoding --- asset-registry/src/tests.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/asset-registry/src/tests.rs b/asset-registry/src/tests.rs index f331cf4c9..562987b59 100644 --- a/asset-registry/src/tests.rs +++ b/asset-registry/src/tests.rs @@ -14,6 +14,10 @@ use sp_runtime::{ }; use xcm_simulator::TestExt; +type OldMultiLocation = xcm::v2::MultiLocation; +type OldJunctions = xcm::v2::Junctions; +type OldJunction = xcm::v2::Junction; + fn treasury_account() -> AccountId32 { TreasuryAccount::get() } @@ -568,3 +572,15 @@ fn test_asset_authority() { )); }); } + +#[test] +fn test_v2_to_v3_incompatible_multilocation() { + // Assert that V2 and V3 Multilocation both are encoded differently + assert!( + OldMultiLocation::new( + 0, + OldJunctions::X1(OldJunction::GeneralKey(vec![0].try_into().unwrap())) + ) + .encode() != MultiLocation::new(0, X1(Junction::from(BoundedVec::try_from(vec![0]).unwrap()))).encode() + ); +} From 17632bc3a6bb189ca52440655d9860bee88d17ed Mon Sep 17 00:00:00 2001 From: tgmichel Date: Fri, 24 Feb 2023 12:18:08 +0100 Subject: [PATCH 15/23] Remove `sp-authorship` --- Cargo.dev.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.dev.toml b/Cargo.dev.toml index ebf65b44e..59595d824 100644 --- a/Cargo.dev.toml +++ b/Cargo.dev.toml @@ -62,7 +62,6 @@ sp-api = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b sp-application-crypto = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } sp-arithmetic = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } sp-authority-discovery = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } -sp-authorship = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } sp-blockchain = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } sp-consensus = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } sp-consensus-slots = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } From 668a3759a9ec4472918f587f9f6782a30731a4f4 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Mon, 27 Feb 2023 08:59:57 +0100 Subject: [PATCH 16/23] Update `sp-weights` pin --- Cargo.dev.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.dev.toml b/Cargo.dev.toml index 59595d824..fd44629fe 100644 --- a/Cargo.dev.toml +++ b/Cargo.dev.toml @@ -86,6 +86,7 @@ sp-version = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c sp-wasm-interface = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } sp-tracing = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } sp-maybe-compressed-blob = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } +sp-weights = { git = "https://github.com/paritytech//substrate", rev = "18bb7c7c841b101c19a8d1881b893ae8e37de460" } [patch.'https://github.com/paritytech/cumulus'] cumulus-primitives-core = { git = "https://github.com/paritytech//cumulus", rev = "1b2003d48f753be96471c5f96c4a2307592db49f" } From dd6cb579dade4a115daa02106a92178d69542f6f Mon Sep 17 00:00:00 2001 From: tgmichel Date: Mon, 27 Feb 2023 10:20:34 +0100 Subject: [PATCH 17/23] Fix runtime-benchmarks --- asset-registry/src/mock/para.rs | 9 ++++++++- asset-registry/src/mock/relay.rs | 7 +++++++ authority/src/lib.rs | 2 +- vesting/src/mock.rs | 4 ++-- xtokens/src/mock/para.rs | 7 +++++++ xtokens/src/mock/para_relative_view.rs | 7 +++++++ xtokens/src/mock/para_teleport.rs | 7 +++++++ xtokens/src/mock/relay.rs | 7 +++++++ 8 files changed, 46 insertions(+), 4 deletions(-) diff --git a/asset-registry/src/mock/para.rs b/asset-registry/src/mock/para.rs index 06f6109e6..c29fb8f18 100644 --- a/asset-registry/src/mock/para.rs +++ b/asset-registry/src/mock/para.rs @@ -127,7 +127,7 @@ impl EnsureOriginWithArg> for AssetAuthority { } #[cfg(feature = "runtime-benchmarks")] - fn successful_origin(_asset_id: &Option) -> RuntimeOrigin { + fn try_successful_origin(_asset_id: &Option) -> Result { unimplemented!() } } @@ -289,6 +289,11 @@ parameter_types! { pub const MaxAssetsForTransfer: usize = 3; } +#[cfg(feature = "runtime-benchmarks")] +parameter_types! { + pub ReachableDest: Option = Some(Parent.into()); +} + impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SendXcmOrigin = EnsureXcmOrigin; @@ -310,6 +315,8 @@ impl pallet_xcm::Config for Runtime { type SovereignAccountOf = (); type MaxLockers = ConstU32<8>; type WeightInfo = pallet_xcm::TestWeightInfo; + #[cfg(feature = "runtime-benchmarks")] + type ReachableDest = ReachableDest; } pub struct AccountIdToMultiLocation; diff --git a/asset-registry/src/mock/relay.rs b/asset-registry/src/mock/relay.rs index bcd54bc97..35e581f62 100644 --- a/asset-registry/src/mock/relay.rs +++ b/asset-registry/src/mock/relay.rs @@ -127,6 +127,11 @@ parameter_types! { pub SelfLocation: MultiLocation = MultiLocation::here(); } +#[cfg(feature = "runtime-benchmarks")] +parameter_types! { + pub ReachableDest: Option = Some(MultiLocation::here()); +} + impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; @@ -149,6 +154,8 @@ impl pallet_xcm::Config for Runtime { type SovereignAccountOf = (); type MaxLockers = ConstU32<8>; type WeightInfo = pallet_xcm::TestWeightInfo; + #[cfg(feature = "runtime-benchmarks")] + type ReachableDest = ReachableDest; } impl ump::Config for Runtime { diff --git a/authority/src/lib.rs b/authority/src/lib.rs index 506f96578..ae9863c3a 100644 --- a/authority/src/lib.rs +++ b/authority/src/lib.rs @@ -146,7 +146,7 @@ impl< } #[cfg(feature = "runtime-benchmarks")] - fn successful_origin() -> O { + fn try_successful_origin() -> Result { unimplemented!() } } diff --git a/vesting/src/mock.rs b/vesting/src/mock.rs index 9a2a871fa..afbed77f6 100644 --- a/vesting/src/mock.rs +++ b/vesting/src/mock.rs @@ -68,10 +68,10 @@ impl EnsureOrigin for EnsureAliceOrBob { } #[cfg(feature = "runtime-benchmarks")] - fn successful_origin() -> RuntimeOrigin { + fn try_successful_origin() -> Result { let zero_account_id = AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()) .expect("infinite length input; no invalid inputs for type; qed"); - RuntimeOrigin::from(RawOrigin::Signed(zero_account_id)) + Ok(RuntimeOrigin::from(RawOrigin::Signed(zero_account_id))) } } diff --git a/xtokens/src/mock/para.rs b/xtokens/src/mock/para.rs index af2ba9398..e779bdbfa 100644 --- a/xtokens/src/mock/para.rs +++ b/xtokens/src/mock/para.rs @@ -202,6 +202,11 @@ impl cumulus_pallet_xcm::Config for Runtime { pub type LocalOriginToLocation = SignedToAccountId32; +#[cfg(feature = "runtime-benchmarks")] +parameter_types! { + pub ReachableDest: Option = Some(Parent.into()); +} + impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SendXcmOrigin = EnsureXcmOrigin; @@ -223,6 +228,8 @@ impl pallet_xcm::Config for Runtime { type SovereignAccountOf = (); type MaxLockers = ConstU32<8>; type WeightInfo = pallet_xcm::TestWeightInfo; + #[cfg(feature = "runtime-benchmarks")] + type ReachableDest = ReachableDest; } pub struct AccountIdToMultiLocation; diff --git a/xtokens/src/mock/para_relative_view.rs b/xtokens/src/mock/para_relative_view.rs index fb2bf6ba3..34d47c4b8 100644 --- a/xtokens/src/mock/para_relative_view.rs +++ b/xtokens/src/mock/para_relative_view.rs @@ -205,6 +205,11 @@ impl cumulus_pallet_xcm::Config for Runtime { pub type LocalOriginToLocation = SignedToAccountId32; +#[cfg(feature = "runtime-benchmarks")] +parameter_types! { + pub ReachableDest: Option = Some(Parent.into()); +} + impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SendXcmOrigin = EnsureXcmOrigin; @@ -226,6 +231,8 @@ impl pallet_xcm::Config for Runtime { type SovereignAccountOf = (); type MaxLockers = ConstU32<8>; type WeightInfo = pallet_xcm::TestWeightInfo; + #[cfg(feature = "runtime-benchmarks")] + type ReachableDest = ReachableDest; } pub struct AccountIdToMultiLocation; diff --git a/xtokens/src/mock/para_teleport.rs b/xtokens/src/mock/para_teleport.rs index 6bb30edca..dcfedb606 100644 --- a/xtokens/src/mock/para_teleport.rs +++ b/xtokens/src/mock/para_teleport.rs @@ -203,6 +203,11 @@ impl cumulus_pallet_xcm::Config for Runtime { pub type LocalOriginToLocation = SignedToAccountId32; +#[cfg(feature = "runtime-benchmarks")] +parameter_types! { + pub ReachableDest: Option = Some(Parent.into()); +} + impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SendXcmOrigin = EnsureXcmOrigin; @@ -224,6 +229,8 @@ impl pallet_xcm::Config for Runtime { type SovereignAccountOf = (); type MaxLockers = ConstU32<8>; type WeightInfo = pallet_xcm::TestWeightInfo; + #[cfg(feature = "runtime-benchmarks")] + type ReachableDest = ReachableDest; } pub struct AccountIdToMultiLocation; diff --git a/xtokens/src/mock/relay.rs b/xtokens/src/mock/relay.rs index 54c929e1d..d608b564e 100644 --- a/xtokens/src/mock/relay.rs +++ b/xtokens/src/mock/relay.rs @@ -133,6 +133,11 @@ impl Config for XcmConfig { pub type LocalOriginToLocation = SignedToAccountId32; +#[cfg(feature = "runtime-benchmarks")] +parameter_types! { + pub ReachableDest: Option = Some(Parent.into()); +} + impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; @@ -155,6 +160,8 @@ impl pallet_xcm::Config for Runtime { type SovereignAccountOf = (); type MaxLockers = ConstU32<8>; type WeightInfo = pallet_xcm::TestWeightInfo; + #[cfg(feature = "runtime-benchmarks")] + type ReachableDest = ReachableDest; } impl ump::Config for Runtime { From c5491acecf84051cbb078904ad82d5e294a6507f Mon Sep 17 00:00:00 2001 From: tgmichel Date: Mon, 27 Feb 2023 12:50:44 +0100 Subject: [PATCH 18/23] Add `asset-registry` migration --- asset-registry/src/lib.rs | 5 +++ asset-registry/src/migrations.rs | 35 +++++++++++++++++++++ asset-registry/src/mock/para.rs | 4 ++- asset-registry/src/tests.rs | 53 +++++++++++++++++++++++++++++++- 4 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 asset-registry/src/migrations.rs diff --git a/asset-registry/src/lib.rs b/asset-registry/src/lib.rs index dc2ec3669..8db5d4aaa 100644 --- a/asset-registry/src/lib.rs +++ b/asset-registry/src/lib.rs @@ -28,6 +28,8 @@ mod mock; #[cfg(test)] mod tests; +pub mod migrations; + #[frame_support::pallet] pub mod module { use super::*; @@ -130,8 +132,11 @@ pub mod module { } } + const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); + #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] + #[pallet::storage_version(STORAGE_VERSION)] #[pallet::without_storage_info] pub struct Pallet(_); diff --git a/asset-registry/src/migrations.rs b/asset-registry/src/migrations.rs new file mode 100644 index 000000000..2bfe09bf6 --- /dev/null +++ b/asset-registry/src/migrations.rs @@ -0,0 +1,35 @@ +use crate::{Config, LocationToAssetId, Pallet, Weight}; +use frame_support::pallet_prelude::*; +use frame_support::{migration::storage_key_iter, StoragePrefixedMap}; + +use xcm::v3::prelude::*; + +pub mod v2 { + use super::*; + + pub fn migrate() -> Weight { + let mut weight: Weight = Weight::zero(); + let onchain_version = Pallet::::on_chain_storage_version(); + if onchain_version < 2 { + let module_prefix = LocationToAssetId::::module_prefix(); + let storage_prefix = LocationToAssetId::::storage_prefix(); + + weight.saturating_accrue(T::DbWeight::get().reads(1)); + let old_data = storage_key_iter::( + &module_prefix, + storage_prefix, + ) + .drain(); + + for (old_key, value) in old_data { + weight.saturating_accrue(T::DbWeight::get().writes(1)); + let new_key: MultiLocation = old_key.try_into().expect("Stored xcm::v2::MultiLocation"); + LocationToAssetId::::insert(new_key, value); + } + + StorageVersion::new(2).put::>(); + weight.saturating_accrue(T::DbWeight::get().writes(1)); + } + weight + } +} diff --git a/asset-registry/src/mock/para.rs b/asset-registry/src/mock/para.rs index c29fb8f18..489d709ec 100644 --- a/asset-registry/src/mock/para.rs +++ b/asset-registry/src/mock/para.rs @@ -132,10 +132,12 @@ impl EnsureOriginWithArg> for AssetAuthority { } } +pub type ParaAssetId = u32; + impl orml_asset_registry::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; - type AssetId = u32; + type AssetId = ParaAssetId; type AuthorityOrigin = AssetAuthority; type CustomMetadata = CustomMetadata; type AssetProcessor = orml_asset_registry::SequentialId; diff --git a/asset-registry/src/tests.rs b/asset-registry/src/tests.rs index 562987b59..e5149be53 100644 --- a/asset-registry/src/tests.rs +++ b/asset-registry/src/tests.rs @@ -3,7 +3,11 @@ use super::*; use crate as orml_asset_registry; use crate::tests::para::{AdminAssetTwo, AssetRegistry, CustomMetadata, RuntimeOrigin, Tokens, TreasuryAccount}; -use frame_support::{assert_noop, assert_ok}; +use frame_support::{ + assert_noop, assert_ok, + storage::migration::{get_storage_value, put_storage_value}, + StorageHasher, +}; use mock::{para::RuntimeCall, *}; use orml_traits::MultiCurrency; use polkadot_parachain::primitives::Sibling; @@ -584,3 +588,50 @@ fn test_v2_to_v3_incompatible_multilocation() { .encode() != MultiLocation::new(0, X1(Junction::from(BoundedVec::try_from(vec![0]).unwrap()))).encode() ); } + +#[test] +fn from_unversioned_to_v2_storage() { + TestNet::reset(); + + ParaA::execute_with(|| { + let module_prefix = b"AssetRegistry"; + let storage_prefix = b"LocationToAssetId"; + + // V2 storage key + let old_key = xcm::v2::MultiLocation::new( + 0, + xcm::v2::Junctions::X1(xcm::v2::Junction::GeneralKey(vec![0].try_into().unwrap())), + ) + .encode(); + + let asset_id: para::ParaAssetId = 5u32; + + // Store raw xcm::v2 data + put_storage_value( + module_prefix, + storage_prefix, + &Blake2_128Concat::hash(&old_key), + asset_id, + ); + + // V3 storage key + let new_key = MultiLocation::new(0, X1(Junction::from(BoundedVec::try_from(vec![0]).unwrap()))); + + // Assert new StorageKey still does not exist + assert_eq!(AssetRegistry::location_to_asset_id(new_key), None); + + // Run StorageKey migration + crate::migrations::v2::migrate::(); + + // Assert the StorageKey exists and has been migrated to xcm::v3 + assert_eq!(AssetRegistry::location_to_asset_id(new_key), Some(asset_id)); + + // Assert the old key does not exist anymore + assert!(get_storage_value::( + module_prefix, + storage_prefix, + &Blake2_128Concat::hash(&old_key), + ) + .is_none()); + }); +} From ff4df3220785db2046c5e2abdd3696762c6bdda5 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Mon, 27 Feb 2023 13:20:52 +0100 Subject: [PATCH 19/23] clippy --- asset-registry/src/migrations.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/asset-registry/src/migrations.rs b/asset-registry/src/migrations.rs index 2bfe09bf6..fa9a0177e 100644 --- a/asset-registry/src/migrations.rs +++ b/asset-registry/src/migrations.rs @@ -15,11 +15,9 @@ pub mod v2 { let storage_prefix = LocationToAssetId::::storage_prefix(); weight.saturating_accrue(T::DbWeight::get().reads(1)); - let old_data = storage_key_iter::( - &module_prefix, - storage_prefix, - ) - .drain(); + let old_data = + storage_key_iter::(module_prefix, storage_prefix) + .drain(); for (old_key, value) in old_data { weight.saturating_accrue(T::DbWeight::get().writes(1)); From 91e3174ccc50197a1f9d111fd7b594ed56c64771 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Mon, 27 Feb 2023 16:13:43 +0100 Subject: [PATCH 20/23] Assert `StorageVersion` --- asset-registry/src/tests.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/asset-registry/src/tests.rs b/asset-registry/src/tests.rs index e5149be53..71de5e88c 100644 --- a/asset-registry/src/tests.rs +++ b/asset-registry/src/tests.rs @@ -597,6 +597,9 @@ fn from_unversioned_to_v2_storage() { let module_prefix = b"AssetRegistry"; let storage_prefix = b"LocationToAssetId"; + // StorageVersion is 0 before migration + assert_eq!(StorageVersion::get::>(), 0); + // V2 storage key let old_key = xcm::v2::MultiLocation::new( 0, @@ -623,6 +626,9 @@ fn from_unversioned_to_v2_storage() { // Run StorageKey migration crate::migrations::v2::migrate::(); + // StorageVersion is 2 after migration + assert_eq!(StorageVersion::get::>(), 2); + // Assert the StorageKey exists and has been migrated to xcm::v3 assert_eq!(AssetRegistry::location_to_asset_id(new_key), Some(asset_id)); From a2fddf26cb7f034246a300374971a419b652fe65 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Mon, 27 Feb 2023 16:55:50 +0100 Subject: [PATCH 21/23] Assert multiple migration calls --- asset-registry/src/tests.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/asset-registry/src/tests.rs b/asset-registry/src/tests.rs index 71de5e88c..1e2ee4149 100644 --- a/asset-registry/src/tests.rs +++ b/asset-registry/src/tests.rs @@ -639,5 +639,8 @@ fn from_unversioned_to_v2_storage() { &Blake2_128Concat::hash(&old_key), ) .is_none()); + + // Assert further calls are no-op + assert_eq!(crate::migrations::v2::migrate::(), Weight::zero()); }); } From 3eed29e80a4ed003b143263116e8506b3aac9d97 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Tue, 28 Feb 2023 09:25:59 +0100 Subject: [PATCH 22/23] AddImpl `OnRuntimeUpgrade` --- asset-registry/src/lib.rs | 3 ++- asset-registry/src/migrations.rs | 44 ++++++++++++++++++++------------ asset-registry/src/tests.rs | 5 ++-- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/asset-registry/src/lib.rs b/asset-registry/src/lib.rs index 8db5d4aaa..e2d5cea20 100644 --- a/asset-registry/src/lib.rs +++ b/asset-registry/src/lib.rs @@ -28,7 +28,8 @@ mod mock; #[cfg(test)] mod tests; -pub mod migrations; +mod migrations; +pub use migrations::Migration; #[frame_support::pallet] pub mod module { diff --git a/asset-registry/src/migrations.rs b/asset-registry/src/migrations.rs index fa9a0177e..1ce62e72b 100644 --- a/asset-registry/src/migrations.rs +++ b/asset-registry/src/migrations.rs @@ -1,33 +1,43 @@ use crate::{Config, LocationToAssetId, Pallet, Weight}; use frame_support::pallet_prelude::*; -use frame_support::{migration::storage_key_iter, StoragePrefixedMap}; +use frame_support::{migration::storage_key_iter, traits::OnRuntimeUpgrade, StoragePrefixedMap}; use xcm::v3::prelude::*; -pub mod v2 { - use super::*; - - pub fn migrate() -> Weight { +pub struct Migration(PhantomData); +impl OnRuntimeUpgrade for Migration { + fn on_runtime_upgrade() -> Weight { let mut weight: Weight = Weight::zero(); let onchain_version = Pallet::::on_chain_storage_version(); if onchain_version < 2 { - let module_prefix = LocationToAssetId::::module_prefix(); - let storage_prefix = LocationToAssetId::::storage_prefix(); + let inner_weight = v2::migrate::(); + weight.saturating_accrue(inner_weight); + } + weight + } +} - weight.saturating_accrue(T::DbWeight::get().reads(1)); - let old_data = - storage_key_iter::(module_prefix, storage_prefix) - .drain(); +mod v2 { + use super::*; - for (old_key, value) in old_data { - weight.saturating_accrue(T::DbWeight::get().writes(1)); - let new_key: MultiLocation = old_key.try_into().expect("Stored xcm::v2::MultiLocation"); - LocationToAssetId::::insert(new_key, value); - } + pub(crate) fn migrate() -> Weight { + let mut weight: Weight = Weight::zero(); + let module_prefix = LocationToAssetId::::module_prefix(); + let storage_prefix = LocationToAssetId::::storage_prefix(); - StorageVersion::new(2).put::>(); + weight.saturating_accrue(T::DbWeight::get().reads(1)); + let old_data = + storage_key_iter::(module_prefix, storage_prefix) + .drain(); + + for (old_key, value) in old_data { weight.saturating_accrue(T::DbWeight::get().writes(1)); + let new_key: MultiLocation = old_key.try_into().expect("Stored xcm::v2::MultiLocation"); + LocationToAssetId::::insert(new_key, value); } + + StorageVersion::new(2).put::>(); + weight.saturating_accrue(T::DbWeight::get().writes(1)); weight } } diff --git a/asset-registry/src/tests.rs b/asset-registry/src/tests.rs index 1e2ee4149..4a0f53169 100644 --- a/asset-registry/src/tests.rs +++ b/asset-registry/src/tests.rs @@ -6,6 +6,7 @@ use crate::tests::para::{AdminAssetTwo, AssetRegistry, CustomMetadata, RuntimeOr use frame_support::{ assert_noop, assert_ok, storage::migration::{get_storage_value, put_storage_value}, + traits::OnRuntimeUpgrade, StorageHasher, }; use mock::{para::RuntimeCall, *}; @@ -624,7 +625,7 @@ fn from_unversioned_to_v2_storage() { assert_eq!(AssetRegistry::location_to_asset_id(new_key), None); // Run StorageKey migration - crate::migrations::v2::migrate::(); + crate::Migration::::on_runtime_upgrade(); // StorageVersion is 2 after migration assert_eq!(StorageVersion::get::>(), 2); @@ -641,6 +642,6 @@ fn from_unversioned_to_v2_storage() { .is_none()); // Assert further calls are no-op - assert_eq!(crate::migrations::v2::migrate::(), Weight::zero()); + assert_eq!(crate::Migration::::on_runtime_upgrade(), Weight::zero()); }); } From 59d3f1403f382fd1eeecd4f2341c48743cf5e2d4 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Tue, 28 Feb 2023 13:37:02 +0100 Subject: [PATCH 23/23] Add `unknown-tokens` migration --- unknown-tokens/src/lib.rs | 6 ++ unknown-tokens/src/migrations.rs | 82 +++++++++++++++++++++++++ unknown-tokens/src/tests.rs | 101 ++++++++++++++++++++++++++++++- 3 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 unknown-tokens/src/migrations.rs diff --git a/unknown-tokens/src/lib.rs b/unknown-tokens/src/lib.rs index acbf8c373..40ef68959 100644 --- a/unknown-tokens/src/lib.rs +++ b/unknown-tokens/src/lib.rs @@ -12,6 +12,9 @@ pub use module::*; mod mock; mod tests; +mod migrations; +pub use migrations::Migration; + #[frame_support::pallet] pub mod module { use super::*; @@ -40,8 +43,11 @@ pub mod module { UnhandledAsset, } + const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); + #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] + #[pallet::storage_version(STORAGE_VERSION)] #[pallet::without_storage_info] pub struct Pallet(_); diff --git a/unknown-tokens/src/migrations.rs b/unknown-tokens/src/migrations.rs new file mode 100644 index 000000000..84a36584e --- /dev/null +++ b/unknown-tokens/src/migrations.rs @@ -0,0 +1,82 @@ +use crate::{AbstractFungibleBalances, ConcreteFungibleBalances, Config, Pallet, Weight}; +use frame_support::pallet_prelude::*; +use frame_support::{migration::storage_iter, traits::OnRuntimeUpgrade, ReversibleStorageHasher, StoragePrefixedMap}; + +use sp_std::vec::Vec; + +use xcm::v3::prelude::*; + +pub struct Migration(PhantomData); +impl OnRuntimeUpgrade for Migration { + fn on_runtime_upgrade() -> Weight { + let mut weight: Weight = Weight::zero(); + let onchain_version = Pallet::::on_chain_storage_version(); + if onchain_version < 2 { + let inner_weight = v2::migrate::(); + weight.saturating_accrue(inner_weight); + } + weight + } +} + +mod v2 { + use super::*; + + pub(crate) fn migrate() -> Weight { + let mut weight: Weight = Weight::zero(); + + // ConcreteFungibleBalances + let module_prefix = ConcreteFungibleBalances::::module_prefix(); + let storage_prefix = ConcreteFungibleBalances::::storage_prefix(); + + weight.saturating_accrue(T::DbWeight::get().reads(1)); + + let old_data = storage_iter::(module_prefix, storage_prefix).drain(); + + for (raw_k, value) in old_data { + let mut full_key = Vec::new(); + full_key.extend_from_slice(&raw_k); + + let mut k1_k2_material = Blake2_128Concat::reverse(&full_key); + let k1: xcm::v2::MultiLocation = + Decode::decode(&mut k1_k2_material).expect("Stored k1 xcm::v2::MultiLocation"); + + let mut k2_material = Blake2_128Concat::reverse(k1_k2_material); + let k2: xcm::v2::MultiLocation = + Decode::decode(&mut k2_material).expect("Stored k2 xcm::v2::MultiLocation"); + + weight.saturating_accrue(T::DbWeight::get().writes(1)); + let k1_new: MultiLocation = k1.try_into().expect("Stored k1 xcm::v2::MultiLocation"); + let k2_new: MultiLocation = k2.try_into().expect("Stored k2 xcm::v2::MultiLocation"); + ConcreteFungibleBalances::::insert(k1_new, k2_new, value); + } + + // AbstractFungibleBalances + let module_prefix = AbstractFungibleBalances::::module_prefix(); + let storage_prefix = AbstractFungibleBalances::::storage_prefix(); + + weight.saturating_accrue(T::DbWeight::get().reads(1)); + + let old_data = storage_iter::(module_prefix, storage_prefix).drain(); + + for (raw_k, value) in old_data { + let mut full_key = Vec::new(); + full_key.extend_from_slice(&raw_k); + + let mut k1_k2_material = Blake2_128Concat::reverse(&full_key); + let k1: xcm::v2::MultiLocation = + Decode::decode(&mut k1_k2_material).expect("Stored k1 xcm::v2::MultiLocation"); + + let mut k2_material = Blake2_128Concat::reverse(k1_k2_material); + let k2_new: Vec = Decode::decode(&mut k2_material).expect("Stored k1 xcm::v2::MultiLocation"); + + weight.saturating_accrue(T::DbWeight::get().writes(1)); + let k1_new: MultiLocation = k1.try_into().expect("Stored k1 xcm::v2::MultiLocation"); + AbstractFungibleBalances::::insert(k1_new, k2_new, value); + } + + StorageVersion::new(2).put::>(); + weight.saturating_accrue(T::DbWeight::get().writes(1)); + weight + } +} diff --git a/unknown-tokens/src/tests.rs b/unknown-tokens/src/tests.rs index 99b247f4c..45d699ddb 100644 --- a/unknown-tokens/src/tests.rs +++ b/unknown-tokens/src/tests.rs @@ -5,7 +5,11 @@ use super::*; use mock::*; -use frame_support::{assert_err, assert_ok}; +use frame_support::{ + assert_err, assert_ok, + storage::migration::{get_storage_value, put_storage_value}, + traits::OnRuntimeUpgrade, +}; const MOCK_RECIPIENT: MultiLocation = MultiLocation::parent(); const MOCK_CONCRETE_FUNGIBLE_ID: MultiLocation = MultiLocation::parent(); @@ -151,3 +155,98 @@ fn withdraw_unhandled_asset_should_fail() { ); }); } + +#[test] +fn from_unversioned_to_v2_storage() { + ExtBuilder.build().execute_with(|| { + fn blake2_128_concat(d: &[u8]) -> Vec { + let mut v = sp_io::hashing::blake2_128(d).to_vec(); + v.extend_from_slice(d); + v + } + + // StorageVersion is 0 before migration + assert_eq!(StorageVersion::get::>(), 0); + + // V2 `ConcreteFungibleBalances` key + let mut old_concrete_key = Vec::new(); + old_concrete_key.extend_from_slice( + &xcm::v2::MultiLocation::new( + 0, + xcm::v2::Junctions::X1(xcm::v2::Junction::GeneralKey(vec![0].try_into().unwrap())), + ) + .using_encoded(blake2_128_concat), + ); + old_concrete_key.extend_from_slice(&xcm::v2::MultiLocation::here().using_encoded(blake2_128_concat)); + + let balance = 55u128; + + put_storage_value( + b"UnknownTokens", + b"ConcreteFungibleBalances", + &old_concrete_key, + balance, + ); + + // V2 `AbstractFungibleBalances` key + let mut old_abstract_key = Vec::new(); + old_abstract_key.extend_from_slice( + &xcm::v2::MultiLocation::new( + 0, + xcm::v2::Junctions::X1(xcm::v2::Junction::GeneralKey(vec![0].try_into().unwrap())), + ) + .using_encoded(blake2_128_concat), + ); + old_abstract_key.extend_from_slice(&vec![1].using_encoded(blake2_128_concat)); + + let balance = 77u128; + + put_storage_value( + b"UnknownTokens", + b"AbstractFungibleBalances", + &old_abstract_key, + balance, + ); + + // V3 storage keys + let new_concrete_k1 = MultiLocation::new(0, X1(Junction::from(BoundedVec::try_from(vec![0]).unwrap()))); + let new_concrete_k2 = MultiLocation::here(); + let new_abstract_k1 = MultiLocation::new(0, X1(Junction::from(BoundedVec::try_from(vec![0]).unwrap()))); + let new_abstract_k2 = vec![1]; + + // Assert new StorageKey still does not exist + assert_eq!( + UnknownTokens::concrete_fungible_balances(new_concrete_k1, new_concrete_k2), + 0 + ); + assert_eq!( + UnknownTokens::abstract_fungible_balances(new_abstract_k1, new_abstract_k2.clone()), + 0 + ); + + // Migrate + crate::Migration::::on_runtime_upgrade(); + + // StorageVersion is 2 after migration + assert_eq!(StorageVersion::get::>(), 2); + + // Assert the StorageKey exists and has been migrated to xcm::v3 + assert_eq!( + UnknownTokens::concrete_fungible_balances(new_concrete_k1, new_concrete_k2), + 55 + ); + assert_eq!( + UnknownTokens::abstract_fungible_balances(new_abstract_k1, new_abstract_k2), + 77 + ); + + // Assert the old concrete key does not exist anymore + assert!(get_storage_value::(b"UnknownTokens", b"ConcreteFungibleBalances", &old_concrete_key,).is_none()); + + // Assert the old abstract key does not exist anymore + assert!(get_storage_value::(b"UnknownTokens", b"AbstractFungibleBalances", &old_concrete_key,).is_none()); + + // Assert further calls are no-op + assert_eq!(crate::Migration::::on_runtime_upgrade(), Weight::zero()); + }); +}