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 = "Opal";118119type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;120121impl RuntimeInstance for Runtime {122 type CrossAccountId = self::CrossAccountId;123 type TransactionConverter = self::TransactionConverter;124125 fn get_transaction_converter() -> TransactionConverter {126 TransactionConverter127 }128}129130131132pub type AccountIndex = u32;133134135pub type Balance = u128;136137138pub type Index = u32;139140141pub type Hash = sp_core::H256;142143144pub type DigestItem = generic::DigestItem;145146147148149150pub mod opaque {151 use sp_std::prelude::*;152 use sp_runtime::impl_opaque_keys;153 use super::Aura;154155 pub use unique_runtime_common::types::*;156157 impl_opaque_keys! {158 pub struct SessionKeys {159 pub aura: Aura,160 }161 }162}163164165pub const VERSION: RuntimeVersion = RuntimeVersion {166 spec_name: create_runtime_str!(RUNTIME_NAME),167 impl_name: create_runtime_str!(RUNTIME_NAME),168 authoring_version: 1,169 spec_version: 917004,170 impl_version: 0,171 apis: RUNTIME_API_VERSIONS,172 transaction_version: 1,173 state_version: 0,174};175176#[derive(codec::Encode, codec::Decode)]177pub enum XCMPMessage<XAccountId, XBalance> {178 179 TransferToken(XAccountId, XBalance),180}181182183#[cfg(feature = "std")]184pub fn native_version() -> NativeVersion {185 NativeVersion {186 runtime_version: VERSION,187 can_author_with: Default::default(),188 }189}190191type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;192193pub struct DealWithFees;194impl OnUnbalanced<NegativeImbalance> for DealWithFees {195 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {196 if let Some(fees) = fees_then_tips.next() {197 198 let mut split = fees.ration(100, 0);199 if let Some(tips) = fees_then_tips.next() {200 201 tips.ration_merge_into(100, 0, &mut split);202 }203 Treasury::on_unbalanced(split.0);204 205 }206 }207}208209parameter_types! {210 pub const BlockHashCount: BlockNumber = 2400;211 pub RuntimeBlockLength: BlockLength =212 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);213 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);214 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;215 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()216 .base_block(BlockExecutionWeight::get())217 .for_class(DispatchClass::all(), |weights| {218 weights.base_extrinsic = ExtrinsicBaseWeight::get();219 })220 .for_class(DispatchClass::Normal, |weights| {221 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);222 })223 .for_class(DispatchClass::Operational, |weights| {224 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);225 226 227 weights.reserved = Some(228 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT229 );230 })231 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)232 .build_or_panic();233 pub const Version: RuntimeVersion = VERSION;234 pub const SS58Prefix: u8 = 42;235}236237parameter_types! {238 pub const ChainId: u64 = 8882;239}240241pub struct FixedFee;242impl FeeCalculator for FixedFee {243 fn min_gas_price() -> U256 {244 MIN_GAS_PRICE.into()245 }246}247248249250251parameter_types! {252 pub const WritesPerSecond: u64 = WEIGHT_PER_SECOND / <Runtime as frame_system::Config>::DbWeight::get().write;253 pub const GasPerSecond: u64 = WritesPerSecond::get() * 20000;254 pub const WeightPerGas: u64 = WEIGHT_PER_SECOND / GasPerSecond::get();255}256257258259260const EVM_DISPATCH_RATIO: Perbill = Perbill::from_percent(50);261parameter_types! {262 pub BlockGasLimit: U256 = U256::from(NORMAL_DISPATCH_RATIO * EVM_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT / WeightPerGas::get());263}264265pub enum FixedGasWeightMapping {}266impl GasWeightMapping for FixedGasWeightMapping {267 fn gas_to_weight(gas: u64) -> Weight {268 gas.saturating_mul(WeightPerGas::get())269 }270 fn weight_to_gas(weight: Weight) -> u64 {271 weight / WeightPerGas::get()272 }273}274275impl pallet_evm::account::Config for Runtime {276 type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Self>;277 type EvmAddressMapping = pallet_evm::HashedAddressMapping<Self::Hashing>;278 type EvmBackwardsAddressMapping = fp_evm_mapping::MapBackwardsAddressTruncated;279}280281impl pallet_evm::Config for Runtime {282 type BlockGasLimit = BlockGasLimit;283 type FeeCalculator = FixedFee;284 type GasWeightMapping = FixedGasWeightMapping;285 type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;286 type CallOrigin = EnsureAddressTruncated;287 type WithdrawOrigin = EnsureAddressTruncated;288 type AddressMapping = HashedAddressMapping<Self::Hashing>;289 type PrecompilesType = ();290 type PrecompilesValue = ();291 type Currency = Balances;292 type Event = Event;293 type OnMethodCall = (294 pallet_evm_migration::OnMethodCall<Self>,295 pallet_unique::UniqueErcSupport<Self>,296 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,297 );298 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;299 type ChainId = ChainId;300 type Runner = pallet_evm::runner::stack::Runner<Self>;301 type OnChargeTransaction = pallet_evm_transaction_payment::OnChargeTransaction<Self>;302 type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;303 type FindAuthor = EthereumFindAuthor<Aura>;304}305306impl pallet_evm_migration::Config for Runtime {307 type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;308}309310impl frame_common::account::Config for Runtime {311 type EvmAddressMapping = pallet_evm::HashedAddressMapping<Self::Hashing>;312 type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;313}314315pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);316impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {317 fn find_author<'a, I>(digests: I) -> Option<H160>318 where319 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,320 {321 if let Some(author_index) = F::find_author(digests) {322 let authority_id = Aura::authorities()[author_index as usize].clone();323 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));324 }325 None326 }327}328329impl pallet_ethereum::Config for Runtime {330 type Event = Event;331 type StateRoot = pallet_ethereum::IntermediateStateRoot;332}333334impl pallet_randomness_collective_flip::Config for Runtime {}335336impl frame_system::Config for Runtime {337 338 type AccountData = pallet_balances::AccountData<Balance>;339 340 type AccountId = AccountId;341 342 type BaseCallFilter = Everything;343 344 type BlockHashCount = BlockHashCount;345 346 type BlockLength = RuntimeBlockLength;347 348 type BlockNumber = BlockNumber;349 350 type BlockWeights = RuntimeBlockWeights;351 352 type Call = Call;353 354 type DbWeight = RocksDbWeight;355 356 type Event = Event;357 358 type Hash = Hash;359 360 type Hashing = BlakeTwo256;361 362 type Header = generic::Header<BlockNumber, BlakeTwo256>;363 364 type Index = Index;365 366 type Lookup = AccountIdLookup<AccountId, ()>;367 368 type OnKilledAccount = ();369 370 type OnNewAccount = ();371 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;372 373 type Origin = Origin;374 375 type PalletInfo = PalletInfo;376 377 type SS58Prefix = SS58Prefix;378 379 type SystemWeightInfo = frame_system::weights::SubstrateWeight<Self>;380 381 type Version = Version;382 type MaxConsumers = ConstU32<16>;383}384385parameter_types! {386 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;387}388389impl pallet_timestamp::Config for Runtime {390 391 type Moment = u64;392 type OnTimestampSet = ();393 type MinimumPeriod = MinimumPeriod;394 type WeightInfo = ();395}396397parameter_types! {398 399 pub const ExistentialDeposit: u128 = 0;400 pub const MaxLocks: u32 = 50;401}402403impl pallet_balances::Config for Runtime {404 type MaxLocks = MaxLocks;405 type MaxReserves = ();406 type ReserveIdentifier = [u8; 8];407 408 type Balance = Balance;409 410 type Event = Event;411 type DustRemoval = Treasury;412 type ExistentialDeposit = ExistentialDeposit;413 type AccountStore = System;414 type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;415}416417pub const fn deposit(items: u32, bytes: u32) -> Balance {418 items as Balance * 15 * CENTIUNIQUE + (bytes as Balance) * 6 * CENTIUNIQUE419}420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471parameter_types! {472 473 474 pub const OperationalFeeMultiplier: u8 = 5;475}476477478pub struct LinearFee<T>(sp_std::marker::PhantomData<T>);479480impl<T> WeightToFeePolynomial for LinearFee<T>481where482 T: BaseArithmetic + From<u32> + Copy + Unsigned,483{484 type Balance = T;485486 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {487 smallvec!(WeightToFeeCoefficient {488 489 coeff_integer: WEIGHT_TO_FEE_COEFF.into(),490 coeff_frac: Perbill::zero(),491 negative: false,492 degree: 1,493 })494 }495}496497impl pallet_transaction_payment::Config for Runtime {498 type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;499 type TransactionByteFee = TransactionByteFee;500 type OperationalFeeMultiplier = OperationalFeeMultiplier;501 type WeightToFee = LinearFee<Balance>;502 type FeeMultiplierUpdate = ();503}504505parameter_types! {506 pub const ProposalBond: Permill = Permill::from_percent(5);507 pub const ProposalBondMinimum: Balance = 1 * UNIQUE;508 pub const ProposalBondMaximum: Balance = 1000 * UNIQUE;509 pub const SpendPeriod: BlockNumber = 5 * MINUTES;510 pub const Burn: Permill = Permill::from_percent(0);511 pub const TipCountdown: BlockNumber = 1 * DAYS;512 pub const TipFindersFee: Percent = Percent::from_percent(20);513 pub const TipReportDepositBase: Balance = 1 * UNIQUE;514 pub const DataDepositPerByte: Balance = 1 * CENTIUNIQUE;515 pub const BountyDepositBase: Balance = 1 * UNIQUE;516 pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;517 pub const TreasuryModuleId: PalletId = PalletId(*b"py/trsry");518 pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;519 pub const MaximumReasonLength: u32 = 16384;520 pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);521 pub const BountyValueMinimum: Balance = 5 * UNIQUE;522 pub const MaxApprovals: u32 = 100;523}524525impl pallet_treasury::Config for Runtime {526 type PalletId = TreasuryModuleId;527 type Currency = Balances;528 type ApproveOrigin = EnsureRoot<AccountId>;529 type RejectOrigin = EnsureRoot<AccountId>;530 type Event = Event;531 type OnSlash = ();532 type ProposalBond = ProposalBond;533 type ProposalBondMinimum = ProposalBondMinimum;534 type ProposalBondMaximum = ProposalBondMaximum;535 type SpendPeriod = SpendPeriod;536 type Burn = Burn;537 type BurnDestination = ();538 type SpendFunds = ();539 type WeightInfo = pallet_treasury::weights::SubstrateWeight<Self>;540 type MaxApprovals = MaxApprovals;541}542543impl pallet_sudo::Config for Runtime {544 type Event = Event;545 type Call = Call;546}547548pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);549550impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider551 for RelayChainBlockNumberProvider<T>552{553 type BlockNumber = BlockNumber;554555 fn current_block_number() -> Self::BlockNumber {556 cumulus_pallet_parachain_system::Pallet::<T>::validation_data()557 .map(|d| d.relay_parent_number)558 .unwrap_or_default()559 }560}561562parameter_types! {563 pub const MinVestedTransfer: Balance = 10 * UNIQUE;564 pub const MaxVestingSchedules: u32 = 28;565}566567impl orml_vesting::Config for Runtime {568 type Event = Event;569 type Currency = pallet_balances::Pallet<Runtime>;570 type MinVestedTransfer = MinVestedTransfer;571 type VestedTransferOrigin = EnsureSigned<AccountId>;572 type WeightInfo = ();573 type MaxVestingSchedules = MaxVestingSchedules;574 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;575}576577parameter_types! {578 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;579 pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;580}581582impl cumulus_pallet_parachain_system::Config for Runtime {583 type Event = Event;584 type SelfParaId = parachain_info::Pallet<Self>;585 type OnSystemEvent = ();586 587 588 589 590 591 type OutboundXcmpMessageSource = XcmpQueue;592 type DmpMessageHandler = DmpQueue;593 type ReservedDmpWeight = ReservedDmpWeight;594 type ReservedXcmpWeight = ReservedXcmpWeight;595 type XcmpMessageHandler = XcmpQueue;596}597598impl parachain_info::Config for Runtime {}599600impl cumulus_pallet_aura_ext::Config for Runtime {}601602parameter_types! {603 pub const RelayLocation: MultiLocation = MultiLocation::parent();604 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;605 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();606 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();607}608609610611612pub type LocationToAccountId = (613 614 ParentIsPreset<AccountId>,615 616 SiblingParachainConvertsVia<Sibling, AccountId>,617 618 AccountId32Aliases<RelayNetwork, AccountId>,619);620621pub struct OnlySelfCurrency;622impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {623 fn matches_fungible(a: &MultiAsset) -> Option<B> {624 match (&a.id, &a.fun) {625 (Concrete(_), XcmFungible(ref amount)) => CheckedConversion::checked_from(*amount),626 _ => None,627 }628 }629}630631632pub type LocalAssetTransactor = CurrencyAdapter<633 634 Balances,635 636 OnlySelfCurrency,637 638 LocationToAccountId,639 640 AccountId,641 642 (),643>;644645646647648pub type XcmOriginToTransactDispatchOrigin = (649 650 651 652 SovereignSignedViaLocation<LocationToAccountId, Origin>,653 654 655 RelayChainAsNative<RelayOrigin, Origin>,656 657 658 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,659 660 661 ParentAsSuperuser<Origin>,662 663 664 SignedAccountId32AsNative<RelayNetwork, Origin>,665 666 XcmPassthrough<Origin>,667);668669parameter_types! {670 671 pub UnitWeightCost: Weight = 1_000_000;672 673 pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);674 pub const MaxInstructions: u32 = 100;675 pub const MaxAuthorities: u32 = 100_000;676}677678match_type! {679 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {680 MultiLocation { parents: 1, interior: Here } |681 MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }682 };683}684685pub type Barrier = (686 TakeWeightCredit,687 AllowTopLevelPaidExecutionFrom<Everything>,688 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,689 690);691692pub struct UsingOnlySelfCurrencyComponents<693 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,694 AssetId: Get<MultiLocation>,695 AccountId,696 Currency: CurrencyT<AccountId>,697 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,698>(699 Weight,700 Currency::Balance,701 PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,702);703impl<704 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,705 AssetId: Get<MultiLocation>,706 AccountId,707 Currency: CurrencyT<AccountId>,708 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,709 > WeightTrader710 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>711{712 fn new() -> Self {713 Self(0, Zero::zero(), PhantomData)714 }715716 fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {717 let amount = WeightToFee::calc(&weight);718 let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;719720 721 let option1: xcm::v1::AssetId = Concrete(MultiLocation {722 parents: 1,723 interior: X1(Parachain(ParachainInfo::parachain_id().into())),724 });725 726 let option2: xcm::v1::AssetId = Concrete(MultiLocation {727 parents: 0,728 interior: Here,729 });730731 let required = if payment.fungible.contains_key(&option1) {732 (option1, u128_amount).into()733 } else if payment.fungible.contains_key(&option2) {734 (option2, u128_amount).into()735 } else {736 (Concrete(MultiLocation::default()), u128_amount).into()737 };738739 let unused = payment740 .checked_sub(required)741 .map_err(|_| XcmError::TooExpensive)?;742 self.0 = self.0.saturating_add(weight);743 self.1 = self.1.saturating_add(amount);744 Ok(unused)745 }746747 fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {748 let weight = weight.min(self.0);749 let amount = WeightToFee::calc(&weight);750 self.0 -= weight;751 self.1 = self.1.saturating_sub(amount);752 let amount: u128 = amount.saturated_into();753 if amount > 0 {754 Some((AssetId::get(), amount).into())755 } else {756 None757 }758 }759}760impl<761 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,762 AssetId: Get<MultiLocation>,763 AccountId,764 Currency: CurrencyT<AccountId>,765 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,766 > Drop767 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>768{769 fn drop(&mut self) {770 OnUnbalanced::on_unbalanced(Currency::issue(self.1));771 }772}773774pub struct XcmConfig;775impl Config for XcmConfig {776 type Call = Call;777 type XcmSender = XcmRouter;778 779 type AssetTransactor = LocalAssetTransactor;780 type OriginConverter = XcmOriginToTransactDispatchOrigin;781 type IsReserve = NativeAsset;782 type IsTeleporter = (); 783 type LocationInverter = LocationInverter<Ancestry>;784 type Barrier = Barrier;785 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;786 type Trader = UsingOnlySelfCurrencyComponents<787 IdentityFee<Balance>,788 RelayLocation,789 AccountId,790 Balances,791 (),792 >;793 type ResponseHandler = (); 794 type SubscriptionService = PolkadotXcm;795796 type AssetTrap = PolkadotXcm;797 type AssetClaims = PolkadotXcm;798}799800801802803804805pub type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, RelayNetwork>,);806807808809pub type XcmRouter = (810 811 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,812 813 XcmpQueue,814);815816impl pallet_evm_coder_substrate::Config for Runtime {817 type EthereumTransactionSender = pallet_ethereum::Pallet<Self>;818 type GasWeightMapping = FixedGasWeightMapping;819}820821impl pallet_xcm::Config for Runtime {822 type Event = Event;823 type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;824 type XcmRouter = XcmRouter;825 type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;826 type XcmExecuteFilter = Everything;827 type XcmExecutor = XcmExecutor<XcmConfig>;828 type XcmTeleportFilter = Everything;829 type XcmReserveTransferFilter = Everything;830 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;831 type LocationInverter = LocationInverter<Ancestry>;832 type Origin = Origin;833 type Call = Call;834 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;835 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;836}837838impl cumulus_pallet_xcm::Config for Runtime {839 type Event = Event;840 type XcmExecutor = XcmExecutor<XcmConfig>;841}842843impl cumulus_pallet_xcmp_queue::Config for Runtime {844 type WeightInfo = ();845 type Event = Event;846 type XcmExecutor = XcmExecutor<XcmConfig>;847 type ChannelInfo = ParachainSystem;848 type VersionWrapper = ();849 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;850 type ControllerOrigin = EnsureRoot<AccountId>;851 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;852}853854impl cumulus_pallet_dmp_queue::Config for Runtime {855 type Event = Event;856 type XcmExecutor = XcmExecutor<XcmConfig>;857 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;858}859860impl pallet_aura::Config for Runtime {861 type AuthorityId = AuraId;862 type DisabledValidators = ();863 type MaxAuthorities = MaxAuthorities;864}865866parameter_types! {867 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();868 pub const CollectionCreationPrice: Balance = 2 * UNIQUE;869}870871impl pallet_common::Config for Runtime {872 type Event = Event;873 type Currency = Balances;874 type CollectionCreationPrice = CollectionCreationPrice;875 type TreasuryAccountId = TreasuryAccountId;876}877878impl pallet_fungible::Config for Runtime {879 type WeightInfo = pallet_fungible::weights::SubstrateWeight<Self>;880}881impl pallet_refungible::Config for Runtime {882 type WeightInfo = pallet_refungible::weights::SubstrateWeight<Self>;883}884impl pallet_nonfungible::Config for Runtime {885 type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;886}887888impl pallet_unique::Config for Runtime {889 type Event = Event;890 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;891}892893parameter_types! {894 pub const InflationBlockInterval: BlockNumber = 100; 895}896897898impl pallet_inflation::Config for Runtime {899 type Currency = Balances;900 type TreasuryAccountId = TreasuryAccountId;901 type InflationBlockInterval = InflationBlockInterval;902 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;903}904905906907908909910911type EvmSponsorshipHandler = (912 pallet_unique::UniqueEthSponsorshipHandler<Runtime>,913 pallet_evm_contract_helpers::HelpersContractSponsoring<Runtime>,914);915type SponsorshipHandler = (916 pallet_unique::UniqueSponsorshipHandler<Runtime>,917 918 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,919);920921922923924925926927928929930931932933impl pallet_evm_transaction_payment::Config for Runtime {934 type EvmSponsorshipHandler = EvmSponsorshipHandler;935 type Currency = Balances;936}937938impl pallet_charge_transaction::Config for Runtime {939 type SponsorshipHandler = SponsorshipHandler;940}941942943944945946parameter_types! {947 948 pub const HelpersContractAddress: H160 = H160([949 0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,950 ]);951}952953impl pallet_evm_contract_helpers::Config for Runtime {954 type ContractAddress = HelpersContractAddress;955 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;956 type EvmAddressMapping = pallet_evm::HashedAddressMapping<Self::Hashing>;957 type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;958}959960construct_runtime!(961 pub enum Runtime where962 Block = Block,963 NodeBlock = opaque::Block,964 UncheckedExtrinsic = UncheckedExtrinsic965 {966 ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,967 ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,968969 Aura: pallet_aura::{Pallet, Config<T>} = 22,970 AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23,971972 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,973 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,974 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,975 TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 33,976 Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,977 Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,978 System: frame_system::{Pallet, Call, Storage, Config, Event<T>} = 36,979 Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,980 981 982983 984 XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,985 PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,986 CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,987 DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,988989 990 Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,991 Unique: pallet_unique::{Pallet, Call, Storage, Event<T>} = 61,992 993 994 Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64,995 996 Common: pallet_common::{Pallet, Storage, Event<T>} = 66,997 Fungible: pallet_fungible::{Pallet, Storage} = 67,998 Refungible: pallet_refungible::{Pallet, Storage} = 68,999 Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,10001001 1002 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,1003 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,10041005 EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,1006 EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage} = 151,1007 EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,1008 EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,1009 }1010);10111012pub struct TransactionConverter;10131014impl fp_rpc::ConvertTransaction<UncheckedExtrinsic> for TransactionConverter {1015 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic {1016 UncheckedExtrinsic::new_unsigned(1017 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),1018 )1019 }1020}10211022impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConverter {1023 fn convert_transaction(1024 &self,1025 transaction: pallet_ethereum::Transaction,1026 ) -> opaque::UncheckedExtrinsic {1027 let extrinsic = UncheckedExtrinsic::new_unsigned(1028 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),1029 );1030 let encoded = extrinsic.encode();1031 opaque::UncheckedExtrinsic::decode(&mut &encoded[..])1032 .expect("Encoded extrinsic is always valid")1033 }1034}103510361037pub type Address = sp_runtime::MultiAddress<AccountId, ()>;10381039pub type Header = generic::Header<BlockNumber, BlakeTwo256>;10401041pub type Block = generic::Block<Header, UncheckedExtrinsic>;10421043pub type SignedBlock = generic::SignedBlock<Block>;10441045pub type BlockId = generic::BlockId<Block>;10461047pub type SignedExtra = (1048 frame_system::CheckSpecVersion<Runtime>,1049 1050 frame_system::CheckGenesis<Runtime>,1051 frame_system::CheckEra<Runtime>,1052 frame_system::CheckNonce<Runtime>,1053 frame_system::CheckWeight<Runtime>,1054 pallet_charge_transaction::ChargeTransactionPayment<Runtime>,1055 1056);10571058pub type UncheckedExtrinsic =1059 fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;10601061pub type CheckedExtrinsic = fp_self_contained::CheckedExtrinsic<AccountId, Call, SignedExtra, H160>;10621063pub type Executive = frame_executive::Executive<1064 Runtime,1065 Block,1066 frame_system::ChainContext<Runtime>,1067 Runtime,1068 AllPalletsReversedWithSystemFirst,1069>;10701071impl_opaque_keys! {1072 pub struct SessionKeys {1073 pub aura: Aura,1074 }1075}10761077impl fp_self_contained::SelfContainedCall for Call {1078 type SignedInfo = H160;10791080 fn is_self_contained(&self) -> bool {1081 match self {1082 Call::Ethereum(call) => call.is_self_contained(),1083 _ => false,1084 }1085 }10861087 fn check_self_contained(&self) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {1088 match self {1089 Call::Ethereum(call) => call.check_self_contained(),1090 _ => None,1091 }1092 }10931094 fn validate_self_contained(&self, info: &Self::SignedInfo) -> Option<TransactionValidity> {1095 match self {1096 Call::Ethereum(call) => call.validate_self_contained(info),1097 _ => None,1098 }1099 }11001101 fn pre_dispatch_self_contained(1102 &self,1103 info: &Self::SignedInfo,1104 ) -> Option<Result<(), TransactionValidityError>> {1105 match self {1106 Call::Ethereum(call) => call.pre_dispatch_self_contained(info),1107 _ => None,1108 }1109 }11101111 fn apply_self_contained(1112 self,1113 info: Self::SignedInfo,1114 ) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {1115 match self {1116 call @ Call::Ethereum(pallet_ethereum::Call::transact { .. }) => Some(call.dispatch(1117 Origin::from(pallet_ethereum::RawOrigin::EthereumTransaction(info)),1118 )),1119 _ => None,1120 }1121 }1122}11231124macro_rules! dispatch_unique_runtime {1125 ($collection:ident.$method:ident($($name:ident),*)) => {{1126 use pallet_unique::dispatch::Dispatched;11271128 let collection = Dispatched::dispatch(<pallet_common::CollectionHandle<Runtime>>::try_get($collection)?);1129 let dispatch = collection.as_dyn();11301131 Ok(dispatch.$method($($name),*))1132 }};1133}11341135impl_common_runtime_apis!();11361137struct CheckInherents;11381139impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {1140 fn check_inherents(1141 block: &Block,1142 relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,1143 ) -> sp_inherents::CheckInherentsResult {1144 let relay_chain_slot = relay_state_proof1145 .read_slot()1146 .expect("Could not read the relay chain slot from the proof");11471148 let inherent_data =1149 cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(1150 relay_chain_slot,1151 sp_std::time::Duration::from_secs(6),1152 )1153 .create_inherent_data()1154 .expect("Could not create the timestamp inherent data");11551156 inherent_data.check_extrinsics(block)1157 }1158}11591160cumulus_pallet_parachain_system::register_validate_block!(1161 Runtime = Runtime,1162 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,1163 CheckInherents = CheckInherents,1164);