1use super::{
20 parachains_origin, AccountId, AllPalletsWithSystem, Balances, Dmp, FellowshipAdmin,
21 GeneralAdmin, ParaId, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, StakingAdmin,
22 TransactionByteFee, Treasury, WeightToFee, XcmPallet,
23};
24use crate::governance::pallet_custom_origins::Treasurer;
25use frame_support::{
26 parameter_types,
27 traits::{Contains, Equals, Everything, Nothing},
28};
29use frame_system::EnsureRoot;
30use pallet_xcm::XcmPassthrough;
31use polkadot_runtime_common::{
32 xcm_sender::{ChildParachainRouter, ExponentialPrice},
33 ToAuthor,
34};
35use sp_core::ConstU32;
36use westend_runtime_constants::{
37 currency::CENTS, system_parachain::*, xcm::body::FELLOWSHIP_ADMIN_INDEX,
38};
39use xcm::latest::prelude::*;
40use xcm_builder::{
41 AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
42 AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative,
43 ChildParachainConvertsVia, DescribeAllTerminal, DescribeFamily, FrameTransactionalProcessor,
44 FungibleAdapter, HashedDescription, IsChildSystemParachain, IsConcrete, MintLocation,
45 OriginToPluralityVoice, SendXcmFeeToAccount, SignedAccountId32AsNative, SignedToAccountId32,
46 SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
47 WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents,
48};
49use xcm_executor::XcmExecutor;
50
51parameter_types! {
52 pub const TokenLocation: Location = Here.into_location();
53 pub const RootLocation: Location = Location::here();
54 pub const ThisNetwork: NetworkId = Westend;
55 pub UniversalLocation: InteriorLocation = [GlobalConsensus(ThisNetwork::get())].into();
56 pub CheckAccount: AccountId = XcmPallet::check_account();
57 pub LocalCheckAccount: (AccountId, MintLocation) = (CheckAccount::get(), MintLocation::Local);
58 pub TreasuryAccount: AccountId = Treasury::account_id();
59 pub FeeAssetId: AssetId = AssetId(TokenLocation::get());
61 pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
63}
64
65pub type LocationConverter = (
66 ChildParachainConvertsVia<ParaId, AccountId>,
68 AccountId32Aliases<ThisNetwork, AccountId>,
70 HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
72);
73
74pub type LocalAssetTransactor = FungibleAdapter<
75 Balances,
77 IsConcrete<TokenLocation>,
79 LocationConverter,
81 AccountId,
83 LocalCheckAccount,
85>;
86
87type LocalOriginConverter = (
88 SovereignSignedViaLocation<LocationConverter, RuntimeOrigin>,
91 ChildParachainAsNative<parachains_origin::Origin, RuntimeOrigin>,
94 SignedAccountId32AsNative<ThisNetwork, RuntimeOrigin>,
97 XcmPassthrough<RuntimeOrigin>,
99);
100
101pub type PriceForChildParachainDelivery =
102 ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, Dmp>;
103
104pub type XcmRouter = WithUniqueTopic<
107 ChildParachainRouter<Runtime, XcmPallet, PriceForChildParachainDelivery>,
109>;
110
111parameter_types! {
112 pub AssetHub: Location = Parachain(ASSET_HUB_ID).into_location();
113 pub Collectives: Location = Parachain(COLLECTIVES_ID).into_location();
114 pub BridgeHub: Location = Parachain(BRIDGE_HUB_ID).into_location();
115 pub Encointer: Location = Parachain(ENCOINTER_ID).into_location();
116 pub People: Location = Parachain(PEOPLE_ID).into_location();
117 pub Broker: Location = Parachain(BROKER_ID).into_location();
118 pub Wnd: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(TokenLocation::get()) });
119 pub WndForAssetHub: (AssetFilter, Location) = (Wnd::get(), AssetHub::get());
120 pub WndForCollectives: (AssetFilter, Location) = (Wnd::get(), Collectives::get());
121 pub WndForBridgeHub: (AssetFilter, Location) = (Wnd::get(), BridgeHub::get());
122 pub WndForEncointer: (AssetFilter, Location) = (Wnd::get(), Encointer::get());
123 pub WndForPeople: (AssetFilter, Location) = (Wnd::get(), People::get());
124 pub WndForBroker: (AssetFilter, Location) = (Wnd::get(), Broker::get());
125 pub MaxInstructions: u32 = 100;
126 pub MaxAssetsIntoHolding: u32 = 64;
127}
128
129pub type TrustedTeleporters = (
130 xcm_builder::Case<WndForAssetHub>,
131 xcm_builder::Case<WndForCollectives>,
132 xcm_builder::Case<WndForBridgeHub>,
133 xcm_builder::Case<WndForEncointer>,
134 xcm_builder::Case<WndForPeople>,
135 xcm_builder::Case<WndForBroker>,
136);
137
138pub struct OnlyParachains;
139impl Contains<Location> for OnlyParachains {
140 fn contains(location: &Location) -> bool {
141 matches!(location.unpack(), (0, [Parachain(_)]))
142 }
143}
144
145pub struct Fellows;
146impl Contains<Location> for Fellows {
147 fn contains(location: &Location) -> bool {
148 matches!(
149 location.unpack(),
150 (0, [Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }])
151 )
152 }
153}
154
155pub struct LocalPlurality;
156impl Contains<Location> for LocalPlurality {
157 fn contains(loc: &Location) -> bool {
158 matches!(loc.unpack(), (0, [Plurality { .. }]))
159 }
160}
161
162pub type Barrier = TrailingSetTopicAsId<(
164 TakeWeightCredit,
166 AllowKnownQueryResponses<XcmPallet>,
168 WithComputedOrigin<
169 (
170 AllowTopLevelPaidExecutionFrom<Everything>,
172 AllowSubscriptionsFrom<OnlyParachains>,
174 AllowExplicitUnpaidExecutionFrom<(IsChildSystemParachain<ParaId>, Fellows)>,
176 ),
177 UniversalLocation,
178 ConstU32<8>,
179 >,
180)>;
181
182pub type WaivedLocations = (SystemParachains, Equals<RootLocation>, LocalPlurality);
185
186pub struct XcmConfig;
187impl xcm_executor::Config for XcmConfig {
188 type RuntimeCall = RuntimeCall;
189 type XcmSender = XcmRouter;
190 type AssetTransactor = LocalAssetTransactor;
191 type OriginConverter = LocalOriginConverter;
192 type IsReserve = ();
193 type IsTeleporter = TrustedTeleporters;
194 type UniversalLocation = UniversalLocation;
195 type Barrier = Barrier;
196 type Weigher = WeightInfoBounds<
197 crate::weights::xcm::WestendXcmWeight<RuntimeCall>,
198 RuntimeCall,
199 MaxInstructions,
200 >;
201 type Trader =
202 UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToAuthor<Runtime>>;
203 type ResponseHandler = XcmPallet;
204 type AssetTrap = XcmPallet;
205 type AssetLocker = ();
206 type AssetExchanger = ();
207 type AssetClaims = XcmPallet;
208 type SubscriptionService = XcmPallet;
209 type PalletInstancesInfo = AllPalletsWithSystem;
210 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
211 type FeeManager = XcmFeeManagerFromComponents<
212 WaivedLocations,
213 SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
214 >;
215 type MessageExporter = ();
216 type UniversalAliases = Nothing;
217 type CallDispatcher = RuntimeCall;
218 type SafeCallFilter = Everything;
219 type Aliasers = Nothing;
220 type TransactionalProcessor = FrameTransactionalProcessor;
221 type HrmpNewChannelOpenRequestHandler = ();
222 type HrmpChannelAcceptedHandler = ();
223 type HrmpChannelClosingHandler = ();
224 type XcmRecorder = XcmPallet;
225}
226
227parameter_types! {
228 pub const GeneralAdminBodyId: BodyId = BodyId::Administration;
230 pub const StakingAdminBodyId: BodyId = BodyId::Defense;
232 pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX);
234 pub const TreasurerBodyId: BodyId = BodyId::Treasury;
236}
237
238pub type GeneralAdminToPlurality =
240 OriginToPluralityVoice<RuntimeOrigin, GeneralAdmin, GeneralAdminBodyId>;
241
242pub type LocalOriginToLocation = (
244 GeneralAdminToPlurality,
245 SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>,
247);
248
249pub type StakingAdminToPlurality =
251 OriginToPluralityVoice<RuntimeOrigin, StakingAdmin, StakingAdminBodyId>;
252
253pub type FellowshipAdminToPlurality =
255 OriginToPluralityVoice<RuntimeOrigin, FellowshipAdmin, FellowshipAdminBodyId>;
256
257pub type TreasurerToPlurality = OriginToPluralityVoice<RuntimeOrigin, Treasurer, TreasurerBodyId>;
259
260pub type LocalPalletOriginToLocation = (
263 GeneralAdminToPlurality,
265 StakingAdminToPlurality,
267 FellowshipAdminToPlurality,
269 TreasurerToPlurality,
271);
272
273impl pallet_xcm::Config for Runtime {
274 type RuntimeEvent = RuntimeEvent;
275 type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
278 type XcmRouter = XcmRouter;
279 type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
281 type XcmExecuteFilter = Everything;
282 type XcmExecutor = XcmExecutor<XcmConfig>;
283 type XcmTeleportFilter = Everything;
284 type XcmReserveTransferFilter = Everything;
285 type Weigher = WeightInfoBounds<
286 crate::weights::xcm::WestendXcmWeight<RuntimeCall>,
287 RuntimeCall,
288 MaxInstructions,
289 >;
290 type UniversalLocation = UniversalLocation;
291 type RuntimeOrigin = RuntimeOrigin;
292 type RuntimeCall = RuntimeCall;
293 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
294 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
295 type Currency = Balances;
296 type CurrencyMatcher = IsConcrete<TokenLocation>;
297 type TrustedLockers = ();
298 type SovereignAccountOf = LocationConverter;
299 type MaxLockers = ConstU32<8>;
300 type MaxRemoteLockConsumers = ConstU32<0>;
301 type RemoteLockConsumerIdentifier = ();
302 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
303 type AdminOrigin = EnsureRoot<AccountId>;
304}