Skip to content

Commit

Permalink
Remove Liquidity order type from Solvers (#77)
Browse files Browse the repository at this point in the history
Removes Liquidity order type from solvers domain as it's not used
anymore: cowprotocol/services#3059
  • Loading branch information
sunce86 authored Oct 16, 2024
1 parent 337fcba commit 4bc5424
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 63 deletions.
78 changes: 63 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contracts = { git = "https://github.com/cowprotocol/services.git", tag = "v2.280
ethrpc = { git = "https://github.com/cowprotocol/services.git", tag = "v2.280.0", package = "ethrpc" }
observe = { git = "https://github.com/cowprotocol/services.git", tag = "v2.280.0", package = "observe" }
shared = { git = "https://github.com/cowprotocol/services.git", tag = "v2.280.0", package = "shared" }
dto = { git = "https://github.com/cowprotocol/services.git", tag = "v2.280.0", package = "solvers-dto" }
dto = { git = "https://github.com/cowprotocol/services.git", tag = "v2.280.1", package = "solvers-dto" }
rate-limit = { git = "https://github.com/cowprotocol/services.git", tag = "v2.280.0", package = "rate-limit" }
number = { git = "https://github.com/cowprotocol/services.git", tag = "v2.280.0", package = "number" }

Expand Down
1 change: 0 additions & 1 deletion 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
42 changes: 0 additions & 42 deletions 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 arbitrary ethereum interaction that is required for the settlement
Expand Down
7 changes: 3 additions & 4 deletions src/domain/solver/dex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ impl Dex {
&'a self,
auction: &'a auction::Auction,
) -> impl stream::Stream<Item = solution::Solution> + 'a {
stream::iter(auction.orders.iter().filter_map(order::UserOrder::new))
stream::iter(auction.orders.iter())
.enumerate()
.map(|(i, order)| {
let span = tracing::info_span!("solve", order = %order.get().uid);
let span = tracing::info_span!("solve", order = %order.uid);
self.solve_order(order, &auction.tokens, auction.gas_price)
.map(move |solution| solution.map(|s| s.with_id(solution::Id(i as u64))))
.instrument(span)
Expand Down Expand Up @@ -181,11 +181,10 @@ impl Dex {

async fn solve_order(
&self,
order: order::UserOrder<'_>,
order: &order::Order,
tokens: &auction::Tokens,
gas_price: auction::GasPrice,
) -> Option<solution::Solution> {
let order = order.get();
let dex_order = self.fills.dex_order(order, tokens)?;
let swap = self.try_solve(order, &dex_order, tokens).await?;
let sell = tokens.reference_price(&order.sell.token);
Expand Down

0 comments on commit 4bc5424

Please sign in to comment.