referrerpolicy=no-referrer-when-downgrade

glutton_westend_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, Equals, Everything, Nothing},
23	weights::Weight,
24};
25use xcm::latest::{prelude::*, WESTEND_GENESIS_HASH};
26use xcm_builder::{
27	AllowExplicitUnpaidExecutionFrom, FixedWeightBounds, FrameTransactionalProcessor,
28	LocationAsSuperuser, ParentAsSuperuser, ParentIsPreset, SovereignSignedViaLocation,
29};
30
31// Re-export
32pub use testnet_parachains_constants::westend::locations::GovernanceLocation;
33
34parameter_types! {
35	pub const WestendLocation: Location = Location::parent();
36	pub const WestendNetwork: NetworkId = NetworkId::ByGenesis(WESTEND_GENESIS_HASH);
37	pub UniversalLocation: InteriorLocation = [GlobalConsensus(WestendNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into();
38}
39
40/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
41/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can
42/// bias the kind of local `Origin` it will become.
43pub type XcmOriginToTransactDispatchOrigin = (
44	// Governance location can gain root.
45	LocationAsSuperuser<Equals<GovernanceLocation>, RuntimeOrigin>,
46	// Sovereign account converter; this attempts to derive an `AccountId` from the origin location
47	// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for
48	// foreign chains who want to have a local sovereign account on this chain which they control.
49	SovereignSignedViaLocation<ParentIsPreset<AccountId>, RuntimeOrigin>,
50	// Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a
51	// transaction from the Root origin.
52	ParentAsSuperuser<RuntimeOrigin>,
53);
54
55pub struct JustTheParent;
56impl Contains<Location> for JustTheParent {
57	fn contains(location: &Location) -> bool {
58		matches!(location.unpack(), (1, []))
59	}
60}
61
62parameter_types! {
63	// One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate.
64	pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024);
65	pub const MaxInstructions: u32 = 100;
66	pub const MaxAssetsIntoHolding: u32 = 64;
67}
68
69pub struct XcmConfig;
70impl xcm_executor::Config for XcmConfig {
71	type RuntimeCall = RuntimeCall;
72	type XcmSender = (); // sending XCM not supported
73	type XcmEventEmitter = ();
74	type AssetTransactor = (); // balances not supported
75	type OriginConverter = XcmOriginToTransactDispatchOrigin;
76	type IsReserve = (); // balances not supported
77	type IsTeleporter = (); // balances not supported
78	type UniversalLocation = UniversalLocation;
79	type Barrier = AllowExplicitUnpaidExecutionFrom<(JustTheParent, Equals<GovernanceLocation>)>;
80	type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>; // balances not supported
81	type Trader = (); // balances not supported
82	type ResponseHandler = (); // Don't handle responses for now.
83	type AssetTrap = (); // don't trap for now
84	type AssetClaims = (); // don't claim for now
85	type SubscriptionService = (); // don't handle subscriptions for now
86	type PalletInstancesInfo = AllPalletsWithSystem;
87	type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
88	type AssetLocker = ();
89	type AssetExchanger = ();
90	type FeeManager = ();
91	type MessageExporter = ();
92	type UniversalAliases = Nothing;
93	type CallDispatcher = RuntimeCall;
94	type SafeCallFilter = Everything;
95	type Aliasers = Nothing;
96	type TransactionalProcessor = FrameTransactionalProcessor;
97	type HrmpNewChannelOpenRequestHandler = ();
98	type HrmpChannelAcceptedHandler = ();
99	type HrmpChannelClosingHandler = ();
100	type XcmRecorder = ();
101}
102
103impl cumulus_pallet_xcm::Config for Runtime {
104	type RuntimeEvent = RuntimeEvent;
105	type XcmExecutor = xcm_executor::XcmExecutor<XcmConfig>;
106}