1
1
// SPDX-License-Identifier: MIT
2
2
3
- pragma solidity 0.8.6 ;
3
+ pragma solidity 0.8.20 ;
4
4
5
+ import "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol " ;
5
6
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 " ;
10
10
11
11
/**
12
12
* @title The VRFSubscriptionBalanceMonitor contract.
@@ -26,7 +26,7 @@ contract VRFSubscriptionBalanceMonitor is
26
26
event FundsWithdrawn (uint256 amountWithdrawn , address payee );
27
27
event TopUpSucceeded (uint64 indexed subscriptionId );
28
28
event TopUpFailed (uint64 indexed subscriptionId );
29
- event KeeperRegistryAddressUpdated (address oldAddress , address newAddress );
29
+ event ForwarderAddressUpdated (address oldAddress , address newAddress );
30
30
event VRFCoordinatorV2AddressUpdated (
31
31
address oldAddress ,
32
32
address newAddress
@@ -40,6 +40,7 @@ contract VRFSubscriptionBalanceMonitor is
40
40
41
41
error InvalidWatchList ();
42
42
error OnlyKeeperRegistry ();
43
+ error OnlyForwarder ();
43
44
error DuplicateSubcriptionId (uint64 duplicate );
44
45
45
46
struct Target {
@@ -49,26 +50,26 @@ contract VRFSubscriptionBalanceMonitor is
49
50
uint56 lastTopUpTimestamp;
50
51
}
51
52
52
- address public s_keeperRegistryAddress ; // the address of the keeper registry
53
+ address public s_forwarderAddress ; // the address of the upkeep's forwarder
53
54
uint256 public s_minWaitPeriodSeconds; // minimum time to wait between top-ups
54
55
uint64 [] public s_watchList; // the watchlist on which subscriptions are stored
55
56
mapping (uint64 => Target) internal s_targets;
56
57
57
58
/**
58
59
* @param linkTokenAddress the Link token address
59
60
* @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
61
62
* @param minWaitPeriodSeconds the minimum wait period for addresses between funding
62
63
*/
63
64
constructor (
64
65
address linkTokenAddress ,
65
66
address coordinatorAddress ,
66
- address keeperRegistryAddress ,
67
+ address forwarderAddress ,
67
68
uint256 minWaitPeriodSeconds
68
69
) ConfirmedOwner (msg .sender ) {
69
70
setLinkTokenAddress (linkTokenAddress);
70
71
setVRFCoordinatorV2Address (coordinatorAddress);
71
- setKeeperRegistryAddress (keeperRegistryAddress );
72
+ setForwarderAddress (forwarderAddress );
72
73
setMinWaitPeriodSeconds (minWaitPeriodSeconds);
73
74
}
74
75
@@ -218,7 +219,7 @@ contract VRFSubscriptionBalanceMonitor is
218
219
*/
219
220
function performUpkeep (
220
221
bytes calldata performData
221
- ) external override onlyKeeperRegistry whenNotPaused {
222
+ ) external override onlyForwarder whenNotPaused {
222
223
uint64 [] memory needsFunding = abi.decode (performData, (uint64 []));
223
224
topUp (needsFunding);
224
225
}
@@ -261,17 +262,14 @@ contract VRFSubscriptionBalanceMonitor is
261
262
}
262
263
263
264
/**
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
265
268
*/
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;
275
273
}
276
274
277
275
/**
@@ -327,9 +325,9 @@ contract VRFSubscriptionBalanceMonitor is
327
325
_unpause ();
328
326
}
329
327
330
- modifier onlyKeeperRegistry () {
331
- if (msg .sender != s_keeperRegistryAddress ) {
332
- revert OnlyKeeperRegistry ();
328
+ modifier onlyForwarder () {
329
+ if (msg .sender != s_forwarderAddress ) {
330
+ revert OnlyForwarder ();
333
331
}
334
332
_;
335
333
}
0 commit comments