-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathWETH98.sol
99 lines (77 loc) · 2.95 KB
/
WETH98.sol
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// SPDX-License-Identifier: GPL-3.0
// Copyright (C) 2015, 2016, 2017 Dapphub
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Based on WETH9 by Dapphub.
// Modified by OP Labs.
pragma solidity 0.8.15;
import { IWETH } from "src/universal/interfaces/IWETH.sol";
/// @title WETH98
/// @notice WETH98 is a version of WETH9 upgraded for Solidity 0.8.x.
contract WETH98 is IWETH {
uint8 public constant decimals = 18;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
/// @notice Pipes to deposit.
receive() external payable {
deposit();
}
/// @notice Pipes to deposit.
fallback() external payable {
deposit();
}
/// @inheritdoc IWETH
function name() external view virtual override returns (string memory) {
return "Wrapped Ether";
}
/// @inheritdoc IWETH
function symbol() external view virtual override returns (string memory) {
return "WETH";
}
/// @inheritdoc IWETH
function deposit() public payable virtual {
balanceOf[msg.sender] += msg.value;
emit Deposit(msg.sender, msg.value);
}
/// @inheritdoc IWETH
function withdraw(uint256 wad) public virtual {
require(balanceOf[msg.sender] >= wad);
balanceOf[msg.sender] -= wad;
payable(msg.sender).transfer(wad);
emit Withdrawal(msg.sender, wad);
}
/// @inheritdoc IWETH
function totalSupply() external view returns (uint256) {
return address(this).balance;
}
/// @inheritdoc IWETH
function approve(address guy, uint256 wad) external returns (bool) {
allowance[msg.sender][guy] = wad;
emit Approval(msg.sender, guy, wad);
return true;
}
/// @inheritdoc IWETH
function transfer(address dst, uint256 wad) external returns (bool) {
return transferFrom(msg.sender, dst, wad);
}
/// @inheritdoc IWETH
function transferFrom(address src, address dst, uint256 wad) public returns (bool) {
require(balanceOf[src] >= wad);
if (src != msg.sender && allowance[src][msg.sender] != type(uint256).max) {
require(allowance[src][msg.sender] >= wad);
allowance[src][msg.sender] -= wad;
}
balanceOf[src] -= wad;
balanceOf[dst] += wad;
emit Transfer(src, dst, wad);
return true;
}
}