import { Address, Slot } from '@solana/kit'; import Decimal from 'decimal.js'; import { KaminoMarket, KaminoObligation, KaminoReserve } from '../classes'; import { AdjustLeverageCalcsResult, AdjustDepositDebtFlashCalcsResult, AdjustWithdrawCollFlashCalcsResult, DepositLeverageCalcsResult, DepositLeverageDebtFlashCalcsResult, WithdrawLeverageCalcsResult, WithdrawLeverageCollFlashCalcsResult } from './types'; import { LedgerInstant } from '../utils/ledger'; export declare enum LeverageOption { deposit = "Deposit", withdraw = "Withdraw", adjust = "Adjust", close = "Close" } export interface LeverageCalcsArgs { depositAmount: Decimal; withdrawAmount: Decimal; deposited: Decimal; borrowed: Decimal; debtTokenMint: Address; selectedTokenMint: Address; collTokenMint: Address; targetLeverage: Decimal; activeLeverageOption: LeverageOption; flashLoanFeeRatio: Decimal; slippagePct: Decimal; debtBorrowFactorPct: Decimal; priceCollToDebt: Decimal; priceDebtToColl: Decimal; } export interface LeverageCalcsResult { earned: Decimal; totalDeposited: Decimal; totalBorrowed: Decimal; netValue: Decimal; netValueUsd: Decimal; ltv: Decimal; } export declare function calculateMultiplyEffects(getPriceByTokenMintDecimal: (mint: Address) => Promise, { depositAmount, withdrawAmount, deposited, borrowed, debtTokenMint, selectedTokenMint, collTokenMint, targetLeverage, activeLeverageOption, flashLoanFeeRatio, slippagePct, debtBorrowFactorPct, priceCollToDebt, priceDebtToColl, }: LeverageCalcsArgs, logEstimations?: boolean): Promise; /** * returns how much borrowToken will be borrowed to reach leverage given initial collateral amount * @param depositTokenAmount * @param leverage * @param priceAToB * @param flashBorrowFee */ export declare const calcBorrowAmount: ({ depositTokenAmount, targetLeverage, priceCollToDebt, flashLoanFeeRatio, }: { depositTokenAmount: Decimal; targetLeverage: Decimal; priceCollToDebt: Decimal; flashLoanFeeRatio: Decimal; }) => Decimal; interface UseEstimateWithdrawAmountsProps { priceCollToDebt: Decimal; amount: Decimal.Value; deposited: Decimal; borrowed: Decimal; collTokenMint: Address; selectedTokenMint: Address; } export declare const estimateWithdrawMode: (props: UseEstimateWithdrawAmountsProps) => WithdrawResult; export interface WithdrawParams { currentBorrowPosition: Decimal; currentDepositPosition: Decimal; priceCollToDebt: Decimal; withdrawAmount: Decimal; selectedTokenMint: Address; collTokenMint: Address; } interface WithdrawResult { adjustDepositPosition: Decimal; adjustBorrowPosition: Decimal; } export declare function calcWithdrawAmounts(params: WithdrawParams): WithdrawResult; interface UseEstimateAdjustAmountsProps { targetLeverage: Decimal; debtTokenMint: Address; collTokenMint: Address; totalDeposited: Decimal; totalBorrowed: Decimal; flashLoanFee: Decimal; } /** * Calculate how much token will be deposited or withdrawn in case of position adjustment * @param leverage * @param totalDeposited * @param totalBorrowed */ export declare const estimateAdjustMode: (priceCollToDebt: Decimal, { targetLeverage, totalDeposited, totalBorrowed, flashLoanFee }: UseEstimateAdjustAmountsProps) => AdjustLeverageResult; export interface AdjustLeverageParams { targetLeverage: Decimal; currentBorrowPosition: Decimal; currentDepositPosition: Decimal; priceCollToDebt: Decimal; flashLoanFee: Decimal; } interface AdjustLeverageResult { adjustDepositPosition: Decimal; adjustBorrowPosition: Decimal; } /** * Calculates the amounts of tokenA to deposit/withdraw and tokenB to borrow/repay proportionally to adjust the leverage of a position. * * @param {AdjustLeverageParams} params - Parameters for the calculation * @param {number} params.targetLeverage - The target leverage for the position * @param {Decimal} params.currentPositionTokenA - The current amount of tokenA in the position * @param {Decimal} params.currentPositionTokenB - The current amount of borrowed tokenB in the position * @param {number} params.priceAtoB - The conversion rate from tokenA to tokenB (tokenA price = tokenB price * priceAtoB) * @returns {AdjustLeverageResult} An object containing the amounts of tokenA to deposit/withdraw and tokenB to borrow/repay */ export declare function calcAdjustAmounts({ targetLeverage, currentBorrowPosition, currentDepositPosition, priceCollToDebt, flashLoanFee, }: AdjustLeverageParams): AdjustLeverageResult; interface UseTransactionInfoStats { priceCollToDebt: Decimal; priceDebtToColl: Decimal; amount: Decimal; targetLeverage: Decimal; selectedTokenMint: Address; collTokenMint: Address; flashLoanFee: Decimal; slippagePct: Decimal; } export declare const estimateDepositMode: ({ priceCollToDebt, priceDebtToColl, amount, targetLeverage, selectedTokenMint, collTokenMint, flashLoanFee, slippagePct, }: UseTransactionInfoStats) => { adjustDepositPosition: number; adjustBorrowPosition: number; }; export declare const depositLeverageCalcs: (props: { depositAmount: Decimal; depositTokenIsCollToken: boolean; depositTokenIsSol: boolean; priceDebtToColl: Decimal; targetLeverage: Decimal; slippagePct: Decimal; flashLoanFee: Decimal; }) => DepositLeverageCalcsResult; export declare function withdrawLeverageCalcs(market: KaminoMarket, collReserve: KaminoReserve, debtReserve: KaminoReserve, priceCollToDebt: Decimal, withdrawAmount: Decimal, deposited: Decimal, borrowed: Decimal, currentSlotOrLedgerInstant: Slot | LedgerInstant, isClosingPosition: boolean, selectedTokenIsCollToken: boolean, selectedTokenMint: Address, obligation: KaminoObligation, flashLoanFee: Decimal, slippagePct: Decimal, currentLedgerInstant?: LedgerInstant): WithdrawLeverageCalcsResult; /** * Canonical lamport-domain sizing of the coll-flash loan leg, shared by the flash-borrow-type selectors * (`determineWithdrawLeverageFlashBorrowType` / `determineAdjustLeverageFlashBorrowType`) and the transaction * builders so selector viability can never drift from what the builder executes: * * - `flashBorrowLamports`: flash borrow in coll **lamports** (`flashBorrowCollTokens * mintFactor`, ceiled; funds a * ceil-sized exact-in swap). * - `flashFeeLamports`: the SC flash fee on that borrow via `calcFlashLoanFees` (1-lamport minimum honoured; the * flash ixs in these flows carry no referrer and the fee total is referral-split-independent), ceiled to whole * lamports. * - `flashRepayDebitLamports`: the exact ATA debit at flash-repay (`flashBorrow + fee`), in lamports. * - `redeemCollLamports`: the withdraw that must fund the debit — fee-exclusive base (token→lamports, ceiled) + fee. */ export declare function calcCollFlashLegLamports(params: { collReserve: KaminoReserve; /** Flash-borrow size, in coll TOKEN units. */ flashBorrowCollTokens: Decimal; /** Fee-exclusive withdraw base, in coll TOKEN units (`depositTokenWithdrawAmount`). */ redeemBaseCollTokens: Decimal; }): { flashBorrowLamports: Decimal; flashFeeLamports: Decimal; flashRepayDebitLamports: Decimal; redeemCollLamports: Decimal; }; export declare function adjustDepositLeverageCalcs(debtReserve: KaminoReserve, adjustDepositPosition: Decimal, adjustBorrowPosition: Decimal, priceDebtToColl: Decimal, flashLoanFee: Decimal, slippagePct: Decimal): AdjustLeverageCalcsResult; export declare function adjustWithdrawLeverageCalcs(adjustDepositPosition: Decimal, adjustBorrowPosition: Decimal, flashLoanFee: Decimal, slippagePct: Decimal, obligation?: KaminoObligation, debtReserve?: KaminoReserve, currentSlotOrLedgerInstant?: Slot | LedgerInstant, currentLedgerInstant?: LedgerInstant): AdjustLeverageCalcsResult; /** * Deposit with flash borrow DEBT token. * Flow: flash borrow debt -> swap debt->coll -> deposit coll -> borrow debt -> flash repay debt * * The user deposits collateral (or debt token). We flash borrow debt, swap it to coll, * deposit all coll, borrow debt to repay the flash loan (principal + fee). */ export declare const depositLeverageCalcsDebtFlash: (props: { depositAmount: Decimal; depositTokenIsCollToken: boolean; depositTokenIsSol: boolean; priceDebtToColl: Decimal; targetLeverage: Decimal; slippagePct: Decimal; flashLoanFee: Decimal; }) => DepositLeverageDebtFlashCalcsResult; /** * Withdraw with flash borrow COLLATERAL token. * Flow: flash borrow coll -> swap coll->debt -> repay debt -> withdraw coll -> flash repay coll * * We flash borrow enough coll to swap for the debt repayment amount, * then repay debt, withdraw coll, and use the withdrawn coll to repay the flash loan. */ export declare function withdrawLeverageCalcsCollFlash(market: KaminoMarket, collReserve: KaminoReserve, debtReserve: KaminoReserve, priceCollToDebt: Decimal, withdrawAmount: Decimal, deposited: Decimal, borrowed: Decimal, currentSlotOrLedgerInstant: Slot | LedgerInstant, isClosingPosition: boolean, selectedTokenIsCollToken: boolean, selectedTokenMint: Address, obligation: KaminoObligation, flashLoanFee: Decimal, slippagePct: Decimal, currentLedgerInstant?: LedgerInstant): WithdrawLeverageCollFlashCalcsResult; /** * Adjust (increase leverage) with flash borrow DEBT token. * Flow: flash borrow debt -> swap debt->coll -> deposit coll -> borrow debt -> flash repay debt */ export declare function adjustDepositLeverageCalcsDebtFlash(debtReserve: KaminoReserve, adjustDepositPosition: Decimal, adjustBorrowPosition: Decimal, priceDebtToColl: Decimal, flashLoanFee: Decimal, slippagePct: Decimal): AdjustDepositDebtFlashCalcsResult; /** * Adjust (decrease leverage) with flash borrow COLLATERAL token. * Flow: flash borrow coll -> swap coll->debt -> repay debt -> withdraw coll -> flash repay coll */ export declare function adjustWithdrawLeverageCalcsCollFlash(adjustDepositPosition: Decimal, adjustBorrowPosition: Decimal, priceCollToDebt: Decimal, flashLoanFee: Decimal, slippagePct: Decimal, obligation?: KaminoObligation, debtReserve?: KaminoReserve, currentSlotOrLedgerInstant?: Slot | LedgerInstant, currentLedgerInstant?: LedgerInstant): AdjustWithdrawCollFlashCalcsResult; export {}; //# sourceMappingURL=calcs.d.ts.map