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(..)170 | RuntimeCall::Identity(..)171 | RuntimeCall::Preimage(..)172 | RuntimeCall::Democracy(..)173 | RuntimeCall::Council(..)174 | RuntimeCall::TechnicalCommittee(..)175 | RuntimeCall::CouncilMembership(..)176 | RuntimeCall::TechnicalCommitteeMembership(..)177 | RuntimeCall::FellowshipCollective(..)178 | RuntimeCall::FellowshipReferenda(..) => true,179 _ => false,180 }181 }182183 fn allow_utility_call(call: &RuntimeCall) -> bool {184 match call {185 RuntimeCall::Utility(pallet_utility::Call::batch { calls, .. }) => {186 calls.iter().all(|call| Self::allow_gov_and_sys_call(call))187 }188 RuntimeCall::Utility(pallet_utility::Call::batch_all { calls, .. }) => {189 calls.iter().all(|call| Self::allow_gov_and_sys_call(call))190 }191 RuntimeCall::Utility(pallet_utility::Call::as_derivative { call, .. }) => {192 Self::allow_gov_and_sys_call(call)193 }194 RuntimeCall::Utility(pallet_utility::Call::dispatch_as { call, .. }) => {195 Self::allow_gov_and_sys_call(call)196 }197 RuntimeCall::Utility(pallet_utility::Call::force_batch { calls, .. }) => {198 calls.iter().all(|call| Self::allow_gov_and_sys_call(call))199 }200 _ => false,201 }202 }203}204205impl Contains<RuntimeCall> for XcmCallFilter {206 fn contains(call: &RuntimeCall) -> bool {207 Self::allow_gov_and_sys_call(call) || Self::allow_utility_call(call)208 }209}210211pub struct XcmExecutorConfig<T>(PhantomData<T>);212impl<T> xcm_executor::Config for XcmExecutorConfig<T>213where214 T: pallet_configuration::Config,215{216 type RuntimeCall = RuntimeCall;217 type XcmSender = XcmRouter;218 219 type AssetTransactor = AssetTransactor;220 type OriginConverter = XcmOriginToTransactDispatchOrigin;221 type IsReserve = IsReserve;222 type IsTeleporter = (); 223 type UniversalLocation = UniversalLocation;224 type Barrier = Barrier;225 type Weigher = Weigher;226 type Trader = Trader<T>;227 type ResponseHandler = PolkadotXcm;228 type SubscriptionService = PolkadotXcm;229 type PalletInstancesInfo = AllPalletsWithSystem;230 type MaxAssetsIntoHolding = ConstU32<8>;231232 type AssetTrap = PolkadotXcm;233 type AssetClaims = PolkadotXcm;234 type AssetLocker = ();235 type AssetExchanger = ();236 type FeeManager = ();237 type MessageExporter = ();238 type UniversalAliases = Nothing;239 type CallDispatcher = RuntimeCall;240 type SafeCallFilter = XcmCallFilter;241}242243#[cfg(feature = "runtime-benchmarks")]244parameter_types! {245 pub ReachableDest: Option<MultiLocation> = Some(Parent.into());246}247248impl pallet_xcm::Config for Runtime {249 type RuntimeEvent = RuntimeEvent;250 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;251 type XcmRouter = XcmRouter;252 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;253 type XcmExecuteFilter = Everything;254 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;255 type XcmTeleportFilter = Everything;256 type XcmReserveTransferFilter = Everything;257 type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;258 type RuntimeOrigin = RuntimeOrigin;259 type RuntimeCall = RuntimeCall;260 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;261 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;262 type UniversalLocation = UniversalLocation;263 type Currency = Balances;264 type CurrencyMatcher = ();265 type TrustedLockers = ();266 type SovereignAccountOf = LocationToAccountId;267 type MaxLockers = ConstU32<8>;268 type WeightInfo = crate::weights::xcm::SubstrateWeight<Runtime>;269 type AdminOrigin = EnsureRoot<AccountId>;270 type MaxRemoteLockConsumers = ConstU32<0>;271 type RemoteLockConsumerIdentifier = ();272 #[cfg(feature = "runtime-benchmarks")]273 type ReachableDest = ReachableDest;274}275276impl cumulus_pallet_xcm::Config for Runtime {277 type RuntimeEvent = RuntimeEvent;278 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;279}280281impl cumulus_pallet_xcmp_queue::Config for Runtime {282 type WeightInfo = ();283 type RuntimeEvent = RuntimeEvent;284 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;285 type ChannelInfo = ParachainSystem;286 type VersionWrapper = PolkadotXcm;287 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;288289 #[cfg(feature = "governance")]290 type ControllerOrigin = governance::RootOrTechnicalCommitteeMember;291292 #[cfg(not(feature = "governance"))]293 type ControllerOrigin = frame_system::EnsureRoot<AccountId>;294295 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;296 type PriceForSiblingDelivery = ();297}298299impl cumulus_pallet_dmp_queue::Config for Runtime {300 type RuntimeEvent = RuntimeEvent;301 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;302 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;303}