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	#[api_version(2)]
38	pub trait XcmPaymentApi {
39		/// Returns a list of acceptable payment assets.
40		///
41		/// # Arguments
42		///
43		/// * `xcm_version`: Version.
44		fn query_acceptable_payment_assets(xcm_version: Version) -> Result<Vec<VersionedAssetId>, Error>;
45
46		/// Returns a weight needed to execute a XCM.
47		///
48		/// # Arguments
49		///
50		/// * `message`: `VersionedXcm`.
51		fn query_xcm_weight(message: VersionedXcm<()>) -> Result<Weight, Error>;
52
53		/// Converts a weight into a fee for the specified `AssetId`.
54		///
55		/// # Arguments
56		///
57		/// * `weight`: convertible `Weight`.
58		/// * `asset`: `VersionedAssetId`.
59		fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, Error>;
60
61		/// Query delivery fees V1.
62		///
63		/// Get delivery fees for sending a specific `message` to a `destination`.
64		/// These always come in a specific asset, defined by the chain.
65		///
66		/// # Arguments
67		/// * `message`: The message that'll be sent, necessary because most delivery fees are based on the
68		///   size of the message.
69		/// * `destination`: The destination to send the message to. Different destinations may use
70		///   different senders that charge different fees.
71		#[changed_in(2)]
72		fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<VersionedAssets, Error>;
73
74		/// Query delivery fees V2.
75		///
76		/// Get delivery fees for sending a specific `message` to a `destination`.
77		/// These always come in a specific asset, defined by the chain.
78		///
79		/// # Arguments
80		/// * `message`: The message that'll be sent, necessary because most delivery fees are based on the
81		///   size of the message.
82		/// * `destination`: The destination to send the message to. Different destinations may use
83		///   different senders that charge different fees.
84		fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>, asset_id: VersionedAssetId) -> Result<VersionedAssets, Error>;
85	}
86}
87
88#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)]
89pub enum Error {
90	/// An API part is unsupported.
91	#[codec(index = 0)]
92	Unimplemented,
93
94	/// Converting a versioned data structure from one version to another failed.
95	#[codec(index = 1)]
96	VersionedConversionFailed,
97
98	/// XCM message weight calculation failed.
99	#[codec(index = 2)]
100	WeightNotComputable,
101
102	/// XCM version not able to be handled.
103	#[codec(index = 3)]
104	UnhandledXcmVersion,
105
106	/// The given asset is not handled as a fee asset.
107	#[codec(index = 4)]
108	AssetNotFound,
109
110	/// Destination is known to be unroutable.
111	#[codec(index = 5)]
112	Unroutable,
113}