diff --git a/.github/workflows/mangata-dev.yml b/.github/workflows/mangata-dev.yml index 5b72c65af..c2f4eff2a 100644 --- a/.github/workflows/mangata-dev.yml +++ b/.github/workflows/mangata-dev.yml @@ -13,10 +13,10 @@ jobs: with: toolchain: nightly default: true - - name: Install nightly-2020-10-01 with wasm + - name: Install nightly-2022-11-11 with wasm uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2020-10-01 + toolchain: nightly-2022-11-11 target: wasm32-unknown-unknown - name: Check Cargo version run: | diff --git a/Cargo.dev.toml b/Cargo.dev.toml index f59a2f46e..9bfdf7f70 100644 --- a/Cargo.dev.toml +++ b/Cargo.dev.toml @@ -26,6 +26,7 @@ members = [ "build-script-utils", "weight-gen", "weight-meter", + "payments" ] exclude = ["bencher/test"] @@ -60,7 +61,7 @@ pallet-assets = { git = "https://github.com/mangata-finance//substrate", branch pallet-tips = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } pallet-election-provider-multi-phase = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } pallet-beefy-mmr = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } -beefy-merkle-tree = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } +#beefy-merkle-tree = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } pallet-scheduler = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } pallet-multisig = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } frame-executive = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } @@ -93,10 +94,10 @@ pallet-elections-phragmen = { git = "https://github.com/mangata-finance//substra pallet-proxy = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } pallet-vesting = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sc-informant = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } -sc-finality-grandpa-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } -sc-finality-grandpa = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } -beefy-gadget-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } -beefy-gadget = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } +#sc-finality-grandpa-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } +#sc-finality-grandpa = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } +#beefy-gadget-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } +#beefy-gadget = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sc-executor-wasmtime = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sc-executor-common = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sc-executor-wasmi = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } @@ -129,7 +130,7 @@ sc-state-db = { git = "https://github.com/mangata-finance//substrate", branch = sc-allocator = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sc-consensus = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sc-consensus-aura = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } -sc-consensus-uncles = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } +#sc-consensus-uncles = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sc-consensus-epochs = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sc-consensus-slots = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sc-consensus-babe-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } @@ -153,9 +154,9 @@ sp-inherents = { git = "https://github.com/mangata-finance//substrate", branch = sp-authorship = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sp-storage = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sp-std = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } -sp-finality-grandpa = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } -beefy-primitives = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev", package = "sp-beefy" } -remote-externalities = { git = "https://github.com/mangata-finance//substrate" } +#sp-finality-grandpa = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } +#beefy-primitives = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev", package = "sp-beefy" } +#remote-externalities = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev"} sp-version-proc-macro = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sp-version = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sp-transaction-pool = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } diff --git a/README.md b/README.md index 62ede983b..ec64ad8cf 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ ORML is part of the bigger `Open-Web3-Stack` initiative, that is currently under _In alphabetical order_ - [Acala Network](https://github.com/AcalaNetwork/Acala) +- [Ajuna Network](https://github.com/ajuna-network/Ajuna) - [Astar Network](https://github.com/AstarNetwork) - [Bifrost Finance](https://github.com/bifrost-finance/bifrost) - [Bit.Country](https://github.com/bit-country/Bit-Country-Blockchain) @@ -102,8 +103,11 @@ _In alphabetical order_ - [Libra](https://github.com/atscaletech/libra) - [Listen](https://github.com/listenofficial) - [Manta Network](https://github.com/Manta-Network) +- [Mangata Finance](https://github.com/mangata-finance) - [Minterest](https://github.com/minterest-finance/minterest-chain-node) +- [Moonbeam](https://github.com/PureStake/moonbeam/) - [OAK](https://github.com/OAK-Foundation/OAK-blockchain) +- [Parallel Finance](https://github.com/parallel-finance/) - [PolkaFoundry Network](https://github.com/PolkaFoundry) - [Setheum Network](https://github.com/Setheum-Labs/Setheum) - [Valiu Liquidity Network](https://github.com/valibre-org/vln-node) diff --git a/asset-registry/Cargo.toml b/asset-registry/Cargo.toml index 6b121d52a..1bd4aff3a 100644 --- a/asset-registry/Cargo.toml +++ b/asset-registry/Cargo.toml @@ -13,17 +13,17 @@ 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.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false , optional = true } # polkadot -pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" } -xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" } -xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" } +pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" } +xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" } +xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" } # orml orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } @@ -34,21 +34,21 @@ mangata-types = { git = "https://github.com/mangata-finance/substrate", default- [dev-dependencies] # substrate -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } # cumulus -cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" } -cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" } -cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" } -cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" } -parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" } +cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" } +cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" } +cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" } +parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" } # polkadot -polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.36" } -polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.36" } -xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.36" } +polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" } +polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" } +xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" } # orml orml-tokens = { path = "../tokens" } diff --git a/asset-registry/src/impls.rs b/asset-registry/src/impls.rs index 744263669..416672745 100644 --- a/asset-registry/src/impls.rs +++ b/asset-registry/src/impls.rs @@ -1,5 +1,5 @@ use crate::module::*; -use frame_support::{log, pallet_prelude::*, weights::constants::{WEIGHT_REF_TIME_PER_SECOND}}; +use frame_support::{log, pallet_prelude::*, weights::constants::WEIGHT_REF_TIME_PER_SECOND}; use orml_traits::{ asset_registry::{AssetMetadata, FixedConversionRateProvider, Inspect, Mutate, WeightToFeeConverter}, GetByKey, @@ -7,13 +7,10 @@ use orml_traits::{ use sp_runtime::FixedPointNumber; use sp_runtime::{traits::Bounded, FixedU128}; use sp_std::prelude::*; -use xcm::latest::{prelude::*, Weight as XcmWeight}; +use xcm::v3::{prelude::*, Weight as XcmWeight}; use xcm::VersionedMultiLocation; use xcm_builder::TakeRevenue; use xcm_executor::{traits::WeightTrader, Assets}; - -use crate::module::*; - /* /// Alias for AssetMetadata to improve readability (and to placate clippy) pub type DefaultAssetMetadata = AssetMetadata<::Balance, ::CustomMetadata>; @@ -103,7 +100,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. @@ -111,7 +108,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), @@ -119,10 +116,8 @@ 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)?, - asset_location: location.clone(), + weight: existing_weight.checked_add(&weight).ok_or(XcmError::Overflow)?, + asset_location: *location, }); return Ok(unused); } @@ -137,14 +132,14 @@ 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); 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 } @@ -154,7 +149,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/asset-registry/src/lib.rs b/asset-registry/src/lib.rs index b6a64e3d5..aef9086f4 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::*; @@ -29,6 +29,9 @@ mod mock; #[cfg(test)] mod tests; +mod migrations; +pub use migrations::Migration; + #[frame_support::pallet] pub mod module { use super::*; @@ -121,8 +124,10 @@ 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..75320e289 --- /dev/null +++ b/asset-registry/src/migrations.rs @@ -0,0 +1,44 @@ +use crate::{Config, LocationToAssetId, Pallet, Weight}; +use frame_support::pallet_prelude::*; +use frame_support::{migration::storage_key_iter, traits::OnRuntimeUpgrade, StoragePrefixedMap}; + +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(); + 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() + .collect::>(); + + 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/mod.rs b/asset-registry/src/mock/mod.rs index 385f9df2c..7e0cc6207 100644 --- a/asset-registry/src/mock/mod.rs +++ b/asset-registry/src/mock/mod.rs @@ -3,6 +3,9 @@ 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}; @@ -35,6 +38,7 @@ impl Convert> for CurrencyIdConvert { return Some(asset_id); } None + } } impl Convert> for CurrencyIdConvert { @@ -159,7 +163,7 @@ pub fn para_ext(para_id: u32, asset_data: Option<(Vec<(u32, Vec)>, u32)>) -> .unwrap(); if let Some((assets, _)) = asset_data { - GenesisConfig:: { assets: assets } + GenesisConfig:: { assets } .assimilate_storage(&mut t) .unwrap(); } diff --git a/asset-registry/src/mock/para.rs b/asset-registry/src/mock/para.rs index a3f226eca..107a60281 100644 --- a/asset-registry/src/mock/para.rs +++ b/asset-registry/src/mock/para.rs @@ -30,11 +30,11 @@ use sp_runtime::{ traits::{AccountIdConversion, Convert, IdentityLookup}, AccountId32, DispatchError, }; -use xcm::latest::{prelude::*, Weight}; +use xcm::v3::{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}; @@ -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!() } } @@ -157,11 +157,12 @@ impl AssetProcessor } } } +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 = SequentialIdWithCreation; @@ -169,8 +170,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_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); + pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); } impl parachain_info::Config for Runtime {} @@ -179,7 +180,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 = ( @@ -240,6 +242,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; @@ -248,14 +257,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; @@ -277,6 +295,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 { @@ -292,6 +311,16 @@ impl cumulus_pallet_xcm::Config for Runtime { pub type LocalOriginToLocation = SignedToAccountId32; +parameter_types! { + pub SelfLocation: MultiLocation = MultiLocation::here(); + 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; @@ -301,30 +330,33 @@ 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; + #[cfg(feature = "runtime-benchmarks")] + type ReachableDest = ReachableDest; } 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 { .. }) } | @@ -357,9 +389,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..96a94e0aa 100644 --- a/asset-registry/src/mock/relay.rs +++ b/asset-registry/src/mock/relay.rs @@ -1,17 +1,18 @@ +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; use polkadot_runtime_parachains::{configuration, origin, shared, ump}; use sp_core::H256; use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; -use xcm::latest::prelude::*; +use xcm::v3::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,36 @@ 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(); +} + +#[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; @@ -117,12 +142,20 @@ 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; + #[cfg(feature = "runtime-benchmarks")] + type ReachableDest = ReachableDest; } impl ump::Config for Runtime { diff --git a/asset-registry/src/tests.rs b/asset-registry/src/tests.rs index 23f0842e9..16a149558 100644 --- a/asset-registry/src/tests.rs +++ b/asset-registry/src/tests.rs @@ -3,7 +3,12 @@ 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}, + traits::OnRuntimeUpgrade, + StorageHasher, +}; use mock::{para::RuntimeCall, *}; use orml_traits::MultiCurrency; use polkadot_parachain::primitives::Sibling; @@ -14,6 +19,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() } @@ -46,7 +55,13 @@ fn dummy_metadata() -> AssetMetadata<>(), 0); + + // V2 storage + let old_multilocation_0 = xcm::v2::MultiLocation::new( + 0, + xcm::v2::Junctions::X1(xcm::v2::Junction::GeneralKey(vec![0].try_into().unwrap())), + ); + let old_multilocation_1 = xcm::v2::MultiLocation::new( + 1, + xcm::v2::Junctions::X2( + xcm::v2::Junction::Parachain(2096), + xcm::v2::Junction::GeneralKey(vec![0, 0, 0, 0, 0, 0, 0, 0, 0].try_into().unwrap()), + ), + ); + let old_multilocation_2 = xcm::v2::MultiLocation::new( + 1, + xcm::v2::Junctions::X2( + xcm::v2::Junction::Parachain(2096), + xcm::v2::Junction::GeneralKey(vec![1, 1].try_into().unwrap()), + ), + ); + + let asset_id_0: para::ParaAssetId = 5u32; + let asset_id_1: para::ParaAssetId = 6u32; + let asset_id_2: para::ParaAssetId = 7u32; + + // Store raw xcm::v2 data + put_storage_value( + module_prefix, + storage_prefix, + &Twox64Concat::hash(&old_multilocation_0.encode()), + asset_id_0, + ); + put_storage_value( + module_prefix, + storage_prefix, + &Twox64Concat::hash(&old_multilocation_1.encode()), + asset_id_1, + ); + put_storage_value( + module_prefix, + storage_prefix, + &Twox64Concat::hash(&old_multilocation_2.encode()), + asset_id_2, + ); + + // V3 storage key + let new_multilocation_0 = MultiLocation::new(0, X1(Junction::from(BoundedVec::try_from(vec![0]).unwrap()))); + let new_multilocation_1 = MultiLocation::new( + 1, + X2( + Parachain(2096), + Junction::from(BoundedVec::try_from(vec![0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap()), + ), + ); + let new_multilocation_2 = MultiLocation::new( + 1, + X2( + Parachain(2096), + Junction::from(BoundedVec::try_from(vec![1, 1]).unwrap()), + ), + ); + + // Assert new StorageKey still does not exist + assert_eq!(AssetRegistry::location_to_asset_id(new_multilocation_0), None); + assert_eq!(AssetRegistry::location_to_asset_id(new_multilocation_1), None); + assert_eq!(AssetRegistry::location_to_asset_id(new_multilocation_2), None); + + // Run StorageKey migration + 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!( + AssetRegistry::location_to_asset_id(new_multilocation_0), + Some(asset_id_0) + ); + assert_eq!( + AssetRegistry::location_to_asset_id(new_multilocation_1), + Some(asset_id_1) + ); + assert_eq!( + AssetRegistry::location_to_asset_id(new_multilocation_2), + Some(asset_id_2) + ); + + // Assert the old key does not exist anymore + assert!(get_storage_value::( + module_prefix, + storage_prefix, + &Twox64Concat::hash(&old_multilocation_0.encode()), + ) + .is_none()); + assert!(get_storage_value::( + module_prefix, + storage_prefix, + &Twox64Concat::hash(&old_multilocation_1.encode()), + ) + .is_none()); + assert!(get_storage_value::( + module_prefix, + storage_prefix, + &Twox64Concat::hash(&old_multilocation_2.encode()), + ) + .is_none()); + + // Assert further calls are no-op + assert_eq!(crate::Migration::::on_runtime_upgrade(), Weight::zero()); + }); +} diff --git a/asset-registry/src/weights.rs b/asset-registry/src/weights.rs index 61dd5d59f..5434868d4 100644 --- a/asset-registry/src/weights.rs +++ b/asset-registry/src/weights.rs @@ -22,14 +22,14 @@ impl WeightInfo for () { // Storage: AssetRegistry Metadata (r:1 w:1) // Storage: AssetRegistry LocationToAssetId (r:1 w:1) fn register_asset() -> Weight { - Weight::from_ref_time(34_624_000) + Weight::from_parts(34_624_000, 0) .saturating_add(RocksDbWeight::get().reads(4 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } // Storage: AssetRegistry Metadata (r:1 w:1) // Storage: AssetRegistry LocationToAssetId (r:1 w:1) fn update_asset() -> Weight { - Weight::from_ref_time(28_712_000) + Weight::from_parts(28_712_000, 0) .saturating_add(RocksDbWeight::get().reads(2 as u64)) .saturating_add(RocksDbWeight::get().writes(2 as u64)) } diff --git a/auction/Cargo.toml b/auction/Cargo.toml index 034d2d97b..08d2b7966 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.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } 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.36" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } [features] default = ["std"] diff --git a/auction/src/lib.rs b/auction/src/lib.rs index 5c4e00010..476863853 100644 --- a/auction/src/lib.rs +++ b/auction/src/lib.rs @@ -103,7 +103,6 @@ pub mod module { StorageDoubleMap<_, Twox64Concat, T::BlockNumber, Blake2_128Concat, T::AuctionId, (), OptionQuery>; #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); #[pallet::hooks] diff --git a/auction/src/weights.rs b/auction/src/weights.rs index 96fa19293..92af4c258 100644 --- a/auction/src/weights.rs +++ b/auction/src/weights.rs @@ -37,14 +37,14 @@ pub trait WeightInfo { /// Default weights. impl WeightInfo for () { fn bid_collateral_auction() -> Weight { - Weight::from_ref_time(108_000_000) + Weight::from_parts(108_000_000, 0) .saturating_add(RocksDbWeight::get().reads(8 as u64)) .saturating_add(RocksDbWeight::get().writes(9 as u64)) } fn on_finalize(c: u32, ) -> Weight { - Weight::from_ref_time(9_779_000) + Weight::from_parts(9_779_000, 0) // Standard Error: 13_000 - .saturating_add(Weight::from_ref_time(57_962_000).saturating_mul(c as u64)) + .saturating_add(Weight::from_parts(57_962_000, 0).saturating_mul(c as u64)) .saturating_add(RocksDbWeight::get().reads(10 as u64)) .saturating_add(RocksDbWeight::get().reads((3 as u64).saturating_mul(c as u64))) .saturating_add(RocksDbWeight::get().writes(7 as u64)) diff --git a/authority/Cargo.toml b/authority/Cargo.toml index b58121a69..b23053ba4 100644 --- a/authority/Cargo.toml +++ b/authority/Cargo.toml @@ -8,24 +8,22 @@ authors = ["Acala Developers"] edition = "2021" [dependencies] - +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.145", optional = true } -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.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } [dev-dependencies] -pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -pallet-root-testing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } - +pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +pallet-root-testing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } [features] default = ["std"] @@ -33,10 +31,6 @@ std = [ "serde", "codec/std", - "scale-info/std", - "sp-runtime/std", - "sp-std/std", - "sp-io/std", "frame-support/std", "frame-system/std", "scale-info/std", @@ -54,4 +48,3 @@ try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", ] - diff --git a/authority/src/lib.rs b/authority/src/lib.rs index 506f96578..db94411ea 100644 --- a/authority/src/lib.rs +++ b/authority/src/lib.rs @@ -35,7 +35,6 @@ use frame_support::{ schedule::{v1::Named as ScheduleNamed, DispatchTime, Priority}, EitherOfDiverse, EnsureOrigin, Get, IsType, OriginTrait, }, - weights::OldWeight, }; use frame_system::{pallet_prelude::*, EnsureRoot, EnsureSigned}; use scale_info::TypeInfo; @@ -146,7 +145,7 @@ impl< } #[cfg(feature = "runtime-benchmarks")] - fn successful_origin() -> O { + fn try_successful_origin() -> Result { unimplemented!() } } @@ -297,7 +296,6 @@ pub mod module { pub type SavedCalls = StorageMap<_, Identity, T::Hash, (CallOf, Option), OptionQuery>; #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] #[pallet::without_storage_info] pub struct Pallet(_); @@ -488,38 +486,6 @@ pub mod module { }) } - #[pallet::call_index(7)] - #[pallet::weight(( - T::WeightInfo::trigger_call().saturating_add((*call_weight_bound).into()), - DispatchClass::Operational, - ))] - #[allow(deprecated)] - #[deprecated(note = "1D weight is used in this extrinsic, please migrate to `trigger_call`")] - pub fn trigger_old_call( - origin: OriginFor, - hash: T::Hash, - #[pallet::compact] call_weight_bound: OldWeight, - ) -> DispatchResultWithPostInfo { - let call_weight_bound: Weight = call_weight_bound.into(); - let who = ensure_signed(origin)?; - SavedCalls::::try_mutate_exists(hash, |maybe_call| { - let (call, maybe_caller) = maybe_call.take().ok_or(Error::::CallNotAuthorized)?; - if let Some(caller) = maybe_caller { - ensure!(who == caller, Error::::TriggerCallNotPermitted); - } - ensure!( - call_weight_bound.ref_time() >= call.get_dispatch_info().weight.ref_time(), - Error::::WrongCallWeightBound - ); - let result = call.dispatch(OriginFor::::root()); - Self::deposit_event(Event::TriggeredCallBy { hash, caller: who }); - Self::deposit_event(Event::Dispatched { - result: result.map(|_| ()).map_err(|e| e.error), - }); - Ok(Pays::No.into()) - }) - } - #[pallet::call_index(8)] #[pallet::weight(( T::WeightInfo::trigger_call().saturating_add(*call_weight_bound), diff --git a/authority/src/mock.rs b/authority/src/mock.rs index 5709698ff..d42ea175f 100644 --- a/authority/src/mock.rs +++ b/authority/src/mock.rs @@ -24,7 +24,7 @@ pub type BlockNumber = u64; parameter_types! { pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(2_000_000_000_000).set_proof_size(u64::MAX)); + frame_system::limits::BlockWeights::simple_max(Weight::from_parts(2_000_000_000_000, 0).set_proof_size(u64::MAX)); } impl frame_system::Config for Runtime { diff --git a/authority/src/tests.rs b/authority/src/tests.rs index 9aa301588..685fdcddb 100644 --- a/authority/src/tests.rs +++ b/authority/src/tests.rs @@ -510,7 +510,7 @@ fn trigger_call_works() { Authority::trigger_call( RuntimeOrigin::signed(1), hash, - call_weight_bound - Weight::from_ref_time(1) + call_weight_bound - Weight::from_parts(1, 0) ), Error::::WrongCallWeightBound ); @@ -652,48 +652,6 @@ fn trigger_call_should_be_free_and_operational() { }); } -#[test] -fn trigger_old_call_should_be_free_and_operational() { - ExtBuilder::default().build().execute_with(|| { - let call = RuntimeCall::RootTesting(pallet_root_testing::Call::fill_block { - ratio: Perbill::from_percent(50), - }); - let hash = ::Hashing::hash_of(&call); - let call_weight_bound: OldWeight = OldWeight(call.get_dispatch_info().weight.ref_time()); - let trigger_old_call = RuntimeCall::Authority(authority::Call::trigger_old_call { - hash, - call_weight_bound, - }); - - assert_ok!(Authority::authorize_call( - RuntimeOrigin::root(), - Box::new(call), - Some(1) - )); - - // bad caller pays fee - assert_eq!( - trigger_old_call.clone().dispatch(RuntimeOrigin::signed(2)), - Err(DispatchErrorWithPostInfo { - post_info: PostDispatchInfo { - actual_weight: None, - pays_fee: Pays::Yes - }, - error: Error::::TriggerCallNotPermitted.into() - }) - ); - - // successfull call doesn't pay fee - assert_eq!( - trigger_old_call.dispatch(RuntimeOrigin::signed(1)), - Ok(PostDispatchInfo { - actual_weight: None, - pays_fee: Pays::No - }) - ); - }); -} - #[test] fn origin_max_encoded_len_works() { assert_eq!(DelayedOrigin::::max_encoded_len(), 22); diff --git a/authority/src/weights.rs b/authority/src/weights.rs index cc4dd2db5..728d7593b 100644 --- a/authority/src/weights.rs +++ b/authority/src/weights.rs @@ -43,44 +43,44 @@ pub trait WeightInfo { /// Default weights. impl WeightInfo for () { fn dispatch_as() -> Weight { - Weight::from_ref_time(12_000_000) + Weight::from_parts(12_000_000, 0) } fn schedule_dispatch_without_delay() -> Weight { - Weight::from_ref_time(30_000_000) + Weight::from_parts(30_000_000, 0) .saturating_add(RocksDbWeight::get().reads(3 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } fn schedule_dispatch_with_delay() -> Weight { - Weight::from_ref_time(32_000_000) + Weight::from_parts(32_000_000, 0) .saturating_add(RocksDbWeight::get().reads(3 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } fn fast_track_scheduled_dispatch() -> Weight { - Weight::from_ref_time(42_000_000) + Weight::from_parts(42_000_000, 0) .saturating_add(RocksDbWeight::get().reads(3 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } fn delay_scheduled_dispatch() -> Weight { - Weight::from_ref_time(42_000_000) + Weight::from_parts(42_000_000, 0) .saturating_add(RocksDbWeight::get().reads(3 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } fn cancel_scheduled_dispatch() -> Weight { - Weight::from_ref_time(29_000_000) + Weight::from_parts(29_000_000, 0) .saturating_add(RocksDbWeight::get().reads(2 as u64)) .saturating_add(RocksDbWeight::get().writes(2 as u64)) } fn authorize_call() -> Weight { - Weight::from_ref_time(14_000_000) + Weight::from_parts(14_000_000, 0) .saturating_add(RocksDbWeight::get().writes(1 as u64)) } fn remove_authorized_call() -> Weight { - Weight::from_ref_time(16_000_000) + Weight::from_parts(16_000_000, 0) .saturating_add(RocksDbWeight::get().reads(1 as u64)) .saturating_add(RocksDbWeight::get().writes(1 as u64)) } fn trigger_call() -> Weight { - Weight::from_ref_time(29_000_000) + Weight::from_parts(29_000_000, 0) .saturating_add(RocksDbWeight::get().reads(1 as u64)) .saturating_add(RocksDbWeight::get().writes(1 as u64)) } diff --git a/bencher/Cargo.toml b/bencher/Cargo.toml index e61bf3fc1..3bdfaa355 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.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime-interface = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-state-machine = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.36" } -sc-executor = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.36" } -sc-executor-common = { git = "https://github.com/paritytech/substrate", optional = true , branch = "polkadot-v0.9.36" } -sc-client-db = { git = "https://github.com/paritytech/substrate", default-features = false, features = ["rocksdb"], optional = true , branch = "polkadot-v0.9.36" } -sp-maybe-compressed-blob = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.36" } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-externalities = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-storage = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.36" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime-interface = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-state-machine = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.40" } +sc-executor = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.40" } +sc-executor-common = { git = "https://github.com/paritytech/substrate", optional = true , branch = "polkadot-v0.9.40" } +sc-client-db = { git = "https://github.com/paritytech/substrate", default-features = false, features = ["rocksdb"], optional = true , branch = "polkadot-v0.9.40" } +sp-maybe-compressed-blob = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.40" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-externalities = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-storage = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.40" } [features] default = ["std"] diff --git a/bencher/src/bench_ext.rs b/bencher/src/bench_ext.rs index f80222a25..3c94b222c 100644 --- a/bencher/src/bench_ext.rs +++ b/bencher/src/bench_ext.rs @@ -1,5 +1,5 @@ use core::any::{Any, TypeId}; -use hash_db::Hasher; +use sp_core::Hasher; use sp_externalities::{Extension, ExtensionStore, Externalities, MultiRemovalResults}; use sp_state_machine::{Backend, Ext}; use sp_std::sync::Arc; diff --git a/bencher/test/Cargo.toml b/bencher/test/Cargo.toml index f4705f3b6..95beb2bc5 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.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } 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.36" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } [features] default = ["std"] diff --git a/bencher/test/src/lib.rs b/bencher/test/src/lib.rs index 892e9231f..4e191ecc1 100644 --- a/bencher/test/src/lib.rs +++ b/bencher/test/src/lib.rs @@ -21,7 +21,6 @@ pub mod pallet { impl Hooks for Pallet {} #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(PhantomData); #[pallet::storage] diff --git a/bencher/test/src/weights.rs b/bencher/test/src/weights.rs index 8882be9cf..100178d15 100644 --- a/bencher/test/src/weights.rs +++ b/bencher/test/src/weights.rs @@ -14,7 +14,7 @@ impl ModuleWeights { // // Test::Bar (r: 0, w: 1) pub fn whitelist() -> Weight { - Weight::from_ref_time(5_356_000) + Weight::from_parts(5_356_000, 0) .saturating_add(T::DbWeight::get().writes(1)) } // Storage access info @@ -22,7 +22,7 @@ impl ModuleWeights { // Test::Value (r: 1, w: 1) // Unknown 0x3a7472616e73616374696f6e5f6c6576656c3a (r: 1, w: 1) pub fn set_value() -> Weight { - Weight::from_ref_time(3_919_000) + Weight::from_parts(3_919_000, 0) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -32,20 +32,20 @@ impl ModuleWeights { // Test::Foo (r: 0, w: 1) // Test::Value (r: 0, w: 1) pub fn set_foo() -> Weight { - Weight::from_ref_time(5_133_000) + Weight::from_parts(5_133_000, 0) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(4)) } // Storage access info // pub fn remove_all_bar() -> Weight { - Weight::from_ref_time(1_533_000) + Weight::from_parts(1_533_000, 0) } // Storage access info // // Test::Bar (r: 0, w: 10) pub fn remove_all_bar_with_limit() -> Weight { - Weight::from_ref_time(1_600_000) + Weight::from_parts(1_600_000, 0) .saturating_add(T::DbWeight::get().writes(10)) } } diff --git a/benchmarking/Cargo.toml b/benchmarking/Cargo.toml index 30716e8e2..1d63c8835 100644 --- a/benchmarking/Cargo.toml +++ b/benchmarking/Cargo.toml @@ -14,20 +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.36" } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime-interface = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-storage = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime-interface = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-storage = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } [dev-dependencies] hex-literal = "0.3.4" -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } - +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } [features] default = [ "std" ] 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<_>>() } diff --git a/benchmarking/src/tests.rs b/benchmarking/src/tests.rs index 89ee0e7ff..1b2c5d3ec 100644 --- a/benchmarking/src/tests.rs +++ b/benchmarking/src/tests.rs @@ -29,7 +29,6 @@ pub mod test { pub(crate) type Value = StorageValue<_, u32, OptionQuery>; #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); #[pallet::call] diff --git a/currencies/Cargo.toml b/currencies/Cargo.toml index b5263b85c..33f56460d 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.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } 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.36" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } orml_tokens = { package = "orml-tokens", path = "../tokens", version = "0.4.1-dev" } diff --git a/currencies/src/default_weight.rs b/currencies/src/default_weight.rs index 2054fd152..c0fb92770 100644 --- a/currencies/src/default_weight.rs +++ b/currencies/src/default_weight.rs @@ -8,22 +8,22 @@ use frame_support::weights::{constants::RocksDbWeight as DbWeight, Weight}; impl crate::WeightInfo for () { fn transfer_non_native_currency() -> Weight { - Weight::from_ref_time(172_011_000) + Weight::from_parts(172_011_000, 0) .saturating_add(DbWeight::get().reads(5 as u64)) .saturating_add(DbWeight::get().writes(2 as u64)) } fn transfer_native_currency() -> Weight { - Weight::from_ref_time(43_023_000) + Weight::from_parts(43_023_000, 0) } fn update_balance_non_native_currency() -> Weight { - Weight::from_ref_time(137_440_000) + Weight::from_parts(137_440_000, 0) .saturating_add(DbWeight::get().reads(5 as u64)) .saturating_add(DbWeight::get().writes(2 as u64)) } fn update_balance_native_currency_creating() -> Weight { - Weight::from_ref_time(64_432_000) + Weight::from_parts(64_432_000, 0) } fn update_balance_native_currency_killing() -> Weight { - Weight::from_ref_time(62_595_000) + Weight::from_parts(62_595_000, 0) } } diff --git a/currencies/src/mock.rs b/currencies/src/mock.rs index 469c1c14d..6a5ab75f8 100644 --- a/currencies/src/mock.rs +++ b/currencies/src/mock.rs @@ -160,6 +160,7 @@ impl Default for ExtBuilder { } } + impl ExtBuilder { pub fn balances(mut self, balances: Vec<(AccountId, CurrencyId, Balance)>) -> Self { self.balances = balances; diff --git a/currencies/src/weights.rs b/currencies/src/weights.rs index 619190ddb..d6119781f 100644 --- a/currencies/src/weights.rs +++ b/currencies/src/weights.rs @@ -40,27 +40,27 @@ pub trait WeightInfo { /// Default weights. impl WeightInfo for () { fn transfer_non_native_currency() -> Weight { - Weight::from_ref_time(60_000_000) + Weight::from_parts(60_000_000, 0) .saturating_add(RocksDbWeight::get().reads(5 as u64)) .saturating_add(RocksDbWeight::get().writes(4 as u64)) } fn transfer_native_currency() -> Weight { - Weight::from_ref_time(60_000_000) + Weight::from_parts(60_000_000, 0) .saturating_add(RocksDbWeight::get().reads(3 as u64)) .saturating_add(RocksDbWeight::get().writes(2 as u64)) } fn update_balance_non_native_currency() -> Weight { - Weight::from_ref_time(29_000_000) + Weight::from_parts(29_000_000, 0) .saturating_add(RocksDbWeight::get().reads(3 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } fn update_balance_native_currency_creating() -> Weight { - Weight::from_ref_time(31_000_000) + Weight::from_parts(31_000_000, 0) .saturating_add(RocksDbWeight::get().reads(1 as u64)) .saturating_add(RocksDbWeight::get().writes(1 as u64)) } fn update_balance_native_currency_killing() -> Weight { - Weight::from_ref_time(37_000_000) + Weight::from_parts(37_000_000, 0) .saturating_add(RocksDbWeight::get().reads(3 as u64)) .saturating_add(RocksDbWeight::get().writes(2 as u64)) } diff --git a/gradually-update/Cargo.toml b/gradually-update/Cargo.toml index 5a91690bd..7d9539690 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.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } [features] default = ["std"] diff --git a/gradually-update/src/default_weight.rs b/gradually-update/src/default_weight.rs index 995666607..e2c0f35c4 100644 --- a/gradually-update/src/default_weight.rs +++ b/gradually-update/src/default_weight.rs @@ -8,18 +8,18 @@ use frame_support::weights::{constants::RocksDbWeight as DbWeight, Weight}; impl crate::WeightInfo for () { fn gradually_update() -> Weight { - Weight::from_ref_time(57_922_000) + Weight::from_parts(57_922_000, 0) .saturating_add(DbWeight::get().reads(2 as u64)) .saturating_add(DbWeight::get().writes(1 as u64)) } fn cancel_gradually_update() -> Weight { - Weight::from_ref_time(66_687_000) + Weight::from_parts(66_687_000, 0) .saturating_add(DbWeight::get().reads(1 as u64)) .saturating_add(DbWeight::get().writes(1 as u64)) } fn on_finalize(u: u32) -> Weight { - Weight::from_ref_time(37_067_000) - .saturating_add(Weight::from_ref_time(20_890_000).saturating_mul(u as u64)) + Weight::from_parts(37_067_000, 0) + .saturating_add(Weight::from_parts(20_890_000, 0).saturating_mul(u as u64)) .saturating_add(DbWeight::get().reads(3 as u64)) .saturating_add(DbWeight::get().writes(3 as u64)) } diff --git a/nft/Cargo.toml b/nft/Cargo.toml index 5c24f821d..1c1f1154d 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.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } [features] default = ["std"] diff --git a/nft/src/lib.rs b/nft/src/lib.rs index 06ec47375..e7398928f 100644 --- a/nft/src/lib.rs +++ b/nft/src/lib.rs @@ -188,7 +188,6 @@ pub mod module { } #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] #[pallet::without_storage_info] pub struct Pallet(_); diff --git a/oracle/Cargo.toml b/oracle/Cargo.toml index 9edb37cec..0734ea76f 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.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-application-crypto = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-application-crypto = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } 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.36" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } [features] default = ["std"] diff --git a/oracle/rpc/Cargo.toml b/oracle/rpc/Cargo.toml index 32d66dabd..2bbaed96c 100644 --- a/oracle/rpc/Cargo.toml +++ b/oracle/rpc/Cargo.toml @@ -9,11 +9,11 @@ description = "RPC module for orml-oracle." [dependencies] codec = { package = "parity-scale-codec", version = "3.0.0" } jsonrpsee = { version = "0.16.2", features = ["client", "server", "macros"] } -tracing = { version = "0.1.29" } -tracing-core = { version = "0.1.28" } +tracing = "0.1.29" +tracing-core = "0.1.28" -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } 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 183a8a10c..3b1c2d3f8 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.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +sp-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } [features] default = ["std"] diff --git a/oracle/rpc/src/lib.rs b/oracle/rpc/src/lib.rs index acf65fb18..bad779ff9 100644 --- a/oracle/rpc/src/lib.rs +++ b/oracle/rpc/src/lib.rs @@ -8,7 +8,7 @@ use jsonrpsee::{ }; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; -use sp_runtime::{generic::BlockId, traits::Block as BlockT}; +use sp_runtime::traits::Block as BlockT; pub use orml_oracle_rpc_runtime_api::OracleApi as OracleRuntimeApi; @@ -21,12 +21,14 @@ pub trait OracleApi { } /// Provides RPC methods to query oracle value. +#[deprecated(note = "please use `state_call` instead of RPC")] pub struct Oracle { /// Shared reference to the client. client: Arc, _marker: std::marker::PhantomData, } +#[allow(deprecated)] impl Oracle { /// Creates a new instance of the `Oracle` helper. pub fn new(client: Arc) -> Self { @@ -50,6 +52,7 @@ impl From for i32 { } #[async_trait] +#[allow(deprecated)] impl OracleApiServer<::Hash, ProviderId, Key, Value> for Oracle where @@ -67,9 +70,9 @@ where at: Option<::Hash>, ) -> RpcResult> { let api = self.client.runtime_api(); - let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash)); + let at = at.unwrap_or_else(|| self.client.info().best_hash); - api.get_value(&at, provider_id, key).map_err(|e| { + api.get_value(at, provider_id, key).map_err(|e| { CallError::Custom(ErrorObject::owned( Error::RuntimeError.into(), "Unable to get value.", @@ -85,9 +88,9 @@ where at: Option<::Hash>, ) -> RpcResult)>> { let api = self.client.runtime_api(); - let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash)); + let at = at.unwrap_or_else(|| self.client.info().best_hash); - api.get_all_values(&at, provider_id).map_err(|e| { + api.get_all_values(at, provider_id).map_err(|e| { CallError::Custom(ErrorObject::owned( Error::RuntimeError.into(), "Unable to get all values.", diff --git a/oracle/src/lib.rs b/oracle/src/lib.rs index 1ee385602..42568d868 100644 --- a/oracle/src/lib.rs +++ b/oracle/src/lib.rs @@ -134,7 +134,6 @@ pub mod module { StorageValue<_, OrderedSet, ValueQuery>; #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(PhantomData<(T, I)>); #[pallet::hooks] diff --git a/oracle/src/weights.rs b/oracle/src/weights.rs index b1458bb3c..32bf28792 100644 --- a/oracle/src/weights.rs +++ b/oracle/src/weights.rs @@ -37,15 +37,15 @@ pub trait WeightInfo { /// Default weights. impl WeightInfo for () { fn feed_values(c: u32, ) -> Weight { - Weight::from_ref_time(16_800_000) + Weight::from_parts(16_800_000, 0) // Standard Error: 84_000 - .saturating_add(Weight::from_ref_time(3_600_000).saturating_mul(c as u64)) + .saturating_add(Weight::from_parts(3_600_000, 0).saturating_mul(c as u64)) .saturating_add(RocksDbWeight::get().reads(3 as u64)) .saturating_add(RocksDbWeight::get().writes(1 as u64)) .saturating_add(RocksDbWeight::get().writes((2 as u64).saturating_mul(c as u64))) } fn on_finalize() -> Weight { - Weight::from_ref_time(3_000_000) + Weight::from_parts(3_000_000, 0) .saturating_add(RocksDbWeight::get().writes(1 as u64)) } } diff --git a/payments/Cargo.toml b/payments/Cargo.toml index 1a6e07778..a611e79e2 100644 --- a/payments/Cargo.toml +++ b/payments/Cargo.toml @@ -1,5 +1,3 @@ -[workspace] - [package] authors = ["Virto Network "] edition = '2021' @@ -16,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.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } orml-traits = {path = "../traits", version = "0.4.1-dev", default-features = false } [dev-dependencies] -serde = { version = "1.0.136" } +serde = "1.0.136" -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } orml-tokens = { path = "../tokens", version = "0.4.1-dev", default-features = false } @@ -48,8 +46,3 @@ try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", ] - -try-runtime = [ - "frame-system/try-runtime", - "frame-support/try-runtime", -] diff --git a/payments/src/lib.rs b/payments/src/lib.rs index 9f14d1927..fc012e4d6 100644 --- a/payments/src/lib.rs +++ b/payments/src/lib.rs @@ -128,7 +128,6 @@ pub mod pallet { } #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); #[pallet::storage] diff --git a/payments/src/mock.rs b/payments/src/mock.rs index 53bc87e3c..7319c20cf 100644 --- a/payments/src/mock.rs +++ b/payments/src/mock.rs @@ -183,7 +183,7 @@ pub fn run_n_blocks(n: u64) -> u64 { }; // ensure the on_idle is executed >::register_extra_weight_unchecked( - Payment::on_idle(block_number, frame_support::weights::Weight::from_ref_time(idle_weight)), + Payment::on_idle(block_number, frame_support::weights::Weight::from_parts(idle_weight, 0)), DispatchClass::Mandatory, ); diff --git a/payments/src/weights.rs b/payments/src/weights.rs index 857953482..242210142 100644 --- a/payments/src/weights.rs +++ b/payments/src/weights.rs @@ -51,14 +51,14 @@ impl WeightInfo for SubstrateWeight { // Storage: Assets Accounts (r:2 w:2) // Storage: System Account (r:1 w:1) fn pay(_x: u32, ) -> Weight { - Weight::from_ref_time(55_900_000) + Weight::from_parts(55_900_000, 0) .saturating_add(T::DbWeight::get().reads(5 as u64)) .saturating_add(T::DbWeight::get().writes(4 as u64)) } // Storage: Payment Payment (r:1 w:1) // Storage: Assets Accounts (r:2 w:2) fn release() -> Weight { - Weight::from_ref_time(36_000_000) + Weight::from_parts(36_000_000, 0) .saturating_add(T::DbWeight::get().reads(3 as u64)) .saturating_add(T::DbWeight::get().writes(3 as u64)) } @@ -66,35 +66,35 @@ impl WeightInfo for SubstrateWeight { // Storage: Assets Accounts (r:2 w:2) // Storage: System Account (r:1 w:0) fn cancel() -> Weight { - Weight::from_ref_time(48_000_000) + Weight::from_parts(48_000_000, 0) .saturating_add(T::DbWeight::get().reads(4 as u64)) .saturating_add(T::DbWeight::get().writes(3 as u64)) } // Storage: Payment Payment (r:1 w:1) // Storage: Assets Accounts (r:2 w:2) fn resolve_payment() -> Weight { - Weight::from_ref_time(35_000_000) + Weight::from_parts(35_000_000, 0) .saturating_add(T::DbWeight::get().reads(3 as u64)) .saturating_add(T::DbWeight::get().writes(3 as u64)) } // Storage: Payment Payment (r:1 w:1) // Storage: Payment ScheduledTasks (r:1 w:1) fn request_refund() -> Weight { - Weight::from_ref_time(20_000_000) + Weight::from_parts(20_000_000, 0) .saturating_add(T::DbWeight::get().reads(2 as u64)) .saturating_add(T::DbWeight::get().writes(2 as u64)) } // Storage: Payment Payment (r:1 w:1) // Storage: Payment ScheduledTasks (r:1 w:1) fn dispute_refund() -> Weight { - Weight::from_ref_time(21_000_000) + Weight::from_parts(21_000_000, 0) .saturating_add(T::DbWeight::get().reads(2 as u64)) .saturating_add(T::DbWeight::get().writes(2 as u64)) } // Storage: Payment Payment (r:1 w:1) // Storage: Sudo Key (r:1 w:0) fn request_payment() -> Weight { - Weight::from_ref_time(17_000_000) + Weight::from_parts(17_000_000, 0) .saturating_add(T::DbWeight::get().reads(2 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } @@ -102,13 +102,13 @@ impl WeightInfo for SubstrateWeight { // Storage: Assets Accounts (r:2 w:2) // Storage: System Account (r:1 w:1) fn accept_and_pay() -> Weight { - Weight::from_ref_time(58_000_000) + Weight::from_parts(58_000_000, 0) .saturating_add(T::DbWeight::get().reads(4 as u64)) .saturating_add(T::DbWeight::get().writes(4 as u64)) } // Storage: Payment ScheduledTasks (r:1 w:1) fn remove_task() -> Weight { - Weight::from_ref_time(4_000_000) + Weight::from_parts(4_000_000, 0) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } @@ -121,14 +121,14 @@ impl WeightInfo for () { // Storage: Assets Accounts (r:2 w:2) // Storage: System Account (r:1 w:1) fn pay(_x: u32, ) -> Weight { - Weight::from_ref_time(55_900_000) + Weight::from_parts(55_900_000, 0) .saturating_add(RocksDbWeight::get().reads(5 as u64)) .saturating_add(RocksDbWeight::get().writes(4 as u64)) } // Storage: Payment Payment (r:1 w:1) // Storage: Assets Accounts (r:2 w:2) fn release() -> Weight { - Weight::from_ref_time(36_000_000) + Weight::from_parts(36_000_000, 0) .saturating_add(RocksDbWeight::get().reads(3 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } @@ -136,35 +136,35 @@ impl WeightInfo for () { // Storage: Assets Accounts (r:2 w:2) // Storage: System Account (r:1 w:0) fn cancel() -> Weight { - Weight::from_ref_time(48_000_000) + Weight::from_parts(48_000_000, 0) .saturating_add(RocksDbWeight::get().reads(4 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } // Storage: Payment Payment (r:1 w:1) // Storage: Assets Accounts (r:2 w:2) fn resolve_payment() -> Weight { - Weight::from_ref_time(35_000_000) + Weight::from_parts(35_000_000, 0) .saturating_add(RocksDbWeight::get().reads(3 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } // Storage: Payment Payment (r:1 w:1) // Storage: Payment ScheduledTasks (r:1 w:1) fn request_refund() -> Weight { - Weight::from_ref_time(20_000_000) + Weight::from_parts(20_000_000, 0) .saturating_add(RocksDbWeight::get().reads(2 as u64)) .saturating_add(RocksDbWeight::get().writes(2 as u64)) } // Storage: Payment Payment (r:1 w:1) // Storage: Payment ScheduledTasks (r:1 w:1) fn dispute_refund() -> Weight { - Weight::from_ref_time(21_000_000) + Weight::from_parts(21_000_000, 0) .saturating_add(RocksDbWeight::get().reads(2 as u64)) .saturating_add(RocksDbWeight::get().writes(2 as u64)) } // Storage: Payment Payment (r:1 w:1) // Storage: Sudo Key (r:1 w:0) fn request_payment() -> Weight { - Weight::from_ref_time(17_000_000) + Weight::from_parts(17_000_000, 0) .saturating_add(RocksDbWeight::get().reads(2 as u64)) .saturating_add(RocksDbWeight::get().writes(1 as u64)) } @@ -172,14 +172,14 @@ impl WeightInfo for () { // Storage: Assets Accounts (r:2 w:2) // Storage: System Account (r:1 w:1) fn accept_and_pay() -> Weight { - Weight::from_ref_time(58_000_000) + Weight::from_parts(58_000_000, 0) .saturating_add(RocksDbWeight::get().reads(4 as u64)) .saturating_add(RocksDbWeight::get().writes(4 as u64)) } // Storage: Payment ScheduledTasks (r:1 w:1) fn remove_task() -> Weight { - Weight::from_ref_time(4_000_000) + Weight::from_parts(4_000_000, 0) .saturating_add(RocksDbWeight::get().reads(1 as u64)) .saturating_add(RocksDbWeight::get().writes(1 as u64)) } -} \ No newline at end of file +} diff --git a/rewards/Cargo.toml b/rewards/Cargo.toml index dad1b52c5..5b65a24d8 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.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } 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.36" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } [features] default = ["std"] diff --git a/rewards/src/lib.rs b/rewards/src/lib.rs index f395f9506..b24063c39 100644 --- a/rewards/src/lib.rs +++ b/rewards/src/lib.rs @@ -112,7 +112,6 @@ pub mod module { >; #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] #[pallet::without_storage_info] pub struct Pallet(_); diff --git a/scripts/run-clippy.sh b/scripts/run-clippy.sh index a172ae411..e11fed87a 100755 --- a/scripts/run-clippy.sh +++ b/scripts/run-clippy.sh @@ -6,7 +6,7 @@ COMMAND=$1 ALLOW_CLIPPY_RULES=( "clippy::identity_op" # this helps the code to be consistant - "clippy::blacklisted-name" # TODO: allow them in test only + "clippy::disallowed_names" # TODO: allow them in test only "clippy::ptr-arg" # TODO: decide if we want to fix those "clippy::match_single_binding" # TODO: fix those ) diff --git a/tokens/Cargo.toml b/tokens/Cargo.toml index 590d01bd2..19461a9e3 100644 --- a/tokens/Cargo.toml +++ b/tokens/Cargo.toml @@ -12,20 +12,20 @@ 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.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } mangata-types = { git="https://github.com/mangata-finance/substrate", branch = "mangata-dev", default-features = false, version = '0.1.0' } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } [dev-dependencies] -pallet-elections-phragmen = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-elections-phragmen = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } [features] default = ["std"] @@ -45,10 +45,11 @@ std = [ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", - "frame-benchmarking/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks" ] try-runtime = [ - "frame-system/try-runtime", "frame-support/try-runtime", - "sp-runtime/runtime-benchmarks", + "frame-system/try-runtime", + "sp-runtime/runtime-benchmarks" ] diff --git a/tokens/rpc/Cargo.toml b/tokens/rpc/Cargo.toml index b873b2ebc..a488c180c 100644 --- a/tokens/rpc/Cargo.toml +++ b/tokens/rpc/Cargo.toml @@ -9,14 +9,14 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.0.0" } jsonrpsee = { version = "0.16.2", features = ["client", "server", "macros"] } -tracing = { version = "0.1.29" } -tracing-core = { version = "0.1.28" } +tracing = "0.1.29" +tracing-core = "0.1.28" -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } 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 3d8491ce8..15eb31365 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.36" } -sp-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } orml-tokens = { default-features = false, path = "../../../tokens" } [features] diff --git a/tokens/rpc/src/lib.rs b/tokens/rpc/src/lib.rs index 81efda106..df10d8692 100644 --- a/tokens/rpc/src/lib.rs +++ b/tokens/rpc/src/lib.rs @@ -10,10 +10,7 @@ use jsonrpsee::{ use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_rpc::number::NumberOrHex; -use sp_runtime::{ - generic::BlockId, - traits::{Block as BlockT, MaybeDisplay}, -}; +use sp_runtime::traits::{Block as BlockT, MaybeDisplay}; pub use orml_tokens_rpc_runtime_api::TokensApi as TokensRuntimeApi; @@ -24,12 +21,14 @@ pub trait TokensApi { } /// Provides RPC methods to query existential deposit of currency. +#[deprecated(note = "please use `state_call` instead of RPC")] pub struct Tokens { /// Shared reference to the client. client: Arc, _marker: std::marker::PhantomData

