Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/driver/src/boundary/liquidity/balancer/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use {
BalancerV2WeightedPoolFactoryV3,
},
ethrpc::{
alloy::conversions::IntoAlloy,
alloy::conversions::{IntoAlloy, IntoLegacy},
block_stream::{BlockRetrieving, CurrentBlockWatcher},
},
shared::{
Expand Down Expand Up @@ -68,9 +68,9 @@ fn to_interaction(
let (target, value, call_data) = interaction.encode_swap();

eth::Interaction {
target: target.into(),
value: value.into(),
call_data: call_data.0.into(),
target: target.into_legacy().into(),
value: value.into_legacy().into(),
call_data: call_data.0.to_vec().into(),
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/driver/src/boundary/liquidity/uniswap/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ pub fn to_interaction(
let (target, value, call_data) = interaction.encode_swap();

eth::Interaction {
target: target.into(),
value: value.into(),
call_data: call_data.0.into(),
target: target.into_legacy().into(),
value: value.into_legacy().into(),
call_data: call_data.0.to_vec().into(),
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/driver/src/boundary/liquidity/uniswap/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ pub fn to_interaction(

let encoded = interaction.encode();
eth::Interaction {
target: eth::Address(encoded.0),
value: eth::Ether(encoded.1),
call_data: crate::util::Bytes(encoded.2.0),
target: eth::Address(encoded.0.into_legacy()),
value: eth::Ether(encoded.1.into_legacy()),
call_data: crate::util::Bytes(encoded.2.0.to_vec()),
}
}

Expand Down
15 changes: 7 additions & 8 deletions crates/e2e/tests/e2e/quote_verification.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
::alloy::primitives::address,
::alloy::primitives::{Address, U256, address},
bigdecimal::{BigDecimal, Zero},
e2e::setup::{eth, *},
ethcontract::H160,
Expand Down Expand Up @@ -184,16 +184,15 @@ async fn test_bypass_verification_for_rfq_quotes(web3: Web3) {
buy_token_destination: BuyTokenDestination::Erc20,
},
TradeKind::Legacy(LegacyTrade {
out_amount: 16380122291179526144u128.into(),
out_amount: U256::from(16380122291179526144u128),
gas_estimate: Some(225000),
interactions: vec![Interaction {
target: H160::from_str("0xdef1c0ded9bec7f1a1670819833240f027b25eff")
.unwrap(),
target: address!("0xdef1c0ded9bec7f1a1670819833240f027b25eff"),
data: const_hex::decode("aa77476c000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000000000000000000000000000e357b42c3a9d8ccf0000000000000000000000000000000000000000000000000000000004d0e79e000000000000000000000000a69babef1ca67a37ffaf7a485dfff3382056e78c0000000000000000000000009008d19f58aabd9ed0d60971565aa8510560ab41000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000066360af101ffffffffffffffffffffffffffffffffffffff0f3f47f166360a8d0000003f0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000001c66b3383f287dd9c85ad90e7c5a576ea4ba1bdf5a001d794a9afa379e6b2517b47e487a1aef32e75af432cbdbd301ada42754eaeac21ec4ca744afd92732f47540000000000000000000000000000000000000000000000000000000004d0c80f").unwrap(),
value: 0.into(),
value: U256::ZERO,
}],
solver: H160::from_str("0xe3067c7c27c1038de4e8ad95a83b927d23dfbd99")
.unwrap(),
solver: address!("0xe3067c7c27c1038de4e8ad95a83b927d23dfbd99")
,
tx_origin,
}),
)
Expand All @@ -220,7 +219,7 @@ async fn test_bypass_verification_for_rfq_quotes(web3: Web3) {
// `tx_origin: 0x0000` is currently used to bypass quote verification due to an
// implementation detail of zeroex RFQ orders.
// TODO: remove with #2693
let verification = verify_trade(Some(H160::zero())).await;
let verification = verify_trade(Some(Address::ZERO)).await;
assert_eq!(&verification.unwrap(), &verified_quote);

// Trades using any other `tx_origin` can not bypass the verification.
Expand Down
12 changes: 12 additions & 0 deletions crates/number/src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ pub mod alloy {
ensure!(!ratio.denom().is_zero(), "zero denominator");
big_int_to_u256(&(ratio.numer() / ratio.denom()))
}

pub fn u256_to_big_uint(input: &U256) -> BigUint {
BigUint::from_bytes_be(&input.to_be_bytes::<32>())
}

pub fn u256_to_big_int(input: &U256) -> BigInt {
BigInt::from_biguint(Sign::Plus, u256_to_big_uint(input))
}

pub fn u256_to_big_rational(input: &U256) -> BigRational {
BigRational::new(u256_to_big_int(input), 1.into())
}
}

pub fn rational_to_big_decimal<T>(value: &Ratio<T>) -> BigDecimal
Expand Down
20 changes: 20 additions & 0 deletions crates/shared/src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,23 @@ impl U256Ext for U256 {
.expect("ceiling division arithmetic error")
}
}

impl U256Ext for alloy::primitives::U256 {
fn to_big_int(&self) -> BigInt {
number::conversions::alloy::u256_to_big_int(self)
}

fn to_big_rational(&self) -> BigRational {
number::conversions::alloy::u256_to_big_rational(self)
}

fn checked_ceil_div(&self, other: &Self) -> Option<Self> {
self.checked_add(other.checked_sub(alloy::primitives::U256::ONE)?)?
.checked_div(*other)
}

fn ceil_div(&self, other: &Self) -> Self {
self.checked_ceil_div(other)
.expect("ceiling division arithmetic error")
}
}
16 changes: 7 additions & 9 deletions crates/shared/src/interaction.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use {
ethcontract::Bytes,
ethrpc::alloy::conversions::IntoLegacy,
alloy::primitives::{Address, Bytes, U256},
model::interaction::InteractionData,
primitive_types::{H160, U256},
};

pub trait Interaction: std::fmt::Debug + Send + Sync {
Expand All @@ -20,9 +18,9 @@ impl Interaction for Box<dyn Interaction> {
}

pub type EncodedInteraction = (
H160, // target
U256, // value
Bytes<Vec<u8>>, // callData
Address, // target
U256, // value
Bytes, // callData
);

impl Interaction for EncodedInteraction {
Expand All @@ -34,9 +32,9 @@ impl Interaction for EncodedInteraction {
impl Interaction for InteractionData {
fn encode(&self) -> EncodedInteraction {
(
self.target.into_legacy(),
self.value.into_legacy(),
Bytes(self.call_data.clone()),
self.target,
self.value,
Bytes::copy_from_slice(self.call_data.as_slice()),
)
}
}
5 changes: 2 additions & 3 deletions crates/shared/src/order_quoting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use {
chrono::{DateTime, Duration, Utc},
database::quotes::{Quote as QuoteRow, QuoteKind},
ethcontract::{H160, U256},
ethrpc::alloy::conversions::IntoAlloy,
futures::TryFutureExt,
gas_estimation::GasPriceEstimating,
model::{
Expand Down Expand Up @@ -568,8 +567,8 @@ impl OrderQuoter {
.pre_interactions
.iter()
.map(|i| InteractionData {
target: i.target.into_alloy(),
value: i.value.into_alloy(),
target: i.target,
value: i.value,
call_data: i.data.clone(),
})
.collect(),
Expand Down
5 changes: 3 additions & 2 deletions crates/shared/src/price_estimation/trade_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use {
},
crate::trade_finding::{TradeError, TradeFinding},
anyhow::{Result, anyhow},
ethrpc::alloy::conversions::IntoLegacy,
futures::future::FutureExt,
rate_limit::RateLimiter,
std::sync::Arc,
Expand Down Expand Up @@ -85,9 +86,9 @@ impl Inner {

let quote = self.finder.get_quote(&query).await?;
Ok(Estimate {
out_amount: quote.out_amount,
out_amount: quote.out_amount.into_legacy(),
gas: quote.gas_estimate,
solver: quote.solver,
solver: quote.solver.into_legacy(),
verified: false,
execution: quote.execution,
})
Expand Down
Loading
Loading