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::Session(..)
175 | RuntimeCall::Proxy(
176 pallet_proxy::Call::add_proxy { .. }
177 | pallet_proxy::Call::remove_proxy { .. }
178 | pallet_proxy::Call::remove_proxies { .. }
179 | pallet_proxy::Call::create_pure { .. }
180 | pallet_proxy::Call::kill_pure { .. }
181 | pallet_proxy::Call::announce { .. }
182 | pallet_proxy::Call::remove_announcement { .. }
183 | pallet_proxy::Call::reject_announcement { .. },
184 )
185 | RuntimeCall::Multisig(
186 pallet_multisig::Call::approve_as_multi { .. }
187 | pallet_multisig::Call::cancel_as_multi { .. },
188 ) => true,
189 RuntimeCall::PolkadotXcm(call) => !matches!(
190 call,
191 pallet_xcm::Call::send { .. } | pallet_xcm::Call::execute { .. }
192 ),
193 _ => false,
194 }
195 }
196 pub fn allow_composite_call(call: &RuntimeCall) -> bool {
200 match call {
201 RuntimeCall::Proxy(pallet_proxy::Call::proxy { call, .. }) => {
202 Self::allow_base_call(call)
203 }
204 RuntimeCall::Proxy(pallet_proxy::Call::proxy_announced { call, .. }) => {
205 Self::allow_base_call(call)
206 }
207 RuntimeCall::Utility(pallet_utility::Call::batch { calls, .. }) => {
208 calls.iter().all(|call| Self::allow_base_call(call))
209 }
210 RuntimeCall::Utility(pallet_utility::Call::batch_all { calls, .. }) => {
211 calls.iter().all(|call| Self::allow_base_call(call))
212 }
213 RuntimeCall::Utility(pallet_utility::Call::as_derivative { call, .. }) => {
214 Self::allow_base_call(call)
215 }
216 RuntimeCall::Multisig(pallet_multisig::Call::as_multi_threshold_1 { call, .. }) => {
217 Self::allow_base_call(call)
218 }
219 RuntimeCall::Multisig(pallet_multisig::Call::as_multi { call, .. }) => {
220 Self::allow_base_call(call)
221 }
222 _ => false,
223 }
224 }
225}
226
227impl Contains<RuntimeCall> for SafeCallFilter {
228 fn contains(call: &RuntimeCall) -> bool {
229 Self::allow_base_call(call) || Self::allow_composite_call(call)
230 }
231}
232
233pub type XcmBarrier = TrailingSetTopicAsId<(
234 TakeWeightCredit,
235 AllowKnownQueryResponses<PolkadotXcm>,
237 WithComputedOrigin<
239 (
240 AllowTopLevelPaidExecutionFrom<Everything>,
242 AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
244 ),
245 UniversalLocation,
246 ConstU32<8>,
247 >,
248 AllowUnpaidExecutionFrom<ParentOrParentsPlurality>,
250)>;
251
252pub type AstarXcmFungibleFeeHandler = XcmFungibleFeeHandler<
254 AccountId,
255 ConvertedConcreteId<AssetId, Balance, AstarAssetLocationIdConverter, JustTry>,
256 Assets,
257 TreasuryAccountId,
258>;
259
260pub struct XcmConfig;
261impl xcm_executor::Config for XcmConfig {
262 type RuntimeCall = RuntimeCall;
263 type XcmSender = XcmRouter;
264 type AssetTransactor = AssetTransactors;
265 type OriginConverter = XcmOriginToTransactDispatchOrigin;
266 type IsReserve = ReserveAssetFilter;
267 type IsTeleporter = ();
268 type UniversalLocation = UniversalLocation;
269 type Barrier = XcmBarrier;
270 type Weigher = Weigher;
271 type Trader = (
272 UsingComponents<XcmWeightToFee, AstarLocation, AccountId, Balances, DealWithFees>,
273 FixedRateOfForeignAsset<XcAssetConfig, AstarXcmFungibleFeeHandler>,
274 );
275 type ResponseHandler = PolkadotXcm;
276 type AssetTrap = PolkadotXcm;
277 type AssetClaims = PolkadotXcm;
278 type SubscriptionService = PolkadotXcm;
279
280 type PalletInstancesInfo = AllPalletsWithSystem;
281 type MaxAssetsIntoHolding = ConstU32<64>;
282 type AssetLocker = ();
283 type AssetExchanger = ();
284 type FeeManager = ();
285 type MessageExporter = ();
286 type UniversalAliases = Nothing;
287 type CallDispatcher = WithOriginFilter<SafeCallFilter>;
288 type SafeCallFilter = SafeCallFilter;
289 type Aliasers = Nothing;
290 type TransactionalProcessor = FrameTransactionalProcessor;
291
292 type HrmpNewChannelOpenRequestHandler = ();
293 type HrmpChannelAcceptedHandler = ();
294 type HrmpChannelClosingHandler = ();
295 type XcmRecorder = PolkadotXcm;
296 type XcmEventEmitter = PolkadotXcm;
297}
298
299pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
301
302pub type XcmRouter = (
305 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
307 XcmpQueue,
309);
310
311pub type Weigher =
312 WeightInfoBounds<weights::xcm::XcmWeight<Runtime, RuntimeCall>, RuntimeCall, MaxInstructions>;
313
314impl pallet_xcm::Config for Runtime {
315 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
316
317 type RuntimeEvent = RuntimeEvent;
318 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
319 type XcmRouter = XcmRouter;
320 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
321 type XcmExecuteFilter = Nothing;
322 type XcmExecutor = XcmExecutor<XcmConfig>;
323 type XcmTeleportFilter = Nothing;
324 type XcmReserveTransferFilter = Everything;
325 type Weigher = Weigher;
326 type UniversalLocation = UniversalLocation;
327 type RuntimeOrigin = RuntimeOrigin;
328 type RuntimeCall = RuntimeCall;
329 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; type Currency = Balances;
332 type CurrencyMatcher = ();
333 type TrustedLockers = ();
334 type SovereignAccountOf = LocationToAccountId;
335 type MaxLockers = ConstU32<0>;
336 type WeightInfo = weights::pallet_xcm::SubstrateWeight<Runtime>;
337 type MaxRemoteLockConsumers = ConstU32<0>;
338 type RemoteLockConsumerIdentifier = ();
339 type AdminOrigin = EnsureRoot<AccountId>;
340 type AuthorizedAliasConsideration = Disabled;
341}
342
343impl cumulus_pallet_xcm::Config for Runtime {
344 type RuntimeEvent = RuntimeEvent;
345 type XcmExecutor = XcmExecutor<XcmConfig>;
346}
347
348impl cumulus_pallet_xcmp_queue::Config for Runtime {
349 type RuntimeEvent = RuntimeEvent;
350 type ChannelInfo = ParachainSystem;
351 type VersionWrapper = PolkadotXcm;
352 type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
353 type MaxInboundSuspended = ConstU32<1_000>;
354 type MaxActiveOutboundChannels = ConstU32<128>;
355 type MaxPageSize = ConstU32<{ 128 * 1024 }>;
356 type ControllerOrigin = EnsureRoot<AccountId>;
357 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
358 type PriceForSiblingDelivery = NoPriceForMessageDelivery<ParaId>;
359 type WeightInfo = cumulus_pallet_xcmp_queue::weights::SubstrateWeight<Runtime>;
360}
361
362parameter_types! {
363 pub AstarLocationAbsolute: Location = Location {
365 parents: 1,
366 interior: Parachain(ParachainInfo::parachain_id().into()).into()
367
368 };
369 pub const MaxAssetsForTransfer: usize = 2;
372}
373
374pub struct AssetIdConvert;
377impl Convert<AssetId, Option<Location>> for AssetIdConvert {
378 fn convert(asset_id: AssetId) -> Option<Location> {
379 AstarAssetLocationIdConverter::convert_back(&asset_id)
380 }
381}
382
383impl orml_xtokens::Config for Runtime {
384 type Balance = Balance;
385 type CurrencyId = AssetId;
386 type CurrencyIdConvert = AssetIdConvert;
387 type AccountIdToLocation = AccountIdToMultiLocation;
388 type SelfLocation = AstarLocation;
389 type XcmExecutor = XcmExecutor<XcmConfig>;
390 type Weigher = Weigher;
391 type BaseXcmWeight = UnitWeightCost;
392 type UniversalLocation = UniversalLocation;
393 type MaxAssetsForTransfer = MaxAssetsForTransfer;
394 type MinXcmFee = DisabledParachainFee;
396 type LocationsFilter = Everything;
397 type ReserveProvider = AbsoluteAndRelativeReserveProvider<AstarLocationAbsolute>;
398 type RateLimiter = ();
399 type RateLimiterId = ();
400}