import Decimal from 'decimal.js'; import { KaminoMarket, KaminoObligation, KaminoReserve } from '../classes'; import { Address, Option, Slot } from '@solana/kit'; import { LedgerInstant } from '../utils/ledger'; export declare enum MaxWithdrawLtvCheck { MAX_LTV = 0, LIQUIDATION_THRESHOLD = 1 } export declare function calcRepayAmountWithSlippage(kaminoMarket: KaminoMarket, debtReserve: KaminoReserve, currentSlotOrLedgerInstant: Slot | LedgerInstant, obligation: KaminoObligation, amount: Decimal, referrer: Option
, currentLedgerInstant?: LedgerInstant): { repayAmount: Decimal; /** The repay principal (debt lamports). This is the `liquidity_amount` of the on-chain repay instruction. */ repayAmountLamports: Decimal; /** * Fixed-term early-repay penalty (debt lamports) charged on-chain *in addition* to the repay * (`lending_operations.rs:766`). Zero for open-term reserves / matured / untracked borrows. It is NOT part of the * repay-instruction amount — it only inflates the debt that must be made available (flash-borrowed or swapped for). */ earlyRepayPenaltyLamports: Decimal; /** Debt that must be made available to the repay step = principal + penalty. */ repayFundingLamports: Decimal; flashRepayAmountLamports: Decimal; }; /** * Single source of truth for the SC flash-loan-fee debit, in the lamport domain. * * Mirrors the on-chain flash repay (`handler_flash_repay_reserve_liquidity` / `lending_operations::flash_repay`): * the borrower must hold `flashBorrow + protocolFee + referrerFee` in the destination ATA when the flash-repay * instruction runs — the repay instruction's `liquidity_amount` is the bare borrow principal, and the SC adds the fee * on top. The fee is `reserve.calculateFlashLoanFees` (exclusive: `max(flashBorrow × rate, 1)` when the rate is > 0, * split into protocol/referrer). Use this everywhere instead of hand-rolling `mul(1 + flashLoanFee)`, which both * misses the 1-lamport minimum and silently drops the referrer split. * * @param flashBorrowAmountLamports the flash-borrow principal (integer lamports — ceil at the call site first). * @returns the protocol/referrer fee split and `flashRepayDebitLamports = flashBorrow + protocolFee + referrerFee`. */ export declare const calcFlashLoanFees: (props: { reserve: KaminoReserve; referralFeeBps: number; hasReferral: boolean; flashBorrowAmountLamports: Decimal; }) => { protocolFeeLamports: Decimal; referrerFeeLamports: Decimal; flashLoanFeeLamports: Decimal; flashRepayDebitLamports: Decimal; }; export declare const calcFlashRepayAmount: (props: { reserve: KaminoReserve; referralFeeBps: number; hasReferral: boolean; flashBorrowAmountLamports: Decimal; }) => { flashRepayAmountLamports: Decimal; }; export declare function calcMaxWithdrawCollateral(market: KaminoMarket, obligation: KaminoObligation, collReserveAddr: Address, debtReserveAddr: Address, repayAmountLamports: Decimal): { maxWithdrawableCollLamports: Decimal; canWithdrawAllColl: boolean; repayingAllDebt: boolean; }; export declare function estimateDebtRepaymentWithColl(props: { collAmount: Decimal; priceDebtToColl: Decimal; slippagePct: Decimal; flashLoanFeePct: Decimal; kaminoMarket: KaminoMarket; debtReserveAddress: Address; obligation: KaminoObligation; currentSlot: Slot; }): Decimal; /** * Calculates the coll-flash sizing for repay-with-collateral: * 1. Flash borrow `flashBorrowInCollLamports` of collateral. * 2. Swap that coll → debt; produces at least `repayAmountLamports` of debt after slippage. * 3. Repay the obligation debt with the swapped output. * 4. Withdraw `collWithdrawForFlashRepayLamports` (= flashBorrow + `calcFlashLoanFees` debit) of coll. * 5. Flash repay coll with the withdrawn amount. * * @returns the lamport-denominated sizing values for the coll-flash repay-with-coll path. * @throws if `swapPriceCollToDebt` is not finite and strictly positive. */ export declare function calcRepayWithCollCollFlashSwap(props: { repayAmountLamports: Decimal; swapPriceCollToDebt: Decimal; slippagePct: Decimal; collReserve: KaminoReserve; debtMintFactor: Decimal; }): { flashBorrowInCollLamports: Decimal; collSwapInLamports: Decimal; debtMinOutLamports: Decimal; collWithdrawForFlashRepayLamports: Decimal; }; export declare function validateCollFlashWithdrawCap(props: { collWithdrawLamports: Decimal; maxCollateralWithdrawLamports: Decimal; }): void; export declare function estimateCollNeededForDebtRepayment(props: { debtAmount: Decimal; priceDebtToColl: Decimal; slippagePct: Decimal; flashLoanFeePct: Decimal; }): Decimal; export declare const getMaxWithdrawLtvCheck: (obligation: KaminoObligation, repayAmountLamports: Decimal, debtReserve: KaminoReserve, collWithdrawAmount: Decimal, collReserve: KaminoReserve) => MaxWithdrawLtvCheck; export declare function getMaxCollateralFromRepayAmount(repayAmount: Decimal, debtReserve: KaminoReserve, collReserve: KaminoReserve): Decimal; //# sourceMappingURL=repay_with_collateral_calcs.d.ts.map