12345678910111213141516171819#![cfg_attr(not(feature = "std"), no_std)]2021#![recursion_limit = "1024"]22#![allow(clippy::from_over_into, clippy::identity_op)]23#![allow(clippy::fn_to_numeric_cast_with_truncation)]2425#[cfg(feature = "std")]26include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));2728use sp_api::impl_runtime_apis;29use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160};30use sp_runtime::DispatchError;31323334use sp_runtime::{35 Permill, Perbill, Percent, create_runtime_str, generic, impl_opaque_keys,36 traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion, Zero},37 transaction_validity::{TransactionSource, TransactionValidity},38 ApplyExtrinsicResult, RuntimeAppPublic,39};4041use sp_std::prelude::*;4243#[cfg(feature = "std")]44use sp_version::NativeVersion;45use sp_version::RuntimeVersion;46pub use pallet_transaction_payment::{47 Multiplier, TargetedFeeAdjustment, FeeDetails, RuntimeDispatchInfo,48};4950pub use pallet_balances::Call as BalancesCall;51pub use pallet_evm::{52 EnsureAddressTruncated, HashedAddressMapping, Runner, account::CrossAccountId as _,53};54pub use frame_support::{55 construct_runtime, match_types,56 dispatch::DispatchResult,57 PalletId, parameter_types, StorageValue, ConsensusEngineId,58 traits::{59 tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Everything,60 Currency, ExistenceRequirement, Get, IsInVec, KeyOwnerProofSystem, LockIdentifier,61 OnUnbalanced, Randomness, FindAuthor, ConstU32, Imbalance,62 },63 weights::{64 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},65 DispatchClass, DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,66 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, ConstantMultiplier,67 },68};69use up_data_structs::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};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 );310 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;311 type ChainId = ChainId;312 type Runner = pallet_evm::runner::stack::Runner<Self>;313 type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, DealWithFees>;314 type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;315 type FindAuthor = EthereumFindAuthor<Aura>;316}317318impl pallet_evm_migration::Config for Runtime {319 type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;320}321322pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);323impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {324 fn find_author<'a, I>(digests: I) -> Option<H160>325 where326 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,327 {328 if let Some(author_index) = F::find_author(digests) {329 let authority_id = Aura::authorities()[author_index as usize].clone();330 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));331 }332 None333 }334}335336impl pallet_ethereum::Config for Runtime {337 type Event = Event;338 type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;339}340341impl pallet_randomness_collective_flip::Config for Runtime {}342343impl frame_system::Config for Runtime {344 345 type AccountData = pallet_balances::AccountData<Balance>;346 347 type AccountId = AccountId;348 349 type BaseCallFilter = Everything;350 351 type BlockHashCount = BlockHashCount;352 353 type BlockLength = RuntimeBlockLength;354 355 type BlockNumber = BlockNumber;356 357 type BlockWeights = RuntimeBlockWeights;358 359 type Call = Call;360 361 type DbWeight = RocksDbWeight;362 363 type Event = Event;364 365 type Hash = Hash;366 367 type Hashing = BlakeTwo256;368 369 type Header = generic::Header<BlockNumber, BlakeTwo256>;370 371 type Index = Index;372 373 type Lookup = AccountIdLookup<AccountId, ()>;374 375 type OnKilledAccount = ();376 377 type OnNewAccount = ();378 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;379 380 type Origin = Origin;381 382 type PalletInfo = PalletInfo;383 384 type SS58Prefix = SS58Prefix;385 386 type SystemWeightInfo = frame_system::weights::SubstrateWeight<Self>;387 388 type Version = Version;389 type MaxConsumers = ConstU32<16>;390}391392parameter_types! {393 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;394}395396impl pallet_timestamp::Config for Runtime {397 398 type Moment = u64;399 type OnTimestampSet = ();400 type MinimumPeriod = MinimumPeriod;401 type WeightInfo = ();402}403404parameter_types! {405 406 pub const ExistentialDeposit: u128 = 0;407 pub const MaxLocks: u32 = 50;408}409410impl pallet_balances::Config for Runtime {411 type MaxLocks = MaxLocks;412 type MaxReserves = ();413 type ReserveIdentifier = [u8; 8];414 415 type Balance = Balance;416 417 type Event = Event;418 type DustRemoval = Treasury;419 type ExistentialDeposit = ExistentialDeposit;420 type AccountStore = System;421 type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;422}423424pub const fn deposit(items: u32, bytes: u32) -> Balance {425 items as Balance * 15 * CENTIUNIQUE + (bytes as Balance) * 6 * CENTIUNIQUE426}427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478parameter_types! {479 480 481 pub const OperationalFeeMultiplier: u8 = 5;482}483484485pub struct LinearFee<T>(sp_std::marker::PhantomData<T>);486487impl<T> WeightToFeePolynomial for LinearFee<T>488where489 T: BaseArithmetic + From<u32> + Copy + Unsigned,490{491 type Balance = T;492493 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {494 smallvec!(WeightToFeeCoefficient {495 496 coeff_integer: WEIGHT_TO_FEE_COEFF.into(),497 coeff_frac: Perbill::zero(),498 negative: false,499 degree: 1,500 })501 }502}503504impl pallet_transaction_payment::Config for Runtime {505 type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;506 type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;507 type OperationalFeeMultiplier = OperationalFeeMultiplier;508 type WeightToFee = LinearFee<Balance>;509 type FeeMultiplierUpdate = ();510}511512parameter_types! {513 pub const ProposalBond: Permill = Permill::from_percent(5);514 pub const ProposalBondMinimum: Balance = 1 * UNIQUE;515 pub const ProposalBondMaximum: Balance = 1000 * UNIQUE;516 pub const SpendPeriod: BlockNumber = 5 * MINUTES;517 pub const Burn: Permill = Permill::from_percent(0);518 pub const TipCountdown: BlockNumber = 1 * DAYS;519 pub const TipFindersFee: Percent = Percent::from_percent(20);520 pub const TipReportDepositBase: Balance = 1 * UNIQUE;521 pub const DataDepositPerByte: Balance = 1 * CENTIUNIQUE;522 pub const BountyDepositBase: Balance = 1 * UNIQUE;523 pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;524 pub const TreasuryModuleId: PalletId = PalletId(*b"py/trsry");525 pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;526 pub const MaximumReasonLength: u32 = 16384;527 pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);528 pub const BountyValueMinimum: Balance = 5 * UNIQUE;529 pub const MaxApprovals: u32 = 100;530}531532impl pallet_treasury::Config for Runtime {533 type PalletId = TreasuryModuleId;534 type Currency = Balances;535 type ApproveOrigin = EnsureRoot<AccountId>;536 type RejectOrigin = EnsureRoot<AccountId>;537 type Event = Event;538 type OnSlash = ();539 type ProposalBond = ProposalBond;540 type ProposalBondMinimum = ProposalBondMinimum;541 type ProposalBondMaximum = ProposalBondMaximum;542 type SpendPeriod = SpendPeriod;543 type Burn = Burn;544 type BurnDestination = ();545 type SpendFunds = ();546 type WeightInfo = pallet_treasury::weights::SubstrateWeight<Self>;547 type MaxApprovals = MaxApprovals;548}549550impl pallet_sudo::Config for Runtime {551 type Event = Event;552 type Call = Call;553}554555pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);556557impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider558 for RelayChainBlockNumberProvider<T>559{560 type BlockNumber = BlockNumber;561562 fn current_block_number() -> Self::BlockNumber {563 cumulus_pallet_parachain_system::Pallet::<T>::validation_data()564 .map(|d| d.relay_parent_number)565 .unwrap_or_default()566 }567}568569parameter_types! {570 pub const MinVestedTransfer: Balance = 10 * UNIQUE;571 pub const MaxVestingSchedules: u32 = 28;572}573574impl orml_vesting::Config for Runtime {575 type Event = Event;576 type Currency = pallet_balances::Pallet<Runtime>;577 type MinVestedTransfer = MinVestedTransfer;578 type VestedTransferOrigin = EnsureSigned<AccountId>;579 type WeightInfo = ();580 type MaxVestingSchedules = MaxVestingSchedules;581 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;582}583584parameter_types! {585 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;586 pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;587}588589impl cumulus_pallet_parachain_system::Config for Runtime {590 type Event = Event;591 type SelfParaId = parachain_info::Pallet<Self>;592 type OnSystemEvent = ();593 594 595 596 597 598 type OutboundXcmpMessageSource = XcmpQueue;599 type DmpMessageHandler = DmpQueue;600 type ReservedDmpWeight = ReservedDmpWeight;601 type ReservedXcmpWeight = ReservedXcmpWeight;602 type XcmpMessageHandler = XcmpQueue;603}604605impl parachain_info::Config for Runtime {}606607impl cumulus_pallet_aura_ext::Config for Runtime {}608609parameter_types! {610 pub const RelayLocation: MultiLocation = MultiLocation::parent();611 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;612 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();613 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();614}615616617618619pub type LocationToAccountId = (620 621 ParentIsPreset<AccountId>,622 623 SiblingParachainConvertsVia<Sibling, AccountId>,624 625 AccountId32Aliases<RelayNetwork, AccountId>,626);627628pub struct OnlySelfCurrency;629impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {630 fn matches_fungible(a: &MultiAsset) -> Option<B> {631 match (&a.id, &a.fun) {632 (Concrete(_), XcmFungible(ref amount)) => CheckedConversion::checked_from(*amount),633 _ => None,634 }635 }636}637638639pub type LocalAssetTransactor = CurrencyAdapter<640 641 Balances,642 643 OnlySelfCurrency,644 645 LocationToAccountId,646 647 AccountId,648 649 (),650>;651652653654655pub type XcmOriginToTransactDispatchOrigin = (656 657 658 659 SovereignSignedViaLocation<LocationToAccountId, Origin>,660 661 662 RelayChainAsNative<RelayOrigin, Origin>,663 664 665 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,666 667 668 ParentAsSuperuser<Origin>,669 670 671 SignedAccountId32AsNative<RelayNetwork, Origin>,672 673 XcmPassthrough<Origin>,674);675676parameter_types! {677 678 pub UnitWeightCost: Weight = 1_000_000;679 680 pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);681 pub const MaxInstructions: u32 = 100;682 pub const MaxAuthorities: u32 = 100_000;683}684685match_types! {686 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {687 MultiLocation { parents: 1, interior: Here } |688 MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }689 };690}691692pub type Barrier = (693 TakeWeightCredit,694 AllowTopLevelPaidExecutionFrom<Everything>,695 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,696 697);698699pub struct UsingOnlySelfCurrencyComponents<700 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,701 AssetId: Get<MultiLocation>,702 AccountId,703 Currency: CurrencyT<AccountId>,704 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,705>(706 Weight,707 Currency::Balance,708 PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,709);710impl<711 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,712 AssetId: Get<MultiLocation>,713 AccountId,714 Currency: CurrencyT<AccountId>,715 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,716 > WeightTrader717 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>718{719 fn new() -> Self {720 Self(0, Zero::zero(), PhantomData)721 }722723 fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {724 let amount = WeightToFee::calc(&weight);725 let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;726727 728 let option1: xcm::v1::AssetId = Concrete(MultiLocation {729 parents: 1,730 interior: X1(Parachain(ParachainInfo::parachain_id().into())),731 });732 733 let option2: xcm::v1::AssetId = Concrete(MultiLocation {734 parents: 0,735 interior: Here,736 });737738 let required = if payment.fungible.contains_key(&option1) {739 (option1, u128_amount).into()740 } else if payment.fungible.contains_key(&option2) {741 (option2, u128_amount).into()742 } else {743 (Concrete(MultiLocation::default()), u128_amount).into()744 };745746 let unused = payment747 .checked_sub(required)748 .map_err(|_| XcmError::TooExpensive)?;749 self.0 = self.0.saturating_add(weight);750 self.1 = self.1.saturating_add(amount);751 Ok(unused)752 }753754 fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {755 let weight = weight.min(self.0);756 let amount = WeightToFee::calc(&weight);757 self.0 -= weight;758 self.1 = self.1.saturating_sub(amount);759 let amount: u128 = amount.saturated_into();760 if amount > 0 {761 Some((AssetId::get(), amount).into())762 } else {763 None764 }765 }766}767impl<768 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,769 AssetId: Get<MultiLocation>,770 AccountId,771 Currency: CurrencyT<AccountId>,772 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,773 > Drop774 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>775{776 fn drop(&mut self) {777 OnUnbalanced::on_unbalanced(Currency::issue(self.1));778 }779}780781pub struct XcmConfig;782impl Config for XcmConfig {783 type Call = Call;784 type XcmSender = XcmRouter;785 786 type AssetTransactor = LocalAssetTransactor;787 type OriginConverter = XcmOriginToTransactDispatchOrigin;788 type IsReserve = NativeAsset;789 type IsTeleporter = (); 790 type LocationInverter = LocationInverter<Ancestry>;791 type Barrier = Barrier;792 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;793 type Trader = UsingOnlySelfCurrencyComponents<794 IdentityFee<Balance>,795 RelayLocation,796 AccountId,797 Balances,798 (),799 >;800 type ResponseHandler = (); 801 type SubscriptionService = PolkadotXcm;802803 type AssetTrap = PolkadotXcm;804 type AssetClaims = PolkadotXcm;805}806807808809810811812pub type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, RelayNetwork>,);813814815816pub type XcmRouter = (817 818 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,819 820 XcmpQueue,821);822823impl pallet_evm_coder_substrate::Config for Runtime {824 type GasWeightMapping = FixedGasWeightMapping;825}826827impl pallet_xcm::Config for Runtime {828 type Event = Event;829 type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;830 type XcmRouter = XcmRouter;831 type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;832 type XcmExecuteFilter = Everything;833 type XcmExecutor = XcmExecutor<XcmConfig>;834 type XcmTeleportFilter = Everything;835 type XcmReserveTransferFilter = Everything;836 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;837 type LocationInverter = LocationInverter<Ancestry>;838 type Origin = Origin;839 type Call = Call;840 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;841 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;842}843844impl cumulus_pallet_xcm::Config for Runtime {845 type Event = Event;846 type XcmExecutor = XcmExecutor<XcmConfig>;847}848849impl cumulus_pallet_xcmp_queue::Config for Runtime {850 type WeightInfo = ();851 type Event = Event;852 type XcmExecutor = XcmExecutor<XcmConfig>;853 type ChannelInfo = ParachainSystem;854 type VersionWrapper = ();855 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;856 type ControllerOrigin = EnsureRoot<AccountId>;857 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;858}859860impl cumulus_pallet_dmp_queue::Config for Runtime {861 type Event = Event;862 type XcmExecutor = XcmExecutor<XcmConfig>;863 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;864}865866impl pallet_aura::Config for Runtime {867 type AuthorityId = AuraId;868 type DisabledValidators = ();869 type MaxAuthorities = MaxAuthorities;870}871872parameter_types! {873 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();874 pub const CollectionCreationPrice: Balance = 2 * UNIQUE;875}876877impl pallet_common::Config for Runtime {878 type WeightInfo = pallet_common::weights::SubstrateWeight<Self>;879 type Event = Event;880 type Currency = Balances;881 type CollectionCreationPrice = CollectionCreationPrice;882 type TreasuryAccountId = TreasuryAccountId;883 type CollectionDispatch = CollectionDispatchT<Self>;884885 type EvmTokenAddressMapping = EvmTokenAddressMapping;886 type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;887}888889impl pallet_structure::Config for Runtime {890 type Event = Event;891 type Call = Call;892 type WeightInfo = pallet_structure::weights::SubstrateWeight<Self>;893}894895impl pallet_fungible::Config for Runtime {896 type WeightInfo = pallet_fungible::weights::SubstrateWeight<Self>;897}898impl pallet_refungible::Config for Runtime {899 type WeightInfo = pallet_refungible::weights::SubstrateWeight<Self>;900}901impl pallet_nonfungible::Config for Runtime {902 type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;903}904905impl pallet_proxy_rmrk_core::Config for Runtime {906 type Event = Event;907}908909impl pallet_unique::Config for Runtime {910 type Event = Event;911 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;912 type CommonWeightInfo = CommonWeights<Self>;913}914915parameter_types! {916 pub const InflationBlockInterval: BlockNumber = 100; 917}918919920impl pallet_inflation::Config for Runtime {921 type Currency = Balances;922 type TreasuryAccountId = TreasuryAccountId;923 type InflationBlockInterval = InflationBlockInterval;924 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;925}926927928929930931932933type EvmSponsorshipHandler = (934 UniqueEthSponsorshipHandler<Runtime>,935 pallet_evm_contract_helpers::HelpersContractSponsoring<Runtime>,936);937type SponsorshipHandler = (938 UniqueSponsorshipHandler<Runtime>,939 940 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,941);942943944945946947948949950951952953954955impl pallet_evm_transaction_payment::Config for Runtime {956 type EvmSponsorshipHandler = EvmSponsorshipHandler;957 type Currency = Balances;958}959960impl pallet_charge_transaction::Config for Runtime {961 type SponsorshipHandler = SponsorshipHandler;962}963964965966967968parameter_types! {969 970 pub const HelpersContractAddress: H160 = H160([971 0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,972 ]);973}974975impl pallet_evm_contract_helpers::Config for Runtime {976 type ContractAddress = HelpersContractAddress;977 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;978}979980construct_runtime!(981 pub enum Runtime where982 Block = Block,983 NodeBlock = opaque::Block,984 UncheckedExtrinsic = UncheckedExtrinsic985 {986 ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,987 ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,988989 Aura: pallet_aura::{Pallet, Config<T>} = 22,990 AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23,991992 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,993 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,994 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,995 TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 33,996 Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,997 Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,998 System: frame_system::{Pallet, Call, Storage, Config, Event<T>} = 36,999 Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,1000 1001 10021003 1004 XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,1005 PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,1006 CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,1007 DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,10081009 1010 Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,1011 Unique: pallet_unique::{Pallet, Call, Storage, Event<T>} = 61,1012 1013 1014 Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64,1015 1016 Common: pallet_common::{Pallet, Storage, Event<T>} = 66,1017 Fungible: pallet_fungible::{Pallet, Storage} = 67,1018 Refungible: pallet_refungible::{Pallet, Storage} = 68,1019 Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,1020 Structure: pallet_structure::{Pallet, Call, Storage, Event<T>} = 70,1021 RmrkCore: pallet_proxy_rmrk_core::{Pallet, Call, Storage, Event<T>} = 71,10221023 1024 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,1025 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,10261027 EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,1028 EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage} = 151,1029 EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,1030 EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,1031 }1032);10331034pub struct TransactionConverter;10351036impl fp_rpc::ConvertTransaction<UncheckedExtrinsic> for TransactionConverter {1037 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic {1038 UncheckedExtrinsic::new_unsigned(1039 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),1040 )1041 }1042}10431044impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConverter {1045 fn convert_transaction(1046 &self,1047 transaction: pallet_ethereum::Transaction,1048 ) -> opaque::UncheckedExtrinsic {1049 let extrinsic = UncheckedExtrinsic::new_unsigned(1050 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),1051 );1052 let encoded = extrinsic.encode();1053 opaque::UncheckedExtrinsic::decode(&mut &encoded[..])1054 .expect("Encoded extrinsic is always valid")1055 }1056}105710581059pub type Address = sp_runtime::MultiAddress<AccountId, ()>;10601061pub type Header = generic::Header<BlockNumber, BlakeTwo256>;10621063pub type Block = generic::Block<Header, UncheckedExtrinsic>;10641065pub type SignedBlock = generic::SignedBlock<Block>;10661067pub type BlockId = generic::BlockId<Block>;10681069pub type SignedExtra = (1070 frame_system::CheckSpecVersion<Runtime>,1071 1072 frame_system::CheckGenesis<Runtime>,1073 frame_system::CheckEra<Runtime>,1074 frame_system::CheckNonce<Runtime>,1075 frame_system::CheckWeight<Runtime>,1076 pallet_charge_transaction::ChargeTransactionPayment<Runtime>,1077 1078 pallet_ethereum::FakeTransactionFinalizer<Runtime>,1079);10801081pub type UncheckedExtrinsic =1082 fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;10831084pub type CheckedExtrinsic = fp_self_contained::CheckedExtrinsic<AccountId, Call, SignedExtra, H160>;10851086pub type Executive = frame_executive::Executive<1087 Runtime,1088 Block,1089 frame_system::ChainContext<Runtime>,1090 Runtime,1091 AllPalletsReversedWithSystemFirst,1092>;10931094impl_opaque_keys! {1095 pub struct SessionKeys {1096 pub aura: Aura,1097 }1098}10991100impl fp_self_contained::SelfContainedCall for Call {1101 type SignedInfo = H160;11021103 fn is_self_contained(&self) -> bool {1104 match self {1105 Call::Ethereum(call) => call.is_self_contained(),1106 _ => false,1107 }1108 }11091110 fn check_self_contained(&self) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {1111 match self {1112 Call::Ethereum(call) => call.check_self_contained(),1113 _ => None,1114 }1115 }11161117 fn validate_self_contained(&self, info: &Self::SignedInfo) -> Option<TransactionValidity> {1118 match self {1119 Call::Ethereum(call) => call.validate_self_contained(info),1120 _ => None,1121 }1122 }11231124 fn pre_dispatch_self_contained(1125 &self,1126 info: &Self::SignedInfo,1127 ) -> Option<Result<(), TransactionValidityError>> {1128 match self {1129 Call::Ethereum(call) => call.pre_dispatch_self_contained(info),1130 _ => None,1131 }1132 }11331134 fn apply_self_contained(1135 self,1136 info: Self::SignedInfo,1137 ) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {1138 match self {1139 call @ Call::Ethereum(pallet_ethereum::Call::transact { .. }) => Some(call.dispatch(1140 Origin::from(pallet_ethereum::RawOrigin::EthereumTransaction(info)),1141 )),1142 _ => None,1143 }1144 }1145}11461147macro_rules! dispatch_unique_runtime {1148 ($collection:ident.$method:ident($($name:ident),*)) => {{1149 let collection = <Runtime as pallet_common::Config>::CollectionDispatch::dispatch(<pallet_common::CollectionHandle<Runtime>>::try_get($collection)?);1150 let dispatch = collection.as_dyn();11511152 Ok::<_, DispatchError>(dispatch.$method($($name),*))1153 }};1154}11551156impl_common_runtime_apis!();11571158struct CheckInherents;11591160impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {1161 fn check_inherents(1162 block: &Block,1163 relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,1164 ) -> sp_inherents::CheckInherentsResult {1165 let relay_chain_slot = relay_state_proof1166 .read_slot()1167 .expect("Could not read the relay chain slot from the proof");11681169 let inherent_data =1170 cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(1171 relay_chain_slot,1172 sp_std::time::Duration::from_secs(6),1173 )1174 .create_inherent_data()1175 .expect("Could not create the timestamp inherent data");11761177 inherent_data.check_extrinsics(block)1178 }1179}11801181cumulus_pallet_parachain_system::register_validate_block!(1182 Runtime = Runtime,1183 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,1184 CheckInherents = CheckInherents,1185);