Skip to content

Commit

Permalink
feat(units): add units to BigNumber static
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Oct 14, 2022
1 parent 0dfec56 commit d81f802
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { formatUnits, parseUnits } from "@ethersproject/units";

import { avgUp, max, min, mulDivUp, pow10 } from "./utils";

const PERCENT = pow10(4);
const WAD = pow10(18);
const RAY = pow10(27);
export const PERCENT = pow10(4);
export const WAD = pow10(18);
export const RAY = pow10(27);

const RAY_WAD_RATIO = RAY.div(WAD);
const HALF_RAY_WAD_RATIO = RAY_WAD_RATIO.div(2);
Expand Down Expand Up @@ -54,6 +54,10 @@ declare module "@ethersproject/bignumber/lib/bignumber" {
}

namespace BigNumber {
let PERCENT: BigNumber;
let WAD: BigNumber;
let RAY: BigNumber;

let pow10: (power: BigNumberish) => BigNumber;
let parsePercent: (value: string) => BigNumber;
let parseWad: (value: string) => BigNumber;
Expand Down Expand Up @@ -153,6 +157,10 @@ BigNumber.prototype.formatRay = function () {
return formatUnits(this, 27);
};

BigNumber.PERCENT = PERCENT;
BigNumber.WAD = WAD;
BigNumber.RAY = RAY;

BigNumber.pow10 = pow10;
BigNumber.parsePercent = function (value: string) {
return parseUnits(value, 2);
Expand Down

0 comments on commit d81f802

Please sign in to comment.