Commit c8277f3b authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

contracts-bedrock: update weth98 (#10102)

* contracts-bedrock: update weth98

The custom gas token project is moving away from using
the original weth9 code as a predeploy to using the
weth98 code as a predeploy. As part of this, the ability
to override the name and symbol are required for chains
that use a custom gas token. There is no way to
mark an inline declaration as `virtual`, it requires
moving to a `function` syntax. Definitely less clean
looking but necessary to support the override ability.

The implementation of the new WETH predeploy is as follows:

```solidity
contract WETH is WETH98 {
    /// @notice Returns the name of the token from the L1Block contract
    function name() external view override returns (string memory) {
        return string.concat("Wrapped ", L1Block(Predeploys.L1_BLOCK_ATTRIBUTES).gasPayingTokenName());
    }

    /// @notice Returns the symbol of the token from the L1Block contract
    function symbol() external view override returns (string memory) {
        return string.concat("W", L1Block(Predeploys.L1_BLOCK_ATTRIBUTES).gasPayingTokenSymbol());
    }
}
```

Where when not in custom gas token mode, it with return `Wrapped Ether`
and `WETH`, so it is backwards compatible.

This commit also adds a fallback function since the original weth9 has
a fallback function but this one does not. While the receive function
can work, adding the fallback function ensures that the same behavior
as weth9 is achieved when making a call that includes calldata + value.

* contracts-bedrock: fix compile

* snapshots: update

* op-bindings: regenerate

* contracts-bedrock: cleanup weth98

* contracts-bedrock: semver lock

* contracts-bedrock: weth98 tests

* lint: fix
parent 71342ebf
This diff is collapsed.
This diff is collapsed.
...@@ -116,7 +116,7 @@ ...@@ -116,7 +116,7 @@
"sourceCodeHash": "0xc5f90543341e426d0fbc834e997a727c9b71e118491a935afd61fe053c134811" "sourceCodeHash": "0xc5f90543341e426d0fbc834e997a727c9b71e118491a935afd61fe053c134811"
}, },
"src/dispute/weth/DelayedWETH.sol": { "src/dispute/weth/DelayedWETH.sol": {
"initCodeHash": "0xf179e4249be6eda22b24ae2b32717f154f35edeb9dee0332aefa6fad3ace4dbe", "initCodeHash": "0x7b6ec89eaec09e369426e73161a9c6932223bb1f974377190c3f6f552995da35",
"sourceCodeHash": "0x1a37c92242f612588f60256554107ee675678687b49b1f41087411dfcd6aabd3" "sourceCodeHash": "0x1a37c92242f612588f60256554107ee675678687b49b1f41087411dfcd6aabd3"
}, },
"src/legacy/DeployerWhitelist.sol": { "src/legacy/DeployerWhitelist.sol": {
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "constructor" "type": "constructor"
}, },
{
"stateMutability": "payable",
"type": "fallback"
},
{ {
"stateMutability": "payable", "stateMutability": "payable",
"type": "receive" "type": "receive"
......
[ [
{
"stateMutability": "payable",
"type": "fallback"
},
{ {
"stateMutability": "payable", "stateMutability": "payable",
"type": "receive" "type": "receive"
......
...@@ -28,11 +28,11 @@ interface IWETH { ...@@ -28,11 +28,11 @@ interface IWETH {
/// @notice Returns the name of the token. /// @notice Returns the name of the token.
/// @return The name of the token. /// @return The name of the token.
function name() external pure returns (string memory); function name() external view returns (string memory);
/// @notice Returns the symbol of the token. /// @notice Returns the symbol of the token.
/// @return The symbol of the token. /// @return The symbol of the token.
function symbol() external pure returns (string memory); function symbol() external view returns (string memory);
/// @notice Returns the number of decimals the token uses. /// @notice Returns the number of decimals the token uses.
/// @return The number of decimals the token uses. /// @return The number of decimals the token uses.
......
...@@ -24,8 +24,6 @@ import { IWETH } from "src/dispute/interfaces/IWETH.sol"; ...@@ -24,8 +24,6 @@ import { IWETH } from "src/dispute/interfaces/IWETH.sol";
/// @title WETH98 /// @title WETH98
/// @notice WETH98 is a version of WETH9 upgraded for Solidity 0.8.x. /// @notice WETH98 is a version of WETH9 upgraded for Solidity 0.8.x.
contract WETH98 is IWETH { contract WETH98 is IWETH {
string public constant name = "Wrapped Ether";
string public constant symbol = "WETH";
uint8 public constant decimals = 18; uint8 public constant decimals = 18;
mapping(address => uint256) public balanceOf; mapping(address => uint256) public balanceOf;
...@@ -36,6 +34,21 @@ contract WETH98 is IWETH { ...@@ -36,6 +34,21 @@ contract WETH98 is IWETH {
deposit(); 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 /// @inheritdoc IWETH
function deposit() public payable { function deposit() public payable {
balanceOf[msg.sender] += msg.value; balanceOf[msg.sender] += msg.value;
......
pragma solidity 0.8.15;
import { Test } from "forge-std/Test.sol";
import { WETH98 } from "src/dispute/weth/WETH98.sol";
contract WETH98_Test is Test {
WETH98 public weth;
address alice;
function setUp() public {
weth = new WETH98();
alice = makeAddr("alice");
deal(alice, 1 ether);
}
function test_receive_succeeds() public {
vm.prank(alice);
(bool success,) = address(weth).call{ value: 1 ether }("");
assertTrue(success);
assertEq(weth.balanceOf(alice), 1 ether);
}
function test_fallback_succeeds() public {
vm.prank(alice);
(bool success,) = address(weth).call{ value: 1 ether }(hex"1234");
assertTrue(success);
assertEq(weth.balanceOf(alice), 1 ether);
}
function test_getName_succeeds() public {
assertEq(weth.name(), "Wrapped Ether");
assertEq(weth.symbol(), "WETH");
assertEq(weth.decimals(), 18);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment