Skip to content

Commit 1c8a399

Browse files
committed
Migrate driver
1 parent decca80 commit 1c8a399

File tree

8 files changed

+321
-518
lines changed

8 files changed

+321
-518
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/driver/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ serde_json = { workspace = true }
4949
serde_with = { workspace = true }
5050
solvers-dto = { path = "../solvers-dto" }
5151
thiserror = { workspace = true }
52+
winner-selection = { path = "../winner-selection" }
5253
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal", "time"] }
5354
toml = { workspace = true }
5455
tower = { workspace = true }

crates/driver/src/domain/competition/mod.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,7 @@ impl Competition {
285285
.into_iter()
286286
.map(|settlement| {
287287
observe::scoring(&settlement);
288-
(
289-
settlement.score(
290-
&auction.native_prices(),
291-
auction.surplus_capturing_jit_order_owners(),
292-
),
293-
settlement,
294-
)
288+
(settlement.score(&auction), settlement)
295289
})
296290
.collect_vec();
297291

@@ -782,10 +776,7 @@ fn merge(
782776
merged.sort_by_key(|solution| {
783777
Reverse(
784778
solution
785-
.scoring(
786-
&auction.native_prices(),
787-
auction.surplus_capturing_jit_order_owners(),
788-
)
779+
.scoring(&auction)
789780
.map(|score| score.0)
790781
.unwrap_or_default(),
791782
)

crates/driver/src/domain/competition/solution/mod.rs

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use {
22
self::trade::{ClearingPrices, Fee, Fulfillment},
3-
super::auction,
43
crate::{
54
boundary,
65
domain::{
@@ -30,10 +29,10 @@ use {
3029
pub mod encoding;
3130
pub mod fee;
3231
pub mod interaction;
33-
pub mod scoring;
3432
pub mod settlement;
3533
pub mod slippage;
3634
pub mod trade;
35+
pub mod winner_selection;
3736

3837
pub use {error::Error, interaction::Interaction, settlement::Settlement, trade::Trade};
3938

@@ -235,42 +234,10 @@ impl Solution {
235234
}
236235

237236
/// JIT score calculation.
238-
pub fn scoring(
239-
&self,
240-
native_prices: &auction::Prices,
241-
surplus_capturing_jit_order_owners: &HashSet<eth::Address>,
242-
) -> Result<eth::Ether, error::Scoring> {
243-
let mut trades = Vec::with_capacity(self.trades.len());
244-
for trade in self.trades().iter().filter(|trade| {
245-
self.trade_count_for_scorable(trade, surplus_capturing_jit_order_owners)
246-
}) {
247-
// Solver generated fulfillment does not include the fee in the executed amount
248-
// for sell orders.
249-
let executed = match trade.side() {
250-
order::Side::Sell => (trade.executed().0 + trade.fee().0).into(),
251-
order::Side::Buy => trade.executed(),
252-
};
253-
let buy = trade.buy();
254-
let sell = trade.sell();
255-
let uniform_prices = ClearingPrices {
256-
sell: self
257-
.clearing_price(sell.token)
258-
.ok_or(error::Scoring::InvalidClearingPrices)?,
259-
buy: self
260-
.clearing_price(buy.token)
261-
.ok_or(error::Scoring::InvalidClearingPrices)?,
262-
};
263-
trades.push(scoring::Trade::new(
264-
sell,
265-
buy,
266-
trade.side(),
267-
executed,
268-
trade.custom_prices(&uniform_prices)?,
269-
trade.protocol_fees(),
270-
))
271-
}
272-
273-
scoring::compute_score(&trades, native_prices).map_err(error::Scoring::from)
237+
///
238+
/// Uses winner-selection crate for score computation to deduplicate logic.
239+
pub fn scoring(&self, auction: &competition::Auction) -> Result<eth::Ether, error::Scoring> {
240+
winner_selection::compute_score(self, auction, self.weth)
274241
}
275242

276243
/// Approval interactions necessary for encoding the settlement.
@@ -690,16 +657,6 @@ pub mod error {
690657
MissingPrice(TokenAddress),
691658
}
692659

693-
impl From<scoring::Error> for Scoring {
694-
fn from(value: scoring::Error) -> Self {
695-
match value {
696-
scoring::Error::MissingPrice(e) => Self::MissingPrice(e),
697-
scoring::Error::Math(e) => Self::Math(e),
698-
scoring::Error::Scoring(e) => e,
699-
}
700-
}
701-
}
702-
703660
#[derive(Debug, thiserror::Error)]
704661
pub enum Trade {
705662
#[error("orders with non solver determined gas cost fees are not supported")]

0 commit comments

Comments
 (0)