UNPKG

@kamino-finance/klend-sdk

Version:

Typescript SDK for interacting with the Kamino Lending (klend) protocol

554 lines 88.1 kB
import BN from 'bn.js'; import { Address, AccountMeta, Instruction, ProgramDerivedAddress, Rpc, Slot, SolanaRpcApi, TransactionSigner } from '@solana/kit'; import { AllOracleAccounts, CdnResources, KaminoMarket, KaminoReserve, KVaultGlobalConfig, Reserve } from '../lib'; import { UpdateReserveWhitelistModeKind, VaultConfigFieldKind } from '../@codegen/kvault/types'; import { ReserveWhitelistEntry, VaultState } from '../@codegen/kvault/accounts'; import Decimal from 'decimal.js'; import { ReserveWithAddress } from './reserve'; import { AcceptVaultOwnershipIxs, AllDepositAccounts, AllWithdrawAccounts, APYs, CreateVaultFarm, DepositIxs, DisinvestAllReservesIxs, InitVaultIxs, ReserveAllocationOverview, SyncVaultLUTIxs, UpdateReserveAllocationIxs, UpdateVaultConfigIxs, UserSharesForVault, VaultComputedAllocation, VaultReleaseCheckResult, WithdrawAndBlockReserveIxs, WithdrawIxs } from './vault_types'; import { FarmIncentives, FarmState } from '@kamino-finance/farms-sdk/dist'; import { Farms } from '@kamino-finance/farms-sdk'; export declare const kaminoVaultId: Address<"KvauGMspG5k6rtzrqqn7WNn3oZdyKqLKwK2XWQ8FLjd">; export declare const kaminoVaultStagingId: Address<"stKvQfwRsQiKnLtMNVLHKS3exFJmZFsgfzBPWHECUYK">; export declare const METADATA_SEED = "metadata"; export declare const METADATA_PROGRAM_ID: Address; export declare const INITIAL_DEPOSIT_LAMPORTS = 1000; export declare const DEFAULT_CU_PER_TX = 1400000; /** * KaminoVaultClient is a class that provides a high-level interface to interact with the Kamino Vault program. */ export declare class KaminoVaultClient { private readonly _rpc; private readonly _kaminoVaultProgramId; private readonly _kaminoLendProgramId; private readonly _farmsProgramId?; recentSlotDurationMs: number; private _cdnResources?; private _cdnResourcesPromise?; constructor(rpc: Rpc<SolanaRpcApi>, recentSlotDurationMs: number, kaminoVaultprogramId?: Address, kaminoLendProgramId?: Address, cdnResources?: CdnResources, farmsProgramId?: Address); getConnection(): Rpc<import("@solana/kit").RequestAirdropApi & import("@solana/kit").GetAccountInfoApi & import("@solana/kit").GetBalanceApi & import("@solana/kit").GetBlockApi & import("@solana/kit").GetBlockCommitmentApi & import("@solana/kit").GetBlockHeightApi & import("@solana/kit").GetBlockProductionApi & import("@solana/kit").GetBlocksApi & import("@solana/kit").GetBlocksWithLimitApi & import("@solana/kit").GetBlockTimeApi & import("@solana/kit").GetClusterNodesApi & import("@solana/kit").GetEpochInfoApi & import("@solana/kit").GetEpochScheduleApi & import("@solana/kit").GetFeeForMessageApi & import("@solana/kit").GetFirstAvailableBlockApi & import("@solana/kit").GetGenesisHashApi & import("@solana/kit").GetHealthApi & import("@solana/kit").GetHighestSnapshotSlotApi & import("@solana/kit").GetIdentityApi & import("@solana/kit").GetInflationGovernorApi & import("@solana/kit").GetInflationRateApi & import("@solana/kit").GetInflationRewardApi & import("@solana/kit").GetLargestAccountsApi & import("@solana/kit").GetLatestBlockhashApi & import("@solana/kit").GetLeaderScheduleApi & import("@solana/kit").GetMaxRetransmitSlotApi & import("@solana/kit").GetMaxShredInsertSlotApi & import("@solana/kit").GetMinimumBalanceForRentExemptionApi & import("@solana/kit").GetMultipleAccountsApi & import("@solana/kit").GetProgramAccountsApi & import("@solana/kit").GetRecentPerformanceSamplesApi & import("@solana/kit").GetRecentPrioritizationFeesApi & import("@solana/kit").GetSignaturesForAddressApi & import("@solana/kit").GetSignatureStatusesApi & import("@solana/kit").GetSlotApi & import("@solana/kit").GetSlotLeaderApi & import("@solana/kit").GetSlotLeadersApi & import("@solana/kit").GetStakeMinimumDelegationApi & import("@solana/kit").GetSupplyApi & import("@solana/kit").GetTokenAccountBalanceApi & import("@solana/kit").GetTokenAccountsByDelegateApi & import("@solana/kit").GetTokenAccountsByOwnerApi & import("@solana/kit").GetTokenLargestAccountsApi & import("@solana/kit").GetTokenSupplyApi & import("@solana/kit").GetTransactionApi & import("@solana/kit").GetTransactionCountApi & import("@solana/kit").GetVersionApi & import("@solana/kit").GetVoteAccountsApi & import("@solana/kit").IsBlockhashValidApi & import("@solana/kit").MinimumLedgerSlotApi & import("@solana/kit").SendTransactionApi & import("@solana/kit").SimulateTransactionApi>; getProgramID(): Address; getRpc(): Rpc<import("@solana/kit").RequestAirdropApi & import("@solana/kit").GetAccountInfoApi & import("@solana/kit").GetBalanceApi & import("@solana/kit").GetBlockApi & import("@solana/kit").GetBlockCommitmentApi & import("@solana/kit").GetBlockHeightApi & import("@solana/kit").GetBlockProductionApi & import("@solana/kit").GetBlocksApi & import("@solana/kit").GetBlocksWithLimitApi & import("@solana/kit").GetBlockTimeApi & import("@solana/kit").GetClusterNodesApi & import("@solana/kit").GetEpochInfoApi & import("@solana/kit").GetEpochScheduleApi & import("@solana/kit").GetFeeForMessageApi & import("@solana/kit").GetFirstAvailableBlockApi & import("@solana/kit").GetGenesisHashApi & import("@solana/kit").GetHealthApi & import("@solana/kit").GetHighestSnapshotSlotApi & import("@solana/kit").GetIdentityApi & import("@solana/kit").GetInflationGovernorApi & import("@solana/kit").GetInflationRateApi & import("@solana/kit").GetInflationRewardApi & import("@solana/kit").GetLargestAccountsApi & import("@solana/kit").GetLatestBlockhashApi & import("@solana/kit").GetLeaderScheduleApi & import("@solana/kit").GetMaxRetransmitSlotApi & import("@solana/kit").GetMaxShredInsertSlotApi & import("@solana/kit").GetMinimumBalanceForRentExemptionApi & import("@solana/kit").GetMultipleAccountsApi & import("@solana/kit").GetProgramAccountsApi & import("@solana/kit").GetRecentPerformanceSamplesApi & import("@solana/kit").GetRecentPrioritizationFeesApi & import("@solana/kit").GetSignaturesForAddressApi & import("@solana/kit").GetSignatureStatusesApi & import("@solana/kit").GetSlotApi & import("@solana/kit").GetSlotLeaderApi & import("@solana/kit").GetSlotLeadersApi & import("@solana/kit").GetStakeMinimumDelegationApi & import("@solana/kit").GetSupplyApi & import("@solana/kit").GetTokenAccountBalanceApi & import("@solana/kit").GetTokenAccountsByDelegateApi & import("@solana/kit").GetTokenAccountsByOwnerApi & import("@solana/kit").GetTokenLargestAccountsApi & import("@solana/kit").GetTokenSupplyApi & import("@solana/kit").GetTransactionApi & import("@solana/kit").GetTransactionCountApi & import("@solana/kit").GetVersionApi & import("@solana/kit").GetVoteAccountsApi & import("@solana/kit").IsBlockhashValidApi & import("@solana/kit").MinimumLedgerSlotApi & import("@solana/kit").SendTransactionApi & import("@solana/kit").SimulateTransactionApi>; hasFarm(): void; private loadCdnResourcesOnce; /** * Check if a vault has all the needed criteria to be released * - owner is multisig * - vaultFarm is set and it is a farm that is valid * - FLC farm is set and it is a farm that is valid (warning if not) * - check shares token metadata is set * - Check min deposit is not 0 * - Check the vault has at least one allocation * - Check there are allocations with weight > 0 and cap > 0 (and give warning for each allocation which doesn't have cap == u64::MAX) * - Check CDN (using loadCdnResourcesOnce) that the vaultAdmin exists in the list of admins and has a description * @param vault - the vault to check * @returns - a promise that resolves to the release status of the vault */ checkVaultReleaseStatus(vault: KaminoVault): Promise<VaultReleaseCheckResult>; /** * 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 * @param [slot] - optional slot to use for calculations; if not provided, the latest confirmed slot will be fetched * @returns - void; prints the vault to the console */ printVault(vaultPubkey: Address, vaultState?: VaultState, slot?: Slot): Promise<void>; /** * This method initializes the kvault global config (one off, needs to be signed by program owner) * @param admin - the admin of the kvault program * @returns - an instruction to initialize the kvault global config */ initKvaultGlobalConfigIx(admin: TransactionSigner): Promise<Instruction<string, readonly (AccountMeta<string> | import("@solana/kit").AccountLookupMeta<string, string>)[]>>; /** * This method updates the kvault global config * @param mode - the mode to update the global config with * @returns - an instruction to update the global config */ updateGlobalConfigIx(mode: string, value: string): Promise<Instruction<string, readonly (AccountMeta<string> | import("@solana/kit").AccountLookupMeta<string, string>)[]>>; /** * This method accepts the ownership of the global config * @param admin - the admin of the transaction * @returns - an instruction to accept the ownership of the global config */ acceptGlobalConfigOwnershipIx(admin: TransactionSigner): Promise<Instruction<string, readonly (AccountMeta<string> | import("@solana/kit").AccountLookupMeta<string, string>)[]>>; /** * 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 * @param [useDevnetFarms] - whether to use devnet farms * @param [slot] - optional slot to use for lookup table creation; if not provided, the latest finalized slot will be fetched * @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, useDevnetFarms?: boolean, slot?: Slot): Promise<{ vault: TransactionSigner; lut: Address; initVaultIxs: InitVaultIxs; }>; /** * This method creates a farm for a vault * @param signer - the signer of the transaction * @param vaultSharesMint - the mint of the vault shares * @param vaultAddress - the address of the vault (it doesn't need to be already initialized) * @returns a struct with the farm, the setup farm ixs and the update farm ixs */ createVaultFarm(signer: TransactionSigner, vaultAddress: Address, vaultSharesMint: Address, useDevnetFarms?: boolean): Promise<CreateVaultFarm>; /** * This method creates an instruction to set the shares metadata for a vault * @param rpc * @param vaultAdmin * @param vault - the vault to set the shares metadata for * @param sharesMint * @param baseVaultAuthority * @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(rpc: Rpc<SolanaRpcApi>, vaultAdmin: TransactionSigner, vault: Address, sharesMint: Address, baseVaultAuthority: Address, tokenName: string, extraName: string, metadataProgramId?: Address, kvaultProgramId?: Address): Promise<Instruction<string, readonly (AccountMeta<string> | import("@solana/kit").AccountLookupMeta<string, string>)[]>>; /** * This method updates the vault reserve allocation config 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 [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @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, vaultAdminAuthority?: TransactionSigner): Promise<UpdateReserveAllocationIxs>; /** * This method updates the unallocated weight and cap of a vault (both are optional, if not provided the current values will be used) * @param vault - the vault to update the unallocated weight and cap for * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @param [unallocatedWeight] - the new unallocated weight to set. If not provided, the current unallocated weight will be used * @param [unallocatedCap] - the new unallocated cap to set. If not provided, the current unallocated cap will be used * @returns - a list of instructions to update the unallocated weight and cap */ updateVaultUnallocatedWeightAndCapIxs(vault: KaminoVault, vaultAdminAuthority?: TransactionSigner, unallocatedWeight?: BN, unallocatedCap?: BN): Promise<Instruction<string, readonly (AccountMeta<string> | import("@solana/kit").AccountLookupMeta<string, string>)[]>[]>; /** * 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 [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @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: Address, vaultAdminAuthority?: TransactionSigner): 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 allocations (set weight and ctoken allocation to 0) and an a list of instructions to disinvest the funds in the reserves */ withdrawEverythingFromAllReservesAndBlockInvest(vault: KaminoVault, vaultReservesMap?: Map<Address, KaminoReserve>, payer?: TransactionSigner): Promise<WithdrawAndBlockReserveIxs>; /** * This method disinvests all the funds from all the reserves and set their weight to 0; for vaults that are managed by external bot/crank, the bot can change the weight and invest in the reserves again * @param vault - the vault to disinvest 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 allocations to 0 weight and a list of instructions to disinvest the funds in the reserves */ disinvestAllReservesIxs(vault: KaminoVault, vaultReservesMap?: Map<Address, KaminoReserve>, payer?: TransactionSigner): Promise<DisinvestAllReservesIxs>; /** * 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 * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @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: Address, vaultAdminAuthority?: TransactionSigner): Promise<Instruction | 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 [adminAuthority] 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. * The global admin should be passed in when wanting to change the AllowAllocationsInWhitelistedReservesOnly or AllowInvestInWhitelistedReservesOnly fields to false * @param [lutIxsSigner] the signer of the transaction to be used for the lookup table instructions. 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 * @param [skipLutUpdate] if true, the lookup table instructions will not be included in the returned instructions * @param errorOnOverride throw error if vault already has a farm * @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, adminAuthority?: TransactionSigner, lutIxsSigner?: TransactionSigner, skipLutUpdate?: boolean, errorOnOverride?: boolean): Promise<UpdateVaultConfigIxs>; /** * Update the vault performance fee (in bps). * @param vault - vault to update * @param feeBps - performance fee in basis points * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultPerfFeeIxs(vault: KaminoVault, feeBps: BN | number | string, vaultAdminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; /** * Update the vault management fee (in bps). * @param vault - vault to update * @param feeBps - management fee in basis points * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultMgmtFeeIxs(vault: KaminoVault, feeBps: BN | number | string, vaultAdminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; /** * Update the pending admin for the vault (step 1/2 of the ownership transfer). * @param vault - vault to update * @param newAdmin - new pending admin pubkey * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @param [lutIxsSigner] - signer for LUT updates when adding the new admin * @param [skipLutUpdate] - if true, the LUT update instructions are not returned * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultPendingAdminIxs(vault: KaminoVault, newAdmin: Address, vaultAdminAuthority?: TransactionSigner, lutIxsSigner?: TransactionSigner, skipLutUpdate?: boolean): Promise<UpdateVaultConfigIxs>; /** * Update the vault name. * @param vault - vault to update * @param name - new vault name * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultNameIxs(vault: KaminoVault, name: string, vaultAdminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; /** * Update the vault lookup table address. * @param vault - vault to update * @param lookupTable - new LUT address * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultLookupTableIxs(vault: KaminoVault, lookupTable: Address, vaultAdminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; /** * Update the vault allocation admin. * @param vault - vault to update * @param allocationAdmin - new allocation admin pubkey * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultAllocationAdminIxs(vault: KaminoVault, allocationAdmin: Address, vaultAdminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; /** * Update the vault unallocated weight. * @param vault - vault to update * @param unallocatedWeight - new unallocated weight * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultUnallocatedWeightIxs(vault: KaminoVault, unallocatedWeight: BN | number | string, vaultAdminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; /** * Update the vault unallocated tokens cap. * @param vault - vault to update * @param unallocatedTokensCap - new unallocated tokens cap * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultUnallocatedTokensCapIxs(vault: KaminoVault, unallocatedTokensCap: BN | number | string, vaultAdminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; /** * Update the vault farm address. * @param vault - vault to update * @param farm - farm address * @param [errorOnOverride] - if true, it will throw if the vault already has a farm * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @param [lutIxsSigner] - signer for LUT updates when adding the farm * @param [skipLutUpdate] - if true, the LUT update instructions are not returned * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultFarmIxs(vault: KaminoVault, farm: Address, errorOnOverride?: boolean, vaultAdminAuthority?: TransactionSigner, lutIxsSigner?: TransactionSigner, skipLutUpdate?: boolean): Promise<UpdateVaultConfigIxs>; /** * Update the first loss capital farm address. * @param vault - vault to update * @param farm - farm address * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultFirstLossCapitalFarmIxs(vault: KaminoVault, farm: Address, vaultAdminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; /** * Update the vault min deposit amount (in lamports). * @param vault - vault to update * @param minDepositAmount - new minimum deposit amount * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultMinDepositAmountIxs(vault: KaminoVault, minDepositAmount: BN | number | string, vaultAdminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; /** * Update the vault min withdraw amount (in lamports). * @param vault - vault to update * @param minWithdrawAmount - new minimum withdraw amount * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultMinWithdrawAmountIxs(vault: KaminoVault, minWithdrawAmount: BN | number | string, vaultAdminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; /** * Update the vault min invest amount (in lamports). * @param vault - vault to update * @param minInvestAmount - new minimum invest amount * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultMinInvestAmountIxs(vault: KaminoVault, minInvestAmount: BN | number | string, vaultAdminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; /** * Update the vault min invest delay (in slots). * @param vault - vault to update * @param minInvestDelaySlots - new minimum invest delay in slots * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultMinInvestDelaySlotsIxs(vault: KaminoVault, minInvestDelaySlots: BN | number | string, vaultAdminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; /** * Update the vault crank fund fee per reserve (in lamports). * @param vault - vault to update * @param crankFundFeePerReserve - new fee per reserve * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultCrankFundFeePerReserveIxs(vault: KaminoVault, crankFundFeePerReserve: BN | number | string, vaultAdminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; /** * Update the vault withdrawal penalty (in lamports). * @param vault - vault to update * @param withdrawalPenaltyLamports - new withdrawal penalty amount * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultWithdrawalPenaltyLamportsIxs(vault: KaminoVault, withdrawalPenaltyLamports: BN | number | string, vaultAdminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; /** * Update the vault withdrawal penalty (in bps). * @param vault - vault to update * @param withdrawalPenaltyBps - new withdrawal penalty bps * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultWithdrawalPenaltyBpsIxs(vault: KaminoVault, withdrawalPenaltyBps: BN | number | string, vaultAdminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; /** * Update whether allocations are restricted to whitelisted reserves only. * @param vault - vault to update * @param allowWhitelistedOnly - true to restrict, false to allow any reserve * @param [adminAuthority] - signer; pass global admin when setting to false * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultAllowAllocationsInWhitelistedReservesOnlyIxs(vault: KaminoVault, allowWhitelistedOnly: boolean | string, adminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; /** * Update whether invest is restricted to whitelisted reserves only. * @param vault - vault to update * @param allowWhitelistedOnly - true to restrict, false to allow any reserve * @param [adminAuthority] - signer; pass global admin when setting to false * @returns - a struct containing the update instruction and optional LUT updates */ updateVaultAllowInvestInWhitelistedReservesOnlyIxs(vault: KaminoVault, allowWhitelistedOnly: boolean | string, adminAuthority?: TransactionSigner): Promise<UpdateVaultConfigIxs>; updateVaultConfigValidations(mode: VaultConfigFieldKind, value: string, vaultState: VaultState): Promise<void>; /** * Add or update a reserve whitelist entry. This controls whether the reserve is whitelisted for adding/updating * allocations or for invest, depending on the mode parameter. * * @param reserve - Address of the reserve to whitelist * @param mode - The whitelist mode: either 'Invest' or 'AddAllocation' with a value (1 = allow, 0 = deny) * @param globalAdmin - The global admin that signs the transaction * @returns - An instruction to add/update the whitelisted reserve */ addUpdateWhitelistedReserveIx(reserve: Address, mode: UpdateReserveWhitelistModeKind, globalAdmin: TransactionSigner): Promise<Instruction>; /** 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 * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @param [lutIxsSigner] - the signer of the transaction to be used for the lookup table instructions. 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 * @param [skipLutUpdate] - if true, the lookup table instructions will not be included in the returned instructions * @returns - a struct that contains the instruction to update the farm and an optional list of instructions to update the lookup table */ setVaultFarmIxs(vault: KaminoVault, farm: Address, errorOnOverride?: boolean, vaultAdminAuthority?: TransactionSigner, lutIxsSigner?: TransactionSigner, skipLutUpdate?: boolean): Promise<UpdateVaultConfigIxs>; /** * This method updates the vault config during vault initialization, within the same transaction * where the vault is created. Use this when the vault state is not yet committed to the chain * and cannot be fetched via RPC. For updates to existing vaults, use updateVaultConfigIxs instead. * * @param admin - the admin that signs the transaction * @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 * @param [pendingAdmin] - pending vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @param [slot] - optional slot to use for lookup table creation; if not provided, the latest finalized slot will be fetched * @returns - an instruction to accept the ownership of the vault and a list of instructions to update the lookup table */ acceptVaultOwnershipIxs(vault: KaminoVault, pendingAdmin?: TransactionSigner, slot?: Slot): 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 * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - an instruction to give up the specified pending fees */ giveUpPendingFeesIx(vault: KaminoVault, maxAmountToGiveUp: Decimal, vaultAdminAuthority?: TransactionSigner): Promise<Instruction>; /** * 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 * @param [vaultAdminAuthority] - vault admin - a noop vaultAdminAuthority is provided when absent for multisigs * @returns - list of instructions to withdraw all pending fees, including the ATA creation instructions if needed */ withdrawPendingFeesIxs(vault: KaminoVault, currentSlot?: Slot, vaultReservesMap?: Map<Address, KaminoReserve>, vaultAdminAuthority?: TransactionSigner): Promise<Instruction[]>; /** * 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 as well as ixs to stake in the first loss capital farm if the vault has one - only one set on ixs so stake in a farm can be used -> staking can be either done in the farm or in the first loss capital farm */ depositIxs(user: TransactionSigner, vault: KaminoVault, tokenAmount: Decimal, vaultReservesMap?: Map<Address, KaminoReserve>, farmState?: FarmState, payer?: TransactionSigner): Promise<DepositIxs>; buySharesIxs(user: TransactionSigner, vault: KaminoVault, tokenAmount: Decimal, vaultReservesMap?: Map<Address, KaminoReserve>, farmState?: FarmState, payer?: TransactionSigner): Promise<DepositIxs>; private buildShareEntryIxs; /** * Returns the accounts needed for a vault deposit instruction, without building the instruction itself. * Includes the deposit accounts, the remaining accounts for vault reserves, and optionally the stake shares instructions if the vault has a farm. * @param user - the user depositing into the vault * @param vault - the vault to deposit into * @param [vaultReservesMap] - optional preloaded reserve states; if not provided they will be fetched * @param [farmState] - optional preloaded farm state; if not provided and the vault has a farm, it will be fetched * @returns the deposit accounts, remaining accounts, and optional stake shares instructions */ getDepositAccounts(user: TransactionSigner, vault: KaminoVault, vaultReservesMap?: Map<Address, KaminoReserve>, farmState?: FarmState): Promise<AllDepositAccounts>; /** * Returns the accounts needed for a vault withdraw instruction, without building the instruction itself. * If a reserve is provided, builds the full WithdrawAccounts (withdraw from reserve). Otherwise builds WithdrawFromAvailableAccounts (withdraw from available liquidity only). * Also includes remaining accounts for vault reserves and optionally the unstake instructions if the vault has a farm. * @param user - the user withdrawing from the vault * @param vault - the vault to withdraw from * @param [reserve] - optional reserve to withdraw from; if omitted, builds accounts for withdrawing from available liquidity only * @param [vaultReservesMap] - optional preloaded reserve states; if not provided they will be fetched * @param [farmState] - optional preloaded farm state; if not provided and the vault has a farm, it will be fetched * @returns the withdraw accounts, remaining accounts, and optional unstake shares instructions */ getWithdrawAccounts(user: TransactionSigner, vault: KaminoVault, reserve?: ReserveWithAddress, vaultReservesMap?: Map<Address, KaminoReserve>, farmState?: FarmState): Promise<AllWithdrawAccounts>; /** * 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: TransactionSigner, vault: KaminoVault, sharesAmount?: Decimal, farmState?: FarmState): Promise<Instruction[]>; /** * This function creates instructions to stake the shares in the vault firstLossCapital farm if the vault has a farm * @param user - user to stake * @param vault - vault to deposit into its flc 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 flc 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 firstLossCapital farm, including the creation of prerequisite accounts if needed */ stakeSharesInFlcFarmIxs(user: TransactionSigner, vault: KaminoVault, sharesAmount?: Decimal, farmState?: FarmState): Promise<Instruction[]>; /** * 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 shareAmountToWithdraw - 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: TransactionSigner, vault: KaminoVault, shareAmountToWithdraw: Decimal, slot: Slot, vaultReservesMap?: Map<Address, KaminoReserve>, farmState?: FarmState, payer?: TransactionSigner): Promise<WithdrawIxs>; /** * 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 sell shares for vault tokens * @param vault - vault to sell shares from * @param shareAmountToWithdraw - share amount to sell (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 */ sellSharesIxs(user: TransactionSigner, vault: KaminoVault, shareAmountToWithdraw: Decimal, slot: Slot, vaultReservesMap?: Map<Address, KaminoReserve>, farmState?: FarmState, payer?: TransactionSigner): Promise<WithdrawIxs>; private buildShareExitIxs; private withdrawFromAvailableIxs; private buildReserveExitIxs; /** * 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 * @param skipComputationChecks - if true, the function will skip the computation checks and will invest all the reserves; it is useful for txs where we update reserve allocations and invest atomically * @returns - an array of invest instructions for each invest action required for the vault reserves */ investAllReservesIxs(payer: TransactionSigner, vault: KaminoVault, skipComputationChecks?: boolean): Promise<Instruction[]>; /** * 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 - the instruction is permissionless and does not require the vault admin, due to rounding between cTokens and the underlying, the payer may have to contribute 1 or more lamports of the underlying from their token account * @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 * @param [createAtaIfNeeded] * @returns - an array of invest instructions for each invest action required for the vault reserves */ investSingleReserveIxs(payer: TransactionSigner, vault: KaminoVault, reserve: ReserveWithAddress, vaultReservesMap?: Map<Address, KaminoReserve>, createAtaIfNeeded?: boolean): Promise<Instruction[]>; /** 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; /** Helper to serialize value as Buffer for updateVaultConfig instruction */ private getValueForModeAsBuffer; private sellIx; 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 authority - vault admin * @param vault the vault to sync and set the LUT for if needed * @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] - optional slot to use for lookup table creation; if not provided, the latest confirmed slot will be fetched * @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(authority: TransactionSigner, vault: KaminoVault, vaultReservesMap?: Map<Address, KaminoReserve>, slot?: Slot): Promise<SyncVaultLUTIxs>; private getReserveAccountsToInsertInLut; /** 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?: Slot, vaultReserves?: Map<Address, KaminoReserve>, currentSlot?: Slot): Promise<VaultComputedAllocation>; private computeReservesAllocation; /** * 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: Address, 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: Address, vaultsOverride?: Array<KaminoVault>): Promise<Map<Address, 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 vaultState - vault state 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(vaultOrState: KaminoVault | VaultState, slot?: Slot, vaultReservesMap?: Map<Address, KaminoReserve>, currentSlot?: Slot): 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: Slot, vaultsOverride?: Array<KaminoVault>, vaultReservesMap?: Map<Address, KaminoReserve>): Promise<Map<Address, 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: Address): Promise<Array<KaminoV