-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for pallet-xcm precompile (#35)
* add pallet-xcm precompile * update interface docs * update comment for Unlimited weight * add comment in record_cost * mock cleanup * remove custom address from solidity interface * start converter implementation (PoC) * use size_of in AssetIdInfo * fmt * refactor converter * fmt * add Erc20PalletMatcher and adapt mock * remove unused import * minor fixes * add new functions * refactor ForeignAssetMatcher * rust fmt * add more tests and handle db reads costs * fix tests * use proper origin in mock * update solidity interface docs * remove TODO comment
- Loading branch information
Showing
14 changed files
with
1,699 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, features = ["codec-xcm"] } | ||
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", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// 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 using Location format | ||
struct AssetLocationInfo { | ||
Location location; | ||
uint256 amount; | ||
} | ||
|
||
// A way to represent fungible assets in XCM using address format | ||
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 on 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; | ||
|
||
/// @dev Function to send assets via XCM to a 20 byte-like parachain | ||
/// using transfer_assets() pallet-xcm extrinsic. | ||
/// @custom:selector b489262e | ||
/// @param paraId The para-id of the destination chain. | ||
/// @param beneficiary The actual account that will receive the tokens on paraId destination. | ||
/// @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 transferAssetsToPara20( | ||
uint32 paraId, | ||
address beneficiary, | ||
AssetAddressInfo[] memory assets, | ||
uint32 feeAssetItem, | ||
Weight memory weight | ||
) external; | ||
|
||
/// @dev Function to send assets via XCM to a 32 byte-like parachain | ||
/// using transfer_assets() pallet-xcm extrinsic. | ||
/// @custom:selector 4461e6f5 | ||
/// @param paraId The para-id of the destination chain. | ||
/// @param beneficiary The actual account that will receive the tokens on paraId destination. | ||
/// @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 transferAssetsToPara32( | ||
uint32 paraId, | ||
bytes32 beneficiary, | ||
AssetAddressInfo[] memory assets, | ||
uint32 feeAssetItem, | ||
Weight memory weight | ||
) external; | ||
|
||
/// @dev Function to send assets via XCM to the relay chain | ||
/// using transfer_assets() pallet-xcm extrinsic. | ||
/// @custom:selector d7c89659 | ||
/// @param beneficiary The actual account that will receive the tokens on the relay chain. | ||
/// @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 transferAssetsToRelay( | ||
bytes32 beneficiary, | ||
AssetAddressInfo[] memory assets, | ||
uint32 feeAssetItem, | ||
Weight memory weight | ||
) external; | ||
} |
Oops, something went wrong.