|
1 | 1 | use { |
2 | 2 | self::trade::{ClearingPrices, Fee, Fulfillment}, |
3 | | - super::auction, |
4 | 3 | crate::{ |
5 | 4 | boundary, |
6 | 5 | domain::{ |
@@ -30,10 +29,10 @@ use { |
30 | 29 | pub mod encoding; |
31 | 30 | pub mod fee; |
32 | 31 | pub mod interaction; |
33 | | -pub mod scoring; |
34 | 32 | pub mod settlement; |
35 | 33 | pub mod slippage; |
36 | 34 | pub mod trade; |
| 35 | +pub mod winner_selection; |
37 | 36 |
|
38 | 37 | pub use {error::Error, interaction::Interaction, settlement::Settlement, trade::Trade}; |
39 | 38 |
|
@@ -235,42 +234,10 @@ impl Solution { |
235 | 234 | } |
236 | 235 |
|
237 | 236 | /// 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) |
274 | 241 | } |
275 | 242 |
|
276 | 243 | /// Approval interactions necessary for encoding the settlement. |
@@ -690,16 +657,6 @@ pub mod error { |
690 | 657 | MissingPrice(TokenAddress), |
691 | 658 | } |
692 | 659 |
|
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 | | - |
703 | 660 | #[derive(Debug, thiserror::Error)] |
704 | 661 | pub enum Trade { |
705 | 662 | #[error("orders with non solver determined gas cost fees are not supported")] |
|
0 commit comments