Skip to content

update XcmPaymentApi query_delivery_fees to return the fee based on V…#8297

Closed
jpserrat wants to merge 2 commits intoparitytech:masterfrom
jpserrat:jpserrat/query-delivery-fees-v2
Closed

update XcmPaymentApi query_delivery_fees to return the fee based on V…#8297
jpserrat wants to merge 2 commits intoparitytech:masterfrom
jpserrat:jpserrat/query-delivery-fees-v2

Conversation

@jpserrat
Copy link
Contributor

Closes #7061

@acatangiu Two questions.

  1. where is the best place to write the tests for the AssetHubWestend impl?
  2. For the other places that are implementing the XcmPaymentApi I've just added the VersionedAssetId without any use. Should I implement this for all of them?

@jpserrat jpserrat requested a review from a team as a code owner April 22, 2025 11:58
@franciscoaguirre franciscoaguirre added the T6-XCM This PR/Issue is related to XCM. label Apr 23, 2025
fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<VersionedAssets, XcmPaymentApiError> {
PolkadotXcm::query_delivery_fees(destination, message)
fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>, asset: VersionedAssetId) -> Result<VersionedAssets, XcmPaymentApiError> {
let fee_in_native = PolkadotXcm::query_delivery_fees(destination, message)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather modify the helper query_delivery_fees in pallet-xcm so that other runtimes integrating this can just use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this, I would need to add a new dependency, right? I added it into the implementation of XcmPaymentApi due to this comment.
It would have been much simpler to add it in pallet-xcm, but from what I understand, we’re going to let the runtime decide how to implement this.

For the query_weight_to_asset_fee, we also do the conversion in the runtime. This way, we can keep things more consistent by leaving all the conversions to be implemented by the runtime (I’m assuming that’s the case—I don’t know all the implementations 🤣).

Anyway, I’m going to leave this decision to you. Also, let me know if I got all wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

The runtime decides how to implement this, but we've seen in #8281 an example of using an existing configuration item to move more things into the helper function and make these APIs simpler to implement for teams

}

fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<VersionedAssets, XcmPaymentApiError> {
fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>, _: VersionedAssetId) -> Result<VersionedAssets, XcmPaymentApiError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Even though bridge hub doesn't support multiple assets for fee payment, I would still throw an error if the asset is not the expected one ({ parents: 1, interior: Here })

/// These always come in a specific asset, defined by the parameter `asset`.
///
/// # Arguments
/// * `asset`: The asset to charge fees in.
Copy link
Contributor

Choose a reason for hiding this comment

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

Move to end of argument list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The function signature currently is (destination: VersionedLocation, message: VersionedXcm<()>, asset: VersionedAssetId). And in the argument list it looks like the order is starting from the last.

  • asset
  • message
  • destination

This is why I left this as the first argument in the list instead of put it in at the end. What do you think?

@franciscoaguirre
Copy link
Contributor

Thank you for contributing! 😁 Left some comments

@jpserrat
Copy link
Contributor Author

Thank you for all the comments Francisco!

let fee_in_native = PolkadotXcm::query_delivery_fees(destination, message)?;
let asset_id: Result<AssetId, ()> = asset.clone().try_into();
let native_asset = xcm_config::WestendLocation::get();
match asset_id {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for adding this new functionality. I've noticed that the tests currently cover only the native asset branch. Would you mind adding tests for the remaining branches to ensure comprehensive coverage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! I didn't add test, because I'm waiting for @franciscoaguirre response about where the conversion should be implement. If you have any directions on this would be great, should I keep it where it is or should I move it to pallet-xcm

Runtime::query_delivery_fees(
destination_to_query.clone(),
remote_message.clone(),
VersionedAssetId::from(AssetId(Location::parent()))
Copy link
Contributor

Choose a reason for hiding this comment

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

You may want to use macro overloading to parametrise this macro too, e.g. #8392

@franciscoaguirre franciscoaguirre mentioned this pull request Oct 7, 2025
3 tasks
@franciscoaguirre
Copy link
Contributor

I'm closing this in favor of #9963

@jpserrat
Copy link
Contributor Author

I've just noticed that you responded Francisco. Thank you for the continuation, I'll take a look at what you did to learn a little bit more! Sorry for not finishing this.

github-merge-queue bot pushed a commit that referenced this pull request Nov 10, 2025
Adds an `asset_id` parameter to `XcmPaymentApi.query_delivery_fees` so
fees can be estimated in assets other than the native one.

Fixes #7061

Continuation of #8297

## TODO
- [x] Add parameter to runtime API
- [x] Add parameter to pallet-xcm helper
- [x] Test querying delivery fee in an asset other than native

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Branislav Kontur <bkontur@gmail.com>
Co-authored-by: Adrian Catangiu <adrian@parity.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T6-XCM This PR/Issue is related to XCM.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XcmPaymentApi::query_delivery_fees() should allow querying fee using custom asset

4 participants