xcm_runtime_apis/fees.rs
1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3// SPDX-License-Identifier: Apache-2.0
4
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17//! Runtime API definition for getting XCM fees.
18
19use alloc::vec::Vec;
20use codec::{Decode, Encode};
21use frame_support::pallet_prelude::TypeInfo;
22use sp_weights::Weight;
23use xcm::{Version, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm};
24
25sp_api::decl_runtime_apis! {
26 /// A trait of XCM payment API.
27 ///
28 /// API provides functionality for obtaining:
29 ///
30 /// * the weight required to execute an XCM message,
31 /// * a list of acceptable `AssetId`s for message execution payment,
32 /// * the cost of the weight in the specified acceptable `AssetId`.
33 /// * the fees for an XCM message delivery.
34 ///
35 /// To determine the execution weight of the calls required for
36 /// [`xcm::latest::Instruction::Transact`] instruction, `TransactionPaymentCallApi` can be used.
37 pub trait XcmPaymentApi {
38 /// Returns a list of acceptable payment assets.
39 ///
40 /// # Arguments
41 ///
42 /// * `xcm_version`: Version.
43 fn query_acceptable_payment_assets(xcm_version: Version) -> Result<Vec<VersionedAssetId>, Error>;
44
45 /// Returns a weight needed to execute a XCM.
46 ///
47 /// # Arguments
48 ///
49 /// * `message`: `VersionedXcm`.
50 fn query_xcm_weight(message: VersionedXcm<()>) -> Result<Weight, Error>;
51
52 /// Converts a weight into a fee for the specified `AssetId`.
53 ///
54 /// # Arguments
55 ///
56 /// * `weight`: convertible `Weight`.
57 /// * `asset`: `VersionedAssetId`.
58 fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, Error>;
59
60 /// Get delivery fees for sending a specific `message` to a `destination`.
61 /// These always come in a specific asset, defined by the chain.
62 ///
63 /// # Arguments
64 /// * `message`: The message that'll be sent, necessary because most delivery fees are based on the
65 /// size of the message.
66 /// * `destination`: The destination to send the message to. Different destinations may use
67 /// different senders that charge different fees.
68 fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<VersionedAssets, Error>;
69 }
70}
71
72#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)]
73pub enum Error {
74 /// An API part is unsupported.
75 #[codec(index = 0)]
76 Unimplemented,
77
78 /// Converting a versioned data structure from one version to another failed.
79 #[codec(index = 1)]
80 VersionedConversionFailed,
81
82 /// XCM message weight calculation failed.
83 #[codec(index = 2)]
84 WeightNotComputable,
85
86 /// XCM version not able to be handled.
87 #[codec(index = 3)]
88 UnhandledXcmVersion,
89
90 /// The given asset is not handled as a fee asset.
91 #[codec(index = 4)]
92 AssetNotFound,
93
94 /// Destination is known to be unroutable.
95 #[codec(index = 5)]
96 Unroutable,
97}