Skip to content

Commit 2f2bea4

Browse files
authored
Pass endpoint instruction to quote delivery price (#128)
* Pass endpoint instruction to quote delivery price * Fix IntegrationRelayer tests
1 parent f384868 commit 2f2bea4

12 files changed

+121
-268
lines changed

src/Endpoint.sol

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ abstract contract Endpoint is PausableOwnable {
1919
EndpointStructs.ManagerMessage memory payload
2020
) internal virtual;
2121

22-
function _quoteDeliveryPrice(uint16 targetChain) internal view virtual returns (uint256);
22+
function _quoteDeliveryPrice(
23+
uint16 targetChain,
24+
EndpointStructs.EndpointInstruction memory endpointInstruction
25+
) internal view virtual returns (uint256);
2326

2427
/// @notice pause the endpoint
2528
function _pauseEndpoint() internal {

src/EndpointAndManager.sol

+5-7
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ abstract contract EndpointAndManager is Endpoint, Manager, Implementation {
3838
_upgrade(newImplementation);
3939
}
4040

41-
function quoteDeliveryPrice(uint16 recipientChain)
42-
public
43-
view
44-
override
45-
returns (uint256[] memory)
46-
{
41+
function quoteDeliveryPrice(
42+
uint16 recipientChain,
43+
EndpointStructs.EndpointInstruction[] memory endpointInstructions
44+
) public view override returns (uint256[] memory) {
4745
uint256[] memory quotes = new uint256[](1);
48-
quotes[0] = _quoteDeliveryPrice(recipientChain);
46+
quotes[0] = _quoteDeliveryPrice(recipientChain, endpointInstructions[0]);
4947
return quotes;
5048
}
5149

src/EndpointStandalone.sol

+5-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,11 @@ abstract contract EndpointStandalone is
7373
_sendMessage(recipientChain, msg.value, msg.sender, instruction, managerMessage);
7474
}
7575

76-
function quoteDeliveryPrice(uint16 targetChain) external view override returns (uint256) {
77-
return _quoteDeliveryPrice(targetChain);
76+
function quoteDeliveryPrice(
77+
uint16 targetChain,
78+
EndpointStructs.EndpointInstruction memory instruction
79+
) external view override returns (uint256) {
80+
return _quoteDeliveryPrice(targetChain, instruction);
7881
}
7982

8083
function _deliverToManager(

src/Manager.sol

+9-10
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,10 @@ abstract contract Manager is
116116

117117
/// @dev This will either cross-call or internal call, depending on whether the contract is standalone or not.
118118
/// This method should return an array of delivery prices corresponding to each endpoint.
119-
function quoteDeliveryPrice(uint16 recipientChain)
120-
public
121-
view
122-
virtual
123-
returns (uint256[] memory);
119+
function quoteDeliveryPrice(
120+
uint16 recipientChain,
121+
EndpointStructs.EndpointInstruction[] memory endpointInstructions
122+
) public view virtual returns (uint256[] memory);
124123

125124
/// @dev This will either cross-call or internal call, depending on whether the contract is standalone or not.
126125
function _sendMessageToEndpoints(
@@ -384,7 +383,11 @@ abstract contract Manager is
384383
address sender,
385384
bytes memory endpointInstructions
386385
) internal returns (uint64 msgSequence) {
387-
uint256[] memory priceQuotes = quoteDeliveryPrice(recipientChain);
386+
// parse and reorganize the endpoint instructions based on index
387+
EndpointStructs.EndpointInstruction[] memory sortedInstructions = EndpointStructs
388+
.sortEndpointInstructions(EndpointStructs.parseEndpointInstructions(endpointInstructions));
389+
390+
uint256[] memory priceQuotes = quoteDeliveryPrice(recipientChain, sortedInstructions);
388391
{
389392
// check up front that msg.value will cover the delivery price
390393
uint256 totalPriceQuote = arraySum(priceQuotes);
@@ -412,10 +415,6 @@ abstract contract Manager is
412415
)
413416
);
414417

415-
// parse and reorganize the endpoint instructions based on index
416-
EndpointStructs.EndpointInstruction[] memory sortedInstructions = EndpointStructs
417-
.sortEndpointInstructions(EndpointStructs.parseEndpointInstructions(endpointInstructions));
418-
419418
// send the message
420419
_sendMessageToEndpoints(
421420
recipientChain, priceQuotes, sortedInstructions, encodedManagerPayload

src/ManagerStandalone.sol

+10-8
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,19 @@ contract ManagerStandalone is IManagerStandalone, Manager, Implementation {
137137
emit EndpointRemoved(endpoint, _threshold.num);
138138
}
139139

140-
function quoteDeliveryPrice(uint16 recipientChain)
141-
public
142-
view
143-
override
144-
returns (uint256[] memory)
145-
{
140+
function quoteDeliveryPrice(
141+
uint16 recipientChain,
142+
EndpointStructs.EndpointInstruction[] memory endpointInstructions
143+
) public view override returns (uint256[] memory) {
146144
address[] storage _enabledEndpoints = _getEnabledEndpointsStorage();
145+
mapping(address => EndpointInfo) storage endpointInfos = _getEndpointInfosStorage();
146+
147147
uint256[] memory priceQuotes = new uint256[](_enabledEndpoints.length);
148148
for (uint256 i = 0; i < _enabledEndpoints.length; i++) {
149-
uint256 endpointPriceQuote =
150-
IEndpointStandalone(_enabledEndpoints[i]).quoteDeliveryPrice(recipientChain);
149+
address endpointAddr = _enabledEndpoints[i];
150+
uint8 registeredEndpointIndex = endpointInfos[endpointAddr].index;
151+
uint256 endpointPriceQuote = IEndpointStandalone(_enabledEndpoints[i])
152+
.quoteDeliveryPrice(recipientChain, endpointInstructions[registeredEndpointIndex]);
151153
priceQuotes[i] = endpointPriceQuote;
152154
}
153155
return priceQuotes;

src/WormholeEndpoint.sol

+13-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
pragma solidity >=0.8.8 <0.9.0;
33

44
import "wormhole-solidity-sdk/WormholeRelayerSDK.sol";
5+
import "wormhole-solidity-sdk/libraries/BytesParsing.sol";
6+
import "wormhole-solidity-sdk/interfaces/IWormhole.sol";
57

68
import "./libraries/EndpointHelpers.sol";
7-
import "./interfaces/IWormhole.sol";
89
import "./interfaces/IWormholeEndpoint.sol";
910
import "./Endpoint.sol";
10-
import "wormhole-solidity-sdk/libraries/BytesParsing.sol";
1111

1212
abstract contract WormholeEndpoint is Endpoint, IWormholeEndpoint, IWormholeReceiver {
1313
using BytesParsing for bytes;
@@ -111,12 +111,17 @@ abstract contract WormholeEndpoint is Endpoint, IWormholeEndpoint, IWormholeRece
111111
return isWormholeRelayingEnabled(chainId) && isWormholeEvmChain(chainId);
112112
}
113113

114-
function _quoteDeliveryPrice(uint16 targetChain)
115-
internal
116-
view
117-
override
118-
returns (uint256 nativePriceQuote)
119-
{
114+
function _quoteDeliveryPrice(
115+
uint16 targetChain,
116+
EndpointStructs.EndpointInstruction memory instruction
117+
) internal view override returns (uint256 nativePriceQuote) {
118+
// Check the special instruction up front to see if we should skip sending via a relayer
119+
WormholeEndpointInstruction memory weIns =
120+
parseWormholeEndpointInstruction(instruction.payload);
121+
if (weIns.shouldSkipRelayerSend) {
122+
return 0;
123+
}
124+
120125
if (checkInvalidRelayingConfig(targetChain)) {
121126
revert InvalidRelayingConfig(targetChain);
122127
}

src/interfaces/IEndpointStandalone.sol

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ interface IEndpointStandalone {
88
error CannotRenounceEndpointOwnership(address currentOwner);
99
error CannotTransferEndpointOwnership(address currentOwner, address newOwner);
1010

11-
function quoteDeliveryPrice(uint16 recipientChain) external view returns (uint256);
11+
function quoteDeliveryPrice(
12+
uint16 recipientChain,
13+
EndpointStructs.EndpointInstruction memory instruction
14+
) external view returns (uint256);
1215

1316
function sendMessage(
1417
uint16 recipientChain,

src/interfaces/IManager.sol

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
pragma solidity >=0.8.8 <0.9.0;
33

44
import "../libraries/NormalizedAmount.sol";
5+
import "../libraries/EndpointStructs.sol";
56

67
interface IManager {
78
error DeliveryPaymentTooLow(uint256 requiredPayment, uint256 providedPayment);
@@ -42,7 +43,10 @@ interface IManager {
4243

4344
function setInboundLimit(uint256 limit, uint16 chainId) external;
4445

45-
function quoteDeliveryPrice(uint16 recipientChain) external view returns (uint256[] memory);
46+
function quoteDeliveryPrice(
47+
uint16 recipientChain,
48+
EndpointStructs.EndpointInstruction[] memory endpointInstructions
49+
) external view returns (uint256[] memory);
4650

4751
function nextMessageSequence() external view returns (uint64);
4852

src/interfaces/IWormhole.sol

-163
This file was deleted.

0 commit comments

Comments
 (0)