github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/src/dispute/weth/WETH98.sol (about)

     1  // Copyright (C) 2015, 2016, 2017 Dapphub
     2  
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU General Public License as published by
     5  // the Free Software Foundation, either version 3 of the License, or
     6  // (at your option) any later version.
     7  
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU General Public License for more details.
    12  
    13  // You should have received a copy of the GNU General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  // Based on WETH9 by Dapphub.
    17  // Modified by OP Labs.
    18  
    19  pragma solidity 0.8.15;
    20  
    21  import { IWETH } from "src/dispute/interfaces/IWETH.sol";
    22  
    23  /// @title WETH98
    24  /// @notice WETH98 is a version of WETH9 upgraded for Solidity 0.8.x.
    25  contract WETH98 is IWETH {
    26      string public constant name = "Wrapped Ether";
    27      string public constant symbol = "WETH";
    28      uint8 public constant decimals = 18;
    29  
    30      mapping(address => uint256) public balanceOf;
    31      mapping(address => mapping(address => uint256)) public allowance;
    32  
    33      /// @notice Pipes to deposit.
    34      receive() external payable {
    35          deposit();
    36      }
    37  
    38      /// @inheritdoc IWETH
    39      function deposit() public payable {
    40          balanceOf[msg.sender] += msg.value;
    41          emit Deposit(msg.sender, msg.value);
    42      }
    43  
    44      /// @inheritdoc IWETH
    45      function withdraw(uint256 wad) public virtual {
    46          require(balanceOf[msg.sender] >= wad);
    47          balanceOf[msg.sender] -= wad;
    48          payable(msg.sender).transfer(wad);
    49          emit Withdrawal(msg.sender, wad);
    50      }
    51  
    52      /// @inheritdoc IWETH
    53      function totalSupply() external view returns (uint256) {
    54          return address(this).balance;
    55      }
    56  
    57      /// @inheritdoc IWETH
    58      function approve(address guy, uint256 wad) external returns (bool) {
    59          allowance[msg.sender][guy] = wad;
    60          emit Approval(msg.sender, guy, wad);
    61          return true;
    62      }
    63  
    64      /// @inheritdoc IWETH
    65      function transfer(address dst, uint256 wad) external returns (bool) {
    66          return transferFrom(msg.sender, dst, wad);
    67      }
    68  
    69      /// @inheritdoc IWETH
    70      function transferFrom(address src, address dst, uint256 wad) public returns (bool) {
    71          require(balanceOf[src] >= wad);
    72  
    73          if (src != msg.sender && allowance[src][msg.sender] != type(uint256).max) {
    74              require(allowance[src][msg.sender] >= wad);
    75              allowance[src][msg.sender] -= wad;
    76          }
    77  
    78          balanceOf[src] -= wad;
    79          balanceOf[dst] += wad;
    80  
    81          emit Transfer(src, dst, wad);
    82  
    83          return true;
    84      }
    85  }