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 Account as EVMAccount, FeeCalculator, GasWeightMapping,54};55pub use frame_support::{56 construct_runtime, match_types,57 dispatch::DispatchResult,58 PalletId, parameter_types, StorageValue, ConsensusEngineId,59 traits::{60 tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Everything,61 Currency, ExistenceRequirement, Get, IsInVec, KeyOwnerProofSystem, LockIdentifier,62 OnUnbalanced, Randomness, FindAuthor, ConstU32, Imbalance,63 },64 weights::{65 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},66 DispatchClass, DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,67 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, ConstantMultiplier,68 },69};70use up_data_structs::mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping};71use up_data_structs::*;727374use frame_system::{75 self as frame_system, EnsureRoot, EnsureSigned,76 limits::{BlockWeights, BlockLength},77};78use sp_arithmetic::{79 traits::{BaseArithmetic, Unsigned},80};81use smallvec::smallvec;82use codec::{Encode, Decode};83use pallet_unique::pallet_evm_collection;84use fp_rpc::TransactionStatus;85use sp_runtime::{86 traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating},87 transaction_validity::TransactionValidityError,88 SaturatedConversion,89};909192pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;939495use pallet_xcm::XcmPassthrough;96use polkadot_parachain::primitives::Sibling;97use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*};98use xcm_builder::{99 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,100 EnsureXcmOrigin, FixedWeightBounds, LocationInverter, NativeAsset, ParentAsSuperuser,101 RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,102 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,103 ParentIsPreset,104};105use xcm_executor::{Config, XcmExecutor, Assets};106use sp_std::{marker::PhantomData};107108use xcm::latest::{109 110 AssetId::{Concrete},111 Fungibility::Fungible as XcmFungible,112 MultiAsset,113 Error as XcmError,114};115use xcm_executor::traits::{MatchesFungible, WeightTrader};116117use sp_runtime::traits::CheckedConversion;118119use unique_runtime_common::{120 impl_common_runtime_apis,121 types::*,122 constants::*,123 dispatch::{CollectionDispatchT, CollectionDispatch},124 sponsoring::UniqueSponsorshipHandler,125 eth_sponsoring::UniqueEthSponsorshipHandler,126 weights::CommonWeights,127};128129pub const RUNTIME_NAME: &str = "opal";130pub const TOKEN_SYMBOL: &str = "OPL";131132type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;133134impl RuntimeInstance for Runtime {135 type CrossAccountId = self::CrossAccountId;136 type TransactionConverter = self::TransactionConverter;137138 fn get_transaction_converter() -> TransactionConverter {139 TransactionConverter140 }141}142143144145pub type AccountIndex = u32;146147148pub type Balance = u128;149150151pub type Index = u32;152153154pub type Hash = sp_core::H256;155156157pub type DigestItem = generic::DigestItem;158159160161162163pub mod opaque {164 use sp_std::prelude::*;165 use sp_runtime::impl_opaque_keys;166 use super::Aura;167168 pub use unique_runtime_common::types::*;169170 impl_opaque_keys! {171 pub struct SessionKeys {172 pub aura: Aura,173 }174 }175}176177178pub const VERSION: RuntimeVersion = RuntimeVersion {179 spec_name: create_runtime_str!(RUNTIME_NAME),180 impl_name: create_runtime_str!(RUNTIME_NAME),181 authoring_version: 1,182 spec_version: 920000,183 impl_version: 0,184 apis: RUNTIME_API_VERSIONS,185 transaction_version: 1,186 state_version: 0,187};188189#[derive(codec::Encode, codec::Decode)]190pub enum XCMPMessage<XAccountId, XBalance> {191 192 TransferToken(XAccountId, XBalance),193}194195196#[cfg(feature = "std")]197pub fn native_version() -> NativeVersion {198 NativeVersion {199 runtime_version: VERSION,200 can_author_with: Default::default(),201 }202}203204type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;205206pub struct DealWithFees;207impl OnUnbalanced<NegativeImbalance> for DealWithFees {208 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {209 if let Some(fees) = fees_then_tips.next() {210 211 let mut split = fees.ration(100, 0);212 if let Some(tips) = fees_then_tips.next() {213 214 tips.ration_merge_into(100, 0, &mut split);215 }216 Treasury::on_unbalanced(split.0);217 218 }219 }220}221222parameter_types! {223 pub const BlockHashCount: BlockNumber = 2400;224 pub RuntimeBlockLength: BlockLength =225 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);226 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);227 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;228 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()229 .base_block(BlockExecutionWeight::get())230 .for_class(DispatchClass::all(), |weights| {231 weights.base_extrinsic = ExtrinsicBaseWeight::get();232 })233 .for_class(DispatchClass::Normal, |weights| {234 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);235 })236 .for_class(DispatchClass::Operational, |weights| {237 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);238 239 240 weights.reserved = Some(241 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT242 );243 })244 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)245 .build_or_panic();246 pub const Version: RuntimeVersion = VERSION;247 pub const SS58Prefix: u8 = 42;248}249250parameter_types! {251 pub const ChainId: u64 = 8882;252}253254pub struct FixedFee;255impl FeeCalculator for FixedFee {256 fn min_gas_price() -> U256 {257 MIN_GAS_PRICE.into()258 }259}260261262263264parameter_types! {265 pub const WritesPerSecond: u64 = WEIGHT_PER_SECOND / <Runtime as frame_system::Config>::DbWeight::get().write;266 pub const GasPerSecond: u64 = WritesPerSecond::get() * 20000;267 pub const WeightPerGas: u64 = WEIGHT_PER_SECOND / GasPerSecond::get();268}269270271272273const EVM_DISPATCH_RATIO: Perbill = Perbill::from_percent(50);274parameter_types! {275 pub BlockGasLimit: U256 = U256::from(NORMAL_DISPATCH_RATIO * EVM_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT / WeightPerGas::get());276}277278pub enum FixedGasWeightMapping {}279impl GasWeightMapping for FixedGasWeightMapping {280 fn gas_to_weight(gas: u64) -> Weight {281 gas.saturating_mul(WeightPerGas::get())282 }283 fn weight_to_gas(weight: Weight) -> u64 {284 weight / WeightPerGas::get()285 }286}287288impl pallet_evm::account::Config for Runtime {289 type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Self>;290 type EvmAddressMapping = pallet_evm::HashedAddressMapping<Self::Hashing>;291 type EvmBackwardsAddressMapping = fp_evm_mapping::MapBackwardsAddressTruncated;292}293294impl pallet_evm::Config for Runtime {295 type BlockGasLimit = BlockGasLimit;296 type FeeCalculator = FixedFee;297 type GasWeightMapping = FixedGasWeightMapping;298 type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;299 type CallOrigin = EnsureAddressTruncated<Self>;300 type WithdrawOrigin = EnsureAddressTruncated<Self>;301 type AddressMapping = HashedAddressMapping<Self::Hashing>;302 type PrecompilesType = ();303 type PrecompilesValue = ();304 type Currency = Balances;305 type Event = Event;306 type OnMethodCall = (307 pallet_evm_migration::OnMethodCall<Self>,308 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,309 CollectionDispatchT<Self>,310 pallet_evm_collection::CollectionOnMethodCall<Self>,311 );312 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;313 type ChainId = ChainId;314 type Runner = pallet_evm::runner::stack::Runner<Self>;315 type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, DealWithFees>;316 type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;317 type FindAuthor = EthereumFindAuthor<Aura>;318}319320impl pallet_evm_migration::Config for Runtime {321 type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;322}323324pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);325impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {326 fn find_author<'a, I>(digests: I) -> Option<H160>327 where328 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,329 {330 if let Some(author_index) = F::find_author(digests) {331 let authority_id = Aura::authorities()[author_index as usize].clone();332 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));333 }334 None335 }336}337338impl pallet_ethereum::Config for Runtime {339 type Event = Event;340 type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;341}342343impl pallet_randomness_collective_flip::Config for Runtime {}344345impl frame_system::Config for Runtime {346 347 type AccountData = pallet_balances::AccountData<Balance>;348 349 type AccountId = AccountId;350 351 type BaseCallFilter = Everything;352 353 type BlockHashCount = BlockHashCount;354 355 type BlockLength = RuntimeBlockLength;356 357 type BlockNumber = BlockNumber;358 359 type BlockWeights = RuntimeBlockWeights;360 361 type Call = Call;362 363 type DbWeight = RocksDbWeight;364 365 type Event = Event;366 367 type Hash = Hash;368 369 type Hashing = BlakeTwo256;370 371 type Header = generic::Header<BlockNumber, BlakeTwo256>;372 373 type Index = Index;374 375 type Lookup = AccountIdLookup<AccountId, ()>;376 377 type OnKilledAccount = ();378 379 type OnNewAccount = ();380 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;381 382 type Origin = Origin;383 384 type PalletInfo = PalletInfo;385 386 type SS58Prefix = SS58Prefix;387 388 type SystemWeightInfo = frame_system::weights::SubstrateWeight<Self>;389 390 type Version = Version;391 type MaxConsumers = ConstU32<16>;392}393394parameter_types! {395 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;396}397398impl pallet_timestamp::Config for Runtime {399 400 type Moment = u64;401 type OnTimestampSet = ();402 type MinimumPeriod = MinimumPeriod;403 type WeightInfo = ();404}405406parameter_types! {407 408 pub const ExistentialDeposit: u128 = 0;409 pub const MaxLocks: u32 = 50;410}411412impl pallet_balances::Config for Runtime {413 type MaxLocks = MaxLocks;414 type MaxReserves = ();415 type ReserveIdentifier = [u8; 8];416 417 type Balance = Balance;418 419 type Event = Event;420 type DustRemoval = Treasury;421 type ExistentialDeposit = ExistentialDeposit;422 type AccountStore = System;423 type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;424}425426pub const fn deposit(items: u32, bytes: u32) -> Balance {427 items as Balance * 15 * CENTIUNIQUE + (bytes as Balance) * 6 * CENTIUNIQUE428}429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480parameter_types! {481 482 483 pub const OperationalFeeMultiplier: u8 = 5;484}485486487pub struct LinearFee<T>(sp_std::marker::PhantomData<T>);488489impl<T> WeightToFeePolynomial for LinearFee<T>490where491 T: BaseArithmetic + From<u32> + Copy + Unsigned,492{493 type Balance = T;494495 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {496 smallvec!(WeightToFeeCoefficient {497 498 coeff_integer: WEIGHT_TO_FEE_COEFF.into(),499 coeff_frac: Perbill::zero(),500 negative: false,501 degree: 1,502 })503 }504}505506impl pallet_transaction_payment::Config for Runtime {507 type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;508 type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;509 type OperationalFeeMultiplier = OperationalFeeMultiplier;510 type WeightToFee = LinearFee<Balance>;511 type FeeMultiplierUpdate = ();512}513514parameter_types! {515 pub const ProposalBond: Permill = Permill::from_percent(5);516 pub const ProposalBondMinimum: Balance = 1 * UNIQUE;517 pub const ProposalBondMaximum: Balance = 1000 * UNIQUE;518 pub const SpendPeriod: BlockNumber = 5 * MINUTES;519 pub const Burn: Permill = Permill::from_percent(0);520 pub const TipCountdown: BlockNumber = 1 * DAYS;521 pub const TipFindersFee: Percent = Percent::from_percent(20);522 pub const TipReportDepositBase: Balance = 1 * UNIQUE;523 pub const DataDepositPerByte: Balance = 1 * CENTIUNIQUE;524 pub const BountyDepositBase: Balance = 1 * UNIQUE;525 pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;526 pub const TreasuryModuleId: PalletId = PalletId(*b"py/trsry");527 pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;528 pub const MaximumReasonLength: u32 = 16384;529 pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);530 pub const BountyValueMinimum: Balance = 5 * UNIQUE;531 pub const MaxApprovals: u32 = 100;532}533534impl pallet_treasury::Config for Runtime {535 type PalletId = TreasuryModuleId;536 type Currency = Balances;537 type ApproveOrigin = EnsureRoot<AccountId>;538 type RejectOrigin = EnsureRoot<AccountId>;539 type Event = Event;540 type OnSlash = ();541 type ProposalBond = ProposalBond;542 type ProposalBondMinimum = ProposalBondMinimum;543 type ProposalBondMaximum = ProposalBondMaximum;544 type SpendPeriod = SpendPeriod;545 type Burn = Burn;546 type BurnDestination = ();547 type SpendFunds = ();548 type WeightInfo = pallet_treasury::weights::SubstrateWeight<Self>;549 type MaxApprovals = MaxApprovals;550}551552impl pallet_sudo::Config for Runtime {553 type Event = Event;554 type Call = Call;555}556557pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);558559impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider560 for RelayChainBlockNumberProvider<T>561{562 type BlockNumber = BlockNumber;563564 fn current_block_number() -> Self::BlockNumber {565 cumulus_pallet_parachain_system::Pallet::<T>::validation_data()566 .map(|d| d.relay_parent_number)567 .unwrap_or_default()568 }569}570571parameter_types! {572 pub const MinVestedTransfer: Balance = 10 * UNIQUE;573 pub const MaxVestingSchedules: u32 = 28;574}575576impl orml_vesting::Config for Runtime {577 type Event = Event;578 type Currency = pallet_balances::Pallet<Runtime>;579 type MinVestedTransfer = MinVestedTransfer;580 type VestedTransferOrigin = EnsureSigned<AccountId>;581 type WeightInfo = ();582 type MaxVestingSchedules = MaxVestingSchedules;583 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;584}585586parameter_types! {587 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;588 pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;589}590591impl cumulus_pallet_parachain_system::Config for Runtime {592 type Event = Event;593 type SelfParaId = parachain_info::Pallet<Self>;594 type OnSystemEvent = ();595 596 597 598 599 600 type OutboundXcmpMessageSource = XcmpQueue;601 type DmpMessageHandler = DmpQueue;602 type ReservedDmpWeight = ReservedDmpWeight;603 type ReservedXcmpWeight = ReservedXcmpWeight;604 type XcmpMessageHandler = XcmpQueue;605}606607impl parachain_info::Config for Runtime {}608609impl cumulus_pallet_aura_ext::Config for Runtime {}610611parameter_types! {612 pub const RelayLocation: MultiLocation = MultiLocation::parent();613 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;614 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();615 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();616}617618619620621pub type LocationToAccountId = (622 623 ParentIsPreset<AccountId>,624 625 SiblingParachainConvertsVia<Sibling, AccountId>,626 627 AccountId32Aliases<RelayNetwork, AccountId>,628);629630pub struct OnlySelfCurrency;631impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {632 fn matches_fungible(a: &MultiAsset) -> Option<B> {633 match (&a.id, &a.fun) {634 (Concrete(_), XcmFungible(ref amount)) => CheckedConversion::checked_from(*amount),635 _ => None,636 }637 }638}639640641pub type LocalAssetTransactor = CurrencyAdapter<642 643 Balances,644 645 OnlySelfCurrency,646 647 LocationToAccountId,648 649 AccountId,650 651 (),652>;653654655656657pub type XcmOriginToTransactDispatchOrigin = (658 659 660 661 SovereignSignedViaLocation<LocationToAccountId, Origin>,662 663 664 RelayChainAsNative<RelayOrigin, Origin>,665 666 667 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,668 669 670 ParentAsSuperuser<Origin>,671 672 673 SignedAccountId32AsNative<RelayNetwork, Origin>,674 675 XcmPassthrough<Origin>,676);677678parameter_types! {679 680 pub UnitWeightCost: Weight = 1_000_000;681 682 pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);683 pub const MaxInstructions: u32 = 100;684 pub const MaxAuthorities: u32 = 100_000;685}686687match_types! {688 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {689 MultiLocation { parents: 1, interior: Here } |690 MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }691 };692}693694pub type Barrier = (695 TakeWeightCredit,696 AllowTopLevelPaidExecutionFrom<Everything>,697 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,698 699);700701pub struct UsingOnlySelfCurrencyComponents<702 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,703 AssetId: Get<MultiLocation>,704 AccountId,705 Currency: CurrencyT<AccountId>,706 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,707>(708 Weight,709 Currency::Balance,710 PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,711);712impl<713 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,714 AssetId: Get<MultiLocation>,715 AccountId,716 Currency: CurrencyT<AccountId>,717 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,718 > WeightTrader719 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>720{721 fn new() -> Self {722 Self(0, Zero::zero(), PhantomData)723 }724725 fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {726 let amount = WeightToFee::calc(&weight);727 let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;728729 730 let option1: xcm::v1::AssetId = Concrete(MultiLocation {731 parents: 1,732 interior: X1(Parachain(ParachainInfo::parachain_id().into())),733 });734 735 let option2: xcm::v1::AssetId = Concrete(MultiLocation {736 parents: 0,737 interior: Here,738 });739740 let required = if payment.fungible.contains_key(&option1) {741 (option1, u128_amount).into()742 } else if payment.fungible.contains_key(&option2) {743 (option2, u128_amount).into()744 } else {745 (Concrete(MultiLocation::default()), u128_amount).into()746 };747748 let unused = payment749 .checked_sub(required)750 .map_err(|_| XcmError::TooExpensive)?;751 self.0 = self.0.saturating_add(weight);752 self.1 = self.1.saturating_add(amount);753 Ok(unused)754 }755756 fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {757 let weight = weight.min(self.0);758 let amount = WeightToFee::calc(&weight);759 self.0 -= weight;760 self.1 = self.1.saturating_sub(amount);761 let amount: u128 = amount.saturated_into();762 if amount > 0 {763 Some((AssetId::get(), amount).into())764 } else {765 None766 }767 }768}769impl<770 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,771 AssetId: Get<MultiLocation>,772 AccountId,773 Currency: CurrencyT<AccountId>,774 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,775 > Drop776 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>777{778 fn drop(&mut self) {779 OnUnbalanced::on_unbalanced(Currency::issue(self.1));780 }781}782783pub struct XcmConfig;784impl Config for XcmConfig {785 type Call = Call;786 type XcmSender = XcmRouter;787 788 type AssetTransactor = LocalAssetTransactor;789 type OriginConverter = XcmOriginToTransactDispatchOrigin;790 type IsReserve = NativeAsset;791 type IsTeleporter = (); 792 type LocationInverter = LocationInverter<Ancestry>;793 type Barrier = Barrier;794 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;795 type Trader = UsingOnlySelfCurrencyComponents<796 IdentityFee<Balance>,797 RelayLocation,798 AccountId,799 Balances,800 (),801 >;802 type ResponseHandler = (); 803 type SubscriptionService = PolkadotXcm;804805 type AssetTrap = PolkadotXcm;806 type AssetClaims = PolkadotXcm;807}808809810811812813814pub type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, RelayNetwork>,);815816817818pub type XcmRouter = (819 820 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,821 822 XcmpQueue,823);824825impl pallet_evm_coder_substrate::Config for Runtime {826 type GasWeightMapping = FixedGasWeightMapping;827}828829impl pallet_xcm::Config for Runtime {830 type Event = Event;831 type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;832 type XcmRouter = XcmRouter;833 type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;834 type XcmExecuteFilter = Everything;835 type XcmExecutor = XcmExecutor<XcmConfig>;836 type XcmTeleportFilter = Everything;837 type XcmReserveTransferFilter = Everything;838 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;839 type LocationInverter = LocationInverter<Ancestry>;840 type Origin = Origin;841 type Call = Call;842 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;843 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;844}845846impl cumulus_pallet_xcm::Config for Runtime {847 type Event = Event;848 type XcmExecutor = XcmExecutor<XcmConfig>;849}850851impl cumulus_pallet_xcmp_queue::Config for Runtime {852 type WeightInfo = ();853 type Event = Event;854 type XcmExecutor = XcmExecutor<XcmConfig>;855 type ChannelInfo = ParachainSystem;856 type VersionWrapper = ();857 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;858 type ControllerOrigin = EnsureRoot<AccountId>;859 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;860}861862impl cumulus_pallet_dmp_queue::Config for Runtime {863 type Event = Event;864 type XcmExecutor = XcmExecutor<XcmConfig>;865 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;866}867868impl pallet_aura::Config for Runtime {869 type AuthorityId = AuraId;870 type DisabledValidators = ();871 type MaxAuthorities = MaxAuthorities;872}873874parameter_types! {875 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();876 pub const CollectionCreationPrice: Balance = 2 * UNIQUE;877}878879impl pallet_common::Config for Runtime {880 type WeightInfo = pallet_common::weights::SubstrateWeight<Self>;881 type Event = Event;882 type Currency = Balances;883 type CollectionCreationPrice = CollectionCreationPrice;884 type TreasuryAccountId = TreasuryAccountId;885 type CollectionDispatch = CollectionDispatchT<Self>;886887 type EvmTokenAddressMapping = EvmTokenAddressMapping;888 type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;889}890891impl pallet_structure::Config for Runtime {892 type Event = Event;893 type Call = Call;894 type WeightInfo = pallet_structure::weights::SubstrateWeight<Self>;895}896897impl pallet_fungible::Config for Runtime {898 type WeightInfo = pallet_fungible::weights::SubstrateWeight<Self>;899}900impl pallet_refungible::Config for Runtime {901 type WeightInfo = pallet_refungible::weights::SubstrateWeight<Self>;902}903impl pallet_nonfungible::Config for Runtime {904 type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;905}906907impl pallet_proxy_rmrk_core::Config for Runtime {908 type Event = Event;909}910911impl pallet_proxy_rmrk_equip::Config for Runtime {912 type Event = Event;913}914915impl pallet_unique::Config for Runtime {916 type Event = Event;917 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;918 type CommonWeightInfo = CommonWeights<Self>;919}920921parameter_types! {922 pub const InflationBlockInterval: BlockNumber = 100; 923}924925926impl pallet_inflation::Config for Runtime {927 type Currency = Balances;928 type TreasuryAccountId = TreasuryAccountId;929 type InflationBlockInterval = InflationBlockInterval;930 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;931}932933934935936937938939type EvmSponsorshipHandler = (940 UniqueEthSponsorshipHandler<Runtime>,941 pallet_evm_contract_helpers::HelpersContractSponsoring<Runtime>,942);943type SponsorshipHandler = (944 UniqueSponsorshipHandler<Runtime>,945 946 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,947);948949950951952953954955956957958959960961impl pallet_evm_transaction_payment::Config for Runtime {962 type EvmSponsorshipHandler = EvmSponsorshipHandler;963 type Currency = Balances;964}965966impl pallet_charge_transaction::Config for Runtime {967 type SponsorshipHandler = SponsorshipHandler;968}969970971972973974parameter_types! {975 976 pub const HelpersContractAddress: H160 = H160([977 0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,978 ]);979980 981 pub const EvmCollectionAddress: H160 = H160([982 0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,983 ]);984}985986impl pallet_evm_contract_helpers::Config for Runtime {987 type ContractAddress = HelpersContractAddress;988 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;989}990991impl pallet_evm_collection::Config for Runtime {992 type ContractAddress = EvmCollectionAddress;993}994995construct_runtime!(996 pub enum Runtime where997 Block = Block,998 NodeBlock = opaque::Block,999 UncheckedExtrinsic = UncheckedExtrinsic1000 {1001 ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,1002 ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,10031004 Aura: pallet_aura::{Pallet, Config<T>} = 22,1005 AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23,10061007 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,1008 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,1009 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,1010 TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 33,1011 Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,1012 Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,1013 System: frame_system::{Pallet, Call, Storage, Config, Event<T>} = 36,1014 Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,1015 1016 10171018 1019 XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,1020 PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,1021 CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,1022 DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,10231024 1025 Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,1026 Unique: pallet_unique::{Pallet, Call, Storage, Event<T>} = 61,1027 1028 1029 Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64,1030 1031 Common: pallet_common::{Pallet, Storage, Event<T>} = 66,1032 Fungible: pallet_fungible::{Pallet, Storage} = 67,1033 Refungible: pallet_refungible::{Pallet, Storage} = 68,1034 Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,1035 Structure: pallet_structure::{Pallet, Call, Storage, Event<T>} = 70,1036 RmrkCore: pallet_proxy_rmrk_core::{Pallet, Call, Storage, Event<T>} = 71,1037 RmrkEquip: pallet_proxy_rmrk_equip::{Pallet, Call, Storage, Event<T>} = 72,10381039 1040 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,1041 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,10421043 EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,1044 EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage} = 151,1045 EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,1046 EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,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);