yet_another_parachain_runtime/
xcm_config.rs1use crate::{
18 AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm,
19 Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue,
20};
21use frame_support::{
22 parameter_types,
23 traits::{ConstU32, Contains, Everything, Nothing},
24 weights::Weight,
25};
26use frame_system::EnsureRoot;
27use pallet_xcm::XcmPassthrough;
28use polkadot_parachain_primitives::primitives::Sibling;
29use polkadot_runtime_common::impls::ToAuthor;
30use xcm::latest::prelude::*;
31use xcm_builder::{
32 AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom,
33 DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds,
34 FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, ParentIsPreset,
35 RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
36 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
37 TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic,
38};
39use xcm_executor::XcmExecutor;
40
41parameter_types! {
42 pub const RelayLocation: Location = Location::parent();
43 pub const RelayNetwork: Option<NetworkId> = None;
44 pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
45 pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into();
48}
49
50pub type LocationToAccountId = (
54 ParentIsPreset<AccountId>,
56 SiblingParachainConvertsVia<Sibling, AccountId>,
58 AccountId32Aliases<RelayNetwork, AccountId>,
60);
61
62pub type LocalAssetTransactor = FungibleAdapter<
64 Balances,
66 IsConcrete<RelayLocation>,
68 LocationToAccountId,
70 AccountId,
72 (),
74>;
75
76pub type XcmOriginToTransactDispatchOrigin = (
80 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
84 RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
87 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
90 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
93 XcmPassthrough<RuntimeOrigin>,
95);
96
97parameter_types! {
98 pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024);
100 pub const MaxInstructions: u32 = 100;
101 pub const MaxAssetsIntoHolding: u32 = 64;
102}
103
104pub struct ParentOrParentsExecutivePlurality;
105impl Contains<Location> for ParentOrParentsExecutivePlurality {
106 fn contains(location: &Location) -> bool {
107 matches!(location.unpack(), (1, []) | (1, [Plurality { id: BodyId::Executive, .. }]))
108 }
109}
110
111pub type Barrier = TrailingSetTopicAsId<
112 DenyThenTry<
113 DenyReserveTransferToRelayChain,
114 (
115 TakeWeightCredit,
116 WithComputedOrigin<
117 (
118 AllowTopLevelPaidExecutionFrom<Everything>,
119 AllowExplicitUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
120 ),
122 UniversalLocation,
123 ConstU32<8>,
124 >,
125 ),
126 >,
127>;
128
129pub struct XcmConfig;
130impl xcm_executor::Config for XcmConfig {
131 type RuntimeCall = RuntimeCall;
132 type XcmSender = XcmRouter;
133 type XcmEventEmitter = PolkadotXcm;
134 type AssetTransactor = LocalAssetTransactor;
136 type OriginConverter = XcmOriginToTransactDispatchOrigin;
137 type IsReserve = NativeAsset;
138 type IsTeleporter = (); type UniversalLocation = UniversalLocation;
140 type Barrier = Barrier;
141 type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
142 type Trader =
143 UsingComponents<WeightToFee, RelayLocation, AccountId, Balances, ToAuthor<Runtime>>;
144 type ResponseHandler = PolkadotXcm;
145 type AssetTrap = PolkadotXcm;
146 type AssetClaims = PolkadotXcm;
147 type SubscriptionService = PolkadotXcm;
148 type PalletInstancesInfo = AllPalletsWithSystem;
149 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
150 type AssetLocker = ();
151 type AssetExchanger = ();
152 type FeeManager = ();
153 type MessageExporter = ();
154 type UniversalAliases = Nothing;
155 type CallDispatcher = RuntimeCall;
156 type SafeCallFilter = Everything;
157 type Aliasers = Nothing;
158 type TransactionalProcessor = FrameTransactionalProcessor;
159 type HrmpNewChannelOpenRequestHandler = ();
160 type HrmpChannelAcceptedHandler = ();
161 type HrmpChannelClosingHandler = ();
162 type XcmRecorder = PolkadotXcm;
163}
164
165pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
167
168pub type XcmRouter = WithUniqueTopic<(
171 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, (), ()>,
173 XcmpQueue,
175)>;
176
177impl pallet_xcm::Config for Runtime {
178 type RuntimeEvent = RuntimeEvent;
179 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
180 type XcmRouter = XcmRouter;
181 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
182 type XcmExecuteFilter = Nothing;
183 type XcmExecutor = XcmExecutor<XcmConfig>;
186 type XcmTeleportFilter = Everything;
187 type XcmReserveTransferFilter = Nothing;
188 type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
189 type UniversalLocation = UniversalLocation;
190 type RuntimeOrigin = RuntimeOrigin;
191 type RuntimeCall = RuntimeCall;
192
193 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
194 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
196 type Currency = Balances;
197 type CurrencyMatcher = ();
198 type TrustedLockers = ();
199 type SovereignAccountOf = LocationToAccountId;
200 type MaxLockers = ConstU32<8>;
201 type WeightInfo = pallet_xcm::TestWeightInfo;
202 type AdminOrigin = EnsureRoot<AccountId>;
203 type MaxRemoteLockConsumers = ConstU32<0>;
204 type RemoteLockConsumerIdentifier = ();
205 type AuthorizedAliasConsideration = ();
206}
207
208impl cumulus_pallet_xcm::Config for Runtime {
209 type RuntimeEvent = RuntimeEvent;
210 type XcmExecutor = XcmExecutor<XcmConfig>;
211}