Giter VIP home page Giter VIP logo

tokenvault's Introduction

TokenVault Contract

A Simple vault contract, calculating shares to mint on deposit and the amount of tokens to withdraw.

Overview of working

  • User deposit underlying staking token and in return gets shares which acts as their representation.
  • Vault will accrue yield on top of the deposited tokens via further lending the tokens to others DeFi protocols.
  • User anytime can redeem these shares against it's principal amount plus any yield generated on top of it.

Code Overview

The TokenVault contract is written in Solidity and uses the OpenZeppelin ERC20 contract interface. The following are the public functions of the contract:

Constructor

The constructor function takes a single parameter, _token, which is the address of the ERC20 token that the vault will hold.

depositTokens Function

The depositTokens function is called by a user to deposit tokens into the vault. The function calculates the number of shares to mint based on the current total number of shares and the amount of tokens being deposited. The function then mints the shares and transfers the tokens from the user's address to the vault.

withdrawTokens Function

The withdrawTokens function is called by a user to withdraw tokens from the vault. The function calculates the amount of tokens to withdraw based on the number of shares being burned and the current balance of the ERC20 token held by the vault. The function then burns the shares and transfers the tokens to the user's address.

mintShares and burnShares Functions

The mintShares and burnShares functions are private functions used to update the total number of shares and the balance of shares held by a particular user.

License

This code is licensed under the MIT License. See the LICENSE file for more information.

Try running some of the following tasks:

npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test
npx hardhat node
npx hardhat run scripts/deploy.js

tokenvault's People

Contributors

akkii4 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.