From 0932d7a3090496cb865de8f03d595b0d2614adb4 Mon Sep 17 00:00:00 2001 From: toints Date: Thu, 25 Apr 2024 10:29:30 +0800 Subject: [PATCH 1/2] perf(*): removed the binding relationship before transfer tokens between Substrate Account and EVM Account MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. use precompile contract to handle token transfers from EVM account to substrate account 2. removed claim_account() and dissolve() methods. --- Cargo.lock | 913 +++++++------- Cargo.toml | 2 + pallets/assets-bridge/src/lib.rs | 172 +-- pallets/assets-bridge/src/mock.rs | 10 +- pallets/assets-bridge/src/tests.rs | 42 +- .../precompile/transfer-to-magnet/Cargo.toml | 78 ++ .../precompile/transfer-to-magnet/README.md | 11 + .../contracts/AssetsBridgeAdaptor.sol | 57 + .../contracts/AssetsBridgeErc20.sol | 399 +++++++ .../contracts/AssetsBridgeErc20_ByteCode.txt | 1 + .../precompile/transfer-to-magnet/src/lib.rs | 264 +++++ .../precompile/transfer-to-magnet/src/mock.rs | 329 ++++++ .../transfer-to-magnet/src/tests.rs | 1048 +++++++++++++++++ runtime/Cargo.toml | 4 + runtime/src/lib.rs | 11 +- runtime/src/precompiles.rs | 22 +- 16 files changed, 2777 insertions(+), 586 deletions(-) create mode 100644 pallets/evm/precompile/transfer-to-magnet/Cargo.toml create mode 100644 pallets/evm/precompile/transfer-to-magnet/README.md create mode 100644 pallets/evm/precompile/transfer-to-magnet/contracts/AssetsBridgeAdaptor.sol create mode 100644 pallets/evm/precompile/transfer-to-magnet/contracts/AssetsBridgeErc20.sol create mode 100644 pallets/evm/precompile/transfer-to-magnet/contracts/AssetsBridgeErc20_ByteCode.txt create mode 100644 pallets/evm/precompile/transfer-to-magnet/src/lib.rs create mode 100644 pallets/evm/precompile/transfer-to-magnet/src/mock.rs create mode 100644 pallets/evm/precompile/transfer-to-magnet/src/tests.rs diff --git a/Cargo.lock b/Cargo.lock index 2214ef8..b5f817e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,7 +77,7 @@ version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" dependencies = [ - "getrandom 0.2.12", + "getrandom 0.2.14", "once_cell", "version_check", ] @@ -89,7 +89,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", - "getrandom 0.2.12", + "getrandom 0.2.14", "once_cell", "version_check", "zerocopy", @@ -97,18 +97,18 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] [[package]] name = "allocator-api2" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "always-assert" @@ -190,9 +190,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" [[package]] name = "approx" @@ -214,7 +214,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -601,28 +601,27 @@ dependencies = [ [[package]] name = "async-channel" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28243a43d821d11341ab73c80bed182dc015c514b951616cf79bd4af39af0c3" +checksum = "136d4d23bcc79e27423727b36823d86233aad06dfea531837b038394d11e9928" dependencies = [ "concurrent-queue", - "event-listener 5.2.0", - "event-listener-strategy 0.5.0", + "event-listener 5.3.0", + "event-listener-strategy 0.5.1", "futures-core", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", ] [[package]] name = "async-executor" -version = "1.8.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ae5ebefcc48e7452b4987947920dac9450be1110cadf34d1b8c116bdbaf97c" +checksum = "b10202063978b3351199d68f8b22c4e47e4b1b822f8d43fd862d5ea8c006b29a" dependencies = [ - "async-lock 3.3.0", "async-task", "concurrent-queue", - "fastrand 2.0.1", - "futures-lite 2.2.0", + "fastrand 2.0.2", + "futures-lite 2.3.0", "slab", ] @@ -668,10 +667,10 @@ dependencies = [ "cfg-if", "concurrent-queue", "futures-io", - "futures-lite 2.2.0", + "futures-lite 2.3.0", "parking", - "polling 3.5.0", - "rustix 0.38.31", + "polling 3.6.0", + "rustix 0.38.32", "slab", "tracing", "windows-sys 0.52.0", @@ -694,7 +693,7 @@ checksum = "d034b430882f8381900d3fe6f0aaa3ad94f2cb4ac519b429692a1bc2dda4ae7b" dependencies = [ "event-listener 4.0.3", "event-listener-strategy 0.4.0", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", ] [[package]] @@ -721,7 +720,7 @@ dependencies = [ "cfg-if", "event-listener 3.1.0", "futures-lite 1.13.0", - "rustix 0.38.31", + "rustix 0.38.32", "windows-sys 0.48.0", ] @@ -737,7 +736,7 @@ dependencies = [ "cfg-if", "futures-core", "futures-io", - "rustix 0.38.31", + "rustix 0.38.32", "signal-hook-registry", "slab", "windows-sys 0.48.0", @@ -751,13 +750,13 @@ checksum = "fbb36e985947064623dbd357f727af08ffd077f93d696782f3c56365fa2e2799" [[package]] name = "async-trait" -version = "0.1.77" +version = "0.1.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" +checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -770,7 +769,7 @@ dependencies = [ "futures-sink", "futures-util", "memchr", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", ] [[package]] @@ -802,20 +801,20 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] name = "autocfg" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "backtrace" -version = "0.3.69" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" dependencies = [ "addr2line 0.21.0", "cc", @@ -924,13 +923,13 @@ dependencies = [ "lazy_static", "lazycell", "peeking_take_while", - "prettyplease 0.2.16", + "prettyplease 0.2.19", "proc-macro2", "quote", "regex", "rustc-hash", "shlex", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -960,9 +959,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "bitvec" @@ -1032,9 +1031,9 @@ dependencies = [ [[package]] name = "blake3" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0231f06152bf547e9c2b5194f247cd97aacf6dcd8b15d8e5ec0663f64580da87" +checksum = "30cca6d3674597c30ddf2c587bf8d9d65c9a84d2326d941cc79c9842dfe0ef52" dependencies = [ "arrayref", "arrayvec 0.7.4", @@ -1088,12 +1087,12 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a37913e8dc4ddcc604f0c6d3bf2887c995153af3611de9e23c352b44c1b9118" dependencies = [ - "async-channel 2.2.0", + "async-channel 2.2.1", "async-lock 3.3.0", "async-task", - "fastrand 2.0.1", + "fastrand 2.0.2", "futures-io", - "futures-lite 2.2.0", + "futures-lite 2.3.0", "piper", "tracing", ] @@ -1150,9 +1149,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bs58" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5353f36341f7451062466f0b755b96ac3a9547e4d7f6b70d603fc721a7d7896" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" dependencies = [ "tinyvec", ] @@ -1168,9 +1167,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.15.4" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "byte-slice-cast" @@ -1186,9 +1185,9 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" [[package]] name = "bytemuck" -version = "1.14.3" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ef034f05691a48569bd920a96c81b9d91bbad1ab5ac7c4616c1f6ef36cb79f" +checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" [[package]] name = "byteorder" @@ -1198,9 +1197,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "bzip2-sys" @@ -1234,9 +1233,9 @@ dependencies = [ [[package]] name = "cargo-platform" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "694c8807f2ae16faecc43dc17d74b3eb042482789fd0eb64b39a2e04e087053f" +checksum = "24b1f0365a6c6bb4020cd05806fd0d33c44d38046b8bd7f0e40814b9763cabfc" dependencies = [ "serde", ] @@ -1263,9 +1262,9 @@ checksum = "fd6c0e7b807d60291f42f33f58480c0bfafe28ed08286446f45e463728cf9c1c" [[package]] name = "cc" -version = "1.0.90" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" +checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" dependencies = [ "jobserver", "libc", @@ -1282,9 +1281,9 @@ dependencies = [ [[package]] name = "cfg-expr" -version = "0.15.7" +version = "0.15.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa50868b64a9a6fda9d593ce778849ea8715cd2a3d2cc17ffdb4a2f2f2f1961d" +checksum = "d067ad48b8650848b989a59a86c6c36a995d02d2bf778d45c3c5d57bc2718f02" dependencies = [ "smallvec", ] @@ -1337,16 +1336,16 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.35" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", "js-sys", "num-traits", "wasm-bindgen", - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -1404,9 +1403,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.2" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b230ab84b0ffdf890d5a10abdbc8b83ae1c4918275daea1ab8801f71536b2651" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ "clap_builder", "clap_derive", @@ -1421,20 +1420,20 @@ dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim 0.11.0", + "strsim 0.11.1", "terminal_size", ] [[package]] name = "clap_derive" -version = "4.5.0" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -1493,12 +1492,12 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "comfy-table" -version = "7.1.0" +version = "7.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c64043d6c7b7a4c58e39e7efccfdea7b93d885a795d0c054a69dbbf4dd52686" +checksum = "b34115915337defe99b2aff5c2ce6771e5fbc4079f4b506301f5cf394c8452f7" dependencies = [ - "strum 0.25.0", - "strum_macros 0.25.3", + "strum 0.26.2", + "strum_macros 0.26.2", "unicode-width", ] @@ -1567,7 +1566,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" dependencies = [ - "getrandom 0.2.12", + "getrandom 0.2.14", "once_cell", "tiny-keccak", ] @@ -1749,9 +1748,9 @@ dependencies = [ [[package]] name = "crc" -version = "3.0.1" +version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" dependencies = [ "crc-catalog", ] @@ -2166,7 +2165,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -2501,7 +2500,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -2519,9 +2518,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.119" +version = "1.0.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "635179be18797d7e10edb9cd06c859580237750c7351f39ed9b298bfc17544ad" +checksum = "21db378d04296a84d8b7d047c36bb3954f0b46529db725d7e62fb02f9ba53ccc" dependencies = [ "cc", "cxxbridge-flags", @@ -2531,9 +2530,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.119" +version = "1.0.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9324397d262f63ef77eb795d900c0d682a34a43ac0932bec049ed73055d52f63" +checksum = "3e5262a7fa3f0bae2a55b767c223ba98032d7c328f5c13fa5cdc980b77fc0658" dependencies = [ "cc", "codespan-reporting", @@ -2541,24 +2540,24 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] name = "cxxbridge-flags" -version = "1.0.119" +version = "1.0.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a87ff7342ffaa54b7c61618e0ce2bbcf827eba6d55b923b83d82551acbbecfe5" +checksum = "be8dcadd2e2fb4a501e1d9e93d6e88e6ea494306d8272069c92d5a9edf8855c0" [[package]] name = "cxxbridge-macro" -version = "1.0.119" +version = "1.0.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70b5b86cf65fa0626d85720619d80b288013477a91a0389fa8bc716bf4903ad1" +checksum = "ad08a837629ad949b73d032c637653d069e909cffe4ee7870b02301939ce39cc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -2606,7 +2605,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -2628,7 +2627,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core 0.20.8", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -2659,9 +2658,9 @@ dependencies = [ [[package]] name = "der" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", "zeroize", @@ -2712,6 +2711,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive-syn-parse" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d65d7ce8132b7c0e54497a4d9a55a1c2a0912a0d786cf894472ba818fba45762" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + [[package]] name = "derive_more" version = "0.99.17" @@ -2811,7 +2821,7 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -2832,28 +2842,28 @@ dependencies = [ [[package]] name = "docify" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cc4fd38aaa9fb98ac70794c82a00360d1e165a87fbf96a8a91f9dfc602aaee2" +checksum = "43a2f138ad521dc4a2ced1a4576148a6a610b4c5923933b062a263130a6802ce" dependencies = [ "docify_macros", ] [[package]] name = "docify_macros" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63fa215f3a0d40fb2a221b3aa90d8e1fbb8379785a990cb60d62ac71ebdc6460" +checksum = "1a081e51fb188742f5a7a1164ad752121abcb22874b21e2c3b0dd040c515fdad" dependencies = [ "common-path", - "derive-syn-parse", + "derive-syn-parse 0.2.0", "once_cell", "proc-macro2", "quote", "regex", - "syn 2.0.52", + "syn 2.0.60", "termcolor", - "toml 0.8.11", + "toml 0.8.12", "walkdir", ] @@ -2871,9 +2881,9 @@ checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" [[package]] name = "downcast-rs" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] name = "dtoa" @@ -2978,9 +2988,9 @@ dependencies = [ [[package]] name = "either" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" dependencies = [ "serde", ] @@ -3016,7 +3026,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9720bba047d567ffc8a3cba48bf19126600e249ab7f128e9233e6376976a116" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "syn 1.0.109", @@ -3039,7 +3049,7 @@ checksum = "5c785274071b1b420972453b306eeca06acf4633829db4223b58a2a8c5953bc4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -3050,7 +3060,7 @@ checksum = "6fd000fd6988e73bbe993ea3db9b1aa64906ab88766d654973924340c8cddb42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -3168,7 +3178,7 @@ checksum = "d93877bcde0eb80ca09131a08d23f0a5c18a620b01db137dba666d18cd9b30c2" dependencies = [ "concurrent-queue", "parking", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", ] [[package]] @@ -3179,18 +3189,18 @@ checksum = "67b215c49b2b248c855fb73579eb1f4f26c38ffdc12973e20e07b91d78d5646e" dependencies = [ "concurrent-queue", "parking", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", ] [[package]] name = "event-listener" -version = "5.2.0" +version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b5fb89194fa3cad959b833185b3063ba881dbfc7030680b314250779fb4cc91" +checksum = "6d9944b8ca13534cdfb2800775f8dd4902ff3fc75a50101466decadfdf322a24" dependencies = [ "concurrent-queue", "parking", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", ] [[package]] @@ -3200,17 +3210,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "958e4d70b6d5e81971bebec42271ec641e7ff4e170a6fa605f2b8a8b65cb97d3" dependencies = [ "event-listener 4.0.3", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", ] [[package]] name = "event-listener-strategy" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "feedafcaa9b749175d5ac357452a9d41ea2911da598fde46ce1fe02c37751291" +checksum = "332f51cb23d20b0de8458b86580878211da09bcd4503cb579c225b3d124cabb3" dependencies = [ - "event-listener 5.2.0", - "pin-project-lite 0.2.13", + "event-listener 5.3.0", + "pin-project-lite 0.2.14", ] [[package]] @@ -3303,7 +3313,7 @@ dependencies = [ "prettier-please", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -3329,9 +3339,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.1" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" [[package]] name = "fatality" @@ -3581,9 +3591,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1676f435fc1dadde4d03e43f5d62b259e1ce5f40bd4ffb21db2b42ebe59c1382" +checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" [[package]] name = "file-per-thread-logger" @@ -3905,7 +3915,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -4036,7 +4046,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "Inflector", "cfg-expr", - "derive-syn-parse", + "derive-syn-parse 0.1.5", "expander 2.1.0", "frame-support-procedural-tools", "itertools 0.10.5", @@ -4045,7 +4055,7 @@ dependencies = [ "proc-macro2", "quote", "sp-crypto-hashing", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -4057,7 +4067,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -4067,7 +4077,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -4151,7 +4161,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29f9df8a11882c4e3335eb2d18a0137c505d9ca927470b0cac9c6f0ae07d28f7" dependencies = [ - "rustix 0.38.31", + "rustix 0.38.32", "windows-sys 0.48.0", ] @@ -4232,21 +4242,21 @@ dependencies = [ "futures-io", "memchr", "parking", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", "waker-fn", ] [[package]] name = "futures-lite" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445ba825b27408685aaecefd65178908c36c6e96aaf6d8599419d46e624192ba" +checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5" dependencies = [ - "fastrand 2.0.1", + "fastrand 2.0.2", "futures-core", "futures-io", "parking", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", ] [[package]] @@ -4257,7 +4267,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -4302,7 +4312,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", "pin-utils", "slab", ] @@ -4359,9 +4369,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" dependencies = [ "cfg-if", "libc", @@ -4424,9 +4434,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.24" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" dependencies = [ "bytes", "fnv", @@ -4434,7 +4444,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap 2.2.5", + "indexmap 2.2.6", "slab", "tokio", "tokio-util", @@ -4517,6 +4527,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.3.9" @@ -4623,7 +4639,7 @@ checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", "http", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", ] [[package]] @@ -4666,7 +4682,7 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", "socket2 0.5.6", "tokio", "tower-service", @@ -4839,9 +4855,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.5" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown 0.14.3", @@ -4983,15 +4999,15 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jobserver" -version = "0.1.28" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" +checksum = "685a7d121ee3f65ae4fddd72b25a04bb36b6af81bc0828f7d5434c0fe60fa3a2" dependencies = [ "libc", ] @@ -5093,7 +5109,7 @@ version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29110019693a4fa2dbda04876499d098fa16d70eba06b1e6e2b3f1b251419515" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro-crate 1.3.1", "proc-macro2", "quote", @@ -5213,9 +5229,9 @@ dependencies = [ [[package]] name = "landlock" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1530c5b973eeed4ac216af7e24baf5737645a6272e361f1fb95710678b67d9cc" +checksum = "9baa9eeb6e315942429397e617a190f4fdc696ef1ee0342939d641029cbb4ea7" dependencies = [ "enumflags2", "libc", @@ -5247,7 +5263,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -5265,7 +5281,7 @@ dependencies = [ "bytes", "futures", "futures-timer", - "getrandom 0.2.12", + "getrandom 0.2.14", "instant", "libp2p-allow-block-list", "libp2p-connection-limits", @@ -5563,7 +5579,7 @@ version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fba456131824ab6acd4c7bf61e9c0f0a3014b5fc9868ccb8e10d344594cdc4f" dependencies = [ - "heck", + "heck 0.4.1", "quote", "syn 1.0.109", ] @@ -5651,13 +5667,12 @@ dependencies = [ [[package]] name = "libredox" -version = "0.0.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "libc", - "redox_syscall 0.4.1", ] [[package]] @@ -5736,9 +5751,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.15" +version = "1.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "037731f5d3aaa87a5675e895b63ddff1a87624bc29f77004ea829809654e48f6" +checksum = "5e143b5e666b2695d28f6bca6497720813f699c9602dd7f5cac91008b8ada7f9" dependencies = [ "cc", "pkg-config", @@ -5895,7 +5910,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -5905,11 +5920,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "468155613a44cfd825f1fb0ffa532b018253920d404e6fca1e8d43155198a46d" dependencies = [ "const-random", - "derive-syn-parse", + "derive-syn-parse 0.1.5", "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -5920,7 +5935,7 @@ checksum = "9ea73aa640dc01d62a590d48c0c3521ed739d53b27f919b25c3551e233481654" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -5931,7 +5946,7 @@ checksum = "ef9d79ae96aaba821963320eb2b6e34d17df1e5a83d8a1985c29cc5be59577b3" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -6025,6 +6040,15 @@ dependencies = [ "regex-automata 0.1.10", ] +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "matches" version = "0.1.10" @@ -6043,9 +6067,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "memfd" @@ -6053,7 +6077,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" dependencies = [ - "rustix 0.38.31", + "rustix 0.38.32", ] [[package]] @@ -6399,9 +6423,9 @@ dependencies = [ [[package]] name = "nalgebra" -version = "0.32.4" +version = "0.32.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4541eb06dce09c0241ebbaab7102f0a01a0c8994afed2e5d0d66775016e25ac2" +checksum = "3ea4908d4f23254adda3daa60ffef0f1ac7b8c3e9a864cf3cc154b251908a2ef" dependencies = [ "approx", "matrixmultiply", @@ -6512,9 +6536,9 @@ dependencies = [ [[package]] name = "netlink-sys" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6471bf08e7ac0135876a9581bf3217ef0333c191c128d34878079f42ee150411" +checksum = "416060d346fbaf1f23f9512963e3e878f1a78e707cb699ba9215761754244307" dependencies = [ "bytes", "futures", @@ -6540,7 +6564,7 @@ version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "cfg-if", "libc", ] @@ -6579,11 +6603,21 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +checksum = "3135b08af27d103b0a51f2ae0f8632117b7b185ccf931445affa8df530576a41" dependencies = [ "num-bigint", "num-complex", @@ -6699,7 +6733,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -6762,7 +6796,7 @@ version = "0.10.64" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "cfg-if", "foreign-types", "libc", @@ -6779,7 +6813,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -6790,9 +6824,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.101" +version = "0.9.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dda2b0f344e78efc2facf7d195d098df0dd72151b26ab98da807afc26c198dff" +checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" dependencies = [ "cc", "libc", @@ -6830,7 +6864,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eedb646674596266dc9bb2b5c7eea7c36b32ecc7777eba0d510196972d72c4fd" dependencies = [ "expander 2.1.0", - "indexmap 2.2.5", + "indexmap 2.2.6", "itertools 0.11.0", "petgraph", "proc-macro-crate 1.3.1", @@ -6848,6 +6882,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "pallet-asset-conversion" version = "10.0.0" @@ -7255,7 +7295,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -7909,6 +7949,30 @@ dependencies = [ "sp-runtime 31.0.1", ] +[[package]] +name = "pallet-precompile-transfer-to-magnet" +version = "0.1.0" +dependencies = [ + "fp-account", + "fp-evm", + "frame-support", + "frame-system", + "hex", + "pallet-assets", + "pallet-assets-bridge", + "pallet-balances", + "pallet-evm", + "pallet-timestamp", + "parity-scale-codec", + "precompile-utils", + "scale-info", + "sp-core 28.0.0", + "sp-io 30.0.0", + "sp-runtime 31.0.1", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.0)", + "staging-xcm", +] + [[package]] name = "pallet-preimage" version = "28.0.0" @@ -8115,7 +8179,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -8362,7 +8426,7 @@ dependencies = [ [[package]] name = "parachain-magnet-node" -version = "0.5.6" +version = "0.6.0" dependencies = [ "array-bytes 6.2.2", "clap", @@ -8459,7 +8523,7 @@ dependencies = [ [[package]] name = "parachain-magnet-runtime" -version = "0.5.6" +version = "0.6.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -8512,6 +8576,7 @@ dependencies = [ "pallet-pot", "pallet-pot-runtime-api", "pallet-precompile-substrate-utils", + "pallet-precompile-transfer-to-magnet", "pallet-preimage", "pallet-ranked-collective", "pallet-referenda", @@ -8751,9 +8816,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.8" +version = "2.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56f8023d0fb78c8e03784ea1c7f3fa36e68a723138990b8d5a47d916b651e7a8" +checksum = "311fb059dee1a7b802f036316d790138c613a4e8b180c822e3925a662e9f0c95" dependencies = [ "memchr", "thiserror", @@ -8762,9 +8827,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.7.8" +version = "2.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0d24f72393fd16ab6ac5738bc33cdb6a9aa73f8b902e8fe29cf4e67d7dd1026" +checksum = "f73541b156d32197eecda1a4014d7f868fd2bcb3c550d5386087cfba442bf69c" dependencies = [ "pest", "pest_generator", @@ -8772,22 +8837,22 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.8" +version = "2.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdc17e2a6c7d0a492f0158d7a4bd66cc17280308bbaff78d5bef566dca35ab80" +checksum = "c35eeed0a3fab112f75165fdc026b3913f4183133f19b49be773ac9ea966e8bd" dependencies = [ "pest", "pest_meta", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] name = "pest_meta" -version = "2.7.8" +version = "2.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "934cd7631c050f4674352a6e835d5f6711ffbfb9345c2fc0107155ac495ae293" +checksum = "2adbf29bb9776f28caece835398781ab24435585fe0d4dc1374a61db5accedca" dependencies = [ "once_cell", "pest", @@ -8801,7 +8866,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 2.2.5", + "indexmap 2.2.6", ] [[package]] @@ -8821,7 +8886,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -8832,9 +8897,9 @@ checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" [[package]] name = "pin-project-lite" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "pin-utils" @@ -8849,7 +8914,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "668d31b1c4eba19242f2088b2bf3316b82ca31082a8335764db4e083db7485d4" dependencies = [ "atomic-waker", - "fastrand 2.0.1", + "fastrand 2.0.2", "futures-io", ] @@ -8871,9 +8936,9 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "platforms" -version = "3.3.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c" +checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" [[package]] name = "polkadot-approval-distribution" @@ -9028,7 +9093,7 @@ dependencies = [ "fatality", "futures", "futures-timer", - "indexmap 2.2.5", + "indexmap 2.2.6", "parity-scale-codec", "polkadot-erasure-coding", "polkadot-node-network-protocol", @@ -9446,7 +9511,7 @@ name = "polkadot-node-metrics" version = "7.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.0#162c6796bac740802fe11c9e39f3094677d1f08f" dependencies = [ - "bs58 0.5.0", + "bs58 0.5.1", "futures", "futures-timer", "log", @@ -9735,7 +9800,7 @@ name = "polkadot-runtime-metrics" version = "7.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.0#162c6796bac740802fe11c9e39f3094677d1f08f" dependencies = [ - "bs58 0.5.0", + "bs58 0.5.1", "frame-benchmarking", "parity-scale-codec", "polkadot-primitives", @@ -9920,7 +9985,7 @@ dependencies = [ "fatality", "futures", "futures-timer", - "indexmap 2.2.5", + "indexmap 2.2.6", "parity-scale-codec", "polkadot-node-network-protocol", "polkadot-node-primitives", @@ -9962,7 +10027,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6380dbe1fb03ecc74ad55d841cfc75480222d153ba69ddcb00977866cbdabdb8" dependencies = [ "polkavm-derive-impl 0.5.0", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -9983,7 +10048,7 @@ dependencies = [ "polkavm-common 0.5.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -9995,7 +10060,7 @@ dependencies = [ "polkavm-common 0.9.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -10005,7 +10070,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" dependencies = [ "polkavm-derive-impl 0.9.0", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -10020,20 +10085,21 @@ dependencies = [ "concurrent-queue", "libc", "log", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", "windows-sys 0.48.0", ] [[package]] name = "polling" -version = "3.5.0" +version = "3.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24f040dee2588b4963afb4e420540439d126f73fdacf4a9c486a96d840bac3c9" +checksum = "e0c976a60b2d7e99d6f229e414670a9b85d13ac305cc6d1e9c134de58c5aaaf6" dependencies = [ "cfg-if", "concurrent-queue", - "pin-project-lite 0.2.13", - "rustix 0.38.31", + "hermit-abi", + "pin-project-lite 0.2.14", + "rustix 0.38.32", "tracing", "windows-sys 0.52.0", ] @@ -10111,7 +10177,7 @@ source = "git+https://github.com/paritytech/frontier?branch=polkadot-v1.7.0#c5d6 dependencies = [ "case", "num_enum", - "prettyplease 0.2.16", + "prettyplease 0.2.19", "proc-macro2", "quote", "sp-core-hashing 15.0.0", @@ -10155,7 +10221,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22020dfcf177fcc7bf5deaf7440af371400c67c0de14c399938d8ed4fb4645d3" dependencies = [ "proc-macro2", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -10170,12 +10236,12 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.16" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" +checksum = "5ac2cf0f2e4f42b49f5ffd07dae8d746508ef7526c13940e5f524012ae6c6550" dependencies = [ "proc-macro2", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -10268,14 +10334,14 @@ checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ "unicode-ident", ] @@ -10314,7 +10380,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -10329,12 +10395,12 @@ dependencies = [ [[package]] name = "prost" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "146c289cda302b98a28d40c8b3b90498d6e526dd24ac2ecea73e4e491685b94a" +checksum = "d0f5d036824e4761737860779c906171497f6d55681139d8312388f8fe398922" dependencies = [ "bytes", - "prost-derive 0.12.3", + "prost-derive 0.12.4", ] [[package]] @@ -10344,7 +10410,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" dependencies = [ "bytes", - "heck", + "heck 0.4.1", "itertools 0.10.5", "lazy_static", "log", @@ -10374,15 +10440,15 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efb6c9a1dd1def8e2124d17e83a20af56f1570d6c2d2bd9e266ccb768df3840e" +checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" dependencies = [ "anyhow", - "itertools 0.11.0", + "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -10462,9 +10528,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -10534,7 +10600,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.12", + "getrandom 0.2.14", ] [[package]] @@ -10573,9 +10639,9 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "rayon" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4963ed1bc86e4f3ee217022bd855b297cef07fb9eac5dfa1f788b220b49b3bd" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ "either", "rayon-core", @@ -10623,11 +10689,11 @@ dependencies = [ [[package]] name = "redox_users" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" +checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" dependencies = [ - "getrandom 0.2.12", + "getrandom 0.2.14", "libredox", "thiserror", ] @@ -10661,7 +10727,7 @@ checksum = "5fddb4f8d99b0a2ebafc65a87a69a7b9875e4b1ae1f00db265d300ef7f28bccc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -10678,14 +10744,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.3" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", "regex-automata 0.4.6", - "regex-syntax 0.8.2", + "regex-syntax 0.8.3", ] [[package]] @@ -10705,7 +10771,7 @@ checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.2", + "regex-syntax 0.8.3", ] [[package]] @@ -10716,9 +10782,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "resolv-conf" @@ -10779,7 +10845,7 @@ checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" dependencies = [ "cc", "cfg-if", - "getrandom 0.2.12", + "getrandom 0.2.14", "libc", "spin 0.9.8", "untrusted 0.9.0", @@ -11056,11 +11122,11 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.31" +version = "0.38.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "errno", "libc", "linux-raw-sys 0.4.13", @@ -11124,9 +11190,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47" [[package]] name = "ruzstd" @@ -11219,7 +11285,7 @@ dependencies = [ "multihash 0.18.1", "multihash-codetable", "parity-scale-codec", - "prost 0.12.3", + "prost 0.12.4", "prost-build", "rand 0.8.5", "sc-client-api", @@ -11305,7 +11371,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -11868,7 +11934,7 @@ dependencies = [ "futures", "libp2p-identity", "log", - "prost 0.12.3", + "prost 0.12.4", "prost-build", "sc-client-api", "sc-network", @@ -11925,7 +11991,7 @@ dependencies = [ "libp2p-identity", "log", "parity-scale-codec", - "prost 0.12.3", + "prost 0.12.4", "prost-build", "sc-client-api", "sc-network", @@ -11950,7 +12016,7 @@ dependencies = [ "log", "mockall", "parity-scale-codec", - "prost 0.12.3", + "prost 0.12.4", "prost-build", "sc-client-api", "sc-consensus", @@ -12302,8 +12368,8 @@ dependencies = [ "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.0)", "thiserror", "tracing", - "tracing-log", - "tracing-subscriber", + "tracing-log 0.1.4", + "tracing-subscriber 0.2.25", ] [[package]] @@ -12314,7 +12380,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -12444,9 +12510,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.10.0" +version = "2.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7d66a1128282b7ef025a8ead62a4a9fcf017382ec53b8ffbf4d7bf77bd3c60" +checksum = "7c453e59a955f81fb62ee5d596b450383d699f152d350e9d23a0db2adb78e4c0" dependencies = [ "bitvec", "cfg-if", @@ -12458,9 +12524,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.10.0" +version = "2.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf2c68b89cafb3b8d918dd07b42be0da66ff202cf1155c5739a4e0c1ea0dc19" +checksum = "18cf6c6447f813ef19eb450e985bcce6705f9ce7660db221b59093d15c79c4b7" dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", @@ -12653,9 +12719,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.9.2" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" dependencies = [ "bitflags 1.3.2", "core-foundation", @@ -12666,9 +12732,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.9.1" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" dependencies = [ "core-foundation-sys", "libc", @@ -12709,9 +12775,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.197" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" dependencies = [ "serde_derive", ] @@ -12727,20 +12793,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] name = "serde_json" -version = "1.0.114" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" dependencies = [ "itoa", "ryu", @@ -12886,9 +12952,9 @@ checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" [[package]] name = "siphasher" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54ac45299ccbd390721be55b412d41931911f654fa99e2cb8bfb57184b2061fe" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" [[package]] name = "slab" @@ -12928,9 +12994,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smol" @@ -12961,7 +13027,7 @@ dependencies = [ "base64 0.21.7", "bip39", "blake2-rfc", - "bs58 0.5.0", + "bs58 0.5.1", "chacha20", "crossbeam-queue", "derive_more", @@ -13015,7 +13081,7 @@ dependencies = [ "base64 0.21.7", "bip39", "blake2-rfc", - "bs58 0.5.0", + "bs58 0.5.1", "chacha20", "crossbeam-queue", "derive_more", @@ -13023,7 +13089,7 @@ dependencies = [ "either", "event-listener 3.1.0", "fnv", - "futures-lite 2.2.0", + "futures-lite 2.3.0", "futures-util", "hashbrown 0.14.3", "hex", @@ -13048,7 +13114,7 @@ dependencies = [ "serde_json", "sha2 0.10.8", "sha3", - "siphasher 1.0.0", + "siphasher 1.0.1", "slab", "smallvec", "soketto", @@ -13100,7 +13166,7 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e6f1898682b618b81570047b9d870b3faaff6ae1891b468eddd94d7f903c2fe" dependencies = [ - "async-channel 2.2.0", + "async-channel 2.2.1", "async-lock 3.3.0", "base64 0.21.7", "blake2-rfc", @@ -13109,7 +13175,7 @@ dependencies = [ "event-listener 3.1.0", "fnv", "futures-channel", - "futures-lite 2.2.0", + "futures-lite 2.3.0", "futures-util", "hashbrown 0.14.3", "hex", @@ -13123,7 +13189,7 @@ dependencies = [ "rand_chacha 0.3.1", "serde", "serde_json", - "siphasher 1.0.0", + "siphasher 1.0.1", "slab", "smol", "smoldot 0.14.0", @@ -13222,7 +13288,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -13453,7 +13519,7 @@ dependencies = [ "bitflags 1.3.2", "blake2 0.10.6", "bounded-collections 0.1.9", - "bs58 0.5.0", + "bs58 0.5.1", "dyn-clonable", "ed25519-zebra 3.1.0", "futures", @@ -13501,7 +13567,7 @@ dependencies = [ "bitflags 1.3.2", "blake2 0.10.6", "bounded-collections 0.2.0", - "bs58 0.5.0", + "bs58 0.5.1", "dyn-clonable", "ed25519-zebra 3.1.0", "futures", @@ -13561,7 +13627,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b0f34e4b2953f814254f92c8d151f22ffcf9c034" +source = "git+https://github.com/paritytech/polkadot-sdk#98a364fe6e7abf10819f5fddd3de0588f7c38700" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -13576,7 +13642,6 @@ dependencies = [ "ark-ed-on-bls12-381-bandersnatch-ext", "ark-scale", "sp-runtime-interface 24.0.0 (git+https://github.com/paritytech/polkadot-sdk)", - "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk)", ] [[package]] @@ -13599,7 +13664,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "quote", "sp-crypto-hashing", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -13619,7 +13684,7 @@ checksum = "50535e1a5708d3ba5c1195b59ebefac61cc8679c2c24716b87a86e8b7ed2e4a1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -13629,17 +13694,17 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b0f34e4b2953f814254f92c8d151f22ffcf9c034" +source = "git+https://github.com/paritytech/polkadot-sdk#98a364fe6e7abf10819f5fddd3de0588f7c38700" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -13668,11 +13733,10 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b0f34e4b2953f814254f92c8d151f22ffcf9c034" +source = "git+https://github.com/paritytech/polkadot-sdk#98a364fe6e7abf10819f5fddd3de0588f7c38700" dependencies = [ "environmental", "parity-scale-codec", - "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk)", "sp-storage 19.0.0 (git+https://github.com/paritytech/polkadot-sdk)", ] @@ -13978,7 +14042,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b0f34e4b2953f814254f92c8d151f22ffcf9c034" +source = "git+https://github.com/paritytech/polkadot-sdk#98a364fe6e7abf10819f5fddd3de0588f7c38700" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -14004,7 +14068,7 @@ dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -14017,20 +14081,20 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b0f34e4b2953f814254f92c8d151f22ffcf9c034" +source = "git+https://github.com/paritytech/polkadot-sdk#98a364fe6e7abf10819f5fddd3de0588f7c38700" dependencies = [ "Inflector", "expander 2.1.0", "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -14144,7 +14208,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b0f34e4b2953f814254f92c8d151f22ffcf9c034" +source = "git+https://github.com/paritytech/polkadot-sdk#98a364fe6e7abf10819f5fddd3de0588f7c38700" [[package]] name = "sp-storage" @@ -14176,14 +14240,13 @@ dependencies = [ [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b0f34e4b2953f814254f92c8d151f22ffcf9c034" +source = "git+https://github.com/paritytech/polkadot-sdk#98a364fe6e7abf10819f5fddd3de0588f7c38700" dependencies = [ "impl-serde", "parity-scale-codec", "ref-cast", "serde", "sp-debug-derive 14.0.0 (git+https://github.com/paritytech/polkadot-sdk)", - "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk)", ] [[package]] @@ -14209,7 +14272,7 @@ dependencies = [ "sp-std 12.0.0", "tracing", "tracing-core", - "tracing-subscriber", + "tracing-subscriber 0.2.25", ] [[package]] @@ -14221,19 +14284,18 @@ dependencies = [ "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.0)", "tracing", "tracing-core", - "tracing-subscriber", + "tracing-subscriber 0.2.25", ] [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b0f34e4b2953f814254f92c8d151f22ffcf9c034" +source = "git+https://github.com/paritytech/polkadot-sdk#98a364fe6e7abf10819f5fddd3de0588f7c38700" dependencies = [ "parity-scale-codec", - "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk)", "tracing", "tracing-core", - "tracing-subscriber", + "tracing-subscriber 0.3.18", ] [[package]] @@ -14334,7 +14396,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -14367,14 +14429,11 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b0f34e4b2953f814254f92c8d151f22ffcf9c034" +source = "git+https://github.com/paritytech/polkadot-sdk#98a364fe6e7abf10819f5fddd3de0588f7c38700" dependencies = [ - "anyhow", "impl-trait-for-tuples", "log", "parity-scale-codec", - "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk)", - "wasmtime", ] [[package]] @@ -14487,7 +14546,7 @@ dependencies = [ "futures-util", "hashlink", "hex", - "indexmap 2.2.5", + "indexmap 2.2.6", "log", "memchr", "native-tls", @@ -14526,7 +14585,7 @@ checksum = "5833ef53aaa16d860e92123292f1f6a3d53c34ba8b1969f152ef1a7bb803f3c8" dependencies = [ "dotenvy", "either", - "heck", + "heck 0.4.1", "hex", "once_cell", "proc-macro2", @@ -14567,9 +14626,9 @@ dependencies = [ [[package]] name = "ss58-registry" -version = "1.46.0" +version = "1.47.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1114ee5900b8569bbc8b1a014a942f937b752af4b44f4607430b5f86cedaac0" +checksum = "4743ce898933fbff7bbf414f497c459a782d496269644b3d650a398ae6a487ba" dependencies = [ "Inflector", "num-format", @@ -14716,9 +14775,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "strsim" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "strum" @@ -14731,9 +14790,9 @@ dependencies = [ [[package]] name = "strum" -version = "0.25.0" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +checksum = "5d8cec3501a5194c432b2b7976db6b7d10ec95c253208b45f83f7136aa985e29" [[package]] name = "strum_macros" @@ -14741,7 +14800,7 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", @@ -14750,15 +14809,15 @@ dependencies = [ [[package]] name = "strum_macros" -version = "0.25.3" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +checksum = "c6cf59daf282c0a494ba14fd21610a0325f9f90ec9d1231dea26bcb1d696c946" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -14853,7 +14912,7 @@ dependencies = [ "sp-maybe-compressed-blob", "strum 0.24.1", "tempfile", - "toml 0.8.11", + "toml 0.8.12", "walkdir", "wasm-opt", ] @@ -14918,7 +14977,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12800ad6128b4bfc93d2af89b7d368bff7ea2f6604add35f96f6a8c06c7f9abf" dependencies = [ "frame-metadata 16.0.0", - "heck", + "heck 0.4.1", "hex", "jsonrpsee", "parity-scale-codec", @@ -14926,7 +14985,7 @@ dependencies = [ "quote", "scale-info", "subxt-metadata", - "syn 2.0.52", + "syn 2.0.60", "thiserror", "tokio", ] @@ -14958,7 +15017,7 @@ dependencies = [ "parity-scale-codec", "proc-macro-error", "subxt-codegen", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -15009,9 +15068,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.52" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", @@ -15070,8 +15129,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", - "fastrand 2.0.1", - "rustix 0.38.31", + "fastrand 2.0.2", + "rustix 0.38.32", "windows-sys 0.52.0", ] @@ -15090,7 +15149,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" dependencies = [ - "rustix 0.38.31", + "rustix 0.38.32", "windows-sys 0.48.0", ] @@ -15126,7 +15185,7 @@ checksum = "e4c60d69f36615a077cc7663b9cb8e42275722d23e58a7fa3d2c7f2915d09d04" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -15137,7 +15196,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -15201,9 +15260,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.34" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", @@ -15222,9 +15281,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ "num-conv", "time-core", @@ -15256,9 +15315,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.36.0" +version = "1.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", "bytes", @@ -15266,7 +15325,7 @@ dependencies = [ "mio", "num_cpus", "parking_lot 0.12.1", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", "signal-hook-registry", "socket2 0.5.6", "tokio-macros", @@ -15281,7 +15340,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -15307,12 +15366,12 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" dependencies = [ "futures-core", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", "tokio", "tokio-util", ] @@ -15327,7 +15386,7 @@ dependencies = [ "futures-core", "futures-io", "futures-sink", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", "tokio", "tracing", ] @@ -15343,14 +15402,14 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af06656561d28735e9c1cd63dfd57132c8155426aa6af24f36a00a351f88c48e" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.7", + "toml_edit 0.22.11", ] [[package]] @@ -15368,7 +15427,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.2.5", + "indexmap 2.2.6", "toml_datetime", "winnow 0.5.40", ] @@ -15379,7 +15438,7 @@ version = "0.20.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" dependencies = [ - "indexmap 2.2.5", + "indexmap 2.2.6", "toml_datetime", "winnow 0.5.40", ] @@ -15390,22 +15449,22 @@ version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ - "indexmap 2.2.5", + "indexmap 2.2.6", "toml_datetime", "winnow 0.5.40", ] [[package]] name = "toml_edit" -version = "0.22.7" +version = "0.22.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18769cd1cec395d70860ceb4d932812a0b4d06b1a4bb336745a4d21b9496e992" +checksum = "fb686a972ccef8537b39eead3968b0e8616cb5040dbb9bba93007c8e07c9215f" dependencies = [ - "indexmap 2.2.5", + "indexmap 2.2.6", "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.5", + "winnow 0.6.6", ] [[package]] @@ -15417,7 +15476,7 @@ dependencies = [ "futures-core", "futures-util", "pin-project", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", "tower-layer", "tower-service", "tracing", @@ -15429,14 +15488,14 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61c5bb1d698276a2443e5ecfabc1008bf15a36c12e6a7176e7bf089ea9131140" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "bytes", "futures-core", "futures-util", "http", "http-body", "http-range-header", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", "tower-layer", "tower-service", ] @@ -15460,7 +15519,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "log", - "pin-project-lite 0.2.13", + "pin-project-lite 0.2.14", "tracing-attributes", "tracing-core", ] @@ -15473,7 +15532,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -15516,7 +15575,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -15530,6 +15589,17 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + [[package]] name = "tracing-serde" version = "0.1.3" @@ -15549,7 +15619,7 @@ dependencies = [ "ansi_term", "chrono", "lazy_static", - "matchers", + "matchers 0.0.1", "parking_lot 0.11.2", "regex", "serde", @@ -15559,10 +15629,28 @@ dependencies = [ "thread_local", "tracing", "tracing-core", - "tracing-log", + "tracing-log 0.1.4", "tracing-serde", ] +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "matchers 0.1.0", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log 0.2.0", +] + [[package]] name = "trie-db" version = "0.28.0" @@ -15932,7 +16020,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", "wasm-bindgen-shared", ] @@ -15966,7 +16054,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -15988,9 +16076,9 @@ dependencies = [ [[package]] name = "wasm-opt" -version = "0.116.0" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc942673e7684671f0c5708fc18993569d184265fd5223bb51fc8e5b9b6cfd52" +checksum = "2fd87a4c135535ffed86123b6fb0f0a5a0bc89e50416c942c5f0662c645f679c" dependencies = [ "anyhow", "libc", @@ -16446,14 +16534,14 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.31", + "rustix 0.38.32", ] [[package]] name = "wide" -version = "0.7.15" +version = "0.7.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89beec544f246e679fc25490e3f8e08003bc4bf612068f325120dad4cea02c1c" +checksum = "81a1851a719f11d1d2fea40e15c72f6c00de8c142d7ac47c1441cc7e4d0d5bc6" dependencies = [ "bytemuck", "safe_arch", @@ -16461,9 +16549,9 @@ dependencies = [ [[package]] name = "widestring" -version = "1.0.2" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" +checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311" [[package]] name = "winapi" @@ -16521,7 +16609,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -16548,7 +16636,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -16583,17 +16671,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.4", - "windows_aarch64_msvc 0.52.4", - "windows_i686_gnu 0.52.4", - "windows_i686_msvc 0.52.4", - "windows_x86_64_gnu 0.52.4", - "windows_x86_64_gnullvm 0.52.4", - "windows_x86_64_msvc 0.52.4", + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] [[package]] @@ -16610,9 +16699,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" @@ -16628,9 +16717,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" @@ -16646,9 +16735,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" @@ -16664,9 +16759,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" @@ -16682,9 +16777,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" @@ -16700,9 +16795,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" @@ -16718,9 +16813,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" @@ -16733,9 +16828,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +checksum = "f0c976aaaa0e1f90dbb21e9587cdaf1d9679a1cde8875c0d6bd83ab96a208352" dependencies = [ "memchr", ] @@ -16808,7 +16903,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -16857,7 +16952,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -16877,7 +16972,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.60", ] [[package]] @@ -16920,9 +17015,9 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.9+zstd.1.5.5" +version = "2.0.10+zstd.1.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e16efa8a874a0481a574084d34cc26fdb3b99627480f785888deb6386506656" +checksum = "c253a4914af5bafc8fa8c86ee400827e83cf6ec01195ec1f1ed8441bf00d65aa" dependencies = [ "cc", "pkg-config", diff --git a/Cargo.toml b/Cargo.toml index 1487df9..1dcf507 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,11 +21,13 @@ members = [ "primitives/system", "pallets/evm-utils", "pallets/evm/precompile/substrate-utils", + "pallets/evm/precompile/transfer-to-magnet", "pallets/pot/runtime-api", "pallets/pot/rpc", "pallets/pot", "pallets/assurance", "pallets/liquidation", + "pallets/assets-bridge", ] resolver = "2" diff --git a/pallets/assets-bridge/src/lib.rs b/pallets/assets-bridge/src/lib.rs index 61fec21..0b2e3a1 100644 --- a/pallets/assets-bridge/src/lib.rs +++ b/pallets/assets-bridge/src/lib.rs @@ -34,7 +34,7 @@ use frame_support::{ pallet_prelude::*, traits::{ tokens::{Fortitude, Precision}, - Currency, ExistenceRequirement, IsType, + Currency, IsType, }, transactional, }; @@ -42,9 +42,9 @@ use frame_support::{ use sp_core::{ecdsa, H160, U256}; use sp_io::{crypto::secp256k1_ecdsa_recover, hashing::keccak_256}; use sp_runtime::traits::{StaticLookup, UniqueSaturatedInto, Zero}; -use sp_std::vec::Vec; +use sp_std::{collections::btree_set::BTreeSet, vec::Vec}; -use pallet_evm::{AddressMapping, ExitReason, Runner}; +use pallet_evm::{ExitReason, Runner}; pub type EcdsaSignature = ecdsa::Signature; pub type AddressMappingOf = ::AddressMapping; @@ -57,9 +57,6 @@ pub type ReserveBalanceOf = <::Currency as Curren #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, scale_info::TypeInfo)] pub enum ActionType { - Direct(H160), - FromSubToEth, - FromEthToSub, BackForeign(AssetId), } @@ -197,7 +194,7 @@ pub use pallet::*; #[frame_support::pallet] pub mod pallet { use super::*; - use frame_support::traits::{fungibles::Mutate, ReservableCurrency}; + use frame_support::traits::fungibles::Mutate; use frame_system::pallet_prelude::*; #[pallet::pallet] @@ -215,6 +212,10 @@ pub mod pallet { /// How much should be locked up in order to claim account. #[pallet::constant] type ClaimBond: Get>; + + /// The assets-bridge's evm contract deployer. + #[pallet::constant] + type EvmAdmins: Get>; } /// The Substrate Account for Evm Addresses @@ -356,78 +357,18 @@ pub mod pallet { where DispatchError: From<<::Runner as pallet_evm::Runner>::Error>, { - /// Claim account mapping between Substrate accounts and EVM accounts. - /// Ensure eth_address has not been mapped. - /// Note: for general users - /// - /// - `eth_address`: The address to bind to the caller's account - /// - `eth_signature`: A signature generated by the address to prove ownership - #[pallet::call_index(0)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] - #[transactional] - pub fn claim_account( - origin: OriginFor, - eth_address: H160, - eth_signature: EcdsaSignature, - ) -> DispatchResult { - let who = ensure_signed(origin)?; - - // ensure account_id and eth_address has not been mapped - ensure!(!EvmAccounts::::contains_key(&who), Error::::AccountIdHasMapped); - ensure!(!SubAccounts::::contains_key(eth_address), Error::::EthAddressHasMapped); - - // recover evm address from signature - let address = eth_recover(ð_signature, &who.using_encoded(to_ascii_hex), &[][..]) - .ok_or(Error::::BadSignature)?; - - ensure!(eth_address == address, Error::::InvalidSignature); - - ::Currency::reserve(&who, T::ClaimBond::get())?; - - SubAccounts::::insert(eth_address, &who); - EvmAccounts::::insert(&who, eth_address); - - Self::deposit_event(Event::ClaimAccount(who, eth_address)); - - Ok(()) - } - - /// Dissolve substrate accounts and EVM accounts. - /// Note: for general users - #[pallet::call_index(1)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] - #[transactional] - pub fn dissolve(origin: OriginFor) -> DispatchResult { - let who = ensure_signed(origin)?; - - let evm_account = Self::evm_accounts(&who).ok_or(Error::::EthAddressHasNotMapped)?; - - ensure!( - SubAccounts::::contains_key(evm_account), - Error::::EthAddressHasNotMapped - ); - - ::Currency::unreserve(&who, T::ClaimBond::get()); - - SubAccounts::::remove(evm_account); - EvmAccounts::::remove(&who); - - Self::deposit_event(Event::Dissolve(who)); - - Ok(()) - } - /// Deposit substrate assets into evm erc20 contracts. /// Note: for general users /// /// - `asset_id`: The asset id /// - `amount`: Deposit amount - #[pallet::call_index(2)] + #[pallet::call_index(0)] #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] #[transactional] pub fn deposit( origin: OriginFor, asset_id: T::AssetId, + evm_account: H160, amount: T::Balance, precision: LocalPrecision, force: LocalFortitude, @@ -437,7 +378,7 @@ pub mod pallet { ensure!(!amount.is_zero(), Error::::ZeroBalance); // 1. check evm account - let evm_account = Self::evm_accounts(&who).ok_or(Error::::EthAddressHasNotMapped)?; + //let evm_account = Self::evm_accounts(&who).ok_or(Error::::EthAddressHasNotMapped)?; let external_precision: Precision = precision.into(); let external_force: Fortitude = force.into(); @@ -463,58 +404,13 @@ pub mod pallet { Ok(Pays::No.into()) } - /// Withdraw from evm erc20 contracts into substrate assets - /// Note: for general users - /// - /// - `asset_id`: The asset id - /// - `amount`: Withdraw amount - #[pallet::call_index(3)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] - #[transactional] - pub fn withdraw( - origin: OriginFor, - asset_id: T::AssetId, - amount: T::Balance, - ) -> DispatchResultWithPostInfo { - let who = ensure_signed(origin)?; - ensure!(!Self::is_in_emergency(asset_id.clone()), Error::::InEmergency); - ensure!(!amount.is_zero(), Error::::ZeroBalance); - - // 1. check evm account - let evm_account = Self::evm_accounts(&who).ok_or(Error::::EthAddressHasNotMapped)?; - - // 2. burn erc20 - let erc20 = - Self::erc20s(asset_id.clone()).ok_or(Error::::ContractAddressHasNotMapped)?; - - let inputs = burn_from_encode(evm_account, amount.unique_saturated_into()); - - Self::call_evm(erc20, inputs)?; - - // 3. mint asset - pallet_assets::Pallet::::mint_into(asset_id.clone(), &who, amount)?; - - Self::deposit_event(Event::WithdrawExecuted( - asset_id.clone(), - who, - evm_account, - amount, - erc20, - )); - - Ok(Pays::No.into()) - } - /// Teleport native currency between substrate account and evm address - /// Ensure eth_address has been mapped /// Note: for general users /// /// - `amount`: Teleport amount - /// - `action`: (1) Direct(H160): direct transfer into unchecked evm address (2) - /// FromSubToEth: transfer from substrate account to mapped evm address (3) FromEthToSub: - /// transfer from mapped evm address to substrate account - /// - companion with `relay`: (4) BackForeign(asset_id): transfer assets back foreign chain - #[pallet::call_index(4)] + /// - `action`: + /// - (1) BackForeign(asset_id): transfer assets back foreign chain + #[pallet::call_index(1)] #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] #[transactional] pub fn teleport( @@ -529,24 +425,7 @@ pub mod pallet { ensure!(!amount.is_zero(), Error::::ZeroBalance); - let (from, to, back_foreign) = match action { - ActionType::Direct(unchecked) => { - (who.clone(), AddressMappingOf::::into_account_id(unchecked), false) - }, - ActionType::FromSubToEth => ( - who.clone(), - Self::evm_accounts(&who) - .map(AddressMappingOf::::into_account_id) - .ok_or(Error::::EthAddressHasNotMapped)?, - false, - ), - ActionType::FromEthToSub => ( - Self::evm_accounts(&who) - .map(AddressMappingOf::::into_account_id) - .ok_or(Error::::EthAddressHasNotMapped)?, - who.clone(), - false, - ), + let (_from, _to, _back_foreign) = match action { ActionType::BackForeign(asset_id) => { // ensure asset_id registered in back_foreign list ensure!(Self::is_in_back_foreign(asset_id.clone()), Error::::BanBackForeign); @@ -569,15 +448,6 @@ pub mod pallet { }, }; - if !back_foreign { - ::Currency::transfer( - &from, - &to, - amount, - ExistenceRequirement::AllowDeath, - )?; - } - Self::deposit_event(Event::Teleport(who, amount, action_clone)); Ok(Pays::No.into()) @@ -588,7 +458,7 @@ pub mod pallet { /// /// - `asset_id`: The asset id /// - `erc20`: The erc20 contract address - #[pallet::call_index(5)] + #[pallet::call_index(2)] #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] pub fn register( origin: OriginFor, @@ -614,7 +484,7 @@ pub mod pallet { /// Note: for admin /// /// - `asset_id`: None will pause all, Some(id) will pause the specified asset - #[pallet::call_index(6)] + #[pallet::call_index(3)] #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] pub fn pause( origin: OriginFor, @@ -649,7 +519,7 @@ pub mod pallet { /// Note: for admin /// /// - `asset_id`: None will unpause all, Some(id) will unpause the specified asset - #[pallet::call_index(7)] + #[pallet::call_index(4)] #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] pub fn unpause( origin: OriginFor, @@ -682,7 +552,7 @@ pub mod pallet { /// Note: for admin /// /// - `asset_id`: - #[pallet::call_index(8)] + #[pallet::call_index(5)] #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] pub fn back_foreign( origin: OriginFor, @@ -709,7 +579,7 @@ pub mod pallet { /// Set this pallet admin key /// Note: for super admin - #[pallet::call_index(9)] + #[pallet::call_index(6)] #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] pub fn set_admin( origin: OriginFor, @@ -734,7 +604,7 @@ pub mod pallet { /// Force unregister substrate assets and erc20 contracts /// Note: for super admin - #[pallet::call_index(10)] + #[pallet::call_index(7)] #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] pub fn force_unregister( origin: OriginFor, diff --git a/pallets/assets-bridge/src/mock.rs b/pallets/assets-bridge/src/mock.rs index fda35cf..a4e226a 100644 --- a/pallets/assets-bridge/src/mock.rs +++ b/pallets/assets-bridge/src/mock.rs @@ -14,6 +14,8 @@ pub use crate as assets_bridge; pub use assets_bridge::{Config, Error, Event as AssetsBridgeEvent}; +use sp_std::collections::btree_set::BTreeSet; + use frame_support::{ derive_impl, pallet_prelude::Weight, @@ -127,7 +129,12 @@ parameter_types! { // 0x1111111111111111111111111111111111111111 pub EvmCaller: H160 = H160::from_slice(&[17u8;20][..]); pub ClaimBond: u128 = 2; - + //pub EvmAdmin: H160 = H160([0x05, 0xF9, 0xb8, 0xC7, 0x6E, 0x89, 0x87, 0xB8, 0x15, 0xC9, 0x3C, 0x27, 0xD1, 0x45, 0x20, 0xb6, 0xeD, 0x57, 0x39, 0x02]); + pub EvmAdmins: BTreeSet = { + let mut set = BTreeSet::new(); + set.insert(H160([0x05, 0xF9, 0xb8, 0xC7, 0x6E, 0x89, 0x87, 0xB8, 0x15, 0xC9, 0x3C, 0x27, 0xD1, 0x45, 0x20, 0xb6, 0xeD, 0x57, 0x39, 0x02])); + set + }; pub const WeightPerGas: Weight = Weight::from_parts(20_000, 0); pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE); @@ -186,6 +193,7 @@ impl assets_bridge::Config for Test { type RuntimeEvent = RuntimeEvent; type EvmCaller = EvmCaller; type ClaimBond = ClaimBond; + type EvmAdmins = EvmAdmins; } pub const ALICE: [u8; 32] = [1u8; 32]; diff --git a/pallets/assets-bridge/src/tests.rs b/pallets/assets-bridge/src/tests.rs index 3017bad..cbea967 100644 --- a/pallets/assets-bridge/src/tests.rs +++ b/pallets/assets-bridge/src/tests.rs @@ -17,6 +17,7 @@ use sp_core::{H160, U256}; use ethabi::{Function, Param, ParamType, Token}; use hex_literal::hex; +use sp_runtime::TokenError; use std::str::FromStr; use crate::LocalFortitude; @@ -154,11 +155,12 @@ fn pause_should_work() { AssetsBridge::deposit( RuntimeOrigin::signed(BOB.into()), 1, + H160::from_slice(&EVM_ADDR), 1, LocalPrecision::Exact, LocalFortitude::Polite ), - Error::::EthAddressHasNotMapped + TokenError::FundsUnavailable ); assert_ok!(AssetsBridge::pause(RuntimeOrigin::signed(ALICE.into()), Some(1))); @@ -168,6 +170,7 @@ fn pause_should_work() { AssetsBridge::deposit( RuntimeOrigin::signed(BOB.into()), 1, + H160::from_slice(&EVM_ADDR), 1, LocalPrecision::Exact, LocalFortitude::Polite @@ -220,11 +223,12 @@ fn pause_after_pause_should_work() { AssetsBridge::deposit( RuntimeOrigin::signed(BOB.into()), 1, + H160::from_slice(&EVM_ADDR), 1, LocalPrecision::Exact, LocalFortitude::Polite ), - Error::::EthAddressHasNotMapped + TokenError::FundsUnavailable ); // 1. pause(1) @@ -236,6 +240,7 @@ fn pause_after_pause_should_work() { AssetsBridge::deposit( RuntimeOrigin::signed(BOB.into()), 1, + H160::from_slice(&EVM_ADDR), 1, LocalPrecision::Exact, LocalFortitude::Polite @@ -281,6 +286,7 @@ fn unpause_should_work() { AssetsBridge::deposit( RuntimeOrigin::signed(BOB.into()), 1, + H160::from_slice(&EVM_ADDR), 1, LocalPrecision::Exact, LocalFortitude::Polite @@ -295,11 +301,12 @@ fn unpause_should_work() { AssetsBridge::deposit( RuntimeOrigin::signed(BOB.into()), 1, + H160::from_slice(&EVM_ADDR), 1, LocalPrecision::Exact, LocalFortitude::Polite ), - Error::::EthAddressHasNotMapped + TokenError::FundsUnavailable ); }) } @@ -367,6 +374,7 @@ fn unpause_after_unpause_should_work() { AssetsBridge::deposit( RuntimeOrigin::signed(BOB.into()), 1, + H160::from_slice(&EVM_ADDR), 1, LocalPrecision::Exact, LocalFortitude::Polite @@ -374,27 +382,14 @@ fn unpause_after_unpause_should_work() { Error::::InEmergency ); - assert_noop!( - AssetsBridge::withdraw(RuntimeOrigin::signed(BOB.into()), 1, 1), - Error::::InEmergency - ); - assert_ok!(AssetsBridge::unpause(RuntimeOrigin::signed(ALICE.into()), Some(2))); expect_event(AssetsBridgeEvent::UnPaused(2)); - assert_noop!( - AssetsBridge::withdraw(RuntimeOrigin::signed(BOB.into()), 2, 1), - Error::::EthAddressHasNotMapped - ); assert_eq!(AssetsBridge::emergencies(), vec![1]); assert_ok!(AssetsBridge::unpause(RuntimeOrigin::signed(ALICE.into()), None)); expect_event(AssetsBridgeEvent::UnPausedAll); - assert_noop!( - AssetsBridge::withdraw(RuntimeOrigin::signed(BOB.into()), 1, 1), - Error::::EthAddressHasNotMapped - ); assert!(AssetsBridge::emergencies().is_empty()); }) } @@ -422,22 +417,24 @@ fn more_pause_and_unpause_should_work() { AssetsBridge::deposit( RuntimeOrigin::signed(BOB.into()), 1, + H160::from_slice(&EVM_ADDR), 1, LocalPrecision::Exact, LocalFortitude::Polite ), - Error::::EthAddressHasNotMapped + TokenError::FundsUnavailable ); assert_noop!( AssetsBridge::deposit( RuntimeOrigin::signed(BOB.into()), 2, + H160::from_slice(&EVM_ADDR), 1, LocalPrecision::Exact, LocalFortitude::Polite ), - Error::::EthAddressHasNotMapped + TokenError::FundsUnavailable ); assert_ok!(AssetsBridge::pause(RuntimeOrigin::signed(ALICE.into()), None)); @@ -449,6 +446,7 @@ fn more_pause_and_unpause_should_work() { AssetsBridge::deposit( RuntimeOrigin::signed(BOB.into()), 1, + H160::from_slice(&EVM_ADDR), 1, LocalPrecision::Exact, LocalFortitude::Polite @@ -460,6 +458,7 @@ fn more_pause_and_unpause_should_work() { AssetsBridge::deposit( RuntimeOrigin::signed(BOB.into()), 2, + H160::from_slice(&EVM_ADDR), 1, LocalPrecision::Exact, LocalFortitude::Polite @@ -476,6 +475,7 @@ fn more_pause_and_unpause_should_work() { AssetsBridge::deposit( RuntimeOrigin::signed(BOB.into()), 1, + H160::from_slice(&EVM_ADDR), 1, LocalPrecision::Exact, LocalFortitude::Polite @@ -487,11 +487,12 @@ fn more_pause_and_unpause_should_work() { AssetsBridge::deposit( RuntimeOrigin::signed(BOB.into()), 2, + H160::from_slice(&EVM_ADDR), 1, LocalPrecision::Exact, LocalFortitude::Polite ), - Error::::EthAddressHasNotMapped + TokenError::FundsUnavailable ); assert_ok!(AssetsBridge::unpause(RuntimeOrigin::signed(ALICE.into()), None)); @@ -503,11 +504,12 @@ fn more_pause_and_unpause_should_work() { AssetsBridge::deposit( RuntimeOrigin::signed(BOB.into()), 1, + H160::from_slice(&EVM_ADDR), 1, LocalPrecision::Exact, LocalFortitude::Polite ), - Error::::EthAddressHasNotMapped + TokenError::FundsUnavailable ); }) } diff --git a/pallets/evm/precompile/transfer-to-magnet/Cargo.toml b/pallets/evm/precompile/transfer-to-magnet/Cargo.toml new file mode 100644 index 0000000..64e06b4 --- /dev/null +++ b/pallets/evm/precompile/transfer-to-magnet/Cargo.toml @@ -0,0 +1,78 @@ +[package] +name = "pallet-precompile-transfer-to-magnet" +version = "0.1.0" +authors = ["toints"] +description = "precompile transfer token to Magnet." +license = "Apache-2.0" +homepage = "https://magnet.magport.io/" +repository.workspace = true +edition.workspace = true +readme = "README.md" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +codec = { package = "parity-scale-codec", workspace = true, features = ["derive"], default-features = false } +scale-info = { workspace = true, default-features = false, features = ["derive"] } +hex = { workspace = true, default-features = false } + +#Local +pallet-assets-bridge = {path = "../../../../pallets/assets-bridge", default-features = false} + +# Substrate +sp-io = { workspace = true, default-features = false} +sp-std = { workspace = true, default-features = false} +sp-core = { workspace = true, default-features = false} +sp-runtime = { workspace = true, default-features = false} +frame-support = { workspace = true, default-features = false} +frame-system = { workspace = true, default-features = false} +pallet-assets = {workspace = true, default-features = false} + +xcm = { workspace = true, default-features = false} + +#Frontier FRAME +pallet-evm = { workspace = true, default-features = false } + +# Frontier Primitive +fp-evm = { workspace = true, default-features = false } +fp-account = { workspace = true, default-features = false } +precompile-utils = { workspace = true, default-features = false } + +[dev-dependencies] +pallet-balances = { workspace = true, default-features = false} +pallet-timestamp = { workspace = true, default-features = false} + + +[features] +default = ["std"] +std = [ + "codec/std", + "scale-info/std", + # Substrate + "sp-io/std", + "sp-std/std", + "sp-core/std", + "sp-runtime/std", + "frame-system/std", + "frame-support/std", + "pallet-balances/std", + "pallet-timestamp/std", + "pallet-assets-bridge/std", + "pallet-assets/std", + "xcm/std", + # Frontier + "fp-evm/std", + "fp-account/std", + "precompile-utils/std", + #Frontier FRAME + "pallet-evm/std", +] +runtime-benchmarks = [ + "frame-support/runtime-benchmarks", + "pallet-evm/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "pallet-evm/try-runtime", +] diff --git a/pallets/evm/precompile/transfer-to-magnet/README.md b/pallets/evm/precompile/transfer-to-magnet/README.md new file mode 100644 index 0000000..6dec347 --- /dev/null +++ b/pallets/evm/precompile/transfer-to-magnet/README.md @@ -0,0 +1,11 @@ +# precompile-substrate-transfer-to-magnet + +The evm precompile substrate-transfer-to-magnet module provides procompile substrate Practical Functions to transfer token from evm account to magnet account + + +## Interface + +### Functions + +`transferToMagnet(uint256 amount, string calldata ss58Address)` - transfer token from EVM address account in EVM to substrate address account. + diff --git a/pallets/evm/precompile/transfer-to-magnet/contracts/AssetsBridgeAdaptor.sol b/pallets/evm/precompile/transfer-to-magnet/contracts/AssetsBridgeAdaptor.sol new file mode 100644 index 0000000..a8d409c --- /dev/null +++ b/pallets/evm/precompile/transfer-to-magnet/contracts/AssetsBridgeAdaptor.sol @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.4.1/contracts/utils/Context.sol"; +import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.4.1/contracts/access/Ownable.sol"; + +/** + * @dev Interface of the AssetsBridge + */ +interface IAssetsBridge { + /* + * @dev mint the token to account for assets bridge admin. + * @param account The receiver of token. + * @param amount The amount of token. + */ + function mint_into(address account, uint256 amount) external returns (bool); + + /* + * @dev burn the token from account for assets bridge admin. + * @param account The owner of token. + * @param amount The amount of token. + */ + function burn_from(address account, uint256 amount) external returns (bool); +} + +interface ITransferToMagnet { + function transferToMagnet(address tokenAddress, uint256 amount, string calldata ss58Address) external; +} + +abstract contract AssetsBridgeAdmin is Context { + address public constant admin = 0x8c2D71ecFBc9E7D4ee5E09dEc448671a2DEbea7f; + + modifier AssetsBridgeRequire() { + require(_msgSender() == admin, "AssetsBridge: require called by the assets bridge admin address"); + + _; + } +} + +abstract contract AssetsBridgeOwner is Context, Ownable { + modifier AssetsBridgeRequire() { + require(_msgSender() == owner(), "AssetsBridge: require called by owner"); + + _; + } +} + +abstract contract AssetsBridgeAdminOrOwner is Context, Ownable { + address public constant admin = 0x8c2D71ecFBc9E7D4ee5E09dEc448671a2DEbea7f; + + modifier AssetsBridgeRequire() { + require(_msgSender() == owner() || _msgSender() == admin, "AssetsBridge: require called by owner or admin"); + + _; + } +} diff --git a/pallets/evm/precompile/transfer-to-magnet/contracts/AssetsBridgeErc20.sol b/pallets/evm/precompile/transfer-to-magnet/contracts/AssetsBridgeErc20.sol new file mode 100644 index 0000000..5873a16 --- /dev/null +++ b/pallets/evm/precompile/transfer-to-magnet/contracts/AssetsBridgeErc20.sol @@ -0,0 +1,399 @@ +// SPDX-License-Identifier: MIT +// OpenZeppelin Contracts v4.4.1 (token/ERC20/ERC20.sol) + +pragma solidity ^0.8.0; + +import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.4.1/contracts/token/ERC20/IERC20.sol"; +import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.4.1/contracts/token/ERC20/extensions/IERC20Metadata.sol"; +import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.4.1/contracts/utils/Context.sol"; +import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.4.1/contracts/security/Pausable.sol"; +import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.4.1/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; + +import "./AssetsBridgeAdaptor.sol"; + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin Contracts guidelines: functions revert + * instead returning `false` on failure. This behavior is nonetheless + * conventional and does not conflict with the expectations of ERC20 + * applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract AssetsBridgeErc20 is Context, IERC20, IERC20Metadata, Pausable, Ownable, IAssetsBridge, AssetsBridgeAdminOrOwner { + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + address private constant PRECOMPILE_ADDRESS = 0x0000000000000000000000000000000000000801; + + /** + * @dev Sets the values for {name} and {symbol}. + * + * The default value of {decimals} is 18. To select a different value for + * {decimals} you should overload it. + * + * All two of these values are immutable: they can only be set once during + * construction. + */ + constructor(string memory name_, string memory symbol_, uint8 decimals_) { + _name = name_; + _symbol = symbol_; + _decimals = decimals_; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view virtual override returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view virtual override returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5.05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless this function is + * overridden; + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view virtual override returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view virtual override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view virtual override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + + uint256 currentAllowance = _allowances[sender][_msgSender()]; + require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); + unchecked { + _approve(sender, _msgSender(), currentAllowance - amount); + } + + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + uint256 currentAllowance = _allowances[_msgSender()][spender]; + require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); + unchecked { + _approve(_msgSender(), spender, currentAllowance - subtractedValue); + } + + return true; + } + + /** + * @dev Moves `amount` of tokens from `sender` to `recipient`. + * + * This internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + uint256 senderBalance = _balances[sender]; + require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); + unchecked { + _balances[sender] = senderBalance - amount; + } + _balances[recipient] += amount; + + emit Transfer(sender, recipient, amount); + + _afterTokenTransfer(sender, recipient, amount); + } + + function mint_into(address account, uint256 amount) external virtual AssetsBridgeRequire override returns (bool) { + _mint(account, amount); + + return true; + } + + function burn_from(address account, uint256 amount) external virtual AssetsBridgeRequire override returns (bool) { + _burn(account, amount); + + return true; + } + + function pause() external whenNotPaused { + require(_msgSender() == owner(), "ERC20: require called by the contract owner"); + _pause(); + } + + function unpause() external whenPaused { + require(_msgSender() == owner(), "ERC20: require called by the contract owner"); + _unpause(); + } + + function transferToMagnet(uint256 amount, string calldata ss58Address) external { + _burn(msg.sender, amount); + + bytes4 selector = bytes4(keccak256("transferToMagnet(address,uint256,string)")); + bytes memory data = abi.encodeWithSelector(selector, address(this), amount, ss58Address); + + (bool success, ) = PRECOMPILE_ADDRESS.call(data); + require(success, "Call to precompile failed"); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply += amount; + _balances[account] += amount; + emit Transfer(address(0), account, amount); + + _afterTokenTransfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + uint256 accountBalance = _balances[account]; + require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); + unchecked { + _balances[account] = accountBalance - amount; + } + _totalSupply -= amount; + + emit Transfer(account, address(0), amount); + + _afterTokenTransfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + require(owner != address(0), "ERC20: approve from the zero address"); + require(spender != address(0), "ERC20: approve to the zero address"); + + _allowances[owner][spender] = amount; + emit Approval(owner, spender, amount); + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address, + address, + uint256 + ) internal virtual { + require(!paused(), "ERC20Pausable: token transfer while paused"); + } + + /** + * @dev Hook that is called after any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * has been transferred to `to`. + * - when `from` is zero, `amount` tokens have been minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens have been burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _afterTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} +} diff --git a/pallets/evm/precompile/transfer-to-magnet/contracts/AssetsBridgeErc20_ByteCode.txt b/pallets/evm/precompile/transfer-to-magnet/contracts/AssetsBridgeErc20_ByteCode.txt new file mode 100644 index 0000000..9b72591 --- /dev/null +++ b/pallets/evm/precompile/transfer-to-magnet/contracts/AssetsBridgeErc20_ByteCode.txt @@ -0,0 +1 @@ +0x60806040523480156200001157600080fd5b5060405162002cad38038062002cad8339818101604052810190620000379190620002cd565b60008060006101000a81548160ff0219169083151502179055506200007162000065620000c760201b60201c565b620000cf60201b60201c565b82600490805190602001906200008992919062000194565b508160059080519060200190620000a292919062000194565b5080600660006101000a81548160ff021916908360ff160217905550505050620004ad565b600033905090565b60008060019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600060016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b828054620001a290620003ff565b90600052602060002090601f016020900481019282620001c6576000855562000212565b82601f10620001e157805160ff191683800117855562000212565b8280016001018555821562000212579182015b8281111562000211578251825591602001919060010190620001f4565b5b50905062000221919062000225565b5090565b5b808211156200024057600081600090555060010162000226565b5090565b60006200025b620002558462000389565b62000355565b9050828152602081018484840111156200027457600080fd5b62000281848285620003c9565b509392505050565b600082601f8301126200029b57600080fd5b8151620002ad84826020860162000244565b91505092915050565b600081519050620002c78162000493565b92915050565b600080600060608486031215620002e357600080fd5b600084015167ffffffffffffffff811115620002fe57600080fd5b6200030c8682870162000289565b935050602084015167ffffffffffffffff8111156200032a57600080fd5b620003388682870162000289565b92505060406200034b86828701620002b6565b9150509250925092565b6000604051905081810181811067ffffffffffffffff821117156200037f576200037e62000464565b5b8060405250919050565b600067ffffffffffffffff821115620003a757620003a662000464565b5b601f19601f8301169050602081019050919050565b600060ff82169050919050565b60005b83811015620003e9578082015181840152602081019050620003cc565b83811115620003f9576000848401525b50505050565b600060028204905060018216806200041857607f821691505b602082108114156200042f576200042e62000435565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6200049e81620003bc565b8114620004aa57600080fd5b50565b6127f080620004bd6000396000f3fe608060405234801561001057600080fd5b50600436106101375760003560e01c8063715018a6116100b8578063a457c2d71161007c578063a457c2d71461031a578063a9059cbb1461034a578063dd62ed3e1461037a578063efe51695146103aa578063f2fde38b146103da578063f851a440146103f657610137565b8063715018a6146102ae5780638456cb59146102b85780638da5cb5b146102c257806395d89b41146102e0578063a31bb953146102fe57610137565b8063313ce567116100ff578063313ce5671461020857806339509351146102265780633f4ba83a146102565780635c975abb1461026057806370a082311461027e57610137565b806306fdde031461013c578063095ea7b31461015a5780630f536f841461018a57806318160ddd146101ba57806323b872dd146101d8575b600080fd5b610144610414565b6040516101519190612300565b60405180910390f35b610174600480360381019061016f9190611a9e565b6104a6565b60405161018191906122e5565b60405180910390f35b6101a4600480360381019061019f9190611a9e565b6104c4565b6040516101b191906122e5565b60405180910390f35b6101c26105a7565b6040516101cf9190612562565b60405180910390f35b6101f260048036038101906101ed9190611a4f565b6105b1565b6040516101ff91906122e5565b60405180910390f35b6102106106a9565b60405161021d919061257d565b60405180910390f35b610240600480360381019061023b9190611a9e565b6106c0565b60405161024d91906122e5565b60405180910390f35b61025e61076c565b005b610268610839565b60405161027591906122e5565b60405180910390f35b610298600480360381019061029391906119ea565b61084f565b6040516102a59190612562565b60405180910390f35b6102b6610898565b005b6102c0610920565b005b6102ca6109ee565b6040516102d7919061228a565b60405180910390f35b6102e8610a17565b6040516102f59190612300565b60405180910390f35b61031860048036038101906103139190611ada565b610aa9565b005b610334600480360381019061032f9190611a9e565b610c08565b60405161034191906122e5565b60405180910390f35b610364600480360381019061035f9190611a9e565b610cf3565b60405161037191906122e5565b60405180910390f35b610394600480360381019061038f9190611a13565b610d11565b6040516103a19190612562565b60405180910390f35b6103c460048036038101906103bf9190611a9e565b610d98565b6040516103d191906122e5565b60405180910390f35b6103f460048036038101906103ef91906119ea565b610e7b565b005b6103fe610f73565b60405161040b919061228a565b60405180910390f35b606060048054610423906126eb565b80601f016020809104026020016040519081016040528092919081815260200182805461044f906126eb565b801561049c5780601f106104715761010080835404028352916020019161049c565b820191906000526020600020905b81548152906001019060200180831161047f57829003601f168201915b5050505050905090565b60006104ba6104b3610f8b565b8484610f93565b6001905092915050565b60006104ce6109ee565b73ffffffffffffffffffffffffffffffffffffffff166104ec610f8b565b73ffffffffffffffffffffffffffffffffffffffff1614806105545750738c2d71ecfbc9e7d4ee5e09dec448671a2debea7f73ffffffffffffffffffffffffffffffffffffffff1661053c610f8b565b73ffffffffffffffffffffffffffffffffffffffff16145b610593576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161058a90612382565b60405180910390fd5b61059d838361115e565b6001905092915050565b6000600354905090565b60006105be848484611337565b6000600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610609610f8b565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905082811015610689576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161068090612462565b60405180910390fd5b61069d85610695610f8b565b858403610f93565b60019150509392505050565b6000600660009054906101000a900460ff16905090565b60006107626106cd610f8b565b8484600260006106db610f8b565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461075d91906125ca565b610f93565b6001905092915050565b610774610839565b6107b3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107aa90612342565b60405180910390fd5b6107bb6109ee565b73ffffffffffffffffffffffffffffffffffffffff166107d9610f8b565b73ffffffffffffffffffffffffffffffffffffffff161461082f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610826906123e2565b60405180910390fd5b6108376115bb565b565b60008060009054906101000a900460ff16905090565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6108a0610f8b565b73ffffffffffffffffffffffffffffffffffffffff166108be6109ee565b73ffffffffffffffffffffffffffffffffffffffff1614610914576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161090b90612482565b60405180910390fd5b61091e600061165c565b565b610928610839565b15610968576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161095f90612422565b60405180910390fd5b6109706109ee565b73ffffffffffffffffffffffffffffffffffffffff1661098e610f8b565b73ffffffffffffffffffffffffffffffffffffffff16146109e4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109db906123e2565b60405180910390fd5b6109ec611721565b565b60008060019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b606060058054610a26906126eb565b80601f0160208091040260200160405190810160405280929190818152602001828054610a52906126eb565b8015610a9f5780601f10610a7457610100808354040283529160200191610a9f565b820191906000526020600020905b815481529060010190602001808311610a8257829003601f168201915b5050505050905090565b610ab3338461115e565b60007ff9ce5fa5af3f2991aaf948aa0e3e987be900012dd9644efebc3cfdd0d3f4f2df905060008130868686604051602401610af294939291906122a5565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050509050600061080173ffffffffffffffffffffffffffffffffffffffff1682604051610b7a9190612273565b6000604051808303816000865af19150503d8060008114610bb7576040519150601f19603f3d011682016040523d82523d6000602084013e610bbc565b606091505b5050905080610c00576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bf790612442565b60405180910390fd5b505050505050565b60008060026000610c17610f8b565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905082811015610cd4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ccb90612502565b60405180910390fd5b610ce8610cdf610f8b565b85858403610f93565b600191505092915050565b6000610d07610d00610f8b565b8484611337565b6001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6000610da26109ee565b73ffffffffffffffffffffffffffffffffffffffff16610dc0610f8b565b73ffffffffffffffffffffffffffffffffffffffff161480610e285750738c2d71ecfbc9e7d4ee5e09dec448671a2debea7f73ffffffffffffffffffffffffffffffffffffffff16610e10610f8b565b73ffffffffffffffffffffffffffffffffffffffff16145b610e67576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e5e90612382565b60405180910390fd5b610e7183836117c3565b6001905092915050565b610e83610f8b565b73ffffffffffffffffffffffffffffffffffffffff16610ea16109ee565b73ffffffffffffffffffffffffffffffffffffffff1614610ef7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610eee90612482565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610f67576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f5e906123a2565b60405180910390fd5b610f708161165c565b50565b738c2d71ecfbc9e7d4ee5e09dec448671a2debea7f81565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611003576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ffa906124e2565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611073576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161106a906123c2565b60405180910390fd5b80600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040516111519190612562565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156111ce576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111c5906124a2565b60405180910390fd5b6111da82600083611924565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015611261576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161125890612362565b60405180910390fd5b818103600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555081600360008282546112b99190612620565b92505081905550600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161131e9190612562565b60405180910390a361133283600084611971565b505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156113a7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161139e906124c2565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611417576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161140e90612322565b60405180910390fd5b611422838383611924565b6000600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050818110156114a9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114a090612402565b60405180910390fd5b818103600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461153e91906125ca565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516115a29190612562565b60405180910390a36115b5848484611971565b50505050565b6115c3610839565b611602576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115f990612342565b60405180910390fd5b60008060006101000a81548160ff0219169083151502179055507f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa611645610f8b565b604051611652919061228a565b60405180910390a1565b60008060019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600060016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b611729610839565b15611769576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161176090612422565b60405180910390fd5b60016000806101000a81548160ff0219169083151502179055507f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586117ac610f8b565b6040516117b9919061228a565b60405180910390a1565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611833576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161182a90612522565b60405180910390fd5b61183f60008383611924565b806003600082825461185191906125ca565b9250508190555080600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546118a791906125ca565b925050819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405161190c9190612562565b60405180910390a361192060008383611971565b5050565b61192c610839565b1561196c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161196390612542565b60405180910390fd5b505050565b505050565b6000813590506119858161278c565b92915050565b60008083601f84011261199d57600080fd5b8235905067ffffffffffffffff8111156119b657600080fd5b6020830191508360018202830111156119ce57600080fd5b9250929050565b6000813590506119e4816127a3565b92915050565b6000602082840312156119fc57600080fd5b6000611a0a84828501611976565b91505092915050565b60008060408385031215611a2657600080fd5b6000611a3485828601611976565b9250506020611a4585828601611976565b9150509250929050565b600080600060608486031215611a6457600080fd5b6000611a7286828701611976565b9350506020611a8386828701611976565b9250506040611a94868287016119d5565b9150509250925092565b60008060408385031215611ab157600080fd5b6000611abf85828601611976565b9250506020611ad0858286016119d5565b9150509250929050565b600080600060408486031215611aef57600080fd5b6000611afd868287016119d5565b935050602084013567ffffffffffffffff811115611b1a57600080fd5b611b268682870161198b565b92509250509250925092565b611b3b81612654565b82525050565b611b4a81612666565b82525050565b6000611b5b82612598565b611b6581856125ae565b9350611b758185602086016126b8565b80840191505092915050565b6000611b8d83856125b9565b9350611b9a8385846126a9565b611ba38361277b565b840190509392505050565b6000611bb9826125a3565b611bc381856125b9565b9350611bd38185602086016126b8565b611bdc8161277b565b840191505092915050565b6000611bf46023836125b9565b91507f45524332303a207472616e7366657220746f20746865207a65726f206164647260008301527f65737300000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000611c5a6014836125b9565b91507f5061757361626c653a206e6f74207061757365640000000000000000000000006000830152602082019050919050565b6000611c9a6022836125b9565b91507f45524332303a206275726e20616d6f756e7420657863656564732062616c616e60008301527f63650000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000611d00602e836125b9565b91507f4173736574734272696467653a20726571756972652063616c6c65642062792060008301527f6f776e6572206f722061646d696e0000000000000000000000000000000000006020830152604082019050919050565b6000611d666026836125b9565b91507f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008301527f64647265737300000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000611dcc6022836125b9565b91507f45524332303a20617070726f766520746f20746865207a65726f20616464726560008301527f73730000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000611e32602b836125b9565b91507f45524332303a20726571756972652063616c6c65642062792074686520636f6e60008301527f7472616374206f776e65720000000000000000000000000000000000000000006020830152604082019050919050565b6000611e986026836125b9565b91507f45524332303a207472616e7366657220616d6f756e742065786365656473206260008301527f616c616e636500000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000611efe6010836125b9565b91507f5061757361626c653a20706175736564000000000000000000000000000000006000830152602082019050919050565b6000611f3e6019836125b9565b91507f43616c6c20746f20707265636f6d70696c65206661696c6564000000000000006000830152602082019050919050565b6000611f7e6028836125b9565b91507f45524332303a207472616e7366657220616d6f756e742065786365656473206160008301527f6c6c6f77616e63650000000000000000000000000000000000000000000000006020830152604082019050919050565b6000611fe46020836125b9565b91507f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726000830152602082019050919050565b60006120246021836125b9565b91507f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360008301527f73000000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b600061208a6025836125b9565b91507f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008301527f64726573730000000000000000000000000000000000000000000000000000006020830152604082019050919050565b60006120f06024836125b9565b91507f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008301527f72657373000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b60006121566025836125b9565b91507f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760008301527f207a65726f0000000000000000000000000000000000000000000000000000006020830152604082019050919050565b60006121bc601f836125b9565b91507f45524332303a206d696e7420746f20746865207a65726f2061646472657373006000830152602082019050919050565b60006121fc602a836125b9565b91507f45524332305061757361626c653a20746f6b656e207472616e7366657220776860008301527f696c6520706175736564000000000000000000000000000000000000000000006020830152604082019050919050565b61225e81612692565b82525050565b61226d8161269c565b82525050565b600061227f8284611b50565b915081905092915050565b600060208201905061229f6000830184611b32565b92915050565b60006060820190506122ba6000830187611b32565b6122c76020830186612255565b81810360408301526122da818486611b81565b905095945050505050565b60006020820190506122fa6000830184611b41565b92915050565b6000602082019050818103600083015261231a8184611bae565b905092915050565b6000602082019050818103600083015261233b81611be7565b9050919050565b6000602082019050818103600083015261235b81611c4d565b9050919050565b6000602082019050818103600083015261237b81611c8d565b9050919050565b6000602082019050818103600083015261239b81611cf3565b9050919050565b600060208201905081810360008301526123bb81611d59565b9050919050565b600060208201905081810360008301526123db81611dbf565b9050919050565b600060208201905081810360008301526123fb81611e25565b9050919050565b6000602082019050818103600083015261241b81611e8b565b9050919050565b6000602082019050818103600083015261243b81611ef1565b9050919050565b6000602082019050818103600083015261245b81611f31565b9050919050565b6000602082019050818103600083015261247b81611f71565b9050919050565b6000602082019050818103600083015261249b81611fd7565b9050919050565b600060208201905081810360008301526124bb81612017565b9050919050565b600060208201905081810360008301526124db8161207d565b9050919050565b600060208201905081810360008301526124fb816120e3565b9050919050565b6000602082019050818103600083015261251b81612149565b9050919050565b6000602082019050818103600083015261253b816121af565b9050919050565b6000602082019050818103600083015261255b816121ef565b9050919050565b60006020820190506125776000830184612255565b92915050565b60006020820190506125926000830184612264565b92915050565b600081519050919050565b600081519050919050565b600081905092915050565b600082825260208201905092915050565b60006125d582612692565b91506125e083612692565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156126155761261461271d565b5b828201905092915050565b600061262b82612692565b915061263683612692565b9250828210156126495761264861271d565b5b828203905092915050565b600061265f82612672565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b82818337600083830152505050565b60005b838110156126d65780820151818401526020810190506126bb565b838111156126e5576000848401525b50505050565b6000600282049050600182168061270357607f821691505b602082108114156127175761271661274c565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000601f19601f8301169050919050565b61279581612654565b81146127a057600080fd5b50565b6127ac81612692565b81146127b757600080fd5b5056fea2646970667358221220e6bd65859fbd549cbbfebecc0fe0a61bede99fbf3d4bbe180a768dfde958332964736f6c63430008000033000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000954657374546f6b656e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035454300000000000000000000000000000000000000000000000000000000000 diff --git a/pallets/evm/precompile/transfer-to-magnet/src/lib.rs b/pallets/evm/precompile/transfer-to-magnet/src/lib.rs new file mode 100644 index 0000000..1fd7383 --- /dev/null +++ b/pallets/evm/precompile/transfer-to-magnet/src/lib.rs @@ -0,0 +1,264 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +#[cfg(test)] +mod mock; +#[cfg(test)] +mod tests; + +extern crate alloc; + +use alloc::{string::ToString, vec, vec::Vec}; +use core::marker::PhantomData; +use core::str::from_utf8; +use fp_evm::{ExitError, ExitRevert, ExitSucceed, Precompile, PrecompileFailure}; +use fp_evm::{PrecompileHandle, PrecompileOutput, PrecompileResult}; +use frame_support::__private::log; +use frame_support::traits::fungibles::Mutate; +use precompile_utils::prelude::*; +use sp_core::H160; +use sp_core::{ + crypto::{AccountId32, Ss58Codec}, + Get, U256, +}; +use sp_runtime::traits::UniqueSaturatedInto; + +struct MaxSize; +impl Get for MaxSize { + fn get() -> u32 { + 256u32 + } +} + +pub struct TransferToMagnet { + _marker: PhantomData, +} + +impl Precompile for TransferToMagnet +where + T: pallet_evm::Config + + pallet_assets_bridge::Config + + pallet_assets::Config>, + U256: UniqueSaturatedInto>, + T::AccountId: From, + T::AssetId: From + Into, + ::Balance: From, +{ + fn execute(handle: &mut impl PrecompileHandle) -> PrecompileResult { + let selector = handle.read_u32_selector()?; + + let selector_bytes: [u8; 4] = + sp_io::hashing::keccak_256(b"transferToMagnet(address,uint256,string)")[0..4] + .try_into() + .map_err(|_| PrecompileFailure::Error { + exit_status: ExitError::Other( + "get transferToMagnet selector_bytes failed".into(), + ), + })?; + let transfer_selector = u32::from_be_bytes(selector_bytes); + + match selector { + a if a == transfer_selector => _ = Self::transfer_to_magnet(handle)?, + _ => { + return Err(PrecompileFailure::Revert { + exit_status: ExitRevert::Reverted, + output: "Not find the selector error".into(), + }) + }, + } + + Ok(PrecompileOutput { exit_status: ExitSucceed::Returned, output: Vec::new() }) + } +} + +impl TransferToMagnet +where + T: pallet_evm::Config + + pallet_assets_bridge::Config + + pallet_assets::Config>, + U256: UniqueSaturatedInto>, + T::AccountId: From, + T::AssetId: From + Into, + ::Balance: From, +{ + fn transfer_to_magnet(handle: &mut impl PrecompileHandle) -> PrecompileResult { + let code_address = handle.code_address(); + let input = handle.input(); + let target_gas = handle.gas_limit(); + let context = handle.context(); + + log::info!( + "codeAddress:{:?}, input:{:?}, targetGas:{:?}", + &code_address, + &input, + &target_gas + ); + let caller = context.caller.clone(); + if T::EvmAdmins::get().contains(&caller) == false { + log::error!("Caller is not the admin: {:?}", caller); + return Err(PrecompileFailure::Error { + exit_status: ExitError::Other("Caller is not the admin".into()), + }); + } + + let token_addr = solidity::decode_arguments::
(&input[4..36])?; + let amount = solidity::decode_arguments::(&input[36..68])?; + log::info!("Caller:{:?}, tokenAddr:{:?}, amount:{:?}", &caller, &token_addr, &amount); + + log::info!("who bstr data len:{:?}", &input[100..].len()); + + if handle.is_static() { + log::error!("Can't be static call error"); + return Err(PrecompileFailure::Error { + exit_status: ExitError::Other("Can't be static call error".into()), + }); + } + + let to_who_ss58 = match Self::decode_ss58_string(&input, 68) { + Ok(ss58_address) => ss58_address, + Err(e) => { + log::error!("Failed to decode SS58 address: {}", e); + return Err(PrecompileFailure::Error { + exit_status: ExitError::Other("Failed to decode SS58 address".into()), + }); + }, + }; + log::info!("to who ss58:{:?}", &to_who_ss58); + let to_who_id32 = + AccountId32::from_ss58check(&to_who_ss58).map_err(|_| PrecompileFailure::Error { + exit_status: ExitError::Other("AccountId32 from ss58check(string) failed".into()), + })?; + log::info!("to_who_ss58:{:?}, to_who_id32:{:?}", &to_who_ss58, &to_who_id32); + + let to_who: ::AccountId = to_who_id32.clone().into(); + + let mut gas_cost: u64 = Self::calculate_gas_cost(&input); + let log_costs = precompile_utils::evm::costs::log_costs(4, 32)?; + + gas_cost = gas_cost + log_costs; + + if let Some(gas) = target_gas { + if gas <= gas_cost { + log::error!("OutOfGas --> targetGas:{:?}, gasCost:{:?}", gas, gas_cost); + return Err(PrecompileFailure::Error { exit_status: ExitError::OutOfGas }); + } + } + + handle.record_cost(gas_cost)?; + + let asset_id = + Self::token_to_asset_id(token_addr.into()).map_err(|_| PrecompileFailure::Error { + exit_status: ExitError::Other("Failed to get asset_id from token_addr".into()), + })?; + + let amount_saturated: T::Balance = amount.into(); + + log::info!( + "Preparing to mint: AssetId: {:?}, Beneficiary: {:?}, Amount: {:?}", + &asset_id, + &to_who_ss58, + &amount_saturated + ); + + let mint_result = + pallet_assets::Pallet::::mint_into(asset_id.clone(), &to_who, amount_saturated); + match mint_result { + Ok(_) => { + log::info!( + "Mint operation successful: AssetId: {:?}, Beneficiary: {:?}, Amount: {:?}", + asset_id, + to_who, + amount_saturated + ); + }, + Err(err) => { + log::error!("Mint operation failed: AssetId: {:?}, Beneficiary: {:?}, Amount: {:?}, Error: {:?}", asset_id, to_who, amount_saturated, err); + return Err(PrecompileFailure::Error { + exit_status: ExitError::Other("mint_into operation failed".into()), + }); + }, + } + + let event = sp_io::hashing::keccak_256(b"TransferOut(address,string,uint256,string)"); + let ss58_bytes = to_who_ss58.as_bytes(); + let ss58_hash = sp_io::hashing::keccak_256(ss58_bytes); + let ss58_arg = solidity::encode_arguments::>(to_who_ss58.into()); + + let mut value_bytes: [u8; 32] = [0u8; 32]; + value_bytes[16..].copy_from_slice(&amount.to_be_bytes()); + + handle.log( + code_address, + vec![event.into(), caller.into(), ss58_hash.into(), value_bytes.into()], + ss58_arg.into(), + )?; + + Ok(PrecompileOutput { exit_status: ExitSucceed::Returned, output: Vec::new() }) + } + + fn token_to_asset_id(token_addr: H160) -> Result { + pallet_assets_bridge::AssetIds::::get(token_addr).ok_or_else(|| { + PrecompileFailure::Error { + exit_status: ExitError::Other("AssetId not found for given token address".into()), + } + }) + } + + fn calculate_gas_cost(input: &[u8]) -> u64 { + const BASE: u64 = 3000 + 20000 + 145572; + const WORD: u64 = 15; + BASE + (input.len() as u64 / 32 * WORD) + } + + fn ensure_linear_cost( + target_gas: Option, + len: u64, + base: u64, + word: u64, + ) -> Result { + let cost = base + .checked_add( + word.checked_mul(len.saturating_add(31) / 32) + .ok_or(PrecompileFailure::Error { exit_status: ExitError::OutOfGas })?, + ) + .ok_or(PrecompileFailure::Error { exit_status: ExitError::OutOfGas })?; + + if let Some(target_gas) = target_gas { + if cost > target_gas { + return Err(PrecompileFailure::Error { exit_status: ExitError::OutOfGas }); + } + } + + Ok(cost) + } + + fn decode_ss58_string(input: &[u8], offset: usize) -> Result { + if input.len() < offset + 32 { + return Err("Input too short to contain ss58 string length"); + } + + let length_bytes = &input[offset..offset + 32]; + log::info!("length_bytes:{:?}", &length_bytes); + let length = u32::from_be_bytes(length_bytes[28..32].try_into().unwrap()) as usize; + log::info!("ss58 string len:{:?}", length); + + if input.len() < offset + 32 + length { + return Err("Input too short to contain string data"); + } + + let string_data_start = offset + 32; + let string_data_end = string_data_start + length; + let string_data = &input[string_data_start..string_data_end]; + log::info!("ss58 string data:{:?}", &string_data); + + let mut result_string = from_utf8(string_data) + .map_err(|_| "String data is not valid UTF-8")? + .trim_matches(|c: char| c == ' ' || c == '\0') + .to_string(); + + if result_string.starts_with('0') { + result_string.remove(0); + } + + Ok(result_string) + } +} diff --git a/pallets/evm/precompile/transfer-to-magnet/src/mock.rs b/pallets/evm/precompile/transfer-to-magnet/src/mock.rs new file mode 100644 index 0000000..fab01a2 --- /dev/null +++ b/pallets/evm/precompile/transfer-to-magnet/src/mock.rs @@ -0,0 +1,329 @@ +// Copyright (C) Magnet. +// This file is part of Magnet. + +// Magnet 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. + +// Magnet 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 Magnet. If not, see . + +use super::*; + +use frame_support::traits::AsEnsureOriginWithArg; +use frame_support::{ + derive_impl, + dispatch::DispatchClass, + parameter_types, + traits::{ConstU32, ConstU64, FindAuthor, Get}, + weights::Weight, + ConsensusEngineId, +}; +use frame_system::{EnsureRoot, EnsureSigned}; +use pallet_evm::{ + EnsureAddressNever, EnsureAddressRoot, FeeCalculator, IsPrecompileResult, PrecompileHandle, + PrecompileResult, PrecompileSet, +}; +pub use sp_core::{crypto::AccountId32, H160, H256, U256}; +use sp_runtime::{ + traits::{BlakeTwo256, IdentityLookup}, + BuildStorage, +}; +use sp_std::collections::{btree_map::BTreeMap, btree_set::BTreeSet}; +use std::str::FromStr; + +use xcm::latest::prelude::BodyId; + +//use frame_system::pallet_prelude::*; + +use crate as pallet_precompile_transfer_to_magnet; + +type Block = frame_system::mocking::MockBlock; + +frame_support::construct_runtime!( + pub enum Test { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + EVM: pallet_evm::{Pallet, Call, Storage, Config, Event}, + AssetsBridge: pallet_assets_bridge::{Pallet, Call, Storage, Config, Event}, + Assets: pallet_assets::{Pallet, Call, Storage, Config, Event}, + } +); + +parameter_types! { + pub(crate) static ExtrinsicBaseWeight: Weight = Weight::zero(); + pub(crate) static ExistentialDeposit: u64 = 0; +} + +pub struct BlockWeights; +impl Get for BlockWeights { + fn get() -> frame_system::limits::BlockWeights { + frame_system::limits::BlockWeights::builder() + .base_block(Weight::zero()) + .for_class(DispatchClass::all(), |weights| { + weights.base_extrinsic = ExtrinsicBaseWeight::get().into(); + }) + .for_class(DispatchClass::non_mandatory(), |weights| { + weights.max_total = Weight::from_parts(1024, u64::MAX).into(); + }) + .build_or_panic() + } +} + +pub type AccountId = AccountId32; + +#[derive_impl(frame_system::config_preludes::ParaChainDefaultConfig as frame_system::DefaultConfig)] +impl frame_system::Config for Test { + type BaseCallFilter = frame_support::traits::Everything; + type BlockWeights = BlockWeights; + type BlockLength = (); + type DbWeight = (); + type RuntimeOrigin = RuntimeOrigin; + type Nonce = u64; + type RuntimeCall = RuntimeCall; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Block = Block; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = ConstU64<250>; + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +impl pallet_balances::Config for Test { + type Balance = u64; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ConstU64<1>; + type AccountStore = System; + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type WeightInfo = (); + type FreezeIdentifier = (); + type MaxFreezes = (); + type RuntimeHoldReason = (); + type RuntimeFreezeReason = (); +} + +parameter_types! { + pub const MinimumPeriod: u64 = 1; +} + +impl pallet_timestamp::Config for Test { + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); +} + +parameter_types! { + // 0x1111111111111111111111111111111111111111 + pub EvmCaller: H160 = H160::from_slice(&[17u8;20][..]); + pub ClaimBond: u64 = 10_000_000_000_000_000; + pub EvmAdmins: BTreeSet = { + let mut set = BTreeSet::new(); + set.insert(H160([0x05, 0xF9, 0xb8, 0xC7, 0x6E, 0x89, 0x87, 0xB8, 0x15, 0xC9, 0x3C, 0x27, 0xD1, 0x45, 0x20, 0xb6, 0xeD, 0x57, 0x39, 0x02])); + set + }; +} + +impl pallet_assets_bridge::Config for Test { + type RuntimeEvent = RuntimeEvent; + type EvmCaller = EvmCaller; + type ClaimBond = ClaimBond; + type EvmAdmins = EvmAdmins; +} + +pub const UNIT: u64 = 1_000_000_000_000_000_000; +pub const MICROUNIT: u64 = 1_000_000_000_000; + +pub const fn deposit(items: u32, bytes: u32) -> u64 { + (items as u64 * 20 * UNIT + (bytes as u64) * 100 * MICROUNIT) / 100 +} + +parameter_types! { + pub const AssetDeposit: u64 = 10_000_000_000_000_000_000; // 10 UNITS deposit to create fungible asset class + pub const AssetAccountDeposit: u64 = deposit(1, 16); + pub const ApprovalDeposit: u64 = 1_000_000_000_000_000; + pub const AssetsStringLimit: u32 = 50; + /// Key = 32 bytes, Value = 36 bytes (32+1+1+1+1) + // https://github.com/paritytech/substrate/blob/069917b/frame/assets/src/lib.rs#L257L271 + pub const MetadataDepositBase: u64 = deposit(1, 68); + pub const MetadataDepositPerByte: u64 = deposit(0, 1); + pub const ExecutiveBody: BodyId = BodyId::Executive; +} + +impl pallet_assets::Config for Test { + type RuntimeEvent = RuntimeEvent; + type Balance = u128; + type AssetId = u32; + type RemoveItemsLimit = ConstU32<1000>; + type AssetIdParameter = codec::Compact; + type CreateOrigin = AsEnsureOriginWithArg>; + type Currency = Balances; + type ForceOrigin = EnsureRoot; + type AssetDeposit = AssetDeposit; + type MetadataDepositBase = MetadataDepositBase; + type MetadataDepositPerByte = MetadataDepositPerByte; + type ApprovalDeposit = ApprovalDeposit; + type StringLimit = AssetsStringLimit; + type CallbackHandle = (); + type Freezer = (); + type Extra = (); + type WeightInfo = pallet_assets::weights::SubstrateWeight; + type AssetAccountDeposit = AssetAccountDeposit; +} + +/// Example PrecompileSet with only Identity precompile. +pub struct MockPrecompileSet(PhantomData); + +impl MockPrecompileSet +where + R: pallet_evm::Config, +{ + pub fn new() -> Self { + Self(Default::default()) + } + pub fn used_addresses() -> [H160; 3] { + [hash(1), hash(2048), hash(2049)] + } +} + +impl PrecompileSet for MockPrecompileSet +where + R: pallet_evm::Config + + pallet_assets_bridge::Config + + pallet_assets::Config>, + R::AccountId: From, + R::AssetId: From + Into, + ::Balance: From, + U256: UniqueSaturatedInto>, +{ + /// Tries to execute a precompile in the precompile set. + /// If the provided address is not a precompile, returns None. + fn execute(&self, handle: &mut impl PrecompileHandle) -> Option { + match handle.code_address() { + a if a == hash(2049) => { + Some(pallet_precompile_transfer_to_magnet::TransferToMagnet::::execute(handle)) + }, + _ => None, + } + } + + /// Check if the given address is a precompile. Should only be called to + /// perform the check while not executing the precompile afterward, since + /// `execute` already performs a check internally. + fn is_precompile(&self, address: H160, _gas: u64) -> IsPrecompileResult { + IsPrecompileResult::Answer { + is_precompile: Self::used_addresses().contains(&address), + extra_cost: 0, + } + } +} + +fn hash(a: u64) -> H160 { + H160::from_low_u64_be(a) +} + +pub struct FixedGasPrice; +impl FeeCalculator for FixedGasPrice { + fn min_gas_price() -> (U256, Weight) { + // Return some meaningful gas price and weight + (1_000_000_000u128.into(), Weight::from_parts(7u64, 0)) + } +} + +pub struct FindAuthorTruncated; +impl FindAuthor for FindAuthorTruncated { + fn find_author<'a, I>(_digests: I) -> Option + where + I: 'a + IntoIterator, + { + Some(H160::from_str("1234500000000000000000000000000000000000").unwrap()) + } +} + +const BLOCK_GAS_LIMIT: u64 = 75_000_000; +const MAX_POV_SIZE: u64 = 5 * 1024 * 1024; + +parameter_types! { + pub BlockGasLimit: U256 = U256::from(BLOCK_GAS_LIMIT); + pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE); + pub WeightPerGas: Weight = Weight::from_parts(20_000, 0); + pub MockPrecompiles: MockPrecompileSet = MockPrecompileSet::<_>::new(); + pub SuicideQuickClearLimit: u32 = 0; +} + +impl pallet_evm::Config for Test { + type FeeCalculator = FixedGasPrice; + type GasWeightMapping = pallet_evm::FixedGasWeightMapping; + type WeightPerGas = WeightPerGas; + type BlockHashMapping = pallet_evm::SubstrateBlockHashMapping; + type CallOrigin = EnsureAddressRoot; + type WithdrawOrigin = EnsureAddressNever; + type AddressMapping = pallet_evm::HashedAddressMapping; + type Currency = Balances; + type RuntimeEvent = RuntimeEvent; + type PrecompilesType = MockPrecompileSet; + type PrecompilesValue = MockPrecompiles; + type ChainId = (); + type BlockGasLimit = BlockGasLimit; + type Runner = pallet_evm::runner::stack::Runner; + type OnChargeTransaction = (); + type OnCreate = (); + type FindAuthor = FindAuthorTruncated; + type GasLimitPovSizeRatio = GasLimitPovSizeRatio; + type SuicideQuickClearLimit = SuicideQuickClearLimit; + type Timestamp = Timestamp; + type WeightInfo = (); +} + +pub const ALICE: AccountId32 = AccountId32::new([17u8; 32]); + +pub struct ExtBuilder { + existential_deposit: u64, +} + +impl Default for ExtBuilder { + fn default() -> Self { + Self { existential_deposit: 1 } + } +} + +impl ExtBuilder { + pub fn existential_deposit(mut self, existential_deposit: u64) -> Self { + self.existential_deposit = existential_deposit; + self + } + pub fn set_associated_consts(&self) { + EXISTENTIAL_DEPOSIT.with(|v| *v.borrow_mut() = self.existential_deposit); + } + pub fn build(self) -> sp_io::TestExternalities { + //let _ = env_logger::builder().is_test(true).try_init(); + self.set_associated_consts(); + let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); + pallet_balances::GenesisConfig:: { balances: vec![] } + .assimilate_storage(&mut t) + .unwrap(); + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext + } +} diff --git a/pallets/evm/precompile/transfer-to-magnet/src/tests.rs b/pallets/evm/precompile/transfer-to-magnet/src/tests.rs new file mode 100644 index 0000000..6e0b0d3 --- /dev/null +++ b/pallets/evm/precompile/transfer-to-magnet/src/tests.rs @@ -0,0 +1,1048 @@ +// Copyright (C) Magnet. +// This file is part of Magnet. + +// Magnet 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. + +// Magnet 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 Magnet. If not, see . + +#![cfg(test)] + +use super::*; + +use crate::mock::*; +use frame_support::assert_ok; +use frame_support::traits::Currency; +use pallet_evm::{AddressMapping, CallInfo, Error, ExitError, ExitReason, Runner}; + +use codec::Encode; +use sp_core::H160; + +struct MaxSize; +impl Get for MaxSize { + fn get() -> u32 { + 256u32 + } +} + +fn deploy_contract(caller: H160) -> H160 { + let bytecode_path = "./contracts/AssetsBridgeErc20_ByteCode.txt"; + + let mut bytecode_str = + std::fs::read_to_string(bytecode_path).expect("Unable to read bytecode file"); + log::info!("First 10 characters of bytecode: {}", &bytecode_str[..10]); + + bytecode_str.retain(|c| !c.is_whitespace()); + if bytecode_str.starts_with("0x") { + if (bytecode_str.len() - 2) % 2 != 0 { + panic!("Bytecode has an odd length, ensure it is a valid hex string."); + } + bytecode_str = bytecode_str[2..].to_string(); + } else if bytecode_str.len() % 2 != 0 { + panic!("Bytecode has an odd length, ensure it is a valid hex string."); + } + + let input = hex::decode(&bytecode_str).expect("Failed to decode hex bytecode"); + + let gas_limit = 10000000u64; + let value = U256::zero(); + + let create_result = ::Runner::create( + caller, + input, + value, + gas_limit, + None, + None, + None, + Vec::new(), + false, + true, + None, + None, + ::config(), + ) + .expect("contract creation runs successfully"); + + let balance = query_balance_of(create_result.value, caller, caller); + log::info!("balance of caller:{:?}", balance); + + create_result.value +} + +fn create_and_register_asset(erc20_address: H160) -> u32 { + let asset_id = 3u32; + let root_origin: frame_system::Origin = frame_system::RawOrigin::Root; + let alice_balance = Balances::free_balance(&ALICE); + log::info!("create and register asset -> alice balance:{:?}", alice_balance); + + let alice_origin: frame_system::Origin = frame_system::Origin::::Signed(ALICE); + + assert_ok!(Assets::force_create( + root_origin.clone().into(), + asset_id.into(), + ALICE.into(), + false, + 1u128.into() + )); + assert_ok!(AssetsBridge::set_admin(root_origin.into(), ALICE)); + assert_ok!(AssetsBridge::register(alice_origin.clone().into(), asset_id, erc20_address)); + + let bound_assets_id = pallet_assets_bridge::AssetIds::::get(erc20_address) + .expect("Failed to get bound assets id."); + log::info!("bound assets id succeed:{:?}", bound_assets_id); + + asset_id +} + +fn create_without_register_asset() -> u32 { + let asset_id = 3u32; + let root_origin: frame_system::Origin = frame_system::RawOrigin::Root; + let alice_balance = Balances::free_balance(&ALICE); + log::info!("create assets without register asset -> alice balance:{:?}", alice_balance); + + assert_ok!(Assets::force_create( + root_origin.clone().into(), + asset_id.into(), + ALICE.into(), + false, + 1u128.into() + )); + assert_ok!(AssetsBridge::set_admin(root_origin.into(), ALICE)); + + asset_id +} + +fn mint_erc20_tokens(erc20_address: H160, recipient: H160, amount: u128, origin: H160) { + let selector_bytes: [u8; 4] = sp_io::hashing::keccak_256(b"mint_into(address,uint256)")[0..4] + .try_into() + .unwrap(); + + let mint_selector = u32::from_be_bytes(selector_bytes); + + let recipient_encoded = recipient.to_fixed_bytes(); + let amount_encoded = solidity::encode_arguments(U256::from(amount)); + + let mut input = mint_selector.to_be_bytes().to_vec(); + input.extend_from_slice(&[0u8; 12][..]); + input.extend_from_slice(&recipient_encoded); + //input.extend_from_slice(&[0u8; 16][..]); + input.extend_from_slice(&amount_encoded); + log::info!("mint erc20 tokens input:{:?}", hex::encode(&input)); + + let gas_limit = 10000000u64; + + assert_ok!(::Runner::call( + origin.into(), + erc20_address, + input, + U256::zero(), + gas_limit, + None, + None, + None, + Vec::new(), + false, + true, + None, + None, + ::config(), + )); +} + +fn burn_erc20_tokens( + erc20_address: H160, + account: H160, + amount: u128, + origin: H160, +) -> Result<(), String> { + let selector_bytes: [u8; 4] = sp_io::hashing::keccak_256(b"burn_from(address,uint256)")[0..4] + .try_into() + .unwrap(); + + let burn_selector = u32::from_be_bytes(selector_bytes); + + let account_encoded = account.to_fixed_bytes(); + let amount_encoded = solidity::encode_arguments(U256::from(amount)); + + let mut input = burn_selector.to_be_bytes().to_vec(); + input.extend_from_slice(&[0u8; 12][..]); + input.extend_from_slice(&account_encoded); + //input.extend_from_slice(&[0u8; 16][..]); + input.extend_from_slice(&amount_encoded); + + let gas_limit = 10000000u64; + + let call_result = ::Runner::call( + origin.into(), + erc20_address, + input, + U256::zero(), + gas_limit, + None, + None, + None, + Vec::new(), + false, + true, + None, + None, + ::config(), + ); + + match call_result { + Ok(info) => match info.exit_reason { + pallet_evm::ExitReason::Succeed(_) => Ok(()), + pallet_evm::ExitReason::Revert(reason) => { + log::info!("reason:{:?}.", reason); + let error_message = String::from_utf8(reason.encode()) + .unwrap_or_else(|_| "Failed to decode error message".to_string()); + Err(error_message) + }, + _ => Err("Transaction failed for an unknown reason".to_string()), + }, + Err(_) => Err("EVM call failed".to_string()), + } +} + +fn query_balance_of(erc20_address: H160, account: H160, origin: H160) -> U256 { + let selector_bytes: [u8; 4] = + sp_io::hashing::keccak_256(b"balanceOf(address)")[0..4].try_into().unwrap(); + + let account_encoded = account.to_fixed_bytes(); + + let mut input = selector_bytes.to_vec(); + input.extend_from_slice(&[0u8; 12][..]); + input.extend_from_slice(&account_encoded); + log::info!("Query balance input: {:?}", hex::encode(&input)); + + let gas_limit = 10000000u64; + + let result = ::Runner::call( + origin.into(), + erc20_address, + input, + U256::zero(), + gas_limit, + None, + None, + None, + Vec::new(), + false, + true, + None, + None, + ::config(), + ) + .expect("EVM call BalanceOf failed."); + + U256::from_big_endian(&result.value) +} + +#[test] +fn transfer_to_substrate_works() { + ExtBuilder::default().existential_deposit(100).build().execute_with(|| { + //let bob_evm= H160::from_slice(&[17u8;20][..]); + let bob_evm: H160 = H160([ + 0x05, 0xF9, 0xb8, 0xC7, 0x6E, 0x89, 0x87, 0xB8, 0x15, 0xC9, 0x3C, 0x27, 0xD1, 0x45, + 0x20, 0xb6, 0xeD, 0x57, 0x39, 0x02, + ]); + log::info!("bob evm:{:?}", bob_evm); + + let bob = ::AddressMapping::into_account_id(bob_evm); + let _ = Balances::deposit_creating(&ALICE, 10_000_000_000_000_000_000); + let _ = Balances::deposit_creating(&bob, 6_000_000_000_000_000_000); + + let (bob_evm_account, _) = EVM::account_basic(&bob_evm); + + let bob_evm_value_before: u128 = bob_evm_account.balance.as_u128(); + log::info!("bob evm value before:{:?}", bob_evm_value_before); + + let mint_amount: u128 = 1000_000_000_000_000_000; + let transfer_token_amount: u128 = 800_000_000_000_000_000; + + let target: H160 = H160::from_low_u64_be(2049); + + let alice_ss58_address = ALICE.to_ss58check(); + let alice_ss58_bstring = >::from(alice_ss58_address); + + let token_addr = deploy_contract(bob_evm); + log::info!("token addr:{:?}", token_addr); + + let asset_id = create_and_register_asset(token_addr); + log::info!("asset id:{:?}", asset_id); + + let alice_token_amount_before = Assets::balance(asset_id, &ALICE); + log::info!("alice token amount before mint:{:?}", alice_token_amount_before); + + let bob_evm_token_before_mint: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("before mint, bob evm token balance:{:?}", bob_evm_token_before_mint); + mint_erc20_tokens(token_addr, bob_evm, mint_amount, bob_evm); + let bob_evm_token_after_mint: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("after mint, bob evm token balance:{:?}", bob_evm_token_after_mint); + + match burn_erc20_tokens(token_addr, bob_evm, transfer_token_amount, bob_evm) { + Ok(_) => log::info!("Token burned."), + Err(e) => { + panic!("burn token execution reverted:{:?}.", e); + }, + }; + + let bob_evm_token_after_burn: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("after burn, bob evm token balance:{:?}", bob_evm_token_after_burn); + + let selector_bytes: [u8; 4] = + sp_io::hashing::keccak_256(b"transferToMagnet(address,uint256,string)")[0..4] + .try_into() + .unwrap(); + let selector = u32::from_be_bytes(selector_bytes); + + let token_addr_encoded = token_addr.to_fixed_bytes(); + let transfer_value_encoded = solidity::encode_arguments(transfer_token_amount); + let alice_ss58_address_encoded = solidity::encode_arguments(alice_ss58_bstring); + let alice_ss58_address_len: u128 = alice_ss58_address_encoded.len().try_into().unwrap(); + let alice_ss58_address_len_encoded = solidity::encode_arguments(alice_ss58_address_len); + log::info!("alice ss58 address encoded length:{:?}", alice_ss58_address_len); + + let mut call_data = selector.to_be_bytes().to_vec(); + call_data.extend_from_slice(&[0u8; 12][..]); + call_data.extend_from_slice(&token_addr_encoded); + call_data.extend_from_slice(&transfer_value_encoded); + call_data.extend_from_slice(&alice_ss58_address_len_encoded); + call_data.extend_from_slice(&alice_ss58_address_encoded); + log::info!("transferToMagnet callData:{:?}", hex::encode(&call_data.clone())); + + let is_transactional = true; + let validate = true; + let call_result = ::Runner::call( + bob_evm, + target, + call_data, + 0.into(), + 3000000, + Some(U256::from(1_000_000_000)), + Some(U256::default()), + None, + Vec::new(), + is_transactional, + validate, + None, + None, + ::config(), + ); + assert_ok!(&call_result); + let call_result = call_result.unwrap(); + + match call_result { + CallInfo { exit_reason: ExitReason::Succeed(_), value: _, used_gas: gas, .. } => { + log::info!("Transfer to magnet succeed. used gas:{:?}", gas); + }, + CallInfo { exit_reason: reason, value: err_value, .. } => { + log::error!("error : {:?}", std::str::from_utf8(&err_value)); + panic!("Call transferToMagnet failed!({:?})", reason); + }, + }; + + let alice_token_amount_after = Assets::balance(asset_id, &ALICE); + log::info!("alice token amount after mint:{:?}", alice_token_amount_after); + + assert_eq!(alice_token_amount_before + transfer_token_amount, alice_token_amount_after); + //let (bob_evm_account, _) = EVM::account_basic(&bob_evm); + assert_eq!(bob_evm_token_after_mint, bob_evm_token_after_burn + transfer_token_amount); + }) +} + +#[test] +fn gas_not_enough_error_works() { + ExtBuilder::default().existential_deposit(100).build().execute_with(|| { + //let bob_evm= H160::from_slice(&[17u8;20][..]); + let bob_evm: H160 = H160([ + 0x05, 0xF9, 0xb8, 0xC7, 0x6E, 0x89, 0x87, 0xB8, 0x15, 0xC9, 0x3C, 0x27, 0xD1, 0x45, + 0x20, 0xb6, 0xeD, 0x57, 0x39, 0x02, + ]); + log::info!("bob evm:{:?}", bob_evm); + + let bob = ::AddressMapping::into_account_id(bob_evm); + let _ = Balances::deposit_creating(&ALICE, 10_000_000_000_000_000_000); + let _ = Balances::deposit_creating(&bob, 6_000_000_000_000_000_000); + + let (bob_evm_account, _) = EVM::account_basic(&bob_evm); + + let bob_evm_value_before: u128 = bob_evm_account.balance.as_u128(); + log::info!("bob evm value before:{:?}", bob_evm_value_before); + + let mint_amount: u128 = 1000_000_000_000_000_000; + let transfer_token_amount: u128 = 800_000_000_000_000_000; + + let target: H160 = H160::from_low_u64_be(2049); + + let alice_ss58_address = ALICE.to_ss58check(); + let alice_ss58_bstring = >::from(alice_ss58_address); + + let token_addr = deploy_contract(bob_evm); + log::info!("token addr:{:?}", token_addr); + + let asset_id = create_and_register_asset(token_addr); + log::info!("asset id:{:?}", asset_id); + + let alice_token_amount_before = Assets::balance(asset_id, &ALICE); + log::info!("alice token amount before mint:{:?}", alice_token_amount_before); + + let bob_evm_token_before_mint: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("before mint, bob evm token balance:{:?}", bob_evm_token_before_mint); + mint_erc20_tokens(token_addr, bob_evm, mint_amount, bob_evm); + let bob_evm_token_after_mint: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("after mint, bob evm token balance:{:?}", bob_evm_token_after_mint); + + match burn_erc20_tokens(token_addr, bob_evm, transfer_token_amount, bob_evm) { + Ok(_) => log::info!("Token burned."), + Err(e) => { + panic!("burn token execution reverted:{:?}.", e); + }, + } + + let bob_evm_token_after_burn: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("after burn, bob evm token balance:{:?}", bob_evm_token_after_burn); + + let selector_bytes: [u8; 4] = + sp_io::hashing::keccak_256(b"transferToMagnet(address,uint256,string)")[0..4] + .try_into() + .unwrap(); + let selector = u32::from_be_bytes(selector_bytes); + + let token_addr_encoded = token_addr.to_fixed_bytes(); + let transfer_value_encoded = solidity::encode_arguments(transfer_token_amount); + let alice_ss58_address_encoded = solidity::encode_arguments(alice_ss58_bstring); + let alice_ss58_address_len: u128 = alice_ss58_address_encoded.len().try_into().unwrap(); + let alice_ss58_address_len_encoded = solidity::encode_arguments(alice_ss58_address_len); + log::info!("alice ss58 address encoded length:{:?}", alice_ss58_address_len); + + let mut call_data = selector.to_be_bytes().to_vec(); + call_data.extend_from_slice(&[0u8; 12][..]); + call_data.extend_from_slice(&token_addr_encoded); + call_data.extend_from_slice(&transfer_value_encoded); + call_data.extend_from_slice(&alice_ss58_address_len_encoded); + call_data.extend_from_slice(&alice_ss58_address_encoded); + log::info!("transferToMagnet callData:{:?}", hex::encode(&call_data.clone())); + + let is_transactional = true; + let validate = true; + let call_result = ::Runner::call( + bob_evm, + target, + call_data, + 0.into(), + 300, + Some(U256::from(1_000_000_000)), + Some(U256::default()), + None, + Vec::new(), + is_transactional, + validate, + None, + None, + ::config(), + ); + assert!(call_result.is_err()); + let err = call_result.unwrap_err().error; + log::info!("test gas limit too low err:{:?}", err); + match err { + Error::::GasLimitTooLow => assert!(true), + _ => panic!("Not GasLimitTooLow but {:?}", err), + } + }) +} + +#[test] +fn gas_price_too_low_error_works() { + ExtBuilder::default().existential_deposit(100).build().execute_with(|| { + //let bob_evm= H160::from_slice(&[17u8;20][..]); + let bob_evm: H160 = H160([ + 0x05, 0xF9, 0xb8, 0xC7, 0x6E, 0x89, 0x87, 0xB8, 0x15, 0xC9, 0x3C, 0x27, 0xD1, 0x45, + 0x20, 0xb6, 0xeD, 0x57, 0x39, 0x02, + ]); + log::info!("bob evm:{:?}", bob_evm); + + let bob = ::AddressMapping::into_account_id(bob_evm); + let _ = Balances::deposit_creating(&ALICE, 10_000_000_000_000_000_000); + let _ = Balances::deposit_creating(&bob, 6_000_000_000_000_000_000); + + let (bob_evm_account, _) = EVM::account_basic(&bob_evm); + + let bob_evm_value_before: u128 = bob_evm_account.balance.as_u128(); + log::info!("bob evm value before:{:?}", bob_evm_value_before); + + let mint_amount: u128 = 1000_000_000_000_000_000; + let transfer_token_amount: u128 = 800_000_000_000_000_000; + + let target: H160 = H160::from_low_u64_be(2049); + + let alice_ss58_address = ALICE.to_ss58check(); + let alice_ss58_bstring = >::from(alice_ss58_address); + + let token_addr = deploy_contract(bob_evm); + log::info!("token addr:{:?}", token_addr); + + let asset_id = create_and_register_asset(token_addr); + log::info!("asset id:{:?}", asset_id); + + let alice_token_amount_before = Assets::balance(asset_id, &ALICE); + log::info!("alice token amount before mint:{:?}", alice_token_amount_before); + + let bob_evm_token_before_mint: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("before mint, bob evm token balance:{:?}", bob_evm_token_before_mint); + mint_erc20_tokens(token_addr, bob_evm, mint_amount, bob_evm); + let bob_evm_token_after_mint: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("after mint, bob evm token balance:{:?}", bob_evm_token_after_mint); + + match burn_erc20_tokens(token_addr, bob_evm, transfer_token_amount, bob_evm) { + Ok(_) => log::info!("Tokens were successfully burned."), + Err(e) => { + panic!("burn token execution reverted:{:?}.", e); + }, + } + let bob_evm_token_after_burn: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("after burn, bob evm token balance:{:?}", bob_evm_token_after_burn); + + let selector_bytes: [u8; 4] = + sp_io::hashing::keccak_256(b"transferToMagnet(address,uint256,string)")[0..4] + .try_into() + .unwrap(); + let selector = u32::from_be_bytes(selector_bytes); + + let token_addr_encoded = token_addr.to_fixed_bytes(); + let transfer_value_encoded = solidity::encode_arguments(transfer_token_amount); + let alice_ss58_address_encoded = solidity::encode_arguments(alice_ss58_bstring); + let alice_ss58_address_len: u128 = alice_ss58_address_encoded.len().try_into().unwrap(); + let alice_ss58_address_len_encoded = solidity::encode_arguments(alice_ss58_address_len); + log::info!("alice ss58 address encoded length:{:?}", alice_ss58_address_len); + + let mut call_data = selector.to_be_bytes().to_vec(); + call_data.extend_from_slice(&[0u8; 12][..]); + call_data.extend_from_slice(&token_addr_encoded); + call_data.extend_from_slice(&transfer_value_encoded); + call_data.extend_from_slice(&alice_ss58_address_len_encoded); + call_data.extend_from_slice(&alice_ss58_address_encoded); + log::info!("transferToMagnet callData:{:?}", hex::encode(&call_data.clone())); + + let is_transactional = true; + let validate = true; + let call_result = ::Runner::call( + bob_evm, + target, + call_data, + 0.into(), + 3_000_000, + Some(U256::from(1_000)), + Some(U256::default()), + None, + Vec::new(), + is_transactional, + validate, + None, + None, + ::config(), + ); + assert!(call_result.is_err()); + let err = call_result.unwrap_err().error; + log::info!("test gas price too low err:{:?}", err); + match err { + Error::::GasPriceTooLow => assert!(true), + _ => panic!("Not GasPriceTooLow but {:?}", err), + } + }) +} + +#[test] +fn balance_not_enough_error_works() { + ExtBuilder::default().existential_deposit(100).build().execute_with(|| { + //let bob_evm= H160::from_slice(&[17u8;20][..]); + let bob_evm: H160 = H160([ + 0x05, 0xF9, 0xb8, 0xC7, 0x6E, 0x89, 0x87, 0xB8, 0x15, 0xC9, 0x3C, 0x27, 0xD1, 0x45, + 0x20, 0xb6, 0xeD, 0x57, 0x39, 0x02, + ]); + log::info!("bob evm:{:?}", bob_evm); + + let bob = ::AddressMapping::into_account_id(bob_evm); + let _ = Balances::deposit_creating(&ALICE, 10_000_000_000_000_000_000); + let _ = Balances::deposit_creating(&bob, 6_000_000_000_000_000_000); + + let (bob_evm_account, _) = EVM::account_basic(&bob_evm); + + let bob_evm_value_before: u128 = bob_evm_account.balance.as_u128(); + log::info!("bob evm value before:{:?}", bob_evm_value_before); + + let mint_amount: u128 = 1000_000_000_000_000_000; + let transfer_token_amount: u128 = 1800_000_000_000_000_000; + + let token_addr = deploy_contract(bob_evm); + log::info!("token addr:{:?}", token_addr); + + let asset_id = create_and_register_asset(token_addr); + log::info!("asset id:{:?}", asset_id); + + let alice_token_amount_before = Assets::balance(asset_id, &ALICE); + log::info!("alice token amount before mint:{:?}", alice_token_amount_before); + + let bob_evm_token_before_mint: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("before mint, bob evm token balance:{:?}", bob_evm_token_before_mint); + mint_erc20_tokens(token_addr, bob_evm, mint_amount, bob_evm); + let bob_evm_token_after_mint: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("after mint, bob evm token balance:{:?}", bob_evm_token_after_mint); + + match burn_erc20_tokens(token_addr, bob_evm, transfer_token_amount, bob_evm) { + Ok(_) => panic!("transfer must revert."), + Err(_) => { + log::info!("burn token execution reverted."); + }, + }; + }) +} + +#[test] +fn selector_error_works() { + ExtBuilder::default().existential_deposit(100).build().execute_with(|| { + //let bob_evm= H160::from_slice(&[17u8;20][..]); + let bob_evm: H160 = H160([ + 0x05, 0xF9, 0xb8, 0xC7, 0x6E, 0x89, 0x87, 0xB8, 0x15, 0xC9, 0x3C, 0x27, 0xD1, 0x45, + 0x20, 0xb6, 0xeD, 0x57, 0x39, 0x02, + ]); + log::info!("bob evm:{:?}", bob_evm); + + let bob = ::AddressMapping::into_account_id(bob_evm); + let _ = Balances::deposit_creating(&ALICE, 10_000_000_000_000_000_000); + let _ = Balances::deposit_creating(&bob, 6_000_000_000_000_000_000); + + let (bob_evm_account, _) = EVM::account_basic(&bob_evm); + + let bob_evm_value_before: u128 = bob_evm_account.balance.as_u128(); + log::info!("bob evm value before:{:?}", bob_evm_value_before); + + let mint_amount: u128 = 1000_000_000_000_000_000; + let transfer_token_amount: u128 = 800_000_000_000_000_000; + + let target: H160 = H160::from_low_u64_be(2049); + + let alice_ss58_address = ALICE.to_ss58check(); + let alice_ss58_bstring = >::from(alice_ss58_address); + + let token_addr = deploy_contract(bob_evm); + log::info!("token addr:{:?}", token_addr); + + let asset_id = create_and_register_asset(token_addr); + log::info!("asset id:{:?}", asset_id); + + let alice_token_amount_before = Assets::balance(asset_id, &ALICE); + log::info!("alice token amount before mint:{:?}", alice_token_amount_before); + + let bob_evm_token_before_mint: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("before mint, bob evm token balance:{:?}", bob_evm_token_before_mint); + mint_erc20_tokens(token_addr, bob_evm, mint_amount, bob_evm); + let bob_evm_token_after_mint: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("after mint, bob evm token balance:{:?}", bob_evm_token_after_mint); + + match burn_erc20_tokens(token_addr, bob_evm, transfer_token_amount, bob_evm) { + Ok(_) => log::info!("Token burned."), + Err(e) => { + panic!("burn token execution reverted:{:?}.", e); + }, + } + + let bob_evm_token_after_burn: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("after burn, bob evm token balance:{:?}", bob_evm_token_after_burn); + + let selector_bytes: [u8; 4] = + sp_io::hashing::keccak_256(b"111transferToMagnet(address,uint256,string)")[0..4] + .try_into() + .unwrap(); + let selector = u32::from_be_bytes(selector_bytes); + + let token_addr_encoded = token_addr.to_fixed_bytes(); + let transfer_value_encoded = solidity::encode_arguments(transfer_token_amount); + let alice_ss58_address_encoded = solidity::encode_arguments(alice_ss58_bstring); + let alice_ss58_address_len: u128 = alice_ss58_address_encoded.len().try_into().unwrap(); + let alice_ss58_address_len_encoded = solidity::encode_arguments(alice_ss58_address_len); + log::info!("alice ss58 address encoded length:{:?}", alice_ss58_address_len); + + let mut call_data = selector.to_be_bytes().to_vec(); + call_data.extend_from_slice(&[0u8; 12][..]); + call_data.extend_from_slice(&token_addr_encoded); + call_data.extend_from_slice(&transfer_value_encoded); + call_data.extend_from_slice(&alice_ss58_address_len_encoded); + call_data.extend_from_slice(&alice_ss58_address_encoded); + log::info!("transferToMagnet callData:{:?}", hex::encode(&call_data.clone())); + + let is_transactional = true; + let validate = true; + let call_result = ::Runner::call( + bob_evm, + target, + call_data, + 0.into(), + 3_000_000, + Some(U256::from(1_000_000_000)), + Some(U256::default()), + None, + Vec::new(), + is_transactional, + validate, + None, + None, + ::config(), + ); + assert_ok!(&call_result); + let call_result = call_result.unwrap(); + + match call_result { + CallInfo { exit_reason: ExitReason::Succeed(_), value: _, used_gas: _, .. } => { + panic!("exit_reason must not Succeed!"); + }, + CallInfo { exit_reason: _, value: err_value, .. } => { + let v = unsafe { String::from_utf8_unchecked(err_value.clone()) }; + log::info!("exit value:{:?}", v); + assert_eq!(err_value, "Not find the selector error".as_bytes().to_owned()); + }, + }; + }) +} + +#[test] +fn ss58address_error_works() { + ExtBuilder::default().existential_deposit(100).build().execute_with(|| { + //let bob_evm= H160::from_slice(&[17u8;20][..]); + let bob_evm: H160 = H160([ + 0x05, 0xF9, 0xb8, 0xC7, 0x6E, 0x89, 0x87, 0xB8, 0x15, 0xC9, 0x3C, 0x27, 0xD1, 0x45, + 0x20, 0xb6, 0xeD, 0x57, 0x39, 0x02, + ]); + log::info!("bob evm:{:?}", bob_evm); + + let bob = ::AddressMapping::into_account_id(bob_evm); + let _ = Balances::deposit_creating(&ALICE, 10_000_000_000_000_000_000); + let _ = Balances::deposit_creating(&bob, 6_000_000_000_000_000_000); + + let (bob_evm_account, _) = EVM::account_basic(&bob_evm); + + let bob_evm_value_before: u128 = bob_evm_account.balance.as_u128(); + log::info!("bob evm value before:{:?}", bob_evm_value_before); + + let mint_amount: u128 = 1000_000_000_000_000_000; + let transfer_token_amount: u128 = 800_000_000_000_000_000; + + let target: H160 = H160::from_low_u64_be(2049); + + //let alice_ss58_address = ALICE.to_ss58check(); + //let alice_ss58_bstring = >::from(alice_ss58_address); + let alice_ss58_bstring = >::from("1234567890"); + + let token_addr = deploy_contract(bob_evm); + log::info!("token addr:{:?}", token_addr); + + let asset_id = create_and_register_asset(token_addr); + log::info!("asset id:{:?}", asset_id); + + let alice_token_amount_before = Assets::balance(asset_id, &ALICE); + log::info!("alice token amount before mint:{:?}", alice_token_amount_before); + + let bob_evm_token_before_mint: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("before mint, bob evm token balance:{:?}", bob_evm_token_before_mint); + mint_erc20_tokens(token_addr, bob_evm, mint_amount, bob_evm); + let bob_evm_token_after_mint: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("after mint, bob evm token balance:{:?}", bob_evm_token_after_mint); + + match burn_erc20_tokens(token_addr, bob_evm, transfer_token_amount, bob_evm) { + Ok(_) => log::info!("Token burned."), + Err(e) => { + panic!("burn token execution reverted:{:?}.", e); + }, + } + + let bob_evm_token_after_burn: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("after burn, bob evm token balance:{:?}", bob_evm_token_after_burn); + + let selector_bytes: [u8; 4] = + sp_io::hashing::keccak_256(b"transferToMagnet(address,uint256,string)")[0..4] + .try_into() + .unwrap(); + let selector = u32::from_be_bytes(selector_bytes); + + let token_addr_encoded = token_addr.to_fixed_bytes(); + let transfer_value_encoded = solidity::encode_arguments(transfer_token_amount); + let alice_ss58_address_encoded = solidity::encode_arguments(alice_ss58_bstring); + let alice_ss58_address_len: u128 = alice_ss58_address_encoded.len().try_into().unwrap(); + let alice_ss58_address_len_encoded = solidity::encode_arguments(alice_ss58_address_len); + log::info!("alice ss58 address encoded length:{:?}", alice_ss58_address_len); + + let mut call_data = selector.to_be_bytes().to_vec(); + call_data.extend_from_slice(&[0u8; 12][..]); + call_data.extend_from_slice(&token_addr_encoded); + call_data.extend_from_slice(&transfer_value_encoded); + call_data.extend_from_slice(&alice_ss58_address_len_encoded); + call_data.extend_from_slice(&alice_ss58_address_encoded); + log::info!("transferToMagnet callData:{:?}", hex::encode(&call_data.clone())); + + let is_transactional = true; + let validate = true; + let call_result = ::Runner::call( + bob_evm, + target, + call_data, + 0.into(), + 3_000_000, + Some(U256::from(1_000_000_000)), + Some(U256::default()), + None, + Vec::new(), + is_transactional, + validate, + None, + None, + ::config(), + ); + assert_ok!(&call_result); + let call_result = call_result.unwrap(); + + match call_result { + CallInfo { exit_reason: ExitReason::Succeed(_), value: _, used_gas: _, .. } => { + panic!("exit_reason must not Succeed!"); + }, + CallInfo { exit_reason: reason, value: _, .. } => { + assert_eq!( + reason, + ExitReason::Error(ExitError::Other(std::borrow::Cow::Borrowed( + "AccountId32 from ss58check(string) failed" + ))) + ); + }, + }; + }) +} + +#[test] +fn not_evm_admin_works() { + ExtBuilder::default().existential_deposit(100).build().execute_with(|| { + let bob_evm = H160::from_slice(&[17u8; 20][..]); + /* + let bob_evm: H160 = H160([ + 0x05, 0xF9, 0xb8, 0xC7, 0x6E, 0x89, 0x87, 0xB8, 0x15, 0xC9, 0x3C, 0x27, 0xD1, 0x45, + 0x20, 0xb6, 0xeD, 0x57, 0x39, 0x02, + ]); + */ + log::info!("bob evm:{:?}", bob_evm); + + let bob = ::AddressMapping::into_account_id(bob_evm); + let _ = Balances::deposit_creating(&ALICE, 10_000_000_000_000_000_000); + let _ = Balances::deposit_creating(&bob, 6_000_000_000_000_000_000); + + let (bob_evm_account, _) = EVM::account_basic(&bob_evm); + + let bob_evm_value_before: u128 = bob_evm_account.balance.as_u128(); + log::info!("bob evm value before:{:?}", bob_evm_value_before); + + let mint_amount: u128 = 1000_000_000_000_000_000; + let transfer_token_amount: u128 = 800_000_000_000_000_000; + + let target: H160 = H160::from_low_u64_be(2049); + + let alice_ss58_address = ALICE.to_ss58check(); + let alice_ss58_bstring = >::from(alice_ss58_address); + + let token_addr = deploy_contract(bob_evm); + log::info!("token addr:{:?}", token_addr); + + let asset_id = create_and_register_asset(token_addr); + log::info!("asset id:{:?}", asset_id); + + let alice_token_amount_before = Assets::balance(asset_id, &ALICE); + log::info!("alice token amount before mint:{:?}", alice_token_amount_before); + + let bob_evm_token_before_mint: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("before mint, bob evm token balance:{:?}", bob_evm_token_before_mint); + mint_erc20_tokens(token_addr, bob_evm, mint_amount, bob_evm); + let bob_evm_token_after_mint: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("after mint, bob evm token balance:{:?}", bob_evm_token_after_mint); + + match burn_erc20_tokens(token_addr, bob_evm, transfer_token_amount, bob_evm) { + Ok(_) => log::info!("Token burned."), + Err(e) => { + panic!("burn token execution reverted:{:?}.", e); + }, + } + + let bob_evm_token_after_burn: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("after burn, bob evm token balance:{:?}", bob_evm_token_after_burn); + + let selector_bytes: [u8; 4] = + sp_io::hashing::keccak_256(b"transferToMagnet(address,uint256,string)")[0..4] + .try_into() + .unwrap(); + let selector = u32::from_be_bytes(selector_bytes); + + let token_addr_encoded = token_addr.to_fixed_bytes(); + let transfer_value_encoded = solidity::encode_arguments(transfer_token_amount); + let alice_ss58_address_encoded = solidity::encode_arguments(alice_ss58_bstring); + let alice_ss58_address_len: u128 = alice_ss58_address_encoded.len().try_into().unwrap(); + let alice_ss58_address_len_encoded = solidity::encode_arguments(alice_ss58_address_len); + log::info!("alice ss58 address encoded length:{:?}", alice_ss58_address_len); + + let mut call_data = selector.to_be_bytes().to_vec(); + call_data.extend_from_slice(&[0u8; 12][..]); + call_data.extend_from_slice(&token_addr_encoded); + call_data.extend_from_slice(&transfer_value_encoded); + call_data.extend_from_slice(&alice_ss58_address_len_encoded); + call_data.extend_from_slice(&alice_ss58_address_encoded); + log::info!("transferToMagnet callData:{:?}", hex::encode(&call_data.clone())); + + let is_transactional = true; + let validate = true; + let call_result = ::Runner::call( + bob_evm, + target, + call_data, + 0.into(), + 3_000_000, + Some(U256::from(1_000_000_000)), + Some(U256::default()), + None, + Vec::new(), + is_transactional, + validate, + None, + None, + ::config(), + ); + assert_ok!(&call_result); + let call_result = call_result.unwrap(); + + match call_result { + CallInfo { exit_reason: ExitReason::Succeed(_), value: _, used_gas: _, .. } => { + panic!("exit_reason must not Succeed!"); + }, + CallInfo { exit_reason: reason, value: _, .. } => { + assert_eq!( + reason, + ExitReason::Error(ExitError::Other(std::borrow::Cow::Borrowed( + "Caller is not the admin" + ))) + ); + }, + }; + }) +} + +#[test] +fn token_and_assets_not_bound_works() { + ExtBuilder::default().existential_deposit(100).build().execute_with(|| { + //let bob_evm= H160::from_slice(&[17u8;20][..]); + let bob_evm: H160 = H160([ + 0x05, 0xF9, 0xb8, 0xC7, 0x6E, 0x89, 0x87, 0xB8, 0x15, 0xC9, 0x3C, 0x27, 0xD1, 0x45, + 0x20, 0xb6, 0xeD, 0x57, 0x39, 0x02, + ]); + log::info!("bob evm:{:?}", bob_evm); + + let bob = ::AddressMapping::into_account_id(bob_evm); + let _ = Balances::deposit_creating(&ALICE, 10_000_000_000_000_000_000); + let _ = Balances::deposit_creating(&bob, 6_000_000_000_000_000_000); + + let (bob_evm_account, _) = EVM::account_basic(&bob_evm); + + let bob_evm_value_before: u128 = bob_evm_account.balance.as_u128(); + log::info!("bob evm value before:{:?}", bob_evm_value_before); + + let mint_amount: u128 = 1000_000_000_000_000_000; + let transfer_token_amount: u128 = 800_000_000_000_000_000; + + let target: H160 = H160::from_low_u64_be(2049); + + let alice_ss58_address = ALICE.to_ss58check(); + let alice_ss58_bstring = >::from(alice_ss58_address); + + let token_addr = deploy_contract(bob_evm); + log::info!("token addr:{:?}", token_addr); + + let asset_id = create_without_register_asset(); + log::info!("asset id:{:?}", asset_id); + + let alice_token_amount_before = Assets::balance(asset_id, &ALICE); + log::info!("alice token amount before mint:{:?}", alice_token_amount_before); + + let bob_evm_token_before_mint: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("before mint, bob evm token balance:{:?}", bob_evm_token_before_mint); + mint_erc20_tokens(token_addr, bob_evm, mint_amount, bob_evm); + let bob_evm_token_after_mint: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("after mint, bob evm token balance:{:?}", bob_evm_token_after_mint); + + match burn_erc20_tokens(token_addr, bob_evm, transfer_token_amount, bob_evm) { + Ok(_) => log::info!("Token burned."), + Err(e) => { + panic!("burn token execution reverted:{:?}.", e); + }, + } + + let bob_evm_token_after_burn: U256 = query_balance_of(token_addr, bob_evm, bob_evm); + log::info!("after burn, bob evm token balance:{:?}", bob_evm_token_after_burn); + + let selector_bytes: [u8; 4] = + sp_io::hashing::keccak_256(b"transferToMagnet(address,uint256,string)")[0..4] + .try_into() + .unwrap(); + let selector = u32::from_be_bytes(selector_bytes); + + let token_addr_encoded = token_addr.to_fixed_bytes(); + let transfer_value_encoded = solidity::encode_arguments(transfer_token_amount); + let alice_ss58_address_encoded = solidity::encode_arguments(alice_ss58_bstring); + let alice_ss58_address_len: u128 = alice_ss58_address_encoded.len().try_into().unwrap(); + let alice_ss58_address_len_encoded = solidity::encode_arguments(alice_ss58_address_len); + log::info!("alice ss58 address encoded length:{:?}", alice_ss58_address_len); + + let mut call_data = selector.to_be_bytes().to_vec(); + call_data.extend_from_slice(&[0u8; 12][..]); + call_data.extend_from_slice(&token_addr_encoded); + call_data.extend_from_slice(&transfer_value_encoded); + call_data.extend_from_slice(&alice_ss58_address_len_encoded); + call_data.extend_from_slice(&alice_ss58_address_encoded); + log::info!("transferToMagnet callData:{:?}", hex::encode(&call_data.clone())); + + let is_transactional = true; + let validate = true; + let call_result = ::Runner::call( + bob_evm, + target, + call_data, + 0.into(), + 3_000_000, + Some(U256::from(1_000_000_000)), + Some(U256::default()), + None, + Vec::new(), + is_transactional, + validate, + None, + None, + ::config(), + ); + assert_ok!(&call_result); + let call_result = call_result.unwrap(); + + match call_result { + CallInfo { exit_reason: ExitReason::Succeed(_), value: _, used_gas: _, .. } => { + panic!("exit_reason must not Succeed!"); + }, + CallInfo { exit_reason: reason, value: _, .. } => { + assert_eq!( + reason, + ExitReason::Error(ExitError::Other(std::borrow::Cow::Borrowed( + "Failed to get asset_id from token_addr" + ))) + ); + }, + }; + }) +} diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 03cfdb4..9c8c7ed 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -26,6 +26,7 @@ mp-system = { path = "../primitives/system", default-features = false } pallet-assets-bridge = { path = "../pallets/assets-bridge", default-features = false } pallet-evm-utils = { path = "../pallets/evm-utils", default-features = false } pallet-precompile-substrate-utils = { path = "../pallets/evm/precompile/substrate-utils", default-features = false } +pallet-precompile-transfer-to-magnet = { path = "../pallets/evm/precompile/transfer-to-magnet", default-features = false } pallet-order = { path = "../pallets/order", default-features = false } magnet-primitives-order = { path = "../primitives/order", default-features = false } pallet-pot = { path = "../pallets/pot", default-features = false } @@ -189,6 +190,7 @@ std = [ "pallet-assets-bridge/std", "pallet-evm-utils/std", "pallet-precompile-substrate-utils/std", + "pallet-precompile-transfer-to-magnet/std", "magnet-primitives-order/std", "pallet-order/std", "sp-trie/std", @@ -229,6 +231,7 @@ runtime-benchmarks = [ "xcm-executor/runtime-benchmarks", "pallet-evm-utils/runtime-benchmarks", "pallet-precompile-substrate-utils/runtime-benchmarks", + "pallet-precompile-transfer-to-magnet/runtime-benchmarks", "pallet-order/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-society/runtime-benchmarks", @@ -273,6 +276,7 @@ try-runtime = [ "sp-runtime/try-runtime", "pallet-evm-utils/try-runtime", "pallet-precompile-substrate-utils/try-runtime", + "pallet-precompile-transfer-to-magnet/try-runtime", "pallet-order/try-runtime", "pallet-liquidation/try-runtime", "pallet-assets/try-runtime", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 3047a11..ebe933d 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -31,12 +31,12 @@ use sp_runtime::{ }; use scale_info::prelude::string::String; -use sp_std::collections::btree_map::BTreeMap; +use sp_std::collections::{btree_map::BTreeMap, btree_set::BTreeSet}; use sp_std::{cmp::Ordering, marker::PhantomData, prelude::*}; #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; - +q // Substrate FRAME #[cfg(feature = "with-paritydb-weights")] use frame_support::weights::constants::ParityDbWeight as RuntimeDbWeight; @@ -901,11 +901,18 @@ parameter_types! { // 0x1111111111111111111111111111111111111111 pub EvmCaller: H160 = H160::from_slice(&[17u8;20][..]); pub ClaimBond: Balance = 10 * EXISTENTIAL_DEPOSIT; + //pub EvmAdmin: H160 = H160([0x05, 0xF9, 0xb8, 0xC7, 0x6E, 0x89, 0x87, 0xB8, 0x15, 0xC9, 0x3C, 0x27, 0xD1, 0x45, 0x20, 0xb6, 0xeD, 0x57, 0x39, 0x02]); + pub EvmAdmins: BTreeSet = { + let mut set = BTreeSet::new(); + set.insert(H160([0x05, 0xF9, 0xb8, 0xC7, 0x6E, 0x89, 0x87, 0xB8, 0x15, 0xC9, 0x3C, 0x27, 0xD1, 0x45, 0x20, 0xb6, 0xeD, 0x57, 0x39, 0x02])); + set + }; } impl pallet_assets_bridge::Config for Runtime { type RuntimeEvent = RuntimeEvent; type EvmCaller = EvmCaller; type ClaimBond = ClaimBond; + type EvmAdmins = EvmAdmins; } impl pallet_evm_utils::Config for Runtime { diff --git a/runtime/src/precompiles.rs b/runtime/src/precompiles.rs index 08c79d7..c7e7560 100644 --- a/runtime/src/precompiles.rs +++ b/runtime/src/precompiles.rs @@ -9,6 +9,7 @@ use pallet_evm_precompile_modexp::Modexp; use pallet_evm_precompile_sha3fips::Sha3FIPS256; use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256}; use pallet_precompile_substrate_utils::SubstrateUtils; +use pallet_precompile_transfer_to_magnet::TransferToMagnet; pub struct FrontierPrecompiles(PhantomData); @@ -19,14 +20,28 @@ where pub fn new() -> Self { Self(Default::default()) } - pub fn used_addresses() -> [H160; 8] { - [hash(1), hash(2), hash(3), hash(4), hash(5), hash(1024), hash(1025), hash(2048)] + pub fn used_addresses() -> [H160; 9] { + [ + hash(1), + hash(2), + hash(3), + hash(4), + hash(5), + hash(1024), + hash(1025), + hash(2048), + hash(2049), + ] } } impl PrecompileSet for FrontierPrecompiles where - R: pallet_evm::Config, + R: pallet_evm::Config + + pallet_assets_bridge::Config + + pallet_assets::Config>, R::AccountId: From, + R::AssetId: From + Into, + ::Balance: From, U256: UniqueSaturatedInto>, { fn execute(&self, handle: &mut impl PrecompileHandle) -> Option { @@ -41,6 +56,7 @@ where a if a == hash(1024) => Some(Sha3FIPS256::execute(handle)), a if a == hash(1025) => Some(ECRecoverPublicKey::execute(handle)), a if a == hash(2048) => Some(SubstrateUtils::::execute(handle)), + a if a == hash(2049) => Some(TransferToMagnet::::execute(handle)), _ => None, } } From 7ebe558d373e4bc8722043749c77b34ba4bc20c2 Mon Sep 17 00:00:00 2001 From: toints Date: Thu, 25 Apr 2024 10:43:02 +0800 Subject: [PATCH 2/2] Fixed: removed useless code --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index ebe933d..ce93b1b 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -36,7 +36,7 @@ use sp_std::{cmp::Ordering, marker::PhantomData, prelude::*}; #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; -q + // Substrate FRAME #[cfg(feature = "with-paritydb-weights")] use frame_support::weights::constants::ParityDbWeight as RuntimeDbWeight;