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, Contains, Equals,
27 Everything, LinearStoragePrice, Nothing,
28 },
29};
30use frame_system::EnsureRoot;
31use pallet_collator_selection::StakingPotAccountId;
32use pallet_xcm::{AuthorizedAliasers, XcmPassthrough};
33use parachains_common::{
34 xcm_config::{
35 AliasAccountId32FromSiblingSystemChain, AllSiblingSystemParachains,
36 ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains,
37 },
38 TREASURY_PALLET_ID,
39};
40use polkadot_parachain_primitives::primitives::Sibling;
41use polkadot_runtime_common::xcm_sender::ExponentialPrice;
42use sp_runtime::traits::AccountIdConversion;
43use westend_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID};
44use xcm::latest::{prelude::*, WESTEND_GENESIS_HASH};
45use xcm_builder::{
46 AccountId32Aliases, AliasChildLocation, AliasOriginRootUsingFilter,
47 AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain,
48 AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
49 DenyRecursively, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal,
50 DescribeFamily, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter,
51 HashedDescription, IsConcrete, NonFungibleAdapter, ParentAsSuperuser, ParentIsPreset,
52 RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia,
53 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
54 TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
55 XcmFeeManagerFromComponents,
56};
57use xcm_executor::XcmExecutor;
58
59parameter_types! {
60 pub const RootLocation: Location = Location::here();
61 pub const TokenRelayLocation: Location = Location::parent();
62 pub AssetHubLocation: Location = Location::new(1, [Parachain(ASSET_HUB_ID)]);
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 pub const GovernanceLocation: Location = Location::parent();
73}
74
75pub type LocationToAccountId = (
79 ParentIsPreset<AccountId>,
81 SiblingParachainConvertsVia<Sibling, AccountId>,
83 AccountId32Aliases<RelayNetwork, AccountId>,
85 HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
87);
88
89pub type FungibleTransactor = FungibleAdapter<
91 Balances,
93 IsConcrete<TokenRelayLocation>,
95 LocationToAccountId,
98 AccountId,
100 (),
102>;
103
104pub type RegionTransactor = NonFungibleAdapter<
106 Broker,
108 IsConcrete<BrokerPalletLocation>,
110 LocationToAccountId,
112 AccountId,
114 (),
116>;
117
118pub type AssetTransactors = (FungibleTransactor, RegionTransactor);
120
121pub type XcmOriginToTransactDispatchOrigin = (
125 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
129 RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
132 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
135 ParentAsSuperuser<RuntimeOrigin>,
138 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
141 XcmPassthrough<RuntimeOrigin>,
143);
144
145pub struct ParentOrParentsPlurality;
146impl Contains<Location> for ParentOrParentsPlurality {
147 fn contains(location: &Location) -> bool {
148 matches!(location.unpack(), (1, []) | (1, [Plurality { .. }]))
149 }
150}
151
152pub struct FellowsPlurality;
153impl Contains<Location> for FellowsPlurality {
154 fn contains(location: &Location) -> bool {
155 matches!(
156 location.unpack(),
157 (1, [Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }])
158 )
159 }
160}
161
162pub type Barrier = TrailingSetTopicAsId<
163 DenyThenTry<
164 DenyRecursively<DenyReserveTransferToRelayChain>,
165 (
166 TakeWeightCredit,
168 AllowKnownQueryResponses<PolkadotXcm>,
170 WithComputedOrigin<
171 (
172 AllowTopLevelPaidExecutionFrom<Everything>,
175 AllowExplicitUnpaidExecutionFrom<(ParentOrParentsPlurality, FellowsPlurality)>,
178 AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
180 AllowHrmpNotificationsFromRelayChain,
182 ),
183 UniversalLocation,
184 ConstU32<8>,
185 >,
186 ),
187 >,
188>;
189
190parameter_types! {
191 pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
192 pub RelayTreasuryLocation: Location = (Parent, PalletInstance(westend_runtime_constants::TREASURY_PALLET_ID)).into();
193}
194
195pub type WaivedLocations = (
198 Equals<RootLocation>,
199 RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
200 Equals<RelayTreasuryLocation>,
201);
202
203pub type TrustedTeleporters = ConcreteAssetFromSystem<TokenRelayLocation>;
206
207pub type TrustedAliasers = (
214 AliasChildLocation,
215 AliasAccountId32FromSiblingSystemChain,
216 AliasOriginRootUsingFilter<AssetHubLocation, Everything>,
217 AuthorizedAliasers<Runtime>,
218);
219
220pub struct XcmConfig;
221impl xcm_executor::Config for XcmConfig {
222 type RuntimeCall = RuntimeCall;
223 type XcmSender = XcmRouter;
224 type XcmEventEmitter = PolkadotXcm;
225 type AssetTransactor = AssetTransactors;
226 type OriginConverter = XcmOriginToTransactDispatchOrigin;
227 type IsReserve = ();
230 type IsTeleporter = TrustedTeleporters;
231 type UniversalLocation = UniversalLocation;
232 type Barrier = Barrier;
233 type Weigher = WeightInfoBounds<
234 crate::weights::xcm::CoretimeWestendXcmWeight<RuntimeCall>,
235 RuntimeCall,
236 MaxInstructions,
237 >;
238 type Trader = UsingComponents<
239 WeightToFee,
240 TokenRelayLocation,
241 AccountId,
242 Balances,
243 ResolveTo<StakingPotAccountId<Runtime>, Balances>,
244 >;
245 type ResponseHandler = PolkadotXcm;
246 type AssetTrap = PolkadotXcm;
247 type AssetClaims = PolkadotXcm;
248 type SubscriptionService = PolkadotXcm;
249 type PalletInstancesInfo = AllPalletsWithSystem;
250 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
251 type AssetLocker = ();
252 type AssetExchanger = ();
253 type FeeManager = XcmFeeManagerFromComponents<
254 WaivedLocations,
255 SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
256 >;
257 type MessageExporter = ();
258 type UniversalAliases = Nothing;
259 type CallDispatcher = RuntimeCall;
260 type SafeCallFilter = Everything;
261 type Aliasers = TrustedAliasers;
262 type TransactionalProcessor = FrameTransactionalProcessor;
263 type HrmpNewChannelOpenRequestHandler = ();
264 type HrmpChannelAcceptedHandler = ();
265 type HrmpChannelClosingHandler = ();
266 type XcmRecorder = PolkadotXcm;
267}
268
269pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
272
273pub type PriceForParentDelivery =
274 ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, ParachainSystem>;
275
276pub type XcmRouter = WithUniqueTopic<(
279 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
281 XcmpQueue,
283)>;
284
285parameter_types! {
286 pub const DepositPerItem: Balance = crate::deposit(1, 0);
287 pub const DepositPerByte: Balance = crate::deposit(0, 1);
288 pub const AuthorizeAliasHoldReason: RuntimeHoldReason = RuntimeHoldReason::PolkadotXcm(pallet_xcm::HoldReason::AuthorizeAlias);
289}
290
291impl pallet_xcm::Config for Runtime {
292 type RuntimeEvent = RuntimeEvent;
293 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
295 type XcmRouter = XcmRouter;
296 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
298 type XcmExecuteFilter = Everything;
299 type XcmExecutor = XcmExecutor<XcmConfig>;
300 type XcmTeleportFilter = Everything;
301 type XcmReserveTransferFilter = Everything;
302 type Weigher = WeightInfoBounds<
303 crate::weights::xcm::CoretimeWestendXcmWeight<RuntimeCall>,
304 RuntimeCall,
305 MaxInstructions,
306 >;
307 type UniversalLocation = UniversalLocation;
308 type RuntimeOrigin = RuntimeOrigin;
309 type RuntimeCall = RuntimeCall;
310 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
311 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
312 type Currency = Balances;
313 type CurrencyMatcher = ();
314 type TrustedLockers = ();
315 type SovereignAccountOf = LocationToAccountId;
316 type MaxLockers = ConstU32<8>;
317 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
318 type AdminOrigin = EnsureRoot<AccountId>;
319 type MaxRemoteLockConsumers = ConstU32<0>;
320 type RemoteLockConsumerIdentifier = ();
321 type AuthorizedAliasConsideration = HoldConsideration<
323 AccountId,
324 Balances,
325 AuthorizeAliasHoldReason,
326 LinearStoragePrice<DepositPerItem, DepositPerByte, Balance>,
327 >;
328}
329
330impl cumulus_pallet_xcm::Config for Runtime {
331 type RuntimeEvent = RuntimeEvent;
332 type XcmExecutor = XcmExecutor<XcmConfig>;
333}