use crate::*;
use frame_support::{
traits::{ConstBool, NeverEnsureOrigin, PrivilegeCmp},
PalletId,
};
use circuit_runtime_types::{MICROUNIT, UNIT as TRN};
use frame_system::EnsureRoot;
use smallvec::smallvec;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
use sp_runtime::{impl_opaque_keys, Permill};
use sp_std::{cmp::Ordering, prelude::*};
use t3rn_primitives::monetary::EXISTENTIAL_DEPOSIT;
pub struct WeightToFee;
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
let p = MILLIUNIT / 10;
let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational(p % q, q),
coeff_integer: p / q,
}]
}
}
pub mod opaque {
use super::*;
pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
use sp_runtime::{generic, traits::BlakeTwo256};
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type BlockId = generic::BlockId<Block>;
}
impl_opaque_keys! {
pub struct SessionKeys {
pub aura: Aura,
}
}
pub const fn deposit(items: u32, bytes: u32) -> Balance {
(items as Balance) * 56 * MILLIUNIT + (bytes as Balance) * 50 * MICROUNIT
}
parameter_types! {
pub const UncleGenerations: u32 = 0;
}
impl pallet_authorship::Config for Runtime {
type EventHandler = (CollatorSelection,);
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
}
parameter_types! {
pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
}
impl cumulus_pallet_parachain_system::Config for Runtime {
type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
type DmpMessageHandler = DmpQueue;
type OnSystemEvent = ();
type OutboundXcmpMessageSource = XcmpQueue;
type ReservedDmpWeight = ReservedDmpWeight;
type ReservedXcmpWeight = ReservedXcmpWeight;
type RuntimeEvent = RuntimeEvent;
type SelfParaId = parachain_info::Pallet<Runtime>;
type XcmpMessageHandler = XcmpQueue;
}
impl parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {}
parameter_types! {
pub const Period: u32 = 6 * HOURS;
pub const Offset: u32 = 0;
pub const MaxAuthorities: u32 = 100_000;
}
impl pallet_session::Config for Runtime {
type Keys = SessionKeys;
type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
type RuntimeEvent = RuntimeEvent;
type SessionHandler = <SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
type SessionManager = CollatorSelection;
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
type ValidatorId = <Self as frame_system::Config>::AccountId;
type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
type WeightInfo = ();
}
impl pallet_aura::Config for Runtime {
type AllowMultipleBlocksPerSlot = ConstBool<false>;
type AuthorityId = AuraId;
type DisabledValidators = ();
type MaxAuthorities = MaxAuthorities;
}
parameter_types! {
pub const PotId: PalletId = PalletId(*b"PotStake");
pub const MaxCandidates: u32 = 1000;
pub const MinCandidates: u32 = 2;
pub const SessionLength: BlockNumber = 24 * HOURS;
pub const MaxInvulnerables: u32 = 100;
}
pub type CollatorSelectionUpdateOrigin = EnsureRoot<AccountId>;
impl pallet_collator_selection::Config for Runtime {
type Currency = Balances;
type KickThreshold = Period;
type MaxCandidates = MaxCandidates;
type MaxInvulnerables = MaxInvulnerables;
type MinEligibleCollators = MinCandidates;
type PotId = PotId;
type RuntimeEvent = RuntimeEvent;
type UpdateOrigin = CollatorSelectionUpdateOrigin;
type ValidatorId = <Self as frame_system::Config>::AccountId;
type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
type ValidatorRegistration = Session;
type WeightInfo = ();
}
parameter_types! {
pub const PreimageMaxSize: u32 = 4096 * 1024;
pub const PreimageBaseDeposit: Balance = deposit(2, 64);
pub const PreimageByteDeposit: Balance = deposit(0, 1); }
impl pallet_preimage::Config for Runtime {
type BaseDeposit = PreimageBaseDeposit;
type ByteDeposit = PreimageByteDeposit;
type Currency = Balances;
type ManagerOrigin = EnsureRoot<AccountId>;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_preimage::weights::SubstrateWeight<Runtime>;
}
parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) *
circuit_runtime_types::RuntimeBlockWeights::get().max_block;
pub const MaxScheduledPerBlock: u32 = 50;
}
impl pallet_scheduler::Config for Runtime {
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type MaximumWeight = MaximumSchedulerWeight;
type OriginPrivilegeCmp = OriginPrivilegeCmp;
type PalletsOrigin = OriginCaller;
type Preimages = Preimage;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type ScheduleOrigin = EnsureRoot<AccountId>;
type WeightInfo = pallet_scheduler::weights::SubstrateWeight<Runtime>;
}
pub struct OriginPrivilegeCmp;
impl PrivilegeCmp<OriginCaller> for OriginPrivilegeCmp {
fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option<Ordering> {
if left == right {
return Some(Ordering::Equal)
}
match (left, right) {
(OriginCaller::system(frame_system::RawOrigin::Root), _) => Some(Ordering::Greater),
_ => None,
}
}
}
parameter_types! {
pub const TreasuryId: PalletId = PalletId(*b"pottrsry");
pub const MaxApprovals: u32 = 100;
pub const ProposalBond: Permill = Permill::from_percent(3);
pub const SpendPeriod: u32 = (60 * 60 * 24) / 12;
pub const ProposalBondMinimum: u128 = 10_u128 * (TRN as u128);
}
impl pallet_treasury::Config for Runtime {
type ApproveOrigin = EnsureRoot<AccountId>;
type Burn = ();
type BurnDestination = ();
type Currency = Balances;
type MaxApprovals = MaxApprovals;
type OnSlash = Treasury;
type PalletId = TreasuryId;
type ProposalBond = ProposalBond;
type ProposalBondMaximum = ();
type ProposalBondMinimum = ProposalBondMinimum;
type RejectOrigin = EnsureRoot<AccountId>;
type RuntimeEvent = RuntimeEvent;
type SpendFunds = ();
type SpendOrigin = NeverEnsureOrigin<Balance>;
type SpendPeriod = SpendPeriod;
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
}
struct CheckInherents;
impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {
fn check_inherents(
block: &Block,
relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,
) -> sp_inherents::CheckInherentsResult {
let relay_chain_slot = relay_state_proof
.read_slot()
.expect("Could not read the relay chain slot from the proof");
let inherent_data =
cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(
relay_chain_slot,
sp_std::time::Duration::from_secs(6),
)
.create_inherent_data()
.expect("Could not create the timestamp inherent data");
inherent_data.check_extrinsics(block)
}
}
cumulus_pallet_parachain_system::register_validate_block! {
Runtime = Runtime,
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
CheckInherents = CheckInherents,
}