-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into npai/custom-gas-token-precision
- Loading branch information
Showing
6 changed files
with
63 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.0; | ||
|
||
import "./interfaces/AdapterInterface.sol"; | ||
import { AdapterInterface } from "./interfaces/AdapterInterface.sol"; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import "../external/interfaces/CCTPInterfaces.sol"; | ||
import "../libraries/CircleCCTPAdapter.sol"; | ||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import { ITokenMessenger as ICCTPTokenMessenger } from "../external/interfaces/CCTPInterfaces.sol"; | ||
import { CircleCCTPAdapter, CircleDomainIds } from "../libraries/CircleCCTPAdapter.sol"; | ||
|
||
interface FunderInterface { | ||
function withdraw(IERC20 token, uint256 amount) external; | ||
|
@@ -28,6 +28,7 @@ interface ArbitrumL1ERC20Bridge { | |
/** | ||
* @notice Returns token that is escrowed in bridge on L1 side and minted on L2 as native currency. | ||
* @dev This function doesn't exist on the generic Bridge interface. | ||
* @return address of the native token. | ||
*/ | ||
function nativeToken() external view returns (address); | ||
|
||
|
@@ -48,6 +49,7 @@ interface ArbitrumL1InboxLike { | |
/** | ||
* @dev we only use this function to check the native token used by the bridge, so we hardcode the interface | ||
* to return an ArbitrumL1ERC20Bridge instead of a more generic Bridge interface. | ||
* @return address of the bridge. | ||
*/ | ||
function bridge() external view returns (ArbitrumL1ERC20Bridge); | ||
|
||
|
@@ -128,9 +130,9 @@ interface ArbitrumL1ERC20GatewayLike { | |
* called via delegatecall, which will execute this contract's logic within the context of the originating contract. | ||
* For example, the HubPool will delegatecall these functions, therefore its only necessary that the HubPool's methods | ||
* that call this contract's logic guard against reentrancy. | ||
* @dev This contract is very similar to Arbitrum_Adapter but it allows the caller to pay for submission | ||
* fees using a custom gas token. This is required to support certain Arbitrum orbit L2s and L3s. | ||
* @dev This contract | ||
* @dev This contract is very similar to Arbitrum_Adapter but it allows the caller to pay for retryable ticket | ||
* submission fees using a custom gas token. This is required to support certain Arbitrum orbit L2s and L3s. | ||
* @custom:security-contact [email protected] | ||
*/ | ||
|
||
// solhint-disable-next-line contract-name-camelcase | ||
|
@@ -166,6 +168,9 @@ contract Arbitrum_CustomGasToken_Adapter is AdapterInterface, CircleCCTPAdapter | |
|
||
FunderInterface public immutable CUSTOM_GAS_TOKEN_FUNDER; | ||
Check warning on line 169 in contracts/chain-adapters/Arbitrum_CustomGasToken_Adapter.sol GitHub Actions / Solhint (16)
|
||
|
||
error InvalidCustomGasToken(); | ||
error InsufficientCustomGasToken(); | ||
|
||
/** | ||
* @notice Constructs new Adapter. | ||
* @param _l1ArbitrumInbox Inbox helper contract to send messages to Arbitrum. | ||
|
@@ -176,13 +181,16 @@ contract Arbitrum_CustomGasToken_Adapter is AdapterInterface, CircleCCTPAdapter | |
* @param _l2GasPrice Gas price bid for L2 execution. Should be set conservatively high to avoid stuck messages. | ||
* @param _cctpTokenMessenger TokenMessenger contract to bridge via CCTP. | ||
* @param _customGasTokenFunder Contract that funds the custom gas token. | ||
* @param _l2MaxSubmissionCost Amount of gas token allocated to pay for the base submission fee. The base | ||
* submission fee is a parameter unique to Arbitrum retryable transactions. This value is hardcoded | ||
* and used for all messages sent by this adapter. | ||
*/ | ||
constructor( | ||
ArbitrumL1InboxLike _l1ArbitrumInbox, | ||
ArbitrumL1ERC20GatewayLike _l1ERC20GatewayRouter, | ||
address _l2RefundL2Address, | ||
IERC20 _l1Usdc, | ||
ITokenMessenger _cctpTokenMessenger, | ||
ICCTPTokenMessenger _cctpTokenMessenger, | ||
FunderInterface _customGasTokenFunder, | ||
uint256 _l2MaxSubmissionCost, | ||
uint256 _l2GasPrice | ||
|
@@ -191,8 +199,7 @@ contract Arbitrum_CustomGasToken_Adapter is AdapterInterface, CircleCCTPAdapter | |
L1_ERC20_GATEWAY_ROUTER = _l1ERC20GatewayRouter; | ||
L2_REFUND_L2_ADDRESS = _l2RefundL2Address; | ||
CUSTOM_GAS_TOKEN = IERC20(L1_INBOX.bridge().nativeToken()); | ||
require(L1_INBOX.bridge().nativeTokenDecimals() <= 18, "Invalid precision"); | ||
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; | ||
L2_GAS_PRICE = _l2GasPrice; | ||
CUSTOM_GAS_TOKEN_FUNDER = _customGasTokenFunder; | ||
|
@@ -291,6 +298,7 @@ contract Arbitrum_CustomGasToken_Adapter is AdapterInterface, CircleCCTPAdapter | |
/** | ||
* @notice Returns required amount of gas token to send a message via the Inbox. | ||
* @dev Should return a value in the same precision as the gas token's precision. | ||
* @param l2GasLimit L2 gas limit for the message. | ||
* @return amount of gas token that this contract needs to hold in order for relayMessage to succeed. | ||
*/ | ||
function getL1CallValue(uint32 l2GasLimit) public view returns (uint256) { | ||
|
@@ -300,7 +308,7 @@ contract Arbitrum_CustomGasToken_Adapter is AdapterInterface, CircleCCTPAdapter | |
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; | ||
} | ||
|
||
|
19 changes: 0 additions & 19 deletions
19
contracts/chain-adapters/Arbitrum_CustomGasToken_Funder.sol
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
||
/** | ||
* @notice Users can donate tokens to this contract that only the owner can withdraw. | ||
* @dev This contract is designed to be used as a convience for the owner to store funds to pay for | ||
* future transactions, such as donating custom gas tokens to pay for future retryable ticket messages | ||
* to be sent via the Arbitrum_Adapter. | ||
* @custom:security-contact [email protected] | ||
*/ | ||
contract DonationBox is Ownable { | ||
using SafeERC20 for IERC20; | ||
|
||
/** | ||
* @notice Withdraw tokens from the contract. | ||
* @dev Only callable by owner, which should be set to the HubPool | ||
* so that it can use these funds to pay for relaying messages to | ||
* an Arbitrum L2 that uses custom gas tokens as the L1 payment currency, | ||
* via the Arbitrum_CustomGasToken_Adapter. | ||
* @param token Token to withdraw. | ||
* @param amount Amount of tokens to withdraw. | ||
*/ | ||
function withdraw(IERC20 token, uint256 amount) external onlyOwner { | ||
token.safeTransfer(msg.sender, amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters