Skip to content

Commit

Permalink
[EASY] Remove rank by surplus config (#2582)
Browse files Browse the repository at this point in the history
# Description
Fixes #2462

## How to test
Existing tests. No change in behavior.
  • Loading branch information
sunce86 authored Mar 29, 2024
1 parent 2a6b916 commit 5430414
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 141 deletions.
1 change: 1 addition & 0 deletions crates/driver/src/domain/competition/solution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ impl SolverScore {
(SolverScore::RiskAdjusted(a), SolverScore::RiskAdjusted(b)) => {
Some(SolverScore::RiskAdjusted(a * b))
}
(SolverScore::Surplus, SolverScore::Surplus) => Some(SolverScore::Surplus),
_ => None,
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/driver/src/infra/config/file/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ pub async fn load(chain: eth::ChainId, path: &Path) -> infra::Config {
.unwrap(),
},
request_headers: config.request_headers,
rank_by_surplus_date: config.rank_by_surplus_date,
fee_handler: config.fee_handler,
}
}))
Expand Down
3 changes: 0 additions & 3 deletions crates/driver/src/infra/config/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ struct SolverConfig {
#[serde(default)]
request_headers: HashMap<String, String>,

/// Datetime when the CIP38 rank by surplus rules should be activated.
rank_by_surplus_date: Option<chrono::DateTime<chrono::Utc>>,

/// Determines whether the `solver` or the `driver` handles the fees
#[serde(default)]
fee_handler: FeeHandler,
Expand Down
18 changes: 2 additions & 16 deletions crates/driver/src/infra/solver/dto/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,7 @@ impl Solutions {
})
.try_collect()?,
solver.clone(),
match solver_config
.rank_by_surplus_date
.is_some_and(|date| auction.deadline().driver() > date)
{
true => competition::solution::SolverScore::Surplus,
false => match solution.score {
Score::Solver { score } => {
competition::solution::SolverScore::Solver(score)
}
Score::RiskAdjusted {
success_probability,
} => competition::solution::SolverScore::RiskAdjusted(
success_probability,
),
},
},
competition::solution::SolverScore::Surplus,
weth,
solution.gas.map(|gas| eth::Gas(gas.into())),
solver_config.fee_handler,
Expand Down Expand Up @@ -238,6 +223,7 @@ pub struct Solution {
prices: HashMap<eth::H160, eth::U256>,
trades: Vec<Trade>,
interactions: Vec<Interaction>,
#[allow(dead_code)]
score: Score,
gas: Option<u64>,
}
Expand Down
2 changes: 0 additions & 2 deletions crates/driver/src/infra/solver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ pub struct Config {
pub timeouts: Timeouts,
/// HTTP headers that should be added to every request.
pub request_headers: HashMap<String, String>,
/// Datetime when the CIP38 rank by surplus rules should be activated.
pub rank_by_surplus_date: Option<chrono::DateTime<chrono::Utc>>,
/// Determines whether the `solver` or the `driver` handles the fees
pub fee_handler: FeeHandler,
}
Expand Down
6 changes: 0 additions & 6 deletions crates/driver/src/tests/cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub mod negative_scores;
pub mod order_prioritization;
pub mod protocol_fees;
pub mod quote;
pub mod score_competition;
pub mod settle;
pub mod solver_balance;

Expand All @@ -44,11 +43,6 @@ pub const CD_ORDER_AMOUNT: u64 = 40;

pub const ETH_ORDER_AMOUNT: u64 = 40;

/// With the default amounts defined above, this is the expected score range for
/// both buy and sell orders.
pub const DEFAULT_SCORE_MIN: u64 = 2;
pub const DEFAULT_SCORE_MAX: u64 = 500000000000;

/// The default solver fee for limit orders.
pub const DEFAULT_SOLVER_FEE: &str = "1e-16";

Expand Down
4 changes: 2 additions & 2 deletions crates/driver/src/tests/cases/multiple_solutions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async fn valid() {
.done()
.await;

test.solve().await.ok().default_score().orders(&[order]);
test.solve().await.ok().orders(&[order]);
test.reveal().await.ok().calldata();
}

