shell_runtime/
xcm_config.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// 	http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use super::{
17	AccountId, AllPalletsWithSystem, ParachainInfo, Runtime, RuntimeCall, RuntimeEvent,
18	RuntimeOrigin,
19};
20use frame_support::{
21	parameter_types,
22	traits::{Contains, Everything, Nothing},
23	weights::Weight,
24};
25use xcm::latest::prelude::*;
26use xcm_builder::{
27	AllowExplicitUnpaidExecutionFrom, FixedWeightBounds, ParentAsSuperuser, ParentIsPreset,
28	SovereignSignedViaLocation,
29};
30
31parameter_types! {
32	pub const RococoLocation: Location = Location::parent();
33	pub const RococoNetwork: NetworkId = NetworkId::Rococo;
34	pub UniversalLocation: InteriorLocation = [GlobalConsensus(RococoNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into();
35}
36
37/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
38/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can
39/// bias the kind of local `Origin` it will become.
40pub type XcmOriginToTransactDispatchOrigin = (
41	// Sovereign account converter; this attempts to derive an `AccountId` from the origin location
42	// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for
43	// foreign chains who want to have a local sovereign account on this chain which they control.
44	SovereignSignedViaLocation<ParentIsPreset<AccountId>, RuntimeOrigin>,
45	// Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a
46	// transaction from the Root origin.
47	ParentAsSuperuser<RuntimeOrigin>,
48);
49
50pub struct JustTheParent;
51impl Contains<Location> for JustTheParent {
52	fn contains(location: &Location) -> bool {
53		matches!(location.unpack(), (1, []))
54	}
55}
56
57parameter_types! {
58	// One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate.
59	pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024);
60	pub const MaxInstructions: u32 = 100;
61	pub const MaxAssetsIntoHolding: u32 = 64;
62}
63
64pub struct XcmConfig;
65impl xcm_executor::Config for XcmConfig {
66	type RuntimeCall = RuntimeCall;
67	type XcmSender = (); // sending XCM not supported
68	type AssetTransactor = (); // balances not supported
69	type OriginConverter = XcmOriginToTransactDispatchOrigin;
70	type IsReserve = (); // balances not supported
71	type IsTeleporter = (); // balances not supported
72	type UniversalLocation = UniversalLocation;
73	type Barrier = AllowExplicitUnpaidExecutionFrom<JustTheParent>;
74	type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>; // balances not supported
75	type Trader = (); // balances not supported
76	type ResponseHandler = (); // Don't handle responses for now.
77	type AssetTrap = (); // don't trap for now
78	type AssetClaims = (); // don't claim for now
79	type SubscriptionService = (); // don't handle subscriptions for now
80	type PalletInstancesInfo = AllPalletsWithSystem;
81	type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
82	type AssetLocker = ();
83	type AssetExchanger = ();
84	type FeeManager = ();
85	type MessageExporter = ();
86	type UniversalAliases = Nothing;
87	type CallDispatcher = RuntimeCall;
88	type SafeCallFilter = Everything;
89	type Aliasers = Nothing;
90	type TransactionalProcessor = ();
91	type HrmpNewChannelOpenRequestHandler = ();
92	type HrmpChannelAcceptedHandler = ();
93	type HrmpChannelClosingHandler = ();
94	type XcmRecorder = ();
95}
96
97impl cumulus_pallet_xcm::Config for Runtime {
98	type RuntimeEvent = RuntimeEvent;
99	type XcmExecutor = xcm_executor::XcmExecutor<XcmConfig>;
100}