Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions polkadot/xcm/xcm-runtime-apis/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ sp_api::decl_runtime_apis! {
///
/// To determine the execution weight of the calls required for
/// [`xcm::latest::Instruction::Transact`] instruction, `TransactionPaymentCallApi` can be used.
#[api_version(5)]
pub trait XcmPaymentApi {
/// Returns a list of acceptable payment assets.
///
Expand Down Expand Up @@ -65,7 +66,18 @@ 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.
#[changed_in(5)]
fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<VersionedAssets, Error>;

/// Get delivery fees for sending a specific `message` to a `destination`.
/// These always come in a specific asset, defined by the chain.
///
/// # Arguments
/// * `message`: The message that'll be sent, necessary because most delivery fees are based on the
/// 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<()>, asset_id: 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
6 changes: 4 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,10 @@ 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_id: VersionedAssetId) -> Result<VersionedAssets, XcmPaymentApiError> {
let delivery_fee_dot = XcmPallet::query_delivery_fees(destination, message)?;
quote_price_tokens_for_exact_tokens(delivery_fee_dot, asset_id)
.map_err(|_| XcmPaymentApiError::AssetNotFound)
}
}

Expand Down
Loading