Skip to content

Commit

Permalink
Remove Liquidity order type from Solvers (#3059)
Browse files Browse the repository at this point in the history
# Description
A follow up for #3058

Removes Liquidity order type from solvers API.

Solvers PR: gnosis/solvers#77

# Changes
<!-- List of detailed changes (how the change is accomplished) -->

- [ ] Removed Liquidity order type from interface and from the domain

## How to test
Existing tests.
  • Loading branch information
sunce86 authored Oct 16, 2024
1 parent a17e419 commit 1c8c14f
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 64 deletions.
1 change: 0 additions & 1 deletion crates/solvers-dto/src/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ pub enum Kind {
pub enum Class {
Market,
Limit,
Liquidity,
}

#[derive(Debug, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion crates/solvers/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ components:
description: |
How the CoW Protocol order was classified.
type: string
enum: [ market, limit, liquidity ]
enum: [ market, limit ]

AppData:
description: |
Expand Down
1 change: 0 additions & 1 deletion crates/solvers/src/api/routes/solve/dto/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ pub fn to_domain(auction: &Auction) -> Result<auction::Auction, Error> {
class: match order.class {
Class::Market => order::Class::Market,
Class::Limit => order::Class::Limit,
Class::Liquidity => order::Class::Liquidity,
},
partially_fillable: order.partially_fillable,
})
Expand Down
5 changes: 0 additions & 5 deletions crates/solvers/src/boundary/naive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use {
LimitOrder,
LimitOrderExecution,
LimitOrderId,
LiquidityOrderId,
SettlementHandling,
},
settlement::SettlementEncoder,
Expand Down Expand Up @@ -57,9 +56,6 @@ pub fn solve(
id: match order.class {
order::Class::Market => LimitOrderId::Market(OrderUid(order.uid.0)),
order::Class::Limit => LimitOrderId::Limit(OrderUid(order.uid.0)),
order::Class::Liquidity => {
LimitOrderId::Liquidity(LiquidityOrderId::Protocol(OrderUid(order.uid.0)))
}
},
sell_token: order.sell.token.0,
buy_token: order.buy.token.0,
Expand All @@ -78,7 +74,6 @@ pub fn solve(
class: match order.class {
order::Class::Market => OrderClass::Market,
order::Class::Limit => OrderClass::Limit,
order::Class::Liquidity => OrderClass::Liquidity,
},
solver_fee: 0.into(),
..Default::default()
Expand Down
42 changes: 0 additions & 42 deletions crates/solvers/src/domain/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,48 +63,6 @@ pub enum Side {
pub enum Class {
Market,
Limit,
Liquidity,
}

/// 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:
///
/// - 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
/// non-liquidity orders.
/// - Liquidity orders do not provide any solver rewards.
///
/// As their name suggests, they are meant as a mechanism for providing
/// liquidity on CoW Protocol to other non-liquidity orders: they provide a
/// mechanism for turning one token into another. In this regard, a liquidity
/// order is conceptually similar to `liquidity::Liquidity`. One notable
/// difference between the two is in how they are executed. General liquidity
/// requires tokens up-front in order to exchange them for something else. On
/// the other hand, liquidity orders are CoW Protocol orders, meaning that they
/// first provide the tokens being swapped to and only get paid at the end of
/// the settlement.
#[derive(Clone, Copy, Debug)]
pub struct UserOrder<'a>(&'a Order);

impl<'a> UserOrder<'a> {
/// Wraps an order as a user order, returns `None` if the specified order is
/// not a user order.
pub fn new(order: &'a Order) -> Option<Self> {
match order.class {
Class::Market | Class::Limit => Some(Self(order)),
Class::Liquidity => None,
}
}

/// Returns a reference to the underlying CoW Protocol order.
pub fn get(&self) -> &'a Order {
self.0
}
}

/// An order that can be used to provide just-in-time liquidity in form of a CoW
Expand Down
22 changes: 9 additions & 13 deletions crates/solvers/src/domain/solver/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use {
auction,
eth,
liquidity,
order::{self, UserOrder},
order::{self, Order},
solution,
},
},
Expand Down Expand Up @@ -126,11 +126,7 @@ impl Inner {
boundary::baseline::Solver::new(&self.weth, &self.base_tokens, &auction.liquidity);

for (i, order) in auction.orders.into_iter().enumerate() {
let Some(user_order) = UserOrder::new(&order) else {
continue;
};

let sell_token = user_order.get().sell.token;
let sell_token = order.sell.token;
let sell_token_price = match auction.tokens.reference_price(&sell_token) {
Some(price) => price,
None if sell_token == self.weth.0.into() => {
Expand All @@ -139,7 +135,7 @@ impl Inner {
}
None => {
// Estimate the price of the sell token in the native token
let native_price_request = self.native_price_request(user_order);
let native_price_request = self.native_price_request(&order);
if let Some(route) = boundary_solver.route(native_price_request, self.max_hops)
{
// how many units of buy_token are bought for one unit of sell_token
Expand All @@ -159,7 +155,7 @@ impl Inner {
}
};

let solution = self.requests_for_order(user_order).find_map(|request| {
let solution = self.requests_for_order(&order).find_map(|request| {
tracing::trace!(order =% order.uid, ?request, "finding route");

let route = boundary_solver.route(request, self.max_hops)?;
Expand Down Expand Up @@ -215,12 +211,12 @@ impl Inner {
}
}

fn requests_for_order(&self, order: UserOrder) -> impl Iterator<Item = Request> {
fn requests_for_order(&self, order: &Order) -> impl Iterator<Item = Request> {
let order::Order {
sell, buy, side, ..
} = order.get().clone();
} = order.clone();

let n = if order.get().partially_fillable {
let n = if order.partially_fillable {
self.max_partial_attempts
} else {
1
Expand All @@ -244,9 +240,9 @@ impl Inner {
.filter(|r| !r.sell.amount.is_zero() && !r.buy.amount.is_zero())
}

fn native_price_request(&self, order: UserOrder) -> Request {
fn native_price_request(&self, order: &Order) -> Request {
let sell = eth::Asset {
token: order.get().sell.token,
token: order.sell.token,
// Note that we intentionally do not use [`eth::U256::max_value()`]
// as an order with this would cause overflows with the smart
// contract, so buy orders requiring excessively large sell amounts
Expand Down
2 changes: 1 addition & 1 deletion crates/solvers/src/tests/naive/swap_less_than_reserves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn test() {
"postInteractions": [],
"sellTokenSource": "erc20",
"buyTokenDestination": "erc20",
"class": "liquidity",
"class": "limit",
"appData": "0x6000000000000000000000000000000000000000000000000000000000000007",
"signingScheme": "presign",
"signature": "0x",
Expand Down

0 comments on commit 1c8c14f

Please sign in to comment.