Benjam6 / Flashloan-Yield-Farming

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Machine set up (Optional if you have not setup before or having challenges on your system)

  1. Mac & Linux
  • Have python 2.7 installed Check if installed using command below
python -V

If not installed download from python Python Download version 2.7 related to your system

  • Download Ganache Graphical User Interface (GUI ) from Truffle Framework Site choose related to your system

  • Have node-gyp installed Check if installed using command below

If not installed, install using command below

npm i -g node-gyp
  1. Windows machine

Ignore Step 7 in the document below (document for bootcamp setup but applies to setup ubuntu environment)

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.37.2/install.sh | bash
$ source ~/.nvm/nvm.sh

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-cli --version

If not installed install with below

$ npm install -g ganache-cli
$ ganache-cli

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

  1. Install yarn if not installed. Check if installed using
yarn --version

If not installed install with below

$ npm install --global yarn
  1. Enter project directory and install dependancies
$ cd nft_collectibles_masterclass
$ yarn install  

Running the project

Make sure you are in project directory

$ cd flash_loan_masterclass_examples
  1. Run Ganache Fork Go to Infura.io create a new project and copy the Project ID Replace with your infura project id in ganache command below and leave running ganache-cli -p 7545 -f https://mainnet.infura.io/v3/ See example below, make sure you use your own id instead of 8888888888888888888888888888888
$ ganache-cli -p 7545 -f https://mainnet.infura.io/v3/8888888888888888888888888888888  
  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

About


Languages

Language:Solidity 86.9%Language:JavaScript 12.8%Language:Shell 0.3%