Skip to content

Commit 32be40d

Browse files
Some updates
1 parent 44881b5 commit 32be40d

File tree

4 files changed

+51
-40
lines changed

4 files changed

+51
-40
lines changed

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/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
}

src/content/quickstarts/eth-balance-monitor.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Before you start this tutorial, complete the following items:
5454

5555
<Accordion title="Configure the address watch list" number={2}>
5656

57-
Before your contract will fund an address, you must set the `watchList` address array with `minBalancesWei` and `topUpAmmountsWei` variables. For demonstration purposes, you configure your own wallet as the top-up address. This makes it easy to see the ETH being sent as part of the automated top-up function. After you complete this tutorial, you can configure any wallet or contract address that you want to keep funded.
57+
Before your contract will fund an address, you must set the `watchList` address array with `minBalancesWei` and `topUpAmountsWei` variables. For demonstration purposes, you configure your own wallet as the top-up address. This makes it easy to see the ETH being sent as part of the automated top-up function. After you complete this tutorial, you can configure any wallet or contract address that you want to keep funded.
5858

5959
1. In the list of functions for your deployed contract, run the `setWatchList` function. This function requires an `addresses` array, a `minBalancesWei` array that maps to the addresses, and a `topUpAmountsWei` array that also maps to the addresses. In Remix, arrays require brackets and quotes around both addresses and integer values. For this example, set the following values:
6060

@@ -104,7 +104,7 @@ The upkeep runs the `checkUpkeep` function in your contract, which checks the ba
104104

