From a11e25ae16cf8be2e5ecfb28f87688bd2d426b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Tue, 17 Sep 2024 16:05:27 +0200 Subject: [PATCH 01/24] refactor xtokens precompile: get rid of orml-xtokens pallet --- Cargo.lock | 2 +- precompiles/xtokens/Cargo.toml | 4 +- precompiles/xtokens/src/lib.rs | 257 ++++++++++++++++++++------------- 3 files changed, 161 insertions(+), 102 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3612469a21..22dc4cba71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9551,11 +9551,11 @@ dependencies = [ "log", "num_enum 0.5.11", "orml-traits", - "orml-xtokens", "pallet-balances", "pallet-evm", "pallet-timestamp", "pallet-xcm", + "pallet-xcm-transactor", "parity-scale-codec", "precompile-utils", "rustc-hex", diff --git a/precompiles/xtokens/Cargo.toml b/precompiles/xtokens/Cargo.toml index 496c46d201..58c37f62b2 100644 --- a/precompiles/xtokens/Cargo.toml +++ b/precompiles/xtokens/Cargo.toml @@ -13,6 +13,7 @@ rustc-hex = { workspace = true } # Moonbeam account = { workspace = true } xcm-primitives = { workspace = true } +pallet-xcm-transactor = { workspace = true } # Substrate frame-support = { workspace = true } @@ -28,8 +29,8 @@ pallet-evm = { workspace = true, features = ["forbid-evm-reentrancy"] } precompile-utils = { workspace = true, features = ["codec-xcm"] } # Polkadot / XCM -orml-xtokens = { workspace = true } xcm = { workspace = true } +pallet-xcm = { workspace = true } [dev-dependencies] derive_more = { workspace = true } @@ -61,7 +62,6 @@ std = [ "fp-evm/std", "frame-support/std", "frame-system/std", - "orml-xtokens/std", "pallet-evm/std", "precompile-utils/std", "sp-core/std", diff --git a/precompiles/xtokens/src/lib.rs b/precompiles/xtokens/src/lib.rs index e8c8543b84..28f427fc0a 100644 --- a/precompiles/xtokens/src/lib.rs +++ b/precompiles/xtokens/src/lib.rs @@ -20,24 +20,16 @@ use account::SYSTEM_ACCOUNT_SIZE; use fp_evm::PrecompileHandle; -use frame_support::{ - dispatch::{GetDispatchInfo, PostDispatchInfo}, - traits::Get, -}; +use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; use pallet_evm::AddressMapping; use precompile_utils::prelude::*; -use sp_core::{H160, U256}; -use sp_runtime::traits::Dispatchable; -use sp_std::{ - boxed::Box, - convert::{TryFrom, TryInto}, - marker::PhantomData, - vec::Vec, -}; +use sp_core::{ConstU32, H160, U256}; +use sp_runtime::traits::{Convert, Dispatchable}; +use sp_std::{boxed::Box, convert::TryInto, marker::PhantomData, vec::Vec}; use sp_weights::Weight; use xcm::{ - latest::{Asset, AssetId, Assets, Fungibility, Location, WeightLimit}, - VersionedAsset, VersionedAssets, VersionedLocation, + latest::{Asset, AssetId, Assets, Fungibility, Junction, Junctions, Location, WeightLimit}, + VersionedAssets, VersionedLocation, }; use xcm_primitives::{AccountIdToCurrencyId, DEFAULT_PROOF_SIZE}; @@ -46,21 +38,11 @@ mod mock; #[cfg(test)] mod tests; -pub type XBalanceOf = ::Balance; -pub type MaxAssetsForTransfer = ::MaxAssetsForTransfer; - -pub type CurrencyIdOf = ::CurrencyId; - -pub struct GetMaxAssets(PhantomData); +pub type CurrencyIdOf = ::CurrencyId; +pub type CurrencyIdToLocationOf = + ::CurrencyIdToLocation; -impl Get for GetMaxAssets -where - R: orml_xtokens::Config, -{ - fn get() -> u32 { - ::MaxAssetsForTransfer::get() as u32 - } -} +const MAX_ASSETS: u32 = 20; /// A precompile to wrap the functionality from xtokens pub struct XtokensPrecompile(PhantomData); @@ -69,11 +51,15 @@ pub struct XtokensPrecompile(PhantomData); #[precompile::test_concrete_types(mock::Runtime)] impl XtokensPrecompile where - Runtime: orml_xtokens::Config + pallet_evm::Config + frame_system::Config, - Runtime::RuntimeCall: Dispatchable + GetDispatchInfo, - Runtime::RuntimeCall: From>, - ::RuntimeOrigin: From>, - XBalanceOf: TryFrom + Into + solidity::Codec, + Runtime: pallet_evm::Config + + pallet_xcm::Config + + pallet_xcm_transactor::Config + + frame_system::Config, + ::RuntimeCall: + Dispatchable + GetDispatchInfo, + ::RuntimeCall: From>, + <::RuntimeCall as Dispatchable>::RuntimeOrigin: + From>, Runtime: AccountIdToCurrencyId>, { #[precompile::public("transfer(address,uint256,(uint8,bytes[]),uint64)")] @@ -88,9 +74,8 @@ where let to_account = Runtime::AddressMapping::into_account_id(to_address); // We convert the address into a currency id xtokens understands - let currency_id: ::CurrencyId = - Runtime::account_to_currency_id(to_account) - .ok_or(revert("cannot convert into currency id"))?; + let currency_id: CurrencyIdOf = Runtime::account_to_currency_id(to_account) + .ok_or(revert("cannot convert into currency id"))?; let origin = Runtime::AddressMapping::into_account_id(handle.context().caller); let amount = amount @@ -103,11 +88,20 @@ where WeightLimit::Limited(Weight::from_parts(weight, DEFAULT_PROOF_SIZE)) }; - let call = orml_xtokens::Call::::transfer { - currency_id, - amount, - dest: Box::new(VersionedLocation::V4(destination)), - dest_weight_limit, + let asset = Self::currency_to_asset(currency_id, amount).ok_or( + RevertReason::custom("Cannot convert currency into xcm asset") + .in_field("currency_address"), + )?; + + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(destination) + .ok_or_else(|| RevertReason::custom("Invalid destination").in_field("destination"))?; + + let call = pallet_xcm::Call::::transfer_assets { + dest: Box::new(VersionedLocation::V4(chain_part)), + beneficiary: Box::new(VersionedLocation::V4(beneficiary)), + assets: Box::new(VersionedAssets::V4(asset.into())), + fee_asset_item: 0, + weight_limit: dest_weight_limit, }; RuntimeHelper::::try_dispatch( @@ -126,7 +120,7 @@ where handle: &mut impl PrecompileHandle, currency_address: Address, amount: U256, - fee: U256, + _fee: U256, destination: Location, weight: u64, ) -> EvmResult { @@ -134,8 +128,8 @@ where let to_account = Runtime::AddressMapping::into_account_id(to_address); // We convert the address into a currency id xtokens understands - let currency_id: ::CurrencyId = - Runtime::account_to_currency_id(to_account).ok_or( + let currency_id: CurrencyIdOf = Runtime::account_to_currency_id(to_account) + .ok_or( RevertReason::custom("Cannot convert into currency id").in_field("currencyAddress"), )?; @@ -147,9 +141,9 @@ where .map_err(|_| RevertReason::value_is_too_large("balance type").in_field("amount"))?; // Fee amount - let fee = fee - .try_into() - .map_err(|_| RevertReason::value_is_too_large("balance type").in_field("fee"))?; + /*let _fee = fee + .try_into() + .map_err(|_| RevertReason::value_is_too_large("balance type").in_field("fee"))?;*/ let dest_weight_limit = if weight == u64::MAX { WeightLimit::Unlimited @@ -157,12 +151,20 @@ where WeightLimit::Limited(Weight::from_parts(weight, DEFAULT_PROOF_SIZE)) }; - let call = orml_xtokens::Call::::transfer_with_fee { - currency_id, - amount, - fee, - dest: Box::new(VersionedLocation::V4(destination)), - dest_weight_limit, + let asset = Self::currency_to_asset(currency_id, amount).ok_or( + RevertReason::custom("Cannot convert currency into xcm asset") + .in_field("currency_address"), + )?; + + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(destination) + .ok_or_else(|| RevertReason::custom("Invalid destination").in_field("destination"))?; + + let call = pallet_xcm::Call::::transfer_assets { + dest: Box::new(VersionedLocation::V4(chain_part)), + beneficiary: Box::new(VersionedLocation::V4(beneficiary)), + assets: Box::new(VersionedAssets::V4(asset.into())), + fee_asset_item: 0, + weight_limit: dest_weight_limit, }; RuntimeHelper::::try_dispatch( @@ -195,13 +197,21 @@ where WeightLimit::Limited(Weight::from_parts(weight, DEFAULT_PROOF_SIZE)) }; - let call = orml_xtokens::Call::::transfer_multiasset { - asset: Box::new(VersionedAsset::V4(Asset { - id: AssetId(asset), - fun: Fungibility::Fungible(to_balance), - })), - dest: Box::new(VersionedLocation::V4(destination)), - dest_weight_limit, + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(destination) + .ok_or_else(|| RevertReason::custom("Invalid destination").in_field("destination"))?; + + let call = pallet_xcm::Call::::transfer_assets { + dest: Box::new(VersionedLocation::V4(chain_part)), + beneficiary: Box::new(VersionedLocation::V4(beneficiary)), + assets: Box::new(VersionedAssets::V4( + Asset { + id: AssetId(asset), + fun: Fungibility::Fungible(to_balance), + } + .into(), + )), + fee_asset_item: 0, + weight_limit: dest_weight_limit, }; RuntimeHelper::::try_dispatch( @@ -224,7 +234,7 @@ where handle: &mut impl PrecompileHandle, asset: Location, amount: U256, - fee: U256, + _fee: U256, destination: Location, weight: u64, ) -> EvmResult { @@ -232,9 +242,9 @@ where let amount = amount .try_into() .map_err(|_| RevertReason::value_is_too_large("balance type").in_field("amount"))?; - let fee = fee - .try_into() - .map_err(|_| RevertReason::value_is_too_large("balance type").in_field("fee"))?; + /*let _fee = fee + .try_into() + .map_err(|_| RevertReason::value_is_too_large("balance type").in_field("fee"))?;*/ let dest_weight_limit = if weight == u64::MAX { WeightLimit::Unlimited @@ -242,17 +252,21 @@ where WeightLimit::Limited(Weight::from_parts(weight, DEFAULT_PROOF_SIZE)) }; - let call = orml_xtokens::Call::::transfer_multiasset_with_fee { - asset: Box::new(VersionedAsset::V4(Asset { - id: AssetId(asset.clone()), - fun: Fungibility::Fungible(amount), - })), - fee: Box::new(VersionedAsset::V4(Asset { - id: AssetId(asset), - fun: Fungibility::Fungible(fee), - })), - dest: Box::new(VersionedLocation::V4(destination)), - dest_weight_limit, + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(destination) + .ok_or_else(|| RevertReason::custom("Invalid destination").in_field("destination"))?; + + let call = pallet_xcm::Call::::transfer_assets { + dest: Box::new(VersionedLocation::V4(chain_part)), + beneficiary: Box::new(VersionedLocation::V4(beneficiary)), + assets: Box::new(VersionedAssets::V4( + Asset { + id: AssetId(asset.clone()), + fun: Fungibility::Fungible(amount), + } + .into(), + )), + fee_asset_item: 0, + weight_limit: dest_weight_limit, }; RuntimeHelper::::try_dispatch( @@ -273,7 +287,7 @@ where )] fn transfer_multi_currencies( handle: &mut impl PrecompileHandle, - currencies: BoundedVec>, + currencies: BoundedVec>, fee_item: u32, destination: Location, weight: u64, @@ -282,7 +296,7 @@ where // Build all currencies let currencies: Vec<_> = currencies.into(); - let currencies = currencies + let assets = currencies .into_iter() .enumerate() .map(|(index, currency)| { @@ -293,19 +307,23 @@ where .in_field("currencies") })?; - Ok(( - Runtime::account_to_currency_id(Runtime::AddressMapping::into_account_id( - address_as_h160, - )) - .ok_or( - RevertReason::custom("Cannot convert into currency id") - .in_array(index) - .in_field("currencies"), - )?, - amount, - )) + let currency_id = Runtime::account_to_currency_id( + Runtime::AddressMapping::into_account_id(address_as_h160), + ) + .ok_or( + RevertReason::custom("Cannot convert into currency id") + .in_array(index) + .in_field("currencies"), + )?; + + Self::currency_to_asset(currency_id, amount).ok_or( + RevertReason::custom("Cannot convert currency into xcm asset") + .in_array(index) + .in_field("currencies") + .into(), + ) }) - .collect::>()?; + .collect::>>()?; let dest_weight_limit = if weight == u64::MAX { WeightLimit::Unlimited @@ -313,11 +331,15 @@ where WeightLimit::Limited(Weight::from_parts(weight, DEFAULT_PROOF_SIZE)) }; - let call = orml_xtokens::Call::::transfer_multicurrencies { - currencies, - fee_item, - dest: Box::new(VersionedLocation::V4(destination)), - dest_weight_limit, + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(destination) + .ok_or_else(|| RevertReason::custom("Invalid destination").in_field("destination"))?; + + let call = pallet_xcm::Call::::transfer_assets { + dest: Box::new(VersionedLocation::V4(chain_part)), + beneficiary: Box::new(VersionedLocation::V4(beneficiary)), + assets: Box::new(VersionedAssets::V4(assets.into())), + fee_asset_item: fee_item, + weight_limit: dest_weight_limit, }; RuntimeHelper::::try_dispatch( @@ -338,7 +360,7 @@ where )] fn transfer_multi_assets( handle: &mut impl PrecompileHandle, - assets: BoundedVec>, + assets: BoundedVec>, fee_item: u32, destination: Location, weight: u64, @@ -372,11 +394,15 @@ where WeightLimit::Limited(Weight::from_parts(weight, DEFAULT_PROOF_SIZE)) }; - let call = orml_xtokens::Call::::transfer_multiassets { + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(destination) + .ok_or_else(|| RevertReason::custom("Invalid destination").in_field("destination"))?; + + let call = pallet_xcm::Call::::transfer_assets { + dest: Box::new(VersionedLocation::V4(chain_part)), + beneficiary: Box::new(VersionedLocation::V4(beneficiary)), assets: Box::new(VersionedAssets::V4(assets)), - fee_item, - dest: Box::new(VersionedLocation::V4(destination)), - dest_weight_limit, + fee_asset_item: fee_item, + weight_limit: dest_weight_limit, }; RuntimeHelper::::try_dispatch( @@ -388,6 +414,13 @@ where Ok(()) } + + fn currency_to_asset(currency_id: CurrencyIdOf, amount: u128) -> Option { + Some(Asset { + fun: Fungibility::Fungible(amount), + id: AssetId(>::convert(currency_id)?), + }) + } } // Currency @@ -420,3 +453,29 @@ impl From<(Location, U256)> for EvmAsset { } } } + +fn split_location_into_chain_part_and_beneficiary( + mut location: Location, +) -> Option<(Location, Location)> { + let mut beneficiary_junctions = Junctions::Here; + + // start popping junctions until we reach chain identifier + while let Some(j) = location.last() { + if matches!(j, Junction::Parachain(_) | Junction::GlobalConsensus(_)) { + // return chain subsection + return Some((location, beneficiary_junctions.into_location())); + } else { + let (location_prefix, maybe_last_junction) = location.split_last_interior(); + location = location_prefix; + if let Some(junction) = maybe_last_junction { + beneficiary_junctions.push(junction).ok()?; + } + } + } + + if location.parent_count() == 1 { + Some((Location::parent(), beneficiary_junctions.into_location())) + } else { + None + } +} From 6e5af040c6a07eaec565757daa436f4147981379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Tue, 17 Sep 2024 18:03:35 +0200 Subject: [PATCH 02/24] refactor GMP precompile: get rid of orml-xtokens pallet --- Cargo.lock | 2 +- precompiles/gmp/Cargo.toml | 2 +- precompiles/gmp/src/lib.rs | 82 +++++++++++++++++++++++++--------- precompiles/xtokens/src/lib.rs | 32 ++----------- primitives/xcm/src/lib.rs | 28 ++++++++++++ 5 files changed, 95 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 22dc4cba71..11584e6db7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9119,11 +9119,11 @@ dependencies = [ "log", "num_enum 0.5.11", "orml-traits", - "orml-xtokens", "pallet-balances", "pallet-evm", "pallet-timestamp", "pallet-xcm", + "pallet-xcm-transactor", "parity-scale-codec", "paste", "precompile-utils", diff --git a/precompiles/gmp/Cargo.toml b/precompiles/gmp/Cargo.toml index f2ad365014..b273023c9e 100644 --- a/precompiles/gmp/Cargo.toml +++ b/precompiles/gmp/Cargo.toml @@ -13,6 +13,7 @@ slices = { workspace = true } # Moonbeam account = { workspace = true } +pallet-xcm-transactor = { workspace = true } # Substrate frame-support = { workspace = true } @@ -31,7 +32,6 @@ precompile-utils = { workspace = true } # Polkadot / XCM orml-traits = { workspace = true } -orml-xtokens = { workspace = true } pallet-xcm = { workspace = true } xcm = { workspace = true } xcm-builder = { workspace = true } diff --git a/precompiles/gmp/src/lib.rs b/precompiles/gmp/src/lib.rs index ccd14d0956..6e13b3501d 100644 --- a/precompiles/gmp/src/lib.rs +++ b/precompiles/gmp/src/lib.rs @@ -23,19 +23,20 @@ use evm::ExitReason; use fp_evm::{Context, ExitRevert, PrecompileFailure, PrecompileHandle}; use frame_support::{ dispatch::{GetDispatchInfo, PostDispatchInfo}, - sp_runtime::{traits::Zero, Saturating}, + sp_runtime::traits::Zero, traits::ConstU32, }; use pallet_evm::AddressMapping; use parity_scale_codec::{Decode, DecodeLimit}; use precompile_utils::{prelude::*, solidity::revert::revert_as_bytes}; use sp_core::{H160, U256}; -use sp_runtime::traits::Dispatchable; +use sp_runtime::traits::{Convert, Dispatchable}; use sp_std::boxed::Box; use sp_std::{marker::PhantomData, vec::Vec}; use types::*; -use xcm::opaque::latest::WeightLimit; -use xcm_primitives::AccountIdToCurrencyId; +use xcm::opaque::latest::{Asset, AssetId, Fungibility, WeightLimit}; +use xcm::{VersionedAssets, VersionedLocation}; +use xcm_primitives::{split_location_into_chain_part_and_beneficiary, AccountIdToCurrencyId}; #[cfg(test)] mod mock; @@ -45,8 +46,10 @@ mod tests; pub mod types; pub type SystemCallOf = ::RuntimeCall; -pub type CurrencyIdOf = ::CurrencyId; -pub type XBalanceOf = ::Balance; +pub type CurrencyIdOf = ::CurrencyId; +pub type CurrencyIdToLocationOf = + ::CurrencyIdToLocation; + pub const CALL_DATA_LIMIT: u32 = 2u32.pow(16); type GetCallDataLimit = ConstU32; @@ -66,13 +69,15 @@ pub struct GmpPrecompile(PhantomData); #[precompile_utils::precompile] impl GmpPrecompile where - Runtime: pallet_evm::Config + frame_system::Config + pallet_xcm::Config + orml_xtokens::Config, + Runtime: pallet_evm::Config + + frame_system::Config + + pallet_xcm::Config + + pallet_xcm_transactor::Config, SystemCallOf: Dispatchable + Decode + GetDispatchInfo, <::RuntimeCall as Dispatchable>::RuntimeOrigin: From>, - ::RuntimeCall: From>, + ::RuntimeCall: From>, Runtime: AccountIdToCurrencyId>, - XBalanceOf: TryFrom + Into + solidity::Codec, { #[precompile::public("wormholeTransferERC20(bytes)")] pub fn wormhole_transfer_erc20( @@ -176,7 +181,7 @@ where let currency_account_id = Runtime::AddressMapping::into_account_id(asset_erc20_address.into()); - let currency_id: ::CurrencyId = + let currency_id: CurrencyIdOf = Runtime::account_to_currency_id(currency_account_id) .ok_or(revert("Unsupported asset, not a valid currency id"))?; @@ -207,14 +212,32 @@ where .map_err(|_| revert("Amount overflows balance"))?; log::debug!(target: "gmp-precompile", "sending XCM via xtokens::transfer..."); - let call: Option> = match user_action { + let call: Option> = match user_action { VersionedUserAction::V1(action) => { log::debug!(target: "gmp-precompile", "Payload: V1"); - Some(orml_xtokens::Call::::transfer { - currency_id, - amount, - dest: Box::new(action.destination), - dest_weight_limit: WeightLimit::Unlimited, + + let asset = Asset { + fun: Fungibility::Fungible(amount), + id: AssetId( + >::convert(currency_id) + .ok_or(revert("Cannot convert CurrencyId into xcm asset"))?, + ), + }; + + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary( + action + .destination + .try_into() + .map_err(|_| revert("Invalid destination"))?, + ) + .ok_or(revert("Invalid destination"))?; + + Some(pallet_xcm::Call::::transfer_assets { + dest: Box::new(VersionedLocation::V4(chain_part)), + beneficiary: Box::new(VersionedLocation::V4(beneficiary)), + assets: Box::new(VersionedAssets::V4(asset.into())), + fee_asset_item: 0, + weight_limit: WeightLimit::Unlimited, }) } VersionedUserAction::V2(action) => { @@ -252,11 +275,28 @@ where let remaining = amount.saturating_sub(fee); if !remaining.is_zero() { - Some(orml_xtokens::Call::::transfer { - currency_id, - amount: remaining, - dest: Box::new(action.destination), - dest_weight_limit: WeightLimit::Unlimited, + let asset = Asset { + fun: Fungibility::Fungible(remaining), + id: AssetId( + >::convert(currency_id) + .ok_or(revert("Cannot convert CurrencyId into xcm asset"))?, + ), + }; + + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary( + action + .destination + .try_into() + .map_err(|_| revert("Invalid destination"))?, + ) + .ok_or(revert("Invalid destination"))?; + + Some(pallet_xcm::Call::::transfer_assets { + dest: Box::new(VersionedLocation::V4(chain_part)), + beneficiary: Box::new(VersionedLocation::V4(beneficiary)), + assets: Box::new(VersionedAssets::V4(asset.into())), + fee_asset_item: 0, + weight_limit: WeightLimit::Unlimited, }) } else { None diff --git a/precompiles/xtokens/src/lib.rs b/precompiles/xtokens/src/lib.rs index 28f427fc0a..687f5572f3 100644 --- a/precompiles/xtokens/src/lib.rs +++ b/precompiles/xtokens/src/lib.rs @@ -28,10 +28,12 @@ use sp_runtime::traits::{Convert, Dispatchable}; use sp_std::{boxed::Box, convert::TryInto, marker::PhantomData, vec::Vec}; use sp_weights::Weight; use xcm::{ - latest::{Asset, AssetId, Assets, Fungibility, Junction, Junctions, Location, WeightLimit}, + latest::{Asset, AssetId, Assets, Fungibility, Location, WeightLimit}, VersionedAssets, VersionedLocation, }; -use xcm_primitives::{AccountIdToCurrencyId, DEFAULT_PROOF_SIZE}; +use xcm_primitives::{ + split_location_into_chain_part_and_beneficiary, AccountIdToCurrencyId, DEFAULT_PROOF_SIZE, +}; #[cfg(test)] mod mock; @@ -453,29 +455,3 @@ impl From<(Location, U256)> for EvmAsset { } } } - -fn split_location_into_chain_part_and_beneficiary( - mut location: Location, -) -> Option<(Location, Location)> { - let mut beneficiary_junctions = Junctions::Here; - - // start popping junctions until we reach chain identifier - while let Some(j) = location.last() { - if matches!(j, Junction::Parachain(_) | Junction::GlobalConsensus(_)) { - // return chain subsection - return Some((location, beneficiary_junctions.into_location())); - } else { - let (location_prefix, maybe_last_junction) = location.split_last_interior(); - location = location_prefix; - if let Some(junction) = maybe_last_junction { - beneficiary_junctions.push(junction).ok()?; - } - } - } - - if location.parent_count() == 1 { - Some((Location::parent(), beneficiary_junctions.into_location())) - } else { - None - } -} diff --git a/primitives/xcm/src/lib.rs b/primitives/xcm/src/lib.rs index d63f13327d..50cea8ae5b 100644 --- a/primitives/xcm/src/lib.rs +++ b/primitives/xcm/src/lib.rs @@ -36,4 +36,32 @@ pub use ethereum_xcm::*; mod filter_asset_max_fee; pub use filter_asset_max_fee::*; +use xcm::latest::{Junction, Junctions, Location}; + pub type XcmV2Weight = xcm::v2::Weight; + +pub fn split_location_into_chain_part_and_beneficiary( + mut location: Location, +) -> Option<(Location, Location)> { + let mut beneficiary_junctions = Junctions::Here; + + // start popping junctions until we reach chain identifier + while let Some(j) = location.last() { + if matches!(j, Junction::Parachain(_) | Junction::GlobalConsensus(_)) { + // return chain subsection + return Some((location, beneficiary_junctions.into_location())); + } else { + let (location_prefix, maybe_last_junction) = location.split_last_interior(); + location = location_prefix; + if let Some(junction) = maybe_last_junction { + beneficiary_junctions.push(junction).ok()?; + } + } + } + + if location.parent_count() == 1 { + Some((Location::parent(), beneficiary_junctions.into_location())) + } else { + None + } +} From 464be87cc1fcc5e400fb9644162228faf6c7b5b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Tue, 17 Sep 2024 19:55:44 +0200 Subject: [PATCH 03/24] chore: remove all orml deps (reimplement som primitives) --- Cargo.lock | 86 ------------------- Cargo.toml | 3 - pallets/xcm-transactor/Cargo.toml | 2 - pallets/xcm-transactor/src/encode.rs | 1 - pallets/xcm-transactor/src/lib.rs | 10 +-- precompiles/gmp/Cargo.toml | 1 - precompiles/relay-encoder/Cargo.toml | 3 - precompiles/xcm-transactor/Cargo.toml | 3 - precompiles/xcm-utils/Cargo.toml | 4 - precompiles/xtokens/Cargo.toml | 1 - primitives/xcm/Cargo.toml | 1 - primitives/xcm/src/get_by_key.rs | 57 ++++++++++++ primitives/xcm/src/lib.rs | 13 +-- primitives/xcm/src/origin_conversion.rs | 46 +++++++++- runtime/moonbase/Cargo.toml | 5 -- runtime/moonbase/src/lib.rs | 4 +- runtime/moonbase/src/xcm_config.rs | 31 +------ runtime/moonbase/tests/xcm_mock/parachain.rs | 1 - .../moonbase/tests/xcm_mock/statemint_like.rs | 20 ++++- runtime/moonbeam/Cargo.toml | 5 -- runtime/moonbeam/src/lib.rs | 3 +- runtime/moonbeam/src/xcm_config.rs | 26 +----- runtime/moonbeam/tests/xcm_mock/parachain.rs | 2 +- runtime/moonriver/Cargo.toml | 5 -- runtime/moonriver/src/governance/origins.rs | 2 +- runtime/moonriver/src/lib.rs | 3 +- runtime/moonriver/src/xcm_config.rs | 26 +----- runtime/moonriver/tests/xcm_mock/parachain.rs | 2 +- 28 files changed, 145 insertions(+), 221 deletions(-) create mode 100644 primitives/xcm/src/get_by_key.rs diff --git a/Cargo.lock b/Cargo.lock index 11584e6db7..2fd590c725 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6341,9 +6341,6 @@ dependencies = [ "moonbeam-xcm-benchmarks", "nimbus-primitives", "num_enum 0.5.11", - "orml-traits", - "orml-xcm-support", - "orml-xtokens", "pallet-asset-manager", "pallet-assets", "pallet-async-backing", @@ -6858,9 +6855,6 @@ dependencies = [ "moonbeam-xcm-benchmarks", "nimbus-primitives", "num_enum 0.5.11", - "orml-traits", - "orml-xcm-support", - "orml-xtokens", "pallet-asset-manager", "pallet-assets", "pallet-async-backing", @@ -7285,9 +7279,6 @@ dependencies = [ "moonbeam-xcm-benchmarks", "nimbus-primitives", "num_enum 0.5.11", - "orml-traits", - "orml-xcm-support", - "orml-xtokens", "pallet-asset-manager", "pallet-assets", "pallet-async-backing", @@ -8137,76 +8128,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "orml-traits" -version = "0.10.0" -source = "git+https://github.com/moonbeam-foundation/open-runtime-module-library?branch=moonbeam-polkadot-v1.11.0#f653f239532bd72b6bc4a7290db10790a38b0b92" -dependencies = [ - "frame-support", - "impl-trait-for-tuples", - "num-traits", - "orml-utilities", - "parity-scale-codec", - "paste", - "scale-info", - "serde", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std", - "staging-xcm", -] - -[[package]] -name = "orml-utilities" -version = "0.10.0" -source = "git+https://github.com/moonbeam-foundation/open-runtime-module-library?branch=moonbeam-polkadot-v1.11.0#f653f239532bd72b6bc4a7290db10790a38b0b92" -dependencies = [ - "frame-support", - "parity-scale-codec", - "scale-info", - "serde", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std", -] - -[[package]] -name = "orml-xcm-support" -version = "0.10.0" -source = "git+https://github.com/moonbeam-foundation/open-runtime-module-library?branch=moonbeam-polkadot-v1.11.0#f653f239532bd72b6bc4a7290db10790a38b0b92" -dependencies = [ - "frame-support", - "orml-traits", - "parity-scale-codec", - "sp-runtime", - "sp-std", - "staging-xcm", - "staging-xcm-executor", -] - -[[package]] -name = "orml-xtokens" -version = "0.10.0" -source = "git+https://github.com/moonbeam-foundation/open-runtime-module-library?branch=moonbeam-polkadot-v1.11.0#f653f239532bd72b6bc4a7290db10790a38b0b92" -dependencies = [ - "frame-support", - "frame-system", - "log", - "orml-traits", - "orml-xcm-support", - "pallet-xcm", - "parity-scale-codec", - "scale-info", - "serde", - "sp-io", - "sp-runtime", - "sp-std", - "staging-xcm", - "staging-xcm-executor", -] - [[package]] name = "overload" version = "0.1.1" @@ -9118,7 +9039,6 @@ dependencies = [ "hex-literal 0.3.4", "log", "num_enum 0.5.11", - "orml-traits", "pallet-balances", "pallet-evm", "pallet-timestamp", @@ -9365,7 +9285,6 @@ dependencies = [ "hex-literal 0.3.4", "log", "num_enum 0.5.11", - "orml-traits", "pallet-balances", "pallet-evm", "pallet-message-queue", @@ -9483,7 +9402,6 @@ dependencies = [ "frame-system", "log", "num_enum 0.5.11", - "orml-traits", "pallet-balances", "pallet-evm", "pallet-timestamp", @@ -9516,7 +9434,6 @@ dependencies = [ "frame-support", "frame-system", "num_enum 0.5.11", - "orml-traits", "pallet-balances", "pallet-evm", "pallet-timestamp", @@ -9550,7 +9467,6 @@ dependencies = [ "frame-system", "log", "num_enum 0.5.11", - "orml-traits", "pallet-balances", "pallet-evm", "pallet-timestamp", @@ -10566,7 +10482,6 @@ dependencies = [ "frame-support", "frame-system", "log", - "orml-traits", "pallet-balances", "pallet-timestamp", "pallet-xcm", @@ -18754,7 +18669,6 @@ dependencies = [ "hex", "impl-trait-for-tuples", "log", - "orml-traits", "pallet-staking", "parity-scale-codec", "polkadot-runtime-common", diff --git a/Cargo.toml b/Cargo.toml index 2ea8e23544..5930340e2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -314,9 +314,6 @@ cumulus-relay-chain-minimal-node = { git = "https://github.com/moonbeam-foundati cumulus-relay-chain-rpc-interface = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0" } # Polkadot / XCM (wasm) -orml-traits = { git = "https://github.com/moonbeam-foundation/open-runtime-module-library", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -orml-xcm-support = { git = "https://github.com/moonbeam-foundation/open-runtime-module-library", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -orml-xtokens = { git = "https://github.com/moonbeam-foundation/open-runtime-module-library", branch = "moonbeam-polkadot-v1.11.0", default-features = false } pallet-xcm = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false } pallet-xcm-benchmarks = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false } polkadot-core-primitives = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false } diff --git a/pallets/xcm-transactor/Cargo.toml b/pallets/xcm-transactor/Cargo.toml index db390ca17e..b2a54ecd14 100644 --- a/pallets/xcm-transactor/Cargo.toml +++ b/pallets/xcm-transactor/Cargo.toml @@ -24,7 +24,6 @@ sp-std = { workspace = true } cumulus-primitives-core = { workspace = true } # Polkadot / XCM -orml-traits = { workspace = true } xcm = { workspace = true } xcm-builder = { workspace = true } xcm-executor = { workspace = true } @@ -47,7 +46,6 @@ std = [ "frame-benchmarking/std", "frame-support/std", "frame-system/std", - "orml-traits/std", "parity-scale-codec/std", "sp-io/std", "sp-runtime/std", diff --git a/pallets/xcm-transactor/src/encode.rs b/pallets/xcm-transactor/src/encode.rs index 6d5f3c9113..11e587e2fb 100644 --- a/pallets/xcm-transactor/src/encode.rs +++ b/pallets/xcm-transactor/src/encode.rs @@ -21,7 +21,6 @@ //! Module to provide `StakeEncodeCall`, `HrmpEncodeCall` and `UtilityEncodeCall` implementations //! for the Xcm Transactor pallet -#![cfg_attr(not(feature = "std"), no_std)] use frame_support::pallet_prelude::*; use sp_runtime::traits::{AccountIdLookup, StaticLookup}; use sp_std::prelude::*; diff --git a/pallets/xcm-transactor/src/lib.rs b/pallets/xcm-transactor/src/lib.rs index a6ba5b2024..59a3d8fc53 100644 --- a/pallets/xcm-transactor/src/lib.rs +++ b/pallets/xcm-transactor/src/lib.rs @@ -100,7 +100,6 @@ pub mod pallet { dispatch::DispatchResult, pallet_prelude::*, weights::constants::WEIGHT_REF_TIME_PER_SECOND, }; use frame_system::{ensure_signed, pallet_prelude::*}; - use orml_traits::location::{Parse, Reserve}; use sp_runtime::traits::{AtLeast32BitUnsigned, Bounded, Convert}; use sp_std::boxed::Box; use sp_std::convert::TryFrom; @@ -109,7 +108,7 @@ pub mod pallet { use xcm::{latest::prelude::*, VersionedLocation}; use xcm_executor::traits::{TransactAsset, WeightBounds}; use xcm_primitives::{ - FilterMaxAssetFee, HrmpAvailableCalls, HrmpEncodeCall, UtilityAvailableCalls, + FilterMaxAssetFee, HrmpAvailableCalls, HrmpEncodeCall, Reserve, UtilityAvailableCalls, UtilityEncodeCall, XcmTransact, }; @@ -180,7 +179,7 @@ pub mod pallet { /// The way to retrieve the reserve of a Asset. This can be /// configured to accept absolute or relative paths for self tokens - type ReserveProvider: Reserve; + type ReserveProvider: xcm_primitives::Reserve; /// The way to filter the max fee to use for HRMP management operations type MaxHrmpFee: FilterMaxAssetFee; @@ -1167,8 +1166,9 @@ pub mod pallet { /// Ensure `dest` has chain part and none recipient part. fn ensure_valid_dest(dest: &Location) -> Result { - if let (Some(dest), None) = (dest.chain_part(), dest.non_chain_part()) { - Ok(dest) + let chain_location = dest.chain_location(); + if *dest == chain_location { + Ok(chain_location) } else { Err(Error::::InvalidDest.into()) } diff --git a/precompiles/gmp/Cargo.toml b/precompiles/gmp/Cargo.toml index b273023c9e..e46ab48c12 100644 --- a/precompiles/gmp/Cargo.toml +++ b/precompiles/gmp/Cargo.toml @@ -31,7 +31,6 @@ pallet-evm = { workspace = true, features = ["forbid-evm-reentrancy"] } precompile-utils = { workspace = true } # Polkadot / XCM -orml-traits = { workspace = true } pallet-xcm = { workspace = true } xcm = { workspace = true } xcm-builder = { workspace = true } diff --git a/precompiles/relay-encoder/Cargo.toml b/precompiles/relay-encoder/Cargo.toml index 9679a2777a..c27bf84a8e 100644 --- a/precompiles/relay-encoder/Cargo.toml +++ b/precompiles/relay-encoder/Cargo.toml @@ -55,9 +55,6 @@ xcm = { workspace = true, features = ["std"] } xcm-builder = { workspace = true, features = ["std"] } xcm-executor = { workspace = true, features = ["std"] } -# ORML -orml-traits = { workspace = true, features = ["std"] } - [features] default = ["std"] std = [ diff --git a/precompiles/xcm-transactor/Cargo.toml b/precompiles/xcm-transactor/Cargo.toml index 45eee059e2..8e15b33713 100644 --- a/precompiles/xcm-transactor/Cargo.toml +++ b/precompiles/xcm-transactor/Cargo.toml @@ -55,9 +55,6 @@ pallet-xcm = { workspace = true } xcm-builder = { workspace = true } xcm-executor = { workspace = true } -# ORML -orml-traits = { workspace = true } - [features] default = ["std"] std = [ diff --git a/precompiles/xcm-utils/Cargo.toml b/precompiles/xcm-utils/Cargo.toml index 7d49f6b145..5c5b1a6311 100644 --- a/precompiles/xcm-utils/Cargo.toml +++ b/precompiles/xcm-utils/Cargo.toml @@ -53,15 +53,11 @@ cumulus-primitives-core = { workspace = true } polkadot-parachain = { workspace = true } xcm-builder = { workspace = true } -# ORML -orml-traits = { workspace = true } - [features] default = ["std"] std = [ "frame-support/std", "frame-system/std", - "orml-traits/std", "pallet-balances/std", "pallet-evm/std", "pallet-timestamp/std", diff --git a/precompiles/xtokens/Cargo.toml b/precompiles/xtokens/Cargo.toml index 58c37f62b2..7021b5c4e9 100644 --- a/precompiles/xtokens/Cargo.toml +++ b/precompiles/xtokens/Cargo.toml @@ -51,7 +51,6 @@ sp-io = { workspace = true } cumulus-primitives-core = { workspace = true } # Polkadot -orml-traits = { workspace = true } pallet-xcm = { workspace = true } xcm-builder = { workspace = true } xcm-executor = { workspace = true } diff --git a/primitives/xcm/Cargo.toml b/primitives/xcm/Cargo.toml index c8e7338ba5..1fb2bbe4ae 100644 --- a/primitives/xcm/Cargo.toml +++ b/primitives/xcm/Cargo.toml @@ -33,7 +33,6 @@ sp-std = { workspace = true } cumulus-primitives-core = { workspace = true } # Polkadot / XCM -orml-traits = { workspace = true } polkadot-runtime-common = { workspace = true } xcm = { workspace = true } xcm-builder = { workspace = true } diff --git a/primitives/xcm/src/get_by_key.rs b/primitives/xcm/src/get_by_key.rs new file mode 100644 index 0000000000..7253470269 --- /dev/null +++ b/primitives/xcm/src/get_by_key.rs @@ -0,0 +1,57 @@ +/// A trait for querying a value by a key. +pub trait GetByKey { + /// Return the value. + fn get(k: &Key) -> Value; +} + +/// Create new implementations of the `GetByKey` trait. +/// +/// The implementation is typically used like a map or set. +/// +/// Example: +/// ```ignore +/// use primitives::CurrencyId; +/// parameter_type_with_key! { +/// pub Rates: |currency_id: CurrencyId| -> u32 { +/// match currency_id { +/// CurrencyId::DOT => 1, +/// CurrencyId::KSM => 2, +/// _ => 3, +/// } +/// } +/// } +/// ``` +#[macro_export] +macro_rules! parameter_type_with_key { + ( + pub $name:ident: |$k:ident: $key:ty| -> $value:ty $body:block; + ) => { + pub struct $name; + impl $crate::get_by_key::GetByKey<$key, $value> for $name { + fn get($k: &$key) -> $value { + $body + } + } + }; +} + +#[cfg(test)] +mod tests { + use super::*; + + parameter_type_with_key! { + pub Test: |k: u32| -> u32 { + match k { + 1 => 1, + _ => 2, + } + }; + } + + #[test] + fn get_by_key_should_work() { + assert_eq!(Test::get(&1), 1); + assert_eq!(Test::get(&2), 2); + assert_eq!(Test::get(&3), 2); + } +} diff --git a/primitives/xcm/src/lib.rs b/primitives/xcm/src/lib.rs index 50cea8ae5b..461c725f83 100644 --- a/primitives/xcm/src/lib.rs +++ b/primitives/xcm/src/lib.rs @@ -24,11 +24,8 @@ pub use asset_id_conversions::*; mod constants; pub use constants::*; -mod origin_conversion; -pub use origin_conversion::*; - -mod transactor_traits; -pub use transactor_traits::*; +pub mod get_by_key; +pub use get_by_key::*; mod ethereum_xcm; pub use ethereum_xcm::*; @@ -36,6 +33,12 @@ pub use ethereum_xcm::*; mod filter_asset_max_fee; pub use filter_asset_max_fee::*; +mod origin_conversion; +pub use origin_conversion::*; + +mod transactor_traits; +pub use transactor_traits::*; + use xcm::latest::{Junction, Junctions, Location}; pub type XcmV2Weight = xcm::v2::Weight; diff --git a/primitives/xcm/src/origin_conversion.rs b/primitives/xcm/src/origin_conversion.rs index a215627486..04732f8194 100644 --- a/primitives/xcm/src/origin_conversion.rs +++ b/primitives/xcm/src/origin_conversion.rs @@ -15,10 +15,14 @@ // along with Moonbeam. If not, see . use frame_support::traits::{ContainsPair, Get, OriginTrait}; -use orml_traits::location::{RelativeReserveProvider, Reserve}; use sp_runtime::traits::TryConvert; use sp_std::{convert::TryInto, marker::PhantomData}; -use xcm::latest::{Asset, AssetId, Fungibility, Junction::AccountKey20, Location, NetworkId}; +use xcm::latest::{Asset, AssetId, Fungibility, Junction, Location, NetworkId}; + +pub trait Reserve { + /// Returns assets reserve location. + fn reserve(asset: &Asset) -> Option; +} /// Instructs how to convert a 20 byte accountId into a Location pub struct AccountIdToLocation(sp_std::marker::PhantomData); @@ -29,7 +33,7 @@ where fn convert(account: AccountId) -> Location { Location { parents: 0, - interior: [AccountKey20 { + interior: [Junction::AccountKey20 { network: None, key: account.into(), }] @@ -50,7 +54,7 @@ where { fn try_convert(o: Origin) -> Result { o.try_with_caller(|caller| match caller.try_into() { - Ok(frame_system::RawOrigin::Signed(who)) => Ok(AccountKey20 { + Ok(frame_system::RawOrigin::Signed(who)) => Ok(Junction::AccountKey20 { key: who.into(), network: Some(Network::get()), } @@ -61,6 +65,40 @@ where } } +/// A `ContainsPair` implementation. Filters multi native assets whose +/// reserve is same with `origin`. +pub struct MultiNativeAsset(PhantomData); +impl ContainsPair for MultiNativeAsset +where + ReserveProvider: Reserve, +{ + fn contains(asset: &Asset, origin: &Location) -> bool { + if let Some(ref reserve) = ReserveProvider::reserve(asset) { + if reserve == origin { + return true; + } + } + false + } +} + +// Provide reserve in relative path view +// Self tokens are represeneted as Here +pub struct RelativeReserveProvider; + +impl Reserve for RelativeReserveProvider { + fn reserve(asset: &Asset) -> Option { + let AssetId(location) = &asset.id; + if location.parents == 0 + && !matches!(location.first_interior(), Some(Junction::Parachain(_))) + { + Some(Location::here()) + } else { + Some(location.chain_location()) + } + } +} + /// This struct offers uses RelativeReserveProvider to output relative views of multilocations /// However, additionally accepts a Location that aims at representing the chain part /// (parent: 1, Parachain(paraId)) of the absolute representation of our chain. diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index e1b95f5aaf..03318e0100 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -143,9 +143,6 @@ precompile-utils = { workspace = true } # Polkadot / XCM -orml-traits = { workspace = true } -orml-xcm-support = { workspace = true } -orml-xtokens = { workspace = true } pallet-xcm = { workspace = true } pallet-xcm-benchmarks = { workspace = true, optional = true } pallet-message-queue = { workspace = true } @@ -234,7 +231,6 @@ std = [ "moonbeam-runtime-common/std", "moonkit-xcm-primitives/std", "nimbus-primitives/std", - "orml-xtokens/std", "pallet-asset-manager/std", "pallet-assets/std", "pallet-async-backing/std", @@ -442,7 +438,6 @@ try-runtime = [ "pallet-crowdloan-rewards/try-runtime", "pallet-proxy/try-runtime", "pallet-identity/try-runtime", - "orml-xtokens/try-runtime", "pallet-assets/try-runtime", "pallet-xcm-transactor/try-runtime", "pallet-proxy-genesis-companion/try-runtime", diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index fe4204b6f1..0a57477abb 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1176,7 +1176,6 @@ impl Contains for MaintenanceFilter { RuntimeCall::Ethereum(_) => false, RuntimeCall::EVM(_) => false, RuntimeCall::Identity(_) => false, - RuntimeCall::XTokens(_) => false, RuntimeCall::ParachainStaking(_) => false, RuntimeCall::MoonbeamOrbiters(_) => false, RuntimeCall::PolkadotXcm(_) => false, @@ -1420,7 +1419,7 @@ construct_runtime! { DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 27, PolkadotXcm: pallet_xcm::{Pallet, Call, Storage, Event, Origin, Config} = 28, Assets: pallet_assets::{Pallet, Call, Storage, Event} = 29, - XTokens: orml_xtokens::{Pallet, Call, Storage, Event} = 30, + //XTokens: orml_xtokens::{Pallet, Call, Storage, Event} = 30, AssetManager: pallet_asset_manager::{Pallet, Call, Storage, Event} = 31, Migrations: pallet_migrations::{Pallet, Storage, Config, Event} = 32, XcmTransactor: pallet_xcm_transactor::{Pallet, Call, Config, Storage, Event} = 33, @@ -1692,7 +1691,6 @@ mod tests { assert!( std::mem::size_of::>() <= CALL_ALIGN as usize ); - assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); assert!( diff --git a/runtime/moonbase/src/xcm_config.rs b/runtime/moonbase/src/xcm_config.rs index 253f898c6d..76d2132be2 100644 --- a/runtime/moonbase/src/xcm_config.rs +++ b/runtime/moonbase/src/xcm_config.rs @@ -58,11 +58,10 @@ use xcm::latest::prelude::{ use xcm_executor::traits::{CallDispatcher, ConvertLocation, JustTry}; use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; -use orml_xcm_support::MultiNativeAsset; use xcm_primitives::{ AbsoluteAndRelativeReserve, AccountIdToCurrencyId, AccountIdToLocation, AsAssetType, - IsBridgedConcreteAssetFrom, SignedToAccountId20, UtilityAvailableCalls, UtilityEncodeCall, - XcmTransact, + IsBridgedConcreteAssetFrom, MultiNativeAsset, SignedToAccountId20, UtilityAvailableCalls, + UtilityEncodeCall, XcmTransact, }; use parity_scale_codec::{Decode, Encode}; @@ -74,8 +73,6 @@ use sp_std::{ prelude::*, }; -use orml_traits::parameter_type_with_key; - use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot}; parameter_types! { @@ -586,7 +583,7 @@ parameter_types! { } -parameter_type_with_key! { +xcm_primitives::parameter_type_with_key! { pub ParachainMinFee: |location: Location| -> Option { match (location.parents, location.first_interior()) { // AssetHub fee @@ -596,28 +593,6 @@ parameter_type_with_key! { }; } -impl orml_xtokens::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Balance = Balance; - type CurrencyId = CurrencyId; - type AccountIdToLocation = AccountIdToLocation; - type CurrencyIdConvert = CurrencyIdToLocation<( - EvmForeignAssets, - AsAssetType, - )>; - type XcmExecutor = XcmExecutor; - type SelfLocation = SelfLocation; - type Weigher = XcmWeigher; - type BaseXcmWeight = BaseXcmWeight; - type UniversalLocation = UniversalLocation; - type MaxAssetsForTransfer = MaxAssetsForTransfer; - type MinXcmFee = ParachainMinFee; - type LocationsFilter = Everything; - type ReserveProvider = AbsoluteAndRelativeReserve; - type RateLimiter = (); - type RateLimiterId = (); -} - // 1 WND/ROC should be enough parameter_types! { pub MaxHrmpRelayFee: Asset = (Location::parent(), 1_000_000_000_000u128).into(); diff --git a/runtime/moonbase/tests/xcm_mock/parachain.rs b/runtime/moonbase/tests/xcm_mock/parachain.rs index 7dbc8584aa..cd180f797e 100644 --- a/runtime/moonbase/tests/xcm_mock/parachain.rs +++ b/runtime/moonbase/tests/xcm_mock/parachain.rs @@ -39,7 +39,6 @@ use sp_std::{convert::TryFrom, prelude::*}; use xcm::{latest::prelude::*, Version as XcmVersion, VersionedXcm}; use cumulus_primitives_core::relay_chain::HrmpChannelId; -use orml_traits::parameter_type_with_key; use pallet_ethereum::PostLogContent; use polkadot_core_primitives::BlockNumber as RelayBlockNumber; use polkadot_parachain::primitives::{Id as ParaId, Sibling}; diff --git a/runtime/moonbase/tests/xcm_mock/statemint_like.rs b/runtime/moonbase/tests/xcm_mock/statemint_like.rs index 594919836f..51aa33d63f 100644 --- a/runtime/moonbase/tests/xcm_mock/statemint_like.rs +++ b/runtime/moonbase/tests/xcm_mock/statemint_like.rs @@ -315,14 +315,30 @@ impl> ContainsPair pub type TrustedTeleporters = (ConcreteAssetFromRelay,); +/// Trust reserves from sibling parachains, relay chain, and here +pub struct TrustedReserves; +impl ContainsPair for IsReserve { + fn contains(asset: &Asset, origin: &Location) -> bool { + let AssetId(location) = &asset.id; + match (&asset.id.0.parent_count(), &asset.id.0.first_interior()) { + // Sibling parachains + (1, Junctions::Parachain(id)) => location.chain_location() == origin, + // Relay chain + (1, _) => location.chain_location() == origin, + // Here + (0, _) => Location::here() == origin, + _ => false, + } + } +} + pub struct XcmConfig; impl Config for XcmConfig { type RuntimeCall = RuntimeCall; type XcmSender = XcmRouter; type AssetTransactor = AssetTransactors; type OriginConverter = XcmOriginToTransactDispatchOrigin; - type IsReserve = - orml_xcm_support::MultiNativeAsset; + type IsReserve = TrustedReserves; type IsTeleporter = TrustedTeleporters; type UniversalLocation = UniversalLocation; type Barrier = Barrier; diff --git a/runtime/moonbeam/Cargo.toml b/runtime/moonbeam/Cargo.toml index 7d956c0b7b..2a800f1b31 100644 --- a/runtime/moonbeam/Cargo.toml +++ b/runtime/moonbeam/Cargo.toml @@ -138,9 +138,6 @@ pallet-evm-precompile-simple = { workspace = true } precompile-utils = { workspace = true } # Polkadot / XCM -orml-traits = { workspace = true } -orml-xcm-support = { workspace = true } -orml-xtokens = { workspace = true } pallet-xcm = { workspace = true } pallet-xcm-benchmarks = { workspace = true, optional = true } pallet-message-queue = { workspace = true } @@ -228,7 +225,6 @@ std = [ "moonbeam-xcm-benchmarks/std", "moonkit-xcm-primitives/std", "nimbus-primitives/std", - "orml-xtokens/std", "pallet-asset-manager/std", "pallet-assets/std", "pallet-async-backing/std", @@ -425,7 +421,6 @@ try-runtime = [ "pallet-crowdloan-rewards/try-runtime", "pallet-proxy/try-runtime", "pallet-identity/try-runtime", - "orml-xtokens/try-runtime", "pallet-assets/try-runtime", "pallet-xcm-transactor/try-runtime", "pallet-proxy-genesis-companion/try-runtime", diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 6fb184398a..0a8e26b5ee 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -1160,7 +1160,6 @@ impl Contains for MaintenanceFilter { RuntimeCall::Ethereum(_) => false, RuntimeCall::EVM(_) => false, RuntimeCall::Identity(_) => false, - RuntimeCall::XTokens(_) => false, RuntimeCall::ParachainStaking(_) => false, RuntimeCall::MoonbeamOrbiters(_) => false, RuntimeCall::PolkadotXcm(_) => false, @@ -1441,7 +1440,7 @@ construct_runtime! { PolkadotXcm: pallet_xcm::{Pallet, Storage, Call, Event, Origin, Config} = 103, Assets: pallet_assets::{Pallet, Call, Storage, Event} = 104, AssetManager: pallet_asset_manager::{Pallet, Call, Storage, Event} = 105, - XTokens: orml_xtokens::{Pallet, Call, Storage, Event} = 106, + //XTokens: orml_xtokens::{Pallet, Call, Storage, Event} = 106, XcmTransactor: pallet_xcm_transactor::{Pallet, Call, Storage, Event} = 107, // Previously 108: pallet_assets:: EthereumXcm: pallet_ethereum_xcm::{Pallet, Call, Storage, Origin, Event} = 109, diff --git a/runtime/moonbeam/src/xcm_config.rs b/runtime/moonbeam/src/xcm_config.rs index 7ffab1d7d9..8e5789ff1b 100644 --- a/runtime/moonbeam/src/xcm_config.rs +++ b/runtime/moonbeam/src/xcm_config.rs @@ -57,11 +57,10 @@ use xcm::latest::prelude::{ use xcm_executor::traits::{CallDispatcher, ConvertLocation, JustTry}; use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; -use orml_xcm_support::MultiNativeAsset; use xcm_primitives::{ AbsoluteAndRelativeReserve, AccountIdToCurrencyId, AccountIdToLocation, AsAssetType, - IsBridgedConcreteAssetFrom, SignedToAccountId20, UtilityAvailableCalls, UtilityEncodeCall, - XcmTransact, + IsBridgedConcreteAssetFrom, MultiNativeAsset, SignedToAccountId20, UtilityAvailableCalls, + UtilityEncodeCall, XcmTransact, }; use parity_scale_codec::{Decode, Encode}; @@ -73,7 +72,7 @@ use sp_std::{ prelude::*, }; -use orml_traits::parameter_type_with_key; +use xcm_primitives::parameter_type_with_key; use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot}; @@ -584,25 +583,6 @@ parameter_type_with_key! { }; } -impl orml_xtokens::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Balance = Balance; - type CurrencyId = CurrencyId; - type AccountIdToLocation = AccountIdToLocation; - type CurrencyIdConvert = CurrencyIdToLocation>; - type XcmExecutor = XcmExecutor; - type SelfLocation = SelfLocation; - type Weigher = XcmWeigher; - type BaseXcmWeight = BaseXcmWeight; - type UniversalLocation = UniversalLocation; - type MaxAssetsForTransfer = MaxAssetsForTransfer; - type MinXcmFee = ParachainMinFee; - type LocationsFilter = Everything; - type ReserveProvider = AbsoluteAndRelativeReserve; - type RateLimiter = (); - type RateLimiterId = (); -} - // 1 DOT should be enough parameter_types! { pub MaxHrmpRelayFee: Asset = (Location::parent(), 1_000_000_000_000u128).into(); diff --git a/runtime/moonbeam/tests/xcm_mock/parachain.rs b/runtime/moonbeam/tests/xcm_mock/parachain.rs index 3f41bcad58..db2ade3048 100644 --- a/runtime/moonbeam/tests/xcm_mock/parachain.rs +++ b/runtime/moonbeam/tests/xcm_mock/parachain.rs @@ -40,7 +40,6 @@ use sp_std::{convert::TryFrom, prelude::*}; use xcm::{latest::prelude::*, Version as XcmVersion, VersionedXcm}; use cumulus_primitives_core::relay_chain::HrmpChannelId; -use orml_traits::parameter_type_with_key; use pallet_ethereum::PostLogContent; use polkadot_core_primitives::BlockNumber as RelayBlockNumber; use polkadot_parachain::primitives::{Id as ParaId, Sibling}; @@ -58,6 +57,7 @@ use xcm_builder::{ TakeWeightCredit, WithComputedOrigin, }; use xcm_executor::{traits::JustTry, Config, XcmExecutor}; +use xcm_primitives::parameter_type_with_key; #[cfg(feature = "runtime-benchmarks")] use moonbeam_runtime_common::benchmarking::BenchmarkHelper as ArgumentsBenchmarkHelper; diff --git a/runtime/moonriver/Cargo.toml b/runtime/moonriver/Cargo.toml index cac100dbe2..15e83b7d85 100644 --- a/runtime/moonriver/Cargo.toml +++ b/runtime/moonriver/Cargo.toml @@ -139,9 +139,6 @@ pallet-evm-precompile-simple = { workspace = true } precompile-utils = { workspace = true } # Polkadot / XCM -orml-traits = { workspace = true } -orml-xcm-support = { workspace = true } -orml-xtokens = { workspace = true } pallet-xcm = { workspace = true } pallet-xcm-benchmarks = { workspace = true, optional = true } polkadot-core-primitives = { workspace = true } @@ -229,7 +226,6 @@ std = [ "moonbeam-xcm-benchmarks/std", "moonkit-xcm-primitives/std", "nimbus-primitives/std", - "orml-xtokens/std", "pallet-asset-manager/std", "pallet-assets/std", "pallet-async-backing/std", @@ -429,7 +425,6 @@ try-runtime = [ "pallet-crowdloan-rewards/try-runtime", "pallet-proxy/try-runtime", "pallet-identity/try-runtime", - "orml-xtokens/try-runtime", "pallet-assets/try-runtime", "pallet-async-backing/try-runtime", "pallet-xcm-transactor/try-runtime", diff --git a/runtime/moonriver/src/governance/origins.rs b/runtime/moonriver/src/governance/origins.rs index ef4675d629..bbfebcafe6 100644 --- a/runtime/moonriver/src/governance/origins.rs +++ b/runtime/moonriver/src/governance/origins.rs @@ -12,7 +12,7 @@ // GNU General Public License for more details. //! Custom origins for governance interventions. -#![cfg_attr(not(feature = "std"), no_std)] + pub use custom_origins::*; #[frame_support::pallet] diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 1aadd64b94..432251e00c 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -1164,7 +1164,6 @@ impl Contains for MaintenanceFilter { RuntimeCall::Ethereum(_) => false, RuntimeCall::EVM(_) => false, RuntimeCall::Identity(_) => false, - RuntimeCall::XTokens(_) => false, RuntimeCall::ParachainStaking(_) => false, RuntimeCall::MoonbeamOrbiters(_) => false, RuntimeCall::PolkadotXcm(_) => false, @@ -1444,7 +1443,7 @@ construct_runtime! { PolkadotXcm: pallet_xcm::{Pallet, Storage, Call, Event, Origin, Config} = 103, Assets: pallet_assets::{Pallet, Call, Storage, Event} = 104, AssetManager: pallet_asset_manager::{Pallet, Call, Storage, Event} = 105, - XTokens: orml_xtokens::{Pallet, Call, Storage, Event} = 106, + //XTokens: orml_xtokens::{Pallet, Call, Storage, Event} = 106, XcmTransactor: pallet_xcm_transactor::{Pallet, Call, Storage, Event} = 107, // Previously 108: pallet_assets:: EthereumXcm: pallet_ethereum_xcm::{Pallet, Call, Storage, Origin, Event} = 109, diff --git a/runtime/moonriver/src/xcm_config.rs b/runtime/moonriver/src/xcm_config.rs index cf55c3db0b..7f3b122880 100644 --- a/runtime/moonriver/src/xcm_config.rs +++ b/runtime/moonriver/src/xcm_config.rs @@ -57,11 +57,10 @@ use xcm::latest::prelude::{ use xcm_executor::traits::{CallDispatcher, ConvertLocation, JustTry}; use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; -use orml_xcm_support::MultiNativeAsset; use xcm_primitives::{ AbsoluteAndRelativeReserve, AccountIdToCurrencyId, AccountIdToLocation, AsAssetType, - IsBridgedConcreteAssetFrom, SignedToAccountId20, UtilityAvailableCalls, UtilityEncodeCall, - XcmTransact, + IsBridgedConcreteAssetFrom, MultiNativeAsset, SignedToAccountId20, UtilityAvailableCalls, + UtilityEncodeCall, XcmTransact, }; use parity_scale_codec::{Decode, Encode}; @@ -73,7 +72,7 @@ use sp_std::{ prelude::*, }; -use orml_traits::parameter_type_with_key; +use xcm_primitives::parameter_type_with_key; use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot}; @@ -597,25 +596,6 @@ parameter_type_with_key! { }; } -impl orml_xtokens::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Balance = Balance; - type CurrencyId = CurrencyId; - type AccountIdToLocation = AccountIdToLocation; - type CurrencyIdConvert = CurrencyIdToLocation>; - type XcmExecutor = XcmExecutor; - type SelfLocation = SelfLocation; - type Weigher = XcmWeigher; - type BaseXcmWeight = BaseXcmWeight; - type UniversalLocation = UniversalLocation; - type MaxAssetsForTransfer = MaxAssetsForTransfer; - type MinXcmFee = ParachainMinFee; - type LocationsFilter = Everything; - type ReserveProvider = AbsoluteAndRelativeReserve; - type RateLimiter = (); - type RateLimiterId = (); -} - // 1 KSM should be enough parameter_types! { pub MaxHrmpRelayFee: Asset = (Location::parent(), 1_000_000_000_000u128).into(); diff --git a/runtime/moonriver/tests/xcm_mock/parachain.rs b/runtime/moonriver/tests/xcm_mock/parachain.rs index e71bc1e21e..6622960775 100644 --- a/runtime/moonriver/tests/xcm_mock/parachain.rs +++ b/runtime/moonriver/tests/xcm_mock/parachain.rs @@ -38,7 +38,6 @@ use sp_std::{convert::TryFrom, prelude::*}; use xcm::{latest::prelude::*, Version as XcmVersion, VersionedXcm}; use cumulus_primitives_core::relay_chain::HrmpChannelId; -use orml_traits::parameter_type_with_key; use pallet_ethereum::PostLogContent; use polkadot_core_primitives::BlockNumber as RelayBlockNumber; use polkadot_parachain::primitives::{Id as ParaId, Sibling}; @@ -56,6 +55,7 @@ use xcm_builder::{ TakeWeightCredit, WithComputedOrigin, }; use xcm_executor::{traits::JustTry, Config, XcmExecutor}; +use xcm_primitives::parameter_type_with_key; #[cfg(feature = "runtime-benchmarks")] use moonbeam_runtime_common::benchmarking::BenchmarkHelper as ArgumentsBenchmarkHelper; From a1a1f801a23dbf825a7b09453b57236a1e57698a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Tue, 24 Sep 2024 12:33:49 +0200 Subject: [PATCH 04/24] update some comments --- pallets/parachain-staking/src/set.rs | 2 -- runtime/moonbase/src/lib.rs | 2 +- runtime/moonbeam/src/lib.rs | 2 +- runtime/moonriver/src/lib.rs | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pallets/parachain-staking/src/set.rs b/pallets/parachain-staking/src/set.rs index 2fb15ffadf..9db24f4724 100644 --- a/pallets/parachain-staking/src/set.rs +++ b/pallets/parachain-staking/src/set.rs @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moonbeam. If not, see . -/* TODO: use orml_utilities::OrderedSet without leaking substrate v2.0 dependencies*/ - use frame_support::traits::Get; use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 0a57477abb..21bb001f2a 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1419,7 +1419,7 @@ construct_runtime! { DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 27, PolkadotXcm: pallet_xcm::{Pallet, Call, Storage, Event, Origin, Config} = 28, Assets: pallet_assets::{Pallet, Call, Storage, Event} = 29, - //XTokens: orml_xtokens::{Pallet, Call, Storage, Event} = 30, + // Previously 30: XTokens AssetManager: pallet_asset_manager::{Pallet, Call, Storage, Event} = 31, Migrations: pallet_migrations::{Pallet, Storage, Config, Event} = 32, XcmTransactor: pallet_xcm_transactor::{Pallet, Call, Config, Storage, Event} = 33, diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 0a8e26b5ee..8d468f341a 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -1440,7 +1440,7 @@ construct_runtime! { PolkadotXcm: pallet_xcm::{Pallet, Storage, Call, Event, Origin, Config} = 103, Assets: pallet_assets::{Pallet, Call, Storage, Event} = 104, AssetManager: pallet_asset_manager::{Pallet, Call, Storage, Event} = 105, - //XTokens: orml_xtokens::{Pallet, Call, Storage, Event} = 106, + // Previously 106: XTokens XcmTransactor: pallet_xcm_transactor::{Pallet, Call, Storage, Event} = 107, // Previously 108: pallet_assets:: EthereumXcm: pallet_ethereum_xcm::{Pallet, Call, Storage, Origin, Event} = 109, diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 432251e00c..7480c04770 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -1443,7 +1443,7 @@ construct_runtime! { PolkadotXcm: pallet_xcm::{Pallet, Storage, Call, Event, Origin, Config} = 103, Assets: pallet_assets::{Pallet, Call, Storage, Event} = 104, AssetManager: pallet_asset_manager::{Pallet, Call, Storage, Event} = 105, - //XTokens: orml_xtokens::{Pallet, Call, Storage, Event} = 106, + // Previously 106: XTokens XcmTransactor: pallet_xcm_transactor::{Pallet, Call, Storage, Event} = 107, // Previously 108: pallet_assets:: EthereumXcm: pallet_ethereum_xcm::{Pallet, Call, Storage, Origin, Event} = 109, From 87092791212f21dbcc94529e7b55ac112d78e570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Tue, 24 Sep 2024 12:54:13 +0200 Subject: [PATCH 05/24] fix dev-test maintenance-filter --- .../test-maintenance-filter.ts | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter.ts b/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter.ts index 0d8bf793f5..1b9e986f90 100644 --- a/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter.ts +++ b/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter.ts @@ -148,29 +148,51 @@ describeSuite({ it({ id: "T05", - title: "should forbid xtokens transfer", + title: "should forbid xcm transfer", test: async () => { expect( async () => await context.createBlock( context .polkadotJs() - .tx.xTokens.transfer( - "SelfReserve", //enum - 100n * GLMR, + .tx.polkadotXcm.transferAssets( + // Destination { - V3: { + V4: { parents: 1n, interior: { - X2: [ - { Parachain: 2000n }, + X1: [{ Parachain: 2000n }] + } + }, + } as any, + // Beneficiary + { + V4: { + parents: 0n, + interior: { + X1: [ { AccountKey20: { network: null, key: hexToU8a(baltathar.address) } }, - ], + ] }, }, } as any, + // Assets + { + V4: [{ + id: { + V4: { + parents: 0n, + interior: { + Here: null, + }, + } + }, + fun: { Fungible: 100n * GLMR }, + }] + }, + 0, // FeeAssetItem { - Limited: { refTime: 4000000000, proofSize: 64 * 1024 }, + Limited: { refTime: 8000000000, proofSize: 128 * 1024 }, } ) .signAsync(baltathar) From 0c469fea22bb80af7ee2ac3e0453e479c8c89c94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Tue, 24 Sep 2024 13:31:05 +0200 Subject: [PATCH 06/24] transferWithFee and transferMultiassetWithFee ignore fee parameter now --- .../test-precompile/test-precompile-xtokens.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-xtokens.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-xtokens.ts index d5872abc4a..9cf563a8c5 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-xtokens.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-xtokens.ts @@ -61,7 +61,8 @@ describeSuite({ }, }); - it({ + // transferWithFee behave the same as transfer now + /*it({ id: "T02", title: "allows to issue transfer xtokens with fee", test: async function () { @@ -105,7 +106,7 @@ describeSuite({ expect(balBefore - balAfter).to.equal(amountTransferred + fee + fees); await verifyLatestBlockFees(context, amountTransferred + fee); }, - }); + });*/ it({ id: "T03", @@ -167,7 +168,8 @@ describeSuite({ }, }); - it({ + // transferMultiassetWithFee behacve the same as transferMultiasset now + /*it({ id: "T04", title: "allows to issue transfer_multiasset xtokens with fee", test: async function () { @@ -226,7 +228,7 @@ describeSuite({ expect(balBefore - balAfter).to.equal(amountTransferred + fee + fees); await verifyLatestBlockFees(context, amountTransferred + fee); }, - }); + });*/ it({ id: "T05", From 0be705fce990568d0b98f0d2354eb57da071cce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Tue, 24 Sep 2024 20:47:43 +0200 Subject: [PATCH 07/24] fix dev-test wormhole --- .../test-precompile-wormhole.ts | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-wormhole.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-wormhole.ts index 02905121ee..9196331a84 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-wormhole.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-wormhole.ts @@ -375,11 +375,9 @@ describeSuite({ } expectEVMResult(block.result.events, "Succeed", "Returned"); - const events = expectSubstrateEvents(block, "xTokens", "TransferredAssets"); - const transferFungible = events[0].data[1][0].fun; - expect(transferFungible.isFungible); - const transferAmount = transferFungible.asFungible.toBigInt(); - expect(transferAmount).to.eq(realAmount); + const events = expectSubstrateEvents(block, "polkadotXcm", "Attempted"); + const outcomeEvent = events[0].data[0]; + expect(outcomeEvent.isComplete); }, }); @@ -426,11 +424,9 @@ describeSuite({ } expectEVMResult(block.result.events, "Succeed", "Returned"); - const events = expectSubstrateEvents(block, "xTokens", "TransferredAssets"); - const transferFungible = events[0].data[1][0].fun; - expect(transferFungible.isFungible); - const transferAmount = transferFungible.asFungible.toBigInt(); - expect(transferAmount).to.eq(realAmount - fee); + const events = expectSubstrateEvents(block, "polkadotXcm", "Attempted"); + const outcomeEvent = events[0].data[0]; + expect(outcomeEvent.isComplete); const alithWHTokenAfter = await whWethContract.balanceOf(ALITH_ADDRESS); expect(alithWHTokenAfter - alithWHTokenBefore).to.eq(fee); @@ -481,7 +477,7 @@ describeSuite({ expectEVMResult(block.result.events, "Succeed", "Returned"); // there should be no xTokens TransferredMultiAssets event since fee >= amount sent - const events = expectSubstrateEvents(block!, "xTokens", "TransferredAssets"); + const events = expectSubstrateEvents(block!, "polkadotXcm", "Attempted"); expect(events.length).to.eq(0); // TODO: isn't expectSubstrateEvents supposed to expect > 0? const alithWHTokenAfter = await whWethContract.balanceOf(ALITH_ADDRESS); @@ -532,11 +528,9 @@ describeSuite({ } expectEVMResult(block.result.events, "Succeed", "Returned"); - const events = expectSubstrateEvents(block, "xTokens", "TransferredAssets"); - const transferFungible = events[0].data[1][0].fun; - expect(transferFungible.isFungible); - const transferAmount = transferFungible.asFungible.toBigInt(); - expect(transferAmount).to.eq(realAmount); + const events = expectSubstrateEvents(block, "polkadotXcm", "Attempted"); + const outcomeEvent = events[0].data[0]; + expect(outcomeEvent.isComplete); // no fee paid const alithWHTokenAfter = await whWethContract.balanceOf(ALITH_ADDRESS); From f1525974aa7a403c2588becbac1b620580f5179c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Tue, 24 Sep 2024 20:49:55 +0200 Subject: [PATCH 08/24] fix dev-test wormhole (2) --- .../moonbase/test-precompile/test-precompile-wormhole.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-wormhole.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-wormhole.ts index 9196331a84..da36d5e40a 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-wormhole.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-wormhole.ts @@ -638,11 +638,9 @@ describeSuite({ } expectEVMResult(result.result.events, "Succeed", "Returned"); - const events = expectSubstrateEvents(result, "xTokens", "TransferredAssets"); - const transferFungible = events[0].data[1][0].fun; - expect(transferFungible.isFungible); - const transferAmount = transferFungible.asFungible.toBigInt(); - expect(transferAmount).to.eq(realAmount); + const events = expectSubstrateEvents(result, "polkadotXcm", "Attempted"); + const outcomeEvent = events[0].data[0]; + expect(outcomeEvent.isComplete); }, }); }, From 338a7c7b4733cf6f52e17222de67ad33347fd295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Thu, 26 Sep 2024 12:07:37 +0200 Subject: [PATCH 09/24] wip: example --- runtime/moonbase/tests/xcm_tests.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/runtime/moonbase/tests/xcm_tests.rs b/runtime/moonbase/tests/xcm_tests.rs index e9234554ff..c69c4eb64b 100644 --- a/runtime/moonbase/tests/xcm_tests.rs +++ b/runtime/moonbase/tests/xcm_tests.rs @@ -192,6 +192,31 @@ fn send_relay_asset_to_relay() { ParaA::execute_with(|| { // free execution, full amount received + assert_ok!(PolkadotXcm::transfer_assets( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + // dest chain part + Location::parent(), + // beneficiary + Location { + parents: 0, + interior: [AccountId32 { + network: None, + id: RELAYALICE.into(), + }] + .into(), + }, + // assets + Asset { + id: Location, + fun: Fungibility::Fungible(1232) + }.into(), + // feeitem + 0, + // weightLimit + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + assert_ok!(XTokens::transfer( parachain::RuntimeOrigin::signed(PARAALICE.into()), parachain::CurrencyId::ForeignAsset(source_id), From 292fc09f0e6b008c547eab3aa092d6336f27432f Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Thu, 3 Oct 2024 12:25:48 +0200 Subject: [PATCH 10/24] remove unused code --- runtime/moonbase/src/xcm_config.rs | 10 ---------- runtime/moonbeam/src/xcm_config.rs | 12 ------------ runtime/moonriver/src/xcm_config.rs | 12 ------------ 3 files changed, 34 deletions(-) diff --git a/runtime/moonbase/src/xcm_config.rs b/runtime/moonbase/src/xcm_config.rs index 76d2132be2..14c679a18d 100644 --- a/runtime/moonbase/src/xcm_config.rs +++ b/runtime/moonbase/src/xcm_config.rs @@ -583,16 +583,6 @@ parameter_types! { } -xcm_primitives::parameter_type_with_key! { - pub ParachainMinFee: |location: Location| -> Option { - match (location.parents, location.first_interior()) { - // AssetHub fee - (1, Some(Parachain(1001u32))) => Some(50_000_000u128), - _ => None, - } - }; -} - // 1 WND/ROC should be enough parameter_types! { pub MaxHrmpRelayFee: Asset = (Location::parent(), 1_000_000_000_000u128).into(); diff --git a/runtime/moonbeam/src/xcm_config.rs b/runtime/moonbeam/src/xcm_config.rs index 8e5789ff1b..4b84c688aa 100644 --- a/runtime/moonbeam/src/xcm_config.rs +++ b/runtime/moonbeam/src/xcm_config.rs @@ -72,8 +72,6 @@ use sp_std::{ prelude::*, }; -use xcm_primitives::parameter_type_with_key; - use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot}; parameter_types! { @@ -573,16 +571,6 @@ parameter_types! { }; } -parameter_type_with_key! { - pub ParachainMinFee: |location: Location| -> Option { - match (location.parents, location.first_interior()) { - // Polkadot AssetHub fee - (1, Some(Parachain(1000u32))) => Some(50_000_000u128), - _ => None, - } - }; -} - // 1 DOT should be enough parameter_types! { pub MaxHrmpRelayFee: Asset = (Location::parent(), 1_000_000_000_000u128).into(); diff --git a/runtime/moonriver/src/xcm_config.rs b/runtime/moonriver/src/xcm_config.rs index 7f3b122880..04b5000edf 100644 --- a/runtime/moonriver/src/xcm_config.rs +++ b/runtime/moonriver/src/xcm_config.rs @@ -72,8 +72,6 @@ use sp_std::{ prelude::*, }; -use xcm_primitives::parameter_type_with_key; - use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot}; parameter_types! { @@ -586,16 +584,6 @@ parameter_types! { }; } -parameter_type_with_key! { - pub ParachainMinFee: |location: Location| -> Option { - match (location.parents, location.first_interior()) { - // Kusama AssetHub fee - (1, Some(Parachain(1000u32))) => Some(50_000_000u128), - _ => None, - } - }; -} - // 1 KSM should be enough parameter_types! { pub MaxHrmpRelayFee: Asset = (Location::parent(), 1_000_000_000_000u128).into(); From 18a5f0a1d2dccfbd068afcaacbf0b38ef008122e Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Fri, 4 Oct 2024 10:42:27 +0200 Subject: [PATCH 11/24] remove orml dependencies from mocks and fix compilation --- pallets/xcm-transactor/src/mock.rs | 6 +- precompiles/gmp/src/mock.rs | 117 ++++++++++++----- precompiles/relay-encoder/src/mock.rs | 9 +- precompiles/xcm-transactor/src/mock.rs | 6 +- precompiles/xtokens/src/mock.rs | 119 +++++++++++++----- runtime/moonbase/tests/xcm_mock/mod.rs | 1 - runtime/moonbase/tests/xcm_mock/parachain.rs | 33 +---- runtime/moonbeam/tests/xcm_mock/mod.rs | 1 - runtime/moonbeam/tests/xcm_mock/parachain.rs | 33 +---- .../moonbeam/tests/xcm_mock/statemint_like.rs | 3 +- runtime/moonriver/tests/xcm_mock/mod.rs | 1 - runtime/moonriver/tests/xcm_mock/parachain.rs | 33 +---- 12 files changed, 201 insertions(+), 161 deletions(-) diff --git a/pallets/xcm-transactor/src/mock.rs b/pallets/xcm-transactor/src/mock.rs index f641d187cb..a6576dcccc 100644 --- a/pallets/xcm-transactor/src/mock.rs +++ b/pallets/xcm-transactor/src/mock.rs @@ -380,6 +380,10 @@ impl SendXcm for TestSendXcm { parameter_types! { pub MaxFee: Asset = (Location::parent(), 1_000_000_000_000u128).into(); + pub SelfLocationAbsolute: Location = Location { + parents: 1, + interior: [Parachain(ParachainId::get().into())].into(), + }; } pub type MaxHrmpRelayFee = xcm_builder::Case; @@ -398,7 +402,7 @@ impl Config for Test { type UniversalLocation = UniversalLocation; type BaseXcmWeight = BaseXcmWeight; type XcmSender = TestSendXcm; - type ReserveProvider = orml_traits::location::RelativeReserveProvider; + type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; type WeightInfo = (); type HrmpManipulatorOrigin = EnsureRoot; type HrmpOpenOrigin = EnsureRoot; diff --git a/precompiles/gmp/src/mock.rs b/precompiles/gmp/src/mock.rs index 28f5621f9e..4d82374d87 100644 --- a/precompiles/gmp/src/mock.rs +++ b/precompiles/gmp/src/mock.rs @@ -16,11 +16,11 @@ //! Test utilities use super::*; +use cumulus_primitives_core::{relay_chain::HrmpChannelId, ParaId}; use frame_support::traits::{ EnsureOrigin, Everything, Nothing, OriginTrait, PalletInfo as PalletInfoTrait, }; use frame_support::{construct_runtime, parameter_types, weights::Weight}; -use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key}; use pallet_evm::{EnsureAddressNever, EnsureAddressRoot}; use parity_scale_codec::{Decode, Encode}; use precompile_utils::{mock_account, precompile_set::*, testing::MockAccount}; @@ -35,7 +35,7 @@ use xcm::latest::{prelude::*, Error as XcmError}; use xcm_builder::{AllowUnpaidExecutionFrom, FixedWeightBounds}; use xcm_executor::{ traits::{TransactAsset, WeightTrader}, - AssetsInHolding, XcmExecutor, + AssetsInHolding, }; use xcm_primitives::XcmV2Weight; @@ -51,8 +51,8 @@ construct_runtime!( Balances: pallet_balances, Evm: pallet_evm, Timestamp: pallet_timestamp, - Xtokens: orml_xtokens, PolkadotXcm: pallet_xcm, + XcmTransactor: pallet_xcm_transactor, } ); @@ -288,6 +288,92 @@ impl pallet_evm::Config for Runtime { type WeightInfo = pallet_evm::weights::SubstrateWeight; } +#[derive(Encode, Decode)] +pub enum RelayCall { + #[codec(index = 5u8)] + // the index should match the position of the module in `construct_runtime!` + Utility(UtilityCall), + #[codec(index = 6u8)] + // the index should match the position of the module in `construct_runtime!` + Hrmp(HrmpCall), +} + +#[derive(Encode, Decode)] +pub enum UtilityCall { + #[codec(index = 1u8)] + AsDerivative(u16), +} + +// HRMP call encoding, needed for xcm transactor pallet +#[derive(Encode, Decode)] +pub enum HrmpCall { + #[codec(index = 0u8)] + InitOpenChannel(ParaId, u32, u32), + #[codec(index = 1u8)] + AcceptOpenChannel(ParaId), + #[codec(index = 2u8)] + CloseChannel(HrmpChannelId), + #[codec(index = 6u8)] + CancelOpenRequest(HrmpChannelId, u32), +} + +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum MockTransactors { + Relay, +} + +impl xcm_primitives::XcmTransact for MockTransactors { + fn destination(self) -> Location { + match self { + MockTransactors::Relay => Location::parent(), + } + } +} + +impl xcm_primitives::UtilityEncodeCall for MockTransactors { + fn encode_call(self, call: xcm_primitives::UtilityAvailableCalls) -> Vec { + match self { + MockTransactors::Relay => match call { + xcm_primitives::UtilityAvailableCalls::AsDerivative(a, b) => { + let mut call = + RelayCall::Utility(UtilityCall::AsDerivative(a.clone())).encode(); + call.append(&mut b.clone()); + call + } + }, + } + } +} + +parameter_types! { + pub SelfLocationAbsolute: Location = Location { + parents: 1, + interior: [Parachain(ParachainId::get().into())].into(), + }; +} + +impl pallet_xcm_transactor::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type Transactor = MockTransactors; + type DerivativeAddressRegistrationOrigin = frame_system::EnsureRoot; + type SovereignAccountDispatcherOrigin = frame_system::EnsureRoot; + type CurrencyId = CurrencyId; + type AccountIdToLocation = AccountIdToLocation; + type CurrencyIdToLocation = CurrencyIdToMultiLocation; + type SelfLocation = SelfLocation; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type BaseXcmWeight = BaseXcmWeight; + type XcmSender = DoNothingRouter; + type AssetTransactor = DummyAssetTransactor; + type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; + type WeightInfo = (); + type HrmpManipulatorOrigin = frame_system::EnsureRoot; + type HrmpOpenOrigin = frame_system::EnsureRoot; + type MaxHrmpFee = (); +} + parameter_types! { pub const MinimumPeriod: u64 = 5; } @@ -366,12 +452,6 @@ parameter_types! { pub MaxInstructions: u32 = 100; } -parameter_type_with_key! { - pub ParachainMinFee: |_location: Location| -> Option { - Some(u128::MAX) - }; -} - pub struct CurrencyIdToMultiLocation; impl sp_runtime::traits::Convert> for CurrencyIdToMultiLocation { @@ -393,25 +473,6 @@ impl sp_runtime::traits::Convert> for CurrencyIdToM } } -impl orml_xtokens::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Balance = Balance; - type CurrencyId = CurrencyId; - type AccountIdToLocation = AccountIdToLocation; - type CurrencyIdConvert = CurrencyIdToMultiLocation; - type XcmExecutor = XcmExecutor; - type SelfLocation = SelfLocation; - type Weigher = xcm_builder::FixedWeightBounds; - type BaseXcmWeight = BaseXcmWeight; - type MaxAssetsForTransfer = MaxAssetsForTransfer; - type MinXcmFee = ParachainMinFee; - type LocationsFilter = Everything; - type ReserveProvider = AbsoluteReserveProvider; - type UniversalLocation = UniversalLocation; - type RateLimiter = (); - type RateLimiterId = (); -} - pub(crate) struct ExtBuilder { /// Endowed accounts with balances balances: Vec<(AccountId, Balance)>, diff --git a/precompiles/relay-encoder/src/mock.rs b/precompiles/relay-encoder/src/mock.rs index 12587dd736..bd9c58252f 100644 --- a/precompiles/relay-encoder/src/mock.rs +++ b/precompiles/relay-encoder/src/mock.rs @@ -297,6 +297,13 @@ impl TransactAsset for DummyAssetTransactor { } } +parameter_types! { + pub SelfLocationAbsolute: Location = Location { + parents: 1, + interior: [Parachain(ParachainId::get().into())].into(), + }; +} + impl pallet_xcm_transactor::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; @@ -312,7 +319,7 @@ impl pallet_xcm_transactor::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type XcmSender = DoNothingRouter; type AssetTransactor = DummyAssetTransactor; - type ReserveProvider = orml_traits::location::RelativeReserveProvider; + type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; type WeightInfo = (); type HrmpManipulatorOrigin = frame_system::EnsureRoot; type HrmpOpenOrigin = frame_system::EnsureRoot; diff --git a/precompiles/xcm-transactor/src/mock.rs b/precompiles/xcm-transactor/src/mock.rs index b239e660cc..948678bfa7 100644 --- a/precompiles/xcm-transactor/src/mock.rs +++ b/precompiles/xcm-transactor/src/mock.rs @@ -319,6 +319,10 @@ parameter_types! { pub MaxInstructions: u32 = 100; pub UniversalLocation: InteriorLocation = Here; + pub SelfLocationAbsolute: Location = Location { + parents: 1, + interior: [Parachain(ParachainId::get().into())].into(), + }; } impl pallet_xcm_transactor::Config for Runtime { @@ -336,7 +340,7 @@ impl pallet_xcm_transactor::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type XcmSender = DoNothingRouter; type AssetTransactor = DummyAssetTransactor; - type ReserveProvider = orml_traits::location::RelativeReserveProvider; + type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; type WeightInfo = (); type HrmpManipulatorOrigin = frame_system::EnsureRoot; type HrmpOpenOrigin = frame_system::EnsureRoot; diff --git a/precompiles/xtokens/src/mock.rs b/precompiles/xtokens/src/mock.rs index db681be3d7..a9b8c4767b 100644 --- a/precompiles/xtokens/src/mock.rs +++ b/precompiles/xtokens/src/mock.rs @@ -16,11 +16,11 @@ //! Test utilities use super::*; +use cumulus_primitives_core::{relay_chain::HrmpChannelId, ParaId}; use frame_support::traits::{ ConstU32, EnsureOrigin, Everything, Nothing, OriginTrait, PalletInfo as PalletInfoTrait, }; use frame_support::{construct_runtime, parameter_types, weights::Weight}; -use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key}; use pallet_evm::{EnsureAddressNever, EnsureAddressRoot}; use parity_scale_codec::{Decode, Encode}; use precompile_utils::{ @@ -37,7 +37,7 @@ use xcm::latest::{prelude::*, Error as XcmError}; use xcm_builder::{AllowUnpaidExecutionFrom, FixedWeightBounds, IsConcrete}; use xcm_executor::{ traits::{TransactAsset, WeightTrader}, - AssetsInHolding, XcmExecutor, + AssetsInHolding, }; pub type AccountId = MockAccount; @@ -48,13 +48,13 @@ type Block = frame_system::mocking::MockBlockU32; // Configure a mock runtime to test the pallet. construct_runtime!( - pub enum Runtime { + pub enum Runtime { System: frame_system, Balances: pallet_balances, Evm: pallet_evm, Timestamp: pallet_timestamp, - Xtokens: orml_xtokens, PolkadotXcm: pallet_xcm, + XcmTransactor: pallet_xcm_transactor, } ); @@ -286,6 +286,92 @@ impl pallet_xcm::Config for Runtime { type AdminOrigin = frame_system::EnsureRoot; } +#[derive(Encode, Decode)] +pub enum RelayCall { + #[codec(index = 5u8)] + // the index should match the position of the module in `construct_runtime!` + Utility(UtilityCall), + #[codec(index = 6u8)] + // the index should match the position of the module in `construct_runtime!` + Hrmp(HrmpCall), +} + +#[derive(Encode, Decode)] +pub enum UtilityCall { + #[codec(index = 1u8)] + AsDerivative(u16), +} + +// HRMP call encoding, needed for xcm transactor pallet +#[derive(Encode, Decode)] +pub enum HrmpCall { + #[codec(index = 0u8)] + InitOpenChannel(ParaId, u32, u32), + #[codec(index = 1u8)] + AcceptOpenChannel(ParaId), + #[codec(index = 2u8)] + CloseChannel(HrmpChannelId), + #[codec(index = 6u8)] + CancelOpenRequest(HrmpChannelId, u32), +} + +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum MockTransactors { + Relay, +} + +impl xcm_primitives::XcmTransact for MockTransactors { + fn destination(self) -> Location { + match self { + MockTransactors::Relay => Location::parent(), + } + } +} + +impl xcm_primitives::UtilityEncodeCall for MockTransactors { + fn encode_call(self, call: xcm_primitives::UtilityAvailableCalls) -> Vec { + match self { + MockTransactors::Relay => match call { + xcm_primitives::UtilityAvailableCalls::AsDerivative(a, b) => { + let mut call = + RelayCall::Utility(UtilityCall::AsDerivative(a.clone())).encode(); + call.append(&mut b.clone()); + call + } + }, + } + } +} + +parameter_types! { + pub SelfLocationAbsolute: Location = Location { + parents: 1, + interior: [Parachain(ParachainId::get().into())].into(), + }; +} + +impl pallet_xcm_transactor::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type Transactor = MockTransactors; + type DerivativeAddressRegistrationOrigin = frame_system::EnsureRoot; + type SovereignAccountDispatcherOrigin = frame_system::EnsureRoot; + type CurrencyId = CurrencyId; + type AccountIdToLocation = AccountIdToLocation; + type CurrencyIdToLocation = CurrencyIdToMultiLocation; + type SelfLocation = SelfLocation; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type BaseXcmWeight = BaseXcmWeight; + type XcmSender = DoNothingRouter; + type AssetTransactor = DummyAssetTransactor; + type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; + type WeightInfo = (); + type HrmpManipulatorOrigin = frame_system::EnsureRoot; + type HrmpOpenOrigin = frame_system::EnsureRoot; + type MaxHrmpFee = (); +} + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -393,31 +479,6 @@ parameter_types! { pub MaxInstructions: u32 = 100; } -parameter_type_with_key! { - pub ParachainMinFee: |_location: Location| -> Option { - Some(u128::MAX) - }; -} - -impl orml_xtokens::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Balance = Balance; - type CurrencyId = CurrencyId; - type AccountIdToLocation = AccountIdToLocation; - type CurrencyIdConvert = CurrencyIdToMultiLocation; - type XcmExecutor = XcmExecutor; - type SelfLocation = SelfLocation; - type Weigher = xcm_builder::FixedWeightBounds; - type BaseXcmWeight = BaseXcmWeight; - type UniversalLocation = UniversalLocation; - type MaxAssetsForTransfer = MaxAssetsForTransfer; - type MinXcmFee = ParachainMinFee; - type LocationsFilter = Everything; - type ReserveProvider = AbsoluteReserveProvider; - type RateLimiter = (); - type RateLimiterId = (); -} - pub(crate) struct ExtBuilder { // endowed accounts with balances balances: Vec<(AccountId, Balance)>, diff --git a/runtime/moonbase/tests/xcm_mock/mod.rs b/runtime/moonbase/tests/xcm_mock/mod.rs index 4a9e567d99..36822a3023 100644 --- a/runtime/moonbase/tests/xcm_mock/mod.rs +++ b/runtime/moonbase/tests/xcm_mock/mod.rs @@ -266,7 +266,6 @@ pub type Assets = pallet_assets::Pallet; pub type AssetManager = pallet_asset_manager::Pallet; -pub type XTokens = orml_xtokens::Pallet; pub type RelayBalances = pallet_balances::Pallet; pub type ParaBalances = pallet_balances::Pallet; pub type XcmTransactor = pallet_xcm_transactor::Pallet; diff --git a/runtime/moonbase/tests/xcm_mock/parachain.rs b/runtime/moonbase/tests/xcm_mock/parachain.rs index cd180f797e..2f5406954e 100644 --- a/runtime/moonbase/tests/xcm_mock/parachain.rs +++ b/runtime/moonbase/tests/xcm_mock/parachain.rs @@ -340,7 +340,7 @@ type Reserves = ( // Relaychain (DOT) from Asset Hub Case, // Assets which the reserve is the same as the origin. - orml_xcm_support::MultiNativeAsset< + xcm_primitives::MultiNativeAsset< xcm_primitives::AbsoluteAndRelativeReserve, >, ); @@ -425,36 +425,6 @@ parameter_types! { }; } -parameter_type_with_key! { - pub ParachainMinFee: |location: Location| -> Option { - match (location.parents, location.first_interior()) { - (1, Some(Parachain(1000u32))) => Some(50u128), - _ => None, - } - }; -} - -// The XCM message wrapper wrapper -impl orml_xtokens::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Balance = Balance; - type CurrencyId = CurrencyId; - type AccountIdToLocation = xcm_primitives::AccountIdToLocation; - type CurrencyIdConvert = - CurrencyIdToLocation>; - type XcmExecutor = XcmExecutor; - type SelfLocation = SelfLocation; - type Weigher = xcm_builder::FixedWeightBounds; - type BaseXcmWeight = BaseXcmWeight; - type UniversalLocation = UniversalLocation; - type MaxAssetsForTransfer = MaxAssetsForTransfer; - type MinXcmFee = ParachainMinFee; - type LocationsFilter = Everything; - type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; - type RateLimiter = (); - type RateLimiterId = (); -} - parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); pub const ProposalBondMinimum: Balance = 0; @@ -1095,7 +1065,6 @@ construct_runtime!( PolkadotXcm: pallet_xcm, Assets: pallet_assets, CumulusXcm: cumulus_pallet_xcm, - XTokens: orml_xtokens, AssetManager: pallet_asset_manager, XcmTransactor: pallet_xcm_transactor, XcmWeightTrader: pallet_xcm_weight_trader, diff --git a/runtime/moonbeam/tests/xcm_mock/mod.rs b/runtime/moonbeam/tests/xcm_mock/mod.rs index 231196031e..cf6b507984 100644 --- a/runtime/moonbeam/tests/xcm_mock/mod.rs +++ b/runtime/moonbeam/tests/xcm_mock/mod.rs @@ -265,7 +265,6 @@ pub type StatemintAssets = pallet_assets::Pallet; pub type Assets = pallet_assets::Pallet; pub type Treasury = pallet_treasury::Pallet; pub type AssetManager = pallet_asset_manager::Pallet; -pub type XTokens = orml_xtokens::Pallet; pub type RelayBalances = pallet_balances::Pallet; pub type ParaBalances = pallet_balances::Pallet; pub type XcmTransactor = pallet_xcm_transactor::Pallet; diff --git a/runtime/moonbeam/tests/xcm_mock/parachain.rs b/runtime/moonbeam/tests/xcm_mock/parachain.rs index db2ade3048..47fec7fa20 100644 --- a/runtime/moonbeam/tests/xcm_mock/parachain.rs +++ b/runtime/moonbeam/tests/xcm_mock/parachain.rs @@ -333,7 +333,7 @@ type Reserves = ( // Relaychain (DOT) from Asset Hub Case, // Assets which the reserve is the same as the origin. - orml_xcm_support::MultiNativeAsset< + xcm_primitives::MultiNativeAsset< xcm_primitives::AbsoluteAndRelativeReserve, >, ); @@ -412,36 +412,6 @@ parameter_types! { }; } -parameter_type_with_key! { - pub ParachainMinFee: |location: Location| -> Option { - match (location.parents, location.first_interior()) { - (1, Some(Parachain(1000u32))) => Some(50u128), - _ => None, - } - }; -} - -// The XCM message wrapper wrapper -impl orml_xtokens::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Balance = Balance; - type CurrencyId = CurrencyId; - type AccountIdToLocation = xcm_primitives::AccountIdToLocation; - type CurrencyIdConvert = - CurrencyIdToLocation>; - type XcmExecutor = XcmExecutor; - type SelfLocation = SelfLocation; - type Weigher = xcm_builder::FixedWeightBounds; - type BaseXcmWeight = BaseXcmWeight; - type UniversalLocation = UniversalLocation; - type MaxAssetsForTransfer = MaxAssetsForTransfer; - type MinXcmFee = ParachainMinFee; - type LocationsFilter = Everything; - type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; - type RateLimiter = (); - type RateLimiterId = (); -} - parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); pub const ProposalBondMinimum: Balance = 0; @@ -1082,7 +1052,6 @@ construct_runtime!( PolkadotXcm: pallet_xcm, Assets: pallet_assets, CumulusXcm: cumulus_pallet_xcm, - XTokens: orml_xtokens, AssetManager: pallet_asset_manager, XcmTransactor: pallet_xcm_transactor, XcmWeightTrader: pallet_xcm_weight_trader, diff --git a/runtime/moonbeam/tests/xcm_mock/statemint_like.rs b/runtime/moonbeam/tests/xcm_mock/statemint_like.rs index 3b37a8e6c3..fd3eb2fd95 100644 --- a/runtime/moonbeam/tests/xcm_mock/statemint_like.rs +++ b/runtime/moonbeam/tests/xcm_mock/statemint_like.rs @@ -323,8 +323,7 @@ impl Config for XcmConfig { type XcmSender = XcmRouter; type AssetTransactor = AssetTransactors; type OriginConverter = XcmOriginToTransactDispatchOrigin; - type IsReserve = - orml_xcm_support::MultiNativeAsset; + type IsReserve = xcm_primitives::MultiNativeAsset; type IsTeleporter = TrustedTeleporters; type UniversalLocation = UniversalLocation; type Barrier = Barrier; diff --git a/runtime/moonriver/tests/xcm_mock/mod.rs b/runtime/moonriver/tests/xcm_mock/mod.rs index cb1cacc488..ac703fe039 100644 --- a/runtime/moonriver/tests/xcm_mock/mod.rs +++ b/runtime/moonriver/tests/xcm_mock/mod.rs @@ -267,7 +267,6 @@ pub type Assets = pallet_assets::Pallet; pub type AssetManager = pallet_asset_manager::Pallet; -pub type XTokens = orml_xtokens::Pallet; pub type RelayBalances = pallet_balances::Pallet; pub type ParaBalances = pallet_balances::Pallet; pub type XcmTransactor = pallet_xcm_transactor::Pallet; diff --git a/runtime/moonriver/tests/xcm_mock/parachain.rs b/runtime/moonriver/tests/xcm_mock/parachain.rs index 6622960775..db10312665 100644 --- a/runtime/moonriver/tests/xcm_mock/parachain.rs +++ b/runtime/moonriver/tests/xcm_mock/parachain.rs @@ -333,7 +333,7 @@ type Reserves = ( // Relaychain (DOT) from Asset Hub Case, // Assets which the reserve is the same as the origin. - orml_xcm_support::MultiNativeAsset< + xcm_primitives::MultiNativeAsset< xcm_primitives::AbsoluteAndRelativeReserve, >, ); @@ -417,36 +417,6 @@ parameter_types! { }; } -parameter_type_with_key! { - pub ParachainMinFee: |location: Location| -> Option { - match (location.parents, location.first_interior()) { - (1, Some(Parachain(1000u32))) => Some(50u128), - _ => None, - } - }; -} - -// The XCM message wrapper wrapper -impl orml_xtokens::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Balance = Balance; - type CurrencyId = CurrencyId; - type AccountIdToLocation = xcm_primitives::AccountIdToLocation; - type CurrencyIdConvert = - CurrencyIdToLocation>; - type XcmExecutor = XcmExecutor; - type SelfLocation = SelfLocation; - type Weigher = xcm_builder::FixedWeightBounds; - type BaseXcmWeight = BaseXcmWeight; - type UniversalLocation = UniversalLocation; - type MaxAssetsForTransfer = MaxAssetsForTransfer; - type MinXcmFee = ParachainMinFee; - type LocationsFilter = Everything; - type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; - type RateLimiter = (); - type RateLimiterId = (); -} - parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); pub const ProposalBondMinimum: Balance = 0; @@ -1088,7 +1058,6 @@ construct_runtime!( PolkadotXcm: pallet_xcm, Assets: pallet_assets, CumulusXcm: cumulus_pallet_xcm, - XTokens: orml_xtokens, AssetManager: pallet_asset_manager, XcmTransactor: pallet_xcm_transactor, XcmWeightTrader: pallet_xcm_weight_trader, From d47169fb20b264ba1f823de6b27cd289a9da6a5a Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Mon, 7 Oct 2024 08:47:52 +0200 Subject: [PATCH 12/24] fix rust tests --- precompiles/xtokens/src/tests.rs | 229 +++-------- runtime/moonbase/tests/integration_test.rs | 58 ++- .../moonbase/tests/xcm_mock/statemint_like.rs | 13 +- runtime/moonbase/tests/xcm_tests.rs | 362 ++++++++++-------- runtime/moonbeam/tests/integration_test.rs | 126 +++--- runtime/moonbeam/tests/xcm_mock/parachain.rs | 1 - runtime/moonbeam/tests/xcm_tests.rs | 303 +++++++++------ runtime/moonriver/tests/integration_test.rs | 59 ++- runtime/moonriver/tests/xcm_mock/parachain.rs | 1 - .../tests/xcm_mock/statemine_like.rs | 3 +- runtime/moonriver/tests/xcm_tests.rs | 334 ++++++++++------ 11 files changed, 834 insertions(+), 655 deletions(-) diff --git a/precompiles/xtokens/src/tests.rs b/precompiles/xtokens/src/tests.rs index ce2dff8a85..de6558ea7e 100644 --- a/precompiles/xtokens/src/tests.rs +++ b/precompiles/xtokens/src/tests.rs @@ -15,15 +15,15 @@ // along with Moonbeam. If not, see . use crate::mock::{ - events, AssetAccount, CurrencyId, CurrencyIdToMultiLocation, ExtBuilder, PCall, Precompiles, - PrecompilesValue, Runtime, SelfReserveAccount, + events, AssetAccount, ExtBuilder, PCall, Precompiles, PrecompilesValue, Runtime, + SelfReserveAccount, }; use crate::{Currency, EvmAsset}; -use orml_xtokens::Event as XtokensEvent; +use pallet_xcm::Event as PolkadotXcmEvent; use precompile_utils::{prelude::*, testing::*}; use sp_core::U256; -use sp_runtime::traits::Convert; -use xcm::latest::{Asset, AssetId, Assets, Fungibility, Junction, Location}; +use sp_weights::Weight; +use xcm::latest::{Junction, Location}; fn precompiles() -> Precompiles { PrecompilesValue::get() @@ -98,17 +98,13 @@ fn transfer_self_reserve_works() { .expect_no_logs() .execute_returns(()); - let expected_asset: Asset = Asset { - id: AssetId(CurrencyIdToMultiLocation::convert(CurrencyId::SelfReserve).unwrap()), - fun: Fungibility::Fungible(500), - }; - let expected: crate::mock::RuntimeEvent = XtokensEvent::TransferredAssets { - sender: Alice.into(), - assets: vec![expected_asset.clone()].into(), - fee: expected_asset, - dest: destination, + let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { + outcome: xcm::latest::Outcome::Complete { + used: Weight::zero(), + }, } .into(); + // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -143,17 +139,10 @@ fn transfer_to_reserve_works() { .expect_no_logs() .execute_returns(()); - let expected_asset: Asset = Asset { - id: AssetId( - CurrencyIdToMultiLocation::convert(CurrencyId::OtherReserve(0u128)).unwrap(), - ), - fun: Fungibility::Fungible(500), - }; - let expected: crate::mock::RuntimeEvent = XtokensEvent::TransferredAssets { - sender: Alice.into(), - assets: vec![expected_asset.clone()].into(), - fee: expected_asset, - dest: destination, + let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { + outcome: xcm::latest::Outcome::Complete { + used: Weight::zero(), + }, } .into(); // Assert that the events vector contains the one expected @@ -190,19 +179,13 @@ fn transfer_to_reserve_with_unlimited_weight_works() { .expect_no_logs() .execute_returns(()); - let expected_asset: Asset = Asset { - id: AssetId( - CurrencyIdToMultiLocation::convert(CurrencyId::OtherReserve(0u128)).unwrap(), - ), - fun: Fungibility::Fungible(500), - }; - let expected: crate::mock::RuntimeEvent = XtokensEvent::TransferredAssets { - sender: Alice.into(), - assets: vec![expected_asset.clone()].into(), - fee: expected_asset, - dest: destination, + let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { + outcome: xcm::latest::Outcome::Complete { + used: Weight::zero(), + }, } .into(); + // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -230,7 +213,7 @@ fn transfer_to_reserve_with_fee_works() { PCall::transfer_with_fee { currency_address: Address(AssetAccount(0u128).into()), amount: 500.into(), - fee: 50.into(), + _fee: 50.into(), destination: destination.clone().into(), weight: 4_000_000, }, @@ -239,23 +222,10 @@ fn transfer_to_reserve_with_fee_works() { .expect_no_logs() .execute_returns(()); - let expected_asset: Asset = Asset { - id: AssetId( - CurrencyIdToMultiLocation::convert(CurrencyId::OtherReserve(0u128)).unwrap(), - ), - fun: Fungibility::Fungible(500), - }; - let expected_fee: Asset = Asset { - id: AssetId( - CurrencyIdToMultiLocation::convert(CurrencyId::OtherReserve(0u128)).unwrap(), - ), - fun: Fungibility::Fungible(50), - }; - let expected: crate::mock::RuntimeEvent = XtokensEvent::TransferredAssets { - sender: Alice.into(), - assets: vec![expected_asset.clone(), expected_fee.clone()].into(), - fee: expected_fee, - dest: destination, + let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { + outcome: xcm::latest::Outcome::Complete { + used: Weight::zero(), + }, } .into(); @@ -294,17 +264,10 @@ fn transfer_non_reserve_to_non_reserve_works() { .expect_no_logs() .execute_returns(()); - let expected_asset: Asset = Asset { - id: AssetId( - CurrencyIdToMultiLocation::convert(CurrencyId::OtherReserve(1u128)).unwrap(), - ), - fun: Fungibility::Fungible(500), - }; - let expected: crate::mock::RuntimeEvent = XtokensEvent::TransferredAssets { - sender: Alice.into(), - assets: vec![expected_asset.clone()].into(), - fee: expected_asset, - dest: destination, + let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { + outcome: xcm::latest::Outcome::Complete { + used: Weight::zero(), + }, } .into(); // Assert that the events vector contains the one expected @@ -334,7 +297,7 @@ fn transfer_non_reserve_to_non_reserve_with_fee_works() { PCall::transfer_with_fee { currency_address: Address(AssetAccount(1u128).into()), amount: 500.into(), - fee: 50.into(), + _fee: 50.into(), destination: destination.clone().into(), weight: 4_000_000, }, @@ -343,23 +306,10 @@ fn transfer_non_reserve_to_non_reserve_with_fee_works() { .expect_no_logs() .execute_returns(()); - let expected_asset: Asset = Asset { - id: AssetId( - CurrencyIdToMultiLocation::convert(CurrencyId::OtherReserve(1u128)).unwrap(), - ), - fun: Fungibility::Fungible(500), - }; - let expected_fee: Asset = Asset { - id: AssetId( - CurrencyIdToMultiLocation::convert(CurrencyId::OtherReserve(1u128)).unwrap(), - ), - fun: Fungibility::Fungible(50), - }; - let expected: crate::mock::RuntimeEvent = XtokensEvent::TransferredAssets { - sender: Alice.into(), - assets: vec![expected_asset.clone(), expected_fee.clone()].into(), - fee: expected_fee, - dest: destination, + let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { + outcome: xcm::latest::Outcome::Complete { + used: Weight::zero(), + }, } .into(); // Assert that the events vector contains the one expected @@ -398,15 +348,10 @@ fn transfer_multi_asset_to_reserve_works() { .expect_no_logs() .execute_returns(()); - let expected_asset: Asset = Asset { - id: AssetId(asset), - fun: Fungibility::Fungible(500), - }; - let expected: crate::mock::RuntimeEvent = XtokensEvent::TransferredAssets { - sender: Alice.into(), - assets: vec![expected_asset.clone()].into(), - fee: expected_asset, - dest: destination, + let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { + outcome: xcm::latest::Outcome::Complete { + used: Weight::zero(), + }, } .into(); @@ -446,15 +391,10 @@ fn transfer_multi_asset_self_reserve_works() { .expect_no_logs() .execute_returns(()); - let expected_asset: Asset = Asset { - id: AssetId(self_reserve), - fun: Fungibility::Fungible(500), - }; - let expected: crate::mock::RuntimeEvent = XtokensEvent::TransferredAssets { - sender: Alice.into(), - assets: vec![expected_asset.clone()].into(), - fee: expected_asset, - dest: destination, + let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { + outcome: xcm::latest::Outcome::Complete { + used: Weight::zero(), + }, } .into(); // Assert that the events vector contains the one expected @@ -485,7 +425,7 @@ fn transfer_multi_asset_self_reserve_with_fee_works() { PCall::transfer_multiasset_with_fee { asset: self_reserve.clone().into(), amount: 500.into(), - fee: 50.into(), + _fee: 50.into(), destination: destination.clone().into(), weight: 4_000_000, }, @@ -494,19 +434,10 @@ fn transfer_multi_asset_self_reserve_with_fee_works() { .expect_no_logs() .execute_returns(()); - let expected_asset: Asset = Asset { - id: AssetId(self_reserve.clone()), - fun: Fungibility::Fungible(500), - }; - let expected_fee: Asset = Asset { - id: AssetId(self_reserve), - fun: Fungibility::Fungible(50), - }; - let expected: crate::mock::RuntimeEvent = XtokensEvent::TransferredAssets { - sender: Alice.into(), - assets: vec![expected_asset.clone(), expected_fee.clone()].into(), - fee: expected_fee, - dest: destination, + let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { + outcome: xcm::latest::Outcome::Complete { + used: Weight::zero(), + }, } .into(); // Assert that the events vector contains the one expected @@ -546,15 +477,10 @@ fn transfer_multi_asset_non_reserve_to_non_reserve() { .expect_no_logs() .execute_returns(()); - let expected_asset: Asset = Asset { - id: AssetId(asset_location), - fun: Fungibility::Fungible(500), - }; - let expected: crate::mock::RuntimeEvent = XtokensEvent::TransferredAssets { - sender: Alice.into(), - assets: vec![expected_asset.clone()].into(), - fee: expected_asset, - dest: destination, + let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { + outcome: xcm::latest::Outcome::Complete { + used: Weight::zero(), + }, } .into(); // Assert that the events vector contains the one expected @@ -586,7 +512,7 @@ fn transfer_multi_asset_non_reserve_to_non_reserve_with_fee() { PCall::transfer_multiasset_with_fee { asset: asset_location.clone().into(), amount: 500.into(), - fee: 50.into(), + _fee: 50.into(), destination: destination.clone().into(), weight: 4_000_000, }, @@ -595,19 +521,10 @@ fn transfer_multi_asset_non_reserve_to_non_reserve_with_fee() { .expect_no_logs() .execute_returns(()); - let expected_asset: Asset = Asset { - id: AssetId(asset_location.clone()), - fun: Fungibility::Fungible(500), - }; - let expected_fee: Asset = Asset { - id: AssetId(asset_location), - fun: Fungibility::Fungible(50), - }; - let expected: crate::mock::RuntimeEvent = XtokensEvent::TransferredAssets { - sender: Alice.into(), - assets: vec![expected_asset.clone(), expected_fee.clone()].into(), - fee: expected_fee, - dest: destination, + let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { + outcome: xcm::latest::Outcome::Complete { + used: Weight::zero(), + }, } .into(); // Assert that the events vector contains the one expected @@ -649,23 +566,10 @@ fn transfer_multi_currencies() { .expect_no_logs() .execute_returns(()); - let expected_asset_1: Asset = Asset { - id: AssetId( - CurrencyIdToMultiLocation::convert(CurrencyId::OtherReserve(1u128)).unwrap(), - ), - fun: Fungibility::Fungible(500), - }; - let expected_asset_2: Asset = Asset { - id: AssetId( - CurrencyIdToMultiLocation::convert(CurrencyId::OtherReserve(2u128)).unwrap(), - ), - fun: Fungibility::Fungible(500), - }; - let expected: crate::mock::RuntimeEvent = XtokensEvent::TransferredAssets { - sender: Alice.into(), - assets: vec![expected_asset_1.clone(), expected_asset_2].into(), - fee: expected_asset_1, - dest: destination, + let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { + outcome: xcm::latest::Outcome::Complete { + used: Weight::zero(), + }, } .into(); // Assert that the events vector contains the one expected @@ -700,12 +604,6 @@ fn transfer_multi_assets() { (asset_2_location.clone(), U256::from(500)).into(), ]; - let multiassets = Assets::from_sorted_and_deduplicated(vec![ - (asset_1_location.clone(), 500).into(), - (asset_2_location, 500).into(), - ]) - .unwrap(); - // We are transferring 2 assets precompiles() .prepare_test( @@ -722,11 +620,10 @@ fn transfer_multi_assets() { .expect_no_logs() .execute_returns(()); - let expected: crate::mock::RuntimeEvent = XtokensEvent::TransferredAssets { - sender: Alice.into(), - assets: multiassets, - fee: (asset_1_location, 500).into(), - dest: destination, + let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { + outcome: xcm::latest::Outcome::Complete { + used: Weight::zero(), + }, } .into(); println!("Events are {:?}", events()); diff --git a/runtime/moonbase/tests/integration_test.rs b/runtime/moonbase/tests/integration_test.rs index 95727d7954..56270d7dd2 100644 --- a/runtime/moonbase/tests/integration_test.rs +++ b/runtime/moonbase/tests/integration_test.rs @@ -57,7 +57,6 @@ use moonbase_runtime::{ TransactionPayment, TransactionPaymentAsGasPrice, TreasuryCouncilCollective, - XTokens, XcmTransactor, FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, WEEKS, @@ -87,7 +86,7 @@ use sp_core::{crypto::UncheckedFrom, ByteArray, Pair, H160, H256, U256}; use sp_runtime::{bounded_vec, DispatchError, ModuleError}; use std::cell::Cell; use std::rc::Rc; -use xcm::latest::prelude::*; +use xcm::{latest::prelude::*, VersionedAssets, VersionedLocation}; type AuthorMappingPCall = pallet_evm_precompile_author_mapping::AuthorMappingPrecompileCall; @@ -161,7 +160,6 @@ fn verify_pallet_prefixes() { is_pallet_prefix::("DmpQueue"); is_pallet_prefix::("PolkadotXcm"); is_pallet_prefix::("Assets"); - is_pallet_prefix::("XTokens"); is_pallet_prefix::("AssetManager"); is_pallet_prefix::("Migrations"); is_pallet_prefix::("XcmTransactor"); @@ -443,7 +441,7 @@ fn verify_pallet_indices() { is_pallet_index::(27); is_pallet_index::(28); is_pallet_index::(29); - is_pallet_index::(30); + // is_pallet_index::(30); Removed is_pallet_index::(31); is_pallet_index::(32); is_pallet_index::(33); @@ -2078,26 +2076,36 @@ fn root_can_change_default_xcm_vers() { }]) .build() .execute_with(|| { - let dest = Location { - parents: 1, - interior: [AccountId32 { - network: None, - id: [1u8; 32], - }] - .into(), - }; let source_id: moonbase_runtime::AssetId = 1; + let currency_id = moonbase_runtime::xcm_config::CurrencyId::ForeignAsset(source_id); + let asset = Asset { + id: AssetId( + ::CurrencyIdToLocation::convert( + currency_id, + ) + .unwrap(), + ), + fun: Fungibility::Fungible(100_000_000_000_000), + }; // Default XCM version is not set yet, so xtokens should fail because it does not // know with which version to send assert_noop!( - XTokens::transfer( + PolkadotXcm::transfer_assets( origin_of(AccountId::from(ALICE)), - moonbase_runtime::xcm_config::CurrencyId::ForeignAsset(source_id), - 100_000_000_000_000, - Box::new(xcm::VersionedLocation::V4(dest.clone())), + Box::new(VersionedLocation::V4(Location::parent())), + Box::new(VersionedLocation::V4(Location { + parents: 0, + interior: [AccountId32 { + network: None, + id: [1u8; 32], + }] + .into(), + })), + Box::new(VersionedAssets::V4(asset.clone().into())), + 0, WeightLimit::Unlimited ), - orml_xtokens::Error::::XcmExecutionFailed + pallet_xcm::Error::::BadVersion ); // Root sets the defaultXcm @@ -2107,11 +2115,19 @@ fn root_can_change_default_xcm_vers() { )); // Now transferring does not fail - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( origin_of(AccountId::from(ALICE)), - moonbase_runtime::xcm_config::CurrencyId::ForeignAsset(source_id), - 100_000_000_000_000, - Box::new(xcm::VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(Location::parent())), + Box::new(VersionedLocation::V4(Location { + parents: 0, + interior: [AccountId32 { + network: None, + id: [1u8; 32], + }] + .into(), + })), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Unlimited )); }) diff --git a/runtime/moonbase/tests/xcm_mock/statemint_like.rs b/runtime/moonbase/tests/xcm_mock/statemint_like.rs index 51aa33d63f..6e66f53327 100644 --- a/runtime/moonbase/tests/xcm_mock/statemint_like.rs +++ b/runtime/moonbase/tests/xcm_mock/statemint_like.rs @@ -317,16 +317,19 @@ pub type TrustedTeleporters = (ConcreteAssetFromRelay,); /// Trust reserves from sibling parachains, relay chain, and here pub struct TrustedReserves; -impl ContainsPair for IsReserve { +impl ContainsPair for TrustedReserves { fn contains(asset: &Asset, origin: &Location) -> bool { let AssetId(location) = &asset.id; - match (&asset.id.0.parent_count(), &asset.id.0.first_interior()) { + match ( + &asset.id.0.parent_count(), + &asset.id.0.first_interior().unwrap(), + ) { // Sibling parachains - (1, Junctions::Parachain(id)) => location.chain_location() == origin, + (1, Junction::Parachain(_id)) => location.chain_location() == *origin, // Relay chain - (1, _) => location.chain_location() == origin, + (1, _) => location.chain_location() == *origin, // Here - (0, _) => Location::here() == origin, + (0, _) => Location::here() == *origin, _ => false, } } diff --git a/runtime/moonbase/tests/xcm_tests.rs b/runtime/moonbase/tests/xcm_tests.rs index c69c4eb64b..4d3de2f021 100644 --- a/runtime/moonbase/tests/xcm_tests.rs +++ b/runtime/moonbase/tests/xcm_tests.rs @@ -27,21 +27,27 @@ use frame_support::{ use pallet_xcm_transactor::{ Currency, CurrencyPayment, HrmpInitParams, HrmpOperation, TransactWeights, }; -use sp_runtime::traits::MaybeEquivalence; +use sp_runtime::traits::{Convert, MaybeEquivalence}; use sp_std::boxed::Box; -use xcm::latest::prelude::{ - AccountId32, AccountKey20, All, Asset as XcmAsset, AssetId as XcmAssetId, Assets as XcmAssets, - BuyExecution, ClearOrigin, DepositAsset, Fungible, GeneralIndex, Junction, Junctions, Limited, - Location, OriginKind, PalletInstance, Parachain, QueryResponse, Reanchorable, Response, - WeightLimit, WithdrawAsset, Xcm, +use xcm::{ + latest::prelude::{ + AccountId32, AccountKey20, All, Asset, AssetId, Assets as XcmAssets, BuyExecution, + ClearOrigin, DepositAsset, Fungibility, GeneralIndex, Junction, Junctions, Limited, + Location, OriginKind, PalletInstance, Parachain, QueryResponse, Reanchorable, Response, + WeightLimit, WithdrawAsset, Xcm, + }, + VersionedAssets, }; use xcm::{IntoVersion, VersionedLocation, WrapVersion}; use xcm_executor::traits::ConvertLocation; use xcm_mock::*; -use xcm_primitives::{UtilityEncodeCall, DEFAULT_PROOF_SIZE}; +use xcm_primitives::{ + split_location_into_chain_part_and_beneficiary, UtilityEncodeCall, DEFAULT_PROOF_SIZE, +}; use xcm_simulator::TestExt; mod common; use cumulus_primitives_core::relay_chain::HrmpChannelId; +use parachain::PolkadotXcm; fn add_supported_asset(asset_type: parachain::AssetType, units_per_second: u128) -> Result<(), ()> { let parachain::AssetType::Xcm(location_v3) = asset_type; @@ -76,6 +82,18 @@ fn add_supported_asset(asset_type: parachain::AssetType, units_per_second: u128) Ok(()) } +fn currency_to_asset(currency_id: parachain::CurrencyId, amount: u128) -> Asset { + Asset { + id: AssetId( + ::CurrencyIdToLocation::convert( + currency_id, + ) + .unwrap(), + ), + fun: Fungibility::Fungible(amount), + } +} + // Send a relay asset (like DOT) to a parachain A #[test] fn receive_relay_asset_from_relay() { @@ -162,7 +180,7 @@ fn send_relay_asset_to_relay() { assert_ok!(RelayChainPalletXcm::limited_reserve_transfer_assets( relay_chain::RuntimeOrigin::signed(RELAYALICE), Box::new(Parachain(1).into()), - Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(VersionedLocation::V4(dest.clone()).into()), Box::new(([], 123).into()), 0, WeightLimit::Unlimited @@ -180,48 +198,17 @@ fn send_relay_asset_to_relay() { balance_before_sending = RelayBalances::free_balance(&RELAYALICE); }); - // We now send back some money to the relay - let dest = Location { - parents: 1, - interior: [AccountId32 { - network: None, - id: RELAYALICE.into(), - }] - .into(), - }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 123); ParaA::execute_with(|| { // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( - parachain::RuntimeOrigin::signed(PARAALICE.into()), - // dest chain part - Location::parent(), - // beneficiary - Location { - parents: 0, - interior: [AccountId32 { - network: None, - id: RELAYALICE.into(), - }] - .into(), - }, - // assets - Asset { - id: Location, - fun: Fungibility::Fungible(1232) - }.into(), - // feeitem - 0, - // weightLimit - WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) - )); - }); - - assert_ok!(XTokens::transfer( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 123, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -309,13 +296,16 @@ fn send_relay_asset_to_para_b() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -373,13 +363,17 @@ fn send_para_a_asset_to_para_b() { .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + ParaA::execute_with(|| { // Free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(800000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -451,13 +445,17 @@ fn send_para_a_asset_from_para_b_to_para_c() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) )); }); @@ -487,17 +485,21 @@ fn send_para_a_asset_from_para_b_to_para_c() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaB::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) )); }); + // The message passed through parachainA so we needed to pay since its the native token // The message passed through parachainA so we needed to pay since its the native token ParaC::execute_with(|| { assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 96); @@ -545,12 +547,16 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) )); }); @@ -580,12 +586,16 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + ParaB::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) )); }); @@ -637,12 +647,16 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a_with_new_reanchoring() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) )); }); @@ -802,15 +816,18 @@ fn send_para_a_asset_to_para_b_with_trader() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); // In destination chain, we only need 4 weight // We put 10 weight, 6 of which should be refunded and 4 of which should go to treasury ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(10u64, DEFAULT_PROOF_SIZE)) )); }); @@ -875,15 +892,17 @@ fn send_para_a_asset_to_para_b_with_trader_and_fee() { ] .into(), }; - + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset_fee = currency_to_asset(parachain::CurrencyId::SelfReserve, 1); // we use transfer_with_fee ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_with_fee( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - 1, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset_fee, asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(800000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1043,14 +1062,17 @@ fn transact_through_derivative_multilocation() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1192,14 +1214,17 @@ fn transact_through_derivative_with_custom_fee_weight() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1343,14 +1368,17 @@ fn transact_through_derivative_with_custom_fee_weight_refund() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1505,14 +1533,17 @@ fn transact_through_sovereign() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1757,14 +1788,17 @@ fn transact_through_sovereign_with_custom_fee_weight() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1906,14 +1940,17 @@ fn transact_through_sovereign_with_custom_fee_weight_refund() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -2210,13 +2247,16 @@ fn test_automatic_versioning_on_runtime_upgrade_with_para_b() { .into(), } .into(); + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) )); // free execution, full amount received @@ -2827,19 +2867,21 @@ fn send_statemint_asset_from_para_a_to_statemint_with_relay_fee() { assert_eq!(StatemintAssets::account_balances(RELAYBOB), vec![]); }); + let (chain_part, beneficiary) = + split_location_into_chain_part_and_beneficiary(statemint_beneficiary).unwrap(); + let asset = currency_to_asset( + parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), + 100, + ); + let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); // Transfer USDC from Parachain A to Statemint using Relay asset as fee ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_multicurrencies( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - vec![ - ( - parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), - 100 - ), - (parachain::CurrencyId::ForeignAsset(source_relay_id), 100) - ], - 1, - Box::new(VersionedLocation::V4(statemint_beneficiary)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset_fee, asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(80_000_000u64, 100_000u64)) )); }); @@ -2966,14 +3008,17 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer() { }, ], ); + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_relay_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); @@ -3119,15 +3164,18 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_with_fee() { }, ], ); + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 10); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_with_fee( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_relay_id), - 100, - 10, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset_fee, asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); @@ -3277,12 +3325,19 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multiasset() { ], ); + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = Asset { + id: AssetId(Location::parent()), + fun: Fungibility::Fungible(100), + }; // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_multiasset( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - Box::new((Location::parent(), 100).into()), - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); @@ -3507,19 +3562,20 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multicurrencies() { ], ); + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset( + parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), + 100, + ); + let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_multicurrencies( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - vec![ - ( - parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), - 100 - ), - (parachain::CurrencyId::ForeignAsset(source_relay_id), 100) - ], - 1, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset_fee, asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(80_000_000u64, 100_000u64)) )); @@ -3753,16 +3809,17 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multiassets() { ], ); - let statemint_asset_to_send = XcmAsset { - id: XcmAssetId(statemint_asset), - fun: Fungible(100), + let statemint_asset_to_send = Asset { + id: AssetId(statemint_asset), + fun: Fungibility::Fungible(100), }; - let relay_asset_to_send = XcmAsset { - id: XcmAssetId(Location::parent()), - fun: Fungible(100), + let relay_asset_to_send = Asset { + id: AssetId(Location::parent()), + fun: Fungibility::Fungible(100), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); let assets_to_send: XcmAssets = XcmAssets::from(vec![statemint_asset_to_send, relay_asset_to_send.clone()]); @@ -3772,11 +3829,12 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multiassets() { // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_multiassets( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - Box::new(assets_to_send.into()), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(assets_to_send.into())), 0, - Box::new(VersionedLocation::V4(dest)), WeightLimit::Limited(Weight::from_parts(80_000_000u64, 100_000u64)) )); diff --git a/runtime/moonbeam/tests/integration_test.rs b/runtime/moonbeam/tests/integration_test.rs index 78a80b0465..0b16154fbe 100644 --- a/runtime/moonbeam/tests/integration_test.rs +++ b/runtime/moonbeam/tests/integration_test.rs @@ -40,8 +40,7 @@ use moonbeam_runtime::{ AccountId, Balances, CrowdloanRewards, Executive, OpenTechCommitteeCollective, ParachainStaking, PolkadotXcm, Precompiles, Runtime, RuntimeBlockWeights, RuntimeCall, RuntimeEvent, System, TransactionPayment, TransactionPaymentAsGasPrice, - TreasuryCouncilCollective, XTokens, XcmTransactor, FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, - WEEKS, + TreasuryCouncilCollective, XcmTransactor, FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, WEEKS, }; use moonbeam_xcm_benchmarks::weights::XcmWeight; use moonkit_xcm_primitives::AccountIdAssetIdConversion; @@ -64,10 +63,10 @@ use sp_runtime::{ BuildStorage, DispatchError, ModuleError, }; use std::str::from_utf8; -use xcm::latest::prelude::*; -use xcm::{VersionedAsset, VersionedAssets, VersionedLocation}; +use xcm::{latest::prelude::*, VersionedAssets, VersionedLocation}; use xcm_builder::{ParentIsPreset, SiblingParachainConvertsVia}; use xcm_executor::traits::ConvertLocation; +use xcm_primitives::split_location_into_chain_part_and_beneficiary; type BatchPCall = pallet_evm_precompile_batch::BatchPrecompileCall; type CrowdloanRewardsPCall = @@ -86,6 +85,17 @@ type XcmTransactorV2PCall = const BASE_FEE_GENESIS: u128 = 10000 * GIGAWEI; +fn currency_to_asset(currency_id: CurrencyId, amount: u128) -> Asset { + Asset { + id: AssetId( + ::CurrencyIdToLocation::convert( + currency_id, + ) + .unwrap(), + ), + fun: Fungibility::Fungible(amount), + } +} #[test] fn xcmp_queue_controller_origin_is_root() { // important for the XcmExecutionManager impl of PauseExecution which uses root origin @@ -136,7 +146,6 @@ fn verify_pallet_prefixes() { is_pallet_prefix::("DmpQueue"); is_pallet_prefix::("PolkadotXcm"); is_pallet_prefix::("Assets"); - is_pallet_prefix::("XTokens"); is_pallet_prefix::("AssetManager"); is_pallet_prefix::("Migrations"); is_pallet_prefix::("XcmTransactor"); @@ -444,7 +453,7 @@ fn verify_pallet_indices() { is_pallet_index::(103); is_pallet_index::(104); is_pallet_index::(105); - is_pallet_index::(106); + // is_pallet_index::(106); Removed is_pallet_index::(107); } @@ -1617,26 +1626,27 @@ fn root_can_change_default_xcm_vers() { .build() .execute_with(|| { let source_location = AssetType::Xcm(xcm::v3::Location::parent()); - let dest = Location { - parents: 1, - interior: [AccountId32 { - network: None, - id: [1u8; 32], - }] - .into(), - }; let source_id: moonbeam_runtime::AssetId = source_location.clone().into(); + let asset = currency_to_asset(CurrencyId::ForeignAsset(source_id), 100_000_000_000_000); // Default XCM version is not set yet, so xtokens should fail because it does not // know with which version to send assert_noop!( - XTokens::transfer( + PolkadotXcm::transfer_assets( origin_of(AccountId::from(ALICE)), - CurrencyId::ForeignAsset(source_id), - 100_000_000_000_000, - Box::new(xcm::VersionedLocation::V4(dest.clone())), - WeightLimit::Limited(4000000000.into()) + Box::new(VersionedLocation::V4(Location::parent())), + Box::new(VersionedLocation::V4(Location { + parents: 0, + interior: [AccountId32 { + network: None, + id: [1u8; 32], + }] + .into(), + })), + Box::new(VersionedAssets::V4(asset.clone().into())), + 0, + WeightLimit::Unlimited ), - orml_xtokens::Error::::XcmExecutionFailed + pallet_xcm::Error::::BadVersion ); // Root sets the defaultXcm @@ -1646,12 +1656,20 @@ fn root_can_change_default_xcm_vers() { )); // Now transferring does not fail - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( origin_of(AccountId::from(ALICE)), - CurrencyId::ForeignAsset(source_id), - 100_000_000_000_000, - Box::new(xcm::VersionedLocation::V4(dest)), - WeightLimit::Limited(4000000000.into()) + Box::new(VersionedLocation::V4(Location::parent())), + Box::new(VersionedLocation::V4(Location { + parents: 0, + interior: [AccountId32 { + network: None, + id: [1u8; 32], + }] + .into(), + })), + Box::new(VersionedAssets::V4(asset.clone().into())), + 0, + WeightLimit::Unlimited )); }) } @@ -2018,21 +2036,25 @@ fn make_sure_glmr_can_be_transferred_precompile() { .with_safe_xcm_version(2) .build() .execute_with(|| { - let dest = Location { - parents: 1, - interior: [AccountId32 { - network: None, - id: [1u8; 32], - }] - .into(), - }; - assert_ok!(XTokens::transfer_multiasset( + assert_ok!(PolkadotXcm::transfer_assets( origin_of(AccountId::from(ALICE)), - Box::new(VersionedAsset::V4(Asset { - id: AssetId(moonbeam_runtime::xcm_config::SelfReserve::get()), - fun: Fungible(1000) + Box::new(VersionedLocation::V4(Location::parent())), + Box::new(VersionedLocation::V4(Location { + parents: 0, + interior: [AccountId32 { + network: None, + id: [1u8; 32], + }] + .into(), })), - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedAssets::V4( + Asset { + id: AssetId(moonbeam_runtime::xcm_config::SelfReserve::get()), + fun: Fungible(1000) + } + .into() + )), + 0, WeightLimit::Limited(40000.into()) )); }); @@ -2061,11 +2083,18 @@ fn make_sure_glmr_can_be_transferred() { }] .into(), }; - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( origin_of(AccountId::from(ALICE)), - CurrencyId::SelfReserve, - 100, + Box::new(VersionedLocation::V4(Location::parent())), Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedAssets::V4( + Asset { + id: AssetId(moonbeam_runtime::xcm_config::SelfReserve::get()), + fun: Fungible(100) + } + .into() + )), + 0, WeightLimit::Limited(40000.into()) )); }); @@ -2319,14 +2348,17 @@ fn call_xtokens_with_fee() { let before_balance = moonbeam_runtime::Assets::balance(source_id, &AccountId::from(ALICE)); - + let (chain_part, beneficiary) = + split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(CurrencyId::ForeignAsset(source_id), 100_000_000_000_000); + let asset_fee = currency_to_asset(CurrencyId::ForeignAsset(source_id), 100); // We are able to transfer with fee - assert_ok!(XTokens::transfer_with_fee( + assert_ok!(PolkadotXcm::transfer_assets( origin_of(AccountId::from(ALICE)), - CurrencyId::ForeignAsset(source_id), - 100_000_000_000_000, - 100, - Box::new(xcm::VersionedLocation::V4(dest.clone())), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset_fee, asset].into())), + 0, WeightLimit::Limited(4000000000.into()) )); diff --git a/runtime/moonbeam/tests/xcm_mock/parachain.rs b/runtime/moonbeam/tests/xcm_mock/parachain.rs index 47fec7fa20..a754c92761 100644 --- a/runtime/moonbeam/tests/xcm_mock/parachain.rs +++ b/runtime/moonbeam/tests/xcm_mock/parachain.rs @@ -57,7 +57,6 @@ use xcm_builder::{ TakeWeightCredit, WithComputedOrigin, }; use xcm_executor::{traits::JustTry, Config, XcmExecutor}; -use xcm_primitives::parameter_type_with_key; #[cfg(feature = "runtime-benchmarks")] use moonbeam_runtime_common::benchmarking::BenchmarkHelper as ArgumentsBenchmarkHelper; diff --git a/runtime/moonbeam/tests/xcm_tests.rs b/runtime/moonbeam/tests/xcm_tests.rs index 1fdaa220d3..781de53ab3 100644 --- a/runtime/moonbeam/tests/xcm_tests.rs +++ b/runtime/moonbeam/tests/xcm_tests.rs @@ -29,18 +29,25 @@ use pallet_xcm_transactor::{ Currency, CurrencyPayment, HrmpInitParams, HrmpOperation, TransactWeights, }; use sp_core::ConstU32; -use sp_runtime::traits::MaybeEquivalence; -use xcm::latest::prelude::{ - AccountId32, AccountKey20, Asset as XcmAsset, AssetId as XcmAssetId, Assets as XcmAssets, - Fungible, GeneralIndex, Junction, Junctions, Limited, Location, OriginKind, PalletInstance, - Parachain, QueryResponse, Reanchorable, Response, WeightLimit, Xcm, +use sp_runtime::traits::{Convert, MaybeEquivalence}; +use xcm::{ + latest::{ + prelude::{ + AccountId32, AccountKey20, Fungible, GeneralIndex, Junction, Junctions, Limited, + Location, OriginKind, PalletInstance, Parachain, QueryResponse, Reanchorable, Response, + WeightLimit, Xcm, + }, + Asset, AssetId, Fungibility, + }, + IntoVersion, VersionedAssets, VersionedLocation, WrapVersion, }; -use xcm::{IntoVersion, VersionedLocation, WrapVersion}; use xcm_executor::traits::ConvertLocation; -use xcm_mock::parachain; +use xcm_mock::parachain::{self, PolkadotXcm}; use xcm_mock::relay_chain; use xcm_mock::*; -use xcm_primitives::{UtilityEncodeCall, DEFAULT_PROOF_SIZE}; +use xcm_primitives::{ + split_location_into_chain_part_and_beneficiary, UtilityEncodeCall, DEFAULT_PROOF_SIZE, +}; use xcm_simulator::TestExt; fn add_supported_asset(asset_type: parachain::AssetType, units_per_second: u128) -> Result<(), ()> { @@ -76,6 +83,18 @@ fn add_supported_asset(asset_type: parachain::AssetType, units_per_second: u128) Ok(()) } +fn currency_to_asset(currency_id: parachain::CurrencyId, amount: u128) -> Asset { + Asset { + id: AssetId( + ::CurrencyIdToLocation::convert( + currency_id, + ) + .unwrap(), + ), + fun: Fungibility::Fungible(amount), + } +} + // Send a relay asset (like DOT) to a parachain A #[test] fn receive_relay_asset_from_relay() { @@ -192,13 +211,15 @@ fn send_relay_asset_to_relay() { }] .into(), }; - + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 123); ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 123, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -285,13 +306,15 @@ fn send_relay_asset_to_para_b() { ] .into(), }; - + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -349,14 +372,17 @@ fn send_para_a_asset_to_para_b() { .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); // Native token is substracted in paraA ParaA::execute_with(|| { // Free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(800000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -427,12 +453,15 @@ fn send_para_a_asset_from_para_b_to_para_c() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) )); }); @@ -462,13 +491,15 @@ fn send_para_a_asset_from_para_b_to_para_c() { ] .into(), }; - + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaB::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) )); }); @@ -520,13 +551,15 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a() { ] .into(), }; - + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) )); }); @@ -556,12 +589,15 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaB::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) )); }); @@ -677,14 +713,17 @@ fn send_para_a_asset_to_para_b_with_trader() { .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); // In destination chain, we only need 4 weight // We put 10 weight, 6 of which should be refunded and 4 of which should go to treasury ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(10u64, DEFAULT_PROOF_SIZE)) )); }); @@ -749,15 +788,17 @@ fn send_para_a_asset_to_para_b_with_trader_and_fee() { ] .into(), }; - + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset_fee = currency_to_asset(parachain::CurrencyId::SelfReserve, 1); // we use transfer_with_fee ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_with_fee( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - 1, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset_fee, asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(800000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -915,14 +956,17 @@ fn transact_through_derivative_multilocation() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1054,14 +1098,17 @@ fn transact_through_derivative_with_custom_fee_weight() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1205,14 +1252,17 @@ fn transact_through_derivative_with_custom_fee_weight_refund() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1367,14 +1417,17 @@ fn transact_through_sovereign() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1619,14 +1672,17 @@ fn transact_through_sovereign_with_custom_fee_weight() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1768,14 +1824,17 @@ fn transact_through_sovereign_with_custom_fee_weight_refund() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -2540,20 +2599,21 @@ fn send_statemint_asset_from_para_a_to_statemint_with_relay_fee() { // Check that BOB's balance is empty before the transfer assert_eq!(StatemintAssets::account_balances(RELAYBOB), vec![]); }); - + let (chain_part, beneficiary) = + split_location_into_chain_part_and_beneficiary(statemint_beneficiary).unwrap(); + let asset = currency_to_asset( + parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), + 100, + ); + let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 1); // Transfer USDC from Parachain A to Statemint using Relay asset as fee ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_multicurrencies( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - vec![ - ( - parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), - 100 - ), - (parachain::CurrencyId::ForeignAsset(source_relay_id), 100) - ], + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset, asset_fee].into())), 1, - Box::new(VersionedLocation::V4(statemint_beneficiary)), WeightLimit::Limited(Weight::from_parts(80_000_000u64, 100_000u64)) )); }); @@ -2681,14 +2741,17 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer() { }, ], ); + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_relay_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); @@ -2834,15 +2897,18 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_with_fee() { }, ], ); + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 10); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_with_fee( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_relay_id), - 100, - 10, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset_fee, asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); @@ -2991,13 +3057,15 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multiasset() { }, ], ); - + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_multiasset( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - Box::new((Location::parent(), 100).into()), - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4((Location::parent(), 100).into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); @@ -3222,19 +3290,22 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multicurrencies() { ], ); + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset_1 = currency_to_asset( + parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), + 100, + ); + let asset_2 = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let assets_to_send = vec![asset_1, asset_2]; + // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_multicurrencies( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - vec![ - ( - parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), - 100 - ), - (parachain::CurrencyId::ForeignAsset(source_relay_id), 100) - ], + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(assets_to_send.into())), 1, - Box::new(VersionedLocation::V4(dest)), WeightLimit::Limited(Weight::from_parts(80_000_000u64, 100_000u64)) )); @@ -3468,30 +3539,30 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multiassets() { ], ); - let statemint_asset_to_send = XcmAsset { - id: XcmAssetId(statemint_asset), + let statemint_asset_to_send = Asset { + id: AssetId(statemint_asset), fun: Fungible(100), }; - let relay_asset_to_send = XcmAsset { - id: XcmAssetId(Location::parent()), + let relay_asset_to_send = Asset { + id: AssetId(Location::parent()), fun: Fungible(100), }; - let assets_to_send: XcmAssets = - XcmAssets::from(vec![statemint_asset_to_send, relay_asset_to_send.clone()]); - + let assets_to_send = vec![statemint_asset_to_send, relay_asset_to_send.clone()]; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); // For some reason the order of the assets is inverted when creating the array above. // We need to use relay asset for fees, so we pick index 0. assert_eq!(assets_to_send.get(0).unwrap(), &relay_asset_to_send); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_multiassets( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - Box::new(assets_to_send.into()), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(assets_to_send.into())), 0, - Box::new(VersionedLocation::V4(dest)), WeightLimit::Limited(Weight::from_parts(80_000_000u64, 100_000u64)) )); diff --git a/runtime/moonriver/tests/integration_test.rs b/runtime/moonriver/tests/integration_test.rs index b5c6464749..435f40a75f 100644 --- a/runtime/moonriver/tests/integration_test.rs +++ b/runtime/moonriver/tests/integration_test.rs @@ -38,8 +38,7 @@ use moonriver_runtime::{ xcm_config::{CurrencyId, SelfReserve}, AssetId, Balances, CrowdloanRewards, Executive, OpenTechCommitteeCollective, PolkadotXcm, Precompiles, RuntimeBlockWeights, TransactionPayment, TransactionPaymentAsGasPrice, - TreasuryCouncilCollective, XTokens, XcmTransactor, FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, - WEEKS, + TreasuryCouncilCollective, XcmTransactor, FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, WEEKS, }; use nimbus_primitives::NimbusId; use pallet_evm::PrecompileSet; @@ -64,6 +63,7 @@ use xcm::latest::prelude::*; use xcm::{VersionedAssets, VersionedLocation}; use xcm_builder::{ParentIsPreset, SiblingParachainConvertsVia}; use xcm_executor::traits::ConvertLocation; +use xcm_primitives::split_location_into_chain_part_and_beneficiary; type BatchPCall = pallet_evm_precompile_batch::BatchPrecompileCall; type CrowdloanRewardsPCall = @@ -82,6 +82,18 @@ type XcmTransactorV2PCall = const BASE_FEE_GENESIS: u128 = 100 * GIGAWEI; +fn currency_to_asset(currency_id: CurrencyId, amount: u128) -> Asset { + Asset { + id: AssetId( + ::CurrencyIdToLocation::convert( + currency_id, + ) + .unwrap(), + ), + fun: Fungibility::Fungible(amount), + } +} + #[test] fn xcmp_queue_controller_origin_is_root() { // important for the XcmExecutionManager impl of PauseExecution which uses root origin @@ -132,7 +144,6 @@ fn verify_pallet_prefixes() { is_pallet_prefix::("DmpQueue"); is_pallet_prefix::("PolkadotXcm"); is_pallet_prefix::("Assets"); - is_pallet_prefix::("XTokens"); is_pallet_prefix::("AssetManager"); is_pallet_prefix::("Migrations"); is_pallet_prefix::("XcmTransactor"); @@ -439,7 +450,7 @@ fn verify_pallet_indices() { is_pallet_index::(103); is_pallet_index::(104); is_pallet_index::(105); - is_pallet_index::(106); + // is_pallet_index::(106); Removed is_pallet_index::(107); } @@ -1609,17 +1620,21 @@ fn root_can_change_default_xcm_vers() { .into(), }; let source_id: moonriver_runtime::AssetId = source_location.clone().into(); + let asset = currency_to_asset(CurrencyId::ForeignAsset(source_id), 100_000_000_000_000); + let (chain_part, beneficiary) = + split_location_into_chain_part_and_beneficiary(dest).unwrap(); // Default XCM version is not set yet, so xtokens should fail because it does not // know with which version to send assert_noop!( - XTokens::transfer( + PolkadotXcm::transfer_assets( origin_of(AccountId::from(ALICE)), - CurrencyId::ForeignAsset(source_id), - 100_000_000_000_000, - Box::new(xcm::VersionedLocation::V4(dest.clone())), + Box::new(xcm::VersionedLocation::V4(chain_part.clone())), + Box::new(xcm::VersionedLocation::V4(beneficiary.clone())), + Box::new(VersionedAssets::V4(asset.clone().into())), + 0, WeightLimit::Limited(4000000000.into()) ), - orml_xtokens::Error::::XcmExecutionFailed + pallet_xcm::Error::::BadVersion ); // Root sets the defaultXcm @@ -1629,11 +1644,12 @@ fn root_can_change_default_xcm_vers() { )); // Now transferring does not fail - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( origin_of(AccountId::from(ALICE)), - CurrencyId::ForeignAsset(source_id), - 100_000_000_000_000, - Box::new(xcm::VersionedLocation::V4(dest)), + Box::new(xcm::VersionedLocation::V4(chain_part)), + Box::new(xcm::VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(asset.clone().into())), + 0, WeightLimit::Limited(4000000000.into()) )); }) @@ -2232,14 +2248,19 @@ fn call_xtokens_with_fee() { let before_balance = moonriver_runtime::Assets::balance(source_id, &AccountId::from(ALICE)); + let asset = currency_to_asset(CurrencyId::ForeignAsset(source_id), 100_000_000_000_000); + let asset_fee = currency_to_asset(CurrencyId::ForeignAsset(source_id), 100); + let (chain_part, beneficiary) = + split_location_into_chain_part_and_beneficiary(dest).unwrap(); + // We are able to transfer with fee - assert_ok!(XTokens::transfer_with_fee( + assert_ok!(PolkadotXcm::transfer_assets( origin_of(AccountId::from(ALICE)), - CurrencyId::ForeignAsset(source_id), - 100_000_000_000_000, - 100, - Box::new(xcm::VersionedLocation::V4(dest.clone())), - WeightLimit::Limited(4000000000.into()) + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset_fee, asset].into())), + 0, + WeightLimit::Limited(4000000000.into()), ),); let after_balance = diff --git a/runtime/moonriver/tests/xcm_mock/parachain.rs b/runtime/moonriver/tests/xcm_mock/parachain.rs index db10312665..c0b4e7097f 100644 --- a/runtime/moonriver/tests/xcm_mock/parachain.rs +++ b/runtime/moonriver/tests/xcm_mock/parachain.rs @@ -55,7 +55,6 @@ use xcm_builder::{ TakeWeightCredit, WithComputedOrigin, }; use xcm_executor::{traits::JustTry, Config, XcmExecutor}; -use xcm_primitives::parameter_type_with_key; #[cfg(feature = "runtime-benchmarks")] use moonbeam_runtime_common::benchmarking::BenchmarkHelper as ArgumentsBenchmarkHelper; diff --git a/runtime/moonriver/tests/xcm_mock/statemine_like.rs b/runtime/moonriver/tests/xcm_mock/statemine_like.rs index f5d2b46cdf..52091fb0bf 100644 --- a/runtime/moonriver/tests/xcm_mock/statemine_like.rs +++ b/runtime/moonriver/tests/xcm_mock/statemine_like.rs @@ -323,8 +323,7 @@ impl Config for XcmConfig { type XcmSender = XcmRouter; type AssetTransactor = AssetTransactors; type OriginConverter = XcmOriginToTransactDispatchOrigin; - type IsReserve = - orml_xcm_support::MultiNativeAsset; + type IsReserve = xcm_primitives::MultiNativeAsset; type IsTeleporter = TrustedTeleporters; type UniversalLocation = UniversalLocation; type Barrier = Barrier; diff --git a/runtime/moonriver/tests/xcm_tests.rs b/runtime/moonriver/tests/xcm_tests.rs index ceee8aa521..e113cf8c7e 100644 --- a/runtime/moonriver/tests/xcm_tests.rs +++ b/runtime/moonriver/tests/xcm_tests.rs @@ -24,16 +24,18 @@ use frame_support::{ BoundedVec, }; use sp_core::ConstU32; -use sp_runtime::traits::MaybeEquivalence; -use xcm::latest::prelude::{ - AccountId32, AccountKey20, All, Asset as XcmAsset, AssetId as XcmAssetId, Assets as XcmAssets, - BuyExecution, ClearOrigin, DepositAsset, Fungible, GeneralIndex, Junction, Junctions, Limited, - Location, OriginKind, PalletInstance, Parachain, QueryResponse, Reanchorable, Response, - WeightLimit, WithdrawAsset, Xcm, +use sp_runtime::traits::{Convert, MaybeEquivalence}; +use xcm::{ + latest::prelude::{ + AccountId32, AccountKey20, All, Asset, AssetId, BuyExecution, ClearOrigin, DepositAsset, + Fungibility, GeneralIndex, Junction, Junctions, Limited, Location, OriginKind, + PalletInstance, Parachain, QueryResponse, Reanchorable, Response, WeightLimit, + WithdrawAsset, Xcm, + }, + IntoVersion, VersionedAssets, VersionedLocation, WrapVersion, }; -use xcm::{IntoVersion, VersionedLocation, WrapVersion}; use xcm_executor::traits::ConvertLocation; -use xcm_mock::parachain; +use xcm_mock::parachain::{self, PolkadotXcm}; use xcm_mock::relay_chain; use xcm_mock::*; use xcm_simulator::TestExt; @@ -42,7 +44,9 @@ use cumulus_primitives_core::relay_chain::HrmpChannelId; use pallet_xcm_transactor::{ Currency, CurrencyPayment, HrmpInitParams, HrmpOperation, TransactWeights, }; -use xcm_primitives::{UtilityEncodeCall, DEFAULT_PROOF_SIZE}; +use xcm_primitives::{ + split_location_into_chain_part_and_beneficiary, UtilityEncodeCall, DEFAULT_PROOF_SIZE, +}; fn add_supported_asset(asset_type: parachain::AssetType, units_per_second: u128) -> Result<(), ()> { let parachain::AssetType::Xcm(location_v3) = asset_type; @@ -77,6 +81,18 @@ fn add_supported_asset(asset_type: parachain::AssetType, units_per_second: u128) Ok(()) } +fn currency_to_asset(currency_id: parachain::CurrencyId, amount: u128) -> Asset { + Asset { + id: AssetId( + ::CurrencyIdToLocation::convert( + currency_id, + ) + .unwrap(), + ), + fun: Fungibility::Fungible(amount), + } +} + // Send a relay asset (like DOT) to a parachain A #[test] fn receive_relay_asset_from_relay() { @@ -190,13 +206,16 @@ fn send_relay_asset_to_relay() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 123); ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 123, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -282,13 +301,16 @@ fn send_relay_asset_to_para_b() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -345,13 +367,16 @@ fn send_para_a_asset_to_para_b() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(800000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -425,12 +450,16 @@ fn send_para_a_asset_from_para_b_to_para_c() { ] .into(), }; - ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + + ParaB::execute_with(|| { + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) )); }); @@ -460,13 +489,16 @@ fn send_para_a_asset_from_para_b_to_para_c() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaB::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) )); }); @@ -519,12 +551,16 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a() { ] .into(), }; - ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + + ParaB::execute_with(|| { + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) )); }); @@ -554,12 +590,16 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + ParaB::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) )); }); @@ -612,12 +652,16 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a_with_new_reanchoring() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) )); }); @@ -826,15 +870,18 @@ fn send_para_a_asset_to_para_b_with_trader() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); // In destination chain, we only need 4 weight // We put 10 weight, 6 of which should be refunded and 4 of which should go to treasury ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(10u64, DEFAULT_PROOF_SIZE)) )); }); @@ -899,15 +946,18 @@ fn send_para_a_asset_to_para_b_with_trader_and_fee() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset_fee = currency_to_asset(parachain::CurrencyId::SelfReserve, 1); // we use transfer_with_fee ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_with_fee( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - 1, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset_fee, asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(800000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1065,14 +1115,17 @@ fn transact_through_derivative_multilocation() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1204,14 +1257,17 @@ fn transact_through_derivative_with_custom_fee_weight() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1355,14 +1411,17 @@ fn transact_through_derivative_with_custom_fee_weight_refund() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1517,14 +1576,17 @@ fn transact_through_sovereign() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1769,14 +1831,17 @@ fn transact_through_sovereign_with_custom_fee_weight() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -1918,14 +1983,17 @@ fn transact_through_sovereign_with_custom_fee_weight_refund() { }] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); }); @@ -2222,13 +2290,16 @@ fn test_automatic_versioning_on_runtime_upgrade_with_para_b() { ] .into(), }; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaA::execute_with(|| { // free execution, full amount received - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::SelfReserve, - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) )); // free execution, full amount received @@ -2838,20 +2909,22 @@ fn send_statemine_asset_from_para_a_to_statemine_with_relay_fee() { // Check that BOB's balance is empty before the transfer assert_eq!(StatemineAssets::account_balances(RELAYBOB), vec![]); }); - + let (chain_part, beneficiary) = + split_location_into_chain_part_and_beneficiary(statemine_beneficiary).unwrap(); + let asset_1 = currency_to_asset( + parachain::CurrencyId::ForeignAsset(source_statemine_asset_id), + 100, + ); + let asset_2 = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let assets_to_send = vec![asset_1, asset_2]; // Transfer USDC from Parachain A to Statemine using Relay asset as fee ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_multicurrencies( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - vec![ - ( - parachain::CurrencyId::ForeignAsset(source_statemine_asset_id), - 100 - ), - (parachain::CurrencyId::ForeignAsset(source_relay_id), 100) - ], + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(assets_to_send.into())), 1, - Box::new(VersionedLocation::V4(statemine_beneficiary)), WeightLimit::Limited(Weight::from_parts(80_000_000u64, 100_000u64)) )); }); @@ -2978,14 +3051,16 @@ fn send_dot_from_moonbeam_to_statemine_via_xtokens_transfer() { }, ], ); - + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - assert_ok!(XTokens::transfer( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_relay_id), - 100, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); @@ -3131,15 +3206,17 @@ fn send_dot_from_moonbeam_to_statemine_via_xtokens_transfer_with_fee() { }, ], ); - + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 10); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_with_fee( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - parachain::CurrencyId::ForeignAsset(source_relay_id), - 100, - 10, - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset_fee, asset].into())), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); @@ -3289,12 +3366,18 @@ fn send_dot_from_moonbeam_to_statemine_via_xtokens_transfer_multiasset() { ], ); + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_multiasset( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - Box::new((Location::parent(), 100).into()), - Box::new(VersionedLocation::V4(dest)), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4( + vec![(Location::parent(), 100).into()].into() + )), + 0, WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) )); @@ -3519,19 +3602,20 @@ fn send_dot_from_moonbeam_to_statemine_via_xtokens_transfer_multicurrencies() { ], ); + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let asset_1 = currency_to_asset( + parachain::CurrencyId::ForeignAsset(source_statemine_asset_id), + 100, + ); + let asset_2 = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_multicurrencies( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - vec![ - ( - parachain::CurrencyId::ForeignAsset(source_statemine_asset_id), - 100 - ), - (parachain::CurrencyId::ForeignAsset(source_relay_id), 100) - ], + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(vec![asset_1, asset_2].into())), 1, - Box::new(VersionedLocation::V4(dest)), WeightLimit::Limited(Weight::from_parts(80_000_000u64, 100_000u64)) )); @@ -3765,30 +3849,30 @@ fn send_dot_from_moonbeam_to_statemine_via_xtokens_transfer_multiassets() { ], ); - let statemine_asset_to_send = XcmAsset { - id: XcmAssetId(statemine_asset), - fun: Fungible(100), + let statemine_asset_to_send = Asset { + id: AssetId(statemine_asset), + fun: Fungibility::Fungible(100), }; - let relay_asset_to_send = XcmAsset { - id: XcmAssetId(Location::parent()), - fun: Fungible(100), + let relay_asset_to_send = Asset { + id: AssetId(Location::parent()), + fun: Fungibility::Fungible(100), }; - let assets_to_send: XcmAssets = - XcmAssets::from(vec![statemine_asset_to_send, relay_asset_to_send.clone()]); - + let assets_to_send = vec![statemine_asset_to_send, relay_asset_to_send.clone()]; + let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); // For some reason the order of the assets is inverted when creating the array above. // We need to use relay asset for fees, so we pick index 0. assert_eq!(assets_to_send.get(0).unwrap(), &relay_asset_to_send); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - assert_ok!(XTokens::transfer_multiassets( + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), - Box::new(assets_to_send.into()), + Box::new(VersionedLocation::V4(chain_part)), + Box::new(VersionedLocation::V4(beneficiary)), + Box::new(VersionedAssets::V4(assets_to_send.into())), 0, - Box::new(VersionedLocation::V4(dest)), WeightLimit::Limited(Weight::from_parts(80_000_000u64, 100_000u64)) )); From 0c86795364c2b408b81d1df87a95d4efe0d6a00f Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Mon, 7 Oct 2024 12:10:19 +0200 Subject: [PATCH 13/24] fix --- Cargo.toml | 1 - .../moonbase/tests/xcm_mock/statemint_like.rs | 7 +- runtime/moonbase/tests/xcm_tests.rs | 51 +++++++------- runtime/moonbeam/tests/xcm_tests.rs | 54 +++++++-------- runtime/moonriver/tests/xcm_tests.rs | 66 ++++++++++--------- 5 files changed, 89 insertions(+), 90 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8eb1c18000..9ff6678e5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -439,7 +439,6 @@ crossbeam-deque = { opt-level = 3 } crypto-mac = { opt-level = 3 } curve25519-dalek = { opt-level = 3 } ed25519-zebra = { opt-level = 3 } -flate2 = { opt-level = 3 } futures-channel = { opt-level = 3 } hash-db = { opt-level = 3 } hashbrown = { opt-level = 3 } diff --git a/runtime/moonbase/tests/xcm_mock/statemint_like.rs b/runtime/moonbase/tests/xcm_mock/statemint_like.rs index b1747bd6f8..8344560123 100644 --- a/runtime/moonbase/tests/xcm_mock/statemint_like.rs +++ b/runtime/moonbase/tests/xcm_mock/statemint_like.rs @@ -320,12 +320,9 @@ pub struct TrustedReserves; impl ContainsPair for TrustedReserves { fn contains(asset: &Asset, origin: &Location) -> bool { let AssetId(location) = &asset.id; - match ( - &asset.id.0.parent_count(), - &asset.id.0.first_interior().unwrap(), - ) { + match (&asset.id.0.parent_count(), &asset.id.0.first_interior()) { // Sibling parachains - (1, Junction::Parachain(_id)) => location.chain_location() == *origin, + (1, Some(Junction::Parachain(_id))) => location.chain_location() == *origin, // Relay chain (1, _) => location.chain_location() == *origin, // Here diff --git a/runtime/moonbase/tests/xcm_tests.rs b/runtime/moonbase/tests/xcm_tests.rs index 4d3de2f021..3020d548f8 100644 --- a/runtime/moonbase/tests/xcm_tests.rs +++ b/runtime/moonbase/tests/xcm_tests.rs @@ -199,9 +199,9 @@ fn send_relay_asset_to_relay() { }); let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 123); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 123); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -297,9 +297,9 @@ fn send_relay_asset_to_para_b() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -364,9 +364,9 @@ fn send_para_a_asset_to_para_b() { }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); // Free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -446,9 +446,9 @@ fn send_para_a_asset_from_para_b_to_para_c() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -486,9 +486,9 @@ fn send_para_a_asset_from_para_b_to_para_c() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaB::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -548,9 +548,9 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -587,9 +587,9 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaB::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -648,9 +648,9 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a_with_new_reanchoring() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -817,11 +817,11 @@ fn send_para_a_asset_to_para_b_with_trader() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); // In destination chain, we only need 4 weight // We put 10 weight, 6 of which should be refunded and 4 of which should go to treasury ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -893,10 +893,10 @@ fn send_para_a_asset_to_para_b_with_trader_and_fee() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); - let asset_fee = currency_to_asset(parachain::CurrencyId::SelfReserve, 1); // we use transfer_with_fee ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset_fee = currency_to_asset(parachain::CurrencyId::SelfReserve, 1); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -1063,9 +1063,9 @@ fn transact_through_derivative_multilocation() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1215,9 +1215,9 @@ fn transact_through_derivative_with_custom_fee_weight() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1369,9 +1369,9 @@ fn transact_through_derivative_with_custom_fee_weight_refund() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1534,9 +1534,9 @@ fn transact_through_sovereign() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1789,9 +1789,9 @@ fn transact_through_sovereign_with_custom_fee_weight() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1941,9 +1941,9 @@ fn transact_through_sovereign_with_custom_fee_weight_refund() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -2248,8 +2248,8 @@ fn test_automatic_versioning_on_runtime_upgrade_with_para_b() { } .into(); let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -2869,13 +2869,14 @@ fn send_statemint_asset_from_para_a_to_statemint_with_relay_fee() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(statemint_beneficiary).unwrap(); + + // Transfer USDC from Parachain A to Statemint using Relay asset as fee + ParaA::execute_with(|| { let asset = currency_to_asset( parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), 100, ); let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); - // Transfer USDC from Parachain A to Statemint using Relay asset as fee - ParaA::execute_with(|| { assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -3009,10 +3010,10 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer() { ], ); let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -3165,11 +3166,11 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_with_fee() { ], ); let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); - let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 10); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 10); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -3563,13 +3564,13 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multicurrencies() { ); let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA + ParaA::execute_with(|| { let asset = currency_to_asset( parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), 100, ); let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); - // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA - ParaA::execute_with(|| { assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), diff --git a/runtime/moonbeam/tests/xcm_tests.rs b/runtime/moonbeam/tests/xcm_tests.rs index 781de53ab3..4097f3dfc4 100644 --- a/runtime/moonbeam/tests/xcm_tests.rs +++ b/runtime/moonbeam/tests/xcm_tests.rs @@ -212,8 +212,8 @@ fn send_relay_asset_to_relay() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 123); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 123); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -307,8 +307,8 @@ fn send_relay_asset_to_para_b() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -373,9 +373,9 @@ fn send_para_a_asset_to_para_b() { }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); // Native token is substracted in paraA ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); // Free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -454,8 +454,8 @@ fn send_para_a_asset_from_para_b_to_para_c() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -492,8 +492,8 @@ fn send_para_a_asset_from_para_b_to_para_c() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaB::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -552,8 +552,8 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -590,8 +590,8 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaB::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -714,10 +714,10 @@ fn send_para_a_asset_to_para_b_with_trader() { }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); // In destination chain, we only need 4 weight // We put 10 weight, 6 of which should be refunded and 4 of which should go to treasury ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -789,10 +789,10 @@ fn send_para_a_asset_to_para_b_with_trader_and_fee() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); - let asset_fee = currency_to_asset(parachain::CurrencyId::SelfReserve, 1); // we use transfer_with_fee ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset_fee = currency_to_asset(parachain::CurrencyId::SelfReserve, 1); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -957,9 +957,9 @@ fn transact_through_derivative_multilocation() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1099,9 +1099,9 @@ fn transact_through_derivative_with_custom_fee_weight() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1253,9 +1253,9 @@ fn transact_through_derivative_with_custom_fee_weight_refund() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1418,9 +1418,9 @@ fn transact_through_sovereign() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1673,9 +1673,9 @@ fn transact_through_sovereign_with_custom_fee_weight() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1825,9 +1825,9 @@ fn transact_through_sovereign_with_custom_fee_weight_refund() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -2601,13 +2601,13 @@ fn send_statemint_asset_from_para_a_to_statemint_with_relay_fee() { }); let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(statemint_beneficiary).unwrap(); - let asset = currency_to_asset( - parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), - 100, - ); - let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 1); // Transfer USDC from Parachain A to Statemint using Relay asset as fee ParaA::execute_with(|| { + let asset = currency_to_asset( + parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), + 100, + ); + let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 1); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -2742,10 +2742,10 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer() { ], ); let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -2898,11 +2898,11 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_with_fee() { ], ); let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); - let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 10); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 10); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -3291,15 +3291,15 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multicurrencies() { ); let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + + // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA + ParaA::execute_with(|| { let asset_1 = currency_to_asset( parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), 100, ); let asset_2 = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); let assets_to_send = vec![asset_1, asset_2]; - - // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA - ParaA::execute_with(|| { assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), diff --git a/runtime/moonriver/tests/xcm_tests.rs b/runtime/moonriver/tests/xcm_tests.rs index e113cf8c7e..afb00907ee 100644 --- a/runtime/moonriver/tests/xcm_tests.rs +++ b/runtime/moonriver/tests/xcm_tests.rs @@ -207,9 +207,9 @@ fn send_relay_asset_to_relay() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 123); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 123); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -302,9 +302,9 @@ fn send_relay_asset_to_para_b() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -368,9 +368,9 @@ fn send_para_a_asset_to_para_b() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -451,9 +451,9 @@ fn send_para_a_asset_from_para_b_to_para_c() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaB::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -490,9 +490,9 @@ fn send_para_a_asset_from_para_b_to_para_c() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaB::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -552,9 +552,9 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaB::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -591,9 +591,9 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaB::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -653,9 +653,9 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a_with_new_reanchoring() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -871,11 +871,11 @@ fn send_para_a_asset_to_para_b_with_trader() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); // In destination chain, we only need 4 weight // We put 10 weight, 6 of which should be refunded and 4 of which should go to treasury ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -947,11 +947,11 @@ fn send_para_a_asset_to_para_b_with_trader_and_fee() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); - let asset_fee = currency_to_asset(parachain::CurrencyId::SelfReserve, 1); // we use transfer_with_fee ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset_fee = currency_to_asset(parachain::CurrencyId::SelfReserve, 1); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -1116,9 +1116,9 @@ fn transact_through_derivative_multilocation() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1258,9 +1258,9 @@ fn transact_through_derivative_with_custom_fee_weight() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1412,9 +1412,9 @@ fn transact_through_derivative_with_custom_fee_weight_refund() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1577,9 +1577,9 @@ fn transact_through_sovereign() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1832,9 +1832,9 @@ fn transact_through_sovereign_with_custom_fee_weight() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1984,9 +1984,9 @@ fn transact_through_sovereign_with_custom_fee_weight_refund() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -2291,8 +2291,8 @@ fn test_automatic_versioning_on_runtime_upgrade_with_para_b() { .into(), }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -2911,14 +2911,15 @@ fn send_statemine_asset_from_para_a_to_statemine_with_relay_fee() { }); let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(statemine_beneficiary).unwrap(); - let asset_1 = currency_to_asset( - parachain::CurrencyId::ForeignAsset(source_statemine_asset_id), - 100, - ); - let asset_2 = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); - let assets_to_send = vec![asset_1, asset_2]; + // Transfer USDC from Parachain A to Statemine using Relay asset as fee ParaA::execute_with(|| { + let asset_1 = currency_to_asset( + parachain::CurrencyId::ForeignAsset(source_statemine_asset_id), + 100, + ); + let asset_2 = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let assets_to_send = vec![asset_1, asset_2]; assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -3052,9 +3053,9 @@ fn send_dot_from_moonbeam_to_statemine_via_xtokens_transfer() { ], ); let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -3207,10 +3208,10 @@ fn send_dot_from_moonbeam_to_statemine_via_xtokens_transfer_with_fee() { ], ); let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); - let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 10); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 10); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -3603,13 +3604,14 @@ fn send_dot_from_moonbeam_to_statemine_via_xtokens_transfer_multicurrencies() { ); let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - let asset_1 = currency_to_asset( - parachain::CurrencyId::ForeignAsset(source_statemine_asset_id), - 100, - ); - let asset_2 = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { + let asset_1 = currency_to_asset( + parachain::CurrencyId::ForeignAsset(source_statemine_asset_id), + 100, + ); + let asset_2 = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), From 57e67a847cf9cdc55b6df3dfe7c474bc18783ed5 Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Mon, 7 Oct 2024 13:21:47 +0200 Subject: [PATCH 14/24] Add missing copyright --- primitives/xcm/src/get_by_key.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/primitives/xcm/src/get_by_key.rs b/primitives/xcm/src/get_by_key.rs index 7253470269..0a9b248401 100644 --- a/primitives/xcm/src/get_by_key.rs +++ b/primitives/xcm/src/get_by_key.rs @@ -1,3 +1,19 @@ +// Copyright 2024 Moonbeam foundation +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . + /// A trait for querying a value by a key. pub trait GetByKey { /// Return the value. From 4c5390192d20ca2fd8005e6f83ca7f04bb232911 Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Tue, 8 Oct 2024 08:58:44 +0200 Subject: [PATCH 15/24] Fix rust tests --- precompiles/xtokens/Cargo.toml | 2 + precompiles/xtokens/src/mock.rs | 4 +- precompiles/xtokens/src/tests.rs | 84 ++++++++++----------- runtime/moonbase/tests/integration_test.rs | 8 +- runtime/moonbase/tests/xcm_tests.rs | 77 ++++++++++--------- runtime/moonbeam/tests/integration_test.rs | 6 +- runtime/moonbeam/tests/xcm_tests.rs | 35 +++++---- runtime/moonriver/tests/integration_test.rs | 6 +- runtime/moonriver/tests/xcm_tests.rs | 59 ++++++++------- 9 files changed, 145 insertions(+), 136 deletions(-) diff --git a/precompiles/xtokens/Cargo.toml b/precompiles/xtokens/Cargo.toml index 7021b5c4e9..a75ede8089 100644 --- a/precompiles/xtokens/Cargo.toml +++ b/precompiles/xtokens/Cargo.toml @@ -62,6 +62,8 @@ std = [ "frame-support/std", "frame-system/std", "pallet-evm/std", + "pallet-xcm/std", + "pallet-xcm-transactor/std", "precompile-utils/std", "sp-core/std", "sp-std/std", diff --git a/precompiles/xtokens/src/mock.rs b/precompiles/xtokens/src/mock.rs index b4f9c2264e..93cb545efe 100644 --- a/precompiles/xtokens/src/mock.rs +++ b/precompiles/xtokens/src/mock.rs @@ -360,7 +360,7 @@ impl pallet_xcm_transactor::Config for Runtime { type AccountIdToLocation = AccountIdToLocation; type CurrencyIdToLocation = CurrencyIdToMultiLocation; type SelfLocation = SelfLocation; - type Weigher = FixedWeightBounds; + type Weigher = xcm_builder::FixedWeightBounds; type UniversalLocation = UniversalLocation; type BaseXcmWeight = BaseXcmWeight; type XcmSender = DoNothingRouter; @@ -378,7 +378,7 @@ impl xcm_executor::Config for XcmConfig { type XcmSender = DoNothingRouter; type AssetTransactor = DummyAssetTransactor; type OriginConverter = pallet_xcm::XcmPassthrough; - type IsReserve = (); + type IsReserve = xcm_primitives::MultiNativeAsset; type IsTeleporter = (); type UniversalLocation = UniversalLocation; type Barrier = Barrier; diff --git a/precompiles/xtokens/src/tests.rs b/precompiles/xtokens/src/tests.rs index de6558ea7e..ff06430d68 100644 --- a/precompiles/xtokens/src/tests.rs +++ b/precompiles/xtokens/src/tests.rs @@ -18,7 +18,7 @@ use crate::mock::{ events, AssetAccount, ExtBuilder, PCall, Precompiles, PrecompilesValue, Runtime, SelfReserveAccount, }; -use crate::{Currency, EvmAsset}; +use crate::{Currency, EvmAsset, MAX_ASSETS}; use pallet_xcm::Event as PolkadotXcmEvent; use precompile_utils::{prelude::*, testing::*}; use sp_core::U256; @@ -94,13 +94,13 @@ fn transfer_self_reserve_works() { weight: 4_000_000, }, ) - .expect_cost(3000) + .expect_cost(100000000) .expect_no_logs() .execute_returns(()); let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { outcome: xcm::latest::Outcome::Complete { - used: Weight::zero(), + used: Weight::from_parts(3000, 3000), }, } .into(); @@ -135,13 +135,13 @@ fn transfer_to_reserve_works() { weight: 4_000_000, }, ) - .expect_cost(4000) + .expect_cost(100000000) .expect_no_logs() .execute_returns(()); let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { outcome: xcm::latest::Outcome::Complete { - used: Weight::zero(), + used: Weight::from_parts(2000, 2000), }, } .into(); @@ -175,13 +175,13 @@ fn transfer_to_reserve_with_unlimited_weight_works() { weight: u64::MAX, }, ) - .expect_cost(4000) + .expect_cost(100000000) .expect_no_logs() .execute_returns(()); let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { outcome: xcm::latest::Outcome::Complete { - used: Weight::zero(), + used: Weight::from_parts(2000, 2000), }, } .into(); @@ -218,13 +218,13 @@ fn transfer_to_reserve_with_fee_works() { weight: 4_000_000, }, ) - .expect_cost(4000) + .expect_cost(100000000) .expect_no_logs() .execute_returns(()); let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { outcome: xcm::latest::Outcome::Complete { - used: Weight::zero(), + used: Weight::from_parts(2000, 2000), }, } .into(); @@ -260,13 +260,13 @@ fn transfer_non_reserve_to_non_reserve_works() { weight: 4_000_000, }, ) - .expect_cost(4000) + .expect_cost(100000000) .expect_no_logs() .execute_returns(()); let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { outcome: xcm::latest::Outcome::Complete { - used: Weight::zero(), + used: Weight::from_parts(3000, 3000), }, } .into(); @@ -302,13 +302,13 @@ fn transfer_non_reserve_to_non_reserve_with_fee_works() { weight: 4_000_000, }, ) - .expect_cost(4000) + .expect_cost(100000000) .expect_no_logs() .execute_returns(()); let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { outcome: xcm::latest::Outcome::Complete { - used: Weight::zero(), + used: Weight::from_parts(3000, 3000), }, } .into(); @@ -344,13 +344,13 @@ fn transfer_multi_asset_to_reserve_works() { weight: 4_000_000, }, ) - .expect_cost(4000) + .expect_cost(100000000) .expect_no_logs() .execute_returns(()); let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { outcome: xcm::latest::Outcome::Complete { - used: Weight::zero(), + used: Weight::from_parts(2000, 2000), }, } .into(); @@ -387,13 +387,13 @@ fn transfer_multi_asset_self_reserve_works() { weight: 4_000_000, }, ) - .expect_cost(3000) + .expect_cost(100000000) .expect_no_logs() .execute_returns(()); let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { outcome: xcm::latest::Outcome::Complete { - used: Weight::zero(), + used: Weight::from_parts(3000, 3000), }, } .into(); @@ -430,13 +430,13 @@ fn transfer_multi_asset_self_reserve_with_fee_works() { weight: 4_000_000, }, ) - .expect_cost(3000) + .expect_cost(100000000) .expect_no_logs() .execute_returns(()); let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { outcome: xcm::latest::Outcome::Complete { - used: Weight::zero(), + used: Weight::from_parts(3000, 3000), }, } .into(); @@ -473,13 +473,13 @@ fn transfer_multi_asset_non_reserve_to_non_reserve() { weight: 4_000_000, }, ) - .expect_cost(4000) + .expect_cost(100000000) .expect_no_logs() .execute_returns(()); let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { outcome: xcm::latest::Outcome::Complete { - used: Weight::zero(), + used: Weight::from_parts(3000, 3000), }, } .into(); @@ -517,13 +517,13 @@ fn transfer_multi_asset_non_reserve_to_non_reserve_with_fee() { weight: 4_000_000, }, ) - .expect_cost(4000) + .expect_cost(100000000) .expect_no_logs() .execute_returns(()); let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { outcome: xcm::latest::Outcome::Complete { - used: Weight::zero(), + used: Weight::from_parts(3000, 3000), }, } .into(); @@ -562,13 +562,13 @@ fn transfer_multi_currencies() { weight: 4_000_000, }, ) - .expect_cost(4000) + .expect_cost(100000000) .expect_no_logs() .execute_returns(()); let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { outcome: xcm::latest::Outcome::Complete { - used: Weight::zero(), + used: Weight::from_parts(3000, 3000), }, } .into(); @@ -616,13 +616,13 @@ fn transfer_multi_assets() { weight: 4_000_000, }, ) - .expect_cost(4000) + .expect_cost(100000000) .expect_no_logs() .execute_returns(()); let expected: crate::mock::RuntimeEvent = PolkadotXcmEvent::Attempted { outcome: xcm::latest::Outcome::Complete { - used: Weight::zero(), + used: Weight::from_parts(2000, 2000), }, } .into(); @@ -646,11 +646,10 @@ fn transfer_multi_currencies_cannot_insert_more_than_max() { id: [1u8; 32], }], ); - let currencies: Vec = vec![ - (Address(AssetAccount(1u128).into()), U256::from(500)).into(), - (Address(AssetAccount(2u128).into()), U256::from(500)).into(), - (Address(AssetAccount(3u128).into()), U256::from(500)).into(), - ]; + let mut currencies: Vec = Vec::new(); + for i in 0..MAX_ASSETS + 1 { + currencies.push((Address(AssetAccount(i as u128).into()), U256::from(500)).into()); + } // We are transferring 3 assets, when max is 2 precompiles() @@ -685,19 +684,14 @@ fn transfer_multi_assets_cannot_insert_more_than_max() { ], ); - let asset_1_location = - Location::new(1, [Junction::Parachain(2), Junction::GeneralIndex(0u128)]); - let asset_2_location = - Location::new(1, [Junction::Parachain(2), Junction::GeneralIndex(1u128)]); - - let asset_3_location = - Location::new(1, [Junction::Parachain(2), Junction::GeneralIndex(2u128)]); - - let assets: Vec = vec![ - (asset_1_location.clone(), U256::from(500)).into(), - (asset_2_location.clone(), U256::from(500)).into(), - (asset_3_location.clone(), U256::from(500)).into(), - ]; + let mut assets: Vec = Vec::new(); + for i in 0..MAX_ASSETS + 1 { + let asset_location = Location::new( + 1, + [Junction::Parachain(2), Junction::GeneralIndex(i as u128)], + ); + assets.push((asset_location, U256::from(500)).into()); + } // We are transferring 3 assets, when max is 2 precompiles() diff --git a/runtime/moonbase/tests/integration_test.rs b/runtime/moonbase/tests/integration_test.rs index 92438c4f72..b9018dcb23 100644 --- a/runtime/moonbase/tests/integration_test.rs +++ b/runtime/moonbase/tests/integration_test.rs @@ -1564,7 +1564,7 @@ fn xtokens_precompiles_transfer() { weight: 4_000_000, }, ) - .expect_cost(348298) + .expect_cost(174530) .expect_no_logs() // We expect an evm subcall ERC20.burnFrom .with_subcall_handle(move |subcall| { @@ -1655,7 +1655,7 @@ fn xtokens_precompiles_transfer_multiasset() { weight: 4_000_000, }, ) - .expect_cost(348298) + .expect_cost(174530) .expect_no_logs() // We expect an evm subcall ERC20.burnFrom .with_subcall_handle(move |subcall| { @@ -1739,7 +1739,7 @@ fn xtokens_precompiles_transfer_native() { weight: 4_000_000, }, ) - .expect_cost(16208) + .expect_cost(22930) .expect_no_logs() .execute_returns(()); }) @@ -2103,7 +2103,7 @@ fn root_can_change_default_xcm_vers() { 0, WeightLimit::Unlimited ), - pallet_xcm::Error::::BadVersion + pallet_xcm::Error::::SendFailure ); // Root sets the defaultXcm diff --git a/runtime/moonbase/tests/xcm_tests.rs b/runtime/moonbase/tests/xcm_tests.rs index 3020d548f8..a7f38123be 100644 --- a/runtime/moonbase/tests/xcm_tests.rs +++ b/runtime/moonbase/tests/xcm_tests.rs @@ -198,10 +198,19 @@ fn send_relay_asset_to_relay() { balance_before_sending = RelayBalances::free_balance(&RELAYALICE); }); + // We now send back some money to the relay + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: RELAYALICE.into(), + }] + .into(), + }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 123); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 123); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -299,7 +308,7 @@ fn send_relay_asset_to_para_b() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -448,7 +457,7 @@ fn send_para_a_asset_from_para_b_to_para_c() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -488,7 +497,7 @@ fn send_para_a_asset_from_para_b_to_para_c() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaB::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -550,7 +559,7 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -589,7 +598,7 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaB::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -650,7 +659,7 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a_with_new_reanchoring() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -821,7 +830,7 @@ fn send_para_a_asset_to_para_b_with_trader() { // In destination chain, we only need 4 weight // We put 10 weight, 6 of which should be refunded and 4 of which should go to treasury ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -895,8 +904,8 @@ fn send_para_a_asset_to_para_b_with_trader_and_fee() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); // we use transfer_with_fee ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); - let asset_fee = currency_to_asset(parachain::CurrencyId::SelfReserve, 1); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset_fee = currency_to_asset(parachain::CurrencyId::SelfReserve, 1); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -1065,7 +1074,7 @@ fn transact_through_derivative_multilocation() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1217,7 +1226,7 @@ fn transact_through_derivative_with_custom_fee_weight() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1536,7 +1545,7 @@ fn transact_through_sovereign() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1791,7 +1800,7 @@ fn transact_through_sovereign_with_custom_fee_weight() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1943,7 +1952,7 @@ fn transact_through_sovereign_with_custom_fee_weight_refund() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -2249,7 +2258,7 @@ fn test_automatic_versioning_on_runtime_upgrade_with_para_b() { .into(); let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -2872,11 +2881,12 @@ fn send_statemint_asset_from_para_a_to_statemint_with_relay_fee() { // Transfer USDC from Parachain A to Statemint using Relay asset as fee ParaA::execute_with(|| { - let asset = currency_to_asset( - parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), - 100, - ); - let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let asset = currency_to_asset( + parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), + 100, + ); + let asset_fee = + currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -3013,7 +3023,7 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer() { // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -3169,8 +3179,8 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_with_fee() { // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); - let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 10); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 10); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -3566,11 +3576,12 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multicurrencies() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - let asset = currency_to_asset( - parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), - 100, - ); - let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let asset = currency_to_asset( + parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), + 100, + ); + let asset_fee = + currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -3585,10 +3596,9 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multicurrencies() { Statemint::execute_with(|| { // Check that Bob received relay tokens back in AssetHub - // (100 - MinXcmFee) assert_eq!( StatemintBalances::free_balance(RELAYBOB), - INITIAL_BALANCE + 50 + INITIAL_BALANCE + 100 ); // Check that BOB received 100 USDC on AssetHub @@ -3834,7 +3844,7 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multiassets() { parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), Box::new(VersionedLocation::V4(beneficiary)), - Box::new(VersionedAssets::V4(assets_to_send.into())), + Box::new(VersionedAssets::V4(assets_to_send)), 0, WeightLimit::Limited(Weight::from_parts(80_000_000u64, 100_000u64)) )); @@ -3844,10 +3854,9 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multiassets() { Statemint::execute_with(|| { // Check that Bob received relay tokens back in AssetHub - // (100 - MinXcmFee) assert_eq!( StatemintBalances::free_balance(RELAYBOB), - INITIAL_BALANCE + 50 + INITIAL_BALANCE + 100 ); // Check that BOB received 100 USDC on AssetHub diff --git a/runtime/moonbeam/tests/integration_test.rs b/runtime/moonbeam/tests/integration_test.rs index 37916280a0..ce323946de 100644 --- a/runtime/moonbeam/tests/integration_test.rs +++ b/runtime/moonbeam/tests/integration_test.rs @@ -1644,7 +1644,7 @@ fn root_can_change_default_xcm_vers() { 0, WeightLimit::Unlimited ), - pallet_xcm::Error::::BadVersion + pallet_xcm::Error::::SendFailure ); // Root sets the defaultXcm @@ -1961,7 +1961,7 @@ fn xtokens_precompile_transfer() { weight: 4_000_000, }, ) - .expect_cost(196698) + .expect_cost(22930) .expect_no_logs() .execute_returns(()) }) @@ -2013,7 +2013,7 @@ fn xtokens_precompile_transfer_multiasset() { weight: 4_000_000, }, ) - .expect_cost(196698) + .expect_cost(22930) .expect_no_logs() .execute_returns(()); }) diff --git a/runtime/moonbeam/tests/xcm_tests.rs b/runtime/moonbeam/tests/xcm_tests.rs index 4097f3dfc4..916190d68c 100644 --- a/runtime/moonbeam/tests/xcm_tests.rs +++ b/runtime/moonbeam/tests/xcm_tests.rs @@ -37,7 +37,7 @@ use xcm::{ Location, OriginKind, PalletInstance, Parachain, QueryResponse, Reanchorable, Response, WeightLimit, Xcm, }, - Asset, AssetId, Fungibility, + Asset, AssetId, Assets as XcmAssets, Fungibility, }, IntoVersion, VersionedAssets, VersionedLocation, WrapVersion, }; @@ -2607,13 +2607,17 @@ fn send_statemint_asset_from_para_a_to_statemint_with_relay_fee() { parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), 100, ); - let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 1); + let asset_fee = + currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let assets_to_send: XcmAssets = XcmAssets::from(vec![asset, asset_fee.clone()]); + assert_eq!(assets_to_send.get(0).unwrap(), &asset_fee); + assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), Box::new(VersionedLocation::V4(beneficiary)), - Box::new(VersionedAssets::V4(vec![asset, asset_fee].into())), - 1, + Box::new(VersionedAssets::V4(assets_to_send)), + 0, WeightLimit::Limited(Weight::from_parts(80_000_000u64, 100_000u64)) )); }); @@ -3294,12 +3298,12 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multicurrencies() { // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - let asset_1 = currency_to_asset( - parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), - 100, - ); - let asset_2 = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); - let assets_to_send = vec![asset_1, asset_2]; + let asset_1 = currency_to_asset( + parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), + 100, + ); + let asset_2 = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let assets_to_send = vec![asset_1, asset_2]; assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -3314,10 +3318,9 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multicurrencies() { Statemint::execute_with(|| { // Check that Bob received relay tokens back in AssetHub - // (100 - MinXcmFee) assert_eq!( StatemintBalances::free_balance(RELAYBOB), - INITIAL_BALANCE + 50 + INITIAL_BALANCE + 100 ); // Check that BOB received 100 USDC on AssetHub @@ -3549,7 +3552,8 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multiassets() { fun: Fungible(100), }; - let assets_to_send = vec![statemint_asset_to_send, relay_asset_to_send.clone()]; + let assets_to_send: XcmAssets = + XcmAssets::from(vec![statemint_asset_to_send, relay_asset_to_send.clone()]); let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); // For some reason the order of the assets is inverted when creating the array above. // We need to use relay asset for fees, so we pick index 0. @@ -3561,7 +3565,7 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multiassets() { parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), Box::new(VersionedLocation::V4(beneficiary)), - Box::new(VersionedAssets::V4(assets_to_send.into())), + Box::new(VersionedAssets::V4(assets_to_send)), 0, WeightLimit::Limited(Weight::from_parts(80_000_000u64, 100_000u64)) )); @@ -3571,10 +3575,9 @@ fn send_dot_from_moonbeam_to_statemint_via_xtokens_transfer_multiassets() { Statemint::execute_with(|| { // Check that Bob received relay tokens back in AssetHub - // (100 - MinXcmFee) assert_eq!( StatemintBalances::free_balance(RELAYBOB), - INITIAL_BALANCE + 50 + INITIAL_BALANCE + 100 ); // Check that BOB received 100 USDC on AssetHub diff --git a/runtime/moonriver/tests/integration_test.rs b/runtime/moonriver/tests/integration_test.rs index 9e4c5d3f10..e91b43465e 100644 --- a/runtime/moonriver/tests/integration_test.rs +++ b/runtime/moonriver/tests/integration_test.rs @@ -1632,7 +1632,7 @@ fn root_can_change_default_xcm_vers() { 0, WeightLimit::Limited(4000000000.into()) ), - pallet_xcm::Error::::BadVersion + pallet_xcm::Error::::SendFailure ); // Root sets the defaultXcm @@ -1939,7 +1939,7 @@ fn xtokens_precompiles_transfer() { weight: 4_000_000, }, ) - .expect_cost(196698) + .expect_cost(22930) .expect_no_logs() .execute_returns(()) }) @@ -1991,7 +1991,7 @@ fn xtokens_precompiles_transfer_multiasset() { weight: 4_000_000, }, ) - .expect_cost(196698) + .expect_cost(22930) .expect_no_logs() .execute_returns(()); }) diff --git a/runtime/moonriver/tests/xcm_tests.rs b/runtime/moonriver/tests/xcm_tests.rs index afb00907ee..920f440dda 100644 --- a/runtime/moonriver/tests/xcm_tests.rs +++ b/runtime/moonriver/tests/xcm_tests.rs @@ -27,10 +27,10 @@ use sp_core::ConstU32; use sp_runtime::traits::{Convert, MaybeEquivalence}; use xcm::{ latest::prelude::{ - AccountId32, AccountKey20, All, Asset, AssetId, BuyExecution, ClearOrigin, DepositAsset, - Fungibility, GeneralIndex, Junction, Junctions, Limited, Location, OriginKind, - PalletInstance, Parachain, QueryResponse, Reanchorable, Response, WeightLimit, - WithdrawAsset, Xcm, + AccountId32, AccountKey20, All, Asset, AssetId, Assets as XcmAssets, BuyExecution, + ClearOrigin, DepositAsset, Fungibility, GeneralIndex, Junction, Junctions, Limited, + Location, OriginKind, PalletInstance, Parachain, QueryResponse, Reanchorable, Response, + WeightLimit, WithdrawAsset, Xcm, }, IntoVersion, VersionedAssets, VersionedLocation, WrapVersion, }; @@ -209,7 +209,7 @@ fn send_relay_asset_to_relay() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 123); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 123); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -304,7 +304,7 @@ fn send_relay_asset_to_para_b() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -370,7 +370,7 @@ fn send_para_a_asset_to_para_b() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -452,8 +452,8 @@ fn send_para_a_asset_from_para_b_to_para_c() { }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - ParaB::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + ParaA::execute_with(|| { + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -492,7 +492,7 @@ fn send_para_a_asset_from_para_b_to_para_c() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaB::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -553,7 +553,7 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a() { }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); - ParaB::execute_with(|| { + ParaA::execute_with(|| { let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -655,7 +655,7 @@ fn send_para_a_asset_to_para_b_and_back_to_para_a_with_new_reanchoring() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -875,7 +875,7 @@ fn send_para_a_asset_to_para_b_with_trader() { // In destination chain, we only need 4 weight // We put 10 weight, 6 of which should be refunded and 4 of which should go to treasury ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -950,8 +950,8 @@ fn send_para_a_asset_to_para_b_with_trader_and_fee() { // we use transfer_with_fee ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); - let asset_fee = currency_to_asset(parachain::CurrencyId::SelfReserve, 1); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset_fee = currency_to_asset(parachain::CurrencyId::SelfReserve, 1); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -1118,7 +1118,7 @@ fn transact_through_derivative_multilocation() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1260,7 +1260,7 @@ fn transact_through_derivative_with_custom_fee_weight() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1414,7 +1414,7 @@ fn transact_through_derivative_with_custom_fee_weight_refund() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1579,7 +1579,7 @@ fn transact_through_sovereign() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1834,7 +1834,7 @@ fn transact_through_sovereign_with_custom_fee_weight() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -1986,7 +1986,7 @@ fn transact_through_sovereign_with_custom_fee_weight_refund() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_id), 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -2292,7 +2292,7 @@ fn test_automatic_versioning_on_runtime_upgrade_with_para_b() { }; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); + let asset = currency_to_asset(parachain::CurrencyId::SelfReserve, 100); // free execution, full amount received assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), @@ -3055,7 +3055,7 @@ fn send_dot_from_moonbeam_to_statemine_via_xtokens_transfer() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -3210,8 +3210,8 @@ fn send_dot_from_moonbeam_to_statemine_via_xtokens_transfer_with_fee() { let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); // Finally we test that we are able to send back the DOTs to AssetHub from the ParaA ParaA::execute_with(|| { - let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); - let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 10); + let asset = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 100); + let asset_fee = currency_to_asset(parachain::CurrencyId::ForeignAsset(source_relay_id), 10); assert_ok!(PolkadotXcm::transfer_assets( parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), @@ -3629,7 +3629,7 @@ fn send_dot_from_moonbeam_to_statemine_via_xtokens_transfer_multicurrencies() { // (100 - MinXcmFee) assert_eq!( StatemineBalances::free_balance(RELAYBOB), - INITIAL_BALANCE + 50 + INITIAL_BALANCE + 100 ); // Check that BOB received 100 USDC on AssetHub @@ -3861,8 +3861,9 @@ fn send_dot_from_moonbeam_to_statemine_via_xtokens_transfer_multiassets() { fun: Fungibility::Fungible(100), }; - let assets_to_send = vec![statemine_asset_to_send, relay_asset_to_send.clone()]; let (chain_part, beneficiary) = split_location_into_chain_part_and_beneficiary(dest).unwrap(); + let assets_to_send: XcmAssets = + XcmAssets::from(vec![statemine_asset_to_send, relay_asset_to_send.clone()]); // For some reason the order of the assets is inverted when creating the array above. // We need to use relay asset for fees, so we pick index 0. assert_eq!(assets_to_send.get(0).unwrap(), &relay_asset_to_send); @@ -3873,7 +3874,7 @@ fn send_dot_from_moonbeam_to_statemine_via_xtokens_transfer_multiassets() { parachain::RuntimeOrigin::signed(PARAALICE.into()), Box::new(VersionedLocation::V4(chain_part)), Box::new(VersionedLocation::V4(beneficiary)), - Box::new(VersionedAssets::V4(assets_to_send.into())), + Box::new(VersionedAssets::V4(assets_to_send)), 0, WeightLimit::Limited(Weight::from_parts(80_000_000u64, 100_000u64)) )); @@ -3886,7 +3887,7 @@ fn send_dot_from_moonbeam_to_statemine_via_xtokens_transfer_multiassets() { // (100 - MinXcmFee) assert_eq!( StatemineBalances::free_balance(RELAYBOB), - INITIAL_BALANCE + 50 + INITIAL_BALANCE + 100 ); // Check that BOB received 100 USDC on AssetHub From 53c4a949b8a3d949c3a5524c60c01067c8cdaa07 Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Tue, 8 Oct 2024 09:37:20 +0200 Subject: [PATCH 16/24] fix format --- .../test-maintenance-filter.ts | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter.ts b/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter.ts index 1b9e986f90..256dfc7a20 100644 --- a/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter.ts +++ b/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter.ts @@ -27,7 +27,7 @@ describeSuite({ beforeAll(async () => { await execOpenTechCommitteeProposal( context, - context.polkadotJs().tx.maintenanceMode.enterMaintenanceMode() + context.polkadotJs().tx.maintenanceMode.enterMaintenanceMode(), ); }); @@ -39,8 +39,8 @@ describeSuite({ expect( async () => await context.createBlock( - context.polkadotJs().tx.balances.transferAllowDeath(BALTATHAR_ADDRESS, 1n * GLMR) - ) + context.polkadotJs().tx.balances.transferAllowDeath(BALTATHAR_ADDRESS, 1n * GLMR), + ), ).rejects.toThrowError("1010: Invalid Transaction: Transaction call is not expected"); }, }); @@ -65,13 +65,13 @@ describeSuite({ 10_000_000_000n, "0", null, - [] - ) - ) + [], + ), + ), ); expect(result?.successful).to.be.true; expect(await context.viem().getBalance({ address: randomAccount.address })).to.equal( - 100n * GLMR + 100n * GLMR, ); }, }); @@ -88,8 +88,8 @@ describeSuite({ .polkadotJs() .tx.crowdloanRewards.initializeRewardVec([ [RELAYCHAIN_ARBITRARY_ADDRESS_1, CHARLETH_ADDRESS, 3_000_000n * GLMR], - ]) - ) + ]), + ), ); const initBlock = await context.polkadotJs().query.crowdloanRewards.initRelayBlock(); await context.createBlock( @@ -99,13 +99,13 @@ describeSuite({ context .polkadotJs() .tx.crowdloanRewards.completeInitialization( - initBlock.toBigInt() + ARBITRARY_VESTING_PERIOD - ) - ) + initBlock.toBigInt() + ARBITRARY_VESTING_PERIOD, + ), + ), ); expect( - async () => await context.createBlock(context.polkadotJs().tx.crowdloanRewards.claim()) + async () => await context.createBlock(context.polkadotJs().tx.crowdloanRewards.claim()), ).rejects.toThrowError("1010: Invalid Transaction: Transaction call is not expected"); }, }); @@ -134,14 +134,14 @@ describeSuite({ assetDetails, alith, newAssetId, - ALITH_ADDRESS + ALITH_ADDRESS, ); expect( async () => await context.createBlock( - context.polkadotJs().tx.assets.transfer(newAssetId, BALTATHAR_ADDRESS, 1000) - ) + context.polkadotJs().tx.assets.transfer(newAssetId, BALTATHAR_ADDRESS, 1000), + ), ).rejects.toThrowError("1010: Invalid Transaction: Transaction call is not expected"); }, }); @@ -161,8 +161,8 @@ describeSuite({ V4: { parents: 1n, interior: { - X1: [{ Parachain: 2000n }] - } + X1: [{ Parachain: 2000n }], + }, }, } as any, // Beneficiary @@ -170,33 +170,33 @@ describeSuite({ V4: { parents: 0n, interior: { - X1: [ - { AccountKey20: { network: null, key: hexToU8a(baltathar.address) } }, - ] + X1: [{ AccountKey20: { network: null, key: hexToU8a(baltathar.address) } }], }, }, } as any, // Assets { - V4: [{ - id: { - V4: { - parents: 0n, - interior: { - Here: null, + V4: [ + { + id: { + V4: { + parents: 0n, + interior: { + Here: null, + }, }, - } + }, + fun: { Fungible: 100n * GLMR }, }, - fun: { Fungible: 100n * GLMR }, - }] + ], }, 0, // FeeAssetItem { Limited: { refTime: 8000000000, proofSize: 128 * 1024 }, - } + }, ) - .signAsync(baltathar) - ) + .signAsync(baltathar), + ), ).rejects.toThrowError("1010: Invalid Transaction: Transaction call is not expected"); }, }); @@ -232,10 +232,10 @@ describeSuite({ fee as any, "", transactWeights as any, - false + false, ) - .signAsync(baltathar) - ) + .signAsync(baltathar), + ), ).rejects.toThrowError("1010: Invalid Transaction: Transaction call is not expected"); }, }); From 3693209b7dcb31e7471a68e9c094dc453186f73f Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Tue, 8 Oct 2024 11:02:02 +0200 Subject: [PATCH 17/24] formatting --- .../test-maintenance-filter.ts | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter.ts b/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter.ts index 256dfc7a20..6c76ba2c9a 100644 --- a/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter.ts +++ b/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter.ts @@ -27,7 +27,7 @@ describeSuite({ beforeAll(async () => { await execOpenTechCommitteeProposal( context, - context.polkadotJs().tx.maintenanceMode.enterMaintenanceMode(), + context.polkadotJs().tx.maintenanceMode.enterMaintenanceMode() ); }); @@ -39,8 +39,8 @@ describeSuite({ expect( async () => await context.createBlock( - context.polkadotJs().tx.balances.transferAllowDeath(BALTATHAR_ADDRESS, 1n * GLMR), - ), + context.polkadotJs().tx.balances.transferAllowDeath(BALTATHAR_ADDRESS, 1n * GLMR) + ) ).rejects.toThrowError("1010: Invalid Transaction: Transaction call is not expected"); }, }); @@ -65,13 +65,13 @@ describeSuite({ 10_000_000_000n, "0", null, - [], - ), - ), + [] + ) + ) ); expect(result?.successful).to.be.true; expect(await context.viem().getBalance({ address: randomAccount.address })).to.equal( - 100n * GLMR, + 100n * GLMR ); }, }); @@ -88,8 +88,8 @@ describeSuite({ .polkadotJs() .tx.crowdloanRewards.initializeRewardVec([ [RELAYCHAIN_ARBITRARY_ADDRESS_1, CHARLETH_ADDRESS, 3_000_000n * GLMR], - ]), - ), + ]) + ) ); const initBlock = await context.polkadotJs().query.crowdloanRewards.initRelayBlock(); await context.createBlock( @@ -99,13 +99,13 @@ describeSuite({ context .polkadotJs() .tx.crowdloanRewards.completeInitialization( - initBlock.toBigInt() + ARBITRARY_VESTING_PERIOD, - ), - ), + initBlock.toBigInt() + ARBITRARY_VESTING_PERIOD + ) + ) ); expect( - async () => await context.createBlock(context.polkadotJs().tx.crowdloanRewards.claim()), + async () => await context.createBlock(context.polkadotJs().tx.crowdloanRewards.claim()) ).rejects.toThrowError("1010: Invalid Transaction: Transaction call is not expected"); }, }); @@ -134,14 +134,14 @@ describeSuite({ assetDetails, alith, newAssetId, - ALITH_ADDRESS, + ALITH_ADDRESS ); expect( async () => await context.createBlock( - context.polkadotJs().tx.assets.transfer(newAssetId, BALTATHAR_ADDRESS, 1000), - ), + context.polkadotJs().tx.assets.transfer(newAssetId, BALTATHAR_ADDRESS, 1000) + ) ).rejects.toThrowError("1010: Invalid Transaction: Transaction call is not expected"); }, }); @@ -193,10 +193,10 @@ describeSuite({ 0, // FeeAssetItem { Limited: { refTime: 8000000000, proofSize: 128 * 1024 }, - }, + } ) - .signAsync(baltathar), - ), + .signAsync(baltathar) + ) ).rejects.toThrowError("1010: Invalid Transaction: Transaction call is not expected"); }, }); @@ -232,10 +232,10 @@ describeSuite({ fee as any, "", transactWeights as any, - false, + false ) - .signAsync(baltathar), - ), + .signAsync(baltathar) + ) ).rejects.toThrowError("1010: Invalid Transaction: Transaction call is not expected"); }, }); From ac5af639cd19cbf3a2e827c85d6c8fd54e99711e Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Tue, 8 Oct 2024 13:54:33 +0200 Subject: [PATCH 18/24] fix tracing test --- .../suites/tracing-tests/test-trace-filter.ts | 79 ++++++++++++++----- 1 file changed, 58 insertions(+), 21 deletions(-) diff --git a/test/suites/tracing-tests/test-trace-filter.ts b/test/suites/tracing-tests/test-trace-filter.ts index ca9becdec8..10620b9c36 100644 --- a/test/suites/tracing-tests/test-trace-filter.ts +++ b/test/suites/tracing-tests/test-trace-filter.ts @@ -258,31 +258,68 @@ describeSuite({ id: "T10", title: "should only trace transactions included in a block", test: async function () { - context - .polkadotJs() - .tx.xTokens.transfer( - { - Erc20: { - contractAddress: "0x931715fee2d06333043d11f658c8ce934ac61d0c", - }, - }, //enum - 100n * GLMR, + const metadata = await context.polkadotJs().rpc.state.getMetadata(); + const erc20XcmBridgePalletIndex = metadata.asLatest.pallets + .find(({ name }) => name.toString() == "Erc20XcmBridge")!.index.toNumber(); + + const dest = { + V3: { + parents: 1, + interior: { + X1: { Parachain: 2104n }, + }, + }, + }; + + const beneficiary = { + V3: { + parents: 0n, + interior: { + X1: [ + { + AccountId32: { + network: "Any", + id: "0x608a07e4dfc71e7d99a3d3759ce12ccbb1e4d9f917cc67779c13aaeaea52794d", + }, + }, + ], + }, + }, + }; + + const assetsToSend = { + V3: [ { - V2: { - parents: 1n, - interior: { - X2: [ - { Parachain: 2104n }, - { - AccountId32: { - network: "Any", - id: "0x608a07e4dfc71e7d99a3d3759ce12ccbb1e4d9f917cc67779c13aaeaea52794d", + id: { + Concrete: { + parents: 0, + interior: { + X2: [ + { PalletInstance: Number(erc20XcmBridgePalletIndex) }, + { + AccountId20: { + network: "Any", + id: "0x931715fee2d06333043d11f658c8ce934ac61d0c", + }, }, - }, - ], + ], + }, }, }, - } as any, + fun: { + Fungible: 100n * GLMR, + }, + }, + ] + }; + + context + .polkadotJs() + .tx.polkadotXcm.transferAssets( + dest, + beneficiary, + assetsToSend, + 0, // feeAssetId { Limited: { refTime: 4000000000, proofSize: 0 }, } From d577ff94ae6f4096fbc4ed3f24b3ad5ac393176f Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Tue, 8 Oct 2024 13:57:30 +0200 Subject: [PATCH 19/24] fix format --- test/suites/tracing-tests/test-trace-filter.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/suites/tracing-tests/test-trace-filter.ts b/test/suites/tracing-tests/test-trace-filter.ts index 10620b9c36..0c8b4ace45 100644 --- a/test/suites/tracing-tests/test-trace-filter.ts +++ b/test/suites/tracing-tests/test-trace-filter.ts @@ -260,7 +260,8 @@ describeSuite({ test: async function () { const metadata = await context.polkadotJs().rpc.state.getMetadata(); const erc20XcmBridgePalletIndex = metadata.asLatest.pallets - .find(({ name }) => name.toString() == "Erc20XcmBridge")!.index.toNumber(); + .find(({ name }) => name.toString() == "Erc20XcmBridge")! + .index.toNumber(); const dest = { V3: { @@ -310,7 +311,7 @@ describeSuite({ Fungible: 100n * GLMR, }, }, - ] + ], }; context From f2305df7c5dcb554374aa83ed93ad69af8c9d15b Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Tue, 8 Oct 2024 14:44:40 +0200 Subject: [PATCH 20/24] fix tracing --- test/suites/tracing-tests/test-trace-filter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/suites/tracing-tests/test-trace-filter.ts b/test/suites/tracing-tests/test-trace-filter.ts index 0c8b4ace45..09fabdef7f 100644 --- a/test/suites/tracing-tests/test-trace-filter.ts +++ b/test/suites/tracing-tests/test-trace-filter.ts @@ -298,7 +298,7 @@ describeSuite({ X2: [ { PalletInstance: Number(erc20XcmBridgePalletIndex) }, { - AccountId20: { + AccountKey20: { network: "Any", id: "0x931715fee2d06333043d11f658c8ce934ac61d0c", }, From 38f93545c32d53e2cd352f0f1fc43f2f7971670b Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Tue, 8 Oct 2024 15:03:03 +0200 Subject: [PATCH 21/24] enable call of transfer_assets --- runtime/moonbeam/src/lib.rs | 1 + runtime/moonriver/src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 6afd818f40..2789c17486 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -1202,6 +1202,7 @@ impl Contains for NormalFilter { // is populated at genesis RuntimeCall::PolkadotXcm(method) => match method { pallet_xcm::Call::force_default_xcm_version { .. } => true, + pallet_xcm::Call::transfer_assets { .. } => true, _ => false, }, // We filter anonymous proxy as they make "reserve" inconsistent diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 1469eef039..18643fc7db 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -1206,6 +1206,7 @@ impl Contains for NormalFilter { // is populated at genesis RuntimeCall::PolkadotXcm(method) => match method { pallet_xcm::Call::force_default_xcm_version { .. } => true, + pallet_xcm::Call::transfer_assets { .. } => true, _ => false, }, // We filter anonymous proxy as they make "reserve" inconsistent From 6da2e9a6e38688319363d0cc82634bab6c0f5c0b Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Wed, 9 Oct 2024 10:54:13 +0200 Subject: [PATCH 22/24] fix tracing test --- .../suites/tracing-tests/test-trace-filter.ts | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/test/suites/tracing-tests/test-trace-filter.ts b/test/suites/tracing-tests/test-trace-filter.ts index 09fabdef7f..65f4686b38 100644 --- a/test/suites/tracing-tests/test-trace-filter.ts +++ b/test/suites/tracing-tests/test-trace-filter.ts @@ -1,5 +1,6 @@ import { beforeAll, customDevRpcRequest, describeSuite, expect } from "@moonwall/cli"; import { ALITH_ADDRESS, ALITH_CONTRACT_ADDRESSES, GLMR, alith } from "@moonwall/util"; +import { hexToU8a } from "@polkadot/util"; describeSuite({ id: "T14", @@ -264,43 +265,54 @@ describeSuite({ .index.toNumber(); const dest = { - V3: { - parents: 1, + V4: { + parents: 1n, interior: { - X1: { Parachain: 2104n }, + X1: [{ Parachain: 2104n }], }, }, - }; + } as any; const beneficiary = { - V3: { + V4: { parents: 0n, interior: { X1: [ { AccountId32: { - network: "Any", + network: null, id: "0x608a07e4dfc71e7d99a3d3759ce12ccbb1e4d9f917cc67779c13aaeaea52794d", }, }, ], }, }, - }; + } as any; const assetsToSend = { - V3: [ + V4: [ + { + id: { + V4: { + parents: 0n, + interior: { + Here: null, + }, + }, + }, + fun: { Fungible: 100n * GLMR }, + }, { id: { - Concrete: { - parents: 0, + V4: { + parents: 0n, interior: { X2: [ { PalletInstance: Number(erc20XcmBridgePalletIndex) }, { AccountKey20: { - network: "Any", - id: "0x931715fee2d06333043d11f658c8ce934ac61d0c", + network: null, + key: hexToU8a("0x931715fee2d06333043d11f658c8ce934ac61d0c"), }, }, ], From ff4d811dfc67351b39a0177bdc2aea4ecf6fb92f Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com> Date: Wed, 9 Oct 2024 17:37:09 +0200 Subject: [PATCH 23/24] remove unused code Co-authored-by: Rodrigo Quelhas <22591718+RomarQ@users.noreply.github.com> --- precompiles/xtokens/src/lib.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/precompiles/xtokens/src/lib.rs b/precompiles/xtokens/src/lib.rs index 687f5572f3..65c9c06577 100644 --- a/precompiles/xtokens/src/lib.rs +++ b/precompiles/xtokens/src/lib.rs @@ -244,9 +244,6 @@ where let amount = amount .try_into() .map_err(|_| RevertReason::value_is_too_large("balance type").in_field("amount"))?; - /*let _fee = fee - .try_into() - .map_err(|_| RevertReason::value_is_too_large("balance type").in_field("fee"))?;*/ let dest_weight_limit = if weight == u64::MAX { WeightLimit::Unlimited From 2aa407e1198cd7c20c64a41aab7ffc198401b0fb Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Thu, 10 Oct 2024 09:47:15 +0200 Subject: [PATCH 24/24] improvements --- precompiles/xtokens/src/lib.rs | 8 +- .../moonbase/tests/xcm_mock/statemint_like.rs | 19 +-- .../test-precompile-xtokens.ts | 109 ------------------ 3 files changed, 4 insertions(+), 132 deletions(-) diff --git a/precompiles/xtokens/src/lib.rs b/precompiles/xtokens/src/lib.rs index 65c9c06577..5fc36c70e6 100644 --- a/precompiles/xtokens/src/lib.rs +++ b/precompiles/xtokens/src/lib.rs @@ -116,6 +116,9 @@ where Ok(()) } + // transfer_with_fee no longer take the fee parameter into account since we start using + // pallet-xcm. Now, if you want to limit the maximum amount of fees, you'll have to use a + // different asset from the one you wish to transfer and use transfer_multi* selectors. #[precompile::public("transferWithFee(address,uint256,uint256,(uint8,bytes[]),uint64)")] #[precompile::public("transfer_with_fee(address,uint256,uint256,(uint8,bytes[]),uint64)")] fn transfer_with_fee( @@ -142,11 +145,6 @@ where .try_into() .map_err(|_| RevertReason::value_is_too_large("balance type").in_field("amount"))?; - // Fee amount - /*let _fee = fee - .try_into() - .map_err(|_| RevertReason::value_is_too_large("balance type").in_field("fee"))?;*/ - let dest_weight_limit = if weight == u64::MAX { WeightLimit::Unlimited } else { diff --git a/runtime/moonbase/tests/xcm_mock/statemint_like.rs b/runtime/moonbase/tests/xcm_mock/statemint_like.rs index 8344560123..53f39b2a77 100644 --- a/runtime/moonbase/tests/xcm_mock/statemint_like.rs +++ b/runtime/moonbase/tests/xcm_mock/statemint_like.rs @@ -315,30 +315,13 @@ impl> ContainsPair pub type TrustedTeleporters = (ConcreteAssetFromRelay,); -/// Trust reserves from sibling parachains, relay chain, and here -pub struct TrustedReserves; -impl ContainsPair for TrustedReserves { - fn contains(asset: &Asset, origin: &Location) -> bool { - let AssetId(location) = &asset.id; - match (&asset.id.0.parent_count(), &asset.id.0.first_interior()) { - // Sibling parachains - (1, Some(Junction::Parachain(_id))) => location.chain_location() == *origin, - // Relay chain - (1, _) => location.chain_location() == *origin, - // Here - (0, _) => Location::here() == *origin, - _ => false, - } - } -} - pub struct XcmConfig; impl Config for XcmConfig { type RuntimeCall = RuntimeCall; type XcmSender = XcmRouter; type AssetTransactor = AssetTransactors; type OriginConverter = XcmOriginToTransactDispatchOrigin; - type IsReserve = TrustedReserves; + type IsReserve = xcm_primitives::MultiNativeAsset; type IsTeleporter = TrustedTeleporters; type UniversalLocation = UniversalLocation; type Barrier = Barrier; diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-xtokens.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-xtokens.ts index 9cf563a8c5..db14721c5d 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-xtokens.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-xtokens.ts @@ -61,53 +61,6 @@ describeSuite({ }, }); - // transferWithFee behave the same as transfer now - /*it({ - id: "T02", - title: "allows to issue transfer xtokens with fee", - test: async function () { - const destination_enum_selector = "0x01"; - // [0x01; 32] - const destination_address = - "0101010101010101010101010101010101010101010101010101010101010101"; - // NetworkId::Any - const destination_network_id = "00"; - - // This represents X2(Parent, AccountId32([0x01; 32])) - // We will transfer the tokens the former account in the relay chain - // However it does not really matter as we are not testing what happens - // in the relay side of things - const destination = [ - 1, - // junction: AccountId32 enum (01) + the 32 byte account + Any network selector(00) - [destination_enum_selector + destination_address + destination_network_id], - ]; - const amountTransferred = 1000n; - const fee = 100n; - const weight = 100n; - const balBefore = await context.viem().getBalance({ address: ALITH_ADDRESS }); - const rawTxn = await context.writePrecompile!({ - precompileName: "Xtokens", - functionName: "transferWithFee", - args: [PRECOMPILES.NativeErc20[0], amountTransferred, fee, destination, weight], - rawTxOnly: true, - gas: 500_000n, - }); - - const { result } = await context.createBlock(rawTxn); - const balAfter = await context.viem().getBalance({ address: ALITH_ADDRESS }); - const receipt = await context - .viem() - .getTransactionReceipt({ hash: result!.hash as `0x${string}` }); - expectEVMResult(result!.events, "Succeed"); - const gasPrice = receipt.effectiveGasPrice; - const fees = receipt.gasUsed * gasPrice; - - expect(balBefore - balAfter).to.equal(amountTransferred + fee + fees); - await verifyLatestBlockFees(context, amountTransferred + fee); - }, - });*/ - it({ id: "T03", title: "allows to issue transfer_multiasset xtokens", @@ -168,68 +121,6 @@ describeSuite({ }, }); - // transferMultiassetWithFee behacve the same as transferMultiasset now - /*it({ - id: "T04", - title: "allows to issue transfer_multiasset xtokens with fee", - test: async function () { - const destination_enum_selector = "0x01"; - // [0x01; 32] - const destination_address = - "0101010101010101010101010101010101010101010101010101010101010101"; - // NetworkId::Any - const destination_network_id = "00"; - - const x2_pallet_instance_enum_selector = "0x04"; - const x2_instance = "03"; - - // This represents X1(PalletInstance(3))) - // This multilocation represents our native token - const asset = [ - // one parent - 0, - // X1(PalletInstance) - // PalletInstance: Selector (04) + palconst instance 1 byte (03) - [x2_pallet_instance_enum_selector + x2_instance], - ]; - // This represents X2(Parent, AccountId32([0x01; 32])) - // We will transfer the tokens the former account in the relay chain - // However it does not really matter as we are not testing what happens - // in the relay side of things - const destination = [ - 1, - // junction: AccountId32 enum (01) + the 32 byte account + Any network selector(00) - [destination_enum_selector + destination_address + destination_network_id], - ]; - const amountTransferred = 1000n; - - const fee = 100n; - const weight = 100; - - const balBefore = await context.viem().getBalance({ address: ALITH_ADDRESS }); - const rawTxn = await context.writePrecompile!({ - precompileName: "Xtokens", - functionName: "transferMultiassetWithFee", - args: [asset, amountTransferred, fee, destination, weight], - gas: 1_200_000n, - rawTxOnly: true, - }); - - const { result } = await context.createBlock(rawTxn); - const balAfter = await context.viem().getBalance({ address: ALITH_ADDRESS }); - const receipt = await context - .viem() - .getTransactionReceipt({ hash: result!.hash as `0x${string}` }); - expectEVMResult(result!.events, "Succeed"); - - const gasPrice = receipt.effectiveGasPrice; - const fees = receipt.gasUsed * gasPrice; - - expect(balBefore - balAfter).to.equal(amountTransferred + fee + fees); - await verifyLatestBlockFees(context, amountTransferred + fee); - }, - });*/ - it({ id: "T05", title: "allows to issue transfer multicurrencies xtokens",