penpal_runtime/
lib.rs

1// This file is part of Cumulus.
2// SPDX-License-Identifier: Unlicense
3
4// This is free and unencumbered software released into the public domain.
5
6// Anyone is free to copy, modify, publish, use, compile, sell, or
7// distribute this software, either in source code form or as a compiled
8// binary, for any purpose, commercial or non-commercial, and by any
9// means.
10
11// In jurisdictions that recognize copyright laws, the author or authors
12// of this software dedicate any and all copyright interest in the
13// software to the public domain. We make this dedication for the benefit
14// of the public at large and to the detriment of our heirs and
15// successors. We intend this dedication to be an overt act of
16// relinquishment in perpetuity of all present and future rights to this
17// software under copyright law.
18
19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25// OTHER DEALINGS IN THE SOFTWARE.
26
27// For more information, please refer to <http://unlicense.org/>
28
29//! The PenPal runtime is designed as a test runtime that can be created with an arbitrary `ParaId`,
30//! such that multiple instances of the parachain can be on the same parent relay. Ensure that you
31//! have enough nodes running to support this or you will get scheduling errors.
32//!
33//! The PenPal runtime's primary use is for testing interactions between System parachains and
34//! other chains that are not trusted teleporters.
35
36#![cfg_attr(not(feature = "std"), no_std)]
37// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
38#![recursion_limit = "256"]
39
40// Make the WASM binary available.
41#[cfg(feature = "std")]
42include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
43
44mod genesis_config_presets;
45mod weights;
46pub mod xcm_config;
47
48extern crate alloc;
49
50use alloc::{vec, vec::Vec};
51pub use assets_common::local_and_foreign_assets::ForeignAssetReserveData;
52use assets_common::{
53	foreign_creators::ForeignCreators,
54	local_and_foreign_assets::{LocalFromLeft, TargetFromLeft},
55	AssetIdForTrustBackedAssetsConvert,
56};
57use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
58use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
59use frame_support::{
60	construct_runtime, derive_impl,
61	dispatch::DispatchClass,
62	genesis_builder_helper::{build_state, get_preset},
63	ord_parameter_types,
64	pallet_prelude::Weight,
65	parameter_types,
66	traits::{
67		tokens::{fungible, fungibles, imbalance::ResolveAssetTo},
68		AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, Everything,
69		TransformOrigin,
70	},
71	weights::{
72		constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, FeePolynomial,
73		WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
74	},
75	PalletId,
76};
77use frame_system::{
78	limits::{BlockLength, BlockWeights},
79	EnsureRoot, EnsureSigned, EnsureSignedBy,
80};
81use pallet_revive::evm::runtime::EthExtra;
82use parachains_common::{
83	impls::{AssetsToBlockAuthor, NonZeroIssuance},
84	message_queue::{NarrowOriginToSibling, ParaIdToSibling},
85	AccountId, Balance, BlockNumber, Hash, Header, Nonce, Signature,
86};
87use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
88use smallvec::smallvec;
89use sp_api::impl_runtime_apis;
90pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
91use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
92use sp_runtime::{
93	generic, impl_opaque_keys,
94	traits::{AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT},
95	transaction_validity::{TransactionSource, TransactionValidity},
96	ApplyExtrinsicResult, FixedU128,
97};
98pub use sp_runtime::{traits::ConvertInto, MultiAddress, Perbill, Permill};
99use testnet_parachains_constants::westend::{consensus::*, time::*};
100use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
101use xcm::{
102	latest::prelude::{AssetId as AssetLocationId, BodyId},
103	Version as XcmVersion, VersionedAsset, VersionedAssetId, VersionedAssets, VersionedLocation,
104	VersionedXcm,
105};
106use xcm_runtime_apis::{
107	dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
108	fees::Error as XcmPaymentApiError,
109};
110
111#[cfg(any(feature = "std", test))]
112pub use sp_runtime::BuildStorage;
113#[cfg(feature = "std")]
114use sp_version::NativeVersion;
115use sp_version::RuntimeVersion;
116use xcm_config::{
117	ForeignAssetsAssetId, LocationToAccountId, XcmConfig, XcmOriginToTransactDispatchOrigin,
118};
119
120/// The address format for describing accounts.
121pub type Address = MultiAddress<AccountId, ()>;
122
123/// Block type as expected by this runtime.
124pub type Block = generic::Block<Header, UncheckedExtrinsic>;
125
126/// A Block signed with a Justification
127pub type SignedBlock = generic::SignedBlock<Block>;
128
129/// BlockId type as expected by this runtime.
130pub type BlockId = generic::BlockId<Block>;
131
132// Id used for identifying assets.
133pub type AssetId = u32;
134
135/// The extension to the basic transaction logic.
136pub type TxExtension = (
137	frame_system::AuthorizeCall<Runtime>,
138	frame_system::CheckNonZeroSender<Runtime>,
139	frame_system::CheckSpecVersion<Runtime>,
140	frame_system::CheckTxVersion<Runtime>,
141	frame_system::CheckGenesis<Runtime>,
142	frame_system::CheckEra<Runtime>,
143	frame_system::CheckNonce<Runtime>,
144	frame_system::CheckWeight<Runtime>,
145	pallet_asset_tx_payment::ChargeAssetTxPayment<Runtime>,
146	frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
147	pallet_revive::evm::tx_extension::SetOrigin<Runtime>,
148	frame_system::WeightReclaim<Runtime>,
149);
150
151/// Default extensions applied to Ethereum transactions.
152#[derive(Clone, PartialEq, Eq, Debug)]
153pub struct EthExtraImpl;
154
155impl EthExtra for EthExtraImpl {
156	type Config = Runtime;
157	type Extension = TxExtension;
158
159	fn get_eth_extension(nonce: u32, tip: Balance) -> Self::Extension {
160		(
161			frame_system::AuthorizeCall::<Runtime>::new(),
162			frame_system::CheckNonZeroSender::<Runtime>::new(),
163			frame_system::CheckSpecVersion::<Runtime>::new(),
164			frame_system::CheckTxVersion::<Runtime>::new(),
165			frame_system::CheckGenesis::<Runtime>::new(),
166			frame_system::CheckEra::<Runtime>::from(generic::Era::Immortal),
167			frame_system::CheckNonce::<Runtime>::from(nonce),
168			frame_system::CheckWeight::<Runtime>::new(),
169			pallet_asset_tx_payment::ChargeAssetTxPayment::<Runtime>::from(tip, None),
170			frame_metadata_hash_extension::CheckMetadataHash::<Runtime>::new(false),
171			pallet_revive::evm::tx_extension::SetOrigin::<Runtime>::new_from_eth_transaction(),
172			frame_system::WeightReclaim::<Runtime>::new(),
173		)
174			.into()
175	}
176}
177
178/// Unchecked extrinsic type as expected by this runtime.
179pub type UncheckedExtrinsic =
180	pallet_revive::evm::runtime::UncheckedExtrinsic<Address, Signature, EthExtraImpl>;
181
182pub type Migrations = (
183	pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckingAccount>,
184	pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,
185	pallet_session::migrations::v1::MigrateV0ToV1<
186		Runtime,
187		pallet_session::migrations::v1::InitOffenceSeverity<Runtime>,
188	>,
189);
190
191/// Executive: handles dispatch to the various modules.
192pub type Executive = frame_executive::Executive<
193	Runtime,
194	Block,
195	frame_system::ChainContext<Runtime>,
196	Runtime,
197	AllPalletsWithSystem,
198>;
199
200/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
201/// node's balance type.
202///
203/// This should typically create a mapping between the following ranges:
204///   - `[0, MAXIMUM_BLOCK_WEIGHT]`
205///   - `[Balance::min, Balance::max]`
206///
207/// Yet, it can be used for any other sort of change to weight-fee. Some examples being:
208///   - Setting it to `0` will essentially disable the weight fee.
209///   - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
210pub struct WeightToFee;
211impl frame_support::weights::WeightToFee for WeightToFee {
212	type Balance = Balance;
213
214	fn weight_to_fee(weight: &Weight) -> Self::Balance {
215		let time_poly: FeePolynomial<Balance> = RefTimeToFee::polynomial().into();
216		let proof_poly: FeePolynomial<Balance> = ProofSizeToFee::polynomial().into();
217
218		// Take the maximum instead of the sum to charge by the more scarce resource.
219		time_poly.eval(weight.ref_time()).max(proof_poly.eval(weight.proof_size()))
220	}
221}
222
223/// Maps the reference time component of `Weight` to a fee.
224pub struct RefTimeToFee;
225impl WeightToFeePolynomial for RefTimeToFee {
226	type Balance = Balance;
227	fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
228		let p = MILLIUNIT / 10;
229		let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
230
231		smallvec![WeightToFeeCoefficient {
232			degree: 1,
233			negative: false,
234			coeff_frac: Perbill::from_rational(p % q, q),
235			coeff_integer: p / q,
236		}]
237	}
238}
239
240/// Maps the proof size component of `Weight` to a fee.
241pub struct ProofSizeToFee;
242impl WeightToFeePolynomial for ProofSizeToFee {
243	type Balance = Balance;
244	fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
245		// Map 10kb proof to 1 CENT.
246		let p = MILLIUNIT / 10;
247		let q = 10_000;
248
249		smallvec![WeightToFeeCoefficient {
250			degree: 1,
251			negative: false,
252			coeff_frac: Perbill::from_rational(p % q, q),
253			coeff_integer: p / q,
254		}]
255	}
256}
257/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
258/// the specifics of the runtime. They can then be made to be agnostic over specific formats
259/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
260/// to even the core data structures.
261pub mod opaque {
262	use super::*;
263	use sp_runtime::{generic, traits::BlakeTwo256};
264
265	pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
266	/// Opaque block header type.
267	pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
268	/// Opaque block type.
269	pub type Block = generic::Block<Header, UncheckedExtrinsic>;
270	/// Opaque block identifier type.
271	pub type BlockId = generic::BlockId<Block>;
272}
273
274impl_opaque_keys! {
275	pub struct SessionKeys {
276		pub aura: Aura,
277	}
278}
279
280#[sp_version::runtime_version]
281pub const VERSION: RuntimeVersion = RuntimeVersion {
282	spec_name: alloc::borrow::Cow::Borrowed("penpal-parachain"),
283	impl_name: alloc::borrow::Cow::Borrowed("penpal-parachain"),
284	authoring_version: 1,
285	spec_version: 1,
286	impl_version: 0,
287	apis: RUNTIME_API_VERSIONS,
288	transaction_version: 1,
289	system_version: 1,
290};
291
292// Unit = the base number of indivisible units for balances
293pub const UNIT: Balance = 1_000_000_000_000;
294pub const MILLIUNIT: Balance = 1_000_000_000;
295pub const MICROUNIT: Balance = 1_000_000;
296
297/// The existential deposit. Set to 1/10 of the Connected Relay Chain.
298pub const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT;
299
300/// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is
301/// used to limit the maximal weight of a single extrinsic.
302const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5);
303
304/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used by
305/// `Operational` extrinsics.
306const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
307
308/// We allow for 0.5 of a second of compute with a 12 second average block time.
309const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
310	WEIGHT_REF_TIME_PER_SECOND.saturating_div(2),
311	cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
312);
313
314/// The version information used to identify this runtime when compiled natively.
315#[cfg(feature = "std")]
316pub fn native_version() -> NativeVersion {
317	NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
318}
319
320parameter_types! {
321	pub const Version: RuntimeVersion = VERSION;
322
323	// This part is copied from Substrate's `bin/node/runtime/src/lib.rs`.
324	//  The `RuntimeBlockLength` and `RuntimeBlockWeights` exist here because the
325	// `DeletionWeightLimit` and `DeletionQueueDepth` depend on those to parameterize
326	// the lazy contract deletion.
327	pub RuntimeBlockLength: BlockLength =
328		BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
329	pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
330		.base_block(BlockExecutionWeight::get())
331		.for_class(DispatchClass::all(), |weights| {
332			weights.base_extrinsic = ExtrinsicBaseWeight::get();
333		})
334		.for_class(DispatchClass::Normal, |weights| {
335			weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
336		})
337		.for_class(DispatchClass::Operational, |weights| {
338			weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
339			// Operational transactions have some extra reserved space, so that they
340			// are included even if block reached `MAXIMUM_BLOCK_WEIGHT`.
341			weights.reserved = Some(
342				MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
343			);
344		})
345		.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
346		.build_or_panic();
347	pub const SS58Prefix: u16 = 42;
348}
349
350// Configure FRAME pallets to include in runtime.
351
352#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
353impl frame_system::Config for Runtime {
354	/// The identifier used to distinguish between accounts.
355	type AccountId = AccountId;
356	/// The aggregated dispatch type that is available for extrinsics.
357	type RuntimeCall = RuntimeCall;
358	/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
359	type Lookup = AccountIdLookup<AccountId, ()>;
360	/// The index type for storing how many extrinsics an account has signed.
361	type Nonce = Nonce;
362	/// The type for hashing blocks and tries.
363	type Hash = Hash;
364	/// The hashing algorithm used.
365	type Hashing = BlakeTwo256;
366	/// The block type.
367	type Block = Block;
368	/// The ubiquitous event type.
369	type RuntimeEvent = RuntimeEvent;
370	/// The ubiquitous origin type.
371	type RuntimeOrigin = RuntimeOrigin;
372	/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
373	type BlockHashCount = BlockHashCount;
374	/// Runtime version.
375	type Version = Version;
376	/// Converts a module to an index of this module in the runtime.
377	type PalletInfo = PalletInfo;
378	/// The data to be stored in an account.
379	type AccountData = pallet_balances::AccountData<Balance>;
380	/// What to do if a new account is created.
381	type OnNewAccount = ();
382	/// What to do if an account is fully reaped from the system.
383	type OnKilledAccount = ();
384	/// The weight of database operations that the runtime can invoke.
385	type DbWeight = RocksDbWeight;
386	/// The basic call filter to use in dispatchable.
387	type BaseCallFilter = Everything;
388	/// Weight information for the extrinsics of this pallet.
389	type SystemWeightInfo = ();
390	/// Block & extrinsics weights: base values and limits.
391	type BlockWeights = RuntimeBlockWeights;
392	/// The maximum length of a block (in bytes).
393	type BlockLength = RuntimeBlockLength;
394	/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
395	type SS58Prefix = SS58Prefix;
396	/// The action to take on a Runtime Upgrade
397	type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
398	type MaxConsumers = frame_support::traits::ConstU32<16>;
399	type SingleBlockMigrations = Migrations;
400}
401
402impl pallet_timestamp::Config for Runtime {
403	/// A timestamp: milliseconds since the unix epoch.
404	type Moment = u64;
405	type OnTimestampSet = Aura;
406	type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
407	type WeightInfo = ();
408}
409
410impl pallet_authorship::Config for Runtime {
411	type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
412	type EventHandler = (CollatorSelection,);
413}
414
415parameter_types! {
416	pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT;
417}
418
419impl pallet_balances::Config for Runtime {
420	type MaxLocks = ConstU32<50>;
421	/// The type for recording an account's balance.
422	type Balance = Balance;
423	/// The ubiquitous event type.
424	type RuntimeEvent = RuntimeEvent;
425	type DustRemoval = ();
426	type ExistentialDeposit = ExistentialDeposit;
427	type AccountStore = System;
428	type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
429	type MaxReserves = ConstU32<50>;
430	type ReserveIdentifier = [u8; 8];
431	type RuntimeHoldReason = RuntimeHoldReason;
432	type RuntimeFreezeReason = RuntimeFreezeReason;
433	type FreezeIdentifier = ();
434	type MaxFreezes = ConstU32<0>;
435	type DoneSlashHandler = ();
436}
437
438parameter_types! {
439	/// Relay Chain `TransactionByteFee` / 10
440	pub const TransactionByteFee: Balance = 10 * MICROUNIT;
441}
442
443impl pallet_transaction_payment::Config for Runtime {
444	type RuntimeEvent = RuntimeEvent;
445	type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, ()>;
446	type WeightToFee = pallet_revive::evm::fees::BlockRatioFee<1, 1, Self, Balance>;
447	type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
448	type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
449	type OperationalFeeMultiplier = ConstU8<5>;
450	type WeightInfo = ();
451}
452
453parameter_types! {
454	pub const AssetDeposit: Balance = 0;
455	pub const AssetAccountDeposit: Balance = 0;
456	pub const ApprovalDeposit: Balance = 0;
457	pub const AssetsStringLimit: u32 = 50;
458	pub const MetadataDepositBase: Balance = 0;
459	pub const MetadataDepositPerByte: Balance = 0;
460}
461
462// /// We allow root and the Relay Chain council to execute privileged asset operations.
463// pub type AssetsForceOrigin =
464// 	EnsureOneOf<EnsureRoot<AccountId>, EnsureXcm<IsMajorityOfBody<KsmLocation, ExecutiveBody>>>;
465
466pub type TrustBackedAssetsInstance = pallet_assets::Instance1;
467
468impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
469	type RuntimeEvent = RuntimeEvent;
470	type Balance = Balance;
471	type AssetId = AssetId;
472	type AssetIdParameter = codec::Compact<AssetId>;
473	type ReserveData = ();
474	type Currency = Balances;
475	type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
476	type ForceOrigin = EnsureRoot<AccountId>;
477	type AssetDeposit = AssetDeposit;
478	type MetadataDepositBase = MetadataDepositBase;
479	type MetadataDepositPerByte = MetadataDepositPerByte;
480	type ApprovalDeposit = ApprovalDeposit;
481	type StringLimit = AssetsStringLimit;
482	type Holder = ();
483	type Freezer = ();
484	type Extra = ();
485	type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
486	type CallbackHandle = ();
487	type AssetAccountDeposit = AssetAccountDeposit;
488	type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
489	#[cfg(feature = "runtime-benchmarks")]
490	type BenchmarkHelper = ();
491}
492
493parameter_types! {
494	// we just reuse the same deposits
495	pub const ForeignAssetsAssetDeposit: Balance = AssetDeposit::get();
496	pub const ForeignAssetsAssetAccountDeposit: Balance = AssetAccountDeposit::get();
497	pub const ForeignAssetsApprovalDeposit: Balance = ApprovalDeposit::get();
498	pub const ForeignAssetsAssetsStringLimit: u32 = AssetsStringLimit::get();
499	pub const ForeignAssetsMetadataDepositBase: Balance = MetadataDepositBase::get();
500	pub const ForeignAssetsMetadataDepositPerByte: Balance = MetadataDepositPerByte::get();
501}
502
503/// Another pallet assets instance to store foreign assets from bridgehub.
504pub type ForeignAssetsInstance = pallet_assets::Instance2;
505impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
506	type RuntimeEvent = RuntimeEvent;
507	type Balance = Balance;
508	type AssetId = ForeignAssetsAssetId;
509	type AssetIdParameter = ForeignAssetsAssetId;
510	type ReserveData = ForeignAssetReserveData;
511	type Currency = Balances;
512	// This is to allow any other remote location to create foreign assets. Used in tests, not
513	// recommended on real chains.
514	type CreateOrigin =
515		ForeignCreators<Everything, LocationToAccountId, AccountId, xcm::latest::Location>;
516	type ForceOrigin = EnsureRoot<AccountId>;
517	type AssetDeposit = ForeignAssetsAssetDeposit;
518	type MetadataDepositBase = ForeignAssetsMetadataDepositBase;
519	type MetadataDepositPerByte = ForeignAssetsMetadataDepositPerByte;
520	type ApprovalDeposit = ForeignAssetsApprovalDeposit;
521	type StringLimit = ForeignAssetsAssetsStringLimit;
522	type Holder = ();
523	type Freezer = ();
524	type Extra = ();
525	type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
526	type CallbackHandle = ();
527	type AssetAccountDeposit = ForeignAssetsAssetAccountDeposit;
528	type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
529	#[cfg(feature = "runtime-benchmarks")]
530	type BenchmarkHelper = assets_common::benchmarks::LocationAssetsBenchmarkHelper;
531}
532
533parameter_types! {
534	pub const AssetConversionPalletId: PalletId = PalletId(*b"py/ascon");
535	pub const LiquidityWithdrawalFee: Permill = Permill::from_percent(0);
536}
537
538ord_parameter_types! {
539	pub const AssetConversionOrigin: sp_runtime::AccountId32 =
540		AccountIdConversion::<sp_runtime::AccountId32>::into_account_truncating(&AssetConversionPalletId::get());
541}
542
543pub type AssetsForceOrigin = EnsureRoot<AccountId>;
544
545pub type PoolAssetsInstance = pallet_assets::Instance3;
546impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
547	type RuntimeEvent = RuntimeEvent;
548	type Balance = Balance;
549	type RemoveItemsLimit = ConstU32<1000>;
550	type AssetId = u32;
551	type AssetIdParameter = u32;
552	type ReserveData = ();
553	type Currency = Balances;
554	type CreateOrigin =
555		AsEnsureOriginWithArg<EnsureSignedBy<AssetConversionOrigin, sp_runtime::AccountId32>>;
556	type ForceOrigin = AssetsForceOrigin;
557	type AssetDeposit = ConstU128<0>;
558	type AssetAccountDeposit = ConstU128<0>;
559	type MetadataDepositBase = ConstU128<0>;
560	type MetadataDepositPerByte = ConstU128<0>;
561	type ApprovalDeposit = ConstU128<0>;
562	type StringLimit = ConstU32<50>;
563	type Holder = ();
564	type Freezer = ();
565	type Extra = ();
566	type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
567	type CallbackHandle = ();
568	#[cfg(feature = "runtime-benchmarks")]
569	type BenchmarkHelper = ();
570}
571
572/// Union fungibles implementation for `Assets` and `ForeignAssets`.
573pub type LocalAndForeignAssets = fungibles::UnionOf<
574	Assets,
575	ForeignAssets,
576	LocalFromLeft<
577		AssetIdForTrustBackedAssetsConvert<
578			xcm_config::TrustBackedAssetsPalletLocation,
579			xcm::latest::Location,
580		>,
581		parachains_common::AssetIdForTrustBackedAssets,
582		xcm::latest::Location,
583	>,
584	xcm::latest::Location,
585	AccountId,
586>;
587
588/// Union fungibles implementation for [`LocalAndForeignAssets`] and `Balances`.
589pub type NativeAndAssets = fungible::UnionOf<
590	Balances,
591	LocalAndForeignAssets,
592	TargetFromLeft<xcm_config::RelayLocation, xcm::latest::Location>,
593	xcm::latest::Location,
594	AccountId,
595>;
596
597pub type PoolIdToAccountId = pallet_asset_conversion::AccountIdConverter<
598	AssetConversionPalletId,
599	(xcm::latest::Location, xcm::latest::Location),
600>;
601
602impl pallet_asset_conversion::Config for Runtime {
603	type RuntimeEvent = RuntimeEvent;
604	type Balance = Balance;
605	type HigherPrecisionBalance = sp_core::U256;
606	type AssetKind = xcm::latest::Location;
607	type Assets = NativeAndAssets;
608	type PoolId = (Self::AssetKind, Self::AssetKind);
609	type PoolLocator = pallet_asset_conversion::WithFirstAsset<
610		xcm_config::RelayLocation,
611		AccountId,
612		Self::AssetKind,
613		PoolIdToAccountId,
614	>;
615	type PoolAssetId = u32;
616	type PoolAssets = PoolAssets;
617	type PoolSetupFee = ConstU128<0>; // Asset class deposit fees are sufficient to prevent spam
618	type PoolSetupFeeAsset = xcm_config::RelayLocation;
619	type PoolSetupFeeTarget = ResolveAssetTo<AssetConversionOrigin, Self::Assets>;
620	type LiquidityWithdrawalFee = LiquidityWithdrawalFee;
621	type LPFee = ConstU32<3>;
622	type PalletId = AssetConversionPalletId;
623	type MaxSwapPathLength = ConstU32<3>;
624	type MintMinLiquidity = ConstU128<100>;
625	type WeightInfo = ();
626	#[cfg(feature = "runtime-benchmarks")]
627	type BenchmarkHelper = assets_common::benchmarks::AssetPairFactory<
628		xcm_config::RelayLocation,
629		parachain_info::Pallet<Runtime>,
630		xcm_config::TrustBackedAssetsPalletIndex,
631		xcm::latest::Location,
632	>;
633}
634
635parameter_types! {
636	pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
637	pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
638	pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent;
639}
640
641type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
642	Runtime,
643	RELAY_CHAIN_SLOT_DURATION_MILLIS,
644	BLOCK_PROCESSING_VELOCITY,
645	UNINCLUDED_SEGMENT_CAPACITY,
646>;
647
648impl cumulus_pallet_parachain_system::Config for Runtime {
649	type WeightInfo = ();
650	type RuntimeEvent = RuntimeEvent;
651	type OnSystemEvent = ();
652	type SelfParaId = parachain_info::Pallet<Runtime>;
653	type DmpQueue = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
654	type ReservedDmpWeight = ReservedDmpWeight;
655	type OutboundXcmpMessageSource = XcmpQueue;
656	type XcmpMessageHandler = XcmpQueue;
657	type ReservedXcmpWeight = ReservedXcmpWeight;
658	type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases;
659	type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
660		Runtime,
661		RELAY_CHAIN_SLOT_DURATION_MILLIS,
662		BLOCK_PROCESSING_VELOCITY,
663		UNINCLUDED_SEGMENT_CAPACITY,
664	>;
665
666	type RelayParentOffset = ConstU32<0>;
667}
668
669impl parachain_info::Config for Runtime {}
670
671parameter_types! {
672	pub MessageQueueServiceWeight: Weight = Perbill::from_percent(35) * RuntimeBlockWeights::get().max_block;
673}
674
675impl pallet_message_queue::Config for Runtime {
676	type RuntimeEvent = RuntimeEvent;
677	type WeightInfo = ();
678	type MessageProcessor = xcm_builder::ProcessXcmMessage<
679		AggregateMessageOrigin,
680		xcm_executor::XcmExecutor<xcm_config::XcmConfig>,
681		RuntimeCall,
682	>;
683	type Size = u32;
684	// The XCMP queue pallet is only ever able to handle the `Sibling(ParaId)` origin:
685	type QueueChangeHandler = NarrowOriginToSibling<XcmpQueue>;
686	type QueuePausedQuery = NarrowOriginToSibling<XcmpQueue>;
687	type HeapSize = sp_core::ConstU32<{ 103 * 1024 }>;
688	type MaxStale = sp_core::ConstU32<8>;
689	type ServiceWeight = MessageQueueServiceWeight;
690	type IdleMaxServiceWeight = MessageQueueServiceWeight;
691}
692
693impl cumulus_pallet_aura_ext::Config for Runtime {}
694
695parameter_types! {
696	/// The asset ID for the asset that we use to pay for message delivery fees.
697	pub FeeAssetId: AssetLocationId = AssetLocationId(xcm_config::RelayLocation::get());
698	/// The base fee for the message delivery fees (3 CENTS).
699	pub const BaseDeliveryFee: u128 = (1_000_000_000_000u128 / 100).saturating_mul(3);
700}
701
702pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice<
703	FeeAssetId,
704	BaseDeliveryFee,
705	TransactionByteFee,
706	XcmpQueue,
707>;
708
709impl cumulus_pallet_xcmp_queue::Config for Runtime {
710	type RuntimeEvent = RuntimeEvent;
711	type ChannelInfo = ParachainSystem;
712	type VersionWrapper = PolkadotXcm;
713	// Enqueue XCMP messages from siblings for later processing.
714	type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
715	type MaxInboundSuspended = ConstU32<1_000>;
716	type MaxActiveOutboundChannels = ConstU32<128>;
717	// Most on-chain HRMP channels are configured to use 102400 bytes of max message size, so we
718	// need to set the page size larger than that until we reduce the channel size on-chain.
719	type MaxPageSize = ConstU32<{ 103 * 1024 }>;
720	type ControllerOrigin = EnsureRoot<AccountId>;
721	type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
722	type WeightInfo = ();
723	type PriceForSiblingDelivery = PriceForSiblingParachainDelivery;
724}
725
726parameter_types! {
727	pub const Period: u32 = 6 * HOURS;
728	pub const Offset: u32 = 0;
729}
730impl pallet_session::Config for Runtime {
731	type RuntimeEvent = RuntimeEvent;
732	type ValidatorId = <Self as frame_system::Config>::AccountId;
733	// we don't have stash and controller, thus we don't need the convert as well.
734	type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
735	type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
736	type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
737	type SessionManager = CollatorSelection;
738	// Essentially just Aura, but let's be pedantic.
739	type SessionHandler = <SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
740	type Keys = SessionKeys;
741	type DisablingStrategy = ();
742	type WeightInfo = ();
743	type Currency = Balances;
744	type KeyDeposit = ();
745}
746
747impl pallet_aura::Config for Runtime {
748	type AuthorityId = AuraId;
749	type DisabledValidators = ();
750	type MaxAuthorities = ConstU32<100_000>;
751	type AllowMultipleBlocksPerSlot = ConstBool<true>;
752	type SlotDuration = ConstU64<SLOT_DURATION>;
753}
754
755parameter_types! {
756	pub const PotId: PalletId = PalletId(*b"PotStake");
757	pub const SessionLength: BlockNumber = 6 * HOURS;
758	pub const ExecutiveBody: BodyId = BodyId::Executive;
759}
760
761// We allow root only to execute privileged collator selection operations.
762pub type CollatorSelectionUpdateOrigin = EnsureRoot<AccountId>;
763
764impl pallet_collator_selection::Config for Runtime {
765	type RuntimeEvent = RuntimeEvent;
766	type Currency = Balances;
767	type UpdateOrigin = CollatorSelectionUpdateOrigin;
768	type PotId = PotId;
769	type MaxCandidates = ConstU32<100>;
770	type MinEligibleCollators = ConstU32<4>;
771	type MaxInvulnerables = ConstU32<20>;
772	// should be a multiple of session or things will get inconsistent
773	type KickThreshold = Period;
774	type ValidatorId = <Self as frame_system::Config>::AccountId;
775	type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
776	type ValidatorRegistration = Session;
777	type WeightInfo = ();
778}
779
780#[cfg(feature = "runtime-benchmarks")]
781pub struct AssetTxHelper;
782
783#[cfg(feature = "runtime-benchmarks")]
784impl pallet_asset_tx_payment::BenchmarkHelperTrait<AccountId, u32, u32> for AssetTxHelper {
785	fn create_asset_id_parameter(_id: u32) -> (u32, u32) {
786		unimplemented!("Penpal uses default weights");
787	}
788	fn setup_balances_and_pool(_asset_id: u32, _account: AccountId) {
789		unimplemented!("Penpal uses default weights");
790	}
791}
792
793impl pallet_asset_tx_payment::Config for Runtime {
794	type RuntimeEvent = RuntimeEvent;
795	type Fungibles = Assets;
796	type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter<
797		pallet_assets::BalanceToAssetBalance<
798			Balances,
799			Runtime,
800			ConvertInto,
801			TrustBackedAssetsInstance,
802		>,
803		AssetsToBlockAuthor<Runtime, TrustBackedAssetsInstance>,
804	>;
805	type WeightInfo = ();
806	#[cfg(feature = "runtime-benchmarks")]
807	type BenchmarkHelper = AssetTxHelper;
808}
809
810parameter_types! {
811	pub const DepositPerItem: Balance = 0;
812	pub const DepositPerChildTrieItem: Balance = 0;
813	pub const DepositPerByte: Balance = 0;
814	pub CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(30);
815	pub const MaxEthExtrinsicWeight: FixedU128 = FixedU128::from_rational(9, 10);
816}
817
818impl pallet_revive::Config for Runtime {
819	type Time = Timestamp;
820	type Balance = Balance;
821	type Currency = Balances;
822	type RuntimeEvent = RuntimeEvent;
823	type RuntimeCall = RuntimeCall;
824	type RuntimeOrigin = RuntimeOrigin;
825	type DepositPerItem = DepositPerItem;
826	type DepositPerChildTrieItem = DepositPerChildTrieItem;
827	type DepositPerByte = DepositPerByte;
828	type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
829	type Precompiles = ();
830	type AddressMapper = pallet_revive::AccountId32Mapper<Self>;
831	type RuntimeMemory = ConstU32<{ 128 * 1024 * 1024 }>;
832	type PVFMemory = ConstU32<{ 512 * 1024 * 1024 }>;
833	type UnsafeUnstableInterface = ConstBool<true>;
834	type AllowEVMBytecode = ConstBool<true>;
835	type UploadOrigin = EnsureSigned<Self::AccountId>;
836	type InstantiateOrigin = EnsureSigned<Self::AccountId>;
837	type RuntimeHoldReason = RuntimeHoldReason;
838	type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
839	type ChainId = ConstU64<420_420_999>;
840	type NativeToEthRatio = ConstU32<1_000_000>; // 10^(18 - 12) Eth is 10^18, Native is 10^12.
841	type FindAuthor = <Runtime as pallet_authorship::Config>::FindAuthor;
842	type FeeInfo = pallet_revive::evm::fees::Info<Address, Signature, EthExtraImpl>;
843	type MaxEthExtrinsicWeight = MaxEthExtrinsicWeight;
844	type DebugEnabled = ConstBool<false>;
845	type GasScale = ConstU32<1000>;
846}
847
848impl pallet_sudo::Config for Runtime {
849	type RuntimeEvent = RuntimeEvent;
850	type RuntimeCall = RuntimeCall;
851	type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
852}
853
854impl pallet_utility::Config for Runtime {
855	type RuntimeEvent = RuntimeEvent;
856	type RuntimeCall = RuntimeCall;
857	type PalletsOrigin = OriginCaller;
858	type WeightInfo = pallet_utility::weights::SubstrateWeight<Runtime>;
859}
860
861// Create the runtime by composing the FRAME pallets that were previously configured.
862construct_runtime!(
863	pub enum Runtime
864	{
865		// System support stuff.
866		System: frame_system = 0,
867		ParachainSystem: cumulus_pallet_parachain_system = 1,
868		Timestamp: pallet_timestamp = 2,
869		ParachainInfo: parachain_info = 3,
870
871		// Monetary stuff.
872		Balances: pallet_balances = 10,
873		TransactionPayment: pallet_transaction_payment = 11,
874		AssetTxPayment: pallet_asset_tx_payment = 12,
875
876		// Collator support. The order of these 4 are important and shall not change.
877		Authorship: pallet_authorship = 20,
878		CollatorSelection: pallet_collator_selection = 21,
879		Session: pallet_session = 22,
880		Aura: pallet_aura = 23,
881		AuraExt: cumulus_pallet_aura_ext = 24,
882
883		// XCM helpers.
884		XcmpQueue: cumulus_pallet_xcmp_queue = 30,
885		PolkadotXcm: pallet_xcm = 31,
886		CumulusXcm: cumulus_pallet_xcm = 32,
887		MessageQueue: pallet_message_queue = 34,
888
889		// Handy utilities.
890		Utility: pallet_utility = 40,
891
892		// The main stage.
893		Assets: pallet_assets::<Instance1> = 50,
894		ForeignAssets: pallet_assets::<Instance2> = 51,
895		PoolAssets: pallet_assets::<Instance3> = 52,
896		AssetConversion: pallet_asset_conversion = 53,
897
898		Revive: pallet_revive = 60,
899
900		Sudo: pallet_sudo = 255,
901	}
902);
903
904#[cfg(feature = "runtime-benchmarks")]
905mod benches {
906	frame_benchmarking::define_benchmarks!(
907		[frame_system, SystemBench::<Runtime>]
908		[frame_system_extensions, SystemExtensionsBench::<Runtime>]
909		[pallet_balances, Balances]
910		[pallet_message_queue, MessageQueue]
911		[pallet_session, SessionBench::<Runtime>]
912		[pallet_sudo, Sudo]
913		[pallet_timestamp, Timestamp]
914		[pallet_collator_selection, CollatorSelection]
915		[cumulus_pallet_parachain_system, ParachainSystem]
916		[cumulus_pallet_xcmp_queue, XcmpQueue]
917		[pallet_utility, Utility]
918	);
919}
920
921pallet_revive::impl_runtime_apis_plus_revive_traits!(
922	Runtime,
923	Revive,
924	Executive,
925	EthExtraImpl,
926
927	impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
928		fn slot_duration() -> sp_consensus_aura::SlotDuration {
929			sp_consensus_aura::SlotDuration::from_millis(SLOT_DURATION)
930		}
931
932		fn authorities() -> Vec<AuraId> {
933			pallet_aura::Authorities::<Runtime>::get().into_inner()
934		}
935	}
936
937	impl sp_api::Core<Block> for Runtime {
938		fn version() -> RuntimeVersion {
939			VERSION
940		}
941
942		fn execute_block(block: <Block as BlockT>::LazyBlock) {
943			Executive::execute_block(block)
944		}
945
946		fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
947			Executive::initialize_block(header)
948		}
949	}
950
951	impl sp_api::Metadata<Block> for Runtime {
952		fn metadata() -> OpaqueMetadata {
953			OpaqueMetadata::new(Runtime::metadata().into())
954		}
955
956		fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
957			Runtime::metadata_at_version(version)
958		}
959
960		fn metadata_versions() -> alloc::vec::Vec<u32> {
961			Runtime::metadata_versions()
962		}
963	}
964
965	impl sp_block_builder::BlockBuilder<Block> for Runtime {
966		fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
967			Executive::apply_extrinsic(extrinsic)
968		}
969
970		fn finalize_block() -> <Block as BlockT>::Header {
971			Executive::finalize_block()
972		}
973
974		fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
975			data.create_extrinsics()
976		}
977
978		fn check_inherents(
979			block: <Block as BlockT>::LazyBlock,
980			data: sp_inherents::InherentData,
981		) -> sp_inherents::CheckInherentsResult {
982			data.check_extrinsics(&block)
983		}
984	}
985
986	impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
987		fn validate_transaction(
988			source: TransactionSource,
989			tx: <Block as BlockT>::Extrinsic,
990			block_hash: <Block as BlockT>::Hash,
991		) -> TransactionValidity {
992			Executive::validate_transaction(source, tx, block_hash)
993		}
994	}
995
996	impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
997		fn offchain_worker(header: &<Block as BlockT>::Header) {
998			Executive::offchain_worker(header)
999		}
1000	}
1001
1002	impl sp_session::SessionKeys<Block> for Runtime {
1003		fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
1004			SessionKeys::generate(seed)
1005		}
1006
1007		fn decode_session_keys(
1008			encoded: Vec<u8>,
1009		) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
1010			SessionKeys::decode_into_raw_public_keys(&encoded)
1011		}
1012	}
1013
1014	impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
1015		fn account_nonce(account: AccountId) -> Nonce {
1016			System::account_nonce(account)
1017		}
1018	}
1019
1020	impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
1021		fn query_info(
1022			uxt: <Block as BlockT>::Extrinsic,
1023			len: u32,
1024		) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
1025			TransactionPayment::query_info(uxt, len)
1026		}
1027		fn query_fee_details(
1028			uxt: <Block as BlockT>::Extrinsic,
1029			len: u32,
1030		) -> pallet_transaction_payment::FeeDetails<Balance> {
1031			TransactionPayment::query_fee_details(uxt, len)
1032		}
1033		fn query_weight_to_fee(weight: Weight) -> Balance {
1034			TransactionPayment::weight_to_fee(weight)
1035		}
1036		fn query_length_to_fee(length: u32) -> Balance {
1037			TransactionPayment::length_to_fee(length)
1038		}
1039	}
1040
1041	impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi<Block, Balance, RuntimeCall>
1042		for Runtime
1043	{
1044		fn query_call_info(
1045			call: RuntimeCall,
1046			len: u32,
1047		) -> pallet_transaction_payment::RuntimeDispatchInfo<Balance> {
1048			TransactionPayment::query_call_info(call, len)
1049		}
1050		fn query_call_fee_details(
1051			call: RuntimeCall,
1052			len: u32,
1053		) -> pallet_transaction_payment::FeeDetails<Balance> {
1054			TransactionPayment::query_call_fee_details(call, len)
1055		}
1056		fn query_weight_to_fee(weight: Weight) -> Balance {
1057			TransactionPayment::weight_to_fee(weight)
1058		}
1059		fn query_length_to_fee(length: u32) -> Balance {
1060			TransactionPayment::length_to_fee(length)
1061		}
1062	}
1063
1064	impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
1065		fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
1066			ParachainSystem::collect_collation_info(header)
1067		}
1068	}
1069
1070	impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
1071		fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
1072			let acceptable_assets = vec![AssetLocationId(xcm_config::RelayLocation::get())];
1073			PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)
1074		}
1075
1076		fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
1077			type Trader = <XcmConfig as xcm_executor::Config>::Trader;
1078			PolkadotXcm::query_weight_to_asset_fee::<Trader>(weight, asset)
1079		}
1080
1081		fn query_xcm_weight(message: VersionedXcm<()>) -> Result<Weight, XcmPaymentApiError> {
1082			PolkadotXcm::query_xcm_weight(message)
1083		}
1084
1085		fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>, asset_id: VersionedAssetId) -> Result<VersionedAssets, XcmPaymentApiError> {
1086			type AssetExchanger = <XcmConfig as xcm_executor::Config>::AssetExchanger;
1087			PolkadotXcm::query_delivery_fees::<AssetExchanger>(destination, message, asset_id)
1088		}
1089	}
1090
1091	impl xcm_runtime_apis::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
1092		fn dry_run_call(origin: OriginCaller, call: RuntimeCall, result_xcms_version: XcmVersion) -> Result<CallDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
1093			PolkadotXcm::dry_run_call::<Runtime, xcm_config::XcmRouter, OriginCaller, RuntimeCall>(origin, call, result_xcms_version)
1094		}
1095
1096		fn dry_run_xcm(origin_location: VersionedLocation, xcm: VersionedXcm<RuntimeCall>) -> Result<XcmDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
1097			PolkadotXcm::dry_run_xcm::<xcm_config::XcmRouter>(origin_location, xcm)
1098		}
1099	}
1100
1101	impl xcm_runtime_apis::conversions::LocationToAccountApi<Block, AccountId> for Runtime {
1102		fn convert_location(location: VersionedLocation) -> Result<
1103			AccountId,
1104			xcm_runtime_apis::conversions::Error
1105		> {
1106			xcm_runtime_apis::conversions::LocationToAccountHelper::<
1107				AccountId,
1108				xcm_config::LocationToAccountId,
1109			>::convert_location(location)
1110		}
1111	}
1112
1113	impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
1114		fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
1115			PolkadotXcm::is_trusted_reserve(asset, location)
1116		}
1117		fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
1118			PolkadotXcm::is_trusted_teleporter(asset, location)
1119		}
1120	}
1121
1122	impl xcm_runtime_apis::authorized_aliases::AuthorizedAliasersApi<Block> for Runtime {
1123		fn authorized_aliasers(target: VersionedLocation) -> Result<
1124			Vec<xcm_runtime_apis::authorized_aliases::OriginAliaser>,
1125			xcm_runtime_apis::authorized_aliases::Error
1126		> {
1127			PolkadotXcm::authorized_aliasers(target)
1128		}
1129		fn is_authorized_alias(origin: VersionedLocation, target: VersionedLocation) -> Result<
1130			bool,
1131			xcm_runtime_apis::authorized_aliases::Error
1132		> {
1133			PolkadotXcm::is_authorized_alias(origin, target)
1134		}
1135	}
1136
1137	#[cfg(feature = "try-runtime")]
1138	impl frame_try_runtime::TryRuntime<Block> for Runtime {
1139		fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
1140			let weight = Executive::try_runtime_upgrade(checks).unwrap();
1141			(weight, RuntimeBlockWeights::get().max_block)
1142		}
1143
1144		fn execute_block(
1145			block: <Block as BlockT>::LazyBlock,
1146			state_root_check: bool,
1147			signature_check: bool,
1148			select: frame_try_runtime::TryStateSelect,
1149		) -> Weight {
1150			// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
1151			// have a backtrace here.
1152			Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
1153		}
1154	}
1155
1156	#[cfg(feature = "runtime-benchmarks")]
1157	impl frame_benchmarking::Benchmark<Block> for Runtime {
1158		fn benchmark_metadata(extra: bool) -> (
1159			Vec<frame_benchmarking::BenchmarkList>,
1160			Vec<frame_support::traits::StorageInfo>,
1161		) {
1162			use frame_benchmarking::BenchmarkList;
1163			use frame_support::traits::StorageInfoTrait;
1164			use frame_system_benchmarking::Pallet as SystemBench;
1165			use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
1166			use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
1167
1168			let mut list = Vec::<BenchmarkList>::new();
1169			list_benchmarks!(list, extra);
1170
1171			let storage_info = AllPalletsWithSystem::storage_info();
1172			(list, storage_info)
1173		}
1174
1175		#[allow(non_local_definitions)]
1176		fn dispatch_benchmark(
1177			config: frame_benchmarking::BenchmarkConfig
1178		) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> {
1179			use frame_benchmarking::BenchmarkBatch;
1180			use sp_storage::TrackedStorageKey;
1181
1182			use frame_system_benchmarking::Pallet as SystemBench;
1183			use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
1184			impl frame_system_benchmarking::Config for Runtime {}
1185
1186			use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
1187			impl cumulus_pallet_session_benchmarking::Config for Runtime {}
1188
1189			use frame_support::traits::WhitelistedStorageKeys;
1190			let whitelist: Vec<TrackedStorageKey> = AllPalletsWithSystem::whitelisted_storage_keys();
1191
1192			let mut batches = Vec::<BenchmarkBatch>::new();
1193			let params = (&config, &whitelist);
1194			add_benchmarks!(params, batches);
1195
1196			if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
1197			Ok(batches)
1198		}
1199	}
1200
1201	impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
1202		fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
1203			build_state::<RuntimeGenesisConfig>(config)
1204		}
1205
1206		fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
1207			get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset)
1208		}
1209
1210		fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
1211			genesis_config_presets::preset_names()
1212		}
1213	}
1214
1215	impl cumulus_primitives_core::GetParachainInfo<Block> for Runtime {
1216		fn parachain_id() -> ParaId {
1217			ParachainInfo::parachain_id()
1218		}
1219	}
1220
1221	impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
1222		fn can_build_upon(
1223			included_hash: <Block as BlockT>::Hash,
1224			slot: cumulus_primitives_aura::Slot,
1225		) -> bool {
1226			ConsensusHook::can_build_upon(included_hash, slot)
1227		}
1228	}
1229);
1230
1231cumulus_pallet_parachain_system::register_validate_block! {
1232	Runtime = Runtime,
1233	BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
1234}