UNPKG

@kamino-finance/klend-sdk

Version:

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

209 lines 16 kB
import { Connection, PublicKey, RpcResponseAndContext, SimulatedTransactionResponse, Transaction, TransactionInstruction, TransactionSignature } from '@solana/web3.js'; import BN from 'bn.js'; import { ObligationType, ScopePriceRefreshConfig } from '../utils'; import { KaminoMarket } from './market'; import { KaminoObligation } from './obligation'; import { KaminoReserve } from './reserve'; import { Scope } from '@kamino-finance/scope-sdk'; import { ObligationOrderAtIndex } from './obligationOrder'; export type ActionType = 'deposit' | 'borrow' | 'withdraw' | 'repay' | 'mint' | 'redeem' | 'depositCollateral' | 'liquidate' | 'depositAndBorrow' | 'repayAndWithdraw' | 'refreshObligation' | 'requestElevationGroup' | 'withdrawReferrerFees' | 'repayAndWithdrawV2' | 'depositAndWithdraw'; export type AuxiliaryIx = 'setup' | 'inBetween' | 'cleanup'; export declare class KaminoAction { kaminoMarket: KaminoMarket; reserve: KaminoReserve; outflowReserve: KaminoReserve | undefined; owner: PublicKey; payer: PublicKey; obligation: KaminoObligation | ObligationType; referrer: PublicKey; /** * Null unless the obligation is not passed */ obligationType: ObligationType | null; mint: PublicKey; secondaryMint?: PublicKey; positions?: number; amount: BN; outflowAmount?: BN; computeBudgetIxs: Array<TransactionInstruction>; computeBudgetIxsLabels: Array<string>; setupIxs: Array<TransactionInstruction>; setupIxsLabels: Array<string>; inBetweenIxs: Array<TransactionInstruction>; inBetweenIxsLabels: Array<string>; lendingIxs: Array<TransactionInstruction>; lendingIxsLabels: Array<string>; cleanupIxs: Array<TransactionInstruction>; cleanupIxsLabels: Array<string>; refreshFarmsCleanupTxnIxs: Array<TransactionInstruction>; refreshFarmsCleanupTxnIxsLabels: Array<string>; depositReserves: Array<PublicKey>; borrowReserves: Array<PublicKey>; preLoadedDepositReservesSameTx: Array<PublicKey>; currentSlot: number; private constructor(); static initialize(action: ActionType, amount: string | BN, mint: PublicKey, owner: PublicKey, kaminoMarket: KaminoMarket, obligation: KaminoObligation | ObligationType, referrer?: PublicKey, currentSlot?: number, payer?: PublicKey): Promise<KaminoAction>; private static getUserAccountAddresses; private static loadObligation; static buildRefreshObligationTxns(kaminoMarket: KaminoMarket, payer: PublicKey, obligation: KaminoObligation, extraComputeBudget?: number, // if > 0 then adds the ix currentSlot?: number): Promise<KaminoAction>; static buildRequestElevationGroupTxns(kaminoMarket: KaminoMarket, payer: PublicKey, obligation: KaminoObligation, elevationGroup: number, extraComputeBudget?: number, // if > 0 then adds the ix currentSlot?: number): Promise<KaminoAction>; static buildDepositTxns(kaminoMarket: KaminoMarket, amount: string | BN, mint: PublicKey, owner: PublicKey, obligation: KaminoObligation | ObligationType, useV2Ixs: boolean, scopeRefreshConfig: ScopePriceRefreshConfig | undefined, extraComputeBudget?: number, // if > 0 then adds the ix includeAtaIxs?: boolean, // if true it includes create and close wsol and token atas, requestElevationGroup?: boolean, // to be requested *before* the deposit initUserMetadata?: { skipInitialization: boolean; skipLutCreation: boolean; }, referrer?: PublicKey, currentSlot?: number, overrideElevationGroupRequest?: number | undefined): Promise<KaminoAction>; addScopeRefreshIxs(scope: Scope, tokens: number[], feed?: string): Promise<void>; static buildBorrowTxns(kaminoMarket: KaminoMarket, amount: string | BN, mint: PublicKey, owner: PublicKey, obligation: KaminoObligation | ObligationType, useV2Ixs: boolean, scopeRefreshConfig: ScopePriceRefreshConfig | undefined, extraComputeBudget?: number, // if > 0 then adds the ix includeAtaIxs?: boolean, // if true it includes create and close wsol and token atas, requestElevationGroup?: boolean, initUserMetadata?: { skipInitialization: boolean; skipLutCreation: boolean; }, referrer?: PublicKey, currentSlot?: number, overrideElevationGroupRequest?: number | undefined): Promise<KaminoAction>; static buildDepositReserveLiquidityTxns(kaminoMarket: KaminoMarket, amount: string | BN, mint: PublicKey, owner: PublicKey, obligation: KaminoObligation | ObligationType, scopeRefreshConfig: ScopePriceRefreshConfig | undefined, extraComputeBudget?: number, // if > 0 then adds the ix includeAtaIxs?: boolean, // if true it includes create and close wsol and token atas requestElevationGroup?: boolean, referrer?: PublicKey, currentSlot?: number): Promise<KaminoAction>; static buildRedeemReserveCollateralTxns(kaminoMarket: KaminoMarket, amount: string | BN, mint: PublicKey, owner: PublicKey, obligation: KaminoObligation | ObligationType, scopeRefreshConfig: ScopePriceRefreshConfig | undefined, extraComputeBudget?: number, // if > 0 then adds the ix includeAtaIxs?: boolean, // if true it includes create and close wsol and token atas requestElevationGroup?: boolean, referrer?: PublicKey, currentSlot?: number): Promise<KaminoAction>; static buildDepositObligationCollateralTxns(kaminoMarket: KaminoMarket, amount: string | BN, mint: PublicKey, owner: PublicKey, obligation: KaminoObligation | ObligationType, useV2Ixs: boolean, scopeRefreshConfig: ScopePriceRefreshConfig | undefined, extraComputeBudget?: number, // if > 0 then adds the ix includeAtaIxs?: boolean, // if true it includes create and close wsol and token atas requestElevationGroup?: boolean, initUserMetadata?: { skipInitialization: boolean; skipLutCreation: boolean; }, referrer?: PublicKey, currentSlot?: number): Promise<KaminoAction>; static buildDepositAndBorrowTxns(kaminoMarket: KaminoMarket, depositAmount: string | BN, depositMint: PublicKey, borrowAmount: string | BN, borrowMint: PublicKey, payer: PublicKey, obligation: KaminoObligation | ObligationType, useV2Ixs: boolean, scopeRefreshConfig: ScopePriceRefreshConfig | undefined, extraComputeBudget?: number, // if > 0 then adds the ix includeAtaIxs?: boolean, // if true it includes create and close wsol and token atas, requestElevationGroup?: boolean, initUserMetadata?: { skipInitialization: boolean; skipLutCreation: boolean; }, referrer?: PublicKey, currentSlot?: number): Promise<KaminoAction>; static buildDepositAndWithdrawV2Txns(kaminoMarket: KaminoMarket, depositAmount: string | BN, depositMint: PublicKey, withdrawAmount: string | BN, withdrawMint: PublicKey, payer: PublicKey, currentSlot: number, obligation: KaminoObligation | ObligationType, scopeRefreshConfig: ScopePriceRefreshConfig | undefined, extraComputeBudget?: number, // if > 0 then adds the ix includeAtaIxs?: boolean, // if true it includes create and close wsol and token atas, requestElevationGroup?: boolean, initUserMetadata?: { skipInitialization: boolean; skipLutCreation: boolean; }, referrer?: PublicKey): Promise<KaminoAction>; static buildRepayAndWithdrawV2Txns(kaminoMarket: KaminoMarket, repayAmount: string | BN, repayMint: PublicKey, withdrawAmount: string | BN, withdrawMint: PublicKey, payer: PublicKey, currentSlot: number, obligation: KaminoObligation | ObligationType, scopeRefreshConfig: ScopePriceRefreshConfig | undefined, extraComputeBudget?: number, // if > 0 then adds the ix includeAtaIxs?: boolean, // if true it includes create and close wsol and token atas, requestElevationGroup?: boolean, initUserMetadata?: { skipInitialization: boolean; skipLutCreation: boolean; }, referrer?: PublicKey): Promise<KaminoAction>; static buildRepayAndWithdrawTxns(kaminoMarket: KaminoMarket, repayAmount: string | BN, repayMint: PublicKey, withdrawAmount: string | BN, withdrawMint: PublicKey, payer: PublicKey, currentSlot: number, obligation: KaminoObligation | ObligationType, useV2Ixs: boolean, scopeRefreshConfig: ScopePriceRefreshConfig | undefined, extraComputeBudget?: number, // if > 0 then adds the ix includeAtaIxs?: boolean, // if true it includes create and close wsol and token atas, requestElevationGroup?: boolean, initUserMetadata?: { skipInitialization: boolean; skipLutCreation: boolean; }, referrer?: PublicKey): Promise<KaminoAction>; static buildWithdrawTxns(kaminoMarket: KaminoMarket, amount: string | BN, mint: PublicKey, owner: PublicKey, obligation: KaminoObligation | ObligationType, useV2Ixs: boolean, scopeRefreshConfig: ScopePriceRefreshConfig | undefined, extraComputeBudget?: number, // if > 0 then adds the ix includeAtaIxs?: boolean, // if true it includes create and close wsol and token atas, requestElevationGroup?: boolean, // to be requested *after* the withdraw initUserMetadata?: { skipInitialization: boolean; skipLutCreation: boolean; }, referrer?: PublicKey, currentSlot?: number, overrideElevationGroupRequest?: number, obligationCustomizations?: { addedDepositReserves?: PublicKey[]; }): Promise<KaminoAction>; /** * * @param kaminoMarket * @param amount * @param mint * @param owner * @param obligation - obligation to repay or the PDA seeds * @param currentSlot * @param payer - if not set then owner is used * @param extraComputeBudget - if > 0 then adds the ix * @param includeAtaIxs - if true it includes create and close wsol and token atas * @param requestElevationGroup * @param includeUserMetadata - if true it includes user metadata * @param referrer */ static buildRepayTxns(kaminoMarket: KaminoMarket, amount: string | BN, mint: PublicKey, owner: PublicKey, obligation: KaminoObligation | ObligationType, useV2Ixs: boolean, scopeRefreshConfig: ScopePriceRefreshConfig | undefined, currentSlot: number, payer?: PublicKey | undefined, extraComputeBudget?: number, includeAtaIxs?: boolean, requestElevationGroup?: boolean, initUserMetadata?: { skipInitialization: boolean; skipLutCreation: boolean; }, referrer?: PublicKey): Promise<KaminoAction>; static buildLiquidateTxns(kaminoMarket: KaminoMarket, amount: string | BN, minCollateralReceiveAmount: string | BN, repayTokenMint: PublicKey, withdrawTokenMint: PublicKey, liquidator: PublicKey, obligationOwner: PublicKey, obligation: KaminoObligation | ObligationType, useV2Ixs: boolean, scopeRefreshConfig?: ScopePriceRefreshConfig | undefined, extraComputeBudget?: number, // if > 0 then adds the ix includeAtaIxs?: boolean, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist requestElevationGroup?: boolean, initUserMetadata?: { skipInitialization: boolean; skipLutCreation: boolean; }, referrer?: PublicKey, maxAllowedLtvOverridePercent?: number, currentSlot?: number): Promise<KaminoAction>; static buildWithdrawReferrerFeeTxns(owner: PublicKey, tokenMint: PublicKey, kaminoMarket: KaminoMarket, currentSlot?: number): Promise<KaminoAction>; /** * Builds an instruction for setting the new state of one of the given obligation's orders. * * In other words: it will overwrite the given slot in the {@link Obligation.orders} array. This possibly includes * setting the `null` state (i.e. cancelling the order). */ static buildSetObligationOrderIxn(kaminoMarket: KaminoMarket, obligation: KaminoObligation, orderAtIndex: ObligationOrderAtIndex): TransactionInstruction; getTransactions(): Promise<Transaction>; sendTransactions(sendTransaction: (txn: Transaction, connection: Connection) => Promise<TransactionSignature>): Promise<string>; private sendSingleTransaction; simulateTransactions(sendTransaction: (txn: Transaction, connection: Connection) => Promise<RpcResponseAndContext<SimulatedTransactionResponse>>): Promise<"" | RpcResponseAndContext<SimulatedTransactionResponse>>; private simulateSingleTransaction; addDepositReserveLiquidityIx(): void; addRedeemReserveCollateralIx(): void; addDepositIx(): void; addDepositIxV2(): void; addDepositObligationCollateralIx(): void; addDepositObligationCollateralIxV2(): void; addBorrowIx(): void; addBorrowIxV2(): void; addWithdrawIx(collateralAmount: BN): Promise<void>; addWithdrawIxV2(collateralAmount: BN): Promise<void>; addRepayIx(): Promise<void>; addRepayIxV2(): Promise<void>; addRepayAndWithdrawV2Ixs(withdrawCollateralAmount: BN): void; addDepositAndWithdrawV2Ixs(withdrawCollateralAmount: BN): void; addDepositAndBorrowIx(): Promise<void>; addDepositAndBorrowIxV2(): Promise<void>; addRepayAndWithdrawIxs(withdrawCollateralAmount: BN): Promise<void>; addRepayAndWithdrawIxsV2(withdrawCollateralAmount: BN): Promise<void>; addLiquidateIx(maxAllowedLtvOverridePercent?: number): void; addLiquidateIxV2(maxAllowedLtvOverridePercent?: number): Promise<void>; addInBetweenIxs(action: ActionType, includeAtaIxs: boolean, requestElevationGroup: boolean, addInitObligationForFarm: boolean, useV2Ixs: boolean): Promise<void>; addRefreshObligation(crank: PublicKey): void; addSupportIxsWithoutInitObligation(action: ActionType, includeAtaIxs: boolean, useV2Ixs: boolean, addAsSupportIx?: AuxiliaryIx, requestElevationGroup?: boolean, addInitObligationForFarm?: boolean, twoTokenAction?: boolean, overrideElevationGroupRequest?: number): Promise<void>; addSupportIxs(action: ActionType, includeAtaIxs: boolean, requestElevationGroup: boolean, addInitObligationForFarm: boolean, useV2Ixs: boolean, scopeRefreshConfig: ScopePriceRefreshConfig | undefined, initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean; }, twoTokenAction?: boolean, overrideElevationGroupRequest?: number): Promise<void>; private static optionalAccount; private addRefreshReserveIxs; static getRefreshAllReserves(kaminoMarket: KaminoMarket, reserves: PublicKey[]): TransactionInstruction[]; private addRefreshObligationIx; private addRequestElevationIx; private addRefreshFarmsForReserve; private addRefreshFarmsCleanupTxnIxsToCleanupIxs; private addInitObligationForFarm; private addInitObligationIxs; private addInitUserMetadataIxs; private addInitReferrerTokenStateIx; private addWithdrawReferrerFeesIxs; private addComputeBudgetIxn; private addAtaIxs; private updateWSOLAccount; static initializeMultiTokenAction(kaminoMarket: KaminoMarket, action: ActionType, inflowAmount: string | BN, inflowTokenMint: PublicKey, outflowTokenMint: PublicKey, payer: PublicKey, obligationOwner: PublicKey, obligation: KaminoObligation | ObligationType, outflowAmount?: string | BN, referrer?: PublicKey, currentSlot?: number): Promise<KaminoAction>; static initializeWithdrawReferrerFees(mint: PublicKey, owner: PublicKey, kaminoMarket: KaminoMarket, currentSlot?: number): Promise<{ axn: KaminoAction; createAtaIxs: TransactionInstruction[]; }>; getWithdrawCollateralAmount(reserve: KaminoReserve, amount: BN): BN; getObligationPda(): PublicKey; isObligationInitialized(): boolean; getAdditionalDepositReservesList(): PublicKey[]; private static getReferrerKey; getUserTokenAccountAddress(reserve: KaminoReserve): PublicKey; getTokenAccountAddressByUser(reserve: KaminoReserve, user: PublicKey): PublicKey; getUserCollateralAccountAddress(reserve: KaminoReserve): PublicKey; static actionToIxs(action: KaminoAction): Array<TransactionInstruction>; static actionToLendingIxs(action: KaminoAction): Array<TransactionInstruction>; static actionToIxLabels(action: KaminoAction): Array<string>; static actionToLendingIxLabels(action: KaminoAction): Array<string>; } //# sourceMappingURL=action.d.ts.map