-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCCTPReceiver.sol
52 lines (43 loc) · 1.5 KB
/
CCTPReceiver.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
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.0;
/**
* @title CCTPReceiver
* @notice Receive messages from CCTP-style bridge.
*/
abstract contract CCTPReceiver {
address public immutable destinationMessenger;
uint32 public immutable sourceDomainId;
address public immutable sourceAuthority;
constructor(
address _destinationMessenger,
uint32 _sourceDomainId,
address _sourceAuthority
) {
destinationMessenger = _destinationMessenger;
sourceDomainId = _sourceDomainId;
sourceAuthority = _sourceAuthority;
}
function _onlyCrossChainMessage() internal view {
require(msg.sender == address(this), "Receiver/invalid-sender");
}
modifier onlyCrossChainMessage() {
_onlyCrossChainMessage();
_;
}
function handleReceiveMessage(
uint32 sourceDomain,
bytes32 sender,
bytes calldata messageBody
) external returns (bool) {
require(msg.sender == destinationMessenger, "Receiver/invalid-sender");
require(sourceDomainId == sourceDomain, "Receiver/invalid-sourceDomain");
require(sender == bytes32(uint256(uint160(sourceAuthority))), "Receiver/invalid-sourceAuthority");
(bool success, bytes memory ret) = address(this).call(messageBody);
if (!success) {
assembly {
revert(add(ret, 0x20), mload(ret))
}
}
return true;
}
}