Skip to content

Commit 70335f5

Browse files
Updates QS to use Sepolia and Automation forwarder (#1894)
* Sepolia and forwarder updates * Giveaway partial text update * Pass cost to end user - updated and retested * Some updates * fix one import path * try 0.8.19 * Update CLA registry address * Enable 0.8.20 in hardhat config * Adjust setWatchlist inputs * Minor prereq change --------- Co-authored-by: Dwight Lyle <[email protected]>
1 parent d0819ba commit 70335f5

9 files changed

+119
-112
lines changed

hardhat.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const config: HardhatUserConfig = {
2020
{ version: "0.8.6" },
2121
{ version: "0.8.16" },
2222
{ version: "0.8.19" },
23+
{ version: "0.8.20" },
2324
],
2425
},
2526
}

public/samples/Automation/tutorials/EthBalanceMonitor.sol

+22-30
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
pragma solidity ^0.8.7;
44

5-
import {ConfirmedOwner} from "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol";
6-
import {AutomationCompatibleInterface} from "@chainlink/contracts/src/v0.8/automation/interfaces/AutomationCompatibleInterface.sol";
7-
import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
5+
import "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol";
6+
import "@chainlink/contracts/src/v0.8/automation/interfaces/AutomationCompatibleInterface.sol";
7+
import "@openzeppelin/contracts/security/Pausable.sol";
88

99
/**
1010
* @title The EthBalanceMonitor contract
@@ -29,14 +29,14 @@ contract EthBalanceMonitor is
2929
event FundsWithdrawn(uint256 amountWithdrawn, address payee);
3030
event TopUpSucceeded(address indexed recipient);
3131
event TopUpFailed(address indexed recipient);
32-
event KeeperRegistryAddressUpdated(address oldAddress, address newAddress);
32+
event ForwarderAddressUpdated(address oldAddress, address newAddress);
3333
event MinWaitPeriodUpdated(
3434
uint256 oldMinWaitPeriod,
3535
uint256 newMinWaitPeriod
3636
);
3737

3838
error InvalidWatchList();
39-
error OnlyKeeperRegistry();
39+
error OnlyForwarder();
4040
error DuplicateAddress(address duplicate);
4141

4242
struct Target {
@@ -46,20 +46,15 @@ contract EthBalanceMonitor is
4646
uint56 lastTopUpTimestamp; // enough space for 2 trillion years
4747
}
4848

49-
address private s_keeperRegistryAddress;
49+
address private s_forwarderAddress;
5050
uint256 private s_minWaitPeriodSeconds;
5151
address[] private s_watchList;
5252
mapping(address => Target) internal s_targets;
5353

5454
/**
55-
* @param keeperRegistryAddress The address of the Chainlink Automation registry contract
5655
* @param minWaitPeriodSeconds The minimum wait period for addresses between funding
5756
*/
58-
constructor(
59-
address keeperRegistryAddress,
60-
uint256 minWaitPeriodSeconds
61-
) ConfirmedOwner(msg.sender) {
62-
setKeeperRegistryAddress(keeperRegistryAddress);
57+
constructor(uint256 minWaitPeriodSeconds) ConfirmedOwner(msg.sender) {
6358
setMinWaitPeriodSeconds(minWaitPeriodSeconds);
6459
}
6560

@@ -193,7 +188,7 @@ contract EthBalanceMonitor is
193188
*/
194189
function performUpkeep(
195190
bytes calldata performData
196-
) external override onlyKeeperRegistry whenNotPaused {
191+
) external override onlyForwarder whenNotPaused {
197192
address[] memory needsFunding = abi.decode(performData, (address[]));
198193
topUp(needsFunding);
199194
}
@@ -220,17 +215,14 @@ contract EthBalanceMonitor is
220215
}
221216

