From e9c11f14949e4554faee06574d89773c28c2a55e Mon Sep 17 00:00:00 2001 From: TaprootFreak <142087526+TaprootFreak@users.noreply.github.com> Date: Mon, 11 May 2026 00:23:33 +0200 Subject: [PATCH] fix(monitoringV2): cast NUMERIC columns to text in challenge raw query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `findActiveWithChallengePeriod` selects `size` and `current_price` from `challenge_states`, both NUMERIC(78,0). Prisma's `$queryRaw` was materialising the values as JS `number`, which loses precision for values beyond 2^53 and serialises them via `.toString()` in scientific notation (e.g. `2.8391...e+22`). `BigInt()` does not accept that format, so the monitoring cycle crashed with "Cannot convert to a BigInt" on mainnet — JDM has challenges over 28391.7 JUSD (28.4e21 wei), JDT does not, which is why only JDM was affected. Fix mirrors the pattern already used in `position.repository.ts`: explicit `::text` casts in the SQL, typed as `string` in the row shape, then `BigInt(r.size)` directly without an intermediate `.toString()`. --- .../prisma/repositories/challenge.repository.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/monitoringV2/prisma/repositories/challenge.repository.ts b/src/monitoringV2/prisma/repositories/challenge.repository.ts index 2d62578..48bcdf6 100644 --- a/src/monitoringV2/prisma/repositories/challenge.repository.ts +++ b/src/monitoringV2/prisma/repositories/challenge.repository.ts @@ -88,15 +88,18 @@ export class ChallengeRepository { challenger_address: string; position_address: string; start_timestamp: bigint; - size: any; - current_price: any; + size: string; + current_price: string; t24_alerted: boolean; t2_alerted: boolean; challenge_period: bigint | null; }> >` SELECT c.challenge_id, c.hub_address, c.challenger_address, c.position_address, - c.start_timestamp, c.size, c.current_price, c.t24_alerted, c.t2_alerted, + c.start_timestamp, + c.size::text as size, + c.current_price::text as current_price, + c.t24_alerted, c.t2_alerted, p.challenge_period FROM challenge_states c LEFT JOIN position_states p ON p.address = c.position_address @@ -127,8 +130,8 @@ export class ChallengeRepository { challengerAddress: r.challenger_address, positionAddress: r.position_address, startTimestamp: BigInt(r.start_timestamp), - size: BigInt(r.size.toString()), - currentPrice: BigInt(r.current_price.toString()), + size: BigInt(r.size), + currentPrice: BigInt(r.current_price), t24Alerted: r.t24_alerted, t2Alerted: r.t2_alerted, challengePeriod: BigInt(r.challenge_period),