Skip to content

Commit

Permalink
add pallet-xcm precompile to MB and MR with TS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusrodri committed Oct 5, 2024
1 parent 4bd16bf commit ba148c7
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 64 deletions.
35 changes: 20 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -337,23 +337,23 @@ westend-runtime = { git = "https://github.com/moonbeam-foundation/polkadot-sdk",
xcm-simulator = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-stable2407" }

# Moonkit (wasm)
async-backing-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-stable2407", default-features = false }
moonkit-xcm-primitives = { package = "xcm-primitives", git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-stable2407", default-features = false }
nimbus-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-stable2407", default-features = false }
pallet-async-backing = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-stable2407", default-features = false }
pallet-author-inherent = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-stable2407", default-features = false }
pallet-author-mapping = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-stable2407", default-features = false }
pallet-author-slot-filter = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-stable2407", default-features = false }
pallet-emergency-para-xcm = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-stable2407", default-features = false }
pallet-evm-precompile-xcm = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-stable2407", default-features = false }
pallet-maintenance-mode = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-stable2407", default-features = false }
pallet-migrations = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-stable2407", default-features = false }
pallet-randomness = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-stable2407", default-features = false }
pallet-relay-storage-roots = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-stable2407", default-features = false }
session-keys-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-stable2407", default-features = false }
async-backing-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "agustin-xcm-transfer-assets-using-temporary", default-features = false }
moonkit-xcm-primitives = { package = "xcm-primitives", git = "https://github.com/Moonsong-Labs/moonkit", branch = "agustin-xcm-transfer-assets-using-temporary", default-features = false }
nimbus-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "agustin-xcm-transfer-assets-using-temporary", default-features = false }
pallet-async-backing = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "agustin-xcm-transfer-assets-using-temporary", default-features = false }
pallet-author-inherent = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "agustin-xcm-transfer-assets-using-temporary", default-features = false }
pallet-author-mapping = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "agustin-xcm-transfer-assets-using-temporary", default-features = false }
pallet-author-slot-filter = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "agustin-xcm-transfer-assets-using-temporary", default-features = false }
pallet-emergency-para-xcm = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "agustin-xcm-transfer-assets-using-temporary", default-features = false }
pallet-evm-precompile-xcm = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "agustin-xcm-transfer-assets-using-temporary", default-features = false }
pallet-maintenance-mode = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "agustin-xcm-transfer-assets-using-temporary", default-features = false }
pallet-migrations = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "agustin-xcm-transfer-assets-using-temporary", default-features = false }
pallet-randomness = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "agustin-xcm-transfer-assets-using-temporary", default-features = false }
pallet-relay-storage-roots = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "agustin-xcm-transfer-assets-using-temporary", default-features = false }
session-keys-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "agustin-xcm-transfer-assets-using-temporary", default-features = false }

# Moonkit (client)
nimbus-consensus = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-stable2407" }
nimbus-consensus = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "agustin-xcm-transfer-assets-using-temporary" }

# Other (wasm)
async-trait = { version = "0.1.42" }
Expand Down
2 changes: 2 additions & 0 deletions runtime/moonbeam/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ nimbus-primitives = { workspace = true }
pallet-async-backing = { workspace = true }
pallet-author-inherent = { workspace = true }
pallet-author-slot-filter = { workspace = true }
pallet-evm-precompile-xcm = { workspace = true }
pallet-relay-storage-roots = { workspace = true }

