UNPKG

aftermath-ts-sdk

Version:
213 lines 9.07 kB
import { BcsType } from "@mysten/sui/bcs"; import { SuiFrensApiCasting } from "../../packages/suiFrens/api/suiFrensApiCasting"; import { FaucetApiCasting } from "../../packages/faucet/api/faucetApiCasting"; import { NftAmmApiCasting } from "../../packages/nftAmm/api/nftAmmApiCasting"; import { PoolsApiCasting } from "../../packages/pools/api/poolsApiCasting"; import { StakingApiCasting } from "../../packages/staking/api/stakingApiCasting"; import { Byte, Percentage, SuiAddress } from "../types"; import { RouterApiCasting } from "../../packages/router/api/routerApiCasting"; import { FixedUtils } from "./fixedUtils"; import { IFixedUtils } from "./iFixedUtils"; import { PerpetualsApiCasting } from "../../packages/perpetuals/api/perpetualsApiCasting"; import { FarmsApiCasting } from "../../packages/farms/api/farmsApiCasting"; import { LeveragedStakingApiCasting } from "../../packages/leveragedStaking/api/leveragedStakingApiCasting"; import { SuiObjectResponse } from "@mysten/sui/client"; import { NftsApiCasting } from "../nfts/nftsApiCasting"; import { OracleApiCasting } from "../../packages/oracle/api/oracleApiCasting"; /** * A central utility class for casting and conversion routines across * different Aftermath modules. Provides both direct numeric transformations * (e.g., fixed-point arithmetic) and advanced BCS-based object deserialization. */ export declare class Casting { /** * Casting utilities for pools-related data (AMM pools, liquidity, etc.). */ static pools: typeof PoolsApiCasting; /** * Casting utilities for SuiFrens-related data or objects. */ static suiFrens: typeof SuiFrensApiCasting; /** * Casting utilities for faucet-related data, typically for devnet or testnet tokens. */ static faucet: typeof FaucetApiCasting; /** * Casting utilities for staking-related data (positions, pools, etc.). */ static staking: typeof StakingApiCasting; /** * Casting utilities for leveraged staking data structures. */ static leveragedStaking: typeof LeveragedStakingApiCasting; /** * Casting utilities for NFT AMM objects and events. */ static nftAmm: typeof NftAmmApiCasting; /** * Casting utilities for router-based data, such as trade routes and DEX interactions. */ static router: typeof RouterApiCasting; /** * Casting utilities for perpetuals/futures data. */ static perpetuals: typeof PerpetualsApiCasting; /** * Casting utilities for oracle-based data or price feed objects. */ static oracle: typeof OracleApiCasting; /** * Casting utilities for farming data (yield farms, locked positions, etc.). */ static farms: typeof FarmsApiCasting; /** * Casting utilities for NFT structures and data retrieval logic. */ static nfts: typeof NftsApiCasting; /** * Reference to the standard fixed-point arithmetic utilities (18 decimals). */ static Fixed: typeof FixedUtils; /** * Reference to the intermediate fixed type (signed 18 decimals). */ static IFixed: typeof IFixedUtils; /** * The maximum unsigned 64-bit integer value as a bigint (0xFFFFFFFFFFFFFFFF). */ static u64MaxBigInt: bigint; /** * Converts a floating-point number to a fixed bigint with 18 decimals. * For example, `1.23` => `1230000000000000000n` if we consider 18 decimals. * * @param a - The number to convert. * @returns A bigint representing the number in 18-decimal fixed format. */ static numberToFixedBigInt: (a: number) => bigint; /** * Converts an 18-decimal fixed bigint to a floating-point number. * For example, `1230000000000000000n` => `1.23`. * * @param a - The fixed bigint to convert. * @returns A floating-point representation of the 18-decimal fixed value. */ static bigIntToFixedNumber: (a: bigint) => number; /** * Scales a bigint by a floating-point scalar. For instance, a scalar of 0.5 * and a bigint of 100 => 50n. * * @param scalar - The floating-point multiplier (e.g., 0.5). * @param int - The bigint to be scaled. * @returns A bigint result after scaling. */ static scaleNumberByBigInt: (scalar: number, int: bigint) => bigint; /** * Converts a decimal percentage into basis points (bps), returned as a bigint. * For example, 0.05 => 500 bps. * * @param percentage - The decimal percentage to convert (e.g., 0.05 for 5%). * @returns A bigint representing basis points. */ static percentageToBps(percentage: Percentage): bigint; /** * Converts a bigint basis points value back to a decimal percentage. * For example, 500n => 0.05 (5%). * * @param bps - The bigint basis points to convert (e.g., 500n). * @returns The decimal percentage (0.05). */ static bpsToPercentage(bps: bigint): Percentage; /** * Converts an array of bytes into a string by interpreting each byte as a character code. * * @param bytes - An array of bytes to convert. * @returns The resulting ASCII string. */ static stringFromBytes: (bytes: Byte[]) => string; /** * Interprets an array of bytes as a little-endian hex string, converting * that string into a bigint. For example, `[0x01, 0x02]` => `0x0201` => `513n`. * * @param bytes - An array of bytes. * @returns The resulting bigint from the hex. */ static bigIntFromBytes: (bytes: Byte[]) => bigint; /** * Converts BCS-encoded address bytes into a SuiAddress (0x...) string, * preserving any needed leading zeroes. * * @param bytes - The address bytes in BCS-encoded form. * @returns A normalized Sui address string (e.g., "0x000123..."). */ static addressFromBcsBytes: (bytes: Byte[]) => SuiAddress; /** * Converts an array of bytes directly to a Sui address string in "0x..." format, * adding any leading zeros if needed. * * @param bytes - The raw bytes for the address. * @returns A normalized Sui address. */ static addressFromBytes: (bytes: Byte[]) => SuiAddress; /** * Converts an array of hex string bytes into a Sui address. Each element of * the array is a string representing a byte (e.g., `["255", "0", ...]`). * * @param bytes - An array of stringified bytes to convert. * @returns A normalized Sui address. */ static addressFromStringBytes: (bytes: string[]) => SuiAddress; /** * Converts an array of decimal-encoded string bytes (e.g., `["255", "0"]`) * into a numeric `Byte[]` array. * * @param bytes - The string array representing decimal values. * @returns A numeric array of bytes. */ static bytesFromStringBytes: (bytes: string[]) => Byte[]; /** * Unwraps a deserialized "Option" type from the BCS, returning its contents * if present, or `undefined` if not. * * @param deserializedData - The BCS-deserialized structure that might contain `{ Some: value }` or `{ None: true }`. * @returns The unwrapped data if present, or `undefined`. */ static unwrapDeserializedOption: (deserializedData: any) => any | undefined; /** * Encodes a JavaScript string into a UTF-8 `Uint8Array`, suitable for * on-chain usage or hashing. * * @param str - The string to encode. * @returns An array of numeric bytes representing the UTF-8 encoded string. */ static u8VectorFromString: (str: string) => number[]; /** * Normalizes a user-provided slippage tolerance from an integer percentage * into a decimal fraction. E.g., `1 => 0.01`. * * @param slippageTolerance - The slippage in integer percent form (e.g., 1 for 1%). * @returns A decimal fraction (e.g., 0.01). */ static normalizeSlippageTolerance: (slippageTolerance: number) => number; /** * Deserializes a `SuiObjectResponse`'s BCS bytes into an object of type `T` using * a specified `bcsType`. Typically used for on-chain object decoding. * * @param inputs - The inputs including `suiObjectResponse`, `bcsType`, and a `fromDeserialized` transform function. * @returns The transformed object of type `T` after BCS deserialization. * @throws If no BCS bytes are found in the object. */ static castObjectBcs: <T, U>(inputs: { suiObjectResponse: SuiObjectResponse; bcsType: BcsType<U>; fromDeserialized: (deserialized: U) => T; }) => T; /** * Extracts base64 BCS bytes from a `SuiObjectResponse` if present. Throws an error otherwise. * * @param suiObjectResponse - The Sui object response containing `bcsBytes`. * @returns A base64 string representing the object's BCS data. * @throws If the object response does not contain `bcsBytes`. */ static bcsBytesFromSuiObjectResponse(suiObjectResponse: SuiObjectResponse): string; } //# sourceMappingURL=casting.d.ts.map