aftermath-ts-sdk - v3.3.3
    Preparing search index...

    Provides local casting and conversion routines shared by the Aftermath modules.

    The class does not perform network I/O. Its methods convert numbers, bytes, addresses, and BCS object responses, while its module properties expose the package-specific caster namespaces.

    Index
    farms: typeof FarmsApiCasting = FarmsApiCasting

    The farms package's casting namespace for farm objects and events.

    faucet: typeof FaucetApiCasting = FaucetApiCasting

    The faucet package's casting namespace for faucet objects and events.

    Fixed: typeof FixedUtils = FixedUtils

    The standard 18-decimal fixed-point utility class.

    i64MaxBigInt: bigint = ...

    The maximum value of a signed 64-bit integer, 9223372036854775807n.

    IFixed: typeof IFixedUtils = IFixedUtils

    The signed 18-decimal IFixed utility class.

    nftAmm: typeof NftAmmApiCasting = NftAmmApiCasting

    The NFT AMM package's casting namespace for NFT pool objects and events.

    nfts: typeof NftsApiCasting = NftsApiCasting

    The NFT package's casting namespace for NFT object and display data.

    perpetuals: typeof PerpetualsApiCasting = PerpetualsApiCasting

    The perpetuals package's casting namespace for market and position data.

    pools: typeof PoolsApiCasting = PoolsApiCasting

    The pools package's casting namespace for pool, coin, and pool-event shapes.

    router: typeof RouterApiCasting = RouterApiCasting

    The router package's casting namespace for routes and trade data.

    staking: typeof StakingApiCasting = StakingApiCasting

    The staking package's casting namespace for staking objects and events.

    suiFrens: typeof SuiFrensApiCasting = SuiFrensApiCasting

    The SuiFrens package's casting namespace for SuiFren objects and events.

    u64MaxBigInt: bigint = ...

    The maximum value of an unsigned 64-bit integer, 18446744073709551615n.

    • Decodes a 32-byte BCS address into a zero-padded Sui address string.

      Parameters

      • bytes: number[]

        The BCS address bytes in their on-chain order.

      Returns string

      A 0x-prefixed address with 64 hexadecimal digits.

      When the BCS address bytes are malformed or are not 32 bytes long.

    • Converts byte values directly to a zero-padded Sui address string.

      Each byte is rendered as two hexadecimal digits, concatenated after 0x, and then left-padded to 64 hexadecimal digits. This method does not validate that the input contains exactly 32 values.

      Parameters

      • bytes: number[]

        The raw address byte values.

      Returns string

      A 0x-prefixed address with 64 hexadecimal digits when the input fits within 32 bytes.

      When the rendered address is longer than 64 hexadecimal digits.

    • Converts decimal byte strings to a zero-padded Sui address.

      Each string is passed to Number without a separate range check, then the resulting values are handled by addressFromBytes.

      Parameters

      • bytes: string[]

        Decimal strings such as "255" and "0".

      Returns string

      The string rendered by addressFromBytes; the helper does not validate that the result is hexadecimal or contains exactly 32 bytes.

      When the rendered address is longer than 64 hexadecimal digits.

    • Extracts base64 BCS bytes from a Sui object response.

      Parameters

      • suiObjectResponse: SuiObjectResponse

        The response whose data.bcs field to inspect.

      Returns string

      The data.bcs.bcsBytes base64 string.

      Error when data.bcs is absent or does not contain bcsBytes.

    • Converts little-endian byte values to a bigint.

      For example, [0x01, 0x02] becomes 0x0201, or 513n. The method calls reverse() on bytes, so it reverses the caller's array in place. It does not interpret a sign bit.

      Parameters

      • bytes: number[]

        The little-endian byte values.

      Returns bigint

      The resulting unsigned bigint.

      SyntaxError or RangeError when the byte array cannot form a valid bigint, including an empty array.

    • Converts an 18-decimal fixed-point bigint to a JavaScript number.

      The method divides by 1e18. Large values can lose integer or fractional precision when they pass through Number.

      Parameters

      • a: bigint

        The 18-decimal fixed-point value.

      Returns number

      The unscaled value as a JavaScript number.

    • Converts basis points to an unscaled percentage fraction.

      The method divides by 10000 after converting the bigint to number, so very large basis-point values can lose precision.

      Parameters

      • bps: bigint

        The basis-point count, where 500n means 5%.

      Returns number

      The unscaled percentage fraction.

    • Converts decimal byte strings to JavaScript numbers.

      The method calls Number for each string and does not validate the 0-255 byte range, so a non-numeric string produces NaN.

      Parameters

      • bytes: string[]

        The decimal strings to convert.

      Returns number[]

      A new numeric array with one value for each input string.

    • Deserializes a SuiObjectResponse's base64 BCS bytes and maps the result.

      The method extracts data.bcs.bcsBytes, calls bcsType.fromBase64, and passes the decoded value to fromDeserialized. It performs no network I/O and does not mutate the response.

      Type Parameters

      • T
      • U

      Parameters

      • inputs: {
            bcsType: BcsType<U>;
            fromDeserialized: (deserialized: U) => T;
            suiObjectResponse: SuiObjectResponse;
        }

        The response, BCS schema, and decoded-value mapper.

        • bcsType: BcsType<U>

          The BCS schema for the serialized object.

        • fromDeserialized: (deserialized: U) => T

          Converts the decoded BCS value to the requested result.

        • suiObjectResponse: SuiObjectResponse

          The object response containing data.bcs.bcsBytes.

      Returns T

      The mapped value.

      Error when the response has no BCS bytes. BCS decoding and mapper errors are propagated unchanged.

    • Converts an unscaled integer-percent slippage value to a fraction.

      The method divides by 100 without validation, so 1 becomes 0.01 and 0.5 becomes 0.005.

      Parameters

      • slippageTolerance: number

        The percent value to divide by 100.

      Returns number

      The unscaled slippage fraction.

    • Converts a JavaScript number to an 18-decimal fixed-point bigint.

      The method multiplies by 1e18, applies Math.floor, and converts the result to bigint. Flooring also applies to negative values, so negative fractional scaled values round toward negative infinity. The conversion inherits JavaScript number precision.

      Parameters

      • a: number

        The number to encode. Its scaled value must be finite; the result is floored before conversion to bigint.

      Returns bigint

      The 18-decimal fixed-point representation as a bigint.

      RangeError when a is NaN, infinite, or produces an invalid bigint conversion.

    • Converts a decimal fraction to basis points.

      One basis point is 0.0001, so 0.05 becomes 500n and 1 becomes 10000n. The method rounds the product to the nearest integer basis point.

      Parameters

      • percentage: number

        The unscaled percentage fraction, where 0.05 means 5%.

      Returns bigint

      The rounded basis-point count as a bigint.

    • Multiplies a bigint by a JavaScript number and returns a bigint.

      The method first converts the bigint to number, multiplies by scalar, applies Math.floor, and converts the result to bigint. Large bigint inputs can lose precision during the Number conversion.

      Parameters

      • scalar: number

        The numeric multiplier.

      • int: bigint

        The bigint to multiply.

      Returns bigint

      The floored product as a bigint.

      RangeError when the scaled number is not finite or cannot convert to a bigint.

    • Converts each byte to a JavaScript character code and joins the characters.

      This is a character-code conversion, not UTF-8 decoding. The input array is not mutated.

      Parameters

      • bytes: number[]

        The byte values to convert.

      Returns string

      The resulting string.

    • Encodes a JavaScript string as UTF-8 byte values.

      Parameters

      • str: string

        The string to encode.

      Returns number[]

      A new number[] containing the UTF-8 bytes.

    • Returns the value of a deserialized BCS Option's Some property.

      Any object without a Some property, including a { None: ... } value, returns undefined. Falsy Some values, including 0, false, "", and null, are returned unchanged.

      Parameters

      • deserializedData: any

        The object produced by BCS deserialization.

      Returns any

      The Some value, or undefined when the property is absent.

      TypeError when deserializedData is null, undefined, or a primitive value that cannot be used with the in operator.