1234567891011121314151617use cumulus_primitives_core::ParaId;18use frame_support::{19 parameter_types,20 traits::{ConstU32, Everything, Get, Nothing, ProcessMessageError},21};22use frame_system::EnsureRoot;23use pallet_xcm::XcmPassthrough;24use polkadot_parachain_primitives::primitives::Sibling;25use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;26use sp_std::marker::PhantomData;27use staging_xcm::{28 latest::{prelude::*, MultiLocation, Weight},29 v3::Instruction,30};31use staging_xcm_builder::{32 AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, ParentIsPreset, RelayChainAsNative,33 SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,34 SignedToAccountId32, SovereignSignedViaLocation,35};36use staging_xcm_executor::{37 traits::{Properties, ShouldExecute},38 XcmExecutor,39};40use up_common::types::AccountId;4142use crate::{43 xcm_barrier::Barrier, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem,44 PolkadotXcm, RelayNetwork, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, XcmpQueue,45};4647#[cfg(feature = "foreign-assets")]48pub mod foreignassets;4950#[cfg(not(feature = "foreign-assets"))]51pub mod nativeassets;5253#[cfg(feature = "foreign-assets")]54pub use foreignassets as xcm_assets;55#[cfg(not(feature = "foreign-assets"))]56pub use nativeassets as xcm_assets;57use xcm_assets::{AssetTransactor, IsReserve, Trader};5859#[cfg(feature = "governance")]60use crate::runtime_common::config::governance;6162parameter_types! {63 pub const RelayLocation: MultiLocation = MultiLocation::parent();64 pub RelayOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();65 pub UniversalLocation: InteriorMultiLocation = (66 GlobalConsensus(crate::RelayNetwork::get()),67 Parachain(ParachainInfo::get().into()),68 ).into();69 pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));7071 72 pub UnitWeightCost: Weight = Weight::from_parts(1_000_000, 1000); 73 pub const MaxInstructions: u32 = 100;74}7576777879pub type LocationToAccountId = (80 81 ParentIsPreset<AccountId>,82 83 SiblingParachainConvertsVia<Sibling, AccountId>,84 85 AccountId32Aliases<RelayNetwork, AccountId>,86);878889pub type LocalOriginToLocation = (SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>,);90919293pub type XcmRouter = (94 95 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,96 97 XcmpQueue,98);99100101102103pub type XcmOriginToTransactDispatchOrigin = (104 105 106 107 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,108 109 110 RelayChainAsNative<RelayOrigin, RuntimeOrigin>,111 112 113 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,114 115 116 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,117 118 XcmPassthrough<RuntimeOrigin>,119);120121pub trait TryPass {122 fn try_pass<Call>(123 origin: &MultiLocation,124 message: &mut [Instruction<Call>],125 ) -> Result<(), ProcessMessageError>;126}127128#[impl_trait_for_tuples::impl_for_tuples(30)]129impl TryPass for Tuple {130 fn try_pass<Call>(131 origin: &MultiLocation,132 message: &mut [Instruction<Call>],133 ) -> Result<(), ProcessMessageError> {134 for_tuples!( #(135 Tuple::try_pass(origin, message)?;136 )* );137138 Ok(())139 }140}141142143144pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)145where146 Deny: TryPass,147 Allow: ShouldExecute;148149impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>150where151 Deny: TryPass,152 Allow: ShouldExecute,153{154 fn should_execute<Call>(155 origin: &MultiLocation,156 message: &mut [Instruction<Call>],157 max_weight: Weight,158 properties: &mut Properties,159 ) -> Result<(), ProcessMessageError> {160 Deny::try_pass(origin, message)?;161 Allow::should_execute(origin, message, max_weight, properties)162 }163}164165pub type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;166167pub struct XcmExecutorConfig<T>(PhantomData<T>);168impl<T> staging_xcm_executor::Config for XcmExecutorConfig<T>169where170 T: pallet_configuration::Config,171{172 type RuntimeCall = RuntimeCall;173 type XcmSender = XcmRouter;174 175 type AssetTransactor = AssetTransactor;176 type OriginConverter = XcmOriginToTransactDispatchOrigin;177 type IsReserve = IsReserve;178 type IsTeleporter = (); 179 type UniversalLocation = UniversalLocation;180 type Barrier = Barrier;181 type Weigher = Weigher;182 type Trader = Trader<T>;183 type ResponseHandler = PolkadotXcm;184 type SubscriptionService = PolkadotXcm;185 type PalletInstancesInfo = AllPalletsWithSystem;186 type MaxAssetsIntoHolding = ConstU32<8>;187188 type AssetTrap = PolkadotXcm;189 type AssetClaims = PolkadotXcm;190 type AssetLocker = ();191 type AssetExchanger = ();192 type FeeManager = ();193 type MessageExporter = ();194 type UniversalAliases = Nothing;195 type CallDispatcher = RuntimeCall;196 type SafeCallFilter = Nothing;197 type Aliasers = Nothing;198}199200#[cfg(feature = "runtime-benchmarks")]201parameter_types! {202 pub ReachableDest: Option<MultiLocation> = Some(Parent.into());203}204205impl pallet_xcm::Config for Runtime {206 type RuntimeEvent = RuntimeEvent;207 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;208 type XcmRouter = XcmRouter;209 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;210 type XcmExecuteFilter = Everything;211 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;212 type XcmTeleportFilter = Everything;213 type XcmReserveTransferFilter = Everything;214 type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;215 type RuntimeOrigin = RuntimeOrigin;216 type RuntimeCall = RuntimeCall;217 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;218 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;219 type UniversalLocation = UniversalLocation;220 type Currency = Balances;221 type CurrencyMatcher = ();222 type TrustedLockers = ();223 type SovereignAccountOf = LocationToAccountId;224 type MaxLockers = ConstU32<8>;225 type WeightInfo = crate::weights::xcm::SubstrateWeight<Runtime>;226 type AdminOrigin = EnsureRoot<AccountId>;227 type MaxRemoteLockConsumers = ConstU32<0>;228 type RemoteLockConsumerIdentifier = ();229 #[cfg(feature = "runtime-benchmarks")]230 type ReachableDest = ReachableDest;231}232233impl cumulus_pallet_xcm::Config for Runtime {234 type RuntimeEvent = RuntimeEvent;235 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;236}237impl cumulus_pallet_xcmp_queue::Config for Runtime {238 type WeightInfo = ();239 type RuntimeEvent = RuntimeEvent;240 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;241 type ChannelInfo = ParachainSystem;242 type VersionWrapper = PolkadotXcm;243 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;244245 #[cfg(feature = "governance")]246 type ControllerOrigin = governance::RootOrTechnicalCommitteeMember;247248 #[cfg(not(feature = "governance"))]249 type ControllerOrigin = frame_system::EnsureRoot<AccountId>;250251 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;252 type PriceForSiblingDelivery = NoPriceForMessageDelivery<ParaId>;253}254255impl cumulus_pallet_dmp_queue::Config for Runtime {256 type RuntimeEvent = RuntimeEvent;257 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;258 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;259}