Solidity

動態供應連結給chainlink upkeeper

  • December 25, 2021

我在多邊形上創建了一個簡單的鏈環維護任務:

import "@chainlink/contracts/src/v0.7/KeeperCompatible.sol";

contract Counter is KeeperCompatibleInterface {
   /**
   * Public counter variable
   */
   uint public counter;

   /**
   * Use an interval in seconds and a timestamp to slow execution of Upkeep
   */
   uint public immutable interval;
   uint public lastTimeStamp;

   constructor(uint updateInterval) {
   interval = updateInterval;
   lastTimeStamp = block.timestamp;

   counter = 0;
   }

   function checkUpkeep(bytes calldata /* checkData */) external override returns (bool upkeepNeeded, bytes memory /* performData */) {
       upkeepNeeded = (block.timestamp - lastTimeStamp) > interval;
       // We don't use the checkData in this example. The checkData is defined when the Upkeep was registered.
   }

   function performUpkeep(bytes calldata /* performData */) external override {
       lastTimeStamp = block.timestamp;
       counter = counter + 1;
       // We don't use the performData in this example. The performData is generated by the Keeper's call to your checkUpkeep function
   }
}

我最初為它提供了 5 個連結,我希望我的應用程序完全分散,如何動態地為 keeper 提供更多連結?

這可以使用 keeper 系統資料庫基本介面來完成。這是一個概念證明,一旦我開始工作,我就停止優化它。

interface IERC20 {

function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);

function transferFrom(
   address sender,
   address recipient,
   uint256 amount
) external returns (bool);

event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}

interface IKeeperRegistry {
function registerUpkeep(
   address target,
   uint32 gasLimit,
   address admin,
   bytes calldata checkData
) external returns (uint256 id);

function performUpkeep(uint256 id, bytes calldata performData) external returns (bool success);

function cancelUpkeep(uint256 id) external;

function addFunds(uint256 id, uint96 amount) external;
}

contract KeeperManager {

   //Default is Mumbai TestNet 0x6179B349067af80D0c171f43E6d767E4A00775Cd
   address public KeeperRegistry;
   address public Target;
   address public chainlinkToken;
   address owner;
   uint256 public upkeepId;
   IKeeperRegistry _keeperRegistry;

   // chain link token address 0x326c977e6efc84e512bb9c30f76e30c160ed06fb
   constructor(address keeperRegistry, address target, address chainlink) {
       KeeperRegistry = keeperRegistry;
       Target = target;
       owner = msg.sender;
       chainlinkToken = chainlink;
       _keeperRegistry = IKeeperRegistry(keeperRegistry);

   }

   function supply(uint256 upkeepId, uint96 amount) external {
       IERC20(chainlinkToken).approve(KeeperRegistry, amount);
       _keeperRegistry.addFunds(upkeepId, amount);
   }
}

引用自:https://ethereum.stackexchange.com/questions/117133