Skip to content

Commit

Permalink
Clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
squadgazzz committed Jan 25, 2024
1 parent dce04b6 commit f5d0564
Showing 1 changed file with 2 additions and 34 deletions.
36 changes: 2 additions & 34 deletions crates/solvers/src/boundary/liquidity/limit_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use {
contracts::ethcontract::{H160, U256},
shared::baseline_solver::BaselineSolvable,
};
use shared::price_estimation::gas::GAS_PER_ZEROEX_ORDER;

impl BaselineSolvable for LimitOrder {
fn get_amount_out(&self, out_token: H160, (in_amount, in_token): (U256, H160)) -> Option<U256> {
Expand Down Expand Up @@ -42,40 +43,7 @@ impl BaselineSolvable for LimitOrder {
}

fn gas_cost(&self) -> usize {
0
}
}

fn calculate_amount_out(
in_amount: U256,
maker_amount: U256,
taker_amount: U256,
fee: &TakerAmount,
) -> Option<U256> {
let fee_adjusted_amount = in_amount.checked_sub(fee.0)?;
if maker_amount > taker_amount {
let price_ratio = maker_amount.checked_div(taker_amount)?;
fee_adjusted_amount.checked_mul(price_ratio)
} else {
let inverse_price_ratio = taker_amount.checked_div(maker_amount)?;
fee_adjusted_amount.checked_div(inverse_price_ratio)
}
}

fn calculate_amount_in(
out_amount: U256,
maker_amount: U256,
taker_amount: U256,
fee: &TakerAmount,
) -> Option<U256> {
if maker_amount > taker_amount {
let inverse_price_ratio = maker_amount.checked_div(taker_amount)?;
let required_amount_before_fee = out_amount.checked_div(inverse_price_ratio)?;
required_amount_before_fee.checked_add(fee.0)
} else {
let price_ratio = taker_amount.checked_div(maker_amount)?;
let intermediate_amount = out_amount.checked_mul(price_ratio)?;
intermediate_amount.checked_add(fee.0)
GAS_PER_ZEROEX_ORDER as usize
}
}

Expand Down

0 comments on commit f5d0564

Please sign in to comment.