Flash Builder

Combine up to 12 actions, including swaps, borrowing and repayments in one atomic transaction using flash loan. The contract executes them in your chosen order and sends any remaining tokens to your wallet. If any action fails, the entire transaction reverts.

On this page
On the roadmap
V2 Execution
Flash loans and lending
Morpho Blue and more
Flash loan fee
0
Actions
12
Transactions
1

Execution order

Use Flash Builder for multi-step trades, arbitrage and DeFi operations. Set up the blocks without writing a contract:

  • Arbitrage between two pools: Borrow through a flash loan, buy in one pool, sell in another, repay the loan and keep the profit.
  • Rebuild a position: Repay a loan, withdraw collateral, swap it and borrow on another market, all in one transaction.
  • Reduce liquidation risk: Use a flash loan to repay part of your debt, withdraw collateral and swap it to repay the flash loan, improving your loan’s health.
One Flash Builder set, block by block
  1. You send the set: the flash loan, the blocks and your limits

  2. Every block, token, pool, market and cap is checked before anything moves

  3. Morpho Blue lends the flash loan, with no fee $50,000 USDC

  4. Block 1 buys in one pool 25 WETH

  5. Block 2 sells in the other, for at least its minimum $50,500 USDC

  6. The fee goes to the fee recipient $100 USDC

  7. Morpho takes the flash loan back $50,000 USDC

  8. The rest comes back to you $400 USDC

SETTLEDOne transaction. Every block landed, and the loan was repaid.

  1. Checks: Validates the flash loan and all 1–12 blocks before moving tokens.
  2. Flash loan: Protocols provide the borrowed assets. Your signed authorization is used where required.
  3. Blocks run in your chosen order. If one fails, StepFailed(index, reason) identifies it.
  4. Settlement: The fee is paid, the protocol receives the exact borrowed amount and remaining tokens go to your wallet.

If anything fails, the entire transaction reverts, including the flash loan. Only gas is spent.

Transaction fee

FlasetBuilder: fee
fee = flashAssets * feeBps / 10_000
    + (flashOut - flashIn) * profitFeeBps / 10_000
feeBps             = 20
profitFeeBps       = 0

One fee per transaction, paid in the flash loan token regardless of block count. Check the fee before signing with quoteFee(flashAssets, profit).

Set, worked outSETTLED
Flash loan
$50,000 USDC
Bought
25 WETH
Sold for
$50,500 USDC
Flash loan repaid
$50,000 USDC
Left after repaying
$500 USDC
Fee, 50,000 × 20 ÷ 10,000
$100 USDC
To your wallet
$400 USDC
Transactions
1

Set minReturn to $400 USDC or less and maxFee to at least $100 USDC. The transaction enforces your limits: maxFee, minReturn, minHealth, deadline and each swap’s minOut.

Price changes and borrowing risk

  • Slippage and competition: Prices may change. If a swap falls below minOut or the transaction misses minReturn, everything reverts and you still pay gas fees.
  • Pausing stops new executions. Your loan position remains accessible directly.