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:
Deposits: Users deposit collateral → receive LP tokens representing vault share
Trading: Vault owner trades with pooled collateral
Withdrawals: Users request withdrawal → wait for lock period → receive collateral
Performance Fees: Owner earns fees on positive performance
Force Withdrawals: Emergency mechanism to close positions and process withdrawals
Typical Usage:
Constructor
constructor
constructorCreates a new PerpetualsVault wrapper instance.
You typically don't construct this directly. Instead, use Perpetuals.getAllVaults(), Perpetuals.getVault(), or Perpetuals.getVaults().
Parameters:
vaultObject:PerpetualsVaultObjectRaw on-chain vault object snapshot containing:
objectId: Vault IDownerAddress: Vault owner addressaccountId: Underlying perpetuals account IDaccountObjectId: Account object IDcollateralCoinType: Collateral coin type (e.g., USDC)lpCoinType: LP token coin typelockPeriodMs: Minimum lock period for withdrawalsforceWithdrawDelayMs: Delay before force withdrawal can processperformanceFeePercentage: Vault performance feepausedUntilTimestamp: Optional pause timestampOther vault state fields
config(optional):CallerConfigConfiguration object containing network settings
Provider(optional):AftermathApiShared provider instance for transaction building
Remarks:
This class extends
Callerwith the"perpetuals"route prefixAll API calls resolve under
/perpetuals/vault/...
Example:
Use Cases:
Vault Wrapping: Wrap raw vault data with convenient methods
Testing: Create vault instances with mock data
Custom Initialization: Initialize with specific network configs
Static Constants
PerpetualsVault.constants
PerpetualsVault.constantsVault-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:12Maximum number of distinct markets the vault can trade
maxPendingOrdersPerPosition:70Maximum pending orders per position in the vault
Example:
Use Cases:
Validation: Validate vault parameters before creation/updates
UI Constraints: Set input field limits in user interfaces
Documentation: Show users the protocol limits
Error Handling: Provide clear error messages when limits exceeded
Withdraw Request Transaction Methods
getProcessForceWithdrawRequestTx
getProcessForceWithdrawRequestTxBuild a process-force-withdraw-request transaction.
What This Does:
Force-withdraw is an emergency mechanism that:
Closes specified positions in the vault
Processes a pending withdraw request after the delay window
Returns collateral to the user
This is used when normal withdrawal processing is delayed or unavailable.
Parameters:
walletAddress:SuiAddressUser 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):SuiAddressAddress to receive the withdrawn collateral
If omitted, collateral goes to
walletAddress
tx(optional):TransactionExisting transaction to extend
Returns:
Object containing:
tx:Transaction- Transaction ready to sign and executeOther response fields from backend
Example:
Use Cases:
Emergency Withdrawals: Process withdrawals when normal flow is blocked
Position Closure: Close specific positions for withdrawal
Partial Withdrawals: Close subset of positions
Automated Processing: Build automated force withdrawal systems
getPauseVaultForForceWithdrawRequestTx
getPauseVaultForForceWithdrawRequestTxBuild 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):TransactionExisting transaction to extend
Returns:
Object containing:
tx:Transaction- Transaction ready to sign and execute
Example:
Use Cases:
Force Withdraw Preparation: Pause vault before processing force withdrawals
Emergency Procedures: Implement emergency pause mechanisms
Maintenance: Temporarily halt vault activity
getUpdateWithdrawRequestSlippageTx
getUpdateWithdrawRequestSlippageTxBuild 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_000nfor USDC
tx(optional):TransactionExisting transaction to extend
Returns:
Object containing:
tx:Transaction- Transaction ready to sign and execute
Example:
Use Cases:
Slippage Adjustment: Update slippage tolerance based on market conditions
Price Protection: Tighten slippage during favorable price movements
Flexibility: Loosen slippage if withdrawal is urgent
Risk Management: Adjust protection dynamically
getCancelWithdrawRequestTx
getCancelWithdrawRequestTxBuild 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:SuiAddressWallet that created the withdraw request
tx(optional):TransactionExisting transaction to extend
Returns:
Object containing:
tx:Transaction- Transaction ready to sign and execute
Example:
getDepositTx
getDepositTxBuild a user deposit transaction.
What This Does:
Deposits collateral into the vault and receives LP tokens representing vault share.
Parameters:
walletAddress:SuiAddressDepositing wallet address
Deposit Amount (choose one):
depositAmount:Balance(bigint)Amount in collateral units (6 decimals for USDC:
1_000_000n)
depositCoinArg:TransactionObjectArgumentTransaction 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
getOwnerUpdateForceWithdrawDelayTxUpdate vault's force withdraw delay (owner only).
Example:
getOwnerUpdateLockPeriodTx
getOwnerUpdateLockPeriodTxUpdate vault's withdrawal lock period (owner only).
Example:
getOwnerUpdatePerformanceFeeTx
getOwnerUpdatePerformanceFeeTxUpdate vault's performance fee (owner only).
Example:
getOwnerProcessWithdrawRequestsTx
getOwnerProcessWithdrawRequestsTxProcess withdraw requests (owner only).
Example:
getOwnerWithdrawPerformanceFeesTx
getOwnerWithdrawPerformanceFeesTxWithdraw performance fees (owner only).
Example:
getOwnerWithdrawCollateralTx
getOwnerWithdrawCollateralTxOwner redeems LP for collateral.
Example:
Preview Methods
getPreviewOwnerProcessWithdrawRequests
getPreviewOwnerProcessWithdrawRequestsPreview processing withdrawals.
getPreviewOwnerWithdrawPerformanceFees
getPreviewOwnerWithdrawPerformanceFeesPreview available performance fees.
getPreviewOwnerWithdrawCollateral
getPreviewOwnerWithdrawCollateralPreview owner LP redemption.
getPreviewCreateWithdrawRequest
getPreviewCreateWithdrawRequestPreview creating withdraw request.
getPreviewDeposit
getPreviewDepositPreview deposit and LP tokens received.
Example:
getPreviewPauseVaultForForceWithdrawRequest
getPreviewPauseVaultForForceWithdrawRequestPreview 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:SuiAddressUser wallet with pending force withdraw request
Returns:
ApiPerpetualsVaultPreviewPauseVaultForForceWithdrawRequestResponse containing:
If vault is able to be paused
Next possible pause tiemstamp
Example:
Use Cases:
Impact Assessment: Understand pause effects before executing
Decision Support: Help determine if pause is appropriate
User Communication: Inform users about potential vault pause
Risk Management: Evaluate tradeoffs of pausing
getPreviewProcessForceWithdrawRequest
getPreviewProcessForceWithdrawRequestPreview force withdraw processing.
Data Query Methods
getWithdrawRequests
getWithdrawRequestsFetch withdraw requests for the vault.
Example:
getAllWithdrawRequests
getAllWithdrawRequestsFetch 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 requestlpAmount: LP tokens to redeemminCollateralAmountOut: Minimum collateral expectedrequestTimestamp: When request was createdreadyTimestamp: When request can be processedOther request metadata
Example:
Use Cases:
Owner Monitoring: Track all pending withdrawal requests
Batch Processing: Identify and process ready requests
Liquidity Planning: Forecast collateral needs
Analytics: Analyze withdrawal patterns and slippage
Account Access Methods
partialVaultCap
partialVaultCapBuild vault cap for account operations.
getAccountObject
getAccountObjectGet underlying account object.
getAccount
getAccountGet PerpetualsAccount wrapper for vault's account.
Example:
getLpCoinPrice
getLpCoinPriceGet current LP token price in collateral units.
Example:
isPaused
isPausedCheck if vault is paused.
Example:
Static Validation Methods
PerpetualsVault.isValidLpCoinName
PerpetualsVault.isValidLpCoinNameCheck if string is valid LP coin name (ASCII only).
PerpetualsVault.isValidLpCoinTypeSymbol
PerpetualsVault.isValidLpCoinTypeSymbolCheck if string is valid LP coin symbol (A-Z and underscore).
Calculation Methods
PerpetualsVault.calcWithdrawRequestSlippage
PerpetualsVault.calcWithdrawRequestSlippageCalculate withdraw request slippage.
Formula:
Example:
Complete Usage Examples
Example 1: User Vault Lifecycle
Example 2: Vault Owner Management
Last updated