@kamino-finance/klend-sdk
Version:
Typescript SDK for interacting with the Kamino Lending (klend) protocol
534 lines • 38.8 kB
TypeScript
import { Connection, Keypair, PublicKey, TransactionInstruction } from '@solana/web3.js';
import { KaminoMarket, KaminoReserve, PubkeyHashMap, Reserve } from '../lib';
import { VaultConfigFieldKind } from '../idl_codegen_kamino_vault/types';
import { VaultState } from '../idl_codegen_kamino_vault/accounts';
import Decimal from 'decimal.js';
import { ReserveWithAddress } from './reserve';
import { AcceptVaultOwnershipIxs, APYs, DepositIxs, InitVaultIxs, ReserveAllocationOverview, SyncVaultLUTIxs, UpdateReserveAllocationIxs, UpdateVaultConfigIxs, UserSharesForVault, WithdrawAndBlockReserveIxs, WithdrawIxs } from './vault_types';
import { FarmState } from '@kamino-finance/farms-sdk/dist';
export declare const kaminoVaultId: PublicKey;
export declare const kaminoVaultStagingId: PublicKey;
export declare const METADATA_SEED = "metadata";
export declare const METADATA_PROGRAM_ID: PublicKey;
export declare const INITIAL_DEPOSIT_LAMPORTS = 1000;
/**
* KaminoVaultClient is a class that provides a high-level interface to interact with the Kamino Vault program.
*/
export declare class KaminoVaultClient {
private readonly _connection;
private readonly _kaminoVaultProgramId;
private readonly _kaminoLendProgramId;
recentSlotDurationMs: number;
constructor(connection: Connection, recentSlotDurationMs: number, kaminoVaultprogramId?: PublicKey, kaminoLendProgramId?: PublicKey);
getConnection(): Connection;
getProgramID(): PublicKey;
hasFarm(): void;
/**
* Prints a vault in a human readable form
* @param vaultPubkey - the address of the vault
* @param [vaultState] - optional parameter to pass the vault state directly; this will save a network call
* @returns - void; prints the vault to the console
*/
printVault(vaultPubkey: PublicKey, vaultState?: VaultState): Promise<void>;
/**
* This method will create a vault with a given config. The config can be changed later on, but it is recommended to set it up correctly from the start
* @param vaultConfig - the config object used to create a vault
* @returns vault: the keypair of the vault, used to sign the initialization transaction; initVaultIxs: a struct with ixs to initialize the vault and its lookup table + populateLUTIxs, a list to populate the lookup table which has to be executed in a separate transaction
*/
createVaultIxs(vaultConfig: KaminoVaultConfig): Promise<{
vault: Keypair;
initVaultIxs: InitVaultIxs;
}>;
/**
* This method creates an instruction to set the shares metadata for a vault
* @param vault - the vault to set the shares metadata for
* @param tokenName - the name of the token in the vault (symbol; e.g. "USDC" which becomes "kVUSDC")
* @param extraName - the extra string appended to the prefix("Kamino Vault USDC <extraName>")
* @returns - an instruction to set the shares metadata for the vault
*/
getSetSharesMetadataIx(connection: Connection, vaultAdmin: PublicKey, vault: PublicKey, sharesMint: PublicKey, baseVaultAuthority: PublicKey, tokenName: string, extraName: string): Promise<TransactionInstruction>;
/**
* This method updates the vault reserve allocation cofnig for an exiting vault reserve, or adds a new reserve to the vault if it does not exist.
* @param vault - vault to be updated
* @param reserveAllocationConfig - new reserve allocation config
* @param [signer] - optional parameter to pass a different signer for the instruction. If not provided, the admin of the vault will be used
* @returns - a struct with an instruction to update the reserve allocation and an optional list of instructions to update the lookup table for the allocation changes
*/
updateReserveAllocationIxs(vault: KaminoVault, reserveAllocationConfig: ReserveAllocationConfig, signer?: PublicKey): Promise<UpdateReserveAllocationIxs>;
/**
* This method withdraws all the funds from a reserve and blocks it from being invested by setting its weight and ctoken allocation to 0
* @param vault - the vault to withdraw the funds from
* @param reserve - the reserve to withdraw the funds from
* @param payer - the payer of the transaction. If not provided, the admin of the vault will be used
* @returns - a struct with an instruction to update the reserve allocation and an optional list of instructions to update the lookup table for the allocation changes
*/
withdrawEverythingAndBlockInvestReserve(vault: KaminoVault, reserve: PublicKey, payer?: PublicKey): Promise<WithdrawAndBlockReserveIxs>;
/**
* This method withdraws all the funds from all the reserves and blocks them from being invested by setting their weight and ctoken allocation to 0
* @param vault - the vault to withdraw the invested funds from
* @param [vaultReservesMap] - optional parameter to pass a map of the vault reserves. If not provided, the reserves will be loaded from the vault
* @param [payer] - optional parameter to pass a different payer for the transaction. If not provided, the admin of the vault will be used; this is the payer for the invest ixs and it should have an ATA and some lamports (2x no_of_reserves) of the token vault
* @returns - a struct with an instruction to update the reserve allocation and an optional list of instructions to update the lookup table for the allocation changes
*/
withdrawEverythingFromAllReservesAndBlockInvest(vault: KaminoVault, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>, payer?: PublicKey): Promise<WithdrawAndBlockReserveIxs>;
/**
* This method removes a reserve from the vault allocation strategy if already part of the allocation strategy
* @param vault - vault to remove the reserve from
* @param reserve - reserve to remove from the vault allocation strategy
* @returns - an instruction to remove the reserve from the vault allocation strategy or undefined if the reserve is not part of the allocation strategy
*/
removeReserveFromAllocationIx(vault: KaminoVault, reserve: PublicKey): Promise<TransactionInstruction | undefined>;
/**
* Update a field of the vault. If the field is a pubkey it will return an extra instruction to add that account into the lookup table
* @param vault the vault to update
* @param mode the field to update (based on VaultConfigFieldKind enum)
* @param value the value to update the field with
* @param [signer] the signer of the transaction. Optional. If not provided the admin of the vault will be used. It should be used when changing the admin of the vault if we want to build or batch multiple ixs in the same tx
* @returns a struct that contains the instruction to update the field and an optional list of instructions to update the lookup table
*/
updateVaultConfigIxs(vault: KaminoVault, mode: VaultConfigFieldKind, value: string, signer?: PublicKey): Promise<UpdateVaultConfigIxs>;
/** Sets the farm where the shares can be staked. This is store in vault state and a vault can only have one farm, so the new farm will ovveride the old farm
* @param vault - vault to set the farm for
* @param farm - the farm where the vault shares can be staked
* @param [errorOnOverride] - if true, the function will throw an error if the vault already has a farm. If false, it will override the farm
*/
setVaultFarmIxs(vault: KaminoVault, farm: PublicKey, errorOnOverride?: boolean): Promise<UpdateVaultConfigIxs>;
/**
* This method updates the vault config for a vault that
* @param vault - address of vault to be updated
* @param mode - the field to be updated
* @param value - the new value for the field to be updated (number or pubkey)
* @returns - an instruction to update the vault config
*/
private updateUninitialisedVaultConfigIx;
/**
* This function creates the instruction for the `pendingAdmin` of the vault to accept to become the owner of the vault (step 2/2 of the ownership transfer)
* @param vault - vault to change the ownership for
* @returns - an instruction to accept the ownership of the vault and a list of instructions to update the lookup table
*/
acceptVaultOwnershipIxs(vault: KaminoVault): Promise<AcceptVaultOwnershipIxs>;
/**
* This function creates the instruction for the admin to give up a part of the pending fees (which will be accounted as part of the vault)
* @param vault - vault to give up pending fees for
* @param maxAmountToGiveUp - the maximum amount of fees to give up, in tokens
* @returns - an instruction to give up the specified pending fees
*/
giveUpPendingFeesIx(vault: KaminoVault, maxAmountToGiveUp: Decimal): Promise<TransactionInstruction>;
/**
* This method withdraws all the pending fees from the vault to the owner's token ATA
* @param vault - vault for which the admin withdraws the pending fees
* @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
* @param [vaultReservesMap] - a hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
* @returns - list of instructions to withdraw all pending fees, including the ATA creation instructions if needed
*/
withdrawPendingFeesIxs(vault: KaminoVault, slot: number, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>): Promise<TransactionInstruction[]>;
/**
* This function creates instructions to deposit into a vault. It will also create ATA creation instructions for the vault shares that the user receives in return
* @param user - user to deposit
* @param vault - vault to deposit into (if the state is not provided, it will be fetched)
* @param tokenAmount - token amount to be deposited, in decimals (will be converted in lamports)
* @param [vaultReservesMap] - optional parameter; a hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
* @param [farmState] - the state of the vault farm, if the vault has a farm. Optional. If not provided, it will be fetched
* @returns - an instance of DepositIxs which contains the instructions to deposit in vault and the instructions to stake the shares in the farm if the vault has a farm
*/
depositIxs(user: PublicKey, vault: KaminoVault, tokenAmount: Decimal, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>, farmState?: FarmState): Promise<DepositIxs>;
/**
* This function creates instructions to stake the shares in the vault farm if the vault has a farm
* @param user - user to stake
* @param vault - vault to deposit into its farm (if the state is not provided, it will be fetched)
* @param [sharesAmount] - token amount to be deposited, in decimals (will be converted in lamports). Optional. If not provided, the user's share balance will be used
* @param [farmState] - the state of the vault farm, if the vault has a farm. Optional. If not provided, it will be fetched
* @returns - a list of instructions for the user to stake shares into the vault's farm, including the creation of prerequisite accounts if needed
*/
stakeSharesIxs(user: PublicKey, vault: KaminoVault, sharesAmount?: Decimal, farmState?: FarmState): Promise<TransactionInstruction[]>;
/**
* This function will return a struct with the instructions to unstake from the farm if necessary and the instructions for the missing ATA creation instructions, as well as one or multiple withdraw instructions, based on how many reserves it's needed to withdraw from. This might have to be split in multiple transactions
* @param user - user to withdraw
* @param vault - vault to withdraw from
* @param shareAmount - share amount to withdraw (in tokens, not lamports), in order to withdraw everything, any value > user share amount
* @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
* @param [vaultReservesMap] - optional parameter; a hashmap from each reserve pubkey to the reserve state. If provided the function will be significantly faster as it will not have to fetch the reserves
* @param [farmState] - the state of the vault farm, if the vault has a farm. Optional. If not provided, it will be fetched
* @returns an array of instructions to create missing ATAs if needed and the withdraw instructions
*/
withdrawIxs(user: PublicKey, vault: KaminoVault, shareAmount: Decimal, slot: number, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>, farmState?: FarmState): Promise<WithdrawIxs>;
private withdrawFromAvailableIxs;
private withdrawWithReserveIxs;
/**
* This will trigger invest by balancing, based on weights, the reserve allocations of the vault. It can either withdraw or deposit into reserves to balance them. This is a function that should be cranked
* @param payer wallet that pays the tx
* @param vault - vault to invest from
* @returns - an array of invest instructions for each invest action required for the vault reserves
*/
investAllReservesIxs(payer: PublicKey, vault: KaminoVault): Promise<TransactionInstruction[]>;
/**
* This will trigger invest by balancing, based on weights, the reserve allocation of the vault. It can either withdraw or deposit into the given reserve to balance it
* @param payer wallet pubkey
* @param vault - vault to invest from
* @param reserve - reserve to invest into or disinvest from
* @param [vaultReservesMap] - optional parameter; a hashmap from each reserve pubkey to the reserve state. If provided the function will be significantly faster as it will not have to fetch the reserves
* @returns - an array of invest instructions for each invest action required for the vault reserves
*/
investSingleReserveIxs(payer: PublicKey, vault: KaminoVault, reserve: ReserveWithAddress, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>, createAtaIfNeeded?: boolean): Promise<TransactionInstruction[]>;
/** Convert a string to a u8 representation to be stored on chain */
encodeVaultName(token: string): Uint8Array;
/**Convert an u8 array to a string */
decodeVaultName(token: number[]): string;
private withdrawIx;
private withdrawFromAvailableIx;
private withdrawPendingFeesIx;
/**
* Sync a vault for lookup table; create and set the LUT for the vault if needed and fill it with all the needed accounts
* @param vault the vault to sync and set the LUT for if needed
* @param vaultReserves optional; the state of the reserves in the vault allocation
* @param [vaultReservesMap] - optional parameter; a hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
* @returns a struct that contains a list of ix to create the LUT and assign it to the vault if needed + a list of ixs to insert all the accounts in the LUT
*/
syncVaultLookupTableIxs(vault: KaminoVault, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>): Promise<SyncVaultLUTIxs>;
private getReserveAccountsToInsertInLut;
/**
* This method inserts the missing keys from the provided keys into an existent lookup table
* @param payer - payer wallet pubkey
* @param lookupTable - lookup table to insert the keys into
* @param keys - keys to insert into the lookup table
* @param [accountsInLUT] - the existent accounts in the lookup table. Optional. If provided, the function will not fetch the accounts in the lookup table
* @returns - an array of instructions to insert the missing keys into the lookup table
*/
insertIntoLookupTableIxs(payer: PublicKey, lookupTable: PublicKey, keys: PublicKey[], accountsInLUT?: PublicKey[]): Promise<TransactionInstruction[]>;
/** Read the total holdings of a vault and the reserve weights and returns a map from each reserve to how many tokens should be deposited.
* @param vaultState - the vault state to calculate the allocation for
* @param [slot] - the slot for which to calculate the allocation. Optional. If not provided the function will fetch the current slot
* @param [vaultReserves] - a hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
* @param [currentSlot] - the latest confirmed slot. Optional. If provided the function will be faster as it will not have to fetch the latest slot
* @returns - a map from each reserve to how many tokens should be invested into
*/
getVaultComputedReservesAllocation(vaultState: VaultState, slot?: number, vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>, currentSlot?: number): Promise<PubkeyHashMap<PublicKey, Decimal>>;
/**
* This method returns the user shares balance for a given vault
* @param user - user to calculate the shares balance for
* @param vault - vault to calculate shares balance for
* @returns - user share balance in tokens (not lamports)
*/
getUserSharesBalanceSingleVault(user: PublicKey, vault: KaminoVault): Promise<UserSharesForVault>;
/**
* This method returns the user shares balance for all existing vaults
* @param user - user to calculate the shares balance for
* @param [vaultsOverride] - the kamino vaults if already fetched, in order to reduce rpc calls.Optional
* @returns - hash map with keys as vault address and value as user share balance in decimal (not lamports)
*/
getUserSharesBalanceAllVaults(user: PublicKey, vaultsOverride?: Array<KaminoVault>): Promise<PubkeyHashMap<PublicKey, UserSharesForVault>>;
/**
* This method returns the management and performance fee percentages
* @param vaultState - vault to retrieve the fees percentages from
* @returns - VaultFeesPct containing management and performance fee percentages
*/
getVaultFeesPct(vaultState: VaultState): VaultFeesPct;
/**
* This method calculates the token per share value. This will always change based on interest earned from the vault, but calculating it requires a bunch of rpc requests. Caching this for a short duration would be optimal
* @param vault - vault to calculate tokensPerShare for
* @param [slot] - the slot at which we retrieve the tokens per share. Optional. If not provided, the function will fetch the current slot
* @param [vaultReservesMap] - hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
* @param [currentSlot] - the latest confirmed slot. Optional. If provided the function will be faster as it will not have to fetch the latest slot
* @returns - token per share value
*/
getTokensPerShareSingleVault(vault: KaminoVault, slot?: number, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>, currentSlot?: number): Promise<Decimal>;
/**
* This method calculates the token per share value. This will always change based on interest earned from the vault, but calculating it requires a bunch of rpc requests. Caching this for a short duration would be optimal
* @param [vaultsOverride] - a list of vaults to get the tokens per share for; if provided with state it will not fetch the state again. Optional
* @param [vaultReservesMap] - optional parameter; a hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
* @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
* @returns - token per share value
*/
getTokensPerShareAllVaults(slot: number, vaultsOverride?: Array<KaminoVault>, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>): Promise<PubkeyHashMap<PublicKey, Decimal>>;
/**
* Get all vaults
* @returns an array of all vaults
*/
getAllVaults(): Promise<KaminoVault[]>;
/**
* Get all vaults for a given token
* @param token - the token to get all vaults for
* @returns an array of all vaults for the given token
*/
getAllVaultsForToken(token: PublicKey): Promise<Array<KaminoVault>>;
private getAllVaultsWithFilter;
/**
* Get a list of kaminoVaults
* @param vaults - a list of vaults to get the states for; if not provided, all vaults will be fetched
* @returns a list of vaults
*/
getVaults(vaults?: Array<PublicKey>): Promise<Array<KaminoVault | null>>;
private getVaultsStates;
/**
* This will return the amount of token invested from the vault into the given reserve
* @param vault - the kamino vault to get invested amount in reserve for
* @param slot - current slot
* @param reserve - the reserve state to get vault invested amount in
* @returns vault amount supplied in reserve in decimal
*/
getSuppliedInReserve(vaultState: VaultState, slot: number, reserve: KaminoReserve): Decimal;
/**
* This will return the a map between reserve pubkey and the pct of the vault invested amount in each reserve
* @param vaultState - the kamino vault to get reserves distribution for
* @returns a map between reserve pubkey and the allocation pct for the reserve
*/
getAllocationsDistribuionPct(vaultState: VaultState): PubkeyHashMap<PublicKey, Decimal>;
/**
* This will return the a map between reserve pubkey and the allocation overview for the reserve
* @param vaultState - the kamino vault to get reserves allocation overview for
* @returns a map between reserve pubkey and the allocation overview for the reserve
*/
getVaultAllocations(vaultState: VaultState): PubkeyHashMap<PublicKey, ReserveAllocationOverview>;
/**
* This will return an unsorted hash map of all reserves that the given vault has allocations for, toghether with the amount that can be withdrawn from each of the reserves
* @param vault - the kamino vault to get available liquidity to withdraw for
* @param slot - current slot
*@param [vaultReservesMap] - a hashmap from each reserve pubkey to the reserve state
* @returns an HashMap of reserves (key) with the amount available to withdraw for each (value)
*/
private getReserveAllocationAvailableLiquidityToWithdraw;
/**
* This will get the list of all reserve pubkeys that the vault has allocations for ex
* @param vault - the vault state to load reserves for
* @returns a hashmap from each reserve pubkey to the reserve state
*/
getVaultReserves(vault: VaultState): PublicKey[];
/**
* This will load the onchain state for all the reserves that the vault has allocations for
* @param vaultState - the vault state to load reserves for
* @returns a hashmap from each reserve pubkey to the reserve state
*/
loadVaultReserves(vaultState: VaultState): Promise<PubkeyHashMap<PublicKey, KaminoReserve>>;
/**
* This will load the onchain state for all the reserves that the vaults have allocations for, deduplicating the reserves
* @param vaults - the vault states to load reserves for
* @returns a hashmap from each reserve pubkey to the reserve state
*/
loadVaultsReserves(vaults: VaultState[]): Promise<PubkeyHashMap<PublicKey, KaminoReserve>>;
/**
* This will retrieve all the tokens that can be used as collateral by the users who borrow the token in the vault alongside details about the min and max loan to value ratio
* @param vaultState - the vault state to load reserves for
* @param [slot] - the slot for which to retrieve the vault collaterals for. Optional. If not provided the function will fetch the current slot
* @param [vaultReservesMap] - hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
* @param [kaminoMarkets] - a list of all the kamino markets. Optional. If provided the function will be significantly faster as it will not have to fetch the markets
* @returns a hashmap from each reserve pubkey to the market overview of the collaterals that can be used and the min and max loan to value ratio in that market
*/
getVaultCollaterals(vaultState: VaultState, slot: number, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>, kaminoMarkets?: KaminoMarket[]): Promise<PubkeyHashMap<PublicKey, MarketOverview>>;
/**
* This will return an VaultHoldings object which contains the amount available (uninvested) in vault, total amount invested in reseves and a breakdown of the amount invested in each reserve
* @param vault - the kamino vault to get available liquidity to withdraw for
* @param [slot] - the slot for which to calculate the holdings. Optional. If not provided the function will fetch the current slot
* @param [vaultReserves] - a hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
* @param [currentSlot] - the latest confirmed slot. Optional. If provided the function will be faster as it will not have to fetch the latest slot
* @returns an VaultHoldings object representing the amount available (uninvested) in vault, total amount invested in reseves and a breakdown of the amount invested in each reserve
*/
getVaultHoldings(vault: VaultState, slot?: number, vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>, currentSlot?: number): Promise<VaultHoldings>;
/**
* This will return an VaultOverview object that encapsulates all the information about the vault, including the holdings, reserves details, theoretical APY, utilization ratio and total borrowed amount
* @param vault - the kamino vault to get available liquidity to withdraw for
* @param price - the price of the token in the vault (e.g. USDC)
* @param [slot] - the slot for which to retrieve the vault overview for. Optional. If not provided the function will fetch the current slot
* @param [vaultReservesMap] - hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
* @param [currentSlot] - the latest confirmed slot. Optional. If provided the function will be faster as it will not have to fetch the latest slot
* @returns an VaultOverview object with details about the tokens available and invested in the vault, denominated in tokens and USD
*/
getVaultHoldingsWithPrice(vault: VaultState, price: Decimal, slot?: number, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>, currentSlot?: number): Promise<VaultHoldingsWithUSDValue>;
/**
* This will return an VaultOverview object that encapsulates all the information about the vault, including the holdings, reserves details, theoretical APY, utilization ratio and total borrowed amount
* @param vault - the kamino vault to get available liquidity to withdraw for
* @param price - the price of the token in the vault (e.g. USDC)
* @param [slot] - the slot for which to retrieve the vault overview for. Optional. If not provided the function will fetch the current slot
* @param [vaultReservesMap] - hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
* @param [kaminoMarkets] - a list of all kamino markets. Optional. If provided the function will be significantly faster as it will not have to fetch the markets
* @param [currentSlot] - the latest confirmed slot. Optional. If provided the function will be faster as it will not have to fetch the latest slot
* @returns an VaultOverview object with details about the tokens available and invested in the vault, denominated in tokens and USD
*/
getVaultOverview(vault: VaultState, price: Decimal, slot?: number, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>, kaminoMarkets?: KaminoMarket[], currentSlot?: number): Promise<VaultOverview>;
/**
* This will return an aggregation of the current state of the vault with all the invested amounts and the utilization ratio of the vault
* @param vault - the kamino vault to get available liquidity to withdraw for
* @param slot - current slot
* @param [vaultReservesMap] - hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
* @returns an VaultReserveTotalBorrowedAndInvested object with the total invested amount, total borrowed amount and the utilization ratio of the vault
*/
getTotalBorrowedAndInvested(vault: VaultState, slot: number, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>): Promise<VaultReserveTotalBorrowedAndInvested>;
/**
* This will return an overview of each reserve that is part of the vault allocation
* @param vault - the kamino vault to get available liquidity to withdraw for
* @param slot - current slot
* @param [vaultReservesMap] - hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
* @returns a hashmap from vault reserve pubkey to ReserveOverview object
*/
getVaultReservesDetails(vault: VaultState, slot: number, vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>): Promise<PubkeyHashMap<PublicKey, ReserveOverview>>;
/**
* This will return the APY of the vault under the assumption that all the available tokens in the vault are all the time invested in the reserves as ratio; for percentage it needs multiplication by 100
* @param vault - the kamino vault to get APY for
* @param slot - current slot
* @param [vaultReservesMap] - hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
* @returns a struct containing estimated gross APY and net APY (gross - vault fees) for the vault
*/
getVaultTheoreticalAPY(vault: VaultState, slot: number, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>): Promise<APYs>;
/**
* This will return the APY of the vault based on the current invested amounts; for percentage it needs multiplication by 100
* @param vault - the kamino vault to get APY for
* @param slot - current slot
* @param [vaultReservesMap] - hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
* @returns a struct containing estimated gross APY and net APY (gross - vault fees) for the vault
*/
getVaultActualAPY(vault: VaultState, slot: number, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>): Promise<APYs>;
/**
* Retrive the total amount of interest earned by the vault since its inception, up to the last interaction with the vault on chain, including what was charged as fees
* @param vaultState the kamino vault state to get total net yield for
* @returns a struct containing a Decimal representing the net number of tokens earned by the vault since its inception and the timestamp of the last fee charge
*/
getVaultCumulativeInterest(vaultState: VaultState): Promise<VaultCumulativeInterestWithTimestamp>;
/**
* Simulate the current holdings of the vault and the earned interest
* @param vaultState the kamino vault state to get simulated holdings and earnings for
* @param [vaultReservesMap] - hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
* @param [currentSlot] - the current slot. Optional. If not provided it will fetch the current slot
* @param [previousNetAUM] - the previous AUM of the vault to compute the earned interest relative to this value. Optional. If not provided the function will estimate the total AUM at the slot of the last state update on chain
* @param [currentSlot] - the latest confirmed slot. Optional. If provided the function will be faster as it will not have to fetch the latest slot
* @returns a struct of simulated vault holdings and earned interest
*/
calculateSimulatedHoldingsWithInterest(vaultState: VaultState, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>, slot?: number, previousNetAUM?: Decimal, currentSlot?: number): Promise<SimulatedVaultHoldingsWithEarnedInterest>;
/**
* Simulate the current holdings and compute the fees that would be charged
* @param vaultState the kamino vault state to get simulated fees for
* @param [simulatedCurrentHoldingsWithInterest] the simulated holdings and interest earned by the vault. Optional
* @param [currentTimestamp] the current date. Optional. If not provided it will fetch the current unix timestamp
* @returns a VaultFees struct of simulated management and interest fees
*/
calculateSimulatedFees(vaultState: VaultState, simulatedCurrentHoldingsWithInterest?: SimulatedVaultHoldingsWithEarnedInterest, currentTimestamp?: Date): Promise<VaultFees>;
computeUserFarmStateDelegateePDAForUserInVault(farmProgramID: PublicKey, vault: PublicKey, reserve: PublicKey, user: PublicKey): [PublicKey, number];
}
export declare class KaminoVault {
readonly address: PublicKey;
state: VaultState | undefined | null;
programId: PublicKey;
constructor(vaultAddress: PublicKey, state?: VaultState, programId?: PublicKey);
getState(connection: Connection): Promise<VaultState>;
reloadState(connection: Connection): Promise<VaultState>;
hasFarm(connection: Connection): Promise<boolean>;
}
/**
* Used to initialize a Kamino Vault
*/
export declare class KaminoVaultConfig {
/** The admin of the vault */
readonly admin: PublicKey;
/** The token mint for the vault */
readonly tokenMint: PublicKey;
/** The token mint program id */
readonly tokenMintProgramId: PublicKey;
/** The performance fee rate of the vault, as percents, expressed as a decimal */
readonly performanceFeeRatePercentage: Decimal;
/** The management fee rate of the vault, as percents, expressed as a decimal */
readonly managementFeeRatePercentage: Decimal;
/** The name to be stored on chain for the vault (max 40 characters). */
readonly name: string;
/** The symbol of the vault token to be stored (max 5 characters). E.g. USDC for a vault using USDC as token. */
readonly vaultTokenSymbol: string;
/** The name of the vault token to be stored (max 10 characters), after the prefix `Kamino Vault <vaultTokenSymbol>`. E.g. USDC Vault for a vault using USDC as token. */
readonly vaultTokenName: string;
constructor(args: {
admin: PublicKey;
tokenMint: PublicKey;
tokenMintProgramId: PublicKey;
performanceFeeRatePercentage: Decimal;
managementFeeRatePercentage: Decimal;
name: string;
vaultTokenSymbol: string;
vaultTokenName: string;
});
getPerformanceFeeBps(): number;
getManagementFeeBps(): number;
}
export declare class ReserveAllocationConfig {
readonly reserve: ReserveWithAddress;
readonly targetAllocationWeight: number;
readonly allocationCapDecimal: Decimal;
constructor(reserve: ReserveWithAddress, targetAllocationWeight: number, allocationCapDecimal: Decimal);
getAllocationCapLamports(): Decimal;
getReserveState(): Reserve;
getReserveAddress(): PublicKey;
}
export declare function getCTokenVaultPda(vaultAddress: PublicKey, reserveAddress: PublicKey, kaminoVaultProgramId: PublicKey): PublicKey;
export declare function getEventAuthorityPda(kaminoVaultProgramId: PublicKey): PublicKey;
export type VaultHolder = {
holderPubkey: PublicKey;
amount: Decimal;
};
export type VaultHoldings = {
available: Decimal;
invested: Decimal;
investedInReserves: PubkeyHashMap<PublicKey, Decimal>;
pendingFees: Decimal;
totalAUMIncludingFees: Decimal;
};
/**
* earnedInterest represents the interest earned from now until the slot provided in the future
*/
export type SimulatedVaultHoldingsWithEarnedInterest = {
holdings: VaultHoldings;
earnedInterest: Decimal;
};
export type VaultHoldingsWithUSDValue = {
holdings: VaultHoldings;
availableUSD: Decimal;
investedUSD: Decimal;
investedInReservesUSD: PubkeyHashMap<PublicKey, Decimal>;
totalUSDIncludingFees: Decimal;
pendingFeesUSD: Decimal;
};
export type ReserveOverview = {
supplyAPY: Decimal;
utilizationRatio: Decimal;
liquidationThresholdPct: Decimal;
totalBorrowedAmount: Decimal;
amountBorrowedFromSupplied: Decimal;
suppliedAmount: Decimal;
market: PublicKey;
};
export type VaultReserveTotalBorrowedAndInvested = {
totalInvested: Decimal;
totalBorrowed: Decimal;
utilizationRatio: Decimal;
};
export type MarketOverview = {
address: PublicKey;
reservesAsCollateral: ReserveAsCollateral[];
minLTVPct: Decimal;
maxLTVPct: Decimal;
};
export type ReserveAsCollateral = {
mint: PublicKey;
liquidationLTVPct: Decimal;
address: PublicKey;
};
export type VaultOverview = {
holdingsUSD: VaultHoldingsWithUSDValue;
reservesOverview: PubkeyHashMap<PublicKey, ReserveOverview>;
vaultCollaterals: PubkeyHashMap<PublicKey, MarketOverview>;
theoreticalSupplyAPY: APYs;
actualSupplyAPY: APYs;
totalBorrowed: Decimal;
totalBorrowedUSD: Decimal;
totalSupplied: Decimal;
totalSuppliedUSD: Decimal;
utilizationRatio: Decimal;
};
export type VaultFeesPct = {
managementFeePct: Decimal;
performanceFeePct: Decimal;
};
export type VaultFees = {
managementFee: Decimal;
performanceFee: Decimal;
};
export type VaultCumulativeInterestWithTimestamp = {
cumulativeInterest: Decimal;
timestamp: number;
};
export declare function printHoldings(holdings: VaultHoldings): void;
//# sourceMappingURL=vault.d.ts.map