Giter Site home page Giter Site logo

defi-box's Introduction

DeFi Truffle Box

This project demonstrates interacting with on-chain protocols (like Uniswap).

Currently the following is demonstrated:

  • Forking off Mainnet with Ganache
  • Forking off of a fork of Mainnet to run tests in parallel (thanks to Jest)
  • Buying DAI with ETH from Uniswap
  • Checking ETH price in DAI from custom function in MyDapp.sol which extends off of UniswapLiteBase.sol which uses Uniswap's on-chain contracts

Usage

  1. Clone the repo or npx truffle unbox defi

  2. Run npm install

  3. Create a .env file with the following contents:

    MAINNET_NODE_URL=https://mainnet.infura.io/v3/<API_KEY_HERE>
    PRIV_KEY_TEST=<some private key>
    PRIV_KEY_DEPLOY=<some other private key>
    
    • Get an API key from: https://infura.io/
    • Both of the private keys can be any private key you choose:
      • PRIV_KEY_DEPLOY refers to an account specifically for deploying
      • PRIV_KEY_TEST refers to an account specifically for testing
  4. Run npm start to start a local Ganache chain with forked Mainnet state

  5. Run npm run migrate in order to compile and migrate the project's contracts to this local Ganache chain

  6. Run npm test in order to run the tests.

    • Each test suite will fork off the local Ganache instance (yes, it's a fork of a fork) and create its own Ganache instance in-memory. This is to prevent out-of-order nonce issues since our tests are run in parallel by Jest.

Testing

Some information about the test chains:

  • ./tests/utils/test-chain.js starts a test chain exposed at http://127.0.0.1:8545 and our contracts need to be migrated to it with truffle migrate (or the npm run migrate script).

  • ./tests/utils/test-environment.js is instantiated for each and every test suite (i.e. test file in our case). It makes another Ganache instance in-memory that is forked off the local test-chain at http://127.0.0.1:8545

Contracts

UniswapLiteBase.sol utilizes the interface contracts: IUniswapExchange.sol and IUniswapFactory.sol in order to provide more convenient internal functions.

MyDapp.sol then inherits from UniswapLiteBase.sol to expose convenient outward facing contract functions.

defi-box's People

Contributors

adrianmcli avatar cruzmolina avatar kevinbluer avatar leckylao 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.