Coder Social home page Coder Social logo

ez-flashloan's Introduction

EZ-Flashloan

A barebones solidity template for Aave's flashloans

Prerequisite

  • Basic knowledge of Solidity
  • Basic knowledge of Truffle
  • Basic knowledge of Javascript
  • An Infura account and API key

Flashing

  1. In Flashloan.sol, code your logic into the executeOperation() function
  2. When ready, call flashloan() on your contract
  3. Remember that your contract needs to have enough funds of whatever asset you are borrowing to payback the flashloan fee.
  4. If not deploying on mainnet, then change the addressProvider in ./aave/FlashLoanReceiverBase.sol to the relevant address

Set up

  1. Clone this repo and:

    npm install
    
  2. (Install and) Run Ganache, preferably the CLI version

  3. In truffle-config.js, ensure the details for the development network match up with your running Ganache instance

  4. To minimise set up steps with Aave's lending pools, use Ganache's fork feature. This will 'fork' mainnet into your Ganache instance. Open terminal and run:

    ganache-cli --fork https://mainnet.infura.io/v3/YOUR_INFURA_KEY
    
  5. In a new terminal window in your repo directory, run:

    truffle console
    
  6. Migrate your Flashloan contract to your instance of Ganache with:

    migrate --reset
    
  7. Your contract is now deployed on your local Ganache, which is mirroring mainnet. Call your contract's flashloan function within the truffle console with:

    let f = await Flashloan.deployed()
    await f.flashloan()
    

    Be patient as your ganache instance works its magic.

  8. If your implementation is correct, then the transaction will succeed. If it fails/reverts, a reason will be given.

    • if you didn't make any changes to this template and just deployed it, then the call to f.flashloan() will fail as the contract is not funded with any DAI, so cannot make the flashloan repayment (which includes the amount borrowed + a fee). Solve this by using an address already funded with DAI, or send yourself some DAI to begin with.

Making it mainnet ready

My recommendations would be:

  • If doing arbitrage and taking profits, hardcode your profit taking address

Deploying to mainnet

  1. Rename env file to .env and include your infura key and deployment wallet private key (don't commit this file to Git!)
  2. In truffle-config.js, uncomment the mainnet section under networks.
  3. Deploy to mainnet with truffle migrate --network mainnet

Verify, don't trust

  • Aave's official documentation: This template is a bit different to their example as everything happens within this one contract, including the calling of flashloan()

  • Aave's contract addresses

  • All imported contracts will have a link to the 'official' contract at the top.

ez-flashloan's People

Contributors

emilianobonassi avatar matprime avatar mrdavey avatar tycooperaow avatar

Watchers

 avatar  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.