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::*, 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 Collectives: Location = Parachain(COLLECTIVES_ID).into_location();
115 pub BridgeHub: Location = Parachain(BRIDGE_HUB_ID).into_location();
116 pub Encointer: Location = Parachain(ENCOINTER_ID).into_location();
117 pub People: Location = Parachain(PEOPLE_ID).into_location();
118 pub Broker: Location = Parachain(BROKER_ID).into_location();
119 pub Wnd: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(TokenLocation::get()) });
120 pub WndForAssetHub: (AssetFilter, Location) = (Wnd::get(), AssetHub::get());
121 pub WndForCollectives: (AssetFilter, Location) = (Wnd::get(), Collectives::get());
122 pub WndForBridgeHub: (AssetFilter, Location) = (Wnd::get(), BridgeHub::get());
123 pub WndForEncointer: (AssetFilter, Location) = (Wnd::get(), Encointer::get());
124 pub WndForPeople: (AssetFilter, Location) = (Wnd::get(), People::get());
125 pub WndForBroker: (AssetFilter, Location) = (Wnd::get(), Broker::get());
126 pub MaxInstructions: u32 = 100;
127 pub MaxAssetsIntoHolding: u32 = 64;
128}
129
130pub type TrustedTeleporters = (
131 xcm_builder::Case<WndForAssetHub>,
132 xcm_builder::Case<WndForCollectives>,
133 xcm_builder::Case<WndForBridgeHub>,
134 xcm_builder::Case<WndForEncointer>,
135 xcm_builder::Case<WndForPeople>,
136 xcm_builder::Case<WndForBroker>,
137);
138
139pub struct OnlyParachains;
140impl Contains<Location> for OnlyParachains {
141 fn contains(location: &Location) -> bool {
142 matches!(location.unpack(), (0, [Parachain(_)]))
143 }
144}
145
146pub struct Fellows;
147impl Contains<Location> for Fellows {
148 fn contains(location: &Location) -> bool {
149 matches!(
150 location.unpack(),
151 (0, [Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }])
152 )
153 }
154}
155
156pub struct LocalPlurality;
157impl Contains<Location> for LocalPlurality {
158 fn contains(loc: &Location) -> bool {
159 matches!(loc.unpack(), (0, [Plurality { .. }]))
160 }
161}
162
163pub type Barrier = TrailingSetTopicAsId<(
165 TakeWeightCredit,
167 AllowKnownQueryResponses<XcmPallet>,
169 WithComputedOrigin<
170 (
171 AllowTopLevelPaidExecutionFrom<Everything>,
173 AllowSubscriptionsFrom<OnlyParachains>,
175 AllowExplicitUnpaidExecutionFrom<(IsChildSystemParachain<ParaId>, Fellows)>,
177 ),
178 UniversalLocation,
179 ConstU32<8>,
180 >,
181)>;
182
183pub type WaivedLocations = (SystemParachains, Equals<RootLocation>, LocalPlurality);
186
187pub type Aliasers = AliasChildLocation;
191
192pub struct XcmConfig;
193impl xcm_executor::Config for XcmConfig {
194 type RuntimeCall = RuntimeCall;
195 type XcmSender = XcmRouter;
196 type AssetTransactor = LocalAssetTransactor;
197 type OriginConverter = LocalOriginConverter;
198 type IsReserve = ();
199 type IsTeleporter = TrustedTeleporters;
200 type UniversalLocation = UniversalLocation;
201 type Barrier = Barrier;
202 type Weigher = WeightInfoBounds<
203 crate::weights::xcm::WestendXcmWeight<RuntimeCall>,
204 RuntimeCall,
205 MaxInstructions,
206 >;
207 type Trader =
208 UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToAuthor<Runtime>>;
209 type ResponseHandler = XcmPallet;
210 type AssetTrap = XcmPallet;
211 type AssetLocker = ();
212 type AssetExchanger = ();
213 type AssetClaims = XcmPallet;
214 type SubscriptionService = XcmPallet;
215 type PalletInstancesInfo = AllPalletsWithSystem;
216 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
217 type FeeManager = XcmFeeManagerFromComponents<
218 WaivedLocations,
219 SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
220 >;
221 type MessageExporter = ();
222 type UniversalAliases = Nothing;
223 type CallDispatcher = RuntimeCall;
224 type SafeCallFilter = Everything;
225 type Aliasers = Aliasers;
226 type TransactionalProcessor = FrameTransactionalProcessor;
227 type HrmpNewChannelOpenRequestHandler = ();
228 type HrmpChannelAcceptedHandler = ();
229 type HrmpChannelClosingHandler = ();
230 type XcmRecorder = XcmPallet;
231}
232
233parameter_types! {
234 pub const GeneralAdminBodyId: BodyId = BodyId::Administration;
236 pub const StakingAdminBodyId: BodyId = BodyId::Defense;
238 pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX);
240 pub const TreasurerBodyId: BodyId = BodyId::Treasury;
242}
243
244pub type GeneralAdminToPlurality =
246 OriginToPluralityVoice<RuntimeOrigin, GeneralAdmin, GeneralAdminBodyId>;
247
248pub type LocalOriginToLocation = (
250 GeneralAdminToPlurality,
251 SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>,
253);
254
255pub type StakingAdminToPlurality =
257 OriginToPluralityVoice<RuntimeOrigin, StakingAdmin, StakingAdminBodyId>;
258
259pub type FellowshipAdminToPlurality =
261 OriginToPluralityVoice<RuntimeOrigin, FellowshipAdmin, FellowshipAdminBodyId>;
262
263pub type TreasurerToPlurality = OriginToPluralityVoice<RuntimeOrigin, Treasurer, TreasurerBodyId>;
265
266pub type LocalPalletOriginToLocation = (
269 GeneralAdminToPlurality,
271 StakingAdminToPlurality,
273 FellowshipAdminToPlurality,
275 TreasurerToPlurality,
277);
278
279impl pallet_xcm::Config for Runtime {
280 type RuntimeEvent = RuntimeEvent;
281 type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
284 type XcmRouter = XcmRouter;
285 type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
287 type XcmExecuteFilter = Everything;
288 type XcmExecutor = XcmExecutor<XcmConfig>;
289 type XcmTeleportFilter = Everything;
290 type XcmReserveTransferFilter = Everything;
291 type Weigher = WeightInfoBounds<
292 crate::weights::xcm::WestendXcmWeight<RuntimeCall>,
293 RuntimeCall,
294 MaxInstructions,
295 >;
296 type UniversalLocation = UniversalLocation;
297 type RuntimeOrigin = RuntimeOrigin;
298 type RuntimeCall = RuntimeCall;
299 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
300 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
301 type Currency = Balances;
302 type CurrencyMatcher = IsConcrete<TokenLocation>;
303 type TrustedLockers = ();
304 type SovereignAccountOf = LocationConverter;
305 type MaxLockers = ConstU32<8>;
306 type MaxRemoteLockConsumers = ConstU32<0>;
307 type RemoteLockConsumerIdentifier = ();
308 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
309 type AdminOrigin = EnsureRoot<AccountId>;
310}