From 901f6351ea48109d362eceb809a633c03b370be1 Mon Sep 17 00:00:00 2001 From: ptisserand Date: Tue, 15 Oct 2024 13:53:38 +0200 Subject: [PATCH] feat(diri): split diri orderbook event in another package (#482) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description - Create `orderbook` package to handle smart contract event parsing. - Remove unused crates from Cargo.toml ## What type of PR is this? (check all applicable) - [x] 🍕 Feature (`feat:`) - [ ] 🐛 Bug Fix (`fix:`) - [ ] 📝 Documentation Update (`docs:`) - [ ] 🎨 Style (`style:`) - [x] 🧑‍💻 Code Refactor (`refactor:`) - [ ] 🔥 Performance Improvements (`perf:`) - [ ] ✅ Test (`test:`) - [ ] 🤖 Build (`build:`) - [ ] 🔁 CI (`ci:`) - [ ] 📦 Chore (`chore:`) - [ ] ⏩ Revert (`revert:`) - [ ] 🚀 Breaking Changes (`BREAKING CHANGE:`) ## Related Tickets & Documents ## Added tests? - [ ] 👍 yes - [ ] 🙅 no, because they aren't needed - [ ] 🙋 no, because I need help ## Added to documentation? - [ ] 📜 README.md - [ ] 📓 Documentation - [ ] 🙅 no documentation needed ## [optional] Are there any post-deployment tasks we need to perform? ## [optional] What gif best describes this PR or how it makes you feel? ### PR Title and Description Guidelines: - Ensure your PR title follows semantic versioning standards. This helps automate releases and changelogs. - Use types like `feat:`, `fix:`, `chore:`, `BREAKING CHANGE:` etc. in your PR title. - Your PR title will be used as a commit message when merging. Make sure it adheres to [Conventional Commits standards](https://www.conventionalcommits.org/). ## Closing Issues --- Cargo.lock | 389 ++++-------------- Cargo.toml | 19 +- crates/diri/Cargo.toml | 11 +- crates/diri/src/lib.rs | 4 +- crates/diri/src/mod.rs | 1 - crates/diri/src/storage/types.rs | 107 +++++ crates/orderbook/Cargo.toml | 14 + .../src}/events/common.rs | 2 + .../orderbook => orderbook/src}/events/mod.rs | 14 +- .../src}/events/order_cancelled.rs | 24 +- .../src}/events/order_executed.rs | 37 +- .../src}/events/order_fulfilled.rs | 26 +- .../src}/events/order_placed.rs | 36 +- .../src}/events/rollback_status.rs | 24 +- .../orderbook/mod.rs => orderbook/src/lib.rs} | 4 +- src/lib.rs | 4 + 16 files changed, 240 insertions(+), 476 deletions(-) delete mode 100644 crates/diri/src/mod.rs create mode 100644 crates/orderbook/Cargo.toml rename crates/{diri/src/orderbook => orderbook/src}/events/common.rs (94%) rename crates/{diri/src/orderbook => orderbook/src}/events/mod.rs (70%) rename crates/{diri/src/orderbook => orderbook/src}/events/order_cancelled.rs (79%) rename crates/{diri/src/orderbook => orderbook/src}/events/order_executed.rs (86%) rename crates/{diri/src/orderbook => orderbook/src}/events/order_fulfilled.rs (78%) rename crates/{diri/src/orderbook => orderbook/src}/events/order_placed.rs (74%) rename crates/{diri/src/orderbook => orderbook/src}/events/rollback_status.rs (78%) rename crates/{diri/src/orderbook/mod.rs => orderbook/src/lib.rs} (96%) diff --git a/Cargo.lock b/Cargo.lock index 60efb60b1..c9e788425 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,80 +56,6 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" -[[package]] -name = "alloy-primitives" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db8aa973e647ec336810a9356af8aea787249c9d00b1525359f3db29a68d231b" -dependencies = [ - "bytes", - "cfg-if", - "const-hex", - "derive_more", - "hex-literal", - "itoa", - "ruint", - "tiny-keccak", -] - -[[package]] -name = "alloy-sol-macro" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dbd17d67f3e89478c8a634416358e539e577899666c927bc3d2b1328ee9b6ca" -dependencies = [ - "alloy-sol-macro-expander", - "alloy-sol-macro-input", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 2.0.64", -] - -[[package]] -name = "alloy-sol-macro-expander" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6da95adcf4760bb4b108fefa51d50096c5e5fdd29ee72fed3e86ee414f2e34" -dependencies = [ - "alloy-sol-macro-input", - "const-hex", - "heck 0.4.1", - "indexmap 2.1.0", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 2.0.64", - "syn-solidity", - "tiny-keccak", -] - -[[package]] -name = "alloy-sol-macro-input" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32c8da04c1343871fb6ce5a489218f9c85323c8340a36e9106b5fc98d4dd59d5" -dependencies = [ - "const-hex", - "dunce", - "heck 0.5.0", - "proc-macro2", - "quote", - "syn 2.0.64", - "syn-solidity", -] - -[[package]] -name = "alloy-sol-types" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40a64d2d2395c1ac636b62419a7b17ec39031d6b2367e66e9acbf566e6055e9c" -dependencies = [ - "alloy-primitives", - "alloy-sol-macro", - "const-hex", -] - [[package]] name = "android-tzdata" version = "0.1.1" @@ -309,8 +235,6 @@ dependencies = [ name = "arkproject" version = "0.1.0" dependencies = [ - "alloy-primitives", - "alloy-sol-types", "anyhow", "ark-metadata", "ark-starknet", @@ -319,6 +243,7 @@ dependencies = [ "futures", "log", "mockall", + "orderbook", "pontos", "sana", "sqlx", @@ -497,7 +422,7 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cainome" version = "0.2.3" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.0#0d29bb06b3f7cb7fcb8f0749c3b2ad105a5551dd" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" dependencies = [ "anyhow", "async-trait", @@ -508,11 +433,11 @@ dependencies = [ "camino", "clap", "clap_complete", - "convert_case 0.6.0", + "convert_case", "serde", "serde_json", - "starknet 0.11.0", - "starknet-types-core 0.1.5 (git+https://github.com/starknet-io/types-rs?rev=f98f048)", + "starknet 0.12.0", + "starknet-types-core", "thiserror", "tracing", "tracing-subscriber", @@ -522,22 +447,22 @@ dependencies = [ [[package]] name = "cainome-cairo-serde" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.0#0d29bb06b3f7cb7fcb8f0749c3b2ad105a5551dd" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" dependencies = [ "serde", - "starknet 0.11.0", + "starknet 0.12.0", "thiserror", ] [[package]] name = "cainome-parser" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.0#0d29bb06b3f7cb7fcb8f0749c3b2ad105a5551dd" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" dependencies = [ - "convert_case 0.6.0", + "convert_case", "quote", "serde_json", - "starknet 0.11.0", + "starknet 0.12.0", "syn 2.0.64", "thiserror", ] @@ -545,7 +470,7 @@ dependencies = [ [[package]] name = "cainome-rs" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.0#0d29bb06b3f7cb7fcb8f0749c3b2ad105a5551dd" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" dependencies = [ "anyhow", "cainome-cairo-serde", @@ -555,7 +480,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "starknet 0.11.0", + "starknet 0.12.0", "syn 2.0.64", "thiserror", ] @@ -563,7 +488,7 @@ dependencies = [ [[package]] name = "cainome-rs-macro" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.0#0d29bb06b3f7cb7fcb8f0749c3b2ad105a5551dd" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" dependencies = [ "anyhow", "cainome-cairo-serde", @@ -573,7 +498,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "starknet 0.11.0", + "starknet 0.12.0", "syn 2.0.64", "thiserror", ] @@ -682,31 +607,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" -[[package]] -name = "const-hex" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5104de16b218eddf8e34ffe2f86f74bfa4e61e95a1b89732fccf6325efd0557" -dependencies = [ - "cfg-if", - "cpufeatures", - "hex", - "proptest", - "serde", -] - [[package]] name = "const-oid" version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - [[package]] name = "convert_case" version = "0.6.0" @@ -887,19 +793,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "derive_more" -version = "0.99.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" -dependencies = [ - "convert_case 0.4.0", - "proc-macro2", - "quote", - "rustc_version", - "syn 1.0.109", -] - [[package]] name = "digest" version = "0.10.7" @@ -918,7 +811,6 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", - "cainome", "clap", "dotenv", "env_logger", @@ -926,11 +818,12 @@ dependencies = [ "log", "num-bigint", "num-traits", + "orderbook", "regex", "serde", "serde_json", - "starknet 0.11.0", - "starknet-types-core 0.1.5 (git+https://github.com/starknet-io/types-rs?rev=f98f048)", + "starknet 0.12.0", + "starknet-types-core", "thiserror", "tokio", "tracing", @@ -956,12 +849,6 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" -[[package]] -name = "dunce" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" - [[package]] name = "either" version = "1.9.0" @@ -1362,12 +1249,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hex-literal" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" - [[package]] name = "hkdf" version = "0.12.4" @@ -1661,9 +1542,9 @@ dependencies = [ [[package]] name = "lambdaworks-crypto" -version = "0.7.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fb5d4f22241504f7c7b8d2c3a7d7835d7c07117f10bff2a7d96a9ef6ef217c3" +checksum = "bbc2a4da0d9e52ccfe6306801a112e81a8fc0c76aa3e4449fefeda7fef72bb34" dependencies = [ "lambdaworks-math", "serde", @@ -1673,9 +1554,9 @@ dependencies = [ [[package]] name = "lambdaworks-math" -version = "0.7.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "358e172628e713b80a530a59654154bfc45783a6ed70ea284839800cebdf8f97" +checksum = "d1bd2632acbd9957afc5aeec07ad39f078ae38656654043bf16e046fa2730e23" dependencies = [ "serde", "serde_json", @@ -2012,6 +1893,15 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "orderbook" +version = "0.1.0" +dependencies = [ + "cainome", + "num-bigint", + "starknet 0.12.0", +] + [[package]] name = "overload" version = "0.1.1" @@ -2262,20 +2152,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "proptest" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" -dependencies = [ - "bitflags 2.4.1", - "num-traits", - "rand", - "rand_chacha", - "rand_xorshift", - "unarray", -] - [[package]] name = "quote" version = "1.0.36" @@ -2321,15 +2197,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rand_xorshift" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" -dependencies = [ - "rand_core", -] - [[package]] name = "redox_syscall" version = "0.4.1" @@ -2480,26 +2347,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "ruint" -version = "1.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f308135fef9fc398342da5472ce7c484529df23743fb7c734e0f3d472971e62" -dependencies = [ - "proptest", - "rand", - "ruint-macro", - "serde", - "valuable", - "zeroize", -] - -[[package]] -name = "ruint-macro" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f86854cf50259291520509879a5c294c3c9a4c334e9ff65071c51e42ef1e2343" - [[package]] name = "rustc-demangle" version = "0.1.23" @@ -3143,16 +2990,17 @@ dependencies = [ [[package]] name = "starknet" -version = "0.11.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=2ddc694#2ddc69479d326ed154df438d22f2d720fbba746e" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0c9ac3809cc7630784e8c8565fa3013af819d83c97aa2720d566016d439011" dependencies = [ - "starknet-accounts 0.10.0", - "starknet-contract 0.10.0", - "starknet-core 0.11.1", - "starknet-crypto 0.7.1", - "starknet-macros 0.2.0", - "starknet-providers 0.11.0", - "starknet-signers 0.9.0", + "starknet-accounts 0.11.0", + "starknet-contract 0.11.0", + "starknet-core 0.12.0", + "starknet-crypto 0.7.2", + "starknet-macros 0.2.1", + "starknet-providers 0.12.0", + "starknet-signers 0.10.0", ] [[package]] @@ -3185,15 +3033,16 @@ dependencies = [ [[package]] name = "starknet-accounts" -version = "0.10.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=2ddc694#2ddc69479d326ed154df438d22f2d720fbba746e" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee27ded58ade61da410fccafd57ed5429b0e79a9d62a4ae8b65818cb9d6f400" dependencies = [ "async-trait", "auto_impl", - "starknet-core 0.11.1", - "starknet-crypto 0.7.1", - "starknet-providers 0.11.0", - "starknet-signers 0.9.0", + "starknet-core 0.12.0", + "starknet-crypto 0.7.2", + "starknet-providers 0.12.0", + "starknet-signers 0.10.0", "thiserror", ] @@ -3229,15 +3078,16 @@ dependencies = [ [[package]] name = "starknet-contract" -version = "0.10.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=2ddc694#2ddc69479d326ed154df438d22f2d720fbba746e" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd6ee5762d24c4f06ab7e9406550925df406712e73719bd2de905c879c674a87" dependencies = [ "serde", "serde_json", "serde_with 3.9.0", - "starknet-accounts 0.10.0", - "starknet-core 0.11.1", - "starknet-providers 0.11.0", + "starknet-accounts 0.11.0", + "starknet-core 0.12.0", + "starknet-providers 0.12.0", "thiserror", ] @@ -3279,8 +3129,9 @@ dependencies = [ [[package]] name = "starknet-core" -version = "0.11.1" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=2ddc694#2ddc69479d326ed154df438d22f2d720fbba746e" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538240cbe6663c673fe77465f294da707080f39678dd7066761554899e46100" dependencies = [ "base64 0.21.5", "crypto-bigint", @@ -3291,8 +3142,8 @@ dependencies = [ "serde_json_pythonic", "serde_with 3.9.0", "sha3", - "starknet-crypto 0.7.1", - "starknet-types-core 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-crypto 0.7.2", + "starknet-types-core", ] [[package]] @@ -3317,8 +3168,9 @@ dependencies = [ [[package]] name = "starknet-crypto" -version = "0.7.1" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=2ddc694#2ddc69479d326ed154df438d22f2d720fbba746e" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a5064173a8e8d2675e67744fd07f310de44573924b6b7af225a6bdd8102913" dependencies = [ "crypto-bigint", "hex", @@ -3328,8 +3180,8 @@ dependencies = [ "num-traits", "rfc6979", "sha2", - "starknet-curve 0.5.0", - "starknet-types-core 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-curve 0.5.1", + "starknet-types-core", "zeroize", ] @@ -3355,10 +3207,11 @@ dependencies = [ [[package]] name = "starknet-curve" -version = "0.5.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=2ddc694#2ddc69479d326ed154df438d22f2d720fbba746e" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcde6bd74269b8161948190ace6cf069ef20ac6e79cd2ba09b320efa7500b6de" dependencies = [ - "starknet-types-core 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-types-core", ] [[package]] @@ -3388,10 +3241,11 @@ dependencies = [ [[package]] name = "starknet-macros" -version = "0.2.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=2ddc694#2ddc69479d326ed154df438d22f2d720fbba746e" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8986a940af916fc0a034f4e42c6ba76d94f1e97216d75447693dfd7aefaf3ef2" dependencies = [ - "starknet-core 0.11.1", + "starknet-core 0.12.0", "syn 2.0.64", ] @@ -3437,8 +3291,9 @@ dependencies = [ [[package]] name = "starknet-providers" -version = "0.11.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=2ddc694#2ddc69479d326ed154df438d22f2d720fbba746e" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60e8e69ba7a36dea2d28333be82b4011f8784333d3ae5618482b6587c1ffb66c" dependencies = [ "async-trait", "auto_impl", @@ -3450,7 +3305,7 @@ dependencies = [ "serde", "serde_json", "serde_with 3.9.0", - "starknet-core 0.11.1", + "starknet-core 0.12.0", "thiserror", "url", ] @@ -3489,8 +3344,9 @@ dependencies = [ [[package]] name = "starknet-signers" -version = "0.9.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=2ddc694#2ddc69479d326ed154df438d22f2d720fbba746e" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70b9e01b61ae51d722e2b100d6ef913c5a2e70d1ea672733d385f7296d6055ef" dependencies = [ "async-trait", "auto_impl", @@ -3498,29 +3354,16 @@ dependencies = [ "eth-keystore", "getrandom", "rand", - "starknet-core 0.11.1", - "starknet-crypto 0.7.1", + "starknet-core 0.12.0", + "starknet-crypto 0.7.2", "thiserror", ] [[package]] name = "starknet-types-core" -version = "0.1.5" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6bacf0ba19bc721e518bc4bf389ff13daa8a7c5db5fd320600473b8aa9fcbd" -dependencies = [ - "lambdaworks-crypto", - "lambdaworks-math", - "num-bigint", - "num-integer", - "num-traits", - "serde", -] - -[[package]] -name = "starknet-types-core" -version = "0.1.5" -source = "git+https://github.com/starknet-io/types-rs?rev=f98f048#f98f048efa776f1f8da81a19f337a9b8c2f4b8f7" +checksum = "fa1b9e01ccb217ab6d475c5cda05dbb22c30029f7bb52b192a010a00d77a3d74" dependencies = [ "lambdaworks-crypto", "lambdaworks-math", @@ -3587,18 +3430,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "syn-solidity" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8db114c44cf843a8bacd37a146e37987a0b823a0e8bc4fdc610c9c72ab397a5" -dependencies = [ - "paste", - "proc-macro2", - "quote", - "syn 2.0.64", -] - [[package]] name = "system-configuration" version = "0.5.1" @@ -3947,12 +3778,6 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "unarray" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" - [[package]] name = "unicode-bidi" version = "0.3.14" @@ -4391,53 +4216,3 @@ dependencies = [ "quote", "syn 2.0.64", ] - -[[patch.unused]] -name = "alloy-contract" -version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce#5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce" - -[[patch.unused]] -name = "alloy-json-rpc" -version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce#5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce" - -[[patch.unused]] -name = "alloy-network" -version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce#5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce" - -[[patch.unused]] -name = "alloy-provider" -version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce#5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce" - -[[patch.unused]] -name = "alloy-rpc-types" -version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce#5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce" - -[[patch.unused]] -name = "alloy-signer" -version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce#5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce" - -[[patch.unused]] -name = "alloy-signer-wallet" -version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce#5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce" - -[[patch.unused]] -name = "alloy-transport" -version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce#5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce" - -[[patch.unused]] -name = "cairo-felt" -version = "0.9.1" -source = "git+https://github.com/dojoengine/cairo-rs.git?rev=1031381#10313816b4ba7891e3c8ba90f6d0068a9149d682" - -[[patch.unused]] -name = "cairo-vm" -version = "0.9.2" -source = "git+https://github.com/dojoengine/cairo-rs.git?rev=1031381#10313816b4ba7891e3c8ba90f6d0068a9149d682" diff --git a/Cargo.toml b/Cargo.toml index 725c59b8c..669a53c44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ members = [ "crates/pontos", "crates/diri", "crates/sana", + "crates/orderbook", ] [workspace.dependencies] @@ -27,6 +28,8 @@ ark-metadata = { path = "./crates/ark-metadata" } pontos = { path = "./crates/pontos" } sana = { path = "./crates/sana" } diri = { path = "./crates/diri" } +orderbook = { path = "./crates/orderbook" } + async-trait = "0.1.73" starknet = "0.10.0" anyhow = "1.0" @@ -46,25 +49,11 @@ ark-metadata.workspace = true pontos = { path = "./crates/pontos", features = ["sqlxdb"] } sana = { path = "./crates/sana", features = ["sqlxdb"] } diri.workspace = true +orderbook.workspace = true tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } tracing = "0.1" tracing-log = "0.1" sqlx = { version = "0.7", features = ["sqlite", "runtime-tokio"] } -alloy-primitives = { version = "0.7.1", default-features = false } -alloy-sol-types = { version = "0.7.1", default-features = false } - -[patch.crates-io] -cairo-felt = { git = "https://github.com/dojoengine/cairo-rs.git", rev = "1031381" } -cairo-vm = { git = "https://github.com/dojoengine/cairo-rs.git", rev = "1031381" } - -alloy-contract = { git = "https://github.com/alloy-rs/alloy", rev = "5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce" } -alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy", rev = "5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce" } -alloy-network = { git = "https://github.com/alloy-rs/alloy", rev = "5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce" } -alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce" } -alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce" } -alloy-signer = { git = "https://github.com/alloy-rs/alloy", rev = "5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce" } -alloy-signer-wallet = { git = "https://github.com/alloy-rs/alloy", rev = "5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce" } -alloy-transport = { git = "https://github.com/alloy-rs/alloy", rev = "5a5f29eb7d92a194bb2c67b1f879e84b2c6716ce" } [dev-dependencies] mockall = "0.12.1" diff --git a/crates/diri/Cargo.toml b/crates/diri/Cargo.toml index cff2f1860..1e233e161 100644 --- a/crates/diri/Cargo.toml +++ b/crates/diri/Cargo.toml @@ -27,20 +27,19 @@ log = "0.4.17" thiserror = "1.0.32" # For now, Diri can't use the ark-starknet due to the dependency # on ArkProjectNFTs for of starknet-rs. -starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "2ddc694" } -starknet-types-core = { git = "https://github.com/starknet-io/types-rs", rev = "f98f048" } +starknet = "0.12.0" +starknet-types-core = "0.1.7" + tracing = "0.1" num-bigint = "0.4.4" num-traits = "0.2.19" -cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.4.0", features = [ - "abigen-rs", -] } - anyhow.workspace = true async-trait.workspace = true tokio.workspace = true +orderbook = { path = "../orderbook" } + [dev-dependencies] clap = { version = "4.3.19", features = ["derive", "env", "string"] } dotenv = "0.15.0" diff --git a/crates/diri/src/lib.rs b/crates/diri/src/lib.rs index a37db1120..c3d4ff509 100644 --- a/crates/diri/src/lib.rs +++ b/crates/diri/src/lib.rs @@ -4,8 +4,6 @@ use storage::*; pub mod event_handler; use event_handler::EventHandler; -mod orderbook; - use starknet::core::types::{ BlockId, EmittedEvent, EventFilter, Felt, MaybePendingBlockWithTxHashes, }; @@ -15,7 +13,7 @@ use std::collections::HashMap; use std::sync::Arc; use tracing::{error, trace, warn}; -use crate::orderbook::Event; +use orderbook::Event; pub type IndexerResult = Result; diff --git a/crates/diri/src/mod.rs b/crates/diri/src/mod.rs deleted file mode 100644 index 959ef2db9..000000000 --- a/crates/diri/src/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod orderbook; diff --git a/crates/diri/src/storage/types.rs b/crates/diri/src/storage/types.rs index 1a1cf49bb..7c5f15862 100644 --- a/crates/diri/src/storage/types.rs +++ b/crates/diri/src/storage/types.rs @@ -1,3 +1,9 @@ +use orderbook::events::{ + common::{to_hex_str, to_hex_str_opt, u256_to_hex, u256_to_hex_opt}, + OrderCancelled, OrderExecuted, OrderFulfilled, OrderPlaced, RollbackStatus, +}; +use starknet::core::{types::Felt, utils::parse_cairo_short_string}; + #[derive(Debug, Clone)] pub struct PlacedData { pub order_hash: String, @@ -52,3 +58,104 @@ pub struct ExecutedData { pub from: Option, pub to: Option, } + +impl From for CancelledData { + fn from(value: OrderCancelled) -> Self { + match value { + OrderCancelled::V1(value) => Self { + order_hash: to_hex_str(&value.order_hash), + order_type: format!("{:?}", value.order_type), + reason: parse_cairo_short_string(&value.reason) + .unwrap_or(to_hex_str(&value.reason)), + }, + } + } +} + +impl From for ExecutedData { + fn from(value: OrderExecuted) -> Self { + match value { + OrderExecuted::V0(v) => Self { + version: 0, + order_hash: to_hex_str(&v.order_hash), + order_type: None, + transaction_hash: None, + from: None, + to: None, + }, + OrderExecuted::V1(v) => Self { + version: 1, + order_hash: to_hex_str(&v.order_hash), + order_type: None, + transaction_hash: Some(to_hex_str(&v.transaction_hash)), + from: Some(to_hex_str(&Felt::from(v.from))), + to: Some(to_hex_str(&Felt::from(v.to))), + }, + OrderExecuted::V2(v) => Self { + version: 2, + order_hash: to_hex_str(&v.order_hash), + order_type: Some(format!("{:?}", v.order_type)), + transaction_hash: Some(to_hex_str(&v.transaction_hash)), + from: Some(to_hex_str(&Felt::from(v.from))), + to: Some(to_hex_str(&Felt::from(v.to))), + }, + } + } +} + +impl From for FulfilledData { + fn from(value: OrderFulfilled) -> Self { + match value { + OrderFulfilled::V1(value) => { + let related_order_hash = value.related_order_hash.map(Felt::from); + + Self { + order_hash: to_hex_str(&value.order_hash), + order_type: format!("{:?}", value.order_type), + fulfiller: to_hex_str(&Felt::from(value.fulfiller)), + related_order_hash: to_hex_str_opt(&related_order_hash), + } + } + } + } +} + +impl From for PlacedData { + fn from(value: OrderPlaced) -> Self { + match value { + OrderPlaced::V1(value) => Self { + order_hash: to_hex_str(&value.order_hash), + order_version: to_hex_str(&value.order_version), + order_type: format!("{:?}", value.order_type), + cancelled_order_hash: to_hex_str_opt(&value.cancelled_order_hash), + route: format!("{:?}", value.order.route), + currency_address: to_hex_str(&Felt::from(value.order.currency_address)), + currency_chain_id: to_hex_str(&value.order.currency_chain_id), + salt: to_hex_str(&value.order.salt), + offerer: to_hex_str(&Felt::from(value.order.offerer)), + token_chain_id: format!("0x{:x}", value.order.token_chain_id), + token_address: to_hex_str(&Felt::from(value.order.token_address)), + token_id: u256_to_hex_opt(&value.order.token_id), + quantity: u256_to_hex(&value.order.quantity), + start_amount: u256_to_hex(&value.order.start_amount), + end_amount: u256_to_hex(&value.order.end_amount), + start_date: value.order.start_date, + end_date: value.order.end_date, + broker_id: to_hex_str(&Felt::from(value.order.broker_id)), + }, + } + } +} + +impl From for RollbackStatusData { + fn from(value: RollbackStatus) -> Self { + match value { + RollbackStatus::V1(value) => Self { + order_hash: to_hex_str(&value.order_hash), + order_type: format!("{:?}", value.order_type), + reason: parse_cairo_short_string(&value.reason) + .unwrap_or(to_hex_str(&value.reason)), + }, + } + } +} diff --git a/crates/orderbook/Cargo.toml b/crates/orderbook/Cargo.toml new file mode 100644 index 000000000..3f9b39228 --- /dev/null +++ b/crates/orderbook/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "orderbook" +version = "0.1.0" +edition = "2021" + +[lib] +path = "src/lib.rs" + +[dependencies] +cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.4.2", features = [ + "abigen-rs", +] } +num-bigint = "0.4.4" +starknet = "0.12.0" diff --git a/crates/diri/src/orderbook/events/common.rs b/crates/orderbook/src/events/common.rs similarity index 94% rename from crates/diri/src/orderbook/events/common.rs rename to crates/orderbook/src/events/common.rs index 1e7672b40..21642b1e0 100644 --- a/crates/diri/src/orderbook/events/common.rs +++ b/crates/orderbook/src/events/common.rs @@ -1,6 +1,8 @@ use cainome::cairo_serde::U256; use num_bigint::BigUint; +pub use starknet::core::utils::parse_cairo_short_string; + use std::fmt::LowerHex; /// Returns the padded hex of '0x' prefixed diff --git a/crates/diri/src/orderbook/events/mod.rs b/crates/orderbook/src/events/mod.rs similarity index 70% rename from crates/diri/src/orderbook/events/mod.rs rename to crates/orderbook/src/events/mod.rs index 3105839fc..ae604ac10 100644 --- a/crates/diri/src/orderbook/events/mod.rs +++ b/crates/orderbook/src/events/mod.rs @@ -1,21 +1,21 @@ -pub(crate) mod common; +pub mod common; pub(crate) mod order_cancelled; pub(crate) mod order_executed; pub(crate) mod order_fulfilled; pub(crate) mod order_placed; pub(crate) mod rollback_status; -pub(crate) use order_cancelled::OrderCancelled; -pub(crate) use order_executed::OrderExecuted; -pub(crate) use order_fulfilled::OrderFulfilled; -pub(crate) use order_placed::OrderPlaced; -pub(crate) use rollback_status::RollbackStatus; +pub use order_cancelled::OrderCancelled; +pub use order_executed::OrderExecuted; +pub use order_fulfilled::OrderFulfilled; +pub use order_placed::OrderPlaced; +pub use rollback_status::RollbackStatus; // pub(crate) use cainome::cairo_serde::U256; use starknet::{core::types::Felt, macros::selector}; #[derive(Debug)] -pub(crate) enum OrderbookParseError { +pub enum OrderbookParseError { Selector, KeyLength, DataLength, diff --git a/crates/diri/src/orderbook/events/order_cancelled.rs b/crates/orderbook/src/events/order_cancelled.rs similarity index 79% rename from crates/diri/src/orderbook/events/order_cancelled.rs rename to crates/orderbook/src/events/order_cancelled.rs index f30087f1e..485d95df6 100644 --- a/crates/diri/src/orderbook/events/order_cancelled.rs +++ b/crates/orderbook/src/events/order_cancelled.rs @@ -1,12 +1,7 @@ use cainome::rs::abigen; -use starknet::core::{ - types::{EmittedEvent, Felt}, - utils::parse_cairo_short_string, -}; +use starknet::core::types::{EmittedEvent, Felt}; -use crate::types::CancelledData; - -use super::{common::to_hex_str, OrderbookParseError, ORDER_CANCELLED_SELECTOR}; +use super::{OrderbookParseError, ORDER_CANCELLED_SELECTOR}; abigen!( V1, @@ -82,7 +77,7 @@ abigen!( ); #[derive(Debug)] -pub(crate) enum OrderCancelled { +pub enum OrderCancelled { V1(OrderCancelledV1), } @@ -111,16 +106,3 @@ impl TryFrom for OrderCancelled { } } } - -impl From for CancelledData { - fn from(value: OrderCancelled) -> Self { - match value { - OrderCancelled::V1(value) => Self { - order_hash: to_hex_str(&value.order_hash), - order_type: format!("{:?}", value.order_type), - reason: parse_cairo_short_string(&value.reason) - .unwrap_or(to_hex_str(&value.reason)), - }, - } - } -} diff --git a/crates/diri/src/orderbook/events/order_executed.rs b/crates/orderbook/src/events/order_executed.rs similarity index 86% rename from crates/diri/src/orderbook/events/order_executed.rs rename to crates/orderbook/src/events/order_executed.rs index f791a3fd2..7e341b19b 100644 --- a/crates/diri/src/orderbook/events/order_executed.rs +++ b/crates/orderbook/src/events/order_executed.rs @@ -1,9 +1,7 @@ use cainome::rs::abigen; use starknet::core::types::{EmittedEvent, Felt}; -use crate::types::ExecutedData; - -use super::{common::to_hex_str, OrderbookParseError, ORDER_EXECUTED_SELECTOR}; +use super::{OrderbookParseError, ORDER_EXECUTED_SELECTOR}; abigen!( V0, @@ -327,7 +325,7 @@ abigen!( ); #[derive(Debug)] -pub(crate) enum OrderExecuted { +pub enum OrderExecuted { V0(OrderExecutedV0), V1(OrderExecutedV1), V2(OrderExecutedV2), @@ -371,34 +369,3 @@ impl TryFrom for OrderExecuted { } } } - -impl From for ExecutedData { - fn from(value: OrderExecuted) -> Self { - match value { - OrderExecuted::V0(v) => Self { - version: 0, - order_hash: to_hex_str(&v.order_hash), - order_type: None, - transaction_hash: None, - from: None, - to: None, - }, - OrderExecuted::V1(v) => Self { - version: 1, - order_hash: to_hex_str(&v.order_hash), - order_type: None, - transaction_hash: Some(to_hex_str(&v.transaction_hash)), - from: Some(to_hex_str(&Felt::from(v.from))), - to: Some(to_hex_str(&Felt::from(v.to))), - }, - OrderExecuted::V2(v) => Self { - version: 2, - order_hash: to_hex_str(&v.order_hash), - order_type: Some(format!("{:?}", v.order_type)), - transaction_hash: Some(to_hex_str(&v.transaction_hash)), - from: Some(to_hex_str(&Felt::from(v.from))), - to: Some(to_hex_str(&Felt::from(v.to))), - }, - } - } -} diff --git a/crates/diri/src/orderbook/events/order_fulfilled.rs b/crates/orderbook/src/events/order_fulfilled.rs similarity index 78% rename from crates/diri/src/orderbook/events/order_fulfilled.rs rename to crates/orderbook/src/events/order_fulfilled.rs index fe6869f0a..86a2b81f8 100644 --- a/crates/diri/src/orderbook/events/order_fulfilled.rs +++ b/crates/orderbook/src/events/order_fulfilled.rs @@ -1,12 +1,7 @@ use cainome::rs::abigen; use starknet::core::types::{EmittedEvent, Felt}; -use crate::types::FulfilledData; - -use super::{ - common::{to_hex_str, to_hex_str_opt}, - OrderbookParseError, ORDER_FULFILLED_SELECTOR, -}; +use super::{OrderbookParseError, ORDER_FULFILLED_SELECTOR}; abigen!( V1, @@ -88,7 +83,7 @@ abigen!( ); #[derive(Debug)] -pub(crate) enum OrderFulfilled { +pub enum OrderFulfilled { V1(OrderFulfilledV1), } @@ -116,20 +111,3 @@ impl TryFrom for OrderFulfilled { } } } - -impl From for FulfilledData { - fn from(value: OrderFulfilled) -> Self { - match value { - OrderFulfilled::V1(value) => { - let related_order_hash = value.related_order_hash.map(Felt::from); - - Self { - order_hash: to_hex_str(&value.order_hash), - order_type: format!("{:?}", value.order_type), - fulfiller: to_hex_str(&Felt::from(value.fulfiller)), - related_order_hash: to_hex_str_opt(&related_order_hash), - } - } - } - } -} diff --git a/crates/diri/src/orderbook/events/order_placed.rs b/crates/orderbook/src/events/order_placed.rs similarity index 74% rename from crates/diri/src/orderbook/events/order_placed.rs rename to crates/orderbook/src/events/order_placed.rs index 434cfee2d..b1a87c6e2 100644 --- a/crates/diri/src/orderbook/events/order_placed.rs +++ b/crates/orderbook/src/events/order_placed.rs @@ -1,12 +1,7 @@ use cainome::rs::abigen; use starknet::core::types::{EmittedEvent, Felt}; -use crate::types::PlacedData; - -use super::{ - common::{to_hex_str, to_hex_str_opt, u256_to_hex, u256_to_hex_opt}, - OrderbookParseError, ORDER_PLACED_SELECTOR, -}; +use super::{OrderbookParseError, ORDER_PLACED_SELECTOR}; abigen!( V1, @@ -174,7 +169,7 @@ abigen!( ); #[derive(Debug)] -pub(crate) enum OrderPlaced { +pub enum OrderPlaced { V1(OrderPlacedV1), } @@ -203,30 +198,3 @@ impl TryFrom for OrderPlaced { } } } - -impl From for PlacedData { - fn from(value: OrderPlaced) -> Self { - match value { - OrderPlaced::V1(value) => Self { - order_hash: to_hex_str(&value.order_hash), - order_version: to_hex_str(&value.order_version), - order_type: format!("{:?}", value.order_type), - cancelled_order_hash: to_hex_str_opt(&value.cancelled_order_hash), - route: format!("{:?}", value.order.route), - currency_address: to_hex_str(&Felt::from(value.order.currency_address)), - currency_chain_id: to_hex_str(&value.order.currency_chain_id), - salt: to_hex_str(&value.order.salt), - offerer: to_hex_str(&Felt::from(value.order.offerer)), - token_chain_id: format!("0x{:x}", value.order.token_chain_id), - token_address: to_hex_str(&Felt::from(value.order.token_address)), - token_id: u256_to_hex_opt(&value.order.token_id), - quantity: u256_to_hex(&value.order.quantity), - start_amount: u256_to_hex(&value.order.start_amount), - end_amount: u256_to_hex(&value.order.end_amount), - start_date: value.order.start_date, - end_date: value.order.end_date, - broker_id: to_hex_str(&Felt::from(value.order.broker_id)), - }, - } - } -} diff --git a/crates/diri/src/orderbook/events/rollback_status.rs b/crates/orderbook/src/events/rollback_status.rs similarity index 78% rename from crates/diri/src/orderbook/events/rollback_status.rs rename to crates/orderbook/src/events/rollback_status.rs index 423b0982b..646a01001 100644 --- a/crates/diri/src/orderbook/events/rollback_status.rs +++ b/crates/orderbook/src/events/rollback_status.rs @@ -1,12 +1,7 @@ use cainome::rs::abigen; -use starknet::core::{ - types::{EmittedEvent, Felt}, - utils::parse_cairo_short_string, -}; +use starknet::core::types::{EmittedEvent, Felt}; -use crate::types::RollbackStatusData; - -use super::{common::to_hex_str, OrderbookParseError, ROLLBACK_STATUS_SELECTOR}; +use super::{OrderbookParseError, ROLLBACK_STATUS_SELECTOR}; abigen!( V1, @@ -83,7 +78,7 @@ abigen!( ); #[derive(Debug)] -pub(crate) enum RollbackStatus { +pub enum RollbackStatus { V1(RollbackStatusV1), } @@ -112,16 +107,3 @@ impl TryFrom for RollbackStatus { } } } - -impl From for RollbackStatusData { - fn from(value: RollbackStatus) -> Self { - match value { - RollbackStatus::V1(value) => Self { - order_hash: to_hex_str(&value.order_hash), - order_type: format!("{:?}", value.order_type), - reason: parse_cairo_short_string(&value.reason) - .unwrap_or(to_hex_str(&value.reason)), - }, - } - } -} diff --git a/crates/diri/src/orderbook/mod.rs b/crates/orderbook/src/lib.rs similarity index 96% rename from crates/diri/src/orderbook/mod.rs rename to crates/orderbook/src/lib.rs index cf1fbd40b..e140f9fb8 100644 --- a/crates/diri/src/orderbook/mod.rs +++ b/crates/orderbook/src/lib.rs @@ -5,10 +5,10 @@ use events::{ }; use starknet::core::types::EmittedEvent; -pub(crate) mod events; +pub mod events; #[derive(Debug)] -pub(crate) enum Event { +pub enum Event { OrderPlaced(OrderPlaced), OrderExecuted(OrderExecuted), OrderCancelled(OrderCancelled), diff --git a/src/lib.rs b/src/lib.rs index c03bdcd4f..902b6ac87 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,3 +19,7 @@ pub mod diri { pub mod sana { pub use sana::*; } + +pub mod orderbook { + pub use orderbook::*; +}