|
2 | 2 | crate::{
|
3 | 3 | boundary,
|
4 | 4 | database::{order_events::store_order_events, Postgres},
|
5 |
| - domain::{self, competition, eth}, |
| 5 | + domain::{self, eth}, |
6 | 6 | infra::persistence::dto::AuctionId,
|
7 | 7 | },
|
8 | 8 | anyhow::Context,
|
|
26 | 26 | },
|
27 | 27 | futures::{StreamExt, TryStreamExt},
|
28 | 28 | number::conversions::{big_decimal_to_u256, u256_to_big_decimal, u256_to_big_uint},
|
29 |
| - primitive_types::{H160, H256}, |
| 29 | + primitive_types::H256, |
30 | 30 | shared::db_order_conversions::full_order_into_model_order,
|
31 | 31 | std::{
|
32 | 32 | collections::{HashMap, HashSet},
|
@@ -313,94 +313,6 @@ impl Persistence {
|
313 | 313 | })
|
314 | 314 | }
|
315 | 315 |
|
316 |
| - /// Returns the proposed solver solution that won the competition for a |
317 |
| - /// given auction. |
318 |
| - /// |
319 |
| - /// It is expected for a solution to exist, so missing data is considered an |
320 |
| - /// error. |
321 |
| - /// |
322 |
| - /// Returns error for old non-colocated auctions. |
323 |
| - pub async fn get_winning_solution( |
324 |
| - &self, |
325 |
| - auction_id: domain::auction::Id, |
326 |
| - ) -> Result<domain::competition::Solution, error::Solution> { |
327 |
| - let _timer = Metrics::get() |
328 |
| - .database_queries |
329 |
| - .with_label_values(&["get_competition_winner"]) |
330 |
| - .start_timer(); |
331 |
| - |
332 |
| - let mut ex = self |
333 |
| - .postgres |
334 |
| - .pool |
335 |
| - .begin() |
336 |
| - .await |
337 |
| - .map_err(error::Solution::DatabaseError)?; |
338 |
| - |
339 |
| - let competition = database::settlement_scores::fetch(&mut ex, auction_id) |
340 |
| - .await |
341 |
| - .map_err(error::Solution::DatabaseError)? |
342 |
| - .ok_or(error::Solution::NotFound)?; |
343 |
| - |
344 |
| - let winner = H160(competition.winner.0).into(); |
345 |
| - let score = competition::Score::new( |
346 |
| - big_decimal_to_u256(&competition.winning_score) |
347 |
| - .ok_or(error::Solution::InvalidScore(anyhow::anyhow!( |
348 |
| - "database score" |
349 |
| - )))? |
350 |
| - .into(), |
351 |
| - ) |
352 |
| - .map_err(|err| error::Solution::InvalidScore(anyhow::anyhow!("score, {}", err)))?; |
353 |
| - |
354 |
| - let solution = { |
355 |
| - // TODO: stabilize the solver competition table to get promised solution. |
356 |
| - let solver_competition = database::solver_competition::load_by_id(&mut ex, auction_id) |
357 |
| - .await |
358 |
| - .map_err(error::Solution::DatabaseError)? |
359 |
| - .ok_or(error::Solution::NotFound)?; |
360 |
| - let competition: model::solver_competition::SolverCompetitionDB = |
361 |
| - serde_json::from_value(solver_competition.json) |
362 |
| - .context("deserialize SolverCompetitionDB") |
363 |
| - .map_err(error::Solution::InvalidSolverCompetition)?; |
364 |
| - let winning_solution = competition |
365 |
| - .solutions |
366 |
| - .last() |
367 |
| - .ok_or(error::Solution::NotFound)?; |
368 |
| - let mut orders = HashMap::new(); |
369 |
| - for order in winning_solution.orders.iter() { |
370 |
| - match order { |
371 |
| - model::solver_competition::Order::Colocated { |
372 |
| - id, |
373 |
| - sell_amount, |
374 |
| - buy_amount, |
375 |
| - } => { |
376 |
| - orders.insert( |
377 |
| - domain::OrderUid(id.0), |
378 |
| - competition::TradedAmounts { |
379 |
| - sell: (*sell_amount).into(), |
380 |
| - buy: (*buy_amount).into(), |
381 |
| - }, |
382 |
| - ); |
383 |
| - } |
384 |
| - model::solver_competition::Order::Legacy { |
385 |
| - id: _, |
386 |
| - executed_amount: _, |
387 |
| - } => return Err(error::Solution::NotFound), |
388 |
| - } |
389 |
| - } |
390 |
| - let mut prices = HashMap::new(); |
391 |
| - for (token, price) in winning_solution.clearing_prices.clone().into_iter() { |
392 |
| - prices.insert( |
393 |
| - token.into(), |
394 |
| - domain::auction::Price::new(price.into()) |
395 |
| - .map_err(|_| error::Solution::InvalidPrice(eth::TokenAddress(token)))?, |
396 |
| - ); |
397 |
| - } |
398 |
| - competition::Solution::new(winner, score, orders, prices) |
399 |
| - }; |
400 |
| - |
401 |
| - Ok(solution) |
402 |
| - } |
403 |
| - |
404 | 316 | /// Computes solvable orders based on the latest observed block number,
|
405 | 317 | /// order creation timestamp, and minimum validity period.
|
406 | 318 | pub async fn solvable_orders_after(
|
@@ -746,18 +658,4 @@ pub mod error {
|
746 | 658 | #[error("invalid price fetched from database for token: {0:?}")]
|
747 | 659 | InvalidPrice(eth::TokenAddress),
|
748 | 660 | }
|
749 |
| - |
750 |
| - #[derive(Debug, thiserror::Error)] |
751 |
| - pub enum Solution { |
752 |
| - #[error("failed communication with the database: {0}")] |
753 |
| - DatabaseError(#[from] sqlx::Error), |
754 |
| - #[error("solution not found")] |
755 |
| - NotFound, |
756 |
| - #[error("invalid score fetched from database: {0}")] |
757 |
| - InvalidScore(anyhow::Error), |
758 |
| - #[error("invalid price fetched from database for token: {0:?}")] |
759 |
| - InvalidPrice(eth::TokenAddress), |
760 |
| - #[error("invalid solver competition data fetched from database: {0}")] |
761 |
| - InvalidSolverCompetition(anyhow::Error), |
762 |
| - } |
763 | 661 | }
|
0 commit comments