Flashloans
How to use flashloans on Project 0 for atomic, uncollateralized borrowing within a single transaction.
Flashloans allow you to borrow any amount from P0 without collateral, as long as you repay it within the same transaction. If the loan is not repaid, the entire transaction reverts as if it never happened.
Flashloans are a primitive for automated traders, HFT operators, liquidation bots, and integrators. Under the hood, P0's looping and strategies features use flashloans to build leveraged positions atomically.
How Flashloans Work
A flashloan is a pair of instructions that bookend a transaction:
lending_account_start_flashloan
(any operations: borrows, swaps, deposits, etc.)
lending_account_end_flashloanBetween the start and end:
- You can borrow as much as you want from any Bank, with no health check.
- At the end of the transaction, the risk engine runs a final health check.
- If your Account is healthy after everything executes, the transaction succeeds.
- If not, the entire transaction reverts.
Use Cases
Leverage Loops
Build a leveraged position in a single transaction:
Start flashloan
Borrow 60 USDC
Swap USDC to SOL on Jupiter
Deposit SOL as collateral
End flashloanLiquidation
Borrow the funds needed to repay a liquidatee's debt, execute the liquidation, and repay the flashloan from the seized collateral:
Start flashloan
Liquidate unhealthy account (seize collateral)
Swap seized collateral to debt token
Repay the liquidatee's debt
End flashloanArbitrage
Capture price discrepancies across venues without tying up capital:
Start flashloan
Borrow Asset A
Sell A on Venue 1 at higher price
Buy A on Venue 2 at lower price
Repay flashloan
End flashloanFees
There are no fees to execute flashloans on P0.
Rules and Restrictions
- Cannot be called via CPI. Flashloans must be invoked directly in a transaction, not through cross-program invocation from another program.
- Start must come first.
lending_account_start_flashloanmust appear at the beginning of the transaction (after optional compute budget instructions). - End must come last.
lending_account_end_flashloanmust be the final instruction. The risk engine check happens here. - One flashloan per transaction. You cannot nest flashloans.
For programmatic flashloan implementation, see the TypeScript SDK.