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 generic::Era,37 traits::{38 Applyable, BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating,39 CheckedConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion,40 Zero, Member,41 },42 transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError},43 ApplyExtrinsicResult, RuntimeAppPublic, SaturatedConversion, DispatchErrorWithPostInfo,44};4546use fp_self_contained::{SelfContainedCall, CheckedSignature};47use sp_std::{cmp::Ordering, marker::PhantomData};48use pallet_unq_scheduler::DispatchCall;4950use sp_std::prelude::*;5152#[cfg(feature = "std")]53use sp_version::NativeVersion;54use sp_version::RuntimeVersion;55pub use pallet_transaction_payment::{56 Multiplier, TargetedFeeAdjustment, FeeDetails, RuntimeDispatchInfo,57};5859pub use pallet_balances::Call as BalancesCall;60pub use pallet_evm::{61 EnsureAddressTruncated, HashedAddressMapping, Runner, account::CrossAccountId as _,62};63pub use frame_support::{64 construct_runtime, match_types,65 dispatch::DispatchResult,66 PalletId, parameter_types, StorageValue, ConsensusEngineId,67 traits::{68 tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Everything,69 Currency, ExistenceRequirement, Get, IsInVec, KeyOwnerProofSystem, LockIdentifier,70 OnUnbalanced, Randomness, FindAuthor, PrivilegeCmp,71 },72 weights::{73 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},74 DispatchClass, DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,75 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, ConstantMultiplier,76 },77};78use up_data_structs::*;798081use frame_system::{82 self as frame_system, EnsureRoot, EnsureSigned,83 limits::{BlockWeights, BlockLength},84};85use sp_arithmetic::{86 traits::{BaseArithmetic, Unsigned},87};88use smallvec::smallvec;89use codec::{Encode, Decode};90use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping};91use fp_rpc::TransactionStatus;9293949596use pallet_xcm::XcmPassthrough;97use polkadot_parachain::primitives::Sibling;98use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*};99use xcm_builder::{100 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,101 EnsureXcmOrigin, FixedWeightBounds, LocationInverter, NativeAsset, ParentAsSuperuser,102 RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,103 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,104 ParentIsPreset,105};106use xcm_executor::{Config, XcmExecutor, Assets};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};116use unique_runtime_common::{impl_common_runtime_apis, types::*, constants::*};117118pub const RUNTIME_NAME: &str = "unique";119pub const TOKEN_SYMBOL: &str = "UNQ";120121type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;122123impl RuntimeInstance for Runtime {124 type CrossAccountId = self::CrossAccountId;125126 type TransactionConverter = self::TransactionConverter;127128 fn get_transaction_converter() -> TransactionConverter {129 TransactionConverter130 }131}132133134135136137pub mod opaque {138 use sp_std::prelude::*;139 use sp_runtime::impl_opaque_keys;140 use super::Aura;141142 pub use unique_runtime_common::types::*;143144 impl_opaque_keys! {145 pub struct SessionKeys {146 pub aura: Aura,147 }148 }149}150151152pub const VERSION: RuntimeVersion = RuntimeVersion {153 spec_name: create_runtime_str!(RUNTIME_NAME),154 impl_name: create_runtime_str!(RUNTIME_NAME),155 authoring_version: 1,156 spec_version: 921000,157 impl_version: 0,158 apis: RUNTIME_API_VERSIONS,159 transaction_version: 1,160 state_version: 0,161};162163#[derive(codec::Encode, codec::Decode)]164pub enum XCMPMessage<XAccountId, XBalance> {165 166 TransferToken(XAccountId, XBalance),167}168169170#[cfg(feature = "std")]171pub fn native_version() -> NativeVersion {172 NativeVersion {173 runtime_version: VERSION,174 can_author_with: Default::default(),175 }176}177178type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;179180pub struct DealWithFees;181impl OnUnbalanced<NegativeImbalance> for DealWithFees {182 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {183 if let Some(fees) = fees_then_tips.next() {184 185 let mut split = fees.ration(100, 0);186 if let Some(tips) = fees_then_tips.next() {187 188 tips.ration_merge_into(100, 0, &mut split);189 }190 Treasury::on_unbalanced(split.0);191 192 }193 }194}195196parameter_types! {197 pub const BlockHashCount: BlockNumber = 2400;198 pub RuntimeBlockLength: BlockLength =199 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);200 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);201 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;202 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()203 .base_block(BlockExecutionWeight::get())204 .for_class(DispatchClass::all(), |weights| {205 weights.base_extrinsic = ExtrinsicBaseWeight::get();206 })207 .for_class(DispatchClass::Normal, |weights| {208 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);209 })210 .for_class(DispatchClass::Operational, |weights| {211 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);212 213 214 weights.reserved = Some(215 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT216 );217 })218 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)219 .build_or_panic();220 pub const Version: RuntimeVersion = VERSION;221 pub const SS58Prefix: u16 = 7391;222}223224parameter_types! {225 pub const ChainId: u64 = 8880;226}227228pub struct FixedFee;229impl FeeCalculator for FixedFee {230 fn min_gas_price() -> U256 {231 MIN_GAS_PRICE.into()232 }233}234235236237238parameter_types! {239 pub const WritesPerSecond: u64 = WEIGHT_PER_SECOND / <Runtime as frame_system::Config>::DbWeight::get().write;240 pub const GasPerSecond: u64 = WritesPerSecond::get() * 20000;241 pub const WeightPerGas: u64 = WEIGHT_PER_SECOND / GasPerSecond::get();242}243244245246247const EVM_DISPATCH_RATIO: Perbill = Perbill::from_percent(50);248parameter_types! {249 pub BlockGasLimit: U256 = U256::from(NORMAL_DISPATCH_RATIO * EVM_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT / WeightPerGas::get());250}251252pub enum FixedGasWeightMapping {}253impl GasWeightMapping for FixedGasWeightMapping {254 fn gas_to_weight(gas: u64) -> Weight {255 gas.saturating_mul(WeightPerGas::get())256 }257 fn weight_to_gas(weight: Weight) -> u64 {258 weight / WeightPerGas::get()259 }260}261262impl pallet_evm::Config for Runtime {263 type BlockGasLimit = BlockGasLimit;264 type FeeCalculator = FixedFee;265 type GasWeightMapping = FixedGasWeightMapping;266 type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;267 type CallOrigin = EnsureAddressTruncated<Self>;268 type WithdrawOrigin = EnsureAddressTruncated<Self>;269 type AddressMapping = HashedAddressMapping<Self::Hashing>;270 type PrecompilesType = ();271 type PrecompilesValue = ();272 type Currency = Balances;273 type Event = Event;274 type OnMethodCall = (275 pallet_evm_migration::OnMethodCall<Self>,276 pallet_unique::UniqueErcSupport<Self>,277 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,278 );279 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;280 type ChainId = ChainId;281 type Runner = pallet_evm::runner::stack::Runner<Self>;282 type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, DealWithFees>;283 type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;284 type FindAuthor = EthereumFindAuthor<Aura>;285}286287impl pallet_evm_migration::Config for Runtime {288 type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;289}290291pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);292impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {293 fn find_author<'a, I>(digests: I) -> Option<H160>294 where295 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,296 {297 if let Some(author_index) = F::find_author(digests) {298 let authority_id = Aura::authorities()[author_index as usize].clone();299 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));300 }301 None302 }303}304305impl pallet_ethereum::Config for Runtime {306 type Event = Event;307 type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;308}309310impl pallet_randomness_collective_flip::Config for Runtime {}311312impl frame_system::Config for Runtime {313 314 type AccountData = pallet_balances::AccountData<Balance>;315 316 type AccountId = AccountId;317 318 type BaseCallFilter = Everything;319 320 type BlockHashCount = BlockHashCount;321 322 type BlockLength = RuntimeBlockLength;323 324 type BlockNumber = BlockNumber;325 326 type BlockWeights = RuntimeBlockWeights;327 328 type Call = Call;329 330 type DbWeight = RocksDbWeight;331 332 type Event = Event;333 334 type Hash = Hash;335 336 type Hashing = BlakeTwo256;337 338 type Header = generic::Header<BlockNumber, BlakeTwo256>;339 340 type Index = Index;341 342 type Lookup = AccountIdLookup<AccountId, ()>;343 344 type OnKilledAccount = ();345 346 type OnNewAccount = ();347 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;348 349 type Origin = Origin;350 351 type PalletInfo = PalletInfo;352 353 type SS58Prefix = SS58Prefix;354 355 type SystemWeightInfo = frame_system::weights::SubstrateWeight<Self>;356 357 type Version = Version;358 type MaxConsumers = ConstU32<16>;359}360361parameter_types! {362 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;363}364365impl pallet_timestamp::Config for Runtime {366 367 type Moment = u64;368 type OnTimestampSet = ();369 type MinimumPeriod = MinimumPeriod;370 type WeightInfo = ();371}372373parameter_types! {374 375 pub const ExistentialDeposit: u128 = 0;376 pub const MaxLocks: u32 = 50;377}378379impl pallet_balances::Config for Runtime {380 type MaxLocks = MaxLocks;381 type MaxReserves = ();382 type ReserveIdentifier = [u8; 16];383 384 type Balance = Balance;385 386 type Event = Event;387 type DustRemoval = Treasury;388 type ExistentialDeposit = ExistentialDeposit;389 type AccountStore = System;390 type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;391}392393pub const fn deposit(items: u32, bytes: u32) -> Balance {394 items as Balance * 15 * CENTIUNIQUE + (bytes as Balance) * 6 * CENTIUNIQUE395}396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447parameter_types! {448 449 450 pub const OperationalFeeMultiplier: u8 = 5;451}452453454pub struct LinearFee<T>(sp_std::marker::PhantomData<T>);455456impl<T> WeightToFeePolynomial for LinearFee<T>457where458 T: BaseArithmetic + From<u32> + Copy + Unsigned,459{460 type Balance = T;461462 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {463 smallvec!(WeightToFeeCoefficient {464 465 coeff_integer: WEIGHT_TO_FEE_COEFF.into(),466 coeff_frac: Perbill::zero(),467 negative: false,468 degree: 1,469 })470 }471}472473impl pallet_transaction_payment::Config for Runtime {474 type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;475 type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;476 type OperationalFeeMultiplier = OperationalFeeMultiplier;477 type WeightToFee = LinearFee<Balance>;478 type FeeMultiplierUpdate = ();479}480481parameter_types! {482 pub const ProposalBond: Permill = Permill::from_percent(5);483 pub const ProposalBondMinimum: Balance = 1 * UNIQUE;484 pub const ProposalBondMaximum: Balance = 1000 * UNIQUE;485 pub const SpendPeriod: BlockNumber = 5 * MINUTES;486 pub const Burn: Permill = Permill::from_percent(0);487 pub const TipCountdown: BlockNumber = 1 * DAYS;488 pub const TipFindersFee: Percent = Percent::from_percent(20);489 pub const TipReportDepositBase: Balance = 1 * UNIQUE;490 pub const DataDepositPerByte: Balance = 1 * CENTIUNIQUE;491 pub const BountyDepositBase: Balance = 1 * UNIQUE;492 pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;493 pub const TreasuryModuleId: PalletId = PalletId(*b"py/trsry");494 pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;495 pub const MaximumReasonLength: u32 = 16384;496 pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);497 pub const BountyValueMinimum: Balance = 5 * UNIQUE;498 pub const MaxApprovals: u32 = 100;499}500501impl pallet_treasury::Config for Runtime {502 type PalletId = TreasuryModuleId;503 type Currency = Balances;504 type ApproveOrigin = EnsureRoot<AccountId>;505 type RejectOrigin = EnsureRoot<AccountId>;506 type Event = Event;507 type OnSlash = ();508 type ProposalBond = ProposalBond;509 type ProposalBondMinimum = ProposalBondMinimum;510 type ProposalBondMaximum = ProposalBondMaximum;511 type SpendPeriod = SpendPeriod;512 type Burn = Burn;513 type BurnDestination = ();514 type SpendFunds = ();515 type WeightInfo = pallet_treasury::weights::SubstrateWeight<Self>;516 type MaxApprovals = MaxApprovals;517}518519impl pallet_sudo::Config for Runtime {520 type Event = Event;521 type Call = Call;522}523524pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);525526impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider527 for RelayChainBlockNumberProvider<T>528{529 type BlockNumber = BlockNumber;530531 fn current_block_number() -> Self::BlockNumber {532 cumulus_pallet_parachain_system::Pallet::<T>::validation_data()533 .map(|d| d.relay_parent_number)534 .unwrap_or_default()535 }536}537538parameter_types! {539 pub const MinVestedTransfer: Balance = 10 * UNIQUE;540 pub const MaxVestingSchedules: u32 = 28;541}542543impl orml_vesting::Config for Runtime {544 type Event = Event;545 type Currency = pallet_balances::Pallet<Runtime>;546 type MinVestedTransfer = MinVestedTransfer;547 type VestedTransferOrigin = EnsureSigned<AccountId>;548 type WeightInfo = ();549 type MaxVestingSchedules = MaxVestingSchedules;550 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;551}552553parameter_types! {554 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;555 pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;556}557558impl cumulus_pallet_parachain_system::Config for Runtime {559 type Event = Event;560 type SelfParaId = parachain_info::Pallet<Self>;561 type OnSystemEvent = ();562 563 564 565 566 567 type OutboundXcmpMessageSource = XcmpQueue;568 type DmpMessageHandler = DmpQueue;569 type ReservedDmpWeight = ReservedDmpWeight;570 type ReservedXcmpWeight = ReservedXcmpWeight;571 type XcmpMessageHandler = XcmpQueue;572}573574impl parachain_info::Config for Runtime {}575576impl cumulus_pallet_aura_ext::Config for Runtime {}577578parameter_types! {579 pub const RelayLocation: MultiLocation = MultiLocation::parent();580 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;581 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();582 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();583}584585586587588pub type LocationToAccountId = (589 590 ParentIsPreset<AccountId>,591 592 SiblingParachainConvertsVia<Sibling, AccountId>,593 594 AccountId32Aliases<RelayNetwork, AccountId>,595);596597pub struct OnlySelfCurrency;598impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {599 fn matches_fungible(a: &MultiAsset) -> Option<B> {600 match (&a.id, &a.fun) {601 (Concrete(_), XcmFungible(ref amount)) => CheckedConversion::checked_from(*amount),602 _ => None,603 }604 }605}606607608pub type LocalAssetTransactor = CurrencyAdapter<609 610 Balances,611 612 OnlySelfCurrency,613 614 LocationToAccountId,615 616 AccountId,617 618 (),619>;620621622623624pub type XcmOriginToTransactDispatchOrigin = (625 626 627 628 SovereignSignedViaLocation<LocationToAccountId, Origin>,629 630 631 RelayChainAsNative<RelayOrigin, Origin>,632 633 634 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,635 636 637 ParentAsSuperuser<Origin>,638 639 640 SignedAccountId32AsNative<RelayNetwork, Origin>,641 642 XcmPassthrough<Origin>,643);644645parameter_types! {646 647 pub UnitWeightCost: Weight = 1_000_000;648 649 pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);650 pub const MaxInstructions: u32 = 100;651 pub const MaxAuthorities: u32 = 100_000;652}653654match_types! {655 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {656 MultiLocation { parents: 1, interior: Here } |657 MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }658 };659}660661pub type Barrier = (662 TakeWeightCredit,663 AllowTopLevelPaidExecutionFrom<Everything>,664 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,665 666);667668pub struct UsingOnlySelfCurrencyComponents<669 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,670 AssetId: Get<MultiLocation>,671 AccountId,672 Currency: CurrencyT<AccountId>,673 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,674>(675 Weight,676 Currency::Balance,677 PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,678);679impl<680 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,681 AssetId: Get<MultiLocation>,682 AccountId,683 Currency: CurrencyT<AccountId>,684 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,685 > WeightTrader686 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>687{688 fn new() -> Self {689 Self(0, Zero::zero(), PhantomData)690 }691692 fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {693 let amount = WeightToFee::calc(&weight);694 let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;695696 697 let option1: xcm::v1::AssetId = Concrete(MultiLocation {698 parents: 1,699 interior: X1(Parachain(ParachainInfo::parachain_id().into())),700 });701 702 let option2: xcm::v1::AssetId = Concrete(MultiLocation {703 parents: 0,704 interior: Here,705 });706707 let required = if payment.fungible.contains_key(&option1) {708 (option1, u128_amount).into()709 } else if payment.fungible.contains_key(&option2) {710 (option2, u128_amount).into()711 } else {712 (Concrete(MultiLocation::default()), u128_amount).into()713 };714715 let unused = payment716 .checked_sub(required)717 .map_err(|_| XcmError::TooExpensive)?;718 self.0 = self.0.saturating_add(weight);719 self.1 = self.1.saturating_add(amount);720 Ok(unused)721 }722723 fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {724 let weight = weight.min(self.0);725 let amount = WeightToFee::calc(&weight);726 self.0 -= weight;727 self.1 = self.1.saturating_sub(amount);728 let amount: u128 = amount.saturated_into();729 if amount > 0 {730 Some((AssetId::get(), amount).into())731 } else {732 None733 }734 }735}736impl<737 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,738 AssetId: Get<MultiLocation>,739 AccountId,740 Currency: CurrencyT<AccountId>,741 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,742 > Drop743 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>744{745 fn drop(&mut self) {746 OnUnbalanced::on_unbalanced(Currency::issue(self.1));747 }748}749750pub struct XcmConfig;751impl Config for XcmConfig {752 type Call = Call;753 type XcmSender = XcmRouter;754 755 type AssetTransactor = LocalAssetTransactor;756 type OriginConverter = XcmOriginToTransactDispatchOrigin;757 type IsReserve = NativeAsset;758 type IsTeleporter = (); 759 type LocationInverter = LocationInverter<Ancestry>;760 type Barrier = Barrier;761 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;762 type Trader = UsingOnlySelfCurrencyComponents<763 IdentityFee<Balance>,764 RelayLocation,765 AccountId,766 Balances,767 (),768 >;769 type ResponseHandler = (); 770 type SubscriptionService = PolkadotXcm;771772 type AssetTrap = PolkadotXcm;773 type AssetClaims = PolkadotXcm;774}775776777778779780781pub type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, RelayNetwork>,);782783784785pub type XcmRouter = (786 787 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,788 789 XcmpQueue,790);791792impl pallet_evm_coder_substrate::Config for Runtime {793 type EthereumTransactionSender = pallet_ethereum::Pallet<Self>;794 type GasWeightMapping = FixedGasWeightMapping;795}796797impl pallet_xcm::Config for Runtime {798 type Event = Event;799 type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;800 type XcmRouter = XcmRouter;801 type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;802 type XcmExecuteFilter = Everything;803 type XcmExecutor = XcmExecutor<XcmConfig>;804 type XcmTeleportFilter = Everything;805 type XcmReserveTransferFilter = Everything;806 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;807 type LocationInverter = LocationInverter<Ancestry>;808 type Origin = Origin;809 type Call = Call;810 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;811 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;812}813814impl cumulus_pallet_xcm::Config for Runtime {815 type Event = Event;816 type XcmExecutor = XcmExecutor<XcmConfig>;817}818819impl cumulus_pallet_xcmp_queue::Config for Runtime {820 type WeightInfo = ();821 type Event = Event;822 type XcmExecutor = XcmExecutor<XcmConfig>;823 type ChannelInfo = ParachainSystem;824 type VersionWrapper = ();825 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;826 type ControllerOrigin = EnsureRoot<AccountId>;827 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;828}829830impl cumulus_pallet_dmp_queue::Config for Runtime {831 type Event = Event;832 type XcmExecutor = XcmExecutor<XcmConfig>;833 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;834}835836impl pallet_aura::Config for Runtime {837 type AuthorityId = AuraId;838 type DisabledValidators = ();839 type MaxAuthorities = MaxAuthorities;840}841842parameter_types! {843 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();844 pub const CollectionCreationPrice: Balance = 2 * UNIQUE;845}846847impl pallet_common::Config for Runtime {848 type Event = Event;849 type Currency = Balances;850 type CollectionCreationPrice = CollectionCreationPrice;851 type TreasuryAccountId = TreasuryAccountId;852}853854impl pallet_evm::account::Config for Runtime {855 type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Self>;856 type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;857 type EvmBackwardsAddressMapping = fp_evm_mapping::MapBackwardsAddressTruncated;858}859860impl pallet_fungible::Config for Runtime {861 type WeightInfo = pallet_fungible::weights::SubstrateWeight<Self>;862}863impl pallet_refungible::Config for Runtime {864 type WeightInfo = pallet_refungible::weights::SubstrateWeight<Self>;865}866impl pallet_nonfungible::Config for Runtime {867 type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;868}869870impl pallet_unique::Config for Runtime {871 type Event = Event;872 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;873}874875parameter_types! {876 pub const InflationBlockInterval: BlockNumber = 100; 877}878879880impl pallet_inflation::Config for Runtime {881 type Currency = Balances;882 type TreasuryAccountId = TreasuryAccountId;883 type InflationBlockInterval = InflationBlockInterval;884 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;885}886887parameter_types! {888 pub MaximumSchedulerWeight: Weight = Perbill::from_percent(50) *889 RuntimeBlockWeights::get().max_block;890 pub const MaxScheduledPerBlock: u32 = 50;891}892893parameter_types! {894 pub const NoPreimagePostponement: Option<u32> = Some(10);895 pub const Preimage: Option<u32> = Some(10);896}897898899pub struct OriginPrivilegeCmp;900impl PrivilegeCmp<OriginCaller> for OriginPrivilegeCmp {901 fn cmp_privilege(_left: &OriginCaller, _right: &OriginCaller) -> Option<Ordering> {902 Some(Ordering::Equal)903 }904}905906impl pallet_unq_scheduler::Config for Runtime {907 type Event = Event;908 type Origin = Origin;909 type Currency = Balances;910 type PalletsOrigin = OriginCaller;911 type Call = Call;912 type MaximumWeight = MaximumSchedulerWeight;913 type ScheduleOrigin = EnsureSigned<AccountId>;914 type MaxScheduledPerBlock = MaxScheduledPerBlock;915 type WeightInfo = ();916 type CallExecutor = SchedulerPaymentExecutor;917 type OriginPrivilegeCmp = OriginPrivilegeCmp;918 type PreimageProvider = ();919 type NoPreimagePostponement = NoPreimagePostponement;920}921922type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;923use frame_support::traits::NamedReservableCurrency;924925fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {926 (927 frame_system::CheckSpecVersion::<Runtime>::new(),928 frame_system::CheckGenesis::<Runtime>::new(),929 frame_system::CheckEra::<Runtime>::from(Era::Immortal),930 frame_system::CheckNonce::<Runtime>::from(frame_system::Pallet::<Runtime>::account_nonce(931 from,932 )),933 frame_system::CheckWeight::<Runtime>::new(),934 935 936 )937}938939pub struct SchedulerPaymentExecutor;940impl<T: frame_system::Config + pallet_unq_scheduler::Config, SelfContainedSignedInfo>941 DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor942where943 <T as frame_system::Config>::Call: Member944 + Dispatchable<Origin = Origin, Info = DispatchInfo>945 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>946 + GetDispatchInfo947 + From<frame_system::Call<Runtime>>,948 SelfContainedSignedInfo: Send + Sync + 'static,949 Call: From<<T as frame_system::Config>::Call>950 + From<<T as pallet_unq_scheduler::Config>::Call>951 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,952 sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,953{954 fn dispatch_call(955 signer: <T as frame_system::Config>::AccountId,956 call: <T as pallet_unq_scheduler::Config>::Call,957 ) -> Result<958 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,959 TransactionValidityError,960 > {961 let dispatch_info = call.get_dispatch_info();962 let extrinsic = fp_self_contained::CheckedExtrinsic::<963 AccountId,964 Call,965 SignedExtraScheduler,966 SelfContainedSignedInfo,967 > {968 signed:969 CheckedSignature::<AccountId, SignedExtraScheduler, SelfContainedSignedInfo>::Signed(970 signer.clone().into(),971 get_signed_extras(signer.into()),972 ),973 function: call.into(),974 };975976 extrinsic.apply::<Runtime>(&dispatch_info, 0)977 }978979 fn reserve_balance(980 id: [u8; 16],981 sponsor: <T as frame_system::Config>::AccountId,982 call: <T as pallet_unq_scheduler::Config>::Call,983 count: u32,984 ) -> Result<(), DispatchError> {985 let dispatch_info = call.get_dispatch_info();986 let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)987 .saturating_mul(count.into());988989 <Balances as NamedReservableCurrency<AccountId>>::reserve_named(990 &id,991 &(sponsor.into()),992 weight.into(),993 )994 }995996 fn pay_for_call(997 id: [u8; 16],998 sponsor: <T as frame_system::Config>::AccountId,999 call: <T as pallet_unq_scheduler::Config>::Call,1000 ) -> Result<u128, DispatchError> {1001 let dispatch_info = call.get_dispatch_info();1002 let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);1003 Ok(1004 <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(1005 &id,1006 &(sponsor.into()),1007 weight.into(),1008 ),1009 )1010 }10111012 fn cancel_reserve(1013 id: [u8; 16],1014 sponsor: <T as frame_system::Config>::AccountId,1015 ) -> Result<u128, DispatchError> {1016 Ok(1017 <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(1018 &id,1019 &(sponsor.into()),1020 u128::MAX,1021 ),1022 )1023 }1024}10251026type EvmSponsorshipHandler = (1027 pallet_unique::UniqueEthSponsorshipHandler<Runtime>,1028 pallet_evm_contract_helpers::HelpersContractSponsoring<Runtime>,1029);1030type SponsorshipHandler = (1031 pallet_unique::UniqueSponsorshipHandler<Runtime>,1032 1033 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,1034);10351036impl pallet_evm_transaction_payment::Config for Runtime {1037 type EvmSponsorshipHandler = EvmSponsorshipHandler;1038 type Currency = Balances;1039}10401041impl pallet_charge_transaction::Config for Runtime {1042 type SponsorshipHandler = SponsorshipHandler;1043}104410451046104710481049parameter_types! {1050 1051 pub const HelpersContractAddress: H160 = H160([1052 0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,1053 ]);1054}10551056impl pallet_evm_contract_helpers::Config for Runtime {1057 type ContractAddress = HelpersContractAddress;1058 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;1059}10601061construct_runtime!(1062 pub enum Runtime where1063 Block = Block,1064 NodeBlock = opaque::Block,1065 UncheckedExtrinsic = UncheckedExtrinsic1066 {1067 ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,1068 ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,10691070 Aura: pallet_aura::{Pallet, Config<T>} = 22,1071 AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23,10721073 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,1074 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,1075 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,1076 TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 33,1077 Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,1078 Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,1079 System: frame_system::{Pallet, Call, Storage, Config, Event<T>} = 36,1080 Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,1081 1082 10831084 1085 XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,1086 PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,1087 CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,1088 DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,10891090 1091 Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,1092 Unique: pallet_unique::{Pallet, Call, Storage, Event<T>} = 61,1093 Scheduler: pallet_unq_scheduler::{Pallet, Call, Storage, Event<T>} = 62,1094 1095 Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64,1096 1097 Common: pallet_common::{Pallet, Storage, Event<T>} = 66,1098 Fungible: pallet_fungible::{Pallet, Storage} = 67,1099 Refungible: pallet_refungible::{Pallet, Storage} = 68,1100 Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,11011102 1103 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,1104 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,11051106 EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,1107 EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage} = 151,1108 EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,1109 EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,1110 }1111);11121113pub struct TransactionConverter;11141115impl fp_rpc::ConvertTransaction<UncheckedExtrinsic> for TransactionConverter {1116 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic {1117 UncheckedExtrinsic::new_unsigned(1118 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),1119 )1120 }1121}11221123impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConverter {1124 fn convert_transaction(1125 &self,1126 transaction: pallet_ethereum::Transaction,1127 ) -> opaque::UncheckedExtrinsic {1128 let extrinsic = UncheckedExtrinsic::new_unsigned(1129 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),1130 );1131 let encoded = extrinsic.encode();1132 opaque::UncheckedExtrinsic::decode(&mut &encoded[..])1133 .expect("Encoded extrinsic is always valid")1134 }1135}113611371138pub type Address = sp_runtime::MultiAddress<AccountId, ()>;11391140pub type Header = generic::Header<BlockNumber, BlakeTwo256>;11411142pub type Block = generic::Block<Header, UncheckedExtrinsic>;11431144pub type SignedBlock = generic::SignedBlock<Block>;11451146pub type BlockId = generic::BlockId<Block>;11471148pub type SignedExtra = (1149 frame_system::CheckSpecVersion<Runtime>,1150 1151 frame_system::CheckGenesis<Runtime>,1152 frame_system::CheckEra<Runtime>,1153 frame_system::CheckNonce<Runtime>,1154 frame_system::CheckWeight<Runtime>,1155 pallet_charge_transaction::ChargeTransactionPayment<Runtime>,1156 1157);1158pub type SignedExtraScheduler = (1159 frame_system::CheckSpecVersion<Runtime>,1160 frame_system::CheckGenesis<Runtime>,1161 frame_system::CheckEra<Runtime>,1162 frame_system::CheckNonce<Runtime>,1163 frame_system::CheckWeight<Runtime>,1164 1165);11661167pub type UncheckedExtrinsic =1168 fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;11691170pub type CheckedExtrinsic = fp_self_contained::CheckedExtrinsic<AccountId, Call, SignedExtra, H160>;11711172pub type Executive = frame_executive::Executive<1173 Runtime,1174 Block,1175 frame_system::ChainContext<Runtime>,1176 Runtime,1177 AllPalletsReversedWithSystemFirst,1178>;11791180impl_opaque_keys! {1181 pub struct SessionKeys {1182 pub aura: Aura,1183 }1184}11851186impl fp_self_contained::SelfContainedCall for Call {1187 type SignedInfo = H160;11881189 fn is_self_contained(&self) -> bool {1190 match self {1191 Call::Ethereum(call) => call.is_self_contained(),1192 _ => false,1193 }1194 }11951196 fn check_self_contained(&self) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {1197 match self {1198 Call::Ethereum(call) => call.check_self_contained(),1199 _ => None,1200 }1201 }12021203 fn validate_self_contained(&self, info: &Self::SignedInfo) -> Option<TransactionValidity> {1204 match self {1205 Call::Ethereum(call) => call.validate_self_contained(info),1206 _ => None,1207 }1208 }12091210 fn pre_dispatch_self_contained(1211 &self,1212 info: &Self::SignedInfo,1213 ) -> Option<Result<(), TransactionValidityError>> {1214 match self {1215 Call::Ethereum(call) => call.pre_dispatch_self_contained(info),1216 _ => None,1217 }1218 }12191220 fn apply_self_contained(1221 self,1222 info: Self::SignedInfo,1223 ) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {1224 match self {1225 call @ Call::Ethereum(pallet_ethereum::Call::transact { .. }) => Some(call.dispatch(1226 Origin::from(pallet_ethereum::RawOrigin::EthereumTransaction(info)),1227 )),1228 _ => None,1229 }1230 }1231}12321233macro_rules! dispatch_unique_runtime {1234 ($collection:ident.$method:ident($($name:ident),*)) => {{1235 use pallet_unique::dispatch::Dispatched;12361237 let collection = Dispatched::dispatch(<pallet_common::CollectionHandle<Runtime>>::try_get($collection)?);1238 let dispatch = collection.as_dyn();12391240 Ok(dispatch.$method($($name),*))1241 }};1242}12431244impl_common_runtime_apis!();12451246struct CheckInherents;12471248impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {1249 fn check_inherents(1250 block: &Block,1251 relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,1252 ) -> sp_inherents::CheckInherentsResult {1253 let relay_chain_slot = relay_state_proof1254 .read_slot()1255 .expect("Could not read the relay chain slot from the proof");12561257 let inherent_data =1258 cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(1259 relay_chain_slot,1260 sp_std::time::Duration::from_secs(6),1261 )1262 .create_inherent_data()1263 .expect("Could not create the timestamp inherent data");12641265 inherent_data.check_extrinsics(block)1266 }1267}12681269cumulus_pallet_parachain_system::register_validate_block!(1270 Runtime = Runtime,1271 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,1272 CheckInherents = CheckInherents,1273);