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 _, OnMethodCall,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::mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping};70use up_data_structs::*;717273use frame_system::{74 self as frame_system, EnsureRoot, EnsureSigned,75 limits::{BlockWeights, BlockLength},76};77use sp_arithmetic::{78 traits::{BaseArithmetic, Unsigned},79};80use smallvec::smallvec;81use codec::{Encode, Decode};82use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping, OnMethodCall};83use fp_rpc::TransactionStatus;84use sp_runtime::{85 traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating},86 transaction_validity::TransactionValidityError,87 SaturatedConversion,88};899091pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;929394use pallet_xcm::XcmPassthrough;95use polkadot_parachain::primitives::Sibling;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 = "opal";129pub const TOKEN_SYMBOL: &str = "OPL";130131type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;132133impl RuntimeInstance for Runtime {134 type CrossAccountId = self::CrossAccountId;135 type TransactionConverter = self::TransactionConverter;136137 fn get_transaction_converter() -> TransactionConverter {138 TransactionConverter139 }140}141142143144pub type AccountIndex = u32;145146147pub type Balance = u128;148149150pub type Index = u32;151152153pub type Hash = sp_core::H256;154155156pub type DigestItem = generic::DigestItem;157158159160161162pub mod opaque {163 use sp_std::prelude::*;164 use sp_runtime::impl_opaque_keys;165 use super::Aura;166167 pub use unique_runtime_common::types::*;168169 impl_opaque_keys! {170 pub struct SessionKeys {171 pub aura: Aura,172 }173 }174}175176177pub const VERSION: RuntimeVersion = RuntimeVersion {178 spec_name: create_runtime_str!(RUNTIME_NAME),179 impl_name: create_runtime_str!(RUNTIME_NAME),180 authoring_version: 1,181 spec_version: 920000,182 impl_version: 0,183 apis: RUNTIME_API_VERSIONS,184 transaction_version: 1,185 state_version: 0,186};187188#[derive(codec::Encode, codec::Decode)]189pub enum XCMPMessage<XAccountId, XBalance> {190 191 TransferToken(XAccountId, XBalance),192}193194195#[cfg(feature = "std")]196pub fn native_version() -> NativeVersion {197 NativeVersion {198 runtime_version: VERSION,199 can_author_with: Default::default(),200 }201}202203type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;204205pub struct DealWithFees;206impl OnUnbalanced<NegativeImbalance> for DealWithFees {207 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {208 if let Some(fees) = fees_then_tips.next() {209 210 let mut split = fees.ration(100, 0);211 if let Some(tips) = fees_then_tips.next() {212 213 tips.ration_merge_into(100, 0, &mut split);214 }215 Treasury::on_unbalanced(split.0);216 217 }218 }219}220221parameter_types! {222 pub const BlockHashCount: BlockNumber = 2400;223 pub RuntimeBlockLength: BlockLength =224 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);225 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);226 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;227 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()228 .base_block(BlockExecutionWeight::get())229 .for_class(DispatchClass::all(), |weights| {230 weights.base_extrinsic = ExtrinsicBaseWeight::get();231 })232 .for_class(DispatchClass::Normal, |weights| {233 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);234 })235 .for_class(DispatchClass::Operational, |weights| {236 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);237 238 239 weights.reserved = Some(240 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT241 );242 })243 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)244 .build_or_panic();245 pub const Version: RuntimeVersion = VERSION;246 pub const SS58Prefix: u8 = 42;247}248249parameter_types! {250 pub const ChainId: u64 = 8882;251}252253pub struct FixedFee;254impl FeeCalculator for FixedFee {255 fn min_gas_price() -> U256 {256 MIN_GAS_PRICE.into()257 }258}259260261262263parameter_types! {264 pub const WritesPerSecond: u64 = WEIGHT_PER_SECOND / <Runtime as frame_system::Config>::DbWeight::get().write;265 pub const GasPerSecond: u64 = WritesPerSecond::get() * 20000;266 pub const WeightPerGas: u64 = WEIGHT_PER_SECOND / GasPerSecond::get();267}268269270271272const EVM_DISPATCH_RATIO: Perbill = Perbill::from_percent(50);273parameter_types! {274 pub BlockGasLimit: U256 = U256::from(NORMAL_DISPATCH_RATIO * EVM_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT / WeightPerGas::get());275}276277pub enum FixedGasWeightMapping {}278impl GasWeightMapping for FixedGasWeightMapping {279 fn gas_to_weight(gas: u64) -> Weight {280 gas.saturating_mul(WeightPerGas::get())281 }282 fn weight_to_gas(weight: Weight) -> u64 {283 weight / WeightPerGas::get()284 }285}286287impl pallet_evm::account::Config for Runtime {288 type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Self>;289 type EvmAddressMapping = pallet_evm::HashedAddressMapping<Self::Hashing>;290 type EvmBackwardsAddressMapping = fp_evm_mapping::MapBackwardsAddressTruncated;291}292293impl pallet_evm::Config for Runtime {294 type BlockGasLimit = BlockGasLimit;295 type FeeCalculator = FixedFee;296 type GasWeightMapping = FixedGasWeightMapping;297 type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;298 type CallOrigin = EnsureAddressTruncated<Self>;299 type WithdrawOrigin = EnsureAddressTruncated<Self>;300 type AddressMapping = HashedAddressMapping<Self::Hashing>;301 type PrecompilesType = ();302 type PrecompilesValue = ();303 type Currency = Balances;304 type Event = Event;305 type OnMethodCall = (306 pallet_evm_migration::OnMethodCall<Self>,307 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,308 CollectionDispatchT<Self>,309 pallet_evm_collection::CollectionOnMethodCall<Self>,310 );311 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;312 type ChainId = ChainId;313 type Runner = pallet_evm::runner::stack::Runner<Self>;314 type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, DealWithFees>;315 type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;316 type FindAuthor = EthereumFindAuthor<Aura>;317}318319impl pallet_evm_migration::Config for Runtime {320 type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;321}322323pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);324impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {325 fn find_author<'a, I>(digests: I) -> Option<H160>326 where327 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,328 {329 if let Some(author_index) = F::find_author(digests) {330 let authority_id = Aura::authorities()[author_index as usize].clone();331 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));332 }333 None334 }335}336337impl pallet_ethereum::Config for Runtime {338 type Event = Event;339 type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;340}341342impl pallet_randomness_collective_flip::Config for Runtime {}343344impl frame_system::Config for Runtime {345 346 type AccountData = pallet_balances::AccountData<Balance>;347 348 type AccountId = AccountId;349 350 type BaseCallFilter = Everything;351 352 type BlockHashCount = BlockHashCount;353 354 type BlockLength = RuntimeBlockLength;355 356 type BlockNumber = BlockNumber;357 358 type BlockWeights = RuntimeBlockWeights;359 360 type Call = Call;361 362 type DbWeight = RocksDbWeight;363 364 type Event = Event;365 366 type Hash = Hash;367 368 type Hashing = BlakeTwo256;369 370 type Header = generic::Header<BlockNumber, BlakeTwo256>;371 372 type Index = Index;373 374 type Lookup = AccountIdLookup<AccountId, ()>;375 376 type OnKilledAccount = ();377 378 type OnNewAccount = ();379 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;380 381 type Origin = Origin;382 383 type PalletInfo = PalletInfo;384 385 type SS58Prefix = SS58Prefix;386 387 type SystemWeightInfo = frame_system::weights::SubstrateWeight<Self>;388 389 type Version = Version;390 type MaxConsumers = ConstU32<16>;391}392393parameter_types! {394 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;395}396397impl pallet_timestamp::Config for Runtime {398 399 type Moment = u64;400 type OnTimestampSet = ();401 type MinimumPeriod = MinimumPeriod;402 type WeightInfo = ();403}404405parameter_types! {406 407 pub const ExistentialDeposit: u128 = 0;408 pub const MaxLocks: u32 = 50;409}410411impl pallet_balances::Config for Runtime {412 type MaxLocks = MaxLocks;413 type MaxReserves = ();414 type ReserveIdentifier = [u8; 8];415 416 type Balance = Balance;417 418 type Event = Event;419 type DustRemoval = Treasury;420 type ExistentialDeposit = ExistentialDeposit;421 type AccountStore = System;422 type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;423}424425pub const fn deposit(items: u32, bytes: u32) -> Balance {426 items as Balance * 15 * CENTIUNIQUE + (bytes as Balance) * 6 * CENTIUNIQUE427}428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479parameter_types! {480 481 482 pub const OperationalFeeMultiplier: u8 = 5;483}484485486pub struct LinearFee<T>(sp_std::marker::PhantomData<T>);487488impl<T> WeightToFeePolynomial for LinearFee<T>489where490 T: BaseArithmetic + From<u32> + Copy + Unsigned,491{492 type Balance = T;493494 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {495 smallvec!(WeightToFeeCoefficient {496 497 coeff_integer: WEIGHT_TO_FEE_COEFF.into(),498 coeff_frac: Perbill::zero(),499 negative: false,500 degree: 1,501 })502 }503}504505impl pallet_transaction_payment::Config for Runtime {506 type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;507 type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;508 type OperationalFeeMultiplier = OperationalFeeMultiplier;509 type WeightToFee = LinearFee<Balance>;510 type FeeMultiplierUpdate = ();511}512513parameter_types! {514 pub const ProposalBond: Permill = Permill::from_percent(5);515 pub const ProposalBondMinimum: Balance = 1 * UNIQUE;516 pub const ProposalBondMaximum: Balance = 1000 * UNIQUE;517 pub const SpendPeriod: BlockNumber = 5 * MINUTES;518 pub const Burn: Permill = Permill::from_percent(0);519 pub const TipCountdown: BlockNumber = 1 * DAYS;520 pub const TipFindersFee: Percent = Percent::from_percent(20);521 pub const TipReportDepositBase: Balance = 1 * UNIQUE;522 pub const DataDepositPerByte: Balance = 1 * CENTIUNIQUE;523 pub const BountyDepositBase: Balance = 1 * UNIQUE;524 pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;525 pub const TreasuryModuleId: PalletId = PalletId(*b"py/trsry");526 pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;527 pub const MaximumReasonLength: u32 = 16384;528 pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);529 pub const BountyValueMinimum: Balance = 5 * UNIQUE;530 pub const MaxApprovals: u32 = 100;531}532533impl pallet_treasury::Config for Runtime {534 type PalletId = TreasuryModuleId;535 type Currency = Balances;536 type ApproveOrigin = EnsureRoot<AccountId>;537 type RejectOrigin = EnsureRoot<AccountId>;538 type Event = Event;539 type OnSlash = ();540 type ProposalBond = ProposalBond;541 type ProposalBondMinimum = ProposalBondMinimum;542 type ProposalBondMaximum = ProposalBondMaximum;543 type SpendPeriod = SpendPeriod;544 type Burn = Burn;545 type BurnDestination = ();546 type SpendFunds = ();547 type WeightInfo = pallet_treasury::weights::SubstrateWeight<Self>;548 type MaxApprovals = MaxApprovals;549}550551impl pallet_sudo::Config for Runtime {552 type Event = Event;553 type Call = Call;554}555556pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);557558impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider559 for RelayChainBlockNumberProvider<T>560{561 type BlockNumber = BlockNumber;562563 fn current_block_number() -> Self::BlockNumber {564 cumulus_pallet_parachain_system::Pallet::<T>::validation_data()565 .map(|d| d.relay_parent_number)566 .unwrap_or_default()567 }568}569570parameter_types! {571 pub const MinVestedTransfer: Balance = 10 * UNIQUE;572 pub const MaxVestingSchedules: u32 = 28;573}574575impl orml_vesting::Config for Runtime {576 type Event = Event;577 type Currency = pallet_balances::Pallet<Runtime>;578 type MinVestedTransfer = MinVestedTransfer;579 type VestedTransferOrigin = EnsureSigned<AccountId>;580 type WeightInfo = ();581 type MaxVestingSchedules = MaxVestingSchedules;582 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;583}584585parameter_types! {586 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;587 pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;588}589590impl cumulus_pallet_parachain_system::Config for Runtime {591 type Event = Event;592 type SelfParaId = parachain_info::Pallet<Self>;593 type OnSystemEvent = ();594 595 596 597 598 599 type OutboundXcmpMessageSource = XcmpQueue;600 type DmpMessageHandler = DmpQueue;601 type ReservedDmpWeight = ReservedDmpWeight;602 type ReservedXcmpWeight = ReservedXcmpWeight;603 type XcmpMessageHandler = XcmpQueue;604}605606impl parachain_info::Config for Runtime {}607608impl cumulus_pallet_aura_ext::Config for Runtime {}609610parameter_types! {611 pub const RelayLocation: MultiLocation = MultiLocation::parent();612 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;613 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();614 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();615}616617618619620pub type LocationToAccountId = (621 622 ParentIsPreset<AccountId>,623 624 SiblingParachainConvertsVia<Sibling, AccountId>,625 626 AccountId32Aliases<RelayNetwork, AccountId>,627);628629pub struct OnlySelfCurrency;630impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {631 fn matches_fungible(a: &MultiAsset) -> Option<B> {632 match (&a.id, &a.fun) {633 (Concrete(_), XcmFungible(ref amount)) => CheckedConversion::checked_from(*amount),634 _ => None,635 }636 }637}638639640pub type LocalAssetTransactor = CurrencyAdapter<641 642 Balances,643 644 OnlySelfCurrency,645 646 LocationToAccountId,647 648 AccountId,649 650 (),651>;652653654655656pub type XcmOriginToTransactDispatchOrigin = (657 658 659 660 SovereignSignedViaLocation<LocationToAccountId, Origin>,661 662 663 RelayChainAsNative<RelayOrigin, Origin>,664 665 666 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,667 668 669 ParentAsSuperuser<Origin>,670 671 672 SignedAccountId32AsNative<RelayNetwork, Origin>,673 674 XcmPassthrough<Origin>,675);676677parameter_types! {678 679 pub UnitWeightCost: Weight = 1_000_000;680 681 pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);682 pub const MaxInstructions: u32 = 100;683 pub const MaxAuthorities: u32 = 100_000;684}685686match_types! {687 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {688 MultiLocation { parents: 1, interior: Here } |689 MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }690 };691}692693pub type Barrier = (694 TakeWeightCredit,695 AllowTopLevelPaidExecutionFrom<Everything>,696 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,697 698);699700pub struct UsingOnlySelfCurrencyComponents<701 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,702 AssetId: Get<MultiLocation>,703 AccountId,704 Currency: CurrencyT<AccountId>,705 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,706>(707 Weight,708 Currency::Balance,709 PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,710);711impl<712 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,713 AssetId: Get<MultiLocation>,714 AccountId,715 Currency: CurrencyT<AccountId>,716 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,717 > WeightTrader718 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>719{720 fn new() -> Self {721 Self(0, Zero::zero(), PhantomData)722 }723724 fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {725 let amount = WeightToFee::calc(&weight);726 let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;727728 729 let option1: xcm::v1::AssetId = Concrete(MultiLocation {730 parents: 1,731 interior: X1(Parachain(ParachainInfo::parachain_id().into())),732 });733 734 let option2: xcm::v1::AssetId = Concrete(MultiLocation {735 parents: 0,736 interior: Here,737 });738739 let required = if payment.fungible.contains_key(&option1) {740 (option1, u128_amount).into()741 } else if payment.fungible.contains_key(&option2) {742 (option2, u128_amount).into()743 } else {744 (Concrete(MultiLocation::default()), u128_amount).into()745 };746747 let unused = payment748 .checked_sub(required)749 .map_err(|_| XcmError::TooExpensive)?;750 self.0 = self.0.saturating_add(weight);751 self.1 = self.1.saturating_add(amount);752 Ok(unused)753 }754755 fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {756 let weight = weight.min(self.0);757 let amount = WeightToFee::calc(&weight);758 self.0 -= weight;759 self.1 = self.1.saturating_sub(amount);760 let amount: u128 = amount.saturated_into();761 if amount > 0 {762 Some((AssetId::get(), amount).into())763 } else {764 None765 }766 }767}768impl<769 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,770 AssetId: Get<MultiLocation>,771 AccountId,772 Currency: CurrencyT<AccountId>,773 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,774 > Drop775 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>776{777 fn drop(&mut self) {778 OnUnbalanced::on_unbalanced(Currency::issue(self.1));779 }780}781782pub struct XcmConfig;783impl Config for XcmConfig {784 type Call = Call;785 type XcmSender = XcmRouter;786 787 type AssetTransactor = LocalAssetTransactor;788 type OriginConverter = XcmOriginToTransactDispatchOrigin;789 type IsReserve = NativeAsset;790 type IsTeleporter = (); 791 type LocationInverter = LocationInverter<Ancestry>;792 type Barrier = Barrier;793 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;794 type Trader = UsingOnlySelfCurrencyComponents<795 IdentityFee<Balance>,796 RelayLocation,797 AccountId,798 Balances,799 (),800 >;801 type ResponseHandler = (); 802 type SubscriptionService = PolkadotXcm;803804 type AssetTrap = PolkadotXcm;805 type AssetClaims = PolkadotXcm;806}807808809810811812813pub type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, RelayNetwork>,);814815816817pub type XcmRouter = (818 819 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,820 821 XcmpQueue,822);823824impl pallet_evm_coder_substrate::Config for Runtime {825 type GasWeightMapping = FixedGasWeightMapping;826}827828impl pallet_xcm::Config for Runtime {829 type Event = Event;830 type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;831 type XcmRouter = XcmRouter;832 type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;833 type XcmExecuteFilter = Everything;834 type XcmExecutor = XcmExecutor<XcmConfig>;835 type XcmTeleportFilter = Everything;836 type XcmReserveTransferFilter = Everything;837 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;838 type LocationInverter = LocationInverter<Ancestry>;839 type Origin = Origin;840 type Call = Call;841 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;842 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;843}844845impl cumulus_pallet_xcm::Config for Runtime {846 type Event = Event;847 type XcmExecutor = XcmExecutor<XcmConfig>;848}849850impl cumulus_pallet_xcmp_queue::Config for Runtime {851 type WeightInfo = ();852 type Event = Event;853 type XcmExecutor = XcmExecutor<XcmConfig>;854 type ChannelInfo = ParachainSystem;855 type VersionWrapper = ();856 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;857 type ControllerOrigin = EnsureRoot<AccountId>;858 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;859}860861impl cumulus_pallet_dmp_queue::Config for Runtime {862 type Event = Event;863 type XcmExecutor = XcmExecutor<XcmConfig>;864 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;865}866867impl pallet_aura::Config for Runtime {868 type AuthorityId = AuraId;869 type DisabledValidators = ();870 type MaxAuthorities = MaxAuthorities;871}872873parameter_types! {874 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();875 pub const CollectionCreationPrice: Balance = 2 * UNIQUE;876}877878impl pallet_common::Config for Runtime {879 type WeightInfo = pallet_common::weights::SubstrateWeight<Self>;880 type Event = Event;881 type Currency = Balances;882 type CollectionCreationPrice = CollectionCreationPrice;883 type TreasuryAccountId = TreasuryAccountId;884 type CollectionDispatch = CollectionDispatchT<Self>;885886 type EvmTokenAddressMapping = EvmTokenAddressMapping;887 type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;888}889890impl pallet_structure::Config for Runtime {891 type Event = Event;892 type Call = Call;893 type WeightInfo = pallet_structure::weights::SubstrateWeight<Self>;894}895896impl pallet_fungible::Config for Runtime {897 type WeightInfo = pallet_fungible::weights::SubstrateWeight<Self>;898}899impl pallet_refungible::Config for Runtime {900 type WeightInfo = pallet_refungible::weights::SubstrateWeight<Self>;901}902impl pallet_nonfungible::Config for Runtime {903 type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;904}905906impl pallet_proxy_rmrk_core::Config for Runtime {907 type Event = Event;908}909910impl pallet_proxy_rmrk_equip::Config for Runtime {911 type Event = Event;912}913914impl pallet_unique::Config for Runtime {915 type Event = Event;916 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;917 type CommonWeightInfo = CommonWeights<Self>;918}919920parameter_types! {921 pub const InflationBlockInterval: BlockNumber = 100; 922}923924925impl pallet_inflation::Config for Runtime {926 type Currency = Balances;927 type TreasuryAccountId = TreasuryAccountId;928 type InflationBlockInterval = InflationBlockInterval;929 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;930}931932933934935936937938type EvmSponsorshipHandler = (939 UniqueEthSponsorshipHandler<Runtime>,940 pallet_evm_contract_helpers::HelpersContractSponsoring<Runtime>,941);942type SponsorshipHandler = (943 UniqueSponsorshipHandler<Runtime>,944 945 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,946);947948949950951952953954955956957958959960impl pallet_evm_transaction_payment::Config for Runtime {961 type EvmSponsorshipHandler = EvmSponsorshipHandler;962 type Currency = Balances;963}964965impl pallet_charge_transaction::Config for Runtime {966 type SponsorshipHandler = SponsorshipHandler;967}968969970971972973parameter_types! {974 975 pub const HelpersContractAddress: H160 = H160([976 0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,977 ]);978979 980 pub const EvmCollectionAddress: H160 = H160([981 0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,982 ]);983}984985impl pallet_evm_contract_helpers::Config for Runtime {986 type ContractAddress = HelpersContractAddress;987 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;988}989990impl pallet_evm_collection::Config for Runtime {991 type ContractAddress = EvmCollectionAddress;992}993994construct_runtime!(995 pub enum Runtime where996 Block = Block,997 NodeBlock = opaque::Block,998 UncheckedExtrinsic = UncheckedExtrinsic999 {1000 ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,1001 ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,10021003 Aura: pallet_aura::{Pallet, Config<T>} = 22,1004 AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23,10051006 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,1007 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,1008 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,1009 TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 33,1010 Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,1011 Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,1012 System: frame_system::{Pallet, Call, Storage, Config, Event<T>} = 36,1013 Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,1014 1015 10161017 1018 XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,1019 PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,1020 CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,1021 DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,10221023 1024 Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,1025 Unique: pallet_unique::{Pallet, Call, Storage, Event<T>} = 61,1026 1027 1028 Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64,1029 1030 Common: pallet_common::{Pallet, Storage, Event<T>} = 66,1031 Fungible: pallet_fungible::{Pallet, Storage} = 67,1032 Refungible: pallet_refungible::{Pallet, Storage} = 68,1033 Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,1034 Structure: pallet_structure::{Pallet, Call, Storage, Event<T>} = 70,1035 RmrkCore: pallet_proxy_rmrk_core::{Pallet, Call, Storage, Event<T>} = 71,1036 RmrkEquip: pallet_proxy_rmrk_equip::{Pallet, Call, Storage, Event<T>} = 72,10371038 1039 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,1040 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,10411042 EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,1043 EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage} = 151,1044 EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,1045 EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,1046 EvmCollection: pallet_evm_collection::{Pallet} = 154,1047 }1048);10491050pub struct TransactionConverter;10511052impl fp_rpc::ConvertTransaction<UncheckedExtrinsic> for TransactionConverter {1053 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic {1054 UncheckedExtrinsic::new_unsigned(1055 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),1056 )1057 }1058}10591060impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConverter {1061 fn convert_transaction(1062 &self,1063 transaction: pallet_ethereum::Transaction,1064 ) -> opaque::UncheckedExtrinsic {1065 let extrinsic = UncheckedExtrinsic::new_unsigned(1066 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),1067 );1068 let encoded = extrinsic.encode();1069 opaque::UncheckedExtrinsic::decode(&mut &encoded[..])1070 .expect("Encoded extrinsic is always valid")1071 }1072}107310741075pub type Address = sp_runtime::MultiAddress<AccountId, ()>;10761077pub type Header = generic::Header<BlockNumber, BlakeTwo256>;10781079pub type Block = generic::Block<Header, UncheckedExtrinsic>;10801081pub type SignedBlock = generic::SignedBlock<Block>;10821083pub type BlockId = generic::BlockId<Block>;10841085pub type SignedExtra = (1086 frame_system::CheckSpecVersion<Runtime>,1087 1088 frame_system::CheckGenesis<Runtime>,1089 frame_system::CheckEra<Runtime>,1090 frame_system::CheckNonce<Runtime>,1091 frame_system::CheckWeight<Runtime>,1092 pallet_charge_transaction::ChargeTransactionPayment<Runtime>,1093 1094 pallet_ethereum::FakeTransactionFinalizer<Runtime>,1095);10961097pub type UncheckedExtrinsic =1098 fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;10991100pub type CheckedExtrinsic = fp_self_contained::CheckedExtrinsic<AccountId, Call, SignedExtra, H160>;11011102pub type Executive = frame_executive::Executive<1103 Runtime,1104 Block,1105 frame_system::ChainContext<Runtime>,1106 Runtime,1107 AllPalletsReversedWithSystemFirst,1108>;11091110impl_opaque_keys! {1111 pub struct SessionKeys {1112 pub aura: Aura,1113 }1114}11151116impl fp_self_contained::SelfContainedCall for Call {1117 type SignedInfo = H160;11181119 fn is_self_contained(&self) -> bool {1120 match self {1121 Call::Ethereum(call) => call.is_self_contained(),1122 _ => false,1123 }1124 }11251126 fn check_self_contained(&self) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {1127 match self {1128 Call::Ethereum(call) => call.check_self_contained(),1129 _ => None,1130 }1131 }11321133 fn validate_self_contained(&self, info: &Self::SignedInfo) -> Option<TransactionValidity> {1134 match self {1135 Call::Ethereum(call) => call.validate_self_contained(info),1136 _ => None,1137 }1138 }11391140 fn pre_dispatch_self_contained(1141 &self,1142 info: &Self::SignedInfo,1143 ) -> Option<Result<(), TransactionValidityError>> {1144 match self {1145 Call::Ethereum(call) => call.pre_dispatch_self_contained(info),1146 _ => None,1147 }1148 }11491150 fn apply_self_contained(1151 self,1152 info: Self::SignedInfo,1153 ) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {1154 match self {1155 call @ Call::Ethereum(pallet_ethereum::Call::transact { .. }) => Some(call.dispatch(1156 Origin::from(pallet_ethereum::RawOrigin::EthereumTransaction(info)),1157 )),1158 _ => None,1159 }1160 }1161}11621163macro_rules! dispatch_unique_runtime {1164 ($collection:ident.$method:ident($($name:ident),*)) => {{1165 let collection = <Runtime as pallet_common::Config>::CollectionDispatch::dispatch(<pallet_common::CollectionHandle<Runtime>>::try_get($collection)?);1166 let dispatch = collection.as_dyn();11671168 Ok::<_, DispatchError>(dispatch.$method($($name),*))1169 }};1170}11711172impl_common_runtime_apis!();11731174struct CheckInherents;11751176impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {1177 fn check_inherents(1178 block: &Block,1179 relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,1180 ) -> sp_inherents::CheckInherentsResult {1181 let relay_chain_slot = relay_state_proof1182 .read_slot()1183 .expect("Could not read the relay chain slot from the proof");11841185 let inherent_data =1186 cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(1187 relay_chain_slot,1188 sp_std::time::Duration::from_secs(6),1189 )1190 .create_inherent_data()1191 .expect("Could not create the timestamp inherent data");11921193 inherent_data.check_extrinsics(block)1194 }1195}11961197cumulus_pallet_parachain_system::register_validate_block!(1198 Runtime = Runtime,1199 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,1200 CheckInherents = CheckInherents,1201);