@volare.finance/utils.js
Version:
The Blockchain Utils
31 lines • 939 B
JavaScript
;
/**
* @file index.ts
* @author astra <astra@volare.finance>
* @date 2022
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.$float = exports.$ = exports.convert = exports.e18 = exports.e = void 0;
const bignumber_1 = require("@ethersproject/bignumber");
const bignumber_js_1 = require("bignumber.js");
const e = (x) => new bignumber_js_1.BigNumber(10).pow(x);
exports.e = e;
exports.e18 = (0, exports.e)(18);
function convert(x) {
if (x instanceof bignumber_js_1.BigNumber)
return x;
if (x instanceof bignumber_1.BigNumber) {
x = x.toString();
}
return new bignumber_js_1.BigNumber(x);
}
exports.convert = convert;
function $(x, decimals = 18) {
return convert(x).shiftedBy(decimals).decimalPlaces(0, 1);
}
exports.$ = $;
function $float(x, decimals = 18) {
return convert(x).shiftedBy(-decimals);
}
exports.$float = $float;
//# sourceMappingURL=index.js.map