Skip to content

Commit

Permalink
Add assets in pool with native to query_acceptable_payment_assets's r…
Browse files Browse the repository at this point in the history
…eturn (#5599)

`XcmPaymentApi::query_acceptable_payment_assets` is an API that returns
the assets that can be used to pay fees on the runtime where it's
called.
For relays and most system chains this was configured only as the native
asset: ROC and WND.
However, the asset hubs have the asset conversion pallet, which allows
fees to be paid in any asset in a pool with the native one.
This PR adds the list of assets in a pool with the native one to the
return value of this API for the asset hubs.

---------

Co-authored-by: Branislav Kontur <bkontur@gmail.com>
(cherry picked from commit d2ba567)
  • Loading branch information
franciscoaguirre authored and github-actions[bot] committed Oct 15, 2024
1 parent 61182fb commit d67ad13
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
18 changes: 17 additions & 1 deletion cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,23 @@ impl_runtime_apis! {

impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
let acceptable_assets = vec![AssetId(xcm_config::TokenLocation::get())];
let native_token = xcm_config::TokenLocation::get();
// We accept the native token to pay fees.
let mut acceptable_assets = vec![AssetId(native_token.clone())];
// We also accept all assets in a pool with the native token.
acceptable_assets.extend(
pallet_asset_conversion::Pools::<Runtime>::iter_keys().filter_map(
|(asset_1, asset_2)| {
if asset_1 == native_token {
Some(asset_2.clone().into())
} else if asset_2 == native_token {
Some(asset_1.clone().into())
} else {
None
}
},
),
);
PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)
}

Expand Down
18 changes: 17 additions & 1 deletion cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,23 @@ impl_runtime_apis! {

impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
let acceptable_assets = vec![AssetId(xcm_config::WestendLocation::get())];
let native_token = xcm_config::WestendLocation::get();
// We accept the native token to pay fees.
let mut acceptable_assets = vec![AssetId(native_token.clone())];
// We also accept all assets in a pool with the native token.
acceptable_assets.extend(
pallet_asset_conversion::Pools::<Runtime>::iter_keys().filter_map(
|(asset_1, asset_2)| {
if asset_1 == native_token {
Some(asset_2.clone().into())
} else if asset_2 == native_token {
Some(asset_1.clone().into())
} else {
None
}
},
),
);
PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)
}

Expand Down
19 changes: 19 additions & 0 deletions prdoc/pr_5599.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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: Add assets in pool with native to query_acceptable_payment_assets

doc:
- audience: Runtime Dev
description: |
The `XcmPaymentApi::query_acceptable_payment_assets` API can be used to get a list of all
the assets that can be used for fee payment.
This is usually just the native asset, but the asset hubs have the asset conversion pallet.
In the case of the asset hubs, this list now includes all assets in a liquidity pool with
the native one.

crates:
- name: asset-hub-rococo-runtime
bump: minor
- name: asset-hub-westend-runtime
bump: minor

0 comments on commit d67ad13

Please sign in to comment.