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;
32
33use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
35use frame_support::traits::{Disabled, TransformOrigin};
36use parachains_common::{
37 message_queue::ParaIdToSibling, xcm_config::ParentRelayOrSiblingParachains,
38};
39use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;
40use xcm::latest::prelude::*;
41use xcm_builder::{
42 Account32Hash, AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
43 AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, ConvertedConcreteId, EnsureXcmOrigin,
44 FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, IsConcrete, NoChecking,
45 ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
46 SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
47 SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
48 WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
49};
50use xcm_executor::{
51 traits::{JustTry, WithOriginFilter},
52 XcmExecutor,
53};
54
55use astar_primitives::xcm::{FixedRateOfForeignAsset, ReserveAssetFilter, XcmFungibleFeeHandler};
57
58parameter_types! {
59 pub RelayNetwork: Option<NetworkId> = Some(NetworkId::Polkadot);
60 pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
61 pub UniversalLocation: InteriorLocation =
62 [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into();
63 pub AstarLocation: Location = Here.into_location();
64 pub DummyCheckingAccount: AccountId = PolkadotXcm::check_account();
65 pub TreasuryLocation: Location = Junction::AccountId32 { network: None, id: TreasuryAccountId::get().into() }.into();
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 {
161 match call {
162 RuntimeCall::System(..)
163 | RuntimeCall::Identity(..)
164 | RuntimeCall::Balances(..)
165 | RuntimeCall::Vesting(..)
166 | RuntimeCall::DappStaking(..)
167 | RuntimeCall::Assets(..)
168 | RuntimeCall::Session(..)
169 | RuntimeCall::Proxy(
170 pallet_proxy::Call::add_proxy { .. }
171 | pallet_proxy::Call::remove_proxy { .. }
172 | pallet_proxy::Call::remove_proxies { .. }
173 | pallet_proxy::Call::create_pure { .. }
174 | pallet_proxy::Call::kill_pure { .. }
175 | pallet_proxy::Call::announce { .. }
176 | pallet_proxy::Call::remove_announcement { .. }
177 | pallet_proxy::Call::reject_announcement { .. },
178 )
179 | RuntimeCall::Multisig(
180 pallet_multisig::Call::approve_as_multi { .. }
181 | pallet_multisig::Call::cancel_as_multi { .. },
182 ) => true,
183 RuntimeCall::PolkadotXcm(call) => !matches!(
184 call,
185 pallet_xcm::Call::send { .. } | pallet_xcm::Call::execute { .. }
186 ),
187 _ => false,
188 }
189 }
190 pub fn allow_composite_call(call: &RuntimeCall) -> bool {
194 match call {
195 RuntimeCall::Proxy(pallet_proxy::Call::proxy { call, .. }) => {
196 Self::allow_base_call(call)
197 }
198 RuntimeCall::Proxy(pallet_proxy::Call::proxy_announced { call, .. }) => {
199 Self::allow_base_call(call)
200 }
201 RuntimeCall::Utility(pallet_utility::Call::batch { calls, .. }) => {
202 calls.iter().all(|call| Self::allow_base_call(call))
203 }
204 RuntimeCall::Utility(pallet_utility::Call::batch_all { calls, .. }) => {
205 calls.iter().all(|call| Self::allow_base_call(call))
206 }
207 RuntimeCall::Utility(pallet_utility::Call::as_derivative { call, .. }) => {
208 Self::allow_base_call(call)
209 }
210 RuntimeCall::Multisig(pallet_multisig::Call::as_multi_threshold_1 { call, .. }) => {
211 Self::allow_base_call(call)
212 }
213 RuntimeCall::Multisig(pallet_multisig::Call::as_multi { call, .. }) => {
214 Self::allow_base_call(call)
215 }
216 _ => false,
217 }
218 }
219}
220
221impl Contains<RuntimeCall> for SafeCallFilter {
222 fn contains(call: &RuntimeCall) -> bool {
223 Self::allow_base_call(call) || Self::allow_composite_call(call)
224 }
225}
226
227pub type XcmBarrier = TrailingSetTopicAsId<(
228 TakeWeightCredit,
229 AllowKnownQueryResponses<PolkadotXcm>,
231 WithComputedOrigin<
233 (
234 AllowTopLevelPaidExecutionFrom<Everything>,
236 AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
238 ),
239 UniversalLocation,
240 ConstU32<8>,
241 >,
242 AllowUnpaidExecutionFrom<ParentOrParentsPlurality>,
244)>;
245
246pub type AstarXcmFungibleFeeHandler = XcmFungibleFeeHandler<AssetTransactors, TreasuryLocation>;
248
249pub struct XcmConfig;
250impl xcm_executor::Config for XcmConfig {
251 type RuntimeCall = RuntimeCall;
252 type XcmSender = XcmRouter;
253 type AssetTransactor = AssetTransactors;
254 type OriginConverter = XcmOriginToTransactDispatchOrigin;
255 type IsReserve = ReserveAssetFilter;
256 type IsTeleporter = ();
257 type UniversalLocation = UniversalLocation;
258 type Barrier = XcmBarrier;
259 type Weigher = Weigher;
260 type Trader = (
261 UsingComponents<XcmWeightToFee, AstarLocation, AccountId, Balances, DealWithFees>,
262 FixedRateOfForeignAsset<XcAssetConfig, AstarXcmFungibleFeeHandler>,
263 );
264 type ResponseHandler = PolkadotXcm;
265 type AssetTrap = PolkadotXcm;
266 type SubscriptionService = PolkadotXcm;
267
268 type PalletInstancesInfo = AllPalletsWithSystem;
269 type MaxAssetsIntoHolding = ConstU32<64>;
270 type AssetLocker = ();
271 type AssetExchanger = ();
272 type FeeManager = ();
273 type MessageExporter = ();
274 type UniversalAliases = Nothing;
275 type CallDispatcher = WithOriginFilter<SafeCallFilter>;
276 type SafeCallFilter = SafeCallFilter;
277 type Aliasers = Nothing;
278 type TransactionalProcessor = FrameTransactionalProcessor;
279
280 type HrmpNewChannelOpenRequestHandler = ();
281 type HrmpChannelAcceptedHandler = ();
282 type HrmpChannelClosingHandler = ();
283 type XcmRecorder = PolkadotXcm;
284 type XcmEventEmitter = PolkadotXcm;
285}
286
287pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
289
290pub type XcmRouter = WithUniqueTopic<(
293 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
295 XcmpQueue,
297)>;
298
299pub type Weigher =
300 WeightInfoBounds<weights::xcm::XcmWeight<Runtime, RuntimeCall>, RuntimeCall, MaxInstructions>;
301
302impl pallet_xcm::Config for Runtime {
303 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
304
305 type RuntimeEvent = RuntimeEvent;
306 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
307 type XcmRouter = XcmRouter;
308 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
309 type XcmExecuteFilter = Nothing;
310 type XcmExecutor = XcmExecutor<XcmConfig>;
311 type XcmTeleportFilter = Nothing;
312 type XcmReserveTransferFilter = Everything;
313 type Weigher = Weigher;
314 type UniversalLocation = UniversalLocation;
315 type RuntimeOrigin = RuntimeOrigin;
316 type RuntimeCall = RuntimeCall;
317 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; type Currency = Balances;
320 type CurrencyMatcher = ();
321 type TrustedLockers = ();
322 type SovereignAccountOf = LocationToAccountId;
323 type MaxLockers = ConstU32<0>;
324 type WeightInfo = weights::pallet_xcm::SubstrateWeight<Runtime>;
325 type MaxRemoteLockConsumers = ConstU32<0>;
326 type RemoteLockConsumerIdentifier = ();
327 type AdminOrigin = EnsureRoot<AccountId>;
328 type AuthorizedAliasConsideration = Disabled;
329}
330
331impl cumulus_pallet_xcm::Config for Runtime {
332 type RuntimeEvent = RuntimeEvent;
333 type XcmExecutor = XcmExecutor<XcmConfig>;
334}
335
336impl cumulus_pallet_xcmp_queue::Config for Runtime {
337 type RuntimeEvent = RuntimeEvent;
338 type ChannelInfo = ParachainSystem;
339 type VersionWrapper = PolkadotXcm;
340 type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
341 type MaxInboundSuspended = ConstU32<1_000>;
342 type MaxActiveOutboundChannels = ConstU32<128>;
343 type MaxPageSize = ConstU32<{ 128 * 1024 }>;
344 type ControllerOrigin = EnsureRoot<AccountId>;
345 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
346 type PriceForSiblingDelivery = NoPriceForMessageDelivery<ParaId>;
347 type WeightInfo = cumulus_pallet_xcmp_queue::weights::SubstrateWeight<Runtime>;
348}