0

I would like to make a task queue in solidity

contract Task{
  function shouldExecute() external view returns (bool) {

  }

  //function Execute() 
}

I would like to be able to dynamically pop conditions into this object to be checked e.g store simple functions in byte code like address(this).balance > 1e18

so in practice it would look some thing like

// Create a new task, if the target address balance is greater than a token, call the
// 'ClaimBalance' function on the target address
new Task(targetAddress,abi.ToBytes(`address(targetAddress).balance > 1e18`), 'ClaimBalance')  

is there a way I can do this dynamically or will I have to manually make factories for all the options I would like to execute?

1 Answer 1

0

If the contract knows what logic it needs to do, why can't it do it? This is not really the way to do things on the chain. Compound Governance does something like this, but it's a little different. See GovernorBravoDelegate.proposeInternal. The user specifies:

address[] memory  targets,
uint[]    memory  values,
string[]  memory  signatures,
bytes[]   memory  calldatas,

They hash these because they don't want to pay to store these on chain. If a proposal passes and the timelock delay is over, a user can execute the specified calls by providing the exact parameters again, which are then dispatched through the execute function, which passes execution to Timelock.executeTransaction.

function executeTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public payable returns (bytes memory) {
        // ... skipping the checks

        bytes memory callData;

        if (bytes(signature).length == 0) {
            callData = data;
        } else {
            callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data);
        }

        (bool success, bytes memory returnData) = target.call{value: value}(callData);
        require(success, "Timelock::executeTransaction: Transaction execution reverted.");
        
        // ...

        return returnData;
    }

But again, I would think hard about how you want to do this. Storing things on chain is expensive. Creating a dynamic array of call data is just not how I would go about solving your problem, whatever it may be.

1
  • I'm aware this would work but I'm pretty sure I saw somewhere you can pass raw delegates as byte code,
    – johnny 5
    Commented Dec 27, 2023 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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