Class VoltrClient

Main client for interacting with the Voltr protocol

The VoltrClient provides methods for initializing and managing vaults, handling strategies, and performing deposits/withdrawals. It requires a Solana connection and optionally accepts a wallet for signing transactions.

import { VoltrClient } from '@voltr/sdk';
import { Connection } from '@solana/web3.js';

const connection = new Connection('https://api.mainnet-beta.solana.com');
const client = new VoltrClient(connection);

Hierarchy

  • AccountUtils
    • VoltrClient

Constructors

  • Creates a new VoltrClient instance

    Parameters

    • conn: Connection

      Solana connection instance

    • Optionalwallet: Keypair

      Optional keypair for signing transactions

    Returns VoltrClient

Properties

adaptorIdl: Idl
adaptorProgram: Program<VoltrAdaptor>
conn: Connection
provider: AnchorProvider
vaultIdl: Idl
vaultProgram: Program<VoltrVault>

Methods

  • Creates an instruction to add a strategy to a vault

    Parameters

    • params: { payer: PublicKey; strategy: PublicKey; vault: PublicKey }

      Parameters for adding strategy to vault

    Returns Promise<TransactionInstruction>

    Promise resolving to a TransactionInstruction

    If the instruction creation fails

    const ix = await client.addStrategyToVaultIx({
    payer: payerPubkey,
    vault: vaultPubkey,
    strategy: strategyPubkey
    });
  • Calculates the amount of assets that would be received for a given LP token amount

    Parameters

    • vaultPk: PublicKey

      Public key of the vault

    • lpAmount: BN

      Amount of LP tokens to calculate for

    Returns Promise<BN>

    Promise resolving to the amount of assets that would be received

    If LP supply or total assets are invalid

    If math overflow occurs during calculation

    const assetsToReceive = await client.calculateAssetsForWithdraw(
    vaultPubkey,
    new BN('1000000000')
    );
  • Calculates the amount of LP tokens that would be received for a given asset deposit

    Parameters

    • depositAmount: BN

      Amount of assets to deposit

    • vaultPk: PublicKey

      Public key of the vault

    Returns Promise<BN>

    Promise resolving to the amount of LP tokens that would be received

    If math overflow occurs during calculation

    const lpTokens = await client.calculateLpTokensForDeposit(
    new BN('1000000000'),
    vaultPubkey
    );
  • Creates a deposit instruction

    Parameters

    • amount: BN

      Amount of tokens to deposit

    • params: { userAuthority: PublicKey; vault: PublicKey; vaultAssetMint: PublicKey }

      Deposit parameters

    Returns Promise<TransactionInstruction>

    Promise resolving to a TransactionInstruction

    const ix = await client.createDepositIx(
    new BN('1000000000'),
    {
    userAuthority: userPubkey,
    vault: vaultPubkey,
    vaultAssetMint: mintPubkey
    }
    );
  • Creates an instruction to deposit assets into a strategy

    Parameters

    • amount: BN

      Amount of assets to deposit

    • params: {
          counterpartyAssetTa: PublicKey;
          protocolProgram: PublicKey;
          remainingAccounts: {
              isSigner: boolean;
              isWritable: boolean;
              pubkey: PublicKey;
          }[];
          strategy: PublicKey;
          vault: PublicKey;
          vaultAssetMint: PublicKey;
          vaultStrategy: PublicKey;
      }

      Strategy deposit parameters

    Returns Promise<TransactionInstruction>

    Promise resolving to a TransactionInstruction

    If the instruction creation fails

    const ix = await client.createDepositStrategyIx(
    new BN('1000000000'),
    {
    vault: vaultPubkey,
    vaultAssetMint: mintPubkey,
    strategy: strategyPubkey,
    vaultStrategy: vaultStrategyPubkey,
    counterpartyAssetTa: taPubkey,
    remainingAccounts: []
    }
    );
  • Creates an instruction to initialize a new vault

    Parameters

    • params: {
          admin: PublicKey;
          manager: PublicKey;
          payer: PublicKey;
          vault: Keypair;
          vaultAssetMint: PublicKey;
          vaultParams: VaultParams;
      }

      Parameters for initializing the vault

    Returns Promise<TransactionInstruction>

    Promise resolving to a TransactionInstruction

    const ix = await client.createInitializeVaultIx({
    vault: vaultKeypair,
    vaultAssetMint: new PublicKey('...'),
    admin: adminPubkey,
    manager: managerPubkey,
    payer: payerPubkey,
    vaultParams: {
    config: {
    managementFee: 50, // 0.5%
    performanceFee: 1000, // 10%
    maxCap: new BN('1000000000')
    },
    name: "My Vault",
    description: "Example vault"
    }
    });
  • Creates an instruction to remove a strategy from a vault

    Parameters

    • params: { admin: PublicKey; strategy: PublicKey; vault: PublicKey }

      Parameters for removing strategy

    Returns Promise<TransactionInstruction>

    Promise resolving to a TransactionInstruction

    If the instruction creation fails

    const ix = await client.createRemoveStrategyIx({
    admin: adminPubkey,
    vault: vaultPubkey,
    strategy: strategyPubkey
    });
  • Creates an instruction to initialize a new strategy

    Parameters

    • strategyType:
          | { marginfi: Record<string, never> }
          | { kamino: Record<string, never> }
          | { solend: Record<string, never> }
          | { driftx: Record<string, never> }

      Type of strategy to create (marginfi or kamino or drift or solend)

    • params: {
          admin: PublicKey;
          counterpartyAssetTa: PublicKey;
          payer: PublicKey;
          protocolProgram: PublicKey;
      }

      Strategy initialization parameters

    Returns Promise<TransactionInstruction>

    Promise resolving to a TransactionInstruction

    If the instruction creation fails

    const ix = await client.createStrategyIx(
    { marginfi: {} },
    {
    payer: payerPubkey,
    admin: adminPubkey,
    counterpartyAssetTa: taPubkey,
    protocolProgram: programPubkey
    }
    );
  • Creates a withdraw instruction

    Parameters

    • amount: BN

      Amount of LP tokens to withdraw

    • params: { userAuthority: PublicKey; vault: PublicKey; vaultAssetMint: PublicKey }

      Withdraw parameters

    Returns Promise<TransactionInstruction>

    Promise resolving to a TransactionInstruction

    If the instruction creation fails

    const ix = await client.createWithdrawIx(
    new BN('1000000000'),
    {
    userAuthority: userPubkey,
    vault: vaultPubkey,
    vaultAssetMint: mintPubkey
    }
    );
  • Creates an instruction to withdraw assets from a strategy

    Parameters

    • amount: BN

      Amount of assets to withdraw

    • params: {
          counterpartyAssetTa: PublicKey;
          counterpartyAssetTaAuth: PublicKey;
          protocolProgram: PublicKey;
          remainingAccounts: {
              isSigner: boolean;
              isWritable: boolean;
              pubkey: PublicKey;
          }[];
          strategy: PublicKey;
          vault: PublicKey;
          vaultAssetMint: PublicKey;
          vaultStrategy: PublicKey;
      }

      Strategy withdrawal parameters

    Returns Promise<TransactionInstruction>

    Promise resolving to a TransactionInstruction

    If the instruction creation fails

    const ix = await client.createWithdrawStrategyIx(
    new BN('1000000000'),
    {
    vault: vaultPubkey,
    vaultAssetMint: mintPubkey,
    strategy: strategyPubkey,
    vaultStrategy: vaultStrategyPubkey,
    counterpartyAssetTa: taPubkey,
    counterpartyAssetTaAuth: taAuthPubkey,
    remainingAccounts: []
    }
    );
  • Fetches an adaptor strategy account's data

    Parameters

    • adaptorStrategy: PublicKey

      Public key of the adaptor strategy account

    Returns Promise<{ adaptorProgram: PublicKey; strategy: PublicKey; vault: PublicKey }>

    Promise resolving to the adaptor strategy account data

    const adaptorStrategyAccount = await client.fetchAdaptorStrategyAccount(adaptorStrategyPubkey);
    
  • Fetches all strategy accounts

    Returns Promise<
        ProgramAccount<
            {
                counterpartyAssetTa: PublicKey;
                protocolProgram: PublicKey;
                strategyType: any;
            },
        >[],
    >

    Promise resolving to an array of strategy accounts

    const strategyAccounts = await client.fetchAllStrategyAccounts();
    
  • Fetches a strategy account's data

    Parameters

    • strategy: PublicKey

      Public key of the strategy

    Returns Promise<
        {
            counterpartyAssetTa: PublicKey;
            protocolProgram: PublicKey;
            strategyType: any;
        },
    >

    Promise resolving to the strategy account data

    const strategyAccount = await client.fetchStrategyAccount(strategyPubkey);
    
  • Fetches a vault account's data

    Parameters

    • vault: PublicKey

      Public key of the vault

    Returns Promise<
        {
            admin: PublicKey;
            asset: any;
            configuration: any;
            description: number[];
            lastUpdateSlot: BN;
            lp: any;
            manager: PublicKey;
            name: number[];
        },
    >

    Promise resolving to the vault account data

  • Fetches a vault strategy account's data

    Parameters

    • vaultStrategy: PublicKey

      Public key of the vault strategy account

    Returns Promise<
        {
            currentAmount: BN;
            strategy: PublicKey;
            vaultAssetIdleAuth: PublicKey;
        },
    >

    Promise resolving to the vault strategy account data

    const vaultStrategyAccount = await client.fetchVaultStrategyAccount(vaultStrategyPubkey);
    
  • Fetches all vault strategy accounts

    Parameters

    • vaultAssetIdleAuth: PublicKey

      Public key of the vault asset idle auth

    Returns Promise<
        ProgramAccount<
            {
                currentAmount: BN;
                strategy: PublicKey;
                vaultAssetIdleAuth: PublicKey;
            },
        >[],
    >

    Promise resolving to an array of vault strategy accounts

    const vaultStrategyAccounts = await client.fetchVaultStrategyAccounts(vaultAssetIdleAuthPubkey);
    
  • Finds the adaptor strategy PDA for a given vault and strategy

    Parameters

    • vault: PublicKey

      Public key of the vault

    • strategy: PublicKey

      Public key of the strategy

    Returns PublicKey

    The PDA for the adaptor strategy account

    const adaptorStrategy = client.findAdaptorStrategy(vaultPubkey, strategyPubkey);
    
  • Finds the strategy PDA for a given counterparty asset token account

    Parameters

    • counterpartyAssetTa: PublicKey

      Public key of the counterparty asset token account

    Returns PublicKey

    The PDA for the strategy account

    const strategy = client.findStrategy(counterpartyAssetTaPubkey);
    
  • Finds all strategy-related addresses

    Parameters

    • vault: PublicKey

      Public key of the vault

    • vaultAssetIdleAuth: PublicKey

      Public key of the vault's asset idle authority

    • counterpartyAssetTa: PublicKey

      Public key of the counterparty asset token account

    Returns { adaptorStrategy: PublicKey; strategy: PublicKey; vaultStrategy: PublicKey }

    Object containing all strategy-related PDAs

  • Finds all vault-related addresses

    Parameters

    • vault: PublicKey

      Public key of the vault

    Returns {
        vaultAssetIdleAuth: PublicKey;
        vaultLpFeeAuth: PublicKey;
        vaultLpMint: PublicKey;
    }

    Object containing all vault-related PDAs

  • Finds the vault's asset idle authority address

    Parameters

    • vault: PublicKey

      Public key of the vault

    Returns PublicKey

    The PDA for the vault's asset idle authority

  • Finds the vault's LP fee authority address

    Parameters

    • vault: PublicKey

      Public key of the vault

    Returns PublicKey

    The PDA for the vault's LP fee authority

    const feeAuth = client.findVaultLpFeeAuth(vaultPubkey);
    
  • Finds the vault LP mint address for a given vault

    Parameters

    • vault: PublicKey

      Public key of the vault

    Returns PublicKey

    The PDA for the vault's LP mint

  • Finds the vault strategy PDA for a given vault and strategy

    Parameters

    • vaultAssetIdleAuth: PublicKey

      Public key of the vault's asset idle authority

    • strategy: PublicKey

      Public key of the strategy

    Returns PublicKey

    The PDA for the vault strategy account

  • Parameters

    • publicKey: PublicKey

    Returns Promise<number>