Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Liquidity order type from Solvers #77

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading