Skip to content

Commit 302342c

Browse files
authored
Merge branch 'main' into backlinks
2 parents 352bbd8 + e471ace commit 302342c

File tree

5 files changed

+6
-212
lines changed

5 files changed

+6
-212
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ forge install wormhole-foundation/wormhole-solidity-sdk
2828
Look at [test/Fork.t.sol](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/test/Fork.t.sol#L16) for an example usage of Base
2929
- Included are also the ‘[TokenSender](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/src/WormholeRelayerSDK.sol#L79)’ and ‘[TokenReceiver](https://github.com/wormhole-foundation/wormhole-solidity-sdk/blob/main/src/WormholeRelayerSDK.sol#L186)’ base classes with helpers for smart contracts that wish to send and receive tokens using Wormhole’s TokenBridge. See ‘[HelloToken](https://github.com/wormhole-foundation/hello-token)’ for example usage.
3030
- Included are helpers that help set up a local forge testing environment. See ‘[HelloWormhole](https://github.com/wormhole-foundation/hello-wormhole)’ for example usage.
31+
**Note: This code is meant to be used as starter / reference code. Feel free to modify for use in your contracts, and also make sure to audit any code used from here as part of your contracts before deploying to mainnet.**

src/WormholeRelayerSDK.sol

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -163,24 +163,6 @@ abstract contract TokenSender is TokenBase {
163163
targetChain, targetAddress, payload, receiverValue, gasLimit, vaaKeys, refundChain, refundAddress
164164
);
165165
}
166-
167-
function forwardTokenWithPayloadToEvm(
168-
uint16 targetChain,
169-
address targetAddress,
170-
bytes memory payload,
171-
uint256 receiverValue,
172-
uint256 gasLimit,
173-
uint256 forwardMsgValue,
174-
address token,
175-
uint256 amount
176-
) internal {
177-
VaaKey[] memory vaaKeys = new VaaKey[](1);
178-
vaaKeys[0] = transferTokens(token, amount, targetChain, targetAddress);
179-
180-
wormholeRelayer.forwardVaasToEvm{value: forwardMsgValue}(
181-
targetChain, targetAddress, payload, receiverValue, gasLimit, vaaKeys
182-
);
183-
}
184166
}
185167

186168
abstract contract TokenReceiver is TokenBase {

src/interfaces/IWormholeReceiver.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface IWormholeReceiver {
1717
* on every call, checks that deliveryHash has not already been stored in the
1818
* map (This is to prevent other users maliciously trying to relay the same message)
1919
* - Checks that `sourceChain` and `sourceAddress` are indeed who
20-
* you expect to have requested the calling of `send` or `forward` on the source chain
20+
* you expect to have requested the calling of `send` on the source chain
2121
*
2222
* The invocation of this function corresponding to the `send` request will have msg.value equal
2323
* to the receiverValue specified in the send request.

src/interfaces/IWormholeRelayer.sol

Lines changed: 3 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -238,182 +238,6 @@ interface IWormholeRelayerSend is IWormholeRelayerBase {
238238
uint8 consistencyLevel
239239
) external payable returns (uint64 sequence);
240240

241-
/**
242-
* @notice Performs the same function as a `send`, except:
243-
* 1) Can only be used during a delivery (i.e. in execution of `receiveWormholeMessages`)
244-
* 2) Is paid for (along with any other calls to forward) by (any msg.value passed in) + (refund leftover from current delivery)
245-
* 3) Only executes after `receiveWormholeMessages` is completed (and thus does not return a sequence number)
246-
*
247-
* The refund from the delivery currently in progress will not be sent to the user; it will instead
248-
* be paid to the delivery provider to perform the instruction specified here
249-
*
250-
* Publishes an instruction for the same delivery provider (or default, if the same one doesn't support the new target chain)
251-
* to relay a payload to the address `targetAddress` on chain `targetChain`
252-
* with gas limit `gasLimit` and with `msg.value` equal to `receiverValue`
253-
*
254-
* The following equation must be satisfied (sum_f indicates summing over all forwards requested in `receiveWormholeMessages`):
255-
* (refund amount from current execution of receiveWormholeMessages) + sum_f [msg.value_f]
256-
* >= sum_f [quoteEVMDeliveryPrice(targetChain_f, receiverValue_f, gasLimit_f)]
257-
*
258-
* The difference between the two sides of the above inequality will be added to `paymentForExtraReceiverValue` of the first forward requested
259-
*
260-
* Any refunds (from leftover gas) from this forward will be paid to the same refundChain and refundAddress specified for the current delivery.
261-
*
262-
* @param targetChain in Wormhole Chain ID format
263-
* @param targetAddress address to call on targetChain (that implements IWormholeReceiver), in Wormhole bytes32 format
264-
* @param payload arbitrary bytes to pass in as parameter in call to `targetAddress`
265-
* @param receiverValue msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units)
266-
* @param gasLimit gas limit with which to call `targetAddress`.
267-
*/
268-
function forwardPayloadToEvm(
269-
uint16 targetChain,
270-
address targetAddress,
271-
bytes memory payload,
272-
uint256 receiverValue,
273-
uint256 gasLimit
274-
) external payable;
275-
276-
/**
277-
* @notice Performs the same function as a `send`, except:
278-
* 1) Can only be used during a delivery (i.e. in execution of `receiveWormholeMessages`)
279-
* 2) Is paid for (along with any other calls to forward) by (any msg.value passed in) + (refund leftover from current delivery)
280-
* 3) Only executes after `receiveWormholeMessages` is completed (and thus does not return a sequence number)
281-
*
282-
* The refund from the delivery currently in progress will not be sent to the user; it will instead
283-
* be paid to the delivery provider to perform the instruction specified here
284-
*
285-
* Publishes an instruction for the same delivery provider (or default, if the same one doesn't support the new target chain)
286-
* to relay a payload and VAAs specified by `vaaKeys` to the address `targetAddress` on chain `targetChain`
287-
* with gas limit `gasLimit` and with `msg.value` equal to `receiverValue`
288-
*
289-
* The following equation must be satisfied (sum_f indicates summing over all forwards requested in `receiveWormholeMessages`):
290-
* (refund amount from current execution of receiveWormholeMessages) + sum_f [msg.value_f]
291-
* >= sum_f [quoteEVMDeliveryPrice(targetChain_f, receiverValue_f, gasLimit_f)]
292-
*
293-
* The difference between the two sides of the above inequality will be added to `paymentForExtraReceiverValue` of the first forward requested
294-
*
295-
* Any refunds (from leftover gas) from this forward will be paid to the same refundChain and refundAddress specified for the current delivery.
296-
*
297-
* @param targetChain in Wormhole Chain ID format
298-
* @param targetAddress address to call on targetChain (that implements IWormholeReceiver), in Wormhole bytes32 format
299-
* @param payload arbitrary bytes to pass in as parameter in call to `targetAddress`
300-
* @param receiverValue msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units)
301-
* @param gasLimit gas limit with which to call `targetAddress`.
302-
* @param vaaKeys Additional VAAs to pass in as parameter in call to `targetAddress`
303-
*/
304-
function forwardVaasToEvm(
305-
uint16 targetChain,
306-
address targetAddress,
307-
bytes memory payload,
308-
uint256 receiverValue,
309-
uint256 gasLimit,
310-
VaaKey[] memory vaaKeys
311-
) external payable;
312-
313-
/**
314-
* @notice Performs the same function as a `send`, except:
315-
* 1) Can only be used during a delivery (i.e. in execution of `receiveWormholeMessages`)
316-
* 2) Is paid for (along with any other calls to forward) by (any msg.value passed in) + (refund leftover from current delivery)
317-
* 3) Only executes after `receiveWormholeMessages` is completed (and thus does not return a sequence number)
318-
*
319-
* The refund from the delivery currently in progress will not be sent to the user; it will instead
320-
* be paid to the delivery provider to perform the instruction specified here
321-
*
322-
* Publishes an instruction for the delivery provider at `deliveryProviderAddress`
323-
* to relay a payload and VAAs specified by `vaaKeys` to the address `targetAddress` on chain `targetChain`
324-
* with gas limit `gasLimit` and with `msg.value` equal to
325-
* receiverValue + (arbitrary amount that is paid for by paymentForExtraReceiverValue of this chain's wei) in targetChain wei.
326-
*
327-
* Any refunds (from leftover gas) will be sent to `refundAddress` on chain `refundChain`
328-
* `targetAddress` must implement the IWormholeReceiver interface
329-
*
330-
* The following equation must be satisfied (sum_f indicates summing over all forwards requested in `receiveWormholeMessages`):
331-
* (refund amount from current execution of receiveWormholeMessages) + sum_f [msg.value_f]
332-
* >= sum_f [quoteEVMDeliveryPrice(targetChain_f, receiverValue_f, gasLimit_f, deliveryProviderAddress_f) + paymentForExtraReceiverValue_f]
333-
*
334-
* The difference between the two sides of the above inequality will be added to `paymentForExtraReceiverValue` of the first forward requested
335-
*
336-
* @param targetChain in Wormhole Chain ID format
337-
* @param targetAddress address to call on targetChain (that implements IWormholeReceiver), in Wormhole bytes32 format
338-
* @param payload arbitrary bytes to pass in as parameter in call to `targetAddress`
339-
* @param receiverValue msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units)
340-
* @param paymentForExtraReceiverValue amount (in current chain currency units) to spend on extra receiverValue
341-
* (in addition to the `receiverValue` specified)
342-
* @param gasLimit gas limit with which to call `targetAddress`. Any units of gas unused will be refunded according to the
343-
* `targetChainRefundPerGasUnused` rate quoted by the delivery provider
344-
* @param refundChain The chain to deliver any refund to, in Wormhole Chain ID format
345-
* @param refundAddress The address on `refundChain` to deliver any refund to, in Wormhole bytes32 format
346-
* @param deliveryProviderAddress The address of the desired delivery provider's implementation of IDeliveryProvider
347-
* @param vaaKeys Additional VAAs to pass in as parameter in call to `targetAddress`
348-
* @param consistencyLevel Consistency level with which to publish the delivery instructions - see
349-
* https://book.wormhole.com/wormhole/3_coreLayerContracts.html?highlight=consistency#consistency-levels
350-
*/
351-
function forwardToEvm(
352-
uint16 targetChain,
353-
address targetAddress,
354-
bytes memory payload,
355-
uint256 receiverValue,
356-
uint256 paymentForExtraReceiverValue,
357-
uint256 gasLimit,
358-
uint16 refundChain,
359-
address refundAddress,
360-
address deliveryProviderAddress,
361-
VaaKey[] memory vaaKeys,
362-
uint8 consistencyLevel
363-
) external payable;
364-
365-
/**
366-
* @notice Performs the same function as a `send`, except:
367-
* 1) Can only be used during a delivery (i.e. in execution of `receiveWormholeMessages`)
368-
* 2) Is paid for (along with any other calls to forward) by (any msg.value passed in) + (refund leftover from current delivery)
369-
* 3) Only executes after `receiveWormholeMessages` is completed (and thus does not return a sequence number)
370-
*
371-
* The refund from the delivery currently in progress will not be sent to the user; it will instead
372-
* be paid to the delivery provider to perform the instruction specified here
373-
*
374-
* Publishes an instruction for the delivery provider at `deliveryProviderAddress`
375-
* to relay a payload and VAAs specified by `vaaKeys` to the address `targetAddress` on chain `targetChain`
376-
* with `msg.value` equal to
377-
* receiverValue + (arbitrary amount that is paid for by paymentForExtraReceiverValue of this chain's wei) in targetChain wei.
378-
*
379-
* Any refunds (from leftover gas) will be sent to `refundAddress` on chain `refundChain`
380-
* `targetAddress` must implement the IWormholeReceiver interface
381-
*
382-
* The following equation must be satisfied (sum_f indicates summing over all forwards requested in `receiveWormholeMessages`):
383-
* (refund amount from current execution of receiveWormholeMessages) + sum_f [msg.value_f]
384-
* >= sum_f [quoteDeliveryPrice(targetChain_f, receiverValue_f, encodedExecutionParameters_f, deliveryProviderAddress_f) + paymentForExtraReceiverValue_f]
385-
*
386-
* The difference between the two sides of the above inequality will be added to `paymentForExtraReceiverValue` of the first forward requested
387-
*
388-
* @param targetChain in Wormhole Chain ID format
389-
* @param targetAddress address to call on targetChain (that implements IWormholeReceiver), in Wormhole bytes32 format
390-
* @param payload arbitrary bytes to pass in as parameter in call to `targetAddress`
391-
* @param receiverValue msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units)
392-
* @param paymentForExtraReceiverValue amount (in current chain currency units) to spend on extra receiverValue
393-
* (in addition to the `receiverValue` specified)
394-
* @param encodedExecutionParameters encoded information on how to execute delivery that may impact pricing
395-
* e.g. for version EVM_V1, this is a struct that encodes the `gasLimit` with which to call `targetAddress`
396-
* @param refundChain The chain to deliver any refund to, in Wormhole Chain ID format
397-
* @param refundAddress The address on `refundChain` to deliver any refund to, in Wormhole bytes32 format
398-
* @param deliveryProviderAddress The address of the desired delivery provider's implementation of IDeliveryProvider
399-
* @param vaaKeys Additional VAAs to pass in as parameter in call to `targetAddress`
400-
* @param consistencyLevel Consistency level with which to publish the delivery instructions - see
401-
* https://book.wormhole.com/wormhole/3_coreLayerContracts.html?highlight=consistency#consistency-levels
402-
*/
403-
function forward(
404-
uint16 targetChain,
405-
bytes32 targetAddress,
406-
bytes memory payload,
407-
uint256 receiverValue,
408-
uint256 paymentForExtraReceiverValue,
409-
bytes memory encodedExecutionParameters,
410-
uint16 refundChain,
411-
bytes32 refundAddress,
412-
address deliveryProviderAddress,
413-
VaaKey[] memory vaaKeys,
414-
uint8 consistencyLevel
415-
) external payable;
416-
417241
/**
418242
* @notice Requests a previously published delivery instruction to be redelivered
419243
* (e.g. with a different delivery provider)
@@ -561,9 +385,7 @@ interface IWormholeRelayerSend is IWormholeRelayerBase {
561385
interface IWormholeRelayerDelivery is IWormholeRelayerBase {
562386
enum DeliveryStatus {
563387
SUCCESS,
564-
RECEIVER_FAILURE,
565-
FORWARD_REQUEST_FAILURE,
566-
FORWARD_REQUEST_SUCCESS
388+
RECEIVER_FAILURE
567389
}
568390

569391
enum RefundStatus {
@@ -585,16 +407,11 @@ interface IWormholeRelayerDelivery is IWormholeRelayerBase {
585407
* @custom:member gasUsed - The amount of gas that was used to call your target contract
586408
* @custom:member status:
587409
* - RECEIVER_FAILURE, if the target contract reverts
588-
* - SUCCESS, if the target contract doesn't revert and no forwards were requested
589-
* - FORWARD_REQUEST_FAILURE, if the target contract doesn't revert, forwards were requested,
590-
* but provided/leftover funds were not sufficient to cover them all
591-
* - FORWARD_REQUEST_SUCCESS, if the target contract doesn't revert and all forwards are covered
410+
* - SUCCESS, if the target contract doesn't revert
592411
* @custom:member additionalStatusInfo:
593-
* - If status is SUCCESS or FORWARD_REQUEST_SUCCESS, then this is empty.
412+
* - If status is SUCCESS, then this is empty.
594413
* - If status is RECEIVER_FAILURE, this is `RETURNDATA_TRUNCATION_THRESHOLD` bytes of the
595414
* return data (i.e. potentially truncated revert reason information).
596-
* - If status is FORWARD_REQUEST_FAILURE, this is also the revert data - the reason the forward failed.
597-
* This will be either an encoded Cancelled, DeliveryProviderReverted, or DeliveryProviderPaymentFailed error
598415
* @custom:member refundStatus - Result of the refund. REFUND_SUCCESS or REFUND_FAIL are for
599416
* refunds where targetChain=refundChain; the others are for targetChain!=refundChain,
600417
* where a cross chain refund is necessary
@@ -663,13 +480,8 @@ error RequestedGasLimitTooLow();
663480
error DeliveryProviderDoesNotSupportTargetChain(address relayer, uint16 chainId);
664481
error DeliveryProviderCannotReceivePayment();
665482

666-
//When calling `forward()` on the WormholeRelayer if no delivery is in progress
667-
error NoDeliveryInProgress();
668483
//When calling `delivery()` a second time even though a delivery is already in progress
669484
error ReentrantDelivery(address msgSender, address lockedBy);
670-
//When any other contract but the delivery target calls `forward()` on the WormholeRelayer while a
671-
// delivery is in progress
672-
error ForwardRequestFromWrongAddress(address msgSender, address deliveryTarget);
673485

674486
error InvalidPayloadId(uint8 parsed, uint8 expected);
675487
error InvalidPayloadLength(uint256 received, uint256 expected);
@@ -687,7 +499,6 @@ error RequesterNotWormholeRelayer();
687499

688500
//When trying to relay a `DeliveryInstruction` to any other chain but the one it was specified for
689501
error TargetChainIsNotThisChain(uint16 targetChain);
690-
error ForwardNotSufficientlyFunded(uint256 amountOfFunds, uint256 amountOfFundsNeeded);
691502
//When a `DeliveryOverride` contains a gas limit that's less than the original
692503
error InvalidOverrideGasLimit();
693504
//When a `DeliveryOverride` contains a receiver value that's less than the original

src/testing/WormholeRelayerTest.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ abstract contract WormholeRelayerTest is Test {
309309
chainInfosMainnet[24] = ChainInfo({
310310
chainId: 24,
311311
name: "optimism",
312-
url: "https://rpc.ankr.com/arbitrum",
312+
url: "https://rpc.ankr.com/optimism",
313313
relayer: IWormholeRelayer(0x27428DD2d3DD32A4D7f7C497eAaa23130d894911),
314314
tokenBridge: ITokenBridge(0x1D68124e65faFC907325e3EDbF8c4d84499DAa8b),
315315
wormhole: IWormhole(0xEe91C335eab126dF5fDB3797EA9d6aD93aeC9722)

0 commit comments

Comments
 (0)