# Benchmarking
Expand Down Expand Up @@ -256,6 +257,7 @@ std = [
"pallet-evm-precompile-referenda/std",
"pallet-evm-precompile-relay-encoder/std",
"pallet-evm-precompile-relay-verifier/std",
"pallet-evm-precompile-xcm/std",
"pallet-evm-precompile-xcm-transactor/std",
"pallet-evm-precompile-xcm-utils/std",
"pallet-evm-precompile-xtokens/std",
Expand Down
35 changes: 31 additions & 4 deletions runtime/moonbeam/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.

use crate::{
asset_config::ForeignAssetInstance, xcm_config::XcmExecutorConfig, OpenTechCommitteeInstance,
Runtime, TreasuryCouncilInstance,
asset_config::ForeignAssetInstance,
xcm_config::{AssetType, XcmExecutorConfig},
AccountId, AssetId, AssetManager, Balances, Erc20XcmBridge, OpenTechCommitteeInstance, Runtime,
TreasuryCouncilInstance, H160,
};
use crate::{AssetId, H160};
use frame_support::parameter_types;
use moonbeam_runtime_common::weights as moonbeam_weights;
use moonkit_xcm_primitives::AccountIdAssetIdConversion;
use moonkit_xcm_primitives::{
location_matcher::{Erc20PalletMatcher, ForeignAssetMatcher, SingleAddressMatcher},
AccountIdAssetIdConversion,
};
use pallet_evm_precompile_author_mapping::AuthorMappingPrecompile;
use pallet_evm_precompile_balances_erc20::{Erc20BalancesPrecompile, Erc20Metadata};
use pallet_evm_precompile_batch::BatchPrecompile;
Expand All @@ -45,6 +49,7 @@ use pallet_evm_precompile_relay_encoder::RelayEncoderPrecompile;
use pallet_evm_precompile_relay_verifier::RelayDataVerifierPrecompile;
use pallet_evm_precompile_sha3fips::Sha3FIPS256;
use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256};
use pallet_evm_precompile_xcm::PalletXcmPrecompile;
use pallet_evm_precompile_xcm_transactor::{
v1::XcmTransactorPrecompileV1, v2::XcmTransactorPrecompileV2, v3::XcmTransactorPrecompileV3,
};
Expand All @@ -54,6 +59,7 @@ use pallet_evm_precompileset_assets_erc20::Erc20AssetsPrecompileSet;
use pallet_precompile_benchmarks::WeightInfo;
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 @@ -93,13 +99,29 @@ pub const FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX: &[u8] = &[255u8; 4];
/// to Erc20AssetsPrecompileSet being marked as local
pub const LOCAL_ASSET_PRECOMPILE_ADDRESS_PREFIX: &[u8] = &[255u8, 255u8, 255u8, 254u8];

/// Const to identify ERC20_BALANCES_PRECOMPILE address
pub const ERC20_BALANCES_PRECOMPILE: u64 = 2050;

parameter_types! {
pub ForeignAssetPrefix: &'static [u8] = FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX;
pub LocalAssetPrefix: &'static [u8] = LOCAL_ASSET_PRECOMPILE_ADDRESS_PREFIX;
}

type EthereumPrecompilesChecks = (AcceptDelegateCall, CallableByContract, CallableByPrecompile);

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

// The pallet-balances address is identified by ERC20_BALANCES_PRECOMPILE const
type SingleAddressMatch = SingleAddressMatcher<AccountId, ERC20_BALANCES_PRECOMPILE, Balances>;

// Type that matches an AccountId with a foreign asset address (if any)
type ForeignAssetMatch = ForeignAssetMatcher<AccountId, AssetId, Runtime, AssetIdToLocationManager>;

// Erc20XcmBridge pallet is used to match ERC20s
type Erc20Match = Erc20PalletMatcher<AccountId, Erc20XcmBridge>;

#[precompile_utils::precompile_name_from_address]
type MoonbeamPrecompilesAt<R> = (
// Ethereum precompiles:
Expand Down Expand Up @@ -249,6 +271,11 @@ type MoonbeamPrecompilesAt<R> = (
RelayDataVerifierPrecompile<R>,
(CallableByContract, CallableByPrecompile),
>,
PrecompileAt<
AddressU64<2074>,
PalletXcmPrecompile<R, (SingleAddressMatch, ForeignAssetMatch, Erc20Match)>,
(CallableByContract, CallableByPrecompile),
>,
);

pub struct DisabledLocalAssets<Runtime>(sp_std::marker::PhantomData<Runtime>);
Expand Down
2 changes: 2 additions & 0 deletions runtime/moonriver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ nimbus-primitives = { workspace = true }
pallet-async-backing = { workspace = true }
pallet-author-inherent = { workspace = true }
pallet-author-slot-filter = { workspace = true }
pallet-evm-precompile-xcm = { workspace = true }
pallet-relay-storage-roots = { workspace = true }

# Benchmarking
Expand Down Expand Up @@ -257,6 +258,7 @@ std = [
"pallet-evm-precompile-referenda/std",
"pallet-evm-precompile-relay-encoder/std",
"pallet-evm-precompile-relay-verifier/std",
"pallet-evm-precompile-xcm/std",
"pallet-evm-precompile-xcm-transactor/std",
"pallet-evm-precompile-xcm-utils/std",
"pallet-evm-precompile-xtokens/std",
Expand Down
Loading

0 comments on commit ba148c7

Please sign in to comment.