Skip to content

Commit

Permalink
Remove naive solver (#3161)
Browse files Browse the repository at this point in the history
# Description
The naive solver is extremely basic and never wins any auctions anymore.
Also AFAICT it's no longer used in e2e tests either so by now it's just
dead weight.
Sparked by this
[thread](https://cowservices.slack.com/archives/C036JAGRQ04/p1733911881085109)

# Changes
Removes:
* original algorithm in legacy code
* wrapper logic in `solvers` crate
* config code
* test cases
* documentation

Also in many cases we had an enum with 2 variants (`baseline` and
`naive`). Since we now only have 1 variant left I collapsed all the
logic and got rid of a few modules which are no longer necessary.
  • Loading branch information
MartinquaXD authored Dec 12, 2024
1 parent 5b26d73 commit df9ca2b
Show file tree
Hide file tree
Showing 32 changed files with 60 additions and 2,940 deletions.
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ Concretely, it is responsible for "cutting" new auctions (i.e. determining aucti

The `autopilot` connects to the same PostgreSQL database as the `orderbook` and uses it to query orders as well as storing the most recent auction and settlement competition.

## Solver

The `solver` crate is responsible for submitting on-chain settlements based on the orders it gets from the order book and other liquidity sources like Balancer or Uniswap pools.

It implements a few settlement strategies directly in Rust:

- Naive Solver: Can match to overlapping opposing orders (e.g. DAI for WETH & WETH for DAI) with one another settling the excess with Uniswap
- Uniswap Baseline: Same path finding as used by the Uniswap frontend (settling orders individually instead of batching them together)

It can also interact with a more advanced, Gnosis internal, closed source solver which tries to settle all orders using the combinatorial optimization formulations described in [Multi-Token Batch Auctions with Uniform Clearing Price](https://github.com/gnosis/dex-research/blob/master/BatchAuctionOptimization/batchauctions.pdf)

## Other Crates

There are additional crates that live in the cargo workspace.
Expand Down
8 changes: 0 additions & 8 deletions crates/solver/src/settlement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,6 @@ impl Settlement {
self.encoder.clearing_prices()
}

/// Returns the clearing price for the specified token.
///
/// Returns `None` if the token is not part of the settlement.
#[cfg(test)]
pub(crate) fn clearing_price(&self, token: H160) -> Option<U256> {
self.clearing_prices().get(&token).copied()
}

/// Returns all orders included in the settlement.
pub fn traded_orders(&self) -> impl Iterator<Item = &Order> + '_ {
self.encoder.all_trades().map(|trade| &trade.data.order)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
use {
crate::liquidity::{ConstantProductOrder, WeightedProductOrder},
anyhow::anyhow,
ethcontract::{H160, U256},
shared::{
baseline_solver::BaselineSolvable,
sources::{balancer_v2::swap::WeightedPoolRef, uniswap_v2::pool_fetching::Pool},
},
std::{fmt::Debug, str::FromStr},
};

// Wrapper type for AWS ARN identifiers
#[derive(Debug, Clone)]
pub struct Arn(pub String);

impl FromStr for Arn {
type Err = anyhow::Error;

fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
// Could be more strict here, but this should suffice to catch unintended
// configuration mistakes
if s.starts_with("arn:aws:kms:") {
Ok(Self(s.to_string()))
} else {
Err(anyhow!("Invalid ARN identifier: {}", s))
}
}
}

impl BaselineSolvable for ConstantProductOrder {
fn get_amount_out(&self, out_token: H160, input: (U256, H160)) -> Option<U256> {
amm_to_pool(self).get_amount_out(out_token, input)
Expand Down
25 changes: 0 additions & 25 deletions crates/solver/src/solver/mod.rs

This file was deleted.

Loading

0 comments on commit df9ca2b

Please sign in to comment.