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

  • 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 an instruction to add an adaptor to a vault

    Parameters

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

      Parameters for adding adaptor to vault

      • payer: PublicKey

        Public key of the payer

      • vault: PublicKey

        Public key of the vault

    Returns Promise<TransactionInstruction>

    Transaction instruction for adding adaptor to vault

    If the instruction creation fails

    const ix = await client.createAddAdaptorIx({
    vault: vaultPubkey,
    payer: payerPubkey
    });
  • Creates a deposit instruction

    Parameters

    • amount: BN

      Amount of tokens to deposit

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

      Deposit parameters

      • assetTokenProgram: PublicKey

        Public key of the asset token program

      • userAuthority: PublicKey

        Public key of the user's transfer authority

      • vault: PublicKey

        Public key of the vault

      • vaultAssetMint: PublicKey

        Public key of the vault asset mint

    Returns Promise<TransactionInstruction>

    Transaction instruction for depositing tokens

    If instruction creation fails

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

    Parameters

    • depositArgs: depositStrategyArgs

      Deposit arguments

      • OptionaladditionalArgs?: null | Buffer<ArrayBufferLike>
      • depositAmount: BN
      • OptionalinstructionDiscriminator?: null | Buffer<ArrayBufferLike>
    • params: {
          assetTokenProgram: PublicKey;
          remainingAccounts: {
              isSigner: boolean;
              isWritable: boolean;
              pubkey: PublicKey;
          }[];
          strategy: PublicKey;
          vault: PublicKey;
          vaultAssetMint: PublicKey;
      }

      Strategy deposit parameters

      • assetTokenProgram: PublicKey

        Public key of the asset token program

      • remainingAccounts: { isSigner: boolean; isWritable: boolean; pubkey: PublicKey }[]

        Remaining accounts for the instruction

      • strategy: PublicKey

        Public key of the strategy

      • vault: PublicKey

        Public key of the vault

      • vaultAssetMint: PublicKey

        Public key of the vault asset mint

    Returns Promise<TransactionInstruction>

    Transaction instruction for depositing assets into strategy

    If the instruction creation fails

    const ix = await client.createDepositStrategyIx(
    {
    depositAmount: new BN('1000000000'),
    instructionDiscriminator: Buffer.from('...'),
    additionalArgs: Buffer.from('...')
    },
    {
    vault: vaultPubkey,
    vaultAssetMint: mintPubkey,
    strategy: strategyPubkey,
    assetTokenProgram: tokenProgramPubkey,
    remainingAccounts: []
    }
    );
  • Creates an instruction to initialize a strategy to a vault

    Parameters

    • initArgs: InitializeStrategyArgs

      Arguments for strategy initialization

      • OptionaladditionalArgs?: null | Buffer<ArrayBufferLike>
      • OptionalinstructionDiscriminator?: null | Buffer<ArrayBufferLike>
    • Optionalparams: { manager: PublicKey; payer: PublicKey; strategy: PublicKey; vault: PublicKey }

      Parameters for initializing strategy to vault

      • manager: PublicKey

        Public key of the manager

      • payer: PublicKey

        Public key of the payer

      • strategy: PublicKey

        Public key of the strategy

      • vault: PublicKey

        Public key of the vault

    Returns Promise<TransactionInstruction>

    Transaction instruction for initializing strategy to vault

    If the instruction creation fails

    const ix = await client.createInitializeStrategyIx(
    {
    instructionDiscriminator: Buffer.from('...'), // optional
    additionalArgs: Buffer.from('...') // optional
    },
    {
    payer: payerPubkey,
    vault: vaultPubkey,
    manager: managerPubkey,
    strategy: strategyPubkey
    }
    );
  • Creates an instruction to initialize a new vault

    Parameters

    • vaultParams: VaultParams

      Configuration parameters for the vault

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

      Additional parameters for initializing the vault

      • admin: PublicKey

        Public key of the vault admin

      • manager: PublicKey

        Public key of the vault manager

      • payer: PublicKey

        Public key of the fee payer

      • vault: Keypair

        Keypair for the new vault

      • vaultAssetMint: PublicKey

        Public key of the vault's asset mint

    Returns Promise<TransactionInstruction>

    Transaction instruction for initializing the vault

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

    Parameters

    • params: { vault: PublicKey }

      Parameters for removing strategy

      • vault: PublicKey

        Public key of the vault

    Returns Promise<TransactionInstruction>

    Transaction instruction for removing strategy from vault

    If instruction creation fails

    const ix = await client.createRemoveStrategyIx({
    vault: vaultPubkey
    });
  • Creates a withdraw instruction

    Parameters

    • amount: BN

      Amount of LP tokens to withdraw

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

      Withdraw parameters

      • assetTokenProgram: PublicKey

        Public key of the asset token program

      • userAuthority: PublicKey

        Public key of the user authority

      • vault: PublicKey

        Public key of the vault

      • vaultAssetMint: PublicKey

        Public key of the vault asset mint

    Returns Promise<TransactionInstruction>

    Transaction instruction for withdrawal

    If the instruction creation fails

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

    Parameters

    • withdrawArgs: withdrawStrategyArgs

      Withdrawal arguments

      • OptionaladditionalArgs?: null | Buffer<ArrayBufferLike>
      • OptionalinstructionDiscriminator?: null | Buffer<ArrayBufferLike>
      • withdrawAmount: BN
    • params: {
          assetTokenProgram: PublicKey;
          remainingAccounts: {
              isSigner: boolean;
              isWritable: boolean;
              pubkey: PublicKey;
          }[];
          strategy: PublicKey;
          vault: PublicKey;
          vaultAssetMint: PublicKey;
      }

      Strategy withdrawal parameters

      • assetTokenProgram: PublicKey

        Public key of the asset token program

      • remainingAccounts: { isSigner: boolean; isWritable: boolean; pubkey: PublicKey }[]

        Remaining accounts for the instruction

      • strategy: PublicKey

        Public key of the strategy

      • vault: PublicKey

        Public key of the vault

      • vaultAssetMint: PublicKey

        Public key of the vault asset mint

    Returns Promise<TransactionInstruction>

    Transaction instruction for withdrawing assets from strategy

    If the instruction creation fails

    const ix = await client.createWithdrawStrategyIx(
    {
    withdrawAmount: new BN('1000000000'),
    instructionDiscriminator: Buffer.from('...'),
    additionalArgs: Buffer.from('...')
    },
    {
    vault: vaultPubkey,
    vaultAssetMint: mintPubkey,
    strategy: strategyPubkey,
    assetTokenProgram: tokenProgramPubkey,
    remainingAccounts: []
    }
    );
  • Fetches an adaptor add receipt account's data

    Parameters

    • adaptorAddReceipt: PublicKey

      Public key of the adaptor add receipt account

    Returns Promise<
        {
            adaptorProgram: PublicKey;
            bump: number;
            padding0: number[];
            reserved: number[];
            vault: PublicKey;
            version: number;
        },
    >

    Promise resolving to the adaptor add receipt account data

    const adaptorAddReceiptAccount = await client.fetchAdaptorAddReceiptAccount(adaptorAddReceiptPubkey);
    
  • Fetches all adaptor add receipt accounts of a vault

    Parameters

    • vault: PublicKey

      Public key of the vault

    Returns Promise<
        ProgramAccount<
            {
                adaptorProgram: PublicKey;
                bump: number;
                padding0: number[];
                reserved: number[];
                vault: PublicKey;
                version: number;
            },
        >[],
    >

    Promise resolving to an array of adaptor add receipt accounts

    const adaptorAddReceiptAccounts = await client.fetchAllAdaptorAddReceiptAccountsOfVault(vaultPubkey);
    
  • Fetches all strategy accounts

    Returns Promise<
        ProgramAccount<
            {
                bump: number;
                counterpartyAssetTa: PublicKey;
                description: number[];
                name: number[];
                padding0: number[];
                protocolProgram: PublicKey;
                reserved: number[];
                strategyType: DecodeEnum<
                    {
                        kind: "enum";
                        variants: [
                            { name: "solend" },
                            { name: "drift" },
                            { name: "marginfi" },
                            { name: "kamino" },
                        ];
                    },
                    DecodedHelper<
                        [
                            {
                                name: "strategy";
                                repr: { kind: "c" };
                                serialization: "bytemuckunsafe";
                                type: {
                                    fields: [
                                        { docs: ...; name: ...; type: ... },
                                        { docs: ...; name: ...; type: ... },
                                        { docs: ...; name: ...; type: ... },
                                        { docs: ...; name: ...; type: ... },
                                        { docs: ...; name: ...; type: ... },
                                    ];
                                    kind: "struct";
                                };
                            },
                            {
                                docs: ["1-byte enum"];
                                name: "strategyType";
                                repr: { kind: "rust" };
                                type: {
                                    kind: "enum";
                                    variants: [
                                        { name: ... },
                                        { name: ... },
                                        { name: ... },
                                        { name: ... },
                                    ];
                                };
                            },
                        ],
                        EmptyDefined,
                    >,
                >;
                version: number;
            },
        >[],
    >

    Promise resolving to an array of strategy accounts

    const strategyAccounts = await client.fetchAllStrategyAccounts();
    
  • Fetches all strategy init receipt accounts

    Returns Promise<
        ProgramAccount<
            {
                bump: number;
                lastUpdatedTs: BN;
                padding0: number[];
                positionValue: BN;
                reserved: number[];
                strategy: PublicKey;
                vault: PublicKey;
                vaultStrategyAuthBump: number;
                version: number;
            },
        >[],
    >

    Promise resolving to an array of strategy init receipt accounts

    const strategyInitReceiptAccounts = await client.fetchAllStrategyInitReceiptAccounts();
    
  • Fetches all strategy init receipt accounts of a vault

    Parameters

    • vault: PublicKey

      Public key of the vault

    Returns Promise<
        ProgramAccount<
            {
                bump: number;
                lastUpdatedTs: BN;
                padding0: number[];
                positionValue: BN;
                reserved: number[];
                strategy: PublicKey;
                vault: PublicKey;
                vaultStrategyAuthBump: number;
                version: number;
            },
        >[],
    >

    Promise resolving to an array of strategy init receipt accounts

    const strategyInitReceiptAccounts = await client.fetchAllStrategyInitReceiptAccountsOfVault(vaultPubkey);
    
  • Fetches a strategy account's data

    Parameters

    • strategy: PublicKey

      Public key of the strategy

    Returns Promise<
        {
            bump: number;
            counterpartyAssetTa: PublicKey;
            description: number[];
            name: number[];
            padding0: number[];
            protocolProgram: PublicKey;
            reserved: number[];
            strategyType: DecodeEnum<
                {
                    kind: "enum";
                    variants: [
                        { name: "solend" },
                        { name: "drift" },
                        { name: "marginfi" },
                        { name: "kamino" },
                    ];
                },
                DecodedHelper<
                    [
                        {
                            name: "strategy";
                            repr: { kind: "c" };
                            serialization: "bytemuckunsafe";
                            type: {
                                fields: [
                                    {
                                        docs: ["The name (fixed-length)."];
                                        name: "name";
                                        type: { array: [(...), (...)] };
                                    },
                                    {
                                        docs: ["The description (fixed-length)."];
                                        name: "description";
                                        type: { array: [(...), (...)] };
                                    },
                                    {
                                        docs: ["The counterparty asset token account."];
                                        name: "counterpartyAssetTa";
                                        type: "pubkey";
                                    },
                                    {
                                        docs: ["The protocol’s main program ID."];
                                        name: "protocolProgram";
                                        type: "pubkey";
                                    },
                                    {
                                        docs: [
                                            "A version number to help with migrations or struct upgrades (1 byte).",
                                        ];
                                        name: "version";
                                        type: "u8";
                                    },
                                ];
                                kind: "struct";
                            };
                        },
                        {
                            docs: ["1-byte enum"];
                            name: "strategyType";
                            repr: { kind: "rust" };
                            type: {
                                kind: "enum";
                                variants: [
                                    { name: "solend" },
                                    { name: "drift" },
                                    { name: "marginfi" },
                                    { name: "kamino" },
                                ];
                            };
                        },
                    ],
                    EmptyDefined,
                >,
            >;
            version: number;
        },
    >

    Promise resolving to the strategy account data

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

    Parameters

    • strategyInitReceipt: PublicKey

      Public key of the strategy init receipt account

    Returns Promise<
        {
            bump: number;
            lastUpdatedTs: BN;
            padding0: number[];
            positionValue: BN;
            reserved: number[];
            strategy: PublicKey;
            vault: PublicKey;
            vaultStrategyAuthBump: number;
            version: number;
        },
    >

    Promise resolving to the strategy init receipt account data

    const strategyInitReceiptAccount = await client.fetchStrategyInitReceiptAccount(strategyInitReceiptPubkey);
    
  • Fetches a vault account's data

    Parameters

    • vault: PublicKey

      Public key of the vault

    Returns Promise<
        {
            admin: PublicKey;
            asset: any;
            description: number[];
            feeConfiguration: any;
            lastUpdatedTs: BN;
            lp: any;
            manager: PublicKey;
            name: number[];
            padding0: number[];
            reserved: number[];
            vaultConfiguration: any;
            version: number;
        },
    >

    Promise resolving to the vault account data

  • 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 the strategy init receipt address

    Parameters

    • vault: PublicKey

      Public key of the vault

    • strategy: PublicKey

      Public key of the strategy

    Returns PublicKey

    The PDA for the strategy init receipt

    const strategyInitReceipt = client.findStrategyInitReceipt(vaultPubkey, strategyPubkey);
    
  • 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

    const addresses = client.findVaultAddresses(vaultPubkey);
    console.log(addresses.vaultLpMint.toBase58());
    console.log(addresses.vaultAssetIdleAuth.toBase58());
    console.log(addresses.vaultLpFeeAuth.toBase58());
  • 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 auth address

    Parameters

    • vault: PublicKey

      Public key of the vault

    • strategy: PublicKey

      Public key of the strategy

    Returns PublicKey

    The PDA for the vault strategy auth

    const vaultStrategyAuth = client.findVaultStrategyAuth(vaultPubkey, strategyPubkey);
    
  • Gets the balance of a Solana account

    Parameters

    • publicKey: PublicKey

      Public key to check balance for

    Returns Promise<number>

    Promise resolving to the account balance in lamports

    If fetching balance fails

  • Parameters

    • vault: PublicKey

    Returns Promise<{ strategies: { amount: any; strategyId: string }[]; totalValue: any }>