Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.meteora.ag/llms.txt

Use this file to discover all available pages before exploring further.

Use @meteora-ag/vault-sdk when building an off-chain app, backend service, or script that needs to read Dynamic Vault state or build deposit and withdrawal transactions.

Vault SDK Repository

Public TypeScript SDK source, tests, IDL, and Rust client helper.

NPM Package

Published @meteora-ag/vault-sdk package.

Install

npm install @meteora-ag/vault-sdk @coral-xyz/anchor @solana/web3.js@1 @solana/spl-token bn.js
The package currently targets the @solana/web3.js v1 transaction model.

Create A Client

VaultImpl.create takes a token mint public key. For SOL, use NATIVE_MINT from @solana/spl-token.
import VaultImpl from "@meteora-ag/vault-sdk";
import { AnchorProvider, BN, Wallet } from "@coral-xyz/anchor";
import { NATIVE_MINT } from "@solana/spl-token";
import { Connection, Keypair } from "@solana/web3.js";

const connection = new Connection(process.env.RPC_URL!, "confirmed");

// Server-side scripts can use a Keypair-backed Anchor wallet.
// Browser apps should use the connected wallet's signing adapter instead.
const signer = Keypair.generate();
const wallet = new Wallet(signer);
const provider = new AnchorProvider(connection, wallet, {
  commitment: "confirmed",
});

const vault = await VaultImpl.create(connection, NATIVE_MINT, {
  cluster: "mainnet-beta",
});

console.log({
  vault: vault.vaultPda.toBase58(),
  tokenVault: vault.tokenVaultPda.toBase58(),
  lpMint: vault.vaultState.lpMint.toBase58(),
});

Read Vault State

await vault.refreshVaultState();

const lpSupply = await vault.getVaultSupply();
const withdrawableAmount = await vault.getWithdrawableAmount();
const userLpBalance = await vault.getUserBalance(wallet.publicKey);

console.log({
  totalAmount: vault.vaultState.totalAmount.toString(),
  withdrawableAmount: withdrawableAmount.toString(),
  lpSupply: lpSupply.toString(),
  userLpBalance: userLpBalance.toString(),
});
getWithdrawableAmount() computes the unlocked vault amount from on-chain time and vaultState.lockedProfitTracker. It is the client-side equivalent of the program’s get_unlocked_amount simulation flow.

Deposit

deposit returns an unsigned Transaction with ATA setup and SOL wrapping instructions when needed.
const amountInLamports = new BN(1_000_000_000); // 1 SOL

const depositTx = await vault.deposit(wallet.publicKey, amountInLamports);

depositTx.feePayer = wallet.publicKey;
console.log(await connection.simulateTransaction(depositTx));

const depositSignature = await provider.sendAndConfirm(depositTx);
console.log("Deposit", depositSignature);

Withdraw

withdraw expects the LP token amount to burn. Use getUserBalance or getUnmintAmount to choose the LP amount.
const userLpBalance = await vault.getUserBalance(wallet.publicKey);
const withdrawTx = await vault.withdraw(wallet.publicKey, userLpBalance);

withdrawTx.feePayer = wallet.publicKey;
console.log(await connection.simulateTransaction(withdrawTx));

const withdrawSignature = await provider.sendAndConfirm(withdrawTx);
console.log("Withdraw", withdrawSignature);
The SDK method parameter is named baseTokenAmount, but the withdrawal path passes it to the program as LP unmint_amount. Treat the value as vault LP tokens to burn.

Affiliate Initialization

Affiliate partners pass affiliateId when creating the vault client. Deposits and withdrawals then route through the affiliate program wrapper.
import { PublicKey } from "@solana/web3.js";

const affiliateVault = await VaultImpl.create(connection, NATIVE_MINT, {
  cluster: "mainnet-beta",
  affiliateId: new PublicKey("YOUR_PARTNER_PUBLIC_KEY"),
});

const partnerInfo = await affiliateVault.getAffiliateInfo();
console.log({
  partnerToken: partnerInfo.partnerToken.toBase58(),
  feeRatio: partnerInfo.feeRatio.toString(),
  cumulativeFee: partnerInfo.cummulativeFee.toString(),
});

Local SDK Tests

cd vault-sdk/ts-client
pnpm install
pnpm test
pnpm run test-affiliate
Some tests and examples expect live RPC access, deployed vault accounts, or local validator fixtures. For production integrations, simulate transactions and test on devnet before sending mainnet transactions.