forked from SocketDotTech/socket-plugs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectorPlug.sol
127 lines (110 loc) · 3.63 KB
/
ConnectorPlug.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import "./utils/RescueBase.sol";
import {ISocket} from "./interfaces/ISocket.sol";
import {IPlug} from "./interfaces/IPlug.sol";
import {IConnector} from "./interfaces/IConnector.sol";
import {IBridge} from "./interfaces/IBridge.sol";
import "./common/Errors.sol";
import {IBlast, YieldMode, GasMode} from "./interfaces/IBlast.sol";
contract ConnectorPlug is IConnector, IPlug, RescueBase {
IBridge public immutable bridge__;
ISocket public immutable socket__;
uint32 public immutable siblingChainSlug;
uint256 public messageIdPart;
event ConnectorPlugDisconnected();
constructor(
address bridge_,
address socket_,
uint32 siblingChainSlug_
) AccessControl(msg.sender) {
bridge__ = IBridge(bridge_);
socket__ = ISocket(socket_);
siblingChainSlug = siblingChainSlug_;
_grantRole(RESCUE_ROLE, msg.sender);
if (block.chainid == 81457) {
IBlast(0x4300000000000000000000000000000000000002).configure(
YieldMode.CLAIMABLE,
GasMode.CLAIMABLE,
0x1d52b7c0EF56141998E99d65eE429a8EC24d23Ea
);
}
}
function outbound(
uint256 msgGasLimit_,
bytes memory payload_,
bytes memory
) external payable override returns (bytes32 messageId_) {
if (msg.sender != address(bridge__)) revert NotBridge();
return
socket__.outbound{value: msg.value}(
siblingChainSlug,
msgGasLimit_,
bytes32(0),
bytes32(0),
payload_
);
}
function inbound(
uint32 siblingChainSlug_, // cannot be connected for any other slug, immutable variable
bytes calldata payload_
) external payable override {
if (msg.sender != address(socket__)) revert NotSocket();
bridge__.receiveInbound(siblingChainSlug_, payload_);
}
/**
* @notice this function calculates the fees needed to send the message to Socket.
* @param msgGasLimit_ min gas limit needed at destination chain to execute the message.
*/
function getMinFees(
uint256 msgGasLimit_,
uint256 payloadSize_
) external view returns (uint256 totalFees) {
return
socket__.getMinFees(
msgGasLimit_,
payloadSize_,
bytes32(0),
bytes32(0),
siblingChainSlug,
address(this)
);
}
function connect(
address siblingPlug_,
address switchboard_
) external onlyOwner {
messageIdPart =
(uint256(socket__.chainSlug()) << 224) |
(uint256(uint160(siblingPlug_)) << 64);
socket__.connect(
siblingChainSlug,
siblingPlug_,
switchboard_,
switchboard_
);
}
function disconnect() external onlyOwner {
messageIdPart = 0;
(
,
address inboundSwitchboard,
address outboundSwitchboard,
,
) = socket__.getPlugConfig(address(this), siblingChainSlug);
socket__.connect(
siblingChainSlug,
address(0),
inboundSwitchboard,
outboundSwitchboard
);
emit ConnectorPlugDisconnected();
}
/**
* @notice this function is used to calculate message id before sending outbound().
* @return messageId
*/
function getMessageId() external view returns (bytes32) {
return bytes32(messageIdPart | (socket__.globalMessageCount()));
}
}