xcm_primitives/fee_trader.rs
1// Copyright 2025 Moonbeam foundation
2// This file is part of Moonbeam.
3
4// Moonbeam is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Moonbeam is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.
16
17//! Trait for computing XCM fees and managing asset pricing.
18
19use frame_support::weights::Weight;
20use sp_runtime::DispatchError;
21use xcm::latest::Location;
22
23/// Trait for computing XCM fees and managing asset pricing.
24/// This allows pallets to delegate fee calculation to an external system
25/// (e.g., pallet-xcm-weight-trader) instead of maintaining their own storage.
26pub trait XcmFeeTrader {
27 /// Compute the fee amount for a given weight and asset location.
28 ///
29 /// The fee should be calculated based on the weight and asset pricing configured
30 /// for the given asset location.
31 fn compute_fee(weight: Weight, asset_location: &Location) -> Result<u128, DispatchError>;
32
33 /// Get the current price/fee-per-second for an asset, if configured.
34 /// Returns None if the asset is not configured.
35 fn get_asset_price(asset_location: &Location) -> Option<u128>;
36
37 /// Set the price/configuration for an asset.
38
39 fn set_asset_price(_asset_location: Location, _value: u128) -> Result<(), DispatchError>;
40
41 /// Remove the price/configuration for an asset.
42 fn remove_asset(_asset_location: Location) -> Result<(), DispatchError>;
43}