From d54d2319f3a4408538b8578aef5b091ec2e24431 Mon Sep 17 00:00:00 2001 From: Dusan Stanivukovic Date: Mon, 2 Dec 2024 12:04:31 +0100 Subject: [PATCH 1/2] Sepolia fix for Cow AMMs (#3110) # Description Signature verification is now part of order creation for cow amm orders. # Changes - [ ] isValidSignature call is executed as part of creating the cow amm order ## How to test Cow amm e2e test should confirm no new issues are introduced. Fixes # https://github.com/cowprotocol/services/issues/3102 --------- Co-authored-by: MartinquaXD --- crates/cow-amm/src/amm.rs | 35 +++++++++++++++++-- .../driver/src/domain/competition/auction.rs | 20 +++++++++-- crates/driver/src/infra/blockchain/mod.rs | 4 +++ 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/crates/cow-amm/src/amm.rs b/crates/cow-amm/src/amm.rs index 9bb6385d51..64c3965acf 100644 --- a/crates/cow-amm/src/amm.rs +++ b/crates/cow-amm/src/amm.rs @@ -1,13 +1,15 @@ use { - anyhow::Result, + anyhow::{Context, Result}, app_data::AppDataHash, contracts::CowAmmLegacyHelper, ethcontract::{errors::MethodError, Address, Bytes, U256}, model::{ interaction::InteractionData, order::{BuyTokenDestination, OrderData, OrderKind, SellTokenSource}, - signature::Signature, + signature::{hashed_eip712_message, Signature}, + DomainSeparator, }, + shared::signature_validator::{SignatureCheck, SignatureValidating}, }; #[derive(Clone, Debug)] @@ -25,8 +27,8 @@ impl Amm { let tradeable_tokens = helper.tokens(address).call().await?; Ok(Self { - helper: helper.clone(), address, + helper: helper.clone(), tradeable_tokens, }) } @@ -50,6 +52,33 @@ impl Amm { self.convert_orders_reponse(order, signature, pre_interactions, post_interactions) } + /// Generates a template order to rebalance the AMM but also verifies that + /// the signature is actually valid to protect against buggy helper + /// contracts. + pub async fn validated_template_order( + &self, + prices: Vec, + validator: &dyn SignatureValidating, + domain_separator: &DomainSeparator, + ) -> Result { + let template = self.template_order(prices).await?; + + // A buggy helper contract could return a signature that is actually not valid. + // To avoid issues caused by that we check the validity of the signature. + let hash = hashed_eip712_message(domain_separator, &template.order.hash_struct()); + validator + .validate_signature_and_get_additional_gas(SignatureCheck { + signer: self.address, + hash, + signature: template.signature.to_bytes(), + interactions: template.pre_interactions.clone(), + }) + .await + .context("invalid signature")?; + + Ok(template) + } + /// Converts a successful response of the CowAmmHelper into domain types. /// Can be used for any contract that correctly implements the CoW AMM /// helper interface. diff --git a/crates/driver/src/domain/competition/auction.rs b/crates/driver/src/domain/competition/auction.rs index 8764767e6f..59cddff203 100644 --- a/crates/driver/src/domain/competition/auction.rs +++ b/crates/driver/src/domain/competition/auction.rs @@ -14,6 +14,7 @@ use { futures::future::{join_all, BoxFuture, FutureExt, Shared}, itertools::Itertools, model::{order::OrderKind, signature::Signature}, + shared::signature_validator::{Contracts, SignatureValidating}, std::{ collections::{HashMap, HashSet}, sync::{Arc, Mutex}, @@ -133,6 +134,7 @@ struct Inner { /// Order sorting strategies should be in the same order as the /// `order_priority_strategies` from the driver's config. order_sorting_strategies: Vec>, + signature_validator: Arc, } type BalanceGroup = (order::Trader, eth::TokenAddress, order::SellTokenBalance); @@ -171,6 +173,7 @@ impl AuctionProcessor { let rt = tokio::runtime::Handle::current(); let tokens: Tokens = auction.tokens().clone(); + let signature_validator = lock.signature_validator.clone(); let cow_amms = auction.surplus_capturing_jit_order_owners.clone(); let mut orders = auction.orders.clone(); let solver = *solver; @@ -180,7 +183,7 @@ impl AuctionProcessor { // and we don't want to block the runtime for too long. let fut = tokio::task::spawn_blocking(move || { let start = std::time::Instant::now(); - orders.extend(rt.block_on(Self::cow_amm_orders(ð, &tokens, &cow_amms))); + orders.extend(rt.block_on(Self::cow_amm_orders(ð, &tokens, &cow_amms, signature_validator.as_ref()))); sorting::sort_orders(&mut orders, &tokens, &solver, &order_comparators); let mut balances = rt.block_on(async { Self::fetch_balances(ð, &orders).await }); @@ -329,8 +332,11 @@ impl AuctionProcessor { eth: &Ethereum, tokens: &Tokens, eligible_for_surplus: &HashSet, + signature_validator: &dyn SignatureValidating, ) -> Vec { let cow_amms = eth.contracts().cow_amm_registry().amms().await; + let domain_separator = eth.contracts().settlement_domain_separator(); + let domain_separator = model::DomainSeparator(domain_separator.0); let results: Vec<_> = futures::future::join_all( cow_amms .into_iter() @@ -356,7 +362,7 @@ impl AuctionProcessor { Some((amm, prices)) }) .map(|(cow_amm, prices)| async move { - (*cow_amm.address(), cow_amm.template_order(prices).await) + (*cow_amm.address(), cow_amm.validated_template_order(prices, signature_validator, &domain_separator).await) }), ) .await; @@ -461,11 +467,21 @@ impl AuctionProcessor { }; order_sorting_strategies.push(comparator); } + + let signature_validator = shared::signature_validator::validator( + eth.web3(), + Contracts { + settlement: eth.contracts().settlement().address(), + vault_relayer: eth.contracts().vault_relayer().0, + }, + ); + Self(Arc::new(Mutex::new(Inner { auction: Id(0), fut: futures::future::pending().boxed().shared(), eth, order_sorting_strategies, + signature_validator, }))) } } diff --git a/crates/driver/src/infra/blockchain/mod.rs b/crates/driver/src/infra/blockchain/mod.rs index 9115d203a0..e2c930a1a9 100644 --- a/crates/driver/src/infra/blockchain/mod.rs +++ b/crates/driver/src/infra/blockchain/mod.rs @@ -254,6 +254,10 @@ impl Ethereum { .ok() .map(|gas| gas.effective().0 .0) } + + pub fn web3(&self) -> &DynWeb3 { + &self.web3 + } } impl fmt::Debug for Ethereum { From 69a68bfd8fdab0f26d80b6c767c3af64c21549c5 Mon Sep 17 00:00:00 2001 From: m-lord-renkse <160488334+m-lord-renkse@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:51:29 +0100 Subject: [PATCH 2/2] Use Debug from derive_more (#3145) # Description Use Debug from `derive_more` crate. The `Derivative` crate wasn't fully removed because of the `Default` derives. # Changes - Use Debug from `derive_more` crate - Update `derive_more` to use the first stable release `1.0.0` - Remove unused crates dependencies ## How to test 1. Unit test 2. Regression tests --- Cargo.lock | 101 +++++++----------- Cargo.toml | 2 +- crates/alerter/Cargo.toml | 2 - crates/autopilot/Cargo.toml | 3 - crates/autopilot/src/database/competition.rs | 5 +- crates/cow-amm/Cargo.toml | 1 - crates/database/Cargo.toml | 1 - crates/driver/Cargo.toml | 1 - .../driver/src/domain/liquidity/uniswap/v3.rs | 7 +- crates/driver/src/infra/liquidity/config.rs | 7 +- crates/e2e/Cargo.toml | 6 -- crates/ethrpc/Cargo.toml | 1 - crates/model/Cargo.toml | 3 +- crates/model/src/order.rs | 22 ++-- crates/model/src/solver_competition.rs | 4 +- crates/order-validation/Cargo.toml | 1 - crates/orderbook/Cargo.toml | 5 - crates/refunder/Cargo.toml | 9 +- crates/shared/Cargo.toml | 6 +- crates/shared/src/lib.rs | 7 -- crates/shared/src/trade_finding/mod.rs | 30 +++++- crates/solver/Cargo.toml | 16 +-- crates/solvers/Cargo.toml | 4 - 23 files changed, 86 insertions(+), 158 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9108e9514c..e4d50d7d64 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "Inflector" @@ -65,7 +65,6 @@ name = "alerter" version = "0.1.0" dependencies = [ "anyhow", - "chrono", "clap", "humantime", "mimalloc", @@ -80,7 +79,6 @@ dependencies = [ "shared", "tokio", "tracing", - "tracing-subscriber", "url", "warp", ] @@ -276,12 +274,10 @@ dependencies = [ "contracts", "cow-amm", "database", - "derivative", - "derive_more", + "derive_more 1.0.0", "ethcontract", "ethrpc", "futures", - "gas-estimation", "hex", "hex-literal", "humantime", @@ -307,7 +303,6 @@ dependencies = [ "shared", "sqlx", "strum", - "testlib", "thiserror", "tokio", "tracing", @@ -1271,7 +1266,7 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" name = "chain" version = "0.1.0" dependencies = [ - "derive_more", + "derive_more 1.0.0", "ethcontract", "serde", "serde_json", @@ -1420,6 +1415,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "cookie" version = "0.17.0" @@ -1477,7 +1481,6 @@ dependencies = [ "hex", "hex-literal", "model", - "primitive-types", "shared", "tokio", "tracing", @@ -1679,7 +1682,6 @@ dependencies = [ "const_format", "futures", "hex", - "hex-literal", "maplit", "sqlx", "strum", @@ -1724,13 +1726,35 @@ version = "0.99.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ - "convert_case", + "convert_case 0.4.0", "proc-macro2", "quote", "rustc_version", "syn 1.0.109", ] +[[package]] +name = "derive_more" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" +dependencies = [ + "convert_case 0.6.0", + "proc-macro2", + "quote", + "syn 2.0.66", + "unicode-xid", +] + [[package]] name = "difflib" version = "0.4.0" @@ -1776,8 +1800,7 @@ dependencies = [ "clap", "contracts", "cow-amm", - "derivative", - "derive_more", + "derive_more 1.0.0", "ethabi", "ethcontract", "ethereum-types", @@ -1831,13 +1854,11 @@ version = "1.0.0" dependencies = [ "anyhow", "app-data", - "async-trait", "autopilot", "axum", "chrono", "clap", "contracts", - "cow-amm", "database", "driver", "ethcontract", @@ -1849,7 +1870,6 @@ dependencies = [ "number", "observe", "orderbook", - "rand", "refunder", "reqwest", "secp256k1", @@ -1862,10 +1882,7 @@ dependencies = [ "sqlx", "tempfile", "tokio", - "tower", - "tower-http", "tracing", - "uuid", "warp", "web3", ] @@ -2053,7 +2070,6 @@ dependencies = [ "async-trait", "contracts", "ethcontract", - "ethereum-types", "futures", "hex", "hex-literal", @@ -3096,7 +3112,7 @@ dependencies = [ "bigdecimal", "bytes-hex", "chrono", - "derivative", + "derive_more 1.0.0", "hex", "hex-literal", "lazy_static", @@ -3108,7 +3124,6 @@ dependencies = [ "serde", "serde_json", "serde_with", - "shared", "strum", "testlib", "web3", @@ -3378,7 +3393,6 @@ dependencies = [ name = "order-validation" version = "0.1.0" dependencies = [ - "cached", "contracts", "ethcontract", "thiserror", @@ -3402,12 +3416,10 @@ dependencies = [ "database", "ethcontract", "futures", - "gas-estimation", "hex", "hex-literal", "humantime", "hyper", - "maplit", "mimalloc", "mockall 0.12.1", "model", @@ -3420,21 +3432,18 @@ dependencies = [ "prometheus", "prometheus-metric-storage", "reqwest", - "secp256k1", "serde", "serde_json", "serde_with", "shared", "sqlx", "strum_macros", - "testlib", "thiserror", "tokio", "tracing", "url", "vergen", "warp", - "web3", ] [[package]] @@ -3884,7 +3893,6 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", - "chrono", "clap", "contracts", "database", @@ -3893,19 +3901,15 @@ dependencies = [ "futures", "gas-estimation", "humantime", - "lazy_static", "mimalloc", - "model", "number", "observe", - "primitive-types", "prometheus", "prometheus-metric-storage", "shared", "sqlx", "tokio", "tracing", - "tracing-subscriber", "url", ] @@ -4467,10 +4471,10 @@ dependencies = [ "dashmap", "database", "derivative", + "derive_more 1.0.0", "ethcontract", "ethcontract-mock", "ethrpc", - "flate2", "futures", "gas-estimation", "hex", @@ -4499,17 +4503,13 @@ dependencies = [ "serde_json", "serde_with", "strum", - "tempfile", "testlib", "thiserror", - "time", "tokio", - "tokio-stream", "tracing", "tracing-subscriber", "ttl_cache", "url", - "warp", "web3", ] @@ -4570,21 +4570,14 @@ dependencies = [ "anyhow", "arc-swap", "async-trait", - "chrono", - "clap", "contracts", "derivative", "ethcontract", - "ethcontract-mock", "ethrpc", - "flate2", "futures", - "gas-estimation", "hex", "hex-literal", - "humantime", "itertools 0.12.1", - "jsonrpc-core", "lazy_static", "maplit", "mockall 0.12.1", @@ -4596,20 +4589,13 @@ dependencies = [ "primitive-types", "prometheus", "prometheus-metric-storage", - "rand", - "rate-limit", - "reqwest", "serde", "serde_json", - "serde_with", "shared", "strum", "testlib", - "thiserror", "tokio", "tracing", - "tracing-subscriber", - "url", "web3", ] @@ -4624,11 +4610,10 @@ dependencies = [ "chrono", "clap", "contracts", - "derive_more", + "derive_more 1.0.0", "ethcontract", "ethereum-types", "ethrpc", - "futures", "hex", "hex-literal", "hyper", @@ -4639,9 +4624,7 @@ dependencies = [ "observe", "prometheus", "prometheus-metric-storage", - "rate-limit", "reqwest", - "s3", "serde", "serde_json", "serde_with", @@ -4649,7 +4632,6 @@ dependencies = [ "solver", "solvers-dto", "tempfile", - "thiserror", "tokio", "toml", "tower", @@ -5557,9 +5539,6 @@ name = "uuid" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" -dependencies = [ - "getrandom", -] [[package]] name = "valuable" @@ -5729,7 +5708,7 @@ dependencies = [ "arrayvec", "base64 0.21.7", "bytes", - "derive_more", + "derive_more 0.99.17", "ethabi", "ethereum-types", "futures", diff --git a/Cargo.toml b/Cargo.toml index c3dd3d5a69..d25c30318f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ cached = { version = "0.49.3", default-features = false } chrono = { version = "0.4.38", default-features = false } clap = { version = "4.5.6", features = ["derive", "env"] } derivative = "2.2.0" -derive_more = "0.99.17" +derive_more = { version = "1.0.0", features = ["full"] } ethcontract = { version = "0.25.7", default-features = false, features = ["aws-kms"] } mimalloc = "0.1.43" ethcontract-generate = { version = "0.25.7", default-features = false } diff --git a/crates/alerter/Cargo.toml b/crates/alerter/Cargo.toml index 6b836c495c..168768e0b7 100644 --- a/crates/alerter/Cargo.toml +++ b/crates/alerter/Cargo.toml @@ -7,7 +7,6 @@ license = "MIT OR Apache-2.0" [dependencies] anyhow = { workspace = true } -chrono = { workspace = true } clap = { workspace = true } humantime = { workspace = true } observe = { path = "../observe" } @@ -22,7 +21,6 @@ serde = { workspace = true } shared = { path = "../shared" } tokio = { workspace = true, features = ["macros", "time", "rt-multi-thread"] } tracing = { workspace = true } -tracing-subscriber = { workspace = true } url = { workspace = true } warp = { workspace = true } diff --git a/crates/autopilot/Cargo.toml b/crates/autopilot/Cargo.toml index 8a28b46688..9cdfb90295 100644 --- a/crates/autopilot/Cargo.toml +++ b/crates/autopilot/Cargo.toml @@ -26,12 +26,10 @@ clap = { workspace = true } contracts = { path = "../contracts" } cow-amm = { path = "../cow-amm" } database = { path = "../database" } -derivative = { workspace = true } derive_more = { workspace = true } ethcontract = { workspace = true } ethrpc = { path = "../ethrpc" } futures = { workspace = true } -gas-estimation = { workspace = true } observe = { path = "../observe" } hex = { workspace = true } hex-literal = { workspace = true } @@ -64,7 +62,6 @@ web3 = { workspace = true } [dev-dependencies] mockall = { workspace = true } -testlib = { path = "../testlib" } tokio = { workspace = true, features = ["test-util"] } [lints] diff --git a/crates/autopilot/src/database/competition.rs b/crates/autopilot/src/database/competition.rs index 7d55fce9c1..81cc5e63ef 100644 --- a/crates/autopilot/src/database/competition.rs +++ b/crates/autopilot/src/database/competition.rs @@ -9,15 +9,14 @@ use { surplus_capturing_jit_order_owners, Address, }, - derivative::Derivative, + derive_more::Debug, model::solver_competition::SolverCompetitionDB, number::conversions::u256_to_big_decimal, primitive_types::{H160, U256}, std::collections::{BTreeMap, HashSet}, }; -#[derive(Clone, Default, Derivative)] -#[derivative(Debug)] +#[derive(Clone, Default, Debug)] pub struct Competition { pub auction_id: AuctionId, pub winner: H160, diff --git a/crates/cow-amm/Cargo.toml b/crates/cow-amm/Cargo.toml index e4a949b6b5..7c3bcc4dae 100644 --- a/crates/cow-amm/Cargo.toml +++ b/crates/cow-amm/Cargo.toml @@ -11,7 +11,6 @@ contracts = { path = "../contracts" } ethcontract = { workspace = true } ethrpc = { path = "../ethrpc" } model = { path = "../model" } -primitive-types = { workspace = true } shared = { path = "../shared" } tokio = { workspace = true, features = [] } tracing = { workspace = true } diff --git a/crates/database/Cargo.toml b/crates/database/Cargo.toml index 59d00f0745..572530a842 100644 --- a/crates/database/Cargo.toml +++ b/crates/database/Cargo.toml @@ -15,7 +15,6 @@ sqlx = { workspace = true } strum = { workspace = true } [dev-dependencies] -hex-literal = { workspace = true } maplit = { workspace = true } tokio = { workspace = true, features = ["macros"] } diff --git a/crates/driver/Cargo.toml b/crates/driver/Cargo.toml index 874cc5a008..35dd748162 100644 --- a/crates/driver/Cargo.toml +++ b/crates/driver/Cargo.toml @@ -24,7 +24,6 @@ axum = { workspace = true } bigdecimal = { workspace = true } chrono = { workspace = true, features = ["clock"], default-features = false } cow-amm = { path = "../cow-amm" } -derivative = { workspace = true } derive_more = { workspace = true } ethabi = "18.0" ethereum-types = { workspace = true } diff --git a/crates/driver/src/domain/liquidity/uniswap/v3.rs b/crates/driver/src/domain/liquidity/uniswap/v3.rs index 7293c1a1e0..8325db95a5 100644 --- a/crates/driver/src/domain/liquidity/uniswap/v3.rs +++ b/crates/driver/src/domain/liquidity/uniswap/v3.rs @@ -6,15 +6,14 @@ use { liquidity::{self, InvalidSwap}, }, }, - derivative::Derivative, + derive_more::Debug, std::collections::BTreeMap, }; /// A Uniswap V3 concentrated liquidity pool. /// /// [^1]: -#[derive(Clone, Derivative)] -#[derivative(Debug)] +#[derive(Clone, Debug)] pub struct Pool { pub router: eth::ContractAddress, pub address: eth::ContractAddress, @@ -22,7 +21,7 @@ pub struct Pool { pub sqrt_price: SqrtPrice, pub liquidity: Liquidity, pub tick: Tick, - #[derivative(Debug = "ignore")] + #[debug(ignore)] pub liquidity_net: BTreeMap, pub fee: Fee, } diff --git a/crates/driver/src/infra/liquidity/config.rs b/crates/driver/src/infra/liquidity/config.rs index 49fd218ac9..9900d374a3 100644 --- a/crates/driver/src/infra/liquidity/config.rs +++ b/crates/driver/src/infra/liquidity/config.rs @@ -1,6 +1,6 @@ use { crate::{domain::eth, infra::blockchain::contracts::deployment_address}, - derivative::Derivative, + derive_more::Debug, hex_literal::hex, reqwest::Url, std::{collections::HashSet, time::Duration}, @@ -235,11 +235,10 @@ impl BalancerV2 { } /// ZeroEx liquidity fetching options. -#[derive(Clone, Derivative)] -#[derivative(Debug)] +#[derive(Clone, Debug)] pub struct ZeroEx { pub base_url: String, - #[derivative(Debug = "ignore")] + #[debug(ignore)] pub api_key: Option, pub http_timeout: Duration, } diff --git a/crates/e2e/Cargo.toml b/crates/e2e/Cargo.toml index 2540329abc..96a90421ca 100644 --- a/crates/e2e/Cargo.toml +++ b/crates/e2e/Cargo.toml @@ -8,13 +8,11 @@ license = "MIT OR Apache-2.0" [dependencies] app-data = { path = "../app-data" } anyhow = { workspace = true } -async-trait = { workspace = true } autopilot = { path = "../autopilot" } axum = { workspace = true } chrono = { workspace = true } clap = { workspace = true } contracts = { path = "../contracts" } -cow-amm = { path = "../cow-amm" } database = { path = "../database" } driver = { path = "../driver" } ethcontract = { workspace = true } @@ -36,16 +34,12 @@ solvers-dto = { path = "../solvers-dto" } sqlx = { workspace = true } tempfile = { workspace = true } tokio = { workspace = true, features = ["macros", "process"] } -tower = "0.4" -tower-http = { version = "0.4", features = ["limit", "trace"] } tracing = { workspace = true } warp = { workspace = true } web3 = { workspace = true, features = ["http"] } -uuid = { version = "1.8.0", features = ["v4"] } [dev-dependencies] futures = { workspace = true } -rand = { workspace = true } refunder = { path = "../refunder" } [lints] diff --git a/crates/ethrpc/Cargo.toml b/crates/ethrpc/Cargo.toml index 1d26464d9b..a6e628dabc 100644 --- a/crates/ethrpc/Cargo.toml +++ b/crates/ethrpc/Cargo.toml @@ -13,7 +13,6 @@ doctest = false [dependencies] anyhow = { workspace = true } async-trait = { workspace = true } -ethereum-types = { workspace = true } futures = { workspace = true } hex = { workspace = true } hex-literal = { workspace = true } diff --git a/crates/model/Cargo.toml b/crates/model/Cargo.toml index 4636d07a9f..d6a8f19af1 100644 --- a/crates/model/Cargo.toml +++ b/crates/model/Cargo.toml @@ -14,7 +14,7 @@ app-data = { path = "../app-data" } bytes-hex = { path = "../bytes-hex" } bigdecimal = { workspace = true } chrono = { workspace = true, features = ["serde", "clock"] } -derivative = { workspace = true } +derive_more = { workspace = true } hex = { workspace = true, default-features = false } hex-literal = { workspace = true } lazy_static = { workspace = true } @@ -29,7 +29,6 @@ web3 = { workspace = true, features = ["signing"] } [dev-dependencies] serde_json = { workspace = true } -shared = { path = "../shared" } maplit = { workspace = true } testlib = { path = "../testlib" } diff --git a/crates/model/src/order.rs b/crates/model/src/order.rs index 0e2f6c86a4..4d3ca859a7 100644 --- a/crates/model/src/order.rs +++ b/crates/model/src/order.rs @@ -1,6 +1,5 @@ //! Contains the order type as described by the specification with serialization //! as described by the openapi documentation. -#![allow(clippy::needless_lifetimes)] // todo: migrate from derivative to derive_more use { crate::{ @@ -13,7 +12,7 @@ use { anyhow::{anyhow, Result}, app_data::{hash_full_app_data, AppDataHash}, chrono::{offset::Utc, DateTime}, - derivative::Derivative, + derive_more::Debug as DeriveDebug, hex_literal::hex, num::BigUint, number::serialization::HexOrDecimalU256, @@ -642,7 +641,7 @@ impl ::serde::Serialize for EthflowData { } } -#[derive(Debug, Eq, PartialEq, Clone, Derivative, Deserialize, Serialize)] +#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub enum OnchainOrderPlacementError { ValidToTooFarInTheFuture, @@ -669,8 +668,7 @@ pub enum OnchainOrderPlacementError { // stores all data related to onchain order palcement #[serde_as] -#[derive(Eq, PartialEq, Clone, Default, Derivative, Deserialize, Serialize)] -#[derivative(Debug)] +#[derive(Eq, PartialEq, Clone, Default, Deserialize, Serialize, Debug)] #[serde(rename_all = "camelCase")] pub struct OnchainOrderData { pub sender: H160, @@ -679,8 +677,7 @@ pub struct OnchainOrderData { /// An order as provided to the orderbook by the frontend. #[serde_as] -#[derive(Eq, PartialEq, Clone, Default, Derivative, Deserialize, Serialize)] -#[derivative(Debug)] +#[derive(Eq, PartialEq, Clone, Default, Deserialize, Serialize, DeriveDebug)] #[serde(rename_all = "camelCase")] pub struct OrderMetadata { pub creation_date: DateTime, @@ -689,10 +686,10 @@ pub struct OrderMetadata { /// deprecated, always set to null #[serde_as(as = "Option")] pub available_balance: Option, - #[derivative(Debug(format_with = "debug_biguint_to_string"))] + #[debug("{}", format_args!("{executed_buy_amount}"))] #[serde_as(as = "DisplayFromStr")] pub executed_buy_amount: BigUint, - #[derivative(Debug(format_with = "debug_biguint_to_string"))] + #[debug("{}", format_args!("{executed_sell_amount}"))] #[serde_as(as = "DisplayFromStr")] pub executed_sell_amount: BigUint, #[serde_as(as = "HexOrDecimalU256")] @@ -1010,13 +1007,6 @@ impl BuyTokenDestination { } } -pub fn debug_biguint_to_string( - value: &BigUint, - formatter: &mut std::fmt::Formatter, -) -> Result<(), std::fmt::Error> { - formatter.write_fmt(format_args!("{value}")) -} - #[cfg(test)] mod tests { use { diff --git a/crates/model/src/solver_competition.rs b/crates/model/src/solver_competition.rs index 58a00a732e..6fba23d1ed 100644 --- a/crates/model/src/solver_competition.rs +++ b/crates/model/src/solver_competition.rs @@ -1,6 +1,5 @@ use { crate::{auction::AuctionId, order::OrderUid}, - derivative::Derivative, number::serialization::HexOrDecimalU256, primitive_types::{H160, H256, U256}, serde::{Deserialize, Serialize}, @@ -40,8 +39,7 @@ pub struct CompetitionAuction { } #[serde_as] -#[derive(Clone, Default, Deserialize, Serialize, PartialEq, Derivative)] -#[derivative(Debug)] +#[derive(Clone, Default, Deserialize, Serialize, PartialEq, Debug)] #[serde(rename_all = "camelCase")] pub struct SolverSettlement { pub solver: String, diff --git a/crates/order-validation/Cargo.toml b/crates/order-validation/Cargo.toml index 428e9f8af5..30b46115b0 100644 --- a/crates/order-validation/Cargo.toml +++ b/crates/order-validation/Cargo.toml @@ -6,7 +6,6 @@ edition = "2021" license = "MIT OR Apache-2.0" [dependencies] -cached = { workspace = true } contracts = { path = "../contracts" } ethcontract = { workspace = true } thiserror = { workspace = true } diff --git a/crates/orderbook/Cargo.toml b/crates/orderbook/Cargo.toml index 88ed70160a..9097e76ba5 100644 --- a/crates/orderbook/Cargo.toml +++ b/crates/orderbook/Cargo.toml @@ -28,12 +28,10 @@ contracts = { path = "../contracts" } database = { path = "../database" } ethcontract = { workspace = true } futures = { workspace = true } -gas-estimation = { workspace = true } hex = { workspace = true } hex-literal = { workspace = true } humantime = { workspace = true } hyper = { workspace = true } -maplit = { workspace = true } mimalloc = { workspace = true } model = { path = "../model" } multibase = "0.9" @@ -56,12 +54,9 @@ tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal", " tracing = { workspace = true } url = { workspace = true } warp = { workspace = true } -web3 = { workspace = true } [dev-dependencies] mockall = { workspace = true } -secp256k1 = { workspace = true } -testlib = { path = "../testlib" } tokio = { workspace = true, features = ["test-util"] } [build-dependencies] diff --git a/crates/refunder/Cargo.toml b/crates/refunder/Cargo.toml index d201b78438..3e6438b84a 100644 --- a/crates/refunder/Cargo.toml +++ b/crates/refunder/Cargo.toml @@ -8,28 +8,23 @@ license = "MIT OR Apache-2.0" [dependencies] anyhow = { workspace = true } async-trait = { workspace = true } -chrono = { workspace = true } clap = { workspace = true } -contracts = { path = "../contracts" } +contracts = { path = "../contracts" } database = { path = "../database" } ethcontract = { workspace = true } ethrpc = { path = "../ethrpc" } -futures = {workspace = true} +futures = { workspace = true } gas-estimation = { workspace = true } humantime = { workspace = true } -lazy_static = { workspace = true } mimalloc = "0.1.43" -model = { path = "../model" } number = { path = "../number" } observe = { path = "../observe" } -primitive-types = { workspace = true } prometheus = { workspace = true } prometheus-metric-storage = { workspace = true } shared = { path = "../shared" } sqlx = { workspace = true } tokio = { workspace = true, features = ["macros", "time", "rt-multi-thread"] } tracing = { workspace = true } -tracing-subscriber = { workspace = true } url = { workspace = true } [lints] diff --git a/crates/shared/Cargo.toml b/crates/shared/Cargo.toml index 104127e75e..f86b75cfd3 100644 --- a/crates/shared/Cargo.toml +++ b/crates/shared/Cargo.toml @@ -21,11 +21,11 @@ clap = { workspace = true } contracts = { path = "../contracts" } dashmap = "6.1.0" database = { path = "../database" } +derive_more = { workspace = true } ttl_cache = "0.5" derivative = { workspace = true } ethcontract = { workspace = true } ethrpc = { path = "../ethrpc" } -flate2 = { workspace = true } futures = { workspace = true } gas-estimation = { workspace = true } observe = { path = "../observe" } @@ -54,18 +54,14 @@ serde_json = { workspace = true } serde_with = { workspace = true } strum = { workspace = true } thiserror = { workspace = true } -time = { workspace = true } tokio = { workspace = true, features = ["macros", "time"] } -tokio-stream = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true, features = ["env-filter", "fmt", "time"] } url = { workspace = true } -warp = { workspace = true } web3 = { workspace = true } [dev-dependencies] async-stream = "0.3.5" -tempfile = { workspace = true } ethcontract-mock = { workspace = true } regex = { workspace = true } testlib = { path = "../testlib" } diff --git a/crates/shared/src/lib.rs b/crates/shared/src/lib.rs index f56731404c..ed325a2f4e 100644 --- a/crates/shared/src/lib.rs +++ b/crates/shared/src/lib.rs @@ -54,13 +54,6 @@ pub async fn measure_time(future: impl Future, timer: impl FnOnce result } -pub fn debug_bytes( - bytes: impl AsRef<[u8]>, - formatter: &mut std::fmt::Formatter, -) -> Result<(), std::fmt::Error> { - formatter.write_fmt(format_args!("0x{}", hex::encode(bytes.as_ref()))) -} - /// anyhow errors are not clonable natively. This is a workaround that creates a /// new anyhow error based on formatting the error with its inner sources /// without backtrace. diff --git a/crates/shared/src/trade_finding/mod.rs b/crates/shared/src/trade_finding/mod.rs index 2cb4cba961..221964b0e7 100644 --- a/crates/shared/src/trade_finding/mod.rs +++ b/crates/shared/src/trade_finding/mod.rs @@ -1,13 +1,12 @@ //! A module for abstracting a component that can produce a quote with calldata //! for a specified token pair and amount. -#![allow(clippy::needless_lifetimes)] // todo: migrate from derivative to derive_more pub mod external; use { crate::price_estimation::{PriceEstimationError, Query}, anyhow::Result, - derivative::Derivative, + derive_more::Debug, ethcontract::{contract::MethodBuilder, tokens::Tokenize, web3::Transport, Bytes, H160, U256}, model::interaction::InteractionData, serde::Serialize, @@ -51,12 +50,11 @@ pub struct Trade { } /// Data for a raw GPv2 interaction. -#[derive(Clone, PartialEq, Eq, Hash, Default, Serialize, Derivative)] -#[derivative(Debug)] +#[derive(Clone, PartialEq, Eq, Hash, Default, Serialize, Debug)] pub struct Interaction { pub target: H160, pub value: U256, - #[derivative(Debug(format_with = "crate::debug_bytes"))] + #[debug("0x{}", hex::encode::<&[u8]>(data.as_ref()))] pub data: Vec, } @@ -142,3 +140,25 @@ impl Clone for TradeError { pub fn map_interactions(interactions: &[InteractionData]) -> Vec { interactions.iter().cloned().map(Into::into).collect() } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_debug_interaction() { + let interaction = Interaction { + target: H160::zero(), + value: U256::one(), + data: vec![0x01, 0x02, 0x03, 0x04, 0x05, 0x06], + }; + + let interaction_debug = format!("{:?}", interaction); + + assert_eq!( + interaction_debug, + "Interaction { target: 0x0000000000000000000000000000000000000000, value: 1, data: \ + 0x010203040506 }" + ); + } +} diff --git a/crates/solver/Cargo.toml b/crates/solver/Cargo.toml index cbb488c755..aa80153249 100644 --- a/crates/solver/Cargo.toml +++ b/crates/solver/Cargo.toml @@ -14,21 +14,14 @@ doctest = false anyhow = { workspace = true } arc-swap = "1.7.1" async-trait = { workspace = true } -chrono = { workspace = true, features = ["clock"] } -clap = { workspace = true } contracts = { path = "../contracts" } -derivative = { workspace = true } ethcontract = { workspace = true } ethrpc = { path = "../ethrpc" } -flate2 = { workspace = true } futures = { workspace = true } -gas-estimation = { workspace = true } observe = { path = "../observe" } hex = { workspace = true } hex-literal = { workspace = true } -humantime = { workspace = true } itertools = { workspace = true } -jsonrpc-core = "18" lazy_static = { workspace = true } maplit = { workspace = true } mockall = { workspace = true } @@ -39,24 +32,17 @@ once_cell = { workspace = true } primitive-types = { workspace = true } prometheus = { workspace = true } prometheus-metric-storage = { workspace = true } -rand = { workspace = true } -rate-limit = { path = "../rate-limit" } -reqwest = { workspace = true, features = ["json"] } serde = { workspace = true } serde_json = { workspace = true } -serde_with = { workspace = true } shared = { path = "../shared" } strum = { workspace = true } -thiserror = { workspace = true } tokio = { workspace = true, features = ["macros", "rt-multi-thread", "time"] } tracing = { workspace = true } -url = { workspace = true } web3 = { workspace = true } [dev-dependencies] -ethcontract-mock = { workspace = true } +derivative = { workspace = true } tokio = { workspace = true, features = ["test-util"] } -tracing-subscriber = { workspace = true } testlib = { path = "../testlib" } [lints] diff --git a/crates/solvers/Cargo.toml b/crates/solvers/Cargo.toml index 54eb233926..46bf8a143e 100644 --- a/crates/solvers/Cargo.toml +++ b/crates/solvers/Cargo.toml @@ -21,7 +21,6 @@ clap = { workspace = true, features = ["derive", "env"] } derive_more = { workspace = true } ethereum-types = { workspace = true } ethrpc = { path = "../ethrpc" } -futures = { workspace = true } hex = { workspace = true } hyper = { workspace = true } itertools = { workspace = true } @@ -29,14 +28,11 @@ mimalloc = { workspace = true } num = { workspace = true } prometheus = { workspace = true } prometheus-metric-storage = { workspace = true } -rate-limit = { path = "../rate-limit" } reqwest = { workspace = true } -s3 = { path = "../s3" } serde = { workspace = true } serde_json = { workspace = true } serde_with = { workspace = true } solvers-dto = { path = "../solvers-dto" } -thiserror = { workspace = true } tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal", "time"] } toml = { workspace = true } tower = "0.4"