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, PalletInfoAccess},
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 TreasuryLocation: Location = PalletInstance(<Treasury as PalletInfoAccess>::index() as u8).into();
62 pub FeeAssetId: AssetId = AssetId(TokenLocation::get());
64 pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
66 pub const FellowsBodyId: BodyId = BodyId::Technical;
68}
69
70pub type LocationConverter = (
71 ChildParachainConvertsVia<ParaId, AccountId>,
73 AccountId32Aliases<ThisNetwork, AccountId>,
75 HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
77);
78
79pub type LocalAssetTransactor = FungibleAdapter<
80 Balances,
82 IsConcrete<TokenLocation>,
84 LocationConverter,
86 AccountId,
88 TeleportTracking,
89>;
90
91type LocalOriginConverter = (
92 LocationAsSuperuser<Equals<AssetHub>, RuntimeOrigin>,
94 SovereignSignedViaLocation<LocationConverter, RuntimeOrigin>,
97 ChildParachainAsNative<parachains_origin::Origin, RuntimeOrigin>,
100 SignedAccountId32AsNative<ThisNetwork, RuntimeOrigin>,
103 XcmPassthrough<RuntimeOrigin>,
105);
106
107pub type PriceForChildParachainDelivery =
108 ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, Dmp>;
109
110pub type XcmRouter = WithUniqueTopic<
113 ChildParachainRouter<Runtime, XcmPallet, PriceForChildParachainDelivery>,
115>;
116
117parameter_types! {
118 pub AssetHub: Location = Parachain(ASSET_HUB_ID).into_location();
119 pub AssetHubNext: Location = Parachain(ASSET_HUB_NEXT_ID).into_location();
120 pub Collectives: Location = Parachain(COLLECTIVES_ID).into_location();
121 pub BridgeHub: Location = Parachain(BRIDGE_HUB_ID).into_location();
122 pub Encointer: Location = Parachain(ENCOINTER_ID).into_location();
123 pub People: Location = Parachain(PEOPLE_ID).into_location();
124 pub Broker: Location = Parachain(BROKER_ID).into_location();
125 pub Wnd: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(TokenLocation::get()) });
126 pub WndForAssetHub: (AssetFilter, Location) = (Wnd::get(), AssetHub::get());
127 pub WndForAssetHubNext: (AssetFilter, Location) = (Wnd::get(), AssetHubNext::get());
128 pub WndForCollectives: (AssetFilter, Location) = (Wnd::get(), Collectives::get());
129 pub WndForBridgeHub: (AssetFilter, Location) = (Wnd::get(), BridgeHub::get());
130 pub WndForEncointer: (AssetFilter, Location) = (Wnd::get(), Encointer::get());
131 pub WndForPeople: (AssetFilter, Location) = (Wnd::get(), People::get());
132 pub WndForBroker: (AssetFilter, Location) = (Wnd::get(), Broker::get());
133 pub MaxInstructions: u32 = 100;
134 pub MaxAssetsIntoHolding: u32 = 64;
135}
136
137pub type TrustedTeleporters = (
138 xcm_builder::Case<WndForAssetHub>,
139 xcm_builder::Case<WndForAssetHubNext>,
140 xcm_builder::Case<WndForCollectives>,
141 xcm_builder::Case<WndForBridgeHub>,
142 xcm_builder::Case<WndForEncointer>,
143 xcm_builder::Case<WndForPeople>,
144 xcm_builder::Case<WndForBroker>,
145);
146
147pub struct OnlyParachains;
148impl Contains<Location> for OnlyParachains {
149 fn contains(location: &Location) -> bool {
150 matches!(location.unpack(), (0, [Parachain(_)]))
151 }
152}
153
154pub struct Fellows;
155impl Contains<Location> for Fellows {
156 fn contains(location: &Location) -> bool {
157 matches!(
158 location.unpack(),
159 (0, [Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }])
160 )
161 }
162}
163
164pub struct LocalPlurality;
165impl Contains<Location> for LocalPlurality {
166 fn contains(loc: &Location) -> bool {
167 matches!(loc.unpack(), (0, [Plurality { .. }]))
168 }
169}
170
171pub type Barrier = TrailingSetTopicAsId<(
173 TakeWeightCredit,
175 AllowKnownQueryResponses<XcmPallet>,
177 WithComputedOrigin<
178 (
179 AllowTopLevelPaidExecutionFrom<Everything>,
181 AllowSubscriptionsFrom<OnlyParachains>,
183 AllowExplicitUnpaidExecutionFrom<(IsChildSystemParachain<ParaId>, Fellows)>,
185 ),
186 UniversalLocation,
187 ConstU32<8>,
188 >,
189)>;
190
191pub type WaivedLocations =
194 (SystemParachains, Equals<RootLocation>, LocalPlurality, Equals<TreasuryLocation>);
195
196pub type Aliasers = AliasChildLocation;
200
201pub struct XcmConfig;
202impl xcm_executor::Config for XcmConfig {
203 type RuntimeCall = RuntimeCall;
204 type XcmSender = XcmRouter;
205 type XcmEventEmitter = XcmPallet;
206 type AssetTransactor = LocalAssetTransactor;
207 type OriginConverter = LocalOriginConverter;
208 type IsReserve = ();
209 type IsTeleporter = TrustedTeleporters;
210 type UniversalLocation = UniversalLocation;
211 type Barrier = Barrier;
212 type Weigher = WeightInfoBounds<
213 crate::weights::xcm::WestendXcmWeight<RuntimeCall>,
214 RuntimeCall,
215 MaxInstructions,
216 >;
217 type Trader =
221 UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToAuthor<Runtime>>;
222 type ResponseHandler = XcmPallet;
223 type AssetTrap = XcmPallet;
224 type AssetLocker = ();
225 type AssetExchanger = ();
226 type SubscriptionService = XcmPallet;
227 type PalletInstancesInfo = AllPalletsWithSystem;
228 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
229 type FeeManager = XcmFeeManagerFromComponents<
231 WaivedLocations,
232 SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
233 >;
234 type MessageExporter = ();
235 type UniversalAliases = Nothing;
236 type CallDispatcher = RuntimeCall;
237 type SafeCallFilter = Everything;
238 type Aliasers = Aliasers;
239 type TransactionalProcessor = FrameTransactionalProcessor;
240 type HrmpNewChannelOpenRequestHandler = ();
241 type HrmpChannelAcceptedHandler = ();
242 type HrmpChannelClosingHandler = ();
243 type XcmRecorder = XcmPallet;
244}
245
246parameter_types! {
247 pub const GeneralAdminBodyId: BodyId = BodyId::Administration;
249 pub const StakingAdminBodyId: BodyId = BodyId::Defense;
251 pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX);
253 pub const TreasurerBodyId: BodyId = BodyId::Treasury;
255 pub const DDayBodyId: BodyId = BodyId::Moniker([b'd', b'd', b'a', b'y']);
257}
258
259pub type GeneralAdminToPlurality =
261 OriginToPluralityVoice<RuntimeOrigin, GeneralAdmin, GeneralAdminBodyId>;
262
263pub type LocalOriginToLocation = (
266 GeneralAdminToPlurality,
267 SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>,
269);
270
271pub type StakingAdminToPlurality =
273 OriginToPluralityVoice<RuntimeOrigin, StakingAdmin, StakingAdminBodyId>;
274
275pub type FellowshipAdminToPlurality =
277 OriginToPluralityVoice<RuntimeOrigin, FellowshipAdmin, FellowshipAdminBodyId>;
278
279pub type TreasurerToPlurality = OriginToPluralityVoice<RuntimeOrigin, Treasurer, TreasurerBodyId>;
281
282pub type LocalPalletOriginToLocation = (
285 GeneralAdminToPlurality,
287 StakingAdminToPlurality,
289 FellowshipAdminToPlurality,
291 TreasurerToPlurality,
293);
294
295impl pallet_xcm::Config for Runtime {
296 type RuntimeEvent = RuntimeEvent;
297 type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<
300 RuntimeOrigin,
301 (LocalPalletOriginToLocation, LocalOriginToLocation),
302 >;
303 type XcmRouter = XcmRouter;
304 type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
306 type XcmExecuteFilter = Everything;
307 type XcmExecutor = XcmExecutor<XcmConfig>;
308 type XcmTeleportFilter = Everything;
309 type XcmReserveTransferFilter = Everything;
310 type Weigher = WeightInfoBounds<
311 crate::weights::xcm::WestendXcmWeight<RuntimeCall>,
312 RuntimeCall,
313 MaxInstructions,
314 >;
315 type UniversalLocation = UniversalLocation;
316 type RuntimeOrigin = RuntimeOrigin;
317 type RuntimeCall = RuntimeCall;
318 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
319 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
320 type Currency = Balances;
321 type CurrencyMatcher = IsConcrete<TokenLocation>;
322 type TrustedLockers = ();
323 type SovereignAccountOf = LocationConverter;
324 type MaxLockers = ConstU32<8>;
325 type MaxRemoteLockConsumers = ConstU32<0>;
326 type RemoteLockConsumerIdentifier = ();
327 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
328 type AdminOrigin = EnsureRoot<AccountId>;
329 type AuthorizedAliasConsideration = Disabled;
331}