Skip to content

Commit

Permalink
Cleanup score (#2585)
Browse files Browse the repository at this point in the history
# Description
Fixes #2493
Fixes #1494

Important notes:
1. ~Removed risk parameter config from solvers - requires cleanup of
"riskParameters" in infrastructure repo~ - will be done in a separate PR
2. Solvers api "score" field is optional until solvers update their
responses - will be removed completely
#2588.

Follow ups:
1. cleanup of "riskParameters" in infrastructure repo
3. Update gnosis solvers response
https://github.com/gnosis/solvers/blob/main/src/api/routes/solve/dto/solution.rs
- gnosis/solvers#10
4. Add more score errors to notify endpoint -
#2597

## How to test
Existing tests. No change in behaviour is expected.
  • Loading branch information
sunce86 authored Apr 5, 2024
1 parent 6c17db6 commit 0adc355
Show file tree
Hide file tree
Showing 53 changed files with 55 additions and 1,436 deletions.
1 change: 0 additions & 1 deletion crates/driver/src/boundary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
pub mod liquidity;
pub mod quote;
pub mod score;
pub mod settlement;

// The [`anyhow::Error`] type is re-exported because the legacy code mostly
Expand Down
31 changes: 0 additions & 31 deletions crates/driver/src/boundary/score.rs

This file was deleted.

56 changes: 1 addition & 55 deletions crates/driver/src/boundary/settlement.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
use {
crate::{
boundary,
domain::{
competition::{
self,
auction,
order,
score,
solution::settlement::{self, Internalization},
},
eth,
liquidity,
},
infra::Ethereum,
util::conv::u256::U256Ext,
},
anyhow::{anyhow, Context, Ok, Result},
app_data::AppDataHash,
Expand All @@ -35,10 +32,7 @@ use {
},
shared::{
external_prices::ExternalPrices,
http_solver::{
self,
model::{InternalizationStrategy, TokenAmount},
},
http_solver::model::{InternalizationStrategy, TokenAmount},
},
solver::{
interactions::Erc20ApproveInteraction,
Expand Down Expand Up @@ -159,17 +153,6 @@ impl Settlement {
);
}

settlement.score = match solution.score().clone() {
competition::SolverScore::Solver(score) => http_solver::model::Score::Solver { score },
competition::SolverScore::RiskAdjusted(success_probability) => {
http_solver::model::Score::RiskAdjusted {
success_probability,
gas_amount: None,
}
}
competition::SolverScore::Surplus => http_solver::model::Score::Surplus,
};

Ok(Self {
inner: settlement,
solver: solution.solver().address(),
Expand Down Expand Up @@ -205,43 +188,6 @@ impl Settlement {
}
}

pub fn score(&self) -> competition::SolverScore {
match self.inner.score {
http_solver::model::Score::Solver { score } => competition::SolverScore::Solver(score),
http_solver::model::Score::RiskAdjusted {
success_probability,
..
} => competition::SolverScore::RiskAdjusted(success_probability),
http_solver::model::Score::Surplus => competition::SolverScore::Surplus,
}
}

/// Observed quality of the settlement defined as surplus + fees.
pub fn quality(
&self,
eth: &Ethereum,
auction: &competition::Auction,
) -> Result<score::Quality, boundary::Error> {
let prices = ExternalPrices::try_from_auction_prices(
eth.contracts().weth().address(),
auction
.tokens()
.iter()
.filter_map(|token| {
token
.price
.map(|price| (token.address.into(), price.into()))
})
.collect(),
)?;

let surplus = self.inner.total_surplus(&prices);
let scoring_fees = self.inner.total_scoring_fees(&prices);
let quality = surplus + scoring_fees;

Ok(eth::U256::from_big_rational(&quality)?.into())
}

pub fn clearing_prices(&self) -> HashMap<eth::TokenAddress, eth::TokenAmount> {
self.inner
.clearing_prices()
Expand Down
14 changes: 3 additions & 11 deletions crates/driver/src/domain/competition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@ use {

pub mod auction;
pub mod order;
pub mod score;
pub mod solution;

pub use {
auction::{Auction, AuctionProcessor},
order::Order,
score::{
risk::{ObjectiveValue, SuccessProbability},
Score,
},
solution::{Solution, SolverScore},
solution::Solution,
};

/// An ongoing competition. There is one competition going on per solver at any
Expand Down Expand Up @@ -149,10 +144,7 @@ impl Competition {
.into_iter()
.map(|settlement| {
observe::scoring(&settlement);
(
settlement.score(&self.eth, auction, &self.mempools.revert_protection()),
settlement,
)
(settlement.score(&auction.prices()), settlement)
})
.collect_vec();

Expand Down Expand Up @@ -366,7 +358,7 @@ fn merge(solutions: impl Iterator<Item = Solution>, auction: &Auction) -> Vec<So
/// ranking happens.
#[derive(Debug)]
pub struct Solved {
pub score: Score,
pub score: eth::Ether,
pub trades: HashMap<order::Uid, Amounts>,
pub prices: HashMap<eth::TokenAddress, eth::TokenAmount>,
pub gas: Option<eth::Gas>,
Expand Down
157 changes: 0 additions & 157 deletions crates/driver/src/domain/competition/score.rs

This file was deleted.

Loading

0 comments on commit 0adc355

Please sign in to comment.