Skip to content
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 Bridge Implementation #5

Closed
wants to merge 1 commit into from

Conversation

mpopovac-txfusion
Copy link

No description provided.

Co-authored-by: mpavlovic-txfusion <[email protected]>

/// @dev The accumulated deposited amount per user.
/// @dev A mapping user address => the total deposited WETH amount by the user
mapping(address => uint256) public totalDepositedAmountPerUser;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are going to remove this limit in the next release, so better to remove it here too.

uint256 _l2TxGasLimit,
uint256 _l2TxGasPerPubdataByte
) external payable nonReentrant returns (bytes32 txHash) {
// ) external payable nonReentrant senderCanCallFunction(allowList) returns (bytes32 txHash) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Artifact?

);
}

function deposit(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: It is a bit of outdated interface, the integrating last one will be easy, so no problem. We have added the address _refundRecipient to the interface. You can find up to date info in the

require(depositedAmount == _amount, "Incorrect amount of funds deposited");

// // verify the deposit amount is allowed
// _verifyDepositLimit(msg.sender, _amount, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Artifacts?

require(_l2Receiver != address(0), "L2 receiver address can not be zero");

// Deposit WETH tokens from the depositor address to the smart contract address
uint256 depositedAmount = _transferWethFunds(msg.sender, address(this), _amount);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have used the _transferWethFunds function logic, since the token implementation was untrusted. Here the token is static and well-known. So you could use _amount instead of depositedAmount, and replace _transferWethFunds with l1Weth.safeTransferFrom(_from, _to, _amount);

For using the safeTransferFrom you need to import the https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/utils/SafeERC20.sol OZ lib.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the L1 WETH implementation we want to support https://etherscan.io/token/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2#code.
This WETH implementation is not ERC20, so unfortunately we can't use l1Weth.safeTransferFrom(_from, _to, _amount);...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. it is an ERC20, it is implement all methods from the https://eips.ethereum.org/EIPS/eip-20, so it is ERC20
  2. The safeTransferFrom is not a function on token itself, but a method from the OZ library

address public override l2WethAddress;

/// @dev ETH token address on L2.
address public constant l2EthAddress = address(0x800a);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: maybe use caps snake case for constant variables?

// Burn WETH on L2.
IL2StandardToken(l2WethAddress).bridgeBurn(msg.sender, _amount);
// Withdraw ETH to L1 bridge.
IEthToken(l2EthAddress).withdraw{value: _amount}(l1WethBridge);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need to withdraw? The bridge already burn tokens and send ether to you

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After calling the bridgeBurn method, ETH is withdrawn to the L2 WETH Bridge. It’s important to transfer the ETH to the L1 WETH Bridge after this step so that the WETH can be wrapped and sent back to the user on L1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it is me misunderstand the logic. I was confused, because I thought that the contract address that you use for withdrawing is l2WethAddress not l2EthAddress.

}

receive() external payable {}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: new line

return abi.encodePacked(IL1WethBridge.finalizeWithdrawal.selector, _l2Sender, _l1Receiver, _amount);
}

receive() external payable {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: event would be nice to have there


pragma solidity ^0.8.0;

interface IEthToken {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Suggested change
interface IEthToken {
interface IL2WethToken {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the interface for ETH on L2. We use it to withdraw ETH from the L2 WETH Bridge to the L1 WETH Bridge.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, makes perfect sense then.

@vladbochok
Copy link
Member

@mpopovac-txfusion Thanks for your contribution! This PR was merged in the private repo and migrated to this repo already. Closing it because of this reason.

@vladbochok vladbochok closed this Sep 12, 2023
StanislavBreadless pushed a commit that referenced this pull request Sep 14, 2023
benceharomi pushed a commit that referenced this pull request Nov 17, 2023
Add comment on `MAX_SYSTEM_CONTRACT_ADDRESS` choice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants