import { Address, AccountMeta, Instruction, Option, Slot, TransactionSigner } from '@solana/kit';
import BN from 'bn.js';
import { ObligationType, ScopePriceRefreshConfig } from '../utils';
import { KaminoBorrowOrder } from './borrowOrder';
import { KaminoMarket } from './market';
import { KaminoObligation } from './obligation';
import { KaminoReserve } from './reserve';
import { ProgressCallbackType } from '../@codegen/klend/types';
import { Scope } from '@kamino-finance/scope-sdk';
import { ObligationOrderAtIndex } from './obligationOrder';
import { BuildDepositTxnsProps, BuildBorrowTxnsProps, BuildBorrowRolloverConfigIxsProps, BuildDepositReserveLiquidityTxnsProps, BuildRedeemReserveCollateralTxnsProps, BuildWithdrawTxnsProps, BuildWithdrawFromObligationAndEnqueueTxnsProps, BuildRepayTxnsProps, BuildDepositAndBorrowTxnsProps, BuildRefreshObligationTxnsProps, BuildRolloverFixedTermBorrowTxnsProps, BuildRequestElevationGroupTxnsProps, BuildDepositAndWithdrawV2TxnsProps, BuildRepayAndWithdrawTxnsProps, BuildRepayAndWithdrawV2TxnsProps, BuildLiquidateTxnsProps, BuildWithdrawReferrerFeeTxnsProps, BuildDepositObligationCollateralTxnsProps, BuildDepositAndSetBorrowOrderTxnsProps, BuildDepositAndFillBorrowOrderTxnsProps, InitializeActionProps } from './actionTypes';
export type ActionType = 'deposit' | 'borrow' | 'withdraw' | 'repay' | 'mint' | 'redeem' | 'depositCollateral' | 'liquidate' | 'depositAndBorrow' | 'repayAndWithdraw' | 'refreshObligation' | 'requestElevationGroup' | 'withdrawReferrerFees' | 'repayAndWithdrawV2' | 'depositAndWithdraw' | 'withdrawAndEnqueue' | 'setBorrowOrder' | 'fillBorrowOrder';
export type AuxiliaryIx = 'setup' | 'inBetween' | 'cleanup';
type InitUserMetadataConfig = {
skipInitialization: boolean;
skipLutCreation: boolean;
};
interface AddSupportIxsOptions {
action: ActionType;
includeAtaIxs: boolean;
requestElevationGroup?: boolean;
addInitObligationForFarm?: boolean;
useV2Ixs: boolean;
scopeRefreshConfig: ScopePriceRefreshConfig | undefined;
initUserMetadata: InitUserMetadataConfig;
twoTokenAction?: boolean;
overrideElevationGroupRequest?: number;
addUserAndObligationInitIxs?: boolean;
}
export declare class KaminoAction {
kaminoMarket: KaminoMarket;
reserve: KaminoReserve;
outflowReserve: KaminoReserve | undefined;
owner: TransactionSigner;
payer: TransactionSigner;
obligation: KaminoObligation | ObligationType;
referrer: Option
;
/**
* Null unless the obligation is not passed
*/
obligationType: ObligationType | null;
mint: Address;
secondaryMint?: Address;
positions?: number;
amount: BN;
outflowAmount?: BN;
computeBudgetIxs: Array;
computeBudgetIxsLabels: Array;
setupIxs: Array;
setupIxsLabels: Array;
luts: Array;
inBetweenIxs: Array;
inBetweenIxsLabels: Array;
lendingIxs: Array;
lendingIxsLabels: Array;
postLendingIxs: Array;
postLendingIxsLabels: Array;
cleanupIxs: Array;
cleanupIxsLabels: Array;
refreshFarmsCleanupTxnIxs: Array;
refreshFarmsCleanupTxnIxsLabels: Array;
depositReserves: Array;
borrowReserves: Array;
preLoadedDepositReservesSameTx: Array;
currentSlot: Slot;
permissionAuthority?: TransactionSigner;
private constructor();
private appendLendingIx;
static initialize(props: InitializeActionProps): Promise;
private static getUserAccountAddresses;
private static loadObligation;
static buildRefreshObligationTxns(props: BuildRefreshObligationTxnsProps): Promise;
static buildRequestElevationGroupTxns(props: BuildRequestElevationGroupTxnsProps): Promise;
static buildDepositTxns(props: BuildDepositTxnsProps): Promise;
private static buildDepositTxnsInternal;
static buildDepositAndSetBorrowOrderTxns(props: BuildDepositAndSetBorrowOrderTxnsProps): Promise;
/**
* Builds a transaction that rolls an existing borrow over from one reserve into another (the
* `rolloverFixedTermBorrow` instruction). The target reserve may be fixed-term or variable/open-term.
* The program requires a single signer (the `payer`) but not specifically the obligation owner, so the
* transaction can be signed by the owner directly or cranked by a keeper.
*
* The returned action includes the setup refresh/farm-init instructions and the rollover instruction.
* The program enforces several additional rollover preconditions at execution time (shared liquidity
* mint, rollover config opt-in, matching borrow factor, target rate/term limits, the market's rollover
* execution window, etc.) that this method does not pre-validate; a violation fails the transaction.
* Rollover is configured on the borrow via {@link KaminoAction.buildBorrowRolloverConfigIxs}.
*/
static buildRolloverFixedTermBorrowTxns(props: BuildRolloverFixedTermBorrowTxnsProps): Promise;
/**
* Emits the setup instructions for a rollover: refreshes every reserve the obligation touches (plus the
* source and target), then refreshes the obligation. No farm-refresh instructions are emitted - the
* `rolloverFixedTermBorrow` handler refreshes the source and target debt farms internally. The source's
* and target's debt obligation farm-user-states are initialized first if missing, since that internal
* refresh loads them and fails if absent (the source's usually already exists from its borrow, but not
* guaranteed if its debt farm was added later); both inits are idempotent no-ops when already present.
*
* When a {@link ScopePriceRefreshConfig} is provided, the Scope price refresh is prepended so the reserve
* refreshes below (which read the Scope feed) succeed for Scope-priced reserves.
*/
private addRolloverFixedTermBorrowSupportIxs;
/**
* Appends the `rolloverFixedTermBorrow` instruction, resolving the source/target reserve vaults and
* their debt-farm accounts (the on-chain handler refreshes debt farms only).
*/
private addRolloverFixedTermBorrowIx;
addScopeRefreshIxs(scope: Scope, tokens: number[], scopeConfig: Address): Promise;
/**
* Add the opt-in borrow support instructions used when creating and filling a borrow order from vaults.
* These setup instructions mirror the borrow builder's user-metadata initialization, elevation switching,
* and Scope refresh flow for an existing obligation.
*/
addBorrowOrderSupportIxs(scopeRefreshConfig: ScopePriceRefreshConfig | undefined, initUserMetadata?: {
skipInitialization: boolean;
skipLutCreation: boolean;
}, requestElevationGroup?: boolean, overrideElevationGroupRequest?: number): Promise;
static buildBorrowTxns(props: BuildBorrowTxnsProps): Promise;
static buildDepositReserveLiquidityTxns(props: BuildDepositReserveLiquidityTxnsProps): Promise;
static buildRedeemReserveCollateralTxns(props: BuildRedeemReserveCollateralTxnsProps): Promise;
static buildDepositObligationCollateralTxns(props: BuildDepositObligationCollateralTxnsProps): Promise;
static buildDepositAndBorrowTxns(props: BuildDepositAndBorrowTxnsProps): Promise;
static buildDepositAndWithdrawV2Txns(props: BuildDepositAndWithdrawV2TxnsProps): Promise;
static buildRepayAndWithdrawV2Txns(props: BuildRepayAndWithdrawV2TxnsProps): Promise;
static buildRepayAndWithdrawTxns(props: BuildRepayAndWithdrawTxnsProps): Promise;
static buildWithdrawTxns(props: BuildWithdrawTxnsProps): Promise;
static buildWithdrawFromObligationAndEnqueueTxns(props: BuildWithdrawFromObligationAndEnqueueTxnsProps): Promise;
/**
* Build repay transactions
* @param props - BuildRepayTxnsProps containing all required and optional parameters
*/
static buildRepayTxns(props: BuildRepayTxnsProps): Promise;
static buildLiquidateTxns(props: BuildLiquidateTxnsProps): Promise;
static buildWithdrawReferrerFeeTxns(props: BuildWithdrawReferrerFeeTxnsProps): Promise;
/**
* 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(owner: TransactionSigner, kaminoMarket: KaminoMarket, obligation: KaminoObligation, orderAtIndex: ObligationOrderAtIndex): Instruction;
/**
* Builds an instruction for the current obligation owner to initiate an ownership transfer
* to a new owner. Once this instruction succeeds, the obligation is locked for user-facing
* operations until the transfer is approved by the global admin and accepted by the new owner
* (or aborted by the current owner).
*
* Four-step flow:
* 1. Current owner calls this (buildInitiateObligationOwnershipTransferIxn)
* 2. Global admin calls buildApproveObligationOwnershipTransferIxn
* 3. New owner calls buildAcceptObligationOwnershipIxn
*
* Between steps 1 and 2 the current owner can also call
* {@link buildAbortObligationOwnershipTransferIxn} to cancel.
*/
static buildInitiateObligationOwnershipTransferIxn(owner: TransactionSigner, kaminoMarket: KaminoMarket, obligation: KaminoObligation, newOwner: Address): Instruction;
/**
* Builds an instruction for the global admin to approve a pending obligation ownership transfer.
* Must be called after {@link buildInitiateObligationOwnershipTransferIxn} and before
* {@link buildAcceptObligationOwnershipIxn}.
*
* `pendingOwner` must match the pending owner set on the obligation; if omitted it is read from
* {@link KaminoObligation.state.pendingOwner}.
*/
static buildApproveObligationOwnershipTransferIxn(globalAdmin: TransactionSigner, kaminoMarket: KaminoMarket, obligation: KaminoObligation, pendingOwner?: Address): Promise;
/**
* Builds an instruction for the pending owner (set via
* {@link buildInitiateObligationOwnershipTransferIxn} and approved via
* {@link buildApproveObligationOwnershipTransferIxn}) to accept and finalize the ownership transfer.
*/
static buildAcceptObligationOwnershipIxn(pendingOwner: TransactionSigner, kaminoMarket: KaminoMarket, obligation: KaminoObligation): Instruction;
/**
* Builds an instruction for the current obligation owner to abort an in-progress ownership
* transfer. Valid only while the transfer is in the Initiated state (i.e. has not yet been
* approved by the global admin).
*/
static buildAbortObligationOwnershipTransferIxn(owner: TransactionSigner, kaminoMarket: KaminoMarket, obligation: KaminoObligation): Instruction;
/**
* Builds an instruction for enqueueing a withdrawal request to the withdraw queue.
* This is used when there isn't enough liquidity to immediately withdraw.
*/
static buildEnqueueToWithdrawIx(owner: TransactionSigner, kaminoMarket: KaminoMarket, reserve: KaminoReserve, collateralAmount: BN, userDestinationLiquidityTa: Address, progressCallbackType?: ProgressCallbackType.None | ProgressCallbackType.KlendQueueAccountingHandlerOnKvault, progressCallbackCustomAccount0?: Option, progressCallbackCustomAccount1?: Option): Promise;
/**
* Builds an instruction for withdrawing queued liquidity (permissionless).
* This allows anyone to process a withdraw ticket when liquidity becomes available.
*/
static buildWithdrawQueuedLiquidityIx(payer: TransactionSigner, kaminoMarket: KaminoMarket, reserve: KaminoReserve, withdrawTicket: Address, withdrawTicketOwner: Address, userDestinationLiquidity: Address, progressCallbackProgram?: Option, progressCallbackCustomAccount0?: Option, progressCallbackCustomAccount1?: Option): Promise;
/**
* Builds instructions for setting a borrow order on an obligation.
* Includes an idempotent ATA creation for the filled debt destination when setting an order.
*
* @param owner - the obligation owner and signer for the instruction
* @param kaminoMarket - the lending market that owns the obligation
* @param obligation - the obligation to attach the borrow order to
* @param borrowOrder - the order to set, or null to cancel the existing order
* @param orderIdx - which of the obligation's borrow orders to write
* @param minExpectedCurrentRemainingDebtAmount - minimum expected remaining debt amount
*/
static buildSetBorrowOrderIxs(owner: TransactionSigner, kaminoMarket: KaminoMarket, obligation: KaminoObligation | Address, borrowOrder: KaminoBorrowOrder | null, orderIdx: number, minExpectedCurrentRemainingDebtAmount?: BN): Promise;
/**
* Builds an instruction for filling a borrow order on an obligation.
* This allows lenders to provide liquidity for fixed-term loan requests.
* @param payer - the signer paying for the transaction
* @param kaminoMarket - the lending market that owns the obligation
* @param obligation - the obligation that holds the borrow order
* @param reserve - the reserve that provides the borrow liquidity
* @param currentTimestamp - current unix time in seconds, used to resolve which order is still fillable
* @param orderIdx - which of the obligation's borrow orders to fill; omit to fill its only fillable one
*/
static buildFillBorrowOrderIx(payer: TransactionSigner, kaminoMarket: KaminoMarket, obligation: KaminoObligation, reserve: KaminoReserve, currentTimestamp: number, orderIdx?: number): Promise;
/**
* Builds a lender flow that deposits liquidity into the reserve matching a borrower's borrow order and fills
* that order in the same flow. The lender deposit is recorded as lender obligation collateral, not as cTokens
* in the lender's wallet. The fill reserve is selected from the order's debt mint among the
* reserves that can fill the order on-chain (the term + rate gates of
* {@link KaminoObligation.getCompatibleBorrowOrderFillReserves}); a fixed-term order is restricted to
* fixed/maturity-term reserves (never an open-term float reserve). Among those, it picks the lender-favorable
* one: the highest peak borrow rate, tie-broken by the shortest remaining term (the shortest active cap among
* configured term and/or seconds until maturity). It throws if no reserve can fill the order. By default the
* lender deposits exactly enough to fully fill the order (its
* remaining debt plus the borrow origination/referrer fees); pass `amount` to deposit a specific amount
* instead - a smaller amount may partially fill the order (subject to the order's on-chain min-fill and
* min-remainder constraints), a larger one fully fills it and leaves the excess as lender obligation collateral.
*
* The borrower's obligation is expected to hold an active borrow order. When the flow requires accounts that can
* be initialized before the main deposit/fill transaction - lender metadata, the lender obligation, lender
* collateral farm state, borrower debt farm state, or the referrer's token state for the fill reserve - the
* result returns those setup instructions separately in `preFillSetupIxs`. Send them before the main `action`
* when the array is non-empty. This means the lender may pay rent for borrower-side accounts, and that rent is
* not reclaimable.
*
* @returns the composed {@link KaminoAction} together with the chosen fill reserve and the deposited amount.
*/
static buildDepositAndFillBorrowOrderTxns(props: BuildDepositAndFillBorrowOrderTxnsProps): Promise;
addDepositReserveLiquidityIx(): Promise;
addRedeemReserveCollateralIx(): Promise;
addDepositIx(): Promise;
addDepositIxV2(): Promise;
addDepositObligationCollateralIx(): Promise;
addDepositObligationCollateralIxV2(): Promise;
addBorrowIx(): Promise;
addBorrowIxV2(): Promise;
/**
* Creates the instructions to configure rollover settings for fixed-rate borrows: 4, plus one more when
* {@link BuildBorrowRolloverConfigIxsProps.fixedTermRolloverWindowDurationDays} is given.
*
* @param props - BuildBorrowRolloverConfigIxsProps containing all required parameters
* @returns Array of update obligation config instructions
*/
static buildBorrowRolloverConfigIxs(props: BuildBorrowRolloverConfigIxsProps): Instruction[];
private addBorrowRolloverConfigIxs;
addWithdrawIx(collateralAmount: BN): Promise;
addWithdrawIxV2(collateralAmount: BN): Promise;
addWithdrawObligationCollateralIxV2(collateralAmount: BN): Promise;
addRepayIx(): Promise;
addRepayIxV2(): Promise;
addRepayAndWithdrawV2Ixs(withdrawCollateralAmount: BN): Promise;
addDepositAndWithdrawV2Ixs(withdrawCollateralAmount: BN): Promise;
addDepositAndBorrowIx(): Promise;
addDepositAndBorrowIxV2(): Promise;
addRepayAndWithdrawIxs(withdrawCollateralAmount: BN): Promise;
addRepayAndWithdrawIxsV2(withdrawCollateralAmount: BN): Promise;
addLiquidateIx(maxAllowedLtvOverridePercent?: number): Promise;
addLiquidateIxV2(maxAllowedLtvOverridePercent?: number): Promise;
addInBetweenIxs(action: ActionType, includeAtaIxs: boolean, requestElevationGroup: boolean, addInitObligationForFarm: boolean, useV2Ixs: boolean, overrideElevationGroupRequest?: number): Promise;
addRefreshObligation(crank: TransactionSigner): Promise;
addSupportIxsWithoutInitObligation(action: ActionType, includeAtaIxs: boolean, useV2Ixs: boolean, addAsSupportIx?: AuxiliaryIx, requestElevationGroup?: boolean, addInitObligationForFarm?: boolean, twoTokenAction?: boolean, overrideElevationGroupRequest?: number): Promise;
addSupportIxs({ action, includeAtaIxs, requestElevationGroup, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, initUserMetadata, twoTokenAction, overrideElevationGroupRequest, addUserAndObligationInitIxs, }: AddSupportIxsOptions): Promise;
private getSupportScopeRefreshReserves;
private addSupportScopeRefreshIxs;
private static emptyInstructionBundle;
private static appendInstructionBundle;
private static combineInstructionBundles;
private appendInstructionBundle;
private maybeAddUserMetadataIxs;
private static buildUserMetadataSetupIxs;
private addBorrowElevationSupportIxs;
private getBorrowElevationGroupRequest;
private getPreferredElevationGroupForBorrowPair;
private static optionalAccount;
private addRefreshReserveIxs;
static getRefreshAllReserves(kaminoMarket: KaminoMarket, reserves: Address[]): Instruction[];
private addRefreshObligationIx;
private addRequestElevationIx;
private addRefreshFarmsForReserve;
private addRefreshFarmsCleanupTxnIxsToCleanupIxs;
private addInitObligationForFarm;
/**
* Appends already-built init-obligation-for-farm instructions (from {@link buildInitObligationForFarmIxs}) to
* the requested support instruction list. Callers that build several reserves' ixs concurrently use this to
* append them in a deterministic order afterwards.
*/
private pushInitObligationForFarmIxs;
/**
* Builds the `initObligationFarmsForReserve` instruction(s) needed for this reserve's farm of the given kind,
* without mutating the action. Returns an entry only when the reserve has that farm and the obligation's
* farm-user-state does not yet exist. This lets callers fetch existence checks concurrently and then append the
* resulting ixs in a deterministic order via {@link pushInitObligationForFarmIxs}.
*/
private buildInitObligationForFarmIxs;
private static buildInitObligationFarmForReserveSetupIxs;
private addInitObligationIxs;
private static buildInitObligationSetupIxs;
private static buildDepositOwnerPreActionSetupIxs;
private static buildDepositAndFillBorrowOrderSetupIxs;
private static buildReferrerTokenStateSetupIxs;
private addInitReferrerTokenStateIx;
private addWithdrawReferrerFeesIxs;
private addComputeBudgetIx;
private addAtaIxs;
private updateWSOLAccount;
static initializeMultiTokenAction(kaminoMarket: KaminoMarket, action: ActionType, inflowAmount: string | BN, inflowReserveAddress: Address, outflowReserveAddress: Address, signer: TransactionSigner, obligationOwner: Address, obligation: KaminoObligation | ObligationType, outflowAmount: string | BN | undefined, referrer: Option, currentSlot: Slot, permissionAuthority?: TransactionSigner): Promise;
static initializeWithdrawReferrerFees(reserveAddress: Address, owner: TransactionSigner, kaminoMarket: KaminoMarket, currentSlot: Slot): Promise<{
axn: KaminoAction;
createAtaIxs: Instruction | import("@solana/kit").AccountLookupMeta)[]>[];
}>;
getWithdrawCollateralAmount(reserve: KaminoReserve, amount: BN): BN;
getObligationPda(): Promise;
isObligationInitialized(): boolean;
getAdditionalDepositReservesList(): Address[];
private static getReferrerMetadataAccount;
private getReferrerTokenStateAccountMeta;
private getReferrerTokenStateAddress;
getUserTokenAccountAddress(reserve: KaminoReserve): Promise;
getTokenAccountAddressByUser(reserve: KaminoReserve, user: Address): Promise;
getUserCollateralAccountAddress(reserve: KaminoReserve): Promise;
static actionToIxs(action: KaminoAction): Array;
static actionToLendingIxs(action: KaminoAction): Array;
static actionToIxLabels(action: KaminoAction): Array;
static actionToLendingIxLabels(action: KaminoAction): Array;
private static getFarmAccountsForReserve;
private static getReferrerKey;
private static getReferrerTokenStateAddressImpl;
}
/**
* Result of {@link KaminoAction.buildDepositAndFillBorrowOrderTxns}.
*/
export interface DepositAndFillBorrowOrderResult {
/**
* Setup instructions that must be sent before `action` when non-empty. These create accounts that are safe to
* initialize before the main deposit/fill transaction, such as lender user metadata, the lender obligation,
* lender collateral farm state, borrower debt farm state, or referrer token state.
*/
preFillSetupIxs: Instruction[];
/**
* Labels for `preFillSetupIxs`.
*/
preFillSetupIxsLabels: string[];
/**
* Lookup table addresses created by `preFillSetupIxs`.
*/
preFillSetupLuts: Address[];
/**
* The composed main action: the lender deposit, reserve refreshes, borrower-obligation refresh, and fill. Send
* `preFillSetupIxs` first when they are non-empty.
*/
action: KaminoAction;
/**
* The reserve selected for the fill: among the order's debt-mint reserves that can fill it on-chain (a
* fixed-term order excludes open-term float reserves), the lender-favorable one - highest peak borrow rate,
* tie-broken by shortest remaining term.
*/
fillReserve: KaminoReserve;
/**
* The liquidity amount the lender deposits: the `amount` prop when provided, otherwise exactly enough to fully
* fill the order (its remaining debt plus the borrow origination/referrer fees).
*/
depositedAmount: BN;
}
export {};
//# sourceMappingURL=action.d.ts.map