105105
1. Go to [automation.chain.link](https://automation.chain.link/), view your new upkeep, and confirm that it is performing upkeeps in the **History** list.
106106

107-
1. View your contract address and your wallet address at [mumbai.polygonscan.com](https://mumbai.polygonscan.com/) to see the transactions happening between your contract and your wallet address.
107+
1. View your contract address and your wallet address at the [Sepolia block explorer](https://sepolia.etherscan.io/) to see the transactions happening between your contract and your wallet address.
108108

109109
The example continues to run until your upkeep runs out of LINK, your contract runs out of ETH, or until you manually pause or cancel the upkeep.
110110

src/content/quickstarts/giveaway.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ Set environment variables to run the UI and then view it locally.
235235
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
236236
| `UI_GIVEAWAY_MANAGER_CONTRACT_ADDRESS` | The address of the Giveaway Contract Manager contract that you [deployed earlier](#deploy-contract) |
237237
| `UI_LINK_TOKEN_CONTRACT_ADDRESS` | For Ethereum Sepolia: <CopyText text="0x779877A7B0D9E8603169DdbD7836e478b4624789" code/> <br/> See all [LINK token contract addresses](/resources/link-token-contracts) |
238-
| `UI_KEEPER_REGISTRY_CONTRACT_ADDRESS` | For Ethereum Sepolia: <CopyText text="0x86EFBD0b6736Bed994962f9797049422A3A8E8Ad" code/> <br/> This app currently supports Automation v1.2. See all [Automation registry contract addresses](/chainlink-automation/overview/supported-networks/) |
238+
| `UI_KEEPER_REGISTRY_CONTRACT_ADDRESS` | For Ethereum Sepolia: <CopyText text="0xE16Df59B887e3Caa439E0b29B42bA2e7976FD8b2" code/> <br/> This app currently supports Automation v1.2. See all [Automation registry contract addresses](/chainlink-automation/overview/supported-networks/) |
239239

240240
1. Navigate to the `/client/packages/ui` directory, and run these commands to set up your UI environment variables. Do not use quotes to assign values:
241241
```bash
242242
# <root>/client/packages/ui
243243
export UI_GIVEAWAY_MANAGER_CONTRACT_ADDRESS=
244-
export UI_LINK_TOKEN_CONTRACT_ADDRESS=
245-
export UI_KEEPER_REGISTRY_CONTRACT_ADDRESS=
244+
export UI_LINK_TOKEN_CONTRACT_ADDRESS=0x779877A7B0D9E8603169DdbD7836e478b4624789
245+
export UI_KEEPER_REGISTRY_CONTRACT_ADDRESS=0xE16Df59B887e3Caa439E0b29B42bA2e7976FD8b2
246246
```
247247
1. After setting the environment variables, run the UI locally:
248248
```bash

src/content/quickstarts/vrf-subscription-monitor.mdx

+24-11
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,35 @@ Registering an upkeep on Chainlink Automation creates a smart contract that will
163163

164164
1. Click **Register new Upkeep**.
165165

166-
1. Select the _Custom logic_ trigger.
166+
1. Select the _Custom logic_ trigger option.
167167

168-
1. Input the address of your deployed subscription balance monitor contract.
168+
1. Copy your contract address from Remix and paste it into the **Target contract address** field.
169169

170-
1. Get the ABI from Remix.
170+
1. Specify a name for your upkeep and set a **Starting balance** of 5 LINK for this demo. Leave the other settings at their default values.
171171

172-
1. Enter the values for the constructor.
172+
1. Go to the **Upkeep details** page and copy your **Forwarder address**.
173173

174-
| Item | Value |
175-
| ----------------------- | ------------------------------------------------------------------ |
176-
| `LINKTOKENADDRESS` | <CopyText text="0x779877A7B0D9E8603169DdbD7836e478b4624789" code/> |
177-
| `COORDINATORADDRESS` | <CopyText text="0x8103B0A8A00be2DDC778e6e7eaa21791Cd364625" code/> |
178-
| `KEEPERREGISTRYADDRESS` | <CopyText text="0xE16Df59B887e3Caa439E0b29B42bA2e7976FD8b2" code/> |
179-
| `MINWAITPERIODSECONDS` | <CopyText text="60" code/> |
174+
1. Navigate back to Remix and find the `setForwarderAddress` function. Paste your forwarder address and click click **transact** to run the function. MetaMask asks you to confirm the transaction.
175+
176+
Now that you've registered the upkeep and configured your contract with your new upkeep's forwarder address, Chainlink Automation handles the rest of the process.
177+
178+
</Accordion>
179+
180+
<Accordion title="Configure the subscription watch list" number={5}>
181+
182+
Before your contract will fund a subscription, you must set the `watchList` address array with `minBalancesJuels` and `topUpAmountsJuels` variables. For demonstration purposes, you configure your own wallet as the top-up address. This makes it easy to see the ETH being sent as part of the automated top-up function. After you complete this tutorial, you can configure any wallet or contract address that you want to keep funded.
183+
184+
1. In the list of functions for your deployed contract, run the `setWatchList` function. This function requires an `subscriptionIds` array, a `minBalancesJuels` array that maps to the subscriptions, and a `topUpAmountsJuels` array that also maps to the subscriptions. In Remix, arrays require brackets and quotes around integer values. For this example, set the following values:
185+
186+
- **subscriptionIds**: `["SUB_ID_1", "SUB_ID_2"]`
187+
- **minBalancesJuels**: `["2000000000000000000"]`
188+
- **topUpAmountsJuels**: `["10000000000000000"]`
189+
190+
These values tell the top up contract to top up the specified address with 0.01 LINK if the address balance is less than 2 LINK. These settings are intended to demonstrate the example using testnet faucet funds. For a production application, you might set more reasonable values that top up a smart contract with 10 LINK if the balance is less than 1 LINK.
191+
192+
1. After you configure the function values, click **transact** to run the function. MetaMask asks you to confirm the transaction.
180193

181-
1. Fund the upkeep with enough LINK to monitor your VRF subscriptions.
194+
1. In the functions list, click the `getWatchList` function to confirm your settings are correct.
182195

183196
</Accordion>
184197

0 commit comments

Comments
 (0)