referrerpolicy=no-referrer-when-downgrade

coretime_rococo_runtime/
xcm_config.rs

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