Skip to content

Commit

Permalink
Merge branch 'main' into settle-queue-to-driver
Browse files Browse the repository at this point in the history
  • Loading branch information
squadgazzz authored Dec 20, 2024
2 parents 572c68a + 796e7bd commit ca67121
Show file tree
Hide file tree
Showing 178 changed files with 3,355 additions and 4,509 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

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
4 changes: 0 additions & 4 deletions crates/app-data/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ pub struct Hooks {
}

impl Hooks {
pub fn is_empty(&self) -> bool {
self.pre.is_empty() && self.post.is_empty()
}

pub fn gas_limit(&self) -> u64 {
std::iter::empty()
.chain(&self.pre)
Expand Down
6 changes: 0 additions & 6 deletions crates/autopilot/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@ pub struct Arguments {
#[clap(long, env, use_value_delimiter = true)]
pub fee_policies: Vec<FeePolicy>,

/// Enables multiple fees
#[clap(long, env, action = clap::ArgAction::Set, default_value = "false")]
pub enable_multiple_fees: bool,

/// Maximum partner fee allow. If the partner fee specified is greater than
/// this maximum, the partner fee will be capped
#[clap(long, env, default_value = "0.01")]
Expand Down Expand Up @@ -269,7 +265,6 @@ impl std::fmt::Display for Arguments {
shadow,
solve_deadline,
fee_policies,
enable_multiple_fees,
fee_policy_max_partner_fee,
order_events_cleanup_interval,
order_events_cleanup_threshold,
Expand Down Expand Up @@ -326,7 +321,6 @@ impl std::fmt::Display for Arguments {
display_option(f, "shadow", shadow)?;
writeln!(f, "solve_deadline: {:?}", solve_deadline)?;
writeln!(f, "fee_policies: {:?}", fee_policies)?;
writeln!(f, "enable_multiple_fees: {:?}", enable_multiple_fees)?;
writeln!(
f,
"fee_policy_max_partner_fee: {:?}",
Expand Down
2 changes: 1 addition & 1 deletion crates/autopilot/src/database/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl QuoteStoring for Postgres {
.start_timer();

let mut ex = self.pool.acquire().await?;
let row = create_quote_row(data);
let row = create_quote_row(data)?;
let id = database::quotes::save(&mut ex, &row).await?;
Ok(id)
}
Expand Down
4 changes: 4 additions & 0 deletions crates/autopilot/src/database/onchain_order_events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ async fn parse_general_onchain_order_placement_data<'a>(
sell_amount: u256_to_big_decimal(&quote.sell_amount),
buy_amount: u256_to_big_decimal(&quote.buy_amount),
solver: ByteArray(quote.data.solver.0),
verified: quote.data.verified,
metadata: quote.data.metadata.try_into()?,
}),
Err(err) => {
let err_label = err.to_metrics_label();
Expand Down Expand Up @@ -1187,6 +1189,8 @@ mod test {
sell_amount: u256_to_big_decimal(&quote.sell_amount),
buy_amount: u256_to_big_decimal(&quote.buy_amount),
solver: ByteArray(quote.data.solver.0),
verified: quote.data.verified,
metadata: quote.data.metadata.try_into().unwrap(),
};
assert_eq!(result.1, vec![Some(expected_quote)]);
assert_eq!(
Expand Down
3 changes: 0 additions & 3 deletions crates/autopilot/src/domain/auction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub mod order;
#[derive(Clone, Debug, PartialEq)]
pub struct RawAuctionData {
pub block: u64,
pub latest_settlement_block: u64,
pub orders: Vec<Order>,
pub prices: Prices,
pub surplus_capturing_jit_order_owners: Vec<eth::Address>,
Expand All @@ -25,7 +24,6 @@ pub type Id = i64;
pub struct Auction {
pub id: Id,
pub block: u64,
pub latest_settlement_block: u64,
pub orders: Vec<Order>,
pub prices: Prices,
pub surplus_capturing_jit_order_owners: Vec<eth::Address>,
Expand All @@ -34,7 +32,6 @@ pub struct Auction {
impl PartialEq for Auction {
fn eq(&self, other: &Self) -> bool {
self.block == other.block
&& self.latest_settlement_block == other.latest_settlement_block
&& self.orders == other.orders
&& self.prices == other.prices
&& self.surplus_capturing_jit_order_owners == other.surplus_capturing_jit_order_owners
Expand Down
35 changes: 2 additions & 33 deletions crates/autopilot/src/domain/fee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use {
},
app_data::Validator,
derive_more::Into,
itertools::Itertools,
primitive_types::{H160, U256},
prometheus::core::Number,
std::{collections::HashSet, str::FromStr},
Expand Down Expand Up @@ -57,14 +56,12 @@ pub type ProtocolFeeExemptAddresses = HashSet<H160>;
pub struct ProtocolFees {
fee_policies: Vec<ProtocolFee>,
max_partner_fee: FeeFactor,
enable_protocol_fees: bool,
}

impl ProtocolFees {
pub fn new(
fee_policies: &[arguments::FeePolicy],
fee_policy_max_partner_fee: FeeFactor,
enable_protocol_fees: bool,
) -> Self {
Self {
fee_policies: fee_policies
Expand All @@ -73,7 +70,6 @@ impl ProtocolFees {
.map(ProtocolFee::from)
.collect(),
max_partner_fee: fee_policy_max_partner_fee,
enable_protocol_fees,
}
}

Expand Down Expand Up @@ -132,37 +128,10 @@ impl ProtocolFees {
fee: quote.fee.into(),
};

if self.enable_protocol_fees {
self.apply_multiple_policies(order, quote, order_, quote_, partner_fee)
} else {
self.apply_single_policy(order, quote, order_, quote_, partner_fee)
}
}

fn apply_single_policy(
&self,
order: boundary::Order,
quote: domain::Quote,
order_: boundary::Amounts,
quote_: boundary::Amounts,
partner_fees: Vec<Policy>,
) -> domain::Order {
if let Some(partner_fee) = partner_fees.first() {
return boundary::order::to_domain(order, vec![*partner_fee], Some(quote));
}
let protocol_fees = self
.fee_policies
.iter()
.find_map(|fee_policy| {
Self::protocol_fee_into_policy(&order, &order_, &quote_, fee_policy)
})
.and_then(|policy| Self::variant_fee_apply(&order, &quote, policy))
.into_iter()
.collect_vec();
boundary::order::to_domain(order, protocol_fees, Some(quote))
self.apply_policies(order, quote, order_, quote_, partner_fee)
}

fn apply_multiple_policies(
fn apply_policies(
&self,
order: boundary::Order,
quote: domain::Quote,
Expand Down
85 changes: 0 additions & 85 deletions crates/autopilot/src/infra/blockchain/authenticator.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/autopilot/src/infra/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use {
url::Url,
};

pub mod authenticator;
pub mod contracts;

/// An Ethereum RPC connection.
Expand Down
3 changes: 0 additions & 3 deletions crates/autopilot/src/infra/persistence/dto/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use {
pub fn from_domain(auction: domain::RawAuctionData) -> RawAuctionData {
RawAuctionData {
block: auction.block,
latest_settlement_block: auction.latest_settlement_block,
orders: auction
.orders
.into_iter()
Expand All @@ -38,7 +37,6 @@ pub fn from_domain(auction: domain::RawAuctionData) -> RawAuctionData {
#[serde(rename_all = "camelCase")]
pub struct RawAuctionData {
pub block: u64,
pub latest_settlement_block: u64,
pub orders: Vec<Order>,
#[serde_as(as = "BTreeMap<_, HexOrDecimalU256>")]
pub prices: BTreeMap<H160, U256>,
Expand All @@ -62,7 +60,6 @@ impl Auction {
Ok(domain::Auction {
id: self.id,
block: self.auction.block,
latest_settlement_block: self.auction.latest_settlement_block,
orders: self
.auction
.orders
Expand Down
1 change: 0 additions & 1 deletion crates/autopilot/src/infra/solvers/dto/reveal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use {
#[serde(rename_all = "camelCase")]
pub struct Request {
/// Unique ID of the solution (per driver competition), to reveal.
#[serde_as(as = "serde_with::DisplayFromStr")]
pub solution_id: u64,
/// Auction ID in which the specified solution ID is competing.
#[serde_as(as = "Option<serde_with::DisplayFromStr>")]
Expand Down
22 changes: 1 addition & 21 deletions crates/autopilot/src/infra/solvers/dto/settle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use {
primitive_types::H256,
serde::{Deserialize, Serialize},
serde::Serialize,
serde_with::{serde_as, skip_serializing_none},
};

Expand All @@ -10,29 +9,10 @@ use {
#[serde(rename_all = "camelCase")]
pub struct Request {
/// Unique ID of the solution (per driver competition), to settle.
#[serde_as(as = "serde_with::DisplayFromStr")]
pub solution_id: u64,
/// The last block number in which the solution TX can be included
pub submission_deadline_latest_block: u64,
/// Auction ID in which the specified solution ID is competing.
#[serde_as(as = "Option<serde_with::DisplayFromStr>")]
pub auction_id: Option<i64>,
}

#[serde_as]
#[derive(Clone, Debug, Default, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Response {
pub calldata: Calldata,
pub tx_hash: H256,
}

#[serde_as]
#[derive(Clone, Debug, Default, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Calldata {
#[serde(with = "bytes_hex")]
pub internalized: Vec<u8>,
#[serde(with = "bytes_hex")]
pub uninternalized: Vec<u8>,
}
Loading

0 comments on commit ca67121

Please sign in to comment.