A set of base scripts for interacting with the Voltr Vault protocol on Solana using the @voltr/vault-sdk. These scripts provide fundamental operations for vault administration and user interaction.
- Introduction
- Prerequisites
- Installation
- Configuration
- Available Scripts
- Basic Usage Flow
- Project Structure
- Development
This repository contains a collection of TypeScript scripts demonstrating basic interactions with Voltr Vaults on the Solana blockchain. They cover core functionalities like initializing and managing vaults, depositing and withdrawing assets for users, and querying vault/user state.
These scripts serve as a starting point and example for building more complex integrations with the Voltr protocol.
-
Node.js v18+ Ensure you have Node.js version 18 or higher installed.
-
pnpm This project uses pnpm for package management. Install it if you haven't already:
npm install -g pnpm
Or see the pnpm website.
-
Solana Keypairs You'll need separate Solana keypair files (in JSON format) for the following roles:
- Admin: Manages vault configuration and fee harvesting.
- Manager: Designated during vault initialization (role specified by Voltr protocol, used in init/harvest).
- User: Interacts with the vault (deposit/withdraw).
Store these JSON files securely on your filesystem.
-
Solana RPC URL A reliable Solana RPC endpoint URL is required. The scripts are configured to use a Helius RPC URL provided via an environment variable, but any compatible RPC should work.
-
Clone this repository:
git clone <your-repo-url> voltr-base-scripts cd voltr-base-scripts
-
Install dependencies:
pnpm install
Configuration requires setting environment variables and editing the config/base.ts file.
These scripts expect the following environment variables to be set, pointing to your keypair files and RPC URL:
ADMIN_FILE_PATH: Absolute path to the Admin keypair JSON file.MANAGER_FILE_PATH: Absolute path to the Manager keypair JSON file.USER_FILE_PATH: Absolute path to the User keypair JSON file.HELIUS_RPC_URL: Your Solana RPC endpoint URL.
Example (using .env file or exporting):
export ADMIN_FILE_PATH="/path/to/your/admin.json"
export MANAGER_FILE_PATH="/path/to/your/manager.json"
export USER_FILE_PATH="/path/to/your/user.json"
export HELIUS_RPC_URL="https://your-rpc-provider-url"Security Note: Never commit your private key JSON files to version control. Keep them secure and use environment variables or a secure secrets management system.
This file contains parameters for vault operations. You must edit this file before running scripts.
-
Vault Initialization (Needed for
admin-init-vault.ts)vaultConfig: An object defining parameters likemaxCap, fees (managerPerformanceFee,adminPerformanceFee, etc.),lockedProfitDegradationDuration,redemptionFee,issuanceFee,withdrawalWaitingPeriod.vaultParams: ContainsvaultConfigand basic metadata likename,description.
-
Core Vault Details
assetMintAddress: Required. The public key (string) of the token mint that will be deposited into the vault (e.g., USDC, SOL).assetTokenProgram: Required. The public key (string) of the SPL Token program governing theassetMintAddress(e.g.,Tokenkeg...for SPL Token,Tokenz...for Token-2022).vaultAddress: Required after initialization. Leave empty initially. After runningadmin-init-vault.ts, paste the outputted vault public key here.
-
Transaction Optimization (Optional)
useLookupTable: Boolean. Set totrueto create and use an Address Lookup Table (LUT) during initialization for potentially cheaper transactions.lookupTableAddress: Required ifuseLookupTableis true. Leave empty initially. After runningadmin-init-vault.tswithuseLookupTable: true, paste the outputted LUT public key here.
-
Action Parameters (Needed for deposit/withdraw scripts)
depositAmountVault: The amount of the base asset (in its smallest unit, e.g., lamports for SOL, 10^6 for USDC) to deposit.withdrawAmountVault: The amount to withdraw. Interpretation depends onisWithdrawInLp.isWithdrawAll: Boolean. Iftrue, attempts to withdraw the user's entire position, overridingwithdrawAmountVault.isWithdrawInLp: Boolean. Iftrue,withdrawAmountVaultis interpreted as the amount of LP tokens to withdraw. Iffalse, it's interpreted as the amount of the underlying asset to withdraw.
Run scripts using pnpm ts-node <script_path>. Ensure environment variables are set and config/base.ts is updated appropriately for the script you are running.
-
src/scripts/admin-init-vault.ts- Initializes a new Voltr vault using the Admin as payer and designates the Manager.
- Requires
vaultConfig,vaultParams,assetMintAddress,assetTokenPrograminbase.ts. - Outputs the new
vaultAddressandlookupTableAddress(ifuseLookupTableis true). You must updatebase.tswith these values after running. - Uses
ADMIN_FILE_PATHandMANAGER_FILE_PATH.
-
src/scripts/admin-update-vault.ts- Updates the configuration (
vaultConfig) of an existing vault. - Requires
vaultAddressand the desiredvaultConfiginbase.ts. - Uses
ADMIN_FILE_PATH.
- Updates the configuration (
-
src/scripts/admin-harvest-fee.ts- Collects accumulated performance and protocol fees from the vault, distributing them to Admin, Manager, and Protocol Admin.
- Requires
vaultAddressinbase.ts. - Uses
ADMIN_FILE_PATHandMANAGER_FILE_PATH.
-
src/scripts/user-deposit-vault.ts- Deposits a specified amount (
depositAmountVault) of the vault's asset token from the User's account into the vault, receiving LP tokens in return. - Handles wSOL wrapping/unwrapping if
assetMintAddressis the native SOL mint. - Requires
vaultAddress,assetMintAddress,assetTokenProgram,depositAmountVaultinbase.ts. - Uses
USER_FILE_PATH.
- Deposits a specified amount (
-
src/scripts/user-request-withdraw-vault.ts- Initiates a withdrawal request for the User. Fails if another request is pending.
- Uses
withdrawAmountVault,isWithdrawInLp,isWithdrawAllfrombase.ts. - Requires
vaultAddressinbase.ts. - Uses
USER_FILE_PATH.
-
src/scripts/user-withdraw-vault.ts- Completes a previously requested withdrawal after any waiting period has passed. Fails if no request was made or the waiting period isn't over.
- Handles wSOL unwrapping if necessary.
- Requires
vaultAddress,assetMintAddress,assetTokenPrograminbase.ts. - Uses
USER_FILE_PATH.
-
src/scripts/user-instant-withdraw-vault.ts- Performs an instant withdrawal from the vault in a single transaction.
- Uses
withdrawAmountVault,isWithdrawInLp,isWithdrawAllfrombase.ts. - Requires
vaultAddress,assetMintAddress,assetTokenPrograminbase.ts. - Uses
USER_FILE_PATH.
-
src/scripts/user-query-position.ts- Fetches the User's current LP token balance and calculates the approximate equivalent value in the underlying vault asset (both before and after potential withdrawal fees/degradation).
- Requires
vaultAddressinbase.ts. - Uses
USER_FILE_PATH.
-
src/scripts/query-strategy-positions.ts- Fetches the vault account data, displays the total asset value, and lists any initialized strategy allocations (showing strategy address and position value).
- Requires
vaultAddressinbase.ts. - Uses
ADMIN_FILE_PATH(implicitly via RPC connection, though no signing needed).
- Configure Environment: Set the
ADMIN_FILE_PATH,MANAGER_FILE_PATH,USER_FILE_PATH, andHELIUS_RPC_URLenvironment variables. - Configure Vault Parameters: Edit
config/base.ts. Fill invaultConfig,vaultParams,assetMintAddress,assetTokenProgram. Decide onuseLookupTable. LeavevaultAddressandlookupTableAddressempty for now. - Initialize Vault (Admin):
pnpm ts-node src/scripts/admin-init-vault.ts
- Update Config: Copy the outputted
Vault:andLookup Table:(if used) addresses and paste them into thevaultAddressandlookupTableAddressfields inconfig/base.ts. - Update Vault (Admin, Optional): If you need to change config after init:
pnpm ts-node src/scripts/admin-update-vault.ts
- Deposit (User): Set
depositAmountVaultinconfig/base.ts.pnpm ts-node src/scripts/user-deposit-vault.ts
- Check Position (User):
pnpm ts-node src/scripts/user-query-position.ts
- Withdraw (User): Set withdrawal parameters (
withdrawAmountVault,isWithdrawInLp,isWithdrawAll) inconfig/base.ts.- If
withdrawalWaitingPeriod> 0:# Step 1: Request pnpm ts-node src/scripts/user-request-withdraw-vault.ts # Step 2: Wait for the period, then withdraw pnpm ts-node src/scripts/user-withdraw-vault.ts
- Instant withdraw:
pnpm ts-node src/scripts/user-instant-withdraw-vault.ts
- If
- Harvest Fees (Admin):
pnpm ts-node src/scripts/admin-harvest-fee.ts
- Query Strategies (Admin/General):
pnpm ts-node src/scripts/query-strategy-positions.ts
voltr-base-scripts
├── config/
│ └── base.ts # Main configuration file
├── src/
│ ├── constants/
│ │ └── base.ts # Base constants (e.g., PROTOCOL_ADMIN)
│ ├── utils/
│ │ └── helper.ts # Utility functions (transactions, ATAs, LUTs)
│ └── scripts/ # Executable scripts for vault interactions
│ ├── admin-*.ts # Scripts requiring Admin keypair
│ ├── user-*.ts # Scripts requiring User keypair
│ └── query-*.ts # Scripts for querying state
├── node_modules/ # Project dependencies
├── pnpm-lock.yaml # Dependency lockfile
├── package.json # Project metadata and dependencies
├── tsconfig.json # TypeScript compiler options
└── README.md # This file
@coral-xyz/anchor: For interacting with Anchor programs.@solana/web3.js: Core Solana JavaScript SDK.@solana/spl-token: Utilities for SPL Tokens.@voltr/vault-sdk: The official SDK for interacting with Voltr Vaults.bs58: Base58 encoding/decoding.
typescript: TypeScript language support.ts-node: Execute TypeScript files directly.@types/*: Type definitions for Node.js and libraries.
Feel free to extend these base scripts for more specific use cases or integrations.
For questions or support regarding the Voltr protocol itself, please refer to the official Voltr documentation.