Skip to content

Commit

Permalink
fee information in types
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Nov 24, 2023
1 parent 0b104c0 commit eedc80b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
7 changes: 7 additions & 0 deletions libs/traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,13 @@ pub mod fees {
fee: Fee<Self::Balance, Self::FeeKey>,
) -> 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<AccountId> {
fn pay_for(who: &AccountId) -> DispatchResult;
}
}

/// Trait to determine whether a sending account and currency have a
Expand Down
2 changes: 2 additions & 0 deletions libs/types/src/fee_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ impl Default for FeeKey {
FeeKey::AnchorsCommit
}
}

pub type Fee = cfg_traits::fees::Fee<cfg_primitives::Balance, FeeKey>;
39 changes: 38 additions & 1 deletion runtime/common/src/fees.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -82,6 +86,39 @@ impl WeightToFeePolynomial for WeightToFee {
}
}

pub struct FeeToTreasury<F, V>(sp_std::marker::PhantomData<(F, V)>);
impl<
F: Fees<AccountId = AccountId, Balance = Balance, FeeKey = FeeKey>,
V: Get<Fee<Balance, FeeKey>>,
> PayFee<AccountId> for FeeToTreasury<F, V>
{
fn pay_for(who: &AccountId) -> DispatchResult {
F::fee_to_treasury(who, V::get())
}
}

pub struct FeeToAuthor<F, V>(sp_std::marker::PhantomData<(F, V)>);
impl<
F: Fees<AccountId = AccountId, Balance = Balance, FeeKey = FeeKey>,
V: Get<Fee<Balance, FeeKey>>,
> PayFee<AccountId> for FeeToAuthor<F, V>
{
fn pay_for(who: &AccountId) -> DispatchResult {
F::fee_to_author(who, V::get())
}
}

pub struct FeeToBurn<F, V>(sp_std::marker::PhantomData<(F, V)>);
impl<
F: Fees<AccountId = AccountId, Balance = Balance, FeeKey = FeeKey>,
V: Get<Fee<Balance, FeeKey>>,
> PayFee<AccountId> for FeeToBurn<F, V>
{
fn pay_for(who: &AccountId) -> DispatchResult {
F::fee_to_burn(who, V::get())
}
}

#[cfg(test)]
mod test {
use cfg_primitives::{AccountId, TREASURY_FEE_RATIO};
Expand Down

0 comments on commit eedc80b

Please sign in to comment.