referrerpolicy=no-referrer-when-downgrade

people_rococo_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, Balances, ParachainInfo, ParachainSystem, PolkadotXcm,
18	Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue,
19};
20use crate::{TransactionByteFee, CENTS};
21use frame_support::{
22	parameter_types,
23	traits::{
24		tokens::imbalance::ResolveTo, ConstU32, Contains, Disabled, Equals, Everything, Nothing,
25	},
26};
27use frame_system::EnsureRoot;
28use pallet_collator_selection::StakingPotAccountId;
29use pallet_xcm::XcmPassthrough;
30use parachains_common::{
31	xcm_config::{
32		AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains,
33		RelayOrOtherSystemParachains,
34	},
35	TREASURY_PALLET_ID,
36};
37use polkadot_parachain_primitives::primitives::Sibling;
38use sp_runtime::traits::AccountIdConversion;
39use xcm::latest::{prelude::*, ROCOCO_GENESIS_HASH};
40use xcm_builder::{
41	AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain,
42	AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
43	DenyRecursively, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal,
44	DescribeFamily, DescribeTerminus, EnsureXcmOrigin, FrameTransactionalProcessor,
45	FungibleAdapter, HashedDescription, IsConcrete, ParentAsSuperuser, ParentIsPreset,
46	RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia,
47	SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
48	TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
49	XcmFeeManagerFromComponents,
50};
51use xcm_executor::XcmExecutor;
52
53parameter_types! {
54	pub const RootLocation: Location = Location::here();
55	pub const RelayLocation: Location = Location::parent();
56	pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::ByGenesis(ROCOCO_GENESIS_HASH));
57	pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
58	pub UniversalLocation: InteriorLocation =
59		[GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into();
60	pub const MaxInstructions: u32 = 100;
61	pub const MaxAssetsIntoHolding: u32 = 64;
62	pub const GovernanceLocation: Location = Location::parent();
63	pub const FellowshipLocation: Location = Location::parent();
64	/// The asset ID for the asset that we use to pay for message delivery fees. Just ROC.
65	pub FeeAssetId: AssetId = AssetId(RelayLocation::get());
66	/// The base fee for the message delivery fees.
67	pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
68	pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
69	pub RelayTreasuryLocation: Location =
70		(Parent, PalletInstance(rococo_runtime_constants::TREASURY_PALLET_ID)).into();
71}
72
73pub type PriceForParentDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice<
74	FeeAssetId,
75	BaseDeliveryFee,
76	TransactionByteFee,
77	ParachainSystem,
78>;
79
80pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice<
81	FeeAssetId,
82	BaseDeliveryFee,
83	TransactionByteFee,
84	XcmpQueue,
85>;
86
87/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used
88/// when determining ownership of accounts for asset transacting and when attempting to use XCM
89/// `Transact` in order to determine the dispatch Origin.
90pub type LocationToAccountId = (
91	// The parent (Relay-chain) origin converts to the parent `AccountId`.
92	ParentIsPreset<AccountId>,
93	// Sibling parachain origins convert to AccountId via the `ParaId::into`.
94	SiblingParachainConvertsVia<Sibling, AccountId>,
95	// Straight up local `AccountId32` origins just alias directly to `AccountId`.
96	AccountId32Aliases<RelayNetwork, AccountId>,
97	// Here/local root location to `AccountId`.
98	HashedDescription<AccountId, DescribeTerminus>,
99	// Foreign locations alias into accounts according to a hash of their standard description.
100	HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
101);
102
103/// Means for transacting the native currency on this chain.
104pub type FungibleTransactor = FungibleAdapter<
105	// Use this currency:
106	Balances,
107	// Use this currency when it is a fungible asset matching the given location or name:
108	IsConcrete<RelayLocation>,
109	// Do a simple punn to convert an `AccountId32` `Location` into a native chain
110	// `AccountId`:
111	LocationToAccountId,
112	// Our chain's `AccountId` type (we can't get away without mentioning it explicitly):
113	AccountId,
114	// We don't track any teleports of `Balances`.
115	(),
116>;
117
118/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
119/// ready for dispatching a transaction with XCM's `Transact`. There is an `OriginKind` that can
120/// bias the kind of local `Origin` it will become.
121pub type XcmOriginToTransactDispatchOrigin = (
122	// Sovereign account converter; this attempts to derive an `AccountId` from the origin location
123	// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for
124	// foreign chains who want to have a local sovereign account on this chain that they control.
125	SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
126	// Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when
127	// recognized.
128	RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
129	// Native converter for sibling Parachains; will convert to a `SiblingPara` origin when
130	// recognized.
131	SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
132	// Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a
133	// transaction from the Root origin.
134	ParentAsSuperuser<RuntimeOrigin>,
135	// Native signed account converter; this just converts an `AccountId32` origin into a normal
136	// `RuntimeOrigin::Signed` origin of the same 32-byte value.
137	SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
138	// XCM origins can be represented natively under the XCM pallet's `Xcm` origin.
139	XcmPassthrough<RuntimeOrigin>,
140);
141
142pub struct LocalPlurality;
143impl Contains<Location> for LocalPlurality {
144	fn contains(location: &Location) -> bool {
145		matches!(location.unpack(), (0, [Plurality { .. }]))
146	}
147}
148
149pub struct ParentOrParentsPlurality;
150impl Contains<Location> for ParentOrParentsPlurality {
151	fn contains(location: &Location) -> bool {
152		matches!(location.unpack(), (1, []) | (1, [Plurality { .. }]))
153	}
154}
155
156pub type Barrier = TrailingSetTopicAsId<
157	DenyThenTry<
158		DenyRecursively<DenyReserveTransferToRelayChain>,
159		(
160			// Allow local users to buy weight credit.
161			TakeWeightCredit,
162			// Expected responses are OK.
163			AllowKnownQueryResponses<PolkadotXcm>,
164			WithComputedOrigin<
165				(
166					// If the message is one that immediately attempts to pay for execution, then
167					// allow it.
168					AllowTopLevelPaidExecutionFrom<Everything>,
169					// Parent and its pluralities (i.e. governance bodies) get free execution.
170					AllowExplicitUnpaidExecutionFrom<ParentOrParentsPlurality>,
171					// Subscriptions for version tracking are OK.
172					AllowSubscriptionsFrom<ParentRelayOrSiblingParachains>,
173					// HRMP notifications from the relay chain are OK.
174					AllowHrmpNotificationsFromRelayChain,
175				),
176				UniversalLocation,
177				ConstU32<8>,
178			>,
179		),
180	>,
181>;
182
183/// Locations that will not be charged fees in the executor, neither for execution nor delivery. We
184/// only waive fees for system functions, which these locations represent.
185pub type WaivedLocations = (
186	RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
187	Equals<RelayTreasuryLocation>,
188	Equals<RootLocation>,
189	LocalPlurality,
190);
191
192pub struct XcmConfig;
193impl xcm_executor::Config for XcmConfig {
194	type RuntimeCall = RuntimeCall;
195	type XcmSender = XcmRouter;
196	type XcmEventEmitter = PolkadotXcm;
197	type AssetTransactor = FungibleTransactor;
198	type OriginConverter = XcmOriginToTransactDispatchOrigin;
199	// People chain does not recognize a reserve location for any asset. Users must teleport ROC
200	// where allowed (e.g. with the Relay Chain).
201	type IsReserve = ();
202	/// Only allow teleportation of ROC.
203	type IsTeleporter = ConcreteAssetFromSystem<RelayLocation>;
204	type UniversalLocation = UniversalLocation;
205	type Barrier = Barrier;
206	type Weigher = WeightInfoBounds<
207		crate::weights::xcm::PeopleRococoXcmWeight<RuntimeCall>,
208		RuntimeCall,
209		MaxInstructions,
210	>;
211	type Trader = UsingComponents<
212		WeightToFee,
213		RelayLocation,
214		AccountId,
215		Balances,
216		ResolveTo<StakingPotAccountId<Runtime>, Balances>,
217	>;
218	type ResponseHandler = PolkadotXcm;
219	type AssetTrap = PolkadotXcm;
220	type AssetClaims = PolkadotXcm;
221	type SubscriptionService = PolkadotXcm;
222	type PalletInstancesInfo = AllPalletsWithSystem;
223	type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
224	type AssetLocker = ();
225	type AssetExchanger = ();
226	type FeeManager = XcmFeeManagerFromComponents<
227		WaivedLocations,
228		SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
229	>;
230	type MessageExporter = ();
231	type UniversalAliases = Nothing;
232	type CallDispatcher = RuntimeCall;
233	type SafeCallFilter = Everything;
234	type Aliasers = Nothing;
235	type TransactionalProcessor = FrameTransactionalProcessor;
236	type HrmpNewChannelOpenRequestHandler = ();
237	type HrmpChannelAcceptedHandler = ();
238	type HrmpChannelClosingHandler = ();
239	type XcmRecorder = PolkadotXcm;
240}
241
242/// Converts a local signed origin into an XCM location. Forms the basis for local origins
243/// sending/executing XCMs.
244pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
245
246/// The means for routing XCM messages which are not for local execution into the right message
247/// queues.
248pub type XcmRouter = WithUniqueTopic<(
249	// Two routers - use UMP to communicate with the relay chain:
250	cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
251	// ..and XCMP to communicate with the sibling chains.
252	XcmpQueue,
253)>;
254
255impl pallet_xcm::Config for Runtime {
256	type RuntimeEvent = RuntimeEvent;
257	// We want to disallow users sending (arbitrary) XCM programs from this chain.
258	type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
259	type XcmRouter = XcmRouter;
260	// We support local origins dispatching XCM executions.
261	type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
262	type XcmExecuteFilter = Everything;
263	type XcmExecutor = XcmExecutor<XcmConfig>;
264	type XcmTeleportFilter = Everything;
265	type XcmReserveTransferFilter = Nothing; // This parachain is not meant as a reserve location.
266	type Weigher = WeightInfoBounds<
267		crate::weights::xcm::PeopleRococoXcmWeight<RuntimeCall>,
268		RuntimeCall,
269		MaxInstructions,
270	>;
271	type UniversalLocation = UniversalLocation;
272	type RuntimeOrigin = RuntimeOrigin;
273	type RuntimeCall = RuntimeCall;
274	const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
275	type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
276	type Currency = Balances;
277	type CurrencyMatcher = ();
278	type TrustedLockers = ();
279	type SovereignAccountOf = LocationToAccountId;
280	type MaxLockers = ConstU32<8>;
281	type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
282	type AdminOrigin = EnsureRoot<AccountId>;
283	type MaxRemoteLockConsumers = ConstU32<0>;
284	type RemoteLockConsumerIdentifier = ();
285	// Aliasing is disabled: xcm_executor::Config::Aliasers is set to `Nothing`.
286	type AuthorizedAliasConsideration = Disabled;
287}
288
289impl cumulus_pallet_xcm::Config for Runtime {
290	type RuntimeEvent = RuntimeEvent;
291	type XcmExecutor = XcmExecutor<XcmConfig>;
292}