@devasher/kuru-sdk
Version:
Ethers v6 SDK to interact with Kuru (forked from @kuru-labs/kuru-sdk)
35 lines • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.clipToDecimals = exports.mulDivRound = exports.log10BigNumber = void 0;
/**
* @dev Calculates the base-10 logarithm of a BigNumber.
* @param bn - The BigNumber to calculate the logarithm of.
* @returns The base-10 logarithm of the BigNumber.
*/
function log10BigNumber(bn) {
if (bn === 0) {
throw new Error('Log10 of zero is undefined');
}
const bnString = bn.toString();
return bnString.length - 1;
}
exports.log10BigNumber = log10BigNumber;
function mulDivRound(value, multiplier, divisor) {
// Convert all inputs to bigint for arithmetic operations
const valueBigInt = BigInt(value.toString());
const multiplierBigInt = BigInt(multiplier.toString());
const divisorBigInt = BigInt(divisor.toString());
const product = valueBigInt * multiplierBigInt;
const halfDenominator = divisorBigInt / BigInt(2);
return (product + halfDenominator) / divisorBigInt;
}
exports.mulDivRound = mulDivRound;
function clipToDecimals(value, decimals) {
const [integer, decimal] = value.split('.');
if (decimal) {
return `${integer}.${decimal.slice(0, decimals)}`;
}
return value;
}
exports.clipToDecimals = clipToDecimals;
//# sourceMappingURL=math.js.map