UNPKG

aftermath-ts-sdk

Version:
78 lines 3.11 kB
import { Byte, IFixed } from "../types"; /** * The `IFixedUtils` class provides support for signed 18-decimal fixed math, * referred to as "IFixed" in the Aftermath codebase. An `IFixed` value * is a bigint that includes sign bit manipulation. */ export declare class IFixedUtils { /** * The representation of 1.0 in the IFixed format, i.e. 1e18. */ static readonly ONE: IFixed; /** * The greatest bit in a 256-bit representation. This is used to indicate negative values in some approaches. */ static readonly GREATEST_BIT: IFixed; /** * A mask that can be used to flip or remove the greatest bit in a 256-bit number. */ static readonly NOT_GREATEST_BIT: IFixed; /** * Converts an IFixed bigint into a floating-point number, extracting both the integer * and decimal portions. For negative values, the sign bit is checked and value is negated. * * @param value - The IFixed value (signed 18-decimal) as a bigint. * @returns A standard JavaScript number with fractional parts intact. */ static numberFromIFixed: (value: IFixed) => number; /** * Converts a floating-point number into an IFixed bigint with 18 decimals of precision. * Negative numbers have the sign bit set. * * @param value - The JavaScript number to convert. * @returns The resulting IFixed bigint in on-chain-compatible format. */ static iFixedFromNumber: (value: number) => IFixed; /** * Returns the absolute value of an IFixed number. If the value is negative, * it's converted to its positive counterpart by flipping bits. * * @param value - The signed IFixed number as a bigint. * @returns The absolute value in IFixed. */ static abs: (value: IFixed) => IFixed; /** * Determines the sign of an IFixed number. * - If >= GREATEST_BIT, it's negative (-1). * - If exactly 0, sign is 0. * - Otherwise, sign is +1. * * @param value - The IFixed number to check. * @returns `-1`, `0`, or `1` based on the sign. */ static sign: (value: IFixed) => number; /** * Negates an IFixed number by flipping bits. This effectively does `-value` for the signed 18-dec representation. * * @param value - The IFixed number to negate. * @returns The negated IFixed number as a bigint. */ static neg: (value: IFixed) => IFixed; /** * Constructs an IFixed number from an array of bytes in little-endian format. * The sign bit might be set if the top bit is `1`. * * @param bytes - The byte array representing the IFixed number. * @returns The IFixed bigint. */ static iFixedFromBytes: (bytes: Byte[]) => IFixed; /** * Constructs an IFixed number from an array of stringified bytes, * each representing a decimal numeric value (e.g., `"255"`, `"0"`). * * @param bytes - An array of string bytes. * @returns The IFixed bigint. */ static iFixedFromStringBytes: (bytes: string[]) => IFixed; } //# sourceMappingURL=iFixedUtils.d.ts.map