import { KaminoMarket, KaminoObligation } from '../classes'; import { FlashBorrowType, FlashLoanInfo, SwapInputs, SwapIxsProvider, SwapQuote, SwapQuoteProvider } from '../leverage/types'; import { KlendAccountsResult } from '../utils'; import { AddressLookupTable } from '@solana-program/address-lookup-table'; import { Account, Address, Instruction, Option, Slot, TransactionSigner } from '@solana/kit'; import Decimal from 'decimal.js'; import { DistributiveOmit, LedgerInstant, LedgerInstantCompatible } from '../utils/ledger'; export type RepayWithCollIxsResponse = { ixs: Instruction[]; lookupTables: Account[]; flashLoanInfo: FlashLoanInfo; swapInputs: SwapInputs; initialInputs: RepayWithCollInitialInputs; quote?: QuoteResponse; }; interface RepayWithCollInitialInputsCommon { /** Debt-token-denominated amount being repaid to the obligation (the on-chain repay `liquidity_amount`, principal only). */ debtRepayAmountLamports: Decimal; /** * Fixed-term early-repay penalty (debt lamports) charged on-chain in addition to the repay. Zero for open-term / * matured / untracked borrows. Surfaced for clients; additive funding only, NOT part of the repay instruction amount. */ earlyRepayPenaltyLamports: Decimal; /** Debt that must be made available to the repay step = `debtRepayAmountLamports` + `earlyRepayPenaltyLamports`. */ debtFundingLamports: Decimal; /** * Flash-loan repay amount in the lamports of the FLASH-BORROWED reserve. * - debt-flash: debt lamports = `debtRepayAmountLamports` + flash fee. * - coll-flash: coll lamports = `collSwapInLamports * (1 + collFlashLoanFee)`. * Use the `flashBorrowType` discriminant on the parent type to know which denomination. */ flashRepayAmountLamports: Decimal; /** * The amount of collateral available to withdraw, if this is less than the swap input amount, then the swap may fail due to slippage, or tokens may be debited from the user's ATA, so the caller needs to check this */ maxCollateralWithdrawLamports: Decimal; /** * The quote from the provided quoter */ swapQuote: SwapQuote; /** Current slot retained for source compatibility. */ currentSlot: Slot; /** Matching slot + block time used consistently for interest and term calculations. */ currentLedgerInstant?: LedgerInstant; klendAccounts: Array
; } export interface DebtFlashRepayWithCollInitialInputs extends RepayWithCollInitialInputsCommon { flashBorrowType: 'debt'; } export interface CollFlashRepayWithCollInitialInputs extends RepayWithCollInitialInputsCommon { flashBorrowType: 'coll'; } export type RepayWithCollInitialInputs = DebtFlashRepayWithCollInitialInputs | CollFlashRepayWithCollInitialInputs; export interface RepayWithCollSwapInputsProps { kaminoMarket: KaminoMarket; debtReserveAddress: Address; collReserveAddress: Address; owner: TransactionSigner; obligation: KaminoObligation; referrer: Option
; currentSlot: Slot; currentLedgerInstant?: LedgerInstant; repayAmount: Decimal; isClosingPosition: boolean; budgetAndPriorityFeeIxs?: Instruction[]; scopeRefreshIx: Instruction[]; useV2Ixs: boolean; quoter: SwapQuoteProvider; /** * The user's max-acceptable swap slippage, expressed as a percent (e.g. `0.5` for 0.5%). * * Contract: callers pass a SIMULATED (mid) `priceAInB` from the quoter — the SDK applies this * value as the sizing buffer when computing the flash-borrow / swap-input lamports, so the * worst-case real fill still satisfies the on-chain repay / flash-repay constraint. Conceptually * a separate knob from the on-chain swap `min_out` (which the swapper sets); in the future this * could be a smaller, capped value. */ slippagePct: Decimal; /** * Which side to flash borrow on: * - `'debt'` (default): flash borrow debt → repay+withdraw → swap coll→debt → flash repay debt. * - `'coll'`: flash borrow coll → swap coll→debt → repay+withdraw → flash repay coll. * Useful when the default reserve has flash loans disabled or insufficient liquidity. */ flashBorrowType?: FlashBorrowType; } export type RepayWithCollSwapInputsParams = LedgerInstantCompatible>; /** * Inputs for {@link getRepayWithCollKlendAccounts}: the subset of {@link getRepayWithCollSwapInputs}'s props that * the klend account footprint depends on. Derived from {@link RepayWithCollSwapInputsProps} (so the two never drift) * by dropping only the fields account discovery does not use: the quoter and the slippage. Unlike the swap-coll / * swap-debt families, `flashBorrowType` is KEPT, because the two repay routes flash-borrow different reserves * (debt vs coll) and so reference a different reserve fee-vault — the account set is NOT invariant to the side. */ export type RepayWithCollKlendAccountsInputs = DistributiveOmit, 'quoter' | 'slippagePct'>; /** * Light helper: returns the exact, final set of klend accounts (and program ids) a repay-with-collateral operation * with the same inputs would consume, plus their count, WITHOUT calling the quoter/swapper. This is the same set the * operation passes to the quoter (invariant to the swap amounts), so the count is accurate and final — the FE can use * it to know how many accounts remain for the external swap. Pass the same `flashBorrowType` the operation will use: * the debt-flash and coll-flash routes flash different reserves and so reference a different fee vault. */ export declare function getRepayWithCollKlendAccounts(inputs: RepayWithCollKlendAccountsInputs): Promise; export declare function getRepayWithCollSwapInputs({ collReserveAddress, currentSlot: suppliedCurrentSlot, currentLedgerInstant, debtReserveAddress, kaminoMarket, owner, obligation, quoter, referrer, repayAmount, isClosingPosition, budgetAndPriorityFeeIxs, scopeRefreshIx, useV2Ixs, slippagePct, flashBorrowType, }: RepayWithCollSwapInputsParams): Promise<{ swapInputs: SwapInputs; flashLoanInfo: FlashLoanInfo; initialInputs: RepayWithCollInitialInputs; }>; type RepayWithCollIxsProps = RepayWithCollSwapInputsParams & { swapper: SwapIxsProvider; logger?: (msg: string, ...extra: any[]) => void; }; export declare function getRepayWithCollIxs({ repayAmount, isClosingPosition, budgetAndPriorityFeeIxs, collReserveAddress, currentSlot: suppliedCurrentSlot, currentLedgerInstant, debtReserveAddress, kaminoMarket, owner, obligation, quoter, swapper, referrer, scopeRefreshIx, useV2Ixs, slippagePct, flashBorrowType, logger, }: RepayWithCollIxsProps): Promise>>; export {}; //# sourceMappingURL=repay_with_collateral_operations.d.ts.map