Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: tx acceleration #5

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion contracts/SecretDelay.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ contract SecretDelay is Modifier {
bytes data,
Enum.Operation operation
);
event TransactionPromoted(uint256 indexed nonce);

uint256 public txCooldown;
uint256 public txExpiration;
uint256 public txNonce;
uint256 public queueNonce;
uint256 public approved;

// Mapping of queue nonce to transaction hash.
mapping(uint256 => bytes32) public txHash;
// Mapping of queue nonce to creation timestamp.
Expand Down Expand Up @@ -106,9 +109,26 @@ contract SecretDelay is Modifier {
function setTxNonce(uint256 _nonce) public onlyOwner {
require(_nonce > txNonce, "New nonce must be higher than current txNonce");
require(_nonce <= queueNonce, "Cannot be higher than queueNonce");

adjustApprovals(_nonce);
txNonce = _nonce;
}

function setTxNonceAndApprove(uint256 _nonce, uint256 _transactions)
public
onlyOwner
{
require(_nonce < queueNonce, "Cannot skip all transactions");
if (_nonce > txNonce) setTxNonce(_nonce);
approveNext(_transactions);
}

function approveNext(uint256 transactions) public onlyOwner {
require(transactions > 0, "Must approve at least one tx");
require(queueNonce - txNonce >= transactions, "Cannot approve unknown tx");
approved = transactions;
}

/// @dev Adds a transaction to the queue (same as avatar interface so that this can be placed between other modules and the avatar).
/// @param to Destination address of module transaction
/// @param value Ether value of module transaction
Expand Down Expand Up @@ -149,7 +169,7 @@ contract SecretDelay is Modifier {
) public {
require(txNonce < queueNonce, "Transaction queue is empty");
require(
block.timestamp - txCreatedAt[txNonce] >= txCooldown,
(block.timestamp - txCreatedAt[txNonce] >= txCooldown) || approved > 0,
"Transaction is still in cooldown"
);
if (txExpiration != 0) {
Expand All @@ -163,6 +183,7 @@ contract SecretDelay is Modifier {
"Transaction hashes do not match"
);
txNonce++;
if (approved > 0) approved--;
require(exec(to, value, data, operation), "Module transaction failed");
}

Expand Down Expand Up @@ -192,4 +213,14 @@ contract SecretDelay is Modifier {
function getTxCreatedAt(uint256 _nonce) public view returns (uint256) {
return (txCreatedAt[_nonce]);
}

function adjustApprovals(uint256 _nonce) internal {
uint256 delta = _nonce - txNonce;

if (delta > approved) {
if (approved != 0) approved = 0;
} else {
approved -= delta;
}
}
}
13 changes: 13 additions & 0 deletions contracts/test/TestContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity >=0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";

contract TestContract is Ownable {
event ButtonPushed(address pusher);

function pushButton() public onlyOwner {
emit ButtonPushed(msg.sender);
}
}
Loading