@hyperlane-xyz/core 1.1.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/contracts/GasRouter.sol +103 -0
- package/contracts/OwnableMulticall.sol +5 -4
- package/contracts/PausableReentrancyGuard.sol +2 -2
- package/contracts/igps/InterchainGasPaymaster.sol +2 -1
- package/contracts/libs/Call.sol +108 -19
- package/contracts/middleware/InterchainAccountRouter.sol +47 -34
- package/contracts/middleware/InterchainCallMessage.sol +112 -0
- package/contracts/middleware/InterchainQueryRouter.sol +36 -80
- package/contracts/mock/MockHyperlaneEnvironment.sol +4 -4
- package/contracts/mock/MockMailbox.sol +4 -0
- package/contracts/test/TestGasRouter.sol +28 -0
- package/contracts/test/TestInterchainGasPaymaster.sol +8 -17
- package/contracts/test/TestQuery.sol +11 -6
- package/contracts/test/TestQuerySender.sol +22 -11
- package/dist/contracts/GasRouter.d.ts +336 -0
- package/dist/contracts/GasRouter.d.ts.map +1 -0
- package/dist/contracts/GasRouter.js +4 -0
- package/dist/contracts/GasRouter.js.map +1 -0
- package/dist/contracts/OwnableMulticall.d.ts +13 -5
- package/dist/contracts/OwnableMulticall.d.ts.map +1 -1
- package/dist/contracts/index.d.ts +1 -0
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/middleware/InterchainAccountRouter.d.ts +60 -44
- package/dist/contracts/middleware/InterchainAccountRouter.d.ts.map +1 -1
- package/dist/contracts/middleware/InterchainQueryRouter.d.ts +36 -57
- package/dist/contracts/middleware/InterchainQueryRouter.d.ts.map +1 -1
- package/dist/contracts/mock/MockMailbox.d.ts +9 -1
- package/dist/contracts/mock/MockMailbox.d.ts.map +1 -1
- package/dist/contracts/test/TestGasRouter.d.ts +441 -0
- package/dist/contracts/test/TestGasRouter.d.ts.map +1 -0
- package/dist/contracts/test/TestGasRouter.js +4 -0
- package/dist/contracts/test/TestGasRouter.js.map +1 -0
- package/dist/contracts/test/TestInterchainGasPaymaster.d.ts +122 -12
- package/dist/contracts/test/TestInterchainGasPaymaster.d.ts.map +1 -1
- package/dist/contracts/test/TestQuery.d.ts +9 -9
- package/dist/contracts/test/TestQuery.d.ts.map +1 -1
- package/dist/contracts/test/index.d.ts +1 -0
- package/dist/contracts/test/index.d.ts.map +1 -1
- package/dist/factories/contracts/GasRouter__factory.d.ts +52 -0
- package/dist/factories/contracts/GasRouter__factory.d.ts.map +1 -0
- package/dist/factories/contracts/GasRouter__factory.js +392 -0
- package/dist/factories/contracts/GasRouter__factory.js.map +1 -0
- package/dist/factories/contracts/Mailbox__factory.d.ts +1 -1
- package/dist/factories/contracts/Mailbox__factory.js +1 -1
- package/dist/factories/contracts/OwnableMulticall__factory.d.ts +20 -3
- package/dist/factories/contracts/OwnableMulticall__factory.d.ts.map +1 -1
- package/dist/factories/contracts/OwnableMulticall__factory.js +23 -7
- package/dist/factories/contracts/OwnableMulticall__factory.js.map +1 -1
- package/dist/factories/contracts/igps/InterchainGasPaymaster__factory.d.ts +1 -1
- package/dist/factories/contracts/igps/InterchainGasPaymaster__factory.js +2 -2
- package/dist/factories/contracts/index.d.ts +1 -0
- package/dist/factories/contracts/index.d.ts.map +1 -1
- package/dist/factories/contracts/index.js +3 -1
- package/dist/factories/contracts/index.js.map +1 -1
- package/dist/factories/contracts/middleware/InterchainAccountRouter__factory.d.ts +13 -3
- package/dist/factories/contracts/middleware/InterchainAccountRouter__factory.d.ts.map +1 -1
- package/dist/factories/contracts/middleware/InterchainAccountRouter__factory.js +70 -39
- package/dist/factories/contracts/middleware/InterchainAccountRouter__factory.js.map +1 -1
- package/dist/factories/contracts/middleware/InterchainQueryRouter__factory.d.ts +13 -3
- package/dist/factories/contracts/middleware/InterchainQueryRouter__factory.d.ts.map +1 -1
- package/dist/factories/contracts/middleware/InterchainQueryRouter__factory.js +24 -92
- package/dist/factories/contracts/middleware/InterchainQueryRouter__factory.js.map +1 -1
- package/dist/factories/contracts/mock/MockHyperlaneEnvironment__factory.d.ts +1 -1
- package/dist/factories/contracts/mock/MockHyperlaneEnvironment__factory.d.ts.map +1 -1
- package/dist/factories/contracts/mock/MockHyperlaneEnvironment__factory.js +2 -2
- package/dist/factories/contracts/mock/MockHyperlaneEnvironment__factory.js.map +1 -1
- package/dist/factories/contracts/mock/MockMailbox__factory.d.ts +1 -1
- package/dist/factories/contracts/mock/MockMailbox__factory.d.ts.map +1 -1
- package/dist/factories/contracts/mock/MockMailbox__factory.js +14 -1
- package/dist/factories/contracts/mock/MockMailbox__factory.js.map +1 -1
- package/dist/factories/contracts/test/TestGasRouter__factory.d.ts +64 -0
- package/dist/factories/contracts/test/TestGasRouter__factory.d.ts.map +1 -0
- package/dist/factories/contracts/test/TestGasRouter__factory.js +579 -0
- package/dist/factories/contracts/test/TestGasRouter__factory.js.map +1 -0
- package/dist/factories/contracts/test/TestInterchainGasPaymaster__factory.d.ts +1 -1
- package/dist/factories/contracts/test/TestInterchainGasPaymaster__factory.d.ts.map +1 -1
- package/dist/factories/contracts/test/TestInterchainGasPaymaster__factory.js +97 -5
- package/dist/factories/contracts/test/TestInterchainGasPaymaster__factory.js.map +1 -1
- package/dist/factories/contracts/test/TestMailbox__factory.d.ts +1 -1
- package/dist/factories/contracts/test/TestMailbox__factory.js +1 -1
- package/dist/factories/contracts/test/TestQuerySender__factory.d.ts +1 -1
- package/dist/factories/contracts/test/TestQuerySender__factory.d.ts.map +1 -1
- package/dist/factories/contracts/test/TestQuerySender__factory.js +1 -1
- package/dist/factories/contracts/test/TestQuerySender__factory.js.map +1 -1
- package/dist/factories/contracts/test/TestQuery__factory.d.ts +1 -1
- package/dist/factories/contracts/test/TestQuery__factory.d.ts.map +1 -1
- package/dist/factories/contracts/test/TestQuery__factory.js +2 -2
- package/dist/factories/contracts/test/TestQuery__factory.js.map +1 -1
- package/dist/factories/contracts/test/index.d.ts +1 -0
- package/dist/factories/contracts/test/index.d.ts.map +1 -1
- package/dist/factories/contracts/test/index.js +3 -1
- package/dist/factories/contracts/test/index.js.map +1 -1
- package/dist/factories/interfaces/IInterchainAccountRouter__factory.d.ts +12 -2
- package/dist/factories/interfaces/IInterchainAccountRouter__factory.d.ts.map +1 -1
- package/dist/factories/interfaces/IInterchainAccountRouter__factory.js +27 -20
- package/dist/factories/interfaces/IInterchainAccountRouter__factory.js.map +1 -1
- package/dist/factories/interfaces/IInterchainQueryRouter__factory.d.ts +12 -2
- package/dist/factories/interfaces/IInterchainQueryRouter__factory.d.ts.map +1 -1
- package/dist/factories/interfaces/IInterchainQueryRouter__factory.js +17 -85
- package/dist/factories/interfaces/IInterchainQueryRouter__factory.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/interfaces/IInterchainAccountRouter.d.ts +35 -35
- package/dist/interfaces/IInterchainAccountRouter.d.ts.map +1 -1
- package/dist/interfaces/IInterchainQueryRouter.d.ts +23 -44
- package/dist/interfaces/IInterchainQueryRouter.d.ts.map +1 -1
- package/interfaces/IInterchainAccountRouter.sol +5 -6
- package/interfaces/IInterchainQueryRouter.sol +1 -15
- package/package.json +5 -4
|
@@ -5,6 +5,8 @@ pragma solidity ^0.8.13;
|
|
|
5
5
|
import {CallLib} from "../libs/Call.sol";
|
|
6
6
|
import {Router} from "../Router.sol";
|
|
7
7
|
import {IInterchainQueryRouter} from "../../interfaces/IInterchainQueryRouter.sol";
|
|
8
|
+
import {InterchainCallMessage} from "./InterchainCallMessage.sol";
|
|
9
|
+
import {TypeCasts} from "../libs/TypeCasts.sol";
|
|
8
10
|
|
|
9
11
|
// ============ External Imports ============
|
|
10
12
|
import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
|
|
@@ -16,13 +18,8 @@ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Ini
|
|
|
16
18
|
* @dev Currently does not support Sovereign Consensus (user specified Interchain Security Modules).
|
|
17
19
|
*/
|
|
18
20
|
contract InterchainQueryRouter is Router, IInterchainQueryRouter {
|
|
19
|
-
using
|
|
20
|
-
using
|
|
21
|
-
|
|
22
|
-
enum Action {
|
|
23
|
-
DISPATCH,
|
|
24
|
-
RESOLVE
|
|
25
|
-
}
|
|
21
|
+
using TypeCasts for address;
|
|
22
|
+
using TypeCasts for bytes32;
|
|
26
23
|
|
|
27
24
|
/**
|
|
28
25
|
* @notice Emitted when a query is dispatched to another chain.
|
|
@@ -34,11 +31,11 @@ contract InterchainQueryRouter is Router, IInterchainQueryRouter {
|
|
|
34
31
|
address indexed sender
|
|
35
32
|
);
|
|
36
33
|
/**
|
|
37
|
-
* @notice Emitted when a query is
|
|
38
|
-
* @param originDomain The domain of the chain
|
|
34
|
+
* @notice Emitted when a query is executed on the and callback dispatched to the origin chain.
|
|
35
|
+
* @param originDomain The domain of the chain that dispatched the query and receives the callback.
|
|
39
36
|
* @param sender The address to receive the result.
|
|
40
37
|
*/
|
|
41
|
-
event
|
|
38
|
+
event QueryExecuted(uint32 indexed originDomain, bytes32 indexed sender);
|
|
42
39
|
/**
|
|
43
40
|
* @notice Emitted when a query is resolved on the origin chain.
|
|
44
41
|
* @param destinationDomain The domain of the chain that was queried.
|
|
@@ -71,63 +68,21 @@ contract InterchainQueryRouter is Router, IInterchainQueryRouter {
|
|
|
71
68
|
}
|
|
72
69
|
|
|
73
70
|
/**
|
|
74
|
-
* @
|
|
75
|
-
* @param
|
|
76
|
-
* @param
|
|
77
|
-
* @
|
|
78
|
-
* @
|
|
71
|
+
* @notice Dispatches a sequence of static calls (query) to the destination domain and set of callbacks to resolve the results on the dispatcher.
|
|
72
|
+
* @param _destinationDomain The domain of the chain to query.
|
|
73
|
+
* @param calls The sequence of static calls to dispatch and callbacks on the sender to resolve the results.
|
|
74
|
+
* @dev Recommend using CallLib.build to format the interchain calls.
|
|
75
|
+
* @dev Callbacks must be returned to the `msg.sender` for security reasons. Require this contract is the `msg.sender` on callbacks.
|
|
79
76
|
*/
|
|
80
77
|
function query(
|
|
81
78
|
uint32 _destinationDomain,
|
|
82
|
-
|
|
83
|
-
bytes calldata queryData,
|
|
84
|
-
bytes calldata callback
|
|
85
|
-
) external returns (bytes32 messageId) {
|
|
86
|
-
// TODO: fix this ugly arrayification
|
|
87
|
-
CallLib.Call[] memory calls = new CallLib.Call[](1);
|
|
88
|
-
calls[0] = CallLib.Call({to: target, data: queryData});
|
|
89
|
-
bytes[] memory callbacks = new bytes[](1);
|
|
90
|
-
callbacks[0] = callback;
|
|
91
|
-
messageId = query(_destinationDomain, calls, callbacks);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* @param _destinationDomain Domain of destination chain
|
|
96
|
-
* @param call Call (to and data packed struct) to be made on destination chain.
|
|
97
|
-
* @param callback Callback function selector on `msg.sender` and optionally abi-encoded prefix arguments.
|
|
98
|
-
*/
|
|
99
|
-
function query(
|
|
100
|
-
uint32 _destinationDomain,
|
|
101
|
-
CallLib.Call calldata call,
|
|
102
|
-
bytes calldata callback
|
|
103
|
-
) external returns (bytes32 messageId) {
|
|
104
|
-
// TODO: fix this ugly arrayification
|
|
105
|
-
CallLib.Call[] memory calls = new CallLib.Call[](1);
|
|
106
|
-
calls[0] = call;
|
|
107
|
-
bytes[] memory callbacks = new bytes[](1);
|
|
108
|
-
callbacks[0] = callback;
|
|
109
|
-
messageId = query(_destinationDomain, calls, callbacks);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @param _destinationDomain Domain of destination chain
|
|
114
|
-
* @param calls Array of calls (to and data packed struct) to be made on destination chain in sequence.
|
|
115
|
-
* @param callbacks Array of callback function selectors on `msg.sender` and optionally abi-encoded prefix arguments.
|
|
116
|
-
*/
|
|
117
|
-
function query(
|
|
118
|
-
uint32 _destinationDomain,
|
|
119
|
-
CallLib.Call[] memory calls,
|
|
120
|
-
bytes[] memory callbacks
|
|
79
|
+
CallLib.StaticCallWithCallback[] calldata calls
|
|
121
80
|
) public returns (bytes32 messageId) {
|
|
122
|
-
|
|
123
|
-
calls.length == callbacks.length,
|
|
124
|
-
"InterchainQueryRouter: calls and callbacks must be same length"
|
|
125
|
-
);
|
|
81
|
+
emit QueryDispatched(_destinationDomain, msg.sender);
|
|
126
82
|
messageId = _dispatch(
|
|
127
83
|
_destinationDomain,
|
|
128
|
-
|
|
84
|
+
InterchainCallMessage.format(calls, msg.sender.addressToBytes32())
|
|
129
85
|
);
|
|
130
|
-
emit QueryDispatched(_destinationDomain, msg.sender);
|
|
131
86
|
}
|
|
132
87
|
|
|
133
88
|
/**
|
|
@@ -140,27 +95,28 @@ contract InterchainQueryRouter is Router, IInterchainQueryRouter {
|
|
|
140
95
|
bytes32, // router sender
|
|
141
96
|
bytes calldata _message
|
|
142
97
|
) internal override {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
_message
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
callbacks = calls._multicallAndResolve(callbacks);
|
|
155
|
-
_dispatch(_origin, abi.encode(Action.RESOLVE, sender, callbacks));
|
|
156
|
-
emit QueryReturned(_origin, sender);
|
|
157
|
-
} else if (action == Action.RESOLVE) {
|
|
158
|
-
(, address sender, bytes[] memory resolveCallbacks) = abi.decode(
|
|
159
|
-
_message,
|
|
160
|
-
(Action, address, bytes[])
|
|
98
|
+
InterchainCallMessage.CallType calltype = InterchainCallMessage
|
|
99
|
+
.calltype(_message);
|
|
100
|
+
bytes32 sender = InterchainCallMessage.sender(_message);
|
|
101
|
+
if (
|
|
102
|
+
calltype == InterchainCallMessage.CallType.STATIC_CALL_WITH_CALLBACK
|
|
103
|
+
) {
|
|
104
|
+
CallLib.StaticCallWithCallback[]
|
|
105
|
+
memory callsWithCallback = InterchainCallMessage
|
|
106
|
+
.callsWithCallbacks(_message);
|
|
107
|
+
bytes[] memory callbacks = CallLib.multistaticcall(
|
|
108
|
+
callsWithCallback
|
|
161
109
|
);
|
|
162
|
-
sender
|
|
163
|
-
|
|
110
|
+
emit QueryExecuted(_origin, sender);
|
|
111
|
+
_dispatch(_origin, InterchainCallMessage.format(callbacks, sender));
|
|
112
|
+
} else if (calltype == InterchainCallMessage.CallType.RAW_CALLDATA) {
|
|
113
|
+
address senderAddress = sender.bytes32ToAddress();
|
|
114
|
+
bytes[] memory rawCalls = InterchainCallMessage.rawCalls(_message);
|
|
115
|
+
CallLib.multicallto(senderAddress, rawCalls);
|
|
116
|
+
//
|
|
117
|
+
emit QueryResolved(_origin, senderAddress);
|
|
118
|
+
} else {
|
|
119
|
+
assert(false);
|
|
164
120
|
}
|
|
165
121
|
}
|
|
166
122
|
}
|
|
@@ -3,7 +3,7 @@ pragma solidity ^0.8.13;
|
|
|
3
3
|
|
|
4
4
|
import "./MockMailbox.sol";
|
|
5
5
|
import "../middleware/InterchainQueryRouter.sol";
|
|
6
|
-
import "../
|
|
6
|
+
import "../test/TestInterchainGasPaymaster.sol";
|
|
7
7
|
import "../test/TestIsm.sol";
|
|
8
8
|
|
|
9
9
|
import {TypeCasts} from "../libs/TypeCasts.sol";
|
|
@@ -13,7 +13,7 @@ contract MockHyperlaneEnvironment {
|
|
|
13
13
|
uint32 destinationDomain;
|
|
14
14
|
|
|
15
15
|
mapping(uint32 => MockMailbox) public mailboxes;
|
|
16
|
-
mapping(uint32 =>
|
|
16
|
+
mapping(uint32 => TestInterchainGasPaymaster) public igps;
|
|
17
17
|
mapping(uint32 => IInterchainSecurityModule) public isms;
|
|
18
18
|
mapping(uint32 => InterchainQueryRouter) public queryRouters;
|
|
19
19
|
|
|
@@ -27,8 +27,8 @@ contract MockHyperlaneEnvironment {
|
|
|
27
27
|
originMailbox.addRemoteMailbox(_destinationDomain, destinationMailbox);
|
|
28
28
|
destinationMailbox.addRemoteMailbox(_originDomain, originMailbox);
|
|
29
29
|
|
|
30
|
-
igps[originDomain] = new
|
|
31
|
-
igps[destinationDomain] = new
|
|
30
|
+
igps[originDomain] = new TestInterchainGasPaymaster();
|
|
31
|
+
igps[destinationDomain] = new TestInterchainGasPaymaster();
|
|
32
32
|
|
|
33
33
|
isms[originDomain] = new TestIsm();
|
|
34
34
|
isms[destinationDomain] = new TestIsm();
|
|
@@ -8,8 +8,11 @@ contract MockMailbox {
|
|
|
8
8
|
using TypeCasts for address;
|
|
9
9
|
using TypeCasts for bytes32;
|
|
10
10
|
// Domain of chain on which the contract is deployed
|
|
11
|
+
|
|
12
|
+
// ============ Constants ============
|
|
11
13
|
uint32 public immutable localDomain;
|
|
12
14
|
uint32 public immutable VERSION = 0;
|
|
15
|
+
uint256 public constant MAX_MESSAGE_BODY_BYTES = 2 * 2**10;
|
|
13
16
|
|
|
14
17
|
uint256 public outboundNonce = 0;
|
|
15
18
|
uint256 public inboundUnprocessedNonce = 0;
|
|
@@ -37,6 +40,7 @@ contract MockMailbox {
|
|
|
37
40
|
bytes32 _recipientAddress,
|
|
38
41
|
bytes calldata _messageBody
|
|
39
42
|
) external returns (bytes32) {
|
|
43
|
+
require(_messageBody.length <= MAX_MESSAGE_BODY_BYTES, "msg too long");
|
|
40
44
|
MockMailbox _destinationMailbox = remoteMailboxes[_destinationDomain];
|
|
41
45
|
require(
|
|
42
46
|
address(_destinationMailbox) != address(0),
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
pragma solidity >=0.6.11;
|
|
3
|
+
|
|
4
|
+
import "./TestRouter.sol";
|
|
5
|
+
import "../GasRouter.sol";
|
|
6
|
+
|
|
7
|
+
contract TestGasRouter is TestRouter, GasRouter {
|
|
8
|
+
function dispatchWithGas(
|
|
9
|
+
uint32 _destinationDomain,
|
|
10
|
+
bytes memory _messageBody,
|
|
11
|
+
uint256 _gasPayment,
|
|
12
|
+
address _gasPaymentRefundAddress
|
|
13
|
+
) external payable {
|
|
14
|
+
_dispatchWithGas(
|
|
15
|
+
_destinationDomain,
|
|
16
|
+
_messageBody,
|
|
17
|
+
_gasPayment,
|
|
18
|
+
_gasPaymentRefundAddress
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function dispatchWithGas(
|
|
23
|
+
uint32 _destinationDomain,
|
|
24
|
+
bytes memory _messageBody
|
|
25
|
+
) external payable {
|
|
26
|
+
_dispatchWithGas(_destinationDomain, _messageBody);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -2,30 +2,21 @@
|
|
|
2
2
|
pragma solidity >=0.8.0;
|
|
3
3
|
|
|
4
4
|
// ============ Internal Imports ============
|
|
5
|
-
import {
|
|
5
|
+
import {InterchainGasPaymaster} from "../igps/InterchainGasPaymaster.sol";
|
|
6
6
|
|
|
7
|
-
contract TestInterchainGasPaymaster is
|
|
8
|
-
|
|
9
|
-
bytes32 indexed messageId,
|
|
10
|
-
uint256 gasAmount,
|
|
11
|
-
uint256 payment
|
|
12
|
-
);
|
|
7
|
+
contract TestInterchainGasPaymaster is InterchainGasPaymaster {
|
|
8
|
+
uint256 gasPrice = 0;
|
|
13
9
|
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
uint32,
|
|
17
|
-
uint256 _gasAmount,
|
|
18
|
-
address
|
|
19
|
-
) external payable override {
|
|
20
|
-
emit GasPayment(_messageId, _gasAmount, msg.value);
|
|
10
|
+
function setGasPrice(uint256 _gasPrice) external {
|
|
11
|
+
gasPrice = _gasPrice;
|
|
21
12
|
}
|
|
22
13
|
|
|
23
|
-
function quoteGasPayment(uint32, uint256)
|
|
14
|
+
function quoteGasPayment(uint32, uint256 gasAmount)
|
|
24
15
|
public
|
|
25
|
-
|
|
16
|
+
view
|
|
26
17
|
override
|
|
27
18
|
returns (uint256)
|
|
28
19
|
{
|
|
29
|
-
return
|
|
20
|
+
return gasPrice * gasAmount;
|
|
30
21
|
}
|
|
31
22
|
}
|
|
@@ -3,6 +3,9 @@ pragma solidity ^0.8.13;
|
|
|
3
3
|
|
|
4
4
|
import {InterchainQueryRouter} from "../middleware/InterchainQueryRouter.sol";
|
|
5
5
|
import {TypeCasts} from "../libs/TypeCasts.sol";
|
|
6
|
+
import {CallLib} from "../libs/Call.sol";
|
|
7
|
+
|
|
8
|
+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
|
|
6
9
|
|
|
7
10
|
contract TestQuery {
|
|
8
11
|
InterchainQueryRouter public router;
|
|
@@ -18,18 +21,20 @@ contract TestQuery {
|
|
|
18
21
|
*/
|
|
19
22
|
function queryRouterOwner(uint32 domain, uint256 secret) external {
|
|
20
23
|
address target = TypeCasts.bytes32ToAddress(router.routers(domain));
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
CallLib.StaticCallWithCallback[]
|
|
25
|
+
memory calls = new CallLib.StaticCallWithCallback[](1);
|
|
26
|
+
calls[0] = CallLib.build(
|
|
27
|
+
target,
|
|
28
|
+
abi.encodeWithSelector(Ownable.owner.selector),
|
|
29
|
+
abi.encodeWithSelector(this.receiveRouterOwner.selector, secret)
|
|
25
30
|
);
|
|
26
|
-
router.query(domain,
|
|
31
|
+
router.query(domain, calls);
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
/**
|
|
30
35
|
* @dev `msg.sender` must be restricted to `this.router` to prevent any local account from spoofing query data.
|
|
31
36
|
*/
|
|
32
|
-
function
|
|
37
|
+
function receiveRouterOwner(uint256 secret, address owner) external {
|
|
33
38
|
require(msg.sender == address(router), "TestQuery: not from router");
|
|
34
39
|
emit Owner(secret, owner);
|
|
35
40
|
}
|
|
@@ -3,6 +3,7 @@ pragma solidity >=0.8.0;
|
|
|
3
3
|
|
|
4
4
|
import {IInterchainGasPaymaster} from "../../interfaces/IInterchainGasPaymaster.sol";
|
|
5
5
|
import {IInterchainQueryRouter} from "../../interfaces/IInterchainQueryRouter.sol";
|
|
6
|
+
import {CallLib} from "../libs/Call.sol";
|
|
6
7
|
|
|
7
8
|
contract TestQuerySender {
|
|
8
9
|
IInterchainQueryRouter queryRouter;
|
|
@@ -32,13 +33,13 @@ contract TestQuerySender {
|
|
|
32
33
|
bytes calldata _targetData,
|
|
33
34
|
uint256 _gasAmount
|
|
34
35
|
) external payable {
|
|
35
|
-
|
|
36
|
+
queryAndPayFor(
|
|
36
37
|
_destinationDomain,
|
|
37
38
|
_target,
|
|
38
39
|
_targetData,
|
|
39
|
-
|
|
40
|
+
this.handleQueryAddressResult.selector,
|
|
41
|
+
_gasAmount
|
|
40
42
|
);
|
|
41
|
-
_payForGas(_messageId, _destinationDomain, _gasAmount);
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
function handleQueryAddressResult(address _result) external {
|
|
@@ -52,13 +53,13 @@ contract TestQuerySender {
|
|
|
52
53
|
bytes calldata _targetData,
|
|
53
54
|
uint256 _gasAmount
|
|
54
55
|
) external payable {
|
|
55
|
-
|
|
56
|
+
queryAndPayFor(
|
|
56
57
|
_destinationDomain,
|
|
57
58
|
_target,
|
|
58
59
|
_targetData,
|
|
59
|
-
|
|
60
|
+
this.handleQueryUint256Result.selector,
|
|
61
|
+
_gasAmount
|
|
60
62
|
);
|
|
61
|
-
_payForGas(_messageId, _destinationDomain, _gasAmount);
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
function handleQueryUint256Result(uint256 _result) external {
|
|
@@ -72,13 +73,13 @@ contract TestQuerySender {
|
|
|
72
73
|
bytes calldata _targetData,
|
|
73
74
|
uint256 _gasAmount
|
|
74
75
|
) external payable {
|
|
75
|
-
|
|
76
|
+
queryAndPayFor(
|
|
76
77
|
_destinationDomain,
|
|
77
78
|
_target,
|
|
78
79
|
_targetData,
|
|
79
|
-
|
|
80
|
+
this.handleQueryBytes32Result.selector,
|
|
81
|
+
_gasAmount
|
|
80
82
|
);
|
|
81
|
-
_payForGas(_messageId, _destinationDomain, _gasAmount);
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
function handleQueryBytes32Result(bytes32 _result) external {
|
|
@@ -86,11 +87,21 @@ contract TestQuerySender {
|
|
|
86
87
|
lastBytes32Result = _result;
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
function
|
|
90
|
-
bytes32 _messageId,
|
|
90
|
+
function queryAndPayFor(
|
|
91
91
|
uint32 _destinationDomain,
|
|
92
|
+
address _target,
|
|
93
|
+
bytes calldata _targetData,
|
|
94
|
+
bytes4 _callbackSelector,
|
|
92
95
|
uint256 _gasAmount
|
|
93
96
|
) internal {
|
|
97
|
+
CallLib.StaticCallWithCallback[]
|
|
98
|
+
memory calls = new CallLib.StaticCallWithCallback[](1);
|
|
99
|
+
calls[0] = CallLib.build(
|
|
100
|
+
_target,
|
|
101
|
+
_targetData,
|
|
102
|
+
abi.encodePacked(_callbackSelector)
|
|
103
|
+
);
|
|
104
|
+
bytes32 _messageId = queryRouter.query(_destinationDomain, calls);
|
|
94
105
|
interchainGasPaymaster.payForGas{value: msg.value}(
|
|
95
106
|
_messageId,
|
|
96
107
|
_destinationDomain,
|