Skip to content

Commit

Permalink
Cleaning: Repo organization before Polkadot 1.1.0 (#1737)
Browse files Browse the repository at this point in the history
* 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
lemunozm authored Feb 21, 2024
1 parent 19e2b6d commit 8067daf
Show file tree
Hide file tree
Showing 41 changed files with 1,289 additions and 1,398 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,7 @@ pallet-recovery = { git = "https://github.com/paritytech//substrate", branch = "
pallet-scheduler = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-session = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-session-benchmarking = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-society = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-staking = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-staking-reward-curve = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-staking-reward-fn = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-sudo = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-timestamp = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-tips = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
Expand Down Expand Up @@ -567,10 +564,7 @@ pallet-recovery = { git = "https://github.com/paritytech//substrate", branch = "
pallet-scheduler = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-session = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-session-benchmarking = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-society = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-staking = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-staking-reward-curve = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-staking-reward-fn = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-sudo = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-timestamp = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
pallet-tips = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.43" }
Expand Down
2 changes: 1 addition & 1 deletion libs/mocks/src/token_swaps.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[frame_support::pallet]
pub mod pallet {
use cfg_traits::{OrderInfo, OrderRatio, TokenSwaps};
use cfg_traits::swaps::{OrderInfo, OrderRatio, TokenSwaps};
use frame_support::pallet_prelude::*;
use mock_builder::{execute_call, register_call};

Expand Down
5 changes: 1 addition & 4 deletions libs/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ pub mod types {
/// it equivalent to the public key of our transaction signing scheme.
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;

/// The type for looking up accounts. We don't expect more than 4 billion of
/// them, but you never know...
pub type AccountIndex = u32;

/// The address format for describing accounts.
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;

Expand All @@ -102,6 +98,7 @@ pub mod types {
/// A generic block for the node to use, as we can not commit to
/// a specific Extrinsic format at this point. Runtimes will ensure
/// Extrinsic are correctly decoded.
/// Used by the node.
pub type Block = sp_runtime::generic::Block<Header, OpaqueExtrinsic>;

/// Block header type as expected by this runtime.
Expand Down
90 changes: 90 additions & 0 deletions libs/traits/src/fees.rs
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(())
}
}
Loading

0 comments on commit 8067daf

Please sign in to comment.