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 { let message = hashed_signing_message(signing_scheme, domain_separator, struct_hash); - let signature = alloy::primitives::Signature::from_raw(&self.to_bytes())?; + let signature = alloy_primitives::Signature::from_raw(&self.to_bytes())?; let signer = signature.recover_address_from_prehash(&message)?; Ok(Recovered { message, signer }) @@ -427,7 +426,7 @@ impl<'de> Deserialize<'de> for EcdsaSignature { #[cfg(test)] mod tests { - use {super::*, serde_json::json, testlib::assert_json_matches}; + use {super::*, alloy_primitives::U256, serde_json::json, testlib::assert_json_matches}; #[test] fn onchain_signatures_cannot_recover_owners() { @@ -634,7 +633,7 @@ mod tests { #[test] fn test_ecdsa_signature_recovery() { - let private_key = alloy::primitives::U256::from(1u64); + let private_key = U256::from(1u64); let signer = PrivateKeySigner::from_bytes(&private_key.to_be_bytes().into()).unwrap(); let signer_address = signer.address(); diff --git a/crates/model/src/solver_competition.rs b/crates/model/src/solver_competition.rs index e2532459a8..20b9dd934b 100644 --- a/crates/model/src/solver_competition.rs +++ b/crates/model/src/solver_competition.rs @@ -1,6 +1,6 @@ use { crate::{AuctionId, order::OrderUid}, - alloy::primitives::{Address, B256, U256}, + alloy_primitives::{Address, B256, U256}, number::serialization::HexOrDecimalU256, serde::{Deserialize, Serialize}, serde_with::serde_as, @@ -105,16 +105,16 @@ pub enum Order { id: OrderUid, /// The effective amount that left the user's wallet including all fees. #[serde_as(as = "HexOrDecimalU256")] - sell_amount: alloy::primitives::U256, + sell_amount: U256, /// The effective amount the user received after all fees. #[serde_as(as = "HexOrDecimalU256")] - buy_amount: alloy::primitives::U256, + buy_amount: U256, }, #[serde(rename_all = "camelCase")] Legacy { id: OrderUid, #[serde_as(as = "HexOrDecimalU256")] - executed_amount: alloy::primitives::U256, + executed_amount: U256, }, } diff --git a/crates/model/src/solver_competition_v2.rs b/crates/model/src/solver_competition_v2.rs index e9a0ff372a..f36447f506 100644 --- a/crates/model/src/solver_competition_v2.rs +++ b/crates/model/src/solver_competition_v2.rs @@ -1,6 +1,6 @@ use { crate::{AuctionId, order::OrderUid}, - alloy::primitives::{Address, B256, U256}, + alloy_primitives::{Address, B256, U256}, number::serialization::HexOrDecimalU256, serde::{Deserialize, Serialize}, serde_with::serde_as, diff --git a/crates/model/src/trade.rs b/crates/model/src/trade.rs index cba1d470a9..586c2afa74 100644 --- a/crates/model/src/trade.rs +++ b/crates/model/src/trade.rs @@ -3,7 +3,7 @@ use { crate::{fee_policy::ExecutedProtocolFee, order::OrderUid}, - alloy::primitives::{Address, B256}, + alloy_primitives::{Address, B256}, num::BigUint, serde::Serialize, serde_with::{DisplayFromStr, serde_as}, @@ -37,7 +37,7 @@ mod tests { use { super::*, crate::fee_policy::{FeePolicy, Quote}, - alloy::primitives::U256, + alloy_primitives::U256, serde_json::json, testlib::assert_json_matches, }; diff --git a/crates/number/Cargo.toml b/crates/number/Cargo.toml index cd89b4d159..1f2a11e921 100644 --- a/crates/number/Cargo.toml +++ b/crates/number/Cargo.toml @@ -6,13 +6,13 @@ edition = "2024" license = "MIT OR Apache-2.0" [dependencies] +alloy-primitives = { workspace = true, features = ["serde"] } anyhow = { workspace = true } -alloy = { workspace = true, features = ["serde"] } -ruint = { workspace = true, features = ["num-bigint"] } bigdecimal = { workspace = true } num = { workspace = true } -serde_with = { workspace = true } +ruint = { workspace = true, features = ["num-bigint"] } serde = { workspace = true } +serde_with = { workspace = true } [lints] workspace = true diff --git a/crates/number/src/conversions.rs b/crates/number/src/conversions.rs index 0cb508916e..efccde0a16 100644 --- a/crates/number/src/conversions.rs +++ b/crates/number/src/conversions.rs @@ -1,5 +1,5 @@ use { - alloy::primitives::{U256, aliases::I512}, + alloy_primitives::{U256, aliases::I512}, anyhow::{Result, ensure}, bigdecimal::{BigDecimal, num_bigint::ToBigInt}, num::{BigInt, BigRational, BigUint, Zero, bigint::Sign, rational::Ratio}, @@ -80,8 +80,8 @@ pub fn u256_to_big_decimal(u256: &U256) -> BigDecimal { pub fn i512_to_big_int(i512: &I512) -> BigInt { BigInt::from_bytes_be( match i512.sign() { - alloy::primitives::Sign::Positive => Sign::Plus, - alloy::primitives::Sign::Negative => Sign::Minus, + alloy_primitives::Sign::Positive => Sign::Plus, + alloy_primitives::Sign::Negative => Sign::Minus, }, &i512.abs().to_be_bytes::<64>(), ) @@ -95,7 +95,7 @@ pub fn i512_to_big_rational(input: &I512) -> BigRational { pub fn i512_to_u256(input: &I512) -> Result { anyhow::ensure!(input >= &I512::ZERO, "Negative input value"); anyhow::ensure!(input < &I512::from(U256::MAX), "Input exceeds U256::MAX"); - Ok(alloy::primitives::U256::from_be_slice( + Ok(alloy_primitives::U256::from_be_slice( &input.to_be_bytes::<64>()[32..], )) } diff --git a/crates/number/src/nonzero.rs b/crates/number/src/nonzero.rs index 92daf2b1d2..da0ce46f0b 100644 --- a/crates/number/src/nonzero.rs +++ b/crates/number/src/nonzero.rs @@ -1,5 +1,5 @@ use { - alloy::primitives::U256, + alloy_primitives::U256, anyhow::Context, serde::{Deserialize, Deserializer, Serialize, Serializer}, std::fmt::{self, Display, Formatter}, diff --git a/crates/number/src/ratio_ext.rs b/crates/number/src/ratio_ext.rs index d27c74ee9b..aa70c2faec 100644 --- a/crates/number/src/ratio_ext.rs +++ b/crates/number/src/ratio_ext.rs @@ -1,5 +1,5 @@ use { - alloy::primitives::{U256, U512, ruint::UintTryFrom}, + alloy_primitives::{U256, U512, ruint::UintTryFrom}, num::rational::Ratio, }; diff --git a/crates/number/src/serialization.rs b/crates/number/src/serialization.rs index 7e4cdb6aef..801e1e8ad0 100644 --- a/crates/number/src/serialization.rs +++ b/crates/number/src/serialization.rs @@ -1,5 +1,5 @@ use { - alloy::primitives::U256, + alloy_primitives::U256, serde::{Deserialize, Deserializer, Serializer}, serde_with::{DeserializeAs, SerializeAs}, }; @@ -22,7 +22,7 @@ impl SerializeAs for HexOrDecimalU256 { where S: Serializer, { - // alloy::primitives::U256 serializes as hex, this gives us decimals instead + // alloy_primitives::U256 serializes as hex, this gives us decimals instead serializer.serialize_str(&source.to_string()) } } diff --git a/crates/number/src/testing.rs b/crates/number/src/testing.rs index 49da2ffc37..17c71853ba 100644 --- a/crates/number/src/testing.rs +++ b/crates/number/src/testing.rs @@ -53,7 +53,7 @@ where #[cfg(test)] mod test { - use {super::*, alloy::primitives::U256}; + use {super::*, alloy_primitives::U256}; #[test] fn u64_identical_values() { diff --git a/crates/number/src/u256_ext.rs b/crates/number/src/u256_ext.rs index 7a9f87fe88..f54b072b7f 100644 --- a/crates/number/src/u256_ext.rs +++ b/crates/number/src/u256_ext.rs @@ -1,7 +1,7 @@ //! Extension trait for U256 arithmetic operations. use { - alloy::primitives::U256, + alloy_primitives::U256, num::{BigInt, BigRational, BigUint, One}, }; diff --git a/crates/number/src/units.rs b/crates/number/src/units.rs index fde77ce0d4..ed9e6c7a2f 100644 --- a/crates/number/src/units.rs +++ b/crates/number/src/units.rs @@ -1,4 +1,4 @@ -use alloy::primitives::{U256, utils::Unit}; +use alloy_primitives::{U256, utils::Unit}; pub trait EthUnit: std::marker::Sized { /// Converts this value to wei. diff --git a/crates/order-validation/Cargo.toml b/crates/order-validation/Cargo.toml index 88196cfdd0..1f6686b5d0 100644 --- a/crates/order-validation/Cargo.toml +++ b/crates/order-validation/Cargo.toml @@ -6,13 +6,13 @@ edition = "2024" license = "MIT OR Apache-2.0" [dependencies] -alloy = { workspace = true } +alloy-contract = { workspace = true } +alloy-primitives = { workspace = true } contracts = { workspace = true } +futures = { workspace = true } moka = { workspace = true, features = ["sync"] } -thiserror = { workspace = true } tokio = { workspace = true } tracing = { workspace = true } -futures = {workspace = true } [lints] workspace = true diff --git a/crates/order-validation/src/banned.rs b/crates/order-validation/src/banned.rs index f7c27eb8d7..d281b85206 100644 --- a/crates/order-validation/src/banned.rs +++ b/crates/order-validation/src/banned.rs @@ -5,7 +5,7 @@ //! expiry, LRU eviction) with background refresh every 60 seconds. use { - alloy::primitives::Address, + alloy_primitives::Address, contracts::alloy::ChainalysisOracle, futures::future::join_all, moka::sync::Cache, @@ -221,13 +221,7 @@ impl Users { } impl Onchain { - async fn fetch(&self, address: Address) -> Result { - Ok(self.contract.isSanctioned(address).call().await?) + async fn fetch(&self, address: Address) -> Result { + self.contract.isSanctioned(address).call().await } } - -#[derive(Debug, thiserror::Error)] -pub enum Error { - #[error("failed to fetch banned users from onchain")] - Onchain(#[from] alloy::contract::Error), -} diff --git a/crates/serde-ext/Cargo.toml b/crates/serde-ext/Cargo.toml index e45beaa60a..f3720ab8f5 100644 --- a/crates/serde-ext/Cargo.toml +++ b/crates/serde-ext/Cargo.toml @@ -6,7 +6,7 @@ edition = "2024" license = "MIT OR Apache-2.0" [dependencies] -alloy = { workspace = true } +alloy-primitives = { workspace = true } const-hex = { workspace = true } serde = { workspace = true } -serde_with = { workspace = true } \ No newline at end of file +serde_with = { workspace = true } diff --git a/crates/serde-ext/src/u256.rs b/crates/serde-ext/src/u256.rs index a0a5e0e9a0..68dc258054 100644 --- a/crates/serde-ext/src/u256.rs +++ b/crates/serde-ext/src/u256.rs @@ -1,5 +1,4 @@ use { - alloy::primitives as alloy, serde::{Deserializer, Serializer, de}, serde_with::{DeserializeAs, SerializeAs}, }; @@ -10,12 +9,14 @@ use { #[derive(Debug)] pub struct U256; -impl<'de> DeserializeAs<'de, alloy::U256> for U256 { - fn deserialize_as>(deserializer: D) -> Result { +impl<'de> DeserializeAs<'de, alloy_primitives::U256> for U256 { + fn deserialize_as>( + deserializer: D, + ) -> Result { struct Visitor; impl de::Visitor<'_> for Visitor { - type Value = alloy::U256; + type Value = alloy_primitives::U256; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { write!(formatter, "a 256-bit decimal string") @@ -25,7 +26,7 @@ impl<'de> DeserializeAs<'de, alloy::U256> for U256 { where E: de::Error, { - alloy::U256::from_str_radix(s, 10).map_err(|err| { + alloy_primitives::U256::from_str_radix(s, 10).map_err(|err| { de::Error::custom(format!("failed to decode {s:?} as a 256-bit number: {err}")) }) } @@ -35,8 +36,11 @@ impl<'de> DeserializeAs<'de, alloy::U256> for U256 { } } -impl SerializeAs for U256 { - fn serialize_as(source: &alloy::U256, serializer: S) -> Result { +impl SerializeAs for U256 { + fn serialize_as( + source: &alloy_primitives::U256, + serializer: S, + ) -> Result { serializer.serialize_str(&source.to_string()) } } diff --git a/crates/testlib/Cargo.toml b/crates/testlib/Cargo.toml index ce872726da..9962c65591 100644 --- a/crates/testlib/Cargo.toml +++ b/crates/testlib/Cargo.toml @@ -1,12 +1,15 @@ [package] name = "testlib" version = "0.1.0" -authors = ["Gnosis Developers ", "Cow Protocol Developers "] +authors = [ + "Gnosis Developers ", + "Cow Protocol Developers " +] edition = "2024" license = "MIT OR Apache-2.0" [dependencies] -alloy = {workspace = true} +alloy-primitives = { workspace = true } anyhow = { workspace = true } serde_json = { workspace = true } diff --git a/crates/testlib/src/protocol.rs b/crates/testlib/src/protocol.rs index 73b2f51cb1..75fc245fbb 100644 --- a/crates/testlib/src/protocol.rs +++ b/crates/testlib/src/protocol.rs @@ -1,6 +1,6 @@ //! Mainnet addresses of protocol contracts. -use alloy::primitives::{Address, address}; +use alloy_primitives::{Address, address}; /// Address for the settlement contract. pub const SETTLEMENT: Address = address!("9008D19f58AAbD9eD0D60971565AA8510560ab41"); diff --git a/crates/testlib/src/tokens.rs b/crates/testlib/src/tokens.rs index 51a5ed2410..bd7493e604 100644 --- a/crates/testlib/src/tokens.rs +++ b/crates/testlib/src/tokens.rs @@ -1,6 +1,6 @@ //! Mainnet addresses of commonly used tokens. -use alloy::primitives::{Address, address}; +use alloy_primitives::{Address, address}; /// Address for the `WETH` token. pub const WETH: Address = address!("c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"); diff --git a/crates/winner-selection/Cargo.toml b/crates/winner-selection/Cargo.toml index 3897310c3e..d8e3f9f559 100644 --- a/crates/winner-selection/Cargo.toml +++ b/crates/winner-selection/Cargo.toml @@ -4,9 +4,9 @@ version = "0.1.0" edition = "2024" [dependencies] -alloy = { workspace = true } -itertools = { workspace = true } +alloy-primitives = { workspace = true } anyhow = { workspace = true } +itertools = { workspace = true } +number = { workspace = true } thiserror = { workspace = true } tracing = { workspace = true } -number = { path = "../number" } diff --git a/crates/winner-selection/src/arbitrator.rs b/crates/winner-selection/src/arbitrator.rs index b15c4cdc3a..446df78572 100644 --- a/crates/winner-selection/src/arbitrator.rs +++ b/crates/winner-selection/src/arbitrator.rs @@ -11,7 +11,7 @@ use { solution::{Order, RankType, Ranked, Scored, Solution, Unscored}, state::{RankedItem, ScoredItem, UnscoredItem}, }, - alloy::primitives::{Address, U256}, + alloy_primitives::{Address, U256}, anyhow::{Context, Result}, itertools::{Either, Itertools}, number::u256_ext::U256Ext, @@ -248,7 +248,7 @@ impl Arbitrator { // to avoid loss of precision because we work with integers we first multiply // and then divide: // buy_amount = surplus * buy_price / sell_price - use alloy::primitives::{U512, ruint::UintTryFrom}; + use alloy_primitives::{U512, ruint::UintTryFrom}; let surplus_in_buy_tokens = surplus_in_surplus_token .widening_mul(order.buy_amount) diff --git a/crates/winner-selection/src/auction.rs b/crates/winner-selection/src/auction.rs index 926c4a5476..d60ad9c6d3 100644 --- a/crates/winner-selection/src/auction.rs +++ b/crates/winner-selection/src/auction.rs @@ -6,7 +6,7 @@ use { crate::primitives::{FeePolicy, OrderUid}, - alloy::primitives::{Address, U256}, + alloy_primitives::{Address, U256}, std::collections::{HashMap, HashSet}, }; diff --git a/crates/winner-selection/src/primitives.rs b/crates/winner-selection/src/primitives.rs index 59a23a12a3..c7aa78ef25 100644 --- a/crates/winner-selection/src/primitives.rs +++ b/crates/winner-selection/src/primitives.rs @@ -1,6 +1,6 @@ //! Primitive types for winner selection. -pub use alloy::primitives::{Address, U256}; +pub use alloy_primitives::{Address, U256}; /// Native token constant. pub const NATIVE_TOKEN: Address = Address::repeat_byte(0xee); diff --git a/crates/winner-selection/src/solution.rs b/crates/winner-selection/src/solution.rs index ecf5bb6638..4996335d86 100644 --- a/crates/winner-selection/src/solution.rs +++ b/crates/winner-selection/src/solution.rs @@ -9,7 +9,7 @@ use { primitives::{OrderUid, Side}, state, }, - alloy::primitives::{Address, U256}, + alloy_primitives::{Address, U256}, std::collections::HashMap, }; pub type Scored = state::Scored;