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.
“Unwind” (deleverage) is the process of closing or reducing a leveraged position. Use Jupiter Lite API for swap quotes and instructions. Build your own transaction, do not use a pre-built swap transaction. For example, to unwind a SOL/USDC position:
  1. Flashloan collateral (SOL) from Jupiter Lend.
  2. Swap SOL → USDC using Jupiter Lite API (you need USDC to repay debt).
  3. Use getOperateIx to repay debt and withdraw collateral.
  4. Pay back the flashloan with the withdrawn SOL.
All of this happens atomically in a single Solana transaction.

Unwind

1

Import Dependencies

2

Load Keypair and Initialise Connection

Set positionId (NFT ID from your multiply position) and withdrawAmount (collateral to unwind in base units). For full unwind, use MAX_REPAY_AMOUNT and MAX_WITHDRAW_AMOUNT.
3

Get Flashloan Instructions

Use getFlashBorrowIx and getFlashPaybackIx to flashloan the collateral asset (e.g. SOL).
4

Get Quote and Swap Instructions (Jupiter Lite API)

Fetch a quote from Jupiter Lite API (swap collateral → debt), then POST to swap-instructions. Use otherAmountThreshold from the quote as the repay amount for partial unwind.
The jupIxToTransactionInstruction helper converts the JSON instruction from the API into a Solana TransactionInstruction:
5

Get Vault Operations (Repay + Withdraw)

Use getOperateIx with negative amounts. For full unwind use MAX_WITHDRAW_AMOUNT and MAX_REPAY_AMOUNT. For partial, use withdrawAmount.neg() and repayAmount.neg() where repayAmount = new BN(quoteResponse.otherAmountThreshold).
6

Assemble and Execute the Transaction

Order: Flashloan Borrow (collateral) → Swap (collateral → debt) → Vault Operate (repay + withdraw) → Flashloan PaybackThe getAddressLookupTableAccounts helper resolves lookup table addresses into account objects: