1234567891011121314151617use frame_support::{18 traits::{Everything, Nothing, Get, ConstU32},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, vec::Vec};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;5152use xcm_assets::{AssetTransactor, IsReserve, Trader};5354parameter_types! {55 pub const RelayLocation: MultiLocation = MultiLocation::parent();56 pub RelayOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();57 pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::get().into()));58 pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));5960 61 pub UnitWeightCost: Weight = Weight::from_parts(1_000_000, 1000); 62 pub const MaxInstructions: u32 = 100;63}6465666768pub type LocationToAccountId = (69 70 ParentIsPreset<AccountId>,71 72 SiblingParachainConvertsVia<Sibling, AccountId>,73 74 AccountId32Aliases<RelayNetwork, AccountId>,75);767778pub type LocalOriginToLocation = (SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>,);79808182pub type XcmRouter = (83 84 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,85 86 XcmpQueue,87);8889909192pub type XcmOriginToTransactDispatchOrigin = (93 94 95 96 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,97 98 99 RelayChainAsNative<RelayOrigin, RuntimeOrigin>,100 101 102 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,103 104 105 ParentAsSuperuser<RuntimeOrigin>,106 107 108 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,109 110 XcmPassthrough<RuntimeOrigin>,111);112113pub trait TryPass {114 fn try_pass<Call>(origin: &MultiLocation, message: &mut [Instruction<Call>]) -> Result<(), ()>;115}116117#[impl_trait_for_tuples::impl_for_tuples(30)]118impl TryPass for Tuple {119 fn try_pass<Call>(origin: &MultiLocation, message: &mut [Instruction<Call>]) -> Result<(), ()> {120 for_tuples!( #(121 Tuple::try_pass(origin, message)?;122 )* );123124 Ok(())125 }126}127128129130pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)131where132 Deny: TryPass,133 Allow: ShouldExecute;134135impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>136where137 Deny: TryPass,138 Allow: ShouldExecute,139{140 fn should_execute<Call>(141 origin: &MultiLocation,142 message: &mut [Instruction<Call>],143 max_weight: Weight,144 weight_credit: &mut Weight,145 ) -> Result<(), ()> {146 Deny::try_pass(origin, message)?;147 Allow::should_execute(origin, message, max_weight, weight_credit)148 }149}150151pub type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;152153pub struct XcmExecutorConfig<T>(PhantomData<T>);154impl<T> xcm_executor::Config for XcmExecutorConfig<T>155where156 T: pallet_configuration::Config,157{158 type RuntimeCall = RuntimeCall;159 type XcmSender = XcmRouter;160 161 type AssetTransactor = AssetTransactor;162 type OriginConverter = XcmOriginToTransactDispatchOrigin;163 type IsReserve = IsReserve;164 type IsTeleporter = (); 165 type UniversalLocation = UniversalLocation;166 type Barrier = Barrier;167 type Weigher = Weigher;168 type Trader = Trader<T>;169 type ResponseHandler = PolkadotXcm;170 type SubscriptionService = PolkadotXcm;171 type PalletInstancesInfo = AllPalletsWithSystem;172 type MaxAssetsIntoHolding = ConstU32<8>;173174 type AssetTrap = PolkadotXcm;175 type AssetClaims = PolkadotXcm;176 type AssetLocker = ();177 type AssetExchanger = ();178 type FeeManager = ();179 type MessageExporter = ();180 type UniversalAliases = Nothing;181 type CallDispatcher = RuntimeCall;182183 184 type SafeCallFilter = Nothing;185}186187#[cfg(feature = "runtime-benchmarks")]188parameter_types! {189 pub ReachableDest: Option<MultiLocation> = Some(Parent.into());190}191192impl pallet_xcm::Config for Runtime {193 type RuntimeEvent = RuntimeEvent;194 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;195 type XcmRouter = XcmRouter;196 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;197 type XcmExecuteFilter = Everything;198 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;199 type XcmTeleportFilter = Everything;200 type XcmReserveTransferFilter = Everything;201 type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;202 type RuntimeOrigin = RuntimeOrigin;203 type RuntimeCall = RuntimeCall;204 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;205 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;206 type UniversalLocation = UniversalLocation;207 type Currency = Balances;208 type CurrencyMatcher = ();209 type TrustedLockers = ();210 type SovereignAccountOf = LocationToAccountId;211 type MaxLockers = ConstU32<8>;212 type WeightInfo = crate::weights::xcm::SubstrateWeight<Runtime>;213 #[cfg(feature = "runtime-benchmarks")]214 type ReachableDest = ReachableDest;215}216217impl cumulus_pallet_xcm::Config for Runtime {218 type RuntimeEvent = RuntimeEvent;219 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;220}221222impl cumulus_pallet_xcmp_queue::Config for Runtime {223 type WeightInfo = ();224 type RuntimeEvent = RuntimeEvent;225 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;226 type ChannelInfo = ParachainSystem;227 type VersionWrapper = ();228 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;229 type ControllerOrigin = EnsureRoot<AccountId>;230 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;231 type PriceForSiblingDelivery = ();232}233234impl cumulus_pallet_dmp_queue::Config for Runtime {235 type RuntimeEvent = RuntimeEvent;236 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;237 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;238}