1#![cfg_attr(not(feature = "std"), no_std)]
25#![recursion_limit = "256"]
27
28#[cfg(feature = "std")]
30include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
31
32mod weights;
33pub mod xcm_config;
34
35extern crate alloc;
36
37use alloc::{vec, vec::Vec};
38use assets_common::{
39 local_and_foreign_assets::{LocalFromLeft, TargetFromLeft},
40 AssetIdForTrustBackedAssetsConvert,
41};
42use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
43use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
44use frame_support::{
45 construct_runtime, derive_impl,
46 dispatch::DispatchClass,
47 genesis_builder_helper::{build_state, get_preset},
48 ord_parameter_types,
49 pallet_prelude::Weight,
50 parameter_types,
51 traits::{
52 tokens::{fungible, fungibles, imbalance::ResolveAssetTo},
53 AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, Everything,
54 TransformOrigin,
55 },
56 weights::{
57 constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, FeePolynomial, WeightToFee as _,
58 WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
59 },
60 PalletId,
61};
62use frame_system::{
63 limits::{BlockLength, BlockWeights},
64 EnsureRoot, EnsureSigned, EnsureSignedBy,
65};
66use parachains_common::{
67 impls::{AssetsToBlockAuthor, NonZeroIssuance},
68 message_queue::{NarrowOriginToSibling, ParaIdToSibling},
69};
70use smallvec::smallvec;
71use sp_api::impl_runtime_apis;
72pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
73use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
74use sp_runtime::{
75 create_runtime_str, generic, impl_opaque_keys,
76 traits::{AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT},
77 transaction_validity::{TransactionSource, TransactionValidity},
78 ApplyExtrinsicResult,
79};
80pub use sp_runtime::{traits::ConvertInto, MultiAddress, Perbill, Permill};
81#[cfg(feature = "std")]
82use sp_version::NativeVersion;
83use sp_version::RuntimeVersion;
84use xcm_config::{ForeignAssetsAssetId, XcmOriginToTransactDispatchOrigin};
85
86#[cfg(any(feature = "std", test))]
87pub use sp_runtime::BuildStorage;
88
89use parachains_common::{AccountId, Signature};
90use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
91use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
92use xcm::{
93 latest::prelude::{AssetId as AssetLocationId, BodyId},
94 Version as XcmVersion, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
95};
96use xcm_runtime_apis::{
97 dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
98 fees::Error as XcmPaymentApiError,
99};
100
101pub type Balance = u128;
103
104pub type Nonce = u32;
106
107pub type Hash = sp_core::H256;
109
110pub type BlockNumber = u32;
112
113pub type Address = MultiAddress<AccountId, ()>;
115
116pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
118
119pub type Block = generic::Block<Header, UncheckedExtrinsic>;
121
122pub type SignedBlock = generic::SignedBlock<Block>;
124
125pub type BlockId = generic::BlockId<Block>;
127
128pub type AssetId = u32;
130
131pub type SignedExtra = (
133 frame_system::CheckNonZeroSender<Runtime>,
134 frame_system::CheckSpecVersion<Runtime>,
135 frame_system::CheckTxVersion<Runtime>,
136 frame_system::CheckGenesis<Runtime>,
137 frame_system::CheckEra<Runtime>,
138 frame_system::CheckNonce<Runtime>,
139 frame_system::CheckWeight<Runtime>,
140 pallet_asset_tx_payment::ChargeAssetTxPayment<Runtime>,
141);
142
143pub type UncheckedExtrinsic =
145 generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
146
147pub type Migrations = (
148 pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckingAccount>,
149 pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,
150);
151
152pub type Executive = frame_executive::Executive<
154 Runtime,
155 Block,
156 frame_system::ChainContext<Runtime>,
157 Runtime,
158 AllPalletsWithSystem,
159 Migrations,
160>;
161
162pub struct WeightToFee;
173impl frame_support::weights::WeightToFee for WeightToFee {
174 type Balance = Balance;
175
176 fn weight_to_fee(weight: &Weight) -> Self::Balance {
177 let time_poly: FeePolynomial<Balance> = RefTimeToFee::polynomial().into();
178 let proof_poly: FeePolynomial<Balance> = ProofSizeToFee::polynomial().into();
179
180 time_poly.eval(weight.ref_time()).max(proof_poly.eval(weight.proof_size()))
182 }
183}
184
185pub struct RefTimeToFee;
187impl WeightToFeePolynomial for RefTimeToFee {
188 type Balance = Balance;
189 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
190 let p = MILLIUNIT / 10;
191 let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
192
193 smallvec![WeightToFeeCoefficient {
194 degree: 1,
195 negative: false,
196 coeff_frac: Perbill::from_rational(p % q, q),
197 coeff_integer: p / q,
198 }]
199 }
200}
201
202pub struct ProofSizeToFee;
204impl WeightToFeePolynomial for ProofSizeToFee {
205 type Balance = Balance;
206 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
207 let p = MILLIUNIT / 10;
209 let q = 10_000;
210
211 smallvec![WeightToFeeCoefficient {
212 degree: 1,
213 negative: false,
214 coeff_frac: Perbill::from_rational(p % q, q),
215 coeff_integer: p / q,
216 }]
217 }
218}
219pub mod opaque {
224 use super::*;
225 use sp_runtime::{generic, traits::BlakeTwo256};
226
227 pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
228 pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
230 pub type Block = generic::Block<Header, UncheckedExtrinsic>;
232 pub type BlockId = generic::BlockId<Block>;
234}
235
236impl_opaque_keys! {
237 pub struct SessionKeys {
238 pub aura: Aura,
239 }
240}
241
242#[sp_version::runtime_version]
243pub const VERSION: RuntimeVersion = RuntimeVersion {
244 spec_name: create_runtime_str!("penpal-parachain"),
245 impl_name: create_runtime_str!("penpal-parachain"),
246 authoring_version: 1,
247 spec_version: 1,
248 impl_version: 0,
249 apis: RUNTIME_API_VERSIONS,
250 transaction_version: 1,
251 state_version: 1,
252};
253
254pub const MILLISECS_PER_BLOCK: u64 = 12000;
261
262pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
265
266pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
268pub const HOURS: BlockNumber = MINUTES * 60;
269pub const DAYS: BlockNumber = HOURS * 24;
270
271pub const UNIT: Balance = 1_000_000_000_000;
273pub const MILLIUNIT: Balance = 1_000_000_000;
274pub const MICROUNIT: Balance = 1_000_000;
275
276pub const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT;
278
279const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5);
282
283const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
286
287const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
289 WEIGHT_REF_TIME_PER_SECOND.saturating_div(2),
290 cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
291);
292
293const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
296const BLOCK_PROCESSING_VELOCITY: u32 = 1;
299const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
301
302#[cfg(feature = "std")]
304pub fn native_version() -> NativeVersion {
305 NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
306}
307
308parameter_types! {
309 pub const Version: RuntimeVersion = VERSION;
310
311 pub RuntimeBlockLength: BlockLength =
316 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
317 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
318 .base_block(BlockExecutionWeight::get())
319 .for_class(DispatchClass::all(), |weights| {
320 weights.base_extrinsic = ExtrinsicBaseWeight::get();
321 })
322 .for_class(DispatchClass::Normal, |weights| {
323 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
324 })
325 .for_class(DispatchClass::Operational, |weights| {
326 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
327 weights.reserved = Some(
330 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
331 );
332 })
333 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
334 .build_or_panic();
335 pub const SS58Prefix: u16 = 42;
336}
337
338#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
341impl frame_system::Config for Runtime {
342 type AccountId = AccountId;
344 type RuntimeCall = RuntimeCall;
346 type Lookup = AccountIdLookup<AccountId, ()>;
348 type Nonce = Nonce;
350 type Hash = Hash;
352 type Hashing = BlakeTwo256;
354 type Block = Block;
356 type RuntimeEvent = RuntimeEvent;
358 type RuntimeOrigin = RuntimeOrigin;
360 type BlockHashCount = BlockHashCount;
362 type Version = Version;
364 type PalletInfo = PalletInfo;
366 type AccountData = pallet_balances::AccountData<Balance>;
368 type OnNewAccount = ();
370 type OnKilledAccount = ();
372 type DbWeight = RocksDbWeight;
374 type BaseCallFilter = Everything;
376 type SystemWeightInfo = ();
378 type BlockWeights = RuntimeBlockWeights;
380 type BlockLength = RuntimeBlockLength;
382 type SS58Prefix = SS58Prefix;
384 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
386 type MaxConsumers = frame_support::traits::ConstU32<16>;
387}
388
389impl pallet_timestamp::Config for Runtime {
390 type Moment = u64;
392 type OnTimestampSet = Aura;
393 type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
394 type WeightInfo = ();
395}
396
397impl pallet_authorship::Config for Runtime {
398 type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
399 type EventHandler = (CollatorSelection,);
400}
401
402parameter_types! {
403 pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT;
404}
405
406impl pallet_balances::Config for Runtime {
407 type MaxLocks = ConstU32<50>;
408 type Balance = Balance;
410 type RuntimeEvent = RuntimeEvent;
412 type DustRemoval = ();
413 type ExistentialDeposit = ExistentialDeposit;
414 type AccountStore = System;
415 type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
416 type MaxReserves = ConstU32<50>;
417 type ReserveIdentifier = [u8; 8];
418 type RuntimeHoldReason = RuntimeHoldReason;
419 type RuntimeFreezeReason = RuntimeFreezeReason;
420 type FreezeIdentifier = ();
421 type MaxFreezes = ConstU32<0>;
422}
423
424parameter_types! {
425 pub const TransactionByteFee: Balance = 10 * MICROUNIT;
427}
428
429impl pallet_transaction_payment::Config for Runtime {
430 type RuntimeEvent = RuntimeEvent;
431 type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, ()>;
432 type WeightToFee = WeightToFee;
433 type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
434 type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
435 type OperationalFeeMultiplier = ConstU8<5>;
436}
437
438parameter_types! {
439 pub const AssetDeposit: Balance = 0;
440 pub const AssetAccountDeposit: Balance = 0;
441 pub const ApprovalDeposit: Balance = 0;
442 pub const AssetsStringLimit: u32 = 50;
443 pub const MetadataDepositBase: Balance = 0;
444 pub const MetadataDepositPerByte: Balance = 0;
445}
446
447pub type TrustBackedAssetsInstance = pallet_assets::Instance1;
452
453impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
454 type RuntimeEvent = RuntimeEvent;
455 type Balance = Balance;
456 type AssetId = AssetId;
457 type AssetIdParameter = codec::Compact<AssetId>;
458 type Currency = Balances;
459 type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
460 type ForceOrigin = EnsureRoot<AccountId>;
461 type AssetDeposit = AssetDeposit;
462 type MetadataDepositBase = MetadataDepositBase;
463 type MetadataDepositPerByte = MetadataDepositPerByte;
464 type ApprovalDeposit = ApprovalDeposit;
465 type StringLimit = AssetsStringLimit;
466 type Freezer = ();
467 type Extra = ();
468 type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
469 type CallbackHandle = ();
470 type AssetAccountDeposit = AssetAccountDeposit;
471 type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
472 #[cfg(feature = "runtime-benchmarks")]
473 type BenchmarkHelper = ();
474}
475
476parameter_types! {
477 pub const ForeignAssetsAssetDeposit: Balance = AssetDeposit::get();
479 pub const ForeignAssetsAssetAccountDeposit: Balance = AssetAccountDeposit::get();
480 pub const ForeignAssetsApprovalDeposit: Balance = ApprovalDeposit::get();
481 pub const ForeignAssetsAssetsStringLimit: u32 = AssetsStringLimit::get();
482 pub const ForeignAssetsMetadataDepositBase: Balance = MetadataDepositBase::get();
483 pub const ForeignAssetsMetadataDepositPerByte: Balance = MetadataDepositPerByte::get();
484}
485
486pub type ForeignAssetsInstance = pallet_assets::Instance2;
488impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
489 type RuntimeEvent = RuntimeEvent;
490 type Balance = Balance;
491 type AssetId = ForeignAssetsAssetId;
492 type AssetIdParameter = ForeignAssetsAssetId;
493 type Currency = Balances;
494 type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
495 type ForceOrigin = EnsureRoot<AccountId>;
496 type AssetDeposit = ForeignAssetsAssetDeposit;
497 type MetadataDepositBase = ForeignAssetsMetadataDepositBase;
498 type MetadataDepositPerByte = ForeignAssetsMetadataDepositPerByte;
499 type ApprovalDeposit = ForeignAssetsApprovalDeposit;
500 type StringLimit = ForeignAssetsAssetsStringLimit;
501 type Freezer = ();
502 type Extra = ();
503 type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
504 type CallbackHandle = ();
505 type AssetAccountDeposit = ForeignAssetsAssetAccountDeposit;
506 type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
507 #[cfg(feature = "runtime-benchmarks")]
508 type BenchmarkHelper = xcm_config::XcmBenchmarkHelper;
509}
510
511parameter_types! {
512 pub const AssetConversionPalletId: PalletId = PalletId(*b"py/ascon");
513 pub const LiquidityWithdrawalFee: Permill = Permill::from_percent(0);
514}
515
516ord_parameter_types! {
517 pub const AssetConversionOrigin: sp_runtime::AccountId32 =
518 AccountIdConversion::<sp_runtime::AccountId32>::into_account_truncating(&AssetConversionPalletId::get());
519}
520
521pub type AssetsForceOrigin = EnsureRoot<AccountId>;
522
523pub type PoolAssetsInstance = pallet_assets::Instance3;
524impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
525 type RuntimeEvent = RuntimeEvent;
526 type Balance = Balance;
527 type RemoveItemsLimit = ConstU32<1000>;
528 type AssetId = u32;
529 type AssetIdParameter = u32;
530 type Currency = Balances;
531 type CreateOrigin =
532 AsEnsureOriginWithArg<EnsureSignedBy<AssetConversionOrigin, sp_runtime::AccountId32>>;
533 type ForceOrigin = AssetsForceOrigin;
534 type AssetDeposit = ConstU128<0>;
535 type AssetAccountDeposit = ConstU128<0>;
536 type MetadataDepositBase = ConstU128<0>;
537 type MetadataDepositPerByte = ConstU128<0>;
538 type ApprovalDeposit = ConstU128<0>;
539 type StringLimit = ConstU32<50>;
540 type Freezer = ();
541 type Extra = ();
542 type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
543 type CallbackHandle = ();
544 #[cfg(feature = "runtime-benchmarks")]
545 type BenchmarkHelper = ();
546}
547
548pub type LocalAndForeignAssets = fungibles::UnionOf<
550 Assets,
551 ForeignAssets,
552 LocalFromLeft<
553 AssetIdForTrustBackedAssetsConvert<
554 xcm_config::TrustBackedAssetsPalletLocation,
555 xcm::latest::Location,
556 >,
557 parachains_common::AssetIdForTrustBackedAssets,
558 xcm::latest::Location,
559 >,
560 xcm::latest::Location,
561 AccountId,
562>;
563
564pub type NativeAndAssets = fungible::UnionOf<
566 Balances,
567 LocalAndForeignAssets,
568 TargetFromLeft<xcm_config::RelayLocation, xcm::latest::Location>,
569 xcm::latest::Location,
570 AccountId,
571>;
572
573pub type PoolIdToAccountId = pallet_asset_conversion::AccountIdConverter<
574 AssetConversionPalletId,
575 (xcm::latest::Location, xcm::latest::Location),
576>;
577
578impl pallet_asset_conversion::Config for Runtime {
579 type RuntimeEvent = RuntimeEvent;
580 type Balance = Balance;
581 type HigherPrecisionBalance = sp_core::U256;
582 type AssetKind = xcm::latest::Location;
583 type Assets = NativeAndAssets;
584 type PoolId = (Self::AssetKind, Self::AssetKind);
585 type PoolLocator = pallet_asset_conversion::WithFirstAsset<
586 xcm_config::RelayLocation,
587 AccountId,
588 Self::AssetKind,
589 PoolIdToAccountId,
590 >;
591 type PoolAssetId = u32;
592 type PoolAssets = PoolAssets;
593 type PoolSetupFee = ConstU128<0>; type PoolSetupFeeAsset = xcm_config::RelayLocation;
595 type PoolSetupFeeTarget = ResolveAssetTo<AssetConversionOrigin, Self::Assets>;
596 type LiquidityWithdrawalFee = LiquidityWithdrawalFee;
597 type LPFee = ConstU32<3>;
598 type PalletId = AssetConversionPalletId;
599 type MaxSwapPathLength = ConstU32<3>;
600 type MintMinLiquidity = ConstU128<100>;
601 type WeightInfo = ();
602 #[cfg(feature = "runtime-benchmarks")]
603 type BenchmarkHelper = assets_common::benchmarks::AssetPairFactory<
604 xcm_config::RelayLocation,
605 parachain_info::Pallet<Runtime>,
606 xcm_config::TrustBackedAssetsPalletIndex,
607 xcm::latest::Location,
608 >;
609}
610
611parameter_types! {
612 pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
613 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
614 pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent;
615}
616
617impl cumulus_pallet_parachain_system::Config for Runtime {
618 type WeightInfo = ();
619 type RuntimeEvent = RuntimeEvent;
620 type OnSystemEvent = ();
621 type SelfParaId = parachain_info::Pallet<Runtime>;
622 type DmpQueue = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
623 type ReservedDmpWeight = ReservedDmpWeight;
624 type OutboundXcmpMessageSource = XcmpQueue;
625 type XcmpMessageHandler = XcmpQueue;
626 type ReservedXcmpWeight = ReservedXcmpWeight;
627 type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases;
628 type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
629 Runtime,
630 RELAY_CHAIN_SLOT_DURATION_MILLIS,
631 BLOCK_PROCESSING_VELOCITY,
632 UNINCLUDED_SEGMENT_CAPACITY,
633 >;
634}
635
636impl parachain_info::Config for Runtime {}
637
638parameter_types! {
639 pub MessageQueueServiceWeight: Weight = Perbill::from_percent(35) * RuntimeBlockWeights::get().max_block;
640}
641
642impl pallet_message_queue::Config for Runtime {
643 type RuntimeEvent = RuntimeEvent;
644 type WeightInfo = ();
645 type MessageProcessor = xcm_builder::ProcessXcmMessage<
646 AggregateMessageOrigin,
647 xcm_executor::XcmExecutor<xcm_config::XcmConfig>,
648 RuntimeCall,
649 >;
650 type Size = u32;
651 type QueueChangeHandler = NarrowOriginToSibling<XcmpQueue>;
653 type QueuePausedQuery = NarrowOriginToSibling<XcmpQueue>;
654 type HeapSize = sp_core::ConstU32<{ 103 * 1024 }>;
655 type MaxStale = sp_core::ConstU32<8>;
656 type ServiceWeight = MessageQueueServiceWeight;
657 type IdleMaxServiceWeight = MessageQueueServiceWeight;
658}
659
660impl cumulus_pallet_aura_ext::Config for Runtime {}
661
662parameter_types! {
663 pub FeeAssetId: AssetLocationId = AssetLocationId(xcm_config::RelayLocation::get());
665 pub const BaseDeliveryFee: u128 = (1_000_000_000_000u128 / 100).saturating_mul(3);
667}
668
669pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice<
670 FeeAssetId,
671 BaseDeliveryFee,
672 TransactionByteFee,
673 XcmpQueue,
674>;
675
676impl cumulus_pallet_xcmp_queue::Config for Runtime {
677 type RuntimeEvent = RuntimeEvent;
678 type ChannelInfo = ParachainSystem;
679 type VersionWrapper = PolkadotXcm;
680 type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
682 type MaxInboundSuspended = ConstU32<1_000>;
683 type MaxActiveOutboundChannels = ConstU32<128>;
684 type MaxPageSize = ConstU32<{ 103 * 1024 }>;
687 type ControllerOrigin = EnsureRoot<AccountId>;
688 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
689 type WeightInfo = ();
690 type PriceForSiblingDelivery = PriceForSiblingParachainDelivery;
691}
692
693parameter_types! {
694 pub const Period: u32 = 6 * HOURS;
695 pub const Offset: u32 = 0;
696}
697
698impl pallet_session::Config for Runtime {
699 type RuntimeEvent = RuntimeEvent;
700 type ValidatorId = <Self as frame_system::Config>::AccountId;
701 type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
703 type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
704 type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
705 type SessionManager = CollatorSelection;
706 type SessionHandler = <SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
708 type Keys = SessionKeys;
709 type WeightInfo = ();
710}
711
712impl pallet_aura::Config for Runtime {
713 type AuthorityId = AuraId;
714 type DisabledValidators = ();
715 type MaxAuthorities = ConstU32<100_000>;
716 type AllowMultipleBlocksPerSlot = ConstBool<false>;
717 type SlotDuration = pallet_aura::MinimumPeriodTimesTwo<Self>;
718}
719
720parameter_types! {
721 pub const PotId: PalletId = PalletId(*b"PotStake");
722 pub const SessionLength: BlockNumber = 6 * HOURS;
723 pub const ExecutiveBody: BodyId = BodyId::Executive;
724}
725
726pub type CollatorSelectionUpdateOrigin = EnsureRoot<AccountId>;
728
729impl pallet_collator_selection::Config for Runtime {
730 type RuntimeEvent = RuntimeEvent;
731 type Currency = Balances;
732 type UpdateOrigin = CollatorSelectionUpdateOrigin;
733 type PotId = PotId;
734 type MaxCandidates = ConstU32<100>;
735 type MinEligibleCollators = ConstU32<4>;
736 type MaxInvulnerables = ConstU32<20>;
737 type KickThreshold = Period;
739 type ValidatorId = <Self as frame_system::Config>::AccountId;
740 type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
741 type ValidatorRegistration = Session;
742 type WeightInfo = ();
743}
744
745impl pallet_asset_tx_payment::Config for Runtime {
746 type RuntimeEvent = RuntimeEvent;
747 type Fungibles = Assets;
748 type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter<
749 pallet_assets::BalanceToAssetBalance<
750 Balances,
751 Runtime,
752 ConvertInto,
753 TrustBackedAssetsInstance,
754 >,
755 AssetsToBlockAuthor<Runtime, TrustBackedAssetsInstance>,
756 >;
757}
758
759impl pallet_sudo::Config for Runtime {
760 type RuntimeEvent = RuntimeEvent;
761 type RuntimeCall = RuntimeCall;
762 type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
763}
764
765construct_runtime!(
767 pub enum Runtime
768 {
769 System: frame_system = 0,
771 ParachainSystem: cumulus_pallet_parachain_system = 1,
772 Timestamp: pallet_timestamp = 2,
773 ParachainInfo: parachain_info = 3,
774
775 Balances: pallet_balances = 10,
777 TransactionPayment: pallet_transaction_payment = 11,
778 AssetTxPayment: pallet_asset_tx_payment = 12,
779
780 Authorship: pallet_authorship = 20,
782 CollatorSelection: pallet_collator_selection = 21,
783 Session: pallet_session = 22,
784 Aura: pallet_aura = 23,
785 AuraExt: cumulus_pallet_aura_ext = 24,
786
787 XcmpQueue: cumulus_pallet_xcmp_queue = 30,
789 PolkadotXcm: pallet_xcm = 31,
790 CumulusXcm: cumulus_pallet_xcm = 32,
791 MessageQueue: pallet_message_queue = 34,
792
793 Assets: pallet_assets::<Instance1> = 50,
795 ForeignAssets: pallet_assets::<Instance2> = 51,
796 PoolAssets: pallet_assets::<Instance3> = 52,
797 AssetConversion: pallet_asset_conversion = 53,
798
799 Sudo: pallet_sudo = 255,
800 }
801);
802
803#[cfg(feature = "runtime-benchmarks")]
804mod benches {
805 frame_benchmarking::define_benchmarks!(
806 [frame_system, SystemBench::<Runtime>]
807 [pallet_balances, Balances]
808 [pallet_message_queue, MessageQueue]
809 [pallet_session, SessionBench::<Runtime>]
810 [pallet_sudo, Sudo]
811 [pallet_timestamp, Timestamp]
812 [pallet_collator_selection, CollatorSelection]
813 [cumulus_pallet_parachain_system, ParachainSystem]
814 [cumulus_pallet_xcmp_queue, XcmpQueue]
815 );
816}
817
818impl_runtime_apis! {
819 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
820 fn slot_duration() -> sp_consensus_aura::SlotDuration {
821 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
822 }
823
824 fn authorities() -> Vec<AuraId> {
825 pallet_aura::Authorities::<Runtime>::get().into_inner()
826 }
827 }
828
829 impl sp_api::Core<Block> for Runtime {
830 fn version() -> RuntimeVersion {
831 VERSION
832 }
833
834 fn execute_block(block: Block) {
835 Executive::execute_block(block)
836 }
837
838 fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
839 Executive::initialize_block(header)
840 }
841 }
842
843 impl sp_api::Metadata<Block> for Runtime {
844 fn metadata() -> OpaqueMetadata {
845 OpaqueMetadata::new(Runtime::metadata().into())
846 }
847
848 fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
849 Runtime::metadata_at_version(version)
850 }
851
852 fn metadata_versions() -> alloc::vec::Vec<u32> {
853 Runtime::metadata_versions()
854 }
855 }
856
857 impl sp_block_builder::BlockBuilder<Block> for Runtime {
858 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
859 Executive::apply_extrinsic(extrinsic)
860 }
861
862 fn finalize_block() -> <Block as BlockT>::Header {
863 Executive::finalize_block()
864 }
865
866 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
867 data.create_extrinsics()
868 }
869
870 fn check_inherents(
871 block: Block,
872 data: sp_inherents::InherentData,
873 ) -> sp_inherents::CheckInherentsResult {
874 data.check_extrinsics(&block)
875 }
876 }
877
878 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
879 fn validate_transaction(
880 source: TransactionSource,
881 tx: <Block as BlockT>::Extrinsic,
882 block_hash: <Block as BlockT>::Hash,
883 ) -> TransactionValidity {
884 Executive::validate_transaction(source, tx, block_hash)
885 }
886 }
887
888 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
889 fn offchain_worker(header: &<Block as BlockT>::Header) {
890 Executive::offchain_worker(header)
891 }
892 }
893
894 impl sp_session::SessionKeys<Block> for Runtime {
895 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
896 SessionKeys::generate(seed)
897 }
898
899 fn decode_session_keys(
900 encoded: Vec<u8>,
901 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
902 SessionKeys::decode_into_raw_public_keys(&encoded)
903 }
904 }
905
906 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
907 fn account_nonce(account: AccountId) -> Nonce {
908 System::account_nonce(account)
909 }
910 }
911
912 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
913 fn query_info(
914 uxt: <Block as BlockT>::Extrinsic,
915 len: u32,
916 ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
917 TransactionPayment::query_info(uxt, len)
918 }
919 fn query_fee_details(
920 uxt: <Block as BlockT>::Extrinsic,
921 len: u32,
922 ) -> pallet_transaction_payment::FeeDetails<Balance> {
923 TransactionPayment::query_fee_details(uxt, len)
924 }
925 fn query_weight_to_fee(weight: Weight) -> Balance {
926 TransactionPayment::weight_to_fee(weight)
927 }
928 fn query_length_to_fee(length: u32) -> Balance {
929 TransactionPayment::length_to_fee(length)
930 }
931 }
932
933 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi<Block, Balance, RuntimeCall>
934 for Runtime
935 {
936 fn query_call_info(
937 call: RuntimeCall,
938 len: u32,
939 ) -> pallet_transaction_payment::RuntimeDispatchInfo<Balance> {
940 TransactionPayment::query_call_info(call, len)
941 }
942 fn query_call_fee_details(
943 call: RuntimeCall,
944 len: u32,
945 ) -> pallet_transaction_payment::FeeDetails<Balance> {
946 TransactionPayment::query_call_fee_details(call, len)
947 }
948 fn query_weight_to_fee(weight: Weight) -> Balance {
949 TransactionPayment::weight_to_fee(weight)
950 }
951 fn query_length_to_fee(length: u32) -> Balance {
952 TransactionPayment::length_to_fee(length)
953 }
954 }
955
956 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
957 fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
958 ParachainSystem::collect_collation_info(header)
959 }
960 }
961
962 impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
963 fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
964 let acceptable_assets = vec![AssetLocationId(xcm_config::RelayLocation::get())];
965 PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)
966 }
967
968 fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
969 match asset.try_as::<AssetLocationId>() {
970 Ok(asset_id) if asset_id.0 == xcm_config::RelayLocation::get() => {
971 Ok(WeightToFee::weight_to_fee(&weight))
973 },
974 Ok(asset_id) => {
975 log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - unhandled asset_id: {asset_id:?}!");
976 Err(XcmPaymentApiError::AssetNotFound)
977 },
978 Err(_) => {
979 log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - failed to convert asset: {asset:?}!");
980 Err(XcmPaymentApiError::VersionedConversionFailed)
981 }
982 }
983 }
984
985 fn query_xcm_weight(message: VersionedXcm<()>) -> Result<Weight, XcmPaymentApiError> {
986 PolkadotXcm::query_xcm_weight(message)
987 }
988
989 fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<VersionedAssets, XcmPaymentApiError> {
990 PolkadotXcm::query_delivery_fees(destination, message)
991 }
992 }
993
994 impl xcm_runtime_apis::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
995 fn dry_run_call(origin: OriginCaller, call: RuntimeCall, result_xcms_version: XcmVersion) -> Result<CallDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
996 PolkadotXcm::dry_run_call::<Runtime, xcm_config::XcmRouter, OriginCaller, RuntimeCall>(origin, call, result_xcms_version)
997 }
998
999 fn dry_run_xcm(origin_location: VersionedLocation, xcm: VersionedXcm<RuntimeCall>) -> Result<XcmDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
1000 PolkadotXcm::dry_run_xcm::<Runtime, xcm_config::XcmRouter, RuntimeCall, xcm_config::XcmConfig>(origin_location, xcm)
1001 }
1002 }
1003
1004 #[cfg(feature = "try-runtime")]
1005 impl frame_try_runtime::TryRuntime<Block> for Runtime {
1006 fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
1007 let weight = Executive::try_runtime_upgrade(checks).unwrap();
1008 (weight, RuntimeBlockWeights::get().max_block)
1009 }
1010
1011 fn execute_block(
1012 block: Block,
1013 state_root_check: bool,
1014 signature_check: bool,
1015 select: frame_try_runtime::TryStateSelect,
1016 ) -> Weight {
1017 Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
1020 }
1021 }
1022
1023 #[cfg(feature = "runtime-benchmarks")]
1024 impl frame_benchmarking::Benchmark<Block> for Runtime {
1025 fn benchmark_metadata(extra: bool) -> (
1026 Vec<frame_benchmarking::BenchmarkList>,
1027 Vec<frame_support::traits::StorageInfo>,
1028 ) {
1029 use frame_benchmarking::{Benchmarking, BenchmarkList};
1030 use frame_support::traits::StorageInfoTrait;
1031 use frame_system_benchmarking::Pallet as SystemBench;
1032 use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
1033
1034 let mut list = Vec::<BenchmarkList>::new();
1035 list_benchmarks!(list, extra);
1036
1037 let storage_info = AllPalletsWithSystem::storage_info();
1038 (list, storage_info)
1039 }
1040
1041 fn dispatch_benchmark(
1042 config: frame_benchmarking::BenchmarkConfig
1043 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
1044 use frame_benchmarking::{Benchmarking, BenchmarkBatch};
1045 use sp_storage::TrackedStorageKey;
1046
1047 use frame_system_benchmarking::Pallet as SystemBench;
1048 impl frame_system_benchmarking::Config for Runtime {}
1049
1050 use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
1051 impl cumulus_pallet_session_benchmarking::Config for Runtime {}
1052
1053 let whitelist: Vec<TrackedStorageKey> = vec![
1054 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
1056 hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),
1058 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),
1060 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),
1062 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),
1064 ];
1065
1066 let mut batches = Vec::<BenchmarkBatch>::new();
1067 let params = (&config, &whitelist);
1068 add_benchmarks!(params, batches);
1069
1070 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
1071 Ok(batches)
1072 }
1073 }
1074
1075 impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
1076 fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
1077 build_state::<RuntimeGenesisConfig>(config)
1078 }
1079
1080 fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
1081 get_preset::<RuntimeGenesisConfig>(id, |_| None)
1082 }
1083
1084 fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
1085 vec![]
1086 }
1087 }
1088}
1089
1090cumulus_pallet_parachain_system::register_validate_block! {
1091 Runtime = Runtime,
1092 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
1093}