Skip to content

Commit

Permalink
Merge branch 'develop' into BCI-2702-Apply-LimitMultiplier-to-gas-lim…
Browse files Browse the repository at this point in the history
…it-in-all-gas-estimators
  • Loading branch information
silaslenihan authored Mar 25, 2024
2 parents da7d128 + 20e730a commit c0964fd
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 132 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-coats-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

safeTransfer and cleanups
5 changes: 5 additions & 0 deletions contracts/.changeset/many-onions-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chainlink/contracts": patch
---

safeTransfer and cleanups

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ contract GetMinBalanceForUpkeep is SetUp {
}

contract BillingOverrides is SetUp {
event BillingConfigOverridden(uint256 indexed id);
event BillingConfigOverridden(uint256 indexed id, AutomationRegistryBase2_3.BillingOverrides overrides);
event BillingConfigOverrideRemoved(uint256 indexed id);

function test_RevertsWhen_NotPrivilegeManager() public {
Expand Down Expand Up @@ -937,7 +937,7 @@ contract BillingOverrides is SetUp {
vm.startPrank(PRIVILEGE_MANAGER);

vm.expectEmit();
emit BillingConfigOverridden(linkUpkeepID);
emit BillingConfigOverridden(linkUpkeepID, billingOverrides);
registry.setBillingOverrides(linkUpkeepID, billingOverrides);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ abstract contract AutomationRegistryBase2_3 is ConfirmedOwner {
}

event AdminPrivilegeConfigSet(address indexed admin, bytes privilegeConfig);
event BillingConfigOverridden(uint256 indexed id);
event BillingConfigOverridden(uint256 indexed id, BillingOverrides overrides);
event BillingConfigOverrideRemoved(uint256 indexed id);
event CancelledUpkeepReport(uint256 indexed id, bytes trigger);
event ChainSpecificModuleUpdated(address newModule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {IAutomationForwarder} from "../../interfaces/IAutomationForwarder.sol";
import {UpkeepTranscoderInterfaceV2} from "../../interfaces/UpkeepTranscoderInterfaceV2.sol";
import {MigratableKeeperRegistryInterfaceV2} from "../../interfaces/MigratableKeeperRegistryInterfaceV2.sol";
import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/utils/SafeERC20.sol";

/**
* @notice Logic contract, works in tandem with AutomationRegistry as a proxy
Expand All @@ -20,6 +21,7 @@ contract AutomationRegistryLogicA2_3 is AutomationRegistryBase2_3, Chainable {
using Address for address;
using EnumerableSet for EnumerableSet.UintSet;
using EnumerableSet for EnumerableSet.AddressSet;
using SafeERC20 for IERC20;

/**
* @param logicB the address of the second logic contract
Expand Down Expand Up @@ -163,56 +165,6 @@ contract AutomationRegistryLogicA2_3 is AutomationRegistryBase2_3, Chainable {
return checkUpkeep(id, bytes(""));
}

/**
* @dev checkCallback is used specifically for automation data streams lookups (see StreamsLookupCompatibleInterface.sol)
* @param id the upkeepID to execute a callback for
* @param values the values returned from the data streams lookup
* @param extraData the user-provided extra context data
*/
function checkCallback(
uint256 id,
bytes[] memory values,
bytes calldata extraData
)
external
returns (bool upkeepNeeded, bytes memory performData, UpkeepFailureReason upkeepFailureReason, uint256 gasUsed)
{
bytes memory payload = abi.encodeWithSelector(CHECK_CALLBACK_SELECTOR, values, extraData);
return executeCallback(id, payload);
}

/**
* @notice this is a generic callback executor that forwards a call to a user's contract with the configured
* gas limit
* @param id the upkeepID to execute a callback for
* @param payload the data (including function selector) to call on the upkeep target contract
*/
function executeCallback(
uint256 id,
bytes memory payload
)
public
returns (bool upkeepNeeded, bytes memory performData, UpkeepFailureReason upkeepFailureReason, uint256 gasUsed)
{
_preventExecution();

Upkeep memory upkeep = s_upkeep[id];
gasUsed = gasleft();
(bool success, bytes memory result) = upkeep.forwarder.getTarget().call{gas: s_storage.checkGasLimit}(payload);
gasUsed = gasUsed - gasleft();
if (!success) {
return (false, bytes(""), UpkeepFailureReason.CALLBACK_REVERTED, gasUsed);
}
(upkeepNeeded, performData) = abi.decode(result, (bool, bytes));
if (!upkeepNeeded) {
return (false, bytes(""), UpkeepFailureReason.UPKEEP_NOT_NEEDED, gasUsed);
}
if (performData.length > s_storage.maxPerformDataSize) {
return (false, bytes(""), UpkeepFailureReason.PERFORM_DATA_EXCEEDS_LIMIT, gasUsed);
}
return (upkeepNeeded, performData, upkeepFailureReason, gasUsed);
}

/**
* @notice adds a new upkeep
* @param target address to perform upkeep on
Expand Down Expand Up @@ -346,7 +298,7 @@ contract AutomationRegistryLogicA2_3 is AutomationRegistryBase2_3, Chainable {
s_upkeepIDs.remove(id);
emit UpkeepMigrated(id, upkeep.balance, destination);
s_reserveAmounts[upkeep.billingToken] = s_reserveAmounts[upkeep.billingToken] - upkeep.balance;
upkeep.billingToken.transfer(destination, upkeep.balance);
upkeep.billingToken.safeTransfer(destination, upkeep.balance);
}
bytes memory encodedUpkeeps = abi.encode(
ids,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import {AutomationRegistryLogicC2_3} from "./AutomationRegistryLogicC2_3.sol";
import {Chainable} from "../../Chainable.sol";
import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {SafeCast} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/utils/math/SafeCast.sol";
import {SafeERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/utils/SafeERC20.sol";

contract AutomationRegistryLogicB2_3 is AutomationRegistryBase2_3, Chainable {
using Address for address;
using EnumerableSet for EnumerableSet.UintSet;
using EnumerableSet for EnumerableSet.AddressSet;
using SafeERC20 for IERC20;

/**
* @param logicC the address of the third logic contract
Expand Down Expand Up @@ -48,7 +50,7 @@ contract AutomationRegistryLogicB2_3 is AutomationRegistryBase2_3, Chainable {

s_upkeep[id].overridesEnabled = true;
s_billingOverrides[id] = billingOverrides;
emit BillingConfigOverridden(id);
emit BillingConfigOverridden(id, billingOverrides);
}

/**
Expand Down Expand Up @@ -198,8 +200,7 @@ contract AutomationRegistryLogicB2_3 is AutomationRegistryBase2_3, Chainable {
uint96 amountToWithdraw = s_upkeep[id].balance;
s_reserveAmounts[upkeep.billingToken] = s_reserveAmounts[upkeep.billingToken] - amountToWithdraw;
s_upkeep[id].balance = 0;
bool success = upkeep.billingToken.transfer(to, amountToWithdraw);
if (!success) revert TransferFailed();
upkeep.billingToken.safeTransfer(to, amountToWithdraw);
emit FundsWithdrawn(id, amountToWithdraw, to);
}

Expand Down Expand Up @@ -229,11 +230,58 @@ contract AutomationRegistryLogicB2_3 is AutomationRegistryBase2_3, Chainable {
_onlyFinanceAdminAllowed();
if (to == ZERO_ADDRESS) revert InvalidRecipient();

bool transferStatus = IERC20(assetAddress).transfer(to, amount);
if (!transferStatus) {
revert TransferFailed();
}
IERC20(assetAddress).safeTransfer(to, amount);

emit FeesWithdrawn(to, assetAddress, amount);
}

/**
* @dev checkCallback is used specifically for automation data streams lookups (see StreamsLookupCompatibleInterface.sol)
* @param id the upkeepID to execute a callback for
* @param values the values returned from the data streams lookup
* @param extraData the user-provided extra context data
*/
function checkCallback(
uint256 id,
bytes[] memory values,
bytes calldata extraData
)
external
returns (bool upkeepNeeded, bytes memory performData, UpkeepFailureReason upkeepFailureReason, uint256 gasUsed)
{
bytes memory payload = abi.encodeWithSelector(CHECK_CALLBACK_SELECTOR, values, extraData);
return executeCallback(id, payload);
}

/**
* @notice this is a generic callback executor that forwards a call to a user's contract with the configured
* gas limit
* @param id the upkeepID to execute a callback for
* @param payload the data (including function selector) to call on the upkeep target contract
*/
function executeCallback(
uint256 id,
bytes memory payload
)
public
returns (bool upkeepNeeded, bytes memory performData, UpkeepFailureReason upkeepFailureReason, uint256 gasUsed)
{
_preventExecution();

Upkeep memory upkeep = s_upkeep[id];
gasUsed = gasleft();
(bool success, bytes memory result) = upkeep.forwarder.getTarget().call{gas: s_storage.checkGasLimit}(payload);
gasUsed = gasUsed - gasleft();
if (!success) {
return (false, bytes(""), UpkeepFailureReason.CALLBACK_REVERTED, gasUsed);
}
(upkeepNeeded, performData) = abi.decode(result, (bool, bytes));
if (!upkeepNeeded) {
return (false, bytes(""), UpkeepFailureReason.UPKEEP_NOT_NEEDED, gasUsed);
}
if (performData.length > s_storage.maxPerformDataSize) {
return (false, bytes(""), UpkeepFailureReason.PERFORM_DATA_EXCEEDS_LIMIT, gasUsed);
}
return (upkeepNeeded, performData, upkeepFailureReason, gasUsed);
}
}
3 changes: 1 addition & 2 deletions contracts/test/v0.8/automation/AutomationRegistry2_3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3745,8 +3745,6 @@ describe('AutomationRegistry2_3', () => {
})

describeMaybe('#setConfig - onchain', async () => {
const payment = BigNumber.from(1)
const flatFee = BigNumber.from(2)
const maxGas = BigNumber.from(6)
const staleness = BigNumber.from(4)
const ceiling = BigNumber.from(5)
Expand Down Expand Up @@ -5220,6 +5218,7 @@ describe('AutomationRegistry2_3', () => {

describe('when called by the owner when the admin has just canceled', () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// @ts-ignore
let oldExpiration: BigNumber

beforeEach(async () => {
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ automation_forwarder_logic: ../../contracts/solc/v0.8.16/AutomationForwarderLogi
automation_registrar_wrapper2_1: ../../contracts/solc/v0.8.16/AutomationRegistrar2_1/AutomationRegistrar2_1.abi ../../contracts/solc/v0.8.16/AutomationRegistrar2_1/AutomationRegistrar2_1.bin eb06d853aab39d3196c593b03e555851cbe8386e0fe54a74c2479f62d14b3c42
automation_registrar_wrapper2_3: ../../contracts/solc/v0.8.19/AutomationRegistrar2_3/AutomationRegistrar2_3.abi ../../contracts/solc/v0.8.19/AutomationRegistrar2_3/AutomationRegistrar2_3.bin 20fac1208261e866caa1f3ffc71030f682a96761bebe79e5ecd71186fce86c60
automation_registry_logic_a_wrapper_2_2: ../../contracts/solc/v0.8.19/AutomationRegistryLogicA2_2/AutomationRegistryLogicA2_2.abi ../../contracts/solc/v0.8.19/AutomationRegistryLogicA2_2/AutomationRegistryLogicA2_2.bin 2f267fb8467a15c587ce4586ac56069f7229344ad3936430d7c7624c0528a171
automation_registry_logic_a_wrapper_2_3: ../../contracts/solc/v0.8.19/AutomationRegistryLogicA2_3/AutomationRegistryLogicA2_3.abi ../../contracts/solc/v0.8.19/AutomationRegistryLogicA2_3/AutomationRegistryLogicA2_3.bin 9bbbcdf0cef19784f47d6a6daf17c8cfc6a76dd29b8bd0fff191c8eb2d026b03
automation_registry_logic_a_wrapper_2_3: ../../contracts/solc/v0.8.19/AutomationRegistryLogicA2_3/AutomationRegistryLogicA2_3.abi ../../contracts/solc/v0.8.19/AutomationRegistryLogicA2_3/AutomationRegistryLogicA2_3.bin 0ec86026840302ec1db31455d039d4e2f93c2646ee48879d644fe489bf873695
automation_registry_logic_b_wrapper_2_2: ../../contracts/solc/v0.8.19/AutomationRegistryLogicB2_2/AutomationRegistryLogicB2_2.abi ../../contracts/solc/v0.8.19/AutomationRegistryLogicB2_2/AutomationRegistryLogicB2_2.bin a6d33dfbbfb0ff253eb59a51f4f6d6d4c22ea5ec95aae52d25d49a312b37a22f
automation_registry_logic_b_wrapper_2_3: ../../contracts/solc/v0.8.19/AutomationRegistryLogicB2_3/AutomationRegistryLogicB2_3.abi ../../contracts/solc/v0.8.19/AutomationRegistryLogicB2_3/AutomationRegistryLogicB2_3.bin ea2efc6faac0630fad4f8554c69d3a8b1ca287c9e221d414a3abc35eb9f2d14e
automation_registry_logic_b_wrapper_2_3: ../../contracts/solc/v0.8.19/AutomationRegistryLogicB2_3/AutomationRegistryLogicB2_3.abi ../../contracts/solc/v0.8.19/AutomationRegistryLogicB2_3/AutomationRegistryLogicB2_3.bin 9f634b949412b06383fe53fd0531a6574e90163855238dbdd3d63589df94b77e
automation_registry_wrapper_2_2: ../../contracts/solc/v0.8.19/AutomationRegistry2_2/AutomationRegistry2_2.abi ../../contracts/solc/v0.8.19/AutomationRegistry2_2/AutomationRegistry2_2.bin de60f69878e9b32a291a001c91fc8636544c2cfbd9b507c8c1a4873b602bfb62
automation_registry_wrapper_2_3: ../../contracts/solc/v0.8.19/AutomationRegistry2_3/AutomationRegistry2_3.abi ../../contracts/solc/v0.8.19/AutomationRegistry2_3/AutomationRegistry2_3.bin ec9d629a5b6ed6a9f11b97a961ee6dbfd692ccad614bfa5216a6935b5aacf309
automation_registry_wrapper_2_3: ../../contracts/solc/v0.8.19/AutomationRegistry2_3/AutomationRegistry2_3.abi ../../contracts/solc/v0.8.19/AutomationRegistry2_3/AutomationRegistry2_3.bin 335dfe64a5cabcf12c6bac6e231919dddec5544a66cd647c229e8fe1f773ab61
automation_utils_2_1: ../../contracts/solc/v0.8.16/AutomationUtils2_1/AutomationUtils2_1.abi ../../contracts/solc/v0.8.16/AutomationUtils2_1/AutomationUtils2_1.bin 815b17b63f15d26a0274b962eefad98cdee4ec897ead58688bbb8e2470e585f5
automation_utils_2_2: ../../contracts/solc/v0.8.19/AutomationUtils2_2/AutomationUtils2_2.abi ../../contracts/solc/v0.8.19/AutomationUtils2_2/AutomationUtils2_2.bin 8743f6231aaefa3f2a0b2d484258070d506e2d0860690e66890dccc3949edb2e
automation_utils_2_3: ../../contracts/solc/v0.8.19/AutomationUtils2_3/AutomationUtils2_3.abi ../../contracts/solc/v0.8.19/AutomationUtils2_3/AutomationUtils2_3.bin 11e2b481dc9a4d936e3443345d45d2cc571164459d214917b42a8054b295393b
Expand All @@ -34,7 +34,7 @@ flux_aggregator_wrapper: ../../contracts/solc/v0.6/FluxAggregator/FluxAggregator
gas_wrapper: ../../contracts/solc/v0.8.6/KeeperRegistryCheckUpkeepGasUsageWrapper1_2/KeeperRegistryCheckUpkeepGasUsageWrapper1_2.abi ../../contracts/solc/v0.8.6/KeeperRegistryCheckUpkeepGasUsageWrapper1_2/KeeperRegistryCheckUpkeepGasUsageWrapper1_2.bin 4a5dcdac486d18fcd58e3488c15c1710ae76b977556a3f3191bd269a4bc75723
gas_wrapper_mock: ../../contracts/solc/v0.8.6/KeeperRegistryCheckUpkeepGasUsageWrapper1_2Mock/KeeperRegistryCheckUpkeepGasUsageWrapper1_2Mock.abi ../../contracts/solc/v0.8.6/KeeperRegistryCheckUpkeepGasUsageWrapper1_2Mock/KeeperRegistryCheckUpkeepGasUsageWrapper1_2Mock.bin a9b08f18da59125c6fc305855710241f3d35161b8b9f3e3f635a7b1d5c6da9c8
i_automation_registry_master_wrapper_2_2: ../../contracts/solc/v0.8.19/IAutomationRegistryMaster/IAutomationRegistryMaster.abi ../../contracts/solc/v0.8.19/IAutomationRegistryMaster/IAutomationRegistryMaster.bin 9ff7087179f89f9b05964ebc3e71332fce11f1b8e85058f7b16b3bc0dd6fb96b
i_automation_registry_master_wrapper_2_3: ../../contracts/solc/v0.8.19/IAutomationRegistryMaster2_3/IAutomationRegistryMaster2_3.abi ../../contracts/solc/v0.8.19/IAutomationRegistryMaster2_3/IAutomationRegistryMaster2_3.bin 1c8827ef4a4539b368644a12029acedb2e83410a790848e53e780b2261c97a76
i_automation_registry_master_wrapper_2_3: ../../contracts/solc/v0.8.19/IAutomationRegistryMaster2_3/IAutomationRegistryMaster2_3.abi ../../contracts/solc/v0.8.19/IAutomationRegistryMaster2_3/IAutomationRegistryMaster2_3.bin 461ef24891bd14e5ba956c2bb565715e309809d6e5cb65c39a3a932da7729915
i_automation_v21_plus_common: ../../contracts/solc/v0.8.19/IAutomationV21PlusCommon/IAutomationV21PlusCommon.abi ../../contracts/solc/v0.8.19/IAutomationV21PlusCommon/IAutomationV21PlusCommon.bin e8a601ec382c0a2e83c49759de13b0622b5e04e6b95901e96a1e9504329e594c
i_chain_module: ../../contracts/solc/v0.8.19/IChainModule/IChainModule.abi ../../contracts/solc/v0.8.19/IChainModule/IChainModule.bin 383611981c86c70522f41b8750719faacc7d7933a22849d5004799ebef3371fa
i_keeper_registry_master_wrapper_2_1: ../../contracts/solc/v0.8.16/IKeeperRegistryMaster/IKeeperRegistryMaster.abi ../../contracts/solc/v0.8.16/IKeeperRegistryMaster/IKeeperRegistryMaster.bin ee0f150b3afbab2df3d24ff3f4c87851efa635da30db04cd1f70cb4e185a1781
Expand Down
6 changes: 4 additions & 2 deletions integration-tests/load/automationv2_1/automationv2_1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ Load Config:
Values: map[string]interface{}{
"resources": gethNodeSpec,
"geth": map[string]interface{}{
"blocktime": *loadedTestConfig.Automation.General.BlockTime,
"capacity": "20Gi",
"blocktime": *loadedTestConfig.Automation.General.BlockTime,
"capacity": "20Gi",
"startGaslimit": "20000000",
"targetGasLimit": "30000000",
},
},
}))
Expand Down

0 comments on commit c0964fd

Please sign in to comment.