From 0a9eda94a8454463ba5f1c91a72cb772d9203da6 Mon Sep 17 00:00:00 2001 From: simzzz Date: Fri, 12 Mar 2021 01:12:23 +0200 Subject: [PATCH 01/60] early draft of get_spendable() function --- Cargo.lock | 844 ++++++++++++++++---------------------- adapter/src/dummy.rs | 10 +- adapter/src/ethereum.rs | 43 +- lib/protocol-eth | 2 +- primitives/Cargo.toml | 1 + primitives/src/adapter.rs | 13 + 6 files changed, 415 insertions(+), 498 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 28b7bdb5d..7d560898c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,11 +6,11 @@ version = "0.1.0" dependencies = [ "async-trait", "base64 0.10.1", - "byteorder 1.4.2", + "byteorder 1.4.3", "chrono", "eth_checksum", "ethstore", - "futures 0.3.12", + "futures 0.3.13", "hex", "lazy_static", "primitives", @@ -20,7 +20,7 @@ dependencies = [ "serde_json", "sha2 0.8.2", "tiny-keccak 1.5.0", - "tokio 1.0.2", + "tokio 1.3.0", "tokio-compat-02", "web3", "wiremock", @@ -37,9 +37,9 @@ dependencies = [ [[package]] name = "adler" -version = "0.2.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "adview-manager" @@ -50,7 +50,7 @@ dependencies = [ "lazy_static", "num-integer", "primitives", - "rand 0.8.2", + "rand 0.8.3", "reqwest", "serde", "serde_json", @@ -89,7 +89,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfd7e7ae3f9a1fb5c03b389fc6bb9a51400d0c13053f0dca698c832bfd893a0d" dependencies = [ "block-cipher-trait", - "byteorder 1.4.2", + "byteorder 1.4.3", "opaque-debug 0.2.3", ] @@ -160,9 +160,9 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "async-channel" -version = "1.5.1" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59740d83946db6a5af71ae25ddf9562c2b176b2ca42cf99a455f09f4a220d6b9" +checksum = "2114d64672151c0c5eaa5e131ec84a74f06e1e559830dabba01ca30605d66319" dependencies = [ "concurrent-queue", "event-listener", @@ -245,7 +245,7 @@ checksum = "9e9e7a929bd34c68a82d58a4de7f86fffdaf97fb2af850162a7bb19dd7269b33" dependencies = [ "native-tls", "thiserror", - "tokio 0.2.24", + "tokio 0.2.25", "url", ] @@ -270,7 +270,7 @@ dependencies = [ "memchr", "num_cpus", "once_cell", - "pin-project-lite 0.2.4", + "pin-project-lite 0.2.6", "pin-utils", "slab", "wasm-bindgen-futures", @@ -284,9 +284,9 @@ checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" [[package]] name = "async-trait" -version = "0.1.42" +version = "0.1.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3a45e77e34375a7923b1e8febb049bb011f064714a8e17a1a616fef01da13d" +checksum = "36ea56748e10732c49404c153638a15ec3d6211ec5ff35d9bb20e13b93576adf" dependencies = [ "proc-macro2", "quote", @@ -324,9 +324,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "backtrace" -version = "0.3.55" +version = "0.3.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef5140344c85b01f9bbb4d4b7288a8aa4b3287ccef913a14bcc78a1063623598" +checksum = "9d117600f438b1707d4e4ae15d3595657288f8235a0eb593e80ecc98ab34e1bc" dependencies = [ "addr2line", "cfg-if 1.0.0", @@ -348,7 +348,7 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" dependencies = [ - "byteorder 1.4.2", + "byteorder 1.4.3", ] [[package]] @@ -379,7 +379,7 @@ dependencies = [ "futures-channel", "futures-util", "parking_lot 0.11.1", - "tokio 1.0.2", + "tokio 1.3.0", ] [[package]] @@ -390,7 +390,7 @@ checksum = "61fdf56d52b2cca401d2380407e5c35d3d25d3560224ecf74d6e4ca13e51239b" dependencies = [ "async-trait", "bb8", - "tokio 1.0.2", + "tokio 1.3.0", "tokio-postgres 0.7.0", ] @@ -465,8 +465,8 @@ checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" dependencies = [ "block-padding 0.1.5", "byte-tools 0.3.1", - "byteorder 1.4.2", - "generic-array 0.12.3", + "byteorder 1.4.3", + "generic-array 0.12.4", ] [[package]] @@ -485,7 +485,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" dependencies = [ - "generic-array 0.12.3", + "generic-array 0.12.4", ] [[package]] @@ -529,9 +529,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.4.0" +version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" +checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" [[package]] name = "byte-slice-cast" @@ -559,9 +559,9 @@ checksum = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" [[package]] name = "byteorder" -version = "1.4.2" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" @@ -583,9 +583,9 @@ checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" [[package]] name = "cc" -version = "1.0.66" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" +checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" [[package]] name = "cfg-if" @@ -609,15 +609,15 @@ dependencies = [ "num-integer", "num-traits", "serde", - "time 0.1.43", + "time", "winapi 0.3.9", ] [[package]] name = "cid" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d88f30b1e74e7063df5711496f3ee6e74a9735d62062242d70cddf77717f18e" +checksum = "ff0e3bc0b6446b3f9663c1a6aba6ef06c5aeaa1bc92bd18077be337198ab9768" dependencies = [ "multibase", "multihash", @@ -657,8 +657,8 @@ dependencies = [ "bytes 1.0.1", "futures-util", "memchr", - "pin-project-lite 0.2.4", - "tokio 1.0.2", + "pin-project-lite 0.2.6", + "tokio 1.3.0", ] [[package]] @@ -681,29 +681,12 @@ dependencies = [ "serde", ] -[[package]] -name = "const_fn" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6" - [[package]] name = "constant_time_eq" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" -[[package]] -name = "cookie" -version = "0.14.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "784ad0fbab4f3e9cef09f20e0aea6000ae08d2cb98ac4c0abc53df18803d702f" -dependencies = [ - "percent-encoding", - "time 0.2.24", - "version_check", -] - [[package]] name = "core-foundation" version = "0.9.1" @@ -749,12 +732,11 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.1" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d" +checksum = "2584f639eb95fea8c798496315b297cf81b9b58b6d30ab066a75455333cf4b12" dependencies = [ "cfg-if 1.0.0", - "const_fn", "crossbeam-utils", "lazy_static", "memoffset", @@ -773,9 +755,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.1" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" +checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49" dependencies = [ "autocfg 1.0.1", "cfg-if 1.0.0", @@ -801,7 +783,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7afa06d05a046c7a47c3a849907ec303504608c927f4e85f7bfff22b7180d971" dependencies = [ "constant_time_eq", - "generic-array 0.9.0", + "generic-array 0.9.1", ] [[package]] @@ -836,9 +818,9 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10bcb9d7dcbf7002aaffbb53eac22906b64cdcc127971dcc387d8eb7c95d5560" +checksum = "e8f45d9ad417bcef4817d614a501ab55cdd96a6fdb24f49aab89a54acfd66b19" dependencies = [ "quote", "syn", @@ -856,9 +838,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.10.2" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" +checksum = "a06d4a9551359071d1890820e3571252b91229e0712e7c36b08940e603c5a8fc" dependencies = [ "darling_core", "darling_macro", @@ -866,23 +848,23 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.10.2" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" +checksum = "b443e5fb0ddd56e0c9bfa47dc060c5306ee500cb731f2b91432dd65589a77684" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", - "strsim 0.9.3", + "strsim 0.10.0", "syn", ] [[package]] name = "darling_macro" -version = "0.10.2" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" +checksum = "c0220073ce504f12a70efc4e7cdaea9e9b1b324872e7ad96a208056d7a638b81" dependencies = [ "darling_core", "quote", @@ -891,9 +873,9 @@ dependencies = [ [[package]] name = "data-encoding" -version = "2.3.1" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "993a608597367c6377b258c25d7120740f00ed23a2252b729b1932dd7866f908" +checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" [[package]] name = "data-encoding-macro" @@ -926,7 +908,7 @@ dependencies = [ "crossbeam-queue", "num_cpus", "serde", - "tokio 1.0.2", + "tokio 1.3.0", ] [[package]] @@ -952,7 +934,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90" dependencies = [ - "generic-array 0.9.0", + "generic-array 0.9.1", ] [[package]] @@ -961,7 +943,7 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" dependencies = [ - "generic-array 0.12.3", + "generic-array 0.12.4", ] [[package]] @@ -974,32 +956,26 @@ dependencies = [ ] [[package]] -name = "dirs" -version = "2.0.2" +name = "dirs-next" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" dependencies = [ - "cfg-if 0.1.10", - "dirs-sys", + "cfg-if 1.0.0", + "dirs-sys-next", ] [[package]] -name = "dirs-sys" -version = "0.3.5" +name = "dirs-sys-next" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ "libc", "redox_users", "winapi 0.3.9", ] -[[package]] -name = "discard" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" - [[package]] name = "dtoa" version = "0.4.7" @@ -1020,9 +996,9 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "encoding_rs" -version = "0.8.26" +version = "0.8.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "801bbab217d7f79c0062f4f7205b5d4427c6d1a7bd7aafdd1475f7c59d62b283" +checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" dependencies = [ "cfg-if 1.0.0", ] @@ -1178,7 +1154,7 @@ dependencies = [ "serde_json", "smallvec 0.6.14", "tempdir", - "time 0.1.43", + "time", ] [[package]] @@ -1235,8 +1211,8 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" dependencies = [ - "byteorder 1.4.2", - "rand 0.8.2", + "byteorder 1.4.3", + "rand 0.8.3", "rustc-hex 2.1.0", "static_assertions", ] @@ -1264,9 +1240,9 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ece68d15c92e84fa4f19d3780f1294e5ca82a78a6d515f1efaabcc144688be00" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" dependencies = [ "matches", "percent-encoding", @@ -1296,15 +1272,15 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" [[package]] name = "futures" -version = "0.1.30" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7e4c2612746b0df8fed4ce0c69156021b704c9aefa360311c04e6e9e002eed" +checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" [[package]] name = "futures" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9052a1a50244d8d5aa9bf55cbc2fb6f357c86cc52e46c62ed390a7180cf150" +checksum = "7f55667319111d593ba876406af7c409c0ebb44dc4be6132a783ccf163ea14c1" dependencies = [ "futures-channel", "futures-core", @@ -1317,9 +1293,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2d31b7ec7efab6eefc7c57233bb10b847986139d88cc2f5a02a1ae6871a1846" +checksum = "8c2dd2df839b57db9ab69c2c9d8f3e8c81984781937fe2807dc6dcf3b2ad2939" dependencies = [ "futures-core", "futures-sink", @@ -1327,15 +1303,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79e5145dde8da7d1b3892dad07a9c98fc04bc39892b1ecc9692cf53e2b780a65" +checksum = "15496a72fabf0e62bdc3df11a59a3787429221dd0710ba8ef163d6f7a9112c94" [[package]] name = "futures-executor" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9e59fdc009a4b3096bf94f740a0f2424c082521f20a9b08c5c07c48d90fd9b9" +checksum = "891a4b7b96d84d5940084b2a37632dd65deeae662c114ceaa2c879629c9c0ad1" dependencies = [ "futures-core", "futures-task", @@ -1344,9 +1320,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28be053525281ad8259d47e4de5de657b25e7bac113458555bb4b70bc6870500" +checksum = "d71c2c65c57704c32f5241c1223167c2c3294fd34ac020c807ddbe6db287ba59" [[package]] name = "futures-lite" @@ -1359,15 +1335,15 @@ dependencies = [ "futures-io", "memchr", "parking", - "pin-project-lite 0.2.4", + "pin-project-lite 0.2.6", "waker-fn", ] [[package]] name = "futures-macro" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c287d25add322d9f9abdcdc5927ca398917996600182178774032e9f8258fedd" +checksum = "ea405816a5139fb39af82c2beb921d52143f556038378d6db21183a5c37fbfb7" dependencies = [ "proc-macro-hack", "proc-macro2", @@ -1377,18 +1353,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caf5c69029bda2e743fddd0582d1083951d65cc9539aebf8812f36c3491342d6" +checksum = "85754d98985841b7d4f5e8e6fbfa4a4ac847916893ec511a2917ccd8525b8bb3" [[package]] name = "futures-task" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13de07eb8ea81ae445aca7b69f5f7bf15d7bf4912d8ca37d6645c77ae8a58d86" -dependencies = [ - "once_cell", -] +checksum = "fa189ef211c15ee602667a6fcfe1c1fd9e07d42250d2156382820fba33c9df80" [[package]] name = "futures-timer" @@ -1398,11 +1371,11 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" [[package]] name = "futures-util" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "632a8cd0f2a4b3fdea1657f08bde063848c3bd00f9bbf6e256b8be78802e624b" +checksum = "1812c7ab8aedf8d6f2701a43e1243acdbcc2b36ab26e2ad421eb99ac963d96d1" dependencies = [ - "futures 0.1.30", + "futures 0.1.31", "futures-channel", "futures-core", "futures-io", @@ -1410,7 +1383,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.4", + "pin-project-lite 0.2.6", "pin-utils", "proc-macro-hack", "proc-macro-nested", @@ -1425,18 +1398,18 @@ checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" [[package]] name = "generic-array" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d" +checksum = "6d00328cedcac5e81c683e5620ca6a30756fc23027ebf9bff405c0e8da1fbb7e" dependencies = [ "typenum", ] [[package]] name = "generic-array" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" dependencies = [ "typenum", ] @@ -1464,13 +1437,13 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4060f4657be78b8e766215b02b18a2e862d83745545de804638e2b545e81aee6" +checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi 0.10.1+wasi-snapshot-preview1", + "wasi 0.10.0+wasi-snapshot-preview1", ] [[package]] @@ -1506,7 +1479,7 @@ dependencies = [ "http", "indexmap", "slab", - "tokio 0.2.24", + "tokio 0.2.25", "tokio-util 0.3.1", "tracing", "tracing-futures", @@ -1514,9 +1487,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b67e66362108efccd8ac053abafc8b7a8d86a37e6e48fc4f6f7485eb5e9e6a5" +checksum = "d832b01df74254fe364568d6ddc294443f61cbec82816b60904303af87efae78" dependencies = [ "bytes 1.0.1", "fnv", @@ -1526,10 +1499,9 @@ dependencies = [ "http", "indexmap", "slab", - "tokio 1.0.2", - "tokio-util 0.6.1", + "tokio 1.3.0", + "tokio-util 0.6.4", "tracing", - "tracing-futures", ] [[package]] @@ -1549,18 +1521,18 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" dependencies = [ "libc", ] [[package]] name = "hex" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hmac" @@ -1625,18 +1597,17 @@ dependencies = [ [[package]] name = "http-types" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ab8d0085fb82859c9adf050bd53992297ecdd03a665a230dfa50c8c964bf3d" +checksum = "32613ebb139d1d430ef5783676f84abfa06fc5f2b4b5a25220cdeeff7e16ef5c" dependencies = [ "anyhow", "async-channel", "base64 0.13.0", - "cookie", "futures-lite", "http", "infer", - "pin-project-lite 0.1.11", + "pin-project-lite 0.2.6", "rand 0.7.3", "serde", "serde_json", @@ -1647,9 +1618,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.3.4" +version = "1.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" +checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691" [[package]] name = "httpdate" @@ -1659,9 +1630,9 @@ checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" [[package]] name = "hyper" -version = "0.13.9" +version = "0.13.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ad767baac13b44d4529fcf58ba2cd0995e36e7b435bc5b039de6f47e880dbf" +checksum = "8a6f157065790a3ed2f88679250419b5cdd96e714a0d65f7797fd337186e96bb" dependencies = [ "bytes 0.5.6", "futures-channel", @@ -1673,9 +1644,9 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project 1.0.4", + "pin-project", "socket2", - "tokio 0.2.24", + "tokio 0.2.25", "tower-service", "tracing", "want", @@ -1683,23 +1654,23 @@ dependencies = [ [[package]] name = "hyper" -version = "0.14.2" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12219dc884514cb4a6a03737f4413c0e01c23a1b059b0156004b23f1e19dccbe" +checksum = "e8e946c2b1349055e0b72ae281b238baf1a3ea7307c7e9f9d64673bdd9c26ac7" dependencies = [ "bytes 1.0.1", "futures-channel", "futures-core", "futures-util", - "h2 0.3.0", + "h2 0.3.1", "http", "http-body 0.4.0", "httparse", "httpdate", "itoa", - "pin-project 1.0.4", + "pin-project", "socket2", - "tokio 1.0.2", + "tokio 1.3.0", "tower-service", "tracing", "want", @@ -1712,12 +1683,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f93ec5be69758dfc06b9b29efa9d6e9306e387c85eb362c603912eead2ad98c7" dependencies = [ "bytes 0.5.6", - "futures 0.3.12", + "futures 0.3.13", "http", - "hyper 0.13.9", + "hyper 0.13.10", "hyper-tls 0.4.3", "native-tls", - "tokio 0.2.24", + "tokio 0.2.25", "tokio-tls", "tower-service", "typed-headers", @@ -1730,9 +1701,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed" dependencies = [ "bytes 0.5.6", - "hyper 0.13.9", + "hyper 0.13.10", "native-tls", - "tokio 0.2.24", + "tokio 0.2.25", "tokio-tls", ] @@ -1743,9 +1714,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes 1.0.1", - "hyper 0.14.2", + "hyper 0.14.4", "native-tls", - "tokio 1.0.2", + "tokio 1.3.0", "tokio-native-tls", ] @@ -1757,9 +1728,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" +checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21" dependencies = [ "matches", "unicode-bidi", @@ -1795,9 +1766,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.1" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ "autocfg 1.0.1", "hashbrown", @@ -1850,9 +1821,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "js-sys" -version = "0.3.46" +version = "0.3.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3d7383929f7c9c7c2d0fa596f325832df98c3704f2c60553080f7127a58175" +checksum = "dc9f84f9b115ce7843d60706df1422a916680bfdfcbdb0447c5614ff9d7e4d78" dependencies = [ "wasm-bindgen", ] @@ -1863,7 +1834,7 @@ version = "16.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a47c4c3ac843f9a4238943f97620619033dadef4b378cd1e8addd170de396b3" dependencies = [ - "futures 0.3.12", + "futures 0.3.13", "log", "serde", "serde_derive", @@ -1903,22 +1874,22 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lexical-core" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db65c6da02e61f55dae90a0ae427b2a5f6b3e8db09f58d10efab23af92592616" +checksum = "21f866863575d0e1d654fbeeabdc927292fdf862873dc3c96c6f753357e13374" dependencies = [ "arrayvec 0.5.2", "bitflags", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "ryu", "static_assertions", ] [[package]] name = "libc" -version = "0.2.82" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929" +checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a" [[package]] name = "lock_api" @@ -1941,11 +1912,12 @@ dependencies = [ [[package]] name = "log" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcf3805d4480bb5b86070dcfeb9e2cb2ebc148adb753c5cca5f884d1d65a42b2" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", + "value-bag", ] [[package]] @@ -2038,9 +2010,9 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" [[package]] name = "miniz_oxide" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" dependencies = [ "adler", "autocfg 1.0.1", @@ -2067,9 +2039,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.7" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e50ae3f04d169fcc9bde0b547d1c205219b7157e07ded9c5aff03e0637cb3ed7" +checksum = "a5dede4e2065b3842b8b0af444119f3aa331cc7cc2dd20388bfb0f5d5a38823a" dependencies = [ "libc", "log", @@ -2146,7 +2118,7 @@ dependencies = [ "digest 0.9.0", "generic-array 0.14.4", "multihash-derive", - "sha2 0.9.2", + "sha2 0.9.3", "sha3", "unsigned-varint", ] @@ -2185,12 +2157,12 @@ dependencies = [ [[package]] name = "nb-connect" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8123a81538e457d44b933a02faf885d3fe8408806b23fa700e8f01c6c3a98998" +checksum = "670361df1bc2399ee1ff50406a0d422587dd3bb0da596e1978fe8e05dabddf4f" dependencies = [ "libc", - "winapi 0.3.9", + "socket2", ] [[package]] @@ -2246,9 +2218,9 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e9a41747ae4633fce5adffb4d2e81ffc5e89593cb19917f8fb2cc5ff76507bf" +checksum = "7d0a3d5e207573f948a9e5376662aa743a2ea13f7c50a554d7af443a73fbfeba" dependencies = [ "autocfg 1.0.1", "num-integer", @@ -2330,15 +2302,15 @@ dependencies = [ [[package]] name = "object" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" +checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" [[package]] name = "once_cell" -version = "1.5.2" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" +checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" [[package]] name = "opaque-debug" @@ -2423,9 +2395,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "1.3.6" +version = "1.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79602888a81ace83e3d1d4b2873286c1f5f906c84db667594e8db8da3506c383" +checksum = "a4b26b16c7687c3075982af47719e481815df30bc544f7a6690763a25ca16e9d" dependencies = [ "arrayvec 0.5.2", "bitvec", @@ -2467,7 +2439,7 @@ checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" dependencies = [ "instant", "lock_api 0.4.2", - "parking_lot_core 0.8.2", + "parking_lot_core 0.8.3", ] [[package]] @@ -2485,14 +2457,14 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ccb628cad4f84851442432c60ad8e1f607e29752d0bf072cbd0baf28aa34272" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" dependencies = [ "cfg-if 1.0.0", "instant", "libc", - "redox_syscall 0.1.57", + "redox_syscall", "smallvec 1.6.1", "winapi 0.3.9", ] @@ -2528,9 +2500,9 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c09cddfbfc98de7f76931acf44460972edb4023eb14d0c6d4018800e552d8e0" dependencies = [ - "byteorder 1.4.2", + "byteorder 1.4.3", "crypto-mac 0.6.2", - "generic-array 0.9.0", + "generic-array 0.9.1", ] [[package]] @@ -2559,38 +2531,18 @@ dependencies = [ [[package]] name = "pin-project" -version = "0.4.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" -dependencies = [ - "pin-project-internal 0.4.27", -] - -[[package]] -name = "pin-project" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b70b68509f17aa2857863b6fa00bf21fc93674c7a8893de2f469f6aa7ca2f2" -dependencies = [ - "pin-project-internal 1.0.4", -] - -[[package]] -name = "pin-project-internal" -version = "0.4.27" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" +checksum = "96fa8ebb90271c4477f144354485b8068bd8f6b78b428b01ba892ca26caf0b63" dependencies = [ - "proc-macro2", - "quote", - "syn", + "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caa25a6393f22ce819b0f50e0be89287292fda8d425be38ee0ca14c4931d9e71" +checksum = "758669ae3558c6f74bd2a18b41f7ac0b5a195aea6639d6a9b5e5d1ad5ba24c0b" dependencies = [ "proc-macro2", "quote", @@ -2599,15 +2551,15 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b" +checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" [[package]] name = "pin-project-lite" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" [[package]] name = "pin-utils" @@ -2654,9 +2606,9 @@ checksum = "14d864cf6c2eabf1323afe4145ff273aad1898e4f2a3bcb30347715df8624a07" dependencies = [ "bytes 0.5.6", "fallible-iterator", - "futures 0.3.12", + "futures 0.3.13", "log", - "tokio 0.2.24", + "tokio 0.2.25", "tokio-postgres 0.5.5", ] @@ -2667,14 +2619,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4888a0e36637ab38d76cace88c1476937d617ad015f07f6b669cec11beacc019" dependencies = [ "base64 0.13.0", - "byteorder 1.4.2", + "byteorder 1.4.3", "bytes 0.5.6", "fallible-iterator", "hmac 0.9.0", "md5", "memchr", "rand 0.7.3", - "sha2 0.9.2", + "sha2 0.9.3", "stringprep", ] @@ -2685,14 +2637,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70e34ad3dc5c56d036b9418185ee97e14b6766d55c8ccf9dc18302ad4e6371d9" dependencies = [ "base64 0.13.0", - "byteorder 1.4.2", + "byteorder 1.4.3", "bytes 1.0.1", "fallible-iterator", "hmac 0.10.1", "md5", "memchr", - "rand 0.8.2", - "sha2 0.9.2", + "rand 0.8.3", + "sha2 0.9.3", "stringprep", ] @@ -2761,7 +2713,7 @@ dependencies = [ "chrono", "cid", "fake", - "futures 0.3.12", + "futures 0.3.13", "hex", "lazy_static", "merkletree", @@ -2772,7 +2724,7 @@ dependencies = [ "parse-display", "postgres-types 0.2.0", "pretty_assertions", - "rand 0.8.2", + "rand 0.8.3", "rust-crypto", "serde", "serde-hex", @@ -2783,11 +2735,12 @@ dependencies = [ "slog-async", "slog-term", "thiserror", - "time 0.1.43", + "time", "tiny-keccak 1.5.0", "tokio-postgres 0.7.0", "toml", "url", + "web3", ] [[package]] @@ -2852,9 +2805,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.8" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ "proc-macro2", ] @@ -2922,13 +2875,13 @@ dependencies = [ [[package]] name = "rand" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18519b42a40024d661e1714153e9ad0c3de27cd495760ceb09710920f1098b1e" +checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" dependencies = [ "libc", "rand_chacha 0.3.0", - "rand_core 0.6.1", + "rand_core 0.6.2", "rand_hc 0.3.0", ] @@ -2959,7 +2912,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" dependencies = [ "ppv-lite86", - "rand_core 0.6.1", + "rand_core 0.6.2", ] [[package]] @@ -2988,11 +2941,11 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c026d7df8b298d90ccbbc5190bd04d85e159eaf5576caeacf8741da93ccbd2e5" +checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" dependencies = [ - "getrandom 0.2.1", + "getrandom 0.2.2", ] [[package]] @@ -3019,7 +2972,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" dependencies = [ - "rand_core 0.6.1", + "rand_core 0.6.2", ] [[package]] @@ -3122,37 +3075,30 @@ dependencies = [ "futures-util", "itoa", "percent-encoding", - "pin-project-lite 0.2.4", + "pin-project-lite 0.2.6", "sha1", - "tokio 1.0.2", - "tokio-util 0.6.1", + "tokio 1.3.0", + "tokio-util 0.6.4", "url", ] [[package]] name = "redox_syscall" -version = "0.1.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" - -[[package]] -name = "redox_syscall" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ec8ca9416c5ea37062b502703cd7fcb207736bc294f6e0cf367ac6fc234570" +checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" dependencies = [ "bitflags", ] [[package]] name = "redox_users" -version = "0.3.5" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" +checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" dependencies = [ - "getrandom 0.1.16", - "redox_syscall 0.1.57", - "rust-argon2", + "getrandom 0.2.2", + "redox_syscall", ] [[package]] @@ -3184,9 +3130,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd281b1030aa675fb90aa994d07187645bb3c8fc756ca766e7c3070b439de9de" +checksum = "bf12057f289428dbf5c591c74bf10392e4a8003f993405a902f20117019022d4" dependencies = [ "base64 0.13.0", "bytes 1.0.1", @@ -3195,7 +3141,7 @@ dependencies = [ "futures-util", "http", "http-body 0.4.0", - "hyper 0.14.2", + "hyper 0.14.4", "hyper-tls 0.5.0", "ipnet", "js-sys", @@ -3204,11 +3150,11 @@ dependencies = [ "mime", "native-tls", "percent-encoding", - "pin-project-lite 0.2.4", + "pin-project-lite 0.2.6", "serde", "serde_json", "serde_urlencoded", - "tokio 1.0.2", + "tokio 1.3.0", "tokio-native-tls", "url", "wasm-bindgen", @@ -3252,18 +3198,6 @@ dependencies = [ "rustc-hex 2.1.0", ] -[[package]] -name = "rust-argon2" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" -dependencies = [ - "base64 0.13.0", - "blake2b_simd", - "constant_time_eq", - "crossbeam-utils", -] - [[package]] name = "rust-crypto" version = "0.2.36" @@ -3274,7 +3208,7 @@ dependencies = [ "libc", "rand 0.3.23", "rustc-serialize", - "time 0.1.43", + "time", ] [[package]] @@ -3310,6 +3244,12 @@ dependencies = [ "semver", ] +[[package]] +name = "rustversion" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb5d2a036dc6d2d8fd16fde3498b04306e29bd193bf306a57427019b823d5acd" + [[package]] name = "ryu" version = "1.0.5" @@ -3354,7 +3294,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8570c5e2fa69cb29d492fd4e9974b6b5facb5a888e1c6da630d4a3cd7ebfef4a" dependencies = [ "byte-tools 0.3.1", - "byteorder 1.4.2", + "byteorder 1.4.3", "hmac 0.6.3", "pbkdf2", "sha2 0.7.1", @@ -3380,9 +3320,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.0.0" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1759c2e3c8580017a484a7ac56d3abc5a6c1feadf88db2f3633f12ae4268c69" +checksum = "d493c5f39e02dfb062cd8f33301f90f9b13b650e8c1b1d0fd75c19dd64bff69d" dependencies = [ "bitflags", "core-foundation", @@ -3393,9 +3333,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f99b9d5e26d2a71633cc4f2ebae7cc9f874044e0c351a27e17892d76dce5678b" +checksum = "dee48cdde5ed250b0d3252818f646e174ab414036edb884dde62d80a3ac6082d" dependencies = [ "core-foundation-sys", "libc", @@ -3427,9 +3367,9 @@ dependencies = [ "bb8-postgres", "chrono", "clap", - "futures 0.3.12", + "futures 0.3.13", "hex", - "hyper 0.14.2", + "hyper 0.14.4", "lazy_static", "migrant_lib", "primitives", @@ -3440,14 +3380,14 @@ dependencies = [ "serde_urlencoded", "slog", "thiserror", - "tokio 1.0.2", + "tokio 1.3.0", ] [[package]] name = "serde" -version = "1.0.119" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bdd36f49e35b61d49efd8aa7fc068fd295961fd2286d0b2ee9a4c7a14e99cc3" +checksum = "bd761ff957cb2a45fbb9ab3da6512de9de55872866160b23c25f1a841e99d29f" dependencies = [ "serde_derive", ] @@ -3465,9 +3405,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.119" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552954ce79a059ddd5fd68c271592374bd15cab2274970380c000118aeffe1cd" +checksum = "1800f7693e94e186f5e25a28291ae1570da908aff7d97a095dec1e56ff99069b" dependencies = [ "proc-macro2", "quote", @@ -3476,9 +3416,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.61" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a" +checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" dependencies = [ "itoa", "ryu", @@ -3520,9 +3460,9 @@ dependencies = [ [[package]] name = "serde_with" -version = "1.6.0" +version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f6201e064705553ece353a736a64be975680bd244908cf63e8fa71e478a51a" +checksum = "b44be9227e214a0420707c9ca74c2d4991d9955bae9415a8f93f05cebf561be5" dependencies = [ "serde", "serde_with_macros", @@ -3530,9 +3470,9 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "1.3.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1197ff7de45494f290c1e3e1a6f80e108974681984c87a3e480991ef3d0f1950" +checksum = "e48b35457e9d855d3dc05ef32a73e0df1e2c0fd72c38796a4ee909160c8eeec2" dependencies = [ "darling", "proc-macro2", @@ -3542,9 +3482,9 @@ dependencies = [ [[package]] name = "sha-1" -version = "0.9.2" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce3cdf1b5e620a498ee6f2a171885ac7e22f0e12089ec4b3d22b84921792507c" +checksum = "dfebf75d25bd900fd1e7d11501efab59bc846dbc76196839663e6637bba9f25f" dependencies = [ "block-buffer 0.9.0", "cfg-if 1.0.0", @@ -3585,9 +3525,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e7aab86fe2149bad8c507606bdb3f4ef5e7b2380eb92350f56122cca72a42a8" +checksum = "fa827a14b29ab7f44778d14a88d3cb76e949c45083f7dbfa507d0cb699dc12de" dependencies = [ "block-buffer 0.9.0", "cfg-if 1.0.0", @@ -3649,9 +3589,9 @@ dependencies = [ [[package]] name = "slog-term" -version = "2.6.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab1d807cf71129b05ce36914e1dbb6fbfbdecaf686301cb457f4fa967f9f5b6" +checksum = "95c1e7e5aab61ced6006149ea772770b84a0d16ce0f7885def313e4829946d76" dependencies = [ "atty", "chrono", @@ -3694,7 +3634,7 @@ checksum = "b5c71ed3d54db0a699f4948e1bb3e45b450fa31fe602621dee6680361d569c88" dependencies = [ "base64 0.12.3", "bytes 0.5.6", - "futures 0.3.12", + "futures 0.3.13", "httparse", "log", "rand 0.7.3", @@ -3713,77 +3653,19 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" -[[package]] -name = "standback" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c66a8cff4fa24853fdf6b51f75c6d7f8206d7c75cab4e467bcd7f25c2b1febe0" -dependencies = [ - "version_check", -] - [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "stdweb" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" -dependencies = [ - "discard", - "rustc_version", - "stdweb-derive", - "stdweb-internal-macros", - "stdweb-internal-runtime", - "wasm-bindgen", -] - -[[package]] -name = "stdweb-derive" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" -dependencies = [ - "proc-macro2", - "quote", - "serde", - "serde_derive", - "syn", -] - -[[package]] -name = "stdweb-internal-macros" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" -dependencies = [ - "base-x", - "proc-macro2", - "quote", - "serde", - "serde_derive", - "serde_json", - "sha1", - "syn", -] - -[[package]] -name = "stdweb-internal-runtime" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" - [[package]] name = "stream-cipher" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8131256a5896cabcf5eb04f4d6dacbe1aefda854b0d9896e09cb58829ec5638c" dependencies = [ - "generic-array 0.12.3", + "generic-array 0.12.4", ] [[package]] @@ -3804,9 +3686,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "strsim" -version = "0.9.3" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "subtle" @@ -3816,9 +3698,9 @@ checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" -version = "1.0.58" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc60a3d73ea6594cd712d830cc1f0390fd71542d8c8cd24e70cc54cdfd5e05d5" +checksum = "8fd9bc7ccc2688b3344c2f48b9b546648b25ce0b20fc717ee7fa7981a8ca9717" dependencies = [ "proc-macro2", "quote", @@ -3861,19 +3743,20 @@ checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ "cfg-if 1.0.0", "libc", - "rand 0.8.2", - "redox_syscall 0.2.4", + "rand 0.8.3", + "redox_syscall", "remove_dir_all", "winapi 0.3.9", ] [[package]] name = "term" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0863a3345e70f61d613eab32ee046ccd1bcc5f9105fe402c61fcd0c13eeb8b5" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" dependencies = [ - "dirs", + "dirs-next", + "rustversion", "winapi 0.3.9", ] @@ -3888,18 +3771,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.23" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76cc616c6abf8c8928e2fdcc0dbfab37175edd8fb49a4641066ad1364fdab146" +checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.23" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9be73a2caec27583d0046ef3796c3794f868a5bc813db689eed00c7631275cd1" +checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0" dependencies = [ "proc-macro2", "quote", @@ -3908,61 +3791,24 @@ dependencies = [ [[package]] name = "thread_local" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb9bc092d0d51e76b2b19d9d85534ffc9ec2db959a2523cdae0697e2972cd447" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "time" -version = "0.1.43" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" dependencies = [ - "libc", - "winapi 0.3.9", + "once_cell", ] [[package]] name = "time" -version = "0.2.24" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "273d3ed44dca264b0d6b3665e8d48fb515042d42466fad93d2a45b90ec4058f7" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ - "const_fn", "libc", - "standback", - "stdweb", - "time-macros", - "version_check", + "wasi 0.10.0+wasi-snapshot-preview1", "winapi 0.3.9", ] -[[package]] -name = "time-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" -dependencies = [ - "proc-macro-hack", - "time-macros-impl", -] - -[[package]] -name = "time-macros-impl" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5c3be1edfad6027c69f5491cf4cb310d1a71ecd6af742788c6ff8bced86b8fa" -dependencies = [ - "proc-macro-hack", - "proc-macro2", - "quote", - "standback", - "syn", -] - [[package]] name = "tiny-keccak" version = "1.5.0" @@ -3983,9 +3829,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f" +checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" dependencies = [ "tinyvec_macros", ] @@ -3998,9 +3844,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "0.2.24" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099837d3464c16a808060bb3f02263b412f6fafcb5d01c533d309985fbeebe48" +checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" dependencies = [ "bytes 0.5.6", "fnv", @@ -4013,7 +3859,7 @@ dependencies = [ "mio-named-pipes", "mio-uds", "num_cpus", - "pin-project-lite 0.1.11", + "pin-project-lite 0.1.12", "signal-hook-registry", "slab", "tokio-macros 0.2.6", @@ -4022,19 +3868,19 @@ dependencies = [ [[package]] name = "tokio" -version = "1.0.2" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca04cec6ff2474c638057b65798f60ac183e5e79d3448bb7163d36a39cff6ec" +checksum = "8d56477f6ed99e10225f38f9f75f872f29b8b8bd8c0b946f63345bb144e9eeda" dependencies = [ "autocfg 1.0.1", "bytes 1.0.1", "libc", "memchr", - "mio 0.7.7", + "mio 0.7.9", "num_cpus", "parking_lot 0.11.1", - "pin-project-lite 0.2.4", - "tokio-macros 1.0.0", + "pin-project-lite 0.2.6", + "tokio-macros 1.1.0", ] [[package]] @@ -4045,9 +3891,9 @@ checksum = "e7d4237822b7be8fff0a7a27927462fad435dcb6650f95cea9e946bf6bdc7e07" dependencies = [ "bytes 0.5.6", "once_cell", - "pin-project-lite 0.2.4", - "tokio 0.2.24", - "tokio 1.0.2", + "pin-project-lite 0.2.6", + "tokio 0.2.25", + "tokio 1.3.0", "tokio-stream", ] @@ -4064,9 +3910,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42517d2975ca3114b22a16192634e8241dc5cc1f130be194645970cc1c371494" +checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57" dependencies = [ "proc-macro2", "quote", @@ -4080,7 +3926,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" dependencies = [ "native-tls", - "tokio 1.0.2", + "tokio 1.3.0", ] [[package]] @@ -4090,18 +3936,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55a2482c9fe4dd481723cf5c0616f34afc710e55dcda0944e12e7b3316117892" dependencies = [ "async-trait", - "byteorder 1.4.2", + "byteorder 1.4.3", "bytes 0.5.6", "fallible-iterator", - "futures 0.3.12", + "futures 0.3.13", "log", "parking_lot 0.11.1", "percent-encoding", "phf", - "pin-project-lite 0.1.11", + "pin-project-lite 0.1.12", "postgres-protocol 0.5.3", "postgres-types 0.1.3", - "tokio 0.2.24", + "tokio 0.2.25", "tokio-util 0.3.1", ] @@ -4112,31 +3958,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cc9f82c2bfb06a33dd0dfb44b07ca98fe72df19e681d80c78d05a1bac2138e2" dependencies = [ "async-trait", - "byteorder 1.4.2", + "byteorder 1.4.3", "bytes 1.0.1", "fallible-iterator", - "futures 0.3.12", + "futures 0.3.13", "log", "parking_lot 0.11.1", "percent-encoding", "phf", - "pin-project-lite 0.2.4", + "pin-project-lite 0.2.6", "postgres-protocol 0.6.0", "postgres-types 0.2.0", "socket2", - "tokio 1.0.2", - "tokio-util 0.6.1", + "tokio 1.3.0", + "tokio-util 0.6.4", ] [[package]] name = "tokio-stream" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76066865172052eb8796c686f0b441a93df8b08d40a950b062ffb9a426f00edd" +checksum = "c535f53c0cfa1acace62995a8994fc9cc1f12d202420da96ff306ee24d576469" dependencies = [ "futures-core", - "pin-project-lite 0.2.4", - "tokio 1.0.2", + "pin-project-lite 0.2.6", + "tokio 1.3.0", ] [[package]] @@ -4146,7 +3992,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343" dependencies = [ "native-tls", - "tokio 0.2.24", + "tokio 0.2.25", ] [[package]] @@ -4159,24 +4005,23 @@ dependencies = [ "futures-core", "futures-sink", "log", - "pin-project-lite 0.1.11", - "tokio 0.2.24", + "pin-project-lite 0.1.12", + "tokio 0.2.25", ] [[package]] name = "tokio-util" -version = "0.6.1" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12ae4751faa60b9f96dd8344d74592e5a17c0c9a220413dbc6942d14139bbfcc" +checksum = "ec31e5cc6b46e653cf57762f36f71d5e6386391d88a72fd6db4508f8f676fb29" dependencies = [ "bytes 1.0.1", "futures-core", "futures-io", "futures-sink", "log", - "pin-project-lite 0.2.4", - "tokio 1.0.2", - "tokio-stream", + "pin-project-lite 0.2.6", + "tokio 1.3.0", ] [[package]] @@ -4190,19 +4035,19 @@ dependencies = [ [[package]] name = "tower-service" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.22" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3" +checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" dependencies = [ "cfg-if 1.0.0", "log", - "pin-project-lite 0.2.4", + "pin-project-lite 0.2.6", "tracing-core", ] @@ -4217,11 +4062,11 @@ dependencies = [ [[package]] name = "tracing-futures" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab7bb6f14721aa00656086e9335d363c5c8747bae02ebe32ea2c7dece5689b4c" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" dependencies = [ - "pin-project 0.4.27", + "pin-project", "tracing", ] @@ -4256,7 +4101,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "754ba11732b9161b94c41798e5197e5e75388d012f760c42adb5000353e98646" dependencies = [ - "byteorder 1.4.2", + "byteorder 1.4.3", "crunchy 0.1.6", "heapsize", "rustc-hex 2.1.0", @@ -4268,7 +4113,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e11fe9a9348741cf134085ad57c249508345fe16411b3d7fb4ff2da2f1d6382e" dependencies = [ - "byteorder 1.4.2", + "byteorder 1.4.3", "crunchy 0.2.2", "hex", "static_assertions", @@ -4285,9 +4130,9 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a13e63ab62dbe32aeee58d1c5408d35c36c392bba5d9d3142287219721afe606" +checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" dependencies = [ "tinyvec", ] @@ -4318,9 +4163,9 @@ checksum = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" [[package]] name = "url" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5909f2b0817350449ed73e8bcd81c8c3c8d9a7a5d8acba4b27db277f1868976e" +checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" dependencies = [ "form_urlencoded", "idna", @@ -4334,10 +4179,10 @@ name = "validator_worker" version = "0.2.0" dependencies = [ "adapter", - "byteorder 1.4.2", + "byteorder 1.4.3", "chrono", "clap", - "futures 0.3.12", + "futures 0.3.13", "hex", "lazy_static", "num", @@ -4347,10 +4192,19 @@ dependencies = [ "serde", "serde_json", "slog", - "tokio 1.0.2", + "tokio 1.3.0", "toml", ] +[[package]] +name = "value-bag" +version = "1.0.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b676010e055c99033117c2343b33a40a30b91fecd6c49055ac9cd2d6c305ab1" +dependencies = [ + "ctor", +] + [[package]] name = "vcpkg" version = "0.2.11" @@ -4410,15 +4264,15 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" -version = "0.10.1+wasi-snapshot-preview1" +version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93c6c3420963c5c64bca373b25e77acb562081b9bb4dd5bb864187742186cea9" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "wasm-bindgen" -version = "0.2.69" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e" +checksum = "7ee1280240b7c461d6a0071313e08f34a60b0365f14260362e5a2b17d1d31aa7" dependencies = [ "cfg-if 1.0.0", "serde", @@ -4428,9 +4282,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.69" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62" +checksum = "5b7d8b6942b8bb3a9b0e73fc79b98095a27de6fa247615e59d096754a3bc2aa8" dependencies = [ "bumpalo", "lazy_static", @@ -4443,9 +4297,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.19" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fe9756085a84584ee9457a002b7cdfe0bfff169f45d2591d8be1345a6780e35" +checksum = "8e67a5806118af01f0d9045915676b22aaebecf4178ae7021bc171dab0b897ab" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -4455,9 +4309,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.69" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084" +checksum = "e5ac38da8ef716661f0f36c0d8320b89028efe10c7c0afde65baffb496ce0d3b" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4465,9 +4319,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.69" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549" +checksum = "cc053ec74d454df287b9374ee8abb36ffd5acb95ba87da3ba5b7d3fe20eb401e" dependencies = [ "proc-macro2", "quote", @@ -4478,15 +4332,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.69" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158" +checksum = "7d6f8ec44822dd71f5f221a5847fb34acd9060535c1211b70a05844c0f6383b1" [[package]] name = "web-sys" -version = "0.3.46" +version = "0.3.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222b1ef9334f92a21d3fb53dc3fd80f30836959a90f9274a626d7e06315ba3c3" +checksum = "ec600b26223b2948cedfde2a0aa6756dcf1fef616f43d7b3097aaf53a6c4d92b" dependencies = [ "js-sys", "wasm-bindgen", @@ -4504,25 +4358,25 @@ dependencies = [ "derive_more", "ethabi", "ethereum-types 0.10.0", - "futures 0.3.12", + "futures 0.3.13", "futures-timer", "hex", - "hyper 0.13.9", + "hyper 0.13.10", "hyper-proxy", "hyper-tls 0.4.3", "jsonrpc-core", "log", "native-tls", "parking_lot 0.11.1", - "pin-project 1.0.4", + "pin-project", "rlp", "secp256k1", "serde", "serde_json", "soketto", "tiny-keccak 2.0.2", - "tokio 0.2.24", - "tokio-util 0.6.1", + "tokio 0.2.25", + "tokio-util 0.6.4", "typed-headers", "url", ] @@ -4590,22 +4444,22 @@ dependencies = [ [[package]] name = "wiremock" -version = "0.4.6" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5cb4fb12a3feb97521a5a09031ef4ba84d9d177a6e6382f8b788d88bc231b12" +checksum = "860c1b991b29b6bc5096b46bdaaea904417ed12fda814d38ccf1b869c13629c8" dependencies = [ "async-trait", "deadpool", - "futures 0.3.12", + "futures 0.3.13", "futures-timer", "http-types", - "hyper 0.14.2", + "hyper 0.14.4", "log", "once_cell", "regex", "serde", "serde_json", - "tokio 1.0.2", + "tokio 1.3.0", ] [[package]] diff --git a/adapter/src/dummy.rs b/adapter/src/dummy.rs index de3d8ebc7..bf2fe35f4 100644 --- a/adapter/src/dummy.rs +++ b/adapter/src/dummy.rs @@ -2,11 +2,12 @@ use async_trait::async_trait; use primitives::{ adapter::{ Adapter, AdapterErrorKind, AdapterResult, DummyAdapterOptions, Error as AdapterError, - Session, + Session, SpendableOutput }, channel_validator::ChannelValidator, config::Config, Channel, ToETHChecksum, ValidatorId, + BigNum }; use std::collections::HashMap; use std::fmt; @@ -129,4 +130,11 @@ impl Adapter for DummyAdapter { ))), } } + + async fn get_spendable(&self, channel: &Channel, spender: &ValidatorId) -> AdapterResult { + Ok(SpendableOutput { + amount: 10.into(), + to_be_deposited: 1.into(), + }) + } } diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 27e0c0d20..44bc14d5c 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -9,7 +9,7 @@ use ethstore::{ use futures::TryFutureExt; use lazy_static::lazy_static; use primitives::{ - adapter::{Adapter, AdapterResult, Error as AdapterError, KeystoreOptions, Session}, + adapter::{Adapter, AdapterResult, Error as AdapterError, KeystoreOptions, Session, SpendableOutput}, channel_validator::ChannelValidator, config::Config, Channel, ChannelId, ToETHChecksum, ValidatorId, @@ -31,7 +31,10 @@ mod error; lazy_static! { static ref ADEXCORE_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/AdExCore.json"); + static ref ERC20_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/ERC20.json"); static ref CHANNEL_STATE_ACTIVE: U256 = 1.into(); + //TODO + static ref MINIMUM_DEPOSIT_AMOUNT: U256 = 0.into(); } #[derive(Debug, Clone)] @@ -269,6 +272,44 @@ impl Adapter for EthereumAdapter { ewt_sign(&wallet, &self.keystore_pwd, &payload) .map_err(|err| AdapterError::Adapter(Error::SignMessage(err).into())) } + + + async fn get_spendable(&self, channel: &Channel, spender: &ValidatorId) -> AdapterResult { + let contract = Contract::from_json( + self.web3.eth(), + self.config.ethereum_core_address.into(), + &ADEXCORE_ABI, + ) + .map_err(Error::ContractInitialization)?; + + + // TODO: Get deposited per channel/spender from outpace + let mut amount: U256 = 1.into(); + + let to_be_deposited: U256 = tokio_compat_02::FutureExt::compat(async { + tokio_compat_02::FutureExt::compat(contract.query( + "balanceOf", + channel.deposit_asset.clone().into_token(), + None, + Options::default(), + None, + )) + .await + }) + .await + .map_err(Error::ContractQuerying)?; + + if to_be_deposited > *MINIMUM_DEPOSIT_AMOUNT { + amount += to_be_deposited; + } + + Ok(SpendableOutput { + amount, + to_be_deposited, + }) + + //? Should toBeDeposited be returned if it is less than Min? + } } #[derive(Debug, Clone)] diff --git a/lib/protocol-eth b/lib/protocol-eth index 40f2c57fa..a98e0efc5 160000 --- a/lib/protocol-eth +++ b/lib/protocol-eth @@ -1 +1 @@ -Subproject commit 40f2c57fad7aafcd09e15ca99a1513d278e51340 +Subproject commit a98e0efc57bbc9d5fb95ee0007a71b9605245278 diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 5c4c4758c..819fb2776 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -52,6 +52,7 @@ futures = "0.3" async-trait = "0.1" # Other lazy_static = "1.4.0" +web3 = { version = "0.15" } [dev-dependencies] pretty_assertions = "^0.6" diff --git a/primitives/src/adapter.rs b/primitives/src/adapter.rs index cc3ff58ac..4e3f6201c 100644 --- a/primitives/src/adapter.rs +++ b/primitives/src/adapter.rs @@ -6,11 +6,17 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::convert::From; use std::fmt; +use web3::types::U256; pub type AdapterResult = Result>; pub trait AdapterErrorKind: fmt::Debug + fmt::Display {} +pub struct SpendableOutput { + pub amount: U256, + pub to_be_deposited: U256, +} + #[derive(Debug)] pub enum Error { Authentication(String), @@ -104,4 +110,11 @@ pub trait Adapter: ChannelValidator + Send + Sync + fmt::Debug + Clone { /// Gets authentication for specific validator fn get_auth(&self, validator_id: &ValidatorId) -> AdapterResult; + + /// Calculates and returns the total spendable amount + async fn get_spendable( + &self, + channel: &Channel, + spender: &ValidatorId + ) -> AdapterResult; } From 009dde8fa27f5c7155fe0a7b82df3f1f84661a90 Mon Sep 17 00:00:00 2001 From: simzzz Date: Fri, 12 Mar 2021 16:38:16 +0200 Subject: [PATCH 02/60] changed a wrong parameter --- adapter/src/ethereum.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 44bc14d5c..a99490095 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -278,7 +278,7 @@ impl Adapter for EthereumAdapter { let contract = Contract::from_json( self.web3.eth(), self.config.ethereum_core_address.into(), - &ADEXCORE_ABI, + &ERC20_ABI, ) .map_err(Error::ContractInitialization)?; From 641d1ad6434b21f408acf8c5586985f46d139850 Mon Sep 17 00:00:00 2001 From: simzzz Date: Fri, 12 Mar 2021 17:17:07 +0200 Subject: [PATCH 03/60] change the way minimum deposit is retrieved --- adapter/src/ethereum.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index a99490095..e3212a4ae 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -33,8 +33,6 @@ lazy_static! { include_bytes!("../../lib/protocol-eth/abi/AdExCore.json"); static ref ERC20_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/ERC20.json"); static ref CHANNEL_STATE_ACTIVE: U256 = 1.into(); - //TODO - static ref MINIMUM_DEPOSIT_AMOUNT: U256 = 0.into(); } #[derive(Debug, Clone)] @@ -282,7 +280,6 @@ impl Adapter for EthereumAdapter { ) .map_err(Error::ContractInitialization)?; - // TODO: Get deposited per channel/spender from outpace let mut amount: U256 = 1.into(); @@ -298,8 +295,9 @@ impl Adapter for EthereumAdapter { }) .await .map_err(Error::ContractQuerying)?; + let minimum_deposit: U256 = self.config.minimal_deposit.to_string(); - if to_be_deposited > *MINIMUM_DEPOSIT_AMOUNT { + if to_be_deposited > minimum_deposit { amount += to_be_deposited; } From c73bf121d2ddf47c847f46ffcbd9ebac864ba2ac Mon Sep 17 00:00:00 2001 From: simzzz Date: Mon, 15 Mar 2021 15:15:38 +0200 Subject: [PATCH 04/60] progress made for ethereum adapter --- adapter/src/dummy.rs | 1 + adapter/src/ethereum.rs | 33 +++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/adapter/src/dummy.rs b/adapter/src/dummy.rs index bf2fe35f4..def9e2426 100644 --- a/adapter/src/dummy.rs +++ b/adapter/src/dummy.rs @@ -132,6 +132,7 @@ impl Adapter for DummyAdapter { } async fn get_spendable(&self, channel: &Channel, spender: &ValidatorId) -> AdapterResult { + // TODO - complete function Ok(SpendableOutput { amount: 10.into(), to_be_deposited: 1.into(), diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index e3212a4ae..b403b0a66 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -32,7 +32,10 @@ lazy_static! { static ref ADEXCORE_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/AdExCore.json"); static ref ERC20_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/ERC20.json"); + static ref OUTPACE_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/OUTPACE.json"); static ref CHANNEL_STATE_ACTIVE: U256 = 1.into(); + //TODO + static ref MINIMUM_DEPOSIT_AMOUNT: U256 = 0.into(); } #[derive(Debug, Clone)] @@ -273,18 +276,35 @@ impl Adapter for EthereumAdapter { async fn get_spendable(&self, channel: &Channel, spender: &ValidatorId) -> AdapterResult { - let contract = Contract::from_json( + let outpace_contract = Contract::from_json( + self.web3.eth(), + self.config.ethereum_core_address.into(), + &OUTPACE_ABI, + ) + .map_err(Error::ContractInitialization)?; + + let erc20_contract = Contract::from_json( self.web3.eth(), self.config.ethereum_core_address.into(), &ERC20_ABI, ) .map_err(Error::ContractInitialization)?; - // TODO: Get deposited per channel/spender from outpace - let mut amount: U256 = 1.into(); + let mut amount: U256 = tokio_compat_02::FutureExt::compat(async { + tokio_compat_02::FutureExt::compat(outpace_contract.query( + "deposits", + (channel.id.into_token(), spender.to_hex_prefix_string().into_token()), + None, + Options::default(), + None, + )) + .await + }) + .await + .map_err(Error::ContractQuerying)?; let to_be_deposited: U256 = tokio_compat_02::FutureExt::compat(async { - tokio_compat_02::FutureExt::compat(contract.query( + tokio_compat_02::FutureExt::compat(erc20_contract.query( "balanceOf", channel.deposit_asset.clone().into_token(), None, @@ -295,9 +315,8 @@ impl Adapter for EthereumAdapter { }) .await .map_err(Error::ContractQuerying)?; - let minimum_deposit: U256 = self.config.minimal_deposit.to_string(); - if to_be_deposited > minimum_deposit { + if to_be_deposited > *MINIMUM_DEPOSIT_AMOUNT { amount += to_be_deposited; } @@ -305,8 +324,6 @@ impl Adapter for EthereumAdapter { amount, to_be_deposited, }) - - //? Should toBeDeposited be returned if it is less than Min? } } From 9ab853cc1cd7ee0c12460d30144c3eb1ffd893e4 Mon Sep 17 00:00:00 2001 From: simzzz Date: Mon, 15 Mar 2021 15:18:35 +0200 Subject: [PATCH 05/60] updated /lib/protocol-eth --- .gitmodules | 3 ++- lib/protocol-eth | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index df0dea378..c4ec8ffb7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "lib/protocol-eth"] path = lib/protocol-eth - url = https://github.com/AdExNetwork/adex-protocol-eth + url = https://github.com/AdExNetwork/adex-protocol-eth/ + branch = outpace-abi-json diff --git a/lib/protocol-eth b/lib/protocol-eth index a98e0efc5..80eb362ef 160000 --- a/lib/protocol-eth +++ b/lib/protocol-eth @@ -1 +1 @@ -Subproject commit a98e0efc57bbc9d5fb95ee0007a71b9605245278 +Subproject commit 80eb362efa460fb4b5317ed006f8af0b9291fdc4 From 4c2b143c889dc943f645f8823a5ebdb62de5d6ed Mon Sep 17 00:00:00 2001 From: simzzz Date: Mon, 15 Mar 2021 20:47:40 +0200 Subject: [PATCH 06/60] Done with Ethereum Adapter --- adapter/src/ethereum.rs | 10 +++++++--- adapter/src/ethereum/error.rs | 4 +++- primitives/src/channel_validator.rs | 7 ++++--- primitives/src/config.rs | 9 ++++++++- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index b403b0a66..6c48136ca 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -34,8 +34,6 @@ lazy_static! { static ref ERC20_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/ERC20.json"); static ref OUTPACE_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/OUTPACE.json"); static ref CHANNEL_STATE_ACTIVE: U256 = 1.into(); - //TODO - static ref MINIMUM_DEPOSIT_AMOUNT: U256 = 0.into(); } #[derive(Debug, Clone)] @@ -316,7 +314,13 @@ impl Adapter for EthereumAdapter { .await .map_err(Error::ContractQuerying)?; - if to_be_deposited > *MINIMUM_DEPOSIT_AMOUNT { + let token_info = self.config.token_address_whitelist + .get(&channel.deposit_asset) + .ok_or(Error::TokenNotWhitelisted)?; + + let minimum_deposit_amount = U256::from(token_info.min_deposit); + + if to_be_deposited > minimum_deposit_amount { amount += to_be_deposited; } diff --git a/adapter/src/ethereum/error.rs b/adapter/src/ethereum/error.rs index 4026458c4..dc83ea6dd 100644 --- a/adapter/src/ethereum/error.rs +++ b/adapter/src/ethereum/error.rs @@ -22,6 +22,7 @@ pub enum Error { ContractQuerying(web3::contract::Error), /// Error occurred during verification of Signature and/or StateRoot and/or Address VerifyAddress(VerifyError), + TokenNotWhitelisted, } impl std::error::Error for Error {} @@ -43,7 +44,8 @@ impl fmt::Display for Error { VerifyMessage(err) => write!(f, "Verifying message: {}", err), ContractInitialization(err) => write!(f, "Contract initialization: {}", err), ContractQuerying(err) => write!(f, "Contract querying: {}", err), - VerifyAddress(err) => write!(f, "Verifying address: {}", err) + VerifyAddress(err) => write!(f, "Verifying address: {}", err), + TokenNotWhiteListed => write!(f, "Token not whitelisted") } } } diff --git a/primitives/src/channel_validator.rs b/primitives/src/channel_validator.rs index f8ef7acee..ec7069af1 100644 --- a/primitives/src/channel_validator.rs +++ b/primitives/src/channel_validator.rs @@ -1,9 +1,10 @@ use crate::channel::{Channel, ChannelError, SpecValidator, SpecValidators}; -use crate::config::Config; +use crate::config::{Config, TokenInfo}; use crate::BigNum; use crate::ValidatorId; use chrono::Utc; use std::cmp::PartialEq; +use std::collections::HashMap; use time::Duration; pub trait ChannelValidator { @@ -96,11 +97,11 @@ pub fn creator_listed(channel: &Channel, whitelist: &[ValidatorId]) -> bool { whitelist.is_empty() || whitelist.iter().any(|allowed| allowed.eq(&channel.creator)) } -pub fn asset_listed(channel: &Channel, whitelist: &[String]) -> bool { +pub fn asset_listed(channel: &Channel, whitelist: &HashMap) -> bool { // if the list is empty, return true, as we don't have a whitelist to restrict us to // or if we have a list, check if it includes the `channel.deposit_asset` whitelist.is_empty() || whitelist - .iter() + .keys() .any(|allowed| allowed == &channel.deposit_asset) } diff --git a/primitives/src/config.rs b/primitives/src/config.rs index 5c7de047e..8e73e5180 100644 --- a/primitives/src/config.rs +++ b/primitives/src/config.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; use crate::event_submission::RateLimit; use crate::{BigNum, ValidatorId}; use lazy_static::lazy_static; @@ -14,6 +15,12 @@ lazy_static! { .expect("Failed to parse prod.toml config file"); } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct TokenInfo { + pub min_deposit: u32, + pub decimals: u32, +} + #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(rename_all(serialize = "SCREAMING_SNAKE_CASE"))] pub struct Config { @@ -34,7 +41,7 @@ pub struct Config { pub creators_whitelist: Vec, pub minimal_deposit: BigNum, pub minimal_fee: BigNum, - pub token_address_whitelist: Vec, + pub token_address_whitelist: HashMap, #[serde(with = "SerHex::")] pub ethereum_core_address: [u8; 20], pub ethereum_network: String, From d8d079b88647cc408ad9838abc131e1a1c94a00a Mon Sep 17 00:00:00 2001 From: simzzz Date: Mon, 15 Mar 2021 20:59:58 +0200 Subject: [PATCH 07/60] Better error for TokenNotWhitelisted --- adapter/src/ethereum.rs | 2 +- adapter/src/ethereum/error.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 6c48136ca..fa2fb1021 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -316,7 +316,7 @@ impl Adapter for EthereumAdapter { let token_info = self.config.token_address_whitelist .get(&channel.deposit_asset) - .ok_or(Error::TokenNotWhitelisted)?; + .ok_or(Error::TokenNotWhitelisted(channel.deposit_asset.clone()))?; let minimum_deposit_amount = U256::from(token_info.min_deposit); diff --git a/adapter/src/ethereum/error.rs b/adapter/src/ethereum/error.rs index dc83ea6dd..063ca30eb 100644 --- a/adapter/src/ethereum/error.rs +++ b/adapter/src/ethereum/error.rs @@ -22,7 +22,7 @@ pub enum Error { ContractQuerying(web3::contract::Error), /// Error occurred during verification of Signature and/or StateRoot and/or Address VerifyAddress(VerifyError), - TokenNotWhitelisted, + TokenNotWhitelisted(String), } impl std::error::Error for Error {} @@ -45,7 +45,7 @@ impl fmt::Display for Error { ContractInitialization(err) => write!(f, "Contract initialization: {}", err), ContractQuerying(err) => write!(f, "Contract querying: {}", err), VerifyAddress(err) => write!(f, "Verifying address: {}", err), - TokenNotWhiteListed => write!(f, "Token not whitelisted") + TokenNotWhitelisted(deposit_asset) => write!(f, "Token not whitelisted: {}", deposit_asset), } } } From 3c1b9fa62b5a6e8e2c2915c80f4b994649aafeef Mon Sep 17 00:00:00 2001 From: simzzz Date: Thu, 18 Mar 2021 15:14:50 +0200 Subject: [PATCH 08/60] added Deposit type + fixes --- adapter/src/dummy.rs | 10 +++++----- adapter/src/ethereum.rs | 22 +++++++++++----------- docs/config/dev.toml | 2 +- docs/config/prod.toml | 1 + primitives/src/adapter.rs | 14 +++++++------- primitives/src/config.rs | 2 +- 6 files changed, 26 insertions(+), 25 deletions(-) diff --git a/adapter/src/dummy.rs b/adapter/src/dummy.rs index def9e2426..b1737e9c2 100644 --- a/adapter/src/dummy.rs +++ b/adapter/src/dummy.rs @@ -2,7 +2,7 @@ use async_trait::async_trait; use primitives::{ adapter::{ Adapter, AdapterErrorKind, AdapterResult, DummyAdapterOptions, Error as AdapterError, - Session, SpendableOutput + Session, Deposit }, channel_validator::ChannelValidator, config::Config, @@ -131,11 +131,11 @@ impl Adapter for DummyAdapter { } } - async fn get_spendable(&self, channel: &Channel, spender: &ValidatorId) -> AdapterResult { + async fn get_deposit(&self, channel: &Channel, spender: &ValidatorId) -> AdapterResult { // TODO - complete function - Ok(SpendableOutput { - amount: 10.into(), - to_be_deposited: 1.into(), + Ok(Deposit { + total: 10.into(), + pending: 1.into(), }) } } diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index fa2fb1021..fd7a9cc83 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -9,7 +9,7 @@ use ethstore::{ use futures::TryFutureExt; use lazy_static::lazy_static; use primitives::{ - adapter::{Adapter, AdapterResult, Error as AdapterError, KeystoreOptions, Session, SpendableOutput}, + adapter::{Adapter, AdapterResult, Error as AdapterError, KeystoreOptions, Session, Deposit}, channel_validator::ChannelValidator, config::Config, Channel, ChannelId, ToETHChecksum, ValidatorId, @@ -273,7 +273,7 @@ impl Adapter for EthereumAdapter { } - async fn get_spendable(&self, channel: &Channel, spender: &ValidatorId) -> AdapterResult { + async fn get_deposit(&self, channel: &Channel, user: &ValidatorId) -> AdapterResult { let outpace_contract = Contract::from_json( self.web3.eth(), self.config.ethereum_core_address.into(), @@ -288,10 +288,10 @@ impl Adapter for EthereumAdapter { ) .map_err(Error::ContractInitialization)?; - let mut amount: U256 = tokio_compat_02::FutureExt::compat(async { + let mut total: U256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(outpace_contract.query( "deposits", - (channel.id.into_token(), spender.to_hex_prefix_string().into_token()), + (channel.id.into_token(), user.to_hex_prefix_string().into_token()), None, Options::default(), None, @@ -301,7 +301,7 @@ impl Adapter for EthereumAdapter { .await .map_err(Error::ContractQuerying)?; - let to_be_deposited: U256 = tokio_compat_02::FutureExt::compat(async { + let pending: U256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(erc20_contract.query( "balanceOf", channel.deposit_asset.clone().into_token(), @@ -318,15 +318,15 @@ impl Adapter for EthereumAdapter { .get(&channel.deposit_asset) .ok_or(Error::TokenNotWhitelisted(channel.deposit_asset.clone()))?; - let minimum_deposit_amount = U256::from(token_info.min_deposit); + let minimum_deposit_amount = U256::from(token_info.min_token_units_for_deposit); - if to_be_deposited > minimum_deposit_amount { - amount += to_be_deposited; + if pending > minimum_deposit_amount { + total += pending; } - Ok(SpendableOutput { - amount, - to_be_deposited, + Ok(Deposit { + total, + pending, }) } } diff --git a/docs/config/dev.toml b/docs/config/dev.toml index a16add636..fd1c155f6 100644 --- a/docs/config/dev.toml +++ b/docs/config/dev.toml @@ -26,5 +26,5 @@ ethereum_adapter_relayer = 'https://goerli-relayer.adex.network' creators_whitelist = [] minimal_deposit = "0" minimal_fee = "0" -token_address_whitelist = [] validators_whitelist = [] +token_address_whitelist = [{ address = '0x73967c6a0904aa032c103b4104747e88c566b1a2', min_token_units_for_deposit = 100000000, precision = 18}] diff --git a/docs/config/prod.toml b/docs/config/prod.toml index a2c61e367..d12d2531b 100644 --- a/docs/config/prod.toml +++ b/docs/config/prod.toml @@ -27,3 +27,4 @@ minimal_deposit = "0" minimal_fee = "0" token_address_whitelist = ['0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359', '0x6B175474E89094C44Da98b954EedeAC495271d0F'] validators_whitelist = [] +token_address_whitelist = [{ address = '0x6b175474e89094c44da98b954eedeac495271d0f', min_token_units_for_deposit = 100000000, precision = 18}, { address = '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359', min_token_units_for_deposit = 100000000, precision = 18}] \ No newline at end of file diff --git a/primitives/src/adapter.rs b/primitives/src/adapter.rs index 4e3f6201c..9b3c5f094 100644 --- a/primitives/src/adapter.rs +++ b/primitives/src/adapter.rs @@ -1,6 +1,6 @@ use crate::channel::ChannelError; use crate::channel_validator::ChannelValidator; -use crate::{Channel, DomainError, ValidatorId}; +use crate::{Channel, DomainError, ValidatorId, BigNum}; use async_trait::async_trait; use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -12,9 +12,9 @@ pub type AdapterResult = Result>; pub trait AdapterErrorKind: fmt::Debug + fmt::Display {} -pub struct SpendableOutput { - pub amount: U256, - pub to_be_deposited: U256, +pub struct Deposit { + pub total: U256, + pub pending: U256, } #[derive(Debug)] @@ -112,9 +112,9 @@ pub trait Adapter: ChannelValidator + Send + Sync + fmt::Debug + Clone { fn get_auth(&self, validator_id: &ValidatorId) -> AdapterResult; /// Calculates and returns the total spendable amount - async fn get_spendable( + async fn get_deposit( &self, channel: &Channel, - spender: &ValidatorId - ) -> AdapterResult; + user: &ValidatorId + ) -> AdapterResult; } diff --git a/primitives/src/config.rs b/primitives/src/config.rs index 8e73e5180..29f25563c 100644 --- a/primitives/src/config.rs +++ b/primitives/src/config.rs @@ -17,7 +17,7 @@ lazy_static! { #[derive(Serialize, Deserialize, Debug, Clone)] pub struct TokenInfo { - pub min_deposit: u32, + pub min_token_units_for_deposit: u32, pub decimals: u32, } From 1da31bab70ef55eb42374f269ded42110a32818b Mon Sep 17 00:00:00 2001 From: simzzz Date: Fri, 19 Mar 2021 15:59:39 +0200 Subject: [PATCH 09/60] Merged new Channel/Campaign PR + more fixes --- Cargo.lock | 9 +++++---- adapter/Cargo.toml | 2 ++ adapter/src/dummy.rs | 4 ++-- adapter/src/ethereum.rs | 25 +++++++++++++------------ adapter/src/ethereum/error.rs | 4 ++-- primitives/src/adapter.rs | 9 ++++----- primitives/src/channel_validator.rs | 6 ++++-- primitives/src/config.rs | 9 +++++---- 8 files changed, 37 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b8b86fbb0..a7e662912 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,6 +9,7 @@ dependencies = [ "byteorder 1.4.3", "chrono", "eth_checksum", + "ethabi", "ethstore", "futures 0.3.13", "hex", @@ -1804,7 +1805,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1be51a921b067b0eaca2fad532d9400041561aa922221cc65f95a85641c6bf53" dependencies = [ - "parity-scale-codec 1.3.6", + "parity-scale-codec 1.3.7", ] [[package]] @@ -2822,7 +2823,7 @@ dependencies = [ "parse-display", "postgres-types 0.2.0", "pretty_assertions", - "rand 0.8.2", + "rand 0.8.3", "serde", "serde-hex", "serde_json", @@ -2832,7 +2833,7 @@ dependencies = [ "slog-async", "slog-term", "thiserror", - "time 0.1.43", + "time", "tiny-keccak 2.0.2", "tokio-postgres 0.7.0", "toml", @@ -3472,7 +3473,7 @@ dependencies = [ "clap", "dashmap", "deadpool", - "futures 0.3.12", + "futures 0.3.13", "hex", "hyper 0.14.4", "lazy_static", diff --git a/adapter/Cargo.toml b/adapter/Cargo.toml index b6949cf94..2c403832e 100644 --- a/adapter/Cargo.toml +++ b/adapter/Cargo.toml @@ -18,6 +18,8 @@ web3 = { version = "0.15", features = ["http-tls", "signing"] } eth_checksum = "0.1" tiny-keccak = "1.5" ethstore = { git = "https://github.com/openethereum/openethereum", tag = "v3.1.1-rc.1" } +ethabi = "13.0.0" + # API client reqwest = { version = "0.11", features = ["json"] } # reqwest = { version = "0.10", features = ["json"] } diff --git a/adapter/src/dummy.rs b/adapter/src/dummy.rs index b1737e9c2..dd4df27a9 100644 --- a/adapter/src/dummy.rs +++ b/adapter/src/dummy.rs @@ -7,7 +7,7 @@ use primitives::{ channel_validator::ChannelValidator, config::Config, Channel, ToETHChecksum, ValidatorId, - BigNum + BigNum, Address }; use std::collections::HashMap; use std::fmt; @@ -131,7 +131,7 @@ impl Adapter for DummyAdapter { } } - async fn get_deposit(&self, channel: &Channel, spender: &ValidatorId) -> AdapterResult { + async fn get_deposit(&self, channel: &Channel, spender: &Address) -> AdapterResult { // TODO - complete function Ok(Deposit { total: 10.into(), diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index fd7a9cc83..c5d78f369 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -12,7 +12,7 @@ use primitives::{ adapter::{Adapter, AdapterResult, Error as AdapterError, KeystoreOptions, Session, Deposit}, channel_validator::ChannelValidator, config::Config, - Channel, ChannelId, ToETHChecksum, ValidatorId, + Channel, ChannelId, ToETHChecksum, ValidatorId, Address as PrimitivesAddress, BigNum }; use reqwest::Client; use serde::{Deserialize, Serialize}; @@ -22,9 +22,10 @@ use tiny_keccak::Keccak; use web3::{ contract::{tokens::Tokenizable, Contract, Options}, transports::Http, - types::{H256, U256}, + types::{H256, U256, H160, Bytes}, Web3, }; +use ethabi::FixedBytes; mod error; @@ -273,7 +274,7 @@ impl Adapter for EthereumAdapter { } - async fn get_deposit(&self, channel: &Channel, user: &ValidatorId) -> AdapterResult { + async fn get_deposit(&self, channel: &Channel, user: &PrimitivesAddress) -> AdapterResult { let outpace_contract = Contract::from_json( self.web3.eth(), self.config.ethereum_core_address.into(), @@ -281,9 +282,11 @@ impl Adapter for EthereumAdapter { ) .map_err(Error::ContractInitialization)?; + // TODO: fix + let deposit_asset_as_address = PrimitivesAddress::try_from(&channel.deposit_asset).unwrap(); let erc20_contract = Contract::from_json( self.web3.eth(), - self.config.ethereum_core_address.into(), + deposit_asset_as_address.as_bytes().into(), &ERC20_ABI, ) .map_err(Error::ContractInitialization)?; @@ -291,7 +294,7 @@ impl Adapter for EthereumAdapter { let mut total: U256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(outpace_contract.query( "deposits", - (channel.id.into_token(), user.to_hex_prefix_string().into_token()), + (H256(*channel.id).into_token(), H160(*user.as_bytes()).into_token()), None, Options::default(), None, @@ -304,7 +307,7 @@ impl Adapter for EthereumAdapter { let pending: U256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(erc20_contract.query( "balanceOf", - channel.deposit_asset.clone().into_token(), + Bytes(channel.deposit_asset.as_bytes().to_vec()).into_token(), None, Options::default(), None, @@ -315,13 +318,11 @@ impl Adapter for EthereumAdapter { .map_err(Error::ContractQuerying)?; let token_info = self.config.token_address_whitelist - .get(&channel.deposit_asset) - .ok_or(Error::TokenNotWhitelisted(channel.deposit_asset.clone()))?; - - let minimum_deposit_amount = U256::from(token_info.min_token_units_for_deposit); + .get(&deposit_asset_as_address) + .ok_or(Error::TokenNotWhitelisted(deposit_asset_as_address.clone()))?; - if pending > minimum_deposit_amount { - total += pending; + if pending > token_info.min_token_units_for_deposit { + total += &pending; } Ok(Deposit { diff --git a/adapter/src/ethereum/error.rs b/adapter/src/ethereum/error.rs index 063ca30eb..cf9eba32d 100644 --- a/adapter/src/ethereum/error.rs +++ b/adapter/src/ethereum/error.rs @@ -1,5 +1,5 @@ use primitives::adapter::{AdapterErrorKind, Error as AdapterError}; -use primitives::ChannelId; +use primitives::{ChannelId, Address}; use std::fmt; #[derive(Debug)] @@ -22,7 +22,7 @@ pub enum Error { ContractQuerying(web3::contract::Error), /// Error occurred during verification of Signature and/or StateRoot and/or Address VerifyAddress(VerifyError), - TokenNotWhitelisted(String), + TokenNotWhitelisted(Address), } impl std::error::Error for Error {} diff --git a/primitives/src/adapter.rs b/primitives/src/adapter.rs index 9b3c5f094..3c7d208c1 100644 --- a/primitives/src/adapter.rs +++ b/primitives/src/adapter.rs @@ -1,20 +1,19 @@ use crate::channel::ChannelError; use crate::channel_validator::ChannelValidator; -use crate::{Channel, DomainError, ValidatorId, BigNum}; +use crate::{Channel, DomainError, ValidatorId, BigNum, Address}; use async_trait::async_trait; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::convert::From; use std::fmt; -use web3::types::U256; pub type AdapterResult = Result>; pub trait AdapterErrorKind: fmt::Debug + fmt::Display {} pub struct Deposit { - pub total: U256, - pub pending: U256, + pub total: BigNum, + pub pending: BigNum, } #[derive(Debug)] @@ -115,6 +114,6 @@ pub trait Adapter: ChannelValidator + Send + Sync + fmt::Debug + Clone { async fn get_deposit( &self, channel: &Channel, - user: &ValidatorId + user: &Address ) -> AdapterResult; } diff --git a/primitives/src/channel_validator.rs b/primitives/src/channel_validator.rs index ec7069af1..6cdf68ba7 100644 --- a/primitives/src/channel_validator.rs +++ b/primitives/src/channel_validator.rs @@ -6,6 +6,8 @@ use chrono::Utc; use std::cmp::PartialEq; use std::collections::HashMap; use time::Duration; +use crate::Address; +use std::convert::TryFrom; pub trait ChannelValidator { fn is_channel_valid( @@ -97,11 +99,11 @@ pub fn creator_listed(channel: &Channel, whitelist: &[ValidatorId]) -> bool { whitelist.is_empty() || whitelist.iter().any(|allowed| allowed.eq(&channel.creator)) } -pub fn asset_listed(channel: &Channel, whitelist: &HashMap) -> bool { +pub fn asset_listed(channel: &Channel, whitelist: &HashMap) -> bool { // if the list is empty, return true, as we don't have a whitelist to restrict us to // or if we have a list, check if it includes the `channel.deposit_asset` whitelist.is_empty() || whitelist .keys() - .any(|allowed| allowed == &channel.deposit_asset) + .any(|allowed| allowed == &Address::try_from(&channel.deposit_asset).unwrap()) // TODO: fix } diff --git a/primitives/src/config.rs b/primitives/src/config.rs index 29f25563c..6a554a12f 100644 --- a/primitives/src/config.rs +++ b/primitives/src/config.rs @@ -1,10 +1,11 @@ use std::collections::HashMap; use crate::event_submission::RateLimit; -use crate::{BigNum, ValidatorId}; +use crate::{BigNum, ValidatorId, Address}; use lazy_static::lazy_static; use serde::{Deserialize, Serialize}; use serde_hex::{SerHex, StrictPfx}; use std::fs; +use std::num::NonZeroU8; lazy_static! { static ref DEVELOPMENT_CONFIG: Config = @@ -17,8 +18,8 @@ lazy_static! { #[derive(Serialize, Deserialize, Debug, Clone)] pub struct TokenInfo { - pub min_token_units_for_deposit: u32, - pub decimals: u32, + pub min_token_units_for_deposit: BigNum, + pub decimals: NonZeroU8, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -41,7 +42,7 @@ pub struct Config { pub creators_whitelist: Vec, pub minimal_deposit: BigNum, pub minimal_fee: BigNum, - pub token_address_whitelist: HashMap, + pub token_address_whitelist: HashMap, #[serde(with = "SerHex::")] pub ethereum_core_address: [u8; 20], pub ethereum_network: String, From b27a1286dd832e802faca3393de37a8d72064e13 Mon Sep 17 00:00:00 2001 From: simzzz Date: Fri, 19 Mar 2021 18:01:12 +0200 Subject: [PATCH 10/60] changed total + pending variables to be BigNum --- adapter/src/ethereum.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index c5d78f369..ab325e6ab 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -26,6 +26,7 @@ use web3::{ Web3, }; use ethabi::FixedBytes; +use std::str::FromStr; mod error; @@ -291,7 +292,7 @@ impl Adapter for EthereumAdapter { ) .map_err(Error::ContractInitialization)?; - let mut total: U256 = tokio_compat_02::FutureExt::compat(async { + let mut total: H256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(outpace_contract.query( "deposits", (H256(*channel.id).into_token(), H160(*user.as_bytes()).into_token()), @@ -303,8 +304,9 @@ impl Adapter for EthereumAdapter { }) .await .map_err(Error::ContractQuerying)?; + let mut total = BigNum::from_str(&total.to_string())?; - let pending: U256 = tokio_compat_02::FutureExt::compat(async { + let pending: H256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(erc20_contract.query( "balanceOf", Bytes(channel.deposit_asset.as_bytes().to_vec()).into_token(), @@ -316,6 +318,7 @@ impl Adapter for EthereumAdapter { }) .await .map_err(Error::ContractQuerying)?; + let pending = BigNum::from_str(&pending.to_string())?; let token_info = self.config.token_address_whitelist .get(&deposit_asset_as_address) From b7e7af8f7517db2dda4678f6d402b324d31429d1 Mon Sep 17 00:00:00 2001 From: simzzz Date: Fri, 19 Mar 2021 21:38:31 +0200 Subject: [PATCH 11/60] Done with deserialization + tests passing + cargo fmt/clippy --- Cargo.lock | 1 - adapter/Cargo.toml | 1 - adapter/src/dummy.rs | 13 ++++++---- adapter/src/ethereum.rs | 39 ++++++++++++++++------------ adapter/src/ethereum/error.rs | 2 +- docs/config/dev.toml | 2 +- docs/config/prod.toml | 2 +- primitives/src/adapter.rs | 4 +-- primitives/src/channel_validator.rs | 7 ++--- primitives/src/config.rs | 40 ++++++++++++++++++++++++++--- sentry/src/middleware/auth.rs | 2 +- 11 files changed, 77 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a7e662912..909324692 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,7 +9,6 @@ dependencies = [ "byteorder 1.4.3", "chrono", "eth_checksum", - "ethabi", "ethstore", "futures 0.3.13", "hex", diff --git a/adapter/Cargo.toml b/adapter/Cargo.toml index 2c403832e..559d15da1 100644 --- a/adapter/Cargo.toml +++ b/adapter/Cargo.toml @@ -18,7 +18,6 @@ web3 = { version = "0.15", features = ["http-tls", "signing"] } eth_checksum = "0.1" tiny-keccak = "1.5" ethstore = { git = "https://github.com/openethereum/openethereum", tag = "v3.1.1-rc.1" } -ethabi = "13.0.0" # API client reqwest = { version = "0.11", features = ["json"] } diff --git a/adapter/src/dummy.rs b/adapter/src/dummy.rs index dd4df27a9..e92031cf5 100644 --- a/adapter/src/dummy.rs +++ b/adapter/src/dummy.rs @@ -1,13 +1,12 @@ use async_trait::async_trait; use primitives::{ adapter::{ - Adapter, AdapterErrorKind, AdapterResult, DummyAdapterOptions, Error as AdapterError, - Session, Deposit + Adapter, AdapterErrorKind, AdapterResult, Deposit, DummyAdapterOptions, + Error as AdapterError, Session, }, channel_validator::ChannelValidator, config::Config, - Channel, ToETHChecksum, ValidatorId, - BigNum, Address + Address, BigNum, Channel, ToETHChecksum, ValidatorId, }; use std::collections::HashMap; use std::fmt; @@ -131,7 +130,11 @@ impl Adapter for DummyAdapter { } } - async fn get_deposit(&self, channel: &Channel, spender: &Address) -> AdapterResult { + async fn get_deposit( + &self, + channel: &Channel, + spender: &Address, + ) -> AdapterResult { // TODO - complete function Ok(Deposit { total: 10.into(), diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index ab325e6ab..c28e85bb0 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -9,24 +9,23 @@ use ethstore::{ use futures::TryFutureExt; use lazy_static::lazy_static; use primitives::{ - adapter::{Adapter, AdapterResult, Error as AdapterError, KeystoreOptions, Session, Deposit}, + adapter::{Adapter, AdapterResult, Deposit, Error as AdapterError, KeystoreOptions, Session}, channel_validator::ChannelValidator, config::Config, - Channel, ChannelId, ToETHChecksum, ValidatorId, Address as PrimitivesAddress, BigNum + Address as PrimitivesAddress, BigNum, Channel, ChannelId, ToETHChecksum, ValidatorId, }; use reqwest::Client; use serde::{Deserialize, Serialize}; use serde_json::Value; +use std::str::FromStr; use std::{convert::TryFrom, fs}; use tiny_keccak::Keccak; use web3::{ contract::{tokens::Tokenizable, Contract, Options}, transports::Http, - types::{H256, U256, H160, Bytes}, + types::{Bytes, H160, H256, U256}, Web3, }; -use ethabi::FixedBytes; -use std::str::FromStr; mod error; @@ -34,7 +33,8 @@ lazy_static! { static ref ADEXCORE_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/AdExCore.json"); static ref ERC20_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/ERC20.json"); - static ref OUTPACE_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/OUTPACE.json"); + static ref OUTPACE_ABI: &'static [u8] = + include_bytes!("../../lib/protocol-eth/abi/OUTPACE.json"); static ref CHANNEL_STATE_ACTIVE: U256 = 1.into(); } @@ -274,8 +274,11 @@ impl Adapter for EthereumAdapter { .map_err(|err| AdapterError::Adapter(Error::SignMessage(err).into())) } - - async fn get_deposit(&self, channel: &Channel, user: &PrimitivesAddress) -> AdapterResult { + async fn get_deposit( + &self, + channel: &Channel, + user: &PrimitivesAddress, + ) -> AdapterResult { let outpace_contract = Contract::from_json( self.web3.eth(), self.config.ethereum_core_address.into(), @@ -292,10 +295,13 @@ impl Adapter for EthereumAdapter { ) .map_err(Error::ContractInitialization)?; - let mut total: H256 = tokio_compat_02::FutureExt::compat(async { + let total: H256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(outpace_contract.query( "deposits", - (H256(*channel.id).into_token(), H160(*user.as_bytes()).into_token()), + ( + H256(*channel.id).into_token(), + H160(*user.as_bytes()).into_token(), + ), None, Options::default(), None, @@ -320,18 +326,17 @@ impl Adapter for EthereumAdapter { .map_err(Error::ContractQuerying)?; let pending = BigNum::from_str(&pending.to_string())?; - let token_info = self.config.token_address_whitelist - .get(&deposit_asset_as_address) - .ok_or(Error::TokenNotWhitelisted(deposit_asset_as_address.clone()))?; + let token_info = self + .config + .token_address_whitelist + .get(&deposit_asset_as_address) + .ok_or(Error::TokenNotWhitelisted(deposit_asset_as_address))?; if pending > token_info.min_token_units_for_deposit { total += &pending; } - Ok(Deposit { - total, - pending, - }) + Ok(Deposit { total, pending }) } } diff --git a/adapter/src/ethereum/error.rs b/adapter/src/ethereum/error.rs index cf9eba32d..1ca144d36 100644 --- a/adapter/src/ethereum/error.rs +++ b/adapter/src/ethereum/error.rs @@ -1,5 +1,5 @@ use primitives::adapter::{AdapterErrorKind, Error as AdapterError}; -use primitives::{ChannelId, Address}; +use primitives::{Address, ChannelId}; use std::fmt; #[derive(Debug)] diff --git a/docs/config/dev.toml b/docs/config/dev.toml index fd1c155f6..b75ef0655 100644 --- a/docs/config/dev.toml +++ b/docs/config/dev.toml @@ -27,4 +27,4 @@ creators_whitelist = [] minimal_deposit = "0" minimal_fee = "0" validators_whitelist = [] -token_address_whitelist = [{ address = '0x73967c6a0904aa032c103b4104747e88c566b1a2', min_token_units_for_deposit = 100000000, precision = 18}] +token_address_whitelist = [{ address = '0x73967c6a0904aa032c103b4104747e88c566b1a2', min_token_units_for_deposit = '100000000', precision = 18}] diff --git a/docs/config/prod.toml b/docs/config/prod.toml index d12d2531b..68dfe3d95 100644 --- a/docs/config/prod.toml +++ b/docs/config/prod.toml @@ -27,4 +27,4 @@ minimal_deposit = "0" minimal_fee = "0" token_address_whitelist = ['0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359', '0x6B175474E89094C44Da98b954EedeAC495271d0F'] validators_whitelist = [] -token_address_whitelist = [{ address = '0x6b175474e89094c44da98b954eedeac495271d0f', min_token_units_for_deposit = 100000000, precision = 18}, { address = '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359', min_token_units_for_deposit = 100000000, precision = 18}] \ No newline at end of file +token_address_whitelist = [{ address = '0x6b175474e89094c44da98b954eedeac495271d0f', min_token_units_for_deposit = '100000000', precision = 18}, { address = '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359', min_token_units_for_deposit = '100000000', precision = 18}] \ No newline at end of file diff --git a/primitives/src/adapter.rs b/primitives/src/adapter.rs index 3c7d208c1..bda5e7eed 100644 --- a/primitives/src/adapter.rs +++ b/primitives/src/adapter.rs @@ -1,6 +1,6 @@ use crate::channel::ChannelError; use crate::channel_validator::ChannelValidator; -use crate::{Channel, DomainError, ValidatorId, BigNum, Address}; +use crate::{Address, BigNum, Channel, DomainError, ValidatorId}; use async_trait::async_trait; use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -114,6 +114,6 @@ pub trait Adapter: ChannelValidator + Send + Sync + fmt::Debug + Clone { async fn get_deposit( &self, channel: &Channel, - user: &Address + user: &Address, ) -> AdapterResult; } diff --git a/primitives/src/channel_validator.rs b/primitives/src/channel_validator.rs index 6cdf68ba7..c1f7afa0f 100644 --- a/primitives/src/channel_validator.rs +++ b/primitives/src/channel_validator.rs @@ -1,13 +1,13 @@ use crate::channel::{Channel, ChannelError, SpecValidator, SpecValidators}; use crate::config::{Config, TokenInfo}; +use crate::Address; use crate::BigNum; use crate::ValidatorId; use chrono::Utc; use std::cmp::PartialEq; use std::collections::HashMap; -use time::Duration; -use crate::Address; use std::convert::TryFrom; +use time::Duration; pub trait ChannelValidator { fn is_channel_valid( @@ -105,5 +105,6 @@ pub fn asset_listed(channel: &Channel, whitelist: &HashMap) whitelist.is_empty() || whitelist .keys() - .any(|allowed| allowed == &Address::try_from(&channel.deposit_asset).unwrap()) // TODO: fix + .any(|allowed| allowed == &Address::try_from(&channel.deposit_asset).unwrap()) + // TODO: fix } diff --git a/primitives/src/config.rs b/primitives/src/config.rs index 6a554a12f..a5ac0f524 100644 --- a/primitives/src/config.rs +++ b/primitives/src/config.rs @@ -1,11 +1,13 @@ -use std::collections::HashMap; use crate::event_submission::RateLimit; -use crate::{BigNum, ValidatorId, Address}; +use crate::{Address, BigNum, ValidatorId}; use lazy_static::lazy_static; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Deserializer, Serialize}; use serde_hex::{SerHex, StrictPfx}; +use std::collections::HashMap; +use std::convert::TryFrom; use std::fs; use std::num::NonZeroU8; +use std::str::FromStr; lazy_static! { static ref DEVELOPMENT_CONFIG: Config = @@ -42,6 +44,7 @@ pub struct Config { pub creators_whitelist: Vec, pub minimal_deposit: BigNum, pub minimal_fee: BigNum, + #[serde(deserialize_with = "deserialize_token_whitelist")] pub token_address_whitelist: HashMap, #[serde(with = "SerHex::")] pub ethereum_core_address: [u8; 20], @@ -50,6 +53,37 @@ pub struct Config { pub validators_whitelist: Vec, } +#[derive(Serialize, Deserialize, Debug, Clone)] +struct ConfigWhitelist { + address: String, + min_token_units_for_deposit: String, + precision: NonZeroU8, +} + +fn deserialize_token_whitelist<'de, D>( + deserializer: D, +) -> Result, D::Error> +where + D: Deserializer<'de>, +{ + let mut tokens_whitelist = HashMap::new(); + let array: Vec = Deserialize::deserialize(deserializer)?; + array.into_iter().for_each(|i| { + // TODO: Remove unwraps + tokens_whitelist.insert( + Address::try_from(&i.address).unwrap(), + TokenInfo { + min_token_units_for_deposit: BigNum::from_str(&i.min_token_units_for_deposit) + .unwrap(), + decimals: i.precision, + }, + ); + }); + + Ok(tokens_whitelist) + // Ok(BigUint::from_str(&num).map_err(serde::de::Error::custom)?) +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub enum ConfigError { InvalidFile(String), diff --git a/sentry/src/middleware/auth.rs b/sentry/src/middleware/auth.rs index 82c9b6548..ce404e98a 100644 --- a/sentry/src/middleware/auth.rs +++ b/sentry/src/middleware/auth.rs @@ -133,7 +133,7 @@ mod test { use primitives::util::tests::prep_db::{AUTH, IDS}; - use primitives::{config::configuration}; + use primitives::config::configuration; use deadpool::managed::Object; From 33dcd4cc2e13cdddf3ef028ba4db87c5bb2d860f Mon Sep 17 00:00:00 2001 From: simzzz Date: Wed, 24 Mar 2021 16:54:57 +0200 Subject: [PATCH 12/60] renaming + updating protocol-eth --- .gitmodules | 2 +- adapter/src/dummy.rs | 4 ++-- adapter/src/ethereum.rs | 17 ++++++++++------- lib/protocol-eth | 2 +- primitives/src/adapter.rs | 4 ++-- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.gitmodules b/.gitmodules index c4ec8ffb7..05dad7482 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "lib/protocol-eth"] path = lib/protocol-eth url = https://github.com/AdExNetwork/adex-protocol-eth/ - branch = outpace-abi-json + branch = guardian-separate-claim diff --git a/adapter/src/dummy.rs b/adapter/src/dummy.rs index e92031cf5..aed255e31 100644 --- a/adapter/src/dummy.rs +++ b/adapter/src/dummy.rs @@ -133,12 +133,12 @@ impl Adapter for DummyAdapter { async fn get_deposit( &self, channel: &Channel, - spender: &Address, + address: &Address, ) -> AdapterResult { // TODO - complete function Ok(Deposit { total: 10.into(), - pending: 1.into(), + still_on_create_2: 1.into(), }) } } diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index c28e85bb0..cbba9cc49 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -277,7 +277,7 @@ impl Adapter for EthereumAdapter { async fn get_deposit( &self, channel: &Channel, - user: &PrimitivesAddress, + address: &PrimitivesAddress, ) -> AdapterResult { let outpace_contract = Contract::from_json( self.web3.eth(), @@ -300,7 +300,7 @@ impl Adapter for EthereumAdapter { "deposits", ( H256(*channel.id).into_token(), - H160(*user.as_bytes()).into_token(), + H160(*address.as_bytes()).into_token(), ), None, Options::default(), @@ -312,7 +312,7 @@ impl Adapter for EthereumAdapter { .map_err(Error::ContractQuerying)?; let mut total = BigNum::from_str(&total.to_string())?; - let pending: H256 = tokio_compat_02::FutureExt::compat(async { + let still_on_create_2: H256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(erc20_contract.query( "balanceOf", Bytes(channel.deposit_asset.as_bytes().to_vec()).into_token(), @@ -324,7 +324,7 @@ impl Adapter for EthereumAdapter { }) .await .map_err(Error::ContractQuerying)?; - let pending = BigNum::from_str(&pending.to_string())?; + let still_on_create_2 = BigNum::from_str(&still_on_create_2.to_string())?; let token_info = self .config @@ -332,11 +332,14 @@ impl Adapter for EthereumAdapter { .get(&deposit_asset_as_address) .ok_or(Error::TokenNotWhitelisted(deposit_asset_as_address))?; - if pending > token_info.min_token_units_for_deposit { - total += &pending; + if still_on_create_2 > token_info.min_token_units_for_deposit { + total += &still_on_create_2; } - Ok(Deposit { total, pending }) + Ok(Deposit { + total, + still_on_create_2, + }) } } diff --git a/lib/protocol-eth b/lib/protocol-eth index 80eb362ef..e8533085c 160000 --- a/lib/protocol-eth +++ b/lib/protocol-eth @@ -1 +1 @@ -Subproject commit 80eb362efa460fb4b5317ed006f8af0b9291fdc4 +Subproject commit e8533085c9a801f938c9d8fb3338109512ff5b9e diff --git a/primitives/src/adapter.rs b/primitives/src/adapter.rs index bda5e7eed..cc21c1680 100644 --- a/primitives/src/adapter.rs +++ b/primitives/src/adapter.rs @@ -13,7 +13,7 @@ pub trait AdapterErrorKind: fmt::Debug + fmt::Display {} pub struct Deposit { pub total: BigNum, - pub pending: BigNum, + pub still_on_create_2: BigNum, } #[derive(Debug)] @@ -114,6 +114,6 @@ pub trait Adapter: ChannelValidator + Send + Sync + fmt::Debug + Clone { async fn get_deposit( &self, channel: &Channel, - user: &Address, + address: &Address, ) -> AdapterResult; } From 8ac2305d753bf9ba11412883e01ca0e735dd3a8e Mon Sep 17 00:00:00 2001 From: simzzz Date: Wed, 24 Mar 2021 17:44:05 +0200 Subject: [PATCH 13/60] updated submodules --- lib/protocol-eth | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protocol-eth b/lib/protocol-eth index e8533085c..4a19c05e2 160000 --- a/lib/protocol-eth +++ b/lib/protocol-eth @@ -1 +1 @@ -Subproject commit e8533085c9a801f938c9d8fb3338109512ff5b9e +Subproject commit 4a19c05e27d59a97b24cb2dbd74748ebbab81d08 From e912f4fcca4dd8188c46512b463e50f5e6804156 Mon Sep 17 00:00:00 2001 From: simzzz Date: Wed, 24 Mar 2021 18:54:28 +0200 Subject: [PATCH 14/60] minor changes --- adapter/src/ethereum.rs | 2 ++ docs/config/prod.toml | 2 +- primitives/src/channel_validator.rs | 2 +- primitives/src/config.rs | 1 - 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index cbba9cc49..382190ba2 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -310,6 +310,7 @@ impl Adapter for EthereumAdapter { }) .await .map_err(Error::ContractQuerying)?; + let mut total = BigNum::from_str(&total.to_string())?; let still_on_create_2: H256 = tokio_compat_02::FutureExt::compat(async { @@ -324,6 +325,7 @@ impl Adapter for EthereumAdapter { }) .await .map_err(Error::ContractQuerying)?; + let still_on_create_2 = BigNum::from_str(&still_on_create_2.to_string())?; let token_info = self diff --git a/docs/config/prod.toml b/docs/config/prod.toml index 68dfe3d95..a5ba4f340 100644 --- a/docs/config/prod.toml +++ b/docs/config/prod.toml @@ -27,4 +27,4 @@ minimal_deposit = "0" minimal_fee = "0" token_address_whitelist = ['0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359', '0x6B175474E89094C44Da98b954EedeAC495271d0F'] validators_whitelist = [] -token_address_whitelist = [{ address = '0x6b175474e89094c44da98b954eedeac495271d0f', min_token_units_for_deposit = '100000000', precision = 18}, { address = '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359', min_token_units_for_deposit = '100000000', precision = 18}] \ No newline at end of file +token_address_whitelist = [{ address = '0x6b175474e89094c44da98b954eedeac495271d0f', min_token_units_for_deposit = '100000000', precision = 18}, { address = '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359', min_token_units_for_deposit = '100000000', precision = 18}] diff --git a/primitives/src/channel_validator.rs b/primitives/src/channel_validator.rs index c1f7afa0f..b182d4d40 100644 --- a/primitives/src/channel_validator.rs +++ b/primitives/src/channel_validator.rs @@ -105,6 +105,6 @@ pub fn asset_listed(channel: &Channel, whitelist: &HashMap) whitelist.is_empty() || whitelist .keys() + // TODO: fix .any(|allowed| allowed == &Address::try_from(&channel.deposit_asset).unwrap()) - // TODO: fix } diff --git a/primitives/src/config.rs b/primitives/src/config.rs index a5ac0f524..dbad965ac 100644 --- a/primitives/src/config.rs +++ b/primitives/src/config.rs @@ -81,7 +81,6 @@ where }); Ok(tokens_whitelist) - // Ok(BigUint::from_str(&num).map_err(serde::de::Error::custom)?) } #[derive(Serialize, Deserialize, Debug, Clone)] From 2dd1692eef234c2e63950c0644857e42f64212c4 Mon Sep 17 00:00:00 2001 From: simzzz Date: Thu, 25 Mar 2021 18:27:12 +0200 Subject: [PATCH 15/60] fixed some unwraps --- adapter/src/ethereum.rs | 5 +++-- adapter/src/ethereum/error.rs | 3 +++ primitives/src/channel_validator.rs | 5 +++-- primitives/src/config.rs | 13 +++++++------ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 382190ba2..aef49bbcb 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -286,8 +286,9 @@ impl Adapter for EthereumAdapter { ) .map_err(Error::ContractInitialization)?; - // TODO: fix - let deposit_asset_as_address = PrimitivesAddress::try_from(&channel.deposit_asset).unwrap(); + let deposit_asset_as_address = PrimitivesAddress::try_from(&channel.deposit_asset) + .map_err(Error::InvalidDepositAsset)?; + let erc20_contract = Contract::from_json( self.web3.eth(), deposit_asset_as_address.as_bytes().into(), diff --git a/adapter/src/ethereum/error.rs b/adapter/src/ethereum/error.rs index 1ca144d36..1cbae44d0 100644 --- a/adapter/src/ethereum/error.rs +++ b/adapter/src/ethereum/error.rs @@ -1,5 +1,6 @@ use primitives::adapter::{AdapterErrorKind, Error as AdapterError}; use primitives::{Address, ChannelId}; +use primitives::address::Error as AddressError; use std::fmt; #[derive(Debug)] @@ -23,6 +24,7 @@ pub enum Error { /// Error occurred during verification of Signature and/or StateRoot and/or Address VerifyAddress(VerifyError), TokenNotWhitelisted(Address), + InvalidDepositAsset(AddressError), } impl std::error::Error for Error {} @@ -46,6 +48,7 @@ impl fmt::Display for Error { ContractQuerying(err) => write!(f, "Contract querying: {}", err), VerifyAddress(err) => write!(f, "Verifying address: {}", err), TokenNotWhitelisted(deposit_asset) => write!(f, "Token not whitelisted: {}", deposit_asset), + InvalidDepositAsset(err) => write!(f, "Deposit asset {} is invalid", err), } } } diff --git a/primitives/src/channel_validator.rs b/primitives/src/channel_validator.rs index b182d4d40..01a261d60 100644 --- a/primitives/src/channel_validator.rs +++ b/primitives/src/channel_validator.rs @@ -100,11 +100,12 @@ pub fn creator_listed(channel: &Channel, whitelist: &[ValidatorId]) -> bool { } pub fn asset_listed(channel: &Channel, whitelist: &HashMap) -> bool { + // TODO: Fix unwrap + let asset_as_address = Address::try_from(&channel.deposit_asset).unwrap(); // if the list is empty, return true, as we don't have a whitelist to restrict us to // or if we have a list, check if it includes the `channel.deposit_asset` whitelist.is_empty() || whitelist .keys() - // TODO: fix - .any(|allowed| allowed == &Address::try_from(&channel.deposit_asset).unwrap()) + .any(|allowed| allowed == &asset_as_address) } diff --git a/primitives/src/config.rs b/primitives/src/config.rs index dbad965ac..fdef4025c 100644 --- a/primitives/src/config.rs +++ b/primitives/src/config.rs @@ -68,17 +68,18 @@ where { let mut tokens_whitelist = HashMap::new(); let array: Vec = Deserialize::deserialize(deserializer)?; - array.into_iter().for_each(|i| { - // TODO: Remove unwraps + for i in array { + let addr = Address::try_from(&i.address).map_err(serde::de::Error::custom)?; + let min_token_units_for_deposit = BigNum::from_str(&i.min_token_units_for_deposit) + .map_err(serde::de::Error::custom)?; tokens_whitelist.insert( - Address::try_from(&i.address).unwrap(), + addr, TokenInfo { - min_token_units_for_deposit: BigNum::from_str(&i.min_token_units_for_deposit) - .unwrap(), + min_token_units_for_deposit, decimals: i.precision, }, ); - }); + } Ok(tokens_whitelist) } From 3beccae221116e2674af3b90bef3a6e500a24e58 Mon Sep 17 00:00:00 2001 From: simzzz Date: Thu, 25 Mar 2021 19:21:40 +0200 Subject: [PATCH 16/60] Simplified deserialization of token whitelist --- primitives/src/config.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/primitives/src/config.rs b/primitives/src/config.rs index fdef4025c..e1add5cb2 100644 --- a/primitives/src/config.rs +++ b/primitives/src/config.rs @@ -55,8 +55,8 @@ pub struct Config { #[derive(Serialize, Deserialize, Debug, Clone)] struct ConfigWhitelist { - address: String, - min_token_units_for_deposit: String, + address: Address, + min_token_units_for_deposit: BigNum, precision: NonZeroU8, } @@ -68,18 +68,16 @@ where { let mut tokens_whitelist = HashMap::new(); let array: Vec = Deserialize::deserialize(deserializer)?; - for i in array { - let addr = Address::try_from(&i.address).map_err(serde::de::Error::custom)?; - let min_token_units_for_deposit = BigNum::from_str(&i.min_token_units_for_deposit) - .map_err(serde::de::Error::custom)?; + + array.into_iter().for_each(|i| { tokens_whitelist.insert( - addr, + i.address, TokenInfo { - min_token_units_for_deposit, + min_token_units_for_deposit: i.min_token_units_for_deposit, decimals: i.precision, }, ); - } + }); Ok(tokens_whitelist) } From 4894910b15d80e5b65bbe8e134cfdd817fec5a05 Mon Sep 17 00:00:00 2001 From: simzzz Date: Fri, 26 Mar 2021 14:09:10 +0200 Subject: [PATCH 17/60] binded import to a different name + merged main v5 branch --- adapter/src/ethereum.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index aef49bbcb..ece4fae4f 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use chrono::Utc; use error::*; use ethstore::{ - ethkey::{public_to_address, recover, verify_address, Address, Message, Password, Signature}, + ethkey::{public_to_address, recover, verify_address, Address as EthAddress, Message, Password, Signature}, SafeAccount, }; use futures::TryFutureExt; @@ -12,7 +12,7 @@ use primitives::{ adapter::{Adapter, AdapterResult, Deposit, Error as AdapterError, KeystoreOptions, Session}, channel_validator::ChannelValidator, config::Config, - Address as PrimitivesAddress, BigNum, Channel, ChannelId, ToETHChecksum, ValidatorId, + Address, BigNum, Channel, ChannelId, ToETHChecksum, ValidatorId, }; use reqwest::Client; use serde::{Deserialize, Serialize}; @@ -135,7 +135,7 @@ impl Adapter for EthereumAdapter { return Err(VerifyError::SignatureNotPrefixed.into()); } let decoded_signature = hex::decode(&sig[2..]).map_err(VerifyError::SignatureDecoding)?; - let address = Address::from(*signer.inner()); + let address = EthAddress::from(*signer.inner()); let signature = Signature::from_electrum(&decoded_signature); let state_root = hex::decode(state_root).map_err(VerifyError::StateRootDecoding)?; let message = Message::from(hash_message(&state_root)); @@ -277,7 +277,7 @@ impl Adapter for EthereumAdapter { async fn get_deposit( &self, channel: &Channel, - address: &PrimitivesAddress, + address: &Address, ) -> AdapterResult { let outpace_contract = Contract::from_json( self.web3.eth(), @@ -286,7 +286,7 @@ impl Adapter for EthereumAdapter { ) .map_err(Error::ContractInitialization)?; - let deposit_asset_as_address = PrimitivesAddress::try_from(&channel.deposit_asset) + let deposit_asset_as_address = Address::try_from(&channel.deposit_asset) .map_err(Error::InvalidDepositAsset)?; let erc20_contract = Contract::from_json( From e8dfe270f8c7308e61e51c2edc1368e9e7470738 Mon Sep 17 00:00:00 2001 From: simzzz Date: Mon, 29 Mar 2021 16:25:01 +0300 Subject: [PATCH 18/60] adde ERC20.json to the adapter temporarily --- adapter/ERC20.json | 1 + adapter/src/ethereum.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 adapter/ERC20.json diff --git a/adapter/ERC20.json b/adapter/ERC20.json new file mode 100644 index 000000000..a3de7b8f3 --- /dev/null +++ b/adapter/ERC20.json @@ -0,0 +1 @@ +[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}] diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index ece4fae4f..9cb0419a1 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -32,7 +32,8 @@ mod error; lazy_static! { static ref ADEXCORE_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/AdExCore.json"); - static ref ERC20_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/ERC20.json"); + // TODO: Fix it once ERC20 and OUTPACE are merged + static ref ERC20_ABI: &'static [u8] = include_bytes!("../ERC20.json"); static ref OUTPACE_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/OUTPACE.json"); static ref CHANNEL_STATE_ACTIVE: U256 = 1.into(); From 133a9a54f6eea8adea8eea47b92453a80935e0b1 Mon Sep 17 00:00:00 2001 From: simzzz Date: Mon, 29 Mar 2021 16:38:53 +0300 Subject: [PATCH 19/60] formatting and removed unwrap --- adapter/src/ethereum.rs | 9 ++++++--- adapter/src/ethereum/error.rs | 2 +- primitives/src/channel_validator.rs | 5 +---- primitives/src/config.rs | 2 -- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 9cb0419a1..b7dc351d4 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -3,7 +3,10 @@ use async_trait::async_trait; use chrono::Utc; use error::*; use ethstore::{ - ethkey::{public_to_address, recover, verify_address, Address as EthAddress, Message, Password, Signature}, + ethkey::{ + public_to_address, recover, verify_address, Address as EthAddress, Message, Password, + Signature, + }, SafeAccount, }; use futures::TryFutureExt; @@ -287,8 +290,8 @@ impl Adapter for EthereumAdapter { ) .map_err(Error::ContractInitialization)?; - let deposit_asset_as_address = Address::try_from(&channel.deposit_asset) - .map_err(Error::InvalidDepositAsset)?; + let deposit_asset_as_address = + Address::try_from(&channel.deposit_asset).map_err(Error::InvalidDepositAsset)?; let erc20_contract = Contract::from_json( self.web3.eth(), diff --git a/adapter/src/ethereum/error.rs b/adapter/src/ethereum/error.rs index 4518d6e8c..9b0eaab3b 100644 --- a/adapter/src/ethereum/error.rs +++ b/adapter/src/ethereum/error.rs @@ -1,6 +1,6 @@ use primitives::adapter::{AdapterErrorKind, Error as AdapterError}; -use primitives::{Address, ChannelId}; use primitives::address::Error as AddressError; +use primitives::{Address, ChannelId}; use std::fmt; #[derive(Debug)] diff --git a/primitives/src/channel_validator.rs b/primitives/src/channel_validator.rs index 01a261d60..2e0eb6c04 100644 --- a/primitives/src/channel_validator.rs +++ b/primitives/src/channel_validator.rs @@ -6,7 +6,6 @@ use crate::ValidatorId; use chrono::Utc; use std::cmp::PartialEq; use std::collections::HashMap; -use std::convert::TryFrom; use time::Duration; pub trait ChannelValidator { @@ -100,12 +99,10 @@ pub fn creator_listed(channel: &Channel, whitelist: &[ValidatorId]) -> bool { } pub fn asset_listed(channel: &Channel, whitelist: &HashMap) -> bool { - // TODO: Fix unwrap - let asset_as_address = Address::try_from(&channel.deposit_asset).unwrap(); // if the list is empty, return true, as we don't have a whitelist to restrict us to // or if we have a list, check if it includes the `channel.deposit_asset` whitelist.is_empty() || whitelist .keys() - .any(|allowed| allowed == &asset_as_address) + .any(|allowed| &allowed.to_string() == &channel.deposit_asset) } diff --git a/primitives/src/config.rs b/primitives/src/config.rs index e1add5cb2..7b8500930 100644 --- a/primitives/src/config.rs +++ b/primitives/src/config.rs @@ -4,10 +4,8 @@ use lazy_static::lazy_static; use serde::{Deserialize, Deserializer, Serialize}; use serde_hex::{SerHex, StrictPfx}; use std::collections::HashMap; -use std::convert::TryFrom; use std::fs; use std::num::NonZeroU8; -use std::str::FromStr; lazy_static! { static ref DEVELOPMENT_CONFIG: Config = From 84e60fdda8ea08da021172b8009a4bcf5d32d8f6 Mon Sep 17 00:00:00 2001 From: simzzz Date: Mon, 29 Mar 2021 16:57:50 +0300 Subject: [PATCH 20/60] Fixes from PR review --- Cargo.lock | 1 - adapter/src/dummy.rs | 3 ++- adapter/src/ethereum.rs | 23 +++++++++-------------- primitives/Cargo.toml | 1 - primitives/src/adapter.rs | 4 ++-- primitives/src/config.rs | 24 +++++++++++++----------- 6 files changed, 26 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 909324692..f523b4e57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2837,7 +2837,6 @@ dependencies = [ "tokio-postgres 0.7.0", "toml", "url", - "web3", ] [[package]] diff --git a/adapter/src/dummy.rs b/adapter/src/dummy.rs index aed255e31..64f09a8be 100644 --- a/adapter/src/dummy.rs +++ b/adapter/src/dummy.rs @@ -4,6 +4,7 @@ use primitives::{ Adapter, AdapterErrorKind, AdapterResult, Deposit, DummyAdapterOptions, Error as AdapterError, Session, }, + channel_v5::Channel as ChannelV5, channel_validator::ChannelValidator, config::Config, Address, BigNum, Channel, ToETHChecksum, ValidatorId, @@ -132,7 +133,7 @@ impl Adapter for DummyAdapter { async fn get_deposit( &self, - channel: &Channel, + channel: &ChannelV5, address: &Address, ) -> AdapterResult { // TODO - complete function diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index b7dc351d4..adfa36bc4 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -13,6 +13,7 @@ use futures::TryFutureExt; use lazy_static::lazy_static; use primitives::{ adapter::{Adapter, AdapterResult, Deposit, Error as AdapterError, KeystoreOptions, Session}, + channel_v5::Channel as ChannelV5, channel_validator::ChannelValidator, config::Config, Address, BigNum, Channel, ChannelId, ToETHChecksum, ValidatorId, @@ -280,7 +281,7 @@ impl Adapter for EthereumAdapter { async fn get_deposit( &self, - channel: &Channel, + channel: &ChannelV5, address: &Address, ) -> AdapterResult { let outpace_contract = Contract::from_json( @@ -290,21 +291,15 @@ impl Adapter for EthereumAdapter { ) .map_err(Error::ContractInitialization)?; - let deposit_asset_as_address = - Address::try_from(&channel.deposit_asset).map_err(Error::InvalidDepositAsset)?; - - let erc20_contract = Contract::from_json( - self.web3.eth(), - deposit_asset_as_address.as_bytes().into(), - &ERC20_ABI, - ) - .map_err(Error::ContractInitialization)?; + let erc20_contract = + Contract::from_json(self.web3.eth(), channel.token.as_bytes().into(), &ERC20_ABI) + .map_err(Error::ContractInitialization)?; let total: H256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(outpace_contract.query( "deposits", ( - H256(*channel.id).into_token(), + H256(*channel.id()).into_token(), H160(*address.as_bytes()).into_token(), ), None, @@ -321,7 +316,7 @@ impl Adapter for EthereumAdapter { let still_on_create_2: H256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(erc20_contract.query( "balanceOf", - Bytes(channel.deposit_asset.as_bytes().to_vec()).into_token(), + Bytes(channel.token.as_bytes().to_vec()).into_token(), None, Options::default(), None, @@ -336,8 +331,8 @@ impl Adapter for EthereumAdapter { let token_info = self .config .token_address_whitelist - .get(&deposit_asset_as_address) - .ok_or(Error::TokenNotWhitelisted(deposit_asset_as_address))?; + .get(&channel.token) + .ok_or(Error::TokenNotWhitelisted(channel.token))?; if still_on_create_2 > token_info.min_token_units_for_deposit { total += &still_on_create_2; diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index df82a1d0c..7fa47099e 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -54,7 +54,6 @@ futures = "0.3" async-trait = "0.1" # Other lazy_static = "1.4.0" -web3 = { version = "0.15" } [dev-dependencies] pretty_assertions = "^0.6" diff --git a/primitives/src/adapter.rs b/primitives/src/adapter.rs index cc21c1680..ca2902226 100644 --- a/primitives/src/adapter.rs +++ b/primitives/src/adapter.rs @@ -1,6 +1,6 @@ use crate::channel::ChannelError; use crate::channel_validator::ChannelValidator; -use crate::{Address, BigNum, Channel, DomainError, ValidatorId}; +use crate::{channel_v5::Channel as ChannelV5, Address, BigNum, Channel, DomainError, ValidatorId}; use async_trait::async_trait; use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -113,7 +113,7 @@ pub trait Adapter: ChannelValidator + Send + Sync + fmt::Debug + Clone { /// Calculates and returns the total spendable amount async fn get_deposit( &self, - channel: &Channel, + channel: &ChannelV5, address: &Address, ) -> AdapterResult; } diff --git a/primitives/src/config.rs b/primitives/src/config.rs index 7b8500930..d5b287418 100644 --- a/primitives/src/config.rs +++ b/primitives/src/config.rs @@ -19,7 +19,7 @@ lazy_static! { #[derive(Serialize, Deserialize, Debug, Clone)] pub struct TokenInfo { pub min_token_units_for_deposit: BigNum, - pub decimals: NonZeroU8, + pub precision: NonZeroU8, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -64,18 +64,20 @@ fn deserialize_token_whitelist<'de, D>( where D: Deserializer<'de>, { - let mut tokens_whitelist = HashMap::new(); let array: Vec = Deserialize::deserialize(deserializer)?; - array.into_iter().for_each(|i| { - tokens_whitelist.insert( - i.address, - TokenInfo { - min_token_units_for_deposit: i.min_token_units_for_deposit, - decimals: i.precision, - }, - ); - }); + let tokens_whitelist: HashMap = array + .into_iter() + .map(|i| { + ( + i.address, + TokenInfo { + min_token_units_for_deposit: i.min_token_units_for_deposit, + precision: i.precision, + }, + ) + }) + .collect(); Ok(tokens_whitelist) } From 10ef8e1add9b6f6cf7975ed34bee9e11f1ec5d74 Mon Sep 17 00:00:00 2001 From: simzzz Date: Mon, 29 Mar 2021 17:23:51 +0300 Subject: [PATCH 21/60] Removed whitelist for dev.toml causing a test to fail --- docs/config/dev.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/config/dev.toml b/docs/config/dev.toml index b75ef0655..5bc86ff0b 100644 --- a/docs/config/dev.toml +++ b/docs/config/dev.toml @@ -27,4 +27,4 @@ creators_whitelist = [] minimal_deposit = "0" minimal_fee = "0" validators_whitelist = [] -token_address_whitelist = [{ address = '0x73967c6a0904aa032c103b4104747e88c566b1a2', min_token_units_for_deposit = '100000000', precision = 18}] +token_address_whitelist = [] From fc68d42398546f057f2d932c9c1871f1ff20695b Mon Sep 17 00:00:00 2001 From: simzzz Date: Mon, 29 Mar 2021 21:17:07 +0300 Subject: [PATCH 22/60] more fixes from PR --- adapter/src/ethereum.rs | 18 ++++++++++-------- adapter/src/ethereum/error.rs | 8 +++++--- docs/config/prod.toml | 23 +++++++++++++++++++++-- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index adfa36bc4..afb22c03c 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -26,6 +26,7 @@ use std::{convert::TryFrom, fs}; use tiny_keccak::Keccak; use web3::{ contract::{tokens::Tokenizable, Contract, Options}, + ethabi::Token, transports::Http, types::{Bytes, H160, H256, U256}, Web3, @@ -62,7 +63,6 @@ impl EthereumAdapter { pub fn init(opts: KeystoreOptions, config: &Config) -> AdapterResult { let keystore_contents = fs::read_to_string(&opts.keystore_file).map_err(KeystoreError::ReadingFile)?; - let keystore_json: Value = serde_json::from_str(&keystore_contents).map_err(KeystoreError::Deserialization)?; @@ -299,7 +299,7 @@ impl Adapter for EthereumAdapter { tokio_compat_02::FutureExt::compat(outpace_contract.query( "deposits", ( - H256(*channel.id()).into_token(), + channel.id().into_token(), H160(*address.as_bytes()).into_token(), ), None, @@ -313,7 +313,7 @@ impl Adapter for EthereumAdapter { let mut total = BigNum::from_str(&total.to_string())?; - let still_on_create_2: H256 = tokio_compat_02::FutureExt::compat(async { + let still_on_create_2: U256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(erc20_contract.query( "balanceOf", Bytes(channel.token.as_bytes().to_vec()).into_token(), @@ -326,7 +326,7 @@ impl Adapter for EthereumAdapter { .await .map_err(Error::ContractQuerying)?; - let still_on_create_2 = BigNum::from_str(&still_on_create_2.to_string())?; + let still_on_create_2: BigNum = still_on_create_2.to_string().parse()?; let token_info = self .config @@ -501,10 +501,12 @@ mod test { use crate::EthereumChannel; use chrono::{Duration, Utc}; use hex::FromHex; - use primitives::config::configuration; - use primitives::ChannelId; - use primitives::{adapter::KeystoreOptions, targeting::Rules}; - use primitives::{ChannelSpec, EventSubmission, SpecValidators, ValidatorDesc}; + use primitives::{ + config::configutaion, + adapter::KeystoreOptions, + targeting::Rules, + ChannelId, ChannelSpec, EventSubmission, SpecValidators, ValidatorDesc + }; use std::convert::TryFrom; use web3::types::Address; use wiremock::{ diff --git a/adapter/src/ethereum/error.rs b/adapter/src/ethereum/error.rs index 9b0eaab3b..9b7257aff 100644 --- a/adapter/src/ethereum/error.rs +++ b/adapter/src/ethereum/error.rs @@ -1,6 +1,8 @@ -use primitives::adapter::{AdapterErrorKind, Error as AdapterError}; -use primitives::address::Error as AddressError; -use primitives::{Address, ChannelId}; +use primitives::{ + adapter::{AdapterErrorKind, Error as AdapterError}, + address::Error as AddressError, + Address, ChannelId +}; use std::fmt; #[derive(Debug)] diff --git a/docs/config/prod.toml b/docs/config/prod.toml index a5ba4f340..d83355722 100644 --- a/docs/config/prod.toml +++ b/docs/config/prod.toml @@ -25,6 +25,25 @@ ethereum_adapter_relayer = 'https://relayer.adex.network' creators_whitelist = [] minimal_deposit = "0" minimal_fee = "0" -token_address_whitelist = ['0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359', '0x6B175474E89094C44Da98b954EedeAC495271d0F'] validators_whitelist = [] -token_address_whitelist = [{ address = '0x6b175474e89094c44da98b954eedeac495271d0f', min_token_units_for_deposit = '100000000', precision = 18}, { address = '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359', min_token_units_for_deposit = '100000000', precision = 18}] + +[[token_address_whitelist]] +address = '0x6b175474e89094c44da98b954eedeac495271d0f' #DAI +min_token_units_for_deposit = '100000000' +precision = 18 + +[[token_address_whitelist]] +address = '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359' #SAI +min_token_units_for_deposit = '100000000' +precision = 18 + +[[token_address_whitelist]] +address = '0xdac17f958d2ee523a2206206994597c13d831ec7' #USDT +min_token_units_for_deposit = '100000000' +precision = 6 + +[[token_address_whitelist]] +address = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' #USDC +min_token_units_for_deposit = '100000000' +precision = 6 + From 3f2810448473f2481da86df7781551e25b183454 Mon Sep 17 00:00:00 2001 From: simzzz Date: Mon, 12 Apr 2021 17:58:25 +0300 Subject: [PATCH 23/60] dummy adapter + integration tests --- adapter/src/dummy.rs | 123 +++++++++++++++++++++++++++++++++++++--- adapter/src/ethereum.rs | 108 ++++++++++++++++++++++++++++++----- docs/config/dev.toml | 16 +++++- 3 files changed, 225 insertions(+), 22 deletions(-) diff --git a/adapter/src/dummy.rs b/adapter/src/dummy.rs index 64f09a8be..12366a288 100644 --- a/adapter/src/dummy.rs +++ b/adapter/src/dummy.rs @@ -1,16 +1,17 @@ use async_trait::async_trait; +use lazy_static::lazy_static; use primitives::{ adapter::{ Adapter, AdapterErrorKind, AdapterResult, Deposit, DummyAdapterOptions, Error as AdapterError, Session, }, - channel_v5::Channel as ChannelV5, + channel_v5::{Channel as ChannelV5, Nonce}, channel_validator::ChannelValidator, - config::Config, - Address, BigNum, Channel, ToETHChecksum, ValidatorId, + config::{Config, TokenInfo}, + Address, BigNum, Channel, ChannelId, ToETHChecksum, ValidatorId, }; -use std::collections::HashMap; -use std::fmt; +use std::ops::Add; +use std::{collections::HashMap, convert::TryFrom, fmt}; #[derive(Debug, Clone)] pub struct DummyAdapter { @@ -20,6 +21,24 @@ pub struct DummyAdapter { session_tokens: HashMap, // Auth tokens that we've generated to authenticate with someone (address => token) authorization_tokens: HashMap, + // Generated for retrieving deposit of channel-spender pair + deposits: HashMap<(ChannelId, Address), BigNum>, + // Generated for retrieving balances of tokens + token_balances: HashMap, +} + +lazy_static! { + static ref DUMMY_V5_CHANNEL: ChannelV5 = ChannelV5 { + leader: ValidatorId::try_from("2bdeafae53940669daa6f519373f686c1f3d3393") + .expect("failed to create id"), + follower: ValidatorId::try_from("6704Fbfcd5Ef766B287262fA2281C105d57246a6") + .expect("failed to create id"), + guardian: Address::try_from("0000000000000000000000000000000000000000") + .expect("failed to create address"), + token: Address::try_from("0x73967c6a0904aa032c103b4104747e88c566b1a2") + .expect("should create an address"), + nonce: Nonce::from(12345_u32), + }; } // Enables DummyAdapter to be able to @@ -33,10 +52,39 @@ impl DummyAdapter { config: config.to_owned(), session_tokens: opts.dummy_auth, authorization_tokens: opts.dummy_auth_tokens, + deposits: generate_deposits(), + token_balances: generate_balances(&config.token_address_whitelist), } } } +fn generate_deposits() -> HashMap<(ChannelId, Address), BigNum> { + let mut deposits = HashMap::new(); + deposits.insert( + ( + DUMMY_V5_CHANNEL.id(), + Address::try_from("1111111111111111111111111111111111111111").expect("should generate"), + ), + BigNum::try_from("1000000000000").expect("should make bignum"), + ); + deposits +} + +fn generate_balances(whitelist: &HashMap) -> HashMap { + let mut balances = HashMap::new(); + whitelist.keys().for_each(|k| { + balances.insert( + *k, + whitelist + .get(k) + .unwrap() + .min_token_units_for_deposit + .clone(), + ); + }); + balances +} + #[derive(Debug)] pub struct Error {} impl fmt::Display for Error { @@ -136,10 +184,69 @@ impl Adapter for DummyAdapter { channel: &ChannelV5, address: &Address, ) -> AdapterResult { - // TODO - complete function + let mut total = self + .deposits + .get(&(channel.id(), *address)) + .unwrap() + .clone(); + let still_on_create_2 = self.token_balances.get(&channel.token).unwrap().clone(); + let token_info = self + .config + .token_address_whitelist + .get(&channel.token) + .unwrap(); + + if still_on_create_2 > token_info.min_token_units_for_deposit { + total = total.add(still_on_create_2.clone()); + } + Ok(Deposit { - total: 10.into(), - still_on_create_2: 1.into(), + total, + still_on_create_2, }) } } + +#[cfg(test)] +mod test { + use super::*; + use primitives::{ + config::configuration, + util::tests::prep_db::{AUTH, IDS}, + }; + use std::convert::TryFrom; + + fn setup_dummy_adapter(dummy_identity: &str) -> DummyAdapter { + let config = configuration("development", None).expect("failed parse config"); + + let options = DummyAdapterOptions { + dummy_identity: ValidatorId::try_from(dummy_identity).expect("should generate id"), + dummy_auth: IDS.clone(), + dummy_auth_tokens: AUTH.clone(), + }; + + DummyAdapter::init(options, &config) + } + + #[tokio::test] + async fn test_dummy_get_deposit() { + let dummy_adapter = setup_dummy_adapter("0000000000000000000000000000000000000000"); + + let spender: Address = Address::try_from("1111111111111111111111111111111111111111") + .expect("should create an address"); + let deposit = dummy_adapter + .get_deposit(&DUMMY_V5_CHANNEL, &spender) + .await + .expect("should get deposit"); + let expected_total = dummy_adapter + .deposits + .get(&(DUMMY_V5_CHANNEL.id(), spender)) + .expect("should get balance"); + assert_eq!(deposit.total, *expected_total); + let expected_on_create_2 = dummy_adapter + .token_balances + .get(&DUMMY_V5_CHANNEL.token) + .expect("should get token"); + assert_eq!(deposit.still_on_create_2, *expected_on_create_2); + } +} diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index afb22c03c..91963cb2d 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -26,9 +26,8 @@ use std::{convert::TryFrom, fs}; use tiny_keccak::Keccak; use web3::{ contract::{tokens::Tokenizable, Contract, Options}, - ethabi::Token, transports::Http, - types::{Bytes, H160, H256, U256}, + types::{H160, H256, U256}, Web3, }; @@ -295,12 +294,12 @@ impl Adapter for EthereumAdapter { Contract::from_json(self.web3.eth(), channel.token.as_bytes().into(), &ERC20_ABI) .map_err(Error::ContractInitialization)?; - let total: H256 = tokio_compat_02::FutureExt::compat(async { + let total: U256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(outpace_contract.query( "deposits", ( - channel.id().into_token(), - H160(*address.as_bytes()).into_token(), + *channel.id(), + H160(*address.as_bytes()), ), None, Options::default(), @@ -316,7 +315,7 @@ impl Adapter for EthereumAdapter { let still_on_create_2: U256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(erc20_contract.query( "balanceOf", - Bytes(channel.token.as_bytes().to_vec()).into_token(), + H160(*channel.token.as_bytes()), None, Options::default(), None, @@ -502,13 +501,15 @@ mod test { use chrono::{Duration, Utc}; use hex::FromHex; use primitives::{ - config::configutaion, adapter::KeystoreOptions, + channel_v5::Nonce, + config::{configuration, TokenInfo}, targeting::Rules, ChannelId, ChannelSpec, EventSubmission, SpecValidators, ValidatorDesc }; use std::convert::TryFrom; - use web3::types::Address; + use std::num::NonZeroU8; + use web3::types::Address as EthAddress; use wiremock::{ matchers::{method, path}, Mock, MockServer, ResponseTemplate, @@ -645,7 +646,7 @@ mod test { let payload = Payload { id: eth_adapter.whoami().to_checksum(), era: era.floor() as i64, - identity: Some(identity.clone()), + identity: Some(identity), address: eth_adapter.whoami().to_checksum(), }; @@ -662,10 +663,10 @@ mod test { web3::transports::Http::new("http://localhost:8545").expect("failed to init transport"); let web3 = web3::Web3::new(http); - let leader_account: Address = "Df08F82De32B8d460adbE8D72043E3a7e25A3B39" + let leader_account: EthAddress = "Df08F82De32B8d460adbE8D72043E3a7e25A3B39" .parse() .expect("failed to parse leader account"); - let _follower_account: Address = "6704Fbfcd5Ef766B287262fA2281C105d57246a6" + let _follower_account: EthAddress = "6704Fbfcd5Ef766B287262fA2281C105d57246a6" .parse() .expect("failed to parse leader account"); @@ -713,7 +714,7 @@ mod test { // contract call set balance tokio_compat_02::FutureExt::compat(token_contract.call( "setBalanceTo", - (Address::from(leader_account), U256::from(2000_u64)), + (EthAddress::from(leader_account), U256::from(2000_u64)), leader_account, Options::default(), )) @@ -787,9 +788,16 @@ mod test { let channel_id = eth_channel.hash(&contract_addr); // set id to proper id valid_channel.id = ChannelId::from(channel_id); - + let token_address = Address::from(&token_contract.address().to_fixed_bytes()); // eth adapter let mut eth_adapter = setup_eth_adapter(Some(contract_addr)); + eth_adapter.config.token_address_whitelist.insert( + token_address, + TokenInfo { + min_token_units_for_deposit: BigNum::from(1000000), + precision: NonZeroU8::new(18).expect("should create NonZeroU8"), + }, + ); eth_adapter.unlock().expect("should unlock eth adapter"); // validate channel let result = eth_adapter @@ -799,4 +807,78 @@ mod test { assert!(result, "should validate valid channel correctly"); } + + #[tokio::test] + async fn should_get_correct_deposit() { + let http = + web3::transports::Http::new("http://localhost:8545").expect("failed to init transport"); + + let web3 = web3::Web3::new(http); + let leader_account: EthAddress = "Df08F82De32B8d460adbE8D72043E3a7e25A3B39" + .parse() + .expect("failed to parse leader account"); + // tokenbytecode.json + let token_bytecode = + include_str!("../test/resources/tokenbytecode.json").trim_end_matches("\n"); + // token_abi.json + let token_abi = include_bytes!("../test/resources/tokenabi.json"); + + // deploy contracts + let token_contract = tokio_compat_02::FutureExt::compat(async { + Contract::deploy(web3.eth(), token_abi) + .expect("invalid token token contract") + .confirmations(0) + .options(Options::with(|opt| { + opt.gas_price = Some(1.into()); + opt.gas = Some(6_721_975.into()); + })) + .execute(token_bytecode, (), leader_account) + }) + .await; + + let token_contract = tokio_compat_02::FutureExt::compat(token_contract) + .await + .expect("Correct parameters are passed to the constructor."); + let leader = ValidatorId::try_from("2bdeafae53940669daa6f519373f686c1f3d3393") + .expect("failed to create id"); + let follower = ValidatorId::try_from("6704Fbfcd5Ef766B287262fA2281C105d57246a6") + .expect("failed to create id"); + let nonce = Nonce::from(12345_u32); + let guardian: Address = Address::try_from("0000000000000000000000000000000000000000") + .expect("should create an address"); + let token_address = token_contract.address().to_fixed_bytes(); + + let token: Address = Address::from(&token_contract.address().to_fixed_bytes()); + let spender: Address = Address::try_from("0000000000000000000000000000000000000000") + .expect("should create an address"); + let channel_to_pass = ChannelV5 { + leader, + follower, + guardian, + token, + nonce, + }; + + let mut eth_adapter = setup_eth_adapter(Some(token_address)); + eth_adapter.config.token_address_whitelist.insert( + token, + TokenInfo { + min_token_units_for_deposit: BigNum::from(1000000), + precision: NonZeroU8::new(18).expect("should create NonZeroU8"), + }, + ); + eth_adapter.unlock().expect("should unlock eth adapter"); + + let deposit = eth_adapter + .get_deposit(&channel_to_pass, &spender) + .await + .expect("should get deposit"); + + let expected_deposit = Deposit { + total: BigNum::from(0), + still_on_create_2: BigNum::from(0), + }; + assert_eq!(deposit.total, expected_deposit.total); + assert_eq!(deposit.still_on_create_2, expected_deposit.still_on_create_2); + } } diff --git a/docs/config/dev.toml b/docs/config/dev.toml index 5bc86ff0b..251a4a463 100644 --- a/docs/config/dev.toml +++ b/docs/config/dev.toml @@ -27,4 +27,18 @@ creators_whitelist = [] minimal_deposit = "0" minimal_fee = "0" validators_whitelist = [] -token_address_whitelist = [] + +[[token_address_whitelist]] +address = '0x73967c6a0904aa032c103b4104747e88c566b1a2' #DAI +min_token_units_for_deposit = '100000000' +precision = 18 + +[[token_address_whitelist]] +address = '0x509ee0d083ddf8ac028f2a56731412edd63223b9' #USDT +min_token_units_for_deposit = '100000000' +precision = 6 + +[[token_address_whitelist]] +address = '0x44dcfcead37be45206af6079648988b29284b2c6' #USDC +min_token_units_for_deposit = '100000000' +precision = 6 From 780422e4aa87dc05d73bd6abf4371865b8ab2532 Mon Sep 17 00:00:00 2001 From: simzzz Date: Mon, 12 Apr 2021 18:19:01 +0300 Subject: [PATCH 24/60] cargo fmt + realistic test spender address --- adapter/src/ethereum.rs | 15 ++++++++------- adapter/src/ethereum/error.rs | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 91963cb2d..4cbf74cbe 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -297,10 +297,7 @@ impl Adapter for EthereumAdapter { let total: U256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(outpace_contract.query( "deposits", - ( - *channel.id(), - H160(*address.as_bytes()), - ), + (*channel.id(), H160(*address.as_bytes())), None, Options::default(), None, @@ -505,7 +502,7 @@ mod test { channel_v5::Nonce, config::{configuration, TokenInfo}, targeting::Rules, - ChannelId, ChannelSpec, EventSubmission, SpecValidators, ValidatorDesc + ChannelId, ChannelSpec, EventSubmission, SpecValidators, ValidatorDesc, }; use std::convert::TryFrom; use std::num::NonZeroU8; @@ -849,7 +846,7 @@ mod test { let token_address = token_contract.address().to_fixed_bytes(); let token: Address = Address::from(&token_contract.address().to_fixed_bytes()); - let spender: Address = Address::try_from("0000000000000000000000000000000000000000") + let spender: Address = Address::try_from("0x3d9C9C9673B2E3e9046137E752C5F8dCE823A1bB") .expect("should create an address"); let channel_to_pass = ChannelV5 { leader, @@ -874,11 +871,15 @@ mod test { .await .expect("should get deposit"); + // TODO: Mock contract output let expected_deposit = Deposit { total: BigNum::from(0), still_on_create_2: BigNum::from(0), }; assert_eq!(deposit.total, expected_deposit.total); - assert_eq!(deposit.still_on_create_2, expected_deposit.still_on_create_2); + assert_eq!( + deposit.still_on_create_2, + expected_deposit.still_on_create_2 + ); } } diff --git a/adapter/src/ethereum/error.rs b/adapter/src/ethereum/error.rs index 9b7257aff..5826115ea 100644 --- a/adapter/src/ethereum/error.rs +++ b/adapter/src/ethereum/error.rs @@ -1,7 +1,7 @@ use primitives::{ adapter::{AdapterErrorKind, Error as AdapterError}, address::Error as AddressError, - Address, ChannelId + Address, ChannelId, }; use std::fmt; From a8a70dc421c161c99bc43aaa5ce7d5ce1fc08ee8 Mon Sep 17 00:00:00 2001 From: simzzz Date: Wed, 14 Apr 2021 17:12:08 +0300 Subject: [PATCH 25/60] comitting progress with smart contracts --- Cargo.lock | 1 + adapter/Cargo.toml | 1 + adapter/src/ethereum.rs | 23 ++++++++++++++++++++++- primitives/src/channel_validator.rs | 2 +- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f523b4e57..90e10a7fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,6 +14,7 @@ dependencies = [ "hex", "lazy_static", "primitives", + "rand 0.8.3", "reqwest", "serde", "serde-hex", diff --git a/adapter/Cargo.toml b/adapter/Cargo.toml index 559d15da1..e017326ea 100644 --- a/adapter/Cargo.toml +++ b/adapter/Cargo.toml @@ -18,6 +18,7 @@ web3 = { version = "0.15", features = ["http-tls", "signing"] } eth_checksum = "0.1" tiny-keccak = "1.5" ethstore = { git = "https://github.com/openethereum/openethereum", tag = "v3.1.1-rc.1" } +rand = "^0.8" # API client reqwest = { version = "0.11", features = ["json"] } diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 4cbf74cbe..e19f587da 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -18,6 +18,7 @@ use primitives::{ config::Config, Address, BigNum, Channel, ChannelId, ToETHChecksum, ValidatorId, }; +use rand::{thread_rng, RngCore}; use reqwest::Client; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -90,6 +91,25 @@ impl EthereumAdapter { } } +fn get_counterfactual_address(token: Address) -> H160 { + let mut salt: [u8; 32] = [0; 32]; + thread_rng().fill_bytes(&mut salt); + let mut init_code = Keccak::new_keccak256(); + init_code.update(b"0x00"); + let mut hashed_init_code: [u8; 32] = [0; 32]; + init_code.finalize(&mut hashed_init_code); + + let mut result = Keccak::new_keccak256(); + result.update(b"0xff"); + result.update(token.as_bytes()); + result.update(&salt); + result.update(&hashed_init_code); + let mut res: [u8; 20] = [0; 20]; + result.finalize(&mut res); + + H160::from(res) +} + #[async_trait] impl Adapter for EthereumAdapter { type AdapterError = Error; @@ -309,10 +329,11 @@ impl Adapter for EthereumAdapter { let mut total = BigNum::from_str(&total.to_string())?; + let counterfactual_address = get_counterfactual_address(channel.token); let still_on_create_2: U256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(erc20_contract.query( "balanceOf", - H160(*channel.token.as_bytes()), + counterfactual_address, None, Options::default(), None, diff --git a/primitives/src/channel_validator.rs b/primitives/src/channel_validator.rs index 2e0eb6c04..6bd8a2d10 100644 --- a/primitives/src/channel_validator.rs +++ b/primitives/src/channel_validator.rs @@ -104,5 +104,5 @@ pub fn asset_listed(channel: &Channel, whitelist: &HashMap) whitelist.is_empty() || whitelist .keys() - .any(|allowed| &allowed.to_string() == &channel.deposit_asset) + .any(|allowed| allowed.to_string() == channel.deposit_asset) } From 5b69723d139a6f6c4c6e7639a3a13b7a7f1f5ecb Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Wed, 14 Apr 2021 19:33:58 +0300 Subject: [PATCH 26/60] fix merge issues --- Cargo.lock | 8 ++++---- primitives/src/campaign.rs | 16 ---------------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1aae834d..78a311c2b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -949,10 +949,10 @@ dependencies = [ "async-trait", "config", "deadpool", - "futures 0.3.12", + "futures 0.3.13", "log", "serde", - "tokio 1.0.2", + "tokio 1.3.0", "tokio-postgres 0.7.0", ] @@ -2853,7 +2853,7 @@ dependencies = [ "thiserror", "time", "tiny-keccak 2.0.2", - "tokio 1.0.2", + "tokio 1.3.0", "tokio-postgres 0.7.0", "toml", "url", @@ -4312,7 +4312,7 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ - "getrandom 0.2.1", + "getrandom 0.2.2", ] [[package]] diff --git a/primitives/src/campaign.rs b/primitives/src/campaign.rs index e0b6fc625..75ed6c9fc 100644 --- a/primitives/src/campaign.rs +++ b/primitives/src/campaign.rs @@ -183,22 +183,6 @@ pub struct Campaign { pub active: Active, } -#[derive(Debug, Serialize, Deserialize)] -pub struct Active { - #[serde( - default, - skip_serializing_if = "Option::is_none", - with = "ts_milliseconds_option" - )] - pub from: Option>, - /// A millisecond timestamp of when the campaign should enter a withdraw period - /// (no longer accept any events other than CHANNEL_CLOSE) - /// A sane value should be lower than channel.validUntil * 1000 and higher than created - /// It's recommended to set this at least one month prior to channel.validUntil * 1000 - #[serde(with = "ts_milliseconds")] - pub to: DateTime, -} - impl Campaign { /// Matches the Channel.leader to the Campaign.spec.leader /// If they match it returns `Some`, otherwise, it returns `None` From 452bef98aea22588eeefbeb9628a0f8e6d9925d5 Mon Sep 17 00:00:00 2001 From: simzzz Date: Thu, 15 Apr 2021 15:29:48 +0300 Subject: [PATCH 27/60] changes to the dummy adapter --- adapter/src/dummy.rs | 125 +++------------------------------------- adapter/src/ethereum.rs | 1 + 2 files changed, 9 insertions(+), 117 deletions(-) diff --git a/adapter/src/dummy.rs b/adapter/src/dummy.rs index 12366a288..0ab6b0543 100644 --- a/adapter/src/dummy.rs +++ b/adapter/src/dummy.rs @@ -1,17 +1,15 @@ use async_trait::async_trait; -use lazy_static::lazy_static; use primitives::{ adapter::{ Adapter, AdapterErrorKind, AdapterResult, Deposit, DummyAdapterOptions, Error as AdapterError, Session, }, - channel_v5::{Channel as ChannelV5, Nonce}, + channel_v5::Channel as ChannelV5, channel_validator::ChannelValidator, - config::{Config, TokenInfo}, - Address, BigNum, Channel, ChannelId, ToETHChecksum, ValidatorId, + config::Config, + Address, BigNum, Channel, ToETHChecksum, ValidatorId, }; -use std::ops::Add; -use std::{collections::HashMap, convert::TryFrom, fmt}; +use std::{collections::HashMap, fmt}; #[derive(Debug, Clone)] pub struct DummyAdapter { @@ -21,24 +19,6 @@ pub struct DummyAdapter { session_tokens: HashMap, // Auth tokens that we've generated to authenticate with someone (address => token) authorization_tokens: HashMap, - // Generated for retrieving deposit of channel-spender pair - deposits: HashMap<(ChannelId, Address), BigNum>, - // Generated for retrieving balances of tokens - token_balances: HashMap, -} - -lazy_static! { - static ref DUMMY_V5_CHANNEL: ChannelV5 = ChannelV5 { - leader: ValidatorId::try_from("2bdeafae53940669daa6f519373f686c1f3d3393") - .expect("failed to create id"), - follower: ValidatorId::try_from("6704Fbfcd5Ef766B287262fA2281C105d57246a6") - .expect("failed to create id"), - guardian: Address::try_from("0000000000000000000000000000000000000000") - .expect("failed to create address"), - token: Address::try_from("0x73967c6a0904aa032c103b4104747e88c566b1a2") - .expect("should create an address"), - nonce: Nonce::from(12345_u32), - }; } // Enables DummyAdapter to be able to @@ -52,39 +32,10 @@ impl DummyAdapter { config: config.to_owned(), session_tokens: opts.dummy_auth, authorization_tokens: opts.dummy_auth_tokens, - deposits: generate_deposits(), - token_balances: generate_balances(&config.token_address_whitelist), } } } -fn generate_deposits() -> HashMap<(ChannelId, Address), BigNum> { - let mut deposits = HashMap::new(); - deposits.insert( - ( - DUMMY_V5_CHANNEL.id(), - Address::try_from("1111111111111111111111111111111111111111").expect("should generate"), - ), - BigNum::try_from("1000000000000").expect("should make bignum"), - ); - deposits -} - -fn generate_balances(whitelist: &HashMap) -> HashMap { - let mut balances = HashMap::new(); - whitelist.keys().for_each(|k| { - balances.insert( - *k, - whitelist - .get(k) - .unwrap() - .min_token_units_for_deposit - .clone(), - ); - }); - balances -} - #[derive(Debug)] pub struct Error {} impl fmt::Display for Error { @@ -181,72 +132,12 @@ impl Adapter for DummyAdapter { async fn get_deposit( &self, - channel: &ChannelV5, - address: &Address, + _channel: &ChannelV5, + _address: &Address, ) -> AdapterResult { - let mut total = self - .deposits - .get(&(channel.id(), *address)) - .unwrap() - .clone(); - let still_on_create_2 = self.token_balances.get(&channel.token).unwrap().clone(); - let token_info = self - .config - .token_address_whitelist - .get(&channel.token) - .unwrap(); - - if still_on_create_2 > token_info.min_token_units_for_deposit { - total = total.add(still_on_create_2.clone()); - } - Ok(Deposit { - total, - still_on_create_2, + total: BigNum::from(1000000), + still_on_create_2: BigNum::from(0), }) } } - -#[cfg(test)] -mod test { - use super::*; - use primitives::{ - config::configuration, - util::tests::prep_db::{AUTH, IDS}, - }; - use std::convert::TryFrom; - - fn setup_dummy_adapter(dummy_identity: &str) -> DummyAdapter { - let config = configuration("development", None).expect("failed parse config"); - - let options = DummyAdapterOptions { - dummy_identity: ValidatorId::try_from(dummy_identity).expect("should generate id"), - dummy_auth: IDS.clone(), - dummy_auth_tokens: AUTH.clone(), - }; - - DummyAdapter::init(options, &config) - } - - #[tokio::test] - async fn test_dummy_get_deposit() { - let dummy_adapter = setup_dummy_adapter("0000000000000000000000000000000000000000"); - - let spender: Address = Address::try_from("1111111111111111111111111111111111111111") - .expect("should create an address"); - let deposit = dummy_adapter - .get_deposit(&DUMMY_V5_CHANNEL, &spender) - .await - .expect("should get deposit"); - let expected_total = dummy_adapter - .deposits - .get(&(DUMMY_V5_CHANNEL.id(), spender)) - .expect("should get balance"); - assert_eq!(deposit.total, *expected_total); - let expected_on_create_2 = dummy_adapter - .token_balances - .get(&DUMMY_V5_CHANNEL.token) - .expect("should get token"); - assert_eq!(deposit.still_on_create_2, *expected_on_create_2); - } -} diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index e19f587da..d6739cc7b 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -853,6 +853,7 @@ mod test { .execute(token_bytecode, (), leader_account) }) .await; + // deploy contracts let token_contract = tokio_compat_02::FutureExt::compat(token_contract) .await From add80cc404b562d2c576c20da8a8a87722962929 Mon Sep 17 00:00:00 2001 From: simzzz Date: Thu, 15 Apr 2021 15:35:13 +0300 Subject: [PATCH 28/60] Update protocol-eth --- lib/protocol-eth | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protocol-eth b/lib/protocol-eth index 40f2c57fa..4a19c05e2 160000 --- a/lib/protocol-eth +++ b/lib/protocol-eth @@ -1 +1 @@ -Subproject commit 40f2c57fad7aafcd09e15ca99a1513d278e51340 +Subproject commit 4a19c05e27d59a97b24cb2dbd74748ebbab81d08 From 5bb928ae3af36ffdae07ef4714a23d80b9220aa9 Mon Sep 17 00:00:00 2001 From: simzzz Date: Thu, 15 Apr 2021 16:38:08 +0300 Subject: [PATCH 29/60] changes from merge --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1aae834d..78a311c2b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -949,10 +949,10 @@ dependencies = [ "async-trait", "config", "deadpool", - "futures 0.3.12", + "futures 0.3.13", "log", "serde", - "tokio 1.0.2", + "tokio 1.3.0", "tokio-postgres 0.7.0", ] @@ -2853,7 +2853,7 @@ dependencies = [ "thiserror", "time", "tiny-keccak 2.0.2", - "tokio 1.0.2", + "tokio 1.3.0", "tokio-postgres 0.7.0", "toml", "url", @@ -4312,7 +4312,7 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ - "getrandom 0.2.1", + "getrandom 0.2.2", ] [[package]] From eb231acaafe6434552af3f219fb5c635bb448dcb Mon Sep 17 00:00:00 2001 From: simzzz Date: Fri, 16 Apr 2021 18:32:01 +0300 Subject: [PATCH 30/60] fixed salt --- adapter/src/ethereum.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index d6739cc7b..df3ababba 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -93,7 +93,6 @@ impl EthereumAdapter { fn get_counterfactual_address(token: Address) -> H160 { let mut salt: [u8; 32] = [0; 32]; - thread_rng().fill_bytes(&mut salt); let mut init_code = Keccak::new_keccak256(); init_code.update(b"0x00"); let mut hashed_init_code: [u8; 32] = [0; 32]; From 235a105fa4c10830d7d556b89b7bb88241edd1da Mon Sep 17 00:00:00 2001 From: simzzz Date: Fri, 23 Apr 2021 19:40:54 +0300 Subject: [PATCH 31/60] create2 address should be generated successfully right now --- Cargo.lock | 29 +++++++++++++++-- adapter/Cargo.toml | 2 +- adapter/Depositor.bin | 1 + adapter/Sweeper.json | 1 + adapter/src/ethereum.rs | 72 ++++++++++++++++++++++++++++------------- 5 files changed, 79 insertions(+), 26 deletions(-) create mode 100644 adapter/Depositor.bin create mode 100644 adapter/Sweeper.json diff --git a/Cargo.lock b/Cargo.lock index 78a311c2b..b67604634 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,13 +8,13 @@ dependencies = [ "base64 0.10.1", "byteorder 1.4.3", "chrono", + "create2", "eth_checksum", "ethstore", "futures 0.3.13", "hex", "lazy_static", "primitives", - "rand 0.8.3", "reqwest", "serde", "serde-hex", @@ -728,6 +728,16 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" +[[package]] +name = "create2" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e77400797683577a98863496c945600573f30a738651ee5cc047234f9a4cc821" +dependencies = [ + "hex", + "sha3 0.8.2", +] + [[package]] name = "crossbeam-channel" version = "0.5.0" @@ -1089,7 +1099,7 @@ dependencies = [ "hex", "serde", "serde_json", - "sha3", + "sha3 0.9.1", "thiserror", "uint 0.9.0", ] @@ -2206,7 +2216,7 @@ dependencies = [ "generic-array 0.14.4", "multihash-derive", "sha2 0.9.3", - "sha3", + "sha3 0.9.1", "unsigned-varint", ] @@ -3662,6 +3672,19 @@ dependencies = [ "opaque-debug 0.3.0", ] +[[package]] +name = "sha3" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd26bc0e7a2e3a7c959bc494caf58b72ee0c71d67704e9520f736ca7e4853ecf" +dependencies = [ + "block-buffer 0.7.3", + "byte-tools 0.3.1", + "digest 0.8.1", + "keccak", + "opaque-debug 0.2.3", +] + [[package]] name = "sha3" version = "0.9.1" diff --git a/adapter/Cargo.toml b/adapter/Cargo.toml index e017326ea..167d21072 100644 --- a/adapter/Cargo.toml +++ b/adapter/Cargo.toml @@ -18,7 +18,7 @@ web3 = { version = "0.15", features = ["http-tls", "signing"] } eth_checksum = "0.1" tiny-keccak = "1.5" ethstore = { git = "https://github.com/openethereum/openethereum", tag = "v3.1.1-rc.1" } -rand = "^0.8" +create2 = "0.0.2" # API client reqwest = { version = "0.11", features = ["json"] } diff --git a/adapter/Depositor.bin b/adapter/Depositor.bin new file mode 100644 index 000000000..bb609c705 --- /dev/null +++ b/adapter/Depositor.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b5060405161068638038061068683398181016040528101906100329190610327565b6000826060015173ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016100719190610466565b60206040518083038186803b15801561008957600080fd5b505afa15801561009d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100c19190610376565b90506100dc8360600151858361014e60201b6100091760201c565b8373ffffffffffffffffffffffffffffffffffffffff1663db6198a38484846040518463ffffffff1660e01b8152600401610119939291906104ca565b600060405180830381600087803b15801561013357600080fd5b505af1158015610147573d6000803e3d6000fd5b5050505081ff5b8273ffffffffffffffffffffffffffffffffffffffff1663095ea7b383836040518363ffffffff1660e01b8152600401610189929190610481565b600060405180830381600087803b1580156101a357600080fd5b505af11580156101b7573d6000803e3d6000fd5b505050506101c961020d60201b60201c565b610208576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101ff906104aa565b60405180910390fd5b505050565b600080600090503d6000811461022a57602081146102335761023f565b6001915061023f565b60206000803e60005191505b50600081141591505090565b60008151905061025a81610629565b92915050565b60008151905061026f81610640565b92915050565b60008151905061028481610657565b92915050565b600060a0828403121561029c57600080fd5b6102a660a0610501565b905060006102b68482850161024b565b60008301525060206102ca8482850161024b565b60208301525060406102de8482850161024b565b60408301525060606102f28482850161024b565b606083015250608061030684828501610260565b60808301525092915050565b6000815190506103218161066e565b92915050565b600080600060e0848603121561033c57600080fd5b600061034a86828701610275565b935050602061035b8682870161028a565b92505060c061036c8682870161024b565b9150509250925092565b60006020828403121561038857600080fd5b600061039684828501610312565b91505092915050565b6103a881610537565b82525050565b6103b781610537565b82525050565b6103c681610549565b82525050565b60006103d9601983610526565b91506103e482610600565b602082019050919050565b60a082016000820151610405600085018261039f565b506020820151610418602085018261039f565b50604082015161042b604085018261039f565b50606082015161043e606085018261039f565b50608082015161045160808501826103bd565b50505050565b61046081610585565b82525050565b600060208201905061047b60008301846103ae565b92915050565b600060408201905061049660008301856103ae565b6104a36020830184610457565b9392505050565b600060208201905081810360008301526104c3816103cc565b9050919050565b600060e0820190506104df60008301866103ef565b6104ec60a08301856103ae565b6104f960c0830184610457565b949350505050565b600061050b61051c565b9050610517828261058f565b919050565b6000604051905090565b600082825260208201905092915050565b600061054282610565565b9050919050565b6000819050919050565b600061055e82610537565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b610598826105ef565b810181811067ffffffffffffffff821117156105b7576105b66105c0565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f5361666545524332303a20617070726f7665206661696c656400000000000000600082015250565b61063281610537565b811461063d57600080fd5b50565b61064981610549565b811461065457600080fd5b50565b61066081610553565b811461066b57600080fd5b50565b61067781610585565b811461068257600080fd5b5056fe \ No newline at end of file diff --git a/adapter/Sweeper.json b/adapter/Sweeper.json new file mode 100644 index 000000000..c6eb9e018 --- /dev/null +++ b/adapter/Sweeper.json @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"contract OUTPACE","name":"outpace","type":"address"},{"components":[{"internalType":"address","name":"leader","type":"address"},{"internalType":"address","name":"follower","type":"address"},{"internalType":"address","name":"guardian","type":"address"},{"internalType":"address","name":"tokenAddr","type":"address"},{"internalType":"bytes32","name":"nonce","type":"bytes32"}],"internalType":"struct OUTPACE.Channel","name":"channel","type":"tuple"},{"internalType":"address[]","name":"depositors","type":"address[]"}],"name":"sweep","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index df3ababba..48f257ebd 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -1,6 +1,7 @@ use crate::EthereumChannel; use async_trait::async_trait; use chrono::Utc; +use create2::calc_addr; use error::*; use ethstore::{ ethkey::{ @@ -18,7 +19,6 @@ use primitives::{ config::Config, Address, BigNum, Channel, ChannelId, ToETHChecksum, ValidatorId, }; -use rand::{thread_rng, RngCore}; use reqwest::Client; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -27,6 +27,7 @@ use std::{convert::TryFrom, fs}; use tiny_keccak::Keccak; use web3::{ contract::{tokens::Tokenizable, Contract, Options}, + ethabi::{encode, Token}, transports::Http, types::{H160, H256, U256}, Web3, @@ -37,11 +38,14 @@ mod error; lazy_static! { static ref ADEXCORE_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/AdExCore.json"); - // TODO: Fix it once ERC20 and OUTPACE are merged - static ref ERC20_ABI: &'static [u8] = include_bytes!("../ERC20.json"); static ref OUTPACE_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/OUTPACE.json"); static ref CHANNEL_STATE_ACTIVE: U256 = 1.into(); + // TODO: Fix it once ERC20 and OUTPACE are merged + static ref ERC20_ABI: &'static [u8] = include_bytes!("../ERC20.json"); + // TODO: Open PR with those in protocol-eth and sync module once it's ready + static ref SWEEPER_ABI: &'static [u8] = include_bytes!("../Sweeper.json"); + static ref DEPOSITOR_BYTECODE: &'static [u8] = include_bytes!("../Depositor.bin"); } #[derive(Debug, Clone)] @@ -91,22 +95,31 @@ impl EthereumAdapter { } } -fn get_counterfactual_address(token: Address) -> H160 { - let mut salt: [u8; 32] = [0; 32]; - let mut init_code = Keccak::new_keccak256(); - init_code.update(b"0x00"); - let mut hashed_init_code: [u8; 32] = [0; 32]; - init_code.finalize(&mut hashed_init_code); - - let mut result = Keccak::new_keccak256(); - result.update(b"0xff"); - result.update(token.as_bytes()); - result.update(&salt); - result.update(&hashed_init_code); - let mut res: [u8; 20] = [0; 20]; - result.finalize(&mut res); - - H160::from(res) +fn get_counterfactual_address( + sweeper: H160, + channel: &ChannelV5, + outpace: H160, + depositor: &Address, +) -> H160 { + let salt: [u8; 32] = [0; 32]; + let mut init_code: Vec = DEPOSITOR_BYTECODE.to_vec(); + let channel_as_token_vec: Vec = vec![ + Token::Address(channel.leader.as_bytes().into()), + Token::Address(channel.follower.as_bytes().into()), + Token::Address(channel.guardian.as_bytes().into()), + Token::Address(channel.token.as_bytes().into()), + Token::FixedBytes(channel.nonce.to_bytes().to_vec()), + ]; + // TODO: Encode channel too + let mut encoded_params = encode(&[ + Token::Tuple(channel_as_token_vec), + Token::Address(outpace), + Token::Address(H160(*depositor.as_bytes())), + ]) + .to_vec(); + init_code.append(&mut encoded_params); + let address = calc_addr(sweeper.as_fixed_bytes(), &salt, &init_code); + H160::from(address) } #[async_trait] @@ -300,7 +313,7 @@ impl Adapter for EthereumAdapter { async fn get_deposit( &self, channel: &ChannelV5, - address: &Address, + depositor_address: &Address, ) -> AdapterResult { let outpace_contract = Contract::from_json( self.web3.eth(), @@ -313,10 +326,20 @@ impl Adapter for EthereumAdapter { Contract::from_json(self.web3.eth(), channel.token.as_bytes().into(), &ERC20_ABI) .map_err(Error::ContractInitialization)?; + let sweeper_contract = Contract::from_json( + self.web3.eth(), + self.config.ethereum_core_address.into(), //-??? + &SWEEPER_ABI, + ) + .map_err(Error::ContractInitialization)?; + + let sweeper_address = sweeper_contract.address(); + let outpace_address = outpace_contract.address(); + let total: U256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(outpace_contract.query( "deposits", - (*channel.id(), H160(*address.as_bytes())), + (*channel.id(), H160(*depositor_address.as_bytes())), None, Options::default(), None, @@ -328,7 +351,12 @@ impl Adapter for EthereumAdapter { let mut total = BigNum::from_str(&total.to_string())?; - let counterfactual_address = get_counterfactual_address(channel.token); + let counterfactual_address = get_counterfactual_address( + sweeper_address, + channel, + outpace_address, + depositor_address, + ); let still_on_create_2: U256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(erc20_contract.query( "balanceOf", From 015af58ddc43fe1ba12c4a6df51ae9dc8bf9805d Mon Sep 17 00:00:00 2001 From: simzzz Date: Tue, 27 Apr 2021 14:27:21 +0300 Subject: [PATCH 32/60] removed obsolete comment --- adapter/src/ethereum.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 48f257ebd..b1366881f 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -110,7 +110,6 @@ fn get_counterfactual_address( Token::Address(channel.token.as_bytes().into()), Token::FixedBytes(channel.nonce.to_bytes().to_vec()), ]; - // TODO: Encode channel too let mut encoded_params = encode(&[ Token::Tuple(channel_as_token_vec), Token::Address(outpace), From 172fd62e348902e709d3a8eef5f16473af2de8d1 Mon Sep 17 00:00:00 2001 From: simzzz Date: Wed, 28 Apr 2021 15:36:48 +0300 Subject: [PATCH 33/60] Added additional test --- adapter/src/ethereum.rs | 118 +++++++++++++++++++++++++++++++++++----- 1 file changed, 103 insertions(+), 15 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index b1366881f..56b282bed 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -335,20 +335,21 @@ impl Adapter for EthereumAdapter { let sweeper_address = sweeper_contract.address(); let outpace_address = outpace_contract.address(); - let total: U256 = tokio_compat_02::FutureExt::compat(async { - tokio_compat_02::FutureExt::compat(outpace_contract.query( - "deposits", - (*channel.id(), H160(*depositor_address.as_bytes())), - None, - Options::default(), - None, - )) - .await - }) - .await - .map_err(Error::ContractQuerying)?; - - let mut total = BigNum::from_str(&total.to_string())?; + // let total: U256 = tokio_compat_02::FutureExt::compat(async { + // tokio_compat_02::FutureExt::compat(outpace_contract.query( + // "deposits", + // (*channel.id(), H160(*depositor_address.as_bytes())), + // None, + // Options::default(), + // None, + // )) + // .await + // }) + // .await + // .map_err(Error::ContractQuerying)?; + + // let mut total = BigNum::from_str(&total.to_string())?; + let mut total = BigNum::from(0); let counterfactual_address = get_counterfactual_address( sweeper_address, @@ -919,7 +920,7 @@ mod test { .await .expect("should get deposit"); - // TODO: Mock contract output + // TODO: Mock "total" output let expected_deposit = Deposit { total: BigNum::from(0), still_on_create_2: BigNum::from(0), @@ -930,4 +931,91 @@ mod test { expected_deposit.still_on_create_2 ); } + + #[tokio::test] + async fn should_get_correct_deposit_with_left_on_create_2() { + let http = + web3::transports::Http::new("http://localhost:8545").expect("failed to init transport"); + + let web3 = web3::Web3::new(http); + let leader_account: EthAddress = "Df08F82De32B8d460adbE8D72043E3a7e25A3B39" + .parse() + .expect("failed to parse leader account"); + // tokenbytecode.json + let token_bytecode = + include_str!("../test/resources/tokenbytecode.json").trim_end_matches("\n"); + // token_abi.json + let token_abi = include_bytes!("../test/resources/tokenabi.json"); + + // deploy contracts + let token_contract = tokio_compat_02::FutureExt::compat(async { + Contract::deploy(web3.eth(), token_abi) + .expect("invalid token token contract") + .confirmations(0) + .options(Options::with(|opt| { + opt.gas_price = Some(1.into()); + opt.gas = Some(6_721_975.into()); + })) + .execute(token_bytecode, (), leader_account) + }) + .await; + + let token_contract = tokio_compat_02::FutureExt::compat(token_contract) + .await + .expect("Correct parameters are passed to the constructor."); + + let leader = ValidatorId::try_from("2bdeafae53940669daa6f519373f686c1f3d3393") + .expect("failed to create id"); + let follower = ValidatorId::try_from("6704Fbfcd5Ef766B287262fA2281C105d57246a6") + .expect("failed to create id"); + let nonce = Nonce::from(12345_u32); + let guardian: Address = Address::try_from("0000000000000000000000000000000000000000") + .expect("should create an address"); + let token_address = token_contract.address().to_fixed_bytes(); + + let token: Address = Address::from(&token_contract.address().to_fixed_bytes()); + let spender: Address = Address::try_from("0x3d9C9C9673B2E3e9046137E752C5F8dCE823A1bB") + .expect("should create an address"); + let channel_to_pass = ChannelV5 { + leader, + follower, + guardian, + token, + nonce, + }; + + tokio_compat_02::FutureExt::compat(token_contract.call( + "setBalanceTo", + (H160(*spender.as_bytes()), U256::from(10000_u64)), + leader_account, + Options::default(), + )) + .await + .expect("Failed to set balance"); + + let mut eth_adapter = setup_eth_adapter(Some(token_address)); + eth_adapter.config.token_address_whitelist.insert( + token, + TokenInfo { + min_token_units_for_deposit: BigNum::from(1000000), + precision: NonZeroU8::new(18).expect("should create NonZeroU8"), + }, + ); + eth_adapter.unlock().expect("should unlock eth adapter"); + + let deposit = eth_adapter + .get_deposit(&channel_to_pass, &spender) + .await + .expect("should get deposit"); + + let expected_deposit = Deposit { + total: BigNum::from(10000), + still_on_create_2: BigNum::from(10000), + }; + assert_eq!(deposit.total, expected_deposit.total); + assert_eq!( + deposit.still_on_create_2, + expected_deposit.still_on_create_2 + ); + } } From 8c92f0113958d162069da8cd526ab71f72e900dd Mon Sep 17 00:00:00 2001 From: simzzz Date: Wed, 28 Apr 2021 15:42:11 +0300 Subject: [PATCH 34/60] uncommented code that was commented out while testing --- adapter/src/ethereum.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 56b282bed..c8a20c436 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -335,21 +335,20 @@ impl Adapter for EthereumAdapter { let sweeper_address = sweeper_contract.address(); let outpace_address = outpace_contract.address(); - // let total: U256 = tokio_compat_02::FutureExt::compat(async { - // tokio_compat_02::FutureExt::compat(outpace_contract.query( - // "deposits", - // (*channel.id(), H160(*depositor_address.as_bytes())), - // None, - // Options::default(), - // None, - // )) - // .await - // }) - // .await - // .map_err(Error::ContractQuerying)?; - - // let mut total = BigNum::from_str(&total.to_string())?; - let mut total = BigNum::from(0); + let total: U256 = tokio_compat_02::FutureExt::compat(async { + tokio_compat_02::FutureExt::compat(outpace_contract.query( + "deposits", + (*channel.id(), H160(*depositor_address.as_bytes())), + None, + Options::default(), + None, + )) + .await + }) + .await + .map_err(Error::ContractQuerying)?; + + let mut total = BigNum::from_str(&total.to_string())?; let counterfactual_address = get_counterfactual_address( sweeper_address, From ca25335837d75f47f72a00ed6d51d93db6a3b186 Mon Sep 17 00:00:00 2001 From: simzzz Date: Wed, 28 Apr 2021 20:27:22 +0300 Subject: [PATCH 35/60] changes to bytecode files and tests --- adapter/Depositor.bin | 1 - adapter/Depositorbytecode.json | 1 + adapter/OUTPACEbytecode.json | 1 + adapter/Sweeperbytecode.json | 1 + adapter/src/ethereum.rs | 42 +++++++++++++++++++++++++++++++++- 5 files changed, 44 insertions(+), 2 deletions(-) delete mode 100644 adapter/Depositor.bin create mode 100644 adapter/Depositorbytecode.json create mode 100644 adapter/OUTPACEbytecode.json create mode 100644 adapter/Sweeperbytecode.json diff --git a/adapter/Depositor.bin b/adapter/Depositor.bin deleted file mode 100644 index bb609c705..000000000 --- a/adapter/Depositor.bin +++ /dev/null @@ -1 +0,0 @@ -608060405234801561001057600080fd5b5060405161068638038061068683398181016040528101906100329190610327565b6000826060015173ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016100719190610466565b60206040518083038186803b15801561008957600080fd5b505afa15801561009d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100c19190610376565b90506100dc8360600151858361014e60201b6100091760201c565b8373ffffffffffffffffffffffffffffffffffffffff1663db6198a38484846040518463ffffffff1660e01b8152600401610119939291906104ca565b600060405180830381600087803b15801561013357600080fd5b505af1158015610147573d6000803e3d6000fd5b5050505081ff5b8273ffffffffffffffffffffffffffffffffffffffff1663095ea7b383836040518363ffffffff1660e01b8152600401610189929190610481565b600060405180830381600087803b1580156101a357600080fd5b505af11580156101b7573d6000803e3d6000fd5b505050506101c961020d60201b60201c565b610208576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101ff906104aa565b60405180910390fd5b505050565b600080600090503d6000811461022a57602081146102335761023f565b6001915061023f565b60206000803e60005191505b50600081141591505090565b60008151905061025a81610629565b92915050565b60008151905061026f81610640565b92915050565b60008151905061028481610657565b92915050565b600060a0828403121561029c57600080fd5b6102a660a0610501565b905060006102b68482850161024b565b60008301525060206102ca8482850161024b565b60208301525060406102de8482850161024b565b60408301525060606102f28482850161024b565b606083015250608061030684828501610260565b60808301525092915050565b6000815190506103218161066e565b92915050565b600080600060e0848603121561033c57600080fd5b600061034a86828701610275565b935050602061035b8682870161028a565b92505060c061036c8682870161024b565b9150509250925092565b60006020828403121561038857600080fd5b600061039684828501610312565b91505092915050565b6103a881610537565b82525050565b6103b781610537565b82525050565b6103c681610549565b82525050565b60006103d9601983610526565b91506103e482610600565b602082019050919050565b60a082016000820151610405600085018261039f565b506020820151610418602085018261039f565b50604082015161042b604085018261039f565b50606082015161043e606085018261039f565b50608082015161045160808501826103bd565b50505050565b61046081610585565b82525050565b600060208201905061047b60008301846103ae565b92915050565b600060408201905061049660008301856103ae565b6104a36020830184610457565b9392505050565b600060208201905081810360008301526104c3816103cc565b9050919050565b600060e0820190506104df60008301866103ef565b6104ec60a08301856103ae565b6104f960c0830184610457565b949350505050565b600061050b61051c565b9050610517828261058f565b919050565b6000604051905090565b600082825260208201905092915050565b600061054282610565565b9050919050565b6000819050919050565b600061055e82610537565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b610598826105ef565b810181811067ffffffffffffffff821117156105b7576105b66105c0565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f5361666545524332303a20617070726f7665206661696c656400000000000000600082015250565b61063281610537565b811461063d57600080fd5b50565b61064981610549565b811461065457600080fd5b50565b61066081610553565b811461066b57600080fd5b50565b61067781610585565b811461068257600080fd5b5056fe \ No newline at end of file diff --git a/adapter/Depositorbytecode.json b/adapter/Depositorbytecode.json new file mode 100644 index 000000000..b3d3433a6 --- /dev/null +++ b/adapter/Depositorbytecode.json @@ -0,0 +1 @@ +"608060405234801561001057600080fd5b5060405161068638038061068683398181016040528101906100329190610327565b6000826060015173ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016100719190610466565b60206040518083038186803b15801561008957600080fd5b505afa15801561009d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100c19190610376565b90506100dc8360600151858361014e60201b6100091760201c565b8373ffffffffffffffffffffffffffffffffffffffff1663db6198a38484846040518463ffffffff1660e01b8152600401610119939291906104ca565b600060405180830381600087803b15801561013357600080fd5b505af1158015610147573d6000803e3d6000fd5b5050505081ff5b8273ffffffffffffffffffffffffffffffffffffffff1663095ea7b383836040518363ffffffff1660e01b8152600401610189929190610481565b600060405180830381600087803b1580156101a357600080fd5b505af11580156101b7573d6000803e3d6000fd5b505050506101c961020d60201b60201c565b610208576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101ff906104aa565b60405180910390fd5b505050565b600080600090503d6000811461022a57602081146102335761023f565b6001915061023f565b60206000803e60005191505b50600081141591505090565b60008151905061025a81610629565b92915050565b60008151905061026f81610640565b92915050565b60008151905061028481610657565b92915050565b600060a0828403121561029c57600080fd5b6102a660a0610501565b905060006102b68482850161024b565b60008301525060206102ca8482850161024b565b60208301525060406102de8482850161024b565b60408301525060606102f28482850161024b565b606083015250608061030684828501610260565b60808301525092915050565b6000815190506103218161066e565b92915050565b600080600060e0848603121561033c57600080fd5b600061034a86828701610275565b935050602061035b8682870161028a565b92505060c061036c8682870161024b565b9150509250925092565b60006020828403121561038857600080fd5b600061039684828501610312565b91505092915050565b6103a881610537565b82525050565b6103b781610537565b82525050565b6103c681610549565b82525050565b60006103d9601983610526565b91506103e482610600565b602082019050919050565b60a082016000820151610405600085018261039f565b506020820151610418602085018261039f565b50604082015161042b604085018261039f565b50606082015161043e606085018261039f565b50608082015161045160808501826103bd565b50505050565b61046081610585565b82525050565b600060208201905061047b60008301846103ae565b92915050565b600060408201905061049660008301856103ae565b6104a36020830184610457565b9392505050565b600060208201905081810360008301526104c3816103cc565b9050919050565b600060e0820190506104df60008301866103ef565b6104ec60a08301856103ae565b6104f960c0830184610457565b949350505050565b600061050b61051c565b9050610517828261058f565b919050565b6000604051905090565b600082825260208201905092915050565b600061054282610565565b9050919050565b6000819050919050565b600061055e82610537565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b610598826105ef565b810181811067ffffffffffffffff821117156105b7576105b66105c0565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f5361666545524332303a20617070726f7665206661696c656400000000000000600082015250565b61063281610537565b811461063d57600080fd5b50565b61064981610549565b811461065457600080fd5b50565b61066081610553565b811461066b57600080fd5b50565b61067781610585565b811461068257600080fd5b5056fe" \ No newline at end of file diff --git a/adapter/OUTPACEbytecode.json b/adapter/OUTPACEbytecode.json new file mode 100644 index 000000000..1d039a8b5 --- /dev/null +++ b/adapter/OUTPACEbytecode.json @@ -0,0 +1 @@ +"608060405234801561001057600080fd5b50612a98806100206000396000f3fe608060405234801561001057600080fd5b50600436106100b45760003560e01c8063b634dc1a11610071578063b634dc1a1461018b578063b716d6fa146101a7578063bc1ed74c146101d7578063c1e69b6614610207578063db6198a314610237578063f8d682ea14610253576100b4565b8063056036d4146100b957806331c31bba146100d757806343f183e9146100f35780634f1c2c311461010f578063553721c51461013f5780638126e4d21461016f575b600080fd5b6100c161026f565b6040516100ce919061242d565b60405180910390f35b6100f160048036038101906100ec9190611a97565b610276565b005b61010d60048036038101906101089190611be0565b610477565b005b61012960048036038101906101249190611b2c565b6106c9565b604051610136919061242d565b60405180910390f35b61015960048036038101906101549190611b2c565b6106ee565b604051610166919061242d565b60405180910390f35b61018960048036038101906101849190611c31565b610713565b005b6101a560048036038101906101a09190611b68565b61073f565b005b6101c160048036038101906101bc9190611b03565b610971565b6040516101ce91906121b2565b60405180910390f35b6101f160048036038101906101ec9190611b03565b610989565b6040516101fe919061242d565b60405180910390f35b610221600480360381019061021c9190611b03565b6109a1565b60405161022e919061242d565b60405180910390f35b610251600480360381019061024c9190611b91565b6109b9565b005b61026d60048036038101906102689190611b68565b610b89565b005b6203f48081565b600082829050116102bc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102b3906123b2565b60405180910390fd5b600080838360008181106102f9577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b905060200281019061030b919061249f565b60000160600160208101906103209190611a6e565b905060005b8484905081101561042c573685858381811061036a577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b905060200281019061037c919061249f565b90508273ffffffffffffffffffffffffffffffffffffffff168160000160600160208101906103ab9190611a6e565b73ffffffffffffffffffffffffffffffffffffffff1614610401576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f8906123d2565b60405180910390fd5b61040b8882610d80565b84610416919061250e565b9350508080610424906125eb565b915050610325565b503373ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff1614610464578594505b61046f8186846111b0565b505050505050565b60008360405160200161048a9190612412565b6040516020818303038152906040528051906020012090506000806000838152602001908152602001600020549050600081141580156104ea57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8114155b610529576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161052090612292565b60405180910390fd5b6000828260405160200161053e9291906120be565b6040516020818303038152906040528051906020012090506105aa8187600001602081019061056d9190611a6e565b876003806020026040519081016040528092919082600360200280828437600081840152601f19601f820116905080830192505050505050611269565b6105e9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105e0906122d2565b60405180910390fd5b61063d818760200160208101906106009190611a6e565b866003806020026040519081016040528092919082600360200280828437600081840152601f19601f820116905080830192505050505050611269565b61067c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161067390612252565b60405180910390fd5b600080600085815260200190815260200160002081905550827f409a8212a993396d693371967374bdba995ec35612a17f889479a729a19d003660405160405180910390a2505050505050565b6003602052816000526040600020602052806000526040600020600091509150505481565b6002602052816000526040600020602052806000526040600020600091509150505481565b61073c81600001606001602081019061072c9190611a6e565b336107373385610d80565b6111b0565b50565b60008160400160208101906107549190611a6e565b90508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146107c4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107bb906122b2565b60405180910390fd5b6000826040516020016107d79190612412565b60405160208183030381529060405280519060200120905060008060008381526020019081526020016000205490506000811415801561083757507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8114155b610876576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161086d90612292565b60405180910390fd5b8042116108b8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108af90612352565b60405180910390fd5b600060016000848152602001908152602001600020549050600060016000858152602001908152602001600020819055507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6000808581526020019081526020016000208190555061093d8560600160208101906109369190611a6e565b85836111b0565b827fe9a9ab8e37ca2b37117cbb846041a32b8f55a552541bf29fb796ad0afb7d62cf60405160405180910390a25050505050565b60046020528060005260406000206000915090505481565b60016020528060005260406000206000915090505481565b60006020528060005260406000206000915090505481565b6000836040516020016109cc9190612412565b60405160208183030381529060405280519060200120905060008211610a27576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1e90612272565b60405180910390fd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600080838152602001908152602001600020541415610a9c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a9390612232565b60405180910390fd5b81600160008381526020019081526020016000206000828254610abf919061250e565b92505081905550816003600083815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610b26919061250e565b92505081905550610b4b846060016020810190610b439190611a6e565b3330856112ac565b807fa765a94fd33ed0f4ebffd65738fc6efe0c9703f2eedae11f19c264f8e491317783604051610b7b919061242d565b60405180910390a250505050565b806000016020810190610b9c9190611a6e565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161480610c125750806020016020810190610be39190611a6e565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b80610c5a5750806040016020810190610c2b9190611a6e565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b610c99576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c90906123f2565b60405180910390fd5b600081604051602001610cac9190612412565b60405160208183030381529060405280519060200120905060008060008381526020019081526020016000205414610d19576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d1090612392565b60405180910390fd5b60006203f48042610d2a919061250e565b90508060008084815260200190815260200160002081905550817fc1cd86686cbd41c5d91e32e48f9051478b1e4f51084cfe29632ed9d3fdadf23e82604051610d73919061242d565b60405180910390a2505050565b60008082600001604051602001610d979190612412565b60405160208183030381529060405280519060200120905060008060008381526020019081526020016000205490507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811415610e29576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e2090612232565b60405180910390fd5b60008114610e4e578360c0013560046000848152602001908152602001600020819055505b600030838660c00135604051602001610e6993929190612152565b604051602081830303815290604052805190602001209050610edb81866000016000016020810190610e9b9190611a6e565b8760e0016003806020026040519081016040528092919082600360200280828437600081840152601f19601f820116905080830192505050505050611269565b610f1a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f11906122f2565b60405180910390fd5b610f7581866000016020016020810190610f349190611a6e565b87610140016003806020026040519081016040528092919082600360200280828437600081840152601f19601f820116905080830192505050505050611269565b610fb4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fab90612372565b60405180910390fd5b6000868660a00135604051602001610fcd929190612189565b6040516020818303038152906040528051906020012090506110448187806101a00190610ffa9190612448565b80806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050508860c00135611368565b611083576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161107a90612312565b60405180910390fd5b60006002600086815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548760a001356110e59190612564565b90508660a001356002600087815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550806001600087815260200190815260200160002060008282546111639190612564565b92505081905550847fa37d093ea5991ef0b49761069825328a6eb46d0a2a274b55d08fd17ff16d3ec38260405161119a919061242d565b60405180910390a2809550505050505092915050565b8273ffffffffffffffffffffffffffffffffffffffff1663a9059cbb83836040518363ffffffff1660e01b81526004016111eb929190612189565b600060405180830381600087803b15801561120557600080fd5b505af1158015611219573d6000803e3d6000fd5b505050506112256114c5565b611264576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161125b90612332565b60405180910390fd5b505050565b60008273ffffffffffffffffffffffffffffffffffffffff1661128c8584611503565b73ffffffffffffffffffffffffffffffffffffffff161490509392505050565b8373ffffffffffffffffffffffffffffffffffffffff166323b872dd8484846040518463ffffffff1660e01b81526004016112e99392919061211b565b600060405180830381600087803b15801561130357600080fd5b505af1158015611317573d6000803e3d6000fd5b505050506113236114c5565b611362576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161135990612212565b60405180910390fd5b50505050565b60008084905060008451905060005b818110156114b6578581815181106113b8577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200260200101518310156114375782868281518110611401577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015160405160200161141a929190612046565b6040516020818303038152906040528051906020012092506114a3565b858181518110611470577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200260200101518360405160200161148a929190612046565b6040516020818303038152906040528051906020012092505b80806114ae906125eb565b915050611377565b50838214925050509392505050565b600080600090503d600081146114e257602081146114eb576114f7565b600191506114f7565b60206000803e60005191505b50600081141591505090565b60008082600060038110611540577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002015160006020811061157e577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b1a60f81b60f81c60ff1660048111156115c0577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b9050600060048111156115fc577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b816004811115611635577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b141561164557600091505061198a565b600083600060038110611681577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200201516001602081106116bf577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b1a60f81b60f81c905060026004811115611702577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b82600481111561173b577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b141561176f57846040516020016117529190612072565b6040516020818303038152906040528051906020012094506118ba565b600360048111156117a9577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b8260048111156117e2577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b141561181657846040516020016117f991906120f5565b6040516020818303038152906040528051906020012094506118b9565b60048081111561184f577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b826004811115611888577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b14156118b8578460405160200161189f9190612098565b6040516020818303038152906040528051906020012094505b5b5b60018582866001600381106118f8577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002015187600260038110611937577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200201516040516000815260200160405260405161195994939291906121cd565b6020604051602081039080840390855afa15801561197b573d6000803e3d6000fd5b50505060206040510351925050505b92915050565b60008135905061199f81612a1d565b92915050565b6000819050826020600302820111156119bd57600080fd5b92915050565b60008083601f8401126119d557600080fd5b8235905067ffffffffffffffff8111156119ee57600080fd5b602083019150836020820283011115611a0657600080fd5b9250929050565b600081359050611a1c81612a34565b92915050565b600060a08284031215611a3457600080fd5b81905092915050565b60006101c08284031215611a5057600080fd5b81905092915050565b600081359050611a6881612a4b565b92915050565b600060208284031215611a8057600080fd5b6000611a8e84828501611990565b91505092915050565b60008060008060608587031215611aad57600080fd5b6000611abb87828801611990565b9450506020611acc87828801611990565b935050604085013567ffffffffffffffff811115611ae957600080fd5b611af5878288016119c3565b925092505092959194509250565b600060208284031215611b1557600080fd5b6000611b2384828501611a0d565b91505092915050565b60008060408385031215611b3f57600080fd5b6000611b4d85828601611a0d565b9250506020611b5e85828601611990565b9150509250929050565b600060a08284031215611b7a57600080fd5b6000611b8884828501611a22565b91505092915050565b600080600060e08486031215611ba657600080fd5b6000611bb486828701611a22565b93505060a0611bc586828701611990565b92505060c0611bd686828701611a59565b9150509250925092565b60008060006101608486031215611bf657600080fd5b6000611c0486828701611a22565b93505060a0611c15868287016119a5565b925050610100611c27868287016119a5565b9150509250925092565b600060208284031215611c4357600080fd5b600082013567ffffffffffffffff811115611c5d57600080fd5b611c6984828501611a3d565b91505092915050565b611c7b81612598565b82525050565b611c8a81612598565b82525050565b611c99816125aa565b82525050565b611ca8816125aa565b82525050565b611cbf611cba826125aa565b612634565b82525050565b6000611cd2601c836124d5565b9150611cdd82612677565b601c82019050919050565b6000611cf5601e836124c4565b9150611d00826126a0565b602082019050919050565b6000611d18600e836124c4565b9150611d23826126c9565b602082019050919050565b6000611d3b6014836124c4565b9150611d46826126f2565b602082019050919050565b6000611d5e600a836124c4565b9150611d698261271b565b602082019050919050565b6000611d816016836124c4565b9150611d8c82612744565b602082019050919050565b6000611da4600c836124c4565b9150611daf8261276d565b602082019050919050565b6000611dc76012836124c4565b9150611dd282612796565b602082019050919050565b6000611dea600a836124c4565b9150611df5826127bf565b602082019050919050565b6000611e0d6069836124d5565b9150611e18826127e8565b606982019050919050565b6000611e306016836124c4565b9150611e3b82612883565b602082019050919050565b6000611e53601a836124c4565b9150611e5e826128ac565b602082019050919050565b6000611e766014836124c4565b9150611e81826128d5565b602082019050919050565b6000611e99600c836124c4565b9150611ea4826128fe565b602082019050919050565b6000611ebc6006836124d5565b9150611ec782612927565b600682019050919050565b6000611edf601a836124c4565b9150611eea82612950565b602082019050919050565b6000611f02600e836124c4565b9150611f0d82612979565b602082019050919050565b6000611f256013836124c4565b9150611f30826129a2565b602082019050919050565b6000611f48601b836124d5565b9150611f53826129cb565b601b82019050919050565b6000611f6b600e836124c4565b9150611f76826129f4565b602082019050919050565b60a08201611f9260008301836124e0565b611f9f6000850182611c72565b50611fad60208301836124e0565b611fba6020850182611c72565b50611fc860408301836124e0565b611fd56040850182611c72565b50611fe360608301836124e0565b611ff06060850182611c72565b50611ffe60808301836124f7565b61200b6080850182611c90565b50505050565b61201a816125d4565b82525050565b61203161202c826125d4565b61263e565b82525050565b612040816125de565b82525050565b60006120528285611cae565b6020820191506120628284611cae565b6020820191508190509392505050565b600061207d82611cc5565b91506120898284611cae565b60208201915081905092915050565b60006120a382611e00565b91506120af8284611cae565b60208201915081905092915050565b60006120c982611eaf565b91506120d58285611cae565b6020820191506120e58284612020565b6020820191508190509392505050565b600061210082611f3b565b915061210c8284611cae565b60208201915081905092915050565b60006060820190506121306000830186611c81565b61213d6020830185611c81565b61214a6040830184612011565b949350505050565b60006060820190506121676000830186611c81565b6121746020830185611c9f565b6121816040830184611c9f565b949350505050565b600060408201905061219e6000830185611c81565b6121ab6020830184612011565b9392505050565b60006020820190506121c76000830184611c9f565b92915050565b60006080820190506121e26000830187611c9f565b6121ef6020830186612037565b6121fc6040830185611c9f565b6122096060830184611c9f565b95945050505050565b6000602082019050818103600083015261222b81611ce8565b9050919050565b6000602082019050818103600083015261224b81611d0b565b9050919050565b6000602082019050818103600083015261226b81611d2e565b9050919050565b6000602082019050818103600083015261228b81611d51565b9050919050565b600060208201905081810360008301526122ab81611d74565b9050919050565b600060208201905081810360008301526122cb81611d97565b9050919050565b600060208201905081810360008301526122eb81611dba565b9050919050565b6000602082019050818103600083015261230b81611ddd565b9050919050565b6000602082019050818103600083015261232b81611e23565b9050919050565b6000602082019050818103600083015261234b81611e46565b9050919050565b6000602082019050818103600083015261236b81611e69565b9050919050565b6000602082019050818103600083015261238b81611e8c565b9050919050565b600060208201905081810360008301526123ab81611ed2565b9050919050565b600060208201905081810360008301526123cb81611ef5565b9050919050565b600060208201905081810360008301526123eb81611f18565b9050919050565b6000602082019050818103600083015261240b81611f5e565b9050919050565b600060a0820190506124276000830184611f81565b92915050565b60006020820190506124426000830184612011565b92915050565b6000808335600160200384360303811261246157600080fd5b80840192508235915067ffffffffffffffff82111561247f57600080fd5b60208301925060208202360383131561249757600080fd5b509250929050565b6000823560016101c0038336030381126124b857600080fd5b80830191505092915050565b600082825260208201905092915050565b600081905092915050565b60006124ef6020840184611990565b905092915050565b60006125066020840184611a0d565b905092915050565b6000612519826125d4565b9150612524836125d4565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561255957612558612648565b5b828201905092915050565b600061256f826125d4565b915061257a836125d4565b92508282101561258d5761258c612648565b5b828203905092915050565b60006125a3826125b4565b9050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b60006125f6826125d4565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561262957612628612648565b5b600182019050919050565b6000819050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f19457468657265756d205369676e6564204d6573736167653a0a333200000000600082015250565b7f5361666545524332303a207472616e7366657246726f6d206661696c65640000600082015250565b7f4348414e4e454c5f434c4f534544000000000000000000000000000000000000600082015250565b7f494e56414c49445f464f4c4c4f5745525f534947000000000000000000000000600082015250565b7f4e4f5f4445504f53495400000000000000000000000000000000000000000000600082015250565b7f4348414e4e454c5f4e4f545f4348414c4c454e47454400000000000000000000600082015250565b7f4e4f545f475541524449414e0000000000000000000000000000000000000000600082015250565b7f494e56414c49445f4c45414445525f5349470000000000000000000000000000600082015250565b7f4c45414445525f53494700000000000000000000000000000000000000000000600082015250565b7f19457468657265756d205369676e6564204d6573736167653a0a31303842792060008201527f7369676e696e672074686973206d6573736167652c20796f752061636b6e6f7760208201527f6c65646765207369676e696e6720616e2041644578206269642077697468207460408201527f686520686173683a0a0000000000000000000000000000000000000000000000606082015250565b7f42414c414e4345524c4541465f4e4f545f464f554e4400000000000000000000600082015250565b7f5361666545524332303a207472616e73666572206661696c6564000000000000600082015250565b7f4348414e4e454c5f4e4f545f434c4f5341424c45000000000000000000000000600082015250565b7f464f4c4c4f5745525f5349470000000000000000000000000000000000000000600082015250565b7f726573756d650000000000000000000000000000000000000000000000000000600082015250565b7f4348414e4e454c5f414c52454144595f4348414c4c454e474544000000000000600082015250565b7f4e4f5f5749544844524157414c53000000000000000000000000000000000000600082015250565b7f4d5553545f5553455f53414d455f544f4b454e00000000000000000000000000600082015250565b7f19457468657265756d205369676e6564204d6573736167653a0a200000000000600082015250565b7f4e4f545f415554484f52495a4544000000000000000000000000000000000000600082015250565b612a2681612598565b8114612a3157600080fd5b50565b612a3d816125aa565b8114612a4857600080fd5b50565b612a54816125d4565b8114612a5f57600080fd5b5056fea26469706673582212203206d965bbe6adf9cfd6de5e9647eeb0436628bde391f9c50785bfa81071d34564736f6c63430008020033" \ No newline at end of file diff --git a/adapter/Sweeperbytecode.json b/adapter/Sweeperbytecode.json new file mode 100644 index 000000000..218e4a2b9 --- /dev/null +++ b/adapter/Sweeperbytecode.json @@ -0,0 +1 @@ +"608060405234801561001057600080fd5b50610cc8806100206000396000f3fe60806040523480156200001157600080fd5b50600436106200002e5760003560e01c8063a41283ff1462000033575b600080fd5b6200005160048036038101906200004b91906200028d565b62000053565b005b60005b8151811015620000fd576000801b8484848481518110620000a0577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6020026020010151604051620000b69062000103565b620000c493929190620003b2565b8190604051809103906000f5905080158015620000e5573d6000803e3d6000fd5b50508080620000f49062000501565b91505062000056565b50505050565b610686806200060d83390190565b600062000128620001228462000418565b620003ef565b905080838252602082019050828560208602820111156200014857600080fd5b60005b858110156200017c578162000161888262000186565b8452602084019350602083019250506001810190506200014b565b5050509392505050565b6000813590506200019781620005be565b92915050565b600082601f830112620001af57600080fd5b8135620001c184826020860162000111565b91505092915050565b600081359050620001db81620005d8565b92915050565b600081359050620001f281620005f2565b92915050565b600060a082840312156200020b57600080fd5b6200021760a0620003ef565b90506000620002298482850162000186565b60008301525060206200023f8482850162000186565b6020830152506040620002558482850162000186565b60408301525060606200026b8482850162000186565b60608301525060806200028184828501620001ca565b60808301525092915050565b600080600060e08486031215620002a357600080fd5b6000620002b386828701620001e1565b9350506020620002c686828701620001f8565b92505060c084013567ffffffffffffffff811115620002e457600080fd5b620002f2868287016200019d565b9150509250925092565b620003078162000447565b82525050565b620003188162000447565b82525050565b62000329816200045b565b82525050565b6200033a81620004a3565b82525050565b60a082016000820151620003586000850182620002fc565b5060208201516200036d6020850182620002fc565b506040820151620003826040850182620002fc565b506060820151620003976060850182620002fc565b506080820151620003ac60808501826200031e565b50505050565b600060e082019050620003c960008301866200032f565b620003d8602083018562000340565b620003e760c08301846200030d565b949350505050565b6000620003fb6200040e565b9050620004098282620004cb565b919050565b6000604051905090565b600067ffffffffffffffff8211156200043657620004356200057e565b5b602082029050602081019050919050565b6000620004548262000479565b9050919050565b6000819050919050565b6000620004728262000447565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000620004b082620004b7565b9050919050565b6000620004c48262000479565b9050919050565b620004d682620005ad565b810181811067ffffffffffffffff82111715620004f857620004f76200057e565b5b80604052505050565b60006200050e8262000499565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156200054457620005436200054f565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b620005c98162000447565b8114620005d557600080fd5b50565b620005e3816200045b565b8114620005ef57600080fd5b50565b620005fd8162000465565b81146200060957600080fd5b5056fe608060405234801561001057600080fd5b5060405161068638038061068683398181016040528101906100329190610327565b6000826060015173ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016100719190610466565b60206040518083038186803b15801561008957600080fd5b505afa15801561009d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100c19190610376565b90506100dc8360600151858361014e60201b6100091760201c565b8373ffffffffffffffffffffffffffffffffffffffff1663db6198a38484846040518463ffffffff1660e01b8152600401610119939291906104ca565b600060405180830381600087803b15801561013357600080fd5b505af1158015610147573d6000803e3d6000fd5b5050505081ff5b8273ffffffffffffffffffffffffffffffffffffffff1663095ea7b383836040518363ffffffff1660e01b8152600401610189929190610481565b600060405180830381600087803b1580156101a357600080fd5b505af11580156101b7573d6000803e3d6000fd5b505050506101c961020d60201b60201c565b610208576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101ff906104aa565b60405180910390fd5b505050565b600080600090503d6000811461022a57602081146102335761023f565b6001915061023f565b60206000803e60005191505b50600081141591505090565b60008151905061025a81610629565b92915050565b60008151905061026f81610640565b92915050565b60008151905061028481610657565b92915050565b600060a0828403121561029c57600080fd5b6102a660a0610501565b905060006102b68482850161024b565b60008301525060206102ca8482850161024b565b60208301525060406102de8482850161024b565b60408301525060606102f28482850161024b565b606083015250608061030684828501610260565b60808301525092915050565b6000815190506103218161066e565b92915050565b600080600060e0848603121561033c57600080fd5b600061034a86828701610275565b935050602061035b8682870161028a565b92505060c061036c8682870161024b565b9150509250925092565b60006020828403121561038857600080fd5b600061039684828501610312565b91505092915050565b6103a881610537565b82525050565b6103b781610537565b82525050565b6103c681610549565b82525050565b60006103d9601983610526565b91506103e482610600565b602082019050919050565b60a082016000820151610405600085018261039f565b506020820151610418602085018261039f565b50604082015161042b604085018261039f565b50606082015161043e606085018261039f565b50608082015161045160808501826103bd565b50505050565b61046081610585565b82525050565b600060208201905061047b60008301846103ae565b92915050565b600060408201905061049660008301856103ae565b6104a36020830184610457565b9392505050565b600060208201905081810360008301526104c3816103cc565b9050919050565b600060e0820190506104df60008301866103ef565b6104ec60a08301856103ae565b6104f960c0830184610457565b949350505050565b600061050b61051c565b9050610517828261058f565b919050565b6000604051905090565b600082825260208201905092915050565b600061054282610565565b9050919050565b6000819050919050565b600061055e82610537565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b610598826105ef565b810181811067ffffffffffffffff821117156105b7576105b66105c0565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f5361666545524332303a20617070726f7665206661696c656400000000000000600082015250565b61063281610537565b811461063d57600080fd5b50565b61064981610549565b811461065457600080fd5b50565b61066081610553565b811461066b57600080fd5b50565b61067781610585565b811461068257600080fd5b5056fea2646970667358221220c291867c98021a3783a6b51efea938b9305c29a5c9b6723b70d4e8f1190f9bde64736f6c63430008020033" \ No newline at end of file diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index c8a20c436..548f55e8e 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -45,7 +45,7 @@ lazy_static! { static ref ERC20_ABI: &'static [u8] = include_bytes!("../ERC20.json"); // TODO: Open PR with those in protocol-eth and sync module once it's ready static ref SWEEPER_ABI: &'static [u8] = include_bytes!("../Sweeper.json"); - static ref DEPOSITOR_BYTECODE: &'static [u8] = include_bytes!("../Depositor.bin"); + static ref DEPOSITOR_BYTECODE: &'static [u8] = include_bytes!("../Depositorbytecode.json"); } #[derive(Debug, Clone)] @@ -943,6 +943,10 @@ mod test { // tokenbytecode.json let token_bytecode = include_str!("../test/resources/tokenbytecode.json").trim_end_matches("\n"); + // Outpacebytecode.json + let outpace_bytecode = include_str!("../OUTPACEbytecode.json").trim_end_matches("\n"); + // Sweeperbytecode.json + let sweeper_bytecode = include_str!("../Sweeperbytecode.json").trim_end_matches("\n"); // token_abi.json let token_abi = include_bytes!("../test/resources/tokenabi.json"); @@ -963,6 +967,35 @@ mod test { .await .expect("Correct parameters are passed to the constructor."); + let sweeper_contract = tokio_compat_02::FutureExt::compat(async { + Contract::deploy(web3.eth(), &SWEEPER_ABI) + .expect("invalid sweeper contract") + .confirmations(0) + .options(Options::default()) + .execute(sweeper_bytecode, (), leader_account) + }) + .await; + + let sweeper_contract = tokio_compat_02::FutureExt::compat(sweeper_contract) + .await + .expect("Correct parameters are passed to the constructor."); + + let outpace_contract = tokio_compat_02::FutureExt::compat(async { + Contract::deploy(web3.eth(), &OUTPACE_ABI) + .expect("invalid outpace contract") + .confirmations(0) + .options(Options::default()) + .execute(outpace_bytecode, (), leader_account) + }) + .await; + + let outpace_contract = tokio_compat_02::FutureExt::compat(outpace_contract) + .await + .expect("Correct parameters are passed to the constructor."); + + let outpace_address = outpace_contract.address(); + let sweeper_address = sweeper_contract.address(); + let leader = ValidatorId::try_from("2bdeafae53940669daa6f519373f686c1f3d3393") .expect("failed to create id"); let follower = ValidatorId::try_from("6704Fbfcd5Ef766B287262fA2281C105d57246a6") @@ -1002,6 +1035,13 @@ mod test { ); eth_adapter.unlock().expect("should unlock eth adapter"); + let counterfactual_address = get_counterfactual_address( + sweeper_address, + &channel_to_pass, + outpace_address, + &spender, + ); + let deposit = eth_adapter .get_deposit(&channel_to_pass, &spender) .await From fc5d58e5b5422225aef4eb4193807e1174b136a1 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Wed, 5 May 2021 19:01:40 +0300 Subject: [PATCH 36/60] scripts - ethereum - ganache-cli - setup accs with priv keys --- scripts/ethereum/ganache-cli.sh | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/scripts/ethereum/ganache-cli.sh b/scripts/ethereum/ganache-cli.sh index 525ef5859..f20c1153a 100755 --- a/scripts/ethereum/ganache-cli.sh +++ b/scripts/ethereum/ganache-cli.sh @@ -2,14 +2,17 @@ # We use shell (`/bin/sh`) since the Docker image doesn't contain `/bin/bash` # runs in Docker, so leave default port and export it instead of setting it up here + +# Address 0: 0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39 +# Address 1: 0x5a04A8fB90242fB7E1db7d1F51e268A03b7f93A5 +# Address 2: 0xe3896ebd3F32092AFC7D27e9ef7b67E26C49fB02 +# Address 3: 0x0E45891a570Af9e5A962F181C219468A6C9EB4e1 +# Address 4: 0x8c4B95383a46D30F056aCe085D8f453fCF4Ed66d +# Address 5: 0x1059B025E3F8b8f76A8120D6D6Fd9fBa172c80b8 node /app/ganache-core.docker.cli.js --gasLimit 0xfffffffffffff \ - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200,9000000000000000000000000000" \ - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501201,9000000000000000000000000000" \ - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501202,9000000000000000000000000000" \ - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501203,9000000000000000000000000000" \ - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501204,9000000000000000000000000000" \ - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501205,9000000000000000000000000000" \ - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501206,9000000000000000000000000000" \ - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501207,9000000000000000000000000000" \ - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501208,9000000000000000000000000000" \ - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501209,9000000000000000000000000000" + --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200,9000000000000000000000000000" \ + --account="0xd66ecc35fe42ae2063888bfd11c4573db08bdbd5c2b9b835deef05beb43b407f,9000000000000000000000000000" \ + --account="0x1d00a65debb6143cebc3b48b11db2ddfa81411c1f7c443f706d4f2bd8145ee4a,9000000000000000000000000000" \ + --account="0x30e87297872f658845b755fe9e5ff319605a2513177a871110e25aebfe115f0f,9000000000000000000000000000" \ + --account="0xe001626993056febeae724da4cb5c1028a55ac40ce5df4b0c7441d51a843e3fc,9000000000000000000000000000" \ + --account="0xcb5158eccfe180f35d4c05483cfaf3f769210ade3fd1f281737d10d491b5be40,9000000000000000000000000000" \ From 9b905ed18e0cd51bc4ec6efe9ba205398b5c4842 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Mon, 10 May 2021 16:07:41 +0300 Subject: [PATCH 37/60] primitives - Config - add outpace & sweeper addresses - primitives - Config - deprecate ethereum_core_address --- docs/config/dev.toml | 5 +++++ docs/config/prod.toml | 5 +++++ primitives/src/config.rs | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/docs/config/dev.toml b/docs/config/dev.toml index 251a4a463..3ec9f9a98 100644 --- a/docs/config/dev.toml +++ b/docs/config/dev.toml @@ -20,6 +20,11 @@ ip_rate_limit = { type = 'ip', timeframe = 20000 } sid_rate_limit = { type = 'sid', timeframe = 20000 } ethereum_core_address = '0x333420fc6a897356e69b62417cd17ff012177d2b' +# TODO: Replace with real contract address +outpace_address = '0x333420fc6a897356e69b62417cd17ff012177d2b' +# TODO: Replace with real contract address +sweeper_address = '0x333420fc6a897356e69b62417cd17ff012177d2b' + ethereum_network = 'http://localhost:8545' ethereum_adapter_relayer = 'https://goerli-relayer.adex.network' diff --git a/docs/config/prod.toml b/docs/config/prod.toml index d83355722..57e7b8fcb 100644 --- a/docs/config/prod.toml +++ b/docs/config/prod.toml @@ -19,6 +19,11 @@ validator_tick_timeout = 10000 ip_rate_limit = { type = 'ip', timeframe = 1200000 } sid_rate_limit = { type = 'sid', timeframe = 0 } ethereum_core_address = '0x333420fc6a897356e69b62417cd17ff012177d2b' +# TODO: Replace with real contract address +outpace_address = '0x333420fc6a897356e69b62417cd17ff012177d2b' +# TODO: Replace with real contract address +sweeper_address = '0x333420fc6a897356e69b62417cd17ff012177d2b' + ethereum_network = 'http://localhost:8545' ethereum_adapter_relayer = 'https://relayer.adex.network' diff --git a/primitives/src/config.rs b/primitives/src/config.rs index d5b287418..e353c5601 100644 --- a/primitives/src/config.rs +++ b/primitives/src/config.rs @@ -44,8 +44,14 @@ pub struct Config { pub minimal_fee: BigNum, #[serde(deserialize_with = "deserialize_token_whitelist")] pub token_address_whitelist: HashMap, + /// DEPRECATED since this is v4! + #[deprecated(note = "REMOVE, this is V4")] #[serde(with = "SerHex::")] pub ethereum_core_address: [u8; 20], + #[serde(with = "SerHex::")] + pub outpace_address: [u8; 20], + #[serde(with = "SerHex::")] + pub sweeper_address: [u8; 20], pub ethereum_network: String, pub ethereum_adapter_relayer: String, pub validators_whitelist: Vec, From b51619ecdf74669991a44f7cb5014f377a938cf1 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Mon, 10 May 2021 17:12:03 +0300 Subject: [PATCH 38/60] adapter - Ethereum - fix get_deposit & test it - primitives - ChannelId - fn as_bytes - fixed Cargo.lock --- Cargo.lock | 20 +- adapter/src/dummy.rs | 2 +- adapter/src/ethereum.rs | 742 ++++++++---------- .../{tokenabi.json => mock_token_abi.json} | 0 ...bytecode.json => mock_token_bytecode.json} | 0 primitives/src/adapter.rs | 4 +- primitives/src/channel.rs | 6 + 7 files changed, 365 insertions(+), 409 deletions(-) rename adapter/test/resources/{tokenabi.json => mock_token_abi.json} (100%) rename adapter/test/resources/{tokenbytecode.json => mock_token_bytecode.json} (100%) diff --git a/Cargo.lock b/Cargo.lock index 39c868363..4a8c51765 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -928,7 +928,7 @@ dependencies = [ "log", "serde", "tokio 1.3.0", - "tokio-postgres 0.7.0", + "tokio-postgres", ] [[package]] @@ -2676,7 +2676,7 @@ dependencies = [ "fallible-iterator", "futures 0.3.13", "log", - "tokio 1.0.2", + "tokio 1.3.0", "tokio-postgres", ] @@ -2686,9 +2686,9 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d442770e2b1e244bb5eb03b31c79b65bb2568f413b899eaba850fa945a65954" dependencies = [ - "futures 0.3.12", + "futures 0.3.13", "native-tls", - "tokio 1.0.2", + "tokio 1.3.0", "tokio-native-tls", "tokio-postgres", ] @@ -2804,7 +2804,7 @@ dependencies = [ "thiserror", "time", "tiny-keccak 2.0.2", - "tokio 1.0.2", + "tokio 1.3.0", "tokio-postgres", "toml", "url", @@ -3442,7 +3442,7 @@ dependencies = [ "dashmap", "deadpool", "deadpool-postgres", - "futures 0.3.12", + "futures 0.3.13", "hex", "hyper 0.14.4", "lazy_static", @@ -3456,7 +3456,7 @@ dependencies = [ "serde_urlencoded", "slog", "thiserror", - "tokio 1.0.2", + "tokio 1.3.0", "tokio-postgres", ] @@ -3974,8 +3974,8 @@ dependencies = [ "memchr", "mio 0.7.9", "num_cpus", - "pin-project-lite 0.2.4", - "tokio-macros 1.0.0", + "pin-project-lite 0.2.6", + "tokio-macros 1.1.0", ] [[package]] @@ -4039,7 +4039,7 @@ dependencies = [ "parking_lot 0.11.1", "percent-encoding", "phf", - "pin-project-lite 0.2.4", + "pin-project-lite 0.2.6", "postgres-protocol", "postgres-types", "socket2", diff --git a/adapter/src/dummy.rs b/adapter/src/dummy.rs index 0ab6b0543..fbf04950f 100644 --- a/adapter/src/dummy.rs +++ b/adapter/src/dummy.rs @@ -137,7 +137,7 @@ impl Adapter for DummyAdapter { ) -> AdapterResult { Ok(Deposit { total: BigNum::from(1000000), - still_on_create_2: BigNum::from(0), + still_on_create2: BigNum::from(0), }) } } diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 548f55e8e..836974350 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -1,4 +1,3 @@ -use crate::EthereumChannel; use async_trait::async_trait; use chrono::Utc; use create2::calc_addr; @@ -17,37 +16,93 @@ use primitives::{ channel_v5::Channel as ChannelV5, channel_validator::ChannelValidator, config::Config, - Address, BigNum, Channel, ChannelId, ToETHChecksum, ValidatorId, + Address, BigNum, Channel, ToETHChecksum, ValidatorId, }; use reqwest::Client; use serde::{Deserialize, Serialize}; use serde_json::Value; -use std::str::FromStr; -use std::{convert::TryFrom, fs}; +use std::{convert::TryFrom, fs, str::FromStr}; use tiny_keccak::Keccak; use web3::{ - contract::{tokens::Tokenizable, Contract, Options}, + contract::{Contract, Options}, ethabi::{encode, Token}, transports::Http, - types::{H160, H256, U256}, + types::{H160, U256}, Web3, }; +#[cfg(test)] +use test_utils::*; + mod error; lazy_static! { + // TODO: Deprecated! This is v4! static ref ADEXCORE_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/AdExCore.json"); static ref OUTPACE_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/OUTPACE.json"); - static ref CHANNEL_STATE_ACTIVE: U256 = 1.into(); // TODO: Fix it once ERC20 and OUTPACE are merged - static ref ERC20_ABI: &'static [u8] = include_bytes!("../ERC20.json"); + static ref ERC20_ABI: &'static [u8] = include_str!("../ERC20.json").trim_end_matches('\n').as_bytes(); // TODO: Open PR with those in protocol-eth and sync module once it's ready static ref SWEEPER_ABI: &'static [u8] = include_bytes!("../Sweeper.json"); static ref DEPOSITOR_BYTECODE: &'static [u8] = include_bytes!("../Depositorbytecode.json"); } +#[cfg(test)] +mod test_utils { + use lazy_static::lazy_static; + use std::collections::HashMap; + + use primitives::Address; + + // See `adex-eth-protocol` `contracts/mocks/Token.sol` + lazy_static! { + /// Mocked Token ABI + pub static ref MOCK_TOKEN_ABI: &'static [u8] = + include_bytes!("../test/resources/mock_token_abi.json"); + /// Mocked Token bytecode + pub static ref MOCK_TOKEN_BYTECODE: &'static str = + include_str!("../test/resources/mock_token_bytecode.json").trim_end_matches("\n"); + /// Sweeper bytecode + pub static ref SWEEPER_BYTECODE: &'static str = include_str!("../Sweeperbytecode.json").trim_end_matches("\n"); + /// Outpace bytecode + pub static ref OUTPACE_BYTECODE: &'static str = include_str!("../OUTPACEbytecode.json").trim_end_matches("\n"); + pub static ref GANACHE_ADDRESSES: HashMap = { + vec![ + ( + "leader".to_string(), + "0x5a04A8fB90242fB7E1db7d1F51e268A03b7f93A5" + .parse() + .expect("Valid Address"), + ), + ( + "follower".to_string(), + "0xe3896ebd3F32092AFC7D27e9ef7b67E26C49fB02" + .parse() + .expect("Valid Address"), + ), + ( + "creator".to_string(), + "0x0E45891a570Af9e5A962F181C219468A6C9EB4e1" + .parse() + .expect("Valid Address"), + ), + ( + "advertiser".to_string(), + "0x8c4B95383a46D30F056aCe085D8f453fCF4Ed66d" + .parse() + .expect("Valid Address"), + ), + ] + .into_iter() + .collect() + }; + } + + pub const GANACHE_URL: &'static str = "http://localhost:8545"; +} + #[derive(Debug, Clone)] pub struct EthereumAdapter { address: ValidatorId, @@ -95,6 +150,17 @@ impl EthereumAdapter { } } +// TODO: replace with EthChannel when we alter it! +pub fn channel_to_eth_channel(channel: &ChannelV5) -> Vec { + vec![ + Token::Address(channel.leader.as_bytes().into()), + Token::Address(channel.follower.as_bytes().into()), + Token::Address(channel.guardian.as_bytes().into()), + Token::Address(channel.token.as_bytes().into()), + Token::FixedBytes(channel.nonce.to_bytes().to_vec()), + ] +} + fn get_counterfactual_address( sweeper: H160, channel: &ChannelV5, @@ -103,13 +169,8 @@ fn get_counterfactual_address( ) -> H160 { let salt: [u8; 32] = [0; 32]; let mut init_code: Vec = DEPOSITOR_BYTECODE.to_vec(); - let channel_as_token_vec: Vec = vec![ - Token::Address(channel.leader.as_bytes().into()), - Token::Address(channel.follower.as_bytes().into()), - Token::Address(channel.guardian.as_bytes().into()), - Token::Address(channel.token.as_bytes().into()), - Token::FixedBytes(channel.nonce.to_bytes().to_vec()), - ]; + // TODO: Change the EthereumChannel and use it! + let channel_as_token_vec = channel_to_eth_channel(&channel); let mut encoded_params = encode(&[ Token::Tuple(channel_as_token_vec), Token::Address(outpace), @@ -181,56 +242,12 @@ impl Adapter for EthereumAdapter { Ok(verify_address) } + // TODO: Remove async fn validate_channel<'a>( &'a self, - channel: &'a Channel, + _channel: &'a Channel, ) -> AdapterResult { - // check if channel is valid - EthereumAdapter::is_channel_valid(&self.config, self.whoami(), channel) - .map_err(AdapterError::InvalidChannel)?; - - let eth_channel = - EthereumChannel::try_from(channel).map_err(AdapterError::InvalidChannel)?; - - let eth_channel_id = ChannelId::from(eth_channel.hash(&self.config.ethereum_core_address)); - - if eth_channel_id != channel.id { - return Err(AdapterError::Adapter( - Error::InvalidChannelId { - expected: eth_channel_id, - actual: channel.id, - } - .into(), - )); - } - - let contract = Contract::from_json( - self.web3.eth(), - self.config.ethereum_core_address.into(), - &ADEXCORE_ABI, - ) - .map_err(Error::ContractInitialization)?; - - let channel_status: U256 = tokio_compat_02::FutureExt::compat(async { - tokio_compat_02::FutureExt::compat(contract.query( - "states", - H256(*channel.id).into_token(), - None, - Options::default(), - None, - )) - .await - }) - .await - .map_err(Error::ContractQuerying)?; - - if channel_status != *CHANNEL_STATE_ACTIVE { - Err(AdapterError::Adapter( - Error::ChannelInactive(channel.id).into(), - )) - } else { - Ok(true) - } + Ok(true) } /// Creates a `Session` from a provided Token by calling the Contract. @@ -316,7 +333,7 @@ impl Adapter for EthereumAdapter { ) -> AdapterResult { let outpace_contract = Contract::from_json( self.web3.eth(), - self.config.ethereum_core_address.into(), + self.config.outpace_address.into(), &OUTPACE_ABI, ) .map_err(Error::ContractInitialization)?; @@ -327,7 +344,7 @@ impl Adapter for EthereumAdapter { let sweeper_contract = Contract::from_json( self.web3.eth(), - self.config.ethereum_core_address.into(), //-??? + self.config.sweeper_address.into(), &SWEEPER_ABI, ) .map_err(Error::ContractInitialization)?; @@ -335,10 +352,13 @@ impl Adapter for EthereumAdapter { let sweeper_address = sweeper_contract.address(); let outpace_address = outpace_contract.address(); - let total: U256 = tokio_compat_02::FutureExt::compat(async { + let on_outpace: U256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(outpace_contract.query( "deposits", - (*channel.id(), H160(*depositor_address.as_bytes())), + ( + Token::FixedBytes(channel.id().as_bytes().to_vec()), + Token::Address(depositor_address.as_bytes().into()), + ), None, Options::default(), None, @@ -348,7 +368,7 @@ impl Adapter for EthereumAdapter { .await .map_err(Error::ContractQuerying)?; - let mut total = BigNum::from_str(&total.to_string())?; + let on_outpace = BigNum::from_str(&on_outpace.to_string())?; let counterfactual_address = get_counterfactual_address( sweeper_address, @@ -356,7 +376,7 @@ impl Adapter for EthereumAdapter { outpace_address, depositor_address, ); - let still_on_create_2: U256 = tokio_compat_02::FutureExt::compat(async { + let still_on_create2: U256 = tokio_compat_02::FutureExt::compat(async { tokio_compat_02::FutureExt::compat(erc20_contract.query( "balanceOf", counterfactual_address, @@ -369,7 +389,7 @@ impl Adapter for EthereumAdapter { .await .map_err(Error::ContractQuerying)?; - let still_on_create_2: BigNum = still_on_create_2.to_string().parse()?; + let still_on_create2: BigNum = still_on_create2.to_string().parse()?; let token_info = self .config @@ -377,14 +397,20 @@ impl Adapter for EthereumAdapter { .get(&channel.token) .ok_or(Error::TokenNotWhitelisted(channel.token))?; - if still_on_create_2 > token_info.min_token_units_for_deposit { - total += &still_on_create_2; - } + // Count the create2 deposit only if it's > minimum token units configured + let deposit = if still_on_create2 > token_info.min_token_units_for_deposit { + Deposit { + total: &still_on_create2 + &on_outpace, + still_on_create2, + } + } else { + Deposit { + total: on_outpace, + still_on_create2: BigNum::from(0), + } + }; - Ok(Deposit { - total, - still_on_create_2, - }) + Ok(deposit) } } @@ -541,33 +567,50 @@ pub fn ewt_verify( #[cfg(test)] mod test { use super::*; - use crate::EthereumChannel; - use chrono::{Duration, Utc}; - use hex::FromHex; + use chrono::Utc; use primitives::{ adapter::KeystoreOptions, channel_v5::Nonce, config::{configuration, TokenInfo}, - targeting::Rules, - ChannelId, ChannelSpec, EventSubmission, SpecValidators, ValidatorDesc, }; - use std::convert::TryFrom; - use std::num::NonZeroU8; - use web3::types::Address as EthAddress; + use std::{convert::TryFrom, num::NonZeroU8}; + use web3::{ + transports::Http, + types::{Address as EthAddress, H256}, + Web3, + }; use wiremock::{ matchers::{method, path}, Mock, MockServer, ResponseTemplate, }; - fn setup_eth_adapter(contract_address: Option<[u8; 20]>) -> EthereumAdapter { + fn setup_eth_adapter( + sweeper_address: Option<[u8; 20]>, + outpace_address: Option<[u8; 20]>, + token_whitelist: Option<(Address, TokenInfo)>, + ) -> EthereumAdapter { let mut config = configuration("development", None).expect("failed parse config"); let keystore_options = KeystoreOptions { keystore_file: "./test/resources/keystore.json".to_string(), keystore_pwd: "adexvalidator".to_string(), }; - if let Some(ct_address) = contract_address { - config.ethereum_core_address = ct_address; + if let Some(address) = sweeper_address { + config.sweeper_address = address; + } + + if let Some(address) = outpace_address { + config.outpace_address = address; + } + + if let Some((address, token_info)) = token_whitelist { + assert!( + config + .token_address_whitelist + .insert(address, token_info) + .is_none(), + "It should not contain the generated token prior to this call!" + ) } EthereumAdapter::init(keystore_options, &config).expect("should init ethereum adapter") @@ -575,14 +618,14 @@ mod test { #[test] fn should_init_and_unlock_ethereum_adapter() { - let mut eth_adapter = setup_eth_adapter(None); + let mut eth_adapter = setup_eth_adapter(None, None, None); eth_adapter.unlock().expect("should unlock eth adapter"); } #[test] fn should_get_whoami_sign_and_verify_messages() { // whoami - let mut eth_adapter = setup_eth_adapter(None); + let mut eth_adapter = setup_eth_adapter(None, None, None); let whoami = eth_adapter.whoami(); assert_eq!( whoami.to_string(), @@ -629,7 +672,8 @@ mod test { #[test] fn should_generate_correct_ewt_sign_and_verify() { - let mut eth_adapter = setup_eth_adapter(None); + let mut eth_adapter = setup_eth_adapter(None, None, None); + eth_adapter.unlock().expect("should unlock eth adapter"); let payload = Payload { @@ -675,7 +719,7 @@ mod test { let mut identities_owned: HashMap = HashMap::new(); identities_owned.insert(identity, 2); - let mut eth_adapter = setup_eth_adapter(None); + let mut eth_adapter = setup_eth_adapter(None, None, None); Mock::given(method("GET")) .and(path(format!("/identity/by-owner/{}", eth_adapter.whoami()))) @@ -702,359 +746,263 @@ mod test { } #[tokio::test] - async fn should_validate_valid_channel_properly() { - let http = - web3::transports::Http::new("http://localhost:8545").expect("failed to init transport"); - - let web3 = web3::Web3::new(http); - let leader_account: EthAddress = "Df08F82De32B8d460adbE8D72043E3a7e25A3B39" - .parse() - .expect("failed to parse leader account"); - let _follower_account: EthAddress = "6704Fbfcd5Ef766B287262fA2281C105d57246a6" - .parse() - .expect("failed to parse leader account"); - - // tokenbytecode.json - let token_bytecode = - include_str!("../test/resources/tokenbytecode.json").trim_end_matches("\n"); - // token_abi.json - let token_abi = include_bytes!("../test/resources/tokenabi.json"); - // adexbytecode.json - let adex_bytecode = include_str!("../../lib/protocol-eth/resources/bytecode/AdExCore.json") - .trim_end_matches("\n"); + async fn get_deposit_and_count_create2_when_min_tokens_received() { + let web3 = Web3::new(Http::new(&GANACHE_URL).expect("failed to init transport")); + + let leader_account: EthAddress = EthAddress::from(GANACHE_ADDRESSES["leader"].as_bytes()); // deploy contracts - let token_contract = tokio_compat_02::FutureExt::compat(async { - Contract::deploy(web3.eth(), token_abi) - .expect("invalid token token contract") - .confirmations(0) - .options(Options::with(|opt| { - opt.gas_price = Some(1.into()); - opt.gas = Some(6_721_975.into()); - })) - .execute(token_bytecode, (), leader_account) - }) - .await; + let token = deploy_token_contract(&web3, 1_000) + .await + .expect("Correct parameters are passed to the Token constructor."); + let token_address = Address::from_bytes(&token.1.to_fixed_bytes()); - let token_contract = tokio_compat_02::FutureExt::compat(token_contract) + let sweeper = deploy_sweeper_contract(&web3) .await - .expect("Correct parameters are passed to the constructor."); + .expect("Correct parameters are passed to the Sweeper constructor."); - let adex_contract = tokio_compat_02::FutureExt::compat(async { - Contract::deploy(web3.eth(), &ADEXCORE_ABI) - .expect("invalid adex contract") - .confirmations(0) - .options(Options::with(|opt| { - opt.gas_price = Some(1.into()); - opt.gas = Some(6_721_975.into()); - })) - .execute(adex_bytecode, (), leader_account) - }) - .await; - let adex_contract = tokio_compat_02::FutureExt::compat(adex_contract) + let outpace = deploy_outpace_contract(&web3) .await - .expect("Correct parameters are passed to the constructor."); + .expect("Correct parameters are passed to the OUTPACE constructor."); - // contract call set balance - tokio_compat_02::FutureExt::compat(token_contract.call( - "setBalanceTo", - (EthAddress::from(leader_account), U256::from(2000_u64)), - leader_account, - Options::default(), - )) - .await - .expect("Failed to set balance"); - - let leader_validator_desc = ValidatorDesc { - // keystore.json address (same with js) - id: ValidatorId::try_from("2bdeafae53940669daa6f519373f686c1f3d3393") - .expect("failed to create id"), - url: "http://localhost:8005".to_string(), - fee: 100.into(), - fee_addr: None, - }; + let spender = GANACHE_ADDRESSES["creator"]; - let follower_validator_desc = ValidatorDesc { - // keystore2.json address (same with js) - id: ValidatorId::try_from("6704Fbfcd5Ef766B287262fA2281C105d57246a6") - .expect("failed to create id"), - url: "http://localhost:8006".to_string(), - fee: 100.into(), - fee_addr: None, - }; + let channel = get_test_channel(token_address); + + let mut eth_adapter = setup_eth_adapter( + Some(*sweeper.0.as_fixed_bytes()), + Some(*outpace.0.as_fixed_bytes()), + Some((token_address, token.0)), + ); + eth_adapter.unlock().expect("should unlock eth adapter"); - let mut valid_channel = Channel { - // to be replace with the proper id - id: ChannelId::from_hex( - "061d5e2a67d0a9a10f1c732bca12a676d83f79663a396f7d87b3e30b9b411088", + let counterfactual_address = + get_counterfactual_address(sweeper.0, &channel, outpace.0, &spender); + + // No Regular nor Create2 deposit + { + let no_deposits = eth_adapter + .get_deposit(&channel, &spender) + .await + .expect("should get deposit"); + + assert_eq!( + Deposit { + total: BigNum::from(0), + still_on_create2: BigNum::from(0), + }, + no_deposits + ); + } + + // Regular deposit in Outpace without Create2 + { + mock_set_balance( + &token.2, + *GANACHE_ADDRESSES["leader"].as_bytes(), + *spender.as_bytes(), + 10_000_u64, ) - .expect("prep_db: failed to deserialize channel id"), - // leader_account - creator: ValidatorId::try_from("Df08F82De32B8d460adbE8D72043E3a7e25A3B39") - .expect("should be valid ValidatorId"), - deposit_asset: eth_checksum::checksum(&format!("{:?}", token_contract.address())), - deposit_amount: 2_000.into(), - valid_until: Utc::now() + Duration::days(2), - targeting_rules: Rules::new(), - spec: ChannelSpec { - title: None, - validators: SpecValidators::new(leader_validator_desc, follower_validator_desc), - max_per_impression: 10.into(), - min_per_impression: 10.into(), - targeting_rules: Rules::new(), - event_submission: Some(EventSubmission { allow: vec![] }), - created: Utc::now(), - active_from: None, - nonce: None, - withdraw_period_start: Utc::now() + Duration::days(1), - ad_units: vec![], - pricing_bounds: None, - }, - exhausted: Default::default(), - }; + .await + .expect("Failed to set balance"); + + outpace_deposit(&outpace.1, &channel, *spender.as_bytes(), 10_000) + .await + .expect("Should deposit funds"); + + let regular_deposit = eth_adapter + .get_deposit(&channel, &spender) + .await + .expect("should get deposit"); + + assert_eq!( + Deposit { + total: BigNum::from(10_000), + still_on_create2: BigNum::from(0), + }, + regular_deposit + ); + } - // convert to eth channel - let eth_channel = - EthereumChannel::try_from(&valid_channel).expect("failed to create eth channel"); - let sol_tuple = eth_channel.to_solidity_tuple(); + // Deposit with less than minimum token units + { + // Set balance < minimal token units, i.e. `1_000` + mock_set_balance( + &token.2, + leader_account.to_fixed_bytes(), + counterfactual_address.to_fixed_bytes(), + 999_u64, + ) + .await + .expect("Failed to set balance"); + + let deposit_with_create2 = eth_adapter + .get_deposit(&channel, &spender) + .await + .expect("should get deposit"); + + assert_eq!( + Deposit { + total: BigNum::from(10_000), + // tokens are **less** than the minimum tokens required for deposits to count + still_on_create2: BigNum::from(0), + }, + deposit_with_create2 + ); + } - // contract call open channel - tokio_compat_02::FutureExt::compat(adex_contract.call( - "channelOpen", - (sol_tuple,), - leader_account, + // Deposit with less than minimum token units + { + // Set balance > minimal token units + mock_set_balance( + &token.2, + leader_account.to_fixed_bytes(), + counterfactual_address.to_fixed_bytes(), + 1_999_u64, + ) + .await + .expect("Failed to set balance"); + + let deposit_with_create2 = eth_adapter + .get_deposit(&channel, &spender) + .await + .expect("should get deposit"); + + assert_eq!( + Deposit { + total: BigNum::from(11_999), + // tokens are more than the minimum tokens required for deposits to count + still_on_create2: BigNum::from(1_999), + }, + deposit_with_create2 + ); + } + } + + pub fn get_test_channel(token_address: Address) -> ChannelV5 { + ChannelV5 { + leader: ValidatorId::from(&GANACHE_ADDRESSES["leader"]), + follower: ValidatorId::from(&GANACHE_ADDRESSES["follower"]), + guardian: Address::try_from("0000000000000000000000000000000000000000") + .expect("should create an address"), + token: token_address, + nonce: Nonce::from(12345_u32), + } + } + + pub async fn mock_set_balance( + token_contract: &Contract, + from: [u8; 20], + address: [u8; 20], + amount: u64, + ) -> web3::contract::Result { + tokio_compat_02::FutureExt::compat(token_contract.call( + "setBalanceTo", + (H160(address), U256::from(amount)), + H160(from), Options::default(), )) .await - .expect("open channel"); - - let contract_addr = adex_contract.address().to_fixed_bytes(); - let channel_id = eth_channel.hash(&contract_addr); - // set id to proper id - valid_channel.id = ChannelId::from(channel_id); - let token_address = Address::from(&token_contract.address().to_fixed_bytes()); - // eth adapter - let mut eth_adapter = setup_eth_adapter(Some(contract_addr)); - eth_adapter.config.token_address_whitelist.insert( - token_address, - TokenInfo { - min_token_units_for_deposit: BigNum::from(1000000), - precision: NonZeroU8::new(18).expect("should create NonZeroU8"), - }, - ); - eth_adapter.unlock().expect("should unlock eth adapter"); - // validate channel - let result = eth_adapter - .validate_channel(&valid_channel) - .await - .expect("failed to validate channel"); + } - assert!(result, "should validate valid channel correctly"); + pub async fn outpace_deposit( + outpace_contract: &Contract, + channel: &ChannelV5, + to: [u8; 20], + amount: u64, + ) -> web3::contract::Result { + tokio_compat_02::FutureExt::compat(outpace_contract.call( + "deposit", + ( + Token::Tuple(channel_to_eth_channel(channel)), + H160(to), + U256::from(amount), + ), + H160(to), + Options::with(|opt| { + opt.gas_price = Some(1.into()); + // TODO: Check how much should this gas limit be! + opt.gas = Some(61_721_975.into()); + }), + )) + .await } - #[tokio::test] - async fn should_get_correct_deposit() { - let http = - web3::transports::Http::new("http://localhost:8545").expect("failed to init transport"); - - let web3 = web3::Web3::new(http); - let leader_account: EthAddress = "Df08F82De32B8d460adbE8D72043E3a7e25A3B39" - .parse() - .expect("failed to parse leader account"); - // tokenbytecode.json - let token_bytecode = - include_str!("../test/resources/tokenbytecode.json").trim_end_matches("\n"); - // token_abi.json - let token_abi = include_bytes!("../test/resources/tokenabi.json"); + /// Deploys the Sweeper contract from `GANACHE_ADDRESS['leader']` + async fn deploy_sweeper_contract( + web3: &Web3, + ) -> web3::contract::Result<(H160, Contract)> { + let from_leader_account: EthAddress = + EthAddress::from(GANACHE_ADDRESSES["leader"].as_bytes()); - // deploy contracts - let token_contract = tokio_compat_02::FutureExt::compat(async { - Contract::deploy(web3.eth(), token_abi) - .expect("invalid token token contract") + let feature = tokio_compat_02::FutureExt::compat(async { + Contract::deploy(web3.eth(), &SWEEPER_ABI) + .expect("Invalid ABI of Sweeper contract") .confirmations(0) .options(Options::with(|opt| { opt.gas_price = Some(1.into()); opt.gas = Some(6_721_975.into()); })) - .execute(token_bytecode, (), leader_account) + .execute(*SWEEPER_BYTECODE, (), from_leader_account) }) .await; - // deploy contracts - let token_contract = tokio_compat_02::FutureExt::compat(token_contract) - .await - .expect("Correct parameters are passed to the constructor."); - let leader = ValidatorId::try_from("2bdeafae53940669daa6f519373f686c1f3d3393") - .expect("failed to create id"); - let follower = ValidatorId::try_from("6704Fbfcd5Ef766B287262fA2281C105d57246a6") - .expect("failed to create id"); - let nonce = Nonce::from(12345_u32); - let guardian: Address = Address::try_from("0000000000000000000000000000000000000000") - .expect("should create an address"); - let token_address = token_contract.address().to_fixed_bytes(); - - let token: Address = Address::from(&token_contract.address().to_fixed_bytes()); - let spender: Address = Address::try_from("0x3d9C9C9673B2E3e9046137E752C5F8dCE823A1bB") - .expect("should create an address"); - let channel_to_pass = ChannelV5 { - leader, - follower, - guardian, - token, - nonce, - }; - - let mut eth_adapter = setup_eth_adapter(Some(token_address)); - eth_adapter.config.token_address_whitelist.insert( - token, - TokenInfo { - min_token_units_for_deposit: BigNum::from(1000000), - precision: NonZeroU8::new(18).expect("should create NonZeroU8"), - }, - ); - eth_adapter.unlock().expect("should unlock eth adapter"); - - let deposit = eth_adapter - .get_deposit(&channel_to_pass, &spender) - .await - .expect("should get deposit"); + let sweeper_contract = tokio_compat_02::FutureExt::compat(feature).await?; - // TODO: Mock "total" output - let expected_deposit = Deposit { - total: BigNum::from(0), - still_on_create_2: BigNum::from(0), - }; - assert_eq!(deposit.total, expected_deposit.total); - assert_eq!( - deposit.still_on_create_2, - expected_deposit.still_on_create_2 - ); + Ok((sweeper_contract.address(), sweeper_contract)) } - #[tokio::test] - async fn should_get_correct_deposit_with_left_on_create_2() { - let http = - web3::transports::Http::new("http://localhost:8545").expect("failed to init transport"); - - let web3 = web3::Web3::new(http); - let leader_account: EthAddress = "Df08F82De32B8d460adbE8D72043E3a7e25A3B39" - .parse() - .expect("failed to parse leader account"); - // tokenbytecode.json - let token_bytecode = - include_str!("../test/resources/tokenbytecode.json").trim_end_matches("\n"); - // Outpacebytecode.json - let outpace_bytecode = include_str!("../OUTPACEbytecode.json").trim_end_matches("\n"); - // Sweeperbytecode.json - let sweeper_bytecode = include_str!("../Sweeperbytecode.json").trim_end_matches("\n"); - // token_abi.json - let token_abi = include_bytes!("../test/resources/tokenabi.json"); + /// Deploys the Outpace contract from `GANACHE_ADDRESS['leader']` + async fn deploy_outpace_contract( + web3: &Web3, + ) -> web3::contract::Result<(H160, Contract)> { + let from_leader_account: EthAddress = + EthAddress::from(GANACHE_ADDRESSES["leader"].as_bytes()); - // deploy contracts - let token_contract = tokio_compat_02::FutureExt::compat(async { - Contract::deploy(web3.eth(), token_abi) - .expect("invalid token token contract") + let feature = tokio_compat_02::FutureExt::compat(async { + Contract::deploy(web3.eth(), &OUTPACE_ABI) + .expect("Invalid ABI of Sweeper contract") .confirmations(0) .options(Options::with(|opt| { opt.gas_price = Some(1.into()); opt.gas = Some(6_721_975.into()); })) - .execute(token_bytecode, (), leader_account) + .execute(*OUTPACE_BYTECODE, (), from_leader_account) }) .await; - let token_contract = tokio_compat_02::FutureExt::compat(token_contract) - .await - .expect("Correct parameters are passed to the constructor."); - - let sweeper_contract = tokio_compat_02::FutureExt::compat(async { - Contract::deploy(web3.eth(), &SWEEPER_ABI) - .expect("invalid sweeper contract") - .confirmations(0) - .options(Options::default()) - .execute(sweeper_bytecode, (), leader_account) - }) - .await; + let outpace_contract = tokio_compat_02::FutureExt::compat(feature).await?; - let sweeper_contract = tokio_compat_02::FutureExt::compat(sweeper_contract) - .await - .expect("Correct parameters are passed to the constructor."); + Ok((outpace_contract.address(), outpace_contract)) + } - let outpace_contract = tokio_compat_02::FutureExt::compat(async { - Contract::deploy(web3.eth(), &OUTPACE_ABI) - .expect("invalid outpace contract") + /// Deploys the Mock Token contract from `GANACHE_ADDRESS['leader']` + async fn deploy_token_contract( + web3: &Web3, + min_token_units: u64, + ) -> web3::contract::Result<(TokenInfo, H160, Contract)> { + let from_leader_account: EthAddress = + EthAddress::from(GANACHE_ADDRESSES["leader"].as_bytes()); + + let feature = tokio_compat_02::FutureExt::compat(async { + Contract::deploy(web3.eth(), &MOCK_TOKEN_ABI) + .expect("Invalid ABI of Mock Token contract") .confirmations(0) - .options(Options::default()) - .execute(outpace_bytecode, (), leader_account) + .options(Options::with(|opt| { + opt.gas_price = Some(1.into()); + opt.gas = Some(6_721_975.into()); + })) + .execute(*MOCK_TOKEN_BYTECODE, (), from_leader_account) }) .await; - let outpace_contract = tokio_compat_02::FutureExt::compat(outpace_contract) - .await - .expect("Correct parameters are passed to the constructor."); - - let outpace_address = outpace_contract.address(); - let sweeper_address = sweeper_contract.address(); + let token_contract = tokio_compat_02::FutureExt::compat(feature).await?; - let leader = ValidatorId::try_from("2bdeafae53940669daa6f519373f686c1f3d3393") - .expect("failed to create id"); - let follower = ValidatorId::try_from("6704Fbfcd5Ef766B287262fA2281C105d57246a6") - .expect("failed to create id"); - let nonce = Nonce::from(12345_u32); - let guardian: Address = Address::try_from("0000000000000000000000000000000000000000") - .expect("should create an address"); - let token_address = token_contract.address().to_fixed_bytes(); - - let token: Address = Address::from(&token_contract.address().to_fixed_bytes()); - let spender: Address = Address::try_from("0x3d9C9C9673B2E3e9046137E752C5F8dCE823A1bB") - .expect("should create an address"); - let channel_to_pass = ChannelV5 { - leader, - follower, - guardian, - token, - nonce, + let token_info = TokenInfo { + min_token_units_for_deposit: BigNum::from(min_token_units), + precision: NonZeroU8::new(18).expect("should create NonZeroU8"), }; - tokio_compat_02::FutureExt::compat(token_contract.call( - "setBalanceTo", - (H160(*spender.as_bytes()), U256::from(10000_u64)), - leader_account, - Options::default(), - )) - .await - .expect("Failed to set balance"); - - let mut eth_adapter = setup_eth_adapter(Some(token_address)); - eth_adapter.config.token_address_whitelist.insert( - token, - TokenInfo { - min_token_units_for_deposit: BigNum::from(1000000), - precision: NonZeroU8::new(18).expect("should create NonZeroU8"), - }, - ); - eth_adapter.unlock().expect("should unlock eth adapter"); - - let counterfactual_address = get_counterfactual_address( - sweeper_address, - &channel_to_pass, - outpace_address, - &spender, - ); - - let deposit = eth_adapter - .get_deposit(&channel_to_pass, &spender) - .await - .expect("should get deposit"); - - let expected_deposit = Deposit { - total: BigNum::from(10000), - still_on_create_2: BigNum::from(10000), - }; - assert_eq!(deposit.total, expected_deposit.total); - assert_eq!( - deposit.still_on_create_2, - expected_deposit.still_on_create_2 - ); + Ok((token_info, token_contract.address(), token_contract)) } } diff --git a/adapter/test/resources/tokenabi.json b/adapter/test/resources/mock_token_abi.json similarity index 100% rename from adapter/test/resources/tokenabi.json rename to adapter/test/resources/mock_token_abi.json diff --git a/adapter/test/resources/tokenbytecode.json b/adapter/test/resources/mock_token_bytecode.json similarity index 100% rename from adapter/test/resources/tokenbytecode.json rename to adapter/test/resources/mock_token_bytecode.json diff --git a/primitives/src/adapter.rs b/primitives/src/adapter.rs index ca2902226..c31324026 100644 --- a/primitives/src/adapter.rs +++ b/primitives/src/adapter.rs @@ -11,9 +11,10 @@ pub type AdapterResult = Result>; pub trait AdapterErrorKind: fmt::Debug + fmt::Display {} +#[derive(Debug, Eq, PartialEq)] pub struct Deposit { pub total: BigNum, - pub still_on_create_2: BigNum, + pub still_on_create2: BigNum, } #[derive(Debug)] @@ -96,6 +97,7 @@ pub trait Adapter: ChannelValidator + Send + Sync + fmt::Debug + Clone { ) -> AdapterResult; /// Validate a channel + #[deprecated(note = "REMOVE, this is v4! no longer needed")] async fn validate_channel<'a>( &'a self, channel: &'a Channel, diff --git a/primitives/src/channel.rs b/primitives/src/channel.rs index e991fbfd6..507d4060b 100644 --- a/primitives/src/channel.rs +++ b/primitives/src/channel.rs @@ -21,6 +21,12 @@ pub struct ChannelId( [u8; 32], ); +impl ChannelId { + pub fn as_bytes(&self) -> &[u8; 32] { + &self.0 + } +} + impl fmt::Debug for ChannelId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "ChannelId({})", self) From 8182c1c914242e29b65da0fcd06a29ffdf53f34b Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Mon, 10 May 2021 17:12:25 +0300 Subject: [PATCH 39/60] - Address - fix var name --- primitives/src/address.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/primitives/src/address.rs b/primitives/src/address.rs index 8c31a562a..7be07881f 100644 --- a/primitives/src/address.rs +++ b/primitives/src/address.rs @@ -124,9 +124,9 @@ mod de { where D: Deserializer<'de>, { - let validator_id = String::deserialize(deserializer)?; + let address = String::deserialize(deserializer)?; - from_bytes(validator_id, Prefix::Insensitive).map_err(serde::de::Error::custom) + from_bytes(address, Prefix::Insensitive).map_err(serde::de::Error::custom) } } From 8c5bb9bfd4725fe8d841225e108d9b2799cef1af Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Mon, 10 May 2021 17:21:18 +0300 Subject: [PATCH 40/60] git - update protocol-eth submodule --- .gitmodules | 2 +- lib/protocol-eth | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 05dad7482..acb172053 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "lib/protocol-eth"] path = lib/protocol-eth url = https://github.com/AdExNetwork/adex-protocol-eth/ - branch = guardian-separate-claim + branch = master diff --git a/lib/protocol-eth b/lib/protocol-eth index 4a19c05e2..4441aee1d 160000 --- a/lib/protocol-eth +++ b/lib/protocol-eth @@ -1 +1 @@ -Subproject commit 4a19c05e27d59a97b24cb2dbd74748ebbab81d08 +Subproject commit 4441aee1ddea65abebac1d1cd1feef7fbcb2eeb5 From f2b2fa23faaec7e927994543c734d12f0f0a25ca Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Mon, 10 May 2021 17:25:40 +0300 Subject: [PATCH 41/60] adapter - use `protocol-eth` ABI & bytecode paths - adapter - ABI & bytecode files clean up --- adapter/Depositorbytecode.json | 1 - adapter/ERC20.json | 1 - adapter/OUTPACEbytecode.json | 1 - adapter/Sweeper.json | 1 - adapter/Sweeperbytecode.json | 1 - adapter/src/ethereum.rs | 11 +++-------- 6 files changed, 3 insertions(+), 13 deletions(-) delete mode 100644 adapter/Depositorbytecode.json delete mode 100644 adapter/ERC20.json delete mode 100644 adapter/OUTPACEbytecode.json delete mode 100644 adapter/Sweeper.json delete mode 100644 adapter/Sweeperbytecode.json diff --git a/adapter/Depositorbytecode.json b/adapter/Depositorbytecode.json deleted file mode 100644 index b3d3433a6..000000000 --- a/adapter/Depositorbytecode.json +++ /dev/null @@ -1 +0,0 @@ -"608060405234801561001057600080fd5b5060405161068638038061068683398181016040528101906100329190610327565b6000826060015173ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016100719190610466565b60206040518083038186803b15801561008957600080fd5b505afa15801561009d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100c19190610376565b90506100dc8360600151858361014e60201b6100091760201c565b8373ffffffffffffffffffffffffffffffffffffffff1663db6198a38484846040518463ffffffff1660e01b8152600401610119939291906104ca565b600060405180830381600087803b15801561013357600080fd5b505af1158015610147573d6000803e3d6000fd5b5050505081ff5b8273ffffffffffffffffffffffffffffffffffffffff1663095ea7b383836040518363ffffffff1660e01b8152600401610189929190610481565b600060405180830381600087803b1580156101a357600080fd5b505af11580156101b7573d6000803e3d6000fd5b505050506101c961020d60201b60201c565b610208576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101ff906104aa565b60405180910390fd5b505050565b600080600090503d6000811461022a57602081146102335761023f565b6001915061023f565b60206000803e60005191505b50600081141591505090565b60008151905061025a81610629565b92915050565b60008151905061026f81610640565b92915050565b60008151905061028481610657565b92915050565b600060a0828403121561029c57600080fd5b6102a660a0610501565b905060006102b68482850161024b565b60008301525060206102ca8482850161024b565b60208301525060406102de8482850161024b565b60408301525060606102f28482850161024b565b606083015250608061030684828501610260565b60808301525092915050565b6000815190506103218161066e565b92915050565b600080600060e0848603121561033c57600080fd5b600061034a86828701610275565b935050602061035b8682870161028a565b92505060c061036c8682870161024b565b9150509250925092565b60006020828403121561038857600080fd5b600061039684828501610312565b91505092915050565b6103a881610537565b82525050565b6103b781610537565b82525050565b6103c681610549565b82525050565b60006103d9601983610526565b91506103e482610600565b602082019050919050565b60a082016000820151610405600085018261039f565b506020820151610418602085018261039f565b50604082015161042b604085018261039f565b50606082015161043e606085018261039f565b50608082015161045160808501826103bd565b50505050565b61046081610585565b82525050565b600060208201905061047b60008301846103ae565b92915050565b600060408201905061049660008301856103ae565b6104a36020830184610457565b9392505050565b600060208201905081810360008301526104c3816103cc565b9050919050565b600060e0820190506104df60008301866103ef565b6104ec60a08301856103ae565b6104f960c0830184610457565b949350505050565b600061050b61051c565b9050610517828261058f565b919050565b6000604051905090565b600082825260208201905092915050565b600061054282610565565b9050919050565b6000819050919050565b600061055e82610537565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b610598826105ef565b810181811067ffffffffffffffff821117156105b7576105b66105c0565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f5361666545524332303a20617070726f7665206661696c656400000000000000600082015250565b61063281610537565b811461063d57600080fd5b50565b61064981610549565b811461065457600080fd5b50565b61066081610553565b811461066b57600080fd5b50565b61067781610585565b811461068257600080fd5b5056fe" \ No newline at end of file diff --git a/adapter/ERC20.json b/adapter/ERC20.json deleted file mode 100644 index a3de7b8f3..000000000 --- a/adapter/ERC20.json +++ /dev/null @@ -1 +0,0 @@ -[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}] diff --git a/adapter/OUTPACEbytecode.json b/adapter/OUTPACEbytecode.json deleted file mode 100644 index 1d039a8b5..000000000 --- a/adapter/OUTPACEbytecode.json +++ /dev/null @@ -1 +0,0 @@ -"608060405234801561001057600080fd5b50612a98806100206000396000f3fe608060405234801561001057600080fd5b50600436106100b45760003560e01c8063b634dc1a11610071578063b634dc1a1461018b578063b716d6fa146101a7578063bc1ed74c146101d7578063c1e69b6614610207578063db6198a314610237578063f8d682ea14610253576100b4565b8063056036d4146100b957806331c31bba146100d757806343f183e9146100f35780634f1c2c311461010f578063553721c51461013f5780638126e4d21461016f575b600080fd5b6100c161026f565b6040516100ce919061242d565b60405180910390f35b6100f160048036038101906100ec9190611a97565b610276565b005b61010d60048036038101906101089190611be0565b610477565b005b61012960048036038101906101249190611b2c565b6106c9565b604051610136919061242d565b60405180910390f35b61015960048036038101906101549190611b2c565b6106ee565b604051610166919061242d565b60405180910390f35b61018960048036038101906101849190611c31565b610713565b005b6101a560048036038101906101a09190611b68565b61073f565b005b6101c160048036038101906101bc9190611b03565b610971565b6040516101ce91906121b2565b60405180910390f35b6101f160048036038101906101ec9190611b03565b610989565b6040516101fe919061242d565b60405180910390f35b610221600480360381019061021c9190611b03565b6109a1565b60405161022e919061242d565b60405180910390f35b610251600480360381019061024c9190611b91565b6109b9565b005b61026d60048036038101906102689190611b68565b610b89565b005b6203f48081565b600082829050116102bc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102b3906123b2565b60405180910390fd5b600080838360008181106102f9577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b905060200281019061030b919061249f565b60000160600160208101906103209190611a6e565b905060005b8484905081101561042c573685858381811061036a577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b905060200281019061037c919061249f565b90508273ffffffffffffffffffffffffffffffffffffffff168160000160600160208101906103ab9190611a6e565b73ffffffffffffffffffffffffffffffffffffffff1614610401576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f8906123d2565b60405180910390fd5b61040b8882610d80565b84610416919061250e565b9350508080610424906125eb565b915050610325565b503373ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff1614610464578594505b61046f8186846111b0565b505050505050565b60008360405160200161048a9190612412565b6040516020818303038152906040528051906020012090506000806000838152602001908152602001600020549050600081141580156104ea57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8114155b610529576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161052090612292565b60405180910390fd5b6000828260405160200161053e9291906120be565b6040516020818303038152906040528051906020012090506105aa8187600001602081019061056d9190611a6e565b876003806020026040519081016040528092919082600360200280828437600081840152601f19601f820116905080830192505050505050611269565b6105e9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105e0906122d2565b60405180910390fd5b61063d818760200160208101906106009190611a6e565b866003806020026040519081016040528092919082600360200280828437600081840152601f19601f820116905080830192505050505050611269565b61067c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161067390612252565b60405180910390fd5b600080600085815260200190815260200160002081905550827f409a8212a993396d693371967374bdba995ec35612a17f889479a729a19d003660405160405180910390a2505050505050565b6003602052816000526040600020602052806000526040600020600091509150505481565b6002602052816000526040600020602052806000526040600020600091509150505481565b61073c81600001606001602081019061072c9190611a6e565b336107373385610d80565b6111b0565b50565b60008160400160208101906107549190611a6e565b90508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146107c4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107bb906122b2565b60405180910390fd5b6000826040516020016107d79190612412565b60405160208183030381529060405280519060200120905060008060008381526020019081526020016000205490506000811415801561083757507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8114155b610876576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161086d90612292565b60405180910390fd5b8042116108b8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108af90612352565b60405180910390fd5b600060016000848152602001908152602001600020549050600060016000858152602001908152602001600020819055507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6000808581526020019081526020016000208190555061093d8560600160208101906109369190611a6e565b85836111b0565b827fe9a9ab8e37ca2b37117cbb846041a32b8f55a552541bf29fb796ad0afb7d62cf60405160405180910390a25050505050565b60046020528060005260406000206000915090505481565b60016020528060005260406000206000915090505481565b60006020528060005260406000206000915090505481565b6000836040516020016109cc9190612412565b60405160208183030381529060405280519060200120905060008211610a27576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1e90612272565b60405180910390fd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600080838152602001908152602001600020541415610a9c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a9390612232565b60405180910390fd5b81600160008381526020019081526020016000206000828254610abf919061250e565b92505081905550816003600083815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610b26919061250e565b92505081905550610b4b846060016020810190610b439190611a6e565b3330856112ac565b807fa765a94fd33ed0f4ebffd65738fc6efe0c9703f2eedae11f19c264f8e491317783604051610b7b919061242d565b60405180910390a250505050565b806000016020810190610b9c9190611a6e565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161480610c125750806020016020810190610be39190611a6e565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b80610c5a5750806040016020810190610c2b9190611a6e565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b610c99576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c90906123f2565b60405180910390fd5b600081604051602001610cac9190612412565b60405160208183030381529060405280519060200120905060008060008381526020019081526020016000205414610d19576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d1090612392565b60405180910390fd5b60006203f48042610d2a919061250e565b90508060008084815260200190815260200160002081905550817fc1cd86686cbd41c5d91e32e48f9051478b1e4f51084cfe29632ed9d3fdadf23e82604051610d73919061242d565b60405180910390a2505050565b60008082600001604051602001610d979190612412565b60405160208183030381529060405280519060200120905060008060008381526020019081526020016000205490507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811415610e29576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e2090612232565b60405180910390fd5b60008114610e4e578360c0013560046000848152602001908152602001600020819055505b600030838660c00135604051602001610e6993929190612152565b604051602081830303815290604052805190602001209050610edb81866000016000016020810190610e9b9190611a6e565b8760e0016003806020026040519081016040528092919082600360200280828437600081840152601f19601f820116905080830192505050505050611269565b610f1a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f11906122f2565b60405180910390fd5b610f7581866000016020016020810190610f349190611a6e565b87610140016003806020026040519081016040528092919082600360200280828437600081840152601f19601f820116905080830192505050505050611269565b610fb4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fab90612372565b60405180910390fd5b6000868660a00135604051602001610fcd929190612189565b6040516020818303038152906040528051906020012090506110448187806101a00190610ffa9190612448565b80806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050508860c00135611368565b611083576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161107a90612312565b60405180910390fd5b60006002600086815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548760a001356110e59190612564565b90508660a001356002600087815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550806001600087815260200190815260200160002060008282546111639190612564565b92505081905550847fa37d093ea5991ef0b49761069825328a6eb46d0a2a274b55d08fd17ff16d3ec38260405161119a919061242d565b60405180910390a2809550505050505092915050565b8273ffffffffffffffffffffffffffffffffffffffff1663a9059cbb83836040518363ffffffff1660e01b81526004016111eb929190612189565b600060405180830381600087803b15801561120557600080fd5b505af1158015611219573d6000803e3d6000fd5b505050506112256114c5565b611264576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161125b90612332565b60405180910390fd5b505050565b60008273ffffffffffffffffffffffffffffffffffffffff1661128c8584611503565b73ffffffffffffffffffffffffffffffffffffffff161490509392505050565b8373ffffffffffffffffffffffffffffffffffffffff166323b872dd8484846040518463ffffffff1660e01b81526004016112e99392919061211b565b600060405180830381600087803b15801561130357600080fd5b505af1158015611317573d6000803e3d6000fd5b505050506113236114c5565b611362576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161135990612212565b60405180910390fd5b50505050565b60008084905060008451905060005b818110156114b6578581815181106113b8577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200260200101518310156114375782868281518110611401577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015160405160200161141a929190612046565b6040516020818303038152906040528051906020012092506114a3565b858181518110611470577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200260200101518360405160200161148a929190612046565b6040516020818303038152906040528051906020012092505b80806114ae906125eb565b915050611377565b50838214925050509392505050565b600080600090503d600081146114e257602081146114eb576114f7565b600191506114f7565b60206000803e60005191505b50600081141591505090565b60008082600060038110611540577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002015160006020811061157e577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b1a60f81b60f81c60ff1660048111156115c0577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b9050600060048111156115fc577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b816004811115611635577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b141561164557600091505061198a565b600083600060038110611681577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200201516001602081106116bf577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b1a60f81b60f81c905060026004811115611702577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b82600481111561173b577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b141561176f57846040516020016117529190612072565b6040516020818303038152906040528051906020012094506118ba565b600360048111156117a9577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b8260048111156117e2577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b141561181657846040516020016117f991906120f5565b6040516020818303038152906040528051906020012094506118b9565b60048081111561184f577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b826004811115611888577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b14156118b8578460405160200161189f9190612098565b6040516020818303038152906040528051906020012094505b5b5b60018582866001600381106118f8577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002015187600260038110611937577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200201516040516000815260200160405260405161195994939291906121cd565b6020604051602081039080840390855afa15801561197b573d6000803e3d6000fd5b50505060206040510351925050505b92915050565b60008135905061199f81612a1d565b92915050565b6000819050826020600302820111156119bd57600080fd5b92915050565b60008083601f8401126119d557600080fd5b8235905067ffffffffffffffff8111156119ee57600080fd5b602083019150836020820283011115611a0657600080fd5b9250929050565b600081359050611a1c81612a34565b92915050565b600060a08284031215611a3457600080fd5b81905092915050565b60006101c08284031215611a5057600080fd5b81905092915050565b600081359050611a6881612a4b565b92915050565b600060208284031215611a8057600080fd5b6000611a8e84828501611990565b91505092915050565b60008060008060608587031215611aad57600080fd5b6000611abb87828801611990565b9450506020611acc87828801611990565b935050604085013567ffffffffffffffff811115611ae957600080fd5b611af5878288016119c3565b925092505092959194509250565b600060208284031215611b1557600080fd5b6000611b2384828501611a0d565b91505092915050565b60008060408385031215611b3f57600080fd5b6000611b4d85828601611a0d565b9250506020611b5e85828601611990565b9150509250929050565b600060a08284031215611b7a57600080fd5b6000611b8884828501611a22565b91505092915050565b600080600060e08486031215611ba657600080fd5b6000611bb486828701611a22565b93505060a0611bc586828701611990565b92505060c0611bd686828701611a59565b9150509250925092565b60008060006101608486031215611bf657600080fd5b6000611c0486828701611a22565b93505060a0611c15868287016119a5565b925050610100611c27868287016119a5565b9150509250925092565b600060208284031215611c4357600080fd5b600082013567ffffffffffffffff811115611c5d57600080fd5b611c6984828501611a3d565b91505092915050565b611c7b81612598565b82525050565b611c8a81612598565b82525050565b611c99816125aa565b82525050565b611ca8816125aa565b82525050565b611cbf611cba826125aa565b612634565b82525050565b6000611cd2601c836124d5565b9150611cdd82612677565b601c82019050919050565b6000611cf5601e836124c4565b9150611d00826126a0565b602082019050919050565b6000611d18600e836124c4565b9150611d23826126c9565b602082019050919050565b6000611d3b6014836124c4565b9150611d46826126f2565b602082019050919050565b6000611d5e600a836124c4565b9150611d698261271b565b602082019050919050565b6000611d816016836124c4565b9150611d8c82612744565b602082019050919050565b6000611da4600c836124c4565b9150611daf8261276d565b602082019050919050565b6000611dc76012836124c4565b9150611dd282612796565b602082019050919050565b6000611dea600a836124c4565b9150611df5826127bf565b602082019050919050565b6000611e0d6069836124d5565b9150611e18826127e8565b606982019050919050565b6000611e306016836124c4565b9150611e3b82612883565b602082019050919050565b6000611e53601a836124c4565b9150611e5e826128ac565b602082019050919050565b6000611e766014836124c4565b9150611e81826128d5565b602082019050919050565b6000611e99600c836124c4565b9150611ea4826128fe565b602082019050919050565b6000611ebc6006836124d5565b9150611ec782612927565b600682019050919050565b6000611edf601a836124c4565b9150611eea82612950565b602082019050919050565b6000611f02600e836124c4565b9150611f0d82612979565b602082019050919050565b6000611f256013836124c4565b9150611f30826129a2565b602082019050919050565b6000611f48601b836124d5565b9150611f53826129cb565b601b82019050919050565b6000611f6b600e836124c4565b9150611f76826129f4565b602082019050919050565b60a08201611f9260008301836124e0565b611f9f6000850182611c72565b50611fad60208301836124e0565b611fba6020850182611c72565b50611fc860408301836124e0565b611fd56040850182611c72565b50611fe360608301836124e0565b611ff06060850182611c72565b50611ffe60808301836124f7565b61200b6080850182611c90565b50505050565b61201a816125d4565b82525050565b61203161202c826125d4565b61263e565b82525050565b612040816125de565b82525050565b60006120528285611cae565b6020820191506120628284611cae565b6020820191508190509392505050565b600061207d82611cc5565b91506120898284611cae565b60208201915081905092915050565b60006120a382611e00565b91506120af8284611cae565b60208201915081905092915050565b60006120c982611eaf565b91506120d58285611cae565b6020820191506120e58284612020565b6020820191508190509392505050565b600061210082611f3b565b915061210c8284611cae565b60208201915081905092915050565b60006060820190506121306000830186611c81565b61213d6020830185611c81565b61214a6040830184612011565b949350505050565b60006060820190506121676000830186611c81565b6121746020830185611c9f565b6121816040830184611c9f565b949350505050565b600060408201905061219e6000830185611c81565b6121ab6020830184612011565b9392505050565b60006020820190506121c76000830184611c9f565b92915050565b60006080820190506121e26000830187611c9f565b6121ef6020830186612037565b6121fc6040830185611c9f565b6122096060830184611c9f565b95945050505050565b6000602082019050818103600083015261222b81611ce8565b9050919050565b6000602082019050818103600083015261224b81611d0b565b9050919050565b6000602082019050818103600083015261226b81611d2e565b9050919050565b6000602082019050818103600083015261228b81611d51565b9050919050565b600060208201905081810360008301526122ab81611d74565b9050919050565b600060208201905081810360008301526122cb81611d97565b9050919050565b600060208201905081810360008301526122eb81611dba565b9050919050565b6000602082019050818103600083015261230b81611ddd565b9050919050565b6000602082019050818103600083015261232b81611e23565b9050919050565b6000602082019050818103600083015261234b81611e46565b9050919050565b6000602082019050818103600083015261236b81611e69565b9050919050565b6000602082019050818103600083015261238b81611e8c565b9050919050565b600060208201905081810360008301526123ab81611ed2565b9050919050565b600060208201905081810360008301526123cb81611ef5565b9050919050565b600060208201905081810360008301526123eb81611f18565b9050919050565b6000602082019050818103600083015261240b81611f5e565b9050919050565b600060a0820190506124276000830184611f81565b92915050565b60006020820190506124426000830184612011565b92915050565b6000808335600160200384360303811261246157600080fd5b80840192508235915067ffffffffffffffff82111561247f57600080fd5b60208301925060208202360383131561249757600080fd5b509250929050565b6000823560016101c0038336030381126124b857600080fd5b80830191505092915050565b600082825260208201905092915050565b600081905092915050565b60006124ef6020840184611990565b905092915050565b60006125066020840184611a0d565b905092915050565b6000612519826125d4565b9150612524836125d4565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561255957612558612648565b5b828201905092915050565b600061256f826125d4565b915061257a836125d4565b92508282101561258d5761258c612648565b5b828203905092915050565b60006125a3826125b4565b9050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b60006125f6826125d4565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561262957612628612648565b5b600182019050919050565b6000819050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f19457468657265756d205369676e6564204d6573736167653a0a333200000000600082015250565b7f5361666545524332303a207472616e7366657246726f6d206661696c65640000600082015250565b7f4348414e4e454c5f434c4f534544000000000000000000000000000000000000600082015250565b7f494e56414c49445f464f4c4c4f5745525f534947000000000000000000000000600082015250565b7f4e4f5f4445504f53495400000000000000000000000000000000000000000000600082015250565b7f4348414e4e454c5f4e4f545f4348414c4c454e47454400000000000000000000600082015250565b7f4e4f545f475541524449414e0000000000000000000000000000000000000000600082015250565b7f494e56414c49445f4c45414445525f5349470000000000000000000000000000600082015250565b7f4c45414445525f53494700000000000000000000000000000000000000000000600082015250565b7f19457468657265756d205369676e6564204d6573736167653a0a31303842792060008201527f7369676e696e672074686973206d6573736167652c20796f752061636b6e6f7760208201527f6c65646765207369676e696e6720616e2041644578206269642077697468207460408201527f686520686173683a0a0000000000000000000000000000000000000000000000606082015250565b7f42414c414e4345524c4541465f4e4f545f464f554e4400000000000000000000600082015250565b7f5361666545524332303a207472616e73666572206661696c6564000000000000600082015250565b7f4348414e4e454c5f4e4f545f434c4f5341424c45000000000000000000000000600082015250565b7f464f4c4c4f5745525f5349470000000000000000000000000000000000000000600082015250565b7f726573756d650000000000000000000000000000000000000000000000000000600082015250565b7f4348414e4e454c5f414c52454144595f4348414c4c454e474544000000000000600082015250565b7f4e4f5f5749544844524157414c53000000000000000000000000000000000000600082015250565b7f4d5553545f5553455f53414d455f544f4b454e00000000000000000000000000600082015250565b7f19457468657265756d205369676e6564204d6573736167653a0a200000000000600082015250565b7f4e4f545f415554484f52495a4544000000000000000000000000000000000000600082015250565b612a2681612598565b8114612a3157600080fd5b50565b612a3d816125aa565b8114612a4857600080fd5b50565b612a54816125d4565b8114612a5f57600080fd5b5056fea26469706673582212203206d965bbe6adf9cfd6de5e9647eeb0436628bde391f9c50785bfa81071d34564736f6c63430008020033" \ No newline at end of file diff --git a/adapter/Sweeper.json b/adapter/Sweeper.json deleted file mode 100644 index c6eb9e018..000000000 --- a/adapter/Sweeper.json +++ /dev/null @@ -1 +0,0 @@ -[{"inputs":[{"internalType":"contract OUTPACE","name":"outpace","type":"address"},{"components":[{"internalType":"address","name":"leader","type":"address"},{"internalType":"address","name":"follower","type":"address"},{"internalType":"address","name":"guardian","type":"address"},{"internalType":"address","name":"tokenAddr","type":"address"},{"internalType":"bytes32","name":"nonce","type":"bytes32"}],"internalType":"struct OUTPACE.Channel","name":"channel","type":"tuple"},{"internalType":"address[]","name":"depositors","type":"address[]"}],"name":"sweep","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/adapter/Sweeperbytecode.json b/adapter/Sweeperbytecode.json deleted file mode 100644 index 218e4a2b9..000000000 --- a/adapter/Sweeperbytecode.json +++ /dev/null @@ -1 +0,0 @@ -"608060405234801561001057600080fd5b50610cc8806100206000396000f3fe60806040523480156200001157600080fd5b50600436106200002e5760003560e01c8063a41283ff1462000033575b600080fd5b6200005160048036038101906200004b91906200028d565b62000053565b005b60005b8151811015620000fd576000801b8484848481518110620000a0577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6020026020010151604051620000b69062000103565b620000c493929190620003b2565b8190604051809103906000f5905080158015620000e5573d6000803e3d6000fd5b50508080620000f49062000501565b91505062000056565b50505050565b610686806200060d83390190565b600062000128620001228462000418565b620003ef565b905080838252602082019050828560208602820111156200014857600080fd5b60005b858110156200017c578162000161888262000186565b8452602084019350602083019250506001810190506200014b565b5050509392505050565b6000813590506200019781620005be565b92915050565b600082601f830112620001af57600080fd5b8135620001c184826020860162000111565b91505092915050565b600081359050620001db81620005d8565b92915050565b600081359050620001f281620005f2565b92915050565b600060a082840312156200020b57600080fd5b6200021760a0620003ef565b90506000620002298482850162000186565b60008301525060206200023f8482850162000186565b6020830152506040620002558482850162000186565b60408301525060606200026b8482850162000186565b60608301525060806200028184828501620001ca565b60808301525092915050565b600080600060e08486031215620002a357600080fd5b6000620002b386828701620001e1565b9350506020620002c686828701620001f8565b92505060c084013567ffffffffffffffff811115620002e457600080fd5b620002f2868287016200019d565b9150509250925092565b620003078162000447565b82525050565b620003188162000447565b82525050565b62000329816200045b565b82525050565b6200033a81620004a3565b82525050565b60a082016000820151620003586000850182620002fc565b5060208201516200036d6020850182620002fc565b506040820151620003826040850182620002fc565b506060820151620003976060850182620002fc565b506080820151620003ac60808501826200031e565b50505050565b600060e082019050620003c960008301866200032f565b620003d8602083018562000340565b620003e760c08301846200030d565b949350505050565b6000620003fb6200040e565b9050620004098282620004cb565b919050565b6000604051905090565b600067ffffffffffffffff8211156200043657620004356200057e565b5b602082029050602081019050919050565b6000620004548262000479565b9050919050565b6000819050919050565b6000620004728262000447565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000620004b082620004b7565b9050919050565b6000620004c48262000479565b9050919050565b620004d682620005ad565b810181811067ffffffffffffffff82111715620004f857620004f76200057e565b5b80604052505050565b60006200050e8262000499565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156200054457620005436200054f565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b620005c98162000447565b8114620005d557600080fd5b50565b620005e3816200045b565b8114620005ef57600080fd5b50565b620005fd8162000465565b81146200060957600080fd5b5056fe608060405234801561001057600080fd5b5060405161068638038061068683398181016040528101906100329190610327565b6000826060015173ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016100719190610466565b60206040518083038186803b15801561008957600080fd5b505afa15801561009d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100c19190610376565b90506100dc8360600151858361014e60201b6100091760201c565b8373ffffffffffffffffffffffffffffffffffffffff1663db6198a38484846040518463ffffffff1660e01b8152600401610119939291906104ca565b600060405180830381600087803b15801561013357600080fd5b505af1158015610147573d6000803e3d6000fd5b5050505081ff5b8273ffffffffffffffffffffffffffffffffffffffff1663095ea7b383836040518363ffffffff1660e01b8152600401610189929190610481565b600060405180830381600087803b1580156101a357600080fd5b505af11580156101b7573d6000803e3d6000fd5b505050506101c961020d60201b60201c565b610208576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101ff906104aa565b60405180910390fd5b505050565b600080600090503d6000811461022a57602081146102335761023f565b6001915061023f565b60206000803e60005191505b50600081141591505090565b60008151905061025a81610629565b92915050565b60008151905061026f81610640565b92915050565b60008151905061028481610657565b92915050565b600060a0828403121561029c57600080fd5b6102a660a0610501565b905060006102b68482850161024b565b60008301525060206102ca8482850161024b565b60208301525060406102de8482850161024b565b60408301525060606102f28482850161024b565b606083015250608061030684828501610260565b60808301525092915050565b6000815190506103218161066e565b92915050565b600080600060e0848603121561033c57600080fd5b600061034a86828701610275565b935050602061035b8682870161028a565b92505060c061036c8682870161024b565b9150509250925092565b60006020828403121561038857600080fd5b600061039684828501610312565b91505092915050565b6103a881610537565b82525050565b6103b781610537565b82525050565b6103c681610549565b82525050565b60006103d9601983610526565b91506103e482610600565b602082019050919050565b60a082016000820151610405600085018261039f565b506020820151610418602085018261039f565b50604082015161042b604085018261039f565b50606082015161043e606085018261039f565b50608082015161045160808501826103bd565b50505050565b61046081610585565b82525050565b600060208201905061047b60008301846103ae565b92915050565b600060408201905061049660008301856103ae565b6104a36020830184610457565b9392505050565b600060208201905081810360008301526104c3816103cc565b9050919050565b600060e0820190506104df60008301866103ef565b6104ec60a08301856103ae565b6104f960c0830184610457565b949350505050565b600061050b61051c565b9050610517828261058f565b919050565b6000604051905090565b600082825260208201905092915050565b600061054282610565565b9050919050565b6000819050919050565b600061055e82610537565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b610598826105ef565b810181811067ffffffffffffffff821117156105b7576105b66105c0565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f5361666545524332303a20617070726f7665206661696c656400000000000000600082015250565b61063281610537565b811461063d57600080fd5b50565b61064981610549565b811461065457600080fd5b50565b61066081610553565b811461066b57600080fd5b50565b61067781610585565b811461068257600080fd5b5056fea2646970667358221220c291867c98021a3783a6b51efea938b9305c29a5c9b6723b70d4e8f1190f9bde64736f6c63430008020033" \ No newline at end of file diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 836974350..c48c204b3 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -37,16 +37,11 @@ use test_utils::*; mod error; lazy_static! { - // TODO: Deprecated! This is v4! - static ref ADEXCORE_ABI: &'static [u8] = - include_bytes!("../../lib/protocol-eth/abi/AdExCore.json"); static ref OUTPACE_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/OUTPACE.json"); - // TODO: Fix it once ERC20 and OUTPACE are merged - static ref ERC20_ABI: &'static [u8] = include_str!("../ERC20.json").trim_end_matches('\n').as_bytes(); - // TODO: Open PR with those in protocol-eth and sync module once it's ready - static ref SWEEPER_ABI: &'static [u8] = include_bytes!("../Sweeper.json"); - static ref DEPOSITOR_BYTECODE: &'static [u8] = include_bytes!("../Depositorbytecode.json"); + static ref ERC20_ABI: &'static [u8] = include_str!("../../lib/protocol-eth/abi/ERC20.json").trim_end_matches('\n').as_bytes(); + static ref SWEEPER_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/Sweeper.json"); + static ref DEPOSITOR_BYTECODE: &'static [u8] = include_bytes!("../../lib/protocol-eth/resources/bytecode/Depositor.json"); } #[cfg(test)] From 7fa7317fc50ab3cc10d85c8f2f6f96afac670774 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Mon, 10 May 2021 17:37:28 +0300 Subject: [PATCH 42/60] adapter - ethereum - fix outpace & sweeper bytecode paths for tests --- adapter/src/ethereum.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index c48c204b3..2b38344f5 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -60,9 +60,9 @@ mod test_utils { pub static ref MOCK_TOKEN_BYTECODE: &'static str = include_str!("../test/resources/mock_token_bytecode.json").trim_end_matches("\n"); /// Sweeper bytecode - pub static ref SWEEPER_BYTECODE: &'static str = include_str!("../Sweeperbytecode.json").trim_end_matches("\n"); + pub static ref SWEEPER_BYTECODE: &'static str = include_str!("../../lib/protocol-eth/resources/bytecode/Sweeper.json").trim_end_matches("\n"); /// Outpace bytecode - pub static ref OUTPACE_BYTECODE: &'static str = include_str!("../OUTPACEbytecode.json").trim_end_matches("\n"); + pub static ref OUTPACE_BYTECODE: &'static str = include_str!("../../lib/protocol-eth/resources/bytecode/OUTPACE.json").trim_end_matches("\n"); pub static ref GANACHE_ADDRESSES: HashMap = { vec![ ( From 59ba82be6fa00b9fdf7ea6c5df02e86b2eb1d271 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Mon, 10 May 2021 17:38:40 +0300 Subject: [PATCH 43/60] rustfmt --- adapter/src/ethereum.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 2b38344f5..e4e4752d7 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -39,9 +39,13 @@ mod error; lazy_static! { static ref OUTPACE_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/OUTPACE.json"); - static ref ERC20_ABI: &'static [u8] = include_str!("../../lib/protocol-eth/abi/ERC20.json").trim_end_matches('\n').as_bytes(); - static ref SWEEPER_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/Sweeper.json"); - static ref DEPOSITOR_BYTECODE: &'static [u8] = include_bytes!("../../lib/protocol-eth/resources/bytecode/Depositor.json"); + static ref ERC20_ABI: &'static [u8] = include_str!("../../lib/protocol-eth/abi/ERC20.json") + .trim_end_matches('\n') + .as_bytes(); + static ref SWEEPER_ABI: &'static [u8] = + include_bytes!("../../lib/protocol-eth/abi/Sweeper.json"); + static ref DEPOSITOR_BYTECODE: &'static [u8] = + include_bytes!("../../lib/protocol-eth/resources/bytecode/Depositor.json"); } #[cfg(test)] From cd1a0149f72fce269800c87e820549f4dd606da1 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Tue, 11 May 2021 14:40:45 +0300 Subject: [PATCH 44/60] adapter - ethereum - add Sweeper contract sweep test case --- adapter/src/ethereum.rs | 56 ++++++++++++++++++++++++++++++++++++--- primitives/src/adapter.rs | 2 +- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index e4e4752d7..ba81e7b36 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -778,7 +778,7 @@ mod test { let counterfactual_address = get_counterfactual_address(sweeper.0, &channel, outpace.0, &spender); - // No Regular nor Create2 deposit + // No Regular nor Create2 deposits { let no_deposits = eth_adapter .get_deposit(&channel, &spender) @@ -850,7 +850,7 @@ mod test { ); } - // Deposit with less than minimum token units + // Deposit with more than minimum token units { // Set balance > minimal token units mock_set_balance( @@ -876,14 +876,39 @@ mod test { deposit_with_create2 ); } + + // Run sweeper, it should clear the previously set create2 deposit and leave the total + { + sweeper_sweep( + &sweeper.1, + outpace.0.to_fixed_bytes(), + &channel, + *spender.as_bytes(), + ) + .await + .expect("Should sweep the Spender account"); + + let swept_deposit = eth_adapter + .get_deposit(&channel, &spender) + .await + .expect("should get deposit"); + + assert_eq!( + Deposit { + total: BigNum::from(11_999), + // we've just swept the account, so create2 should be empty + still_on_create2: BigNum::from(0), + }, + swept_deposit + ); + } } pub fn get_test_channel(token_address: Address) -> ChannelV5 { ChannelV5 { leader: ValidatorId::from(&GANACHE_ADDRESSES["leader"]), follower: ValidatorId::from(&GANACHE_ADDRESSES["follower"]), - guardian: Address::try_from("0000000000000000000000000000000000000000") - .expect("should create an address"), + guardian: GANACHE_ADDRESSES["advertiser"], token: token_address, nonce: Nonce::from(12345_u32), } @@ -927,6 +952,29 @@ mod test { .await } + pub async fn sweeper_sweep( + sweeper_contract: &Contract, + outpace_address: [u8; 20], + channel: &ChannelV5, + depositor: [u8; 20], + ) -> web3::contract::Result { + tokio_compat_02::FutureExt::compat(sweeper_contract.call( + "sweep", + ( + Token::Address(H160(outpace_address)), + Token::Tuple(channel_to_eth_channel(channel)), + Token::Array(vec![Token::Address(H160(depositor))]), + ), + H160(depositor), + Options::with(|opt| { + opt.gas_price = Some(1.into()); + // TODO: Check how much should this gas limit be! + opt.gas = Some(61_721_975.into()); + }), + )) + .await + } + /// Deploys the Sweeper contract from `GANACHE_ADDRESS['leader']` async fn deploy_sweeper_contract( web3: &Web3, diff --git a/primitives/src/adapter.rs b/primitives/src/adapter.rs index c31324026..20b8cac88 100644 --- a/primitives/src/adapter.rs +++ b/primitives/src/adapter.rs @@ -11,7 +11,7 @@ pub type AdapterResult = Result>; pub trait AdapterErrorKind: fmt::Debug + fmt::Display {} -#[derive(Debug, Eq, PartialEq)] +#[derive(Debug, Clone, Eq, PartialEq)] pub struct Deposit { pub total: BigNum, pub still_on_create2: BigNum, From 766ab9ea1d25903d8459632207ef9164b033af1b Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Tue, 11 May 2021 14:41:15 +0300 Subject: [PATCH 45/60] adapter - dummy - impl mocking of deposit calls --- Cargo.lock | 1 + adapter/Cargo.toml | 3 ++ adapter/src/dummy.rs | 124 ++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 120 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a8c51765..5c8d9b124 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,6 +9,7 @@ dependencies = [ "byteorder 1.4.3", "chrono", "create2", + "dashmap", "eth_checksum", "ethstore", "futures 0.3.13", diff --git a/adapter/Cargo.toml b/adapter/Cargo.toml index c90aeb557..7cd375826 100644 --- a/adapter/Cargo.toml +++ b/adapter/Cargo.toml @@ -31,6 +31,9 @@ futures = { version = "0.3", features = ["compat"] } async-trait = "0.1" tokio-compat-02 = "0.2" +# Dummy adapter +dashmap = "4.0" + [dev-dependencies] byteorder = "^1.4" tokio = { version = "^1", features = ["macros", "rt-multi-thread"] } diff --git a/adapter/src/dummy.rs b/adapter/src/dummy.rs index fbf04950f..d7e9dd6d1 100644 --- a/adapter/src/dummy.rs +++ b/adapter/src/dummy.rs @@ -1,4 +1,5 @@ use async_trait::async_trait; +use dashmap::{mapref::entry::Entry, DashMap}; use primitives::{ adapter::{ Adapter, AdapterErrorKind, AdapterResult, Deposit, DummyAdapterOptions, @@ -7,9 +8,9 @@ use primitives::{ channel_v5::Channel as ChannelV5, channel_validator::ChannelValidator, config::Config, - Address, BigNum, Channel, ToETHChecksum, ValidatorId, + Address, Channel, ChannelId, ToETHChecksum, ValidatorId, }; -use std::{collections::HashMap, fmt}; +use std::{collections::HashMap, fmt, sync::Arc}; #[derive(Debug, Clone)] pub struct DummyAdapter { @@ -19,6 +20,42 @@ pub struct DummyAdapter { session_tokens: HashMap, // Auth tokens that we've generated to authenticate with someone (address => token) authorization_tokens: HashMap, + deposits: Deposits, +} + +#[derive(Debug, Clone, Default)] +pub struct Deposits(Arc)>>); + +impl Deposits { + pub fn add_deposit(&self, channel: ChannelId, address: Address, deposit: Deposit) { + match self.0.entry((channel, address)) { + Entry::Occupied(mut deposit_calls) => { + // add the new deposit to the Vec + deposit_calls.get_mut().1.push(deposit); + } + Entry::Vacant(empty) => { + // add the new `(ChannelId, Address)` key and init with index 0 and the passed Deposit + empty.insert((0, vec![deposit])); + } + } + } + + pub fn get_next_deposit(&self, channel: ChannelId, address: Address) -> Option { + match self.0.entry((channel, address)) { + Entry::Occupied(mut entry) => { + let (call_index, deposit_calls) = entry.get_mut(); + + let deposit = deposit_calls.get(*call_index).cloned()?; + + // increment the index for the next call + *call_index = call_index + .checked_add(1) + .expect("Deposit call index has overflowed"); + Some(deposit) + } + Entry::Vacant(_) => None, + } + } } // Enables DummyAdapter to be able to @@ -32,8 +69,13 @@ impl DummyAdapter { config: config.to_owned(), session_tokens: opts.dummy_auth, authorization_tokens: opts.dummy_auth_tokens, + deposits: Default::default(), } } + + pub fn add_deposit_call(&self, channel: ChannelId, address: Address, deposit: Deposit) { + self.deposits.add_deposit(channel, address, deposit) + } } #[derive(Debug)] @@ -132,12 +174,78 @@ impl Adapter for DummyAdapter { async fn get_deposit( &self, - _channel: &ChannelV5, - _address: &Address, + channel: &ChannelV5, + address: &Address, ) -> AdapterResult { - Ok(Deposit { - total: BigNum::from(1000000), - still_on_create2: BigNum::from(0), - }) + self.deposits + .get_next_deposit(channel.id(), *address) + .ok_or_else(|| AdapterError::Adapter(Box::new(Error {}))) + } +} + +#[cfg(test)] +mod test { + use primitives::{ + config::configuration, + util::tests::prep_db::{ADDRESSES, DUMMY_CAMPAIGN, IDS}, + BigNum, + }; + + use super::*; + + #[tokio::test] + async fn test_deposits_calls() { + let config = configuration("development", None).expect("Should get Config"); + let channel = DUMMY_CAMPAIGN.channel.clone(); + let adapter = DummyAdapter::init( + DummyAdapterOptions { + dummy_identity: IDS["leader"], + dummy_auth: Default::default(), + dummy_auth_tokens: Default::default(), + }, + &config, + ); + + let address = ADDRESSES["creator"]; + + // no mocked deposit calls should cause an Error + { + let result = adapter.get_deposit(&channel, &address).await; + + assert!(result.is_err()); + } + + let get_deposit = |total: u64, create2: u64| Deposit { + total: BigNum::from(total), + still_on_create2: BigNum::from(create2), + }; + + // add two deposit and call 3 times + // also check if different address does not have access to these calls + { + let deposits = [get_deposit(6969, 69), get_deposit(1000, 0)]; + adapter.add_deposit_call(channel.id(), address, deposits[0].clone()); + adapter.add_deposit_call(channel.id(), address, deposits[1].clone()); + + let first_call = adapter + .get_deposit(&channel, &address) + .await + .expect("Should get first mocked deposit"); + assert_eq!(&deposits[0], &first_call); + + // should not affect the Mocked deposit calls and should cause an error + let different_address_call = adapter.get_deposit(&channel, &ADDRESSES["leader"]).await; + assert!(different_address_call.is_err()); + + let second_call = adapter + .get_deposit(&channel, &address) + .await + .expect("Should get second mocked deposit"); + assert_eq!(&deposits[1], &second_call); + + // Third call should error, we've only mocked 2 calls! + let third_call = adapter.get_deposit(&channel, &address).await; + assert!(third_call.is_err()); + } } } From 8bec0f37d529398c2a659e0c705e1539043e8d73 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Tue, 11 May 2021 18:07:01 +0300 Subject: [PATCH 46/60] adapter - ethereum - move setup fns to `mod test_utils` --- adapter/src/ethereum.rs | 232 +++-------------------------- adapter/src/ethereum/test_utils.rs | 191 ++++++++++++++++++++++++ 2 files changed, 212 insertions(+), 211 deletions(-) create mode 100644 adapter/src/ethereum/test_utils.rs diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index ba81e7b36..521f71872 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -35,6 +35,8 @@ use web3::{ use test_utils::*; mod error; +#[cfg(test)] +mod test_utils; lazy_static! { static ref OUTPACE_ABI: &'static [u8] = @@ -48,60 +50,6 @@ lazy_static! { include_bytes!("../../lib/protocol-eth/resources/bytecode/Depositor.json"); } -#[cfg(test)] -mod test_utils { - use lazy_static::lazy_static; - use std::collections::HashMap; - - use primitives::Address; - - // See `adex-eth-protocol` `contracts/mocks/Token.sol` - lazy_static! { - /// Mocked Token ABI - pub static ref MOCK_TOKEN_ABI: &'static [u8] = - include_bytes!("../test/resources/mock_token_abi.json"); - /// Mocked Token bytecode - pub static ref MOCK_TOKEN_BYTECODE: &'static str = - include_str!("../test/resources/mock_token_bytecode.json").trim_end_matches("\n"); - /// Sweeper bytecode - pub static ref SWEEPER_BYTECODE: &'static str = include_str!("../../lib/protocol-eth/resources/bytecode/Sweeper.json").trim_end_matches("\n"); - /// Outpace bytecode - pub static ref OUTPACE_BYTECODE: &'static str = include_str!("../../lib/protocol-eth/resources/bytecode/OUTPACE.json").trim_end_matches("\n"); - pub static ref GANACHE_ADDRESSES: HashMap = { - vec![ - ( - "leader".to_string(), - "0x5a04A8fB90242fB7E1db7d1F51e268A03b7f93A5" - .parse() - .expect("Valid Address"), - ), - ( - "follower".to_string(), - "0xe3896ebd3F32092AFC7D27e9ef7b67E26C49fB02" - .parse() - .expect("Valid Address"), - ), - ( - "creator".to_string(), - "0x0E45891a570Af9e5A962F181C219468A6C9EB4e1" - .parse() - .expect("Valid Address"), - ), - ( - "advertiser".to_string(), - "0x8c4B95383a46D30F056aCe085D8f453fCF4Ed66d" - .parse() - .expect("Valid Address"), - ), - ] - .into_iter() - .collect() - }; - } - - pub const GANACHE_URL: &'static str = "http://localhost:8545"; -} - #[derive(Debug, Clone)] pub struct EthereumAdapter { address: ValidatorId, @@ -149,15 +97,22 @@ impl EthereumAdapter { } } -// TODO: replace with EthChannel when we alter it! -pub fn channel_to_eth_channel(channel: &ChannelV5) -> Vec { - vec![ - Token::Address(channel.leader.as_bytes().into()), - Token::Address(channel.follower.as_bytes().into()), - Token::Address(channel.guardian.as_bytes().into()), - Token::Address(channel.token.as_bytes().into()), - Token::FixedBytes(channel.nonce.to_bytes().to_vec()), - ] +trait EthereumChannel { + fn tokenize(&self) -> Token; +} + +impl EthereumChannel for ChannelV5 { + fn tokenize(&self) -> Token { + let tokens = vec![ + Token::Address(self.leader.as_bytes().into()), + Token::Address(self.follower.as_bytes().into()), + Token::Address(self.guardian.as_bytes().into()), + Token::Address(self.token.as_bytes().into()), + Token::FixedBytes(self.nonce.to_bytes().to_vec()), + ]; + + Token::Tuple(tokens) + } } fn get_counterfactual_address( @@ -168,10 +123,8 @@ fn get_counterfactual_address( ) -> H160 { let salt: [u8; 32] = [0; 32]; let mut init_code: Vec = DEPOSITOR_BYTECODE.to_vec(); - // TODO: Change the EthereumChannel and use it! - let channel_as_token_vec = channel_to_eth_channel(&channel); let mut encoded_params = encode(&[ - Token::Tuple(channel_as_token_vec), + channel.tokenize(), Token::Address(outpace), Token::Address(H160(*depositor.as_bytes())), ]) @@ -572,12 +525,8 @@ mod test { channel_v5::Nonce, config::{configuration, TokenInfo}, }; - use std::{convert::TryFrom, num::NonZeroU8}; - use web3::{ - transports::Http, - types::{Address as EthAddress, H256}, - Web3, - }; + use std::convert::TryFrom; + use web3::{transports::Http, types::Address as EthAddress, Web3}; use wiremock::{ matchers::{method, path}, Mock, MockServer, ResponseTemplate, @@ -913,143 +862,4 @@ mod test { nonce: Nonce::from(12345_u32), } } - - pub async fn mock_set_balance( - token_contract: &Contract, - from: [u8; 20], - address: [u8; 20], - amount: u64, - ) -> web3::contract::Result { - tokio_compat_02::FutureExt::compat(token_contract.call( - "setBalanceTo", - (H160(address), U256::from(amount)), - H160(from), - Options::default(), - )) - .await - } - - pub async fn outpace_deposit( - outpace_contract: &Contract, - channel: &ChannelV5, - to: [u8; 20], - amount: u64, - ) -> web3::contract::Result { - tokio_compat_02::FutureExt::compat(outpace_contract.call( - "deposit", - ( - Token::Tuple(channel_to_eth_channel(channel)), - H160(to), - U256::from(amount), - ), - H160(to), - Options::with(|opt| { - opt.gas_price = Some(1.into()); - // TODO: Check how much should this gas limit be! - opt.gas = Some(61_721_975.into()); - }), - )) - .await - } - - pub async fn sweeper_sweep( - sweeper_contract: &Contract, - outpace_address: [u8; 20], - channel: &ChannelV5, - depositor: [u8; 20], - ) -> web3::contract::Result { - tokio_compat_02::FutureExt::compat(sweeper_contract.call( - "sweep", - ( - Token::Address(H160(outpace_address)), - Token::Tuple(channel_to_eth_channel(channel)), - Token::Array(vec![Token::Address(H160(depositor))]), - ), - H160(depositor), - Options::with(|opt| { - opt.gas_price = Some(1.into()); - // TODO: Check how much should this gas limit be! - opt.gas = Some(61_721_975.into()); - }), - )) - .await - } - - /// Deploys the Sweeper contract from `GANACHE_ADDRESS['leader']` - async fn deploy_sweeper_contract( - web3: &Web3, - ) -> web3::contract::Result<(H160, Contract)> { - let from_leader_account: EthAddress = - EthAddress::from(GANACHE_ADDRESSES["leader"].as_bytes()); - - let feature = tokio_compat_02::FutureExt::compat(async { - Contract::deploy(web3.eth(), &SWEEPER_ABI) - .expect("Invalid ABI of Sweeper contract") - .confirmations(0) - .options(Options::with(|opt| { - opt.gas_price = Some(1.into()); - opt.gas = Some(6_721_975.into()); - })) - .execute(*SWEEPER_BYTECODE, (), from_leader_account) - }) - .await; - - let sweeper_contract = tokio_compat_02::FutureExt::compat(feature).await?; - - Ok((sweeper_contract.address(), sweeper_contract)) - } - - /// Deploys the Outpace contract from `GANACHE_ADDRESS['leader']` - async fn deploy_outpace_contract( - web3: &Web3, - ) -> web3::contract::Result<(H160, Contract)> { - let from_leader_account: EthAddress = - EthAddress::from(GANACHE_ADDRESSES["leader"].as_bytes()); - - let feature = tokio_compat_02::FutureExt::compat(async { - Contract::deploy(web3.eth(), &OUTPACE_ABI) - .expect("Invalid ABI of Sweeper contract") - .confirmations(0) - .options(Options::with(|opt| { - opt.gas_price = Some(1.into()); - opt.gas = Some(6_721_975.into()); - })) - .execute(*OUTPACE_BYTECODE, (), from_leader_account) - }) - .await; - - let outpace_contract = tokio_compat_02::FutureExt::compat(feature).await?; - - Ok((outpace_contract.address(), outpace_contract)) - } - - /// Deploys the Mock Token contract from `GANACHE_ADDRESS['leader']` - async fn deploy_token_contract( - web3: &Web3, - min_token_units: u64, - ) -> web3::contract::Result<(TokenInfo, H160, Contract)> { - let from_leader_account: EthAddress = - EthAddress::from(GANACHE_ADDRESSES["leader"].as_bytes()); - - let feature = tokio_compat_02::FutureExt::compat(async { - Contract::deploy(web3.eth(), &MOCK_TOKEN_ABI) - .expect("Invalid ABI of Mock Token contract") - .confirmations(0) - .options(Options::with(|opt| { - opt.gas_price = Some(1.into()); - opt.gas = Some(6_721_975.into()); - })) - .execute(*MOCK_TOKEN_BYTECODE, (), from_leader_account) - }) - .await; - - let token_contract = tokio_compat_02::FutureExt::compat(feature).await?; - - let token_info = TokenInfo { - min_token_units_for_deposit: BigNum::from(min_token_units), - precision: NonZeroU8::new(18).expect("should create NonZeroU8"), - }; - - Ok((token_info, token_contract.address(), token_contract)) - } } diff --git a/adapter/src/ethereum/test_utils.rs b/adapter/src/ethereum/test_utils.rs new file mode 100644 index 000000000..514e2e1e8 --- /dev/null +++ b/adapter/src/ethereum/test_utils.rs @@ -0,0 +1,191 @@ +use lazy_static::lazy_static; +use std::{collections::HashMap, num::NonZeroU8}; +use web3::{ + contract::{Contract, Options}, + ethabi::Token, + transports::Http, + types::{H160, H256, U256}, + Web3, +}; + +use primitives::{channel_v5::Channel, config::TokenInfo, Address, BigNum}; + +use super::{EthereumChannel, OUTPACE_ABI, SWEEPER_ABI}; + +// See `adex-eth-protocol` `contracts/mocks/Token.sol` +lazy_static! { + /// Mocked Token ABI + pub static ref MOCK_TOKEN_ABI: &'static [u8] = + include_bytes!("../../test/resources/mock_token_abi.json"); + /// Mocked Token bytecode + pub static ref MOCK_TOKEN_BYTECODE: &'static str = + include_str!("../../test/resources/mock_token_bytecode.json").trim_end_matches("\n"); + /// Sweeper bytecode + pub static ref SWEEPER_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/Sweeper.json").trim_end_matches("\n"); + /// Outpace bytecode + pub static ref OUTPACE_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/OUTPACE.json").trim_end_matches("\n"); + pub static ref GANACHE_ADDRESSES: HashMap = { + vec![ + ( + "leader".to_string(), + "0x5a04A8fB90242fB7E1db7d1F51e268A03b7f93A5" + .parse() + .expect("Valid Address"), + ), + ( + "follower".to_string(), + "0xe3896ebd3F32092AFC7D27e9ef7b67E26C49fB02" + .parse() + .expect("Valid Address"), + ), + ( + "creator".to_string(), + "0x0E45891a570Af9e5A962F181C219468A6C9EB4e1" + .parse() + .expect("Valid Address"), + ), + ( + "advertiser".to_string(), + "0x8c4B95383a46D30F056aCe085D8f453fCF4Ed66d" + .parse() + .expect("Valid Address"), + ), + ] + .into_iter() + .collect() + }; +} + +pub const GANACHE_URL: &'static str = "http://localhost:8545"; + +pub async fn mock_set_balance( + token_contract: &Contract, + from: [u8; 20], + address: [u8; 20], + amount: u64, +) -> web3::contract::Result { + tokio_compat_02::FutureExt::compat(token_contract.call( + "setBalanceTo", + (H160(address), U256::from(amount)), + H160(from), + Options::default(), + )) + .await +} + +pub async fn outpace_deposit( + outpace_contract: &Contract, + channel: &Channel, + to: [u8; 20], + amount: u64, +) -> web3::contract::Result { + tokio_compat_02::FutureExt::compat(outpace_contract.call( + "deposit", + (channel.tokenize(), H160(to), U256::from(amount)), + H160(to), + Options::with(|opt| { + opt.gas_price = Some(1.into()); + // TODO: Check how much should this gas limit be! + opt.gas = Some(61_721_975.into()); + }), + )) + .await +} + +pub async fn sweeper_sweep( + sweeper_contract: &Contract, + outpace_address: [u8; 20], + channel: &Channel, + depositor: [u8; 20], +) -> web3::contract::Result { + tokio_compat_02::FutureExt::compat(sweeper_contract.call( + "sweep", + ( + Token::Address(H160(outpace_address)), + channel.tokenize(), + Token::Array(vec![Token::Address(H160(depositor))]), + ), + H160(depositor), + Options::with(|opt| { + opt.gas_price = Some(1.into()); + // TODO: Check how much should this gas limit be! + opt.gas = Some(61_721_975.into()); + }), + )) + .await +} + +/// Deploys the Sweeper contract from `GANACHE_ADDRESS['leader']` +pub async fn deploy_sweeper_contract( + web3: &Web3, +) -> web3::contract::Result<(H160, Contract)> { + let from_leader_account = H160(*GANACHE_ADDRESSES["leader"].as_bytes()); + + let feature = tokio_compat_02::FutureExt::compat(async { + Contract::deploy(web3.eth(), &SWEEPER_ABI) + .expect("Invalid ABI of Sweeper contract") + .confirmations(0) + .options(Options::with(|opt| { + opt.gas_price = Some(1.into()); + opt.gas = Some(6_721_975.into()); + })) + .execute(*SWEEPER_BYTECODE, (), from_leader_account) + }) + .await; + + let sweeper_contract = tokio_compat_02::FutureExt::compat(feature).await?; + + Ok((sweeper_contract.address(), sweeper_contract)) +} + +/// Deploys the Outpace contract from `GANACHE_ADDRESS['leader']` +pub async fn deploy_outpace_contract( + web3: &Web3, +) -> web3::contract::Result<(H160, Contract)> { + let from_leader_account = H160(*GANACHE_ADDRESSES["leader"].as_bytes()); + + let feature = tokio_compat_02::FutureExt::compat(async { + Contract::deploy(web3.eth(), &OUTPACE_ABI) + .expect("Invalid ABI of Sweeper contract") + .confirmations(0) + .options(Options::with(|opt| { + opt.gas_price = Some(1.into()); + opt.gas = Some(6_721_975.into()); + })) + .execute(*OUTPACE_BYTECODE, (), from_leader_account) + }) + .await; + + let outpace_contract = tokio_compat_02::FutureExt::compat(feature).await?; + + Ok((outpace_contract.address(), outpace_contract)) +} + +/// Deploys the Mock Token contract from `GANACHE_ADDRESS['leader']` +pub async fn deploy_token_contract( + web3: &Web3, + min_token_units: u64, +) -> web3::contract::Result<(TokenInfo, H160, Contract)> { + let from_leader_account = H160(*GANACHE_ADDRESSES["leader"].as_bytes()); + + let feature = tokio_compat_02::FutureExt::compat(async { + Contract::deploy(web3.eth(), &MOCK_TOKEN_ABI) + .expect("Invalid ABI of Mock Token contract") + .confirmations(0) + .options(Options::with(|opt| { + opt.gas_price = Some(1.into()); + opt.gas = Some(6_721_975.into()); + })) + .execute(*MOCK_TOKEN_BYTECODE, (), from_leader_account) + }) + .await; + + let token_contract = tokio_compat_02::FutureExt::compat(feature).await?; + + let token_info = TokenInfo { + min_token_units_for_deposit: BigNum::from(min_token_units), + precision: NonZeroU8::new(18).expect("should create NonZeroU8"), + }; + + Ok((token_info, token_contract.address(), token_contract)) +} From 1ffcbfe49ae4af917f74f755aa38dd101c621261 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Tue, 11 May 2021 18:07:26 +0300 Subject: [PATCH 47/60] adapter - remove `EthereumChannel` struct --- adapter/src/lib.rs | 140 --------------------------------------------- 1 file changed, 140 deletions(-) diff --git a/adapter/src/lib.rs b/adapter/src/lib.rs index e13b74cc8..c33a5fd01 100644 --- a/adapter/src/lib.rs +++ b/adapter/src/lib.rs @@ -65,146 +65,6 @@ pub fn get_balance_leaf(acc: &Address, amnt: &BigNum) -> Result<[u8; 32], Box, - pub spec: [u8; 32], -} - -impl TryFrom<&Channel> for EthereumChannel { - type Error = ChannelError; - - fn try_from(channel: &Channel) -> Result { - let spec = serde_json::to_string(&channel.spec) - .map_err(|e| ChannelError::InvalidArgument(e.to_string()))?; - - let mut hash = Sha256::new(); - hash.input(spec); - let spec_hash: [u8; 32] = hash.result().into(); - - let validators = channel - .spec - .validators - .iter() - .map(|v| &v.id) - .collect::>(); - - let creator = channel.creator.inner(); - let deposit_asset = <[u8; 20]>::from_hex(&channel.deposit_asset[2..]) - .map_err(|_| ChannelError::InvalidArgument("failed to parse deposit asset".into()))?; - - EthereumChannel::new( - &creator, - &deposit_asset, - &channel.deposit_amount.to_string(), - channel.valid_until, - &validators, - &spec_hash, - ) - } -} - -impl EthereumChannel { - pub fn new( - creator: &[u8; 20], - token_addr: &[u8; 20], - token_amount: &str, // big num string - valid_until: DateTime, - validators: &[&ValidatorId], - spec: &[u8; 32], - ) -> Result { - if BigNum::try_from(token_amount).is_err() { - return Err(ChannelError::InvalidArgument("invalid token amount".into())); - } - - let creator = EthAddress::from_slice(creator); - let token_addr = EthAddress::from_slice(token_addr); - let token_amount = U256::from_dec_str(&token_amount) - .map_err(|_| ChannelError::InvalidArgument("failed to parse token amount".into()))?; - let valid_until = U256::from_dec_str(&valid_until.timestamp().to_string()) - .map_err(|_| ChannelError::InvalidArgument("failed to parse valid until".into()))?; - - let validators = validators - .iter() - .map(|v| EthAddress::from_slice(v.as_bytes())) - .collect(); - - Ok(Self { - creator, - token_addr, - token_amount, - valid_until, - validators, - spec: spec.to_owned(), - }) - } - - pub fn hash(&self, contract_addr: &[u8; 20]) -> [u8; 32] { - let tokens = [ - Token::Address(EthAddress::from_slice(contract_addr)), - Token::Address(self.creator.to_owned()), - Token::Address(self.token_addr.to_owned()), - Token::Uint(self.token_amount.to_owned()), - Token::Uint(self.valid_until.to_owned()), - Token::Array( - self.validators - .iter() - .map(|v| Token::Address(v.to_owned())) - .collect(), - ), - Token::FixedBytes(self.spec.to_vec()), - ]; - - let encoded = encode(&tokens).to_vec(); - let mut result = Keccak::new_keccak256(); - result.update(&encoded); - - let mut res: [u8; 32] = [0; 32]; - result.finalize(&mut res); - - res - } - - pub fn to_solidity_tuple(&self) -> Token { - Token::Tuple(vec![ - Token::Address(self.creator.to_owned()), - Token::Address(self.token_addr.to_owned()), - Token::Uint(self.token_amount.to_owned()), - Token::Uint(self.valid_until.to_owned()), - Token::Array( - self.validators - .iter() - .map(|v| Token::Address(v.to_owned())) - .collect(), - ), - Token::FixedBytes(self.spec.to_vec()), - ]) - } - - pub fn hash_to_sign( - &self, - contract_addr: &str, - balance_root: &str, - ) -> Result<[u8; 32], Box> { - let root = <[u8; 32]>::from_hex(balance_root)?; - let addr = hex::decode(contract_addr)?; - get_signable_state_root(&addr, &root) - } - - pub fn hash_to_sign_hex( - &self, - contract_addr: &str, - balance_root: &str, - ) -> Result> { - let result = self.hash_to_sign(contract_addr, balance_root)?; - Ok(format!("0x{}", hex::encode(result))) - } -} - #[cfg(test)] mod test { use std::convert::TryFrom; From 7cdfeb5b64e3d16489f7b25d66e9e231a373f929 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Tue, 11 May 2021 18:08:41 +0300 Subject: [PATCH 48/60] primitives - Adapter - remove `validate_channel` --- adapter/src/dummy.rs | 9 --------- adapter/src/ethereum.rs | 8 -------- primitives/src/adapter.rs | 7 ------- sentry/src/routes/channel.rs | 7 ++++--- 4 files changed, 4 insertions(+), 27 deletions(-) diff --git a/adapter/src/dummy.rs b/adapter/src/dummy.rs index d7e9dd6d1..9eb859af6 100644 --- a/adapter/src/dummy.rs +++ b/adapter/src/dummy.rs @@ -125,15 +125,6 @@ impl Adapter for DummyAdapter { Ok(is_same) } - async fn validate_channel<'a>( - &'a self, - channel: &'a Channel, - ) -> AdapterResult { - DummyAdapter::is_channel_valid(&self.config, self.whoami(), channel) - .map(|_| true) - .map_err(AdapterError::InvalidChannel) - } - async fn session_from_token<'a>( &'a self, token: &'a str, diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 521f71872..68ea37415 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -194,14 +194,6 @@ impl Adapter for EthereumAdapter { Ok(verify_address) } - // TODO: Remove - async fn validate_channel<'a>( - &'a self, - _channel: &'a Channel, - ) -> AdapterResult { - Ok(true) - } - /// Creates a `Session` from a provided Token by calling the Contract. /// Does **not** cache the (`Token`, `Session`) pair. async fn session_from_token<'a>( diff --git a/primitives/src/adapter.rs b/primitives/src/adapter.rs index 20b8cac88..3b4d1d13f 100644 --- a/primitives/src/adapter.rs +++ b/primitives/src/adapter.rs @@ -96,13 +96,6 @@ pub trait Adapter: ChannelValidator + Send + Sync + fmt::Debug + Clone { signature: &str, ) -> AdapterResult; - /// Validate a channel - #[deprecated(note = "REMOVE, this is v4! no longer needed")] - async fn validate_channel<'a>( - &'a self, - channel: &'a Channel, - ) -> AdapterResult; - /// Get user session from token async fn session_from_token<'a>( &'a self, diff --git a/sentry/src/routes/channel.rs b/sentry/src/routes/channel.rs index 9c485d78f..7ad81a370 100644 --- a/sentry/src/routes/channel.rs +++ b/sentry/src/routes/channel.rs @@ -49,9 +49,10 @@ pub async fn create_channel( let channel = serde_json::from_slice::(&body) .map_err(|e| ResponseError::FailedValidation(e.to_string()))?; - if let Err(e) = app.adapter.validate_channel(&channel).await { - return Err(ResponseError::BadRequest(e.to_string())); - } + // TODO AIP#61: No longer needed, remove! + // if let Err(e) = app.adapter.validate_channel(&channel).await { + // return Err(ResponseError::BadRequest(e.to_string())); + // } let error_response = ResponseError::BadRequest("err occurred; please try again later".into()); From 06484f19878589267ebd75668018b0e358655240 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Tue, 11 May 2021 18:21:36 +0300 Subject: [PATCH 49/60] adapter - cleanup old code --- adapter/src/dummy.rs | 7 ++++--- adapter/src/ethereum.rs | 14 +++++++------- adapter/src/lib.rs | 6 +----- primitives/src/adapter.rs | 13 ++++++------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/adapter/src/dummy.rs b/adapter/src/dummy.rs index 9eb859af6..429d5cd9e 100644 --- a/adapter/src/dummy.rs +++ b/adapter/src/dummy.rs @@ -5,10 +5,10 @@ use primitives::{ Adapter, AdapterErrorKind, AdapterResult, Deposit, DummyAdapterOptions, Error as AdapterError, Session, }, - channel_v5::Channel as ChannelV5, + channel_v5::Channel, channel_validator::ChannelValidator, config::Config, - Address, Channel, ChannelId, ToETHChecksum, ValidatorId, + Address, ChannelId, ToETHChecksum, ValidatorId, }; use std::{collections::HashMap, fmt, sync::Arc}; @@ -24,6 +24,7 @@ pub struct DummyAdapter { } #[derive(Debug, Clone, Default)] +#[allow(clippy::type_complexity)] pub struct Deposits(Arc)>>); impl Deposits { @@ -165,7 +166,7 @@ impl Adapter for DummyAdapter { async fn get_deposit( &self, - channel: &ChannelV5, + channel: &Channel, address: &Address, ) -> AdapterResult { self.deposits diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 68ea37415..245fe7832 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -13,10 +13,10 @@ use futures::TryFutureExt; use lazy_static::lazy_static; use primitives::{ adapter::{Adapter, AdapterResult, Deposit, Error as AdapterError, KeystoreOptions, Session}, - channel_v5::Channel as ChannelV5, + channel_v5::Channel, channel_validator::ChannelValidator, config::Config, - Address, BigNum, Channel, ToETHChecksum, ValidatorId, + Address, BigNum, ToETHChecksum, ValidatorId, }; use reqwest::Client; use serde::{Deserialize, Serialize}; @@ -101,7 +101,7 @@ trait EthereumChannel { fn tokenize(&self) -> Token; } -impl EthereumChannel for ChannelV5 { +impl EthereumChannel for Channel { fn tokenize(&self) -> Token { let tokens = vec![ Token::Address(self.leader.as_bytes().into()), @@ -117,7 +117,7 @@ impl EthereumChannel for ChannelV5 { fn get_counterfactual_address( sweeper: H160, - channel: &ChannelV5, + channel: &Channel, outpace: H160, depositor: &Address, ) -> H160 { @@ -272,7 +272,7 @@ impl Adapter for EthereumAdapter { async fn get_deposit( &self, - channel: &ChannelV5, + channel: &Channel, depositor_address: &Address, ) -> AdapterResult { let outpace_contract = Contract::from_json( @@ -845,8 +845,8 @@ mod test { } } - pub fn get_test_channel(token_address: Address) -> ChannelV5 { - ChannelV5 { + pub fn get_test_channel(token_address: Address) -> Channel { + Channel { leader: ValidatorId::from(&GANACHE_ADDRESSES["leader"]), follower: ValidatorId::from(&GANACHE_ADDRESSES["follower"]), guardian: GANACHE_ADDRESSES["advertiser"], diff --git a/adapter/src/lib.rs b/adapter/src/lib.rs index c33a5fd01..d6c52fe1a 100644 --- a/adapter/src/lib.rs +++ b/adapter/src/lib.rs @@ -4,11 +4,7 @@ use std::error::Error; -use chrono::{DateTime, Utc}; -use hex::FromHex; -use primitives::{channel::ChannelError, Address, BigNum, Channel, ValidatorId}; -use sha2::{Digest, Sha256}; -use std::convert::TryFrom; +use primitives::{channel::ChannelError, Address, BigNum}; use tiny_keccak::Keccak; use web3::{ ethabi::{encode, token::Token}, diff --git a/primitives/src/adapter.rs b/primitives/src/adapter.rs index 3b4d1d13f..b28dd7b9f 100644 --- a/primitives/src/adapter.rs +++ b/primitives/src/adapter.rs @@ -1,11 +1,10 @@ -use crate::channel::ChannelError; -use crate::channel_validator::ChannelValidator; -use crate::{channel_v5::Channel as ChannelV5, Address, BigNum, Channel, DomainError, ValidatorId}; +use crate::{ + channel::ChannelError, channel_v5::Channel, channel_validator::ChannelValidator, Address, + BigNum, DomainError, ValidatorId, +}; use async_trait::async_trait; use serde::{Deserialize, Serialize}; -use std::collections::HashMap; -use std::convert::From; -use std::fmt; +use std::{collections::HashMap, convert::From, fmt}; pub type AdapterResult = Result>; @@ -108,7 +107,7 @@ pub trait Adapter: ChannelValidator + Send + Sync + fmt::Debug + Clone { /// Calculates and returns the total spendable amount async fn get_deposit( &self, - channel: &ChannelV5, + channel: &Channel, address: &Address, ) -> AdapterResult; } From 994382b4e57e8de5d456affeeed67c2c8815919f Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Tue, 11 May 2021 18:50:51 +0300 Subject: [PATCH 50/60] adapter - ethereum - contrafactual address clean up --- adapter/src/ethereum.rs | 76 +++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 245fe7832..13c1d4e54 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -50,6 +50,45 @@ lazy_static! { include_bytes!("../../lib/protocol-eth/resources/bytecode/Depositor.json"); } +trait EthereumChannel { + fn tokenize(&self) -> Token; +} + +impl EthereumChannel for Channel { + fn tokenize(&self) -> Token { + let tokens = vec![ + Token::Address(self.leader.as_bytes().into()), + Token::Address(self.follower.as_bytes().into()), + Token::Address(self.guardian.as_bytes().into()), + Token::Address(self.token.as_bytes().into()), + Token::FixedBytes(self.nonce.to_bytes().to_vec()), + ]; + + Token::Tuple(tokens) + } +} + +fn get_counterfactual_address( + sweeper: H160, + channel: &Channel, + outpace: H160, + depositor: &Address, +) -> H160 { + let salt: [u8; 32] = [0; 32]; + let encoded_params = encode(&[ + Token::Address(outpace), + channel.tokenize(), + Token::Address(H160(*depositor.as_bytes())), + ]); + + let mut init_code = DEPOSITOR_BYTECODE.to_vec(); + init_code.extend(&encoded_params); + + let address = calc_addr(sweeper.as_fixed_bytes(), &salt, &init_code); + + H160(address) +} + #[derive(Debug, Clone)] pub struct EthereumAdapter { address: ValidatorId, @@ -97,43 +136,6 @@ impl EthereumAdapter { } } -trait EthereumChannel { - fn tokenize(&self) -> Token; -} - -impl EthereumChannel for Channel { - fn tokenize(&self) -> Token { - let tokens = vec![ - Token::Address(self.leader.as_bytes().into()), - Token::Address(self.follower.as_bytes().into()), - Token::Address(self.guardian.as_bytes().into()), - Token::Address(self.token.as_bytes().into()), - Token::FixedBytes(self.nonce.to_bytes().to_vec()), - ]; - - Token::Tuple(tokens) - } -} - -fn get_counterfactual_address( - sweeper: H160, - channel: &Channel, - outpace: H160, - depositor: &Address, -) -> H160 { - let salt: [u8; 32] = [0; 32]; - let mut init_code: Vec = DEPOSITOR_BYTECODE.to_vec(); - let mut encoded_params = encode(&[ - channel.tokenize(), - Token::Address(outpace), - Token::Address(H160(*depositor.as_bytes())), - ]) - .to_vec(); - init_code.append(&mut encoded_params); - let address = calc_addr(sweeper.as_fixed_bytes(), &salt, &init_code); - H160::from(address) -} - #[async_trait] impl Adapter for EthereumAdapter { type AdapterError = Error; From 5337871a7d1deb5081cb76cf1948367e0d0d3199 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Wed, 12 May 2021 09:30:24 +0300 Subject: [PATCH 51/60] adapter - remove ChannelValidator & clean up code TODO: uncomment sweeper test case once we figure out what's wrong with the contract call --- adapter/src/dummy.rs | 5 --- adapter/src/ethereum.rs | 68 +++--------------------------- adapter/src/ethereum/test_utils.rs | 58 +++++++++++++++++++++++-- primitives/src/adapter.rs | 4 +- 4 files changed, 63 insertions(+), 72 deletions(-) diff --git a/adapter/src/dummy.rs b/adapter/src/dummy.rs index 429d5cd9e..cc9c98b3a 100644 --- a/adapter/src/dummy.rs +++ b/adapter/src/dummy.rs @@ -6,7 +6,6 @@ use primitives::{ Error as AdapterError, Session, }, channel_v5::Channel, - channel_validator::ChannelValidator, config::Config, Address, ChannelId, ToETHChecksum, ValidatorId, }; @@ -59,10 +58,6 @@ impl Deposits { } } -// Enables DummyAdapter to be able to -// check if a channel is valid -impl ChannelValidator for DummyAdapter {} - impl DummyAdapter { pub fn init(opts: DummyAdapterOptions, config: &Config) -> Self { Self { diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 13c1d4e54..a8e5891bf 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -3,10 +3,7 @@ use chrono::Utc; use create2::calc_addr; use error::*; use ethstore::{ - ethkey::{ - public_to_address, recover, verify_address, Address as EthAddress, Message, Password, - Signature, - }, + ethkey::{public_to_address, recover, verify_address, Message, Password, Signature}, SafeAccount, }; use futures::TryFutureExt; @@ -14,7 +11,6 @@ use lazy_static::lazy_static; use primitives::{ adapter::{Adapter, AdapterResult, Deposit, Error as AdapterError, KeystoreOptions, Session}, channel_v5::Channel, - channel_validator::ChannelValidator, config::Config, Address, BigNum, ToETHChecksum, ValidatorId, }; @@ -100,10 +96,6 @@ pub struct EthereumAdapter { relayer: RelayerClient, } -// Enables EthereumAdapter to be able to -// check if a channel is valid -impl ChannelValidator for EthereumAdapter {} - impl EthereumAdapter { pub fn init(opts: KeystoreOptions, config: &Config) -> AdapterResult { let keystore_contents = @@ -185,7 +177,7 @@ impl Adapter for EthereumAdapter { return Err(VerifyError::SignatureNotPrefixed.into()); } let decoded_signature = hex::decode(&sig[2..]).map_err(VerifyError::SignatureDecoding)?; - let address = EthAddress::from(*signer.inner()); + let address = ethstore::ethkey::Address::from(*signer.as_bytes()); let signature = Signature::from_electrum(&decoded_signature); let state_root = hex::decode(state_root).map_err(VerifyError::StateRootDecoding)?; let message = Message::from(hash_message(&state_root)); @@ -514,50 +506,13 @@ pub fn ewt_verify( mod test { use super::*; use chrono::Utc; - use primitives::{ - adapter::KeystoreOptions, - channel_v5::Nonce, - config::{configuration, TokenInfo}, - }; use std::convert::TryFrom; - use web3::{transports::Http, types::Address as EthAddress, Web3}; + use web3::{transports::Http, Web3}; use wiremock::{ matchers::{method, path}, Mock, MockServer, ResponseTemplate, }; - fn setup_eth_adapter( - sweeper_address: Option<[u8; 20]>, - outpace_address: Option<[u8; 20]>, - token_whitelist: Option<(Address, TokenInfo)>, - ) -> EthereumAdapter { - let mut config = configuration("development", None).expect("failed parse config"); - let keystore_options = KeystoreOptions { - keystore_file: "./test/resources/keystore.json".to_string(), - keystore_pwd: "adexvalidator".to_string(), - }; - - if let Some(address) = sweeper_address { - config.sweeper_address = address; - } - - if let Some(address) = outpace_address { - config.outpace_address = address; - } - - if let Some((address, token_info)) = token_whitelist { - assert!( - config - .token_address_whitelist - .insert(address, token_info) - .is_none(), - "It should not contain the generated token prior to this call!" - ) - } - - EthereumAdapter::init(keystore_options, &config).expect("should init ethereum adapter") - } - #[test] fn should_init_and_unlock_ethereum_adapter() { let mut eth_adapter = setup_eth_adapter(None, None, None); @@ -691,7 +646,7 @@ mod test { async fn get_deposit_and_count_create2_when_min_tokens_received() { let web3 = Web3::new(Http::new(&GANACHE_URL).expect("failed to init transport")); - let leader_account: EthAddress = EthAddress::from(GANACHE_ADDRESSES["leader"].as_bytes()); + let leader_account = H160(*GANACHE_ADDRESSES["leader"].as_bytes()); // deploy contracts let token = deploy_token_contract(&web3, 1_000) @@ -821,7 +776,8 @@ mod test { } // Run sweeper, it should clear the previously set create2 deposit and leave the total - { + // TODO: Check why the `sweep()` is failing to run and remove the `allow(dead_code)` attr of `fn sweeper_sweep` + /* { sweeper_sweep( &sweeper.1, outpace.0.to_fixed_bytes(), @@ -844,16 +800,6 @@ mod test { }, swept_deposit ); - } - } - - pub fn get_test_channel(token_address: Address) -> Channel { - Channel { - leader: ValidatorId::from(&GANACHE_ADDRESSES["leader"]), - follower: ValidatorId::from(&GANACHE_ADDRESSES["follower"]), - guardian: GANACHE_ADDRESSES["advertiser"], - token: token_address, - nonce: Nonce::from(12345_u32), - } + } */ } } diff --git a/adapter/src/ethereum/test_utils.rs b/adapter/src/ethereum/test_utils.rs index 514e2e1e8..9b33ed0b3 100644 --- a/adapter/src/ethereum/test_utils.rs +++ b/adapter/src/ethereum/test_utils.rs @@ -8,7 +8,14 @@ use web3::{ Web3, }; -use primitives::{channel_v5::Channel, config::TokenInfo, Address, BigNum}; +use primitives::{ + adapter::KeystoreOptions, + channel_v5::{Channel, Nonce}, + config::{configuration, TokenInfo}, + Address, BigNum, ValidatorId, +}; + +use crate::EthereumAdapter; use super::{EthereumChannel, OUTPACE_ABI, SWEEPER_ABI}; @@ -58,6 +65,48 @@ lazy_static! { pub const GANACHE_URL: &'static str = "http://localhost:8545"; +pub fn get_test_channel(token_address: Address) -> Channel { + Channel { + leader: ValidatorId::from(&GANACHE_ADDRESSES["leader"]), + follower: ValidatorId::from(&GANACHE_ADDRESSES["follower"]), + guardian: GANACHE_ADDRESSES["advertiser"], + token: token_address, + nonce: Nonce::from(12345_u32), + } +} + +pub fn setup_eth_adapter( + sweeper_address: Option<[u8; 20]>, + outpace_address: Option<[u8; 20]>, + token_whitelist: Option<(Address, TokenInfo)>, +) -> EthereumAdapter { + let mut config = configuration("development", None).expect("failed parse config"); + let keystore_options = KeystoreOptions { + keystore_file: "./test/resources/keystore.json".to_string(), + keystore_pwd: "adexvalidator".to_string(), + }; + + if let Some(address) = sweeper_address { + config.sweeper_address = address; + } + + if let Some(address) = outpace_address { + config.outpace_address = address; + } + + if let Some((address, token_info)) = token_whitelist { + assert!( + config + .token_address_whitelist + .insert(address, token_info) + .is_none(), + "It should not contain the generated token prior to this call!" + ) + } + + EthereumAdapter::init(keystore_options, &config).expect("should init ethereum adapter") +} + pub async fn mock_set_balance( token_contract: &Contract, from: [u8; 20], @@ -92,6 +141,7 @@ pub async fn outpace_deposit( .await } +#[allow(dead_code)] pub async fn sweeper_sweep( sweeper_contract: &Contract, outpace_address: [u8; 20], @@ -127,7 +177,7 @@ pub async fn deploy_sweeper_contract( .confirmations(0) .options(Options::with(|opt| { opt.gas_price = Some(1.into()); - opt.gas = Some(6_721_975.into()); + opt.gas = Some(756_093.into()); })) .execute(*SWEEPER_BYTECODE, (), from_leader_account) }) @@ -150,7 +200,7 @@ pub async fn deploy_outpace_contract( .confirmations(0) .options(Options::with(|opt| { opt.gas_price = Some(1.into()); - opt.gas = Some(6_721_975.into()); + opt.gas = Some(2_390_256.into()); })) .execute(*OUTPACE_BYTECODE, (), from_leader_account) }) @@ -174,7 +224,7 @@ pub async fn deploy_token_contract( .confirmations(0) .options(Options::with(|opt| { opt.gas_price = Some(1.into()); - opt.gas = Some(6_721_975.into()); + opt.gas = Some(384_095.into()); })) .execute(*MOCK_TOKEN_BYTECODE, (), from_leader_account) }) diff --git a/primitives/src/adapter.rs b/primitives/src/adapter.rs index b28dd7b9f..f65f1a3a7 100644 --- a/primitives/src/adapter.rs +++ b/primitives/src/adapter.rs @@ -1,5 +1,5 @@ use crate::{ - channel::ChannelError, channel_v5::Channel, channel_validator::ChannelValidator, Address, + channel::ChannelError, channel_v5::Channel, Address, BigNum, DomainError, ValidatorId, }; use async_trait::async_trait; @@ -75,7 +75,7 @@ pub struct Session { } #[async_trait] -pub trait Adapter: ChannelValidator + Send + Sync + fmt::Debug + Clone { +pub trait Adapter: Send + Sync + fmt::Debug + Clone { type AdapterError: AdapterErrorKind + 'static; /// Unlock adapter From d62024d819cda72719e0a6112720461da1b2c015 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Wed, 12 May 2021 11:04:50 +0300 Subject: [PATCH 52/60] WIP try to fix sweeper_sweep --- adapter/src/ethereum.rs | 37 ++++++++++++++++-------------- adapter/src/ethereum/test_utils.rs | 22 +++++++++--------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index a8e5891bf..9ee3010ab 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -35,15 +35,15 @@ mod error; mod test_utils; lazy_static! { - static ref OUTPACE_ABI: &'static [u8] = - include_bytes!("../../lib/protocol-eth/abi/OUTPACE.json"); - static ref ERC20_ABI: &'static [u8] = include_str!("../../lib/protocol-eth/abi/ERC20.json") - .trim_end_matches('\n') - .as_bytes(); - static ref SWEEPER_ABI: &'static [u8] = - include_bytes!("../../lib/protocol-eth/abi/Sweeper.json"); - static ref DEPOSITOR_BYTECODE: &'static [u8] = - include_bytes!("../../lib/protocol-eth/resources/bytecode/Depositor.json"); + static ref OUTPACE_ABI: &'static str = include_str!("../../lib/protocol-eth/abi/OUTPACE.json"); + static ref ERC20_ABI: &'static str = include_str!("../../lib/protocol-eth/abi/ERC20.json"); + static ref SWEEPER_ABI: &'static str = include_str!("../../lib/protocol-eth/abi/Sweeper.json"); + /// Depositor bytecode, unwrapped from JSON + static ref DEPOSITOR_BYTECODE: &'static str = + include_str!("../../lib/protocol-eth/resources/bytecode/Depositor.json") + .trim_start_matches('"') + .trim_end_matches('\n') + .trim_end_matches('"'); } trait EthereumChannel { @@ -77,7 +77,7 @@ fn get_counterfactual_address( Token::Address(H160(*depositor.as_bytes())), ]); - let mut init_code = DEPOSITOR_BYTECODE.to_vec(); + let mut init_code = hex::decode(*DEPOSITOR_BYTECODE).expect("here"); init_code.extend(&encoded_params); let address = calc_addr(sweeper.as_fixed_bytes(), &salt, &init_code); @@ -272,18 +272,21 @@ impl Adapter for EthereumAdapter { let outpace_contract = Contract::from_json( self.web3.eth(), self.config.outpace_address.into(), - &OUTPACE_ABI, + OUTPACE_ABI.as_bytes(), ) .map_err(Error::ContractInitialization)?; - let erc20_contract = - Contract::from_json(self.web3.eth(), channel.token.as_bytes().into(), &ERC20_ABI) - .map_err(Error::ContractInitialization)?; + let erc20_contract = Contract::from_json( + self.web3.eth(), + channel.token.as_bytes().into(), + &ERC20_ABI.as_bytes(), + ) + .map_err(Error::ContractInitialization)?; let sweeper_contract = Contract::from_json( self.web3.eth(), self.config.sweeper_address.into(), - &SWEEPER_ABI, + SWEEPER_ABI.as_bytes(), ) .map_err(Error::ContractInitialization)?; @@ -777,7 +780,7 @@ mod test { // Run sweeper, it should clear the previously set create2 deposit and leave the total // TODO: Check why the `sweep()` is failing to run and remove the `allow(dead_code)` attr of `fn sweeper_sweep` - /* { + { sweeper_sweep( &sweeper.1, outpace.0.to_fixed_bytes(), @@ -800,6 +803,6 @@ mod test { }, swept_deposit ); - } */ + } } } diff --git a/adapter/src/ethereum/test_utils.rs b/adapter/src/ethereum/test_utils.rs index 9b33ed0b3..b80ebcf05 100644 --- a/adapter/src/ethereum/test_utils.rs +++ b/adapter/src/ethereum/test_utils.rs @@ -22,15 +22,15 @@ use super::{EthereumChannel, OUTPACE_ABI, SWEEPER_ABI}; // See `adex-eth-protocol` `contracts/mocks/Token.sol` lazy_static! { /// Mocked Token ABI - pub static ref MOCK_TOKEN_ABI: &'static [u8] = - include_bytes!("../../test/resources/mock_token_abi.json"); - /// Mocked Token bytecode + pub static ref MOCK_TOKEN_ABI: &'static str = + include_str!("../../test/resources/mock_token_abi.json"); + /// Mocked Token bytecode in JSON pub static ref MOCK_TOKEN_BYTECODE: &'static str = - include_str!("../../test/resources/mock_token_bytecode.json").trim_end_matches("\n"); - /// Sweeper bytecode - pub static ref SWEEPER_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/Sweeper.json").trim_end_matches("\n"); - /// Outpace bytecode - pub static ref OUTPACE_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/OUTPACE.json").trim_end_matches("\n"); + include_str!("../../test/resources/mock_token_bytecode.json").trim_end_matches('\n'); + /// Sweeper bytecode in JSON + pub static ref SWEEPER_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/Sweeper.json").trim_end_matches('\n'); + /// Outpace bytecode in JSON + pub static ref OUTPACE_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/OUTPACE.json").trim_end_matches('\n'); pub static ref GANACHE_ADDRESSES: HashMap = { vec![ ( @@ -172,7 +172,7 @@ pub async fn deploy_sweeper_contract( let from_leader_account = H160(*GANACHE_ADDRESSES["leader"].as_bytes()); let feature = tokio_compat_02::FutureExt::compat(async { - Contract::deploy(web3.eth(), &SWEEPER_ABI) + Contract::deploy(web3.eth(), SWEEPER_ABI.as_bytes()) .expect("Invalid ABI of Sweeper contract") .confirmations(0) .options(Options::with(|opt| { @@ -195,7 +195,7 @@ pub async fn deploy_outpace_contract( let from_leader_account = H160(*GANACHE_ADDRESSES["leader"].as_bytes()); let feature = tokio_compat_02::FutureExt::compat(async { - Contract::deploy(web3.eth(), &OUTPACE_ABI) + Contract::deploy(web3.eth(), OUTPACE_ABI.as_bytes()) .expect("Invalid ABI of Sweeper contract") .confirmations(0) .options(Options::with(|opt| { @@ -219,7 +219,7 @@ pub async fn deploy_token_contract( let from_leader_account = H160(*GANACHE_ADDRESSES["leader"].as_bytes()); let feature = tokio_compat_02::FutureExt::compat(async { - Contract::deploy(web3.eth(), &MOCK_TOKEN_ABI) + Contract::deploy(web3.eth(), MOCK_TOKEN_ABI.as_bytes()) .expect("Invalid ABI of Mock Token contract") .confirmations(0) .options(Options::with(|opt| { From 11b6e6514e56ffd989a1cfe82f15ea3e55ba3c99 Mon Sep 17 00:00:00 2001 From: samparsky <8148384+samparsky@users.noreply.github.com> Date: Thu, 13 May 2021 22:21:17 +0300 Subject: [PATCH 53/60] fix: sweeper test case --- .cargo/config | 0 Dockerfile-dev-sentry | 89 +++++++++++++++++++ adapter/src/ethereum.rs | 25 ++++-- adapter/src/ethereum/test_utils.rs | 14 +-- adapter/test/resources/mock_token_abi.json | 2 +- .../test/resources/mock_token_bytecode.bin | 1 + .../test/resources/mock_token_bytecode.json | 1 - lib/protocol-eth | 2 +- 8 files changed, 116 insertions(+), 18 deletions(-) create mode 100644 .cargo/config create mode 100644 Dockerfile-dev-sentry create mode 100644 adapter/test/resources/mock_token_bytecode.bin delete mode 100644 adapter/test/resources/mock_token_bytecode.json diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 000000000..e69de29bb diff --git a/Dockerfile-dev-sentry b/Dockerfile-dev-sentry new file mode 100644 index 000000000..56cf363b6 --- /dev/null +++ b/Dockerfile-dev-sentry @@ -0,0 +1,89 @@ +# Builder +FROM rust:1.48.0 as builder + +LABEL maintainer="dev@adex.network" + +WORKDIR /usr/src/app + +# A hack around the build step that will cache dependencies and make builds faster + +RUN mkdir -p primitives/src/ adapter/src/ sentry/src/ + +# primitives +COPY ./primitives/Cargo.toml ./primitives/Cargo.toml +# RUN touch ./primitives/src/main.rs && echo "pub fn main() {println!(\"cargo:rerun-if-changed=\\\"/tmp/build.rs\\\"\");}" >> ./primitives/src/main.rs +RUN touch ./primitives/src/lib.rs && echo "pub fn main() {println!(\"cargo:rerun-if-changed=\\\"/tmp/build.rs\\\"\");}" >> ./primitives/src/lib.rs + +# adapter +COPY ./adapter/Cargo.toml ./adapter/Cargo.toml +COPY ./Cargo.lock ./adapter/Cargo.lock + +# RUN touch ./adapter/src/main.rs && echo "fn main() {println!(\"cargo:rerun-if-changed=\\\"/tmp/build.rs\\\"\");}" >> ./adapter/src/main.rs +RUN touch ./adapter/src/lib.rs && echo "pub fn main() {println!(\"cargo:rerun-if-changed=\\\"/tmp/build.rs\\\"\");}" >> ./adapter/src/lib.rs + +# sentry +COPY ./sentry/Cargo.toml ./sentry/Cargo.toml +COPY ./Cargo.lock ./sentry/Cargo.lock +RUN touch ./sentry/src/main.rs && echo "fn main() {println!(\"cargo:rerun-if-changed=\\\"/tmp/build.rs\\\"\");}" >> ./sentry/src/main.rs +# RUN touch ./sentry/src/lib.rs && echo "pub fn main() {println!(\"cargo:rerun-if-changed=\\\"/tmp/build.rs\\\"\");}" >> ./sentry/src/lib.rs + +# workspace cargo configuration +COPY ./Cargo.lock ./Cargo.lock +RUN touch Cargo.toml && echo "[workspace]\n members = [ 'primitives', 'adapter', 'sentry' ]" >> Cargo.toml + +RUN cargo build -p sentry --release + +# remove the not needed build artifacts +RUN rm -f target/release/deps/sentry* +RUN rm -f target/release/deps/adapter* +RUN rm -f target/release/deps/primitives* +RUN rm -f target/release/deps/libadapter* +RUN rm -f target/release/deps/libprimitives* +RUN rm -f target/release/deps/libsentry* + +COPY . . + +# We install the sentry binary with all features in Release mode +# Inlcude the full backtrace for easier debugging + +RUN RUST_BACKTRACE=full cargo install --path sentry --all-features + +WORKDIR /usr/local/bin + +RUN cp $CARGO_HOME/bin/sentry . + +FROM rust:1.48.0 + +RUN apt update && apt-get install -y libssl-dev ca-certificates + +# `ethereum` or `dummy` +ENV ADAPTER= + +# only applicable if you use the `--adapter ethereum` +ENV KEYSTORE_FILE= +ENV KEYSTORE_PWD= + +# Only applicable if you use the `--adapter dummy` +ENV DUMMY_IDENTITY= + +# If set it will override the configuration file used +ENV CONFIG= + +WORKDIR /usr/local/bin + +COPY docs/config/cloudflare_origin.crt /usr/local/share/ca-certificates/ + +RUN update-ca-certificates + +RUN mkdir scripts + +COPY ./scripts/sentry-docker ./scripts + +COPY --from=builder /usr/local/bin/sentry . + +ENTRYPOINT ["./scripts/entrypoint.sh"] + +CMD sentry -a ${ADAPTER:-ethereum} \ + ${KEYSTORE_FILE:+-k $KEYSTORE_FILE} \ + ${DUMMY_IDENTITY:+-i $DUMMY_IDENTITY} \ + ${CONFIG} diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 9ee3010ab..e547d6c5f 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -35,15 +35,14 @@ mod error; mod test_utils; lazy_static! { - static ref OUTPACE_ABI: &'static str = include_str!("../../lib/protocol-eth/abi/OUTPACE.json"); - static ref ERC20_ABI: &'static str = include_str!("../../lib/protocol-eth/abi/ERC20.json"); - static ref SWEEPER_ABI: &'static str = include_str!("../../lib/protocol-eth/abi/Sweeper.json"); - /// Depositor bytecode, unwrapped from JSON - static ref DEPOSITOR_BYTECODE: &'static str = - include_str!("../../lib/protocol-eth/resources/bytecode/Depositor.json") - .trim_start_matches('"') - .trim_end_matches('\n') - .trim_end_matches('"'); + static ref OUTPACE_ABI: &'static [u8] = + include_bytes!("../../lib/protocol-eth/abi/OUTPACE.json"); + static ref ERC20_ABI: &'static [u8] = include_str!("../../lib/protocol-eth/abi/ERC20.json") + .trim_end_matches('\n') + .as_bytes(); + static ref SWEEPER_ABI: &'static [u8] = + include_bytes!("../../lib/protocol-eth/abi/Sweeper.json"); + static ref DEPOSITOR_BYTECODE: &'static str = include_str!("../../lib/protocol-eth/resources/bytecode/Depositor.bin"); } trait EthereumChannel { @@ -76,8 +75,13 @@ fn get_counterfactual_address( channel.tokenize(), Token::Address(H160(*depositor.as_bytes())), ]); +<<<<<<< HEAD let mut init_code = hex::decode(*DEPOSITOR_BYTECODE).expect("here"); +======= + + let mut init_code = hex::decode(*DEPOSITOR_BYTECODE).expect("decoded properly"); +>>>>>>> 29c861f... fix: sweeper test case init_code.extend(&encoded_params); let address = calc_addr(sweeper.as_fixed_bytes(), &salt, &init_code); @@ -679,6 +683,9 @@ mod test { let counterfactual_address = get_counterfactual_address(sweeper.0, &channel, outpace.0, &spender); + println!("{:?}", token_address); + println!("{:?}", counterfactual_address); + // No Regular nor Create2 deposits { let no_deposits = eth_adapter diff --git a/adapter/src/ethereum/test_utils.rs b/adapter/src/ethereum/test_utils.rs index b80ebcf05..9a1f0e757 100644 --- a/adapter/src/ethereum/test_utils.rs +++ b/adapter/src/ethereum/test_utils.rs @@ -26,11 +26,11 @@ lazy_static! { include_str!("../../test/resources/mock_token_abi.json"); /// Mocked Token bytecode in JSON pub static ref MOCK_TOKEN_BYTECODE: &'static str = - include_str!("../../test/resources/mock_token_bytecode.json").trim_end_matches('\n'); - /// Sweeper bytecode in JSON - pub static ref SWEEPER_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/Sweeper.json").trim_end_matches('\n'); - /// Outpace bytecode in JSON - pub static ref OUTPACE_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/OUTPACE.json").trim_end_matches('\n'); + include_str!("../../test/resources/mock_token_bytecode.bin").trim_end_matches("\n"); + /// Sweeper bytecode + pub static ref SWEEPER_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/Sweeper.bin").trim_end_matches("\n"); + /// Outpace bytecode + pub static ref OUTPACE_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/OUTPACE.json").trim_end_matches("\n"); pub static ref GANACHE_ADDRESSES: HashMap = { vec![ ( @@ -148,6 +148,8 @@ pub async fn sweeper_sweep( channel: &Channel, depositor: [u8; 20], ) -> web3::contract::Result { + let from_leader_account = H160(*GANACHE_ADDRESSES["leader"].as_bytes()); + tokio_compat_02::FutureExt::compat(sweeper_contract.call( "sweep", ( @@ -155,7 +157,7 @@ pub async fn sweeper_sweep( channel.tokenize(), Token::Array(vec![Token::Address(H160(depositor))]), ), - H160(depositor), + from_leader_account, Options::with(|opt| { opt.gas_price = Some(1.into()); // TODO: Check how much should this gas limit be! diff --git a/adapter/test/resources/mock_token_abi.json b/adapter/test/resources/mock_token_abi.json index a360e3352..237547b2e 100644 --- a/adapter/test/resources/mock_token_abi.json +++ b/adapter/test/resources/mock_token_abi.json @@ -1 +1 @@ -[{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"setBalanceTo","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}] \ No newline at end of file +[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"setBalanceTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/adapter/test/resources/mock_token_bytecode.bin b/adapter/test/resources/mock_token_bytecode.bin new file mode 100644 index 000000000..07d1c3750 --- /dev/null +++ b/adapter/test/resources/mock_token_bytecode.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b50610a8f806100206000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c8063095ea7b31461006757806323b872dd1461009757806370a08231146100c7578063a2b0a1c7146100f7578063a9059cbb14610113578063dd62ed3e14610143575b600080fd5b610081600480360381019061007c919061081d565b610173565b60405161008e919061089a565b60405180910390f35b6100b160048036038101906100ac91906107ce565b6101c3565b6040516100be919061089a565b60405180910390f35b6100e160048036038101906100dc9190610769565b61045c565b6040516100ee91906108d5565b60405180910390f35b610111600480360381019061010c919061081d565b6104a4565b005b61012d6004803603810190610128919061081d565b6104eb565b60405161013a919061089a565b60405180910390f35b61015d60048036038101906101589190610792565b6106f5565b60405161016a91906108d5565b60405180910390f35b600081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506001905092915050565b6000816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610246576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161023d906108b5565b60405180910390fd5b816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546102909190610957565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461031c9190610901565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205411156103ec576000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161044991906108d5565b60405180910390a3600190509392505050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505050565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561056e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610565906108b5565b60405180910390fd5b816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546105b89190610957565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546106449190610901565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516106e391906108d5565b60405180910390a36001905092915050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b60008135905061074e81610a2b565b92915050565b60008135905061076381610a42565b92915050565b60006020828403121561077b57600080fd5b60006107898482850161073f565b91505092915050565b600080604083850312156107a557600080fd5b60006107b38582860161073f565b92505060206107c48582860161073f565b9150509250929050565b6000806000606084860312156107e357600080fd5b60006107f18682870161073f565b93505060206108028682870161073f565b925050604061081386828701610754565b9150509250925092565b6000806040838503121561083057600080fd5b600061083e8582860161073f565b925050602061084f85828601610754565b9150509250929050565b6108628161099d565b82525050565b60006108756012836108f0565b915061088082610a02565b602082019050919050565b610894816109c9565b82525050565b60006020820190506108af6000830184610859565b92915050565b600060208201905081810360008301526108ce81610868565b9050919050565b60006020820190506108ea600083018461088b565b92915050565b600082825260208201905092915050565b600061090c826109c9565b9150610917836109c9565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561094c5761094b6109d3565b5b828201905092915050565b6000610962826109c9565b915061096d836109c9565b9250828210156109805761097f6109d3565b5b828203905092915050565b6000610996826109a9565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f494e53554646494349454e545f46554e44530000000000000000000000000000600082015250565b610a348161098b565b8114610a3f57600080fd5b50565b610a4b816109c9565b8114610a5657600080fd5b5056fea264697066735822122012d9e565a541ef14f604411fe60ee4679227706bb736ccd2d5aeb4962f73033e64736f6c63430008010033 \ No newline at end of file diff --git a/adapter/test/resources/mock_token_bytecode.json b/adapter/test/resources/mock_token_bytecode.json deleted file mode 100644 index 9107a4460..000000000 --- a/adapter/test/resources/mock_token_bytecode.json +++ /dev/null @@ -1 +0,0 @@ -"608060405234801561001057600080fd5b506105fd806100206000396000f3fe608060405234801561001057600080fd5b5060043610610069576000357c01000000000000000000000000000000000000000000000000000000009004806323b872dd1461006e57806370a08231146100f4578063a2b0a1c71461014c578063a9059cbb1461019a575b600080fd5b6100da6004803603606081101561008457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610200565b604051808215151515815260200191505060405180910390f35b6101366004803603602081101561010a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610386565b6040518082815260200191505060405180910390f35b6101986004803603604081101561016257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506103ce565b005b6101e6600480360360408110156101b057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610415565b604051808215151515815260200191505060405180910390f35b600061024a6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548361059a565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506102d46000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836105b3565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505050565b600061045f6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548361059a565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506104e96000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836105b3565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b60008282111515156105a857fe5b818303905092915050565b60008082840190508381101515156105c757fe5b809150509291505056fea165627a7a72305820868f9d98bc02466f02dddb8feb6fdc69bdb5c3169e8bb4a57ae1d6a259873d820029" diff --git a/lib/protocol-eth b/lib/protocol-eth index 4441aee1d..9afff6263 160000 --- a/lib/protocol-eth +++ b/lib/protocol-eth @@ -1 +1 @@ -Subproject commit 4441aee1ddea65abebac1d1cd1feef7fbcb2eeb5 +Subproject commit 9afff6263faebb0179b20e3685209c7a42ee9079 From 886cea01db100a82c604f6754ecc76fe12a2151e Mon Sep 17 00:00:00 2001 From: samparsky <8148384+samparsky@users.noreply.github.com> Date: Thu, 13 May 2021 22:26:27 +0300 Subject: [PATCH 54/60] fix: remove println --- Dockerfile-dev-sentry | 89 ----------------------------------------- adapter/src/ethereum.rs | 3 -- 2 files changed, 92 deletions(-) delete mode 100644 Dockerfile-dev-sentry diff --git a/Dockerfile-dev-sentry b/Dockerfile-dev-sentry deleted file mode 100644 index 56cf363b6..000000000 --- a/Dockerfile-dev-sentry +++ /dev/null @@ -1,89 +0,0 @@ -# Builder -FROM rust:1.48.0 as builder - -LABEL maintainer="dev@adex.network" - -WORKDIR /usr/src/app - -# A hack around the build step that will cache dependencies and make builds faster - -RUN mkdir -p primitives/src/ adapter/src/ sentry/src/ - -# primitives -COPY ./primitives/Cargo.toml ./primitives/Cargo.toml -# RUN touch ./primitives/src/main.rs && echo "pub fn main() {println!(\"cargo:rerun-if-changed=\\\"/tmp/build.rs\\\"\");}" >> ./primitives/src/main.rs -RUN touch ./primitives/src/lib.rs && echo "pub fn main() {println!(\"cargo:rerun-if-changed=\\\"/tmp/build.rs\\\"\");}" >> ./primitives/src/lib.rs - -# adapter -COPY ./adapter/Cargo.toml ./adapter/Cargo.toml -COPY ./Cargo.lock ./adapter/Cargo.lock - -# RUN touch ./adapter/src/main.rs && echo "fn main() {println!(\"cargo:rerun-if-changed=\\\"/tmp/build.rs\\\"\");}" >> ./adapter/src/main.rs -RUN touch ./adapter/src/lib.rs && echo "pub fn main() {println!(\"cargo:rerun-if-changed=\\\"/tmp/build.rs\\\"\");}" >> ./adapter/src/lib.rs - -# sentry -COPY ./sentry/Cargo.toml ./sentry/Cargo.toml -COPY ./Cargo.lock ./sentry/Cargo.lock -RUN touch ./sentry/src/main.rs && echo "fn main() {println!(\"cargo:rerun-if-changed=\\\"/tmp/build.rs\\\"\");}" >> ./sentry/src/main.rs -# RUN touch ./sentry/src/lib.rs && echo "pub fn main() {println!(\"cargo:rerun-if-changed=\\\"/tmp/build.rs\\\"\");}" >> ./sentry/src/lib.rs - -# workspace cargo configuration -COPY ./Cargo.lock ./Cargo.lock -RUN touch Cargo.toml && echo "[workspace]\n members = [ 'primitives', 'adapter', 'sentry' ]" >> Cargo.toml - -RUN cargo build -p sentry --release - -# remove the not needed build artifacts -RUN rm -f target/release/deps/sentry* -RUN rm -f target/release/deps/adapter* -RUN rm -f target/release/deps/primitives* -RUN rm -f target/release/deps/libadapter* -RUN rm -f target/release/deps/libprimitives* -RUN rm -f target/release/deps/libsentry* - -COPY . . - -# We install the sentry binary with all features in Release mode -# Inlcude the full backtrace for easier debugging - -RUN RUST_BACKTRACE=full cargo install --path sentry --all-features - -WORKDIR /usr/local/bin - -RUN cp $CARGO_HOME/bin/sentry . - -FROM rust:1.48.0 - -RUN apt update && apt-get install -y libssl-dev ca-certificates - -# `ethereum` or `dummy` -ENV ADAPTER= - -# only applicable if you use the `--adapter ethereum` -ENV KEYSTORE_FILE= -ENV KEYSTORE_PWD= - -# Only applicable if you use the `--adapter dummy` -ENV DUMMY_IDENTITY= - -# If set it will override the configuration file used -ENV CONFIG= - -WORKDIR /usr/local/bin - -COPY docs/config/cloudflare_origin.crt /usr/local/share/ca-certificates/ - -RUN update-ca-certificates - -RUN mkdir scripts - -COPY ./scripts/sentry-docker ./scripts - -COPY --from=builder /usr/local/bin/sentry . - -ENTRYPOINT ["./scripts/entrypoint.sh"] - -CMD sentry -a ${ADAPTER:-ethereum} \ - ${KEYSTORE_FILE:+-k $KEYSTORE_FILE} \ - ${DUMMY_IDENTITY:+-i $DUMMY_IDENTITY} \ - ${CONFIG} diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index e547d6c5f..dddf83594 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -683,9 +683,6 @@ mod test { let counterfactual_address = get_counterfactual_address(sweeper.0, &channel, outpace.0, &spender); - println!("{:?}", token_address); - println!("{:?}", counterfactual_address); - // No Regular nor Create2 deposits { let no_deposits = eth_adapter From 5a2997e126eed4553c9476e4ca68f50bdc9f28de Mon Sep 17 00:00:00 2001 From: samparsky <8148384+samparsky@users.noreply.github.com> Date: Fri, 14 May 2021 08:21:21 +0300 Subject: [PATCH 55/60] fix: out of gaserrors --- adapter/src/ethereum.rs | 11 +++-------- adapter/src/ethereum/test_utils.rs | 18 +++++++++--------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index dddf83594..050f1d71e 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -75,13 +75,8 @@ fn get_counterfactual_address( channel.tokenize(), Token::Address(H160(*depositor.as_bytes())), ]); -<<<<<<< HEAD - - let mut init_code = hex::decode(*DEPOSITOR_BYTECODE).expect("here"); -======= let mut init_code = hex::decode(*DEPOSITOR_BYTECODE).expect("decoded properly"); ->>>>>>> 29c861f... fix: sweeper test case init_code.extend(&encoded_params); let address = calc_addr(sweeper.as_fixed_bytes(), &salt, &init_code); @@ -276,21 +271,21 @@ impl Adapter for EthereumAdapter { let outpace_contract = Contract::from_json( self.web3.eth(), self.config.outpace_address.into(), - OUTPACE_ABI.as_bytes(), + &OUTPACE_ABI, ) .map_err(Error::ContractInitialization)?; let erc20_contract = Contract::from_json( self.web3.eth(), channel.token.as_bytes().into(), - &ERC20_ABI.as_bytes(), + &ERC20_ABI, ) .map_err(Error::ContractInitialization)?; let sweeper_contract = Contract::from_json( self.web3.eth(), self.config.sweeper_address.into(), - SWEEPER_ABI.as_bytes(), + &SWEEPER_ABI, ) .map_err(Error::ContractInitialization)?; diff --git a/adapter/src/ethereum/test_utils.rs b/adapter/src/ethereum/test_utils.rs index 9a1f0e757..1c3c3c69f 100644 --- a/adapter/src/ethereum/test_utils.rs +++ b/adapter/src/ethereum/test_utils.rs @@ -22,8 +22,8 @@ use super::{EthereumChannel, OUTPACE_ABI, SWEEPER_ABI}; // See `adex-eth-protocol` `contracts/mocks/Token.sol` lazy_static! { /// Mocked Token ABI - pub static ref MOCK_TOKEN_ABI: &'static str = - include_str!("../../test/resources/mock_token_abi.json"); + pub static ref MOCK_TOKEN_ABI: &'static [u8] = + include_bytes!("../../test/resources/mock_token_abi.json"); /// Mocked Token bytecode in JSON pub static ref MOCK_TOKEN_BYTECODE: &'static str = include_str!("../../test/resources/mock_token_bytecode.bin").trim_end_matches("\n"); @@ -161,7 +161,7 @@ pub async fn sweeper_sweep( Options::with(|opt| { opt.gas_price = Some(1.into()); // TODO: Check how much should this gas limit be! - opt.gas = Some(61_721_975.into()); + opt.gas = Some(6_721_975.into()); }), )) .await @@ -174,12 +174,12 @@ pub async fn deploy_sweeper_contract( let from_leader_account = H160(*GANACHE_ADDRESSES["leader"].as_bytes()); let feature = tokio_compat_02::FutureExt::compat(async { - Contract::deploy(web3.eth(), SWEEPER_ABI.as_bytes()) + Contract::deploy(web3.eth(), &SWEEPER_ABI) .expect("Invalid ABI of Sweeper contract") .confirmations(0) .options(Options::with(|opt| { opt.gas_price = Some(1.into()); - opt.gas = Some(756_093.into()); + opt.gas = Some(6_721_975.into()); })) .execute(*SWEEPER_BYTECODE, (), from_leader_account) }) @@ -197,12 +197,12 @@ pub async fn deploy_outpace_contract( let from_leader_account = H160(*GANACHE_ADDRESSES["leader"].as_bytes()); let feature = tokio_compat_02::FutureExt::compat(async { - Contract::deploy(web3.eth(), OUTPACE_ABI.as_bytes()) + Contract::deploy(web3.eth(), &OUTPACE_ABI) .expect("Invalid ABI of Sweeper contract") .confirmations(0) .options(Options::with(|opt| { opt.gas_price = Some(1.into()); - opt.gas = Some(2_390_256.into()); + opt.gas = Some(6_721_975.into()); })) .execute(*OUTPACE_BYTECODE, (), from_leader_account) }) @@ -221,12 +221,12 @@ pub async fn deploy_token_contract( let from_leader_account = H160(*GANACHE_ADDRESSES["leader"].as_bytes()); let feature = tokio_compat_02::FutureExt::compat(async { - Contract::deploy(web3.eth(), MOCK_TOKEN_ABI.as_bytes()) + Contract::deploy(web3.eth(), &MOCK_TOKEN_ABI) .expect("Invalid ABI of Mock Token contract") .confirmations(0) .options(Options::with(|opt| { opt.gas_price = Some(1.into()); - opt.gas = Some(384_095.into()); + opt.gas = Some(6_721_975.into()); })) .execute(*MOCK_TOKEN_BYTECODE, (), from_leader_account) }) From 16f11befd6c9011b274832b5e7e9fd2afa8c6f1f Mon Sep 17 00:00:00 2001 From: samparsky <8148384+samparsky@users.noreply.github.com> Date: Fri, 14 May 2021 08:27:20 +0300 Subject: [PATCH 56/60] update: Outpace bytecode file --- adapter/src/ethereum/test_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapter/src/ethereum/test_utils.rs b/adapter/src/ethereum/test_utils.rs index 1c3c3c69f..74e3f151a 100644 --- a/adapter/src/ethereum/test_utils.rs +++ b/adapter/src/ethereum/test_utils.rs @@ -30,7 +30,7 @@ lazy_static! { /// Sweeper bytecode pub static ref SWEEPER_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/Sweeper.bin").trim_end_matches("\n"); /// Outpace bytecode - pub static ref OUTPACE_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/OUTPACE.json").trim_end_matches("\n"); + pub static ref OUTPACE_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/OUTPACE.bin").trim_end_matches("\n"); pub static ref GANACHE_ADDRESSES: HashMap = { vec![ ( From badeecea629b531a672d15a809e9ea26627ce78a Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Fri, 14 May 2021 10:18:41 +0300 Subject: [PATCH 57/60] git - Update protocol-eth --- lib/protocol-eth | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protocol-eth b/lib/protocol-eth index 4441aee1d..9afff6263 160000 --- a/lib/protocol-eth +++ b/lib/protocol-eth @@ -1 +1 @@ -Subproject commit 4441aee1ddea65abebac1d1cd1feef7fbcb2eeb5 +Subproject commit 9afff6263faebb0179b20e3685209c7a42ee9079 From b02717193975b468672061b629d9787ec99b9ae1 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Mon, 17 May 2021 10:47:43 +0300 Subject: [PATCH 58/60] update protocol-eth --- adapter/src/ethereum.rs | 22 +++++++++++----------- adapter/src/ethereum/test_utils.rs | 7 +++---- lib/protocol-eth | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/adapter/src/ethereum.rs b/adapter/src/ethereum.rs index 050f1d71e..ce5e1a9fd 100644 --- a/adapter/src/ethereum.rs +++ b/adapter/src/ethereum.rs @@ -42,7 +42,11 @@ lazy_static! { .as_bytes(); static ref SWEEPER_ABI: &'static [u8] = include_bytes!("../../lib/protocol-eth/abi/Sweeper.json"); - static ref DEPOSITOR_BYTECODE: &'static str = include_str!("../../lib/protocol-eth/resources/bytecode/Depositor.bin"); + /// Ready to use init code (i.e. decoded) for calculating the create2 address + static ref DEPOSITOR_BYTECODE_DECODED: Vec = { + let bytecode = include_str!("../../lib/protocol-eth/resources/bytecode/Depositor.bin"); + hex::decode(bytecode).expect("Decoded properly") + }; } trait EthereumChannel { @@ -75,8 +79,8 @@ fn get_counterfactual_address( channel.tokenize(), Token::Address(H160(*depositor.as_bytes())), ]); - - let mut init_code = hex::decode(*DEPOSITOR_BYTECODE).expect("decoded properly"); + + let mut init_code = DEPOSITOR_BYTECODE_DECODED.clone(); init_code.extend(&encoded_params); let address = calc_addr(sweeper.as_fixed_bytes(), &salt, &init_code); @@ -165,7 +169,7 @@ impl Adapter for EthereumAdapter { } /// `state_root` is hex string which **should not** be `0x` prefixed - /// `sig` is hex string wihch **should be** `0x` prefixed + /// `sig` is hex string which **should be** `0x` prefixed fn verify( &self, signer: &ValidatorId, @@ -275,12 +279,9 @@ impl Adapter for EthereumAdapter { ) .map_err(Error::ContractInitialization)?; - let erc20_contract = Contract::from_json( - self.web3.eth(), - channel.token.as_bytes().into(), - &ERC20_ABI, - ) - .map_err(Error::ContractInitialization)?; + let erc20_contract = + Contract::from_json(self.web3.eth(), channel.token.as_bytes().into(), &ERC20_ABI) + .map_err(Error::ContractInitialization)?; let sweeper_contract = Contract::from_json( self.web3.eth(), @@ -778,7 +779,6 @@ mod test { } // Run sweeper, it should clear the previously set create2 deposit and leave the total - // TODO: Check why the `sweep()` is failing to run and remove the `allow(dead_code)` attr of `fn sweeper_sweep` { sweeper_sweep( &sweeper.1, diff --git a/adapter/src/ethereum/test_utils.rs b/adapter/src/ethereum/test_utils.rs index 74e3f151a..dad7193cf 100644 --- a/adapter/src/ethereum/test_utils.rs +++ b/adapter/src/ethereum/test_utils.rs @@ -26,11 +26,11 @@ lazy_static! { include_bytes!("../../test/resources/mock_token_abi.json"); /// Mocked Token bytecode in JSON pub static ref MOCK_TOKEN_BYTECODE: &'static str = - include_str!("../../test/resources/mock_token_bytecode.bin").trim_end_matches("\n"); + include_str!("../../test/resources/mock_token_bytecode.bin"); /// Sweeper bytecode - pub static ref SWEEPER_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/Sweeper.bin").trim_end_matches("\n"); + pub static ref SWEEPER_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/Sweeper.bin"); /// Outpace bytecode - pub static ref OUTPACE_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/OUTPACE.bin").trim_end_matches("\n"); + pub static ref OUTPACE_BYTECODE: &'static str = include_str!("../../../lib/protocol-eth/resources/bytecode/OUTPACE.bin"); pub static ref GANACHE_ADDRESSES: HashMap = { vec![ ( @@ -141,7 +141,6 @@ pub async fn outpace_deposit( .await } -#[allow(dead_code)] pub async fn sweeper_sweep( sweeper_contract: &Contract, outpace_address: [u8; 20], diff --git a/lib/protocol-eth b/lib/protocol-eth index 9afff6263..77748887d 160000 --- a/lib/protocol-eth +++ b/lib/protocol-eth @@ -1 +1 @@ -Subproject commit 9afff6263faebb0179b20e3685209c7a42ee9079 +Subproject commit 77748887d74bf861faf58dacad6d90b0c7224b82 From 0752b29258c2dae73cba3bc5f4ce1b991ff579f6 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Mon, 17 May 2021 10:48:58 +0300 Subject: [PATCH 59/60] remove empty file that Sam introduced --- .cargo/config | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .cargo/config diff --git a/.cargo/config b/.cargo/config deleted file mode 100644 index e69de29bb..000000000 From a466d7fbd1792cc81377881bb57e0b79830db526 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Mon, 17 May 2021 10:51:01 +0300 Subject: [PATCH 60/60] adapter - ethereum - remove todos --- adapter/src/ethereum/test_utils.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/adapter/src/ethereum/test_utils.rs b/adapter/src/ethereum/test_utils.rs index dad7193cf..0dbb4b5fb 100644 --- a/adapter/src/ethereum/test_utils.rs +++ b/adapter/src/ethereum/test_utils.rs @@ -134,8 +134,7 @@ pub async fn outpace_deposit( H160(to), Options::with(|opt| { opt.gas_price = Some(1.into()); - // TODO: Check how much should this gas limit be! - opt.gas = Some(61_721_975.into()); + opt.gas = Some(6_721_975.into()); }), )) .await @@ -159,7 +158,6 @@ pub async fn sweeper_sweep( from_leader_account, Options::with(|opt| { opt.gas_price = Some(1.into()); - // TODO: Check how much should this gas limit be! opt.gas = Some(6_721_975.into()); }), ))