2022-09-30 09:18:49 -07:00
|
|
|
// contracts/Relayer.sol
|
|
|
|
// SPDX-License-Identifier: Apache 2
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Upgrade.sol";
|
|
|
|
|
|
|
|
import "../libraries/external/BytesLib.sol";
|
|
|
|
|
|
|
|
import "./CoreRelayerGetters.sol";
|
|
|
|
import "./CoreRelayerSetters.sol";
|
|
|
|
import "./CoreRelayerStructs.sol";
|
|
|
|
import "./CoreRelayerMessages.sol";
|
|
|
|
|
|
|
|
import "../interfaces/IWormhole.sol";
|
2023-01-08 22:00:40 -08:00
|
|
|
import "./CoreRelayerLibrary.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
|
|
|
abstract contract CoreRelayerGovernance is
|
|
|
|
CoreRelayerGetters,
|
|
|
|
CoreRelayerSetters,
|
|
|
|
CoreRelayerMessages,
|
|
|
|
ERC1967Upgrade
|
|
|
|
{
|
2023-01-07 13:47:01 -08:00
|
|
|
using BytesLib for bytes;
|
2023-01-11 11:11:43 -08:00
|
|
|
|
2023-01-19 06:59:35 -08:00
|
|
|
error InvalidFork();
|
|
|
|
error InvalidGovernanceVM(string reason);
|
|
|
|
error WrongChainId(uint16 chainId);
|
|
|
|
error InvalidChainId(uint16 chainId);
|
|
|
|
error FailedToInitializeImplementation(string reason);
|
|
|
|
|
2023-01-07 13:47:01 -08:00
|
|
|
event ContractUpgraded(address indexed oldContract, address indexed newContract);
|
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-01-07 13:47:01 -08:00
|
|
|
// "CoreRelayer" (left padded)
|
|
|
|
bytes32 constant module = 0x000000000000000000000000000000000000000000436f726552656c61796572;
|
2023-01-05 16:46:58 -08:00
|
|
|
|
2023-01-07 13:47:01 -08:00
|
|
|
function submitContractUpgrade(bytes memory _vm) public {
|
2023-01-19 06:59:35 -08:00
|
|
|
if (isFork()) {
|
|
|
|
revert InvalidFork();
|
|
|
|
}
|
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-01-07 13:47:01 -08:00
|
|
|
(IWormhole.VM memory vm, bool valid, string memory reason) = verifyGovernanceVM(_vm);
|
2023-01-19 06:59:35 -08:00
|
|
|
if (!valid) {
|
|
|
|
revert InvalidGovernanceVM(string(reason));
|
|
|
|
}
|
2023-01-07 13:47:01 -08:00
|
|
|
|
|
|
|
setConsumedGovernanceAction(vm.hash);
|
|
|
|
|
2023-01-08 22:00:40 -08:00
|
|
|
CoreRelayerLibrary.ContractUpgrade memory contractUpgrade = CoreRelayerLibrary.parseUpgrade(vm.payload, module);
|
2023-01-19 06:59:35 -08:00
|
|
|
if (contractUpgrade.chain != chainId()) {
|
|
|
|
revert WrongChainId(contractUpgrade.chain);
|
|
|
|
}
|
2023-01-07 13:47:01 -08:00
|
|
|
|
|
|
|
upgradeImplementation(contractUpgrade.newContract);
|
2022-09-30 09:18:49 -07:00
|
|
|
}
|
|
|
|
|
2023-01-07 13:47:01 -08:00
|
|
|
function registerCoreRelayerContract(bytes memory vaa) public {
|
|
|
|
(IWormhole.VM memory vm, bool valid, string memory reason) = verifyGovernanceVM(vaa);
|
2023-01-19 06:59:35 -08:00
|
|
|
if (!valid) {
|
|
|
|
revert InvalidGovernanceVM(string(reason));
|
|
|
|
}
|
2022-09-30 09:18:49 -07:00
|
|
|
|
2023-01-07 13:47:01 -08:00
|
|
|
setConsumedGovernanceAction(vm.hash);
|
2022-09-30 09:18:49 -07:00
|
|
|
|
2023-01-08 22:00:40 -08:00
|
|
|
CoreRelayerLibrary.RegisterChain memory rc = CoreRelayerLibrary.parseRegisterChain(vm.payload, module);
|
2022-09-30 09:18:49 -07:00
|
|
|
|
2023-01-19 06:59:35 -08:00
|
|
|
if ((rc.chain != chainId() || isFork()) && rc.chain != 0) {
|
|
|
|
revert InvalidChainId(rc.chain);
|
|
|
|
}
|
2022-09-30 09:18:49 -07:00
|
|
|
|
2023-01-07 13:47:01 -08:00
|
|
|
setRegisteredCoreRelayerContract(rc.emitterChain, rc.emitterAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setDefaultRelayProvider(bytes memory vaa) public {
|
|
|
|
(IWormhole.VM memory vm, bool valid, string memory reason) = verifyGovernanceVM(vaa);
|
2023-01-19 06:59:35 -08:00
|
|
|
if (!valid) {
|
|
|
|
revert InvalidGovernanceVM(string(reason));
|
|
|
|
}
|
2023-01-07 13:47:01 -08:00
|
|
|
|
|
|
|
setConsumedGovernanceAction(vm.hash);
|
|
|
|
|
2023-01-11 11:11:43 -08:00
|
|
|
CoreRelayerLibrary.UpdateDefaultProvider memory provider =
|
|
|
|
CoreRelayerLibrary.parseUpdateDefaultProvider(vm.payload, module);
|
2023-01-07 13:47:01 -08:00
|
|
|
|
2023-01-19 06:59:35 -08:00
|
|
|
if ((provider.chain != chainId() || isFork()) && provider.chain != 0) {
|
|
|
|
revert InvalidChainId(provider.chain);
|
|
|
|
}
|
2022-09-30 09:18:49 -07:00
|
|
|
|
2023-01-07 13:47:01 -08:00
|
|
|
setRelayProvider(provider.newProvider);
|
2022-09-30 09:18:49 -07:00
|
|
|
}
|
|
|
|
|
2023-01-08 22:00:40 -08:00
|
|
|
function upgradeImplementation(address newImplementation) internal {
|
|
|
|
address currentImplementation = _getImplementation();
|
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-01-08 22:00:40 -08:00
|
|
|
_upgradeTo(newImplementation);
|
2022-09-30 09:18:49 -07:00
|
|
|
|
2023-01-08 22:00:40 -08:00
|
|
|
// Call initialize function of the new implementation
|
|
|
|
(bool success, bytes memory reason) = newImplementation.delegatecall(abi.encodeWithSignature("initialize()"));
|
2023-01-07 13:47:01 -08:00
|
|
|
|
2023-01-19 06:59:35 -08:00
|
|
|
if (!success) {
|
|
|
|
revert FailedToInitializeImplementation(string(reason));
|
|
|
|
}
|
2023-01-07 13:47:01 -08:00
|
|
|
|
2023-01-08 22:00:40 -08:00
|
|
|
emit ContractUpgraded(currentImplementation, newImplementation);
|
2023-01-07 13:47:01 -08:00
|
|
|
}
|
|
|
|
|
2023-01-11 11:11:43 -08:00
|
|
|
function verifyGovernanceVM(bytes memory encodedVM)
|
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns (IWormhole.VM memory parsedVM, bool isValid, string memory invalidReason)
|
|
|
|
{
|
2023-01-07 13:47:01 -08:00
|
|
|
(IWormhole.VM memory vm, bool valid, string memory reason) = wormhole().parseAndVerifyVM(encodedVM);
|
|
|
|
|
|
|
|
if (!valid) {
|
|
|
|
return (vm, valid, reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vm.emitterChainId != governanceChainId()) {
|
|
|
|
return (vm, false, "wrong governance chain");
|
|
|
|
}
|
|
|
|
if (vm.emitterAddress != governanceContract()) {
|
|
|
|
return (vm, false, "wrong governance contract");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (governanceActionIsConsumed(vm.hash)) {
|
|
|
|
return (vm, false, "governance action already consumed");
|
|
|
|
}
|
|
|
|
|
|
|
|
return (vm, true, "");
|
|
|
|
}
|
2022-09-30 09:18:49 -07:00
|
|
|
}
|