1

We are looking to have performUpkeep run until the wallet balanace hits 0 on a set of Chainlink Keepers.

We managed to try out an error-less execute on remix with a plausible syntax. However would still like to know if the solution is right or over-engineered.


// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;

interface KeeperCompatibleInterface {
    function checkUpkeep(bytes calldata checkData) external returns (bool upkeepNeeded, bytes memory performData);
    function performUpkeep(bytes calldata performData) external;
}

contract Counter is KeeperCompatibleInterface {

    uint public counter;    // Public counter variable

    // 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 view override returns (bool upkeepNeeded, bytes memory performData) {
        upkeepNeeded = (block.timestamp - lastTimeStamp) > interval;
        performData = checkData;
    }

    function balance() public view returns (uint256) {
        return address(this).balance;

    }

    function performUpkeep(bytes calldata) external override {
        lastTimeStamp = block.timestamp;
        require(address(this).balance > 0);
       
    }

}
1
  • Hi. When asking questions if you keep them minimalistic. I'll answer this question at face value, but please update your question to resemble the minimalistic question you have. Take a read here on how to ask a well-formatted question: stackoverflow.com/help/how-to-ask Dec 15 '21 at 20:20
1

If you want an upkeep to occur untill the balance reaches 0, you'd need to quantify so in the checkUpkeep and performUpkeep, for example:

    function checkBalance() public view returns(bool){
        return address(this).balance >= 0;
    } 
    function checkUpkeep(bytes calldata /** checkData **/ ) external view override returns (bool upkeepNeeded, bytes memory performData) {
        upkeepNeeded = checkBalance();
    }

    function performUpkeep(bytes calldata) external override {
        require(checkBalance(), "Balance not 0");
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.