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, Balance, RuntimeHoldReason};
25use frame_support::{
26 parameter_types,
27 traits::{
28 fungible::HoldConsideration, Contains, Equals, Everything, LinearStoragePrice, Nothing,
29 },
30};
31use frame_system::EnsureRoot;
32use pallet_staking_async_rc_runtime_constants::{
33 currency::CENTS, system_parachain::*, xcm::body::FELLOWSHIP_ADMIN_INDEX,
34};
35use pallet_xcm::XcmPassthrough;
36use polkadot_runtime_common::{
37 xcm_sender::{ChildParachainRouter, ExponentialPrice},
38 ToAuthor,
39};
40use sp_core::ConstU32;
41use xcm::latest::{prelude::*, WESTEND_GENESIS_HASH};
42use xcm_builder::{
43 AccountId32Aliases, AliasChildLocation, AllowExplicitUnpaidExecutionFrom,
44 AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
45 ChildParachainAsNative, ChildParachainConvertsVia, DescribeAllTerminal, DescribeFamily,
46 FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsChildSystemParachain,
47 IsConcrete, MintLocation, OriginToPluralityVoice, SendXcmFeeToAccount,
48 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
49 TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
50 XcmFeeManagerFromComponents,
51};
52use xcm_executor::XcmExecutor;
53
54parameter_types! {
55 pub const TokenLocation: Location = Here.into_location();
56 pub const RootLocation: Location = Location::here();
57 pub const ThisNetwork: NetworkId = ByGenesis(WESTEND_GENESIS_HASH);
58 pub UniversalLocation: InteriorLocation = [GlobalConsensus(ThisNetwork::get())].into();
59 pub CheckAccount: AccountId = XcmPallet::check_account();
60 pub LocalCheckAccount: (AccountId, MintLocation) = (CheckAccount::get(), MintLocation::Local);
61 pub TreasuryAccount: AccountId = Treasury::account_id();
62 pub FeeAssetId: AssetId = AssetId(TokenLocation::get());
64 pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
66 pub TeleportTracking: Option<(AccountId, MintLocation)> = None;
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,
90>;
91
92type LocalOriginConverter = (
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 Collectives: Location = Parachain(COLLECTIVES_ID).into_location();
119 pub BridgeHub: Location = Parachain(BRIDGE_HUB_ID).into_location();
120 pub Encointer: Location = Parachain(ENCOINTER_ID).into_location();
121 pub People: Location = Parachain(PEOPLE_ID).into_location();
122 pub Broker: Location = Parachain(BROKER_ID).into_location();
123 pub Wnd: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(TokenLocation::get()) });
124 pub WndForAssetHub: (AssetFilter, Location) = (Wnd::get(), AssetHub::get());
125 pub WndForCollectives: (AssetFilter, Location) = (Wnd::get(), Collectives::get());
126 pub WndForBridgeHub: (AssetFilter, Location) = (Wnd::get(), BridgeHub::get());
127 pub WndForEncointer: (AssetFilter, Location) = (Wnd::get(), Encointer::get());
128 pub WndForPeople: (AssetFilter, Location) = (Wnd::get(), People::get());
129 pub WndForBroker: (AssetFilter, Location) = (Wnd::get(), Broker::get());
130 pub MaxInstructions: u32 = 100;
131 pub MaxAssetsIntoHolding: u32 = 64;
132}
133
134pub type TrustedTeleporters = (
135 xcm_builder::Case<WndForAssetHub>,
136 xcm_builder::Case<WndForCollectives>,
137 xcm_builder::Case<WndForBridgeHub>,
138 xcm_builder::Case<WndForEncointer>,
139 xcm_builder::Case<WndForPeople>,
140 xcm_builder::Case<WndForBroker>,
141);
142
143pub struct OnlyParachains;
144impl Contains<Location> for OnlyParachains {
145 fn contains(location: &Location) -> bool {
146 matches!(location.unpack(), (0, [Parachain(_)]))
147 }
148}
149
150pub struct Fellows;
151impl Contains<Location> for Fellows {
152 fn contains(location: &Location) -> bool {
153 matches!(
154 location.unpack(),
155 (0, [Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }])
156 )
157 }
158}
159
160pub struct LocalPlurality;
161impl Contains<Location> for LocalPlurality {
162 fn contains(loc: &Location) -> bool {
163 matches!(loc.unpack(), (0, [Plurality { .. }]))
164 }
165}
166
167pub type Barrier = TrailingSetTopicAsId<(
169 TakeWeightCredit,
171 AllowKnownQueryResponses<XcmPallet>,
173 WithComputedOrigin<
174 (
175 AllowTopLevelPaidExecutionFrom<Everything>,
177 AllowSubscriptionsFrom<OnlyParachains>,
179 AllowExplicitUnpaidExecutionFrom<(IsChildSystemParachain<ParaId>, Fellows)>,
181 ),
182 UniversalLocation,
183 ConstU32<8>,
184 >,
185)>;
186
187pub type WaivedLocations = (SystemParachains, Equals<RootLocation>, LocalPlurality);
190
191pub type Aliasers = AliasChildLocation;
195
196pub struct XcmConfig;
197impl xcm_executor::Config for XcmConfig {
198 type RuntimeCall = RuntimeCall;
199 type XcmSender = XcmRouter;
200 type AssetTransactor = LocalAssetTransactor;
201 type OriginConverter = LocalOriginConverter;
202 type IsReserve = ();
203 type XcmEventEmitter = XcmPallet;
204 type IsTeleporter = TrustedTeleporters;
205 type UniversalLocation = UniversalLocation;
206 type Barrier = Barrier;
207 type Weigher = WeightInfoBounds<
208 crate::weights::xcm::WestendXcmWeight<RuntimeCall>,
209 RuntimeCall,
210 MaxInstructions,
211 >;
212 type Trader =
213 UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToAuthor<Runtime>>;
214 type ResponseHandler = XcmPallet;
215 type AssetTrap = XcmPallet;
216 type AssetLocker = ();
217 type AssetExchanger = ();
218 type AssetClaims = XcmPallet;
219 type SubscriptionService = XcmPallet;
220 type PalletInstancesInfo = AllPalletsWithSystem;
221 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
222 type FeeManager = XcmFeeManagerFromComponents<
223 WaivedLocations,
224 SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
225 >;
226 type MessageExporter = ();
227 type UniversalAliases = Nothing;
228 type CallDispatcher = RuntimeCall;
229 type SafeCallFilter = Everything;
230 type Aliasers = Aliasers;
231 type TransactionalProcessor = FrameTransactionalProcessor;
232 type HrmpNewChannelOpenRequestHandler = ();
233 type HrmpChannelAcceptedHandler = ();
234 type HrmpChannelClosingHandler = ();
235 type XcmRecorder = XcmPallet;
236}
237
238parameter_types! {
239 pub const GeneralAdminBodyId: BodyId = BodyId::Administration;
241 pub const StakingAdminBodyId: BodyId = BodyId::Defense;
243 pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX);
245 pub const TreasurerBodyId: BodyId = BodyId::Treasury;
247
248 pub const DepositPerItem: Balance = crate::deposit(1, 0);
249 pub const DepositPerByte: Balance = crate::deposit(0, 1);
250 pub const AuthorizeAliasHoldReason: RuntimeHoldReason = RuntimeHoldReason::XcmPallet(pallet_xcm::HoldReason::AuthorizeAlias);
251}
252
253pub type GeneralAdminToPlurality =
255 OriginToPluralityVoice<RuntimeOrigin, GeneralAdmin, GeneralAdminBodyId>;
256
257pub type LocalOriginToLocation = (
259 GeneralAdminToPlurality,
260 SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>,
262);
263
264pub type StakingAdminToPlurality =
266 OriginToPluralityVoice<RuntimeOrigin, StakingAdmin, StakingAdminBodyId>;
267
268pub type FellowshipAdminToPlurality =
270 OriginToPluralityVoice<RuntimeOrigin, FellowshipAdmin, FellowshipAdminBodyId>;
271
272pub type TreasurerToPlurality = OriginToPluralityVoice<RuntimeOrigin, Treasurer, TreasurerBodyId>;
274
275pub type LocalPalletOriginToLocation = (
278 GeneralAdminToPlurality,
280 StakingAdminToPlurality,
282 FellowshipAdminToPlurality,
284 TreasurerToPlurality,
286);
287
288impl pallet_xcm::Config for Runtime {
289 type RuntimeEvent = RuntimeEvent;
290 type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<
293 RuntimeOrigin,
294 (LocalPalletOriginToLocation, LocalOriginToLocation),
295 >;
296 type XcmRouter = XcmRouter;
297 type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
299 type XcmExecuteFilter = Everything;
300 type XcmExecutor = XcmExecutor<XcmConfig>;
301 type XcmTeleportFilter = Everything;
302 type XcmReserveTransferFilter = Everything;
303 type Weigher = WeightInfoBounds<
304 crate::weights::xcm::WestendXcmWeight<RuntimeCall>,
305 RuntimeCall,
306 MaxInstructions,
307 >;
308 type UniversalLocation = UniversalLocation;
309 type RuntimeOrigin = RuntimeOrigin;
310 type RuntimeCall = RuntimeCall;
311 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
312 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
313 type Currency = Balances;
314 type CurrencyMatcher = IsConcrete<TokenLocation>;
315 type TrustedLockers = ();
316 type SovereignAccountOf = LocationConverter;
317 type MaxLockers = ConstU32<8>;
318 type MaxRemoteLockConsumers = ConstU32<0>;
319 type RemoteLockConsumerIdentifier = ();
320 type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
321 type AdminOrigin = EnsureRoot<AccountId>;
322 type AuthorizedAliasConsideration = HoldConsideration<
323 AccountId,
324 Balances,
325 AuthorizeAliasHoldReason,
326 LinearStoragePrice<DepositPerItem, DepositPerByte, Balance>,
327 >;
328}