1234567891011121314151617use 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 63 pub UnitWeightCost: Weight = Weight::from_parts(1_000_000, 1000); 64 pub const MaxInstructions: u32 = 100;65}6667686970pub type LocationToAccountId = (71 72 ParentIsPreset<AccountId>,73 74 SiblingParachainConvertsVia<Sibling, AccountId>,75 76 AccountId32Aliases<RelayNetwork, AccountId>,77);787980pub type LocalOriginToLocation = (SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>,);81828384pub type XcmRouter = (85 86 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,87 88 XcmpQueue,89);9091929394pub type XcmOriginToTransactDispatchOrigin = (95 96 97 98 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,99 100 101 RelayChainAsNative<RelayOrigin, RuntimeOrigin>,102 103 104 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,105 106 107 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,108 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}132133134135pub 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 170 type AssetTransactor = ForeignAssets;171 type OriginConverter = XcmOriginToTransactDispatchOrigin;172 type IsReserve = IsReserve;173 type IsTeleporter = (); 174 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}