Skip to content

Commit

Permalink
Don't Match Liquidity Orders Against Onchain Liquidity (#1850)
Browse files Browse the repository at this point in the history
This PR fixes DEX aggregator API based solvers to not try and solve
liquidity orders.

### Test Plan

Rust CI - `UserOrder` logic is already tested.
  • Loading branch information
Nicholas Rodrigues Lordello authored Sep 8, 2023
1 parent aac97f1 commit 3a9eef0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions crates/solvers/src/domain/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ pub enum Class {

/// A user order, guaranteed to not be a liquidity order.
///
/// Note that the concept of a user order is important enough to
/// merit its own type. The reason for this is that these orders and liquidity
/// orders differ in fundamental ways and we do not want to confuse them and
/// accidentally use a liquidity order where it shouldn't be used. Some of the
/// notable differences between the order types are:
/// Note that the concept of a user order is important enough to merit its own
/// type. The reason for this is that these orders and liquidity orders differ
/// in fundamental ways and we do not want to confuse them and accidentally use
/// a liquidity order where it shouldn't be used. Some of the notable
/// differences between the order types are:
///
/// - Liquidity orders can't be settled directly against on-chain liquidity.
/// They are meant to only be used in CoWs to facilitate the trading of other
Expand Down
12 changes: 6 additions & 6 deletions crates/solvers/src/domain/solver/dex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ impl Dex {

pub async fn solve(&self, auction: auction::Auction) -> Vec<solution::Solution> {
// TODO:
// * skip liquidity orders
// * concurrency

let mut solutions = Vec::new();
let solve_orders = async {
for order in auction.orders.iter().cloned() {
let span = tracing::info_span!("solve", order = %order.uid);
for order in auction.orders.iter().filter_map(order::UserOrder::new) {
let span = tracing::info_span!("solve", order = %order.get().uid);
if let Some(solution) = self
.solve_order(order, &auction.tokens, auction.gas_price)
.instrument(span)
Expand All @@ -62,12 +61,13 @@ impl Dex {

async fn solve_order(
&self,
order: order::Order,
order: order::UserOrder<'_>,
tokens: &auction::Tokens,
gas_price: auction::GasPrice,
) -> Option<solution::Solution> {
let order = order.get();
let swap = {
let order = self.fills.dex_order(&order, tokens)?;
let order = self.fills.dex_order(order, tokens)?;
let slippage = self.slippage.relative(&order.amount(), tokens);
self.dex.swap(&order, &slippage, tokens, gas_price).await
};
Expand Down Expand Up @@ -96,7 +96,7 @@ impl Dex {

let uid = order.uid;
let sell = tokens.reference_price(&order.sell.token);
let Some(solution) = swap.into_solution(order, gas_price, sell) else {
let Some(solution) = swap.into_solution(order.clone(), gas_price, sell) else {
tracing::debug!("no solution for swap");
return None;
};
Expand Down

0 comments on commit 3a9eef0

Please sign in to comment.