, } +#[allow(deprecated)] impl Tokens { /// Creates a new instance of the `Tokens` helper. pub fn new(client: Arc) -> Self { @@ -55,6 +54,7 @@ impl From for i32 { } #[async_trait] +#[allow(deprecated)] impl TokensApiServer<::Hash, CurrencyId, Balance> for Tokens where Block: BlockT, @@ -69,9 +69,9 @@ where at: Option<::Hash>, ) -> RpcResult { let api = self.client.runtime_api(); - let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash)); + let at = at.unwrap_or_else(|| self.client.info().best_hash); - let balance = api.query_existential_deposit(&at, currency_id).map_err(|e| { + let balance = api.query_existential_deposit(at, currency_id).map_err(|e| { CallError::Custom(ErrorObject::owned( Error::RuntimeError.into(), "Unable to query existential deposit.", diff --git a/tokens/src/lib.rs b/tokens/src/lib.rs index dcf8f4808..e8cc46e90 100644 --- a/tokens/src/lib.rs +++ b/tokens/src/lib.rs @@ -376,6 +376,18 @@ pub mod module { Issued(T::CurrencyId, T::AccountId, T::Balance), /// A token was minted. Minted(T::CurrencyId, T::AccountId, T::Balance), + /// Some free balance was locked. + Locked { + currency_id: T::CurrencyId, + who: T::AccountId, + amount: T::Balance, + }, + /// Some locked balance was freed. + Unlocked { + currency_id: T::CurrencyId, + who: T::AccountId, + amount: T::Balance, + }, } /// The total issuance of a token type. @@ -489,7 +501,6 @@ pub mod module { } #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); #[pallet::hooks] @@ -920,12 +931,18 @@ impl Pallet { who: &T::AccountId, locks: &[BalanceLock], ) -> DispatchResult { + // track lock delta + let mut total_frozen_prev = Zero::zero(); + let mut total_frozen_after = Zero::zero(); + // update account data Self::mutate_account(who, currency_id, |account, _| { + total_frozen_prev = account.frozen; account.frozen = Zero::zero(); for lock in locks.iter() { account.frozen = account.frozen.max(lock.amount); } + total_frozen_after = account.frozen; }); // update locks @@ -954,6 +971,22 @@ impl Pallet { } } + if total_frozen_prev < total_frozen_after { + let amount = total_frozen_after.saturating_sub(total_frozen_prev); + Self::deposit_event(Event::Locked { + currency_id, + who: who.clone(), + amount, + }); + } else if total_frozen_prev > total_frozen_after { + let amount = total_frozen_prev.saturating_sub(total_frozen_after); + Self::deposit_event(Event::Unlocked { + currency_id, + who: who.clone(), + amount, + }); + } + Ok(()) } diff --git a/tokens/src/mock.rs b/tokens/src/mock.rs index feb85e898..e3066e6ca 100644 --- a/tokens/src/mock.rs +++ b/tokens/src/mock.rs @@ -198,6 +198,7 @@ impl pallet_elections_phragmen::Config for Runtime { type DesiredRunnersUp = ConstU32<2>; type MaxCandidates = ConstU32<5>; type MaxVoters = ConstU32<5>; + type MaxVotesPerVoter = (); type LoserCandidate = (); type KickedMember = (); type WeightInfo = (); diff --git a/tokens/src/tests_events.rs b/tokens/src/tests_events.rs index 07896f866..eca7e4c22 100644 --- a/tokens/src/tests_events.rs +++ b/tokens/src/tests_events.rs @@ -6,6 +6,12 @@ use super::*; use frame_support::assert_ok; use mock::*; +fn events() -> Vec { + let evt = System::events().into_iter().map(|evt| evt.event).collect::>(); + System::reset_events(); + evt +} + #[test] fn pallet_multicurrency_deposit_events() { ExtBuilder::default() @@ -300,3 +306,98 @@ fn currency_adapter_pallet_currency_deposit_events() { })); }); } + +#[test] +fn pallet_change_locks_events() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(Tokens::do_deposit(DOT, &ALICE, 100, false, false)); + assert_ok!(Tokens::do_deposit(BTC, &ALICE, 100, false, false)); + System::reset_events(); + + // Locks: [10/DOT] + assert_ok!(Tokens::set_lock(ID_1, DOT, &ALICE, 10)); + assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::Locked { + currency_id: DOT, + who: ALICE, + amount: 10 + }))); + + // Locks: [15/DOT] + assert_ok!(Tokens::set_lock(ID_1, DOT, &ALICE, 15)); + assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::Locked { + currency_id: DOT, + who: ALICE, + amount: 5 + }))); + + // Locks: [15/DOT, 20/BTC] + assert_ok!(Tokens::set_lock(ID_1, BTC, &ALICE, 20)); + assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::Locked { + currency_id: BTC, + who: ALICE, + amount: 20 + }))); + + // Locks: [15/DOT, 20/BTC, 10/DOT] + assert_ok!(Tokens::set_lock(ID_2, DOT, &ALICE, 10)); + for event in events() { + match event { + RuntimeEvent::Tokens(crate::Event::Locked { .. }) => assert!(false, "unexpected lock event"), + RuntimeEvent::Tokens(crate::Event::Unlocked { .. }) => assert!(false, "unexpected unlock event"), + _ => continue, + } + } + + // Locks: [15/DOT, 20/BTC, 12/DOT] + assert_ok!(Tokens::set_lock(ID_2, DOT, &ALICE, 12)); + for event in events() { + match event { + RuntimeEvent::Tokens(crate::Event::Locked { .. }) => assert!(false, "unexpected lock event"), + RuntimeEvent::Tokens(crate::Event::Unlocked { .. }) => assert!(false, "unexpected unlock event"), + _ => continue, + } + } + + // Locks: [15/DOT, 20/BTC, 10/DOT] + assert_ok!(Tokens::set_lock(ID_2, DOT, &ALICE, 10)); + for event in events() { + match event { + RuntimeEvent::Tokens(crate::Event::Locked { .. }) => assert!(false, "unexpected lock event"), + RuntimeEvent::Tokens(crate::Event::Unlocked { .. }) => assert!(false, "unexpected unlock event"), + _ => continue, + } + } + + // Locks: [15/DOT, 20/BTC, 20/DOT] + assert_ok!(Tokens::set_lock(ID_2, DOT, &ALICE, 20)); + assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::Locked { + currency_id: DOT, + who: ALICE, + amount: 5 + }))); + + // Locks: [15/DOT, 20/BTC, 16/DOT] + assert_ok!(Tokens::set_lock(ID_2, DOT, &ALICE, 16)); + assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::Unlocked { + currency_id: DOT, + who: ALICE, + amount: 4 + }))); + + // Locks: [15/DOT, 12/BTC, 16/DOT] + assert_ok!(Tokens::set_lock(ID_1, BTC, &ALICE, 12)); + assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::Unlocked { + currency_id: BTC, + who: ALICE, + amount: 8 + }))); + + // Locks: [15/DOT, 12/BTC] + assert_ok!(Tokens::remove_lock(ID_2, DOT, &ALICE)); + assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::Unlocked { + currency_id: DOT, + who: ALICE, + amount: 1 + }))); + }); +} diff --git a/tokens/src/weights.rs b/tokens/src/weights.rs index 71143fe60..994c69440 100644 --- a/tokens/src/weights.rs +++ b/tokens/src/weights.rs @@ -41,39 +41,39 @@ pub trait WeightInfo { /// Default weights. impl WeightInfo for () { fn transfer() -> Weight { - Weight::from_ref_time(69_000_000) + Weight::from_parts(69_000_000, 0) .saturating_add(RocksDbWeight::get().reads(5 as u64)) .saturating_add(RocksDbWeight::get().writes(4 as u64)) } fn transfer_all() -> Weight { - Weight::from_ref_time(69_000_000) + Weight::from_parts(69_000_000, 0) .saturating_add(RocksDbWeight::get().reads(5 as u64)) .saturating_add(RocksDbWeight::get().writes(4 as u64)) } fn transfer_keep_alive() -> Weight { - Weight::from_ref_time(38_000_000) + Weight::from_parts(38_000_000, 0) .saturating_add(RocksDbWeight::get().reads(3 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } fn force_transfer() -> Weight { - Weight::from_ref_time(45_000_000) + Weight::from_parts(45_000_000, 0) .saturating_add(RocksDbWeight::get().reads(4 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } fn set_balance() -> Weight { - Weight::from_ref_time(34_000_000) + Weight::from_parts(34_000_000, 0) .saturating_add(RocksDbWeight::get().reads(3 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } // tmp fn create() -> Weight { - Weight::from_ref_time(69_000_000) + Weight::from_parts(69_000_000, 0) .saturating_add(RocksDbWeight::get().reads(5 as u64)) .saturating_add(RocksDbWeight::get().writes(4 as u64)) } // tmp fn mint() -> Weight { - Weight::from_ref_time(69_000_000) + Weight::from_parts(69_000_000, 0) .saturating_add(RocksDbWeight::get().reads(5 as u64)) .saturating_add(RocksDbWeight::get().writes(4 as u64)) } diff --git a/traits/Cargo.toml b/traits/Cargo.toml index 7a7fa01d0..9887c83dc 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.36" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" } 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/asset_registry.rs b/traits/src/asset_registry.rs index a57c29cd7..98d411c7d 100644 --- a/traits/src/asset_registry.rs +++ b/traits/src/asset_registry.rs @@ -1,7 +1,7 @@ use frame_support::pallet_prelude::*; use sp_runtime::DispatchResult; use sp_std::vec::Vec; -use xcm::latest::prelude::*; +use xcm::v3::prelude::*; use xcm::VersionedMultiLocation; pub trait WeightToFeeConverter { diff --git a/traits/src/lib.rs b/traits/src/lib.rs index ea5231dd9..672c58231 100644 --- a/traits/src/lib.rs +++ b/traits/src/lib.rs @@ -24,7 +24,7 @@ pub use rewards::RewardHandler; use scale_info::TypeInfo; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; -pub use xcm_transfer::XcmTransfer; +pub use xcm_transfer::{XcmTransfer, XtokensWeightInfo}; pub mod arithmetic; pub mod asset_registry; diff --git a/traits/src/location.rs b/traits/src/location.rs index 14a3fe67f..aad202300 100644 --- a/traits/src/location.rs +++ b/traits/src/location.rs @@ -1,6 +1,5 @@ -use sp_runtime::{traits::ConstU32, WeakBoundedVec}; -use sp_std::prelude::*; -use xcm::latest::prelude::*; +use sp_core::{bounded::BoundedVec, ConstU32}; +use xcm::v3::prelude::*; pub trait Parse { /// Returns the "chain" location part. It could be parent, sibling @@ -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(); } @@ -78,12 +77,12 @@ 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>) -> MultiLocation; } 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>) -> MultiLocation { + return MultiLocation::new(1, X2(Parachain(para_id), general_key.as_bounded_slice().into())); } } @@ -139,14 +138,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()) ); diff --git a/traits/src/multi_asset.rs b/traits/src/multi_asset.rs index d7c7dd807..3697467fc 100644 --- a/traits/src/multi_asset.rs +++ b/traits/src/multi_asset.rs @@ -1,20 +1,15 @@ -use sp_runtime::{traits::ConstU32, WeakBoundedVec}; -use xcm::latest::prelude::*; +use sp_core::{bounded::BoundedVec, ConstU32}; +use xcm::v3::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) -> MultiAsset; fn parent_asset(amount: u128) -> MultiAsset; } impl ConcreteFungibleAsset for MultiAsset { - 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) -> MultiAsset { ( MultiLocation::sibling_parachain_general_key(para_id, general_key), amount, diff --git a/traits/src/xcm_transfer.rs b/traits/src/xcm_transfer.rs index c4dacb116..4426c67cf 100644 --- a/traits/src/xcm_transfer.rs +++ b/traits/src/xcm_transfer.rs @@ -1,31 +1,84 @@ -use frame_support::dispatch::DispatchResult; -use xcm::latest::prelude::*; +use frame_support::dispatch::DispatchError; +use sp_std::vec::Vec; +use xcm::{ + v3::{prelude::*, Weight}, + VersionedMultiAsset, VersionedMultiAssets, VersionedMultiLocation, +}; +pub struct Transferred { + pub sender: AccountId, + pub assets: MultiAssets, + pub fee: MultiAsset, + pub dest: MultiLocation, +} /// Abstraction over cross-chain token transfers. pub trait XcmTransfer { - /// Transfer native currencies. + /// Transfer local assets with given `CurrencyId` and `Amount`. fn transfer( who: AccountId, currency_id: CurrencyId, amount: Balance, dest: MultiLocation, dest_weight_limit: WeightLimit, - ) -> DispatchResult; + ) -> Result, DispatchError>; - /// Transfer `MultiAsset` - fn transfer_multi_asset( + /// Transfer `MultiAsset` assets. + fn transfer_multiasset( who: AccountId, asset: MultiAsset, dest: MultiLocation, dest_weight_limit: WeightLimit, - ) -> DispatchResult; + ) -> Result, DispatchError>; - /// Transfer `MultiAssetWithFee` + /// Transfer native currencies specifying the fee and amount as separate. + fn transfer_with_fee( + who: AccountId, + currency_id: CurrencyId, + amount: Balance, + fee: Balance, + dest: MultiLocation, + dest_weight_limit: WeightLimit, + ) -> Result, DispatchError>; + + /// Transfer `MultiAsset` specifying the fee and amount as separate. fn transfer_multiasset_with_fee( who: AccountId, asset: MultiAsset, fee: MultiAsset, dest: MultiLocation, dest_weight_limit: WeightLimit, - ) -> DispatchResult; + ) -> Result, DispatchError>; + + /// Transfer several currencies specifying the item to be used as fee. + fn transfer_multicurrencies( + who: AccountId, + currencies: Vec<(CurrencyId, Balance)>, + fee_item: u32, + dest: MultiLocation, + dest_weight_limit: WeightLimit, + ) -> Result, DispatchError>; + + /// Transfer several `MultiAsset` specifying the item to be used as fee. + fn transfer_multiassets( + who: AccountId, + assets: MultiAssets, + fee: MultiAsset, + dest: MultiLocation, + dest_weight_limit: WeightLimit, + ) -> Result, DispatchError>; +} + +pub trait XtokensWeightInfo { + fn weight_of_transfer_multiasset(asset: &VersionedMultiAsset, dest: &VersionedMultiLocation) -> Weight; + fn weight_of_transfer(currency_id: CurrencyId, amount: Balance, dest: &VersionedMultiLocation) -> Weight; + fn weight_of_transfer_multicurrencies( + currencies: &[(CurrencyId, Balance)], + fee_item: &u32, + dest: &VersionedMultiLocation, + ) -> Weight; + fn weight_of_transfer_multiassets( + assets: &VersionedMultiAssets, + fee_item: &u32, + dest: &VersionedMultiLocation, + ) -> Weight; } diff --git a/unknown-tokens/Cargo.toml b/unknown-tokens/Cargo.toml index e8a10eaaa..2a293ecbc 100644 --- a/unknown-tokens/Cargo.toml +++ b/unknown-tokens/Cargo.toml @@ -12,18 +12,19 @@ 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.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" } orml-xcm-support = { path = "../xcm-support", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +hex-literal = "0.3.1" [features] default = ["std"] diff --git a/unknown-tokens/src/lib.rs b/unknown-tokens/src/lib.rs index be7fee5d2..c0ba1da7d 100644 --- a/unknown-tokens/src/lib.rs +++ b/unknown-tokens/src/lib.rs @@ -3,7 +3,7 @@ use frame_support::pallet_prelude::*; use sp_std::vec::Vec; -use xcm::latest::prelude::*; +use xcm::v3::prelude::*; use orml_xcm_support::UnknownAsset; @@ -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,10 @@ 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(_); @@ -83,7 +88,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(()) }), @@ -92,7 +97,7 @@ impl UnknownAsset for Pallet { Self::deposit_event(Event::Deposited { asset: asset.clone(), - who: to.clone(), + who: *to, }); Ok(()) @@ -110,7 +115,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(()) }), @@ -119,7 +124,7 @@ impl UnknownAsset for Pallet { Self::deposit_event(Event::Withdrawn { asset: asset.clone(), - who: from.clone(), + who: *from, }); Ok(()) diff --git a/unknown-tokens/src/migrations.rs b/unknown-tokens/src/migrations.rs new file mode 100644 index 000000000..9c866d30c --- /dev/null +++ b/unknown-tokens/src/migrations.rs @@ -0,0 +1,86 @@ +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() + .collect::>(); + + 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() + .collect::>(); + + 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 236d7f1fe..66d573cc6 100644 --- a/unknown-tokens/src/tests.rs +++ b/unknown-tokens/src/tests.rs @@ -5,13 +5,20 @@ 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}, + unhashed::put_raw, + }, + traits::OnRuntimeUpgrade, +}; 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 +58,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 +73,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 +122,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 { @@ -151,3 +158,107 @@ 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()); + }); +} + +#[test] +fn migrate_should_not_panic() { + ExtBuilder.build().execute_with(|| { + put_raw(&hex_literal::hex!["8d4649c9ee31ba6b2d10c66f5fcc252e76391a415c3fca956dccff701fe02e98082b3a7e1c0db7de23c07c6f14cc6c51000100411f728d113b5f9fee983dba4cbb22827c05000106080081"], &hex_literal::hex!["0b2493d4010000000000000000000000"]); + + crate::Migration::::on_runtime_upgrade(); + }); +} diff --git a/utilities/Cargo.toml b/utilities/Cargo.toml index be4e2dae5..7eaf04142 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.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } [dev-dependencies] serde_json = "1.0.64" -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } [features] default = ["std"] diff --git a/utilities/src/iterator.rs b/utilities/src/iterator.rs deleted file mode 100644 index c2e26c639..000000000 --- a/utilities/src/iterator.rs +++ /dev/null @@ -1,336 +0,0 @@ -use codec::{Decode, EncodeLike, FullCodec, FullEncode}; -use frame_support::{ - storage::{ - generator::{StorageDoubleMap as StorageDoubleMapT, StorageMap as StorageMapT}, - unhashed, StorageDoubleMap, StorageMap, - }, - ReversibleStorageHasher, -}; -use sp_std::prelude::*; - -/// Utility to iterate through items in a storage map. -/// Forks from substrate, expose previous_key field -pub struct StorageMapIterator { - prefix: Vec, - pub previous_key: Vec, - drain: bool, - _phantom: sp_std::marker::PhantomData<(K, V, Hasher)>, -} - -/// Forks from substrate -impl Iterator - for StorageMapIterator -{ - type Item = (K, V); - - fn next(&mut self) -> Option<(K, V)> { - loop { - let maybe_next = sp_io::storage::next_key(&self.previous_key).filter(|n| n.starts_with(&self.prefix)); - break match maybe_next { - Some(next) => { - self.previous_key = next; - match unhashed::get::(&self.previous_key) { - Some(value) => { - if self.drain { - unhashed::kill(&self.previous_key) - } - let mut key_material = Hasher::reverse(&self.previous_key[self.prefix.len()..]); - match K::decode(&mut key_material) { - Ok(key) => Some((key, value)), - Err(_) => continue, - } - } - None => continue, - } - } - None => None, - }; - } - } -} - -/// Shim for StorageMapIterator, add more features -pub struct StorageMapIteratorShim { - pub storage_map_iterator: StorageMapIterator, - pub remain_iterator_count: Option, - pub finished: bool, -} - -impl Iterator for StorageMapIteratorShim { - type Item = as Iterator>::Item; - - fn next(&mut self) -> Option { - // check accumulated iteration count - if let Some(remain_iterator_count) = self.remain_iterator_count { - if remain_iterator_count == 0 { - return None; - } else { - self.remain_iterator_count = Some(remain_iterator_count - 1); - } - } - - self.storage_map_iterator.next().or_else(|| { - // mark this map iterator has already finished - self.finished = true; - None - }) - } -} - -/// A strongly-typed map in storage whose keys and values can be iterated over. -pub trait IterableStorageMapExtended: StorageMap { - /// The type that iterates over all `(key, value)`. - type Iterator: Iterator; - - /// Enumerate all elements in the map in no particular order. If you alter - /// the map while doing this, you'll get undefined results. - fn iter(max_iterations: Option, start_key: Option>) -> Self::Iterator; - - /// Remove all elements from the map and iterate through them in no - /// particular order. If you add elements to the map while doing this, - /// you'll get undefined results. - fn drain(max_iterations: Option, start_key: Option>) -> Self::Iterator; -} - -impl> IterableStorageMapExtended for G -where - G::Hasher: ReversibleStorageHasher, -{ - type Iterator = StorageMapIteratorShim; - - /// Enumerate all elements in the map. - fn iter(max_iterations: Option, start_key: Option>) -> Self::Iterator { - let prefix = G::prefix_hash(); - let previous_key = start_key - .filter(|k| k.starts_with(&prefix)) - .unwrap_or_else(|| prefix.clone()); - let storage_map_iterator = StorageMapIterator { - prefix, - previous_key, - drain: false, - _phantom: Default::default(), - }; - - StorageMapIteratorShim { - storage_map_iterator, - remain_iterator_count: max_iterations, - finished: false, - } - } - - /// Enumerate all elements in the map. - fn drain(max_iterations: Option, start_key: Option>) -> Self::Iterator { - let prefix = G::prefix_hash(); - - let previous_key = start_key - .filter(|k| k.starts_with(&prefix)) - .unwrap_or_else(|| prefix.clone()); - let storage_map_iterator = StorageMapIterator { - prefix, - previous_key, - drain: true, - _phantom: Default::default(), - }; - - StorageMapIteratorShim { - storage_map_iterator, - remain_iterator_count: max_iterations, - finished: false, - } - } -} - -/// Iterate over a prefix and decode raw_key and raw_value into `T`. -/// Forks from substrate, expose previous_key field -pub struct MapIterator { - prefix: Vec, - pub previous_key: Vec, - /// If true then value are removed while iterating - drain: bool, - /// Function that take `(raw_key_without_prefix, raw_value)` and decode `T`. - /// `raw_key_without_prefix` is the raw storage key without the prefix - /// iterated on. - closure: fn(&[u8], &[u8]) -> Result, -} - -/// Forks from substrate -impl Iterator for MapIterator { - type Item = T; - - fn next(&mut self) -> Option { - loop { - let maybe_next = sp_io::storage::next_key(&self.previous_key).filter(|n| n.starts_with(&self.prefix)); - break match maybe_next { - Some(next) => { - self.previous_key = next; - let raw_value = match unhashed::get_raw(&self.previous_key) { - Some(raw_value) => raw_value, - None => { - frame_support::print("ERROR: next_key returned a key with no value in MapIterator"); - continue; - } - }; - if self.drain { - unhashed::kill(&self.previous_key) - } - let raw_key_without_prefix = &self.previous_key[self.prefix.len()..]; - let item = match (self.closure)(raw_key_without_prefix, &raw_value[..]) { - Ok(item) => item, - Err(_e) => { - frame_support::print("ERROR: (key, value) failed to decode in MapIterator"); - continue; - } - }; - - Some(item) - } - None => None, - }; - } - } -} - -/// Shim for MapIterator, add more features -pub struct MapIteratorShim { - pub map_iterator: MapIterator, - pub remain_iterator_count: Option, - pub finished: bool, -} - -impl Iterator for MapIteratorShim { - type Item = as Iterator>::Item; - - fn next(&mut self) -> Option { - // check accumulated iteration count - if let Some(remain_iterator_count) = self.remain_iterator_count { - if remain_iterator_count == 0 { - return None; - } else { - self.remain_iterator_count = Some(remain_iterator_count - 1); - } - } - - self.map_iterator.next().or_else(|| { - // mark this map iterator has already finished - self.finished = true; - None - }) - } -} - -/// A strongly-typed map in storage whose keys and values can be iterated over. -pub trait IterableStorageDoubleMapExtended: - StorageDoubleMap -{ - /// The type that iterates over all `(key2, value)`. - type PrefixIterator: Iterator; - - /// The type that iterates over all `(key1, key2, value)`. - type Iterator: Iterator; - - /// Enumerate all elements in the map with first key `k1` in no particular - /// order. If you add or remove values whose first key is `k1` to the map - /// while doing this, you'll get undefined results. - fn iter_prefix( - k1: impl EncodeLike, - max_iterations: Option, - start_key: Option>, - ) -> Self::PrefixIterator; - - /// Remove all elements from the map with first key `k1` and iterate through - /// them in no particular order. If you add elements with first key `k1` to - /// the map while doing this, you'll get undefined results. - fn drain_prefix( - k1: impl EncodeLike, - max_iterations: Option, - start_key: Option>, - ) -> Self::PrefixIterator; - - /// Enumerate all elements in the map in no particular order. If you add or - /// remove values to the map while doing this, you'll get undefined results. - fn iter(max_iterations: Option, start_key: Option>) -> Self::Iterator; - - /// Remove all elements from the map and iterate through them in no - /// particular order. If you add elements to the map while doing this, - /// you'll get undefined results. - fn drain(max_iterations: Option, start_key: Option>) -> Self::Iterator; -} - -impl> - IterableStorageDoubleMapExtended for G -where - G::Hasher1: ReversibleStorageHasher, - G::Hasher2: ReversibleStorageHasher, -{ - type PrefixIterator = MapIteratorShim<(K2, V)>; - type Iterator = MapIteratorShim<(K1, K2, V)>; - - fn iter_prefix( - k1: impl EncodeLike, - max_iterations: Option, - start_key: Option>, - ) -> Self::PrefixIterator { - let prefix = G::storage_double_map_final_key1(k1); - let previous_key = start_key - .filter(|k| k.starts_with(&prefix)) - .unwrap_or_else(|| prefix.clone()); - - let map_iterator = MapIterator { - prefix, - previous_key, - drain: false, - closure: |raw_key_without_prefix, mut raw_value| { - let mut key_material = G::Hasher2::reverse(raw_key_without_prefix); - Ok((K2::decode(&mut key_material)?, V::decode(&mut raw_value)?)) - }, - }; - - MapIteratorShim { - map_iterator, - remain_iterator_count: max_iterations, - finished: false, - } - } - - fn drain_prefix( - k1: impl EncodeLike, - max_iterations: Option, - start_key: Option>, - ) -> Self::PrefixIterator { - let mut shim = Self::iter_prefix(k1, max_iterations, start_key); - shim.map_iterator.drain = true; - shim - } - - fn iter(max_iterations: Option, start_key: Option>) -> Self::Iterator { - let prefix = G::prefix_hash(); - let previous_key = start_key - .filter(|k| k.starts_with(&prefix)) - .unwrap_or_else(|| prefix.clone()); - - let map_iterator = MapIterator { - prefix, - previous_key, - drain: false, - closure: |raw_key_without_prefix, mut raw_value| { - let mut k1_k2_material = G::Hasher1::reverse(raw_key_without_prefix); - let k1 = K1::decode(&mut k1_k2_material)?; - let mut k2_material = G::Hasher2::reverse(k1_k2_material); - let k2 = K2::decode(&mut k2_material)?; - Ok((k1, k2, V::decode(&mut raw_value)?)) - }, - }; - - MapIteratorShim { - map_iterator, - remain_iterator_count: max_iterations, - finished: false, - } - } - - fn drain(max_iterations: Option, start_key: Option>) -> Self::Iterator { - let mut shim = Self::iter(max_iterations, start_key); - shim.map_iterator.drain = true; - shim - } -} diff --git a/utilities/src/lib.rs b/utilities/src/lib.rs index a75ea1534..b63f2a2fd 100644 --- a/utilities/src/lib.rs +++ b/utilities/src/lib.rs @@ -4,17 +4,9 @@ use frame_support::storage::{with_transaction, TransactionOutcome}; use sp_runtime::DispatchError; use sp_std::result::Result; -#[deprecated( - since = "0.4.1", - note = "iterator module's functionality is now available in substrate's frame-support" -)] -pub mod iterator; pub mod offchain_worker; pub mod ordered_set; -#[allow(deprecated)] -pub use iterator::{IterableStorageDoubleMapExtended, IterableStorageMapExtended}; - pub use offchain_worker::OffchainErr; pub use ordered_set::OrderedSet; diff --git a/vesting/Cargo.toml b/vesting/Cargo.toml index f5f8115e5..ba54bece5 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.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } [dev-dependencies] -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } [features] default = ["std"] @@ -44,4 +44,3 @@ try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", ] - diff --git a/vesting/src/default_weight.rs b/vesting/src/default_weight.rs index d716ab759..42da01846 100644 --- a/vesting/src/default_weight.rs +++ b/vesting/src/default_weight.rs @@ -8,19 +8,19 @@ use frame_support::weights::{constants::RocksDbWeight as DbWeight, Weight}; impl crate::WeightInfo for () { fn vested_transfer() -> Weight { - Weight::from_ref_time(310_862_000) + Weight::from_parts(310_862_000, 0) .saturating_add(DbWeight::get().reads(4 as u64)) .saturating_add(DbWeight::get().writes(4 as u64)) } fn claim(i: u32) -> Weight { - Weight::from_ref_time(158_614_000) - .saturating_add(Weight::from_ref_time(958_000).saturating_mul(i as u64)) + Weight::from_parts(158_614_000, 0) + .saturating_add(Weight::from_parts(958_000, 0).saturating_mul(i as u64)) .saturating_add(DbWeight::get().reads(3 as u64)) .saturating_add(DbWeight::get().writes(3 as u64)) } fn update_vesting_schedules(i: u32) -> Weight { - Weight::from_ref_time(119_811_000) - .saturating_add(Weight::from_ref_time(2_320_000).saturating_mul(i as u64)) + Weight::from_parts(119_811_000, 0) + .saturating_add(Weight::from_parts(2_320_000, 0).saturating_mul(i as u64)) .saturating_add(DbWeight::get().reads(2 as u64)) .saturating_add(DbWeight::get().writes(3 as u64)) } 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/vesting/src/weights.rs b/vesting/src/weights.rs index 49c11e2ed..be6eb9ac0 100644 --- a/vesting/src/weights.rs +++ b/vesting/src/weights.rs @@ -38,21 +38,21 @@ pub trait WeightInfo { /// Default weights. impl WeightInfo for () { fn vested_transfer() -> Weight { - Weight::from_ref_time(69_000_000) + Weight::from_parts(69_000_000, 0) .saturating_add(RocksDbWeight::get().reads(4 as u64)) .saturating_add(RocksDbWeight::get().writes(4 as u64)) } fn claim(i: u32, ) -> Weight { - Weight::from_ref_time(31_747_000) + Weight::from_parts(31_747_000, 0) // Standard Error: 4_000 - .saturating_add(Weight::from_ref_time(63_000).saturating_mul(i as u64)) + .saturating_add(Weight::from_parts(63_000, 0).saturating_mul(i as u64)) .saturating_add(RocksDbWeight::get().reads(2 as u64)) .saturating_add(RocksDbWeight::get().writes(2 as u64)) } fn update_vesting_schedules(i: u32, ) -> Weight { - Weight::from_ref_time(29_457_000) + Weight::from_parts(29_457_000, 0) // Standard Error: 4_000 - .saturating_add(Weight::from_ref_time(117_000).saturating_mul(i as u64)) + .saturating_add(Weight::from_parts(117_000, 0).saturating_mul(i as u64)) .saturating_add(RocksDbWeight::get().reads(2 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } diff --git a/weight-gen/Cargo.toml b/weight-gen/Cargo.toml index d2d206196..a6162073c 100644 --- a/weight-gen/Cargo.toml +++ b/weight-gen/Cargo.toml @@ -10,7 +10,7 @@ edition = "2021" serde = { version = "1.0.136", features = ["derive"] } serde_json = "1.0" clap = "4.0.9" -handlebars = { version = "4.1.0" } +handlebars = "4.1.0" [features] default = ["std"] diff --git a/weight-gen/src/template.hbs b/weight-gen/src/template.hbs index 0f4233ebc..814dd60a8 100644 --- a/weight-gen/src/template.hbs +++ b/weight-gen/src/template.hbs @@ -17,7 +17,7 @@ impl ModuleWeights { // {{comment}} {{/each}} pub fn {{benchmark.name~}} () -> Weight { - Weight::from_ref_time({{underscore benchmark.weight}}) + Weight::from_parts({{underscore benchmark.weight}}, 0) {{#if (ne benchmark.reads 0)}} .saturating_add(T::DbWeight::get().reads({{benchmark.reads}})) {{/if}} diff --git a/weight-meter/Cargo.toml b/weight-meter/Cargo.toml index 7f9d38ca7..d526dc0de 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.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } weight-meter-procedural = { path = "weight-meter-procedural", default-features = false } [dev-dependencies] -serde = { version = "1.0.136" } +serde = "1.0.136" codec = { package = "parity-scale-codec", version = "3.0.0" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } orml-bencher = { path = "../bencher" } diff --git a/weight-meter/src/mock.rs b/weight-meter/src/mock.rs index 8126a377f..9af9d26fa 100644 --- a/weight-meter/src/mock.rs +++ b/weight-meter/src/mock.rs @@ -7,7 +7,6 @@ pub mod test_module { pub trait Config: frame_system::Config {} #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(PhantomData); #[pallet::hooks] diff --git a/weight-meter/src/tests.rs b/weight-meter/src/tests.rs index 3c261ee2e..eb95ce152 100644 --- a/weight-meter/src/tests.rs +++ b/weight-meter/src/tests.rs @@ -6,12 +6,12 @@ fn used_weight_works() { new_test_ext().execute_with(|| { let result: PostDispatchInfo = TestModule::expect_100(RuntimeOrigin::signed(100)).unwrap(); // Check used weight is correct - assert_eq!(Some(Weight::from_ref_time(100)), result.actual_weight); + assert_eq!(Some(Weight::from_parts(100, 0)), result.actual_weight); // Check that the method ran correctly assert_eq!(Some(100), TestModule::something()); let result: PostDispatchInfo = TestModule::expect_500(RuntimeOrigin::signed(100)).unwrap(); - assert_eq!(Some(Weight::from_ref_time(500)), result.actual_weight); + assert_eq!(Some(Weight::from_parts(500, 0)), result.actual_weight); assert_eq!(Some(600), TestModule::something()); }); } @@ -21,13 +21,13 @@ fn used_weight_branch_works() { new_test_ext().execute_with(|| { let result: PostDispatchInfo = TestModule::expect_100_or_200(RuntimeOrigin::signed(100), false).unwrap(); // Check used weight is correct - assert_eq!(Some(Weight::from_ref_time(100)), result.actual_weight); + assert_eq!(Some(Weight::from_parts(100, 0)), result.actual_weight); // Check that the method ran correctly assert_eq!(Some(100), TestModule::something()); let result: PostDispatchInfo = TestModule::expect_100_or_200(RuntimeOrigin::signed(100), true).unwrap(); // Check used weight is correct - assert_eq!(Some(Weight::from_ref_time(200)), result.actual_weight); + assert_eq!(Some(Weight::from_parts(200, 0)), result.actual_weight); // Check that the method ran correctly assert_eq!(Some(300), TestModule::something()); }); @@ -38,7 +38,7 @@ fn used_weight_nested_calls_works() { new_test_ext().execute_with(|| { let result: PostDispatchInfo = TestModule::nested_inner_methods(RuntimeOrigin::signed(100)).unwrap(); // Check used weight is correct - assert_eq!(Some(Weight::from_ref_time(300)), result.actual_weight); + assert_eq!(Some(Weight::from_parts(300, 0)), result.actual_weight); }); } @@ -47,7 +47,7 @@ fn exceed_max_weight_works() { new_test_ext().execute_with(|| { let result: PostDispatchInfo = TestModule::expect_max_weight(RuntimeOrigin::signed(100)).unwrap(); // Check used weight is correct - assert_eq!(Some(Weight::from_ref_time(u64::MAX)), result.actual_weight); + assert_eq!(Some(Weight::from_parts(u64::MAX, 0)), result.actual_weight); }); } @@ -55,6 +55,6 @@ fn exceed_max_weight_works() { fn nested_module_calls_works() { new_test_ext().execute_with(|| { let result = TestModule::nested_extrinsic(RuntimeOrigin::signed(0)).unwrap(); - assert_eq!(result.actual_weight, Some(Weight::from_ref_time(700))); + assert_eq!(result.actual_weight, Some(Weight::from_parts(700, 0))); }); } diff --git a/weight-meter/weight-meter-procedural/src/lib.rs b/weight-meter/weight-meter-procedural/src/lib.rs index a2abf3671..785e72023 100644 --- a/weight-meter/weight-meter-procedural/src/lib.rs +++ b/weight-meter/weight-meter-procedural/src/lib.rs @@ -14,7 +14,7 @@ pub fn start(attr: TokenStream, item: TokenStream) -> TokenStream { #(#attrs)* #[cfg_attr(feature = "bench", ::orml_bencher::benchmarkable)] #vis #sig { - ::orml_weight_meter::start(frame_support::weights::Weight::from_ref_time(#weight)); + ::orml_weight_meter::start(frame_support::weights::Weight::from_parts(#weight, 0)); let result = #block; ::orml_weight_meter::finish(); result @@ -31,7 +31,7 @@ pub fn weight(attr: TokenStream, item: TokenStream) -> TokenStream { #(#attrs)* #[cfg_attr(feature = "bench", ::orml_bencher::benchmarkable)] #vis #sig { - ::orml_weight_meter::using(frame_support::weights::Weight::from_ref_time(#weight)); + ::orml_weight_meter::using(frame_support::weights::Weight::from_parts(#weight, 0)); #block } }) diff --git a/xcm-support/Cargo.toml b/xcm-support/Cargo.toml index c2ef881a0..2e5474104 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.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" } -xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" } +xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" } 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..71d094b22 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::v3::{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..79b37205f 100644 --- a/xcm-support/src/lib.rs +++ b/xcm-support/src/lib.rs @@ -9,12 +9,15 @@ #![cfg_attr(not(feature = "std"), no_std)] #![allow(clippy::unused_unit)] -use frame_support::dispatch::{DispatchError, DispatchResult}; +use frame_support::{ + dispatch::{DispatchError, DispatchResult}, + 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::{FilterAssetLocation, MatchesFungible}; +use xcm::v3::prelude::*; +use xcm_executor::traits::MatchesFungible; use orml_traits::{location::Reserve, GetByKey}; @@ -34,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); } } @@ -42,14 +45,14 @@ where } } -/// A `FilterAssetLocation` implementation. Filters multi native assets whose +/// A `ContainsPair` implementation. Filters multi native assets whose /// reserve is same with `origin`. pub struct MultiNativeAsset(PhantomData); -impl FilterAssetLocation for MultiNativeAsset +impl ContainsPair 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..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() @@ -91,18 +93,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 0008292dc..285c4fb1a 100644 --- a/xcm/Cargo.toml +++ b/xcm/Cargo.toml @@ -11,16 +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.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } -pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" } +pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" } [dev-dependencies] -xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.36" } - +xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" } [features] default = ["std"] diff --git a/xcm/src/lib.rs b/xcm/src/lib.rs index 40057f889..5c52a3ea9 100644 --- a/xcm/src/lib.rs +++ b/xcm/src/lib.rs @@ -6,7 +6,7 @@ use frame_support::{pallet_prelude::*, traits::EnsureOrigin}; use frame_system::pallet_prelude::*; use sp_std::boxed::Box; -use xcm::{latest::prelude::*, VersionedMultiLocation, VersionedXcm}; +use xcm::{v3::prelude::*, VersionedMultiLocation, VersionedXcm}; pub use module::*; @@ -61,8 +61,8 @@ 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 { - SendError::CannotReachDestination(..) => Error::::Unreachable, + pallet_xcm::Pallet::::send_xcm(Here, dest, message.clone()).map_err(|e| match e { + 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 8de34d5c1..21069e427 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.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" } # cumulus -cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", default-features = false , branch = "polkadot-v0.9.36" } +cumulus-primitives-core = { default-features = false , git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" } # polkadot -pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" } -xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" } +pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" } +xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" } # 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.36" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } # cumulus -cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" } -cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" } -cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" } -cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" } -parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" } +cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" } +cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" } +cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" } +parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" } # polkadot -polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.36" } -polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.36" } -xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.36" } -xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.36" } +polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" } +polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" } +xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" } +xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" } # orml orml-tokens = { path = "../tokens" } diff --git a/xtokens/src/lib.rs b/xtokens/src/lib.rs index 17470c9ec..64793ad04 100644 --- a/xtokens/src/lib.rs +++ b/xtokens/src/lib.rs @@ -16,6 +16,14 @@ //! //! - `transfer`: Transfer local assets with given `CurrencyId` and `Amount`. //! - `transfer_multiasset`: Transfer `MultiAsset` assets. +//! - `transfer_with_fee`: Transfer native currencies specifying the fee and +//! amount as separate. +//! - `transfer_multiasset_with_fee`: Transfer `MultiAsset` specifying the fee +//! and amount as separate. +//! - `transfer_multicurrencies`: Transfer several currencies specifying the +//! item to be used as fee. +//! - `transfer_multiassets`: Transfer several `MultiAsset` specifying the item +//! to be used as fee. #![cfg_attr(not(feature = "std"), no_std)] #![allow(clippy::from_over_into)] @@ -33,17 +41,21 @@ 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::{ + v3::{prelude::*, Weight}, + VersionedMultiAsset, VersionedMultiAssets, VersionedMultiLocation, +}; +use xcm_executor::traits::WeightBounds; pub use module::*; use orml_traits::{ location::{Parse, Reserve}, + xcm_transfer::{Transferred}, GetByKey, XcmTransfer, }; @@ -110,8 +122,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. @@ -146,7 +158,6 @@ pub mod module { NotCrossChainTransferableCurrency, /// The message's weight could not be determined. UnweighableMessage, - // TODO: expand into XcmExecutionFailed(XcmError) after https://github.com/paritytech/substrate/pull/10242 done /// XCM execution failed. XcmExecutionFailed, /// Could not re-anchor the assets to declare the fees for the @@ -211,7 +222,7 @@ pub mod module { ) -> DispatchResult { let who = ensure_signed(origin)?; let dest: MultiLocation = (*dest).try_into().map_err(|()| Error::::BadVersion)?; - Self::do_transfer(who, currency_id, amount, dest, dest_weight_limit) + Self::do_transfer(who, currency_id, amount, dest, dest_weight_limit).map(|_| ()) } /// Transfer `MultiAsset`. @@ -237,7 +248,7 @@ pub mod module { let who = ensure_signed(origin)?; let asset: MultiAsset = (*asset).try_into().map_err(|()| Error::::BadVersion)?; let dest: MultiLocation = (*dest).try_into().map_err(|()| Error::::BadVersion)?; - Self::do_transfer_multiasset(who, asset, dest, dest_weight_limit) + Self::do_transfer_multiasset(who, asset, dest, dest_weight_limit).map(|_| ()) } /// Transfer native currencies specifying the fee and amount as @@ -274,7 +285,7 @@ pub mod module { let who = ensure_signed(origin)?; let dest: MultiLocation = (*dest).try_into().map_err(|()| Error::::BadVersion)?; - Self::do_transfer_with_fee(who, currency_id, amount, fee, dest, dest_weight_limit) + Self::do_transfer_with_fee(who, currency_id, amount, fee, dest, dest_weight_limit).map(|_| ()) } /// Transfer `MultiAsset` specifying the fee and amount as separate. @@ -312,7 +323,7 @@ pub mod module { let fee: MultiAsset = (*fee).try_into().map_err(|()| Error::::BadVersion)?; let dest: MultiLocation = (*dest).try_into().map_err(|()| Error::::BadVersion)?; - Self::do_transfer_multiasset_with_fee(who, asset, fee, dest, dest_weight_limit) + Self::do_transfer_multiasset_with_fee(who, asset, fee, dest, dest_weight_limit).map(|_| ()) } /// Transfer several currencies specifying the item to be used as fee @@ -342,7 +353,7 @@ pub mod module { let who = ensure_signed(origin)?; let dest: MultiLocation = (*dest).try_into().map_err(|()| Error::::BadVersion)?; - Self::do_transfer_multicurrencies(who, currencies, fee_item, dest, dest_weight_limit) + Self::do_transfer_multicurrencies(who, currencies, fee_item, dest, dest_weight_limit).map(|_| ()) } /// Transfer several `MultiAsset` specifying the item to be used as fee @@ -376,7 +387,7 @@ pub mod module { // We first grab the fee let fee: &MultiAsset = assets.get(fee_item as usize).ok_or(Error::::AssetIndexNonExistent)?; - Self::do_transfer_multiassets(who, assets.clone(), fee.clone(), dest, dest_weight_limit) + Self::do_transfer_multiassets(who, assets.clone(), fee.clone(), dest, dest_weight_limit).map(|_| ()) } } @@ -387,7 +398,7 @@ pub mod module { amount: T::Balance, dest: MultiLocation, dest_weight_limit: WeightLimit, - ) -> DispatchResult { + ) -> Result, DispatchError> { let location: MultiLocation = T::CurrencyIdConvert::convert(currency_id).ok_or(Error::::NotCrossChainTransferableCurrency)?; @@ -408,7 +419,7 @@ pub mod module { fee: T::Balance, dest: MultiLocation, dest_weight_limit: WeightLimit, - ) -> DispatchResult { + ) -> Result, DispatchError> { let location: MultiLocation = T::CurrencyIdConvert::convert(currency_id).ok_or(Error::::NotCrossChainTransferableCurrency)?; @@ -419,7 +430,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 @@ -435,7 +446,7 @@ pub mod module { asset: MultiAsset, dest: MultiLocation, dest_weight_limit: WeightLimit, - ) -> DispatchResult { + ) -> Result, DispatchError> { Self::do_transfer_multiassets(who, vec![asset.clone()].into(), asset, dest, dest_weight_limit) } @@ -445,15 +456,13 @@ pub mod module { fee: MultiAsset, dest: MultiLocation, dest_weight_limit: WeightLimit, - ) -> DispatchResult { + ) -> Result, DispatchError> { // Push contains saturated addition, so we should be able to use it safely let mut assets = MultiAssets::new(); assets.push(asset); assets.push(fee.clone()); - Self::do_transfer_multiassets(who, assets, fee, dest, dest_weight_limit)?; - - Ok(()) + Self::do_transfer_multiassets(who, assets, fee, dest, dest_weight_limit) } fn do_transfer_multicurrencies( @@ -462,7 +471,7 @@ pub mod module { fee_item: u32, dest: MultiLocation, dest_weight_limit: WeightLimit, - ) -> DispatchResult { + ) -> Result, DispatchError> { ensure!( currencies.len() <= T::MaxAssetsForTransfer::get(), Error::::TooManyAssetsBeingSent @@ -504,7 +513,7 @@ pub mod module { fee: MultiAsset, dest: MultiLocation, dest_weight_limit: WeightLimit, - ) -> DispatchResult { + ) -> Result, DispatchError> { ensure!( assets.len() <= T::MaxAssetsForTransfer::get(), Error::::TooManyAssetsBeingSent @@ -542,11 +551,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(); @@ -566,9 +575,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); } @@ -577,7 +586,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, @@ -612,13 +621,18 @@ pub mod module { } Self::deposit_event(Event::::TransferredMultiAssets { + sender: who.clone(), + assets: assets.clone(), + fee: fee.clone(), + dest, + }); + + Ok(Transferred { sender: who, assets, fee, dest, - }); - - Ok(()) + }) } /// Execute and send xcm with given assets and fee to dest chain or @@ -638,7 +652,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)?, @@ -652,9 +665,10 @@ 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)?; - 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); @@ -673,7 +687,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), @@ -692,7 +706,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), @@ -710,7 +724,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 { @@ -723,21 +737,21 @@ 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 { - assets: All.into(), - max_assets: assets.len() as u32, + assets: AllCounted(max_assets).into(), 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, max_assets), ]), }, ]), @@ -745,10 +759,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 { @@ -756,7 +770,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, max_assets), ]), }, ]), @@ -767,8 +781,7 @@ pub mod module { fn deposit_asset(recipient: MultiLocation, max_assets: u32) -> Instruction<()> { DepositAsset { - assets: All.into(), - max_assets, + assets: AllCounted(max_assets).into(), beneficiary: recipient, } } @@ -778,10 +791,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 }) } @@ -821,12 +832,26 @@ pub mod module { }; Ok((transfer_kind, dest, reserve, recipient)) } + + /// Get reserve location by `assets` and `fee_item`. the `assets` + /// includes fee asset and non fee asset. make sure assets have ge one + /// asset. all non fee asset should share same reserve location. + fn get_reserve_location(assets: &MultiAssets, fee_item: &u32) -> Option { + let reserve_idx = if assets.len() == 1 { + 0 + } else { + (*fee_item == 0) as usize + }; + let asset = assets.get(reserve_idx); + asset.and_then(T::ReserveProvider::reserve) + } } + pub struct XtokensWeight(PhantomData); // weights impl Pallet { fn fixed_weight_of_transfer() -> Weight { - (2_000_000_000 as Weight).saturating_add(T::BaseXcmWeight::get()) + (Weight::from_parts(2_000_000_000, 0)).saturating_add(T::BaseXcmWeight::get()) } /// Returns weight of `transfer_multiasset` call. fn weight_of_transfer_multiasset(asset: &VersionedMultiAsset, dest: &VersionedMultiLocation) -> Weight { @@ -834,7 +859,7 @@ pub mod module { let dest = dest.clone().try_into(); if let (Ok(asset), Ok(dest)) = (asset, dest) { if let Ok((transfer_kind, dest, _, reserve)) = - Self::transfer_kind(T::ReserveProvider::reserve(&asset), &dest) + Pallet::::transfer_kind(T::ReserveProvider::reserve(&asset), &dest) { let mut msg = match transfer_kind { SelfReserveAsset => Xcm(vec![TransferReserveAsset { @@ -856,7 +881,7 @@ pub mod module { .map_or(Weight::max_value(), |w| T::BaseXcmWeight::get().saturating_add(w)); } } - 0 + Weight::zero() } /// Returns weight of `transfer` call. @@ -865,7 +890,7 @@ pub mod module { let asset = (location, amount.into()).into(); Self::weight_of_transfer_multiasset(&asset, dest) } else { - 0 + Weight::zero() } } @@ -878,10 +903,10 @@ 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 0; + return Weight::zero(); } } @@ -897,8 +922,8 @@ pub mod module { let assets: Result = assets.clone().try_into(); let dest = dest.clone().try_into(); if let (Ok(assets), Ok(dest)) = (assets, dest) { - let reserve_location = Self::get_reserve_location(&assets, fee_item); - if let Ok((transfer_kind, dest, _, reserve)) = Self::transfer_kind(reserve_location, &dest) { + let reserve_location = Pallet::::get_reserve_location(&assets, fee_item); + if let Ok((transfer_kind, dest, _, reserve)) = Pallet::::transfer_kind(reserve_location, &dest) { let mut msg = match transfer_kind { SelfReserveAsset => Xcm(vec![TransferReserveAsset { assets, @@ -919,20 +944,7 @@ pub mod module { .map_or(Weight::max_value(), |w| T::BaseXcmWeight::get().saturating_add(w)); } } - 0 - } - - /// Get reserve location by `assets` and `fee_item`. the `assets` - /// includes fee asset and non fee asset. make sure assets have ge one - /// asset. all non fee asset should share same reserve location. - fn get_reserve_location(assets: &MultiAssets, fee_item: &u32) -> Option { - let reserve_idx = if assets.len() == 1 { - 0 - } else { - (*fee_item == 0) as usize - }; - let asset = assets.get(reserve_idx); - asset.and_then(T::ReserveProvider::reserve) + Weight::zero() } } @@ -944,20 +956,32 @@ pub mod module { amount: T::Balance, dest: MultiLocation, dest_weight_limit: WeightLimit, - ) -> DispatchResult { + ) -> Result, DispatchError> { Self::do_transfer(who, currency_id, amount, dest, dest_weight_limit) } #[require_transactional] - fn transfer_multi_asset( + fn transfer_multiasset( who: T::AccountId, asset: MultiAsset, dest: MultiLocation, dest_weight_limit: WeightLimit, - ) -> DispatchResult { + ) -> Result, DispatchError> { Self::do_transfer_multiasset(who, asset, dest, dest_weight_limit) } + #[require_transactional] + fn transfer_with_fee( + who: T::AccountId, + currency_id: T::CurrencyId, + amount: T::Balance, + fee: T::Balance, + dest: MultiLocation, + dest_weight_limit: WeightLimit, + ) -> Result, DispatchError> { + Self::do_transfer_with_fee(who, currency_id, amount, fee, dest, dest_weight_limit) + } + #[require_transactional] fn transfer_multiasset_with_fee( who: T::AccountId, @@ -965,9 +989,31 @@ pub mod module { fee: MultiAsset, dest: MultiLocation, dest_weight_limit: WeightLimit, - ) -> DispatchResult { + ) -> Result, DispatchError> { Self::do_transfer_multiasset_with_fee(who, asset, fee, dest, dest_weight_limit) } + + #[require_transactional] + fn transfer_multicurrencies( + who: T::AccountId, + currencies: Vec<(T::CurrencyId, T::Balance)>, + fee_item: u32, + dest: MultiLocation, + dest_weight_limit: WeightLimit, + ) -> Result, DispatchError> { + Self::do_transfer_multicurrencies(who, currencies, fee_item, dest, dest_weight_limit) + } + + #[require_transactional] + fn transfer_multiassets( + who: T::AccountId, + assets: MultiAssets, + fee: MultiAsset, + dest: MultiLocation, + dest_weight_limit: WeightLimit, + ) -> Result, DispatchError> { + Self::do_transfer_multiassets(who, assets, fee, dest, dest_weight_limit) + } } } @@ -986,7 +1032,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 +1040,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, } } diff --git a/xtokens/src/mock/mod.rs b/xtokens/src/mock/mod.rs index ed4cd3444..d0d47cd99 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, @@ -266,7 +322,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 { @@ -285,7 +341,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 19f38d690..60666a0bf 100644 --- a/xtokens/src/mock/para.rs +++ b/xtokens/src/mock/para.rs @@ -17,10 +17,10 @@ use sp_runtime::{ use cumulus_primitives_core::{ChannelStatus, GetChannelInfo, ParaId}; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; -use xcm::latest::{prelude::*, Weight}; +use xcm::v3::{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}; @@ -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_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); + pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); } 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 Ancestry: MultiLocation = 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; @@ -140,14 +148,23 @@ 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 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 { @@ -184,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; @@ -193,19 +216,27 @@ 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; + #[cfg(feature = "runtime-benchmarks")] + type ReachableDest = ReachableDest; } pub struct AccountIdToMultiLocation; impl Convert for AccountIdToMultiLocation { fn convert(account: AccountId) -> MultiLocation { X1(Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: account.into(), }) .into() @@ -249,9 +280,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 = AbsoluteReserveProvider; } diff --git a/xtokens/src/mock/para_relative_view.rs b/xtokens/src/mock/para_relative_view.rs index a44283438..57ad84734 100644 --- a/xtokens/src/mock/para_relative_view.rs +++ b/xtokens/src/mock/para_relative_view.rs @@ -11,17 +11,17 @@ use sp_core::H256; use sp_runtime::{ testing::Header, traits::{Convert, IdentityLookup}, - AccountId32, + AccountId32, BoundedVec, }; use cumulus_primitives_core::{ChannelStatus, GetChannelInfo, ParaId}; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; -use xcm::latest::{prelude::*, Weight}; +use xcm::v3::{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}; @@ -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_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); + pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); } 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 Ancestry: MultiLocation = 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; @@ -143,14 +151,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 = 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 { @@ -187,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; @@ -196,19 +219,27 @@ 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; + #[cfg(feature = "runtime-benchmarks")] + type ReachableDest = ReachableDest; } pub struct AccountIdToMultiLocation; impl Convert for AccountIdToMultiLocation { fn convert(account: AccountId) -> MultiLocation { X1(Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: account.into(), }) .into() @@ -220,25 +251,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 +326,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,9 +403,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/xtokens/src/mock/para_teleport.rs b/xtokens/src/mock/para_teleport.rs index 75fbd509c..defd1ff57 100644 --- a/xtokens/src/mock/para_teleport.rs +++ b/xtokens/src/mock/para_teleport.rs @@ -17,10 +17,10 @@ use sp_runtime::{ use cumulus_primitives_core::{ChannelStatus, GetChannelInfo, ParaId}; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; -use xcm::latest::{prelude::*, Weight}; +use xcm::v3::{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}; @@ -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_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); + pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); } 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 Ancestry: MultiLocation = 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; @@ -141,14 +149,23 @@ 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 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 { @@ -185,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; @@ -194,19 +217,27 @@ 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; + #[cfg(feature = "runtime-benchmarks")] + type ReachableDest = ReachableDest; } pub struct AccountIdToMultiLocation; impl Convert for AccountIdToMultiLocation { fn convert(account: AccountId) -> MultiLocation { X1(Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: account.into(), }) .into() @@ -240,9 +271,9 @@ 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 LocationInverter = LocationInverter; + 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 e0b1e9965..264416302 100644 --- a/xtokens/src/mock/relay.rs +++ b/xtokens/src/mock/relay.rs @@ -1,18 +1,19 @@ 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::*; +use xcm::v3::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}; @@ -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 Ancestry: MultiLocation = Here.into(); + 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; @@ -104,18 +112,32 @@ 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 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; +#[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; @@ -126,12 +148,20 @@ 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 = (); + type TrustedLockers = (); + 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/xtokens/src/mock/teleport_currency_adapter.rs b/xtokens/src/mock/teleport_currency_adapter.rs index 2056b07cc..ceb1b8f4d 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::v3::{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 79ef3c0b7..701e3abba 100644 --- a/xtokens/src/tests.rs +++ b/xtokens/src/tests.rs @@ -8,6 +8,7 @@ use mock::*; use orml_traits::{ConcreteFungibleAsset, MultiCurrency}; use polkadot_parachain::primitives::Sibling; use sp_runtime::{traits::AccountIdConversion, AccountId32}; +use xcm::{v3::OriginKind::SovereignAccount, VersionedXcm}; use xcm_simulator::TestExt; fn para_a_account() -> AccountId32 { @@ -65,7 +66,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 +101,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 +135,7 @@ fn cannot_lost_fund_on_send_failed() { Parent, Parachain(100), Junction::AccountId32 { - network: NetworkId::Kusama, + network: None, id: BOB.into(), }, ) @@ -168,7 +169,7 @@ fn send_relay_chain_asset_to_sibling() { X2( Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -210,7 +211,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 +259,7 @@ fn send_sibling_asset_to_reserve_sibling() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -283,7 +284,7 @@ fn send_sibling_asset_to_reserve_sibling() { Parent, Parachain(1), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: ALICE.into(), }, ) @@ -323,7 +324,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 +367,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 +413,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 +458,7 @@ fn send_sibling_asset_to_non_reserve_sibling() { X2( Parachain(3), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -504,7 +505,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 +547,7 @@ fn send_self_parachain_asset_to_sibling() { X2( Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -583,7 +584,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 +622,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,13 +676,13 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_works() { Parent, Parachain(3), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) .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)); @@ -735,13 +736,13 @@ 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(), }, ) .into() ), - WeightLimit::Limited(weight as u64), + WeightLimit::Limited((weight as u64).into()), )); assert_eq!(550, ParaRelativeTokens::free_balance(CurrencyId::C, &ALICE)); assert_eq!( @@ -798,13 +799,13 @@ 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(), }, ) .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)); @@ -844,7 +845,7 @@ fn transfer_asset_with_relay_fee_failed() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -868,7 +869,7 @@ fn transfer_asset_with_relay_fee_failed() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -893,7 +894,7 @@ fn transfer_asset_with_relay_fee_failed() { Parent, Parachain(3), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -917,7 +918,7 @@ fn transfer_asset_with_relay_fee_failed() { Parent, Parachain(1), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -935,16 +936,17 @@ 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, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into() } ) @@ -972,7 +974,7 @@ fn transfer_to_self_chain_fails() { X2( Parachain(1), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into() } ) @@ -999,7 +1001,7 @@ fn transfer_to_invalid_dest_fails() { MultiLocation::new( 0, X1(Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into() }) ) @@ -1021,12 +1023,10 @@ fn send_as_sovereign() { }); ParaA::execute_with(|| { - use xcm::latest::OriginKind::SovereignAccount; - 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 +1034,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(), } ]))) @@ -1064,12 +1064,10 @@ fn send_as_sovereign_fails_if_bad_origin() { }); ParaA::execute_with(|| { - use xcm::latest::OriginKind::SovereignAccount; - 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 +1076,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(), } ]))) @@ -1130,7 +1128,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 +1162,7 @@ fn send_with_insufficient_fee_traps_assets() { X2( Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -1207,7 +1205,7 @@ fn send_with_fee_should_handle_overflow() { X2( Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), } ) @@ -1258,7 +1256,7 @@ fn specifying_more_than_assets_limit_should_error() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -1299,7 +1297,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 +1333,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 +1361,7 @@ fn send_with_zero_amount() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -1384,7 +1382,7 @@ fn send_with_zero_amount() { Parent, Parachain(2), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, ) @@ -1416,7 +1414,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 +1460,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 +1488,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 +1528,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 +1576,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 +1615,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 +1636,7 @@ fn unsupported_multilocation_should_be_filtered() { Parent, Parachain(5), Junction::AccountId32 { - network: NetworkId::Any, + network: None, id: BOB.into(), }, )