2022-09-30 09:18:49 -07:00
|
|
|
// contracts/mock/MockBatchedVAASender.sol
|
|
|
|
// SPDX-License-Identifier: Apache 2
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
import "../libraries/external/BytesLib.sol";
|
|
|
|
import "../interfaces/IWormhole.sol";
|
2023-02-10 12:33:00 -08:00
|
|
|
import "../interfaces/IWormholeRelayer.sol";
|
Move development branch to main (#23)
* refactoring for multidelivery
* partial ts-test fixes
* use typechain in integration tests, update prettier, fix remaining integration tests
* run formatter on solidity files
* gas refunding
* gas forwarding logic
* msg.send -> refundAmount
* minor test refactor & additions
* created relayer engine directory
* more testing & tilt environment config for relayer engine
* starting work on the xMint example contracts
* additions for relayer engine
* minor modifications & todos
* fixed some errors
* refactoring + cleaned up some TODOs
* updated ICoreRelayer interface
* adjusted tests for new interface
* Working testSend
* Merged refactoring + cleaned up some TODOs
* updated ICoreRelayer interface
* adjusted tests for new interface
* Working testSend with new interface'
* refactoring interfaces & files for single VAA design
* GasOracle implementation of new interface
* GasOracle compiles
* Gas oracle upgradable
* Fix compile errors in GasOracleGovernance
* minor core relayer cleanup
* Changes to getters, setters, state
* implement quoteEvmDeliveryPrice, quoteTargetEvmGas, assetConversionAmount for corerelayer
* Correcting interface inconsistencies between CoreRelayerStructs and ICoreRelayer
* Fix encodeDeliveryRequestsContainer
* added single vaa delivery entrypoint logic
* Encode and Decode delivery instructions
* Fixed many compile errors
* First attempt at removing stacktoodeep error
* Commenting out chunks of code to identify stack too deep error
* Continue stack too deep quest
* Revert "Commenting out chunks of code to identify stack too deep error"
This reverts commit 8cd55d26cea2c49dc6e6bfa481c310f1a1c1143a.
* Revert "Continue stack too deep quest"
This reverts commit f0cde6871e26a7063e20d9a83b63b6a50e32bf37.
* Fix stack too deep error in CoreRelayerMessages
* tests compile, run, pass
* fixing up fee collection assertions
* GasOracle tests altering
* Rename encodeDeliveryIntructions to convertToEncodedDeliveryInstructions because we are going from delivery request to delivery instruction
* adding evm events to delivery execution
* forwarding refactor for single vaa
* relay provider name refactor
* Test file slight refactor to allow for multiple chains
* first impl of hub and spoke example
* Forward test progress
* Forwarding test passes!
* More general parameters for test
* Testing file more modular, calls 'generic relayer'
* redelivery implementation
* removing todos
* Tests can use arbitrary amount of chains
* Address various TODOs
* refactored RelayProvider to be upgradeable via proxy
* Add overhead inteface to RelayProvider & adjusted necessary fee calculations
* added TODOs related to rewardAddress payout
* provider price quoting changes
* provider payments made at source
* Fixed all compile errors
* testForward and testSend pass again!
* Switched quoteAssetConversion to quoteApplicationBudgetFee in CoreRelayer interface
* First round of changes to support individual vaas in offchain relayer
- Use new custom plugin event source api in relayer engine
- Supports mulit delivery
- Config for celo and fuji
* contracts deploy successfully to tilt
* bug fixes, contracts deploy to tilt
* Starting the redelivery test
* Tests pass again, with exception of the RelayProvider tests that tested reverts, and the new testRedelivery which isn't finished
* small plugin changes
* MockRelayerIntegration is used for sending
* prepare offchain relayer to run in both tilt and testnet
* update readme and npm scripts for offchain relayer
* nit: remove console.log(argv)
* solc version bump
* Tests changed to pass (commented out the tests with differing require statements and kept redelivery incomplete
* chain registration typescript scripts
* Redeliver works!
* Redelivery test works!
* testnet deploy + relayer engine test
* Testing two sends
* Friday changes to round trip on testnet
* Shortening current tests
* Funds are correct! Relayer gets paid!
* Remove extraneous comments
* ts scripts for deployment and config
* Wormhole Fee Test
Co-authored-by: chase-45 <chasemoran45@gmail.com>
Co-authored-by: derpy-duck <115193320+derpy-duck@users.noreply.github.com>
2023-01-05 14:26:27 -08:00
|
|
|
import "../interfaces/IWormholeReceiver.sol";
|
2022-09-30 09:18:49 -07:00
|
|
|
|
Move development branch to main (#23)
* refactoring for multidelivery
* partial ts-test fixes
* use typechain in integration tests, update prettier, fix remaining integration tests
* run formatter on solidity files
* gas refunding
* gas forwarding logic
* msg.send -> refundAmount
* minor test refactor & additions
* created relayer engine directory
* more testing & tilt environment config for relayer engine
* starting work on the xMint example contracts
* additions for relayer engine
* minor modifications & todos
* fixed some errors
* refactoring + cleaned up some TODOs
* updated ICoreRelayer interface
* adjusted tests for new interface
* Working testSend
* Merged refactoring + cleaned up some TODOs
* updated ICoreRelayer interface
* adjusted tests for new interface
* Working testSend with new interface'
* refactoring interfaces & files for single VAA design
* GasOracle implementation of new interface
* GasOracle compiles
* Gas oracle upgradable
* Fix compile errors in GasOracleGovernance
* minor core relayer cleanup
* Changes to getters, setters, state
* implement quoteEvmDeliveryPrice, quoteTargetEvmGas, assetConversionAmount for corerelayer
* Correcting interface inconsistencies between CoreRelayerStructs and ICoreRelayer
* Fix encodeDeliveryRequestsContainer
* added single vaa delivery entrypoint logic
* Encode and Decode delivery instructions
* Fixed many compile errors
* First attempt at removing stacktoodeep error
* Commenting out chunks of code to identify stack too deep error
* Continue stack too deep quest
* Revert "Commenting out chunks of code to identify stack too deep error"
This reverts commit 8cd55d26cea2c49dc6e6bfa481c310f1a1c1143a.
* Revert "Continue stack too deep quest"
This reverts commit f0cde6871e26a7063e20d9a83b63b6a50e32bf37.
* Fix stack too deep error in CoreRelayerMessages
* tests compile, run, pass
* fixing up fee collection assertions
* GasOracle tests altering
* Rename encodeDeliveryIntructions to convertToEncodedDeliveryInstructions because we are going from delivery request to delivery instruction
* adding evm events to delivery execution
* forwarding refactor for single vaa
* relay provider name refactor
* Test file slight refactor to allow for multiple chains
* first impl of hub and spoke example
* Forward test progress
* Forwarding test passes!
* More general parameters for test
* Testing file more modular, calls 'generic relayer'
* redelivery implementation
* removing todos
* Tests can use arbitrary amount of chains
* Address various TODOs
* refactored RelayProvider to be upgradeable via proxy
* Add overhead inteface to RelayProvider & adjusted necessary fee calculations
* added TODOs related to rewardAddress payout
* provider price quoting changes
* provider payments made at source
* Fixed all compile errors
* testForward and testSend pass again!
* Switched quoteAssetConversion to quoteApplicationBudgetFee in CoreRelayer interface
* First round of changes to support individual vaas in offchain relayer
- Use new custom plugin event source api in relayer engine
- Supports mulit delivery
- Config for celo and fuji
* contracts deploy successfully to tilt
* bug fixes, contracts deploy to tilt
* Starting the redelivery test
* Tests pass again, with exception of the RelayProvider tests that tested reverts, and the new testRedelivery which isn't finished
* small plugin changes
* MockRelayerIntegration is used for sending
* prepare offchain relayer to run in both tilt and testnet
* update readme and npm scripts for offchain relayer
* nit: remove console.log(argv)
* solc version bump
* Tests changed to pass (commented out the tests with differing require statements and kept redelivery incomplete
* chain registration typescript scripts
* Redeliver works!
* Redelivery test works!
* testnet deploy + relayer engine test
* Testing two sends
* Friday changes to round trip on testnet
* Shortening current tests
* Funds are correct! Relayer gets paid!
* Remove extraneous comments
* ts scripts for deployment and config
* Wormhole Fee Test
Co-authored-by: chase-45 <chasemoran45@gmail.com>
Co-authored-by: derpy-duck <115193320+derpy-duck@users.noreply.github.com>
2023-01-05 14:26:27 -08:00
|
|
|
import "forge-std/console.sol";
|
|
|
|
|
2023-03-14 10:45:03 -07:00
|
|
|
interface Structs {
|
|
|
|
struct XAddress {
|
|
|
|
uint16 chainId;
|
|
|
|
bytes32 addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Move development branch to main (#23)
* refactoring for multidelivery
* partial ts-test fixes
* use typechain in integration tests, update prettier, fix remaining integration tests
* run formatter on solidity files
* gas refunding
* gas forwarding logic
* msg.send -> refundAmount
* minor test refactor & additions
* created relayer engine directory
* more testing & tilt environment config for relayer engine
* starting work on the xMint example contracts
* additions for relayer engine
* minor modifications & todos
* fixed some errors
* refactoring + cleaned up some TODOs
* updated ICoreRelayer interface
* adjusted tests for new interface
* Working testSend
* Merged refactoring + cleaned up some TODOs
* updated ICoreRelayer interface
* adjusted tests for new interface
* Working testSend with new interface'
* refactoring interfaces & files for single VAA design
* GasOracle implementation of new interface
* GasOracle compiles
* Gas oracle upgradable
* Fix compile errors in GasOracleGovernance
* minor core relayer cleanup
* Changes to getters, setters, state
* implement quoteEvmDeliveryPrice, quoteTargetEvmGas, assetConversionAmount for corerelayer
* Correcting interface inconsistencies between CoreRelayerStructs and ICoreRelayer
* Fix encodeDeliveryRequestsContainer
* added single vaa delivery entrypoint logic
* Encode and Decode delivery instructions
* Fixed many compile errors
* First attempt at removing stacktoodeep error
* Commenting out chunks of code to identify stack too deep error
* Continue stack too deep quest
* Revert "Commenting out chunks of code to identify stack too deep error"
This reverts commit 8cd55d26cea2c49dc6e6bfa481c310f1a1c1143a.
* Revert "Continue stack too deep quest"
This reverts commit f0cde6871e26a7063e20d9a83b63b6a50e32bf37.
* Fix stack too deep error in CoreRelayerMessages
* tests compile, run, pass
* fixing up fee collection assertions
* GasOracle tests altering
* Rename encodeDeliveryIntructions to convertToEncodedDeliveryInstructions because we are going from delivery request to delivery instruction
* adding evm events to delivery execution
* forwarding refactor for single vaa
* relay provider name refactor
* Test file slight refactor to allow for multiple chains
* first impl of hub and spoke example
* Forward test progress
* Forwarding test passes!
* More general parameters for test
* Testing file more modular, calls 'generic relayer'
* redelivery implementation
* removing todos
* Tests can use arbitrary amount of chains
* Address various TODOs
* refactored RelayProvider to be upgradeable via proxy
* Add overhead inteface to RelayProvider & adjusted necessary fee calculations
* added TODOs related to rewardAddress payout
* provider price quoting changes
* provider payments made at source
* Fixed all compile errors
* testForward and testSend pass again!
* Switched quoteAssetConversion to quoteApplicationBudgetFee in CoreRelayer interface
* First round of changes to support individual vaas in offchain relayer
- Use new custom plugin event source api in relayer engine
- Supports mulit delivery
- Config for celo and fuji
* contracts deploy successfully to tilt
* bug fixes, contracts deploy to tilt
* Starting the redelivery test
* Tests pass again, with exception of the RelayProvider tests that tested reverts, and the new testRedelivery which isn't finished
* small plugin changes
* MockRelayerIntegration is used for sending
* prepare offchain relayer to run in both tilt and testnet
* update readme and npm scripts for offchain relayer
* nit: remove console.log(argv)
* solc version bump
* Tests changed to pass (commented out the tests with differing require statements and kept redelivery incomplete
* chain registration typescript scripts
* Redeliver works!
* Redelivery test works!
* testnet deploy + relayer engine test
* Testing two sends
* Friday changes to round trip on testnet
* Shortening current tests
* Funds are correct! Relayer gets paid!
* Remove extraneous comments
* ts scripts for deployment and config
* Wormhole Fee Test
Co-authored-by: chase-45 <chasemoran45@gmail.com>
Co-authored-by: derpy-duck <115193320+derpy-duck@users.noreply.github.com>
2023-01-05 14:26:27 -08:00
|
|
|
contract MockRelayerIntegration is IWormholeReceiver {
|
2022-09-30 09:18:49 -07:00
|
|
|
using BytesLib for bytes;
|
|
|
|
|
|
|
|
// wormhole instance on this chain
|
|
|
|
IWormhole immutable wormhole;
|
|
|
|
|
|
|
|
// trusted relayer contract on this chain
|
2023-02-10 12:33:00 -08:00
|
|
|
IWormholeRelayer immutable relayer;
|
2022-09-30 09:18:49 -07:00
|
|
|
|
|
|
|
// deployer of this contract
|
|
|
|
address immutable owner;
|
|
|
|
|
|
|
|
// map that stores payloads from received VAAs
|
|
|
|
mapping(bytes32 => bytes) verifiedPayloads;
|
|
|
|
|
2023-02-10 15:32:44 -08:00
|
|
|
// mapping of other MockRelayerIntegration contracts
|
|
|
|
mapping(uint16 => bytes32) registeredContracts;
|
|
|
|
|
2023-03-14 10:45:03 -07:00
|
|
|
// bytes[] messages;
|
|
|
|
bytes[][] messageHistory;
|
Move development branch to main (#23)
* refactoring for multidelivery
* partial ts-test fixes
* use typechain in integration tests, update prettier, fix remaining integration tests
* run formatter on solidity files
* gas refunding
* gas forwarding logic
* msg.send -> refundAmount
* minor test refactor & additions
* created relayer engine directory
* more testing & tilt environment config for relayer engine
* starting work on the xMint example contracts
* additions for relayer engine
* minor modifications & todos
* fixed some errors
* refactoring + cleaned up some TODOs
* updated ICoreRelayer interface
* adjusted tests for new interface
* Working testSend
* Merged refactoring + cleaned up some TODOs
* updated ICoreRelayer interface
* adjusted tests for new interface
* Working testSend with new interface'
* refactoring interfaces & files for single VAA design
* GasOracle implementation of new interface
* GasOracle compiles
* Gas oracle upgradable
* Fix compile errors in GasOracleGovernance
* minor core relayer cleanup
* Changes to getters, setters, state
* implement quoteEvmDeliveryPrice, quoteTargetEvmGas, assetConversionAmount for corerelayer
* Correcting interface inconsistencies between CoreRelayerStructs and ICoreRelayer
* Fix encodeDeliveryRequestsContainer
* added single vaa delivery entrypoint logic
* Encode and Decode delivery instructions
* Fixed many compile errors
* First attempt at removing stacktoodeep error
* Commenting out chunks of code to identify stack too deep error
* Continue stack too deep quest
* Revert "Commenting out chunks of code to identify stack too deep error"
This reverts commit 8cd55d26cea2c49dc6e6bfa481c310f1a1c1143a.
* Revert "Continue stack too deep quest"
This reverts commit f0cde6871e26a7063e20d9a83b63b6a50e32bf37.
* Fix stack too deep error in CoreRelayerMessages
* tests compile, run, pass
* fixing up fee collection assertions
* GasOracle tests altering
* Rename encodeDeliveryIntructions to convertToEncodedDeliveryInstructions because we are going from delivery request to delivery instruction
* adding evm events to delivery execution
* forwarding refactor for single vaa
* relay provider name refactor
* Test file slight refactor to allow for multiple chains
* first impl of hub and spoke example
* Forward test progress
* Forwarding test passes!
* More general parameters for test
* Testing file more modular, calls 'generic relayer'
* redelivery implementation
* removing todos
* Tests can use arbitrary amount of chains
* Address various TODOs
* refactored RelayProvider to be upgradeable via proxy
* Add overhead inteface to RelayProvider & adjusted necessary fee calculations
* added TODOs related to rewardAddress payout
* provider price quoting changes
* provider payments made at source
* Fixed all compile errors
* testForward and testSend pass again!
* Switched quoteAssetConversion to quoteApplicationBudgetFee in CoreRelayer interface
* First round of changes to support individual vaas in offchain relayer
- Use new custom plugin event source api in relayer engine
- Supports mulit delivery
- Config for celo and fuji
* contracts deploy successfully to tilt
* bug fixes, contracts deploy to tilt
* Starting the redelivery test
* Tests pass again, with exception of the RelayProvider tests that tested reverts, and the new testRedelivery which isn't finished
* small plugin changes
* MockRelayerIntegration is used for sending
* prepare offchain relayer to run in both tilt and testnet
* update readme and npm scripts for offchain relayer
* nit: remove console.log(argv)
* solc version bump
* Tests changed to pass (commented out the tests with differing require statements and kept redelivery incomplete
* chain registration typescript scripts
* Redeliver works!
* Redelivery test works!
* testnet deploy + relayer engine test
* Testing two sends
* Friday changes to round trip on testnet
* Shortening current tests
* Funds are correct! Relayer gets paid!
* Remove extraneous comments
* ts scripts for deployment and config
* Wormhole Fee Test
Co-authored-by: chase-45 <chasemoran45@gmail.com>
Co-authored-by: derpy-duck <115193320+derpy-duck@users.noreply.github.com>
2023-01-05 14:26:27 -08:00
|
|
|
|
2023-02-10 10:53:49 -08:00
|
|
|
struct FurtherInstructions {
|
|
|
|
bool keepSending;
|
2023-02-10 15:32:44 -08:00
|
|
|
bytes[] newMessages;
|
2023-02-10 10:53:49 -08:00
|
|
|
uint16[] chains;
|
|
|
|
uint32[] gasLimits;
|
|
|
|
}
|
|
|
|
|
2022-09-30 09:18:49 -07:00
|
|
|
constructor(address _wormholeCore, address _coreRelayer) {
|
|
|
|
wormhole = IWormhole(_wormholeCore);
|
2023-02-10 12:33:00 -08:00
|
|
|
relayer = IWormholeRelayer(_coreRelayer);
|
2022-09-30 09:18:49 -07:00
|
|
|
owner = msg.sender;
|
|
|
|
}
|
|
|
|
|
2023-02-10 15:32:44 -08:00
|
|
|
function sendMessage(bytes memory _message, uint16 targetChainId, address destination) public payable {
|
2023-02-13 07:26:27 -08:00
|
|
|
sendMessageGeneral(_message, targetChainId, destination, destination, 0, 1);
|
2023-02-10 15:32:44 -08:00
|
|
|
}
|
|
|
|
|
2023-02-13 07:29:45 -08:00
|
|
|
function sendMessageWithRefundAddress(
|
|
|
|
bytes memory _message,
|
|
|
|
uint16 targetChainId,
|
|
|
|
address destination,
|
|
|
|
address refundAddress
|
|
|
|
) public payable {
|
2023-02-10 15:32:44 -08:00
|
|
|
sendMessageGeneral(_message, targetChainId, destination, refundAddress, 0, 1);
|
2022-09-30 09:18:49 -07:00
|
|
|
}
|
|
|
|
|
2023-01-05 16:46:58 -08:00
|
|
|
function sendMessageWithForwardedResponse(
|
|
|
|
bytes memory _message,
|
|
|
|
uint16 targetChainId,
|
|
|
|
address destination,
|
|
|
|
address refundAddress
|
2023-02-10 12:33:00 -08:00
|
|
|
) public payable {
|
2023-02-10 15:32:44 -08:00
|
|
|
uint16[] memory chains = new uint16[](1);
|
|
|
|
chains[0] = wormhole.chainId();
|
|
|
|
uint32[] memory gasLimits = new uint32[](1);
|
|
|
|
gasLimits[0] = 1000000;
|
2023-02-10 22:26:06 -08:00
|
|
|
bytes[] memory newMessages = new bytes[](2);
|
2023-02-10 15:32:44 -08:00
|
|
|
newMessages[0] = bytes("received!");
|
2023-02-10 22:26:06 -08:00
|
|
|
newMessages[1] = abi.encodePacked(uint8(0));
|
|
|
|
FurtherInstructions memory instructions =
|
|
|
|
FurtherInstructions({keepSending: true, newMessages: newMessages, chains: chains, gasLimits: gasLimits});
|
2023-02-10 15:32:44 -08:00
|
|
|
wormhole.publishMessage{value: wormhole.messageFee()}(1, _message, 200);
|
|
|
|
wormhole.publishMessage{value: wormhole.messageFee()}(1, encodeFurtherInstructions(instructions), 200);
|
|
|
|
executeSend(targetChainId, destination, refundAddress, 0, 1);
|
2022-09-30 09:18:49 -07:00
|
|
|
}
|
|
|
|
|
2023-01-05 16:46:58 -08:00
|
|
|
function sendMessageGeneral(
|
|
|
|
bytes memory fullMessage,
|
|
|
|
uint16 targetChainId,
|
|
|
|
address destination,
|
|
|
|
address refundAddress,
|
2023-02-10 12:33:00 -08:00
|
|
|
uint256 receiverValue,
|
2023-01-05 16:46:58 -08:00
|
|
|
uint32 nonce
|
2023-02-10 12:33:00 -08:00
|
|
|
) public payable {
|
2023-02-10 15:32:44 -08:00
|
|
|
wormhole.publishMessage{value: wormhole.messageFee()}(nonce, fullMessage, 200);
|
2023-02-10 22:26:06 -08:00
|
|
|
wormhole.publishMessage{value: wormhole.messageFee()}(nonce, abi.encodePacked(uint8(0)), 200);
|
2023-02-10 15:32:44 -08:00
|
|
|
executeSend(targetChainId, destination, refundAddress, receiverValue, nonce);
|
2023-01-05 16:21:30 -08:00
|
|
|
}
|
|
|
|
|
2023-02-13 10:23:25 -08:00
|
|
|
function sendMessagesWithFurtherInstructions(
|
|
|
|
bytes[] memory messages,
|
|
|
|
FurtherInstructions memory furtherInstructions,
|
2023-02-13 12:02:53 -08:00
|
|
|
uint16[] memory chains,
|
|
|
|
uint256[] memory computeBudgets
|
2023-02-13 10:23:25 -08:00
|
|
|
) public payable {
|
2023-02-13 16:43:12 -08:00
|
|
|
for (uint16 i = 0; i < messages.length; i++) {
|
2023-02-13 12:02:53 -08:00
|
|
|
wormhole.publishMessage{value: wormhole.messageFee()}(1, messages[i], 200);
|
|
|
|
}
|
|
|
|
wormhole.publishMessage{value: wormhole.messageFee()}(1, encodeFurtherInstructions(furtherInstructions), 200);
|
2023-02-13 16:43:12 -08:00
|
|
|
IWormholeRelayer.Send[] memory requests = new IWormholeRelayer.Send[](chains.length);
|
|
|
|
for (uint16 i = 0; i < chains.length; i++) {
|
|
|
|
requests[i] = IWormholeRelayer.Send({
|
2023-02-13 12:02:53 -08:00
|
|
|
targetChain: chains[i],
|
|
|
|
targetAddress: registeredContracts[chains[i]],
|
|
|
|
refundAddress: registeredContracts[chains[i]],
|
2023-02-13 16:43:12 -08:00
|
|
|
maxTransactionFee: computeBudgets[i],
|
|
|
|
receiverValue: 0,
|
2023-02-13 12:02:53 -08:00
|
|
|
relayParameters: relayer.getDefaultRelayParams()
|
2023-02-13 16:43:12 -08:00
|
|
|
});
|
2023-02-13 10:23:25 -08:00
|
|
|
}
|
2023-02-13 16:43:12 -08:00
|
|
|
IWormholeRelayer.MultichainSend memory container = IWormholeRelayer.MultichainSend({
|
2023-02-13 12:02:53 -08:00
|
|
|
requests: requests,
|
2023-02-13 16:43:12 -08:00
|
|
|
relayProviderAddress: relayer.getDefaultRelayProvider()
|
2023-02-13 12:02:53 -08:00
|
|
|
});
|
2023-02-13 16:43:12 -08:00
|
|
|
relayer.multichainSend{value: (msg.value - wormhole.messageFee() * (1 + messages.length))}(container, 1);
|
2023-02-13 10:23:25 -08:00
|
|
|
}
|
|
|
|
|
2023-01-05 16:46:58 -08:00
|
|
|
function executeSend(
|
|
|
|
uint16 targetChainId,
|
|
|
|
address destination,
|
|
|
|
address refundAddress,
|
2023-02-10 12:33:00 -08:00
|
|
|
uint256 receiverValue,
|
2023-01-05 16:46:58 -08:00
|
|
|
uint32 nonce
|
2023-02-10 12:33:00 -08:00
|
|
|
) internal {
|
|
|
|
IWormholeRelayer.Send memory request = IWormholeRelayer.Send({
|
2023-01-13 12:27:59 -08:00
|
|
|
targetChain: targetChainId,
|
|
|
|
targetAddress: relayer.toWormholeFormat(address(destination)),
|
|
|
|
refundAddress: relayer.toWormholeFormat(address(refundAddress)), // This will be ignored on the target chain if the intent is to perform a forward
|
2023-02-13 16:43:12 -08:00
|
|
|
maxTransactionFee: msg.value - 3 * wormhole.messageFee() - receiverValue,
|
2023-02-10 22:26:06 -08:00
|
|
|
receiverValue: receiverValue,
|
|
|
|
relayParameters: relayer.getDefaultRelayParams()
|
2023-01-13 12:27:59 -08:00
|
|
|
});
|
2022-09-30 09:18:49 -07:00
|
|
|
|
2023-02-13 16:43:12 -08:00
|
|
|
relayer.send{value: msg.value - 2 * wormhole.messageFee()}(request, nonce, relayer.getDefaultRelayProvider());
|
2022-09-30 09:18:49 -07:00
|
|
|
}
|
|
|
|
|
Move development branch to main (#23)
* refactoring for multidelivery
* partial ts-test fixes
* use typechain in integration tests, update prettier, fix remaining integration tests
* run formatter on solidity files
* gas refunding
* gas forwarding logic
* msg.send -> refundAmount
* minor test refactor & additions
* created relayer engine directory
* more testing & tilt environment config for relayer engine
* starting work on the xMint example contracts
* additions for relayer engine
* minor modifications & todos
* fixed some errors
* refactoring + cleaned up some TODOs
* updated ICoreRelayer interface
* adjusted tests for new interface
* Working testSend
* Merged refactoring + cleaned up some TODOs
* updated ICoreRelayer interface
* adjusted tests for new interface
* Working testSend with new interface'
* refactoring interfaces & files for single VAA design
* GasOracle implementation of new interface
* GasOracle compiles
* Gas oracle upgradable
* Fix compile errors in GasOracleGovernance
* minor core relayer cleanup
* Changes to getters, setters, state
* implement quoteEvmDeliveryPrice, quoteTargetEvmGas, assetConversionAmount for corerelayer
* Correcting interface inconsistencies between CoreRelayerStructs and ICoreRelayer
* Fix encodeDeliveryRequestsContainer
* added single vaa delivery entrypoint logic
* Encode and Decode delivery instructions
* Fixed many compile errors
* First attempt at removing stacktoodeep error
* Commenting out chunks of code to identify stack too deep error
* Continue stack too deep quest
* Revert "Commenting out chunks of code to identify stack too deep error"
This reverts commit 8cd55d26cea2c49dc6e6bfa481c310f1a1c1143a.
* Revert "Continue stack too deep quest"
This reverts commit f0cde6871e26a7063e20d9a83b63b6a50e32bf37.
* Fix stack too deep error in CoreRelayerMessages
* tests compile, run, pass
* fixing up fee collection assertions
* GasOracle tests altering
* Rename encodeDeliveryIntructions to convertToEncodedDeliveryInstructions because we are going from delivery request to delivery instruction
* adding evm events to delivery execution
* forwarding refactor for single vaa
* relay provider name refactor
* Test file slight refactor to allow for multiple chains
* first impl of hub and spoke example
* Forward test progress
* Forwarding test passes!
* More general parameters for test
* Testing file more modular, calls 'generic relayer'
* redelivery implementation
* removing todos
* Tests can use arbitrary amount of chains
* Address various TODOs
* refactored RelayProvider to be upgradeable via proxy
* Add overhead inteface to RelayProvider & adjusted necessary fee calculations
* added TODOs related to rewardAddress payout
* provider price quoting changes
* provider payments made at source
* Fixed all compile errors
* testForward and testSend pass again!
* Switched quoteAssetConversion to quoteApplicationBudgetFee in CoreRelayer interface
* First round of changes to support individual vaas in offchain relayer
- Use new custom plugin event source api in relayer engine
- Supports mulit delivery
- Config for celo and fuji
* contracts deploy successfully to tilt
* bug fixes, contracts deploy to tilt
* Starting the redelivery test
* Tests pass again, with exception of the RelayProvider tests that tested reverts, and the new testRedelivery which isn't finished
* small plugin changes
* MockRelayerIntegration is used for sending
* prepare offchain relayer to run in both tilt and testnet
* update readme and npm scripts for offchain relayer
* nit: remove console.log(argv)
* solc version bump
* Tests changed to pass (commented out the tests with differing require statements and kept redelivery incomplete
* chain registration typescript scripts
* Redeliver works!
* Redelivery test works!
* testnet deploy + relayer engine test
* Testing two sends
* Friday changes to round trip on testnet
* Shortening current tests
* Funds are correct! Relayer gets paid!
* Remove extraneous comments
* ts scripts for deployment and config
* Wormhole Fee Test
Co-authored-by: chase-45 <chasemoran45@gmail.com>
Co-authored-by: derpy-duck <115193320+derpy-duck@users.noreply.github.com>
2023-01-05 14:26:27 -08:00
|
|
|
function receiveWormholeMessages(bytes[] memory wormholeObservations, bytes[] memory) public payable override {
|
2022-10-06 10:16:57 -07:00
|
|
|
// loop through the array of wormhole observations from the batch and store each payload
|
Move development branch to main (#23)
* refactoring for multidelivery
* partial ts-test fixes
* use typechain in integration tests, update prettier, fix remaining integration tests
* run formatter on solidity files
* gas refunding
* gas forwarding logic
* msg.send -> refundAmount
* minor test refactor & additions
* created relayer engine directory
* more testing & tilt environment config for relayer engine
* starting work on the xMint example contracts
* additions for relayer engine
* minor modifications & todos
* fixed some errors
* refactoring + cleaned up some TODOs
* updated ICoreRelayer interface
* adjusted tests for new interface
* Working testSend
* Merged refactoring + cleaned up some TODOs
* updated ICoreRelayer interface
* adjusted tests for new interface
* Working testSend with new interface'
* refactoring interfaces & files for single VAA design
* GasOracle implementation of new interface
* GasOracle compiles
* Gas oracle upgradable
* Fix compile errors in GasOracleGovernance
* minor core relayer cleanup
* Changes to getters, setters, state
* implement quoteEvmDeliveryPrice, quoteTargetEvmGas, assetConversionAmount for corerelayer
* Correcting interface inconsistencies between CoreRelayerStructs and ICoreRelayer
* Fix encodeDeliveryRequestsContainer
* added single vaa delivery entrypoint logic
* Encode and Decode delivery instructions
* Fixed many compile errors
* First attempt at removing stacktoodeep error
* Commenting out chunks of code to identify stack too deep error
* Continue stack too deep quest
* Revert "Commenting out chunks of code to identify stack too deep error"
This reverts commit 8cd55d26cea2c49dc6e6bfa481c310f1a1c1143a.
* Revert "Continue stack too deep quest"
This reverts commit f0cde6871e26a7063e20d9a83b63b6a50e32bf37.
* Fix stack too deep error in CoreRelayerMessages
* tests compile, run, pass
* fixing up fee collection assertions
* GasOracle tests altering
* Rename encodeDeliveryIntructions to convertToEncodedDeliveryInstructions because we are going from delivery request to delivery instruction
* adding evm events to delivery execution
* forwarding refactor for single vaa
* relay provider name refactor
* Test file slight refactor to allow for multiple chains
* first impl of hub and spoke example
* Forward test progress
* Forwarding test passes!
* More general parameters for test
* Testing file more modular, calls 'generic relayer'
* redelivery implementation
* removing todos
* Tests can use arbitrary amount of chains
* Address various TODOs
* refactored RelayProvider to be upgradeable via proxy
* Add overhead inteface to RelayProvider & adjusted necessary fee calculations
* added TODOs related to rewardAddress payout
* provider price quoting changes
* provider payments made at source
* Fixed all compile errors
* testForward and testSend pass again!
* Switched quoteAssetConversion to quoteApplicationBudgetFee in CoreRelayer interface
* First round of changes to support individual vaas in offchain relayer
- Use new custom plugin event source api in relayer engine
- Supports mulit delivery
- Config for celo and fuji
* contracts deploy successfully to tilt
* bug fixes, contracts deploy to tilt
* Starting the redelivery test
* Tests pass again, with exception of the RelayProvider tests that tested reverts, and the new testRedelivery which isn't finished
* small plugin changes
* MockRelayerIntegration is used for sending
* prepare offchain relayer to run in both tilt and testnet
* update readme and npm scripts for offchain relayer
* nit: remove console.log(argv)
* solc version bump
* Tests changed to pass (commented out the tests with differing require statements and kept redelivery incomplete
* chain registration typescript scripts
* Redeliver works!
* Redelivery test works!
* testnet deploy + relayer engine test
* Testing two sends
* Friday changes to round trip on testnet
* Shortening current tests
* Funds are correct! Relayer gets paid!
* Remove extraneous comments
* ts scripts for deployment and config
* Wormhole Fee Test
Co-authored-by: chase-45 <chasemoran45@gmail.com>
Co-authored-by: derpy-duck <115193320+derpy-duck@users.noreply.github.com>
2023-01-05 14:26:27 -08:00
|
|
|
uint256 numObservations = wormholeObservations.length;
|
2023-03-14 10:45:03 -07:00
|
|
|
bytes[] memory messages = new bytes[](wormholeObservations.length - 2);
|
|
|
|
uint16 emitterChainId;
|
2023-02-10 15:32:44 -08:00
|
|
|
for (uint256 i = 0; i < numObservations - 2; i++) {
|
2022-10-06 10:16:57 -07:00
|
|
|
(IWormhole.VM memory parsed, bool valid, string memory reason) =
|
|
|
|
wormhole.parseAndVerifyVM(wormholeObservations[i]);
|
|
|
|
require(valid, reason);
|
2023-02-10 15:32:44 -08:00
|
|
|
require(registeredContracts[parsed.emitterChainId] == parsed.emitterAddress);
|
2023-03-14 10:45:03 -07:00
|
|
|
emitterChainId = parsed.emitterChainId;
|
2023-02-10 15:32:44 -08:00
|
|
|
messages[i] = parsed.payload;
|
|
|
|
}
|
2023-03-14 10:45:03 -07:00
|
|
|
messageHistory.push(messages);
|
2022-10-06 10:16:57 -07:00
|
|
|
|
2023-02-10 15:32:44 -08:00
|
|
|
(IWormhole.VM memory parsed, bool valid, string memory reason) =
|
2023-02-10 22:26:06 -08:00
|
|
|
wormhole.parseAndVerifyVM(wormholeObservations[wormholeObservations.length - 2]);
|
2023-02-10 15:32:44 -08:00
|
|
|
FurtherInstructions memory instructions = decodeFurtherInstructions(parsed.payload);
|
|
|
|
|
2023-02-10 22:26:06 -08:00
|
|
|
if (instructions.keepSending) {
|
|
|
|
for (uint16 i = 0; i < instructions.newMessages.length; i++) {
|
|
|
|
wormhole.publishMessage{value: wormhole.messageFee()}(parsed.nonce, instructions.newMessages[i], 200);
|
2023-02-10 15:32:44 -08:00
|
|
|
}
|
2023-02-13 16:43:12 -08:00
|
|
|
IWormholeRelayer.Send[] memory sendRequests = new IWormholeRelayer.Send[](instructions.chains.length);
|
2023-02-10 22:26:06 -08:00
|
|
|
for (uint16 i = 0; i < instructions.chains.length; i++) {
|
|
|
|
sendRequests[i] = IWormholeRelayer.Send({
|
2023-02-10 15:32:44 -08:00
|
|
|
targetChain: instructions.chains[i],
|
|
|
|
targetAddress: registeredContracts[instructions.chains[i]],
|
|
|
|
refundAddress: registeredContracts[instructions.chains[i]],
|
2023-02-10 22:26:06 -08:00
|
|
|
maxTransactionFee: relayer.quoteGas(
|
|
|
|
instructions.chains[i], instructions.gasLimits[i], relayer.getDefaultRelayProvider()
|
|
|
|
),
|
2023-02-10 12:33:00 -08:00
|
|
|
receiverValue: 0,
|
2023-01-13 12:27:59 -08:00
|
|
|
relayParameters: relayer.getDefaultRelayParams()
|
|
|
|
});
|
2022-10-06 10:16:57 -07:00
|
|
|
}
|
2023-02-13 16:44:05 -08:00
|
|
|
IWormholeRelayer.MultichainSend memory container = IWormholeRelayer.MultichainSend({
|
|
|
|
requests: sendRequests,
|
|
|
|
relayProviderAddress: relayer.getDefaultRelayProvider()
|
|
|
|
});
|
|
|
|
|
2023-02-27 11:32:57 -08:00
|
|
|
relayer.multichainForward(container, parsed.nonce);
|
2022-10-06 10:16:57 -07:00
|
|
|
}
|
2022-09-30 09:18:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPayload(bytes32 hash) public view returns (bytes memory) {
|
|
|
|
return verifiedPayloads[hash];
|
|
|
|
}
|
|
|
|
|
2023-02-13 07:14:49 -08:00
|
|
|
function getMessage() public view returns (bytes memory) {
|
2023-03-14 10:45:03 -07:00
|
|
|
if (messageHistory.length == 0 || messageHistory[messageHistory.length - 1].length == 0) {
|
2023-02-10 15:32:44 -08:00
|
|
|
return new bytes(0);
|
|
|
|
}
|
2023-03-14 10:45:03 -07:00
|
|
|
return messageHistory[messageHistory.length - 1][0];
|
2022-09-30 09:18:49 -07:00
|
|
|
}
|
|
|
|
|
2023-02-13 07:14:49 -08:00
|
|
|
function getMessages() public view returns (bytes[] memory) {
|
2023-03-14 10:45:03 -07:00
|
|
|
if (messageHistory.length == 0 || messageHistory[messageHistory.length - 1].length == 0) {
|
|
|
|
return new bytes[](0);
|
|
|
|
}
|
|
|
|
return messageHistory[messageHistory.length - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
function getMessageHistory() public view returns (bytes[][] memory) {
|
|
|
|
return messageHistory;
|
2023-02-13 07:14:49 -08:00
|
|
|
}
|
|
|
|
|
Move development branch to main (#23)
* refactoring for multidelivery
* partial ts-test fixes
* use typechain in integration tests, update prettier, fix remaining integration tests
* run formatter on solidity files
* gas refunding
* gas forwarding logic
* msg.send -> refundAmount
* minor test refactor & additions
* created relayer engine directory
* more testing & tilt environment config for relayer engine
* starting work on the xMint example contracts
* additions for relayer engine
* minor modifications & todos
* fixed some errors
* refactoring + cleaned up some TODOs
* updated ICoreRelayer interface
* adjusted tests for new interface
* Working testSend
* Merged refactoring + cleaned up some TODOs
* updated ICoreRelayer interface
* adjusted tests for new interface
* Working testSend with new interface'
* refactoring interfaces & files for single VAA design
* GasOracle implementation of new interface
* GasOracle compiles
* Gas oracle upgradable
* Fix compile errors in GasOracleGovernance
* minor core relayer cleanup
* Changes to getters, setters, state
* implement quoteEvmDeliveryPrice, quoteTargetEvmGas, assetConversionAmount for corerelayer
* Correcting interface inconsistencies between CoreRelayerStructs and ICoreRelayer
* Fix encodeDeliveryRequestsContainer
* added single vaa delivery entrypoint logic
* Encode and Decode delivery instructions
* Fixed many compile errors
* First attempt at removing stacktoodeep error
* Commenting out chunks of code to identify stack too deep error
* Continue stack too deep quest
* Revert "Commenting out chunks of code to identify stack too deep error"
This reverts commit 8cd55d26cea2c49dc6e6bfa481c310f1a1c1143a.
* Revert "Continue stack too deep quest"
This reverts commit f0cde6871e26a7063e20d9a83b63b6a50e32bf37.
* Fix stack too deep error in CoreRelayerMessages
* tests compile, run, pass
* fixing up fee collection assertions
* GasOracle tests altering
* Rename encodeDeliveryIntructions to convertToEncodedDeliveryInstructions because we are going from delivery request to delivery instruction
* adding evm events to delivery execution
* forwarding refactor for single vaa
* relay provider name refactor
* Test file slight refactor to allow for multiple chains
* first impl of hub and spoke example
* Forward test progress
* Forwarding test passes!
* More general parameters for test
* Testing file more modular, calls 'generic relayer'
* redelivery implementation
* removing todos
* Tests can use arbitrary amount of chains
* Address various TODOs
* refactored RelayProvider to be upgradeable via proxy
* Add overhead inteface to RelayProvider & adjusted necessary fee calculations
* added TODOs related to rewardAddress payout
* provider price quoting changes
* provider payments made at source
* Fixed all compile errors
* testForward and testSend pass again!
* Switched quoteAssetConversion to quoteApplicationBudgetFee in CoreRelayer interface
* First round of changes to support individual vaas in offchain relayer
- Use new custom plugin event source api in relayer engine
- Supports mulit delivery
- Config for celo and fuji
* contracts deploy successfully to tilt
* bug fixes, contracts deploy to tilt
* Starting the redelivery test
* Tests pass again, with exception of the RelayProvider tests that tested reverts, and the new testRedelivery which isn't finished
* small plugin changes
* MockRelayerIntegration is used for sending
* prepare offchain relayer to run in both tilt and testnet
* update readme and npm scripts for offchain relayer
* nit: remove console.log(argv)
* solc version bump
* Tests changed to pass (commented out the tests with differing require statements and kept redelivery incomplete
* chain registration typescript scripts
* Redeliver works!
* Redelivery test works!
* testnet deploy + relayer engine test
* Testing two sends
* Friday changes to round trip on testnet
* Shortening current tests
* Funds are correct! Relayer gets paid!
* Remove extraneous comments
* ts scripts for deployment and config
* Wormhole Fee Test
Co-authored-by: chase-45 <chasemoran45@gmail.com>
Co-authored-by: derpy-duck <115193320+derpy-duck@users.noreply.github.com>
2023-01-05 14:26:27 -08:00
|
|
|
function clearPayload(bytes32 hash) public {
|
|
|
|
delete verifiedPayloads[hash];
|
2022-09-30 09:18:49 -07:00
|
|
|
}
|
|
|
|
|
2022-10-06 10:16:57 -07:00
|
|
|
function parseWormholeObservation(bytes memory encoded) public view returns (IWormhole.VM memory) {
|
2022-09-30 09:18:49 -07:00
|
|
|
return wormhole.parseVM(encoded);
|
|
|
|
}
|
2022-10-06 10:16:57 -07:00
|
|
|
|
|
|
|
function emitterAddress() public view returns (bytes32) {
|
|
|
|
return bytes32(uint256(uint160(address(this))));
|
|
|
|
}
|
2023-02-10 10:53:49 -08:00
|
|
|
|
2023-02-10 15:32:44 -08:00
|
|
|
function registerEmitter(uint16 chainId, bytes32 emitterAddress) public {
|
|
|
|
require(msg.sender == owner);
|
|
|
|
registeredContracts[chainId] = emitterAddress;
|
2023-02-10 10:53:49 -08:00
|
|
|
}
|
|
|
|
|
2023-03-14 10:45:03 -07:00
|
|
|
function registerEmitters(Structs.XAddress[] calldata emitters) public {
|
|
|
|
require(msg.sender == owner);
|
|
|
|
for (uint256 i = 0; i < emitters.length; i++) {
|
|
|
|
registeredContracts[emitters[i].chainId] = emitters[i].addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-10 22:26:06 -08:00
|
|
|
function encodeFurtherInstructions(FurtherInstructions memory furtherInstructions)
|
|
|
|
public
|
|
|
|
view
|
|
|
|
returns (bytes memory encodedFurtherInstructions)
|
|
|
|
{
|
|
|
|
encodedFurtherInstructions = abi.encodePacked(
|
|
|
|
furtherInstructions.keepSending ? uint8(1) : uint8(0), uint16(furtherInstructions.newMessages.length)
|
|
|
|
);
|
|
|
|
for (uint16 i = 0; i < furtherInstructions.newMessages.length; i++) {
|
|
|
|
encodedFurtherInstructions = abi.encodePacked(
|
|
|
|
encodedFurtherInstructions,
|
|
|
|
uint16(furtherInstructions.newMessages[i].length),
|
|
|
|
furtherInstructions.newMessages[i]
|
|
|
|
);
|
2023-02-10 15:32:44 -08:00
|
|
|
}
|
2023-02-10 22:26:06 -08:00
|
|
|
encodedFurtherInstructions =
|
|
|
|
abi.encodePacked(encodedFurtherInstructions, uint16(furtherInstructions.chains.length));
|
|
|
|
for (uint16 i = 0; i < furtherInstructions.chains.length; i++) {
|
|
|
|
encodedFurtherInstructions = abi.encodePacked(
|
|
|
|
encodedFurtherInstructions, furtherInstructions.chains[i], furtherInstructions.gasLimits[i]
|
|
|
|
);
|
2023-02-10 10:53:49 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-10 22:26:06 -08:00
|
|
|
function decodeFurtherInstructions(bytes memory encodedFurtherInstructions)
|
|
|
|
public
|
|
|
|
view
|
|
|
|
returns (FurtherInstructions memory furtherInstructions)
|
|
|
|
{
|
2023-02-10 10:53:49 -08:00
|
|
|
uint256 index = 0;
|
2023-02-10 15:32:44 -08:00
|
|
|
|
|
|
|
furtherInstructions.keepSending = encodedFurtherInstructions.toUint8(index) == 1;
|
2023-02-10 10:53:49 -08:00
|
|
|
index += 1;
|
2023-02-10 15:32:44 -08:00
|
|
|
|
2023-02-10 22:26:06 -08:00
|
|
|
if (!furtherInstructions.keepSending) {
|
2023-02-10 15:32:44 -08:00
|
|
|
return furtherInstructions;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16 length = encodedFurtherInstructions.toUint16(index);
|
2023-02-10 10:53:49 -08:00
|
|
|
index += 2;
|
2023-02-10 15:32:44 -08:00
|
|
|
furtherInstructions.newMessages = new bytes[](length);
|
2023-02-10 22:26:06 -08:00
|
|
|
for (uint16 i = 0; i < length; i++) {
|
2023-02-10 15:32:44 -08:00
|
|
|
uint16 msgLength = encodedFurtherInstructions.toUint16(index);
|
|
|
|
index += 2;
|
|
|
|
furtherInstructions.newMessages[i] = encodedFurtherInstructions.slice(index, msgLength);
|
|
|
|
index += msgLength;
|
|
|
|
}
|
2023-02-10 22:26:06 -08:00
|
|
|
|
2023-02-10 15:32:44 -08:00
|
|
|
length = encodedFurtherInstructions.toUint16(index);
|
|
|
|
index += 2;
|
|
|
|
uint16[] memory chains = new uint16[](length);
|
|
|
|
uint32[] memory gasLimits = new uint32[](length);
|
2023-02-10 22:26:06 -08:00
|
|
|
for (uint16 i = 0; i < length; i++) {
|
2023-02-10 15:32:44 -08:00
|
|
|
chains[i] = encodedFurtherInstructions.toUint16(index);
|
|
|
|
index += 2;
|
|
|
|
gasLimits[i] = encodedFurtherInstructions.toUint32(index);
|
|
|
|
index += 4;
|
|
|
|
}
|
|
|
|
furtherInstructions.chains = chains;
|
|
|
|
furtherInstructions.gasLimits = gasLimits;
|
2023-02-10 10:53:49 -08:00
|
|
|
}
|
2023-02-15 14:23:11 -08:00
|
|
|
|
|
|
|
receive() external payable {}
|
2022-09-30 09:18:49 -07:00
|
|
|
}
|