Skip to content

Commit

Permalink
Remove risk parameters from solvers (#2598)
Browse files Browse the repository at this point in the history
# Description
A follow up for #2585

Risk parameters are no longer used, and we have other means of tweaking
the gas cost estimation.

## How to test
Existing tests.
  • Loading branch information
sunce86 authored Apr 5, 2024
1 parent 3178089 commit 2e6fbac
Show file tree
Hide file tree
Showing 23 changed files with 16 additions and 182 deletions.
6 changes: 0 additions & 6 deletions crates/e2e/src/setup/colocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ weth = "{weth:?}"
base-tokens = []
max-hops = 1
max-partial-attempts = 5
risk-parameters = [0,0,0,0]
"#,
));

start_solver(config_file, "baseline".to_string()).await
}

pub async fn start_naive_solver() -> Url {
let config_file = config_tmp_file("risk-parameters = [0,0,0,0]");
start_solver(config_file, "naive".to_string()).await
}

pub async fn start_legacy_solver(solver_endpoint: Url, chain_id: Option<U256>) -> Url {
let chain_id = chain_id.unwrap_or(U256::from(1));
let config_file = config_tmp_file(format!(
Expand Down
1 change: 0 additions & 1 deletion crates/solvers/config/example.baseline.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ chain-id = "1"
base-tokens = []
max-hops = 0
max-partial-attempts = 5
risk-parameters = [0,0,0,0]
# solution-gas-offset = 106391 # rough estimate of the settlement overhead
1 change: 0 additions & 1 deletion crates/solvers/config/example.naive.toml

This file was deleted.

3 changes: 0 additions & 3 deletions crates/solvers/src/domain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ pub mod eth;
pub mod liquidity;
pub mod notification;
pub mod order;
mod risk;
pub mod solution;
pub mod solver;

pub use risk::Risk;
26 changes: 0 additions & 26 deletions crates/solvers/src/domain/risk.rs

This file was deleted.

6 changes: 0 additions & 6 deletions crates/solvers/src/domain/solver/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use {
crate::{
boundary,
domain::{
self,
auction,
eth,
liquidity,
Expand All @@ -32,7 +31,6 @@ pub struct Config {
pub base_tokens: Vec<eth::TokenAddress>,
pub max_hops: usize,
pub max_partial_attempts: usize,
pub risk: domain::Risk,
pub solution_gas_offset: eth::SignedGas,
}

Expand All @@ -58,9 +56,6 @@ struct Inner {
/// valid solution or exceed this count.
max_partial_attempts: usize,

/// Parameters used to calculate the revert risk of a solution.
risk: domain::Risk,

/// Units of gas that get added to the gas estimate for executing a
/// computed trade route to arrive at a gas estimate for a whole settlement.
solution_gas_offset: eth::SignedGas,
Expand All @@ -74,7 +69,6 @@ impl Baseline {
base_tokens: config.base_tokens.into_iter().collect(),
max_hops: config.max_hops,
max_partial_attempts: config.max_partial_attempts,
risk: config.risk,
solution_gas_offset: config.solution_gas_offset,
}))
}
Expand Down
16 changes: 2 additions & 14 deletions crates/solvers/src/domain/solver/naive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,14 @@
use {
crate::{
boundary,
domain::{self, auction, eth, liquidity, order, solution},
domain::{auction, eth, liquidity, order, solution},
},
std::collections::HashMap,
};

pub struct Config {
pub risk: domain::Risk,
}

pub struct Naive {
/// Parameters used to calculate the revert risk of a solution.
risk: domain::Risk,
}
pub struct Naive;

impl Naive {
/// Creates a new naive solver for the specified configuration.
pub fn new(config: Config) -> Self {
Self { risk: config.risk }
}

/// Solves the specified auction, returning a vector of all possible
/// solutions.
pub async fn solve(&self, auction: auction::Auction) -> Vec<solution::Solution> {
Expand Down
5 changes: 1 addition & 4 deletions crates/solvers/src/infra/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ pub enum Command {
config: PathBuf,
},
/// optimistically batch similar orders and get difference from AMMs
Naive {
#[clap(long, env)]
config: PathBuf,
},
Naive,
/// forward auction to solver implementing the legacy HTTP interface
Legacy {
#[clap(long, env)]
Expand Down
12 changes: 1 addition & 11 deletions crates/solvers/src/infra/config/baseline.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
crate::{
domain::{eth, solver::baseline, Risk},
domain::{eth, solver::baseline},
infra::{config::unwrap_or_log, contracts},
util::serialize,
},
Expand Down Expand Up @@ -39,10 +39,6 @@ struct Config {
/// when trying to solve it against baseline liquidity.
max_partial_attempts: usize,

/// Parameters used to calculate the revert risk of a solution.
/// (gas_amount_factor, gas_price_factor, nmb_orders_factor, intercept)
risk_parameters: (f64, f64, f64, f64),

/// Units of gas that get added to the gas estimate for executing a
/// computed trade route to arrive at a gas estimate for a whole settlement.
#[serde(default = "default_gas_offset")]
Expand Down Expand Up @@ -81,12 +77,6 @@ pub async fn load(path: &Path) -> baseline::Config {
.collect(),
max_hops: config.max_hops,
max_partial_attempts: config.max_partial_attempts,
risk: Risk {
gas_amount_factor: config.risk_parameters.0,
gas_price_factor: config.risk_parameters.1,
nmb_orders_factor: config.risk_parameters.2,
intercept: config.risk_parameters.3,
},
solution_gas_offset: config.solution_gas_offset.into(),
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/solvers/src/infra/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::fmt::Debug;

pub mod baseline;
pub mod legacy;
pub mod naive;

/// Unwraps result or logs a `TOML` parsing error.
fn unwrap_or_log<T, E, P>(result: Result<T, E>, path: &P) -> T
Expand Down
40 changes: 0 additions & 40 deletions crates/solvers/src/infra/config/naive.rs

This file was deleted.

5 changes: 1 addition & 4 deletions crates/solvers/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ async fn run_with(args: cli::Args, bind: Option<oneshot::Sender<SocketAddr>>) {
let config = config::baseline::load(&config).await;
Solver::Baseline(solver::Baseline::new(config))
}
cli::Command::Naive { config } => {
let config = config::naive::load(&config).await;
Solver::Naive(solver::Naive::new(config))
}
cli::Command::Naive => Solver::Naive(solver::Naive),
cli::Command::Legacy { config } => {
let config = config::legacy::load(&config).await;
Solver::Legacy(solver::Legacy::new(config))
Expand Down
4 changes: 0 additions & 4 deletions crates/solvers/src/tests/baseline/bal_liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ async fn weighted() {
base-tokens = []
max-hops = 0
max-partial-attempts = 1
risk-parameters = [0,0,0,0]
"#
.to_owned(),
),
Expand Down Expand Up @@ -134,7 +133,6 @@ async fn weighted_v3plus() {
base-tokens = []
max-hops = 0
max-partial-attempts = 1
risk-parameters = [0,0,0,0]
"#
.to_owned(),
),
Expand Down Expand Up @@ -249,7 +247,6 @@ async fn stable() {
base-tokens = []
max-hops = 0
max-partial-attempts = 1
risk-parameters = [0,0,0,0]
"#
.to_owned(),
),
Expand Down Expand Up @@ -417,7 +414,6 @@ async fn composable_stable_v4() {
base-tokens = []
max-hops = 0
max-partial-attempts = 1
risk-parameters = [0,0,0,0]
"#
.to_owned(),
),
Expand Down
5 changes: 0 additions & 5 deletions crates/solvers/src/tests/baseline/buy_order_rounding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ async fn balancer_weighted() {
base-tokens = ["0x9c58bacc331c9aa871afd802db6379a98e80cedb"]
max-hops = 1
max-partial-attempts = 1
risk-parameters = [0,0,0,0]
"#
.to_owned(),
),
Expand Down Expand Up @@ -285,7 +284,6 @@ async fn balancer_weighted_v3plus() {
base-tokens = []
max-hops = 0
max-partial-attempts = 1
risk-parameters = [0,0,0,0]
"#
.to_owned(),
),
Expand Down Expand Up @@ -400,7 +398,6 @@ async fn distant_convergence() {
base-tokens = []
max-hops = 0
max-partial-attempts = 1
risk-parameters = [0,0,0,0]
"#
.to_owned(),
),
Expand Down Expand Up @@ -515,7 +512,6 @@ async fn same_path() {
base-tokens = ["0x9c58bacc331c9aa871afd802db6379a98e80cedb"]
max-hops = 0
max-partial-attempts = 1
risk-parameters = [0,0,0,0]
"#
.to_owned(),
),
Expand Down Expand Up @@ -666,7 +662,6 @@ async fn balancer_stable() {
base-tokens = []
max-hops = 0
max-partial-attempts = 1
risk-parameters = [0,0,0,0]
"#
.to_owned(),
),
Expand Down
6 changes: 1 addition & 5 deletions crates/solvers/src/tests/naive/extract_deepest_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ use {crate::tests, serde_json::json};

#[tokio::test]
async fn test() {
let engine = tests::SolverEngine::new(
"naive",
tests::Config::File("config/example.naive.toml".into()),
)
.await;
let engine = tests::SolverEngine::new("naive", tests::Config::None).await;

let solution = engine
.solve(json!({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ use {crate::tests, serde_json::json};

#[tokio::test]
async fn sell_orders_on_both_sides() {
let engine = tests::SolverEngine::new(
"naive",
tests::Config::String(r#"risk-parameters = [0,0,0,0]"#.to_owned()),
)
.await;
let engine = tests::SolverEngine::new("naive", tests::Config::None).await;

let solution = engine
.solve(json!({
Expand Down
6 changes: 1 addition & 5 deletions crates/solvers/src/tests/naive/limit_order_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ use {crate::tests, serde_json::json};

#[tokio::test]
async fn test() {
let engine = tests::SolverEngine::new(
"naive",
tests::Config::String(r#"risk-parameters = [0,0,0,0]"#.to_owned()),
)
.await;
let engine = tests::SolverEngine::new("naive", tests::Config::None).await;

let solution = engine
.solve(json!({
Expand Down
24 changes: 4 additions & 20 deletions crates/solvers/src/tests/naive/matches_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ use {crate::tests, serde_json::json};

#[tokio::test]
async fn sell_orders_on_both_sides() {
let engine = tests::SolverEngine::new(
"naive",
tests::Config::String(r#"risk-parameters = [0,0,0,0]"#.to_owned()),
)
.await;
let engine = tests::SolverEngine::new("naive", tests::Config::None).await;

let solution = engine
.solve(json!({
Expand Down Expand Up @@ -112,11 +108,7 @@ async fn sell_orders_on_both_sides() {

#[tokio::test]
async fn sell_orders_on_one_side() {
let engine = tests::SolverEngine::new(
"naive",
tests::Config::String(r#"risk-parameters = [0,0,0,0]"#.to_owned()),
)
.await;
let engine = tests::SolverEngine::new("naive", tests::Config::None).await;

let solution = engine
.solve(json!({
Expand Down Expand Up @@ -219,11 +211,7 @@ async fn sell_orders_on_one_side() {

#[tokio::test]
async fn buy_orders_on_both_sides() {
let engine = tests::SolverEngine::new(
"naive",
tests::Config::String(r#"risk-parameters = [0,0,0,0]"#.to_owned()),
)
.await;
let engine = tests::SolverEngine::new("naive", tests::Config::None).await;

let solution = engine
.solve(json!({
Expand Down Expand Up @@ -326,11 +314,7 @@ async fn buy_orders_on_both_sides() {

#[tokio::test]
async fn buy_and_sell_orders() {
let engine = tests::SolverEngine::new(
"naive",
tests::Config::String(r#"risk-parameters = [0,0,0,0]"#.to_owned()),
)
.await;
let engine = tests::SolverEngine::new("naive", tests::Config::None).await;

let solution = engine
.solve(json!({
Expand Down
Loading

0 comments on commit 2e6fbac

Please sign in to comment.