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.
Solana transactions have a 1232-byte size limit. If the serialised transaction exceeds 1232 bytes, the vault swap will not be possible in a single transaction. Consider splitting large positions or using simpler swap routes.
A vault swap moves your position from one vault to another atomically. Use Jupiter Lite API for swap quotes and instructions. Flow: swap from SOL/USDC to SOL/USDT:
  1. Flashloan USDC
  2. Repay all USDC debt and withdraw all SOL from vault 1
  3. Deposit SOL into vault 2 and borrow USDT with a 1-2 USD buffer for slippage
  4. Swap the new debt token → USDC
  5. Pay back the flashloan

Vault Swap

1

Import Dependencies

2

Set Parameters

Hardcode vault IDs, positionId (NFT ID in vault 1), debtAmount, collateralSupply, and a borrow buffer (e.g. 2 USDC) for slippage.
3

Get Flashloan Instructions

Flashloan the debt asset of vault 1 (e.g. USDC).
4

Close Position in Vault 1 (Repay + Withdraw)

5

Open Position in Vault 2 (Deposit + Borrow)

Use positionId: 0 for a new position. Deposit the withdrawn collateral and borrow the new debt token plus buffer.
6

Get Quote and Swap Instructions

Fetch a quote to swap the new debt token (e.g. USDT) → USDC. Ensure output is at least debtAmount to cover the flashloan.
The jupIxToTransactionInstruction helper converts the JSON instruction from the API into a Solana TransactionInstruction:
7

Assemble and Execute the Transaction

Order: Flashloan Borrow → Vault 1 Operate (repay + withdraw) → Vault 2 Operate (deposit + borrow) → Swap (new debt → USDC) → Flashloan PaybackThe getAddressLookupTableAccounts helper resolves lookup table addresses into account objects: