1#![cfg_attr(not(feature = "std"), no_std)]
37#![recursion_limit = "256"]
39
40#[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};
51use assets_common::{
52 foreign_creators::ForeignCreators,
53 local_and_foreign_assets::{LocalFromLeft, TargetFromLeft},
54 AssetIdForTrustBackedAssetsConvert,
55};
56use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
57use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId};
58use frame_support::{
59 construct_runtime, derive_impl,
60 dispatch::DispatchClass,
61 genesis_builder_helper::{build_state, get_preset},
62 ord_parameter_types,
63 pallet_prelude::Weight,
64 parameter_types,
65 traits::{
66 tokens::{fungible, fungibles, imbalance::ResolveAssetTo},
67 AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, Everything,
68 TransformOrigin,
69 },
70 weights::{
71 constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, FeePolynomial,
72 WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
73 },
74 PalletId,
75};
76use frame_system::{
77 limits::{BlockLength, BlockWeights},
78 EnsureRoot, EnsureSigned, EnsureSignedBy,
79};
80use pallet_revive::evm::runtime::EthExtra;
81use parachains_common::{
82 impls::{AssetsToBlockAuthor, NonZeroIssuance},
83 message_queue::{NarrowOriginToSibling, ParaIdToSibling},
84};
85use smallvec::smallvec;
86use sp_api::impl_runtime_apis;
87pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
88use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
89use sp_runtime::{
90 generic, impl_opaque_keys,
91 traits::{AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT},
92 transaction_validity::{TransactionSource, TransactionValidity},
93 ApplyExtrinsicResult,
94};
95pub use sp_runtime::{traits::ConvertInto, MultiAddress, Perbill, Permill};
96#[cfg(feature = "std")]
97use sp_version::NativeVersion;
98use sp_version::RuntimeVersion;
99use xcm_config::{ForeignAssetsAssetId, LocationToAccountId, XcmOriginToTransactDispatchOrigin};
100
101#[cfg(any(feature = "std", test))]
102pub use sp_runtime::BuildStorage;
103
104use parachains_common::{AccountId, Signature};
105use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
106use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
107use xcm::{
108 latest::prelude::{AssetId as AssetLocationId, BodyId},
109 Version as XcmVersion, VersionedAsset, VersionedAssetId, VersionedAssets, VersionedLocation,
110 VersionedXcm,
111};
112use xcm_runtime_apis::{
113 dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
114 fees::Error as XcmPaymentApiError,
115};
116
117pub type Balance = u128;
119
120pub type Nonce = u32;
122
123pub type Hash = sp_core::H256;
125
126pub type BlockNumber = u32;
128
129pub type Address = MultiAddress<AccountId, ()>;
131
132pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
134
135pub type Block = generic::Block<Header, UncheckedExtrinsic>;
137
138pub type SignedBlock = generic::SignedBlock<Block>;
140
141pub type BlockId = generic::BlockId<Block>;
143
144pub type AssetId = u32;
146
147pub type TxExtension = (
149 frame_system::AuthorizeCall<Runtime>,
150 frame_system::CheckNonZeroSender<Runtime>,
151 frame_system::CheckSpecVersion<Runtime>,
152 frame_system::CheckTxVersion<Runtime>,
153 frame_system::CheckGenesis<Runtime>,
154 frame_system::CheckEra<Runtime>,
155 frame_system::CheckNonce<Runtime>,
156 frame_system::CheckWeight<Runtime>,
157 pallet_asset_tx_payment::ChargeAssetTxPayment<Runtime>,
158 frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
159 frame_system::WeightReclaim<Runtime>,
160);
161
162#[derive(Clone, PartialEq, Eq, Debug)]
164pub struct EthExtraImpl;
165
166impl EthExtra for EthExtraImpl {
167 type Config = Runtime;
168 type Extension = TxExtension;
169
170 fn get_eth_extension(nonce: u32, tip: Balance) -> Self::Extension {
171 (
172 frame_system::AuthorizeCall::<Runtime>::new(),
173 frame_system::CheckNonZeroSender::<Runtime>::new(),
174 frame_system::CheckSpecVersion::<Runtime>::new(),
175 frame_system::CheckTxVersion::<Runtime>::new(),
176 frame_system::CheckGenesis::<Runtime>::new(),
177 frame_system::CheckEra::<Runtime>::from(generic::Era::Immortal),
178 frame_system::CheckNonce::<Runtime>::from(nonce),
179 frame_system::CheckWeight::<Runtime>::new(),
180 pallet_asset_tx_payment::ChargeAssetTxPayment::<Runtime>::from(tip, None),
181 frame_metadata_hash_extension::CheckMetadataHash::<Runtime>::new(false),
182 frame_system::WeightReclaim::<Runtime>::new(),
183 )
184 .into()
185 }
186}
187
188pub type UncheckedExtrinsic =
190 pallet_revive::evm::runtime::UncheckedExtrinsic<Address, Signature, EthExtraImpl>;
191
192pub type Migrations = (
193 pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckingAccount>,
194 pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,
195 pallet_session::migrations::v1::MigrateV0ToV1<
196 Runtime,
197 pallet_session::migrations::v1::InitOffenceSeverity<Runtime>,
198 >,
199);
200
201pub type Executive = frame_executive::Executive<
203 Runtime,
204 Block,
205 frame_system::ChainContext<Runtime>,
206 Runtime,
207 AllPalletsWithSystem,
208 Migrations,
209>;
210
211pub struct WeightToFee;
222impl frame_support::weights::WeightToFee for WeightToFee {
223 type Balance = Balance;
224
225 fn weight_to_fee(weight: &Weight) -> Self::Balance {
226 let time_poly: FeePolynomial<Balance> = RefTimeToFee::polynomial().into();
227 let proof_poly: FeePolynomial<Balance> = ProofSizeToFee::polynomial().into();
228
229 time_poly.eval(weight.ref_time()).max(proof_poly.eval(weight.proof_size()))
231 }
232}
233
234pub struct RefTimeToFee;
236impl WeightToFeePolynomial for RefTimeToFee {
237 type Balance = Balance;
238 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
239 let p = MILLIUNIT / 10;
240 let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
241
242 smallvec![WeightToFeeCoefficient {
243 degree: 1,
244 negative: false,
245 coeff_frac: Perbill::from_rational(p % q, q),
246 coeff_integer: p / q,
247 }]
248 }
249}
250
251pub struct ProofSizeToFee;
253impl WeightToFeePolynomial for ProofSizeToFee {
254 type Balance = Balance;
255 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
256 let p = MILLIUNIT / 10;
258 let q = 10_000;
259
260 smallvec![WeightToFeeCoefficient {
261 degree: 1,
262 negative: false,
263 coeff_frac: Perbill::from_rational(p % q, q),
264 coeff_integer: p / q,
265 }]
266 }
267}
268pub mod opaque {
273 use super::*;
274 use sp_runtime::{generic, traits::BlakeTwo256};
275
276 pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
277 pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
279 pub type Block = generic::Block<Header, UncheckedExtrinsic>;
281 pub type BlockId = generic::BlockId<Block>;
283}
284
285impl_opaque_keys! {
286 pub struct SessionKeys {
287 pub aura: Aura,
288 }
289}
290
291#[sp_version::runtime_version]
292pub const VERSION: RuntimeVersion = RuntimeVersion {
293 spec_name: alloc::borrow::Cow::Borrowed("penpal-parachain"),
294 impl_name: alloc::borrow::Cow::Borrowed("penpal-parachain"),
295 authoring_version: 1,
296 spec_version: 1,
297 impl_version: 0,
298 apis: RUNTIME_API_VERSIONS,
299 transaction_version: 1,
300 system_version: 1,
301};
302
303pub const MILLISECS_PER_BLOCK: u64 = 12000;
310
311pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
314
315pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
317pub const HOURS: BlockNumber = MINUTES * 60;
318pub const DAYS: BlockNumber = HOURS * 24;
319
320pub const UNIT: Balance = 1_000_000_000_000;
322pub const MILLIUNIT: Balance = 1_000_000_000;
323pub const MICROUNIT: Balance = 1_000_000;
324
325pub const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT;
327
328const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5);
331
332const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
335
336const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
338 WEIGHT_REF_TIME_PER_SECOND.saturating_div(2),
339 cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
340);
341
342const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
345const BLOCK_PROCESSING_VELOCITY: u32 = 1;
348const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
350
351#[cfg(feature = "std")]
353pub fn native_version() -> NativeVersion {
354 NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
355}
356
357parameter_types! {
358 pub const Version: RuntimeVersion = VERSION;
359
360 pub RuntimeBlockLength: BlockLength =
365 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
366 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
367 .base_block(BlockExecutionWeight::get())
368 .for_class(DispatchClass::all(), |weights| {
369 weights.base_extrinsic = ExtrinsicBaseWeight::get();
370 })
371 .for_class(DispatchClass::Normal, |weights| {
372 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
373 })
374 .for_class(DispatchClass::Operational, |weights| {
375 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
376 weights.reserved = Some(
379 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
380 );
381 })
382 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
383 .build_or_panic();
384 pub const SS58Prefix: u16 = 42;
385}
386
387#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
390impl frame_system::Config for Runtime {
391 type AccountId = AccountId;
393 type RuntimeCall = RuntimeCall;
395 type Lookup = AccountIdLookup<AccountId, ()>;
397 type Nonce = Nonce;
399 type Hash = Hash;
401 type Hashing = BlakeTwo256;
403 type Block = Block;
405 type RuntimeEvent = RuntimeEvent;
407 type RuntimeOrigin = RuntimeOrigin;
409 type BlockHashCount = BlockHashCount;
411 type Version = Version;
413 type PalletInfo = PalletInfo;
415 type AccountData = pallet_balances::AccountData<Balance>;
417 type OnNewAccount = ();
419 type OnKilledAccount = ();
421 type DbWeight = RocksDbWeight;
423 type BaseCallFilter = Everything;
425 type SystemWeightInfo = ();
427 type BlockWeights = RuntimeBlockWeights;
429 type BlockLength = RuntimeBlockLength;
431 type SS58Prefix = SS58Prefix;
433 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
435 type MaxConsumers = frame_support::traits::ConstU32<16>;
436}
437
438impl pallet_timestamp::Config for Runtime {
439 type Moment = u64;
441 type OnTimestampSet = Aura;
442 type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
443 type WeightInfo = ();
444}
445
446impl pallet_authorship::Config for Runtime {
447 type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
448 type EventHandler = (CollatorSelection,);
449}
450
451parameter_types! {
452 pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT;
453}
454
455impl pallet_balances::Config for Runtime {
456 type MaxLocks = ConstU32<50>;
457 type Balance = Balance;
459 type RuntimeEvent = RuntimeEvent;
461 type DustRemoval = ();
462 type ExistentialDeposit = ExistentialDeposit;
463 type AccountStore = System;
464 type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
465 type MaxReserves = ConstU32<50>;
466 type ReserveIdentifier = [u8; 8];
467 type RuntimeHoldReason = RuntimeHoldReason;
468 type RuntimeFreezeReason = RuntimeFreezeReason;
469 type FreezeIdentifier = ();
470 type MaxFreezes = ConstU32<0>;
471 type DoneSlashHandler = ();
472}
473
474parameter_types! {
475 pub const TransactionByteFee: Balance = 10 * MICROUNIT;
477}
478
479impl pallet_transaction_payment::Config for Runtime {
480 type RuntimeEvent = RuntimeEvent;
481 type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, ()>;
482 type WeightToFee = WeightToFee;
483 type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
484 type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
485 type OperationalFeeMultiplier = ConstU8<5>;
486 type WeightInfo = ();
487}
488
489parameter_types! {
490 pub const AssetDeposit: Balance = 0;
491 pub const AssetAccountDeposit: Balance = 0;
492 pub const ApprovalDeposit: Balance = 0;
493 pub const AssetsStringLimit: u32 = 50;
494 pub const MetadataDepositBase: Balance = 0;
495 pub const MetadataDepositPerByte: Balance = 0;
496}
497
498pub type TrustBackedAssetsInstance = pallet_assets::Instance1;
503
504impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
505 type RuntimeEvent = RuntimeEvent;
506 type Balance = Balance;
507 type AssetId = AssetId;
508 type AssetIdParameter = codec::Compact<AssetId>;
509 type Currency = Balances;
510 type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
511 type ForceOrigin = EnsureRoot<AccountId>;
512 type AssetDeposit = AssetDeposit;
513 type MetadataDepositBase = MetadataDepositBase;
514 type MetadataDepositPerByte = MetadataDepositPerByte;
515 type ApprovalDeposit = ApprovalDeposit;
516 type StringLimit = AssetsStringLimit;
517 type Holder = ();
518 type Freezer = ();
519 type Extra = ();
520 type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
521 type CallbackHandle = ();
522 type AssetAccountDeposit = AssetAccountDeposit;
523 type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
524 #[cfg(feature = "runtime-benchmarks")]
525 type BenchmarkHelper = ();
526}
527
528parameter_types! {
529 pub const ForeignAssetsAssetDeposit: Balance = AssetDeposit::get();
531 pub const ForeignAssetsAssetAccountDeposit: Balance = AssetAccountDeposit::get();
532 pub const ForeignAssetsApprovalDeposit: Balance = ApprovalDeposit::get();
533 pub const ForeignAssetsAssetsStringLimit: u32 = AssetsStringLimit::get();
534 pub const ForeignAssetsMetadataDepositBase: Balance = MetadataDepositBase::get();
535 pub const ForeignAssetsMetadataDepositPerByte: Balance = MetadataDepositPerByte::get();
536}
537
538pub type ForeignAssetsInstance = pallet_assets::Instance2;
540impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
541 type RuntimeEvent = RuntimeEvent;
542 type Balance = Balance;
543 type AssetId = ForeignAssetsAssetId;
544 type AssetIdParameter = ForeignAssetsAssetId;
545 type Currency = Balances;
546 type CreateOrigin =
549 ForeignCreators<Everything, LocationToAccountId, AccountId, xcm::latest::Location>;
550 type ForceOrigin = EnsureRoot<AccountId>;
551 type AssetDeposit = ForeignAssetsAssetDeposit;
552 type MetadataDepositBase = ForeignAssetsMetadataDepositBase;
553 type MetadataDepositPerByte = ForeignAssetsMetadataDepositPerByte;
554 type ApprovalDeposit = ForeignAssetsApprovalDeposit;
555 type StringLimit = ForeignAssetsAssetsStringLimit;
556 type Holder = ();
557 type Freezer = ();
558 type Extra = ();
559 type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
560 type CallbackHandle = ();
561 type AssetAccountDeposit = ForeignAssetsAssetAccountDeposit;
562 type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
563 #[cfg(feature = "runtime-benchmarks")]
564 type BenchmarkHelper = xcm_config::XcmBenchmarkHelper;
565}
566
567parameter_types! {
568 pub const AssetConversionPalletId: PalletId = PalletId(*b"py/ascon");
569 pub const LiquidityWithdrawalFee: Permill = Permill::from_percent(0);
570}
571
572ord_parameter_types! {
573 pub const AssetConversionOrigin: sp_runtime::AccountId32 =
574 AccountIdConversion::<sp_runtime::AccountId32>::into_account_truncating(&AssetConversionPalletId::get());
575}
576
577pub type AssetsForceOrigin = EnsureRoot<AccountId>;
578
579pub type PoolAssetsInstance = pallet_assets::Instance3;
580impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
581 type RuntimeEvent = RuntimeEvent;
582 type Balance = Balance;
583 type RemoveItemsLimit = ConstU32<1000>;
584 type AssetId = u32;
585 type AssetIdParameter = u32;
586 type Currency = Balances;
587 type CreateOrigin =
588 AsEnsureOriginWithArg<EnsureSignedBy<AssetConversionOrigin, sp_runtime::AccountId32>>;
589 type ForceOrigin = AssetsForceOrigin;
590 type AssetDeposit = ConstU128<0>;
591 type AssetAccountDeposit = ConstU128<0>;
592 type MetadataDepositBase = ConstU128<0>;
593 type MetadataDepositPerByte = ConstU128<0>;
594 type ApprovalDeposit = ConstU128<0>;
595 type StringLimit = ConstU32<50>;
596 type Holder = ();
597 type Freezer = ();
598 type Extra = ();
599 type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
600 type CallbackHandle = ();
601 #[cfg(feature = "runtime-benchmarks")]
602 type BenchmarkHelper = ();
603}
604
605pub type LocalAndForeignAssets = fungibles::UnionOf<
607 Assets,
608 ForeignAssets,
609 LocalFromLeft<
610 AssetIdForTrustBackedAssetsConvert<
611 xcm_config::TrustBackedAssetsPalletLocation,
612 xcm::latest::Location,
613 >,
614 parachains_common::AssetIdForTrustBackedAssets,
615 xcm::latest::Location,
616 >,
617 xcm::latest::Location,
618 AccountId,
619>;
620
621pub type NativeAndAssets = fungible::UnionOf<
623 Balances,
624 LocalAndForeignAssets,
625 TargetFromLeft<xcm_config::RelayLocation, xcm::latest::Location>,
626 xcm::latest::Location,
627 AccountId,
628>;
629
630pub type PoolIdToAccountId = pallet_asset_conversion::AccountIdConverter<
631 AssetConversionPalletId,
632 (xcm::latest::Location, xcm::latest::Location),
633>;
634
635impl pallet_asset_conversion::Config for Runtime {
636 type RuntimeEvent = RuntimeEvent;
637 type Balance = Balance;
638 type HigherPrecisionBalance = sp_core::U256;
639 type AssetKind = xcm::latest::Location;
640 type Assets = NativeAndAssets;
641 type PoolId = (Self::AssetKind, Self::AssetKind);
642 type PoolLocator = pallet_asset_conversion::WithFirstAsset<
643 xcm_config::RelayLocation,
644 AccountId,
645 Self::AssetKind,
646 PoolIdToAccountId,
647 >;
648 type PoolAssetId = u32;
649 type PoolAssets = PoolAssets;
650 type PoolSetupFee = ConstU128<0>; type PoolSetupFeeAsset = xcm_config::RelayLocation;
652 type PoolSetupFeeTarget = ResolveAssetTo<AssetConversionOrigin, Self::Assets>;
653 type LiquidityWithdrawalFee = LiquidityWithdrawalFee;
654 type LPFee = ConstU32<3>;
655 type PalletId = AssetConversionPalletId;
656 type MaxSwapPathLength = ConstU32<3>;
657 type MintMinLiquidity = ConstU128<100>;
658 type WeightInfo = ();
659 #[cfg(feature = "runtime-benchmarks")]
660 type BenchmarkHelper = assets_common::benchmarks::AssetPairFactory<
661 xcm_config::RelayLocation,
662 parachain_info::Pallet<Runtime>,
663 xcm_config::TrustBackedAssetsPalletIndex,
664 xcm::latest::Location,
665 >;
666}
667
668parameter_types! {
669 pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
670 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
671 pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent;
672}
673
674impl cumulus_pallet_parachain_system::Config for Runtime {
675 type WeightInfo = ();
676 type RuntimeEvent = RuntimeEvent;
677 type OnSystemEvent = ();
678 type SelfParaId = parachain_info::Pallet<Runtime>;
679 type DmpQueue = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
680 type ReservedDmpWeight = ReservedDmpWeight;
681 type OutboundXcmpMessageSource = XcmpQueue;
682 type XcmpMessageHandler = XcmpQueue;
683 type ReservedXcmpWeight = ReservedXcmpWeight;
684 type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases;
685 type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
686 Runtime,
687 RELAY_CHAIN_SLOT_DURATION_MILLIS,
688 BLOCK_PROCESSING_VELOCITY,
689 UNINCLUDED_SEGMENT_CAPACITY,
690 >;
691 type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
692 type RelayParentOffset = ConstU32<0>;
693}
694
695impl parachain_info::Config for Runtime {}
696
697parameter_types! {
698 pub MessageQueueServiceWeight: Weight = Perbill::from_percent(35) * RuntimeBlockWeights::get().max_block;
699}
700
701impl pallet_message_queue::Config for Runtime {
702 type RuntimeEvent = RuntimeEvent;
703 type WeightInfo = ();
704 type MessageProcessor = xcm_builder::ProcessXcmMessage<
705 AggregateMessageOrigin,
706 xcm_executor::XcmExecutor<xcm_config::XcmConfig>,
707 RuntimeCall,
708 >;
709 type Size = u32;
710 type QueueChangeHandler = NarrowOriginToSibling<XcmpQueue>;
712 type QueuePausedQuery = NarrowOriginToSibling<XcmpQueue>;
713 type HeapSize = sp_core::ConstU32<{ 103 * 1024 }>;
714 type MaxStale = sp_core::ConstU32<8>;
715 type ServiceWeight = MessageQueueServiceWeight;
716 type IdleMaxServiceWeight = MessageQueueServiceWeight;
717}
718
719impl cumulus_pallet_aura_ext::Config for Runtime {}
720
721parameter_types! {
722 pub FeeAssetId: AssetLocationId = AssetLocationId(xcm_config::RelayLocation::get());
724 pub const BaseDeliveryFee: u128 = (1_000_000_000_000u128 / 100).saturating_mul(3);
726}
727
728pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice<
729 FeeAssetId,
730 BaseDeliveryFee,
731 TransactionByteFee,
732 XcmpQueue,
733>;
734
735impl cumulus_pallet_xcmp_queue::Config for Runtime {
736 type RuntimeEvent = RuntimeEvent;
737 type ChannelInfo = ParachainSystem;
738 type VersionWrapper = PolkadotXcm;
739 type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
741 type MaxInboundSuspended = ConstU32<1_000>;
742 type MaxActiveOutboundChannels = ConstU32<128>;
743 type MaxPageSize = ConstU32<{ 103 * 1024 }>;
746 type ControllerOrigin = EnsureRoot<AccountId>;
747 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
748 type WeightInfo = ();
749 type PriceForSiblingDelivery = PriceForSiblingParachainDelivery;
750}
751
752parameter_types! {
753 pub const Period: u32 = 6 * HOURS;
754 pub const Offset: u32 = 0;
755}
756impl pallet_session::Config for Runtime {
757 type RuntimeEvent = RuntimeEvent;
758 type ValidatorId = <Self as frame_system::Config>::AccountId;
759 type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
761 type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
762 type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
763 type SessionManager = CollatorSelection;
764 type SessionHandler = <SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
766 type Keys = SessionKeys;
767 type DisablingStrategy = ();
768 type WeightInfo = ();
769 type Currency = Balances;
770 type KeyDeposit = ();
771}
772
773impl pallet_aura::Config for Runtime {
774 type AuthorityId = AuraId;
775 type DisabledValidators = ();
776 type MaxAuthorities = ConstU32<100_000>;
777 type AllowMultipleBlocksPerSlot = ConstBool<false>;
778 type SlotDuration = pallet_aura::MinimumPeriodTimesTwo<Self>;
779}
780
781parameter_types! {
782 pub const PotId: PalletId = PalletId(*b"PotStake");
783 pub const SessionLength: BlockNumber = 6 * HOURS;
784 pub const ExecutiveBody: BodyId = BodyId::Executive;
785}
786
787pub type CollatorSelectionUpdateOrigin = EnsureRoot<AccountId>;
789
790impl pallet_collator_selection::Config for Runtime {
791 type RuntimeEvent = RuntimeEvent;
792 type Currency = Balances;
793 type UpdateOrigin = CollatorSelectionUpdateOrigin;
794 type PotId = PotId;
795 type MaxCandidates = ConstU32<100>;
796 type MinEligibleCollators = ConstU32<4>;
797 type MaxInvulnerables = ConstU32<20>;
798 type KickThreshold = Period;
800 type ValidatorId = <Self as frame_system::Config>::AccountId;
801 type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
802 type ValidatorRegistration = Session;
803 type WeightInfo = ();
804}
805
806#[cfg(feature = "runtime-benchmarks")]
807pub struct AssetTxHelper;
808
809#[cfg(feature = "runtime-benchmarks")]
810impl pallet_asset_tx_payment::BenchmarkHelperTrait<AccountId, u32, u32> for AssetTxHelper {
811 fn create_asset_id_parameter(_id: u32) -> (u32, u32) {
812 unimplemented!("Penpal uses default weights");
813 }
814 fn setup_balances_and_pool(_asset_id: u32, _account: AccountId) {
815 unimplemented!("Penpal uses default weights");
816 }
817}
818
819impl pallet_asset_tx_payment::Config for Runtime {
820 type RuntimeEvent = RuntimeEvent;
821 type Fungibles = Assets;
822 type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter<
823 pallet_assets::BalanceToAssetBalance<
824 Balances,
825 Runtime,
826 ConvertInto,
827 TrustBackedAssetsInstance,
828 >,
829 AssetsToBlockAuthor<Runtime, TrustBackedAssetsInstance>,
830 >;
831 type WeightInfo = ();
832 #[cfg(feature = "runtime-benchmarks")]
833 type BenchmarkHelper = AssetTxHelper;
834}
835
836parameter_types! {
837 pub const DepositPerItem: Balance = 0;
838 pub const DepositPerByte: Balance = 0;
839 pub CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(30);
840}
841
842impl pallet_revive::Config for Runtime {
843 type Time = Timestamp;
844 type Currency = Balances;
845 type RuntimeEvent = RuntimeEvent;
846 type RuntimeCall = RuntimeCall;
847 type DepositPerItem = DepositPerItem;
848 type DepositPerByte = DepositPerByte;
849 type WeightPrice = pallet_transaction_payment::Pallet<Self>;
850 type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
851 type Precompiles = ();
852 type AddressMapper = pallet_revive::AccountId32Mapper<Self>;
853 type RuntimeMemory = ConstU32<{ 128 * 1024 * 1024 }>;
854 type PVFMemory = ConstU32<{ 512 * 1024 * 1024 }>;
855 type UnsafeUnstableInterface = ConstBool<true>;
856 type UploadOrigin = EnsureSigned<Self::AccountId>;
857 type InstantiateOrigin = EnsureSigned<Self::AccountId>;
858 type RuntimeHoldReason = RuntimeHoldReason;
859 type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
860 type ChainId = ConstU64<420_420_999>;
861 type NativeToEthRatio = ConstU32<1_000_000>; type EthGasEncoder = ();
863 type FindAuthor = <Runtime as pallet_authorship::Config>::FindAuthor;
864}
865
866impl pallet_sudo::Config for Runtime {
867 type RuntimeEvent = RuntimeEvent;
868 type RuntimeCall = RuntimeCall;
869 type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
870}
871
872impl pallet_utility::Config for Runtime {
873 type RuntimeEvent = RuntimeEvent;
874 type RuntimeCall = RuntimeCall;
875 type PalletsOrigin = OriginCaller;
876 type WeightInfo = pallet_utility::weights::SubstrateWeight<Runtime>;
877}
878
879construct_runtime!(
881 pub enum Runtime
882 {
883 System: frame_system = 0,
885 ParachainSystem: cumulus_pallet_parachain_system = 1,
886 Timestamp: pallet_timestamp = 2,
887 ParachainInfo: parachain_info = 3,
888
889 Balances: pallet_balances = 10,
891 TransactionPayment: pallet_transaction_payment = 11,
892 AssetTxPayment: pallet_asset_tx_payment = 12,
893
894 Authorship: pallet_authorship = 20,
896 CollatorSelection: pallet_collator_selection = 21,
897 Session: pallet_session = 22,
898 Aura: pallet_aura = 23,
899 AuraExt: cumulus_pallet_aura_ext = 24,
900
901 XcmpQueue: cumulus_pallet_xcmp_queue = 30,
903 PolkadotXcm: pallet_xcm = 31,
904 CumulusXcm: cumulus_pallet_xcm = 32,
905 MessageQueue: pallet_message_queue = 34,
906
907 Utility: pallet_utility = 40,
909
910 Assets: pallet_assets::<Instance1> = 50,
912 ForeignAssets: pallet_assets::<Instance2> = 51,
913 PoolAssets: pallet_assets::<Instance3> = 52,
914 AssetConversion: pallet_asset_conversion = 53,
915
916 Revive: pallet_revive = 60,
917
918 Sudo: pallet_sudo = 255,
919 }
920);
921
922#[cfg(feature = "runtime-benchmarks")]
923mod benches {
924 frame_benchmarking::define_benchmarks!(
925 [frame_system, SystemBench::<Runtime>]
926 [frame_system_extensions, SystemExtensionsBench::<Runtime>]
927 [pallet_balances, Balances]
928 [pallet_message_queue, MessageQueue]
929 [pallet_session, SessionBench::<Runtime>]
930 [pallet_sudo, Sudo]
931 [pallet_timestamp, Timestamp]
932 [pallet_collator_selection, CollatorSelection]
933 [cumulus_pallet_parachain_system, ParachainSystem]
934 [cumulus_pallet_xcmp_queue, XcmpQueue]
935 [pallet_utility, Utility]
936 );
937}
938
939impl_runtime_apis! {
940 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
941 fn slot_duration() -> sp_consensus_aura::SlotDuration {
942 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
943 }
944
945 fn authorities() -> Vec<AuraId> {
946 pallet_aura::Authorities::<Runtime>::get().into_inner()
947 }
948 }
949
950 impl sp_api::Core<Block> for Runtime {
951 fn version() -> RuntimeVersion {
952 VERSION
953 }
954
955 fn execute_block(block: Block) {
956 Executive::execute_block(block)
957 }
958
959 fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
960 Executive::initialize_block(header)
961 }
962 }
963
964 impl sp_api::Metadata<Block> for Runtime {
965 fn metadata() -> OpaqueMetadata {
966 OpaqueMetadata::new(Runtime::metadata().into())
967 }
968
969 fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
970 Runtime::metadata_at_version(version)
971 }
972
973 fn metadata_versions() -> alloc::vec::Vec<u32> {
974 Runtime::metadata_versions()
975 }
976 }
977
978 impl sp_block_builder::BlockBuilder<Block> for Runtime {
979 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
980 Executive::apply_extrinsic(extrinsic)
981 }
982
983 fn finalize_block() -> <Block as BlockT>::Header {
984 Executive::finalize_block()
985 }
986
987 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
988 data.create_extrinsics()
989 }
990
991 fn check_inherents(
992 block: Block,
993 data: sp_inherents::InherentData,
994 ) -> sp_inherents::CheckInherentsResult {
995 data.check_extrinsics(&block)
996 }
997 }
998
999 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
1000 fn validate_transaction(
1001 source: TransactionSource,
1002 tx: <Block as BlockT>::Extrinsic,
1003 block_hash: <Block as BlockT>::Hash,
1004 ) -> TransactionValidity {
1005 Executive::validate_transaction(source, tx, block_hash)
1006 }
1007 }
1008
1009 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
1010 fn offchain_worker(header: &<Block as BlockT>::Header) {
1011 Executive::offchain_worker(header)
1012 }
1013 }
1014
1015 impl sp_session::SessionKeys<Block> for Runtime {
1016 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
1017 SessionKeys::generate(seed)
1018 }
1019
1020 fn decode_session_keys(
1021 encoded: Vec<u8>,
1022 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
1023 SessionKeys::decode_into_raw_public_keys(&encoded)
1024 }
1025 }
1026
1027 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
1028 fn account_nonce(account: AccountId) -> Nonce {
1029 System::account_nonce(account)
1030 }
1031 }
1032
1033 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
1034 fn query_info(
1035 uxt: <Block as BlockT>::Extrinsic,
1036 len: u32,
1037 ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
1038 TransactionPayment::query_info(uxt, len)
1039 }
1040 fn query_fee_details(
1041 uxt: <Block as BlockT>::Extrinsic,
1042 len: u32,
1043 ) -> pallet_transaction_payment::FeeDetails<Balance> {
1044 TransactionPayment::query_fee_details(uxt, len)
1045 }
1046 fn query_weight_to_fee(weight: Weight) -> Balance {
1047 TransactionPayment::weight_to_fee(weight)
1048 }
1049 fn query_length_to_fee(length: u32) -> Balance {
1050 TransactionPayment::length_to_fee(length)
1051 }
1052 }
1053
1054 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi<Block, Balance, RuntimeCall>
1055 for Runtime
1056 {
1057 fn query_call_info(
1058 call: RuntimeCall,
1059 len: u32,
1060 ) -> pallet_transaction_payment::RuntimeDispatchInfo<Balance> {
1061 TransactionPayment::query_call_info(call, len)
1062 }
1063 fn query_call_fee_details(
1064 call: RuntimeCall,
1065 len: u32,
1066 ) -> pallet_transaction_payment::FeeDetails<Balance> {
1067 TransactionPayment::query_call_fee_details(call, len)
1068 }
1069 fn query_weight_to_fee(weight: Weight) -> Balance {
1070 TransactionPayment::weight_to_fee(weight)
1071 }
1072 fn query_length_to_fee(length: u32) -> Balance {
1073 TransactionPayment::length_to_fee(length)
1074 }
1075 }
1076
1077 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
1078 fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
1079 ParachainSystem::collect_collation_info(header)
1080 }
1081 }
1082
1083 impl cumulus_primitives_core::GetCoreSelectorApi<Block> for Runtime {
1084 fn core_selector() -> (CoreSelector, ClaimQueueOffset) {
1085 ParachainSystem::core_selector()
1086 }
1087 }
1088
1089 impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
1090 fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
1091 let acceptable_assets = vec![AssetLocationId(xcm_config::RelayLocation::get())];
1092 PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)
1093 }
1094
1095 fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
1096 use crate::xcm_config::XcmConfig;
1097
1098 type Trader = <XcmConfig as xcm_executor::Config>::Trader;
1099
1100 PolkadotXcm::query_weight_to_asset_fee::<Trader>(weight, asset)
1101 }
1102
1103 fn query_xcm_weight(message: VersionedXcm<()>) -> Result<Weight, XcmPaymentApiError> {
1104 PolkadotXcm::query_xcm_weight(message)
1105 }
1106
1107 fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<VersionedAssets, XcmPaymentApiError> {
1108 PolkadotXcm::query_delivery_fees(destination, message)
1109 }
1110 }
1111
1112 impl xcm_runtime_apis::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
1113 fn dry_run_call(origin: OriginCaller, call: RuntimeCall, result_xcms_version: XcmVersion) -> Result<CallDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
1114 PolkadotXcm::dry_run_call::<Runtime, xcm_config::XcmRouter, OriginCaller, RuntimeCall>(origin, call, result_xcms_version)
1115 }
1116
1117 fn dry_run_xcm(origin_location: VersionedLocation, xcm: VersionedXcm<RuntimeCall>) -> Result<XcmDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
1118 PolkadotXcm::dry_run_xcm::<Runtime, xcm_config::XcmRouter, RuntimeCall, xcm_config::XcmConfig>(origin_location, xcm)
1119 }
1120 }
1121
1122 impl xcm_runtime_apis::conversions::LocationToAccountApi<Block, AccountId> for Runtime {
1123 fn convert_location(location: VersionedLocation) -> Result<
1124 AccountId,
1125 xcm_runtime_apis::conversions::Error
1126 > {
1127 xcm_runtime_apis::conversions::LocationToAccountHelper::<
1128 AccountId,
1129 xcm_config::LocationToAccountId,
1130 >::convert_location(location)
1131 }
1132 }
1133
1134 impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
1135 fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
1136 PolkadotXcm::is_trusted_reserve(asset, location)
1137 }
1138 fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
1139 PolkadotXcm::is_trusted_teleporter(asset, location)
1140 }
1141 }
1142
1143 impl xcm_runtime_apis::authorized_aliases::AuthorizedAliasersApi<Block> for Runtime {
1144 fn authorized_aliasers(target: VersionedLocation) -> Result<
1145 Vec<xcm_runtime_apis::authorized_aliases::OriginAliaser>,
1146 xcm_runtime_apis::authorized_aliases::Error
1147 > {
1148 PolkadotXcm::authorized_aliasers(target)
1149 }
1150 fn is_authorized_alias(origin: VersionedLocation, target: VersionedLocation) -> Result<
1151 bool,
1152 xcm_runtime_apis::authorized_aliases::Error
1153 > {
1154 PolkadotXcm::is_authorized_alias(origin, target)
1155 }
1156 }
1157
1158 #[cfg(feature = "try-runtime")]
1159 impl frame_try_runtime::TryRuntime<Block> for Runtime {
1160 fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
1161 let weight = Executive::try_runtime_upgrade(checks).unwrap();
1162 (weight, RuntimeBlockWeights::get().max_block)
1163 }
1164
1165 fn execute_block(
1166 block: Block,
1167 state_root_check: bool,
1168 signature_check: bool,
1169 select: frame_try_runtime::TryStateSelect,
1170 ) -> Weight {
1171 Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
1174 }
1175 }
1176
1177 #[cfg(feature = "runtime-benchmarks")]
1178 impl frame_benchmarking::Benchmark<Block> for Runtime {
1179 fn benchmark_metadata(extra: bool) -> (
1180 Vec<frame_benchmarking::BenchmarkList>,
1181 Vec<frame_support::traits::StorageInfo>,
1182 ) {
1183 use frame_benchmarking::BenchmarkList;
1184 use frame_support::traits::StorageInfoTrait;
1185 use frame_system_benchmarking::Pallet as SystemBench;
1186 use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
1187 use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
1188
1189 let mut list = Vec::<BenchmarkList>::new();
1190 list_benchmarks!(list, extra);
1191
1192 let storage_info = AllPalletsWithSystem::storage_info();
1193 (list, storage_info)
1194 }
1195
1196 #[allow(non_local_definitions)]
1197 fn dispatch_benchmark(
1198 config: frame_benchmarking::BenchmarkConfig
1199 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> {
1200 use frame_benchmarking::BenchmarkBatch;
1201 use sp_storage::TrackedStorageKey;
1202
1203 use frame_system_benchmarking::Pallet as SystemBench;
1204 use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
1205 impl frame_system_benchmarking::Config for Runtime {}
1206
1207 use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
1208 impl cumulus_pallet_session_benchmarking::Config for Runtime {}
1209
1210 use frame_support::traits::WhitelistedStorageKeys;
1211 let whitelist: Vec<TrackedStorageKey> = AllPalletsWithSystem::whitelisted_storage_keys();
1212
1213 let mut batches = Vec::<BenchmarkBatch>::new();
1214 let params = (&config, &whitelist);
1215 add_benchmarks!(params, batches);
1216
1217 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
1218 Ok(batches)
1219 }
1220 }
1221
1222 impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
1223 fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
1224 build_state::<RuntimeGenesisConfig>(config)
1225 }
1226
1227 fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
1228 get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset)
1229 }
1230
1231 fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
1232 genesis_config_presets::preset_names()
1233 }
1234 }
1235
1236 impl cumulus_primitives_core::GetParachainInfo<Block> for Runtime {
1237 fn parachain_id() -> ParaId {
1238 ParachainInfo::parachain_id()
1239 }
1240 }
1241}
1242
1243cumulus_pallet_parachain_system::register_validate_block! {
1244 Runtime = Runtime,
1245 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
1246}