Skip to content

Commit

Permalink
Allow assets managed by AssetManager and EvmForeignAssets to use the …
Browse files Browse the repository at this point in the history
…pallet-xcm precompile (#3136)

* update AssetIdToLocationManager to support both EvmForeignAssets and AssetManager as asset managers

* test pallet xcm precompile with old foreign assets approach

* fix test
  • Loading branch information
RomarQ authored Jan 19, 2025
1 parent e167a3a commit a322ae9
Show file tree
Hide file tree
Showing 6 changed files with 441 additions and 16 deletions.
15 changes: 11 additions & 4 deletions runtime/moonbase/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

use super::moonbase_weights;
use crate::{
asset_config::ForeignAssetInstance, xcm_config::XcmExecutorConfig, OpenTechCommitteeInstance,
TreasuryCouncilInstance,
asset_config::ForeignAssetInstance,
xcm_config::{AssetType, XcmExecutorConfig},
OpenTechCommitteeInstance, TreasuryCouncilInstance,
};
use crate::{
AccountId, AssetId, AssetManager, Balances, Erc20XcmBridge, EvmForeignAssets, Runtime, H160,
};
use crate::{AccountId, AssetId, Balances, Erc20XcmBridge, EvmForeignAssets, Runtime, H160};
use frame_support::parameter_types;
use moonkit_xcm_primitives::{
location_matcher::{Erc20PalletMatcher, ForeignAssetMatcher, SingleAddressMatcher},
Expand Down Expand Up @@ -60,6 +63,7 @@ use pallet_precompile_benchmarks::WeightInfo;
use precompile_foreign_asset_migrator::ForeignAssetMigratorPrecompile;
use precompile_utils::precompile_set::*;
use sp_std::prelude::*;
use xcm_primitives::AsAssetType;

parameter_types! {
pub P256VerifyWeight: frame_support::weights::Weight =
Expand Down Expand Up @@ -111,7 +115,10 @@ type EthereumPrecompilesChecks = (AcceptDelegateCall, CallableByContract, Callab

// Pallet-xcm precompile types.
// Type that converts AssetId into Location
type AssetIdToLocationManager = EvmForeignAssets;
type AssetIdToLocationManager = (
AsAssetType<AssetId, AssetType, AssetManager>,
EvmForeignAssets,
);

// The pallet-balances address is identified by ERC20_BALANCES_PRECOMPILE const
type SingleAddressMatch = SingleAddressMatcher<AccountId, ERC20_BALANCES_PRECOMPILE, Balances>;
Expand Down
9 changes: 6 additions & 3 deletions runtime/moonbeam/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use super::moonbeam_weights;
use crate::{
asset_config::ForeignAssetInstance,
xcm_config::{AssetType, XcmExecutorConfig},
AccountId, AssetId, AssetManager, Balances, Erc20XcmBridge, OpenTechCommitteeInstance, Runtime,
TreasuryCouncilInstance, H160,
AccountId, AssetId, AssetManager, Balances, Erc20XcmBridge, EvmForeignAssets,
OpenTechCommitteeInstance, Runtime, TreasuryCouncilInstance, H160,
};
use frame_support::parameter_types;
use moonkit_xcm_primitives::{
Expand Down Expand Up @@ -111,7 +111,10 @@ type EthereumPrecompilesChecks = (AcceptDelegateCall, CallableByContract, Callab

// Pallet-xcm precompile types.
// Type that converts AssetId into Location
type AssetIdToLocationManager = AsAssetType<AssetId, AssetType, AssetManager>;
type AssetIdToLocationManager = (
AsAssetType<AssetId, AssetType, AssetManager>,
EvmForeignAssets,
);

// The pallet-balances address is identified by ERC20_BALANCES_PRECOMPILE const
type SingleAddressMatch = SingleAddressMatcher<AccountId, ERC20_BALANCES_PRECOMPILE, Balances>;
Expand Down
9 changes: 6 additions & 3 deletions runtime/moonriver/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use super::moonriver_weights;
use crate::{
asset_config::ForeignAssetInstance,
xcm_config::{AssetType, XcmExecutorConfig},
AccountId, AssetId, AssetManager, Balances, Erc20XcmBridge, OpenTechCommitteeInstance, Runtime,
TreasuryCouncilInstance,
AccountId, AssetId, AssetManager, Balances, Erc20XcmBridge, EvmForeignAssets,
OpenTechCommitteeInstance, Runtime, TreasuryCouncilInstance,
};
use frame_support::parameter_types;
use moonkit_xcm_primitives::location_matcher::{
Expand Down Expand Up @@ -105,7 +105,10 @@ type EthereumPrecompilesChecks = (AcceptDelegateCall, CallableByContract, Callab

// Pallet-xcm precompile types.
// Type that converts AssetId into Location
type AssetIdToLocationManager = AsAssetType<AssetId, AssetType, AssetManager>;
type AssetIdToLocationManager = (
AsAssetType<AssetId, AssetType, AssetManager>,
EvmForeignAssets,
);

// The pallet-balances address is identified by ERC20_BALANCES_PRECOMPILE const
type SingleAddressMatch = SingleAddressMatcher<AccountId, ERC20_BALANCES_PRECOMPILE, Balances>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import {
PARA_1000_SOURCE_LOCATION,
mockHrmpChannelExistanceTx,
ARBITRARY_ASSET_ID,
mockAssetBalance,
registerForeignAsset,
relayAssetMetadata,
RELAY_SOURCE_LOCATION_V4,
registerAndFundAsset,
Expand Down
Loading

0 comments on commit a322ae9

Please sign in to comment.