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, LocationAsSuperuser, 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 TeleportTracking: Option<(AccountId, MintLocation)> = None;
60 pub TreasuryAccount: AccountId = Treasury::account_id();
61 pub FeeAssetId: AssetId = AssetId(TokenLocation::get());
63 pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
65 pub const FellowsBodyId: BodyId = BodyId::Technical;
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 = (SystemParachains, Equals<RootLocation>, LocalPlurality);
193
194pub type Aliasers = AliasChildLocation;
198
199pub struct XcmConfig;
200impl xcm_executor::Config for XcmConfig {
201 type RuntimeCall = RuntimeCall;
202 type XcmSender = XcmRouter;
203 type XcmEventEmitter = XcmPallet;
204 type AssetTransactor = LocalAssetTransactor;
205 type OriginConverter = LocalOriginConverter;
206 type IsReserve = ();
207 type IsTeleporter = TrustedTeleporters;
208 type UniversalLocation = UniversalLocation;
209 type Barrier = Barrier;
210 type Weigher = WeightInfoBounds<
211 crate::weights::xcm::WestendXcmWeight<RuntimeCall>,
212 RuntimeCall,
213 MaxInstructions,
214 >;
215 type Trader =
216 UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToAuthor<Runtime>>;
217 type ResponseHandler = XcmPallet;
218 type AssetTrap = XcmPallet;
219 type AssetLocker = ();
220 type AssetExchanger = ();
221 type AssetClaims = XcmPallet;
222 type SubscriptionService = XcmPallet;
223 type PalletInstancesInfo = AllPalletsWithSystem;
224 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
225 type FeeManager = XcmFeeManagerFromComponents<
226 WaivedLocations,
227 SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
228 >;
229 type MessageExporter = ();
230 type UniversalAliases = Nothing;
231 type CallDispatcher = RuntimeCall;
232 type SafeCallFilter = Everything;
233 type Aliasers = Aliasers;
234 type TransactionalProcessor = FrameTransactionalProcessor;
235 type HrmpNewChannelOpenRequestHandler = ();
236 type HrmpChannelAcceptedHandler = ();
237 type HrmpChannelClosingHandler = ();
238 type XcmRecorder = XcmPallet;
239}
240
241parameter_types! {
242 pub const GeneralAdminBodyId: BodyId = BodyId::Administration;
244 pub const StakingAdminBodyId: BodyId = BodyId::Defense;
246 pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX);
248 pub const TreasurerBodyId: BodyId = BodyId::Treasury;
250 pub const DDayBodyId: BodyId = BodyId::Moniker([b'd', b'd', b'a', b'y']);
252}
253
254pub type GeneralAdminToPlurality =
256 OriginToPluralityVoice<RuntimeOrigin, GeneralAdmin, GeneralAdminBodyId>;
257
258pub type LocalOriginToLocation = (
261 GeneralAdminToPlurality,
262 SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>,
264);
265
266pub type StakingAdminToPlurality =
268 OriginToPluralityVoice<RuntimeOrigin, StakingAdmin, StakingAdminBodyId>;
269
270pub type FellowshipAdminToPlurality =
272 OriginToPluralityVoice<RuntimeOrigin, FellowshipAdmin, FellowshipAdminBodyId>;
273
274pub type TreasurerToPlurality = OriginToPluralityVoice<RuntimeOrigin, Treasurer, TreasurerBodyId>;
276
277pub type LocalPalletOriginToLocation = (
280 GeneralAdminToPlurality,
282 StakingAdminToPlurality,
284 FellowshipAdminToPlurality,
286 TreasurerToPlurality,
288);
289
290impl pallet_xcm::Config for Runtime {
291 type RuntimeEvent = RuntimeEvent;
292 type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<
295 RuntimeOrigin,
296 (LocalPalletOriginToLocation, LocalOriginToLocation),
297 >;
298 type XcmRouter = XcmRouter;
299 type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
301 type XcmExecuteFilter = Everything;
302 type XcmExecutor = XcmExecutor<XcmConfig>;
303 type XcmTeleportFilter = Everything;
304 type XcmReserveTransferFilter = Everything;
305 type Weigher = WeightInfoBounds<
306 crate::weights::xcm::WestendXcmWeight<RuntimeCall>,
307 RuntimeCall,
308 MaxInstructions,
309 >;
310 type UniversalLocation = UniversalLocation;
311 type RuntimeOrigin = RuntimeOrigin;
312 type RuntimeCall = RuntimeCall;
313 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
314 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
315 type Currency = Balances;
316 type CurrencyMatcher = IsConcrete<TokenLocation>;
317 type TrustedLockers = ();
318 type SovereignAccountOf = LocationConverter;
319 type MaxLockers = ConstU32<8>;
320 type MaxRemoteLockConsumers = ConstU32<0>;
321 type RemoteLockConsumerIdentifier = ();
322 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
323 type AdminOrigin = EnsureRoot<AccountId>;
324 type AuthorizedAliasConsideration = Disabled;
326}