diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d9cbc5dfd..fdcf47ef85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed -Change Polkadot inflation to 120M DOT per year ([polkadot-fellows/runtimes#471](https://github.com/polkadot-fellows/runtimes/pull/471)) +- Change Polkadot inflation to 120M DOT per year ([polkadot-fellows/runtimes#471](https://github.com/polkadot-fellows/runtimes/pull/471)) +- Update foreign asset ids in Asset Hub Polkadot and Asset Hub Kusama from v3 to v4 locations ([polkadot-fellows/runtimes#472](https://github.com/polkadot-fellows/runtimes/pull/472)) ## [1.3.3] 01.10.2024 diff --git a/integration-tests/emulated/chains/parachains/assets/asset-hub-kusama/src/genesis.rs b/integration-tests/emulated/chains/parachains/assets/asset-hub-kusama/src/genesis.rs index 5880e98368..ede135e87e 100644 --- a/integration-tests/emulated/chains/parachains/assets/asset-hub-kusama/src/genesis.rs +++ b/integration-tests/emulated/chains/parachains/assets/asset-hub-kusama/src/genesis.rs @@ -88,7 +88,7 @@ pub fn genesis() -> Storage { assets: vec![ // Penpal's teleportable asset representation ( - PenpalATeleportableAssetLocation::get().try_into().unwrap(), + PenpalATeleportableAssetLocation::get(), PenpalASiblingSovereignAccount::get(), false, ED, diff --git a/integration-tests/emulated/chains/parachains/assets/asset-hub-kusama/src/lib.rs b/integration-tests/emulated/chains/parachains/assets/asset-hub-kusama/src/lib.rs index af76285d73..af127b7e1a 100644 --- a/integration-tests/emulated/chains/parachains/assets/asset-hub-kusama/src/lib.rs +++ b/integration-tests/emulated/chains/parachains/assets/asset-hub-kusama/src/lib.rs @@ -57,5 +57,5 @@ impl_accounts_helpers_for_parachain!(AssetHubKusama); impl_assert_events_helpers_for_parachain!(AssetHubKusama); impl_assets_helpers_for_system_parachain!(AssetHubKusama, Kusama); impl_assets_helpers_for_parachain!(AssetHubKusama); -impl_foreign_assets_helpers_for_parachain!(AssetHubKusama, xcm::v3::Location); +impl_foreign_assets_helpers_for_parachain!(AssetHubKusama, xcm::v4::Location); impl_xcm_helpers_for_parachain!(AssetHubKusama); diff --git a/integration-tests/emulated/chains/parachains/assets/asset-hub-polkadot/src/genesis.rs b/integration-tests/emulated/chains/parachains/assets/asset-hub-polkadot/src/genesis.rs index 1a4054839d..f4efa482d3 100644 --- a/integration-tests/emulated/chains/parachains/assets/asset-hub-polkadot/src/genesis.rs +++ b/integration-tests/emulated/chains/parachains/assets/asset-hub-polkadot/src/genesis.rs @@ -114,13 +114,13 @@ pub fn genesis() -> Storage { assets: vec![ // Penpal's teleportable asset representation ( - PenpalATeleportableAssetLocation::get().try_into().unwrap(), + PenpalATeleportableAssetLocation::get(), PenpalASiblingSovereignAccount::get(), false, ED, ), ( - PenpalBTeleportableAssetLocation::get().try_into().unwrap(), + PenpalBTeleportableAssetLocation::get(), PenpalBSiblingSovereignAccount::get(), false, ED, diff --git a/integration-tests/emulated/chains/parachains/assets/asset-hub-polkadot/src/lib.rs b/integration-tests/emulated/chains/parachains/assets/asset-hub-polkadot/src/lib.rs index b24ba95926..ecefcf0148 100644 --- a/integration-tests/emulated/chains/parachains/assets/asset-hub-polkadot/src/lib.rs +++ b/integration-tests/emulated/chains/parachains/assets/asset-hub-polkadot/src/lib.rs @@ -57,5 +57,5 @@ impl_accounts_helpers_for_parachain!(AssetHubPolkadot); impl_assert_events_helpers_for_parachain!(AssetHubPolkadot); impl_assets_helpers_for_system_parachain!(AssetHubPolkadot, Polkadot); impl_assets_helpers_for_parachain!(AssetHubPolkadot); -impl_foreign_assets_helpers_for_parachain!(AssetHubPolkadot, xcm::v3::Location); +impl_foreign_assets_helpers_for_parachain!(AssetHubPolkadot, xcm::v4::Location); impl_xcm_helpers_for_parachain!(AssetHubPolkadot); diff --git a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/lib.rs b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/lib.rs index 4b9857cd69..af4c48a3d0 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/lib.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/lib.rs @@ -28,7 +28,7 @@ pub use sp_runtime::traits::Dispatchable; // Polkadot pub use xcm::{ prelude::{AccountId32 as AccountId32Junction, *}, - v3::{self, Error, NetworkId::Kusama as KusamaId}, + v4::{self, Error, NetworkId::Kusama as KusamaId}, }; pub use xcm_executor::traits::TransferType; @@ -41,7 +41,7 @@ pub use emulated_integration_tests_common::{ RelayChain as Relay, Test, TestArgs, TestContext, TestExt, }, xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, - PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, RESERVABLE_ASSET_ID, XCM_V3, + PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, RESERVABLE_ASSET_ID, XCM_V4, }; pub use integration_tests_helpers::{ test_parachain_is_trusted_teleporter_for_relay, test_relay_is_trusted_teleporter, diff --git a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/hybrid_transfers.rs b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/hybrid_transfers.rs index f6f8999f0c..fe0a8b6aa6 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/hybrid_transfers.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/hybrid_transfers.rs @@ -183,7 +183,7 @@ fn transfer_foreign_assets_from_asset_hub_to_para() { vec![], ); AssetHubKusama::force_create_foreign_asset( - dot_at_kusama_parachains.clone().try_into().unwrap(), + dot_at_kusama_parachains.clone(), assets_owner.clone(), false, ASSET_MIN_BALANCE, @@ -191,7 +191,7 @@ fn transfer_foreign_assets_from_asset_hub_to_para() { ); AssetHubKusama::mint_foreign_asset( ::RuntimeOrigin::signed(assets_owner), - dot_at_kusama_parachains.clone().try_into().unwrap(), + dot_at_kusama_parachains.clone(), sender.clone(), foreign_amount_to_send * 2, ); @@ -223,10 +223,7 @@ fn transfer_foreign_assets_from_asset_hub_to_para() { let sender_balance_before = test.sender.balance; let sender_dots_before = AssetHubKusama::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance( - dot_at_kusama_parachains.clone().try_into().unwrap(), - &sender, - ) + >::balance(dot_at_kusama_parachains.clone(), &sender) }); let receiver_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; @@ -247,10 +244,7 @@ fn transfer_foreign_assets_from_asset_hub_to_para() { let sender_balance_after = test.sender.balance; let sender_dots_after = AssetHubKusama::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance( - dot_at_kusama_parachains.clone().try_into().unwrap(), - &sender, - ) + >::balance(dot_at_kusama_parachains.clone(), &sender) }); let receiver_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; @@ -312,7 +306,7 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { vec![], ); AssetHubKusama::force_create_foreign_asset( - dot_at_kusama_parachains.clone().try_into().unwrap(), + dot_at_kusama_parachains.clone(), assets_owner.clone(), false, ASSET_MIN_BALANCE, @@ -342,7 +336,7 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { AssetHubKusama::fund_accounts(vec![(sov_penpal_on_ahk.clone(), native_amount_to_send * 2)]); AssetHubKusama::mint_foreign_asset( ::RuntimeOrigin::signed(assets_owner), - dot_at_kusama_parachains.clone().try_into().unwrap(), + dot_at_kusama_parachains.clone(), sov_penpal_on_ahk, foreign_amount_to_send * 2, ); @@ -382,10 +376,7 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { let receiver_native_before = test.receiver.balance; let receiver_dots_before = AssetHubKusama::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance( - dot_at_kusama_parachains.clone().try_into().unwrap(), - &receiver, - ) + >::balance(dot_at_kusama_parachains.clone(), &receiver) }); // Set assertions and dispatchables @@ -406,10 +397,7 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { let receiver_native_after = test.receiver.balance; let receiver_dots_after = AssetHubKusama::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance( - dot_at_kusama_parachains.try_into().unwrap(), - &receiver, - ) + >::balance(dot_at_kusama_parachains, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees @@ -459,7 +447,7 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { // Register DOT as foreign asset and transfer it around the Kusama ecosystem let dot_at_kusama_parachains = Location::new(2, [GlobalConsensus(Polkadot)]); AssetHubKusama::force_create_foreign_asset( - dot_at_kusama_parachains.clone().try_into().unwrap(), + dot_at_kusama_parachains.clone(), assets_owner.clone(), false, ASSET_MIN_BALANCE, @@ -497,7 +485,7 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { AssetHubKusama::fund_accounts(vec![(sov_of_sender_on_ah.clone(), ksm_to_send * 2)]); AssetHubKusama::mint_foreign_asset( ::RuntimeOrigin::signed(assets_owner), - dot_at_kusama_parachains.clone().try_into().unwrap(), + dot_at_kusama_parachains.clone(), sov_of_sender_on_ah.clone(), dot_to_send * 2, ); @@ -541,19 +529,13 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { ::account_data_of(sov_of_sender_on_ah.clone()).free; let dots_in_sender_reserve_on_ahk_before = AssetHubKusama::execute_with(|| { type Assets = ::ForeignAssets; - >::balance( - dot_at_kusama_parachains.clone().try_into().unwrap(), - &sov_of_sender_on_ah, - ) + >::balance(dot_at_kusama_parachains.clone(), &sov_of_sender_on_ah) }); let ksms_in_receiver_reserve_on_ahk_before = ::account_data_of(sov_of_receiver_on_ah.clone()).free; let dots_in_receiver_reserve_on_ahk_before = AssetHubKusama::execute_with(|| { type Assets = ::ForeignAssets; - >::balance( - dot_at_kusama_parachains.clone().try_into().unwrap(), - &sov_of_receiver_on_ah, - ) + >::balance(dot_at_kusama_parachains.clone(), &sov_of_receiver_on_ah) }); let receiver_ksms_before = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; @@ -582,19 +564,13 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { }); let dots_in_sender_reserve_on_ahk_after = AssetHubKusama::execute_with(|| { type Assets = ::ForeignAssets; - >::balance( - dot_at_kusama_parachains.clone().try_into().unwrap(), - &sov_of_sender_on_ah, - ) + >::balance(dot_at_kusama_parachains.clone(), &sov_of_sender_on_ah) }); let ksms_in_sender_reserve_on_ahk_after = ::account_data_of(sov_of_sender_on_ah).free; let dots_in_receiver_reserve_on_ahk_after = AssetHubKusama::execute_with(|| { type Assets = ::ForeignAssets; - >::balance( - dot_at_kusama_parachains.clone().try_into().unwrap(), - &sov_of_receiver_on_ah, - ) + >::balance(dot_at_kusama_parachains.clone(), &sov_of_receiver_on_ah) }); let ksms_in_receiver_reserve_on_ahk_after = ::account_data_of(sov_of_receiver_on_ah).free; 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 e4f1051177..d5a24ed0f2 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 @@ -36,21 +36,21 @@ fn send_xcm_from_para_to_asset_hub_paying_fee_with_system_asset() { let para_sovereign_account = AssetHubKusama::sovereign_account_id_of( AssetHubKusama::sibling_location_of(PenpalA::para_id()), ); - let asset_location_on_penpal = v3::Location::new( + let asset_location_on_penpal = v4::Location::new( 0, [ - v3::Junction::PalletInstance(ASSETS_PALLET_ID), - v3::Junction::GeneralIndex(ASSET_ID.into()), + v4::Junction::PalletInstance(ASSETS_PALLET_ID), + v4::Junction::GeneralIndex(ASSET_ID.into()), ], ); let foreign_asset_at_asset_hub = - v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) + v4::Location::new(1, [v4::Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) .unwrap(); // Encoded `create_asset` call to be executed in AssetHub let call = AssetHubKusama::create_foreign_asset_call( - foreign_asset_at_asset_hub, + foreign_asset_at_asset_hub.clone(), ASSET_MIN_BALANCE, para_sovereign_account.clone(), ); @@ -97,7 +97,7 @@ fn send_xcm_from_para_to_asset_hub_paying_fee_with_system_asset() { }, // Foreign Asset created RuntimeEvent::ForeignAssets(pallet_assets::Event::Created { asset_id, creator, owner }) => { - asset_id: *asset_id == foreign_asset_at_asset_hub, + asset_id: *asset_id == foreign_asset_at_asset_hub.clone(), creator: *creator == para_sovereign_account.clone(), owner: *owner == para_sovereign_account, }, diff --git a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/set_xcm_versions.rs b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/set_xcm_versions.rs index 9570f33d75..b621c7c2b7 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/set_xcm_versions.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/set_xcm_versions.rs @@ -26,7 +26,7 @@ fn relay_sets_system_para_xcm_supported_version() { assert_ok!(::XcmPallet::force_xcm_version( sudo_origin, bx!(system_para_destination.clone()), - XCM_V3 + XCM_V4 )); type RuntimeEvent = ::RuntimeEvent; @@ -36,7 +36,7 @@ fn relay_sets_system_para_xcm_supported_version() { vec![ RuntimeEvent::XcmPallet(pallet_xcm::Event::SupportedVersionChanged { location, - version: XCM_V3 + version: XCM_V4 }) => { location: *location == system_para_destination, }, ] ); @@ -52,7 +52,7 @@ fn system_para_sets_relay_xcm_supported_version() { ::Runtime, >::force_xcm_version { location: bx!(parent_location.clone()), - version: XCM_V3, + version: XCM_V4, }) .encode() .into(); @@ -74,7 +74,7 @@ fn system_para_sets_relay_xcm_supported_version() { vec![ RuntimeEvent::PolkadotXcm(pallet_xcm::Event::SupportedVersionChanged { location, - version: XCM_V3 + version: XCM_V4 }) => { location: *location == parent_location, }, ] ); 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 c963e32e19..e31b1b6426 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 @@ -20,15 +20,12 @@ use system_parachains_constants::kusama::currency::SYSTEM_PARA_EXISTENTIAL_DEPOS #[test] fn swap_locally_on_chain_using_local_assets() { - let asset_native = Box::new( - v3::Location::try_from(asset_hub_kusama_runtime::xcm_config::KsmLocation::get()) - .expect("conversion works"), - ); - let asset_one = Box::new(v3::Location::new( + let asset_native = Box::new(asset_hub_kusama_runtime::xcm_config::KsmLocation::get()); + let asset_one = Box::new(v4::Location::new( 0, [ - v3::Junction::PalletInstance(ASSETS_PALLET_ID), - v3::Junction::GeneralIndex(ASSET_ID.into()), + v4::Junction::PalletInstance(ASSETS_PALLET_ID), + v4::Junction::GeneralIndex(ASSET_ID.into()), ], )); @@ -119,14 +116,10 @@ fn swap_locally_on_chain_using_local_assets() { #[test] fn swap_locally_on_chain_using_foreign_assets() { - let asset_native = Box::new( - v3::Location::try_from(asset_hub_kusama_runtime::xcm_config::KsmLocation::get()) - .expect("conversion works"), - ); - let asset_location_on_penpal = - v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion works"); + let asset_native = Box::new(asset_hub_kusama_runtime::xcm_config::KsmLocation::get()); + let asset_location_on_penpal = PenpalLocalTeleportableToAssetHub::get(); let foreign_asset_at_asset_hub_kusama = - v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) + v4::Location::new(1, [v4::Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) .unwrap(); @@ -151,7 +144,7 @@ fn swap_locally_on_chain_using_foreign_assets() { // 3. Mint foreign asset (in reality this should be a teleport or some such) assert_ok!(::ForeignAssets::mint( ::RuntimeOrigin::signed(sov_penpal_on_ahk.clone()), - foreign_asset_at_asset_hub_kusama, + foreign_asset_at_asset_hub_kusama.clone(), sov_penpal_on_ahk.clone().into(), ASSET_HUB_KUSAMA_ED * 3_000_000_000_000, )); @@ -167,7 +160,7 @@ fn swap_locally_on_chain_using_foreign_assets() { assert_ok!(::AssetConversion::create_pool( ::RuntimeOrigin::signed(AssetHubKusamaSender::get()), asset_native.clone(), - Box::new(foreign_asset_at_asset_hub_kusama), + Box::new(foreign_asset_at_asset_hub_kusama.clone()), )); assert_expected_events!( @@ -181,7 +174,7 @@ fn swap_locally_on_chain_using_foreign_assets() { assert_ok!(::AssetConversion::add_liquidity( ::RuntimeOrigin::signed(sov_penpal_on_ahk.clone()), asset_native.clone(), - Box::new(foreign_asset_at_asset_hub_kusama), + Box::new(foreign_asset_at_asset_hub_kusama.clone()), 1_000_000_000_000, 2_000_000_000_000, 0, @@ -199,7 +192,7 @@ fn swap_locally_on_chain_using_foreign_assets() { ); // 6. Swap! - let path = vec![asset_native.clone(), Box::new(foreign_asset_at_asset_hub_kusama)]; + let path = vec![asset_native.clone(), Box::new(foreign_asset_at_asset_hub_kusama.clone())]; assert_ok!( ::AssetConversion::swap_exact_tokens_for_tokens( @@ -237,14 +230,10 @@ fn swap_locally_on_chain_using_foreign_assets() { #[test] fn cannot_create_pool_from_pool_assets() { - let asset_native = asset_hub_kusama_runtime::xcm_config::KsmLocation::get() - .try_into() - .expect("conversion works"); + let asset_native = asset_hub_kusama_runtime::xcm_config::KsmLocation::get(); let asset_one = asset_hub_kusama_runtime::xcm_config::PoolAssetsPalletLocation::get() .appended_with(GeneralIndex(ASSET_ID.into())) - .expect("valid location") - .try_into() - .expect("conversion works"); + .expect("valid location"); AssetHubKusama::execute_with(|| { let pool_owner_account_id = asset_hub_kusama_runtime::AssetConversionOrigin::get(); @@ -277,14 +266,12 @@ fn cannot_create_pool_from_pool_assets() { #[test] fn pay_xcm_fee_with_some_asset_swapped_for_native() { - let asset_native: xcm::v3::Location = asset_hub_kusama_runtime::xcm_config::KsmLocation::get() - .try_into() - .expect("conversion works"); - let asset_one = xcm::v3::Location { + let asset_native: xcm::v4::Location = asset_hub_kusama_runtime::xcm_config::KsmLocation::get(); + let asset_one = xcm::v4::Location { parents: 0, interior: [ - xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), - xcm::v3::Junction::GeneralIndex(ASSET_ID.into()), + xcm::v4::Junction::PalletInstance(ASSETS_PALLET_ID), + xcm::v4::Junction::GeneralIndex(ASSET_ID.into()), ] .into(), }; @@ -313,8 +300,8 @@ fn pay_xcm_fee_with_some_asset_swapped_for_native() { assert_ok!(::AssetConversion::create_pool( ::RuntimeOrigin::signed(AssetHubKusamaSender::get()), - Box::new(asset_native), - Box::new(asset_one), + Box::new(asset_native.clone()), + Box::new(asset_one.clone()), )); assert_expected_events!( diff --git a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/teleport.rs b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/teleport.rs index d6ffc5472c..76776b44b3 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/teleport.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/teleport.rs @@ -86,7 +86,6 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { ); let (expected_foreign_asset_id, expected_foreign_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); - let expected_foreign_asset_id_v3: v3::Location = expected_foreign_asset_id.try_into().unwrap(); AssetHubKusama::assert_xcmp_queue_success(None); assert_expected_events!( @@ -103,7 +102,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 == expected_foreign_asset_id_v3, + asset_id: *asset_id == expected_foreign_asset_id, owner: *owner == t.receiver.account_id, amount: *amount == expected_foreign_asset_amount, }, @@ -117,7 +116,6 @@ fn ah_to_penpal_foreign_assets_sender_assertions(t: SystemParaToParaTest) { AssetHubKusama::assert_xcm_pallet_attempted_complete(None); let (expected_foreign_asset_id, expected_foreign_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); - let expected_foreign_asset_id_v3: v3::Location = expected_foreign_asset_id.try_into().unwrap(); assert_expected_events!( AssetHubKusama, vec![ @@ -133,7 +131,7 @@ fn ah_to_penpal_foreign_assets_sender_assertions(t: SystemParaToParaTest) { }, // foreign asset is burned locally as part of teleportation RuntimeEvent::ForeignAssets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { - asset_id: *asset_id == expected_foreign_asset_id_v3, + asset_id: *asset_id == expected_foreign_asset_id, owner: *owner == t.sender.account_id, balance: *balance == expected_foreign_asset_amount, }, @@ -377,7 +375,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let ah_receiver_assets_before = AssetHubKusama::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - foreign_asset_at_asset_hub_kusama.clone().try_into().unwrap(), + foreign_asset_at_asset_hub_kusama.clone(), &AssetHubKusamaReceiver::get(), ) }); @@ -404,7 +402,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let ah_receiver_assets_after = AssetHubKusama::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - foreign_asset_at_asset_hub_kusama.clone().try_into().unwrap(), + foreign_asset_at_asset_hub_kusama.clone(), &AssetHubKusamaReceiver::get(), ) }); @@ -432,7 +430,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using type ForeignAssets = ::ForeignAssets; assert_ok!(ForeignAssets::transfer( ::RuntimeOrigin::signed(AssetHubKusamaReceiver::get()), - foreign_asset_at_asset_hub_kusama.clone().try_into().unwrap(), + foreign_asset_at_asset_hub_kusama.clone(), AssetHubKusamaSender::get().into(), asset_amount_to_send, )); @@ -478,7 +476,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let ah_sender_assets_before = AssetHubKusama::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - foreign_asset_at_asset_hub_kusama.clone().try_into().unwrap(), + foreign_asset_at_asset_hub_kusama.clone(), &AssetHubKusamaSender::get(), ) }); @@ -504,7 +502,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let ah_sender_assets_after = AssetHubKusama::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - foreign_asset_at_asset_hub_kusama.try_into().unwrap(), + foreign_asset_at_asset_hub_kusama, &AssetHubKusamaSender::get(), ) }); diff --git a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/treasury.rs b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/treasury.rs index 5f830b41ef..f060fc96e7 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/treasury.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/treasury.rs @@ -175,13 +175,13 @@ fn create_and_claim_treasury_spend_in_usdt() { ) .unwrap(); let asset_hub_location = - v3::Location::new(0, v3::Junction::Parachain(AssetHubKusama::para_id().into())); + v4::Location::new(0, v4::Junction::Parachain(AssetHubKusama::para_id().into())); let root = ::RuntimeOrigin::root(); // asset kind to be spend from the treasury. - let asset_kind = VersionedLocatableAsset::V3 { + let asset_kind = VersionedLocatableAsset::V4 { location: asset_hub_location, - asset_id: v3::AssetId::Concrete( - (v3::Junction::PalletInstance(50), v3::Junction::GeneralIndex(USDT_ID.into())).into(), + asset_id: v4::AssetId( + (v4::Junction::PalletInstance(50), v4::Junction::GeneralIndex(USDT_ID.into())).into(), ), }; // treasury spend beneficiary. diff --git a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/lib.rs b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/lib.rs index c6c84dbfc0..e47727b67b 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/lib.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/lib.rs @@ -30,7 +30,7 @@ pub use sp_runtime::traits::Dispatchable; // Polkadot pub use xcm::{ prelude::{AccountId32 as AccountId32Junction, *}, - v3::{self, Error, NetworkId::Polkadot as PolkadotId}, + v4::{self, Error, NetworkId::Polkadot as PolkadotId}, }; pub use xcm_executor::traits::TransferType; @@ -43,7 +43,7 @@ pub use emulated_integration_tests_common::{ RelayChain as Relay, Test, TestArgs, TestContext, TestExt, }, xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, - PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, + PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V4, }; pub use integration_tests_helpers::{ test_parachain_is_trusted_teleporter_for_relay, test_relay_is_trusted_teleporter, diff --git a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/fellowship_treasury.rs b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/fellowship_treasury.rs index 9fbcba4e00..e1783f63b4 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/fellowship_treasury.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/fellowship_treasury.rs @@ -40,13 +40,13 @@ fn create_and_claim_treasury_spend_in_usdt() { ) .unwrap(); let asset_hub_location = - v3::Location::new(1, v3::Junction::Parachain(AssetHubPolkadot::para_id().into())); + v4::Location::new(1, v4::Junction::Parachain(AssetHubPolkadot::para_id().into())); let root = ::RuntimeOrigin::root(); // asset kind to be spent from the treasury. - let asset_kind = VersionedLocatableAsset::V3 { + let asset_kind = VersionedLocatableAsset::V4 { location: asset_hub_location, - asset_id: v3::AssetId::Concrete( - (v3::Junction::PalletInstance(50), v3::Junction::GeneralIndex(USDT_ID.into())).into(), + asset_id: v4::AssetId( + (v4::Junction::PalletInstance(50), v4::Junction::GeneralIndex(USDT_ID.into())).into(), ), }; // treasury spend beneficiary. diff --git a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/hybrid_transfers.rs b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/hybrid_transfers.rs index 27c0cb34b6..e1ae744679 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/hybrid_transfers.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/hybrid_transfers.rs @@ -183,7 +183,7 @@ fn transfer_foreign_assets_from_asset_hub_to_para() { vec![], ); AssetHubPolkadot::force_create_foreign_asset( - ksm_at_polkadot_parachains.clone().try_into().unwrap(), + ksm_at_polkadot_parachains.clone(), assets_owner.clone(), false, ASSET_MIN_BALANCE, @@ -191,7 +191,7 @@ fn transfer_foreign_assets_from_asset_hub_to_para() { ); AssetHubPolkadot::mint_foreign_asset( ::RuntimeOrigin::signed(assets_owner), - ksm_at_polkadot_parachains.clone().try_into().unwrap(), + ksm_at_polkadot_parachains.clone(), sender.clone(), foreign_amount_to_send * 2, ); @@ -223,10 +223,7 @@ fn transfer_foreign_assets_from_asset_hub_to_para() { let sender_balance_before = test.sender.balance; let sender_ksm_before = AssetHubPolkadot::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance( - ksm_at_polkadot_parachains.clone().try_into().unwrap(), - &sender, - ) + >::balance(ksm_at_polkadot_parachains.clone(), &sender) }); let receiver_assets_before = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; @@ -247,10 +244,7 @@ fn transfer_foreign_assets_from_asset_hub_to_para() { let sender_balance_after = test.sender.balance; let sender_ksm_after = AssetHubPolkadot::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance( - ksm_at_polkadot_parachains.clone().try_into().unwrap(), - &sender, - ) + >::balance(ksm_at_polkadot_parachains.clone(), &sender) }); let receiver_assets_after = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; @@ -312,7 +306,7 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { vec![], ); AssetHubPolkadot::force_create_foreign_asset( - ksm_at_polkadot_parachains.clone().try_into().unwrap(), + ksm_at_polkadot_parachains.clone(), assets_owner.clone(), false, ASSET_MIN_BALANCE, @@ -343,7 +337,7 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { AssetHubPolkadot::fund_accounts(vec![(sov_penpal_on_ahp.clone(), native_amount_to_send * 2)]); AssetHubPolkadot::mint_foreign_asset( ::RuntimeOrigin::signed(assets_owner), - ksm_at_polkadot_parachains.clone().try_into().unwrap(), + ksm_at_polkadot_parachains.clone(), sov_penpal_on_ahp, foreign_amount_to_send * 2, ); @@ -383,10 +377,7 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { let receiver_native_before = test.receiver.balance; let receiver_ksm_before = AssetHubPolkadot::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance( - ksm_at_polkadot_parachains.clone().try_into().unwrap(), - &receiver, - ) + >::balance(ksm_at_polkadot_parachains.clone(), &receiver) }); // Set assertions and dispatchables @@ -407,10 +398,7 @@ fn transfer_foreign_assets_from_para_to_asset_hub() { let receiver_native_after = test.receiver.balance; let receiver_ksm_after = AssetHubPolkadot::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance( - ksm_at_polkadot_parachains.try_into().unwrap(), - &receiver, - ) + >::balance(ksm_at_polkadot_parachains, &receiver) }); // Sender's balance is reduced by amount sent plus delivery fees @@ -460,7 +448,7 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { // Register KSM as foreign asset and transfer it around the Polkadot ecosystem let ksm_at_polkadot_parachains = Location::new(2, [GlobalConsensus(Kusama)]); AssetHubPolkadot::force_create_foreign_asset( - ksm_at_polkadot_parachains.clone().try_into().unwrap(), + ksm_at_polkadot_parachains.clone(), assets_owner.clone(), false, ASSET_MIN_BALANCE, @@ -498,7 +486,7 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { AssetHubPolkadot::fund_accounts(vec![(sov_of_sender_on_ah.clone(), dot_to_send * 2)]); AssetHubPolkadot::mint_foreign_asset( ::RuntimeOrigin::signed(assets_owner), - ksm_at_polkadot_parachains.clone().try_into().unwrap(), + ksm_at_polkadot_parachains.clone(), sov_of_sender_on_ah.clone(), ksm_to_send * 2, ); @@ -542,19 +530,13 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { ::account_data_of(sov_of_sender_on_ah.clone()).free; let ksm_in_sender_reserve_on_ahp_before = AssetHubPolkadot::execute_with(|| { type Assets = ::ForeignAssets; - >::balance( - ksm_at_polkadot_parachains.clone().try_into().unwrap(), - &sov_of_sender_on_ah, - ) + >::balance(ksm_at_polkadot_parachains.clone(), &sov_of_sender_on_ah) }); let dot_in_receiver_reserve_on_ahp_before = ::account_data_of(sov_of_receiver_on_ah.clone()).free; let ksm_in_receiver_reserve_on_ahp_before = AssetHubPolkadot::execute_with(|| { type Assets = ::ForeignAssets; - >::balance( - ksm_at_polkadot_parachains.clone().try_into().unwrap(), - &sov_of_receiver_on_ah, - ) + >::balance(ksm_at_polkadot_parachains.clone(), &sov_of_receiver_on_ah) }); let receiver_dot_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; @@ -583,19 +565,13 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() { }); let ksm_in_sender_reserve_on_ahp_after = AssetHubPolkadot::execute_with(|| { type Assets = ::ForeignAssets; - >::balance( - ksm_at_polkadot_parachains.clone().try_into().unwrap(), - &sov_of_sender_on_ah, - ) + >::balance(ksm_at_polkadot_parachains.clone(), &sov_of_sender_on_ah) }); let dot_in_sender_reserve_on_ahp_after = ::account_data_of(sov_of_sender_on_ah).free; let ksm_in_receiver_reserve_on_ahp_after = AssetHubPolkadot::execute_with(|| { type Assets = ::ForeignAssets; - >::balance( - ksm_at_polkadot_parachains.clone().try_into().unwrap(), - &sov_of_receiver_on_ah, - ) + >::balance(ksm_at_polkadot_parachains.clone(), &sov_of_receiver_on_ah) }); let dot_in_receiver_reserve_on_ahp_after = ::account_data_of(sov_of_receiver_on_ah).free; 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 c8542c8ece..23e6fe4323 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 @@ -36,21 +36,21 @@ fn send_xcm_from_para_to_asset_hub_paying_fee_with_system_asset() { let para_sovereign_account = AssetHubPolkadot::sovereign_account_id_of( AssetHubPolkadot::sibling_location_of(PenpalA::para_id()), ); - let asset_location_on_penpal = v3::Location::new( + let asset_location_on_penpal = v4::Location::new( 0, [ - v3::Junction::PalletInstance(ASSETS_PALLET_ID), - v3::Junction::GeneralIndex(ASSET_ID.into()), + v4::Junction::PalletInstance(ASSETS_PALLET_ID), + v4::Junction::GeneralIndex(ASSET_ID.into()), ], ); let foreign_asset_at_asset_hub = - v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) + v4::Location::new(1, [v4::Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) .unwrap(); // Encoded `create_asset` call to be executed in AssetHub let call = AssetHubPolkadot::create_foreign_asset_call( - foreign_asset_at_asset_hub, + foreign_asset_at_asset_hub.clone(), ASSET_MIN_BALANCE, para_sovereign_account.clone(), ); @@ -97,7 +97,7 @@ fn send_xcm_from_para_to_asset_hub_paying_fee_with_system_asset() { }, // Foreign Asset created RuntimeEvent::ForeignAssets(pallet_assets::Event::Created { asset_id, creator, owner }) => { - asset_id: *asset_id == foreign_asset_at_asset_hub, + asset_id: *asset_id == foreign_asset_at_asset_hub.clone(), creator: *creator == para_sovereign_account.clone(), owner: *owner == para_sovereign_account, }, diff --git a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/set_xcm_versions.rs b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/set_xcm_versions.rs index 736670dcfe..1835b2931c 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/set_xcm_versions.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/set_xcm_versions.rs @@ -27,7 +27,7 @@ fn relay_sets_system_para_xcm_supported_version() { assert_ok!(::XcmPallet::force_xcm_version( sudo_origin, bx!(system_para_destination.clone()), - XCM_V3 + XCM_V4 )); type RuntimeEvent = ::RuntimeEvent; @@ -37,7 +37,7 @@ fn relay_sets_system_para_xcm_supported_version() { vec![ RuntimeEvent::XcmPallet(pallet_xcm::Event::SupportedVersionChanged { location, - version: XCM_V3 + version: XCM_V4 }) => { location: *location == system_para_destination, }, ] ); @@ -53,7 +53,7 @@ fn system_para_sets_relay_xcm_supported_version() { ::Runtime, >::force_xcm_version { location: bx!(parent_location.clone()), - version: XCM_V3, + version: XCM_V4, }) .encode() .into(); @@ -78,7 +78,7 @@ fn system_para_sets_relay_xcm_supported_version() { vec![ RuntimeEvent::PolkadotXcm(pallet_xcm::Event::SupportedVersionChanged { location, - version: XCM_V3 + version: XCM_V4 }) => { location: *location == parent_location, }, ] ); 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 139bc70286..c3188c67b4 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 @@ -21,15 +21,12 @@ use system_parachains_constants::polkadot::currency::SYSTEM_PARA_EXISTENTIAL_DEP fn swap_locally_on_chain_using_local_assets() { use frame_support::traits::fungible::Mutate; - let asset_native: xcm::v3::Location = - asset_hub_polkadot_runtime::xcm_config::DotLocation::get() - .try_into() - .expect("conversion works"); - let asset_one = v3::Location::new( + let asset_native = asset_hub_polkadot_runtime::xcm_config::DotLocation::get(); + let asset_one = v4::Location::new( 0, [ - v3::Junction::PalletInstance(ASSETS_PALLET_ID), - v3::Junction::GeneralIndex(ASSET_ID.into()), + v4::Junction::PalletInstance(ASSETS_PALLET_ID), + v4::Junction::GeneralIndex(ASSET_ID.into()), ], ); @@ -58,8 +55,8 @@ fn swap_locally_on_chain_using_local_assets() { assert_ok!(::AssetConversion::create_pool( ::RuntimeOrigin::signed(AssetHubPolkadotSender::get()), - bx!(asset_native), - bx!(asset_one), + bx!(asset_native.clone()), + bx!(asset_one.clone()), )); assert_expected_events!( @@ -71,8 +68,8 @@ fn swap_locally_on_chain_using_local_assets() { assert_ok!(::AssetConversion::add_liquidity( ::RuntimeOrigin::signed(AssetHubPolkadotSender::get()), - bx!(asset_native), - bx!(asset_one), + bx!(asset_native.clone()), + bx!(asset_one.clone()), 1_000_000_000_000, 2_000_000_000_000, 0, @@ -87,7 +84,7 @@ fn swap_locally_on_chain_using_local_assets() { ] ); - let path = vec![bx!(asset_native), bx!(asset_one)]; + let path = vec![bx!(asset_native.clone()), bx!(asset_one.clone())]; assert_ok!( ::AssetConversion::swap_exact_tokens_for_tokens( @@ -128,14 +125,10 @@ fn swap_locally_on_chain_using_local_assets() { #[test] fn swap_locally_on_chain_using_foreign_assets() { - let asset_native = Box::new( - v3::Location::try_from(asset_hub_polkadot_runtime::xcm_config::DotLocation::get()) - .expect("conversion works"), - ); - let asset_location_on_penpal = - v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion works"); + let asset_native = Box::new(asset_hub_polkadot_runtime::xcm_config::DotLocation::get()); + let asset_location_on_penpal = PenpalLocalTeleportableToAssetHub::get(); let foreign_asset_at_asset_hub_polkadot = - v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) + v4::Location::new(1, [v4::Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) .unwrap(); @@ -160,7 +153,7 @@ fn swap_locally_on_chain_using_foreign_assets() { // 3. Mint foreign asset (in reality this should be a teleport or some such) assert_ok!(::ForeignAssets::mint( ::RuntimeOrigin::signed(sov_penpal_on_ahp.clone()), - foreign_asset_at_asset_hub_polkadot, + foreign_asset_at_asset_hub_polkadot.clone(), sov_penpal_on_ahp.clone().into(), ASSET_HUB_POLKADOT_ED * 3_000_000_000_000, )); @@ -176,7 +169,7 @@ fn swap_locally_on_chain_using_foreign_assets() { assert_ok!(::AssetConversion::create_pool( ::RuntimeOrigin::signed(AssetHubPolkadotSender::get()), asset_native.clone(), - Box::new(foreign_asset_at_asset_hub_polkadot), + Box::new(foreign_asset_at_asset_hub_polkadot.clone()), )); assert_expected_events!( @@ -190,7 +183,7 @@ fn swap_locally_on_chain_using_foreign_assets() { assert_ok!(::AssetConversion::add_liquidity( ::RuntimeOrigin::signed(sov_penpal_on_ahp.clone()), asset_native.clone(), - Box::new(foreign_asset_at_asset_hub_polkadot), + Box::new(foreign_asset_at_asset_hub_polkadot.clone()), 1_000_000_000_000, 2_000_000_000_000, 0, @@ -208,7 +201,8 @@ fn swap_locally_on_chain_using_foreign_assets() { ); // 6. Swap! - let path = vec![asset_native.clone(), Box::new(foreign_asset_at_asset_hub_polkadot)]; + let path = + vec![asset_native.clone(), Box::new(foreign_asset_at_asset_hub_polkadot.clone())]; assert_ok!( ::AssetConversion::swap_exact_tokens_for_tokens( @@ -250,14 +244,10 @@ fn swap_locally_on_chain_using_foreign_assets() { fn cannot_create_pool_from_pool_assets() { use frame_support::traits::fungibles::{Create, Mutate}; - let asset_native = asset_hub_polkadot_runtime::xcm_config::DotLocation::get() - .try_into() - .expect("conversion works"); + let asset_native = asset_hub_polkadot_runtime::xcm_config::DotLocation::get(); let asset_one = asset_hub_polkadot_runtime::xcm_config::PoolAssetsPalletLocation::get() .appended_with(GeneralIndex(ASSET_ID.into())) - .expect("valid location") - .try_into() - .expect("conversion works"); + .expect("valid location"); AssetHubPolkadot::execute_with(|| { assert_ok!( @@ -291,15 +281,13 @@ fn cannot_create_pool_from_pool_assets() { fn pay_xcm_fee_with_some_asset_swapped_for_native() { use frame_support::traits::fungible::Mutate; - let asset_native: xcm::v3::Location = - asset_hub_polkadot_runtime::xcm_config::DotLocation::get() - .try_into() - .expect("conversion works"); - let asset_one = xcm::v3::Location { + let asset_native: xcm::v4::Location = + asset_hub_polkadot_runtime::xcm_config::DotLocation::get(); + let asset_one = xcm::v4::Location { parents: 0, interior: [ - xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), - xcm::v3::Junction::GeneralIndex(ASSET_ID.into()), + xcm::v4::Junction::PalletInstance(ASSETS_PALLET_ID), + xcm::v4::Junction::GeneralIndex(ASSET_ID.into()), ] .into(), }; @@ -333,8 +321,8 @@ fn pay_xcm_fee_with_some_asset_swapped_for_native() { assert_ok!(::AssetConversion::create_pool( ::RuntimeOrigin::signed(AssetHubPolkadotSender::get()), - Box::new(asset_native), - Box::new(asset_one), + Box::new(asset_native.clone()), + Box::new(asset_one.clone()), )); assert_expected_events!( diff --git a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/teleport.rs b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/teleport.rs index 5037a4379f..6965fe571d 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/teleport.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/teleport.rs @@ -86,7 +86,6 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { ); let (expected_foreign_asset_id, expected_foreign_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); - let expected_foreign_asset_id_v3: v3::Location = expected_foreign_asset_id.try_into().unwrap(); AssetHubPolkadot::assert_xcmp_queue_success(None); assert_expected_events!( AssetHubPolkadot, @@ -102,7 +101,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 == expected_foreign_asset_id_v3, + asset_id: *asset_id == expected_foreign_asset_id, owner: *owner == t.receiver.account_id, amount: *amount == expected_foreign_asset_amount, }, @@ -116,7 +115,6 @@ fn ah_to_penpal_foreign_assets_sender_assertions(t: SystemParaToParaTest) { AssetHubPolkadot::assert_xcm_pallet_attempted_complete(None); let (expected_foreign_asset_id, expected_foreign_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); - let expected_foreign_asset_id_v3: v3::Location = expected_foreign_asset_id.try_into().unwrap(); assert_expected_events!( AssetHubPolkadot, vec![ @@ -132,7 +130,7 @@ fn ah_to_penpal_foreign_assets_sender_assertions(t: SystemParaToParaTest) { }, // foreign asset is burned locally as part of teleportation RuntimeEvent::ForeignAssets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { - asset_id: *asset_id == expected_foreign_asset_id_v3, + asset_id: *asset_id == expected_foreign_asset_id, owner: *owner == t.sender.account_id, balance: *balance == expected_foreign_asset_amount, }, @@ -376,7 +374,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let ah_receiver_assets_before = AssetHubPolkadot::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - foreign_asset_at_asset_hub_polkadot.clone().try_into().unwrap(), + foreign_asset_at_asset_hub_polkadot.clone(), &AssetHubPolkadotReceiver::get(), ) }); @@ -403,7 +401,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let ah_receiver_assets_after = AssetHubPolkadot::execute_with(|| { type Assets = ::ForeignAssets; >::balance( - foreign_asset_at_asset_hub_polkadot.clone().try_into().unwrap(), + foreign_asset_at_asset_hub_polkadot.clone(), &AssetHubPolkadotReceiver::get(), ) }); @@ -431,7 +429,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using type ForeignAssets = ::ForeignAssets; assert_ok!(ForeignAssets::transfer( ::RuntimeOrigin::signed(AssetHubPolkadotReceiver::get()), - foreign_asset_at_asset_hub_polkadot.clone().try_into().unwrap(), + foreign_asset_at_asset_hub_polkadot.clone(), AssetHubPolkadotSender::get().into(), asset_amount_to_send, )); @@ -477,7 +475,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let ah_sender_assets_before = AssetHubPolkadot::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - foreign_asset_at_asset_hub_polkadot.clone().try_into().unwrap(), + foreign_asset_at_asset_hub_polkadot.clone(), &AssetHubPolkadotSender::get(), ) }); @@ -503,7 +501,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using let ah_sender_assets_after = AssetHubPolkadot::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - foreign_asset_at_asset_hub_polkadot.try_into().unwrap(), + foreign_asset_at_asset_hub_polkadot, &AssetHubPolkadotSender::get(), ) }); diff --git a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/treasury.rs b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/treasury.rs index b9d1786667..57319bb5fe 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/treasury.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/treasury.rs @@ -32,13 +32,13 @@ fn create_and_claim_treasury_spend_in_usdt() { ) .unwrap(); let asset_hub_location = - v3::Location::new(0, v3::Junction::Parachain(AssetHubPolkadot::para_id().into())); + v4::Location::new(0, v4::Junction::Parachain(AssetHubPolkadot::para_id().into())); let root = ::RuntimeOrigin::root(); // asset kind to be spend from the treasury. - let asset_kind = VersionedLocatableAsset::V3 { + let asset_kind = VersionedLocatableAsset::V4 { location: asset_hub_location, - asset_id: v3::AssetId::Concrete( - (v3::Junction::PalletInstance(50), v3::Junction::GeneralIndex(USDT_ID.into())).into(), + asset_id: v4::AssetId( + (v4::Junction::PalletInstance(50), v4::Junction::GeneralIndex(USDT_ID.into())).into(), ), }; // treasury spend beneficiary. diff --git a/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/lib.rs b/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/lib.rs index 8b8610d4f7..548bdccea2 100644 --- a/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/lib.rs +++ b/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/lib.rs @@ -21,7 +21,7 @@ pub use sp_runtime::{traits::Dispatchable, DispatchError}; pub use xcm::{ latest::ParentThen, prelude::{AccountId32 as AccountId32Junction, *}, - v3::{ + v4::{ self, Error, NetworkId::{Kusama as KusamaId, Polkadot as PolkadotId}, }, @@ -41,7 +41,7 @@ pub use emulated_integration_tests_common::{ RelayChain as Relay, Test, TestArgs, TestContext, TestExt, }, xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, - ASSETS_PALLET_ID, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, + ASSETS_PALLET_ID, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V4, }; pub use kusama_polkadot_system_emulated_network::{ asset_hub_kusama_emulated_chain::{ 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 ed19440c46..0e7621dabd 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 @@ -36,10 +36,10 @@ fn send_assets_over_bridge(send_fn: F) { fn set_up_ksm_for_penpal_kusama_through_kah_to_pah( sender: &AccountId, amount: u128, -) -> (Location, v3::Location) { +) -> (Location, v4::Location) { let ksm_at_kusama_parachains = ksm_at_ah_kusama(); - let ksm_at_asset_hub_polkadot = v3::Location::try_from(bridged_ksm_at_ah_polkadot()).unwrap(); - create_foreign_on_ah_polkadot(ksm_at_asset_hub_polkadot, true); + let ksm_at_asset_hub_polkadot = bridged_ksm_at_ah_polkadot(); + create_foreign_on_ah_polkadot(ksm_at_asset_hub_polkadot.clone(), true); let penpal_location = AssetHubKusama::sibling_location_of(PenpalA::para_id()); let sov_penpal_on_kah = AssetHubKusama::sovereign_account_id_of(penpal_location); @@ -115,11 +115,11 @@ fn send_ksm_from_asset_hub_kusama_to_asset_hub_polkadot() { let amount = ASSET_HUB_KUSAMA_ED * 1_000; let sender = AssetHubKusamaSender::get(); let receiver = AssetHubPolkadotReceiver::get(); - let ksm_at_asset_hub_kusama = v3::Location::try_from(ksm_at_ah_kusama()).unwrap(); - let bridged_ksm_at_ah_polkadot = v3::Location::try_from(bridged_ksm_at_ah_polkadot()).unwrap(); + let ksm_at_asset_hub_kusama = ksm_at_ah_kusama(); + let bridged_ksm_at_ah_polkadot = bridged_ksm_at_ah_polkadot(); - create_foreign_on_ah_polkadot(bridged_ksm_at_ah_polkadot, true); - set_up_pool_with_dot_on_ah_polkadot(bridged_ksm_at_ah_polkadot, true); + create_foreign_on_ah_polkadot(bridged_ksm_at_ah_polkadot.clone(), true); + set_up_pool_with_dot_on_ah_polkadot(bridged_ksm_at_ah_polkadot.clone(), true); let sov_ahp_on_ahk = AssetHubKusama::sovereign_account_of_parachain_on_other_global_consensus( Polkadot, @@ -129,7 +129,7 @@ fn send_ksm_from_asset_hub_kusama_to_asset_hub_polkadot() { ::account_data_of(sov_ahp_on_ahk.clone()).free; let sender_ksms_before = ::account_data_of(sender.clone()).free; let receiver_ksms_before = - foreign_balance_on_ah_polkadot(bridged_ksm_at_ah_polkadot, &receiver); + foreign_balance_on_ah_polkadot(bridged_ksm_at_ah_polkadot.clone(), &receiver); let ksm_at_ah_kusama_latest = ksm_at_ah_kusama(); @@ -187,9 +187,9 @@ fn send_back_dot_usdt_and_weth_from_asset_hub_kusama_to_asset_hub_polkadot() { let amount_to_send = ASSET_HUB_POLKADOT_ED * 1_000; let sender = AssetHubKusamaSender::get(); let receiver = AssetHubPolkadotReceiver::get(); - let dot_at_asset_hub_kusama = v3::Location::try_from(bridged_dot_at_ah_kusama()).unwrap(); + let dot_at_asset_hub_kusama = bridged_dot_at_ah_kusama(); let prefund_accounts = vec![(sender.clone(), prefund_amount)]; - create_foreign_on_ah_kusama(dot_at_asset_hub_kusama, true, prefund_accounts); + create_foreign_on_ah_kusama(dot_at_asset_hub_kusama.clone(), true, prefund_accounts); //////////////////////////////////////////////////////////// // Let's first send back just some DOTs as a simple example @@ -206,7 +206,7 @@ fn send_back_dot_usdt_and_weth_from_asset_hub_kusama_to_asset_hub_polkadot() { ::account_data_of(sov_kah_on_pah.clone()).free; assert_eq!(dot_in_reserve_on_pah_before, prefund_amount); - let sender_dot_before = foreign_balance_on_ah_kusama(dot_at_asset_hub_kusama, &sender); + let sender_dot_before = foreign_balance_on_ah_kusama(dot_at_asset_hub_kusama.clone(), &sender); assert_eq!(sender_dot_before, prefund_amount); let receiver_dot_before = ::account_data_of(receiver.clone()).free; @@ -259,15 +259,14 @@ fn send_back_dot_usdt_and_weth_from_asset_hub_kusama_to_asset_hub_polkadot() { ////////////////////////////////////////////////////////////////// // wETH has same relative location on both Polkadot and Kusama AssetHubs - let bridged_weth_at_ah = v3::Location::try_from(weth_at_asset_hubs()).unwrap(); - let bridged_usdt_at_asset_hub_kusama = - v3::Location::try_from(bridged_usdt_at_ah_kusama()).unwrap(); + let bridged_weth_at_ah = weth_at_asset_hubs(); + let bridged_usdt_at_asset_hub_kusama = bridged_usdt_at_ah_kusama(); // set up destination chain AH Polkadot: // create a DOT/USDT pool to be able to pay fees with USDT (USDT created in genesis) - set_up_pool_with_dot_on_ah_polkadot(usdt_at_ah_polkadot().try_into().unwrap(), false); + set_up_pool_with_dot_on_ah_polkadot(usdt_at_ah_polkadot(), false); // create wETH on Polkadot (IRL it's already created by Snowbridge) - create_foreign_on_ah_polkadot(bridged_weth_at_ah, true); + create_foreign_on_ah_polkadot(bridged_weth_at_ah.clone(), true); // prefund KAH's sovereign account on PAH to be able to withdraw USDT and wETH from reserves let sov_kah_on_pah = AssetHubPolkadot::sovereign_account_of_parachain_on_other_global_consensus( Kusama, @@ -281,7 +280,7 @@ fn send_back_dot_usdt_and_weth_from_asset_hub_kusama_to_asset_hub_polkadot() { ); AssetHubPolkadot::mint_foreign_asset( ::RuntimeOrigin::signed(AssetHubPolkadot::account_id_of(ALICE)), - bridged_weth_at_ah, + bridged_weth_at_ah.clone(), sov_kah_on_pah, amount_to_send * 2, ); @@ -289,21 +288,22 @@ fn send_back_dot_usdt_and_weth_from_asset_hub_kusama_to_asset_hub_polkadot() { // set up source chain AH Kusama: // create wETH and USDT foreign assets on Kusama and prefund sender's account let prefund_accounts = vec![(sender.clone(), amount_to_send * 2)]; - create_foreign_on_ah_kusama(bridged_weth_at_ah, true, prefund_accounts.clone()); - create_foreign_on_ah_kusama(bridged_usdt_at_asset_hub_kusama, true, prefund_accounts); + create_foreign_on_ah_kusama(bridged_weth_at_ah.clone(), true, prefund_accounts.clone()); + create_foreign_on_ah_kusama(bridged_usdt_at_asset_hub_kusama.clone(), true, prefund_accounts); // check balances before let receiver_usdts_before = AssetHubPolkadot::execute_with(|| { type Assets = ::Assets; >::balance(USDT_ID, &receiver) }); - let receiver_weth_before = foreign_balance_on_ah_polkadot(bridged_weth_at_ah, &receiver); + let receiver_weth_before = + foreign_balance_on_ah_polkadot(bridged_weth_at_ah.clone(), &receiver); - let usdt_id: AssetId = Location::try_from(bridged_usdt_at_asset_hub_kusama).unwrap().into(); + let usdt_id: AssetId = bridged_usdt_at_asset_hub_kusama.into(); // send USDTs and wETHs let assets: Assets = vec![ (usdt_id.clone(), amount_to_send).into(), - (Location::try_from(bridged_weth_at_ah).unwrap(), amount_to_send).into(), + (bridged_weth_at_ah.clone(), amount_to_send).into(), ] .into(); // use USDT for fees @@ -365,7 +365,8 @@ fn send_ksm_from_penpal_kusama_through_asset_hub_kusama_to_asset_hub_polkadot() type ForeignAssets = ::ForeignAssets; >::balance(ksm_at_kusama_parachains.clone(), &sender) }); - let receiver_ksm_before = foreign_balance_on_ah_polkadot(ksm_at_asset_hub_polkadot, &receiver); + let receiver_ksm_before = + foreign_balance_on_ah_polkadot(ksm_at_asset_hub_polkadot.clone(), &receiver); // Send KSMs over bridge { @@ -396,7 +397,7 @@ fn send_ksm_from_penpal_kusama_through_asset_hub_kusama_to_asset_hub_polkadot() vec![ // issue KSMs on PAH RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == v3::Location::try_from(ksm_at_kusama_parachains.clone()).unwrap(), + asset_id: *asset_id == ksm_at_kusama_parachains.clone(), owner: owner == &receiver, }, // message processed successfully @@ -426,9 +427,7 @@ fn send_ksm_from_penpal_kusama_through_asset_hub_kusama_to_asset_hub_polkadot() #[test] fn send_back_dot_from_penpal_kusama_through_asset_hub_kusama_to_asset_hub_polkadot() { - let dot_at_kusama_parachains_latest = bridged_dot_at_ah_kusama(); - let dot_at_kusama_parachains = - v3::Location::try_from(dot_at_kusama_parachains_latest.clone()).unwrap(); + let dot_at_kusama_parachains = bridged_dot_at_ah_kusama(); let amount = ASSET_HUB_KUSAMA_ED * 10_000_000; let sender = PenpalASender::get(); let receiver = AssetHubPolkadotReceiver::get(); @@ -441,10 +440,10 @@ fn send_back_dot_from_penpal_kusama_through_asset_hub_kusama_to_asset_hub_polkad let penpal_location = AssetHubKusama::sibling_location_of(PenpalA::para_id()); let sov_penpal_on_kah = AssetHubKusama::sovereign_account_id_of(penpal_location); let prefund_accounts = vec![(sov_penpal_on_kah, amount * 2)]; - create_foreign_on_ah_kusama(dot_at_kusama_parachains, true, prefund_accounts); + create_foreign_on_ah_kusama(dot_at_kusama_parachains.clone(), true, prefund_accounts); let asset_owner: AccountId = AssetHubKusama::account_id_of(ALICE); PenpalA::force_create_foreign_asset( - dot_at_kusama_parachains_latest.clone(), + dot_at_kusama_parachains.clone(), asset_owner.clone(), true, ASSET_MIN_BALANCE, @@ -461,7 +460,7 @@ fn send_back_dot_from_penpal_kusama_through_asset_hub_kusama_to_asset_hub_polkad // balances before let sender_dot_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(dot_at_kusama_parachains_latest.clone(), &sender) + >::balance(dot_at_kusama_parachains.clone(), &sender) }); let receiver_dot_before = ::account_data_of(receiver.clone()).free; @@ -474,7 +473,7 @@ fn send_back_dot_from_penpal_kusama_through_asset_hub_kusama_to_asset_hub_polkad // what happens at final destination let beneficiary = AccountId32Junction { network: None, id: receiver.clone().into() }.into(); // use DOT as fees on the final destination (PAH) - let remote_fees: Asset = (dot_at_kusama_parachains_latest.clone(), amount).into(); + let remote_fees: Asset = (dot_at_kusama_parachains.clone(), amount).into(); let remote_fees = remote_fees.reanchored(&final_destination, &context).unwrap(); // buy execution using DOTs, then deposit all remaining DOTs let xcm_on_final_dest = Xcm::<()>(vec![ @@ -487,7 +486,7 @@ fn send_back_dot_from_penpal_kusama_through_asset_hub_kusama_to_asset_hub_polkad let mut final_destination = final_destination.clone(); final_destination.reanchor(&intermediary_hop, &context).unwrap(); // reanchor DOTs to the view of hop (Asset Hub Kusama) - let asset: Asset = (dot_at_kusama_parachains_latest.clone(), amount).into(); + let asset: Asset = (dot_at_kusama_parachains.clone(), amount).into(); let asset = asset.reanchored(&intermediary_hop, &context).unwrap(); // on Asset Hub Kusama, forward a request to withdraw DOTs from reserve on Asset Hub // Polkadot @@ -498,7 +497,7 @@ fn send_back_dot_from_penpal_kusama_through_asset_hub_kusama_to_asset_hub_polkad }]); // assets to send from Penpal and how they reach the intermediary hop let assets: Assets = vec![ - (dot_at_kusama_parachains_latest.clone(), amount).into(), + (dot_at_kusama_parachains.clone(), amount).into(), (ksm_at_kusama_parachains.clone(), amount).into(), ] .into(); @@ -533,7 +532,7 @@ fn send_back_dot_from_penpal_kusama_through_asset_hub_kusama_to_asset_hub_polkad let sender_dot_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(dot_at_kusama_parachains_latest, &sender) + >::balance(dot_at_kusama_parachains, &sender) }); let receiver_dot_after = ::account_data_of(receiver).free; diff --git a/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/tests/mod.rs b/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/tests/mod.rs index 3856201712..b943295e4a 100644 --- a/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/tests/mod.rs +++ b/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/tests/mod.rs @@ -75,7 +75,7 @@ pub(crate) fn weth_at_asset_hubs() -> Location { } pub(crate) fn create_foreign_on_ah_kusama( - id: v3::Location, + id: v4::Location, sufficient: bool, prefund_accounts: Vec<(AccountId, u128)>, ) { @@ -84,18 +84,18 @@ pub(crate) fn create_foreign_on_ah_kusama( AssetHubKusama::force_create_foreign_asset(id, owner, sufficient, min, prefund_accounts); } -pub(crate) fn create_foreign_on_ah_polkadot(id: v3::Location, sufficient: bool) { +pub(crate) fn create_foreign_on_ah_polkadot(id: v4::Location, sufficient: bool) { let owner = AssetHubPolkadot::account_id_of(ALICE); AssetHubPolkadot::force_create_foreign_asset(id, owner, sufficient, ASSET_MIN_BALANCE, vec![]); } -pub(crate) fn foreign_balance_on_ah_kusama(id: v3::Location, who: &AccountId) -> u128 { +pub(crate) fn foreign_balance_on_ah_kusama(id: v4::Location, who: &AccountId) -> u128 { AssetHubKusama::execute_with(|| { type Assets = ::ForeignAssets; >::balance(id, who) }) } -pub(crate) fn foreign_balance_on_ah_polkadot(id: v3::Location, who: &AccountId) -> u128 { +pub(crate) fn foreign_balance_on_ah_polkadot(id: v4::Location, who: &AccountId) -> u128 { AssetHubPolkadot::execute_with(|| { type Assets = ::ForeignAssets; >::balance(id, who) @@ -103,8 +103,8 @@ pub(crate) fn foreign_balance_on_ah_polkadot(id: v3::Location, who: &AccountId) } // set up pool -pub(crate) fn set_up_pool_with_dot_on_ah_polkadot(asset: v3::Location, is_foreign: bool) { - let dot: v3::Location = v3::Parent.into(); +pub(crate) fn set_up_pool_with_dot_on_ah_polkadot(asset: v4::Location, is_foreign: bool) { + let dot: v4::Location = v4::Parent.into(); AssetHubPolkadot::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; let owner = AssetHubPolkadotSender::get(); @@ -113,13 +113,13 @@ pub(crate) fn set_up_pool_with_dot_on_ah_polkadot(asset: v3::Location, is_foreig if is_foreign { assert_ok!(::ForeignAssets::mint( signed_owner.clone(), - asset, + asset.clone(), owner.clone().into(), 3_000_000_000_000, )); } else { let asset_id = match asset.interior.last() { - Some(v3::Junction::GeneralIndex(id)) => *id as u32, + Some(v4::Junction::GeneralIndex(id)) => *id as u32, _ => unreachable!(), }; assert_ok!(::Assets::mint( @@ -131,8 +131,8 @@ pub(crate) fn set_up_pool_with_dot_on_ah_polkadot(asset: v3::Location, is_foreig } assert_ok!(::AssetConversion::create_pool( signed_owner.clone(), - Box::new(dot), - Box::new(asset), + Box::new(dot.clone()), + Box::new(asset.clone()), )); assert_expected_events!( AssetHubPolkadot, diff --git a/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/tests/register_bridged_assets.rs b/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/tests/register_bridged_assets.rs index c719589e9c..2e42fcb4f7 100644 --- a/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/tests/register_bridged_assets.rs +++ b/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/tests/register_bridged_assets.rs @@ -27,19 +27,19 @@ fn register_kusama_asset_on_pah_from_kah() { ); // Kusama Asset Hub asset when bridged to Polkadot Asset Hub. - let bridged_asset_at_pah = v3::Location::new( + let bridged_asset_at_pah = v4::Location::new( 2, [ - v3::Junction::GlobalConsensus(v3::NetworkId::Kusama), - v3::Junction::Parachain(AssetHubKusama::para_id().into()), - v3::Junction::PalletInstance(ASSETS_PALLET_ID), - v3::Junction::GeneralIndex(ASSET_ID.into()), + v4::Junction::GlobalConsensus(v4::NetworkId::Kusama), + v4::Junction::Parachain(AssetHubKusama::para_id().into()), + v4::Junction::PalletInstance(ASSETS_PALLET_ID), + v4::Junction::GeneralIndex(ASSET_ID.into()), ], ); // Encoded `create_asset` call to be executed in Polkadot Asset Hub ForeignAssets pallet. let call = AssetHubPolkadot::create_foreign_asset_call( - bridged_asset_at_pah, + bridged_asset_at_pah.clone(), ASSET_MIN_BALANCE, sa_of_kah_on_pah.clone(), ); diff --git a/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/tests/send_xcm.rs b/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/tests/send_xcm.rs index a2de082dc1..a166e9ac0d 100644 --- a/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/tests/send_xcm.rs +++ b/integration-tests/emulated/tests/bridges/bridge-hub-kusama/src/tests/send_xcm.rs @@ -29,7 +29,7 @@ fn send_xcm_from_kusama_relay_to_polkadot_asset_hub_should_fail_on_not_applicabl let xcm = VersionedXcm::from(Xcm(vec![ UnpaidExecution { weight_limit, check_origin }, ExportMessage { - network: PolkadotId.into(), + network: PolkadotId, destination: [Parachain(AssetHubPolkadot::para_id().into())].into(), xcm: remote_xcm, }, diff --git a/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/lib.rs b/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/lib.rs index 14d75e66f6..96c99fa117 100644 --- a/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/lib.rs +++ b/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/lib.rs @@ -21,7 +21,7 @@ pub use sp_runtime::DispatchError; pub use xcm::{ latest::ParentThen, prelude::{AccountId32 as AccountId32Junction, *}, - v3::{ + v4::{ self, Error, NetworkId::{Kusama as KusamaId, Polkadot as PolkadotId}, }, @@ -41,7 +41,7 @@ pub use emulated_integration_tests_common::{ RelayChain as Relay, Test, TestArgs, TestContext, TestExt, }, xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, - ASSETS_PALLET_ID, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, + ASSETS_PALLET_ID, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V4, }; pub use kusama_polkadot_system_emulated_network::{ asset_hub_kusama_emulated_chain::{ 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 b41169bdbe..6ce75f3441 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 @@ -36,10 +36,10 @@ fn send_assets_over_bridge(send_fn: F) { fn set_up_dot_for_penpal_polkadot_through_pah_to_kah( sender: &AccountId, amount: u128, -) -> (Location, v3::Location) { +) -> (Location, v4::Location) { let dot_at_polkadot_parachains = dot_at_ah_polkadot(); - let dot_at_asset_hub_kusama = v3::Location::try_from(bridged_dot_at_ah_kusama()).unwrap(); - create_foreign_on_ah_kusama(dot_at_asset_hub_kusama, true); + let dot_at_asset_hub_kusama = bridged_dot_at_ah_kusama(); + create_foreign_on_ah_kusama(dot_at_asset_hub_kusama.clone(), true); let penpal_location = AssetHubPolkadot::sibling_location_of(PenpalB::para_id()); let sov_penpal_on_pah = AssetHubPolkadot::sovereign_account_id_of(penpal_location); @@ -123,11 +123,10 @@ fn send_dot_usdt_and_weth_from_asset_hub_polkadot_to_asset_hub_kusama() { let sender = AssetHubPolkadotSender::get(); let receiver = AssetHubKusamaReceiver::get(); let dot_at_asset_hub_polkadot = dot_at_ah_polkadot(); - let bridged_dot_at_asset_hub_kusama = - v3::Location::try_from(bridged_dot_at_ah_kusama()).unwrap(); + let bridged_dot_at_asset_hub_kusama = bridged_dot_at_ah_kusama(); - create_foreign_on_ah_kusama(bridged_dot_at_asset_hub_kusama, true); - set_up_pool_with_ksm_on_ah_kusama(bridged_dot_at_asset_hub_kusama, true); + create_foreign_on_ah_kusama(bridged_dot_at_asset_hub_kusama.clone(), true); + set_up_pool_with_ksm_on_ah_kusama(bridged_dot_at_asset_hub_kusama.clone(), true); //////////////////////////////////////////////////////////// // Let's first send over just some DOTs as a simple example @@ -140,7 +139,7 @@ fn send_dot_usdt_and_weth_from_asset_hub_polkadot_to_asset_hub_kusama() { ::account_data_of(sov_kah_on_pah.clone()).free; let sender_dot_before = ::account_data_of(sender.clone()).free; let receiver_dot_before = - foreign_balance_on_ah_kusama(bridged_dot_at_asset_hub_kusama, &receiver); + foreign_balance_on_ah_kusama(bridged_dot_at_asset_hub_kusama.clone(), &receiver); // send DOTs, use them for fees send_assets_over_bridge(|| { @@ -186,10 +185,9 @@ fn send_dot_usdt_and_weth_from_asset_hub_polkadot_to_asset_hub_kusama() { // Now let's send over USDTs + wETH (and pay fees with USDT) ///////////////////////////////////////////////////////////// let usdt_at_asset_hub_polkadot = usdt_at_ah_polkadot(); - let bridged_usdt_at_asset_hub_kusama = - v3::Location::try_from(bridged_usdt_at_ah_kusama()).unwrap(); + let bridged_usdt_at_asset_hub_kusama = bridged_usdt_at_ah_kusama(); // wETH has same relative location on both Polkadot and Kusama AssetHubs - let bridged_weth_at_ah = v3::Location::try_from(weth_at_asset_hubs()).unwrap(); + let bridged_weth_at_ah = weth_at_asset_hubs(); // mint USDT in sender's account (USDT already created in genesis) AssetHubPolkadot::mint_asset( @@ -199,19 +197,23 @@ fn send_dot_usdt_and_weth_from_asset_hub_polkadot_to_asset_hub_kusama() { amount * 2, ); // create wETH at src and dest and prefund sender's account - create_foreign_on_ah_polkadot(bridged_weth_at_ah, true, vec![(sender.clone(), amount * 2)]); - create_foreign_on_ah_kusama(bridged_weth_at_ah, true); - create_foreign_on_ah_kusama(bridged_usdt_at_asset_hub_kusama, true); - set_up_pool_with_ksm_on_ah_kusama(bridged_usdt_at_asset_hub_kusama, true); + create_foreign_on_ah_polkadot( + bridged_weth_at_ah.clone(), + true, + vec![(sender.clone(), amount * 2)], + ); + create_foreign_on_ah_kusama(bridged_weth_at_ah.clone(), true); + create_foreign_on_ah_kusama(bridged_usdt_at_asset_hub_kusama.clone(), true); + set_up_pool_with_ksm_on_ah_kusama(bridged_usdt_at_asset_hub_kusama.clone(), true); let receiver_usdts_before = - foreign_balance_on_ah_kusama(bridged_usdt_at_asset_hub_kusama, &receiver); - let receiver_weth_before = foreign_balance_on_ah_kusama(bridged_weth_at_ah, &receiver); + foreign_balance_on_ah_kusama(bridged_usdt_at_asset_hub_kusama.clone(), &receiver); + let receiver_weth_before = foreign_balance_on_ah_kusama(bridged_weth_at_ah.clone(), &receiver); // send USDTs and wETHs let assets: Assets = vec![ (usdt_at_asset_hub_polkadot.clone(), amount).into(), - (Location::try_from(bridged_weth_at_ah).unwrap(), amount).into(), + (bridged_weth_at_ah.clone(), amount).into(), ] .into(); // use USDT for fees @@ -259,10 +261,13 @@ fn send_back_ksm_from_asset_hub_polkadot_to_asset_hub_kusama() { let amount_to_send = ASSET_HUB_KUSAMA_ED * 1_000; let sender = AssetHubPolkadotSender::get(); let receiver = AssetHubKusamaReceiver::get(); - let bridged_ksm_at_asset_hub_polkadot = - v3::Location::try_from(bridged_ksm_at_ah_polkadot()).unwrap(); + let bridged_ksm_at_asset_hub_polkadot = bridged_ksm_at_ah_polkadot(); let prefund_accounts = vec![(sender.clone(), prefund_amount)]; - create_foreign_on_ah_polkadot(bridged_ksm_at_asset_hub_polkadot, true, prefund_accounts); + create_foreign_on_ah_polkadot( + bridged_ksm_at_asset_hub_polkadot.clone(), + true, + prefund_accounts, + ); // fund the PAH's SA on KAH with the KSM tokens held in reserve let sov_pah_on_kah = AssetHubKusama::sovereign_account_of_parachain_on_other_global_consensus( @@ -276,15 +281,14 @@ fn send_back_ksm_from_asset_hub_polkadot_to_asset_hub_kusama() { assert_eq!(ksm_in_reserve_on_kah_before, prefund_amount); let sender_ksm_before = - foreign_balance_on_ah_polkadot(bridged_ksm_at_asset_hub_polkadot, &sender); + foreign_balance_on_ah_polkadot(bridged_ksm_at_asset_hub_polkadot.clone(), &sender); assert_eq!(sender_ksm_before, prefund_amount); let receiver_ksm_before = ::account_data_of(receiver.clone()).free; // send back KSMs, use them for fees send_assets_over_bridge(|| { let destination = asset_hub_kusama_location(); - let assets: Assets = - (Location::try_from(bridged_ksm_at_asset_hub_polkadot).unwrap(), amount_to_send).into(); + let assets: Assets = (bridged_ksm_at_asset_hub_polkadot.clone(), amount_to_send).into(); let fee_idx = 0; assert_ok!(send_assets_from_asset_hub_polkadot(destination, assets, fee_idx)); }); @@ -346,7 +350,8 @@ fn send_dot_from_penpal_polkadot_through_asset_hub_polkadot_to_asset_hub_kusama( type ForeignAssets = ::ForeignAssets; >::balance(dot_at_polkadot_parachains.clone(), &sender) }); - let receiver_dot_before = foreign_balance_on_ah_kusama(dot_at_asset_hub_kusama, &receiver); + let receiver_dot_before = + foreign_balance_on_ah_kusama(dot_at_asset_hub_kusama.clone(), &receiver); // Send DOTs over bridge { @@ -377,7 +382,7 @@ fn send_dot_from_penpal_polkadot_through_asset_hub_polkadot_to_asset_hub_kusama( vec![ // issue DOTs on KAH RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == v3::Location::try_from(dot_at_polkadot_parachains.clone()).unwrap(), + asset_id: *asset_id == dot_at_polkadot_parachains.clone(), owner: owner == &receiver, }, // message processed successfully @@ -407,7 +412,7 @@ fn send_dot_from_penpal_polkadot_through_asset_hub_polkadot_to_asset_hub_kusama( #[test] fn send_back_ksm_from_penpal_polkadot_through_asset_hub_polkadot_to_asset_hub_kusama() { - let ksm_at_polkadot_parachains = v3::Location::try_from(bridged_ksm_at_ah_polkadot()).unwrap(); + let ksm_at_polkadot_parachains = bridged_ksm_at_ah_polkadot(); let amount = ASSET_HUB_POLKADOT_ED * 10_000_000; let sender = PenpalBSender::get(); let receiver = AssetHubKusamaReceiver::get(); @@ -420,10 +425,10 @@ fn send_back_ksm_from_penpal_polkadot_through_asset_hub_polkadot_to_asset_hub_ku let penpal_location = AssetHubPolkadot::sibling_location_of(PenpalB::para_id()); let sov_penpal_on_kah = AssetHubPolkadot::sovereign_account_id_of(penpal_location); let prefund_accounts = vec![(sov_penpal_on_kah, amount * 2)]; - create_foreign_on_ah_polkadot(ksm_at_polkadot_parachains, true, prefund_accounts); + create_foreign_on_ah_polkadot(ksm_at_polkadot_parachains.clone(), true, prefund_accounts); let asset_owner: AccountId = AssetHubPolkadot::account_id_of(ALICE); PenpalB::force_create_foreign_asset( - ksm_at_polkadot_parachains.try_into().unwrap(), + ksm_at_polkadot_parachains.clone(), asset_owner.clone(), true, ASSET_MIN_BALANCE, @@ -440,15 +445,10 @@ fn send_back_ksm_from_penpal_polkadot_through_asset_hub_polkadot_to_asset_hub_ku // balances before let sender_ksm_before = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance( - ksm_at_polkadot_parachains.try_into().unwrap(), - &sender, - ) + >::balance(ksm_at_polkadot_parachains.clone(), &sender) }); let receiver_ksm_before = ::account_data_of(receiver.clone()).free; - let ksm_at_polkadot_parachains_latest: Location = - ksm_at_polkadot_parachains.try_into().unwrap(); // send KSMs over the bridge, DOTs only used to pay fees on local AH, pay with KSM on remote AH { let final_destination = asset_hub_kusama_location(); @@ -458,7 +458,7 @@ fn send_back_ksm_from_penpal_polkadot_through_asset_hub_polkadot_to_asset_hub_ku // what happens at final destination let beneficiary = AccountId32Junction { network: None, id: receiver.clone().into() }.into(); // use KSM as fees on the final destination (PAH) - let remote_fees: Asset = (ksm_at_polkadot_parachains_latest.clone(), amount).into(); + let remote_fees: Asset = (ksm_at_polkadot_parachains.clone(), amount).into(); let remote_fees = remote_fees.reanchored(&final_destination, &context).unwrap(); // buy execution using KSMs, then deposit all remaining KSMs let xcm_on_final_dest = Xcm::<()>(vec![ @@ -471,7 +471,7 @@ fn send_back_ksm_from_penpal_polkadot_through_asset_hub_polkadot_to_asset_hub_ku let mut final_destination = final_destination.clone(); final_destination.reanchor(&intermediary_hop, &context).unwrap(); // reanchor KSMs to the view of hop (Asset Hub Polkadot) - let asset: Asset = (ksm_at_polkadot_parachains_latest.clone(), amount).into(); + let asset: Asset = (ksm_at_polkadot_parachains.clone(), amount).into(); let asset = asset.reanchored(&intermediary_hop, &context).unwrap(); // on Asset Hub Polkadot, forward a request to withdraw KSMs from reserve on Asset Hub // Kusama @@ -482,7 +482,7 @@ fn send_back_ksm_from_penpal_polkadot_through_asset_hub_polkadot_to_asset_hub_ku }]); // assets to send from Penpal and how they reach the intermediary hop let assets: Assets = vec![ - (ksm_at_polkadot_parachains_latest, amount).into(), + (ksm_at_polkadot_parachains.clone(), amount).into(), (dot_at_polkadot_parachains.clone(), amount).into(), ] .into(); @@ -517,10 +517,7 @@ fn send_back_ksm_from_penpal_polkadot_through_asset_hub_polkadot_to_asset_hub_ku let sender_ksm_after = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance( - ksm_at_polkadot_parachains.try_into().unwrap(), - &sender, - ) + >::balance(ksm_at_polkadot_parachains, &sender) }); let receiver_ksm_after = ::account_data_of(receiver).free; diff --git a/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/mod.rs b/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/mod.rs index 98b09fac52..82556e1885 100644 --- a/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/mod.rs +++ b/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/mod.rs @@ -70,13 +70,13 @@ pub(crate) fn weth_at_asset_hubs() -> Location { ) } -pub(crate) fn create_foreign_on_ah_kusama(id: v3::Location, sufficient: bool) { +pub(crate) fn create_foreign_on_ah_kusama(id: v4::Location, sufficient: bool) { let owner = AssetHubKusama::account_id_of(ALICE); AssetHubKusama::force_create_foreign_asset(id, owner, sufficient, ASSET_MIN_BALANCE, vec![]); } pub(crate) fn create_foreign_on_ah_polkadot( - id: v3::Location, + id: v4::Location, sufficient: bool, prefund_accounts: Vec<(AccountId, u128)>, ) { @@ -85,13 +85,13 @@ pub(crate) fn create_foreign_on_ah_polkadot( AssetHubPolkadot::force_create_foreign_asset(id, owner, sufficient, min, prefund_accounts); } -pub(crate) fn foreign_balance_on_ah_kusama(id: v3::Location, who: &AccountId) -> u128 { +pub(crate) fn foreign_balance_on_ah_kusama(id: v4::Location, who: &AccountId) -> u128 { AssetHubKusama::execute_with(|| { type Assets = ::ForeignAssets; >::balance(id, who) }) } -pub(crate) fn foreign_balance_on_ah_polkadot(id: v3::Location, who: &AccountId) -> u128 { +pub(crate) fn foreign_balance_on_ah_polkadot(id: v4::Location, who: &AccountId) -> u128 { AssetHubPolkadot::execute_with(|| { type Assets = ::ForeignAssets; >::balance(id, who) @@ -99,8 +99,8 @@ pub(crate) fn foreign_balance_on_ah_polkadot(id: v3::Location, who: &AccountId) } // set up pool -pub(crate) fn set_up_pool_with_ksm_on_ah_kusama(asset: v3::Location, is_foreign: bool) { - let ksm: v3::Location = v3::Parent.into(); +pub(crate) fn set_up_pool_with_ksm_on_ah_kusama(asset: v4::Location, is_foreign: bool) { + let ksm: v4::Location = v4::Parent.into(); AssetHubKusama::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; let owner = AssetHubKusamaSender::get(); @@ -109,13 +109,13 @@ pub(crate) fn set_up_pool_with_ksm_on_ah_kusama(asset: v3::Location, is_foreign: if is_foreign { assert_ok!(::ForeignAssets::mint( signed_owner.clone(), - asset, + asset.clone(), owner.clone().into(), 3_000_000_000_000, )); } else { let asset_id = match asset.interior.last() { - Some(v3::Junction::GeneralIndex(id)) => *id as u32, + Some(v4::Junction::GeneralIndex(id)) => *id as u32, _ => unreachable!(), }; assert_ok!(::Assets::mint( @@ -127,8 +127,8 @@ pub(crate) fn set_up_pool_with_ksm_on_ah_kusama(asset: v3::Location, is_foreign: } assert_ok!(::AssetConversion::create_pool( signed_owner.clone(), - Box::new(ksm), - Box::new(asset), + Box::new(ksm.clone()), + Box::new(asset.clone()), )); assert_expected_events!( AssetHubKusama, diff --git a/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/register_bridged_assets.rs b/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/register_bridged_assets.rs index c9c690a2d8..928b486fd4 100644 --- a/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/register_bridged_assets.rs +++ b/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/register_bridged_assets.rs @@ -24,13 +24,13 @@ const XCM_FEE: u128 = 40_000_000_000; #[test] fn register_polkadot_asset_on_kah_from_pah() { // Polkadot Asset Hub asset when bridged to Kusama Asset Hub. - let bridged_asset_at_kah = v3::Location::new( + let bridged_asset_at_kah = v4::Location::new( 2, [ - v3::Junction::GlobalConsensus(v3::NetworkId::Polkadot), - v3::Junction::Parachain(AssetHubPolkadot::para_id().into()), - v3::Junction::PalletInstance(ASSETS_PALLET_ID), - v3::Junction::GeneralIndex(ASSET_ID.into()), + v4::Junction::GlobalConsensus(v4::NetworkId::Polkadot), + v4::Junction::Parachain(AssetHubPolkadot::para_id().into()), + v4::Junction::PalletInstance(ASSETS_PALLET_ID), + v4::Junction::GeneralIndex(ASSET_ID.into()), ], ); // Register above asset on Kusama AH from Polkadot AH. @@ -41,18 +41,18 @@ fn register_polkadot_asset_on_kah_from_pah() { #[test] fn register_ethereum_asset_on_kah_from_pah() { // Ethereum asset when bridged to Kusama Asset Hub. - let bridged_asset_at_kah = v3::Location::new( + let bridged_asset_at_kah = v4::Location::new( 2, [ - v3::Junction::GlobalConsensus(v3::NetworkId::Ethereum { chain_id: CHAIN_ID }), - v3::Junction::AccountKey20 { network: None, key: WETH }, + v4::Junction::GlobalConsensus(v4::NetworkId::Ethereum { chain_id: CHAIN_ID }), + v4::Junction::AccountKey20 { network: None, key: WETH }, ], ); // Register above asset on Kusama AH from Polkadot AH. register_asset_on_kah_from_pah(bridged_asset_at_kah); } -fn register_asset_on_kah_from_pah(bridged_asset_at_kah: v3::Location) { +fn register_asset_on_kah_from_pah(bridged_asset_at_kah: v4::Location) { let sa_of_pah_on_kah = AssetHubKusama::sovereign_account_of_parachain_on_other_global_consensus( Polkadot, AssetHubPolkadot::para_id(), @@ -60,7 +60,7 @@ fn register_asset_on_kah_from_pah(bridged_asset_at_kah: v3::Location) { // Encoded `create_asset` call to be executed in Kusama Asset Hub ForeignAssets pallet. let call = AssetHubKusama::create_foreign_asset_call( - bridged_asset_at_kah, + bridged_asset_at_kah.clone(), ASSET_MIN_BALANCE, sa_of_pah_on_kah.clone(), ); diff --git a/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/send_xcm.rs b/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/send_xcm.rs index 7bea665eb3..65a0dea677 100644 --- a/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/send_xcm.rs +++ b/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/send_xcm.rs @@ -29,7 +29,7 @@ fn send_xcm_from_polkadot_relay_to_kusama_asset_hub_should_fail_on_not_applicabl let xcm = VersionedXcm::from(Xcm(vec![ UnpaidExecution { weight_limit, check_origin }, ExportMessage { - network: KusamaId.into(), + network: KusamaId, destination: [Parachain(AssetHubKusama::para_id().into())].into(), xcm: remote_xcm, }, diff --git a/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/snowbridge.rs b/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/snowbridge.rs index c6374c2cfd..30f28c9951 100644 --- a/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/snowbridge.rs +++ b/integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/snowbridge.rs @@ -284,7 +284,7 @@ fn send_token_from_ethereum_to_penpal() { let weth_asset_location: Location = (Parent, Parent, EthereumNetwork::get(), AccountKey20 { network: None, key: WETH }).into(); // Converts the Weth asset location into an asset ID - let weth_asset_id: v3::Location = weth_asset_location.clone().try_into().unwrap(); + let weth_asset_id = weth_asset_location.clone(); // Fund ethereum sovereign on AssetHub AssetHubPolkadot::fund_accounts(vec![(ethereum_sovereign_account(), INITIAL_FUND)]); @@ -313,7 +313,7 @@ fn send_token_from_ethereum_to_penpal() { AssetHubPolkadot::execute_with(|| { assert_ok!(::ForeignAssets::force_create( ::RuntimeOrigin::root(), - weth_asset_id, + weth_asset_id.clone(), asset_hub_sovereign.clone().into(), true, 1000, @@ -734,7 +734,7 @@ fn asset_hub_foreign_assets_pallet_is_configured_correctly_in_bridge_hub() { ::Runtime, pallet_assets::Instance2, >::create { - id: v3::Location::default(), + id: v4::Location::default(), min_balance: ASSET_MIN_BALANCE, admin: assethub_sovereign.into(), }) @@ -853,14 +853,14 @@ fn send_token_from_ethereum_to_asset_hub_with_fee(account_id: [u8; 32], fee: u12 assert_ok!(::ForeignAssets::force_create( RuntimeOrigin::root(), - weth_asset_location.clone().try_into().unwrap(), + weth_asset_location.clone(), asset_hub_sovereign.into(), false, 1, )); assert!(::ForeignAssets::asset_exists( - weth_asset_location.clone().try_into().unwrap(), + weth_asset_location.clone(), )); }); diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index ec92b587f7..0ef1e15ccb 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -89,8 +89,8 @@ use xcm::{ }; use xcm_config::{ FellowshipLocation, ForeignAssetsConvertedConcreteId, ForeignCreatorsSovereignAccountOf, - GovernanceLocation, KsmLocation, KsmLocationV3, PoolAssetsConvertedConcreteId, - TrustBackedAssetsConvertedConcreteId, TrustBackedAssetsPalletLocationV3, + GovernanceLocation, KsmLocation, PoolAssetsConvertedConcreteId, + TrustBackedAssetsConvertedConcreteId, TrustBackedAssetsPalletLocation, }; use xcm_runtime_apis::{ dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects}, @@ -275,7 +275,7 @@ impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = impls::tx_payment::FungiblesAdapter< NativeAndAssets, - KsmLocationV3, + KsmLocation, ResolveAssetTo, >; type WeightToFee = WeightToFee; @@ -369,11 +369,11 @@ pub type LocalAndForeignAssets = fungibles::UnionOf< Assets, ForeignAssets, LocalFromLeft< - AssetIdForTrustBackedAssetsConvert, + AssetIdForTrustBackedAssetsConvert, AssetIdForTrustBackedAssets, - xcm::v3::Location, + xcm::v4::Location, >, - xcm::v3::Location, + xcm::v4::Location, AccountId, >; @@ -381,23 +381,23 @@ pub type LocalAndForeignAssets = fungibles::UnionOf< pub type NativeAndAssets = fungible::UnionOf< Balances, LocalAndForeignAssets, - TargetFromLeft, - xcm::v3::Location, + TargetFromLeft, + xcm::v4::Location, AccountId, >; pub type PoolIdToAccountId = - pallet_asset_conversion::AccountIdConverterNoSeed<(xcm::v3::Location, xcm::v3::Location)>; + pallet_asset_conversion::AccountIdConverterNoSeed<(xcm::v4::Location, xcm::v4::Location)>; impl pallet_asset_conversion::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; type HigherPrecisionBalance = sp_core::U256; - type AssetKind = xcm::v3::Location; + type AssetKind = xcm::v4::Location; type Assets = NativeAndAssets; type PoolId = (Self::AssetKind, Self::AssetKind); type PoolLocator = pallet_asset_conversion::WithFirstAsset< - KsmLocationV3, + KsmLocation, AccountId, Self::AssetKind, PoolIdToAccountId, @@ -405,7 +405,7 @@ impl pallet_asset_conversion::Config for Runtime { type PoolAssetId = u32; type PoolAssets = PoolAssets; type PoolSetupFee = PoolSetupFee; - type PoolSetupFeeAsset = KsmLocationV3; + type PoolSetupFeeAsset = KsmLocation; type PoolSetupFeeTarget = ResolveAssetTo; type LiquidityWithdrawalFee = LiquidityWithdrawalFee; type LPFee = ConstU32<3>; @@ -415,10 +415,10 @@ impl pallet_asset_conversion::Config for Runtime { type WeightInfo = weights::pallet_asset_conversion::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = assets_common::benchmarks::AssetPairFactory< - KsmLocationV3, + KsmLocation, parachain_info::Pallet, xcm_config::TrustBackedAssetsPalletIndex, - xcm::v3::Location, + xcm::v4::Location, >; } @@ -441,17 +441,17 @@ pub type ForeignAssetsInstance = pallet_assets::Instance2; impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; - type AssetId = xcm::v3::Location; - type AssetIdParameter = xcm::v3::Location; + type AssetId = xcm::v4::Location; + type AssetIdParameter = xcm::v4::Location; type Currency = Balances; type CreateOrigin = ForeignCreators< ( - FromSiblingParachain, xcm::v3::Location>, + FromSiblingParachain, xcm::v4::Location>, xcm_config::bridging::to_polkadot::PolkadotOrEthereumAssetFromAssetHubPolkadot, ), ForeignCreatorsSovereignAccountOf, AccountId, - xcm::v3::Location, + xcm::v4::Location, >; type ForceOrigin = AssetsForceOrigin; type AssetDeposit = ForeignAssetsAssetDeposit; @@ -841,7 +841,7 @@ impl pallet_asset_conversion_tx_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Fungibles = LocalAndForeignAssets; type OnChargeAssetTransaction = - impls::tx_payment::SwapCreditAdapter; + impls::tx_payment::SwapCreditAdapter; } parameter_types! { @@ -1208,18 +1208,18 @@ impl_runtime_apis! { impl pallet_asset_conversion::AssetConversionApi< Block, Balance, - xcm::v3::Location, + xcm::v4::Location, > for Runtime { - fn quote_price_exact_tokens_for_tokens(asset1: xcm::v3::Location, asset2: xcm::v3::Location, amount: Balance, include_fee: bool) -> Option { + fn quote_price_exact_tokens_for_tokens(asset1: xcm::v4::Location, asset2: xcm::v4::Location, amount: Balance, include_fee: bool) -> Option { AssetConversion::quote_price_exact_tokens_for_tokens(asset1, asset2, amount, include_fee) } - fn quote_price_tokens_for_exact_tokens(asset1: xcm::v3::Location, asset2: xcm::v3::Location, amount: Balance, include_fee: bool) -> Option { + fn quote_price_tokens_for_exact_tokens(asset1: xcm::v4::Location, asset2: xcm::v4::Location, amount: Balance, include_fee: bool) -> Option { AssetConversion::quote_price_tokens_for_exact_tokens(asset1, asset2, amount, include_fee) } - fn get_reserves(asset1: xcm::v3::Location, asset2: xcm::v3::Location) -> Option<(Balance, Balance)> { + fn get_reserves(asset1: xcm::v4::Location, asset2: xcm::v4::Location) -> Option<(Balance, Balance)> { AssetConversion::get_reserves(asset1, asset2).ok() } } 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 5a7d089e1e..0ab78671eb 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 @@ -58,7 +58,6 @@ use xcm_executor::{traits::ConvertLocation, XcmExecutor}; parameter_types! { pub const KsmLocation: Location = Location::parent(); - pub const KsmLocationV3: xcm::v3::Location = xcm::v3::Location::parent(); pub const RelayNetwork: Option = Some(NetworkId::Kusama); pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorLocation = @@ -67,7 +66,6 @@ parameter_types! { pub TrustBackedAssetsPalletIndex: u8 = ::index() as u8; pub TrustBackedAssetsPalletLocation: Location = PalletInstance(TrustBackedAssetsPalletIndex::get()).into(); - pub TrustBackedAssetsPalletLocationV3: xcm::v3::Location = xcm::v3::Junction::PalletInstance(TrustBackedAssetsPalletIndex::get()).into(); pub ForeignAssetsPalletLocation: Location = PalletInstance(::index() as u8).into(); @@ -155,7 +153,7 @@ pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConverte StartsWithExplicitGlobalConsensus, ), Balance, - xcm::v3::Location, + xcm::v4::Location, >; /// Means for transacting foreign assets from different global consensus. @@ -331,7 +329,7 @@ impl xcm_executor::Config for XcmConfig { // This trader allows to pay with any assets exchangeable to KSM with // [`AssetConversion`]. cumulus_primitives_utility::SwapFirstAssetTrader< - KsmLocationV3, + KsmLocation, AssetConversion, WeightToFee, NativeAndAssets, @@ -339,7 +337,7 @@ impl xcm_executor::Config for XcmConfig { TrustBackedAssetsAsLocation< TrustBackedAssetsPalletLocation, Balance, - xcm::v3::Location, + xcm::v4::Location, >, ForeignAssetsConvertedConcreteId, ), @@ -467,9 +465,9 @@ pub type ForeignCreatorsSovereignAccountOf = ( /// Simple conversion of `u32` into an `AssetId` for use in benchmarking. pub struct XcmBenchmarkHelper; #[cfg(feature = "runtime-benchmarks")] -impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { - fn create_asset_id_parameter(id: u32) -> xcm::v3::Location { - xcm::v3::Location::new(1, xcm::v3::Junction::Parachain(id)) +impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { + fn create_asset_id_parameter(id: u32) -> xcm::v4::Location { + xcm::v4::Location::new(1, xcm::v4::Junction::Parachain(id)) } } 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 9e3e2ded06..4ae5e17a73 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs @@ -76,7 +76,7 @@ fn slot_durations() -> SlotDurations { fn setup_pool_for_paying_fees_with_foreign_assets( (foreign_asset_owner, foreign_asset_id_location, foreign_asset_id_minimum_balance): ( AccountId, - xcm::v3::Location, + xcm::v4::Location, Balance, ), ) { @@ -84,7 +84,7 @@ fn setup_pool_for_paying_fees_with_foreign_assets( // setup a pool to pay fees with `foreign_asset_id_location` tokens let pool_owner: AccountId = [14u8; 32].into(); - let native_asset = xcm::v3::Location::parent(); + let native_asset = xcm::v4::Location::parent(); let pool_liquidity: Balance = existential_deposit.max(foreign_asset_id_minimum_balance).mul(100_000); @@ -96,15 +96,15 @@ fn setup_pool_for_paying_fees_with_foreign_assets( assert_ok!(ForeignAssets::mint( RuntimeOrigin::signed(foreign_asset_owner), - foreign_asset_id_location, + foreign_asset_id_location.clone(), pool_owner.clone().into(), (foreign_asset_id_minimum_balance + pool_liquidity).mul(2), )); assert_ok!(AssetConversion::create_pool( RuntimeOrigin::signed(pool_owner.clone()), - Box::new(native_asset), - Box::new(foreign_asset_id_location) + Box::new(native_asset.clone()), + Box::new(foreign_asset_id_location.clone()) )); assert_ok!(AssetConversion::add_liquidity( @@ -150,15 +150,15 @@ fn test_assets_balances_api_works() { .build() .execute_with(|| { let local_asset_id = 1; - let foreign_asset_id_location = xcm::v3::Location::new( + let foreign_asset_id_location = xcm::v4::Location::new( 1, - [xcm::v3::Junction::Parachain(1234), xcm::v3::Junction::GeneralIndex(12345)], + [xcm::v4::Junction::Parachain(1234), xcm::v4::Junction::GeneralIndex(12345)], ); // check before assert_eq!(Assets::balance(local_asset_id, AccountId::from(ALICE)), 0); assert_eq!( - ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)), + ForeignAssets::balance(foreign_asset_id_location.clone(), AccountId::from(ALICE)), 0 ); assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 0); @@ -195,7 +195,7 @@ fn test_assets_balances_api_works() { let foreign_asset_minimum_asset_balance = 3333333_u128; assert_ok!(ForeignAssets::force_create( RuntimeHelper::root_origin(), - foreign_asset_id_location, + foreign_asset_id_location.clone(), AccountId::from(SOME_ASSET_ADMIN).into(), false, foreign_asset_minimum_asset_balance @@ -204,7 +204,7 @@ fn test_assets_balances_api_works() { // We first mint enough asset for the account to exist for assets assert_ok!(ForeignAssets::mint( RuntimeHelper::origin_of(AccountId::from(SOME_ASSET_ADMIN)), - foreign_asset_id_location, + foreign_asset_id_location.clone(), AccountId::from(ALICE).into(), 6 * foreign_asset_minimum_asset_balance )); @@ -215,7 +215,7 @@ fn test_assets_balances_api_works() { minimum_asset_balance ); assert_eq!( - ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)), + ForeignAssets::balance(foreign_asset_id_location.clone(), AccountId::from(ALICE)), 6 * minimum_asset_balance ); assert_eq!(Balances::free_balance(AccountId::from(ALICE)), some_currency); @@ -267,7 +267,7 @@ asset_test_utils::include_teleports_for_native_asset_works!( 1000 ); -asset_test_utils::include_teleports_for_foreign_assets_works!( +include_teleports_for_foreign_assets_works!( Runtime, AllPalletsWithoutSystem, XcmConfig, @@ -331,13 +331,13 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_ Runtime, XcmConfig, ForeignAssetsInstance, - xcm::v3::Location, + xcm::v4::Location, JustTry, collator_session_keys(), ExistentialDeposit::get(), - xcm::v3::Location::new( + xcm::v4::Location::new( 1, - [xcm::v3::Junction::Parachain(1313), xcm::v3::Junction::GeneralIndex(12345)] + [xcm::v4::Junction::Parachain(1313), xcm::v4::Junction::GeneralIndex(12345)] ), Box::new(|| { assert!(Assets::asset_ids().collect::>().is_empty()); @@ -353,8 +353,8 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p WeightToFee, ForeignCreatorsSovereignAccountOf, ForeignAssetsInstance, - xcm::v3::Location, - WithLatestLocationConverter, + xcm::v4::Location, + WithLatestLocationConverter, collator_session_keys(), ExistentialDeposit::get(), AssetDeposit::get(), @@ -431,17 +431,17 @@ fn receive_reserve_asset_deposited_dot_from_asset_hub_polkadot_fees_paid_by_pool let block_author_account = AccountId::from(BLOCK_AUTHOR_ACCOUNT); let staking_pot = StakingPot::get(); - let foreign_asset_id_location = xcm::v3::Location::new( + let foreign_asset_id_location = xcm::v4::Location::new( 2, - [xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::Polkadot)], + [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, foreign_asset_id_minimum_balance); + (foreign_asset_owner, foreign_asset_id_location.clone(), foreign_asset_id_minimum_balance); - asset_test_utils::test_cases_over_bridge::receive_reserve_asset_deposited_from_different_consensus_works::< + remove_when_updated_to_stable2409::receive_reserve_asset_deposited_from_different_consensus_works::< Runtime, AllPalletsWithoutSystem, XcmConfig, @@ -473,7 +473,7 @@ fn receive_reserve_asset_deposited_dot_from_asset_hub_polkadot_fees_paid_by_pool // check now foreign asset for staking pot assert_eq!( ForeignAssets::balance( - foreign_asset_id_location, + foreign_asset_id_location.clone(), &staking_pot ), 0 @@ -487,7 +487,7 @@ fn receive_reserve_asset_deposited_dot_from_asset_hub_polkadot_fees_paid_by_pool // staking pot receives no foreign assets assert_eq!( ForeignAssets::balance( - foreign_asset_id_location, + foreign_asset_id_location.clone(), &staking_pot ), 0 @@ -503,17 +503,17 @@ fn receive_reserve_asset_deposited_dot_from_asset_hub_polkadot_fees_paid_by_suff let block_author_account = AccountId::from(BLOCK_AUTHOR_ACCOUNT); let staking_pot = >::account_id(); - let foreign_asset_id_location = xcm::v3::Location::new( + let foreign_asset_id_location = xcm::v4::Location::new( 2, - [xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::Polkadot)], + [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, foreign_asset_id_minimum_balance); + (foreign_asset_owner, foreign_asset_id_location.clone(), foreign_asset_id_minimum_balance); - asset_test_utils::test_cases_over_bridge::receive_reserve_asset_deposited_from_different_consensus_works::< + remove_when_updated_to_stable2409::receive_reserve_asset_deposited_from_different_consensus_works::< Runtime, AllPalletsWithoutSystem, XcmConfig, @@ -536,7 +536,7 @@ fn receive_reserve_asset_deposited_dot_from_asset_hub_polkadot_fees_paid_by_suff // check block author before assert_eq!( ForeignAssets::balance( - foreign_asset_id_location, + foreign_asset_id_location.clone(), &block_author_account ), 0 @@ -546,7 +546,7 @@ fn receive_reserve_asset_deposited_dot_from_asset_hub_polkadot_fees_paid_by_suff // `TakeFirstAssetTrader` puts fees to the block author assert!( ForeignAssets::balance( - foreign_asset_id_location, + foreign_asset_id_location.clone(), &block_author_account ) > 0 ); @@ -706,3 +706,600 @@ fn treasury_pallet_account_not_none() { LocationToAccountId::convert_location(&RelayTreasuryLocation::get()).unwrap() ) } + +#[allow(clippy::too_many_arguments)] +pub mod remove_when_updated_to_stable2409 { + use crate::{AccountId, Balance, TestBridgingConfig}; + + use asset_test_utils::*; + use codec::Encode; + use core::fmt::Debug; + use frame_support::{ + assert_ok, + traits::{ + fungible::Mutate, Currency, OnFinalize, OnInitialize, OriginTrait, ProcessMessageError, + }, + }; + use frame_system::pallet_prelude::BlockNumberFor; + use sp_core::Get; + use sp_runtime::traits::StaticLookup; + use xcm::prelude::*; + use xcm_builder::{CreateMatcher, MatchXcm}; + use xcm_executor::{traits::ConvertLocation, XcmExecutor}; + + #[macro_export] + macro_rules! include_teleports_for_foreign_assets_works( + ( + $runtime:path, + $all_pallets_without_system:path, + $xcm_config:path, + $checking_account:path, + $weight_to_fee:path, + $hrmp_channel_opener:path, + $sovereign_account_of:path, + $assets_pallet_instance:path, + $collator_session_key:expr, + $slot_durations:expr, + $existential_deposit:expr, + $unwrap_pallet_xcm_event:expr, + $unwrap_xcmp_queue_event:expr + ) => { + #[test] + fn teleports_for_foreign_assets_works() { + const BOB: [u8; 32] = [2u8; 32]; + let target_account = parachains_common::AccountId::from(BOB); + const SOME_ASSET_OWNER: [u8; 32] = [5u8; 32]; + let asset_owner = parachains_common::AccountId::from(SOME_ASSET_OWNER); + + $crate::remove_when_updated_to_stable2409::teleports_for_foreign_assets_works::< + $runtime, + $all_pallets_without_system, + $xcm_config, + $checking_account, + $weight_to_fee, + $hrmp_channel_opener, + $sovereign_account_of, + $assets_pallet_instance + >( + $collator_session_key, + $slot_durations, + target_account, + $existential_deposit, + asset_owner, + $unwrap_pallet_xcm_event, + $unwrap_xcmp_queue_event + ) + } + } + ); + + /// Test-case makes sure that `Runtime` can receive teleported assets from sibling parachain, + /// and can teleport it back + pub fn teleports_for_foreign_assets_works< + Runtime, + AllPalletsWithoutSystem, + XcmConfig, + CheckingAccount, + WeightToFee, + HrmpChannelOpener, + SovereignAccountOf, + ForeignAssetsPalletInstance, + >( + collator_session_keys: CollatorSessionKeys, + slot_durations: SlotDurations, + target_account: AccountIdOf, + existential_deposit: BalanceOf, + asset_owner: AccountIdOf, + unwrap_pallet_xcm_event: Box) -> Option>>, + unwrap_xcmp_queue_event: Box< + dyn Fn(Vec) -> Option>, + >, + ) where + Runtime: frame_system::Config + + pallet_balances::Config + + pallet_session::Config + + pallet_xcm::Config + + parachain_info::Config + + pallet_collator_selection::Config + + cumulus_pallet_parachain_system::Config + + cumulus_pallet_xcmp_queue::Config + + pallet_assets::Config + + pallet_timestamp::Config, + AllPalletsWithoutSystem: + OnInitialize> + OnFinalize>, + AccountIdOf: Into<[u8; 32]>, + ValidatorIdOf: From>, + BalanceOf: From, + XcmConfig: xcm_executor::Config, + CheckingAccount: Get>, + HrmpChannelOpener: frame_support::inherent::ProvideInherent< + Call = cumulus_pallet_parachain_system::Call, + >, + WeightToFee: frame_support::weights::WeightToFee, + ::Balance: From + Into, + SovereignAccountOf: ConvertLocation>, + >::AssetId: + From + Into, + >::AssetIdParameter: + From + Into, + >::Balance: + From + Into, + ::AccountId: + Into<<::RuntimeOrigin as OriginTrait>::AccountId>, + <::Lookup as StaticLookup>::Source: + From<::AccountId>, + ::AccountId: From, + ForeignAssetsPalletInstance: 'static, + { + // foreign parachain with the same consensus currency as asset + let foreign_para_id = 2222; + let foreign_asset_id_location = xcm::v4::Location { + parents: 1, + interior: [ + xcm::v4::Junction::Parachain(foreign_para_id), + xcm::v4::Junction::GeneralIndex(1234567), + ] + .into(), + }; + + // foreign creator, which can be sibling parachain to match ForeignCreators + let foreign_creator = + Location { parents: 1, interior: [Parachain(foreign_para_id)].into() }; + let foreign_creator_as_account_id = + SovereignAccountOf::convert_location(&foreign_creator).expect(""); + + // we want to buy execution with local relay chain currency + let buy_execution_fee_amount = + WeightToFee::weight_to_fee(&Weight::from_parts(90_000_000_000, 0)); + let buy_execution_fee = + Asset { id: AssetId(Location::parent()), fun: Fungible(buy_execution_fee_amount) }; + + let teleported_foreign_asset_amount = 10_000_000_000_000; + let runtime_para_id = 1000; + ExtBuilder::::default() + .with_collators(collator_session_keys.collators()) + .with_session_keys(collator_session_keys.session_keys()) + .with_balances(vec![ + ( + foreign_creator_as_account_id, + existential_deposit + (buy_execution_fee_amount * 2).into(), + ), + (target_account.clone(), existential_deposit), + (CheckingAccount::get(), existential_deposit), + ]) + .with_safe_xcm_version(XCM_VERSION) + .with_para_id(runtime_para_id.into()) + .with_tracing() + .build() + .execute_with(|| { + let mut alice = [0u8; 32]; + alice[0] = 1; + + let included_head = RuntimeHelper::::run_to_block( + 2, + AccountId::from(alice).into(), + ); + // checks target_account before + assert_eq!( + >::free_balance(&target_account), + existential_deposit + ); + // check `CheckingAccount` before + assert_eq!( + >::free_balance(CheckingAccount::get()), + existential_deposit + ); + assert_eq!( + >::balance( + foreign_asset_id_location.clone().into(), + &target_account + ), + 0.into() + ); + assert_eq!( + >::balance( + foreign_asset_id_location.clone().into(), + CheckingAccount::get() + ), + 0.into() + ); + // check totals before + assert_total::< + pallet_assets::Pallet, + AccountIdOf, + >(foreign_asset_id_location.clone(), 0, 0); + + // create foreign asset (0 total issuance) + let asset_minimum_asset_balance = 3333333_u128; + assert_ok!( + >::force_create( + RuntimeHelper::::root_origin(), + foreign_asset_id_location.clone().into(), + asset_owner.into(), + false, + asset_minimum_asset_balance.into() + ) + ); + assert_total::< + pallet_assets::Pallet, + AccountIdOf, + >(foreign_asset_id_location.clone(), 0, 0); + assert!(teleported_foreign_asset_amount > asset_minimum_asset_balance); + + // 1. process received teleported assets from sibling parachain (foreign_para_id) + let xcm = Xcm(vec![ + // BuyExecution with relaychain native token + WithdrawAsset(buy_execution_fee.clone().into()), + BuyExecution { + fees: Asset { + id: AssetId(Location::parent()), + fun: Fungible(buy_execution_fee_amount), + }, + weight_limit: Limited(Weight::from_parts(403531000, 65536)), + }, + // Process teleported asset + ReceiveTeleportedAsset(Assets::from(vec![Asset { + id: AssetId(foreign_asset_id_location.clone()), + fun: Fungible(teleported_foreign_asset_amount), + }])), + DepositAsset { + assets: Wild(AllOf { + id: AssetId(foreign_asset_id_location.clone()), + fun: WildFungibility::Fungible, + }), + beneficiary: Location { + parents: 0, + interior: [AccountId32 { + network: None, + id: target_account.clone().into(), + }] + .into(), + }, + }, + ExpectTransactStatus(MaybeErrorCode::Success), + ]); + let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256); + + let outcome = XcmExecutor::::prepare_and_execute( + foreign_creator, + xcm, + &mut hash, + RuntimeHelper::::xcm_max_weight(XcmReceivedFrom::Sibling), + Weight::zero(), + ); + assert_ok!(outcome.ensure_complete()); + + // checks target_account after + assert_eq!( + >::free_balance(&target_account), + existential_deposit + ); + assert_eq!( + >::balance( + foreign_asset_id_location.clone().into(), + &target_account + ), + teleported_foreign_asset_amount.into() + ); + // checks `CheckingAccount` after + assert_eq!( + >::free_balance(CheckingAccount::get()), + existential_deposit + ); + assert_eq!( + >::balance( + foreign_asset_id_location.clone().into(), + CheckingAccount::get() + ), + 0.into() + ); + // check total after (twice: target_account + CheckingAccount) + assert_total::< + pallet_assets::Pallet, + AccountIdOf, + >( + foreign_asset_id_location.clone(), + teleported_foreign_asset_amount, + teleported_foreign_asset_amount, + ); + + // 2. try to teleport asset back to source parachain (foreign_para_id) + { + let dest = Location::new(1, [Parachain(foreign_para_id)]); + let mut dest_beneficiary = Location::new(1, [Parachain(foreign_para_id)]) + .appended_with(AccountId32 { + network: None, + id: sp_runtime::AccountId32::new([3; 32]).into(), + }) + .unwrap(); + dest_beneficiary.reanchor(&dest, &XcmConfig::UniversalLocation::get()).unwrap(); + + let target_account_balance_before_teleport = + >::balance( + foreign_asset_id_location.clone().into(), + &target_account, + ); + let asset_to_teleport_away = asset_minimum_asset_balance * 3; + assert!( + asset_to_teleport_away < + (target_account_balance_before_teleport - + asset_minimum_asset_balance.into()) + .into() + ); + + // Make sure the target account has enough native asset to pay for delivery fees + let delivery_fees = + xcm_helpers::teleport_assets_delivery_fees::( + (foreign_asset_id_location.clone(), asset_to_teleport_away).into(), + 0, + Unlimited, + dest_beneficiary.clone(), + dest.clone(), + ); + >::mint_into( + &target_account, + delivery_fees.into(), + ) + .unwrap(); + + assert_ok!( + RuntimeHelper::::do_teleport_assets::( + RuntimeHelper::::origin_of(target_account.clone()), + dest, + dest_beneficiary, + (foreign_asset_id_location.clone(), asset_to_teleport_away), + Some((runtime_para_id, foreign_para_id)), + included_head, + &alice, + &slot_durations, + ) + ); + + // check balances + assert_eq!( + >::balance( + foreign_asset_id_location.clone().into(), + &target_account + ), + (target_account_balance_before_teleport - asset_to_teleport_away.into()) + ); + assert_eq!( + >::balance( + foreign_asset_id_location.clone().into(), + CheckingAccount::get() + ), + 0.into() + ); + // check total after (twice: target_account + CheckingAccount) + assert_total::< + pallet_assets::Pallet, + AccountIdOf, + >( + foreign_asset_id_location.clone(), + teleported_foreign_asset_amount - asset_to_teleport_away, + teleported_foreign_asset_amount - asset_to_teleport_away, + ); + + // check events + RuntimeHelper::::assert_pallet_xcm_event_outcome( + &unwrap_pallet_xcm_event, + |outcome| { + assert_ok!(outcome.ensure_complete()); + }, + ); + assert!(RuntimeHelper::::xcmp_queue_message_sent( + unwrap_xcmp_queue_event + ) + .is_some()); + } + }) + } + + /// Helper function to verify `xcm` contains all relevant instructions expected on destination + /// chain as part of a reserve-asset-transfer. + pub(crate) fn assert_matches_reserve_asset_deposited_instructions( + xcm: &mut Xcm, + expected_reserve_assets_deposited: &Assets, + expected_beneficiary: &Location, + ) { + let _ = xcm + .0 + .matcher() + .skip_inst_while(|inst| !matches!(inst, ReserveAssetDeposited(..))) + .expect("no instruction ReserveAssetDeposited?") + .match_next_inst(|instr| match instr { + ReserveAssetDeposited(reserve_assets) => { + assert_eq!(reserve_assets.clone(), expected_reserve_assets_deposited.clone()); + Ok(()) + }, + _ => Err(ProcessMessageError::BadFormat), + }) + .expect("expected instruction ReserveAssetDeposited") + .match_next_inst(|instr| match instr { + ClearOrigin => Ok(()), + _ => Err(ProcessMessageError::BadFormat), + }) + .expect("expected instruction ClearOrigin") + .match_next_inst(|instr| match instr { + BuyExecution { .. } => Ok(()), + _ => Err(ProcessMessageError::BadFormat), + }) + .expect("expected instruction BuyExecution") + .match_next_inst(|instr| match instr { + DepositAsset { assets: _, beneficiary } if beneficiary == expected_beneficiary => + Ok(()), + _ => Err(ProcessMessageError::BadFormat), + }) + .expect("expected instruction DepositAsset"); + } + + pub fn receive_reserve_asset_deposited_from_different_consensus_works< + Runtime, + AllPalletsWithoutSystem, + XcmConfig, + ForeignAssetsPalletInstance, + >( + collator_session_keys: CollatorSessionKeys, + existential_deposit: BalanceOf, + target_account: AccountIdOf, + block_author_account: AccountIdOf, + (foreign_asset_owner, foreign_asset_id_location, foreign_asset_id_minimum_balance): ( + AccountIdOf, + xcm::v4::Location, + u128, + ), + foreign_asset_id_amount_to_transfer: u128, + prepare_configuration: impl FnOnce() -> TestBridgingConfig, + (bridge_instance, universal_origin, descend_origin): (Junctions, Junction, Junctions), /* bridge adds origin manipulation on the way */ + additional_checks_before: impl FnOnce(), + additional_checks_after: impl FnOnce(), + ) where + Runtime: frame_system::Config + + pallet_balances::Config + + pallet_session::Config + + pallet_xcm::Config + + parachain_info::Config + + pallet_collator_selection::Config + + cumulus_pallet_parachain_system::Config + + cumulus_pallet_xcmp_queue::Config + + pallet_assets::Config + + pallet_timestamp::Config, + AllPalletsWithoutSystem: + OnInitialize> + OnFinalize>, + AccountIdOf: Into<[u8; 32]> + From<[u8; 32]>, + ValidatorIdOf: From>, + BalanceOf: From + Into, + XcmConfig: xcm_executor::Config, + >::AssetId: + From + Into, + >::AssetIdParameter: + From + Into, + >::Balance: + From + Into + From, + ::AccountId: Into<<::RuntimeOrigin as OriginTrait>::AccountId> + + Into, + <::Lookup as StaticLookup>::Source: + From<::AccountId>, + ForeignAssetsPalletInstance: 'static, + { + ExtBuilder::::default() + .with_collators(collator_session_keys.collators()) + .with_session_keys(collator_session_keys.session_keys()) + .with_tracing() + .build() + .execute_with(|| { + // Set account as block author, who will receive fees + RuntimeHelper::::run_to_block( + 2, + block_author_account.clone(), + ); + + // drip 'ED' user target account + let _ = >::deposit_creating( + &target_account, + existential_deposit, + ); + + // create foreign asset for wrapped/derived representation + assert_ok!( + >::force_create( + RuntimeHelper::::root_origin(), + foreign_asset_id_location.clone().into(), + foreign_asset_owner.into(), + true, // is_sufficient=true + foreign_asset_id_minimum_balance.into() + ) + ); + + // prepare bridge config + let TestBridgingConfig { local_bridge_hub_location, .. } = prepare_configuration(); + + // Balances before + assert_eq!( + >::free_balance(&target_account), + existential_deposit.clone() + ); + + // ForeignAssets balances before + assert_eq!( + >::balance( + foreign_asset_id_location.clone().into(), + &target_account + ), + 0.into() + ); + + // additional check before + additional_checks_before(); + + let expected_assets = Assets::from(vec![Asset { + id: AssetId(foreign_asset_id_location.clone()), + fun: Fungible(foreign_asset_id_amount_to_transfer), + }]); + let expected_beneficiary = Location::new( + 0, + [AccountId32 { network: None, id: target_account.clone().into() }], + ); + + // Call received XCM execution + let xcm = Xcm(vec![ + DescendOrigin(bridge_instance), + UniversalOrigin(universal_origin), + DescendOrigin(descend_origin), + ReserveAssetDeposited(expected_assets.clone()), + ClearOrigin, + BuyExecution { + fees: Asset { + id: AssetId(foreign_asset_id_location.clone()), + fun: Fungible(foreign_asset_id_amount_to_transfer), + }, + weight_limit: Unlimited, + }, + DepositAsset { + assets: Wild(AllCounted(1)), + beneficiary: expected_beneficiary.clone(), + }, + SetTopic([ + 220, 188, 144, 32, 213, 83, 111, 175, 44, 210, 111, 19, 90, 165, 191, 112, + 140, 247, 192, 124, 42, 17, 153, 141, 114, 34, 189, 20, 83, 69, 237, 173, + ]), + ]); + assert_matches_reserve_asset_deposited_instructions( + &mut xcm.clone(), + &expected_assets, + &expected_beneficiary, + ); + + let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256); + + // execute xcm as XcmpQueue would do + let outcome = XcmExecutor::::prepare_and_execute( + local_bridge_hub_location, + xcm, + &mut hash, + RuntimeHelper::::xcm_max_weight( + XcmReceivedFrom::Sibling, + ), + Weight::zero(), + ); + assert_ok!(outcome.ensure_complete()); + + // Balances after + assert_eq!( + >::free_balance(&target_account), + existential_deposit.clone() + ); + + // ForeignAssets balances after + assert!( + >::balance( + foreign_asset_id_location.into(), + &target_account + ) > 0.into() + ); + + // additional check after + additional_checks_after(); + }) + } +} 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 dc79c0c4e8..762f3cc93d 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 @@ -17,10 +17,11 @@ use asset_hub_kusama_runtime::{ xcm_config::{ - KsmLocation, KsmLocationV3, StakingPot, TrustBackedAssetsPalletLocationV3, XcmConfig, + AssetFeeAsExistentialDepositMultiplierFeeCharger, KsmLocation, StakingPot, + TrustBackedAssetsPalletLocation, XcmConfig, }, - AllPalletsWithoutSystem, AssetConversion, Assets, Balances, ForeignAssets, Runtime, - SessionKeys, + AllPalletsWithoutSystem, AssetConversion, Assets, Balances, ExistentialDeposit, ForeignAssets, + Runtime, SessionKeys, }; use asset_test_utils::ExtBuilder; use assets_common::AssetIdForTrustBackedAssetsConvert; @@ -33,12 +34,6 @@ use frame_support::{ weights::WeightToFee as WeightToFeeT, }; -use asset_hub_kusama_runtime::{ - xcm_config::{ - AssetFeeAsExistentialDepositMultiplierFeeCharger, TrustBackedAssetsPalletLocation, - }, - ExistentialDeposit, -}; use cumulus_primitives_utility::ChargeWeightInFungibles; use frame_support::assert_noop; @@ -466,10 +461,10 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { let bob: AccountId = SOME_ASSET_ADMIN.into(); let staking_pot = StakingPot::get(); let asset_1: u32 = 1; - let native_location = KsmLocationV3::get(); + let native_location = KsmLocation::get(); let asset_1_location = AssetIdForTrustBackedAssetsConvert::< - TrustBackedAssetsPalletLocationV3, - xcm::v3::Location, + TrustBackedAssetsPalletLocation, + xcm::v4::Location, >::convert_back(&asset_1) .unwrap(); // bob's initial balance for native and `asset1` assets. @@ -486,14 +481,14 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { assert_ok!(AssetConversion::create_pool( RuntimeHelper::origin_of(bob.clone()), - Box::new(native_location), - Box::new(asset_1_location) + Box::new(native_location.clone()), + Box::new(asset_1_location.clone()) )); assert_ok!(AssetConversion::add_liquidity( RuntimeHelper::origin_of(bob.clone()), - Box::new(native_location), - Box::new(asset_1_location), + Box::new(native_location.clone()), + Box::new(asset_1_location.clone()), pool_liquidity, pool_liquidity, 1, @@ -505,8 +500,6 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { let asset_total_issuance = Assets::total_issuance(asset_1); let native_total_issuance = Balances::total_issuance(); - let asset_1_location_latest: Location = asset_1_location.try_into().unwrap(); - // prepare input to buy weight. let weight = Weight::from_parts(4_000_000_000, 0); let fee = WeightToFee::weight_to_fee(&weight); @@ -514,7 +507,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap(); let extra_amount = 100; let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - let payment: Asset = (asset_1_location_latest.clone(), asset_fee + extra_amount).into(); + let payment: Asset = (asset_1_location.clone(), asset_fee + extra_amount).into(); // init trader and buy weight. let mut trader = ::Trader::new(); @@ -522,10 +515,8 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok"); // assert. - let unused_amount = unused_asset - .fungible - .get(&asset_1_location_latest.clone().into()) - .map_or(0, |a| *a); + let unused_amount = + unused_asset.fungible.get(&asset_1_location.clone().into()).map_or(0, |a| *a); assert_eq!(unused_amount, extra_amount); assert_eq!(Assets::total_issuance(asset_1), asset_total_issuance + asset_fee); @@ -533,13 +524,13 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { let refund_weight = Weight::from_parts(1_000_000_000, 0); let refund = WeightToFee::weight_to_fee(&refund_weight); let (reserve1, reserve2) = - AssetConversion::get_reserves(native_location, asset_1_location).unwrap(); + AssetConversion::get_reserves(native_location, asset_1_location.clone()).unwrap(); let asset_refund = AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap(); // refund. let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap(); - assert_eq!(actual_refund, (asset_1_location_latest, asset_refund).into()); + assert_eq!(actual_refund, (asset_1_location, asset_refund).into()); // assert. assert_eq!(Balances::balance(&staking_pot), initial_balance); @@ -568,12 +559,12 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { .execute_with(|| { let bob: AccountId = SOME_ASSET_ADMIN.into(); let staking_pot = StakingPot::get(); - let native_location = KsmLocationV3::get(); - let foreign_location = xcm::v3::Location { + let native_location = KsmLocation::get(); + let foreign_location = xcm::v4::Location { parents: 1, interior: ( - xcm::v3::Junction::Parachain(1234), - xcm::v3::Junction::GeneralIndex(12345), + xcm::v4::Junction::Parachain(1234), + xcm::v4::Junction::GeneralIndex(12345), ) .into(), }; @@ -584,26 +575,26 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { // init asset, balances and pool. assert_ok!(>::create( - foreign_location, + foreign_location.clone(), bob.clone(), true, 10 )); - assert_ok!(ForeignAssets::mint_into(foreign_location, &bob, initial_balance)); + assert_ok!(ForeignAssets::mint_into(foreign_location.clone(), &bob, initial_balance)); assert_ok!(Balances::mint_into(&bob, initial_balance)); assert_ok!(Balances::mint_into(&staking_pot, initial_balance)); assert_ok!(AssetConversion::create_pool( RuntimeHelper::origin_of(bob.clone()), - Box::new(native_location), - Box::new(foreign_location) + Box::new(native_location.clone()), + Box::new(foreign_location.clone()) )); assert_ok!(AssetConversion::add_liquidity( RuntimeHelper::origin_of(bob.clone()), - Box::new(native_location), - Box::new(foreign_location), + Box::new(native_location.clone()), + Box::new(foreign_location.clone()), pool_liquidity, pool_liquidity, 1, @@ -612,11 +603,9 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { )); // keep initial total issuance to assert later. - let asset_total_issuance = ForeignAssets::total_issuance(foreign_location); + let asset_total_issuance = ForeignAssets::total_issuance(foreign_location.clone()); let native_total_issuance = Balances::total_issuance(); - let foreign_location_latest: Location = foreign_location.try_into().unwrap(); - // prepare input to buy weight. let weight = Weight::from_parts(4_000_000_000, 0); let fee = WeightToFee::weight_to_fee(&weight); @@ -624,7 +613,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap(); let extra_amount = 100; let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - let payment: Asset = (foreign_location_latest.clone(), asset_fee + extra_amount).into(); + let payment: Asset = (foreign_location.clone(), asset_fee + extra_amount).into(); // init trader and buy weight. let mut trader = ::Trader::new(); @@ -632,13 +621,11 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok"); // assert. - let unused_amount = unused_asset - .fungible - .get(&foreign_location_latest.clone().into()) - .map_or(0, |a| *a); + let unused_amount = + unused_asset.fungible.get(&foreign_location.clone().into()).map_or(0, |a| *a); assert_eq!(unused_amount, extra_amount); assert_eq!( - ForeignAssets::total_issuance(foreign_location), + ForeignAssets::total_issuance(foreign_location.clone()), asset_total_issuance + asset_fee ); @@ -646,13 +633,13 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { let refund_weight = Weight::from_parts(1_000_000_000, 0); let refund = WeightToFee::weight_to_fee(&refund_weight); let (reserve1, reserve2) = - AssetConversion::get_reserves(native_location, foreign_location).unwrap(); + AssetConversion::get_reserves(native_location, foreign_location.clone()).unwrap(); let asset_refund = AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap(); // refund. let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap(); - assert_eq!(actual_refund, (foreign_location_latest, asset_refund).into()); + assert_eq!(actual_refund, (foreign_location.clone(), asset_refund).into()); // assert. assert_eq!(Balances::balance(&staking_pot), initial_balance); diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 2a8764ee48..6c42ceac92 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -81,7 +81,7 @@ use sp_runtime::{ transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, Perbill, Permill, }; -use xcm_config::TrustBackedAssetsPalletLocationV3; +use xcm_config::TrustBackedAssetsPalletLocation; use xcm_runtime_apis::{ dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects}, fees::Error as XcmPaymentApiError, @@ -127,7 +127,7 @@ use xcm::{ VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm, }; use xcm_config::{ - DotLocation, DotLocationV3, FellowshipLocation, ForeignAssetsConvertedConcreteId, + DotLocation, FellowshipLocation, ForeignAssetsConvertedConcreteId, ForeignCreatorsSovereignAccountOf, GovernanceLocation, PoolAssetsConvertedConcreteId, TrustBackedAssetsConvertedConcreteId, XcmOriginToTransactDispatchOrigin, }; @@ -293,7 +293,7 @@ impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = impls::tx_payment::FungiblesAdapter< NativeAndAssets, - DotLocationV3, + DotLocation, ResolveAssetTo, >; type WeightToFee = WeightToFee; @@ -362,22 +362,22 @@ pub type ForeignAssetsInstance = pallet_assets::Instance2; impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; - type AssetId = xcm::v3::Location; - type AssetIdParameter = xcm::v3::Location; + type AssetId = xcm::v4::Location; + type AssetIdParameter = xcm::v4::Location; type Currency = Balances; type CreateOrigin = ForeignCreators< ( - FromSiblingParachain, xcm::v3::Location>, + FromSiblingParachain, xcm::v4::Location>, FromNetwork< xcm_config::UniversalLocation, xcm_config::bridging::to_ethereum::EthereumNetwork, - xcm::v3::Location, + xcm::v4::Location, >, xcm_config::bridging::to_kusama::KusamaAssetFromAssetHubKusama, ), ForeignCreatorsSovereignAccountOf, AccountId, - xcm::v3::Location, + xcm::v4::Location, >; type ForceOrigin = AssetsForceOrigin; type AssetDeposit = ForeignAssetsAssetDeposit; @@ -766,7 +766,7 @@ impl pallet_asset_conversion_tx_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Fungibles = LocalAndForeignAssets; type OnChargeAssetTransaction = - impls::tx_payment::SwapCreditAdapter; + impls::tx_payment::SwapCreditAdapter; } parameter_types! { @@ -899,11 +899,11 @@ pub type LocalAndForeignAssets = fungibles::UnionOf< Assets, ForeignAssets, LocalFromLeft< - AssetIdForTrustBackedAssetsConvert, + AssetIdForTrustBackedAssetsConvert, AssetIdForTrustBackedAssets, - xcm::v3::Location, + xcm::v4::Location, >, - xcm::v3::Location, + xcm::v4::Location, AccountId, >; @@ -911,8 +911,8 @@ pub type LocalAndForeignAssets = fungibles::UnionOf< pub type NativeAndAssets = fungible::UnionOf< Balances, LocalAndForeignAssets, - TargetFromLeft, - xcm::v3::Location, + TargetFromLeft, + xcm::v4::Location, AccountId, >; @@ -926,18 +926,18 @@ parameter_types! { pub type PoolIdToAccountId = pallet_asset_conversion::AccountIdConverter< AssetConversionPalletId, - (xcm::v3::Location, xcm::v3::Location), + (xcm::v4::Location, xcm::v4::Location), >; impl pallet_asset_conversion::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; type HigherPrecisionBalance = sp_core::U256; - type AssetKind = xcm::v3::Location; + type AssetKind = xcm::v4::Location; type Assets = NativeAndAssets; type PoolId = (Self::AssetKind, Self::AssetKind); type PoolLocator = pallet_asset_conversion::WithFirstAsset< - DotLocationV3, + DotLocation, AccountId, Self::AssetKind, PoolIdToAccountId, @@ -945,7 +945,7 @@ impl pallet_asset_conversion::Config for Runtime { type PoolAssetId = u32; type PoolAssets = PoolAssets; type PoolSetupFee = PoolSetupFee; - type PoolSetupFeeAsset = DotLocationV3; + type PoolSetupFeeAsset = DotLocation; type PoolSetupFeeTarget = ResolveAssetTo; type LiquidityWithdrawalFee = LiquidityWithdrawalFee; type LPFee = ConstU32<3>; @@ -955,7 +955,7 @@ impl pallet_asset_conversion::Config for Runtime { type WeightInfo = weights::pallet_asset_conversion::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = assets_common::benchmarks::AssetPairFactory< - DotLocationV3, + DotLocation, parachain_info::Pallet, xcm_config::TrustBackedAssetsPalletIndex, Self::AssetKind, @@ -1348,10 +1348,10 @@ impl_runtime_apis! { } } - impl pallet_asset_conversion::AssetConversionApi for Runtime { + impl pallet_asset_conversion::AssetConversionApi for Runtime { fn quote_price_exact_tokens_for_tokens( - asset1: xcm::v3::Location, - asset2: xcm::v3::Location, + asset1: xcm::v4::Location, + asset2: xcm::v4::Location, amount: Balance, include_fee: bool, ) -> Option { @@ -1364,8 +1364,8 @@ impl_runtime_apis! { } fn quote_price_tokens_for_exact_tokens( - asset1: xcm::v3::Location, - asset2: xcm::v3::Location, + asset1: xcm::v4::Location, + asset2: xcm::v4::Location, amount: Balance, include_fee: bool, ) -> Option { @@ -1378,8 +1378,8 @@ impl_runtime_apis! { } fn get_reserves( - asset1: xcm::v3::Location, - asset2: xcm::v3::Location, + asset1: xcm::v4::Location, + asset2: xcm::v4::Location, ) -> Option<(Balance, Balance)> { AssetConversion::get_reserves(asset1, asset2).ok() } 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 2873ac3d12..a485abd6cb 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 @@ -60,7 +60,6 @@ use xcm_executor::{traits::ConvertLocation, XcmExecutor}; parameter_types! { pub const DotLocation: Location = Location::parent(); - pub const DotLocationV3: xcm::v3::Location = xcm::v3::Location::parent(); pub const RelayNetwork: Option = Some(NetworkId::Polkadot); pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorLocation = @@ -69,8 +68,6 @@ parameter_types! { pub TrustBackedAssetsPalletIndex: u8 = ::index() as u8; pub TrustBackedAssetsPalletLocation: Location = PalletInstance(TrustBackedAssetsPalletIndex::get()).into(); - pub TrustBackedAssetsPalletLocationV3: xcm::v3::Location = - xcm::v3::Junction::PalletInstance(TrustBackedAssetsPalletIndex::get()).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub FellowshipLocation: Location = Location::new(1, Parachain(system_parachain::COLLECTIVES_ID)); pub const GovernanceLocation: Location = Location::parent(); @@ -155,7 +152,7 @@ pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConverte StartsWithExplicitGlobalConsensus, ), Balance, - xcm::v3::Location, + xcm::v4::Location, >; /// Means for transacting foreign assets from different global consensus. @@ -397,7 +394,7 @@ impl xcm_executor::Config for XcmConfig { // This trader allows to pay with any assets exchangeable to DOT with // [`AssetConversion`]. cumulus_primitives_utility::SwapFirstAssetTrader< - DotLocationV3, + DotLocation, AssetConversion, WeightToFee, NativeAndAssets, @@ -405,7 +402,7 @@ impl xcm_executor::Config for XcmConfig { TrustBackedAssetsAsLocation< TrustBackedAssetsPalletLocation, Balance, - xcm::v3::Location, + xcm::v4::Location, >, ForeignAssetsConvertedConcreteId, ), @@ -541,9 +538,9 @@ pub type ForeignCreatorsSovereignAccountOf = ( /// Simple conversion of `u32` into an `AssetId` for use in benchmarking. pub struct XcmBenchmarkHelper; #[cfg(feature = "runtime-benchmarks")] -impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { - fn create_asset_id_parameter(id: u32) -> xcm::v3::Location { - xcm::v3::Location::new(1, xcm::v3::Junction::Parachain(id)) +impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { + fn create_asset_id_parameter(id: u32) -> xcm::v4::Location { + xcm::v4::Location::new(1, xcm::v4::Junction::Parachain(id)) } } 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 7da4172102..63cb71cfad 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs @@ -78,7 +78,7 @@ fn slot_durations() -> SlotDurations { fn setup_pool_for_paying_fees_with_foreign_assets( (foreign_asset_owner, foreign_asset_id_location, foreign_asset_id_minimum_balance): ( AccountId, - xcm::v3::Location, + xcm::v4::Location, Balance, ), ) { @@ -86,7 +86,7 @@ fn setup_pool_for_paying_fees_with_foreign_assets( // setup a pool to pay fees with `foreign_asset_id_location` tokens let pool_owner: AccountId = [14u8; 32].into(); - let native_asset = xcm::v3::Location::parent(); + let native_asset = xcm::v4::Location::parent(); let pool_liquidity: Balance = existential_deposit.max(foreign_asset_id_minimum_balance).mul(100_000); @@ -98,15 +98,15 @@ fn setup_pool_for_paying_fees_with_foreign_assets( assert_ok!(ForeignAssets::mint( RuntimeOrigin::signed(foreign_asset_owner), - foreign_asset_id_location, + foreign_asset_id_location.clone(), pool_owner.clone().into(), (foreign_asset_id_minimum_balance + pool_liquidity).mul(2), )); assert_ok!(AssetConversion::create_pool( RuntimeOrigin::signed(pool_owner.clone()), - Box::new(native_asset), - Box::new(foreign_asset_id_location) + Box::new(native_asset.clone()), + Box::new(foreign_asset_id_location.clone()) )); assert_ok!(AssetConversion::add_liquidity( @@ -152,15 +152,15 @@ fn test_assets_balances_api_works() { .build() .execute_with(|| { let local_asset_id = 1; - let foreign_asset_id_location = xcm::v3::Location::new( + let foreign_asset_id_location = xcm::v4::Location::new( 1, - [xcm::v3::Junction::Parachain(1234), xcm::v3::Junction::GeneralIndex(12345)], + [xcm::v4::Junction::Parachain(1234), xcm::v4::Junction::GeneralIndex(12345)], ); // check before assert_eq!(Assets::balance(local_asset_id, AccountId::from(ALICE)), 0); assert_eq!( - ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)), + ForeignAssets::balance(foreign_asset_id_location.clone(), AccountId::from(ALICE)), 0 ); assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 0); @@ -197,7 +197,7 @@ fn test_assets_balances_api_works() { let foreign_asset_minimum_asset_balance = 3333333_u128; assert_ok!(ForeignAssets::force_create( RuntimeHelper::root_origin(), - foreign_asset_id_location, + foreign_asset_id_location.clone(), AccountId::from(SOME_ASSET_ADMIN).into(), false, foreign_asset_minimum_asset_balance @@ -206,7 +206,7 @@ fn test_assets_balances_api_works() { // We first mint enough asset for the account to exist for assets assert_ok!(ForeignAssets::mint( RuntimeHelper::origin_of(AccountId::from(SOME_ASSET_ADMIN)), - foreign_asset_id_location, + foreign_asset_id_location.clone(), AccountId::from(ALICE).into(), 6 * foreign_asset_minimum_asset_balance )); @@ -217,7 +217,7 @@ fn test_assets_balances_api_works() { minimum_asset_balance ); assert_eq!( - ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)), + ForeignAssets::balance(foreign_asset_id_location.clone(), AccountId::from(ALICE)), 6 * minimum_asset_balance ); assert_eq!(Balances::free_balance(AccountId::from(ALICE)), some_currency); @@ -269,7 +269,7 @@ asset_test_utils::include_teleports_for_native_asset_works!( 1000 ); -asset_test_utils::include_teleports_for_foreign_assets_works!( +include_teleports_for_foreign_assets_works!( Runtime, AllPalletsWithoutSystem, XcmConfig, @@ -333,13 +333,13 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_ Runtime, XcmConfig, ForeignAssetsInstance, - xcm::v3::Location, + xcm::v4::Location, JustTry, collator_session_keys(), ExistentialDeposit::get(), - xcm::v3::Location::new( + xcm::v4::Location::new( 1, - [xcm::v3::Junction::Parachain(1313), xcm::v3::Junction::GeneralIndex(12345)] + [xcm::v4::Junction::Parachain(1313), xcm::v4::Junction::GeneralIndex(12345)] ), Box::new(|| { assert!(Assets::asset_ids().collect::>().is_empty()); @@ -355,8 +355,8 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p WeightToFee, ForeignCreatorsSovereignAccountOf, ForeignAssetsInstance, - xcm::v3::Location, - WithLatestLocationConverter, + xcm::v4::Location, + WithLatestLocationConverter, collator_session_keys(), ExistentialDeposit::get(), AssetDeposit::get(), @@ -434,14 +434,14 @@ fn receive_reserve_asset_deposited_ksm_from_asset_hub_kusama_fees_paid_by_pool_s let staking_pot = StakingPot::get(); let foreign_asset_id_location = - xcm::v3::Location::new(2, [xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::Kusama)]); + 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, foreign_asset_id_minimum_balance); + (foreign_asset_owner, foreign_asset_id_location.clone(), foreign_asset_id_minimum_balance); - asset_test_utils::test_cases_over_bridge::receive_reserve_asset_deposited_from_different_consensus_works::< + remove_when_updated_to_stable2409::receive_reserve_asset_deposited_from_different_consensus_works::< Runtime, AllPalletsWithoutSystem, XcmConfig, @@ -473,7 +473,7 @@ fn receive_reserve_asset_deposited_ksm_from_asset_hub_kusama_fees_paid_by_pool_s // check now foreign asset for staking pot assert_eq!( ForeignAssets::balance( - foreign_asset_id_location, + foreign_asset_id_location.clone(), &staking_pot ), 0 @@ -487,7 +487,7 @@ fn receive_reserve_asset_deposited_ksm_from_asset_hub_kusama_fees_paid_by_pool_s // staking pot receives no foreign assets assert_eq!( ForeignAssets::balance( - foreign_asset_id_location, + foreign_asset_id_location.clone(), &staking_pot ), 0 @@ -503,14 +503,14 @@ fn receive_reserve_asset_deposited_ksm_from_asset_hub_kusama_fees_paid_by_suffic let staking_pot = >::account_id(); let foreign_asset_id_location = - xcm::v3::Location::new(2, [xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::Kusama)]); + 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, foreign_asset_id_minimum_balance); + (foreign_asset_owner, foreign_asset_id_location.clone(), foreign_asset_id_minimum_balance); - asset_test_utils::test_cases_over_bridge::receive_reserve_asset_deposited_from_different_consensus_works::< + remove_when_updated_to_stable2409::receive_reserve_asset_deposited_from_different_consensus_works::< Runtime, AllPalletsWithoutSystem, XcmConfig, @@ -533,7 +533,7 @@ fn receive_reserve_asset_deposited_ksm_from_asset_hub_kusama_fees_paid_by_suffic // check block author before assert_eq!( ForeignAssets::balance( - foreign_asset_id_location, + foreign_asset_id_location.clone(), &block_author_account ), 0 @@ -543,7 +543,7 @@ fn receive_reserve_asset_deposited_ksm_from_asset_hub_kusama_fees_paid_by_suffic // `TakeFirstAssetTrader` puts fees to the block author assert!( ForeignAssets::balance( - foreign_asset_id_location, + foreign_asset_id_location.clone(), &block_author_account ) > 0 ); @@ -730,3 +730,600 @@ fn change_xcm_bridge_hub_ethereum_base_fee_by_governance_works() { }, ) } + +#[allow(clippy::too_many_arguments)] +pub mod remove_when_updated_to_stable2409 { + use crate::{AccountId, Balance, TestBridgingConfig}; + + use asset_test_utils::*; + use codec::Encode; + use core::fmt::Debug; + use frame_support::{ + assert_ok, + traits::{ + fungible::Mutate, Currency, OnFinalize, OnInitialize, OriginTrait, ProcessMessageError, + }, + }; + use frame_system::pallet_prelude::BlockNumberFor; + use sp_core::Get; + use sp_runtime::traits::StaticLookup; + use xcm::prelude::*; + use xcm_builder::{CreateMatcher, MatchXcm}; + use xcm_executor::{traits::ConvertLocation, XcmExecutor}; + + #[macro_export] + macro_rules! include_teleports_for_foreign_assets_works( + ( + $runtime:path, + $all_pallets_without_system:path, + $xcm_config:path, + $checking_account:path, + $weight_to_fee:path, + $hrmp_channel_opener:path, + $sovereign_account_of:path, + $assets_pallet_instance:path, + $collator_session_key:expr, + $slot_durations:expr, + $existential_deposit:expr, + $unwrap_pallet_xcm_event:expr, + $unwrap_xcmp_queue_event:expr + ) => { + #[test] + fn teleports_for_foreign_assets_works() { + const BOB: [u8; 32] = [2u8; 32]; + let target_account = parachains_common::AccountId::from(BOB); + const SOME_ASSET_OWNER: [u8; 32] = [5u8; 32]; + let asset_owner = parachains_common::AccountId::from(SOME_ASSET_OWNER); + + $crate::remove_when_updated_to_stable2409::teleports_for_foreign_assets_works::< + $runtime, + $all_pallets_without_system, + $xcm_config, + $checking_account, + $weight_to_fee, + $hrmp_channel_opener, + $sovereign_account_of, + $assets_pallet_instance + >( + $collator_session_key, + $slot_durations, + target_account, + $existential_deposit, + asset_owner, + $unwrap_pallet_xcm_event, + $unwrap_xcmp_queue_event + ) + } + } + ); + + /// Test-case makes sure that `Runtime` can receive teleported assets from sibling parachain, + /// and can teleport it back + pub fn teleports_for_foreign_assets_works< + Runtime, + AllPalletsWithoutSystem, + XcmConfig, + CheckingAccount, + WeightToFee, + HrmpChannelOpener, + SovereignAccountOf, + ForeignAssetsPalletInstance, + >( + collator_session_keys: CollatorSessionKeys, + slot_durations: SlotDurations, + target_account: AccountIdOf, + existential_deposit: BalanceOf, + asset_owner: AccountIdOf, + unwrap_pallet_xcm_event: Box) -> Option>>, + unwrap_xcmp_queue_event: Box< + dyn Fn(Vec) -> Option>, + >, + ) where + Runtime: frame_system::Config + + pallet_balances::Config + + pallet_session::Config + + pallet_xcm::Config + + parachain_info::Config + + pallet_collator_selection::Config + + cumulus_pallet_parachain_system::Config + + cumulus_pallet_xcmp_queue::Config + + pallet_assets::Config + + pallet_timestamp::Config, + AllPalletsWithoutSystem: + OnInitialize> + OnFinalize>, + AccountIdOf: Into<[u8; 32]>, + ValidatorIdOf: From>, + BalanceOf: From, + XcmConfig: xcm_executor::Config, + CheckingAccount: Get>, + HrmpChannelOpener: frame_support::inherent::ProvideInherent< + Call = cumulus_pallet_parachain_system::Call, + >, + WeightToFee: frame_support::weights::WeightToFee, + ::Balance: From + Into, + SovereignAccountOf: ConvertLocation>, + >::AssetId: + From + Into, + >::AssetIdParameter: + From + Into, + >::Balance: + From + Into, + ::AccountId: + Into<<::RuntimeOrigin as OriginTrait>::AccountId>, + <::Lookup as StaticLookup>::Source: + From<::AccountId>, + ::AccountId: From, + ForeignAssetsPalletInstance: 'static, + { + // foreign parachain with the same consensus currency as asset + let foreign_para_id = 2222; + let foreign_asset_id_location = xcm::v4::Location { + parents: 1, + interior: [ + xcm::v4::Junction::Parachain(foreign_para_id), + xcm::v4::Junction::GeneralIndex(1234567), + ] + .into(), + }; + + // foreign creator, which can be sibling parachain to match ForeignCreators + let foreign_creator = + Location { parents: 1, interior: [Parachain(foreign_para_id)].into() }; + let foreign_creator_as_account_id = + SovereignAccountOf::convert_location(&foreign_creator).expect(""); + + // we want to buy execution with local relay chain currency + let buy_execution_fee_amount = + WeightToFee::weight_to_fee(&Weight::from_parts(90_000_000_000, 0)); + let buy_execution_fee = + Asset { id: AssetId(Location::parent()), fun: Fungible(buy_execution_fee_amount) }; + + let teleported_foreign_asset_amount = 10_000_000_000_000; + let runtime_para_id = 1000; + ExtBuilder::::default() + .with_collators(collator_session_keys.collators()) + .with_session_keys(collator_session_keys.session_keys()) + .with_balances(vec![ + ( + foreign_creator_as_account_id, + existential_deposit + (buy_execution_fee_amount * 2).into(), + ), + (target_account.clone(), existential_deposit), + (CheckingAccount::get(), existential_deposit), + ]) + .with_safe_xcm_version(XCM_VERSION) + .with_para_id(runtime_para_id.into()) + .with_tracing() + .build() + .execute_with(|| { + let mut alice = [0u8; 32]; + alice[0] = 1; + + let included_head = RuntimeHelper::::run_to_block( + 2, + AccountId::from(alice).into(), + ); + // checks target_account before + assert_eq!( + >::free_balance(&target_account), + existential_deposit + ); + // check `CheckingAccount` before + assert_eq!( + >::free_balance(CheckingAccount::get()), + existential_deposit + ); + assert_eq!( + >::balance( + foreign_asset_id_location.clone().into(), + &target_account + ), + 0.into() + ); + assert_eq!( + >::balance( + foreign_asset_id_location.clone().into(), + CheckingAccount::get() + ), + 0.into() + ); + // check totals before + assert_total::< + pallet_assets::Pallet, + AccountIdOf, + >(foreign_asset_id_location.clone(), 0, 0); + + // create foreign asset (0 total issuance) + let asset_minimum_asset_balance = 3333333_u128; + assert_ok!( + >::force_create( + RuntimeHelper::::root_origin(), + foreign_asset_id_location.clone().into(), + asset_owner.into(), + false, + asset_minimum_asset_balance.into() + ) + ); + assert_total::< + pallet_assets::Pallet, + AccountIdOf, + >(foreign_asset_id_location.clone(), 0, 0); + assert!(teleported_foreign_asset_amount > asset_minimum_asset_balance); + + // 1. process received teleported assets from sibling parachain (foreign_para_id) + let xcm = Xcm(vec![ + // BuyExecution with relaychain native token + WithdrawAsset(buy_execution_fee.clone().into()), + BuyExecution { + fees: Asset { + id: AssetId(Location::parent()), + fun: Fungible(buy_execution_fee_amount), + }, + weight_limit: Limited(Weight::from_parts(403531000, 65536)), + }, + // Process teleported asset + ReceiveTeleportedAsset(Assets::from(vec![Asset { + id: AssetId(foreign_asset_id_location.clone()), + fun: Fungible(teleported_foreign_asset_amount), + }])), + DepositAsset { + assets: Wild(AllOf { + id: AssetId(foreign_asset_id_location.clone()), + fun: WildFungibility::Fungible, + }), + beneficiary: Location { + parents: 0, + interior: [AccountId32 { + network: None, + id: target_account.clone().into(), + }] + .into(), + }, + }, + ExpectTransactStatus(MaybeErrorCode::Success), + ]); + let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256); + + let outcome = XcmExecutor::::prepare_and_execute( + foreign_creator, + xcm, + &mut hash, + RuntimeHelper::::xcm_max_weight(XcmReceivedFrom::Sibling), + Weight::zero(), + ); + assert_ok!(outcome.ensure_complete()); + + // checks target_account after + assert_eq!( + >::free_balance(&target_account), + existential_deposit + ); + assert_eq!( + >::balance( + foreign_asset_id_location.clone().into(), + &target_account + ), + teleported_foreign_asset_amount.into() + ); + // checks `CheckingAccount` after + assert_eq!( + >::free_balance(CheckingAccount::get()), + existential_deposit + ); + assert_eq!( + >::balance( + foreign_asset_id_location.clone().into(), + CheckingAccount::get() + ), + 0.into() + ); + // check total after (twice: target_account + CheckingAccount) + assert_total::< + pallet_assets::Pallet, + AccountIdOf, + >( + foreign_asset_id_location.clone(), + teleported_foreign_asset_amount, + teleported_foreign_asset_amount, + ); + + // 2. try to teleport asset back to source parachain (foreign_para_id) + { + let dest = Location::new(1, [Parachain(foreign_para_id)]); + let mut dest_beneficiary = Location::new(1, [Parachain(foreign_para_id)]) + .appended_with(AccountId32 { + network: None, + id: sp_runtime::AccountId32::new([3; 32]).into(), + }) + .unwrap(); + dest_beneficiary.reanchor(&dest, &XcmConfig::UniversalLocation::get()).unwrap(); + + let target_account_balance_before_teleport = + >::balance( + foreign_asset_id_location.clone().into(), + &target_account, + ); + let asset_to_teleport_away = asset_minimum_asset_balance * 3; + assert!( + asset_to_teleport_away < + (target_account_balance_before_teleport - + asset_minimum_asset_balance.into()) + .into() + ); + + // Make sure the target account has enough native asset to pay for delivery fees + let delivery_fees = + xcm_helpers::teleport_assets_delivery_fees::( + (foreign_asset_id_location.clone(), asset_to_teleport_away).into(), + 0, + Unlimited, + dest_beneficiary.clone(), + dest.clone(), + ); + >::mint_into( + &target_account, + delivery_fees.into(), + ) + .unwrap(); + + assert_ok!( + RuntimeHelper::::do_teleport_assets::( + RuntimeHelper::::origin_of(target_account.clone()), + dest, + dest_beneficiary, + (foreign_asset_id_location.clone(), asset_to_teleport_away), + Some((runtime_para_id, foreign_para_id)), + included_head, + &alice, + &slot_durations, + ) + ); + + // check balances + assert_eq!( + >::balance( + foreign_asset_id_location.clone().into(), + &target_account + ), + (target_account_balance_before_teleport - asset_to_teleport_away.into()) + ); + assert_eq!( + >::balance( + foreign_asset_id_location.clone().into(), + CheckingAccount::get() + ), + 0.into() + ); + // check total after (twice: target_account + CheckingAccount) + assert_total::< + pallet_assets::Pallet, + AccountIdOf, + >( + foreign_asset_id_location.clone(), + teleported_foreign_asset_amount - asset_to_teleport_away, + teleported_foreign_asset_amount - asset_to_teleport_away, + ); + + // check events + RuntimeHelper::::assert_pallet_xcm_event_outcome( + &unwrap_pallet_xcm_event, + |outcome| { + assert_ok!(outcome.ensure_complete()); + }, + ); + assert!(RuntimeHelper::::xcmp_queue_message_sent( + unwrap_xcmp_queue_event + ) + .is_some()); + } + }) + } + + /// Helper function to verify `xcm` contains all relevant instructions expected on destination + /// chain as part of a reserve-asset-transfer. + pub(crate) fn assert_matches_reserve_asset_deposited_instructions( + xcm: &mut Xcm, + expected_reserve_assets_deposited: &Assets, + expected_beneficiary: &Location, + ) { + let _ = xcm + .0 + .matcher() + .skip_inst_while(|inst| !matches!(inst, ReserveAssetDeposited(..))) + .expect("no instruction ReserveAssetDeposited?") + .match_next_inst(|instr| match instr { + ReserveAssetDeposited(reserve_assets) => { + assert_eq!(reserve_assets.clone(), expected_reserve_assets_deposited.clone()); + Ok(()) + }, + _ => Err(ProcessMessageError::BadFormat), + }) + .expect("expected instruction ReserveAssetDeposited") + .match_next_inst(|instr| match instr { + ClearOrigin => Ok(()), + _ => Err(ProcessMessageError::BadFormat), + }) + .expect("expected instruction ClearOrigin") + .match_next_inst(|instr| match instr { + BuyExecution { .. } => Ok(()), + _ => Err(ProcessMessageError::BadFormat), + }) + .expect("expected instruction BuyExecution") + .match_next_inst(|instr| match instr { + DepositAsset { assets: _, beneficiary } if beneficiary == expected_beneficiary => + Ok(()), + _ => Err(ProcessMessageError::BadFormat), + }) + .expect("expected instruction DepositAsset"); + } + + pub fn receive_reserve_asset_deposited_from_different_consensus_works< + Runtime, + AllPalletsWithoutSystem, + XcmConfig, + ForeignAssetsPalletInstance, + >( + collator_session_keys: CollatorSessionKeys, + existential_deposit: BalanceOf, + target_account: AccountIdOf, + block_author_account: AccountIdOf, + (foreign_asset_owner, foreign_asset_id_location, foreign_asset_id_minimum_balance): ( + AccountIdOf, + xcm::v4::Location, + u128, + ), + foreign_asset_id_amount_to_transfer: u128, + prepare_configuration: impl FnOnce() -> TestBridgingConfig, + (bridge_instance, universal_origin, descend_origin): (Junctions, Junction, Junctions), /* bridge adds origin manipulation on the way */ + additional_checks_before: impl FnOnce(), + additional_checks_after: impl FnOnce(), + ) where + Runtime: frame_system::Config + + pallet_balances::Config + + pallet_session::Config + + pallet_xcm::Config + + parachain_info::Config + + pallet_collator_selection::Config + + cumulus_pallet_parachain_system::Config + + cumulus_pallet_xcmp_queue::Config + + pallet_assets::Config + + pallet_timestamp::Config, + AllPalletsWithoutSystem: + OnInitialize> + OnFinalize>, + AccountIdOf: Into<[u8; 32]> + From<[u8; 32]>, + ValidatorIdOf: From>, + BalanceOf: From + Into, + XcmConfig: xcm_executor::Config, + >::AssetId: + From + Into, + >::AssetIdParameter: + From + Into, + >::Balance: + From + Into + From, + ::AccountId: Into<<::RuntimeOrigin as OriginTrait>::AccountId> + + Into, + <::Lookup as StaticLookup>::Source: + From<::AccountId>, + ForeignAssetsPalletInstance: 'static, + { + ExtBuilder::::default() + .with_collators(collator_session_keys.collators()) + .with_session_keys(collator_session_keys.session_keys()) + .with_tracing() + .build() + .execute_with(|| { + // Set account as block author, who will receive fees + RuntimeHelper::::run_to_block( + 2, + block_author_account.clone(), + ); + + // drip 'ED' user target account + let _ = >::deposit_creating( + &target_account, + existential_deposit, + ); + + // create foreign asset for wrapped/derived representation + assert_ok!( + >::force_create( + RuntimeHelper::::root_origin(), + foreign_asset_id_location.clone().into(), + foreign_asset_owner.into(), + true, // is_sufficient=true + foreign_asset_id_minimum_balance.into() + ) + ); + + // prepare bridge config + let TestBridgingConfig { local_bridge_hub_location, .. } = prepare_configuration(); + + // Balances before + assert_eq!( + >::free_balance(&target_account), + existential_deposit.clone() + ); + + // ForeignAssets balances before + assert_eq!( + >::balance( + foreign_asset_id_location.clone().into(), + &target_account + ), + 0.into() + ); + + // additional check before + additional_checks_before(); + + let expected_assets = Assets::from(vec![Asset { + id: AssetId(foreign_asset_id_location.clone()), + fun: Fungible(foreign_asset_id_amount_to_transfer), + }]); + let expected_beneficiary = Location::new( + 0, + [AccountId32 { network: None, id: target_account.clone().into() }], + ); + + // Call received XCM execution + let xcm = Xcm(vec![ + DescendOrigin(bridge_instance), + UniversalOrigin(universal_origin), + DescendOrigin(descend_origin), + ReserveAssetDeposited(expected_assets.clone()), + ClearOrigin, + BuyExecution { + fees: Asset { + id: AssetId(foreign_asset_id_location.clone()), + fun: Fungible(foreign_asset_id_amount_to_transfer), + }, + weight_limit: Unlimited, + }, + DepositAsset { + assets: Wild(AllCounted(1)), + beneficiary: expected_beneficiary.clone(), + }, + SetTopic([ + 220, 188, 144, 32, 213, 83, 111, 175, 44, 210, 111, 19, 90, 165, 191, 112, + 140, 247, 192, 124, 42, 17, 153, 141, 114, 34, 189, 20, 83, 69, 237, 173, + ]), + ]); + assert_matches_reserve_asset_deposited_instructions( + &mut xcm.clone(), + &expected_assets, + &expected_beneficiary, + ); + + let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256); + + // execute xcm as XcmpQueue would do + let outcome = XcmExecutor::::prepare_and_execute( + local_bridge_hub_location, + xcm, + &mut hash, + RuntimeHelper::::xcm_max_weight( + XcmReceivedFrom::Sibling, + ), + Weight::zero(), + ); + assert_ok!(outcome.ensure_complete()); + + // Balances after + assert_eq!( + >::free_balance(&target_account), + existential_deposit.clone() + ); + + // ForeignAssets balances after + assert!( + >::balance( + foreign_asset_id_location.into(), + &target_account + ) > 0.into() + ); + + // additional check after + additional_checks_after(); + }) + } +} 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 2905aef046..66f2e2ce8f 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 @@ -17,8 +17,8 @@ use asset_hub_polkadot_runtime::{ xcm_config::{ - AssetFeeAsExistentialDepositMultiplierFeeCharger, DotLocation, DotLocationV3, StakingPot, - TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3, XcmConfig, + AssetFeeAsExistentialDepositMultiplierFeeCharger, DotLocation, StakingPot, + TrustBackedAssetsPalletLocation, XcmConfig, }, AllPalletsWithoutSystem, AssetConversion, Assets, Balances, ExistentialDeposit, ForeignAssets, Runtime, SessionKeys, @@ -470,10 +470,10 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { let bob: AccountId = SOME_ASSET_ADMIN.into(); let staking_pot = StakingPot::get(); let asset_1: u32 = 1; - let native_location = DotLocationV3::get(); + let native_location = DotLocation::get(); let asset_1_location = AssetIdForTrustBackedAssetsConvert::< - TrustBackedAssetsPalletLocationV3, - xcm::v3::Location, + TrustBackedAssetsPalletLocation, + xcm::v4::Location, >::convert_back(&asset_1) .unwrap(); // bob's initial balance for native and `asset1` assets. @@ -490,14 +490,14 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { assert_ok!(AssetConversion::create_pool( RuntimeHelper::origin_of(bob.clone()), - Box::new(native_location), - Box::new(asset_1_location) + Box::new(native_location.clone()), + Box::new(asset_1_location.clone()) )); assert_ok!(AssetConversion::add_liquidity( RuntimeHelper::origin_of(bob.clone()), - Box::new(native_location), - Box::new(asset_1_location), + Box::new(native_location.clone()), + Box::new(asset_1_location.clone()), pool_liquidity, pool_liquidity, 1, @@ -509,8 +509,6 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { let asset_total_issuance = Assets::total_issuance(asset_1); let native_total_issuance = Balances::total_issuance(); - let asset_1_location_latest: Location = asset_1_location.try_into().unwrap(); - // prepare input to buy weight. let weight = Weight::from_parts(4_000_000_000, 0); let fee = WeightToFee::weight_to_fee(&weight); @@ -518,7 +516,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap(); let extra_amount = 100; let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - let payment: Asset = (asset_1_location_latest.clone(), asset_fee + extra_amount).into(); + let payment: Asset = (asset_1_location.clone(), asset_fee + extra_amount).into(); // init trader and buy weight. let mut trader = ::Trader::new(); @@ -526,10 +524,8 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok"); // assert. - let unused_amount = unused_asset - .fungible - .get(&asset_1_location_latest.clone().into()) - .map_or(0, |a| *a); + let unused_amount = + unused_asset.fungible.get(&asset_1_location.clone().into()).map_or(0, |a| *a); assert_eq!(unused_amount, extra_amount); assert_eq!(Assets::total_issuance(asset_1), asset_total_issuance + asset_fee); @@ -537,13 +533,13 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { let refund_weight = Weight::from_parts(1_000_000_000, 0); let refund = WeightToFee::weight_to_fee(&refund_weight); let (reserve1, reserve2) = - AssetConversion::get_reserves(native_location, asset_1_location).unwrap(); + AssetConversion::get_reserves(native_location, asset_1_location.clone()).unwrap(); let asset_refund = AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap(); // refund. let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap(); - assert_eq!(actual_refund, (asset_1_location_latest, asset_refund).into()); + assert_eq!(actual_refund, (asset_1_location, asset_refund).into()); // assert. assert_eq!(Balances::balance(&staking_pot), initial_balance); @@ -572,12 +568,12 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { .execute_with(|| { let bob: AccountId = SOME_ASSET_ADMIN.into(); let staking_pot = StakingPot::get(); - let native_location = DotLocationV3::get(); - let foreign_location = xcm::v3::Location { + let native_location = DotLocation::get(); + let foreign_location = xcm::v4::Location { parents: 1, interior: ( - xcm::v3::Junction::Parachain(1234), - xcm::v3::Junction::GeneralIndex(12345), + xcm::v4::Junction::Parachain(1234), + xcm::v4::Junction::GeneralIndex(12345), ) .into(), }; @@ -588,26 +584,26 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { // init asset, balances and pool. assert_ok!(>::create( - foreign_location, + foreign_location.clone(), bob.clone(), true, 10 )); - assert_ok!(ForeignAssets::mint_into(foreign_location, &bob, initial_balance)); + assert_ok!(ForeignAssets::mint_into(foreign_location.clone(), &bob, initial_balance)); assert_ok!(Balances::mint_into(&bob, initial_balance)); assert_ok!(Balances::mint_into(&staking_pot, initial_balance)); assert_ok!(AssetConversion::create_pool( RuntimeHelper::origin_of(bob.clone()), - Box::new(native_location), - Box::new(foreign_location) + Box::new(native_location.clone()), + Box::new(foreign_location.clone()) )); assert_ok!(AssetConversion::add_liquidity( RuntimeHelper::origin_of(bob.clone()), - Box::new(native_location), - Box::new(foreign_location), + Box::new(native_location.clone()), + Box::new(foreign_location.clone()), pool_liquidity, pool_liquidity, 1, @@ -616,11 +612,9 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { )); // keep initial total issuance to assert later. - let asset_total_issuance = ForeignAssets::total_issuance(foreign_location); + let asset_total_issuance = ForeignAssets::total_issuance(foreign_location.clone()); let native_total_issuance = Balances::total_issuance(); - let foreign_location_latest: Location = foreign_location.try_into().unwrap(); - // prepare input to buy weight. let weight = Weight::from_parts(4_000_000_000, 0); let fee = WeightToFee::weight_to_fee(&weight); @@ -628,7 +622,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap(); let extra_amount = 100; let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - let payment: Asset = (foreign_location_latest.clone(), asset_fee + extra_amount).into(); + let payment: Asset = (foreign_location.clone(), asset_fee + extra_amount).into(); // init trader and buy weight. let mut trader = ::Trader::new(); @@ -636,13 +630,11 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok"); // assert. - let unused_amount = unused_asset - .fungible - .get(&foreign_location_latest.clone().into()) - .map_or(0, |a| *a); + let unused_amount = + unused_asset.fungible.get(&foreign_location.clone().into()).map_or(0, |a| *a); assert_eq!(unused_amount, extra_amount); assert_eq!( - ForeignAssets::total_issuance(foreign_location), + ForeignAssets::total_issuance(foreign_location.clone()), asset_total_issuance + asset_fee ); @@ -650,13 +642,13 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { let refund_weight = Weight::from_parts(1_000_000_000, 0); let refund = WeightToFee::weight_to_fee(&refund_weight); let (reserve1, reserve2) = - AssetConversion::get_reserves(native_location, foreign_location).unwrap(); + AssetConversion::get_reserves(native_location, foreign_location.clone()).unwrap(); let asset_refund = AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap(); // refund. let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap(); - assert_eq!(actual_refund, (foreign_location_latest, asset_refund).into()); + assert_eq!(actual_refund, (foreign_location.clone(), asset_refund).into()); // assert. assert_eq!(Balances::balance(&staking_pot), initial_balance);