43 lines
1.8 KiB
JavaScript
43 lines
1.8 KiB
JavaScript
|
"use strict";
|
||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||
|
};
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.convertETHToToken = exports.fromGweiToWeiHex = exports.bump = exports.calculateGasPriceInWei = exports.serializeTx = void 0;
|
||
|
var transactions_1 = require("@ethersproject/transactions");
|
||
|
var ethers_1 = require("ethers");
|
||
|
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
||
|
bignumber_js_1.default.config({ EXPONENTIAL_AT: 100 });
|
||
|
var GWEI = 1e9;
|
||
|
function serializeTx(tx) {
|
||
|
if (!tx)
|
||
|
tx = '0x';
|
||
|
if (typeof tx === 'string')
|
||
|
return tx;
|
||
|
return (0, transactions_1.serialize)(tx);
|
||
|
}
|
||
|
exports.serializeTx = serializeTx;
|
||
|
function calculateGasPriceInWei(gasPrice) {
|
||
|
// @ts-ignore
|
||
|
return ethers_1.BigNumber.from(gasPrice.gasPrice || gasPrice.maxFeePerGas);
|
||
|
}
|
||
|
exports.calculateGasPriceInWei = calculateGasPriceInWei;
|
||
|
function bump(value, percent) {
|
||
|
var hundredPercents = (0, bignumber_js_1.default)(100);
|
||
|
return ethers_1.BigNumber.from((0, bignumber_js_1.default)(ethers_1.BigNumber.from(value).toHexString())
|
||
|
.times(hundredPercents.plus((0, bignumber_js_1.default)(percent)))
|
||
|
.div(hundredPercents)
|
||
|
.decimalPlaces(0, 1)
|
||
|
.toString());
|
||
|
}
|
||
|
exports.bump = bump;
|
||
|
function fromGweiToWeiHex(value) {
|
||
|
return ethers_1.BigNumber.from((0, bignumber_js_1.default)(value).times(GWEI).toString()).toHexString();
|
||
|
}
|
||
|
exports.fromGweiToWeiHex = fromGweiToWeiHex;
|
||
|
function convertETHToToken(amountInWEI, tokenDecimals, tokenPriceInWei) {
|
||
|
var tokenDecimalsMultiplier = ethers_1.BigNumber.from(10).pow(tokenDecimals);
|
||
|
return ethers_1.BigNumber.from(amountInWEI).mul(tokenDecimalsMultiplier).div(tokenPriceInWei);
|
||
|
}
|
||
|
exports.convertETHToToken = convertETHToToken;
|
||
|
//# sourceMappingURL=utils.js.map
|