From 3c00ad66eb58d4729887ad78330982bd3c360893 Mon Sep 17 00:00:00 2001 From: "Alexandru.Stefan" Date: Mon, 8 Jul 2024 22:54:39 +0300 Subject: [PATCH] fix: bn to number division (#70) --- CHANGELOG.md | 6 ++++++ package.json | 2 +- src/util/conversion.ts | 9 +++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ca0e9f..1ff5897 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v5.0.13 + +### Fix: + + - Bring BN division fix from @glitchful-dev/sol-apy-sdk + ## v5.0.12 ### Chore: diff --git a/package.json b/package.json index 5ccc0e1..1e7fd42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@marinade.finance/marinade-ts-sdk", - "version": "5.0.12", + "version": "5.0.13", "description": "Marinade SDK for Typescript", "main": "dist/src/index.js", "repository": { diff --git a/src/util/conversion.ts b/src/util/conversion.ts index 12a1265..b64328b 100644 --- a/src/util/conversion.ts +++ b/src/util/conversion.ts @@ -25,10 +25,15 @@ export function divideBnToNumber(numerator: BN, denominator: BN): number { if (denominator.isZero()) { return 0 } - 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() + + const quotientNumber = parseFloat(quotient.toString()) + const remNumber = parseFloat(rem.div(gcd).toString()) + const denominatorNumber = parseFloat(denominator.div(gcd).toString()) + + return quotientNumber + remNumber / denominatorNumber } export function calcLamportsWithdrawAmount(