Deposit to Earn Vault
Deposit assets to start earning yield.1
Import Dependencies
Import the required packages for Solana RPC communication, Kamino SDK operations, and Kit transaction building.2
Load Signer and Initialize RPC
Load your keypair from a file and initialize RPC connections.Replace
/path/to/your/keypair.json with the actual path to your keypair file. parseKeypairFile loads an existing keypair from a JSON file. The rpcSubscriptions enables real-time transaction confirmation.3
Load the Vault
Initialize the vault and load its state, reserves, and farm state once. The deposit instructions need all three.4
Set Slippage Protection
Estimate the shares the deposit will mint, minus a slippage tolerance. The deposit reverts if fewer shares would be minted.The deposit amount is in tokens (
1.0 is 1 USDC), not lamports.5
Build Deposit Instructions
Generate the deposit instructions, plus the instructions that stake the new shares in the vault’s farm.If the vault has a rewards farm,
stakeInFarmIfNeededIxs stakes the minted shares in it so the position earns farm rewards. Shares staked here are unstaked automatically when you withdraw.6
Load the Vault’s Lookup Table
Fetch the vault’s address lookup table to keep the transaction small.Every vault has its own lookup table. Compressing with it cuts the deposit from about 1,021 to 528 bytes, well under Solana’s 1,232-byte transaction limit.
7
Build and Sign Transaction
Use Kit’s functional pipe pattern to build, compress, and sign the transaction with a fresh blockhash.8
Send and Confirm Transaction
Send the deposit transaction and wait for confirmation.Once the deposit transaction is confirmed, your assets are deposited into the vault and you start earning yield. Vault shares are minted to represent your position.
Withdraw from Earn Vault
Withdraw your vault shares to receive the underlying tokens plus accrued interest.1
Import Dependencies
Import the required packages for Solana RPC communication, Kamino SDK operations, and Kit transaction building.2
Load Signer and Initialize RPC
Load your keypair from a file and initialize RPC connections.Replace
/path/to/your/keypair.json with the actual path to your keypair file. parseKeypairFile loads an existing keypair from a JSON file. The rpcSubscriptions enables real-time transaction confirmation.3
Load the Vault
Initialize the vault and load its state, reserves, and farm state once. The withdraw instructions need all three.4
Convert Tokens to Shares
Convert the token amount you want back into vault shares, capped at the shares you hold.withdrawIxs takes an amount of vault shares, not tokens. Shares grow in value as interest accrues, so one share is worth more than one token. To withdraw everything, pass userShares.totalShares.5
Build Withdraw Instructions
Generate the unstake and withdraw instructions.Deposits stake shares in the vault’s farm, so
unstakeFromFarmIfNeededIxs must come before withdrawIxs. Without it, withdrawing staked shares fails with CannotWithdrawZeroShares.6
Load the Vault’s Lookup Table
Fetch the vault’s address lookup table to keep the transaction small.Some vaults need the lookup table for a withdraw to fit in one transaction. Without it, a withdraw from one vault we tested was 1,274 bytes, over Solana’s 1,232-byte limit.
7
Build and Sign Transaction
Use Kit’s functional pipe pattern to build, compress, and sign the transaction with a fresh blockhash.8
Send and Confirm Transaction
Send the withdraw transaction and wait for confirmation.Once the withdraw transaction is confirmed, your vault shares are burned and you receive the underlying tokens plus any accrued interest.
What Happens When You Deposit?
What Happens When You Deposit?
- You deposit USDC (or another token) into the vault
- You receive vault share tokens (like kVUSDC or similar). If the vault has a rewards farm, the shares are staked in it automatically so they also earn farm rewards
- These shares represent your proportional ownership of the vault
- The shares appreciate in value as the vault earns yield
What Happens When You Withdraw?
What Happens When You Withdraw?
- Your shares are unstaked from the vault’s farm (if staked) and burned
- You receive back the underlying tokens (USDC) based on the current exchange rate