Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/autopilot/src/run_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ impl RunLoop {
.map(|(index, bid)| SolverSettlement {
solver: bid.driver().name.clone(),
solver_address: bid.solution().solver(),
score: Some(Score::Solver(bid.score().get().0)),
score: Some(Score::Protocol(bid.score().get().0)),
ranking: index + 1,
orders: bid
.solution()
Expand Down
4 changes: 1 addition & 3 deletions crates/driver/src/domain/competition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,9 @@ impl Competition {
let scored: Vec<(Solved, Settlement)> = scores
.into_iter()
.sorted_by_key(|(score, _)| Reverse(*score))
.map(|(score, settlement)| {
.map(|(_, settlement)| {
let solved = Solved {
id: settlement.solution().clone(),
score,
trades: settlement.orders(),
prices: settlement.prices(),
gas: Some(settlement.gas.estimate),
Expand Down Expand Up @@ -1009,7 +1008,6 @@ fn merge(
#[derive(Debug)]
pub struct Solved {
pub id: solution::Id,
pub score: eth::Ether,
pub trades: HashMap<order::Uid, Amounts>,
pub prices: HashMap<eth::TokenAddress, eth::TokenAmount>,
pub gas: Option<eth::Gas>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ impl Solution {
pub fn new(solution_id: u64, solved: competition::Solved, solver: &Solver) -> Self {
Self {
solution_id,
score: solved.score.0,
submission_address: solver.address(),
orders: solved
.trades
Expand Down Expand Up @@ -72,8 +71,6 @@ pub struct Solution {
/// in subsequent requests (reveal, settle).
solution_id: u64,
submission_address: eth::Address,
#[serde_as(as = "serde_ext::U256")]
score: eth::U256,
#[serde_as(as = "HashMap<serde_ext::Hex, _>")]
orders: HashMap<OrderId, TradedOrder>,
#[serde_as(as = "HashMap<_, serde_ext::U256>")]
Expand Down
25 changes: 20 additions & 5 deletions crates/model/src/solver_competition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,14 @@ pub struct SolverSettlement {
#[serde_as]
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)]
pub enum Score {
/// The score is provided by the solver.
/// [DEPRECATED] Kept to not break the solver competition API.
#[serde(rename = "score")]
Solver(#[serde_as(as = "HexOrDecimalU256")] U256),
/// The score is calculated by the protocol (and equal to the objective
/// function).
#[serde(rename = "scoreProtocol")]
Protocol(#[serde_as(as = "HexOrDecimalU256")] U256),
/// The score is calculated by the protocol and success_probability provided
/// by solver is taken into account
/// [DEPRECATED] Kept to not break the solver competition API.
#[serde(rename = "scoreProtocolWithSolverRisk")]
ProtocolWithSolverRisk(#[serde_as(as = "HexOrDecimalU256")] U256),
/// The score is calculated by the protocol, by applying a discount to the
Expand Down Expand Up @@ -151,7 +150,7 @@ mod tests {
{
"solver": "2",
"solverAddress": "0x2222222222222222222222222222222222222222",
"score": "1",
"scoreProtocol": "1",
"ranking": 1,
"clearingPrices": {
"0x2222222222222222222222222222222222222222": "8",
Expand Down Expand Up @@ -196,7 +195,7 @@ mod tests {
solutions: vec![SolverSettlement {
solver: "2".to_string(),
solver_address: Address::repeat_byte(0x22),
score: Some(Score::Solver(U256::ONE)),
score: Some(Score::Protocol(U256::ONE)),
ranking: 1,
clearing_prices: btreemap! {
Address::repeat_byte(0x22) => U256::from(8),
Expand Down Expand Up @@ -378,4 +377,20 @@ mod tests {
});
assert!(serde_json::from_value::<SolverCompetitionAPI>(competition).is_ok())
}

#[test]
fn score_protocol_round_trip() {
let score = Score::Protocol(U256::from(42));
let json = serde_json::to_value(&score).unwrap();
assert_eq!(json, serde_json::json!({"scoreProtocol": "42"}));
let deserialized: Score = serde_json::from_value(json).unwrap();
assert_eq!(deserialized, score);
}

#[test]
fn score_solver_legacy_deserialize() {
let json = serde_json::json!({"score": "100"});
let score: Score = serde_json::from_value(json).unwrap();
assert_eq!(score, Score::Solver(U256::from(100)));
}
}
Loading