Skip to content

Latest commit

 

History

History
788 lines (635 loc) · 22.5 KB

Timelock.md

File metadata and controls

788 lines (635 loc) · 22.5 KB

Timelock.sol

View Source: contracts/governance/Timelock.sol

↗ Extends: ErrorDecoder, ITimelock ↘ Derived Contracts: Administered, TimelockHarness

Timelock contract

Contract Members

Constants & Variables

uint256 public constant GRACE_PERIOD;
uint256 public constant MINIMUM_DELAY;
uint256 public constant MAXIMUM_DELAY;
address public admin;
address public pendingAdmin;
uint256 public delay;
mapping(bytes32 => bool) public queuedTransactions;

Events

event NewAdmin(address indexed newAdmin);
event NewPendingAdmin(address indexed newPendingAdmin);
event NewDelay(uint256 indexed newDelay);
event CancelTransaction(bytes32 indexed txHash, address indexed target, uint256  value, string  signature, bytes  data, uint256  eta);
event ExecuteTransaction(bytes32 indexed txHash, address indexed target, uint256  value, string  signature, bytes  data, uint256  eta);
event QueueTransaction(bytes32 indexed txHash, address indexed target, uint256  value, string  signature, bytes  data, uint256  eta);

Functions


delay

function delay() external view
returns(uint256)
Source Code
function delay() external view returns (uint256);

GRACE_PERIOD

function GRACE_PERIOD() external view
returns(uint256)
Source Code
function GRACE_PERIOD() external view returns (uint256);

acceptAdmin

⤿ Overridden Implementation(s): ITimelock.acceptAdmin,Timelock.acceptAdmin

function acceptAdmin() external nonpayable
Source Code
function acceptAdmin() external;

queuedTransactions

function queuedTransactions(bytes32 hash) external view
returns(bool)

Arguments

Name Type Description
hash bytes32
Source Code
function queuedTransactions(bytes32 hash) external view returns (bool);

queueTransaction

⤿ Overridden Implementation(s): ITimelock.queueTransaction,Timelock.queueTransaction

function queueTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) external nonpayable
returns(bytes32)

Arguments

Name Type Description
target address
value uint256
signature string
data bytes
eta uint256
Source Code
function queueTransaction(
        address target,
        uint256 value,
        string calldata signature,
        bytes calldata data,
        uint256 eta
    ) external returns (bytes32);

cancelTransaction

⤿ Overridden Implementation(s): ITimelock.cancelTransaction,Timelock.cancelTransaction

function cancelTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) external nonpayable

Arguments

Name Type Description
target address
value uint256
signature string
data bytes
eta uint256
Source Code
function cancelTransaction(
        address target,
        uint256 value,
        string calldata signature,
        bytes calldata data,
        uint256 eta
    ) external;

executeTransaction

⤿ Overridden Implementation(s): ITimelock.executeTransaction,Timelock.executeTransaction

function executeTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) external payable
returns(bytes)

Arguments

Name Type Description
target address
value uint256
signature string
data bytes
eta uint256
Source Code
function executeTransaction(
        address target,
        uint256 value,
        string calldata signature,
        bytes calldata data,
        uint256 eta
    ) external payable returns (bytes memory);

constructor

Function called on instance deployment of the contract.

function (address admin_, uint256 delay_) public nonpayable

Arguments

