Skip to content

Commit

Permalink
Registry 2 1 utils contract (#9727)
Browse files Browse the repository at this point in the history
* build AutomationUtils contract and update tests

* use report struct as rawReport bytes

* update wrappers

* add Log struct

---------

Co-authored-by: FelixFan1992 <fankejin@gmail.com>
  • Loading branch information
RyanRHall and FelixFan1992 committed Jul 6, 2023
1 parent 963eb51 commit fd13074
Show file tree
Hide file tree
Showing 9 changed files with 500 additions and 139 deletions.
1 change: 1 addition & 0 deletions contracts/scripts/native_solc_compile_all
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ $SCRIPTPATH/native_solc8_16_compile dev/automation/2_1/KeeperRegistryLogicA2_1.s
$SCRIPTPATH/native_solc8_16_compile dev/automation/2_1/KeeperRegistryLogicB2_1.sol
$SCRIPTPATH/native_solc8_16_compile dev/automation/2_1/interfaces/IKeeperRegistryMaster.sol
$SCRIPTPATH/native_solc8_16_compile dev/automation/2_1/interfaces/ILogAutomation.sol
$SCRIPTPATH/native_solc8_16_compile dev/automation/2_1/AutomationUtils2_1.sol
$SCRIPTPATH/native_solc8_6_compile dev/automation/tests/LogUpkeepCounter.sol
$SCRIPTPATH/native_solc8_16_compile dev/automation/tests/LogTriggeredFeedLookup.sol
$SCRIPTPATH/native_solc8_6_compile automation/UpkeepTranscoder.sol
Expand Down
27 changes: 27 additions & 0 deletions contracts/src/v0.8/dev/automation/2_1/AutomationUtils2_1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;

import "./KeeperRegistryBase2_1.sol";
import "./interfaces/ILogAutomation.sol";

/**
* @notice this file exposes structs that are otherwise internal to the automation registry
* doing this allows those structs to be encoded and decoded with type safety in offchain code
* and tests because generated wrappers are made available
*/

contract AutomationUtils2_1 {
function _onChainConfig(KeeperRegistryBase2_1.OnchainConfig memory) external {}

function _report(KeeperRegistryBase2_1.Report memory) external {}

function _logTriggerConfig(KeeperRegistryBase2_1.LogTriggerConfig memory) external {}

function _conditionalTriggerConfig(KeeperRegistryBase2_1.ConditionalTriggerConfig memory) external {}

function _logTrigger(KeeperRegistryBase2_1.LogTrigger memory) external {}

function _conditionalTrigger(KeeperRegistryBase2_1.ConditionalTrigger memory) external {}

function _log(Log memory) external {}
}
28 changes: 7 additions & 21 deletions contracts/src/v0.8/dev/automation/2_1/KeeperRegistry2_1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -384,31 +384,17 @@ contract KeeperRegistry2_1 is KeeperRegistryBase2_1, OCR2Abstract, Chainable, ER
/**
* @dev _decodeReport decodes a serialized report into a Report struct
*/
function _decodeReport(bytes memory rawReport) internal pure returns (Report memory) {
(
uint256 fastGasWei,
uint256 linkNative,
uint256[] memory upkeepIds,
uint256[] memory gasLimits,
bytes[] memory triggers,
bytes[] memory performDatas
) = abi.decode(rawReport, (uint256, uint256, uint256[], uint256[], bytes[], bytes[]));
function _decodeReport(bytes calldata rawReport) internal pure returns (Report memory) {
Report memory report = abi.decode(rawReport, (Report));
uint256 expectedLength = report.upkeepIds.length;
if (
upkeepIds.length != gasLimits.length ||
upkeepIds.length != triggers.length ||
upkeepIds.length != performDatas.length
report.gasLimits.length != expectedLength ||
report.triggers.length != expectedLength ||
report.performDatas.length != expectedLength
) {
revert InvalidReport();
}
return
Report({
fastGasWei: fastGasWei,
linkNative: linkNative,
upkeepIds: upkeepIds,
gasLimits: gasLimits,
triggers: triggers,
performDatas: performDatas
});
return report;
}

/**
Expand Down
Loading

0 comments on commit fd13074

Please sign in to comment.