From 4f6a3c1a93b3bafe381ca85538e5618ecffde52c Mon Sep 17 00:00:00 2001 From: kelemeno Date: Wed, 24 Jan 2024 18:03:59 +0000 Subject: [PATCH] modified weth deployment --- l2-contracts/contracts/bridge/L2Weth.sol | 22 +++++++++---------- .../contracts/bridge/L2WethBridge.sol | 3 +-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/l2-contracts/contracts/bridge/L2Weth.sol b/l2-contracts/contracts/bridge/L2Weth.sol index 4164ed8d2..e4aa8d79b 100644 --- a/l2-contracts/contracts/bridge/L2Weth.sol +++ b/l2-contracts/contracts/bridge/L2Weth.sol @@ -37,11 +37,20 @@ contract L2Weth is ERC20PermitUpgradeable, IL2Weth, IL2StandardToken { } /// @notice Initializes a contract token for later use. Expected to be used in the proxy. + /// @notice This function is used to integrate the previously deployed WETH token with the bridge. /// @dev Sets up `name`/`symbol`/`decimals` getters. /// @param name_ The name of the token. /// @param symbol_ The symbol of the token. + /// @param _l2Bridge Address of the L2 bridge + /// @param _l1Address Address of the L1 token that can be deposited to mint this L2 WETH. /// Note: The decimals are hardcoded to 18, the same as on Ether. - function initialize(string memory name_, string memory symbol_) external initializer { + function initializeV2(string memory name_, string memory symbol_, address _l2Bridge, address _l1Address, bool _isEthBaseToken) external reinitializer(2) { + require(_l2Bridge != address(0), "L2 bridge address cannot be zero"); + require(_l1Address != address(0), "L1 WETH token address cannot be zero"); + l2Bridge = _l2Bridge; + l1Address = _l1Address; + isEthBaseToken = _isEthBaseToken; + // Set decoded values for name and symbol. __ERC20_init_unchained(name_, symbol_); @@ -51,17 +60,6 @@ contract L2Weth is ERC20PermitUpgradeable, IL2Weth, IL2StandardToken { emit Initialize(name_, symbol_, 18); } - /// @notice This function is used to integrate the previously deployed WETH token with the bridge. - /// @param _l2Bridge Address of the L2 bridge - /// @param _l1Address Address of the L1 token that can be deposited to mint this L2 WETH. - function initializeV2(address _l2Bridge, address _l1Address, bool _isEthBaseToken) external reinitializer(2) { - require(_l2Bridge != address(0), "L2 bridge address cannot be zero"); - require(_l1Address != address(0), "L1 WETH token address cannot be zero"); - l2Bridge = _l2Bridge; - l1Address = _l1Address; - isEthBaseToken = _isEthBaseToken; - } - modifier onlyBridge() { require(msg.sender == l2Bridge, "permission denied"); // Only L2 bridge can call this method _; diff --git a/l2-contracts/contracts/bridge/L2WethBridge.sol b/l2-contracts/contracts/bridge/L2WethBridge.sol index 5f3dd1bd7..1cc8b4feb 100644 --- a/l2-contracts/contracts/bridge/L2WethBridge.sol +++ b/l2-contracts/contracts/bridge/L2WethBridge.sol @@ -62,13 +62,12 @@ contract L2WethBridge is IL2Bridge, Initializable { if (block.chainid != ERA_CHAIN_ID){ address l2WethImplementation = address(new L2Weth{salt: bytes32(0)}()); - bytes memory initData = abi.encodeWithSelector(L2Weth.initializeV2.selector, "Wrapped Ether", "WETH"); + bytes memory initData = abi.encodeWithSelector(L2Weth.initializeV2.selector, "Wrapped Ether", "WETH", address(this), l1WethAddress, _isEthBaseToken); TransparentUpgradeableProxy l2Weth = new TransparentUpgradeableProxy{salt: bytes32(0)}( l2WethImplementation, _aliasedOwner, initData ); - L2Weth(payable(address(l2Weth))).initializeV2(address(this), l1WethAddress, _isEthBaseToken); l2WethAddress = address(l2Weth); } else { // we deployed Weth on Era earlier, and also initializeV2 it separately as we upgrade