Skip to content

Commit dcc7652

Browse files
muharemsvyatonik
andauthored
Westend/Rococo Asset Hub: pay xcm fees with sufficient assets (paritytech#2978)
Set up the `TakeFirstAssetTrader` trader for Westend and Rococo Asset Hubs to cover XCM fees with sufficient assets. This PR reintroduces previously [removed](paritytech#1845) trader setups, as it was decided to keep both traders, `TakeFirstAssetTrader` and `SwapFirstAssetTrader`, during the transition period. --------- Co-authored-by: Svyatoslav Nikolsky <[email protected]>
1 parent 13f2342 commit dcc7652

File tree

8 files changed

+1071
-32
lines changed

8 files changed

+1071
-32
lines changed

bridges/zombienet/tests/0001-asset-transfer-works-rococo-to-westend.zndsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bridge-hub-westend-collator1: js-script ../helpers/best-finalized-header-at-brid
1414

1515
# step 4: send WND to //Alice on Rococo AH
1616
# (that's a required part of a sibling 0001-asset-transfer-works-westend-to-rococo.zndsl test)
17-
asset-hub-westend-collator1: run ../scripts/invoke-script.sh with "reserve-transfer-assets-from-asset-hub-westend-local" within 60 seconds
17+
asset-hub-westend-collator1: run ../scripts/invoke-script.sh with "reserve-transfer-assets-from-asset-hub-westend-local" within 120 seconds
1818

1919
# step 5: elsewhere Rococo has sent ROC to //Alice - let's wait for it
2020
asset-hub-westend-collator1: js-script ../helpers/wrapped-assets-balance.js with "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY,0,Rococo" within 600 seconds
@@ -24,7 +24,7 @@ bridge-hub-westend-collator1: js-script ../helpers/relayer-rewards.js with "5FLS
2424
bridge-hub-westend-collator1: js-script ../helpers/relayer-rewards.js with "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y,0x00000002,0x6268726F,ThisChain,0" within 300 seconds
2525

2626
# step 7: send wROC back to Alice at Rococo AH
27-
asset-hub-westend-collator1: run ../scripts/invoke-script.sh with "withdraw-reserve-assets-from-asset-hub-westend-local" within 60 seconds
27+
asset-hub-westend-collator1: run ../scripts/invoke-script.sh with "withdraw-reserve-assets-from-asset-hub-westend-local" within 120 seconds
2828

2929
# step 8: elsewhere Rococo has sent wWND to //Alice - let's wait for it
3030
# (we wait until //Alice account increases here - there are no other transactionc that may increase it)

bridges/zombienet/tests/0001-asset-transfer-works-westend-to-rococo.zndsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bridge-hub-rococo-collator1: js-script ../helpers/best-finalized-header-at-bridg
1414

1515
# step 4: send ROC to //Alice on Westend AH
1616
# (that's a required part of a sibling 0001-asset-transfer-works-rococo-to-westend.zndsl test)
17-
asset-hub-rococo-collator1: run ../scripts/invoke-script.sh with "reserve-transfer-assets-from-asset-hub-rococo-local" within 60 seconds
17+
asset-hub-rococo-collator1: run ../scripts/invoke-script.sh with "reserve-transfer-assets-from-asset-hub-rococo-local" within 120 seconds
1818

1919
# step 5: elsewhere Westend has sent WND to //Alice - let's wait for it
2020
asset-hub-rococo-collator1: js-script ../helpers/wrapped-assets-balance.js with "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY,0,Westend" within 600 seconds
@@ -24,7 +24,7 @@ bridge-hub-rococo-collator1: js-script ../helpers/relayer-rewards.js with "5FLSi
2424
bridge-hub-rococo-collator1: js-script ../helpers/relayer-rewards.js with "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y,0x00000002,0x62687764,ThisChain,0" within 300 seconds
2525

2626
# step 7: send wWND back to Alice at Westend AH
27-
asset-hub-rococo-collator1: run ../scripts/invoke-script.sh with "withdraw-reserve-assets-from-asset-hub-rococo-local" within 60 seconds
27+
asset-hub-rococo-collator1: run ../scripts/invoke-script.sh with "withdraw-reserve-assets-from-asset-hub-rococo-local" within 120 seconds
2828

2929
# step 8: elsewhere Westend has sent wROC to //Alice - let's wait for it
3030
# (we wait until //Alice account increases here - there are no other transactionc that may increase it)

cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,78 @@ fn send_transact_as_superuser_from_relay_to_system_para_works() {
2727
Some(Weight::from_parts(1_019_445_000, 200_000)),
2828
)
2929
}
30+
31+
/// Parachain should be able to send XCM paying its fee with sufficient asset
32+
/// in the System Parachain
33+
#[test]
34+
fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() {
35+
let para_sovereign_account = AssetHubRococo::sovereign_account_id_of(
36+
AssetHubRococo::sibling_location_of(PenpalA::para_id()),
37+
);
38+
39+
// Force create and mint assets for Parachain's sovereign account
40+
AssetHubRococo::force_create_and_mint_asset(
41+
ASSET_ID,
42+
ASSET_MIN_BALANCE,
43+
true,
44+
para_sovereign_account.clone(),
45+
Some(Weight::from_parts(1_019_445_000, 200_000)),
46+
ASSET_MIN_BALANCE * 1000000000,
47+
);
48+
49+
// We just need a call that can pass the `SafeCallFilter`
50+
// Call values are not relevant
51+
let call = AssetHubRococo::force_create_asset_call(
52+
ASSET_ID,
53+
para_sovereign_account.clone(),
54+
true,
55+
ASSET_MIN_BALANCE,
56+
);
57+
58+
let origin_kind = OriginKind::SovereignAccount;
59+
let fee_amount = ASSET_MIN_BALANCE * 1000000;
60+
let native_asset =
61+
([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], fee_amount).into();
62+
63+
let root_origin = <PenpalA as Chain>::RuntimeOrigin::root();
64+
let system_para_destination = PenpalA::sibling_location_of(AssetHubRococo::para_id()).into();
65+
let xcm = xcm_transact_paid_execution(
66+
call,
67+
origin_kind,
68+
native_asset,
69+
para_sovereign_account.clone(),
70+
);
71+
72+
PenpalA::execute_with(|| {
73+
assert_ok!(<PenpalA as PenpalAPallet>::PolkadotXcm::send(
74+
root_origin,
75+
bx!(system_para_destination),
76+
bx!(xcm),
77+
));
78+
79+
PenpalA::assert_xcm_pallet_sent();
80+
});
81+
82+
AssetHubRococo::execute_with(|| {
83+
type RuntimeEvent = <AssetHubRococo as Chain>::RuntimeEvent;
84+
85+
AssetHubRococo::assert_xcmp_queue_success(Some(Weight::from_parts(
86+
15_594_564_000,
87+
562_893,
88+
)));
89+
90+
assert_expected_events!(
91+
AssetHubRococo,
92+
vec![
93+
RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => {
94+
asset_id: *asset_id == ASSET_ID,
95+
owner: *owner == para_sovereign_account,
96+
balance: *balance == fee_amount,
97+
},
98+
RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, .. }) => {
99+
asset_id: *asset_id == ASSET_ID,
100+
},
101+
]
102+
);
103+
});
104+
}

cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,78 @@ fn send_transact_as_superuser_from_relay_to_system_para_works() {
2727
Some(Weight::from_parts(1_019_445_000, 200_000)),
2828
)
2929
}
30+
31+
/// Parachain should be able to send XCM paying its fee with sufficient asset
32+
/// in the System Parachain
33+
#[test]
34+
fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() {
35+
let para_sovereign_account = AssetHubWestend::sovereign_account_id_of(
36+
AssetHubWestend::sibling_location_of(PenpalB::para_id()),
37+
);
38+
39+
// Force create and mint assets for Parachain's sovereign account
40+
AssetHubWestend::force_create_and_mint_asset(
41+
ASSET_ID,
42+
ASSET_MIN_BALANCE,
43+
true,
44+
para_sovereign_account.clone(),
45+
Some(Weight::from_parts(1_019_445_000, 200_000)),
46+
ASSET_MIN_BALANCE * 1000000000,
47+
);
48+
49+
// We just need a call that can pass the `SafeCallFilter`
50+
// Call values are not relevant
51+
let call = AssetHubWestend::force_create_asset_call(
52+
ASSET_ID,
53+
para_sovereign_account.clone(),
54+
true,
55+
ASSET_MIN_BALANCE,
56+
);
57+
58+
let origin_kind = OriginKind::SovereignAccount;
59+
let fee_amount = ASSET_MIN_BALANCE * 1000000;
60+
let native_asset =
61+
([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], fee_amount).into();
62+
63+
let root_origin = <PenpalB as Chain>::RuntimeOrigin::root();
64+
let system_para_destination = PenpalB::sibling_location_of(AssetHubWestend::para_id()).into();
65+
let xcm = xcm_transact_paid_execution(
66+
call,
67+
origin_kind,
68+
native_asset,
69+
para_sovereign_account.clone(),
70+
);
71+
72+
PenpalB::execute_with(|| {
73+
assert_ok!(<PenpalB as PenpalBPallet>::PolkadotXcm::send(
74+
root_origin,
75+
bx!(system_para_destination),
76+
bx!(xcm),
77+
));
78+
79+
PenpalB::assert_xcm_pallet_sent();
80+
});
81+
82+
AssetHubWestend::execute_with(|| {
83+
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
84+
85+
AssetHubWestend::assert_xcmp_queue_success(Some(Weight::from_parts(
86+
16_290_336_000,
87+
562_893,
88+
)));
89+
90+
assert_expected_events!(
91+
AssetHubWestend,
92+
vec![
93+
RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => {
94+
asset_id: *asset_id == ASSET_ID,
95+
owner: *owner == para_sovereign_account,
96+
balance: *balance == fee_amount,
97+
},
98+
RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, .. }) => {
99+
asset_id: *asset_id == ASSET_ID,
100+
},
101+
]
102+
);
103+
});
104+
}

cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,32 @@ impl xcm_executor::Config for XcmConfig {
585585
ResolveAssetTo<StakingPot, crate::NativeAndAssets>,
586586
AccountId,
587587
>,
588+
// This trader allows to pay with `is_sufficient=true` "Trust Backed" assets from dedicated
589+
// `pallet_assets` instance - `Assets`.
590+
cumulus_primitives_utility::TakeFirstAssetTrader<
591+
AccountId,
592+
AssetFeeAsExistentialDepositMultiplierFeeCharger,
593+
TrustBackedAssetsConvertedConcreteId,
594+
Assets,
595+
cumulus_primitives_utility::XcmFeesTo32ByteAccount<
596+
FungiblesTransactor,
597+
AccountId,
598+
XcmAssetFeesReceiver,
599+
>,
600+
>,
601+
// This trader allows to pay with `is_sufficient=true` "Foreign" assets from dedicated
602+
// `pallet_assets` instance - `ForeignAssets`.
603+
cumulus_primitives_utility::TakeFirstAssetTrader<
604+
AccountId,
605+
ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger,
606+
ForeignAssetsConvertedConcreteId,
607+
ForeignAssets,
608+
cumulus_primitives_utility::XcmFeesTo32ByteAccount<
609+
ForeignFungiblesTransactor,
610+
AccountId,
611+
XcmAssetFeesReceiver,
612+
>,
613+
>,
588614
);
589615
type ResponseHandler = PolkadotXcm;
590616
type AssetTrap = PolkadotXcm;

0 commit comments

Comments
 (0)