1234567891011121314151617use frame_support::{18 traits::{Everything, Nothing, Get, ConstU32, ProcessMessageError},19 parameter_types,20};21use frame_system::EnsureRoot;22use pallet_xcm::XcmPassthrough;23use polkadot_parachain::primitives::Sibling;24use xcm::latest::{prelude::*, Weight, MultiLocation};25use xcm::v3::Instruction;26use xcm_builder::{27 AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, ParentAsSuperuser, RelayChainAsNative,28 SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,29 SignedToAccountId32, SovereignSignedViaLocation, ParentIsPreset,30};31use xcm_executor::{XcmExecutor, traits::ShouldExecute};32use sp_std::marker::PhantomData;33use crate::{34 Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, ParachainInfo, ParachainSystem, PolkadotXcm,35 XcmpQueue, xcm_barrier::Barrier, RelayNetwork, AllPalletsWithSystem, Balances,36};3738use up_common::types::AccountId;3940#[cfg(feature = "foreign-assets")]41pub mod foreignassets;4243#[cfg(not(feature = "foreign-assets"))]44pub mod nativeassets;4546#[cfg(feature = "foreign-assets")]47pub use foreignassets as xcm_assets;4849#[cfg(not(feature = "foreign-assets"))]50pub use nativeassets as xcm_assets;5152#[cfg(feature = "governance")]53use crate::runtime_common::config::governance;5455use xcm_assets::{AssetTransactor, IsReserve, Trader};5657parameter_types! {58 pub const RelayLocation: MultiLocation = MultiLocation::parent();59 pub RelayOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();60 pub UniversalLocation: InteriorMultiLocation = (61 GlobalConsensus(crate::RelayNetwork::get()),62 Parachain(ParachainInfo::get().into()),63 ).into();64 pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));6566 67 pub UnitWeightCost: Weight = Weight::from_parts(1_000_000, 1000); 68 pub const MaxInstructions: u32 = 100;69}7071727374pub type LocationToAccountId = (75 76 ParentIsPreset<AccountId>,77 78 SiblingParachainConvertsVia<Sibling, AccountId>,79 80 AccountId32Aliases<RelayNetwork, AccountId>,81);828384pub type LocalOriginToLocation = (SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>,);85868788pub type XcmRouter = (89 90 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,91 92 XcmpQueue,93);9495969798pub type XcmOriginToTransactDispatchOrigin = (99 100 101 102 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,103 104 105 RelayChainAsNative<RelayOrigin, RuntimeOrigin>,106 107 108 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,109 110 111 ParentAsSuperuser<RuntimeOrigin>,112 113 114 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,115 116 XcmPassthrough<RuntimeOrigin>,117);118119pub trait TryPass {120 fn try_pass<Call>(121 origin: &MultiLocation,122 message: &mut [Instruction<Call>],123 ) -> Result<(), ProcessMessageError>;124}125126#[impl_trait_for_tuples::impl_for_tuples(30)]127impl TryPass for Tuple {128 fn try_pass<Call>(129 origin: &MultiLocation,130 message: &mut [Instruction<Call>],131 ) -> Result<(), ProcessMessageError> {132 for_tuples!( #(133 Tuple::try_pass(origin, message)?;134 )* );135136 Ok(())137 }138}139140141142pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)143where144 Deny: TryPass,145 Allow: ShouldExecute;146147impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>148where149 Deny: TryPass,150 Allow: ShouldExecute,151{152 fn should_execute<Call>(153 origin: &MultiLocation,154 message: &mut [Instruction<Call>],155 max_weight: Weight,156 weight_credit: &mut Weight,157 ) -> Result<(), ProcessMessageError> {158 Deny::try_pass(origin, message)?;159 Allow::should_execute(origin, message, max_weight, weight_credit)160 }161}162163pub type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;164165pub struct XcmExecutorConfig<T>(PhantomData<T>);166impl<T> xcm_executor::Config for XcmExecutorConfig<T>167where168 T: pallet_configuration::Config,169{170 type RuntimeCall = RuntimeCall;171 type XcmSender = XcmRouter;172 173 type AssetTransactor = AssetTransactor;174 type OriginConverter = XcmOriginToTransactDispatchOrigin;175 type IsReserve = IsReserve;176 type IsTeleporter = (); 177 type UniversalLocation = UniversalLocation;178 type Barrier = Barrier;179 type Weigher = Weigher;180 type Trader = Trader<T>;181 type ResponseHandler = PolkadotXcm;182 type SubscriptionService = PolkadotXcm;183 type PalletInstancesInfo = AllPalletsWithSystem;184 type MaxAssetsIntoHolding = ConstU32<8>;185186 type AssetTrap = PolkadotXcm;187 type AssetClaims = PolkadotXcm;188 type AssetLocker = ();189 type AssetExchanger = ();190 type FeeManager = ();191 type MessageExporter = ();192 type UniversalAliases = Nothing;193 type CallDispatcher = RuntimeCall;194195 196 type SafeCallFilter = Nothing;197}198199#[cfg(feature = "runtime-benchmarks")]200parameter_types! {201 pub ReachableDest: Option<MultiLocation> = Some(Parent.into());202}203204impl pallet_xcm::Config for Runtime {205 type RuntimeEvent = RuntimeEvent;206 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;207 type XcmRouter = XcmRouter;208 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;209 type XcmExecuteFilter = Everything;210 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;211 type XcmTeleportFilter = Everything;212 type XcmReserveTransferFilter = Everything;213 type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;214 type RuntimeOrigin = RuntimeOrigin;215 type RuntimeCall = RuntimeCall;216 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;217 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;218 type UniversalLocation = UniversalLocation;219 type Currency = Balances;220 type CurrencyMatcher = ();221 type TrustedLockers = ();222 type SovereignAccountOf = LocationToAccountId;223 type MaxLockers = ConstU32<8>;224 type WeightInfo = crate::weights::xcm::SubstrateWeight<Runtime>;225 type AdminOrigin = EnsureRoot<AccountId>;226 type MaxRemoteLockConsumers = ConstU32<0>;227 type RemoteLockConsumerIdentifier = ();228 #[cfg(feature = "runtime-benchmarks")]229 type ReachableDest = ReachableDest;230}231232impl cumulus_pallet_xcm::Config for Runtime {233 type RuntimeEvent = RuntimeEvent;234 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;235}236237impl 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 = ();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}