1234567891011121314151617use frame_support::{18 parameter_types,19 traits::{ConstU32, Contains, Everything, Get, Nothing, ProcessMessageError},20};21use frame_system::EnsureRoot;22use pallet_xcm::XcmPassthrough;23use polkadot_parachain_primitives::primitives::Sibling;24use sp_std::marker::PhantomData;25use staging_xcm::{26 latest::{prelude::*, MultiLocation, Weight},27 v3::Instruction,28};29use staging_xcm_builder::{30 AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, ParentAsSuperuser, ParentIsPreset,31 RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,32 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,33};34use staging_xcm_executor::{35 traits::{Properties, ShouldExecute},36 XcmExecutor,37};38use up_common::types::AccountId;3940use crate::{41 xcm_barrier::Barrier, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem,42 PolkadotXcm, RelayNetwork, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, XcmpQueue,43};4445#[cfg(feature = "foreign-assets")]46pub mod foreignassets;4748#[cfg(not(feature = "foreign-assets"))]49pub mod nativeassets;5051#[cfg(feature = "foreign-assets")]52pub use foreignassets as xcm_assets;53#[cfg(not(feature = "foreign-assets"))]54pub use nativeassets as xcm_assets;55use xcm_assets::{AssetTransactor, IsReserve, Trader};5657#[cfg(feature = "governance")]58use crate::runtime_common::config::governance;5960parameter_types! {61 pub const RelayLocation: MultiLocation = MultiLocation::parent();62 pub RelayOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();63 pub UniversalLocation: InteriorMultiLocation = (64 GlobalConsensus(crate::RelayNetwork::get()),65 Parachain(ParachainInfo::get().into()),66 ).into();67 pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));6869 70 pub UnitWeightCost: Weight = Weight::from_parts(1_000_000, 1000); 71 pub const MaxInstructions: u32 = 100;72}7374757677pub type LocationToAccountId = (78 79 ParentIsPreset<AccountId>,80 81 SiblingParachainConvertsVia<Sibling, AccountId>,82 83 AccountId32Aliases<RelayNetwork, AccountId>,84);858687pub type LocalOriginToLocation = (SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>,);88899091pub type XcmRouter = (92 93 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,94 95 XcmpQueue,96);979899100101pub type XcmOriginToTransactDispatchOrigin = (102 103 104 105 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,106 107 108 RelayChainAsNative<RelayOrigin, RuntimeOrigin>,109 110 111 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,112 113 114 ParentAsSuperuser<RuntimeOrigin>,115 116 117 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,118 119 XcmPassthrough<RuntimeOrigin>,120);121122pub trait TryPass {123 fn try_pass<Call>(124 origin: &MultiLocation,125 message: &mut [Instruction<Call>],126 ) -> Result<(), ProcessMessageError>;127}128129#[impl_trait_for_tuples::impl_for_tuples(30)]130impl TryPass for Tuple {131 fn try_pass<Call>(132 origin: &MultiLocation,133 message: &mut [Instruction<Call>],134 ) -> Result<(), ProcessMessageError> {135 for_tuples!( #(136 Tuple::try_pass(origin, message)?;137 )* );138139 Ok(())140 }141}142143144145pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)146where147 Deny: TryPass,148 Allow: ShouldExecute;149150impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>151where152 Deny: TryPass,153 Allow: ShouldExecute,154{155 fn should_execute<Call>(156 origin: &MultiLocation,157 message: &mut [Instruction<Call>],158 max_weight: Weight,159 properties: &mut Properties,160 ) -> Result<(), ProcessMessageError> {161 Deny::try_pass(origin, message)?;162 Allow::should_execute(origin, message, max_weight, properties)163 }164}165166pub type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;167168pub struct XcmCallFilter;169impl XcmCallFilter {170 fn allow_gov_and_sys_call(call: &RuntimeCall) -> bool {171 match call {172 RuntimeCall::System(..) => true,173174 #[cfg(feature = "governance")]175 RuntimeCall::Identity(..)176 | RuntimeCall::Preimage(..)177 | RuntimeCall::Democracy(..)178 | RuntimeCall::Council(..)179 | RuntimeCall::TechnicalCommittee(..)180 | RuntimeCall::CouncilMembership(..)181 | RuntimeCall::TechnicalCommitteeMembership(..)182 | RuntimeCall::FellowshipCollective(..)183 | RuntimeCall::FellowshipReferenda(..) => true,184 _ => false,185 }186 }187188 fn allow_utility_call(call: &RuntimeCall) -> bool {189 match call {190 RuntimeCall::Utility(pallet_utility::Call::batch { calls, .. }) => {191 calls.iter().all(Self::allow_gov_and_sys_call)192 }193 RuntimeCall::Utility(pallet_utility::Call::batch_all { calls, .. }) => {194 calls.iter().all(Self::allow_gov_and_sys_call)195 }196 RuntimeCall::Utility(pallet_utility::Call::as_derivative { call, .. }) => {197 Self::allow_gov_and_sys_call(call)198 }199 RuntimeCall::Utility(pallet_utility::Call::dispatch_as { call, .. }) => {200 Self::allow_gov_and_sys_call(call)201 }202 RuntimeCall::Utility(pallet_utility::Call::force_batch { calls, .. }) => {203 calls.iter().all(Self::allow_gov_and_sys_call)204 }205 _ => false,206 }207 }208}209210impl Contains<RuntimeCall> for XcmCallFilter {211 fn contains(call: &RuntimeCall) -> bool {212 Self::allow_gov_and_sys_call(call) || Self::allow_utility_call(call)213 }214}215216pub struct XcmExecutorConfig<T>(PhantomData<T>);217impl<T> staging_xcm_executor::Config for XcmExecutorConfig<T>218where219 T: pallet_configuration::Config,220{221 type RuntimeCall = RuntimeCall;222 type XcmSender = XcmRouter;223 224 type AssetTransactor = AssetTransactor;225 type OriginConverter = XcmOriginToTransactDispatchOrigin;226 type IsReserve = IsReserve;227 type IsTeleporter = (); 228 type UniversalLocation = UniversalLocation;229 type Barrier = Barrier;230 type Weigher = Weigher;231 type Trader = Trader<T>;232 type ResponseHandler = PolkadotXcm;233 type SubscriptionService = PolkadotXcm;234 type PalletInstancesInfo = AllPalletsWithSystem;235 type MaxAssetsIntoHolding = ConstU32<8>;236237 type AssetTrap = PolkadotXcm;238 type AssetClaims = PolkadotXcm;239 type AssetLocker = ();240 type AssetExchanger = ();241 type FeeManager = ();242 type MessageExporter = ();243 type UniversalAliases = Nothing;244 type CallDispatcher = RuntimeCall;245 type SafeCallFilter = XcmCallFilter;246 type Aliasers = Nothing;247}248249#[cfg(feature = "runtime-benchmarks")]250parameter_types! {251 pub ReachableDest: Option<MultiLocation> = Some(Parent.into());252}253254impl pallet_xcm::Config for Runtime {255 type RuntimeEvent = RuntimeEvent;256 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;257 type XcmRouter = XcmRouter;258 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;259 type XcmExecuteFilter = Everything;260 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;261 type XcmTeleportFilter = Everything;262 type XcmReserveTransferFilter = Everything;263 type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;264 type RuntimeOrigin = RuntimeOrigin;265 type RuntimeCall = RuntimeCall;266 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;267 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;268 type UniversalLocation = UniversalLocation;269 type Currency = Balances;270 type CurrencyMatcher = ();271 type TrustedLockers = ();272 type SovereignAccountOf = LocationToAccountId;273 type MaxLockers = ConstU32<8>;274 type WeightInfo = crate::weights::xcm::SubstrateWeight<Runtime>;275 type AdminOrigin = EnsureRoot<AccountId>;276 type MaxRemoteLockConsumers = ConstU32<0>;277 type RemoteLockConsumerIdentifier = ();278 #[cfg(feature = "runtime-benchmarks")]279 type ReachableDest = ReachableDest;280}281282impl cumulus_pallet_xcm::Config for Runtime {283 type RuntimeEvent = RuntimeEvent;284 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;285}286287impl cumulus_pallet_xcmp_queue::Config for Runtime {288 type WeightInfo = ();289 type RuntimeEvent = RuntimeEvent;290 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;291 type ChannelInfo = ParachainSystem;292 type VersionWrapper = PolkadotXcm;293 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;294295 #[cfg(feature = "governance")]296 type ControllerOrigin = governance::RootOrTechnicalCommitteeMember;297298 #[cfg(not(feature = "governance"))]299 type ControllerOrigin = frame_system::EnsureRoot<AccountId>;300301 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;302 type PriceForSiblingDelivery = ();303}304305impl cumulus_pallet_dmp_queue::Config for Runtime {306 type RuntimeEvent = RuntimeEvent;307 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;308 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;309}