pallet_staking_async_rc_runtime/
lib.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Substrate.
3
4// Substrate is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Substrate is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Substrate.  If not, see <http://www.gnu.org/licenses/>.
16
17//! The Westend runtime. This can be compiled with `#[no_std]`, ready for Wasm.
18
19#![cfg_attr(not(feature = "std"), no_std)]
20// `#[frame_support::runtime]!` does a lot of recursion and requires us to increase the limit.
21#![recursion_limit = "512"]
22
23extern crate alloc;
24
25use alloc::{
26	collections::{btree_map::BTreeMap, vec_deque::VecDeque},
27	vec,
28	vec::Vec,
29};
30use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
31use frame_election_provider_support::{
32	bounds::ElectionBoundsBuilder, onchain, SequentialPhragmen, VoteWeight,
33};
34use frame_support::{
35	derive_impl,
36	dynamic_params::{dynamic_pallet_params, dynamic_params},
37	genesis_builder_helper::{build_state, get_preset},
38	parameter_types,
39	traits::{
40		fungible::HoldConsideration, tokens::UnityOrOuterConversion, ConstBool, ConstU32, Contains,
41		EitherOf, EitherOfDiverse, EnsureOriginWithArg, EverythingBut, FromContains,
42		InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, Nothing, ProcessMessage,
43		ProcessMessageError, VariantCountOf, WithdrawReasons,
44	},
45	weights::{ConstantMultiplier, WeightMeter, WeightToFee as _},
46	PalletId,
47};
48pub use frame_system::Call as SystemCall;
49use frame_system::{EnsureRoot, EnsureSigned};
50pub use pallet_balances::Call as BalancesCall;
51use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId};
52use pallet_identity::legacy::IdentityInfo;
53use pallet_session::historical as session_historical;
54use pallet_staking_async_ah_client::{self as ah_client};
55use pallet_staking_async_rc_client::{self as rc_client};
56pub use pallet_timestamp::Call as TimestampCall;
57use pallet_transaction_payment::{FeeDetails, FungibleAdapter, RuntimeDispatchInfo};
58use polkadot_primitives::{
59	slashing,
60	vstaging::{
61		async_backing::Constraints, CandidateEvent,
62		CommittedCandidateReceiptV2 as CommittedCandidateReceipt, CoreState, ScrapedOnChainVotes,
63	},
64	AccountId, AccountIndex, ApprovalVotingParams, Balance, BlockNumber, CandidateHash, CoreIndex,
65	DisputeState, ExecutorParams, GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage,
66	InboundHrmpMessage, Moment, NodeFeatures, Nonce, OccupiedCoreAssumption,
67	PersistedValidationData, PvfCheckStatement, SessionInfo, Signature, ValidationCode,
68	ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature, PARACHAIN_KEY_TYPE_ID,
69};
70use polkadot_runtime_common::{
71	assigned_slots, auctions, crowdloan, identity_migrator, impl_runtime_weights,
72	impls::{
73		ContainsParts, LocatableAssetConverter, ToAuthor, VersionedLocatableAsset,
74		VersionedLocationConverter,
75	},
76	paras_registrar, paras_sudo_wrapper, prod_or_fast, slots,
77	traits::OnSwap,
78	BlockHashCount, BlockLength, SlowAdjustingFeeUpdate,
79};
80use polkadot_runtime_parachains::{
81	assigner_coretime as parachains_assigner_coretime, configuration as parachains_configuration,
82	configuration::ActiveConfigHrmpChannelSizeAndCapacityRatio,
83	coretime, disputes as parachains_disputes,
84	disputes::slashing as parachains_slashing,
85	dmp as parachains_dmp, hrmp as parachains_hrmp, inclusion as parachains_inclusion,
86	inclusion::{AggregateMessageOrigin, UmpQueueId},
87	initializer as parachains_initializer, on_demand as parachains_on_demand,
88	origin as parachains_origin, paras as parachains_paras,
89	paras_inherent as parachains_paras_inherent, reward_points as parachains_reward_points,
90	runtime_api_impl::{
91		v11 as parachains_runtime_api_impl, vstaging as parachains_staging_runtime_api_impl,
92	},
93	scheduler as parachains_scheduler, session_info as parachains_session_info,
94	shared as parachains_shared,
95};
96use scale_info::TypeInfo;
97use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
98use sp_consensus_beefy::{
99	ecdsa_crypto::{AuthorityId as BeefyId, Signature as BeefySignature},
100	mmr::{BeefyDataProvider, MmrLeafVersion},
101};
102use sp_core::{ConstU8, ConstUint, OpaqueMetadata, RuntimeDebug, H256};
103#[cfg(any(feature = "std", test))]
104pub use sp_runtime::BuildStorage;
105use sp_runtime::{
106	generic, impl_opaque_keys,
107	traits::{
108		AccountIdConversion, BlakeTwo256, Block as BlockT, Convert, ConvertInto, Get,
109		IdentityLookup, Keccak256, OpaqueKeys, SaturatedConversion, Verify,
110	},
111	transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
112	ApplyExtrinsicResult, FixedU128, KeyTypeId, Percent, Permill,
113};
114use sp_staking::SessionIndex;
115#[cfg(any(feature = "std", test))]
116use sp_version::NativeVersion;
117use sp_version::RuntimeVersion;
118use xcm::{
119	latest::prelude::*, VersionedAsset, VersionedAssetId, VersionedAssets, VersionedLocation,
120	VersionedXcm,
121};
122use xcm_builder::PayOverXcm;
123use xcm_runtime_apis::{
124	dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
125	fees::Error as XcmPaymentApiError,
126};
127
128/// Constant values used within the runtime.
129use pallet_staking_async_rc_runtime_constants::{
130	currency::*,
131	fee::*,
132	system_parachain::{coretime::TIMESLICE_PERIOD, ASSET_HUB_ID, BROKER_ID},
133	time::*,
134};
135
136pub mod pallet_reward_point_filler {
137	use frame_support::pallet_prelude::*;
138	use frame_system::pallet_prelude::*;
139
140	#[frame_support::pallet]
141	pub mod pallet {
142		use super::*;
143
144		#[pallet::config]
145		pub trait Config: frame_system::Config + pallet_staking_async_ah_client::Config {
146			type FillValidatorPointsTo: Get<u32>;
147		}
148
149		#[pallet::pallet]
150		pub struct Pallet<T>(_);
151
152		#[pallet::hooks]
153		impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T>
154		where
155			T::AccountId: From<[u8; 32]>,
156		{
157			fn on_initialize(_: BlockNumberFor<T>) -> Weight {
158				let current =
159					pallet_staking_async_ah_client::ValidatorPoints::<T>::iter().count() as u32;
160				if let Some(deficit) = T::FillValidatorPointsTo::get().checked_sub(current) {
161					for index in 0..deficit {
162						let unique = index.to_le_bytes();
163						let mut key = [0u8; 32];
164						// first 4 bytes should be `unique`, rest 0
165						key[..4].copy_from_slice(&unique);
166						pallet_staking_async_ah_client::ValidatorPoints::<T>::insert(
167							T::AccountId::from(key),
168							42,
169						);
170					}
171				}
172				Default::default()
173			}
174		}
175	}
176}
177
178impl pallet_reward_point_filler::pallet::Config for Runtime {
179	// we may have 2/4 validators by default, so let's fill it up to 994.
180	type FillValidatorPointsTo = ConstU32<994>;
181}
182
183mod genesis_config_presets;
184mod weights;
185pub mod xcm_config;
186
187// Implemented types.
188mod impls;
189use impls::ToParachainIdentityReaper;
190
191// Governance and configurations.
192pub mod governance;
193use governance::{
194	pallet_custom_origins, AuctionAdmin, FellowshipAdmin, GeneralAdmin, LeaseAdmin, StakingAdmin,
195	Treasurer, TreasurySpender,
196};
197
198#[cfg(test)]
199mod tests;
200
201impl_runtime_weights!(pallet_staking_async_rc_runtime_constants);
202
203// Make the WASM binary available.
204#[cfg(feature = "std")]
205include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
206
207#[cfg(feature = "std")]
208pub mod fast_runtime_binary {
209	include!(concat!(env!("OUT_DIR"), "/fast_runtime_binary.rs"));
210}
211
212/// Runtime version (Westend).
213#[sp_version::runtime_version]
214pub const VERSION: RuntimeVersion = RuntimeVersion {
215	spec_name: alloc::borrow::Cow::Borrowed("staking-async-rc"),
216	impl_name: alloc::borrow::Cow::Borrowed("staking-async-rc"),
217	authoring_version: 2,
218	spec_version: 1_017_001,
219	impl_version: 0,
220	apis: RUNTIME_API_VERSIONS,
221	transaction_version: 27,
222	system_version: 1,
223};
224
225/// The BABE epoch configuration at genesis.
226pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration =
227	sp_consensus_babe::BabeEpochConfiguration {
228		c: PRIMARY_PROBABILITY,
229		allowed_slots: sp_consensus_babe::AllowedSlots::PrimaryAndSecondaryVRFSlots,
230	};
231
232/// Native version.
233#[cfg(any(feature = "std", test))]
234pub fn native_version() -> NativeVersion {
235	NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
236}
237
238/// A type to identify calls to the Identity pallet. These will be filtered to prevent invocation,
239/// locking the state of the pallet and preventing further updates to identities and sub-identities.
240/// The locked state will be the genesis state of a new system chain and then removed from the Relay
241/// Chain.
242pub struct IsIdentityCall;
243impl Contains<RuntimeCall> for IsIdentityCall {
244	fn contains(c: &RuntimeCall) -> bool {
245		matches!(c, RuntimeCall::Identity(_))
246	}
247}
248
249parameter_types! {
250	pub const Version: RuntimeVersion = VERSION;
251	pub const SS58Prefix: u8 = 42;
252}
253
254#[derive_impl(frame_system::config_preludes::RelayChainDefaultConfig)]
255impl frame_system::Config for Runtime {
256	type BaseCallFilter = EverythingBut<IsIdentityCall>;
257	type BlockWeights = BlockWeights;
258	type BlockLength = BlockLength;
259	type Nonce = Nonce;
260	type Hash = Hash;
261	type AccountId = AccountId;
262	type Block = Block;
263	type BlockHashCount = BlockHashCount;
264	type DbWeight = RocksDbWeight;
265	type Version = Version;
266	type AccountData = pallet_balances::AccountData<Balance>;
267	type SystemWeightInfo = weights::frame_system::WeightInfo<Runtime>;
268	type ExtensionsWeightInfo = weights::frame_system_extensions::WeightInfo<Runtime>;
269	type SS58Prefix = SS58Prefix;
270	type MaxConsumers = frame_support::traits::ConstU32<16>;
271	type MultiBlockMigrator = MultiBlockMigrations;
272}
273
274parameter_types! {
275	pub MaximumSchedulerWeight: frame_support::weights::Weight = Perbill::from_percent(80) *
276		BlockWeights::get().max_block;
277	pub const MaxScheduledPerBlock: u32 = 50;
278	pub const NoPreimagePostponement: Option<u32> = Some(10);
279}
280
281impl pallet_scheduler::Config for Runtime {
282	type RuntimeOrigin = RuntimeOrigin;
283	type RuntimeEvent = RuntimeEvent;
284	type PalletsOrigin = OriginCaller;
285	type RuntimeCall = RuntimeCall;
286	type MaximumWeight = MaximumSchedulerWeight;
287	// The goal of having ScheduleOrigin include AuctionAdmin is to allow the auctions track of
288	// OpenGov to schedule periodic auctions.
289	type ScheduleOrigin = EitherOf<EnsureRoot<AccountId>, AuctionAdmin>;
290	type MaxScheduledPerBlock = MaxScheduledPerBlock;
291	type WeightInfo = weights::pallet_scheduler::WeightInfo<Runtime>;
292	type OriginPrivilegeCmp = frame_support::traits::EqualPrivilegeOnly;
293	type Preimages = Preimage;
294	type BlockNumberProvider = frame_system::Pallet<Runtime>;
295}
296
297parameter_types! {
298	pub const PreimageBaseDeposit: Balance = deposit(2, 64);
299	pub const PreimageByteDeposit: Balance = deposit(0, 1);
300	pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);
301}
302
303/// Dynamic params that can be adjusted at runtime.
304#[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::<Runtime>)]
305pub mod dynamic_params {
306	use super::*;
307
308	/// Parameters used to calculate era payouts, see
309	/// [`polkadot_runtime_common::impls::EraPayoutParams`].
310	#[dynamic_pallet_params]
311	#[codec(index = 0)]
312	pub mod inflation {
313		/// Minimum inflation rate used to calculate era payouts.
314		#[codec(index = 0)]
315		pub static MinInflation: Perquintill = Perquintill::from_rational(25u64, 1000u64);
316
317		/// Maximum inflation rate used to calculate era payouts.
318		#[codec(index = 1)]
319		pub static MaxInflation: Perquintill = Perquintill::from_rational(10u64, 100u64);
320
321		/// Ideal stake ratio used to calculate era payouts.
322		#[codec(index = 2)]
323		pub static IdealStake: Perquintill = Perquintill::from_rational(50u64, 100u64);
324
325		/// Falloff used to calculate era payouts.
326		#[codec(index = 3)]
327		pub static Falloff: Perquintill = Perquintill::from_rational(50u64, 1000u64);
328
329		/// Whether to use auction slots or not in the calculation of era payouts. If set to true,
330		/// the `legacy_auction_proportion` of 60% will be used in the calculation of era payouts.
331		#[codec(index = 4)]
332		pub static UseAuctionSlots: bool = false;
333	}
334}
335
336#[cfg(feature = "runtime-benchmarks")]
337impl Default for RuntimeParameters {
338	fn default() -> Self {
339		RuntimeParameters::Inflation(dynamic_params::inflation::Parameters::MinInflation(
340			dynamic_params::inflation::MinInflation,
341			Some(Perquintill::from_rational(25u64, 1000u64)),
342		))
343	}
344}
345
346impl pallet_parameters::Config for Runtime {
347	type RuntimeEvent = RuntimeEvent;
348	type RuntimeParameters = RuntimeParameters;
349	type AdminOrigin = DynamicParameterOrigin;
350	type WeightInfo = weights::pallet_parameters::WeightInfo<Runtime>;
351}
352
353/// Defines what origin can modify which dynamic parameters.
354pub struct DynamicParameterOrigin;
355impl EnsureOriginWithArg<RuntimeOrigin, RuntimeParametersKey> for DynamicParameterOrigin {
356	type Success = ();
357
358	fn try_origin(
359		origin: RuntimeOrigin,
360		key: &RuntimeParametersKey,
361	) -> Result<Self::Success, RuntimeOrigin> {
362		use crate::RuntimeParametersKey::*;
363
364		match key {
365			Inflation(_) => frame_system::ensure_root(origin.clone()),
366		}
367		.map_err(|_| origin)
368	}
369
370	#[cfg(feature = "runtime-benchmarks")]
371	fn try_successful_origin(_key: &RuntimeParametersKey) -> Result<RuntimeOrigin, ()> {
372		// Provide the origin for the parameter returned by `Default`:
373		Ok(RuntimeOrigin::root())
374	}
375}
376
377impl pallet_preimage::Config for Runtime {
378	type WeightInfo = weights::pallet_preimage::WeightInfo<Runtime>;
379	type RuntimeEvent = RuntimeEvent;
380	type Currency = Balances;
381	type ManagerOrigin = EnsureRoot<AccountId>;
382	type Consideration = HoldConsideration<
383		AccountId,
384		Balances,
385		PreimageHoldReason,
386		LinearStoragePrice<PreimageBaseDeposit, PreimageByteDeposit, Balance>,
387	>;
388}
389
390parameter_types! {
391	pub const EpochDuration: u64 = prod_or_fast!(
392		EPOCH_DURATION_IN_SLOTS as u64,
393		1 * MINUTES as u64
394	);
395	pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
396	pub const ReportLongevity: u64 = 256 * EpochDuration::get();
397}
398
399impl pallet_babe::Config for Runtime {
400	type EpochDuration = EpochDuration;
401	type ExpectedBlockTime = ExpectedBlockTime;
402
403	// session module is the trigger
404	type EpochChangeTrigger = pallet_babe::ExternalTrigger;
405
406	type DisabledValidators = Session;
407
408	type WeightInfo = ();
409
410	type MaxAuthorities = MaxAuthorities;
411	type MaxNominators = ConstU32<1024>;
412
413	type KeyOwnerProof = sp_session::MembershipProof;
414
415	type EquivocationReportSystem =
416		pallet_babe::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
417}
418
419parameter_types! {
420	pub const IndexDeposit: Balance = 100 * CENTS;
421}
422
423impl pallet_indices::Config for Runtime {
424	type AccountIndex = AccountIndex;
425	type Currency = Balances;
426	type Deposit = IndexDeposit;
427	type RuntimeEvent = RuntimeEvent;
428	type WeightInfo = weights::pallet_indices::WeightInfo<Runtime>;
429}
430
431parameter_types! {
432	pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT;
433	pub const MaxLocks: u32 = 50;
434	pub const MaxReserves: u32 = 50;
435}
436
437impl pallet_balances::Config for Runtime {
438	type Balance = Balance;
439	type DustRemoval = ();
440	type RuntimeEvent = RuntimeEvent;
441	type ExistentialDeposit = ExistentialDeposit;
442	type AccountStore = System;
443	type MaxLocks = MaxLocks;
444	type MaxReserves = MaxReserves;
445	type ReserveIdentifier = [u8; 8];
446	type WeightInfo = weights::pallet_balances::WeightInfo<Runtime>;
447	type RuntimeHoldReason = RuntimeHoldReason;
448	type RuntimeFreezeReason = RuntimeFreezeReason;
449	type FreezeIdentifier = RuntimeFreezeReason;
450	type MaxFreezes = VariantCountOf<RuntimeFreezeReason>;
451	type DoneSlashHandler = ();
452}
453
454parameter_types! {
455	pub const BeefySetIdSessionEntries: u32 = 1024;
456}
457
458impl pallet_beefy::Config for Runtime {
459	type BeefyId = BeefyId;
460	type MaxAuthorities = MaxAuthorities;
461	type MaxNominators = <Self as pallet_babe::Config>::MaxNominators;
462	type MaxSetIdSessionEntries = BeefySetIdSessionEntries;
463	type OnNewValidatorSet = BeefyMmrLeaf;
464	type AncestryHelper = BeefyMmrLeaf;
465	type WeightInfo = ();
466	type KeyOwnerProof = sp_session::MembershipProof;
467	type EquivocationReportSystem =
468		pallet_beefy::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
469}
470
471impl pallet_mmr::Config for Runtime {
472	const INDEXING_PREFIX: &'static [u8] = mmr::INDEXING_PREFIX;
473	type Hashing = Keccak256;
474	type OnNewRoot = pallet_beefy_mmr::DepositBeefyDigest<Runtime>;
475	type LeafData = pallet_beefy_mmr::Pallet<Runtime>;
476	type BlockHashProvider = pallet_mmr::DefaultBlockHashProvider<Runtime>;
477	type WeightInfo = weights::pallet_mmr::WeightInfo<Runtime>;
478	#[cfg(feature = "runtime-benchmarks")]
479	type BenchmarkHelper = parachains_paras::benchmarking::mmr_setup::MmrSetup<Runtime>;
480}
481
482/// MMR helper types.
483mod mmr {
484	use super::Runtime;
485	pub use pallet_mmr::primitives::*;
486
487	pub type Leaf = <<Runtime as pallet_mmr::Config>::LeafData as LeafDataProvider>::LeafData;
488	pub type Hashing = <Runtime as pallet_mmr::Config>::Hashing;
489	pub type Hash = <Hashing as sp_runtime::traits::Hash>::Output;
490}
491
492parameter_types! {
493	pub LeafVersion: MmrLeafVersion = MmrLeafVersion::new(0, 0);
494}
495
496/// A BEEFY data provider that merkelizes all the parachain heads at the current block
497/// (sorted by their parachain id).
498pub struct ParaHeadsRootProvider;
499impl BeefyDataProvider<H256> for ParaHeadsRootProvider {
500	fn extra_data() -> H256 {
501		let para_heads: Vec<(u32, Vec<u8>)> =
502			parachains_paras::Pallet::<Runtime>::sorted_para_heads();
503		binary_merkle_tree::merkle_root::<mmr::Hashing, _>(
504			para_heads.into_iter().map(|pair| pair.encode()),
505		)
506		.into()
507	}
508}
509
510impl pallet_beefy_mmr::Config for Runtime {
511	type LeafVersion = LeafVersion;
512	type BeefyAuthorityToMerkleLeaf = pallet_beefy_mmr::BeefyEcdsaToEthereum;
513	type LeafExtra = H256;
514	type BeefyDataProvider = ParaHeadsRootProvider;
515	type WeightInfo = weights::pallet_beefy_mmr::WeightInfo<Runtime>;
516}
517
518parameter_types! {
519	pub const TransactionByteFee: Balance = 10 * MILLICENTS;
520	/// This value increases the priority of `Operational` transactions by adding
521	/// a "virtual tip" that's equal to the `OperationalFeeMultiplier * final_fee`.
522	pub const OperationalFeeMultiplier: u8 = 5;
523}
524
525impl pallet_transaction_payment::Config for Runtime {
526	type RuntimeEvent = RuntimeEvent;
527	type OnChargeTransaction = FungibleAdapter<Balances, ToAuthor<Runtime>>;
528	type OperationalFeeMultiplier = OperationalFeeMultiplier;
529	type WeightToFee = WeightToFee;
530	type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
531	type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
532	type WeightInfo = weights::pallet_transaction_payment::WeightInfo<Runtime>;
533}
534
535parameter_types! {
536	pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
537}
538impl pallet_timestamp::Config for Runtime {
539	type Moment = u64;
540	type OnTimestampSet = Babe;
541	type MinimumPeriod = MinimumPeriod;
542	type WeightInfo = weights::pallet_timestamp::WeightInfo<Runtime>;
543}
544
545impl pallet_authorship::Config for Runtime {
546	type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
547	type EventHandler = StakingAhClient;
548}
549
550parameter_types! {
551	pub const Period: BlockNumber = 10 * MINUTES;
552	pub const Offset: BlockNumber = 0;
553}
554
555impl_opaque_keys! {
556	pub struct SessionKeys {
557		pub grandpa: Grandpa,
558		pub babe: Babe,
559		pub para_validator: Initializer,
560		pub para_assignment: ParaSessionInfo,
561		pub authority_discovery: AuthorityDiscovery,
562		pub beefy: Beefy,
563	}
564}
565
566pub struct IdentityValidatorIdeOf;
567impl sp_runtime::traits::Convert<AccountId, Option<AccountId>> for IdentityValidatorIdeOf {
568	fn convert(account: AccountId) -> Option<AccountId> {
569		Some(account)
570	}
571}
572
573/// A testing type that implements SessionManager, it receives a new validator set from
574/// `StakingAhClient`, but it prevents them from being passed over to the session pallet and
575/// just uses the previous session keys.
576pub struct AckButPreviousSessionValidatorsPersist<I>(core::marker::PhantomData<I>);
577
578impl<I: pallet_session::SessionManager<AccountId>> pallet_session::SessionManager<AccountId>
579	for AckButPreviousSessionValidatorsPersist<I>
580{
581	fn end_session(end_index: SessionIndex) {
582		<I as pallet_session::SessionManager<_>>::end_session(end_index);
583	}
584	fn new_session(new_index: SessionIndex) -> Option<Vec<AccountId>> {
585		match <I as pallet_session::SessionManager<_>>::new_session(new_index) {
586			Some(_new_ignored) => {
587				let current_validators = pallet_session::Validators::<Runtime>::get();
588				log::info!(target: "runtime", ">> received {} validators, but overriding with {} old ones", _new_ignored.len(), current_validators.len());
589				Some(current_validators)
590			},
591			None => None,
592		}
593	}
594	fn new_session_genesis(new_index: SessionIndex) -> Option<Vec<AccountId>> {
595		<I as pallet_session::SessionManager<_>>::new_session_genesis(new_index)
596	}
597	fn start_session(start_index: SessionIndex) {
598		<I as pallet_session::SessionManager<_>>::start_session(start_index);
599	}
600}
601
602impl pallet_session::Config for Runtime {
603	type RuntimeEvent = RuntimeEvent;
604	type ValidatorId = AccountId;
605	type ValidatorIdOf = IdentityValidatorIdeOf;
606	type ShouldEndSession = Babe;
607	type NextSessionRotation = Babe;
608	type SessionManager = AckButPreviousSessionValidatorsPersist<
609		session_historical::NoteHistoricalRoot<Self, StakingAhClient>,
610	>;
611	type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
612	type Keys = SessionKeys;
613	type DisablingStrategy = pallet_session::disabling::UpToLimitWithReEnablingDisablingStrategy;
614	type WeightInfo = weights::pallet_session::WeightInfo<Runtime>;
615	type Currency = Balances;
616	type KeyDeposit = ();
617}
618
619impl session_historical::Config for Runtime {
620	type RuntimeEvent = RuntimeEvent;
621	type FullIdentification = sp_staking::Exposure<AccountId, Balance>;
622	type FullIdentificationOf = ah_client::DefaultExposureOf<Self>;
623}
624
625// impl pallet_root_offences::Config for Runtime {
626// 	type RuntimeEvent = RuntimeEvent;
627// 	type OffenceHandler = StakingAhClient;
628// 	type ReportOffence = Offences;
629// }
630
631pub struct AssetHubLocation;
632impl Get<Location> for AssetHubLocation {
633	fn get() -> Location {
634		Location::new(0, [Junction::Parachain(1100)])
635	}
636}
637
638pub struct SessionReportToXcm;
639impl Convert<rc_client::SessionReport<AccountId>, Xcm<()>> for SessionReportToXcm {
640	fn convert(a: rc_client::SessionReport<AccountId>) -> Xcm<()> {
641		Xcm(vec![
642			Instruction::UnpaidExecution {
643				weight_limit: WeightLimit::Unlimited,
644				check_origin: None,
645			},
646			Instruction::Transact {
647				origin_kind: OriginKind::Superuser,
648				fallback_max_weight: None,
649				call: AssetHubRuntimePallets::RcClient(RcClientCalls::RelaySessionReport(a))
650					.encode()
651					.into(),
652			},
653		])
654	}
655}
656
657pub struct QueuedOffenceToXcm;
658impl Convert<Vec<ah_client::QueuedOffenceOf<Runtime>>, Xcm<()>> for QueuedOffenceToXcm {
659	fn convert(offences: Vec<ah_client::QueuedOffenceOf<Runtime>>) -> Xcm<()> {
660		Xcm(vec![
661			Instruction::UnpaidExecution {
662				weight_limit: WeightLimit::Unlimited,
663				check_origin: None,
664			},
665			Instruction::Transact {
666				origin_kind: OriginKind::Superuser,
667				fallback_max_weight: None,
668				call: AssetHubRuntimePallets::RcClient(RcClientCalls::RelayNewOffencePaged(
669					offences,
670				))
671				.encode()
672				.into(),
673			},
674		])
675	}
676}
677
678pub struct StakingXcmToAssetHub;
679impl ah_client::SendToAssetHub for StakingXcmToAssetHub {
680	type AccountId = AccountId;
681
682	fn relay_session_report(
683		session_report: rc_client::SessionReport<Self::AccountId>,
684	) -> Result<(), ()> {
685		rc_client::XCMSender::<
686			xcm_config::XcmRouter,
687			AssetHubLocation,
688			rc_client::SessionReport<AccountId>,
689			SessionReportToXcm,
690		>::send(session_report)
691	}
692
693	fn relay_new_offence_paged(
694		offences: Vec<ah_client::QueuedOffenceOf<Runtime>>,
695	) -> Result<(), ()> {
696		rc_client::XCMSender::<
697			xcm_config::XcmRouter,
698			AssetHubLocation,
699			Vec<ah_client::QueuedOffenceOf<Runtime>>,
700			QueuedOffenceToXcm,
701		>::send(offences)
702	}
703}
704
705#[derive(Encode, Decode)]
706enum AssetHubRuntimePallets<AccountId> {
707	#[codec(index = 89)]
708	RcClient(RcClientCalls<AccountId>),
709}
710
711/// Call encoding for the calls needed from the rc-client pallet.
712#[derive(Encode, Decode)]
713enum RcClientCalls<AccountId> {
714	/// A session with the given index has started.
715	#[codec(index = 0)]
716	RelaySessionReport(rc_client::SessionReport<AccountId>),
717	#[codec(index = 1)]
718	RelayNewOffencePaged(Vec<(SessionIndex, rc_client::Offence<AccountId>)>),
719}
720
721pub struct EnsureAssetHub;
722impl frame_support::traits::EnsureOrigin<RuntimeOrigin> for EnsureAssetHub {
723	type Success = ();
724	fn try_origin(o: RuntimeOrigin) -> Result<Self::Success, RuntimeOrigin> {
725		match <RuntimeOrigin as Into<Result<parachains_origin::Origin, RuntimeOrigin>>>::into(
726			o.clone(),
727		) {
728			Ok(parachains_origin::Origin::Parachain(id)) if id == 1100.into() => Ok(()),
729			_ => Err(o),
730		}
731	}
732
733	#[cfg(feature = "runtime-benchmarks")]
734	fn try_successful_origin() -> Result<RuntimeOrigin, ()> {
735		Ok(RuntimeOrigin::root())
736	}
737}
738
739parameter_types! {
740	/// each offence is 74 bytes max, sending 50 at a time will be 3,700 bytes.
741	pub const MaxOffenceBatchSize: u32 = 50;
742}
743
744impl pallet_staking_async_ah_client::Config for Runtime {
745	type CurrencyBalance = Balance;
746	type AssetHubOrigin =
747		frame_support::traits::EitherOfDiverse<EnsureRoot<AccountId>, EnsureAssetHub>;
748	type AdminOrigin = EnsureRoot<AccountId>;
749	type SessionInterface = Self;
750	type SendToAssetHub = StakingXcmToAssetHub;
751	type MinimumValidatorSetSize = ConstU32<1>;
752	type MaximumValidatorsWithPoints = ConstU32<{ MaxActiveValidators::get() * 4 }>;
753	type UnixTime = Timestamp;
754	type PointsPerBlock = ConstU32<20>;
755	type MaxOffenceBatchSize = MaxOffenceBatchSize;
756	type Fallback = Staking;
757	type MaxSessionReportRetries = ConstU32<3>;
758}
759
760parameter_types! {
761	// phase durations. 1/4 of the last session for each.
762	pub SignedPhase: u32 = prod_or_fast!(
763		EPOCH_DURATION_IN_SLOTS / 4,
764		(1 * MINUTES).min(EpochDuration::get().saturated_into::<u32>() / 2)
765	);
766	pub UnsignedPhase: u32 = prod_or_fast!(
767		EPOCH_DURATION_IN_SLOTS / 4,
768		(1 * MINUTES).min(EpochDuration::get().saturated_into::<u32>() / 2)
769	);
770
771	// signed config
772	pub const SignedMaxSubmissions: u32 = 128;
773	pub const SignedMaxRefunds: u32 = 128 / 4;
774	pub const SignedFixedDeposit: Balance = deposit(2, 0);
775	pub const SignedDepositIncreaseFactor: Percent = Percent::from_percent(10);
776	pub const SignedDepositByte: Balance = deposit(0, 10) / 1024;
777	// Each good submission will get 1 WND as reward
778	pub SignedRewardBase: Balance = 1 * UNITS;
779
780	// 1 hour session, 15 minutes unsigned phase, 4 offchain executions.
781	pub OffchainRepeat: BlockNumber = UnsignedPhase::get() / 4;
782
783	pub const MaxElectingVoters: u32 = 22_500;
784	/// We take the top 22500 nominators as electing voters and all of the validators as electable
785	/// targets. Whilst this is the case, we cannot and shall not increase the size of the
786	/// validator intentions.
787	pub ElectionBounds: frame_election_provider_support::bounds::ElectionBounds =
788		ElectionBoundsBuilder::default().voters_count(MaxElectingVoters::get().into()).build();
789	// Maximum winners that can be chosen as active validators
790	pub const MaxActiveValidators: u32 = 1000;
791	// One page only, fill the whole page with the `MaxActiveValidators`.
792	pub const MaxWinnersPerPage: u32 = MaxActiveValidators::get();
793	// Unbonded, thus the max backers per winner maps to the max electing voters limit.
794	pub const MaxBackersPerWinner: u32 = MaxElectingVoters::get();
795}
796
797frame_election_provider_support::generate_solution_type!(
798	#[compact]
799	pub struct NposCompactSolution16::<
800		VoterIndex = u32,
801		TargetIndex = u16,
802		Accuracy = sp_runtime::PerU16,
803		MaxVoters = MaxElectingVoters,
804	>(16)
805);
806
807pub struct OnChainSeqPhragmen;
808impl onchain::Config for OnChainSeqPhragmen {
809	type Sort = ConstBool<true>;
810	type System = Runtime;
811	type Solver = SequentialPhragmen<
812		AccountId,
813		pallet_election_provider_multi_phase::SolutionAccuracyOf<Runtime>,
814	>;
815	type DataProvider = Staking;
816	type WeightInfo = ();
817	type Bounds = ElectionBounds;
818	type MaxBackersPerWinner = MaxBackersPerWinner;
819	type MaxWinnersPerPage = MaxWinnersPerPage;
820}
821
822impl pallet_election_provider_multi_phase::MinerConfig for Runtime {
823	type AccountId = AccountId;
824	type MaxLength = OffchainSolutionLengthLimit;
825	type MaxWeight = OffchainSolutionWeightLimit;
826	type Solution = NposCompactSolution16;
827	type MaxVotesPerVoter = <
828	<Self as pallet_election_provider_multi_phase::Config>::DataProvider
829	as
830	frame_election_provider_support::ElectionDataProvider
831	>::MaxVotesPerVoter;
832	type MaxBackersPerWinner = MaxBackersPerWinner;
833	type MaxWinners = MaxWinnersPerPage;
834
835	// The unsigned submissions have to respect the weight of the submit_unsigned call, thus their
836	// weight estimate function is wired to this call's weight.
837	fn solution_weight(v: u32, t: u32, a: u32, d: u32) -> Weight {
838		<
839		<Self as pallet_election_provider_multi_phase::Config>::WeightInfo
840		as
841		pallet_election_provider_multi_phase::WeightInfo
842		>::submit_unsigned(v, t, a, d)
843	}
844}
845
846impl pallet_election_provider_multi_phase::Config for Runtime {
847	type RuntimeEvent = RuntimeEvent;
848	type Currency = Balances;
849	type EstimateCallFee = TransactionPayment;
850	type SignedPhase = SignedPhase;
851	type UnsignedPhase = UnsignedPhase;
852	type SignedMaxSubmissions = SignedMaxSubmissions;
853	type SignedMaxRefunds = SignedMaxRefunds;
854	type SignedRewardBase = SignedRewardBase;
855	type SignedDepositBase = pallet_election_provider_multi_phase::GeometricDepositBase<
856		Balance,
857		SignedFixedDeposit,
858		SignedDepositIncreaseFactor,
859	>;
860	type SignedDepositByte = SignedDepositByte;
861	type SignedDepositWeight = ();
862	type SignedMaxWeight =
863		<Self::MinerConfig as pallet_election_provider_multi_phase::MinerConfig>::MaxWeight;
864	type MinerConfig = Self;
865	type SlashHandler = (); // burn slashes
866	type RewardHandler = (); // rewards are minted from the void
867	type BetterSignedThreshold = ();
868	type OffchainRepeat = OffchainRepeat;
869	type MinerTxPriority = NposSolutionPriority;
870	type MaxWinners = MaxWinnersPerPage;
871	type MaxBackersPerWinner = MaxBackersPerWinner;
872	type DataProvider = Staking;
873	#[cfg(any(feature = "fast-runtime", feature = "runtime-benchmarks"))]
874	type Fallback = onchain::OnChainExecution<OnChainSeqPhragmen>;
875	#[cfg(not(any(feature = "fast-runtime", feature = "runtime-benchmarks")))]
876	type Fallback = frame_election_provider_support::NoElection<(
877		AccountId,
878		BlockNumber,
879		Staking,
880		MaxWinnersPerPage,
881		MaxBackersPerWinner,
882	)>;
883	type GovernanceFallback = onchain::OnChainExecution<OnChainSeqPhragmen>;
884	type Solver = SequentialPhragmen<
885		AccountId,
886		pallet_election_provider_multi_phase::SolutionAccuracyOf<Self>,
887		(),
888	>;
889	type BenchmarkingConfig = polkadot_runtime_common::elections::BenchmarkConfig;
890	type ForceOrigin = EnsureRoot<AccountId>;
891	type WeightInfo = ();
892	type ElectionBounds = ElectionBounds;
893}
894
895parameter_types! {
896	pub const SessionsPerEra: SessionIndex = 3;
897	pub const BondingDuration: sp_staking::EraIndex = 3;
898	pub const SlashDeferDuration: sp_staking::EraIndex = 1;
899	pub const MaxExposurePageSize: u32 = 64;
900	pub const MaxNominations: u32 = <NposCompactSolution16 as frame_election_provider_support::NposSolution>::LIMIT as u32;
901	pub const MaxControllersInDeprecationBatch: u32 = 751;
902}
903
904impl pallet_staking::Config for Runtime {
905	type OldCurrency = Balances;
906	type Currency = Balances;
907	type UnixTime = Timestamp;
908	type SessionInterface = Self;
909	type CurrencyBalance = Balance;
910	type RuntimeHoldReason = RuntimeHoldReason;
911	type CurrencyToVote = sp_staking::currency_to_vote::U128CurrencyToVote;
912	type RewardRemainder = ();
913	type RuntimeEvent = RuntimeEvent;
914	type Slash = ();
915	type Reward = ();
916	type SessionsPerEra = SessionsPerEra;
917	type BondingDuration = BondingDuration;
918	type SlashDeferDuration = SlashDeferDuration;
919	type AdminOrigin = EitherOf<EnsureRoot<AccountId>, StakingAdmin>;
920	type EraPayout = ();
921	type MaxExposurePageSize = MaxExposurePageSize;
922	type NextNewSession = Session;
923	type ElectionProvider = ElectionProviderMultiPhase;
924	type GenesisElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
925	type VoterList = VoterList;
926	type TargetList = pallet_staking::UseValidatorsMap<Self>;
927	type MaxValidatorSet = MaxActiveValidators;
928	type NominationsQuota = pallet_staking::FixedNominationsQuota<{ MaxNominations::get() }>;
929	type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
930	type HistoryDepth = frame_support::traits::ConstU32<84>;
931	type MaxControllersInDeprecationBatch = MaxControllersInDeprecationBatch;
932	type BenchmarkingConfig = polkadot_runtime_common::StakingBenchmarkingConfig;
933	type EventListeners = ();
934	type WeightInfo = ();
935	type Filter = Nothing;
936}
937
938const THRESHOLDS: [VoteWeight; 9] = [10, 20, 30, 40, 50, 60, 1_000, 2_000, 10_000];
939
940parameter_types! {
941	pub const BagThresholds: &'static [sp_npos_elections::VoteWeight] = &THRESHOLDS;
942}
943
944type VoterBagsListInstance = pallet_bags_list::Instance1;
945impl pallet_bags_list::Config<VoterBagsListInstance> for Runtime {
946	type RuntimeEvent = RuntimeEvent;
947	type ScoreProvider = Staking;
948	type WeightInfo = ();
949	type BagThresholds = BagThresholds;
950	type Score = sp_npos_elections::VoteWeight;
951	type MaxAutoRebagPerBlock = ();
952}
953
954parameter_types! {
955	pub const SpendPeriod: BlockNumber = 6 * DAYS;
956	pub const Burn: Permill = Permill::from_perthousand(2);
957	pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
958	pub const PayoutSpendPeriod: BlockNumber = 30 * DAYS;
959	// The asset's interior location for the paying account. This is the Treasury
960	// pallet instance (which sits at index 37).
961	pub TreasuryInteriorLocation: InteriorLocation = PalletInstance(37).into();
962
963	pub const TipCountdown: BlockNumber = 1 * DAYS;
964	pub const TipFindersFee: Percent = Percent::from_percent(20);
965	pub const TipReportDepositBase: Balance = 100 * CENTS;
966	pub const DataDepositPerByte: Balance = 1 * CENTS;
967	pub const MaxApprovals: u32 = 100;
968	pub const MaxAuthorities: u32 = 100_000;
969	pub const MaxKeys: u32 = 10_000;
970	pub const MaxPeerInHeartbeats: u32 = 10_000;
971	pub const MaxBalance: Balance = Balance::max_value();
972}
973
974impl pallet_treasury::Config for Runtime {
975	type PalletId = TreasuryPalletId;
976	type Currency = Balances;
977	type RejectOrigin = EitherOfDiverse<EnsureRoot<AccountId>, Treasurer>;
978	type RuntimeEvent = RuntimeEvent;
979	type SpendPeriod = SpendPeriod;
980	type Burn = Burn;
981	type BurnDestination = ();
982	type MaxApprovals = MaxApprovals;
983	type WeightInfo = weights::pallet_treasury::WeightInfo<Runtime>;
984	type SpendFunds = ();
985	type SpendOrigin = TreasurySpender;
986	type AssetKind = VersionedLocatableAsset;
987	type Beneficiary = VersionedLocation;
988	type BeneficiaryLookup = IdentityLookup<Self::Beneficiary>;
989	type Paymaster = PayOverXcm<
990		TreasuryInteriorLocation,
991		crate::xcm_config::XcmRouter,
992		crate::XcmPallet,
993		ConstU32<{ 6 * HOURS }>,
994		Self::Beneficiary,
995		Self::AssetKind,
996		LocatableAssetConverter,
997		VersionedLocationConverter,
998	>;
999	type BalanceConverter = UnityOrOuterConversion<
1000		ContainsParts<
1001			FromContains<
1002				xcm_builder::IsChildSystemParachain<ParaId>,
1003				xcm_builder::IsParentsOnly<ConstU8<1>>,
1004			>,
1005		>,
1006		AssetRate,
1007	>;
1008	type PayoutPeriod = PayoutSpendPeriod;
1009	type BlockNumberProvider = System;
1010	#[cfg(feature = "runtime-benchmarks")]
1011	type BenchmarkHelper = polkadot_runtime_common::impls::benchmarks::TreasuryArguments;
1012}
1013
1014impl pallet_offences::Config for Runtime {
1015	type RuntimeEvent = RuntimeEvent;
1016	type IdentificationTuple = session_historical::IdentificationTuple<Self>;
1017	type OnOffenceHandler = StakingAhClient;
1018}
1019
1020impl pallet_authority_discovery::Config for Runtime {
1021	type MaxAuthorities = MaxAuthorities;
1022}
1023
1024parameter_types! {
1025	pub const NposSolutionPriority: TransactionPriority = TransactionPriority::max_value() / 2;
1026}
1027
1028parameter_types! {
1029	pub const MaxSetIdSessionEntries: u32 = 1024;
1030}
1031
1032impl pallet_grandpa::Config for Runtime {
1033	type RuntimeEvent = RuntimeEvent;
1034
1035	type WeightInfo = ();
1036	type MaxAuthorities = MaxAuthorities;
1037	type MaxNominators = <Self as pallet_babe::Config>::MaxNominators;
1038	type MaxSetIdSessionEntries = MaxSetIdSessionEntries;
1039
1040	type KeyOwnerProof = sp_session::MembershipProof;
1041
1042	type EquivocationReportSystem =
1043		pallet_grandpa::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
1044}
1045
1046impl frame_system::offchain::SigningTypes for Runtime {
1047	type Public = <Signature as Verify>::Signer;
1048	type Signature = Signature;
1049}
1050
1051impl<C> frame_system::offchain::CreateTransactionBase<C> for Runtime
1052where
1053	RuntimeCall: From<C>,
1054{
1055	type RuntimeCall = RuntimeCall;
1056	type Extrinsic = UncheckedExtrinsic;
1057}
1058
1059impl<LocalCall> frame_system::offchain::CreateTransaction<LocalCall> for Runtime
1060where
1061	RuntimeCall: From<LocalCall>,
1062{
1063	type Extension = TxExtension;
1064
1065	fn create_transaction(call: RuntimeCall, extension: TxExtension) -> UncheckedExtrinsic {
1066		UncheckedExtrinsic::new_transaction(call, extension)
1067	}
1068}
1069
1070/// Submits a transaction with the node's public and signature type. Adheres to the signed extension
1071/// format of the chain.
1072impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime
1073where
1074	RuntimeCall: From<LocalCall>,
1075{
1076	fn create_signed_transaction<
1077		C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>,
1078	>(
1079		call: RuntimeCall,
1080		public: <Signature as Verify>::Signer,
1081		account: AccountId,
1082		nonce: <Runtime as frame_system::Config>::Nonce,
1083	) -> Option<UncheckedExtrinsic> {
1084		use sp_runtime::traits::StaticLookup;
1085		// take the biggest period possible.
1086		let period =
1087			BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64;
1088
1089		let current_block = System::block_number()
1090			.saturated_into::<u64>()
1091			// The `System::block_number` is initialized with `n+1`,
1092			// so the actual block number is `n`.
1093			.saturating_sub(1);
1094		let tip = 0;
1095		let tx_ext: TxExtension = (
1096			frame_system::CheckNonZeroSender::<Runtime>::new(),
1097			frame_system::CheckSpecVersion::<Runtime>::new(),
1098			frame_system::CheckTxVersion::<Runtime>::new(),
1099			frame_system::CheckGenesis::<Runtime>::new(),
1100			frame_system::CheckMortality::<Runtime>::from(generic::Era::mortal(
1101				period,
1102				current_block,
1103			)),
1104			frame_system::CheckNonce::<Runtime>::from(nonce),
1105			frame_system::CheckWeight::<Runtime>::new(),
1106			pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
1107			frame_metadata_hash_extension::CheckMetadataHash::<Runtime>::new(true),
1108			frame_system::WeightReclaim::<Runtime>::new(),
1109		)
1110			.into();
1111		let raw_payload = SignedPayload::new(call, tx_ext)
1112			.map_err(|e| {
1113				log::warn!("Unable to create signed payload: {:?}", e);
1114			})
1115			.ok()?;
1116		let signature = raw_payload.using_encoded(|payload| C::sign(payload, public))?;
1117		let (call, tx_ext, _) = raw_payload.deconstruct();
1118		let address = <Runtime as frame_system::Config>::Lookup::unlookup(account);
1119		let transaction = UncheckedExtrinsic::new_signed(call, address, signature, tx_ext);
1120		Some(transaction)
1121	}
1122}
1123
1124impl<LocalCall> frame_system::offchain::CreateInherent<LocalCall> for Runtime
1125where
1126	RuntimeCall: From<LocalCall>,
1127{
1128	fn create_bare(call: RuntimeCall) -> UncheckedExtrinsic {
1129		UncheckedExtrinsic::new_bare(call)
1130	}
1131}
1132
1133parameter_types! {
1134	// Minimum 100 bytes/KSM deposited (1 CENT/byte)
1135	pub const BasicDeposit: Balance = 1000 * CENTS;       // 258 bytes on-chain
1136	pub const ByteDeposit: Balance = deposit(0, 1);
1137	pub const UsernameDeposit: Balance = deposit(0, 32);
1138	pub const SubAccountDeposit: Balance = 200 * CENTS;   // 53 bytes on-chain
1139	pub const MaxSubAccounts: u32 = 100;
1140	pub const MaxAdditionalFields: u32 = 100;
1141	pub const MaxRegistrars: u32 = 20;
1142}
1143
1144impl pallet_identity::Config for Runtime {
1145	type RuntimeEvent = RuntimeEvent;
1146	type Currency = Balances;
1147	type Slashed = ();
1148	type BasicDeposit = BasicDeposit;
1149	type ByteDeposit = ByteDeposit;
1150	type UsernameDeposit = UsernameDeposit;
1151	type SubAccountDeposit = SubAccountDeposit;
1152	type MaxSubAccounts = MaxSubAccounts;
1153	type IdentityInformation = IdentityInfo<MaxAdditionalFields>;
1154	type MaxRegistrars = MaxRegistrars;
1155	type ForceOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>;
1156	type RegistrarOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>;
1157	type OffchainSignature = Signature;
1158	type SigningPublicKey = <Signature as Verify>::Signer;
1159	type UsernameAuthorityOrigin = EnsureRoot<Self::AccountId>;
1160	type PendingUsernameExpiration = ConstU32<{ 7 * DAYS }>;
1161	type UsernameGracePeriod = ConstU32<{ 30 * DAYS }>;
1162	type MaxSuffixLength = ConstU32<7>;
1163	type MaxUsernameLength = ConstU32<32>;
1164	#[cfg(feature = "runtime-benchmarks")]
1165	type BenchmarkHelper = ();
1166	type WeightInfo = weights::pallet_identity::WeightInfo<Runtime>;
1167}
1168
1169impl pallet_utility::Config for Runtime {
1170	type RuntimeEvent = RuntimeEvent;
1171	type RuntimeCall = RuntimeCall;
1172	type PalletsOrigin = OriginCaller;
1173	type WeightInfo = weights::pallet_utility::WeightInfo<Runtime>;
1174}
1175
1176parameter_types! {
1177	// One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes.
1178	pub const DepositBase: Balance = deposit(1, 88);
1179	// Additional storage item size of 32 bytes.
1180	pub const DepositFactor: Balance = deposit(0, 32);
1181	pub const MaxSignatories: u32 = 100;
1182}
1183
1184impl pallet_multisig::Config for Runtime {
1185	type RuntimeEvent = RuntimeEvent;
1186	type RuntimeCall = RuntimeCall;
1187	type Currency = Balances;
1188	type DepositBase = DepositBase;
1189	type DepositFactor = DepositFactor;
1190	type MaxSignatories = MaxSignatories;
1191	type WeightInfo = weights::pallet_multisig::WeightInfo<Runtime>;
1192	type BlockNumberProvider = frame_system::Pallet<Runtime>;
1193}
1194
1195parameter_types! {
1196	pub const ConfigDepositBase: Balance = 500 * CENTS;
1197	pub const FriendDepositFactor: Balance = 50 * CENTS;
1198	pub const MaxFriends: u16 = 9;
1199	pub const RecoveryDeposit: Balance = 500 * CENTS;
1200}
1201
1202impl pallet_recovery::Config for Runtime {
1203	type RuntimeEvent = RuntimeEvent;
1204	type WeightInfo = ();
1205	type RuntimeCall = RuntimeCall;
1206	type BlockNumberProvider = System;
1207	type Currency = Balances;
1208	type ConfigDepositBase = ConfigDepositBase;
1209	type FriendDepositFactor = FriendDepositFactor;
1210	type MaxFriends = MaxFriends;
1211	type RecoveryDeposit = RecoveryDeposit;
1212}
1213
1214parameter_types! {
1215	pub const MinVestedTransfer: Balance = 100 * CENTS;
1216	pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons =
1217		WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE);
1218}
1219
1220impl pallet_vesting::Config for Runtime {
1221	type RuntimeEvent = RuntimeEvent;
1222	type Currency = Balances;
1223	type BlockNumberToBalance = ConvertInto;
1224	type MinVestedTransfer = MinVestedTransfer;
1225	type WeightInfo = weights::pallet_vesting::WeightInfo<Runtime>;
1226	type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons;
1227	type BlockNumberProvider = System;
1228	const MAX_VESTING_SCHEDULES: u32 = 28;
1229}
1230
1231impl pallet_sudo::Config for Runtime {
1232	type RuntimeEvent = RuntimeEvent;
1233	type RuntimeCall = RuntimeCall;
1234	type WeightInfo = weights::pallet_sudo::WeightInfo<Runtime>;
1235}
1236
1237parameter_types! {
1238	// One storage item; key size 32, value size 8; .
1239	pub const ProxyDepositBase: Balance = deposit(1, 8);
1240	// Additional storage item size of 33 bytes.
1241	pub const ProxyDepositFactor: Balance = deposit(0, 33);
1242	pub const MaxProxies: u16 = 32;
1243	pub const AnnouncementDepositBase: Balance = deposit(1, 8);
1244	pub const AnnouncementDepositFactor: Balance = deposit(0, 66);
1245	pub const MaxPending: u16 = 32;
1246}
1247
1248/// The type used to represent the kinds of proxying allowed.
1249#[derive(
1250	Copy,
1251	Clone,
1252	Eq,
1253	PartialEq,
1254	Ord,
1255	PartialOrd,
1256	Encode,
1257	Decode,
1258	DecodeWithMemTracking,
1259	RuntimeDebug,
1260	MaxEncodedLen,
1261	TypeInfo,
1262)]
1263pub enum ProxyType {
1264	Any,
1265	NonTransfer,
1266	Governance,
1267	Staking,
1268	SudoBalances,
1269	IdentityJudgement,
1270	CancelProxy,
1271	Auction,
1272	NominationPools,
1273	ParaRegistration,
1274}
1275impl Default for ProxyType {
1276	fn default() -> Self {
1277		Self::Any
1278	}
1279}
1280impl InstanceFilter<RuntimeCall> for ProxyType {
1281	fn filter(&self, c: &RuntimeCall) -> bool {
1282		match self {
1283			ProxyType::Any => true,
1284			ProxyType::NonTransfer => matches!(
1285				c,
1286				RuntimeCall::System(..) |
1287				RuntimeCall::Babe(..) |
1288				RuntimeCall::Timestamp(..) |
1289				RuntimeCall::Indices(pallet_indices::Call::claim{..}) |
1290				RuntimeCall::Indices(pallet_indices::Call::free{..}) |
1291				RuntimeCall::Indices(pallet_indices::Call::freeze{..}) |
1292				// Specifically omitting Indices `transfer`, `force_transfer`
1293				// Specifically omitting the entire Balances pallet
1294				RuntimeCall::Session(..) |
1295				RuntimeCall::Grandpa(..) |
1296				RuntimeCall::Utility(..) |
1297				RuntimeCall::Identity(..) |
1298				RuntimeCall::ConvictionVoting(..) |
1299				RuntimeCall::Referenda(..) |
1300				RuntimeCall::Whitelist(..) |
1301				RuntimeCall::Recovery(pallet_recovery::Call::as_recovered{..}) |
1302				RuntimeCall::Recovery(pallet_recovery::Call::vouch_recovery{..}) |
1303				RuntimeCall::Recovery(pallet_recovery::Call::claim_recovery{..}) |
1304				RuntimeCall::Recovery(pallet_recovery::Call::close_recovery{..}) |
1305				RuntimeCall::Recovery(pallet_recovery::Call::remove_recovery{..}) |
1306				RuntimeCall::Recovery(pallet_recovery::Call::cancel_recovered{..}) |
1307				// Specifically omitting Recovery `create_recovery`, `initiate_recovery`
1308				RuntimeCall::Vesting(pallet_vesting::Call::vest{..}) |
1309				RuntimeCall::Vesting(pallet_vesting::Call::vest_other{..}) |
1310				// Specifically omitting Vesting `vested_transfer`, and `force_vested_transfer`
1311				RuntimeCall::Scheduler(..) |
1312				// Specifically omitting Sudo pallet
1313				RuntimeCall::Proxy(..) |
1314				RuntimeCall::Multisig(..) |
1315				RuntimeCall::Registrar(paras_registrar::Call::register{..}) |
1316				RuntimeCall::Registrar(paras_registrar::Call::deregister{..}) |
1317				// Specifically omitting Registrar `swap`
1318				RuntimeCall::Registrar(paras_registrar::Call::reserve{..}) |
1319				RuntimeCall::Crowdloan(..) |
1320				RuntimeCall::Slots(..) |
1321				RuntimeCall::Auctions(..)
1322			),
1323			ProxyType::Staking => {
1324				matches!(c, RuntimeCall::Session(..) | RuntimeCall::Utility(..))
1325			},
1326			ProxyType::NominationPools => {
1327				matches!(c,| RuntimeCall::Utility(..))
1328			},
1329			ProxyType::SudoBalances => match c {
1330				RuntimeCall::Sudo(pallet_sudo::Call::sudo { call: ref x }) => {
1331					matches!(x.as_ref(), &RuntimeCall::Balances(..))
1332				},
1333				RuntimeCall::Utility(..) => true,
1334				_ => false,
1335			},
1336			ProxyType::Governance => matches!(
1337				c,
1338				// OpenGov calls
1339				RuntimeCall::ConvictionVoting(..) |
1340					RuntimeCall::Referenda(..) |
1341					RuntimeCall::Whitelist(..)
1342			),
1343			ProxyType::IdentityJudgement => matches!(
1344				c,
1345				RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) |
1346					RuntimeCall::Utility(..)
1347			),
1348			ProxyType::CancelProxy => {
1349				matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }))
1350			},
1351			ProxyType::Auction => matches!(
1352				c,
1353				RuntimeCall::Auctions(..) |
1354					RuntimeCall::Crowdloan(..) |
1355					RuntimeCall::Registrar(..) |
1356					RuntimeCall::Slots(..)
1357			),
1358			ProxyType::ParaRegistration => matches!(
1359				c,
1360				RuntimeCall::Registrar(paras_registrar::Call::reserve { .. }) |
1361					RuntimeCall::Registrar(paras_registrar::Call::register { .. }) |
1362					RuntimeCall::Utility(pallet_utility::Call::batch { .. }) |
1363					RuntimeCall::Utility(pallet_utility::Call::batch_all { .. }) |
1364					RuntimeCall::Utility(pallet_utility::Call::force_batch { .. }) |
1365					RuntimeCall::Proxy(pallet_proxy::Call::remove_proxy { .. })
1366			),
1367		}
1368	}
1369	fn is_superset(&self, o: &Self) -> bool {
1370		match (self, o) {
1371			(x, y) if x == y => true,
1372			(ProxyType::Any, _) => true,
1373			(_, ProxyType::Any) => false,
1374			(ProxyType::NonTransfer, _) => true,
1375			_ => false,
1376		}
1377	}
1378}
1379
1380impl pallet_proxy::Config for Runtime {
1381	type RuntimeEvent = RuntimeEvent;
1382	type RuntimeCall = RuntimeCall;
1383	type Currency = Balances;
1384	type ProxyType = ProxyType;
1385	type ProxyDepositBase = ProxyDepositBase;
1386	type ProxyDepositFactor = ProxyDepositFactor;
1387	type MaxProxies = MaxProxies;
1388	type WeightInfo = weights::pallet_proxy::WeightInfo<Runtime>;
1389	type MaxPending = MaxPending;
1390	type CallHasher = BlakeTwo256;
1391	type AnnouncementDepositBase = AnnouncementDepositBase;
1392	type AnnouncementDepositFactor = AnnouncementDepositFactor;
1393	type BlockNumberProvider = frame_system::Pallet<Runtime>;
1394}
1395
1396impl parachains_origin::Config for Runtime {}
1397
1398impl parachains_configuration::Config for Runtime {
1399	type WeightInfo = weights::polkadot_runtime_parachains_configuration::WeightInfo<Runtime>;
1400}
1401
1402impl parachains_shared::Config for Runtime {
1403	type DisabledValidators = Session;
1404}
1405
1406impl parachains_session_info::Config for Runtime {
1407	type ValidatorSet = Historical;
1408}
1409
1410impl parachains_inclusion::Config for Runtime {
1411	type RuntimeEvent = RuntimeEvent;
1412	type DisputesHandler = ParasDisputes;
1413	type RewardValidators =
1414		parachains_reward_points::RewardValidatorsWithEraPoints<Runtime, StakingAhClient>;
1415	type MessageQueue = MessageQueue;
1416	type WeightInfo = weights::polkadot_runtime_parachains_inclusion::WeightInfo<Runtime>;
1417}
1418
1419parameter_types! {
1420	pub const ParasUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
1421}
1422
1423impl parachains_paras::Config for Runtime {
1424	type RuntimeEvent = RuntimeEvent;
1425	type WeightInfo = weights::polkadot_runtime_parachains_paras::WeightInfo<Runtime>;
1426	type UnsignedPriority = ParasUnsignedPriority;
1427	type QueueFootprinter = ParaInclusion;
1428	type NextSessionRotation = Babe;
1429	type OnNewHead = ();
1430	type AssignCoretime = CoretimeAssignmentProvider;
1431	type Fungible = Balances;
1432	type CooldownRemovalMultiplier = ConstUint<1>;
1433	type AuthorizeCurrentCodeOrigin = EnsureRoot<AccountId>;
1434}
1435
1436parameter_types! {
1437	/// Amount of weight that can be spent per block to service messages.
1438	///
1439	/// # WARNING
1440	///
1441	/// This is not a good value for para-chains since the `Scheduler` already uses up to 80% block weight.
1442	pub MessageQueueServiceWeight: Weight = Perbill::from_percent(20) * BlockWeights::get().max_block;
1443	pub const MessageQueueHeapSize: u32 = 128 * 1024;
1444	pub const MessageQueueMaxStale: u32 = 48;
1445}
1446
1447/// Message processor to handle any messages that were enqueued into the `MessageQueue` pallet.
1448pub struct MessageProcessor;
1449impl ProcessMessage for MessageProcessor {
1450	type Origin = AggregateMessageOrigin;
1451
1452	fn process_message(
1453		message: &[u8],
1454		origin: Self::Origin,
1455		meter: &mut WeightMeter,
1456		id: &mut [u8; 32],
1457	) -> Result<bool, ProcessMessageError> {
1458		let para = match origin {
1459			AggregateMessageOrigin::Ump(UmpQueueId::Para(para)) => para,
1460		};
1461		xcm_builder::ProcessXcmMessage::<
1462			Junction,
1463			xcm_executor::XcmExecutor<xcm_config::XcmConfig>,
1464			RuntimeCall,
1465		>::process_message(message, Junction::Parachain(para.into()), meter, id)
1466	}
1467}
1468
1469impl pallet_message_queue::Config for Runtime {
1470	type RuntimeEvent = RuntimeEvent;
1471	type Size = u32;
1472	type HeapSize = MessageQueueHeapSize;
1473	type MaxStale = MessageQueueMaxStale;
1474	type ServiceWeight = MessageQueueServiceWeight;
1475	type IdleMaxServiceWeight = MessageQueueServiceWeight;
1476	#[cfg(not(feature = "runtime-benchmarks"))]
1477	type MessageProcessor = MessageProcessor;
1478	#[cfg(feature = "runtime-benchmarks")]
1479	type MessageProcessor =
1480		pallet_message_queue::mock_helpers::NoopMessageProcessor<AggregateMessageOrigin>;
1481	type QueueChangeHandler = ParaInclusion;
1482	type QueuePausedQuery = ();
1483	type WeightInfo = weights::pallet_message_queue::WeightInfo<Runtime>;
1484}
1485
1486impl parachains_dmp::Config for Runtime {}
1487
1488parameter_types! {
1489	pub const HrmpChannelSizeAndCapacityWithSystemRatio: Percent = Percent::from_percent(100);
1490}
1491
1492impl parachains_hrmp::Config for Runtime {
1493	type RuntimeOrigin = RuntimeOrigin;
1494	type RuntimeEvent = RuntimeEvent;
1495	type ChannelManager = EnsureRoot<AccountId>;
1496	type Currency = Balances;
1497	type DefaultChannelSizeAndCapacityWithSystem = ActiveConfigHrmpChannelSizeAndCapacityRatio<
1498		Runtime,
1499		HrmpChannelSizeAndCapacityWithSystemRatio,
1500	>;
1501	type VersionWrapper = crate::XcmPallet;
1502	type WeightInfo = weights::polkadot_runtime_parachains_hrmp::WeightInfo<Self>;
1503}
1504
1505impl parachains_paras_inherent::Config for Runtime {
1506	type WeightInfo = weights::polkadot_runtime_parachains_paras_inherent::WeightInfo<Runtime>;
1507}
1508
1509impl parachains_scheduler::Config for Runtime {
1510	// If you change this, make sure the `Assignment` type of the new provider is binary compatible,
1511	// otherwise provide a migration.
1512	type AssignmentProvider = CoretimeAssignmentProvider;
1513}
1514
1515parameter_types! {
1516	pub const BrokerId: u32 = BROKER_ID;
1517	pub const BrokerPalletId: PalletId = PalletId(*b"py/broke");
1518	pub const AssetHubId: u32 = ASSET_HUB_ID;	// TODO: replace with ASSET_HUB_NEXT_ID
1519	pub MaxXcmTransactWeight: Weight = Weight::from_parts(200_000_000, 20_000);
1520}
1521
1522pub struct BrokerPot;
1523impl Get<InteriorLocation> for AssetHubLocation {
1524	fn get() -> InteriorLocation {
1525		Junction::AccountId32 { network: None, id: BrokerPalletId::get().into_account_truncating() }
1526			.into()
1527	}
1528}
1529
1530impl coretime::Config for Runtime {
1531	type RuntimeOrigin = RuntimeOrigin;
1532	type RuntimeEvent = RuntimeEvent;
1533	type BrokerId = BrokerId;
1534	type BrokerPotLocation = AssetHubLocation;
1535	type WeightInfo = weights::polkadot_runtime_parachains_coretime::WeightInfo<Runtime>;
1536	type SendXcm = crate::xcm_config::XcmRouter;
1537	type AssetTransactor = crate::xcm_config::LocalAssetTransactor;
1538	type AccountToLocation = xcm_builder::AliasesIntoAccountId32<
1539		xcm_config::ThisNetwork,
1540		<Runtime as frame_system::Config>::AccountId,
1541	>;
1542	type MaxXcmTransactWeight = MaxXcmTransactWeight;
1543}
1544
1545parameter_types! {
1546	pub const OnDemandTrafficDefaultValue: FixedU128 = FixedU128::from_u32(1);
1547	// Keep 2 timeslices worth of revenue information.
1548	pub const MaxHistoricalRevenue: BlockNumber = 2 * TIMESLICE_PERIOD;
1549	pub const OnDemandPalletId: PalletId = PalletId(*b"py/ondmd");
1550}
1551
1552impl parachains_on_demand::Config for Runtime {
1553	type RuntimeEvent = RuntimeEvent;
1554	type Currency = Balances;
1555	type TrafficDefaultValue = OnDemandTrafficDefaultValue;
1556	type WeightInfo = weights::polkadot_runtime_parachains_on_demand::WeightInfo<Runtime>;
1557	type MaxHistoricalRevenue = MaxHistoricalRevenue;
1558	type PalletId = OnDemandPalletId;
1559}
1560
1561impl parachains_assigner_coretime::Config for Runtime {}
1562
1563impl parachains_initializer::Config for Runtime {
1564	type Randomness = pallet_babe::RandomnessFromOneEpochAgo<Runtime>;
1565	type ForceOrigin = EnsureRoot<AccountId>;
1566	type WeightInfo = weights::polkadot_runtime_parachains_initializer::WeightInfo<Runtime>;
1567	type CoretimeOnNewSession = Coretime;
1568}
1569
1570impl paras_sudo_wrapper::Config for Runtime {}
1571
1572parameter_types! {
1573	pub const PermanentSlotLeasePeriodLength: u32 = 26;
1574	pub const TemporarySlotLeasePeriodLength: u32 = 1;
1575	pub const MaxTemporarySlotPerLeasePeriod: u32 = 5;
1576}
1577
1578impl assigned_slots::Config for Runtime {
1579	type RuntimeEvent = RuntimeEvent;
1580	type AssignSlotOrigin = EnsureRoot<AccountId>;
1581	type Leaser = Slots;
1582	type PermanentSlotLeasePeriodLength = PermanentSlotLeasePeriodLength;
1583	type TemporarySlotLeasePeriodLength = TemporarySlotLeasePeriodLength;
1584	type MaxTemporarySlotPerLeasePeriod = MaxTemporarySlotPerLeasePeriod;
1585	type WeightInfo = weights::polkadot_runtime_common_assigned_slots::WeightInfo<Runtime>;
1586}
1587
1588impl parachains_disputes::Config for Runtime {
1589	type RuntimeEvent = RuntimeEvent;
1590	type RewardValidators =
1591		parachains_reward_points::RewardValidatorsWithEraPoints<Runtime, StakingAhClient>;
1592	type SlashingHandler = parachains_slashing::SlashValidatorsForDisputes<ParasSlashing>;
1593	type WeightInfo = weights::polkadot_runtime_parachains_disputes::WeightInfo<Runtime>;
1594}
1595
1596impl parachains_slashing::Config for Runtime {
1597	type KeyOwnerProofSystem = Historical;
1598	type KeyOwnerProof =
1599		<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, ValidatorId)>>::Proof;
1600	type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
1601		KeyTypeId,
1602		ValidatorId,
1603	)>>::IdentificationTuple;
1604	type HandleReports = parachains_slashing::SlashingReportHandler<
1605		Self::KeyOwnerIdentification,
1606		Offences,
1607		ReportLongevity,
1608	>;
1609	type WeightInfo = weights::polkadot_runtime_parachains_disputes_slashing::WeightInfo<Runtime>;
1610	type BenchmarkingConfig = parachains_slashing::BenchConfig<300>;
1611}
1612
1613parameter_types! {
1614	pub const ParaDeposit: Balance = 2000 * CENTS;
1615	pub const RegistrarDataDepositPerByte: Balance = deposit(0, 1);
1616}
1617
1618impl paras_registrar::Config for Runtime {
1619	type RuntimeOrigin = RuntimeOrigin;
1620	type RuntimeEvent = RuntimeEvent;
1621	type Currency = Balances;
1622	type OnSwap = (Crowdloan, Slots, SwapLeases);
1623	type ParaDeposit = ParaDeposit;
1624	type DataDepositPerByte = RegistrarDataDepositPerByte;
1625	type WeightInfo = weights::polkadot_runtime_common_paras_registrar::WeightInfo<Runtime>;
1626}
1627
1628parameter_types! {
1629	pub const LeasePeriod: BlockNumber = 28 * DAYS;
1630}
1631
1632impl slots::Config for Runtime {
1633	type RuntimeEvent = RuntimeEvent;
1634	type Currency = Balances;
1635	type Registrar = Registrar;
1636	type LeasePeriod = LeasePeriod;
1637	type LeaseOffset = ();
1638	type ForceOrigin = EitherOf<EnsureRoot<Self::AccountId>, LeaseAdmin>;
1639	type WeightInfo = weights::polkadot_runtime_common_slots::WeightInfo<Runtime>;
1640}
1641
1642parameter_types! {
1643	pub const CrowdloanId: PalletId = PalletId(*b"py/cfund");
1644	pub const SubmissionDeposit: Balance = 100 * 100 * CENTS;
1645	pub const MinContribution: Balance = 100 * CENTS;
1646	pub const RemoveKeysLimit: u32 = 500;
1647	// Allow 32 bytes for an additional memo to a crowdloan.
1648	pub const MaxMemoLength: u8 = 32;
1649}
1650
1651impl crowdloan::Config for Runtime {
1652	type RuntimeEvent = RuntimeEvent;
1653	type PalletId = CrowdloanId;
1654	type SubmissionDeposit = SubmissionDeposit;
1655	type MinContribution = MinContribution;
1656	type RemoveKeysLimit = RemoveKeysLimit;
1657	type Registrar = Registrar;
1658	type Auctioneer = Auctions;
1659	type MaxMemoLength = MaxMemoLength;
1660	type WeightInfo = weights::polkadot_runtime_common_crowdloan::WeightInfo<Runtime>;
1661}
1662
1663parameter_types! {
1664	// The average auction is 7 days long, so this will be 70% for ending period.
1665	// 5 Days = 72000 Blocks @ 6 sec per block
1666	pub const EndingPeriod: BlockNumber = 5 * DAYS;
1667	// ~ 1000 samples per day -> ~ 20 blocks per sample -> 2 minute samples
1668	pub const SampleLength: BlockNumber = 2 * MINUTES;
1669}
1670
1671impl auctions::Config for Runtime {
1672	type RuntimeEvent = RuntimeEvent;
1673	type Leaser = Slots;
1674	type Registrar = Registrar;
1675	type EndingPeriod = EndingPeriod;
1676	type SampleLength = SampleLength;
1677	type Randomness = pallet_babe::RandomnessFromOneEpochAgo<Runtime>;
1678	type InitiateOrigin = EitherOf<EnsureRoot<Self::AccountId>, AuctionAdmin>;
1679	type WeightInfo = weights::polkadot_runtime_common_auctions::WeightInfo<Runtime>;
1680}
1681
1682impl identity_migrator::Config for Runtime {
1683	type RuntimeEvent = RuntimeEvent;
1684	type Reaper = EnsureSigned<AccountId>;
1685	type ReapIdentityHandler = ToParachainIdentityReaper<Runtime, Self::AccountId>;
1686	type WeightInfo = weights::polkadot_runtime_common_identity_migrator::WeightInfo<Runtime>;
1687}
1688
1689impl pallet_root_testing::Config for Runtime {
1690	type RuntimeEvent = RuntimeEvent;
1691}
1692
1693parameter_types! {
1694	pub MbmServiceWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block;
1695}
1696
1697impl pallet_migrations::Config for Runtime {
1698	type RuntimeEvent = RuntimeEvent;
1699	#[cfg(not(feature = "runtime-benchmarks"))]
1700	type Migrations = pallet_identity::migration::v2::LazyMigrationV1ToV2<Runtime>;
1701	// Benchmarks need mocked migrations to guarantee that they succeed.
1702	#[cfg(feature = "runtime-benchmarks")]
1703	type Migrations = pallet_migrations::mock_helpers::MockedMigrations;
1704	type CursorMaxLen = ConstU32<65_536>;
1705	type IdentifierMaxLen = ConstU32<256>;
1706	type MigrationStatusHandler = ();
1707	type FailedMigrationHandler = frame_support::migrations::FreezeChainOnFailedMigration;
1708	type MaxServiceWeight = MbmServiceWeight;
1709	type WeightInfo = weights::pallet_migrations::WeightInfo<Runtime>;
1710}
1711
1712parameter_types! {
1713	// The deposit configuration for the singed migration. Specially if you want to allow any signed account to do the migration (see `SignedFilter`, these deposits should be high)
1714	pub const MigrationSignedDepositPerItem: Balance = 1 * CENTS;
1715	pub const MigrationSignedDepositBase: Balance = 20 * CENTS * 100;
1716	pub const MigrationMaxKeyLen: u32 = 512;
1717}
1718
1719impl pallet_asset_rate::Config for Runtime {
1720	type WeightInfo = weights::pallet_asset_rate::WeightInfo<Runtime>;
1721	type RuntimeEvent = RuntimeEvent;
1722	type CreateOrigin = EnsureRoot<AccountId>;
1723	type RemoveOrigin = EnsureRoot<AccountId>;
1724	type UpdateOrigin = EnsureRoot<AccountId>;
1725	type Currency = Balances;
1726	type AssetKind = <Runtime as pallet_treasury::Config>::AssetKind;
1727	#[cfg(feature = "runtime-benchmarks")]
1728	type BenchmarkHelper = polkadot_runtime_common::impls::benchmarks::AssetRateArguments;
1729}
1730
1731// Notify `coretime` pallet when a lease swap occurs
1732pub struct SwapLeases;
1733impl OnSwap for SwapLeases {
1734	fn on_swap(one: ParaId, other: ParaId) {
1735		coretime::Pallet::<Runtime>::on_legacy_lease_swap(one, other);
1736	}
1737}
1738
1739#[frame_support::runtime(legacy_ordering)]
1740mod runtime {
1741	#[runtime::runtime]
1742	#[runtime::derive(
1743		RuntimeCall,
1744		RuntimeEvent,
1745		RuntimeError,
1746		RuntimeOrigin,
1747		RuntimeFreezeReason,
1748		RuntimeHoldReason,
1749		RuntimeSlashReason,
1750		RuntimeLockId,
1751		RuntimeTask,
1752		RuntimeViewFunction
1753	)]
1754	pub struct Runtime;
1755
1756	// Basic stuff; balances is uncallable initially.
1757	#[runtime::pallet_index(0)]
1758	pub type System = frame_system;
1759
1760	// Babe must be before session.
1761	#[runtime::pallet_index(1)]
1762	pub type Babe = pallet_babe;
1763
1764	#[runtime::pallet_index(2)]
1765	pub type Timestamp = pallet_timestamp;
1766	#[runtime::pallet_index(3)]
1767	pub type Indices = pallet_indices;
1768	#[runtime::pallet_index(4)]
1769	pub type Balances = pallet_balances;
1770	#[runtime::pallet_index(26)]
1771	pub type TransactionPayment = pallet_transaction_payment;
1772
1773	// Consensus support.
1774	// Authorship must be before session in order to note author in the correct session and era.
1775	#[runtime::pallet_index(5)]
1776	pub type Authorship = pallet_authorship;
1777	#[runtime::pallet_index(6)]
1778	pub type Staking = pallet_staking;
1779	#[runtime::pallet_index(7)]
1780	pub type Offences = pallet_offences;
1781	#[runtime::pallet_index(27)]
1782	pub type Historical = session_historical;
1783	#[runtime::pallet_index(70)]
1784	pub type Parameters = pallet_parameters;
1785
1786	#[runtime::pallet_index(8)]
1787	pub type Session = pallet_session;
1788	#[runtime::pallet_index(10)]
1789	pub type Grandpa = pallet_grandpa;
1790	#[runtime::pallet_index(12)]
1791	pub type AuthorityDiscovery = pallet_authority_discovery;
1792
1793	// Utility module.
1794	#[runtime::pallet_index(16)]
1795	pub type Utility = pallet_utility;
1796
1797	// Less simple identity module.
1798	#[runtime::pallet_index(17)]
1799	pub type Identity = pallet_identity;
1800
1801	// Social recovery module.
1802	#[runtime::pallet_index(18)]
1803	pub type Recovery = pallet_recovery;
1804
1805	// Vesting. Usable initially, but removed once all vesting is finished.
1806	#[runtime::pallet_index(19)]
1807	pub type Vesting = pallet_vesting;
1808
1809	// System scheduler.
1810	#[runtime::pallet_index(20)]
1811	pub type Scheduler = pallet_scheduler;
1812
1813	// Preimage registrar.
1814	#[runtime::pallet_index(28)]
1815	pub type Preimage = pallet_preimage;
1816
1817	// Sudo.
1818	#[runtime::pallet_index(21)]
1819	pub type Sudo = pallet_sudo;
1820
1821	// Proxy module. Late addition.
1822	#[runtime::pallet_index(22)]
1823	pub type Proxy = pallet_proxy;
1824
1825	// Multisig module. Late addition.
1826	#[runtime::pallet_index(23)]
1827	pub type Multisig = pallet_multisig;
1828
1829	// Election pallet. Only works with staking, but placed here to maintain indices.
1830	#[runtime::pallet_index(24)]
1831	pub type ElectionProviderMultiPhase = pallet_election_provider_multi_phase;
1832
1833	#[runtime::pallet_index(25)]
1834	pub type VoterList = pallet_bags_list<Instance1>;
1835
1836	// OpenGov
1837	#[runtime::pallet_index(31)]
1838	pub type ConvictionVoting = pallet_conviction_voting;
1839	#[runtime::pallet_index(32)]
1840	pub type Referenda = pallet_referenda;
1841	#[runtime::pallet_index(35)]
1842	pub type Origins = pallet_custom_origins;
1843	#[runtime::pallet_index(36)]
1844	pub type Whitelist = pallet_whitelist;
1845
1846	// Treasury
1847	#[runtime::pallet_index(37)]
1848	pub type Treasury = pallet_treasury;
1849
1850	// Parachains pallets. Start indices at 40 to leave room.
1851	#[runtime::pallet_index(41)]
1852	pub type ParachainsOrigin = parachains_origin;
1853	#[runtime::pallet_index(42)]
1854	pub type Configuration = parachains_configuration;
1855	#[runtime::pallet_index(43)]
1856	pub type ParasShared = parachains_shared;
1857	#[runtime::pallet_index(44)]
1858	pub type ParaInclusion = parachains_inclusion;
1859	#[runtime::pallet_index(45)]
1860	pub type ParaInherent = parachains_paras_inherent;
1861	#[runtime::pallet_index(46)]
1862	pub type ParaScheduler = parachains_scheduler;
1863	#[runtime::pallet_index(47)]
1864	pub type Paras = parachains_paras;
1865	#[runtime::pallet_index(48)]
1866	pub type Initializer = parachains_initializer;
1867	#[runtime::pallet_index(49)]
1868	pub type Dmp = parachains_dmp;
1869	// RIP Ump 50
1870	#[runtime::pallet_index(51)]
1871	pub type Hrmp = parachains_hrmp;
1872	#[runtime::pallet_index(52)]
1873	pub type ParaSessionInfo = parachains_session_info;
1874	#[runtime::pallet_index(53)]
1875	pub type ParasDisputes = parachains_disputes;
1876	#[runtime::pallet_index(54)]
1877	pub type ParasSlashing = parachains_slashing;
1878	#[runtime::pallet_index(56)]
1879	pub type OnDemandAssignmentProvider = parachains_on_demand;
1880	#[runtime::pallet_index(57)]
1881	pub type CoretimeAssignmentProvider = parachains_assigner_coretime;
1882
1883	// Parachain Onboarding Pallets. Start indices at 60 to leave room.
1884	#[runtime::pallet_index(60)]
1885	pub type Registrar = paras_registrar;
1886	#[runtime::pallet_index(61)]
1887	pub type Slots = slots;
1888	#[runtime::pallet_index(62)]
1889	pub type ParasSudoWrapper = paras_sudo_wrapper;
1890	#[runtime::pallet_index(63)]
1891	pub type Auctions = auctions;
1892	#[runtime::pallet_index(64)]
1893	pub type Crowdloan = crowdloan;
1894	#[runtime::pallet_index(65)]
1895	pub type AssignedSlots = assigned_slots;
1896	#[runtime::pallet_index(66)]
1897	pub type Coretime = coretime;
1898
1899	#[runtime::pallet_index(67)]
1900	pub type StakingAhClient = pallet_staking_async_ah_client;
1901	#[runtime::pallet_index(69)]
1902	pub type RewardPointFiller = pallet_reward_point_filler::pallet;
1903
1904	// Migrations pallet
1905	#[runtime::pallet_index(98)]
1906	pub type MultiBlockMigrations = pallet_migrations;
1907
1908	// Pallet for sending XCM.
1909	#[runtime::pallet_index(99)]
1910	pub type XcmPallet = pallet_xcm;
1911
1912	// Generalized message queue
1913	#[runtime::pallet_index(100)]
1914	pub type MessageQueue = pallet_message_queue;
1915
1916	// Asset rate.
1917	#[runtime::pallet_index(101)]
1918	pub type AssetRate = pallet_asset_rate;
1919
1920	// Root testing pallet.
1921	#[runtime::pallet_index(102)]
1922	pub type RootTesting = pallet_root_testing;
1923
1924	// BEEFY Bridges support.
1925	#[runtime::pallet_index(200)]
1926	pub type Beefy = pallet_beefy;
1927	// MMR leaf construction must be after session in order to have a leaf's next_auth_set
1928	// refer to block<N>. See issue polkadot-fellows/runtimes#160 for details.
1929	#[runtime::pallet_index(201)]
1930	pub type Mmr = pallet_mmr;
1931	#[runtime::pallet_index(202)]
1932	pub type BeefyMmrLeaf = pallet_beefy_mmr;
1933
1934	// Pallet for migrating Identity to a parachain. To be removed post-migration.
1935	#[runtime::pallet_index(248)]
1936	pub type IdentityMigrator = identity_migrator;
1937}
1938
1939/// The address format for describing accounts.
1940pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
1941/// Block header type as expected by this runtime.
1942pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
1943/// Block type as expected by this runtime.
1944pub type Block = generic::Block<Header, UncheckedExtrinsic>;
1945/// A Block signed with a Justification
1946pub type SignedBlock = generic::SignedBlock<Block>;
1947/// `BlockId` type as expected by this runtime.
1948pub type BlockId = generic::BlockId<Block>;
1949/// The extension to the basic transaction logic.
1950pub type TxExtension = (
1951	frame_system::CheckNonZeroSender<Runtime>,
1952	frame_system::CheckSpecVersion<Runtime>,
1953	frame_system::CheckTxVersion<Runtime>,
1954	frame_system::CheckGenesis<Runtime>,
1955	frame_system::CheckMortality<Runtime>,
1956	frame_system::CheckNonce<Runtime>,
1957	frame_system::CheckWeight<Runtime>,
1958	pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
1959	frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
1960	frame_system::WeightReclaim<Runtime>,
1961);
1962
1963parameter_types! {
1964	/// Bounding number of agent pot accounts to be migrated in a single block.
1965	pub const MaxAgentsToMigrate: u32 = 300;
1966}
1967
1968/// All migrations that will run on the next runtime upgrade.
1969///
1970/// This contains the combined migrations of the last 10 releases. It allows to skip runtime
1971/// upgrades in case governance decides to do so. THE ORDER IS IMPORTANT.
1972pub type Migrations = migrations::Unreleased;
1973
1974/// The runtime migrations per release.
1975#[allow(deprecated, missing_docs)]
1976pub mod migrations {
1977	use super::*;
1978
1979	/// Unreleased migrations. Add new ones here:
1980	pub type Unreleased = (
1981		parachains_shared::migration::MigrateToV1<Runtime>,
1982		parachains_scheduler::migration::MigrateV2ToV3<Runtime>,
1983		// permanent
1984		pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
1985	);
1986}
1987
1988/// Unchecked extrinsic type as expected by this runtime.
1989pub type UncheckedExtrinsic =
1990	generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
1991/// Unchecked signature payload type as expected by this runtime.
1992pub type UncheckedSignaturePayload =
1993	generic::UncheckedSignaturePayload<Address, Signature, TxExtension>;
1994
1995/// Executive: handles dispatch to the various modules.
1996pub type Executive = frame_executive::Executive<
1997	Runtime,
1998	Block,
1999	frame_system::ChainContext<Runtime>,
2000	Runtime,
2001	AllPalletsWithSystem,
2002	Migrations,
2003>;
2004/// The payload being signed in transactions.
2005pub type SignedPayload = generic::SignedPayload<RuntimeCall, TxExtension>;
2006
2007#[cfg(feature = "runtime-benchmarks")]
2008mod benches {
2009	frame_benchmarking::define_benchmarks!(
2010		// Polkadot
2011		// NOTE: Make sure to prefix these with `runtime_common::` so
2012		// the that path resolves correctly in the generated file.
2013		[polkadot_runtime_common::assigned_slots, AssignedSlots]
2014		[polkadot_runtime_common::auctions, Auctions]
2015		[polkadot_runtime_common::crowdloan, Crowdloan]
2016		[polkadot_runtime_common::identity_migrator, IdentityMigrator]
2017		[polkadot_runtime_common::paras_registrar, Registrar]
2018		[polkadot_runtime_common::slots, Slots]
2019		[polkadot_runtime_parachains::configuration, Configuration]
2020		[polkadot_runtime_parachains::disputes, ParasDisputes]
2021		[polkadot_runtime_parachains::disputes::slashing, ParasSlashing]
2022		[polkadot_runtime_parachains::hrmp, Hrmp]
2023		[polkadot_runtime_parachains::inclusion, ParaInclusion]
2024		[polkadot_runtime_parachains::initializer, Initializer]
2025		[polkadot_runtime_parachains::paras, Paras]
2026		[polkadot_runtime_parachains::paras_inherent, ParaInherent]
2027		[polkadot_runtime_parachains::on_demand, OnDemandAssignmentProvider]
2028		[polkadot_runtime_parachains::coretime, Coretime]
2029		// Substrate
2030		[pallet_bags_list, VoterList]
2031		[pallet_balances, Balances]
2032		[pallet_beefy_mmr, BeefyMmrLeaf]
2033		[pallet_conviction_voting, ConvictionVoting]
2034		[frame_election_provider_support, ElectionProviderBench::<Runtime>]
2035		[pallet_identity, Identity]
2036		[pallet_indices, Indices]
2037		[pallet_message_queue, MessageQueue]
2038		[pallet_migrations, MultiBlockMigrations]
2039		[pallet_mmr, Mmr]
2040		[pallet_multisig, Multisig]
2041		[pallet_offences, OffencesBench::<Runtime>]
2042		[pallet_parameters, Parameters]
2043		[pallet_preimage, Preimage]
2044		[pallet_proxy, Proxy]
2045		[pallet_recovery, Recovery]
2046		[pallet_referenda, Referenda]
2047		[pallet_scheduler, Scheduler]
2048		[pallet_session, SessionBench::<Runtime>]
2049		[pallet_sudo, Sudo]
2050		[frame_system, SystemBench::<Runtime>]
2051		[frame_system_extensions, SystemExtensionsBench::<Runtime>]
2052		[pallet_timestamp, Timestamp]
2053		[pallet_transaction_payment, TransactionPayment]
2054		[pallet_treasury, Treasury]
2055		[pallet_utility, Utility]
2056		[pallet_vesting, Vesting]
2057		[pallet_whitelist, Whitelist]
2058		[pallet_asset_rate, AssetRate]
2059		// XCM
2060		[pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
2061		// NOTE: Make sure you point to the individual modules below.
2062		[pallet_xcm_benchmarks::fungible, XcmBalances]
2063		[pallet_xcm_benchmarks::generic, XcmGeneric]
2064	);
2065}
2066
2067sp_api::impl_runtime_apis! {
2068	impl sp_api::Core<Block> for Runtime {
2069		fn version() -> RuntimeVersion {
2070			VERSION
2071		}
2072
2073		fn execute_block(block: Block) {
2074			Executive::execute_block(block);
2075		}
2076
2077		fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
2078			Executive::initialize_block(header)
2079		}
2080	}
2081
2082	impl sp_api::Metadata<Block> for Runtime {
2083		fn metadata() -> OpaqueMetadata {
2084			OpaqueMetadata::new(Runtime::metadata().into())
2085		}
2086
2087		fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
2088			Runtime::metadata_at_version(version)
2089		}
2090
2091		fn metadata_versions() -> alloc::vec::Vec<u32> {
2092			Runtime::metadata_versions()
2093		}
2094	}
2095
2096	impl frame_support::view_functions::runtime_api::RuntimeViewFunction<Block> for Runtime {
2097		fn execute_view_function(id: frame_support::view_functions::ViewFunctionId, input: Vec<u8>) -> Result<Vec<u8>, frame_support::view_functions::ViewFunctionDispatchError> {
2098			Runtime::execute_view_function(id, input)
2099		}
2100	}
2101
2102	impl sp_block_builder::BlockBuilder<Block> for Runtime {
2103		fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
2104			Executive::apply_extrinsic(extrinsic)
2105		}
2106
2107		fn finalize_block() -> <Block as BlockT>::Header {
2108			Executive::finalize_block()
2109		}
2110
2111		fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
2112			data.create_extrinsics()
2113		}
2114
2115		fn check_inherents(
2116			block: Block,
2117			data: sp_inherents::InherentData,
2118		) -> sp_inherents::CheckInherentsResult {
2119			data.check_extrinsics(&block)
2120		}
2121	}
2122
2123	impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
2124		fn validate_transaction(
2125			source: TransactionSource,
2126			tx: <Block as BlockT>::Extrinsic,
2127			block_hash: <Block as BlockT>::Hash,
2128		) -> TransactionValidity {
2129			Executive::validate_transaction(source, tx, block_hash)
2130		}
2131	}
2132
2133	impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
2134		fn offchain_worker(header: &<Block as BlockT>::Header) {
2135			Executive::offchain_worker(header)
2136		}
2137	}
2138
2139	#[api_version(13)]
2140	impl polkadot_primitives::runtime_api::ParachainHost<Block> for Runtime {
2141		fn validators() -> Vec<ValidatorId> {
2142			parachains_runtime_api_impl::validators::<Runtime>()
2143		}
2144
2145		fn validation_code_bomb_limit() -> u32 {
2146			parachains_staging_runtime_api_impl::validation_code_bomb_limit::<Runtime>()
2147		}
2148
2149		fn validator_groups() -> (Vec<Vec<ValidatorIndex>>, GroupRotationInfo<BlockNumber>) {
2150			parachains_runtime_api_impl::validator_groups::<Runtime>()
2151		}
2152
2153		fn availability_cores() -> Vec<CoreState<Hash, BlockNumber>> {
2154			parachains_runtime_api_impl::availability_cores::<Runtime>()
2155		}
2156
2157		fn persisted_validation_data(para_id: ParaId, assumption: OccupiedCoreAssumption)
2158			-> Option<PersistedValidationData<Hash, BlockNumber>> {
2159			parachains_runtime_api_impl::persisted_validation_data::<Runtime>(para_id, assumption)
2160		}
2161
2162		fn assumed_validation_data(
2163			para_id: ParaId,
2164			expected_persisted_validation_data_hash: Hash,
2165		) -> Option<(PersistedValidationData<Hash, BlockNumber>, ValidationCodeHash)> {
2166			parachains_runtime_api_impl::assumed_validation_data::<Runtime>(
2167				para_id,
2168				expected_persisted_validation_data_hash,
2169			)
2170		}
2171
2172		fn check_validation_outputs(
2173			para_id: ParaId,
2174			outputs: polkadot_primitives::CandidateCommitments,
2175		) -> bool {
2176			parachains_runtime_api_impl::check_validation_outputs::<Runtime>(para_id, outputs)
2177		}
2178
2179		fn session_index_for_child() -> SessionIndex {
2180			parachains_runtime_api_impl::session_index_for_child::<Runtime>()
2181		}
2182
2183		fn validation_code(para_id: ParaId, assumption: OccupiedCoreAssumption)
2184			-> Option<ValidationCode> {
2185			parachains_runtime_api_impl::validation_code::<Runtime>(para_id, assumption)
2186		}
2187
2188		fn candidate_pending_availability(para_id: ParaId) -> Option<CommittedCandidateReceipt<Hash>> {
2189			#[allow(deprecated)]
2190			parachains_runtime_api_impl::candidate_pending_availability::<Runtime>(para_id)
2191		}
2192
2193		fn candidate_events() -> Vec<CandidateEvent<Hash>> {
2194			parachains_runtime_api_impl::candidate_events::<Runtime, _>(|ev| {
2195				match ev {
2196					RuntimeEvent::ParaInclusion(ev) => {
2197						Some(ev)
2198					}
2199					_ => None,
2200				}
2201			})
2202		}
2203
2204		fn session_info(index: SessionIndex) -> Option<SessionInfo> {
2205			parachains_runtime_api_impl::session_info::<Runtime>(index)
2206		}
2207
2208		fn session_executor_params(session_index: SessionIndex) -> Option<ExecutorParams> {
2209			parachains_runtime_api_impl::session_executor_params::<Runtime>(session_index)
2210		}
2211
2212		fn dmq_contents(recipient: ParaId) -> Vec<InboundDownwardMessage<BlockNumber>> {
2213			parachains_runtime_api_impl::dmq_contents::<Runtime>(recipient)
2214		}
2215
2216		fn inbound_hrmp_channels_contents(
2217			recipient: ParaId
2218		) -> BTreeMap<ParaId, Vec<InboundHrmpMessage<BlockNumber>>> {
2219			parachains_runtime_api_impl::inbound_hrmp_channels_contents::<Runtime>(recipient)
2220		}
2221
2222		fn validation_code_by_hash(hash: ValidationCodeHash) -> Option<ValidationCode> {
2223			parachains_runtime_api_impl::validation_code_by_hash::<Runtime>(hash)
2224		}
2225
2226		fn on_chain_votes() -> Option<ScrapedOnChainVotes<Hash>> {
2227			parachains_runtime_api_impl::on_chain_votes::<Runtime>()
2228		}
2229
2230		fn submit_pvf_check_statement(
2231			stmt: PvfCheckStatement,
2232			signature: ValidatorSignature,
2233		) {
2234			parachains_runtime_api_impl::submit_pvf_check_statement::<Runtime>(stmt, signature)
2235		}
2236
2237		fn pvfs_require_precheck() -> Vec<ValidationCodeHash> {
2238			parachains_runtime_api_impl::pvfs_require_precheck::<Runtime>()
2239		}
2240
2241		fn validation_code_hash(para_id: ParaId, assumption: OccupiedCoreAssumption)
2242			-> Option<ValidationCodeHash>
2243		{
2244			parachains_runtime_api_impl::validation_code_hash::<Runtime>(para_id, assumption)
2245		}
2246
2247		fn disputes() -> Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)> {
2248			parachains_runtime_api_impl::get_session_disputes::<Runtime>()
2249		}
2250
2251		fn unapplied_slashes(
2252		) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> {
2253			parachains_runtime_api_impl::unapplied_slashes::<Runtime>()
2254		}
2255
2256		fn key_ownership_proof(
2257			validator_id: ValidatorId,
2258		) -> Option<slashing::OpaqueKeyOwnershipProof> {
2259			use codec::Encode;
2260
2261			Historical::prove((PARACHAIN_KEY_TYPE_ID, validator_id))
2262				.map(|p| p.encode())
2263				.map(slashing::OpaqueKeyOwnershipProof::new)
2264		}
2265
2266		fn submit_report_dispute_lost(
2267			dispute_proof: slashing::DisputeProof,
2268			key_ownership_proof: slashing::OpaqueKeyOwnershipProof,
2269		) -> Option<()> {
2270			parachains_runtime_api_impl::submit_unsigned_slashing_report::<Runtime>(
2271				dispute_proof,
2272				key_ownership_proof,
2273			)
2274		}
2275
2276		fn minimum_backing_votes() -> u32 {
2277			parachains_runtime_api_impl::minimum_backing_votes::<Runtime>()
2278		}
2279
2280		fn para_backing_state(para_id: ParaId) -> Option<polkadot_primitives::vstaging::async_backing::BackingState> {
2281			#[allow(deprecated)]
2282			parachains_runtime_api_impl::backing_state::<Runtime>(para_id)
2283		}
2284
2285		fn async_backing_params() -> polkadot_primitives::AsyncBackingParams {
2286			#[allow(deprecated)]
2287			parachains_runtime_api_impl::async_backing_params::<Runtime>()
2288		}
2289
2290		fn approval_voting_params() -> ApprovalVotingParams {
2291			parachains_runtime_api_impl::approval_voting_params::<Runtime>()
2292		}
2293
2294		fn disabled_validators() -> Vec<ValidatorIndex> {
2295			parachains_runtime_api_impl::disabled_validators::<Runtime>()
2296		}
2297
2298		fn node_features() -> NodeFeatures {
2299			parachains_runtime_api_impl::node_features::<Runtime>()
2300		}
2301
2302		fn claim_queue() -> BTreeMap<CoreIndex, VecDeque<ParaId>> {
2303			parachains_runtime_api_impl::claim_queue::<Runtime>()
2304		}
2305
2306		fn candidates_pending_availability(para_id: ParaId) -> Vec<CommittedCandidateReceipt<Hash>> {
2307			parachains_runtime_api_impl::candidates_pending_availability::<Runtime>(para_id)
2308		}
2309
2310		fn backing_constraints(para_id: ParaId) -> Option<Constraints> {
2311			parachains_staging_runtime_api_impl::backing_constraints::<Runtime>(para_id)
2312		}
2313
2314		fn scheduling_lookahead() -> u32 {
2315			parachains_staging_runtime_api_impl::scheduling_lookahead::<Runtime>()
2316		}
2317	}
2318
2319	#[api_version(5)]
2320	impl sp_consensus_beefy::BeefyApi<Block, BeefyId> for Runtime {
2321		fn beefy_genesis() -> Option<BlockNumber> {
2322			pallet_beefy::GenesisBlock::<Runtime>::get()
2323		}
2324
2325		fn validator_set() -> Option<sp_consensus_beefy::ValidatorSet<BeefyId>> {
2326			Beefy::validator_set()
2327		}
2328
2329		fn submit_report_double_voting_unsigned_extrinsic(
2330			equivocation_proof: sp_consensus_beefy::DoubleVotingProof<
2331				BlockNumber,
2332				BeefyId,
2333				BeefySignature,
2334			>,
2335			key_owner_proof: sp_consensus_beefy::OpaqueKeyOwnershipProof,
2336		) -> Option<()> {
2337			let key_owner_proof = key_owner_proof.decode()?;
2338
2339			Beefy::submit_unsigned_double_voting_report(
2340				equivocation_proof,
2341				key_owner_proof,
2342			)
2343		}
2344
2345		fn submit_report_fork_voting_unsigned_extrinsic(
2346			equivocation_proof:
2347				sp_consensus_beefy::ForkVotingProof<
2348					<Block as BlockT>::Header,
2349					BeefyId,
2350					sp_runtime::OpaqueValue
2351				>,
2352			key_owner_proof: sp_consensus_beefy::OpaqueKeyOwnershipProof,
2353		) -> Option<()> {
2354			Beefy::submit_unsigned_fork_voting_report(
2355				equivocation_proof.try_into()?,
2356				key_owner_proof.decode()?,
2357			)
2358		}
2359
2360		fn submit_report_future_block_voting_unsigned_extrinsic(
2361			equivocation_proof: sp_consensus_beefy::FutureBlockVotingProof<BlockNumber, BeefyId>,
2362			key_owner_proof: sp_consensus_beefy::OpaqueKeyOwnershipProof,
2363		) -> Option<()> {
2364			Beefy::submit_unsigned_future_block_voting_report(
2365				equivocation_proof,
2366				key_owner_proof.decode()?,
2367			)
2368		}
2369
2370		fn generate_key_ownership_proof(
2371			_set_id: sp_consensus_beefy::ValidatorSetId,
2372			authority_id: BeefyId,
2373		) -> Option<sp_consensus_beefy::OpaqueKeyOwnershipProof> {
2374			use codec::Encode;
2375
2376			Historical::prove((sp_consensus_beefy::KEY_TYPE, authority_id))
2377				.map(|p| p.encode())
2378				.map(sp_consensus_beefy::OpaqueKeyOwnershipProof::new)
2379		}
2380
2381		fn generate_ancestry_proof(
2382			prev_block_number: BlockNumber,
2383			best_known_block_number: Option<BlockNumber>,
2384		) -> Option<sp_runtime::OpaqueValue> {
2385			use sp_consensus_beefy::AncestryHelper;
2386
2387			BeefyMmrLeaf::generate_proof(prev_block_number, best_known_block_number)
2388				.map(|p| p.encode())
2389				.map(sp_runtime::OpaqueValue::new)
2390		}
2391	}
2392
2393	impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
2394		fn mmr_root() -> Result<mmr::Hash, mmr::Error> {
2395			Ok(pallet_mmr::RootHash::<Runtime>::get())
2396		}
2397
2398		fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
2399			Ok(pallet_mmr::NumberOfLeaves::<Runtime>::get())
2400		}
2401
2402		fn generate_proof(
2403			block_numbers: Vec<BlockNumber>,
2404			best_known_block_number: Option<BlockNumber>,
2405		) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::LeafProof<mmr::Hash>), mmr::Error> {
2406			Mmr::generate_proof(block_numbers, best_known_block_number).map(
2407				|(leaves, proof)| {
2408					(
2409						leaves
2410							.into_iter()
2411							.map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf))
2412							.collect(),
2413						proof,
2414					)
2415				},
2416			)
2417		}
2418
2419		fn verify_proof(leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::LeafProof<mmr::Hash>)
2420			-> Result<(), mmr::Error>
2421		{
2422			let leaves = leaves.into_iter().map(|leaf|
2423				leaf.into_opaque_leaf()
2424				.try_decode()
2425				.ok_or(mmr::Error::Verify)).collect::<Result<Vec<mmr::Leaf>, mmr::Error>>()?;
2426			Mmr::verify_leaves(leaves, proof)
2427		}
2428
2429		fn verify_proof_stateless(
2430			root: mmr::Hash,
2431			leaves: Vec<mmr::EncodableOpaqueLeaf>,
2432			proof: mmr::LeafProof<mmr::Hash>
2433		) -> Result<(), mmr::Error> {
2434			let nodes = leaves.into_iter().map(|leaf|mmr::DataOrHash::Data(leaf.into_opaque_leaf())).collect();
2435			pallet_mmr::verify_leaves_proof::<mmr::Hashing, _>(root, nodes, proof)
2436		}
2437	}
2438
2439	impl pallet_beefy_mmr::BeefyMmrApi<Block, Hash> for RuntimeApi {
2440		fn authority_set_proof() -> sp_consensus_beefy::mmr::BeefyAuthoritySet<Hash> {
2441			BeefyMmrLeaf::authority_set_proof()
2442		}
2443
2444		fn next_authority_set_proof() -> sp_consensus_beefy::mmr::BeefyNextAuthoritySet<Hash> {
2445			BeefyMmrLeaf::next_authority_set_proof()
2446		}
2447	}
2448
2449	impl fg_primitives::GrandpaApi<Block> for Runtime {
2450		fn grandpa_authorities() -> Vec<(GrandpaId, u64)> {
2451			Grandpa::grandpa_authorities()
2452		}
2453
2454		fn current_set_id() -> fg_primitives::SetId {
2455			pallet_grandpa::CurrentSetId::<Runtime>::get()
2456		}
2457
2458		fn submit_report_equivocation_unsigned_extrinsic(
2459			equivocation_proof: fg_primitives::EquivocationProof<
2460				<Block as BlockT>::Hash,
2461				sp_runtime::traits::NumberFor<Block>,
2462			>,
2463			key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,
2464		) -> Option<()> {
2465			let key_owner_proof = key_owner_proof.decode()?;
2466
2467			Grandpa::submit_unsigned_equivocation_report(
2468				equivocation_proof,
2469				key_owner_proof,
2470			)
2471		}
2472
2473		fn generate_key_ownership_proof(
2474			_set_id: fg_primitives::SetId,
2475			authority_id: fg_primitives::AuthorityId,
2476		) -> Option<fg_primitives::OpaqueKeyOwnershipProof> {
2477			use codec::Encode;
2478
2479			Historical::prove((fg_primitives::KEY_TYPE, authority_id))
2480				.map(|p| p.encode())
2481				.map(fg_primitives::OpaqueKeyOwnershipProof::new)
2482		}
2483	}
2484
2485	impl sp_consensus_babe::BabeApi<Block> for Runtime {
2486		fn configuration() -> sp_consensus_babe::BabeConfiguration {
2487			let epoch_config = Babe::epoch_config().unwrap_or(BABE_GENESIS_EPOCH_CONFIG);
2488			sp_consensus_babe::BabeConfiguration {
2489				slot_duration: Babe::slot_duration(),
2490				epoch_length: EpochDuration::get(),
2491				c: epoch_config.c,
2492				authorities: Babe::authorities().to_vec(),
2493				randomness: Babe::randomness(),
2494				allowed_slots: epoch_config.allowed_slots,
2495			}
2496		}
2497
2498		fn current_epoch_start() -> sp_consensus_babe::Slot {
2499			Babe::current_epoch_start()
2500		}
2501
2502		fn current_epoch() -> sp_consensus_babe::Epoch {
2503			Babe::current_epoch()
2504		}
2505
2506		fn next_epoch() -> sp_consensus_babe::Epoch {
2507			Babe::next_epoch()
2508		}
2509
2510		fn generate_key_ownership_proof(
2511			_slot: sp_consensus_babe::Slot,
2512			authority_id: sp_consensus_babe::AuthorityId,
2513		) -> Option<sp_consensus_babe::OpaqueKeyOwnershipProof> {
2514			use codec::Encode;
2515
2516			Historical::prove((sp_consensus_babe::KEY_TYPE, authority_id))
2517				.map(|p| p.encode())
2518				.map(sp_consensus_babe::OpaqueKeyOwnershipProof::new)
2519		}
2520
2521		fn submit_report_equivocation_unsigned_extrinsic(
2522			equivocation_proof: sp_consensus_babe::EquivocationProof<<Block as BlockT>::Header>,
2523			key_owner_proof: sp_consensus_babe::OpaqueKeyOwnershipProof,
2524		) -> Option<()> {
2525			let key_owner_proof = key_owner_proof.decode()?;
2526
2527			Babe::submit_unsigned_equivocation_report(
2528				equivocation_proof,
2529				key_owner_proof,
2530			)
2531		}
2532	}
2533
2534	impl sp_authority_discovery::AuthorityDiscoveryApi<Block> for Runtime {
2535		fn authorities() -> Vec<AuthorityDiscoveryId> {
2536			parachains_runtime_api_impl::relevant_authority_ids::<Runtime>()
2537		}
2538	}
2539
2540	impl sp_session::SessionKeys<Block> for Runtime {
2541		fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
2542			SessionKeys::generate(seed)
2543		}
2544
2545		fn decode_session_keys(
2546			encoded: Vec<u8>,
2547		) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
2548			SessionKeys::decode_into_raw_public_keys(&encoded)
2549		}
2550	}
2551
2552	impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
2553		fn account_nonce(account: AccountId) -> Nonce {
2554			System::account_nonce(account)
2555		}
2556	}
2557
2558	impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<
2559		Block,
2560		Balance,
2561	> for Runtime {
2562		fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {
2563			TransactionPayment::query_info(uxt, len)
2564		}
2565		fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {
2566			TransactionPayment::query_fee_details(uxt, len)
2567		}
2568		fn query_weight_to_fee(weight: Weight) -> Balance {
2569			TransactionPayment::weight_to_fee(weight)
2570		}
2571		fn query_length_to_fee(length: u32) -> Balance {
2572			TransactionPayment::length_to_fee(length)
2573		}
2574	}
2575
2576	impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi<Block, Balance, RuntimeCall>
2577		for Runtime
2578	{
2579		fn query_call_info(call: RuntimeCall, len: u32) -> RuntimeDispatchInfo<Balance> {
2580			TransactionPayment::query_call_info(call, len)
2581		}
2582		fn query_call_fee_details(call: RuntimeCall, len: u32) -> FeeDetails<Balance> {
2583			TransactionPayment::query_call_fee_details(call, len)
2584		}
2585		fn query_weight_to_fee(weight: Weight) -> Balance {
2586			TransactionPayment::weight_to_fee(weight)
2587		}
2588		fn query_length_to_fee(length: u32) -> Balance {
2589			TransactionPayment::length_to_fee(length)
2590		}
2591	}
2592
2593	impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
2594		fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
2595			let acceptable_assets = vec![AssetId(xcm_config::TokenLocation::get())];
2596			XcmPallet::query_acceptable_payment_assets(xcm_version, acceptable_assets)
2597		}
2598
2599		fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
2600			let latest_asset_id: Result<AssetId, ()> = asset.clone().try_into();
2601			match latest_asset_id {
2602				Ok(asset_id) if asset_id.0 == xcm_config::TokenLocation::get() => {
2603					// for native token
2604					Ok(WeightToFee::weight_to_fee(&weight))
2605				},
2606				Ok(asset_id) => {
2607					log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - unhandled asset_id: {asset_id:?}!");
2608					Err(XcmPaymentApiError::AssetNotFound)
2609				},
2610				Err(_) => {
2611					log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - failed to convert asset: {asset:?}!");
2612					Err(XcmPaymentApiError::VersionedConversionFailed)
2613				}
2614			}
2615		}
2616
2617		fn query_xcm_weight(message: VersionedXcm<()>) -> Result<Weight, XcmPaymentApiError> {
2618			XcmPallet::query_xcm_weight(message)
2619		}
2620
2621		fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<VersionedAssets, XcmPaymentApiError> {
2622			XcmPallet::query_delivery_fees(destination, message)
2623		}
2624	}
2625
2626	impl xcm_runtime_apis::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
2627		fn dry_run_call(origin: OriginCaller, call: RuntimeCall, result_xcms_version: xcm::prelude::XcmVersion) -> Result<CallDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
2628			XcmPallet::dry_run_call::<Runtime, xcm_config::XcmRouter, OriginCaller, RuntimeCall>(origin, call, result_xcms_version)
2629		}
2630
2631		fn dry_run_xcm(origin_location: VersionedLocation, xcm: VersionedXcm<RuntimeCall>) -> Result<XcmDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
2632			XcmPallet::dry_run_xcm::<Runtime, xcm_config::XcmRouter, RuntimeCall, xcm_config::XcmConfig>(origin_location, xcm)
2633		}
2634	}
2635
2636	impl xcm_runtime_apis::conversions::LocationToAccountApi<Block, AccountId> for Runtime {
2637		fn convert_location(location: VersionedLocation) -> Result<
2638			AccountId,
2639			xcm_runtime_apis::conversions::Error
2640		> {
2641			xcm_runtime_apis::conversions::LocationToAccountHelper::<
2642				AccountId,
2643				xcm_config::LocationConverter,
2644			>::convert_location(location)
2645		}
2646	}
2647
2648	#[cfg(feature = "try-runtime")]
2649	impl frame_try_runtime::TryRuntime<Block> for Runtime {
2650		fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
2651			log::info!("try-runtime::on_runtime_upgrade westend.");
2652			let weight = Executive::try_runtime_upgrade(checks).unwrap();
2653			(weight, BlockWeights::get().max_block)
2654		}
2655
2656		fn execute_block(
2657			block: Block,
2658			state_root_check: bool,
2659			signature_check: bool,
2660			select: frame_try_runtime::TryStateSelect,
2661		) -> Weight {
2662			// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
2663			// have a backtrace here.
2664			Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
2665		}
2666	}
2667
2668	#[cfg(feature = "runtime-benchmarks")]
2669	impl frame_benchmarking::Benchmark<Block> for Runtime {
2670		fn benchmark_metadata(extra: bool) -> (
2671			Vec<frame_benchmarking::BenchmarkList>,
2672			Vec<frame_support::traits::StorageInfo>,
2673		) {
2674			use frame_benchmarking::BenchmarkList;
2675			use frame_support::traits::StorageInfoTrait;
2676
2677			use pallet_session_benchmarking::Pallet as SessionBench;
2678			use pallet_offences_benchmarking::Pallet as OffencesBench;
2679			use pallet_election_provider_support_benchmarking::Pallet as ElectionProviderBench;
2680			use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
2681			use frame_system_benchmarking::Pallet as SystemBench;
2682			use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
2683
2684			type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::<Runtime>;
2685			type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::<Runtime>;
2686
2687			let mut list = Vec::<BenchmarkList>::new();
2688			list_benchmarks!(list, extra);
2689
2690			let storage_info = AllPalletsWithSystem::storage_info();
2691			return (list, storage_info)
2692		}
2693
2694		#[allow(non_local_definitions)]
2695		fn dispatch_benchmark(
2696			config: frame_benchmarking::BenchmarkConfig,
2697		) -> Result<
2698			Vec<frame_benchmarking::BenchmarkBatch>,
2699			alloc::string::String,
2700		> {
2701			use frame_support::traits::WhitelistedStorageKeys;
2702			use frame_benchmarking::{BenchmarkBatch, BenchmarkError};
2703			use sp_storage::TrackedStorageKey;
2704			// Trying to add benchmarks directly to some pallets caused cyclic dependency issues.
2705			// To get around that, we separated the benchmarks into its own crate.
2706			use pallet_session_benchmarking::Pallet as SessionBench;
2707			use pallet_offences_benchmarking::Pallet as OffencesBench;
2708			use pallet_election_provider_support_benchmarking::Pallet as ElectionProviderBench;
2709			use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
2710			use frame_system_benchmarking::Pallet as SystemBench;
2711			use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
2712
2713			impl pallet_session_benchmarking::Config for Runtime {}
2714			impl pallet_offences_benchmarking::Config for Runtime {}
2715			impl pallet_election_provider_support_benchmarking::Config for Runtime {}
2716
2717			use xcm_config::{AssetHub, TokenLocation};
2718
2719			use alloc::boxed::Box;
2720
2721			parameter_types! {
2722				pub ExistentialDepositAsset: Option<Asset> = Some((
2723					TokenLocation::get(),
2724					ExistentialDeposit::get()
2725				).into());
2726				pub AssetHubParaId: ParaId = pallet_staking_async_rc_runtime_constants::system_parachain::ASSET_HUB_ID.into();
2727				pub const RandomParaId: ParaId = ParaId::new(43211234);
2728			}
2729
2730			impl pallet_xcm::benchmarking::Config for Runtime {
2731				type DeliveryHelper = (
2732					polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper<
2733						xcm_config::XcmConfig,
2734						ExistentialDepositAsset,
2735						xcm_config::PriceForChildParachainDelivery,
2736						AssetHubParaId,
2737						Dmp,
2738					>,
2739					polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper<
2740						xcm_config::XcmConfig,
2741						ExistentialDepositAsset,
2742						xcm_config::PriceForChildParachainDelivery,
2743						RandomParaId,
2744						Dmp,
2745					>
2746				);
2747
2748				fn reachable_dest() -> Option<Location> {
2749					Some(crate::xcm_config::AssetHub::get())
2750				}
2751
2752				fn teleportable_asset_and_dest() -> Option<(Asset, Location)> {
2753					// Relay/native token can be teleported to/from AH.
2754					Some((
2755						Asset { fun: Fungible(ExistentialDeposit::get()), id: AssetId(Here.into()) },
2756						crate::xcm_config::AssetHub::get(),
2757					))
2758				}
2759
2760				fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> {
2761					// Relay can reserve transfer native token to some random parachain.
2762					Some((
2763						Asset {
2764							fun: Fungible(ExistentialDeposit::get()),
2765							id: AssetId(Here.into())
2766						},
2767						crate::Junction::Parachain(RandomParaId::get().into()).into(),
2768					))
2769				}
2770
2771				fn set_up_complex_asset_transfer(
2772				) -> Option<(Assets, u32, Location, Box<dyn FnOnce()>)> {
2773					// Relay supports only native token, either reserve transfer it to non-system parachains,
2774					// or teleport it to system parachain. Use the teleport case for benchmarking as it's
2775					// slightly heavier.
2776
2777					// Relay/native token can be teleported to/from AH.
2778					let native_location = Here.into();
2779					let dest = crate::xcm_config::AssetHub::get();
2780					pallet_xcm::benchmarking::helpers::native_teleport_as_asset_transfer::<Runtime>(
2781						native_location,
2782						dest
2783					)
2784				}
2785
2786				fn get_asset() -> Asset {
2787					Asset {
2788						id: AssetId(Location::here()),
2789						fun: Fungible(ExistentialDeposit::get()),
2790					}
2791				}
2792			}
2793			impl frame_system_benchmarking::Config for Runtime {}
2794			impl polkadot_runtime_parachains::disputes::slashing::benchmarking::Config for Runtime {}
2795
2796			use xcm::latest::{
2797				AssetId, Fungibility::*, InteriorLocation, Junction, Junctions::*,
2798				Asset, Assets, Location, NetworkId, Response,
2799			};
2800
2801			impl pallet_xcm_benchmarks::Config for Runtime {
2802				type XcmConfig = xcm_config::XcmConfig;
2803				type AccountIdConverter = xcm_config::LocationConverter;
2804				type DeliveryHelper = polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper<
2805					xcm_config::XcmConfig,
2806					ExistentialDepositAsset,
2807					xcm_config::PriceForChildParachainDelivery,
2808					AssetHubParaId,
2809					Dmp,
2810				>;
2811				fn valid_destination() -> Result<Location, BenchmarkError> {
2812					Ok(AssetHub::get())
2813				}
2814				fn worst_case_holding(_depositable_count: u32) -> Assets {
2815					// Westend only knows about WND.
2816					vec![Asset{
2817						id: AssetId(TokenLocation::get()),
2818						fun: Fungible(1_000_000 * UNITS),
2819					}].into()
2820				}
2821			}
2822
2823			parameter_types! {
2824				pub TrustedTeleporter: Option<(Location, Asset)> = Some((
2825					AssetHub::get(),
2826					Asset { fun: Fungible(1 * UNITS), id: AssetId(TokenLocation::get()) },
2827				));
2828				pub const TrustedReserve: Option<(Location, Asset)> = None;
2829			}
2830
2831			impl pallet_xcm_benchmarks::fungible::Config for Runtime {
2832				type TransactAsset = Balances;
2833
2834				type CheckedAccount = xcm_config::LocalCheckAccount;
2835				type TrustedTeleporter = TrustedTeleporter;
2836				type TrustedReserve = TrustedReserve;
2837
2838				fn get_asset() -> Asset {
2839					Asset {
2840						id: AssetId(TokenLocation::get()),
2841						fun: Fungible(1 * UNITS),
2842					}
2843				}
2844			}
2845
2846			impl pallet_xcm_benchmarks::generic::Config for Runtime {
2847				type TransactAsset = Balances;
2848				type RuntimeCall = RuntimeCall;
2849
2850				fn worst_case_response() -> (u64, Response) {
2851					(0u64, Response::Version(Default::default()))
2852				}
2853
2854				fn worst_case_asset_exchange() -> Result<(Assets, Assets), BenchmarkError> {
2855					// Westend doesn't support asset exchanges
2856					Err(BenchmarkError::Skip)
2857				}
2858
2859				fn universal_alias() -> Result<(Location, Junction), BenchmarkError> {
2860					// The XCM executor of Westend doesn't have a configured `UniversalAliases`
2861					Err(BenchmarkError::Skip)
2862				}
2863
2864				fn transact_origin_and_runtime_call() -> Result<(Location, RuntimeCall), BenchmarkError> {
2865					Ok((AssetHub::get(), frame_system::Call::remark_with_event { remark: vec![] }.into()))
2866				}
2867
2868				fn subscribe_origin() -> Result<Location, BenchmarkError> {
2869					Ok(AssetHub::get())
2870				}
2871
2872				fn claimable_asset() -> Result<(Location, Location, Assets), BenchmarkError> {
2873					let origin = AssetHub::get();
2874					let assets: Assets = (AssetId(TokenLocation::get()), 1_000 * UNITS).into();
2875					let ticket = Location { parents: 0, interior: Here };
2876					Ok((origin, ticket, assets))
2877				}
2878
2879				fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError> {
2880					Ok((Asset {
2881						id: AssetId(TokenLocation::get()),
2882						fun: Fungible(1_000_000 * UNITS),
2883					}, WeightLimit::Limited(Weight::from_parts(5000, 5000))))
2884				}
2885
2886				fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {
2887					// Westend doesn't support asset locking
2888					Err(BenchmarkError::Skip)
2889				}
2890
2891				fn export_message_origin_and_destination(
2892				) -> Result<(Location, NetworkId, InteriorLocation), BenchmarkError> {
2893					// Westend doesn't support exporting messages
2894					Err(BenchmarkError::Skip)
2895				}
2896
2897				fn alias_origin() -> Result<(Location, Location), BenchmarkError> {
2898					let origin = Location::new(0, [Parachain(1000)]);
2899					let target = Location::new(0, [Parachain(1000), AccountId32 { id: [128u8; 32], network: None }]);
2900					Ok((origin, target))
2901				}
2902			}
2903
2904			type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::<Runtime>;
2905			type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::<Runtime>;
2906
2907			let whitelist: Vec<TrackedStorageKey> = AllPalletsWithSystem::whitelisted_storage_keys();
2908
2909			let mut batches = Vec::<BenchmarkBatch>::new();
2910			let params = (&config, &whitelist);
2911
2912			add_benchmarks!(params, batches);
2913
2914			Ok(batches)
2915		}
2916	}
2917
2918	impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
2919		fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
2920			build_state::<RuntimeGenesisConfig>(config)
2921		}
2922
2923		fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
2924			get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset)
2925		}
2926
2927		fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
2928			genesis_config_presets::preset_names()
2929		}
2930	}
2931
2932	impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
2933		fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
2934			XcmPallet::is_trusted_reserve(asset, location)
2935		}
2936		fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
2937			XcmPallet::is_trusted_teleporter(asset, location)
2938		}
2939	}
2940}