#![cfg_attr(not(feature = "std"), no_std)]
use constants::{AVERAGE_ON_INITIALIZE_RATIO, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO};
use fees::SplitFeesByRatio;
pub use sp_consensus_aura::sr25519::AuthorityId;
pub use opaque::*;
pub use frame_support::weights::constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
use frame_support::{
dispatch::DispatchClass,
parameter_types,
traits::{
fungible::{Balanced, Credit},
Contains, ContainsLengthBound, Currency, Get, OnUnbalanced, SortedMembers,
},
};
use frame_system::limits;
use pallet_balances::Pallet as PalletBalance;
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
use sp_runtime::{
generic,
traits::{BlakeTwo256, Bounded, IdentifyAccount, Verify},
FixedPointNumber, MultiSignature, Perquintill, SaturatedConversion,
};
use sp_std::marker::PhantomData;
pub mod asset_switch;
pub mod assets;
pub mod authorization;
pub mod constants;
pub mod dip;
pub mod errors;
pub mod fees;
pub mod migrations;
pub mod pallet_id;
pub mod xcm_config;
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarks;
pub mod opaque {
use super::*;
use sp_runtime::{generic, traits::BlakeTwo256};
pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type BlockId = generic::BlockId<Block>;
}
pub type BlockNumber = u64;
pub(crate) type CreditOf<T> = Credit<<T as frame_system::Config>::AccountId, PalletBalance<T, ()>>;
pub type Signature = MultiSignature;
pub type AccountPublic = <Signature as Verify>::Signer;
pub type AccountId = <AccountPublic as IdentifyAccount>::AccountId;
pub type AccountIndex = u32;
pub type ChainId = u32;
pub type Balance = u128;
pub type Amount = i128;
pub type Nonce = u64;
pub type Hasher = BlakeTwo256;
pub type Hash = <BlakeTwo256 as sp_core::Hasher>::Out;
pub type DigestItem = generic::DigestItem;
pub type DidIdentifier = AccountId;
pub type NegativeImbalanceOf<T> =
<pallet_balances::Pallet<T> as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(3, 100_000);
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000u128);
pub MaximumMultiplier: Multiplier = Bounded::max_value();
pub BlockLength: limits::BlockLength =
limits::BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub BlockWeights: limits::BlockWeights = limits::BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = ExtrinsicBaseWeight::get();
})
.for_class(DispatchClass::Normal, |weights| {
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
})
.for_class(DispatchClass::Operational, |weights| {
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
weights.reserved = Some(
MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT,
);
})
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
.build_or_panic();
pub const FeeSplitRatio: (u32, u32) = (50, 50);
}
pub type FeeSplit<R, B1, B2> = SplitFeesByRatio<R, FeeSplitRatio, B1, B2>;
pub type SlowAdjustingFeeUpdate<R> =
TargetedFeeAdjustment<R, TargetBlockFullness, AdjustmentVariable, MinimumMultiplier, MaximumMultiplier>;
pub struct Tippers<R, I>(PhantomData<R>, PhantomData<I>);
impl<R, I: 'static> ContainsLengthBound for Tippers<R, I>
where
R: pallet_membership::Config<I>,
{
fn max_len() -> usize {
<R as pallet_membership::Config<I>>::MaxMembers::get().saturated_into()
}
fn min_len() -> usize {
0
}
}
impl<R, I: 'static> SortedMembers<R::AccountId> for Tippers<R, I>
where
R: pallet_membership::Config<I>,
pallet_membership::Pallet<R, I>: SortedMembers<R::AccountId> + Contains<R::AccountId>,
{
fn sorted_members() -> sp_std::vec::Vec<R::AccountId> {
pallet_membership::Pallet::<R, I>::sorted_members()
}
#[cfg(feature = "runtime-benchmarks")]
fn add(who: &R::AccountId) {
pallet_membership::Members::<R, I>::mutate(|members| match members.binary_search_by(|m| m.cmp(who)) {
Ok(_) => (),
Err(pos) => members
.try_insert(pos, who.clone())
.expect("Should not fail to add members"),
})
}
}
pub struct SendDustAndFeesToTreasury<T>(sp_std::marker::PhantomData<T>);
impl<T> OnUnbalanced<CreditOf<T>> for SendDustAndFeesToTreasury<T>
where
T: pallet_balances::Config,
T: pallet_treasury::Config,
{
fn on_nonzero_unbalanced(amount: CreditOf<T>) {
let treasury_account_id = pallet_treasury::Pallet::<T>::account_id();
let result = pallet_balances::Pallet::<T>::resolve(&treasury_account_id, amount);
debug_assert!(result.is_ok(), "The whole credit cannot be countered");
}
}