flashloan-profit-calculator
Version:
A library for analyzing flashloan transactions and calculating profits
30 lines (29 loc) • 976 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseAmountSafely = parseAmountSafely;
exports.padAddress = padAddress;
function parseAmountSafely(hexValue) {
try {
// Try to parse directly as BigInt first
return BigInt(`0x${hexValue.substring(2)}`).toString();
}
catch (error) {
try {
// If direct parsing fails, use Number.parseInt and handle scientific notation
const parsed = Number.parseInt(hexValue, 16);
if (Number.isFinite(parsed)) {
return parsed.toLocaleString("fullwide", { useGrouping: false });
}
throw new Error(`Invalid number: ${hexValue}`);
}
catch (err) {
console.error(`Failed to parse amount ${hexValue}: ${err}`);
return "0";
}
}
}
function padAddress(topic) {
if (!topic)
return "0x0";
return `0x${topic.substring(26).toLowerCase()}`;
}