diff --git a/scripts/mocks/HelloWormhole.sol b/scripts/mocks/HelloWormhole.sol new file mode 100644 index 0000000..9374a74 --- /dev/null +++ b/scripts/mocks/HelloWormhole.sol @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import {IWormholeRelayer} from "../interfaces/IWormholeRelayer.sol"; +import {IWormholeReceiver} from "../interfaces/IWormholeReceiver.sol"; + +contract HelloWormhole is IWormholeReceiver { + event GreetingReceived(string greeting, uint16 senderChain, address sender); + + uint256 constant GAS_LIMIT = 50_000; + + IWormholeRelayer public immutable wormholeRelayer; + + string public latestGreeting; + + constructor(address _wormholeRelayer) { + wormholeRelayer = IWormholeRelayer(_wormholeRelayer); + } + + function quoteCrossChainGreeting( + uint16 targetChain + ) public view returns (uint256 cost) { + (cost, ) = wormholeRelayer.quoteEVMDeliveryPrice( + targetChain, + 0, + GAS_LIMIT + ); + } + + function sendCrossChainGreeting( + uint16 targetChain, + address targetAddress, + string memory greeting + ) public payable { + uint256 cost = quoteCrossChainGreeting(targetChain); + require(msg.value == cost); + wormholeRelayer.sendPayloadToEvm{value: cost}( + targetChain, + targetAddress, + abi.encode(greeting, msg.sender), // payload + 0, // no receiver value needed since we're just passing a message + GAS_LIMIT + ); + } + + function receiveWormholeMessages( + bytes memory payload, + bytes[] memory, // additionalVaas + bytes32, // address that called 'sendPayloadToEvm' (HelloWormhole contract address) + uint16 sourceChain, + bytes32 // unique identifier of delivery + ) public payable override { + require(msg.sender == address(wormholeRelayer), "Only relayer allowed"); + + // Parse the payload and do the corresponding actions! + (string memory greeting, address sender) = abi.decode( + payload, + (string, address) + ); + latestGreeting = greeting; + emit GreetingReceived(latestGreeting, sourceChain, sender); + } +} diff --git a/scripts/publish.sh b/scripts/publish.sh index c0951dc..a1c5530 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -23,9 +23,10 @@ if [[ -d "contracts" ]]; then rm -rf contracts fi -mkdir contracts +mkdir -p contracts cp -r src/* contracts/. +cp -r scripts/mocks contracts/. rm -rf contracts/testing node scripts/clean-remapping.js @@ -40,6 +41,8 @@ npx hardhat compile if [ $? -ne 0 ]; then echo "Compilation failed. Exiting." exit 1 +elif + rm -rf contracts/mocks fi # Continue with the rest of your script