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

    A utility class containing various helper functions for general use across the Aftermath TS ecosystem. This includes numeric operations, object field extraction, array transformations, slippage adjustments, and Move error parsing.

    Index
    blendedOperations: {
        mulBBB: (a: bigint, b: bigint) => bigint;
        mulBBN: (a: bigint, b: bigint) => number;
        mulNBB: (a: number, b: bigint) => bigint;
        mulNBN: (a: number, b: bigint) => number;
        mulNNB: (a: number, b: number) => bigint;
        mulNNN: (a: number, b: number) => number;
    } = ...

    Mixed number and bigint multiplication helpers.

    The suffix describes the argument and return types: N is number and B is bigint. Helpers that return bigint apply Math.floor before the conversion. Converting a bigint product to number can lose precision.

    Type Declaration

    • mulBBB: (a: bigint, b: bigint) => bigint

      Multiplies two bigints and returns the exact bigint product.

    • mulBBN: (a: bigint, b: bigint) => number

      Multiplies two bigints and converts the product to a number.

    • mulNBB: (a: number, b: bigint) => bigint

      Multiplies a number by a bigint after converting the bigint to a number, floors the product, and returns a bigint.

    • mulNBN: (a: number, b: bigint) => number

      Multiplies a number by a bigint after converting the bigint to a number.

    • mulNNB: (a: number, b: number) => bigint

      Multiplies two numbers, floors the product, and returns a bigint.

    • mulNNN: (a: number, b: number) => number

      Multiplies two numbers and returns a number.

    dynamicFields: typeof DynamicFieldsApiHelpers = DynamicFieldsApiHelpers

    Static reference to the DynamicFieldsApiHelpers, providing utility methods for working with dynamic fields in Sui objects.

    events: typeof EventsApiHelpers = EventsApiHelpers

    Static reference to the EventsApiHelpers, providing methods for querying and filtering Sui events.

    inspections: typeof InspectionsApiHelpers = InspectionsApiHelpers

    Static reference to the InspectionsApiHelpers, used for reading Summaries or inspection data from objects.

    objects: typeof ObjectsApiHelpers = ObjectsApiHelpers

    Static reference to the ObjectsApiHelpers, providing direct retrieval or manipulation of on-chain Sui objects.

    transactions: typeof TransactionsApiHelpers = TransactionsApiHelpers

    Static reference to the TransactionsApiHelpers, enabling easier queries for transaction data by digest or other criteria.

    • Returns the non-negative absolute value of a bigint.

      Parameters

      • num: bigint

        The input bigint.

      Returns bigint

      num when it is non-negative, or -num otherwise.

    • Left-pads the first type segment to 64 characters after 0x.

      When type contains ::, the text after the first separator is appended unchanged apart from the helper's existing removal of the next 0x while it splits the suffix. The method does not validate hexadecimal characters.

      Parameters

      • type: string

        The address or extended Move type string.

      Returns string

      A string whose first segment has 64 characters after 0x.

      Error when the first segment is longer than 64 characters.

    • Converts an object ID into a transaction object argument when needed.

      A string calls tx.object(object), which adds an input to the transaction. An existing TransactionObjectArgument is returned by identity and does not call the transaction.

      Parameters

      • tx: Transaction

        The transaction to update when object is a string.

      • object: string | TransactionObjectArgument

        An object ID or an existing transaction object argument.

      Returns TransactionObjectArgument

      A transaction object argument for object.

    • Applies a percent reduction to a JavaScript number.

      The method returns amount - (slippage / 100) * amount without clamping or validating the input.

      Parameters

      • amount: number

        The original numeric amount.

      • slippage: number

        The percent value, where 1 means 1%.

      Returns number

      The reduced amount as a number.

    • Applies a percent reduction to a bigint amount.

      The method computes amount - floor((slippage / 100) * Number(amount)). Converting the amount to number can lose precision before the reduction is converted back to bigint. It does not clamp the result or validate the percent input.

      Parameters

      • amount: bigint

        The original amount.

      • slippage: number

        The percent value, where 1 means 1%.

      Returns bigint

      The reduced amount as a bigint.

      RangeError when the computed reduction cannot be converted to a bigint, such as for a non-finite result.

    • Splits an array according to a synchronous predicate.

      Truthy predicate results go to the first array and falsy results go to the second. The method preserves input order and passes the item, index, and original array to the predicate.

      Type Parameters

      • ArrayType

      Parameters

      • array: ArrayType[]

        The array to filter.

      • func: (item: ArrayType, index: number, arr: ArrayType[]) => boolean

        The predicate to call for each item.

      Returns [trues: ArrayType[], falses: ArrayType[]]

      A tuple of [truthyItems, falsyItems].

    • Splits an array according to asynchronous predicate results.

      The method invokes the predicate for every item before awaiting Promise.all, so the checks run in parallel. It preserves input order and rejects if any predicate promise rejects.

      Type Parameters

      • ArrayType

      Parameters

      • array: ArrayType[]

        The array to filter.

      • func: (item: ArrayType, index: number, arr: ArrayType[]) => Promise<boolean>

        An async predicate receiving the item, index, and original array.

      Returns Promise<[trues: ArrayType[], falses: ArrayType[]]>

      A promise for [truthyItems, falsyItems].

    • Uppercases the first character and lowercases the remaining characters.

      For example, "HELLO" becomes "Hello". An empty string remains empty.

      Parameters

      • str: string

        The input string to transform.

      Returns string

      The transformed string.

    • Checks whether two numbers differ by at most a relative tolerance.

      The exact comparison is Math.abs(a - b) <= tolerance * Math.max(a, b). The method does not clamp tolerance or use absolute values for the operands in the right-hand side.

      Parameters

      • a: number

        The first number.

      • b: number

        The second number.

      • tolerance: number

        The multiplier applied to Math.max(a, b).

      Returns boolean

      true when the comparison passes.

    • Checks bigint closeness after converting both operands to numbers.

      The comparison is therefore subject to JavaScript number precision and uses the same formula as closeEnough.

      Parameters

      • a: bigint

        First bigint.

      • b: bigint

        Second bigint.

      • tolerance: number

        The multiplier passed to closeEnough.

      Returns boolean

      true when the numeric comparison passes.

    • Creates a timestamp-and-random base36 identifier string.

      The value combines Date.now().toString(36) with the random suffix from Math.random().toString(36). It is not guaranteed to be globally unique.

      Returns string

      The generated base36 string.

    • Recursively copies arrays, enumerable object properties, and Date values.

      Dates are cloned from their timestamp. Other objects become plain objects containing their enumerable string-keyed properties. Primitive values are returned unchanged, and cyclic input is not supported.

      Type Parameters

      • T

      Parameters

      • target: T

        The data to clone deeply.

      Returns T

      A copied structure with the same generic type.

    • Returns an object containing only entries accepted by a predicate.

      The method examines the object's enumerable own string-keyed entries and returns a new object. It does not mutate obj.

      Type Parameters

      • Value

      Parameters

      • obj: Record<string, Value>

        The original object to filter.

      • predicate: (key: string, value: Value) => boolean

        A function taking a key and value and returning a boolean.

      Returns Record<string, Value>

      A new object with the accepted entries.

    • Returns display metadata from a gRPC object view in JSON-RPC shape.

      Reshaped onto JSON-RPC's DisplayFieldsResponse so the display casters are unaffected by the transport change; see GrpcCasting.displayFieldsResponseFromGrpcDisplay for the two semantic differences that reshape absorbs.

      display is undefined when it was not requested and null when the object's type has no Display template. A non-null value is reshaped by GrpcCasting.displayFieldsResponseFromGrpcDisplay.

      Parameters

      Returns DisplayFieldsResponse

      The JSON-RPC-shaped display response.

      Error when data.display is undefined, which indicates that display data was not requested or was not returned.

    • Returns the Move fields from a gRPC object view.

      The value is the gRPC json view, not JSON-RPC content.fields. Nested structs can be bare, vector<u8> fields can be base64 strings, and UID fields can be bare object IDs. Use the corresponding GrpcCasting helpers before reading those shapes. The returned record is dynamic and is not statically checked field by field.

      json is undefined unless include: { json: true } was passed at the fetch site.

      Parameters

      • data: SuiObjectView

        The object view containing the requested json fields.

      Returns Record<string, any>

      The dynamic Move field record.

      Error when data.json is absent or falsy.

    • Returns the object ID after applying addLeadingZeroesToType.

      Parameters

      Returns string

      A zero-padded ObjectId string.

      Error when data.objectId is absent or empty, or when the ID is longer than 64 hexadecimal characters.

    • Returns the object type after applying addLeadingZeroesToType.

      The helper pads the outer address segment. Generic arguments keep their source padding and spacing, so equivalent gRPC and JSON-RPC generic type strings can remain textually different.

      Parameters

      Returns string

      The normalized fully qualified object type.

      Error when data.type is absent or empty, or when its first type segment is too long.

    • Finds the first index containing the maximum comparable value.

      Type Parameters

      • T extends string | number | bigint | Date

      Parameters

      • arr: T[]

        The input array.

      Returns number

      The first maximum index, or -1 when the array is empty.

    • Checks whether an unknown value is an array whose items are all strings.

      Parameters

      • value: unknown

        The value to check.

      Returns value is string[]

      true for an empty or string-only array, otherwise false.

    • Checks whether a string matches the helper's unsigned decimal pattern.

      The pattern accepts digits with at most one decimal point, including an empty string, a leading point such as .5, and a trailing point such as 5.. It rejects signs, exponents, and other characters.

      Parameters

      • str: string

        The string to test.

      Returns boolean

      true when str matches that pattern.

    • Checks whether a string contains one or more hexadecimal digits.

      The string may begin with 0x or 0X. Whitespace, signs, and an empty 0x prefix are rejected.

      Parameters

      • hexString: string

        The string to check.

      Returns boolean

      true when the string matches the hexadecimal pattern.

    • Checks whether a string is a valid Sui address.

      Lowercase-0x addresses of up to 64 hexadecimal characters are padded to 64 characters before validation. Invalid prefixes, lengths, characters, and address strings longer than 64 characters return false; normalization errors are caught rather than thrown.

      Parameters

      • address: string

        The address string to validate.

      Returns boolean

      true when the normalized value passes Sui address validation.

    • Applies the helper's minimum-shape check for a Sui Move type.

      After trimming whitespace, the string must start with lowercase 0x, have length at least 9, contain :: at index 3 or later and again at index 6 or later, and not end with :. The method does not validate the full address, module, or type grammar.

      Parameters

      • str: string

        The string to validate.

      Returns boolean

      true when the minimum shape passes.

    • Constructs a Sui keypair from an encoded private key.

      decodeSuiPrivateKey selects the scheme from the encoded key. This method supports ED25519, Secp256k1, and Secp256r1 and returns the matching keypair implementation. It performs no network I/O.

      Parameters

      • privateKey: string

        The encoded private key accepted by decodeSuiPrivateKey.

      Returns Keypair

      A new keypair for signing.

      When the key is malformed, unsupported, or cannot be decoded by the underlying cryptography library.

    • Returns the largest bigint in the argument list.

      Parameters

      • ...args: bigint[]

        The bigints to compare.

      Returns bigint

      The largest argument.

      TypeError when no arguments are supplied.

    • Returns the smallest bigint in the argument list.

      Parameters

      • ...args: bigint[]

        The bigints to compare.

      Returns bigint

      The smallest argument.

      TypeError when no arguments are supplied.

    • Parses JSON while applying the SDK's bigint and null conversions.

      Every string containing an optional minus sign, decimal digits, and a trailing n becomes a bigint after that suffix is removed. Every JSON null becomes undefined, including nested values. With unsafeStringNumberConversion: true, strings accepted by isNumber are also passed to BigInt; this can convert decimal-looking strings only when BigInt accepts them and can throw for strings that match the loose pattern but are not valid bigint input.

      Parameters

      • json: string

        A valid JSON string.

      • unsafeStringNumberConversion: boolean = false

        Whether to convert strings accepted by isNumber to bigint as well.

      Returns any

      The parsed value after recursive reviver conversion. Top-level null becomes undefined.

      SyntaxError for invalid JSON or a bigint conversion error from the reviver.

    • Extracts a Move abort code, package ID, and module from a Sui error message.

      The message must contain MoveAbort and the parser must find an integer after the last comma, an address: ... , name: package segment, and an Identifier("...") module segment. The package ID is normalized to 64 hexadecimal characters. An empty address segment is accepted by the current padding logic and becomes the zero address. If any other required part is missing or invalid, the method returns undefined.

      Parameters

      • inputs: { errorMessage: string }

        The raw Sui error message.

        • errorMessage: string

          The error text to parse.

      Returns ParsedMoveError | undefined

      The parsed error details, or undefined when the message does not match the supported shape.

    • Copies an object or array while replacing repeated references with undefined.

      The seen set tracks every object visited during this call. A cycle and a later occurrence of an already visited shared object both become undefined. The method returns new arrays and plain objects without mutating the input, but it mutates the supplied seen set.

      Type Parameters

      • T

      Parameters

      • obj: T

        The object or array to remove circular references from.

      • seen: WeakSet<object> = ...

        The reference set used to track visited objects.

      Returns T | undefined

      A copied structure, or undefined for a repeated object reference.

    • Returns a promise that resolves after a timer delay.

      Parameters

      • ms: number

        The delay passed to setTimeout, in milliseconds.

      Returns Promise<unknown>

      A promise that resolves with undefined after the timer fires.

    • Splits a coin string at colons for external coin-price lookups.

      When both the first and second segments are non-empty, the method returns those two segments and discards later segments. When either segment is empty or absent, it returns the original string with chain: "sui". The chain value is not validated against the CoinGeckoChain union at runtime.

      Parameters

      • coin: string

        The coin string, which may look like "bsc:0x<...>" or just "0x<...>".

      Returns {
          chain:
              | "ethereum"
              | "arbitrum"
              | "bsc"
              | "solana"
              | "sui"
              | "polygon"
              | "avalanche"
              | "optimism"
              | "base";
          coinType: string;
      }

      An object with the chain (e.g. "bsc") and the coinType.

      • chain:
            | "ethereum"
            | "arbitrum"
            | "bsc"
            | "solana"
            | "sui"
            | "polygon"
            | "avalanche"
            | "optimism"
            | "base"

        The prefix before the first colon, or "sui" for an unsplit value.

      • coinType: string

        The text between the first and second colon when a prefix exists.

    • Removes zeroes from every x0... sequence in a type string.

      For example, "0x0000123" becomes "0x123". The replacement also affects addresses inside generic type arguments, and it does not validate the rest of the string.

      Parameters

      • type: string

        The address or Move type string to process.

      Returns string

      A new string with those zero runs removed.

    • Adds the numbers in an array from left to right.

      Parameters

      • arr: number[]

        The array of numbers to sum.

      Returns number

      The numeric total, or 0 for an empty array.

    • Adds the bigints in an array from left to right.

      Parameters

      • arr: bigint[]

        The array of bigints to sum.

      Returns bigint

      The bigint total, or 0n for an empty array.

    • Maps a parsed Move abort to a message in a package error table.

      The method first requires a package entry. It then prefers an exact module and error-code entry, and falls back to the package's ANY table. It returns undefined when parsing fails, the package is absent, or neither table has the error code.

      Parameters

      • inputs: { errorMessage: string; moveErrors: MoveErrors }

        The error text and lookup table.

        • errorMessage: string

          The raw Sui Move abort message.

        • moveErrors: MoveErrors

          The package, module, and error-code message table.

      Returns TranslatedMoveError | undefined

      The parsed details with the translated message, or undefined.

    • Returns a new array with duplicate elements removed.

      If the first element is an object, the method compares every element by its JSON.stringify result. Otherwise it uses Set equality. Both paths keep the first occurrence's order, and the input array is not mutated.

      Type Parameters

      • T

      Parameters

      • arr: T[]

        The original array.

      Returns T[]

      An array of unique items.

      When the object path cannot serialize an element, such as a bigint.

    • Compares the floored scale buckets of two numbers.

      The method computes Math.floor(a / fixedOne) and Math.floor(b / fixedOne), then checks whether their absolute difference is at most 1.

      Parameters

      • a: number

        First number (scaled).

      • b: number

        Second number (scaled).

      • fixedOne: number

        The scale divisor shared by a and b.

      Returns boolean

      true when the bucket difference is at most 1.

    • Pairs corresponding elements from two arrays.

      The result stops at the shorter input and does not mutate either array.

      Type Parameters

      • S1
      • S2

      Parameters

      • firstCollection: S1[]

        The first collection.

      • lastCollection: S2[]

        The second collection.

      Returns [S1, S2][]

      An array of [firstCollection[i], lastCollection[i]] pairs.