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>;
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}
846
847impl pallet_sudo::Config for Runtime {
848	type RuntimeEvent = RuntimeEvent;
849	type RuntimeCall = RuntimeCall;
850	type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
851}
852
853impl pallet_utility::Config for Runtime {
854	type RuntimeEvent = RuntimeEvent;
855	type RuntimeCall = RuntimeCall;
856	type PalletsOrigin = OriginCaller;
857	type WeightInfo = pallet_utility::weights::SubstrateWeight<Runtime>;
858}
859
860// Create the runtime by composing the FRAME pallets that were previously configured.
861construct_runtime!(
862	pub enum Runtime
863	{
864		// System support stuff.
865		System: frame_system = 0,
866		ParachainSystem: cumulus_pallet_parachain_system = 1,
867		Timestamp: pallet_timestamp = 2,
868		ParachainInfo: parachain_info = 3,
869
870		// Monetary stuff.
871		Balances: pallet_balances = 10,
872		TransactionPayment: pallet_transaction_payment = 11,
873		AssetTxPayment: pallet_asset_tx_payment = 12,
874
875		// Collator support. The order of these 4 are important and shall not change.
876		Authorship: pallet_authorship = 20,
877		CollatorSelection: pallet_collator_selection = 21,
878		Session: pallet_session = 22,
879		Aura: pallet_aura = 23,
880		AuraExt: cumulus_pallet_aura_ext = 24,
881
882		// XCM helpers.
883		XcmpQueue: cumulus_pallet_xcmp_queue = 30,
884		PolkadotXcm: pallet_xcm = 31,
885		CumulusXcm: cumulus_pallet_xcm = 32,
886		MessageQueue: pallet_message_queue = 34,
887
888		// Handy utilities.
889		Utility: pallet_utility = 40,
890
891		// The main stage.
892		Assets: pallet_assets::<Instance1> = 50,
893		ForeignAssets: pallet_assets::<Instance2> = 51,
894		PoolAssets: pallet_assets::<Instance3> = 52,
895		AssetConversion: pallet_asset_conversion = 53,
896
897		Revive: pallet_revive = 60,
898
899		Sudo: pallet_sudo = 255,
900	}
901);
902
903#[cfg(feature = "runtime-benchmarks")]
904mod benches {
905	frame_benchmarking::define_benchmarks!(
906		[frame_system, SystemBench::<Runtime>]
907		[frame_system_extensions, SystemExtensionsBench::<Runtime>]
908		[pallet_balances, Balances]
909		[pallet_message_queue, MessageQueue]
910		[pallet_session, SessionBench::<Runtime>]
911		[pallet_sudo, Sudo]
912		[pallet_timestamp, Timestamp]
913		[pallet_collator_selection, CollatorSelection]
914		[cumulus_pallet_parachain_system, ParachainSystem]
915		[cumulus_pallet_xcmp_queue, XcmpQueue]
916		[pallet_utility, Utility]
917	);
918}
919
920pallet_revive::impl_runtime_apis_plus_revive_traits!(
921	Runtime,
922	Revive,
923	Executive,
924	EthExtraImpl,
925
926	impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
927		fn slot_duration() -> sp_consensus_aura::SlotDuration {
928			sp_consensus_aura::SlotDuration::from_millis(SLOT_DURATION)
929		}
930
931		fn authorities() -> Vec<AuraId> {
932			pallet_aura::Authorities::<Runtime>::get().into_inner()
933		}
934	}
935
936	impl sp_api::Core<Block> for Runtime {
937		fn version() -> RuntimeVersion {
938			VERSION
939		}
940
941		fn execute_block(block: <Block as BlockT>::LazyBlock) {
942			Executive::execute_block(block)
943		}
944
945		fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
946			Executive::initialize_block(header)
947		}
948	}
949
950	impl sp_api::Metadata<Block> for Runtime {
951		fn metadata() -> OpaqueMetadata {
952			OpaqueMetadata::new(Runtime::metadata().into())
953		}
954
955		fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
956			Runtime::metadata_at_version(version)
957		}
958
959		fn metadata_versions() -> alloc::vec::Vec<u32> {
960			Runtime::metadata_versions()
961		}
962	}
963
964	impl sp_block_builder::BlockBuilder<Block> for Runtime {
965		fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
966			Executive::apply_extrinsic(extrinsic)
967		}
968
969		fn finalize_block() -> <Block as BlockT>::Header {
970			Executive::finalize_block()
971		}
972
973		fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
974			data.create_extrinsics()
975		}
976
977		fn check_inherents(
978			block: <Block as BlockT>::LazyBlock,
979			data: sp_inherents::InherentData,
980		) -> sp_inherents::CheckInherentsResult {
981			data.check_extrinsics(&block)
982		}
983	}
984
985	impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
986		fn validate_transaction(
987			source: TransactionSource,
988			tx: <Block as BlockT>::Extrinsic,
989			block_hash: <Block as BlockT>::Hash,
990		) -> TransactionValidity {
991			Executive::validate_transaction(source, tx, block_hash)
992		}
993	}
994
995	impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
996		fn offchain_worker(header: &<Block as BlockT>::Header) {
997			Executive::offchain_worker(header)
998		}
999	}
1000
1001	impl sp_session::SessionKeys<Block> for Runtime {
1002		fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
1003			SessionKeys::generate(seed)
1004		}
1005
1006		fn decode_session_keys(
1007			encoded: Vec<u8>,
1008		) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
1009			SessionKeys::decode_into_raw_public_keys(&encoded)
1010		}
1011	}
1012
1013	impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
1014		fn account_nonce(account: AccountId) -> Nonce {
1015			System::account_nonce(account)
1016		}
1017	}
1018
1019	impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
1020		fn query_info(
1021			uxt: <Block as BlockT>::Extrinsic,
1022			len: u32,
1023		) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
1024			TransactionPayment::query_info(uxt, len)
1025		}
1026		fn query_fee_details(
1027			uxt: <Block as BlockT>::Extrinsic,
1028			len: u32,
1029		) -> pallet_transaction_payment::FeeDetails<Balance> {
1030			TransactionPayment::query_fee_details(uxt, len)
1031		}
1032		fn query_weight_to_fee(weight: Weight) -> Balance {
1033			TransactionPayment::weight_to_fee(weight)
1034		}
1035		fn query_length_to_fee(length: u32) -> Balance {
1036			TransactionPayment::length_to_fee(length)
1037		}
1038	}
1039
1040	impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi<Block, Balance, RuntimeCall>
1041		for Runtime
1042	{
1043		fn query_call_info(
1044			call: RuntimeCall,
1045			len: u32,
1046		) -> pallet_transaction_payment::RuntimeDispatchInfo<Balance> {
1047			TransactionPayment::query_call_info(call, len)
1048		}
1049		fn query_call_fee_details(
1050			call: RuntimeCall,
1051			len: u32,
1052		) -> pallet_transaction_payment::FeeDetails<Balance> {
1053			TransactionPayment::query_call_fee_details(call, len)
1054		}
1055		fn query_weight_to_fee(weight: Weight) -> Balance {
1056			TransactionPayment::weight_to_fee(weight)
1057		}
1058		fn query_length_to_fee(length: u32) -> Balance {
1059			TransactionPayment::length_to_fee(length)
1060		}
1061	}
1062
1063	impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
1064		fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
1065			ParachainSystem::collect_collation_info(header)
1066		}
1067	}
1068
1069	impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
1070		fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
1071			let acceptable_assets = vec![AssetLocationId(xcm_config::RelayLocation::get())];
1072			PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)
1073		}
1074
1075		fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
1076			type Trader = <XcmConfig as xcm_executor::Config>::Trader;
1077			PolkadotXcm::query_weight_to_asset_fee::<Trader>(weight, asset)
1078		}
1079
1080		fn query_xcm_weight(message: VersionedXcm<()>) -> Result<Weight, XcmPaymentApiError> {
1081			PolkadotXcm::query_xcm_weight(message)
1082		}
1083
1084		fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>, asset_id: VersionedAssetId) -> Result<VersionedAssets, XcmPaymentApiError> {
1085			type AssetExchanger = <XcmConfig as xcm_executor::Config>::AssetExchanger;
1086			PolkadotXcm::query_delivery_fees::<AssetExchanger>(destination, message, asset_id)
1087		}
1088	}
1089
1090	impl xcm_runtime_apis::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
1091		fn dry_run_call(origin: OriginCaller, call: RuntimeCall, result_xcms_version: XcmVersion) -> Result<CallDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
1092			PolkadotXcm::dry_run_call::<Runtime, xcm_config::XcmRouter, OriginCaller, RuntimeCall>(origin, call, result_xcms_version)
1093		}
1094
1095		fn dry_run_xcm(origin_location: VersionedLocation, xcm: VersionedXcm<RuntimeCall>) -> Result<XcmDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
1096			PolkadotXcm::dry_run_xcm::<xcm_config::XcmRouter>(origin_location, xcm)
1097		}
1098	}
1099
1100	impl xcm_runtime_apis::conversions::LocationToAccountApi<Block, AccountId> for Runtime {
1101		fn convert_location(location: VersionedLocation) -> Result<
1102			AccountId,
1103			xcm_runtime_apis::conversions::Error
1104		> {
1105			xcm_runtime_apis::conversions::LocationToAccountHelper::<
1106				AccountId,
1107				xcm_config::LocationToAccountId,
1108			>::convert_location(location)
1109		}
1110	}
1111
1112	impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
1113		fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
1114			PolkadotXcm::is_trusted_reserve(asset, location)
1115		}
1116		fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
1117			PolkadotXcm::is_trusted_teleporter(asset, location)
1118		}
1119	}
1120
1121	impl xcm_runtime_apis::authorized_aliases::AuthorizedAliasersApi<Block> for Runtime {
1122		fn authorized_aliasers(target: VersionedLocation) -> Result<
1123			Vec<xcm_runtime_apis::authorized_aliases::OriginAliaser>,
1124			xcm_runtime_apis::authorized_aliases::Error
1125		> {
1126			PolkadotXcm::authorized_aliasers(target)
1127		}
1128		fn is_authorized_alias(origin: VersionedLocation, target: VersionedLocation) -> Result<
1129			bool,
1130			xcm_runtime_apis::authorized_aliases::Error
1131		> {
1132			PolkadotXcm::is_authorized_alias(origin, target)
1133		}
1134	}
1135
1136	#[cfg(feature = "try-runtime")]
1137	impl frame_try_runtime::TryRuntime<Block> for Runtime {
1138		fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
1139			let weight = Executive::try_runtime_upgrade(checks).unwrap();
1140			(weight, RuntimeBlockWeights::get().max_block)
1141		}
1142
1143		fn execute_block(
1144			block: <Block as BlockT>::LazyBlock,
1145			state_root_check: bool,
1146			signature_check: bool,
1147			select: frame_try_runtime::TryStateSelect,
1148		) -> Weight {
1149			// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
1150			// have a backtrace here.
1151			Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
1152		}
1153	}
1154
1155	#[cfg(feature = "runtime-benchmarks")]
1156	impl frame_benchmarking::Benchmark<Block> for Runtime {
1157		fn benchmark_metadata(extra: bool) -> (
1158			Vec<frame_benchmarking::BenchmarkList>,
1159			Vec<frame_support::traits::StorageInfo>,
1160		) {
1161			use frame_benchmarking::BenchmarkList;
1162			use frame_support::traits::StorageInfoTrait;
1163			use frame_system_benchmarking::Pallet as SystemBench;
1164			use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
1165			use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
1166
1167			let mut list = Vec::<BenchmarkList>::new();
1168			list_benchmarks!(list, extra);
1169
1170			let storage_info = AllPalletsWithSystem::storage_info();
1171			(list, storage_info)
1172		}
1173
1174		#[allow(non_local_definitions)]
1175		fn dispatch_benchmark(
1176			config: frame_benchmarking::BenchmarkConfig
1177		) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> {
1178			use frame_benchmarking::BenchmarkBatch;
1179			use sp_storage::TrackedStorageKey;
1180
1181			use frame_system_benchmarking::Pallet as SystemBench;
1182			use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
1183			impl frame_system_benchmarking::Config for Runtime {}
1184
1185			use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
1186			impl cumulus_pallet_session_benchmarking::Config for Runtime {}
1187
1188			use frame_support::traits::WhitelistedStorageKeys;
1189			let whitelist: Vec<TrackedStorageKey> = AllPalletsWithSystem::whitelisted_storage_keys();
1190
1191			let mut batches = Vec::<BenchmarkBatch>::new();
1192			let params = (&config, &whitelist);
1193			add_benchmarks!(params, batches);
1194
1195			if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
1196			Ok(batches)
1197		}
1198	}
1199
1200	impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
1201		fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
1202			build_state::<RuntimeGenesisConfig>(config)
1203		}
1204
1205		fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
1206			get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset)
1207		}
1208
1209		fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
1210			genesis_config_presets::preset_names()
1211		}
1212	}
1213
1214	impl cumulus_primitives_core::GetParachainInfo<Block> for Runtime {
1215		fn parachain_id() -> ParaId {
1216			ParachainInfo::parachain_id()
1217		}
1218	}
1219
1220	impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
1221		fn can_build_upon(
1222			included_hash: <Block as BlockT>::Hash,
1223			slot: cumulus_primitives_aura::Slot,
1224		) -> bool {
1225			ConsensusHook::can_build_upon(included_hash, slot)
1226		}
1227	}
1228);
1229
1230cumulus_pallet_parachain_system::register_validate_block! {
1231	Runtime = Runtime,
1232	BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
1233}