-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathAMBReceiver.sol
44 lines (35 loc) · 1.38 KB
/
AMBReceiver.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
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.0;
import { Address } from "openzeppelin-contracts/contracts/utils/Address.sol";
interface IArbitraryMessagingBridge {
function messageSender() external view returns (address);
function messageSourceChainId() external view returns (bytes32);
}
/**
* @title AMBReceiver
* @notice Receive messages to AMB-style chain.
*/
contract AMBReceiver {
using Address for address;
address public immutable amb;
bytes32 public immutable sourceChainId;
address public immutable sourceAuthority;
address public immutable target;
constructor(
address _amb,
bytes32 _sourceChainId,
address _sourceAuthority,
address _target
) {
amb = _amb;
sourceChainId = _sourceChainId;
sourceAuthority = _sourceAuthority;
target = _target;
}
fallback(bytes calldata message) external returns (bytes memory) {
require(msg.sender == amb, "AMBReceiver/invalid-sender");
require(IArbitraryMessagingBridge(amb).messageSourceChainId() == sourceChainId, "AMBReceiver/invalid-sourceChainId");
require(IArbitraryMessagingBridge(amb).messageSender() == sourceAuthority, "AMBReceiver/invalid-sourceAuthority");
return target.functionCall(message);
}
}