12345678910111213141516171819#![cfg_attr(not(feature = "std"), no_std)]2021#![recursion_limit = "1024"]22#![allow(clippy::from_over_into, clippy::identity_op)]23#![allow(clippy::fn_to_numeric_cast_with_truncation)]2425#[cfg(feature = "std")]26include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));2728use sp_api::impl_runtime_apis;29use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160};30use sp_runtime::DispatchError;31323334use sp_runtime::{35 Permill, Perbill, Percent, create_runtime_str, generic, impl_opaque_keys,36 traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion, Zero},37 transaction_validity::{TransactionSource, TransactionValidity},38 ApplyExtrinsicResult, RuntimeAppPublic,39};4041use sp_std::prelude::*;4243#[cfg(feature = "std")]44use sp_version::NativeVersion;45use sp_version::RuntimeVersion;46pub use pallet_transaction_payment::{47 Multiplier, TargetedFeeAdjustment, FeeDetails, RuntimeDispatchInfo,48};4950pub use pallet_balances::Call as BalancesCall;51pub use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping, Runner};52pub use frame_support::{53 construct_runtime, match_type,54 dispatch::DispatchResult,55 PalletId, parameter_types, StorageValue, ConsensusEngineId,56 traits::{57 tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Everything,58 Currency, ExistenceRequirement, Get, IsInVec, KeyOwnerProofSystem, LockIdentifier,59 OnUnbalanced, Randomness, FindAuthor,60 },61 weights::{62 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},63 DispatchClass, DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,64 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients,65 },66};67use up_data_structs::*;686970use frame_system::{71 self as frame_system, EnsureRoot, EnsureSigned,72 limits::{BlockWeights, BlockLength},73};74use sp_arithmetic::{75 traits::{BaseArithmetic, Unsigned},76};77use smallvec::smallvec;78use codec::{Encode, Decode};79use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping, OnMethodCall};80use fp_rpc::TransactionStatus;81use sp_runtime::{82 traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating},83 transaction_validity::TransactionValidityError,84 SaturatedConversion,85};868788pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;899091use pallet_xcm::XcmPassthrough;92use polkadot_parachain::primitives::Sibling;93use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*};94use xcm_builder::{95 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,96 EnsureXcmOrigin, FixedWeightBounds, LocationInverter, NativeAsset, ParentAsSuperuser,97 RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,98 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,99 ParentIsPreset,100};101use xcm_executor::{Config, XcmExecutor, Assets};102use sp_std::{marker::PhantomData};103104use xcm::latest::{105 106 AssetId::{Concrete},107 Fungibility::Fungible as XcmFungible,108 MultiAsset,109 Error as XcmError,110};111use xcm_executor::traits::{MatchesFungible, WeightTrader};112113use sp_runtime::traits::CheckedConversion;114115use unique_runtime_common::{impl_common_runtime_apis, types::*, constants::*};116117pub const RUNTIME_NAME: &str = "Quartz";118119type CrossAccountId = pallet_common::account::BasicCrossAccountId<Runtime>;120121impl RuntimeInstance for Runtime {122 type CrossAccountId = self::CrossAccountId;123124 type TransactionConverter = self::TransactionConverter;125126 fn get_transaction_converter() -> TransactionConverter {127 TransactionConverter128 }129}130131132133134135pub mod opaque {136 use sp_std::prelude::*;137 use sp_runtime::impl_opaque_keys;138 use super::Aura;139140 pub use unique_runtime_common::types::*;141142 impl_opaque_keys! {143 pub struct SessionKeys {144 pub aura: Aura,145 }146 }147}148149150pub const VERSION: RuntimeVersion = RuntimeVersion {151 spec_name: create_runtime_str!(RUNTIME_NAME),152 impl_name: create_runtime_str!(RUNTIME_NAME),153 authoring_version: 1,154 spec_version: 917004,155 impl_version: 0,156 apis: RUNTIME_API_VERSIONS,157 transaction_version: 1,158 state_version: 0,159};160161#[derive(codec::Encode, codec::Decode)]162pub enum XCMPMessage<XAccountId, XBalance> {163 164 TransferToken(XAccountId, XBalance),165}166167168#[cfg(feature = "std")]169pub fn native_version() -> NativeVersion {170 NativeVersion {171 runtime_version: VERSION,172 can_author_with: Default::default(),173 }174}175176type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;177178pub struct DealWithFees;179impl OnUnbalanced<NegativeImbalance> for DealWithFees {180 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {181 if let Some(fees) = fees_then_tips.next() {182 183 let mut split = fees.ration(100, 0);184 if let Some(tips) = fees_then_tips.next() {185 186 tips.ration_merge_into(100, 0, &mut split);187 }188 Treasury::on_unbalanced(split.0);189 190 }191 }192}193194parameter_types! {195 pub const BlockHashCount: BlockNumber = 2400;196 pub RuntimeBlockLength: BlockLength =197 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);198 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);199 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;200 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()201 .base_block(BlockExecutionWeight::get())202 .for_class(DispatchClass::all(), |weights| {203 weights.base_extrinsic = ExtrinsicBaseWeight::get();204 })205 .for_class(DispatchClass::Normal, |weights| {206 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);207 })208 .for_class(DispatchClass::Operational, |weights| {209 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);210 211 212 weights.reserved = Some(213 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT214 );215 })216 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)217 .build_or_panic();218 pub const Version: RuntimeVersion = VERSION;219 pub const SS58Prefix: u8 = 255;220}221222parameter_types! {223 pub const ChainId: u64 = 8881;224}225226pub struct FixedFee;227impl FeeCalculator for FixedFee {228 fn min_gas_price() -> U256 {229 MIN_GAS_PRICE.into()230 }231}232233234235236parameter_types! {237 pub const WritesPerSecond: u64 = WEIGHT_PER_SECOND / <Runtime as frame_system::Config>::DbWeight::get().write;238 pub const GasPerSecond: u64 = WritesPerSecond::get() * 20000;239 pub const WeightPerGas: u64 = WEIGHT_PER_SECOND / GasPerSecond::get();240}241242243244245const EVM_DISPATCH_RATIO: Perbill = Perbill::from_percent(50);246parameter_types! {247 pub BlockGasLimit: U256 = U256::from(NORMAL_DISPATCH_RATIO * EVM_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT / WeightPerGas::get());248}249250pub enum FixedGasWeightMapping {}251impl GasWeightMapping for FixedGasWeightMapping {252 fn gas_to_weight(gas: u64) -> Weight {253 gas.saturating_mul(WeightPerGas::get())254 }255 fn weight_to_gas(weight: Weight) -> u64 {256 weight / WeightPerGas::get()257 }258}259260impl pallet_evm::Config for Runtime {261 type BlockGasLimit = BlockGasLimit;262 type FeeCalculator = FixedFee;263 type GasWeightMapping = FixedGasWeightMapping;264 type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;265 type CallOrigin = EnsureAddressTruncated;266 type WithdrawOrigin = EnsureAddressTruncated;267 type AddressMapping = HashedAddressMapping<Self::Hashing>;268 type PrecompilesType = ();269 type PrecompilesValue = ();270 type Currency = Balances;271 type Event = Event;272 type OnMethodCall = (273 pallet_evm_migration::OnMethodCall<Self>,274 pallet_unique::UniqueErcSupport<Self>,275 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,276 );277 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;278 type ChainId = ChainId;279 type Runner = pallet_evm::runner::stack::Runner<Self>;280 type OnChargeTransaction = pallet_evm_transaction_payment::OnChargeTransaction<Self>;281 type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;282 type FindAuthor = EthereumFindAuthor<Aura>;283}284285impl pallet_evm_migration::Config for Runtime {286 type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;287}288289pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);290impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {291 fn find_author<'a, I>(digests: I) -> Option<H160>292 where293 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,294 {295 if let Some(author_index) = F::find_author(digests) {296 let authority_id = Aura::authorities()[author_index as usize].clone();297 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));298 }299 None300 }301}302303impl pallet_ethereum::Config for Runtime {304 type Event = Event;305 type StateRoot = pallet_ethereum::IntermediateStateRoot;306}307308impl pallet_randomness_collective_flip::Config for Runtime {}309310impl frame_system::Config for Runtime {311 312 type AccountData = pallet_balances::AccountData<Balance>;313 314 type AccountId = AccountId;315 316 type BaseCallFilter = Everything;317 318 type BlockHashCount = BlockHashCount;319 320 type BlockLength = RuntimeBlockLength;321 322 type BlockNumber = BlockNumber;323 324 type BlockWeights = RuntimeBlockWeights;325 326 type Call = Call;327 328 type DbWeight = RocksDbWeight;329 330 type Event = Event;331 332 type Hash = Hash;333 334 type Hashing = BlakeTwo256;335 336 type Header = generic::Header<BlockNumber, BlakeTwo256>;337 338 type Index = Index;339 340 type Lookup = AccountIdLookup<AccountId, ()>;341 342 type OnKilledAccount = ();343 344 type OnNewAccount = ();345 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;346 347 type Origin = Origin;348 349 type PalletInfo = PalletInfo;350 351 type SS58Prefix = SS58Prefix;352 353 type SystemWeightInfo = frame_system::weights::SubstrateWeight<Self>;354 355 type Version = Version;356 type MaxConsumers = ConstU32<16>;357}358359parameter_types! {360 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;361}362363impl pallet_timestamp::Config for Runtime {364 365 type Moment = u64;366 type OnTimestampSet = ();367 type MinimumPeriod = MinimumPeriod;368 type WeightInfo = ();369}370371parameter_types! {372 373 pub const ExistentialDeposit: u128 = 0;374 pub const MaxLocks: u32 = 50;375}376377impl pallet_balances::Config for Runtime {378 type MaxLocks = MaxLocks;379 type MaxReserves = ();380 type ReserveIdentifier = [u8; 8];381 382 type Balance = Balance;383 384 type Event = Event;385 type DustRemoval = Treasury;386 type ExistentialDeposit = ExistentialDeposit;387 type AccountStore = System;388 type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;389}390391pub const fn deposit(items: u32, bytes: u32) -> Balance {392 items as Balance * 15 * CENTIUNIQUE + (bytes as Balance) * 6 * CENTIUNIQUE393}394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445parameter_types! {446 447 448 pub const OperationalFeeMultiplier: u8 = 5;449}450451452pub struct LinearFee<T>(sp_std::marker::PhantomData<T>);453454impl<T> WeightToFeePolynomial for LinearFee<T>455where456 T: BaseArithmetic + From<u32> + Copy + Unsigned,457{458 type Balance = T;459460 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {461 smallvec!(WeightToFeeCoefficient {462 463 coeff_integer: WEIGHT_TO_FEE_COEFF.into(),464 coeff_frac: Perbill::zero(),465 negative: false,466 degree: 1,467 })468 }469}470471impl pallet_transaction_payment::Config for Runtime {472 type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;473 type TransactionByteFee = TransactionByteFee;474 type OperationalFeeMultiplier = OperationalFeeMultiplier;475 type WeightToFee = LinearFee<Balance>;476 type FeeMultiplierUpdate = ();477}478479parameter_types! {480 pub const ProposalBond: Permill = Permill::from_percent(5);481 pub const ProposalBondMinimum: Balance = 1 * UNIQUE;482 pub const ProposalBondMaximum: Balance = 1000 * UNIQUE;483 pub const SpendPeriod: BlockNumber = 5 * MINUTES;484 pub const Burn: Permill = Permill::from_percent(0);485 pub const TipCountdown: BlockNumber = 1 * DAYS;486 pub const TipFindersFee: Percent = Percent::from_percent(20);487 pub const TipReportDepositBase: Balance = 1 * UNIQUE;488 pub const DataDepositPerByte: Balance = 1 * CENTIUNIQUE;489 pub const BountyDepositBase: Balance = 1 * UNIQUE;490 pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;491 pub const TreasuryModuleId: PalletId = PalletId(*b"py/trsry");492 pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;493 pub const MaximumReasonLength: u32 = 16384;494 pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);495 pub const BountyValueMinimum: Balance = 5 * UNIQUE;496 pub const MaxApprovals: u32 = 100;497}498499impl pallet_treasury::Config for Runtime {500 type PalletId = TreasuryModuleId;501 type Currency = Balances;502 type ApproveOrigin = EnsureRoot<AccountId>;503 type RejectOrigin = EnsureRoot<AccountId>;504 type Event = Event;505 type OnSlash = ();506 type ProposalBond = ProposalBond;507 type ProposalBondMinimum = ProposalBondMinimum;508 type ProposalBondMaximum = ProposalBondMaximum;509 type SpendPeriod = SpendPeriod;510 type Burn = Burn;511 type BurnDestination = ();512 type SpendFunds = ();513 type WeightInfo = pallet_treasury::weights::SubstrateWeight<Self>;514 type MaxApprovals = MaxApprovals;515}516517impl pallet_sudo::Config for Runtime {518 type Event = Event;519 type Call = Call;520}521522pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);523524impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider525 for RelayChainBlockNumberProvider<T>526{527 type BlockNumber = BlockNumber;528529 fn current_block_number() -> Self::BlockNumber {530 cumulus_pallet_parachain_system::Pallet::<T>::validation_data()531 .map(|d| d.relay_parent_number)532 .unwrap_or_default()533 }534}535536parameter_types! {537 pub const MinVestedTransfer: Balance = 10 * UNIQUE;538 pub const MaxVestingSchedules: u32 = 28;539}540541impl orml_vesting::Config for Runtime {542 type Event = Event;543 type Currency = pallet_balances::Pallet<Runtime>;544 type MinVestedTransfer = MinVestedTransfer;545 type VestedTransferOrigin = EnsureSigned<AccountId>;546 type WeightInfo = ();547 type MaxVestingSchedules = MaxVestingSchedules;548 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;549}550551parameter_types! {552 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;553 pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;554}555556impl cumulus_pallet_parachain_system::Config for Runtime {557 type Event = Event;558 type SelfParaId = parachain_info::Pallet<Self>;559 type OnSystemEvent = ();560 561 562 563 564 565 type OutboundXcmpMessageSource = XcmpQueue;566 type DmpMessageHandler = DmpQueue;567 type ReservedDmpWeight = ReservedDmpWeight;568 type ReservedXcmpWeight = ReservedXcmpWeight;569 type XcmpMessageHandler = XcmpQueue;570}571572impl parachain_info::Config for Runtime {}573574impl cumulus_pallet_aura_ext::Config for Runtime {}575576parameter_types! {577 pub const RelayLocation: MultiLocation = MultiLocation::parent();578 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;579 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();580 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();581}582583584585586pub type LocationToAccountId = (587 588 ParentIsPreset<AccountId>,589 590 SiblingParachainConvertsVia<Sibling, AccountId>,591 592 AccountId32Aliases<RelayNetwork, AccountId>,593);594595pub struct OnlySelfCurrency;596impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {597 fn matches_fungible(a: &MultiAsset) -> Option<B> {598 match (&a.id, &a.fun) {599 (Concrete(_), XcmFungible(ref amount)) => CheckedConversion::checked_from(*amount),600 _ => None,601 }602 }603}604605606pub type LocalAssetTransactor = CurrencyAdapter<607 608 Balances,609 610 OnlySelfCurrency,611 612 LocationToAccountId,613 614 AccountId,615 616 (),617>;618619620621622pub type XcmOriginToTransactDispatchOrigin = (623 624 625 626 SovereignSignedViaLocation<LocationToAccountId, Origin>,627 628 629 RelayChainAsNative<RelayOrigin, Origin>,630 631 632 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,633 634 635 ParentAsSuperuser<Origin>,636 637 638 SignedAccountId32AsNative<RelayNetwork, Origin>,639 640 XcmPassthrough<Origin>,641);642643parameter_types! {644 645 pub UnitWeightCost: Weight = 1_000_000;646 647 pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);648 pub const MaxInstructions: u32 = 100;649 pub const MaxAuthorities: u32 = 100_000;650}651652match_type! {653 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {654 MultiLocation { parents: 1, interior: Here } |655 MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }656 };657}658659pub type Barrier = (660 TakeWeightCredit,661 AllowTopLevelPaidExecutionFrom<Everything>,662 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,663 664);665666pub struct UsingOnlySelfCurrencyComponents<667 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,668 AssetId: Get<MultiLocation>,669 AccountId,670 Currency: CurrencyT<AccountId>,671 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,672>(673 Weight,674 Currency::Balance,675 PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,676);677impl<678 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,679 AssetId: Get<MultiLocation>,680 AccountId,681 Currency: CurrencyT<AccountId>,682 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,683 > WeightTrader684 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>685{686 fn new() -> Self {687 Self(0, Zero::zero(), PhantomData)688 }689690 fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {691 let amount = WeightToFee::calc(&weight);692 let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;693694 695 let option1: xcm::v1::AssetId = Concrete(MultiLocation {696 parents: 1,697 interior: X1(Parachain(ParachainInfo::parachain_id().into())),698 });699 700 let option2: xcm::v1::AssetId = Concrete(MultiLocation {701 parents: 0,702 interior: Here,703 });704705 let required = if payment.fungible.contains_key(&option1) {706 (option1, u128_amount).into()707 } else if payment.fungible.contains_key(&option2) {708 (option2, u128_amount).into()709 } else {710 (Concrete(MultiLocation::default()), u128_amount).into()711 };712713 let unused = payment714 .checked_sub(required)715 .map_err(|_| XcmError::TooExpensive)?;716 self.0 = self.0.saturating_add(weight);717 self.1 = self.1.saturating_add(amount);718 Ok(unused)719 }720721 fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {722 let weight = weight.min(self.0);723 let amount = WeightToFee::calc(&weight);724 self.0 -= weight;725 self.1 = self.1.saturating_sub(amount);726 let amount: u128 = amount.saturated_into();727 if amount > 0 {728 Some((AssetId::get(), amount).into())729 } else {730 None731 }732 }733}734impl<735 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,736 AssetId: Get<MultiLocation>,737 AccountId,738 Currency: CurrencyT<AccountId>,739 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,740 > Drop741 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>742{743 fn drop(&mut self) {744 OnUnbalanced::on_unbalanced(Currency::issue(self.1));745 }746}747748pub struct XcmConfig;749impl Config for XcmConfig {750 type Call = Call;751 type XcmSender = XcmRouter;752 753 type AssetTransactor = LocalAssetTransactor;754 type OriginConverter = XcmOriginToTransactDispatchOrigin;755 type IsReserve = NativeAsset;756 type IsTeleporter = (); 757 type LocationInverter = LocationInverter<Ancestry>;758 type Barrier = Barrier;759 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;760 type Trader = UsingOnlySelfCurrencyComponents<761 IdentityFee<Balance>,762 RelayLocation,763 AccountId,764 Balances,765 (),766 >;767 type ResponseHandler = (); 768 type SubscriptionService = PolkadotXcm;769770 type AssetTrap = PolkadotXcm;771 type AssetClaims = PolkadotXcm;772}773774775776777778779pub type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, RelayNetwork>,);780781782783pub type XcmRouter = (784 785 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,786 787 XcmpQueue,788);789790impl pallet_evm_coder_substrate::Config for Runtime {791 type EthereumTransactionSender = pallet_ethereum::Pallet<Self>;792 type GasWeightMapping = FixedGasWeightMapping;793}794795impl pallet_xcm::Config for Runtime {796 type Event = Event;797 type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;798 type XcmRouter = XcmRouter;799 type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;800 type XcmExecuteFilter = Everything;801 type XcmExecutor = XcmExecutor<XcmConfig>;802 type XcmTeleportFilter = Everything;803 type XcmReserveTransferFilter = Everything;804 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;805 type LocationInverter = LocationInverter<Ancestry>;806 type Origin = Origin;807 type Call = Call;808 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;809 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;810}811812impl cumulus_pallet_xcm::Config for Runtime {813 type Event = Event;814 type XcmExecutor = XcmExecutor<XcmConfig>;815}816817impl cumulus_pallet_xcmp_queue::Config for Runtime {818 type Event = Event;819 type XcmExecutor = XcmExecutor<XcmConfig>;820 type ChannelInfo = ParachainSystem;821 type VersionWrapper = ();822 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;823 type ControllerOrigin = EnsureRoot<AccountId>;824 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;825}826827impl cumulus_pallet_dmp_queue::Config for Runtime {828 type Event = Event;829 type XcmExecutor = XcmExecutor<XcmConfig>;830 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;831}832833impl pallet_aura::Config for Runtime {834 type AuthorityId = AuraId;835 type DisabledValidators = ();836 type MaxAuthorities = MaxAuthorities;837}838839parameter_types! {840 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();841 pub const CollectionCreationPrice: Balance = 2 * UNIQUE;842}843844impl pallet_common::Config for Runtime {845 type Event = Event;846 type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;847 type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;848 type CrossAccountId = pallet_common::account::BasicCrossAccountId<Self>;849850 type Currency = Balances;851 type CollectionCreationPrice = CollectionCreationPrice;852 type TreasuryAccountId = TreasuryAccountId;853}854855impl pallet_fungible::Config for Runtime {856 type WeightInfo = pallet_fungible::weights::SubstrateWeight<Self>;857}858impl pallet_refungible::Config for Runtime {859 type WeightInfo = pallet_refungible::weights::SubstrateWeight<Self>;860}861impl pallet_nonfungible::Config for Runtime {862 type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;863}864865impl pallet_unique::Config for Runtime {866 type Event = Event;867 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;868}869870parameter_types! {871 pub const InflationBlockInterval: BlockNumber = 100; 872}873874875impl pallet_inflation::Config for Runtime {876 type Currency = Balances;877 type TreasuryAccountId = TreasuryAccountId;878 type InflationBlockInterval = InflationBlockInterval;879 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;880}881882883884885886887888type EvmSponsorshipHandler = (889 pallet_unique::UniqueEthSponsorshipHandler<Runtime>,890 pallet_evm_contract_helpers::HelpersContractSponsoring<Runtime>,891);892type SponsorshipHandler = (893 pallet_unique::UniqueSponsorshipHandler<Runtime>,894 895 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,896);897898899900901902903904905906907908909910impl pallet_evm_transaction_payment::Config for Runtime {911 type EvmSponsorshipHandler = EvmSponsorshipHandler;912 type Currency = Balances;913 type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;914 type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;915}916917impl pallet_charge_transaction::Config for Runtime {918 type SponsorshipHandler = SponsorshipHandler;919}920921922923924925parameter_types! {926 927 pub const HelpersContractAddress: H160 = H160([928 0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,929 ]);930}931932impl pallet_evm_contract_helpers::Config for Runtime {933 type ContractAddress = HelpersContractAddress;934 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;935}936937construct_runtime!(938 pub enum Runtime where939 Block = Block,940 NodeBlock = opaque::Block,941 UncheckedExtrinsic = UncheckedExtrinsic942 {943 ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,944 ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,945946 Aura: pallet_aura::{Pallet, Config<T>} = 22,947 AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23,948949 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,950 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,951 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,952 TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 33,953 Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,954 Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,955 System: frame_system::{Pallet, Call, Storage, Config, Event<T>} = 36,956 Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,957 958 959960 961 XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,962 PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,963 CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,964 DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,965966 967 Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,968 Unique: pallet_unique::{Pallet, Call, Storage, Event<T>} = 61,969 970 971 Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64,972 973 Common: pallet_common::{Pallet, Storage, Event<T>} = 66,974 Fungible: pallet_fungible::{Pallet, Storage} = 67,975 Refungible: pallet_refungible::{Pallet, Storage} = 68,976 Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,977978 979 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,980 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,981982 EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,983 EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage} = 151,984 EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,985 EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,986 }987);988989pub struct TransactionConverter;990991impl fp_rpc::ConvertTransaction<UncheckedExtrinsic> for TransactionConverter {992 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic {993 UncheckedExtrinsic::new_unsigned(994 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),995 )996 }997}998999impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConverter {1000 fn convert_transaction(1001 &self,1002 transaction: pallet_ethereum::Transaction,1003 ) -> opaque::UncheckedExtrinsic {1004 let extrinsic = UncheckedExtrinsic::new_unsigned(1005 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),1006 );1007 let encoded = extrinsic.encode();1008 opaque::UncheckedExtrinsic::decode(&mut &encoded[..])1009 .expect("Encoded extrinsic is always valid")1010 }1011}101210131014pub type Address = sp_runtime::MultiAddress<AccountId, ()>;10151016pub type Header = generic::Header<BlockNumber, BlakeTwo256>;10171018pub type Block = generic::Block<Header, UncheckedExtrinsic>;10191020pub type SignedBlock = generic::SignedBlock<Block>;10211022pub type BlockId = generic::BlockId<Block>;10231024pub type SignedExtra = (1025 frame_system::CheckSpecVersion<Runtime>,1026 1027 frame_system::CheckGenesis<Runtime>,1028 frame_system::CheckEra<Runtime>,1029 frame_system::CheckNonce<Runtime>,1030 frame_system::CheckWeight<Runtime>,1031 pallet_charge_transaction::ChargeTransactionPayment<Runtime>,1032 1033);10341035pub type UncheckedExtrinsic =1036 fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;10371038pub type CheckedExtrinsic = fp_self_contained::CheckedExtrinsic<AccountId, Call, SignedExtra, H160>;10391040pub type Executive = frame_executive::Executive<1041 Runtime,1042 Block,1043 frame_system::ChainContext<Runtime>,1044 Runtime,1045 AllPalletsReversedWithSystemFirst,1046>;10471048impl_opaque_keys! {1049 pub struct SessionKeys {1050 pub aura: Aura,1051 }1052}10531054impl fp_self_contained::SelfContainedCall for Call {1055 type SignedInfo = H160;10561057 fn is_self_contained(&self) -> bool {1058 match self {1059 Call::Ethereum(call) => call.is_self_contained(),1060 _ => false,1061 }1062 }10631064 fn check_self_contained(&self) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {1065 match self {1066 Call::Ethereum(call) => call.check_self_contained(),1067 _ => None,1068 }1069 }10701071 fn validate_self_contained(&self, info: &Self::SignedInfo) -> Option<TransactionValidity> {1072 match self {1073 Call::Ethereum(call) => call.validate_self_contained(info),1074 _ => None,1075 }1076 }10771078 fn pre_dispatch_self_contained(1079 &self,1080 info: &Self::SignedInfo,1081 ) -> Option<Result<(), TransactionValidityError>> {1082 match self {1083 Call::Ethereum(call) => call.pre_dispatch_self_contained(info),1084 _ => None,1085 }1086 }10871088 fn apply_self_contained(1089 self,1090 info: Self::SignedInfo,1091 ) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {1092 match self {1093 call @ Call::Ethereum(pallet_ethereum::Call::transact { .. }) => Some(call.dispatch(1094 Origin::from(pallet_ethereum::RawOrigin::EthereumTransaction(info)),1095 )),1096 _ => None,1097 }1098 }1099}11001101macro_rules! dispatch_unique_runtime {1102 ($collection:ident.$method:ident($($name:ident),*)) => {{1103 use pallet_unique::dispatch::Dispatched;11041105 let collection = Dispatched::dispatch(<pallet_common::CollectionHandle<Runtime>>::try_get($collection)?);1106 let dispatch = collection.as_dyn();11071108 Ok(dispatch.$method($($name),*))1109 }};1110}11111112impl_common_runtime_apis!();11131114struct CheckInherents;11151116impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {1117 fn check_inherents(1118 block: &Block,1119 relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,1120 ) -> sp_inherents::CheckInherentsResult {1121 let relay_chain_slot = relay_state_proof1122 .read_slot()1123 .expect("Could not read the relay chain slot from the proof");11241125 let inherent_data =1126 cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(1127 relay_chain_slot,1128 sp_std::time::Duration::from_secs(6),1129 )1130 .create_inherent_data()1131 .expect("Could not create the timestamp inherent data");11321133 inherent_data.check_extrinsics(block)1134 }1135}11361137cumulus_pallet_parachain_system::register_validate_block!(1138 Runtime = Runtime,1139 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,1140 CheckInherents = CheckInherents,1141);