-
Notifications
You must be signed in to change notification settings - Fork 7
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
SMR-1834-WETH-Bridging #12
Merged
Merged
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8b8df0f
WIP
proletesseract a3dcb0d
Merge branch 'sprint-1-poc' into SMR-1834-WETH-Bridging
proletesseract ea4dcdc
Fix failing test
ermyas 853c365
last patches and tests added
proletesseract 1335e14
formatting
proletesseract 05a4e93
Delete IERC20.sol
proletesseract 29487d8
Update RootERC20Bridge.sol
proletesseract 11aa4ba
updated comment, reordered functions
proletesseract 364d73f
Update RootERC20Bridge.sol
proletesseract f2beb02
feedback applied
proletesseract 0a6034a
formatting
proletesseract 5e0b1c5
Merge branch 'sprint-1-poc' into SMR-1834-WETH-Bridging
proletesseract d07713c
formatting
proletesseract c806901
deploy scripts WIP
proletesseract 140b51b
readme updates
proletesseract cd63d62
final patches
proletesseract d4bc8cb
formatting
proletesseract File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-License-Identifier: Apache 2.0 | ||
pragma solidity ^0.8.21; | ||
|
||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
/** | ||
* @dev Interface of Wrapped ETH. | ||
*/ | ||
interface IWETH is IERC20 { | ||
/** | ||
* @dev Emitted when `value` native ETH are deposited from `account`. | ||
*/ | ||
event Deposit(address indexed account, uint256 value); | ||
|
||
/** | ||
* @dev Emitted when `value` wETH tokens are withdrawn to `account`. | ||
*/ | ||
event Withdrawal(address indexed account, uint256 value); | ||
|
||
/** | ||
* @notice Deposit native ETH in the function call and mint the equal amount of wrapped ETH to msg.sender. | ||
*/ | ||
function deposit() external payable; | ||
|
||
/** | ||
* @notice Withdraw given amount of native ETH to msg.sender and burn the equal amount of wrapped ETH. | ||
* @param value The amount to withdraw. | ||
*/ | ||
function withdraw(uint256 value) external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.21; | ||
|
||
import {IWETH} from "../../interfaces/root/IWETH.sol"; | ||
import {Address} from "@openzeppelin/contracts/utils/Address.sol"; | ||
|
||
/** | ||
* @notice WETH is a wrapped ETH contract that allows users to wrap their native ETH. | ||
* @dev This contract is adapted from the official Wrapped ETH contract. | ||
*/ | ||
contract WETH is IWETH { | ||
string public name = "Wrapped ETH"; | ||
string public symbol = "WETH"; | ||
uint8 public decimals = 18; | ||
|
||
mapping(address => uint256) public balanceOf; | ||
mapping(address => mapping(address => uint256)) public allowance; | ||
|
||
/** | ||
* @notice Fallback function on recieving native ETH. | ||
*/ | ||
receive() external payable { | ||
deposit(); | ||
} | ||
|
||
/** | ||
* @notice Deposit native ETH in the function call and mint the equal amount of wrapped ETH to msg.sender. | ||
*/ | ||
function deposit() public payable { | ||
balanceOf[msg.sender] += msg.value; | ||
emit Deposit(msg.sender, msg.value); | ||
} | ||
|
||
/** | ||
* @notice Withdraw given amount of native ETH to msg.sender and burn the equal amount of wrapped ETH. | ||
* @param wad The amount to withdraw. | ||
*/ | ||
function withdraw(uint256 wad) public { | ||
require(balanceOf[msg.sender] >= wad, "Wrapped ETH: Insufficient balance"); | ||
balanceOf[msg.sender] -= wad; | ||
|
||
Address.sendValue(payable(msg.sender), wad); | ||
emit Withdrawal(msg.sender, wad); | ||
} | ||
|
||
/** | ||
* @notice Obtain the current total supply of wrapped ETH. | ||
* @return uint The amount of supplied wrapped ETH. | ||
*/ | ||
function totalSupply() public view returns (uint256) { | ||
return address(this).balance; | ||
} | ||
|
||
/** | ||
* @notice Approve given spender the ability to spend a given amount of msg.sender's tokens. | ||
* @param guy Approved spender. | ||
* @param wad Amount of allowance. | ||
* @return bool Returns true if function call is successful. | ||
*/ | ||
function approve(address guy, uint256 wad) public returns (bool) { | ||
allowance[msg.sender][guy] = wad; | ||
emit Approval(msg.sender, guy, wad); | ||
return true; | ||
} | ||
|
||
/** | ||
* @notice Transfer given amount of tokens from msg.sender to given destination. | ||
* @param dst Destination of this transfer. | ||
* @param wad Amount of this transfer. | ||
* @return bool Returns true if function call is successful. | ||
*/ | ||
function transfer(address dst, uint256 wad) public returns (bool) { | ||
return transferFrom(msg.sender, dst, wad); | ||
} | ||
|
||
/** | ||
* @notice Transfer given amount of tokens from given source to given destination. | ||
* @param src Source of this transfer. | ||
* @param dst Destination of this transfer. | ||
* @param wad Amount of this transfer. | ||
* @return bool Returns true if function call is successful. | ||
*/ | ||
function transferFrom(address src, address dst, uint256 wad) public returns (bool) { | ||
require(balanceOf[src] >= wad, "Wrapped ETH: Insufficient balance"); | ||
|
||
if (src != msg.sender && allowance[src][msg.sender] != type(uint256).max) { | ||
require(allowance[src][msg.sender] >= wad, "Wrapped ETH: Insufficient allowance"); | ||
allowance[src][msg.sender] -= wad; | ||
} | ||
|
||
balanceOf[src] -= wad; | ||
balanceOf[dst] += wad; | ||
|
||
emit Transfer(src, dst, wad); | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could we add the steps into ./deploy.sh that deploy WETH (if local), and instructions in README for how to trigger this local deployment of WETH, and explaining that it needs to be manually set
iff
./deploy.sh is not going to be run with the local flag