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 testnet_parachains_constants::westend::locations::AssetHubLocation;
44use westend_runtime_constants::system_parachain::COLLECTIVES_ID;
45use xcm::latest::{prelude::*, WESTEND_GENESIS_HASH};
46use xcm_builder::{
47 AccountId32Aliases, AliasChildLocation, AliasOriginRootUsingFilter,
48 AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain,
49 AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
50 DenyRecursively, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal,
51 DescribeFamily, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter,
52 HashedDescription, IsConcrete, LocationAsSuperuser, NonFungibleAdapter, ParentAsSuperuser,
53 ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative,
54 SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
55 SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
56 WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents,
57};
58use xcm_executor::XcmExecutor;
59
60pub use testnet_parachains_constants::westend::locations::GovernanceLocation;
62
63parameter_types! {
64 pub const RootLocation: Location = Location::here();
65 pub const TokenRelayLocation: Location = Location::parent();
66 pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::ByGenesis(WESTEND_GENESIS_HASH));
67 pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
68 pub UniversalLocation: InteriorLocation =
69 [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into();
70 pub BrokerPalletLocation: Location =
71 PalletInstance(<Broker as PalletInfoAccess>::index() as u8).into();
72 pub const MaxInstructions: u32 = 100;
73 pub const MaxAssetsIntoHolding: u32 = 64;
74 pub FellowshipLocation: Location = Location::new(1, Parachain(COLLECTIVES_ID));
75}
76
77pub type LocationToAccountId = (
81 ParentIsPreset<AccountId>,
83 SiblingParachainConvertsVia<Sibling, AccountId>,
85 AccountId32Aliases<RelayNetwork, AccountId>,
87 HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
89);
90
91pub type FungibleTransactor = FungibleAdapter<
93 Balances,
95 IsConcrete<TokenRelayLocation>,
97 LocationToAccountId,
100 AccountId,
102 (),
104>;
105
106pub type RegionTransactor = NonFungibleAdapter<
108 Broker,
110 IsConcrete<BrokerPalletLocation>,
112 LocationToAccountId,
114 AccountId,
116 (),
118>;
119
120pub type AssetTransactors = (FungibleTransactor, RegionTransactor);
122
123pub type XcmOriginToTransactDispatchOrigin = (
127 LocationAsSuperuser<Equals<GovernanceLocation>, RuntimeOrigin>,
129 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
133 RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
136 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
139 ParentAsSuperuser<RuntimeOrigin>,
142 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
145 XcmPassthrough<RuntimeOrigin>,
147);
148
149pub struct ParentOrParentsPlurality;
150impl Contains<Location> for ParentOrParentsPlurality {
151 fn contains(location: &Location) -> bool {
152 matches!(location.unpack(), (1, []) | (1, [Plurality { .. }]))
153 }
154}
155
156pub struct FellowsPlurality;
157impl Contains<Location> for FellowsPlurality {
158 fn contains(location: &Location) -> bool {
159 matches!(
160 location.unpack(),
161 (1, [Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }])
162 )
163 }
164}
165
166pub type Barrier = TrailingSetTopicAsId<
167 DenyThenTry<
168 DenyRecursively<DenyReserveTransferToRelayChain>,
169 (
170 TakeWeightCredit,
172 AllowKnownQueryResponses<PolkadotXcm>,
174 WithComputedOrigin<
175 (
176 AllowTopLevelPaidExecutionFrom<Everything>,
179 AllowExplicitUnpaidExecutionFrom<(
182 ParentOrParentsPlurality,
183 FellowsPlurality,
184 Equals<GovernanceLocation>,
185 )>,
186 AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
188 AllowHrmpNotificationsFromRelayChain,
190 ),
191 UniversalLocation,
192 ConstU32<8>,
193 >,
194 ),
195 >,
196>;
197
198parameter_types! {
199 pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
200 pub RelayTreasuryLocation: Location = (Parent, PalletInstance(westend_runtime_constants::TREASURY_PALLET_ID)).into();
201}
202
203pub type WaivedLocations = (
206 Equals<RootLocation>,
207 RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
208 Equals<RelayTreasuryLocation>,
209);
210
211pub type TrustedTeleporters = ConcreteAssetFromSystem<TokenRelayLocation>;
214
215pub type TrustedAliasers = (
222 AliasChildLocation,
223 AliasAccountId32FromSiblingSystemChain,
224 AliasOriginRootUsingFilter<AssetHubLocation, Everything>,
225 AuthorizedAliasers<Runtime>,
226);
227
228pub struct XcmConfig;
229impl xcm_executor::Config for XcmConfig {
230 type RuntimeCall = RuntimeCall;
231 type XcmSender = XcmRouter;
232 type XcmEventEmitter = PolkadotXcm;
233 type AssetTransactor = AssetTransactors;
234 type OriginConverter = XcmOriginToTransactDispatchOrigin;
235 type IsReserve = ();
238 type IsTeleporter = TrustedTeleporters;
239 type UniversalLocation = UniversalLocation;
240 type Barrier = Barrier;
241 type Weigher = WeightInfoBounds<
242 crate::weights::xcm::CoretimeWestendXcmWeight<RuntimeCall>,
243 RuntimeCall,
244 MaxInstructions,
245 >;
246 type Trader = UsingComponents<
247 WeightToFee,
248 TokenRelayLocation,
249 AccountId,
250 Balances,
251 ResolveTo<StakingPotAccountId<Runtime>, Balances>,
252 >;
253 type ResponseHandler = PolkadotXcm;
254 type AssetTrap = PolkadotXcm;
255 type AssetClaims = PolkadotXcm;
256 type SubscriptionService = PolkadotXcm;
257 type PalletInstancesInfo = AllPalletsWithSystem;
258 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
259 type AssetLocker = ();
260 type AssetExchanger = ();
261 type FeeManager = XcmFeeManagerFromComponents<
262 WaivedLocations,
263 SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
264 >;
265 type MessageExporter = ();
266 type UniversalAliases = Nothing;
267 type CallDispatcher = RuntimeCall;
268 type SafeCallFilter = Everything;
269 type Aliasers = TrustedAliasers;
270 type TransactionalProcessor = FrameTransactionalProcessor;
271 type HrmpNewChannelOpenRequestHandler = ();
272 type HrmpChannelAcceptedHandler = ();
273 type HrmpChannelClosingHandler = ();
274 type XcmRecorder = PolkadotXcm;
275}
276
277pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
280
281pub type PriceForParentDelivery =
282 ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, ParachainSystem>;
283
284pub type XcmRouter = WithUniqueTopic<(
287 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
289 XcmpQueue,
291)>;
292
293parameter_types! {
294 pub const DepositPerItem: Balance = crate::deposit(1, 0);
295 pub const DepositPerByte: Balance = crate::deposit(0, 1);
296 pub const AuthorizeAliasHoldReason: RuntimeHoldReason = RuntimeHoldReason::PolkadotXcm(pallet_xcm::HoldReason::AuthorizeAlias);
297}
298
299impl pallet_xcm::Config for Runtime {
300 type RuntimeEvent = RuntimeEvent;
301 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
303 type XcmRouter = XcmRouter;
304 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
306 type XcmExecuteFilter = Everything;
307 type XcmExecutor = XcmExecutor<XcmConfig>;
308 type XcmTeleportFilter = Everything;
309 type XcmReserveTransferFilter = Everything;
310 type Weigher = WeightInfoBounds<
311 crate::weights::xcm::CoretimeWestendXcmWeight<RuntimeCall>,
312 RuntimeCall,
313 MaxInstructions,
314 >;
315 type UniversalLocation = UniversalLocation;
316 type RuntimeOrigin = RuntimeOrigin;
317 type RuntimeCall = RuntimeCall;
318 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
319 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
320 type Currency = Balances;
321 type CurrencyMatcher = ();
322 type TrustedLockers = ();
323 type SovereignAccountOf = LocationToAccountId;
324 type MaxLockers = ConstU32<8>;
325 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
326 type AdminOrigin = EnsureRoot<AccountId>;
327 type MaxRemoteLockConsumers = ConstU32<0>;
328 type RemoteLockConsumerIdentifier = ();
329 type AuthorizedAliasConsideration = HoldConsideration<
331 AccountId,
332 Balances,
333 AuthorizeAliasHoldReason,
334 LinearStoragePrice<DepositPerItem, DepositPerByte, Balance>,
335 >;
336}
337
338impl cumulus_pallet_xcm::Config for Runtime {
339 type RuntimeEvent = RuntimeEvent;
340 type XcmExecutor = XcmExecutor<XcmConfig>;
341}