referrerpolicy=no-referrer-when-downgrade

xcm_docs/cookbook/relay_token_transactor/relay_chain/
xcm_config.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
3// This file is part of Polkadot.
4
5// Polkadot is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9
10// Polkadot is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13// GNU General Public License for more details.
14
15// You should have received a copy of the GNU General Public License
16// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
17
18//! Relay chain XCM configuration
19
20use frame::{
21	deps::frame_system,
22	runtime::prelude::*,
23	traits::{Disabled, Everything, Nothing},
24};
25use xcm::latest::prelude::*;
26use xcm_builder::{
27	AccountId32Aliases, DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin,
28	FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete,
29	SignedToAccountId32,
30};
31use xcm_executor::XcmExecutor;
32
33use super::{AccountId, Balances, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin};
34
35parameter_types! {
36	pub HereLocation: Location = Location::here();
37	pub ThisNetwork: NetworkId = NetworkId::Polkadot;
38}
39
40/// Converter from XCM Locations to accounts.
41/// This generates sovereign accounts for Locations and converts
42/// local AccountId32 junctions to local accounts.
43pub type LocationToAccountId = (
44	HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
45	AccountId32Aliases<ThisNetwork, AccountId>,
46);
47
48mod asset_transactor {
49	use super::*;
50
51	/// AssetTransactor for handling the Relay Chain token.
52	pub type FungibleTransactor = FungibleAdapter<
53		// Use this `fungible` implementation.
54		Balances,
55		// This transactor handles the native token.
56		IsConcrete<HereLocation>,
57		// How to convert an XCM Location into a local account id.
58		// Whenever assets are handled, the location is turned into an account.
59		// This account is the one where balances are withdrawn/deposited.
60		LocationToAccountId,
61		// The account id type, needed because `fungible` is generic over it.
62		AccountId,
63		// Not tracking teleports.
64		(),
65	>;
66
67	/// All asset transactors, in this case only one
68	pub type AssetTransactor = FungibleTransactor;
69}
70
71mod weigher {
72	use super::*;
73	use xcm_builder::FixedWeightBounds;
74
75	parameter_types! {
76		pub const WeightPerInstruction: Weight = Weight::from_parts(1, 1);
77		pub const MaxInstructions: u32 = 100;
78	}
79
80	pub type Weigher = FixedWeightBounds<WeightPerInstruction, RuntimeCall, MaxInstructions>;
81}
82
83parameter_types! {
84	pub UniversalLocation: InteriorLocation = [GlobalConsensus(NetworkId::Polkadot)].into();
85}
86
87pub struct XcmConfig;
88impl xcm_executor::Config for XcmConfig {
89	type RuntimeCall = RuntimeCall;
90	type XcmSender = ();
91	type XcmEventEmitter = ();
92	type AssetTransactor = asset_transactor::AssetTransactor;
93	type OriginConverter = ();
94	// We don't need to recognize anyone as a reserve
95	type IsReserve = ();
96	type IsTeleporter = ();
97	type UniversalLocation = UniversalLocation;
98	// This is not safe, you should use `xcm_builder::AllowTopLevelPaidExecutionFrom<T>` in a
99	// production chain
100	type Barrier = xcm_builder::AllowUnpaidExecutionFrom<Everything>;
101	type Weigher = weigher::Weigher;
102	type Trader = ();
103	type ResponseHandler = ();
104	type AssetTrap = ();
105	type AssetLocker = ();
106	type AssetExchanger = ();
107	type AssetClaims = ();
108	type SubscriptionService = ();
109	type PalletInstancesInfo = ();
110	type FeeManager = ();
111	type MaxAssetsIntoHolding = frame::traits::ConstU32<1>;
112	type MessageExporter = ();
113	type UniversalAliases = Nothing;
114	type CallDispatcher = RuntimeCall;
115	type SafeCallFilter = Everything;
116	type Aliasers = Nothing;
117	type TransactionalProcessor = FrameTransactionalProcessor;
118	type HrmpNewChannelOpenRequestHandler = ();
119	type HrmpChannelAcceptedHandler = ();
120	type HrmpChannelClosingHandler = ();
121	type XcmRecorder = ();
122}
123
124/// Converts a local signed origin into an XCM location. Forms the basis for local origins
125/// sending/executing XCMs.
126pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>;
127
128impl pallet_xcm::Config for Runtime {
129	// No one can call `send`
130	type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
131	type XcmRouter = super::super::network::RelayChainXcmRouter; // Provided by xcm-simulator
132															  // Anyone can execute XCM programs
133	type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
134	// We execute any type of program
135	type XcmExecuteFilter = Everything;
136	// How we execute programs
137	type XcmExecutor = XcmExecutor<XcmConfig>;
138	// We don't allow teleports
139	type XcmTeleportFilter = Nothing;
140	// We allow all reserve transfers.
141	// This is so it can act as a reserve for its native token.
142	type XcmReserveTransferFilter = Everything;
143	// Same weigher executor uses to weigh XCM programs
144	type Weigher = weigher::Weigher;
145	// Same universal location
146	type UniversalLocation = UniversalLocation;
147	// No version discovery needed
148	const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 0;
149	type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
150	type AdminOrigin = frame_system::EnsureRoot<AccountId>;
151	// No locking
152	type TrustedLockers = ();
153	type MaxLockers = frame::traits::ConstU32<0>;
154	type MaxRemoteLockConsumers = frame::traits::ConstU32<0>;
155	type RemoteLockConsumerIdentifier = ();
156	// How to turn locations into accounts
157	type SovereignAccountOf = LocationToAccountId;
158	// A currency to pay for things and its matcher, we are using the relay token
159	type Currency = Balances;
160	type CurrencyMatcher = IsConcrete<HereLocation>;
161	// Pallet benchmarks, no need for this example
162	type WeightInfo = pallet_xcm::TestWeightInfo;
163	// Runtime types
164	type RuntimeOrigin = RuntimeOrigin;
165	type RuntimeCall = RuntimeCall;
166	type RuntimeEvent = RuntimeEvent;
167	// Aliasing is disabled: xcm_executor::Config::Aliasers is set to `Nothing`.
168	type AuthorizedAliasConsideration = Disabled;
169}