Solana Vault Integration
Complete SDK for interacting with Boring Vault on Solana blockchain
Introduction
The Boring Vault Solana SDK provides comprehensive tools for interacting with Boring Vault on the Solana blockchain. This SDK supports both SPL token deposits and native SOL deposits, along with queued withdrawals and comprehensive vault management.
Features
- ✅ SPL Token Deposits - Deposit any supported SPL token into vaults
- ✅ Native SOL Deposits - Direct SOL deposits without wrapping
- ✅ Queued Withdrawals - Request withdrawals through the Boring Queue system
- ✅ Withdraw Status Tracking - Check status of pending withdraw requests
- ✅ Vault Information - Get share values, supply, and total assets (TVL)
- ✅ Input Validation - Automatic validation of deposit amounts and parameters
- ✅ Wallet Support - Compatible with both wallet adapters and keypairs
- ✅ Error Handling - Comprehensive error handling with detailed messages
- ✅ Transaction Monitoring - Built-in transaction status polling and explorer links
Installation & Dependency Management
Installation
Handling Dependency Conflicts
Due to version conflicts in the Solana ecosystem, you may encounter module resolution errors. If you see errors like:
Add the following overrides to your package.json
:
After adding the overrides, run:
VaultSDK
The VaultSDK
class is the main interface for interacting with Boring Vault on Solana.
Setup
Getting Vault Information
Get User Share Balance
Get Complete Vault Data
Get Vault Balance
Get Share Value
Get the value of 1 share in terms of the underlying base asset.
Get Total Assets (TVL)
Get the total value locked (TVL) in a vault, calculated as total shares × share value.
Depositing Assets
SPL Token Deposits
Native SOL Deposits
Queued Withdrawals
The SDK supports queued withdrawals through the Boring Queue system, allowing users to request withdrawals that can be fulfilled by external solvers at a discount.
BoringVaultSolana (Low-Level API)
For advanced use cases, you can access the low-level BoringVaultSolana
class directly.
Creating a BoringVaultSolana Instance
User Share Balances
Building Transactions
SPL Token Deposit Transaction
SOL Deposit Transaction
PDA Derivations
Working with Keypairs
For testing or administrative operations, you may need to load keypairs from Solana CLI format:
Input Validation
The SDK automatically validates input parameters:
- Deposit amounts must be positive non-zero values
- Minimum mint amounts must be positive non-zero values
- Discount percentages must be between 0% and 5%
- Share amounts must be greater than 0
- Deadline seconds must be at least 1 hour
Error Handling
The SDK provides comprehensive error handling with detailed messages:
Complete Example
Here's a comprehensive example showing common vault operations:
Constants
The SDK includes useful constants for Solana operations:
Transaction Options
All transaction methods support the following options:
Best Practices
- Always validate inputs - The SDK validates automatically, but check business logic too
- Handle errors gracefully - Network issues and program errors can occur
- Use appropriate slippage - 5% is usually safe for most operations
- Monitor transactions - Use the provided explorer links to track status
- Test on devnet first - Always test new integrations on devnet
- Reserve SOL for fees - Keep ~0.01 SOL for transaction fees when depositing SOL
- Check vault status - Ensure vaults aren't paused before attempting operations
Updating price feeds
To guarantee the freshest JitoSOL/SOL price — crank the Pyth oracle just before sending your state-changing transaction:
User Share Management
fetchUserShares
This function provides the decimal adjusted (human readable) numerical value of vault shares that a user owns in their account.
Inputs
- userAddress: The address of the user in the vault you'd like to get the shares for
- vaultId: The vault ID to check shares for
Outputs
A promise that returns the decimal adjusted (human readable) total numerical value of all shares of a vault a user owns as a number
.
Example
fetchShareValue
This function retrieves the value for 1 share of the vault in terms of the underlying baseAsset.
Inputs
- vaultId: The vault ID to get the share value for
Outputs
A promise that returns the decimal adjusted (human readable) numerical value for 1 share in terms of the underlying baseAsset as a number
.
Example
fetchTotalAssets
This function retrieves a vault's TVL in terms of the baseAsset of the vault. Calculated as total shares × share value.
Inputs
- vaultId: The vault ID to get the total assets for
Outputs
A promise that returns the decimal adjusted (human readable) total asset numerical value of the vault (aka TVL) in terms of the baseAsset as a number
.
Example
Withdraw Status Tracking
boringQueueStatuses
This function retrieves a list of all NON-EXPIRED withdraw intents for a user. It's designed to be compatible with the EVM version of the Boring Vault API.
Inputs
- userAddress: The user's wallet address (string or PublicKey)
- vaultId: (Optional) vault ID to filter by - only returns requests for this specific vault
Outputs
A promise that returns a list of BoringQueueStatus
objects with the following properties:
Property | Type | Description |
---|---|---|
nonce | number | The nonce/ID of the withdraw request |
user | string | The user's wallet address |
tokenOut | TokenMetadata | The output token information |
tokenOut.address | string | Token mint address |
tokenOut.decimals | number | Decimal precision of the token |
sharesWithdrawing | number | Human-readable number of shares being withdrawn |
assetsWithdrawing | number | Human-readable number of tokens being withdrawn |
creationTime | number | Unix seconds when the request was made |
secondsToMaturity | number | Seconds until the request can be fulfilled |
secondsToDeadline | number | Seconds after maturity until the request expires |
errorCode | number | Error code (always 0 on Solana - valid requests only) |
transactionHashOpened | string | Transaction hash (empty string on Solana) |
Features
- ✅ Performance Optimized: Fetches only the latest 7 requests by default
- ✅ Automatic Filtering: Only returns non-expired requests
- ✅ Token Metadata: Automatically fetches token decimals and addresses
- ✅ Human-Readable: Converts raw amounts to properly formatted numbers
- ✅ Vault Filtering: Optional vault-specific filtering