Skip to content

Commit 5291412

Browse files
Swaps for XCM delivery fees (#5131)
# Context Fees can already be paid in other assets locally thanks to the Trader implementations we have. This doesn't work when sending messages because delivery fees go through a different mechanism altogether. The idea is to fix this leveraging the `AssetExchanger` config item that's able to turn the asset the user wants to pay fees in into the asset the router expects for delivery fees. # Main addition An adapter was needed to use `pallet-asset-conversion` for exchanging assets in XCM. This was created in #5130. The XCM executor was modified to use `AssetExchanger` (when available) to swap assets to pay for delivery fees. ## Limitations We can only pay for delivery fees in different assets in intermediate hops. We can't pay in different assets locally. The first hop will always need the native token of the chain (or whatever is specified in the `XcmRouter`). This is a byproduct of using the `BuyExecution` instruction to know which asset should be used for delivery fee payment. Since this instruction is not present when executing an XCM locally, we are left with this limitation. To illustrate this limitation, I'll show two scenarios. All chains involved have pools. ### Scenario 1 Parachain A --> Parachain B Here, parachain A can use any asset in a pool with its native asset to pay for local execution fees. However, as of now we can't use those for local delivery fees. This means transfers from A to B need some amount of A's native token to pay for delivery fees. ### Scenario 2 Parachain A --> Parachain C --> Parachain B Here, Parachain C's remote delivery fees can be paid with any asset in a pool with its native asset. This allows a reserve asset transfer between A and B with C as the reserve to only need A's native token at the starting hop. After that, it could all be pool assets. ## Future work The fact that delivery fees go through a totally different mechanism results in a lot of bugs and pain points. Unfortunately, this is not so easy to solve in a backwards compatible manner. Delivery fees will be integrated into the language in future XCM versions, following polkadot-fellows/xcm-format#53. Old PR: #4375.
1 parent 6b854ac commit 5291412

File tree

20 files changed

+1259
-71
lines changed

20 files changed

+1259
-71
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use parachains_common::{AccountId, Balance};
2727

2828
pub const PARA_ID: u32 = 1000;
2929
pub const ED: Balance = testnet_parachains_constants::westend::currency::EXISTENTIAL_DEPOSIT;
30+
pub const USDT_ED: Balance = 70_000;
3031

3132
parameter_types! {
3233
pub AssetHubWestendAssetOwner: AccountId = get_account_id_from_seed::<sr25519::Public>("Alice");
@@ -67,7 +68,7 @@ pub fn genesis() -> Storage {
6768
assets: asset_hub_westend_runtime::AssetsConfig {
6869
assets: vec![
6970
(RESERVABLE_ASSET_ID, AssetHubWestendAssetOwner::get(), false, ED),
70-
(USDT_ID, AssetHubWestendAssetOwner::get(), true, ED),
71+
(USDT_ID, AssetHubWestendAssetOwner::get(), true, USDT_ED),
7172
],
7273
..Default::default()
7374
},

cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use penpal_runtime::xcm_config::{LocalReservableFromAssetHub, RelayLocation, Usd
2727
pub const PARA_ID_A: u32 = 2000;
2828
pub const PARA_ID_B: u32 = 2001;
2929
pub const ED: Balance = penpal_runtime::EXISTENTIAL_DEPOSIT;
30+
pub const USDT_ED: Balance = 70_000;
3031

3132
parameter_types! {
3233
pub PenpalSudoAccount: AccountId = get_account_id_from_seed::<sr25519::Public>("Alice");
@@ -81,8 +82,8 @@ pub fn genesis(para_id: u32) -> Storage {
8182
(RelayLocation::get(), PenpalAssetOwner::get(), true, ED),
8283
// Sufficient AssetHub asset representation
8384
(LocalReservableFromAssetHub::get(), PenpalAssetOwner::get(), true, ED),
84-
// USDT from Asset Hub
85-
(UsdtFromAssetHub::get(), PenpalAssetOwner::get(), true, ED),
85+
// USDT from AssetHub
86+
(UsdtFromAssetHub::get(), PenpalAssetOwner::get(), true, USDT_ED),
8687
],
8788
..Default::default()
8889
},

cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ decl_test_parachains! {
5353
PolkadotXcm: penpal_runtime::PolkadotXcm,
5454
Assets: penpal_runtime::Assets,
5555
ForeignAssets: penpal_runtime::ForeignAssets,
56+
AssetConversion: penpal_runtime::AssetConversion,
5657
Balances: penpal_runtime::Balances,
5758
}
5859
},
@@ -76,6 +77,7 @@ decl_test_parachains! {
7677
PolkadotXcm: penpal_runtime::PolkadotXcm,
7778
Assets: penpal_runtime::Assets,
7879
ForeignAssets: penpal_runtime::ForeignAssets,
80+
AssetConversion: penpal_runtime::AssetConversion,
7981
Balances: penpal_runtime::Balances,
8082
}
8183
},

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ mod imports {
6666
CustomizableAssetFromSystemAssetHub as PenpalCustomizableAssetFromSystemAssetHub,
6767
LocalReservableFromAssetHub as PenpalLocalReservableFromAssetHub,
6868
LocalTeleportableToAssetHub as PenpalLocalTeleportableToAssetHub,
69+
UsdtFromAssetHub as PenpalUsdtFromAssetHub,
6970
},
7071
PenpalAParaPallet as PenpalAPallet, PenpalAssetOwner,
7172
PenpalBParaPallet as PenpalBPallet, ED as PENPAL_ED,

0 commit comments

Comments
 (0)