Skip to content

Commit

Permalink
Swaps for XCM delivery fees (paritytech#5131)
Browse files Browse the repository at this point in the history
# 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
paritytech#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: paritytech#4375.
  • Loading branch information
franciscoaguirre authored Sep 2, 2024
1 parent 6b854ac commit 5291412
Show file tree
Hide file tree
Showing 20 changed files with 1,259 additions and 71 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use parachains_common::{AccountId, Balance};

pub const PARA_ID: u32 = 1000;
pub const ED: Balance = testnet_parachains_constants::westend::currency::EXISTENTIAL_DEPOSIT;
pub const USDT_ED: Balance = 70_000;

parameter_types! {
pub AssetHubWestendAssetOwner: AccountId = get_account_id_from_seed::<sr25519::Public>("Alice");
Expand Down Expand Up @@ -67,7 +68,7 @@ pub fn genesis() -> Storage {
assets: asset_hub_westend_runtime::AssetsConfig {
assets: vec![
(RESERVABLE_ASSET_ID, AssetHubWestendAssetOwner::get(), false, ED),
(USDT_ID, AssetHubWestendAssetOwner::get(), true, ED),
(USDT_ID, AssetHubWestendAssetOwner::get(), true, USDT_ED),
],
..Default::default()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use penpal_runtime::xcm_config::{LocalReservableFromAssetHub, RelayLocation, Usd
pub const PARA_ID_A: u32 = 2000;
pub const PARA_ID_B: u32 = 2001;
pub const ED: Balance = penpal_runtime::EXISTENTIAL_DEPOSIT;
pub const USDT_ED: Balance = 70_000;

parameter_types! {
pub PenpalSudoAccount: AccountId = get_account_id_from_seed::<sr25519::Public>("Alice");
Expand Down Expand Up @@ -81,8 +82,8 @@ pub fn genesis(para_id: u32) -> Storage {
(RelayLocation::get(), PenpalAssetOwner::get(), true, ED),
// Sufficient AssetHub asset representation
(LocalReservableFromAssetHub::get(), PenpalAssetOwner::get(), true, ED),
// USDT from Asset Hub
(UsdtFromAssetHub::get(), PenpalAssetOwner::get(), true, ED),
// USDT from AssetHub
(UsdtFromAssetHub::get(), PenpalAssetOwner::get(), true, USDT_ED),
],
..Default::default()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ decl_test_parachains! {
PolkadotXcm: penpal_runtime::PolkadotXcm,
Assets: penpal_runtime::Assets,
ForeignAssets: penpal_runtime::ForeignAssets,
AssetConversion: penpal_runtime::AssetConversion,
Balances: penpal_runtime::Balances,
}
},
Expand All @@ -76,6 +77,7 @@ decl_test_parachains! {
PolkadotXcm: penpal_runtime::PolkadotXcm,
Assets: penpal_runtime::Assets,
ForeignAssets: penpal_runtime::ForeignAssets,
AssetConversion: penpal_runtime::AssetConversion,
Balances: penpal_runtime::Balances,
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ mod imports {
CustomizableAssetFromSystemAssetHub as PenpalCustomizableAssetFromSystemAssetHub,
LocalReservableFromAssetHub as PenpalLocalReservableFromAssetHub,
LocalTeleportableToAssetHub as PenpalLocalTeleportableToAssetHub,
UsdtFromAssetHub as PenpalUsdtFromAssetHub,
},
PenpalAParaPallet as PenpalAPallet, PenpalAssetOwner,
PenpalBParaPallet as PenpalBPallet, ED as PENPAL_ED,
Expand Down
Loading

0 comments on commit 5291412

Please sign in to comment.