1use super::{
20 AccountId, AllPalletsWithSystem, AssetId, Assets, Balance, Balances, DealWithFees,
21 MessageQueue, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent,
22 RuntimeOrigin, ShibuyaAssetLocationIdConverter, TreasuryAccountId, XcAssetConfig,
23 XcmWeightToFee, 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::*, v5::ROCOCO_GENESIS_HASH};
42use xcm_builder::{
43 AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowUnpaidExecutionFrom,
44 ConvertedConcreteId, DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin,
45 FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, HashedDescription, IsConcrete,
46 NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
47 SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
48 SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
49 WeightInfoBounds, WithComputedOrigin,
50};
51use xcm_executor::{traits::JustTry, XcmExecutor};
52
53use orml_xcm_support::DisabledParachainFee;
55
56use astar_primitives::xcm::{
58 AbsoluteAndRelativeReserveProvider, AccountIdToMultiLocation, AllowTopLevelPaidExecutionFrom,
59 FixedRateOfForeignAsset, ReserveAssetFilter, XcmFungibleFeeHandler, MAX_ASSETS,
60};
61
62parameter_types! {
63 pub RelayNetwork: Option<NetworkId> = Some(NetworkId::ByGenesis(ROCOCO_GENESIS_HASH));
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 const ShibuyaLocation: 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 HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
84);
85
86pub type CurrencyTransactor = FungibleAdapter<
88 Balances,
90 IsConcrete<ShibuyaLocation>,
92 LocationToAccountId,
94 AccountId,
96 (),
98>;
99
100pub type FungiblesTransactor = FungiblesAdapter<
102 Assets,
104 ConvertedConcreteId<AssetId, Balance, ShibuyaAssetLocationIdConverter, JustTry>,
106 LocationToAccountId,
108 AccountId,
110 NoChecking,
112 DummyCheckingAccount,
114>;
115
116pub type AssetTransactors = (CurrencyTransactor, FungiblesTransactor);
118
119pub type XcmOriginToTransactDispatchOrigin = (
123 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
127 RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
130 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
133 ParentAsSuperuser<RuntimeOrigin>,
136 pallet_xcm::XcmPassthrough<RuntimeOrigin>,
138 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
141);
142
143parameter_types! {
144 pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 4 * 1024);
147 pub const MaxInstructions: u32 = 100;
148 pub const MaxAssetsIntoHolding: u32 = MAX_ASSETS as u32;
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 type XcmBarrier = TrailingSetTopicAsId<(
159 TakeWeightCredit,
160 AllowKnownQueryResponses<PolkadotXcm>,
162 WithComputedOrigin<
164 (
165 AllowTopLevelPaidExecutionFrom<Everything>,
167 AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
169 ),
170 UniversalLocation,
171 ConstU32<8>,
172 >,
173 AllowUnpaidExecutionFrom<ParentOrParentsPlurality>,
175)>;
176
177pub type ShibuyaXcmFungibleFeeHandler = XcmFungibleFeeHandler<
179 AccountId,
180 ConvertedConcreteId<AssetId, Balance, ShibuyaAssetLocationIdConverter, JustTry>,
181 Assets,
182 TreasuryAccountId,
183>;
184
185pub type Weigher =
186 WeightInfoBounds<weights::xcm::XcmWeight<Runtime, RuntimeCall>, RuntimeCall, MaxInstructions>;
187
188pub struct XcmConfig;
189impl xcm_executor::Config for XcmConfig {
190 type RuntimeCall = RuntimeCall;
191 type XcmSender = XcmRouter;
192 type AssetTransactor = AssetTransactors;
193 type OriginConverter = XcmOriginToTransactDispatchOrigin;
194 type IsReserve = ReserveAssetFilter;
195 type IsTeleporter = ();
196 type UniversalLocation = UniversalLocation;
197 type Barrier = XcmBarrier;
198 type Weigher = Weigher;
199 type Trader = (
200 UsingComponents<XcmWeightToFee, ShibuyaLocation, AccountId, Balances, DealWithFees>,
201 FixedRateOfForeignAsset<XcAssetConfig, ShibuyaXcmFungibleFeeHandler>,
202 );
203 type ResponseHandler = PolkadotXcm;
204 type AssetTrap = PolkadotXcm;
205 type AssetClaims = PolkadotXcm;
206 type SubscriptionService = PolkadotXcm;
207
208 type PalletInstancesInfo = AllPalletsWithSystem;
209 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
210 type AssetLocker = ();
211 type AssetExchanger = ();
212 type FeeManager = ();
213 type MessageExporter = ();
214 type UniversalAliases = Nothing;
215 type CallDispatcher = RuntimeCall;
216 type SafeCallFilter = Everything;
217 type Aliasers = Nothing;
218 type TransactionalProcessor = FrameTransactionalProcessor;
219
220 type HrmpNewChannelOpenRequestHandler = ();
221 type HrmpChannelAcceptedHandler = ();
222 type HrmpChannelClosingHandler = ();
223 type XcmRecorder = PolkadotXcm;
224 type XcmEventEmitter = PolkadotXcm;
225}
226
227pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
229
230pub type XcmRouter = (
233 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
235 XcmpQueue,
237);
238
239impl pallet_xcm::Config for Runtime {
240 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
241
242 type RuntimeEvent = RuntimeEvent;
243 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
244 type XcmRouter = XcmRouter;
245 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
246 type XcmExecuteFilter = Nothing;
247 type XcmExecutor = XcmExecutor<XcmConfig>;
248 type XcmTeleportFilter = Nothing;
249 type XcmReserveTransferFilter = Everything;
250 type Weigher = Weigher;
251 type UniversalLocation = UniversalLocation;
252 type RuntimeOrigin = RuntimeOrigin;
253 type RuntimeCall = RuntimeCall;
254 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
255 type Currency = Balances;
256 type CurrencyMatcher = ();
257 type TrustedLockers = ();
258 type SovereignAccountOf = LocationToAccountId;
259 type MaxLockers = ConstU32<0>;
260 type WeightInfo = weights::pallet_xcm::SubstrateWeight<Runtime>;
261 type MaxRemoteLockConsumers = ConstU32<0>;
262 type RemoteLockConsumerIdentifier = ();
263 type AdminOrigin = EnsureRoot<AccountId>;
264 type AuthorizedAliasConsideration = Disabled;
265}
266
267impl cumulus_pallet_xcm::Config for Runtime {
268 type RuntimeEvent = RuntimeEvent;
269 type XcmExecutor = XcmExecutor<XcmConfig>;
270}
271
272impl cumulus_pallet_xcmp_queue::Config for Runtime {
273 type RuntimeEvent = RuntimeEvent;
274 type ChannelInfo = ParachainSystem;
275 type VersionWrapper = PolkadotXcm;
276 type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
277 type MaxInboundSuspended = ConstU32<1_000>;
278 type MaxActiveOutboundChannels = ConstU32<128>;
279 type MaxPageSize = ConstU32<{ 128 * 1024 }>;
280 type ControllerOrigin = EnsureRoot<AccountId>;
281 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
282 type PriceForSiblingDelivery = NoPriceForMessageDelivery<ParaId>;
283 type WeightInfo = cumulus_pallet_xcmp_queue::weights::SubstrateWeight<Runtime>;
284}
285
286parameter_types! {
287 pub ShibuyaLocationAbsolute: Location = Location {
289 parents: 1,
290 interior: Parachain(ParachainInfo::parachain_id().into()).into()
291
292 };
293 pub const MaxAssetsForTransfer: usize = 2;
296}
297
298pub struct AssetIdConvert;
301impl Convert<AssetId, Option<Location>> for AssetIdConvert {
302 fn convert(asset_id: AssetId) -> Option<Location> {
303 ShibuyaAssetLocationIdConverter::convert_back(&asset_id)
304 }
305}
306
307impl orml_xtokens::Config for Runtime {
308 type Balance = Balance;
309 type CurrencyId = AssetId;
310 type CurrencyIdConvert = AssetIdConvert;
311 type AccountIdToLocation = AccountIdToMultiLocation;
312 type SelfLocation = ShibuyaLocation;
313 type XcmExecutor = XcmExecutor<XcmConfig>;
314 type Weigher = Weigher;
315 type BaseXcmWeight = UnitWeightCost;
316 type UniversalLocation = UniversalLocation;
317 type MaxAssetsForTransfer = MaxAssetsForTransfer;
318 type MinXcmFee = DisabledParachainFee;
320 type LocationsFilter = Everything;
321 type ReserveProvider = AbsoluteAndRelativeReserveProvider<ShibuyaLocationAbsolute>;
322 type RateLimiter = ();
323 type RateLimiterId = ();
324}