diff --git a/Cargo.lock b/Cargo.lock index 6467f1c0ade73..df341a82854d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14605,7 +14605,7 @@ dependencies = [ "frame-try-runtime", "hex-literal", "pallet-asset-conversion", - "pallet-asset-tx-payment", + "pallet-asset-conversion-tx-payment", "pallet-assets", "pallet-aura", "pallet-authorship", diff --git a/cumulus/parachains/common/src/impls.rs b/cumulus/parachains/common/src/impls.rs index 00cb9be261c1e..4d81c3978d81a 100644 --- a/cumulus/parachains/common/src/impls.rs +++ b/cumulus/parachains/common/src/impls.rs @@ -20,7 +20,7 @@ use alloc::boxed::Box; use core::marker::PhantomData; use frame_support::traits::{ fungible, fungibles, tokens::imbalance::ResolveTo, Contains, ContainsPair, Currency, Defensive, - Get, Imbalance, OnUnbalanced, OriginTrait, + Get, Imbalance, OnUnbalanced, OriginTrait, TypedGet, }; use pallet_asset_tx_payment::HandleCredit; use pallet_collator_selection::StakingPotAccountId; @@ -83,7 +83,12 @@ where /// A `HandleCredit` implementation that naively transfers the fees to the block author. /// Will drop and burn the assets in case the transfer fails. +#[deprecated( + note = "AssetsToBlockAuthor is deprecated and will be removed after June 2026. Please use frame_support::traits::tokens::imbalance::MaybeResolveTo instead." +)] pub struct AssetsToBlockAuthor(PhantomData<(R, I)>); + +#[allow(deprecated)] impl HandleCredit, pallet_assets::Pallet> for AssetsToBlockAuthor where I: 'static, @@ -99,6 +104,22 @@ where } } +/// Implements `TypedGet` with an option return value to pass into +/// frame_support::traits::tokens::imbalance::MaybeResolveTo. +pub struct BlockAuthor(PhantomData); + +impl TypedGet for BlockAuthor +where + R: pallet_authorship::Config, + AccountIdOf: From + Into, +{ + type Type = Option>; + + fn get() -> Self::Type { + pallet_authorship::Pallet::::author() + } +} + /// Allow checking in assets that have issuance > 0. pub struct NonZeroIssuance(PhantomData<(AccountId, Assets)>); impl Contains<>::AssetId> diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/genesis.rs index bb29d3b63eb69..5e5f3ccc4db15 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/genesis.rs @@ -23,8 +23,8 @@ use emulated_integration_tests_common::{ accounts, build_genesis_storage, collators, snowbridge::{ETHER_MIN_BALANCE, WETH}, xcm_emulator::ConvertLocation, - PenpalALocation, PenpalASiblingSovereignAccount, PenpalATeleportableAssetLocation, - PenpalBLocation, PenpalBSiblingSovereignAccount, PenpalBTeleportableAssetLocation, + PenpalALocation, PenpalAPen2TeleportableAssetLocation, PenpalASiblingSovereignAccount, + PenpalBLocation, PenpalBPen2TeleportableAssetLocation, PenpalBSiblingSovereignAccount, RESERVABLE_ASSET_ID, SAFE_XCM_VERSION, USDT_ID, }; use parachains_common::{AccountId, Balance}; @@ -99,16 +99,19 @@ pub fn genesis() -> Storage { }, foreign_assets: asset_hub_rococo_runtime::ForeignAssetsConfig { assets: vec![ - // PenpalA's teleportable asset representation + // // PenpalA's native asset representation + (PenpalALocation::get(), PenpalASiblingSovereignAccount::get(), true, ED), + // // PenpalB's native asset representation + (PenpalBLocation::get(), PenpalBSiblingSovereignAccount::get(), true, ED), ( - PenpalATeleportableAssetLocation::get(), + PenpalAPen2TeleportableAssetLocation::get(), PenpalASiblingSovereignAccount::get(), false, ED, ), // PenpalB's teleportable asset representation ( - PenpalBTeleportableAssetLocation::get(), + PenpalBPen2TeleportableAssetLocation::get(), PenpalBSiblingSovereignAccount::get(), false, ED, @@ -116,9 +119,8 @@ pub fn genesis() -> Storage { // Ether ( EthereumLocation::get(), - AssetHubWestendSovereignAccount::get(), /* To emulate double bridging, where - * WAH is the owner of assets from - * Ethereum on RAH */ + // Emulate double bridging; WAH is the owner of assets from Ethereum on RAH. + AssetHubWestendSovereignAccount::get(), true, ETHER_MIN_BALANCE, ), @@ -137,12 +139,14 @@ pub fn genesis() -> Storage { ), ], reserves: vec![ + (PenpalALocation::get(), vec![(PenpalALocation::get(), true).into()]), + (PenpalBLocation::get(), vec![(PenpalBLocation::get(), true).into()]), ( - PenpalATeleportableAssetLocation::get(), + PenpalAPen2TeleportableAssetLocation::get(), vec![(PenpalALocation::get(), true).into()], ), ( - PenpalBTeleportableAssetLocation::get(), + PenpalBPen2TeleportableAssetLocation::get(), vec![(PenpalBLocation::get(), true).into()], ), (EthereumLocation::get(), vec![(AssetHubWestendLocation::get(), false).into()]), diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/genesis.rs index 8e436f40d122b..9abda5581df56 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/genesis.rs @@ -23,8 +23,8 @@ use emulated_integration_tests_common::{ accounts, build_genesis_storage, collators, snowbridge::{ETHER_MIN_BALANCE, WETH}, xcm_emulator::ConvertLocation, - PenpalALocation, PenpalASiblingSovereignAccount, PenpalATeleportableAssetLocation, - PenpalBLocation, PenpalBSiblingSovereignAccount, PenpalBTeleportableAssetLocation, + PenpalALocation, PenpalAPen2TeleportableAssetLocation, PenpalASiblingSovereignAccount, + PenpalBLocation, PenpalBPen2TeleportableAssetLocation, PenpalBSiblingSovereignAccount, RESERVABLE_ASSET_ID, SAFE_XCM_VERSION, USDT_ID, }; use parachains_common::{AccountId, Balance}; @@ -99,16 +99,19 @@ pub fn genesis() -> Storage { }, foreign_assets: asset_hub_westend_runtime::ForeignAssetsConfig { assets: vec![ + // // Penpals' native asset representation + (PenpalALocation::get(), PenpalASiblingSovereignAccount::get(), true, ED), + (PenpalBLocation::get(), PenpalBSiblingSovereignAccount::get(), true, ED), // PenpalA's teleportable asset representation ( - PenpalATeleportableAssetLocation::get(), + PenpalAPen2TeleportableAssetLocation::get(), PenpalASiblingSovereignAccount::get(), false, ED, ), // PenpalB's teleportable asset representation ( - PenpalBTeleportableAssetLocation::get(), + PenpalBPen2TeleportableAssetLocation::get(), PenpalBSiblingSovereignAccount::get(), false, ED, @@ -135,12 +138,14 @@ pub fn genesis() -> Storage { ), ], reserves: vec![ + (PenpalALocation::get(), vec![(PenpalALocation::get(), true).into()]), + (PenpalBLocation::get(), vec![(PenpalBLocation::get(), true).into()]), ( - PenpalATeleportableAssetLocation::get(), + PenpalAPen2TeleportableAssetLocation::get(), vec![(PenpalALocation::get(), true).into()], ), ( - PenpalBTeleportableAssetLocation::get(), + PenpalBPen2TeleportableAssetLocation::get(), vec![(PenpalBLocation::get(), true).into()], ), (EthereumLocation::get(), vec![(EthereumLocation::get(), false).into()]), diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs index e514d0cb74773..2c54fc50173b2 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs @@ -23,7 +23,9 @@ use emulated_integration_tests_common::{ accounts, build_genesis_storage, collators, SAFE_XCM_VERSION, }; use parachains_common::{AccountId, Balance}; -use penpal_runtime::xcm_config::{LocalReservableFromAssetHub, RelayLocation, UsdtFromAssetHub}; +use penpal_runtime::xcm_config::{ + LocalPen2Asset, LocalReservableFromAssetHub, RelayLocation, UsdtFromAssetHub, +}; // Penpal pub const PARA_ID_A: u32 = 2000; pub const PARA_ID_B: u32 = 2001; @@ -70,18 +72,11 @@ pub fn genesis(para_id: u32) -> Storage { }, sudo: penpal_runtime::SudoConfig { key: Some(PenpalSudoAccount::get()) }, assets: penpal_runtime::AssetsConfig { - assets: vec![( - penpal_runtime::xcm_config::TELEPORTABLE_ASSET_ID, - PenpalAssetOwner::get(), - false, - ED, - )], - ..Default::default() - }, - foreign_assets: penpal_runtime::ForeignAssetsConfig { assets: vec![ // Relay Native asset representation (RelayLocation::get(), PenpalAssetOwner::get(), true, ED), + // Local Pen2 representation + (LocalPen2Asset::get(), PenpalAssetOwner::get(), false, ED), // Sufficient AssetHub asset representation (LocalReservableFromAssetHub::get(), PenpalAssetOwner::get(), true, ED), // USDT from AssetHub diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs index d5a9f1b718990..74daec091f153 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs @@ -27,8 +27,7 @@ use sp_core::Encode; // Cumulus use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain, - impl_xcm_helpers_for_parachain, + impl_foreign_assets_helpers_for_parachain, impl_xcm_helpers_for_parachain, impls::{NetworkId, Parachain}, xcm_emulator::decl_test_parachains, AuraDigestProvider, @@ -59,7 +58,6 @@ decl_test_parachains! { pallets = { PolkadotXcm: penpal_runtime::PolkadotXcm, Assets: penpal_runtime::Assets, - ForeignAssets: penpal_runtime::ForeignAssets, AssetConversion: penpal_runtime::AssetConversion, Balances: penpal_runtime::Balances, } @@ -84,7 +82,6 @@ decl_test_parachains! { pallets = { PolkadotXcm: penpal_runtime::PolkadotXcm, Assets: penpal_runtime::Assets, - ForeignAssets: penpal_runtime::ForeignAssets, AssetConversion: penpal_runtime::AssetConversion, Balances: penpal_runtime::Balances, } @@ -96,9 +93,17 @@ impl_accounts_helpers_for_parachain!(PenpalA); impl_accounts_helpers_for_parachain!(PenpalB); impl_assert_events_helpers_for_parachain!(PenpalA); impl_assert_events_helpers_for_parachain!(PenpalB); -impl_assets_helpers_for_parachain!(PenpalA); -impl_foreign_assets_helpers_for_parachain!(PenpalA, xcm::latest::Location, ForeignAssetReserveData); -impl_assets_helpers_for_parachain!(PenpalB); -impl_foreign_assets_helpers_for_parachain!(PenpalB, xcm::latest::Location, ForeignAssetReserveData); +impl_foreign_assets_helpers_for_parachain!( + PenpalA, + xcm::latest::Location, + ForeignAssetReserveData, + Assets +); +impl_foreign_assets_helpers_for_parachain!( + PenpalB, + xcm::latest::Location, + ForeignAssetReserveData, + Assets +); impl_xcm_helpers_for_parachain!(PenpalA); impl_xcm_helpers_for_parachain!(PenpalB); diff --git a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs index 273580096e21a..2ff27b233116a 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs @@ -802,7 +802,18 @@ macro_rules! impl_assets_helpers_for_parachain { #[macro_export] macro_rules! impl_foreign_assets_helpers_for_parachain { + // By default, we assume that the pallet_assets instance handling foreign assets is called + // `ForeignAssets`. There are exceptions like `Penpal`, where it is simply called `Assets`. ($chain:ident, $asset_id_type:ty, $reserve_data_type:ty) => { + $crate::impl_foreign_assets_helpers_for_parachain!( + $chain, + $asset_id_type, + $reserve_data_type, + ForeignAssets + ); + }; + + ($chain:ident, $asset_id_type:ty, $reserve_data_type:ty, $pallet_asset_name:ident) => { $crate::impls::paste::paste! { impl $chain { /// Create foreign assets using sudo `ForeignAssets::force_create()` @@ -817,7 +828,7 @@ macro_rules! impl_foreign_assets_helpers_for_parachain { let sudo_origin = <$chain as $crate::impls::Chain>::RuntimeOrigin::root(); ::execute_with(|| { $crate::impls::assert_ok!( - ]>::ForeignAssets::force_create( + ]>::$pallet_asset_name::force_create( sudo_origin, id.clone(), owner.clone().into(), @@ -825,12 +836,12 @@ macro_rules! impl_foreign_assets_helpers_for_parachain { min_balance, ) ); - assert!(]>::ForeignAssets::asset_exists(id.clone())); + assert!(]>::$pallet_asset_name::asset_exists(id.clone())); type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent; $crate::impls::assert_expected_events!( Self, vec![ - RuntimeEvent::::ForeignAssets( + RuntimeEvent::::$pallet_asset_name( $crate::impls::pallet_assets::Event::ForceCreated { asset_id, .. @@ -857,7 +868,7 @@ macro_rules! impl_foreign_assets_helpers_for_parachain { <$chain as $crate::impls::Chain>::RuntimeOrigin::signed(owner.clone()); ::execute_with(|| { $crate::impls::assert_ok!( - ]>::ForeignAssets::set_reserves( + ]>::$pallet_asset_name::set_reserves( owner_origin, id.clone(), reserves.try_into().unwrap(), @@ -874,7 +885,7 @@ macro_rules! impl_foreign_assets_helpers_for_parachain { amount_to_mint: u128, ) { ::execute_with(|| { - $crate::impls::assert_ok!(]>::ForeignAssets::mint( + $crate::impls::assert_ok!(]>::$pallet_asset_name::mint( signed_origin, id.clone().into(), beneficiary.clone().into(), @@ -886,7 +897,7 @@ macro_rules! impl_foreign_assets_helpers_for_parachain { $crate::impls::assert_expected_events!( Self, vec![ - RuntimeEvent::::ForeignAssets( + RuntimeEvent::::$pallet_asset_name( $crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount } ) => { asset_id: *asset_id == id, @@ -906,7 +917,7 @@ macro_rules! impl_foreign_assets_helpers_for_parachain { ) -> $crate::impls::DoubleEncoded<()> { use $crate::impls::{Chain, Encode}; - ::RuntimeCall::ForeignAssets($crate::impls::pallet_assets::Call::< + ::RuntimeCall::$pallet_asset_name($crate::impls::pallet_assets::Call::< ::Runtime, $crate::impls::pallet_assets::Instance2, >::create { diff --git a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs index 141853dce1e88..2b3bcef582537 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs @@ -15,6 +15,7 @@ pub mod impls; pub mod macros; +pub mod pools; pub mod xcm_helpers; use codec::Encode; @@ -41,6 +42,7 @@ use polkadot_runtime_parachains::configuration::HostConfiguration; use parachains_common::{AccountId, AuraId}; use polkadot_primitives::{AssignmentId, ValidatorId}; use sp_runtime::traits::Convert; +use xcm::v5::{Junction, Location}; use xcm_emulator::{RelayBlockNumber, AURA_ENGINE_ID}; pub const XCM_V2: u32 = 2; @@ -56,7 +58,7 @@ pub const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; // (trust-backed) Asset registered on AH and reserve-transferred between Parachain and AH pub const RESERVABLE_ASSET_ID: u32 = 1; // ForeignAsset registered on AH and teleported between Penpal and AH -pub const TELEPORTABLE_ASSET_ID: u32 = 2; +pub const PEN2_TELEPORTABLE_ASSET_ID: u32 = 2; // USDT registered on AH as (trust-backed) Asset and reserve-transferred between Parachain and AH pub const USDT_ID: u32 = 1984; @@ -66,6 +68,7 @@ pub const PENPAL_B_ID: u32 = 2001; pub const ASSET_HUB_ROCOCO_ID: u32 = 1000; pub const ASSET_HUB_WESTEND_ID: u32 = 1000; pub const ASSETS_PALLET_ID: u8 = 50; +pub const PENPAL_ASSETS_PALLET_ID: u8 = 50; pub struct AuraDigestProvider {} @@ -79,28 +82,33 @@ impl Convert<(BlockNumber, RelayBlockNumber), Digest> for AuraDigestProvider { } parameter_types! { - pub PenpalALocation: xcm::v5::Location - = xcm::v5::Location::new(1, [xcm::v5::Junction::Parachain(PENPAL_A_ID)]); - pub PenpalBLocation: xcm::v5::Location - = xcm::v5::Location::new(1, [xcm::v5::Junction::Parachain(PENPAL_B_ID)]); - pub PenpalATeleportableAssetLocation: xcm::v5::Location - = xcm::v5::Location::new(1, [ - xcm::v5::Junction::Parachain(PENPAL_A_ID), - xcm::v5::Junction::PalletInstance(ASSETS_PALLET_ID), - xcm::v5::Junction::GeneralIndex(TELEPORTABLE_ASSET_ID.into()), + pub PenpalALocation: Location = Location::new(1, [Junction::Parachain(PENPAL_A_ID)]); + pub PenpalBLocation: Location = Location::new(1, [Junction::Parachain(PENPAL_B_ID)]); + pub PenpalAPen2TeleportableAssetLocation: Location + = Location::new(1, [ + Junction::Parachain(PENPAL_A_ID), + Junction::PalletInstance(PENPAL_ASSETS_PALLET_ID), + Junction::GeneralIndex(PEN2_TELEPORTABLE_ASSET_ID.into()), ] ); - pub PenpalBTeleportableAssetLocation: xcm::v5::Location - = xcm::v5::Location::new(1, [ - xcm::v5::Junction::Parachain(PENPAL_B_ID), - xcm::v5::Junction::PalletInstance(ASSETS_PALLET_ID), - xcm::v5::Junction::GeneralIndex(TELEPORTABLE_ASSET_ID.into()), + pub PenpalBPen2TeleportableAssetLocation: Location + = Location::new(1, [ + Junction::Parachain(PENPAL_B_ID), + Junction::PalletInstance(PENPAL_ASSETS_PALLET_ID), + Junction::GeneralIndex(PEN2_TELEPORTABLE_ASSET_ID.into()), ] ); pub PenpalASiblingSovereignAccount: AccountId = Sibling::from(PENPAL_A_ID).into_account_truncating(); pub PenpalBSiblingSovereignAccount: AccountId = Sibling::from(PENPAL_B_ID).into_account_truncating(); } +pub fn local_penpal_asset(id: u32) -> Location { + Location::new( + 0, + [Junction::PalletInstance(PENPAL_ASSETS_PALLET_ID), Junction::GeneralIndex(id.into())], + ) +} + pub fn get_host_config() -> HostConfiguration { HostConfiguration { max_upward_queue_count: 10, diff --git a/cumulus/parachains/integration-tests/emulated/common/src/macros.rs b/cumulus/parachains/integration-tests/emulated/common/src/macros.rs index 9d0e595c47a3c..2dce9b1a6dae2 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/macros.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/macros.rs @@ -61,7 +61,7 @@ pub use xcm_runtime_apis::{ pub use frame_support::traits::{fungible::Mutate, fungibles::Inspect, Currency}; pub use sp_runtime::{traits::Dispatchable, AccountId32}; -pub use crate::{ASSETS_PALLET_ID, USDT_ID}; +pub use crate::{create_foreign_pool_with_native_on, ASSETS_PALLET_ID, USDT_ID}; #[macro_export] macro_rules! test_parachain_is_trusted_teleporter { @@ -670,6 +670,10 @@ macro_rules! test_can_estimate_and_pay_exact_fees { $amount * 2, ); + // Create pools to pay with `$asset_id` + create_foreign_pool_with_native_on!($sender_para, Location::from($asset_id), asset_owner.clone()); + create_foreign_pool_with_native_on!($receiver_para, Location::from($asset_id), asset_owner.clone()); + // Fund the parachain origin's SA on Asset Hub with the native tokens. // TODO: consider fund_accounts to be part of xcm_emulator::Chain trait $asset_hub::fund_accounts(vec![(sov_of_sender_on_ah.clone(), $amount * 2)]); @@ -782,19 +786,6 @@ macro_rules! test_can_estimate_and_pay_exact_fees { intermediate_delivery_fees = $crate::xcm_helpers::get_amount_from_versioned_assets(delivery_fees); }); - // Get the final execution fees in the destination. - let mut final_execution_fees = 0; - <$receiver_para as $crate::macros::TestExt>::execute_with(|| { - type Runtime = <$sender_para as $crate::macros::Chain>::Runtime; - - let weight = >::query_xcm_weight( - intermediate_remote_message.clone()).unwrap(); - final_execution_fees = - >::query_weight_to_asset_fee(weight, - $crate::macros::VersionedAssetId::from($crate::macros::AssetId($crate::macros::Location::parent()))) - .unwrap(); - }); - // Dry-running is done. <$sender_para as $crate::macros::TestExt>::reset_ext(); <$asset_hub as $crate::macros::TestExt>::reset_ext(); @@ -802,21 +793,44 @@ macro_rules! test_can_estimate_and_pay_exact_fees { // Fund accounts again. $sender_para::mint_foreign_asset( - <$sender_para as $crate::macros::Chain>::RuntimeOrigin::signed(asset_owner), + <$sender_para as $crate::macros::Chain>::RuntimeOrigin::signed(asset_owner.clone()), $asset_id.clone().into(), sender.clone(), $amount * 2, ); + $sender_para::fund_accounts(vec![(sender.clone(), $amount * 2)]); + + // Create pools to pay with `$asset_id` + create_foreign_pool_with_native_on!($sender_para, Location::from($asset_id), asset_owner.clone()); + create_foreign_pool_with_native_on!($receiver_para, Location::from($asset_id), asset_owner.clone()); + $asset_hub::fund_accounts(vec![(sov_of_sender_on_ah, $amount * 2)]); + // Get the final execution fees at the destination. + // + // Note: We need to do this after resetting the externalities to get an accurate value here. + // This is because the dry-run on asset hub does affect the liquidity pool distribution on PenpalB + // which affects the assets amount we have to pay. + let mut final_execution_fees = 0; + <$receiver_para as $crate::macros::TestExt>::execute_with(|| { + type Runtime = <$receiver_para as $crate::macros::Chain>::Runtime; + + let weight = >::query_xcm_weight( + intermediate_remote_message.clone()).expect("`query_xcm_weight` returned none"); + final_execution_fees = + >::query_weight_to_asset_fee(weight, + $crate::macros::VersionedAssetId::from($crate::macros::AssetId($crate::macros::Location::parent()))) + .expect("`query_weight_to_asset_fee` returned none"); + }); + // Actually run the extrinsic. let sender_assets_before = <$sender_para as $crate::macros::TestExt>::execute_with(|| { - type ForeignAssets = <$sender_para as [<$sender_para Pallet>]>::ForeignAssets; - >::balance($asset_id.clone().into(), &sender) + type Assets = <$sender_para as [<$sender_para Pallet>]>::Assets; + >::balance($asset_id.clone().into(), &sender) }); let receiver_assets_before = <$receiver_para as $crate::macros::TestExt>::execute_with(|| { - type ForeignAssets = <$receiver_para as [<$receiver_para Pallet>]>::ForeignAssets; - >::balance($asset_id.clone().into(), &beneficiary_id) + type Assets = <$receiver_para as [<$receiver_para Pallet>]>::Assets; + >::balance($asset_id.clone().into(), &beneficiary_id) }); test.set_assertion::<$sender_para>(sender_assertions); @@ -825,18 +839,18 @@ macro_rules! test_can_estimate_and_pay_exact_fees { let call = get_call( ($crate::macros::Parent, local_execution_fees + local_delivery_fees), ($crate::macros::Parent, intermediate_execution_fees + intermediate_delivery_fees), - ($crate::macros::Parent, final_execution_fees), + ($crate::macros::Parent, final_execution_fees + 1), ); test.set_call(call); test.assert(); let sender_assets_after = <$sender_para as $crate::macros::TestExt>::execute_with(|| { - type ForeignAssets = <$sender_para as [<$sender_para Pallet>]>::ForeignAssets; - >::balance($asset_id.clone().into(), &sender) + type Assets = <$sender_para as [<$sender_para Pallet>]>::Assets; + >::balance($asset_id.clone().into(), &sender) }); let receiver_assets_after = <$receiver_para as $crate::macros::TestExt>::execute_with(|| { - type ForeignAssets = <$receiver_para as [<$receiver_para Pallet>]>::ForeignAssets; - >::balance($asset_id.into(), &beneficiary_id) + type Assets = <$receiver_para as [<$receiver_para Pallet>]>::Assets; + >::balance($asset_id.into(), &beneficiary_id) }); // We know the exact fees on every hop. @@ -848,7 +862,7 @@ macro_rules! test_can_estimate_and_pay_exact_fees { local_delivery_fees - intermediate_execution_fees - intermediate_delivery_fees - - final_execution_fees + final_execution_fees - 1 ); } }; @@ -1066,83 +1080,6 @@ macro_rules! test_cross_chain_alias { }; } -/// note: $asset needs to be prefunded outside this function -#[macro_export] -macro_rules! create_pool_with_native_on { - ( $chain:ident, $asset:expr, $is_foreign:expr, $asset_owner:expr ) => { - $crate::create_pool_with_native_on!( - $chain, - $asset, - $is_foreign, - $asset_owner, - 1_000_000_000_000, - 2_000_000_000_000 - ); - }; - - ( $chain:ident, $asset:expr, $is_foreign:expr, $asset_owner:expr, $native_amount:expr, $asset_amount:expr ) => { - $crate::macros::paste::paste! { - <$chain as $crate::macros::TestExt>::execute_with(|| { - type RuntimeEvent = <$chain as $crate::macros::Chain>::RuntimeEvent; - let owner = $asset_owner; - let signed_owner = <$chain as $crate::macros::Chain>::RuntimeOrigin::signed(owner.clone()); - let native_asset: $crate::macros::Location = $crate::macros::Parent.into(); - - if $is_foreign { - $crate::macros::assert_ok!(<$chain as [<$chain Pallet>]>::ForeignAssets::mint( - signed_owner.clone(), - $asset.clone().into(), - owner.clone().into(), - 10_000_000_000_000, // For it to have more than enough. - )); - } else { - let asset_id = match $asset.interior.last() { - Some($crate::macros::GeneralIndex(id)) => *id as u32, - _ => unreachable!(), - }; - $crate::macros::assert_ok!(<$chain as [<$chain Pallet>]>::Assets::mint( - signed_owner.clone(), - asset_id.into(), - owner.clone().into(), - 10_000_000_000_000, // For it to have more than enough. - )); - } - - $crate::macros::assert_ok!(<$chain as [<$chain Pallet>]>::AssetConversion::create_pool( - signed_owner.clone(), - Box::new(native_asset.clone()), - Box::new($asset.clone()), - )); - - $crate::macros::assert_expected_events!( - $chain, - vec![ - RuntimeEvent::AssetConversion($crate::macros::pallet_asset_conversion::Event::PoolCreated { .. }) => {}, - ] - ); - - $crate::macros::assert_ok!(<$chain as [<$chain Pallet>]>::AssetConversion::add_liquidity( - signed_owner, - Box::new(native_asset), - Box::new($asset), - $native_amount, - $asset_amount, - 0, - 0, - owner.into() - )); - - $crate::macros::assert_expected_events!( - $chain, - vec![ - RuntimeEvent::AssetConversion($crate::macros::pallet_asset_conversion::Event::LiquidityAdded { .. }) => {}, - ] - ); - }); - } - }; -} - #[macro_export] macro_rules! assert_whitelisted { ($chain:ident, $expected_call_hash:expr) => { diff --git a/cumulus/parachains/integration-tests/emulated/common/src/pools.rs b/cumulus/parachains/integration-tests/emulated/common/src/pools.rs new file mode 100644 index 0000000000000..628404cb8391e --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/common/src/pools.rs @@ -0,0 +1,222 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +pub use paste; + +pub use pallet_asset_conversion; + +/// This function assumes that the asset is prefunded. +/// +/// Usually, this function is only called from the other macros in this module. +#[macro_export] +macro_rules! create_pool_with_native_location_on { + ( $chain:ident, $native_location:expr, $asset_id:expr, $asset_owner:expr, $wnd_amount:expr, $asset_amount:expr ) => { + $crate::pools::paste::paste! { + <$chain>::execute_with(|| { + type RuntimeEvent = <$chain as Chain>::RuntimeEvent; + let owner = $asset_owner; + let signed_owner = <$chain as Chain>::RuntimeOrigin::signed(owner.clone()); + let native_location: Location = $native_location; + + assert_ok!(<$chain as [<$chain Pallet>]>::AssetConversion::create_pool( + signed_owner.clone(), + Box::new(native_location.clone()), + Box::new($asset_id.clone()), + )); + + assert_expected_events!( + $chain, + vec![ + RuntimeEvent::AssetConversion($crate::pools::pallet_asset_conversion::Event::PoolCreated { .. }) => {}, + ] + ); + + assert_ok!(<$chain as [<$chain Pallet>]>::AssetConversion::add_liquidity( + signed_owner, + Box::new(native_location), + Box::new($asset_id), + $wnd_amount, + $asset_amount, + 0, + 0, + owner.into() + )); + + assert_expected_events!( + $chain, + vec![ + RuntimeEvent::AssetConversion($crate::pools::pallet_asset_conversion::Event::LiquidityAdded { .. }) => {}, + ] + ); + }); + } + }; +} + +#[macro_export] +macro_rules! create_pool_with_relay_native_on { + // default amounts + ( $chain:ident, $asset_id:expr, $asset_owner:expr ) => { + $crate::create_pool_with_relay_native_on!( + $chain, + $asset_id, + $asset_owner, + 1_000_000_000_000, + 2_000_000_000_000 + ); + }; + + // custom amounts + ( $chain:ident, $asset_id:expr, $asset_owner:expr, $wnd_amount:expr, $asset_amount:expr ) => { + $crate::pools::paste::paste! { + <$chain>::execute_with(|| { + let owner = $asset_owner; + let signed_owner = <$chain as Chain>::RuntimeOrigin::signed(owner.clone()); + + let asset_id = match $asset_id.interior.last() { + Some(GeneralIndex(id)) => *id as u32, + _ => unreachable!(), + }; + assert_ok!(<$chain as [<$chain Pallet>]>::Assets::mint( + signed_owner.clone(), + asset_id.into(), + owner.clone().into(), + 10_000_000_000_000, // For it to have more than enough. + )); + }); + + let parent_location: Location = Parent.into(); + $crate::create_pool_with_native_location_on!($chain, parent_location, $asset_id, $asset_owner, $wnd_amount, $asset_amount); + } + }; +} + +#[macro_export] +macro_rules! create_foreign_pool_with_parent_native_on { + // default amounts and pallet name + ( $chain:ident, $asset_id:expr, $asset_owner:expr ) => { + $crate::create_foreign_pool_with_parent_native_on!( + $chain, + ForeignAssets, + $asset_id, + $asset_owner, + 1_000_000_000_000, + 2_000_000_000_000 + ); + }; + + // default amounts, custom pallet name + ( $chain:ident, $foreign_pallet_assets:ident, $asset_id:expr, $asset_owner:expr ) => { + $crate::create_foreign_pool_with_parent_native_on!( + $chain, + $foreign_pallet_assets, + $asset_id, + $asset_owner, + 1_000_000_000_000, + 2_000_000_000_000 + ); + }; + + // custom amounts, default pallet name + ( $chain:ident, $asset_id:expr, $asset_owner:expr, $wnd_amount:expr, $asset_amount:expr ) => { + $crate::create_foreign_pool_with_parent_native_on!( + $chain, + ForeignAssets, + $asset_id, + $asset_owner, + $wnd_amount, + $asset_amount + ); + }; + + // custom amounts, custom pallet name + ( $chain:ident, $foreign_pallet_assets:ident, $asset_id:expr, $asset_owner:expr, $wnd_amount:expr, $asset_amount:expr ) => { + $crate::pools::paste::paste! { + <$chain>::execute_with(|| { + let owner = $asset_owner; + let signed_owner = <$chain as Chain>::RuntimeOrigin::signed(owner.clone()); + + assert_ok!(<$chain as [<$chain Pallet>]>::$foreign_pallet_assets::mint( + signed_owner.clone(), + $asset_id.clone().into(), + owner.clone().into(), + 10_000_000_000_000, // For it to have more than enough. + )); + }); + + let wnd_location: Location = Parent.into(); + $crate::create_pool_with_native_location_on!($chain, wnd_location, $asset_id, $asset_owner, $wnd_amount, $asset_amount); + } + }; +} + +#[macro_export] +macro_rules! create_foreign_pool_with_native_on { + // default amounts and pallet name + ( $chain:ident, $asset_id:expr, $asset_owner:expr ) => { + $crate::create_foreign_pool_with_native_on!( + $chain, + Assets, + $asset_id, + $asset_owner, + 1_000_000_000_000, + 2_000_000_000_000 + ); + }; + + // default amounts, custom pallet name + ( $chain:ident, $foreign_pallet_asset:ident, $asset_id:expr, $asset_owner:expr ) => { + $crate::create_foreign_pool_with_native_on!( + $chain, + $foreign_pallet_asset, + $asset_id, + $asset_owner, + 1_000_000_000_000, + 2_000_000_000_000 + ); + }; + + // custom amounts, default pallet name + ( $chain:ident, $asset_id:expr, $asset_owner:expr, $wnd_amount:expr, $asset_amount:expr ) => { + $crate::create_foreign_pool_with_native_on!( + $chain, + Assets, + $asset_id, + $asset_owner, + $wnd_amount, + $asset_amount + ); + }; + + // custom amounts, custom pallet name + ( $chain:ident, $foreign_asset_pallet:ident, $asset_id:expr, $asset_owner:expr, $wnd_amount:expr, $asset_amount:expr ) => { + $crate::pools::paste::paste! { + <$chain>::execute_with(|| { + let owner = $asset_owner; + let signed_owner = <$chain as Chain>::RuntimeOrigin::signed(owner.clone()); + + assert_ok!(<$chain as [<$chain Pallet>]>::$foreign_asset_pallet::mint( + signed_owner.clone(), + $asset_id.clone().into(), + owner.clone().into(), + 10_000_000_000_000, // For it to have more than enough. + )); + }); + + let native_location: Location = Here.into(); + $crate::create_pool_with_native_location_on!($chain, native_location, $asset_id, $asset_owner, $wnd_amount, $asset_amount); + } + }; +} diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs index 253dbaa1e345d..234e05d06bb53 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs @@ -37,6 +37,8 @@ mod imports { pub(crate) use asset_test_utils::xcm_helpers; pub(crate) use emulated_integration_tests_common::{ accounts::DUMMY_EMPTY, + create_foreign_pool_with_native_on, create_foreign_pool_with_parent_native_on, + create_pool_with_relay_native_on, local_penpal_asset, test_can_estimate_and_pay_exact_fees, test_parachain_is_trusted_teleporter, test_parachain_is_trusted_teleporter_for_relay, test_relay_is_trusted_teleporter, test_xcm_fee_querying_apis_work_for_asset_hub, xcm_emulator::{ @@ -48,7 +50,9 @@ mod imports { get_amount_from_versioned_assets, non_fee_asset, xcm_transact_paid_execution, }, xcm_simulator::helpers::TopicIdTracker, - PenpalATeleportableAssetLocation, ASSETS_PALLET_ID, RESERVABLE_ASSET_ID, USDT_ID, XCM_V3, + PenpalALocation, PenpalAPen2TeleportableAssetLocation, + PenpalBPen2TeleportableAssetLocation, ASSETS_PALLET_ID, RESERVABLE_ASSET_ID, USDT_ID, + XCM_V3, }; pub(crate) use parachains_common::{AccountId, Balance}; pub(crate) use westend_system_emulated_network::{ @@ -75,6 +79,7 @@ mod imports { penpal_emulated_chain::{ penpal_runtime::xcm_config::{ CustomizableAssetFromSystemAssetHub as PenpalCustomizableAssetFromSystemAssetHub, + LocalPen2Asset as PenpalLocalPen2Asset, LocalReservableFromAssetHub as PenpalLocalReservableFromAssetHub, LocalTeleportableToAssetHub as PenpalLocalTeleportableToAssetHub, UniversalLocation as PenpalUniversalLocation, @@ -115,10 +120,12 @@ mod imports { pub(crate) type ParaToRelayTest = Test; pub(crate) type RelayToSystemParaTest = Test; pub(crate) type SystemParaToRelayTest = Test; - pub(crate) type SystemParaToParaTest = Test; - pub(crate) type ParaToSystemParaTest = Test; - pub(crate) type ParaToParaThroughRelayTest = Test; - pub(crate) type ParaToParaThroughAHTest = Test; + pub(crate) type SystemParaToParaTest = Test>; + pub(crate) type ParaToSystemParaTest = Test>; + pub(crate) type ParaToParaThroughRelayTest = + Test>; + pub(crate) type ParaToParaThroughAHTest = + Test>; pub(crate) type RelayToParaThroughAHTest = Test; pub(crate) type PenpalToRelayThroughAHTest = Test; } diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/aliases.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/aliases.rs index adcf59e1dc9ce..30efc5f12d293 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/aliases.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/aliases.rs @@ -31,7 +31,7 @@ fn account_on_sibling_syschain_aliases_into_same_local_account() { // origin and target are the same account on different chains let origin: AccountId = [1; 32].into(); let target = origin.clone(); - let fees = WESTEND_ED * 10; + let fees = WESTEND_ED * 20; PenpalB::mint_foreign_asset( ::RuntimeOrigin::signed(PenpalAssetOwner::get()), @@ -40,6 +40,9 @@ fn account_on_sibling_syschain_aliases_into_same_local_account() { fees * 10, ); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + // On Asset Hub we don't want to support aliasing from other chains: // - there is no real world demand for it, the direction is usually reversed, users already have // accounts on AH and want to use them cross-chain on other chains, @@ -69,7 +72,7 @@ fn account_on_sibling_syschain_cannot_alias_into_different_local_account() { // origin and target are different accounts on different chains let origin: AccountId = [1; 32].into(); let target: AccountId = [2; 32].into(); - let fees = WESTEND_ED * 10; + let fees = WESTEND_ED * 20; PenpalB::mint_foreign_asset( ::RuntimeOrigin::signed(PenpalAssetOwner::get()), @@ -78,6 +81,9 @@ fn account_on_sibling_syschain_cannot_alias_into_different_local_account() { fees * 10, ); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + // Aliasing different account on different chains test_cross_chain_alias!( vec![ @@ -198,13 +204,16 @@ fn authorized_cross_chain_aliases() { let origin: AccountId = [100; 32].into(); let bad_origin: AccountId = [150; 32].into(); let target: AccountId = [200; 32].into(); - let fees = WESTEND_ED * 10; + let fees = WESTEND_ED * 20; let pal_admin = ::RuntimeOrigin::signed(PenpalAssetOwner::get()); PenpalB::mint_foreign_asset(pal_admin.clone(), Location::parent(), origin.clone(), fees * 10); PenpalB::mint_foreign_asset(pal_admin, Location::parent(), bad_origin.clone(), fees * 10); AssetHubWestend::fund_accounts(vec![(target.clone(), fees * 10)]); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + // let's authorize `origin` on Penpal to alias `target` on AssetHub AssetHubWestend::execute_with(|| { let penpal_origin = Location::new( diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/exchange_asset.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/exchange_asset.rs index 54775178268c3..d875cce1e7c43 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/exchange_asset.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/exchange_asset.rs @@ -13,9 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{assets_balance_on, create_pool_with_wnd_on, foreign_balance_on, imports::*}; +use crate::{assets_balance_on, imports::*}; use emulated_integration_tests_common::xcm_emulator::TestExt; -use frame_support::assert_ok; use std::convert::Into; use xcm::latest::{Location, Xcm}; @@ -49,18 +48,24 @@ fn exchange_asset_from_penpal_via_asset_hub_back_to_penpal() { ); // We create a pool between WND and USDT in AssetHub so we can do the exchange - create_pool_with_wnd_on!( + create_pool_with_relay_native_on!( AssetHubWestend, usdt_asset_hub_pov.clone(), - false, AssetHubWestendSender::get(), 1_000_000_000_000, 20_000_000_000 ); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!( + PenpalA, + wnd_from_parachain_pov.clone(), + PenpalAssetOwner::get() + ); + // Query initial balances let sender_usdt_on_penpal_before = - foreign_balance_on!(PenpalA, usdt_penpal_pov.clone(), &sender); + assets_balance_on!(PenpalA, usdt_penpal_pov.clone(), &sender); let sender_usdt_on_ah_before = assets_balance_on!(AssetHubWestend, USDT_ID, &sender); let asset_hub_location_penpal_pov = PenpalA::sibling_location_of(AssetHubWestend::para_id()); @@ -176,8 +181,7 @@ fn exchange_asset_from_penpal_via_asset_hub_back_to_penpal() { // Query final balances let sender_usdt_on_ah_after = assets_balance_on!(AssetHubWestend, USDT_ID, &sender); - let sender_usdt_on_penpal_after = - foreign_balance_on!(PenpalA, usdt_penpal_pov.clone(), &sender); + let sender_usdt_on_penpal_after = assets_balance_on!(PenpalA, usdt_penpal_pov.clone(), &sender); // Receiver's balance is increased by usdt amount we got from exchange assert_eq!( diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/foreign_assets.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/foreign_assets.rs index f5ccdd25dda0c..9b8787f3502da 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/foreign_assets.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/foreign_assets.rs @@ -14,7 +14,7 @@ // limitations under the License. use crate::{ - assets_balance_on, create_pool_with_wnd_on, foreign_balance_on, imports::*, + asset_exists_on, assets_balance_on, foreign_balance_on, imports::*, tests::send::penpal_register_foreign_asset_on_asset_hub, }; @@ -24,44 +24,34 @@ use crate::{ // between Penpal and AH. pub fn set_up_foreign_asset( sender: sp_runtime::AccountId32, - asset_id_on_penpal: u32, + asset_location_on_penpal: Location, asset_amount_to_send: u128, teleportable: bool, ) -> (Location, Location) { let asset_owner = PenpalAssetOwner::get(); // Give the sender enough native - PenpalA::mint_foreign_asset( - ::RuntimeOrigin::signed(asset_owner.clone()), - RelayLocation::get(), - sender.clone(), - asset_amount_to_send, - ); + PenpalA::fund_accounts(vec![(sender.clone(), asset_amount_to_send)]); // Create the asset on Penpal let to_fund = asset_amount_to_send * 2; - PenpalA::force_create_asset( - asset_id_on_penpal, + PenpalA::force_create_foreign_asset( + asset_location_on_penpal.clone(), asset_owner.clone(), true, ASSET_MIN_BALANCE, vec![(sender.clone(), to_fund)], ); - PenpalA::execute_with(|| { - type Assets = ::Assets; - assert!(Assets::asset_exists(asset_id_on_penpal)); - }); - let asset_location_on_penpal = Location::new( - 0, - [ - Junction::PalletInstance(ASSETS_PALLET_ID), - Junction::GeneralIndex(asset_id_on_penpal.into()), - ], - ); + + asset_exists_on!(PenpalA, asset_location_on_penpal.clone()); // Setup a pool on Penpal between native asset and newly created asset, so we can pay fees using // new asset directly. - create_pool_with_wnd_on!(PenpalA, asset_location_on_penpal.clone(), false, asset_owner.clone()); + create_foreign_pool_with_native_on!( + PenpalA, + asset_location_on_penpal.clone(), + asset_owner.clone() + ); // Register asset on Asset Hub using XCM let penpal_sovereign_account = AssetHubWestend::sovereign_account_id_of( @@ -75,10 +65,9 @@ pub fn set_up_foreign_asset( // Setup a pool on Asset Hub between native asset and newly created asset, so we can pay fees // using new asset directly. - create_pool_with_wnd_on!( + create_foreign_pool_with_parent_native_on!( AssetHubWestend, foreign_asset_at_asset_hub.clone(), - true, penpal_sovereign_account.clone() ); @@ -148,16 +137,16 @@ pub fn penpal_set_foreign_asset_reserves_on_asset_hub( fn bidirectional_teleport_foreign_asset_between_penpal_and_asset_hub() { let sender = PenpalASender::get(); let receiver = AssetHubWestendReceiver::get(); - let new_asset_id = 42; + let new_asset_id = local_penpal_asset(42); let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 10_000; let (asset_location_on_penpal, foreign_asset_location_on_ah) = - set_up_foreign_asset(sender.clone(), new_asset_id, asset_amount_to_send, true); + set_up_foreign_asset(sender.clone(), new_asset_id.clone(), asset_amount_to_send, true); //////////////////////////////// // Teleport it from Penpal to AH //////////////////////////////// - let penpal_sender_balance_before = assets_balance_on!(PenpalA, new_asset_id, &sender); + let penpal_sender_balance_before = assets_balance_on!(PenpalA, new_asset_id.clone(), &sender); let ah_receiver_balance_before = foreign_balance_on!(AssetHubWestend, foreign_asset_location_on_ah.clone(), &receiver); @@ -194,7 +183,7 @@ fn bidirectional_teleport_foreign_asset_between_penpal_and_asset_hub() { .unwrap(); }); - let penpal_sender_balance_after = assets_balance_on!(PenpalA, new_asset_id, &sender); + let penpal_sender_balance_after = assets_balance_on!(PenpalA, new_asset_id.clone(), &sender); let ah_receiver_balance_after = foreign_balance_on!(AssetHubWestend, foreign_asset_location_on_ah.clone(), &receiver); @@ -245,7 +234,7 @@ fn bidirectional_teleport_foreign_asset_between_penpal_and_asset_hub() { let asset_amount_to_send = ah_receiver_balance_after; let ah_sender_balance_before = foreign_balance_on!(AssetHubWestend, foreign_asset_location_on_ah.clone(), &receiver); - let penpal_receiver_balance_before = assets_balance_on!(PenpalA, new_asset_id, &sender); + let penpal_receiver_balance_before = assets_balance_on!(PenpalA, new_asset_id.clone(), &sender); let dest = AssetHubWestend::sibling_location_of(PenpalA::para_id()); // execute xcm from asset hub to penpal @@ -302,7 +291,7 @@ fn bidirectional_teleport_foreign_asset_between_penpal_and_asset_hub() { let ah_sender_balance_after = foreign_balance_on!(AssetHubWestend, foreign_asset_location_on_ah, &receiver); - let penpal_receiver_balance_after = assets_balance_on!(PenpalA, new_asset_id, &sender); + let penpal_receiver_balance_after = assets_balance_on!(PenpalA, new_asset_id.clone(), &sender); assert!(ah_sender_balance_after < ah_sender_balance_before); assert!(penpal_receiver_balance_after > penpal_receiver_balance_before); @@ -318,16 +307,16 @@ fn bidirectional_teleport_foreign_asset_between_penpal_and_asset_hub() { fn bidirectional_reserve_transfer_foreign_asset_between_penpal_and_asset_hub() { let sender = PenpalASender::get(); let receiver = AssetHubWestendReceiver::get(); - let new_asset_id = 42; + let new_asset_id = local_penpal_asset(42); let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 10_000; let (asset_location_on_penpal, foreign_asset_location_on_ah) = - set_up_foreign_asset(sender.clone(), new_asset_id, asset_amount_to_send, false); + set_up_foreign_asset(sender.clone(), new_asset_id.clone(), asset_amount_to_send, false); //////////////////////////////////////// // Reserve-transfer it from Penpal to AH //////////////////////////////////////// - let penpal_sender_balance_before = assets_balance_on!(PenpalA, new_asset_id, &sender); + let penpal_sender_balance_before = assets_balance_on!(PenpalA, new_asset_id.clone(), &sender); let ah_receiver_balance_before = foreign_balance_on!(AssetHubWestend, foreign_asset_location_on_ah.clone(), &receiver); @@ -383,7 +372,7 @@ fn bidirectional_reserve_transfer_foreign_asset_between_penpal_and_asset_hub() { )); }); - let penpal_sender_balance_after = assets_balance_on!(PenpalA, new_asset_id, &sender); + let penpal_sender_balance_after = assets_balance_on!(PenpalA, new_asset_id.clone(), &sender); let ah_receiver_balance_after = foreign_balance_on!(AssetHubWestend, foreign_asset_location_on_ah.clone(), &receiver); @@ -397,7 +386,7 @@ fn bidirectional_reserve_transfer_foreign_asset_between_penpal_and_asset_hub() { let asset_amount_to_send = ah_receiver_balance_after; let ah_sender_balance_before = foreign_balance_on!(AssetHubWestend, foreign_asset_location_on_ah.clone(), &receiver); - let penpal_receiver_balance_before = assets_balance_on!(PenpalA, new_asset_id, &sender); + let penpal_receiver_balance_before = assets_balance_on!(PenpalA, new_asset_id.clone(), &sender); let dest = AssetHubWestend::sibling_location_of(PenpalA::para_id()); // execute xcm from asset hub to penpal @@ -453,7 +442,7 @@ fn bidirectional_reserve_transfer_foreign_asset_between_penpal_and_asset_hub() { let ah_sender_balance_after = foreign_balance_on!(AssetHubWestend, foreign_asset_location_on_ah, &receiver); - let penpal_receiver_balance_after = assets_balance_on!(PenpalA, new_asset_id, &sender); + let penpal_receiver_balance_after = assets_balance_on!(PenpalA, new_asset_id.clone(), &sender); assert!(ah_sender_balance_after < ah_sender_balance_before); assert!(penpal_receiver_balance_after > penpal_receiver_balance_before); @@ -464,10 +453,10 @@ fn bidirectional_reserve_transfer_foreign_asset_between_penpal_and_asset_hub() { #[test] fn verify_foreign_asset_origin_checks() { let sender = PenpalASender::get(); - let new_asset_id = 42; + let new_asset_id = local_penpal_asset(42); let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 10_000; let (_, foreign_asset_location_on_ah) = - set_up_foreign_asset(sender.clone(), new_asset_id, asset_amount_to_send, false); + set_up_foreign_asset(sender.clone(), new_asset_id.clone(), asset_amount_to_send, false); let penpal_sovereign = AssetHubWestend::sovereign_account_id_of( AssetHubWestend::sibling_location_of(PenpalA::para_id()), @@ -507,7 +496,7 @@ fn verify_foreign_asset_origin_checks() { }); // Now set asset reserves using remote XCM from correct origin chain. // Use wrong `{origin, asset}` combination. - let asset_id_on_ah = emulated_integration_tests_common::PenpalBTeleportableAssetLocation::get(); + let asset_id_on_ah = PenpalBPen2TeleportableAssetLocation::get(); penpal_set_foreign_asset_reserves_on_asset_hub(asset_id_on_ah, vec![]); // Verify it failed. AssetHubWestend::execute_with(|| { diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/hybrid_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/hybrid_transfers.rs index 77a4796b553b7..7461d0c9d84e6 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/hybrid_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/hybrid_transfers.rs @@ -16,6 +16,7 @@ use emulated_integration_tests_common::xcm_helpers::{ find_mq_processed_id, find_xcm_sent_message_id, }; +use frame_support::traits::fungible; use westend_system_emulated_network::westend_emulated_chain::westend_runtime::Dmp; use super::reserve_transfer::*; @@ -193,6 +194,10 @@ fn transfer_foreign_assets_from_asset_hub_to_para() { )], )); }); + + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalA, Location::parent(), PenpalAssetOwner::get()); + PenpalA::force_create_foreign_asset( roc_at_westend_parachains.clone(), assets_owner.clone(), @@ -226,7 +231,7 @@ fn transfer_foreign_assets_from_asset_hub_to_para() { let test_args = TestContext { sender: sender.clone(), receiver: receiver.clone(), - args: TestArgs::new_para( + args: TestArgs::::new_para( destination.clone(), receiver.clone(), native_amount_to_send, @@ -247,12 +252,12 @@ fn transfer_foreign_assets_from_asset_hub_to_para() { ) }); let receiver_assets_before = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(native_asset_location.clone(), &receiver) + type Assets = ::Assets; + >::balance(native_asset_location.clone(), &receiver) }); let receiver_rocs_before = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.clone(), &receiver) + type Assets = ::Assets; + >::balance(roc_at_westend_parachains.clone(), &receiver) }); // Set assertions and dispatchables @@ -271,12 +276,12 @@ fn transfer_foreign_assets_from_asset_hub_to_para() { ) }); let receiver_assets_after = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(native_asset_location, &receiver) + type Assets = ::Assets; + >::balance(native_asset_location, &receiver) }); let receiver_rocs_after = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains, &receiver) + type Assets = ::Assets; + >::balance(roc_at_westend_parachains, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees @@ -304,8 +309,8 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { // Init values for Parachain let destination = PenpalA::sibling_location_of(AssetHubWestend::para_id()); let sender = PenpalASender::get(); - let native_amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 10000; - let native_asset_location = RelayLocation::get(); + let relay_native_amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 10000; + let relay_native_location = RelayLocation::get(); let assets_owner = PenpalAssetOwner::get(); // Foreign asset used: bridged ROC @@ -341,9 +346,9 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { // fund Parachain's sender account PenpalA::mint_foreign_asset( ::RuntimeOrigin::signed(assets_owner.clone()), - native_asset_location.clone(), + relay_native_location.clone(), sender.clone(), - native_amount_to_send * 2, + relay_native_amount_to_send * 2, ); PenpalA::mint_foreign_asset( ::RuntimeOrigin::signed(assets_owner.clone()), @@ -361,7 +366,7 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { // fund Parachain's SA on AssetHub with the assets held in reserve AssetHubWestend::fund_accounts(vec![( sov_penpal_on_ahr.clone().into(), - native_amount_to_send * 2, + relay_native_amount_to_send * 2, )]); AssetHubWestend::mint_foreign_asset( ::RuntimeOrigin::signed(assets_owner), @@ -372,7 +377,7 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { // Assets to send let assets: Vec = vec![ - (Parent, native_amount_to_send).into(), + (Parent, relay_native_amount_to_send).into(), (roc_at_westend_parachains.clone(), foreign_amount_to_send).into(), ]; let fee_asset_id = AssetId(Parent.into()); @@ -385,7 +390,7 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { args: TestArgs::new_para( destination.clone(), receiver.clone(), - native_amount_to_send, + relay_native_amount_to_send, assets.into(), None, fee_asset_item, @@ -394,13 +399,13 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { let mut test = ParaToSystemParaTest::new(test_args); // Query initial balances - let sender_native_before = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(native_asset_location.clone(), &sender) + let sender_relay_native_before = PenpalA::execute_with(|| { + type Assets = ::Assets; + >::balance(relay_native_location.clone(), &sender) }); let sender_rocs_before = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.clone(), &sender) + type Assets = ::Assets; + >::balance(roc_at_westend_parachains.clone(), &sender) }); let receiver_native_before = test.receiver.balance; let receiver_rocs_before = AssetHubWestend::execute_with(|| { @@ -418,15 +423,15 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { test.assert(); // Query final balances - let sender_native_after = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(native_asset_location, &sender) + let sender_relay_native_after = PenpalA::execute_with(|| { + type Assets = ::Assets; + >::balance(relay_native_location, &sender) }); let sender_rocs_after = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.clone(), &sender) + type Assets = ::Assets; + >::balance(roc_at_westend_parachains.clone(), &sender) }); - let receiver_native_after = test.receiver.balance; + let receiver_relay_native_after = test.receiver.balance; let receiver_rocs_after = AssetHubWestend::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( @@ -435,16 +440,16 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { ) }); - // Sender's balance is reduced by amount sent plus delivery fees - assert!(sender_native_after < sender_native_before - native_amount_to_send); + // Sender's balance is reduced by exact amount sent (delivery fees are charged in native) + assert_eq!(sender_relay_native_after, sender_relay_native_before - relay_native_amount_to_send); // Sender's balance is reduced by foreign amount sent assert_eq!(sender_rocs_after, sender_rocs_before - foreign_amount_to_send); // Receiver's balance is increased - assert!(receiver_native_after > receiver_native_before); + assert!(receiver_relay_native_after > receiver_native_before); // Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`; // `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but // should be non-zero - assert!(receiver_native_after < receiver_native_before + native_amount_to_send); + assert!(receiver_relay_native_after < receiver_native_before + relay_native_amount_to_send); // Receiver's balance is increased by foreign amount sent assert_eq!(receiver_rocs_after, receiver_rocs_before + foreign_amount_to_send); } @@ -513,6 +518,9 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { vec![], ); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + // fund Parachain's sender account PenpalA::mint_foreign_asset( ::RuntimeOrigin::signed(assets_owner.clone()), @@ -563,12 +571,12 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { // Query initial balances let sender_wnds_before = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(wnd_location.clone(), &sender) + type Assets = ::Assets; + >::balance(wnd_location.clone(), &sender) }); let sender_rocs_before = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.clone(), &sender) + type Assets = ::Assets; + >::balance(roc_at_westend_parachains.clone(), &sender) }); let wnds_in_sender_reserve_on_ah_before = ::account_data_of(sov_of_sender_on_ah.clone()).free; @@ -589,12 +597,12 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { ) }); let receiver_wnds_before = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(wnd_location.clone(), &receiver) + type Assets = ::Assets; + >::balance(wnd_location.clone(), &receiver) }); let receiver_rocs_before = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.clone(), &receiver) + type Assets = ::Assets; + >::balance(roc_at_westend_parachains.clone(), &receiver) }); // Set assertions and dispatchables @@ -609,12 +617,12 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { // Query final balances let sender_wnds_after = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(wnd_location.clone(), &sender) + type Assets = ::Assets; + >::balance(wnd_location.clone(), &sender) }); let sender_rocs_after = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.clone(), &sender) + type Assets = ::Assets; + >::balance(roc_at_westend_parachains.clone(), &sender) }); let rocs_in_sender_reserve_on_ah_after = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; @@ -635,16 +643,16 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { let wnds_in_receiver_reserve_on_ah_after = ::account_data_of(sov_of_receiver_on_ah).free; let receiver_wnds_after = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(wnd_location, &receiver) + type Assets = ::Assets; + >::balance(wnd_location, &receiver) }); let receiver_rocs_after = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains, &receiver) + type Assets = ::Assets; + >::balance(roc_at_westend_parachains, &receiver) }); // Sender's balance is reduced by amount sent. - assert!(sender_wnds_after < sender_wnds_before - wnd_to_send); + assert_eq!(sender_wnds_after, sender_wnds_before - wnd_to_send); assert_eq!(sender_rocs_after, sender_rocs_before - roc_to_send); // Sovereign accounts on reserve are changed accordingly. assert_eq!( @@ -695,6 +703,9 @@ fn transfer_native_asset_from_relay_to_penpal_through_asset_hub() { let relay_native_asset_location = RelayLocation::get(); let receiver = PenpalAReceiver::get(); + // Create pool with WND to be able to pay execution in WND + create_foreign_pool_with_native_on!(PenpalA, RelayLocation::get(), PenpalAssetOwner::get()); + // Init Test let test_args = TestContext { sender, @@ -712,8 +723,8 @@ fn transfer_native_asset_from_relay_to_penpal_through_asset_hub() { ::Balances::free_balance(sov_penpal_on_ah.clone()) }); let receiver_assets_before = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &receiver) + type Assets = ::Assets; + >::balance(relay_native_asset_location.clone(), &receiver) }); fn relay_assertions(t: RelayToParaThroughAHTest) { @@ -755,7 +766,7 @@ fn transfer_native_asset_from_relay_to_penpal_through_asset_hub() { assert_expected_events!( PenpalA, vec![ - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { asset_id: *asset_id == Location::new(1, Here), owner: *owner == t.receiver.account_id, }, @@ -820,8 +831,8 @@ fn transfer_native_asset_from_relay_to_penpal_through_asset_hub() { ::Balances::free_balance(sov_penpal_on_ah) }); let receiver_assets_after = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location, &receiver) + type Assets = ::Assets; + >::balance(relay_native_asset_location, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees @@ -882,9 +893,13 @@ fn transfer_native_asset_from_penpal_to_relay_through_asset_hub() { AssetHubWestend::fund_accounts(vec![(sov_penpal_on_ah.clone().into(), amount_to_send * 2)]); // Query initial balances - let sender_balance_before = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &sender) + let sender_native_balance_before = PenpalA::execute_with(|| { + type Balances = ::Balances; + >::balance(&sender) + }); + let sender_relay_balance_before = PenpalA::execute_with(|| { + type Assets = ::Assets; + >::balance(relay_native_asset_location.clone(), &sender) }); let sov_penpal_on_ah_before = AssetHubWestend::execute_with(|| { ::Balances::free_balance(sov_penpal_on_ah.clone()) @@ -939,9 +954,13 @@ fn transfer_native_asset_from_penpal_to_relay_through_asset_hub() { test.assert(); // Query final balances + let sender_native_balance_after = PenpalA::execute_with(|| { + type Balances = ::Balances; + >::balance(&sender) + }); let sender_balance_after = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &sender) + type Assets = ::Assets; + >::balance(relay_native_asset_location.clone(), &sender) }); let sov_penpal_on_ah_after = AssetHubWestend::execute_with(|| { ::Balances::free_balance(sov_penpal_on_ah.clone()) @@ -950,8 +969,10 @@ fn transfer_native_asset_from_penpal_to_relay_through_asset_hub() { ::Balances::free_balance(receiver.clone()) }); - // Sender's asset balance is reduced by amount sent plus delivery fees - assert!(sender_balance_after < sender_balance_before - amount_to_send); + // Paid delivery fees in native + assert!(sender_native_balance_after < sender_native_balance_before); + // Sender's asset balance is reduced by exact amount + assert_eq!(sender_balance_after, sender_relay_balance_before - amount_to_send); // SA on AH balance is decreased by `amount_to_send` assert_eq!(sov_penpal_on_ah_after, sov_penpal_on_ah_before - amount_to_send); // Receiver's balance is increased diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/mod.rs index 15946390a6479..b85b2c2034ebe 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/mod.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/mod.rs @@ -56,78 +56,13 @@ macro_rules! assets_balance_on { } #[macro_export] -macro_rules! create_pool_with_wnd_on { - // default amounts - ( $chain:ident, $asset_id:expr, $is_foreign:expr, $asset_owner:expr ) => { - $crate::create_pool_with_wnd_on!( - $chain, - $asset_id, - $is_foreign, - $asset_owner, - 1_000_000_000_000, - 2_000_000_000_000 - ); - }; - - // custom amounts - ( $chain:ident, $asset_id:expr, $is_foreign:expr, $asset_owner:expr, $wnd_amount:expr, $asset_amount:expr ) => { +macro_rules! asset_exists_on { + ( $chain:ident, $id:expr ) => { emulated_integration_tests_common::impls::paste::paste! { <$chain>::execute_with(|| { - type RuntimeEvent = <$chain as Chain>::RuntimeEvent; - let owner = $asset_owner; - let signed_owner = <$chain as Chain>::RuntimeOrigin::signed(owner.clone()); - let wnd_location: Location = Parent.into(); - if $is_foreign { - assert_ok!(<$chain as [<$chain Pallet>]>::ForeignAssets::mint( - signed_owner.clone(), - $asset_id.clone().into(), - owner.clone().into(), - 10_000_000_000_000, // For it to have more than enough. - )); - } else { - let asset_id = match $asset_id.interior.last() { - Some(GeneralIndex(id)) => *id as u32, - _ => unreachable!(), - }; - assert_ok!(<$chain as [<$chain Pallet>]>::Assets::mint( - signed_owner.clone(), - asset_id.into(), - owner.clone().into(), - 10_000_000_000_000, // For it to have more than enough. - )); - } - - assert_ok!(<$chain as [<$chain Pallet>]>::AssetConversion::create_pool( - signed_owner.clone(), - Box::new(wnd_location.clone()), - Box::new($asset_id.clone()), - )); - - assert_expected_events!( - $chain, - vec![ - RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::PoolCreated { .. }) => {}, - ] - ); - - assert_ok!(<$chain as [<$chain Pallet>]>::AssetConversion::add_liquidity( - signed_owner, - Box::new(wnd_location), - Box::new($asset_id), - $wnd_amount, - $asset_amount, - 0, - 0, - owner.into() - )); - - assert_expected_events!( - $chain, - vec![ - RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::LiquidityAdded { .. }) => {}, - ] - ); - }); + type Assets = <$chain as [<$chain Pallet>]>::Assets; + >::asset_exists($id) + }) } }; } diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs index 7738e36e5d728..21b1a56254f52 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{create_pool_with_wnd_on, foreign_balance_on, imports::*}; +use crate::{assets_balance_on, imports::*}; use emulated_integration_tests_common::xcm_helpers::{ find_mq_processed_id, find_xcm_sent_message_id, }; @@ -49,7 +49,7 @@ fn para_to_relay_sender_assertions(t: ParaToRelayTest) { PenpalA, vec![ // Amount to reserve transfer is transferred to Parachain's Sovereign account - RuntimeEvent::ForeignAssets( + RuntimeEvent::Assets( pallet_assets::Event::Burned { asset_id, owner, balance, .. } ) => { asset_id: *asset_id == RelayLocation::get(), @@ -135,7 +135,7 @@ pub fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) { assert_expected_events!( PenpalA, vec![ - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { asset_id: *asset_id == expected_id, owner: *owner == t.receiver.account_id, }, @@ -163,7 +163,7 @@ pub fn system_para_to_penpal_receiver_assertions(t: SystemParaToParaTest) { assert_expected_events!( PenpalA, vec![ - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { asset_id: *asset_id == relative_id, owner: *owner == t.receiver.account_id, }, @@ -181,7 +181,7 @@ pub fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) { assert_expected_events!( PenpalA, vec![ - RuntimeEvent::ForeignAssets( + RuntimeEvent::Assets( pallet_assets::Event::Burned { asset_id, owner, balance } ) => { asset_id: *asset_id == expected_id, @@ -324,14 +324,14 @@ fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { PenpalA, vec![ // Fees amount to reserve transfer is burned from Parachains's sender account - RuntimeEvent::ForeignAssets( + RuntimeEvent::Assets( pallet_assets::Event::Burned { asset_id, owner, .. } ) => { asset_id: *asset_id == system_para_native_asset_location, owner: *owner == t.sender.account_id, }, // Amount to reserve transfer is burned from Parachains's sender account - RuntimeEvent::ForeignAssets( + RuntimeEvent::Assets( pallet_assets::Event::Burned { asset_id, owner, balance } ) => { asset_id: *asset_id == reservable_asset_location, @@ -353,11 +353,11 @@ fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { assert_expected_events!( PenpalA, vec![ - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { asset_id: *asset_id == RelayLocation::get(), owner: *owner == t.receiver.account_id, }, - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { + RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { asset_id: *asset_id == system_para_asset_location, owner: *owner == t.receiver.account_id, amount: *amount == t.args.amount, @@ -405,7 +405,7 @@ fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) { assert_expected_events!( PenpalA, vec![ - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { asset_id: *asset_id == RelayLocation::get(), owner: *owner == t.receiver.account_id, }, @@ -416,7 +416,9 @@ fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) { ); } -pub fn para_to_para_through_hop_sender_assertions(mut t: Test) { +pub fn para_to_para_through_hop_sender_assertions( + mut t: Test>, +) { type RuntimeEvent = ::RuntimeEvent; PenpalA::assert_xcm_pallet_attempted_complete(None); @@ -430,7 +432,7 @@ pub fn para_to_para_through_hop_sender_assertions(mut t: Test { asset_id: *asset_id == expected_id, @@ -498,7 +500,7 @@ fn para_to_para_asset_hub_hop_assertions(t: ParaToParaThroughAHTest) { } pub fn para_to_para_through_hop_receiver_assertions( - mut t: Test, + mut t: Test>, ) { type RuntimeEvent = ::RuntimeEvent; @@ -512,7 +514,7 @@ pub fn para_to_para_through_hop_receiver_assertions( assert_expected_events!( PenpalB, vec![ - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { asset_id: *asset_id == expected_id, owner: *owner == t.receiver.account_id, }, @@ -775,6 +777,13 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let relay_native_asset_location = RelayLocation::get(); let receiver = PenpalAReceiver::get(); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!( + PenpalA, + relay_native_asset_location.clone(), + PenpalAssetOwner::get() + ); + // Init Test let test_args = TestContext { sender, @@ -786,7 +795,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() { // Query initial balances let sender_balance_before = test.sender.balance; let receiver_assets_before = - foreign_balance_on!(PenpalA, relay_native_asset_location.clone(), &receiver); + assets_balance_on!(PenpalA, relay_native_asset_location.clone(), &receiver); // Set assertions and dispatchables test.set_assertion::(relay_to_para_sender_assertions); @@ -796,8 +805,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() { // Query final balances let sender_balance_after = test.sender.balance; - let receiver_assets_after = - foreign_balance_on!(PenpalA, relay_native_asset_location, &receiver); + let receiver_assets_after = assets_balance_on!(PenpalA, relay_native_asset_location, &receiver); // Sender's balance is reduced by amount sent plus delivery fees assert!(sender_balance_after < sender_balance_before - amount_to_send); @@ -853,7 +861,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() { // Query initial balances let sender_assets_before = - foreign_balance_on!(PenpalA, relay_native_asset_location.clone(), &sender); + assets_balance_on!(PenpalA, relay_native_asset_location.clone(), &sender); let receiver_balance_before = test.receiver.balance; // Set assertions and dispatchables @@ -863,11 +871,11 @@ fn reserve_transfer_native_asset_from_para_to_relay() { test.assert(); // Query final balances - let sender_assets_after = foreign_balance_on!(PenpalA, relay_native_asset_location, &sender); + let sender_assets_after = assets_balance_on!(PenpalA, relay_native_asset_location, &sender); let receiver_balance_after = test.receiver.balance; - // Sender's balance is reduced by amount sent plus delivery fees - assert!(sender_assets_after < sender_assets_before - amount_to_send); + // Sender's balance is reduced by amount sent (delivery fees are charged in native tokens). + assert_eq!(sender_assets_after, sender_assets_before - amount_to_send); // Receiver's asset balance is increased assert!(receiver_balance_after > receiver_balance_before); // Receiver's asset balance increased by `amount_to_send - delivery_fees - bought_execution`; @@ -892,6 +900,9 @@ fn reserve_transfer_native_asset_from_asset_hub_to_para() { let system_para_native_asset_location = RelayLocation::get(); let receiver = PenpalAReceiver::get(); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalA, Location::parent(), PenpalAssetOwner::get()); + // Init Test let test_args = TestContext { sender, @@ -910,7 +921,7 @@ fn reserve_transfer_native_asset_from_asset_hub_to_para() { // Query initial balances let sender_balance_before = test.sender.balance; let receiver_assets_before = - foreign_balance_on!(PenpalA, system_para_native_asset_location.clone(), &receiver); + assets_balance_on!(PenpalA, system_para_native_asset_location.clone(), &receiver); // Set assertions and dispatchables test.set_assertion::(system_para_to_para_sender_assertions); @@ -921,7 +932,7 @@ fn reserve_transfer_native_asset_from_asset_hub_to_para() { // Query final balances let sender_balance_after = test.sender.balance; let receiver_assets_after = - foreign_balance_on!(PenpalA, system_para_native_asset_location, &receiver); + assets_balance_on!(PenpalA, system_para_native_asset_location, &receiver); // Sender's balance is reduced by amount sent plus delivery fees assert!(sender_balance_after < sender_balance_before - amount_to_send); @@ -978,7 +989,7 @@ fn reserve_transfer_native_asset_from_para_to_asset_hub() { // Query initial balances let sender_assets_before = - foreign_balance_on!(PenpalA, system_para_native_asset_location.clone(), &sender); + assets_balance_on!(PenpalA, system_para_native_asset_location.clone(), &sender); let receiver_balance_before = test.receiver.balance; // Set assertions and dispatchables @@ -989,11 +1000,11 @@ fn reserve_transfer_native_asset_from_para_to_asset_hub() { // Query final balances let sender_assets_after = - foreign_balance_on!(PenpalA, system_para_native_asset_location, &sender); + assets_balance_on!(PenpalA, system_para_native_asset_location, &sender); let receiver_balance_after = test.receiver.balance; - // Sender's balance is reduced by amount sent plus delivery fees - assert!(sender_assets_after < sender_assets_before - amount_to_send); + // Sender's balance is reduced by amount sent (delivery fees are charged in native) + assert_eq!(sender_assets_after, sender_assets_before - amount_to_send); // Receiver's balance is increased assert!(receiver_balance_after > receiver_balance_before); // Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`; @@ -1046,6 +1057,13 @@ fn reserve_transfer_multiple_assets_from_asset_hub_to_para() { let system_para_native_asset_location = RelayLocation::get(); let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHub::get(); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!( + PenpalA, + system_para_native_asset_location.clone(), + PenpalAssetOwner::get() + ); + // Init Test let para_test_args = TestContext { sender: sender.clone(), @@ -1068,9 +1086,9 @@ fn reserve_transfer_multiple_assets_from_asset_hub_to_para() { >::balance(RESERVABLE_ASSET_ID, &sender) }); let receiver_system_native_assets_before = - foreign_balance_on!(PenpalA, system_para_native_asset_location.clone(), &receiver); + assets_balance_on!(PenpalA, system_para_native_asset_location.clone(), &receiver); let receiver_foreign_assets_before = - foreign_balance_on!(PenpalA, system_para_foreign_asset_location.clone(), &receiver); + assets_balance_on!(PenpalA, system_para_foreign_asset_location.clone(), &receiver); // Set assertions and dispatchables test.set_assertion::(system_para_to_para_assets_sender_assertions); @@ -1085,9 +1103,9 @@ fn reserve_transfer_multiple_assets_from_asset_hub_to_para() { >::balance(RESERVABLE_ASSET_ID, &sender) }); let receiver_system_native_assets_after = - foreign_balance_on!(PenpalA, system_para_native_asset_location, &receiver); + assets_balance_on!(PenpalA, system_para_native_asset_location, &receiver); let receiver_foreign_assets_after = - foreign_balance_on!(PenpalA, system_para_foreign_asset_location.clone(), &receiver); + assets_balance_on!(PenpalA, system_para_foreign_asset_location.clone(), &receiver); // Sender's balance is reduced assert!(sender_balance_after < sender_balance_before); // Receiver's foreign asset balance is increased @@ -1189,9 +1207,9 @@ fn reserve_transfer_multiple_assets_from_para_to_asset_hub() { // Query initial balances let sender_system_assets_before = - foreign_balance_on!(PenpalA, system_asset_location_on_penpal.clone(), &sender); + assets_balance_on!(PenpalA, system_asset_location_on_penpal.clone(), &sender); let sender_foreign_assets_before = - foreign_balance_on!(PenpalA, asset_location_on_penpal.clone(), &sender); + assets_balance_on!(PenpalA, asset_location_on_penpal.clone(), &sender); let receiver_balance_before = test.receiver.balance; let receiver_assets_before = AssetHubWestend::execute_with(|| { type Assets = ::Assets; @@ -1206,9 +1224,9 @@ fn reserve_transfer_multiple_assets_from_para_to_asset_hub() { // Query final balances let sender_system_assets_after = - foreign_balance_on!(PenpalA, system_asset_location_on_penpal, &sender); + assets_balance_on!(PenpalA, system_asset_location_on_penpal, &sender); let sender_foreign_assets_after = - foreign_balance_on!(PenpalA, asset_location_on_penpal, &sender); + assets_balance_on!(PenpalA, asset_location_on_penpal, &sender); let receiver_balance_after = test.receiver.balance; let receiver_assets_after = AssetHubWestend::execute_with(|| { type Assets = ::Assets; @@ -1254,6 +1272,19 @@ fn reserve_transfer_native_asset_from_para_to_para_through_relay() { amount_to_send * 2, ); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!( + PenpalA, + relay_native_asset_location.clone(), + PenpalAssetOwner::get() + ); + + create_foreign_pool_with_native_on!( + PenpalB, + relay_native_asset_location.clone(), + PenpalAssetOwner::get() + ); + // fund the Parachain Origin's SA on Relay Chain with the native tokens held in reserve Westend::fund_accounts(vec![(sov_of_sender_on_relay.into(), amount_to_send * 2)]); @@ -1270,9 +1301,9 @@ fn reserve_transfer_native_asset_from_para_to_para_through_relay() { // Query initial balances let sender_assets_before = - foreign_balance_on!(PenpalA, relay_native_asset_location.clone(), &sender); + assets_balance_on!(PenpalA, relay_native_asset_location.clone(), &sender); let receiver_assets_before = - foreign_balance_on!(PenpalB, relay_native_asset_location.clone(), &receiver); + assets_balance_on!(PenpalB, relay_native_asset_location.clone(), &receiver); // Set assertions and dispatchables test.set_assertion::(para_to_para_through_hop_sender_assertions); @@ -1283,12 +1314,11 @@ fn reserve_transfer_native_asset_from_para_to_para_through_relay() { // Query final balances let sender_assets_after = - foreign_balance_on!(PenpalA, relay_native_asset_location.clone(), &sender); - let receiver_assets_after = - foreign_balance_on!(PenpalB, relay_native_asset_location, &receiver); + assets_balance_on!(PenpalA, relay_native_asset_location.clone(), &sender); + let receiver_assets_after = assets_balance_on!(PenpalB, relay_native_asset_location, &receiver); - // Sender's balance is reduced by amount sent plus delivery fees. - assert!(sender_assets_after < sender_assets_before - amount_to_send); + // Sender's balance is reduced by amount sent (delivery fees are charged in native). + assert_eq!(sender_assets_after, sender_assets_before - amount_to_send); // Receiver's balance is increased by `amount_to_send` minus delivery fees. assert!(receiver_assets_after > receiver_assets_before); assert!(receiver_assets_after < receiver_assets_before + amount_to_send); @@ -1325,7 +1355,11 @@ fn reserve_transfer_usdt_from_asset_hub_to_para() { // Setup the pool between `relay_asset_penpal_pov` and `usdt_from_asset_hub` on PenpalA. // So we can swap the custom asset that comes from AssetHubWestend for native asset to pay for // fees. - create_pool_with_wnd_on!(PenpalA, PenpalUsdtFromAssetHub::get(), true, PenpalAssetOwner::get()); + create_foreign_pool_with_native_on!( + PenpalA, + PenpalUsdtFromAssetHub::get(), + PenpalAssetOwner::get() + ); let assets: Assets = vec![( [PalletInstance(ASSETS_PALLET_ID), GeneralIndex(usdt_id.into())], @@ -1357,7 +1391,7 @@ fn reserve_transfer_usdt_from_asset_hub_to_para() { Balances::free_balance(&sender) }); let receiver_initial_balance = - foreign_balance_on!(PenpalA, usdt_from_asset_hub.clone(), &receiver); + assets_balance_on!(PenpalA, usdt_from_asset_hub.clone(), &receiver); test.set_assertion::(system_para_to_para_sender_assertions); test.set_assertion::(system_para_to_penpal_receiver_assertions); @@ -1372,7 +1406,7 @@ fn reserve_transfer_usdt_from_asset_hub_to_para() { type Balances = ::Balances; Balances::free_balance(&sender) }); - let receiver_after_balance = foreign_balance_on!(PenpalA, usdt_from_asset_hub, &receiver); + let receiver_after_balance = assets_balance_on!(PenpalA, usdt_from_asset_hub, &receiver); // TODO(https://github.com/paritytech/polkadot-sdk/issues/5160): When we allow payment with different assets locally, this should be the same, since // they aren't used for fees. @@ -1428,15 +1462,19 @@ fn reserve_transfer_usdt_from_para_to_para_through_asset_hub() { 0, [Junction::PalletInstance(ASSETS_PALLET_ID), Junction::GeneralIndex(usdt_id.into())], ); - create_pool_with_wnd_on!(AssetHubWestend, usdt, false, AssetHubWestendSender::get()); + create_pool_with_relay_native_on!(AssetHubWestend, usdt, AssetHubWestendSender::get()); // We also need a pool between WND and USDT on PenpalB. - create_pool_with_wnd_on!(PenpalB, PenpalUsdtFromAssetHub::get(), true, PenpalAssetOwner::get()); + create_foreign_pool_with_native_on!( + PenpalB, + PenpalUsdtFromAssetHub::get(), + PenpalAssetOwner::get() + ); let usdt_from_asset_hub = PenpalUsdtFromAssetHub::get(); PenpalA::execute_with(|| { use frame_support::traits::tokens::fungibles::Mutate; - type ForeignAssets = ::ForeignAssets; - assert_ok!(>::mint_into( + type Assets = ::Assets; + assert_ok!(>::mint_into( usdt_from_asset_hub.clone(), &sender, asset_amount_to_send + fee_amount_to_send, @@ -1478,9 +1516,9 @@ fn reserve_transfer_usdt_from_para_to_para_through_asset_hub() { let mut test = ParaToParaThroughAHTest::new(test_args); // Query initial balances - let sender_assets_before = foreign_balance_on!(PenpalA, usdt_from_asset_hub.clone(), &sender); + let sender_assets_before = assets_balance_on!(PenpalA, usdt_from_asset_hub.clone(), &sender); let receiver_assets_before = - foreign_balance_on!(PenpalB, usdt_from_asset_hub.clone(), &receiver); + assets_balance_on!(PenpalB, usdt_from_asset_hub.clone(), &receiver); test.set_assertion::(para_to_para_through_hop_sender_assertions); test.set_assertion::(para_to_para_asset_hub_hop_assertions); test.set_assertion::(para_to_para_through_hop_receiver_assertions); @@ -1490,8 +1528,8 @@ fn reserve_transfer_usdt_from_para_to_para_through_asset_hub() { test.assert(); // Query final balances - let sender_assets_after = foreign_balance_on!(PenpalA, usdt_from_asset_hub.clone(), &sender); - let receiver_assets_after = foreign_balance_on!(PenpalB, usdt_from_asset_hub, &receiver); + let sender_assets_after = assets_balance_on!(PenpalA, usdt_from_asset_hub.clone(), &sender); + let receiver_assets_after = assets_balance_on!(PenpalB, usdt_from_asset_hub, &receiver); // Sender's balance is reduced by amount assert!(sender_assets_after < sender_assets_before - asset_amount_to_send); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs index a941e825bdea6..78af6a706a712 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{create_pool_with_wnd_on, imports::*}; +use crate::imports::*; /// Relay Chain should be able to execute `Transact` instructions in System Parachain /// when `OriginKind::Superuser`. @@ -156,10 +156,9 @@ fn send_xcm_from_para_to_asset_hub_paying_fee_with_sufficient_asset() { ASSET_HUB_WESTEND_ED * 10000000000, )]); - create_pool_with_wnd_on!( + create_pool_with_relay_native_on!( AssetHubWestend, asset_location, - false, para_sovereign_account.clone(), 9_000_000_000_000_000, 9_000_000_000_000 diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs index c32bec7021814..c5d8395c1a0a0 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs @@ -113,13 +113,7 @@ fn swap_locally_on_chain_using_local_assets() { #[test] fn swap_locally_on_chain_using_foreign_assets() { let asset_native = Box::new(Location::try_from(RelayLocation::get()).unwrap()); - let asset_location_on_penpal = PenpalA::execute_with(|| { - Location::try_from(PenpalLocalTeleportableToAssetHub::get()).unwrap() - }); - let foreign_asset_at_asset_hub_westend = - Location::new(1, [Junction::Parachain(PenpalA::para_id().into())]) - .appended_with(asset_location_on_penpal) - .unwrap(); + let foreign_asset_at_asset_hub_westend = PenpalALocation::get(); let penpal_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalA::para_id()); let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of(penpal_as_seen_by_ah); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index 34e538f1e1a7e..888dbe81e41c2 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{foreign_balance_on, imports::*}; +use crate::{assets_balance_on, foreign_balance_on, imports::*}; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -38,22 +38,40 @@ fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) { non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); PenpalA::assert_xcm_pallet_attempted_complete(None); - assert_expected_events!( - PenpalA, - vec![ - RuntimeEvent::ForeignAssets( - pallet_assets::Event::Burned { asset_id, owner, .. } - ) => { - asset_id: *asset_id == system_para_native_asset_location, - owner: *owner == t.sender.account_id, - }, - RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { - asset_id: *asset_id == expected_asset_id, - owner: *owner == t.sender.account_id, - balance: *balance == expected_asset_amount, - }, - ] - ); + if expected_asset_id != Location::here() { + assert_expected_events!( + PenpalA, + vec![ + RuntimeEvent::Assets( + pallet_assets::Event::Burned { asset_id, owner, .. } + ) => { + asset_id: *asset_id == system_para_native_asset_location, + owner: *owner == t.sender.account_id, + }, + RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { + asset_id: *asset_id == expected_asset_id, + owner: *owner == t.sender.account_id, + balance: *balance == expected_asset_amount, + }, + ] + ); + } else { + assert_expected_events!( + PenpalA, + vec![ + RuntimeEvent::Balances(pallet_balances::Event::Burned { who, amount }) => { + who: *who == t.sender.account_id, + amount: *amount == expected_asset_amount, + }, + RuntimeEvent::Assets( + pallet_assets::Event::Burned { asset_id, owner, .. } + ) => { + asset_id: *asset_id == system_para_native_asset_location, + owner: *owner == t.sender.account_id, + }, + ] + ); + } } fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { @@ -81,7 +99,7 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { who: *who == t.receiver.account_id, }, RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { - asset_id: *asset_id == PenpalATeleportableAssetLocation::get(), + asset_id: *asset_id == PenpalAPen2TeleportableAssetLocation::get(), owner: *owner == t.receiver.account_id, amount: *amount == expected_foreign_asset_amount, }, @@ -118,28 +136,46 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) { PenpalA::assert_xcmp_queue_success(None); - assert_expected_events!( - PenpalA, - vec![ - // checking account burns local asset as part of incoming teleport - RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { - asset_id: *asset_id == expected_asset_id, - owner: *owner == checking_account, - balance: *balance == expected_asset_amount, - }, - // local asset is teleported into account of receiver - RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { - asset_id: *asset_id == expected_asset_id, - owner: *owner == t.receiver.account_id, - amount: *amount == expected_asset_amount, - }, - // native asset for fee is deposited to receiver - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == system_para_native_asset_location, - owner: *owner == t.receiver.account_id, - }, - ] - ); + if expected_asset_id != Location::here() { + assert_expected_events!( + PenpalA, + vec![ + // checking account burns local asset as part of incoming teleport + RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { + asset_id: *asset_id == expected_asset_id, + owner: *owner == checking_account, + balance: *balance == expected_asset_amount, + }, + // local asset is teleported into account of receiver + RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { + asset_id: *asset_id == expected_asset_id, + owner: *owner == t.receiver.account_id, + amount: *amount == expected_asset_amount, + }, + // relay chain native asset for fee is deposited to receiver + RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + asset_id: *asset_id == system_para_native_asset_location, + owner: *owner == t.receiver.account_id, + }, + ] + ); + } else { + assert_expected_events!( + PenpalA, + vec![ + // local asset is teleported into account of receiver + RuntimeEvent::Balances(pallet_balances::Event::Minted { who, amount }) => { + who: *who == t.receiver.account_id, + amount: *amount == expected_asset_amount, + }, + // relay chain native asset for fee is deposited to receiver + RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + asset_id: *asset_id == system_para_native_asset_location, + owner: *owner == t.receiver.account_id, + }, + ] + ); + } } fn relay_to_system_para_limited_teleport_assets(t: RelayToSystemParaTest) -> DispatchResult { @@ -515,12 +551,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using ) { // Init values for Parachain let fee_amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000; - let asset_location_on_penpal = - PenpalA::execute_with(|| PenpalLocalTeleportableToAssetHub::get()); - let asset_id_on_penpal = match asset_location_on_penpal.last() { - Some(Junction::GeneralIndex(id)) => *id as u32, - _ => unreachable!(), - }; + let asset_location_on_penpal = PenpalA::execute_with(|| PenpalLocalPen2Asset::get()); let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 1000; let asset_owner = PenpalAssetOwner::get(); let system_para_native_asset_location = RelayLocation::get(); @@ -545,10 +576,18 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using sender.clone(), fee_amount_to_send * 2, ); + + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!( + PenpalA, + system_para_native_asset_location.clone(), + PenpalAssetOwner::get() + ); + // No need to create the asset (only mint) as it exists in genesis. - PenpalA::mint_asset( + PenpalA::mint_foreign_asset( ::RuntimeOrigin::signed(asset_owner.clone()), - asset_id_on_penpal, + asset_location_on_penpal.clone(), sender.clone(), asset_amount_to_send * 2, ); @@ -569,7 +608,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using // Init values for System Parachain let foreign_asset_at_asset_hub = Location::new(1, [Junction::Parachain(PenpalA::para_id().into())]) - .appended_with(asset_location_on_penpal) + .appended_with(asset_location_on_penpal.clone()) .unwrap(); let penpal_to_ah_beneficiary_id = AssetHubWestendReceiver::get(); @@ -582,12 +621,12 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using penpal_to_ah_beneficiary_id, asset_amount_to_send, penpal_assets, - Some(asset_id_on_penpal), + Some(asset_location_on_penpal.clone()), fee_asset_index, ), }; let mut penpal_to_ah = ParaToSystemParaTest::new(penpal_to_ah_test_args); - let penpal_sender_balance_before = foreign_balance_on!( + let penpal_sender_balance_before = assets_balance_on!( PenpalA, system_para_native_asset_location.clone(), &PenpalASender::get() @@ -595,10 +634,8 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let ah_receiver_balance_before = penpal_to_ah.receiver.balance; - let penpal_sender_assets_before = PenpalA::execute_with(|| { - type Assets = ::Assets; - >::balance(asset_id_on_penpal, &PenpalASender::get()) - }); + let penpal_sender_assets_before = + assets_balance_on!(PenpalA, asset_location_on_penpal.clone(), &PenpalASender::get()); let ah_receiver_assets_before = foreign_balance_on!( AssetHubWestend, foreign_asset_at_asset_hub.clone(), @@ -610,7 +647,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using penpal_to_ah.set_dispatchable::(para_to_ah_dispatchable); penpal_to_ah.assert(); - let penpal_sender_balance_after = foreign_balance_on!( + let penpal_sender_balance_after = assets_balance_on!( PenpalA, system_para_native_asset_location.clone(), &PenpalASender::get() @@ -618,10 +655,8 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let ah_receiver_balance_after = penpal_to_ah.receiver.balance; - let penpal_sender_assets_after = PenpalA::execute_with(|| { - type Assets = ::Assets; - >::balance(asset_id_on_penpal, &PenpalASender::get()) - }); + let penpal_sender_assets_after = + assets_balance_on!(PenpalA, asset_location_on_penpal.clone(), &PenpalASender::get()); let ah_receiver_assets_after = foreign_balance_on!( AssetHubWestend, foreign_asset_at_asset_hub.clone(), @@ -683,14 +718,14 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using ah_to_penpal_beneficiary_id, asset_amount_to_send, ah_assets, - Some(asset_id_on_penpal), + Some(asset_location_on_penpal.clone()), fee_asset_index, ), }; let mut ah_to_penpal = SystemParaToParaTest::new(ah_to_penpal_test_args); let ah_sender_balance_before = ah_to_penpal.sender.balance; - let penpal_receiver_balance_before = foreign_balance_on!( + let penpal_receiver_balance_before = assets_balance_on!( PenpalA, system_para_native_asset_location.clone(), &PenpalAReceiver::get() @@ -701,10 +736,8 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using foreign_asset_at_asset_hub.clone(), &AssetHubWestendSender::get() ); - let penpal_receiver_assets_before = PenpalA::execute_with(|| { - type Assets = ::Assets; - >::balance(asset_id_on_penpal, &PenpalAReceiver::get()) - }); + let penpal_receiver_assets_before = + assets_balance_on!(PenpalA, asset_location_on_penpal.clone(), &PenpalAReceiver::get()); ah_to_penpal.set_assertion::(ah_to_penpal_foreign_assets_sender_assertions); ah_to_penpal.set_assertion::(ah_to_penpal_foreign_assets_receiver_assertions); @@ -713,17 +746,15 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let ah_sender_balance_after = ah_to_penpal.sender.balance; let penpal_receiver_balance_after = - foreign_balance_on!(PenpalA, system_para_native_asset_location, &PenpalAReceiver::get()); + assets_balance_on!(PenpalA, system_para_native_asset_location, &PenpalAReceiver::get()); let ah_sender_assets_after = foreign_balance_on!( AssetHubWestend, foreign_asset_at_asset_hub.clone(), &AssetHubWestendSender::get() ); - let penpal_receiver_assets_after = PenpalA::execute_with(|| { - type Assets = ::Assets; - >::balance(asset_id_on_penpal, &PenpalAReceiver::get()) - }); + let penpal_receiver_assets_after = + assets_balance_on!(PenpalA, asset_location_on_penpal.clone(), &PenpalAReceiver::get()); // Sender's balance is reduced assert!(ah_sender_balance_after < ah_sender_balance_before); @@ -767,15 +798,15 @@ fn teleport_to_untrusted_chain_fails() { // this should fail AssetHubWestend::execute_with(|| { let result = ::PolkadotXcm::transfer_assets_using_type_and_then( - signed_origin.clone(), - bx!(destination.clone().into()), - bx!(assets.clone().into()), - bx!(TransferType::Teleport), - bx!(fee_id.into()), - bx!(TransferType::Teleport), - bx!(VersionedXcm::from(Xcm::<()>::new())), - Unlimited, - ); + signed_origin.clone(), + bx!(destination.clone().into()), + bx!(assets.clone().into()), + bx!(TransferType::Teleport), + bx!(fee_id.into()), + bx!(TransferType::Teleport), + bx!(VersionedXcm::from(Xcm::<()>::new())), + Unlimited, + ); assert_err!( result, DispatchError::Module(sp_runtime::ModuleError { diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/transact.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/transact.rs index 6ebcb621f0687..6f4e92225fce4 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/transact.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/transact.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{assets_balance_on, create_pool_with_wnd_on, foreign_balance_on, imports::*}; +use crate::{assets_balance_on, imports::*}; use frame_support::traits::tokens::fungibles::Mutate; use xcm_builder::{DescribeAllTerminal, DescribeFamily, HashedDescription}; use xcm_executor::traits::ConvertLocation; @@ -113,23 +113,30 @@ fn transact_from_para_to_para_through_asset_hub() { // We create a pool between WND and USDT in AssetHub. let usdt = Location::new(0, [PalletInstance(ASSETS_PALLET_ID), GeneralIndex(USDT_ID.into())]); - create_pool_with_wnd_on!( + create_pool_with_relay_native_on!( AssetHubWestend, usdt, - false, AssetHubWestendSender::get(), 1_000_000_000_000, 20_000_000_000 ); - // We also need a pool between WND and USDT on PenpalA. - create_pool_with_wnd_on!(PenpalA, PenpalUsdtFromAssetHub::get(), true, PenpalAssetOwner::get()); - // We also need a pool between WND and USDT on PenpalB. - create_pool_with_wnd_on!(PenpalB, PenpalUsdtFromAssetHub::get(), true, PenpalAssetOwner::get()); + // We also need a pool between the native currency on PenpalA and USDT on PenpalA. + create_foreign_pool_with_native_on!( + PenpalA, + PenpalUsdtFromAssetHub::get(), + PenpalAssetOwner::get() + ); + // We also need a pool between the native currency on PenpalB and USDT on PenpalB. + create_foreign_pool_with_native_on!( + PenpalB, + PenpalUsdtFromAssetHub::get(), + PenpalAssetOwner::get() + ); let usdt_from_asset_hub = PenpalUsdtFromAssetHub::get(); PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - assert_ok!(>::mint_into( + type Assets = ::Assets; + assert_ok!(>::mint_into( usdt_from_asset_hub.clone(), &sender, fee_amount_to_send, @@ -148,9 +155,9 @@ fn transact_from_para_to_para_through_asset_hub() { let receiver = PenpalBReceiver::get(); // Query initial balances - let sender_assets_before = foreign_balance_on!(PenpalA, usdt_from_asset_hub.clone(), &sender); + let sender_assets_before = assets_balance_on!(PenpalA, usdt_from_asset_hub.clone(), &sender); let receiver_assets_before = - foreign_balance_on!(PenpalB, usdt_from_asset_hub.clone(), &receiver); + assets_balance_on!(PenpalB, usdt_from_asset_hub.clone(), &receiver); // Now register a new asset on PenpalB from PenpalA/sender account while paying fees using USDT // (going through Asset Hub) @@ -192,8 +199,8 @@ fn transact_from_para_to_para_through_asset_hub() { }); // Query final balances - let sender_assets_after = foreign_balance_on!(PenpalA, usdt_from_asset_hub.clone(), &sender); - let receiver_assets_after = foreign_balance_on!(PenpalB, usdt_from_asset_hub, &receiver); + let sender_assets_after = assets_balance_on!(PenpalA, usdt_from_asset_hub.clone(), &sender); + let receiver_assets_after = assets_balance_on!(PenpalB, usdt_from_asset_hub, &receiver); // Sender's balance is reduced by amount assert_eq!(sender_assets_after, sender_assets_before - fee_amount_to_send); @@ -241,11 +248,13 @@ fn transact_using_authorized_alias_from_para_to_asset_hub_and_back_to_para() { amount_of_wnd_to_transfer_to_ah, ); + // Create a pool to pay fees with WND + create_foreign_pool_with_native_on!(PenpalA, RelayLocation::get(), PenpalAssetOwner::get()); + // We create a pool between WND and USDT in AssetHub so we can do the exchange - create_pool_with_wnd_on!( + create_pool_with_relay_native_on!( AssetHubWestend, usdt_asset_hub_pov.clone(), - false, AssetHubWestendSender::get(), 1_000_000_000_000, 20_000_000_000 @@ -263,7 +272,7 @@ fn transact_using_authorized_alias_from_para_to_asset_hub_and_back_to_para() { // Query initial balances let sender_usdt_on_penpal_before = - foreign_balance_on!(PenpalA, usdt_penpal_pov.clone(), &sender); + assets_balance_on!(PenpalA, usdt_penpal_pov.clone(), &sender); let sender_usdt_on_ah_before = assets_balance_on!(AssetHubWestend, USDT_ID, &sender); // Encoded `swap_tokens_for_exact_tokens` call to be executed in AH @@ -408,8 +417,7 @@ fn transact_using_authorized_alias_from_para_to_asset_hub_and_back_to_para() { // Query final balances let sender_usdt_on_ah_after = assets_balance_on!(AssetHubWestend, USDT_ID, &sender); - let sender_usdt_on_penpal_after = - foreign_balance_on!(PenpalA, usdt_penpal_pov.clone(), &sender); + let sender_usdt_on_penpal_after = assets_balance_on!(PenpalA, usdt_penpal_pov.clone(), &sender); // Receiver's balance is increased by usdt amount we got from exchange assert_eq!( @@ -463,11 +471,13 @@ fn transact_using_sov_account_from_para_to_asset_hub_and_back_to_para() { amount_of_wnd_to_transfer_to_ah, ); + // Create a pool to pay fees with WND + create_foreign_pool_with_native_on!(PenpalA, RelayLocation::get(), PenpalAssetOwner::get()); + // We create a pool between WND and USDT in AssetHub so we can do the exchange - create_pool_with_wnd_on!( + create_pool_with_relay_native_on!( AssetHubWestend, usdt_asset_hub_pov.clone(), - false, AssetHubWestendSender::get(), 1_000_000_000_000, 20_000_000_000 @@ -475,7 +485,7 @@ fn transact_using_sov_account_from_para_to_asset_hub_and_back_to_para() { // Query initial balances let sender_usdt_on_penpal_before = - foreign_balance_on!(PenpalA, usdt_penpal_pov.clone(), &sender); + assets_balance_on!(PenpalA, usdt_penpal_pov.clone(), &sender); let sender_usdt_on_ah_before = assets_balance_on!(AssetHubWestend, USDT_ID, &sov_of_sender_on_asset_hub); @@ -619,8 +629,7 @@ fn transact_using_sov_account_from_para_to_asset_hub_and_back_to_para() { // Query final balances let sender_usdt_on_ah_after = assets_balance_on!(AssetHubWestend, USDT_ID, &sov_of_sender_on_asset_hub); - let sender_usdt_on_penpal_after = - foreign_balance_on!(PenpalA, usdt_penpal_pov.clone(), &sender); + let sender_usdt_on_penpal_after = assets_balance_on!(PenpalA, usdt_penpal_pov.clone(), &sender); // Receiver's balance is increased by usdt amount we got from exchange assert_eq!( @@ -660,7 +669,7 @@ fn penpal_b_assertions( assert_expected_events!( PenpalB, vec![ - RuntimeEvent::ForeignAssets( + RuntimeEvent::Assets( pallet_assets::Event::Created { asset_id, creator, owner } ) => { asset_id: *asset_id == expected_asset, diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/xcm_fee_estimation.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/xcm_fee_estimation.rs index 3fc49ae4e6f20..e5c0671878682 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/xcm_fee_estimation.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/xcm_fee_estimation.rs @@ -15,10 +15,8 @@ //! Tests to ensure correct XCM fee estimation for cross-chain asset transfers. -use crate::{create_pool_with_wnd_on, imports::*}; - -use emulated_integration_tests_common::test_can_estimate_and_pay_exact_fees; -use frame_support::dispatch::RawOrigin; +use crate::imports::*; +use frame_support::{dispatch::RawOrigin, traits::fungible}; use xcm_runtime_apis::{ dry_run::runtime_decl_for_dry_run_api::DryRunApiV2, fees::runtime_decl_for_xcm_payment_api::XcmPaymentApiV2, @@ -82,7 +80,7 @@ fn sender_assertions(test: ParaToParaThroughAHTest) { assert_expected_events!( PenpalA, vec![ - RuntimeEvent::ForeignAssets( + RuntimeEvent::Assets( pallet_assets::Event::Burned { asset_id, owner, balance } ) => { asset_id: *asset_id == Location::new(1, []), @@ -103,7 +101,7 @@ fn hop_assertions(test: ParaToParaThroughAHTest) { RuntimeEvent::Balances( pallet_balances::Event::Burned { amount, .. } ) => { - amount: *amount >= test.args.amount * 90/100, + amount: *amount >= test.args.amount * 80/100, }, ] ); @@ -116,7 +114,7 @@ fn receiver_assertions(test: ParaToParaThroughAHTest) { assert_expected_events!( PenpalB, vec![ - RuntimeEvent::ForeignAssets( + RuntimeEvent::Assets( pallet_assets::Event::Issued { asset_id, owner, .. } ) => { asset_id: *asset_id == Location::new(1, []), @@ -165,7 +163,7 @@ fn multi_hop_works() { let sender = PenpalASender::get(); let amount_to_send = 1_000_000_000_000; let asset_owner = PenpalAssetOwner::get(); - let assets: Assets = (Parent, amount_to_send).into(); + let relay_native_assets: Assets = (Parent, amount_to_send).into(); let relay_native_asset_location = Location::parent(); let sender_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalA::para_id()); let sov_of_sender_on_ah = @@ -179,6 +177,18 @@ fn multi_hop_works() { amount_to_send * 2, ); + create_foreign_pool_with_native_on!( + PenpalA, + relay_native_asset_location.clone(), + PenpalAssetOwner::get() + ); + + create_foreign_pool_with_native_on!( + PenpalB, + relay_native_asset_location.clone(), + PenpalAssetOwner::get() + ); + // fund the Parachain Origin's SA on AssetHub with the native tokens held in reserve. AssetHubWestend::fund_accounts(vec![(sov_of_sender_on_ah.clone(), amount_to_send * 2)]); @@ -192,7 +202,7 @@ fn multi_hop_works() { destination, beneficiary_id.clone(), amount_to_send, - assets, + relay_native_assets, None, 0, ), @@ -219,7 +229,7 @@ fn multi_hop_works() { .unwrap(); assert_eq!(messages_to_query.len(), 1); remote_message = messages_to_query[0].clone(); - let asset_id_for_delivery_fees = VersionedAssetId::from(Location::parent()); + let asset_id_for_delivery_fees = VersionedAssetId::from(Location::here()); let delivery_fees = Runtime::query_delivery_fees( destination_to_query.clone(), remote_message.clone(), @@ -239,11 +249,9 @@ fn multi_hop_works() { // First we get the execution fees. let weight = Runtime::query_xcm_weight(remote_message.clone()).unwrap(); - intermediate_execution_fees = Runtime::query_weight_to_asset_fee( - weight, - VersionedAssetId::from(AssetId(Location::new(1, []))), - ) - .unwrap(); + intermediate_execution_fees = + Runtime::query_weight_to_asset_fee(weight, VersionedAssetId::from(Location::parent())) + .unwrap(); // We have to do this to turn `VersionedXcm<()>` into `VersionedXcm`. let xcm_program = VersionedXcm::from(Xcm::::from( @@ -276,17 +284,6 @@ fn multi_hop_works() { intermediate_delivery_fees_amount = get_amount_from_versioned_assets(delivery_fees); }); - // Get the final execution fees in the destination. - let mut final_execution_fees = 0; - ::execute_with(|| { - type Runtime = ::Runtime; - - let weight = Runtime::query_xcm_weight(intermediate_remote_message.clone()).unwrap(); - final_execution_fees = - Runtime::query_weight_to_asset_fee(weight, VersionedAssetId::from(Location::parent())) - .unwrap(); - }); - // Dry-running is done. PenpalA::reset_ext(); AssetHubWestend::reset_ext(); @@ -299,16 +296,52 @@ fn multi_hop_works() { sender.clone(), amount_to_send * 2, ); + + create_foreign_pool_with_native_on!( + PenpalA, + relay_native_asset_location.clone(), + PenpalAssetOwner::get() + ); + + create_foreign_pool_with_native_on!( + PenpalB, + relay_native_asset_location.clone(), + PenpalAssetOwner::get() + ); + + // Get the final execution fees at the destination. + // + // Note: We need to do this after resetting the externalities to get an accurate value here. + // This is because the dry-run on Asset Hub does affect the liquidity pool distribution on + // PenpalB which affects the assets amount we have to pay. + let mut final_execution_fees = 0; + ::execute_with(|| { + type Runtime = ::Runtime; + + let weight = Runtime::query_xcm_weight(intermediate_remote_message.clone()).unwrap(); + final_execution_fees = + Runtime::query_weight_to_asset_fee(weight, VersionedAssetId::from(Location::parent())) + .unwrap(); + }); + AssetHubWestend::fund_accounts(vec![(sov_of_sender_on_ah, amount_to_send * 2)]); // Actually run the extrinsic. let sender_assets_before = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &sender) + type Assets = ::Assets; + >::balance(relay_native_asset_location.clone(), &sender) + }); + let sender_balance_before = PenpalA::execute_with(|| { + type Balances = ::Balances; + >::balance(&sender) }); let receiver_assets_before = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &beneficiary_id) + type Assets = ::Assets; + >::balance(relay_native_asset_location.clone(), &beneficiary_id) + }); + let receiver_balance_before = PenpalB::execute_with(|| { + type Balances = ::Balances; + >::balance(&beneficiary_id) }); test.set_assertion::(sender_assertions); @@ -319,21 +352,32 @@ fn multi_hop_works() { test.assert(); let sender_assets_after = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &sender) + type Assets = ::Assets; + >::balance(relay_native_asset_location.clone(), &sender) + }); + let sender_balance_after = PenpalA::execute_with(|| { + type Balances = ::Balances; + >::balance(&sender) }); let receiver_assets_after = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location, &beneficiary_id) + type Assets = ::Assets; + >::balance(relay_native_asset_location, &beneficiary_id) + }); + let receiver_balance_after = PenpalB::execute_with(|| { + type Balances = ::Balances; + >::balance(&beneficiary_id) }); // We know the exact fees on every hop. + assert_eq!(sender_assets_after, sender_assets_before - amount_to_send); assert_eq!( - sender_assets_after, - sender_assets_before - amount_to_send - delivery_fees_amount /* This is charged directly - * from the sender's - * account. */ + sender_balance_after, + // This is charged directly from the sender's account. + sender_balance_before - delivery_fees_amount ); + + // Receiver native balance is unchanged; received funds in relay asset, and paid in relay asset. + assert_eq!(receiver_balance_after, receiver_balance_before); assert_eq!( receiver_assets_after, receiver_assets_before + amount_to_send - @@ -395,10 +439,9 @@ fn usdt_fee_estimation_in_usdt_works() { // Create a liquidity pool between WND (relay token) and USDT on AssetHub // This is needed for the asset conversion in fee estimation - create_pool_with_wnd_on!( + create_pool_with_relay_native_on!( AssetHubWestend, usdt_location_on_ah.clone(), - false, AssetHubWestendSender::get(), 1_000_000_000_000, // 1 WND 2_000_000 // 2 USDT (1:2 ratio) @@ -406,10 +449,9 @@ fn usdt_fee_estimation_in_usdt_works() { // Create a liquidity pool between WND and USDT on PenpalA as well // This is needed for PenpalA to perform asset conversion for fee estimation - create_pool_with_wnd_on!( + create_foreign_pool_with_native_on!( PenpalA, usdt_location_on_penpal.clone(), - true, PenpalAssetOwner::get(), 1_000_000_000_000, // 1 WND 2_000_000 // 2 USDT (1:2 ratio) diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs index c3820245526cb..01bc840f6ecf7 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs @@ -382,8 +382,8 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend() let rocs_in_reserve_on_ahr_before = ::account_data_of(sov_ahw_on_ahr.clone()).free; let sender_rocs_before = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_rococo_parachains.clone(), &sender) + type Assets = ::Assets; + >::balance(roc_at_rococo_parachains.clone(), &sender) }); let receiver_rocs_before = foreign_balance_on_ah_westend(roc_at_asset_hub_westend.clone(), &receiver); @@ -430,8 +430,8 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend() }); let sender_rocs_after = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_rococo_parachains, &sender) + type Assets = ::Assets; + >::balance(roc_at_rococo_parachains, &sender) }); let receiver_rocs_after = foreign_balance_on_ah_westend(roc_at_asset_hub_westend, &receiver); let rocs_in_reserve_on_ahr_after = @@ -491,8 +491,8 @@ fn send_back_wnds_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_weste // balances before let sender_wnds_before = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(wnd_at_rococo_parachains.clone().into(), &sender) + type Assets = ::Assets; + >::balance(wnd_at_rococo_parachains.clone().into(), &sender) }); let receiver_wnds_before = ::account_data_of(receiver.clone()).free; @@ -562,8 +562,8 @@ fn send_back_wnds_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_weste }); let sender_wnds_after = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(wnd_at_rococo_parachains.into(), &sender) + type Assets = ::Assets; + >::balance(wnd_at_rococo_parachains.into(), &sender) }); let receiver_wnds_after = ::account_data_of(receiver).free; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs index acad1acf1583b..18b3ff0abde46 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs @@ -33,15 +33,15 @@ mod imports { // Cumulus pub(crate) use emulated_integration_tests_common::{ accounts::ALICE, - create_pool_with_native_on, - impls::Inspect, + create_foreign_pool_with_native_on, create_foreign_pool_with_parent_native_on, + impls::{Decode, Inspect}, test_dry_run_transfer_across_pk_bridge, test_parachain_is_trusted_teleporter, test_parachain_is_trusted_teleporter_for_relay, test_relay_is_trusted_teleporter, xcm_emulator::{ assert_expected_events, bx, Chain, Parachain as Para, RelayChain as Relay, TestExt, }, xcm_helpers::xcm_transact_paid_execution, - ASSETS_PALLET_ID, USDT_ID, + PenpalBLocation, ASSETS_PALLET_ID, USDT_ID, }; pub(crate) use parachains_common::AccountId; pub(crate) use rococo_westend_system_emulated_network::{ @@ -62,8 +62,9 @@ mod imports { penpal_emulated_chain::{ self, penpal_runtime::xcm_config::{ + CheckingAccount as PenpalCheckingAccount, CustomizableAssetFromSystemAssetHub as PenpalCustomizableAssetFromSystemAssetHub, - LocalTeleportableToAssetHub as PenpalLocalTeleportableToAssetHub, + LocalPen2Asset as PenpalLocalPen2Asset, PenpalNativeCurrency, UniversalLocation as PenpalUniversalLocation, }, PenpalAParaPallet as PenpalAPallet, PenpalAssetOwner, diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/aliases.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/aliases.rs index 67dc541ce01b4..47ad7a3ce0a24 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/aliases.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/aliases.rs @@ -32,7 +32,7 @@ fn account_on_sibling_syschain_aliases_into_same_local_account() { // origin and target are the same account on different chains let origin: AccountId = [1; 32].into(); let target = origin.clone(); - let fees = WESTEND_ED * 10; + let fees = WESTEND_ED * 20; PenpalB::mint_foreign_asset( ::RuntimeOrigin::signed(PenpalAssetOwner::get()), @@ -41,6 +41,9 @@ fn account_on_sibling_syschain_aliases_into_same_local_account() { fees * 10, ); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + // On Bridge Hub we don't want to support aliasing from other chains: there is no real world // demand for it, only low-level power users (like relayers) directly interact with Bridge // Hub. They don't need aliasing to operate cross-chain they can operate locally. @@ -63,7 +66,7 @@ fn account_on_sibling_syschain_cannot_alias_into_different_local_account() { // origin and target are different accounts on different chains let origin: AccountId = [1; 32].into(); let target: AccountId = [2; 32].into(); - let fees = WESTEND_ED * 10; + let fees = WESTEND_ED * 20; PenpalB::mint_foreign_asset( ::RuntimeOrigin::signed(PenpalAssetOwner::get()), @@ -72,6 +75,9 @@ fn account_on_sibling_syschain_cannot_alias_into_different_local_account() { fees * 10, ); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + // Aliasing different account on different chains test_cross_chain_alias!( vec![ @@ -183,13 +189,16 @@ fn authorized_cross_chain_aliases() { let origin: AccountId = [100; 32].into(); let bad_origin: AccountId = [150; 32].into(); let target: AccountId = [200; 32].into(); - let fees = WESTEND_ED * 10; + let fees = WESTEND_ED * 20; let pal_admin = ::RuntimeOrigin::signed(PenpalAssetOwner::get()); PenpalB::mint_foreign_asset(pal_admin.clone(), Location::parent(), origin.clone(), fees * 10); PenpalB::mint_foreign_asset(pal_admin, Location::parent(), bad_origin.clone(), fees * 10); BridgeHubWestend::fund_accounts(vec![(target.clone(), fees * 10)]); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + // let's authorize `origin` on Penpal to alias `target` on BridgeHub BridgeHubWestend::execute_with(|| { let penpal_origin = Location::new( diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs index 0a6f82b04a514..4ec05f22e68e4 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs @@ -15,10 +15,13 @@ use crate::tests::{snowbridge_common::snowbridge_sovereign, *}; use emulated_integration_tests_common::{ + create_foreign_pool_with_native_on, macros::Dmp, xcm_helpers::{find_all_mq_processed_ids, find_mq_processed_id, find_xcm_sent_message_id}, xcm_simulator::helpers::TopicIdTracker, + PenpalBLocation, }; +use frame_support::traits::fungible; use xcm::latest::AssetTransferFilter; fn send_assets_over_bridge(send_fn: F) { @@ -47,10 +50,9 @@ fn set_up_wnds_for_penpal_westend_through_ahw_to_ahr( let wnd_at_asset_hub_rococo = bridged_wnd_at_ah_rococo(); let wnd_reserve = vec![(asset_hub_westend_global_location(), false).into()]; create_foreign_on_ah_rococo(wnd_at_asset_hub_rococo.clone(), true, wnd_reserve); - create_pool_with_native_on!( + create_foreign_pool_with_parent_native_on!( AssetHubRococo, wnd_at_asset_hub_rococo.clone(), - true, AssetHubRococoSender::get() ); @@ -65,6 +67,14 @@ fn set_up_wnds_for_penpal_westend_through_ahw_to_ahr( sender.clone(), amount * 2, ); + + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!( + PenpalB, + wnd_at_westend_parachains.clone(), + PenpalAssetOwner::get() + ); + (wnd_at_westend_parachains, wnd_at_asset_hub_rococo) } @@ -133,10 +143,9 @@ fn send_wnds_usdt_and_weth_from_asset_hub_westend_to_asset_hub_rococo() { let bridged_wnd_at_asset_hub_rococo = bridged_wnd_at_ah_rococo(); let wnd_reserve = vec![(asset_hub_westend_global_location(), false).into()]; create_foreign_on_ah_rococo(bridged_wnd_at_asset_hub_rococo.clone(), true, wnd_reserve); - create_pool_with_native_on!( + create_foreign_pool_with_parent_native_on!( AssetHubRococo, bridged_wnd_at_asset_hub_rococo.clone(), - true, AssetHubRococoSender::get() ); @@ -218,10 +227,9 @@ fn send_wnds_usdt_and_weth_from_asset_hub_westend_to_asset_hub_rococo() { ); let wnd_reserve = vec![(asset_hub_westend_global_location(), false).into()]; create_foreign_on_ah_rococo(bridged_usdt_at_asset_hub_rococo.clone(), true, wnd_reserve); - create_pool_with_native_on!( + create_foreign_pool_with_parent_native_on!( AssetHubRococo, bridged_usdt_at_asset_hub_rococo.clone(), - true, AssetHubRococoSender::get() ); @@ -369,8 +377,8 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo() let wnds_in_reserve_on_ahw_before = ::account_data_of(sov_ahr_on_ahw.clone()).free; let sender_wnds_before = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(wnd_at_westend_parachains.clone(), &sender) + type Assets = ::Assets; + >::balance(wnd_at_westend_parachains.clone(), &sender) }); let receiver_wnds_before = foreign_balance_on_ah_rococo(wnd_at_asset_hub_rococo.clone(), &receiver); @@ -416,8 +424,8 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo() }); let sender_wnds_after = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(wnd_at_westend_parachains, &sender) + type Assets = ::Assets; + >::balance(wnd_at_westend_parachains, &sender) }); let receiver_wnds_after = foreign_balance_on_ah_rococo(wnd_at_asset_hub_rococo, &receiver); let wnds_in_reserve_on_ahw_after = @@ -460,7 +468,12 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo_t )], )); }); - create_pool_with_native_on!(PenpalA, wnd_at_rococo_parachains.clone(), true, asset_owner); + + create_foreign_pool_with_native_on!( + PenpalA, + wnd_at_rococo_parachains.clone(), + asset_owner.clone() + ); let sov_ahr_on_ahw = AssetHubWestend::sovereign_account_of_parachain_on_other_global_consensus( ByGenesis(ROCOCO_GENESIS_HASH), @@ -469,11 +482,11 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo_t let wnds_in_reserve_on_ahw_before = ::account_data_of(sov_ahr_on_ahw.clone()).free; let sender_wnds_before = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(wnd_at_westend_parachains.clone(), &sender) + type Assets = ::Assets; + >::balance(wnd_at_westend_parachains.clone(), &sender) }); let receiver_wnds_before = PenpalA::execute_with(|| { - type Assets = ::ForeignAssets; + type Assets = ::Assets; >::balance(wnd_at_rococo_parachains.clone(), &receiver) }); @@ -528,11 +541,11 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo_t }); let sender_wnds_after = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(wnd_at_westend_parachains, &sender) + type Assets = ::Assets; + >::balance(wnd_at_westend_parachains, &sender) }); let receiver_wnds_after = PenpalA::execute_with(|| { - type Assets = ::ForeignAssets; + type Assets = ::Assets; >::balance(wnd_at_rococo_parachains, &receiver) }); let wnds_in_reserve_on_ahw_after = @@ -560,10 +573,9 @@ fn send_wnds_from_westend_relay_through_asset_hub_westend_to_asset_hub_rococo_to // create foreign WND on AH Rococo create_foreign_on_ah_rococo(wnd_at_rococo_parachains.clone(), true, wnd_reserve); - create_pool_with_native_on!( + create_foreign_pool_with_parent_native_on!( AssetHubRococo, wnd_at_rococo_parachains.clone(), - true, AssetHubRococoSender::get() ); // create foreign WND on Penpal Rococo @@ -585,7 +597,11 @@ fn send_wnds_from_westend_relay_through_asset_hub_westend_to_asset_hub_rococo_to )], )); }); - create_pool_with_native_on!(PenpalA, wnd_at_rococo_parachains.clone(), true, asset_owner); + create_foreign_pool_with_native_on!( + PenpalA, + wnd_at_rococo_parachains.clone(), + asset_owner.clone() + ); Westend::execute_with(|| { let root_origin = ::RuntimeOrigin::root(); @@ -609,7 +625,7 @@ fn send_wnds_from_westend_relay_through_asset_hub_westend_to_asset_hub_rococo_to ::account_data_of(sov_ahr_on_ahw.clone()).free; let sender_wnds_before = ::account_data_of(sender.clone()).free; let receiver_wnds_before = PenpalA::execute_with(|| { - type Assets = ::ForeignAssets; + type Assets = ::Assets; >::balance(wnd_at_rococo_parachains.clone(), &receiver) }); @@ -708,7 +724,7 @@ fn send_wnds_from_westend_relay_through_asset_hub_westend_to_asset_hub_rococo_to let sender_wnds_after = ::account_data_of(sender.clone()).free; let receiver_wnds_after = PenpalA::execute_with(|| { - type Assets = ::ForeignAssets; + type Assets = ::Assets; >::balance(wnd_at_rococo_parachains, &receiver) }); let wnds_in_reserve_on_ahw_after = @@ -773,8 +789,8 @@ fn send_back_rocs_from_penpal_westend_through_asset_hub_westend_to_asset_hub_roc // balances before let sender_rocs_before = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.clone().into(), &sender) + type Assets = ::Assets; + >::balance(roc_at_westend_parachains.clone().into(), &sender) }); let receiver_rocs_before = ::account_data_of(receiver.clone()).free; @@ -844,8 +860,8 @@ fn send_back_rocs_from_penpal_westend_through_asset_hub_westend_to_asset_hub_roc }); let sender_rocs_after = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.into(), &sender) + type Assets = ::Assets; + >::balance(roc_at_westend_parachains.into(), &sender) }); let receiver_rocs_after = ::account_data_of(receiver).free; @@ -876,10 +892,9 @@ fn send_back_rocs_from_penpal_westend_through_asset_hub_westend_to_asset_hub_roc reserves, prefund_accounts, ); - create_pool_with_native_on!( + create_foreign_pool_with_parent_native_on!( AssetHubWestend, roc_at_westend_parachains.clone(), - true, AssetHubRococoSender::get() ); let asset_owner: AccountId = AssetHubWestend::account_id_of(ALICE); @@ -890,6 +905,11 @@ fn send_back_rocs_from_penpal_westend_through_asset_hub_westend_to_asset_hub_roc sender.clone(), amount, ); + + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalA, Location::parent(), PenpalAssetOwner::get()); + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + // Create and fund bridged ROCs on Westend Penpal PenpalB::force_create_foreign_asset( roc_at_westend_parachains.clone(), @@ -918,11 +938,11 @@ fn send_back_rocs_from_penpal_westend_through_asset_hub_westend_to_asset_hub_roc // balances before let sender_rocs_before = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.clone().into(), &sender) + type Assets = ::Assets; + >::balance(roc_at_westend_parachains.clone().into(), &sender) }); let receiver_rocs_before = PenpalA::execute_with(|| { - type Assets = ::ForeignAssets; + type Assets = ::Assets; >::balance(roc_at_rococo_parachains.clone(), &receiver) }); @@ -1033,11 +1053,11 @@ fn send_back_rocs_from_penpal_westend_through_asset_hub_westend_to_asset_hub_roc }); let sender_rocs_after = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.into(), &sender) + type Assets = ::Assets; + >::balance(roc_at_westend_parachains.into(), &sender) }); let receiver_rocs_after = PenpalA::execute_with(|| { - type Assets = ::ForeignAssets; + type Assets = ::Assets; >::balance(roc_at_rococo_parachains.clone(), &receiver) }); @@ -1069,10 +1089,9 @@ fn send_back_rocs_from_penpal_westend_through_asset_hub_westend_to_asset_hub_roc reserves, prefund_accounts, ); - create_pool_with_native_on!( + create_foreign_pool_with_parent_native_on!( AssetHubWestend, roc_at_westend_parachains.clone(), - true, AssetHubRococoSender::get() ); let asset_owner: AccountId = AssetHubWestend::account_id_of(ALICE); @@ -1114,8 +1133,8 @@ fn send_back_rocs_from_penpal_westend_through_asset_hub_westend_to_asset_hub_roc // balances before let sender_rocs_before = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.clone().into(), &sender) + type Assets = ::Assets; + >::balance(roc_at_westend_parachains.clone().into(), &sender) }); let receiver_rocs_before = ::account_data_of(receiver.clone()).free; @@ -1236,8 +1255,8 @@ fn send_back_rocs_from_penpal_westend_through_asset_hub_westend_to_asset_hub_roc topic_id_tracker.assert_only_id_seen_on_all_chains("PenpalB"); let sender_rocs_after = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(roc_at_westend_parachains.into(), &sender) + type Assets = ::Assets; + >::balance(roc_at_westend_parachains.into(), &sender) }); let receiver_rocs_after = ::account_data_of(receiver.clone()).free; @@ -1412,23 +1431,9 @@ fn send_pens_and_wnds_from_penpal_westend_via_ahw_to_ahr() { let (wnd_at_westend_parachains, wnd_at_rococo_parachains) = set_up_wnds_for_penpal_westend_through_ahw_to_ahr(&sender, amount); - let pens_location_on_penpal = PenpalB::execute_with(|| { - Location::try_from(PenpalLocalTeleportableToAssetHub::get()).unwrap() - }); - let pens_id_on_penpal = match pens_location_on_penpal.last() { - Some(Junction::GeneralIndex(id)) => *id as u32, - _ => unreachable!(), - }; - - let penpal_parachain_junction = Junction::Parachain(PenpalB::para_id().into()); - let pens_at_ahw = Location::new( - 1, - pens_location_on_penpal - .interior() - .clone() - .pushed_front_with(penpal_parachain_junction) - .unwrap(), - ); + let pens_location_on_penpal = Location::here(); + + let pens_at_ahw = PenpalBLocation::get(); let pens_at_rococo_parachains = Location::new( 2, pens_at_ahw @@ -1443,15 +1448,11 @@ fn send_pens_and_wnds_from_penpal_westend_via_ahw_to_ahr() { let pens_to_send = amount; // ---------- Set up Penpal Westend ---------- - // Fund Penpal's sender account. No need to create the asset (only mint), it exists in genesis. - PenpalB::mint_asset( - ::RuntimeOrigin::signed(owner.clone()), - pens_id_on_penpal, - sender.clone(), - pens_to_send * 2, - ); - // fund Penpal's check account to be able to teleport - PenpalB::fund_accounts(vec![(penpal_check_account.clone().into(), pens_to_send * 2)]); + PenpalB::fund_accounts(vec![ + (sender.clone(), pens_to_send * 2), + // fund Penpal's check account to be able to teleport + (penpal_check_account.clone().into(), pens_to_send * 2), + ]); // ---------- Set up Asset Hub Rococo ---------- // create PEN at AHR @@ -1465,15 +1466,15 @@ fn send_pens_and_wnds_from_penpal_westend_via_ahw_to_ahr() { // account balances before let sender_wnds_before = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance( + type Assets = ::Assets; + >::balance( wnd_at_westend_parachains.clone().into(), &PenpalBSender::get(), ) }); let sender_pens_before = PenpalB::execute_with(|| { - type Assets = ::Assets; - >::balance(pens_id_on_penpal, &PenpalBSender::get()) + type Balances = ::Balances; + >::balance(&PenpalBSender::get()) }); let sov_ahr_on_ahw = AssetHubWestend::sovereign_account_of_parachain_on_other_global_consensus( ByGenesis(ROCOCO_GENESIS_HASH), @@ -1537,15 +1538,13 @@ fn send_pens_and_wnds_from_penpal_westend_via_ahw_to_ahr() { // account balances after let sender_wnds_after = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance( - wnd_at_westend_parachains.into(), - &PenpalBSender::get(), - ) + type Assets = ::Assets; + >::balance(wnd_at_westend_parachains.into(), &PenpalBSender::get()) }); + let sender_pens_after = PenpalB::execute_with(|| { - type Assets = ::Assets; - >::balance(pens_id_on_penpal, &PenpalBSender::get()) + type Balances = ::Balances; + >::balance(&PenpalBSender::get()) }); let wnds_in_reserve_on_ahw_after = ::account_data_of(sov_ahr_on_ahw.clone()).free; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge.rs index 63137cc8b0409..d058c427b55f7 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge.rs @@ -13,12 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. use crate::{ - imports::{ - penpal_emulated_chain::penpal_runtime::xcm_config::{ - CheckingAccount, TELEPORTABLE_ASSET_ID, - }, - *, - }, + imports::*, tests::{ assert_bridge_hub_rococo_message_received, assert_bridge_hub_westend_message_accepted, asset_hub_rococo_location, asset_hub_westend_global_location, bridged_roc_at_ah_westend, @@ -56,7 +51,7 @@ use testnet_parachains_constants::westend::snowbridge::EthereumNetwork; use xcm_builder::ExternalConsensusLocationsConverterFor; use xcm_executor::traits::ConvertLocation; -const INITIAL_FUND: u128 = 5_000_000_000_000; +const INITIAL_FUND: u128 = 6_000_000_000_000; const ETHEREUM_DESTINATION_ADDRESS: [u8; 20] = hex!("44a57ee2f2FCcb85FDa2B0B18EBD0D8D2333700e"); const XCM_FEE: u128 = 100_000_000_000; const INSUFFICIENT_XCM_FEE: u128 = 1000; @@ -174,6 +169,9 @@ fn send_weth_from_ethereum_to_penpal() { // Fund AssetHub sovereign account so it can pay execution fees for the asset transfer BridgeHubWestend::fund_accounts(vec![(asset_hub_sovereign.clone(), INITIAL_FUND)]); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + // Fund PenPal receiver (covering ED) let native_id: Location = Parent.into(); let receiver: AccountId = [ @@ -214,7 +212,7 @@ fn send_weth_from_ethereum_to_penpal() { // Create asset on the Penpal parachain. PenpalB::execute_with(|| { - assert_ok!(::ForeignAssets::force_create( + assert_ok!(::Assets::force_create( ::RuntimeOrigin::root(), weth_asset_location.clone(), asset_hub_sovereign.into(), @@ -222,7 +220,7 @@ fn send_weth_from_ethereum_to_penpal() { 1000, )); - assert!(::ForeignAssets::asset_exists(weth_asset_location)); + assert!(::Assets::asset_exists(weth_asset_location)); }); // Send the token @@ -272,7 +270,7 @@ fn send_weth_from_ethereum_to_penpal() { assert_expected_events!( PenpalB, vec![ - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { .. }) => {}, + RuntimeEvent::Assets(pallet_assets::Event::Issued { .. }) => {}, ] ); }); @@ -714,6 +712,9 @@ fn send_token_from_ethereum_to_penpal() { // Fund PenPal receiver (covering ED) PenpalB::fund_accounts(vec![(PenpalBReceiver::get(), INITIAL_FUND)]); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + PenpalB::execute_with(|| { assert_ok!(::System::set_storage( ::RuntimeOrigin::root(), @@ -736,7 +737,7 @@ fn send_token_from_ethereum_to_penpal() { // Create asset on the Penpal parachain. PenpalB::execute_with(|| { - assert_ok!(::ForeignAssets::force_create( + assert_ok!(::Assets::force_create( ::RuntimeOrigin::root(), weth_asset_location.clone(), asset_hub_sovereign.clone().into(), @@ -744,9 +745,7 @@ fn send_token_from_ethereum_to_penpal() { 1000, )); - assert!(::ForeignAssets::asset_exists( - weth_asset_location.clone() - )); + assert!(::Assets::asset_exists(weth_asset_location.clone())); }); BridgeHubWestend::execute_with(|| { @@ -793,7 +792,7 @@ fn send_token_from_ethereum_to_penpal() { assert_expected_events!( PenpalB, vec![ - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { .. }) => {}, + RuntimeEvent::Assets(pallet_assets::Event::Issued { .. }) => {}, ] ); }); @@ -1143,10 +1142,9 @@ fn send_weth_from_ethereum_to_ahw_to_ahr_back_to_ahw_and_ethereum() { let bridged_wnd_at_asset_hub_rococo = bridged_wnd_at_ah_rococo(); let wnd_reserve = vec![(asset_hub_westend_global_location(), false).into()]; create_foreign_on_ah_rococo(bridged_wnd_at_asset_hub_rococo.clone(), true, wnd_reserve); - create_pool_with_native_on!( + create_foreign_pool_with_parent_native_on!( AssetHubRococo, bridged_wnd_at_asset_hub_rococo.clone(), - true, AssetHubRococoSender::get() ); @@ -1431,22 +1429,6 @@ fn transfer_penpal_native_asset() { let token_id = TokenIdOf::convert_location(&pal_after_reanchored).unwrap(); - let asset_owner = PenpalAssetOwner::get(); - - AssetHubWestend::force_create_foreign_asset( - pal_at_asset_hub.clone(), - asset_owner.clone().into(), - true, - 1, - vec![], - ); - // Set "pal" as teleportable between Penpal and AH, using the asset owner account - AssetHubWestend::set_foreign_asset_reserves( - pal_at_asset_hub.clone(), - asset_owner.into(), - vec![(pal_at_asset_hub.clone(), true).into()], - ); - let penpal_sovereign = AssetHubWestend::sovereign_account_id_of( AssetHubWestend::sibling_location_of(PenpalB::para_id()), ); @@ -1468,7 +1450,7 @@ fn transfer_penpal_native_asset() { }); PenpalB::execute_with(|| { - assert_ok!(::ForeignAssets::mint_into( + assert_ok!(::Assets::mint_into( Location::parent(), &PenpalBSender::get(), INITIAL_FUND, @@ -1526,7 +1508,7 @@ fn transfer_penpal_native_asset() { assert_expected_events!( PenpalB, - vec![RuntimeEvent::ForeignAssets(pallet_assets::Event::Burned{ .. }) => {},] + vec![RuntimeEvent::Assets(pallet_assets::Event::Burned{ .. }) => {},] ); }); @@ -1632,8 +1614,7 @@ fn transfer_penpal_teleport_enabled_asset() { ); BridgeHubWestend::fund_accounts(vec![(assethub_sovereign.clone(), INITIAL_FUND)]); - let asset_location_on_penpal = - PenpalB::execute_with(|| PenpalLocalTeleportableToAssetHub::get()); + let asset_location_on_penpal = PenpalB::execute_with(|| PenpalLocalPen2Asset::get()); let pal_at_asset_hub = Location::new(1, [Junction::Parachain(PenpalB::para_id().into())]) .appended_with(asset_location_on_penpal.clone()) @@ -1654,6 +1635,9 @@ fn transfer_penpal_teleport_enabled_asset() { AssetHubWestend::fund_accounts(vec![(penpal_sovereign.clone(), INITIAL_FUND)]); AssetHubWestend::fund_accounts(vec![(snowbridge_sovereign(), INITIAL_FUND)]); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + // Register token BridgeHubWestend::execute_with(|| { type RuntimeOrigin = ::RuntimeOrigin; @@ -1670,14 +1654,14 @@ fn transfer_penpal_teleport_enabled_asset() { }); // Fund on Penpal - PenpalB::fund_accounts(vec![(CheckingAccount::get(), INITIAL_FUND)]); + PenpalB::fund_accounts(vec![(PenpalCheckingAccount::get(), INITIAL_FUND)]); PenpalB::execute_with(|| { assert_ok!(::Assets::mint_into( - TELEPORTABLE_ASSET_ID, + PenpalLocalPen2Asset::get(), &PenpalBSender::get(), INITIAL_FUND, )); - assert_ok!(::ForeignAssets::mint_into( + assert_ok!(::Assets::mint_into( Location::parent(), &PenpalBSender::get(), INITIAL_FUND, @@ -1735,7 +1719,7 @@ fn transfer_penpal_teleport_enabled_asset() { assert_expected_events!( PenpalB, - vec![RuntimeEvent::ForeignAssets(pallet_assets::Event::Burned{ .. }) => {},] + vec![RuntimeEvent::Assets(pallet_assets::Event::Burned{ .. }) => {},] ); assert_expected_events!( diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_common.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_common.rs index 75cf7ab7a1546..1abb50b77fc1e 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_common.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_common.rs @@ -15,16 +15,9 @@ use crate::{imports::*, tests::bridged_roc_at_ah_westend}; use asset_hub_westend_runtime::xcm_config::LocationToAccountId; -use emulated_integration_tests_common::{ - snowbridge::{SEPOLIA_ID, WETH}, - PenpalBTeleportableAssetLocation, -}; -use frame_support::traits::fungibles::Mutate; +use emulated_integration_tests_common::snowbridge::{SEPOLIA_ID, WETH}; +use frame_support::traits::{fungible::Mutate as _, fungibles::Mutate}; use hex_literal::hex; -use rococo_westend_system_emulated_network::penpal_emulated_chain::{ - penpal_runtime::xcm_config::{CheckingAccount, TELEPORTABLE_ASSET_ID}, - PenpalAssetOwner, -}; use snowbridge_core::AssetMetadata; use sp_core::H160; use testnet_parachains_constants::westend::snowbridge::EthereumNetwork; @@ -37,6 +30,7 @@ pub const AGENT_ADDRESS: [u8; 20] = hex!("90A987B944Cb1dCcE5564e5FDeCD7a54D3de27 pub const TOKEN_AMOUNT: u128 = 10_000_000_000_000; pub const REMOTE_FEE_AMOUNT_IN_ETHER: u128 = 600_000_000_000; pub const LOCAL_FEE_AMOUNT_IN_DOT: u128 = 800_000_000_000; +pub const LOCAL_FEE_AMOUNT_IN_PAL: u128 = 800_000_000_000; pub const EXECUTION_WEIGHT: u64 = 8_000_000_000; @@ -83,14 +77,14 @@ pub fn register_relay_token_on_bh() { pub fn register_assets_on_penpal() { let ethereum_sovereign: AccountId = snowbridge_sovereign(); PenpalB::execute_with(|| { - assert_ok!(::ForeignAssets::force_create( + assert_ok!(::Assets::force_create( ::RuntimeOrigin::root(), weth_location().try_into().unwrap(), ethereum_sovereign.clone().into(), true, 1, )); - assert_ok!(::ForeignAssets::force_create( + assert_ok!(::Assets::force_create( ::RuntimeOrigin::root(), ethereum().try_into().unwrap(), ethereum_sovereign.into(), @@ -123,20 +117,11 @@ pub fn register_foreign_asset(token_location: Location) { ); } -pub fn register_pal_on_ah() { +pub fn mint_pal_on_ah() { // Create PAL(i.e. native asset for penpal) on AH. AssetHubWestend::execute_with(|| { - type RuntimeOrigin = ::RuntimeOrigin; let penpal_asset_id = Location::new(1, Parachain(PenpalB::para_id().into())); - assert_ok!(::ForeignAssets::force_create( - RuntimeOrigin::root(), - penpal_asset_id.clone(), - PenpalAssetOwner::get().into(), - false, - 1_000_000, - )); - assert!(::ForeignAssets::asset_exists( penpal_asset_id.clone(), )); @@ -170,70 +155,81 @@ pub fn fund_on_penpal() { PenpalB::fund_accounts(vec![ (PenpalBReceiver::get(), INITIAL_FUND), (PenpalBSender::get(), INITIAL_FUND), - (CheckingAccount::get(), INITIAL_FUND), + (PenpalCheckingAccount::get(), INITIAL_FUND), (sudo_account.clone(), INITIAL_FUND), ]); PenpalB::execute_with(|| { - assert_ok!(::ForeignAssets::mint_into( + assert_ok!(::Assets::mint_into( Location::parent(), &PenpalBReceiver::get(), INITIAL_FUND, )); - assert_ok!(::ForeignAssets::mint_into( + assert_ok!(::Assets::mint_into( Location::parent(), &PenpalBSender::get(), INITIAL_FUND, )); - assert_ok!(::ForeignAssets::mint_into( + assert_ok!(::Assets::mint_into( Location::parent(), &sudo_account, INITIAL_FUND, )); }); + PenpalB::execute_with(|| { + assert_ok!(::Balances::mint_into( + &PenpalBReceiver::get(), + INITIAL_FUND, + )); + assert_ok!(::Balances::mint_into( + &PenpalBSender::get(), + INITIAL_FUND, + )); + assert_ok!(::Balances::mint_into(&sudo_account, INITIAL_FUND,)); + }); PenpalB::execute_with(|| { assert_ok!(::Assets::mint_into( - TELEPORTABLE_ASSET_ID, + PenpalLocalPen2Asset::get(), &PenpalBReceiver::get(), INITIAL_FUND, )); assert_ok!(::Assets::mint_into( - TELEPORTABLE_ASSET_ID, + PenpalLocalPen2Asset::get(), &PenpalBSender::get(), INITIAL_FUND, )); assert_ok!(::Assets::mint_into( - TELEPORTABLE_ASSET_ID, + PenpalLocalPen2Asset::get(), &sudo_account, INITIAL_FUND, )); }); PenpalB::execute_with(|| { - assert_ok!(::ForeignAssets::mint_into( + assert_ok!(::Assets::mint_into( weth_location().try_into().unwrap(), &PenpalBReceiver::get(), INITIAL_FUND, )); - assert_ok!(::ForeignAssets::mint_into( + assert_ok!(::Assets::mint_into( weth_location().try_into().unwrap(), &PenpalBSender::get(), INITIAL_FUND, )); - assert_ok!(::ForeignAssets::mint_into( + assert_ok!(::Assets::mint_into( weth_location().try_into().unwrap(), &sudo_account, INITIAL_FUND, )); - assert_ok!(::ForeignAssets::mint_into( + assert_ok!(::Assets::mint_into( ethereum().try_into().unwrap(), &PenpalBReceiver::get(), INITIAL_FUND, )); - assert_ok!(::ForeignAssets::mint_into( + assert_ok!(::Assets::mint_into( ethereum().try_into().unwrap(), &PenpalBSender::get(), INITIAL_FUND, )); - assert_ok!(::ForeignAssets::mint_into( + assert_ok!(::Assets::mint_into( ethereum().try_into().unwrap(), &sudo_account, INITIAL_FUND, @@ -326,18 +322,16 @@ pub fn create_pools_on_ah() { let ethereum_sovereign = snowbridge_sovereign(); AssetHubWestend::fund_accounts(vec![(ethereum_sovereign.clone(), INITIAL_FUND)]); PenpalB::fund_accounts(vec![(ethereum_sovereign.clone(), INITIAL_FUND)]); - create_pool_with_native_on!( + create_foreign_pool_with_parent_native_on!( AssetHubWestend, weth_location(), - true, ethereum_sovereign.clone(), 1_000_000_000_000, 20_000_000_000 ); - create_pool_with_native_on!( + create_foreign_pool_with_parent_native_on!( AssetHubWestend, ethereum(), - true, ethereum_sovereign.clone(), 1_000_000_000_000, 20_000_000_000 @@ -349,14 +343,23 @@ pub(crate) fn set_up_eth_and_dot_pool() { let ethereum_sovereign = snowbridge_sovereign(); AssetHubWestend::fund_accounts(vec![(ethereum_sovereign.clone(), INITIAL_FUND)]); PenpalB::fund_accounts(vec![(ethereum_sovereign.clone(), INITIAL_FUND)]); - create_pool_with_native_on!(AssetHubWestend, eth_location(), true, ethereum_sovereign.clone()); + create_foreign_pool_with_parent_native_on!( + AssetHubWestend, + eth_location(), + ethereum_sovereign.clone() + ); } pub(crate) fn set_up_eth_and_dot_pool_on_penpal() { let ethereum_sovereign = snowbridge_sovereign(); AssetHubWestend::fund_accounts(vec![(ethereum_sovereign.clone(), INITIAL_FUND)]); PenpalB::fund_accounts(vec![(ethereum_sovereign.clone(), INITIAL_FUND)]); - create_pool_with_native_on!(PenpalB, eth_location(), true, ethereum_sovereign.clone()); + create_foreign_pool_with_native_on!( + PenpalB, + Assets, + eth_location(), + ethereum_sovereign.clone() + ); } pub(crate) fn set_up_eth_and_dot_pool_on_rococo() { @@ -365,7 +368,11 @@ pub(crate) fn set_up_eth_and_dot_pool_on_rococo() { AssetHubWestend::para_id(), ); AssetHubRococo::fund_accounts(vec![(sa_of_wah_on_rah.clone(), INITIAL_FUND)]); - create_pool_with_native_on!(AssetHubRococo, eth_location(), true, sa_of_wah_on_rah.clone()); + create_foreign_pool_with_parent_native_on!( + AssetHubRococo, + eth_location(), + sa_of_wah_on_rah.clone() + ); } pub fn register_pal_on_bh() { @@ -375,7 +382,7 @@ pub fn register_pal_on_bh() { assert_ok!(::EthereumSystem::register_token( RuntimeOrigin::root(), - Box::new(VersionedLocation::from(PenpalBTeleportableAssetLocation::get())), + Box::new(VersionedLocation::from(PenpalBLocation::get())), AssetMetadata { name: "pal".as_bytes().to_vec().try_into().unwrap(), symbol: "pal".as_bytes().to_vec().try_into().unwrap(), diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_inbound.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_inbound.rs index 4b120d036703f..41fe1e78dd291 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_inbound.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_inbound.rs @@ -529,7 +529,7 @@ fn send_token_to_penpal_v2() { type RuntimeOrigin = ::RuntimeOrigin; // Register token on Penpal - assert_ok!(::ForeignAssets::force_create( + assert_ok!(::Assets::force_create( RuntimeOrigin::root(), token_location.clone().try_into().unwrap(), snowbridge_sovereign.clone().into(), @@ -537,12 +537,12 @@ fn send_token_to_penpal_v2() { 1000, )); - assert!(::ForeignAssets::asset_exists( + assert!(::Assets::asset_exists( token_location.clone().try_into().unwrap(), )); // Register eth on Penpal - assert_ok!(::ForeignAssets::force_create( + assert_ok!(::Assets::force_create( RuntimeOrigin::root(), eth_location().try_into().unwrap(), snowbridge_sovereign.clone().into(), @@ -550,7 +550,7 @@ fn send_token_to_penpal_v2() { 1000, )); - assert!(::ForeignAssets::asset_exists( + assert!(::Assets::asset_exists( eth_location().try_into().unwrap(), )); @@ -675,6 +675,7 @@ fn send_token_to_penpal_v2() { PenpalB::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; + type Assets = ::Assets; assert_expected_events!( PenpalB, @@ -684,12 +685,12 @@ fn send_token_to_penpal_v2() { pallet_message_queue::Event::Processed { success: true, .. } ) => {}, // Token was issued to beneficiary - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { asset_id: *asset_id == token_location, owner: *owner == beneficiary_acc_bytes.into(), }, // Leftover fees was deposited to beneficiary - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { asset_id: *asset_id == eth_location(), owner: *owner == beneficiary_acc_bytes.into(), }, @@ -698,7 +699,7 @@ fn send_token_to_penpal_v2() { // Beneficiary received the token transfer value assert_eq!( - ForeignAssets::balance(token_location, AccountId::from(beneficiary_acc_bytes)), + Assets::balance(token_location, AccountId::from(beneficiary_acc_bytes)), token_transfer_value ); diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_outbound.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_outbound.rs index d89e42a5b9228..377ea2cfef9b4 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_outbound.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_outbound.rs @@ -20,9 +20,7 @@ use crate::{ use bridge_hub_westend_runtime::{ bridge_to_ethereum_config::EthereumGatewayAddress, EthereumOutboundQueueV2, }; -use emulated_integration_tests_common::{impls::Decode, PenpalBTeleportableAssetLocation}; use frame_support::{assert_err_ignore_postinfo, pallet_prelude::TypeInfo}; -use rococo_westend_system_emulated_network::penpal_emulated_chain::penpal_runtime::xcm_config::LocalTeleportableToAssetHub; use snowbridge_core::{reward::MessageId, AssetMetadata, BasicOperatingMode}; use snowbridge_outbound_queue_primitives::v2::{ContractCall, DeliveryReceipt}; use snowbridge_pallet_outbound_queue_v2::Error; @@ -714,8 +712,7 @@ fn register_token_from_penpal() { }, ], ); - let asset_location_on_penpal = - PenpalB::execute_with(|| PenpalLocalTeleportableToAssetHub::get()); + let asset_location_on_penpal = PenpalB::execute_with(|| PenpalLocalPen2Asset::get()); let foreign_asset_at_asset_hub = Location::new(1, [Junction::Parachain(PenpalB::para_id().into())]) .appended_with(asset_location_on_penpal) @@ -724,7 +721,7 @@ fn register_token_from_penpal() { type RuntimeOrigin = ::RuntimeOrigin; let local_fee_asset_on_penpal = - Asset { id: AssetId(Location::parent()), fun: Fungible(LOCAL_FEE_AMOUNT_IN_DOT) }; + Asset { id: AssetId(Location::here()), fun: Fungible(LOCAL_FEE_AMOUNT_IN_PAL) }; let remote_fee_asset_on_ah = Asset { id: AssetId(ethereum()), fun: Fungible(REMOTE_FEE_AMOUNT_IN_ETHER) }; @@ -820,7 +817,7 @@ fn send_message_from_penpal_to_ethereum(sudo: bool) { // ah register_assets_on_ah(); create_pools_on_ah(); - register_pal_on_ah(); + mint_pal_on_ah(); register_pal_on_bh(); fund_on_ah(); // penpal @@ -832,7 +829,7 @@ fn send_message_from_penpal_to_ethereum(sudo: bool) { type RuntimeOrigin = ::RuntimeOrigin; let local_fee_asset_on_penpal = - Asset { id: AssetId(Location::parent()), fun: Fungible(LOCAL_FEE_AMOUNT_IN_DOT) }; + Asset { id: AssetId(Location::here()), fun: Fungible(LOCAL_FEE_AMOUNT_IN_PAL) }; let remote_fee_asset_on_ah = Asset { id: AssetId(ethereum()), fun: Fungible(REMOTE_FEE_AMOUNT_IN_ETHER) }; @@ -840,15 +837,12 @@ fn send_message_from_penpal_to_ethereum(sudo: bool) { let remote_fee_asset_on_ethereum = Asset { id: AssetId(ethereum()), fun: Fungible(REMOTE_FEE_AMOUNT_IN_ETHER) }; - let pna = - Asset { id: AssetId(LocalTeleportableToAssetHub::get()), fun: Fungible(TOKEN_AMOUNT) }; + let pna = Asset { id: AssetId(PenpalNativeCurrency::get()), fun: Fungible(TOKEN_AMOUNT) }; let ena = Asset { id: AssetId(weth_location()), fun: Fungible(TOKEN_AMOUNT / 2) }; - let transfer_asset_reanchor_on_ah = Asset { - id: AssetId(PenpalBTeleportableAssetLocation::get()), - fun: Fungible(TOKEN_AMOUNT), - }; + let transfer_asset_reanchor_on_ah = + Asset { id: AssetId(PenpalBLocation::get()), fun: Fungible(TOKEN_AMOUNT) }; let assets = vec![ local_fee_asset_on_penpal.clone(), diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_outbound_edge_case.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_outbound_edge_case.rs index a3cab1ad1e931..b7100457898f8 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_outbound_edge_case.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_outbound_edge_case.rs @@ -46,8 +46,7 @@ fn register_penpal_a_asset_from_penpal_b_will_fail() { }, ], ); - let asset_location_on_penpal = - PenpalB::execute_with(|| PenpalLocalTeleportableToAssetHub::get()); + let asset_location_on_penpal = PenpalB::execute_with(|| PenpalLocalPen2Asset::get()); let penpal_a_asset_at_asset_hub = Location::new(1, [Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) @@ -56,7 +55,7 @@ fn register_penpal_a_asset_from_penpal_b_will_fail() { type RuntimeOrigin = ::RuntimeOrigin; let local_fee_asset_on_penpal = - Asset { id: AssetId(Location::parent()), fun: Fungible(LOCAL_FEE_AMOUNT_IN_DOT) }; + Asset { id: AssetId(Location::here()), fun: Fungible(LOCAL_FEE_AMOUNT_IN_PAL) }; let remote_fee_asset_on_ah = Asset { id: AssetId(ethereum()), fun: Fungible(REMOTE_FEE_AMOUNT_IN_ETHER) }; @@ -236,7 +235,7 @@ pub const INSUFFICIENT_REMOTE_FEE_AMOUNT: u128 = 1_000_000_000; #[test] fn transfer_from_penpal_to_ethereum_trapped_on_ah_and_then_claim_can_work() { create_pools_on_ah(); - register_pal_on_ah(); + mint_pal_on_ah(); register_pal_on_bh(); fund_on_ah(); // penpal @@ -260,7 +259,7 @@ fn transfer_from_penpal_to_ethereum_trapped_on_ah_and_then_claim_can_work() { type RuntimeOrigin = ::RuntimeOrigin; let local_fee_asset_on_penpal = - Asset { id: AssetId(Location::parent()), fun: Fungible(LOCAL_FEE_AMOUNT_IN_DOT) }; + Asset { id: AssetId(Location::here()), fun: Fungible(LOCAL_FEE_AMOUNT_IN_PAL) }; let remote_fee_asset_on_ah = Asset { id: AssetId(ethereum()), fun: Fungible(INSUFFICIENT_REMOTE_FEE_AMOUNT) }; @@ -336,7 +335,7 @@ fn transfer_from_penpal_to_ethereum_trapped_on_ah_and_then_claim_can_work() { type RuntimeOrigin = ::RuntimeOrigin; let local_fee_asset_on_penpal = - Asset { id: AssetId(Location::parent()), fun: Fungible(LOCAL_FEE_AMOUNT_IN_DOT) }; + Asset { id: AssetId(Location::here()), fun: Fungible(LOCAL_FEE_AMOUNT_IN_PAL) }; let remote_fee_asset_on_ah = Asset { id: AssetId(ethereum()), fun: Fungible(REMOTE_FEE_AMOUNT_IN_ETHER) }; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/transact.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/transact.rs index 26c45a5e723e1..8f5b32615b797 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/transact.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/transact.rs @@ -138,19 +138,17 @@ fn transact_from_ethereum_to_penpalb_through_asset_hub() { // We create a pool between WND and WETH in AssetHub to support paying for fees with WETH. let snowbridge_sovereign = snowbridge_sovereign(); - create_pool_with_native_on!( + create_foreign_pool_with_parent_native_on!( AssetHubWestend, bridged_weth.clone(), - true, - snowbridge_sovereign, + snowbridge_sovereign.clone(), 1_000_000_000_000, 20_000_000_000 ); - // We also need a pool between WND and WETH on PenpalB to support paying for fees with WETH. - create_pool_with_native_on!( + // We also need a pool between PEN and WETH on PenpalB to support paying for fees with WETH. + create_foreign_pool_with_native_on!( PenpalB, bridged_weth.clone(), - true, PenpalAssetOwner::get(), 1_000_000_000_000, 20_000_000_000 @@ -161,7 +159,7 @@ fn transact_from_ethereum_to_penpalb_through_asset_hub() { // Query initial balances let receiver_assets_before = PenpalB::execute_with(|| { - type Assets = ::ForeignAssets; + type Assets = ::Assets; >::balance(bridged_weth.clone(), &receiver) }); @@ -203,7 +201,7 @@ fn transact_from_ethereum_to_penpalb_through_asset_hub() { // Query final balances let receiver_assets_after = PenpalB::execute_with(|| { - type Assets = ::ForeignAssets; + type Assets = ::Assets; >::balance(bridged_weth, &receiver) }); // Receiver's balance is increased @@ -236,7 +234,7 @@ fn penpal_b_assertions( assert_expected_events!( PenpalB, vec![ - RuntimeEvent::ForeignAssets( + RuntimeEvent::Assets( pallet_assets::Event::Created { asset_id, creator, owner } ) => { asset_id: *asset_id == expected_asset, diff --git a/cumulus/parachains/integration-tests/emulated/tests/collectives/collectives-westend/src/tests/aliases.rs b/cumulus/parachains/integration-tests/emulated/tests/collectives/collectives-westend/src/tests/aliases.rs index be9bc76ab2a18..b45ceed129c49 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/collectives/collectives-westend/src/tests/aliases.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/collectives/collectives-westend/src/tests/aliases.rs @@ -16,7 +16,9 @@ //! Tests related to XCM aliasing. use crate::imports::*; -use emulated_integration_tests_common::{macros::AccountId, test_cross_chain_alias}; +use emulated_integration_tests_common::{ + create_foreign_pool_with_native_on, macros::AccountId, test_cross_chain_alias, +}; use frame_support::traits::ContainsPair; use xcm::latest::Junctions::*; @@ -31,7 +33,7 @@ fn account_on_sibling_syschain_aliases_into_same_local_account() { // origin and target are the same account on different chains let origin: AccountId = [1; 32].into(); let target = origin.clone(); - let fees = WESTEND_ED * 10; + let fees = WESTEND_ED * 20; PenpalB::mint_foreign_asset( ::RuntimeOrigin::signed(PenpalAssetOwner::get()), @@ -40,6 +42,9 @@ fn account_on_sibling_syschain_aliases_into_same_local_account() { fees * 10, ); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + // Aliasing same account on different chains test_cross_chain_alias!( vec![ @@ -65,7 +70,7 @@ fn account_on_sibling_syschain_cannot_alias_into_different_local_account() { // origin and target are different accounts on different chains let origin: AccountId = [1; 32].into(); let target: AccountId = [2; 32].into(); - let fees = WESTEND_ED * 10; + let fees = WESTEND_ED * 20; PenpalB::mint_foreign_asset( ::RuntimeOrigin::signed(PenpalAssetOwner::get()), @@ -74,6 +79,9 @@ fn account_on_sibling_syschain_cannot_alias_into_different_local_account() { fees * 10, ); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + // Aliasing different account on different chains test_cross_chain_alias!( vec![ @@ -194,11 +202,15 @@ fn authorized_cross_chain_aliases() { let origin: AccountId = [100; 32].into(); let bad_origin: AccountId = [150; 32].into(); let target: AccountId = [200; 32].into(); - let fees = WESTEND_ED * 10; + let fees = WESTEND_ED * 20; let pal_admin = ::RuntimeOrigin::signed(PenpalAssetOwner::get()); PenpalB::mint_foreign_asset(pal_admin.clone(), Location::parent(), origin.clone(), fees * 10); PenpalB::mint_foreign_asset(pal_admin, Location::parent(), bad_origin.clone(), fees * 10); + + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + CollectivesWestend::fund_accounts(vec![(target.clone(), fees * 10)]); // let's authorize `origin` on Penpal to alias `target` on Collectives diff --git a/cumulus/parachains/integration-tests/emulated/tests/coretime/coretime-westend/src/tests/aliases.rs b/cumulus/parachains/integration-tests/emulated/tests/coretime/coretime-westend/src/tests/aliases.rs index 40cfa6afb4d04..ea99cff641887 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/coretime/coretime-westend/src/tests/aliases.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/coretime/coretime-westend/src/tests/aliases.rs @@ -17,7 +17,9 @@ use crate::imports::*; use coretime_westend_emulated_chain::coretime_westend_runtime::xcm_config::XcmConfig; -use emulated_integration_tests_common::{macros::AccountId, test_cross_chain_alias}; +use emulated_integration_tests_common::{ + create_foreign_pool_with_native_on, macros::AccountId, test_cross_chain_alias, +}; use frame_support::traits::ContainsPair; use xcm::latest::Junctions::*; @@ -32,7 +34,7 @@ fn account_on_sibling_syschain_aliases_into_same_local_account() { // origin and target are the same account on different chains let origin: AccountId = [1; 32].into(); let target = origin.clone(); - let fees = WESTEND_ED * 10; + let fees = WESTEND_ED * 20; PenpalB::mint_foreign_asset( ::RuntimeOrigin::signed(PenpalAssetOwner::get()), @@ -41,6 +43,9 @@ fn account_on_sibling_syschain_aliases_into_same_local_account() { fees * 10, ); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + // Aliasing same account on different chains test_cross_chain_alias!( vec![ @@ -66,7 +71,7 @@ fn account_on_sibling_syschain_cannot_alias_into_different_local_account() { // origin and target are different accounts on different chains let origin: AccountId = [1; 32].into(); let target: AccountId = [2; 32].into(); - let fees = WESTEND_ED * 10; + let fees = WESTEND_ED * 20; PenpalB::mint_foreign_asset( ::RuntimeOrigin::signed(PenpalAssetOwner::get()), @@ -75,6 +80,9 @@ fn account_on_sibling_syschain_cannot_alias_into_different_local_account() { fees * 10, ); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + // Aliasing different account on different chains test_cross_chain_alias!( vec![ @@ -193,11 +201,15 @@ fn authorized_cross_chain_aliases() { let origin: AccountId = [100; 32].into(); let bad_origin: AccountId = [150; 32].into(); let target: AccountId = [200; 32].into(); - let fees = WESTEND_ED * 10; + let fees = WESTEND_ED * 20; let pal_admin = ::RuntimeOrigin::signed(PenpalAssetOwner::get()); PenpalB::mint_foreign_asset(pal_admin.clone(), Location::parent(), origin.clone(), fees * 10); PenpalB::mint_foreign_asset(pal_admin, Location::parent(), bad_origin.clone(), fees * 10); + + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + CoretimeWestend::fund_accounts(vec![(target.clone(), fees * 10)]); // let's authorize `origin` on Penpal to alias `target` on Coretime diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/aliases.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/aliases.rs index 6b198de751fe3..82f8bce00533e 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/aliases.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/aliases.rs @@ -16,7 +16,9 @@ //! Tests related to XCM aliasing. use crate::imports::*; -use emulated_integration_tests_common::{macros::AccountId, test_cross_chain_alias}; +use emulated_integration_tests_common::{ + create_foreign_pool_with_native_on, macros::AccountId, test_cross_chain_alias, +}; use frame_support::traits::ContainsPair; use xcm::latest::Junctions::*; @@ -31,7 +33,7 @@ fn account_on_sibling_syschain_aliases_into_same_local_account() { // origin and target are the same account on different chains let origin: AccountId = [1; 32].into(); let target = origin.clone(); - let fees = WESTEND_ED * 10; + let fees = WESTEND_ED * 20; PenpalB::mint_foreign_asset( ::RuntimeOrigin::signed(PenpalAssetOwner::get()), @@ -40,6 +42,9 @@ fn account_on_sibling_syschain_aliases_into_same_local_account() { fees * 10, ); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + // Aliasing same account on different chains test_cross_chain_alias!( vec![ @@ -65,7 +70,7 @@ fn account_on_sibling_syschain_cannot_alias_into_different_local_account() { // origin and target are different accounts on different chains let origin: AccountId = [1; 32].into(); let target: AccountId = [2; 32].into(); - let fees = WESTEND_ED * 10; + let fees = WESTEND_ED * 20; PenpalB::mint_foreign_asset( ::RuntimeOrigin::signed(PenpalAssetOwner::get()), @@ -74,6 +79,9 @@ fn account_on_sibling_syschain_cannot_alias_into_different_local_account() { fees * 10, ); + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + // Aliasing different account on different chains test_cross_chain_alias!( vec![ @@ -194,11 +202,15 @@ fn authorized_cross_chain_aliases() { let origin: AccountId = [100; 32].into(); let bad_origin: AccountId = [150; 32].into(); let target: AccountId = [200; 32].into(); - let fees = WESTEND_ED * 10; + let fees = WESTEND_ED * 20; let pal_admin = ::RuntimeOrigin::signed(PenpalAssetOwner::get()); PenpalB::mint_foreign_asset(pal_admin.clone(), Location::parent(), origin.clone(), fees * 10); PenpalB::mint_foreign_asset(pal_admin, Location::parent(), bad_origin.clone(), fees * 10); + + // We need to create a pool to pay execution fees in WND + create_foreign_pool_with_native_on!(PenpalB, Location::parent(), PenpalAssetOwner::get()); + PeopleWestend::fund_accounts(vec![(target.clone(), fees * 10)]); // let's authorize `origin` on Penpal to alias `target` on People diff --git a/cumulus/parachains/runtimes/testing/penpal/Cargo.toml b/cumulus/parachains/runtimes/testing/penpal/Cargo.toml index db85756944637..73c831d06c5f4 100644 --- a/cumulus/parachains/runtimes/testing/penpal/Cargo.toml +++ b/cumulus/parachains/runtimes/testing/penpal/Cargo.toml @@ -32,7 +32,7 @@ frame-system-benchmarking = { optional = true, workspace = true } frame-system-rpc-runtime-api = { workspace = true } frame-try-runtime = { optional = true, workspace = true } pallet-asset-conversion = { workspace = true } -pallet-asset-tx-payment = { workspace = true } +pallet-asset-conversion-tx-payment = { workspace = true } pallet-assets = { workspace = true } pallet-aura = { workspace = true } pallet-authorship = { workspace = true } @@ -114,8 +114,8 @@ std = [ "frame-system-rpc-runtime-api/std", "frame-system/std", "frame-try-runtime?/std", + "pallet-asset-conversion-tx-payment/std", "pallet-asset-conversion/std", - "pallet-asset-tx-payment/std", "pallet-assets/std", "pallet-aura/std", "pallet-authorship/std", @@ -172,8 +172,8 @@ runtime-benchmarks = [ "frame-system-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", "hex-literal", + "pallet-asset-conversion-tx-payment/runtime-benchmarks", "pallet-asset-conversion/runtime-benchmarks", - "pallet-asset-tx-payment/runtime-benchmarks", "pallet-assets/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", @@ -206,8 +206,8 @@ try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", "frame-try-runtime/try-runtime", + "pallet-asset-conversion-tx-payment/try-runtime", "pallet-asset-conversion/try-runtime", - "pallet-asset-tx-payment/try-runtime", "pallet-assets/try-runtime", "pallet-aura/try-runtime", "pallet-authorship/try-runtime", diff --git a/cumulus/parachains/runtimes/testing/penpal/src/genesis_config_presets.rs b/cumulus/parachains/runtimes/testing/penpal/src/genesis_config_presets.rs index 82a7f365159bb..f614626d78e1e 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/genesis_config_presets.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/genesis_config_presets.rs @@ -28,7 +28,13 @@ //! Penpal Parachain Runtime genesis config presets -use crate::*; +use crate::{ + xcm_config::{ + EthFromEthereum, LocalPen2Asset, RelayLocation, UsdtFromAssetHub, ETHER_MIN_BALANCE, + USDT_ED, + }, + *, +}; use alloc::{vec, vec::Vec}; use cumulus_primitives_core::ParaId; use frame_support::build_struct_json_patch; @@ -72,42 +78,44 @@ fn penpal_parachain_genesis( polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) }, sudo: SudoConfig { key: Some(sudo.clone()) }, assets: AssetsConfig { - assets: vec![( - crate::xcm_config::TELEPORTABLE_ASSET_ID, - sudo.clone(), // owner - false, // is_sufficient - crate::EXISTENTIAL_DEPOSIT, - )], - metadata: vec![( - crate::xcm_config::TELEPORTABLE_ASSET_ID, - "pal-2".as_bytes().to_vec(), - "pal-2".as_bytes().to_vec(), - 12, - )], - accounts: vec![( - crate::xcm_config::TELEPORTABLE_ASSET_ID, - sudo.clone(), - crate::EXISTENTIAL_DEPOSIT * 4096, - )] - }, - foreign_assets: ForeignAssetsConfig { - assets: vec![( - crate::xcm_config::RelayLocation::get(), - sudo.clone(), - true, - crate::EXISTENTIAL_DEPOSIT - )], - metadata: vec![( - crate::xcm_config::RelayLocation::get(), - "relay".as_bytes().to_vec(), - "relay".as_bytes().to_vec(), - 12 - )], - accounts: vec![( - crate::xcm_config::RelayLocation::get(), - sudo, - crate::EXISTENTIAL_DEPOSIT * 4096, - )] + assets: vec![ + (RelayLocation::get(), sudo.clone(), true, EXISTENTIAL_DEPOSIT), + (LocalPen2Asset::get(), sudo.clone(), false, EXISTENTIAL_DEPOSIT), + (UsdtFromAssetHub::get(), sudo.clone(), true, EXISTENTIAL_DEPOSIT), + (EthFromEthereum::get(), sudo.clone(), true, EXISTENTIAL_DEPOSIT), + ], + metadata: vec![ + ( + RelayLocation::get(), + "relay".as_bytes().to_vec(), + "relay".as_bytes().to_vec(), + 12 + ), + ( + LocalPen2Asset::get(), + "pen-2".as_bytes().to_vec(), + "PEN2".as_bytes().to_vec(), + 12 + ), + ( + UsdtFromAssetHub::get(), + "Usdt".as_bytes().to_vec(), + "USDT".as_bytes().to_vec(), + 6 + ), + ( + EthFromEthereum::get(), + "Ethereum".as_bytes().to_vec(), + "ETH".as_bytes().to_vec(), + 18 + ), + ], + accounts: vec![ + (RelayLocation::get(), sudo.clone(), EXISTENTIAL_DEPOSIT * 4096,), + (LocalPen2Asset::get(), sudo.clone(), EXISTENTIAL_DEPOSIT * 4096,), + (UsdtFromAssetHub::get(), sudo.clone(), USDT_ED,), + (EthFromEthereum::get(), sudo, ETHER_MIN_BALANCE,), + ] } }) } diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index c70103e4cbf0a..3c0ee85f7c9f0 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -49,11 +49,7 @@ extern crate alloc; use alloc::{vec, vec::Vec}; pub use assets_common::local_and_foreign_assets::ForeignAssetReserveData; -use assets_common::{ - foreign_creators::ForeignCreators, - local_and_foreign_assets::{LocalFromLeft, TargetFromLeft}, - AssetIdForTrustBackedAssetsConvert, -}; +use assets_common::{foreign_creators::ForeignCreators, local_and_foreign_assets::TargetFromLeft}; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ @@ -64,7 +60,10 @@ use frame_support::{ pallet_prelude::Weight, parameter_types, traits::{ - tokens::{fungible, fungibles, imbalance::ResolveAssetTo}, + tokens::{ + fungible, + imbalance::{MaybeResolveAssetTo, ResolveAssetTo}, + }, AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, Everything, TransformOrigin, }, @@ -80,7 +79,7 @@ use frame_system::{ }; use pallet_revive::evm::runtime::EthExtra; use parachains_common::{ - impls::{AssetsToBlockAuthor, NonZeroIssuance}, + impls::BlockAuthor, message_queue::{NarrowOriginToSibling, ParaIdToSibling}, AccountId, Balance, BlockNumber, Hash, Header, Nonce, Signature, }; @@ -99,7 +98,7 @@ pub use sp_runtime::{traits::ConvertInto, MultiAddress, Perbill, Permill}; use testnet_parachains_constants::westend::{consensus::*, time::*}; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; use xcm::{ - latest::prelude::{AssetId as AssetLocationId, BodyId}, + latest::prelude::{AssetId as AssetLocationId, BodyId, Location}, Version as XcmVersion, VersionedAsset, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm, }; @@ -114,7 +113,7 @@ pub use sp_runtime::BuildStorage; use sp_version::NativeVersion; use sp_version::RuntimeVersion; use xcm_config::{ - ForeignAssetsAssetId, LocationToAccountId, XcmConfig, XcmOriginToTransactDispatchOrigin, + AssetsAssetId, LocationToAccountId, XcmConfig, XcmOriginToTransactDispatchOrigin, }; /// The address format for describing accounts. @@ -142,7 +141,7 @@ pub type TxExtension = ( frame_system::CheckEra, frame_system::CheckNonce, frame_system::CheckWeight, - pallet_asset_tx_payment::ChargeAssetTxPayment, + pallet_asset_conversion_tx_payment::ChargeAssetTxPayment, frame_metadata_hash_extension::CheckMetadataHash, pallet_revive::evm::tx_extension::SetOrigin, frame_system::WeightReclaim, @@ -166,7 +165,7 @@ impl EthExtra for EthExtraImpl { frame_system::CheckEra::::from(generic::Era::Immortal), frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), - pallet_asset_tx_payment::ChargeAssetTxPayment::::from(tip, None), + pallet_asset_conversion_tx_payment::ChargeAssetTxPayment::::from(tip, None), frame_metadata_hash_extension::CheckMetadataHash::::new(false), pallet_revive::evm::tx_extension::SetOrigin::::new_from_eth_transaction(), frame_system::WeightReclaim::::new(), @@ -459,20 +458,22 @@ parameter_types! { pub const MetadataDepositPerByte: Balance = 0; } -// /// We allow root and the Relay Chain council to execute privileged asset operations. -// pub type AssetsForceOrigin = -// EnsureOneOf, EnsureXcm>>; - -pub type TrustBackedAssetsInstance = pallet_assets::Instance1; - -impl pallet_assets::Config for Runtime { +/// Pallet Assets instance to store local and foreign assets, where: +/// +/// * Local assets are identified by `assets_common::matching::LocalLocationPattern`. +/// * Foreign assets are the rest +pub type AssetsInstance = pallet_assets::Instance2; +impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; - type AssetId = AssetId; - type AssetIdParameter = codec::Compact; - type ReserveData = (); + type AssetId = AssetsAssetId; + type AssetIdParameter = AssetsAssetId; + type ReserveData = ForeignAssetReserveData; type Currency = Balances; - type CreateOrigin = AsEnsureOriginWithArg>; + // This is to allow any other location to create assets. Used in tests, not + // recommended on real chains. + type CreateOrigin = + ForeignCreators; type ForceOrigin = EnsureRoot; type AssetDeposit = AssetDeposit; type MetadataDepositBase = MetadataDepositBase; @@ -487,46 +488,6 @@ impl pallet_assets::Config for Runtime { type AssetAccountDeposit = AssetAccountDeposit; type RemoveItemsLimit = frame_support::traits::ConstU32<1000>; #[cfg(feature = "runtime-benchmarks")] - type BenchmarkHelper = (); -} - -parameter_types! { - // we just reuse the same deposits - pub const ForeignAssetsAssetDeposit: Balance = AssetDeposit::get(); - pub const ForeignAssetsAssetAccountDeposit: Balance = AssetAccountDeposit::get(); - pub const ForeignAssetsApprovalDeposit: Balance = ApprovalDeposit::get(); - pub const ForeignAssetsAssetsStringLimit: u32 = AssetsStringLimit::get(); - pub const ForeignAssetsMetadataDepositBase: Balance = MetadataDepositBase::get(); - pub const ForeignAssetsMetadataDepositPerByte: Balance = MetadataDepositPerByte::get(); -} - -/// Another pallet assets instance to store foreign assets from bridgehub. -pub type ForeignAssetsInstance = pallet_assets::Instance2; -impl pallet_assets::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Balance = Balance; - type AssetId = ForeignAssetsAssetId; - type AssetIdParameter = ForeignAssetsAssetId; - type ReserveData = ForeignAssetReserveData; - type Currency = Balances; - // This is to allow any other remote location to create foreign assets. Used in tests, not - // recommended on real chains. - type CreateOrigin = - ForeignCreators; - type ForceOrigin = EnsureRoot; - type AssetDeposit = ForeignAssetsAssetDeposit; - type MetadataDepositBase = ForeignAssetsMetadataDepositBase; - type MetadataDepositPerByte = ForeignAssetsMetadataDepositPerByte; - type ApprovalDeposit = ForeignAssetsApprovalDeposit; - type StringLimit = ForeignAssetsAssetsStringLimit; - type Holder = (); - type Freezer = (); - type Extra = (); - type WeightInfo = pallet_assets::weights::SubstrateWeight; - type CallbackHandle = (); - type AssetAccountDeposit = ForeignAssetsAssetAccountDeposit; - type RemoveItemsLimit = frame_support::traits::ConstU32<1000>; - #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = assets_common::benchmarks::LocationAssetsBenchmarkHelper; } @@ -569,27 +530,11 @@ impl pallet_assets::Config for Runtime { type BenchmarkHelper = (); } -/// Union fungibles implementation for `Assets` and `ForeignAssets`. -pub type LocalAndForeignAssets = fungibles::UnionOf< - Assets, - ForeignAssets, - LocalFromLeft< - AssetIdForTrustBackedAssetsConvert< - xcm_config::TrustBackedAssetsPalletLocation, - xcm::latest::Location, - >, - parachains_common::AssetIdForTrustBackedAssets, - xcm::latest::Location, - >, - xcm::latest::Location, - AccountId, ->; - -/// Union fungibles implementation for [`LocalAndForeignAssets`] and `Balances`. +/// Union fungibles implementation for [`Assets`] and `Balances`. pub type NativeAndAssets = fungible::UnionOf< Balances, - LocalAndForeignAssets, - TargetFromLeft, + Assets, + TargetFromLeft, xcm::latest::Location, AccountId, >; @@ -607,7 +552,7 @@ impl pallet_asset_conversion::Config for Runtime { type Assets = NativeAndAssets; type PoolId = (Self::AssetKind, Self::AssetKind); type PoolLocator = pallet_asset_conversion::WithFirstAsset< - xcm_config::RelayLocation, + xcm_config::PenpalNativeCurrency, AccountId, Self::AssetKind, PoolIdToAccountId, @@ -615,19 +560,19 @@ impl pallet_asset_conversion::Config for Runtime { type PoolAssetId = u32; type PoolAssets = PoolAssets; type PoolSetupFee = ConstU128<0>; // Asset class deposit fees are sufficient to prevent spam - type PoolSetupFeeAsset = xcm_config::RelayLocation; + type PoolSetupFeeAsset = xcm_config::PenpalNativeCurrency; type PoolSetupFeeTarget = ResolveAssetTo; type LiquidityWithdrawalFee = LiquidityWithdrawalFee; - type LPFee = ConstU32<3>; + type LPFee = ConstU32<0>; // Makes account balance tracking in tests a bit easier type PalletId = AssetConversionPalletId; type MaxSwapPathLength = ConstU32<3>; type MintMinLiquidity = ConstU128<100>; type WeightInfo = (); #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = assets_common::benchmarks::AssetPairFactory< - xcm_config::RelayLocation, + xcm_config::PenpalNativeCurrency, parachain_info::Pallet, - xcm_config::TrustBackedAssetsPalletIndex, + xcm_config::AssetsPalletIndex, xcm::latest::Location, >; } @@ -694,7 +639,7 @@ impl cumulus_pallet_aura_ext::Config for Runtime {} parameter_types! { /// The asset ID for the asset that we use to pay for message delivery fees. - pub FeeAssetId: AssetLocationId = AssetLocationId(xcm_config::RelayLocation::get()); + pub FeeAssetId: AssetLocationId = AssetLocationId(xcm_config::PenpalNativeCurrency::get()); /// The base fee for the message delivery fees (3 CENTS). pub const BaseDeliveryFee: u128 = (1_000_000_000_000u128 / 100).saturating_mul(3); } @@ -778,33 +723,33 @@ impl pallet_collator_selection::Config for Runtime { } #[cfg(feature = "runtime-benchmarks")] -pub struct AssetTxHelper; +pub struct AssetTxConversionHelper; #[cfg(feature = "runtime-benchmarks")] -impl pallet_asset_tx_payment::BenchmarkHelperTrait for AssetTxHelper { - fn create_asset_id_parameter(_id: u32) -> (u32, u32) { +impl pallet_asset_conversion_tx_payment::BenchmarkHelperTrait + for AssetTxConversionHelper +{ + fn create_asset_id_parameter(_id: u32) -> (Location, Location) { unimplemented!("Penpal uses default weights"); } - fn setup_balances_and_pool(_asset_id: u32, _account: AccountId) { + fn setup_balances_and_pool(_asset_id: Location, _account: AccountId) { unimplemented!("Penpal uses default weights"); } } -impl pallet_asset_tx_payment::Config for Runtime { +impl pallet_asset_conversion_tx_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type Fungibles = Assets; - type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter< - pallet_assets::BalanceToAssetBalance< - Balances, - Runtime, - ConvertInto, - TrustBackedAssetsInstance, - >, - AssetsToBlockAuthor, + type AssetId = Location; + type OnChargeAssetTransaction = pallet_asset_conversion_tx_payment::SwapAssetAdapter< + xcm_config::PenpalNativeCurrency, + NativeAndAssets, + AssetConversion, + MaybeResolveAssetTo, NativeAndAssets, AccountId>, >; type WeightInfo = (); + #[cfg(feature = "runtime-benchmarks")] - type BenchmarkHelper = AssetTxHelper; + type BenchmarkHelper = AssetTxConversionHelper; } parameter_types! { @@ -870,7 +815,7 @@ construct_runtime!( // Monetary stuff. Balances: pallet_balances = 10, TransactionPayment: pallet_transaction_payment = 11, - AssetTxPayment: pallet_asset_tx_payment = 12, + AssetTxPayment: pallet_asset_conversion_tx_payment = 12, // Collator support. The order of these 4 are important and shall not change. Authorship: pallet_authorship = 20, @@ -889,8 +834,10 @@ construct_runtime!( Utility: pallet_utility = 40, // The main stage. - Assets: pallet_assets:: = 50, - ForeignAssets: pallet_assets:: = 51, + + // Removed, i.e. merged into the foreign assets pallet. + // Assets: pallet_assets:: = 50, + Assets: pallet_assets:: = 50, PoolAssets: pallet_assets:: = 52, AssetConversion: pallet_asset_conversion = 53, @@ -1068,7 +1015,7 @@ pallet_revive::impl_runtime_apis_plus_revive_traits!( impl xcm_runtime_apis::fees::XcmPaymentApi for Runtime { fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentApiError> { - let acceptable_assets = vec![AssetLocationId(xcm_config::RelayLocation::get())]; + let acceptable_assets = vec![AssetLocationId(xcm_config::PenpalNativeCurrency::get())]; PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets) } diff --git a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs index f8a9cdbdf56c8..c0e59acb6b403 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs @@ -35,13 +35,11 @@ //! `ReserveAssetTransferDeposited` message but that will but the intension will be to support this //! soon. use super::{ - AccountId, AllPalletsWithSystem, AssetId as AssetIdPalletAssets, Assets, Authorship, Balance, - Balances, CollatorSelection, ForeignAssets, ForeignAssetsInstance, NonZeroIssuance, + AccountId, AllPalletsWithSystem, Assets, Authorship, Balance, Balances, CollatorSelection, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeHoldReason, RuntimeOrigin, WeightToFee, XcmpQueue, }; use crate::{BaseDeliveryFee, FeeAssetId, TransactionByteFee}; -use assets_common::TrustBackedAssetsAsLocation; use core::marker::PhantomData; use frame_support::{ parameter_types, @@ -55,28 +53,27 @@ use frame_support::{ use frame_system::EnsureRoot; use pallet_xcm::{AuthorizedAliasers, XcmPassthrough}; use parachains_common::{ - xcm_config::{AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem}, - TREASURY_PALLET_ID, + impls::NonZeroIssuance, xcm_config::ConcreteAssetFromSystem, TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_common::{impls::ToAuthor, xcm_sender::ExponentialPrice}; -use sp_runtime::traits::{AccountIdConversion, ConvertInto, Identity, TryConvertInto}; +use sp_runtime::traits::{AccountIdConversion, Identity, TryConvertInto}; use testnet_parachains_constants::westend::currency::deposit; use xcm::latest::{prelude::*, WESTEND_GENESIS_HASH}; use xcm_builder::{ AccountId32Aliases, AliasChildLocation, AliasOriginRootUsingFilter, AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, - AsPrefixedGeneralIndex, ConvertedConcreteId, DescribeAllTerminal, DescribeFamily, - DescribeTerminus, EnsureXcmOrigin, ExternalConsensusLocationsConverterFor, FixedWeightBounds, - FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, HashedDescription, IsConcrete, - LocalMint, NativeAsset, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, - SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SingleAssetExchangeAdapter, - SovereignSignedViaLocation, StartsWith, TakeWeightCredit, TrailingSetTopicAsId, - UsingComponents, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, + DescribeAllTerminal, DescribeFamily, DescribeTerminus, EnsureXcmOrigin, + ExternalConsensusLocationsConverterFor, FixedWeightBounds, FrameTransactionalProcessor, + FungibleAdapter, FungiblesAdapter, HashedDescription, IsConcrete, LocalMint, NativeAsset, + NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SingleAssetExchangeAdapter, SovereignSignedViaLocation, StartsWith, + TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic, + XcmFeeManagerFromComponents, }; -use xcm_executor::{traits::JustTry, XcmExecutor}; +use xcm_executor::XcmExecutor; parameter_types! { pub const RelayLocation: Location = Location::parent(); @@ -94,9 +91,9 @@ parameter_types! { ].into(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); pub StakingPot: AccountId = CollatorSelection::account_id(); - pub TrustBackedAssetsPalletIndex: u8 = ::index() as u8; - pub TrustBackedAssetsPalletLocation: Location = - PalletInstance(TrustBackedAssetsPalletIndex::get()).into(); + pub AssetsPalletIndex: u8 = ::index() as u8; + pub AssetsPalletLocation: Location = + PalletInstance(AssetsPalletIndex::get()).into(); } /// Type for specifying how a `Location` can be converted into an `AccountId`. This is used @@ -129,29 +126,13 @@ pub type FungibleTransactor = FungibleAdapter< (), >; -/// Means for transacting assets besides the native currency on this chain. -pub type FungiblesTransactor = FungiblesAdapter< +/// Means for transacting assets besides the native currency on this chain that start with a local +/// location pattern. +pub type LocalFungiblesTransactor = FungiblesAdapter< // Use this fungibles implementation: Assets, - // Use this currency when it is a fungible asset matching the given location or name: - ( - ConvertedConcreteId< - AssetIdPalletAssets, - Balance, - AsPrefixedGeneralIndex, - JustTry, - >, - ConvertedConcreteId< - AssetIdPalletAssets, - Balance, - AsPrefixedGeneralIndex< - SystemAssetHubAssetsPalletLocation, - AssetIdPalletAssets, - JustTry, - >, - JustTry, - >, - ), + // Only allow locations that are local. + LocalAssetsConvertedConcreteId, // Convert an XCM Location into a local account id: LocationToAccountId, // Our chain's account ID type (we can't get away without mentioning it explicitly): @@ -164,7 +145,7 @@ pub type FungiblesTransactor = FungiblesAdapter< >; // Using the latest `Location`, we don't need to worry about migrations for Penpal. -pub type ForeignAssetsAssetId = Location; +pub type AssetsAssetId = Location; pub type ForeignAssetsConvertedConcreteId = xcm_builder::MatchedConvertedConcreteId< Location, Balance, @@ -179,10 +160,25 @@ pub type ForeignAssetsConvertedConcreteId = xcm_builder::MatchedConvertedConcret TryConvertInto, >; +pub type LocalAssetsConvertedConcreteId = xcm_builder::MatchedConvertedConcreteId< + Location, + Balance, + // Only allow patterns with local + ( + // Here we rely on fact that something like this works: + // assert!(Location::new(1, + // [Parachain(100)]).starts_with(&Location::parent())); + // assert!([Parachain(100)].into().starts_with(&Here)); + StartsWith, + ), + Identity, + TryConvertInto, +>; + /// Means for transacting foreign assets from different global consensus. pub type ForeignFungiblesTransactor = FungiblesAdapter< // Use this fungibles implementation: - ForeignAssets, + Assets, // Use this currency when it is a fungible asset matching the given location or name: ForeignAssetsConvertedConcreteId, // Convert an XCM Location into a local account id: @@ -196,7 +192,8 @@ pub type ForeignFungiblesTransactor = FungiblesAdapter< >; /// Means for transacting assets on this chain. -pub type AssetTransactors = (FungibleTransactor, ForeignFungiblesTransactor, FungiblesTransactor); +pub type AssetTransactors = + (FungibleTransactor, ForeignFungiblesTransactor, LocalFungiblesTransactor); /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, /// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can @@ -283,41 +280,51 @@ type AssetsFrom = AssetPrefixFrom; // This asset can be added to AH as Asset and reserved transfer between Penpal and AH pub const RESERVABLE_ASSET_ID: u32 = 1; // This asset can be added to AH as ForeignAsset and teleported between Penpal and AH -pub const TELEPORTABLE_ASSET_ID: u32 = 2; +pub const PEN2_TELEPORTABLE_GENERAL_INDEX: u32 = 2; -pub const ASSETS_PALLET_ID: u8 = 50; +pub const ASSET_HUB_ASSETS_PALLET_ID: u8 = 50; pub const ASSET_HUB_ID: u32 = 1000; +pub const PENPAL_ASSETS_PALLET_ID: u8 = 50; + pub const USDT_ASSET_ID: u128 = 1984; +pub const SEPOLIA_ID: u64 = 11155111; +// The minimum balance for assets pre-registered in emulated tests. +pub const ETHER_MIN_BALANCE: u128 = 1000; +pub const USDT_ED: Balance = 70_000; + parameter_types! { /// The location that this chain recognizes as the Relay network's Asset Hub. pub SystemAssetHubLocation: Location = Location::new(1, [Parachain(ASSET_HUB_ID)]); // the Relay Chain's Asset Hub's Assets pallet index pub SystemAssetHubAssetsPalletLocation: Location = - Location::new(1, [Parachain(ASSET_HUB_ID), PalletInstance(ASSETS_PALLET_ID)]); - pub AssetsPalletLocation: Location = - Location::new(0, [PalletInstance(ASSETS_PALLET_ID)]); + Location::new(1, [Parachain(ASSET_HUB_ID), PalletInstance(ASSET_HUB_ASSETS_PALLET_ID)]); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub LocalReservableFromAssetHub: Location = Location::new( 1, - [Parachain(ASSET_HUB_ID), PalletInstance(ASSETS_PALLET_ID), GeneralIndex(RESERVABLE_ASSET_ID.into())] + [Parachain(ASSET_HUB_ID), PalletInstance(ASSET_HUB_ASSETS_PALLET_ID), GeneralIndex(RESERVABLE_ASSET_ID.into())] ); pub UsdtFromAssetHub: Location = Location::new( 1, - [Parachain(ASSET_HUB_ID), PalletInstance(ASSETS_PALLET_ID), GeneralIndex(USDT_ASSET_ID)], + [Parachain(ASSET_HUB_ID), PalletInstance(ASSET_HUB_ASSETS_PALLET_ID), GeneralIndex(USDT_ASSET_ID)], + ); + + pub EthFromEthereum: Location = Location::new( + 2, + [GlobalConsensus(Ethereum { chain_id: SEPOLIA_ID})], ); + /// A PEN2 test asset. + pub LocalPen2Asset: Location = Location::new(0, [PalletInstance(PENPAL_ASSETS_PALLET_ID), GeneralIndex(PEN2_TELEPORTABLE_GENERAL_INDEX.into())]); + /// The Penpal runtime is utilized for testing with various environment setups. /// This storage item provides the opportunity to customize testing scenarios /// by configuring the trusted asset from the `SystemAssetHub`. /// /// By default, it is configured as a `SystemAssetHubLocation` and can be modified using `System::set_storage`. pub storage CustomizableAssetFromSystemAssetHub: Location = SystemAssetHubLocation::get(); - pub storage LocalTeleportableToAssetHub: Location = Location::new( - 0, - [PalletInstance(ASSETS_PALLET_ID), GeneralIndex(TELEPORTABLE_ASSET_ID.into())] - ); + pub storage LocalTeleportableToAssetHub: Location = LocalPen2Asset::get(); pub const NativeAssetId: AssetId = AssetId(Location::here()); pub const NativeAssetFilter: AssetFilter = Wild(AllOf { fun: WildFungible, id: NativeAssetId::get() }); @@ -344,6 +351,7 @@ pub type TrustedReserves = ( ); pub type TrustedTeleporters = ( + AssetFromChain, AssetFromChain, // This is used in the `IsTeleporter` configuration, meaning it accepts // native tokens teleported from Asset Hub. @@ -362,9 +370,6 @@ pub type TrustedAliasers = ( ); pub type WaivedLocations = Equals; -/// `AssetId`/`Balance` converter for `TrustBackedAssets`. -pub type TrustBackedAssetsConvertedConcreteId = - assets_common::TrustBackedAssetsConvertedConcreteId; /// Asset converter for pool assets. /// Used to convert assets in pools to the asset required for fee payment. @@ -373,14 +378,7 @@ pub type TrustBackedAssetsConvertedConcreteId = pub type PoolAssetsExchanger = SingleAssetExchangeAdapter< crate::AssetConversion, crate::NativeAndAssets, - ( - TrustBackedAssetsAsLocation< - TrustBackedAssetsPalletLocation, - Balance, - xcm::latest::Location, - >, - ForeignAssetsConvertedConcreteId, - ), + (LocalAssetsConvertedConcreteId, ForeignAssetsConvertedConcreteId), AccountId, >; @@ -399,22 +397,16 @@ impl xcm_executor::Config for XcmConfig { type Barrier = Barrier; type Weigher = FixedWeightBounds; type Trader = ( - UsingComponents>, // Allow native asset to pay the execution fee UsingComponents>, + // This trader allows to pay with any assets exchangeable to native asset with + // [`AssetConversion`]. cumulus_primitives_utility::SwapFirstAssetTrader< - RelayLocation, + PenpalNativeCurrency, crate::AssetConversion, WeightToFee, crate::NativeAndAssets, - ( - TrustBackedAssetsAsLocation< - TrustBackedAssetsPalletLocation, - Balance, - xcm::latest::Location, - >, - ForeignAssetsConvertedConcreteId, - ), + (LocalAssetsConvertedConcreteId, ForeignAssetsConvertedConcreteId), ResolveAssetTo, AccountId, >, @@ -443,15 +435,6 @@ impl xcm_executor::Config for XcmConfig { type XcmRecorder = PolkadotXcm; } -/// Multiplier used for dedicated `TakeFirstAssetTrader` with `ForeignAssets` instance. -pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger = - AssetFeeAsExistentialDepositMultiplier< - Runtime, - WeightToFee, - pallet_assets::BalanceToAssetBalance, - ForeignAssetsInstance, - >; - /// Converts a local signed origin into an XCM location. Forms the basis for local origins /// sending/executing XCMs. pub type LocalOriginToLocation = SignedToAccountId32; diff --git a/cumulus/xcm/xcm-emulator/src/lib.rs b/cumulus/xcm/xcm-emulator/src/lib.rs index 44fd383dc263a..1c62e235d3723 100644 --- a/cumulus/xcm/xcm-emulator/src/lib.rs +++ b/cumulus/xcm/xcm-emulator/src/lib.rs @@ -1557,17 +1557,17 @@ pub struct TestAccount { /// Default `Args` provided by xcm-emulator to be stored in a `Test` instance #[derive(Clone)] -pub struct TestArgs { +pub struct TestArgs { pub dest: Location, pub beneficiary: Location, pub amount: Balance, pub assets: Assets, - pub asset_id: Option, + pub asset_id: Option, pub fee_asset_item: u32, pub weight_limit: WeightLimit, } -impl TestArgs { +impl TestArgs { /// Returns a [`TestArgs`] instance to be used for the Relay Chain across integration tests. pub fn new_relay(dest: Location, beneficiary_id: AccountId32, amount: Balance) -> Self { Self { @@ -1587,7 +1587,7 @@ impl TestArgs { beneficiary_id: AccountId32, amount: Balance, assets: Assets, - asset_id: Option, + asset_id: Option, fee_asset_item: u32, ) -> Self { Self { diff --git a/prdoc/pr_10726.prdoc b/prdoc/pr_10726.prdoc new file mode 100644 index 0000000000000..1bee6f090ee9e --- /dev/null +++ b/prdoc/pr_10726.prdoc @@ -0,0 +1,30 @@ +title: '[Penpal] cleanup XCM config setup regarding assets' +doc: +- audience: Runtime Dev + description: |- + Closes #7314 by implementing all the subtasks mentioned in https://github.com/paritytech/polkadot-sdk/issues/7314#issuecomment-2792437373. + + ## Changes + Essentially, the main driver of all changes is that we adjust the Penpal runtime as follows: + * Make the native token the base token for buying weight (before it was a hybrid set up, probably not 100% intentional). + * Merge the `Assets` and the `ForeignAssets` pallet into one pallet called `Assets`, as the local assets can also be identified with a location starting with `parents: 0`. + + + ### Test Changes + I tried to keep the changes minimal in the tests in order to not harm any previously established invariants. Hence, in most cases I just did: + + * Add a PEN<>WND pool in order to be able to pay xcm execution fees in WND + * Replaced the Penpal's teleportable asset with it's new location based version. + * In very few cases, I switched from WND to PEN to make the tests easier, when I was sure that no invariants would be harmed. + * The rest should only be renamings. +crates: +- name: penpal-runtime + bump: major +- name: frame-support + bump: minor +- name: parachains-common + bump: minor +- name: emulated-integration-tests-common + bump: major +- name: xcm-emulator + bump: minor diff --git a/substrate/frame/support/src/traits/tokens/imbalance.rs b/substrate/frame/support/src/traits/tokens/imbalance.rs index ee0d7a81c36e3..f37b152cbac3b 100644 --- a/substrate/frame/support/src/traits/tokens/imbalance.rs +++ b/substrate/frame/support/src/traits/tokens/imbalance.rs @@ -25,7 +25,7 @@ use sp_runtime::traits::Saturating; mod on_unbalanced; mod signed_imbalance; mod split_two_ways; -pub use on_unbalanced::{OnUnbalanced, ResolveAssetTo, ResolveTo}; +pub use on_unbalanced::{MaybeResolveAssetTo, OnUnbalanced, ResolveAssetTo, ResolveTo}; pub use signed_imbalance::SignedImbalance; pub use split_two_ways::SplitTwoWays; diff --git a/substrate/frame/support/src/traits/tokens/imbalance/on_unbalanced.rs b/substrate/frame/support/src/traits/tokens/imbalance/on_unbalanced.rs index 461fd203668d8..24ada893521ea 100644 --- a/substrate/frame/support/src/traits/tokens/imbalance/on_unbalanced.rs +++ b/substrate/frame/support/src/traits/tokens/imbalance/on_unbalanced.rs @@ -96,3 +96,21 @@ impl> OnUnbalanced(PhantomData<(Target, F, AccountId)>); +impl>, F: fungibles::Balanced, AccountId> + OnUnbalanced> for MaybeResolveAssetTo +{ + fn on_nonzero_unbalanced(credit: fungibles::Credit) { + if let Some(account) = Target::get() { + let _ = F::resolve(&account, credit).map_err(|c| drop(c)); + } else { + drop(credit); + } + } +}