-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WETH deposit and withdraw on OVM_ETH #1083
Changes from 7 commits
f7f5aa4
a8dcc01
a15145a
b874e04
0d6a01c
4ac2c1e
537d677
dcf4039
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@eth-optimism/integration-tests': patch | ||
'@eth-optimism/contracts': patch | ||
--- | ||
|
||
Add WETH9 compatible deposit and withdraw functions to OVM_ETH |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import { Lib_PredeployAddresses } from "../../libraries/constants/Lib_PredeployA | |
|
||
/* Contract Imports */ | ||
import { L2StandardERC20 } from "../../libraries/standards/L2StandardERC20.sol"; | ||
import { IWETH9 } from "../../libraries/standards/IWETH9.sol"; | ||
|
||
/** | ||
* @title OVM_ETH | ||
|
@@ -15,7 +16,7 @@ import { L2StandardERC20 } from "../../libraries/standards/L2StandardERC20.sol"; | |
* Compiler used: optimistic-solc | ||
* Runtime target: OVM | ||
*/ | ||
contract OVM_ETH is L2StandardERC20 { | ||
contract OVM_ETH is L2StandardERC20, IWETH9 { | ||
|
||
/*************** | ||
* Constructor * | ||
|
@@ -29,4 +30,50 @@ contract OVM_ETH is L2StandardERC20 { | |
"ETH" | ||
) | ||
{} | ||
|
||
|
||
/****************************** | ||
* Custom WETH9 Functionality * | ||
K-Ho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
******************************/ | ||
fallback() external payable { | ||
deposit(); | ||
} | ||
|
||
/** | ||
* Implements the WETH9 deposit() function as a no-op. | ||
* WARNING: this function does NOT have to do with cross-chain asset bridging. The | ||
* relevant deposit and withdraw functions for that use case can be found at L2StandardBridge.sol. | ||
* This function allows developers to treat OVM_ETH as WETH without any modifications to their code. | ||
*/ | ||
function deposit() | ||
public | ||
K-Ho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
payable | ||
override | ||
{ | ||
// Calling deposit() with nonzero value will send the ETH to this contract address. Once recieved here, | ||
// We transfer it back by sending to the msg.sender. | ||
_transfer(address(this), msg.sender, msg.value); | ||
|
||
emit Deposit(msg.sender, msg.value); | ||
} | ||
|
||
/** | ||
* Implements the WETH9 withdraw() function as a no-op. | ||
* WARNING: this function does NOT have to do with cross-chain asset bridging. The | ||
* relevant deposit and withdraw functions for that use case can be found at L2StandardBridge.sol. | ||
* This function allows developers to treat OVM_ETH as WETH without any modifications to their code. | ||
* @param _wad Amount being withdrawn | ||
*/ | ||
function withdraw( | ||
uint256 _wad | ||
) | ||
external | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Visibility here is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deposit is used in the fallback, so it has to be public. John requested everything that can be to be changed to external, but we could just keep them public to remain loyal to the original implementation 🤷🏻♂️. #1083 (comment) |
||
override | ||
{ | ||
// Calling withdraw() with value exceeding the withdrawer's ovmBALANCE should revert, as in WETH9. | ||
require(balanceOf(msg.sender) >= _wad); | ||
|
||
// Other than emitting an event, OVM_ETH already is native ETH, so we don't need to do anything else. | ||
emit Withdrawal(msg.sender, _wad); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity =0.7.6; | ||
|
||
/// @title Interface for WETH9 | ||
import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; | ||
|
||
/// @title Interface for WETH9 | ||
K-Ho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
interface IWETH9 is IERC20 { | ||
event Deposit(address indexed dst, uint256 wad); | ||
event Withdrawal(address indexed src, uint256 wad); | ||
|
||
/// @notice Deposit ether to get wrapped ether | ||
function deposit() external payable; | ||
|
||
/// @notice Withdraw wrapped ether to get ether | ||
function withdraw(uint256) external; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a successful deposit why would the balance be the same as the initial balance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we're adding
deposit
andwithdraw
to do nothing. If you want to "deposit" (wrap) your ETH into WETH, you actually don't need to do anything, since ETH is already an ERC20 in L2. This is just being added to be backwards compatible with people's contracts that assume that you have to calldeposit
to wrap your ETH to be ERC20-compatible.