Intercoin / ControlContract

Lets a community collectively manage a wallet and tokens, including enforcing limits and lockups.
https://intercoin.org
GNU Affero General Public License v3.0
0 stars 3 forks source link

Implement delays (timelocks) #11

Closed EGreg closed 4 months ago

EGreg commented 1 year ago

In params, add uint32 delay which is the number of seconds to delay since executing "this line":https://github.com/Intercoin/ControlContract/blob/a800a4c8f56b321d5e90407a69035981de1b62d5/contracts/ControlContract.sol#L568

Please emit OperationScheduled right before OperationExecuted, if delay = 0.

Otherwise if delay > 0 then push this operation to the operations array, and emit OperationScheduled only.

I didn't find anything in OpenZeppelin to have an array with "from" and "to" indexes. You can make a class struct Array struct ArrayWindowwhich can have uint32 startIndex, uint32 endIndex, andwindow.push()andwindow.unshift(). Arrays are really stored as mapping. Thewindow.push(value)will simply storewindow[++endIndex] = valuewhileunshift()willdelete window[startIndex++]` (notice that startIndex is incremented after being evaluated, for clarity you can break it out into two different statements). Anyway, so Operation Scheduled will push the operation.

Meanwhile, anyone can call executeNextOperation() which will var operationId = operations.unshift() and then execute this operation, and emit OperationExecuted. The delete will even save some gas.

So basically, refactor into _executeOperation() which may be called immediately if delay = 0 otherwise from executeNextOperation().

Since delay is the same for the whole contract, the operations would always be executed in order! But with a delay.

artman325 commented 4 months ago

This task is about delays, not about the order of executions with delays.

I suggest adding a new method, invoke, with a parameter uint64 delay (defaulting to 0).

function invoke(
    address contractAddress,
    string memory method,
    string memory params,
    uint64 delay
)

The behavior will remain the same. The invoked operation will execute after exceeding the necessary enforced operations. However, if delay != 0, the operation can execute only after the specified delay.

There are no schedules. We cannot wait for a previous operation that might get stuck.

[upd] it would be method addMethod, not invoke

artman325 commented 4 months ago

seems workflow are:

Would be great if invoke can be called with different /minimums/fraction/delay for the same contract/method/params