parachain_template_runtime/configs/
xcm_config.rs1use crate::{
2 AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm,
3 Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue,
4};
5
6use polkadot_sdk::{
7 staging_xcm as xcm, staging_xcm_builder as xcm_builder, staging_xcm_executor as xcm_executor, *,
8};
9
10use frame_support::{
11 parameter_types,
12 traits::{ConstU32, Contains, Everything, Nothing},
13 weights::Weight,
14};
15use frame_system::EnsureRoot;
16use pallet_xcm::XcmPassthrough;
17use polkadot_parachain_primitives::primitives::Sibling;
18use polkadot_runtime_common::impls::ToAuthor;
19use polkadot_sdk::{
20 polkadot_sdk_frame::traits::Disabled,
21 staging_xcm_builder::{DenyRecursively, DenyThenTry},
22};
23use xcm::latest::prelude::*;
24use xcm_builder::{
25 AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom,
26 DenyReserveTransferToRelayChain, EnsureXcmOrigin, FixedWeightBounds,
27 FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, ParentIsPreset,
28 RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
29 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
30 TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic,
31};
32use xcm_executor::XcmExecutor;
33
34parameter_types! {
35 pub const RelayLocation: Location = Location::parent();
36 pub const RelayNetwork: Option<NetworkId> = None;
37 pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
38 pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into();
41}
42
43pub type LocationToAccountId = (
47 ParentIsPreset<AccountId>,
49 SiblingParachainConvertsVia<Sibling, AccountId>,
51 AccountId32Aliases<RelayNetwork, AccountId>,
53);
54
55pub type LocalAssetTransactor = FungibleAdapter<
57 Balances,
59 IsConcrete<RelayLocation>,
61 LocationToAccountId,
63 AccountId,
65 (),
67>;
68
69pub type XcmOriginToTransactDispatchOrigin = (
73 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
77 RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
80 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
83 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
86 XcmPassthrough<RuntimeOrigin>,
88);
89
90parameter_types! {
91 pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024);
93 pub const MaxInstructions: u32 = 100;
94 pub const MaxAssetsIntoHolding: u32 = 64;
95}
96
97pub struct ParentOrParentsExecutivePlurality;
98impl Contains<Location> for ParentOrParentsExecutivePlurality {
99 fn contains(location: &Location) -> bool {
100 matches!(location.unpack(), (1, []) | (1, [Plurality { id: BodyId::Executive, .. }]))
101 }
102}
103
104pub type Barrier = TrailingSetTopicAsId<
105 DenyThenTry<
106 DenyRecursively<DenyReserveTransferToRelayChain>,
107 (
108 TakeWeightCredit,
109 WithComputedOrigin<
110 (
111 AllowTopLevelPaidExecutionFrom<Everything>,
112 AllowExplicitUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
113 ),
115 UniversalLocation,
116 ConstU32<8>,
117 >,
118 ),
119 >,
120>;
121
122pub struct XcmConfig;
123impl xcm_executor::Config for XcmConfig {
124 type RuntimeCall = RuntimeCall;
125 type XcmSender = XcmRouter;
126 type XcmEventEmitter = PolkadotXcm;
127 type AssetTransactor = LocalAssetTransactor;
129 type OriginConverter = XcmOriginToTransactDispatchOrigin;
130 type IsReserve = NativeAsset;
131 type IsTeleporter = (); type UniversalLocation = UniversalLocation;
133 type Barrier = Barrier;
134 type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
135 type Trader =
136 UsingComponents<WeightToFee, RelayLocation, AccountId, Balances, ToAuthor<Runtime>>;
137 type ResponseHandler = PolkadotXcm;
138 type AssetTrap = PolkadotXcm;
139 type AssetClaims = PolkadotXcm;
140 type SubscriptionService = PolkadotXcm;
141 type PalletInstancesInfo = AllPalletsWithSystem;
142 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
143 type AssetLocker = ();
144 type AssetExchanger = ();
145 type FeeManager = ();
146 type MessageExporter = ();
147 type UniversalAliases = Nothing;
148 type CallDispatcher = RuntimeCall;
149 type SafeCallFilter = Everything;
150 type Aliasers = Nothing;
151 type TransactionalProcessor = FrameTransactionalProcessor;
152 type HrmpNewChannelOpenRequestHandler = ();
153 type HrmpChannelAcceptedHandler = ();
154 type HrmpChannelClosingHandler = ();
155 type XcmRecorder = PolkadotXcm;
156}
157
158pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
161
162pub type XcmRouter = WithUniqueTopic<(
165 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, (), ()>,
167 XcmpQueue,
169)>;
170
171impl pallet_xcm::Config for Runtime {
172 type RuntimeEvent = RuntimeEvent;
173 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
174 type XcmRouter = XcmRouter;
175 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
176 type XcmExecuteFilter = Nothing;
177 type XcmExecutor = XcmExecutor<XcmConfig>;
180 type XcmTeleportFilter = Everything;
181 type XcmReserveTransferFilter = Nothing;
182 type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
183 type UniversalLocation = UniversalLocation;
184 type RuntimeOrigin = RuntimeOrigin;
185 type RuntimeCall = RuntimeCall;
186
187 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
188 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
190 type Currency = Balances;
191 type CurrencyMatcher = ();
192 type TrustedLockers = ();
193 type SovereignAccountOf = LocationToAccountId;
194 type MaxLockers = ConstU32<8>;
195 type WeightInfo = pallet_xcm::TestWeightInfo;
196 type AdminOrigin = EnsureRoot<AccountId>;
197 type MaxRemoteLockConsumers = ConstU32<0>;
198 type RemoteLockConsumerIdentifier = ();
199 type AuthorizedAliasConsideration = Disabled;
201}
202
203impl cumulus_pallet_xcm::Config for Runtime {
204 type RuntimeEvent = RuntimeEvent;
205 type XcmExecutor = XcmExecutor<XcmConfig>;
206}