From 1c286e7c7d9c7cc4b656374c22d5bd4a6e7277f7 Mon Sep 17 00:00:00 2001 From: muharem Date: Thu, 14 Nov 2024 20:54:48 +0100 Subject: [PATCH] remove sufficient asset trader --- .../assets/asset-hub-kusama/src/tests/send.rs | 152 +++++--- .../assets/asset-hub-kusama/src/tests/swap.rs | 130 ------- .../asset-hub-polkadot/src/tests/send.rs | 166 +++++--- .../asset-hub-polkadot/src/tests/swap.rs | 138 ------- .../src/tests/asset_transfers.rs | 2 + .../src/tests/asset_transfers.rs | 2 + .../asset-hub-kusama/src/xcm_config.rs | 60 +-- .../asset-hub-kusama/tests/tests.rs | 60 --- .../asset-hub-kusama/tests/weight_trader.rs | 354 +---------------- .../asset-hub-polkadot/src/xcm_config.rs | 61 +-- .../asset-hub-polkadot/tests/tests.rs | 57 --- .../asset-hub-polkadot/tests/weight_trader.rs | 365 +----------------- 12 files changed, 246 insertions(+), 1301 deletions(-) diff --git a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/send.rs b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/send.rs index d5a24ed0f2..0131612f6e 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/send.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/send.rs @@ -110,53 +110,118 @@ fn send_xcm_from_para_to_asset_hub_paying_fee_with_system_asset() { } /// We tests two things here: -/// - Parachain should be able to send XCM paying its fee at Asset Hub using sufficient asset +/// - Parachain should be able to send XCM paying its fee at Asset Hub using a pool /// - Parachain should be able to create a new Asset at Asset Hub #[test] -fn send_xcm_from_para_to_asset_hub_paying_fee_with_sufficient_asset() { - let para_sovereign_account = AssetHubKusama::sovereign_account_id_of( - AssetHubKusama::sibling_location_of(PenpalA::para_id()), - ); +fn send_xcm_from_para_to_asset_hub_paying_fee_from_pool() { + let asset_native: xcm::v4::Location = asset_hub_kusama_runtime::xcm_config::KsmLocation::get(); + let asset_one = xcm::v4::Location { + parents: 0, + interior: [ + xcm::v4::Junction::PalletInstance(ASSETS_PALLET_ID), + xcm::v4::Junction::GeneralIndex(ASSET_ID.into()), + ] + .into(), + }; + let penpal = AssetHubKusama::sovereign_account_id_of(AssetHubKusama::sibling_location_of( + PenpalA::para_id(), + )); - // Force create and mint sufficient assets for Parachain's sovereign account - AssetHubKusama::force_create_and_mint_asset( - ASSET_ID, - ASSET_MIN_BALANCE, - true, - para_sovereign_account.clone(), - Some(Weight::from_parts(1_019_445_000, 200_000)), - ASSET_MIN_BALANCE * 1000000000, - ); + AssetHubKusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; - // Just a different `asset_id`` that does not exist yet - let new_asset_id = ASSET_ID + 1; + // set up pool with ASSET_ID <> NATIVE pair + assert_ok!(::Assets::create( + ::RuntimeOrigin::signed(AssetHubKusamaSender::get()), + ASSET_ID.into(), + AssetHubKusamaSender::get().into(), + ASSET_MIN_BALANCE, + )); + assert!(::Assets::asset_exists(ASSET_ID)); - // Encoded `create_asset` call to be executed in AssetHub - let call = AssetHubKusama::create_asset_call( - new_asset_id, - ASSET_MIN_BALANCE, - para_sovereign_account.clone(), - ); + assert_ok!(::Assets::mint( + ::RuntimeOrigin::signed(AssetHubKusamaSender::get()), + ASSET_ID.into(), + AssetHubKusamaSender::get().into(), + 3_000_000_000_000, + )); - let origin_kind = OriginKind::SovereignAccount; - let fee_amount = ASSET_MIN_BALANCE * 1000000; - let asset = - ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], fee_amount).into(); + assert_ok!(::AssetConversion::create_pool( + ::RuntimeOrigin::signed(AssetHubKusamaSender::get()), + Box::new(asset_native.clone()), + Box::new(asset_one.clone()), + )); - let root_origin = ::RuntimeOrigin::root(); - let system_para_destination = PenpalA::sibling_location_of(AssetHubKusama::para_id()).into(); - let xcm = xcm_transact_paid_execution(call, origin_kind, asset, para_sovereign_account.clone()); + assert_expected_events!( + AssetHubKusama, + vec![ + RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::PoolCreated { .. }) => {}, + ] + ); - // SA-of-Penpal-on-AHK needs to have balance to pay for asset creation deposit - AssetHubKusama::fund_accounts(vec![( - para_sovereign_account.clone(), - ASSET_HUB_KUSAMA_ED * 10000000000, - )]); + assert_ok!(::AssetConversion::add_liquidity( + ::RuntimeOrigin::signed(AssetHubKusamaSender::get()), + Box::new(asset_native), + Box::new(asset_one), + 1_000_000_000_000, + 2_000_000_000_000, + 0, + 0, + AssetHubKusamaSender::get() + )); + + assert_expected_events!( + AssetHubKusama, + vec![ + RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::LiquidityAdded {lp_token_minted, .. }) => { lp_token_minted: *lp_token_minted == 1414213562273, }, + ] + ); + + // ensure `penpal` sovereign account has no native tokens and mint some `ASSET_ID` + assert_eq!( + ::Balances::free_balance(penpal.clone()), + 0 + ); + + assert_ok!(::Assets::touch_other( + ::RuntimeOrigin::signed(AssetHubKusamaSender::get()), + ASSET_ID.into(), + penpal.clone().into(), + )); + + assert_ok!(::Assets::mint( + ::RuntimeOrigin::signed(AssetHubKusamaSender::get()), + ASSET_ID.into(), + penpal.clone().into(), + 10_000_000_000_000, + )); + }); PenpalA::execute_with(|| { + // send xcm transact from `penpal` account which has only `ASSET_ID` tokens on + // `AssetHubKusama` + let call = AssetHubKusama::force_create_asset_call( + ASSET_ID + 1000, + penpal.clone(), + true, + ASSET_MIN_BALANCE, + ); + + let penpal_root = ::RuntimeOrigin::root(); + let fee_amount = 4_000_000_000_000u128; + let asset_one = + ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], fee_amount).into(); + let asset_hub_location = PenpalA::sibling_location_of(AssetHubKusama::para_id()).into(); + let xcm = xcm_transact_paid_execution( + call, + OriginKind::SovereignAccount, + asset_one, + penpal.clone(), + ); + assert_ok!(::PolkadotXcm::send( - root_origin, - bx!(system_para_destination), + penpal_root, + bx!(asset_hub_location), bx!(xcm), )); @@ -165,22 +230,13 @@ fn send_xcm_from_para_to_asset_hub_paying_fee_with_sufficient_asset() { AssetHubKusama::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; + AssetHubKusama::assert_xcmp_queue_success(None); assert_expected_events!( AssetHubKusama, vec![ - // Burned the fee - RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { - asset_id: *asset_id == ASSET_ID, - owner: *owner == para_sovereign_account, - balance: *balance == fee_amount, - }, - // Asset created - RuntimeEvent::Assets(pallet_assets::Event::Created { asset_id, creator, owner }) => { - asset_id: *asset_id == new_asset_id, - creator: *creator == para_sovereign_account.clone(), - owner: *owner == para_sovereign_account, - }, + RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::SwapCreditExecuted { .. },) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true,.. }) => {}, ] ); }); diff --git a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/swap.rs b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/swap.rs index e31b1b6426..3c8b6cb6f0 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/swap.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/swap.rs @@ -263,133 +263,3 @@ fn cannot_create_pool_from_pool_assets() { ); }); } - -#[test] -fn pay_xcm_fee_with_some_asset_swapped_for_native() { - let asset_native: xcm::v4::Location = asset_hub_kusama_runtime::xcm_config::KsmLocation::get(); - let asset_one = xcm::v4::Location { - parents: 0, - interior: [ - xcm::v4::Junction::PalletInstance(ASSETS_PALLET_ID), - xcm::v4::Junction::GeneralIndex(ASSET_ID.into()), - ] - .into(), - }; - let penpal = AssetHubKusama::sovereign_account_id_of(AssetHubKusama::sibling_location_of( - PenpalA::para_id(), - )); - - AssetHubKusama::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - - // set up pool with ASSET_ID <> NATIVE pair - assert_ok!(::Assets::create( - ::RuntimeOrigin::signed(AssetHubKusamaSender::get()), - ASSET_ID.into(), - AssetHubKusamaSender::get().into(), - ASSET_MIN_BALANCE, - )); - assert!(::Assets::asset_exists(ASSET_ID)); - - assert_ok!(::Assets::mint( - ::RuntimeOrigin::signed(AssetHubKusamaSender::get()), - ASSET_ID.into(), - AssetHubKusamaSender::get().into(), - 3_000_000_000_000, - )); - - assert_ok!(::AssetConversion::create_pool( - ::RuntimeOrigin::signed(AssetHubKusamaSender::get()), - Box::new(asset_native.clone()), - Box::new(asset_one.clone()), - )); - - assert_expected_events!( - AssetHubKusama, - vec![ - RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::PoolCreated { .. }) => {}, - ] - ); - - assert_ok!(::AssetConversion::add_liquidity( - ::RuntimeOrigin::signed(AssetHubKusamaSender::get()), - Box::new(asset_native), - Box::new(asset_one), - 1_000_000_000_000, - 2_000_000_000_000, - 0, - 0, - AssetHubKusamaSender::get() - )); - - assert_expected_events!( - AssetHubKusama, - vec![ - RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::LiquidityAdded {lp_token_minted, .. }) => { lp_token_minted: *lp_token_minted == 1414213562273, }, - ] - ); - - // ensure `penpal` sovereign account has no native tokens and mint some `ASSET_ID` - assert_eq!( - ::Balances::free_balance(penpal.clone()), - 0 - ); - - assert_ok!(::Assets::touch_other( - ::RuntimeOrigin::signed(AssetHubKusamaSender::get()), - ASSET_ID.into(), - penpal.clone().into(), - )); - - assert_ok!(::Assets::mint( - ::RuntimeOrigin::signed(AssetHubKusamaSender::get()), - ASSET_ID.into(), - penpal.clone().into(), - 10_000_000_000_000, - )); - }); - - PenpalA::execute_with(|| { - // send xcm transact from `penpal` account which has only `ASSET_ID` tokens on - // `AssetHubKusama` - let call = AssetHubKusama::force_create_asset_call( - ASSET_ID + 1000, - penpal.clone(), - true, - ASSET_MIN_BALANCE, - ); - - let penpal_root = ::RuntimeOrigin::root(); - let fee_amount = 4_000_000_000_000u128; - let asset_one = - ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], fee_amount).into(); - let asset_hub_location = PenpalA::sibling_location_of(AssetHubKusama::para_id()).into(); - let xcm = xcm_transact_paid_execution( - call, - OriginKind::SovereignAccount, - asset_one, - penpal.clone(), - ); - - assert_ok!(::PolkadotXcm::send( - penpal_root, - bx!(asset_hub_location), - bx!(xcm), - )); - - PenpalA::assert_xcm_pallet_sent(); - }); - - AssetHubKusama::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - - AssetHubKusama::assert_xcmp_queue_success(None); - assert_expected_events!( - AssetHubKusama, - vec![ - RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::SwapCreditExecuted { .. },) => {}, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true,.. }) => {}, - ] - ); - }); -} diff --git a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/send.rs b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/send.rs index 23e6fe4323..cf2a3094e1 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/send.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/send.rs @@ -110,77 +110,141 @@ fn send_xcm_from_para_to_asset_hub_paying_fee_with_system_asset() { } /// We tests two things here: -/// - Parachain should be able to send XCM paying its fee at Asset Hub using sufficient asset +/// - Parachain should be able to send XCM paying its fee at Asset Hub using a pool /// - Parachain should be able to create a new Asset at Asset Hub #[test] -fn send_xcm_from_para_to_asset_hub_paying_fee_with_sufficient_asset() { - let para_sovereign_account = AssetHubPolkadot::sovereign_account_id_of( - AssetHubPolkadot::sibling_location_of(PenpalA::para_id()), - ); +fn send_xcm_from_para_to_asset_hub_paying_fee_from_pool() { + use frame_support::traits::fungible::Mutate; + + let asset_native: xcm::v4::Location = + asset_hub_polkadot_runtime::xcm_config::DotLocation::get(); + let asset_one = xcm::v4::Location { + parents: 0, + interior: [ + xcm::v4::Junction::PalletInstance(ASSETS_PALLET_ID), + xcm::v4::Junction::GeneralIndex(ASSET_ID.into()), + ] + .into(), + }; + let penpal = AssetHubPolkadot::sovereign_account_id_of(AssetHubPolkadot::sibling_location_of( + PenpalB::para_id(), + )); - // Force create and mint sufficient assets for Parachain's sovereign account - AssetHubPolkadot::force_create_and_mint_asset( - ASSET_ID, - ASSET_MIN_BALANCE, - true, - para_sovereign_account.clone(), - Some(Weight::from_parts(1_019_445_000, 200_000)), - ASSET_MIN_BALANCE * 1000000000, - ); + AssetHubPolkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; - // Just a different `asset_id`` that does not exist yet - let new_asset_id = ASSET_ID + 1; + // set up pool with ASSET_ID <> NATIVE pair + assert_ok!(::Assets::create( + ::RuntimeOrigin::signed(AssetHubPolkadotSender::get()), + ASSET_ID.into(), + AssetHubPolkadotSender::get().into(), + ASSET_MIN_BALANCE, + )); + assert!(::Assets::asset_exists(ASSET_ID)); - // Encoded `create_asset` call to be executed in AssetHub - let call = AssetHubPolkadot::create_asset_call( - new_asset_id, - ASSET_MIN_BALANCE, - para_sovereign_account.clone(), - ); + assert_ok!(::Assets::mint( + ::RuntimeOrigin::signed(AssetHubPolkadotSender::get()), + ASSET_ID.into(), + AssetHubPolkadotSender::get().into(), + 3_000_000_000_000, + )); - let origin_kind = OriginKind::SovereignAccount; - let fee_amount = ASSET_MIN_BALANCE * 1000000; - let asset = - ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], fee_amount).into(); + ::Balances::set_balance( + &AssetHubPolkadotSender::get(), + 3_000_000_000_000, + ); - let root_origin = ::RuntimeOrigin::root(); - let system_para_destination = PenpalA::sibling_location_of(AssetHubPolkadot::para_id()).into(); - let xcm = xcm_transact_paid_execution(call, origin_kind, asset, para_sovereign_account.clone()); + assert_ok!(::AssetConversion::create_pool( + ::RuntimeOrigin::signed(AssetHubPolkadotSender::get()), + Box::new(asset_native.clone()), + Box::new(asset_one.clone()), + )); - // SA-of-Penpal-on-AHP needs to have balance to pay for asset creation deposit - AssetHubPolkadot::fund_accounts(vec![( - para_sovereign_account.clone(), - ASSET_HUB_POLKADOT_ED * 10000000000, - )]); + assert_expected_events!( + AssetHubPolkadot, + vec![ + RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::PoolCreated { .. }) => {}, + ] + ); - PenpalA::execute_with(|| { - assert_ok!(::PolkadotXcm::send( - root_origin, - bx!(system_para_destination), + assert_ok!(::AssetConversion::add_liquidity( + ::RuntimeOrigin::signed(AssetHubPolkadotSender::get()), + Box::new(asset_native), + Box::new(asset_one), + 1_000_000_000_000, + 2_000_000_000_000, + 0, + 0, + AssetHubPolkadotSender::get() + )); + + assert_expected_events!( + AssetHubPolkadot, + vec![ + RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::LiquidityAdded {lp_token_minted, .. }) => { lp_token_minted: *lp_token_minted == 1414213562273, }, + ] + ); + + // ensure `penpal` sovereign account has no native tokens and mint some `ASSET_ID` + assert_eq!( + ::Balances::free_balance(penpal.clone()), + 0 + ); + + assert_ok!(::Assets::touch_other( + ::RuntimeOrigin::signed(AssetHubPolkadotSender::get()), + ASSET_ID.into(), + penpal.clone().into(), + )); + + assert_ok!(::Assets::mint( + ::RuntimeOrigin::signed(AssetHubPolkadotSender::get()), + ASSET_ID.into(), + penpal.clone().into(), + 10_000_000_000_000, + )); + }); + + PenpalB::execute_with(|| { + // send xcm transact from `penpal` account which as only `ASSET_ID` tokens on + // `AssetHubPolkadot` + let call = AssetHubPolkadot::force_create_asset_call( + ASSET_ID + 1000, + penpal.clone(), + true, + ASSET_MIN_BALANCE, + ); + + let penpal_root = ::RuntimeOrigin::root(); + let fee_amount = 4_000_000_000_000u128; + let asset_one = + ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], fee_amount).into(); + let asset_hub_location = PenpalB::sibling_location_of(AssetHubPolkadot::para_id()).into(); + let xcm = xcm_transact_paid_execution( + call, + OriginKind::SovereignAccount, + asset_one, + penpal.clone(), + ); + + assert_ok!(::PolkadotXcm::send( + penpal_root, + bx!(asset_hub_location), bx!(xcm), )); - PenpalA::assert_xcm_pallet_sent(); + PenpalB::assert_xcm_pallet_sent(); }); AssetHubPolkadot::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; + AssetHubPolkadot::assert_xcmp_queue_success(None); assert_expected_events!( AssetHubPolkadot, vec![ - // Burned the fee - RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { - asset_id: *asset_id == ASSET_ID, - owner: *owner == para_sovereign_account, - balance: *balance == fee_amount, - }, - // Asset created - RuntimeEvent::Assets(pallet_assets::Event::Created { asset_id, creator, owner }) => { - asset_id: *asset_id == new_asset_id, - creator: *creator == para_sovereign_account.clone(), - owner: *owner == para_sovereign_account, - }, + RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::SwapCreditExecuted { .. },) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true,.. }) => {}, ] ); }); diff --git a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/swap.rs b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/swap.rs index c3188c67b4..5b6b11b5fa 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/swap.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/swap.rs @@ -276,141 +276,3 @@ fn cannot_create_pool_from_pool_assets() { ); }); } - -#[test] -fn pay_xcm_fee_with_some_asset_swapped_for_native() { - use frame_support::traits::fungible::Mutate; - - let asset_native: xcm::v4::Location = - asset_hub_polkadot_runtime::xcm_config::DotLocation::get(); - let asset_one = xcm::v4::Location { - parents: 0, - interior: [ - xcm::v4::Junction::PalletInstance(ASSETS_PALLET_ID), - xcm::v4::Junction::GeneralIndex(ASSET_ID.into()), - ] - .into(), - }; - let penpal = AssetHubPolkadot::sovereign_account_id_of(AssetHubPolkadot::sibling_location_of( - PenpalB::para_id(), - )); - - AssetHubPolkadot::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - - // set up pool with ASSET_ID <> NATIVE pair - assert_ok!(::Assets::create( - ::RuntimeOrigin::signed(AssetHubPolkadotSender::get()), - ASSET_ID.into(), - AssetHubPolkadotSender::get().into(), - ASSET_MIN_BALANCE, - )); - assert!(::Assets::asset_exists(ASSET_ID)); - - assert_ok!(::Assets::mint( - ::RuntimeOrigin::signed(AssetHubPolkadotSender::get()), - ASSET_ID.into(), - AssetHubPolkadotSender::get().into(), - 3_000_000_000_000, - )); - - ::Balances::set_balance( - &AssetHubPolkadotSender::get(), - 3_000_000_000_000, - ); - - assert_ok!(::AssetConversion::create_pool( - ::RuntimeOrigin::signed(AssetHubPolkadotSender::get()), - Box::new(asset_native.clone()), - Box::new(asset_one.clone()), - )); - - assert_expected_events!( - AssetHubPolkadot, - vec![ - RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::PoolCreated { .. }) => {}, - ] - ); - - assert_ok!(::AssetConversion::add_liquidity( - ::RuntimeOrigin::signed(AssetHubPolkadotSender::get()), - Box::new(asset_native), - Box::new(asset_one), - 1_000_000_000_000, - 2_000_000_000_000, - 0, - 0, - AssetHubPolkadotSender::get() - )); - - assert_expected_events!( - AssetHubPolkadot, - vec![ - RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::LiquidityAdded {lp_token_minted, .. }) => { lp_token_minted: *lp_token_minted == 1414213562273, }, - ] - ); - - // ensure `penpal` sovereign account has no native tokens and mint some `ASSET_ID` - assert_eq!( - ::Balances::free_balance(penpal.clone()), - 0 - ); - - assert_ok!(::Assets::touch_other( - ::RuntimeOrigin::signed(AssetHubPolkadotSender::get()), - ASSET_ID.into(), - penpal.clone().into(), - )); - - assert_ok!(::Assets::mint( - ::RuntimeOrigin::signed(AssetHubPolkadotSender::get()), - ASSET_ID.into(), - penpal.clone().into(), - 10_000_000_000_000, - )); - }); - - PenpalB::execute_with(|| { - // send xcm transact from `penpal` account which as only `ASSET_ID` tokens on - // `AssetHubPolkadot` - let call = AssetHubPolkadot::force_create_asset_call( - ASSET_ID + 1000, - penpal.clone(), - true, - ASSET_MIN_BALANCE, - ); - - let penpal_root = ::RuntimeOrigin::root(); - let fee_amount = 4_000_000_000_000u128; - let asset_one = - ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], fee_amount).into(); - let asset_hub_location = PenpalB::sibling_location_of(AssetHubPolkadot::para_id()).into(); - let xcm = xcm_transact_paid_execution( - call, - OriginKind::SovereignAccount, - asset_one, - penpal.clone(), - ); - - assert_ok!(::PolkadotXcm::send( - penpal_root, - bx!(asset_hub_location), - bx!(xcm), - )); - - PenpalB::assert_xcm_pallet_sent(); - }); - - AssetHubPolkadot::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - - AssetHubPolkadot::assert_xcmp_queue_success(None); - assert_expected_events!( - AssetHubPolkadot, - vec![ - RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::SwapCreditExecuted { .. },) => {}, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true,.. }) => {}, - ] - ); - }); -} diff --git a/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/tests/asset_transfers.rs b/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/tests/asset_transfers.rs index 0e7621dabd..92f23859e0 100644 --- a/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/tests/asset_transfers.rs +++ b/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/tests/asset_transfers.rs @@ -368,6 +368,8 @@ fn send_ksm_from_penpal_kusama_through_asset_hub_kusama_to_asset_hub_polkadot() let receiver_ksm_before = foreign_balance_on_ah_polkadot(ksm_at_asset_hub_polkadot.clone(), &receiver); + set_up_pool_with_dot_on_ah_polkadot(ksm_at_asset_hub_polkadot.clone(), true); + // Send KSMs over bridge { let destination = asset_hub_polkadot_location(); diff --git a/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/asset_transfers.rs b/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/asset_transfers.rs index 6ce75f3441..73dd4d1f6b 100644 --- a/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/asset_transfers.rs +++ b/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/asset_transfers.rs @@ -353,6 +353,8 @@ fn send_dot_from_penpal_polkadot_through_asset_hub_polkadot_to_asset_hub_kusama( let receiver_dot_before = foreign_balance_on_ah_kusama(dot_at_asset_hub_kusama.clone(), &receiver); + set_up_pool_with_ksm_on_ah_kusama(dot_at_asset_hub_kusama.clone(), true); + // Send DOTs over bridge { let destination = asset_hub_kusama_location(); diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs index 0ab78671eb..266be4da53 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs @@ -14,12 +14,12 @@ // limitations under the License. use super::{ - AccountId, AllPalletsWithSystem, AssetConversion, Assets, Authorship, Balance, Balances, - CollatorSelection, NativeAndAssets, ParachainInfo, ParachainSystem, PolkadotXcm, PoolAssets, + AccountId, AllPalletsWithSystem, AssetConversion, Assets, Balance, Balances, CollatorSelection, + NativeAndAssets, ParachainInfo, ParachainSystem, PolkadotXcm, PoolAssets, PriceForParentDelivery, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, ToPolkadotXcmRouter, - TrustBackedAssetsInstance, WeightToFee, XcmpQueue, + WeightToFee, XcmpQueue, }; -use crate::{ForeignAssets, ForeignAssetsInstance}; +use crate::ForeignAssets; use assets_common::{ matching::{FromSiblingParachain, IsForeignConcreteAsset}, TrustBackedAssetsAsLocation, @@ -35,12 +35,12 @@ use frame_support::{ use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::xcm_config::{ - AllSiblingSystemParachains, AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem, - ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains, + AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, + RelayOrOtherSystemParachains, }; use polkadot_parachain_primitives::primitives::Sibling; use snowbridge_router_primitives::inbound::GlobalConsensusEthereumConvertsFor; -use sp_runtime::traits::{AccountIdConversion, ConvertInto}; +use sp_runtime::traits::AccountIdConversion; use system_parachains_constants::TREASURY_PALLET_ID; use xcm::latest::prelude::*; use xcm_builder::{ @@ -225,7 +225,6 @@ pub type XcmOriginToTransactDispatchOrigin = ( parameter_types! { pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - pub XcmAssetFeesReceiver: Option = Authorship::author(); } pub struct ParentOrParentsPlurality; @@ -265,13 +264,6 @@ pub type Barrier = TrailingSetTopicAsId< >, >; -pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentialDepositMultiplier< - Runtime, - WeightToFee, - pallet_assets::BalanceToAssetBalance, - TrustBackedAssetsInstance, ->; - /// Locations that will not be charged fees in the executor, /// either execution or delivery. /// We only waive fees for system functions, which these locations represent. @@ -289,15 +281,6 @@ pub type TrustedTeleporters = ( IsForeignConcreteAsset>>, ); -/// Multiplier used for dedicated `TakeFirstAssetTrader` with `ForeignAssets` instance. -pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger = - AssetFeeAsExistentialDepositMultiplier< - Runtime, - WeightToFee, - pallet_assets::BalanceToAssetBalance, - ForeignAssetsInstance, - >; - pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -344,32 +327,6 @@ impl xcm_executor::Config for XcmConfig { ResolveAssetTo, AccountId, >, - // This trader allows to pay with `is_sufficient=true` "Trust Backed" assets from dedicated - // `pallet_assets` instance - `Assets`. - cumulus_primitives_utility::TakeFirstAssetTrader< - AccountId, - AssetFeeAsExistentialDepositMultiplierFeeCharger, - TrustBackedAssetsConvertedConcreteId, - Assets, - cumulus_primitives_utility::XcmFeesTo32ByteAccount< - FungiblesTransactor, - AccountId, - XcmAssetFeesReceiver, - >, - >, - // This trader allows to pay with `is_sufficient=true` "Foreign" assets from dedicated - // `pallet_assets` instance - `ForeignAssets`. - cumulus_primitives_utility::TakeFirstAssetTrader< - AccountId, - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, - ForeignAssetsConvertedConcreteId, - ForeignAssets, - cumulus_primitives_utility::XcmFeesTo32ByteAccount< - ForeignFungiblesTransactor, - AccountId, - XcmAssetFeesReceiver, - >, - >, ); type ResponseHandler = PolkadotXcm; type AssetTrap = PolkadotXcm; @@ -603,8 +560,7 @@ pub mod bridging { } } impl, OriginLocation: Get> - ContainsPair - for RemoteAssetFromLocation + ContainsPair for RemoteAssetFromLocation { fn contains(asset: &Asset, origin: &Location) -> bool { >::contains(&asset.id.0, origin) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs index 4ae5e17a73..9807ac1aeb 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs @@ -496,66 +496,6 @@ fn receive_reserve_asset_deposited_dot_from_asset_hub_polkadot_fees_paid_by_pool ) } -#[test] -fn receive_reserve_asset_deposited_dot_from_asset_hub_polkadot_fees_paid_by_sufficient_asset_works() -{ - const BLOCK_AUTHOR_ACCOUNT: [u8; 32] = [13; 32]; - let block_author_account = AccountId::from(BLOCK_AUTHOR_ACCOUNT); - let staking_pot = >::account_id(); - - let foreign_asset_id_location = xcm::v4::Location::new( - 2, - [xcm::v4::Junction::GlobalConsensus(xcm::v4::NetworkId::Polkadot)], - ); - let foreign_asset_id_minimum_balance = 1_000_000_000; - // sovereign account as foreign asset owner (can be whoever for this scenario) - let foreign_asset_owner = LocationToAccountId::convert_location(&Location::parent()).unwrap(); - let foreign_asset_create_params = - (foreign_asset_owner, foreign_asset_id_location.clone(), foreign_asset_id_minimum_balance); - - remove_when_updated_to_stable2409::receive_reserve_asset_deposited_from_different_consensus_works::< - Runtime, - AllPalletsWithoutSystem, - XcmConfig, - ForeignAssetsInstance, - >( - collator_session_keys().add(collator_session_key(BLOCK_AUTHOR_ACCOUNT)), - ExistentialDeposit::get(), - AccountId::from([73; 32]), - block_author_account.clone(), - // receiving DOTs - foreign_asset_create_params, - 1000000000000, - bridging_to_asset_hub_polkadot, - ( - PalletInstance(bp_bridge_hub_kusama::WITH_BRIDGE_KUSAMA_TO_POLKADOT_MESSAGES_PALLET_INDEX).into(), - GlobalConsensus(Polkadot), - Parachain(1000).into() - ), - || { - // check block author before - assert_eq!( - ForeignAssets::balance( - foreign_asset_id_location.clone(), - &block_author_account - ), - 0 - ); - }, - || { - // `TakeFirstAssetTrader` puts fees to the block author - assert!( - ForeignAssets::balance( - foreign_asset_id_location.clone(), - &block_author_account - ) > 0 - ); - // nothing adds fees to stakting_pot (e.g. `SwapFirstAssetTrader`, ...) - assert_eq!(Balances::free_balance(&staking_pot), 0); - } - ) -} - #[test] fn reserve_transfer_native_asset_to_non_teleport_para_works() { asset_test_utils::test_cases::reserve_transfer_native_asset_to_non_teleport_para_works::< diff --git a/system-parachains/asset-hubs/asset-hub-kusama/tests/weight_trader.rs b/system-parachains/asset-hubs/asset-hub-kusama/tests/weight_trader.rs index 762f3cc93d..a30b736847 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/tests/weight_trader.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/tests/weight_trader.rs @@ -16,12 +16,9 @@ //! Tests for `WeighTrader` type of XCM Executor. use asset_hub_kusama_runtime::{ - xcm_config::{ - AssetFeeAsExistentialDepositMultiplierFeeCharger, KsmLocation, StakingPot, - TrustBackedAssetsPalletLocation, XcmConfig, - }, - AllPalletsWithoutSystem, AssetConversion, Assets, Balances, ExistentialDeposit, ForeignAssets, - Runtime, SessionKeys, + xcm_config::{KsmLocation, StakingPot, TrustBackedAssetsPalletLocation, XcmConfig}, + AllPalletsWithoutSystem, AssetConversion, Assets, Balances, ForeignAssets, Runtime, + SessionKeys, }; use asset_test_utils::ExtBuilder; use assets_common::AssetIdForTrustBackedAssetsConvert; @@ -33,10 +30,6 @@ use frame_support::{ }, weights::WeightToFee as WeightToFeeT, }; - -use cumulus_primitives_utility::ChargeWeightInFungibles; -use frame_support::assert_noop; - use parachains_common::{AccountId, AuraId}; use sp_runtime::traits::MaybeEquivalence; use system_parachains_constants::kusama::{currency::*, fee::WeightToFee}; @@ -48,347 +41,6 @@ const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32]; type RuntimeHelper = asset_test_utils::RuntimeHelper; -type AssetIdForTrustBackedAssetsConvertLatest = - assets_common::AssetIdForTrustBackedAssetsConvert; - -#[test] -fn test_asset_xcm_trader() { - ExtBuilder::::default() - .with_collators(vec![AccountId::from(ALICE)]) - .with_session_keys(vec![( - AccountId::from(ALICE), - AccountId::from(ALICE), - SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }, - )]) - .build() - .execute_with(|| { - // We need root origin to create a sufficient asset - let minimum_asset_balance = 3333333_u128; - let local_asset_id = 1; - assert_ok!(Assets::force_create( - RuntimeHelper::root_origin(), - local_asset_id.into(), - AccountId::from(ALICE).into(), - true, - minimum_asset_balance - )); - - // We first mint enough asset for the account to exist for assets - assert_ok!(Assets::mint( - RuntimeHelper::origin_of(AccountId::from(ALICE)), - local_asset_id.into(), - AccountId::from(ALICE).into(), - minimum_asset_balance - )); - - // get asset id as location - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap(); - - // Set Alice as block author, who will receive fees - RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); - - // We are going to buy 4e9 weight - let bought = Weight::from_parts(4_000_000_000u64, 0); - - // Lets calculate amount needed - let asset_amount_needed = - AssetFeeAsExistentialDepositMultiplierFeeCharger::charge_weight_in_fungibles( - local_asset_id, - bought, - ) - .expect("failed to compute"); - - // Lets pay with: asset_amount_needed + asset_amount_extra - let asset_amount_extra = 100_u128; - let asset: Asset = - (asset_location.clone(), asset_amount_needed + asset_amount_extra).into(); - - let mut trader = ::Trader::new(); - let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - - // Lets buy_weight and make sure buy_weight does not return an error - let unused_assets = trader.buy_weight(bought, asset.into(), &ctx).expect("Expected Ok"); - // Check whether a correct amount of unused assets is returned - assert_ok!(unused_assets.ensure_contains(&(asset_location, asset_amount_extra).into())); - - // Drop trader - drop(trader); - - // Make sure author(Alice) has received the amount - assert_eq!( - Assets::balance(local_asset_id, AccountId::from(ALICE)), - minimum_asset_balance + asset_amount_needed - ); - - // We also need to ensure the total supply increased - assert_eq!( - Assets::total_supply(local_asset_id), - minimum_asset_balance + asset_amount_needed - ); - }); -} - -#[test] -fn test_asset_xcm_trader_with_refund() { - ExtBuilder::::default() - .with_collators(vec![AccountId::from(ALICE)]) - .with_session_keys(vec![( - AccountId::from(ALICE), - AccountId::from(ALICE), - SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }, - )]) - .build() - .execute_with(|| { - // We need root origin to create a sufficient asset - // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( - RuntimeHelper::root_origin(), - 1.into(), - AccountId::from(ALICE).into(), - true, - ExistentialDeposit::get() - )); - - // We first mint enough asset for the account to exist for assets - assert_ok!(Assets::mint( - RuntimeHelper::origin_of(AccountId::from(ALICE)), - 1.into(), - AccountId::from(ALICE).into(), - ExistentialDeposit::get() - )); - - let mut trader = ::Trader::new(); - let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - - // Set Alice as block author, who will receive fees - RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); - - // We are going to buy 4e9 weight - let bought = Weight::from_parts(4_000_000_000u64, 0); - - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); - - // lets calculate amount needed - let amount_bought = WeightToFee::weight_to_fee(&bought); - - let asset: Asset = (asset_location.clone(), amount_bought).into(); - - // Make sure buy_weight does not return an error - assert_ok!(trader.buy_weight(bought, asset.clone().into(), &ctx)); - - // Make sure again buy_weight does return an error - // This assert relies on the fact, that we use `TakeFirstAssetTrader` in `WeightTrader` - // tuple chain, which cannot be called twice - assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive); - - // We actually use half of the weight - let weight_used = bought / 2; - - // Make sure refurnd works. - let amount_refunded = WeightToFee::weight_to_fee(&(bought - weight_used)); - - assert_eq!( - trader.refund_weight(bought - weight_used, &ctx), - Some((asset_location, amount_refunded).into()) - ); - - // Drop trader - drop(trader); - - // We only should have paid for half of the bought weight - let fees_paid = WeightToFee::weight_to_fee(&weight_used); - - assert_eq!( - Assets::balance(1, AccountId::from(ALICE)), - ExistentialDeposit::get() + fees_paid - ); - - // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get() + fees_paid); - }); -} - -#[test] -fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { - ExtBuilder::::default() - .with_collators(vec![AccountId::from(ALICE)]) - .with_session_keys(vec![( - AccountId::from(ALICE), - AccountId::from(ALICE), - SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }, - )]) - .build() - .execute_with(|| { - // We need root origin to create a sufficient asset - // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( - RuntimeHelper::root_origin(), - 1.into(), - AccountId::from(ALICE).into(), - true, - ExistentialDeposit::get() - )); - - let mut trader = ::Trader::new(); - let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - - // Set Alice as block author, who will receive fees - RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); - - // We are going to buy small amount - let bought = Weight::from_parts(50_000_000u64, 0); - - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); - - let amount_bought = WeightToFee::weight_to_fee(&bought); - - assert!( - amount_bought < ExistentialDeposit::get(), - "we are testing what happens when the amount does not exceed ED" - ); - - let asset: Asset = (asset_location, amount_bought).into(); - - // Buy weight should return an error - assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive); - - // not credited since the ED is higher than this value - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0); - - // We also need to ensure the total supply did not increase - assert_eq!(Assets::total_supply(1), 0); - }); -} - -#[test] -fn test_that_buying_ed_refund_does_not_refund() { - ExtBuilder::::default() - .with_collators(vec![AccountId::from(ALICE)]) - .with_session_keys(vec![( - AccountId::from(ALICE), - AccountId::from(ALICE), - SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }, - )]) - .build() - .execute_with(|| { - // We need root origin to create a sufficient asset - // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( - RuntimeHelper::root_origin(), - 1.into(), - AccountId::from(ALICE).into(), - true, - ExistentialDeposit::get() - )); - - let mut trader = ::Trader::new(); - let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - - // Set Alice as block author, who will receive fees - RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); - - // We are gonna buy ED - let bought = Weight::from_parts(ExistentialDeposit::get().try_into().unwrap(), 0); - - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); - - let amount_bought = WeightToFee::weight_to_fee(&bought); - - assert!( - amount_bought < ExistentialDeposit::get(), - "we are testing what happens when the amount does not exceed ED" - ); - - // We know we will have to buy at least ED, so lets make sure first it will - // fail with a payment of less than ED - let asset: Asset = (asset_location.clone(), amount_bought).into(); - assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive); - - // Now lets buy ED at least - let asset: Asset = (asset_location, ExistentialDeposit::get()).into(); - - // Buy weight should work - assert_ok!(trader.buy_weight(bought, asset.into(), &ctx)); - - // Should return None. We have a specific check making sure we dont go below ED for - // drop payment - assert_eq!(trader.refund_weight(bought, &ctx), None); - - // Drop trader - drop(trader); - - // Make sure author(Alice) has received the amount - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get()); - - // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get()); - }); -} - -#[test] -fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { - ExtBuilder::::default() - .with_collators(vec![AccountId::from(ALICE)]) - .with_session_keys(vec![( - AccountId::from(ALICE), - AccountId::from(ALICE), - SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }, - )]) - .build() - .execute_with(|| { - // Create a non-sufficient asset with specific existential deposit - let minimum_asset_balance = 1_000_000_u128; - assert_ok!(Assets::force_create( - RuntimeHelper::root_origin(), - 1.into(), - AccountId::from(ALICE).into(), - false, - minimum_asset_balance - )); - - // We first mint enough asset for the account to exist for assets - assert_ok!(Assets::mint( - RuntimeHelper::origin_of(AccountId::from(ALICE)), - 1.into(), - AccountId::from(ALICE).into(), - minimum_asset_balance - )); - - let mut trader = ::Trader::new(); - let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - - // Set Alice as block author, who will receive fees - RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); - - // We are going to buy 4e9 weight - let bought = Weight::from_parts(4_000_000_000u64, 0); - - // lets calculate amount needed - let asset_amount_needed = WeightToFee::weight_to_fee(&bought); - - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); - - let asset: Asset = (asset_location, asset_amount_needed).into(); - - // Make sure again buy_weight does return an error - assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive); - - // Drop trader - drop(trader); - - // Make sure author(Alice) has NOT received the amount - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), minimum_asset_balance); - - // We also need to ensure the total supply NOT increased - assert_eq!(Assets::total_supply(1), minimum_asset_balance); - }); -} - #[test] fn test_buy_and_refund_weight_with_native() { ExtBuilder::::default() diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index a485abd6cb..09bce4de71 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -14,12 +14,11 @@ // limitations under the License. use super::{ - AccountId, AllPalletsWithSystem, AssetConversion, Assets, Authorship, Balance, Balances, - CollatorSelection, ForeignAssets, NativeAndAssets, ParachainInfo, ParachainSystem, PolkadotXcm, - PoolAssets, PriceForParentDelivery, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - ToKusamaXcmRouter, TrustBackedAssetsInstance, WeightToFee, XcmpQueue, + AccountId, AllPalletsWithSystem, AssetConversion, Assets, Balance, Balances, CollatorSelection, + ForeignAssets, NativeAndAssets, ParachainInfo, ParachainSystem, PolkadotXcm, PoolAssets, + PriceForParentDelivery, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, ToKusamaXcmRouter, + WeightToFee, XcmpQueue, }; -use crate::ForeignAssetsInstance; use assets_common::{ matching::{FromNetwork, FromSiblingParachain, IsForeignConcreteAsset}, TrustBackedAssetsAsLocation, @@ -35,13 +34,13 @@ use frame_support::{ use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::xcm_config::{ - AllSiblingSystemParachains, AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem, - ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains, + AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, + RelayOrOtherSystemParachains, }; use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_constants::system_parachain; use snowbridge_router_primitives::inbound::GlobalConsensusEthereumConvertsFor; -use sp_runtime::traits::{AccountIdConversion, ConvertInto}; +use sp_runtime::traits::AccountIdConversion; use system_parachains_constants::TREASURY_PALLET_ID; use xcm::latest::prelude::*; use xcm_builder::{ @@ -224,7 +223,6 @@ pub type XcmOriginToTransactDispatchOrigin = ( parameter_types! { pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - pub XcmAssetFeesReceiver: Option = Authorship::author(); } pub struct FellowshipEntities; @@ -325,13 +323,6 @@ pub type Barrier = TrailingSetTopicAsId< >, >; -pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentialDepositMultiplier< - Runtime, - WeightToFee, - pallet_assets::BalanceToAssetBalance, - TrustBackedAssetsInstance, ->; - /// Locations that will not be charged fees in the executor, /// either execution or delivery. /// We only waive fees for system functions, which these locations represent. @@ -351,15 +342,6 @@ pub type TrustedTeleporters = ( IsForeignConcreteAsset>>, ); -/// Multiplier used for dedicated `TakeFirstAssetTrader` with `ForeignAssets` instance. -pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger = - AssetFeeAsExistentialDepositMultiplier< - Runtime, - WeightToFee, - pallet_assets::BalanceToAssetBalance, - ForeignAssetsInstance, - >; - pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -409,32 +391,6 @@ impl xcm_executor::Config for XcmConfig { ResolveAssetTo, AccountId, >, - // This trader allows to pay with `is_sufficient=true` "Trust Backed" assets from dedicated - // `pallet_assets` instance - `Assets`. - cumulus_primitives_utility::TakeFirstAssetTrader< - AccountId, - AssetFeeAsExistentialDepositMultiplierFeeCharger, - TrustBackedAssetsConvertedConcreteId, - Assets, - cumulus_primitives_utility::XcmFeesTo32ByteAccount< - FungiblesTransactor, - AccountId, - XcmAssetFeesReceiver, - >, - >, - // This trader allows to pay with `is_sufficient=true` "Foreign" assets from dedicated - // `pallet_assets` instance - `ForeignAssets`. - cumulus_primitives_utility::TakeFirstAssetTrader< - AccountId, - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, - ForeignAssetsConvertedConcreteId, - ForeignAssets, - cumulus_primitives_utility::XcmFeesTo32ByteAccount< - ForeignFungiblesTransactor, - AccountId, - XcmAssetFeesReceiver, - >, - >, ); type ResponseHandler = PolkadotXcm; type AssetTrap = PolkadotXcm; @@ -670,8 +626,7 @@ pub mod bridging { } } impl, OriginLocation: Get> - ContainsPair - for RemoteAssetFromLocation + ContainsPair for RemoteAssetFromLocation { fn contains(asset: &Asset, origin: &Location) -> bool { >::contains(&asset.id.0, origin) diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs index 63cb71cfad..018b4f66a0 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs @@ -496,63 +496,6 @@ fn receive_reserve_asset_deposited_ksm_from_asset_hub_kusama_fees_paid_by_pool_s ) } -#[test] -fn receive_reserve_asset_deposited_ksm_from_asset_hub_kusama_fees_paid_by_sufficient_asset_works() { - const BLOCK_AUTHOR_ACCOUNT: [u8; 32] = [13; 32]; - let block_author_account = AccountId::from(BLOCK_AUTHOR_ACCOUNT); - let staking_pot = >::account_id(); - - let foreign_asset_id_location = - xcm::v4::Location::new(2, [xcm::v4::Junction::GlobalConsensus(xcm::v4::NetworkId::Kusama)]); - let foreign_asset_id_minimum_balance = 1_000_000_000; - // sovereign account as foreign asset owner (can be whoever for this scenario) - let foreign_asset_owner = LocationToAccountId::convert_location(&Location::parent()).unwrap(); - let foreign_asset_create_params = - (foreign_asset_owner, foreign_asset_id_location.clone(), foreign_asset_id_minimum_balance); - - remove_when_updated_to_stable2409::receive_reserve_asset_deposited_from_different_consensus_works::< - Runtime, - AllPalletsWithoutSystem, - XcmConfig, - ForeignAssetsInstance, - >( - collator_session_keys().add(collator_session_key(BLOCK_AUTHOR_ACCOUNT)), - ExistentialDeposit::get(), - AccountId::from([73; 32]), - block_author_account.clone(), - // receiving KSMs - foreign_asset_create_params, - 1000000000000, - bridging_to_asset_hub_kusama, - ( - PalletInstance(bp_bridge_hub_polkadot::WITH_BRIDGE_POLKADOT_TO_KUSAMA_MESSAGES_PALLET_INDEX).into(), - GlobalConsensus(Kusama), - Parachain(1000).into() - ), - || { - // check block author before - assert_eq!( - ForeignAssets::balance( - foreign_asset_id_location.clone(), - &block_author_account - ), - 0 - ); - }, - || { - // `TakeFirstAssetTrader` puts fees to the block author - assert!( - ForeignAssets::balance( - foreign_asset_id_location.clone(), - &block_author_account - ) > 0 - ); - // nothing adds fees to stakting_pot (e.g. `SwapFirstAssetTrader`, ...) - assert_eq!(Balances::free_balance(&staking_pot), 0); - } - ) -} - #[test] fn reserve_transfer_native_asset_to_non_teleport_para_works() { asset_test_utils::test_cases::reserve_transfer_native_asset_to_non_teleport_para_works::< diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/tests/weight_trader.rs b/system-parachains/asset-hubs/asset-hub-polkadot/tests/weight_trader.rs index 66f2e2ce8f..cb2fc14b3c 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/weight_trader.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/weight_trader.rs @@ -16,18 +16,14 @@ //! Tests for `WeighTrader` type of XCM Executor. use asset_hub_polkadot_runtime::{ - xcm_config::{ - AssetFeeAsExistentialDepositMultiplierFeeCharger, DotLocation, StakingPot, - TrustBackedAssetsPalletLocation, XcmConfig, - }, - AllPalletsWithoutSystem, AssetConversion, Assets, Balances, ExistentialDeposit, ForeignAssets, - Runtime, SessionKeys, + xcm_config::{DotLocation, StakingPot, TrustBackedAssetsPalletLocation, XcmConfig}, + AllPalletsWithoutSystem, AssetConversion, Assets, Balances, ForeignAssets, Runtime, + SessionKeys, }; use asset_test_utils::ExtBuilder; use assets_common::AssetIdForTrustBackedAssetsConvert; -use cumulus_primitives_utility::ChargeWeightInFungibles; use frame_support::{ - assert_noop, assert_ok, + assert_ok, traits::{ fungible::{Inspect, Mutate}, fungibles::{Create, Inspect as FungiblesInspect, Mutate as FungiblesMutate}, @@ -45,359 +41,6 @@ const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32]; type RuntimeHelper = asset_test_utils::RuntimeHelper; -type AssetIdForTrustBackedAssetsConvertLatest = - assets_common::AssetIdForTrustBackedAssetsConvert; - -#[test] -fn test_asset_xcm_trader() { - ExtBuilder::::default() - .with_collators(vec![AccountId::from(ALICE)]) - .with_session_keys(vec![( - AccountId::from(ALICE), - AccountId::from(ALICE), - SessionKeys { aura: AuraId::from(sp_core::ed25519::Public::from_raw(ALICE)) }, - )]) - .build() - .execute_with(|| { - // We need root origin to create a sufficient asset - let minimum_asset_balance = 333333333_u128; - let local_asset_id = 1; - assert_ok!(Assets::force_create( - RuntimeHelper::root_origin(), - local_asset_id.into(), - AccountId::from(ALICE).into(), - true, - minimum_asset_balance - )); - - // We first mint enough asset for the account to exist for assets - assert_ok!(Assets::mint( - RuntimeHelper::origin_of(AccountId::from(ALICE)), - local_asset_id.into(), - AccountId::from(ALICE).into(), - minimum_asset_balance - )); - - // get asset id as location - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap(); - - // Set Alice as block author, who will receive fees - RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); - - // We are going to buy 400e9 weight - // Because of the ED being higher in kusama's asset hub - // and not to complicate things, we use a little - // bit more of weight - let bought = Weight::from_parts(400_000_000_000u64, 0); - - // Lets calculate amount needed - let asset_amount_needed = - AssetFeeAsExistentialDepositMultiplierFeeCharger::charge_weight_in_fungibles( - local_asset_id, - bought, - ) - .expect("failed to compute"); - - // Lets pay with: asset_amount_needed + asset_amount_extra - let asset_amount_extra = 100_u128; - let asset: Asset = - (asset_location.clone(), asset_amount_needed + asset_amount_extra).into(); - - let mut trader = ::Trader::new(); - let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - - // Lets buy_weight and make sure buy_weight does not return an error - let unused_assets = trader.buy_weight(bought, asset.into(), &ctx).expect("Expected Ok"); - // Check whether a correct amount of unused assets is returned - assert_ok!(unused_assets.ensure_contains(&(asset_location, asset_amount_extra).into())); - - // Drop trader - drop(trader); - - // Make sure author(Alice) has received the amount - assert_eq!( - Assets::balance(local_asset_id, AccountId::from(ALICE)), - minimum_asset_balance + asset_amount_needed - ); - - // We also need to ensure the total supply increased - assert_eq!( - Assets::total_supply(local_asset_id), - minimum_asset_balance + asset_amount_needed - ); - }); -} - -#[test] -fn test_asset_xcm_trader_with_refund() { - ExtBuilder::::default() - .with_collators(vec![AccountId::from(ALICE)]) - .with_session_keys(vec![( - AccountId::from(ALICE), - AccountId::from(ALICE), - SessionKeys { aura: AuraId::from(sp_core::ed25519::Public::from_raw(ALICE)) }, - )]) - .build() - .execute_with(|| { - // We need root origin to create a sufficient asset - // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( - RuntimeHelper::root_origin(), - 1.into(), - AccountId::from(ALICE).into(), - true, - ExistentialDeposit::get() - )); - - // We first mint enough asset for the account to exist for assets - assert_ok!(Assets::mint( - RuntimeHelper::origin_of(AccountId::from(ALICE)), - 1.into(), - AccountId::from(ALICE).into(), - ExistentialDeposit::get() - )); - - let mut trader = ::Trader::new(); - let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - - // Set Alice as block author, who will receive fees - RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); - - // We are going to buy 400e9 weight - // Because of the ED being higher in kusama's asset hub - // and not to complicate things, we use a little - // bit more of weight - let bought = Weight::from_parts(400_000_000_000u64, 0); - - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); - - // lets calculate amount needed - let amount_bought = WeightToFee::weight_to_fee(&bought); - - let asset: Asset = (asset_location.clone(), amount_bought).into(); - - // Make sure buy_weight does not return an error - assert_ok!(trader.buy_weight(bought, asset.clone().into(), &ctx)); - - // Make sure again buy_weight does return an error - // This assert relies on the fact, that we use `TakeFirstAssetTrader` in `WeightTrader` - // tuple chain, which cannot be called twice - assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive); - - // We actually use half of the weight - let weight_used = bought / 2; - - // Make sure refurnd works. - let amount_refunded = WeightToFee::weight_to_fee(&(bought - weight_used)); - - assert_eq!( - trader.refund_weight(bought - weight_used, &ctx), - Some((asset_location, amount_refunded).into()) - ); - - // Drop trader - drop(trader); - - // We only should have paid for half of the bought weight - let fees_paid = WeightToFee::weight_to_fee(&weight_used); - - assert_eq!( - Assets::balance(1, AccountId::from(ALICE)), - ExistentialDeposit::get() + fees_paid - ); - - // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get() + fees_paid); - }); -} - -#[test] -fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { - ExtBuilder::::default() - .with_collators(vec![AccountId::from(ALICE)]) - .with_session_keys(vec![( - AccountId::from(ALICE), - AccountId::from(ALICE), - SessionKeys { aura: AuraId::from(sp_core::ed25519::Public::from_raw(ALICE)) }, - )]) - .build() - .execute_with(|| { - // We need root origin to create a sufficient asset - // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( - RuntimeHelper::root_origin(), - 1.into(), - AccountId::from(ALICE).into(), - true, - ExistentialDeposit::get() - )); - - let mut trader = ::Trader::new(); - let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - - // Set Alice as block author, who will receive fees - RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); - - // We are going to buy 50e9 weight - // Because of the ED being higher in kusama's asset hub - // and not to complicate things, we use a little - // bit more of weight - let bought = Weight::from_parts(5_000_000_000u64, 0); - - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); - - let amount_bought = WeightToFee::weight_to_fee(&bought); - - assert!( - amount_bought < ExistentialDeposit::get(), - "we are testing what happens when the amount does not exceed ED" - ); - - let asset: Asset = (asset_location, amount_bought).into(); - - // Buy weight should return an error - assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive); - - // not credited since the ED is higher than this value - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0); - - // We also need to ensure the total supply did not increase - assert_eq!(Assets::total_supply(1), 0); - }); -} - -#[test] -fn test_that_buying_ed_refund_does_not_refund() { - ExtBuilder::::default() - .with_collators(vec![AccountId::from(ALICE)]) - .with_session_keys(vec![( - AccountId::from(ALICE), - AccountId::from(ALICE), - SessionKeys { aura: AuraId::from(sp_core::ed25519::Public::from_raw(ALICE)) }, - )]) - .build() - .execute_with(|| { - // We need root origin to create a sufficient asset - // We set existential deposit to be identical to the one for Balances first - assert_ok!(Assets::force_create( - RuntimeHelper::root_origin(), - 1.into(), - AccountId::from(ALICE).into(), - true, - ExistentialDeposit::get() - )); - - let mut trader = ::Trader::new(); - let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - - // Set Alice as block author, who will receive fees - RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); - - // We are gonna buy ED - let bought = Weight::from_parts(ExistentialDeposit::get().try_into().unwrap(), 0); - - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); - - let amount_bought = WeightToFee::weight_to_fee(&bought); - - assert!( - amount_bought < ExistentialDeposit::get(), - "we are testing what happens when the amount does not exceed ED" - ); - - // We know we will have to buy at least ED, so lets make sure first it will - // fail with a payment of less than ED - let asset: Asset = (asset_location.clone(), amount_bought).into(); - assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive); - - // Now lets buy ED at least - let asset: Asset = (asset_location, ExistentialDeposit::get()).into(); - - // Buy weight should work - assert_ok!(trader.buy_weight(bought, asset.into(), &ctx)); - - // Should return None. We have a specific check making sure we dont go below ED for - // drop payment - assert_eq!(trader.refund_weight(bought, &ctx), None); - - // Drop trader - drop(trader); - - // Make sure author(Alice) has received the amount - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get()); - - // We also need to ensure the total supply increased - assert_eq!(Assets::total_supply(1), ExistentialDeposit::get()); - }); -} - -#[test] -fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { - ExtBuilder::::default() - .with_collators(vec![AccountId::from(ALICE)]) - .with_session_keys(vec![( - AccountId::from(ALICE), - AccountId::from(ALICE), - SessionKeys { aura: AuraId::from(sp_core::ed25519::Public::from_raw(ALICE)) }, - )]) - .build() - .execute_with(|| { - // Create a non-sufficient asset - let minimum_asset_balance = 1_000_000_u128; - assert_ok!(Assets::force_create( - RuntimeHelper::root_origin(), - 1.into(), - AccountId::from(ALICE).into(), - false, - minimum_asset_balance - )); - - // We first mint enough asset for the account to exist for assets - assert_ok!(Assets::mint( - RuntimeHelper::origin_of(AccountId::from(ALICE)), - 1.into(), - AccountId::from(ALICE).into(), - minimum_asset_balance - )); - - let mut trader = ::Trader::new(); - let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - - // Set Alice as block author, who will receive fees - RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); - - // We are going to buy 400e9 weight - // Because of the ED being higher in kusama's asset hub - // and not to complicate things, we use a little - // bit more of weight - let bought = Weight::from_parts(400_000_000_000u64, 0); - - // lets calculate amount needed - let asset_amount_needed = WeightToFee::weight_to_fee(&bought); - - let asset_location = - AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap(); - - let asset: Asset = (asset_location, asset_amount_needed).into(); - - // Make sure again buy_weight does return an error - assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive); - - // Drop trader - drop(trader); - - // Make sure author(Alice) has NOT received the amount - assert_eq!(Assets::balance(1, AccountId::from(ALICE)), minimum_asset_balance); - - // We also need to ensure the total supply NOT increased - assert_eq!(Assets::total_supply(1), minimum_asset_balance); - }); -} - #[test] fn test_buy_and_refund_weight_with_native() { ExtBuilder::::default()