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

    High-level wrapper around a single Perpetuals vault.

    A vault is a managed perpetuals account that accepts user deposits (LP), trades across up to a bounded set of markets, and supports withdrawals via a request flow.

    This class provides:

    • Transaction builders for:
      • User actions (deposit, create/cancel withdraw request, update slippage)
      • Force-withdraw processing (close positions and settle a request)
      • Owner admin actions (update params, process requests, withdraw fees/collateral)
    • Read helpers for:
      • Vault withdraw requests
      • LP token pricing
      • Accessing the vault’s underlying perpetuals account
    • Static validation helpers for LP coin metadata (name/symbol constraints)
    • A small calculation helper for withdraw-request slippage

    Typical usage:

    const perps = afSdk.Perpetuals();
    const { vaults } = await perps.getAllVaults();
    const vault = vaults[0];

    const { tx } = await vault.getDepositTx({
    walletAddress: "0x...",
    depositAmount: BigInt("1000000000"),
    minLpAmountOut: 0n,
    });

    Hierarchy (View Summary)

    Index

    Optional shared AftermathApi provider. When provided, transaction builders will serialize Transactions into txKind.

    config: CallerConfig

    The mutable configuration used for subsequent requests.

    Raw on-chain vault object snapshot.

    • Build a user transaction to create a vault withdraw request.

      Withdrawals are request-based: the user specifies how much LP to redeem and a minimum collateral output amount.

      Parameters

      • inputs: {
            lpWithdrawAmount: bigint;
            minCollateralAmountOut: bigint;
            sponsor?: PerpetualsSponsorConfig;
            tx?: Transaction;
            walletAddress: string;
        }
        • lpWithdrawAmount: bigint

          Amount of LP to withdraw.

        • minCollateralAmountOut: bigint

          Minimum collateral out (slippage guard).

        • Optionalsponsor?: PerpetualsSponsorConfig
        • Optionaltx?: Transaction

          Optional transaction to extend.

        • walletAddress: string

          Wallet creating the request.

      Returns Promise<Omit<ApiTransactionResponse, "txKind"> & { tx: Transaction }>

      Transaction response containing tx.

    • Build a user transaction to deposit collateral into the vault in exchange for LP.

      You can specify the deposit as:

      • depositAmount (wallet pays directly), OR
      • depositCoinArg (use an existing transaction argument)

      Parameters

      • inputs: {
            isSponsoredTx?: boolean;
            minLpAmountOut: bigint;
            sponsor?: PerpetualsSponsorConfig;
            tx?: Transaction;
            walletAddress: string;
        } & (
            | { depositAmount: bigint }
            | { depositCoinArg: TransactionObjectArgument }
        )
        • OptionalisSponsoredTx?: boolean

          Whether the tx is sponsored (gas paid by another party).

        • minLpAmountOut: bigint

          Minimum LP out (slippage guard).

        • Optionalsponsor?: PerpetualsSponsorConfig
        • Optionaltx?: Transaction

          Optional transaction to extend.

        • walletAddress: string

          Depositor wallet.

        • { depositAmount: bigint }
          • depositAmount: bigint

            Amount of collateral to deposit (mutually exclusive with depositCoinArg).

        • { depositCoinArg: TransactionObjectArgument }
          • depositCoinArg: TransactionObjectArgument

            Transaction argument referencing collateral coin.

      Returns Promise<Omit<ApiTransactionResponse, "txKind"> & { tx: Transaction }>

      Transaction response containing tx.

      const { txKind } = await vault.getDepositTx({
      walletAddress: "0x...",
      depositAmount: 1_000_000_000n,
      minLpAmountOut: 0n,
      });
    • Build an owner transaction to process one or more users' withdraw requests.

      This is the normal (non-force) processing path for withdrawals. The owner batches users and settles their requests in a single transaction.

      Parameters

      • inputs: { sponsor?: PerpetualsSponsorConfig; tx?: Transaction; userAddresses: string[] }
        • Optionalsponsor?: PerpetualsSponsorConfig
        • Optionaltx?: Transaction

          Optional transaction to extend.

        • userAddresses: string[]

          Users whose requests should be processed.

      Returns Promise<Omit<ApiTransactionResponse, "txKind"> & { tx: Transaction }>

      Transaction response containing tx.

    • Build an owner transaction to withdraw vault collateral by redeeming LP.

      Parameters

      • inputs: {
            lpWithdrawAmount: bigint;
            minCollateralAmountOut: bigint;
            recipientAddress?: string;
            tx?: Transaction;
        }
        • lpWithdrawAmount: bigint

          Amount of LP to redeem.

        • minCollateralAmountOut: bigint

          Minimum collateral out to protect from slippage.

        • OptionalrecipientAddress?: string

          Optional recipient address for withdrawn collateral.

        • Optionaltx?: Transaction

          Optional transaction to extend.

      Returns Promise<
          Omit<ApiPerpetualsVaultOwnerWithdrawCollateralTxResponse, "txKind"> & {
              tx: Transaction;
          },
      >

      Response containing tx and any extra outputs described by ApiPerpetualsVaultOwnerWithdrawCollateralTxResponse.

    • Build an owner transaction to withdraw locked liquidity from the vault.

      Owner-locked liquidity is LP that was locked at vault creation time. This flow allows the owner to withdraw a portion without going through the standard withdraw-request lifecycle. Owner-locked withdrawals are exempt from performance fees.

      Parameters

      • inputs: {
            amount: bigint;
            minCollateralAmountOut: bigint;
            recipientAddress?: string;
            tx?: Transaction;
        }
        • amount: bigint

          Amount of locked LP to withdraw (native units).

        • minCollateralAmountOut: bigint

          Minimum collateral out to protect from slippage.

        • OptionalrecipientAddress?: string

          Optional recipient address for withdrawn collateral.

        • Optionaltx?: Transaction

          Optional transaction to extend.

      Returns Promise<
          Omit<ApiPerpetualsVaultOwnerWithdrawLockedLiquidityTxResponse, "txKind"> & {
              tx: Transaction;
          },
      >

      Response containing tx and any extra outputs described by ApiPerpetualsVaultOwnerWithdrawLockedLiquidityTxResponse.

    • Build a transaction that pauses this vault for force-withdraw processing.

      The builder adds this vault's object ID, serializes the supplied transaction as txKind when an AftermathApi is available, and leaves signing and execution to the caller. Optional sponsor data is forwarded to the API.

      Parameters

      • inputs: { sponsor?: PerpetualsSponsorConfig; tx?: Transaction }
        • Optionalsponsor?: PerpetualsSponsorConfig

          Cached gas-pool sponsorship data, if required.

        • Optionaltx?: Transaction

          Existing transaction to extend; otherwise a new one is used.

      Returns Promise<Omit<ApiTransactionResponse, "txKind"> & { tx: Transaction }>

      The backend transaction response.

    • Build an update-withdraw-request-slippage transaction.

      This updates the user's minimum acceptable collateral output amount for an existing withdraw request.

      Parameters

      • inputs: {
            minCollateralAmountOut: bigint;
            sponsor?: PerpetualsSponsorConfig;
            tx?: Transaction;
        }
        • minCollateralAmountOut: bigint

          New minimum collateral amount out.

        • Optionalsponsor?: PerpetualsSponsorConfig
        • Optionaltx?: Transaction

          Optional transaction to extend.

      Returns Promise<Omit<ApiTransactionResponse, "txKind"> & { tx: Transaction }>

      Transaction response containing tx.

    • Reports whether the vault is currently paused for force withdrawals.

      The comparison uses vaultObject.pausedUntilTimestamp in Unix milliseconds. A missing timestamp or a timestamp at or before Date.now() means that the vault is not paused.

      Returns boolean

      true while the current time is before the pause deadline.

    • Returns the canonical Aftermath API host for a Sui network.

      To target a custom or local host, pass baseUrl in CallerConfig to the constructor instead.

      Parameters

      • network: SuiNetwork

        The Sui network whose host to return.

      Returns string

      The network's HTTPS or local HTTP API host.

    • Checks if a string is a valid LP coin name.

      Parameters

      • value: string

        The string to check.

      Returns boolean

      true if value can be used as a valid LP coin name, otherwise false.

      Current rule: ASCII-only. This aligns with many on-chain metadata constraints.

    • Checks if a string is a valid LP coin type symbol.

      Parameters

      • value: string

        The string to check.

      Returns boolean

      true if value can be used as a valid LP coin type symbol, otherwise false.

      Current rule: uppercase A–Z plus underscore.