Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion polkadot/xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2669,8 +2669,9 @@ impl<T: Config> Pallet<T> {
pub fn query_delivery_fees(
destination: VersionedLocation,
message: VersionedXcm<()>,
custom_asset: VersionedAssetId,
) -> Result<VersionedAssets, XcmPaymentApiError> {
let result_version = destination.identify_version().max(message.identify_version());
let result_version = custom_asset.identify_version();

let destination: Location = destination
.clone()
Expand All @@ -2691,6 +2692,12 @@ impl<T: Config> Pallet<T> {
XcmPaymentApiError::Unroutable
})?;

// fees.into_inner().iter().for_each(|asset| {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acatangiu how can I convert fee to new asset corresponding custom_asset without introduce new dependency?

@acatangiu acatangiu Jan 16, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't change pallet_xcm::query_delivery_fees() - it provides delivery fee as X DOT

you change xcm_runtime_apis::fees::XcmPaymentApi implementation fn query_delivery_fees(dest, msg, asset_id) to convert X DOT to Y custom_asset using assets_common::PoolAdapter::::quote_price_tokens_for_exact_tokens()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to change the XcmPaymentApi to take custom asset_id for delivery fees.

You can either change existing fn query_delivery_fees() - which would be a API breaking change - or you can add a new function..

RuntimeAPIs are versioned so it's not a big deal to break them, but not sure which one's better. @franciscoaguirre thoughts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to change the XcmPaymentApi to take custom asset_id for delivery fees.

You can either change existing fn query_delivery_fees() - which would be a API breaking change - or you can add a new function..

RuntimeAPIs are versioned so it's not a big deal to break them, but not sure which one's better. @franciscoaguirre thoughts?

I think add a new is better

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime APIs are versioned so there's no problem with changing the signature.
You just need to specify the version, leave the old signature and point to the new one.
Example:

Screenshot 2025-01-17 at 10 50 36

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't change pallet_xcm::query_delivery_fees() - it provides delivery fee as X DOT

you change xcm_runtime_apis::fees::XcmPaymentApi implementation fn query_delivery_fees(dest, msg, asset_id) to convert X DOT to Y custom_asset using assets_common::PoolAdapter::::quote_price_tokens_for_exact_tokens()

assets_common causes cyclic package dependency. So directly use pallet-asset-conversion::quote_price_tokens_for_exact_tokens()?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think returning the delivery fees in the required asset (DOT, for example) is as far as this pallet-xcm helper is going to get.
This pallet doesn't assume the runtime it's running on has pallet-asset-conversion, or any pallet.
So we should call assets_common::PoolAdapter::::quote_price_tokens_for_exact_tokens() on the runtimes we want to swap, so asset-hub-westend.

The implementation in asset-hub-westend would call this pallet-xcm helper to get the fee in DOT and then call the asset conversion function to convert it into the custom asset that was passed in

// if asset.id != custom_asset {
// tracing::error!(target: "xcm::pallet_xcm::query_delivery_fees", ?asset,
// ?result_version, "Asset version mismatch"); }
// });

VersionedAssets::from(fees)
.into_version(result_version)
.map_err(|e| {
Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/xcm-runtime-apis/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ sp_api::decl_runtime_apis! {
/// size of the message.
/// * `destination`: The destination to send the message to. Different destinations may use
/// different senders that charge different fees.
fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<VersionedAssets, Error>;
fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>, asset: VersionedAssetId) -> Result<VersionedAssets, Error>;
}
}

Expand Down
8 changes: 7 additions & 1 deletion polkadot/xcm/xcm-runtime-apis/tests/fee_estimation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,15 @@ fn fee_estimation_for_teleport() {

let (destination, remote_messages) = forwarded_xcms_iter.next().unwrap();
let remote_message = &remote_messages[0];
let costum_asset = VersionedAssetId::from(AssetId(HereLocation::get()));

let delivery_fees = runtime_api
.query_delivery_fees(H256::zero(), destination.clone(), remote_message.clone())
.query_delivery_fees(
H256::zero(),
destination.clone(),
remote_message.clone(),
costum_asset,
)
.unwrap()
.unwrap();
assert_eq!(delivery_fees, VersionedAssets::from((Here, 20u128)));
Expand Down
4 changes: 2 additions & 2 deletions polkadot/xcm/xcm-runtime-apis/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ sp_api::mock_impl_runtime_apis! {
}
}

fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<VersionedAssets, XcmPaymentApiError> {
XcmPallet::query_delivery_fees(destination, message)
fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>, asset: VersionedAssetId) -> Result<VersionedAssets, XcmPaymentApiError> {
XcmPallet::query_delivery_fees(destination, message, asset)
}
}

Expand Down