Skip to content

Commit

Permalink
Updates QS to use Sepolia and Automation forwarder (#1894)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
thedriftofwords and dwightjl authored Apr 29, 2024
1 parent d0819ba commit 70335f5
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 112 deletions.
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const config: HardhatUserConfig = {
{ version: "0.8.6" },
{ version: "0.8.16" },
{ version: "0.8.19" },
{ version: "0.8.20" },
],
},
}
Expand Down
52 changes: 22 additions & 30 deletions public/samples/Automation/tutorials/EthBalanceMonitor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

pragma solidity ^0.8.7;

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

/**
* @title The EthBalanceMonitor contract
Expand All @@ -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 {
Expand All @@ -46,20 +46,15 @@ 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 minWaitPeriodSeconds The minimum wait period for addresses between funding
*/
constructor(
address keeperRegistryAddress,
uint256 minWaitPeriodSeconds
) ConfirmedOwner(msg.sender) {
setKeeperRegistryAddress(keeperRegistryAddress);
constructor(uint256 minWaitPeriodSeconds) ConfirmedOwner(msg.sender) {
setMinWaitPeriodSeconds(minWaitPeriodSeconds);
}

Expand Down Expand Up @@ -193,7 +188,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);
}
Expand All @@ -220,17 +215,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;
}

/**
Expand All @@ -242,14 +234,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;
}

/**
Expand Down Expand Up @@ -304,9 +296,9 @@ contract EthBalanceMonitor is
_unpause();
}

modifier onlyKeeperRegistry() {
if (msg.sender != s_keeperRegistryAddress) {
revert OnlyKeeperRegistry();
modifier onlyForwarder() {
if (msg.sender != s_forwarderAddress) {
revert OnlyForwarder();
}
_;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// 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";
import {ConfirmedOwner} from "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol";
import {VRFCoordinatorV2Interface} from "@chainlink/contracts/src/v0.8/vrf/interfaces/VRFCoordinatorV2Interface.sol";
import {LinkTokenInterface} from "@chainlink/contracts/src/v0.8/shared/interfaces/LinkTokenInterface.sol";
import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
import "@chainlink/contracts/src/v0.8/vrf/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/shared/interfaces/LinkTokenInterface.sol";
import "@openzeppelin/contracts/security/Pausable.sol";

/**
* @title The VRFSubscriptionBalanceMonitor contract.
Expand All @@ -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
Expand All @@ -40,6 +40,7 @@ contract VRFSubscriptionBalanceMonitor is

error InvalidWatchList();
error OnlyKeeperRegistry();
error OnlyForwarder();
error DuplicateSubcriptionId(uint64 duplicate);

struct Target {
Expand All @@ -49,26 +50,26 @@ 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;

/**
* @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);
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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();
}
_;
}
Expand Down
Loading

0 comments on commit 70335f5

Please sign in to comment.