-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding mocks to verify that the sdk is actually importable
- Loading branch information
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters