Borrower Guide

This guide shows how to take a flash loan from FlashBank for MEV and arbitrage strategies. You will deploy a small borrower contract that receives funds, executes your strategy, and repays amount + fee within the callback.

Interface

Your contract must implement executeFlashLoan(address token, uint256 amount, uint256 fee, bytes data) and return true on success.

interface IFlashLoanReceiver {
    function executeFlashLoan(
        address token,
        uint256 amount,
        uint256 fee,
        bytes calldata data
    ) external returns (bool);
}

// Call the router to initiate a flash loan:
// router.flashLoan(token, amount, toNative, data)

Minimal Solidity Example

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract MyArbBot is IFlashLoanReceiver {
    address immutable router;
    address immutable weth;

    constructor(address _router, address _weth) {
        router = _router;
        weth = _weth;
    }

    function start(uint256 amount, bytes calldata data) external {
        // toNative=false → receive WETH; toNative=true → receive ETH
        IFlashBankRouter(router).flashLoan(weth, amount, false, data);
    }

    function executeFlashLoan(
        address token,
        uint256 amount,
        uint256 fee,
        bytes calldata data
    ) external returns (bool) {
        require(msg.sender == router, "only router");

        // Your MEV/arb strategy here — you hold the borrowed WETH
        // ...

        // Repay: approve router for amount + fee (WETH mode)
        IERC20(token).approve(router, amount + fee);
        return true;
    }

    receive() external payable {}
}

interface IFlashBankRouter {
    function flashLoan(
        address token,
        uint256 amount,
        bool toNative,
        bytes calldata data
    ) external;
}

Script Snippet (ethers v6)

const borrower = new ethers.Contract(borrowerAddress, borrowerAbi, wallet);
await borrower.start(ethers.parseEther("10"), "0x"); // Request 10 WETH

Rules & Limits

  • Maximum single loan: 1,000 WETH (subject to available liquidity and 50% pool cap)
  • Fee: 0.02% of the amount (2 bps, configurable by dual-control)
  • Repay amount + fee within executeFlashLoan, otherwise the entire transaction reverts
  • Set toNative=true to receive native ETH instead of WETH (useful for strategies that need ETH)

Tips

  • Pass DEX routes/pools in data and decode inside executeFlashLoan.
  • Fail safely: revert or return false on a missed opportunity; funds are returned to providers.
  • Optimise gas; your EOA funds the transaction.

⛽ Gas Cost Analysis

Want to understand the gas costs of multi-provider flash loans? We've published a detailed study based on real Sepolia transactions.

📊 Read Gas Cost Study

Learn when to use WETH-only mode, how provider count affects gas, and when FlashBank is more economical than Aave.