import type { Address, Option } from '@solana/kit'; import Decimal from 'decimal.js'; import { type KaminoMarket, type KaminoObligation } from '../classes'; import type { FlashBorrowType } from './types'; import type { LedgerInstant } from '../utils/ledger'; /** * Intent-level helpers that pick a viable `FlashBorrowType` for each leverage operation. * * Callers provide only the intent (amounts, target leverage, price); the SDK computes the * required-lamport size for each candidate flash side — AND the collateral redeemed in the same tx * for ops that have a redeem leg — then runs the `determineFlashBorrowType` viability check (flash * loans enabled + the reserve covers flash-borrow + redeem). Coll-flash is preferred when it is * genuinely viable; otherwise it falls back to debt-flash. * * Each helper throws with a diagnostic message if neither side is viable. */ /** * Picks a viable `FlashBorrowType` for a leveraged DEPOSIT (open / scale-into position). * * - debt-flash flash-borrows the loan-side; coll-flash flash-borrows the collateral side. * - Sizes are derived from `depositLeverageCalcs` (coll-flash) and `depositLeverageCalcsDebtFlash` * (debt-flash), both at the requested target leverage and the provided price. * - `selectedTokenMint` follows the operation's "I'm paying X with this token" convention. * * @throws if neither side is viable. */ export declare function determineDepositLeverageFlashBorrowType(props: { kaminoMarket: KaminoMarket; collReserveAddress: Address; debtReserveAddress: Address; /** Amount the user is depositing, in `selectedTokenMint` decimals (NOT lamports). */ depositAmount: Decimal; /** Which token the user is paying with — must equal coll mint or debt mint (or SOL). */ selectedTokenMint: Address; targetLeverage: Decimal; /** Price expressed as coll-per-debt, i.e. 1 unit of debt = `priceDebtToColl` units of coll. */ priceDebtToColl: Decimal; /** Swap slippage tolerance, percent (e.g. 0.5 = 0.5%). */ slippagePct: Decimal; }): FlashBorrowType; /** * Picks a viable `FlashBorrowType` for a leveraged WITHDRAW (partial unwind or close-position). * * - debt-flash flash-borrows the repay amount in debt lamports. * - coll-flash flash-borrows the swap-in amount in coll lamports AND redeems collateral from the * same reserve in the same tx, so coll-flash viability accounts for both legs (flash + redeem). * - Sizes come from `withdrawLeverageCalcs` and `withdrawLeverageCalcsCollFlash`. * * @throws if neither side is viable. */ export declare function determineWithdrawLeverageFlashBorrowType(props: { kaminoMarket: KaminoMarket; obligation: KaminoObligation; collReserveAddress: Address; debtReserveAddress: Address; /** Withdraw amount in selectedToken decimals — ignored when `isClosingPosition=true`. */ withdrawAmount: Decimal; /** Which token the user wants back — must equal coll mint or debt mint. */ selectedTokenMint: Address; isClosingPosition: boolean; /** Price expressed as debt-per-coll. */ priceCollToDebt: Decimal; /** Current obligation deposit (coll lamports decimal). Defaults to obligation's coll position. */ depositedLamports?: Decimal; /** Current obligation borrow (debt lamports decimal). Defaults to obligation's debt position. */ borrowedLamports?: Decimal; slippagePct: Decimal; /** The ledger instant (slot + block time) the repay sizing is estimated at. */ currentLedgerInstant: LedgerInstant; }): FlashBorrowType; /** * Picks a viable `FlashBorrowType` for a leveraged ADJUST (increase or decrease). * * Auto-detects increase vs decrease from the sign of the position deltas returned by * `calcAdjustAmounts`: * - increase (current < target): coll-flash borrows `adjustDepositPosition` coll lamports, * debt-flash borrows `flashBorrowInDebtToken` debt lamports; deposits collateral, so no redeem; * - decrease (current > target): debt-flash borrows |`adjustBorrowPosition`| debt lamports, * coll-flash borrows `flashBorrowInCollToken` coll lamports AND withdraws * `depositTokenWithdrawAmount` coll from the same reserve to repay the flash loan — a redeem leg * the coll-flash viability check accounts for (thin reserve: flash + redeem can self-collide). * * @throws if neither side is viable, or if `targetLeverage` equals the current leverage exactly * (nothing to adjust — caller should skip the op). */ export declare function determineAdjustLeverageFlashBorrowType(props: { kaminoMarket: KaminoMarket; obligation: KaminoObligation; collReserveAddress: Address; debtReserveAddress: Address; targetLeverage: Decimal; /** Price expressed as debt-per-coll. */ priceCollToDebt: Decimal; /** Price expressed as coll-per-debt. */ priceDebtToColl: Decimal; slippagePct: Decimal; /** The ledger instant (slot + block time) the repay sizing is estimated at. */ currentLedgerInstant: LedgerInstant; }): FlashBorrowType; /** * Picks a viable `FlashBorrowType` for a repay-with-collateral op given only the client-level intent * (which obligation, which reserves, how much debt to repay, the swap price). The SDK computes * the per-side required lamports internally — the caller does NOT need to size the flash borrow. * * Semantics (matches the build flows): * - debt-flash needs to flash borrow the IR-adjusted debt repay amount in debt lamports; * - coll-flash needs to flash borrow enough coll to swap into that same IR-adjusted repay amount, * then withdraws `collWithdrawForFlashRepayLamports` coll from the reserve to repay the flash loan. * * Both sides are then validated against `isFlashLoanEnabled(reserve)` and against the reserve's * available liquidity by `determineFlashBorrowType` — coll-flash must cover flash-borrow + that * redeem leg. Coll-flash is preferred when genuinely viable; otherwise it falls back to debt-flash. * * @throws if neither reserve supports flash borrowing the required amount. */ export declare function determineRepayWithCollFlashBorrowType(props: { kaminoMarket: KaminoMarket; obligation: KaminoObligation; debtReserveAddress: Address; collReserveAddress: Address; /** Debt-token-denominated repay amount (decimal — not lamports). */ repayAmount: Decimal; /** Price expressed as debt-per-coll, i.e. 1 unit of coll = `priceCollToDebt` units of debt. */ priceCollToDebt: Decimal; /** Swap slippage tolerance for the coll→debt swap, percent (e.g. `0.5` = 0.5%). */ slippagePct: Decimal; referrer: Option
; /** The ledger instant (slot + block time) the repay sizing is estimated at. */ currentLedgerInstant: LedgerInstant; }): FlashBorrowType; //# sourceMappingURL=flashBorrowType.d.ts.map