222217
/**
223-
* @notice Sets the Chainlink Automation registry address
218+
* @notice Sets the upkeep's unique forwarder address
219+
* for upkeeps in Automation versions 2.0 and later
220+
* https://docs.chain.link/chainlink-automation/guides/forwarder
224221
*/
225-
function setKeeperRegistryAddress(
226-
address keeperRegistryAddress
227-
) public onlyOwner {
228-
require(keeperRegistryAddress != address(0));
229-
emit KeeperRegistryAddressUpdated(
230-
s_keeperRegistryAddress,
231-
keeperRegistryAddress
232-
);
233-
s_keeperRegistryAddress = keeperRegistryAddress;
222+
function setForwarderAddress(address forwarderAddress) public onlyOwner {
223+
require(forwarderAddress != address(0));
224+
emit ForwarderAddressUpdated(s_forwarderAddress, forwarderAddress);
225+
s_forwarderAddress = forwarderAddress;
234226
}
235227

236228
/**
@@ -242,14 +234,14 @@ contract EthBalanceMonitor is
242234
}
243235

244236
/**
245-
* @notice Gets the Chainlink Automation registry address
237+
* @notice Gets the forwarder address of the Chainlink Automation upkeep
246238
*/
247-
function getKeeperRegistryAddress()
239+
function getForwarderAddress()
248240
external
249241
view
250-
returns (address keeperRegistryAddress)
242+
returns (address forwarderAddress)
251243
{
252-
return s_keeperRegistryAddress;
244+
return s_forwarderAddress;
253245
}
254246

255247
/**
@@ -304,9 +296,9 @@ contract EthBalanceMonitor is
304296
_unpause();
305297
}
306298

307-
modifier onlyKeeperRegistry() {
308-
if (msg.sender != s_keeperRegistryAddress) {
309-
revert OnlyKeeperRegistry();
299+
modifier onlyForwarder() {
300+
if (msg.sender != s_forwarderAddress) {
301+
revert OnlyForwarder();
310302
}
311303
_;
312304
}

public/samples/Automation/tutorials/VRFSubscriptionBalanceMonitor.sol

+22-24
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// SPDX-License-Identifier: MIT
22

3-
pragma solidity 0.8.6;
3+
pragma solidity 0.8.20;
44

5+
import "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol";
56
import "@chainlink/contracts/src/v0.8/automation/interfaces/KeeperCompatibleInterface.sol";
6-
import {ConfirmedOwner} from "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol";
7-
import {VRFCoordinatorV2Interface} from "@chainlink/contracts/src/v0.8/vrf/interfaces/VRFCoordinatorV2Interface.sol";
8-
import {LinkTokenInterface} from "@chainlink/contracts/src/v0.8/shared/interfaces/LinkTokenInterface.sol";
9-
import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
7+
import "@chainlink/contracts/src/v0.8/vrf/interfaces/VRFCoordinatorV2Interface.sol";
8+
import "@chainlink/contracts/src/v0.8/shared/interfaces/LinkTokenInterface.sol";
9+
import "@openzeppelin/contracts/security/Pausable.sol";
1010

1111
/**
1212
* @title The VRFSubscriptionBalanceMonitor contract.
@@ -26,7 +26,7 @@ contract VRFSubscriptionBalanceMonitor is
2626
event FundsWithdrawn(uint256 amountWithdrawn, address payee);
2727
event TopUpSucceeded(uint64 indexed subscriptionId);
2828
event TopUpFailed(uint64 indexed subscriptionId);
29-
event KeeperRegistryAddressUpdated(address oldAddress, address newAddress);
29+
event ForwarderAddressUpdated(address oldAddress, address newAddress);
3030
event VRFCoordinatorV2AddressUpdated(
3131
address oldAddress,
3232
address newAddress
@@ -40,6 +40,7 @@ contract VRFSubscriptionBalanceMonitor is
4040

4141
error InvalidWatchList();
4242
error OnlyKeeperRegistry();
43+
error OnlyForwarder();
4344
error DuplicateSubcriptionId(uint64 duplicate);
4445

4546
struct Target {
@@ -49,26 +50,26 @@ contract VRFSubscriptionBalanceMonitor is
4950
uint56 lastTopUpTimestamp;
5051
}
5152

52-
address public s_keeperRegistryAddress; // the address of the keeper registry
53+
address public s_forwarderAddress; // the address of the upkeep's forwarder
5354
uint256 public s_minWaitPeriodSeconds; // minimum time to wait between top-ups
5455
uint64[] public s_watchList; // the watchlist on which subscriptions are stored
5556
mapping(uint64 => Target) internal s_targets;
5657

5758
/**
5859
* @param linkTokenAddress the Link token address
5960
* @param coordinatorAddress the address of the vrf coordinator contract
60-
* @param keeperRegistryAddress the address of the keeper registry contract
61+
* @param forwarderAddress the address of the upkeep's forwarder
6162
* @param minWaitPeriodSeconds the minimum wait period for addresses between funding
6263
*/
6364
constructor(
6465
address linkTokenAddress,
6566
address coordinatorAddress,
66-
address keeperRegistryAddress,
67+
address forwarderAddress,
6768
uint256 minWaitPeriodSeconds
6869
) ConfirmedOwner(msg.sender) {
6970
setLinkTokenAddress(linkTokenAddress);
7071
setVRFCoordinatorV2Address(coordinatorAddress);
71-
setKeeperRegistryAddress(keeperRegistryAddress);
72+
setForwarderAddress(forwarderAddress);
7273
setMinWaitPeriodSeconds(minWaitPeriodSeconds);
7374
}
7475

@@ -218,7 +219,7 @@ contract VRFSubscriptionBalanceMonitor is
218219
*/
219220
function performUpkeep(
220221
bytes calldata performData
221-
) external override onlyKeeperRegistry whenNotPaused {
222+
) external override onlyForwarder whenNotPaused {
222223
uint64[] memory needsFunding = abi.decode(performData, (uint64[]));
223224
topUp(needsFunding);
224225
}
@@ -261,17 +262,14 @@ contract VRFSubscriptionBalanceMonitor is
261262
}
262263

263264
/**
264-
* @notice Sets the keeper registry address.
265+
* @notice Sets the upkeep's unique forwarder address
266+
* for upkeeps in Automation versions 2.0 and later
267+
* https://docs.chain.link/chainlink-automation/guides/forwarder
265268
*/
266-
function setKeeperRegistryAddress(
267-
address keeperRegistryAddress
268-
) public onlyOwner {
269-
require(keeperRegistryAddress != address(0));
270-
emit KeeperRegistryAddressUpdated(
271-
s_keeperRegistryAddress,
272-
keeperRegistryAddress
273-
);
274-
s_keeperRegistryAddress = keeperRegistryAddress;
269+
function setForwarderAddress(address forwarderAddress) public onlyOwner {
270+
require(forwarderAddress != address(0));
271+
emit ForwarderAddressUpdated(s_forwarderAddress, forwarderAddress);
272+
s_forwarderAddress = forwarderAddress;
275273
}
276274

277275
/**
@@ -327,9 +325,9 @@ contract VRFSubscriptionBalanceMonitor is
327325
_unpause();
328326
}
329327

330-
modifier onlyKeeperRegistry() {
331-
if (msg.sender != s_keeperRegistryAddress) {
332-
revert OnlyKeeperRegistry();
328+
modifier onlyForwarder() {
329+
if (msg.sender != s_forwarderAddress) {
330+
revert OnlyForwarder();
333331
}
334332
_;
335333
}

0 commit comments

Comments
 (0)