Skip to main content
These flows use many instructions. If you hit compute limits, add ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000_000 }) (or higher) as the first instruction in your transaction.
Close a borrow position when you hold only the collateral token (e.g. SOL), not the debt token (e.g. USDC). Use Jupiter Lite API for swap quotes and instructions. Flow:
  1. Flashloan debt asset (USDC) from Jupiter Lend
  2. Repay full debt and withdraw full collateral
  3. Swap collateral → debt (enough to cover the flashloan)
  4. Pay back the flashloan
All of this happens atomically in one transaction.

Repay with Collateral and Max Withdraw

1

Import Dependencies

2

Set Parameters

Hardcode VAULT_ID, positionId (NFT ID of your position), debtAmount, and collateralSupply (collateral to swap, in base units).
3

Get Flashloan Instructions

Flashloan the debt asset (e.g. USDC).
4

Get Vault Operations (Repay + Withdraw)

Use getOperateIx with MAX_REPAY_AMOUNT and MAX_WITHDRAW_AMOUNT to fully close the position.
5

Get Quote and Swap Instructions (Jupiter Lite API)

Fetch a quote (swap collateral → debt). Ensure the swap output yields at least debtAmount of the debt token (account for slippage).
The jupIxToTransactionInstruction helper converts the JSON instruction from the API into a Solana TransactionInstruction:
6

Assemble and Execute the Transaction

Order: Flashloan Borrow (debt) → Repay + Withdraw → Swap (collateral → debt) → Flashloan PaybackThe getAddressLookupTableAccounts helper resolves lookup table addresses into account objects: