Skip to content

Commit

Permalink
modified weth deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
kelemeno committed Jan 24, 2024
1 parent b681368 commit 4f6a3c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
22 changes: 10 additions & 12 deletions l2-contracts/contracts/bridge/L2Weth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_);

Expand All @@ -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
_;
Expand Down
3 changes: 1 addition & 2 deletions l2-contracts/contracts/bridge/L2WethBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4f6a3c1

Please sign in to comment.