diff --git a/pallets/erc20-xcm-bridge/src/lib.rs b/pallets/erc20-xcm-bridge/src/lib.rs index 208c6899b3..69114e98d2 100644 --- a/pallets/erc20-xcm-bridge/src/lib.rs +++ b/pallets/erc20-xcm-bridge/src/lib.rs @@ -27,6 +27,7 @@ use frame_support::pallet; pub use erc20_trap::AssetTrapWrapper; pub use pallet::*; +pub use xcm_holding_ext::XcmExecutorWrapper; #[pallet] pub mod pallet { diff --git a/pallets/erc20-xcm-bridge/src/xcm_holding_ext.rs b/pallets/erc20-xcm-bridge/src/xcm_holding_ext.rs index 942f3f9a7e..68e064f204 100644 --- a/pallets/erc20-xcm-bridge/src/xcm_holding_ext.rs +++ b/pallets/erc20-xcm-bridge/src/xcm_holding_ext.rs @@ -16,6 +16,7 @@ //! Module that provides types to extend xcm holding. +use core::marker::PhantomData; use sp_core::{H160, U256}; use sp_std::collections::btree_map::BTreeMap; use sp_std::vec::Vec; @@ -93,6 +94,43 @@ impl XcmHoldingErc20sOrigins { } } +/// Xcm executor wrapper that inject xcm holding extension "XcmHoldingErc20sOrigins" +pub struct XcmExecutorWrapper( + PhantomData<(RuntimeCall, InnerXcmExecutor)>, +); +impl xcm::latest::ExecuteXcm + for XcmExecutorWrapper +where + InnerXcmExecutor: xcm::latest::ExecuteXcm, +{ + type Prepared = InnerXcmExecutor::Prepared; + + fn prepare( + message: xcm::latest::Xcm, + ) -> Result> { + InnerXcmExecutor::prepare(message) + } + + fn execute( + origin: impl Into, + pre: Self::Prepared, + hash: xcm::latest::XcmHash, + weight_credit: xcm::latest::Weight, + ) -> xcm::latest::Outcome { + let mut erc20s_origins = Default::default(); + XCM_HOLDING_ERC20_ORIGINS::using(&mut erc20s_origins, || { + InnerXcmExecutor::execute(origin, pre, hash, weight_credit) + }) + } + + fn charge_fees( + location: impl Into, + fees: xcm::latest::MultiAssets, + ) -> Result<(), xcm::latest::Error> { + InnerXcmExecutor::charge_fees(location, fees) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/runtime/moonbase/src/xcm_config.rs b/runtime/moonbase/src/xcm_config.rs index 630f0a6414..3b079b21ee 100644 --- a/runtime/moonbase/src/xcm_config.rs +++ b/runtime/moonbase/src/xcm_config.rs @@ -350,6 +350,11 @@ pub type XcmRouter = ( XcmpQueue, ); +type XcmExecutor = pallet_erc20_xcm_bridge::XcmExecutorWrapper< + RuntimeCall, + xcm_executor::XcmExecutor, +>; + #[cfg(feature = "runtime-benchmarks")] parameter_types! { pub ReachableDest: Option = Some(Parent.into()); @@ -361,7 +366,7 @@ impl pallet_xcm::Config for Runtime { type XcmRouter = XcmRouter; type ExecuteXcmOrigin = EnsureXcmOrigin; type XcmExecuteFilter = Everything; - type XcmExecutor = xcm_executor::XcmExecutor; + type XcmExecutor = XcmExecutor; type XcmTeleportFilter = Nothing; type XcmReserveTransferFilter = Everything; type Weigher = XcmWeigher; @@ -383,12 +388,12 @@ impl pallet_xcm::Config for Runtime { impl cumulus_pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type XcmExecutor = xcm_executor::XcmExecutor; + type XcmExecutor = XcmExecutor; } impl cumulus_pallet_xcmp_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type XcmExecutor = xcm_executor::XcmExecutor; + type XcmExecutor = XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = PolkadotXcm; type ExecuteOverweightOrigin = EnsureRoot; @@ -400,7 +405,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { impl cumulus_pallet_dmp_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type XcmExecutor = xcm_executor::XcmExecutor; + type XcmExecutor = XcmExecutor; type ExecuteOverweightOrigin = EnsureRoot; } @@ -547,7 +552,7 @@ impl orml_xtokens::Config for Runtime { type AccountIdToMultiLocation = AccountIdToMultiLocation; type CurrencyIdConvert = CurrencyIdtoMultiLocation>; - type XcmExecutor = xcm_executor::XcmExecutor; + type XcmExecutor = XcmExecutor; type SelfLocation = SelfLocation; type Weigher = XcmWeigher; type BaseXcmWeight = BaseXcmWeight;