@kamino-finance/klend-sdk
Version:
Typescript SDK for interacting with the Kamino Lending (klend) protocol
294 lines • 20.7 kB
TypeScript
import { AccountInfo, Connection, Keypair, ParsedAccountData, PublicKey, TransactionInstruction } from '@solana/web3.js';
import { KaminoVault, KaminoVaultClient, KaminoVaultConfig, MarketOverview, ReserveAllocationConfig, ReserveOverview, VaultHolder, VaultHoldings, VaultHoldingsWithUSDValue } from './vault';
import { AddAssetToMarketParams, CreateKaminoMarketParams, ENV, KaminoReserve, LendingMarket, MarketWithAddress, PubkeyHashMap, Reserve, ReserveWithAddress, ScopeOracleConfig } from '../lib';
import { ReserveConfig } from '../idl_codegen/types';
import Decimal from 'decimal.js';
import { VaultState } from '../idl_codegen_kamino_vault/accounts';
import { VaultConfigFieldKind } from '../idl_codegen_kamino_vault/types';
/**
* KaminoManager is a class that provides a high-level interface to interact with the Kamino Lend and Kamino Vault programs, in order to create and manage a market, as well as vaults
*/
export declare class KaminoManager {
private readonly _connection;
private readonly _kaminoVaultProgramId;
private readonly _kaminoLendProgramId;
private readonly _vaultClient;
recentSlotDurationMs: number;
constructor(connection: Connection, kaminoLendProgramId?: PublicKey, kaminoVaultProgramId?: PublicKey, recentSlotDurationMs?: number);
getConnection(): Connection;
getProgramID(): PublicKey;
/**
* This is a function that helps quickly setting up a reserve for an asset with a default config. The config can be modified later on.
* @param params.admin - the admin of the market
* @returns market keypair - keypair used for market account creation -> to be signed with when executing the transaction
* @returns ixns - an array of ixns for creating and initializing the market account
*/
createMarketIxs(params: CreateKaminoMarketParams): Promise<{
market: Keypair;
ixns: TransactionInstruction[];
}>;
/**
* This is a function that helps quickly setting up a reserve for an asset with a default config. The config can be modified later on.
* @param params.admin - the admin of the reserve
* @param params.marketAddress - the market to create a reserve for, only the market admin can create a reserve for the market
* @param params.assetConfig - an object that helps generate a default reserve config with some inputs which have to be configured before calling this function
* @returns reserve - keypair used for reserve creation -> to be signed with when executing the transaction
* @returns txnIxns - an array of arrays of ixns -> first array for reserve creation, second for updating it with correct params
*/
addAssetToMarketIxs(params: AddAssetToMarketParams): Promise<{
reserve: Keypair;
txnIxns: TransactionInstruction[][];
}>;
/**
* 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
*/
updateVaultReserveAllocationIxs(vault: KaminoVault, reserveAllocationConfig: ReserveAllocationConfig): Promise<TransactionInstruction>;
/**
* This method retruns the reserve config for a given reserve
* @param reserve - reserve to get the config for
* @returns - the reserve config
*/
getReserveConfig(reserve: PublicKey): Promise<ReserveConfig>;
/**
* This function enables the update of the scope oracle configuration. In order to get a list of scope prices, getScopeOracleConfigs can be used
* @param market - lending market which owns the reserve
* @param reserve - reserve which to be updated
* @param scopeOracleConfig - new scope oracle config
* @param scopeTwapConfig - new scope twap config
* @param maxAgeBufferSeconds - buffer to be added to onchain max_age - if oracle price is older than that, txns interacting with the reserve will fail
* @returns - an array of instructions used update the oracle configuration
*/
updateReserveScopeOracleConfigurationIxs(market: MarketWithAddress, reserve: ReserveWithAddress, scopeOracleConfig: ScopeOracleConfig, scopeTwapConfig?: ScopeOracleConfig, maxAgeBufferSeconds?: number): Promise<TransactionInstruction[]>;
/**
* This function updates the given reserve with a new config. It can either update the entire reserve config or just update fields which differ between given reserve and existing reserve
* @param marketWithAddress - the market that owns the reserve to be updated
* @param reserve - the reserve to be updated
* @param config - the new reserve configuration to be used for the update
* @param reserveStateOverride - the reserve state, useful to provide, if already fetched outside this method, in order to avoid an extra rpc call to fetch it. Make sure the reserveConfig has not been updated since fetching the reserveState that you pass in.
* @param updateEntireConfig - when set to false, it will only update fields that are different between @param config and reserveState.config, set to true it will always update entire reserve config. An entire reserveConfig update might be too large for a multisig transaction
* @returns - an array of multiple update ixns. If there are many fields that are being updated without the updateEntireConfig=true, multiple transactions might be required to fit all ixns.
*/
updateReserveIxs(marketWithAddress: MarketWithAddress, reserve: PublicKey, config: ReserveConfig, reserveStateOverride?: Reserve, updateEntireConfig?: boolean): 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
*/
depositToVaultIxs(user: PublicKey, vault: KaminoVault, tokenAmount: Decimal, tokenProgramIDOverride?: PublicKey, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>): Promise<TransactionInstruction[]>;
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 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
*/
withdrawFromVaultIxs(user: PublicKey, vault: KaminoVault, shareAmount: Decimal, slot: number): 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 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 - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
* @returns - token per share value
*/
getTokensPerShareSingleVault(vault: KaminoVault, slot: number): Promise<Decimal>;
/**
* This method calculates the price of one vault share(kToken)
* @param vault - vault to calculate sharePrice for
* @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
* @param tokenPrice - the price of the vault token (e.g. SOL) in USD
* @returns - share value in USD
*/
getSharePriceInUSD(vault: KaminoVault, slot: number, tokenPrice: Decimal): Promise<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 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?: KaminoVault[]): Promise<PubkeyHashMap<PublicKey, Decimal>>;
/**
* @returns - the KaminoVault client
*/
getKaminoVaultClient(): KaminoVaultClient;
/**
* 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[]>;
/**
* Get all vaults for owner
* @param owner the pubkey of the vaults owner
* @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 owned by a given pubkey
*/
getAllVaultsForOwner(owner: PublicKey, useOptimisedRPCCall?: boolean): Promise<KaminoVault[]>;
/**
* Get all token accounts that hold shares for a specific share mint
* @param shareMint
* @returns an array of all holders tokenAccounts pubkeys and their account info
*/
getShareTokenAccounts(shareMint: PublicKey): Promise<{
pubkey: PublicKey;
account: AccountInfo<Buffer | ParsedAccountData>;
}[]>;
/**
* Get all token accounts that hold shares for a specific vault; if you already have the vault state use it in the param so you don't have to fetch it again
* @param vault
* @returns an array of all holders tokenAccounts pubkeys and their account info
*/
getVaultTokenAccounts(vault: KaminoVault): Promise<{
pubkey: PublicKey;
account: AccountInfo<Buffer | ParsedAccountData>;
}[]>;
/**
* Get all vault token holders
* @param vault
* @returns an array of all vault holders with their pubkeys and amounts
*/
getVaultHolders: (vault: KaminoVault) => Promise<VaultHolder[]>;
/**
* 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>;
/**
* 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 get the list of all reserve pubkeys 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
*/
getAllVaultReserves(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
*/
getVaultReserves(vault: VaultState): PublicKey[];
/**
* 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 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 kaminoVault - vault to invest from
* @returns - an array of invest instructions for each invest action required for the vault reserves
*/
investAllReserves(payer: PublicKey, kaminoVault: 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 kaminoVault - 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
*/
investSingleReserve(payer: PublicKey, kaminoVault: KaminoVault, reserveWithAddress: ReserveWithAddress): Promise<TransactionInstruction[]>;
/**
* This retruns an array of scope oracle configs to be used to set the scope price and twap oracles for a reserve
* @param feed - scope feed to fetch prices from
* @param cluster - cluster to fetch from, this should be left unchanged unless working on devnet or locally
* @returns - an array of scope oracle configs
*/
getScopeOracleConfigs(feed?: string, cluster?: ENV): Promise<Array<ScopeOracleConfig>>;
/**
* This retruns an array of instructions to be used to update the lending market configurations
* @param marketWithAddress - the market address and market state object
* @param newMarket - the lending market state with the new configuration - to be build we new config options from the previous state
* @returns - an array of instructions
*/
updateLendingMarketIxs(marketWithAddress: MarketWithAddress, newMarket: LendingMarket): TransactionInstruction[];
/**
* This retruns an instruction to be used to update the market owner. This can only be executed by the current lendingMarketOwnerCached
* @param marketWithAddress - the market address and market state object
* @param newMarket - the lending market state with the new configuration - to be build we new config options from the previous state
* @returns - an array of instructions
*/
updateLendingMarketOwnerIxs(marketWithAddress: MarketWithAddress): TransactionInstruction;
}
//# sourceMappingURL=manager.d.ts.map