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 AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, ConvertedConcreteId, EnsureXcmOrigin,
45 FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, IsConcrete, NoChecking,
46 ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
47 SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
48 SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
49 WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
50};
51use xcm_executor::{
52 traits::{JustTry, WithOriginFilter},
53 XcmExecutor,
54};
55
56use astar_primitives::xcm::{FixedRateOfForeignAsset, ReserveAssetFilter, XcmFungibleFeeHandler};
58
59parameter_types! {
60 pub RelayNetwork: Option<NetworkId> = Some(NetworkId::Polkadot);
61 pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
62 pub UniversalLocation: InteriorLocation =
63 [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into();
64 pub AstarLocation: Location = Here.into_location();
65 pub DummyCheckingAccount: AccountId = PolkadotXcm::check_account();
66}
67
68pub type LocationToAccountId = (
72 ParentIsPreset<AccountId>,
74 SiblingParachainConvertsVia<polkadot_parachain::primitives::Sibling, AccountId>,
76 AccountId32Aliases<RelayNetwork, AccountId>,
78 Account32Hash<RelayNetwork, AccountId>,
80);
81
82pub type CurrencyTransactor = FungibleAdapter<
84 Balances,
86 IsConcrete<AstarLocation>,
88 LocationToAccountId,
90 AccountId,
92 (),
94>;
95
96pub type FungiblesTransactor = FungiblesAdapter<
98 Assets,
100 ConvertedConcreteId<AssetId, Balance, AstarAssetLocationIdConverter, JustTry>,
102 LocationToAccountId,
104 AccountId,
106 NoChecking,
108 DummyCheckingAccount,
110>;
111
112pub type AssetTransactors = (CurrencyTransactor, FungiblesTransactor);
114
115pub type XcmOriginToTransactDispatchOrigin = (
119 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
123 RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
126 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
129 ParentAsSuperuser<RuntimeOrigin>,
132 pallet_xcm::XcmPassthrough<RuntimeOrigin>,
134 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
137);
138
139parameter_types! {
140 pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 4 * 1024);
143 pub const MaxInstructions: u32 = 100;
144}
145
146pub struct ParentOrParentsPlurality;
147impl Contains<Location> for ParentOrParentsPlurality {
148 fn contains(location: &Location) -> bool {
149 matches!(location.unpack(), (1, []) | (1, [Plurality { .. }]))
150 }
151}
152
153pub struct SafeCallFilter;
156impl SafeCallFilter {
157 pub fn allow_base_call(call: &RuntimeCall) -> bool {
162 match call {
163 RuntimeCall::System(..)
164 | RuntimeCall::Identity(..)
165 | RuntimeCall::Balances(..)
166 | RuntimeCall::Vesting(..)
167 | RuntimeCall::DappStaking(..)
168 | RuntimeCall::Assets(..)
169 | RuntimeCall::Session(..)
170 | RuntimeCall::Proxy(
171 pallet_proxy::Call::add_proxy { .. }
172 | pallet_proxy::Call::remove_proxy { .. }
173 | pallet_proxy::Call::remove_proxies { .. }
174 | pallet_proxy::Call::create_pure { .. }
175 | pallet_proxy::Call::kill_pure { .. }
176 | pallet_proxy::Call::announce { .. }
177 | pallet_proxy::Call::remove_announcement { .. }
178 | pallet_proxy::Call::reject_announcement { .. },
179 )
180 | RuntimeCall::Multisig(
181 pallet_multisig::Call::approve_as_multi { .. }
182 | pallet_multisig::Call::cancel_as_multi { .. },
183 ) => true,
184 RuntimeCall::PolkadotXcm(call) => !matches!(
185 call,
186 pallet_xcm::Call::send { .. } | pallet_xcm::Call::execute { .. }
187 ),
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 = TrailingSetTopicAsId<(
229 TakeWeightCredit,
230 AllowKnownQueryResponses<PolkadotXcm>,
232 WithComputedOrigin<
234 (
235 AllowTopLevelPaidExecutionFrom<Everything>,
237 AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
239 ),
240 UniversalLocation,
241 ConstU32<8>,
242 >,
243 AllowUnpaidExecutionFrom<ParentOrParentsPlurality>,
245)>;
246
247pub type AstarXcmFungibleFeeHandler = XcmFungibleFeeHandler<
249 AccountId,
250 ConvertedConcreteId<AssetId, Balance, AstarAssetLocationIdConverter, JustTry>,
251 Assets,
252 TreasuryAccountId,
253>;
254
255pub struct XcmConfig;
256impl xcm_executor::Config for XcmConfig {
257 type RuntimeCall = RuntimeCall;
258 type XcmSender = XcmRouter;
259 type AssetTransactor = AssetTransactors;
260 type OriginConverter = XcmOriginToTransactDispatchOrigin;
261 type IsReserve = ReserveAssetFilter;
262 type IsTeleporter = ();
263 type UniversalLocation = UniversalLocation;
264 type Barrier = XcmBarrier;
265 type Weigher = Weigher;
266 type Trader = (
267 UsingComponents<XcmWeightToFee, AstarLocation, AccountId, Balances, DealWithFees>,
268 FixedRateOfForeignAsset<XcAssetConfig, AstarXcmFungibleFeeHandler>,
269 );
270 type ResponseHandler = PolkadotXcm;
271 type AssetTrap = PolkadotXcm;
272 type AssetClaims = PolkadotXcm;
273 type SubscriptionService = PolkadotXcm;
274
275 type PalletInstancesInfo = AllPalletsWithSystem;
276 type MaxAssetsIntoHolding = ConstU32<64>;
277 type AssetLocker = ();
278 type AssetExchanger = ();
279 type FeeManager = ();
280 type MessageExporter = ();
281 type UniversalAliases = Nothing;
282 type CallDispatcher = WithOriginFilter<SafeCallFilter>;
283 type SafeCallFilter = SafeCallFilter;
284 type Aliasers = Nothing;
285 type TransactionalProcessor = FrameTransactionalProcessor;
286
287 type HrmpNewChannelOpenRequestHandler = ();
288 type HrmpChannelAcceptedHandler = ();
289 type HrmpChannelClosingHandler = ();
290 type XcmRecorder = PolkadotXcm;
291 type XcmEventEmitter = PolkadotXcm;
292}
293
294pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
296
297pub type XcmRouter = WithUniqueTopic<(
300 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
302 XcmpQueue,
304)>;
305
306pub type Weigher =
307 WeightInfoBounds<weights::xcm::XcmWeight<Runtime, RuntimeCall>, RuntimeCall, MaxInstructions>;
308
309impl pallet_xcm::Config for Runtime {
310 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
311
312 type RuntimeEvent = RuntimeEvent;
313 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
314 type XcmRouter = XcmRouter;
315 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
316 type XcmExecuteFilter = Nothing;
317 type XcmExecutor = XcmExecutor<XcmConfig>;
318 type XcmTeleportFilter = Nothing;
319 type XcmReserveTransferFilter = Everything;
320 type Weigher = Weigher;
321 type UniversalLocation = UniversalLocation;
322 type RuntimeOrigin = RuntimeOrigin;
323 type RuntimeCall = RuntimeCall;
324 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; type Currency = Balances;
327 type CurrencyMatcher = ();
328 type TrustedLockers = ();
329 type SovereignAccountOf = LocationToAccountId;
330 type MaxLockers = ConstU32<0>;
331 type WeightInfo = weights::pallet_xcm::SubstrateWeight<Runtime>;
332 type MaxRemoteLockConsumers = ConstU32<0>;
333 type RemoteLockConsumerIdentifier = ();
334 type AdminOrigin = EnsureRoot<AccountId>;
335 type AuthorizedAliasConsideration = Disabled;
336}
337
338impl cumulus_pallet_xcm::Config for Runtime {
339 type RuntimeEvent = RuntimeEvent;
340 type XcmExecutor = XcmExecutor<XcmConfig>;
341}
342
343impl cumulus_pallet_xcmp_queue::Config for Runtime {
344 type RuntimeEvent = RuntimeEvent;
345 type ChannelInfo = ParachainSystem;
346 type VersionWrapper = PolkadotXcm;
347 type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
348 type MaxInboundSuspended = ConstU32<1_000>;
349 type MaxActiveOutboundChannels = ConstU32<128>;
350 type MaxPageSize = ConstU32<{ 128 * 1024 }>;
351 type ControllerOrigin = EnsureRoot<AccountId>;
352 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
353 type PriceForSiblingDelivery = NoPriceForMessageDelivery<ParaId>;
354 type WeightInfo = cumulus_pallet_xcmp_queue::weights::SubstrateWeight<Runtime>;
355}