Skip to content

Drakenwolf/Erc20Vault

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic Sample Hardhat Project

This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts.

Try running some of the following tasks:

npx hardhat accounts
npx hardhat compile
npx hardhat clean
npx hardhat test
npx hardhat node
node scripts/sample-script.js
npx hardhat help

TestToken and Vault Smart Contracts Documentation

This document provides an overview of the TestToken and Vault smart contracts, their features, and their functions.

TestToken

TestToken is an ERC20 token contract that uses OpenZeppelin's ERC20 and Ownable contracts to create a mintable token.

Features

  • Inherits from OpenZeppelin's ERC20 and Ownable contracts.
  • The contract owner can mint new tokens.

Functions

constructor

The constructor initializes the TestToken with a name, symbol, and initial supply.

constructor() ERC20("test", "MTK") {
    _mint(msg.sender, 4000 * 10 ** decimals());
}

mint

The mint function allows the contract owner to mint new tokens and transfer them to a specified address.

function mint(address to, uint256 amount) public onlyOwner {
    _mint(to, amount);
}

Vault

The Vault contract is a simple token vault that allows users to deposit and withdraw an ERC20 token. The vault keeps track of each user's token balance.

Features

  • Stores and manages user balances for a specific ERC20 token.
  • Allows users to deposit and withdraw tokens.
  • Uses OpenZeppelin's IERC20 interface.

Functions

constructor

The constructor sets the token address for the Vault contract.

constructor(address _tokenAddress) {
    tokenAddress = _tokenAddress;
}

depositToken

The depositToken function allows users to deposit a specified amount of tokens into the vault. Before calling this function, users must approve the vault to transfer tokens on their behalf.

function depositToken(uint256 amount) public {
    require(IERC20(tokenAddress).balanceOf(msg.sender) >= amount, "Your token amount must be greater then you are trying to deposit");
    IERC20(tokenAddress).transferFrom(msg.sender, address(this), amount);
    userTokenBalance[msg.sender][tokenAddress] += amount;
    emit tokenDepositComplete(tokenAddress, amount);
}

withDrawAll

The withDrawAll function allows users to withdraw all their tokens from the vault.

function withDrawAll() public {
    require(userTokenBalance[msg.sender][tokenAddress] > 0, "User doesnt has funds on this vault");
    uint256 amount = userTokenBalance[msg.sender][tokenAddress];
    IERC20(tokenAddress).transfer(msg.sender, amount);
    userTokenBalance[msg.sender][tokenAddress] = 0;
    emit tokenWithdrawalComplete(tokenAddress, amount);
}

withDrawAmount

The withDrawAmount function allows users to withdraw a specified amount of tokens from the vault.

function withDrawAmount(uint256 amount) public {
    require(userTokenBalance[msg.sender][tokenAddress] >= amount);
    IERC20(tokenAddress).transfer(msg.sender, amount);
    userTokenBalance[msg.sender][tokenAddress] -= amount;
    emit tokenWithdrawalComplete(tokenAddress, amount);
}

Events

  • tokenDepositComplete: Emitted when a user deposits tokens into the vault.
  • tokenWithdrawalComplete: Emitted when a user withdraws tokens from the vault.

Please note that this documentation provides an overview of the TestToken and Vault smart contracts, but a complete security audit should still be performed by a professional auditor before deploying these contracts to the mainnet.

About

This is a basic vault that can where you can deposit and withdraw an specific erc20 currency. The contract includes a sample erc20 but you change the address on deployment by any other erc20 like usdt or bnb

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors