staging_xcm_executor/traits/fee_manager.rs
1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot 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// Polkadot 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 Polkadot. If not, see <http://www.gnu.org/licenses/>.
16
17use crate::AssetsInHolding;
18use xcm::prelude::*;
19
20/// Handle stuff to do with taking fees in certain XCM instructions.
21pub trait FeeManager {
22 /// Determine if a fee should be waived.
23 fn is_waived(origin: Option<&Location>, r: FeeReason) -> bool;
24
25 /// Do something with the fee which has been paid. Doing nothing here silently burns the
26 /// fees.
27 fn handle_fee(paid_fee: AssetsInHolding, context: Option<&XcmContext>, r: FeeReason);
28}
29
30/// Context under which a fee is paid.
31#[derive(Clone, Debug, Eq, PartialEq)]
32pub enum FeeReason {
33 /// When a reporting instruction is called.
34 Report,
35 /// When the `TransferReserveAsset` instruction is called.
36 TransferReserveAsset,
37 /// When the `DepositReserveAsset` instruction is called.
38 DepositReserveAsset,
39 /// When the `InitiateReserveWithdraw` instruction is called.
40 InitiateReserveWithdraw,
41 /// When the `InitiateTeleport` instruction is called.
42 InitiateTeleport,
43 /// When the `InitiateTransfer` instruction is called.
44 InitiateTransfer,
45 /// When the `QueryPallet` instruction is called.
46 QueryPallet,
47 /// When the `ExportMessage` instruction is called (and includes the network ID).
48 Export { network: NetworkId, destination: InteriorLocation },
49 /// The `charge_fees` API.
50 ChargeFees,
51 /// When the `LockAsset` instruction is called.
52 LockAsset,
53 /// When the `RequestUnlock` instruction is called.
54 RequestUnlock,
55}
56
57impl FeeManager for () {
58 fn is_waived(_: Option<&Location>, _: FeeReason) -> bool {
59 false
60 }
61
62 fn handle_fee(_: AssetsInHolding, _: Option<&XcmContext>, _: FeeReason) {}
63}
64
65pub struct WaiveDeliveryFees;
66
67impl FeeManager for WaiveDeliveryFees {
68 fn is_waived(_: Option<&Location>, _: FeeReason) -> bool {
69 true
70 }
71
72 fn handle_fee(_: AssetsInHolding, _: Option<&XcmContext>, _: FeeReason) {}
73}