Skip to content

Commit

Permalink
Delete more solver code (#2618)
Browse files Browse the repository at this point in the history
# Description
Deletes code that is no longer used outside of the `solver` crate.
Also reduces the visibility of some items to help `clippy` find unused
items.
  • Loading branch information
MartinquaXD authored Apr 15, 2024
1 parent 25ed74b commit aa5f448
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 5,042 deletions.
24 changes: 14 additions & 10 deletions crates/driver/src/boundary/settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ use {
LimitOrderExecution,
},
settlement::Revertable,
settlement_simulation::settle_method_builder,
},
std::{collections::HashMap, sync::Arc},
};
Expand Down Expand Up @@ -106,9 +105,8 @@ impl Settlement {
),
};

let boundary_limit_order = order_converter.normalize_limit_order(
solver::order_balance_filter::BalancedOrder::full(boundary_order),
)?;
let boundary_limit_order = order_converter
.normalize_limit_order(solver::liquidity::BalancedOrder::full(boundary_order))?;
settlement.with_liquidity(&boundary_limit_order, execution)?;
}

Expand Down Expand Up @@ -171,12 +169,18 @@ impl Settlement {
}
settlement::Internalization::Disable => InternalizationStrategy::EncodeAllInteractions,
});
let builder = settle_method_builder(
contract,
encoded_settlement,
ethcontract::Account::Local(self.solver.into(), None),
);
let tx = builder.into_inner();

let account = ethcontract::Account::Local(self.solver.into(), None);
let tx = contract
.settle(
encoded_settlement.tokens,
encoded_settlement.clearing_prices,
encoded_settlement.trades,
encoded_settlement.interactions,
)
.from(account)
.into_inner();

let mut input = tx.data.unwrap().0;
input.extend(auction_id.to_be_bytes());
eth::Tx {
Expand Down
5 changes: 0 additions & 5 deletions crates/solver/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
pub mod interactions;
pub mod liquidity;
pub mod liquidity_collector;
mod metrics;
pub mod order_balance_filter;
pub mod settlement;
pub mod settlement_access_list;
pub mod settlement_simulation;
pub mod settlement_submission;
pub mod solver;
33 changes: 29 additions & 4 deletions crates/solver/src/liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ pub mod zeroex;

#[cfg(test)]
use derivative::Derivative;
#[cfg(test)]
use model::order::Order;
use {
crate::settlement::SettlementEncoder,
anyhow::Result,
model::{
order::{OrderKind, OrderUid},
order::{Order, OrderKind, OrderUid},
TokenPair,
},
num::rational::Ratio,
Expand Down Expand Up @@ -247,11 +245,38 @@ impl Settleable for LimitOrder {
impl From<Order> for LimitOrder {
fn from(order: Order) -> Self {
order_converter::OrderConverter::test(H160([0x42; 20]))
.normalize_limit_order(crate::order_balance_filter::BalancedOrder::full(order))
.normalize_limit_order(BalancedOrder::full(order))
.unwrap()
}
}

/// An order processed by `balance_orders`.
///
/// To ensure that all orders passed to solvers are settleable we need to
/// make a choice for which orders to include when the user only has enough
/// sell token balance for some of them.
#[derive(Debug, Clone)]
pub struct BalancedOrder {
pub order: Order,
/// The amount of sell token balance that is usable by this order.
///
/// The field might be larger than the order's sell_amount + fee_amount .
///
/// The field might be smaller than the order's sell_amount + fee_amount for
/// partially fillable orders. But it is always greater than 0 because no
/// balance being available at all would make an order unsettleable.
pub available_sell_token_balance: U256,
}

impl BalancedOrder {
pub fn full(order: Order) -> Self {
Self {
order,
available_sell_token_balance: U256::MAX,
}
}
}

#[cfg(test)]
impl Default for LimitOrder {
fn default() -> Self {
Expand Down
7 changes: 2 additions & 5 deletions crates/solver/src/liquidity/order_converter.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use {
super::{
BalancedOrder,
Exchange,
LimitOrder,
LimitOrderExecution,
LimitOrderId,
LiquidityOrderId,
SettlementHandling,
},
crate::{
interactions::UnwrapWethInteraction,
order_balance_filter::BalancedOrder,
settlement::SettlementEncoder,
},
crate::{interactions::UnwrapWethInteraction, settlement::SettlementEncoder},
anyhow::{ensure, Result},
contracts::WETH9,
model::order::{Order, OrderClass, BUY_ETH_ADDRESS},
Expand Down
34 changes: 0 additions & 34 deletions crates/solver/src/metrics.rs

This file was deleted.

Loading

0 comments on commit aa5f448

Please sign in to comment.