Flashloan LeveragedYieldFarm

Make use of Flashloan from DY/DX to earn more from Compouond.

🔧 Project Diagram: - How it works

🔧 Deposit Diagram:

Deposit Diagram

🔧 Withdraw Diagram:

Deposit Diagram

Technology Stack and Tools

  • Node Version Manager - node version manager
  • Yarn - Alternative package manager to NPM
  • Truffle - development framework
  • Solidity - ethereum smart contract language
  • Ganache - local blockchain development
  • Web3 - library interact with ethereum nodes
  • JavaScript - logic front end and testing smart contracts
  • Infura - connection to ethereum networks
  • Flashloan - Flashloans allow you to borrow lots of funds for a very small fee without need for collateral do anything else with funds as long as repayments happens in same transaction.
  • Metamask Wallet - You need to install Metamask Wallet
  • ERC20 - ERC20 Token standards
  • Compound Protocol - supply or borrow tokens and earn cTokens
  • Flashloan Providers
    • DY/DX - Decentralized Exchange offering flashloans with cheap feess; that is used on this example code Alternative Flashloan Providers that can be used or to investigate
  • Augement your profits with trading bot - TradingBot Masterclass
  • Uses of Flashloans
    • Arbitrage - use the vast funds to make profits from price discrepencies e.g on Exchange See SimpleArb.sol
    • Leverage - increase exposure e.g earn more with Yield Farmin on protocols like Compound. See FlashloanLeveragedYieldFarm project
Folder / Directory Structure (key folders and files)
  • FlashloanLeveragedYieldFarm
    • flats
    • migrations
    • node_modules
    • src
      • abis
      • contracts
    • test
    • flatten.sh
    • truffle.js
    • package.json
    • .gitignore
    • README.md
    • yarn.lock

Preconfiguration, Installation

  1. You will need nvm if not laready installed; so you can use specific version node version 14 and above
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Restart your terminal

  1. Install node v12.0.0 or versions above e.g node v14.16.0
$ nvm install 14.16.0 
$ nvm alias default 14.16.0 
$ nvm use default
  1. Install truffle globally if not installed. Check if installed using
truffle version

If not installed install with below

$ npm install -g truffle
  1. Ignore if either installed already! If opting to use ganache-cli vs Ganache GUI, install ganache-cli globally. Note that ganache-cli rus on port 8545 and ganache-gui runs on port 7545 as placced in truffle-config.js. Check if ganache-cli installed first with
ganache --version

If not installed install with below

$ npm install -g ganache
$ ganache

Run ganache-cli in different terminal and keep running when compiling, testing, migrating, running app, etc.

Running the project

  1. Enter project directory and install dependancies
$ cd flashloan_masterclass
$ npm install  
  1. Run Ganache Fork
$ ganache -p 7545 -f
  1. Run the test that will show example flashloan and leveraged yield farming compound and repay Open a new terminal and run
$ truffle test 

If you have problems with test e.g archived state, rpc etc, you may need to restart your ganache running fork To reset and run again, you will need to restart the terminal with ganache and rerun the fork