Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fleupold committed Dec 7, 2023
1 parent 4faf94d commit 5b7201f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 29 deletions.
2 changes: 1 addition & 1 deletion crates/autopilot/src/run_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl RunLoop {
.iter()
.map(|(id, order)| Order::Colocated {
id: *id,
sell_amount: order.buy_amount,
sell_amount: order.sell_amount,
buy_amount: order.buy_amount,
})
.collect(),
Expand Down
4 changes: 2 additions & 2 deletions crates/driver/src/domain/competition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ pub struct Solved {

#[derive(Debug, Default)]
pub struct Amounts {
pub sell: order::SellAmount,
pub buy: order::BuyAmount,
pub sell: eth::TokenAmount,
pub buy: eth::TokenAmount,
}

/// Winning solution information revealed to the protocol by the driver before
Expand Down
22 changes: 0 additions & 22 deletions crates/driver/src/domain/competition/order/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,6 @@ impl From<SellAmount> for eth::U256 {
}
}

/// An amount denominated in the buy token of an [`Order`].
#[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd)]
pub struct BuyAmount(pub eth::U256);

impl From<eth::U256> for BuyAmount {
fn from(value: eth::U256) -> Self {
Self(value)
}
}

impl From<eth::TokenAmount> for BuyAmount {
fn from(value: eth::TokenAmount) -> Self {
Self(value.into())
}
}

impl From<BuyAmount> for eth::U256 {
fn from(sell_amount: BuyAmount) -> Self {
sell_amount.0
}
}

/// An amount denominated in the sell token for [`Side::Sell`] [`Order`]s, or in
/// the buy token for [`Side::Buy`] [`Order`]s.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
Expand Down
8 changes: 4 additions & 4 deletions crates/driver/src/domain/competition/solution/trade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Fulfillment {
pub fn sell_amount(
&self,
prices: &HashMap<eth::TokenAddress, eth::U256>,
) -> Option<order::SellAmount> {
) -> Option<eth::TokenAmount> {
let before_fee = match self.order.side {
order::Side::Sell => self.executed.0,
order::Side::Buy => self
Expand All @@ -101,7 +101,7 @@ impl Fulfillment {
.checked_mul(*prices.get(&self.order.buy.token)?)?
.checked_div(*prices.get(&self.order.sell.token)?)?,
};
Some(order::SellAmount(
Some(eth::TokenAmount(
before_fee.checked_add(self.solver_fee().0)?,
))
}
Expand All @@ -110,7 +110,7 @@ impl Fulfillment {
pub fn buy_amount(
&self,
prices: &HashMap<eth::TokenAddress, eth::U256>,
) -> Option<order::BuyAmount> {
) -> Option<eth::TokenAmount> {
let amount = match self.order.side {
order::Side::Buy => self.executed.0,
order::Side::Sell => self
Expand All @@ -119,7 +119,7 @@ impl Fulfillment {
.checked_mul(*prices.get(&self.order.sell.token)?)?
.checked_div(*prices.get(&self.order.buy.token)?)?,
};
Some(order::BuyAmount(amount))
Some(eth::TokenAmount(amount))
}
}

Expand Down

0 comments on commit 5b7201f

Please sign in to comment.