Name Type Description
admin_ address Governance contract address.
delay_ uint256 Time to wait for queued transactions to be executed.
Source Code
tor(address admin_, uint256 delay_) public {
        require(
            delay_ >= MINIMUM_DELAY,
            "Timelock::constructor: Delay must exceed minimum delay."
        );
        require(
            delay_ <= MAXIMUM_DELAY,
            "Timelock::setDelay: Delay must not exceed maximum delay."
        );

        admin = admin_;
        delay = delay_;
    }

    /*

constructor

Fallback function is to react to receiving value (rBTC).

function () external payable
Source Code
() external payable {}

    /*

setDelay

Set a new delay when executing the contract calls.

function setDelay(uint256 delay_) public nonpayable

Arguments

Name Type Description
delay_ uint256 The amount of time to wait until execution.
Source Code
 setDelay(uint256 delay_) public {
        require(msg.sender == address(this), "Timelock::setDelay: Call must come from Timelock.");
        require(delay_ >= MINIMUM_DELAY, "Timelock::setDelay: Delay must exceed minimum delay.");
        require(
            delay_ <= MAXIMUM_DELAY,
            "Timelock::setDelay: Delay must not exceed maximum delay."
        );
        delay = delay_;

        emit NewDelay(delay);
    }

    /*

acceptAdmin

⤾ overrides ITimelock.acceptAdmin

Accept a new admin for the timelock.

function acceptAdmin() public nonpayable
Source Code
 acceptAdmin() public {
        require(
            msg.sender == pendingAdmin,
            "Timelock::acceptAdmin: Call must come from pendingAdmin."
        );
        admin = msg.sender;
        pendingAdmin = address(0);

        emit NewAdmin(admin);
    }

    /*

setPendingAdmin

Set a new pending admin for the timelock.

function setPendingAdmin(address pendingAdmin_) public nonpayable

Arguments

Name Type Description
pendingAdmin_ address The new pending admin address.
Source Code
 setPendingAdmin(address pendingAdmin_) public {
        require(
            msg.sender == address(this),
            "Timelock::setPendingAdmin: Call must come from Timelock."
        );
        pendingAdmin = pendingAdmin_;

        emit NewPendingAdmin(pendingAdmin);
    }

    /*

queueTransaction

⤾ overrides ITimelock.queueTransaction

Queue a new transaction from the governance contract.

function queueTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) public nonpayable
returns(bytes32)

Arguments

Name Type Description
target address The contract to call.
value uint256 The amount to send in the transaction.
signature string The stanndard representation of the function called.
data bytes The ethereum transaction input data payload.
eta uint256 Estimated Time of Accomplishment. The timestamp that the proposal will be available for execution, set once the vote succeeds.
Source Code
 queueTransaction(
        address target,
        uint256 value,
        string memory signature,
        bytes memory data,
        uint256 eta
    ) public returns (bytes32) {
        require(msg.sender == admin, "Timelock::queueTransaction: Call must come from admin.");
        require(
            eta >= getBlockTimestamp().add(delay),
            "Timelock::queueTransaction: Estimated execution block must satisfy delay."
        );

        bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
        queuedTransactions[txHash] = true;

        emit QueueTransaction(txHash, target, value, signature, data, eta);
        return txHash;
    }

    /*

cancelTransaction

⤾ overrides ITimelock.cancelTransaction

Cancel a transaction.

function cancelTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) public nonpayable

Arguments

Name Type Description
target address The contract to call.
value uint256 The amount to send in the transaction.
signature string The stanndard representation of the function called.
data bytes The ethereum transaction input data payload.
eta uint256 Estimated Time of Accomplishment. The timestamp that the proposal will be available for execution, set once the vote succeeds.
Source Code
 cancelTransaction(
        address target,
        uint256 value,
        string memory signature,
        bytes memory data,
        uint256 eta
    ) public {
        require(msg.sender == admin, "Timelock::cancelTransaction: Call must come from admin.");

        bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
        queuedTransactions[txHash] = false;

        emit CancelTransaction(txHash, target, value, signature, data, eta);
    }

    /*

executeTransaction

⤾ overrides ITimelock.executeTransaction

Executes a previously queued transaction from the governance.

function executeTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) public payable
returns(bytes)

Arguments

Name Type Description
target address The contract to call.
value uint256 The amount to send in the transaction.
signature string The stanndard representation of the function called.
data bytes The ethereum transaction input data payload.
eta uint256 Estimated Time of Accomplishment. The timestamp that the proposal will be available for execution, set once the vote succeeds.
Source Code
 executeTransaction(
        address target,
        uint256 value,
        string memory signature,
        bytes memory data,
        uint256 eta
    ) public payable returns (bytes memory) {
        require(msg.sender == admin, "Timelock::executeTransaction: Call must come from admin.");

        bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
        require(
            queuedTransactions[txHash],
            "Timelock::executeTransaction: Transaction hasn't been queued."
        );
        require(
            getBlockTimestamp() >= eta,
            "Timelock::executeTransaction: Transaction hasn't surpassed time lock."
        );
        require(
            getBlockTimestamp() <= eta.add(GRACE_PERIOD),
            "Timelock::executeTransaction: Transaction is stale."
        );

        queuedTransactions[txHash] = false;

        bytes memory callData;

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

        // solium-disable-next-line security/no-call-value
        (bool success, bytes memory returnData) = target.call.value(value)(callData);
        if (!success) {
            if (returnData.length <= ERROR_MESSAGE_SHIFT) {
                revert("Timelock::executeTransaction: Transaction execution reverted.");
            } else {
                revert(_addErrorMessage("Timelock::executeTransaction: ", string(returnData)));
            }
        }

        emit ExecuteTransaction(txHash, target, value, signature, data, eta);

        return returnData;
    }

    /*

getBlockTimestamp

A function used to get the current Block Timestamp.

function getBlockTimestamp() internal view
returns(uint256)
Source Code
 getBlockTimestamp() internal view returns (uint256) {
        // solium-disable-next-line security/no-block-members
        return block.timestamp;
    }
}

Contracts