A smart contract implementation of a Flash Loan Protocol, allowing users to borrow funds from a liquidity pool, use them for arbitrage or other operations, and repay the loan all in the same transaction. This project includes a token contract, a flash loan pool, and a flash loan receiver contract.
Flash loans are uncollateralized loans that allow users to borrow tokens from a pool and repay them within the same transaction. This implementation includes:
- A Token Contract (
Token.sol
) for creating an ERC-20-like token. - A Flash Loan Contract (
FlashLoan.sol
) for handling the flash loan process. - A Flash Loan Receiver Contract (
FlashLoanReceiver.sol
) for utilizing the borrowed funds and ensuring repayment.
- Flash Loan Functionality: Borrow funds temporarily within a single transaction.
- Custom Token: Includes a native ERC-20 token for testing and usage.
- Reentrancy Protection: Secured using OpenZeppelin's
ReentrancyGuard
. - Testing Suite: Comprehensive test cases to validate contract behavior.
An ERC-20-like implementation with minting functionality for testing. This token is used in the flash loan pool.
Manages the liquidity pool and provides the following functions:
depositTokens(uint256 _amount)
: Deposit tokens into the pool.flashLoan(uint256 _borrowAmount)
: Executes the flash loan.
Implements the IReceiver
interface for receiving and utilizing the flash loan:
executeFlashLoan(uint256 _amount)
: Triggers a flash loan and processes the funds.
- Node.js
- Hardhat (Ethereum development environment)
- npm or yarn
- Clone the repository:
git clone <repository-url> cd flash-loan
- Install dependencies:
npm install
- Compile the contracts:
npx hardhat compile
- Deploy the contracts (customize the deployment script as needed):
npx hardhat run scripts/deploy.js --network <network-name>
- Run the test suite using Hardhat:
npx hardhat test test/FlashLoan.js
- Key Test Cases:
- Ensure token balance is transferred to the flash loan pool during deployment.
- Validate successful borrowing and repayment in a single transaction.
- Test event emissions and reentrancy protection.
We welcome contributions to enhance the functionality and usability of the Flash Loan protocol! Here's how you can contribute:
-
Fork the Repository:
- Click the "Fork" button on the top-right corner of the repository page.
-
Clone the Repository:
- Clone the forked repository to your local machine:
git clone https://github.com/ayushn2/flash-loan.git cd flash-loan
- Clone the forked repository to your local machine:
-
Create a New Branch:
- Create a new branch for your feature or bug fix:
git checkout -b feature/new-feature
- Create a new branch for your feature or bug fix:
-
Make Your Changes:
- Add or modify the code to implement your feature or fix.
-
Test Your Changes:
- Ensure all existing and new tests pass:
npx hardhat test
- Ensure all existing and new tests pass:
-
Commit Your Changes:
- Write a meaningful commit message:
git add . git commit -m "Add feature: <description>"
- Write a meaningful commit message:
-
Push Your Changes:
- Push your branch to your forked repository:
git push origin feature/new-feature
- Push your branch to your forked repository:
-
Create a Pull Request:
- Open a pull request from your branch to the main branch of the original repository. Provide a clear description of your changes.
- Follow the existing coding style and conventions.
- Write clear and concise commit messages.
- Ensure all tests pass before creating a pull request.
- Add relevant documentation for new features or modifications.
- Be respectful and professional in all interactions.
We appreciate your efforts and contributions to the project! Let's build something great together. 🚀