1use super::{
20 AccountId, AllPalletsWithSystem, AssetId, Assets, AstarAssetLocationIdConverter, Balance,
21 Balances, DealWithFees, MessageQueue, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime,
22 RuntimeCall, RuntimeEvent, RuntimeOrigin, TreasuryAccountId, XcAssetConfig, XcmWeightToFee,
23 XcmpQueue,
24};
25use crate::weights;
26use frame_support::{
27 parameter_types,
28 traits::{ConstU32, Contains, Everything, Nothing},
29 weights::Weight,
30};
31use frame_system::EnsureRoot;
32use sp_runtime::traits::{Convert, MaybeEquivalence};
33
34use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
36use frame_support::traits::{Disabled, TransformOrigin};
37use parachains_common::{
38 message_queue::ParaIdToSibling, xcm_config::ParentRelayOrSiblingParachains,
39};
40use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;
41use xcm::latest::prelude::*;
42use xcm_builder::{
43 Account32Hash, AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
44 AllowUnpaidExecutionFrom, ConvertedConcreteId, EnsureXcmOrigin, FrameTransactionalProcessor,
45 FungibleAdapter, FungiblesAdapter, IsConcrete, NoChecking, ParentAsSuperuser, ParentIsPreset,
46 RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
47 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
48 TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin,
49};
50use xcm_executor::{
51 traits::{JustTry, WithOriginFilter},
52 XcmExecutor,
53};
54
55use orml_xcm_support::DisabledParachainFee;
57
58use astar_primitives::xcm::{
60 AbsoluteAndRelativeReserveProvider, AccountIdToMultiLocation, AllowTopLevelPaidExecutionFrom,
61 FixedRateOfForeignAsset, ReserveAssetFilter, XcmFungibleFeeHandler,
62};
63
64parameter_types! {
65 pub RelayNetwork: Option<NetworkId> = Some(NetworkId::Polkadot);
66 pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
67 pub UniversalLocation: InteriorLocation =
68 [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into();
69 pub AstarLocation: Location = Here.into_location();
70 pub DummyCheckingAccount: AccountId = PolkadotXcm::check_account();
71}
72
73pub type LocationToAccountId = (
77 ParentIsPreset<AccountId>,
79 SiblingParachainConvertsVia<polkadot_parachain::primitives::Sibling, AccountId>,
81 AccountId32Aliases<RelayNetwork, AccountId>,
83 Account32Hash<RelayNetwork, AccountId>,
85);
86
87pub type CurrencyTransactor = FungibleAdapter<
89 Balances,
91 IsConcrete<AstarLocation>,
93 LocationToAccountId,
95 AccountId,
97 (),
99>;
100
101pub type FungiblesTransactor = FungiblesAdapter<
103 Assets,
105 ConvertedConcreteId<AssetId, Balance, AstarAssetLocationIdConverter, JustTry>,
107 LocationToAccountId,
109 AccountId,
111 NoChecking,
113 DummyCheckingAccount,
115>;
116
117pub type AssetTransactors = (CurrencyTransactor, FungiblesTransactor);
119
120pub type XcmOriginToTransactDispatchOrigin = (
124 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
128 RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
131 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
134 ParentAsSuperuser<RuntimeOrigin>,
137 pallet_xcm::XcmPassthrough<RuntimeOrigin>,
139 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
142);
143
144parameter_types! {
145 pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 4 * 1024);
148 pub const MaxInstructions: u32 = 100;
149}
150
151pub struct ParentOrParentsPlurality;
152impl Contains<Location> for ParentOrParentsPlurality {
153 fn contains(location: &Location) -> bool {
154 matches!(location.unpack(), (1, []) | (1, [Plurality { .. }]))
155 }
156}
157
158pub struct SafeCallFilter;
161impl SafeCallFilter {
162 pub fn allow_base_call(call: &RuntimeCall) -> bool {
167 match call {
168 RuntimeCall::System(..)
169 | RuntimeCall::Identity(..)
170 | RuntimeCall::Balances(..)
171 | RuntimeCall::Vesting(..)
172 | RuntimeCall::DappStaking(..)
173 | RuntimeCall::Assets(..)
174 | RuntimeCall::PolkadotXcm(..)
175 | RuntimeCall::Session(..)
176 | RuntimeCall::Proxy(
177 pallet_proxy::Call::add_proxy { .. }
178 | pallet_proxy::Call::remove_proxy { .. }
179 | pallet_proxy::Call::remove_proxies { .. }
180 | pallet_proxy::Call::create_pure { .. }
181 | pallet_proxy::Call::kill_pure { .. }
182 | pallet_proxy::Call::announce { .. }
183 | pallet_proxy::Call::remove_announcement { .. }
184 | pallet_proxy::Call::reject_announcement { .. },
185 )
186 | RuntimeCall::Multisig(
187 pallet_multisig::Call::approve_as_multi { .. }
188 | pallet_multisig::Call::cancel_as_multi { .. },
189 ) => true,
190 _ => false,
191 }
192 }
193 pub fn allow_composite_call(call: &RuntimeCall) -> bool {
197 match call {
198 RuntimeCall::Proxy(pallet_proxy::Call::proxy { call, .. }) => {
199 Self::allow_base_call(call)
200 }
201 RuntimeCall::Proxy(pallet_proxy::Call::proxy_announced { call, .. }) => {
202 Self::allow_base_call(call)
203 }
204 RuntimeCall::Utility(pallet_utility::Call::batch { calls, .. }) => {
205 calls.iter().all(|call| Self::allow_base_call(call))
206 }
207 RuntimeCall::Utility(pallet_utility::Call::batch_all { calls, .. }) => {
208 calls.iter().all(|call| Self::allow_base_call(call))
209 }
210 RuntimeCall::Utility(pallet_utility::Call::as_derivative { call, .. }) => {
211 Self::allow_base_call(call)
212 }
213 RuntimeCall::Multisig(pallet_multisig::Call::as_multi_threshold_1 { call, .. }) => {
214 Self::allow_base_call(call)
215 }
216 RuntimeCall::Multisig(pallet_multisig::Call::as_multi { call, .. }) => {
217 Self::allow_base_call(call)
218 }
219 _ => false,
220 }
221 }
222}
223
224impl Contains<RuntimeCall> for SafeCallFilter {
225 fn contains(call: &RuntimeCall) -> bool {
226 Self::allow_base_call(call) || Self::allow_composite_call(call)
227 }
228}
229
230pub type XcmBarrier = TrailingSetTopicAsId<(
231 TakeWeightCredit,
232 AllowKnownQueryResponses<PolkadotXcm>,
234 WithComputedOrigin<
236 (
237 AllowTopLevelPaidExecutionFrom<Everything>,
239 AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
241 ),
242 UniversalLocation,
243 ConstU32<8>,
244 >,
245 AllowUnpaidExecutionFrom<ParentOrParentsPlurality>,
247)>;
248
249pub type AstarXcmFungibleFeeHandler = XcmFungibleFeeHandler<
251 AccountId,
252 ConvertedConcreteId<AssetId, Balance, AstarAssetLocationIdConverter, JustTry>,
253 Assets,
254 TreasuryAccountId,
255>;
256
257pub struct XcmConfig;
258impl xcm_executor::Config for XcmConfig {
259 type RuntimeCall = RuntimeCall;
260 type XcmSender = XcmRouter;
261 type AssetTransactor = AssetTransactors;
262 type OriginConverter = XcmOriginToTransactDispatchOrigin;
263 type IsReserve = ReserveAssetFilter;
264 type IsTeleporter = ();
265 type UniversalLocation = UniversalLocation;
266 type Barrier = XcmBarrier;
267 type Weigher = Weigher;
268 type Trader = (
269 UsingComponents<XcmWeightToFee, AstarLocation, AccountId, Balances, DealWithFees>,
270 FixedRateOfForeignAsset<XcAssetConfig, AstarXcmFungibleFeeHandler>,
271 );
272 type ResponseHandler = PolkadotXcm;
273 type AssetTrap = PolkadotXcm;
274 type AssetClaims = PolkadotXcm;
275 type SubscriptionService = PolkadotXcm;
276
277 type PalletInstancesInfo = AllPalletsWithSystem;
278 type MaxAssetsIntoHolding = ConstU32<64>;
279 type AssetLocker = ();
280 type AssetExchanger = ();
281 type FeeManager = ();
282 type MessageExporter = ();
283 type UniversalAliases = Nothing;
284 type CallDispatcher = WithOriginFilter<SafeCallFilter>;
285 type SafeCallFilter = SafeCallFilter;
286 type Aliasers = Nothing;
287 type TransactionalProcessor = FrameTransactionalProcessor;
288
289 type HrmpNewChannelOpenRequestHandler = ();
290 type HrmpChannelAcceptedHandler = ();
291 type HrmpChannelClosingHandler = ();
292 type XcmRecorder = PolkadotXcm;
293 type XcmEventEmitter = PolkadotXcm;
294}
295
296pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
298
299pub type XcmRouter = (
302 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
304 XcmpQueue,
306);
307
308pub type Weigher =
309 WeightInfoBounds<weights::xcm::XcmWeight<Runtime, RuntimeCall>, RuntimeCall, MaxInstructions>;
310
311impl pallet_xcm::Config for Runtime {
312 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
313
314 type RuntimeEvent = RuntimeEvent;
315 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
316 type XcmRouter = XcmRouter;
317 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
318 type XcmExecuteFilter = Nothing;
319 type XcmExecutor = XcmExecutor<XcmConfig>;
320 type XcmTeleportFilter = Nothing;
321 type XcmReserveTransferFilter = Everything;
322 type Weigher = Weigher;
323 type UniversalLocation = UniversalLocation;
324 type RuntimeOrigin = RuntimeOrigin;
325 type RuntimeCall = RuntimeCall;
326 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; type Currency = Balances;
329 type CurrencyMatcher = ();
330 type TrustedLockers = ();
331 type SovereignAccountOf = LocationToAccountId;
332 type MaxLockers = ConstU32<0>;
333 type WeightInfo = weights::pallet_xcm::SubstrateWeight<Runtime>;
334 type MaxRemoteLockConsumers = ConstU32<0>;
335 type RemoteLockConsumerIdentifier = ();
336 type AdminOrigin = EnsureRoot<AccountId>;
337 type AuthorizedAliasConsideration = Disabled;
338}
339
340impl cumulus_pallet_xcm::Config for Runtime {
341 type RuntimeEvent = RuntimeEvent;
342 type XcmExecutor = XcmExecutor<XcmConfig>;
343}
344
345impl cumulus_pallet_xcmp_queue::Config for Runtime {
346 type RuntimeEvent = RuntimeEvent;
347 type ChannelInfo = ParachainSystem;
348 type VersionWrapper = PolkadotXcm;
349 type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
350 type MaxInboundSuspended = ConstU32<1_000>;
351 type MaxActiveOutboundChannels = ConstU32<128>;
352 type MaxPageSize = ConstU32<{ 128 * 1024 }>;
353 type ControllerOrigin = EnsureRoot<AccountId>;
354 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
355 type PriceForSiblingDelivery = NoPriceForMessageDelivery<ParaId>;
356 type WeightInfo = cumulus_pallet_xcmp_queue::weights::SubstrateWeight<Runtime>;
357}
358
359parameter_types! {
360 pub AstarLocationAbsolute: Location = Location {
362 parents: 1,
363 interior: Parachain(ParachainInfo::parachain_id().into()).into()
364
365 };
366 pub const MaxAssetsForTransfer: usize = 2;
369}
370
371pub struct AssetIdConvert;
374impl Convert<AssetId, Option<Location>> for AssetIdConvert {
375 fn convert(asset_id: AssetId) -> Option<Location> {
376 AstarAssetLocationIdConverter::convert_back(&asset_id)
377 }
378}
379
380impl orml_xtokens::Config for Runtime {
381 type Balance = Balance;
382 type CurrencyId = AssetId;
383 type CurrencyIdConvert = AssetIdConvert;
384 type AccountIdToLocation = AccountIdToMultiLocation;
385 type SelfLocation = AstarLocation;
386 type XcmExecutor = XcmExecutor<XcmConfig>;
387 type Weigher = Weigher;
388 type BaseXcmWeight = UnitWeightCost;
389 type UniversalLocation = UniversalLocation;
390 type MaxAssetsForTransfer = MaxAssetsForTransfer;
391 type MinXcmFee = DisabledParachainFee;
393 type LocationsFilter = Everything;
394 type ReserveProvider = AbsoluteAndRelativeReserveProvider<AstarLocationAbsolute>;
395 type RateLimiter = ();
396 type RateLimiterId = ();
397}