Skip to content

Commit 18c32ed

Browse files
yorhodesnambrot
andauthored
chore: refactor warp route inheritance tree (#7064)
Co-authored-by: nambrot <[email protected]>
1 parent d33495a commit 18c32ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1690
-1269
lines changed

.changeset/big-papayas-grow.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@hyperlane-xyz/core": major
3+
---
4+
5+
Refactor warp route contracts for shallower inheritance tree and smaller bytecode size.
6+
7+
Deprecated `Router` and `GasRouter` internal functions have been removed.
8+
9+
`FungibleTokenRouter` has been removed and functionality lifted into `TokenRouter`.
10+
11+
`quoteTransferRemote` and `transferRemote` can no longer be overriden with optional `hook` and `hookMetadata` for simplicity.
12+
13+
`quoteTransferRemote` returns a consistent shape of `[nativeMailboxDispatchFee, internalTokenFee, externalTokenFee]`.
14+
15+
`HypNative` and `HypERC20Collateral` inherit from `MovableCollateral` and `LpCollateral` but other extensions (eg `HypXERC20`) do not. Storage layouts have been preserved to ensure upgrade compatibility.

.changeset/mean-pigs-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperlane-xyz/helloworld": patch
3+
---
4+
5+
Update HelloWorld to use new Router utils

.changeset/sharp-clouds-pay.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@hyperlane-xyz/sdk": minor
3+
"@hyperlane-xyz/cli": patch
4+
---
5+
6+
Decouple movable collateral and hyp collateral token adapters

solidity/contracts/client/GasRouter.sol

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ abstract contract GasRouter is Router {
5959
function quoteGasPayment(
6060
uint32 _destinationDomain
6161
) public view virtual returns (uint256) {
62-
return _GasRouter_quoteDispatch(_destinationDomain, "", address(hook));
62+
return
63+
_Router_quoteDispatch(
64+
_destinationDomain,
65+
"",
66+
_GasRouter_hookMetadata(_destinationDomain),
67+
address(hook)
68+
);
6369
}
6470

6571
function _GasRouter_hookMetadata(
@@ -73,34 +79,4 @@ abstract contract GasRouter is Router {
7379
destinationGas[domain] = gas;
7480
emit GasSet(domain, gas);
7581
}
76-
77-
function _GasRouter_dispatch(
78-
uint32 _destination,
79-
uint256 _value,
80-
bytes memory _messageBody,
81-
address _hook
82-
) internal returns (bytes32) {
83-
return
84-
_Router_dispatch(
85-
_destination,
86-
_value,
87-
_messageBody,
88-
_GasRouter_hookMetadata(_destination),
89-
_hook
90-
);
91-
}
92-
93-
function _GasRouter_quoteDispatch(
94-
uint32 _destination,
95-
bytes memory _messageBody,
96-
address _hook
97-
) internal view returns (uint256) {
98-
return
99-
_Router_quoteDispatch(
100-
_destination,
101-
_messageBody,
102-
_GasRouter_hookMetadata(_destination),
103-
_hook
104-
);
105-
}
10682
}

solidity/contracts/client/Router.sol

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,21 @@ abstract contract Router is MailboxClient, IMessageRecipient {
169169
);
170170
}
171171

172+
function _Router_dispatch(
173+
uint32 _destinationDomain,
174+
uint256 _value,
175+
bytes memory _messageBody
176+
) internal returns (bytes32) {
177+
return
178+
_Router_dispatch(
179+
_destinationDomain,
180+
_value,
181+
_messageBody,
182+
"",
183+
address(hook)
184+
);
185+
}
186+
172187
function _Router_dispatch(
173188
uint32 _destinationDomain,
174189
uint256 _value,
@@ -187,18 +202,13 @@ abstract contract Router is MailboxClient, IMessageRecipient {
187202
);
188203
}
189204

190-
/**
191-
* DEPRECATED: Use `_Router_dispatch` instead
192-
* @dev For backward compatibility with v2 client contracts
193-
*/
194-
function _dispatch(
205+
function _Router_quoteDispatch(
195206
uint32 _destinationDomain,
196207
bytes memory _messageBody
197-
) internal returns (bytes32) {
208+
) internal view returns (uint256) {
198209
return
199-
_Router_dispatch(
210+
_Router_quoteDispatch(
200211
_destinationDomain,
201-
msg.value,
202212
_messageBody,
203213
"",
204214
address(hook)
@@ -221,21 +231,4 @@ abstract contract Router is MailboxClient, IMessageRecipient {
221231
IPostDispatchHook(_hook)
222232
);
223233
}
224-
225-
/**
226-
* DEPRECATED: Use `_Router_quoteDispatch` instead
227-
* @dev For backward compatibility with v2 client contracts
228-
*/
229-
function _quoteDispatch(
230-
uint32 _destinationDomain,
231-
bytes memory _messageBody
232-
) internal view returns (uint256) {
233-
return
234-
_Router_quoteDispatch(
235-
_destinationDomain,
236-
_messageBody,
237-
"",
238-
address(hook)
239-
);
240-
}
241234
}

solidity/contracts/middleware/InterchainQueryRouter.sol

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ contract InterchainQueryRouter is Router {
6969
address _to,
7070
bytes memory _data,
7171
bytes memory _callback
72-
) public returns (bytes32 messageId) {
72+
) public payable returns (bytes32 messageId) {
7373
emit QueryDispatched(_destination, msg.sender);
7474

75-
messageId = _dispatch(
75+
messageId = _Router_dispatch(
7676
_destination,
77+
msg.value,
7778
InterchainQueryMessage.encode(
7879
msg.sender.addressToBytes32(),
7980
_to,
@@ -93,10 +94,11 @@ contract InterchainQueryRouter is Router {
9394
function query(
9495
uint32 _destination,
9596
CallLib.StaticCallWithCallback[] calldata calls
96-
) public returns (bytes32 messageId) {
97+
) public payable returns (bytes32 messageId) {
9798
emit QueryDispatched(_destination, msg.sender);
98-
messageId = _dispatch(
99+
messageId = _Router_dispatch(
99100
_destination,
101+
msg.value,
100102
InterchainQueryMessage.encode(msg.sender.addressToBytes32(), calls)
101103
);
102104
}
@@ -121,8 +123,9 @@ contract InterchainQueryRouter is Router {
121123
callsWithCallback
122124
);
123125
emit QueryExecuted(_origin, sender);
124-
_dispatch(
126+
_Router_dispatch(
125127
_origin,
128+
msg.value,
126129
InterchainQueryMessage.encode(sender, callbacks)
127130
);
128131
} else if (messageType == InterchainQueryMessage.MessageType.RESPONSE) {

solidity/contracts/test/TestGasRouter.sol

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,26 @@ contract TestGasRouter is GasRouter {
77
constructor(address _mailbox) GasRouter(_mailbox) {}
88

99
function dispatch(uint32 _destination, bytes memory _msg) external payable {
10-
_GasRouter_dispatch(_destination, msg.value, _msg, address(hook));
10+
_Router_dispatch(
11+
_destination,
12+
msg.value,
13+
_msg,
14+
_GasRouter_hookMetadata(_destination),
15+
address(hook)
16+
);
17+
}
18+
19+
function quoteDispatch(
20+
uint32 _destination,
21+
bytes memory _msg
22+
) external view returns (uint256) {
23+
return
24+
_Router_quoteDispatch(
25+
_destination,
26+
_msg,
27+
_GasRouter_hookMetadata(_destination),
28+
address(hook)
29+
);
1130
}
1231

1332
function _handle(uint32, bytes32, bytes calldata) internal pure override {}

solidity/contracts/test/TestLpCollateralRouter.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
pragma solidity >=0.8.0;
33

44
import {LpCollateralRouter} from "../token/libs/LpCollateralRouter.sol";
5-
import {FungibleTokenRouter} from "../token/libs/FungibleTokenRouter.sol";
5+
import {TokenRouter} from "../token/libs/TokenRouter.sol";
66

77
contract TestLpCollateralRouter is LpCollateralRouter {
88
constructor(
99
uint256 _scale,
1010
address _mailbox
11-
) FungibleTokenRouter(_scale, _mailbox) initializer {
11+
) TokenRouter(_scale, _mailbox) initializer {
1212
_LpCollateralRouter_initialize();
1313
}
1414

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.8.0;
3+
4+
import {LpCollateralRouter} from "../token/libs/LpCollateralRouter.sol";
5+
import {TokenRouter} from "../token/libs/TokenRouter.sol";
6+
7+
contract TestLpCollateralRouter is LpCollateralRouter {
8+
constructor(
9+
uint256 _scale,
10+
address _mailbox
11+
) TokenRouter(_scale, _mailbox) initializer {
12+
_LpCollateralRouter_initialize();
13+
}
14+
15+
function token() public view override returns (address) {
16+
return address(0);
17+
}
18+
19+
function _transferFromSender(uint256 _amount) internal override {}
20+
21+
function _transferTo(
22+
address _recipient,
23+
uint256 _amount
24+
) internal override {}
25+
}

solidity/contracts/test/TestRouter.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ contract TestRouter is Router {
3131
}
3232

3333
function dispatch(uint32 _destination, bytes memory _msg) external payable {
34-
_dispatch(_destination, _msg);
34+
_Router_dispatch(_destination, msg.value, _msg);
3535
}
3636
}

0 commit comments

Comments
 (0)