forked from davidsemakula/hyperlane-eip-5164
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHyperlaneERC5164Relayer.sol
62 lines (49 loc) · 2.28 KB
/
HyperlaneERC5164Relayer.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.17;
import {IOutbox} from "@hyperlane-xyz/core/interfaces/IOutbox.sol";
import {TypeCasts} from "@hyperlane-xyz/core/contracts/libs/TypeCasts.sol";
import {IERC5164CrossChainRelayer} from "./interfaces/IERC5164CrossChainRelayer.sol";
import {IERC5164CrossChainExecutor} from "./interfaces/IERC5164CrossChainExecutor.sol";
import {Call} from "./utils/Call.sol";
/**
* @title HyperlaneERC5164Relayer implementation
* @notice `CrossChainRelayer` implementation that also uses a Hyperlane `Outbox` as its transporter
*/
contract HyperlaneERC5164Relayer is IERC5164CrossChainRelayer {
/// @notice `Outbox` contract reference
IOutbox public outbox;
/// @notice Hyperlane identifier of destination chain
uint32 public destinationDomain;
/// @notice `CrossChainExecutor` contract reference
IERC5164CrossChainExecutor public executor;
/// @notice Gas limit of receiving chain
uint256 public immutable maxGasLimit;
/// @notice Nonce to uniquely identify each batch of calls.
uint256 internal nonce;
/**
* @notice HyperlaneERC5164Relayer constructor.
* @param outbox_ Address of the Hyperlane `Outbox` contract
* @param destinationDomain_ Hyperlane identifier of destination chain
* @param executor_ Address of the `CrossChainExecutor` contract
*/
constructor(address outbox_, uint32 destinationDomain_, address executor_, uint256 maxGasLimit_) {
outbox = IOutbox(outbox_);
destinationDomain = destinationDomain_;
executor = IERC5164CrossChainExecutor(executor_);
require(maxGasLimit_ > 0, "max gas limit is zero");
maxGasLimit = maxGasLimit_;
}
/// @inheritdoc IERC5164CrossChainRelayer
function relayCalls(Call[] calldata calls, uint256 gasLimit) external payable returns (uint256) {
uint256 _maxGasLimit = maxGasLimit;
if (gasLimit > _maxGasLimit) {
revert GasLimitTooHigh(gasLimit, _maxGasLimit);
}
nonce++;
uint256 _nonce = nonce;
bytes32 recipient = TypeCasts.addressToBytes32(address(executor));
outbox.dispatch(destinationDomain, recipient, abi.encode(_nonce, msg.sender, calls));
emit RelayedCalls(_nonce, msg.sender, calls, gasLimit);
return _nonce;
}
}