diff --git a/src/Base.sol b/src/Base.sol index 492fd24..1f83956 100644 --- a/src/Base.sol +++ b/src/Base.sol @@ -1,4 +1,3 @@ - pragma solidity ^0.8.13; import "./interfaces/IWormholeReceiver.sol"; diff --git a/src/CCTPBase.sol b/src/CCTPBase.sol index 900062b..9c332f4 100644 --- a/src/CCTPBase.sol +++ b/src/CCTPBase.sol @@ -1,4 +1,3 @@ - pragma solidity ^0.8.13; import "./interfaces/IWormholeReceiver.sol"; @@ -94,9 +93,7 @@ abstract contract CCTPSender is CCTPBase { USDC, addressToBytes32CCTP(targetAddress) ); - return MessageKey( - CCTPMessageLib.CCTP_KEY_TYPE, abi.encodePacked(getCCTPDomain(wormhole.chainId()), nonce) - ); + return MessageKey(CCTPMessageLib.CCTP_KEY_TYPE, abi.encodePacked(getCCTPDomain(wormhole.chainId()), nonce)); } function sendUSDCWithPayloadToEvm( @@ -114,7 +111,7 @@ abstract contract CCTPSender is CCTPBase { address defaultDeliveryProvider = wormholeRelayer.getDefaultDeliveryProvider(); (uint256 cost,) = wormholeRelayer.quoteEVMDeliveryPrice(targetChain, receiverValue, gasLimit); - + sequence = wormholeRelayer.sendToEvm{value: cost}( targetChain, targetAddress, diff --git a/src/TokenBase.sol b/src/TokenBase.sol index 0ebdafb..a24d577 100644 --- a/src/TokenBase.sol +++ b/src/TokenBase.sol @@ -1,4 +1,3 @@ - pragma solidity ^0.8.13; import "./interfaces/IWormholeReceiver.sol"; @@ -120,7 +119,6 @@ abstract contract TokenSender is TokenBase { targetChain, targetAddress, payload, receiverValue, gasLimit, vaaKeys, refundChain, refundAddress ); } - } abstract contract TokenReceiver is TokenBase { diff --git a/src/Utils.sol b/src/Utils.sol index 4106e78..d55def5 100644 --- a/src/Utils.sol +++ b/src/Utils.sol @@ -1,4 +1,3 @@ - pragma solidity ^0.8.13; import "./interfaces/IWormholeRelayer.sol"; diff --git a/src/WormholeRelayerSDK.sol b/src/WormholeRelayerSDK.sol index 06c9772..8221b7a 100644 --- a/src/WormholeRelayerSDK.sol +++ b/src/WormholeRelayerSDK.sol @@ -1,4 +1,3 @@ - pragma solidity ^0.8.13; import "./interfaces/IWormholeReceiver.sol"; diff --git a/src/interfaces/CCTPInterfaces/IMessageTransmitter.sol b/src/interfaces/CCTPInterfaces/IMessageTransmitter.sol index c1a12b3..98538bd 100644 --- a/src/interfaces/CCTPInterfaces/IMessageTransmitter.sol +++ b/src/interfaces/CCTPInterfaces/IMessageTransmitter.sol @@ -22,6 +22,4 @@ import "./IReceiver.sol"; * @title IMessageTransmitter * @notice Interface for message transmitters, which both relay and receive messages. */ -interface IMessageTransmitter is IRelayer, IReceiver { - -} +interface IMessageTransmitter is IRelayer, IReceiver {} diff --git a/src/interfaces/CCTPInterfaces/IReceiver.sol b/src/interfaces/CCTPInterfaces/IReceiver.sol index ff8821d..821b467 100644 --- a/src/interfaces/CCTPInterfaces/IReceiver.sol +++ b/src/interfaces/CCTPInterfaces/IReceiver.sol @@ -27,7 +27,5 @@ interface IReceiver { * @param signature The message signature * @return success bool, true if successful */ - function receiveMessage(bytes calldata message, bytes calldata signature) - external - returns (bool success); + function receiveMessage(bytes calldata message, bytes calldata signature) external returns (bool success); } diff --git a/src/interfaces/CCTPInterfaces/IRelayer.sol b/src/interfaces/CCTPInterfaces/IRelayer.sol index a7f50d5..fdf4ae5 100644 --- a/src/interfaces/CCTPInterfaces/IRelayer.sol +++ b/src/interfaces/CCTPInterfaces/IRelayer.sol @@ -28,11 +28,9 @@ interface IRelayer { * @param messageBody Raw bytes content of message * @return nonce reserved by message */ - function sendMessage( - uint32 destinationDomain, - bytes32 recipient, - bytes calldata messageBody - ) external returns (uint64); + function sendMessage(uint32 destinationDomain, bytes32 recipient, bytes calldata messageBody) + external + returns (uint64); /** * @notice Sends an outgoing message from the source domain, with a specified caller on the diff --git a/src/interfaces/CCTPInterfaces/ITokenMessenger.sol b/src/interfaces/CCTPInterfaces/ITokenMessenger.sol index 29e700e..cbf5b37 100644 --- a/src/interfaces/CCTPInterfaces/ITokenMessenger.sol +++ b/src/interfaces/CCTPInterfaces/ITokenMessenger.sol @@ -1,8 +1,7 @@ - pragma solidity ^0.8.0; interface ITokenMessenger { - /** + /** * @notice Deposits and burns tokens from sender to be minted on destination domain. The mint * on the destination domain must be called by `destinationCaller`. * WARNING: if the `destinationCaller` does not represent a valid address as bytes32, then it will not be possible diff --git a/src/interfaces/IWormholeRelayer.sol b/src/interfaces/IWormholeRelayer.sol index b0c28be..6259f65 100644 --- a/src/interfaces/IWormholeRelayer.sol +++ b/src/interfaces/IWormholeRelayer.sol @@ -4,11 +4,11 @@ pragma solidity ^0.8.0; /** * @title WormholeRelayer - * @author - * @notice This project allows developers to build cross-chain applications powered by Wormhole without needing to + * @author + * @notice This project allows developers to build cross-chain applications powered by Wormhole without needing to * write and run their own relaying infrastructure - * - * We implement the IWormholeRelayer interface that allows users to request a delivery provider to relay a payload (and/or additional VAAs) + * + * We implement the IWormholeRelayer interface that allows users to request a delivery provider to relay a payload (and/or additional VAAs) * to a chain and address of their choice. */ @@ -33,11 +33,8 @@ struct MessageKey { bytes encodedKey; } - interface IWormholeRelayerBase { - event SendEvent( - uint64 indexed sequence, uint256 deliveryQuote, uint256 paymentForExtraReceiverValue - ); + event SendEvent(uint64 indexed sequence, uint256 deliveryQuote, uint256 paymentForExtraReceiverValue); function getRegisteredWormholeRelayerContract(uint16 chainId) external view returns (bytes32); @@ -63,21 +60,20 @@ interface IWormholeRelayerBase { * @notice The interface to request deliveries */ interface IWormholeRelayerSend is IWormholeRelayerBase { - /** * @notice Publishes an instruction for the default delivery provider - * to relay a payload to the address `targetAddress` on chain `targetChain` + * to relay a payload to the address `targetAddress` on chain `targetChain` * with gas limit `gasLimit` and `msg.value` equal to `receiverValue` - * + * * `targetAddress` must implement the IWormholeReceiver interface - * + * * This function must be called with `msg.value` equal to `quoteEVMDeliveryPrice(targetChain, receiverValue, gasLimit)` - * - * Any refunds (from leftover gas) will be paid to the delivery provider. In order to receive the refunds, use the `sendPayloadToEvm` function + * + * Any refunds (from leftover gas) will be paid to the delivery provider. In order to receive the refunds, use the `sendPayloadToEvm` function * with `refundChain` and `refundAddress` as parameters - * + * * @param targetChain in Wormhole Chain ID format - * @param targetAddress address to call on targetChain (that implements IWormholeReceiver) + * @param targetAddress address to call on targetChain (that implements IWormholeReceiver) * @param payload arbitrary bytes to pass in as parameter in call to `targetAddress` * @param receiverValue msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units) * @param gasLimit gas limit with which to call `targetAddress`. @@ -93,16 +89,16 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { /** * @notice Publishes an instruction for the default delivery provider - * to relay a payload to the address `targetAddress` on chain `targetChain` + * to relay a payload to the address `targetAddress` on chain `targetChain` * with gas limit `gasLimit` and `msg.value` equal to `receiverValue` - * + * * Any refunds (from leftover gas) will be sent to `refundAddress` on chain `refundChain` * `targetAddress` must implement the IWormholeReceiver interface - * + * * This function must be called with `msg.value` equal to `quoteEVMDeliveryPrice(targetChain, receiverValue, gasLimit)` - * + * * @param targetChain in Wormhole Chain ID format - * @param targetAddress address to call on targetChain (that implements IWormholeReceiver) + * @param targetAddress address to call on targetChain (that implements IWormholeReceiver) * @param payload arbitrary bytes to pass in as parameter in call to `targetAddress` * @param receiverValue msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units) * @param gasLimit gas limit with which to call `targetAddress`. Any units of gas unused will be refunded according to the @@ -123,21 +119,21 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { /** * @notice Publishes an instruction for the default delivery provider - * to relay a payload and VAAs specified by `vaaKeys` to the address `targetAddress` on chain `targetChain` + * to relay a payload and VAAs specified by `vaaKeys` to the address `targetAddress` on chain `targetChain` * with gas limit `gasLimit` and `msg.value` equal to `receiverValue` - * + * * `targetAddress` must implement the IWormholeReceiver interface - * + * * This function must be called with `msg.value` equal to `quoteEVMDeliveryPrice(targetChain, receiverValue, gasLimit)` - * - * Any refunds (from leftover gas) will be paid to the delivery provider. In order to receive the refunds, use the `sendVaasToEvm` function + * + * Any refunds (from leftover gas) will be paid to the delivery provider. In order to receive the refunds, use the `sendVaasToEvm` function * with `refundChain` and `refundAddress` as parameters - * + * * @param targetChain in Wormhole Chain ID format - * @param targetAddress address to call on targetChain (that implements IWormholeReceiver) + * @param targetAddress address to call on targetChain (that implements IWormholeReceiver) * @param payload arbitrary bytes to pass in as parameter in call to `targetAddress` * @param receiverValue msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units) - * @param gasLimit gas limit with which to call `targetAddress`. + * @param gasLimit gas limit with which to call `targetAddress`. * @param vaaKeys Additional VAAs to pass in as parameter in call to `targetAddress` * @return sequence sequence number of published VAA containing delivery instructions */ @@ -152,19 +148,19 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { /** * @notice Publishes an instruction for the default delivery provider - * to relay a payload and VAAs specified by `vaaKeys` to the address `targetAddress` on chain `targetChain` + * to relay a payload and VAAs specified by `vaaKeys` to the address `targetAddress` on chain `targetChain` * with gas limit `gasLimit` and `msg.value` equal to `receiverValue` - * + * * Any refunds (from leftover gas) will be sent to `refundAddress` on chain `refundChain` * `targetAddress` must implement the IWormholeReceiver interface - * + * * This function must be called with `msg.value` equal to `quoteEVMDeliveryPrice(targetChain, receiverValue, gasLimit)` - * + * * @param targetChain in Wormhole Chain ID format - * @param targetAddress address to call on targetChain (that implements IWormholeReceiver) + * @param targetAddress address to call on targetChain (that implements IWormholeReceiver) * @param payload arbitrary bytes to pass in as parameter in call to `targetAddress` * @param receiverValue msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units) - * @param gasLimit gas limit with which to call `targetAddress`. Any units of gas unused will be refunded according to the + * @param gasLimit gas limit with which to call `targetAddress`. Any units of gas unused will be refunded according to the * `targetChainRefundPerGasUnused` rate quoted by the delivery provider * @param vaaKeys Additional VAAs to pass in as parameter in call to `targetAddress` * @param refundChain The chain to deliver any refund to, in Wormhole Chain ID format @@ -183,30 +179,30 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { ) external payable returns (uint64 sequence); /** - * @notice Publishes an instruction for the delivery provider at `deliveryProviderAddress` - * to relay a payload and VAAs specified by `vaaKeys` to the address `targetAddress` on chain `targetChain` - * with gas limit `gasLimit` and `msg.value` equal to + * @notice Publishes an instruction for the delivery provider at `deliveryProviderAddress` + * to relay a payload and VAAs specified by `vaaKeys` to the address `targetAddress` on chain `targetChain` + * with gas limit `gasLimit` and `msg.value` equal to * receiverValue + (arbitrary amount that is paid for by paymentForExtraReceiverValue of this chain's wei) in targetChain wei. - * + * * Any refunds (from leftover gas) will be sent to `refundAddress` on chain `refundChain` * `targetAddress` must implement the IWormholeReceiver interface - * - * This function must be called with `msg.value` equal to + * + * This function must be called with `msg.value` equal to * quoteEVMDeliveryPrice(targetChain, receiverValue, gasLimit, deliveryProviderAddress) + paymentForExtraReceiverValue - * + * * @param targetChain in Wormhole Chain ID format - * @param targetAddress address to call on targetChain (that implements IWormholeReceiver) + * @param targetAddress address to call on targetChain (that implements IWormholeReceiver) * @param payload arbitrary bytes to pass in as parameter in call to `targetAddress` * @param receiverValue msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units) - * @param paymentForExtraReceiverValue amount (in current chain currency units) to spend on extra receiverValue + * @param paymentForExtraReceiverValue amount (in current chain currency units) to spend on extra receiverValue * (in addition to the `receiverValue` specified) - * @param gasLimit gas limit with which to call `targetAddress`. Any units of gas unused will be refunded according to the + * @param gasLimit gas limit with which to call `targetAddress`. Any units of gas unused will be refunded according to the * `targetChainRefundPerGasUnused` rate quoted by the delivery provider * @param refundChain The chain to deliver any refund to, in Wormhole Chain ID format * @param refundAddress The address on `refundChain` to deliver any refund to * @param deliveryProviderAddress The address of the desired delivery provider's implementation of IDeliveryProvider * @param vaaKeys Additional VAAs to pass in as parameter in call to `targetAddress` - * @param consistencyLevel Consistency level with which to publish the delivery instructions - see + * @param consistencyLevel Consistency level with which to publish the delivery instructions - see * https://book.wormhole.com/wormhole/3_coreLayerContracts.html?highlight=consistency#consistency-levels * @return sequence sequence number of published VAA containing delivery instructions */ @@ -225,33 +221,33 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { ) external payable returns (uint64 sequence); /** - * @notice Publishes an instruction for the delivery provider at `deliveryProviderAddress` - * to relay a payload and external messages specified by `messageKeys` to the address `targetAddress` on chain `targetChain` - * with gas limit `gasLimit` and `msg.value` equal to + * @notice Publishes an instruction for the delivery provider at `deliveryProviderAddress` + * to relay a payload and external messages specified by `messageKeys` to the address `targetAddress` on chain `targetChain` + * with gas limit `gasLimit` and `msg.value` equal to * receiverValue + (arbitrary amount that is paid for by paymentForExtraReceiverValue of this chain's wei) in targetChain wei. - * + * * Any refunds (from leftover gas) will be sent to `refundAddress` on chain `refundChain` * `targetAddress` must implement the IWormholeReceiver interface - * - * This function must be called with `msg.value` equal to + * + * This function must be called with `msg.value` equal to * quoteEVMDeliveryPrice(targetChain, receiverValue, gasLimit, deliveryProviderAddress) + paymentForExtraReceiverValue * - * MessageKeys can specify wormhole messages (VaaKeys) or other types of messages (ex. USDC CCTP attestations). Ensure the selected + * MessageKeys can specify wormhole messages (VaaKeys) or other types of messages (ex. USDC CCTP attestations). Ensure the selected * Note: DeliveryProvider supports all the MessageKey.keyType values specified or it will not be delivered! - * + * * @param targetChain in Wormhole Chain ID format - * @param targetAddress address to call on targetChain (that implements IWormholeReceiver) + * @param targetAddress address to call on targetChain (that implements IWormholeReceiver) * @param payload arbitrary bytes to pass in as parameter in call to `targetAddress` * @param receiverValue msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units) - * @param paymentForExtraReceiverValue amount (in current chain currency units) to spend on extra receiverValue + * @param paymentForExtraReceiverValue amount (in current chain currency units) to spend on extra receiverValue * (in addition to the `receiverValue` specified) - * @param gasLimit gas limit with which to call `targetAddress`. Any units of gas unused will be refunded according to the + * @param gasLimit gas limit with which to call `targetAddress`. Any units of gas unused will be refunded according to the * `targetChainRefundPerGasUnused` rate quoted by the delivery provider * @param refundChain The chain to deliver any refund to, in Wormhole Chain ID format * @param refundAddress The address on `refundChain` to deliver any refund to * @param deliveryProviderAddress The address of the desired delivery provider's implementation of IDeliveryProvider * @param messageKeys Additional messagess to pass in as parameter in call to `targetAddress` - * @param consistencyLevel Consistency level with which to publish the delivery instructions - see + * @param consistencyLevel Consistency level with which to publish the delivery instructions - see * https://book.wormhole.com/wormhole/3_coreLayerContracts.html?highlight=consistency#consistency-levels * @return sequence sequence number of published VAA containing delivery instructions */ @@ -268,24 +264,24 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { MessageKey[] memory messageKeys, uint8 consistencyLevel ) external payable returns (uint64 sequence); - + /** - * @notice Publishes an instruction for the delivery provider at `deliveryProviderAddress` - * to relay a payload and VAAs specified by `vaaKeys` to the address `targetAddress` on chain `targetChain` - * with `msg.value` equal to + * @notice Publishes an instruction for the delivery provider at `deliveryProviderAddress` + * to relay a payload and VAAs specified by `vaaKeys` to the address `targetAddress` on chain `targetChain` + * with `msg.value` equal to * receiverValue + (arbitrary amount that is paid for by paymentForExtraReceiverValue of this chain's wei) in targetChain wei. - * + * * Any refunds (from leftover gas) will be sent to `refundAddress` on chain `refundChain` * `targetAddress` must implement the IWormholeReceiver interface - * - * This function must be called with `msg.value` equal to - * quoteDeliveryPrice(targetChain, receiverValue, encodedExecutionParameters, deliveryProviderAddress) + paymentForExtraReceiverValue - * + * + * This function must be called with `msg.value` equal to + * quoteDeliveryPrice(targetChain, receiverValue, encodedExecutionParameters, deliveryProviderAddress) + paymentForExtraReceiverValue + * * @param targetChain in Wormhole Chain ID format * @param targetAddress address to call on targetChain (that implements IWormholeReceiver), in Wormhole bytes32 format * @param payload arbitrary bytes to pass in as parameter in call to `targetAddress` * @param receiverValue msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units) - * @param paymentForExtraReceiverValue amount (in current chain currency units) to spend on extra receiverValue + * @param paymentForExtraReceiverValue amount (in current chain currency units) to spend on extra receiverValue * (in addition to the `receiverValue` specified) * @param encodedExecutionParameters encoded information on how to execute delivery that may impact pricing * e.g. for version EVM_V1, this is a struct that encodes the `gasLimit` with which to call `targetAddress` @@ -293,7 +289,7 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { * @param refundAddress The address on `refundChain` to deliver any refund to, in Wormhole bytes32 format * @param deliveryProviderAddress The address of the desired delivery provider's implementation of IDeliveryProvider * @param vaaKeys Additional VAAs to pass in as parameter in call to `targetAddress` - * @param consistencyLevel Consistency level with which to publish the delivery instructions - see + * @param consistencyLevel Consistency level with which to publish the delivery instructions - see * https://book.wormhole.com/wormhole/3_coreLayerContracts.html?highlight=consistency#consistency-levels * @return sequence sequence number of published VAA containing delivery instructions */ @@ -312,25 +308,25 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { ) external payable returns (uint64 sequence); /** - * @notice Publishes an instruction for the delivery provider at `deliveryProviderAddress` - * to relay a payload and VAAs specified by `vaaKeys` to the address `targetAddress` on chain `targetChain` - * with `msg.value` equal to + * @notice Publishes an instruction for the delivery provider at `deliveryProviderAddress` + * to relay a payload and VAAs specified by `vaaKeys` to the address `targetAddress` on chain `targetChain` + * with `msg.value` equal to * receiverValue + (arbitrary amount that is paid for by paymentForExtraReceiverValue of this chain's wei) in targetChain wei. - * + * * Any refunds (from leftover gas) will be sent to `refundAddress` on chain `refundChain` * `targetAddress` must implement the IWormholeReceiver interface - * - * This function must be called with `msg.value` equal to - * quoteDeliveryPrice(targetChain, receiverValue, encodedExecutionParameters, deliveryProviderAddress) + paymentForExtraReceiverValue * - * MessageKeys can specify wormhole messages (VaaKeys) or other types of messages (ex. USDC CCTP attestations). Ensure the selected + * This function must be called with `msg.value` equal to + * quoteDeliveryPrice(targetChain, receiverValue, encodedExecutionParameters, deliveryProviderAddress) + paymentForExtraReceiverValue + * + * MessageKeys can specify wormhole messages (VaaKeys) or other types of messages (ex. USDC CCTP attestations). Ensure the selected * Note: DeliveryProvider supports all the MessageKey.keyType values specified or it will not be delivered! - * + * * @param targetChain in Wormhole Chain ID format * @param targetAddress address to call on targetChain (that implements IWormholeReceiver), in Wormhole bytes32 format * @param payload arbitrary bytes to pass in as parameter in call to `targetAddress` * @param receiverValue msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units) - * @param paymentForExtraReceiverValue amount (in current chain currency units) to spend on extra receiverValue + * @param paymentForExtraReceiverValue amount (in current chain currency units) to spend on extra receiverValue * (in addition to the `receiverValue` specified) * @param encodedExecutionParameters encoded information on how to execute delivery that may impact pricing * e.g. for version EVM_V1, this is a struct that encodes the `gasLimit` with which to call `targetAddress` @@ -338,7 +334,7 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { * @param refundAddress The address on `refundChain` to deliver any refund to, in Wormhole bytes32 format * @param deliveryProviderAddress The address of the desired delivery provider's implementation of IDeliveryProvider * @param messageKeys Additional messagess to pass in as parameter in call to `targetAddress` - * @param consistencyLevel Consistency level with which to publish the delivery instructions - see + * @param consistencyLevel Consistency level with which to publish the delivery instructions - see * https://book.wormhole.com/wormhole/3_coreLayerContracts.html?highlight=consistency#consistency-levels * @return sequence sequence number of published VAA containing delivery instructions */ @@ -357,22 +353,22 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { ) external payable returns (uint64 sequence); /** - * @notice Requests a previously published delivery instruction to be redelivered + * @notice Requests a previously published delivery instruction to be redelivered * (e.g. with a different delivery provider) * - * This function must be called with `msg.value` equal to + * This function must be called with `msg.value` equal to * quoteEVMDeliveryPrice(targetChain, newReceiverValue, newGasLimit, newDeliveryProviderAddress) - * + * * @notice *** This will only be able to succeed if the following is true ** * - newGasLimit >= gas limit of the old instruction * - newReceiverValue >= receiver value of the old instruction * - newDeliveryProvider's `targetChainRefundPerGasUnused` >= old relay provider's `targetChainRefundPerGasUnused` - * - * @param deliveryVaaKey VaaKey identifying the wormhole message containing the + * + * @param deliveryVaaKey VaaKey identifying the wormhole message containing the * previously published delivery instructions * @param targetChain The target chain that the original delivery targeted. Must match targetChain from original delivery instructions * @param newReceiverValue new msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units) - * @param newGasLimit gas limit with which to call `targetAddress`. Any units of gas unused will be refunded according to the + * @param newGasLimit gas limit with which to call `targetAddress`. Any units of gas unused will be refunded according to the * `targetChainRefundPerGasUnused` rate quoted by the delivery provider, to the refund chain and address specified in the original request * @param newDeliveryProviderAddress The address of the desired delivery provider's implementation of IDeliveryProvider * @return sequence sequence number of published VAA containing redelivery instructions @@ -391,13 +387,13 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { ) external payable returns (uint64 sequence); /** - * @notice Requests a previously published delivery instruction to be redelivered - * + * @notice Requests a previously published delivery instruction to be redelivered + * * - * This function must be called with `msg.value` equal to + * This function must be called with `msg.value` equal to * quoteDeliveryPrice(targetChain, newReceiverValue, newEncodedExecutionParameters, newDeliveryProviderAddress) - * - * @param deliveryVaaKey VaaKey identifying the wormhole message containing the + * + * @param deliveryVaaKey VaaKey identifying the wormhole message containing the * previously published delivery instructions * @param targetChain The target chain that the original delivery targeted. Must match targetChain from original delivery instructions * @param newReceiverValue new msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units) @@ -405,7 +401,7 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { * e.g. for version EVM_V1, this is a struct that encodes the `gasLimit` with which to call `targetAddress` * @param newDeliveryProviderAddress The address of the desired delivery provider's implementation of IDeliveryProvider * @return sequence sequence number of published VAA containing redelivery instructions - * + * * @notice *** This will only be able to succeed if the following is true ** * - (For EVM_V1) newGasLimit >= gas limit of the old instruction * - newReceiverValue >= receiver value of the old instruction @@ -421,29 +417,28 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { /** * @notice Returns the price to request a relay to chain `targetChain`, using the default delivery provider - * + * * @param targetChain in Wormhole Chain ID format * @param receiverValue msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units) - * @param gasLimit gas limit with which to call `targetAddress`. + * @param gasLimit gas limit with which to call `targetAddress`. * @return nativePriceQuote Price, in units of current chain currency, that the delivery provider charges to perform the relay - * @return targetChainRefundPerGasUnused amount of target chain currency that will be refunded per unit of gas unused, + * @return targetChainRefundPerGasUnused amount of target chain currency that will be refunded per unit of gas unused, * if a refundAddress is specified */ - function quoteEVMDeliveryPrice( - uint16 targetChain, - uint256 receiverValue, - uint256 gasLimit - ) external view returns (uint256 nativePriceQuote, uint256 targetChainRefundPerGasUnused); + function quoteEVMDeliveryPrice(uint16 targetChain, uint256 receiverValue, uint256 gasLimit) + external + view + returns (uint256 nativePriceQuote, uint256 targetChainRefundPerGasUnused); /** * @notice Returns the price to request a relay to chain `targetChain`, using delivery provider `deliveryProviderAddress` - * + * * @param targetChain in Wormhole Chain ID format * @param receiverValue msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units) - * @param gasLimit gas limit with which to call `targetAddress`. + * @param gasLimit gas limit with which to call `targetAddress`. * @param deliveryProviderAddress The address of the desired delivery provider's implementation of IDeliveryProvider * @return nativePriceQuote Price, in units of current chain currency, that the delivery provider charges to perform the relay - * @return targetChainRefundPerGasUnused amount of target chain currency that will be refunded per unit of gas unused, + * @return targetChainRefundPerGasUnused amount of target chain currency that will be refunded per unit of gas unused, * if a refundAddress is specified */ function quoteEVMDeliveryPrice( @@ -455,7 +450,7 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { /** * @notice Returns the price to request a relay to chain `targetChain`, using delivery provider `deliveryProviderAddress` - * + * * @param targetChain in Wormhole Chain ID format * @param receiverValue msg.value that delivery provider should pass in for call to `targetAddress` (in targetChain currency units) * @param encodedExecutionParameters encoded information on how to execute delivery that may impact pricing @@ -464,7 +459,7 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { * @return nativePriceQuote Price, in units of current chain currency, that the delivery provider charges to perform the relay * @return encodedExecutionInfo encoded information on how the delivery will be executed * e.g. for version EVM_V1, this is a struct that encodes the `gasLimit` and `targetChainRefundPerGasUnused` - * (which is the amount of target chain currency that will be refunded per unit of gas unused, + * (which is the amount of target chain currency that will be refunded per unit of gas unused, * if a refundAddress is specified) */ function quoteDeliveryPrice( @@ -477,18 +472,17 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { /** * @notice Returns the (extra) amount of target chain currency that `targetAddress` * will be called with, if the `paymentForExtraReceiverValue` field is set to `currentChainAmount` - * + * * @param targetChain in Wormhole Chain ID format * @param currentChainAmount The value that `paymentForExtraReceiverValue` will be set to * @param deliveryProviderAddress The address of the desired delivery provider's implementation of IDeliveryProvider * @return targetChainAmount The amount such that if `targetAddress` will be called with `msg.value` equal to * receiverValue + targetChainAmount */ - function quoteNativeForChain( - uint16 targetChain, - uint256 currentChainAmount, - address deliveryProviderAddress - ) external view returns (uint256 targetChainAmount); + function quoteNativeForChain(uint16 targetChain, uint256 currentChainAmount, address deliveryProviderAddress) + external + view + returns (uint256 targetChainAmount); /** * @notice Returns the address of the current default delivery provider @@ -500,7 +494,7 @@ interface IWormholeRelayerSend is IWormholeRelayerBase { /** * @title IWormholeRelayerDelivery - * @notice The interface to execute deliveries. Only relevant for Delivery Providers + * @notice The interface to execute deliveries. Only relevant for Delivery Providers */ interface IWormholeRelayerDelivery is IWormholeRelayerBase { enum DeliveryStatus { @@ -524,10 +518,10 @@ interface IWormholeRelayerDelivery is IWormholeRelayerBase { * corresponding to this delivery request * @custom:member deliveryVaaHash - The hash of the delivery VAA corresponding to this delivery * request - * @custom:member gasUsed - The amount of gas that was used to call your target contract + * @custom:member gasUsed - The amount of gas that was used to call your target contract * @custom:member status: * - RECEIVER_FAILURE, if the target contract reverts - * - SUCCESS, if the target contract doesn't revert + * - SUCCESS, if the target contract doesn't revert * @custom:member additionalStatusInfo: * - If status is SUCCESS, then this is empty. * - If status is RECEIVER_FAILURE, this is `RETURNDATA_TRUNCATION_THRESHOLD` bytes of the @@ -553,14 +547,14 @@ interface IWormholeRelayerDelivery is IWormholeRelayerBase { /** * @notice The delivery provider calls `deliver` to relay messages as described by one delivery instruction - * + * * The delivery provider must pass in the specified (by VaaKeys[]) signed wormhole messages (VAAs) from the source chain * as well as the signed wormhole message with the delivery instructions (the delivery VAA) * * The messages will be relayed to the target address (with the specified gas limit and receiver value) iff the following checks are met: * - the delivery VAA has a valid signature * - the delivery VAA's emitter is one of these WormholeRelayer contracts - * - the delivery provider passed in at least enough of this chain's currency as msg.value (enough meaning the maximum possible refund) + * - the delivery provider passed in at least enough of this chain's currency as msg.value (enough meaning the maximum possible refund) * - the instruction's target chain is this chain * - the relayed signed VAAs match the descriptions in container.messages (the VAA hashes match, or the emitter address, sequence number pair matches, depending on the description given) * @@ -634,4 +628,4 @@ error InsufficientRelayerFunds(uint256 msgValue, uint256 minimum); //When a bytes32 field can't be converted into a 20 byte EVM address, because the 12 padding bytes // are non-zero (duplicated from Utils.sol) -error NotAnEvmAddress(bytes32); \ No newline at end of file +error NotAnEvmAddress(bytes32); diff --git a/src/testing/ERC20Mock.sol b/src/testing/ERC20Mock.sol index 848ec99..fd05666 100644 --- a/src/testing/ERC20Mock.sol +++ b/src/testing/ERC20Mock.sol @@ -1,4 +1,3 @@ - pragma solidity ^0.8.13; import "../interfaces/IERC20.sol"; diff --git a/src/testing/WormholeRelayerTest.sol b/src/testing/WormholeRelayerTest.sol index 4449af5..d14c4a9 100644 --- a/src/testing/WormholeRelayerTest.sol +++ b/src/testing/WormholeRelayerTest.sol @@ -1,4 +1,3 @@ - pragma solidity ^0.8.13; import "../../src/interfaces/IWormholeRelayer.sol"; @@ -145,7 +144,8 @@ abstract contract WormholeRelayerTest is Test { ActiveFork memory firstFork = activeForks[activeForksList[0]]; vm.selectFork(firstFork.fork); - mockOffchainRelayer = new MockOffchainRelayer(address(firstFork.wormhole), address(firstFork.guardian), address(firstFork.circleAttester)); + mockOffchainRelayer = + new MockOffchainRelayer(address(firstFork.wormhole), address(firstFork.guardian), address(firstFork.circleAttester)); // register all active forks with the 'offchain' relayer for (uint256 i = 0; i < activeForksList.length; ++i) { ActiveFork storage fork = activeForks[activeForksList[i]]; @@ -193,7 +193,7 @@ abstract contract WormholeRelayerTest is Test { bytes memory attestation = home.guardian.fetchSignedMessageFromLogs(log, home.chainId); for (uint256 i = 0; i < activeForksList.length; ++i) { - if(activeForksList[i] == home.chainId) { + if (activeForksList[i] == home.chainId) { continue; } ActiveFork memory fork = activeForks[activeForksList[i]]; @@ -217,7 +217,6 @@ abstract contract WormholeRelayerTest is Test { vm.selectFork(originalFork); } - function logFork() public view { uint256 fork = vm.activeFork(); for (uint256 i = 0; i < activeForksList.length; ++i) { @@ -488,7 +487,6 @@ abstract contract WormholeRelayerBasicTest is WormholeRelayerTest { CircleMessageTransmitterSimulator public circleAttesterSource; CircleMessageTransmitterSimulator public circleAttesterTarget; - /* * end activeForks aliases */ @@ -551,11 +549,10 @@ abstract contract WormholeRelayerBasicTest is WormholeRelayerTest { } function setForkChains(bool testnet, uint16 _sourceChain, uint16 _targetChain) public { - if (testnet) { - setTestnetForkChains(_sourceChain, _targetChain); - return; - } - setMainnetForkChains(_sourceChain, _targetChain); + if (testnet) { + setTestnetForkChains(_sourceChain, _targetChain); + return; + } + setMainnetForkChains(_sourceChain, _targetChain); } - } diff --git a/src/testing/helpers/BytesParsing.sol b/src/testing/helpers/BytesParsing.sol index 945da6e..fa9a27f 100644 --- a/src/testing/helpers/BytesParsing.sol +++ b/src/testing/helpers/BytesParsing.sol @@ -1,4 +1,3 @@ - pragma solidity ^0.8.13; library BytesParsing { diff --git a/src/testing/helpers/CircleCCTPSimulator.sol b/src/testing/helpers/CircleCCTPSimulator.sol index df5669c..dd144a6 100644 --- a/src/testing/helpers/CircleCCTPSimulator.sol +++ b/src/testing/helpers/CircleCCTPSimulator.sol @@ -30,8 +30,7 @@ contract CircleMessageTransmitterSimulator { bool public valid; // Taken from forge-std/Script.sol - address private constant VM_ADDRESS = - address(bytes20(uint160(uint256(keccak256("hevm cheat code"))))); + address private constant VM_ADDRESS = address(bytes20(uint160(uint256(keccak256("hevm cheat code"))))); Vm public constant vm = Vm(VM_ADDRESS); // Allow access to MessageTransmitter @@ -48,16 +47,14 @@ contract CircleMessageTransmitterSimulator { messageTransmitter = IMessageTransmitter(messageTransmitter_); attesterPrivateKey = attesterPrivateKey_; valid = messageTransmitter_ != address(0); - if(valid) overrideAttester(vm.addr(attesterPrivateKey)); + if (valid) overrideAttester(vm.addr(attesterPrivateKey)); } function overrideAttester(address attesterPublicKey) internal { { - MessageTransmitterViewAttesterManager attesterManagerInterface = MessageTransmitterViewAttesterManager( - address(messageTransmitter) - ); - address attesterManager = attesterManagerInterface - .attesterManager(); + MessageTransmitterViewAttesterManager attesterManagerInterface = + MessageTransmitterViewAttesterManager(address(messageTransmitter)); + address attesterManager = attesterManagerInterface.attesterManager(); vm.prank(attesterManager); attesterManagerInterface.enableAttester(attesterPublicKey); @@ -66,10 +63,7 @@ contract CircleMessageTransmitterSimulator { } } - - function parseMessageFromMessageTransmitterLog( - Vm.Log memory log - ) internal pure returns (bytes memory message) { + function parseMessageFromMessageTransmitterLog(Vm.Log memory log) internal pure returns (bytes memory message) { uint256 index = 32; // length of payload @@ -82,25 +76,17 @@ contract CircleMessageTransmitterSimulator { // trailing bytes (due to 32 byte slot overlap) require(log.data.length - index < 32, "Too many extra bytes"); index += log.data.length - index; - require( - index == log.data.length, - "failed to parse MessageTransmitter message" - ); + require(index == log.data.length, "failed to parse MessageTransmitter message"); } /** * @notice Finds published messageTransmitter events in forge logs * @param logs The forge Vm.log captured when recording events during test execution */ - function fetchMessageTransmitterLogsFromLogs( - Vm.Log[] memory logs - ) public pure returns (Vm.Log[] memory) { + function fetchMessageTransmitterLogsFromLogs(Vm.Log[] memory logs) public pure returns (Vm.Log[] memory) { uint256 count = 0; for (uint256 i = 0; i < logs.length; i++) { - if ( - logs[i].topics[0] == - keccak256("MessageSent(bytes)") - ) { + if (logs[i].topics[0] == keccak256("MessageSent(bytes)")) { count += 1; } } @@ -110,10 +96,7 @@ contract CircleMessageTransmitterSimulator { uint256 publishedIndex = 0; for (uint256 i = 0; i < logs.length; i++) { - if ( - logs[i].topics[0] == - keccak256("MessageSent(bytes)") - ) { + if (logs[i].topics[0] == keccak256("MessageSent(bytes)")) { published[publishedIndex] = logs[i]; publishedIndex += 1; } @@ -127,31 +110,25 @@ contract CircleMessageTransmitterSimulator { * @param log The forge Vm.log captured when recording events during test execution * @return attestation attested message */ - - function fetchSignedMessageFromLog( - Vm.Log memory log - ) public view returns (CCTPMessageLib.CCTPMessage memory) { + + function fetchSignedMessageFromLog(Vm.Log memory log) public view returns (CCTPMessageLib.CCTPMessage memory) { // Parse messageTransmitter message from ethereum logs bytes memory message = parseMessageFromMessageTransmitterLog(log); return CCTPMessageLib.CCTPMessage(message, signMessage(message)); } - + /** * @notice Signs a simulated messageTransmitter message * @param message The messageTransmitter message * @return signedMessage signed messageTransmitter message */ - - function signMessage( - bytes memory message - ) public view returns (bytes memory signedMessage) { + function signMessage(bytes memory message) public view returns (bytes memory signedMessage) { bytes32 messageHash = keccak256(message); // Sign the hash with the attester private key (uint8 v, bytes32 r, bytes32 s) = vm.sign(attesterPrivateKey, messageHash); return abi.encodePacked(r, s, v); } - } diff --git a/src/testing/helpers/DeliveryInstructionDecoder.sol b/src/testing/helpers/DeliveryInstructionDecoder.sol index 8158317..36a0901 100644 --- a/src/testing/helpers/DeliveryInstructionDecoder.sol +++ b/src/testing/helpers/DeliveryInstructionDecoder.sol @@ -1,4 +1,3 @@ - pragma solidity ^0.8.13; import "../../../src/interfaces/IWormholeRelayer.sol"; @@ -42,9 +41,7 @@ struct DeliveryOverride { bytes32 redeliveryHash; } -function decodeDeliveryInstruction( - bytes memory encoded -) pure returns (DeliveryInstruction memory strct) { +function decodeDeliveryInstruction(bytes memory encoded) pure returns (DeliveryInstruction memory strct) { uint256 offset = checkUint8(encoded, 0, PAYLOAD_ID_DELIVERY_INSTRUCTION); uint256 requestedReceiverValue; @@ -69,9 +66,7 @@ function decodeDeliveryInstruction( checkLength(encoded, offset); } -function decodeRedeliveryInstruction( - bytes memory encoded -) pure returns (RedeliveryInstruction memory strct) { +function decodeRedeliveryInstruction(bytes memory encoded) pure returns (RedeliveryInstruction memory strct) { uint256 offset = checkUint8(encoded, 0, PAYLOAD_ID_REDELIVERY_INSTRUCTION); uint256 newRequestedReceiverValue; @@ -80,9 +75,7 @@ function decodeRedeliveryInstruction( (strct.targetChain, offset) = encoded.asUint16Unchecked(offset); (newRequestedReceiverValue, offset) = encoded.asUint256Unchecked(offset); (strct.newEncodedExecutionInfo, offset) = decodeBytes(encoded, offset); - (strct.newSourceDeliveryProvider, offset) = encoded.asBytes32Unchecked( - offset - ); + (strct.newSourceDeliveryProvider, offset) = encoded.asBytes32Unchecked(offset); (strct.newSenderAddress, offset) = encoded.asBytes32Unchecked(offset); strct.newRequestedReceiverValue = newRequestedReceiverValue; @@ -90,12 +83,10 @@ function decodeRedeliveryInstruction( checkLength(encoded, offset); } -function vaaKeyArrayToMessageKeyArray( - VaaKey[] memory vaaKeys -) pure returns (MessageKey[] memory msgKeys) { +function vaaKeyArrayToMessageKeyArray(VaaKey[] memory vaaKeys) pure returns (MessageKey[] memory msgKeys) { msgKeys = new MessageKey[](vaaKeys.length); uint256 len = vaaKeys.length; - for (uint256 i = 0; i < len; ) { + for (uint256 i = 0; i < len;) { msgKeys[i] = MessageKey(VAA_KEY_TYPE, encodeVaaKey(vaaKeys[i])); unchecked { ++i; @@ -103,66 +94,47 @@ function vaaKeyArrayToMessageKeyArray( } } -function encodeMessageKey( - MessageKey memory msgKey -) pure returns (bytes memory encoded) { +function encodeMessageKey(MessageKey memory msgKey) pure returns (bytes memory encoded) { if (msgKey.keyType == VAA_KEY_TYPE) { // known length encoded = abi.encodePacked(msgKey.keyType, msgKey.encodedKey); } else { - encoded = abi.encodePacked( - msgKey.keyType, - encodeBytes(msgKey.encodedKey) - ); + encoded = abi.encodePacked(msgKey.keyType, encodeBytes(msgKey.encodedKey)); } } uint256 constant VAA_KEY_TYPE_LENGTH = 2 + 32 + 8; -function decodeMessageKey( - bytes memory encoded, - uint256 startOffset -) pure returns (MessageKey memory msgKey, uint256 offset) { +function decodeMessageKey(bytes memory encoded, uint256 startOffset) + pure + returns (MessageKey memory msgKey, uint256 offset) +{ (msgKey.keyType, offset) = encoded.asUint8Unchecked(startOffset); if (msgKey.keyType == VAA_KEY_TYPE) { - (msgKey.encodedKey, offset) = encoded.sliceUnchecked( - offset, - VAA_KEY_TYPE_LENGTH - ); + (msgKey.encodedKey, offset) = encoded.sliceUnchecked(offset, VAA_KEY_TYPE_LENGTH); } else { (msgKey.encodedKey, offset) = decodeBytes(encoded, offset); } } -function encodeVaaKey( - VaaKey memory vaaKey -) pure returns (bytes memory encoded) { - encoded = abi.encodePacked( - vaaKey.chainId, - vaaKey.emitterAddress, - vaaKey.sequence - ); +function encodeVaaKey(VaaKey memory vaaKey) pure returns (bytes memory encoded) { + encoded = abi.encodePacked(vaaKey.chainId, vaaKey.emitterAddress, vaaKey.sequence); } -function decodeVaaKey( - bytes memory encoded, - uint256 startOffset -) pure returns (VaaKey memory vaaKey, uint256 offset) { +function decodeVaaKey(bytes memory encoded, uint256 startOffset) pure returns (VaaKey memory vaaKey, uint256 offset) { offset = startOffset; (vaaKey.chainId, offset) = encoded.asUint16Unchecked(offset); (vaaKey.emitterAddress, offset) = encoded.asBytes32Unchecked(offset); (vaaKey.sequence, offset) = encoded.asUint64Unchecked(offset); } -function encodeMessageKeyArray( - MessageKey[] memory msgKeys -) pure returns (bytes memory encoded) { +function encodeMessageKeyArray(MessageKey[] memory msgKeys) pure returns (bytes memory encoded) { uint256 len = msgKeys.length; if (len > type(uint8).max) { revert TooManyMessageKeys(len); } encoded = abi.encodePacked(uint8(msgKeys.length)); - for (uint256 i = 0; i < len; ) { + for (uint256 i = 0; i < len;) { encoded = abi.encodePacked(encoded, encodeMessageKey(msgKeys[i])); unchecked { ++i; @@ -170,14 +142,14 @@ function encodeMessageKeyArray( } } -function decodeMessageKeyArray( - bytes memory encoded, - uint256 startOffset -) pure returns (MessageKey[] memory msgKeys, uint256 offset) { +function decodeMessageKeyArray(bytes memory encoded, uint256 startOffset) + pure + returns (MessageKey[] memory msgKeys, uint256 offset) +{ uint8 msgKeysLength; (msgKeysLength, offset) = encoded.asUint8Unchecked(startOffset); msgKeys = new MessageKey[](msgKeysLength); - for (uint256 i = 0; i < msgKeysLength; ) { + for (uint256 i = 0; i < msgKeysLength;) { (msgKeys[i], offset) = decodeMessageKey(encoded, offset); unchecked { ++i; @@ -185,10 +157,10 @@ function decodeMessageKeyArray( } } -function decodeCCTPKey( - bytes memory encoded, - uint256 startOffset -) pure returns (CCTPMessageLib.CCTPKey memory cctpKey, uint256 offset) { +function decodeCCTPKey(bytes memory encoded, uint256 startOffset) + pure + returns (CCTPMessageLib.CCTPKey memory cctpKey, uint256 offset) +{ offset = startOffset; (cctpKey.domain, offset) = encoded.asUint32Unchecked(offset); (cctpKey.nonce, offset) = encoded.asUint64Unchecked(offset); @@ -202,20 +174,13 @@ function encodeBytes(bytes memory payload) pure returns (bytes memory encoded) { encoded = abi.encodePacked(uint32(payload.length), payload); } -function decodeBytes( - bytes memory encoded, - uint256 startOffset -) pure returns (bytes memory payload, uint256 offset) { +function decodeBytes(bytes memory encoded, uint256 startOffset) pure returns (bytes memory payload, uint256 offset) { uint32 payloadLength; (payloadLength, offset) = encoded.asUint32Unchecked(startOffset); (payload, offset) = encoded.sliceUnchecked(offset, payloadLength); } -function checkUint8( - bytes memory encoded, - uint256 startOffset, - uint8 expectedPayloadId -) pure returns (uint256 offset) { +function checkUint8(bytes memory encoded, uint256 startOffset, uint8 expectedPayloadId) pure returns (uint256 offset) { uint8 parsedPayloadId; (parsedPayloadId, offset) = encoded.asUint8Unchecked(startOffset); if (parsedPayloadId != expectedPayloadId) { @@ -229,20 +194,13 @@ function checkLength(bytes memory encoded, uint256 expected) pure { } } -function encode( - DeliveryOverride memory strct -) pure returns (bytes memory encoded) { +function encode(DeliveryOverride memory strct) pure returns (bytes memory encoded) { encoded = abi.encodePacked( - VERSION_DELIVERY_OVERRIDE, - strct.newReceiverValue, - encodeBytes(strct.newExecutionInfo), - strct.redeliveryHash + VERSION_DELIVERY_OVERRIDE, strct.newReceiverValue, encodeBytes(strct.newExecutionInfo), strct.redeliveryHash ); } -function decodeDeliveryOverride( - bytes memory encoded -) pure returns (DeliveryOverride memory strct) { +function decodeDeliveryOverride(bytes memory encoded) pure returns (DeliveryOverride memory strct) { uint256 offset = checkUint8(encoded, 0, VERSION_DELIVERY_OVERRIDE); uint256 receiverValue; diff --git a/src/testing/helpers/MockOffchainRelayer.sol b/src/testing/helpers/MockOffchainRelayer.sol index 6d6777e..7dea406 100644 --- a/src/testing/helpers/MockOffchainRelayer.sol +++ b/src/testing/helpers/MockOffchainRelayer.sol @@ -17,16 +17,13 @@ import "forge-std/console.sol"; using BytesParsing for bytes; contract MockOffchainRelayer { - uint16 chainIdOfWormholeAndGuardianUtilities; IWormhole relayerWormhole; WormholeSimulator relayerWormholeSimulator; CircleMessageTransmitterSimulator relayerCircleSimulator; - // Taken from forge-std/Script.sol - address private constant VM_ADDRESS = - address(bytes20(uint160(uint256(keccak256("hevm cheat code"))))); + address private constant VM_ADDRESS = address(bytes20(uint160(uint256(keccak256("hevm cheat code"))))); Vm public constant vm = Vm(VM_ADDRESS); mapping(uint16 => address) wormholeRelayerContracts; @@ -46,31 +43,19 @@ contract MockOffchainRelayer { chainIdOfWormholeAndGuardianUtilities = relayerWormhole.chainId(); } - function getPastEncodedSignedVaas( - uint16 chainId, - uint64 deliveryVAASequence - ) public view returns (bytes[] memory) { - return - pastEncodedSignedVaas[ - keccak256(abi.encodePacked(chainId, deliveryVAASequence)) - ]; + function getPastEncodedSignedVaas(uint16 chainId, uint64 deliveryVAASequence) + public + view + returns (bytes[] memory) + { + return pastEncodedSignedVaas[keccak256(abi.encodePacked(chainId, deliveryVAASequence))]; } - function getPastDeliveryVAA( - uint16 chainId, - uint64 deliveryVAASequence - ) public view returns (bytes memory) { - return - pastEncodedDeliveryVAA[ - keccak256(abi.encodePacked(chainId, deliveryVAASequence)) - ]; + function getPastDeliveryVAA(uint16 chainId, uint64 deliveryVAASequence) public view returns (bytes memory) { + return pastEncodedDeliveryVAA[keccak256(abi.encodePacked(chainId, deliveryVAASequence))]; } - function registerChain( - uint16 chainId, - address wormholeRelayerContractAddress, - uint256 fork - ) public { + function registerChain(uint16 chainId, address wormholeRelayerContractAddress, uint256 fork) public { wormholeRelayerContracts[chainId] = wormholeRelayerContractAddress; forks[chainId] = fork; chainIdFromFork[fork] = chainId; @@ -88,15 +73,10 @@ contract MockOffchainRelayer { relay(logs, bytes(""), false); } - function vaaKeyMatchesVAA( - VaaKey memory vaaKey, - bytes memory signedVaa - ) internal view returns (bool) { + function vaaKeyMatchesVAA(VaaKey memory vaaKey, bytes memory signedVaa) internal view returns (bool) { IWormhole.VM memory parsedVaa = relayerWormhole.parseVM(signedVaa); - return - (vaaKey.chainId == parsedVaa.emitterChainId) && - (vaaKey.emitterAddress == parsedVaa.emitterAddress) && - (vaaKey.sequence == parsedVaa.sequence); + return (vaaKey.chainId == parsedVaa.emitterChainId) && (vaaKey.emitterAddress == parsedVaa.emitterAddress) + && (vaaKey.sequence == parsedVaa.sequence); } function cctpKeyMatchesCCTPMessage( @@ -105,25 +85,16 @@ contract MockOffchainRelayer { ) internal pure returns (bool) { (uint64 nonce,) = cctpMessage.message.asUint64(12); (uint32 domain,) = cctpMessage.message.asUint32(4); - return - nonce == cctpKey.nonce && domain == cctpKey.domain; + return nonce == cctpKey.nonce && domain == cctpKey.domain; } - function relay( - Vm.Log[] memory logs, - bytes memory deliveryOverrides, - bool debugLogging - ) public { + function relay(Vm.Log[] memory logs, bytes memory deliveryOverrides, bool debugLogging) public { uint16 chainId = chainIdFromFork[vm.activeFork()]; - require( - wormholeRelayerContracts[chainId] != address(0), - "Chain not registered with MockOffchainRelayer" - ); + require(wormholeRelayerContracts[chainId] != address(0), "Chain not registered with MockOffchainRelayer"); vm.selectFork(forks[chainIdOfWormholeAndGuardianUtilities]); - Vm.Log[] memory entries = relayerWormholeSimulator - .fetchWormholeMessageFromLog(logs); + Vm.Log[] memory entries = relayerWormholeSimulator.fetchWormholeMessageFromLog(logs); if (debugLogging) { console.log("Found %s wormhole messages in logs", entries.length); @@ -131,17 +102,13 @@ contract MockOffchainRelayer { bytes[] memory encodedSignedVaas = new bytes[](entries.length); for (uint256 i = 0; i < encodedSignedVaas.length; i++) { - encodedSignedVaas[i] = relayerWormholeSimulator.fetchSignedMessageFromLogs( - entries[i], - chainId - ); + encodedSignedVaas[i] = relayerWormholeSimulator.fetchSignedMessageFromLogs(entries[i], chainId); } bool checkCCTP = relayerCircleSimulator.valid(); Vm.Log[] memory cctpEntries = new Vm.Log[](0); - if(checkCCTP) { - cctpEntries = relayerCircleSimulator - .fetchMessageTransmitterLogsFromLogs(logs); + if (checkCCTP) { + cctpEntries = relayerCircleSimulator.fetchMessageTransmitterLogsFromLogs(logs); } if (debugLogging) { @@ -150,9 +117,7 @@ contract MockOffchainRelayer { CCTPMessageLib.CCTPMessage[] memory circleSignedMessages = new CCTPMessageLib.CCTPMessage[](cctpEntries.length); for (uint256 i = 0; i < cctpEntries.length; i++) { - circleSignedMessages[i] = relayerCircleSimulator.fetchSignedMessageFromLog( - cctpEntries[i] - ); + circleSignedMessages[i] = relayerCircleSimulator.fetchSignedMessageFromLog(cctpEntries[i]); } IWormhole.VM[] memory parsed = new IWormhole.VM[](encodedSignedVaas.length); @@ -169,20 +134,15 @@ contract MockOffchainRelayer { } if ( - parsed[i].emitterAddress == - toWormholeFormat(wormholeRelayerContracts[chainId]) && - (parsed[i].emitterChainId == chainId) + parsed[i].emitterAddress == toWormholeFormat(wormholeRelayerContracts[chainId]) + && (parsed[i].emitterChainId == chainId) ) { if (debugLogging) { console.log("Relaying VAA to chain %s", chainId); } vm.selectFork(forks[chainIdOfWormholeAndGuardianUtilities]); genericRelay( - encodedSignedVaas[i], - encodedSignedVaas, - circleSignedMessages, - parsed[i], - deliveryOverrides + encodedSignedVaas[i], encodedSignedVaas, circleSignedMessages, parsed[i], deliveryOverrides ); } } @@ -212,11 +172,9 @@ contract MockOffchainRelayer { IWormhole.VM memory parsedDeliveryVAA, bytes memory deliveryOverrides ) internal { - (uint8 payloadId, ) = parsedDeliveryVAA.payload.asUint8Unchecked(0); + (uint8 payloadId,) = parsedDeliveryVAA.payload.asUint8Unchecked(0); if (payloadId == 1) { - DeliveryInstruction memory instruction = decodeDeliveryInstruction( - parsedDeliveryVAA.payload - ); + DeliveryInstruction memory instruction = decodeDeliveryInstruction(parsedDeliveryVAA.payload); bytes[] memory encodedSignedVaasToBeDelivered = new bytes[]( instruction.messageKeys.length @@ -225,10 +183,7 @@ contract MockOffchainRelayer { for (uint8 i = 0; i < instruction.messageKeys.length; i++) { if (instruction.messageKeys[i].keyType == 1) { // VaaKey - (VaaKey memory vaaKey, ) = decodeVaaKey( - instruction.messageKeys[i].encodedKey, - 0 - ); + (VaaKey memory vaaKey,) = decodeVaaKey(instruction.messageKeys[i].encodedKey, 0); for (uint8 j = 0; j < encodedSignedVaas.length; j++) { if (vaaKeyMatchesVAA(vaaKey, encodedSignedVaas[j])) { encodedSignedVaasToBeDelivered[i] = encodedSignedVaas[j]; @@ -237,24 +192,21 @@ contract MockOffchainRelayer { } } else if (instruction.messageKeys[i].keyType == 2) { // CCTP Key - (CCTPMessageLib.CCTPKey memory key,) = decodeCCTPKey(instruction.messageKeys[i].encodedKey, 0); + (CCTPMessageLib.CCTPKey memory key,) = decodeCCTPKey(instruction.messageKeys[i].encodedKey, 0); for (uint8 j = 0; j < cctpMessages.length; j++) { if (cctpKeyMatchesCCTPMessage(key, cctpMessages[j])) { - encodedSignedVaasToBeDelivered[i] = abi.encode(cctpMessages[j].message, cctpMessages[j].signature); + encodedSignedVaasToBeDelivered[i] = + abi.encode(cctpMessages[j].message, cctpMessages[j].signature); break; } } } } - EvmExecutionInfoV1 memory executionInfo = decodeEvmExecutionInfoV1( - instruction.encodedExecutionInfo - ); + EvmExecutionInfoV1 memory executionInfo = decodeEvmExecutionInfoV1(instruction.encodedExecutionInfo); - uint256 budget = executionInfo.gasLimit * - executionInfo.targetChainRefundPerGasUnused + - instruction.requestedReceiverValue + - instruction.extraReceiverValue; + uint256 budget = executionInfo.gasLimit * executionInfo.targetChainRefundPerGasUnused + + instruction.requestedReceiverValue + instruction.extraReceiverValue; uint16 targetChain = instruction.targetChain; @@ -263,12 +215,8 @@ contract MockOffchainRelayer { vm.deal(address(this), budget); vm.recordLogs(); - IWormholeRelayerDelivery(wormholeRelayerContracts[targetChain]) - .deliver{value: budget}( - encodedSignedVaasToBeDelivered, - encodedDeliveryVAA, - payable(address(this)), - deliveryOverrides + IWormholeRelayerDelivery(wormholeRelayerContracts[targetChain]).deliver{value: budget}( + encodedSignedVaasToBeDelivered, encodedDeliveryVAA, payable(address(this)), deliveryOverrides ); setInfo( @@ -278,10 +226,7 @@ contract MockOffchainRelayer { encodedDeliveryVAA ); } else if (payloadId == 2) { - RedeliveryInstruction - memory instruction = decodeRedeliveryInstruction( - parsedDeliveryVAA.payload - ); + RedeliveryInstruction memory instruction = decodeRedeliveryInstruction(parsedDeliveryVAA.payload); DeliveryOverride memory deliveryOverride = DeliveryOverride({ newExecutionInfo: instruction.newEncodedExecutionInfo, @@ -289,33 +234,21 @@ contract MockOffchainRelayer { redeliveryHash: parsedDeliveryVAA.hash }); - EvmExecutionInfoV1 memory executionInfo = decodeEvmExecutionInfoV1( - instruction.newEncodedExecutionInfo - ); - uint256 budget = executionInfo.gasLimit * - executionInfo.targetChainRefundPerGasUnused + - instruction.newRequestedReceiverValue; + EvmExecutionInfoV1 memory executionInfo = decodeEvmExecutionInfoV1(instruction.newEncodedExecutionInfo); + uint256 budget = executionInfo.gasLimit * executionInfo.targetChainRefundPerGasUnused + + instruction.newRequestedReceiverValue; - bytes memory oldEncodedDeliveryVAA = getPastDeliveryVAA( - instruction.deliveryVaaKey.chainId, - instruction.deliveryVaaKey.sequence - ); - bytes[] memory oldEncodedSignedVaas = getPastEncodedSignedVaas( - instruction.deliveryVaaKey.chainId, - instruction.deliveryVaaKey.sequence - ); + bytes memory oldEncodedDeliveryVAA = + getPastDeliveryVAA(instruction.deliveryVaaKey.chainId, instruction.deliveryVaaKey.sequence); + bytes[] memory oldEncodedSignedVaas = + getPastEncodedSignedVaas(instruction.deliveryVaaKey.chainId, instruction.deliveryVaaKey.sequence); - uint16 targetChain = decodeDeliveryInstruction( - relayerWormhole.parseVM(oldEncodedDeliveryVAA).payload - ).targetChain; + uint16 targetChain = + decodeDeliveryInstruction(relayerWormhole.parseVM(oldEncodedDeliveryVAA).payload).targetChain; vm.selectFork(forks[targetChain]); - IWormholeRelayerDelivery(wormholeRelayerContracts[targetChain]) - .deliver{value: budget}( - oldEncodedSignedVaas, - oldEncodedDeliveryVAA, - payable(address(this)), - encode(deliveryOverride) + IWormholeRelayerDelivery(wormholeRelayerContracts[targetChain]).deliver{value: budget}( + oldEncodedSignedVaas, oldEncodedDeliveryVAA, payable(address(this)), encode(deliveryOverride) ); } } diff --git a/src/testing/helpers/WormholeSimulator.sol b/src/testing/helpers/WormholeSimulator.sol index a73f6ca..1e6991c 100644 --- a/src/testing/helpers/WormholeSimulator.sol +++ b/src/testing/helpers/WormholeSimulator.sol @@ -18,8 +18,7 @@ contract WormholeSimulator { using BytesLib for bytes; // Taken from forge-std/Script.sol - address private constant VM_ADDRESS = - address(bytes20(uint160(uint256(keccak256("hevm cheat code"))))); + address private constant VM_ADDRESS = address(bytes20(uint160(uint256(keccak256("hevm cheat code"))))); Vm public constant vm = Vm(VM_ADDRESS); // Allow access to Wormhole @@ -45,24 +44,15 @@ contract WormholeSimulator { // Get slot for Guardian Set at the current index uint32 guardianSetIndex = wormhole.getCurrentGuardianSetIndex(); - bytes32 guardianSetSlot = keccak256( - abi.encode(guardianSetIndex, 2) - ); + bytes32 guardianSetSlot = keccak256(abi.encode(guardianSetIndex, 2)); // Overwrite all but first guardian set to zero address. This isn't // necessary, but just in case we inadvertently access these slots // for any reason. - uint256 numGuardians = uint256( - vm.load(address(wormhole), guardianSetSlot) - ); - for (uint256 i = 1; i < numGuardians; ) { + uint256 numGuardians = uint256(vm.load(address(wormhole), guardianSetSlot)); + for (uint256 i = 1; i < numGuardians;) { vm.store( - address(wormhole), - bytes32( - uint256(keccak256(abi.encodePacked(guardianSetSlot))) + - i - ), - bytes32(0) + address(wormhole), bytes32(uint256(keccak256(abi.encodePacked(guardianSetSlot))) + i), bytes32(0) ); unchecked { i += 1; @@ -73,9 +63,7 @@ contract WormholeSimulator { // in the function argument. vm.store( address(wormhole), - bytes32( - uint256(keccak256(abi.encodePacked(guardianSetSlot))) + 0 - ), // just explicit w/ index 0 + bytes32(uint256(keccak256(abi.encodePacked(guardianSetSlot))) + 0), // just explicit w/ index 0 bytes32(uint256(uint160(devnetGuardian))) ); @@ -87,26 +75,17 @@ contract WormholeSimulator { ); // Confirm guardian set override - address[] memory guardians = wormhole - .getGuardianSet(guardianSetIndex) - .keys; + address[] memory guardians = wormhole.getGuardianSet(guardianSetIndex).keys; require(guardians.length == 1, "guardians.length != 1"); - require( - guardians[0] == devnetGuardian, - "incorrect guardian set override" - ); + require(guardians[0] == devnetGuardian, "incorrect guardian set override"); } } - function doubleKeccak256( - bytes memory body - ) internal pure returns (bytes32) { + function doubleKeccak256(bytes memory body) internal pure returns (bytes32) { return keccak256(abi.encodePacked(keccak256(body))); } - function parseVMFromLogs( - Vm.Log memory log - ) internal pure returns (IWormhole.VM memory vm_) { + function parseVMFromLogs(Vm.Log memory log) internal pure returns (IWormhole.VM memory vm_) { uint256 index = 0; // emitterAddress @@ -144,17 +123,10 @@ contract WormholeSimulator { * @notice Finds published Wormhole events in forge logs * @param logs The forge Vm.log captured when recording events during test execution */ - function fetchWormholeMessageFromLog( - Vm.Log[] memory logs - ) public pure returns (Vm.Log[] memory) { + function fetchWormholeMessageFromLog(Vm.Log[] memory logs) public pure returns (Vm.Log[] memory) { uint256 count = 0; for (uint256 i = 0; i < logs.length; i++) { - if ( - logs[i].topics[0] == - keccak256( - "LogMessagePublished(address,uint64,uint32,bytes,uint8)" - ) - ) { + if (logs[i].topics[0] == keccak256("LogMessagePublished(address,uint64,uint32,bytes,uint8)")) { count += 1; } } @@ -164,12 +136,7 @@ contract WormholeSimulator { uint256 publishedIndex = 0; for (uint256 i = 0; i < logs.length; i++) { - if ( - logs[i].topics[0] == - keccak256( - "LogMessagePublished(address,uint64,uint32,bytes,uint8)" - ) - ) { + if (logs[i].topics[0] == keccak256("LogMessagePublished(address,uint64,uint32,bytes,uint8)")) { published[publishedIndex] = logs[i]; publishedIndex += 1; } @@ -183,9 +150,7 @@ contract WormholeSimulator { * @param vm_ Wormhole VM struct * @return encodedObservation Wormhole message body encoded into bytes */ - function encodeObservation( - IWormhole.VM memory vm_ - ) public pure returns (bytes memory encodedObservation) { + function encodeObservation(IWormhole.VM memory vm_) public pure returns (bytes memory encodedObservation) { encodedObservation = abi.encodePacked( vm_.timestamp, vm_.nonce, @@ -202,10 +167,11 @@ contract WormholeSimulator { * @param log The forge Vm.log captured when recording events during test execution * @return signedMessage Formatted and signed Wormhole message */ - function fetchSignedMessageFromLogs( - Vm.Log memory log, - uint16 emitterChainId - ) public view returns (bytes memory signedMessage) { + function fetchSignedMessageFromLogs(Vm.Log memory log, uint16 emitterChainId) + public + view + returns (bytes memory signedMessage) + { // Create message instance IWormhole.VM memory vm_; @@ -225,9 +191,7 @@ contract WormholeSimulator { * @param vm_ The preformatted Wormhole message * @return signedMessage Formatted and signed Wormhole message */ - function encodeAndSignMessage( - IWormhole.VM memory vm_ - ) public view returns (bytes memory signedMessage) { + function encodeAndSignMessage(IWormhole.VM memory vm_) public view returns (bytes memory signedMessage) { // Compute the hash of the body bytes memory body = encodeObservation(vm_); vm_.hash = doubleKeccak256(body); @@ -255,12 +219,7 @@ contract WormholeSimulator { */ function setMessageFee(uint256 newFee) public { bytes32 coreModule = 0x00000000000000000000000000000000000000000000000000000000436f7265; - bytes memory message = abi.encodePacked( - coreModule, - uint8(3), - uint16(wormhole.chainId()), - newFee - ); + bytes memory message = abi.encodePacked(coreModule, uint8(3), uint16(wormhole.chainId()), newFee); IWormhole.VM memory preSignedMessage = IWormhole.VM({ version: 1, timestamp: uint32(block.timestamp), diff --git a/test/CCTPBase.t.sol b/test/CCTPBase.t.sol index 9d66d94..5387edc 100644 --- a/test/CCTPBase.t.sol +++ b/test/CCTPBase.t.sol @@ -1,4 +1,3 @@ - pragma solidity ^0.8.13; import "../src/WormholeRelayerSDK.sol"; @@ -21,38 +20,16 @@ contract CCTPToy is CCTPSender, CCTPReceiver { address _circleMessageTransmitter, address _circleTokenMessenger, address _USDC - ) - CCTPBase( - _wormholeRelayer, - _tokenBridge, - _wormhole, - _circleMessageTransmitter, - _circleTokenMessenger, - _USDC - ) - {} - - function quoteCrossChainDeposit( - uint16 targetChain - ) public view returns (uint256 cost) { + ) CCTPBase(_wormholeRelayer, _tokenBridge, _wormhole, _circleMessageTransmitter, _circleTokenMessenger, _USDC) {} + + function quoteCrossChainDeposit(uint16 targetChain) public view returns (uint256 cost) { // Cost of delivering token and payload to targetChain - (cost, ) = wormholeRelayer.quoteEVMDeliveryPrice( - targetChain, - 0, - GAS_LIMIT - ); + (cost,) = wormholeRelayer.quoteEVMDeliveryPrice(targetChain, 0, GAS_LIMIT); } - function sendCrossChainDeposit( - uint16 targetChain, - address recipient, - uint256 amount - ) public payable { + function sendCrossChainDeposit(uint16 targetChain, address recipient, uint256 amount) public payable { uint256 cost = quoteCrossChainDeposit(targetChain); - require( - msg.value == cost, - "msg.value must be quoteCrossChainDeposit(targetChain)" - ); + require(msg.value == cost, "msg.value must be quoteCrossChainDeposit(targetChain)"); IERC20(USDC).transferFrom(msg.sender, address(this), amount); @@ -73,16 +50,8 @@ contract CCTPToy is CCTPSender, CCTPReceiver { bytes32 sourceAddress, uint16 sourceChain, bytes32 // deliveryHash - ) - internal - override - onlyWormholeRelayer - isRegisteredSender(sourceChain, sourceAddress) - { - (address recipient, uint256 expectedAmount) = abi.decode( - payload, - (address, uint256) - ); + ) internal override onlyWormholeRelayer isRegisteredSender(sourceChain, sourceAddress) { + (address recipient, uint256 expectedAmount) = abi.decode(payload, (address, uint256)); require(amount == expectedAmount, "amount != payload.expectedAmount"); IERC20(USDC).transfer(recipient, amount); } @@ -124,7 +93,7 @@ contract WormholeSDKTest is WormholeRelayerBasicTest { ); } - function setUpGeneral() public override { + function setUpGeneral() public override { vm.selectFork(sourceFork); CCTPToySource.setRegisteredSender(targetChain, toWormholeFormat(address(CCTPToyTarget))); @@ -132,8 +101,6 @@ contract WormholeSDKTest is WormholeRelayerBasicTest { CCTPToyTarget.setRegisteredSender(sourceChain, toWormholeFormat(address(CCTPToySource))); } - - // function setUpGeneral() public override { // vm.selectFork(sourceFork); @@ -153,11 +120,7 @@ contract WormholeSDKTest is WormholeRelayerBasicTest { uint256 cost = CCTPToySource.quoteCrossChainDeposit(targetChain); vm.recordLogs(); - CCTPToySource.sendCrossChainDeposit{value: cost}( - targetChain, - recipient, - amount - ); + CCTPToySource.sendCrossChainDeposit{value: cost}(targetChain, recipient, amount); performDelivery(true); vm.selectFork(targetFork); diff --git a/test/ChooseChains.t.sol b/test/ChooseChains.t.sol index 6ea50c3..be2292b 100644 --- a/test/ChooseChains.t.sol +++ b/test/ChooseChains.t.sol @@ -1,4 +1,3 @@ - pragma solidity ^0.8.13; import "../src/WormholeRelayerSDK.sol"; diff --git a/test/ExtraChains.t.sol b/test/ExtraChains.t.sol index e38066a..bc41652 100644 --- a/test/ExtraChains.t.sol +++ b/test/ExtraChains.t.sol @@ -1,4 +1,3 @@ - pragma solidity ^0.8.13; import "../src/WormholeRelayerSDK.sol"; diff --git a/test/Fork.t.sol b/test/Fork.t.sol index e0923c4..1ee5e5d 100644 --- a/test/Fork.t.sol +++ b/test/Fork.t.sol @@ -1,4 +1,3 @@ - pragma solidity ^0.8.13; import "../src/WormholeRelayerSDK.sol"; @@ -36,10 +35,12 @@ contract Toy is Base { } contract TokenToy is TokenSender, TokenReceiver { - constructor (address _wormholeRelayer, address _bridge, address _wormhole) TokenBase(_wormholeRelayer, _bridge, _wormhole) {} - + constructor(address _wormholeRelayer, address _bridge, address _wormhole) + TokenBase(_wormholeRelayer, _bridge, _wormhole) + {} + uint256 constant GAS_LIMIT = 250_000; - + function quoteCrossChainDeposit(uint16 targetChain) public view returns (uint256 cost) { // Cost of delivering token and payload to targetChain uint256 deliveryCost; @@ -48,13 +49,11 @@ contract TokenToy is TokenSender, TokenReceiver { // Total cost: delivery cost + cost of publishing the 'sending token' wormhole message cost = deliveryCost + wormhole.messageFee(); } - - function sendCrossChainDeposit( - uint16 targetChain, - address recipient, - uint256 amount, - address token - ) public payable { + + function sendCrossChainDeposit(uint16 targetChain, address recipient, uint256 amount, address token) + public + payable + { uint256 cost = quoteCrossChainDeposit(targetChain); require(msg.value == cost, "msg.value must be quoteCrossChainDeposit(targetChain)"); @@ -62,11 +61,11 @@ contract TokenToy is TokenSender, TokenReceiver { bytes memory payload = abi.encode(recipient); sendTokenWithPayloadToEvm( - targetChain, + targetChain, fromWormholeFormat(registeredSenders[targetChain]), // address (on targetChain) to send token and payload to - payload, + payload, 0, // receiver value - GAS_LIMIT, + GAS_LIMIT, token, // address of IERC20 token contract amount ); @@ -87,11 +86,11 @@ contract TokenToy is TokenSender, TokenReceiver { bytes memory payload = abi.encode(recipient); sendTokenWithPayloadToEvm( - targetChain, + targetChain, fromWormholeFormat(registeredSenders[targetChain]), // address (on targetChain) to send token and payload to - payload, + payload, 0, // receiver value - GAS_LIMIT, + GAS_LIMIT, token, // address of IERC20 token contract amount, refundChain, @@ -144,7 +143,6 @@ contract WormholeSDKTest is WormholeRelayerBasicTest { } function testSendMessage() public { - vm.recordLogs(); (uint256 cost,) = relayerSource.quoteEVMDeliveryPrice(targetChain, 1e17, 100_000); relayerSource.sendPayloadToEvm{value: cost}(targetChain, address(toyTarget), abi.encode(55), 1e17, 100_000); @@ -167,7 +165,6 @@ contract WormholeSDKTest is WormholeRelayerBasicTest { } function testSendToken() public { - vm.selectFork(sourceFork); uint256 amount = 19e17; @@ -180,9 +177,7 @@ contract WormholeSDKTest is WormholeRelayerBasicTest { uint256 cost = tokenToySource.quoteCrossChainDeposit(targetChain); vm.recordLogs(); - tokenToySource.sendCrossChainDeposit{value: cost}( - targetChain, recipient, amount, address(token) - ); + tokenToySource.sendCrossChainDeposit{value: cost}(targetChain, recipient, amount, address(token)); performDelivery(); vm.selectFork(targetFork); @@ -191,7 +186,6 @@ contract WormholeSDKTest is WormholeRelayerBasicTest { } function testSendTokenWithRefund() public { - vm.selectFork(sourceFork); uint256 amount = 19e17;