Skip to content

Commit

Permalink
Swaps for XCM delivery fees (#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
#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.
  • Loading branch information
x3c41a committed Sep 4, 2024
1 parent 16e9c0f commit db7ed6d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion polkadot/xcm/xcm-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub struct XcmExecutor<Config: config::Config> {
/// Stores the current message's weight.
message_weight: Weight,
_config: PhantomData<Config>,
assetClaimer: Option<Location>,
}

#[cfg(any(test, feature = "runtime-benchmarks"))]
Expand Down Expand Up @@ -357,7 +358,11 @@ impl<Config: config::Config> XcmExecutor<Config> {
original_origin = ?self.original_origin,
"Trapping assets in holding register",
);
let effective_origin = self.context.origin.as_ref().unwrap_or(&self.original_origin);
let effective_orgin = if let Some(assetClaimer) = self.assetClaimer {
assetClaimer.as_ref().unwrap_or(&self.original_origin)
} else {
self.context.origin.as_ref().unwrap_or(&self.original_origin)
};
let trap_weight =
Config::AssetTrap::drop_assets(effective_origin, self.holding, &self.context);
weight_used.saturating_accrue(trap_weight);
Expand Down Expand Up @@ -1065,6 +1070,10 @@ impl<Config: config::Config> XcmExecutor<Config> {
self.error = None;
Ok(())
},
SetAssetClaimer { location } => {
self.assetClaimer = Some(location);
Ok(())
},
ClaimAsset { assets, ticket } => {
let origin = self.origin_ref().ok_or(XcmError::BadOrigin)?;
self.ensure_can_subsume_assets(assets.len())?;
Expand Down

0 comments on commit db7ed6d

Please sign in to comment.