Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pallet-xcm precompile #35

Merged
merged 23 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ flume = "0.11.0"
jsonrpsee = { version = "0.20.3" }
hex-literal = "0.4.1"

# Moonkit
pallet-foreign-asset-creator = { path = "pallets/foreign-asset-creator", default-features = false }

# Substrate (wasm)
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.0", default-features = false }
Expand Down
76 changes: 76 additions & 0 deletions precompiles/pallet-xcm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[package]
name = "pallet-evm-precompile-xcm"
authors = { workspace = true }
description = "A Precompile to make pallet-xcm accessible to pallet-evm"
edition = "2021"
version = "0.1.0"

[dependencies]
log = { workspace = true }
num_enum = { workspace = true }

# Moonbeam
precompile-utils = { workspace = true }
xcm-primitives = { workspace = true }

# Substrate
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
sp-weights = { workspace = true }

# Frontier
evm = { workspace = true, features = [ "with-codec" ] }
fp-evm = { workspace = true }
pallet-evm = { workspace = true, features = [ "forbid-evm-reentrancy" ] }

# Polkadot
xcm = { workspace = true }
pallet-xcm = { workspace = true }

# Cumulus
cumulus-primitives-core = { workspace = true }

[dev-dependencies]
derive_more = { workspace = true }

# Moonbeam
precompile-utils = { workspace = true, features = [ "testing", "codec-xcm" ] }
xcm-primitives = { workspace = true }

# Substrate
pallet-assets = { workspace = true, features = [ "std" ] }
pallet-balances = { workspace = true, features = [ "std", "insecure_zero_ed" ] }
pallet-foreign-asset-creator = { workspace = true, features = [ "std" ] }
pallet-timestamp = { workspace = true }
parity-scale-codec = { workspace = true, features = [ "max-encoded-len" ] }
scale-info = { workspace = true, features = [ "derive" ] }
sp-io = { workspace = true }

# Polkadot
xcm-builder = { workspace = true }
xcm-executor = { workspace = true }

[features]
default = [ "std" ]
std = [
"cumulus-primitives-core/std",
"frame-support/std",
"frame-system/std",
"pallet-evm/std",
"pallet-xcm/std",
"precompile-utils/std",
"sp-core/std",
"sp-std/std",
"xcm/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm-primitives/std",
]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
]
75 changes: 75 additions & 0 deletions precompiles/pallet-xcm/XcmInterface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.8.3;

/// @author The Moonbeam Team
/// @title XCM precompile Interface
/// @dev The interface that Solidity contracts use to interact with the substrate pallet-xcm.
interface XCM {
// A location is defined by its number of parents and the encoded junctions (interior)
struct Location {
uint8 parents;
bytes[] interior;
}

// Support for Weights V2
struct Weight {
uint64 refTime;
uint64 proofSize;
}

// A way to represent fungible assets in XCM
struct AssetLocationInfo {
Location location;
uint256 amount;
}

struct AssetAddressInfo {
address asset;
uint256 amount;
}

/// @dev Function to send assets via XCM using transfer_assets() pallet-xcm extrinsic.
/// @custom:selector 59df8416
/// @param dest The destination chain.
/// @param beneficiary The actual account that will receive the tokens in dest.
/// @param assets The combination (array) of assets to send.
/// @param feeAssetItem The index of the asset that will be used to pay for fees.
/// @param weight The weight to be used for the whole XCM operation.
/// (uint64::MAX in refTime means Unlimited weight)
function transferAssetsLocation(
Location memory dest,
Location memory beneficiary,
AssetLocationInfo[] memory assets,
uint32 feeAssetItem,
Weight memory weight
) external;

/// TODO add docs
/// @custom:selector b489262e
function transferAssetsToPara20(
uint32 paraId,
address beneficiary,
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
AssetAddressInfo[] memory assets,
uint32 feeAssetItem,
Weight memory weight
) external;

/// TODO add docs
/// @custom:selector 4461e6f5
function transferAssetsToPara32(
uint32 paraId,
bytes32 beneficiary,
AssetAddressInfo[] memory assets,
uint32 feeAssetItem,
Weight memory weight
) external;

/// TODO add docs
/// @custom:selector d7c89659
function transferAssetsToRelay(
bytes32 beneficiary,
AssetAddressInfo[] memory assets,
uint32 feeAssetItem,
Weight memory weight
) external;
}
Loading
Loading