Vault

Complete Reference for the PerpetualsVault Class

Overview

The PerpetualsVault class is a high-level wrapper around a Perpetuals vault - a managed perpetuals account that accepts user deposits (LP tokens), trades across multiple markets, and supports withdrawals via a request-based flow.

Key Features:

  • User Actions:

    • Deposit collateral and receive LP tokens

    • Create withdraw requests

    • Cancel or update withdraw requests

    • Process force withdrawals

  • Owner Admin Actions:

    • Process pending withdraw requests

    • Update vault parameters (lock period, force withdraw delay, performance fee)

    • Withdraw performance fees

    • Withdraw (redeem) LP tokens

  • Trading:

    • Access underlying perpetuals account for trading

    • Trade across up to 12 markets

    • Automated position management

  • Preview Methods:

    • Preview deposits and withdrawals

    • Estimate LP token amounts

    • Calculate performance fees

Vault Mechanics:

  1. Deposits: Users deposit collateral → receive LP tokens representing vault share

  2. Trading: Vault owner trades with pooled collateral

  3. Withdrawals: Users request withdrawal → wait for lock period → receive collateral

  4. Performance Fees: Owner earns fees on positive performance

  5. Force Withdrawals: Emergency mechanism to close positions and process withdrawals

Typical Usage:


Constructor

constructor

Creates a new PerpetualsVault wrapper instance.

circle-exclamation

Parameters:

  • vaultObject: PerpetualsVaultObject

    • Raw on-chain vault object snapshot containing:

      • objectId: Vault ID

      • ownerAddress: Vault owner address

      • accountId: Underlying perpetuals account ID

      • accountObjectId: Account object ID

      • collateralCoinType: Collateral coin type (e.g., USDC)

      • lpCoinType: LP token coin type

      • lockPeriodMs: Minimum lock period for withdrawals

      • forceWithdrawDelayMs: Delay before force withdrawal can process

      • performanceFeePercentage: Vault performance fee

      • pausedUntilTimestamp: Optional pause timestamp

      • Other vault state fields

  • config (optional): CallerConfig

    • Configuration object containing network settings

  • Provider (optional): AftermathApi

    • Shared provider instance for transaction building

Remarks:

  • This class extends Caller with the "perpetuals" route prefix

  • All API calls resolve under /perpetuals/vault/...

Example:

Use Cases:

  1. Vault Wrapping: Wrap raw vault data with convenient methods

  2. Testing: Create vault instances with mock data

  3. Custom Initialization: Initialize with specific network configs


Static Constants

PerpetualsVault.constants

Vault-level protocol limits and UI-friendly constraints.

Constants:

  • maxLockPeriodMs: 5184000000 (2 months)

    • Maximum lock period that can be set for withdrawal requests

  • maxForceWithdrawDelayMs: 86400000 (1 day)

    • Maximum force withdraw delay period

  • maxPerformanceFeePercentage: 0.2 (20%)

    • Maximum performance fee the owner can charge

  • minDepositUsd: 1 ($1)

    • Minimum USD value required for user deposits

  • minOwnerLockUsd: 1 ($1)

    • Minimum USD value vault owner must lock during creation

  • maxMarketsInVault: 12

    • Maximum number of distinct markets the vault can trade

  • maxPendingOrdersPerPosition: 70

    • Maximum pending orders per position in the vault

Example:

Use Cases:

  1. Validation: Validate vault parameters before creation/updates

  2. UI Constraints: Set input field limits in user interfaces

  3. Documentation: Show users the protocol limits

  4. Error Handling: Provide clear error messages when limits exceeded


Withdraw Request Transaction Methods

getProcessForceWithdrawRequestTx

Build a process-force-withdraw-request transaction.

What This Does:

Force-withdraw is an emergency mechanism that:

  1. Closes specified positions in the vault

  2. Processes a pending withdraw request after the delay window

  3. Returns collateral to the user

This is used when normal withdrawal processing is delayed or unavailable.

Parameters:

  • walletAddress: SuiAddress

    • User wallet that owns the withdraw request

  • sizesToClose: Record<PerpetualsMarketId, Balance>

    • Mapping of market IDs to position sizes to close (in base units, 9 decimals)

    • Sizes are in base asset units scaled by Casting.Fixed.fixedOneN9

  • recipientAddress (optional): SuiAddress

    • Address to receive the withdrawn collateral

    • If omitted, collateral goes to walletAddress

  • tx (optional): Transaction

    • Existing transaction to extend

Returns:

Object containing:

  • tx: Transaction - Transaction ready to sign and execute

  • Other response fields from backend

Example:

Use Cases:

  1. Emergency Withdrawals: Process withdrawals when normal flow is blocked

  2. Position Closure: Close specific positions for withdrawal

  3. Partial Withdrawals: Close subset of positions

  4. Automated Processing: Build automated force withdrawal systems


getPauseVaultForForceWithdrawRequestTx

Build a pause-vault-for-force-withdraw-request transaction.

What This Does:

Pauses the vault temporarily to facilitate force withdraw request processing. This prevents new deposits and trading activity while force withdrawals are being processed.

Parameters:

  • tx (optional): Transaction

    • Existing transaction to extend

Returns:

Object containing:

  • tx: Transaction - Transaction ready to sign and execute

Example:

Use Cases:

  1. Force Withdraw Preparation: Pause vault before processing force withdrawals

  2. Emergency Procedures: Implement emergency pause mechanisms

  3. Maintenance: Temporarily halt vault activity


getUpdateWithdrawRequestSlippageTx

Build an update-withdraw-request-slippage transaction.

What This Does:

