Giter Club home page Giter Club logo

basic-vault's Introduction

Objectives: multi-user safe

[yieldprotocol/mentorship2022#2]

  1. This is a single-token Vault that holds a pre-specified erc-20 token.
  2. Users can send tokens to the Vault contract.
  3. Vault contract records the user's token deposits.
  4. Users can withdraw their tokens only to the address they deposited from.

Contracts

  • ERC20Mock.sol
  • BasicVault.sol

Vault contract

  1. Deposit: After approval (handles by front-end), token is deposited via transferFrom.
  2. Withdraw: Token is returned, and the Vault updates its user records.

Vault contract should import the IERC20 interface, take the Token address in the Vault constructor, and cast it into an IERC20 state variable

ERC2Mock contract

  1. Public, unrestricted mint() function (anyone should be able to mint)
  2. Instead of OpenZepplin implementation, import https://github.com/yieldprotocol/yield-utils-v2/blob/main/contracts/mocks/ERC20Mock.sol

Additional Details

  1. Add full NatSpec: the contract as well as every event and function should have complete NatSpec.
  1. Implement CI so when you push to gh, your tests are run automatically. https://gist.github.com/clifton/b5ee5286bb229281fb31d7c4b15e6f31 https://book.getfoundry.sh/config/continous-integration.html

Testing

  • Vault contract should be fully tested.
  • No need to test ERC20Mock. Assume it works as intended.

Testing States

StateZero (user has no tokens)

  • cannot deposit (testUserCannotWithdraw)
  • cannot withdraw (testUserCannotDeposit)
  • fuzz testing (testUserMintApproveDeposit) ** unsure to keep testUserMintApproveDeposit. but was looking for a positive test condition to end this state phase.

StateTokensMinted (user has minted 100 wmd tokens) (only action available is deposit)

  • if transfer fails, deposit should revert (testDepositRevertsIfTransferFails)
  • deposit tokens into vault (testDeposit)

StateTokensDeposited (user has deposited tokens into Vault)

  • cannot withdraw if transfer fails (testWithdrawRevertsIfTransferFails)
  • cannot withdraw more than deposit (testUserCannotWithdrawExcessOfDeposit)
  • partial withdrawal (testUserWithdrawPartial)
  • full withdrawal (testUserWithdrawAll)

Testing Guidelines

  • All state variable changes in the contracts that you code.
  • All state variable changes in other contracts caused by calls from contracts that you code.
  • All require or revert in the contracts that you code.
  • All events being emitted.
  • All return values in contracts that you code.

Deployment

Tenderly

For monitoring/alerts as well as for simulating transactions before running them and also for reviewing transactions after the fact. After you have deployed your vault and done some transactions via etherscan, go on to Tenderly and inspect one of those transactions. There is also a debugger (similar to Foundry debugger) that allows you to step through opcodes. If you're up for it, try simulating a transaction as well. Here is a video of Alberto demo'ing Tenderly: [https://drive.google.com/file/d/1fW16HhnP_Swc4in-fevFf5Z_1Og_p6za/view]

basic-vault's People

Contributors

calnix avatar

Watchers

 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.