12345678#![cfg_attr(not(feature = "std"), no_std)]910#![recursion_limit = "1024"]11#![allow(clippy::from_over_into, clippy::identity_op)]12#![allow(clippy::fn_to_numeric_cast_with_truncation)]1314#[cfg(feature = "std")]15include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));1617use sp_api::impl_runtime_apis;18use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160};19202122use sp_runtime::{23 Permill, Perbill, Percent, create_runtime_str, generic, impl_opaque_keys,24 traits::{25 AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, Verify, AccountIdConversion,26 },27 transaction_validity::{TransactionSource, TransactionValidity},28 ApplyExtrinsicResult, MultiSignature,29};3031use sp_std::prelude::*;3233#[cfg(feature = "std")]34use sp_version::NativeVersion;35use sp_version::RuntimeVersion;36pub use pallet_transaction_payment::{37 Multiplier, TargetedFeeAdjustment, FeeDetails, RuntimeDispatchInfo,38};3940pub use pallet_balances::Call as BalancesCall;41pub use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping, Runner};42pub use frame_support::{43 construct_runtime, match_type,44 dispatch::DispatchResult,45 PalletId, parameter_types, StorageValue, ConsensusEngineId,46 traits::{47 Everything, Currency, ExistenceRequirement, Get, IsInVec, KeyOwnerProofSystem,48 LockIdentifier, OnUnbalanced, Randomness, FindAuthor,49 },50 weights::{51 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},52 DispatchClass, DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,53 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients,54 },55};56use nft_data_structs::*;575859use frame_system::{60 self as system, EnsureRoot, EnsureSigned,61 limits::{BlockWeights, BlockLength},62};63use sp_arithmetic::{64 traits::{BaseArithmetic, Unsigned},65};66use smallvec::smallvec;67use codec::{Encode, Decode};68use pallet_evm::{Account as EVMAccount, FeeCalculator, OnMethodCall};69use fp_rpc::TransactionStatus;70use sp_core::crypto::Public;71use sp_runtime::{72 traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf},73 transaction_validity::TransactionValidityError,74};757677pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;787980use pallet_xcm::XcmPassthrough;81use polkadot_parachain::primitives::Sibling;82use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*};83use xcm_builder::{84 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,85 EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset,86 ParentAsSuperuser, ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative,87 SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,88 SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,89};90use xcm_executor::{Config, XcmExecutor};919293949596pub type BlockNumber = u32;979899pub type Signature = MultiSignature;100101102103pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;104105pub type CrossAccountId = pallet_common::account::BasicCrossAccountId<Runtime>;106107108109pub type AccountIndex = u32;110111112pub type Balance = u128;113114115pub type Index = u32;116117118pub type Hash = sp_core::H256;119120121pub type DigestItem = generic::DigestItem<Hash>;122123124125126127pub mod opaque {128 use super::*;129130 pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;131132 133 pub type Block = generic::Block<Header, UncheckedExtrinsic>;134135 pub type SessionHandlers = ();136137 impl_opaque_keys! {138 pub struct SessionKeys {139 pub aura: Aura,140 }141 }142}143144145pub const VERSION: RuntimeVersion = RuntimeVersion {146 spec_name: create_runtime_str!("opal"),147 impl_name: create_runtime_str!("opal"),148 authoring_version: 1,149 spec_version: 912202,150 impl_version: 1,151 apis: RUNTIME_API_VERSIONS,152 transaction_version: 1,153};154155pub const MILLISECS_PER_BLOCK: u64 = 12000;156157pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;158159160pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);161pub const HOURS: BlockNumber = MINUTES * 60;162pub const DAYS: BlockNumber = HOURS * 24;163164parameter_types! {165 pub const DefaultSponsoringRateLimit: BlockNumber = 1 * DAYS;166}167168#[derive(codec::Encode, codec::Decode)]169pub enum XCMPMessage<XAccountId, XBalance> {170 171 TransferToken(XAccountId, XBalance),172}173174175#[cfg(feature = "std")]176pub fn native_version() -> NativeVersion {177 NativeVersion {178 runtime_version: VERSION,179 can_author_with: Default::default(),180 }181}182183type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;184185pub struct DealWithFees;186impl OnUnbalanced<NegativeImbalance> for DealWithFees {187 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {188 if let Some(fees) = fees_then_tips.next() {189 190 let mut split = fees.ration(100, 0);191 if let Some(tips) = fees_then_tips.next() {192 193 tips.ration_merge_into(100, 0, &mut split);194 }195 Treasury::on_unbalanced(split.0);196 197 }198 }199}200201202203const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);204205206const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);207208const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND / 2;209210parameter_types! {211 pub const BlockHashCount: BlockNumber = 2400;212 pub RuntimeBlockLength: BlockLength =213 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);214 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);215 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;216 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()217 .base_block(BlockExecutionWeight::get())218 .for_class(DispatchClass::all(), |weights| {219 weights.base_extrinsic = ExtrinsicBaseWeight::get();220 })221 .for_class(DispatchClass::Normal, |weights| {222 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);223 })224 .for_class(DispatchClass::Operational, |weights| {225 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);226 227 228 weights.reserved = Some(229 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT230 );231 })232 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)233 .build_or_panic();234 pub const Version: RuntimeVersion = VERSION;235 pub const SS58Prefix: u8 = 42;236}237238parameter_types! {239 pub const ChainId: u64 = 8888;240}241242pub struct FixedFee;243impl FeeCalculator for FixedFee {244 fn min_gas_price() -> U256 {245 1.into()246 }247}248249impl pallet_evm::Config for Runtime {250 type BlockGasLimit = BlockGasLimit;251 type FeeCalculator = FixedFee;252 type GasWeightMapping = ();253 type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;254 type CallOrigin = EnsureAddressTruncated;255 type WithdrawOrigin = EnsureAddressTruncated;256 type AddressMapping = HashedAddressMapping<Self::Hashing>;257 type Precompiles = ();258 type Currency = Balances;259 type Event = Event;260 type OnMethodCall = (261 pallet_evm_migration::OnMethodCall<Self>,262 pallet_nft::NftErcSupport<Self>,263 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,264 );265 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;266 type ChainId = ChainId;267 type Runner = pallet_evm::runner::stack::Runner<Self>;268 type OnChargeTransaction = pallet_evm_transaction_payment::OnChargeTransaction<Self>;269 type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;270 type FindAuthor = EthereumFindAuthor<Aura>;271}272273impl pallet_evm_migration::Config for Runtime {274 type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;275}276277pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);278impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {279 fn find_author<'a, I>(digests: I) -> Option<H160>280 where281 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,282 {283 if let Some(author_index) = F::find_author(digests) {284 let authority_id = Aura::authorities()[author_index as usize].clone();285 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));286 }287 None288 }289}290291parameter_types! {292 pub BlockGasLimit: U256 = U256::from(u32::max_value());293}294295impl pallet_ethereum::Config for Runtime {296 type Event = Event;297 type StateRoot = pallet_ethereum::IntermediateStateRoot;298 type EvmSubmitLog = pallet_evm::Pallet<Self>;299}300301impl pallet_randomness_collective_flip::Config for Runtime {}302303impl system::Config for Runtime {304 305 type AccountData = pallet_balances::AccountData<Balance>;306 307 type AccountId = AccountId;308 309 type BaseCallFilter = Everything;310 311 type BlockHashCount = BlockHashCount;312 313 type BlockLength = RuntimeBlockLength;314 315 type BlockNumber = BlockNumber;316 317 type BlockWeights = RuntimeBlockWeights;318 319 type Call = Call;320 321 type DbWeight = RocksDbWeight;322 323 type Event = Event;324 325 type Hash = Hash;326 327 type Hashing = BlakeTwo256;328 329 type Header = generic::Header<BlockNumber, BlakeTwo256>;330 331 type Index = Index;332 333 type Lookup = AccountIdLookup<AccountId, ()>;334 335 type OnKilledAccount = ();336 337 type OnNewAccount = ();338 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;339 340 type Origin = Origin;341 342 type PalletInfo = PalletInfo;343 344 type SS58Prefix = SS58Prefix;345 346 type SystemWeightInfo = system::weights::SubstrateWeight<Self>;347 348 type Version = Version;349}350351parameter_types! {352 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;353}354355impl pallet_timestamp::Config for Runtime {356 357 type Moment = u64;358 type OnTimestampSet = ();359 type MinimumPeriod = MinimumPeriod;360 type WeightInfo = ();361}362363parameter_types! {364 365 pub const ExistentialDeposit: u128 = 0;366 pub const MaxLocks: u32 = 50;367}368369impl pallet_balances::Config for Runtime {370 type MaxLocks = MaxLocks;371 type MaxReserves = ();372 type ReserveIdentifier = [u8; 8];373 374 type Balance = Balance;375 376 type Event = Event;377 type DustRemoval = Treasury;378 type ExistentialDeposit = ExistentialDeposit;379 type AccountStore = System;380 type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;381}382383pub const MICROUNIQUE: Balance = 1_000_000_000;384pub const MILLIUNIQUE: Balance = 1_000 * MICROUNIQUE;385pub const CENTIUNIQUE: Balance = 10 * MILLIUNIQUE;386pub const UNIQUE: Balance = 100 * CENTIUNIQUE;387388pub const fn deposit(items: u32, bytes: u32) -> Balance {389 items as Balance * 15 * CENTIUNIQUE + (bytes as Balance) * 6 * CENTIUNIQUE390}391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442parameter_types! {443 pub const TransactionByteFee: Balance = 501 * MICROUNIQUE; 444 445 446 pub const OperationalFeeMultiplier: u8 = 5;447}448449450pub struct LinearFee<T>(sp_std::marker::PhantomData<T>);451452impl<T> WeightToFeePolynomial for LinearFee<T>453where454 T: BaseArithmetic + From<u32> + Copy + Unsigned,455{456 type Balance = T;457458 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {459 smallvec!(WeightToFeeCoefficient {460 coeff_integer: 146_700u32.into(), 461 coeff_frac: Perbill::zero(),462 negative: false,463 degree: 1,464 })465 }466}467468impl pallet_transaction_payment::Config for Runtime {469 type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;470 type TransactionByteFee = TransactionByteFee;471 type OperationalFeeMultiplier = OperationalFeeMultiplier;472 type WeightToFee = LinearFee<Balance>;473 type FeeMultiplierUpdate = ();474}475476parameter_types! {477 pub const ProposalBond: Permill = Permill::from_percent(5);478 pub const ProposalBondMinimum: Balance = 1 * UNIQUE;479 pub const SpendPeriod: BlockNumber = 5 * MINUTES;480 pub const Burn: Permill = Permill::from_percent(0);481 pub const TipCountdown: BlockNumber = 1 * DAYS;482 pub const TipFindersFee: Percent = Percent::from_percent(20);483 pub const TipReportDepositBase: Balance = 1 * UNIQUE;484 pub const DataDepositPerByte: Balance = 1 * CENTIUNIQUE;485 pub const BountyDepositBase: Balance = 1 * UNIQUE;486 pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;487 pub const TreasuryModuleId: PalletId = PalletId(*b"py/trsry");488 pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;489 pub const MaximumReasonLength: u32 = 16384;490 pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);491 pub const BountyValueMinimum: Balance = 5 * UNIQUE;492 pub const MaxApprovals: u32 = 100;493}494495impl pallet_treasury::Config for Runtime {496 type PalletId = TreasuryModuleId;497 type Currency = Balances;498 type ApproveOrigin = EnsureRoot<AccountId>;499 type RejectOrigin = EnsureRoot<AccountId>;500 type Event = Event;501 type OnSlash = ();502 type ProposalBond = ProposalBond;503 type ProposalBondMinimum = ProposalBondMinimum;504 type SpendPeriod = SpendPeriod;505 type Burn = Burn;506 type BurnDestination = ();507 type SpendFunds = ();508 type WeightInfo = pallet_treasury::weights::SubstrateWeight<Self>;509 type MaxApprovals = MaxApprovals;510}511512impl pallet_sudo::Config for Runtime {513 type Event = Event;514 type Call = Call;515}516517pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);518519impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider520 for RelayChainBlockNumberProvider<T>521{522 type BlockNumber = BlockNumber;523524 fn current_block_number() -> Self::BlockNumber {525 cumulus_pallet_parachain_system::Pallet::<T>::validation_data()526 .map(|d| d.relay_parent_number)527 .unwrap_or_default()528 }529}530531parameter_types! {532 pub const MinVestedTransfer: Balance = 10 * UNIQUE;533 pub const MaxVestingSchedules: u32 = 28;534}535536impl orml_vesting::Config for Runtime {537 type Event = Event;538 type Currency = pallet_balances::Pallet<Runtime>;539 type MinVestedTransfer = MinVestedTransfer;540 type VestedTransferOrigin = EnsureSigned<AccountId>;541 type WeightInfo = ();542 type MaxVestingSchedules = MaxVestingSchedules;543 type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;544}545546parameter_types! {547 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;548 pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;549}550551impl cumulus_pallet_parachain_system::Config for Runtime {552 type Event = Event;553 type OnValidationData = ();554 type SelfParaId = parachain_info::Pallet<Self>;555 556 557 558 559 560 type OutboundXcmpMessageSource = XcmpQueue;561 type DmpMessageHandler = DmpQueue;562 type ReservedDmpWeight = ReservedDmpWeight;563 type ReservedXcmpWeight = ReservedXcmpWeight;564 type XcmpMessageHandler = XcmpQueue;565}566567impl parachain_info::Config for Runtime {}568569impl cumulus_pallet_aura_ext::Config for Runtime {}570571parameter_types! {572 pub const RelayLocation: MultiLocation = MultiLocation::parent();573 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;574 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();575 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();576}577578579580581pub type LocationToAccountId = (582 583 ParentIsDefault<AccountId>,584 585 SiblingParachainConvertsVia<Sibling, AccountId>,586 587 AccountId32Aliases<RelayNetwork, AccountId>,588);589590591pub type LocalAssetTransactor = CurrencyAdapter<592 593 Balances,594 595 IsConcrete<RelayLocation>,596 597 LocationToAccountId,598 599 AccountId,600 601 (),602>;603604605606607pub type XcmOriginToTransactDispatchOrigin = (608 609 610 611 SovereignSignedViaLocation<LocationToAccountId, Origin>,612 613 614 RelayChainAsNative<RelayOrigin, Origin>,615 616 617 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,618 619 620 ParentAsSuperuser<Origin>,621 622 623 SignedAccountId32AsNative<RelayNetwork, Origin>,624 625 XcmPassthrough<Origin>,626);627628parameter_types! {629 630 pub UnitWeightCost: Weight = 1_000_000;631 632 pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);633 pub const MaxInstructions: u32 = 100;634 pub const MaxAuthorities: u32 = 100_000;635}636637match_type! {638 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {639 MultiLocation { parents: 1, interior: Here } |640 MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }641 };642}643644pub type Barrier = (645 TakeWeightCredit,646 AllowTopLevelPaidExecutionFrom<Everything>,647 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,648 649);650651pub struct XcmConfig;652impl Config for XcmConfig {653 type Call = Call;654 type XcmSender = XcmRouter;655 656 type AssetTransactor = LocalAssetTransactor;657 type OriginConverter = XcmOriginToTransactDispatchOrigin;658 type IsReserve = NativeAsset;659 type IsTeleporter = (); 660 type LocationInverter = LocationInverter<Ancestry>;661 type Barrier = Barrier;662 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;663 type Trader = UsingComponents<IdentityFee<Balance>, RelayLocation, AccountId, Balances, ()>;664 type ResponseHandler = (); 665 type SubscriptionService = PolkadotXcm;666667 type AssetTrap = PolkadotXcm;668 type AssetClaims = PolkadotXcm;669}670671672673674675676pub type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, RelayNetwork>,);677678679680pub type XcmRouter = (681 682 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,683 684 XcmpQueue,685);686687impl pallet_evm_coder_substrate::Config for Runtime {688 type EthereumTransactionSender = pallet_ethereum::Pallet<Self>;689}690691impl pallet_xcm::Config for Runtime {692 type Event = Event;693 type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;694 type XcmRouter = XcmRouter;695 type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;696 type XcmExecuteFilter = Everything;697 type XcmExecutor = XcmExecutor<XcmConfig>;698 type XcmTeleportFilter = Everything;699 type XcmReserveTransferFilter = Everything;700 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;701 type LocationInverter = LocationInverter<Ancestry>;702 type Origin = Origin;703 type Call = Call;704 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;705 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;706}707708impl cumulus_pallet_xcm::Config for Runtime {709 type Event = Event;710 type XcmExecutor = XcmExecutor<XcmConfig>;711}712713impl cumulus_pallet_xcmp_queue::Config for Runtime {714 type Event = Event;715 type XcmExecutor = XcmExecutor<XcmConfig>;716 type ChannelInfo = ParachainSystem;717 type VersionWrapper = ();718}719720impl cumulus_pallet_dmp_queue::Config for Runtime {721 type Event = Event;722 type XcmExecutor = XcmExecutor<XcmConfig>;723 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;724}725726impl pallet_aura::Config for Runtime {727 type AuthorityId = AuraId;728 type DisabledValidators = ();729 type MaxAuthorities = MaxAuthorities;730}731732parameter_types! {733 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();734 pub const CollectionCreationPrice: Balance = 100 * UNIQUE;735}736737impl pallet_common::Config for Runtime {738 type Event = Event;739 type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;740 type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;741 type CrossAccountId = pallet_common::account::BasicCrossAccountId<Self>;742743 type Currency = Balances;744 type CollectionCreationPrice = CollectionCreationPrice;745 type TreasuryAccountId = TreasuryAccountId;746}747748impl pallet_fungible::Config for Runtime {749 type WeightInfo = pallet_fungible::weights::SubstrateWeight<Self>;750}751impl pallet_refungible::Config for Runtime {752 type WeightInfo = pallet_refungible::weights::SubstrateWeight<Self>;753}754impl pallet_nonfungible::Config for Runtime {755 type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;756}757758759impl pallet_nft::Config for Runtime {760 type WeightInfo = pallet_nft::weights::SubstrateWeight<Self>;761}762763parameter_types! {764 pub const InflationBlockInterval: BlockNumber = 100; 765}766767768impl pallet_inflation::Config for Runtime {769 type Currency = Balances;770 type TreasuryAccountId = TreasuryAccountId;771 type InflationBlockInterval = InflationBlockInterval;772}773774parameter_types! {775 pub MaximumSchedulerWeight: Weight = Perbill::from_percent(50) *776 RuntimeBlockWeights::get().max_block;777 pub const MaxScheduledPerBlock: u32 = 50;778}779780type EvmSponsorshipHandler = (781 pallet_nft::NftEthSponsorshipHandler<Runtime>,782 pallet_evm_contract_helpers::HelpersContractSponsoring<Runtime>,783);784type SponsorshipHandler = (785 pallet_nft::NftSponsorshipHandler<Runtime>,786 787 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,788);789790impl pallet_unq_scheduler::Config for Runtime {791 type Event = Event;792 type Origin = Origin;793 type PalletsOrigin = OriginCaller;794 type Call = Call;795 type MaximumWeight = MaximumSchedulerWeight;796 type ScheduleOrigin = EnsureSigned<AccountId>;797 type MaxScheduledPerBlock = MaxScheduledPerBlock;798 type SponsorshipHandler = SponsorshipHandler;799 type WeightInfo = ();800}801802impl pallet_evm_transaction_payment::Config for Runtime {803 type EvmSponsorshipHandler = EvmSponsorshipHandler;804 type Currency = Balances;805 type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;806 type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;807}808809impl pallet_nft_charge_transaction::Config for Runtime {810 type SponsorshipHandler = SponsorshipHandler;811}812813814815816817parameter_types! {818 819 pub const HelpersContractAddress: H160 = H160([820 0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,821 ]);822}823824impl pallet_evm_contract_helpers::Config for Runtime {825 type ContractAddress = HelpersContractAddress;826 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;827}828829construct_runtime!(830 pub enum Runtime where831 Block = Block,832 NodeBlock = opaque::Block,833 UncheckedExtrinsic = UncheckedExtrinsic834 {835 ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,836 ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,837838 Aura: pallet_aura::{Pallet, Config<T>} = 22,839 AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23,840841 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,842 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,843 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,844 TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 33,845 Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,846 Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,847 System: system::{Pallet, Call, Storage, Config, Event<T>} = 36,848 Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,849 850 851852 853 XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,854 PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,855 CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,856 DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,857858 859 Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,860 Nft: pallet_nft::{Pallet, Call, Storage} = 61,861 Scheduler: pallet_unq_scheduler::{Pallet, Call, Storage, Event<T>} = 62,862 863 Charging: pallet_nft_charge_transaction::{Pallet, Call, Storage } = 64,864 865 Common: pallet_common::{Pallet, Storage, Event<T>} = 66,866 Fungible: pallet_fungible::{Pallet, Storage} = 67,867 Refungible: pallet_refungible::{Pallet, Storage} = 68,868 Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,869870 871 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,872 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,873874 EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,875 EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage} = 151,876 EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,877 EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,878 }879);880881pub struct TransactionConverter;882883impl fp_rpc::ConvertTransaction<UncheckedExtrinsic> for TransactionConverter {884 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic {885 UncheckedExtrinsic::new_unsigned(886 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),887 )888 }889}890891impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConverter {892 fn convert_transaction(893 &self,894 transaction: pallet_ethereum::Transaction,895 ) -> opaque::UncheckedExtrinsic {896 let extrinsic = UncheckedExtrinsic::new_unsigned(897 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),898 );899 let encoded = extrinsic.encode();900 opaque::UncheckedExtrinsic::decode(&mut &encoded[..])901 .expect("Encoded extrinsic is always valid")902 }903}904905906pub type Address = sp_runtime::MultiAddress<AccountId, ()>;907908pub type Header = generic::Header<BlockNumber, BlakeTwo256>;909910pub type Block = generic::Block<Header, UncheckedExtrinsic>;911912pub type SignedBlock = generic::SignedBlock<Block>;913914pub type BlockId = generic::BlockId<Block>;915916pub type SignedExtra = (917 system::CheckSpecVersion<Runtime>,918 919 system::CheckGenesis<Runtime>,920 system::CheckEra<Runtime>,921 system::CheckNonce<Runtime>,922 system::CheckWeight<Runtime>,923 pallet_nft_charge_transaction::ChargeTransactionPayment<Runtime>,924 925);926927pub type UncheckedExtrinsic =928 fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;929930pub type CheckedExtrinsic = fp_self_contained::CheckedExtrinsic<AccountId, Call, SignedExtra, H160>;931932pub type Executive = frame_executive::Executive<933 Runtime,934 Block,935 frame_system::ChainContext<Runtime>,936 Runtime,937 AllPallets,938>;939940impl_opaque_keys! {941 pub struct SessionKeys {942 pub aura: Aura,943 }944}945946impl fp_self_contained::SelfContainedCall for Call {947 type SignedInfo = H160;948949 fn is_self_contained(&self) -> bool {950 match self {951 Call::Ethereum(call) => call.is_self_contained(),952 _ => false,953 }954 }955956 fn check_self_contained(&self) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {957 match self {958 Call::Ethereum(call) => call.check_self_contained(),959 _ => None,960 }961 }962963 fn validate_self_contained(&self, info: &Self::SignedInfo) -> Option<TransactionValidity> {964 match self {965 Call::Ethereum(call) => call.validate_self_contained(info),966 _ => None,967 }968 }969970 fn pre_dispatch_self_contained(971 &self,972 info: &Self::SignedInfo,973 ) -> Option<Result<(), TransactionValidityError>> {974 match self {975 Call::Ethereum(call) => call.pre_dispatch_self_contained(info),976 _ => None,977 }978 }979980 fn apply_self_contained(981 self,982 info: Self::SignedInfo,983 ) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {984 match self {985 call @ Call::Ethereum(pallet_ethereum::Call::transact { .. }) => Some(call.dispatch(986 Origin::from(pallet_ethereum::RawOrigin::EthereumTransaction(info)),987 )),988 _ => None,989 }990 }991}992993macro_rules! dispatch_nft_runtime {994 ($collection:ident.$method:ident($($name:ident),*)) => {{995 use pallet_nft::dispatch::Dispatched;996997 let collection = Dispatched::dispatch(<pallet_common::CollectionHandle<Runtime>>::new($collection).unwrap());998 let dispatch = collection.as_dyn();9991000 dispatch.$method($($name),*)1001 }};1002}1003impl_runtime_apis! {1004 impl up_rpc::NftApi<Block, CrossAccountId, AccountId>1005 for Runtime1006 {1007 fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec<TokenId> {1008 dispatch_nft_runtime!(collection.account_tokens(account))1009 }1010 fn token_exists(collection: CollectionId, token: TokenId) -> bool {1011 dispatch_nft_runtime!(collection.token_exists(token))1012 }10131014 fn token_owner(collection: CollectionId, token: TokenId) -> CrossAccountId {1015 dispatch_nft_runtime!(collection.token_owner(token))1016 }1017 fn const_metadata(collection: CollectionId, token: TokenId) -> Vec<u8> {1018 dispatch_nft_runtime!(collection.const_metadata(token))1019 }1020 fn variable_metadata(collection: CollectionId, token: TokenId) -> Vec<u8> {1021 dispatch_nft_runtime!(collection.variable_metadata(token))1022 }10231024 fn collection_tokens(collection: CollectionId) -> u32 {1025 dispatch_nft_runtime!(collection.collection_tokens())1026 }1027 fn account_balance(collection: CollectionId, account: CrossAccountId) -> u32 {1028 dispatch_nft_runtime!(collection.account_balance(account))1029 }1030 fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> u128 {1031 dispatch_nft_runtime!(collection.balance(account, token))1032 }1033 fn allowance(1034 collection: CollectionId,1035 sender: CrossAccountId,1036 spender: CrossAccountId,1037 token: TokenId,1038 ) -> u128 {1039 dispatch_nft_runtime!(collection.allowance(sender, spender, token))1040 }10411042 fn eth_contract_code(account: H160) -> Option<Vec<u8>> {1043 <pallet_nft::NftErcSupport<Runtime>>::get_code(&account)1044 .or_else(|| <pallet_evm_migration::OnMethodCall<Runtime>>::get_code(&account))1045 .or_else(|| <pallet_evm_contract_helpers::HelpersOnMethodCall<Self>>::get_code(&account))1046 }1047 fn adminlist(collection: CollectionId) -> Vec<CrossAccountId> {1048 <pallet_nft::Pallet<Runtime>>::adminlist(collection)1049 }1050 fn allowlist(collection: CollectionId) -> Vec<CrossAccountId> {1051 <pallet_nft::Pallet<Runtime>>::allowlist(collection)1052 }1053 fn last_token_id(collection: CollectionId) -> TokenId {1054 dispatch_nft_runtime!(collection.last_token_id())1055 }1056 }10571058 impl sp_api::Core<Block> for Runtime {1059 fn version() -> RuntimeVersion {1060 VERSION1061 }10621063 fn execute_block(block: Block) {1064 Executive::execute_block(block)1065 }10661067 fn initialize_block(header: &<Block as BlockT>::Header) {1068 Executive::initialize_block(header)1069 }1070 }10711072 impl sp_api::Metadata<Block> for Runtime {1073 fn metadata() -> OpaqueMetadata {1074 OpaqueMetadata::new(Runtime::metadata().into())1075 }1076 }10771078 impl sp_block_builder::BlockBuilder<Block> for Runtime {1079 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {1080 Executive::apply_extrinsic(extrinsic)1081 }10821083 fn finalize_block() -> <Block as BlockT>::Header {1084 Executive::finalize_block()1085 }10861087 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {1088 data.create_extrinsics()1089 }10901091 fn check_inherents(1092 block: Block,1093 data: sp_inherents::InherentData,1094 ) -> sp_inherents::CheckInherentsResult {1095 data.check_extrinsics(&block)1096 }10971098 1099 1100 1101 }11021103 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {1104 fn validate_transaction(1105 source: TransactionSource,1106 tx: <Block as BlockT>::Extrinsic,1107 hash: <Block as BlockT>::Hash,1108 ) -> TransactionValidity {1109 Executive::validate_transaction(source, tx, hash)1110 }1111 }11121113 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {1114 fn offchain_worker(header: &<Block as BlockT>::Header) {1115 Executive::offchain_worker(header)1116 }1117 }11181119 impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {1120 fn chain_id() -> u64 {1121 <Runtime as pallet_evm::Config>::ChainId::get()1122 }11231124 fn account_basic(address: H160) -> EVMAccount {1125 EVM::account_basic(&address)1126 }11271128 fn gas_price() -> U256 {1129 <Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price()1130 }11311132 fn account_code_at(address: H160) -> Vec<u8> {1133 EVM::account_codes(address)1134 }11351136 fn author() -> H160 {1137 <pallet_evm::Pallet<Runtime>>::find_author()1138 }11391140 fn storage_at(address: H160, index: U256) -> H256 {1141 let mut tmp = [0u8; 32];1142 index.to_big_endian(&mut tmp);1143 EVM::account_storages(address, H256::from_slice(&tmp[..]))1144 }11451146 fn call(1147 from: H160,1148 to: H160,1149 data: Vec<u8>,1150 value: U256,1151 gas_limit: U256,1152 gas_price: Option<U256>,1153 nonce: Option<U256>,1154 estimate: bool,1155 ) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {1156 let config = if estimate {1157 let mut config = <Runtime as pallet_evm::Config>::config().clone();1158 config.estimate = true;1159 Some(config)1160 } else {1161 None1162 };11631164 <Runtime as pallet_evm::Config>::Runner::call(1165 from,1166 to,1167 data,1168 value,1169 gas_limit.low_u64(),1170 gas_price,1171 nonce,1172 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),1173 ).map_err(|err| err.into())1174 }11751176 fn create(1177 from: H160,1178 data: Vec<u8>,1179 value: U256,1180 gas_limit: U256,1181 gas_price: Option<U256>,1182 nonce: Option<U256>,1183 estimate: bool,1184 ) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {1185 let config = if estimate {1186 let mut config = <Runtime as pallet_evm::Config>::config().clone();1187 config.estimate = true;1188 Some(config)1189 } else {1190 None1191 };11921193 <Runtime as pallet_evm::Config>::Runner::create(1194 from,1195 data,1196 value,1197 gas_limit.low_u64(),1198 gas_price,1199 nonce,1200 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),1201 ).map_err(|err| err.into())1202 }12031204 fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {1205 Ethereum::current_transaction_statuses()1206 }12071208 fn current_block() -> Option<pallet_ethereum::Block> {1209 Ethereum::current_block()1210 }12111212 fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {1213 Ethereum::current_receipts()1214 }12151216 fn current_all() -> (1217 Option<pallet_ethereum::Block>,1218 Option<Vec<pallet_ethereum::Receipt>>,1219 Option<Vec<TransactionStatus>>1220 ) {1221 (1222 Ethereum::current_block(),1223 Ethereum::current_receipts(),1224 Ethereum::current_transaction_statuses()1225 )1226 }12271228 fn extrinsic_filter(xts: Vec<<Block as sp_api::BlockT>::Extrinsic>) -> Vec<pallet_ethereum::Transaction> {1229 xts.into_iter().filter_map(|xt| match xt.0.function {1230 Call::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction),1231 _ => None1232 }).collect()1233 }1234 }12351236 impl sp_session::SessionKeys<Block> for Runtime {1237 fn decode_session_keys(1238 encoded: Vec<u8>,1239 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {1240 SessionKeys::decode_into_raw_public_keys(&encoded)1241 }12421243 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {1244 SessionKeys::generate(seed)1245 }1246 }12471248 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {1249 fn slot_duration() -> sp_consensus_aura::SlotDuration {1250 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())1251 }12521253 fn authorities() -> Vec<AuraId> {1254 Aura::authorities().to_vec()1255 }1256 }12571258 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {1259 fn collect_collation_info() -> cumulus_primitives_core::CollationInfo {1260 ParachainSystem::collect_collation_info()1261 }1262 }12631264 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {1265 fn account_nonce(account: AccountId) -> Index {1266 System::account_nonce(account)1267 }1268 }12691270 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {1271 fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {1272 TransactionPayment::query_info(uxt, len)1273 }1274 fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {1275 TransactionPayment::query_fee_details(uxt, len)1276 }1277 }12781279 12801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320 #[cfg(feature = "runtime-benchmarks")]1321 impl frame_benchmarking::Benchmark<Block> for Runtime {1322 fn benchmark_metadata(extra: bool) -> (1323 Vec<frame_benchmarking::BenchmarkList>,1324 Vec<frame_support::traits::StorageInfo>,1325 ) {1326 use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};1327 use frame_support::traits::StorageInfoTrait;13281329 let mut list = Vec::<BenchmarkList>::new();13301331 list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);1332 list_benchmark!(list, extra, pallet_nft, Nft);1333 list_benchmark!(list, extra, pallet_inflation, Inflation);1334 list_benchmark!(list, extra, pallet_fungible, Fungible);1335 list_benchmark!(list, extra, pallet_refungible, Refungible);1336 list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);13371338 let storage_info = AllPalletsWithSystem::storage_info();13391340 return (list, storage_info)1341 }13421343 fn dispatch_benchmark(1344 config: frame_benchmarking::BenchmarkConfig1345 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {1346 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};13471348 let allowlist: Vec<TrackedStorageKey> = vec![1349 1350 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),1351 1352 hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),1353 1354 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),1355 1356 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),1357 1358 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),1359 ];13601361 let mut batches = Vec::<BenchmarkBatch>::new();1362 let params = (&config, &allowlist);13631364 add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);1365 add_benchmark!(params, batches, pallet_nft, Nft);1366 add_benchmark!(params, batches, pallet_inflation, Inflation);1367 add_benchmark!(params, batches, pallet_fungible, Fungible);1368 add_benchmark!(params, batches, pallet_refungible, Refungible);1369 add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);13701371 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }1372 Ok(batches)1373 }1374 }1375}13761377struct CheckInherents;13781379impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {1380 fn check_inherents(1381 block: &Block,1382 relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,1383 ) -> sp_inherents::CheckInherentsResult {1384 let relay_chain_slot = relay_state_proof1385 .read_slot()1386 .expect("Could not read the relay chain slot from the proof");13871388 let inherent_data =1389 cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(1390 relay_chain_slot,1391 sp_std::time::Duration::from_secs(6),1392 )1393 .create_inherent_data()1394 .expect("Could not create the timestamp inherent data");13951396 inherent_data.check_extrinsics(block)1397 }1398}13991400cumulus_pallet_parachain_system::register_validate_block!(1401 Runtime = Runtime,1402 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,1403 CheckInherents = CheckInherents,1404);