From cd5c34911fa8d93b38f5978c59c311378123dd73 Mon Sep 17 00:00:00 2001 From: josojo Date: Tue, 15 Nov 2022 22:20:55 +0100 Subject: [PATCH] Mark expired ethflow orders as such (#778) Calculates the expired status based on the ethflow valid to. Test Plan Added unit tests --- crates/database/src/orders.rs | 11 +++++++++++ crates/orderbook/src/database/orders.rs | 12 +++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/database/src/orders.rs b/crates/database/src/orders.rs index af0b8fe442..68cfba2316 100644 --- a/crates/database/src/orders.rs +++ b/crates/database/src/orders.rs @@ -378,6 +378,17 @@ pub struct FullOrder { pub surplus_fee_timestamp: Option>, } +impl FullOrder { + pub fn valid_to(&self) -> i64 { + if let Some((_, valid_to)) = self.ethflow_data { + // For ethflow orders, we always return the user valid_to, + // as the Eip1271 valid to is u32::max + return valid_to; + } + self.valid_to + } +} + // When querying orders we have several specialized use cases working with their own filtering, // ordering, indexes. The parts that are shared between all queries are defined here so they can be // reused. diff --git a/crates/orderbook/src/database/orders.rs b/crates/orderbook/src/database/orders.rs index 29efadf8f0..819ecb952d 100644 --- a/crates/orderbook/src/database/orders.rs +++ b/crates/orderbook/src/database/orders.rs @@ -315,7 +315,7 @@ fn calculate_status(order: &FullOrder) -> OrderStatus { if order.invalidated { return OrderStatus::Cancelled; } - if order.valid_to < Utc::now().timestamp() { + if order.valid_to() < Utc::now().timestamp() { return OrderStatus::Expired; } if order.presignature_pending { @@ -629,6 +629,16 @@ mod tests { }), OrderStatus::Expired ); + + // Expired - for ethflow orders + assert_eq!( + calculate_status(&FullOrder { + invalidated: false, + ethflow_data: Some((false, valid_to_yesterday.timestamp())), + ..order_row() + }), + OrderStatus::Expired + ); } #[tokio::test]