-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaning: Repo organization before Polkadot 1.1.0 (#1737)
* remove unused deps * evm file to runtime file * liquidity pool mod to lib mod * reorganize fees traits * remove parachain info from pool mocks * reorganize and clean runtime imports * fix fmt * fix staking compilation benchmark issue * moving common xcm parts to runtime-common * clean last refactor * swaps related traits to swaps.rs module * import individually some types * fix migration
- Loading branch information
Showing
41 changed files
with
1,289 additions
and
1,398 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
use frame_support::{dispatch::DispatchResult, traits::tokens::Balance}; | ||
use parity_scale_codec::FullCodec; | ||
use scale_info::TypeInfo; | ||
use sp_runtime::traits::MaybeSerializeDeserialize; | ||
|
||
/// Type used for identity the key used to retrieve the fees. | ||
pub trait FeeKey: | ||
FullCodec + TypeInfo + MaybeSerializeDeserialize + sp_std::fmt::Debug + Clone + PartialEq | ||
{ | ||
} | ||
|
||
impl< | ||
T: FullCodec + TypeInfo + MaybeSerializeDeserialize + sp_std::fmt::Debug + Clone + PartialEq, | ||
> FeeKey for T | ||
{ | ||
} | ||
|
||
/// A way to identify a fee value. | ||
pub enum Fee<Balance, FeeKey> { | ||
/// The fee value itself. | ||
Balance(Balance), | ||
|
||
/// The fee value is already stored and identified by a key. | ||
Key(FeeKey), | ||
} | ||
|
||
impl<Balance: Copy, FeeKey: Clone> Fee<Balance, FeeKey> { | ||
pub fn value<F: Fees<Balance = Balance, FeeKey = FeeKey>>(&self) -> Balance { | ||
match self { | ||
Fee::Balance(value) => *value, | ||
Fee::Key(key) => F::fee_value(key.clone()), | ||
} | ||
} | ||
} | ||
|
||
/// A trait that used to deal with fees | ||
pub trait Fees { | ||
type AccountId; | ||
type Balance: Balance; | ||
type FeeKey: FeeKey; | ||
|
||
/// Get the fee balance for a fee key | ||
fn fee_value(key: Self::FeeKey) -> Self::Balance; | ||
|
||
/// Pay an amount of fee to the block author | ||
/// If the `from` account has not enough balance or the author is | ||
/// invalid the fees are not paid. | ||
fn fee_to_author( | ||
from: &Self::AccountId, | ||
fee: Fee<Self::Balance, Self::FeeKey>, | ||
) -> DispatchResult; | ||
|
||
/// Burn an amount of fee | ||
/// If the `from` account has not enough balance the fees are not paid. | ||
fn fee_to_burn(from: &Self::AccountId, fee: Fee<Self::Balance, Self::FeeKey>) | ||
-> DispatchResult; | ||
|
||
/// Send an amount of fee to the treasury | ||
/// If the `from` account has not enough balance the fees are not paid. | ||
fn fee_to_treasury( | ||
from: &Self::AccountId, | ||
fee: Fee<Self::Balance, Self::FeeKey>, | ||
) -> DispatchResult; | ||
|
||
/// Allows to initialize an initial state required for a pallet that | ||
/// calls pay a fee | ||
#[cfg(feature = "runtime-benchmarks")] | ||
fn add_fee_requirements(_from: &Self::AccountId, _fee: Fee<Self::Balance, Self::FeeKey>) {} | ||
} | ||
|
||
/// Trait to pay fees | ||
/// This trait can be used by a pallet to just pay fees without worring | ||
/// about the value or where the fee goes. | ||
pub trait PayFee<AccountId> { | ||
/// Pay the fee using a payer | ||
fn pay(payer: &AccountId) -> DispatchResult; | ||
|
||
/// Allows to initialize an initial state required for a pallet that | ||
/// calls `pay()`. | ||
#[cfg(feature = "runtime-benchmarks")] | ||
fn add_pay_requirements(_payer: &AccountId) {} | ||
} | ||
|
||
/// Type to avoid paying fees | ||
pub struct NoPayFee; | ||
impl<AccountId> PayFee<AccountId> for NoPayFee { | ||
fn pay(_: &AccountId) -> DispatchResult { | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.