Giter Club home page Giter Club logo

aave-flash-loaner's Introduction

Description

FlashLoaner is a smartcontract to make flashloans with AAVE. This mechanism allows you to make a swap with Uniswap if you only have enough money just to pay the fee. This can be used in an arbitrage bot

Contract

This contract takes addresses of the UniswapRouter during deploy, and provides method startFlashLoan to make falshloans

Constructor

constructor(address addressesProvider, address router) public;

You can use your own Router and AddressesProvider or get actual addresses for default networks below:

  • Kovan:
    • LendingPoolAddressesProvider: 0x88757f2f99175387ab4c6a4b3067c77a695b0349
    • UniswapV2Router02: 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
  • Mainnet:
    • LendingPoolAddressesProvider: 0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5
    • UniswapV2Router02: 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D

List of deployed AAVE contracts addresses

startFlashLoan

function startFlashLoan(uint amount, address[] memory path) external;

This method borrows the first token of path from AAVE pool, makes swap with Router, returns loans back and sends balance after deduction to the msg.sender.

  • amount โ€” amount of tokens that will be borrowed.
  • path โ€” an array of token addresses between which the swap will be performed in turn. First and last addresses must be the same to make a looped swap. Contract saves it to a private attribute _path to read it in the method uniswapV2Call that will be called next. You can pass it using params argument instead of an attribute, if you need it. params is a bytes type therefore if you want to pass addresses as an argument you need a library to convert list of addresses to bytes and vice versa. You can read about this here.

Dependencies

Install dependencies of the package.json:

npm i -D

Create config

Use .env as a local config to set private options manually:

Don't commit it to git! (keep it secret)

cp .env.template .env

You should also register at Infura and create new project there.

After that set your Infura Project ID (from project settings) to .env

Scripts

To run any script enter:

npx hardhat run path/to/script.ts --network network_name

Generate a wallet

Use the script to generate a new wallet with it's own private key and address:

npx hardhat run scripts/0_create_new_wallet.ts

Copy generated private key (or your own private key) to .env config on the corresponding line.

Add some ETH to address of this wallet. For tests you can use any faucet for your network. For example faucet.kovan.network

Also you should get DAI in kovan, because AAVE allows to borrow only tokens that were added to its list. Use the AAVE Faucet to get DAI (0xff795577d9ac8bd7d90ee22b6c1703490b6512fd)

Deploy the FlashLoaner contract

A script to deploy the FlashLoaner contract and to get it's address:

npx hardhat run scripts/1_deploy_flashloaner.ts --network kovan

Run local tests

Hardhat allows you to execute tests in it's own network, but due to the fact that you need to interact with Uniswap, you need to make a fork of a network where the Uniswap is. For example - Kovan.

You can use AlchemyAPI, then you will can specify the block from which the fork will be made. If you're going specify block, specify block after you get DAI tokens in kovan network!. To use AlchemyAPI, create an app in its dashboard and set it's URL to .env. If the AlchemyAPI URL not setted Infura API will be used.

Important: Infura API takes a last block during run test. This can lead to different results for the same tests

npx hardhat test test/FlashLoaner.ts

Run tests in a testnet

npx hardhat test test/FlashLoaner.ts --network kovan

aave-flash-loaner's People

Contributors

creestl avatar samwarden avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.