1use super::{
20 parachains_origin, AccountId, AllPalletsWithSystem, Balances, Dmp, ParaId, Runtime,
21 RuntimeCall, RuntimeEvent, RuntimeOrigin, TransactionByteFee, WeightToFee, XcmPallet,
22};
23use frame_support::{
24 parameter_types,
25 traits::{Contains, Disabled, Equals, Everything, Nothing},
26};
27use frame_system::EnsureRoot;
28use pallet_xcm::XcmPassthrough;
29use polkadot_runtime_common::{
30 xcm_sender::{ChildParachainRouter, ExponentialPrice},
31 ToAuthor,
32};
33use sp_core::ConstU32;
34use westend_runtime_constants::{currency::CENTS, system_parachain::*};
35use xcm::latest::{prelude::*, WESTEND_GENESIS_HASH};
36use xcm_builder::{
37 AccountId32Aliases, AliasChildLocation, AllowExplicitUnpaidExecutionFrom,
38 AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
39 ChildParachainAsNative, ChildParachainConvertsVia, DescribeAllTerminal, DescribeFamily,
40 FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsChildSystemParachain,
41 IsConcrete, LocationAsSuperuser, MintLocation, SendXcmFeeToAccount, SignedAccountId32AsNative,
42 SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
43 UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
44 XcmFeeManagerFromComponents,
45};
46use xcm_executor::XcmExecutor;
47
48parameter_types! {
49 pub const TokenLocation: Location = Here.into_location();
50 pub const RootLocation: Location = Location::here();
51 pub const ThisNetwork: NetworkId = ByGenesis(WESTEND_GENESIS_HASH);
52 pub UniversalLocation: InteriorLocation = [GlobalConsensus(ThisNetwork::get())].into();
53 pub CheckAccount: AccountId = XcmPallet::check_account();
54 pub TeleportTracking: Option<(AccountId, MintLocation)> = None;
56 pub AccumulateAccount: AccountId = pallet_accumulate_and_forward::Pallet::<Runtime>::accumulation_account();
57 pub FeeAssetId: AssetId = AssetId(TokenLocation::get());
59 pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
61 pub const FellowsBodyId: BodyId = BodyId::Technical;
63 pub AccumulateForwardLocation: Location = {
65 AccountId32 { network: None, id: AccumulateAccount::get().into() }.into()
66 };
67}
68
69pub type LocationConverter = (
70 ChildParachainConvertsVia<ParaId, AccountId>,
72 AccountId32Aliases<ThisNetwork, AccountId>,
74 HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
76);
77
78pub type LocalAssetTransactor = FungibleAdapter<
79 Balances,
81 IsConcrete<TokenLocation>,
83 LocationConverter,
85 AccountId,
87 TeleportTracking,
88>;
89
90type LocalOriginConverter = (
91 LocationAsSuperuser<Equals<AssetHub>, RuntimeOrigin>,
93 SovereignSignedViaLocation<LocationConverter, RuntimeOrigin>,
96 ChildParachainAsNative<parachains_origin::Origin, RuntimeOrigin>,
99 SignedAccountId32AsNative<ThisNetwork, RuntimeOrigin>,
102 XcmPassthrough<RuntimeOrigin>,
104);
105
106pub type PriceForChildParachainDelivery =
107 ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, Dmp>;
108
109pub type XcmRouter = WithUniqueTopic<
112 ChildParachainRouter<Runtime, XcmPallet, PriceForChildParachainDelivery>,
114>;
115
116parameter_types! {
117 pub AssetHub: Location = Parachain(ASSET_HUB_ID).into_location();
118 pub AssetHubNext: Location = Parachain(ASSET_HUB_NEXT_ID).into_location();
119 pub Collectives: Location = Parachain(COLLECTIVES_ID).into_location();
120 pub BridgeHub: Location = Parachain(BRIDGE_HUB_ID).into_location();
121 pub Encointer: Location = Parachain(ENCOINTER_ID).into_location();
122 pub People: Location = Parachain(PEOPLE_ID).into_location();
123 pub Broker: Location = Parachain(BROKER_ID).into_location();
124 pub Wnd: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(TokenLocation::get()) });
125 pub WndForAssetHub: (AssetFilter, Location) = (Wnd::get(), AssetHub::get());
126 pub WndForAssetHubNext: (AssetFilter, Location) = (Wnd::get(), AssetHubNext::get());
127 pub WndForCollectives: (AssetFilter, Location) = (Wnd::get(), Collectives::get());
128 pub WndForBridgeHub: (AssetFilter, Location) = (Wnd::get(), BridgeHub::get());
129 pub WndForEncointer: (AssetFilter, Location) = (Wnd::get(), Encointer::get());
130 pub WndForPeople: (AssetFilter, Location) = (Wnd::get(), People::get());
131 pub WndForBroker: (AssetFilter, Location) = (Wnd::get(), Broker::get());
132 pub MaxInstructions: u32 = 100;
133 pub MaxAssetsIntoHolding: u32 = 64;
134}
135
136pub type TrustedTeleporters = (
137 xcm_builder::Case<WndForAssetHub>,
138 xcm_builder::Case<WndForAssetHubNext>,
139 xcm_builder::Case<WndForCollectives>,
140 xcm_builder::Case<WndForBridgeHub>,
141 xcm_builder::Case<WndForEncointer>,
142 xcm_builder::Case<WndForPeople>,
143 xcm_builder::Case<WndForBroker>,
144);
145
146pub struct OnlyParachains;
147impl Contains<Location> for OnlyParachains {
148 fn contains(location: &Location) -> bool {
149 matches!(location.unpack(), (0, [Parachain(_)]))
150 }
151}
152
153pub struct Fellows;
154impl Contains<Location> for Fellows {
155 fn contains(location: &Location) -> bool {
156 matches!(
157 location.unpack(),
158 (0, [Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }])
159 )
160 }
161}
162
163pub struct LocalPlurality;
164impl Contains<Location> for LocalPlurality {
165 fn contains(loc: &Location) -> bool {
166 matches!(loc.unpack(), (0, [Plurality { .. }]))
167 }
168}
169
170pub type Barrier = TrailingSetTopicAsId<(
172 TakeWeightCredit,
174 AllowKnownQueryResponses<XcmPallet>,
176 WithComputedOrigin<
177 (
178 AllowTopLevelPaidExecutionFrom<Everything>,
180 AllowSubscriptionsFrom<OnlyParachains>,
182 AllowExplicitUnpaidExecutionFrom<(IsChildSystemParachain<ParaId>, Fellows)>,
184 ),
185 UniversalLocation,
186 ConstU32<8>,
187 >,
188)>;
189
190pub type WaivedLocations =
193 (SystemParachains, Equals<RootLocation>, LocalPlurality, Equals<AccumulateForwardLocation>);
194
195pub type Aliasers = AliasChildLocation;
199
200pub struct XcmConfig;
201impl xcm_executor::Config for XcmConfig {
202 type RuntimeCall = RuntimeCall;
203 type XcmSender = XcmRouter;
204 type XcmEventEmitter = XcmPallet;
205 type AssetTransactor = LocalAssetTransactor;
206 type OriginConverter = LocalOriginConverter;
207 type IsReserve = ();
208 type IsTeleporter = TrustedTeleporters;
209 type UniversalLocation = UniversalLocation;
210 type Barrier = Barrier;
211 type Weigher = WeightInfoBounds<
212 crate::weights::xcm::WestendXcmWeight<RuntimeCall>,
213 RuntimeCall,
214 MaxInstructions,
215 >;
216 type Trader =
220 UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToAuthor<Runtime>>;
221 type ResponseHandler = XcmPallet;
222 type AssetTrap = XcmPallet;
223 type AssetLocker = ();
224 type AssetExchanger = ();
225 type SubscriptionService = XcmPallet;
226 type PalletInstancesInfo = AllPalletsWithSystem;
227 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
228 type FeeManager = XcmFeeManagerFromComponents<
229 WaivedLocations,
230 SendXcmFeeToAccount<Self::AssetTransactor, AccumulateAccount>,
231 >;
232 type MessageExporter = ();
233 type UniversalAliases = Nothing;
234 type CallDispatcher = RuntimeCall;
235 type SafeCallFilter = Everything;
236 type Aliasers = Aliasers;
237 type TransactionalProcessor = FrameTransactionalProcessor;
238 type HrmpNewChannelOpenRequestHandler = ();
239 type HrmpChannelAcceptedHandler = ();
240 type HrmpChannelClosingHandler = ();
241 type XcmRecorder = XcmPallet;
242}
243
244pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>;
247
248impl pallet_xcm::Config for Runtime {
249 type RuntimeEvent = RuntimeEvent;
250 type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
251 type XcmRouter = XcmRouter;
252 type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
254 type XcmExecuteFilter = Everything;
255 type XcmExecutor = XcmExecutor<XcmConfig>;
256 type XcmTeleportFilter = Everything;
257 type XcmReserveTransferFilter = Everything;
258 type Weigher = WeightInfoBounds<
259 crate::weights::xcm::WestendXcmWeight<RuntimeCall>,
260 RuntimeCall,
261 MaxInstructions,
262 >;
263 type UniversalLocation = UniversalLocation;
264 type RuntimeOrigin = RuntimeOrigin;
265 type RuntimeCall = RuntimeCall;
266 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
267 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
268 type Currency = Balances;
269 type CurrencyMatcher = IsConcrete<TokenLocation>;
270 type TrustedLockers = ();
271 type SovereignAccountOf = LocationConverter;
272 type MaxLockers = ConstU32<8>;
273 type MaxRemoteLockConsumers = ConstU32<0>;
274 type RemoteLockConsumerIdentifier = ();
275 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
276 type AdminOrigin = EnsureRoot<AccountId>;
277 type AuthorizedAliasConsideration = Disabled;
279}