skinheadz / mev-flashloan-starter

Flash Loan Starter from AAVE V3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MEV FlashLoan Starter

This project demonstrates a basic Hardhat use case. It comes with a sample contract, and a script that deploys that contract.

This repo is written only for POC. The contract is simple and does not contain any arbitrage or swap logic. It is written as a starting kit for your own implementations. Such as liquidation, or arbitrage bot. Since it uses AAVE_V3, IT DOES NOT SUPPORT ETH Mainnet. (use v2 for that, you won't be able to do anything on eth anyways, thanks to mempool 🥪)

👼

A flash loan starter contract can be used to borrow money for single transaction from AAVE V3 for networks: Polygon, Optimism, Arbitrum, Harmony, Fantom, Avalanche.

Fork project

git clone https://github.com/skinheadz/mev-flashloan-starter.git
cd mev-flashloan-starter
npm install

Deploy the contract

  1. Edit network config in hardhat.config.ts.

  2. Copy and edit the secret(env) sample config:

$ cp .secret.ts.sample .secret.ts
  1. Then run the script to deploy. If you wanna deploy to specific network, specify it when running. You may need to change the network settings in hardhat.config.ts.

For example,

$ npx hardhat node --fork 'https://eth-goerli.public.blastapi.io' --show-stack-traces
$ npx hardhat --network private run scripts/deploy.ts

or

$ npx hardhat --network goerli run scripts/deploy.ts

Bot functions implementation

The contract has a function executeOperation, which will be run by Lending Protocol. Here you specify your custom logic with borrowed funds.

The bot need to call requestFlashLoan(token, amount) to get the requested token with requested amount as a loan.

Contract owner can call withdraw() to withdraw the profit.

Remix/ChainIDE Instructions:

  1. Copy and paste FlashLoan.sol into remix.
  2. Compile
  3. Choose Metamask as provider.
  4. Input Deployed contract address
  5. Run requestFlashLoan(token, amount)

sample flashloan tx on goerli: 'https://goerli.etherscan.io/tx/0x103f4c7548e3992e8eb171c77e39a13ec9582a82b1dbd1bdceabd15e9129ac8f'

goerli faucets: 'https://goerli-faucet.pk910.de/' 'https://staging.aave.com/faucet/'

Screen Shot 2023-01-05 at 1 16 53 PM

Resources

Flashloan with Aave V3 - detailed description of protocol

About

Flash Loan Starter from AAVE V3

License:Do What The F*ck You Want To Public License


Languages

Language:TypeScript 98.6%Language:Solidity 1.4%