From 0ffe4fc6c337fd4799dde6c7f097f68158ad1c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Duarte?= Date: Fri, 28 Nov 2025 16:33:24 +0000 Subject: [PATCH 1/6] Remove eth::Address in favor of alloy::primitives::Address --- crates/autopilot/src/boundary/order.rs | 8 ++--- crates/autopilot/src/database/competition.rs | 8 ++--- crates/autopilot/src/domain/auction/mod.rs | 5 ++-- crates/autopilot/src/domain/auction/order.rs | 9 +++--- .../autopilot/src/domain/competition/mod.rs | 7 +++-- .../participation_guard/onchain.rs | 9 ++---- .../domain/competition/winner_selection.rs | 7 +++-- crates/autopilot/src/domain/eth/mod.rs | 7 +---- crates/autopilot/src/domain/fee/mod.rs | 2 +- crates/autopilot/src/domain/settlement/mod.rs | 30 +++++++------------ .../src/domain/settlement/observer.rs | 9 +----- .../src/domain/settlement/transaction/mod.rs | 4 +-- crates/autopilot/src/infra/blockchain/mod.rs | 15 ++++++---- .../src/infra/persistence/dto/auction.rs | 4 +-- .../src/infra/persistence/dto/order.rs | 8 ++--- crates/autopilot/src/infra/persistence/mod.rs | 2 +- .../autopilot/src/infra/solvers/dto/solve.rs | 6 ++-- crates/autopilot/src/infra/solvers/mod.rs | 2 +- crates/autopilot/src/run_loop.rs | 4 +-- crates/autopilot/src/solvable_orders.rs | 2 +- 20 files changed, 65 insertions(+), 83 deletions(-) diff --git a/crates/autopilot/src/boundary/order.rs b/crates/autopilot/src/boundary/order.rs index 31cb5b5a15..906e211074 100644 --- a/crates/autopilot/src/boundary/order.rs +++ b/crates/autopilot/src/boundary/order.rs @@ -26,12 +26,8 @@ pub fn to_domain( created: u32::try_from(order.metadata.creation_date.timestamp()).unwrap_or(u32::MIN), valid_to: order.data.valid_to, side: order.data.kind.into(), - receiver: order - .data - .receiver - .map(IntoLegacy::into_legacy) - .map(Into::into), - owner: order.metadata.owner.into_legacy().into(), + receiver: order.data.receiver, + owner: order.metadata.owner, partially_fillable: order.data.partially_fillable, executed: remaining_order.executed_amount.into(), pre_interactions: if order_is_untouched { diff --git a/crates/autopilot/src/database/competition.rs b/crates/autopilot/src/database/competition.rs index 84e19ebb6e..0ce7909abd 100644 --- a/crates/autopilot/src/database/competition.rs +++ b/crates/autopilot/src/database/competition.rs @@ -1,8 +1,8 @@ use { - crate::domain::{competition::Score, eth}, + crate::domain::competition::Score, + alloy::primitives::Address, anyhow::Context, database::{ - Address, auction::AuctionId, auction_prices::AuctionPrice, byte_array::ByteArray, @@ -18,7 +18,7 @@ use { #[derive(Clone, Default, Debug)] pub struct Competition { pub auction_id: AuctionId, - pub reference_scores: HashMap, + pub reference_scores: HashMap, /// Addresses to which the CIP20 participation rewards will be payed out. /// Usually the same as the solver addresses. pub participants: HashSet, @@ -91,7 +91,7 @@ impl super::Postgres { pub async fn save_surplus_capturing_jit_order_owners( &self, auction_id: AuctionId, - surplus_capturing_jit_order_owners: &[Address], + surplus_capturing_jit_order_owners: &[database::Address], ) -> anyhow::Result<()> { let mut ex = self.pool.acquire().await.context("acquire")?; diff --git a/crates/autopilot/src/domain/auction/mod.rs b/crates/autopilot/src/domain/auction/mod.rs index 4eb623df8c..6e5b6c554a 100644 --- a/crates/autopilot/src/domain/auction/mod.rs +++ b/crates/autopilot/src/domain/auction/mod.rs @@ -1,4 +1,5 @@ use { + alloy::primitives::Address, super::{Order, eth}, std::collections::HashMap, }; @@ -15,7 +16,7 @@ pub struct RawAuctionData { pub block: u64, pub orders: Vec, pub prices: Prices, - pub surplus_capturing_jit_order_owners: Vec, + pub surplus_capturing_jit_order_owners: Vec
, } pub type Id = i64; @@ -26,7 +27,7 @@ pub struct Auction { pub block: u64, pub orders: Vec, pub prices: Prices, - pub surplus_capturing_jit_order_owners: Vec, + pub surplus_capturing_jit_order_owners: Vec
, } impl PartialEq for Auction { diff --git a/crates/autopilot/src/domain/auction/order.rs b/crates/autopilot/src/domain/auction/order.rs index 24434c687e..f26c43447c 100644 --- a/crates/autopilot/src/domain/auction/order.rs +++ b/crates/autopilot/src/domain/auction/order.rs @@ -1,4 +1,5 @@ use { + alloy::primitives::Address, crate::{ domain, domain::{eth, fee}, @@ -16,8 +17,8 @@ pub struct Order { pub side: Side, pub created: u32, pub valid_to: u32, - pub receiver: Option, - pub owner: eth::Address, + pub receiver: Option
, + pub owner: Address, pub partially_fillable: bool, pub executed: TargetAmount, // Partially fillable orders should have their pre-interactions only executed @@ -36,8 +37,8 @@ pub struct Order { pub struct OrderUid(pub [u8; 56]); impl OrderUid { - pub fn owner(&self) -> eth::Address { - self.parts().1.into() + pub fn owner(&self) -> Address { + Address::from(self.parts().1 .0) } /// Splits an order UID into its parts. diff --git a/crates/autopilot/src/domain/competition/mod.rs b/crates/autopilot/src/domain/competition/mod.rs index bfdc8de5e5..01f4d28e71 100644 --- a/crates/autopilot/src/domain/competition/mod.rs +++ b/crates/autopilot/src/domain/competition/mod.rs @@ -1,4 +1,5 @@ use { + alloy::primitives::Address, super::auction::order, crate::domain::{self, auction, eth}, derive_more::Display, @@ -21,7 +22,7 @@ type SolutionId = u64; pub struct Solution { /// A solution ID provided by the solver. id: SolutionId, - solver: eth::Address, + solver: Address, /// Score reported by the solver in their response. score: Score, orders: HashMap, @@ -35,7 +36,7 @@ pub struct Solution { impl Solution { pub fn new( id: SolutionId, - solver: eth::Address, + solver: Address, score: Score, orders: HashMap, prices: auction::Prices, @@ -54,7 +55,7 @@ impl Solution { self.id } - pub fn solver(&self) -> eth::Address { + pub fn solver(&self) -> Address { self.solver } diff --git a/crates/autopilot/src/domain/competition/participation_guard/onchain.rs b/crates/autopilot/src/domain/competition/participation_guard/onchain.rs index bcdd7140db..3e42885353 100644 --- a/crates/autopilot/src/domain/competition/participation_guard/onchain.rs +++ b/crates/autopilot/src/domain/competition/participation_guard/onchain.rs @@ -1,7 +1,4 @@ -use { - crate::{domain::eth, infra}, - ethrpc::alloy::conversions::IntoAlloy, -}; +use {crate::infra, alloy::primitives::Address}; /// Calls Authenticator contract to check if a solver has a sufficient /// permission. @@ -11,12 +8,12 @@ pub(super) struct Validator { #[async_trait::async_trait] impl super::SolverValidator for Validator { - async fn is_allowed(&self, solver: ð::Address) -> anyhow::Result { + async fn is_allowed(&self, solver: &Address) -> anyhow::Result { Ok(self .eth .contracts() .authenticator() - .isSolver(solver.0.into_alloy()) + .isSolver(*solver) .call() .await?) } diff --git a/crates/autopilot/src/domain/competition/winner_selection.rs b/crates/autopilot/src/domain/competition/winner_selection.rs index ce6f796285..85bab42770 100644 --- a/crates/autopilot/src/domain/competition/winner_selection.rs +++ b/crates/autopilot/src/domain/competition/winner_selection.rs @@ -477,6 +477,7 @@ mod tests { infra::Driver, }, ethcontract::H160, + ethrpc::alloy::conversions::IntoAlloy, hex_literal::hex, number::serialization::HexOrDecimalU256, serde::Deserialize, @@ -1226,7 +1227,7 @@ mod tests { let reference_scores = arbitrator.compute_reference_scores(&ranking); assert_eq!(reference_scores.len(), self.expected_reference_scores.len()); for (solver_id, expected_score) in &self.expected_reference_scores { - let solver_address: eth::Address = (*solver_map.get(solver_id).unwrap()).into(); + let solver_address = solver_map.get(solver_id).unwrap().into_alloy(); let score = reference_scores.get(&solver_address).unwrap(); assert_eq!(score.0, eth::Ether(*expected_score)) } @@ -1387,7 +1388,7 @@ mod tests { }); let trade_order_map: HashMap = trades.into_iter().collect(); - let solver_address = eth::Address(solver_address); + let solver_address = eth::Address::from(solver_address.0); let solution = Solution::new( solution_id, @@ -1402,7 +1403,7 @@ mod tests { url::Url::parse("http://localhost").unwrap(), solver_address.to_string(), None, - crate::arguments::Account::Address(solver_address.0), + crate::arguments::Account::Address(eth::H160(solver_address.0.0)), false, ) .await diff --git a/crates/autopilot/src/domain/eth/mod.rs b/crates/autopilot/src/domain/eth/mod.rs index c0e773a4c5..e5d9a6c2d4 100644 --- a/crates/autopilot/src/domain/eth/mod.rs +++ b/crates/autopilot/src/domain/eth/mod.rs @@ -1,3 +1,4 @@ +pub use alloy::primitives::Address; pub use primitive_types::{H160, H256, U256}; use { crate::{domain, util::conv::U256Ext}, @@ -11,12 +12,6 @@ use { /// Same address is also used for XDAI on Gnosis Chain. pub const NATIVE_TOKEN: TokenAddress = TokenAddress(H160([0xee; 20])); -/// An address. Can be an EOA or a smart contract address. -#[derive( - Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, From, Into, Display, -)] -pub struct Address(pub H160); - /// Block number. #[derive(Debug, Copy, Clone, From, PartialEq, PartialOrd, Default)] pub struct BlockNo(pub u64); diff --git a/crates/autopilot/src/domain/fee/mod.rs b/crates/autopilot/src/domain/fee/mod.rs index cc7bf5e06a..77f6c48d56 100644 --- a/crates/autopilot/src/domain/fee/mod.rs +++ b/crates/autopilot/src/domain/fee/mod.rs @@ -240,7 +240,7 @@ impl ProtocolFees { let partner_fee = Self::get_partner_fee(&order, &reference_quote, self.max_partner_fee.into()); - if surplus_capturing_jit_order_owners.contains(&order.metadata.owner.into_legacy().into()) { + if surplus_capturing_jit_order_owners.contains(&order.metadata.owner) { return boundary::order::to_domain(order, partner_fee, quote); } diff --git a/crates/autopilot/src/domain/settlement/mod.rs b/crates/autopilot/src/domain/settlement/mod.rs index ea01d27e12..f0976949c0 100644 --- a/crates/autopilot/src/domain/settlement/mod.rs +++ b/crates/autopilot/src/domain/settlement/mod.rs @@ -354,6 +354,7 @@ mod tests { eth, settlement::{OrderMatchKey, trade_to_key}, }, + alloy::primitives::address, ethcontract::BlockId, hex_literal::hex, std::collections::{HashMap, HashSet}, @@ -584,9 +585,7 @@ mod tests { let domain_separator = eth::DomainSeparator(hex!( "c078f884a2676e1345748b1feace7b0abee5d00ecadb6e574dcdd109a63e8943" )); - let settlement_contract = eth::Address(eth::H160::from_slice(&hex!( - "9008d19f58aabd9ed0d60971565aa8510560ab41" - ))); + let settlement_contract = address!("9008d19f58aabd9ed0d60971565aa8510560ab41"); let transaction = super::transaction::Transaction::try_new( &domain::eth::Transaction { @@ -694,9 +693,7 @@ mod tests { let domain_separator = eth::DomainSeparator(hex!( "c078f884a2676e1345748b1feace7b0abee5d00ecadb6e574dcdd109a63e8943" )); - let settlement_contract = eth::Address(eth::H160::from_slice(&hex!( - "9008d19f58aabd9ed0d60971565aa8510560ab41" - ))); + let settlement_contract = address!("9008d19f58aabd9ed0d60971565aa8510560ab41"); let transaction = super::transaction::Transaction::try_new( &domain::eth::Transaction { trace_calls: domain::eth::CallFrame { @@ -840,9 +837,7 @@ mod tests { let domain_separator = eth::DomainSeparator(hex!( "c078f884a2676e1345748b1feace7b0abee5d00ecadb6e574dcdd109a63e8943" )); - let settlement_contract = eth::Address(eth::H160::from_slice(&hex!( - "9008d19f58aabd9ed0d60971565aa8510560ab41" - ))); + let settlement_contract = address!("9008d19f58aabd9ed0d60971565aa8510560ab41"); let transaction = super::transaction::Transaction::try_new( &domain::eth::Transaction { trace_calls: domain::eth::CallFrame { @@ -1018,9 +1013,8 @@ mod tests { let domain_separator = eth::DomainSeparator(hex!( "c078f884a2676e1345748b1feace7b0abee5d00ecadb6e574dcdd109a63e8943" )); - let settlement_contract = eth::Address(eth::H160::from_slice(&hex!( - "9008d19f58aabd9ed0d60971565aa8510560ab41" - ))); + let settlement_contract = + eth::Address::from_slice(&hex!("9008d19f58aabd9ed0d60971565aa8510560ab41")); let transaction = super::transaction::Transaction::try_new( &domain::eth::Transaction { trace_calls: domain::eth::CallFrame { @@ -1056,8 +1050,8 @@ mod tests { let auction = super::Auction { block: eth::BlockNo(0), prices, - surplus_capturing_jit_order_owners: HashSet::from([eth::Address( - eth::H160::from_slice(&hex!("f08d4dea369c456d26a3168ff0024b904f2d8b91")), + surplus_capturing_jit_order_owners: HashSet::from([address!( + "f08d4dea369c456d26a3168ff0024b904f2d8b91" )]), id: 0, orders: Default::default(), @@ -1202,9 +1196,7 @@ mod tests { let domain_separator = eth::DomainSeparator(hex!( "c078f884a2676e1345748b1feace7b0abee5d00ecadb6e574dcdd109a63e8943" )); - let settlement_contract = eth::Address(eth::H160::from_slice(&hex!( - "9008d19f58aabd9ed0d60971565aa8510560ab41" - ))); + let settlement_contract = address!("9008d19f58aabd9ed0d60971565aa8510560ab41"); let transaction = super::transaction::Transaction::try_new( &domain::eth::Transaction { trace_calls: domain::eth::CallFrame { @@ -1429,9 +1421,7 @@ mod tests { let domain_separator = eth::DomainSeparator(hex!( "8f05589c4b810bc2f706854508d66d447cd971f8354a4bb0b3471ceb0a466bc7" )); - let settlement_contract = eth::Address(eth::H160::from_slice(&hex!( - "9008d19f58aabd9ed0d60971565aa8510560ab41" - ))); + let settlement_contract = address!("9008d19f58aabd9ed0d60971565aa8510560ab41"); let transaction = super::transaction::Transaction::try_new( &domain::eth::Transaction { trace_calls: domain::eth::CallFrame { diff --git a/crates/autopilot/src/domain/settlement/observer.rs b/crates/autopilot/src/domain/settlement/observer.rs index 438208f49c..a58a42ad2c 100644 --- a/crates/autopilot/src/domain/settlement/observer.rs +++ b/crates/autopilot/src/domain/settlement/observer.rs @@ -19,7 +19,6 @@ use { infra, }, anyhow::{Context, Result, anyhow}, - ethrpc::alloy::conversions::IntoLegacy, futures::StreamExt, rand::Rng, std::time::Duration, @@ -105,13 +104,7 @@ impl Observer { let transaction = match self.eth.transaction(tx).await { Ok(transaction) => { let separator = self.eth.contracts().settlement_domain_separator(); - let settlement_contract = self - .eth - .contracts() - .settlement() - .address() - .into_legacy() - .into(); + let settlement_contract = *self.eth.contracts().settlement().address(); settlement::Transaction::try_new( &transaction, separator, diff --git a/crates/autopilot/src/domain/settlement/transaction/mod.rs b/crates/autopilot/src/domain/settlement/transaction/mod.rs index c1a673c4b4..0704adaaaf 100644 --- a/crates/autopilot/src/domain/settlement/transaction/mod.rs +++ b/crates/autopilot/src/domain/settlement/transaction/mod.rs @@ -37,7 +37,7 @@ impl Authenticator for GPv2AllowListAuthentication::Instance { // find an eligible caller in the callstack. To avoid this case the // underlying call needs to happen on the same block the transaction happened. Ok(self - .isSolver(prospective_solver.0.into_alloy()) + .isSolver(prospective_solver) .block(block.into_alloy()) .call() .await @@ -146,7 +146,7 @@ impl Transaction { amount: trade.buyAmount.into_legacy().into(), }, side: flags.side(), - receiver: trade.receiver.into_legacy().into(), + receiver: eth::Address::from(trade.receiver.into_legacy().0), valid_to: trade.validTo, app_data: domain::auction::order::AppDataHash(trade.appData.into()), fee_amount: trade.feeAmount.into_legacy().into(), diff --git a/crates/autopilot/src/infra/blockchain/mod.rs b/crates/autopilot/src/infra/blockchain/mod.rs index c0c1275f62..17a195d916 100644 --- a/crates/autopilot/src/infra/blockchain/mod.rs +++ b/crates/autopilot/src/infra/blockchain/mod.rs @@ -3,7 +3,12 @@ use { crate::{boundary, domain::eth}, alloy::providers::Provider, chain::Chain, - ethrpc::{Web3, block_stream::CurrentBlockWatcher, extensions::DebugNamespace}, + ethrpc::{ + Web3, + alloy::conversions::IntoAlloy, + block_stream::CurrentBlockWatcher, + extensions::DebugNamespace, + }, primitive_types::U256, thiserror::Error, url::Url, @@ -142,8 +147,8 @@ fn into_domain( hash: transaction.hash.into(), from: transaction .from - .ok_or(anyhow::anyhow!("missing from"))? - .into(), + .map(IntoAlloy::into_alloy) + .ok_or(anyhow::anyhow!("missing from"))?, block: receipt .block_number .ok_or(anyhow::anyhow!("missing block_number"))? @@ -165,8 +170,8 @@ fn into_domain( impl From for eth::CallFrame { fn from(frame: ethrpc::extensions::CallFrame) -> Self { eth::CallFrame { - from: frame.from.into(), - to: frame.to.map(Into::into), + from: eth::Address::from(frame.from.0), + to: frame.to.map(|h160| eth::Address::from(h160.0)), input: frame.input.0.into(), calls: frame.calls.into_iter().map(Into::into).collect(), } diff --git a/crates/autopilot/src/infra/persistence/dto/auction.rs b/crates/autopilot/src/infra/persistence/dto/auction.rs index 6dfa8a4fc6..0872c4b5df 100644 --- a/crates/autopilot/src/infra/persistence/dto/auction.rs +++ b/crates/autopilot/src/infra/persistence/dto/auction.rs @@ -27,7 +27,7 @@ pub fn from_domain(auction: domain::RawAuctionData) -> RawAuctionData { surplus_capturing_jit_order_owners: auction .surplus_capturing_jit_order_owners .into_iter() - .map(Into::into) + .map(|addr| eth::H160(addr.0 .0)) .collect(), } } @@ -78,7 +78,7 @@ impl Auction { .auction .surplus_capturing_jit_order_owners .into_iter() - .map(Into::into) + .map(|h160| eth::Address::from(h160.0)) .collect(), }) } diff --git a/crates/autopilot/src/infra/persistence/dto/order.rs b/crates/autopilot/src/infra/persistence/dto/order.rs index 0f3c1745a6..9b5ec79edd 100644 --- a/crates/autopilot/src/infra/persistence/dto/order.rs +++ b/crates/autopilot/src/infra/persistence/dto/order.rs @@ -59,8 +59,8 @@ pub fn from_domain(order: domain::Order) -> Order { created: order.created, valid_to: order.valid_to, kind: order.side.into(), - receiver: order.receiver.map(Into::into), - owner: order.owner.into(), + receiver: order.receiver.map(IntoLegacy::into_legacy), + owner: order.owner.into_legacy(), partially_fillable: order.partially_fillable, executed: order.executed.into(), pre_interactions: order.pre_interactions.into_iter().map(Into::into).collect(), @@ -97,8 +97,8 @@ pub fn to_domain(order: Order) -> domain::Order { created: order.created, valid_to: order.valid_to, side: order.kind.into(), - receiver: order.receiver.map(Into::into), - owner: order.owner.into(), + receiver: order.receiver.map(|h160| eth::Address::from(h160.0)), + owner: eth::Address::from(order.owner.0), partially_fillable: order.partially_fillable, executed: order.executed.into(), pre_interactions: order.pre_interactions.into_iter().map(Into::into).collect(), diff --git a/crates/autopilot/src/infra/persistence/mod.rs b/crates/autopilot/src/infra/persistence/mod.rs index 4153b2029c..83e81387be 100644 --- a/crates/autopilot/src/infra/persistence/mod.rs +++ b/crates/autopilot/src/infra/persistence/mod.rs @@ -377,7 +377,7 @@ impl Persistence { .map_err(error::Auction::DatabaseError)? .ok_or(error::Auction::NotFound)? .into_iter() - .map(|owner| eth::H160(owner.0).into()) + .map(|owner| eth::Address::from(owner.0)) .collect(); let prices = database::auction_prices::fetch(&mut ex, auction_id) diff --git a/crates/autopilot/src/infra/solvers/dto/solve.rs b/crates/autopilot/src/infra/solvers/dto/solve.rs index 06e0fb549d..330bf6150a 100644 --- a/crates/autopilot/src/infra/solvers/dto/solve.rs +++ b/crates/autopilot/src/infra/solvers/dto/solve.rs @@ -5,6 +5,7 @@ use { infra::persistence::dto::{self, order::Order}, }, chrono::{DateTime, Utc}, + ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy}, itertools::Itertools, number::serialization::HexOrDecimalU256, primitive_types::{H160, U256}, @@ -65,7 +66,8 @@ impl Request { surplus_capturing_jit_order_owners: auction .surplus_capturing_jit_order_owners .iter() - .map(|address| address.0) + .copied() + .map(IntoLegacy::into_legacy) .collect::>(), }; Self(Arc::from(serde_json::value::to_raw_value(&helper).expect( @@ -113,7 +115,7 @@ impl Solution { ) -> Result { Ok(domain::competition::Solution::new( self.solution_id, - self.submission_address.into(), + self.submission_address.into_alloy(), domain::competition::Score::try_new(self.score.into())?, self.orders .into_iter() diff --git a/crates/autopilot/src/infra/solvers/mod.rs b/crates/autopilot/src/infra/solvers/mod.rs index 7cbc99e755..2d74ffba33 100644 --- a/crates/autopilot/src/infra/solvers/mod.rs +++ b/crates/autopilot/src/infra/solvers/mod.rs @@ -75,7 +75,7 @@ impl Driver { .timeout(RESPONSE_TIME_LIMIT) .build() .map_err(Error::FailedToBuildClient)?, - submission_address: submission_address.into(), + submission_address: eth::Address::from(submission_address.0), requested_timeout_on_problems, }) } diff --git a/crates/autopilot/src/run_loop.rs b/crates/autopilot/src/run_loop.rs index 2a1232cb1d..8d964b3e1b 100644 --- a/crates/autopilot/src/run_loop.rs +++ b/crates/autopilot/src/run_loop.rs @@ -440,7 +440,7 @@ impl RunLoop { let participants = ranking .all() - .map(|participant| participant.solution().solver().into()) + .map(|participant| participant.solution().solver().into_legacy()) .collect::>(); let order_lookup: std::collections::HashMap<_, _> = auction .orders @@ -467,7 +467,7 @@ impl RunLoop { .enumerated() .map(|(index, participant)| SolverSettlement { solver: participant.driver().name.clone(), - solver_address: participant.solution().solver().0.into_alloy(), + solver_address: participant.solution().solver(), score: Some(Score::Solver( participant.solution().score().get().0.into_alloy(), )), diff --git a/crates/autopilot/src/solvable_orders.rs b/crates/autopilot/src/solvable_orders.rs index 2710551d1a..84995a913b 100644 --- a/crates/autopilot/src/solvable_orders.rs +++ b/crates/autopilot/src/solvable_orders.rs @@ -292,7 +292,7 @@ impl SolvableOrdersCache { price_exist }) }) - .map(|cow_amm| eth::Address::from(cow_amm.address().into_legacy())) + .map(|cow_amm| *cow_amm.address()) .collect::>(); let auction = domain::RawAuctionData { block, From f909260d128bae89c945163e856e45d801a308dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Duarte?= Date: Fri, 28 Nov 2025 16:46:25 +0000 Subject: [PATCH 2/6] Fmt --- crates/autopilot/src/domain/auction/mod.rs | 2 +- crates/autopilot/src/domain/auction/order.rs | 4 ++-- crates/autopilot/src/domain/competition/mod.rs | 2 +- crates/autopilot/src/domain/eth/mod.rs | 6 ++++-- crates/autopilot/src/infra/persistence/dto/auction.rs | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/autopilot/src/domain/auction/mod.rs b/crates/autopilot/src/domain/auction/mod.rs index 6e5b6c554a..fb6fdb8e62 100644 --- a/crates/autopilot/src/domain/auction/mod.rs +++ b/crates/autopilot/src/domain/auction/mod.rs @@ -1,6 +1,6 @@ use { - alloy::primitives::Address, super::{Order, eth}, + alloy::primitives::Address, std::collections::HashMap, }; diff --git a/crates/autopilot/src/domain/auction/order.rs b/crates/autopilot/src/domain/auction/order.rs index f26c43447c..8d6366e164 100644 --- a/crates/autopilot/src/domain/auction/order.rs +++ b/crates/autopilot/src/domain/auction/order.rs @@ -1,9 +1,9 @@ use { - alloy::primitives::Address, crate::{ domain, domain::{eth, fee}, }, + alloy::primitives::Address, primitive_types::{H160, H256, U256}, std::fmt::{self, Debug, Display, Formatter}, }; @@ -38,7 +38,7 @@ pub struct OrderUid(pub [u8; 56]); impl OrderUid { pub fn owner(&self) -> Address { - Address::from(self.parts().1 .0) + Address::from(self.parts().1.0) } /// Splits an order UID into its parts. diff --git a/crates/autopilot/src/domain/competition/mod.rs b/crates/autopilot/src/domain/competition/mod.rs index 01f4d28e71..0e368e1ad2 100644 --- a/crates/autopilot/src/domain/competition/mod.rs +++ b/crates/autopilot/src/domain/competition/mod.rs @@ -1,7 +1,7 @@ use { - alloy::primitives::Address, super::auction::order, crate::domain::{self, auction, eth}, + alloy::primitives::Address, derive_more::Display, num::Saturating, std::collections::HashMap, diff --git a/crates/autopilot/src/domain/eth/mod.rs b/crates/autopilot/src/domain/eth/mod.rs index e5d9a6c2d4..3bc638c20b 100644 --- a/crates/autopilot/src/domain/eth/mod.rs +++ b/crates/autopilot/src/domain/eth/mod.rs @@ -1,9 +1,11 @@ -pub use alloy::primitives::Address; -pub use primitive_types::{H160, H256, U256}; use { crate::{domain, util::conv::U256Ext}, derive_more::{Display, From, Into}, }; +pub use { + alloy::primitives::Address, + primitive_types::{H160, H256, U256}, +}; /// ERC20 token address for ETH. In reality, ETH is not an ERC20 token because /// it does not implement the ERC20 interface, but this address is used by diff --git a/crates/autopilot/src/infra/persistence/dto/auction.rs b/crates/autopilot/src/infra/persistence/dto/auction.rs index 0872c4b5df..86bb297165 100644 --- a/crates/autopilot/src/infra/persistence/dto/auction.rs +++ b/crates/autopilot/src/infra/persistence/dto/auction.rs @@ -27,7 +27,7 @@ pub fn from_domain(auction: domain::RawAuctionData) -> RawAuctionData { surplus_capturing_jit_order_owners: auction .surplus_capturing_jit_order_owners .into_iter() - .map(|addr| eth::H160(addr.0 .0)) + .map(|addr| eth::H160(addr.0.0)) .collect(), } } From 5684eba22041d12ce8bc1c8f544e49e590d05c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Duarte?= Date: Fri, 28 Nov 2025 17:40:33 +0000 Subject: [PATCH 3/6] Migrate EcdsaSignature internal types to alloy --- .../src/infra/persistence/dto/order.rs | 8 ++--- crates/e2e/src/api/zeroex.rs | 6 ++-- .../e2e/src/setup/onchain_components/safe.rs | 4 +-- crates/model/src/order.rs | 5 ++- crates/model/src/signature.rs | 31 ++++++++++--------- crates/orderbook/src/api/cancel_order.rs | 6 ++-- crates/shared/src/encoded_settlement.rs | 6 ++-- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/crates/autopilot/src/infra/persistence/dto/order.rs b/crates/autopilot/src/infra/persistence/dto/order.rs index 9b5ec79edd..88fd4662c3 100644 --- a/crates/autopilot/src/infra/persistence/dto/order.rs +++ b/crates/autopilot/src/infra/persistence/dto/order.rs @@ -240,8 +240,8 @@ impl From for domain::auction::order::Signature { impl From for boundary::EcdsaSignature { fn from(signature: domain::auction::order::EcdsaSignature) -> Self { Self { - r: signature.r, - s: signature.s, + r: signature.r.0.into(), + s: signature.s.0.into(), v: signature.v, } } @@ -250,8 +250,8 @@ impl From for boundary::EcdsaSignature { impl From for domain::auction::order::EcdsaSignature { fn from(signature: boundary::EcdsaSignature) -> Self { Self { - r: signature.r, - s: signature.s, + r: signature.r.0.into(), + s: signature.s.0.into(), v: signature.v, } } diff --git a/crates/e2e/src/api/zeroex.rs b/crates/e2e/src/api/zeroex.rs index 1aed1feb54..176f935ad7 100644 --- a/crates/e2e/src/api/zeroex.rs +++ b/crates/e2e/src/api/zeroex.rs @@ -2,7 +2,7 @@ use { crate::setup::TestAccount, alloy::primitives::{Address, B256, U256}, chrono::{DateTime, NaiveDateTime, Utc}, - ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy}, + ethrpc::alloy::conversions::IntoLegacy, hex_literal::hex, model::DomainSeparator, shared::zeroex_api::{self, Order, OrderMetadata, OrderRecord, ZeroExSignature}, @@ -114,8 +114,8 @@ impl Eip712TypedZeroExOrder { ) -> ZeroExSignature { let signature = signer.sign_typed_data(domain_separator, &hash); ZeroExSignature { - r: signature.r.into_alloy(), - s: signature.s.into_alloy(), + r: signature.r, + s: signature.s, v: signature.v, // See signature_type: 2, diff --git a/crates/e2e/src/setup/onchain_components/safe.rs b/crates/e2e/src/setup/onchain_components/safe.rs index bc063965fd..954e8c944d 100644 --- a/crates/e2e/src/setup/onchain_components/safe.rs +++ b/crates/e2e/src/setup/onchain_components/safe.rs @@ -275,8 +275,8 @@ impl Safe { // Signature format specified here: // [ - signature.r.as_bytes(), - signature.s.as_bytes(), + signature.r.as_slice(), + signature.s.as_slice(), &[signature.v], ] .concat() diff --git a/crates/model/src/order.rs b/crates/model/src/order.rs index 3f20e87896..e552a3f9b6 100644 --- a/crates/model/src/order.rs +++ b/crates/model/src/order.rs @@ -1075,7 +1075,6 @@ mod tests { chrono::TimeZone, hex_literal::hex, maplit::hashset, - primitive_types::H256, secp256k1::{PublicKey, Secp256k1, SecretKey}, serde_json::json, testlib::assert_json_matches, @@ -1159,11 +1158,11 @@ mod tests { }, signature: EcdsaSignature { v: 1, - r: H256::from_str( + r: B256::from_str( "0200000000000000000000000000000000000000000000000000000000000003", ) .unwrap(), - s: H256::from_str( + s: B256::from_str( "0400000000000000000000000000000000000000000000000000000000000005", ) .unwrap(), diff --git a/crates/model/src/signature.rs b/crates/model/src/signature.rs index 7b8a875e42..f7243a6632 100644 --- a/crates/model/src/signature.rs +++ b/crates/model/src/signature.rs @@ -1,5 +1,6 @@ use { crate::{DomainSeparator, quote::QuoteSigningScheme}, + alloy::primitives::B256, anyhow::{Context as _, Result, ensure}, primitive_types::{H160, H256}, serde::{Deserialize, Serialize, de}, @@ -120,8 +121,8 @@ impl Signature { .try_into() .context("ECDSA signature must be 65 bytes long")?; EcdsaSignature { - r: H256::from_slice(&bytes[..32]), - s: H256::from_slice(&bytes[32..64]), + r: B256::from_slice(&bytes[..32]), + s: B256::from_slice(&bytes[32..64]), v: bytes[64], } .to_signature( @@ -258,8 +259,8 @@ impl SigningScheme { #[derive(Eq, PartialEq, Clone, Copy, Debug, Default, Hash)] pub struct EcdsaSignature { - pub r: H256, - pub s: H256, + pub r: B256, + pub s: B256, pub v: u8, } @@ -306,16 +307,16 @@ impl EcdsaSignature { /// r + s + v pub fn to_bytes(self) -> [u8; 65] { let mut bytes = [0u8; 65]; - bytes[..32].copy_from_slice(self.r.as_bytes()); - bytes[32..64].copy_from_slice(self.s.as_bytes()); + bytes[..32].copy_from_slice(self.r.as_slice()); + bytes[32..64].copy_from_slice(self.s.as_slice()); bytes[64] = self.v; bytes } pub fn from_bytes(bytes: &[u8; 65]) -> Self { EcdsaSignature { - r: H256::from_slice(&bytes[..32]), - s: H256::from_slice(&bytes[32..64]), + r: B256::from_slice(&bytes[..32]), + s: B256::from_slice(&bytes[32..64]), v: bytes[64], } } @@ -327,7 +328,7 @@ impl EcdsaSignature { struct_hash: &[u8; 32], ) -> Result { let message = hashed_signing_message(signing_scheme, domain_separator, struct_hash); - let recovery = Recovery::new(message, self.v as u64, self.r, self.s); + let recovery = Recovery::new(message, self.v as u64, self.r.0.into(), self.s.0.into()); let (signature, recovery_id) = recovery .as_signature() .context("unexpectedly invalid signature")?; @@ -350,8 +351,8 @@ impl EcdsaSignature { let signature = key.sign(&message, None).unwrap(); Self { v: signature.v as u8, - r: signature.r, - s: signature.s, + r: signature.r.0.into(), + s: signature.s.0.into(), } } @@ -359,8 +360,8 @@ impl EcdsaSignature { /// when you don't actually care about the owner. pub fn non_zero() -> Self { Self { - r: H256([1; 32]), - s: H256([2; 32]), + r: B256::repeat_byte(1), + s: B256::repeat_byte(2), v: 27, } } @@ -517,8 +518,8 @@ mod tests { ), ( Signature::EthSign(EcdsaSignature { - r: H256([1; 32]), - s: H256([2; 32]), + r: B256::repeat_byte(1), + s: B256::repeat_byte(2), v: 3, }), json!({ diff --git a/crates/orderbook/src/api/cancel_order.rs b/crates/orderbook/src/api/cancel_order.rs index 25a6484952..76556a2565 100644 --- a/crates/orderbook/src/api/cancel_order.rs +++ b/crates/orderbook/src/api/cancel_order.rs @@ -83,7 +83,7 @@ pub fn cancel_order( mod tests { use { super::*, - ethcontract::H256, + alloy::primitives::B256, hex_literal::hex, model::signature::{EcdsaSignature, EcdsaSigningScheme}, serde_json::json, @@ -103,10 +103,10 @@ mod tests { .unwrap(), CancellationPayload { signature: EcdsaSignature { - r: H256(hex!( + r: B256::new(hex!( "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" )), - s: H256(hex!( + s: B256::new(hex!( "202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f" )), v: 27, diff --git a/crates/shared/src/encoded_settlement.rs b/crates/shared/src/encoded_settlement.rs index 6908b3f724..5d41fa7563 100644 --- a/crates/shared/src/encoded_settlement.rs +++ b/crates/shared/src/encoded_settlement.rs @@ -88,7 +88,7 @@ pub struct EncodedSettlement { #[cfg(test)] mod tests { - use {super::*, ethcontract::H256, hex_literal::hex, model::signature::EcdsaSignature}; + use {super::*, alloy::primitives::B256, hex_literal::hex, model::signature::EcdsaSignature}; #[test] fn order_flag_permutations() { @@ -188,8 +188,8 @@ mod tests { (Signature::Eip712(Default::default()), vec![0; 65]), ( Signature::EthSign(EcdsaSignature { - r: H256([1; 32]), - s: H256([1; 32]), + r: B256::repeat_byte(1), + s: B256::repeat_byte(1), v: 1, }), vec![1; 65], From 6c7057db40b4c44a35b555770516bf4b8f416175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Duarte?= Date: Sun, 30 Nov 2025 14:45:40 +0000 Subject: [PATCH 4/6] Migrate OrderCreation and signature handling to alloy types --- .../settlement/transaction/tokenized.rs | 2 +- .../driver/src/infra/solver/dto/solution.rs | 4 +- crates/e2e/src/setup/colocation.rs | 7 +- crates/e2e/src/setup/services.rs | 3 +- crates/e2e/src/setup/solver/solution.rs | 3 +- crates/e2e/tests/e2e/app_data.rs | 22 +-- crates/e2e/tests/e2e/app_data_signer.rs | 15 +- crates/e2e/tests/e2e/autopilot_leader.rs | 8 +- crates/e2e/tests/e2e/buffers.rs | 20 +-- crates/e2e/tests/e2e/cow_amm.rs | 46 +++--- crates/e2e/tests/e2e/eth_integration.rs | 16 +- crates/e2e/tests/e2e/eth_safe.rs | 17 +- crates/e2e/tests/e2e/ethflow.rs | 20 +-- crates/e2e/tests/e2e/hooks.rs | 50 +++--- crates/e2e/tests/e2e/jit_orders.rs | 12 +- crates/e2e/tests/e2e/limit_orders.rs | 130 +++++++-------- crates/e2e/tests/e2e/liquidity.rs | 34 ++-- .../e2e/liquidity_source_notification.rs | 8 +- crates/e2e/tests/e2e/order_cancellation.rs | 16 +- crates/e2e/tests/e2e/partial_fill.rs | 8 +- .../tests/e2e/partially_fillable_balance.rs | 13 +- .../e2e/tests/e2e/partially_fillable_pool.rs | 13 +- .../e2e/tests/e2e/place_order_with_quote.rs | 13 +- crates/e2e/tests/e2e/protocol_fee.rs | 48 +++--- crates/e2e/tests/e2e/quote_verification.rs | 14 +- crates/e2e/tests/e2e/quoting.rs | 19 +-- crates/e2e/tests/e2e/replace_order.rs | 53 +++--- crates/e2e/tests/e2e/smart_contract_orders.rs | 34 ++-- crates/e2e/tests/e2e/solver_competition.rs | 56 +++---- .../tests/e2e/solver_participation_guard.rs | 25 ++- crates/e2e/tests/e2e/submission.rs | 13 +- .../tests/e2e/tracking_insufficient_funds.rs | 21 +-- crates/e2e/tests/e2e/uncovered_order.rs | 15 +- crates/e2e/tests/e2e/univ2.rs | 13 +- crates/e2e/tests/e2e/vault_balances.rs | 13 +- crates/e2e/tests/e2e/wrapper.rs | 8 +- crates/model/src/order.rs | 71 ++++---- crates/model/src/signature.rs | 18 +- crates/orderbook/src/orderbook.rs | 19 +-- crates/shared/src/order_validation.rs | 154 +++++++++--------- .../price_estimation/trade_verifier/mod.rs | 3 +- 41 files changed, 500 insertions(+), 577 deletions(-) diff --git a/crates/autopilot/src/domain/settlement/transaction/tokenized.rs b/crates/autopilot/src/domain/settlement/transaction/tokenized.rs index c36e8d1b47..d2774125c7 100644 --- a/crates/autopilot/src/domain/settlement/transaction/tokenized.rs +++ b/crates/autopilot/src/domain/settlement/transaction/tokenized.rs @@ -43,7 +43,7 @@ pub fn order_uid( let owner = signature .recover_owner(&trade.signature.0, &domain_separator, &order.hash_struct()) .map_err(error::Uid::RecoverOwner)?; - Ok(order.uid(&domain_separator, &owner).into()) + Ok(order.uid(&domain_separator, &owner.into_legacy()).into()) } /// Trade flags are encoded in a 256-bit integer field. For more information on diff --git a/crates/driver/src/infra/solver/dto/solution.rs b/crates/driver/src/infra/solver/dto/solution.rs index f4592ed613..691e25cc46 100644 --- a/crates/driver/src/infra/solver/dto/solution.rs +++ b/crates/driver/src/infra/solver/dto/solution.rs @@ -9,7 +9,7 @@ use { util::Bytes, }, app_data::AppDataHash, - ethrpc::alloy::conversions::IntoAlloy, + ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy}, itertools::Itertools, model::{ DomainSeparator, @@ -324,7 +324,7 @@ impl JitOrder { signature.data = Bytes(self.0.signature[20..].to_vec()); } - signature.signer = signer.into(); + signature.signer = signer.into_legacy().into(); Ok(signature) } diff --git a/crates/e2e/src/setup/colocation.rs b/crates/e2e/src/setup/colocation.rs index 3ad8af6d31..5da127cb26 100644 --- a/crates/e2e/src/setup/colocation.rs +++ b/crates/e2e/src/setup/colocation.rs @@ -1,7 +1,6 @@ use { crate::{nodes::NODE_WS_HOST, setup::*}, ::alloy::primitives::Address, - ethcontract::H160, reqwest::Url, std::collections::HashSet, tokio::task::JoinHandle, @@ -13,7 +12,7 @@ pub struct SolverEngine { pub name: String, pub endpoint: Url, pub account: TestAccount, - pub base_tokens: Vec, + pub base_tokens: Vec
, pub merge_solutions: bool, } @@ -21,7 +20,7 @@ pub async fn start_baseline_solver( name: String, account: TestAccount, weth: Address, - base_tokens: Vec, + base_tokens: Vec
, max_hops: usize, merge_solutions: bool, ) -> SolverEngine { @@ -227,7 +226,7 @@ mempool = "public" }) } -fn encode_base_tokens(tokens: impl IntoIterator) -> String { +fn encode_base_tokens(tokens: impl IntoIterator) -> String { tokens .into_iter() .map(|token| format!(r#""{token:x}""#)) diff --git a/crates/e2e/src/setup/services.rs b/crates/e2e/src/setup/services.rs index 3930a37d47..074985d63b 100644 --- a/crates/e2e/src/setup/services.rs +++ b/crates/e2e/src/setup/services.rs @@ -7,6 +7,7 @@ use { colocation::{self, SolverEngine}, wait_for_condition, }, + alloy::primitives::Address, app_data::{AppDataDocument, AppDataHash}, autopilot::infra::persistence::dto, clap::Parser, @@ -532,7 +533,7 @@ impl<'a> Services<'a> { pub async fn get_native_price( &self, - token: &H160, + token: &Address, ) -> Result { let response = self .http diff --git a/crates/e2e/src/setup/solver/solution.rs b/crates/e2e/src/setup/solver/solution.rs index 938507e6ac..fb2e325649 100644 --- a/crates/e2e/src/setup/solver/solution.rs +++ b/crates/e2e/src/setup/solver/solution.rs @@ -59,7 +59,8 @@ impl JitOrder { domain, &signature .recover_owner(&signature.to_bytes(), domain, &data.hash_struct()) - .unwrap(), + .unwrap() + .into_legacy(), ); let signature = match signature { model::signature::Signature::Eip712(signature) => signature.to_bytes().to_vec(), diff --git a/crates/e2e/tests/e2e/app_data.rs b/crates/e2e/tests/e2e/app_data.rs index 2a8ad76747..cae06951f4 100644 --- a/crates/e2e/tests/e2e/app_data.rs +++ b/crates/e2e/tests/e2e/app_data.rs @@ -51,10 +51,10 @@ async fn app_data(web3: Web3) { let mut create_order = |app_data| { let order = OrderCreation { app_data, - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(2), - buy_token: token_b.address().into_legacy(), - buy_amount: to_wei(1), + sell_token: *token_a.address(), + sell_amount: eth(2), + buy_token: *token_b.address(), + buy_amount: eth(1), valid_to, kind: OrderKind::Sell, ..Default::default() @@ -114,11 +114,11 @@ async fn app_data(web3: Web3) { }); services .submit_quote(&OrderQuoteRequest { - sell_token: order3.sell_token.into_alloy(), - buy_token: order3.buy_token.into_alloy(), + sell_token: order3.sell_token, + buy_token: order3.buy_token, side: OrderQuoteSide::Sell { sell_amount: SellAmount::AfterFee { - value: order3.sell_amount.try_into().unwrap(), + value: order3.sell_amount.into_legacy().try_into().unwrap(), }, }, app_data: OrderCreationAppData::Hash { @@ -213,10 +213,10 @@ async fn app_data_full_format(web3: Web3) { let mut create_order = |app_data| { let order = OrderCreation { app_data, - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(2), - buy_token: token_b.address().into_legacy(), - buy_amount: to_wei(1), + sell_token: *token_a.address(), + sell_amount: eth(2), + buy_token: *token_b.address(), + buy_amount: eth(1), valid_to, kind: OrderKind::Sell, ..Default::default() diff --git a/crates/e2e/tests/e2e/app_data_signer.rs b/crates/e2e/tests/e2e/app_data_signer.rs index 2a34354536..4a3bdb6e46 100644 --- a/crates/e2e/tests/e2e/app_data_signer.rs +++ b/crates/e2e/tests/e2e/app_data_signer.rs @@ -1,10 +1,7 @@ use { alloy::primitives::Address, e2e::setup::{OnchainComponents, Services, TestAccount, eth, run_test, safe::Safe, to_wei}, - ethrpc::alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy}, model::{ order::{OrderCreation, OrderCreationAppData, OrderKind}, signature::EcdsaSigningScheme, @@ -49,10 +46,10 @@ async fn order_creation_checks_metadata_signer(web3: Web3) { let mut create_order = |app_data| { let order = OrderCreation { app_data, - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(2), - buy_token: token_b.address().into_legacy(), - buy_amount: to_wei(1), + sell_token: *token_a.address(), + sell_amount: eth(2), + buy_token: *token_b.address(), + buy_amount: eth(1), valid_to, kind: OrderKind::Sell, ..Default::default() @@ -116,7 +113,7 @@ async fn order_creation_checks_metadata_signer(web3: Web3) { // Rejected: from and signer are inconsistent. let full_app_data = full_app_data_with_signer(adversary.address()); let mut order5 = create_order(full_app_data); - order5.from = Some(safe.address().into_legacy()); + order5.from = Some(safe.address()); safe.sign_order(&mut order5, &onchain); let err = services.create_order(&order5).await.unwrap_err(); assert!(err.1.contains("AppdataFromMismatch")); diff --git a/crates/e2e/tests/e2e/autopilot_leader.rs b/crates/e2e/tests/e2e/autopilot_leader.rs index d9e53c6bc8..fd4f7fc906 100644 --- a/crates/e2e/tests/e2e/autopilot_leader.rs +++ b/crates/e2e/tests/e2e/autopilot_leader.rs @@ -112,10 +112,10 @@ async fn dual_autopilot_only_leader_produces_auctions(web3: Web3) { let order = || { OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(10), - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: to_wei(5), + sell_token: *token_a.address(), + sell_amount: eth(10), + buy_token: *onchain.contracts().weth.address(), + buy_amount: eth(5), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() diff --git a/crates/e2e/tests/e2e/buffers.rs b/crates/e2e/tests/e2e/buffers.rs index 6a5d31535c..4e927b1e31 100644 --- a/crates/e2e/tests/e2e/buffers.rs +++ b/crates/e2e/tests/e2e/buffers.rs @@ -1,10 +1,7 @@ use { ::alloy::primitives::U256, e2e::setup::{eth, *}, - ethrpc::alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy}, model::{ order::{OrderCreation, OrderKind}, signature::EcdsaSigningScheme, @@ -91,10 +88,10 @@ async fn onchain_settlement_without_liquidity(web3: Web3) { // Place Order let order = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(9), - buy_token: token_b.address().into_legacy(), - buy_amount: to_wei(5), + sell_token: *token_a.address(), + sell_amount: eth(9), + buy_token: *token_b.address(), + buy_amount: eth(5), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Buy, ..Default::default() @@ -108,9 +105,8 @@ async fn onchain_settlement_without_liquidity(web3: Web3) { tracing::info!("waiting for first trade"); onchain.mint_block().await; - let trade_happened = || async { - token_b.balanceOf(trader.address()).call().await.unwrap() == order.buy_amount.into_alloy() - }; + let trade_happened = + || async { token_b.balanceOf(trader.address()).call().await.unwrap() == order.buy_amount }; wait_for_condition(TIMEOUT, trade_happened).await.unwrap(); // Check that settlement buffers were traded. @@ -138,7 +134,7 @@ async fn onchain_settlement_without_liquidity(web3: Web3) { let trade_happened = || async { onchain.mint_block().await; token_b.balanceOf(trader.address()).call().await.unwrap() - == (order.buy_amount.into_alloy() * U256::from(2)) + == (order.buy_amount * ::alloy::primitives::U256::from(2)) }; wait_for_condition(TIMEOUT, trade_happened).await.unwrap(); } diff --git a/crates/e2e/tests/e2e/cow_amm.rs b/crates/e2e/tests/e2e/cow_amm.rs index 3eeff7f5cc..0cb6876214 100644 --- a/crates/e2e/tests/e2e/cow_amm.rs +++ b/crates/e2e/tests/e2e/cow_amm.rs @@ -288,10 +288,10 @@ async fn cow_amm_jit(web3: Web3) { // place user order with the same limit price as the CoW AMM order let user_order = OrderCreation { - sell_token: onchain.contracts().weth.address().into_legacy(), - sell_amount: ethcontract::U256::exp10(17), // 0.1 WETH - buy_token: dai.address().into_legacy(), - buy_amount: to_wei(230), // 230 DAI + sell_token: *onchain.contracts().weth.address(), + sell_amount: alloy::primitives::U256::from(10).pow(alloy::primitives::U256::from(17)), // 0.1 WETH + buy_token: *dai.address(), + buy_amount: eth(230), // 230 DAI valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -307,6 +307,7 @@ async fn cow_amm_jit(web3: Web3) { let bob_balance_before = dai.balanceOf(bob.address()).call().await.unwrap(); let fee = ethcontract::U256::exp10(16); // 0.01 WETH + let fee_alloy = alloy::primitives::U256::from(fee.low_u128()); mock_solver.configure_solution(Some(Solution { id: 1, @@ -340,7 +341,7 @@ async fn cow_amm_jit(web3: Web3) { }), solvers_dto::solution::Trade::Fulfillment(solvers_dto::solution::Fulfillment { order: solvers_dto::solution::OrderUid(user_order_id.0), - executed_amount: user_order.sell_amount - fee, + executed_amount: (user_order.sell_amount - fee_alloy).into_legacy(), fee: Some(fee), }), ], @@ -363,7 +364,7 @@ async fn cow_amm_jit(web3: Web3) { let bob_received = bob_balance - bob_balance_before; // bob and CoW AMM both got surplus and an equal amount - amm_received >= cow_amm_order.buyAmount && bob_received > user_order.buy_amount.into_alloy() + amm_received >= cow_amm_order.buyAmount && bob_received > user_order.buy_amount }) .await .unwrap(); @@ -589,10 +590,10 @@ factory = "0xf76c421bAb7df8548604E60deCCcE50477C10462" // Place Orders let order = OrderCreation { - sell_token: usdc.address().into_legacy(), - sell_amount: to_wei_with_exp(1000, 6), - buy_token: usdt.address().into_legacy(), - buy_amount: to_wei_with_exp(2000, 6), + sell_token: *usdc.address(), + sell_amount: alloy::primitives::U256::from(to_wei_with_exp(1000, 6).low_u128()), + buy_token: *usdt.address(), + buy_amount: alloy::primitives::U256::from(to_wei_with_exp(2000, 6).low_u128()), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -857,7 +858,7 @@ async fn cow_amm_opposite_direction(web3: Web3) { .unwrap() .unwrap(); let valid_to = block.timestamp.as_u32() + 300; - let executed_amount = to_wei(230); + let executed_amount = eth(230); // CoW AMM order remains the same (selling WETH for DAI) let cow_amm_order = contracts::alloy::cow_amm::CowAmm::GPv2Order::Data { @@ -865,7 +866,7 @@ async fn cow_amm_opposite_direction(web3: Web3) { buyToken: *dai.address(), receiver: Default::default(), sellAmount: U256::from(10).pow(U256::from(17)), - buyAmount: executed_amount.into_alloy(), + buyAmount: executed_amount, validTo: valid_to, appData: FixedBytes(APP_DATA), feeAmount: U256::ZERO, @@ -976,7 +977,7 @@ async fn cow_amm_opposite_direction(web3: Web3) { }), solvers_dto::solution::Trade::Fulfillment(solvers_dto::solution::Fulfillment { order: solvers_dto::solution::OrderUid(order_uid.0), - executed_amount: executed_amount - fee_user, + executed_amount: executed_amount.into_legacy() - fee_user, fee: Some(fee_user), }), ], @@ -999,7 +1000,7 @@ async fn cow_amm_opposite_direction(web3: Web3) { buy_token: *onchain.contracts().weth.address(), side: OrderQuoteSide::Sell { sell_amount: SellAmount::AfterFee { - value: NonZeroU256::try_from(executed_amount).unwrap(), + value: NonZeroU256::try_from(executed_amount.into_legacy()).unwrap(), }, }, ..Default::default() @@ -1014,10 +1015,7 @@ async fn cow_amm_opposite_direction(web3: Web3) { *onchain.contracts().weth.address() ); // Ensure the amounts are the same as the solution proposes. - assert_eq!( - quote_response.quote.sell_amount, - executed_amount.into_alloy() - ); + assert_eq!(quote_response.quote.sell_amount, executed_amount); assert_eq!( quote_response.quote.buy_amount, U256::from(10).pow(U256::from(17)) @@ -1025,11 +1023,12 @@ async fn cow_amm_opposite_direction(web3: Web3) { // Place user order where bob sells DAI to buy WETH (opposite direction) let user_order = OrderCreation { - sell_token: dai.address().into_legacy(), + sell_token: *dai.address(), sell_amount: executed_amount, // 230 DAI - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: ethcontract::U256::from(90000000000000000u64), /* 0.09 WETH to generate some - * surplus */ + buy_token: *onchain.contracts().weth.address(), + buy_amount: alloy::primitives::U256::from(90000000000000000u64), /* 0.09 WETH to generate + * some + * surplus */ valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -1068,8 +1067,7 @@ async fn cow_amm_opposite_direction(web3: Web3) { let bob_weth_received = bob_weth_balance_after - bob_weth_balance_before; // Bob should receive WETH, CoW AMM's WETH balance decreases - bob_weth_received >= user_order.buy_amount.into_alloy() - && amm_weth_sent == cow_amm_order.sellAmount + bob_weth_received >= user_order.buy_amount && amm_weth_sent == cow_amm_order.sellAmount }) .await .unwrap(); diff --git a/crates/e2e/tests/e2e/eth_integration.rs b/crates/e2e/tests/e2e/eth_integration.rs index 3f28cc54ae..4d5960e38c 100644 --- a/crates/e2e/tests/e2e/eth_integration.rs +++ b/crates/e2e/tests/e2e/eth_integration.rs @@ -86,10 +86,10 @@ async fn eth_integration(web3: Web3) { assert_ne!(*onchain.contracts().weth.address(), BUY_ETH_ADDRESS); let order_buy_eth_a = OrderCreation { kind: OrderKind::Buy, - sell_token: token.address().into_legacy(), - sell_amount: to_wei(50), - buy_token: BUY_ETH_ADDRESS.into_legacy(), - buy_amount: to_wei(49), + sell_token: *token.address(), + sell_amount: eth(50), + buy_token: BUY_ETH_ADDRESS, + buy_amount: eth(49), valid_to: model::time::now_in_epoch_seconds() + 300, ..Default::default() } @@ -101,10 +101,10 @@ async fn eth_integration(web3: Web3) { services.create_order(&order_buy_eth_a).await.unwrap(); let order_buy_eth_b = OrderCreation { kind: OrderKind::Sell, - sell_token: token.address().into_legacy(), - sell_amount: to_wei(50), - buy_token: BUY_ETH_ADDRESS.into_legacy(), - buy_amount: to_wei(49), + sell_token: *token.address(), + sell_amount: eth(50), + buy_token: BUY_ETH_ADDRESS, + buy_amount: eth(49), valid_to: model::time::now_in_epoch_seconds() + 300, ..Default::default() } diff --git a/crates/e2e/tests/e2e/eth_safe.rs b/crates/e2e/tests/e2e/eth_safe.rs index 6987c9567d..912a5bacb8 100644 --- a/crates/e2e/tests/e2e/eth_safe.rs +++ b/crates/e2e/tests/e2e/eth_safe.rs @@ -10,10 +10,7 @@ use { to_wei, wait_for_condition, }, - ethrpc::alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy}, model::{ order::{BUY_ETH_ADDRESS, OrderCreation, OrderKind}, signature::{Signature, hashed_eip712_message}, @@ -68,15 +65,15 @@ async fn test(web3: Web3) { .unwrap(); assert_eq!(balance, ::alloy::primitives::U256::ZERO); let mut order = OrderCreation { - from: Some(safe.address().into_legacy()), - sell_token: token.address().into_legacy(), - sell_amount: to_wei(4), - buy_token: BUY_ETH_ADDRESS.into_legacy(), - buy_amount: to_wei(3), + from: Some(safe.address()), + sell_token: *token.address(), + sell_amount: eth(4), + buy_token: BUY_ETH_ADDRESS, + buy_amount: eth(3), valid_to: model::time::now_in_epoch_seconds() + 300, partially_fillable: true, kind: OrderKind::Sell, - receiver: Some(safe.address().into_legacy()), + receiver: Some(safe.address()), ..Default::default() }; order.signature = Signature::Eip1271(safe.sign_message(&hashed_eip712_message( diff --git a/crates/e2e/tests/e2e/ethflow.rs b/crates/e2e/tests/e2e/ethflow.rs index 726f2ab758..fea85147fe 100644 --- a/crates/e2e/tests/e2e/ethflow.rs +++ b/crates/e2e/tests/e2e/ethflow.rs @@ -30,7 +30,6 @@ use { }, block_stream::timestamp_of_current_block_in_seconds, }, - hex_literal::hex, model::{ DomainSeparator, order::{ @@ -144,7 +143,7 @@ async fn eth_flow_tx(web3: Web3) { }} }} }}"#, - dai.address().into_legacy(), + dai.address(), approve_call_data, onchain.contracts().weth.address(), approve_call_data, @@ -361,9 +360,9 @@ async fn eth_flow_indexing_after_refund(web3: Web3) { .await; // Create the actual order that should be picked up by the services and matched. - let buy_token = dai.address().into_legacy(); + let buy_token = *dai.address(); let receiver = Address::repeat_byte(0x42); - let sell_amount = to_wei(1); + let sell_amount = eth(1); let valid_to = chrono::offset::Utc::now().timestamp() as u32 + timestamp_of_current_block_in_seconds(&web3.alloy) .await @@ -373,8 +372,8 @@ async fn eth_flow_indexing_after_refund(web3: Web3) { &test_submit_quote( &services, &(EthFlowTradeIntent { - sell_amount: sell_amount.into_alloy(), - buy_token: buy_token.into_alloy(), + sell_amount, + buy_token, receiver, }) .to_quote_request( @@ -487,12 +486,9 @@ async fn test_order_availability_in_api( // Api returns eth flow orders for both eth-flow contract address and actual // owner - for address in [ - &owner.into_legacy(), - ðflow_contract.address().into_legacy(), - ] { + for address in [owner, ethflow_contract.address()] { test_account_query( - address, + &address.into_legacy(), services.client(), order, &owner.into_legacy(), @@ -693,7 +689,7 @@ impl ExtendedEthFlowOrder { .with_valid_to(u32::MAX) .with_app_data(self.0.appData.0) .with_class(OrderClass::Market) // Eth-flow orders only support market orders at this point in time - .with_eip1271(ethflow_contract.address().into_legacy(), hex!("").into()) + .with_eip1271(ethflow_contract.address().into_legacy(), vec![]) .build() } diff --git a/crates/e2e/tests/e2e/hooks.rs b/crates/e2e/tests/e2e/hooks.rs index 36868d0fa5..c8ee68160c 100644 --- a/crates/e2e/tests/e2e/hooks.rs +++ b/crates/e2e/tests/e2e/hooks.rs @@ -80,10 +80,10 @@ async fn gas_limit(web3: Web3) { services.start_protocol(solver).await; let order = OrderCreation { - sell_token: cow.address().into_legacy(), - sell_amount: to_wei(4), - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: to_wei(3), + sell_token: *cow.address(), + sell_amount: eth(4), + buy_token: *onchain.contracts().weth.address(), + buy_amount: eth(3), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, app_data: OrderCreationAppData::Full { @@ -157,10 +157,10 @@ async fn allowance(web3: Web3) { services.start_protocol(solver).await; let order = OrderCreation { - sell_token: cow.address().into_legacy(), - sell_amount: to_wei(5), - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: to_wei(3), + sell_token: *cow.address(), + sell_amount: eth(5), + buy_token: *onchain.contracts().weth.address(), + buy_amount: eth(3), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, app_data: OrderCreationAppData::Full { @@ -205,7 +205,7 @@ async fn allowance(web3: Web3) { .call() .await .unwrap(); - assert!(balance >= order.buy_amount.into_alloy()); + assert!(balance >= order.buy_amount); tracing::info!("Waiting for auction to be cleared."); let auction_is_empty = || async { services.get_auction().await.auction.orders.is_empty() }; @@ -332,17 +332,17 @@ async fn signature(web3: Web3) { // Place Orders let mut order = OrderCreation { - from: Some(safe.address().into_legacy()), + from: Some(safe.address()), // Quotes for trades where the pre-interactions deploy a contract // at the `from` address currently can't be verified. // To not throw an error because we can't get a verifiable quote // we make the order partially fillable and sell slightly more than // `from` currently has. - sell_amount: to_wei(6), + sell_amount: eth(6), partially_fillable: true, - sell_token: token.address().into_legacy(), - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: to_wei(3), + sell_token: *token.address(), + buy_token: *onchain.contracts().weth.address(), + buy_amount: eth(3), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, app_data: OrderCreationAppData::Full { @@ -374,11 +374,7 @@ async fn signature(web3: Web3) { assert_eq!(balance, to_wei(5)); // Check that the Safe really hasn't been deployed yet. - let code = web3 - .eth() - .code(safe.address().into_legacy(), None) - .await - .unwrap(); + let code = web3.alloy.get_code_at(safe.address()).await.unwrap(); assert_eq!(code.0.len(), 0); tracing::info!("Waiting for trade."); @@ -401,14 +397,10 @@ async fn signature(web3: Web3) { .call() .await .unwrap(); - assert!(balance >= order.buy_amount.into_alloy()); + assert!(balance >= order.buy_amount); // Check Safe was deployed - let code = web3 - .eth() - .code(safe.address().into_legacy(), None) - .await - .unwrap(); + let code = web3.alloy.get_code_at(safe.address()).await.unwrap(); assert_ne!(code.0.len(), 0); tracing::info!("Waiting for auction to be cleared."); @@ -469,10 +461,10 @@ async fn partial_fills(web3: Web3) { tracing::info!("Placing order"); let order = OrderCreation { - sell_token: sell_token.address().into_legacy(), - sell_amount: to_wei(2), - buy_token: token.address().into_legacy(), - buy_amount: to_wei(1), + sell_token: *sell_token.address(), + sell_amount: eth(2), + buy_token: *token.address(), + buy_amount: eth(1), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, partially_fillable: true, diff --git a/crates/e2e/tests/e2e/jit_orders.rs b/crates/e2e/tests/e2e/jit_orders.rs index bfca8853e6..ce7132b31a 100644 --- a/crates/e2e/tests/e2e/jit_orders.rs +++ b/crates/e2e/tests/e2e/jit_orders.rs @@ -80,7 +80,7 @@ async fn single_limit_order_test(web3: Web3) { name: "mock_solver".into(), account: solver.clone(), endpoint: mock_solver.url.clone(), - base_tokens: vec![token.address().into_legacy()], + base_tokens: vec![*token.address()], merge_solutions: true, }, ], @@ -111,10 +111,10 @@ async fn single_limit_order_test(web3: Web3) { // Place order let order = OrderCreation { - sell_token: onchain.contracts().weth.address().into_legacy(), - sell_amount: to_wei(10), - buy_token: token.address().into_legacy(), - buy_amount: to_wei(5), + sell_token: *onchain.contracts().weth.address(), + sell_amount: eth(10), + buy_token: *token.address(), + buy_amount: eth(5), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -169,7 +169,7 @@ async fn single_limit_order_test(web3: Web3) { fee: Some(to_wei(1)), }), solvers_dto::solution::Trade::Fulfillment(solvers_dto::solution::Fulfillment { - executed_amount: order.sell_amount, + executed_amount: order.sell_amount.into_legacy(), fee: Some(0.into()), order: solvers_dto::solution::OrderUid(order_id.0), }), diff --git a/crates/e2e/tests/e2e/limit_orders.rs b/crates/e2e/tests/e2e/limit_orders.rs index c3162d13d8..ad8f4666bf 100644 --- a/crates/e2e/tests/e2e/limit_orders.rs +++ b/crates/e2e/tests/e2e/limit_orders.rs @@ -163,10 +163,10 @@ async fn single_limit_order_test(web3: Web3) { services.start_protocol(solver).await; let order = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(10), - buy_token: token_b.address().into_legacy(), - buy_amount: to_wei(5), + sell_token: *token_a.address(), + sell_amount: eth(10), + buy_token: *token_b.address(), + buy_amount: eth(5), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -286,10 +286,10 @@ async fn two_limit_orders_test(web3: Web3) { services.start_protocol(solver).await; let order_a = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(10), - buy_token: token_b.address().into_legacy(), - buy_amount: to_wei(5), + sell_token: *token_a.address(), + sell_amount: eth(10), + buy_token: *token_b.address(), + buy_amount: eth(5), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -310,10 +310,10 @@ async fn two_limit_orders_test(web3: Web3) { assert!(limit_order.metadata.class.is_limit()); let order_b = OrderCreation { - sell_token: token_b.address().into_legacy(), - sell_amount: to_wei(5), - buy_token: token_a.address().into_legacy(), - buy_amount: to_wei(2), + sell_token: *token_b.address(), + sell_amount: eth(5), + buy_token: *token_a.address(), + buy_amount: eth(2), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -392,7 +392,7 @@ async fn two_limit_orders_multiple_winners_test(web3: Web3) { "test_solver".into(), solver_a.clone(), *onchain.contracts().weth.address(), - vec![base_a.address().into_legacy()], + vec![*base_a.address()], 2, false, ) @@ -401,7 +401,7 @@ async fn two_limit_orders_multiple_winners_test(web3: Web3) { "solver2".into(), solver_b.clone(), *onchain.contracts().weth.address(), - vec![base_b.address().into_legacy()], + vec![*base_b.address()], 2, false, ) @@ -420,10 +420,10 @@ async fn two_limit_orders_multiple_winners_test(web3: Web3) { // Place Orders let order_a = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(10), - buy_token: token_c.address().into_legacy(), - buy_amount: to_wei(5), + sell_token: *token_a.address(), + sell_amount: eth(10), + buy_token: *token_c.address(), + buy_amount: eth(5), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -436,10 +436,10 @@ async fn two_limit_orders_multiple_winners_test(web3: Web3) { let uid_a = services.create_order(&order_a).await.unwrap(); let order_b = OrderCreation { - sell_token: token_b.address().into_legacy(), - sell_amount: to_wei(10), - buy_token: token_d.address().into_legacy(), - buy_amount: to_wei(5), + sell_token: *token_b.address(), + sell_amount: eth(10), + buy_token: *token_d.address(), + buy_amount: eth(5), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -504,7 +504,7 @@ async fn two_limit_orders_multiple_winners_test(web3: Web3) { database::solver_competition_v2::fetch_solver_winning_solutions( &mut ex, competition.auction_id, - ByteArray(solver_a.address().into_legacy().0), + ByteArray(solver_a.address().0.0), ) .await .unwrap(); @@ -512,7 +512,7 @@ async fn two_limit_orders_multiple_winners_test(web3: Web3) { database::solver_competition_v2::fetch_solver_winning_solutions( &mut ex, competition.auction_id, - ByteArray(solver_b.address().into_legacy().0), + ByteArray(solver_b.address().0.0), ) .await .unwrap(); @@ -549,10 +549,10 @@ async fn two_limit_orders_multiple_winners_test(web3: Web3) { .unwrap(); assert_eq!(settlements.len(), 2); assert!(settlements.iter().any(|settlement| settlement.solver - == ByteArray(solver_a.address().into_legacy().0) + == ByteArray(solver_a.address().0.0) && settlement.solution_uid == solver_a_winning_solutions[0].uid)); assert!(settlements.iter().any(|settlement| settlement.solver - == ByteArray(solver_b.address().into_legacy().0) + == ByteArray(solver_b.address().0.0) && settlement.solution_uid == solver_b_winning_solutions[0].uid)); // Ensure all the reference scores are indexed @@ -567,11 +567,11 @@ async fn two_limit_orders_multiple_winners_test(web3: Web3) { // fetch the reference scores of both winners let solver_a_reference_score = reference_scores - .get(&ByteArray(solver_a.address().into_legacy().0)) + .get(&ByteArray(solver_a.address().0.0)) .unwrap() .clone(); let solver_b_reference_score = reference_scores - .get(&ByteArray(solver_b.address().into_legacy().0)) + .get(&ByteArray(solver_b.address().0.0)) .unwrap() .clone(); @@ -628,10 +628,10 @@ async fn too_many_limit_orders_test(web3: Web3) { .await; let order = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(1), - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: to_wei(1), + sell_token: *token_a.address(), + sell_amount: eth(1), + buy_token: *onchain.contracts().weth.address(), + buy_amount: eth(1), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -646,10 +646,10 @@ async fn too_many_limit_orders_test(web3: Web3) { // Attempt to place another order, but the orderbook is configured to allow only // one limit order per user. let order = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(1), - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: to_wei(2), + sell_token: *token_a.address(), + sell_amount: eth(1), + buy_token: *onchain.contracts().weth.address(), + buy_amount: eth(2), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -724,10 +724,10 @@ async fn limit_does_not_apply_to_in_market_orders_test(web3: Web3) { // Place "in-market" order let order = OrderCreation { - sell_token: token.address().into_legacy(), - sell_amount: quote.quote.sell_amount.into_legacy(), - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: quote.quote.buy_amount.saturating_sub(eth(4)).into_legacy(), + sell_token: *token.address(), + sell_amount: quote.quote.sell_amount, + buy_token: *onchain.contracts().weth.address(), + buy_amount: quote.quote.buy_amount.saturating_sub(eth(4)), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -741,10 +741,10 @@ async fn limit_does_not_apply_to_in_market_orders_test(web3: Web3) { // Place a "limit" order let order = OrderCreation { - sell_token: token.address().into_legacy(), - sell_amount: to_wei(1), - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: to_wei(3), + sell_token: *token.address(), + sell_amount: eth(1), + buy_token: *onchain.contracts().weth.address(), + buy_amount: eth(3), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -760,10 +760,10 @@ async fn limit_does_not_apply_to_in_market_orders_test(web3: Web3) { // Place another "in-market" order in order to check it is not limited let order = OrderCreation { - sell_token: token.address().into_legacy(), - sell_amount: quote.quote.sell_amount.into_legacy(), - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: quote.quote.buy_amount.saturating_sub(eth(2)).into_legacy(), + sell_token: *token.address(), + sell_amount: quote.quote.sell_amount, + buy_token: *onchain.contracts().weth.address(), + buy_amount: quote.quote.buy_amount.saturating_sub(eth(2)), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -777,10 +777,10 @@ async fn limit_does_not_apply_to_in_market_orders_test(web3: Web3) { // Place a "limit" order in order to see if fails let order = OrderCreation { - sell_token: token.address().into_legacy(), - sell_amount: to_wei(1), - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: to_wei(2), + sell_token: *token.address(), + sell_amount: eth(1), + buy_token: *onchain.contracts().weth.address(), + buy_amount: eth(2), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -849,10 +849,10 @@ async fn forked_mainnet_single_limit_order_test(web3: Web3) { onchain.mint_block().await; let order = OrderCreation { - sell_token: token_usdc.address().into_legacy(), - sell_amount: to_wei_with_exp(1000, 6), - buy_token: token_usdt.address().into_legacy(), - buy_amount: to_wei_with_exp(500, 6), + sell_token: *token_usdc.address(), + sell_amount: to_wei_with_exp(1000, 6).into_alloy(), + buy_token: *token_usdt.address(), + buy_amount: to_wei_with_exp(500, 6).into_alloy(), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -951,10 +951,10 @@ async fn forked_gnosis_single_limit_order_test(web3: Web3) { services.start_protocol(solver).await; let order = OrderCreation { - sell_token: token_usdc.address().into_legacy(), - sell_amount: to_wei_with_exp(1000, 6), - buy_token: token_wxdai.address().into_legacy(), - buy_amount: to_wei(500), + sell_token: *token_usdc.address(), + sell_amount: to_wei_with_exp(1000, 6).into_alloy(), + buy_token: *token_wxdai.address(), + buy_amount: eth(500), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -1050,10 +1050,10 @@ async fn no_liquidity_limit_order(web3: Web3) { // Place order let mut order = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(10), - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: to_wei(1), + sell_token: *token_a.address(), + sell_amount: eth(10), + buy_token: *onchain.contracts().weth.address(), + buy_amount: eth(1), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -1069,7 +1069,7 @@ async fn no_liquidity_limit_order(web3: Web3) { assert_eq!(limit_order.metadata.class, OrderClass::Limit); // Cannot place orders with unsupported tokens - order.sell_token = unsupported.address().into_legacy(); + order.sell_token = *unsupported.address(); services .create_order(&order.sign( EcdsaSigningScheme::Eip712, diff --git a/crates/e2e/tests/e2e/liquidity.rs b/crates/e2e/tests/e2e/liquidity.rs index c610d91dd3..5ddf66321e 100644 --- a/crates/e2e/tests/e2e/liquidity.rs +++ b/crates/e2e/tests/e2e/liquidity.rs @@ -156,10 +156,10 @@ async fn zero_ex_liquidity(web3: Web3) { .unwrap(); let order = OrderCreation { - sell_token: token_usdc.address().into_legacy(), - sell_amount: amount.into_legacy(), - buy_token: token_usdt.address().into_legacy(), - buy_amount: amount.into_legacy(), + sell_token: *token_usdc.address(), + sell_amount: amount, + buy_token: *token_usdt.address(), + buy_amount: amount, valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -305,14 +305,18 @@ fn create_zeroex_liquidity_orders( weth_address: Address, ) -> [shared::zeroex_api::OrderRecord; 3] { let typed_order = Eip712TypedZeroExOrder { - maker_token: order_creation.buy_token.into_alloy(), - taker_token: order_creation.sell_token.into_alloy(), + maker_token: order_creation.buy_token, + taker_token: order_creation.sell_token, // fully covers execution costs - maker_amount: order_creation.buy_amount.as_u128() * 3, - taker_amount: order_creation.sell_amount.as_u128() * 2, + maker_amount: order_creation.buy_amount.try_into().unwrap(), + taker_amount: order_creation.sell_amount.try_into().unwrap(), // makes 0x order partially filled, but the amount is higher than the cowswap order to // make sure the 0x order is not overfilled in the end of the e2e test - remaining_fillable_taker_amount: order_creation.sell_amount.as_u128() * 3 / 2, + remaining_fillable_taker_amount: (order_creation.sell_amount + * alloy::primitives::U256::from(3) + / alloy::primitives::U256::from(2)) + .try_into() + .unwrap(), taker_token_fee_amount: 0, maker: zeroex_maker.address(), // Makes it possible for anyone to fill the order @@ -325,12 +329,12 @@ fn create_zeroex_liquidity_orders( }; let usdt_weth_order = Eip712TypedZeroExOrder { maker_token: weth_address, - taker_token: order_creation.buy_token.into_alloy(), + taker_token: order_creation.buy_token, // the value comes from the `--amount-to-estimate-prices-with` config to provide // sufficient liquidity maker_amount: 1_000_000_000_000_000_000u128, - taker_amount: order_creation.sell_amount.as_u128(), - remaining_fillable_taker_amount: order_creation.sell_amount.as_u128(), + taker_amount: order_creation.sell_amount.try_into().unwrap(), + remaining_fillable_taker_amount: order_creation.sell_amount.try_into().unwrap(), taker_token_fee_amount: 0, maker: zeroex_maker.address(), taker: Default::default(), @@ -342,12 +346,12 @@ fn create_zeroex_liquidity_orders( }; let usdc_weth_order = Eip712TypedZeroExOrder { maker_token: weth_address, - taker_token: order_creation.sell_token.into_alloy(), + taker_token: order_creation.sell_token, // the value comes from the `--amount-to-estimate-prices-with` config to provide // sufficient liquidity maker_amount: 1_000_000_000_000_000_000u128, - taker_amount: order_creation.sell_amount.as_u128(), - remaining_fillable_taker_amount: order_creation.sell_amount.as_u128(), + taker_amount: order_creation.sell_amount.try_into().unwrap(), + remaining_fillable_taker_amount: order_creation.sell_amount.try_into().unwrap(), taker_token_fee_amount: 0, maker: zeroex_maker.address(), taker: Default::default(), diff --git a/crates/e2e/tests/e2e/liquidity_source_notification.rs b/crates/e2e/tests/e2e/liquidity_source_notification.rs index 6fa29f60a6..16fed65c09 100644 --- a/crates/e2e/tests/e2e/liquidity_source_notification.rs +++ b/crates/e2e/tests/e2e/liquidity_source_notification.rs @@ -237,10 +237,10 @@ http-timeout = "10s" // Create CoW order let order_id = { let order = OrderCreation { - sell_token: token_usdc.address().into_legacy(), - sell_amount: trade_amount, - buy_token: token_usdt.address().into_legacy(), - buy_amount: trade_amount, + sell_token: *token_usdc.address(), + sell_amount: trade_amount.into_alloy(), + buy_token: *token_usdt.address(), + buy_amount: trade_amount.into_alloy(), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() diff --git a/crates/e2e/tests/e2e/order_cancellation.rs b/crates/e2e/tests/e2e/order_cancellation.rs index 774c12d59b..0af776f213 100644 --- a/crates/e2e/tests/e2e/order_cancellation.rs +++ b/crates/e2e/tests/e2e/order_cancellation.rs @@ -2,10 +2,7 @@ use { ::alloy::primitives::U256 as AlloyU256, database::order_events::OrderEventLabel, e2e::setup::{eth, *}, - ethrpc::alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy}, model::{ order::{ CancellationPayload, @@ -111,12 +108,11 @@ async fn order_cancellation(web3: Web3) { let order = OrderCreation { kind: quote.kind, - sell_token: quote.sell_token.into_legacy(), - sell_amount: quote.sell_amount.into_legacy(), - fee_amount: 0.into(), - buy_token: quote.buy_token.into_legacy(), - buy_amount: ((quote.buy_amount * AlloyU256::from(99)) / AlloyU256::from(100)) - .into_legacy(), + sell_token: quote.sell_token, + sell_amount: quote.sell_amount, + fee_amount: ::alloy::primitives::U256::ZERO, + buy_token: quote.buy_token, + buy_amount: ((quote.buy_amount * AlloyU256::from(99)) / AlloyU256::from(100)), valid_to: quote.valid_to, app_data: quote.app_data, ..Default::default() diff --git a/crates/e2e/tests/e2e/partial_fill.rs b/crates/e2e/tests/e2e/partial_fill.rs index 81f017ac51..7a2476913b 100644 --- a/crates/e2e/tests/e2e/partial_fill.rs +++ b/crates/e2e/tests/e2e/partial_fill.rs @@ -58,10 +58,10 @@ async fn test(web3: Web3) { let balance = token.balanceOf(trader.address()).call().await.unwrap(); assert_eq!(balance, U256::ZERO); let order = OrderCreation { - sell_token: onchain.contracts().weth.address().into_legacy(), - sell_amount: to_wei(4), - buy_token: token.address().into_legacy(), - buy_amount: to_wei(3), + sell_token: *onchain.contracts().weth.address(), + sell_amount: eth(4), + buy_token: *token.address(), + buy_amount: eth(3), valid_to: model::time::now_in_epoch_seconds() + 300, partially_fillable: true, kind: OrderKind::Sell, diff --git a/crates/e2e/tests/e2e/partially_fillable_balance.rs b/crates/e2e/tests/e2e/partially_fillable_balance.rs index 4d548d8a5a..36b5b26210 100644 --- a/crates/e2e/tests/e2e/partially_fillable_balance.rs +++ b/crates/e2e/tests/e2e/partially_fillable_balance.rs @@ -1,10 +1,7 @@ use { ::alloy::primitives::U256, e2e::setup::{eth, *}, - ethrpc::alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy}, model::{ order::{OrderCreation, OrderKind}, signature::EcdsaSigningScheme, @@ -84,10 +81,10 @@ async fn test(web3: Web3) { services.start_protocol(solver).await; let order_a = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(100), - buy_token: token_b.address().into_legacy(), - buy_amount: to_wei(50), + sell_token: *token_a.address(), + sell_amount: eth(100), + buy_token: *token_b.address(), + buy_amount: eth(50), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, partially_fillable: true, diff --git a/crates/e2e/tests/e2e/partially_fillable_pool.rs b/crates/e2e/tests/e2e/partially_fillable_pool.rs index db8f925b49..fc02f5a8d6 100644 --- a/crates/e2e/tests/e2e/partially_fillable_pool.rs +++ b/crates/e2e/tests/e2e/partially_fillable_pool.rs @@ -1,10 +1,7 @@ use { ::alloy::primitives::U256, e2e::setup::{eth, *}, - ethrpc::alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy}, model::{ order::{OrderCreation, OrderKind}, signature::EcdsaSigningScheme, @@ -84,10 +81,10 @@ async fn test(web3: Web3) { onchain.mint_block().await; let order_a = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(500), - buy_token: token_b.address().into_legacy(), - buy_amount: to_wei(390), + sell_token: *token_a.address(), + sell_amount: eth(500), + buy_token: *token_b.address(), + buy_amount: eth(390), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, partially_fillable: true, diff --git a/crates/e2e/tests/e2e/place_order_with_quote.rs b/crates/e2e/tests/e2e/place_order_with_quote.rs index cc89a975d9..f375426587 100644 --- a/crates/e2e/tests/e2e/place_order_with_quote.rs +++ b/crates/e2e/tests/e2e/place_order_with_quote.rs @@ -2,10 +2,7 @@ use { ::alloy::primitives::U256, driver::domain::eth::NonZeroU256, e2e::{nodes::local_node::TestNodeApi, setup::*}, - ethrpc::alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy}, model::{ order::{OrderCreation, OrderKind}, quote::{OrderQuoteRequest, OrderQuoteSide, SellAmount}, @@ -88,10 +85,10 @@ async fn place_order_with_quote(web3: Web3) { assert_eq!(balance, U256::ZERO); let order = OrderCreation { quote_id: quote_response.id, - sell_token: onchain.contracts().weth.address().into_legacy(), - sell_amount: quote_sell_amount, - buy_token: token.address().into_legacy(), - buy_amount: quote_response.quote.buy_amount.into_legacy(), + sell_token: *onchain.contracts().weth.address(), + sell_amount: quote_sell_amount.into_alloy(), + buy_token: *token.address(), + buy_amount: quote_response.quote.buy_amount, valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() diff --git a/crates/e2e/tests/e2e/protocol_fee.rs b/crates/e2e/tests/e2e/protocol_fee.rs index 180345274a..05548ea2c5 100644 --- a/crates/e2e/tests/e2e/protocol_fee.rs +++ b/crates/e2e/tests/e2e/protocol_fee.rs @@ -188,11 +188,9 @@ async fn combined_protocol_fees(web3: Web3) { .expect("Expected exactly four elements"); let market_price_improvement_order = OrderCreation { - sell_amount, + sell_amount: sell_amount.into_alloy(), // to make sure the order is in-market - buy_amount: (market_quote_before.quote.buy_amount * AlloyU256::from(2) - / AlloyU256::from(3)) - .into_legacy(), + buy_amount: market_quote_before.quote.buy_amount * AlloyU256::from(2) / AlloyU256::from(3), ..sell_order_from_quote(&market_quote_before) } .sign( @@ -201,10 +199,9 @@ async fn combined_protocol_fees(web3: Web3) { SecretKeyRef::from(&SecretKey::from_slice(trader.private_key()).unwrap()), ); let limit_surplus_order = OrderCreation { - sell_amount, + sell_amount: sell_amount.into_alloy(), // to make sure the order is out-of-market - buy_amount: (limit_quote_before.quote.buy_amount * AlloyU256::from(3) / AlloyU256::from(2)) - .into_legacy(), + buy_amount: limit_quote_before.quote.buy_amount * AlloyU256::from(3) / AlloyU256::from(2), ..sell_order_from_quote(&limit_quote_before) } .sign( @@ -213,10 +210,9 @@ async fn combined_protocol_fees(web3: Web3) { SecretKeyRef::from(&SecretKey::from_slice(trader.private_key()).unwrap()), ); let partner_fee_order = OrderCreation { - sell_amount, + sell_amount: sell_amount.into_alloy(), // to make sure the order is out-of-market - buy_amount: (partner_fee_quote.quote.buy_amount * AlloyU256::from(3) / AlloyU256::from(2)) - .into_legacy(), + buy_amount: (partner_fee_quote.quote.buy_amount * AlloyU256::from(3) / AlloyU256::from(2)), app_data: partner_fee_app_data.clone(), ..sell_order_from_quote(&partner_fee_quote) } @@ -515,11 +511,11 @@ async fn surplus_partner_fee(web3: Web3) { .await; let order = OrderCreation { - sell_amount: to_wei(10), - sell_token: onchain.contracts().weth.address().into_legacy(), + sell_amount: eth(10), + sell_token: *onchain.contracts().weth.address(), // just set any low amount since it doesn't matter for this test - buy_amount: to_wei(1), - buy_token: token.address().into_legacy(), + buy_amount: eth(1), + buy_token: *token.address(), app_data: partner_fee_app_data.clone(), valid_to: model::time::now_in_epoch_seconds() + 300, ..Default::default() @@ -637,10 +633,10 @@ fn fee_in_buy_token(order: &Order, quote: &OrderQuote) -> U256 { fn sell_order_from_quote(quote: &OrderQuoteResponse) -> OrderCreation { OrderCreation { - sell_token: quote.quote.sell_token.into_legacy(), - sell_amount: quote.quote.sell_amount.into_legacy(), - buy_token: quote.quote.buy_token.into_legacy(), - buy_amount: quote.quote.buy_amount.into_legacy(), + sell_token: quote.quote.sell_token, + sell_amount: quote.quote.sell_amount, + buy_token: quote.quote.buy_token, + buy_amount: quote.quote.buy_amount, valid_to: quote.quote.valid_to, kind: OrderKind::Sell, quote_id: quote.id, @@ -762,10 +758,10 @@ async fn volume_fee_buy_order_test(web3: Web3) { .quote; let order = OrderCreation { - sell_token: token_gno.address().into_legacy(), - sell_amount: (quote.sell_amount * AlloyU256::from(3) / AlloyU256::from(2)).into_legacy(), - buy_token: token_dai.address().into_legacy(), - buy_amount: to_wei(5), + sell_token: *token_gno.address(), + sell_amount: (quote.sell_amount * AlloyU256::from(3) / AlloyU256::from(2)), + buy_token: *token_dai.address(), + buy_amount: eth(5), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Buy, ..Default::default() @@ -917,10 +913,10 @@ async fn volume_fee_buy_order_upcoming_future_test(web3: Web3) { .quote; let order = OrderCreation { - sell_token: token_gno.address().into_legacy(), - sell_amount: (quote.sell_amount * AlloyU256::from(3) / AlloyU256::from(2)).into_legacy(), - buy_token: token_dai.address().into_legacy(), - buy_amount: to_wei(5), + sell_token: *token_gno.address(), + sell_amount: (quote.sell_amount * AlloyU256::from(3) / AlloyU256::from(2)), + buy_token: *token_dai.address(), + buy_amount: eth(5), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Buy, ..Default::default() diff --git a/crates/e2e/tests/e2e/quote_verification.rs b/crates/e2e/tests/e2e/quote_verification.rs index 329280e63b..2839af1c30 100644 --- a/crates/e2e/tests/e2e/quote_verification.rs +++ b/crates/e2e/tests/e2e/quote_verification.rs @@ -1,14 +1,14 @@ use { - ::alloy::primitives::{Address, U256, address}, + ::alloy::{ + primitives::{Address, U256, address}, + providers::Provider, + }, bigdecimal::{BigDecimal, Zero}, e2e::setup::{eth, *}, ethcontract::H160, ethrpc::{ Web3, - alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + alloy::{CallBuilderExt, conversions::IntoAlloy}, }, model::{ interaction::InteractionData, @@ -423,8 +423,8 @@ async fn verified_quote_with_simulated_balance(web3: Web3) { assert!( onchain .web3() - .eth() - .balance(trader.address().into_legacy(), None) + .alloy + .get_balance(trader.address()) .await .unwrap() .is_zero() diff --git a/crates/e2e/tests/e2e/quoting.rs b/crates/e2e/tests/e2e/quoting.rs index 84ebc3776a..da2cd9a3e1 100644 --- a/crates/e2e/tests/e2e/quoting.rs +++ b/crates/e2e/tests/e2e/quoting.rs @@ -1,9 +1,6 @@ use { e2e::setup::{colocation::SolverEngine, eth, mock::Mock, *}, - ethrpc::alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy}, futures::FutureExt, model::{ order::{OrderCreation, OrderCreationAppData, OrderKind}, @@ -291,14 +288,14 @@ async fn quote_timeout(web3: Web3) { name: "test_solver".into(), account: solver.clone(), endpoint: mock_solver.url.clone(), - base_tokens: vec![sell_token.address().into_legacy()], + base_tokens: vec![*sell_token.address()], merge_solutions: true, }, SolverEngine { name: "test_quoter".into(), account: solver.clone(), endpoint: mock_solver.url.clone(), - base_tokens: vec![sell_token.address().into_legacy()], + base_tokens: vec![*sell_token.address()], merge_solutions: true, }, ], @@ -354,9 +351,7 @@ async fn quote_timeout(web3: Web3) { // native token price requests are also capped to the max timeout let start = std::time::Instant::now(); - let res = services - .get_native_price(&sell_token.address().into_legacy()) - .await; + let res = services.get_native_price(sell_token.address()).await; assert!(res.unwrap_err().1.contains("NoLiquidity")); assert_within_variance(start, MAX_QUOTE_TIME_MS); @@ -395,10 +390,10 @@ async fn quote_timeout(web3: Web3) { .unwrap(); let order = OrderCreation { - sell_token: sell_token.address().into_legacy(), - sell_amount: to_wei(1), + sell_token: *sell_token.address(), + sell_amount: eth(1), buy_token: Default::default(), - buy_amount: to_wei(1), + buy_amount: eth(1), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, partially_fillable: true, diff --git a/crates/e2e/tests/e2e/replace_order.rs b/crates/e2e/tests/e2e/replace_order.rs index 719b551c32..acfb65a3f5 100644 --- a/crates/e2e/tests/e2e/replace_order.rs +++ b/crates/e2e/tests/e2e/replace_order.rs @@ -4,10 +4,7 @@ use { nodes::local_node::TestNodeApi, setup::{eth, *}, }, - ethrpc::alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy}, model::{ order::{OrderCreation, OrderCreationAppData, OrderKind, OrderStatus}, signature::EcdsaSigningScheme, @@ -116,10 +113,10 @@ async fn try_replace_unreplaceable_order_test(web3: Web3) { services.start_protocol(solver).await; let order = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(10), - buy_token: token_b.address().into_legacy(), - buy_amount: to_wei(5), + sell_token: *token_a.address(), + sell_amount: eth(10), + buy_token: *token_b.address(), + buy_amount: eth(5), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -147,10 +144,10 @@ async fn try_replace_unreplaceable_order_test(web3: Web3) { // Replace order let new_order = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(3), - buy_token: token_b.address().into_legacy(), - buy_amount: to_wei(1), + sell_token: *token_a.address(), + sell_amount: eth(3), + buy_token: *token_b.address(), + buy_amount: eth(1), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, partially_fillable: false, @@ -292,10 +289,10 @@ async fn try_replace_someone_else_order_test(web3: Web3) { onchain.mint_block().await; let order = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(10), - buy_token: token_b.address().into_legacy(), - buy_amount: to_wei(5), + sell_token: *token_a.address(), + sell_amount: eth(10), + buy_token: *token_b.address(), + buy_amount: eth(5), valid_to: model::time::now_in_epoch_seconds() + 300, partially_fillable: false, kind: OrderKind::Sell, @@ -310,10 +307,10 @@ async fn try_replace_someone_else_order_test(web3: Web3) { // Replace order let new_order = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(3), - buy_token: token_b.address().into_legacy(), - buy_amount: to_wei(1), + sell_token: *token_a.address(), + sell_amount: eth(3), + buy_token: *token_b.address(), + buy_amount: eth(1), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, partially_fillable: false, @@ -429,10 +426,10 @@ async fn single_replace_order_test(web3: Web3) { let balance_before = token_a.balanceOf(trader.address()).call().await.unwrap(); let order = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(10), - buy_token: token_b.address().into_legacy(), - buy_amount: to_wei(5), + sell_token: *token_a.address(), + sell_amount: eth(10), + buy_token: *token_b.address(), + buy_amount: eth(5), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -458,10 +455,10 @@ async fn single_replace_order_test(web3: Web3) { // Replace order let new_order = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(3), - buy_token: token_b.address().into_legacy(), - buy_amount: to_wei(1), + sell_token: *token_a.address(), + sell_amount: eth(3), + buy_token: *token_b.address(), + buy_amount: eth(1), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, partially_fillable: false, diff --git a/crates/e2e/tests/e2e/smart_contract_orders.rs b/crates/e2e/tests/e2e/smart_contract_orders.rs index 0e238e7575..f8bbc598fc 100644 --- a/crates/e2e/tests/e2e/smart_contract_orders.rs +++ b/crates/e2e/tests/e2e/smart_contract_orders.rs @@ -1,10 +1,8 @@ use { + ::alloy::primitives::Address, e2e::setup::{eth, safe::Safe, *}, - ethcontract::{H160, U256}, - ethrpc::alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + ethcontract::U256, + ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy}, model::{ order::{OrderCreation, OrderCreationAppData, OrderKind, OrderStatus, OrderUid}, signature::Signature, @@ -51,10 +49,10 @@ async fn smart_contract_orders(web3: Web3) { let order_template = OrderCreation { kind: OrderKind::Sell, - sell_token: token.address().into_legacy(), - sell_amount: to_wei(5), - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: to_wei(3), + sell_token: *token.address(), + sell_amount: eth(5), + buy_token: *onchain.contracts().weth.address(), + buy_amount: eth(3), valid_to: model::time::now_in_epoch_seconds() + 300, ..Default::default() }; @@ -63,12 +61,12 @@ async fn smart_contract_orders(web3: Web3) { // Check that we can't place invalid orders. let orders = [ OrderCreation { - from: Some(safe.address().into_legacy()), + from: Some(safe.address()), signature: Signature::Eip1271(b"invalid signature".to_vec()), ..order_template.clone() }, OrderCreation { - from: Some(H160(*b"invalid address\0\0\0\0\0")), + from: Some(Address::new(*b"invalid address\0\0\0\0\0")), signature: Signature::Eip1271(signature1271.clone()), ..order_template.clone() }, @@ -81,7 +79,7 @@ async fn smart_contract_orders(web3: Web3) { // Place orders let orders = [ OrderCreation { - from: Some(safe.address().into_legacy()), + from: Some(safe.address()), signature: Signature::Eip1271(signature1271), ..order_template.clone() }, @@ -89,7 +87,7 @@ async fn smart_contract_orders(web3: Web3) { app_data: OrderCreationAppData::Full { full: "{\"salt\": \"second\"}".to_string(), }, - from: Some(safe.address().into_legacy()), + from: Some(safe.address()), signature: Signature::PreSign, ..order_template.clone() }, @@ -194,14 +192,14 @@ async fn erc1271_gas_limit(web3: Web3) { U256::exp10(6).to_big_endian(&mut signature); let order = OrderCreation { - sell_token: cow.address().into_legacy(), - sell_amount: to_wei(4), - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: to_wei(3), + sell_token: *cow.address(), + sell_amount: eth(4), + buy_token: *onchain.contracts().weth.address(), + buy_amount: eth(3), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, signature: Signature::Eip1271(signature.to_vec()), - from: Some(trader.address().into_legacy()), + from: Some(*trader.address()), ..Default::default() }; diff --git a/crates/e2e/tests/e2e/solver_competition.rs b/crates/e2e/tests/e2e/solver_competition.rs index 351862cd39..ceed182fc9 100644 --- a/crates/e2e/tests/e2e/solver_competition.rs +++ b/crates/e2e/tests/e2e/solver_competition.rs @@ -98,10 +98,10 @@ async fn solver_competition(web3: Web3) { // Place Order let order = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(10), - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: to_wei(5), + sell_token: *token_a.address(), + sell_amount: eth(10), + buy_token: *onchain.contracts().weth.address(), + buy_amount: eth(5), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -204,7 +204,7 @@ async fn wrong_solution_submission_address(web3: Web3) { "test_solver".into(), solver.clone(), *onchain.contracts().weth.address(), - vec![base_a.address().into_legacy()], + vec![*base_a.address()], 1, true, ) @@ -213,7 +213,7 @@ async fn wrong_solution_submission_address(web3: Web3) { "solver2".into(), solver.clone(), *onchain.contracts().weth.address(), - vec![base_b.address().into_legacy()], + vec![*base_b.address()], 1, true, ) @@ -240,10 +240,10 @@ async fn wrong_solution_submission_address(web3: Web3) { // Place Orders let order_a = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(10), - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: to_wei(5), + sell_token: *token_a.address(), + sell_amount: eth(10), + buy_token: *onchain.contracts().weth.address(), + buy_amount: eth(5), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -258,10 +258,10 @@ async fn wrong_solution_submission_address(web3: Web3) { onchain.mint_block().await; let order_b = OrderCreation { - sell_token: token_b.address().into_legacy(), - sell_amount: to_wei(10), - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: to_wei(5), + sell_token: *token_b.address(), + sell_amount: eth(10), + buy_token: *onchain.contracts().weth.address(), + buy_amount: eth(5), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -334,11 +334,7 @@ async fn store_filtered_solutions(web3: Web3) { let bad_solver = Mock::default(); // Start system - let base_tokens = vec![ - token_a.address().into_legacy(), - token_b.address().into_legacy(), - token_c.address().into_legacy(), - ]; + let base_tokens = vec![*token_a.address(), *token_b.address(), *token_c.address()]; colocation::start_driver( onchain.contracts(), vec![ @@ -395,10 +391,10 @@ async fn store_filtered_solutions(web3: Web3) { // Place order let order_ab = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(1), - buy_token: token_b.address().into_legacy(), - buy_amount: to_wei(1), + sell_token: *token_a.address(), + sell_amount: eth(1), + buy_token: *token_b.address(), + buy_amount: eth(1), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -410,10 +406,10 @@ async fn store_filtered_solutions(web3: Web3) { ); let order_ac = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(1), - buy_token: token_c.address().into_legacy(), - buy_amount: to_wei(1), + sell_token: *token_a.address(), + sell_amount: eth(1), + buy_token: *token_c.address(), + buy_amount: eth(1), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() @@ -445,7 +441,7 @@ async fn store_filtered_solutions(web3: Web3) { ]), trades: vec![solvers_dto::solution::Trade::Fulfillment( solvers_dto::solution::Fulfillment { - executed_amount: order_ab.sell_amount, + executed_amount: order_ab.sell_amount.into_legacy(), fee: Some(0.into()), order: solvers_dto::solution::OrderUid(order_ab_id.0), }, @@ -470,12 +466,12 @@ async fn store_filtered_solutions(web3: Web3) { ]), trades: vec![ solvers_dto::solution::Trade::Fulfillment(solvers_dto::solution::Fulfillment { - executed_amount: order_ab.sell_amount, + executed_amount: order_ab.sell_amount.into_legacy(), fee: Some(0.into()), order: solvers_dto::solution::OrderUid(order_ab_id.0), }), solvers_dto::solution::Trade::Fulfillment(solvers_dto::solution::Fulfillment { - executed_amount: order_ac.sell_amount, + executed_amount: order_ac.sell_amount.into_legacy(), fee: Some(0.into()), order: solvers_dto::solution::OrderUid(order_ac_id.0), }), diff --git a/crates/e2e/tests/e2e/solver_participation_guard.rs b/crates/e2e/tests/e2e/solver_participation_guard.rs index 9898443166..24e23463a2 100644 --- a/crates/e2e/tests/e2e/solver_participation_guard.rs +++ b/crates/e2e/tests/e2e/solver_participation_guard.rs @@ -1,5 +1,5 @@ use { - alloy::primitives::U256, + alloy::primitives::{Address, U256}, e2e::setup::{ Db, ExtraServiceArgs, @@ -15,10 +15,7 @@ use { }, ethrpc::{ Web3, - alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + alloy::{CallBuilderExt, conversions::IntoAlloy}, }, model::{ order::{OrderClass, OrderCreation, OrderKind}, @@ -27,7 +24,7 @@ use { secp256k1::SecretKey, sqlx::Row, std::time::Instant, - web3::{signing::SecretKeyRef, types::H160}, + web3::signing::SecretKeyRef, }; #[tokio::test] @@ -90,7 +87,7 @@ async fn non_settling_solver(web3: Web3) { .take(3) .cloned() .collect::>(); - replace_solver_for_auction_ids(pool, &last_auctions, &solver_b.address().into_legacy()).await; + replace_solver_for_auction_ids(pool, &last_auctions, &solver_b.address()).await; // The competition still passes since the stats are updated only after a new // solution from anyone is received and stored. let now = Instant::now(); @@ -162,7 +159,7 @@ async fn low_settling_solver(web3: Web3) { .enumerate() .filter_map(|(i, id)| (i % 2 == 0).then_some(*id)) .collect::>(); - replace_solver_for_auction_ids(pool, &random_auctions, &solver_b.address().into_legacy()).await; + replace_solver_for_auction_ids(pool, &random_auctions, &solver_b.address()).await; // The competition still passes since the stats are updated only after a new // solution from anyone is received and stored. let now = Instant::now(); @@ -301,10 +298,10 @@ async fn setup( (trader_a, token_a, token_b) } -async fn replace_solver_for_auction_ids(pool: &Db, auction_ids: &[i64], solver: &H160) { +async fn replace_solver_for_auction_ids(pool: &Db, auction_ids: &[i64], solver: &Address) { for auction_id in auction_ids { sqlx::query("UPDATE settlements SET solver = $1 WHERE auction_id = $2") - .bind(solver.0) + .bind(solver.as_slice()) .bind(auction_id) .execute(pool) .await @@ -333,10 +330,10 @@ async fn execute_order( services: &Services<'_>, ) -> anyhow::Result<()> { let order = OrderCreation { - sell_token: token_a.address().into_legacy(), - sell_amount: to_wei(10), - buy_token: token_b.address().into_legacy(), - buy_amount: to_wei(5), + sell_token: *token_a.address(), + sell_amount: eth(10), + buy_token: *token_b.address(), + buy_amount: eth(5), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() diff --git a/crates/e2e/tests/e2e/submission.rs b/crates/e2e/tests/e2e/submission.rs index 60a2c63b5d..41d6f18acf 100644 --- a/crates/e2e/tests/e2e/submission.rs +++ b/crates/e2e/tests/e2e/submission.rs @@ -2,10 +2,7 @@ use { ::alloy::primitives::U256, e2e::{nodes::local_node::TestNodeApi, setup::*}, ethcontract::{BlockId, H160, H256}, - ethrpc::alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy}, futures::{Stream, StreamExt}, model::{ order::{OrderCreation, OrderKind}, @@ -65,10 +62,10 @@ async fn test_cancel_on_expiry(web3: Web3) { let balance = token.balanceOf(trader.address()).call().await.unwrap(); assert_eq!(balance, U256::ZERO); let order = OrderCreation { - sell_token: onchain.contracts().weth.address().into_legacy(), - sell_amount: to_wei(2), - buy_token: token.address().into_legacy(), - buy_amount: to_wei(1), + sell_token: *onchain.contracts().weth.address(), + sell_amount: eth(2), + buy_token: *token.address(), + buy_amount: eth(1), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Buy, ..Default::default() diff --git a/crates/e2e/tests/e2e/tracking_insufficient_funds.rs b/crates/e2e/tests/e2e/tracking_insufficient_funds.rs index eea7456e6b..686e80e5ef 100644 --- a/crates/e2e/tests/e2e/tracking_insufficient_funds.rs +++ b/crates/e2e/tests/e2e/tracking_insufficient_funds.rs @@ -1,10 +1,7 @@ use { database::order_events::{OrderEvent, OrderEventLabel}, e2e::setup::*, - ethrpc::alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy}, model::{ order::{OrderCreation, OrderKind}, signature::EcdsaSigningScheme, @@ -71,10 +68,10 @@ async fn test(web3: Web3) { tracing::info!("Placing order"); let order_a = OrderCreation { - sell_token: onchain.contracts().weth.address().into_legacy(), - sell_amount: to_wei(2), - buy_token: token.address().into_legacy(), - buy_amount: to_wei(1), + sell_token: *onchain.contracts().weth.address(), + sell_amount: eth(2), + buy_token: *token.address(), + buy_amount: eth(1), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Buy, ..Default::default() @@ -85,10 +82,10 @@ async fn test(web3: Web3) { SecretKeyRef::from(&SecretKey::from_slice(trader_a.private_key()).unwrap()), ); let order_b = OrderCreation { - sell_token: onchain.contracts().weth.address().into_legacy(), - sell_amount: to_wei(2), - buy_token: token.address().into_legacy(), - buy_amount: to_wei(1), + sell_token: *onchain.contracts().weth.address(), + sell_amount: eth(2), + buy_token: *token.address(), + buy_amount: eth(1), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Buy, ..Default::default() diff --git a/crates/e2e/tests/e2e/uncovered_order.rs b/crates/e2e/tests/e2e/uncovered_order.rs index 3159477a4f..903121a73b 100644 --- a/crates/e2e/tests/e2e/uncovered_order.rs +++ b/crates/e2e/tests/e2e/uncovered_order.rs @@ -1,9 +1,6 @@ use { e2e::setup::*, - ethrpc::alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy}, model::{ order::{OrderCreation, OrderKind}, signature::EcdsaSigningScheme, @@ -45,11 +42,11 @@ async fn test(web3: Web3) { tracing::info!("Placing order with 0 sell tokens"); let order = OrderCreation { - sell_token: weth.address().into_legacy(), - sell_amount: to_wei(2), - fee_amount: 0.into(), - buy_token: token.address().into_legacy(), - buy_amount: to_wei(1), + sell_token: *weth.address(), + sell_amount: eth(2), + fee_amount: ::alloy::primitives::U256::ZERO, + buy_token: *token.address(), + buy_amount: eth(1), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, partially_fillable: false, diff --git a/crates/e2e/tests/e2e/univ2.rs b/crates/e2e/tests/e2e/univ2.rs index f781e43ba1..ac09dfee97 100644 --- a/crates/e2e/tests/e2e/univ2.rs +++ b/crates/e2e/tests/e2e/univ2.rs @@ -3,10 +3,7 @@ use { contracts::alloy::GPv2Settlement, database::order_events::{OrderEvent, OrderEventLabel}, e2e::setup::{eth, *}, - ethrpc::alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy}, model::{ order::{OrderCreation, OrderKind}, signature::EcdsaSigningScheme, @@ -58,10 +55,10 @@ async fn test(web3: Web3) { let balance = token.balanceOf(trader.address()).call().await.unwrap(); assert_eq!(balance, U256::ZERO); let order = OrderCreation { - sell_token: onchain.contracts().weth.address().into_legacy(), - sell_amount: to_wei(2), - buy_token: token.address().into_legacy(), - buy_amount: to_wei(1), + sell_token: *onchain.contracts().weth.address(), + sell_amount: eth(2), + buy_token: *token.address(), + buy_amount: eth(1), valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Buy, ..Default::default() diff --git a/crates/e2e/tests/e2e/vault_balances.rs b/crates/e2e/tests/e2e/vault_balances.rs index 2569021e8d..b56794a168 100644 --- a/crates/e2e/tests/e2e/vault_balances.rs +++ b/crates/e2e/tests/e2e/vault_balances.rs @@ -1,9 +1,6 @@ use { e2e::setup::{eth, *}, - ethrpc::alloy::{ - CallBuilderExt, - conversions::{IntoAlloy, IntoLegacy}, - }, + ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy}, model::{ order::{OrderCreation, OrderKind, SellTokenSource}, signature::EcdsaSigningScheme, @@ -57,11 +54,11 @@ async fn vault_balances(web3: Web3) { // Place Orders let order = OrderCreation { kind: OrderKind::Sell, - sell_token: token.address().into_legacy(), - sell_amount: to_wei(10), + sell_token: *token.address(), + sell_amount: eth(10), sell_token_balance: SellTokenSource::External, - buy_token: onchain.contracts().weth.address().into_legacy(), - buy_amount: to_wei(8), + buy_token: *onchain.contracts().weth.address(), + buy_amount: eth(8), valid_to: model::time::now_in_epoch_seconds() + 300, ..Default::default() } diff --git a/crates/e2e/tests/e2e/wrapper.rs b/crates/e2e/tests/e2e/wrapper.rs index 612166664b..8a46b901cc 100644 --- a/crates/e2e/tests/e2e/wrapper.rs +++ b/crates/e2e/tests/e2e/wrapper.rs @@ -154,10 +154,10 @@ async fn forked_mainnet_wrapper_test(web3: Web3) { full: app_data.clone(), expected: app_data_hash, }, - sell_token: token_weth.address().into_legacy(), - sell_amount: to_wei(1), - buy_token: token_usdc.address().into_legacy(), - buy_amount: 1.into(), + sell_token: *token_weth.address(), + sell_amount: eth(1), + buy_token: *token_usdc.address(), + buy_amount: ::alloy::primitives::U256::ONE, valid_to: model::time::now_in_epoch_seconds() + 300, kind: OrderKind::Sell, ..Default::default() diff --git a/crates/model/src/order.rs b/crates/model/src/order.rs index e552a3f9b6..4b8344fe73 100644 --- a/crates/model/src/order.rs +++ b/crates/model/src/order.rs @@ -296,19 +296,19 @@ pub struct QuoteAmounts { pub struct OrderCreation { // These fields are the same as in `OrderData`. /// The address of the token being sold. - pub sell_token: H160, + pub sell_token: Address, /// The address of the token being bought. - pub buy_token: H160, + pub buy_token: Address, /// The receiver of the `buy_token`. When this field is `None`, the receiver /// is the same as the owner. #[serde(default)] - pub receiver: Option, + pub receiver: Option
, /// The *maximum* amount of `sell_token`s that may be sold. #[serde_as(as = "HexOrDecimalU256")] - pub sell_amount: U256, + pub sell_amount: alloy::primitives::U256, /// The *minimum* amount of `buy_token`s that should be bought. #[serde_as(as = "HexOrDecimalU256")] - pub buy_amount: U256, + pub buy_amount: alloy::primitives::U256, /// The block timestamp when the order can no longer be settled (UNIX /// timestamp in seconds). pub valid_to: u32, @@ -318,7 +318,7 @@ pub struct OrderCreation { /// /// Deprecation note: orders with a non-zero `fee_amount` should be rejected /// by the API. - pub fee_amount: U256, + pub fee_amount: alloy::primitives::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 @@ -336,7 +336,7 @@ pub struct OrderCreation { /// /// In the EthFlow case, it will have the address of the EthFlow smart /// contract. - pub from: Option, + pub from: Option
, /// The owner's signature of the order's data. #[serde(flatten)] pub signature: Signature, @@ -351,24 +351,15 @@ impl OrderCreation { /// Returns the order's data — i.e. the [`OrderCreation`] without /// the metadata: `signature`, `quote_id` and with the `app_data`'s hash. pub fn data(&self) -> OrderData { - let mut sell_amount_buffer = [0; 32]; - self.sell_amount.to_big_endian(&mut sell_amount_buffer); - - let mut buy_amount_buffer = [0; 32]; - self.buy_amount.to_big_endian(&mut buy_amount_buffer); - - let mut fee_amount_buffer = [0; 32]; - self.fee_amount.to_big_endian(&mut fee_amount_buffer); - OrderData { - sell_token: Address::new(self.sell_token.0), - buy_token: Address::new(self.buy_token.0), - receiver: self.receiver.map(|receiver| Address::new(receiver.0)), - sell_amount: alloy::primitives::U256::from_be_slice(&sell_amount_buffer), - buy_amount: alloy::primitives::U256::from_be_slice(&buy_amount_buffer), + sell_token: self.sell_token, + buy_token: self.buy_token, + receiver: self.receiver, + sell_amount: self.sell_amount, + buy_amount: self.buy_amount, valid_to: self.valid_to, app_data: self.app_data.hash(), - fee_amount: alloy::primitives::U256::from_be_slice(&fee_amount_buffer), + fee_amount: self.fee_amount, kind: self.kind, partially_fillable: self.partially_fillable, sell_token_balance: self.sell_token_balance, @@ -405,8 +396,8 @@ impl OrderCreation { pub fn verify_owner( &self, domain: &DomainSeparator, - app_data_signer: Option, - ) -> Result { + app_data_signer: Option
, + ) -> Result { let recovered = self .signature .recover(domain, &self.data().hash_struct()) @@ -496,8 +487,8 @@ impl OrderCreationAppData { #[derive(Debug)] pub struct AppdataFromMismatch { - pub from: H160, - pub app_data_signer: H160, + pub from: Address, + pub app_data_signer: Address, } #[derive(Debug)] @@ -547,7 +538,7 @@ pub struct SignedOrderCancellations { } impl SignedOrderCancellations { - pub fn validate(&self, domain_separator: &DomainSeparator) -> Result { + pub fn validate(&self, domain_separator: &DomainSeparator) -> Result
{ Ok(self .signature .recover( @@ -614,7 +605,7 @@ impl OrderCancellation { signing::keccak256(&hash_data) } - pub fn validate(&self, domain_separator: &DomainSeparator) -> Result { + pub fn validate(&self, domain_separator: &DomainSeparator) -> Result
{ Ok(self .signature .recover(self.signing_scheme, domain_separator, &self.hash_struct())? @@ -1072,6 +1063,7 @@ mod tests { use { super::*, crate::signature::{EcdsaSigningScheme, SigningScheme}, + alloy::primitives::address, chrono::TimeZone, hex_literal::hex, maplit::hashset, @@ -1178,7 +1170,7 @@ mod tests { #[test] fn order_creation_serialization() { - let owner = H160([0xff; 20]); + let owner = Address::repeat_byte(0xff); for (signature, signing_scheme, from, signature_bytes) in [ ( Signature::default_with(SigningScheme::Eip712), @@ -1199,16 +1191,16 @@ mod tests { (Signature::PreSign, "presign", Some(owner), "0x"), ] { let order = OrderCreation { - sell_token: H160([0x11; 20]), - buy_token: H160([0x22; 20]), - receiver: Some(H160([0x33; 20])), - sell_amount: 123.into(), - buy_amount: 456.into(), + 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), valid_to: 1337, app_data: OrderCreationAppData::Hash { hash: AppDataHash([0x44; 32]), }, - fee_amount: 789.into(), + fee_amount: alloy::primitives::U256::from(789), kind: OrderKind::Sell, partially_fillable: false, sell_token_balance: SellTokenSource::Erc20, @@ -1292,7 +1284,7 @@ mod tests { let domain_separator = DomainSeparator(hex!( "74e0b11bd18120612556bae4578cfd3a254d7e2495f543c569a92ff5794d9b09" )); - let expected_owner = H160(hex!("70997970C51812dc3A010C7d01b50e0d17dc79C8")); + let expected_owner = address!("70997970C51812dc3A010C7d01b50e0d17dc79C8"); for (signing_scheme, signature) in &[ ( @@ -1379,7 +1371,7 @@ mod tests { "f8a1143d44c67470a791201b239ff6b0ecc8910aa9682bebd08145f5fd84722b" )); - let expected_owner = H160(hex!("f39Fd6e51aad88F6F4ce6aB8827279cffFb92266")); + let expected_owner = address!("f39Fd6e51aad88F6F4ce6aB8827279cffFb92266"); let eip712_signature = hex!( "f2c69310a4dbcd78feabfd802df296ca4650681e01872f667251916ed3e9a2e14928382316607594a77c620e4bc4536e6fe145ee993a5ccc38fda929e86830231b" @@ -1469,7 +1461,10 @@ mod tests { .unwrap() .unwrap(); - assert_eq!(recovered.signer, h160_from_public_key(public_key)); + assert_eq!( + recovered.signer, + Address::new(h160_from_public_key(public_key).0) + ); } #[test] diff --git a/crates/model/src/signature.rs b/crates/model/src/signature.rs index f7243a6632..040b9034b3 100644 --- a/crates/model/src/signature.rs +++ b/crates/model/src/signature.rs @@ -1,8 +1,8 @@ use { crate::{DomainSeparator, quote::QuoteSigningScheme}, - alloy::primitives::B256, + alloy::primitives::{Address, B256}, anyhow::{Context as _, Result, ensure}, - primitive_types::{H160, H256}, + primitive_types::H160, serde::{Deserialize, Serialize, de}, std::{ convert::TryInto as _, @@ -174,7 +174,7 @@ impl Signature { signature: &[u8], domain_separator: &DomainSeparator, struct_hash: &[u8; 32], - ) -> Result { + ) -> Result
{ match self { Self::Eip712(_) | Self::EthSign(_) => { let recovered = self @@ -183,8 +183,8 @@ impl Signature { .context("unreachable?")?; Ok(recovered.signer) } - Self::Eip1271(_) => Ok(H160::from_slice(&signature[..20])), - Self::PreSign => Ok(H160::from_slice(signature)), + Self::Eip1271(_) => Ok(Address::from_slice(&signature[..20])), + Self::PreSign => Ok(Address::from_slice(signature)), } } } @@ -194,10 +194,10 @@ impl Signature { pub struct Recovered { /// The signing message that was used for recovery. The actual value of this /// message depends on the singing scheme used. - pub message: H256, + pub message: B256, /// The recovered signer address. - pub signer: H160, + pub signer: Address, } /// An internal type used for deriving `serde` implementations for the @@ -332,10 +332,10 @@ impl EcdsaSignature { let (signature, recovery_id) = recovery .as_signature() .context("unexpectedly invalid signature")?; - let signer = signing::recover(&message, &signature, recovery_id)?; + let signer = Address::new(signing::recover(&message, &signature, recovery_id)?.0); Ok(Recovered { - message: H256(message), + message: message.into(), signer, }) } diff --git a/crates/orderbook/src/orderbook.rs b/crates/orderbook/src/orderbook.rs index 0e20eed8cf..ba04ead735 100644 --- a/crates/orderbook/src/orderbook.rs +++ b/crates/orderbook/src/orderbook.rs @@ -348,10 +348,7 @@ impl Orderbook { let signer = cancellation .validate(&self.domain_separator) .map_err(|_| OrderCancellationError::InvalidSignature)?; - if orders - .iter() - .any(|order| signer != order.metadata.owner.into_legacy()) - { + if orders.iter().any(|order| signer != order.metadata.owner) { return Err(OrderCancellationError::WrongOwner); }; @@ -381,7 +378,7 @@ impl Orderbook { let signer = cancellation .validate(&self.domain_separator) .map_err(|_| OrderCancellationError::InvalidSignature)?; - if signer != order.metadata.owner.into_legacy() { + if signer != order.metadata.owner { return Err(OrderCancellationError::WrongOwner); }; @@ -634,8 +631,6 @@ mod tests { use { super::*, crate::database::orders::MockOrderStoring, - ethcontract::H160, - ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy}, mockall::predicate::eq, model::{ order::{OrderData, OrderMetadata}, @@ -678,7 +673,7 @@ mod tests { Ok(( Order { metadata: OrderMetadata { - owner: creation.from.unwrap().into_alloy(), + owner: creation.from.unwrap(), uid: new_order_uid, ..Default::default() }, @@ -714,7 +709,7 @@ mod tests { assert!(matches!( orderbook .add_order(OrderCreation { - from: Some(H160([2; 20])), + from: Some(Address::repeat_byte(2)), signature: Signature::Eip712(Default::default()), app_data: OrderCreationAppData::Full { full: format!( @@ -734,7 +729,7 @@ mod tests { assert!(matches!( orderbook .add_order(OrderCreation { - from: Some(H160([2; 20])), + from: Some(Address::repeat_byte(2)), signature: Signature::Eip712(Default::default()), app_data: OrderCreationAppData::Full { full: format!( @@ -754,7 +749,7 @@ mod tests { assert!(matches!( orderbook .add_order(OrderCreation { - from: Some(old_order.metadata.owner.into_legacy()), + from: Some(old_order.metadata.owner), signature: Signature::PreSign, app_data: OrderCreationAppData::Full { full: format!( @@ -773,7 +768,7 @@ mod tests { // Stars align... let (order_id, _) = orderbook .add_order(OrderCreation { - from: Some(old_order.metadata.owner.into_legacy()), + from: Some(old_order.metadata.owner), signature: Signature::Eip712(Default::default()), app_data: OrderCreationAppData::Full { full: format!( diff --git a/crates/shared/src/order_validation.rs b/crates/shared/src/order_validation.rs index 7ab7aa6455..06ae4d5469 100644 --- a/crates/shared/src/order_validation.rs +++ b/crates/shared/src/order_validation.rs @@ -577,14 +577,14 @@ impl OrderValidating for OrderValidator { let app_data = self.validate_app_data(&order.app_data, &full_app_data_override)?; let app_data_signer = app_data.inner.protocol.signer.map(IntoLegacy::into_legacy); - let owner = order.verify_owner(domain_separator, app_data_signer)?; + let owner = order.verify_owner(domain_separator, app_data_signer.map(IntoAlloy::into_alloy))?; tracing::debug!(?owner, "recovered owner from order and signature"); let signing_scheme = order.signature.scheme(); let data = OrderData { app_data: app_data.inner.hash, ..order.data() }; - let uid = data.uid(domain_separator, &owner); + let uid = data.uid(domain_separator, &owner.into_legacy()); let verification_gas_limit = if let Signature::Eip1271(signature) = &order.signature { if self.eip1271_skip_creation_validation { @@ -595,7 +595,7 @@ impl OrderValidating for OrderValidator { let hash = hashed_eip712_message(domain_separator, &data.hash_struct()); self.signature_validator .validate_signature_and_get_additional_gas(SignatureCheck { - signer: owner, + signer: owner.into_legacy(), hash, signature: signature.to_owned(), interactions: app_data.interactions.pre.clone(), @@ -625,15 +625,15 @@ impl OrderValidating for OrderValidator { } let pre_order = - PreOrderData::from_order_creation(owner.into_alloy(), &data, signing_scheme); + PreOrderData::from_order_creation(owner, &data, signing_scheme); let class = pre_order.class; self.partial_validate(pre_order) .await .map_err(ValidationError::Partial)?; let verification = Verification { - from: owner.into_alloy(), - receiver: order.receiver.unwrap_or(owner).into_alloy(), + from: owner, + receiver: order.receiver.unwrap_or(owner), sell_token_source: order.sell_token_balance, buy_token_destination: order.buy_token_balance, pre_interactions: trade_finding::map_interactions(&app_data.interactions.pre), @@ -657,7 +657,7 @@ impl OrderValidating for OrderValidator { verification, }; - self.ensure_token_is_transferable(&order, owner, &app_data) + self.ensure_token_is_transferable(&order, owner.into_legacy(), &app_data) .await?; // Check if we need to re-classify the market order if it is outside the market @@ -722,7 +722,7 @@ impl OrderValidating for OrderValidator { }, data.kind, ) { - self.check_max_limit_orders(owner.into_alloy()).await?; + self.check_max_limit_orders(owner).await?; } (class, Some(quote)) } @@ -753,7 +753,7 @@ impl OrderValidating for OrderValidator { }, data.kind, ) { - self.check_max_limit_orders(owner.into_alloy()).await?; + self.check_max_limit_orders(owner).await?; } (OrderClass::Limit, None) } @@ -769,7 +769,7 @@ impl OrderValidating for OrderValidator { let order = Order { metadata: OrderMetadata { - owner: owner.into_alloy(), + owner: owner, creation_date: chrono::offset::Utc::now(), uid, settlement_contract: settlement_contract.into_alloy(), @@ -1369,11 +1369,11 @@ mod tests { let creation = OrderCreation { valid_to: time::now_in_epoch_seconds() + 2, - sell_token: H160::from_low_u64_be(1), - buy_token: H160::from_low_u64_be(2), - buy_amount: U256::from(1), - sell_amount: U256::from(1), - fee_amount: U256::from(0), + sell_token: Address::with_last_byte(1), + buy_token: Address::with_last_byte(2), + buy_amount: alloy::primitives::U256::from(1), + sell_amount: alloy::primitives::U256::from(1), + fee_amount: alloy::primitives::U256::from(0), signature: Signature::Eip712(EcdsaSignature::non_zero()), app_data: OrderCreationAppData::Full { full: "{}".to_string(), @@ -1392,7 +1392,7 @@ mod tests { let domain_separator = DomainSeparator::default(); let creation = OrderCreation { - from: Some(H160([1; 20])), + from: Some(Address::repeat_byte(1)), signature: Signature::Eip1271(vec![1, 2, 3]), app_data: OrderCreationAppData::Full { full: json!({ @@ -1440,7 +1440,7 @@ mod tests { signature_validator .expect_validate_signature_and_get_additional_gas() .with(eq(SignatureCheck { - signer: creation.from.unwrap(), + signer: creation.from.unwrap().into_legacy(), hash: order_hash, signature: vec![1, 2, 3], interactions: pre_interactions.clone(), @@ -1469,7 +1469,7 @@ mod tests { signature_validator .expect_validate_signature_and_get_additional_gas() .with(eq(SignatureCheck { - signer: creation.from.unwrap(), + signer: creation.from.unwrap().into_legacy(), hash: order_hash, signature: vec![1, 2, 3], interactions: pre_interactions.clone(), @@ -1496,7 +1496,7 @@ mod tests { ); let creation_ = OrderCreation { - fee_amount: U256::zero(), + fee_amount: alloy::primitives::U256::ZERO, ..creation.clone() }; let (order, _) = validator @@ -1507,7 +1507,7 @@ mod tests { assert!(order.metadata.class.is_limit()); let creation_ = OrderCreation { - fee_amount: U256::zero(), + fee_amount: alloy::primitives::U256::ZERO, partially_fillable: true, app_data: OrderCreationAppData::Full { full: "{}".to_string(), @@ -1585,10 +1585,10 @@ mod tests { let creation = OrderCreation { valid_to: model::time::now_in_epoch_seconds() + 2, - sell_token: H160::from_low_u64_be(1), - buy_token: H160::from_low_u64_be(2), - buy_amount: U256::from(10), - sell_amount: U256::from(1), + sell_token: Address::with_last_byte(1), + buy_token: Address::with_last_byte(2), + buy_amount: alloy::primitives::U256::from(10), + sell_amount: alloy::primitives::U256::from(1), signature: Signature::Eip712(EcdsaSignature::non_zero()), app_data: OrderCreationAppData::Full { full: "{}".to_string(), @@ -1662,10 +1662,10 @@ mod tests { let creation = OrderCreation { valid_to: model::time::now_in_epoch_seconds() + 2, - sell_token: H160::from_low_u64_be(1), - buy_token: H160::from_low_u64_be(2), - buy_amount: U256::from(1), - sell_amount: U256::from(1), + sell_token: Address::with_last_byte(1), + buy_token: Address::with_last_byte(2), + buy_amount: alloy::primitives::U256::from(1), + sell_amount: alloy::primitives::U256::from(1), signature: Signature::Eip712(EcdsaSignature::non_zero()), app_data: OrderCreationAppData::Full { full: "{}".to_string(), @@ -1725,11 +1725,11 @@ mod tests { ); let order = OrderCreation { valid_to: time::now_in_epoch_seconds() + 2, - sell_token: H160::from_low_u64_be(1), - buy_token: H160::from_low_u64_be(2), - buy_amount: U256::from(0), - sell_amount: U256::from(0), - fee_amount: U256::from(1), + sell_token: Address::with_last_byte(1), + buy_token: Address::with_last_byte(2), + buy_amount: alloy::primitives::U256::from(0), + sell_amount: alloy::primitives::U256::from(0), + fee_amount: alloy::primitives::U256::from(1), signature: Signature::Eip712(EcdsaSignature::non_zero()), app_data: OrderCreationAppData::Full { full: "{}".to_string(), @@ -1782,11 +1782,11 @@ mod tests { ); let order = OrderCreation { valid_to: time::now_in_epoch_seconds() + 2, - sell_token: H160::from_low_u64_be(1), - buy_token: H160::from_low_u64_be(2), - buy_amount: U256::from(1), - sell_amount: U256::from(1), - fee_amount: U256::from(1), + sell_token: Address::with_last_byte(1), + buy_token: Address::with_last_byte(2), + buy_amount: alloy::primitives::U256::from(1), + sell_amount: alloy::primitives::U256::from(1), + fee_amount: alloy::primitives::U256::from(1), from: Some(Default::default()), signature: Signature::Eip712(EcdsaSignature::non_zero()), app_data: OrderCreationAppData::Full { @@ -1842,11 +1842,11 @@ mod tests { ); let order = OrderCreation { valid_to: time::now_in_epoch_seconds() + 2, - sell_token: H160::from_low_u64_be(1), - buy_token: H160::from_low_u64_be(2), - buy_amount: U256::from(1), - sell_amount: U256::from(1), - fee_amount: U256::from(1), + sell_token: Address::with_last_byte(1), + buy_token: Address::with_last_byte(2), + buy_amount: alloy::primitives::U256::from(1), + sell_amount: alloy::primitives::U256::from(1), + fee_amount: alloy::primitives::U256::from(1), signature: Signature::Eip712(EcdsaSignature::non_zero()), app_data: OrderCreationAppData::Full { full: "{}".to_string(), @@ -1905,11 +1905,11 @@ mod tests { ); let order = OrderCreation { valid_to: time::now_in_epoch_seconds() + 2, - sell_token: H160::from_low_u64_be(1), - buy_token: H160::from_low_u64_be(2), - buy_amount: U256::from(1), - sell_amount: U256::from(1), - fee_amount: U256::from(1), + sell_token: Address::with_last_byte(1), + buy_token: Address::with_last_byte(2), + buy_amount: alloy::primitives::U256::from(1), + sell_amount: alloy::primitives::U256::from(1), + fee_amount: alloy::primitives::U256::from(1), signature: Signature::Eip712(EcdsaSignature::non_zero()), app_data: OrderCreationAppData::Full { full: "{}".to_string(), @@ -1968,12 +1968,12 @@ mod tests { let creation = OrderCreation { valid_to: time::now_in_epoch_seconds() + 2, - sell_token: H160::from_low_u64_be(1), - buy_token: H160::from_low_u64_be(2), - buy_amount: U256::from(1), - sell_amount: U256::from(1), - fee_amount: U256::from(1), - from: Some(H160([1; 20])), + sell_token: Address::with_last_byte(1), + buy_token: Address::with_last_byte(2), + buy_amount: alloy::primitives::U256::from(1), + sell_amount: alloy::primitives::U256::from(1), + fee_amount: alloy::primitives::U256::from(1), + from: Some(Address::repeat_byte(1)), signature: Signature::Eip1271(vec![1, 2, 3]), app_data: OrderCreationAppData::Full { full: "{}".to_string(), @@ -2037,10 +2037,10 @@ mod tests { let order = OrderCreation { valid_to: u32::MAX, - sell_token: H160::from_low_u64_be(1), - sell_amount: 1.into(), - buy_token: H160::from_low_u64_be(2), - buy_amount: 1.into(), + sell_token: Address::with_last_byte(1), + sell_amount: alloy::primitives::U256::from(1), + buy_token: Address::with_last_byte(2), + buy_amount: alloy::primitives::U256::from(1), app_data: OrderCreationAppData::Full { full: "{}".to_string(), }, @@ -2129,10 +2129,10 @@ mod tests { // Test with flashloan hint that covers the sell amount let order_with_sufficient_flashloan = OrderCreation { valid_to: u32::MAX, - sell_token: H160::from_low_u64_be(1), - sell_amount: 100.into(), - buy_token: H160::from_low_u64_be(2), - buy_amount: 1.into(), + sell_token: Address::with_last_byte(1), + sell_amount: alloy::primitives::U256::from(100), + buy_token: Address::with_last_byte(2), + buy_amount: alloy::primitives::U256::from(1), app_data: OrderCreationAppData::Full { full: r#"{ "metadata": { @@ -2167,10 +2167,10 @@ mod tests { // Test with flashloan hint that doesn't cover the sell amount let order_with_insufficient_flashloan = OrderCreation { valid_to: u32::MAX, - sell_token: H160::from_low_u64_be(1), - sell_amount: 100.into(), - buy_token: H160::from_low_u64_be(2), - buy_amount: 1.into(), + sell_token: Address::with_last_byte(1), + sell_amount: alloy::primitives::U256::from(100), + buy_token: Address::with_last_byte(2), + buy_amount: alloy::primitives::U256::from(1), app_data: OrderCreationAppData::Full { full: r#"{ "metadata": { @@ -2204,10 +2204,10 @@ mod tests { // Test with flashloan hint for different token let order_with_wrong_token_flashloan = OrderCreation { valid_to: u32::MAX, - sell_token: H160::from_low_u64_be(1), - sell_amount: 100.into(), - buy_token: H160::from_low_u64_be(2), - buy_amount: 1.into(), + sell_token: Address::with_last_byte(1), + sell_amount: alloy::primitives::U256::from(100), + buy_token: Address::with_last_byte(2), + buy_amount: alloy::primitives::U256::from(1), app_data: OrderCreationAppData::Full { full: r#"{ "metadata": { @@ -2546,17 +2546,17 @@ mod tests { let creation = OrderCreation { valid_to: time::now_in_epoch_seconds() + 10, - sell_token: H160([1; 20]), - buy_token: H160([2; 20]), - buy_amount: U256::from(4), - sell_amount: U256::from(3), - fee_amount: U256::from(0), + sell_token: Address::repeat_byte(1), + buy_token: Address::repeat_byte(2), + buy_amount: alloy::primitives::U256::from(4), + sell_amount: alloy::primitives::U256::from(3), + fee_amount: alloy::primitives::U256::from(0), signature: Signature::Eip1271(vec![1, 2, 3]), app_data: OrderCreationAppData::Full { full: "{}".to_string(), }, - from: Some(H160([0xf0; 20])), - receiver: Some(H160([0xf0; 20])), + from: Some(Address::repeat_byte(0xf0)), + receiver: Some(Address::repeat_byte(0xf0)), quote_id, ..Default::default() }; diff --git a/crates/shared/src/price_estimation/trade_verifier/mod.rs b/crates/shared/src/price_estimation/trade_verifier/mod.rs index 07fbecf85a..ae96d11724 100644 --- a/crates/shared/src/price_estimation/trade_verifier/mod.rs +++ b/crates/shared/src/price_estimation/trade_verifier/mod.rs @@ -724,7 +724,8 @@ fn recover_jit_order_owner( let owner = signature .recover(domain_separator, &order_data.hash_struct())? .context("could not recover the owner")? - .signer; + .signer + .into_legacy(); (owner, signature) } }; From 7fa8c8dbbe385c26d1cf082b137630c177c6d6d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Duarte?= Date: Fri, 5 Dec 2025 16:46:36 +0000 Subject: [PATCH 5/6] add mult again --- crates/e2e/tests/e2e/liquidity.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/e2e/tests/e2e/liquidity.rs b/crates/e2e/tests/e2e/liquidity.rs index 5ddf66321e..0358ae2d1b 100644 --- a/crates/e2e/tests/e2e/liquidity.rs +++ b/crates/e2e/tests/e2e/liquidity.rs @@ -308,8 +308,8 @@ fn create_zeroex_liquidity_orders( maker_token: order_creation.buy_token, taker_token: order_creation.sell_token, // fully covers execution costs - maker_amount: order_creation.buy_amount.try_into().unwrap(), - taker_amount: order_creation.sell_amount.try_into().unwrap(), + maker_amount: order_creation.buy_amount.try_into().unwrap() * 3, + taker_amount: order_creation.sell_amount.try_into().unwrap() * 2, // makes 0x order partially filled, but the amount is higher than the cowswap order to // make sure the 0x order is not overfilled in the end of the e2e test remaining_fillable_taker_amount: (order_creation.sell_amount From 892e432d574a316bd6318d1dfbe1871e9a10f804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Duarte?= Date: Fri, 5 Dec 2025 17:10:50 +0000 Subject: [PATCH 6/6] fix compilation issues --- crates/e2e/tests/e2e/liquidity.rs | 4 ++-- crates/shared/src/order_validation.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/e2e/tests/e2e/liquidity.rs b/crates/e2e/tests/e2e/liquidity.rs index 0358ae2d1b..0edf750f0d 100644 --- a/crates/e2e/tests/e2e/liquidity.rs +++ b/crates/e2e/tests/e2e/liquidity.rs @@ -308,8 +308,8 @@ fn create_zeroex_liquidity_orders( maker_token: order_creation.buy_token, taker_token: order_creation.sell_token, // fully covers execution costs - maker_amount: order_creation.buy_amount.try_into().unwrap() * 3, - taker_amount: order_creation.sell_amount.try_into().unwrap() * 2, + maker_amount: u128::try_from(order_creation.buy_amount).unwrap() * 3, + taker_amount: u128::try_from(order_creation.sell_amount).unwrap() * 2, // makes 0x order partially filled, but the amount is higher than the cowswap order to // make sure the 0x order is not overfilled in the end of the e2e test remaining_fillable_taker_amount: (order_creation.sell_amount diff --git a/crates/shared/src/order_validation.rs b/crates/shared/src/order_validation.rs index 06ae4d5469..efc7845d25 100644 --- a/crates/shared/src/order_validation.rs +++ b/crates/shared/src/order_validation.rs @@ -577,7 +577,8 @@ impl OrderValidating for OrderValidator { let app_data = self.validate_app_data(&order.app_data, &full_app_data_override)?; let app_data_signer = app_data.inner.protocol.signer.map(IntoLegacy::into_legacy); - let owner = order.verify_owner(domain_separator, app_data_signer.map(IntoAlloy::into_alloy))?; + let owner = + order.verify_owner(domain_separator, app_data_signer.map(IntoAlloy::into_alloy))?; tracing::debug!(?owner, "recovered owner from order and signature"); let signing_scheme = order.signature.scheme(); let data = OrderData { @@ -624,8 +625,7 @@ impl OrderValidating for OrderValidator { return Err(ValidationError::ZeroAmount); } - let pre_order = - PreOrderData::from_order_creation(owner, &data, signing_scheme); + let pre_order = PreOrderData::from_order_creation(owner, &data, signing_scheme); let class = pre_order.class; self.partial_validate(pre_order) .await @@ -769,7 +769,7 @@ impl OrderValidating for OrderValidator { let order = Order { metadata: OrderMetadata { - owner: owner, + owner, creation_date: chrono::offset::Utc::now(), uid, settlement_contract: settlement_contract.into_alloy(),