"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bnMax = exports.toBN = exports.biMax = exports.biMin = exports.bnUint256Max = exports.bnUint32Max = exports.bnOne = exports.bnZero = exports.parseUnits = exports.parseEther = exports.formatUnits = exports.formatEther = void 0;
exports.toWei = toWei;
exports.toGWei = toGWei;
const tslib_1 = require("tslib");
const ethers_1 = require("ethers");
const bignumber_1 = require("@ethersproject/bignumber");
tslib_1.__exportStar(require("@ethersproject/bignumber"), exports);
exports.formatEther = ethers_1.utils.formatEther, exports.formatUnits = ethers_1.utils.formatUnits, exports.parseEther = ethers_1.utils.parseEther, exports.parseUnits = ethers_1.utils.parseUnits;
exports.bnZero = bignumber_1.BigNumber.from("0");
exports.bnOne = bignumber_1.BigNumber.from("1");
exports.bnUint32Max = bignumber_1.BigNumber.from("0xffffffff");
exports.bnUint256Max = bignumber_1.BigNumber.from("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
const biMin = (a, b) => (a > b ? b : a);
exports.biMin = biMin;
const biMax = (a, b) => (a > b ? a : b);
exports.biMax = biMax;
function toWei(num) {
    return ethers_1.utils.parseEther(num.toString());
}
function toGWei(num) {
    return ethers_1.utils.parseUnits(num.toString(), 9);
}
const toBN = (num, rounding = "floor") => {
    if (num.toString().includes(".")) {
        const [integer, decimal] = num.toString().split(".");
        const roundUp = decimal.length > 0 && (rounding === "ceil" || (rounding === "round" && parseInt(decimal[0]) >= 5));
        return bignumber_1.BigNumber.from(integer).add(roundUp ? 1 : 0);
    }
    return bignumber_1.BigNumber.from(num.toString());
};
exports.toBN = toBN;
const bnMax = (val, cmp) => {
    return val.gt(cmp) ? val : cmp;
};
exports.bnMax = bnMax;
//# sourceMappingURL=BigNumberUtils.js.map