Skip to main content

Setup

Import the required dependencies:
import { BN } from "@coral-xyz/anchor";
import { VoltrClient, SEEDS, LENDING_ADAPTOR_PROGRAM_ID } from "@voltr/vault-sdk";
import {
  Connection,
  Keypair,
  PublicKey,
  sendAndConfirmTransaction,
} from "@solana/web3.js";
import fs from "fs";
Vault owners can integrate with the lending adaptor or custom adaptors created by DeFi teams.

Adding an Adaptor

1. Define Required Variables

const adminFilePath = "/path/to/admin.json";
const assetMintAddress = "...";
const solanaRpcUrl = "your-solana-rpc-url";

const adminKp = Keypair.fromSecretKey(
  Uint8Array.from(JSON.parse(fs.readFileSync(adminFilePath, "utf-8")))
);

const vault = new PublicKey("previously-initialized-vault");
const connection = new Connection(solanaRpcUrl);
const client = new VoltrClient(connection);

2. Create Add Adaptor Instruction

const createAddAdaptorIx = await client.createAddAdaptorIx({
  vault,
  admin: adminKp.publicKey,
  payer: adminKp.publicKey,
});

3. Send and Confirm

const txSig = await sendAndConfirmTransaction(
  [createAddAdaptorIx],
  connection,
  [adminKp]
);

Initializing Strategies

1. Derive Strategy Address

// the counterParty's token account the vault will be transferring to
const counterPartyTa = new PublicKey("...");

const [strategy] = PublicKey.findProgramAddressSync(
  [SEEDS.STRATEGY, counterPartyTa.toBuffer()],
  LENDING_ADAPTOR_PROGRAM_ID
);

2. Create Strategy Initialization Instruction

const createInitializeStrategyIx = await client.createInitializeStrategyIx(
  {},
  {
    payer,
    vault,
    manager: payer,
    strategy,
    remainingAccounts: [
      { pubkey: protocolProgram, isSigner: false, isWritable: false },
      // Additional required accounts...
    ],
  }
);

3. Send and Confirm

const txSig = await sendAndConfirmTransaction(
  [createInitializeStrategyIx],
  connection,
  [adminKp]
);

Required Account Structure

The strategy initialization requires several key accounts:
  1. Core Accounts: payer, vault, manager, strategy, protocolProgram
  2. Protocol-Specific Accounts: Protocol program account, required protocol state accounts, token accounts and authorities, system accounts (RENT, etc.)

Best Practices

  • Choose strategies that match your vault’s risk profile
  • Understand the underlying protocol’s mechanisms
  • Verify strategy program compatibility
  • Start with small deposits to test strategy
  • Monitor strategy performance regularly
  • Have a withdrawal plan for emergencies
  • Keep admin keys secure
  • Test on devnet first
  • Verify all account permissions
  • Double-check program IDs
  • Strategy Creation Fails: Verify admin authority, check counterparty token account exists, ensure protocol program ID is correct
  • Strategy Addition Fails: Verify vault admin authority, check strategy account exists, ensure adaptor program matches
  • Strategy Removal Fails: Verify strategy has zero balance, check admin authority, ensure all funds are withdrawn
For additional support, refer to the Voltr SDK documentation or example scripts.