diff --git a/crates/autopilot/src/database/competition.rs b/crates/autopilot/src/database/competition.rs index 2dbea2e58c..8ede03bf10 100644 --- a/crates/autopilot/src/database/competition.rs +++ b/crates/autopilot/src/database/competition.rs @@ -82,17 +82,13 @@ impl super::Postgres { .context("solver_competition::save")?; for order_execution in &competition.order_executions { - let solver_fee = order_execution - .executed_fee - .fee() - .copied() - .unwrap_or_default(); + let solver_fee = order_execution.executed_fee.fee().map(u256_to_big_decimal); database::order_execution::save( &mut ex, &ByteArray(order_execution.order_id.0), competition.auction_id, None, - &u256_to_big_decimal(&solver_fee), + solver_fee.as_ref(), ) .await .context("order_execution::save")?; diff --git a/crates/database/src/order_execution.rs b/crates/database/src/order_execution.rs index f9710c49eb..fed8f6f7bd 100644 --- a/crates/database/src/order_execution.rs +++ b/crates/database/src/order_execution.rs @@ -10,7 +10,7 @@ pub async fn save( order: &OrderUid, auction: AuctionId, surplus_fee: Option<&BigDecimal>, - solver_fee: &BigDecimal, + solver_fee: Option<&BigDecimal>, ) -> Result<(), sqlx::Error> { const QUERY: &str = r#" INSERT INTO order_execution (order_uid, auction_id, reward, surplus_fee, solver_fee) @@ -60,7 +60,7 @@ mod tests { let mut db = db.begin().await.unwrap(); crate::clear_DANGER_(&mut db).await.unwrap(); - save(&mut db, &Default::default(), 0, None, &Default::default()) + save(&mut db, &Default::default(), 0, None, Default::default()) .await .unwrap(); @@ -69,7 +69,7 @@ mod tests { &Default::default(), 1, Some(&Default::default()), - &Default::default(), + Default::default(), ) .await .unwrap(); diff --git a/crates/database/src/orders.rs b/crates/database/src/orders.rs index d79828ae77..8b29c381b0 100644 --- a/crates/database/src/orders.rs +++ b/crates/database/src/orders.rs @@ -1826,7 +1826,7 @@ mod tests { let fee: BigDecimal = 1.into(); let solver_fee: BigDecimal = 2.into(); - crate::order_execution::save(&mut db, &order_uid, 0, Some(&fee), &solver_fee) + crate::order_execution::save(&mut db, &order_uid, 0, Some(&fee), Some(&solver_fee)) .await .unwrap(); @@ -1878,7 +1878,7 @@ mod tests { &order_uid, auction_id, None, - &bigdecimal(463182886014406361088), + Some(&bigdecimal(463182886014406361088)), ) .await .unwrap(); @@ -1958,10 +1958,10 @@ mod tests { insert_order(&mut db, &order).await.unwrap(); - crate::order_execution::save(&mut db, &order.uid, 1, None, &bigdecimal(1)) + crate::order_execution::save(&mut db, &order.uid, 1, None, Some(&bigdecimal(1))) .await .unwrap(); - crate::order_execution::save(&mut db, &order.uid, 42, None, &bigdecimal(42)) + crate::order_execution::save(&mut db, &order.uid, 42, None, Some(&bigdecimal(42))) .await .unwrap(); diff --git a/crates/e2e/tests/e2e/colocation_partial_fill.rs b/crates/e2e/tests/e2e/colocation_partial_fill.rs index c517908aac..f780f7596c 100644 --- a/crates/e2e/tests/e2e/colocation_partial_fill.rs +++ b/crates/e2e/tests/e2e/colocation_partial_fill.rs @@ -2,7 +2,7 @@ use { e2e::{setup::*, tx, tx_value}, ethcontract::U256, model::{ - order::{OrderCreation, OrderKind}, + order::{LimitOrderClass, OrderClass, OrderCreation, OrderKind}, signature::EcdsaSigningScheme, }, secp256k1::SecretKey, @@ -73,7 +73,7 @@ async fn test(web3: Web3) { &onchain.contracts().domain_separator, SecretKeyRef::from(&SecretKey::from_slice(trader.private_key()).unwrap()), ); - services.create_order(&order).await.unwrap(); + let uid = services.create_order(&order).await.unwrap(); tracing::info!("Waiting for trade."); let trade_happened = @@ -99,6 +99,25 @@ async fn test(web3: Web3) { .contains(&buy_balance.as_u128()) ); - // TODO: test that we have other important per-auction data that should have - // made its way into the DB. + onchain.mint_blocks_past_reorg_threshold().await; + + let settlement_event_processed = || async { + let order = services.get_order(&uid).await.unwrap(); + if let OrderClass::Limit(LimitOrderClass { + executed_surplus_fee, + }) = order.metadata.class + { + executed_surplus_fee > U256::zero() + } else { + panic!("order is not a limit order"); + } + }; + wait_for_condition(TIMEOUT, settlement_event_processed) + .await + .unwrap(); + + let tx_hash = services.get_trades(&uid).await.unwrap()[0].tx_hash.unwrap(); + let competition = services.get_solver_competition(tx_hash).await.unwrap(); + assert!(!competition.common.solutions.is_empty()); + assert!(competition.common.auction.orders.contains(&uid)); } diff --git a/crates/orderbook/src/database/solver_competition.rs b/crates/orderbook/src/database/solver_competition.rs index 6faddd0b11..ca1f541e5d 100644 --- a/crates/orderbook/src/database/solver_competition.rs +++ b/crates/orderbook/src/database/solver_competition.rs @@ -46,7 +46,7 @@ impl SolverCompetitionStoring for Postgres { &ByteArray(order.0), request.auction, surplus_fee.as_ref(), - &u256_to_big_decimal(&execution.solver_fee), + Some(&u256_to_big_decimal(&execution.solver_fee)), ) .await .context("order_execution::save")?;