diff --git a/libs/traits/src/lib.rs b/libs/traits/src/lib.rs index 173687fd53..3f5a8c2ace 100644 --- a/libs/traits/src/lib.rs +++ b/libs/traits/src/lib.rs @@ -435,6 +435,13 @@ pub mod fees { fee: Fee, ) -> DispatchResult; } + + /// Trait to pay fees + /// This trait can be used by pallet to just pay fees without worring about + /// the value or where the fee goes. + pub trait PayFee { + fn pay_for(who: &AccountId) -> DispatchResult; + } } /// Trait to determine whether a sending account and currency have a diff --git a/libs/types/src/fee_keys.rs b/libs/types/src/fee_keys.rs index 38baa75e4f..fea226c4c2 100644 --- a/libs/types/src/fee_keys.rs +++ b/libs/types/src/fee_keys.rs @@ -54,3 +54,5 @@ impl Default for FeeKey { FeeKey::AnchorsCommit } } + +pub type Fee = cfg_traits::fees::Fee; diff --git a/runtime/common/src/fees.rs b/runtime/common/src/fees.rs index ff25996ca9..856d0fb286 100644 --- a/runtime/common/src/fees.rs +++ b/runtime/common/src/fees.rs @@ -1,9 +1,13 @@ use cfg_primitives::{ constants::{CENTI_CFG, TREASURY_FEE_RATIO}, types::Balance, + AccountId, }; +use cfg_traits::fees::{Fee, Fees, PayFee}; +use cfg_types::fee_keys::FeeKey; use frame_support::{ - traits::{Currency, Imbalance, OnUnbalanced}, + dispatch::DispatchResult, + traits::{Currency, Get, Imbalance, OnUnbalanced}, weights::{ constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, @@ -82,6 +86,39 @@ impl WeightToFeePolynomial for WeightToFee { } } +pub struct FeeToTreasury(sp_std::marker::PhantomData<(F, V)>); +impl< + F: Fees, + V: Get>, + > PayFee for FeeToTreasury +{ + fn pay_for(who: &AccountId) -> DispatchResult { + F::fee_to_treasury(who, V::get()) + } +} + +pub struct FeeToAuthor(sp_std::marker::PhantomData<(F, V)>); +impl< + F: Fees, + V: Get>, + > PayFee for FeeToAuthor +{ + fn pay_for(who: &AccountId) -> DispatchResult { + F::fee_to_author(who, V::get()) + } +} + +pub struct FeeToBurn(sp_std::marker::PhantomData<(F, V)>); +impl< + F: Fees, + V: Get>, + > PayFee for FeeToBurn +{ + fn pay_for(who: &AccountId) -> DispatchResult { + F::fee_to_burn(who, V::get()) + } +} + #[cfg(test)] mod test { use cfg_primitives::{AccountId, TREASURY_FEE_RATIO};