DefiVault - Defi wallet and funds investor

A smart contract wallet that stores ether and any Erc20 token and can invest in Compound.finance protocol any supported Erc20 token.

The contract is deployed in testnet at address

0x942F7D5251F1Ffd1Ba98fe0dc375e63ddbdAEE41

Front-end link: https://defivault.vercel.app

Smart contracts

The Smart contracts implement functionality to

  • deposit ether in the DefiVault smart contract
  • get the ether balance
  • withdraw ether
  • deposit any ERC20 token in the DefiVault smart contract
  • get all the balances of the deposited ERC20 tokens
  • withdraw ERC20 tokens
  • supply compatible ERC20 tokens to Compound.finance in order to acquire interest
  • redeem ERC20 tokens supplied to Compound.finance along with interest (for short term supply period we could notice that we redeemed less than we supplied due to the fees)

UI client

A Next.js app that uses ethers.js wrapped in custom hooks to interact with the blockchain.
It is deployed with vercel in defivault.vercel.app.
The app integrates with all the smart contract functionalities through the three following sections that correspond to the UI tabs:

  • Ether: exposes functionality to interact with ether (deposit, withdraw)
  • ERC20: exposes functionality to interact with ERC20 tokens (deposit, withdraw, supply to Compound, redeem from compound)
  • PTRD: this is a control panel for a custom deployed ERC20 token that can do all the basic ERC20 token interactions and most importantly transfer tokens to any user and approve tokens towards the DefiVault contract so that we can use its deposit tokens functionality

How to interact with DefiVault

There are two ways to use DefiVault, both of them require metamask browser plugin to be installed.

1. Interact through UI client deployed publicly in Vercel

  • Go to https://defivault.vercel.app
  • Connect with metamask on Ropsten network
  • Get ether from ropsten faucet to use ether wallet functionality (deposit and withdraw ether)
  • Use PTRD control panel to transfer custom deployed ERC20 token to your wallet and interact with ERC20 wallet functionality (depositToken, withdrawToken)
  • Exchange ether with other Compound protocol compatible tokens in uniswap in order to deposit them in DefiVault and invest them in Compound (more on this later)

2. Setup the project locally

Prerequisites

  • npm >= 6
  • Node.js >= 14
  • Ganache CLI >= 6
  • Truffle >= 5
  • Solidity - 0.8.9 (solc-js)

Contracts deployment

  • Clone locally this repository and open a terminal in the top level directory
  • Install truffle and ganache-cli
  • npm install -g truffle
    npm install -g ganache-cli
    
  • Open a new terminal window and run
  •  ganache-cli
    
  • Install smart contract dependencies and deploy contracts to local ganache-cli
  •   npm install
      npm run deploy
    

Front-end deployment

  • Create .env file in ui-app and add the required fields
  • cd ../ui-app
    touch .env
    

    Using the .env.example file as a guide to fill in the .env with the required fields To make it work for local ganache-cli network we need the contract addresses of DefiVault and Petridereum and the private key of the first ganache-cli address (This account is the owner of Petridereum and can transfer us tokens to test the app)

  • Install UI client dependencies and start the server locally
  • yarn dev
    
Disclaimer: The Compound.finance functionality needs the setup of the Compound contracts locally and is not covered. Please use the deployed Ropsten contracts.

Smart contract unit tests

To run the unit tests start ganache-cli (default port 8545) in a terminal and then in a new window run:

truffle test

or

npm run test

Walkthrough

To test the compound.finance integration in Ropsten with COMP token:

  • Get ether from ropsten faucet
  • Exchange some ether for COMP in uniswap, add the correct COMP address in uniswap
  • Use COMP etherscan contract panel to approve COMP to the DefiVault contract
  • Deposit comp to defivault using the 2nd tab (the defivault contract address can be found in PTRD tab or in deployed_addresses.txt)
  • After deposit is complete get the cCOMP contract address from compound website (ropsten) and supply COMP from Invest with Compound tab
  • Upon success you should see the minted cCOMP tokens in your wallet
  • Use the redeem section to send back the cCOMP and get COMP + interest - fees in your DefiVault wallet

Video walkthrough: https://youtu.be/FZUNgM4LhFA

Project structure

The project is a monorepo which consists of two basic top-level directories:

  • smart-contracts: A solidity project built with truffle that has that implements the DefiVault smart contracts, compiles and deploys them in ganache-cli and Rostep testnet and also copies the generated abi to the ui-app directory
  • ui-app: A Next.js application written in typescript that uses Metamask and. ethers to interact with DefiVault smart contracts whether they are in Ropsten or deployed locally.

Corners cut

  • UI is not optimized for smaller screens
  • Gas optimization

Ethereum account (for NFT certification)

0x0484bd57f856eA52bBd00188947E37c9809276B6