diff --git a/public/samples/Automation/tutorials/EthBalanceMonitor.sol b/public/samples/Automation/tutorials/EthBalanceMonitor.sol index 0f50a5d4d4f..99b061960c8 100644 --- a/public/samples/Automation/tutorials/EthBalanceMonitor.sol +++ b/public/samples/Automation/tutorials/EthBalanceMonitor.sol @@ -29,14 +29,14 @@ contract EthBalanceMonitor is event FundsWithdrawn(uint256 amountWithdrawn, address payee); event TopUpSucceeded(address indexed recipient); event TopUpFailed(address indexed recipient); - event KeeperRegistryAddressUpdated(address oldAddress, address newAddress); + event ForwarderAddressUpdated(address oldAddress, address newAddress); event MinWaitPeriodUpdated( uint256 oldMinWaitPeriod, uint256 newMinWaitPeriod ); error InvalidWatchList(); - error OnlyKeeperRegistry(); + error OnlyForwarder(); error DuplicateAddress(address duplicate); struct Target { @@ -46,20 +46,20 @@ contract EthBalanceMonitor is uint56 lastTopUpTimestamp; // enough space for 2 trillion years } - address private s_keeperRegistryAddress; + address private s_forwarderAddress; uint256 private s_minWaitPeriodSeconds; address[] private s_watchList; mapping(address => Target) internal s_targets; /** - * @param keeperRegistryAddress The address of the Chainlink Automation registry contract + * @param forwarderAddress The address of the Chainlink Automation upkeep's forwarder contract * @param minWaitPeriodSeconds The minimum wait period for addresses between funding */ constructor( - address keeperRegistryAddress, + address forwarderAddress, uint256 minWaitPeriodSeconds ) ConfirmedOwner(msg.sender) { - setKeeperRegistryAddress(keeperRegistryAddress); + setForwarderAddress(forwarderAddress); setMinWaitPeriodSeconds(minWaitPeriodSeconds); } @@ -193,7 +193,7 @@ contract EthBalanceMonitor is */ function performUpkeep( bytes calldata performData - ) external override onlyKeeperRegistry whenNotPaused { + ) external override onlyForwarder whenNotPaused { address[] memory needsFunding = abi.decode(performData, (address[])); topUp(needsFunding); } @@ -220,17 +220,14 @@ contract EthBalanceMonitor is } /** - * @notice Sets the Chainlink Automation registry address + * @notice Sets the upkeep's unique forwarder address + * for upkeeps in Automation versions 2.0 and later + * https://docs.chain.link/chainlink-automation/guides/forwarder */ - function setKeeperRegistryAddress( - address keeperRegistryAddress - ) public onlyOwner { - require(keeperRegistryAddress != address(0)); - emit KeeperRegistryAddressUpdated( - s_keeperRegistryAddress, - keeperRegistryAddress - ); - s_keeperRegistryAddress = keeperRegistryAddress; + function setForwarderAddress(address forwarderAddress) public onlyOwner { + require(forwarderAddress != address(0)); + emit ForwarderAddressUpdated(s_forwarderAddress, forwarderAddress); + s_forwarderAddress = forwarderAddress; } /** @@ -242,14 +239,14 @@ contract EthBalanceMonitor is } /** - * @notice Gets the Chainlink Automation registry address + * @notice Gets the forwarder address of the Chainlink Automation upkeep */ - function getKeeperRegistryAddress() + function getForwarderAddress() external view - returns (address keeperRegistryAddress) + returns (address forwarderAddress) { - return s_keeperRegistryAddress; + return s_forwarderAddress; } /** @@ -304,9 +301,9 @@ contract EthBalanceMonitor is _unpause(); } - modifier onlyKeeperRegistry() { - if (msg.sender != s_keeperRegistryAddress) { - revert OnlyKeeperRegistry(); + modifier onlyForwarder() { + if (msg.sender != s_forwarderAddress) { + revert OnlyForwarder(); } _; } diff --git a/public/samples/Automation/tutorials/VRFSubscriptionBalanceMonitor.sol b/public/samples/Automation/tutorials/VRFSubscriptionBalanceMonitor.sol index 52b1bc2c543..d3acff2dc64 100644 --- a/public/samples/Automation/tutorials/VRFSubscriptionBalanceMonitor.sol +++ b/public/samples/Automation/tutorials/VRFSubscriptionBalanceMonitor.sol @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.6; +pragma solidity 0.8.20; import "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol"; import "@chainlink/contracts/src/v0.8/automation/interfaces/KeeperCompatibleInterface.sol"; @@ -26,7 +26,7 @@ contract VRFSubscriptionBalanceMonitor is event FundsWithdrawn(uint256 amountWithdrawn, address payee); event TopUpSucceeded(uint64 indexed subscriptionId); event TopUpFailed(uint64 indexed subscriptionId); - event KeeperRegistryAddressUpdated(address oldAddress, address newAddress); + event ForwarderAddressUpdated(address oldAddress, address newAddress); event VRFCoordinatorV2AddressUpdated( address oldAddress, address newAddress @@ -40,6 +40,7 @@ contract VRFSubscriptionBalanceMonitor is error InvalidWatchList(); error OnlyKeeperRegistry(); + error OnlyForwarder(); error DuplicateSubcriptionId(uint64 duplicate); struct Target { @@ -49,7 +50,7 @@ contract VRFSubscriptionBalanceMonitor is uint56 lastTopUpTimestamp; } - address public s_keeperRegistryAddress; // the address of the keeper registry + address public s_forwarderAddress; // the address of the upkeep's forwarder uint256 public s_minWaitPeriodSeconds; // minimum time to wait between top-ups uint64[] public s_watchList; // the watchlist on which subscriptions are stored mapping(uint64 => Target) internal s_targets; @@ -57,18 +58,18 @@ contract VRFSubscriptionBalanceMonitor is /** * @param linkTokenAddress the Link token address * @param coordinatorAddress the address of the vrf coordinator contract - * @param keeperRegistryAddress the address of the keeper registry contract + * @param forwarderAddress the address of the upkeep's forwarder * @param minWaitPeriodSeconds the minimum wait period for addresses between funding */ constructor( address linkTokenAddress, address coordinatorAddress, - address keeperRegistryAddress, + address forwarderAddress, uint256 minWaitPeriodSeconds ) ConfirmedOwner(msg.sender) { setLinkTokenAddress(linkTokenAddress); setVRFCoordinatorV2Address(coordinatorAddress); - setKeeperRegistryAddress(keeperRegistryAddress); + setForwarderAddress(forwarderAddress); setMinWaitPeriodSeconds(minWaitPeriodSeconds); } @@ -218,7 +219,7 @@ contract VRFSubscriptionBalanceMonitor is */ function performUpkeep( bytes calldata performData - ) external override onlyKeeperRegistry whenNotPaused { + ) external override onlyForwarder whenNotPaused { uint64[] memory needsFunding = abi.decode(performData, (uint64[])); topUp(needsFunding); } @@ -261,17 +262,14 @@ contract VRFSubscriptionBalanceMonitor is } /** - * @notice Sets the keeper registry address. + * @notice Sets the upkeep's unique forwarder address + * for upkeeps in Automation versions 2.0 and later + * https://docs.chain.link/chainlink-automation/guides/forwarder */ - function setKeeperRegistryAddress( - address keeperRegistryAddress - ) public onlyOwner { - require(keeperRegistryAddress != address(0)); - emit KeeperRegistryAddressUpdated( - s_keeperRegistryAddress, - keeperRegistryAddress - ); - s_keeperRegistryAddress = keeperRegistryAddress; + function setForwarderAddress(address forwarderAddress) public onlyOwner { + require(forwarderAddress != address(0)); + emit ForwarderAddressUpdated(s_forwarderAddress, forwarderAddress); + s_forwarderAddress = forwarderAddress; } /** @@ -327,9 +325,9 @@ contract VRFSubscriptionBalanceMonitor is _unpause(); } - modifier onlyKeeperRegistry() { - if (msg.sender != s_keeperRegistryAddress) { - revert OnlyKeeperRegistry(); + modifier onlyForwarder() { + if (msg.sender != s_forwarderAddress) { + revert OnlyForwarder(); } _; }