-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWETH-230928-121007.sol
More file actions
63 lines (47 loc) · 1.98 KB
/
WETH-230928-121007.sol
File metadata and controls
63 lines (47 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
contract WETH {
string public name = "Wrapped Ether";
string public symbol = "WETH";
uint8 public decimals = 18;
uint256 public constant maxInt = type(uint256).max;
event LogDeposit(address _src, uint _amount);
event LogWithdraw(address _src, uint _amount);
event LogApproved(address _sender, address _receiver, uint _amount);
event LogTransfer(address _src, address _dst, uint _amount);
mapping (address => uint) public balanceOf;
mapping (address => mapping (address => uint)) public allowance;
constructor() {}
function deposit() public payable {
balanceOf[msg.sender] += msg.value;
emit LogDeposit(msg.sender, msg.value);
}
function withdraw(uint _amount) public {
require(balanceOf[msg.sender] >= _amount, "not enough funds!");
balanceOf[msg.sender] -= _amount;
payable(msg.sender).transfer(_amount);
emit LogWithdraw(msg.sender, _amount);
}
function totalSupply() public view returns(uint) {
return address(this).balance;
}
function approve(address _account, uint _amount) public returns(bool) {
allowance[msg.sender][_account] = _amount;
emit LogApproved(msg.sender, _account, _amount);
return true;
}
function transfer(address _dst, uint _amount) public returns (bool){
return transferFrom(msg.sender, _dst, _amount);
}
function transferFrom(address _src, address _dst, uint _amount) public returns (bool){
require(balanceOf[_src] >= _amount, "not enough funds!");
if(_src != msg.sender && allowance[_src][msg.sender] != maxInt) {
require(allowance[_src][msg.sender] >= _amount, "not enough allowance");
allowance[_src][msg.sender] -= _amount;
}
balanceOf[_src] -= _amount;
balanceOf[_dst] += _amount;
emit LogTransfer(_src, _dst, _amount);
return true;
}
}