@kamino-finance/klend-sdk
Version:
Typescript SDK for interacting with the Kamino Lending (klend) protocol
109 lines (91 loc) • 3.55 kB
text/typescript
import { AccountMeta, Address, Instruction, TransactionSigner } from '@solana/kit';
import { DepositAccounts, WithdrawAccounts, WithdrawFromAvailableAccounts } from '../@codegen/kvault/instructions';
import Decimal from 'decimal.js/decimal';
/** the populateLUTIxs should be executed in a separate transaction as we cannot create and populate a lookup table in the same tx */
export type InitVaultIxs = {
createAtaIfNeededIxs: Instruction[];
initVaultIxs: Instruction[];
createLUTIx: Instruction;
populateLUTIxs: Instruction[];
cleanupIxs: Instruction[];
initSharesMetadataIx: Instruction;
createVaultFarm: CreateVaultFarm;
setFarmToVaultIx: Instruction;
};
export type AcceptVaultOwnershipIxs = {
acceptVaultOwnershipIx: Instruction;
initNewLUTIx: Instruction;
updateLUTIxs: Instruction[]; // this has to be executed in a transaction after the initNewLUTIx is executed
};
export type UpdateReserveAllocationIxs = {
updateReserveAllocationIx: Instruction;
updateLUTIxs: Instruction[];
};
export type WithdrawAndBlockReserveIxs = {
updateReserveAllocationIxs: Instruction[];
investIxs: Instruction[];
};
export type DisinvestAllReservesIxs = {
updateReserveAllocationIxs: Instruction[];
investIxs: Instruction[];
};
export type UpdateVaultConfigIxs = {
updateVaultConfigIx: Instruction;
updateLUTIxs: Instruction[];
};
export type VaultComputedAllocation = {
targetUnallocatedAmount: Decimal;
targetReservesAllocation: Map<Address, Decimal>;
};
/** If there are ixs to setup the LUT it means it doesn't already exist and it needs to be created in a separate tx before inserting into it */
export type SyncVaultLUTIxs = {
setupLUTIfNeededIxs: Instruction[];
syncLUTIxs: Instruction[];
};
/** If the stakeInFarmIfNeededIxs/stakeInFlcFarmIfNeededIxs exist they have to be executed after the deposit so the shares received from the deposit are staked in the vault farm. Only one of the stake ixs can be executed, either for the vault farms or the first loss capital farm*/
export type DepositIxs = {
depositIxs: Instruction[];
stakeInFarmIfNeededIxs: Instruction[];
stakeInFlcFarmIfNeededIxs: Instruction[]; // if the vault has a firstLossCapital farm, these ixs will stake the shares in the flc farm
};
/** the ixs to unstake shares from farm and withdraw them from the vault. The `unstakeFromFarmIfNeededIxs` should be in the tx before `withdrawIxs`*/
export type WithdrawIxs = {
unstakeFromFarmIfNeededIxs: Instruction[];
withdrawIxs: Instruction[];
postWithdrawIxs: Instruction[]; // if needed: wSOL ATA close ix + share ATA close ix
};
/** The shares an user has in a vault (staked and unstaked), in tokens */
export type UserSharesForVault = {
unstakedShares: Decimal;
stakedShares: Decimal;
totalShares: Decimal;
};
export type ReserveAllocationOverview = {
targetWeight: Decimal;
tokenAllocationCap: Decimal;
ctokenAllocation: Decimal;
};
export type APYs = {
grossAPY: Decimal;
netAPY: Decimal;
};
export type CreateVaultFarm = {
farm: TransactionSigner;
setupFarmIxs: Instruction[];
updateFarmIxs: Instruction[];
};
export type VaultReleaseCheckResult = {
errors: string[];
warnings: string[];
success: boolean;
};
export type AllDepositAccounts = {
depositAccounts: DepositAccounts;
remainingAccounts: AccountMeta[];
stakeSharesIxs?: Instruction[];
};
export type AllWithdrawAccounts = {
withdrawAccounts: WithdrawAccounts | WithdrawFromAvailableAccounts;
remainingAccounts: AccountMeta[];
unstakeSharesIxs?: Instruction[];
};