diff --git a/Cargo.lock b/Cargo.lock index dabe3fc..9650ca5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -155,7 +155,7 @@ dependencies = [ "itoa", "serde", "serde_json", - "winnow 0.6.6", + "winnow 0.6.7", ] [[package]] @@ -304,7 +304,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0045cc89524e1451ccf33e8581355b6027ac7c6e494bb02959d4213ad0d8e91d" dependencies = [ - "winnow 0.6.6", + "winnow 0.6.7", ] [[package]] @@ -560,11 +560,20 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "ascii-canvas" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" +dependencies = [ + "term", +] + [[package]] name = "async-compression" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07dbbf24db18d609b1462965249abdf49129ccad073ec257da372adc83259c60" +checksum = "4e9eabd7a98fe442131a17c316bd9349c43695e49e730c3c8e12cfb5f4da2693" dependencies = [ "brotli", "flate2", @@ -572,8 +581,8 @@ dependencies = [ "memchr", "pin-project-lite", "tokio", - "zstd", - "zstd-safe", + "zstd 0.13.1", + "zstd-safe 7.1.0", ] [[package]] @@ -757,6 +766,12 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + [[package]] name = "beef" version = "0.5.2" @@ -1033,9 +1048,9 @@ checksum = "3190f92dfe48224adc92881c620f08ccf37ff62b91a094bb357fe53bd5e84647" [[package]] name = "brotli" -version = "4.0.0" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "125740193d7fee5cc63ab9e16c2fdc4e07c74ba755cc53b327d6ea029e9fc569" +checksum = "19483b140a7ac7174d34b5a581b406c64f84da5409d3e09cf4fff604f9270e67" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -1044,14 +1059,24 @@ dependencies = [ [[package]] name = "brotli-decompressor" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65622a320492e09b5e0ac436b14c54ff68199bac392d0e89a6832c4518eea525" +checksum = "e6221fe77a248b9117d431ad93761222e1cf8ff282d9d1d5d9f53d6299a1cf76" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", ] +[[package]] +name = "bs58" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" +dependencies = [ + "sha2", + "tinyvec", +] + [[package]] name = "bumpalo" version = "3.16.0" @@ -1085,6 +1110,27 @@ dependencies = [ "serde", ] +[[package]] +name = "bzip2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8" +dependencies = [ + "bzip2-sys", + "libc", +] + +[[package]] +name = "bzip2-sys" +version = "0.1.11+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + [[package]] name = "c-kzg" version = "0.4.2" @@ -1247,6 +1293,58 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" +[[package]] +name = "coins-bip32" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b6be4a5df2098cd811f3194f64ddb96c267606bffd9689ac7b0160097b01ad3" +dependencies = [ + "bs58", + "coins-core", + "digest 0.10.7", + "hmac", + "k256", + "serde", + "sha2", + "thiserror", +] + +[[package]] +name = "coins-bip39" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db8fba409ce3dc04f7d804074039eb68b960b0829161f8e06c95fea3f122528" +dependencies = [ + "bitvec", + "coins-bip32", + "hmac", + "once_cell", + "pbkdf2 0.12.2", + "rand 0.8.5", + "sha2", + "thiserror", +] + +[[package]] +name = "coins-core" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5286a0843c21f8367f7be734f89df9b822e0321d8bcce8d6e735aadff7d74979" +dependencies = [ + "base64 0.21.7", + "bech32", + "bs58", + "digest 0.10.7", + "generic-array", + "hex", + "ripemd", + "serde", + "serde_derive", + "sha2", + "sha3", + "thiserror", +] + [[package]] name = "colorchoice" version = "1.0.0" @@ -1290,6 +1388,12 @@ version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3618cccc083bb987a415d85c02ca6c9994ea5b44731ec28b9ecf09658655fba9" +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + [[package]] name = "convert_case" version = "0.4.0" @@ -1571,7 +1675,7 @@ dependencies = [ "hashbrown 0.14.3", "lock_api", "once_cell", - "parking_lot_core 0.9.9", + "parking_lot_core 0.9.10", ] [[package]] @@ -1879,6 +1983,7 @@ dependencies = [ "async-trait", "c-kzg", "env_logger", + "ethers", "ethers-contract", "ethers-core", "ethers-providers", @@ -1915,7 +2020,7 @@ dependencies = [ "tokio-stream", "tonic", "tonic-build", - "uuid", + "uuid 1.8.0", ] [[package]] @@ -1949,6 +2054,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" +[[package]] +name = "ena" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c533630cf40e9caa44bd91aadc88a75d75a4c3a12b4cfde353cbed41daa1e1f1" +dependencies = [ + "log", +] + [[package]] name = "encoding_rs" version = "0.8.34" @@ -2061,6 +2175,28 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "eth-keystore" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fda3bf123be441da5260717e0661c25a2fd9cb2b2c1d20bf2e05580047158ab" +dependencies = [ + "aes 0.8.4", + "ctr 0.9.2", + "digest 0.10.7", + "hex", + "hmac", + "pbkdf2 0.11.0", + "rand 0.8.5", + "scrypt", + "serde", + "serde_json", + "sha2", + "sha3", + "thiserror", + "uuid 0.8.2", +] + [[package]] name = "ethabi" version = "18.0.0" @@ -2120,6 +2256,34 @@ dependencies = [ "smallvec", ] +[[package]] +name = "ethers" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "816841ea989f0c69e459af1cf23a6b0033b19a55424a1ea3a30099becdb8dec0" +dependencies = [ + "ethers-addressbook", + "ethers-contract", + "ethers-core", + "ethers-etherscan", + "ethers-middleware", + "ethers-providers", + "ethers-signers", + "ethers-solc", +] + +[[package]] +name = "ethers-addressbook" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5495afd16b4faa556c3bba1f21b98b4983e53c1755022377051a975c3b021759" +dependencies = [ + "ethers-core", + "once_cell", + "serde", + "serde_json", +] + [[package]] name = "ethers-contract" version = "2.0.14" @@ -2149,11 +2313,13 @@ dependencies = [ "const-hex", "dunce", "ethers-core", + "ethers-etherscan", "eyre", "prettyplease 0.2.19", "proc-macro2", "quote", "regex", + "reqwest", "serde", "serde_json", "syn 2.0.60", @@ -2207,6 +2373,49 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "ethers-etherscan" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e79e5973c26d4baf0ce55520bd732314328cabe53193286671b47144145b9649" +dependencies = [ + "chrono", + "ethers-core", + "reqwest", + "semver 1.0.22", + "serde", + "serde_json", + "thiserror", + "tracing", +] + +[[package]] +name = "ethers-middleware" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48f9fdf09aec667c099909d91908d5eaf9be1bd0e2500ba4172c1d28bfaa43de" +dependencies = [ + "async-trait", + "auto_impl", + "ethers-contract", + "ethers-core", + "ethers-etherscan", + "ethers-providers", + "ethers-signers", + "futures-channel", + "futures-locks", + "futures-util", + "instant", + "reqwest", + "serde", + "serde_json", + "thiserror", + "tokio", + "tracing", + "tracing-futures", + "url", +] + [[package]] name = "ethers-providers" version = "2.0.14" @@ -2245,6 +2454,57 @@ dependencies = [ "ws_stream_wasm", ] +[[package]] +name = "ethers-signers" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "228875491c782ad851773b652dd8ecac62cda8571d3bc32a5853644dd26766c2" +dependencies = [ + "async-trait", + "coins-bip32", + "coins-bip39", + "const-hex", + "elliptic-curve", + "eth-keystore", + "ethers-core", + "rand 0.8.5", + "sha2", + "thiserror", + "tracing", +] + +[[package]] +name = "ethers-solc" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66244a771d9163282646dbeffe0e6eca4dda4146b6498644e678ac6089b11edd" +dependencies = [ + "cfg-if", + "const-hex", + "dirs", + "dunce", + "ethers-core", + "glob", + "home", + "md-5", + "num_cpus", + "once_cell", + "path-slash", + "rayon", + "regex", + "semver 1.0.22", + "serde", + "serde_json", + "solang-parser", + "svm-rs", + "thiserror", + "tiny-keccak", + "tokio", + "tracing", + "walkdir", + "yansi", +] + [[package]] name = "event-listener" version = "2.5.3" @@ -2331,9 +2591,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.28" +version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +checksum = "4556222738635b7a3417ae6130d8f52201e45a0c4d1a907f0826383adb5f85e7" dependencies = [ "crc32fast", "miniz_oxide", @@ -2354,6 +2614,16 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "funty" version = "2.0.0" @@ -2408,6 +2678,16 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +[[package]] +name = "futures-locks" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45ec6fe3675af967e67c5536c0b9d44e34e6c52f86bedc4ea49c5317b8e94d06" +dependencies = [ + "futures-channel", + "futures-task", +] + [[package]] name = "futures-macro" version = "0.3.30" @@ -3307,7 +3587,7 @@ dependencies = [ "futures-util", "hyper", "jsonrpsee-types", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "rand 0.8.5", "rustc-hash", "serde", @@ -3460,6 +3740,36 @@ dependencies = [ "sha3-asm", ] +[[package]] +name = "lalrpop" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cb077ad656299f160924eb2912aa147d7339ea7d69e1b5517326fdcec3c1ca" +dependencies = [ + "ascii-canvas", + "bit-set", + "ena", + "itertools 0.11.0", + "lalrpop-util", + "petgraph", + "regex", + "regex-syntax 0.8.3", + "string_cache", + "term", + "tiny-keccak", + "unicode-xid", + "walkdir", +] + +[[package]] +name = "lalrpop-util" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "507460a910eb7b32ee961886ff48539633b788a36b65692b95f225b844c82553" +dependencies = [ + "regex-automata 0.4.6", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -3566,9 +3876,9 @@ checksum = "f9d642685b028806386b2b6e75685faadd3eb65a85fff7df711ce18446a422da" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -3640,6 +3950,16 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest 0.10.7", +] + [[package]] name = "memchr" version = "2.7.2" @@ -3804,6 +4124,12 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + [[package]] name = "nibble_vec" version = "0.1.0" @@ -4132,12 +4458,12 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" dependencies = [ "lock_api", - "parking_lot_core 0.9.9", + "parking_lot_core 0.9.10", ] [[package]] @@ -4156,15 +4482,26 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.4.1", + "redox_syscall 0.5.1", "smallvec", - "windows-targets 0.48.5", + "windows-targets 0.52.5", +] + +[[package]] +name = "password-hash" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" +dependencies = [ + "base64ct", + "rand_core 0.6.4", + "subtle", ] [[package]] @@ -4173,6 +4510,34 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "path-slash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42" + +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest 0.10.7", + "hmac", + "password-hash", + "sha2", +] + +[[package]] +name = "pbkdf2" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" +dependencies = [ + "digest 0.10.7", + "hmac", +] + [[package]] name = "pem" version = "1.1.1" @@ -4239,7 +4604,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" dependencies = [ "phf_macros", - "phf_shared", + "phf_shared 0.11.2", ] [[package]] @@ -4248,7 +4613,7 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" dependencies = [ - "phf_shared", + "phf_shared 0.11.2", "rand 0.8.5", ] @@ -4259,12 +4624,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" dependencies = [ "phf_generator", - "phf_shared", + "phf_shared 0.11.2", "proc-macro2", "quote", "syn 2.0.60", ] +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + [[package]] name = "phf_shared" version = "0.11.2" @@ -4375,6 +4749,12 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + [[package]] name = "pretty_assertions" version = "1.4.0" @@ -4779,11 +5159,11 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", ] [[package]] @@ -4992,7 +5372,7 @@ dependencies = [ "linked_hash_set", "lru", "metrics", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "reth-db", "reth-interfaces", "reth-metrics", @@ -5089,7 +5469,7 @@ dependencies = [ "discv5", "enr", "generic-array", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "reth-net-common", "reth-net-nat", "reth-primitives", @@ -5111,7 +5491,7 @@ dependencies = [ "data-encoding", "enr", "linked_hash_set", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "reth-net-common", "reth-primitives", "schnellru", @@ -5298,7 +5678,7 @@ dependencies = [ "indexmap 2.2.6", "libc", "libffi", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "reth-mdbx-sys", "thiserror", "tracing", @@ -5379,7 +5759,7 @@ dependencies = [ "itertools 0.12.1", "linked_hash_set", "metrics", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "pin-project", "rand 0.8.5", "reth-discv4", @@ -5440,7 +5820,7 @@ dependencies = [ "sucds", "thiserror", "tracing", - "zstd", + "zstd 0.13.1", ] [[package]] @@ -5646,7 +6026,7 @@ dependencies = [ "strum", "tempfile", "thiserror", - "zstd", + "zstd 0.13.1", ] [[package]] @@ -5659,7 +6039,7 @@ dependencies = [ "dashmap", "itertools 0.12.1", "metrics", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "pin-project", "rayon", "reth-codecs", @@ -5958,7 +6338,7 @@ dependencies = [ "futures-util", "itertools 0.12.1", "metrics", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "paste", "rand 0.8.5", "reth-eth-wire", @@ -6263,9 +6643,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.11" +version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fecbfb7b1444f477b345853b1fce097a2c6fb637b2bfb87e6bc5db0f043fae4" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", "ring 0.17.8", @@ -6334,6 +6714,15 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6518fc26bced4d53678a22d6e423e9d8716377def84545fe328236e3af070e7f" +[[package]] +name = "salsa20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" +dependencies = [ + "cipher 0.4.4", +] + [[package]] name = "same-file" version = "1.0.6" @@ -6393,6 +6782,18 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "scrypt" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f9e24d2b632954ded8ab2ef9fea0a0c769ea56ea98bddbafbad22caeeadf45d" +dependencies = [ + "hmac", + "pbkdf2 0.11.0", + "salsa20", + "sha2", +] + [[package]] name = "sct" version = "0.7.1" @@ -6619,7 +7020,7 @@ dependencies = [ "futures", "lazy_static", "log", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "serial_test_derive", ] @@ -6817,6 +7218,20 @@ dependencies = [ "sha-1", ] +[[package]] +name = "solang-parser" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c425ce1c59f4b154717592f0bdf4715c3a1d55058883622d3157e1f0908a5b26" +dependencies = [ + "itertools 0.11.0", + "lalrpop", + "lalrpop-util", + "phf", + "thiserror", + "unicode-xid", +] + [[package]] name = "spin" version = "0.5.2" @@ -6857,6 +7272,19 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot 0.12.2", + "phf_shared 0.10.0", + "precomputed-hash", +] + [[package]] name = "strsim" version = "0.9.3" @@ -6926,6 +7354,26 @@ dependencies = [ "num-traits", ] +[[package]] +name = "svm-rs" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11297baafe5fa0c99d5722458eac6a5e25c01eb1b8e5cd137f54079093daa7a4" +dependencies = [ + "dirs", + "fs2", + "hex", + "once_cell", + "reqwest", + "semver 1.0.22", + "serde", + "serde_json", + "sha2", + "thiserror", + "url", + "zip", +] + [[package]] name = "syn" version = "1.0.109" @@ -7016,6 +7464,17 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "term" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +dependencies = [ + "dirs-next", + "rustversion", + "winapi", +] + [[package]] name = "termcolor" version = "1.4.1" @@ -7149,7 +7608,7 @@ dependencies = [ "libc", "mio", "num_cpus", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "pin-project-lite", "signal-hook-registry", "socket2 0.5.6", @@ -7295,7 +7754,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.6", + "winnow 0.6.7", ] [[package]] @@ -7391,7 +7850,7 @@ dependencies = [ "tower-layer", "tower-service", "tracing", - "uuid", + "uuid 1.8.0", ] [[package]] @@ -7609,7 +8068,7 @@ dependencies = [ "ipconfig", "lru-cache", "once_cell", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "rand 0.8.5", "resolv-conf", "smallvec", @@ -7775,6 +8234,16 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "getrandom 0.2.14", + "serde", +] + [[package]] name = "uuid" version = "1.8.0" @@ -8163,9 +8632,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c976aaaa0e1f90dbb21e9587cdaf1d9679a1cde8875c0d6bd83ab96a208352" +checksum = "14b9415ee827af173ebb3f15f9083df5a122eb93572ec28741fb153356ea2578" dependencies = [ "memchr", ] @@ -8317,9 +8786,9 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.8.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63381fa6624bf92130a6b87c0d07380116f80b565c42cf0d754136f0238359ef" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" dependencies = [ "zeroize_derive", ] @@ -8358,13 +8827,52 @@ dependencies = [ "syn 2.0.60", ] +[[package]] +name = "zip" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" +dependencies = [ + "aes 0.8.4", + "byteorder", + "bzip2", + "constant_time_eq", + "crc32fast", + "crossbeam-utils", + "flate2", + "hmac", + "pbkdf2 0.11.0", + "sha1", + "time", + "zstd 0.11.2+zstd.1.5.2", +] + +[[package]] +name = "zstd" +version = "0.11.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" +dependencies = [ + "zstd-safe 5.0.2+zstd.1.5.2", +] + [[package]] name = "zstd" version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d789b1514203a1120ad2429eae43a7bd32b90976a7bb8a05f7ec02fa88cc23a" dependencies = [ - "zstd-safe", + "zstd-safe 7.1.0", +] + +[[package]] +name = "zstd-safe" +version = "5.0.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" +dependencies = [ + "libc", + "zstd-sys", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index fa63e93..dbf74ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,7 @@ reth-libmdbx = { git = "https://github.com/0xEigenLabs/reth", package = "reth-li ethers-providers = { version = "2.0.14", features = ["ws"] } ethers-core = { version = "2.0.14", default-features = false } ethers-contract = { version = "2.0.14", features = ["abigen"] } +ethers = "2.0.14" # lazy_static once_cell = "1.8.0" diff --git a/src/env.rs b/src/env.rs index 0b4f20b..0078803 100644 --- a/src/env.rs +++ b/src/env.rs @@ -11,6 +11,34 @@ pub struct EigenZethEnv { pub curve_type: String, pub host: String, pub zeth_db_path: String, + pub settlement: SettlementEnv, +} + +#[derive(Clone)] +pub struct SettlementEnv { + pub eth_env: EthereumEnv, +} + +#[derive(Clone)] +pub struct EthereumEnv { + pub provider_url: String, + pub local_wallet: LocalWalletConfig, + pub l1_contracts_addr: EthContractsAddr, +} + +#[derive(Clone)] +pub struct LocalWalletConfig { + pub private_key: String, + pub chain_id: u64, +} + +// TODO: Fixme +#[allow(dead_code)] +#[derive(Clone)] +pub struct EthContractsAddr { + pub eigen_bridge: String, + pub eigen_global_exit: String, + pub eigen_zkvm: String, } /// EIGEN_ZETH_ENV is a global variable that holds the environment variables, @@ -22,4 +50,25 @@ pub static GLOBAL_ENV: Lazy = Lazy::new(|| EigenZethEnv { curve_type: std::env::var("CURVE_TYPE").unwrap_or("BN128".to_string()), host: std::env::var("HOST").unwrap_or("0.0.0.0:8182".to_string()), zeth_db_path: std::env::var("ZETH_DB_PATH").unwrap_or("/tmp/chain".to_string()), + // TODO: too many env variables, I will move this to a config file,and use clap command to receive the path to the config file + settlement: SettlementEnv { + eth_env: EthereumEnv { + provider_url: std::env::var("ETH_PROVIDER_URL") + .unwrap_or("http://localhost:8546".to_string()), + local_wallet: LocalWalletConfig { + private_key: std::env::var("PRIVATE_KEY").unwrap_or("".to_string()), + chain_id: std::env::var("CHAIN_ID") + .unwrap_or("12345".to_string()) + .parse() + .unwrap(), + }, + l1_contracts_addr: EthContractsAddr { + eigen_bridge: std::env::var("EIGEN_BRIDGE_CONTRACT_ADDR") + .unwrap_or("0x".to_string()), + eigen_global_exit: std::env::var("EIGEN_GLOBAL_EXIT_CONTRACT_ADDR") + .unwrap_or("0x".to_string()), + eigen_zkvm: std::env::var("EIGEN_ZKVM_CONTRACT_ADDR").unwrap_or("0x".to_string()), + }, + }, + }, }); diff --git a/src/operator.rs b/src/operator.rs index bf3e2a9..9cd0ad0 100644 --- a/src/operator.rs +++ b/src/operator.rs @@ -5,7 +5,7 @@ #![allow(unused_imports)] use crate::prover::ProverChannel; -use crate::settlement::{NetworkSpec, Settlement}; +use crate::settlement::{init_settlement, NetworkSpec, Settlement}; use ethers_core::types::{Bytes, H160, U256}; use ethers_providers::{Http, Provider}; use std::sync::Arc; @@ -13,32 +13,29 @@ use tokio::sync::mpsc::{self, Receiver}; use tokio::time::{interval, Duration}; use crate::db::{lfs, Database}; -use crate::settlement::ethereum::EthereumSettlement; +use crate::env::GLOBAL_ENV; +use crate::settlement::ethereum::{EthereumSettlement, EthereumSettlementConfig}; pub(crate) struct Operator { db: Box, prover: ProverChannel, - provider: Arc>, rx_proof: Receiver>, - // TODO: use trait object - settler: EthereumSettlement, + settler: Box, } impl Operator { - pub fn new(_db_path: &str, l1addr: &str, prover_addr: &str) -> Self { + pub fn new(_db_path: &str, _l1addr: &str, prover_addr: &str) -> Self { let (sx, rx_proof) = mpsc::channel(10); let prover = ProverChannel::new(prover_addr, sx); let db = lfs::open_db(lfs::DBConfig::Memory).unwrap(); - // TODO: abstract this in the settlement - let provider = Provider::::try_from(l1addr).unwrap(); - let provider = Arc::new(provider); - //let settler = init_settlement(NetworkSpec::Ethereum); - let settler = EthereumSettlement {}; + let settler = init_settlement(NetworkSpec::Ethereum(EthereumSettlementConfig { + eth_settlement_env: GLOBAL_ENV.settlement.eth_env.clone(), + })); + // let settler = EthereumSettlement {}; Operator { prover, db, - provider, settler, rx_proof, } @@ -87,13 +84,13 @@ impl Operator { self.db.put(batch_key.clone(), block_no_next.to_be_bytes().to_vec()); // TODO - let _ = self.settler.bridge_asset(H160::zero(), self.provider.clone(), 0, H160::zero(), U256::zero(), H160::zero(), true, Bytes::default()).await; + let _ = self.settler.bridge_asset(0, H160::zero(), U256::zero(), H160::zero(), true, Bytes::default()).await; } else { log::debug!("Wait for the new task coming in"); } } _ = stop_channel.recv() => { - break; + self.prover.stop().await.unwrap(); } }; } diff --git a/src/prover/provider.rs b/src/prover/provider.rs index 1af44d3..004b722 100644 --- a/src/prover/provider.rs +++ b/src/prover/provider.rs @@ -42,6 +42,9 @@ pub struct ProverChannel { /// final proof final_proof_sender: Sender>, + + /// used to stop the endpoint + stop_endpoint_tx: Sender<()>, } type BlockNumber = u64; @@ -76,14 +79,21 @@ impl ProverChannel { pub fn new(addr: &str, sender: Sender>) -> Self { let (response_sender, response_receiver) = mpsc::channel(10); let (request_sender, request_receiver) = mpsc::channel(10); + let (stop_tx, stop_rx) = mpsc::channel(1); ProverChannel { step: ProveStep::Start, current_batch: None, parent_batch: None, - endpoint: Some(ProverEndpoint::new(addr, response_sender, request_receiver)), + endpoint: Some(ProverEndpoint::new( + addr, + response_sender, + request_receiver, + stop_rx, + )), request_sender, response_receiver, final_proof_sender: sender, + stop_endpoint_tx: stop_tx, } } @@ -111,6 +121,8 @@ impl ProverChannel { pub async fn stop(&mut self) -> Result<(), Box> { // stop the endpoint + self.stop_endpoint_tx.send(()).await?; + Ok(()) } @@ -276,8 +288,8 @@ pub struct ProverEndpoint { // request_sender: Sender, /// used to receive request, and send to ProverServer request_receiver: Option>, - /// used to stop the endpoint - stop_endpoint_tx: Sender<()>, + // /// used to stop the endpoint + // stop_endpoint_tx: Sender<()>, /// listen to the stop signal, and stop the endpoint loop stop_endpoint_rx: Receiver<()>, @@ -290,12 +302,11 @@ impl ProverEndpoint { addr: &str, response_sender: Sender, request_receiver: Receiver, + stop_rx: Receiver<()>, ) -> Self { - let (stop_tx, stop_rx) = mpsc::channel(1); ProverEndpoint { addr: addr.to_string(), request_receiver: Some(request_receiver), - stop_endpoint_tx: stop_tx, stop_endpoint_rx: stop_rx, response_sender, } @@ -357,9 +368,9 @@ impl ProverEndpoint { } } - /// stop the endpoint - pub async fn stop(&mut self) -> Result<(), Box> { - self.stop_endpoint_tx.send(()).await?; - Ok(()) - } + // stop the endpoint + // pub async fn stop(&mut self) -> Result<(), Box> { + // self.stop_endpoint_tx.send(()).await?; + // Ok(()) + // } } diff --git a/src/settlement/ethereum/interfaces/eigen_bridge.rs b/src/settlement/ethereum/interfaces/eigen_bridge.rs index ed20c54..6945741 100644 --- a/src/settlement/ethereum/interfaces/eigen_bridge.rs +++ b/src/settlement/ethereum/interfaces/eigen_bridge.rs @@ -1,5 +1,7 @@ //! Rust contract client for https://github.com/0xEigenLabs/eigen-bridge-contracts/blob/feature/bridge_contract/src/EigenBridge.sol use anyhow::Result; +use ethers::middleware::SignerMiddleware; +use ethers::prelude::LocalWallet; use ethers_contract::abigen; use ethers_core::types::{Address, Bytes, U256}; use ethers_providers::{Http, Provider}; @@ -12,36 +14,147 @@ abigen!( function bridgeAsset(uint32 destinationNetwork, address destinationAddress, uint256 amount, address token, bool forceUpdateGlobalExitRoot, bytes calldata permitData) public payable virtual nonReentrant function bridgeMessage(uint32 destinationNetwork, address destinationAddress, bool forceUpdateGlobalExitRoot, bytes calldata metadata) external payable function claimAsset(bytes32[32] calldata smtProof, uint32 index, bytes32 mainnetExitRoot, bytes32 rollupExitRoot, uint32 originNetwork, address originTokenAddress, uint32 destinationNetwork, address destinationAddress, uint256 amount, bytes calldata metadata) external + function claimMessage(bytes32[32] calldata smtProof, uint32 index, bytes32 mainnetExitRoot, bytes32 rollupExitRoot, uint32 originNetwork, address originAddress, uint32 destinationNetwork, address destinationAddress, uint256 amount, bytes calldata metadata) external ]"#, ); -// TODO: Fixme -#[allow(clippy::too_many_arguments)] -pub(crate) async fn bridge_asset( - address: Address, - client: Arc>, - destination_network: u32, - destination_address: Address, - amount: U256, - token: Address, - force_update_global_exit_root: bool, - calldata: Bytes, -) -> Result<()> { - let contract = EigenBridge::new(address, client); - - if let Ok(result) = contract - .bridge_asset( - destination_network, - destination_address, - amount, - token, - force_update_global_exit_root, - calldata, - ) - .call() - .await - { - log::debug!("bridge asset {result:?}"); +pub struct EigenBridgeContractClient { + contract: EigenBridge, LocalWallet>>, +} + +impl EigenBridgeContractClient { + pub fn new(contract_address: Address, provider: Provider, wallet: LocalWallet) -> Self { + let client = SignerMiddleware::new(provider, wallet); + let contract = EigenBridge::new(contract_address, Arc::new(client)); + EigenBridgeContractClient { contract } + } + + // TODO: Fixme + #[allow(clippy::too_many_arguments)] + pub(crate) async fn bridge_asset( + &self, + destination_network: u32, + destination_address: Address, + amount: U256, + token: Address, + force_update_global_exit_root: bool, + calldata: Bytes, + ) -> Result<()> { + if let Ok(result) = self + .contract + .bridge_asset( + destination_network, + destination_address, + amount, + token, + force_update_global_exit_root, + calldata, + ) + .send() + .await + { + log::debug!("bridge asset {result:?}"); + } + Ok(()) + } + + pub(crate) async fn bridge_message( + &self, + destination_network: u32, + destination_address: Address, + force_update_global_exit_root: bool, + calldata: Bytes, + ) -> Result<()> { + if let Ok(result) = self + .contract + .bridge_message( + destination_network, + destination_address, + force_update_global_exit_root, + calldata, + ) + .send() + .await + { + log::debug!("bridge message {result:?}"); + } + Ok(()) + } + + // TODO: Fixme + #[allow(clippy::too_many_arguments)] + pub(crate) async fn claim_asset( + &self, + smt_proof: [[u8; 32]; 32], + index: u32, + mainnet_exit_root: [u8; 32], + rollup_exit_root: [u8; 32], + origin_network: u32, + origin_token_address: Address, + destination_network: u32, + destination_address: Address, + amount: U256, + metadata: Bytes, + ) -> Result<()> { + if let Ok(result) = self + .contract + .claim_asset( + smt_proof, + index, + mainnet_exit_root, + rollup_exit_root, + origin_network, + origin_token_address, + destination_network, + destination_address, + amount, + metadata, + ) + .send() + .await + { + log::debug!("claim asset {result:?}"); + } + Ok(()) + } + + // TODO: Fixme + #[allow(clippy::too_many_arguments)] + pub(crate) async fn claim_message( + &self, + smt_proof: [[u8; 32]; 32], + index: u32, + mainnet_exit_root: [u8; 32], + rollup_exit_root: [u8; 32], + origin_network: u32, + origin_address: Address, + destination_network: u32, + destination_address: Address, + amount: U256, + metadata: Bytes, + ) -> Result<()> { + if let Ok(result) = self + .contract + .claim_message( + smt_proof, + index, + mainnet_exit_root, + rollup_exit_root, + origin_network, + origin_address, + destination_network, + destination_address, + amount, + metadata, + ) + .send() + .await + { + log::debug!("claim message {result:?}"); + } + Ok(()) } - Ok(()) } + +#[cfg(test)] +mod tests {} diff --git a/src/settlement/ethereum/interfaces/eigen_global_exit_root.rs b/src/settlement/ethereum/interfaces/eigen_global_exit_root.rs index 1da74ea..bbd5fa9 100644 --- a/src/settlement/ethereum/interfaces/eigen_global_exit_root.rs +++ b/src/settlement/ethereum/interfaces/eigen_global_exit_root.rs @@ -1 +1,45 @@ //! Rust contract client for https://github.com/0xEigenLabs/eigen-bridge-contracts/blob/feature/bridge_contract/src/EigenGlobalExitRoot.sol +use anyhow::Result; +use ethers::middleware::SignerMiddleware; +use ethers::prelude::LocalWallet; +use ethers_contract::abigen; +use ethers_core::types::Address; +use ethers_providers::{Http, Provider}; +use std::sync::Arc; + +abigen!( + EigenGlobalExitRoot, + r#"[ + function updateExitRoot(bytes32 newRollupExitRoot) external + function getLastGlobalExitRoot() public view returns (bytes32) + ]"#, +); + +pub struct EigenGlobalExitRootContractClient { + contract: EigenGlobalExitRoot, LocalWallet>>, +} + +impl EigenGlobalExitRootContractClient { + pub fn new(contract_address: Address, provider: Provider, wallet: LocalWallet) -> Self { + let client = SignerMiddleware::new(provider, wallet); + let contract = EigenGlobalExitRoot::new(contract_address, Arc::new(client)); + EigenGlobalExitRootContractClient { contract } + } + + pub async fn update_exit_root(&self, new_rollup_exit_root: [u8; 32]) -> Result<()> { + if let Ok(result) = self + .contract + .update_exit_root(new_rollup_exit_root) + .send() + .await + { + log::debug!("update exit root {result:?}"); + } + Ok(()) + } + + pub async fn get_last_global_exit_root(&self) -> Result<[u8; 32]> { + let last_global_exit_root = self.contract.get_last_global_exit_root().call().await?; + Ok(last_global_exit_root) + } +} diff --git a/src/settlement/ethereum/interfaces/eigen_zkvm.rs b/src/settlement/ethereum/interfaces/eigen_zkvm.rs new file mode 100644 index 0000000..0c12577 --- /dev/null +++ b/src/settlement/ethereum/interfaces/eigen_zkvm.rs @@ -0,0 +1,12 @@ +//! Rust contract client for https://github.com/0xEigenLabs/eigen-bridge-contracts/blob/feature/bridge_contract/src/EigenZkVM.sol + +// need abi.json +// abigen!( +// EigenZkVM, +// r#"[ +// function sequenceBatches(BatchData[] calldata batches,address l2Coinbase) external onlyAdmin +// ]"#, +// ); +// +// function verifyBatches(uint64 pendingStateNum, uint64 initNumBatch, uint64 finalNewBatch, bytes32 newLocalExitRoot, bytes32 newStateRoot, Proof calldata proof, uint[1] calldata input) external +// function verifyBatchesTrustedAggregator(uint64 pendingStateNum, uint64 initNumBatch, uint64 finalNewBatch, bytes32 newLocalExitRoot, bytes32 newStateRoot, Proof calldata proof, uint[1] calldata input) external onlyAdmin diff --git a/src/settlement/ethereum/interfaces/mod.rs b/src/settlement/ethereum/interfaces/mod.rs index 8d94bf8..3a6dcc7 100644 --- a/src/settlement/ethereum/interfaces/mod.rs +++ b/src/settlement/ethereum/interfaces/mod.rs @@ -1,2 +1,3 @@ pub(crate) mod eigen_bridge; pub(crate) mod eigen_global_exit_root; +mod eigen_zkvm; diff --git a/src/settlement/ethereum/mod.rs b/src/settlement/ethereum/mod.rs index 1429d8b..8cd81a1 100644 --- a/src/settlement/ethereum/mod.rs +++ b/src/settlement/ethereum/mod.rs @@ -1,17 +1,66 @@ use crate::settlement::Settlement; pub(crate) mod interfaces; +use crate::env::EthereumEnv; +use crate::settlement::ethereum::interfaces::eigen_bridge::EigenBridgeContractClient; +use crate::settlement::ethereum::interfaces::eigen_global_exit_root::EigenGlobalExitRootContractClient; use anyhow::Result; +use async_trait::async_trait; +use ethers::signers::{LocalWallet, Signer}; +use ethers_core::k256::elliptic_curve::SecretKey; use ethers_core::types::{Address, Bytes, U256}; +use ethers_core::utils::hex; use ethers_providers::{Http, Provider}; -use std::sync::Arc; -pub struct EthereumSettlement {} +pub struct EthereumSettlement { + pub eigen_bridge_client: EigenBridgeContractClient, + pub eigen_global_exit_root_client: EigenGlobalExitRootContractClient, +} + +pub struct EthereumSettlementConfig { + pub eth_settlement_env: EthereumEnv, +} + +impl EthereumSettlement { + pub fn new(config: EthereumSettlementConfig) -> Self { + let provider = Provider::::try_from(&config.eth_settlement_env.provider_url).unwrap(); + let kye_bytes = hex::decode(&config.eth_settlement_env.local_wallet.private_key).unwrap(); + let secret_key = SecretKey::from_slice(&kye_bytes).unwrap(); + let local_wallet: LocalWallet = LocalWallet::from(secret_key) + .with_chain_id(config.eth_settlement_env.local_wallet.chain_id); + + let eigen_bridge_address: Address = config + .eth_settlement_env + .l1_contracts_addr + .eigen_bridge + .parse() + .unwrap(); + + let eigen_global_exit_root_address: Address = config + .eth_settlement_env + .l1_contracts_addr + .eigen_global_exit + .parse() + .unwrap(); + + EthereumSettlement { + eigen_bridge_client: EigenBridgeContractClient::new( + eigen_bridge_address, + provider.clone(), + local_wallet.clone(), + ), + eigen_global_exit_root_client: EigenGlobalExitRootContractClient::new( + eigen_global_exit_root_address, + provider, + local_wallet.clone(), + ), + } + } +} +#[async_trait] impl Settlement for EthereumSettlement { async fn bridge_asset( &self, - address: Address, - client: Arc>, destination_network: u32, destination_address: Address, amount: U256, @@ -19,16 +68,102 @@ impl Settlement for EthereumSettlement { force_update_global_exit_root: bool, calldata: Bytes, ) -> Result<()> { - interfaces::eigen_bridge::bridge_asset( - address, - client, - destination_network, - destination_address, - amount, - token, - force_update_global_exit_root, - calldata, - ) - .await + self.eigen_bridge_client + .bridge_asset( + destination_network, + destination_address, + amount, + token, + force_update_global_exit_root, + calldata, + ) + .await + } + + async fn bridge_message( + &self, + destination_network: u32, + destination_address: Address, + force_update_global_exit_root: bool, + calldata: Bytes, + ) -> Result<()> { + self.eigen_bridge_client + .bridge_message( + destination_network, + destination_address, + force_update_global_exit_root, + calldata, + ) + .await + } + + async fn claim_asset( + &self, + smt_proof: [[u8; 32]; 32], + index: u32, + mainnet_exit_root: [u8; 32], + rollup_exit_root: [u8; 32], + origin_network: u32, + origin_token_address: Address, + destination_network: u32, + destination_address: Address, + amount: U256, + metadata: Bytes, + ) -> Result<()> { + self.eigen_bridge_client + .claim_asset( + smt_proof, + index, + mainnet_exit_root, + rollup_exit_root, + origin_network, + origin_token_address, + destination_network, + destination_address, + amount, + metadata, + ) + .await + } + + async fn claim_message( + &self, + smt_proof: [[u8; 32]; 32], + index: u32, + mainnet_exit_root: [u8; 32], + rollup_exit_root: [u8; 32], + origin_network: u32, + origin_address: Address, + destination_network: u32, + destination_address: Address, + amount: U256, + metadata: Bytes, + ) -> Result<()> { + self.eigen_bridge_client + .claim_message( + smt_proof, + index, + mainnet_exit_root, + rollup_exit_root, + origin_network, + origin_address, + destination_network, + destination_address, + amount, + metadata, + ) + .await + } + + async fn update_global_exit_root(&self, new_root: [u8; 32]) -> Result<()> { + self.eigen_global_exit_root_client + .update_exit_root(new_root) + .await + } + + async fn get_global_exit_root(&self) -> Result<[u8; 32]> { + self.eigen_global_exit_root_client + .get_last_global_exit_root() + .await } } diff --git a/src/settlement/mod.rs b/src/settlement/mod.rs index 69d93dc..d93337a 100644 --- a/src/settlement/mod.rs +++ b/src/settlement/mod.rs @@ -4,21 +4,20 @@ //! 2. update_state: update the state of the settlement layer with the given proof and public input. // TODO: Fix me #![allow(dead_code)] - use anyhow::Result; +use async_trait::async_trait; use ethers_core::types::{Address, Bytes, U256}; -use ethers_providers::{Http, Provider}; -use std::sync::Arc; pub(crate) mod ethereum; // TODO: Fixme #[allow(clippy::too_many_arguments)] +#[async_trait] pub trait Settlement { + // eigen_bridge + async fn bridge_asset( &self, - address: Address, - client: Arc>, destination_network: u32, destination_address: Address, amount: U256, @@ -27,19 +26,59 @@ pub trait Settlement { calldata: Bytes, ) -> Result<()>; + async fn bridge_message( + &self, + destination_network: u32, + destination_address: Address, + force_update_global_exit_root: bool, + calldata: Bytes, + ) -> Result<()>; + + async fn claim_asset( + &self, + smt_proof: [[u8; 32]; 32], + index: u32, + mainnet_exit_root: [u8; 32], + rollup_exit_root: [u8; 32], + origin_network: u32, + origin_token_address: Address, + destination_network: u32, + destination_address: Address, + amount: U256, + metadata: Bytes, + ) -> Result<()>; + + async fn claim_message( + &self, + smt_proof: [[u8; 32]; 32], + index: u32, + mainnet_exit_root: [u8; 32], + rollup_exit_root: [u8; 32], + origin_network: u32, + origin_address: Address, + destination_network: u32, + destination_address: Address, + amount: U256, + metadata: Bytes, + ) -> Result<()>; + + // eigen_global_exit_root + + async fn update_global_exit_root(&self, new_root: [u8; 32]) -> Result<()>; + + async fn get_global_exit_root(&self) -> Result<[u8; 32]>; + // TODO: add more interfaces } pub enum NetworkSpec { - Ethereum, + Ethereum(ethereum::EthereumSettlementConfig), Optimism, } -//pub fn init_settlement(spec: NetworkSpec) -> Box { -// match spec { -// NetworkSpec::Ethereum => { -// Box::new(ethereum::EthereumSettlement{}) -// }, -// _ => todo!("Not supported network") -// } -//} +pub fn init_settlement(spec: NetworkSpec) -> Box { + match spec { + NetworkSpec::Ethereum(config) => Box::new(ethereum::EthereumSettlement::new(config)), + _ => todo!("Not supported network"), + } +}