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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ base64 = "0.22.1"
bigdecimal = { version = "0.3", features = ["serde"] }
chrono = { version = "0.4.38", features = ["serde"], default-features = false }
clap = { version = "4", features = ["derive", "env"] }
ethereum-types = "0.14"
futures = "0.3.30"
hex = "0.4"
hmac = "0.12.1"
Expand Down
6 changes: 4 additions & 2 deletions src/api/routes/solve/dto/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ pub fn from_domain(solutions: &[solution::Solution]) -> super::Solutions {
}
})
.collect(),
gas: solution.gas.map(|gas| gas.0.as_u64()),
gas: solution
.gas
.map(|gas| u64::try_from(gas.0).expect("value overflows u64::MAX")),
flashloans: None,
wrappers: Default::default(),
})
Expand All @@ -80,7 +82,7 @@ fn interaction_data_from_domain(interaction_data: &[eth::Interaction]) -> Vec<Ca
interaction_data
.iter()
.map(|interaction| Call {
target: interaction.target.0,
target: interaction.target,
value: interaction.value.0,
calldata: interaction.calldata.clone(),
})
Expand Down
6 changes: 4 additions & 2 deletions src/domain/auction.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
crate::domain::{eth, order},
ethereum_types::U256,
alloy::primitives::U256,
std::{
collections::HashMap,
fmt::{self, Display, Formatter},
Expand Down Expand Up @@ -76,7 +76,9 @@ impl Price {
/// Computes an amount equivalent in value to the specified [`eth::Ether`]
/// at the given price.
pub fn ether_value(&self, eth: eth::Ether) -> Option<U256> {
eth.0.checked_mul(Self::BASE.into())?.checked_div(self.0.0)
eth.0
.checked_mul(U256::from(Self::BASE))?
.checked_div(self.0.0)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/domain/dex/minimum_surplus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use {
crate::domain::{auction, dex::shared, eth},
alloy::primitives::U256,
bigdecimal::{BigDecimal, Zero},
ethereum_types::U256,
std::cmp,
};

Expand Down Expand Up @@ -103,7 +103,7 @@ mod tests {
(
eth::Asset {
token: token("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
amount: 500_000_000_000_000_000_u128.into(), // 0.5 WETH
amount: U256::from(500_000_000_000_000_000_u128), // 0.5 WETH
},
"0.04",
520_000_000_000_000_000_u128,
Expand All @@ -113,7 +113,7 @@ mod tests {
(
eth::Asset {
token: token("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
amount: 5_000_000_000_000_000_000_u128.into(), // 5 WETH
amount: U256::from(5_000_000_000_000_000_000_u128), // 5 WETH
},
"0.01",
5_050_000_000_000_000_000_u128,
Expand All @@ -122,7 +122,7 @@ mod tests {
(
eth::Asset {
token: token("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"),
amount: 10_000_000_000_u128.into(), // 10K USDC
amount: U256::from(10_000_000_000_u128), // 10K USDC
},
"0.01",
10_100_000_000_u128,
Expand Down
24 changes: 13 additions & 11 deletions src/domain/dex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use {
infra,
util,
},
alloy::primitives::Address,
ethereum_types::U256,
ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy},
alloy::primitives::{Address, U256},
std::fmt::{self, Debug, Formatter},
};

Expand All @@ -28,7 +26,7 @@ pub struct Order {
pub buy: eth::TokenAddress,
pub side: order::Side,
pub amount: Amount,
pub owner: eth::H160,
pub owner: eth::Address,
}

impl Order {
Expand Down Expand Up @@ -98,7 +96,7 @@ pub struct Swap {
impl Swap {
pub fn allowance(&self) -> solution::Allowance {
solution::Allowance {
spender: self.allowance.spender.into_legacy(),
spender: self.allowance.spender,
asset: eth::Asset {
token: self.input.token,
amount: self.allowance.amount.0,
Expand All @@ -117,7 +115,7 @@ impl Swap {
gas_offset: eth::Gas,
) -> Option<solution::Solution> {
let gas = if order.class == order::Class::Limit {
match simulator.gas(order.owner().into_alloy(), &self).await {
match simulator.gas(order.owner(), &self).await {
Ok(value) => value,
Err(infra::dex::simulator::Error::SettlementContractIsOwner) => self.gas,
Err(err) => {
Expand All @@ -137,7 +135,7 @@ impl Swap {
.into_iter()
.map(|call| {
solution::Interaction::Custom(solution::CustomInteraction {
target: call.to.into_legacy(),
target: call.to,
value: eth::Ether::default(),
calldata: call.calldata,
inputs: vec![self.input],
Expand All @@ -159,8 +157,10 @@ impl Swap {
}

pub fn satisfies(&self, order: &domain::order::Order) -> bool {
self.output.amount.full_mul(order.sell.amount)
>= self.input.amount.full_mul(order.buy.amount)
self.output
.amount
.widening_mul::<_, _, 512, 8>(order.sell.amount)
>= self.input.amount.widening_mul(order.buy.amount)
}

pub fn satisfies_with_minimum_surplus(
Expand All @@ -169,8 +169,10 @@ impl Swap {
minimum_surplus: &minimum_surplus::MinimumSurplus,
) -> bool {
let required_buy_amount = minimum_surplus.add(order.buy.amount);
self.output.amount.full_mul(order.sell.amount)
>= self.input.amount.full_mul(required_buy_amount)
self.output
.amount
.widening_mul::<_, _, 512, 8>(order.sell.amount)
>= self.input.amount.widening_mul(required_buy_amount)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/domain/dex/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use {
domain::{auction, eth},
util::conv,
},
alloy::primitives::U256,
bigdecimal::{BigDecimal, Zero},
ethereum_types::U256,
num::{BigUint, Integer},
};

Expand Down
20 changes: 10 additions & 10 deletions src/domain/dex/slippage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use {
crate::domain::{auction, dex::shared, eth},
alloy::primitives::U256,
bigdecimal::{BigDecimal, One, ToPrimitive, Zero},
ethereum_types::U256,
std::cmp,
};

Expand Down Expand Up @@ -140,7 +140,7 @@ mod tests {
(
eth::Asset {
token: token("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
amount: 1_000_000_000_000_000_000_u128.into(),
amount: U256::from(1_000_000_000_000_000_000_u128),
},
"0.01",
990_000_000_000_000_000_u128,
Expand All @@ -150,7 +150,7 @@ mod tests {
(
eth::Asset {
token: token("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
amount: 100_000_000_000_000_000_000_u128.into(),
amount: U256::from(100_000_000_000_000_000_000_u128),
},
"0.0002",
99_980_000_000_000_000_000_u128,
Expand All @@ -160,7 +160,7 @@ mod tests {
(
eth::Asset {
token: token("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"),
amount: 1_000_000_000_u128.into(), // 1K USDC
amount: U256::from(1_000_000_000_u128), // 1K USDC
},
"0.01",
990_000_000_u128,
Expand All @@ -171,7 +171,7 @@ mod tests {
(
eth::Asset {
token: token("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"),
amount: 1_000_000_000_000_u128.into(), // 1M USDC
amount: U256::from(1_000_000_000_000_u128), // 1M USDC
},
"0.000033911",
999_966_089_222_u128,
Expand All @@ -181,7 +181,7 @@ mod tests {
(
eth::Asset {
token: token("0xDEf1CA1fb7FBcDC777520aa7f396b4E015F497aB"),
amount: 1_000_000_000_000_000_000_000_u128.into(), // 1K COW
amount: U256::from(1_000_000_000_000_000_000_000_u128), // 1K COW
},
"0.01",
990_000_000_000_000_000_000_u128,
Expand All @@ -192,16 +192,16 @@ mod tests {
(
eth::Asset {
token: token("0xDEf1CA1fb7FBcDC777520aa7f396b4E015F497aB"),
amount: 1_000_000_000_000_000_000_000_000_u128.into(), // 1M COW
amount: U256::from(1_000_000_000_000_000_000_000_000_u128), // 1M COW
},
"0.000350877",
999_649_122_807_017_543_859_649_u128,
1_000_350_877_192_982_456_140_351_u128,
),
] {
let relative = Slippage::new(relative.parse().unwrap());
let min = ethereum_types::U256::from(min);
let max = ethereum_types::U256::from(max);
let min = U256::from(min);
let max = U256::from(max);

let computed = slippage.relative(&asset, &tokens);

Expand Down Expand Up @@ -251,7 +251,7 @@ mod tests {
// Test with zero amount - should not panic and use relative slippage fallback
let asset_with_zero_amount = eth::Asset {
token: token("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
amount: 0.into(), // Zero amount
amount: U256::ZERO, // Zero amount
};

// This should not panic and should return the relative slippage (1%)
Expand Down
Loading
Loading