@@ -5,26 +5,20 @@ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
55import {IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol " ;
66import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol " ;
77import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol " ;
8- import {StableEnumerableSet} from "./libraries/StableEnumerableSet.sol " ;
8+ import {StableEnumerableSet} from ".. /libraries/StableEnumerableSet.sol " ;
99import {Log} from "@chainlink/contracts/src/v0.8/automation/interfaces/ILogAutomation.sol " ;
10- import {IVoter} from "../../vendor/velodrome-contracts/contracts/interfaces/IVoter.sol " ;
11- import {IKeeperRegistryMaster} from "@chainlink/contracts/src/v0.8/automation/interfaces/v2_1/IKeeperRegistryMaster.sol " ;
12- import {IAutomationRegistrarV2_1} from "../interfaces/v2_1/IAutomationRegistrarV2_1.sol " ;
13- import {IUpkeepBalanceMonitor} from "../interfaces/IUpkeepBalanceMonitor.sol " ;
14- import {IPrices} from "./interfaces/IPrices.sol " ;
15- import {TokenUpkeep} from "./TokenUpkeep.sol " ;
16- import {ITokenUpkeepManager} from "./interfaces/ITokenUpkeepManager.sol " ;
17-
18- contract TokenUpkeepManager is ITokenUpkeepManager , Ownable {
10+ import {IVoter} from "../../../vendor/velodrome-contracts/contracts/interfaces/IVoter.sol " ;
11+ import {IPrices} from "../interfaces/IPrices.sol " ;
12+ import {ITokenUpkeepManager} from "../interfaces/common/ITokenUpkeepManager.sol " ;
13+
14+ abstract contract TokenUpkeepManager is ITokenUpkeepManager , Ownable {
1915 using SafeERC20 for IERC20 ;
2016 using StableEnumerableSet for StableEnumerableSet.AddressSet;
2117 using EnumerableSet for EnumerableSet.UintSet;
2218
2319 /// @inheritdoc ITokenUpkeepManager
2420 address public immutable override linkToken;
2521 /// @inheritdoc ITokenUpkeepManager
26- address public immutable override keeperRegistry;
27- /// @inheritdoc ITokenUpkeepManager
2822 address public immutable override automationRegistrar;
2923 /// @inheritdoc ITokenUpkeepManager
3024 address public immutable override voter;
@@ -50,18 +44,17 @@ contract TokenUpkeepManager is ITokenUpkeepManager, Ownable {
5044 uint256 [] public override upkeepIds;
5145
5246 StableEnumerableSet.AddressSet internal _tokenList;
53- EnumerableSet.UintSet private _cancelledUpkeepIds;
47+ EnumerableSet.UintSet internal _cancelledUpkeepIds;
5448
55- uint256 private constant TOKENS_PER_UPKEEP = 100 ;
56- uint256 private constant UPKEEP_CANCEL_BUFFER = 20 ;
57- uint8 private constant CONDITIONAL_TRIGGER_TYPE = 0 ;
58- string private constant UPKEEP_NAME = "Token upkeep " ;
49+ uint256 internal constant TOKENS_PER_UPKEEP = 100 ;
50+ uint256 internal constant UPKEEP_CANCEL_BUFFER = 20 ;
51+ uint8 internal constant CONDITIONAL_TRIGGER_TYPE = 0 ;
52+ string internal constant UPKEEP_NAME = "Token upkeep " ;
5953
6054 bytes32 private constant WHITELIST_TOKEN_EVENT = 0x44948130cf88523dbc150908a47dd6332c33a01a3869d7f2fa78e51d5a5f9c57 ;
6155
6256 constructor (
6357 address _linkToken ,
64- address _keeperRegistry ,
6558 address _automationRegistrar ,
6659 address _voter ,
6760 address _pricesOracle ,
@@ -70,7 +63,6 @@ contract TokenUpkeepManager is ITokenUpkeepManager, Ownable {
7063 uint32 _newUpkeepGasLimit
7164 ) {
7265 linkToken = _linkToken;
73- keeperRegistry = _keeperRegistry;
7466 automationRegistrar = _automationRegistrar;
7567 voter = _voter;
7668 pricesOracle = _pricesOracle;
@@ -337,51 +329,11 @@ contract TokenUpkeepManager is ITokenUpkeepManager, Ownable {
337329 emit TokenDeregistered (_token);
338330 }
339331
340- function _registerTokenUpkeep () internal {
341- uint256 startIndex = _getNextUpkeepStartIndex (upkeepIds.length );
342- uint256 endIndex = startIndex + TOKENS_PER_UPKEEP;
343- address _tokenUpkeep = address (new TokenUpkeep (startIndex, endIndex));
344- isTokenUpkeep[_tokenUpkeep] = true ;
345- IAutomationRegistrarV2_1.RegistrationParams memory params = IAutomationRegistrarV2_1.RegistrationParams ({
346- name: UPKEEP_NAME,
347- encryptedEmail: "" ,
348- upkeepContract: _tokenUpkeep,
349- gasLimit: newUpkeepGasLimit,
350- adminAddress: address (this ),
351- triggerType: CONDITIONAL_TRIGGER_TYPE,
352- checkData: "" ,
353- triggerConfig: "" ,
354- offchainConfig: "" ,
355- amount: newUpkeepFundAmount
356- });
357- uint256 upkeepId = _registerUpkeep (params);
358- upkeepIds.push (upkeepId);
359- tokenUpkeep[upkeepId] = _tokenUpkeep;
360- address forwarder = IKeeperRegistryMaster (keeperRegistry).getForwarder (upkeepId);
361- TokenUpkeep (_tokenUpkeep).setTrustedForwarder (forwarder);
362- IUpkeepBalanceMonitor (upkeepBalanceMonitor).addToWatchList (upkeepId);
363- emit TokenUpkeepRegistered (_tokenUpkeep, upkeepId, startIndex, endIndex);
364- }
332+ function _registerTokenUpkeep () internal virtual ;
365333
366- function _registerUpkeep (IAutomationRegistrarV2_1.RegistrationParams memory _params ) internal returns (uint256 ) {
367- IERC20 (linkToken).safeIncreaseAllowance (automationRegistrar, _params.amount);
368- uint256 upkeepID = IAutomationRegistrarV2_1 (automationRegistrar).registerUpkeep (_params);
369- if (upkeepID != 0 ) {
370- return upkeepID;
371- } else {
372- revert AutoApproveDisabled ();
373- }
374- }
334+ function _cancelTokenUpkeep (uint256 _upkeepId ) internal virtual ;
375335
376- function _cancelTokenUpkeep (uint256 _upkeepId ) internal {
377- upkeepIds.pop ();
378- delete isTokenUpkeep[tokenUpkeep[_upkeepId]];
379- delete tokenUpkeep[_upkeepId];
380- _cancelledUpkeepIds.add (_upkeepId);
381- IUpkeepBalanceMonitor (upkeepBalanceMonitor).removeFromWatchList (_upkeepId);
382- IKeeperRegistryMaster (keeperRegistry).cancelUpkeep (_upkeepId);
383- emit TokenUpkeepCancelled (_upkeepId);
384- }
336+ function _withdrawUpkeep (uint256 _upkeepId ) internal virtual ;
385337
386338 function _finishUpkeepAndCleanup (uint256 _lastRun ) internal {
387339 finishedUpkeeps[_lastRun]++ ;
@@ -395,12 +347,6 @@ contract TokenUpkeepManager is ITokenUpkeepManager, Ownable {
395347 emit TokenListCleaned ();
396348 }
397349
398- function _withdrawUpkeep (uint256 _upkeepId ) internal {
399- _cancelledUpkeepIds.remove (_upkeepId);
400- IKeeperRegistryMaster (keeperRegistry).withdrawFunds (_upkeepId, address (this ));
401- emit TokenUpkeepWithdrawn (_upkeepId);
402- }
403-
404350 function _getNextUpkeepStartIndex (uint256 _upkeepCount ) internal pure returns (uint256 ) {
405351 return _upkeepCount * TOKENS_PER_UPKEEP;
406352 }
0 commit comments