Updates the minimum acceptable collateral output amount for an existing withdraw request. This allows users to adjust their slippage tolerance after creating a withdraw request.

Parameters:

  • minCollateralAmountOut: Balance (bigint)

    • New minimum collateral amount to receive (in collateral units, 6 decimals for USDC)

    • Scaled by 1_000_000n for USDC

  • tx (optional): Transaction

    • Existing transaction to extend

Returns:

Object containing:

  • tx: Transaction - Transaction ready to sign and execute

Example:

Use Cases:

  1. Slippage Adjustment: Update slippage tolerance based on market conditions

  2. Price Protection: Tighten slippage during favorable price movements

  3. Flexibility: Loosen slippage if withdrawal is urgent

  4. Risk Management: Adjust protection dynamically


getCancelWithdrawRequestTx

Build a user transaction to cancel an existing vault withdraw request.

What This Does:

Cancels a pending withdraw request, returning the LP tokens to the user's wallet. Use this when you no longer want to withdraw or want to modify the withdraw amount.

Parameters:

  • walletAddress: SuiAddress

    • Wallet that created the withdraw request

  • tx (optional): Transaction

    • Existing transaction to extend

Returns:

Object containing:

  • tx: Transaction - Transaction ready to sign and execute

Example:


getDepositTx

Build a user deposit transaction.

What This Does:

Deposits collateral into the vault and receives LP tokens representing vault share.

Parameters:

  • walletAddress: SuiAddress

    • Depositing wallet address

  • Deposit Amount (choose one):

    • depositAmount: Balance (bigint)

      • Amount in collateral units (6 decimals for USDC: 1_000_000n)

    • depositCoinArg: TransactionObjectArgument

      • Transaction coin from previous command

  • minLpAmountOut: Balance (bigint)

    • Minimum LP tokens to receive (slippage protection)

    • In LP token units (typically 9 decimals)

  • tx (optional): Transaction

Returns:

Object containing:

  • tx: Transaction

Example:


Owner Admin Transaction Methods

getOwnerUpdateForceWithdrawDelayTx

Update vault's force withdraw delay (owner only).

Example:


getOwnerUpdateLockPeriodTx

Update vault's withdrawal lock period (owner only).

Example:


getOwnerUpdatePerformanceFeeTx

Update vault's performance fee (owner only).

Example:


getOwnerProcessWithdrawRequestsTx

Process withdraw requests (owner only).

Example:


getOwnerWithdrawPerformanceFeesTx

Withdraw performance fees (owner only).

Example:


getOwnerWithdrawCollateralTx

Owner redeems LP for collateral.

Example:


Preview Methods

getPreviewOwnerProcessWithdrawRequests

Preview processing withdrawals.


getPreviewOwnerWithdrawPerformanceFees

Preview available performance fees.


getPreviewOwnerWithdrawCollateral

Preview owner LP redemption.


getPreviewCreateWithdrawRequest

Preview creating withdraw request.


getPreviewDeposit

Preview deposit and LP tokens received.

Example:


getPreviewPauseVaultForForceWithdrawRequest

Preview the effects of pausing the vault for a force withdraw request.

What This Returns:

Preview of if pausing the vault to facilitate a force withdrawal is possible.

Parameters:

  • walletAddress: SuiAddress

    • User wallet with pending force withdraw request

Returns:

ApiPerpetualsVaultPreviewPauseVaultForForceWithdrawRequestResponse containing:

  • If vault is able to be paused

  • Next possible pause tiemstamp

Example:

Use Cases:

  1. Impact Assessment: Understand pause effects before executing

  2. Decision Support: Help determine if pause is appropriate

  3. User Communication: Inform users about potential vault pause

  4. Risk Management: Evaluate tradeoffs of pausing


getPreviewProcessForceWithdrawRequest

Preview force withdraw processing.


Data Query Methods

getWithdrawRequests

Fetch withdraw requests for the vault.

Example:


getAllWithdrawRequests

Fetch all withdraw requests for this vault across all users.

What This Returns:

Complete list of all pending withdraw requests for the vault, useful for vault owners to see all pending requests.

Returns:

ApiPerpetualsVaultsWithdrawRequestsResponse containing:

  • withdrawRequests: PerpetualsVaultWithdrawRequest[]

    • Array of all withdraw requests

    • Each request contains:

      • walletAddress: User who created the request

      • lpAmount: LP tokens to redeem

      • minCollateralAmountOut: Minimum collateral expected

      • requestTimestamp: When request was created

      • readyTimestamp: When request can be processed

      • Other request metadata

Example:

Use Cases:

  1. Owner Monitoring: Track all pending withdrawal requests

  2. Batch Processing: Identify and process ready requests

  3. Liquidity Planning: Forecast collateral needs

  4. Analytics: Analyze withdrawal patterns and slippage


Account Access Methods

partialVaultCap

Build vault cap for account operations.


getAccountObject

Get underlying account object.


getAccount

Get PerpetualsAccount wrapper for vault's account.

Example:


getLpCoinPrice

Get current LP token price in collateral units.

Example:


isPaused

Check if vault is paused.

Example:


Static Validation Methods

PerpetualsVault.isValidLpCoinName

Check if string is valid LP coin name (ASCII only).


PerpetualsVault.isValidLpCoinTypeSymbol

Check if string is valid LP coin symbol (A-Z and underscore).


Calculation Methods

PerpetualsVault.calcWithdrawRequestSlippage

Calculate withdraw request slippage.

Formula:

Example:


Complete Usage Examples

Example 1: User Vault Lifecycle

Example 2: Vault Owner Management

Last updated