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 IsParentsOnly<ConstU8<1>>,
173 RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
174 FellowsPlurality,
175 Equals<GovernanceLocation>,
176 )>,
177 AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
179 AllowHrmpNotificationsFromRelayChain,
181 ),
182 UniversalLocation,
183 ConstU32<8>,
184 >,
185 ),
186 >,
187>;
188
189parameter_types! {
190 pub AccumulateAccount: AccountId = pallet_accumulate_and_forward::Pallet::<Runtime>::accumulation_account();
192 pub AccumulateForwardLocation: Location = {
193 AccountId32 { network: None, id: AccumulateAccount::get().into() }.into()
194 };
195}
196
197pub type WaivedLocations = (
200 Equals<RootLocation>,
201 RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
202 Equals<AccumulateForwardLocation>,
203);
204
205pub type TrustedTeleporters = ConcreteAssetFromSystem<TokenRelayLocation>;
208
209pub type TrustedAliasers = (
216 AliasChildLocation,
217 AliasAccountId32FromSiblingSystemChain,
218 AliasOriginRootUsingFilter<AssetHubLocation, Everything>,
219 AuthorizedAliasers<Runtime>,
220);
221
222pub struct XcmConfig;
223impl xcm_executor::Config for XcmConfig {
224 type RuntimeCall = RuntimeCall;
225 type XcmSender = XcmRouter;
226 type XcmEventEmitter = PolkadotXcm;
227 type AssetTransactor = AssetTransactors;
228 type OriginConverter = XcmOriginToTransactDispatchOrigin;
229 type IsReserve = ();
232 type IsTeleporter = TrustedTeleporters;
233 type UniversalLocation = UniversalLocation;
234 type Barrier = Barrier;
235 type Weigher = WeightInfoBounds<
236 crate::weights::xcm::CoretimeWestendXcmWeight<RuntimeCall>,
237 RuntimeCall,
238 MaxInstructions,
239 >;
240 type Trader = UsingComponents<
244 WeightToFee,
245 TokenRelayLocation,
246 AccountId,
247 Balances,
248 ResolveTo<StakingPotAccountId<Runtime>, Balances>,
249 >;
250 type ResponseHandler = PolkadotXcm;
251 type AssetTrap = PolkadotXcm;
252 type SubscriptionService = PolkadotXcm;
253 type PalletInstancesInfo = AllPalletsWithSystem;
254 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
255 type AssetLocker = ();
256 type AssetExchanger = ();
257 type FeeManager = XcmFeeManagerFromComponents<
258 WaivedLocations,
259 SendXcmFeeToAccount<Self::AssetTransactor, AccumulateAccount>,
260 >;
261 type MessageExporter = ();
262 type UniversalAliases = Nothing;
263 type CallDispatcher = RuntimeCall;
264 type SafeCallFilter = Everything;
265 type Aliasers = TrustedAliasers;
266 type TransactionalProcessor = FrameTransactionalProcessor;
267 type HrmpNewChannelOpenRequestHandler = ();
268 type HrmpChannelAcceptedHandler = ();
269 type HrmpChannelClosingHandler = ();
270 type XcmRecorder = PolkadotXcm;
271}
272
273pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
276
277pub type PriceForParentDelivery =
278 ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, ParachainSystem>;
279
280pub type XcmRouter = WithUniqueTopic<(
283 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, PriceForParentDelivery>,
285 XcmpQueue,
287)>;
288
289parameter_types! {
290 pub const DepositPerItem: Balance = crate::deposit(1, 0);
291 pub const DepositPerByte: Balance = crate::deposit(0, 1);
292 pub const AuthorizeAliasHoldReason: RuntimeHoldReason = RuntimeHoldReason::PolkadotXcm(pallet_xcm::HoldReason::AuthorizeAlias);
293}
294
295impl pallet_xcm::Config for Runtime {
296 type RuntimeEvent = RuntimeEvent;
297 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
299 type XcmRouter = XcmRouter;
300 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
302 type XcmExecuteFilter = Everything;
303 type XcmExecutor = XcmExecutor<XcmConfig>;
304 type XcmTeleportFilter = Everything;
305 type XcmReserveTransferFilter = Everything;
306 type Weigher = WeightInfoBounds<
307 crate::weights::xcm::CoretimeWestendXcmWeight<RuntimeCall>,
308 RuntimeCall,
309 MaxInstructions,
310 >;
311 type UniversalLocation = UniversalLocation;
312 type RuntimeOrigin = RuntimeOrigin;
313 type RuntimeCall = RuntimeCall;
314 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
315 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
316 type Currency = Balances;
317 type CurrencyMatcher = ();
318 type TrustedLockers = ();
319 type SovereignAccountOf = LocationToAccountId;
320 type MaxLockers = ConstU32<8>;
321 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
322 type AdminOrigin = EnsureRoot<AccountId>;
323 type MaxRemoteLockConsumers = ConstU32<0>;
324 type RemoteLockConsumerIdentifier = ();
325 type AuthorizedAliasConsideration = HoldConsideration<
327 AccountId,
328 Balances,
329 AuthorizeAliasHoldReason,
330 LinearStoragePrice<DepositPerItem, DepositPerByte, Balance>,
331 >;
332}
333
334impl cumulus_pallet_xcm::Config for Runtime {
335 type RuntimeEvent = RuntimeEvent;
336 type XcmExecutor = XcmExecutor<XcmConfig>;
337}