import { KaminoMarket, KaminoObligation } from '../classes'; import { SwapIxsProvider, SwapQuoteProvider } from '../leverage'; import { KlendAccountsResult } from '../utils'; import { Account, Address, Instruction, Option, Slot, TransactionSigner } from '@solana/kit'; import Decimal from 'decimal.js'; import { AddressLookupTable } from '@solana-program/address-lookup-table'; import { DistributiveOmit, LedgerInstant, LedgerInstantCompatible } from '../utils/ledger'; /** * Which token to flash borrow for a swap-collateral operation. * * - `targetColl`: flash borrow target collateral, deposit it into the obligation, withdraw source collateral, swap * source → target on external DEX, and use the swap output to repay the flash loan. Works even if the debt * reserve's borrow limit is crossed. The flash-loan fee reduces the final amount of target collateral deposited. * - `sourceColl`: flash borrow source collateral, swap source → target on external DEX, deposit target collateral, * withdraw source collateral, and use the withdrawn source collateral to repay the flash loan. The flash-loan fee * reduces the source amount sent to the external DEX. * - `debt`: flash borrow the debt token, repay debt, withdraw source collateral, swap source → target on external DEX, * deposit target, borrow debt back, and repay the flash loan. Useful when the target collateral reserve has low * flash-loan liquidity. Requires the debt reserve borrow limit to have headroom; fails otherwise. The flash-loan fee * is paid as a small increase in debt. */ export type SwapCollFlashBorrowToken = 'sourceColl' | 'targetColl' | 'debt'; /** * Inputs to the `getSwapCollIxs()` operation. */ export interface SwapCollIxsInputs { /** * The amount of source collateral to be swapped-in for the target collateral. * This value will be treated exactly (i.e. slippage is not applied here) and thus must not exceed the collateral's * total amount. */ sourceCollSwapAmount: Decimal; /** * 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 uses this value * as the sizing buffer to scale the target-collateral deposit amount down by `(1 - slippagePct/100)` * so the worst-case real swap fill still produces at least the encoded deposit amount. Conceptually * a separate knob from the on-chain swap `min_out` (which the swapper sets); could later be a * smaller, capped value. */ slippagePct: Decimal; /** * If true, the source collateral will be closed - whatever amount is left after withdrawing `sourceCollSwapAmount` * will be transferred to the user. */ isClosingSourceColl: boolean; /** * The address of the source collateral reserve (i.e. the current one). */ sourceCollReserveAddress: Address; /** * The address of the target collateral reserve (i.e. the new one). */ targetCollReserveAddress: Address; /** * An elevation group ID that the obligation should end up with after the collateral swap - it will be requested by * this operation (if different from the obligation's current elevation group). */ newElevationGroup: number; /** * Which token to use for the flash loan. Defaults to `targetColl` (preserves pre-existing behavior). */ flashBorrowToken?: SwapCollFlashBorrowToken; /** * The address of the debt reserve. Required when `flashBorrowToken === 'debt'`. */ debtReserveAddress?: Address; market: KaminoMarket; owner: TransactionSigner; obligation: KaminoObligation; referrer: Option
; currentSlot: Slot; currentLedgerInstant?: LedgerInstant; budgetAndPriorityFeeIxs?: Instruction[]; scopeRefreshIx: Instruction[]; useV2Ixs: boolean; quoter: SwapQuoteProvider; swapper: SwapIxsProvider; logger?: (msg: string, ...extra: unknown[]) => void; } export type SwapCollIxsParams = LedgerInstantCompatible>; /** * Outputs from the `getSwapCollIxs()` operation. */ export interface SwapCollIxsOutputs { /** * Instructions for on-chain execution. */ ixs: Instruction[]; /** * Required LUTs. */ lookupTables: Account[]; /** * Whether the swap is using V2 instructions. */ useV2Ixs: boolean; /** * Informational-only details of the token amounts/fees/rates that were used during construction of `ixs`. */ simulationDetails: { /** * Details related to the flash-loan operation needed during collateral swap. */ flashLoan: { /** * The mint of the flash-borrowed token. */ flashBorrowReserveMint: Address; /** * The amount flash-borrowed (in token units). */ flashBorrowedAmount: Decimal; /** * The amount flash-repaid (in token units). Equal to `flashBorrowedAmount` + flash-loan fee. */ flashRepaidAmount: Decimal; }; /** * Details related to the external DEX's swap operation (i.e. `swapper` input) needed during collateral swap. */ externalSwap: { /** * The mint of the token swapped-in to an external DEX (source collateral). */ swapInMint: Address; /** * The mint of the token swapped-out from an external DEX (target collateral). */ swapOutMint: Address; /** * The amount actually swapped-in to an external DEX (after redeem-drift sizing — on a * closing position this is ~1 ppm below the `sourceCollSwapAmount` input; see `redeem_drift.ts`). */ swapInAmount: Decimal; /** * The amount swapped-out from an external DEX (subject to on-chain slippage). */ swapOutAmount: Decimal; /** * The verbatim response coming from the input `quoter`. */ quoteResponse?: QuoteResponse; }; }; } /** * Constructs instructions needed to partially/fully swap the given source collateral for some other collateral type. * * Three flash-borrow flavors are supported via `inputs.flashBorrowToken`: * - `targetColl` (default) uses a target-coll flash loan * - `sourceColl` uses a source-coll flash loan * - `debt` uses a debt-token flash loan (requires `inputs.debtReserveAddress`) */ export declare function getSwapCollIxs(inputs: SwapCollIxsParams): Promise>>; /** * Inputs for {@link getSwapCollKlendAccounts}: the routing/sizing inputs of {@link getSwapCollIxs} minus the * quoter/swapper (and logger), since the klend account footprint is discovered without an external swap. */ export type SwapCollKlendAccountsInputs = DistributiveOmit, 'quoter' | 'swapper' | 'logger'>; /** * Light helper: returns the exact, final set of klend accounts (and program ids) a {@link getSwapCollIxs} call with * the same inputs would consume, plus their count, WITHOUT calling the quoter/swapper. The operation computes this * same set from its klend ixs before quoting and the set is 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 within the tx account limit. */ export declare function getSwapCollKlendAccounts(inputs: SwapCollKlendAccountsInputs): Promise; //# sourceMappingURL=swap_collateral_operations.d.ts.map