Skip to content

Commit

Permalink
feat: try catch for getHumanPrice and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasDeco committed Sep 9, 2024
1 parent 0609605 commit a741c85
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions sdk/src/utils/priceMath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ export class PriceMath {
baseDecimals: number,
quoteDecimals: number
): number {
let decimalScalar = BN_TEN.pow(new BN(quoteDecimals - baseDecimals).abs());

let price1e12 =
const decimalScalar = BN_TEN.pow(
new BN(quoteDecimals - baseDecimals).abs()
);
const price1e12 =
quoteDecimals > baseDecimals
? ammPrice.div(decimalScalar)
: ammPrice.mul(decimalScalar);

return price1e12.toNumber() / 1e12;

try {
return price1e12.toNumber() / 1e12;
} catch (e) {
return price1e12.div(new BN(1e12)).toNumber();
}
}

public static getAmmPrice(
Expand Down

0 comments on commit a741c85

Please sign in to comment.