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

improve(CustomGasTokens): Replace require with revert statements #593

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
// ArbRetryableTx.getSubmissionPrice). ArbRetryableTicket precompile interface exists at L2 address
// 0x000000000000000000000000000000000000006E.
// @dev Unlike in Arbitrum_Adapter, this is immutable because we don't know what precision the custom gas token has.
uint256 public immutable L2_MAX_SUBMISSION_COST;

Check warning on line 139 in contracts/chain-adapters/Arbitrum_CustomGasToken_Adapter.sol

View workflow job for this annotation

GitHub Actions / Solhint (16)

Variable name must be in mixedCase

Check warning on line 139 in contracts/chain-adapters/Arbitrum_CustomGasToken_Adapter.sol

View workflow job for this annotation

GitHub Actions / Solhint (16)

Variable name must be in mixedCase

// L2 Gas price bid for immediate L2 execution attempt (queryable via standard eth*gasPrice RPC)
uint256 public constant L2_GAS_PRICE = 5e9; // 5 gWei
Expand All @@ -147,17 +147,20 @@
uint32 public constant RELAY_MESSAGE_L2_GAS_LIMIT = 2_000_000;

// This address on L2 receives extra gas token that is left over after relaying a message via the inbox.
address public immutable L2_REFUND_L2_ADDRESS;

Check warning on line 150 in contracts/chain-adapters/Arbitrum_CustomGasToken_Adapter.sol

View workflow job for this annotation

GitHub Actions / Solhint (16)

Variable name must be in mixedCase

Check warning on line 150 in contracts/chain-adapters/Arbitrum_CustomGasToken_Adapter.sol

View workflow job for this annotation

GitHub Actions / Solhint (16)

Variable name must be in mixedCase

ArbitrumL1InboxLike public immutable L1_INBOX;

Check warning on line 152 in contracts/chain-adapters/Arbitrum_CustomGasToken_Adapter.sol

View workflow job for this annotation

GitHub Actions / Solhint (16)

Variable name must be in mixedCase

Check warning on line 152 in contracts/chain-adapters/Arbitrum_CustomGasToken_Adapter.sol

View workflow job for this annotation

GitHub Actions / Solhint (16)

Variable name must be in mixedCase

ArbitrumL1ERC20GatewayLike public immutable L1_ERC20_GATEWAY_ROUTER;

Check warning on line 154 in contracts/chain-adapters/Arbitrum_CustomGasToken_Adapter.sol

View workflow job for this annotation

GitHub Actions / Solhint (16)

Variable name must be in mixedCase

Check warning on line 154 in contracts/chain-adapters/Arbitrum_CustomGasToken_Adapter.sol

View workflow job for this annotation

GitHub Actions / Solhint (16)

Variable name must be in mixedCase

// This token is used to pay for l1 to l2 messages if its configured by an Arbitrum orbit chain.
IERC20 public immutable CUSTOM_GAS_TOKEN;

Check warning on line 157 in contracts/chain-adapters/Arbitrum_CustomGasToken_Adapter.sol

View workflow job for this annotation

GitHub Actions / Solhint (16)

Variable name must be in mixedCase

Check warning on line 157 in contracts/chain-adapters/Arbitrum_CustomGasToken_Adapter.sol

View workflow job for this annotation

GitHub Actions / Solhint (16)

Variable name must be in mixedCase

FunderInterface public immutable CUSTOM_GAS_TOKEN_FUNDER;

Check warning on line 159 in contracts/chain-adapters/Arbitrum_CustomGasToken_Adapter.sol

View workflow job for this annotation

GitHub Actions / Solhint (16)

Variable name must be in mixedCase

Check warning on line 159 in contracts/chain-adapters/Arbitrum_CustomGasToken_Adapter.sol

View workflow job for this annotation

GitHub Actions / Solhint (16)

Variable name must be in mixedCase

error InvalidCustomGasToken();
error InsufficientCustomGasToken();

/**
* @notice Constructs new Adapter.
* @param _l1ArbitrumInbox Inbox helper contract to send messages to Arbitrum.
Expand All @@ -180,7 +183,7 @@
L1_ERC20_GATEWAY_ROUTER = _l1ERC20GatewayRouter;
L2_REFUND_L2_ADDRESS = _l2RefundL2Address;
CUSTOM_GAS_TOKEN = IERC20(L1_INBOX.bridge().nativeToken());
require(address(CUSTOM_GAS_TOKEN) != address(0), "Invalid custom gas token");
if (address(CUSTOM_GAS_TOKEN) == address(0)) revert InvalidCustomGasToken();
L2_MAX_SUBMISSION_COST = _l2MaxSubmissionCost;
CUSTOM_GAS_TOKEN_FUNDER = _customGasTokenFunder;
}
Expand Down Expand Up @@ -284,7 +287,7 @@
function _pullCustomGas(uint32 l2GasLimit) internal returns (uint256) {
uint256 requiredL1CallValue = getL1CallValue(l2GasLimit);
CUSTOM_GAS_TOKEN_FUNDER.withdraw(CUSTOM_GAS_TOKEN, requiredL1CallValue);
require(CUSTOM_GAS_TOKEN.balanceOf(address(this)) >= requiredL1CallValue, "Insufficient gas balance");
if (CUSTOM_GAS_TOKEN.balanceOf(address(this)) < requiredL1CallValue) revert InsufficientCustomGasToken();
return requiredL1CallValue;
}
}
Loading