export function displayPrice(amount: bigint, displayDecimal = 2, decimal = 9) { if (!amount) { return null; } const neg = amount < 0; if (neg) { amount = BigInt(amount) * BigInt(-1); } if (amount >= BigInt(1_000_000) * BigInt(Math.pow(10, decimal))) { const inte = amount.toString().slice(0, -decimal - 6) || '0'; const deci = amount .toString() .slice(-decimal - 6) .padStart(decimal, '0') .slice(0, displayDecimal); return `${neg ? '-' : ''}${inte}.${deci}M`; } if (amount >= BigInt(1000) * BigInt(Math.pow(10, decimal))) { const inte = amount.toString().slice(0, -decimal - 3) || '0'; const deci = amount .toString() .slice(-decimal - 3) .padStart(decimal, '0') .slice(0, displayDecimal); return `${neg ? '-' : ''}${inte}.${deci}k`; } const inte = amount.toString().slice(0, -decimal) || '0'; const deci = amount.toString().slice(-decimal).padStart(decimal, '0').slice(0, displayDecimal); return `${neg ? '-' : ''}${inte}.${deci}`; } export function div_ceil(a: bigint, b: bigint) { return (a + b - BigInt(1)) / b; } export function div_floor(a: bigint, b: bigint) { return a / b; } export function toLittleEndian(num: bigint) { const result = new Uint8Array(8); let i = 0; while (num > 0) { result[i] = Number(num % BigInt(256)); num = num / BigInt(256); i += 1; } return result; }