Remove xcm::v3 from assets-common nits (#4037)

This PR mainly removes `xcm::v3` stuff from `assets-common` to make it
more generic and facilitate the transition to newer XCM versions. Some
of the implementations here used hard-coded `xcm::v3::Location`, but now
it's up to the runtime to configure according to its needs.

Additional/consequent changes:
- `penpal` runtime uses now `xcm::latest::Location` for `pallet_assets`
as `AssetId`, because we don't care about migrations here
- it pretty much simplify xcm-emulator integration tests, where we don't
need now a lots of boilerplate conversions:
      ```
      v3::Location::try_from(...).expect("conversion works")`
      ```
- xcm-emulator tests
- split macro `impl_assets_helpers_for_parachain` to the
`impl_assets_helpers_for_parachain` and
`impl_foreign_assets_helpers_for_parachain` (avoids using hard-coded
`xcm::v3::Location`)
This commit is contained in:
Branislav Kontur
2024-04-12 23:24:09 +02:00
committed by GitHub
parent b28ba4ae96
commit 5601f2865b
35 changed files with 654 additions and 549 deletions
Generated
+2
View File
@@ -809,6 +809,7 @@ dependencies = [
"parachains-common", "parachains-common",
"rococo-emulated-chain", "rococo-emulated-chain",
"sp-core", "sp-core",
"staging-xcm",
"testnet-parachains-constants", "testnet-parachains-constants",
] ]
@@ -927,6 +928,7 @@ dependencies = [
"frame-support", "frame-support",
"parachains-common", "parachains-common",
"sp-core", "sp-core",
"staging-xcm",
"testnet-parachains-constants", "testnet-parachains-constants",
"westend-emulated-chain", "westend-emulated-chain",
] ]
@@ -23,3 +23,6 @@ emulated-integration-tests-common = { path = "../../../../common", default-featu
asset-hub-rococo-runtime = { path = "../../../../../../runtimes/assets/asset-hub-rococo" } asset-hub-rococo-runtime = { path = "../../../../../../runtimes/assets/asset-hub-rococo" }
rococo-emulated-chain = { path = "../../../relays/rococo" } rococo-emulated-chain = { path = "../../../relays/rococo" }
testnet-parachains-constants = { path = "../../../../../../runtimes/constants", features = ["rococo"] } testnet-parachains-constants = { path = "../../../../../../runtimes/constants", features = ["rococo"] }
# Polkadot
xcm = { package = "staging-xcm", path = "../../../../../../../../polkadot/xcm", default-features = false }
@@ -22,7 +22,8 @@ use frame_support::traits::OnInitialize;
use emulated_integration_tests_common::{ use emulated_integration_tests_common::{
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
impl_assets_helpers_for_parachain, impl_assets_helpers_for_system_parachain, impl_assets_helpers_for_parachain, impl_assets_helpers_for_system_parachain,
impl_xcm_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains, impl_foreign_assets_helpers_for_parachain, impl_xcm_helpers_for_parachain, impls::Parachain,
xcm_emulator::decl_test_parachains,
}; };
use rococo_emulated_chain::Rococo; use rococo_emulated_chain::Rococo;
@@ -56,4 +57,5 @@ impl_accounts_helpers_for_parachain!(AssetHubRococo);
impl_assert_events_helpers_for_parachain!(AssetHubRococo); impl_assert_events_helpers_for_parachain!(AssetHubRococo);
impl_assets_helpers_for_system_parachain!(AssetHubRococo, Rococo); impl_assets_helpers_for_system_parachain!(AssetHubRococo, Rococo);
impl_assets_helpers_for_parachain!(AssetHubRococo); impl_assets_helpers_for_parachain!(AssetHubRococo);
impl_foreign_assets_helpers_for_parachain!(AssetHubRococo, xcm::v3::Location);
impl_xcm_helpers_for_parachain!(AssetHubRococo); impl_xcm_helpers_for_parachain!(AssetHubRococo);
@@ -23,3 +23,6 @@ emulated-integration-tests-common = { path = "../../../../common", default-featu
asset-hub-westend-runtime = { path = "../../../../../../runtimes/assets/asset-hub-westend" } asset-hub-westend-runtime = { path = "../../../../../../runtimes/assets/asset-hub-westend" }
westend-emulated-chain = { path = "../../../relays/westend" } westend-emulated-chain = { path = "../../../relays/westend" }
testnet-parachains-constants = { path = "../../../../../../runtimes/constants", features = ["westend"] } testnet-parachains-constants = { path = "../../../../../../runtimes/constants", features = ["westend"] }
# Polkadot
xcm = { package = "staging-xcm", path = "../../../../../../../../polkadot/xcm", default-features = false }
@@ -22,7 +22,8 @@ use frame_support::traits::OnInitialize;
use emulated_integration_tests_common::{ use emulated_integration_tests_common::{
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
impl_assets_helpers_for_parachain, impl_assets_helpers_for_system_parachain, impl_assets_helpers_for_parachain, impl_assets_helpers_for_system_parachain,
impl_xcm_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains, impl_foreign_assets_helpers_for_parachain, impl_xcm_helpers_for_parachain, impls::Parachain,
xcm_emulator::decl_test_parachains,
}; };
use westend_emulated_chain::Westend; use westend_emulated_chain::Westend;
@@ -56,4 +57,5 @@ impl_accounts_helpers_for_parachain!(AssetHubWestend);
impl_assert_events_helpers_for_parachain!(AssetHubWestend); impl_assert_events_helpers_for_parachain!(AssetHubWestend);
impl_assets_helpers_for_system_parachain!(AssetHubWestend, Westend); impl_assets_helpers_for_system_parachain!(AssetHubWestend, Westend);
impl_assets_helpers_for_parachain!(AssetHubWestend); impl_assets_helpers_for_parachain!(AssetHubWestend);
impl_foreign_assets_helpers_for_parachain!(AssetHubWestend, xcm::v3::Location);
impl_xcm_helpers_for_parachain!(AssetHubWestend); impl_xcm_helpers_for_parachain!(AssetHubWestend);
@@ -17,8 +17,6 @@
use frame_support::parameter_types; use frame_support::parameter_types;
use sp_core::{sr25519, storage::Storage}; use sp_core::{sr25519, storage::Storage};
// Polkadot
use xcm::v3::Location;
// Cumulus // Cumulus
use emulated_integration_tests_common::{ use emulated_integration_tests_common::{
accounts, build_genesis_storage, collators, get_account_id_from_seed, SAFE_XCM_VERSION, accounts, build_genesis_storage, collators, get_account_id_from_seed, SAFE_XCM_VERSION,
@@ -79,19 +77,9 @@ pub fn genesis(para_id: u32) -> Storage {
foreign_assets: penpal_runtime::ForeignAssetsConfig { foreign_assets: penpal_runtime::ForeignAssetsConfig {
assets: vec![ assets: vec![
// Relay Native asset representation // Relay Native asset representation
( (RelayLocation::get(), PenpalAssetOwner::get(), true, ED),
Location::try_from(RelayLocation::get()).unwrap(),
PenpalAssetOwner::get(),
true,
ED,
),
// Sufficient AssetHub asset representation // Sufficient AssetHub asset representation
( (LocalReservableFromAssetHub::get(), PenpalAssetOwner::get(), true, ED),
Location::try_from(LocalReservableFromAssetHub::get()).unwrap(),
PenpalAssetOwner::get(),
true,
ED,
),
], ],
..Default::default() ..Default::default()
}, },
@@ -26,7 +26,8 @@ use sp_core::Encode;
// Cumulus // Cumulus
use emulated_integration_tests_common::{ use emulated_integration_tests_common::{
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
impl_assets_helpers_for_parachain, impl_xcm_helpers_for_parachain, impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain,
impl_xcm_helpers_for_parachain,
impls::{NetworkId, Parachain}, impls::{NetworkId, Parachain},
xcm_emulator::decl_test_parachains, xcm_emulator::decl_test_parachains,
}; };
@@ -87,6 +88,8 @@ impl_accounts_helpers_for_parachain!(PenpalB);
impl_assert_events_helpers_for_parachain!(PenpalA); impl_assert_events_helpers_for_parachain!(PenpalA);
impl_assert_events_helpers_for_parachain!(PenpalB); impl_assert_events_helpers_for_parachain!(PenpalB);
impl_assets_helpers_for_parachain!(PenpalA); impl_assets_helpers_for_parachain!(PenpalA);
impl_foreign_assets_helpers_for_parachain!(PenpalA, xcm::latest::Location);
impl_assets_helpers_for_parachain!(PenpalB); impl_assets_helpers_for_parachain!(PenpalB);
impl_foreign_assets_helpers_for_parachain!(PenpalB, xcm::latest::Location);
impl_xcm_helpers_for_parachain!(PenpalA); impl_xcm_helpers_for_parachain!(PenpalA);
impl_xcm_helpers_for_parachain!(PenpalB); impl_xcm_helpers_for_parachain!(PenpalB);
@@ -38,9 +38,7 @@ pub use polkadot_runtime_parachains::{
inclusion::{AggregateMessageOrigin, UmpQueueId}, inclusion::{AggregateMessageOrigin, UmpQueueId},
}; };
pub use xcm::{ pub use xcm::{
prelude::{Location, OriginKind, Outcome, VersionedXcm, XcmVersion}, prelude::{Location, OriginKind, Outcome, VersionedXcm, XcmError, XcmVersion},
v3,
v4::Error as XcmError,
DoubleEncoded, DoubleEncoded,
}; };
@@ -696,81 +694,9 @@ macro_rules! impl_assets_helpers_for_system_parachain {
#[macro_export] #[macro_export]
macro_rules! impl_assets_helpers_for_parachain { macro_rules! impl_assets_helpers_for_parachain {
( $chain:ident) => { ($chain:ident) => {
$crate::impls::paste::paste! { $crate::impls::paste::paste! {
impl<N: $crate::impls::Network> $chain<N> { impl<N: $crate::impls::Network> $chain<N> {
/// Create foreign assets using sudo `ForeignAssets::force_create()`
pub fn force_create_foreign_asset(
id: $crate::impls::v3::Location,
owner: $crate::impls::AccountId,
is_sufficient: bool,
min_balance: u128,
prefund_accounts: Vec<($crate::impls::AccountId, u128)>,
) {
use $crate::impls::Inspect;
let sudo_origin = <$chain<N> as $crate::impls::Chain>::RuntimeOrigin::root();
<Self as $crate::impls::TestExt>::execute_with(|| {
$crate::impls::assert_ok!(
<Self as [<$chain ParaPallet>]>::ForeignAssets::force_create(
sudo_origin,
id.clone(),
owner.clone().into(),
is_sufficient,
min_balance,
)
);
assert!(<Self as [<$chain ParaPallet>]>::ForeignAssets::asset_exists(id.clone()));
type RuntimeEvent<N> = <$chain<N> as $crate::impls::Chain>::RuntimeEvent;
$crate::impls::assert_expected_events!(
Self,
vec![
RuntimeEvent::<N>::ForeignAssets(
$crate::impls::pallet_assets::Event::ForceCreated {
asset_id,
..
}
) => { asset_id: *asset_id == id, },
]
);
});
for (beneficiary, amount) in prefund_accounts.into_iter() {
let signed_origin =
<$chain<N> as $crate::impls::Chain>::RuntimeOrigin::signed(owner.clone());
Self::mint_foreign_asset(signed_origin, id.clone(), beneficiary, amount);
}
}
/// Mint assets making use of the ForeignAssets pallet-assets instance
pub fn mint_foreign_asset(
signed_origin: <Self as $crate::impls::Chain>::RuntimeOrigin,
id: $crate::impls::v3::Location,
beneficiary: $crate::impls::AccountId,
amount_to_mint: u128,
) {
<Self as $crate::impls::TestExt>::execute_with(|| {
$crate::impls::assert_ok!(<Self as [<$chain ParaPallet>]>::ForeignAssets::mint(
signed_origin,
id.clone().into(),
beneficiary.clone().into(),
amount_to_mint
));
type RuntimeEvent<N> = <$chain<N> as $crate::impls::Chain>::RuntimeEvent;
$crate::impls::assert_expected_events!(
Self,
vec![
RuntimeEvent::<N>::ForeignAssets(
$crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount }
) => {
asset_id: *asset_id == id,
owner: *owner == beneficiary.clone().into(),
amount: *amount == amount_to_mint,
},
]
);
});
}
/// Create assets using sudo `Assets::force_create()` /// Create assets using sudo `Assets::force_create()`
pub fn force_create_asset( pub fn force_create_asset(
id: u32, id: u32,
@@ -863,10 +789,92 @@ macro_rules! impl_assets_helpers_for_parachain {
.encode() .encode()
.into() .into()
} }
}
}
};
}
#[macro_export]
macro_rules! impl_foreign_assets_helpers_for_parachain {
($chain:ident, $asset_id_type:ty) => {
$crate::impls::paste::paste! {
impl<N: $crate::impls::Network> $chain<N> {
/// Create foreign assets using sudo `ForeignAssets::force_create()`
pub fn force_create_foreign_asset(
id: $asset_id_type,
owner: $crate::impls::AccountId,
is_sufficient: bool,
min_balance: u128,
prefund_accounts: Vec<($crate::impls::AccountId, u128)>,
) {
use $crate::impls::Inspect;
let sudo_origin = <$chain<N> as $crate::impls::Chain>::RuntimeOrigin::root();
<Self as $crate::impls::TestExt>::execute_with(|| {
$crate::impls::assert_ok!(
<Self as [<$chain ParaPallet>]>::ForeignAssets::force_create(
sudo_origin,
id.clone(),
owner.clone().into(),
is_sufficient,
min_balance,
)
);
assert!(<Self as [<$chain ParaPallet>]>::ForeignAssets::asset_exists(id.clone()));
type RuntimeEvent<N> = <$chain<N> as $crate::impls::Chain>::RuntimeEvent;
$crate::impls::assert_expected_events!(
Self,
vec![
RuntimeEvent::<N>::ForeignAssets(
$crate::impls::pallet_assets::Event::ForceCreated {
asset_id,
..
}
) => { asset_id: *asset_id == id, },
]
);
});
for (beneficiary, amount) in prefund_accounts.into_iter() {
let signed_origin =
<$chain<N> as $crate::impls::Chain>::RuntimeOrigin::signed(owner.clone());
Self::mint_foreign_asset(signed_origin, id.clone(), beneficiary, amount);
}
}
/// Mint assets making use of the ForeignAssets pallet-assets instance
pub fn mint_foreign_asset(
signed_origin: <Self as $crate::impls::Chain>::RuntimeOrigin,
id: $asset_id_type,
beneficiary: $crate::impls::AccountId,
amount_to_mint: u128,
) {
<Self as $crate::impls::TestExt>::execute_with(|| {
$crate::impls::assert_ok!(<Self as [<$chain ParaPallet>]>::ForeignAssets::mint(
signed_origin,
id.clone().into(),
beneficiary.clone().into(),
amount_to_mint
));
type RuntimeEvent<N> = <$chain<N> as $crate::impls::Chain>::RuntimeEvent;
$crate::impls::assert_expected_events!(
Self,
vec![
RuntimeEvent::<N>::ForeignAssets(
$crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount }
) => {
asset_id: *asset_id == id,
owner: *owner == beneficiary.clone().into(),
amount: *amount == amount_to_mint,
},
]
);
});
}
/// Returns the encoded call for `create` from the foreign assets pallet /// Returns the encoded call for `create` from the foreign assets pallet
pub fn create_foreign_asset_call( pub fn create_foreign_asset_call(
asset_id: $crate::impls::v3::Location, asset_id: $asset_id_type,
min_balance: $crate::impls::Balance, min_balance: $crate::impls::Balance,
admin: $crate::impls::AccountId, admin: $crate::impls::AccountId,
) -> $crate::impls::DoubleEncoded<()> { ) -> $crate::impls::DoubleEncoded<()> {
@@ -137,14 +137,13 @@ fn transfer_foreign_assets_from_asset_hub_to_para() {
let destination = AssetHubRococo::sibling_location_of(PenpalA::para_id()); let destination = AssetHubRococo::sibling_location_of(PenpalA::para_id());
let sender = AssetHubRococoSender::get(); let sender = AssetHubRococoSender::get();
let native_amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000; let native_amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000;
let native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let native_asset_location = RelayLocation::get();
let receiver = PenpalAReceiver::get(); let receiver = PenpalAReceiver::get();
let assets_owner = PenpalAssetOwner::get(); let assets_owner = PenpalAssetOwner::get();
// Foreign asset used: bridged WND // Foreign asset used: bridged WND
let foreign_amount_to_send = ASSET_HUB_ROCOCO_ED * 10_000_000; let foreign_amount_to_send = ASSET_HUB_ROCOCO_ED * 10_000_000;
let wnd_at_rococo_parachains = let wnd_at_rococo_parachains =
v3::Location::new(2, [v3::Junction::GlobalConsensus(v3::NetworkId::Westend)]); Location::new(2, [Junction::GlobalConsensus(NetworkId::Westend)]);
let wnd_at_rococo_parachains_latest: Location = wnd_at_rococo_parachains.try_into().unwrap();
// Configure destination chain to trust AH as reserve of WND // Configure destination chain to trust AH as reserve of WND
PenpalA::execute_with(|| { PenpalA::execute_with(|| {
@@ -157,14 +156,14 @@ fn transfer_foreign_assets_from_asset_hub_to_para() {
)); ));
}); });
PenpalA::force_create_foreign_asset( PenpalA::force_create_foreign_asset(
wnd_at_rococo_parachains, wnd_at_rococo_parachains.clone(),
assets_owner.clone(), assets_owner.clone(),
false, false,
ASSET_MIN_BALANCE, ASSET_MIN_BALANCE,
vec![], vec![],
); );
AssetHubRococo::force_create_foreign_asset( AssetHubRococo::force_create_foreign_asset(
wnd_at_rococo_parachains, wnd_at_rococo_parachains.clone().try_into().unwrap(),
assets_owner.clone(), assets_owner.clone(),
false, false,
ASSET_MIN_BALANCE, ASSET_MIN_BALANCE,
@@ -172,7 +171,7 @@ fn transfer_foreign_assets_from_asset_hub_to_para() {
); );
AssetHubRococo::mint_foreign_asset( AssetHubRococo::mint_foreign_asset(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(assets_owner), <AssetHubRococo as Chain>::RuntimeOrigin::signed(assets_owner),
wnd_at_rococo_parachains, wnd_at_rococo_parachains.clone().try_into().unwrap(),
sender.clone(), sender.clone(),
foreign_amount_to_send * 2, foreign_amount_to_send * 2,
); );
@@ -180,7 +179,7 @@ fn transfer_foreign_assets_from_asset_hub_to_para() {
// Assets to send // Assets to send
let assets: Vec<Asset> = vec![ let assets: Vec<Asset> = vec![
(Parent, native_amount_to_send).into(), (Parent, native_amount_to_send).into(),
(wnd_at_rococo_parachains_latest, foreign_amount_to_send).into(), (wnd_at_rococo_parachains.clone(), foreign_amount_to_send).into(),
]; ];
let fee_asset_id = AssetId(Parent.into()); let fee_asset_id = AssetId(Parent.into());
let fee_asset_item = assets.iter().position(|a| a.id == fee_asset_id).unwrap() as u32; let fee_asset_item = assets.iter().position(|a| a.id == fee_asset_id).unwrap() as u32;
@@ -204,15 +203,18 @@ fn transfer_foreign_assets_from_asset_hub_to_para() {
let sender_balance_before = test.sender.balance; let sender_balance_before = test.sender.balance;
let sender_wnds_before = AssetHubRococo::execute_with(|| { let sender_wnds_before = AssetHubRococo::execute_with(|| {
type ForeignAssets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets; type ForeignAssets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(wnd_at_rococo_parachains, &sender) <ForeignAssets as Inspect<_>>::balance(
wnd_at_rococo_parachains.clone().try_into().unwrap(),
&sender,
)
}); });
let receiver_assets_before = PenpalA::execute_with(|| { let receiver_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(native_asset_location.into(), &receiver) <ForeignAssets as Inspect<_>>::balance(native_asset_location.clone(), &receiver)
}); });
let receiver_wnds_before = PenpalA::execute_with(|| { let receiver_wnds_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(wnd_at_rococo_parachains, &receiver) <ForeignAssets as Inspect<_>>::balance(wnd_at_rococo_parachains.clone(), &receiver)
}); });
// Set assertions and dispatchables // Set assertions and dispatchables
@@ -225,7 +227,10 @@ fn transfer_foreign_assets_from_asset_hub_to_para() {
let sender_balance_after = test.sender.balance; let sender_balance_after = test.sender.balance;
let sender_wnds_after = AssetHubRococo::execute_with(|| { let sender_wnds_after = AssetHubRococo::execute_with(|| {
type ForeignAssets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets; type ForeignAssets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(wnd_at_rococo_parachains, &sender) <ForeignAssets as Inspect<_>>::balance(
wnd_at_rococo_parachains.clone().try_into().unwrap(),
&sender,
)
}); });
let receiver_assets_after = PenpalA::execute_with(|| { let receiver_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
@@ -262,14 +267,13 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
let destination = PenpalA::sibling_location_of(AssetHubRococo::para_id()); let destination = PenpalA::sibling_location_of(AssetHubRococo::para_id());
let sender = PenpalASender::get(); let sender = PenpalASender::get();
let native_amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000; let native_amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000;
let native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let native_asset_location = RelayLocation::get();
let assets_owner = PenpalAssetOwner::get(); let assets_owner = PenpalAssetOwner::get();
// Foreign asset used: bridged WND // Foreign asset used: bridged WND
let foreign_amount_to_send = ASSET_HUB_ROCOCO_ED * 10_000_000; let foreign_amount_to_send = ASSET_HUB_ROCOCO_ED * 10_000_000;
let wnd_at_rococo_parachains = let wnd_at_rococo_parachains =
v3::Location::new(2, [v3::Junction::GlobalConsensus(v3::NetworkId::Westend)]); Location::new(2, [Junction::GlobalConsensus(NetworkId::Westend)]);
let wnd_at_rococo_parachains_latest: Location = wnd_at_rococo_parachains.try_into().unwrap();
// Configure destination chain to trust AH as reserve of WND // Configure destination chain to trust AH as reserve of WND
PenpalA::execute_with(|| { PenpalA::execute_with(|| {
@@ -282,14 +286,14 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
)); ));
}); });
PenpalA::force_create_foreign_asset( PenpalA::force_create_foreign_asset(
wnd_at_rococo_parachains, wnd_at_rococo_parachains.clone(),
assets_owner.clone(), assets_owner.clone(),
false, false,
ASSET_MIN_BALANCE, ASSET_MIN_BALANCE,
vec![], vec![],
); );
AssetHubRococo::force_create_foreign_asset( AssetHubRococo::force_create_foreign_asset(
wnd_at_rococo_parachains, wnd_at_rococo_parachains.clone().try_into().unwrap(),
assets_owner.clone(), assets_owner.clone(),
false, false,
ASSET_MIN_BALANCE, ASSET_MIN_BALANCE,
@@ -299,13 +303,13 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
// fund Parachain's sender account // fund Parachain's sender account
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(assets_owner.clone()), <PenpalA as Chain>::RuntimeOrigin::signed(assets_owner.clone()),
native_asset_location, native_asset_location.clone(),
sender.clone(), sender.clone(),
native_amount_to_send * 2, native_amount_to_send * 2,
); );
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(assets_owner.clone()), <PenpalA as Chain>::RuntimeOrigin::signed(assets_owner.clone()),
wnd_at_rococo_parachains, wnd_at_rococo_parachains.clone(),
sender.clone(), sender.clone(),
foreign_amount_to_send * 2, foreign_amount_to_send * 2,
); );
@@ -322,7 +326,7 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
)]); )]);
AssetHubRococo::mint_foreign_asset( AssetHubRococo::mint_foreign_asset(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(assets_owner), <AssetHubRococo as Chain>::RuntimeOrigin::signed(assets_owner),
wnd_at_rococo_parachains, wnd_at_rococo_parachains.clone().try_into().unwrap(),
sov_penpal_on_ahr, sov_penpal_on_ahr,
foreign_amount_to_send * 2, foreign_amount_to_send * 2,
); );
@@ -330,7 +334,7 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
// Assets to send // Assets to send
let assets: Vec<Asset> = vec![ let assets: Vec<Asset> = vec![
(Parent, native_amount_to_send).into(), (Parent, native_amount_to_send).into(),
(wnd_at_rococo_parachains_latest, foreign_amount_to_send).into(), (wnd_at_rococo_parachains.clone(), foreign_amount_to_send).into(),
]; ];
let fee_asset_id = AssetId(Parent.into()); let fee_asset_id = AssetId(Parent.into());
let fee_asset_item = assets.iter().position(|a| a.id == fee_asset_id).unwrap() as u32; let fee_asset_item = assets.iter().position(|a| a.id == fee_asset_id).unwrap() as u32;
@@ -353,16 +357,19 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
// Query initial balances // Query initial balances
let sender_native_before = PenpalA::execute_with(|| { let sender_native_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(native_asset_location, &sender) <ForeignAssets as Inspect<_>>::balance(native_asset_location.clone(), &sender)
}); });
let sender_wnds_before = PenpalA::execute_with(|| { let sender_wnds_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(wnd_at_rococo_parachains, &sender) <ForeignAssets as Inspect<_>>::balance(wnd_at_rococo_parachains.clone(), &sender)
}); });
let receiver_native_before = test.receiver.balance; let receiver_native_before = test.receiver.balance;
let receiver_wnds_before = AssetHubRococo::execute_with(|| { let receiver_wnds_before = AssetHubRococo::execute_with(|| {
type ForeignAssets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets; type ForeignAssets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(wnd_at_rococo_parachains, &receiver) <ForeignAssets as Inspect<_>>::balance(
wnd_at_rococo_parachains.clone().try_into().unwrap(),
&receiver,
)
}); });
// Set assertions and dispatchables // Set assertions and dispatchables
@@ -378,12 +385,15 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
}); });
let sender_wnds_after = PenpalA::execute_with(|| { let sender_wnds_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(wnd_at_rococo_parachains, &sender) <ForeignAssets as Inspect<_>>::balance(wnd_at_rococo_parachains.clone(), &sender)
}); });
let receiver_native_after = test.receiver.balance; let receiver_native_after = test.receiver.balance;
let receiver_wnds_after = AssetHubRococo::execute_with(|| { let receiver_wnds_after = AssetHubRococo::execute_with(|| {
type ForeignAssets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets; type ForeignAssets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(wnd_at_rococo_parachains, &receiver) <ForeignAssets as Inspect<_>>::balance(
wnd_at_rococo_parachains.try_into().unwrap(),
&receiver,
)
}); });
// Sender's balance is reduced by amount sent plus delivery fees // Sender's balance is reduced by amount sent plus delivery fees
@@ -412,8 +422,7 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
let sender = PenpalASender::get(); let sender = PenpalASender::get();
let roc_to_send: Balance = ROCOCO_ED * 10000; let roc_to_send: Balance = ROCOCO_ED * 10000;
let assets_owner = PenpalAssetOwner::get(); let assets_owner = PenpalAssetOwner::get();
let roc_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let roc_location = RelayLocation::get();
let roc_location_latest: Location = roc_location.try_into().unwrap();
let sender_as_seen_by_ah = AssetHubRococo::sibling_location_of(PenpalA::para_id()); let sender_as_seen_by_ah = AssetHubRococo::sibling_location_of(PenpalA::para_id());
let sov_of_sender_on_ah = AssetHubRococo::sovereign_account_id_of(sender_as_seen_by_ah); let sov_of_sender_on_ah = AssetHubRococo::sovereign_account_id_of(sender_as_seen_by_ah);
let receiver_as_seen_by_ah = AssetHubRococo::sibling_location_of(PenpalB::para_id()); let receiver_as_seen_by_ah = AssetHubRococo::sibling_location_of(PenpalB::para_id());
@@ -433,24 +442,23 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
// Register WND as foreign asset and transfer it around the Rococo ecosystem // Register WND as foreign asset and transfer it around the Rococo ecosystem
let wnd_at_rococo_parachains = let wnd_at_rococo_parachains =
v3::Location::new(2, [v3::Junction::GlobalConsensus(v3::NetworkId::Westend)]); Location::new(2, [Junction::GlobalConsensus(NetworkId::Westend)]);
let wnd_at_rococo_parachains_latest: Location = wnd_at_rococo_parachains.try_into().unwrap();
AssetHubRococo::force_create_foreign_asset( AssetHubRococo::force_create_foreign_asset(
wnd_at_rococo_parachains, wnd_at_rococo_parachains.clone().try_into().unwrap(),
assets_owner.clone(), assets_owner.clone(),
false, false,
ASSET_MIN_BALANCE, ASSET_MIN_BALANCE,
vec![], vec![],
); );
PenpalA::force_create_foreign_asset( PenpalA::force_create_foreign_asset(
wnd_at_rococo_parachains, wnd_at_rococo_parachains.clone(),
assets_owner.clone(), assets_owner.clone(),
false, false,
ASSET_MIN_BALANCE, ASSET_MIN_BALANCE,
vec![], vec![],
); );
PenpalB::force_create_foreign_asset( PenpalB::force_create_foreign_asset(
wnd_at_rococo_parachains, wnd_at_rococo_parachains.clone(),
assets_owner.clone(), assets_owner.clone(),
false, false,
ASSET_MIN_BALANCE, ASSET_MIN_BALANCE,
@@ -460,13 +468,13 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
// fund Parachain's sender account // fund Parachain's sender account
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(assets_owner.clone()), <PenpalA as Chain>::RuntimeOrigin::signed(assets_owner.clone()),
roc_location, roc_location.clone(),
sender.clone(), sender.clone(),
roc_to_send * 2, roc_to_send * 2,
); );
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(assets_owner.clone()), <PenpalA as Chain>::RuntimeOrigin::signed(assets_owner.clone()),
wnd_at_rococo_parachains, wnd_at_rococo_parachains.clone(),
sender.clone(), sender.clone(),
wnd_to_send * 2, wnd_to_send * 2,
); );
@@ -474,7 +482,7 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
AssetHubRococo::fund_accounts(vec![(sov_of_sender_on_ah.clone().into(), roc_to_send * 2)]); AssetHubRococo::fund_accounts(vec![(sov_of_sender_on_ah.clone().into(), roc_to_send * 2)]);
AssetHubRococo::mint_foreign_asset( AssetHubRococo::mint_foreign_asset(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(assets_owner), <AssetHubRococo as Chain>::RuntimeOrigin::signed(assets_owner),
wnd_at_rococo_parachains, wnd_at_rococo_parachains.clone().try_into().unwrap(),
sov_of_sender_on_ah.clone(), sov_of_sender_on_ah.clone(),
wnd_to_send * 2, wnd_to_send * 2,
); );
@@ -484,10 +492,10 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
// Assets to send // Assets to send
let assets: Vec<Asset> = vec![ let assets: Vec<Asset> = vec![
(roc_location_latest.clone(), roc_to_send).into(), (roc_location.clone(), roc_to_send).into(),
(wnd_at_rococo_parachains_latest, wnd_to_send).into(), (wnd_at_rococo_parachains.clone(), wnd_to_send).into(),
]; ];
let fee_asset_id: AssetId = roc_location_latest.into(); let fee_asset_id: AssetId = roc_location.clone().into();
let fee_asset_item = assets.iter().position(|a| a.id == fee_asset_id).unwrap() as u32; let fee_asset_item = assets.iter().position(|a| a.id == fee_asset_id).unwrap() as u32;
// Init Test // Init Test
@@ -508,31 +516,37 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
// Query initial balances // Query initial balances
let sender_rocs_before = PenpalA::execute_with(|| { let sender_rocs_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(roc_location, &sender) <ForeignAssets as Inspect<_>>::balance(roc_location.clone(), &sender)
}); });
let sender_wnds_before = PenpalA::execute_with(|| { let sender_wnds_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(wnd_at_rococo_parachains, &sender) <ForeignAssets as Inspect<_>>::balance(wnd_at_rococo_parachains.clone(), &sender)
}); });
let rocs_in_sender_reserve_on_ahr_before = let rocs_in_sender_reserve_on_ahr_before =
<AssetHubRococo as Chain>::account_data_of(sov_of_sender_on_ah.clone()).free; <AssetHubRococo as Chain>::account_data_of(sov_of_sender_on_ah.clone()).free;
let wnds_in_sender_reserve_on_ahr_before = AssetHubRococo::execute_with(|| { let wnds_in_sender_reserve_on_ahr_before = AssetHubRococo::execute_with(|| {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets; type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(wnd_at_rococo_parachains, &sov_of_sender_on_ah) <Assets as Inspect<_>>::balance(
wnd_at_rococo_parachains.clone().try_into().unwrap(),
&sov_of_sender_on_ah,
)
}); });
let rocs_in_receiver_reserve_on_ahr_before = let rocs_in_receiver_reserve_on_ahr_before =
<AssetHubRococo as Chain>::account_data_of(sov_of_receiver_on_ah.clone()).free; <AssetHubRococo as Chain>::account_data_of(sov_of_receiver_on_ah.clone()).free;
let wnds_in_receiver_reserve_on_ahr_before = AssetHubRococo::execute_with(|| { let wnds_in_receiver_reserve_on_ahr_before = AssetHubRococo::execute_with(|| {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets; type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(wnd_at_rococo_parachains, &sov_of_receiver_on_ah) <Assets as Inspect<_>>::balance(
wnd_at_rococo_parachains.clone().try_into().unwrap(),
&sov_of_receiver_on_ah,
)
}); });
let receiver_rocs_before = PenpalB::execute_with(|| { let receiver_rocs_before = PenpalB::execute_with(|| {
type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets; type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(roc_location, &receiver) <ForeignAssets as Inspect<_>>::balance(roc_location.clone(), &receiver)
}); });
let receiver_wnds_before = PenpalB::execute_with(|| { let receiver_wnds_before = PenpalB::execute_with(|| {
type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets; type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(wnd_at_rococo_parachains, &receiver) <ForeignAssets as Inspect<_>>::balance(wnd_at_rococo_parachains.clone(), &receiver)
}); });
// Set assertions and dispatchables // Set assertions and dispatchables
@@ -545,21 +559,27 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
// Query final balances // Query final balances
let sender_rocs_after = PenpalA::execute_with(|| { let sender_rocs_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(roc_location, &sender) <ForeignAssets as Inspect<_>>::balance(roc_location.clone(), &sender)
}); });
let sender_wnds_after = PenpalA::execute_with(|| { let sender_wnds_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(wnd_at_rococo_parachains, &sender) <ForeignAssets as Inspect<_>>::balance(wnd_at_rococo_parachains.clone(), &sender)
}); });
let wnds_in_sender_reserve_on_ahr_after = AssetHubRococo::execute_with(|| { let wnds_in_sender_reserve_on_ahr_after = AssetHubRococo::execute_with(|| {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets; type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(wnd_at_rococo_parachains, &sov_of_sender_on_ah) <Assets as Inspect<_>>::balance(
wnd_at_rococo_parachains.clone().try_into().unwrap(),
&sov_of_sender_on_ah,
)
}); });
let rocs_in_sender_reserve_on_ahr_after = let rocs_in_sender_reserve_on_ahr_after =
<AssetHubRococo as Chain>::account_data_of(sov_of_sender_on_ah).free; <AssetHubRococo as Chain>::account_data_of(sov_of_sender_on_ah).free;
let wnds_in_receiver_reserve_on_ahr_after = AssetHubRococo::execute_with(|| { let wnds_in_receiver_reserve_on_ahr_after = AssetHubRococo::execute_with(|| {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets; type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(wnd_at_rococo_parachains, &sov_of_receiver_on_ah) <Assets as Inspect<_>>::balance(
wnd_at_rococo_parachains.clone().try_into().unwrap(),
&sov_of_receiver_on_ah,
)
}); });
let rocs_in_receiver_reserve_on_ahr_after = let rocs_in_receiver_reserve_on_ahr_after =
<AssetHubRococo as Chain>::account_data_of(sov_of_receiver_on_ah).free; <AssetHubRococo as Chain>::account_data_of(sov_of_receiver_on_ah).free;
@@ -47,7 +47,7 @@ fn para_to_relay_sender_assertions(t: ParaToRelayTest) {
RuntimeEvent::ForeignAssets( RuntimeEvent::ForeignAssets(
pallet_assets::Event::Burned { asset_id, owner, balance, .. } pallet_assets::Event::Burned { asset_id, owner, balance, .. }
) => { ) => {
asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).unwrap(), asset_id: *asset_id == RelayLocation::get(),
owner: *owner == t.sender.account_id, owner: *owner == t.sender.account_id,
balance: *balance == t.args.amount, balance: *balance == t.args.amount,
}, },
@@ -106,6 +106,7 @@ pub fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) {
pub fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) { pub fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) {
type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent; type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent;
PenpalA::assert_xcmp_queue_success(None); PenpalA::assert_xcmp_queue_success(None);
for asset in t.args.assets.into_inner().into_iter() { for asset in t.args.assets.into_inner().into_iter() {
let expected_id = asset.id.0.try_into().unwrap(); let expected_id = asset.id.0.try_into().unwrap();
@@ -125,7 +126,7 @@ pub fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) {
type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent; type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent;
PenpalA::assert_xcm_pallet_attempted_complete(None); PenpalA::assert_xcm_pallet_attempted_complete(None);
for asset in t.args.assets.into_inner().into_iter() { for asset in t.args.assets.into_inner().into_iter() {
let expected_id = asset.id.0.try_into().unwrap(); let expected_id = asset.id.0;
let asset_amount = if let Fungible(a) = asset.fun { Some(a) } else { None }.unwrap(); let asset_amount = if let Fungible(a) = asset.fun { Some(a) } else { None }.unwrap();
assert_expected_events!( assert_expected_events!(
PenpalA, PenpalA,
@@ -265,9 +266,8 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) {
fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) {
type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent; type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent;
let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let system_para_native_asset_location = RelayLocation::get();
let reservable_asset_location = let reservable_asset_location = PenpalLocalReservableFromAssetHub::get();
v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).unwrap();
PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8799))); PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8799)));
assert_expected_events!( assert_expected_events!(
PenpalA, PenpalA,
@@ -297,14 +297,13 @@ fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) {
fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) {
type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent; type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent;
let system_para_asset_location = let system_para_asset_location = PenpalLocalReservableFromAssetHub::get();
v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).unwrap();
PenpalA::assert_xcmp_queue_success(None); PenpalA::assert_xcmp_queue_success(None);
assert_expected_events!( assert_expected_events!(
PenpalA, PenpalA,
vec![ vec![
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => {
asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).unwrap(), asset_id: *asset_id == RelayLocation::get(),
owner: *owner == t.receiver.account_id, owner: *owner == t.receiver.account_id,
}, },
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => {
@@ -356,7 +355,7 @@ fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) {
PenpalA, PenpalA,
vec![ vec![
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => {
asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).unwrap(), asset_id: *asset_id == RelayLocation::get(),
owner: *owner == t.receiver.account_id, owner: *owner == t.receiver.account_id,
}, },
RuntimeEvent::MessageQueue( RuntimeEvent::MessageQueue(
@@ -576,7 +575,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() {
let amount_to_send: Balance = ROCOCO_ED * 1000; let amount_to_send: Balance = ROCOCO_ED * 1000;
// Init values fot Parachain // Init values fot Parachain
let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let relay_native_asset_location = RelayLocation::get();
let receiver = PenpalAReceiver::get(); let receiver = PenpalAReceiver::get();
// Init Test // Init Test
@@ -591,7 +590,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() {
let sender_balance_before = test.sender.balance; let sender_balance_before = test.sender.balance;
let receiver_assets_before = PenpalA::execute_with(|| { let receiver_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.into(), &receiver) <ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.clone(), &receiver)
}); });
// Set assertions and dispatchables // Set assertions and dispatchables
@@ -604,7 +603,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() {
let sender_balance_after = test.sender.balance; let sender_balance_after = test.sender.balance;
let receiver_assets_after = PenpalA::execute_with(|| { let receiver_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.into(), &receiver) <ForeignAssets as Inspect<_>>::balance(relay_native_asset_location, &receiver)
}); });
// Sender's balance is reduced by amount sent plus delivery fees // Sender's balance is reduced by amount sent plus delivery fees
@@ -626,12 +625,12 @@ fn reserve_transfer_native_asset_from_para_to_relay() {
let amount_to_send: Balance = ROCOCO_ED * 1000; let amount_to_send: Balance = ROCOCO_ED * 1000;
let assets: Assets = (Parent, amount_to_send).into(); let assets: Assets = (Parent, amount_to_send).into();
let asset_owner = PenpalAssetOwner::get(); let asset_owner = PenpalAssetOwner::get();
let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let relay_native_asset_location = RelayLocation::get();
// fund Parachain's sender account // fund Parachain's sender account
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(asset_owner), <PenpalA as Chain>::RuntimeOrigin::signed(asset_owner),
relay_native_asset_location, relay_native_asset_location.clone(),
sender.clone(), sender.clone(),
amount_to_send * 2, amount_to_send * 2,
); );
@@ -662,7 +661,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() {
// Query initial balances // Query initial balances
let sender_assets_before = PenpalA::execute_with(|| { let sender_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.into(), &sender) <ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.clone(), &sender)
}); });
let receiver_balance_before = test.receiver.balance; let receiver_balance_before = test.receiver.balance;
@@ -675,7 +674,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() {
// Query final balances // Query final balances
let sender_assets_after = PenpalA::execute_with(|| { let sender_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.into(), &sender) <ForeignAssets as Inspect<_>>::balance(relay_native_asset_location, &sender)
}); });
let receiver_balance_after = test.receiver.balance; let receiver_balance_after = test.receiver.balance;
@@ -702,7 +701,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() {
let assets: Assets = (Parent, amount_to_send).into(); let assets: Assets = (Parent, amount_to_send).into();
// Init values for Parachain // Init values for Parachain
let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let system_para_native_asset_location = RelayLocation::get();
let receiver = PenpalAReceiver::get(); let receiver = PenpalAReceiver::get();
// Init Test // Init Test
@@ -724,7 +723,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() {
let sender_balance_before = test.sender.balance; let sender_balance_before = test.sender.balance;
let receiver_assets_before = PenpalA::execute_with(|| { let receiver_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location.into(), &receiver) <ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location.clone(), &receiver)
}); });
// Set assertions and dispatchables // Set assertions and dispatchables
@@ -758,13 +757,13 @@ fn reserve_transfer_native_asset_from_para_to_system_para() {
let sender = PenpalASender::get(); let sender = PenpalASender::get();
let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000; let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000;
let assets: Assets = (Parent, amount_to_send).into(); let assets: Assets = (Parent, amount_to_send).into();
let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let system_para_native_asset_location = RelayLocation::get();
let asset_owner = PenpalAssetOwner::get(); let asset_owner = PenpalAssetOwner::get();
// fund Parachain's sender account // fund Parachain's sender account
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(asset_owner), <PenpalA as Chain>::RuntimeOrigin::signed(asset_owner),
system_para_native_asset_location, system_para_native_asset_location.clone(),
sender.clone(), sender.clone(),
amount_to_send * 2, amount_to_send * 2,
); );
@@ -795,7 +794,7 @@ fn reserve_transfer_native_asset_from_para_to_system_para() {
// Query initial balances // Query initial balances
let sender_assets_before = PenpalA::execute_with(|| { let sender_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location, &sender) <ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location.clone(), &sender)
}); });
let receiver_balance_before = test.receiver.balance; let receiver_balance_before = test.receiver.balance;
@@ -863,9 +862,8 @@ fn reserve_transfer_assets_from_system_para_to_para() {
// Init values for Parachain // Init values for Parachain
let receiver = PenpalAReceiver::get(); let receiver = PenpalAReceiver::get();
let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let system_para_native_asset_location = RelayLocation::get();
let system_para_foreign_asset_location = let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHub::get();
v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).unwrap();
// Init Test // Init Test
let para_test_args = TestContext { let para_test_args = TestContext {
@@ -890,11 +888,14 @@ fn reserve_transfer_assets_from_system_para_to_para() {
}); });
let receiver_system_native_assets_before = PenpalA::execute_with(|| { let receiver_system_native_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location, &receiver) <ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location.clone(), &receiver)
}); });
let receiver_foreign_assets_before = PenpalA::execute_with(|| { let receiver_foreign_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_foreign_asset_location, &receiver) <ForeignAssets as Inspect<_>>::balance(
system_para_foreign_asset_location.clone(),
&receiver,
)
}); });
// Set assertions and dispatchables // Set assertions and dispatchables
@@ -911,7 +912,7 @@ fn reserve_transfer_assets_from_system_para_to_para() {
}); });
let receiver_system_native_assets_after = PenpalA::execute_with(|| { let receiver_system_native_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location, &receiver) <ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location.clone(), &receiver)
}); });
let receiver_foreign_assets_after = PenpalA::execute_with(|| { let receiver_foreign_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
@@ -949,13 +950,11 @@ fn reserve_transfer_assets_from_para_to_system_para() {
let asset_amount_to_send = ASSET_HUB_ROCOCO_ED * 10000; let asset_amount_to_send = ASSET_HUB_ROCOCO_ED * 10000;
let penpal_asset_owner = PenpalAssetOwner::get(); let penpal_asset_owner = PenpalAssetOwner::get();
let penpal_asset_owner_signer = <PenpalA as Chain>::RuntimeOrigin::signed(penpal_asset_owner); let penpal_asset_owner_signer = <PenpalA as Chain>::RuntimeOrigin::signed(penpal_asset_owner);
let asset_location_on_penpal = let asset_location_on_penpal = PenpalLocalReservableFromAssetHub::get();
v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).unwrap(); let system_asset_location_on_penpal = RelayLocation::get();
let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap();
let system_asset_location_on_penpal = v3::Location::try_from(RelayLocation::get()).unwrap();
let assets: Assets = vec![ let assets: Assets = vec![
(Parent, fee_amount_to_send).into(), (Parent, fee_amount_to_send).into(),
(asset_location_on_penpal_latest, asset_amount_to_send).into(), (asset_location_on_penpal.clone(), asset_amount_to_send).into(),
] ]
.into(); .into();
let fee_asset_index = assets let fee_asset_index = assets
@@ -982,9 +981,8 @@ fn reserve_transfer_assets_from_para_to_system_para() {
let receiver = AssetHubRococoReceiver::get(); let receiver = AssetHubRococoReceiver::get();
let penpal_location_as_seen_by_ahr = AssetHubRococo::sibling_location_of(PenpalA::para_id()); let penpal_location_as_seen_by_ahr = AssetHubRococo::sibling_location_of(PenpalA::para_id());
let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_location_as_seen_by_ahr); let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_location_as_seen_by_ahr);
let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let system_para_native_asset_location = RelayLocation::get();
let system_para_foreign_asset_location = let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHub::get();
v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).unwrap();
let ah_asset_owner = AssetHubRococoAssetOwner::get(); let ah_asset_owner = AssetHubRococoAssetOwner::get();
let ah_asset_owner_signer = <AssetHubRococo as Chain>::RuntimeOrigin::signed(ah_asset_owner); let ah_asset_owner_signer = <AssetHubRococo as Chain>::RuntimeOrigin::signed(ah_asset_owner);
@@ -1019,11 +1017,11 @@ fn reserve_transfer_assets_from_para_to_system_para() {
// Query initial balances // Query initial balances
let sender_system_assets_before = PenpalA::execute_with(|| { let sender_system_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location, &sender) <ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location.clone(), &sender)
}); });
let sender_foreign_assets_before = PenpalA::execute_with(|| { let sender_foreign_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_foreign_asset_location, &sender) <ForeignAssets as Inspect<_>>::balance(system_para_foreign_asset_location.clone(), &sender)
}); });
let receiver_balance_before = test.receiver.balance; let receiver_balance_before = test.receiver.balance;
let receiver_assets_before = AssetHubRococo::execute_with(|| { let receiver_assets_before = AssetHubRococo::execute_with(|| {
@@ -1040,7 +1038,7 @@ fn reserve_transfer_assets_from_para_to_system_para() {
// Query final balances // Query final balances
let sender_system_assets_after = PenpalA::execute_with(|| { let sender_system_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location, &sender) <ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location.clone(), &sender)
}); });
let sender_foreign_assets_after = PenpalA::execute_with(|| { let sender_foreign_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
@@ -1079,14 +1077,14 @@ fn reserve_transfer_native_asset_from_para_to_para_through_relay() {
let amount_to_send: Balance = ROCOCO_ED * 10000; let amount_to_send: Balance = ROCOCO_ED * 10000;
let asset_owner = PenpalAssetOwner::get(); let asset_owner = PenpalAssetOwner::get();
let assets = (Parent, amount_to_send).into(); let assets = (Parent, amount_to_send).into();
let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let relay_native_asset_location = RelayLocation::get();
let sender_as_seen_by_relay = Rococo::child_location_of(PenpalA::para_id()); let sender_as_seen_by_relay = Rococo::child_location_of(PenpalA::para_id());
let sov_of_sender_on_relay = Rococo::sovereign_account_id_of(sender_as_seen_by_relay); let sov_of_sender_on_relay = Rococo::sovereign_account_id_of(sender_as_seen_by_relay);
// fund Parachain's sender account // fund Parachain's sender account
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(asset_owner), <PenpalA as Chain>::RuntimeOrigin::signed(asset_owner),
relay_native_asset_location, relay_native_asset_location.clone(),
sender.clone(), sender.clone(),
amount_to_send * 2, amount_to_send * 2,
); );
@@ -1108,11 +1106,11 @@ fn reserve_transfer_native_asset_from_para_to_para_through_relay() {
// Query initial balances // Query initial balances
let sender_assets_before = PenpalA::execute_with(|| { let sender_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(relay_native_asset_location, &sender) <ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.clone(), &sender)
}); });
let receiver_assets_before = PenpalB::execute_with(|| { let receiver_assets_before = PenpalB::execute_with(|| {
type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets; type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(relay_native_asset_location, &receiver) <ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.clone(), &receiver)
}); });
// Set assertions and dispatchables // Set assertions and dispatchables
@@ -1125,7 +1123,7 @@ fn reserve_transfer_native_asset_from_para_to_para_through_relay() {
// Query final balances // Query final balances
let sender_assets_after = PenpalA::execute_with(|| { let sender_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(relay_native_asset_location, &sender) <ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.clone(), &sender)
}); });
let receiver_assets_after = PenpalB::execute_with(|| { let receiver_assets_after = PenpalB::execute_with(|| {
type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets; type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets;
@@ -17,7 +17,10 @@ use crate::imports::*;
#[test] #[test]
fn swap_locally_on_chain_using_local_assets() { fn swap_locally_on_chain_using_local_assets() {
let asset_native = Box::new(asset_hub_rococo_runtime::xcm_config::TokenLocationV3::get()); let asset_native = Box::new(
v3::Location::try_from(asset_hub_rococo_runtime::xcm_config::TokenLocation::get())
.expect("conversion works"),
);
let asset_one = Box::new(v3::Location::new( let asset_one = Box::new(v3::Location::new(
0, 0,
[ [
@@ -227,11 +230,9 @@ fn swap_locally_on_chain_using_foreign_assets() {
#[test] #[test]
fn cannot_create_pool_from_pool_assets() { fn cannot_create_pool_from_pool_assets() {
let asset_native = Box::new(asset_hub_rococo_runtime::xcm_config::TokenLocationV3::get()); let asset_native = asset_hub_rococo_runtime::xcm_config::TokenLocation::get();
let mut asset_one = asset_hub_rococo_runtime::xcm_config::PoolAssetsPalletLocationV3::get(); let mut asset_one = asset_hub_rococo_runtime::xcm_config::PoolAssetsPalletLocation::get();
asset_one asset_one.append_with(GeneralIndex(ASSET_ID.into())).expect("pool assets");
.append_with(v3::Junction::GeneralIndex(ASSET_ID.into()))
.expect("pool assets");
AssetHubRococo::execute_with(|| { AssetHubRococo::execute_with(|| {
let pool_owner_account_id = asset_hub_rococo_runtime::AssetConversionOrigin::get(); let pool_owner_account_id = asset_hub_rococo_runtime::AssetConversionOrigin::get();
@@ -254,8 +255,8 @@ fn cannot_create_pool_from_pool_assets() {
assert_matches::assert_matches!( assert_matches::assert_matches!(
<AssetHubRococo as AssetHubRococoPallet>::AssetConversion::create_pool( <AssetHubRococo as AssetHubRococoPallet>::AssetConversion::create_pool(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()), <AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
asset_native, Box::new(v3::Location::try_from(asset_native).expect("conversion works")),
Box::new(asset_one), Box::new(v3::Location::try_from(asset_one).expect("conversion works")),
), ),
Err(DispatchError::Module(ModuleError{index: _, error: _, message})) => assert_eq!(message, Some("Unknown")) Err(DispatchError::Module(ModuleError{index: _, error: _, message})) => assert_eq!(message, Some("Unknown"))
); );
@@ -264,7 +265,9 @@ fn cannot_create_pool_from_pool_assets() {
#[test] #[test]
fn pay_xcm_fee_with_some_asset_swapped_for_native() { fn pay_xcm_fee_with_some_asset_swapped_for_native() {
let asset_native = asset_hub_rococo_runtime::xcm_config::TokenLocationV3::get(); let asset_native =
v3::Location::try_from(asset_hub_rococo_runtime::xcm_config::TokenLocation::get())
.expect("conversion works");
let asset_one = xcm::v3::Location { let asset_one = xcm::v3::Location {
parents: 0, parents: 0,
interior: [ interior: [
@@ -110,7 +110,7 @@ fn para_dest_assertions(t: RelayToSystemParaTest) {
fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) { fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) {
type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent; type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent;
let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let system_para_native_asset_location = RelayLocation::get();
let expected_asset_id = t.args.asset_id.unwrap(); let expected_asset_id = t.args.asset_id.unwrap();
let (_, expected_asset_amount) = let (_, expected_asset_amount) =
non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap();
@@ -203,7 +203,7 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) {
let (_, expected_asset_amount) = let (_, expected_asset_amount) =
non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap();
let checking_account = <PenpalA as PenpalAPallet>::PolkadotXcm::check_account(); let checking_account = <PenpalA as PenpalAPallet>::PolkadotXcm::check_account();
let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let system_para_native_asset_location = RelayLocation::get();
PenpalA::assert_xcmp_queue_success(None); PenpalA::assert_xcmp_queue_success(None);
@@ -420,22 +420,20 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
) { ) {
// Init values for Parachain // Init values for Parachain
let fee_amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000; let fee_amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000;
let asset_location_on_penpal = let asset_location_on_penpal = PenpalLocalTeleportableToAssetHub::get();
v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).unwrap();
let asset_id_on_penpal = match asset_location_on_penpal.last() { let asset_id_on_penpal = match asset_location_on_penpal.last() {
Some(v3::Junction::GeneralIndex(id)) => *id as u32, Some(Junction::GeneralIndex(id)) => *id as u32,
_ => unreachable!(), _ => unreachable!(),
}; };
let asset_amount_to_send = ASSET_HUB_ROCOCO_ED * 1000; let asset_amount_to_send = ASSET_HUB_ROCOCO_ED * 1000;
let asset_owner = PenpalAssetOwner::get(); let asset_owner = PenpalAssetOwner::get();
let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let system_para_native_asset_location = RelayLocation::get();
let sender = PenpalASender::get(); let sender = PenpalASender::get();
let penpal_check_account = <PenpalA as PenpalAPallet>::PolkadotXcm::check_account(); let penpal_check_account = <PenpalA as PenpalAPallet>::PolkadotXcm::check_account();
let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubRococo::para_id()); let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubRococo::para_id());
let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap();
let penpal_assets: Assets = vec![ let penpal_assets: Assets = vec![
(Parent, fee_amount_to_send).into(), (Parent, fee_amount_to_send).into(),
(asset_location_on_penpal_latest, asset_amount_to_send).into(), (asset_location_on_penpal.clone(), asset_amount_to_send).into(),
] ]
.into(); .into();
let fee_asset_index = penpal_assets let fee_asset_index = penpal_assets
@@ -447,7 +445,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
// fund Parachain's sender account // fund Parachain's sender account
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(asset_owner.clone()), <PenpalA as Chain>::RuntimeOrigin::signed(asset_owner.clone()),
system_para_native_asset_location, system_para_native_asset_location.clone(),
sender.clone(), sender.clone(),
fee_amount_to_send * 2, fee_amount_to_send * 2,
); );
@@ -471,7 +469,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
// Init values for System Parachain // Init values for System Parachain
let foreign_asset_at_asset_hub_rococo = let foreign_asset_at_asset_hub_rococo =
v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) Location::new(1, [Junction::Parachain(PenpalA::para_id().into())])
.appended_with(asset_location_on_penpal) .appended_with(asset_location_on_penpal)
.unwrap(); .unwrap();
let penpal_to_ah_beneficiary_id = AssetHubRococoReceiver::get(); let penpal_to_ah_beneficiary_id = AssetHubRococoReceiver::get();
@@ -493,7 +491,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
let penpal_sender_balance_before = PenpalA::execute_with(|| { let penpal_sender_balance_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance( <ForeignAssets as Inspect<_>>::balance(
system_para_native_asset_location, system_para_native_asset_location.clone(),
&PenpalASender::get(), &PenpalASender::get(),
) )
}); });
@@ -507,7 +505,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
let ah_receiver_assets_before = AssetHubRococo::execute_with(|| { let ah_receiver_assets_before = AssetHubRococo::execute_with(|| {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets; type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance( <Assets as Inspect<_>>::balance(
foreign_asset_at_asset_hub_rococo, foreign_asset_at_asset_hub_rococo.clone().try_into().unwrap(),
&AssetHubRococoReceiver::get(), &AssetHubRococoReceiver::get(),
) )
}); });
@@ -520,7 +518,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
let penpal_sender_balance_after = PenpalA::execute_with(|| { let penpal_sender_balance_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance( <ForeignAssets as Inspect<_>>::balance(
system_para_native_asset_location, system_para_native_asset_location.clone(),
&PenpalASender::get(), &PenpalASender::get(),
) )
}); });
@@ -534,7 +532,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
let ah_receiver_assets_after = AssetHubRococo::execute_with(|| { let ah_receiver_assets_after = AssetHubRococo::execute_with(|| {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets; type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance( <Assets as Inspect<_>>::balance(
foreign_asset_at_asset_hub_rococo, foreign_asset_at_asset_hub_rococo.clone().try_into().unwrap(),
&AssetHubRococoReceiver::get(), &AssetHubRococoReceiver::get(),
) )
}); });
@@ -562,19 +560,17 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
type ForeignAssets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets; type ForeignAssets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
assert_ok!(ForeignAssets::transfer( assert_ok!(ForeignAssets::transfer(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoReceiver::get()), <AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoReceiver::get()),
foreign_asset_at_asset_hub_rococo, foreign_asset_at_asset_hub_rococo.clone().try_into().unwrap(),
AssetHubRococoSender::get().into(), AssetHubRococoSender::get().into(),
asset_amount_to_send, asset_amount_to_send,
)); ));
}); });
let foreign_asset_at_asset_hub_rococo_latest: Location =
foreign_asset_at_asset_hub_rococo.try_into().unwrap();
let ah_to_penpal_beneficiary_id = PenpalAReceiver::get(); let ah_to_penpal_beneficiary_id = PenpalAReceiver::get();
let penpal_as_seen_by_ah = AssetHubRococo::sibling_location_of(PenpalA::para_id()); let penpal_as_seen_by_ah = AssetHubRococo::sibling_location_of(PenpalA::para_id());
let ah_assets: Assets = vec![ let ah_assets: Assets = vec![
(Parent, fee_amount_to_send).into(), (Parent, fee_amount_to_send).into(),
(foreign_asset_at_asset_hub_rococo_latest, asset_amount_to_send).into(), (foreign_asset_at_asset_hub_rococo.clone(), asset_amount_to_send).into(),
] ]
.into(); .into();
let fee_asset_index = ah_assets let fee_asset_index = ah_assets
@@ -602,7 +598,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
let penpal_receiver_balance_before = PenpalA::execute_with(|| { let penpal_receiver_balance_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance( <ForeignAssets as Inspect<_>>::balance(
system_para_native_asset_location, system_para_native_asset_location.clone(),
&PenpalAReceiver::get(), &PenpalAReceiver::get(),
) )
}); });
@@ -610,7 +606,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
let ah_sender_assets_before = AssetHubRococo::execute_with(|| { let ah_sender_assets_before = AssetHubRococo::execute_with(|| {
type ForeignAssets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets; type ForeignAssets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance( <ForeignAssets as Inspect<_>>::balance(
foreign_asset_at_asset_hub_rococo, foreign_asset_at_asset_hub_rococo.clone().try_into().unwrap(),
&AssetHubRococoSender::get(), &AssetHubRococoSender::get(),
) )
}); });
@@ -636,7 +632,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
let ah_sender_assets_after = AssetHubRococo::execute_with(|| { let ah_sender_assets_after = AssetHubRococo::execute_with(|| {
type ForeignAssets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets; type ForeignAssets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance( <ForeignAssets as Inspect<_>>::balance(
foreign_asset_at_asset_hub_rococo, foreign_asset_at_asset_hub_rococo.try_into().unwrap(),
&AssetHubRococoSender::get(), &AssetHubRococoSender::get(),
) )
}); });
@@ -137,14 +137,13 @@ fn transfer_foreign_assets_from_asset_hub_to_para() {
let destination = AssetHubWestend::sibling_location_of(PenpalA::para_id()); let destination = AssetHubWestend::sibling_location_of(PenpalA::para_id());
let sender = AssetHubWestendSender::get(); let sender = AssetHubWestendSender::get();
let native_amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000; let native_amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000;
let native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let native_asset_location = RelayLocation::get();
let receiver = PenpalAReceiver::get(); let receiver = PenpalAReceiver::get();
let assets_owner = PenpalAssetOwner::get(); let assets_owner = PenpalAssetOwner::get();
// Foreign asset used: bridged ROC // Foreign asset used: bridged ROC
let foreign_amount_to_send = ASSET_HUB_WESTEND_ED * 10_000_000; let foreign_amount_to_send = ASSET_HUB_WESTEND_ED * 10_000_000;
let roc_at_westend_parachains = let roc_at_westend_parachains =
v3::Location::new(2, [v3::Junction::GlobalConsensus(v3::NetworkId::Rococo)]); Location::new(2, [Junction::GlobalConsensus(NetworkId::Rococo)]);
let roc_at_westend_parachains_latest: Location = roc_at_westend_parachains.try_into().unwrap();
// Configure destination chain to trust AH as reserve of ROC // Configure destination chain to trust AH as reserve of ROC
PenpalA::execute_with(|| { PenpalA::execute_with(|| {
@@ -157,14 +156,14 @@ fn transfer_foreign_assets_from_asset_hub_to_para() {
)); ));
}); });
PenpalA::force_create_foreign_asset( PenpalA::force_create_foreign_asset(
roc_at_westend_parachains, roc_at_westend_parachains.clone(),
assets_owner.clone(), assets_owner.clone(),
false, false,
ASSET_MIN_BALANCE, ASSET_MIN_BALANCE,
vec![], vec![],
); );
AssetHubWestend::force_create_foreign_asset( AssetHubWestend::force_create_foreign_asset(
roc_at_westend_parachains, roc_at_westend_parachains.clone().try_into().unwrap(),
assets_owner.clone(), assets_owner.clone(),
false, false,
ASSET_MIN_BALANCE, ASSET_MIN_BALANCE,
@@ -172,7 +171,7 @@ fn transfer_foreign_assets_from_asset_hub_to_para() {
); );
AssetHubWestend::mint_foreign_asset( AssetHubWestend::mint_foreign_asset(
<AssetHubWestend as Chain>::RuntimeOrigin::signed(assets_owner), <AssetHubWestend as Chain>::RuntimeOrigin::signed(assets_owner),
roc_at_westend_parachains, roc_at_westend_parachains.clone().try_into().unwrap(),
sender.clone(), sender.clone(),
foreign_amount_to_send * 2, foreign_amount_to_send * 2,
); );
@@ -180,7 +179,7 @@ fn transfer_foreign_assets_from_asset_hub_to_para() {
// Assets to send // Assets to send
let assets: Vec<Asset> = vec![ let assets: Vec<Asset> = vec![
(Parent, native_amount_to_send).into(), (Parent, native_amount_to_send).into(),
(roc_at_westend_parachains_latest, foreign_amount_to_send).into(), (roc_at_westend_parachains.clone(), foreign_amount_to_send).into(),
]; ];
let fee_asset_id = AssetId(Parent.into()); let fee_asset_id = AssetId(Parent.into());
let fee_asset_item = assets.iter().position(|a| a.id == fee_asset_id).unwrap() as u32; let fee_asset_item = assets.iter().position(|a| a.id == fee_asset_id).unwrap() as u32;
@@ -204,15 +203,18 @@ fn transfer_foreign_assets_from_asset_hub_to_para() {
let sender_balance_before = test.sender.balance; let sender_balance_before = test.sender.balance;
let sender_rocs_before = AssetHubWestend::execute_with(|| { let sender_rocs_before = AssetHubWestend::execute_with(|| {
type ForeignAssets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets; type ForeignAssets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains, &sender) <ForeignAssets as Inspect<_>>::balance(
roc_at_westend_parachains.clone().try_into().unwrap(),
&sender,
)
}); });
let receiver_assets_before = PenpalA::execute_with(|| { let receiver_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(native_asset_location.into(), &receiver) <ForeignAssets as Inspect<_>>::balance(native_asset_location.clone(), &receiver)
}); });
let receiver_rocs_before = PenpalA::execute_with(|| { let receiver_rocs_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains, &receiver) <ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains.clone(), &receiver)
}); });
// Set assertions and dispatchables // Set assertions and dispatchables
@@ -225,7 +227,10 @@ fn transfer_foreign_assets_from_asset_hub_to_para() {
let sender_balance_after = test.sender.balance; let sender_balance_after = test.sender.balance;
let sender_rocs_after = AssetHubWestend::execute_with(|| { let sender_rocs_after = AssetHubWestend::execute_with(|| {
type ForeignAssets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets; type ForeignAssets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains, &sender) <ForeignAssets as Inspect<_>>::balance(
roc_at_westend_parachains.clone().try_into().unwrap(),
&sender,
)
}); });
let receiver_assets_after = PenpalA::execute_with(|| { let receiver_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
@@ -262,14 +267,13 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
let destination = PenpalA::sibling_location_of(AssetHubWestend::para_id()); let destination = PenpalA::sibling_location_of(AssetHubWestend::para_id());
let sender = PenpalASender::get(); let sender = PenpalASender::get();
let native_amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 10000; let native_amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 10000;
let native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let native_asset_location = RelayLocation::get();
let assets_owner = PenpalAssetOwner::get(); let assets_owner = PenpalAssetOwner::get();
// Foreign asset used: bridged ROC // Foreign asset used: bridged ROC
let foreign_amount_to_send = ASSET_HUB_WESTEND_ED * 10_000_000; let foreign_amount_to_send = ASSET_HUB_WESTEND_ED * 10_000_000;
let roc_at_westend_parachains = let roc_at_westend_parachains =
v3::Location::new(2, [v3::Junction::GlobalConsensus(v3::NetworkId::Rococo)]); Location::new(2, [Junction::GlobalConsensus(NetworkId::Rococo)]);
let roc_at_westend_parachains_latest: Location = roc_at_westend_parachains.try_into().unwrap();
// Configure destination chain to trust AH as reserve of ROC // Configure destination chain to trust AH as reserve of ROC
PenpalA::execute_with(|| { PenpalA::execute_with(|| {
@@ -282,14 +286,14 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
)); ));
}); });
PenpalA::force_create_foreign_asset( PenpalA::force_create_foreign_asset(
roc_at_westend_parachains, roc_at_westend_parachains.clone(),
assets_owner.clone(), assets_owner.clone(),
false, false,
ASSET_MIN_BALANCE, ASSET_MIN_BALANCE,
vec![], vec![],
); );
AssetHubWestend::force_create_foreign_asset( AssetHubWestend::force_create_foreign_asset(
roc_at_westend_parachains, roc_at_westend_parachains.clone().try_into().unwrap(),
assets_owner.clone(), assets_owner.clone(),
false, false,
ASSET_MIN_BALANCE, ASSET_MIN_BALANCE,
@@ -299,13 +303,13 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
// fund Parachain's sender account // fund Parachain's sender account
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(assets_owner.clone()), <PenpalA as Chain>::RuntimeOrigin::signed(assets_owner.clone()),
native_asset_location, native_asset_location.clone(),
sender.clone(), sender.clone(),
native_amount_to_send * 2, native_amount_to_send * 2,
); );
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(assets_owner.clone()), <PenpalA as Chain>::RuntimeOrigin::signed(assets_owner.clone()),
roc_at_westend_parachains, roc_at_westend_parachains.clone(),
sender.clone(), sender.clone(),
foreign_amount_to_send * 2, foreign_amount_to_send * 2,
); );
@@ -323,7 +327,7 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
)]); )]);
AssetHubWestend::mint_foreign_asset( AssetHubWestend::mint_foreign_asset(
<AssetHubWestend as Chain>::RuntimeOrigin::signed(assets_owner), <AssetHubWestend as Chain>::RuntimeOrigin::signed(assets_owner),
roc_at_westend_parachains, roc_at_westend_parachains.clone().try_into().unwrap(),
sov_penpal_on_ahr, sov_penpal_on_ahr,
foreign_amount_to_send * 2, foreign_amount_to_send * 2,
); );
@@ -331,7 +335,7 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
// Assets to send // Assets to send
let assets: Vec<Asset> = vec![ let assets: Vec<Asset> = vec![
(Parent, native_amount_to_send).into(), (Parent, native_amount_to_send).into(),
(roc_at_westend_parachains_latest, foreign_amount_to_send).into(), (roc_at_westend_parachains.clone(), foreign_amount_to_send).into(),
]; ];
let fee_asset_id = AssetId(Parent.into()); let fee_asset_id = AssetId(Parent.into());
let fee_asset_item = assets.iter().position(|a| a.id == fee_asset_id).unwrap() as u32; let fee_asset_item = assets.iter().position(|a| a.id == fee_asset_id).unwrap() as u32;
@@ -354,16 +358,19 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
// Query initial balances // Query initial balances
let sender_native_before = PenpalA::execute_with(|| { let sender_native_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(native_asset_location, &sender) <ForeignAssets as Inspect<_>>::balance(native_asset_location.clone(), &sender)
}); });
let sender_rocs_before = PenpalA::execute_with(|| { let sender_rocs_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains, &sender) <ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains.clone(), &sender)
}); });
let receiver_native_before = test.receiver.balance; let receiver_native_before = test.receiver.balance;
let receiver_rocs_before = AssetHubWestend::execute_with(|| { let receiver_rocs_before = AssetHubWestend::execute_with(|| {
type ForeignAssets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets; type ForeignAssets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains, &receiver) <ForeignAssets as Inspect<_>>::balance(
roc_at_westend_parachains.clone().try_into().unwrap(),
&receiver,
)
}); });
// Set assertions and dispatchables // Set assertions and dispatchables
@@ -379,12 +386,15 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
}); });
let sender_rocs_after = PenpalA::execute_with(|| { let sender_rocs_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains, &sender) <ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains.clone(), &sender)
}); });
let receiver_native_after = test.receiver.balance; let receiver_native_after = test.receiver.balance;
let receiver_rocs_after = AssetHubWestend::execute_with(|| { let receiver_rocs_after = AssetHubWestend::execute_with(|| {
type ForeignAssets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets; type ForeignAssets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains, &receiver) <ForeignAssets as Inspect<_>>::balance(
roc_at_westend_parachains.try_into().unwrap(),
&receiver,
)
}); });
// Sender's balance is reduced by amount sent plus delivery fees // Sender's balance is reduced by amount sent plus delivery fees
@@ -413,8 +423,7 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
let sender = PenpalASender::get(); let sender = PenpalASender::get();
let wnd_to_send: Balance = WESTEND_ED * 10000; let wnd_to_send: Balance = WESTEND_ED * 10000;
let assets_owner = PenpalAssetOwner::get(); let assets_owner = PenpalAssetOwner::get();
let wnd_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let wnd_location = RelayLocation::get();
let wnd_location_latest: Location = wnd_location.try_into().unwrap();
let sender_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalA::para_id()); let sender_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalA::para_id());
let sov_of_sender_on_ah = AssetHubWestend::sovereign_account_id_of(sender_as_seen_by_ah); let sov_of_sender_on_ah = AssetHubWestend::sovereign_account_id_of(sender_as_seen_by_ah);
let receiver_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalB::para_id()); let receiver_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalB::para_id());
@@ -434,24 +443,23 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
// Register ROC as foreign asset and transfer it around the Westend ecosystem // Register ROC as foreign asset and transfer it around the Westend ecosystem
let roc_at_westend_parachains = let roc_at_westend_parachains =
v3::Location::new(2, [v3::Junction::GlobalConsensus(v3::NetworkId::Rococo)]); Location::new(2, [Junction::GlobalConsensus(NetworkId::Rococo)]);
let roc_at_westend_parachains_latest: Location = roc_at_westend_parachains.try_into().unwrap();
AssetHubWestend::force_create_foreign_asset( AssetHubWestend::force_create_foreign_asset(
roc_at_westend_parachains, roc_at_westend_parachains.clone().try_into().unwrap(),
assets_owner.clone(), assets_owner.clone(),
false, false,
ASSET_MIN_BALANCE, ASSET_MIN_BALANCE,
vec![], vec![],
); );
PenpalA::force_create_foreign_asset( PenpalA::force_create_foreign_asset(
roc_at_westend_parachains, roc_at_westend_parachains.clone(),
assets_owner.clone(), assets_owner.clone(),
false, false,
ASSET_MIN_BALANCE, ASSET_MIN_BALANCE,
vec![], vec![],
); );
PenpalB::force_create_foreign_asset( PenpalB::force_create_foreign_asset(
roc_at_westend_parachains, roc_at_westend_parachains.clone(),
assets_owner.clone(), assets_owner.clone(),
false, false,
ASSET_MIN_BALANCE, ASSET_MIN_BALANCE,
@@ -461,13 +469,13 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
// fund Parachain's sender account // fund Parachain's sender account
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(assets_owner.clone()), <PenpalA as Chain>::RuntimeOrigin::signed(assets_owner.clone()),
wnd_location, wnd_location.clone(),
sender.clone(), sender.clone(),
wnd_to_send * 2, wnd_to_send * 2,
); );
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(assets_owner.clone()), <PenpalA as Chain>::RuntimeOrigin::signed(assets_owner.clone()),
roc_at_westend_parachains, roc_at_westend_parachains.clone(),
sender.clone(), sender.clone(),
roc_to_send * 2, roc_to_send * 2,
); );
@@ -475,7 +483,7 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
AssetHubWestend::fund_accounts(vec![(sov_of_sender_on_ah.clone().into(), wnd_to_send * 2)]); AssetHubWestend::fund_accounts(vec![(sov_of_sender_on_ah.clone().into(), wnd_to_send * 2)]);
AssetHubWestend::mint_foreign_asset( AssetHubWestend::mint_foreign_asset(
<AssetHubWestend as Chain>::RuntimeOrigin::signed(assets_owner), <AssetHubWestend as Chain>::RuntimeOrigin::signed(assets_owner),
roc_at_westend_parachains, roc_at_westend_parachains.clone().try_into().unwrap(),
sov_of_sender_on_ah.clone(), sov_of_sender_on_ah.clone(),
roc_to_send * 2, roc_to_send * 2,
); );
@@ -485,10 +493,10 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
// Assets to send // Assets to send
let assets: Vec<Asset> = vec![ let assets: Vec<Asset> = vec![
(wnd_location_latest.clone(), wnd_to_send).into(), (wnd_location.clone(), wnd_to_send).into(),
(roc_at_westend_parachains_latest, roc_to_send).into(), (roc_at_westend_parachains.clone(), roc_to_send).into(),
]; ];
let fee_asset_id: AssetId = wnd_location_latest.into(); let fee_asset_id: AssetId = wnd_location.clone().into();
let fee_asset_item = assets.iter().position(|a| a.id == fee_asset_id).unwrap() as u32; let fee_asset_item = assets.iter().position(|a| a.id == fee_asset_id).unwrap() as u32;
// Init Test // Init Test
@@ -509,31 +517,37 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
// Query initial balances // Query initial balances
let sender_wnds_before = PenpalA::execute_with(|| { let sender_wnds_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(wnd_location, &sender) <ForeignAssets as Inspect<_>>::balance(wnd_location.clone(), &sender)
}); });
let sender_rocs_before = PenpalA::execute_with(|| { let sender_rocs_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains, &sender) <ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains.clone(), &sender)
}); });
let wnds_in_sender_reserve_on_ah_before = let wnds_in_sender_reserve_on_ah_before =
<AssetHubWestend as Chain>::account_data_of(sov_of_sender_on_ah.clone()).free; <AssetHubWestend as Chain>::account_data_of(sov_of_sender_on_ah.clone()).free;
let rocs_in_sender_reserve_on_ah_before = AssetHubWestend::execute_with(|| { let rocs_in_sender_reserve_on_ah_before = AssetHubWestend::execute_with(|| {
type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets; type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(roc_at_westend_parachains, &sov_of_sender_on_ah) <Assets as Inspect<_>>::balance(
roc_at_westend_parachains.clone().try_into().unwrap(),
&sov_of_sender_on_ah,
)
}); });
let wnds_in_receiver_reserve_on_ah_before = let wnds_in_receiver_reserve_on_ah_before =
<AssetHubWestend as Chain>::account_data_of(sov_of_receiver_on_ah.clone()).free; <AssetHubWestend as Chain>::account_data_of(sov_of_receiver_on_ah.clone()).free;
let rocs_in_receiver_reserve_on_ah_before = AssetHubWestend::execute_with(|| { let rocs_in_receiver_reserve_on_ah_before = AssetHubWestend::execute_with(|| {
type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets; type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(roc_at_westend_parachains, &sov_of_receiver_on_ah) <Assets as Inspect<_>>::balance(
roc_at_westend_parachains.clone().try_into().unwrap(),
&sov_of_receiver_on_ah,
)
}); });
let receiver_wnds_before = PenpalB::execute_with(|| { let receiver_wnds_before = PenpalB::execute_with(|| {
type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets; type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(wnd_location, &receiver) <ForeignAssets as Inspect<_>>::balance(wnd_location.clone(), &receiver)
}); });
let receiver_rocs_before = PenpalB::execute_with(|| { let receiver_rocs_before = PenpalB::execute_with(|| {
type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets; type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains, &receiver) <ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains.clone(), &receiver)
}); });
// Set assertions and dispatchables // Set assertions and dispatchables
@@ -546,21 +560,27 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
// Query final balances // Query final balances
let sender_wnds_after = PenpalA::execute_with(|| { let sender_wnds_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(wnd_location, &sender) <ForeignAssets as Inspect<_>>::balance(wnd_location.clone(), &sender)
}); });
let sender_rocs_after = PenpalA::execute_with(|| { let sender_rocs_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains, &sender) <ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains.clone(), &sender)
}); });
let rocs_in_sender_reserve_on_ah_after = AssetHubWestend::execute_with(|| { let rocs_in_sender_reserve_on_ah_after = AssetHubWestend::execute_with(|| {
type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets; type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(roc_at_westend_parachains, &sov_of_sender_on_ah) <Assets as Inspect<_>>::balance(
roc_at_westend_parachains.clone().try_into().unwrap(),
&sov_of_sender_on_ah,
)
}); });
let wnds_in_sender_reserve_on_ah_after = let wnds_in_sender_reserve_on_ah_after =
<AssetHubWestend as Chain>::account_data_of(sov_of_sender_on_ah).free; <AssetHubWestend as Chain>::account_data_of(sov_of_sender_on_ah).free;
let rocs_in_receiver_reserve_on_ah_after = AssetHubWestend::execute_with(|| { let rocs_in_receiver_reserve_on_ah_after = AssetHubWestend::execute_with(|| {
type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets; type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(roc_at_westend_parachains, &sov_of_receiver_on_ah) <Assets as Inspect<_>>::balance(
roc_at_westend_parachains.clone().try_into().unwrap(),
&sov_of_receiver_on_ah,
)
}); });
let wnds_in_receiver_reserve_on_ah_after = let wnds_in_receiver_reserve_on_ah_after =
<AssetHubWestend as Chain>::account_data_of(sov_of_receiver_on_ah).free; <AssetHubWestend as Chain>::account_data_of(sov_of_receiver_on_ah).free;
@@ -47,7 +47,7 @@ fn para_to_relay_sender_assertions(t: ParaToRelayTest) {
RuntimeEvent::ForeignAssets( RuntimeEvent::ForeignAssets(
pallet_assets::Event::Burned { asset_id, owner, balance, .. } pallet_assets::Event::Burned { asset_id, owner, balance, .. }
) => { ) => {
asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).unwrap(), asset_id: *asset_id == RelayLocation::get(),
owner: *owner == t.sender.account_id, owner: *owner == t.sender.account_id,
balance: *balance == t.args.amount, balance: *balance == t.args.amount,
}, },
@@ -106,6 +106,7 @@ pub fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) {
pub fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) { pub fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) {
type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent; type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent;
PenpalA::assert_xcmp_queue_success(None); PenpalA::assert_xcmp_queue_success(None);
for asset in t.args.assets.into_inner().into_iter() { for asset in t.args.assets.into_inner().into_iter() {
let expected_id = asset.id.0.try_into().unwrap(); let expected_id = asset.id.0.try_into().unwrap();
@@ -125,7 +126,7 @@ pub fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) {
type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent; type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent;
PenpalA::assert_xcm_pallet_attempted_complete(None); PenpalA::assert_xcm_pallet_attempted_complete(None);
for asset in t.args.assets.into_inner().into_iter() { for asset in t.args.assets.into_inner().into_iter() {
let expected_id = asset.id.0.try_into().unwrap(); let expected_id = asset.id.0;
let asset_amount = if let Fungible(a) = asset.fun { Some(a) } else { None }.unwrap(); let asset_amount = if let Fungible(a) = asset.fun { Some(a) } else { None }.unwrap();
assert_expected_events!( assert_expected_events!(
PenpalA, PenpalA,
@@ -265,9 +266,8 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) {
fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) {
type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent; type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent;
let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let system_para_native_asset_location = RelayLocation::get();
let reservable_asset_location = let reservable_asset_location = PenpalLocalReservableFromAssetHub::get();
v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).unwrap();
PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8799))); PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8799)));
assert_expected_events!( assert_expected_events!(
PenpalA, PenpalA,
@@ -297,14 +297,13 @@ fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) {
fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) {
type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent; type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent;
let system_para_asset_location = let system_para_asset_location = PenpalLocalReservableFromAssetHub::get();
v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).unwrap();
PenpalA::assert_xcmp_queue_success(None); PenpalA::assert_xcmp_queue_success(None);
assert_expected_events!( assert_expected_events!(
PenpalA, PenpalA,
vec![ vec![
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => {
asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).unwrap(), asset_id: *asset_id == RelayLocation::get(),
owner: *owner == t.receiver.account_id, owner: *owner == t.receiver.account_id,
}, },
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => {
@@ -356,7 +355,7 @@ fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) {
PenpalA, PenpalA,
vec![ vec![
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => {
asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).unwrap(), asset_id: *asset_id == RelayLocation::get(),
owner: *owner == t.receiver.account_id, owner: *owner == t.receiver.account_id,
}, },
RuntimeEvent::MessageQueue( RuntimeEvent::MessageQueue(
@@ -576,7 +575,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() {
let amount_to_send: Balance = WESTEND_ED * 1000; let amount_to_send: Balance = WESTEND_ED * 1000;
// Init values fot Parachain // Init values fot Parachain
let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let relay_native_asset_location = RelayLocation::get();
let receiver = PenpalAReceiver::get(); let receiver = PenpalAReceiver::get();
// Init Test // Init Test
@@ -591,7 +590,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() {
let sender_balance_before = test.sender.balance; let sender_balance_before = test.sender.balance;
let receiver_assets_before = PenpalA::execute_with(|| { let receiver_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.into(), &receiver) <ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.clone(), &receiver)
}); });
// Set assertions and dispatchables // Set assertions and dispatchables
@@ -604,7 +603,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() {
let sender_balance_after = test.sender.balance; let sender_balance_after = test.sender.balance;
let receiver_assets_after = PenpalA::execute_with(|| { let receiver_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.into(), &receiver) <ForeignAssets as Inspect<_>>::balance(relay_native_asset_location, &receiver)
}); });
// Sender's balance is reduced by amount sent plus delivery fees // Sender's balance is reduced by amount sent plus delivery fees
@@ -626,12 +625,12 @@ fn reserve_transfer_native_asset_from_para_to_relay() {
let amount_to_send: Balance = WESTEND_ED * 1000; let amount_to_send: Balance = WESTEND_ED * 1000;
let assets: Assets = (Parent, amount_to_send).into(); let assets: Assets = (Parent, amount_to_send).into();
let asset_owner = PenpalAssetOwner::get(); let asset_owner = PenpalAssetOwner::get();
let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let relay_native_asset_location = RelayLocation::get();
// fund Parachain's sender account // fund Parachain's sender account
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(asset_owner), <PenpalA as Chain>::RuntimeOrigin::signed(asset_owner),
relay_native_asset_location, relay_native_asset_location.clone(),
sender.clone(), sender.clone(),
amount_to_send * 2, amount_to_send * 2,
); );
@@ -662,7 +661,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() {
// Query initial balances // Query initial balances
let sender_assets_before = PenpalA::execute_with(|| { let sender_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.into(), &sender) <ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.clone(), &sender)
}); });
let receiver_balance_before = test.receiver.balance; let receiver_balance_before = test.receiver.balance;
@@ -675,7 +674,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() {
// Query final balances // Query final balances
let sender_assets_after = PenpalA::execute_with(|| { let sender_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.into(), &sender) <ForeignAssets as Inspect<_>>::balance(relay_native_asset_location, &sender)
}); });
let receiver_balance_after = test.receiver.balance; let receiver_balance_after = test.receiver.balance;
@@ -702,7 +701,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() {
let assets: Assets = (Parent, amount_to_send).into(); let assets: Assets = (Parent, amount_to_send).into();
// Init values for Parachain // Init values for Parachain
let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let system_para_native_asset_location = RelayLocation::get();
let receiver = PenpalAReceiver::get(); let receiver = PenpalAReceiver::get();
// Init Test // Init Test
@@ -724,7 +723,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() {
let sender_balance_before = test.sender.balance; let sender_balance_before = test.sender.balance;
let receiver_assets_before = PenpalA::execute_with(|| { let receiver_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location.into(), &receiver) <ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location.clone(), &receiver)
}); });
// Set assertions and dispatchables // Set assertions and dispatchables
@@ -758,13 +757,13 @@ fn reserve_transfer_native_asset_from_para_to_system_para() {
let sender = PenpalASender::get(); let sender = PenpalASender::get();
let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000; let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000;
let assets: Assets = (Parent, amount_to_send).into(); let assets: Assets = (Parent, amount_to_send).into();
let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let system_para_native_asset_location = RelayLocation::get();
let asset_owner = PenpalAssetOwner::get(); let asset_owner = PenpalAssetOwner::get();
// fund Parachain's sender account // fund Parachain's sender account
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(asset_owner), <PenpalA as Chain>::RuntimeOrigin::signed(asset_owner),
system_para_native_asset_location, system_para_native_asset_location.clone(),
sender.clone(), sender.clone(),
amount_to_send * 2, amount_to_send * 2,
); );
@@ -796,7 +795,7 @@ fn reserve_transfer_native_asset_from_para_to_system_para() {
// Query initial balances // Query initial balances
let sender_assets_before = PenpalA::execute_with(|| { let sender_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location, &sender) <ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location.clone(), &sender)
}); });
let receiver_balance_before = test.receiver.balance; let receiver_balance_before = test.receiver.balance;
@@ -864,9 +863,8 @@ fn reserve_transfer_assets_from_system_para_to_para() {
// Init values for Parachain // Init values for Parachain
let receiver = PenpalAReceiver::get(); let receiver = PenpalAReceiver::get();
let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let system_para_native_asset_location = RelayLocation::get();
let system_para_foreign_asset_location = let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHub::get();
v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).unwrap();
// Init Test // Init Test
let para_test_args = TestContext { let para_test_args = TestContext {
@@ -891,11 +889,14 @@ fn reserve_transfer_assets_from_system_para_to_para() {
}); });
let receiver_system_native_assets_before = PenpalA::execute_with(|| { let receiver_system_native_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location, &receiver) <ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location.clone(), &receiver)
}); });
let receiver_foreign_assets_before = PenpalA::execute_with(|| { let receiver_foreign_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_foreign_asset_location, &receiver) <ForeignAssets as Inspect<_>>::balance(
system_para_foreign_asset_location.clone(),
&receiver,
)
}); });
// Set assertions and dispatchables // Set assertions and dispatchables
@@ -950,13 +951,11 @@ fn reserve_transfer_assets_from_para_to_system_para() {
let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 100; let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 100;
let penpal_asset_owner = PenpalAssetOwner::get(); let penpal_asset_owner = PenpalAssetOwner::get();
let penpal_asset_owner_signer = <PenpalA as Chain>::RuntimeOrigin::signed(penpal_asset_owner); let penpal_asset_owner_signer = <PenpalA as Chain>::RuntimeOrigin::signed(penpal_asset_owner);
let asset_location_on_penpal = let asset_location_on_penpal = PenpalLocalReservableFromAssetHub::get();
v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).unwrap(); let system_asset_location_on_penpal = RelayLocation::get();
let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap();
let system_asset_location_on_penpal = v3::Location::try_from(RelayLocation::get()).unwrap();
let assets: Assets = vec![ let assets: Assets = vec![
(Parent, fee_amount_to_send).into(), (Parent, fee_amount_to_send).into(),
(asset_location_on_penpal_latest, asset_amount_to_send).into(), (asset_location_on_penpal.clone(), asset_amount_to_send).into(),
] ]
.into(); .into();
let fee_asset_index = assets let fee_asset_index = assets
@@ -984,9 +983,8 @@ fn reserve_transfer_assets_from_para_to_system_para() {
let penpal_location_as_seen_by_ahr = AssetHubWestend::sibling_location_of(PenpalA::para_id()); let penpal_location_as_seen_by_ahr = AssetHubWestend::sibling_location_of(PenpalA::para_id());
let sov_penpal_on_ahr = let sov_penpal_on_ahr =
AssetHubWestend::sovereign_account_id_of(penpal_location_as_seen_by_ahr); AssetHubWestend::sovereign_account_id_of(penpal_location_as_seen_by_ahr);
let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let system_para_native_asset_location = RelayLocation::get();
let system_para_foreign_asset_location = let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHub::get();
v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).unwrap();
let ah_asset_owner = AssetHubWestendAssetOwner::get(); let ah_asset_owner = AssetHubWestendAssetOwner::get();
let ah_asset_owner_signer = <AssetHubWestend as Chain>::RuntimeOrigin::signed(ah_asset_owner); let ah_asset_owner_signer = <AssetHubWestend as Chain>::RuntimeOrigin::signed(ah_asset_owner);
@@ -1021,11 +1019,11 @@ fn reserve_transfer_assets_from_para_to_system_para() {
// Query initial balances // Query initial balances
let sender_system_assets_before = PenpalA::execute_with(|| { let sender_system_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location, &sender) <ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location.clone(), &sender)
}); });
let sender_foreign_assets_before = PenpalA::execute_with(|| { let sender_foreign_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_foreign_asset_location, &sender) <ForeignAssets as Inspect<_>>::balance(system_para_foreign_asset_location.clone(), &sender)
}); });
let receiver_balance_before = test.receiver.balance; let receiver_balance_before = test.receiver.balance;
let receiver_assets_before = AssetHubWestend::execute_with(|| { let receiver_assets_before = AssetHubWestend::execute_with(|| {
@@ -1081,14 +1079,14 @@ fn reserve_transfer_native_asset_from_para_to_para_through_relay() {
let amount_to_send: Balance = WESTEND_ED * 10000; let amount_to_send: Balance = WESTEND_ED * 10000;
let asset_owner = PenpalAssetOwner::get(); let asset_owner = PenpalAssetOwner::get();
let assets = (Parent, amount_to_send).into(); let assets = (Parent, amount_to_send).into();
let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let relay_native_asset_location = RelayLocation::get();
let sender_as_seen_by_relay = Westend::child_location_of(PenpalA::para_id()); let sender_as_seen_by_relay = Westend::child_location_of(PenpalA::para_id());
let sov_of_sender_on_relay = Westend::sovereign_account_id_of(sender_as_seen_by_relay); let sov_of_sender_on_relay = Westend::sovereign_account_id_of(sender_as_seen_by_relay);
// fund Parachain's sender account // fund Parachain's sender account
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(asset_owner), <PenpalA as Chain>::RuntimeOrigin::signed(asset_owner),
relay_native_asset_location, relay_native_asset_location.clone(),
sender.clone(), sender.clone(),
amount_to_send * 2, amount_to_send * 2,
); );
@@ -1110,11 +1108,11 @@ fn reserve_transfer_native_asset_from_para_to_para_through_relay() {
// Query initial balances // Query initial balances
let sender_assets_before = PenpalA::execute_with(|| { let sender_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(relay_native_asset_location, &sender) <ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.clone(), &sender)
}); });
let receiver_assets_before = PenpalB::execute_with(|| { let receiver_assets_before = PenpalB::execute_with(|| {
type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets; type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(relay_native_asset_location, &receiver) <ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.clone(), &receiver)
}); });
// Set assertions and dispatchables // Set assertions and dispatchables
@@ -1127,7 +1125,7 @@ fn reserve_transfer_native_asset_from_para_to_para_through_relay() {
// Query final balances // Query final balances
let sender_assets_after = PenpalA::execute_with(|| { let sender_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(relay_native_asset_location, &sender) <ForeignAssets as Inspect<_>>::balance(relay_native_asset_location.clone(), &sender)
}); });
let receiver_assets_after = PenpalB::execute_with(|| { let receiver_assets_after = PenpalB::execute_with(|| {
type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets; type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets;
@@ -17,7 +17,10 @@ use crate::imports::*;
#[test] #[test]
fn swap_locally_on_chain_using_local_assets() { fn swap_locally_on_chain_using_local_assets() {
let asset_native = Box::new(asset_hub_westend_runtime::xcm_config::WestendLocationV3::get()); let asset_native = Box::new(
v3::Location::try_from(asset_hub_westend_runtime::xcm_config::WestendLocation::get())
.expect("conversion works"),
);
let asset_one = Box::new(v3::Location { let asset_one = Box::new(v3::Location {
parents: 0, parents: 0,
interior: [ interior: [
@@ -226,11 +229,9 @@ fn swap_locally_on_chain_using_foreign_assets() {
#[test] #[test]
fn cannot_create_pool_from_pool_assets() { fn cannot_create_pool_from_pool_assets() {
let asset_native = Box::new(asset_hub_westend_runtime::xcm_config::WestendLocationV3::get()); let asset_native = asset_hub_westend_runtime::xcm_config::WestendLocation::get();
let mut asset_one = asset_hub_westend_runtime::xcm_config::PoolAssetsPalletLocationV3::get(); let mut asset_one = asset_hub_westend_runtime::xcm_config::PoolAssetsPalletLocation::get();
asset_one asset_one.append_with(GeneralIndex(ASSET_ID.into())).expect("pool assets");
.append_with(v3::Junction::GeneralIndex(ASSET_ID.into()))
.expect("pool assets");
AssetHubWestend::execute_with(|| { AssetHubWestend::execute_with(|| {
let pool_owner_account_id = asset_hub_westend_runtime::AssetConversionOrigin::get(); let pool_owner_account_id = asset_hub_westend_runtime::AssetConversionOrigin::get();
@@ -253,8 +254,8 @@ fn cannot_create_pool_from_pool_assets() {
assert_matches::assert_matches!( assert_matches::assert_matches!(
<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::create_pool( <AssetHubWestend as AssetHubWestendPallet>::AssetConversion::create_pool(
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()), <AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
asset_native, Box::new(v3::Location::try_from(asset_native).expect("conversion works")),
Box::new(asset_one), Box::new(v3::Location::try_from(asset_one).expect("conversion works")),
), ),
Err(DispatchError::Module(ModuleError{index: _, error: _, message})) => assert_eq!(message, Some("Unknown")) Err(DispatchError::Module(ModuleError{index: _, error: _, message})) => assert_eq!(message, Some("Unknown"))
); );
@@ -263,7 +264,9 @@ fn cannot_create_pool_from_pool_assets() {
#[test] #[test]
fn pay_xcm_fee_with_some_asset_swapped_for_native() { fn pay_xcm_fee_with_some_asset_swapped_for_native() {
let asset_native = asset_hub_westend_runtime::xcm_config::WestendLocationV3::get(); let asset_native =
v3::Location::try_from(asset_hub_westend_runtime::xcm_config::WestendLocation::get())
.expect("conversion works");
let asset_one = xcm::v3::Location { let asset_one = xcm::v3::Location {
parents: 0, parents: 0,
interior: [ interior: [
@@ -110,7 +110,7 @@ fn para_dest_assertions(t: RelayToSystemParaTest) {
fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) { fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) {
type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent; type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent;
let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let system_para_native_asset_location = RelayLocation::get();
let expected_asset_id = t.args.asset_id.unwrap(); let expected_asset_id = t.args.asset_id.unwrap();
let (_, expected_asset_amount) = let (_, expected_asset_amount) =
non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap();
@@ -203,7 +203,7 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) {
let (_, expected_asset_amount) = let (_, expected_asset_amount) =
non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap();
let checking_account = <PenpalA as PenpalAPallet>::PolkadotXcm::check_account(); let checking_account = <PenpalA as PenpalAPallet>::PolkadotXcm::check_account();
let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let system_para_native_asset_location = RelayLocation::get();
PenpalA::assert_xcmp_queue_success(None); PenpalA::assert_xcmp_queue_success(None);
@@ -420,22 +420,20 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
) { ) {
// Init values for Parachain // Init values for Parachain
let fee_amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 100; let fee_amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 100;
let asset_location_on_penpal = let asset_location_on_penpal = PenpalLocalTeleportableToAssetHub::get();
v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).unwrap();
let asset_id_on_penpal = match asset_location_on_penpal.last() { let asset_id_on_penpal = match asset_location_on_penpal.last() {
Some(v3::Junction::GeneralIndex(id)) => *id as u32, Some(Junction::GeneralIndex(id)) => *id as u32,
_ => unreachable!(), _ => unreachable!(),
}; };
let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 100; let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 100;
let asset_owner = PenpalAssetOwner::get(); let asset_owner = PenpalAssetOwner::get();
let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).unwrap(); let system_para_native_asset_location = RelayLocation::get();
let sender = PenpalASender::get(); let sender = PenpalASender::get();
let penpal_check_account = <PenpalA as PenpalAPallet>::PolkadotXcm::check_account(); let penpal_check_account = <PenpalA as PenpalAPallet>::PolkadotXcm::check_account();
let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubWestend::para_id()); let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubWestend::para_id());
let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap();
let penpal_assets: Assets = vec![ let penpal_assets: Assets = vec![
(Parent, fee_amount_to_send).into(), (Parent, fee_amount_to_send).into(),
(asset_location_on_penpal_latest, asset_amount_to_send).into(), (asset_location_on_penpal.clone(), asset_amount_to_send).into(),
] ]
.into(); .into();
let fee_asset_index = penpal_assets let fee_asset_index = penpal_assets
@@ -447,7 +445,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
// fund Parachain's sender account // fund Parachain's sender account
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(asset_owner.clone()), <PenpalA as Chain>::RuntimeOrigin::signed(asset_owner.clone()),
system_para_native_asset_location, system_para_native_asset_location.clone(),
sender.clone(), sender.clone(),
fee_amount_to_send * 2, fee_amount_to_send * 2,
); );
@@ -474,7 +472,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
// Init values for System Parachain // Init values for System Parachain
let foreign_asset_at_asset_hub_westend = let foreign_asset_at_asset_hub_westend =
v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) Location::new(1, [Junction::Parachain(PenpalA::para_id().into())])
.appended_with(asset_location_on_penpal) .appended_with(asset_location_on_penpal)
.unwrap(); .unwrap();
let penpal_to_ah_beneficiary_id = AssetHubWestendReceiver::get(); let penpal_to_ah_beneficiary_id = AssetHubWestendReceiver::get();
@@ -496,7 +494,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
let penpal_sender_balance_before = PenpalA::execute_with(|| { let penpal_sender_balance_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance( <ForeignAssets as Inspect<_>>::balance(
system_para_native_asset_location, system_para_native_asset_location.clone(),
&PenpalASender::get(), &PenpalASender::get(),
) )
}); });
@@ -510,7 +508,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
let ah_receiver_assets_before = AssetHubWestend::execute_with(|| { let ah_receiver_assets_before = AssetHubWestend::execute_with(|| {
type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets; type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance( <Assets as Inspect<_>>::balance(
foreign_asset_at_asset_hub_westend, foreign_asset_at_asset_hub_westend.clone().try_into().unwrap(),
&AssetHubWestendReceiver::get(), &AssetHubWestendReceiver::get(),
) )
}); });
@@ -523,7 +521,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
let penpal_sender_balance_after = PenpalA::execute_with(|| { let penpal_sender_balance_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance( <ForeignAssets as Inspect<_>>::balance(
system_para_native_asset_location, system_para_native_asset_location.clone(),
&PenpalASender::get(), &PenpalASender::get(),
) )
}); });
@@ -537,7 +535,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
let ah_receiver_assets_after = AssetHubWestend::execute_with(|| { let ah_receiver_assets_after = AssetHubWestend::execute_with(|| {
type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets; type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance( <Assets as Inspect<_>>::balance(
foreign_asset_at_asset_hub_westend, foreign_asset_at_asset_hub_westend.clone().try_into().unwrap(),
&AssetHubWestendReceiver::get(), &AssetHubWestendReceiver::get(),
) )
}); });
@@ -565,19 +563,17 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
type ForeignAssets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets; type ForeignAssets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
assert_ok!(ForeignAssets::transfer( assert_ok!(ForeignAssets::transfer(
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendReceiver::get()), <AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendReceiver::get()),
foreign_asset_at_asset_hub_westend, foreign_asset_at_asset_hub_westend.clone().try_into().unwrap(),
AssetHubWestendSender::get().into(), AssetHubWestendSender::get().into(),
asset_amount_to_send, asset_amount_to_send,
)); ));
}); });
let foreign_asset_at_asset_hub_westend_latest: Location =
foreign_asset_at_asset_hub_westend.try_into().unwrap();
let ah_to_penpal_beneficiary_id = PenpalAReceiver::get(); let ah_to_penpal_beneficiary_id = PenpalAReceiver::get();
let penpal_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalA::para_id()); let penpal_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalA::para_id());
let ah_assets: Assets = vec![ let ah_assets: Assets = vec![
(Parent, fee_amount_to_send).into(), (Parent, fee_amount_to_send).into(),
(foreign_asset_at_asset_hub_westend_latest, asset_amount_to_send).into(), (foreign_asset_at_asset_hub_westend.clone(), asset_amount_to_send).into(),
] ]
.into(); .into();
let fee_asset_index = ah_assets let fee_asset_index = ah_assets
@@ -605,7 +601,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
let penpal_receiver_balance_before = PenpalA::execute_with(|| { let penpal_receiver_balance_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance( <ForeignAssets as Inspect<_>>::balance(
system_para_native_asset_location, system_para_native_asset_location.clone(),
&PenpalAReceiver::get(), &PenpalAReceiver::get(),
) )
}); });
@@ -613,7 +609,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
let ah_sender_assets_before = AssetHubWestend::execute_with(|| { let ah_sender_assets_before = AssetHubWestend::execute_with(|| {
type ForeignAssets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets; type ForeignAssets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance( <ForeignAssets as Inspect<_>>::balance(
foreign_asset_at_asset_hub_westend, foreign_asset_at_asset_hub_westend.clone().try_into().unwrap(),
&AssetHubWestendSender::get(), &AssetHubWestendSender::get(),
) )
}); });
@@ -639,7 +635,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
let ah_sender_assets_after = AssetHubWestend::execute_with(|| { let ah_sender_assets_after = AssetHubWestend::execute_with(|| {
type ForeignAssets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets; type ForeignAssets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance( <ForeignAssets as Inspect<_>>::balance(
foreign_asset_at_asset_hub_westend, foreign_asset_at_asset_hub_westend.clone().try_into().unwrap(),
&AssetHubWestendSender::get(), &AssetHubWestendSender::get(),
) )
}); });
@@ -168,9 +168,11 @@ fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() {
<Assets as Inspect<_>>::balance(roc_at_asset_hub_westend, &AssetHubWestendReceiver::get()) <Assets as Inspect<_>>::balance(roc_at_asset_hub_westend, &AssetHubWestendReceiver::get())
}); });
let roc_at_asset_hub_rococo_latest: Location = roc_at_asset_hub_rococo.try_into().unwrap();
let amount = ASSET_HUB_ROCOCO_ED * 1_000_000; let amount = ASSET_HUB_ROCOCO_ED * 1_000_000;
send_asset_from_asset_hub_rococo_to_asset_hub_westend(roc_at_asset_hub_rococo_latest, amount); send_asset_from_asset_hub_rococo_to_asset_hub_westend(
roc_at_asset_hub_rococo.try_into().unwrap(),
amount,
);
AssetHubWestend::execute_with(|| { AssetHubWestend::execute_with(|| {
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent; type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
assert_expected_events!( assert_expected_events!(
@@ -238,10 +240,9 @@ fn send_wnds_from_asset_hub_rococo_to_asset_hub_westend() {
let receiver_wnds_before = let receiver_wnds_before =
<AssetHubWestend as Chain>::account_data_of(AssetHubWestendReceiver::get()).free; <AssetHubWestend as Chain>::account_data_of(AssetHubWestendReceiver::get()).free;
let wnd_at_asset_hub_rococo_latest: Location = wnd_at_asset_hub_rococo.try_into().unwrap();
let amount_to_send = ASSET_HUB_WESTEND_ED * 1_000; let amount_to_send = ASSET_HUB_WESTEND_ED * 1_000;
send_asset_from_asset_hub_rococo_to_asset_hub_westend( send_asset_from_asset_hub_rococo_to_asset_hub_westend(
wnd_at_asset_hub_rococo_latest.clone(), Location::try_from(wnd_at_asset_hub_rococo).unwrap(),
amount_to_send, amount_to_send,
); );
AssetHubWestend::execute_with(|| { AssetHubWestend::execute_with(|| {
@@ -287,13 +288,11 @@ fn send_wnds_from_asset_hub_rococo_to_asset_hub_westend() {
#[test] #[test]
fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend() { fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend() {
let roc_at_rococo_parachains: v3::Location = v3::Parent.into(); let roc_at_rococo_parachains: Location = Parent.into();
let roc_at_asset_hub_westend = let roc_at_asset_hub_westend = Location::new(2, [Junction::GlobalConsensus(NetworkId::Rococo)]);
v3::Location::new(2, [v3::Junction::GlobalConsensus(v3::NetworkId::Rococo)]);
let roc_at_rococo_parachains_latest: Location = roc_at_rococo_parachains.try_into().unwrap();
let owner: AccountId = AssetHubWestend::account_id_of(ALICE); let owner: AccountId = AssetHubWestend::account_id_of(ALICE);
AssetHubWestend::force_create_foreign_asset( AssetHubWestend::force_create_foreign_asset(
roc_at_asset_hub_westend, roc_at_asset_hub_westend.clone().try_into().unwrap(),
owner, owner,
true, true,
ASSET_MIN_BALANCE, ASSET_MIN_BALANCE,
@@ -312,7 +311,7 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend()
// fund Penpal's sender account // fund Penpal's sender account
PenpalA::mint_foreign_asset( PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(PenpalAssetOwner::get()), <PenpalA as Chain>::RuntimeOrigin::signed(PenpalAssetOwner::get()),
roc_at_rococo_parachains, roc_at_rococo_parachains.clone(),
PenpalASender::get(), PenpalASender::get(),
amount * 2, amount * 2,
); );
@@ -322,16 +321,19 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend()
let sender_rocs_before = PenpalA::execute_with(|| { let sender_rocs_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance( <ForeignAssets as Inspect<_>>::balance(
roc_at_rococo_parachains.into(), roc_at_rococo_parachains.clone(),
&PenpalASender::get(), &PenpalASender::get(),
) )
}); });
let receiver_rocs_before = AssetHubWestend::execute_with(|| { let receiver_rocs_before = AssetHubWestend::execute_with(|| {
type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets; type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(roc_at_asset_hub_westend, &AssetHubWestendReceiver::get()) <Assets as Inspect<_>>::balance(
roc_at_asset_hub_westend.clone().try_into().unwrap(),
&AssetHubWestendReceiver::get(),
)
}); });
send_asset_from_penpal_rococo_through_local_asset_hub_to_westend_asset_hub( send_asset_from_penpal_rococo_through_local_asset_hub_to_westend_asset_hub(
roc_at_rococo_parachains_latest, roc_at_rococo_parachains.clone(),
amount, amount,
); );
@@ -342,7 +344,7 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend()
vec![ vec![
// issue ROCs on AHW // issue ROCs on AHW
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => {
asset_id: *asset_id == roc_at_rococo_parachains, asset_id: *asset_id == roc_at_rococo_parachains.clone().try_into().unwrap(),
owner: *owner == AssetHubWestendReceiver::get(), owner: *owner == AssetHubWestendReceiver::get(),
}, },
// message processed successfully // message processed successfully
@@ -355,14 +357,14 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend()
let sender_rocs_after = PenpalA::execute_with(|| { let sender_rocs_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets; type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance( <ForeignAssets as Inspect<_>>::balance(roc_at_rococo_parachains, &PenpalASender::get())
roc_at_rococo_parachains.into(),
&PenpalASender::get(),
)
}); });
let receiver_rocs_after = AssetHubWestend::execute_with(|| { let receiver_rocs_after = AssetHubWestend::execute_with(|| {
type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets; type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(roc_at_asset_hub_westend, &AssetHubWestendReceiver::get()) <Assets as Inspect<_>>::balance(
roc_at_asset_hub_westend.try_into().unwrap(),
&AssetHubWestendReceiver::get(),
)
}); });
let rocs_in_reserve_on_ahr_after = let rocs_in_reserve_on_ahr_after =
<AssetHubRococo as Chain>::account_data_of(sov_ahw_on_ahr.clone()).free; <AssetHubRococo as Chain>::account_data_of(sov_ahw_on_ahr.clone()).free;
@@ -306,8 +306,6 @@ fn send_token_from_ethereum_to_penpal() {
// The Weth asset location, identified by the contract address on Ethereum // The Weth asset location, identified by the contract address on Ethereum
let weth_asset_location: Location = let weth_asset_location: Location =
(Parent, Parent, EthereumNetwork::get(), AccountKey20 { network: None, key: WETH }).into(); (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.try_into().unwrap();
let origin_location = (Parent, Parent, EthereumNetwork::get()).into(); let origin_location = (Parent, Parent, EthereumNetwork::get()).into();
@@ -321,12 +319,12 @@ fn send_token_from_ethereum_to_penpal() {
PenpalA::execute_with(|| { PenpalA::execute_with(|| {
assert_ok!(<PenpalA as PenpalAPallet>::ForeignAssets::create( assert_ok!(<PenpalA as PenpalAPallet>::ForeignAssets::create(
<PenpalA as Chain>::RuntimeOrigin::signed(PenpalASender::get()), <PenpalA as Chain>::RuntimeOrigin::signed(PenpalASender::get()),
weth_asset_id, weth_asset_location.clone(),
asset_hub_sovereign.into(), asset_hub_sovereign.into(),
1000, 1000,
)); ));
assert!(<PenpalA as PenpalAPallet>::ForeignAssets::asset_exists(weth_asset_id)); assert!(<PenpalA as PenpalAPallet>::ForeignAssets::asset_exists(weth_asset_location));
}); });
BridgeHubRococo::execute_with(|| { BridgeHubRococo::execute_with(|| {
@@ -236,10 +236,9 @@ fn send_rocs_from_asset_hub_westend_to_asset_hub_rococo() {
let receiver_rocs_before = let receiver_rocs_before =
<AssetHubRococo as Chain>::account_data_of(AssetHubRococoReceiver::get()).free; <AssetHubRococo as Chain>::account_data_of(AssetHubRococoReceiver::get()).free;
let roc_at_asset_hub_westend_latest: Location = roc_at_asset_hub_westend.try_into().unwrap();
let amount_to_send = ASSET_HUB_ROCOCO_ED * 1_000; let amount_to_send = ASSET_HUB_ROCOCO_ED * 1_000;
send_asset_from_asset_hub_westend_to_asset_hub_rococo( send_asset_from_asset_hub_westend_to_asset_hub_rococo(
roc_at_asset_hub_westend_latest.clone(), roc_at_asset_hub_westend.try_into().unwrap(),
amount_to_send, amount_to_send,
); );
AssetHubRococo::execute_with(|| { AssetHubRococo::execute_with(|| {
@@ -285,13 +284,11 @@ fn send_rocs_from_asset_hub_westend_to_asset_hub_rococo() {
#[test] #[test]
fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo() { fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo() {
let wnd_at_westend_parachains: v3::Location = v3::Parent.into(); let wnd_at_westend_parachains: Location = Parent.into();
let wnd_at_asset_hub_rococo = let wnd_at_asset_hub_rococo = Location::new(2, [Junction::GlobalConsensus(NetworkId::Westend)]);
v3::Location::new(2, [v3::Junction::GlobalConsensus(v3::NetworkId::Westend)]);
let wnd_at_westend_parachains_latest: Location = wnd_at_westend_parachains.try_into().unwrap();
let owner: AccountId = AssetHubRococo::account_id_of(ALICE); let owner: AccountId = AssetHubRococo::account_id_of(ALICE);
AssetHubRococo::force_create_foreign_asset( AssetHubRococo::force_create_foreign_asset(
wnd_at_asset_hub_rococo, wnd_at_asset_hub_rococo.clone().try_into().unwrap(),
owner, owner,
true, true,
ASSET_MIN_BALANCE, ASSET_MIN_BALANCE,
@@ -310,7 +307,7 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo()
// fund Penpal's sender account // fund Penpal's sender account
PenpalB::mint_foreign_asset( PenpalB::mint_foreign_asset(
<PenpalB as Chain>::RuntimeOrigin::signed(PenpalAssetOwner::get()), <PenpalB as Chain>::RuntimeOrigin::signed(PenpalAssetOwner::get()),
wnd_at_westend_parachains, wnd_at_westend_parachains.clone(),
PenpalBSender::get(), PenpalBSender::get(),
amount * 2, amount * 2,
); );
@@ -320,16 +317,19 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo()
let sender_wnds_before = PenpalB::execute_with(|| { let sender_wnds_before = PenpalB::execute_with(|| {
type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets; type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance( <ForeignAssets as Inspect<_>>::balance(
wnd_at_westend_parachains.into(), wnd_at_westend_parachains.clone(),
&PenpalBSender::get(), &PenpalBSender::get(),
) )
}); });
let receiver_wnds_before = AssetHubRococo::execute_with(|| { let receiver_wnds_before = AssetHubRococo::execute_with(|| {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets; type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(wnd_at_asset_hub_rococo, &AssetHubRococoReceiver::get()) <Assets as Inspect<_>>::balance(
wnd_at_asset_hub_rococo.clone().try_into().unwrap(),
&AssetHubRococoReceiver::get(),
)
}); });
send_asset_from_penpal_westend_through_local_asset_hub_to_rococo_asset_hub( send_asset_from_penpal_westend_through_local_asset_hub_to_rococo_asset_hub(
wnd_at_westend_parachains_latest, wnd_at_westend_parachains.clone(),
amount, amount,
); );
@@ -340,7 +340,7 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo()
vec![ vec![
// issue WNDs on AHR // issue WNDs on AHR
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => {
asset_id: *asset_id == wnd_at_westend_parachains, asset_id: *asset_id == wnd_at_westend_parachains.clone().try_into().unwrap(),
owner: *owner == AssetHubRococoReceiver::get(), owner: *owner == AssetHubRococoReceiver::get(),
}, },
// message processed successfully // message processed successfully
@@ -353,14 +353,14 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo()
let sender_wnds_after = PenpalB::execute_with(|| { let sender_wnds_after = PenpalB::execute_with(|| {
type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets; type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance( <ForeignAssets as Inspect<_>>::balance(wnd_at_westend_parachains, &PenpalBSender::get())
wnd_at_westend_parachains.into(),
&PenpalBSender::get(),
)
}); });
let receiver_wnds_after = AssetHubRococo::execute_with(|| { let receiver_wnds_after = AssetHubRococo::execute_with(|| {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets; type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(wnd_at_asset_hub_rococo, &AssetHubRococoReceiver::get()) <Assets as Inspect<_>>::balance(
wnd_at_asset_hub_rococo.try_into().unwrap(),
&AssetHubRococoReceiver::get(),
)
}); });
let wnds_in_reserve_on_ahw_after = let wnds_in_reserve_on_ahw_after =
<AssetHubWestend as Chain>::account_data_of(sov_ahr_on_ahw.clone()).free; <AssetHubWestend as Chain>::account_data_of(sov_ahr_on_ahw.clone()).free;
@@ -316,7 +316,7 @@ pub type LocalAndForeignAssets = fungibles::UnionOf<
Assets, Assets,
ForeignAssets, ForeignAssets,
LocalFromLeft< LocalFromLeft<
AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocationV3>, AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocationV3, xcm::v3::Location>,
AssetIdForTrustBackedAssets, AssetIdForTrustBackedAssets,
xcm::v3::Location, xcm::v3::Location,
>, >,
@@ -82,8 +82,6 @@ parameter_types! {
PalletInstance(<PoolAssets as PalletInfoAccess>::index() as u8).into(); PalletInstance(<PoolAssets as PalletInfoAccess>::index() as u8).into();
pub UniquesPalletLocation: Location = pub UniquesPalletLocation: Location =
PalletInstance(<Uniques as PalletInfoAccess>::index() as u8).into(); PalletInstance(<Uniques as PalletInfoAccess>::index() as u8).into();
pub PoolAssetsPalletLocationV3: xcm::v3::Location =
xcm::v3::Junction::PalletInstance(<PoolAssets as PalletInfoAccess>::index() as u8).into();
pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub CheckingAccount: AccountId = PolkadotXcm::check_account();
pub const GovernanceLocation: Location = Location::parent(); pub const GovernanceLocation: Location = Location::parent();
pub StakingPot: AccountId = CollatorSelection::account_id(); pub StakingPot: AccountId = CollatorSelection::account_id();
@@ -179,6 +177,7 @@ pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConverte
StartsWithExplicitGlobalConsensus<UniversalLocationNetworkId>, StartsWithExplicitGlobalConsensus<UniversalLocationNetworkId>,
), ),
Balance, Balance,
xcm::v3::Location,
>; >;
/// Means for transacting foreign assets from different global consensus. /// Means for transacting foreign assets from different global consensus.
@@ -581,7 +580,11 @@ impl xcm_executor::Config for XcmConfig {
WeightToFee, WeightToFee,
crate::NativeAndAssets, crate::NativeAndAssets,
( (
TrustBackedAssetsAsLocation<TrustBackedAssetsPalletLocation, Balance>, TrustBackedAssetsAsLocation<
TrustBackedAssetsPalletLocation,
Balance,
xcm::v3::Location,
>,
ForeignAssetsConvertedConcreteId, ForeignAssetsConvertedConcreteId,
), ),
ResolveAssetTo<StakingPot, crate::NativeAndAssets>, ResolveAssetTo<StakingPot, crate::NativeAndAssets>,
@@ -22,8 +22,7 @@ use asset_hub_rococo_runtime::{
xcm_config::{ xcm_config::{
bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount,
ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, ForeignCreatorsSovereignAccountOf, ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, ForeignCreatorsSovereignAccountOf,
LocationToAccountId, StakingPot, TokenLocation, TokenLocationV3, LocationToAccountId, StakingPot, TokenLocation, TrustBackedAssetsPalletLocation, XcmConfig,
TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3, XcmConfig,
}, },
AllPalletsWithoutSystem, AssetConversion, AssetDeposit, Assets, Balances, CollatorSelection, AllPalletsWithoutSystem, AssetConversion, AssetDeposit, Assets, Balances, CollatorSelection,
ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase,
@@ -53,17 +52,14 @@ use sp_std::ops::Mul;
use std::convert::Into; use std::convert::Into;
use testnet_parachains_constants::rococo::{consensus::*, currency::UNITS, fee::WeightToFee}; use testnet_parachains_constants::rococo::{consensus::*, currency::UNITS, fee::WeightToFee};
use xcm::latest::prelude::{Assets as XcmAssets, *}; use xcm::latest::prelude::{Assets as XcmAssets, *};
use xcm_builder::V4V3LocationConverter; use xcm_builder::WithLatestLocationConverter;
use xcm_executor::traits::{JustTry, WeightTrader}; use xcm_executor::traits::{JustTry, WeightTrader};
const ALICE: [u8; 32] = [1u8; 32]; const ALICE: [u8; 32] = [1u8; 32];
const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32]; const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32];
type AssetIdForTrustBackedAssetsConvert = type AssetIdForTrustBackedAssetsConvert =
assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocationV3>; assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>;
type AssetIdForTrustBackedAssetsConvertLatest =
assets_common::AssetIdForTrustBackedAssetsConvertLatest<TrustBackedAssetsPalletLocation>;
type RuntimeHelper = asset_test_utils::RuntimeHelper<Runtime, AllPalletsWithoutSystem>; type RuntimeHelper = asset_test_utils::RuntimeHelper<Runtime, AllPalletsWithoutSystem>;
@@ -204,7 +200,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
let bob: AccountId = SOME_ASSET_ADMIN.into(); let bob: AccountId = SOME_ASSET_ADMIN.into();
let staking_pot = CollatorSelection::account_id(); let staking_pot = CollatorSelection::account_id();
let asset_1: u32 = 1; let asset_1: u32 = 1;
let native_location = TokenLocationV3::get(); let native_location = TokenLocation::get();
let asset_1_location = let asset_1_location =
AssetIdForTrustBackedAssetsConvert::convert_back(&asset_1).unwrap(); AssetIdForTrustBackedAssetsConvert::convert_back(&asset_1).unwrap();
// bob's initial balance for native and `asset1` assets. // bob's initial balance for native and `asset1` assets.
@@ -221,14 +217,24 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
assert_ok!(AssetConversion::create_pool( assert_ok!(AssetConversion::create_pool(
RuntimeHelper::origin_of(bob.clone()), RuntimeHelper::origin_of(bob.clone()),
Box::new(native_location), Box::new(
Box::new(asset_1_location) xcm::v3::Location::try_from(native_location.clone()).expect("conversion works")
),
Box::new(
xcm::v3::Location::try_from(asset_1_location.clone())
.expect("conversion works")
)
)); ));
assert_ok!(AssetConversion::add_liquidity( assert_ok!(AssetConversion::add_liquidity(
RuntimeHelper::origin_of(bob.clone()), RuntimeHelper::origin_of(bob.clone()),
Box::new(native_location), Box::new(
Box::new(asset_1_location), xcm::v3::Location::try_from(native_location.clone()).expect("conversion works")
),
Box::new(
xcm::v3::Location::try_from(asset_1_location.clone())
.expect("conversion works")
),
pool_liquidity, pool_liquidity,
pool_liquidity, pool_liquidity,
1, 1,
@@ -240,8 +246,6 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
let asset_total_issuance = Assets::total_issuance(asset_1); let asset_total_issuance = Assets::total_issuance(asset_1);
let native_total_issuance = Balances::total_issuance(); let native_total_issuance = Balances::total_issuance();
let asset_1_location_latest: Location = asset_1_location.try_into().unwrap();
// prepare input to buy weight. // prepare input to buy weight.
let weight = Weight::from_parts(4_000_000_000, 0); let weight = Weight::from_parts(4_000_000_000, 0);
let fee = WeightToFee::weight_to_fee(&weight); let fee = WeightToFee::weight_to_fee(&weight);
@@ -249,7 +253,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap(); AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap();
let extra_amount = 100; let extra_amount = 100;
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; 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. // init trader and buy weight.
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new(); let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
@@ -257,24 +261,25 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok"); trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok");
// assert. // assert.
let unused_amount = unused_asset let unused_amount =
.fungible unused_asset.fungible.get(&asset_1_location.clone().into()).map_or(0, |a| *a);
.get(&asset_1_location_latest.clone().into())
.map_or(0, |a| *a);
assert_eq!(unused_amount, extra_amount); assert_eq!(unused_amount, extra_amount);
assert_eq!(Assets::total_issuance(asset_1), asset_total_issuance + asset_fee); assert_eq!(Assets::total_issuance(asset_1), asset_total_issuance + asset_fee);
// prepare input to refund weight. // prepare input to refund weight.
let refund_weight = Weight::from_parts(1_000_000_000, 0); let refund_weight = Weight::from_parts(1_000_000_000, 0);
let refund = WeightToFee::weight_to_fee(&refund_weight); let refund = WeightToFee::weight_to_fee(&refund_weight);
let (reserve1, reserve2) = let (reserve1, reserve2) = AssetConversion::get_reserves(
AssetConversion::get_reserves(native_location, asset_1_location).unwrap(); xcm::v3::Location::try_from(native_location).expect("conversion works"),
xcm::v3::Location::try_from(asset_1_location.clone()).expect("conversion works"),
)
.unwrap();
let asset_refund = let asset_refund =
AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap(); AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap();
// refund. // refund.
let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap(); 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.
assert_eq!(Balances::balance(&staking_pot), initial_balance); assert_eq!(Balances::balance(&staking_pot), initial_balance);
@@ -303,7 +308,8 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() {
.execute_with(|| { .execute_with(|| {
let bob: AccountId = SOME_ASSET_ADMIN.into(); let bob: AccountId = SOME_ASSET_ADMIN.into();
let staking_pot = CollatorSelection::account_id(); let staking_pot = CollatorSelection::account_id();
let native_location = TokenLocationV3::get(); let native_location =
xcm::v3::Location::try_from(TokenLocation::get()).expect("conversion works");
let foreign_location = xcm::v3::Location { let foreign_location = xcm::v3::Location {
parents: 1, parents: 1,
interior: ( interior: (
@@ -435,7 +441,7 @@ fn test_asset_xcm_take_first_trader() {
// get asset id as location // get asset id as location
let asset_location = let asset_location =
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap(); AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap();
// Set Alice as block author, who will receive fees // Set Alice as block author, who will receive fees
RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); RuntimeHelper::run_to_block(2, AccountId::from(ALICE));
@@ -603,9 +609,7 @@ fn test_asset_xcm_take_first_trader_with_refund() {
// We are going to buy 4e9 weight // We are going to buy 4e9 weight
let bought = Weight::from_parts(4_000_000_000u64, 0); let bought = Weight::from_parts(4_000_000_000u64, 0);
let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap();
let asset_location =
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap();
// lets calculate amount needed // lets calculate amount needed
let amount_bought = WeightToFee::weight_to_fee(&bought); let amount_bought = WeightToFee::weight_to_fee(&bought);
@@ -623,7 +627,7 @@ fn test_asset_xcm_take_first_trader_with_refund() {
// We actually use half of the weight // We actually use half of the weight
let weight_used = bought / 2; let weight_used = bought / 2;
// Make sure refurnd works. // Make sure refund works.
let amount_refunded = WeightToFee::weight_to_fee(&(bought - weight_used)); let amount_refunded = WeightToFee::weight_to_fee(&(bought - weight_used));
assert_eq!( assert_eq!(
@@ -677,8 +681,7 @@ fn test_asset_xcm_take_first_trader_refund_not_possible_since_amount_less_than_e
// We are going to buy small amount // We are going to buy small amount
let bought = Weight::from_parts(500_000_000u64, 0); let bought = Weight::from_parts(500_000_000u64, 0);
let asset_location = let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap();
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap();
let amount_bought = WeightToFee::weight_to_fee(&bought); let amount_bought = WeightToFee::weight_to_fee(&bought);
@@ -730,8 +733,7 @@ fn test_that_buying_ed_refund_does_not_refund_for_take_first_trader() {
// We are gonna buy ED // We are gonna buy ED
let bought = Weight::from_parts(ExistentialDeposit::get().try_into().unwrap(), 0); let bought = Weight::from_parts(ExistentialDeposit::get().try_into().unwrap(), 0);
let asset_location = let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap();
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap();
let amount_bought = WeightToFee::weight_to_fee(&bought); let amount_bought = WeightToFee::weight_to_fee(&bought);
@@ -807,8 +809,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() {
// lets calculate amount needed // lets calculate amount needed
let asset_amount_needed = WeightToFee::weight_to_fee(&bought); let asset_amount_needed = WeightToFee::weight_to_fee(&bought);
let asset_location = let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap();
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap();
let asset: Asset = (asset_location, asset_amount_needed).into(); let asset: Asset = (asset_location, asset_amount_needed).into();
@@ -925,13 +926,16 @@ fn test_assets_balances_api_works() {
))); )));
// check trusted asset // check trusted asset
assert!(result.inner().iter().any(|asset| asset.eq(&( assert!(result.inner().iter().any(|asset| asset.eq(&(
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap(), AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(),
minimum_asset_balance minimum_asset_balance
) )
.into()))); .into())));
// check foreign asset // check foreign asset
assert!(result.inner().iter().any(|asset| asset.eq(&( assert!(result.inner().iter().any(|asset| asset.eq(&(
V4V3LocationConverter::convert_back(&foreign_asset_id_location).unwrap(), WithLatestLocationConverter::<xcm::v3::Location>::convert_back(
&foreign_asset_id_location
)
.unwrap(),
6 * foreign_asset_minimum_asset_balance 6 * foreign_asset_minimum_asset_balance
) )
.into()))); .into())));
@@ -1004,7 +1008,7 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_
XcmConfig, XcmConfig,
TrustBackedAssetsInstance, TrustBackedAssetsInstance,
AssetIdForTrustBackedAssets, AssetIdForTrustBackedAssets,
AssetIdForTrustBackedAssetsConvertLatest, AssetIdForTrustBackedAssetsConvert,
collator_session_keys(), collator_session_keys(),
ExistentialDeposit::get(), ExistentialDeposit::get(),
12345, 12345,
@@ -1044,7 +1048,7 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p
ForeignCreatorsSovereignAccountOf, ForeignCreatorsSovereignAccountOf,
ForeignAssetsInstance, ForeignAssetsInstance,
xcm::v3::Location, xcm::v3::Location,
V4V3LocationConverter, WithLatestLocationConverter<xcm::v3::Location>,
collator_session_keys(), collator_session_keys(),
ExistentialDeposit::get(), ExistentialDeposit::get(),
AssetDeposit::get(), AssetDeposit::get(),
@@ -298,7 +298,7 @@ pub type LocalAndForeignAssets = fungibles::UnionOf<
Assets, Assets,
ForeignAssets, ForeignAssets,
LocalFromLeft< LocalFromLeft<
AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocationV3>, AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocationV3, xcm::v3::Location>,
AssetIdForTrustBackedAssets, AssetIdForTrustBackedAssets,
xcm::v3::Location, xcm::v3::Location,
>, >,
@@ -78,8 +78,6 @@ parameter_types! {
PalletInstance(<PoolAssets as PalletInfoAccess>::index() as u8).into(); PalletInstance(<PoolAssets as PalletInfoAccess>::index() as u8).into();
pub UniquesPalletLocation: Location = pub UniquesPalletLocation: Location =
PalletInstance(<Uniques as PalletInfoAccess>::index() as u8).into(); PalletInstance(<Uniques as PalletInfoAccess>::index() as u8).into();
pub PoolAssetsPalletLocationV3: xcm::v3::Location =
xcm::v3::Junction::PalletInstance(<PoolAssets as PalletInfoAccess>::index() as u8).into();
pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub CheckingAccount: AccountId = PolkadotXcm::check_account();
pub StakingPot: AccountId = CollatorSelection::account_id(); pub StakingPot: AccountId = CollatorSelection::account_id();
pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
@@ -172,6 +170,7 @@ pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConverte
StartsWithExplicitGlobalConsensus<UniversalLocationNetworkId>, StartsWithExplicitGlobalConsensus<UniversalLocationNetworkId>,
), ),
Balance, Balance,
xcm::v3::Location,
>; >;
/// Means for transacting foreign assets from different global consensus. /// Means for transacting foreign assets from different global consensus.
@@ -603,7 +602,11 @@ impl xcm_executor::Config for XcmConfig {
WeightToFee, WeightToFee,
crate::NativeAndAssets, crate::NativeAndAssets,
( (
TrustBackedAssetsAsLocation<TrustBackedAssetsPalletLocation, Balance>, TrustBackedAssetsAsLocation<
TrustBackedAssetsPalletLocation,
Balance,
xcm::v3::Location,
>,
ForeignAssetsConvertedConcreteId, ForeignAssetsConvertedConcreteId,
), ),
ResolveAssetTo<StakingPot, crate::NativeAndAssets>, ResolveAssetTo<StakingPot, crate::NativeAndAssets>,
@@ -22,8 +22,8 @@ use asset_hub_westend_runtime::{
xcm_config::{ xcm_config::{
bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount,
ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, ForeignCreatorsSovereignAccountOf, ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, ForeignCreatorsSovereignAccountOf,
LocationToAccountId, StakingPot, TrustBackedAssetsPalletLocation, LocationToAccountId, StakingPot, TrustBackedAssetsPalletLocation, WestendLocation,
TrustBackedAssetsPalletLocationV3, WestendLocation, WestendLocationV3, XcmConfig, XcmConfig,
}, },
AllPalletsWithoutSystem, Assets, Balances, ExistentialDeposit, ForeignAssets, AllPalletsWithoutSystem, Assets, Balances, ExistentialDeposit, ForeignAssets,
ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem, ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem,
@@ -53,17 +53,14 @@ use sp_runtime::traits::MaybeEquivalence;
use std::{convert::Into, ops::Mul}; use std::{convert::Into, ops::Mul};
use testnet_parachains_constants::westend::{consensus::*, currency::UNITS, fee::WeightToFee}; use testnet_parachains_constants::westend::{consensus::*, currency::UNITS, fee::WeightToFee};
use xcm::latest::prelude::{Assets as XcmAssets, *}; use xcm::latest::prelude::{Assets as XcmAssets, *};
use xcm_builder::V4V3LocationConverter; use xcm_builder::WithLatestLocationConverter;
use xcm_executor::traits::{ConvertLocation, JustTry, WeightTrader}; use xcm_executor::traits::{ConvertLocation, JustTry, WeightTrader};
const ALICE: [u8; 32] = [1u8; 32]; const ALICE: [u8; 32] = [1u8; 32];
const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32]; const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32];
type AssetIdForTrustBackedAssetsConvert = type AssetIdForTrustBackedAssetsConvert =
assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocationV3>; assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>;
type AssetIdForTrustBackedAssetsConvertLatest =
assets_common::AssetIdForTrustBackedAssetsConvertLatest<TrustBackedAssetsPalletLocation>;
type RuntimeHelper = asset_test_utils::RuntimeHelper<Runtime, AllPalletsWithoutSystem>; type RuntimeHelper = asset_test_utils::RuntimeHelper<Runtime, AllPalletsWithoutSystem>;
@@ -204,7 +201,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
let bob: AccountId = SOME_ASSET_ADMIN.into(); let bob: AccountId = SOME_ASSET_ADMIN.into();
let staking_pot = CollatorSelection::account_id(); let staking_pot = CollatorSelection::account_id();
let asset_1: u32 = 1; let asset_1: u32 = 1;
let native_location = WestendLocationV3::get(); let native_location = WestendLocation::get();
let asset_1_location = let asset_1_location =
AssetIdForTrustBackedAssetsConvert::convert_back(&asset_1).unwrap(); AssetIdForTrustBackedAssetsConvert::convert_back(&asset_1).unwrap();
// bob's initial balance for native and `asset1` assets. // bob's initial balance for native and `asset1` assets.
@@ -221,14 +218,24 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
assert_ok!(AssetConversion::create_pool( assert_ok!(AssetConversion::create_pool(
RuntimeHelper::origin_of(bob.clone()), RuntimeHelper::origin_of(bob.clone()),
Box::new(native_location), Box::new(
Box::new(asset_1_location) xcm::v3::Location::try_from(native_location.clone()).expect("conversion works")
),
Box::new(
xcm::v3::Location::try_from(asset_1_location.clone())
.expect("conversion works")
)
)); ));
assert_ok!(AssetConversion::add_liquidity( assert_ok!(AssetConversion::add_liquidity(
RuntimeHelper::origin_of(bob.clone()), RuntimeHelper::origin_of(bob.clone()),
Box::new(native_location), Box::new(
Box::new(asset_1_location), xcm::v3::Location::try_from(native_location.clone()).expect("conversion works")
),
Box::new(
xcm::v3::Location::try_from(asset_1_location.clone())
.expect("conversion works")
),
pool_liquidity, pool_liquidity,
pool_liquidity, pool_liquidity,
1, 1,
@@ -240,8 +247,6 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
let asset_total_issuance = Assets::total_issuance(asset_1); let asset_total_issuance = Assets::total_issuance(asset_1);
let native_total_issuance = Balances::total_issuance(); let native_total_issuance = Balances::total_issuance();
let asset_1_location_latest: Location = asset_1_location.try_into().unwrap();
// prepare input to buy weight. // prepare input to buy weight.
let weight = Weight::from_parts(4_000_000_000, 0); let weight = Weight::from_parts(4_000_000_000, 0);
let fee = WeightToFee::weight_to_fee(&weight); let fee = WeightToFee::weight_to_fee(&weight);
@@ -249,7 +254,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap(); AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap();
let extra_amount = 100; let extra_amount = 100;
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; 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. // init trader and buy weight.
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new(); let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
@@ -257,24 +262,25 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok"); trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok");
// assert. // assert.
let unused_amount = unused_asset let unused_amount =
.fungible unused_asset.fungible.get(&asset_1_location.clone().into()).map_or(0, |a| *a);
.get(&asset_1_location_latest.clone().into())
.map_or(0, |a| *a);
assert_eq!(unused_amount, extra_amount); assert_eq!(unused_amount, extra_amount);
assert_eq!(Assets::total_issuance(asset_1), asset_total_issuance + asset_fee); assert_eq!(Assets::total_issuance(asset_1), asset_total_issuance + asset_fee);
// prepare input to refund weight. // prepare input to refund weight.
let refund_weight = Weight::from_parts(1_000_000_000, 0); let refund_weight = Weight::from_parts(1_000_000_000, 0);
let refund = WeightToFee::weight_to_fee(&refund_weight); let refund = WeightToFee::weight_to_fee(&refund_weight);
let (reserve1, reserve2) = let (reserve1, reserve2) = AssetConversion::get_reserves(
AssetConversion::get_reserves(native_location, asset_1_location).unwrap(); xcm::v3::Location::try_from(native_location).expect("conversion works"),
xcm::v3::Location::try_from(asset_1_location.clone()).expect("conversion works"),
)
.unwrap();
let asset_refund = let asset_refund =
AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap(); AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap();
// refund. // refund.
let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap(); 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.
assert_eq!(Balances::balance(&staking_pot), initial_balance); assert_eq!(Balances::balance(&staking_pot), initial_balance);
@@ -303,7 +309,8 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() {
.execute_with(|| { .execute_with(|| {
let bob: AccountId = SOME_ASSET_ADMIN.into(); let bob: AccountId = SOME_ASSET_ADMIN.into();
let staking_pot = CollatorSelection::account_id(); let staking_pot = CollatorSelection::account_id();
let native_location = WestendLocationV3::get(); let native_location =
xcm::v3::Location::try_from(WestendLocation::get()).expect("conversion works");
let foreign_location = xcm::v3::Location { let foreign_location = xcm::v3::Location {
parents: 1, parents: 1,
interior: ( interior: (
@@ -435,7 +442,7 @@ fn test_asset_xcm_take_first_trader() {
// get asset id as location // get asset id as location
let asset_location = let asset_location =
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap(); AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap();
// Set Alice as block author, who will receive fees // Set Alice as block author, who will receive fees
RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); RuntimeHelper::run_to_block(2, AccountId::from(ALICE));
@@ -599,8 +606,7 @@ fn test_asset_xcm_take_first_trader_with_refund() {
// We are going to buy 4e9 weight // We are going to buy 4e9 weight
let bought = Weight::from_parts(4_000_000_000u64, 0); let bought = Weight::from_parts(4_000_000_000u64, 0);
let asset_location = let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap();
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap();
// lets calculate amount needed // lets calculate amount needed
let amount_bought = WeightToFee::weight_to_fee(&bought); let amount_bought = WeightToFee::weight_to_fee(&bought);
@@ -672,8 +678,7 @@ fn test_asset_xcm_take_first_trader_refund_not_possible_since_amount_less_than_e
// We are going to buy small amount // We are going to buy small amount
let bought = Weight::from_parts(500_000_000u64, 0); let bought = Weight::from_parts(500_000_000u64, 0);
let asset_location = let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap();
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap();
let amount_bought = WeightToFee::weight_to_fee(&bought); let amount_bought = WeightToFee::weight_to_fee(&bought);
@@ -724,8 +729,7 @@ fn test_that_buying_ed_refund_does_not_refund_for_take_first_trader() {
let bought = Weight::from_parts(500_000_000u64, 0); let bought = Weight::from_parts(500_000_000u64, 0);
let asset_location = let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap();
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap();
let amount_bought = WeightToFee::weight_to_fee(&bought); let amount_bought = WeightToFee::weight_to_fee(&bought);
@@ -801,8 +805,7 @@ fn test_asset_xcm_take_first_trader_not_possible_for_non_sufficient_assets() {
// lets calculate amount needed // lets calculate amount needed
let asset_amount_needed = WeightToFee::weight_to_fee(&bought); let asset_amount_needed = WeightToFee::weight_to_fee(&bought);
let asset_location = let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap();
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap();
let asset: Asset = (asset_location, asset_amount_needed).into(); let asset: Asset = (asset_location, asset_amount_needed).into();
@@ -923,13 +926,16 @@ fn test_assets_balances_api_works() {
))); )));
// check trusted asset // check trusted asset
assert!(result.inner().iter().any(|asset| asset.eq(&( assert!(result.inner().iter().any(|asset| asset.eq(&(
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap(), AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(),
minimum_asset_balance minimum_asset_balance
) )
.into()))); .into())));
// check foreign asset // check foreign asset
assert!(result.inner().iter().any(|asset| asset.eq(&( assert!(result.inner().iter().any(|asset| asset.eq(&(
V4V3LocationConverter::convert_back(&foreign_asset_id_location).unwrap(), WithLatestLocationConverter::<xcm::v3::Location>::convert_back(
&foreign_asset_id_location
)
.unwrap(),
6 * foreign_asset_minimum_asset_balance 6 * foreign_asset_minimum_asset_balance
) )
.into()))); .into())));
@@ -1002,7 +1008,7 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_
XcmConfig, XcmConfig,
TrustBackedAssetsInstance, TrustBackedAssetsInstance,
AssetIdForTrustBackedAssets, AssetIdForTrustBackedAssets,
AssetIdForTrustBackedAssetsConvertLatest, AssetIdForTrustBackedAssetsConvert,
collator_session_keys(), collator_session_keys(),
ExistentialDeposit::get(), ExistentialDeposit::get(),
12345, 12345,
@@ -1043,7 +1049,7 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p
ForeignCreatorsSovereignAccountOf, ForeignCreatorsSovereignAccountOf,
ForeignAssetsInstance, ForeignAssetsInstance,
xcm::v3::Location, xcm::v3::Location,
V4V3LocationConverter, WithLatestLocationConverter<xcm::v3::Location>,
collator_session_keys(), collator_session_keys(),
ExistentialDeposit::get(), ExistentialDeposit::get(),
AssetDeposit::get(), AssetDeposit::get(),
@@ -26,36 +26,37 @@ pub mod runtime_api;
use crate::matching::{LocalLocationPattern, ParentLocation}; use crate::matching::{LocalLocationPattern, ParentLocation};
use frame_support::traits::{Equals, EverythingBut}; use frame_support::traits::{Equals, EverythingBut};
use parachains_common::{AssetIdForTrustBackedAssets, CollectionId, ItemId}; use parachains_common::{AssetIdForTrustBackedAssets, CollectionId, ItemId};
use sp_runtime::traits::TryConvertInto;
use xcm::latest::Location;
use xcm_builder::{ use xcm_builder::{
AsPrefixedGeneralIndex, MatchedConvertedConcreteId, StartsWith, V4V3LocationConverter, AsPrefixedGeneralIndex, MatchedConvertedConcreteId, StartsWith, WithLatestLocationConverter,
}; };
use xcm_executor::traits::JustTry;
/// `Location` vs `AssetIdForTrustBackedAssets` converter for `TrustBackedAssets` /// `Location` vs `AssetIdForTrustBackedAssets` converter for `TrustBackedAssets`
pub type AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation> = pub type AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation, L = Location> =
AsPrefixedGeneralIndex< AsPrefixedGeneralIndex<
TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocation,
AssetIdForTrustBackedAssets, AssetIdForTrustBackedAssets,
JustTry, TryConvertInto,
xcm::v3::Location, L,
>; >;
pub type AssetIdForTrustBackedAssetsConvertLatest<TrustBackedAssetsPalletLocation> =
AsPrefixedGeneralIndex<TrustBackedAssetsPalletLocation, AssetIdForTrustBackedAssets, JustTry>;
/// `Location` vs `CollectionId` converter for `Uniques` /// `Location` vs `CollectionId` converter for `Uniques`
pub type CollectionIdForUniquesConvert<UniquesPalletLocation> = pub type CollectionIdForUniquesConvert<UniquesPalletLocation> =
AsPrefixedGeneralIndex<UniquesPalletLocation, CollectionId, JustTry>; AsPrefixedGeneralIndex<UniquesPalletLocation, CollectionId, TryConvertInto>;
/// [`MatchedConvertedConcreteId`] converter dedicated for `TrustBackedAssets` /// [`MatchedConvertedConcreteId`] converter dedicated for `TrustBackedAssets`
pub type TrustBackedAssetsConvertedConcreteId<TrustBackedAssetsPalletLocation, Balance> = pub type TrustBackedAssetsConvertedConcreteId<
MatchedConvertedConcreteId< TrustBackedAssetsPalletLocation,
Balance,
L = Location,
> = MatchedConvertedConcreteId<
AssetIdForTrustBackedAssets, AssetIdForTrustBackedAssets,
Balance, Balance,
StartsWith<TrustBackedAssetsPalletLocation>, StartsWith<TrustBackedAssetsPalletLocation>,
AssetIdForTrustBackedAssetsConvertLatest<TrustBackedAssetsPalletLocation>, AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation, L>,
JustTry, TryConvertInto,
>; >;
/// [`MatchedConvertedConcreteId`] converter dedicated for `Uniques` /// [`MatchedConvertedConcreteId`] converter dedicated for `Uniques`
pub type UniquesConvertedConcreteId<UniquesPalletLocation> = MatchedConvertedConcreteId< pub type UniquesConvertedConcreteId<UniquesPalletLocation> = MatchedConvertedConcreteId<
@@ -65,27 +66,25 @@ pub type UniquesConvertedConcreteId<UniquesPalletLocation> = MatchedConvertedCon
// junction within the pallet itself. // junction within the pallet itself.
StartsWith<UniquesPalletLocation>, StartsWith<UniquesPalletLocation>,
CollectionIdForUniquesConvert<UniquesPalletLocation>, CollectionIdForUniquesConvert<UniquesPalletLocation>,
JustTry, TryConvertInto,
>; >;
/// [`MatchedConvertedConcreteId`] converter dedicated for storing `AssetId` as `Location`. /// [`MatchedConvertedConcreteId`] converter dedicated for `TrustBackedAssets`,
pub type LocationConvertedConcreteId<LocationFilter, Balance> = MatchedConvertedConcreteId< /// it is a similar implementation to `TrustBackedAssetsConvertedConcreteId`,
xcm::v3::Location, /// but it converts `AssetId` to `xcm::v*::Location` type instead of `AssetIdForTrustBackedAssets =
/// u32`
pub type TrustBackedAssetsAsLocation<
TrustBackedAssetsPalletLocation,
Balance, Balance,
LocationFilter, L,
V4V3LocationConverter, LocationConverter = WithLatestLocationConverter<L>,
JustTry, > = MatchedConvertedConcreteId<
>; L,
/// [`MatchedConvertedConcreteId`] converter dedicated for `TrustBackedAssets`
pub type TrustBackedAssetsAsLocation<TrustBackedAssetsPalletLocation, Balance> =
MatchedConvertedConcreteId<
xcm::v3::Location,
Balance, Balance,
StartsWith<TrustBackedAssetsPalletLocation>, StartsWith<TrustBackedAssetsPalletLocation>,
V4V3LocationConverter, LocationConverter,
JustTry, TryConvertInto,
>; >;
/// [`MatchedConvertedConcreteId`] converter dedicated for storing `ForeignAssets` with `AssetId` as /// [`MatchedConvertedConcreteId`] converter dedicated for storing `ForeignAssets` with `AssetId` as
/// `Location`. /// `Location`.
@@ -95,8 +94,15 @@ pub type TrustBackedAssetsAsLocation<TrustBackedAssetsPalletLocation, Balance> =
/// - all local Locations /// - all local Locations
/// ///
/// `AdditionalLocationExclusionFilter` can customize additional excluded Locations /// `AdditionalLocationExclusionFilter` can customize additional excluded Locations
pub type ForeignAssetsConvertedConcreteId<AdditionalLocationExclusionFilter, Balance> = pub type ForeignAssetsConvertedConcreteId<
LocationConvertedConcreteId< AdditionalLocationExclusionFilter,
Balance,
AssetId,
LocationToAssetIdConverter = WithLatestLocationConverter<AssetId>,
BalanceConverter = TryConvertInto,
> = MatchedConvertedConcreteId<
AssetId,
Balance,
EverythingBut<( EverythingBut<(
// Excludes relay/parent chain currency // Excludes relay/parent chain currency
Equals<ParentLocation>, Equals<ParentLocation>,
@@ -108,13 +114,14 @@ pub type ForeignAssetsConvertedConcreteId<AdditionalLocationExclusionFilter, Bal
// Here we can exclude more stuff or leave it as `()` // Here we can exclude more stuff or leave it as `()`
AdditionalLocationExclusionFilter, AdditionalLocationExclusionFilter,
)>, )>,
Balance, LocationToAssetIdConverter,
>; BalanceConverter,
>;
type AssetIdForPoolAssets = u32; type AssetIdForPoolAssets = u32;
/// `Location` vs `AssetIdForPoolAssets` converter for `PoolAssets`. /// `Location` vs `AssetIdForPoolAssets` converter for `PoolAssets`.
pub type AssetIdForPoolAssetsConvert<PoolAssetsPalletLocation> = pub type AssetIdForPoolAssetsConvert<PoolAssetsPalletLocation> =
AsPrefixedGeneralIndex<PoolAssetsPalletLocation, AssetIdForPoolAssets, JustTry>; AsPrefixedGeneralIndex<PoolAssetsPalletLocation, AssetIdForPoolAssets, TryConvertInto>;
/// [`MatchedConvertedConcreteId`] converter dedicated for `PoolAssets` /// [`MatchedConvertedConcreteId`] converter dedicated for `PoolAssets`
pub type PoolAssetsConvertedConcreteId<PoolAssetsPalletLocation, Balance> = pub type PoolAssetsConvertedConcreteId<PoolAssetsPalletLocation, Balance> =
MatchedConvertedConcreteId< MatchedConvertedConcreteId<
@@ -122,7 +129,7 @@ pub type PoolAssetsConvertedConcreteId<PoolAssetsPalletLocation, Balance> =
Balance, Balance,
StartsWith<PoolAssetsPalletLocation>, StartsWith<PoolAssetsPalletLocation>,
AssetIdForPoolAssetsConvert<PoolAssetsPalletLocation>, AssetIdForPoolAssetsConvert<PoolAssetsPalletLocation>,
JustTry, TryConvertInto,
>; >;
#[cfg(test)] #[cfg(test)]
@@ -130,7 +137,7 @@ mod tests {
use super::*; use super::*;
use sp_runtime::traits::MaybeEquivalence; use sp_runtime::traits::MaybeEquivalence;
use xcm::prelude::*; use xcm::prelude::*;
use xcm_builder::StartsWithExplicitGlobalConsensus; use xcm_builder::{StartsWithExplicitGlobalConsensus, WithLatestLocationConverter};
use xcm_executor::traits::{Error as MatchError, MatchesFungibles}; use xcm_executor::traits::{Error as MatchError, MatchesFungibles};
#[test] #[test]
@@ -143,14 +150,14 @@ mod tests {
Location::new(5, [PalletInstance(13), GeneralIndex(local_asset_id.into())]); Location::new(5, [PalletInstance(13), GeneralIndex(local_asset_id.into())]);
assert_eq!( assert_eq!(
AssetIdForTrustBackedAssetsConvertLatest::<TrustBackedAssetsPalletLocation>::convert_back( AssetIdForTrustBackedAssetsConvert::<TrustBackedAssetsPalletLocation>::convert_back(
&local_asset_id &local_asset_id
) )
.unwrap(), .unwrap(),
expected_reverse_ref expected_reverse_ref
); );
assert_eq!( assert_eq!(
AssetIdForTrustBackedAssetsConvertLatest::<TrustBackedAssetsPalletLocation>::convert( AssetIdForTrustBackedAssetsConvert::<TrustBackedAssetsPalletLocation>::convert(
&expected_reverse_ref &expected_reverse_ref
) )
.unwrap(), .unwrap(),
@@ -163,7 +170,7 @@ mod tests {
frame_support::parameter_types! { frame_support::parameter_types! {
pub TrustBackedAssetsPalletLocation: Location = Location::new(0, [PalletInstance(13)]); pub TrustBackedAssetsPalletLocation: Location = Location::new(0, [PalletInstance(13)]);
} }
// setup convert // set up a converter
type TrustBackedAssetsConvert = type TrustBackedAssetsConvert =
TrustBackedAssetsConvertedConcreteId<TrustBackedAssetsPalletLocation, u128>; TrustBackedAssetsConvertedConcreteId<TrustBackedAssetsPalletLocation, u128>;
@@ -246,19 +253,21 @@ mod tests {
} }
#[test] #[test]
fn location_converted_concrete_id_converter_works() { fn foreign_assets_converted_concrete_id_converter_works() {
frame_support::parameter_types! { frame_support::parameter_types! {
pub Parachain100Pattern: Location = Location::new(1, [Parachain(100)]); pub Parachain100Pattern: Location = Location::new(1, [Parachain(100)]);
pub UniversalLocationNetworkId: NetworkId = NetworkId::ByGenesis([9; 32]); pub UniversalLocationNetworkId: NetworkId = NetworkId::ByGenesis([9; 32]);
} }
// setup convert // set up a converter which uses `xcm::v3::Location` under the hood
type Convert = ForeignAssetsConvertedConcreteId< type Convert = ForeignAssetsConvertedConcreteId<
( (
StartsWith<Parachain100Pattern>, StartsWith<Parachain100Pattern>,
StartsWithExplicitGlobalConsensus<UniversalLocationNetworkId>, StartsWithExplicitGlobalConsensus<UniversalLocationNetworkId>,
), ),
u128, u128,
xcm::v3::Location,
WithLatestLocationConverter<xcm::v3::Location>,
>; >;
let test_data = vec![ let test_data = vec![
@@ -78,7 +78,7 @@ pub type LocationToAccountId = (
); );
/// Means for transacting the native currency on this chain. /// Means for transacting the native currency on this chain.
pub type CurrencyTransactor = FungibleAdapter< pub type FungibleTransactor = FungibleAdapter<
// Use this currency: // Use this currency:
Balances, Balances,
// Use this currency when it is a fungible asset matching the given location or name: // Use this currency when it is a fungible asset matching the given location or name:
@@ -171,7 +171,7 @@ pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig { impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall; type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter; type XcmSender = XcmRouter;
type AssetTransactor = CurrencyTransactor; type AssetTransactor = FungibleTransactor;
type OriginConverter = XcmOriginToTransactDispatchOrigin; type OriginConverter = XcmOriginToTransactDispatchOrigin;
type IsReserve = NativeAsset; type IsReserve = NativeAsset;
type IsTeleporter = TrustedTeleporter; type IsTeleporter = TrustedTeleporter;
@@ -77,7 +77,7 @@ pub type LocationToAccountId = (
); );
/// Means for transacting the native currency on this chain. /// Means for transacting the native currency on this chain.
pub type CurrencyTransactor = FungibleAdapter< pub type FungibleTransactor = FungibleAdapter<
// Use this currency: // Use this currency:
Balances, Balances,
// Use this currency when it is a fungible asset matching the given location or name: // Use this currency when it is a fungible asset matching the given location or name:
@@ -106,7 +106,7 @@ pub type RegionTransactor = NonFungibleAdapter<
>; >;
/// Means for transacting assets on this chain. /// Means for transacting assets on this chain.
pub type AssetTransactors = (CurrencyTransactor, RegionTransactor); pub type AssetTransactors = (FungibleTransactor, RegionTransactor);
/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
/// ready for dispatching a transaction with XCM's `Transact`. There is an `OriginKind` that can /// ready for dispatching a transaction with XCM's `Transact`. There is an `OriginKind` that can
@@ -72,18 +72,14 @@ use sp_std::prelude::*;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use sp_version::NativeVersion; use sp_version::NativeVersion;
use sp_version::RuntimeVersion; use sp_version::RuntimeVersion;
use xcm_config::XcmOriginToTransactDispatchOrigin; use xcm_config::{ForeignAssetsAssetId, XcmOriginToTransactDispatchOrigin};
#[cfg(any(feature = "std", test))] #[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage; pub use sp_runtime::BuildStorage;
// Polkadot imports
use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
// XCM Imports
use parachains_common::{AccountId, Signature}; use parachains_common::{AccountId, Signature};
use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
use xcm::latest::prelude::{AssetId as AssetLocationId, BodyId}; use xcm::latest::prelude::{AssetId as AssetLocationId, BodyId};
/// Balance of an account. /// Balance of an account.
@@ -474,8 +470,8 @@ pub type ForeignAssetsInstance = pallet_assets::Instance2;
impl pallet_assets::Config<ForeignAssetsInstance> for Runtime { impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent; type RuntimeEvent = RuntimeEvent;
type Balance = Balance; type Balance = Balance;
type AssetId = xcm::v3::Location; type AssetId = ForeignAssetsAssetId;
type AssetIdParameter = xcm::v3::Location; type AssetIdParameter = ForeignAssetsAssetId;
type Currency = Balances; type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>; type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = EnsureRoot<AccountId>; type ForceOrigin = EnsureRoot<AccountId>;
@@ -40,7 +40,7 @@ use pallet_xcm::XcmPassthrough;
use parachains_common::{xcm_config::AssetFeeAsExistentialDepositMultiplier, TREASURY_PALLET_ID}; use parachains_common::{xcm_config::AssetFeeAsExistentialDepositMultiplier, TREASURY_PALLET_ID};
use polkadot_parachain_primitives::primitives::Sibling; use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::{impls::ToAuthor, xcm_sender::ExponentialPrice}; use polkadot_runtime_common::{impls::ToAuthor, xcm_sender::ExponentialPrice};
use sp_runtime::traits::{AccountIdConversion, ConvertInto}; use sp_runtime::traits::{AccountIdConversion, ConvertInto, Identity, TryConvertInto};
use xcm::latest::prelude::*; use xcm::latest::prelude::*;
use xcm_builder::{ use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
@@ -84,7 +84,7 @@ pub type LocationToAccountId = (
); );
/// Means for transacting assets on this chain. /// Means for transacting assets on this chain.
pub type CurrencyTransactor = FungibleAdapter< pub type FungibleTransactor = FungibleAdapter<
// Use this currency: // Use this currency:
Balances, Balances,
// Use this currency when it is a fungible asset matching the given location or name: // Use this currency when it is a fungible asset matching the given location or name:
@@ -131,7 +131,11 @@ pub type FungiblesTransactor = FungiblesAdapter<
CheckingAccount, CheckingAccount,
>; >;
pub type ForeignAssetsConvertedConcreteId = assets_common::LocationConvertedConcreteId< // Using the latest `Location`, we don't need to worry about migrations for Penpal.
pub type ForeignAssetsAssetId = Location;
pub type ForeignAssetsConvertedConcreteId = xcm_builder::MatchedConvertedConcreteId<
Location,
Balance,
EverythingBut<( EverythingBut<(
// Here we rely on fact that something like this works: // Here we rely on fact that something like this works:
// assert!(Location::new(1, // assert!(Location::new(1,
@@ -139,7 +143,8 @@ pub type ForeignAssetsConvertedConcreteId = assets_common::LocationConvertedConc
// assert!([Parachain(100)].into().starts_with(&Here)); // assert!([Parachain(100)].into().starts_with(&Here));
StartsWith<assets_common::matching::LocalLocationPattern>, StartsWith<assets_common::matching::LocalLocationPattern>,
)>, )>,
Balance, Identity,
TryConvertInto,
>; >;
/// Means for transacting foreign assets from different global consensus. /// Means for transacting foreign assets from different global consensus.
@@ -159,7 +164,7 @@ pub type ForeignFungiblesTransactor = FungiblesAdapter<
>; >;
/// Means for transacting assets on this chain. /// Means for transacting assets on this chain.
pub type AssetTransactors = (CurrencyTransactor, ForeignFungiblesTransactor, FungiblesTransactor); pub type AssetTransactors = (FungibleTransactor, ForeignFungiblesTransactor, FungiblesTransactor);
/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can /// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can
@@ -416,8 +421,8 @@ impl cumulus_pallet_xcm::Config for Runtime {
/// Simple conversion of `u32` into an `AssetId` for use in benchmarking. /// Simple conversion of `u32` into an `AssetId` for use in benchmarking.
pub struct XcmBenchmarkHelper; pub struct XcmBenchmarkHelper;
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
impl pallet_assets::BenchmarkHelper<xcm::v3::Location> for XcmBenchmarkHelper { impl pallet_assets::BenchmarkHelper<ForeignAssetsAssetId> for XcmBenchmarkHelper {
fn create_asset_id_parameter(id: u32) -> xcm::v3::Location { fn create_asset_id_parameter(id: u32) -> ForeignAssetsAssetId {
xcm::v3::Location::new(1, [xcm::v3::Junction::Parachain(id)]) Location::new(1, [Parachain(id)])
} }
} }
@@ -346,7 +346,7 @@ pub type LocationToAccountId = (
); );
/// Means for transacting assets on this chain. /// Means for transacting assets on this chain.
pub type CurrencyTransactor = FungibleAdapter< pub type FungibleTransactor = FungibleAdapter<
// Use this currency: // Use this currency:
Balances, Balances,
// Use this currency when it is a fungible asset matching the given location or name: // Use this currency when it is a fungible asset matching the given location or name:
@@ -385,7 +385,7 @@ pub type FungiblesTransactor = FungiblesAdapter<
CheckingAccount, CheckingAccount,
>; >;
/// Means for transacting assets on this chain. /// Means for transacting assets on this chain.
pub type AssetTransactors = (CurrencyTransactor, FungiblesTransactor); pub type AssetTransactors = (FungibleTransactor, FungiblesTransactor);
/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can /// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can
@@ -107,17 +107,6 @@ impl<
#[deprecated = "Use `ConvertedConcreteId` instead"] #[deprecated = "Use `ConvertedConcreteId` instead"]
pub type ConvertedConcreteAssetId<A, B, C, O> = ConvertedConcreteId<A, B, C, O>; pub type ConvertedConcreteAssetId<A, B, C, O> = ConvertedConcreteId<A, B, C, O>;
pub struct V4V3LocationConverter;
impl MaybeEquivalence<xcm::v4::Location, xcm::v3::Location> for V4V3LocationConverter {
fn convert(old: &xcm::v4::Location) -> Option<xcm::v3::Location> {
(*old).clone().try_into().ok()
}
fn convert_back(new: &xcm::v3::Location) -> Option<xcm::v4::Location> {
(*new).try_into().ok()
}
}
pub struct MatchedConvertedConcreteId<AssetId, Balance, MatchAssetId, ConvertAssetId, ConvertOther>( pub struct MatchedConvertedConcreteId<AssetId, Balance, MatchAssetId, ConvertAssetId, ConvertOther>(
PhantomData<(AssetId, Balance, MatchAssetId, ConvertAssetId, ConvertOther)>, PhantomData<(AssetId, Balance, MatchAssetId, ConvertAssetId, ConvertOther)>,
); );
+4 -2
View File
@@ -30,7 +30,7 @@ mod asset_conversion;
#[allow(deprecated)] #[allow(deprecated)]
pub use asset_conversion::ConvertedConcreteAssetId; pub use asset_conversion::ConvertedConcreteAssetId;
pub use asset_conversion::{ pub use asset_conversion::{
AsPrefixedGeneralIndex, ConvertedConcreteId, MatchedConvertedConcreteId, V4V3LocationConverter, AsPrefixedGeneralIndex, ConvertedConcreteId, MatchedConvertedConcreteId,
}; };
mod barriers; mod barriers;
@@ -81,7 +81,9 @@ pub use location_conversion::{
}; };
mod matches_location; mod matches_location;
pub use matches_location::{StartsWith, StartsWithExplicitGlobalConsensus}; pub use matches_location::{
StartsWith, StartsWithExplicitGlobalConsensus, WithLatestLocationConverter,
};
mod matches_token; mod matches_token;
pub use matches_token::IsConcrete; pub use matches_token::IsConcrete;
@@ -18,6 +18,8 @@
//! `InteriorLocation` types. //! `InteriorLocation` types.
use frame_support::traits::{Contains, Get}; use frame_support::traits::{Contains, Get};
use sp_runtime::traits::MaybeEquivalence;
use sp_std::marker::PhantomData;
use xcm::latest::{InteriorLocation, Location, NetworkId}; use xcm::latest::{InteriorLocation, Location, NetworkId};
/// An implementation of `Contains` that checks for `Location` or /// An implementation of `Contains` that checks for `Location` or
@@ -51,3 +53,18 @@ impl<T: Get<NetworkId>> Contains<InteriorLocation> for StartsWithExplicitGlobalC
matches!(location.global_consensus(), Ok(requested_network) if requested_network.eq(&T::get())) matches!(location.global_consensus(), Ok(requested_network) if requested_network.eq(&T::get()))
} }
} }
/// An adapter implementation of `MaybeEquivalence` which can convert between the latest `Location`
/// and other versions that implement `TryInto<Location>` and `TryFrom<Location>`.
pub struct WithLatestLocationConverter<Target>(PhantomData<Target>);
impl<Target: TryInto<Location> + TryFrom<Location> + Clone> MaybeEquivalence<Location, Target>
for WithLatestLocationConverter<Target>
{
fn convert(old: &Location) -> Option<Target> {
(*old).clone().try_into().ok()
}
fn convert_back(new: &Target) -> Option<Location> {
new.clone().try_into().ok()
}
}
+26
View File
@@ -0,0 +1,26 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
title: "Remove `xcm::v3` from `assets-common` nits"
doc:
- audience: Runtime Dev
description: |
Remove `xcm::v3` imports from `assets-common` to make it more generic and facilitate the transition to newer XCM versions.
The implementations `AssetIdForTrustBackedAssetsConvert`, `ForeignAssetsConvertedConcreteId`, or `TrustBackedAssetsAsLocation`
used hard-coded `xcm::v3::Location`, which has been changed to use `xcm::latest::Location` by default.
Alternatively, the providing runtime can configure them according to its needs, such as with a lower XCM version.
Example:
```patch
- AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocationV3>,
+ AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocationV3, xcm::v3::Location>,
```
Another change is that the removed `xcm_builder::V4V3LocationConverter` can be replaced with `WithLatestLocationConverter`.
crates:
- name: assets-common
bump: patch
- name: staging-xcm-builder
bump: patch