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