1use super::{
17 AccountId, AllPalletsWithSystem, Balance, Balances, ParachainInfo, ParachainSystem,
18 PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeHoldReason, RuntimeOrigin, WeightToFee,
19 XcmpQueue,
20};
21use crate::{TransactionByteFee, CENTS};
22use frame_support::{
23 parameter_types,
24 traits::{
25 fungible::HoldConsideration, tokens::imbalance::ResolveTo, ConstU32, Contains, Equals,
26 Everything, LinearStoragePrice, Nothing,
27 },
28};
29use frame_system::EnsureRoot;
30use pallet_collator_selection::StakingPotAccountId;
31use pallet_xcm::{AuthorizedAliasers, XcmPassthrough};
32use parachains_common::{
33 xcm_config::{
34 AliasAccountId32FromSiblingSystemChain, AllSiblingSystemParachains,
35 ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains,
36 },
37 TREASURY_PALLET_ID,
38};
39use polkadot_parachain_primitives::primitives::Sibling;
40use sp_runtime::traits::AccountIdConversion;
41use testnet_parachains_constants::westend::locations::AssetHubLocation;
42use westend_runtime_constants::system_parachain::COLLECTIVES_ID;
43use xcm::latest::{prelude::*, WESTEND_GENESIS_HASH};
44use xcm_builder::{
45 AccountId32Aliases, AliasChildLocation, AliasOriginRootUsingFilter,
46 AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain,
47 AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
48 DenyRecursively, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal,
49 DescribeFamily, DescribeTerminus, EnsureXcmOrigin, FrameTransactionalProcessor,
50 FungibleAdapter, HashedDescription, IsConcrete, LocationAsSuperuser, ParentAsSuperuser,
51 ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative,
52 SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
53 SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
54 WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents,
55};
56use xcm_executor::XcmExecutor;
57
58pub use testnet_parachains_constants::westend::locations::GovernanceLocation;
60
61parameter_types! {
62 pub const RootLocation: Location = Location::here();
63 pub const RelayLocation: Location = Location::parent();
64 pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::ByGenesis(WESTEND_GENESIS_HASH));
65 pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
66 pub UniversalLocation: InteriorLocation =
67 [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into();
68 pub const MaxInstructions: u32 = 100;
69 pub const MaxAssetsIntoHolding: u32 = 64;
70 pub FellowshipLocation: Location = Location::new(1, Parachain(COLLECTIVES_ID));
71 pub FeeAssetId: AssetId = AssetId(RelayLocation::get());
73 pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
75 pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
76 pub RelayTreasuryLocation: Location =
77 (Parent, PalletInstance(westend_runtime_constants::TREASURY_PALLET_ID)).into();
78}
79
80pub type PriceForParentDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice<
81 FeeAssetId,
82 BaseDeliveryFee,
83 TransactionByteFee,
84 ParachainSystem,
85>;
86
87pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice<
88 FeeAssetId,
89 BaseDeliveryFee,
90 TransactionByteFee,
91 XcmpQueue,
92>;
93
94pub type LocationToAccountId = (
98 ParentIsPreset<AccountId>,
100 SiblingParachainConvertsVia<Sibling, AccountId>,
102 AccountId32Aliases<RelayNetwork, AccountId>,
104 HashedDescription<AccountId, DescribeTerminus>,
106 HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
108);
109
110pub type FungibleTransactor = FungibleAdapter<
112 Balances,
114 IsConcrete<RelayLocation>,
116 LocationToAccountId,
119 AccountId,
121 (),
123>;
124
125pub type XcmOriginToTransactDispatchOrigin = (
129 LocationAsSuperuser<Equals<GovernanceLocation>, RuntimeOrigin>,
131 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
135 RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
138 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
141 ParentAsSuperuser<RuntimeOrigin>,
144 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
147 XcmPassthrough<RuntimeOrigin>,
149);
150
151pub struct LocalPlurality;
152impl Contains<Location> for LocalPlurality {
153 fn contains(location: &Location) -> bool {
154 matches!(location.unpack(), (0, [Plurality { .. }]))
155 }
156}
157
158pub struct ParentOrParentsPlurality;
159impl Contains<Location> for ParentOrParentsPlurality {
160 fn contains(location: &Location) -> bool {
161 matches!(location.unpack(), (1, []) | (1, [Plurality { .. }]))
162 }
163}
164
165pub struct FellowsPlurality;
166impl Contains<Location> for FellowsPlurality {
167 fn contains(location: &Location) -> bool {
168 matches!(
169 location.unpack(),
170 (1, [Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }])
171 )
172 }
173}
174
175pub type Barrier = TrailingSetTopicAsId<
176 DenyThenTry<
177 DenyRecursively<DenyReserveTransferToRelayChain>,
178 (
179 TakeWeightCredit,
181 AllowKnownQueryResponses<PolkadotXcm>,
183 WithComputedOrigin<
184 (
185 AllowTopLevelPaidExecutionFrom<Everything>,
188 AllowExplicitUnpaidExecutionFrom<(
191 ParentOrParentsPlurality,
192 FellowsPlurality,
193 Equals<GovernanceLocation>,
194 )>,
195 AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
197 AllowHrmpNotificationsFromRelayChain,
199 ),
200 UniversalLocation,
201 ConstU32<8>,
202 >,
203 ),
204 >,
205>;
206
207pub type WaivedLocations = (
210 RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
211 Equals<RelayTreasuryLocation>,
212 Equals<RootLocation>,
213 LocalPlurality,
214);
215
216pub type TrustedTeleporters = ConcreteAssetFromSystem<RelayLocation>;
219
220pub type TrustedAliasers = (
227 AliasChildLocation,
228 AliasAccountId32FromSiblingSystemChain,
229 AliasOriginRootUsingFilter<AssetHubLocation, Everything>,
230 AuthorizedAliasers<Runtime>,
231);
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 = FungibleTransactor;
239 type OriginConverter = XcmOriginToTransactDispatchOrigin;
240 type IsReserve = ();
243
244 type IsTeleporter = TrustedTeleporters;
245 type UniversalLocation = UniversalLocation;
246 type Barrier = Barrier;
247 type Weigher = WeightInfoBounds<
248 crate::weights::xcm::PeopleWestendXcmWeight<RuntimeCall>,
249 RuntimeCall,
250 MaxInstructions,
251 >;
252 type Trader = UsingComponents<
253 WeightToFee,
254 RelayLocation,
255 AccountId,
256 Balances,
257 ResolveTo<StakingPotAccountId<Runtime>, Balances>,
258 >;
259 type ResponseHandler = PolkadotXcm;
260 type AssetTrap = PolkadotXcm;
261 type AssetClaims = PolkadotXcm;
262 type SubscriptionService = PolkadotXcm;
263 type PalletInstancesInfo = AllPalletsWithSystem;
264 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
265 type AssetLocker = ();
266 type AssetExchanger = ();
267 type FeeManager = XcmFeeManagerFromComponents<
268 WaivedLocations,
269 SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
270 >;
271 type MessageExporter = ();
272 type UniversalAliases = Nothing;
273 type CallDispatcher = RuntimeCall;
274 type SafeCallFilter = Everything;
275 type Aliasers = TrustedAliasers;
276 type TransactionalProcessor = FrameTransactionalProcessor;
277 type HrmpNewChannelOpenRequestHandler = ();
278 type HrmpChannelAcceptedHandler = ();
279 type HrmpChannelClosingHandler = ();
280 type XcmRecorder = PolkadotXcm;
281}
282
283pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
286
287pub type XcmRouter = WithUniqueTopic<(
290 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
292 XcmpQueue,
294)>;
295
296parameter_types! {
297 pub const DepositPerItem: Balance = crate::deposit(1, 0);
298 pub const DepositPerByte: Balance = crate::deposit(0, 1);
299 pub const AuthorizeAliasHoldReason: RuntimeHoldReason = RuntimeHoldReason::PolkadotXcm(pallet_xcm::HoldReason::AuthorizeAlias);
300}
301
302impl pallet_xcm::Config for Runtime {
303 type RuntimeEvent = RuntimeEvent;
304 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
306 type XcmRouter = XcmRouter;
307 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
309 type XcmExecuteFilter = Everything;
310 type XcmExecutor = XcmExecutor<XcmConfig>;
311 type XcmTeleportFilter = Everything;
312 type XcmReserveTransferFilter = Nothing; type Weigher = WeightInfoBounds<
314 crate::weights::xcm::PeopleWestendXcmWeight<RuntimeCall>,
315 RuntimeCall,
316 MaxInstructions,
317 >;
318 type UniversalLocation = UniversalLocation;
319 type RuntimeOrigin = RuntimeOrigin;
320 type RuntimeCall = RuntimeCall;
321 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
322 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
323 type Currency = Balances;
324 type CurrencyMatcher = ();
325 type TrustedLockers = ();
326 type SovereignAccountOf = LocationToAccountId;
327 type MaxLockers = ConstU32<8>;
328 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
329 type AdminOrigin = EnsureRoot<AccountId>;
330 type MaxRemoteLockConsumers = ConstU32<0>;
331 type RemoteLockConsumerIdentifier = ();
332 type AuthorizedAliasConsideration = HoldConsideration<
334 AccountId,
335 Balances,
336 AuthorizeAliasHoldReason,
337 LinearStoragePrice<DepositPerItem, DepositPerByte, Balance>,
338 >;
339}
340
341impl cumulus_pallet_xcm::Config for Runtime {
342 type RuntimeEvent = RuntimeEvent;
343 type XcmExecutor = XcmExecutor<XcmConfig>;
344}