Skip to main content
Flash loans let you borrow without collateral as long as you repay in the same transaction.

Flash loans in Bend

In Bend, flash loans:
  • Require no collateral
  • Must be repaid in the same transaction
  • Execute in one block
  • Are aimed at developers and advanced users

How they work

The Morpho contract exposes flashLoan and uses a callback to complete the flow.

Flow

  1. Initiate: Your contract calls morpho.flashLoan(token, amount, data).
  2. Receive: Morpho transfers the requested amount to your contract.
  3. Callback: Morpho calls onMorphoFlashLoan(amount, data) on your contract.
  4. Logic: Your contract runs its logic (arbitrage, swap, etc.).
  5. Repay: Your contract approves Morpho to pull back the borrowed amount.
  6. Complete: Morpho pulls the funds. If repayment fails, the whole transaction reverts.

Implementation

To use flash loans:
  1. Implement a contract that conforms to IMorphoFlashLoanCallback.
  2. Implement onMorphoFlashLoan with your logic.
  3. In the callback, approve the Bend (Morpho) contract to pull the borrowed amount before returning.

Use cases

  • Arbitrage: Profit from price differences across protocols in one transaction
  • Collateral swap: Replace one collateral type with another in one transaction
  • Self-liquidation: Liquidate your own position to avoid third-party liquidation
  • Flash actions: Combine several Bend operations in one transaction

Security

  • Atomicity: If the callback doesn’t approve repayment, the transaction reverts.
  • Funds: Don’t leave funds in the flash loan contract after the callback.
  • Reentrancy: Be careful calling external contracts inside the callback.
  • Gas: Flash loan flows can use a lot of gas.

Bend callbacks

Bend supports additional callbacks for richer flows:
  • IMorphoLiquidateCallback: Liquidations
  • IMorphoRepayCallback: Repayments
  • IMorphoSupplyCallback: Supply
  • IMorphoSupplyCollateralCallback: Supply collateral
You can combine supply, borrow, repay, and withdraw in a single transaction using these callbacks.