22 lines
821 B
JavaScript
22 lines
821 B
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.convertETHToTokenAmount = exports.sleep = exports.isNode = void 0;
|
||
|
exports.isNode = !(process.browser
|
||
|
// prettier-ignore
|
||
|
// @ts-ignore
|
||
|
) && typeof globalThis.window === 'undefined';
|
||
|
function sleep(ms) {
|
||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||
|
}
|
||
|
exports.sleep = sleep;
|
||
|
/**
|
||
|
* Example:
|
||
|
*
|
||
|
* amountInWei (0.1 ETH) * tokenDecimals (18) * tokenPriceInWei (0.0008) = 125 TOKEN
|
||
|
*/
|
||
|
function convertETHToTokenAmount(amountInWei, tokenPriceInWei, tokenDecimals = 18) {
|
||
|
const tokenDecimalsMultiplier = BigInt(10 ** Number(tokenDecimals));
|
||
|
return (BigInt(amountInWei) * tokenDecimalsMultiplier) / BigInt(tokenPriceInWei);
|
||
|
}
|
||
|
exports.convertETHToTokenAmount = convertETHToTokenAmount;
|
||
|
//# sourceMappingURL=utils.js.map
|