/** * High water mark and other on-chain decimal values use the Rust `U80F48` * fixed-point representation: a 128-bit unsigned integer whose lower 48 bits * encode the fractional part. Convert to a JS `number` by splitting integer * and fractional halves before crossing the float boundary, so the integer * portion keeps its precision until it actually overflows `Number`. */ export const DECIMAL_FRACTIONAL_BITS = 48n; export const DECIMAL_FRACTIONAL_DIVISOR = 1n << DECIMAL_FRACTIONAL_BITS; export function convertDecimalBitsToNumber(value: bigint): number { const integer = value >> DECIMAL_FRACTIONAL_BITS; const frac = value & (DECIMAL_FRACTIONAL_DIVISOR - 1n); return Number(integer) + Number(frac) / Number(DECIMAL_FRACTIONAL_DIVISOR); }