From 04d420f376a1445c6636926c87485519a1db3fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Rodriguez?= Date: Fri, 17 May 2024 13:40:58 -0300 Subject: [PATCH] Improve Erc20PalletMatcher (#44) --- precompiles/pallet-xcm/src/mock.rs | 11 ++++------- precompiles/pallet-xcm/src/tests.rs | 2 +- primitives/xcm/src/location_matcher.rs | 9 +++++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/precompiles/pallet-xcm/src/mock.rs b/precompiles/pallet-xcm/src/mock.rs index b1d7a91..8aa1b01 100644 --- a/precompiles/pallet-xcm/src/mock.rs +++ b/precompiles/pallet-xcm/src/mock.rs @@ -40,7 +40,7 @@ use xcm_executor::{ AssetsInHolding, }; pub use xcm_primitives::{ - location_matcher::{Erc20PalletMatcher, ForeignAssetMatcher, SingleAddressMatcher}, + location_matcher::{ForeignAssetMatcher, SingleAddressMatcher}, AccountIdAssetIdConversion, }; use Junctions::Here; @@ -204,10 +204,7 @@ pub type SingleAddressMatch = SingleAddressMatcher; -pub type Erc20Match = Erc20PalletMatcher; - -pub type PCall = - PalletXcmPrecompileCall; +pub type PCall = PalletXcmPrecompileCall; mock_account!(ParentAccount, |_| MockAccount::from_u64(4)); @@ -223,7 +220,7 @@ const BLOCK_STORAGE_LIMIT: u64 = 40 * 1024; parameter_types! { pub BlockGasLimit: U256 = U256::from(u64::MAX); - pub PrecompilesValue: Precompiles = Precompiles::new(); + pub PrecompilesValue: Precompiles = Precompiles::new(); pub const WeightPerGas: Weight = Weight::from_parts(1, 0); pub GasLimitPovSizeRatio: u64 = { let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64(); @@ -258,7 +255,7 @@ impl pallet_evm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Runner = pallet_evm::runner::stack::Runner; type PrecompilesValue = PrecompilesValue; - type PrecompilesType = Precompiles; + type PrecompilesType = Precompiles; type ChainId = (); type OnChargeTransaction = (); type BlockGasLimit = BlockGasLimit; diff --git a/precompiles/pallet-xcm/src/tests.rs b/precompiles/pallet-xcm/src/tests.rs index c1e9592..23b90c5 100644 --- a/precompiles/pallet-xcm/src/tests.rs +++ b/precompiles/pallet-xcm/src/tests.rs @@ -22,7 +22,7 @@ use sp_core::{H160, H256}; use sp_weights::Weight; use xcm::latest::Junction::*; -fn precompiles() -> Precompiles { +fn precompiles() -> Precompiles { PrecompilesValue::get() } diff --git a/primitives/xcm/src/location_matcher.rs b/primitives/xcm/src/location_matcher.rs index 48d0f4d..22e73ec 100644 --- a/primitives/xcm/src/location_matcher.rs +++ b/primitives/xcm/src/location_matcher.rs @@ -93,19 +93,20 @@ where } // Matcher for any pallet that handles ERC20s internally. -pub struct Erc20PalletMatcher(PhantomData); +pub struct Erc20PalletMatcher(PhantomData<(AccountId, PalletInstance)>); -impl AccountIdToLocationMatcher - for Erc20PalletMatcher +impl AccountIdToLocationMatcher + for Erc20PalletMatcher where AccountId: Parameter + Into, + PalletInstance: PalletInfoAccess, { fn convert(account: AccountId) -> Option { let h160_account = account.into(); Some(Location::new( 0, [ - PalletInstance(PALLET_INDEX), + PalletInstance(::index() as u8), AccountKey20 { key: h160_account.0, network: None,