Skip to content

Commit

Permalink
将原vault合约变成草稿
Browse files Browse the repository at this point in the history
  • Loading branch information
eiyen committed Apr 12, 2023
1 parent c94f1bf commit e49a3c4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions W3-1/contracts/TokenVault-draft.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract TokenVault {
IERC20 public myToken;
mapping(address => uint256) public deposits;

constructor(address corrorTokenAddress) {
myToken = IERC20(corrorTokenAddress);
}

function deposit(uint256 amount) public {
require(myToken.transferFrom(msg.sender, address(this), amount), "Transfer failed");
deposits[msg.sender] += amount;
}

function withdraw(uint256 amount) public {
require(deposits[msg.sender] > amount, "Insufficient balance");
deposits[msg.sender] -= amount;
require(myToken.transfer(msg.sender, amount), "Transfer failed");
}
}

0 comments on commit e49a3c4

Please sign in to comment.