1234567891011121314151617use frame_support::{18 traits::{Everything, Nothing, Get, ConstU32, ProcessMessageError, Contains},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 XcmCallFilter;166impl XcmCallFilter {167 fn allow_gov_and_sys_call(call: &RuntimeCall) -> bool {168 match call {169 RuntimeCall::System(..) => true,170171 #[cfg(feature = "governance")]172 RuntimeCall::Identity(..)173 | RuntimeCall::Preimage(..)174 | RuntimeCall::Democracy(..)175 | RuntimeCall::Council(..)176 | RuntimeCall::TechnicalCommittee(..)177 | RuntimeCall::CouncilMembership(..)178 | RuntimeCall::TechnicalCommitteeMembership(..)179 | RuntimeCall::FellowshipCollective(..)180 | RuntimeCall::FellowshipReferenda(..) => true,181 _ => false,182 }183 }184185 fn allow_utility_call(call: &RuntimeCall) -> bool {186 match call {187 RuntimeCall::Utility(pallet_utility::Call::batch { calls, .. }) => {188 calls.iter().all(Self::allow_gov_and_sys_call)189 }190 RuntimeCall::Utility(pallet_utility::Call::batch_all { calls, .. }) => {191 calls.iter().all(Self::allow_gov_and_sys_call)192 }193 RuntimeCall::Utility(pallet_utility::Call::as_derivative { call, .. }) => {194 Self::allow_gov_and_sys_call(call)195 }196 RuntimeCall::Utility(pallet_utility::Call::dispatch_as { call, .. }) => {197 Self::allow_gov_and_sys_call(call)198 }199 RuntimeCall::Utility(pallet_utility::Call::force_batch { calls, .. }) => {200 calls.iter().all(Self::allow_gov_and_sys_call)201 }202 _ => false,203 }204 }205}206207impl Contains<RuntimeCall> for XcmCallFilter {208 fn contains(call: &RuntimeCall) -> bool {209 Self::allow_gov_and_sys_call(call) || Self::allow_utility_call(call)210 }211}212213pub struct XcmExecutorConfig<T>(PhantomData<T>);214impl<T> xcm_executor::Config for XcmExecutorConfig<T>215where216 T: pallet_configuration::Config,217{218 type RuntimeCall = RuntimeCall;219 type XcmSender = XcmRouter;220 221 type AssetTransactor = AssetTransactor;222 type OriginConverter = XcmOriginToTransactDispatchOrigin;223 type IsReserve = IsReserve;224 type IsTeleporter = (); 225 type UniversalLocation = UniversalLocation;226 type Barrier = Barrier;227 type Weigher = Weigher;228 type Trader = Trader<T>;229 type ResponseHandler = PolkadotXcm;230 type SubscriptionService = PolkadotXcm;231 type PalletInstancesInfo = AllPalletsWithSystem;232 type MaxAssetsIntoHolding = ConstU32<8>;233234 type AssetTrap = PolkadotXcm;235 type AssetClaims = PolkadotXcm;236 type AssetLocker = ();237 type AssetExchanger = ();238 type FeeManager = ();239 type MessageExporter = ();240 type UniversalAliases = Nothing;241 type CallDispatcher = RuntimeCall;242 type SafeCallFilter = XcmCallFilter;243}244245#[cfg(feature = "runtime-benchmarks")]246parameter_types! {247 pub ReachableDest: Option<MultiLocation> = Some(Parent.into());248}249250impl pallet_xcm::Config for Runtime {251 type RuntimeEvent = RuntimeEvent;252 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;253 type XcmRouter = XcmRouter;254 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;255 type XcmExecuteFilter = Everything;256 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;257 type XcmTeleportFilter = Everything;258 type XcmReserveTransferFilter = Everything;259 type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;260 type RuntimeOrigin = RuntimeOrigin;261 type RuntimeCall = RuntimeCall;262 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;263 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;264 type UniversalLocation = UniversalLocation;265 type Currency = Balances;266 type CurrencyMatcher = ();267 type TrustedLockers = ();268 type SovereignAccountOf = LocationToAccountId;269 type MaxLockers = ConstU32<8>;270 type WeightInfo = crate::weights::xcm::SubstrateWeight<Runtime>;271 type AdminOrigin = EnsureRoot<AccountId>;272 type MaxRemoteLockConsumers = ConstU32<0>;273 type RemoteLockConsumerIdentifier = ();274 #[cfg(feature = "runtime-benchmarks")]275 type ReachableDest = ReachableDest;276}277278impl cumulus_pallet_xcm::Config for Runtime {279 type RuntimeEvent = RuntimeEvent;280 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;281}282283impl cumulus_pallet_xcmp_queue::Config for Runtime {284 type WeightInfo = ();285 type RuntimeEvent = RuntimeEvent;286 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;287 type ChannelInfo = ParachainSystem;288 type VersionWrapper = PolkadotXcm;289 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;290291 #[cfg(feature = "governance")]292 type ControllerOrigin = governance::RootOrTechnicalCommitteeMember;293294 #[cfg(not(feature = "governance"))]295 type ControllerOrigin = frame_system::EnsureRoot<AccountId>;296297 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;298 type PriceForSiblingDelivery = ();299}300301impl cumulus_pallet_dmp_queue::Config for Runtime {302 type RuntimeEvent = RuntimeEvent;303 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;304 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;305}