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::{52 EnsureAddressTruncated, HashedAddressMapping, Runner, account::CrossAccountId as _,53};54pub use frame_support::{55 construct_runtime, match_types,56 dispatch::DispatchResult,57 PalletId, parameter_types, StorageValue, ConsensusEngineId,58 traits::{59 tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Everything,60 Currency, ExistenceRequirement, Get, IsInVec, KeyOwnerProofSystem, LockIdentifier,61 OnUnbalanced, Randomness, FindAuthor, ConstU32, Imbalance,62 },63 weights::{64 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},65 DispatchClass, DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,66 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, ConstantMultiplier,67 },68};69use up_data_structs::*;707172use frame_system::{73 self as frame_system, EnsureRoot, EnsureSigned,74 limits::{BlockWeights, BlockLength},75};76use sp_arithmetic::{77 traits::{BaseArithmetic, Unsigned},78};79use smallvec::smallvec;80use codec::{Encode, Decode};81use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping};82use fp_rpc::TransactionStatus;83use sp_runtime::{84 traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating},85 transaction_validity::TransactionValidityError,86 SaturatedConversion,87};888990pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;919293use pallet_xcm::XcmPassthrough;94use polkadot_parachain::primitives::Sibling;95use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};96use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*};97use xcm_builder::{98 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,99 EnsureXcmOrigin, FixedWeightBounds, LocationInverter, NativeAsset, ParentAsSuperuser,100 RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,101 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,102 ParentIsPreset,103};104use xcm_executor::{Config, XcmExecutor, Assets};105use sp_std::{marker::PhantomData};106107use xcm::latest::{108 109 AssetId::{Concrete},110 Fungibility::Fungible as XcmFungible,111 MultiAsset,112 Error as XcmError,113};114use xcm_executor::traits::{MatchesFungible, WeightTrader};115116use sp_runtime::traits::CheckedConversion;117118use unique_runtime_common::{119 impl_common_runtime_apis,120 types::*,121 constants::*,122 dispatch::{CollectionDispatchT, CollectionDispatch},123 sponsoring::UniqueSponsorshipHandler,124 eth_sponsoring::UniqueEthSponsorshipHandler,125 weights::CommonWeights,126};127128pub const RUNTIME_NAME: &str = "quartz";129pub const TOKEN_SYMBOL: &str = "QTZ";130131type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;132133impl RuntimeInstance for Runtime {134 type CrossAccountId = self::CrossAccountId;135136 type TransactionConverter = self::TransactionConverter;137138 fn get_transaction_converter() -> TransactionConverter {139 TransactionConverter140 }141}142143144145146147pub mod opaque {148 use sp_std::prelude::*;149 use sp_runtime::impl_opaque_keys;150 use super::Aura;151152 pub use unique_runtime_common::types::*;153154 impl_opaque_keys! {155 pub struct SessionKeys {156 pub aura: Aura,157 }158 }159}160161162pub const VERSION: RuntimeVersion = RuntimeVersion {163 spec_name: create_runtime_str!(RUNTIME_NAME),164 impl_name: create_runtime_str!(RUNTIME_NAME),165 authoring_version: 1,166 spec_version: 921080,167 impl_version: 0,168 apis: RUNTIME_API_VERSIONS,169 transaction_version: 1,170 state_version: 0,171};172173#[derive(codec::Encode, codec::Decode)]174pub enum XCMPMessage<XAccountId, XBalance> {175 176 TransferToken(XAccountId, XBalance),177}178179180#[cfg(feature = "std")]181pub fn native_version() -> NativeVersion {182 NativeVersion {183 runtime_version: VERSION,184 can_author_with: Default::default(),185 }186}187188type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;189190pub struct DealWithFees;191impl OnUnbalanced<NegativeImbalance> for DealWithFees {192 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {193 if let Some(fees) = fees_then_tips.next() {194 195 let mut split = fees.ration(100, 0);196 if let Some(tips) = fees_then_tips.next() {197 198 tips.ration_merge_into(100, 0, &mut split);199 }200 Treasury::on_unbalanced(split.0);201 202 }203 }204}205206parameter_types! {207 pub const BlockHashCount: BlockNumber = 2400;208 pub RuntimeBlockLength: BlockLength =209 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);210 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);211 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;212 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()213 .base_block(BlockExecutionWeight::get())214 .for_class(DispatchClass::all(), |weights| {215 weights.base_extrinsic = ExtrinsicBaseWeight::get();216 })217 .for_class(DispatchClass::Normal, |weights| {218 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);219 })220 .for_class(DispatchClass::Operational, |weights| {221 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);222 223 224 weights.reserved = Some(225 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT226 );227 })228 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)229 .build_or_panic();230 pub const Version: RuntimeVersion = VERSION;231 pub const SS58Prefix: u8 = 255;232}233234parameter_types! {235 pub const ChainId: u64 = 8881;236}237238pub struct FixedFee;239impl FeeCalculator for FixedFee {240 fn min_gas_price() -> U256 {241 MIN_GAS_PRICE.into()242 }243}244245246247248parameter_types! {249 pub const WritesPerSecond: u64 = WEIGHT_PER_SECOND / <Runtime as frame_system::Config>::DbWeight::get().write;250 pub const GasPerSecond: u64 = WritesPerSecond::get() * 20000;251 pub const WeightPerGas: u64 = WEIGHT_PER_SECOND / GasPerSecond::get();252}253254255256257const EVM_DISPATCH_RATIO: Perbill = Perbill::from_percent(50);258parameter_types! {259 pub BlockGasLimit: U256 = U256::from(NORMAL_DISPATCH_RATIO * EVM_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT / WeightPerGas::get());260}261262pub enum FixedGasWeightMapping {}263impl GasWeightMapping for FixedGasWeightMapping {264 fn gas_to_weight(gas: u64) -> Weight {265 gas.saturating_mul(WeightPerGas::get())266 }267 fn weight_to_gas(weight: Weight) -> u64 {268 weight / WeightPerGas::get()269 }270}271272impl pallet_evm::Config for Runtime {273 type BlockGasLimit = BlockGasLimit;274 type FeeCalculator = FixedFee;275 type GasWeightMapping = FixedGasWeightMapping;276 type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;277 type CallOrigin = EnsureAddressTruncated<Self>;278 type WithdrawOrigin = EnsureAddressTruncated<Self>;279 type AddressMapping = HashedAddressMapping<Self::Hashing>;280 type PrecompilesType = ();281 type PrecompilesValue = ();282 type Currency = Balances;283 type Event = Event;284 type OnMethodCall = (285 pallet_evm_migration::OnMethodCall<Self>,286 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,287 CollectionDispatchT<Self>,288 pallet_unique::eth::CollectionHelpersOnMethodCall<Self>,289 );290 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;291 type ChainId = ChainId;292 type Runner = pallet_evm::runner::stack::Runner<Self>;293 type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, DealWithFees>;294 type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;295 type FindAuthor = EthereumFindAuthor<Aura>;296}297298impl pallet_evm_migration::Config for Runtime {299 type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;300}301302pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);303impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {304 fn find_author<'a, I>(digests: I) -> Option<H160>305 where306 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,307 {308 if let Some(author_index) = F::find_author(digests) {309 let authority_id = Aura::authorities()[author_index as usize].clone();310 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));311 }312 None313 }314}315316impl pallet_ethereum::Config for Runtime {317 type Event = Event;318 type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;319}320321impl pallet_randomness_collective_flip::Config for Runtime {}322323impl frame_system::Config for Runtime {324 325 type AccountData = pallet_balances::AccountData<Balance>;326 327 type AccountId = AccountId;328 329 type BaseCallFilter = Everything;330 331 type BlockHashCount = BlockHashCount;332 333 type BlockLength = RuntimeBlockLength;334 335 type BlockNumber = BlockNumber;336 337 type BlockWeights = RuntimeBlockWeights;338 339 type Call = Call;340 341 type DbWeight = RocksDbWeight;342 343 type Event = Event;344 345 type Hash = Hash;346 347 type Hashing = BlakeTwo256;348 349 type Header = generic::Header<BlockNumber, BlakeTwo256>;350 351 type Index = Index;352 353 type Lookup = AccountIdLookup<AccountId, ()>;354 355 type OnKilledAccount = ();356 357 type OnNewAccount = ();358 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;359 360 type Origin = Origin;361 362 type PalletInfo = PalletInfo;363 364 type SS58Prefix = SS58Prefix;365 366 type SystemWeightInfo = frame_system::weights::SubstrateWeight<Self>;367 368 type Version = Version;369 type MaxConsumers = ConstU32<16>;370}371372parameter_types! {373 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;374}375376impl pallet_timestamp::Config for Runtime {377 378 type Moment = u64;379 type OnTimestampSet = ();380 type MinimumPeriod = MinimumPeriod;381 type WeightInfo = ();382}383384parameter_types! {385 386 pub const ExistentialDeposit: u128 = 0;387 pub const MaxLocks: u32 = 50;388}389390impl pallet_balances::Config for Runtime {391 type MaxLocks = MaxLocks;392 type MaxReserves = ();393 type ReserveIdentifier = [u8; 8];394 395 type Balance = Balance;396 397 type Event = Event;398 type DustRemoval = Treasury;399 type ExistentialDeposit = ExistentialDeposit;400 type AccountStore = System;401 type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;402}403404pub const fn deposit(items: u32, bytes: u32) -> Balance {405 items as Balance * 15 * CENTIUNIQUE + (bytes as Balance) * 6 * CENTIUNIQUE406}407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458parameter_types! {459 460 461 pub const OperationalFeeMultiplier: u8 = 5;462}463464465pub struct LinearFee<T>(sp_std::marker::PhantomData<T>);466467impl<T> WeightToFeePolynomial for LinearFee<T>468where469 T: BaseArithmetic + From<u32> + Copy + Unsigned,470{471 type Balance = T;472473 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {474 smallvec!(WeightToFeeCoefficient {475 476 coeff_integer: WEIGHT_TO_FEE_COEFF.into(),477 coeff_frac: Perbill::zero(),478 negative: false,479 degree: 1,480 })481 }482}483484impl pallet_transaction_payment::Config for Runtime {485 type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;486 type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;487 type OperationalFeeMultiplier = OperationalFeeMultiplier;488 type WeightToFee = LinearFee<Balance>;489 type FeeMultiplierUpdate = ();490}491492parameter_types! {493 pub const ProposalBond: Permill = Permill::from_percent(5);494 pub const ProposalBondMinimum: Balance = 1 * UNIQUE;495 pub const ProposalBondMaximum: Balance = 1000 * UNIQUE;496 pub const SpendPeriod: BlockNumber = 5 * MINUTES;497 pub const Burn: Permill = Permill::from_percent(0);498 pub const TipCountdown: BlockNumber = 1 * DAYS;499 pub const TipFindersFee: Percent = Percent::from_percent(20);500 pub const TipReportDepositBase: Balance = 1 * UNIQUE;501 pub const DataDepositPerByte: Balance = 1 * CENTIUNIQUE;502 pub const BountyDepositBase: Balance = 1 * UNIQUE;503 pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;504 pub const TreasuryModuleId: PalletId = PalletId(*b"py/trsry");505 pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;506 pub const MaximumReasonLength: u32 = 16384;507 pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);508 pub const BountyValueMinimum: Balance = 5 * UNIQUE;509 pub const MaxApprovals: u32 = 100;510}511512impl pallet_treasury::Config for Runtime {513 type PalletId = TreasuryModuleId;514 type Currency = Balances;515 type ApproveOrigin = EnsureRoot<AccountId>;516 type RejectOrigin = EnsureRoot<AccountId>;517 type Event = Event;518 type OnSlash = ();519 type ProposalBond = ProposalBond;520 type ProposalBondMinimum = ProposalBondMinimum;521 type ProposalBondMaximum = ProposalBondMaximum;522 type SpendPeriod = SpendPeriod;523 type Burn = Burn;524 type BurnDestination = ();525 type SpendFunds = ();526 type WeightInfo = pallet_treasury::weights::SubstrateWeight<Self>;527 type MaxApprovals = MaxApprovals;528}529530impl pallet_sudo::Config for Runtime {531 type Event = Event;532 type Call = Call;533}534535pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);536537impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider538 for RelayChainBlockNumberProvider<T>539{540 type BlockNumber = BlockNumber;541542 fn current_block_number() -> Self::BlockNumber {543 cumulus_pallet_parachain_system::Pallet::<T>::validation_data()544 .map(|d| d.relay_parent_number)545 .unwrap_or_default()546 }547}548549parameter_types! {550 pub const MinVestedTransfer: Balance = 10 * UNIQUE;551 pub const MaxVestingSchedules: u32 = 28;552}553554impl orml_vesting::Config for Runtime {555 type Event = Event;556 type Currency = pallet_balances::Pallet<Runtime>;557 type MinVestedTransfer = MinVestedTransfer;558 type VestedTransferOrigin = EnsureSigned<AccountId>;559 type WeightInfo = ();560 type MaxVestingSchedules = MaxVestingSchedules;561 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;562}563564parameter_types! {565 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;566 pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;567}568569impl cumulus_pallet_parachain_system::Config for Runtime {570 type Event = Event;571 type SelfParaId = parachain_info::Pallet<Self>;572 type OnSystemEvent = ();573 574 575 576 577 578 type OutboundXcmpMessageSource = XcmpQueue;579 type DmpMessageHandler = DmpQueue;580 type ReservedDmpWeight = ReservedDmpWeight;581 type ReservedXcmpWeight = ReservedXcmpWeight;582 type XcmpMessageHandler = XcmpQueue;583}584585impl parachain_info::Config for Runtime {}586587impl cumulus_pallet_aura_ext::Config for Runtime {}588589parameter_types! {590 pub const RelayLocation: MultiLocation = MultiLocation::parent();591 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;592 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();593 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();594}595596597598599pub type LocationToAccountId = (600 601 ParentIsPreset<AccountId>,602 603 SiblingParachainConvertsVia<Sibling, AccountId>,604 605 AccountId32Aliases<RelayNetwork, AccountId>,606);607608pub struct OnlySelfCurrency;609impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {610 fn matches_fungible(a: &MultiAsset) -> Option<B> {611 match (&a.id, &a.fun) {612 (Concrete(_), XcmFungible(ref amount)) => CheckedConversion::checked_from(*amount),613 _ => None,614 }615 }616}617618619pub type LocalAssetTransactor = CurrencyAdapter<620 621 Balances,622 623 OnlySelfCurrency,624 625 LocationToAccountId,626 627 AccountId,628 629 (),630>;631632633634635pub type XcmOriginToTransactDispatchOrigin = (636 637 638 639 SovereignSignedViaLocation<LocationToAccountId, Origin>,640 641 642 RelayChainAsNative<RelayOrigin, Origin>,643 644 645 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,646 647 648 ParentAsSuperuser<Origin>,649 650 651 SignedAccountId32AsNative<RelayNetwork, Origin>,652 653 XcmPassthrough<Origin>,654);655656parameter_types! {657 658 pub UnitWeightCost: Weight = 1_000_000;659 660 pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);661 pub const MaxInstructions: u32 = 100;662 pub const MaxAuthorities: u32 = 100_000;663}664665match_types! {666 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {667 MultiLocation { parents: 1, interior: Here } |668 MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }669 };670}671672pub type Barrier = (673 TakeWeightCredit,674 AllowTopLevelPaidExecutionFrom<Everything>,675 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,676 677);678679pub struct UsingOnlySelfCurrencyComponents<680 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,681 AssetId: Get<MultiLocation>,682 AccountId,683 Currency: CurrencyT<AccountId>,684 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,685>(686 Weight,687 Currency::Balance,688 PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,689);690impl<691 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,692 AssetId: Get<MultiLocation>,693 AccountId,694 Currency: CurrencyT<AccountId>,695 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,696 > WeightTrader697 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>698{699 fn new() -> Self {700 Self(0, Zero::zero(), PhantomData)701 }702703 fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {704 let amount = WeightToFee::calc(&weight);705 let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;706707 708 let option1: xcm::v1::AssetId = Concrete(MultiLocation {709 parents: 1,710 interior: X1(Parachain(ParachainInfo::parachain_id().into())),711 });712 713 let option2: xcm::v1::AssetId = Concrete(MultiLocation {714 parents: 0,715 interior: Here,716 });717718 let required = if payment.fungible.contains_key(&option1) {719 (option1, u128_amount).into()720 } else if payment.fungible.contains_key(&option2) {721 (option2, u128_amount).into()722 } else {723 (Concrete(MultiLocation::default()), u128_amount).into()724 };725726 let unused = payment727 .checked_sub(required)728 .map_err(|_| XcmError::TooExpensive)?;729 self.0 = self.0.saturating_add(weight);730 self.1 = self.1.saturating_add(amount);731 Ok(unused)732 }733734 fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {735 let weight = weight.min(self.0);736 let amount = WeightToFee::calc(&weight);737 self.0 -= weight;738 self.1 = self.1.saturating_sub(amount);739 let amount: u128 = amount.saturated_into();740 if amount > 0 {741 Some((AssetId::get(), amount).into())742 } else {743 None744 }745 }746}747impl<748 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,749 AssetId: Get<MultiLocation>,750 AccountId,751 Currency: CurrencyT<AccountId>,752 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,753 > Drop754 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>755{756 fn drop(&mut self) {757 OnUnbalanced::on_unbalanced(Currency::issue(self.1));758 }759}760761pub struct XcmConfig;762impl Config for XcmConfig {763 type Call = Call;764 type XcmSender = XcmRouter;765 766 type AssetTransactor = LocalAssetTransactor;767 type OriginConverter = XcmOriginToTransactDispatchOrigin;768 type IsReserve = NativeAsset;769 type IsTeleporter = (); 770 type LocationInverter = LocationInverter<Ancestry>;771 type Barrier = Barrier;772 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;773 type Trader = UsingOnlySelfCurrencyComponents<774 IdentityFee<Balance>,775 RelayLocation,776 AccountId,777 Balances,778 (),779 >;780 type ResponseHandler = (); 781 type SubscriptionService = PolkadotXcm;782783 type AssetTrap = PolkadotXcm;784 type AssetClaims = PolkadotXcm;785}786787788789790791792pub type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, RelayNetwork>,);793794795796pub type XcmRouter = (797 798 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,799 800 XcmpQueue,801);802803impl pallet_evm_coder_substrate::Config for Runtime {}804805impl pallet_xcm::Config for Runtime {806 type Event = Event;807 type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;808 type XcmRouter = XcmRouter;809 type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;810 type XcmExecuteFilter = Everything;811 type XcmExecutor = XcmExecutor<XcmConfig>;812 type XcmTeleportFilter = Everything;813 type XcmReserveTransferFilter = Everything;814 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;815 type LocationInverter = LocationInverter<Ancestry>;816 type Origin = Origin;817 type Call = Call;818 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;819 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;820}821822impl cumulus_pallet_xcm::Config for Runtime {823 type Event = Event;824 type XcmExecutor = XcmExecutor<XcmConfig>;825}826827impl cumulus_pallet_xcmp_queue::Config for Runtime {828 type WeightInfo = ();829 type Event = Event;830 type XcmExecutor = XcmExecutor<XcmConfig>;831 type ChannelInfo = ParachainSystem;832 type VersionWrapper = ();833 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;834 type ControllerOrigin = EnsureRoot<AccountId>;835 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;836}837838impl cumulus_pallet_dmp_queue::Config for Runtime {839 type Event = Event;840 type XcmExecutor = XcmExecutor<XcmConfig>;841 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;842}843844impl pallet_aura::Config for Runtime {845 type AuthorityId = AuraId;846 type DisabledValidators = ();847 type MaxAuthorities = MaxAuthorities;848}849850parameter_types! {851 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();852 pub const CollectionCreationPrice: Balance = 2 * UNIQUE;853}854855impl pallet_common::Config for Runtime {856 type Event = Event;857858 type Currency = Balances;859 type CollectionCreationPrice = CollectionCreationPrice;860 type TreasuryAccountId = TreasuryAccountId;861 type CollectionDispatch = CollectionDispatchT<Self>;862863 type EvmTokenAddressMapping = EvmTokenAddressMapping;864 type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;865 type ContractAddress = EvmCollectionHelpersAddress;866}867868impl pallet_structure::Config for Runtime {869 type Event = Event;870 type Call = Call;871 type WeightInfo = pallet_structure::weights::SubstrateWeight<Self>;872}873874impl pallet_evm::account::Config for Runtime {875 type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Self>;876 type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;877 type EvmBackwardsAddressMapping = fp_evm_mapping::MapBackwardsAddressTruncated;878}879880impl pallet_fungible::Config for Runtime {881 type WeightInfo = pallet_fungible::weights::SubstrateWeight<Self>;882}883impl pallet_refungible::Config for Runtime {884 type WeightInfo = pallet_refungible::weights::SubstrateWeight<Self>;885}886impl pallet_nonfungible::Config for Runtime {887 type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;888}889890891892893894895896897898impl pallet_unique::Config for Runtime {899 type Event = Event;900 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;901 type CommonWeightInfo = CommonWeights<Self>;902}903904parameter_types! {905 pub const InflationBlockInterval: BlockNumber = 100; 906}907908909impl pallet_inflation::Config for Runtime {910 type Currency = Balances;911 type TreasuryAccountId = TreasuryAccountId;912 type InflationBlockInterval = InflationBlockInterval;913 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;914}915916917918919920921922type EvmSponsorshipHandler = (923 UniqueEthSponsorshipHandler<Runtime>,924 pallet_evm_contract_helpers::HelpersContractSponsoring<Runtime>,925);926type SponsorshipHandler = (927 UniqueSponsorshipHandler<Runtime>,928 929 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,930);931932933934935936937938939940941942943944impl pallet_evm_transaction_payment::Config for Runtime {945 type EvmSponsorshipHandler = EvmSponsorshipHandler;946 type Currency = Balances;947}948949impl pallet_charge_transaction::Config for Runtime {950 type SponsorshipHandler = SponsorshipHandler;951}952953954955956957parameter_types! {958 959 pub const HelpersContractAddress: H160 = H160([960 0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,961 ]);962 963 964 pub const EvmCollectionHelpersAddress: H160 = H160([965 0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,966 ]);967}968969impl pallet_evm_contract_helpers::Config for Runtime {970 type ContractAddress = HelpersContractAddress;971 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;972}973974construct_runtime!(975 pub enum Runtime where976 Block = Block,977 NodeBlock = opaque::Block,978 UncheckedExtrinsic = UncheckedExtrinsic979 {980 ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,981 ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,982983 Aura: pallet_aura::{Pallet, Config<T>} = 22,984 AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23,985986 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,987 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,988 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,989 TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 33,990 Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,991 Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,992 System: frame_system::{Pallet, Call, Storage, Config, Event<T>} = 36,993 Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,994 995 996997 998 XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,999 PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,1000 CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,1001 DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,10021003 1004 Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,1005 Unique: pallet_unique::{Pallet, Call, Storage, Event<T>} = 61,1006 1007 1008 Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64,1009 1010 Common: pallet_common::{Pallet, Storage, Event<T>} = 66,1011 Fungible: pallet_fungible::{Pallet, Storage} = 67,1012 Refungible: pallet_refungible::{Pallet, Storage} = 68,1013 Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,1014 Structure: pallet_structure::{Pallet, Call, Storage, Event<T>} = 70,1015 1016101710181019 1020 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,1021 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,10221023 EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,1024 EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage} = 151,1025 EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,1026 EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,1027 }1028);10291030pub struct TransactionConverter;10311032impl fp_rpc::ConvertTransaction<UncheckedExtrinsic> for TransactionConverter {1033 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic {1034 UncheckedExtrinsic::new_unsigned(1035 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),1036 )1037 }1038}10391040impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConverter {1041 fn convert_transaction(1042 &self,1043 transaction: pallet_ethereum::Transaction,1044 ) -> opaque::UncheckedExtrinsic {1045 let extrinsic = UncheckedExtrinsic::new_unsigned(1046 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),1047 );1048 let encoded = extrinsic.encode();1049 opaque::UncheckedExtrinsic::decode(&mut &encoded[..])1050 .expect("Encoded extrinsic is always valid")1051 }1052}105310541055pub type Address = sp_runtime::MultiAddress<AccountId, ()>;10561057pub type Header = generic::Header<BlockNumber, BlakeTwo256>;10581059pub type Block = generic::Block<Header, UncheckedExtrinsic>;10601061pub type SignedBlock = generic::SignedBlock<Block>;10621063pub type BlockId = generic::BlockId<Block>;10641065pub type SignedExtra = (1066 frame_system::CheckSpecVersion<Runtime>,1067 1068 frame_system::CheckGenesis<Runtime>,1069 frame_system::CheckEra<Runtime>,1070 frame_system::CheckNonce<Runtime>,1071 frame_system::CheckWeight<Runtime>,1072 pallet_charge_transaction::ChargeTransactionPayment<Runtime>,1073 1074 pallet_ethereum::FakeTransactionFinalizer<Runtime>,1075);10761077pub type UncheckedExtrinsic =1078 fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;10791080pub type CheckedExtrinsic = fp_self_contained::CheckedExtrinsic<AccountId, Call, SignedExtra, H160>;10811082pub type Executive = frame_executive::Executive<1083 Runtime,1084 Block,1085 frame_system::ChainContext<Runtime>,1086 Runtime,1087 AllPalletsReversedWithSystemFirst,1088>;10891090impl_opaque_keys! {1091 pub struct SessionKeys {1092 pub aura: Aura,1093 }1094}10951096impl fp_self_contained::SelfContainedCall for Call {1097 type SignedInfo = H160;10981099 fn is_self_contained(&self) -> bool {1100 match self {1101 Call::Ethereum(call) => call.is_self_contained(),1102 _ => false,1103 }1104 }11051106 fn check_self_contained(&self) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {1107 match self {1108 Call::Ethereum(call) => call.check_self_contained(),1109 _ => None,1110 }1111 }11121113 fn validate_self_contained(&self, info: &Self::SignedInfo) -> Option<TransactionValidity> {1114 match self {1115 Call::Ethereum(call) => call.validate_self_contained(info),1116 _ => None,1117 }1118 }11191120 fn pre_dispatch_self_contained(1121 &self,1122 info: &Self::SignedInfo,1123 ) -> Option<Result<(), TransactionValidityError>> {1124 match self {1125 Call::Ethereum(call) => call.pre_dispatch_self_contained(info),1126 _ => None,1127 }1128 }11291130 fn apply_self_contained(1131 self,1132 info: Self::SignedInfo,1133 ) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {1134 match self {1135 call @ Call::Ethereum(pallet_ethereum::Call::transact { .. }) => Some(call.dispatch(1136 Origin::from(pallet_ethereum::RawOrigin::EthereumTransaction(info)),1137 )),1138 _ => None,1139 }1140 }1141}11421143macro_rules! dispatch_unique_runtime {1144 ($collection:ident.$method:ident($($name:ident),*)) => {{1145 let collection = <Runtime as pallet_common::Config>::CollectionDispatch::dispatch(<pallet_common::CollectionHandle<Runtime>>::try_get($collection)?);1146 let dispatch = collection.as_dyn();11471148 Ok::<_, DispatchError>(dispatch.$method($($name),*))1149 }};1150}11511152impl_common_runtime_apis!();11531154struct CheckInherents;11551156impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {1157 fn check_inherents(1158 block: &Block,1159 relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,1160 ) -> sp_inherents::CheckInherentsResult {1161 let relay_chain_slot = relay_state_proof1162 .read_slot()1163 .expect("Could not read the relay chain slot from the proof");11641165 let inherent_data =1166 cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(1167 relay_chain_slot,1168 sp_std::time::Duration::from_secs(6),1169 )1170 .create_inherent_data()1171 .expect("Could not create the timestamp inherent data");11721173 inherent_data.check_extrinsics(block)1174 }1175}11761177cumulus_pallet_parachain_system::register_validate_block!(1178 Runtime = Runtime,1179 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,1180 CheckInherents = CheckInherents,1181);