From 0bcf1331bb1ede0aa2d5e486671b3af50e8e14fb Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem de Liz Date: Wed, 10 Jun 2026 18:21:15 -0300 Subject: [PATCH] refactor: use event.block.timestamp directly and type ComposableOrder.creationDate as bigint (COW-1007) blockHandler.ts used BigInt(Number(event.block.timestamp)) which unnecessarily round-trips through Number. orderbookClient's ComposableOrder declared creationDate as number, requiring a BigInt() cast at every DB insert site. Both are now consistent with the bigint column type and the rest of the codebase's timestamp handling. Co-Authored-By: Claude Sonnet 4.6 --- src/application/handlers/blockHandler.ts | 2 +- src/application/helpers/orderbookClient.ts | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/application/handlers/blockHandler.ts b/src/application/handlers/blockHandler.ts index dc5c822..0cf5ebe 100644 --- a/src/application/handlers/blockHandler.ts +++ b/src/application/handlers/blockHandler.ts @@ -192,7 +192,7 @@ ponder.on("OrderDiscoveryPoller:block", async ({ event, context }) => { buyAmount: orderData.buyAmount.toString(), feeAmount: orderData.feeAmount.toString(), validTo: orderData.validTo, - creationDate: BigInt(Number(event.block.timestamp)), + creationDate: event.block.timestamp, }) .onConflictDoNothing(), ); diff --git a/src/application/helpers/orderbookClient.ts b/src/application/helpers/orderbookClient.ts index 0b99df5..f6ea119 100644 --- a/src/application/helpers/orderbookClient.ts +++ b/src/application/helpers/orderbookClient.ts @@ -46,8 +46,7 @@ interface OrderbookOrder { } /** Processed composable order stored in cache and returned to callers. - * Shares field types with the discreteOrder schema for the DB-mapped fields. - * creationDate is number here (unix seconds) and converted to bigint at insert time. */ + * Shares field types with the discreteOrder schema for the DB-mapped fields. */ export type ComposableOrder = Pick< typeof discreteOrder.$inferInsert, "status" | "sellAmount" | "buyAmount" | "feeAmount" | "validTo" | "executedSellAmount" | "executedBuyAmount" @@ -56,7 +55,7 @@ export type ComposableOrder = Pick< generatorId: string; generatorHash: string; orderType: OrderType; - creationDate: number; + creationDate: bigint; }; /** Status + executed amounts returned by fetchOrderStatusByUids. */ @@ -187,7 +186,7 @@ export async function upsertDiscreteOrders( buyAmount: order.buyAmount, feeAmount: order.feeAmount, validTo: order.validTo, - creationDate: BigInt(order.creationDate), + creationDate: order.creationDate, executedSellAmount: order.executedSellAmount, executedBuyAmount: order.executedBuyAmount, }) @@ -278,7 +277,7 @@ export async function fetchOrderStatusByUids( buyAmount: order.buyAmount, feeAmount: order.feeAmount, validTo: order.validTo, - creationDate: 0, + creationDate: 0n, executedSellAmount: order.executedSellAmount, executedBuyAmount: order.executedBuyAmount, }); @@ -473,7 +472,7 @@ async function filterAndProcess( buyAmount: order.buyAmount, feeAmount: order.feeAmount, validTo: order.validTo, - creationDate: Math.floor(new Date(order.creationDate).getTime() / 1000), + creationDate: BigInt(Math.floor(new Date(order.creationDate).getTime() / 1000)), executedSellAmount: order.executedSellAmount, executedBuyAmount: order.executedBuyAmount, });