Skip to content

Commit

Permalink
remove setETHGateway
Browse files Browse the repository at this point in the history
  • Loading branch information
zimpha committed Feb 1, 2024
1 parent c06f705 commit 223538d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 65 deletions.
17 changes: 7 additions & 10 deletions contracts/src/L1/gateways/IL1GatewayRouter.sol
Expand Up @@ -10,11 +10,6 @@ interface IL1GatewayRouter is IL1ETHGateway, IL1ERC20Gateway {
* Events *
**********/

/// @notice Emitted when the address of ETH Gateway is updated.
/// @param oldETHGateway The address of the old ETH Gateway.
/// @param newEthGateway The address of the new ETH Gateway.
event SetETHGateway(address indexed oldETHGateway, address indexed newEthGateway);

/// @notice Emitted when the address of default ERC20 Gateway is updated.
/// @param oldDefaultERC20Gateway The address of the old default ERC20 Gateway.
/// @param newDefaultERC20Gateway The address of the new default ERC20 Gateway.
Expand All @@ -26,6 +21,13 @@ interface IL1GatewayRouter is IL1ETHGateway, IL1ERC20Gateway {
/// @param newGateway The corresponding address of the new gateway.
event SetERC20Gateway(address indexed token, address indexed oldGateway, address indexed newGateway);

/**********
* Errors *
**********/

/// @dev Thrown when the given address is `address(0)`.
error ErrorZeroAddress();

/*************************
* Public View Functions *
*************************/
Expand All @@ -52,11 +54,6 @@ interface IL1GatewayRouter is IL1ETHGateway, IL1ERC20Gateway {
* Restricted Functions *
************************/

/// @notice Update the address of ETH gateway contract.
/// @dev This function should only be called by contract owner.
/// @param _ethGateway The address to update.
function setETHGateway(address _ethGateway) external;

/// @notice Update the address of default ERC20 gateway contract.
/// @dev This function should only be called by contract owner.
/// @param _defaultERC20Gateway The address to update.
Expand Down
15 changes: 0 additions & 15 deletions contracts/src/L1/gateways/L1GatewayRouter.sol
Expand Up @@ -19,13 +19,6 @@ import {IL1GatewayRouter} from "./IL1GatewayRouter.sol";
contract L1GatewayRouter is OwnableUpgradeable, IL1GatewayRouter {
using SafeERC20Upgradeable for IERC20Upgradeable;

/**********
* Errors *
**********/

/// @dev Thrown when the given address is `address(0)`.
error ErrorZeroAddress();

/*************
* Constants *
*************/
Expand Down Expand Up @@ -244,14 +237,6 @@ contract L1GatewayRouter is OwnableUpgradeable, IL1GatewayRouter {
* Restricted Functions *
************************/

/// @inheritdoc IL1GatewayRouter
function setETHGateway(address _newEthGateway) external onlyOwner {
address _oldETHGateway = ethGateway;
ethGateway = _newEthGateway;

emit SetETHGateway(_oldETHGateway, _newEthGateway);
}

/// @inheritdoc IL1GatewayRouter
function setDefaultERC20Gateway(address _newDefaultERC20Gateway) external onlyOwner {
address _oldDefaultERC20Gateway = defaultERC20Gateway;
Expand Down
12 changes: 7 additions & 5 deletions contracts/src/L2/gateways/IL2GatewayRouter.sol
Expand Up @@ -10,11 +10,6 @@ interface IL2GatewayRouter is IL2ETHGateway, IL2ERC20Gateway {
* Events *
**********/

/// @notice Emitted when the address of ETH Gateway is updated.
/// @param oldETHGateway The address of the old ETH Gateway.
/// @param newEthGateway The address of the new ETH Gateway.
event SetETHGateway(address indexed oldETHGateway, address indexed newEthGateway);

/// @notice Emitted when the address of default ERC20 Gateway is updated.
/// @param oldDefaultERC20Gateway The address of the old default ERC20 Gateway.
/// @param newDefaultERC20Gateway The address of the new default ERC20 Gateway.
Expand All @@ -25,4 +20,11 @@ interface IL2GatewayRouter is IL2ETHGateway, IL2ERC20Gateway {
/// @param oldGateway The corresponding address of the old gateway.
/// @param newGateway The corresponding address of the new gateway.
event SetERC20Gateway(address indexed token, address indexed oldGateway, address indexed newGateway);

/**********
* Errors *
**********/

/// @dev Thrown when the given address is `address(0)`.
error ErrorZeroAddress();
}
30 changes: 12 additions & 18 deletions contracts/src/L2/gateways/L2GatewayRouter.sol
Expand Up @@ -15,13 +15,6 @@ import {IL2ERC20Gateway} from "./IL2ERC20Gateway.sol";
/// @dev One can also use this contract to query L1/L2 token address mapping.
/// In the future, ERC-721 and ERC-1155 tokens will be added to the router too.
contract L2GatewayRouter is OwnableUpgradeable, IL2GatewayRouter {
/**********
* Errors *
**********/

/// @dev Thrown when the given address is `address(0)`.
error ErrorZeroAddress();

/*************
* Constants *
*************/
Expand Down Expand Up @@ -55,7 +48,16 @@ contract L2GatewayRouter is OwnableUpgradeable, IL2GatewayRouter {
messenger = _messenger;
}

function initialize(address _ethGateway, address _defaultERC20Gateway) external initializer {
/// @notice Initialize the storage of L2GatewayRouter.
///
/// @dev The parameters `_ethGateway` is no longer used.
///
/// @param _defaultERC20Gateway The address of default ERC20 Gateway contract.
function initialize(
address,
/*_ethGateway*/
address _defaultERC20Gateway
) external initializer {
OwnableUpgradeable.__Ownable_init();

// it can be zero during initialization
Expand All @@ -64,11 +66,13 @@ contract L2GatewayRouter is OwnableUpgradeable, IL2GatewayRouter {
emit SetDefaultERC20Gateway(address(0), _defaultERC20Gateway);
}

/* comment out since it is no longer used.
// it can be zero during initialization
if (_ethGateway != address(0)) {
ethGateway = _ethGateway;
emit SetETHGateway(address(0), _ethGateway);
}
*/
}

/*************************
Expand Down Expand Up @@ -190,16 +194,6 @@ contract L2GatewayRouter is OwnableUpgradeable, IL2GatewayRouter {
* Restricted Functions *
************************/

/// @notice Update the address of ETH gateway contract.
/// @dev This function should only be called by contract owner.
/// @param _newEthGateway The address to update.
function setETHGateway(address _newEthGateway) external onlyOwner {
address _oldEthGateway = ethGateway;
ethGateway = _newEthGateway;

emit SetETHGateway(_oldEthGateway, _newEthGateway);
}

/// @notice Update the address of default ERC20 gateway contract.
/// @dev This function should only be called by contract owner.
/// @param _newDefaultERC20Gateway The address to update.
Expand Down
17 changes: 0 additions & 17 deletions contracts/src/test/L2GatewayRouter.t.sol
Expand Up @@ -114,7 +114,6 @@ contract L2GatewayRouterTest is L2GatewayTestBase {
}

function testInitialized() public {
assertEq(address(l2ETHGateway), router.ethGateway());
assertEq(address(l2StandardERC20Gateway), router.defaultERC20Gateway());
assertEq(address(l2StandardERC20Gateway), router.getERC20Gateway(address(l2Token)));

Expand Down Expand Up @@ -181,20 +180,4 @@ contract L2GatewayRouterTest is L2GatewayTestBase {
hevm.expectRevert("should never be called");
router.finalizeDepositETH(address(0), address(0), 0, "");
}

function testSetETHGateway(address gateway) public {
// set by non-owner, should revert
hevm.startPrank(address(1));
hevm.expectRevert("Ownable: caller is not the owner");
router.setETHGateway(gateway);
hevm.stopPrank();

// set by owner, should succeed
hevm.expectEmit(true, true, false, true);
emit SetETHGateway(address(l2ETHGateway), gateway);

assertEq(address(l2ETHGateway), router.ethGateway());
router.setETHGateway(gateway);
assertEq(gateway, router.ethGateway());
}
}

0 comments on commit 223538d

Please sign in to comment.