From 5951653ae5496ffb84289f56ede5cfb86b329005 Mon Sep 17 00:00:00 2001 From: RichoKD Date: Mon, 9 Dec 2024 23:34:43 +0100 Subject: [PATCH 1/3] Feat: AutoSwap --- Cargo.lock | 1112 ++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 1 + src/http/auto_swap.rs | 106 ++++ src/http/mod.rs | 3 + src/http/types.rs | 28 ++ src/http/utils.rs | 114 +++++ 6 files changed, 1285 insertions(+), 79 deletions(-) create mode 100644 src/http/auto_swap.rs create mode 100644 src/http/utils.rs diff --git a/Cargo.lock b/Cargo.lock index bcb4d51..8668cc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,17 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + [[package]] name = "ahash" version = "0.8.11" @@ -65,6 +76,12 @@ version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + [[package]] name = "async-trait" version = "0.1.83" @@ -73,7 +90,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -91,6 +108,17 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" +[[package]] +name = "auto_impl" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", +] + [[package]] name = "autocfg" version = "1.4.0" @@ -104,11 +132,12 @@ dependencies = [ "anyhow", "axum", "dotenvy", - "hyper", - "reqwest", + "hyper 1.5.1", + "reqwest 0.12.9", "serde", "serde_json", "sqlx", + "starknet", "thiserror 2.0.3", "time", "tokio", @@ -116,7 +145,7 @@ dependencies = [ "tower-http", "tracing", "tracing-subscriber", - "uuid", + "uuid 1.11.0", ] [[package]] @@ -129,10 +158,10 @@ dependencies = [ "axum-core", "bytes", "futures-util", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.1", "http-body-util", - "hyper", + "hyper 1.5.1", "hyper-util", "itoa", "matchit", @@ -162,8 +191,8 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.1", "http-body-util", "mime", "pin-project-lite", @@ -189,6 +218,12 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "base64" version = "0.22.1" @@ -201,6 +236,12 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.6.0" @@ -210,6 +251,18 @@ dependencies = [ "serde", ] +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -225,6 +278,12 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +[[package]] +name = "byte-slice-cast" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" + [[package]] name = "byteorder" version = "1.5.0" @@ -261,9 +320,20 @@ dependencies = [ "android-tzdata", "iana-time-zone", "num-traits", + "serde", "windows-targets 0.52.6", ] +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -319,6 +389,15 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + [[package]] name = "crossbeam-queue" version = "0.3.11" @@ -334,6 +413,23 @@ version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -344,6 +440,50 @@ dependencies = [ "typenum", ] +[[package]] +name = "ctr" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +dependencies = [ + "cipher", +] + +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.89", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.89", +] + [[package]] name = "der" version = "0.7.9" @@ -362,6 +502,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", + "serde", ] [[package]] @@ -384,7 +525,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -438,6 +579,55 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "eth-keystore" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fda3bf123be441da5260717e0661c25a2fd9cb2b2c1d20bf2e05580047158ab" +dependencies = [ + "aes", + "ctr", + "digest", + "hex", + "hmac", + "pbkdf2", + "rand", + "scrypt", + "serde", + "serde_json", + "sha2", + "sha3", + "thiserror 1.0.69", + "uuid 0.8.2", +] + +[[package]] +name = "ethbloom" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c22d4b5885b6aa2fe5e8b9329fb8d232bf739e434e6b87347c63bdd00c120f60" +dependencies = [ + "crunchy", + "fixed-hash", + "impl-rlp", + "impl-serde", + "tiny-keccak", +] + +[[package]] +name = "ethereum-types" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" +dependencies = [ + "ethbloom", + "fixed-hash", + "impl-rlp", + "impl-serde", + "primitive-types", + "uint", +] + [[package]] name = "event-listener" version = "5.3.1" @@ -455,6 +645,28 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" +[[package]] +name = "fixed-hash" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" +dependencies = [ + "byteorder", + "rand", + "rustc-hex", + "static_assertions", +] + +[[package]] +name = "flate2" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "flume" version = "0.11.1" @@ -496,6 +708,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "futures-channel" version = "0.3.31" @@ -585,8 +803,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -595,6 +815,25 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +[[package]] +name = "h2" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.12", + "indexmap 2.6.0", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "h2" version = "0.4.7" @@ -606,14 +845,20 @@ dependencies = [ "fnv", "futures-core", "futures-sink", - "http", - "indexmap", + "http 1.1.0", + "indexmap 2.6.0", "slab", "tokio", "tokio-util", "tracing", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "hashbrown" version = "0.14.5" @@ -684,6 +929,17 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http" version = "1.1.0" @@ -695,6 +951,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http 0.2.12", + "pin-project-lite", +] + [[package]] name = "http-body" version = "1.0.1" @@ -702,7 +969,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", - "http", + "http 1.1.0", ] [[package]] @@ -713,8 +980,8 @@ checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" dependencies = [ "bytes", "futures-util", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.1", "pin-project-lite", ] @@ -736,6 +1003,30 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "hyper" +version = "0.14.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c08302e8fa335b151b788c775ff56e7a03ae64ff85c548ee820fecb70356e85" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2 0.3.26", + "http 0.2.12", + "http-body 0.4.6", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + [[package]] name = "hyper" version = "1.5.1" @@ -745,9 +1036,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", - "http", - "http-body", + "h2 0.4.7", + "http 1.1.0", + "http-body 1.0.1", "httparse", "httpdate", "itoa", @@ -757,6 +1048,20 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-rustls" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" +dependencies = [ + "futures-util", + "http 0.2.12", + "hyper 0.14.31", + "rustls 0.21.12", + "tokio", + "tokio-rustls 0.24.1", +] + [[package]] name = "hyper-rustls" version = "0.27.3" @@ -764,13 +1069,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ "futures-util", - "http", - "hyper", + "http 1.1.0", + "hyper 1.5.1", "hyper-util", - "rustls", + "rustls 0.23.17", "rustls-pki-types", "tokio", - "tokio-rustls", + "tokio-rustls 0.26.0", "tower-service", ] @@ -782,7 +1087,7 @@ checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", "http-body-util", - "hyper", + "hyper 1.5.1", "hyper-util", "native-tls", "tokio", @@ -799,9 +1104,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "http", - "http-body", - "hyper", + "http 1.1.0", + "http-body 1.0.1", + "hyper 1.5.1", "pin-project-lite", "socket2", "tokio", @@ -947,9 +1252,15 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "1.0.3" @@ -971,6 +1282,55 @@ dependencies = [ "icu_properties", ] +[[package]] +name = "impl-codec" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "impl-rlp" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28220f89297a075ddc7245cd538076ee98b01f2a9c23a53a4f1105d5a322808" +dependencies = [ + "rlp", +] + +[[package]] +name = "impl-serde" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc88fc67028ae3db0c853baa36269d398d5f45b6982f95549ff5def78c935cd" +dependencies = [ + "serde", +] + +[[package]] +name = "impl-trait-for-tuples" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0eb5a3343abf848c0984fe4604b2b105da9539376e24fc0a3b0007411ae4fd9" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", +] + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + [[package]] name = "indexmap" version = "2.6.0" @@ -979,6 +1339,16 @@ checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", "hashbrown 0.15.1", + "serde", +] + +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array", ] [[package]] @@ -1002,6 +1372,37 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "lambdaworks-crypto" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbc2a4da0d9e52ccfe6306801a112e81a8fc0c76aa3e4449fefeda7fef72bb34" +dependencies = [ + "lambdaworks-math", + "serde", + "sha2", + "sha3", +] + +[[package]] +name = "lambdaworks-math" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1bd2632acbd9957afc5aeec07ad39f078ae38656654043bf16e046fa2730e23" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -1173,6 +1574,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + [[package]] name = "num-bigint-dig" version = "0.8.4" @@ -1247,7 +1658,7 @@ version = "0.10.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" dependencies = [ - "bitflags", + "bitflags 2.6.0", "cfg-if", "foreign-types", "libc", @@ -1264,7 +1675,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -1291,6 +1702,32 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +[[package]] +name = "parity-scale-codec" +version = "3.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "306800abfa29c7f16596b5970a588435e3d5b3149683d00c12b699cc19f895ee" +dependencies = [ + "arrayvec", + "bitvec", + "byte-slice-cast", + "impl-trait-for-tuples", + "parity-scale-codec-derive", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "parking" version = "2.2.1" @@ -1326,6 +1763,15 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest", +] + [[package]] name = "pem-rfc7468" version = "0.7.0" @@ -1395,6 +1841,28 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "primitive-types" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" +dependencies = [ + "fixed-hash", + "impl-codec", + "impl-rlp", + "impl-serde", + "uint", +] + +[[package]] +name = "proc-macro-crate" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" +dependencies = [ + "toml_edit", +] + [[package]] name = "proc-macro2" version = "1.0.91" @@ -1413,6 +1881,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "rand" version = "0.8.5" @@ -1449,7 +1923,7 @@ version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ - "bitflags", + "bitflags 2.6.0", ] [[package]] @@ -1496,23 +1970,64 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "reqwest" +version = "0.11.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" +dependencies = [ + "base64 0.21.7", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2 0.3.26", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.31", + "hyper-rustls 0.24.2", + "ipnet", + "js-sys", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls 0.21.12", + "rustls-pemfile 1.0.4", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper 0.1.2", + "system-configuration 0.5.1", + "tokio", + "tokio-rustls 0.24.1", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots 0.25.4", + "winreg", +] + [[package]] name = "reqwest" version = "0.12.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f" dependencies = [ - "base64", + "base64 0.22.1", "bytes", "encoding_rs", "futures-core", "futures-util", - "h2", - "http", - "http-body", + "h2 0.4.7", + "http 1.1.0", + "http-body 1.0.1", "http-body-util", - "hyper", - "hyper-rustls", + "hyper 1.5.1", + "hyper-rustls 0.27.3", "hyper-tls", "hyper-util", "ipnet", @@ -1523,12 +2038,12 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls-pemfile", + "rustls-pemfile 2.2.0", "serde", "serde_json", "serde_urlencoded", "sync_wrapper 1.0.2", - "system-configuration", + "system-configuration 0.6.1", "tokio", "tokio-native-tls", "tower-service", @@ -1539,6 +2054,16 @@ dependencies = [ "windows-registry", ] +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + [[package]] name = "ring" version = "0.17.8" @@ -1554,6 +2079,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rlp" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb919243f34364b6bd2fc10ef797edbfa75f33c252e7998527479c6d6b47e1ec" +dependencies = [ + "bytes", + "rustc-hex", +] + [[package]] name = "rsa" version = "0.9.6" @@ -1580,17 +2115,35 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc-hex" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" + [[package]] name = "rustix" version = "0.38.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" +checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" +dependencies = [ + "bitflags 2.6.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.21.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", + "log", + "ring", + "rustls-webpki 0.101.7", + "sct", ] [[package]] @@ -1602,11 +2155,20 @@ dependencies = [ "once_cell", "ring", "rustls-pki-types", - "rustls-webpki", + "rustls-webpki 0.102.8", "subtle", "zeroize", ] +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64 0.21.7", +] + [[package]] name = "rustls-pemfile" version = "2.2.0" @@ -1622,6 +2184,16 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "rustls-webpki" version = "0.102.8" @@ -1645,6 +2217,15 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "salsa20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" +dependencies = [ + "cipher", +] + [[package]] name = "schannel" version = "0.1.27" @@ -1660,13 +2241,35 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "scrypt" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f9e24d2b632954ded8ab2ef9fea0a0c769ea56ea98bddbafbad22caeeadf45d" +dependencies = [ + "hmac", + "pbkdf2", + "salsa20", + "sha2", +] + +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "security-framework" version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ - "bitflags", + "bitflags 2.6.0", "core-foundation", "core-foundation-sys", "libc", @@ -1700,7 +2303,7 @@ checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -1715,6 +2318,17 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_json_pythonic" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62212da9872ca2a0cad0093191ee33753eddff9266cbbc1b4a602d13a3a768db" +dependencies = [ + "itoa", + "ryu", + "serde", +] + [[package]] name = "serde_path_to_error" version = "0.1.16" @@ -1737,6 +2351,36 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e28bdad6db2b8340e449f7108f020b3b092e8583a9e3fb82713e1d4e71fe817" +dependencies = [ + "base64 0.22.1", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.6.0", + "serde", + "serde_derive", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d846214a9854ef724f3da161b426242d8de7c1fc7de2f89bb1efcb154dca79d" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.89", +] + [[package]] name = "sha1" version = "0.10.6" @@ -1759,6 +2403,16 @@ dependencies = [ "digest", ] +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest", + "keccak", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -1885,14 +2539,14 @@ dependencies = [ "hashbrown 0.14.5", "hashlink", "hex", - "indexmap", + "indexmap 2.6.0", "log", "memchr", "once_cell", "paste", "percent-encoding", - "rustls", - "rustls-pemfile", + "rustls 0.23.17", + "rustls-pemfile 2.2.0", "serde", "serde_json", "sha2", @@ -1903,8 +2557,8 @@ dependencies = [ "tokio-stream", "tracing", "url", - "uuid", - "webpki-roots", + "uuid 1.11.0", + "webpki-roots 0.26.7", ] [[package]] @@ -1917,7 +2571,7 @@ dependencies = [ "quote", "sqlx-core", "sqlx-macros-core", - "syn", + "syn 2.0.89", ] [[package]] @@ -1940,7 +2594,7 @@ dependencies = [ "sqlx-mysql", "sqlx-postgres", "sqlx-sqlite", - "syn", + "syn 2.0.89", "tempfile", "tokio", "url", @@ -1953,8 +2607,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64bb4714269afa44aef2755150a0fc19d756fb580a67db8885608cf02f47d06a" dependencies = [ "atoi", - "base64", - "bitflags", + "base64 0.22.1", + "bitflags 2.6.0", "byteorder", "bytes", "chrono", @@ -1986,7 +2640,7 @@ dependencies = [ "stringprep", "thiserror 1.0.69", "tracing", - "uuid", + "uuid 1.11.0", "whoami", ] @@ -1997,8 +2651,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fa91a732d854c5d7726349bb4bb879bb9478993ceb764247660aee25f67c2f8" dependencies = [ "atoi", - "base64", - "bitflags", + "base64 0.22.1", + "bitflags 2.6.0", "byteorder", "chrono", "crc", @@ -2026,7 +2680,7 @@ dependencies = [ "stringprep", "thiserror 1.0.69", "tracing", - "uuid", + "uuid 1.11.0", "whoami", ] @@ -2052,7 +2706,7 @@ dependencies = [ "sqlx-core", "tracing", "url", - "uuid", + "uuid 1.11.0", ] [[package]] @@ -2061,6 +2715,170 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +[[package]] +name = "starknet" +version = "0.12.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs#093d5ecbbd0929720db38a1ca34d516ccb807398" +dependencies = [ + "starknet-accounts", + "starknet-contract", + "starknet-core", + "starknet-core-derive", + "starknet-crypto", + "starknet-macros", + "starknet-providers", + "starknet-signers", +] + +[[package]] +name = "starknet-accounts" +version = "0.11.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs#093d5ecbbd0929720db38a1ca34d516ccb807398" +dependencies = [ + "async-trait", + "auto_impl", + "starknet-core", + "starknet-crypto", + "starknet-providers", + "starknet-signers", + "thiserror 1.0.69", +] + +[[package]] +name = "starknet-contract" +version = "0.11.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs#093d5ecbbd0929720db38a1ca34d516ccb807398" +dependencies = [ + "serde", + "serde_json", + "serde_with", + "starknet-accounts", + "starknet-core", + "starknet-providers", + "thiserror 1.0.69", +] + +[[package]] +name = "starknet-core" +version = "0.12.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs#093d5ecbbd0929720db38a1ca34d516ccb807398" +dependencies = [ + "base64 0.21.7", + "crypto-bigint", + "flate2", + "hex", + "num-traits", + "serde", + "serde_json", + "serde_json_pythonic", + "serde_with", + "sha3", + "starknet-core-derive", + "starknet-crypto", + "starknet-types-core", +] + +[[package]] +name = "starknet-core-derive" +version = "0.1.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs#093d5ecbbd0929720db38a1ca34d516ccb807398" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", +] + +[[package]] +name = "starknet-crypto" +version = "0.7.3" +source = "git+https://github.com/xJonathanLEI/starknet-rs#093d5ecbbd0929720db38a1ca34d516ccb807398" +dependencies = [ + "crypto-bigint", + "hex", + "hmac", + "num-bigint", + "num-integer", + "num-traits", + "rfc6979", + "sha2", + "starknet-curve", + "starknet-types-core", + "zeroize", +] + +[[package]] +name = "starknet-curve" +version = "0.5.1" +source = "git+https://github.com/xJonathanLEI/starknet-rs#093d5ecbbd0929720db38a1ca34d516ccb807398" +dependencies = [ + "starknet-types-core", +] + +[[package]] +name = "starknet-macros" +version = "0.2.1" +source = "git+https://github.com/xJonathanLEI/starknet-rs#093d5ecbbd0929720db38a1ca34d516ccb807398" +dependencies = [ + "starknet-core", + "syn 2.0.89", +] + +[[package]] +name = "starknet-providers" +version = "0.12.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs#093d5ecbbd0929720db38a1ca34d516ccb807398" +dependencies = [ + "async-trait", + "auto_impl", + "ethereum-types", + "flate2", + "getrandom", + "log", + "reqwest 0.11.27", + "serde", + "serde_json", + "serde_with", + "starknet-core", + "thiserror 1.0.69", + "url", +] + +[[package]] +name = "starknet-signers" +version = "0.10.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs#093d5ecbbd0929720db38a1ca34d516ccb807398" +dependencies = [ + "async-trait", + "auto_impl", + "crypto-bigint", + "eth-keystore", + "getrandom", + "rand", + "starknet-core", + "starknet-crypto", + "thiserror 1.0.69", +] + +[[package]] +name = "starknet-types-core" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa1b9e01ccb217ab6d475c5cda05dbb22c30029f7bb52b192a010a00d77a3d74" +dependencies = [ + "lambdaworks-crypto", + "lambdaworks-math", + "num-bigint", + "num-integer", + "num-traits", + "serde", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "stringprep" version = "0.1.5" @@ -2072,12 +2890,29 @@ dependencies = [ "unicode-properties", ] +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "subtle" version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.89" @@ -2112,7 +2947,18 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", +] + +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys 0.5.0", ] [[package]] @@ -2121,9 +2967,19 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ - "bitflags", + "bitflags 2.6.0", "core-foundation", - "system-configuration-sys", + "system-configuration-sys 0.6.0", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", ] [[package]] @@ -2136,6 +2992,12 @@ dependencies = [ "libc", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "tempfile" version = "3.14.0" @@ -2175,7 +3037,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -2186,7 +3048,7 @@ checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -2230,6 +3092,15 @@ dependencies = [ "time-core", ] +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "tinystr" version = "0.7.6" @@ -2281,7 +3152,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -2294,13 +3165,23 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls 0.21.12", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "rustls", + "rustls 0.23.17", "rustls-pki-types", "tokio", ] @@ -2329,6 +3210,23 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" + +[[package]] +name = "toml_edit" +version = "0.22.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" +dependencies = [ + "indexmap 2.6.0", + "toml_datetime", + "winnow", +] + [[package]] name = "tower" version = "0.5.1" @@ -2351,11 +3249,11 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "403fa3b783d4b626a8ad51d766ab03cb6d2dbfc46b1c5d4448395e6628dc9697" dependencies = [ - "bitflags", + "bitflags 2.6.0", "bytes", "futures-util", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.1", "http-body-util", "http-range-header", "httpdate", @@ -2368,7 +3266,7 @@ dependencies = [ "tower-layer", "tower-service", "tracing", - "uuid", + "uuid 1.11.0", ] [[package]] @@ -2403,7 +3301,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -2470,6 +3368,18 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + [[package]] name = "unicase" version = "2.8.0" @@ -2538,6 +3448,16 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "getrandom", + "serde", +] + [[package]] name = "uuid" version = "1.11.0" @@ -2609,7 +3529,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.89", "wasm-bindgen-shared", ] @@ -2643,7 +3563,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2664,6 +3584,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.25.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" + [[package]] name = "webpki-roots" version = "0.26.7" @@ -2892,6 +3818,25 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" +dependencies = [ + "memchr", +] + +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + [[package]] name = "write16" version = "1.0.0" @@ -2904,6 +3849,15 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + [[package]] name = "yoke" version = "0.7.4" @@ -2924,7 +3878,7 @@ checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", "synstructure", ] @@ -2946,7 +3900,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -2966,7 +3920,7 @@ checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", "synstructure", ] @@ -2995,5 +3949,5 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] diff --git a/Cargo.toml b/Cargo.toml index cd316b6..e9ca504 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,3 +42,4 @@ uuid = { version = "1.11.0", features = ["v7", "serde"] } serde_json = "1.0.133" thiserror = "2.0.3" time = { version = "0.3.36", features = ["formatting", "parsing"] } +starknet = { git = "https://github.com/xJonathanLEI/starknet-rs" } \ No newline at end of file diff --git a/src/http/auto_swap.rs b/src/http/auto_swap.rs new file mode 100644 index 0000000..a29d29c --- /dev/null +++ b/src/http/auto_swap.rs @@ -0,0 +1,106 @@ +use crate::AppState; +use crate::api_error::ApiError; + +use axum::{extract::State, http::StatusCode, Json}; + +use serde_json::{json, Value}; + +use super::types::{AutoSwapRequest, AutoSwapResponse, SubscriptionData, SwapSubscriptionFromTokenData}; +use super::utils::{validate_address, call_contract}; +// use crate::api_error::ApiError; + + +pub async fn auto_swap_q( + State(app_state): State, + Json(payload): Json, +) -> Result, StatusCode> { + + println!("RRRR: {:#?}", app_state.config.env); + + println!("Payload: {:#?}", payload); + + // function body here + Ok(Json(AutoSwapResponse { + status: "success".to_string(), + message: "Auto swap started".to_string(), + })) +} + +pub async fn auto_swap( + State(app_state): State, + Json(payload): Json, +) -> Result, ApiError> { + + // validate_address(&payload.from)?; + // validate_address(&payload.to); + + if !payload.from.starts_with("0x") && payload.from.len() != 42 { + return Err(ApiError::InvalidRequest( + "Invalid 'from' address format".to_string(), + )); + } + + if !payload.to.starts_with("0x") && payload.to.len() != 42 { + return Err(ApiError::InvalidRequest( + "Invalid 'to' address format".to_string(), + )); + } + + // call_contract().await; + + // if !payload.from.starts_with("0x") && payload.from.len() != 42 { + // return Err(ApiError::InvalidRequest( + // "Invalid token address format".to_string(), + // )); + // } + + println!("RRRR: {:#?}", app_state.config.env); + + println!("Payload: {:#?}", payload); + + + // let row: Subscription_data = sqlx::query_as::<_, Subscription_data>( + // r#" + // SELECT + // wallet_address, + // to_token, + // is_active, + // FROM swap_subscription + // WHERE wallet_address = $1 + // "#, + // ) + // .bind(payload.to) + // .fetch_one(&app_state.db.pool) + // .await + // .map_err(ApiError::DatabaseError)?; + + // if !row.is_active { + // return Err(ApiError::InvalidRequest( + // "Subscription is not active".to_string(), + // )); + // } + + + // let row2: Swap_subscription_from_token_data = sqlx::query_as::<_, Swap_subscription_from_token_data>( + // r#" + // SELECT + // wallet_address, + // from_token, + // percentage + // FROM swap_subscription + // WHERE wallet_address = $1 + // "#, + // ) + // .bind(row.wallet_address) + // .fetch_one(&app_state.db.pool) + // .await + // .map_err(ApiError::DatabaseError)?; + + // call_contract().await; + + // Ok(Json(json!({"status":"success"}))) + Ok(Json(AutoSwapResponse { + status: "success".to_string(), + message: "Auto swap started".to_string(), + })) +} \ No newline at end of file diff --git a/src/http/mod.rs b/src/http/mod.rs index 9bdc2a1..932e9f6 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -8,6 +8,8 @@ mod subscription; mod transaction_logs; mod types; mod unsubscription; +mod auto_swap; +mod utils; use crate::AppState; // Application router. @@ -22,4 +24,5 @@ pub fn router() -> Router { .route("/unsubscribe", post(unsubscription::handle_unsubscribe)) .route("/subscriptions", post(subscription::create_subscription)) .route("/log_retrieval", get(activity_log_retrieval::log_retrieval)) + .route("/auto_swaper", post(auto_swap::auto_swap)) } diff --git a/src/http/types.rs b/src/http/types.rs index 97b465f..8590cac 100644 --- a/src/http/types.rs +++ b/src/http/types.rs @@ -28,6 +28,34 @@ pub struct ActivityLogGetResponse { pub next_cursor: Option, } +#[derive(FromRow, Debug, Serialize)] +pub struct SubscriptionData { + pub wallet_address: String, + pub to_token: String, + pub is_active: bool +} + +#[derive(FromRow, Debug, Serialize)] +pub struct SwapSubscriptionFromTokenData { + pub wallet_address: String, + pub from_token: String, + pub percentage: i16 +} + + +#[derive(Debug, Serialize, Deserialize)] +pub struct AutoSwapRequest { + pub from : String, + pub to : String, + pub value : i64 +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct AutoSwapResponse { + pub status: String, + pub message: String +} + #[derive(Debug, Deserialize)] pub struct CreateSubscriptionRequest { pub wallet_address: String, diff --git a/src/http/utils.rs b/src/http/utils.rs new file mode 100644 index 0000000..fc55a63 --- /dev/null +++ b/src/http/utils.rs @@ -0,0 +1,114 @@ +use crate::api_error::ApiError; + +use starknet::{ + contract, core::types::{BlockId, BlockTag, Felt, FunctionCall}, macros::{felt, selector}, providers::{ + jsonrpc::{HttpTransport, JsonRpcClient}, + Provider, Url, + } +}; + +// pub async fn call_contract() { +// let provider = JsonRpcClient::new(HttpTransport::new( +// Url::parse("https://free-rpc.nethermind.io/sepolia-juno/").unwrap(), +// )); + +// let contract_address = +// felt!("0x55abee888d949203f3973ad9ad725fd7c57c8d5da79a6756ef0473af86af863"); + +// let storage_key = felt!("0x0389b73ec450d58472d9fbf78e97bcd7fe290cc445373ae2c2018c8a87f113c3"); +// let block_id = BlockId::Tag(BlockTag::Latest); + +// // Fetch storage value +// match provider.get_storage_at(contract_address, storage_key, block_id).await { +// Ok(call_result) => { +// println!("Call result (raw): {:?}", call_result); + +// // Optional: Convert `call_result` to `i64` if meaningful +// if let Some(decoded_result) = call_result.to_bytes_be().try_into().ok() { +// let decoded_value = i64::from_be_bytes(decoded_result); +// println!("Decoded call result: {}", decoded_value); +// } else { +// println!("Failed to decode call result."); +// } +// } +// Err(err) => { +// eprintln!("Failed to fetch storage: {:?}", err); +// } +// } +// } + + +pub async fn call_contract(provider_url: &str, contract_address: &str ) { + let provider = JsonRpcClient::new(HttpTransport::new( + Url::parse("https://free-rpc.nethermind.io/sepolia-juno/").unwrap(), + )); + + let contract_address = + felt!("0x55abee888d949203f3973ad9ad725fd7c57c8d5da79a6756ef0473af86af863"); + + let block_id = BlockId::Tag(BlockTag::Latest); + let call_result = + provider + .get_storage_at(contract_address, felt!("0x0389b73ec450d58472d9fbf78e97bcd7fe290cc445373ae2c2018c8a87f113c3"), block_id) + .await + .expect("failed to call contract"); + + + // .call( + + // FunctionCall { + // contract_address: tst_token_address, + // entry_point_selector: selector!("name"), + // calldata: vec![ + // Felt::from_hex("0x6b94abf5540e1e0602150a650749ddad92bb784a517b28f7aa836ad7fd3c4bc").unwrap() + // ], + // }, + // BlockId::Tag(BlockTag::Latest), + // ) + // .await + // .expect("failed to call contract"); + + // let result: i64 = call_result; + println!( + "Call result: {}", call_result + // hex::decode(call_result.to_hex()).unwrap().try_into().unwrap() + ); + // dbg!(call_result); +} + +// use starknet::core::types::FieldElement; +// use starknet::providers::{Provider, StarknetProvider}; +// use starknet::signers::{LocalWallet, Signer}; +// use starknet::accounts::{Account, Execution}; + +// async fn invoke_starknet_contract(app_state: &AppState, contract_address: &str, method_name: &str, params: Vec) -> Result<(), ApiError> { +// // Initialize the provider +// let provider = StarknetProvider::new(&app_state.starknet_rpc_url); + +// // Initialize the wallet +// let wallet = LocalWallet::from_private_key(app_state.private_key); + +// // Initialize the account +// let account = Account::new(provider, wallet); + +// // Prepare the execution +// let execution = Execution::new(contract_address) +// .method(method_name) +// .args(params); + +// // Execute the transaction +// account.execute(execution).await.map_err(|_| ApiError::ContractExecutionError)?; + +// Ok(()) +// } + + +pub fn validate_address(address: &str) -> Result { + if !address.starts_with("0x") && address.len() != 42 { + return Err(ApiError::InvalidRequest( + "Invalid token address format".to_string(), + )); + } + + Ok(true) +} From 2e57b4b693534bf1a4677ef4e0c3e70a6d72fc29 Mon Sep 17 00:00:00 2001 From: RichoKD Date: Tue, 17 Dec 2024 14:00:22 +0100 Subject: [PATCH 2/3] Feat: Updated AutoSwap service --- src/config.rs | 20 +++++++ src/http/auto_swap.rs | 106 ------------------------------------ src/http/mod.rs | 2 - src/http/types.rs | 17 +++--- src/http/utils.rs | 114 --------------------------------------- src/main.rs | 14 ++++- src/service/auto_swap.rs | 89 ++++++++++++++++++++++++++++++ src/service/mod.rs | 1 + 8 files changed, 130 insertions(+), 233 deletions(-) delete mode 100644 src/http/auto_swap.rs delete mode 100644 src/http/utils.rs create mode 100644 src/service/auto_swap.rs diff --git a/src/config.rs b/src/config.rs index 5972a53..d4852cd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -16,6 +16,11 @@ pub struct Configuration { pub app_port: u16, pub db_str: String, pub db_pool_max_size: u32, + pub rpc_url: String, + pub private_key: String, + pub owner_address: String, + pub autoswap_contract: String, + pub token_address: String, } // Environment application is running in. @@ -46,6 +51,16 @@ impl Configuration { // 0.0.0.0 + Port to support containerisation. let listen_address = SocketAddr::from((Ipv6Addr::UNSPECIFIED, app_port)); + let rpc_url = env_var("STARKNET_RPC_URL") + .parse::() + .expect("Unable to parse the value of the STARKNET_RPC_URL environment variable. Please make sure it is a valid string."); + + let autoswap_contract = env_var("AUTOSWAP_CONTRACT_ADDRESS") + .parse::() + .expect("Unable to parse the value of the EKUBO_CONTRACT environment variable. Please make sure it is a valid string."); + + let token_address = env_var("TOKEN_ADDRESS"); + // Configuration values to be safely shared across requests. Arc::new(Configuration { env, @@ -53,6 +68,11 @@ impl Configuration { app_port, db_str, db_pool_max_size, + rpc_url, + private_key: env_var("PRIVATE_KEY"), + owner_address: env_var("OWNER_ADDRESS"), + autoswap_contract, + token_address, }) } diff --git a/src/http/auto_swap.rs b/src/http/auto_swap.rs deleted file mode 100644 index a29d29c..0000000 --- a/src/http/auto_swap.rs +++ /dev/null @@ -1,106 +0,0 @@ -use crate::AppState; -use crate::api_error::ApiError; - -use axum::{extract::State, http::StatusCode, Json}; - -use serde_json::{json, Value}; - -use super::types::{AutoSwapRequest, AutoSwapResponse, SubscriptionData, SwapSubscriptionFromTokenData}; -use super::utils::{validate_address, call_contract}; -// use crate::api_error::ApiError; - - -pub async fn auto_swap_q( - State(app_state): State, - Json(payload): Json, -) -> Result, StatusCode> { - - println!("RRRR: {:#?}", app_state.config.env); - - println!("Payload: {:#?}", payload); - - // function body here - Ok(Json(AutoSwapResponse { - status: "success".to_string(), - message: "Auto swap started".to_string(), - })) -} - -pub async fn auto_swap( - State(app_state): State, - Json(payload): Json, -) -> Result, ApiError> { - - // validate_address(&payload.from)?; - // validate_address(&payload.to); - - if !payload.from.starts_with("0x") && payload.from.len() != 42 { - return Err(ApiError::InvalidRequest( - "Invalid 'from' address format".to_string(), - )); - } - - if !payload.to.starts_with("0x") && payload.to.len() != 42 { - return Err(ApiError::InvalidRequest( - "Invalid 'to' address format".to_string(), - )); - } - - // call_contract().await; - - // if !payload.from.starts_with("0x") && payload.from.len() != 42 { - // return Err(ApiError::InvalidRequest( - // "Invalid token address format".to_string(), - // )); - // } - - println!("RRRR: {:#?}", app_state.config.env); - - println!("Payload: {:#?}", payload); - - - // let row: Subscription_data = sqlx::query_as::<_, Subscription_data>( - // r#" - // SELECT - // wallet_address, - // to_token, - // is_active, - // FROM swap_subscription - // WHERE wallet_address = $1 - // "#, - // ) - // .bind(payload.to) - // .fetch_one(&app_state.db.pool) - // .await - // .map_err(ApiError::DatabaseError)?; - - // if !row.is_active { - // return Err(ApiError::InvalidRequest( - // "Subscription is not active".to_string(), - // )); - // } - - - // let row2: Swap_subscription_from_token_data = sqlx::query_as::<_, Swap_subscription_from_token_data>( - // r#" - // SELECT - // wallet_address, - // from_token, - // percentage - // FROM swap_subscription - // WHERE wallet_address = $1 - // "#, - // ) - // .bind(row.wallet_address) - // .fetch_one(&app_state.db.pool) - // .await - // .map_err(ApiError::DatabaseError)?; - - // call_contract().await; - - // Ok(Json(json!({"status":"success"}))) - Ok(Json(AutoSwapResponse { - status: "success".to_string(), - message: "Auto swap started".to_string(), - })) -} \ No newline at end of file diff --git a/src/http/mod.rs b/src/http/mod.rs index 17cecfd..99f9248 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -9,8 +9,6 @@ mod subscription; mod transaction_logs; mod types; mod unsubscription; -mod auto_swap; -mod utils; use crate::AppState; // Application router. diff --git a/src/http/types.rs b/src/http/types.rs index 80285a2..af581ff 100644 --- a/src/http/types.rs +++ b/src/http/types.rs @@ -33,30 +33,29 @@ pub struct ActivityLogGetResponse { #[derive(FromRow, Debug, Serialize)] pub struct SubscriptionData { - pub wallet_address: String, + pub wallet_address: String, pub to_token: String, - pub is_active: bool + pub is_active: bool, } #[derive(FromRow, Debug, Serialize)] pub struct SwapSubscriptionFromTokenData { - pub wallet_address: String, + pub wallet_address: String, pub from_token: String, - pub percentage: i16 + pub percentage: i16, } - #[derive(Debug, Serialize, Deserialize)] pub struct AutoSwapRequest { - pub from : String, - pub to : String, - pub value : i64 + pub from: String, + pub to: String, + pub value: i64, } #[derive(Debug, Serialize, Deserialize)] pub struct AutoSwapResponse { pub status: String, - pub message: String + pub message: String, } #[derive(Debug, Deserialize)] diff --git a/src/http/utils.rs b/src/http/utils.rs deleted file mode 100644 index fc55a63..0000000 --- a/src/http/utils.rs +++ /dev/null @@ -1,114 +0,0 @@ -use crate::api_error::ApiError; - -use starknet::{ - contract, core::types::{BlockId, BlockTag, Felt, FunctionCall}, macros::{felt, selector}, providers::{ - jsonrpc::{HttpTransport, JsonRpcClient}, - Provider, Url, - } -}; - -// pub async fn call_contract() { -// let provider = JsonRpcClient::new(HttpTransport::new( -// Url::parse("https://free-rpc.nethermind.io/sepolia-juno/").unwrap(), -// )); - -// let contract_address = -// felt!("0x55abee888d949203f3973ad9ad725fd7c57c8d5da79a6756ef0473af86af863"); - -// let storage_key = felt!("0x0389b73ec450d58472d9fbf78e97bcd7fe290cc445373ae2c2018c8a87f113c3"); -// let block_id = BlockId::Tag(BlockTag::Latest); - -// // Fetch storage value -// match provider.get_storage_at(contract_address, storage_key, block_id).await { -// Ok(call_result) => { -// println!("Call result (raw): {:?}", call_result); - -// // Optional: Convert `call_result` to `i64` if meaningful -// if let Some(decoded_result) = call_result.to_bytes_be().try_into().ok() { -// let decoded_value = i64::from_be_bytes(decoded_result); -// println!("Decoded call result: {}", decoded_value); -// } else { -// println!("Failed to decode call result."); -// } -// } -// Err(err) => { -// eprintln!("Failed to fetch storage: {:?}", err); -// } -// } -// } - - -pub async fn call_contract(provider_url: &str, contract_address: &str ) { - let provider = JsonRpcClient::new(HttpTransport::new( - Url::parse("https://free-rpc.nethermind.io/sepolia-juno/").unwrap(), - )); - - let contract_address = - felt!("0x55abee888d949203f3973ad9ad725fd7c57c8d5da79a6756ef0473af86af863"); - - let block_id = BlockId::Tag(BlockTag::Latest); - let call_result = - provider - .get_storage_at(contract_address, felt!("0x0389b73ec450d58472d9fbf78e97bcd7fe290cc445373ae2c2018c8a87f113c3"), block_id) - .await - .expect("failed to call contract"); - - - // .call( - - // FunctionCall { - // contract_address: tst_token_address, - // entry_point_selector: selector!("name"), - // calldata: vec![ - // Felt::from_hex("0x6b94abf5540e1e0602150a650749ddad92bb784a517b28f7aa836ad7fd3c4bc").unwrap() - // ], - // }, - // BlockId::Tag(BlockTag::Latest), - // ) - // .await - // .expect("failed to call contract"); - - // let result: i64 = call_result; - println!( - "Call result: {}", call_result - // hex::decode(call_result.to_hex()).unwrap().try_into().unwrap() - ); - // dbg!(call_result); -} - -// use starknet::core::types::FieldElement; -// use starknet::providers::{Provider, StarknetProvider}; -// use starknet::signers::{LocalWallet, Signer}; -// use starknet::accounts::{Account, Execution}; - -// async fn invoke_starknet_contract(app_state: &AppState, contract_address: &str, method_name: &str, params: Vec) -> Result<(), ApiError> { -// // Initialize the provider -// let provider = StarknetProvider::new(&app_state.starknet_rpc_url); - -// // Initialize the wallet -// let wallet = LocalWallet::from_private_key(app_state.private_key); - -// // Initialize the account -// let account = Account::new(provider, wallet); - -// // Prepare the execution -// let execution = Execution::new(contract_address) -// .method(method_name) -// .args(params); - -// // Execute the transaction -// account.execute(execution).await.map_err(|_| ApiError::ContractExecutionError)?; - -// Ok(()) -// } - - -pub fn validate_address(address: &str) -> Result { - if !address.starts_with("0x") && address.len() != 42 { - return Err(ApiError::InvalidRequest( - "Invalid token address format".to_string(), - )); - } - - Ok(true) -} diff --git a/src/main.rs b/src/main.rs index 2a96389..ff7bacf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ -use autoswappr_backend::{telemetry, Configuration, Db}; -use tokio::net::TcpListener; +use autoswappr_backend::{service::auto_swap::swap, telemetry, Configuration, Db}; +use tokio::{net::TcpListener, task}; #[tokio::main] async fn main() { @@ -23,6 +23,16 @@ async fn main() { tracing::debug!("Running Migrations"); db.migrate().await.expect("Failed to run migrations"); + tracing::info!("Running swap service"); + task::spawn(async move { + if let Err(e) = swap().await { + tracing::error!("Swap function failed: {}", e); + Err(e) // Return the error + } else { + Ok(()) // Return Ok if no error + } + }); + // Listen for requests on specified port. tracing::info!("Starting server on {}", config.listen_address); let listener = TcpListener::bind(&config.listen_address) diff --git a/src/service/auto_swap.rs b/src/service/auto_swap.rs new file mode 100644 index 0000000..6603152 --- /dev/null +++ b/src/service/auto_swap.rs @@ -0,0 +1,89 @@ +// use std::{default, env, str::FromStr}; + +use crate::api_error::ApiError; +use crate::config::env_var; + +use starknet::{ + accounts::Account, + core::{ + chain_id, + types::{BlockId, BlockTag, Call, EventFilter, Felt, FunctionCall}, + utils::get_selector_from_name, + }, + macros::{felt, selector}, + providers::{ + jsonrpc::{HttpTransport, JsonRpcClient}, + Provider, Url, + }, +}; + +use starknet::accounts::{ExecutionEncoding, SingleOwnerAccount}; + +use starknet::signers::{LocalWallet, SigningKey}; + +pub async fn swap() -> Result<(), ApiError> { + let provider = JsonRpcClient::new(HttpTransport::new( + Url::parse(&env_var("STARKNET_RPC_URL")).unwrap(), + )); + + let private_key = + Felt::from_hex(env_var("PRIVATE_KEY").trim()).expect("Invalid PRIVATE_KEY format"); + + // println!("Priv: {}", private_key); + + // let private_key: Felt = felt!(priv_key.trim_start_matches("0x").as_str()); + + let signer = LocalWallet::from(SigningKey::from_secret_scalar(private_key)); + let account_address = Felt::from_hex(env_var("OWNER_ADDRESS").as_str()).unwrap(); + + let id: Felt = match env_var("APP_ENVIRONMENT").as_str() { + "production" => chain_id::MAINNET, + + _ => chain_id::SEPOLIA, + }; + + let account = SingleOwnerAccount::new( + provider.clone(), + signer, + account_address, + id, + ExecutionEncoding::New, + ); + + let contract_address = Felt::from_hex(env_var("AUTOSWAP_CONTRACT_ADDRESS").as_str()).unwrap(); + + let erc20_event_selector = get_selector_from_name("ERC20Event").expect("Invalid event name"); + + let filter: EventFilter = EventFilter { + from_block: None, + to_block: None, + address: Some(contract_address), + keys: Some(vec![vec![erc20_event_selector]]), + }; + let continuation_token: Option = None; + let chunk_size: u64 = 10; + + let stream = provider + .get_events(filter.clone(), continuation_token.clone(), chunk_size) + .await + .expect("Failed to get events"); + + println!("Listening for events..."); + loop { + let response = provider + .get_events(filter.clone(), continuation_token.clone(), chunk_size) + .await + .expect("Failed to fetch events"); + + let events = response.events; + for event in events { + println!("Event received: {:#?}", event); + } + + // Check for pagination + // continuation_token = response.continuation_token; + // if continuation_token.is_none() { + // continue; + // } + } +} diff --git a/src/service/mod.rs b/src/service/mod.rs index 3cdc85d..68c1126 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -1 +1,2 @@ +pub mod auto_swap; pub mod transaction_logs; From 0e0bdbf28328e117ef4206ff91cc4de64e082f1f Mon Sep 17 00:00:00 2001 From: RichoKD Date: Thu, 19 Dec 2024 20:07:00 +0100 Subject: [PATCH 3/3] Fix: Autoswap rework --- src/http/auto_swap.rs | 149 +++++++++++++++++++++++++++++++++++++++ src/http/mod.rs | 2 + src/main.rs | 14 +--- src/service/auto_swap.rs | 89 ----------------------- src/service/mod.rs | 1 - 5 files changed, 153 insertions(+), 102 deletions(-) create mode 100644 src/http/auto_swap.rs delete mode 100644 src/service/auto_swap.rs diff --git a/src/http/auto_swap.rs b/src/http/auto_swap.rs new file mode 100644 index 0000000..7c40dd4 --- /dev/null +++ b/src/http/auto_swap.rs @@ -0,0 +1,149 @@ +use std::str::FromStr; + +use super::types::{ + AutoSwapRequest, AutoSwapResponse, SubscriptionData, SwapSubscriptionFromTokenData, +}; +use crate::api_error::ApiError; +use crate::config::env_var; +use crate::AppState; +use axum::{extract::State, Json}; +// use serde_json::{json, Value}; + +use starknet::{ + accounts::{Account, ExecutionEncoding, SingleOwnerAccount}, + core::{ + chain_id, + types::{Call, Felt}, + utils::get_selector_from_name, + }, + providers::{ + jsonrpc::{HttpTransport, JsonRpcClient}, + Url, + }, + signers::{LocalWallet, SigningKey}, +}; + +async fn call_contract(from: &str, to: &str, value: f64) { + let provider = JsonRpcClient::new(HttpTransport::new( + Url::parse(&env_var("STARKNET_RPC_URL")).unwrap(), + )); + + let private_key = + Felt::from_hex(env_var("PRIVATE_KEY").trim()).expect("Invalid PRIVATE_KEY format"); + + // Initialize the wallet + let signer = LocalWallet::from(SigningKey::from_secret_scalar(private_key)); + // Initialize the account + // println!("Account address: {}", private_key); + + let id: Felt = match env_var("APP_ENVIRONMENT").as_str() { + "production" => chain_id::MAINNET, + _ => chain_id::SEPOLIA, + }; + + let account_address = Felt::from_str(&env_var("OWNER_ADDRESS")); + + // println!("Account address: {}", account_address); + + let account = SingleOwnerAccount::new( + provider, + signer, + account_address.unwrap(), + id, + ExecutionEncoding::New, + ); + + let calldata = vec![ + Felt::from_hex(from).unwrap(), + Felt::from_hex(to).unwrap(), + Felt::from(value as i128), + ]; + + let contract_address = Felt::from_hex(env_var("AUTOSWAP_CONTRACT_ADDRESS").as_str()).unwrap(); + + let call = Call { + to: contract_address, + selector: get_selector_from_name("auto_swap").unwrap(), + calldata, + }; + + match account.execute_v3(vec![call]).send().await { + Ok(response) => { + println!( + "Call successful! Transaction hash: {}", + response.transaction_hash + ); + } + Err(e) => { + eprintln!("Error during call: {}", e); + } + } +} + +pub async fn auto_swap( + State(app_state): State, + Json(payload): Json, +) -> Result, ApiError> { + // validate_address(&payload.from)?; + // validate_address(&payload.to); + if !payload.from.starts_with("0x") && payload.from.len() != 42 { + return Err(ApiError::InvalidRequest( + "Invalid 'from' address format".to_string(), + )); + } + if !payload.to.starts_with("0x") && payload.to.len() != 42 { + return Err(ApiError::InvalidRequest( + "Invalid 'to' address format".to_string(), + )); + } + + // println!("Payload: {:#?}", payload); + + let row: SubscriptionData = sqlx::query_as::<_, SubscriptionData>( + r#" + SELECT + wallet_address, + to_token, + is_active, + FROM swap_subscription + WHERE wallet_address = $1 + "#, + ) + .bind(&payload.to) + .fetch_one(&app_state.db.pool) + .await + .map_err(ApiError::DatabaseError)?; + + if !row.is_active { + return Err(ApiError::InvalidRequest( + "Subscription is not active".to_string(), + )); + } + + let row2: SwapSubscriptionFromTokenData = sqlx::query_as::<_, SwapSubscriptionFromTokenData>( + r#" + SELECT + wallet_address, + from_token, + percentage + FROM swap_subscription + WHERE wallet_address = $1 + "#, + ) + .bind(row.wallet_address) + .fetch_one(&app_state.db.pool) + .await + .map_err(ApiError::DatabaseError)?; + + call_contract( + &row2.from_token, + &payload.to, + (row2.percentage as f64 / 100.0) * payload.value as f64, + ) + .await; + + Ok(Json(AutoSwapResponse { + status: "success".to_string(), + message: "Auto swap started".to_string(), + })) +} diff --git a/src/http/mod.rs b/src/http/mod.rs index 99f9248..c18b0c8 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -3,6 +3,7 @@ use axum::{ Router, }; mod activity_log_retrieval; +mod auto_swap; mod health_check; mod percentage_update; mod subscription; @@ -27,4 +28,5 @@ pub fn router() -> Router { "/update-percentage", post(percentage_update::update_percentage), ) + .route("/auto-swap", post(auto_swap::auto_swap)) } diff --git a/src/main.rs b/src/main.rs index ff7bacf..2a96389 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ -use autoswappr_backend::{service::auto_swap::swap, telemetry, Configuration, Db}; -use tokio::{net::TcpListener, task}; +use autoswappr_backend::{telemetry, Configuration, Db}; +use tokio::net::TcpListener; #[tokio::main] async fn main() { @@ -23,16 +23,6 @@ async fn main() { tracing::debug!("Running Migrations"); db.migrate().await.expect("Failed to run migrations"); - tracing::info!("Running swap service"); - task::spawn(async move { - if let Err(e) = swap().await { - tracing::error!("Swap function failed: {}", e); - Err(e) // Return the error - } else { - Ok(()) // Return Ok if no error - } - }); - // Listen for requests on specified port. tracing::info!("Starting server on {}", config.listen_address); let listener = TcpListener::bind(&config.listen_address) diff --git a/src/service/auto_swap.rs b/src/service/auto_swap.rs deleted file mode 100644 index 6603152..0000000 --- a/src/service/auto_swap.rs +++ /dev/null @@ -1,89 +0,0 @@ -// use std::{default, env, str::FromStr}; - -use crate::api_error::ApiError; -use crate::config::env_var; - -use starknet::{ - accounts::Account, - core::{ - chain_id, - types::{BlockId, BlockTag, Call, EventFilter, Felt, FunctionCall}, - utils::get_selector_from_name, - }, - macros::{felt, selector}, - providers::{ - jsonrpc::{HttpTransport, JsonRpcClient}, - Provider, Url, - }, -}; - -use starknet::accounts::{ExecutionEncoding, SingleOwnerAccount}; - -use starknet::signers::{LocalWallet, SigningKey}; - -pub async fn swap() -> Result<(), ApiError> { - let provider = JsonRpcClient::new(HttpTransport::new( - Url::parse(&env_var("STARKNET_RPC_URL")).unwrap(), - )); - - let private_key = - Felt::from_hex(env_var("PRIVATE_KEY").trim()).expect("Invalid PRIVATE_KEY format"); - - // println!("Priv: {}", private_key); - - // let private_key: Felt = felt!(priv_key.trim_start_matches("0x").as_str()); - - let signer = LocalWallet::from(SigningKey::from_secret_scalar(private_key)); - let account_address = Felt::from_hex(env_var("OWNER_ADDRESS").as_str()).unwrap(); - - let id: Felt = match env_var("APP_ENVIRONMENT").as_str() { - "production" => chain_id::MAINNET, - - _ => chain_id::SEPOLIA, - }; - - let account = SingleOwnerAccount::new( - provider.clone(), - signer, - account_address, - id, - ExecutionEncoding::New, - ); - - let contract_address = Felt::from_hex(env_var("AUTOSWAP_CONTRACT_ADDRESS").as_str()).unwrap(); - - let erc20_event_selector = get_selector_from_name("ERC20Event").expect("Invalid event name"); - - let filter: EventFilter = EventFilter { - from_block: None, - to_block: None, - address: Some(contract_address), - keys: Some(vec![vec![erc20_event_selector]]), - }; - let continuation_token: Option = None; - let chunk_size: u64 = 10; - - let stream = provider - .get_events(filter.clone(), continuation_token.clone(), chunk_size) - .await - .expect("Failed to get events"); - - println!("Listening for events..."); - loop { - let response = provider - .get_events(filter.clone(), continuation_token.clone(), chunk_size) - .await - .expect("Failed to fetch events"); - - let events = response.events; - for event in events { - println!("Event received: {:#?}", event); - } - - // Check for pagination - // continuation_token = response.continuation_token; - // if continuation_token.is_none() { - // continue; - // } - } -} diff --git a/src/service/mod.rs b/src/service/mod.rs index 68c1126..3cdc85d 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -1,2 +1 @@ -pub mod auto_swap; pub mod transaction_logs;