Skip to content

Commit

Permalink
fix: bn to number division (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStefan authored Jul 8, 2024
1 parent 11e2b82 commit 3c00ad6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v5.0.13

### Fix:

- Bring BN division fix from @glitchful-dev/sol-apy-sdk

## v5.0.12

### Chore:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
9 changes: 7 additions & 2 deletions src/util/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 3c00ad6

Please sign in to comment.