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, Disabled, 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::*, WESTEND_GENESIS_HASH};
40use xcm_builder::{
41 AccountId32Aliases, AliasChildLocation, AllowExplicitUnpaidExecutionFrom,
42 AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
43 ChildParachainAsNative, ChildParachainConvertsVia, DescribeAllTerminal, DescribeFamily,
44 FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsChildSystemParachain,
45 IsConcrete, MintLocation, OriginToPluralityVoice, SendXcmFeeToAccount,
46 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
47 TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
48 XcmFeeManagerFromComponents,
49};
50use xcm_executor::XcmExecutor;
51
52parameter_types! {
53 pub const TokenLocation: Location = Here.into_location();
54 pub const RootLocation: Location = Location::here();
55 pub const ThisNetwork: NetworkId = ByGenesis(WESTEND_GENESIS_HASH);
56 pub UniversalLocation: InteriorLocation = [GlobalConsensus(ThisNetwork::get())].into();
57 pub CheckAccount: AccountId = XcmPallet::check_account();
58 pub LocalCheckAccount: (AccountId, MintLocation) = (CheckAccount::get(), MintLocation::Local);
59 pub TreasuryAccount: AccountId = Treasury::account_id();
60 pub FeeAssetId: AssetId = AssetId(TokenLocation::get());
62 pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
64}
65
66pub type LocationConverter = (
67 ChildParachainConvertsVia<ParaId, AccountId>,
69 AccountId32Aliases<ThisNetwork, AccountId>,
71 HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
73);
74
75pub type LocalAssetTransactor = FungibleAdapter<
76 Balances,
78 IsConcrete<TokenLocation>,
80 LocationConverter,
82 AccountId,
84 LocalCheckAccount,
86>;
87
88type LocalOriginConverter = (
89 SovereignSignedViaLocation<LocationConverter, RuntimeOrigin>,
92 ChildParachainAsNative<parachains_origin::Origin, RuntimeOrigin>,
95 SignedAccountId32AsNative<ThisNetwork, RuntimeOrigin>,
98 XcmPassthrough<RuntimeOrigin>,
100);
101
102pub type PriceForChildParachainDelivery =
103 ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, Dmp>;
104
105pub type XcmRouter = WithUniqueTopic<
108 ChildParachainRouter<Runtime, XcmPallet, PriceForChildParachainDelivery>,
110>;
111
112parameter_types! {
113 pub AssetHub: Location = Parachain(ASSET_HUB_ID).into_location();
114 pub AssetHubNext: Location = Parachain(ASSET_HUB_NEXT_ID).into_location();
115 pub Collectives: Location = Parachain(COLLECTIVES_ID).into_location();
116 pub BridgeHub: Location = Parachain(BRIDGE_HUB_ID).into_location();
117 pub Encointer: Location = Parachain(ENCOINTER_ID).into_location();
118 pub People: Location = Parachain(PEOPLE_ID).into_location();
119 pub Broker: Location = Parachain(BROKER_ID).into_location();
120 pub Wnd: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(TokenLocation::get()) });
121 pub WndForAssetHub: (AssetFilter, Location) = (Wnd::get(), AssetHub::get());
122 pub WndForAssetHubNext: (AssetFilter, Location) = (Wnd::get(), AssetHubNext::get());
123 pub WndForCollectives: (AssetFilter, Location) = (Wnd::get(), Collectives::get());
124 pub WndForBridgeHub: (AssetFilter, Location) = (Wnd::get(), BridgeHub::get());
125 pub WndForEncointer: (AssetFilter, Location) = (Wnd::get(), Encointer::get());
126 pub WndForPeople: (AssetFilter, Location) = (Wnd::get(), People::get());
127 pub WndForBroker: (AssetFilter, Location) = (Wnd::get(), Broker::get());
128 pub MaxInstructions: u32 = 100;
129 pub MaxAssetsIntoHolding: u32 = 64;
130}
131
132pub type TrustedTeleporters = (
133 xcm_builder::Case<WndForAssetHub>,
134 xcm_builder::Case<WndForAssetHubNext>,
135 xcm_builder::Case<WndForCollectives>,
136 xcm_builder::Case<WndForBridgeHub>,
137 xcm_builder::Case<WndForEncointer>,
138 xcm_builder::Case<WndForPeople>,
139 xcm_builder::Case<WndForBroker>,
140);
141
142pub struct OnlyParachains;
143impl Contains<Location> for OnlyParachains {
144 fn contains(location: &Location) -> bool {
145 matches!(location.unpack(), (0, [Parachain(_)]))
146 }
147}
148
149pub struct Fellows;
150impl Contains<Location> for Fellows {
151 fn contains(location: &Location) -> bool {
152 matches!(
153 location.unpack(),
154 (0, [Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }])
155 )
156 }
157}
158
159pub struct LocalPlurality;
160impl Contains<Location> for LocalPlurality {
161 fn contains(loc: &Location) -> bool {
162 matches!(loc.unpack(), (0, [Plurality { .. }]))
163 }
164}
165
166pub type Barrier = TrailingSetTopicAsId<(
168 TakeWeightCredit,
170 AllowKnownQueryResponses<XcmPallet>,
172 WithComputedOrigin<
173 (
174 AllowTopLevelPaidExecutionFrom<Everything>,
176 AllowSubscriptionsFrom<OnlyParachains>,
178 AllowExplicitUnpaidExecutionFrom<(IsChildSystemParachain<ParaId>, Fellows)>,
180 ),
181 UniversalLocation,
182 ConstU32<8>,
183 >,
184)>;
185
186pub type WaivedLocations = (SystemParachains, Equals<RootLocation>, LocalPlurality);
189
190pub type Aliasers = AliasChildLocation;
194
195pub struct XcmConfig;
196impl xcm_executor::Config for XcmConfig {
197 type RuntimeCall = RuntimeCall;
198 type XcmSender = XcmRouter;
199 type XcmEventEmitter = XcmPallet;
200 type AssetTransactor = LocalAssetTransactor;
201 type OriginConverter = LocalOriginConverter;
202 type IsReserve = ();
203 type IsTeleporter = TrustedTeleporters;
204 type UniversalLocation = UniversalLocation;
205 type Barrier = Barrier;
206 type Weigher = WeightInfoBounds<
207 crate::weights::xcm::WestendXcmWeight<RuntimeCall>,
208 RuntimeCall,
209 MaxInstructions,
210 >;
211 type Trader =
212 UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToAuthor<Runtime>>;
213 type ResponseHandler = XcmPallet;
214 type AssetTrap = XcmPallet;
215 type AssetLocker = ();
216 type AssetExchanger = ();
217 type AssetClaims = XcmPallet;
218 type SubscriptionService = XcmPallet;
219 type PalletInstancesInfo = AllPalletsWithSystem;
220 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
221 type FeeManager = XcmFeeManagerFromComponents<
222 WaivedLocations,
223 SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
224 >;
225 type MessageExporter = ();
226 type UniversalAliases = Nothing;
227 type CallDispatcher = RuntimeCall;
228 type SafeCallFilter = Everything;
229 type Aliasers = Aliasers;
230 type TransactionalProcessor = FrameTransactionalProcessor;
231 type HrmpNewChannelOpenRequestHandler = ();
232 type HrmpChannelAcceptedHandler = ();
233 type HrmpChannelClosingHandler = ();
234 type XcmRecorder = XcmPallet;
235}
236
237parameter_types! {
238 pub const GeneralAdminBodyId: BodyId = BodyId::Administration;
240 pub const StakingAdminBodyId: BodyId = BodyId::Defense;
242 pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX);
244 pub const TreasurerBodyId: BodyId = BodyId::Treasury;
246}
247
248pub type GeneralAdminToPlurality =
250 OriginToPluralityVoice<RuntimeOrigin, GeneralAdmin, GeneralAdminBodyId>;
251
252pub type LocalOriginToLocation = (
255 GeneralAdminToPlurality,
256 SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>,
258);
259
260pub type StakingAdminToPlurality =
262 OriginToPluralityVoice<RuntimeOrigin, StakingAdmin, StakingAdminBodyId>;
263
264pub type FellowshipAdminToPlurality =
266 OriginToPluralityVoice<RuntimeOrigin, FellowshipAdmin, FellowshipAdminBodyId>;
267
268pub type TreasurerToPlurality = OriginToPluralityVoice<RuntimeOrigin, Treasurer, TreasurerBodyId>;
270
271pub type LocalPalletOriginToLocation = (
274 GeneralAdminToPlurality,
276 StakingAdminToPlurality,
278 FellowshipAdminToPlurality,
280 TreasurerToPlurality,
282);
283
284impl pallet_xcm::Config for Runtime {
285 type RuntimeEvent = RuntimeEvent;
286 type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<
289 RuntimeOrigin,
290 (LocalPalletOriginToLocation, LocalOriginToLocation),
291 >;
292 type XcmRouter = XcmRouter;
293 type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
295 type XcmExecuteFilter = Everything;
296 type XcmExecutor = XcmExecutor<XcmConfig>;
297 type XcmTeleportFilter = Everything;
298 type XcmReserveTransferFilter = Everything;
299 type Weigher = WeightInfoBounds<
300 crate::weights::xcm::WestendXcmWeight<RuntimeCall>,
301 RuntimeCall,
302 MaxInstructions,
303 >;
304 type UniversalLocation = UniversalLocation;
305 type RuntimeOrigin = RuntimeOrigin;
306 type RuntimeCall = RuntimeCall;
307 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
308 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
309 type Currency = Balances;
310 type CurrencyMatcher = IsConcrete<TokenLocation>;
311 type TrustedLockers = ();
312 type SovereignAccountOf = LocationConverter;
313 type MaxLockers = ConstU32<8>;
314 type MaxRemoteLockConsumers = ConstU32<0>;
315 type RemoteLockConsumerIdentifier = ();
316 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
317 type AdminOrigin = EnsureRoot<AccountId>;
318 type AuthorizedAliasConsideration = Disabled;
320}