diff --git a/crates/driver/src/domain/liquidity/zeroex.rs b/crates/driver/src/domain/liquidity/zeroex.rs index 93d8ac31ca..b0dbc193a1 100644 --- a/crates/driver/src/domain/liquidity/zeroex.rs +++ b/crates/driver/src/domain/liquidity/zeroex.rs @@ -1,9 +1,10 @@ use { crate::domain::{eth, liquidity}, + alloy::primitives::{Address, B256}, anyhow::anyhow, contracts::alloy::IZeroex, ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy}, - primitive_types::{H160, H256, U256}, + primitive_types::U256, std::sync::Arc, }; @@ -25,15 +26,15 @@ pub struct LimitOrder { #[derive(Clone, Debug)] pub struct Order { - pub maker: H160, - pub taker: H160, - pub sender: H160, - pub maker_token: H160, - pub taker_token: H160, + pub maker: Address, + pub taker: Address, + pub sender: Address, + pub maker_token: Address, + pub taker_token: Address, pub amounts: Amounts, pub taker_token_fee_amount: u128, - pub fee_recipient: H160, - pub pool: H256, + pub fee_recipient: Address, + pub pool: B256, pub expiry: u64, pub salt: U256, pub signature: ZeroExSignature, @@ -41,8 +42,8 @@ pub struct Order { #[derive(Clone, Debug)] pub struct ZeroExSignature { - pub r: H256, - pub s: H256, + pub r: B256, + pub s: B256, pub v: u8, pub signature_type: u8, } @@ -51,24 +52,24 @@ impl LimitOrder { pub fn to_interaction(&self, input: &liquidity::MaxInput) -> anyhow::Result { let method = self.zeroex.fillOrKillLimitOrder( IZeroex::LibNativeOrder::LimitOrder { - makerToken: self.order.maker_token.into_alloy(), - takerToken: self.order.taker_token.into_alloy(), + makerToken: self.order.maker_token, + takerToken: self.order.taker_token, makerAmount: self.order.amounts.maker, takerAmount: self.order.amounts.taker, takerTokenFeeAmount: self.order.taker_token_fee_amount, - maker: self.order.maker.into_alloy(), - taker: self.order.taker.into_alloy(), - sender: self.order.sender.into_alloy(), - feeRecipient: self.order.fee_recipient.into_alloy(), - pool: self.order.pool.into_alloy(), + maker: self.order.maker, + taker: self.order.taker, + sender: self.order.sender, + feeRecipient: self.order.fee_recipient, + pool: self.order.pool, expiry: self.order.expiry, salt: self.order.salt.into_alloy(), }, IZeroex::LibSignature::Signature { signatureType: self.order.signature.signature_type, v: self.order.signature.v, - r: self.order.signature.r.into_alloy(), - s: self.order.signature.s.into_alloy(), + r: self.order.signature.r, + s: self.order.signature.s, }, input .0 diff --git a/crates/driver/src/infra/solver/dto/auction.rs b/crates/driver/src/infra/solver/dto/auction.rs index 1af418428a..84ce51d7f2 100644 --- a/crates/driver/src/infra/solver/dto/auction.rs +++ b/crates/driver/src/infra/solver/dto/auction.rs @@ -59,8 +59,8 @@ pub fn new( liquidity::Kind::Swapr(pool) => pool.base.reserves.iter().map(|r| r.token).collect(), liquidity::Kind::ZeroEx(limit_order) => { vec![ - limit_order.order.maker_token.into(), - limit_order.order.taker_token.into(), + limit_order.order.maker_token.into_legacy().into(), + limit_order.order.taker_token.into_legacy().into(), ] } }) @@ -309,8 +309,8 @@ pub fn new( address: limit_order.zeroex.address().into_legacy(), gas_estimate: liquidity.gas.into(), hash: Default::default(), - maker_token: limit_order.order.maker_token, - taker_token: limit_order.order.taker_token, + maker_token: limit_order.order.maker_token.into_legacy(), + taker_token: limit_order.order.taker_token.into_legacy(), maker_amount: limit_order.fillable.maker.into(), taker_amount: limit_order.fillable.taker.into(), taker_token_fee_amount: limit_order.order.taker_token_fee_amount.into(), diff --git a/crates/e2e/src/api/zeroex.rs b/crates/e2e/src/api/zeroex.rs index bb176ba7a8..1aed1feb54 100644 --- a/crates/e2e/src/api/zeroex.rs +++ b/crates/e2e/src/api/zeroex.rs @@ -2,14 +2,12 @@ use { crate::setup::TestAccount, alloy::primitives::{Address, B256, U256}, chrono::{DateTime, NaiveDateTime, Utc}, - ethcontract::common::abi::{Token, encode}, - ethrpc::alloy::conversions::IntoLegacy, + ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy}, hex_literal::hex, model::DomainSeparator, shared::zeroex_api::{self, Order, OrderMetadata, OrderRecord, ZeroExSignature}, - std::{net::SocketAddr, sync::LazyLock}, + std::net::SocketAddr, warp::{Filter, Reply}, - web3::{signing, types::H160}, }; pub struct ZeroExApi { @@ -75,22 +73,22 @@ impl Eip712TypedZeroExOrder { pub fn to_order_record( &self, chain_id: u64, - verifying_contract: H160, + verifying_contract: Address, signer: TestAccount, ) -> OrderRecord { OrderRecord::new( Order { chain_id, expiry: NaiveDateTime::MAX.and_utc().timestamp() as u64, - fee_recipient: self.fee_recipient.into_legacy(), - maker: self.maker.into_legacy(), - maker_token: self.maker_token.into_legacy(), + fee_recipient: self.fee_recipient, + maker: self.maker, + maker_token: self.maker_token, maker_amount: self.maker_amount, - pool: self.pool.into_legacy(), + pool: self.pool, salt: self.salt.into_legacy(), - sender: self.sender.into_legacy(), - taker: self.taker.into_legacy(), - taker_token: self.taker_token.into_legacy(), + sender: self.sender, + taker: self.taker, + taker_token: self.taker_token, taker_amount: self.taker_amount, taker_token_fee_amount: self.taker_token_fee_amount, verifying_contract, @@ -116,8 +114,8 @@ impl Eip712TypedZeroExOrder { ) -> ZeroExSignature { let signature = signer.sign_typed_data(domain_separator, &hash); ZeroExSignature { - r: signature.r, - s: signature.s, + r: signature.r.into_alloy(), + s: signature.s.into_alloy(), v: signature.v, // See signature_type: 2, @@ -140,7 +138,7 @@ impl Eip712TypedZeroExOrder { hash_data[320..352].copy_from_slice(self.pool.as_slice()); hash_data[376..384].copy_from_slice(&self.expiry.to_be_bytes()); hash_data[384..416].copy_from_slice(&self.salt.to_be_bytes::<32>()); - signing::keccak256(&hash_data) + alloy::primitives::keccak256(hash_data).into() } } @@ -148,29 +146,15 @@ struct ZeroExDomainSeparator([u8; 32]); impl ZeroExDomainSeparator { // See - pub fn new(chain_id: u64, contract_addr: H160) -> Self { - /// The EIP-712 domain name used for computing the domain separator. - static DOMAIN_NAME: LazyLock<[u8; 32]> = LazyLock::new(|| signing::keccak256(b"ZeroEx")); - - /// The EIP-712 domain version used for computing the domain separator. - static DOMAIN_VERSION: LazyLock<[u8; 32]> = LazyLock::new(|| signing::keccak256(b"1.0.0")); - - /// The EIP-712 domain type used computing the domain separator. - static DOMAIN_TYPE_HASH: LazyLock<[u8; 32]> = LazyLock::new(|| { - signing::keccak256( - b"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)", - ) - }); - - let abi_encode_string = encode(&[ - Token::FixedBytes((*DOMAIN_TYPE_HASH).into()), - Token::FixedBytes((*DOMAIN_NAME).into()), - Token::FixedBytes((*DOMAIN_VERSION).into()), - Token::Uint(chain_id.into()), - Token::Address(contract_addr), - ]); - - Self(signing::keccak256(abi_encode_string.as_slice())) + pub fn new(chain_id: u64, contract_addr: Address) -> Self { + let domain = alloy::sol_types::eip712_domain! { + name: "ZeroEx", + version: "1.0.0", + chain_id: chain_id, + verifying_contract: contract_addr, + }; + + Self(domain.separator().into()) } pub fn to_domain_separator(&self) -> DomainSeparator { diff --git a/crates/e2e/tests/e2e/liquidity.rs b/crates/e2e/tests/e2e/liquidity.rs index 98f3b775dd..c610d91dd3 100644 --- a/crates/e2e/tests/e2e/liquidity.rs +++ b/crates/e2e/tests/e2e/liquidity.rs @@ -5,7 +5,6 @@ use { }, chrono::{NaiveDateTime, Utc}, contracts::alloy::{ERC20, IZeroex}, - driver::domain::eth::H160, e2e::{ api::zeroex::{Eip712TypedZeroExOrder, ZeroExApi}, assert_approximately_eq, @@ -175,9 +174,9 @@ async fn zero_ex_liquidity(web3: Web3) { let zeroex_liquidity_orders = create_zeroex_liquidity_orders( order.clone(), zeroex_maker.clone(), - zeroex.address().into_legacy(), + *zeroex.address(), chain_id, - onchain.contracts().weth.address().into_legacy(), + *onchain.contracts().weth.address(), ); let zeroex_api_port = ZeroExApi::new(zeroex_liquidity_orders.to_vec()).run().await; @@ -281,7 +280,7 @@ async fn zero_ex_liquidity(web3: Web3) { expiry: NaiveDateTime::MAX.and_utc().timestamp() as u64, salt: alloy::primitives::U256::from(Utc::now().timestamp()), } - .to_order_record(chain_id, zeroex.address().into_legacy(), zeroex_maker); + .to_order_record(chain_id, *zeroex.address(), zeroex_maker); fill_or_kill_zeroex_limit_order(&zeroex, &zeroex_order, solver.account().clone()) .await .unwrap(); @@ -301,9 +300,9 @@ async fn zero_ex_liquidity(web3: Web3) { fn create_zeroex_liquidity_orders( order_creation: OrderCreation, zeroex_maker: TestAccount, - zeroex_addr: H160, + zeroex_addr: Address, chain_id: u64, - weth_address: H160, + weth_address: Address, ) -> [shared::zeroex_api::OrderRecord; 3] { let typed_order = Eip712TypedZeroExOrder { maker_token: order_creation.buy_token.into_alloy(), @@ -319,13 +318,13 @@ fn create_zeroex_liquidity_orders( // Makes it possible for anyone to fill the order taker: Default::default(), sender: Default::default(), - fee_recipient: zeroex_addr.into_alloy(), + fee_recipient: zeroex_addr, pool: Default::default(), expiry: NaiveDateTime::MAX.and_utc().timestamp() as u64, salt: alloy::primitives::U256::from(Utc::now().timestamp()), }; let usdt_weth_order = Eip712TypedZeroExOrder { - maker_token: weth_address.into_alloy(), + maker_token: weth_address, taker_token: order_creation.buy_token.into_alloy(), // the value comes from the `--amount-to-estimate-prices-with` config to provide // sufficient liquidity @@ -336,13 +335,13 @@ fn create_zeroex_liquidity_orders( maker: zeroex_maker.address(), taker: Default::default(), sender: Default::default(), - fee_recipient: zeroex_addr.into_alloy(), + fee_recipient: zeroex_addr, pool: Default::default(), expiry: NaiveDateTime::MAX.and_utc().timestamp() as u64, salt: alloy::primitives::U256::from(Utc::now().timestamp()), }; let usdc_weth_order = Eip712TypedZeroExOrder { - maker_token: weth_address.into_alloy(), + maker_token: weth_address, taker_token: order_creation.sell_token.into_alloy(), // the value comes from the `--amount-to-estimate-prices-with` config to provide // sufficient liquidity @@ -353,7 +352,7 @@ fn create_zeroex_liquidity_orders( maker: zeroex_maker.address(), taker: Default::default(), sender: Default::default(), - fee_recipient: zeroex_addr.into_alloy(), + fee_recipient: zeroex_addr, pool: Default::default(), expiry: NaiveDateTime::MAX.and_utc().timestamp() as u64, salt: alloy::primitives::U256::from(Utc::now().timestamp()), @@ -375,24 +374,24 @@ async fn get_zeroex_order_amounts( Ok(zeroex .getLimitOrderRelevantState( IZeroex::LibNativeOrder::LimitOrder { - makerToken: zeroex_order.order().maker_token.into_alloy(), - takerToken: zeroex_order.order().taker_token.into_alloy(), + makerToken: zeroex_order.order().maker_token, + takerToken: zeroex_order.order().taker_token, makerAmount: zeroex_order.order().maker_amount, takerAmount: zeroex_order.order().taker_amount, takerTokenFeeAmount: zeroex_order.order().taker_token_fee_amount, - maker: zeroex_order.order().maker.into_alloy(), - taker: zeroex_order.order().taker.into_alloy(), - sender: zeroex_order.order().sender.into_alloy(), - feeRecipient: zeroex_order.order().fee_recipient.into_alloy(), - pool: zeroex_order.order().pool.into_alloy(), + maker: zeroex_order.order().maker, + taker: zeroex_order.order().taker, + sender: zeroex_order.order().sender, + feeRecipient: zeroex_order.order().fee_recipient, + pool: zeroex_order.order().pool, expiry: zeroex_order.order().expiry, salt: zeroex_order.order().salt.into_alloy(), }, IZeroex::LibSignature::Signature { signatureType: zeroex_order.order().signature.signature_type, v: zeroex_order.order().signature.v, - r: zeroex_order.order().signature.r.into_alloy(), - s: zeroex_order.order().signature.s.into_alloy(), + r: zeroex_order.order().signature.r, + s: zeroex_order.order().signature.s, }, ) .call() @@ -408,27 +407,28 @@ async fn fill_or_kill_zeroex_limit_order( zeroex_order: &shared::zeroex_api::OrderRecord, from_account: Account, ) -> anyhow::Result { + let order = zeroex_order.order(); let tx_hash = zeroex .fillOrKillLimitOrder( IZeroex::LibNativeOrder::LimitOrder { - makerToken: zeroex_order.order().maker_token.into_alloy(), - takerToken: zeroex_order.order().taker_token.into_alloy(), - makerAmount: zeroex_order.order().maker_amount, - takerAmount: zeroex_order.order().taker_amount, - takerTokenFeeAmount: zeroex_order.order().taker_token_fee_amount, - maker: zeroex_order.order().maker.into_alloy(), - taker: zeroex_order.order().taker.into_alloy(), - sender: zeroex_order.order().sender.into_alloy(), - feeRecipient: zeroex_order.order().fee_recipient.into_alloy(), - pool: zeroex_order.order().pool.into_alloy(), - expiry: zeroex_order.order().expiry, - salt: zeroex_order.order().salt.into_alloy(), + makerToken: order.maker_token, + takerToken: order.taker_token, + makerAmount: order.maker_amount, + takerAmount: order.taker_amount, + takerTokenFeeAmount: order.taker_token_fee_amount, + maker: order.maker, + taker: order.taker, + sender: order.sender, + feeRecipient: order.fee_recipient, + pool: order.pool, + expiry: order.expiry, + salt: order.salt.into_alloy(), }, IZeroex::LibSignature::Signature { - signatureType: zeroex_order.order().signature.signature_type, - v: zeroex_order.order().signature.v, - r: zeroex_order.order().signature.r.into_alloy(), - s: zeroex_order.order().signature.s.into_alloy(), + signatureType: order.signature.signature_type, + v: order.signature.v, + r: order.signature.r, + s: order.signature.s, }, zeroex_order.order().taker_amount, ) diff --git a/crates/shared/src/zeroex_api.rs b/crates/shared/src/zeroex_api.rs index 139c05103f..941b98761f 100644 --- a/crates/shared/src/zeroex_api.rs +++ b/crates/shared/src/zeroex_api.rs @@ -5,10 +5,11 @@ //! use { + alloy::primitives::{Address, B256, address}, anyhow::{Context, Result}, chrono::{DateTime, NaiveDateTime, TimeZone, Utc}, derivative::Derivative, - ethcontract::{H160, H256, U256}, + ethcontract::U256, ethrpc::block_stream::{BlockInfo, CurrentBlockWatcher}, number::serialization::HexOrDecimalU256, observe::tracing::tracing_headers, @@ -30,13 +31,6 @@ use { const ORDERS_MAX_PAGE_SIZE: usize = 1_000; -// The `Display` implementation for `H160` unfortunately does not print -// the full address ad instead uses ellipsis (e.g. "0xeeee…eeee"). This -// helper just works around that. -fn addr2str(addr: H160) -> String { - format!("{addr:#x}") -} - /// 0x API orders query parameters. /// /// These parameters are currently incomplete, and missing parameters can be @@ -47,13 +41,13 @@ pub struct OrdersQuery { /// The address of the party that is allowed to fill the order. /// If set to a specific party, the order cannot be filled by anyone else. /// If left unspecified, anyone can fill the order. - pub taker: Option, + pub taker: Option
, /// Allows the maker to enforce that the order flow through some /// additional logic before it can be filled (e.g., a KYC whitelist). - pub sender: Option, + pub sender: Option
, /// Address of the contract where the transaction should be sent, /// usually this is the 0x exchange proxy contract. - pub verifying_contract: Option, + pub verifying_contract: Option
, } impl OrdersQuery { @@ -62,15 +56,16 @@ impl OrdersQuery { let mut url = crate::url::join(base_url, "/orderbook/v1/orders"); if let Some(taker) = self.taker { - url.query_pairs_mut().append_pair("taker", &addr2str(taker)); + url.query_pairs_mut() + .append_pair("taker", &taker.to_string()); } if let Some(sender) = self.sender { url.query_pairs_mut() - .append_pair("sender", &addr2str(sender)); + .append_pair("sender", &sender.to_string()); } if let Some(verifying_contract) = self.verifying_contract { url.query_pairs_mut() - .append_pair("verifyingContract", &addr2str(verifying_contract)); + .append_pair("verifyingContract", &verifying_contract.to_string()); } url @@ -80,8 +75,8 @@ impl OrdersQuery { impl Default for OrdersQuery { fn default() -> Self { Self { - taker: Some(H160::zero()), - sender: Some(H160::zero()), + taker: Some(Address::ZERO), + sender: Some(Address::ZERO), verifying_contract: Some(DefaultZeroExApi::DEFAULT_VERIFICATION_CONTRACT), } } @@ -103,8 +98,8 @@ pub struct OrderMetadata { #[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Default)] #[serde(rename_all = "camelCase")] pub struct ZeroExSignature { - pub r: H256, - pub s: H256, + pub r: B256, + pub s: B256, pub v: u8, pub signature_type: u8, } @@ -123,43 +118,43 @@ pub struct Order { pub expiry: u64, /// The address of the entity that will receive any fees stipulated by the /// order. This is typically used to incentivize off-chain order relay. - pub fee_recipient: H160, + pub fee_recipient: Address, /// The address of the party that creates the order. The maker is also one /// of the two parties that will be involved in the trade if the order /// gets filled. - pub maker: H160, + pub maker: Address, /// The amount of `maker_token` being sold by the maker. #[serde_as(as = "DisplayFromStr")] pub maker_amount: u128, /// The address of the ERC20 token the maker is selling to the taker. - pub maker_token: H160, + pub maker_token: Address, /// The staking pool to attribute the 0x protocol fee from this order. Set /// to zero to attribute to the default pool, not owned by anyone. - pub pool: H256, + pub pool: B256, /// A value that can be used to guarantee order uniqueness. Typically it is /// set to a random number. #[serde_as(as = "HexOrDecimalU256")] pub salt: U256, /// It allows the maker to enforce that the order flow through some /// additional logic before it can be filled (e.g., a KYC whitelist). - pub sender: H160, + pub sender: Address, /// The signature of the signed order. pub signature: ZeroExSignature, /// The address of the party that is allowed to fill the order. If set to a /// specific party, the order cannot be filled by anyone else. If left /// unspecified, anyone can fill the order. - pub taker: H160, + pub taker: Address, /// The amount of `taker_token` being sold by the taker. #[serde_as(as = "DisplayFromStr")] pub taker_amount: u128, /// The address of the ERC20 token the taker is selling to the maker. - pub taker_token: H160, + pub taker_token: Address, /// Amount of takerToken paid by the taker to the feeRecipient. #[serde_as(as = "DisplayFromStr")] pub taker_token_fee_amount: u128, /// Address of the contract where the transaction should be sent, usually /// this is the 0x exchange proxy contract. - pub verifying_contract: H160, + pub verifying_contract: Address, } #[derive(Debug, Default, Clone, Deserialize, Serialize, Eq, PartialEq)] @@ -237,8 +232,8 @@ impl DefaultZeroExApi { pub const DEFAULT_URL: &'static str = "https://api.0x.org/"; /// Default 0x verifying contract. /// The currently latest 0x v4 contract. - pub const DEFAULT_VERIFICATION_CONTRACT: H160 = - addr!("Def1C0ded9bec7F1a1670819833240f027b25EfF"); + pub const DEFAULT_VERIFICATION_CONTRACT: Address = + address!("Def1C0ded9bec7F1a1670819833240f027b25EfF"); /// Create a new 0x HTTP API client with the specified base URL. pub fn new( @@ -456,7 +451,7 @@ impl Metrics { mod tests { use { super::*, - crate::addr, + alloy::primitives::address, chrono::{DateTime, NaiveDate}, }; @@ -548,30 +543,30 @@ mod tests { Order { chain_id: 1u64, expiry: 1646463524u64, - fee_recipient: addr!("86003b044f70dac0abc80ac8957305b6370893ed"), - maker: addr!("683b2388d719e98874d1f9c16b42a7bb498efbeb"), + fee_recipient: address!("86003b044f70dac0abc80ac8957305b6370893ed"), + maker: address!("683b2388d719e98874d1f9c16b42a7bb498efbeb"), maker_amount: 500000000u128, - maker_token: addr!("a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"), - pool: H256::zero(), + maker_token: address!("a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"), + pool: B256::ZERO, salt: 1645858724.into(), - sender: H160::zero(), + sender: Address::ZERO, signature: ZeroExSignature { signature_type: 3, - r: H256::from_slice( + r: B256::from_slice( &const_hex::decode("db60e4fa2b4f2ee073d88eed3502149ba2231d699bc5d92d5627dcd21f915237") .unwrap() ), - s: H256::from_slice( + s: B256::from_slice( &const_hex::decode("4cb1e9c15788b86d5187b99c0d929ad61d2654c242095c26f9ace17e64aca0fd") .unwrap() ), v: 28u8, }, - taker: H160::zero(), + taker: Address::ZERO, taker_amount: 262467000000000000u128, - taker_token: addr!("c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"), + taker_token: address!("c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"), taker_token_fee_amount: 0u128, - verifying_contract: addr!("def1c0ded9bec7f1a1670819833240f027b25eff"), + verifying_contract: address!("def1c0ded9bec7f1a1670819833240f027b25eff"), }, OrderMetadata { order_hash: diff --git a/crates/solver/src/interactions/zeroex.rs b/crates/solver/src/interactions/zeroex.rs index 388acc79e6..4a7b3dc92a 100644 --- a/crates/solver/src/interactions/zeroex.rs +++ b/crates/solver/src/interactions/zeroex.rs @@ -20,24 +20,24 @@ impl Interaction for ZeroExInteraction { fn encode(&self) -> EncodedInteraction { let method = self.zeroex.fillOrKillLimitOrder( IZeroex::LibNativeOrder::LimitOrder { - makerToken: self.order.maker_token.into_alloy(), - takerToken: self.order.taker_token.into_alloy(), + makerToken: self.order.maker_token, + takerToken: self.order.taker_token, makerAmount: self.order.maker_amount, takerAmount: self.order.taker_amount, takerTokenFeeAmount: self.order.taker_token_fee_amount, - maker: self.order.maker.into_alloy(), - taker: self.order.taker.into_alloy(), - sender: self.order.sender.into_alloy(), - feeRecipient: self.order.fee_recipient.into_alloy(), - pool: self.order.pool.into_alloy(), + maker: self.order.maker, + taker: self.order.taker, + sender: self.order.sender, + feeRecipient: self.order.fee_recipient, + pool: self.order.pool, expiry: self.order.expiry, salt: self.order.salt.into_alloy(), }, IZeroex::LibSignature::Signature { signatureType: self.order.signature.signature_type, v: self.order.signature.v, - r: self.order.signature.r.into_alloy(), - s: self.order.signature.s.into_alloy(), + r: self.order.signature.r, + s: self.order.signature.s, }, self.taker_token_fill_amount, ); diff --git a/crates/solver/src/liquidity/zeroex.rs b/crates/solver/src/liquidity/zeroex.rs index a393e246d5..5224c22e3a 100644 --- a/crates/solver/src/liquidity/zeroex.rs +++ b/crates/solver/src/liquidity/zeroex.rs @@ -20,7 +20,7 @@ use { futures::StreamExt, itertools::Itertools, model::{TokenPair, order::OrderKind}, - primitive_types::{H160, U256}, + primitive_types::U256, shared::{ ethrpc::Web3, http_solver::model::TokenAmount, @@ -34,7 +34,7 @@ use { tracing::instrument, }; -type OrderBuckets = HashMap<(H160, H160), Vec>; +type OrderBuckets = HashMap<(Address, Address), Vec>; type OrderbookCache = ArcSwap; pub struct ZeroExLiquidity { @@ -82,8 +82,8 @@ impl ZeroExLiquidity { id: LimitOrderId::Liquidity(LiquidityOrderId::ZeroEx(const_hex::encode( &record.metadata().order_hash, ))), - sell_token: record.order().maker_token, - buy_token: record.order().taker_token, + sell_token: record.order().maker_token.into_legacy(), + buy_token: record.order().taker_token.into_legacy(), sell_amount, buy_amount: record.metadata().remaining_fillable_taker_amount.into(), kind: OrderKind::Buy, @@ -112,7 +112,7 @@ impl ZeroExLiquidity { OrdersQuery::default(), // orders fillable only by our settlement contract OrdersQuery { - sender: Some(gpv2_address.into_legacy()), + sender: Some(gpv2_address), ..Default::default() }, ]; @@ -143,7 +143,7 @@ impl LiquidityCollecting for ZeroExLiquidity { let filtered_zeroex_orders = get_useful_orders(zeroex_order_buckets.as_ref(), &pairs, 5); let tokens: HashSet<_> = filtered_zeroex_orders .iter() - .map(|o| o.order().taker_token.into_alloy()) + .map(|o| o.order().taker_token) .collect(); let allowances = Arc::new( @@ -163,14 +163,10 @@ impl LiquidityCollecting for ZeroExLiquidity { fn group_by_token_pair( orders: impl Iterator, -) -> HashMap<(H160, H160), Vec> { +) -> HashMap<(Address, Address), Vec> { orders .filter_map(|record| { - TokenPair::new( - record.order().taker_token.into_alloy(), - record.order().maker_token.into_alloy(), - ) - .map(|_| { + TokenPair::new(record.order().taker_token, record.order().maker_token).map(|_| { ( (record.order().taker_token, record.order().maker_token), record, @@ -190,7 +186,7 @@ fn get_useful_orders( for orders in order_buckets .iter() .filter_map(|((token_a, token_b), record)| { - TokenPair::new(token_a.into_alloy(), token_b.into_alloy()) + TokenPair::new(*token_a, *token_b) .is_some_and(|pair| relevant_pairs.contains(&pair)) .then_some(record) }) @@ -238,7 +234,7 @@ impl SettlementHandling for OrderSettlementHandler { anyhow::bail!("0x only supports executed amounts of size u128"); } let approval = self.allowances.approve_token(TokenAmount::new( - self.order_record.order().taker_token.into_alloy(), + self.order_record.order().taker_token, execution.filled.into_alloy(), ))?; if let Some(approval) = approval { @@ -276,8 +272,8 @@ pub mod tests { fn order_with_tokens(token_a: Address, token_b: Address) -> OrderRecord { OrderRecord::new( zeroex_api::Order { - taker_token: token_a.into_legacy(), - maker_token: token_b.into_legacy(), + taker_token: token_a, + maker_token: token_b, ..Default::default() }, OrderMetadata::default(), @@ -320,8 +316,8 @@ pub mod tests { let order_with_fillable_amount = |remaining_fillable_taker_amount| { OrderRecord::new( zeroex_api::Order { - taker_token: token_a.into_legacy(), - maker_token: token_b.into_legacy(), + taker_token: token_a, + maker_token: token_b, taker_amount: 100_000_000, maker_amount: 100_000_000, ..Default::default() @@ -360,8 +356,8 @@ pub mod tests { let order_with_amount = |taker_amount, remaining_fillable_taker_amount| { OrderRecord::new( zeroex_api::Order { - taker_token: token_a.into_legacy(), - maker_token: token_b.into_legacy(), + taker_token: token_a, + maker_token: token_b, taker_amount, maker_amount: 100_000_000, ..Default::default() @@ -400,7 +396,7 @@ pub mod tests { let order_record = OrderRecord::new( zeroex_api::Order { taker_amount: 100, - taker_token: sell_token.into_legacy(), + taker_token: sell_token, ..Default::default() }, OrderMetadata::default(), @@ -448,7 +444,7 @@ pub mod tests { let order_record = OrderRecord::new( zeroex_api::Order { taker_amount: 100, - taker_token: sell_token.into_legacy(), + taker_token: sell_token, ..Default::default() }, OrderMetadata::default(),