From b1e45cd862a02e76c3f2a9ce9bb9c6952fd85515 Mon Sep 17 00:00:00 2001
From: WMQ <46511820+wangminqi@users.noreply.github.com>
Date: Fri, 19 Jul 2024 19:15:35 +0800
Subject: [PATCH 1/3] P-901: replace orml with pallet_assets (#2895)
* feat: initial replace orml with pallet_assets
* chore
* chore
* chore: cargo lock
* chore: rust toolchain
* chore: rust toolchain
* debug: copy right
* debug: copy right
* feat: use polkadot frontier instead
* feat: using polkadot frontier
* debug: add utils locally
* chore
* chore
* chore
* chore
* feat: improve evm precompiles
* chore
* chore
* chore
* chore
* chore
* chore
* chore
* chore
* chore
* chore
* chore
* chore
* chore
* chore: cargo lock
* chore
* chore
* chore
* chore
* chore
* chore: try make sp-runtime with std feature
* chore
* chore
* chore
* chore
* chore: precompiles utils macro with features to include sp-runtime std feature
* chore: clippy
* chore
* chore
* chore: limit pallet_assets creating origin
* chore
* chore: use Fungibles instead of Orml trait in test
* fix
* chore
* chore
* chore
* chore
* chore
* chore
* chore
* chore
* chore
* chore
* chore
* chore
* chore: repalce pallet_assets impl with stricter prohibit creating
* chore
* chore
* chore
* chore: weird clippy, allow items_after_test_module
* debug: fix std feature
* chore
* chore
* chore
* chore
* chore: this should work
* chore
* chore: try replace with sp-runtime std
* chore
* chore: I do not want to change in this way, but need confirm why
* chore
* chore
* chore
* chore
* chore
* feat: exclude precompiles-utils as memebrs to avoid clippy check
* chore
* debug: add missing asset registing for testing
* chore: Cargo lock
* feat: rely on external package for avoiding all-features clippy check
* feat: disable integration ts test on precompile
* debug: add comment/license
---------
Signed-off-by: WMQ <46511820+wangminqi@users.noreply.github.com>
---
Cargo.lock | 233 ++++-
Cargo.toml | 13 +-
.../docker/litentry/rococo-dev-2106.json | 2 +-
node/src/chain_specs/litentry.rs | 2 +-
node/src/chain_specs/litmus.rs | 2 +-
node/src/chain_specs/rococo.rs | 2 +-
node/src/tracing.rs | 2 +-
pallets/bridge-transfer/src/lib.rs | 2 +-
pallets/bridge/src/lib.rs | 5 +-
.../{utils => assets-erc20}/Cargo.toml | 37 +-
precompiles/assets-erc20/ERC20.sol | 141 +++
precompiles/assets-erc20/src/lib.rs | 540 ++++++++++
precompiles/assets-erc20/src/mock.rs | 256 +++++
precompiles/assets-erc20/src/tests.rs | 981 ++++++++++++++++++
precompiles/bridge-transfer/src/lib.rs | 102 +-
precompiles/bridge-transfer/src/mock.rs | 31 +-
precompiles/bridge-transfer/src/tests.rs | 18 +-
precompiles/parachain-staking/src/lib.rs | 765 ++------------
precompiles/parachain-staking/src/mock.rs | 32 +-
precompiles/parachain-staking/src/tests.rs | 40 +-
precompiles/utils/macro/Cargo.toml | 19 -
precompiles/utils/macro/src/lib.rs | 132 ---
precompiles/utils/macro/tests/tests.rs | 45 -
precompiles/utils/src/data.rs | 585 -----------
precompiles/utils/src/lib.rs | 398 -------
precompiles/utils/src/testing.rs | 417 --------
precompiles/utils/src/tests.rs | 727 -------------
primitives/core/src/assertion/mod.rs | 5 +-
primitives/core/src/assertion/web3_token.rs | 15 +-
primitives/core/src/error.rs | 2 +-
primitives/core/src/identity.rs | 2 +-
runtime/common/Cargo.toml | 5 +-
runtime/common/src/tests/xcm_parachain/mod.rs | 84 +-
runtime/common/src/xcm_impl.rs | 4 +-
runtime/litentry/Cargo.toml | 6 +-
runtime/litentry/src/asset_config.rs | 66 +-
runtime/litentry/src/lib.rs | 4 +-
runtime/litentry/src/xcm_config.rs | 8 +-
runtime/litmus/Cargo.toml | 6 +-
runtime/litmus/src/asset_config.rs | 66 +-
runtime/litmus/src/lib.rs | 4 +-
runtime/litmus/src/xcm_config.rs | 10 +-
runtime/rococo/Cargo.toml | 14 +-
runtime/rococo/src/asset_config.rs | 79 +-
runtime/rococo/src/lib.rs | 5 +-
runtime/rococo/src/precompiles.rs | 179 ++--
runtime/rococo/src/xcm_config.rs | 10 +-
rust-toolchain.toml | 2 +-
scripts/run-ts-test.sh | 2 +-
.../precompile-contract.test.ts | 88 +-
50 files changed, 2712 insertions(+), 3483 deletions(-)
rename precompiles/{utils => assets-erc20}/Cargo.toml (54%)
create mode 100644 precompiles/assets-erc20/ERC20.sol
create mode 100644 precompiles/assets-erc20/src/lib.rs
create mode 100644 precompiles/assets-erc20/src/mock.rs
create mode 100644 precompiles/assets-erc20/src/tests.rs
delete mode 100644 precompiles/utils/macro/Cargo.toml
delete mode 100644 precompiles/utils/macro/src/lib.rs
delete mode 100644 precompiles/utils/macro/tests/tests.rs
delete mode 100644 precompiles/utils/src/data.rs
delete mode 100644 precompiles/utils/src/lib.rs
delete mode 100644 precompiles/utils/src/testing.rs
delete mode 100644 precompiles/utils/src/tests.rs
diff --git a/Cargo.lock b/Cargo.lock
index 2453dafc85..d45a946cde 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -891,6 +891,12 @@ dependencies = [
"toml 0.8.2",
]
+[[package]]
+name = "case"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd6c0e7b807d60291f42f33f58480c0bfafe28ed08286446f45e463728cf9c1c"
+
[[package]]
name = "cc"
version = "1.0.79"
@@ -2667,6 +2673,24 @@ dependencies = [
"triehash",
]
+[[package]]
+name = "ethereum"
+version = "0.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2e04d24d20b8ff2235cffbf242d5092de3aa45f77c5270ddbfadd2778ca13fea"
+dependencies = [
+ "bytes",
+ "ethereum-types",
+ "hash-db 0.16.0",
+ "hash256-std-hasher",
+ "parity-scale-codec",
+ "rlp",
+ "scale-info",
+ "serde",
+ "sha3",
+ "trie-root",
+]
+
[[package]]
name = "ethereum-types"
version = "0.14.1"
@@ -2697,7 +2721,7 @@ checksum = "f4448c65b71e8e2b9718232d84d09045eeaaccb2320494e6bd6dbf7e58fec8ff"
dependencies = [
"auto_impl",
"environmental",
- "ethereum",
+ "ethereum 0.14.0",
"evm-core 0.37.0",
"evm-gasometer 0.37.0",
"evm-runtime 0.37.0",
@@ -2717,7 +2741,7 @@ source = "git+https://github.com/rust-blockchain/evm?rev=b7b82c7e1fc57b7449d6dfa
dependencies = [
"auto_impl",
"environmental",
- "ethereum",
+ "ethereum 0.14.0",
"evm-core 0.39.0",
"evm-gasometer 0.39.0",
"evm-runtime 0.39.0",
@@ -2730,6 +2754,27 @@ dependencies = [
"sha3",
]
+[[package]]
+name = "evm"
+version = "0.41.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "767f43e9630cc36cf8ff2777cbb0121b055f0d1fd6eaaa13b46a1808f0d0e7e9"
+dependencies = [
+ "auto_impl",
+ "environmental",
+ "ethereum 0.15.0",
+ "evm-core 0.41.0",
+ "evm-gasometer 0.41.0",
+ "evm-runtime 0.41.0",
+ "log",
+ "parity-scale-codec",
+ "primitive-types",
+ "rlp",
+ "scale-info",
+ "serde",
+ "sha3",
+]
+
[[package]]
name = "evm-core"
version = "0.37.0"
@@ -2753,6 +2798,18 @@ dependencies = [
"serde",
]
+[[package]]
+name = "evm-core"
+version = "0.41.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d1da6cedc5cedb4208e59467106db0d1f50db01b920920589f8e672c02fdc04f"
+dependencies = [
+ "parity-scale-codec",
+ "primitive-types",
+ "scale-info",
+ "serde",
+]
+
[[package]]
name = "evm-gasometer"
version = "0.37.0"
@@ -2776,6 +2833,18 @@ dependencies = [
"primitive-types",
]
+[[package]]
+name = "evm-gasometer"
+version = "0.41.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1dc0eb591abc5cd7b05bef6a036c2bb6c66ab6c5e0c5ce94bfe377ab670b1fd7"
+dependencies = [
+ "environmental",
+ "evm-core 0.41.0",
+ "evm-runtime 0.41.0",
+ "primitive-types",
+]
+
[[package]]
name = "evm-runtime"
version = "0.37.0"
@@ -2801,13 +2870,26 @@ dependencies = [
"sha3",
]
+[[package]]
+name = "evm-runtime"
+version = "0.41.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "84bbe09b64ae13a29514048c1bb6fda6374ac0b4f6a1f15a443348ab88ef42cd"
+dependencies = [
+ "auto_impl",
+ "environmental",
+ "evm-core 0.41.0",
+ "primitive-types",
+ "sha3",
+]
+
[[package]]
name = "evm-tracing-events"
version = "0.1.0"
source = "git+https://github.com/litentry/astar-frame?branch=polkadot-v0.9.42#d9a49c58f248f49e274b0730b8f4ef7f1e72c4b5"
dependencies = [
"environmental",
- "ethereum",
+ "ethereum 0.14.0",
"ethereum-types",
"evm 0.37.0",
"evm-gasometer 0.37.0",
@@ -2887,6 +2969,12 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
+[[package]]
+name = "faster-hex"
+version = "0.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "51e2ce894d53b295cf97b05685aa077950ff3e8541af83217fc720a6437169f8"
+
[[package]]
name = "fastrand"
version = "1.9.0"
@@ -2989,7 +3077,7 @@ name = "fc-rpc"
version = "2.0.0-dev"
source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.42#2499d18c936edbcb7fcb711827db7abb9b4f4da4"
dependencies = [
- "ethereum",
+ "ethereum 0.14.0",
"ethereum-types",
"evm 0.39.1",
"fc-db",
@@ -3039,7 +3127,7 @@ name = "fc-rpc-core"
version = "1.1.0-dev"
source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.42#2499d18c936edbcb7fcb711827db7abb9b4f4da4"
dependencies = [
- "ethereum",
+ "ethereum 0.14.0",
"ethereum-types",
"jsonrpsee",
"rustc-hex",
@@ -3052,7 +3140,7 @@ name = "fc-storage"
version = "1.0.0-dev"
source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.42#2499d18c936edbcb7fcb711827db7abb9b4f4da4"
dependencies = [
- "ethereum",
+ "ethereum 0.14.0",
"ethereum-types",
"fp-rpc",
"fp-storage",
@@ -3229,7 +3317,7 @@ name = "fp-consensus"
version = "2.0.0-dev"
source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.42#2499d18c936edbcb7fcb711827db7abb9b4f4da4"
dependencies = [
- "ethereum",
+ "ethereum 0.14.0",
"parity-scale-codec",
"sp-core",
"sp-runtime",
@@ -3241,7 +3329,7 @@ name = "fp-ethereum"
version = "1.0.0-dev"
source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.42#2499d18c936edbcb7fcb711827db7abb9b4f4da4"
dependencies = [
- "ethereum",
+ "ethereum 0.14.0",
"ethereum-types",
"fp-evm",
"frame-support",
@@ -3270,7 +3358,7 @@ name = "fp-rpc"
version = "3.0.0-dev"
source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.42#2499d18c936edbcb7fcb711827db7abb9b4f4da4"
dependencies = [
- "ethereum",
+ "ethereum 0.14.0",
"ethereum-types",
"fp-evm",
"parity-scale-codec",
@@ -5500,11 +5588,11 @@ dependencies = [
"moonbeam-evm-tracer",
"moonbeam-rpc-primitives-debug",
"moonbeam-rpc-primitives-txpool",
- "orml-tokens",
"orml-traits",
"orml-xtokens",
"pallet-account-fix",
"pallet-asset-manager",
+ "pallet-assets",
"pallet-aura",
"pallet-authorship",
"pallet-balances",
@@ -5599,10 +5687,10 @@ dependencies = [
"moonbeam-evm-tracer",
"moonbeam-rpc-primitives-debug",
"moonbeam-rpc-primitives-txpool",
- "orml-tokens",
"orml-traits",
"orml-xtokens",
"pallet-asset-manager",
+ "pallet-assets",
"pallet-aura",
"pallet-authorship",
"pallet-balances",
@@ -6029,7 +6117,7 @@ name = "moonbeam-rpc-core-txpool"
version = "0.6.0"
source = "git+https://github.com/litentry/astar-frame?branch=polkadot-v0.9.42#d9a49c58f248f49e274b0730b8f4ef7f1e72c4b5"
dependencies = [
- "ethereum",
+ "ethereum 0.14.0",
"ethereum-types",
"fc-rpc-core",
"jsonrpsee",
@@ -6052,7 +6140,7 @@ name = "moonbeam-rpc-debug"
version = "0.1.0"
source = "git+https://github.com/litentry/astar-frame?branch=polkadot-v0.9.42#d9a49c58f248f49e274b0730b8f4ef7f1e72c4b5"
dependencies = [
- "ethereum",
+ "ethereum 0.14.0",
"ethereum-types",
"fc-consensus",
"fc-db",
@@ -6083,7 +6171,7 @@ version = "0.1.0"
source = "git+https://github.com/litentry/astar-frame?branch=polkadot-v0.9.42#d9a49c58f248f49e274b0730b8f4ef7f1e72c4b5"
dependencies = [
"environmental",
- "ethereum",
+ "ethereum 0.14.0",
"ethereum-types",
"hex",
"parity-scale-codec",
@@ -6101,7 +6189,7 @@ name = "moonbeam-rpc-primitives-txpool"
version = "0.6.0"
source = "git+https://github.com/litentry/astar-frame?branch=polkadot-v0.9.42#d9a49c58f248f49e274b0730b8f4ef7f1e72c4b5"
dependencies = [
- "ethereum",
+ "ethereum 0.14.0",
"parity-scale-codec",
"scale-info",
"sp-api",
@@ -6115,7 +6203,7 @@ name = "moonbeam-rpc-trace"
version = "0.6.0"
source = "git+https://github.com/litentry/astar-frame?branch=polkadot-v0.9.42#d9a49c58f248f49e274b0730b8f4ef7f1e72c4b5"
dependencies = [
- "ethereum",
+ "ethereum 0.14.0",
"ethereum-types",
"fc-consensus",
"fc-rpc",
@@ -6683,22 +6771,6 @@ dependencies = [
"num-traits",
]
-[[package]]
-name = "orml-tokens"
-version = "0.4.1-dev"
-source = "git+https://github.com/open-web3-stack/open-runtime-module-library?branch=polkadot-v0.9.42#4ae0372e2c624e6acc98305564b9d395f70814c0"
-dependencies = [
- "frame-support",
- "frame-system",
- "orml-traits",
- "parity-scale-codec",
- "scale-info",
- "serde",
- "sp-arithmetic",
- "sp-runtime",
- "sp-std",
-]
-
[[package]]
name = "orml-traits"
version = "0.4.1-dev"
@@ -6822,6 +6894,21 @@ dependencies = [
"xcm",
]
+[[package]]
+name = "pallet-assets"
+version = "4.0.0-dev"
+source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65"
+dependencies = [
+ "frame-benchmarking",
+ "frame-support",
+ "frame-system",
+ "parity-scale-codec",
+ "scale-info",
+ "sp-core",
+ "sp-runtime",
+ "sp-std",
+]
+
[[package]]
name = "pallet-aura"
version = "4.0.0-dev"
@@ -7206,7 +7293,7 @@ name = "pallet-ethereum"
version = "4.0.0-dev"
source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.42#2499d18c936edbcb7fcb711827db7abb9b4f4da4"
dependencies = [
- "ethereum",
+ "ethereum 0.14.0",
"ethereum-types",
"evm 0.39.1",
"fp-consensus",
@@ -7284,6 +7371,32 @@ dependencies = [
"sp-std",
]
+[[package]]
+name = "pallet-evm-precompile-assets-erc20"
+version = "0.1.0"
+dependencies = [
+ "derive_more",
+ "fp-evm",
+ "frame-support",
+ "frame-system",
+ "log",
+ "num_enum 0.7.2",
+ "pallet-assets",
+ "pallet-balances",
+ "pallet-evm",
+ "pallet-timestamp",
+ "parity-scale-codec",
+ "precompile-utils",
+ "scale-info",
+ "serde",
+ "sha3",
+ "slices",
+ "sp-core",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+]
+
[[package]]
name = "pallet-evm-precompile-blake2"
version = "2.0.0-dev"
@@ -9780,37 +9893,43 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "precompile-utils"
version = "0.1.0"
+source = "git+https://github.com/litentry/precompile-utils?branch=main#261ec953f6614bf634e86d9e8967eae3f84486a1"
dependencies = [
- "assert_matches",
- "evm 0.39.1",
+ "derive_more",
+ "environmental",
+ "evm 0.41.1",
"fp-evm",
"frame-support",
"frame-system",
+ "hex",
"hex-literal 0.4.1",
"impl-trait-for-tuples",
"log",
"num_enum 0.7.2",
"pallet-evm",
"parity-scale-codec",
- "precompile-utils-macro",
- "sha3",
+ "precompile-utils-macro-v2",
+ "scale-info",
+ "serde",
"similar-asserts",
"sp-core",
"sp-io",
"sp-runtime",
"sp-std",
- "xcm",
]
[[package]]
-name = "precompile-utils-macro"
+name = "precompile-utils-macro-v2"
version = "0.1.0"
+source = "git+https://github.com/litentry/precompile-utils?branch=main#261ec953f6614bf634e86d9e8967eae3f84486a1"
dependencies = [
+ "case",
"num_enum 0.7.2",
+ "prettyplease 0.2.20",
"proc-macro2",
"quote",
- "sha3",
- "syn 2.0.71",
+ "sp-core-hashing",
+ "syn 1.0.109",
]
[[package]]
@@ -9853,6 +9972,16 @@ dependencies = [
"syn 1.0.109",
]
+[[package]]
+name = "prettyplease"
+version = "0.2.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e"
+dependencies = [
+ "proc-macro2",
+ "syn 2.0.71",
+]
+
[[package]]
name = "primitive-types"
version = "0.12.1"
@@ -9997,7 +10126,7 @@ dependencies = [
"log",
"multimap",
"petgraph",
- "prettyplease",
+ "prettyplease 0.1.25",
"prost",
"prost-types",
"regex",
@@ -10533,6 +10662,7 @@ dependencies = [
"cumulus-primitives-parachain-inherent",
"cumulus-primitives-timestamp",
"cumulus-primitives-utility",
+ "fp-evm",
"fp-rpc",
"fp-self-contained",
"frame-benchmarking",
@@ -10547,11 +10677,12 @@ dependencies = [
"moonbeam-evm-tracer",
"moonbeam-rpc-primitives-debug",
"moonbeam-rpc-primitives-txpool",
- "orml-tokens",
+ "num_enum 0.7.2",
"orml-traits",
"orml-xtokens",
"pallet-account-fix",
"pallet-asset-manager",
+ "pallet-assets",
"pallet-aura",
"pallet-authorship",
"pallet-balances",
@@ -10565,6 +10696,7 @@ dependencies = [
"pallet-ethereum",
"pallet-evm",
"pallet-evm-assertions",
+ "pallet-evm-precompile-assets-erc20",
"pallet-evm-precompile-blake2",
"pallet-evm-precompile-bn128",
"pallet-evm-precompile-bridge-transfer",
@@ -10602,6 +10734,7 @@ dependencies = [
"polkadot-parachain",
"polkadot-primitives",
"polkadot-runtime-parachains",
+ "precompile-utils",
"runtime-common",
"scale-info",
"sp-api",
@@ -10796,10 +10929,10 @@ dependencies = [
"frame-support",
"frame-system",
"log",
- "orml-tokens",
"orml-traits",
"orml-xtokens",
"pallet-asset-manager",
+ "pallet-assets",
"pallet-authorship",
"pallet-balances",
"pallet-collective",
@@ -12588,6 +12721,18 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7"
+[[package]]
+name = "slices"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2086e458a369cdca838e9f6ed04b4cc2e3ce636d99abb80c9e2eada107749cf"
+dependencies = [
+ "faster-hex",
+ "proc-macro2",
+ "quote",
+ "syn 1.0.109",
+]
+
[[package]]
name = "slot-range-helper"
version = "0.9.42"
diff --git a/Cargo.toml b/Cargo.toml
index 2a14f01621..bd440bbeed 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,8 +17,6 @@ members = [
'pallets/teebag',
'pallets/vc-management',
'pallets/xcm-asset-manager',
- 'precompiles/*',
- 'precompiles/utils/macro',
'primitives/core',
'primitives/core/proc-macros',
'primitives/core/macros',
@@ -59,6 +57,8 @@ clap = { version = "4.3", features = ["derive"] }
der = { version = "0.6.0", default-features = false }
derive_more = { version = "0.99" }
env_logger = { version = "0.10.2" }
+environmental = { version = "1.1.2", default-features = false }
+evm = { version = "0.41.1", default-features = false }
impl-trait-for-tuples = { version = "0.2.2" }
log = { version = "0.4", default-features = false }
proc-macro2 = { version = "1" }
@@ -68,6 +68,7 @@ scale-info = { version = "2.11", default-features = false, features = ["derive"]
parity-scale-codec = { version = "3.6", default-features = false, features = ["derive", "max-encoded-len"] }
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
serde_json = { version = "1.0", default-features = false }
+slices = { version = "0.2.0" }
hex = { version = "0.4", default-features = false }
hex-literal = { version = "0.4.1", default-features = false }
similar-asserts = { version = "1.5.0" }
@@ -161,6 +162,7 @@ sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
+sp-core-hashing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
@@ -179,6 +181,7 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "pol
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
frame-try-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
+pallet-assets = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
pallet-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
pallet-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
@@ -223,7 +226,6 @@ pallet-collator-selection = { git = "https://github.com/paritytech/cumulus", bra
parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.42", default-features = false }
substrate-fixed = { git = "https://github.com/encointer/substrate-fixed", default-features = false }
-orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.42", default-features = false }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.42", default-features = false }
orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.42", default-features = false }
@@ -257,10 +259,13 @@ pallet-parachain-staking = { path = "pallets/parachain-staking", default-feature
pallet-score-staking = { path = "pallets/score-staking", default-features = false }
pallet-teebag = { path = "pallets/teebag", default-features = false }
pallet-vc-management = { path = "pallets/vc-management", default-features = false }
-precompile-utils = { path = "precompiles/utils", default-features = false }
+pallet-evm-precompile-assets-erc20 = { path = "precompiles/assets-erc20", default-features = false }
pallet-evm-precompile-bridge-transfer = { path = "precompiles/bridge-transfer", default-features = false }
pallet-evm-precompile-parachain-staking = { path = "precompiles/parachain-staking", default-features = false }
pallet-evm-assertions = { path = "pallets/evm-assertions", default-features = false }
+# This is a temporary pallet copy from Astar with polkadot-0.9.43
+# The official release of this pallet will be in frontier repo
+precompile-utils = { git = "https://github.com/litentry/precompile-utils", branch = "main", default-features = false }
[patch.crates-io]
ring = { git = "https://github.com/betrusted-io/ring-xous", branch = "0.16.20-cleanup" }
diff --git a/bitacross-worker/docker/litentry/rococo-dev-2106.json b/bitacross-worker/docker/litentry/rococo-dev-2106.json
index 3f7995675c..0a424c8a42 100644
--- a/bitacross-worker/docker/litentry/rococo-dev-2106.json
+++ b/bitacross-worker/docker/litentry/rococo-dev-2106.json
@@ -117,7 +117,7 @@
"polkadotXcm": {
"safeXcmVersion": 3
},
- "tokens": {
+ "assets": {
"balances": []
},
"identityManagement": {
diff --git a/node/src/chain_specs/litentry.rs b/node/src/chain_specs/litentry.rs
index 9590a5dbe7..dcb04f7b47 100644
--- a/node/src/chain_specs/litentry.rs
+++ b/node/src/chain_specs/litentry.rs
@@ -230,7 +230,7 @@ fn generate_genesis(
parachain_system: Default::default(),
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
transaction_payment: Default::default(),
- tokens: Default::default(),
+ assets: Default::default(),
teebag: TeebagConfig {
allow_sgx_debug_mode: true,
admin: None,
diff --git a/node/src/chain_specs/litmus.rs b/node/src/chain_specs/litmus.rs
index 5ccbc3b56a..e9a0369f33 100644
--- a/node/src/chain_specs/litmus.rs
+++ b/node/src/chain_specs/litmus.rs
@@ -239,7 +239,7 @@ fn generate_genesis(
parachain_system: Default::default(),
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
transaction_payment: Default::default(),
- tokens: Default::default(),
+ assets: Default::default(),
teebag: TeebagConfig {
allow_sgx_debug_mode: true,
admin: None,
diff --git a/node/src/chain_specs/rococo.rs b/node/src/chain_specs/rococo.rs
index 14a235e96c..d5b75098a3 100644
--- a/node/src/chain_specs/rococo.rs
+++ b/node/src/chain_specs/rococo.rs
@@ -247,7 +247,7 @@ fn generate_genesis(
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
vc_management: VCManagementConfig { admin: Some(root_key.clone()) },
transaction_payment: Default::default(),
- tokens: Default::default(),
+ assets: Default::default(),
ethereum: Default::default(),
evm: Default::default(),
teebag: TeebagConfig {
diff --git a/node/src/tracing.rs b/node/src/tracing.rs
index 3ee1f7bd17..86a6e81285 100644
--- a/node/src/tracing.rs
+++ b/node/src/tracing.rs
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Litentry. If not, see .
-///! EVM tracing RPC support.
+//! EVM tracing RPC support.
use crate::evm_tracing_types::{EthApi as EthApiCmd, EvmTracingConfig};
use fc_rpc::OverrideHandle;
diff --git a/pallets/bridge-transfer/src/lib.rs b/pallets/bridge-transfer/src/lib.rs
index 4a7056bb4e..64ef8aabb2 100644
--- a/pallets/bridge-transfer/src/lib.rs
+++ b/pallets/bridge-transfer/src/lib.rs
@@ -45,7 +45,7 @@ pub mod pallet {
type ResourceId = bridge::ResourceId;
- type BalanceOf = <::Currency as Currency<
+ pub type BalanceOf = <::Currency as Currency<
::AccountId,
>>::Balance;
diff --git a/pallets/bridge/src/lib.rs b/pallets/bridge/src/lib.rs
index 4a2c75d733..584c2b5106 100644
--- a/pallets/bridge/src/lib.rs
+++ b/pallets/bridge/src/lib.rs
@@ -42,11 +42,10 @@ pub mod pallet {
pallet_prelude::*,
{self as system},
};
- use parity_scale_codec::{Decode, Encode, EncodeLike};
- use scale_info::TypeInfo;
+ use parity_scale_codec::EncodeLike;
use sp_runtime::{
traits::{AccountIdConversion, Dispatchable},
- RuntimeDebug, SaturatedConversion,
+ SaturatedConversion,
};
use sp_std::prelude::*;
diff --git a/precompiles/utils/Cargo.toml b/precompiles/assets-erc20/Cargo.toml
similarity index 54%
rename from precompiles/utils/Cargo.toml
rename to precompiles/assets-erc20/Cargo.toml
index 49f3fd0b14..4acc1d8b34 100644
--- a/precompiles/utils/Cargo.toml
+++ b/precompiles/assets-erc20/Cargo.toml
@@ -1,49 +1,54 @@
[package]
+name = "pallet-evm-precompile-assets-erc20"
authors = ["Trust Computing GmbH "]
edition = '2021'
-name = 'precompile-utils'
version = '0.1.0'
[dependencies]
-assert_matches = { workspace = true }
-impl-trait-for-tuples = { workspace = true }
log = { workspace = true }
num_enum = { workspace = true }
-parity-scale-codec = { workspace = true }
-sha3 = { workspace = true }
-similar-asserts = { workspace = true, optional = true }
+slices = { workspace = true }
-precompile-utils-macro = { path = "macro" }
+precompile-utils = { workspace = true }
-fp-evm = { workspace = true }
+# Substrate
frame-support = { workspace = true }
frame-system = { workspace = true }
-pallet-evm = { workspace = true }
+pallet-assets = { workspace = true }
+pallet-balances = { workspace = true }
+parity-scale-codec = { workspace = true, features = ["max-encoded-len"] }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
-xcm = { workspace = true }
-# There's a problem with --all-features when this is moved under dev-deps
-evm = { git = "https://github.com/rust-blockchain/evm", rev = "b7b82c7e1fc57b7449d6dfa6826600de37cc1e65", default-features = false, optional = true }
+# Frontier
+fp-evm = { workspace = true }
+pallet-evm = { workspace = true }
[dev-dependencies]
-hex-literal = { workspace = true }
+derive_more = { workspace = true }
+serde = { workspace = true }
+sha3 = { workspace = true }
+scale-info = { workspace = true }
+
+precompile-utils = { workspace = true, features = ["testing"] }
+pallet-timestamp = { workspace = true, features = ["std"] }
[features]
default = ["std"]
std = [
- "evm/std",
"parity-scale-codec/std",
"fp-evm/std",
"frame-support/std",
"frame-system/std",
+ "pallet-assets/std",
"pallet-evm/std",
+ "pallet-balances/std",
+ "precompile-utils/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
- "xcm/std",
]
-testing = ["similar-asserts", "std"]
+runtime-benchmarks = []
diff --git a/precompiles/assets-erc20/ERC20.sol b/precompiles/assets-erc20/ERC20.sol
new file mode 100644
index 0000000000..32ca243f21
--- /dev/null
+++ b/precompiles/assets-erc20/ERC20.sol
@@ -0,0 +1,141 @@
+ pragma solidity ^0.8.0;
+
+ /**
+ * @title ERC20 interface
+ * @dev see https://github.com/ethereum/EIPs/issues/20
+ * @dev copied from https://github.com/OpenZeppelin/openzeppelin-contracts
+ */
+ interface IERC20 {
+
+ /**
+ * @dev Returns the name of the token.
+ * Selector: 06fdde03
+ */
+ function name() external view returns (string memory);
+
+ /**
+ * @dev Returns the symbol of the token.
+ * Selector: 95d89b41
+ */
+ function symbol() external view returns (string memory);
+
+ /**
+ * @dev Returns the decimals places of the token.
+ * Selector: 313ce567
+ */
+ function decimals() external view returns (uint8);
+
+ /**
+ * @dev Total number of tokens in existence
+ * Selector: 18160ddd
+ */
+ function totalSupply() external view returns (uint256);
+
+ /**
+ * @dev Gets the balance of the specified address.
+ * Selector: 70a08231
+ * @param who The address to query the balance of.
+ * @return An uint256 representing the amount owned by the passed address.
+ */
+ function balanceOf(address who) external view returns (uint256);
+
+ /**
+ * @dev Function to check the amount of tokens that an owner allowed to a spender.
+ * Selector: dd62ed3e
+ * @param owner address The address which owns the funds.
+ * @param spender address The address which will spend the funds.
+ * @return A uint256 specifying the amount of tokens still available for the spender.
+ */
+ function allowance(address owner, address spender)
+ external view returns (uint256);
+
+ /**
+ * @dev Transfer token for a specified address
+ * Selector: a9059cbb
+ * @param to The address to transfer to.
+ * @param value The amount to be transferred.
+ */
+ function transfer(address to, uint256 value) external returns (bool);
+
+ /**
+ * @dev Approve the passed address to spend the specified amount of tokens on behalf
+ * of msg.sender.
+ * Beware that changing an allowance with this method brings the risk that someone may
+ * use both the old
+ * and the new allowance by unfortunate transaction ordering. One possible solution to
+ * mitigate this race condition is to first reduce the spender's allowance to 0 and set
+ * the desired value afterwards:
+ * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
+ * Selector: 095ea7b3
+ * @param spender The address which will spend the funds.
+ * @param value The amount of tokens to be spent.
+ */
+ function approve(address spender, uint256 value)
+ external returns (bool);
+
+ /**
+ * @dev Transfer tokens from one address to another
+ * Selector: 23b872dd
+ * @param from address The address which you want to send tokens from
+ * @param to address The address which you want to transfer to
+ * @param value uint256 the amount of tokens to be transferred
+ */
+ function transferFrom(address from, address to, uint256 value)
+ external returns (bool);
+
+ /**
+ * @dev Event emited when a transfer has been performed.
+ * Selector: ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
+ * @param from address The address sending the tokens
+ * @param to address The address receiving the tokens.
+ * @param value uint256 The amount of tokens transfered.
+ */
+ event Transfer(
+ address indexed from,
+ address indexed to,
+ uint256 value
+ );
+
+ /**
+ * @dev Event emited when an approval has been registered.
+ * Selector: 8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925
+ * @param owner address Owner of the tokens.
+ * @param spender address Allowed spender.
+ * @param value uint256 Amount of tokens approved.
+ */
+ event Approval(
+ address indexed owner,
+ address indexed spender,
+ uint256 value
+ );
+}
+
+ /**
+ * @title Extension for ERC20 interface
+ * @dev Extended functions with minimum balance check as well as mint & burn.
+ */
+ interface IERC20Plus is IERC20 {
+
+ /**
+ * @dev Returns minimum balance an account must have to exist
+ * Selector: b9d1d49b
+ */
+ function minimumBalance() external view returns (uint256);
+
+ /**
+ * @dev Mints the specified amount of asset for the beneficiary.
+ * This operation will increase the total supply.
+ * Only usable by asset admin.
+ * Selector: 40c10f19
+ */
+ function mint(address beneficiary, uint256 amount) external returns (bool);
+
+ /**
+ * @dev Burns by up to the specified amount of asset from the target.
+ * This operation will increase decrease the total supply.
+ * Only usable by asset admin.
+ * Selector: 9dc29fac
+ */
+ function burn(address who, uint256 amount) external returns (bool);
+}
+
diff --git a/precompiles/assets-erc20/src/lib.rs b/precompiles/assets-erc20/src/lib.rs
new file mode 100644
index 0000000000..5a8294b059
--- /dev/null
+++ b/precompiles/assets-erc20/src/lib.rs
@@ -0,0 +1,540 @@
+// Copyright 2020-2024 Trust Computing GmbH.
+// This file is part of Litentry.
+//
+// Litentry is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Litentry is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Litentry. If not, see .
+
+// Copyright 2019-2022 PureStake Inc.
+// Copyright 2022 Stake Technologies
+// This file is part of AssetsERC20 package, originally developed by Purestake Inc.
+// AssetsERC20 package used in Litentry Network in terms of GPLv3.
+//
+// AssetsERC20 is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// AssetsERC20 is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with AssetsERC20. If not, see .
+
+#![cfg_attr(not(feature = "std"), no_std)]
+
+use fp_evm::{ExitError, PrecompileHandle};
+use frame_support::{
+ dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo},
+ sp_runtime::traits::StaticLookup,
+ traits::{
+ fungibles::{
+ approvals::Inspect as ApprovalInspect, metadata::Inspect as MetadataInspect, Inspect,
+ },
+ OriginTrait,
+ },
+ DefaultNoBound,
+};
+use pallet_evm::AddressMapping;
+use precompile_utils::prelude::*;
+use sp_runtime::traits::Bounded;
+
+use sp_core::{Get, MaxEncodedLen, H160, U256};
+use sp_std::{
+ convert::{TryFrom, TryInto},
+ marker::PhantomData,
+};
+
+#[cfg(test)]
+mod mock;
+#[cfg(test)]
+mod tests;
+
+/// Solidity selector of the Transfer log, which is the Keccak of the Log signature.
+pub const SELECTOR_LOG_TRANSFER: [u8; 32] = keccak256!("Transfer(address,address,uint256)");
+
+/// Solidity selector of the Approval log, which is the Keccak of the Log signature.
+pub const SELECTOR_LOG_APPROVAL: [u8; 32] = keccak256!("Approval(address,address,uint256)");
+
+/// Alias for the Balance type for the provided Runtime and Instance.
+pub type BalanceOf = >::Balance;
+
+/// Alias for the Asset Id type for the provided Runtime and Instance.
+pub type AssetIdOf = >::AssetId;
+
+/// This trait ensure we can convert EVM address to AssetIds
+/// We will require Runtime to have this trait implemented
+pub trait AddressToAssetId {
+ // Get assetId from address
+ fn address_to_asset_id(address: H160) -> Option;
+
+ // Get address from AssetId
+ fn asset_id_to_address(asset_id: AssetId) -> H160;
+}
+
+/// The following distribution has been decided for the precompiles
+/// 0-1023: Ethereum Mainnet Precompiles
+/// 1024-2047 Precompiles that are not in Ethereum Mainnet but are neither Litentry specific
+/// 2048-4095 Litentry specific precompiles
+/// Asset precompiles can only fall between
+/// 0xFFFFFFFF00000000000000000000000000000000 - 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+/// The precompile for AssetId X, where X is a u128 (i.e.16 bytes), if 0XFFFFFFFF + Bytes(AssetId)
+/// In order to route the address to Erc20AssetsPrecompile, we first check whether the AssetId
+/// exists in pallet-assets
+/// We cannot do this right now, so instead we check whether the total supply is zero. If so, we
+/// do not route to the precompiles
+
+/// This means that every address that starts with 0xFFFFFFFF will go through an additional db read,
+/// but the probability for this to happen is 2^-32 for random addresses
+#[derive(Clone, DefaultNoBound)]
+pub struct Erc20AssetsPrecompileSet(
+ PhantomData<(Runtime, Instance)>,
+);
+
+impl Erc20AssetsPrecompileSet {
+ pub fn new() -> Self {
+ Self(PhantomData)
+ }
+}
+
+#[precompile_utils::precompile]
+#[precompile::precompile_set]
+#[precompile::test_concrete_types(mock::Runtime, ())]
+impl Erc20AssetsPrecompileSet
+where
+ Instance: 'static,
+ Runtime: pallet_assets::Config + pallet_evm::Config + frame_system::Config,
+ Runtime::RuntimeCall: Dispatchable + GetDispatchInfo,
+ Runtime::RuntimeCall: From>,
+ ::RuntimeOrigin: From