@kamino-finance/klend-sdk
Version:
Typescript SDK for interacting with the Kamino Lending (klend) protocol
284 lines • 17.7 kB
TypeScript
import { Connection, Keypair, PublicKey, TransactionInstruction } from '@solana/web3.js';
import { 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';
export declare const kaminoVaultId: PublicKey;
export declare const kaminoVaultStagingId: PublicKey;
/**
* 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, kaminoVaultprogramId?: PublicKey, kaminoLendProgramId?: PublicKey, recentSlotDurationMs?: number);
getConnection(): Connection;
getProgramID(): PublicKey;
/**
* 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 - keypair, should be used to sign the transaction which creates the vault account
* @returns ixns - an array of instructions to create the vault
*/
createVaultIxs(vaultConfig: KaminoVaultConfig): Promise<{
vault: Keypair;
ixns: 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
* @returns - a list of instructions
*/
updateReserveAllocationIxs(vault: KaminoVault, reserveAllocationConfig: ReserveAllocationConfig): Promise<TransactionInstruction>;
/**
* This method updates the vault config
* @param vault - 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 - a list of instructions
*/
updateVaultConfigIx(vault: KaminoVault, mode: VaultConfigFieldKind, value: string): Promise<TransactionInstruction>;
/**
* 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 be used to be executed
*/
acceptVaultOwnershipIx(vault: KaminoVault): Promise<TransactionInstruction>;
/**
* 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 be used to be executed
*/
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
* @returns - list of instructions to withdraw all pending fees
*/
withdrawPendingFeesIxs(vault: KaminoVault, slot: number): 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
* @param tokenAmount - token amount to be deposited, in decimals (will be converted in lamports)
* @param tokenProgramIDOverride - optional param; should be passed if token to be deposited is token22
* @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 instructions to be used to be executed
*/
depositIxs(user: PublicKey, vault: KaminoVault, tokenAmount: Decimal, tokenProgramIDOverride?: PublicKey, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>): Promise<TransactionInstruction[]>;
/**
* This function will return 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 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
* @returns an array of instructions to be executed
*/
withdrawIxs(user: PublicKey, vault: KaminoVault, shareAmount: Decimal, slot: number): Promise<TransactionInstruction[]>;
/**
* 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
* @returns - an array of invest instructions for each invest action required for the vault reserves
*/
investSingleReserveIxs(payer: PublicKey, vault: KaminoVault, reserve: ReserveWithAddress): Promise<TransactionInstruction[]>;
private withdrawIxn;
private withdrawPendingFeesIxn;
/**
* 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 decimal (not lamports)
*/
getUserSharesBalanceSingleVault(user: PublicKey, vault: KaminoVault): Promise<Decimal>;
/**
* 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
* @returns - hash map with keyh as vault address and value as user share balance in decimal (not lamports)
*/
getUserSharesBalanceAllVaults(user: PublicKey, vaultsOverride?: Array<KaminoVault>): Promise<PubkeyHashMap<PublicKey, Decimal>>;
/**
* This method calculates the token per shar 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 - 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
* @returns - token per share value
*/
getTokensPerShareSingleVault(vault: KaminoVault, slot: number, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>): 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
* @param vaultReservesMap - optional parameter; a hashmap from pubkey to reserve state. 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
* @param useOptimisedRPCCall - if set to true, it will use the optimized getProgramAccounts RPC call, which is more efficient but doesn't work in web environments
* @returns - token per share value
*/
getTokensPerShareAllVaults(slot: number, vaultsOverride?: Array<KaminoVault>, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>, useOptimisedRPCCall?: boolean): Promise<PubkeyHashMap<PublicKey, Decimal>>;
/**
* Get all vaults
* @param useOptimisedRPCCall - if set to true, it will use the optimized getProgramAccounts RPC call, which is more efficient but doesn't work in web environments
* @returns an array of all vaults
*/
getAllVaults(useOptimisedRPCCall?: boolean): Promise<KaminoVault[]>;
/**
* 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
* @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
* @param vault - the vault state to load reserves for
* @returns a hashmap from each reserve pubkey to the reserve state
*/
getAllVaultReserves(vault: VaultState): PublicKey[];
/**
* 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 retrieve all the tokens that can be use 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
*
* @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): 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 - current slot
* @param vaultReserves - 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 VaultHoldings object
*/
getVaultHoldings(vault: VaultState, slot: number, vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>): Promise<VaultHoldings>;
/**
* This will return an VaultHoldingsWithUSDValue object which contains an holdings field representing the amount available (uninvested) in vault, total amount invested in reseves and a breakdown of the amount invested in each reserve and additional fields for the total USD value of the available and invested amounts
* @param vault - the kamino vault to get available liquidity to withdraw for
* @param slot - current slot
* @param vaultReserves - 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 price - the price of the token in the vault (e.g. USDC)
* @returns an VaultHoldingsWithUSDValue object with details about the tokens available and invested in the vault, denominated in tokens and USD
*/
getVaultHoldingsWithPrice(vault: VaultState, slot: number, price: Decimal, vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>): Promise<VaultHoldingsWithUSDValue>;
/**
* 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 vaultReserves - 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 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
* @param vault - the kamino vault to get APY for
* @param slot - current slot
* @param vaultReserves - 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 APY for the vault
*/
getVaultTheoreticalAPY(vault: VaultState, slot: number, vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>): Promise<Decimal>;
/**
* Retrive the total amount of tokenes earned by the vault since its inception after deducting the management and performance fees
* @param vaultState the kamino vault state to get total net yield for
* @returns a decimal representing the net number of tokens earned by the vault since its inception after deducting the management and performance fees
*/
getVaultTotalNetYield(vaultState: VaultState): Promise<Decimal>;
}
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>;
}
/**
* 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, expressed as a decimal */
readonly performanceFeeRate: Decimal;
/** The management fee rate of the vault, expressed as a decimal */
readonly managementFeeRate: Decimal;
constructor(args: {
admin: PublicKey;
tokenMint: PublicKey;
tokenMintProgramId: PublicKey;
performanceFeeRate: Decimal;
managementFeeRate: Decimal;
});
getPerformanceFeeBps(): number;
getManagementFeeRate(): 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 type VaultHolder = {
holderPubkey: PublicKey;
amount: Decimal;
};
export type VaultHoldings = {
available: Decimal;
invested: Decimal;
investedInReserves: PubkeyHashMap<PublicKey, Decimal>;
total: Decimal;
};
export type VaultHoldingsWithUSDValue = {
holdings: VaultHoldings;
availableUSD: Decimal;
investedUSD: Decimal;
investedInReservesUSD: PubkeyHashMap<PublicKey, Decimal>;
};
export type ReserveOverview = {
supplyAPY: Decimal;
uUtilizationRatio: Decimal;
liquidationThresholdPct: Decimal;
borrowedAmount: Decimal;
};
export type MarketOverview = {
address: PublicKey;
reservesAsCollateral: ReserveAsCollateral[];
minLTVPct: Decimal;
maxLTVPct: Decimal;
};
export type ReserveAsCollateral = {
mint: PublicKey;
liquidationLTVPct: Decimal;
};
//# sourceMappingURL=vault.d.ts.map