From 3a9eef0d394970dab42c0affcddedee0ae3d2795 Mon Sep 17 00:00:00 2001 From: Nicholas Rodrigues Lordello Date: Fri, 8 Sep 2023 13:55:09 +0200 Subject: [PATCH] Don't Match Liquidity Orders Against Onchain Liquidity (#1850) This PR fixes DEX aggregator API based solvers to not try and solve liquidity orders. ### Test Plan Rust CI - `UserOrder` logic is already tested. --- crates/solvers/src/domain/order.rs | 10 +++++----- crates/solvers/src/domain/solver/dex/mod.rs | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/solvers/src/domain/order.rs b/crates/solvers/src/domain/order.rs index 105b06b94c..0123775201 100644 --- a/crates/solvers/src/domain/order.rs +++ b/crates/solvers/src/domain/order.rs @@ -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 diff --git a/crates/solvers/src/domain/solver/dex/mod.rs b/crates/solvers/src/domain/solver/dex/mod.rs index 054bac4635..48302f741b 100644 --- a/crates/solvers/src/domain/solver/dex/mod.rs +++ b/crates/solvers/src/domain/solver/dex/mod.rs @@ -34,13 +34,12 @@ impl Dex { pub async fn solve(&self, auction: auction::Auction) -> Vec { // 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) @@ -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 { + 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 }; @@ -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; };