From 2e170551f651c9c6e142bd12f24ae81cc409e858 Mon Sep 17 00:00:00 2001 From: zhengyutay Date: Mon, 15 Nov 2021 19:05:52 +0800 Subject: [PATCH] fix: bn overflow error --- packages/serum/src/market.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/serum/src/market.ts b/packages/serum/src/market.ts index a2b10475..884d1173 100644 --- a/packages/serum/src/market.ts +++ b/packages/serum/src/market.ts @@ -1541,10 +1541,12 @@ function getPriceFromKey(key) { } function divideBnToNumber(numerator: BN, denominator: BN): number { - const quotient = numerator.div(denominator).toNumber(); + const quotient = numerator.div(denominator); const rem = numerator.umod(denominator); const gcd = rem.gcd(denominator); - return quotient + rem.div(gcd).toNumber() / denominator.div(gcd).toNumber(); + return Number( + quotient.add(rem.div(gcd).div(denominator.div(gcd))).toString(), + ); } const MINT_LAYOUT = struct([blob(44), u8('decimals'), blob(37)]);