From 7f06327e0edd3437e508d844167096ad89e99fac Mon Sep 17 00:00:00 2001 From: ilya Date: Thu, 4 Apr 2024 14:09:47 +0100 Subject: [PATCH] Get rid of score --- config/example.balancer.toml | 1 - config/example.oneinch.toml | 1 - config/example.paraswap.toml | 1 - config/example.zeroex.toml | 1 - openapi.yml | 28 ---------------- src/api/routes/solve/dto/solution.rs | 20 ----------- src/domain/dex/mod.rs | 6 +--- src/domain/mod.rs | 3 -- src/domain/notification.rs | 20 +---------- src/domain/risk.rs | 26 --------------- src/domain/solution.rs | 50 +--------------------------- src/domain/solver/dex/mod.rs | 7 +--- src/infra/config/dex/file.rs | 12 +------ src/infra/config/dex/mod.rs | 3 +- src/tests/balancer/market_order.rs | 8 ----- src/tests/balancer/mod.rs | 2 -- src/tests/dex/partial_fill.rs | 14 -------- src/tests/oneinch/market_order.rs | 4 --- src/tests/oneinch/mod.rs | 2 -- src/tests/paraswap/market_order.rs | 8 ----- src/tests/paraswap/mod.rs | 2 -- src/tests/zeroex/market_order.rs | 8 ----- src/tests/zeroex/mod.rs | 2 -- src/tests/zeroex/options.rs | 5 --- 24 files changed, 6 insertions(+), 228 deletions(-) delete mode 100644 src/domain/risk.rs diff --git a/config/example.balancer.toml b/config/example.balancer.toml index f2f9f80..5e48740 100644 --- a/config/example.balancer.toml +++ b/config/example.balancer.toml @@ -1,7 +1,6 @@ node-url = "http://localhost:8545" absolute-slippage = "40000000000000000" # Denominated in wei, optional relative-slippage = "0.001" # Percentage in the [0, 1] range -risk-parameters = [0,0,0,0] [dex] endpoint = "https://balancer.sor.eth/api" diff --git a/config/example.oneinch.toml b/config/example.oneinch.toml index 74dce21..76983ba 100644 --- a/config/example.oneinch.toml +++ b/config/example.oneinch.toml @@ -1,7 +1,6 @@ node-url = "http://localhost:8545" absolute-slippage = "40000000000000000" # Denominated in wei, optional relative-slippage = "0.001" # Percentage in the [0, 1] range -risk-parameters = [0,0,0,0] [dex] chain-id = "1" diff --git a/config/example.paraswap.toml b/config/example.paraswap.toml index d52fb6c..b026716 100644 --- a/config/example.paraswap.toml +++ b/config/example.paraswap.toml @@ -1,7 +1,6 @@ node-url = "http://localhost:8545" absolute-slippage = "40000000000000000" # Denominated in wei, optional relative-slippage = "0.001" # Percentage in the [0, 1] range -risk-parameters = [0,0,0,0] [dex] # these 2 dexs should always be excluded because they are incompatible with `ignoreChecks` diff --git a/config/example.zeroex.toml b/config/example.zeroex.toml index 6884a60..80e91f2 100644 --- a/config/example.zeroex.toml +++ b/config/example.zeroex.toml @@ -1,7 +1,6 @@ node-url = "http://localhost:8545" absolute-slippage = "40000000000000000" # Denominated in wei, optional relative-slippage = "0.001" # Percentage in the [0, 1] range -risk-parameters = [0,0,0,0] [dex] # See here how to get a free key: https://0x.org/docs/introduction/getting-started diff --git a/openapi.yml b/openapi.yml index 83c788c..dabb714 100644 --- a/openapi.yml +++ b/openapi.yml @@ -757,7 +757,6 @@ components: - prices - trades - interactions - - score properties: id: description: An opaque identifier for the solution. @@ -781,30 +780,3 @@ components: type: array items: $ref: "#/components/schemas/Interaction" - score: - description: | - Information required by the driver to score the solution. - - Can either be a raw score or a success probability. - oneOf: - - type: object - properties: - kind: - type: string - enum: [solver] - score: - description: | - The raw score of the solution. This is the score that is - used by the driver to rank solutions. - allOf: - - $ref: "#/components/schemas/Decimal" - - type: object - properties: - kind: - type: string - enum: [riskAdjusted] - successProbability: - description: | - The revert probability of the solution. Used by the driver to compute a risk-adjusted score. - type: number - example: 0.9 diff --git a/src/api/routes/solve/dto/solution.rs b/src/api/routes/solve/dto/solution.rs index 99a237d..46cb6b1 100644 --- a/src/api/routes/solve/dto/solution.rs +++ b/src/api/routes/solve/dto/solution.rs @@ -122,12 +122,6 @@ impl Solutions { } }) .collect(), - score: match solution.score.clone() { - solution::Score::Solver(score) => Score::Solver { score }, - solution::Score::RiskAdjusted(score) => Score::RiskAdjusted { - success_probability: score.0, - }, - }, gas: solution.gas.map(|gas| gas.0.as_u64()), }) .collect(), @@ -150,7 +144,6 @@ struct Solution { prices: HashMap, trades: Vec, interactions: Vec, - score: Score, #[serde(skip_serializing_if = "Option::is_none")] gas: Option, } @@ -311,16 +304,3 @@ enum SigningScheme { PreSign, Eip1271, } - -/// A score for a solution. The score is used to rank solutions. -#[serde_as] -#[derive(Debug, Serialize)] -#[serde(rename_all = "camelCase", tag = "kind")] -pub enum Score { - Solver { - #[serde_as(as = "serialize::U256")] - score: U256, - }, - #[serde(rename_all = "camelCase")] - RiskAdjusted { success_probability: f64 }, -} diff --git a/src/domain/dex/mod.rs b/src/domain/dex/mod.rs index 5289c26..3f56c26 100644 --- a/src/domain/dex/mod.rs +++ b/src/domain/dex/mod.rs @@ -107,7 +107,6 @@ impl Swap { order: order::Order, gas_price: auction::GasPrice, sell_token: Option, - risk: &domain::Risk, simulator: &infra::dex::Simulator, ) -> Option { let gas = match simulator.gas(order.owner(), &self).await { @@ -117,9 +116,6 @@ impl Swap { return None; } }; - let score = solution::Score::RiskAdjusted(solution::SuccessProbability( - risk.success_probability(gas, gas_price, 1), - )); let allowance = self.allowance(); let interactions = vec![solution::Interaction::Custom(solution::CustomInteraction { @@ -139,7 +135,7 @@ impl Swap { interactions, gas, } - .into_solution(gas_price, sell_token, score) + .into_solution(gas_price, sell_token) } pub fn satisfies(&self, order: &domain::order::Order) -> bool { diff --git a/src/domain/mod.rs b/src/domain/mod.rs index 6a0434b..414298a 100644 --- a/src/domain/mod.rs +++ b/src/domain/mod.rs @@ -6,8 +6,5 @@ pub mod eth; pub mod liquidity; pub mod notification; pub mod order; -pub mod risk; pub mod solution; pub mod solver; - -pub use risk::Risk; diff --git a/src/domain/notification.rs b/src/domain/notification.rs index bdb52da..d8fbc14 100644 --- a/src/domain/notification.rs +++ b/src/domain/notification.rs @@ -2,7 +2,7 @@ use { super::{ auction, eth::{self, Ether, TokenAddress}, - solution::{self, SuccessProbability}, + solution, }, std::collections::BTreeSet, }; @@ -30,7 +30,6 @@ pub enum Kind { EmptySolution, DuplicatedSolutionId, SimulationFailed(BlockNo, Transaction, SimulationSucceededAtLeastOnce), - ScoringFailed(ScoreKind), NonBufferableTokensUsed(TokensUsed), SolverAccountInsufficientBalance(RequiredEther), Settled(Settlement), @@ -46,23 +45,6 @@ pub enum Settlement { Fail, } -#[derive(Debug)] -pub enum ScoreKind { - ZeroScore, - ScoreHigherThanQuality(Score, Quality), - SuccessProbabilityOutOfRange(SuccessProbability), - ObjectiveValueNonPositive(Quality, GasCost), -} - -#[derive(Debug, Copy, Clone)] -pub struct Score(pub eth::U256); - -impl From for Score { - fn from(value: eth::U256) -> Self { - Self(value) - } -} - #[derive(Debug, Copy, Clone)] pub struct Quality(pub eth::U256); diff --git a/src/domain/risk.rs b/src/domain/risk.rs deleted file mode 100644 index d74c6e3..0000000 --- a/src/domain/risk.rs +++ /dev/null @@ -1,26 +0,0 @@ -use super::{auction::GasPrice, eth::Gas}; - -/// Parameters that define the possibility of a revert when executing a -/// solution. -#[derive(Debug, Default, Clone)] -pub struct Risk { - pub gas_amount_factor: f64, - pub gas_price_factor: f64, - pub nmb_orders_factor: f64, - pub intercept: f64, -} - -impl Risk { - pub fn success_probability( - &self, - gas_amount: Gas, - gas_price: GasPrice, - nmb_orders: usize, - ) -> f64 { - let exponent = -self.intercept - - self.gas_amount_factor * gas_amount.0.to_f64_lossy() / 1_000_000. - - self.gas_price_factor * gas_price.0 .0.to_f64_lossy() / 10_000_000_000. - - self.nmb_orders_factor * nmb_orders as f64; - 1. / (1. + exponent.exp()) - } -} diff --git a/src/domain/solution.rs b/src/domain/solution.rs index 46534da..08cc03a 100644 --- a/src/domain/solution.rs +++ b/src/domain/solution.rs @@ -1,6 +1,6 @@ use { crate::{ - domain::{auction, eth, liquidity, order, solution, Risk}, + domain::{auction, eth, liquidity, order}, util, }, ethereum_types::{Address, U256}, @@ -23,7 +23,6 @@ pub struct Solution { pub prices: ClearingPrices, pub trades: Vec, pub interactions: Vec, - pub score: Score, pub gas: Option, } @@ -33,23 +32,6 @@ impl Solution { Self { id, ..self } } - /// Returns `self` with a new score. - pub fn with_score(self, score: Score) -> Self { - Self { score, ..self } - } - - pub fn with_risk_adjusted_score( - self, - risk: &Risk, - gas: eth::Gas, - gas_price: auction::GasPrice, - ) -> Self { - let nmb_orders = self.trades.len(); - self.with_score(Score::RiskAdjusted(SuccessProbability( - risk.success_probability(gas, gas_price, nmb_orders), - ))) - } - /// Returns `self` with eligible interactions internalized using the /// Settlement contract buffers. /// @@ -142,7 +124,6 @@ impl Single { self, gas_price: auction::GasPrice, sell_token: Option, - score: solution::Score, ) -> Option { let Self { order, @@ -210,7 +191,6 @@ impl Single { ]), trades: vec![Trade::Fulfillment(Fulfillment::new(order, executed, fee)?)], interactions, - score, gas: Some(self.gas), }) } @@ -387,34 +367,6 @@ pub struct Allowance { pub asset: eth::Asset, } -/// Represents the probability that a solution will be successfully settled. -#[derive(Debug, Copy, Clone)] -pub struct SuccessProbability(pub f64); - -impl From for SuccessProbability { - fn from(value: f64) -> Self { - Self(value) - } -} - -/// A score for a solution. The score is used to rank solutions. -#[derive(Debug, Clone)] -pub enum Score { - /// The score value is provided as is from solver. - /// Success probability is not incorporated into this value. - Solver(U256), - /// This option is used to indicate that the solver did not provide a score. - /// Instead, the score should be computed by the protocol given the success - /// probability. - RiskAdjusted(SuccessProbability), -} - -impl Default for Score { - fn default() -> Self { - Self::RiskAdjusted(SuccessProbability(1.0)) - } -} - // initial tx gas used to call the settle function from the settlement contract pub const INITIALIZATION_COST: u64 = 32_000; /// minimum gas every settlement takes (isSolver) diff --git a/src/domain/solver/dex/mod.rs b/src/domain/solver/dex/mod.rs index 3b222a8..756e33c 100644 --- a/src/domain/solver/dex/mod.rs +++ b/src/domain/solver/dex/mod.rs @@ -5,7 +5,6 @@ use { crate::{ boundary::rate_limiter::{RateLimiter, RateLimiterError}, domain::{ - self, auction, dex::{self, slippage}, order::{self, Order}, @@ -38,9 +37,6 @@ pub struct Dex { /// fillable orders). fills: Fills, - /// Parameters used to calculate the revert risk of a solution. - risk: domain::Risk, - /// Handles 429 Too Many Requests error with a retry mechanism rate_limiter: RateLimiter, } @@ -63,7 +59,6 @@ impl Dex { slippage: config.slippage, concurrent_requests: config.concurrent_requests, fills: Fills::new(config.smallest_partial_fill), - risk: config.risk, rate_limiter, } } @@ -181,7 +176,7 @@ impl Dex { let swap = self.try_solve(order, &dex_order, tokens, gas_price).await?; let sell = tokens.reference_price(&order.sell.token); let Some(solution) = swap - .into_solution(order.clone(), gas_price, sell, &self.risk, &self.simulator) + .into_solution(order.clone(), gas_price, sell, &self.simulator) .await else { tracing::debug!("no solution for swap"); diff --git a/src/infra/config/dex/file.rs b/src/infra/config/dex/file.rs index bd3f716..77464bd 100644 --- a/src/infra/config/dex/file.rs +++ b/src/infra/config/dex/file.rs @@ -3,7 +3,7 @@ use { crate::{ boundary::rate_limiter::RateLimitingStrategy, - domain::{dex::slippage, eth, Risk}, + domain::{dex::slippage, eth}, infra::{blockchain, config::unwrap_or_log, contracts}, util::serialize, }, @@ -45,10 +45,6 @@ struct Config { #[serde_as(as = "serialize::U256")] smallest_partial_fill: eth::U256, - /// 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), - /// Back-off growth factor for rate limiting. #[serde(default = "default_back_off_growth_factor")] back_off_growth_factor: f64, @@ -141,12 +137,6 @@ pub async fn load(path: &Path) -> (super::Config, T) { .expect("invalid slippage limits"), concurrent_requests: config.concurrent_requests, smallest_partial_fill: eth::Ether(config.smallest_partial_fill), - 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, - }, rate_limiting_strategy: RateLimitingStrategy::try_new( config.back_off_growth_factor, config.min_back_off, diff --git a/src/infra/config/dex/mod.rs b/src/infra/config/dex/mod.rs index 921d797..1e8f770 100644 --- a/src/infra/config/dex/mod.rs +++ b/src/infra/config/dex/mod.rs @@ -7,7 +7,7 @@ pub mod zeroex; use { crate::{ boundary::rate_limiter::RateLimitingStrategy, - domain::{dex::slippage, eth, Risk}, + domain::{dex::slippage, eth}, }, std::num::NonZeroUsize, }; @@ -25,7 +25,6 @@ pub struct Config { pub slippage: slippage::Limits, pub concurrent_requests: NonZeroUsize, pub smallest_partial_fill: eth::Ether, - pub risk: Risk, pub rate_limiting_strategy: RateLimitingStrategy, pub solution_gas_offset: eth::SignedGas, } diff --git a/src/tests/balancer/market_order.rs b/src/tests/balancer/market_order.rs index 0a5c58f..bff56fd 100644 --- a/src/tests/balancer/market_order.rs +++ b/src/tests/balancer/market_order.rs @@ -160,10 +160,6 @@ async fn sell() { ], } ], - "score": { - "kind": "riskAdjusted", - "successProbability": 0.5, - }, "gas": 195283, }] }), @@ -324,10 +320,6 @@ async fn buy() { ], } ], - "score": { - "kind": "riskAdjusted", - "successProbability": 0.5, - }, "gas": 195283, }] }), diff --git a/src/tests/balancer/mod.rs b/src/tests/balancer/mod.rs index 0a9d81d..fefcd72 100644 --- a/src/tests/balancer/mod.rs +++ b/src/tests/balancer/mod.rs @@ -9,7 +9,6 @@ pub fn config(solver_addr: &SocketAddr) -> tests::Config { tests::Config::String(format!( r" node-url = 'http://localhost:8545' -risk-parameters = [0,0,0,0] [dex] endpoint = 'http://{solver_addr}/sor' ", @@ -22,7 +21,6 @@ pub fn config_with_node(solver_addr: &SocketAddr, node: &SocketAddr) -> tests::C tests::Config::String(format!( r" node-url = 'http://{node}' -risk-parameters = [0,0,0,0] [dex] endpoint = 'http://{solver_addr}/sor' ", diff --git a/src/tests/dex/partial_fill.rs b/src/tests/dex/partial_fill.rs index 8b8fa99..e232542 100644 --- a/src/tests/dex/partial_fill.rs +++ b/src/tests/dex/partial_fill.rs @@ -127,7 +127,6 @@ async fn tested_amounts_adjust_depending_on_response() { let config = tests::Config::String(format!( r" node-url = 'http://{}' -risk-parameters = [0,0,0,0] [dex] endpoint = 'http://{}/sor' ", @@ -262,10 +261,6 @@ endpoint = 'http://{}/sor' "order": "0x2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a" } ], - "score": { - "kind": "riskAdjusted", - "successProbability": 0.5, - }, "gas": 195283, }] }) @@ -463,7 +458,6 @@ async fn moves_surplus_fee_to_buy_token() { let config = tests::Config::String(format!( r" node-url = 'http://{}' -risk-parameters = [0,0,0,0] [dex] endpoint = 'http://{}/sor' ", @@ -596,10 +590,6 @@ endpoint = 'http://{}/sor' "order": "0x2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a" } ], - "score": { - "kind": "riskAdjusted", - "successProbability": 0.5, - }, "gas": 195283, }] }) @@ -870,10 +860,6 @@ async fn market() { "order": "0x2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a" } ], - "score": { - "kind": "riskAdjusted", - "successProbability": 0.5, - }, "gas": 195283, }] }) diff --git a/src/tests/oneinch/market_order.rs b/src/tests/oneinch/market_order.rs index 0a1b211..4e3c851 100644 --- a/src/tests/oneinch/market_order.rs +++ b/src/tests/oneinch/market_order.rs @@ -211,10 +211,6 @@ async fn sell() { "order": "0x2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a" } ], - "score": { - "kind": "riskAdjusted", - "successProbability": 0.5, - }, "gas": 206391, } ] diff --git a/src/tests/oneinch/mod.rs b/src/tests/oneinch/mod.rs index 0d1f234..5dcb7e7 100644 --- a/src/tests/oneinch/mod.rs +++ b/src/tests/oneinch/mod.rs @@ -9,7 +9,6 @@ pub fn config(solver_addr: &SocketAddr) -> tests::Config { tests::Config::String(format!( r" node-url = 'http://localhost:8545' -risk-parameters = [0,0,0,0] [dex] chain-id = '1' endpoint = 'http://{solver_addr}' @@ -23,7 +22,6 @@ pub fn config_with_node(solver_addr: &SocketAddr, node: &SocketAddr) -> tests::C tests::Config::String(format!( r" node-url = 'http://{node}' -risk-parameters = [0,0,0,0] [dex] chain-id = '1' endpoint = 'http://{solver_addr}' diff --git a/src/tests/paraswap/market_order.rs b/src/tests/paraswap/market_order.rs index befe5e8..55a09d0 100644 --- a/src/tests/paraswap/market_order.rs +++ b/src/tests/paraswap/market_order.rs @@ -240,10 +240,6 @@ async fn sell() { "order": "0x2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a" } ], - "score": { - "kind": "riskAdjusted", - "successProbability": 0.5, - }, "gas": 348691, } ] @@ -501,10 +497,6 @@ async fn buy() { "order": "0x2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a" } ], - "score": { - "kind": "riskAdjusted", - "successProbability": 0.5, - }, "gas": 213326, } ] diff --git a/src/tests/paraswap/mod.rs b/src/tests/paraswap/mod.rs index 28de4cb..5f33dad 100644 --- a/src/tests/paraswap/mod.rs +++ b/src/tests/paraswap/mod.rs @@ -9,7 +9,6 @@ pub fn config(solver_addr: &SocketAddr) -> tests::Config { tests::Config::String(format!( r" node-url = 'http://localhost:8545' -risk-parameters = [0,0,0,0] [dex] endpoint = 'http://{solver_addr}' exclude-dexs = ['UniswapV2'] @@ -24,7 +23,6 @@ pub fn config_with_node(solver_addr: &SocketAddr, node: &SocketAddr) -> tests::C tests::Config::String(format!( r" node-url = 'http://{node}' -risk-parameters = [0,0,0,0] [dex] endpoint = 'http://{solver_addr}' exclude-dexs = ['UniswapV2'] diff --git a/src/tests/zeroex/market_order.rs b/src/tests/zeroex/market_order.rs index 043c7db..1815d11 100644 --- a/src/tests/zeroex/market_order.rs +++ b/src/tests/zeroex/market_order.rs @@ -191,10 +191,6 @@ async fn sell() { ], }, ], - "score": { - "kind": "riskAdjusted", - "successProbability": 0.5, - }, "gas": 234277, }] }), @@ -379,10 +375,6 @@ async fn buy() { ], }, ], - "score": { - "kind": "riskAdjusted", - "successProbability": 0.5, - }, "gas": 217391, }] }), diff --git a/src/tests/zeroex/mod.rs b/src/tests/zeroex/mod.rs index 5142eaa..d5c5279 100644 --- a/src/tests/zeroex/mod.rs +++ b/src/tests/zeroex/mod.rs @@ -10,7 +10,6 @@ pub fn config_with_node(solver_addr: &SocketAddr, node: &SocketAddr) -> tests::C tests::Config::String(format!( r" node-url = 'http://{node}' -risk-parameters = [0,0,0,0] [dex] endpoint = 'http://{solver_addr}/swap/v1/' api-key = 'SUPER_SECRET_API_KEY' @@ -25,7 +24,6 @@ pub fn config(solver_addr: &SocketAddr) -> tests::Config { tests::Config::String(format!( r" node-url = 'http://localhost:8545' -risk-parameters = [0,0,0,0] [dex] endpoint = 'http://{solver_addr}/swap/v1/' api-key = 'SUPER_SECRET_API_KEY' diff --git a/src/tests/zeroex/options.rs b/src/tests/zeroex/options.rs index 1e637f5..4b7898a 100644 --- a/src/tests/zeroex/options.rs +++ b/src/tests/zeroex/options.rs @@ -185,7 +185,6 @@ async fn test() { r" node-url = 'http://{}' relative-slippage = '0.1' -risk-parameters = [0,0,0,0] [dex] endpoint = 'http://{}/swap/v1/' api-key = 'abc123' @@ -294,10 +293,6 @@ enable-slippage-protection = true ], }, ], - "score": { - "kind": "riskAdjusted", - "successProbability": 0.5, - }, "gas": 234277, }] }),