Skip to content

Commit

Permalink
Mark expired ethflow orders as such (#778)
Browse files Browse the repository at this point in the history
Calculates the expired status based on the ethflow valid to.

Test Plan
Added unit tests
  • Loading branch information
josojo committed Nov 15, 2022
1 parent 6209cba commit cd5c349
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
11 changes: 11 additions & 0 deletions crates/database/src/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,17 @@ pub struct FullOrder {
pub surplus_fee_timestamp: Option<DateTime<Utc>>,
}

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.
Expand Down
12 changes: 11 additions & 1 deletion crates/orderbook/src/database/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit cd5c349

Please sign in to comment.