1use super::{
18 AccountId, AllPalletsWithSystem, Balance, Balances, BaseDeliveryFee, Broker, FeeAssetId,
19 ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent,
20 RuntimeHoldReason, RuntimeOrigin, TransactionByteFee, WeightToFee, XcmpQueue,
21};
22use frame_support::{
23 pallet_prelude::PalletInfoAccess,
24 parameter_types,
25 traits::{
26 fungible::HoldConsideration, tokens::imbalance::ResolveTo, ConstU32, ConstU8, Contains,
27 Equals, Everything, LinearStoragePrice, Nothing,
28 },
29};
30use frame_system::EnsureRoot;
31use pallet_collator_selection::StakingPotAccountId;
32use pallet_xcm::{AuthorizedAliasers, XcmPassthrough};
33use parachains_common::xcm_config::{
34 AliasAccountId32FromSiblingSystemChain, AllSiblingSystemParachains, ConcreteAssetFromSystem,
35 ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains,
36};
37use polkadot_parachain_primitives::primitives::Sibling;
38use polkadot_runtime_common::xcm_sender::ExponentialPrice;
39use testnet_parachains_constants::westend::locations::AssetHubLocation;
40use westend_runtime_constants::system_parachain::COLLECTIVES_ID;
41use xcm::latest::{prelude::*, WESTEND_GENESIS_HASH};
42use xcm_builder::{
43 AccountId32Aliases, AliasChildLocation, AliasOriginRootUsingFilter,
44 AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain,
45 AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
46 DenyRecursively, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal,
47 DescribeFamily, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter,
48 HashedDescription, IsConcrete, IsParentsOnly, LocationAsSuperuser, NonFungibleAdapter,
49 ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount,
50 SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
51 SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
52 UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
53 XcmFeeManagerFromComponents,
54};
55use xcm_executor::XcmExecutor;
56
57pub use testnet_parachains_constants::westend::locations::GovernanceLocation;
59
60parameter_types! {
61 pub const RootLocation: Location = Location::here();
62 pub const TokenRelayLocation: Location = Location::parent();
63 pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::ByGenesis(WESTEND_GENESIS_HASH));
64 pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
65 pub UniversalLocation: InteriorLocation =
66 [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into();
67 pub BrokerPalletLocation: Location =
68 PalletInstance(<Broker as PalletInfoAccess>::index() as u8).into();
69 pub const MaxInstructions: u32 = 100;
70 pub const MaxAssetsIntoHolding: u32 = 64;
71 pub FellowshipLocation: Location = Location::new(1, Parachain(COLLECTIVES_ID));
72}
73
74pub type LocationToAccountId = (
78 ParentIsPreset<AccountId>,
80 SiblingParachainConvertsVia<Sibling, AccountId>,
82 AccountId32Aliases<RelayNetwork, AccountId>,
84 HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
86);
87
88pub type FungibleTransactor = FungibleAdapter<
90 Balances,
92 IsConcrete<TokenRelayLocation>,
94 LocationToAccountId,
97 AccountId,
99 (),
101>;
102
103pub type RegionTransactor = NonFungibleAdapter<
105 Broker,
107 IsConcrete<BrokerPalletLocation>,
109 LocationToAccountId,
111 AccountId,
113 (),
115>;
116
117pub type AssetTransactors = (FungibleTransactor, RegionTransactor);
119
120pub type XcmOriginToTransactDispatchOrigin = (
124 LocationAsSuperuser<Equals<GovernanceLocation>, RuntimeOrigin>,
126 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
130 RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
133 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
136 ParentAsSuperuser<RuntimeOrigin>,
139 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
142 XcmPassthrough<RuntimeOrigin>,
144);
145
146pub struct FellowsPlurality;
147impl Contains<Location> for FellowsPlurality {
148 fn contains(location: &Location) -> bool {
149 matches!(
150 location.unpack(),
151 (1, [Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }])
152 )
153 }
154}
155
156pub type Barrier = TrailingSetTopicAsId<
157 DenyThenTry<
158 DenyRecursively<DenyReserveTransferToRelayChain>,
159 (
160 TakeWeightCredit,
162 AllowKnownQueryResponses<PolkadotXcm>,
164 WithComputedOrigin<
165 (
166 AllowTopLevelPaidExecutionFrom<Everything>,
169 AllowExplicitUnpaidExecutionFrom<
172 (
173 IsParentsOnly<ConstU8<1>>,
174 RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
175 FellowsPlurality,
176 Equals<GovernanceLocation>,
177 ),
178 CheapTrustedAliasers,
179 >,
180 AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
182 AllowHrmpNotificationsFromRelayChain,
184 ),
185 UniversalLocation,
186 ConstU32<8>,
187 >,
188 ),
189 >,
190>;
191
192parameter_types! {
193 pub AccumulateAccount: AccountId = pallet_accumulate_and_forward::Pallet::<Runtime>::accumulation_account();
195 pub AccumulateForwardLocation: Location = {
196 AccountId32 { network: None, id: AccumulateAccount::get().into() }.into()
197 };
198}
199
200pub type WaivedLocations = (
203 Equals<RootLocation>,
204 RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
205 Equals<AccumulateForwardLocation>,
206);
207
208pub type TrustedTeleporters = ConcreteAssetFromSystem<TokenRelayLocation>;
211
212pub type CheapTrustedAliasers = (
222 AliasChildLocation,
223 AliasAccountId32FromSiblingSystemChain,
224 AliasOriginRootUsingFilter<AssetHubLocation, Everything>,
225);
226
227pub type TrustedAliasers = (CheapTrustedAliasers, AuthorizedAliasers<Runtime>);
232
233pub struct XcmConfig;
234impl xcm_executor::Config for XcmConfig {
235 type RuntimeCall = RuntimeCall;
236 type XcmSender = XcmRouter;
237 type XcmEventEmitter = PolkadotXcm;
238 type AssetTransactor = AssetTransactors;
239 type OriginConverter = XcmOriginToTransactDispatchOrigin;
240 type IsReserve = ();
243 type IsTeleporter = TrustedTeleporters;
244 type UniversalLocation = UniversalLocation;
245 type Barrier = Barrier;
246 type Weigher = WeightInfoBounds<
247 crate::weights::xcm::CoretimeWestendXcmWeight<RuntimeCall>,
248 RuntimeCall,
249 MaxInstructions,
250 >;
251 type Trader = UsingComponents<
255 WeightToFee,
256 TokenRelayLocation,
257 AccountId,
258 Balances,
259 ResolveTo<StakingPotAccountId<Runtime>, Balances>,
260 >;
261 type ResponseHandler = PolkadotXcm;
262 type AssetTrap = PolkadotXcm;
263 type SubscriptionService = PolkadotXcm;
264 type PalletInstancesInfo = AllPalletsWithSystem;
265 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
266 type AssetLocker = ();
267 type AssetExchanger = ();
268 type FeeManager = XcmFeeManagerFromComponents<
269 WaivedLocations,
270 SendXcmFeeToAccount<Self::AssetTransactor, AccumulateAccount>,
271 >;
272 type MessageExporter = ();
273 type UniversalAliases = Nothing;
274 type CallDispatcher = RuntimeCall;
275 type SafeCallFilter = Everything;
276 type Aliasers = TrustedAliasers;
277 type TransactionalProcessor = FrameTransactionalProcessor;
278 type HrmpNewChannelOpenRequestHandler = ();
279 type HrmpChannelAcceptedHandler = ();
280 type HrmpChannelClosingHandler = ();
281 type XcmRecorder = PolkadotXcm;
282}
283
284pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
287
288pub type PriceForParentDelivery =
289 ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, ParachainSystem>;
290
291pub type XcmRouter = WithUniqueTopic<(
294 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, PriceForParentDelivery>,
296 XcmpQueue,
298)>;
299
300parameter_types! {
301 pub const DepositPerItem: Balance = crate::deposit(1, 0);
302 pub const DepositPerByte: Balance = crate::deposit(0, 1);
303 pub const AuthorizeAliasHoldReason: RuntimeHoldReason = RuntimeHoldReason::PolkadotXcm(pallet_xcm::HoldReason::AuthorizeAlias);
304}
305
306impl pallet_xcm::Config for Runtime {
307 type RuntimeEvent = RuntimeEvent;
308 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
310 type XcmRouter = XcmRouter;
311 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
313 type XcmExecuteFilter = Everything;
314 type XcmExecutor = XcmExecutor<XcmConfig>;
315 type XcmTeleportFilter = Everything;
316 type XcmReserveTransferFilter = Everything;
317 type Weigher = WeightInfoBounds<
318 crate::weights::xcm::CoretimeWestendXcmWeight<RuntimeCall>,
319 RuntimeCall,
320 MaxInstructions,
321 >;
322 type UniversalLocation = UniversalLocation;
323 type RuntimeOrigin = RuntimeOrigin;
324 type RuntimeCall = RuntimeCall;
325 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
326 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
327 type Currency = Balances;
328 type CurrencyMatcher = ();
329 type TrustedLockers = ();
330 type SovereignAccountOf = LocationToAccountId;
331 type MaxLockers = ConstU32<8>;
332 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
333 type AdminOrigin = EnsureRoot<AccountId>;
334 type MaxRemoteLockConsumers = ConstU32<0>;
335 type RemoteLockConsumerIdentifier = ();
336 type AuthorizedAliasConsideration = HoldConsideration<
338 AccountId,
339 Balances,
340 AuthorizeAliasHoldReason,
341 LinearStoragePrice<DepositPerItem, DepositPerByte, Balance>,
342 >;
343}
344
345impl cumulus_pallet_xcm::Config for Runtime {
346 type RuntimeEvent = RuntimeEvent;
347 type XcmExecutor = XcmExecutor<XcmConfig>;
348}