Skip to content

Commit

Permalink
Tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
squadgazzz committed Nov 7, 2024
1 parent 38283f8 commit 88ee77b
Showing 1 changed file with 5 additions and 26 deletions.
31 changes: 5 additions & 26 deletions crates/shared/src/price_estimation/trade_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,40 +696,19 @@ fn ensure_quote_accuracy(
u256_to_big_rational(&sell_amount),
u256_to_big_rational(&buy_amount),
);

// Calculate the expected token losses that should be covered by JIT orders.
let (expected_sell_token_lost, expected_buy_token_lost) = match trade {
TradeKind::Regular(trade) if !trade.jit_orders.is_empty() => {
let jit_orders_net_token_changes = trade.jit_orders_net_token_changes()?;
let jit_orders_sell_token_changes = jit_orders_net_token_changes
.get(&query.sell_token)
.context("missing jit orders sell token executed amount")?;
let jit_orders_buy_token_changes =
jit_orders_net_token_changes
.get(&query.buy_token)
.context("missing jit orders buy token executed amount")?;

let expected_sell_token_lost = -&sell_amount - jit_orders_sell_token_changes;
let expected_buy_token_lost = &buy_amount - jit_orders_buy_token_changes;
(expected_sell_token_lost, expected_buy_token_lost)
}
_ => (BigRational::zero(), BigRational::zero()),
};
let sell_token_lost_limit = inaccuracy_limit * &sell_amount;
let buy_token_lost_limit = inaccuracy_limit * &buy_amount;

let sell_token_lost = summary
.tokens_lost
.get(&query.sell_token)
.context("summary sell token is missing")?
- expected_sell_token_lost;
let sell_token_lost_limit = inaccuracy_limit * &sell_amount;
.context("summary sell token is missing")?;
let buy_token_lost = summary
.tokens_lost
.get(&query.buy_token)
.context("summary buy token is missing")?
- expected_buy_token_lost;
let buy_token_lost_limit = inaccuracy_limit * &buy_amount;
.context("summary buy token is missing")?;

if sell_token_lost >= sell_token_lost_limit || buy_token_lost >= buy_token_lost_limit {
if *sell_token_lost >= sell_token_lost_limit || *buy_token_lost >= buy_token_lost_limit {
return Err(Error::TooInaccurate);
}

Expand Down

0 comments on commit 88ee77b

Please sign in to comment.