-
Notifications
You must be signed in to change notification settings - Fork 0
Add Arbitrum gateway #162
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
Open
viatrix
wants to merge
7
commits into
main
Choose a base branch
from
feat-arbitrum-gateway
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Arbitrum gateway #162
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fa80c06
Add Arbitrum gateway
viatrix 2614b4b
Merge branch 'main' into feat-arbitrum-gateway
viatrix a99aa0b
Update scripts and coverage
viatrix 229201e
Fixes after review
viatrix 34e9877
Remove duplicated test
viatrix 26a0624
Update Everclear test
lastperson acc7150
Add Arbitrum Gateway to Ethereum config
lastperson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,41 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity 0.8.28; | ||
|
|
||
| /** | ||
| * @title Interface for Arbitrum Gateway Router | ||
| */ | ||
| interface IArbitrumGatewayRouter { | ||
|
|
||
| event TransferRouted( | ||
| address indexed token, | ||
| address indexed _userFrom, | ||
| address indexed _userTo, | ||
| address gateway | ||
| ); | ||
|
|
||
| /** | ||
| * @notice For new versions of gateways it's recommended to use outboundTransferCustomRefund() method. | ||
| * @notice Some legacy gateways (for example, DAI) don't have the outboundTransferCustomRefund method | ||
| * @notice so using outboundTransfer() method is a universal solution | ||
| */ | ||
| function outboundTransfer( | ||
| address _token, | ||
| address _to, | ||
| uint256 _amount, | ||
| uint256 _maxGas, | ||
| uint256 _gasPriceBid, | ||
| bytes calldata _data | ||
| ) external payable returns (bytes memory); | ||
|
|
||
| /** | ||
| * @notice Calculate the address used when bridging an ERC20 token | ||
| * @dev the L1 and L2 address oracles may not always be in sync. | ||
| * For example, a custom token may have been registered but not deploy or the contract self destructed. | ||
| * @param l1ERC20 address of L1 token | ||
| * @return L2 address of a bridged ERC20 token | ||
| */ | ||
| function calculateL2TokenAddress(address l1ERC20) external view returns (address); | ||
|
|
||
| function getGateway(address _token) external view returns (address gateway); | ||
| } |
This file contains hidden or 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 hidden or 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,42 @@ | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
| pragma solidity 0.8.28; | ||
|
|
||
| import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
| import {IArbitrumGatewayRouter} from "../interfaces/IArbitrumGatewayRouter.sol"; | ||
|
|
||
| contract TestArbitrumGatewayRouter is IArbitrumGatewayRouter { | ||
|
|
||
| address public immutable LOCAL_TOKEN; | ||
| address public immutable L2_TOKEN; | ||
|
|
||
| error InvalidToken(); | ||
| error SimulatedRevert(); | ||
|
|
||
| constructor(address _localtoken, address _l2token) { | ||
| LOCAL_TOKEN = _localtoken; | ||
| L2_TOKEN = _l2token; | ||
| } | ||
|
|
||
| function calculateL2TokenAddress(address) external view override returns (address) { | ||
| return L2_TOKEN; | ||
| } | ||
|
|
||
| function getGateway(address) external view returns (address gateway) { | ||
| return address(this); | ||
| } | ||
|
|
||
| function outboundTransfer( | ||
| address _token, | ||
| address _to, | ||
| uint256 _amount, | ||
| uint256, | ||
| uint256, | ||
| bytes calldata | ||
| ) external payable returns (bytes memory) { | ||
| require(_token == LOCAL_TOKEN, InvalidToken()); | ||
| require(_amount != 2000, SimulatedRevert()); | ||
| SafeERC20.safeTransferFrom(IERC20(LOCAL_TOKEN), msg.sender, address(this), _amount); | ||
| emit TransferRouted(LOCAL_TOKEN, msg.sender, _to, address(this)); | ||
| return "GATEWAY_DATA"; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,57 @@ | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
| pragma solidity 0.8.28; | ||
|
|
||
| import {BitMaps} from "@openzeppelin/contracts/utils/structs/BitMaps.sol"; | ||
| import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
| import {IArbitrumGatewayRouter} from ".././interfaces/IArbitrumGatewayRouter.sol"; | ||
| import {AdapterHelper} from "./AdapterHelper.sol"; | ||
|
|
||
| abstract contract ArbitrumGatewayAdapter is AdapterHelper { | ||
| using SafeERC20 for IERC20; | ||
|
|
||
| IArbitrumGatewayRouter immutable public ARBITRUM_GATEWAY_ROUTER; | ||
|
|
||
| event ArbitrumERC20TransferInitiated(bytes gatewayData); | ||
|
|
||
| constructor( | ||
| address arbitrumGatewayRouter | ||
| ) { | ||
| // No check for address(0) to allow deployment on chains where Arbitrum Bridge is not available | ||
| ARBITRUM_GATEWAY_ROUTER = IArbitrumGatewayRouter(arbitrumGatewayRouter); | ||
| } | ||
|
|
||
| function initiateTransferArbitrum( | ||
| IERC20 token, | ||
| uint256 amount, | ||
| address destinationPool, | ||
| Domain destinationDomain, | ||
| bytes calldata extraData, | ||
| Domain localDomain, | ||
| mapping(bytes32 => BitMaps.BitMap) storage outputTokens | ||
| ) internal { | ||
| // We are only interested in fast L1->L2 bridging, because the reverse is slow. | ||
| require(localDomain == Domain.ETHEREUM, UnsupportedDomain()); | ||
| require(destinationDomain == Domain.ARBITRUM_ONE, UnsupportedDomain()); | ||
| IArbitrumGatewayRouter router = ARBITRUM_GATEWAY_ROUTER; | ||
| require(address(router) != address(0), ZeroAddress()); | ||
| (address outputToken, uint256 maxGas, uint256 gasPriceBid, bytes memory data) = | ||
| abi.decode(extraData, (address, uint256, uint256, bytes)); | ||
|
|
||
| _validateOutputToken(_addressToBytes32(outputToken), destinationDomain, outputTokens); | ||
| // Get output token from the gateway | ||
| address gatewayOutputToken = ARBITRUM_GATEWAY_ROUTER.calculateL2TokenAddress(address(token)); | ||
| // Check that output tokens match | ||
| require(gatewayOutputToken == outputToken, InvalidOutputToken()); | ||
| address gateway = ARBITRUM_GATEWAY_ROUTER.getGateway(address(token)); | ||
| token.forceApprove(gateway, amount); | ||
| bytes memory gatewayData = router.outboundTransfer{value: msg.value}( | ||
| address(token), | ||
| destinationPool, | ||
| amount, | ||
| maxGas, | ||
| gasPriceBid, | ||
| data | ||
| ); | ||
| emit ArbitrumERC20TransferInitiated(gatewayData); | ||
| } | ||
| } | ||
This file contains hidden or 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,6 +1,6 @@ | ||
| { | ||
| "lines": "96.88", | ||
| "functions": "98.57", | ||
| "branches": "87.76", | ||
| "statements": "96.88" | ||
| "lines": "96.93", | ||
| "functions": "98.58", | ||
| "branches": "87.79", | ||
| "statements": "96.93" | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.