This project is a Flash Loan Simulator built in Solidity, designed to teach and demonstrate how flash loans work in decentralized finance (DeFi) — without using actual lending pools or liquidity protocols.
A flash loan is a type of uncollateralized loan offered by DeFi protocols (like Aave and dYdX) that must be borrowed and repaid within the same transaction. If the loan isn't repaid with interest in that single transaction, it automatically reverts, meaning no funds are lost.
Key Concepts:
- Atomicity: All operations happen in a single transaction.
- No collateral required.
- Useful for arbitrage, collateral swaps, liquidation protection, etc.
This project simulates the flash loan process in a simplified, beginner-friendly way.
- Simulates a liquidity pool where users can deposit ETH.
- A
flashLoan()function sends ETH to a borrower and expects it to be returned within the same transaction. - If not repaid, the transaction reverts, mimicking real flash loan behavior.
- A separate receiver contract (
FlashLoanReceiver) demonstrates how to borrow and repay withinexecuteOperation().
Flash loans are conceptually powerful but complex to learn in live DeFi environments due to:
- Complex protocol codebases (e.g., Aave).
- Gas costs and risk of actual fund loss.
- Inaccessible or hard-to-debug test environments.
This simulator:
- Provides zero-risk experimentation.
- Keeps the logic transparent and self-contained.
- Helps you understand how flash loans are structured internally.
- Prepares you to interact with real-world DeFi protocols.
MIT License. Feel free to fork and build upon it for your learning journey.