If your custom logic is compute-heavy, add
ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000_000 }) (or higher) as the first instruction in your transaction.@jup-ag/lend SDK provides helper functions to retrieve the instructions needed to execute a flashloan.
To perform a flashloan, construct a transaction where the borrow instruction occurs first, followed by your custom logic (which uses the borrowed funds), and ending with the payback instruction.
Transaction Atomicity
Transaction Atomicity
Solana processes the entire list of instructions atomically. If your custom logic fails to return the borrowed amount via
paybackIx, the entire transaction reverts and you only pay network fees.Parameters
getFlashloanIx accepts the following parameters:
Execute Flashloan
Import Dependencies
Import the required packages for Solana RPC, Jupiter Lend flashloan SDK, and versioned transaction building.
Load Keypair and Initialise Connection
Load the signer and create the RPC connection. Define the asset and borrow amount.
Get Flashloan Instructions
Fetch the borrow and payback instructions from the SDK. You borrow and return the same amount with no flashloan fees.
You can also use
getFlashBorrowIx and getFlashPaybackIx separately if you need to fetch the instructions independently.Define Custom Logic
Define the instructions that use the borrowed funds. This could be trades, clearing bad debt, collateral swapping, or any custom flashloan logic.
Build and Sign Transaction
Assemble the transaction. Order is critical: your custom logic must be placed exactly between the borrow and payback instructions.
