12345678910111213141516171819#![cfg_attr(not(feature = "std"), no_std)]2021#![recursion_limit = "1024"]22#![allow(clippy::from_over_into, clippy::identity_op)]23#![allow(clippy::fn_to_numeric_cast_with_truncation)]2425#[cfg(feature = "std")]26include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));2728use sp_api::impl_runtime_apis;29use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160};30use sp_runtime::DispatchError;31323334use sp_runtime::{35 Permill, Perbill, Percent, create_runtime_str, generic, impl_opaque_keys,36 traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion, Zero},37 transaction_validity::{TransactionSource, TransactionValidity},38 ApplyExtrinsicResult, RuntimeAppPublic,39};4041use sp_std::prelude::*;4243#[cfg(feature = "std")]44use sp_version::NativeVersion;45use sp_version::RuntimeVersion;46pub use pallet_transaction_payment::{47 Multiplier, TargetedFeeAdjustment, FeeDetails, RuntimeDispatchInfo,48};4950pub use pallet_balances::Call as BalancesCall;51pub use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping, Runner};52pub use frame_support::{53 construct_runtime, match_type,54 dispatch::DispatchResult,55 PalletId, parameter_types, StorageValue, ConsensusEngineId,56 traits::{57 tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Everything,58 Currency, ExistenceRequirement, Get, IsInVec, KeyOwnerProofSystem, LockIdentifier,59 OnUnbalanced, Randomness, FindAuthor,60 },61 weights::{62 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},63 DispatchClass, DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,64 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients,65 },66};67use up_data_structs::*;686970use frame_system::{71 self as frame_system, EnsureRoot, EnsureSigned,72 limits::{BlockWeights, BlockLength},73};74use sp_arithmetic::{75 traits::{BaseArithmetic, Unsigned},76};77use smallvec::smallvec;78use codec::{Encode, Decode};79use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping, OnMethodCall};80use fp_rpc::TransactionStatus;81use sp_runtime::{82 traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating},83 transaction_validity::TransactionValidityError,84 SaturatedConversion,85};8687888990use pallet_xcm::XcmPassthrough;91use polkadot_parachain::primitives::Sibling;92use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*};93use xcm_builder::{94 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,95 EnsureXcmOrigin, FixedWeightBounds, LocationInverter, NativeAsset, ParentAsSuperuser,96 RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,97 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,98 ParentIsPreset,99};100use xcm_executor::{Config, XcmExecutor, Assets};101use sp_std::{marker::PhantomData};102103use xcm::latest::{104 105 AssetId::{Concrete},106 Fungibility::Fungible as XcmFungible,107 MultiAsset,108 Error as XcmError,109};110use xcm_executor::traits::{MatchesFungible, WeightTrader};111112use sp_runtime::traits::CheckedConversion;113114use unique_runtime_common::{impl_common_runtime_apis, types::*, constants::*};115116pub const RUNTIME_NAME: &str = "Unique";117118type CrossAccountId = pallet_common::account::BasicCrossAccountId<Runtime>;119120impl RuntimeInstance for Runtime {121 type CrossAccountId = self::CrossAccountId;122123 type TransactionConverter = self::TransactionConverter;124125 fn get_transaction_converter() -> TransactionConverter {126 TransactionConverter127 }128}129130131132133134pub mod opaque {135 use sp_std::prelude::*;136 use sp_runtime::impl_opaque_keys;137 use super::Aura;138139 pub use unique_runtime_common::types::*;140141 impl_opaque_keys! {142 pub struct SessionKeys {143 pub aura: Aura,144 }145 }146}147148149pub const VERSION: RuntimeVersion = RuntimeVersion {150 spec_name: create_runtime_str!(RUNTIME_NAME),151 impl_name: create_runtime_str!(RUNTIME_NAME),152 authoring_version: 1,153 spec_version: 917004,154 impl_version: 0,155 apis: RUNTIME_API_VERSIONS,156 transaction_version: 1,157 state_version: 0,158};159160#[derive(codec::Encode, codec::Decode)]161pub enum XCMPMessage<XAccountId, XBalance> {162 163 TransferToken(XAccountId, XBalance),164}165166167#[cfg(feature = "std")]168pub fn native_version() -> NativeVersion {169 NativeVersion {170 runtime_version: VERSION,171 can_author_with: Default::default(),172 }173}174175type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;176177pub struct DealWithFees;178impl OnUnbalanced<NegativeImbalance> for DealWithFees {179 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {180 if let Some(fees) = fees_then_tips.next() {181 182 let mut split = fees.ration(100, 0);183 if let Some(tips) = fees_then_tips.next() {184 185 tips.ration_merge_into(100, 0, &mut split);186 }187 Treasury::on_unbalanced(split.0);188 189 }190 }191}192193parameter_types! {194 pub const BlockHashCount: BlockNumber = 2400;195 pub RuntimeBlockLength: BlockLength =196 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);197 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);198 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;199 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()200 .base_block(BlockExecutionWeight::get())201 .for_class(DispatchClass::all(), |weights| {202 weights.base_extrinsic = ExtrinsicBaseWeight::get();203 })204 .for_class(DispatchClass::Normal, |weights| {205 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);206 })207 .for_class(DispatchClass::Operational, |weights| {208 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);209 210 211 weights.reserved = Some(212 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT213 );214 })215 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)216 .build_or_panic();217 pub const Version: RuntimeVersion = VERSION;218 pub const SS58Prefix: u16 = 7391;219}220221parameter_types! {222 pub const ChainId: u64 = 8880;223}224225pub struct FixedFee;226impl FeeCalculator for FixedFee {227 fn min_gas_price() -> U256 {228 229 1_018_751_825_264u64.into()230 }231}232233234235236parameter_types! {237 pub const WritesPerSecond: u64 = WEIGHT_PER_SECOND / <Runtime as frame_system::Config>::DbWeight::get().write;238 pub const GasPerSecond: u64 = WritesPerSecond::get() * 20000;239 pub const WeightPerGas: u64 = WEIGHT_PER_SECOND / GasPerSecond::get();240}241242243244245const EVM_DISPATCH_RATIO: Perbill = Perbill::from_percent(50);246parameter_types! {247 pub BlockGasLimit: U256 = U256::from(NORMAL_DISPATCH_RATIO * EVM_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT / WeightPerGas::get());248}249250pub enum FixedGasWeightMapping {}251impl GasWeightMapping for FixedGasWeightMapping {252 fn gas_to_weight(gas: u64) -> Weight {253 gas.saturating_mul(WeightPerGas::get())254 }255 fn weight_to_gas(weight: Weight) -> u64 {256 weight / WeightPerGas::get()257 }258}259260impl pallet_evm::Config for Runtime {261 type BlockGasLimit = BlockGasLimit;262 type FeeCalculator = FixedFee;263 type GasWeightMapping = FixedGasWeightMapping;264 type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;265 type CallOrigin = EnsureAddressTruncated;266 type WithdrawOrigin = EnsureAddressTruncated;267 type AddressMapping = HashedAddressMapping<Self::Hashing>;268 type PrecompilesType = ();269 type PrecompilesValue = ();270 type Currency = Balances;271 type Event = Event;272 type OnMethodCall = (273 pallet_evm_migration::OnMethodCall<Self>,274 pallet_unique::UniqueErcSupport<Self>,275 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,276 );277 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;278 type ChainId = ChainId;279 type Runner = pallet_evm::runner::stack::Runner<Self>;280 type OnChargeTransaction = pallet_evm_transaction_payment::OnChargeTransaction<Self>;281 type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;282 type FindAuthor = EthereumFindAuthor<Aura>;283}284285impl pallet_evm_migration::Config for Runtime {286 type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;287}288289pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);290impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {291 fn find_author<'a, I>(digests: I) -> Option<H160>292 where293 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,294 {295 if let Some(author_index) = F::find_author(digests) {296 let authority_id = Aura::authorities()[author_index as usize].clone();297 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));298 }299 None300 }301}302303impl pallet_ethereum::Config for Runtime {304 type Event = Event;305 type StateRoot = pallet_ethereum::IntermediateStateRoot;306}307308impl pallet_randomness_collective_flip::Config for Runtime {}309310impl frame_system::Config for Runtime {311 312 type AccountData = pallet_balances::AccountData<Balance>;313 314 type AccountId = AccountId;315 316 type BaseCallFilter = Everything;317 318 type BlockHashCount = BlockHashCount;319 320 type BlockLength = RuntimeBlockLength;321 322 type BlockNumber = BlockNumber;323 324 type BlockWeights = RuntimeBlockWeights;325 326 type Call = Call;327 328 type DbWeight = RocksDbWeight;329 330 type Event = Event;331 332 type Hash = Hash;333 334 type Hashing = BlakeTwo256;335 336 type Header = generic::Header<BlockNumber, BlakeTwo256>;337 338 type Index = Index;339 340 type Lookup = AccountIdLookup<AccountId, ()>;341 342 type OnKilledAccount = ();343 344 type OnNewAccount = ();345 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;346 347 type Origin = Origin;348 349 type PalletInfo = PalletInfo;350 351 type SS58Prefix = SS58Prefix;352 353 type SystemWeightInfo = frame_system::weights::SubstrateWeight<Self>;354 355 type Version = Version;356 type MaxConsumers = ConstU32<16>;357}358359parameter_types! {360 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;361}362363impl pallet_timestamp::Config for Runtime {364 365 type Moment = u64;366 type OnTimestampSet = ();367 type MinimumPeriod = MinimumPeriod;368 type WeightInfo = ();369}370371parameter_types! {372 373 pub const ExistentialDeposit: u128 = 0;374 pub const MaxLocks: u32 = 50;375}376377impl pallet_balances::Config for Runtime {378 type MaxLocks = MaxLocks;379 type MaxReserves = ();380 type ReserveIdentifier = [u8; 8];381 382 type Balance = Balance;383 384 type Event = Event;385 type DustRemoval = Treasury;386 type ExistentialDeposit = ExistentialDeposit;387 type AccountStore = System;388 type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;389}390391pub const MICROUNIQUE: Balance = 1_000_000_000_000;392pub const MILLIUNIQUE: Balance = 1_000 * MICROUNIQUE;393pub const CENTIUNIQUE: Balance = 10 * MILLIUNIQUE;394pub const UNIQUE: Balance = 100 * CENTIUNIQUE;395396pub const fn deposit(items: u32, bytes: u32) -> Balance {397 items as Balance * 15 * CENTIUNIQUE + (bytes as Balance) * 6 * CENTIUNIQUE398}399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450parameter_types! {451 pub const TransactionByteFee: Balance = 501 * MICROUNIQUE; 452 453 454 pub const OperationalFeeMultiplier: u8 = 5;455}456457458pub struct LinearFee<T>(sp_std::marker::PhantomData<T>);459460impl<T> WeightToFeePolynomial for LinearFee<T>461where462 T: BaseArithmetic + From<u32> + Copy + Unsigned,463{464 type Balance = T;465466 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {467 smallvec!(WeightToFeeCoefficient {468 469 coeff_integer: 142_688_000u32.into(),470 coeff_frac: Perbill::zero(),471 negative: false,472 degree: 1,473 })474 }475}476477impl pallet_transaction_payment::Config for Runtime {478 type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;479 type TransactionByteFee = TransactionByteFee;480 type OperationalFeeMultiplier = OperationalFeeMultiplier;481 type WeightToFee = LinearFee<Balance>;482 type FeeMultiplierUpdate = ();483}484485parameter_types! {486 pub const ProposalBond: Permill = Permill::from_percent(5);487 pub const ProposalBondMinimum: Balance = 1 * UNIQUE;488 pub const ProposalBondMaximum: Balance = 1000 * UNIQUE;489 pub const SpendPeriod: BlockNumber = 5 * MINUTES;490 pub const Burn: Permill = Permill::from_percent(0);491 pub const TipCountdown: BlockNumber = 1 * DAYS;492 pub const TipFindersFee: Percent = Percent::from_percent(20);493 pub const TipReportDepositBase: Balance = 1 * UNIQUE;494 pub const DataDepositPerByte: Balance = 1 * CENTIUNIQUE;495 pub const BountyDepositBase: Balance = 1 * UNIQUE;496 pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;497 pub const TreasuryModuleId: PalletId = PalletId(*b"py/trsry");498 pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;499 pub const MaximumReasonLength: u32 = 16384;500 pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);501 pub const BountyValueMinimum: Balance = 5 * UNIQUE;502 pub const MaxApprovals: u32 = 100;503}504505impl pallet_treasury::Config for Runtime {506 type PalletId = TreasuryModuleId;507 type Currency = Balances;508 type ApproveOrigin = EnsureRoot<AccountId>;509 type RejectOrigin = EnsureRoot<AccountId>;510 type Event = Event;511 type OnSlash = ();512 type ProposalBond = ProposalBond;513 type ProposalBondMinimum = ProposalBondMinimum;514 type ProposalBondMaximum = ProposalBondMaximum;515 type SpendPeriod = SpendPeriod;516 type Burn = Burn;517 type BurnDestination = ();518 type SpendFunds = ();519 type WeightInfo = pallet_treasury::weights::SubstrateWeight<Self>;520 type MaxApprovals = MaxApprovals;521}522523impl pallet_sudo::Config for Runtime {524 type Event = Event;525 type Call = Call;526}527528pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);529530impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider531 for RelayChainBlockNumberProvider<T>532{533 type BlockNumber = BlockNumber;534535 fn current_block_number() -> Self::BlockNumber {536 cumulus_pallet_parachain_system::Pallet::<T>::validation_data()537 .map(|d| d.relay_parent_number)538 .unwrap_or_default()539 }540}541542parameter_types! {543 pub const MinVestedTransfer: Balance = 10 * UNIQUE;544 pub const MaxVestingSchedules: u32 = 28;545}546547impl orml_vesting::Config for Runtime {548 type Event = Event;549 type Currency = pallet_balances::Pallet<Runtime>;550 type MinVestedTransfer = MinVestedTransfer;551 type VestedTransferOrigin = EnsureSigned<AccountId>;552 type WeightInfo = ();553 type MaxVestingSchedules = MaxVestingSchedules;554 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;555}556557parameter_types! {558 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;559 pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;560}561562impl cumulus_pallet_parachain_system::Config for Runtime {563 type Event = Event;564 type SelfParaId = parachain_info::Pallet<Self>;565 type OnSystemEvent = ();566 567 568 569 570 571 type OutboundXcmpMessageSource = XcmpQueue;572 type DmpMessageHandler = DmpQueue;573 type ReservedDmpWeight = ReservedDmpWeight;574 type ReservedXcmpWeight = ReservedXcmpWeight;575 type XcmpMessageHandler = XcmpQueue;576}577578impl parachain_info::Config for Runtime {}579580impl cumulus_pallet_aura_ext::Config for Runtime {}581582parameter_types! {583 pub const RelayLocation: MultiLocation = MultiLocation::parent();584 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;585 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();586 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();587}588589590591592pub type LocationToAccountId = (593 594 ParentIsPreset<AccountId>,595 596 SiblingParachainConvertsVia<Sibling, AccountId>,597 598 AccountId32Aliases<RelayNetwork, AccountId>,599);600601pub struct OnlySelfCurrency;602impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {603 fn matches_fungible(a: &MultiAsset) -> Option<B> {604 match (&a.id, &a.fun) {605 (Concrete(_), XcmFungible(ref amount)) => CheckedConversion::checked_from(*amount),606 _ => None,607 }608 }609}610611612pub type LocalAssetTransactor = CurrencyAdapter<613 614 Balances,615 616 OnlySelfCurrency,617 618 LocationToAccountId,619 620 AccountId,621 622 (),623>;624625626627628pub type XcmOriginToTransactDispatchOrigin = (629 630 631 632 SovereignSignedViaLocation<LocationToAccountId, Origin>,633 634 635 RelayChainAsNative<RelayOrigin, Origin>,636 637 638 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,639 640 641 ParentAsSuperuser<Origin>,642 643 644 SignedAccountId32AsNative<RelayNetwork, Origin>,645 646 XcmPassthrough<Origin>,647);648649parameter_types! {650 651 pub UnitWeightCost: Weight = 1_000_000;652 653 pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);654 pub const MaxInstructions: u32 = 100;655 pub const MaxAuthorities: u32 = 100_000;656}657658match_type! {659 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {660 MultiLocation { parents: 1, interior: Here } |661 MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }662 };663}664665pub type Barrier = (666 TakeWeightCredit,667 AllowTopLevelPaidExecutionFrom<Everything>,668 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,669 670);671672pub struct UsingOnlySelfCurrencyComponents<673 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,674 AssetId: Get<MultiLocation>,675 AccountId,676 Currency: CurrencyT<AccountId>,677 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,678>(679 Weight,680 Currency::Balance,681 PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,682);683impl<684 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,685 AssetId: Get<MultiLocation>,686 AccountId,687 Currency: CurrencyT<AccountId>,688 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,689 > WeightTrader690 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>691{692 fn new() -> Self {693 Self(0, Zero::zero(), PhantomData)694 }695696 fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {697 let amount = WeightToFee::calc(&weight);698 let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;699700 701 let option1: xcm::v1::AssetId = Concrete(MultiLocation {702 parents: 1,703 interior: X1(Parachain(ParachainInfo::parachain_id().into())),704 });705 706 let option2: xcm::v1::AssetId = Concrete(MultiLocation {707 parents: 0,708 interior: Here,709 });710711 let required = if payment.fungible.contains_key(&option1) {712 (option1, u128_amount).into()713 } else if payment.fungible.contains_key(&option2) {714 (option2, u128_amount).into()715 } else {716 (Concrete(MultiLocation::default()), u128_amount).into()717 };718719 let unused = payment720 .checked_sub(required)721 .map_err(|_| XcmError::TooExpensive)?;722 self.0 = self.0.saturating_add(weight);723 self.1 = self.1.saturating_add(amount);724 Ok(unused)725 }726727 fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {728 let weight = weight.min(self.0);729 let amount = WeightToFee::calc(&weight);730 self.0 -= weight;731 self.1 = self.1.saturating_sub(amount);732 let amount: u128 = amount.saturated_into();733 if amount > 0 {734 Some((AssetId::get(), amount).into())735 } else {736 None737 }738 }739}740impl<741 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,742 AssetId: Get<MultiLocation>,743 AccountId,744 Currency: CurrencyT<AccountId>,745 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,746 > Drop747 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>748{749 fn drop(&mut self) {750 OnUnbalanced::on_unbalanced(Currency::issue(self.1));751 }752}753754pub struct XcmConfig;755impl Config for XcmConfig {756 type Call = Call;757 type XcmSender = XcmRouter;758 759 type AssetTransactor = LocalAssetTransactor;760 type OriginConverter = XcmOriginToTransactDispatchOrigin;761 type IsReserve = NativeAsset;762 type IsTeleporter = (); 763 type LocationInverter = LocationInverter<Ancestry>;764 type Barrier = Barrier;765 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;766 type Trader = UsingOnlySelfCurrencyComponents<767 IdentityFee<Balance>,768 RelayLocation,769 AccountId,770 Balances,771 (),772 >;773 type ResponseHandler = (); 774 type SubscriptionService = PolkadotXcm;775776 type AssetTrap = PolkadotXcm;777 type AssetClaims = PolkadotXcm;778}779780781782783784785pub type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, RelayNetwork>,);786787788789pub type XcmRouter = (790 791 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,792 793 XcmpQueue,794);795796impl pallet_evm_coder_substrate::Config for Runtime {797 type EthereumTransactionSender = pallet_ethereum::Pallet<Self>;798 type GasWeightMapping = FixedGasWeightMapping;799}800801impl pallet_xcm::Config for Runtime {802 type Event = Event;803 type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;804 type XcmRouter = XcmRouter;805 type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;806 type XcmExecuteFilter = Everything;807 type XcmExecutor = XcmExecutor<XcmConfig>;808 type XcmTeleportFilter = Everything;809 type XcmReserveTransferFilter = Everything;810 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;811 type LocationInverter = LocationInverter<Ancestry>;812 type Origin = Origin;813 type Call = Call;814 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;815 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;816}817818impl cumulus_pallet_xcm::Config for Runtime {819 type Event = Event;820 type XcmExecutor = XcmExecutor<XcmConfig>;821}822823impl cumulus_pallet_xcmp_queue::Config for Runtime {824 type Event = Event;825 type XcmExecutor = XcmExecutor<XcmConfig>;826 type ChannelInfo = ParachainSystem;827 type VersionWrapper = ();828 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;829 type ControllerOrigin = EnsureRoot<AccountId>;830 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;831}832833impl cumulus_pallet_dmp_queue::Config for Runtime {834 type Event = Event;835 type XcmExecutor = XcmExecutor<XcmConfig>;836 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;837}838839impl pallet_aura::Config for Runtime {840 type AuthorityId = AuraId;841 type DisabledValidators = ();842 type MaxAuthorities = MaxAuthorities;843}844845parameter_types! {846 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();847 pub const CollectionCreationPrice: Balance = 2 * UNIQUE;848}849850impl pallet_common::Config for Runtime {851 type Event = Event;852 type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;853 type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;854 type CrossAccountId = pallet_common::account::BasicCrossAccountId<Self>;855856 type Currency = Balances;857 type CollectionCreationPrice = CollectionCreationPrice;858 type TreasuryAccountId = TreasuryAccountId;859}860861impl pallet_fungible::Config for Runtime {862 type WeightInfo = pallet_fungible::weights::SubstrateWeight<Self>;863}864impl pallet_refungible::Config for Runtime {865 type WeightInfo = pallet_refungible::weights::SubstrateWeight<Self>;866}867impl pallet_nonfungible::Config for Runtime {868 type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;869}870871impl pallet_unique::Config for Runtime {872 type Event = Event;873 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;874}875876parameter_types! {877 pub const InflationBlockInterval: BlockNumber = 100; 878}879880881impl pallet_inflation::Config for Runtime {882 type Currency = Balances;883 type TreasuryAccountId = TreasuryAccountId;884 type InflationBlockInterval = InflationBlockInterval;885 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;886}887888889890891892893894type EvmSponsorshipHandler = (895 pallet_unique::UniqueEthSponsorshipHandler<Runtime>,896 pallet_evm_contract_helpers::HelpersContractSponsoring<Runtime>,897);898type SponsorshipHandler = (899 pallet_unique::UniqueSponsorshipHandler<Runtime>,900 901 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,902);903904905906907908909910911912913914915916impl pallet_evm_transaction_payment::Config for Runtime {917 type EvmSponsorshipHandler = EvmSponsorshipHandler;918 type Currency = Balances;919 type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;920 type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;921}922923impl pallet_charge_transaction::Config for Runtime {924 type SponsorshipHandler = SponsorshipHandler;925}926927928929930931parameter_types! {932 933 pub const HelpersContractAddress: H160 = H160([934 0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,935 ]);936}937938impl pallet_evm_contract_helpers::Config for Runtime {939 type ContractAddress = HelpersContractAddress;940 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;941}942943construct_runtime!(944 pub enum Runtime where945 Block = Block,946 NodeBlock = opaque::Block,947 UncheckedExtrinsic = UncheckedExtrinsic948 {949 ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,950 ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,951952 Aura: pallet_aura::{Pallet, Config<T>} = 22,953 AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23,954955 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,956 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,957 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,958 TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 33,959 Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,960 Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,961 System: frame_system::{Pallet, Call, Storage, Config, Event<T>} = 36,962 Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,963 964 965966 967 XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,968 PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,969 CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,970 DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,971972 973 Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,974 Unique: pallet_unique::{Pallet, Call, Storage, Event<T>} = 61,975 976 977 Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64,978 979 Common: pallet_common::{Pallet, Storage, Event<T>} = 66,980 Fungible: pallet_fungible::{Pallet, Storage} = 67,981 Refungible: pallet_refungible::{Pallet, Storage} = 68,982 Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,983984 985 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,986 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,987988 EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,989 EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage} = 151,990 EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,991 EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,992 }993);994995pub struct TransactionConverter;996997impl fp_rpc::ConvertTransaction<UncheckedExtrinsic> for TransactionConverter {998 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic {999 UncheckedExtrinsic::new_unsigned(1000 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),1001 )1002 }1003}10041005impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConverter {1006 fn convert_transaction(1007 &self,1008 transaction: pallet_ethereum::Transaction,1009 ) -> opaque::UncheckedExtrinsic {1010 let extrinsic = UncheckedExtrinsic::new_unsigned(1011 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),1012 );1013 let encoded = extrinsic.encode();1014 opaque::UncheckedExtrinsic::decode(&mut &encoded[..])1015 .expect("Encoded extrinsic is always valid")1016 }1017}101810191020pub type Address = sp_runtime::MultiAddress<AccountId, ()>;10211022pub type Header = generic::Header<BlockNumber, BlakeTwo256>;10231024pub type Block = generic::Block<Header, UncheckedExtrinsic>;10251026pub type SignedBlock = generic::SignedBlock<Block>;10271028pub type BlockId = generic::BlockId<Block>;10291030pub type SignedExtra = (1031 frame_system::CheckSpecVersion<Runtime>,1032 1033 frame_system::CheckGenesis<Runtime>,1034 frame_system::CheckEra<Runtime>,1035 frame_system::CheckNonce<Runtime>,1036 frame_system::CheckWeight<Runtime>,1037 pallet_charge_transaction::ChargeTransactionPayment<Runtime>,1038 1039);10401041pub type UncheckedExtrinsic =1042 fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;10431044pub type CheckedExtrinsic = fp_self_contained::CheckedExtrinsic<AccountId, Call, SignedExtra, H160>;10451046pub type Executive = frame_executive::Executive<1047 Runtime,1048 Block,1049 frame_system::ChainContext<Runtime>,1050 Runtime,1051 AllPalletsReversedWithSystemFirst,1052>;10531054impl_opaque_keys! {1055 pub struct SessionKeys {1056 pub aura: Aura,1057 }1058}10591060impl fp_self_contained::SelfContainedCall for Call {1061 type SignedInfo = H160;10621063 fn is_self_contained(&self) -> bool {1064 match self {1065 Call::Ethereum(call) => call.is_self_contained(),1066 _ => false,1067 }1068 }10691070 fn check_self_contained(&self) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {1071 match self {1072 Call::Ethereum(call) => call.check_self_contained(),1073 _ => None,1074 }1075 }10761077 fn validate_self_contained(&self, info: &Self::SignedInfo) -> Option<TransactionValidity> {1078 match self {1079 Call::Ethereum(call) => call.validate_self_contained(info),1080 _ => None,1081 }1082 }10831084 fn pre_dispatch_self_contained(1085 &self,1086 info: &Self::SignedInfo,1087 ) -> Option<Result<(), TransactionValidityError>> {1088 match self {1089 Call::Ethereum(call) => call.pre_dispatch_self_contained(info),1090 _ => None,1091 }1092 }10931094 fn apply_self_contained(1095 self,1096 info: Self::SignedInfo,1097 ) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {1098 match self {1099 call @ Call::Ethereum(pallet_ethereum::Call::transact { .. }) => Some(call.dispatch(1100 Origin::from(pallet_ethereum::RawOrigin::EthereumTransaction(info)),1101 )),1102 _ => None,1103 }1104 }1105}11061107macro_rules! dispatch_unique_runtime {1108 ($collection:ident.$method:ident($($name:ident),*)) => {{1109 use pallet_unique::dispatch::Dispatched;11101111 let collection = Dispatched::dispatch(<pallet_common::CollectionHandle<Runtime>>::try_get($collection)?);1112 let dispatch = collection.as_dyn();11131114 Ok(dispatch.$method($($name),*))1115 }};1116}11171118impl_common_runtime_apis!();11191120struct CheckInherents;11211122impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {1123 fn check_inherents(1124 block: &Block,1125 relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,1126 ) -> sp_inherents::CheckInherentsResult {1127 let relay_chain_slot = relay_state_proof1128 .read_slot()1129 .expect("Could not read the relay chain slot from the proof");11301131 let inherent_data =1132 cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(1133 relay_chain_slot,1134 sp_std::time::Duration::from_secs(6),1135 )1136 .create_inherent_data()1137 .expect("Could not create the timestamp inherent data");11381139 inherent_data.check_extrinsics(block)1140 }1141}11421143cumulus_pallet_parachain_system::register_validate_block!(1144 Runtime = Runtime,1145 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,1146 CheckInherents = CheckInherents,1147);