diff --git a/Cargo.lock b/Cargo.lock index d2186bc261..37a8e30dab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -836,7 +836,7 @@ checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" name = "app-data" version = "0.1.0" dependencies = [ - "alloy", + "alloy-primitives", "anyhow", "bytes-hex", "const-hex", @@ -846,7 +846,6 @@ dependencies = [ "serde", "serde_json", "serde_with", - "tiny-keccak", ] [[package]] @@ -2072,10 +2071,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" name = "chain" version = "0.1.0" dependencies = [ - "alloy", + "alloy-primitives", "serde", "serde_json", - "thiserror 1.0.69", ] [[package]] @@ -4341,7 +4339,10 @@ dependencies = [ name = "model" version = "0.1.0" dependencies = [ - "alloy", + "alloy-primitives", + "alloy-signer", + "alloy-signer-local", + "alloy-sol-types", "anyhow", "app-data", "bigdecimal", @@ -4568,7 +4569,7 @@ dependencies = [ name = "number" version = "0.1.0" dependencies = [ - "alloy", + "alloy-primitives", "anyhow", "bigdecimal", "num", @@ -4768,11 +4769,11 @@ dependencies = [ name = "order-validation" version = "0.1.0" dependencies = [ - "alloy", + "alloy-contract", + "alloy-primitives", "contracts", "futures", "moka", - "thiserror 1.0.69", "tokio", "tracing", ] @@ -6172,7 +6173,7 @@ dependencies = [ name = "serde-ext" version = "0.1.0" dependencies = [ - "alloy", + "alloy-primitives", "const-hex", "serde", "serde_with", @@ -6933,7 +6934,7 @@ checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683" name = "testlib" version = "0.1.0" dependencies = [ - "alloy", + "alloy-primitives", "anyhow", "maplit", "serde_json", @@ -8253,7 +8254,7 @@ checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" name = "winner-selection" version = "0.1.0" dependencies = [ - "alloy", + "alloy-primitives", "anyhow", "itertools 0.14.0", "number", diff --git a/Cargo.toml b/Cargo.toml index 850c47dc49..79f6822180 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,9 +4,11 @@ members = ["crates/*"] [workspace.dependencies] alloy = { version = "1.7.3", default-features = false } -# alloy-signer was added because eip712 on the regular alloy crate brings way too much stuff with it -# as such, this is a workaround to force feature unification over alloy to the feature set we want +alloy-contract = { version = "1.7.3", default-features = false } +alloy-primitives = { version = "1.5.2", default-features = false } alloy-signer = { version = "1.7.3", default-features = false} +alloy-signer-local = { version = "1.7.3", default-features = false} +alloy-sol-types = { version = "1.5.2" } anyhow = "1.0.100" async-trait = "0.1.80" axum = "0.8" @@ -93,7 +95,6 @@ solvers-dto = { path = "crates/solvers-dto" } testlib = { path = "crates/testlib" } winner-selection = { path = "crates/winner-selection" } time = "0.3.47" -tiny-keccak = "2.0.2" tower = "0.5" tower-http = "0.6" tracing-opentelemetry = "0.32.1" diff --git a/crates/app-data/Cargo.toml b/crates/app-data/Cargo.toml index 7265a009b4..1658ab82e8 100644 --- a/crates/app-data/Cargo.toml +++ b/crates/app-data/Cargo.toml @@ -6,7 +6,7 @@ edition = "2024" license = "MIT OR Apache-2.0" [dependencies] -alloy = { workspace = true, features = ["serde"] } +alloy-primitives = { workspace = true, features = ["serde"] } anyhow = { workspace = true } bytes-hex = { workspace = true } const-hex = { workspace = true } @@ -15,7 +15,6 @@ number = { path = "../number" } serde = { workspace = true } serde_json = { workspace = true } serde_with = { workspace = true } -tiny-keccak = { workspace = true, features = ["keccak"] } [dev-dependencies] hex-literal = { workspace = true } diff --git a/crates/app-data/src/app_data.rs b/crates/app-data/src/app_data.rs index ac5b49fe50..e1dae79ed9 100644 --- a/crates/app-data/src/app_data.rs +++ b/crates/app-data/src/app_data.rs @@ -1,6 +1,6 @@ use { crate::{AppDataHash, Hooks, app_data_hash::hash_full_app_data}, - alloy::primitives::{Address, U256}, + alloy_primitives::{Address, U256}, anyhow::{Context, Result, anyhow}, bytes_hex::BytesHex, moka::sync::Cache, diff --git a/crates/app-data/src/app_data_hash.rs b/crates/app-data/src/app_data_hash.rs index 91e673e84b..b51b94e27e 100644 --- a/crates/app-data/src/app_data_hash.rs +++ b/crates/app-data/src/app_data_hash.rs @@ -28,7 +28,6 @@ use { fmt::{self, Debug, Formatter}, str::FromStr, }, - tiny_keccak::{Hasher, Keccak}, }; /// A JSON object used to represent app data documents for uploading and @@ -107,11 +106,7 @@ impl PartialEq<[u8; 32]> for AppDataHash { /// Hash full app data to get the bytes expected to be set as the contract level /// app data. pub fn hash_full_app_data(app_data: &[u8]) -> [u8; 32] { - let mut hasher = Keccak::v256(); - hasher.update(app_data); - let mut hash = [0u8; 32]; - hasher.finalize(&mut hash); - hash + alloy_primitives::keccak256(app_data).0 } /// Create an IPFS CIDv1 from a hash created by `hash_full_app_data`. diff --git a/crates/app-data/src/hooks.rs b/crates/app-data/src/hooks.rs index a37a0ba3a2..c61e971761 100644 --- a/crates/app-data/src/hooks.rs +++ b/crates/app-data/src/hooks.rs @@ -1,5 +1,5 @@ use { - alloy::primitives::Address, + alloy_primitives::Address, bytes_hex::BytesHex, serde::{Deserialize, Serialize}, serde_with::{DisplayFromStr, serde_as}, diff --git a/crates/chain/Cargo.toml b/crates/chain/Cargo.toml index e14810e979..4bbdb1d21d 100644 --- a/crates/chain/Cargo.toml +++ b/crates/chain/Cargo.toml @@ -6,9 +6,8 @@ edition = "2024" license = "MIT OR Apache-2.0" [dependencies] -alloy = { workspace = true } +alloy-primitives = { workspace = true } serde = { workspace = true } -thiserror = { workspace = true } [dev-dependencies] serde_json = { workspace = true } diff --git a/crates/chain/src/lib.rs b/crates/chain/src/lib.rs index d9f04dfeae..0321b30b53 100644 --- a/crates/chain/src/lib.rs +++ b/crates/chain/src/lib.rs @@ -1,8 +1,7 @@ use { - alloy::primitives::U256, + alloy_primitives::U256, serde::{Deserialize, Deserializer, de}, - std::time::Duration, - thiserror::Error, + std::{error::Error, fmt::Display, time::Duration}, }; /// Represents each available chain @@ -177,10 +176,17 @@ impl<'de> Deserialize<'de> for Chain { } } -#[derive(Error, Debug)] -#[error("chain id not supported")] +#[derive(Debug)] pub struct ChainIdNotSupported; +impl Display for ChainIdNotSupported { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "chain id not supported") + } +} + +impl Error for ChainIdNotSupported {} + #[cfg(test)] mod test { use super::*; diff --git a/crates/model/Cargo.toml b/crates/model/Cargo.toml index 2db4cc3f15..2df366e60c 100644 --- a/crates/model/Cargo.toml +++ b/crates/model/Cargo.toml @@ -9,7 +9,10 @@ license = "MIT OR Apache-2.0" doctest = false [dependencies] -alloy = { workspace = true, features = ["sol-types", "signers", "signer-local", "rand"] } +alloy-primitives = { workspace = true } +alloy-signer = { workspace = true } +alloy-signer-local = { workspace = true } +alloy-sol-types = { workspace = true } anyhow = { workspace = true } app-data = { workspace = true } bigdecimal = { workspace = true } diff --git a/crates/model/src/fee_policy.rs b/crates/model/src/fee_policy.rs index 68f1f6fa45..72c5c5c1d5 100644 --- a/crates/model/src/fee_policy.rs +++ b/crates/model/src/fee_policy.rs @@ -1,5 +1,5 @@ use { - alloy::primitives::{Address, U256}, + alloy_primitives::{Address, U256}, number::serialization::HexOrDecimalU256, serde::Serialize, serde_with::serde_as, diff --git a/crates/model/src/interaction.rs b/crates/model/src/interaction.rs index 67a6d0f449..1cdbd7c021 100644 --- a/crates/model/src/interaction.rs +++ b/crates/model/src/interaction.rs @@ -1,5 +1,5 @@ use { - alloy::primitives::{Address, U256}, + alloy_primitives::{Address, U256}, number::serialization::HexOrDecimalU256, serde::{Deserialize, Serialize}, serde_with::serde_as, diff --git a/crates/model/src/lib.rs b/crates/model/src/lib.rs index 662e45a3d2..4f3919f717 100644 --- a/crates/model/src/lib.rs +++ b/crates/model/src/lib.rs @@ -11,7 +11,8 @@ pub mod time; pub mod trade; use { - alloy::primitives::Address, + alloy_primitives::{Address, U256}, + alloy_sol_types::Eip712Domain, const_hex::{FromHex, FromHexError}, std::fmt, }; @@ -112,10 +113,10 @@ impl std::fmt::Debug for DomainSeparator { impl DomainSeparator { pub fn new(chain_id: u64, contract_address: Address) -> Self { - let domain = alloy::sol_types::Eip712Domain { + let domain = Eip712Domain { name: Some("Gnosis Protocol".into()), version: Some("v2".into()), - chain_id: Some(alloy::primitives::U256::from(chain_id)), + chain_id: Some(U256::from(chain_id)), verifying_contract: Some(contract_address), salt: None, }; @@ -128,7 +129,7 @@ impl DomainSeparator { mod tests { use { super::*, - alloy::primitives::address, + alloy_primitives::address, hex_literal::hex, std::{cmp::Ordering, str::FromStr}, }; diff --git a/crates/model/src/order.rs b/crates/model/src/order.rs index d83c3003d9..f4b76b1b80 100644 --- a/crates/model/src/order.rs +++ b/crates/model/src/order.rs @@ -9,10 +9,8 @@ use { quote::QuoteId, signature::{self, EcdsaSignature, EcdsaSigningScheme, Signature}, }, - alloy::{ - primitives::{Address, B256, U256, U512, b256, keccak256}, - signers::local::PrivateKeySigner, - }, + alloy_primitives::{Address, B256, U256, U512, b256, keccak256}, + alloy_signer_local::PrivateKeySigner, anyhow::{Result, anyhow}, app_data::{AppDataHash, hash_full_app_data}, bigdecimal::BigDecimal, @@ -100,12 +98,12 @@ impl OrderBuilder { self } - pub fn with_sell_amount(mut self, sell_amount: alloy::primitives::U256) -> Self { + pub fn with_sell_amount(mut self, sell_amount: U256) -> Self { self.0.data.sell_amount = sell_amount; self } - pub fn with_buy_amount(mut self, buy_amount: alloy::primitives::U256) -> Self { + pub fn with_buy_amount(mut self, buy_amount: U256) -> Self { self.0.data.buy_amount = buy_amount; self } @@ -125,7 +123,7 @@ impl OrderBuilder { self } - pub fn with_fee_amount(mut self, fee_amount: alloy::primitives::U256) -> Self { + pub fn with_fee_amount(mut self, fee_amount: U256) -> Self { self.0.data.fee_amount = fee_amount; self } @@ -206,9 +204,9 @@ pub struct OrderData { #[serde(default)] pub receiver: Option
, #[serde_as(as = "HexOrDecimalU256")] - pub sell_amount: alloy::primitives::U256, + pub sell_amount: U256, #[serde_as(as = "HexOrDecimalU256")] - pub buy_amount: alloy::primitives::U256, + pub buy_amount: U256, pub valid_to: u32, pub app_data: AppDataHash, /// Fees that will be taken in terms of `sell_token`. @@ -217,7 +215,7 @@ pub struct OrderData { /// and should not be settled on their own. /// This is 0 for limit orders as their fee gets taken from the surplus. #[serde_as(as = "HexOrDecimalU256")] - pub fee_amount: alloy::primitives::U256, + pub fee_amount: U256, pub kind: OrderKind, pub partially_fillable: bool, #[serde(default)] @@ -283,9 +281,9 @@ impl OrderData { /// sell token and buy `buy` amount of buy token. Additionally, `fee`` /// denominated in the sell token needs to be payed. pub struct QuoteAmounts { - pub sell: alloy::primitives::U256, - pub buy: alloy::primitives::U256, - pub fee: alloy::primitives::U256, + pub sell: U256, + pub buy: U256, + pub fee: U256, } /// An order as provided to the POST order endpoint. @@ -304,10 +302,10 @@ pub struct OrderCreation { pub receiver: Option, /// The *maximum* amount of `sell_token`s that may be sold. #[serde_as(as = "HexOrDecimalU256")] - pub sell_amount: alloy::primitives::U256, + pub sell_amount: U256, /// The *minimum* amount of `buy_token`s that should be bought. #[serde_as(as = "HexOrDecimalU256")] - pub buy_amount: alloy::primitives::U256, + pub buy_amount: U256, /// The block timestamp when the order can no longer be settled (UNIX /// timestamp in seconds). pub valid_to: u32, @@ -317,7 +315,7 @@ pub struct OrderCreation { /// /// Deprecation note: orders with a non-zero `fee_amount` should be rejected /// by the API. - pub fee_amount: alloy::primitives::U256, + pub fee_amount: U256, /// The kind of order (i.e. sell or buy). pub kind: OrderKind, /// Whether the order can be carried out in multiple smaller trades, or it @@ -1066,7 +1064,7 @@ mod tests { use { super::*, crate::signature::{EcdsaSigningScheme, SigningScheme}, - alloy::primitives::{address, b256}, + alloy_primitives::{address, b256}, chrono::TimeZone, hex_literal::hex, maplit::hashset, @@ -1140,13 +1138,13 @@ mod tests { sell_token: Address::with_last_byte(10), buy_token: Address::with_last_byte(9), receiver: Some(Address::with_last_byte(11)), - sell_amount: alloy::primitives::U256::ONE, - buy_amount: alloy::primitives::U256::ZERO, + sell_amount: U256::ONE, + buy_amount: U256::ZERO, valid_to: u32::MAX, app_data: AppDataHash(hex!( "6000000000000000000000000000000000000000000000000000000000000007" )), - fee_amount: alloy::primitives::U256::MAX, + fee_amount: U256::MAX, kind: OrderKind::Buy, partially_fillable: false, sell_token_balance: SellTokenSource::External, @@ -1217,13 +1215,13 @@ mod tests { sell_token: Address::repeat_byte(0x11), buy_token: Address::repeat_byte(0x22), receiver: Some(Address::repeat_byte(0x33)), - sell_amount: alloy::primitives::U256::from(123), - buy_amount: alloy::primitives::U256::from(456), + sell_amount: U256::from(123), + buy_amount: U256::from(456), valid_to: 1337, app_data: OrderCreationAppData::Hash { hash: AppDataHash([0x44; 32]), }, - fee_amount: alloy::primitives::U256::from(789), + fee_amount: U256::from(789), kind: OrderKind::Sell, partially_fillable: false, sell_token_balance: SellTokenSource::Erc20, @@ -1390,13 +1388,13 @@ mod tests { sell_token: hex!("0101010101010101010101010101010101010101").into(), buy_token: hex!("0202020202020202020202020202020202020202").into(), receiver: Some(hex!("0303030303030303030303030303030303030303").into()), - sell_amount: alloy::primitives::U256::from(0x0246ddf97976680000_u128), - buy_amount: alloy::primitives::U256::from(0xb98bc829a6f90000_u128), + sell_amount: U256::from(0x0246ddf97976680000_u128), + buy_amount: U256::from(0xb98bc829a6f90000_u128), valid_to: 0xffffffff, app_data: AppDataHash(hex!( "0000000000000000000000000000000000000000000000000000000000000000" )), - fee_amount: alloy::primitives::U256::from(0x0de0b6b3a7640000_u128), + fee_amount: U256::from(0x0de0b6b3a7640000_u128), kind: OrderKind::Sell, partially_fillable: false, sell_token_balance: SellTokenSource::Erc20, @@ -1424,13 +1422,13 @@ mod tests { sell_token: hex!("0101010101010101010101010101010101010101").into(), buy_token: hex!("0202020202020202020202020202020202020202").into(), receiver: Some(hex!("0303030303030303030303030303030303030303").into()), - sell_amount: alloy::primitives::U256::from(0x0246ddf97976680000_u128), - buy_amount: alloy::primitives::U256::from(0xb98bc829a6f90000_u128), + sell_amount: U256::from(0x0246ddf97976680000_u128), + buy_amount: U256::from(0xb98bc829a6f90000_u128), valid_to: 0xffffffff, app_data: AppDataHash(hex!( "0000000000000000000000000000000000000000000000000000000000000000" )), - fee_amount: alloy::primitives::U256::from(0x0de0b6b3a7640000_u128), + fee_amount: U256::from(0x0de0b6b3a7640000_u128), kind: OrderKind::Sell, partially_fillable: false, sell_token_balance: SellTokenSource::Erc20, @@ -1512,12 +1510,12 @@ mod tests { let order = OrderBuilder::default() .with_sell_token(Address::ZERO) - .with_sell_amount(alloy::primitives::U256::from(100)) + .with_sell_amount(U256::from(100)) .with_buy_token(Address::ZERO) - .with_buy_amount(alloy::primitives::U256::from(80)) + .with_buy_amount(U256::from(80)) .with_valid_to(u32::MAX) .with_app_data([1u8; 32]) - .with_fee_amount(alloy::primitives::U256::from(1337)) + .with_fee_amount(U256::from(1337)) .with_partially_fillable(true) .with_sell_token_balance(SellTokenSource::External) .with_buy_token_balance(BuyTokenDestination::Internal) diff --git a/crates/model/src/quote.rs b/crates/model/src/quote.rs index 7af5f4471c..9d5f83e946 100644 --- a/crates/model/src/quote.rs +++ b/crates/model/src/quote.rs @@ -4,7 +4,7 @@ use { signature::SigningScheme, time, }, - alloy::primitives::{Address, U256}, + alloy_primitives::{Address, U256}, anyhow::bail, app_data::AppDataHash, bigdecimal::BigDecimal, diff --git a/crates/model/src/signature.rs b/crates/model/src/signature.rs index 70da569597..b95db03916 100644 --- a/crates/model/src/signature.rs +++ b/crates/model/src/signature.rs @@ -1,9 +1,8 @@ use { crate::{DomainSeparator, quote::QuoteSigningScheme}, - alloy::{ - primitives::{Address, B256}, - signers::{SignerSync, local::PrivateKeySigner}, - }, + alloy_primitives::{Address, B256, keccak256}, + alloy_signer::SignerSync, + alloy_signer_local::PrivateKeySigner, anyhow::{Context as _, Result, ensure}, serde::{Deserialize, Serialize, de}, std::{ @@ -275,14 +274,14 @@ pub fn hashed_eip712_message(domain_separator: &DomainSeparator, struct_hash: &[ message[0..2].copy_from_slice(&[0x19, 0x01]); message[2..34].copy_from_slice(&domain_separator.0); message[34..66].copy_from_slice(struct_hash); - alloy::primitives::keccak256(message) + keccak256(message) } fn hashed_ethsign_message(domain_separator: &DomainSeparator, struct_hash: &[u8; 32]) -> B256 { let mut message = [0u8; 60]; message[..28].copy_from_slice(b"\x19Ethereum Signed Message:\n32"); message[28..].copy_from_slice(hashed_eip712_message(domain_separator, struct_hash).as_slice()); - alloy::primitives::keccak256(message) + keccak256(message) } /// Orders are always hashed into 32 bytes according to EIP-712. @@ -340,7 +339,7 @@ impl EcdsaSignature { struct_hash: &[u8; 32], ) -> Result