Expand All @@ -35,6 +35,6 @@ async fn invalid() {
.done()
.await;

test.solve().await.ok().default_score().orders(&[order]);
test.solve().await.ok().orders(&[order]);
test.reveal().await.ok().calldata();
}
2 changes: 1 addition & 1 deletion crates/driver/src/tests/cases/negative_scores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ async fn one_valid_solution() {
})
.done()
.await;
test.solve().await.ok().default_score().orders(&[order]);
test.solve().await.ok().orders(&[order]);
test.reveal().await.ok().calldata();
}
37 changes: 16 additions & 21 deletions crates/driver/src/tests/cases/protocol_fees.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
use {
crate::{
domain::{competition::order, eth},
infra::config::file::FeeHandler,
tests::{
self,
cases::EtherExt,
setup::{
ab_adjusted_pool,
ab_liquidity_quote,
ab_order,
ab_solution,
fee::{Policy, Quote},
test_solver,
ExpectedOrderAmounts,
Test,
},
use crate::{
domain::{competition::order, eth},
infra::config::file::FeeHandler,
tests::{
self,
cases::EtherExt,
setup::{
ab_adjusted_pool,
ab_liquidity_quote,
ab_order,
ab_solution,
fee::{Policy, Quote},
test_solver,
ExpectedOrderAmounts,
Test,
},
},
chrono::{DateTime, Utc},
};

struct Amounts {
Expand Down Expand Up @@ -102,9 +99,7 @@ async fn protocol_fee_test_case(test_case: TestCase) {
.pool(pool)
.order(order.clone())
.solution(ab_solution())
.solvers(vec![test_solver()
.rank_by_surplus_date(DateTime::<Utc>::MIN_UTC)
.fee_handler(test_case.fee_handler)])
.solvers(vec![test_solver().fee_handler(test_case.fee_handler)])
.done()
.await;

Expand Down
46 changes: 0 additions & 46 deletions crates/driver/src/tests/cases/score_competition.rs

This file was deleted.

4 changes: 2 additions & 2 deletions crates/driver/src/tests/cases/settle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn matrix() {
.done()
.await;

test.solve().await.ok().default_score();
test.solve().await.ok();
test.settle().await.ok().await.ab_order_executed().await;
}
}
Expand Down Expand Up @@ -70,7 +70,7 @@ async fn private_rpc_with_high_risk_solution() {
.done()
.await;

test.solve().await.ok().default_score();
test.solve().await.ok();
// Public cannot be used and private RPC is not available
let err = test.settle().await.err();
err.kind("FailedToSubmit");
Expand Down
5 changes: 0 additions & 5 deletions crates/driver/src/tests/setup/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ async fn create_config_file(
solving-share-of-deadline = {}
http-time-buffer = "{}ms"
fee-handler = {}
{}
"#,
solver.name,
addr,
Expand All @@ -234,10 +233,6 @@ async fn create_config_file(
solver.timeouts.solving_share_of_deadline.get(),
solver.timeouts.http_delay.num_milliseconds(),
serde_json::to_string(&solver.fee_handler).unwrap(),
solver.rank_by_surplus_date.map_or_else(
|| "".to_string(),
|timestamp| format!("rank-by-surplus-date = \"{}\"", timestamp.to_rfc3339())
),
)
.unwrap();
}
Expand Down
37 changes: 1 addition & 36 deletions crates/driver/src/tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ use {
DEFAULT_POOL_AMOUNT_B,
DEFAULT_POOL_AMOUNT_C,
DEFAULT_POOL_AMOUNT_D,
DEFAULT_SCORE_MAX,
DEFAULT_SCORE_MIN,
DEFAULT_SURPLUS_FACTOR,
ETH_ORDER_AMOUNT,
},
Expand Down Expand Up @@ -69,6 +67,7 @@ pub enum Partial {
#[derive(Debug, Clone, serde::Serialize)]
#[serde(rename_all = "camelCase", tag = "kind")]
pub enum Score {
#[allow(dead_code)]
Solver {
#[serde_as(as = "serialize::U256")]
score: eth::U256,
Expand Down Expand Up @@ -319,8 +318,6 @@ pub struct Solver {
slippage: infra::solver::Slippage,
/// The fraction of time used for solving
timeouts: infra::solver::Timeouts,
/// Datetime when the CIP38 rank by surplus rules should be activated.
rank_by_surplus_date: Option<chrono::DateTime<chrono::Utc>>,
/// Determines whether the `solver` or the `driver` handles the fees
fee_handler: FeeHandler,
}
Expand All @@ -342,7 +339,6 @@ pub fn test_solver() -> Solver {
http_delay: chrono::Duration::from_std(default_http_time_buffer()).unwrap(),
solving_share_of_deadline: default_solving_share_of_deadline().try_into().unwrap(),
},
rank_by_surplus_date: None,
fee_handler: FeeHandler::default(),
}
}
Expand Down Expand Up @@ -373,13 +369,6 @@ impl Solver {
Self { balance, ..self }
}

pub fn rank_by_surplus_date(self, rank_by_surplus_date: chrono::DateTime<chrono::Utc>) -> Self {
Self {
rank_by_surplus_date: Some(rank_by_surplus_date),
..self
}
}

pub fn fee_handler(mut self, fee_handler: FeeHandler) -> Self {
self.fee_handler = fee_handler;
self
Expand Down Expand Up @@ -571,11 +560,6 @@ impl Solution {
..self
}
}

/// Set the solution score to the specified value.
pub fn score(self, score: Score) -> Self {
Self { score, ..self }
}
}

impl Default for Solution {
Expand Down Expand Up @@ -1094,25 +1078,6 @@ impl<'a> SolveOk<'a> {
eth::U256::from_dec_str(score).unwrap()
}

/// Ensure that the score in the response is within a certain range. The
/// reason why this is a range is because small timing differences in
/// the test can lead to the settlement using slightly different amounts
/// of gas, which in turn leads to different scores.
pub fn score_in_range(self, min: eth::U256, max: eth::U256) -> Self {
let score = self.score();
assert!(score >= min, "score less than min {score} < {min}");
assert!(score <= max, "score more than max {score} > {max}");
self
}

/// Ensure that the score is within the default expected range.
pub fn default_score(self) -> Self {
self.score_in_range(
DEFAULT_SCORE_MIN.ether().into_wei(),
DEFAULT_SCORE_MAX.ether().into_wei(),
)
}

/// Ensures that `/solve` returns no solutions.
pub fn empty(self) {
assert!(self.solutions().is_empty());
Expand Down

0 comments on commit 5430414

Please sign in to comment.