Adaptor Management

This guide explains how to add and remove adaptors in the Voltr Protocol. It covers the process of adding adaptors to vaults, and managing adaptor lifecycles.

Prerequisites

Before managing adaptors, ensure you have:

  1. An initialized vault in the Voltr Protocol

  2. Admin authority for the vault

  3. The Voltr SDK installed:

    npm install @voltr/sdk

Setup

Import the required dependencies:

import { Connection, PublicKey, Keypair } from "@solana/web3.js";
import { VoltrClient } from "@voltr/sdk";
import { BN } from "@coral-xyz/anchor";

Strategy Types

Vault owners are welcome to integrate custom adaptors created by DeFi teams. Currently. the protocol supports several in-built adaptor types:

enum StrategyType {
  Solend = "solend",
  Drift = "drift",
  Marginfi = "marginfi",
  Kamino = "kamino"
}

Adding Strategies

1. Create a Strategy

First, create a new strategy account:

const client = new VoltrClient(connection, wallet);

// Create strategy
const createStrategyIx = await client.createStrategyIx(
  { marginfi: {} }, // Or other strategy types
  {
    payer: wallet.publicKey,
    admin: adminPubkey,
    counterpartyAssetTa: counterpartyTokenAccount,
    protocolProgram: protocolProgramId
  }
);

2. Add Strategy to Vault

After creating the strategy, add it to your vault:

const addStrategyIx = await client.addStrategyToVaultIx({
  payer: wallet.publicKey,
  vault: vaultPubkey,
  strategy: strategyPubkey
});

3. To remove a strategy from a vault:

const removeStrategyIx = await client.createRemoveStrategyIx({
  admin: adminPubkey,
  vault: vaultPubkey,
  strategy: strategyPubkey
});

Account Structure

Strategy Account

interface Strategy {
  counterpartyAssetTa: PublicKey;  // Token account for the strategy
  protocolProgram: PublicKey;      // Program ID of the protocol
  strategyType: StrategyType;      // Type of strategy
}

Adaptor Strategy Account

interface AdaptorStrategy {
  adaptorProgram: PublicKey;  // Program handling the strategy
  strategy: PublicKey;        // Strategy account address
  vault: PublicKey;          // Associated vault
}

Vault Strategy Account

interface VaultStrategy {
  vaultAssetIdleAuth: PublicKey;  // Authority over idle assets
  strategy: PublicKey;            // Strategy account address
  currentAmount: BN;              // Current amount in strategy
}

Finding Strategy Addresses

The SDK provides helper functions to find strategy-related addresses:

// Find strategy PDA
const strategy = client.findStrategy(counterpartyAssetTa);

// Find adaptor strategy PDA
const adaptorStrategy = client.findAdaptorStrategy(vault, strategy);

// Find vault strategy PDA
const vaultStrategy = client.findVaultStrategy(vaultAssetIdleAuth, strategy);

// Find all strategy addresses at once
const addresses = client.findStrategyAddresses(
  vault,
  vaultAssetIdleAuth,
  counterpartyAssetTa
);

Important: Strategies can only be removed when they have no funds deployed (currentAmount = 0).

Complete Example

Here's a full example of adding and initializing a strategy:

async function addStrategy() {
  const client = new VoltrClient(connection, wallet);
  
  // Create strategy
  const createStrategyIx = await client.createStrategyIx(
    { marginfi: {} },
    {
      payer: wallet.publicKey,
      admin: wallet.publicKey,
      counterpartyAssetTa: counterpartyTaPubkey,
      protocolProgram: protocolProgramId
    }
  );

  // Find strategy address
  const strategy = client.findStrategy(counterpartyTaPubkey);

  // Add strategy to vault
  const addStrategyIx = await client.addStrategyToVaultIx({
    payer: wallet.publicKey,
    vault: vaultPubkey,
    strategy
  });

  // Combine instructions into a transaction
  // Add your transaction handling code here
}

Error Handling

Common strategy-related errors:

enum VaultError {
  InvalidAccountOwner,    // Wrong account owner
  StrategyNotEmpty,      // Strategy has funds (during removal)
  InvalidAccountInput,   // Invalid account provided
  InvalidAmount         // Invalid amount for deposit/withdraw
}

Best Practices

  1. Strategy Selection:

    • Choose strategies that match your vault's risk profile

    • Understand the underlying protocol's mechanisms

    • Verify strategy program compatibility

  2. Risk Management:

    • Start with small deposits to test strategy

    • Monitor strategy performance regularly

    • Have a withdrawal plan for emergencies

  3. Security:

    • Keep admin keys secure

    • Test on devnet first

    • Verify all account permissions

    • Double-check program IDs

  4. Operations:

    • Always check strategy balance before removal

    • Maintain accurate records of deployed assets

    • Monitor gas costs for operations

Troubleshooting

  1. Strategy Creation Fails:

    • Verify admin authority

    • Check counterparty token account exists

    • Ensure protocol program ID is correct

  2. Strategy Addition Fails:

    • Verify vault admin authority

    • Check strategy account exists

    • Ensure adaptor program matches

  3. Strategy Removal Fails:

    • Verify strategy has zero balance

    • Check admin authority

    • Ensure all funds are withdrawn

  4. Initialization Fails:

    • Check account permissions

    • Verify rent exemption

    • Validate program IDs

For more detailed information, refer to the Voltr SDK documentation or contact the development team.

Last updated