git.delta.rocks / unique-network / refs/commits / e2c10c5a7525

difftreelog

source

runtime/common/config/xcm.rs9.5 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use cumulus_primitives_core::ParaId;18use frame_support::{19	parameter_types,20	traits::{ConstU32, Everything, Get, Nothing, ProcessMessageError},21};22use frame_system::EnsureRoot;23use orml_traits::location::AbsoluteReserveProvider;24use orml_xcm_support::MultiNativeAsset;25use pallet_foreign_assets::FreeForAll;26use pallet_xcm::XcmPassthrough;27use polkadot_parachain_primitives::primitives::Sibling;28use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;29use sp_std::marker::PhantomData;30use staging_xcm::{31	latest::{prelude::*, MultiLocation, Weight},32	v3::Instruction,33};34use staging_xcm_builder::{35	AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, ParentIsPreset, RelayChainAsNative,36	SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,37	SignedToAccountId32, SovereignSignedViaLocation,38};39use staging_xcm_executor::{40	traits::{Properties, ShouldExecute},41	XcmExecutor,42};43use up_common::types::AccountId;4445#[cfg(feature = "governance")]46use crate::runtime_common::config::governance;47use crate::{48	xcm_barrier::Barrier, AllPalletsWithSystem, Balances, ForeignAssets, ParachainInfo,49	ParachainSystem, PolkadotXcm, RelayNetwork, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,50	XcmpQueue,51};5253parameter_types! {54	pub const RelayLocation: MultiLocation = MultiLocation::parent();55	pub RelayOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();56	pub UniversalLocation: InteriorMultiLocation = (57		GlobalConsensus(crate::RelayNetwork::get()),58		Parachain(ParachainInfo::get().into()),59	).into();60	pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));6162	// One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.63	pub UnitWeightCost: Weight = Weight::from_parts(1_000_000, 1000); // ?64	pub const MaxInstructions: u32 = 100;65}6667/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used68/// when determining ownership of accounts for asset transacting and when attempting to use XCM69/// `Transact` in order to determine the dispatch Origin.70pub type LocationToAccountId = (71	// The parent (Relay-chain) origin converts to the default `AccountId`.72	ParentIsPreset<AccountId>,73	// Sibling parachain origins convert to AccountId via the `ParaId::into`.74	SiblingParachainConvertsVia<Sibling, AccountId>,75	// Straight up local `AccountId32` origins just alias directly to `AccountId`.76	AccountId32Aliases<RelayNetwork, AccountId>,77);7879/// No local origins on this chain are allowed to dispatch XCM sends/executions.80pub type LocalOriginToLocation = (SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>,);8182/// The means for routing XCM messages which are not for local execution into the right message83/// queues.84pub type XcmRouter = (85	// Two routers - use UMP to communicate with the relay chain:86	cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,87	// ..and XCMP to communicate with the sibling chains.88	XcmpQueue,89);9091/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,92/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can93/// biases the kind of local `Origin` it will become.94pub type XcmOriginToTransactDispatchOrigin = (95	// Sovereign account converter; this attempts to derive an `AccountId` from the origin location96	// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for97	// foreign chains who want to have a local sovereign account on this chain which they control.98	SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,99	// Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when100	// recognised.101	RelayChainAsNative<RelayOrigin, RuntimeOrigin>,102	// Native converter for sibling Parachains; will convert to a `SiblingPara` origin when103	// recognised.104	SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,105	// Native signed account converter; this just converts an `AccountId32` origin into a normal106	// `Origin::Signed` origin of the same 32-byte value.107	SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,108	// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.109	XcmPassthrough<RuntimeOrigin>,110);111112pub trait TryPass {113	fn try_pass<Call>(114		origin: &MultiLocation,115		message: &mut [Instruction<Call>],116	) -> Result<(), ProcessMessageError>;117}118119#[impl_trait_for_tuples::impl_for_tuples(30)]120impl TryPass for Tuple {121	fn try_pass<Call>(122		origin: &MultiLocation,123		message: &mut [Instruction<Call>],124	) -> Result<(), ProcessMessageError> {125		for_tuples!( #(126			Tuple::try_pass(origin, message)?;127		)* );128129		Ok(())130	}131}132133/// Deny executing the XCM if it matches any of the Deny filter regardless of anything else.134/// If it passes the Deny, and matches one of the Allow cases then it is let through.135pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)136where137	Deny: TryPass,138	Allow: ShouldExecute;139140impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>141where142	Deny: TryPass,143	Allow: ShouldExecute,144{145	fn should_execute<Call>(146		origin: &MultiLocation,147		message: &mut [Instruction<Call>],148		max_weight: Weight,149		properties: &mut Properties,150	) -> Result<(), ProcessMessageError> {151		Deny::try_pass(origin, message)?;152		Allow::should_execute(origin, message, max_weight, properties)153	}154}155156pub type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;157158pub type IsReserve = MultiNativeAsset<AbsoluteReserveProvider>;159160pub type Trader = FreeForAll;161162pub struct XcmExecutorConfig<T>(PhantomData<T>);163impl<T> staging_xcm_executor::Config for XcmExecutorConfig<T>164where165	T: pallet_configuration::Config,166{167	type RuntimeCall = RuntimeCall;168	type XcmSender = XcmRouter;169	// How to withdraw and deposit an asset.170	type AssetTransactor = ForeignAssets;171	type OriginConverter = XcmOriginToTransactDispatchOrigin;172	type IsReserve = IsReserve;173	type IsTeleporter = (); // Teleportation is disabled174	type UniversalLocation = UniversalLocation;175	type Barrier = Barrier;176	type Weigher = Weigher;177	type Trader = Trader;178	type ResponseHandler = PolkadotXcm;179	type SubscriptionService = PolkadotXcm;180	type PalletInstancesInfo = AllPalletsWithSystem;181	type MaxAssetsIntoHolding = ConstU32<8>;182183	type AssetTrap = PolkadotXcm;184	type AssetClaims = PolkadotXcm;185	type AssetLocker = ();186	type AssetExchanger = ();187	type FeeManager = ();188	type MessageExporter = ();189	type UniversalAliases = Nothing;190	type CallDispatcher = RuntimeCall;191	type SafeCallFilter = Nothing;192	type Aliasers = Nothing;193}194195#[cfg(feature = "runtime-benchmarks")]196parameter_types! {197	pub ReachableDest: Option<MultiLocation> = Some(Parent.into());198}199200impl pallet_xcm::Config for Runtime {201	type RuntimeEvent = RuntimeEvent;202	type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;203	type XcmRouter = XcmRouter;204	type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;205	type XcmExecuteFilter = Everything;206	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;207	type XcmTeleportFilter = Everything;208	type XcmReserveTransferFilter = Everything;209	type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;210	type RuntimeOrigin = RuntimeOrigin;211	type RuntimeCall = RuntimeCall;212	const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;213	type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;214	type UniversalLocation = UniversalLocation;215	type Currency = Balances;216	type CurrencyMatcher = ();217	type TrustedLockers = ();218	type SovereignAccountOf = LocationToAccountId;219	type MaxLockers = ConstU32<8>;220	type WeightInfo = crate::weights::xcm::SubstrateWeight<Runtime>;221	type AdminOrigin = EnsureRoot<AccountId>;222	type MaxRemoteLockConsumers = ConstU32<0>;223	type RemoteLockConsumerIdentifier = ();224	#[cfg(feature = "runtime-benchmarks")]225	type ReachableDest = ReachableDest;226}227228impl cumulus_pallet_xcm::Config for Runtime {229	type RuntimeEvent = RuntimeEvent;230	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;231}232impl cumulus_pallet_xcmp_queue::Config for Runtime {233	type WeightInfo = ();234	type RuntimeEvent = RuntimeEvent;235	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;236	type ChannelInfo = ParachainSystem;237	type VersionWrapper = PolkadotXcm;238	type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;239240	#[cfg(feature = "governance")]241	type ControllerOrigin = governance::RootOrTechnicalCommitteeMember;242243	#[cfg(not(feature = "governance"))]244	type ControllerOrigin = frame_system::EnsureRoot<AccountId>;245246	type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;247	type PriceForSiblingDelivery = NoPriceForMessageDelivery<ParaId>;248}249250impl cumulus_pallet_dmp_queue::Config for Runtime {251	type RuntimeEvent = RuntimeEvent;252	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;253	type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;254}