From bf74af23726ca45e382e6312a978f17f58fd880f Mon Sep 17 00:00:00 2001 From: gzeon Date: Tue, 15 Oct 2024 23:57:14 +0800 Subject: [PATCH] feat: RegisterAndSetArbCustomGatewayAction (#308) * feat: RegisterAndSetGatewayAction * fix: send value * chore: rename to RegisterAndSetArbCustomGatewayAction * fix: make payable --- .../RegisterAndSetArbCustomGatewayAction.sol | 52 +++++++++++++++++++ ...egisterL2TokenInArbCustomGatewayAction.sol | 8 +-- .../token-bridge/SetGatewayAction.sol | 8 +-- 3 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 src/gov-action-contracts/token-bridge/RegisterAndSetArbCustomGatewayAction.sol diff --git a/src/gov-action-contracts/token-bridge/RegisterAndSetArbCustomGatewayAction.sol b/src/gov-action-contracts/token-bridge/RegisterAndSetArbCustomGatewayAction.sol new file mode 100644 index 00000000..d3b74769 --- /dev/null +++ b/src/gov-action-contracts/token-bridge/RegisterAndSetArbCustomGatewayAction.sol @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity 0.8.16; + +import "../address-registries/interfaces.sol"; +import "./TokenBridgeActionLib.sol"; + +contract RegisterAndSetArbCustomGatewayAction { + IL1AddressRegistry public immutable addressRegistry; + + constructor(IL1AddressRegistry _addressRegistry) { + addressRegistry = _addressRegistry; + } + + function perform( + address[] memory _l1Tokens, + address[] memory _l2Tokens, + uint256 _maxGasForRegister, + uint256 _gasPriceBidForRegister, + uint256 _maxSubmissionCostForRegister, + uint256 _maxGasForSetGateway, + uint256 _gasPriceBidForSetGateway, + uint256 _maxSubmissionCostForSetGateway + ) external payable { + TokenBridgeActionLib.ensureAllContracts(_l1Tokens); + + IL1CustomGateway customGateway = addressRegistry.customGateway(); + + customGateway.forceRegisterTokenToL2{ + value: _maxGasForRegister * _gasPriceBidForRegister + _maxSubmissionCostForRegister + }( + _l1Tokens, + _l2Tokens, + _maxGasForRegister, + _gasPriceBidForRegister, + _maxSubmissionCostForRegister + ); + + address[] memory gateways = new address[](_l1Tokens.length); + for (uint256 i = 0; i < _l1Tokens.length; i++) { + gateways[i] = address(customGateway); + } + addressRegistry.gatewayRouter().setGateways{ + value: _maxGasForSetGateway * _gasPriceBidForSetGateway + _maxSubmissionCostForSetGateway + }( + _l1Tokens, + gateways, + _maxGasForSetGateway, + _gasPriceBidForSetGateway, + _maxSubmissionCostForSetGateway + ); + } +} diff --git a/src/gov-action-contracts/token-bridge/RegisterL2TokenInArbCustomGatewayAction.sol b/src/gov-action-contracts/token-bridge/RegisterL2TokenInArbCustomGatewayAction.sol index 205699d8..4222858d 100644 --- a/src/gov-action-contracts/token-bridge/RegisterL2TokenInArbCustomGatewayAction.sol +++ b/src/gov-action-contracts/token-bridge/RegisterL2TokenInArbCustomGatewayAction.sol @@ -17,11 +17,11 @@ contract RegisterL2TokenInArbCustomGatewayAction { uint256 _maxGas, uint256 _gasPriceBid, uint256 _maxSubmissionCost - ) external { + ) external payable { TokenBridgeActionLib.ensureAllContracts(_l1Tokens); - addressRegistry.customGateway().forceRegisterTokenToL2( - _l1Tokens, _l2Tokens, _maxGas, _gasPriceBid, _maxSubmissionCost - ); + addressRegistry.customGateway().forceRegisterTokenToL2{ + value: _maxGas * _gasPriceBid + _maxSubmissionCost + }(_l1Tokens, _l2Tokens, _maxGas, _gasPriceBid, _maxSubmissionCost); } } diff --git a/src/gov-action-contracts/token-bridge/SetGatewayAction.sol b/src/gov-action-contracts/token-bridge/SetGatewayAction.sol index 997e9a55..6803770e 100644 --- a/src/gov-action-contracts/token-bridge/SetGatewayAction.sol +++ b/src/gov-action-contracts/token-bridge/SetGatewayAction.sol @@ -17,12 +17,12 @@ contract SetGatewayAction { uint256 _maxGas, uint256 _gasPriceBid, uint256 _maxSubmissionCost - ) external { + ) external payable { TokenBridgeActionLib.ensureAllContracts(_tokens); TokenBridgeActionLib.ensureAllContracts(_gateways); - addressRegistry.gatewayRouter().setGateways( - _tokens, _gateways, _maxGas, _gasPriceBid, _maxSubmissionCost - ); + addressRegistry.gatewayRouter().setGateways{ + value: _maxGas * _gasPriceBid + _maxSubmissionCost + }(_tokens, _gateways, _maxGas, _gasPriceBid, _maxSubmissionCost); } }