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";118119pub type CrossAccountId = pallet_common::account::BasicCrossAccountId<Runtime>;120121122123124125pub mod opaque {126 use sp_std::prelude::*;127 use sp_runtime::impl_opaque_keys;128 use super::Aura;129130 pub use unique_runtime_common::types::*;131 pub use super::CrossAccountId;132133 impl_opaque_keys! {134 pub struct SessionKeys {135 pub aura: Aura,136 }137 }138}139140141pub const VERSION: RuntimeVersion = RuntimeVersion {142 spec_name: create_runtime_str!(RUNTIME_NAME),143 impl_name: create_runtime_str!(RUNTIME_NAME),144 authoring_version: 1,145 spec_version: 917004,146 impl_version: 0,147 apis: RUNTIME_API_VERSIONS,148 transaction_version: 1,149 state_version: 0,150};151152#[derive(codec::Encode, codec::Decode)]153pub enum XCMPMessage<XAccountId, XBalance> {154 155 TransferToken(XAccountId, XBalance),156}157158159#[cfg(feature = "std")]160pub fn native_version() -> NativeVersion {161 NativeVersion {162 runtime_version: VERSION,163 can_author_with: Default::default(),164 }165}166167type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;168169pub struct DealWithFees;170impl OnUnbalanced<NegativeImbalance> for DealWithFees {171 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {172 if let Some(fees) = fees_then_tips.next() {173 174 let mut split = fees.ration(100, 0);175 if let Some(tips) = fees_then_tips.next() {176 177 tips.ration_merge_into(100, 0, &mut split);178 }179 Treasury::on_unbalanced(split.0);180 181 }182 }183}184185parameter_types! {186 pub const BlockHashCount: BlockNumber = 2400;187 pub RuntimeBlockLength: BlockLength =188 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);189 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);190 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;191 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()192 .base_block(BlockExecutionWeight::get())193 .for_class(DispatchClass::all(), |weights| {194 weights.base_extrinsic = ExtrinsicBaseWeight::get();195 })196 .for_class(DispatchClass::Normal, |weights| {197 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);198 })199 .for_class(DispatchClass::Operational, |weights| {200 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);201 202 203 weights.reserved = Some(204 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT205 );206 })207 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)208 .build_or_panic();209 pub const Version: RuntimeVersion = VERSION;210 pub const SS58Prefix: u8 = 42;211}212213214215216217218parameter_types! {219 pub const ChainId: u64 = 8882;220}221222pub struct FixedFee;223impl FeeCalculator for FixedFee {224 fn min_gas_price() -> U256 {225 226 1_018_751_825_264u64.into()227 }228}229230231232233parameter_types! {234 pub const WritesPerSecond: u64 = WEIGHT_PER_SECOND / <Runtime as frame_system::Config>::DbWeight::get().write;235 pub const GasPerSecond: u64 = WritesPerSecond::get() * 20000;236 pub const WeightPerGas: u64 = WEIGHT_PER_SECOND / GasPerSecond::get();237}238239240241242const EVM_DISPATCH_RATIO: Perbill = Perbill::from_percent(50);243parameter_types! {244 pub BlockGasLimit: U256 = U256::from(NORMAL_DISPATCH_RATIO * EVM_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT / WeightPerGas::get());245}246247pub enum FixedGasWeightMapping {}248impl GasWeightMapping for FixedGasWeightMapping {249 fn gas_to_weight(gas: u64) -> Weight {250 gas.saturating_mul(WeightPerGas::get())251 }252 fn weight_to_gas(weight: Weight) -> u64 {253 weight / WeightPerGas::get()254 }255}256257impl pallet_evm::Config for Runtime {258 type BlockGasLimit = BlockGasLimit;259 type FeeCalculator = FixedFee;260 type GasWeightMapping = FixedGasWeightMapping;261 type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;262 type CallOrigin = EnsureAddressTruncated;263 type WithdrawOrigin = EnsureAddressTruncated;264 type AddressMapping = HashedAddressMapping<Self::Hashing>;265 type PrecompilesType = ();266 type PrecompilesValue = ();267 type Currency = Balances;268 type Event = Event;269 type OnMethodCall = (270 pallet_evm_migration::OnMethodCall<Self>,271 pallet_unique::UniqueErcSupport<Self>,272 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,273 );274 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;275 type ChainId = ChainId;276 type Runner = pallet_evm::runner::stack::Runner<Self>;277 type OnChargeTransaction = pallet_evm_transaction_payment::OnChargeTransaction<Self>;278 type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;279 type FindAuthor = EthereumFindAuthor<Aura>;280}281282impl pallet_evm_migration::Config for Runtime {283 type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;284}285286pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);287impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {288 fn find_author<'a, I>(digests: I) -> Option<H160>289 where290 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,291 {292 if let Some(author_index) = F::find_author(digests) {293 let authority_id = Aura::authorities()[author_index as usize].clone();294 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));295 }296 None297 }298}299300impl pallet_ethereum::Config for Runtime {301 type Event = Event;302 type StateRoot = pallet_ethereum::IntermediateStateRoot;303}304305impl pallet_randomness_collective_flip::Config for Runtime {}306307impl frame_system::Config for Runtime {308 309 type AccountData = pallet_balances::AccountData<Balance>;310 311 type AccountId = AccountId;312 313 type BaseCallFilter = Everything;314 315 type BlockHashCount = BlockHashCount;316 317 type BlockLength = RuntimeBlockLength;318 319 type BlockNumber = BlockNumber;320 321 type BlockWeights = RuntimeBlockWeights;322 323 type Call = Call;324 325 type DbWeight = RocksDbWeight;326 327 type Event = Event;328 329 type Hash = Hash;330 331 type Hashing = BlakeTwo256;332 333 type Header = generic::Header<BlockNumber, BlakeTwo256>;334 335 type Index = Index;336 337 type Lookup = AccountIdLookup<AccountId, ()>;338 339 type OnKilledAccount = ();340 341 type OnNewAccount = ();342 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;343 344 type Origin = Origin;345 346 type PalletInfo = PalletInfo;347 348 type SS58Prefix = SS58Prefix;349 350 type SystemWeightInfo = frame_system::weights::SubstrateWeight<Self>;351 352 type Version = Version;353 type MaxConsumers = ConstU32<16>;354}355356parameter_types! {357 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;358}359360impl pallet_timestamp::Config for Runtime {361 362 type Moment = u64;363 type OnTimestampSet = ();364 type MinimumPeriod = MinimumPeriod;365 type WeightInfo = ();366}367368parameter_types! {369 370 pub const ExistentialDeposit: u128 = 0;371 pub const MaxLocks: u32 = 50;372}373374impl pallet_balances::Config for Runtime {375 type MaxLocks = MaxLocks;376 type MaxReserves = ();377 type ReserveIdentifier = [u8; 8];378 379 type Balance = Balance;380 381 type Event = Event;382 type DustRemoval = Treasury;383 type ExistentialDeposit = ExistentialDeposit;384 type AccountStore = System;385 type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;386}387388pub const MICROUNIQUE: Balance = 1_000_000_000_000;389pub const MILLIUNIQUE: Balance = 1_000 * MICROUNIQUE;390pub const CENTIUNIQUE: Balance = 10 * MILLIUNIQUE;391pub const UNIQUE: Balance = 100 * CENTIUNIQUE;392393pub const fn deposit(items: u32, bytes: u32) -> Balance {394 items as Balance * 15 * CENTIUNIQUE + (bytes as Balance) * 6 * CENTIUNIQUE395}396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447parameter_types! {448 pub const TransactionByteFee: Balance = 501 * MICROUNIQUE; 449 450 451 pub const OperationalFeeMultiplier: u8 = 5;452}453454455pub struct LinearFee<T>(sp_std::marker::PhantomData<T>);456457impl<T> WeightToFeePolynomial for LinearFee<T>458where459 T: BaseArithmetic + From<u32> + Copy + Unsigned,460{461 type Balance = T;462463 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {464 smallvec!(WeightToFeeCoefficient {465 466 coeff_integer: 142_688_000u32.into(),467 coeff_frac: Perbill::zero(),468 negative: false,469 degree: 1,470 })471 }472}473474impl pallet_transaction_payment::Config for Runtime {475 type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;476 type TransactionByteFee = TransactionByteFee;477 type OperationalFeeMultiplier = OperationalFeeMultiplier;478 type WeightToFee = LinearFee<Balance>;479 type FeeMultiplierUpdate = ();480}481482parameter_types! {483 pub const ProposalBond: Permill = Permill::from_percent(5);484 pub const ProposalBondMinimum: Balance = 1 * UNIQUE;485 pub const ProposalBondMaximum: Balance = 1000 * UNIQUE;486 pub const SpendPeriod: BlockNumber = 5 * MINUTES;487 pub const Burn: Permill = Permill::from_percent(0);488 pub const TipCountdown: BlockNumber = 1 * DAYS;489 pub const TipFindersFee: Percent = Percent::from_percent(20);490 pub const TipReportDepositBase: Balance = 1 * UNIQUE;491 pub const DataDepositPerByte: Balance = 1 * CENTIUNIQUE;492 pub const BountyDepositBase: Balance = 1 * UNIQUE;493 pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;494 pub const TreasuryModuleId: PalletId = PalletId(*b"py/trsry");495 pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;496 pub const MaximumReasonLength: u32 = 16384;497 pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);498 pub const BountyValueMinimum: Balance = 5 * UNIQUE;499 pub const MaxApprovals: u32 = 100;500}501502impl pallet_treasury::Config for Runtime {503 type PalletId = TreasuryModuleId;504 type Currency = Balances;505 type ApproveOrigin = EnsureRoot<AccountId>;506 type RejectOrigin = EnsureRoot<AccountId>;507 type Event = Event;508 type OnSlash = ();509 type ProposalBond = ProposalBond;510 type ProposalBondMinimum = ProposalBondMinimum;511 type ProposalBondMaximum = ProposalBondMaximum;512 type SpendPeriod = SpendPeriod;513 type Burn = Burn;514 type BurnDestination = ();515 type SpendFunds = ();516 type WeightInfo = pallet_treasury::weights::SubstrateWeight<Self>;517 type MaxApprovals = MaxApprovals;518}519520impl pallet_sudo::Config for Runtime {521 type Event = Event;522 type Call = Call;523}524525pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);526527impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider528 for RelayChainBlockNumberProvider<T>529{530 type BlockNumber = BlockNumber;531532 fn current_block_number() -> Self::BlockNumber {533 cumulus_pallet_parachain_system::Pallet::<T>::validation_data()534 .map(|d| d.relay_parent_number)535 .unwrap_or_default()536 }537}538539parameter_types! {540 pub const MinVestedTransfer: Balance = 10 * UNIQUE;541 pub const MaxVestingSchedules: u32 = 28;542}543544impl orml_vesting::Config for Runtime {545 type Event = Event;546 type Currency = pallet_balances::Pallet<Runtime>;547 type MinVestedTransfer = MinVestedTransfer;548 type VestedTransferOrigin = EnsureSigned<AccountId>;549 type WeightInfo = ();550 type MaxVestingSchedules = MaxVestingSchedules;551 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;552}553554parameter_types! {555 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;556 pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;557}558559impl cumulus_pallet_parachain_system::Config for Runtime {560 type Event = Event;561 type SelfParaId = parachain_info::Pallet<Self>;562 type OnSystemEvent = ();563 564 565 566 567 568 type OutboundXcmpMessageSource = XcmpQueue;569 type DmpMessageHandler = DmpQueue;570 type ReservedDmpWeight = ReservedDmpWeight;571 type ReservedXcmpWeight = ReservedXcmpWeight;572 type XcmpMessageHandler = XcmpQueue;573}574575impl parachain_info::Config for Runtime {}576577impl cumulus_pallet_aura_ext::Config for Runtime {}578579parameter_types! {580 pub const RelayLocation: MultiLocation = MultiLocation::parent();581 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;582 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();583 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();584}585586587588589pub type LocationToAccountId = (590 591 ParentIsPreset<AccountId>,592 593 SiblingParachainConvertsVia<Sibling, AccountId>,594 595 AccountId32Aliases<RelayNetwork, AccountId>,596);597598pub struct OnlySelfCurrency;599impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {600 fn matches_fungible(a: &MultiAsset) -> Option<B> {601 match (&a.id, &a.fun) {602 (Concrete(_), XcmFungible(ref amount)) => CheckedConversion::checked_from(*amount),603 _ => None,604 }605 }606}607608609pub type LocalAssetTransactor = CurrencyAdapter<610 611 Balances,612 613 OnlySelfCurrency,614 615 LocationToAccountId,616 617 AccountId,618 619 (),620>;621622623624625pub type XcmOriginToTransactDispatchOrigin = (626 627 628 629 SovereignSignedViaLocation<LocationToAccountId, Origin>,630 631 632 RelayChainAsNative<RelayOrigin, Origin>,633 634 635 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,636 637 638 ParentAsSuperuser<Origin>,639 640 641 SignedAccountId32AsNative<RelayNetwork, Origin>,642 643 XcmPassthrough<Origin>,644);645646parameter_types! {647 648 pub UnitWeightCost: Weight = 1_000_000;649 650 pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);651 pub const MaxInstructions: u32 = 100;652 pub const MaxAuthorities: u32 = 100_000;653}654655match_type! {656 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {657 MultiLocation { parents: 1, interior: Here } |658 MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }659 };660}661662pub type Barrier = (663 TakeWeightCredit,664 AllowTopLevelPaidExecutionFrom<Everything>,665 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,666 667);668669pub struct UsingOnlySelfCurrencyComponents<670 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,671 AssetId: Get<MultiLocation>,672 AccountId,673 Currency: CurrencyT<AccountId>,674 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,675>(676 Weight,677 Currency::Balance,678 PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,679);680impl<681 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,682 AssetId: Get<MultiLocation>,683 AccountId,684 Currency: CurrencyT<AccountId>,685 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,686 > WeightTrader687 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>688{689 fn new() -> Self {690 Self(0, Zero::zero(), PhantomData)691 }692693 fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {694 let amount = WeightToFee::calc(&weight);695 let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;696697 698 let option1: xcm::v1::AssetId = Concrete(MultiLocation {699 parents: 1,700 interior: X1(Parachain(ParachainInfo::parachain_id().into())),701 });702 703 let option2: xcm::v1::AssetId = Concrete(MultiLocation {704 parents: 0,705 interior: Here,706 });707708 let required = if payment.fungible.contains_key(&option1) {709 (option1, u128_amount).into()710 } else if payment.fungible.contains_key(&option2) {711 (option2, u128_amount).into()712 } else {713 (Concrete(MultiLocation::default()), u128_amount).into()714 };715716 let unused = payment717 .checked_sub(required)718 .map_err(|_| XcmError::TooExpensive)?;719 self.0 = self.0.saturating_add(weight);720 self.1 = self.1.saturating_add(amount);721 Ok(unused)722 }723724 fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {725 let weight = weight.min(self.0);726 let amount = WeightToFee::calc(&weight);727 self.0 -= weight;728 self.1 = self.1.saturating_sub(amount);729 let amount: u128 = amount.saturated_into();730 if amount > 0 {731 Some((AssetId::get(), amount).into())732 } else {733 None734 }735 }736}737impl<738 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,739 AssetId: Get<MultiLocation>,740 AccountId,741 Currency: CurrencyT<AccountId>,742 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,743 > Drop744 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>745{746 fn drop(&mut self) {747 OnUnbalanced::on_unbalanced(Currency::issue(self.1));748 }749}750751pub struct XcmConfig;752impl Config for XcmConfig {753 type Call = Call;754 type XcmSender = XcmRouter;755 756 type AssetTransactor = LocalAssetTransactor;757 type OriginConverter = XcmOriginToTransactDispatchOrigin;758 type IsReserve = NativeAsset;759 type IsTeleporter = (); 760 type LocationInverter = LocationInverter<Ancestry>;761 type Barrier = Barrier;762 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;763 type Trader = UsingOnlySelfCurrencyComponents<764 IdentityFee<Balance>,765 RelayLocation,766 AccountId,767 Balances,768 (),769 >;770 type ResponseHandler = (); 771 type SubscriptionService = PolkadotXcm;772773 type AssetTrap = PolkadotXcm;774 type AssetClaims = PolkadotXcm;775}776777778779780781782pub type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, RelayNetwork>,);783784785786pub type XcmRouter = (787 788 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,789 790 XcmpQueue,791);792793impl pallet_evm_coder_substrate::Config for Runtime {794 type EthereumTransactionSender = pallet_ethereum::Pallet<Self>;795 type GasWeightMapping = FixedGasWeightMapping;796}797798impl pallet_xcm::Config for Runtime {799 type Event = Event;800 type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;801 type XcmRouter = XcmRouter;802 type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;803 type XcmExecuteFilter = Everything;804 type XcmExecutor = XcmExecutor<XcmConfig>;805 type XcmTeleportFilter = Everything;806 type XcmReserveTransferFilter = Everything;807 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;808 type LocationInverter = LocationInverter<Ancestry>;809 type Origin = Origin;810 type Call = Call;811 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;812 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;813}814815impl cumulus_pallet_xcm::Config for Runtime {816 type Event = Event;817 type XcmExecutor = XcmExecutor<XcmConfig>;818}819820impl cumulus_pallet_xcmp_queue::Config for Runtime {821 type Event = Event;822 type XcmExecutor = XcmExecutor<XcmConfig>;823 type ChannelInfo = ParachainSystem;824 type VersionWrapper = ();825 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;826 type ControllerOrigin = EnsureRoot<AccountId>;827 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;828}829830impl cumulus_pallet_dmp_queue::Config for Runtime {831 type Event = Event;832 type XcmExecutor = XcmExecutor<XcmConfig>;833 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;834}835836impl pallet_aura::Config for Runtime {837 type AuthorityId = AuraId;838 type DisabledValidators = ();839 type MaxAuthorities = MaxAuthorities;840}841842parameter_types! {843 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();844 pub const CollectionCreationPrice: Balance = 2 * UNIQUE;845}846847impl pallet_common::Config for Runtime {848 type Event = Event;849 type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;850 type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;851 type CrossAccountId = pallet_common::account::BasicCrossAccountId<Self>;852853 type Currency = Balances;854 type CollectionCreationPrice = CollectionCreationPrice;855 type TreasuryAccountId = TreasuryAccountId;856}857858impl pallet_fungible::Config for Runtime {859 type WeightInfo = pallet_fungible::weights::SubstrateWeight<Self>;860}861impl pallet_refungible::Config for Runtime {862 type WeightInfo = pallet_refungible::weights::SubstrateWeight<Self>;863}864impl pallet_nonfungible::Config for Runtime {865 type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;866}867868impl pallet_unique::Config for Runtime {869 type Event = Event;870 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;871}872873parameter_types! {874 pub const InflationBlockInterval: BlockNumber = 100; 875}876877878impl pallet_inflation::Config for Runtime {879 type Currency = Balances;880 type TreasuryAccountId = TreasuryAccountId;881 type InflationBlockInterval = InflationBlockInterval;882 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;883}884885886887888889890891type EvmSponsorshipHandler = (892 pallet_unique::UniqueEthSponsorshipHandler<Runtime>,893 pallet_evm_contract_helpers::HelpersContractSponsoring<Runtime>,894);895type SponsorshipHandler = (896 pallet_unique::UniqueSponsorshipHandler<Runtime>,897 898 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,899);900901902903904905906907908909910911912913impl pallet_evm_transaction_payment::Config for Runtime {914 type EvmSponsorshipHandler = EvmSponsorshipHandler;915 type Currency = Balances;916 type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;917 type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;918}919920impl pallet_charge_transaction::Config for Runtime {921 type SponsorshipHandler = SponsorshipHandler;922}923924925926927928parameter_types! {929 930 pub const HelpersContractAddress: H160 = H160([931 0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,932 ]);933}934935impl pallet_evm_contract_helpers::Config for Runtime {936 type ContractAddress = HelpersContractAddress;937 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;938}939940construct_runtime!(941 pub enum Runtime where942 Block = Block,943 NodeBlock = opaque::Block,944 UncheckedExtrinsic = UncheckedExtrinsic945 {946 ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,947 ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,948949 Aura: pallet_aura::{Pallet, Config<T>} = 22,950 AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23,951952 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,953 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,954 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,955 TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 33,956 Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,957 Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,958 System: frame_system::{Pallet, Call, Storage, Config, Event<T>} = 36,959 Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,960 961 962963 964 XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,965 PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,966 CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,967 DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,968969 970 Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,971 Unique: pallet_unique::{Pallet, Call, Storage, Event<T>} = 61,972 973 974 Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64,975 976 Common: pallet_common::{Pallet, Storage, Event<T>} = 66,977 Fungible: pallet_fungible::{Pallet, Storage} = 67,978 Refungible: pallet_refungible::{Pallet, Storage} = 68,979 Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,980981 982 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,983 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,984985 EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,986 EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage} = 151,987 EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,988 EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,989 }990);991992pub struct TransactionConverter;993994impl fp_rpc::ConvertTransaction<UncheckedExtrinsic> for TransactionConverter {995 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic {996 UncheckedExtrinsic::new_unsigned(997 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),998 )999 }1000}10011002impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConverter {1003 fn convert_transaction(1004 &self,1005 transaction: pallet_ethereum::Transaction,1006 ) -> opaque::UncheckedExtrinsic {1007 let extrinsic = UncheckedExtrinsic::new_unsigned(1008 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),1009 );1010 let encoded = extrinsic.encode();1011 opaque::UncheckedExtrinsic::decode(&mut &encoded[..])1012 .expect("Encoded extrinsic is always valid")1013 }1014}101510161017pub type Address = sp_runtime::MultiAddress<AccountId, ()>;10181019pub type Header = generic::Header<BlockNumber, BlakeTwo256>;10201021pub type Block = generic::Block<Header, UncheckedExtrinsic>;10221023pub type SignedBlock = generic::SignedBlock<Block>;10241025pub type BlockId = generic::BlockId<Block>;10261027pub type SignedExtra = (1028 frame_system::CheckSpecVersion<Runtime>,1029 1030 frame_system::CheckGenesis<Runtime>,1031 frame_system::CheckEra<Runtime>,1032 frame_system::CheckNonce<Runtime>,1033 frame_system::CheckWeight<Runtime>,1034 pallet_charge_transaction::ChargeTransactionPayment<Runtime>,1035 1036);10371038pub type UncheckedExtrinsic =1039 fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;10401041pub type CheckedExtrinsic = fp_self_contained::CheckedExtrinsic<AccountId, Call, SignedExtra, H160>;10421043pub type Executive = frame_executive::Executive<1044 Runtime,1045 Block,1046 frame_system::ChainContext<Runtime>,1047 Runtime,1048 AllPalletsReversedWithSystemFirst,1049>;10501051impl_opaque_keys! {1052 pub struct SessionKeys {1053 pub aura: Aura,1054 }1055}10561057impl fp_self_contained::SelfContainedCall for Call {1058 type SignedInfo = H160;10591060 fn is_self_contained(&self) -> bool {1061 match self {1062 Call::Ethereum(call) => call.is_self_contained(),1063 _ => false,1064 }1065 }10661067 fn check_self_contained(&self) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {1068 match self {1069 Call::Ethereum(call) => call.check_self_contained(),1070 _ => None,1071 }1072 }10731074 fn validate_self_contained(&self, info: &Self::SignedInfo) -> Option<TransactionValidity> {1075 match self {1076 Call::Ethereum(call) => call.validate_self_contained(info),1077 _ => None,1078 }1079 }10801081 fn pre_dispatch_self_contained(1082 &self,1083 info: &Self::SignedInfo,1084 ) -> Option<Result<(), TransactionValidityError>> {1085 match self {1086 Call::Ethereum(call) => call.pre_dispatch_self_contained(info),1087 _ => None,1088 }1089 }10901091 fn apply_self_contained(1092 self,1093 info: Self::SignedInfo,1094 ) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {1095 match self {1096 call @ Call::Ethereum(pallet_ethereum::Call::transact { .. }) => Some(call.dispatch(1097 Origin::from(pallet_ethereum::RawOrigin::EthereumTransaction(info)),1098 )),1099 _ => None,1100 }1101 }1102}11031104macro_rules! dispatch_unique_runtime {1105 ($collection:ident.$method:ident($($name:ident),*)) => {{1106 use pallet_unique::dispatch::Dispatched;11071108 let collection = Dispatched::dispatch(<pallet_common::CollectionHandle<Runtime>>::try_get($collection)?);1109 let dispatch = collection.as_dyn();11101111 Ok(dispatch.$method($($name),*))1112 }};1113}11141115impl_common_runtime_apis!();11161117struct CheckInherents;11181119impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {1120 fn check_inherents(1121 block: &Block,1122 relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,1123 ) -> sp_inherents::CheckInherentsResult {1124 let relay_chain_slot = relay_state_proof1125 .read_slot()1126 .expect("Could not read the relay chain slot from the proof");11271128 let inherent_data =1129 cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(1130 relay_chain_slot,1131 sp_std::time::Duration::from_secs(6),1132 )1133 .create_inherent_data()1134 .expect("Could not create the timestamp inherent data");11351136 inherent_data.check_extrinsics(block)1137 }1138}11391140cumulus_pallet_parachain_system::register_validate_block!(1141 Runtime = Runtime,1142 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,1143 CheckInherents = CheckInherents,1144);