@venusprotocol/governance-contracts 1.4.0-dev.2 → 1.4.0-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +1 -1
- package/artifacts/build-info/5c939a36c2c6b8a9a6706a808e87cc78.json +1 -0
- package/artifacts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +1 -1
- package/artifacts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +1 -1
- package/artifacts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +1 -1
- package/artifacts/contracts/Governance/TimelockV8.sol/TimelockV8.dbg.json +4 -0
- package/artifacts/contracts/Governance/TimelockV8.sol/TimelockV8.json +445 -0
- package/artifacts/contracts/test/MockAccessTest.sol/MockAccessTest.dbg.json +1 -1
- package/artifacts/contracts/test/TestTimelockV8.sol/TestTimelockV8.dbg.json +4 -0
- package/artifacts/contracts/test/TestTimelockV8.sol/TestTimelockV8.json +445 -0
- package/contracts/Governance/TimelockV8.sol +229 -0
- package/contracts/test/TestTimelockV8.sol +19 -0
- package/package.json +4 -1
- package/artifacts/build-info/0e028ff5062f0f59a7ffef92b702c074.json +0 -1
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
pragma solidity 0.8.13;
|
|
3
|
+
import { ensureNonzeroAddress } from "@venusprotocol/solidity-utilities/contracts/validators.sol";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @title TimelockV8
|
|
7
|
+
* @author Venus
|
|
8
|
+
* @notice The Timelock contract using solidity V8.
|
|
9
|
+
* This contract also differs from the original timelock because it has a virtual function to get minimum delays
|
|
10
|
+
* and allow test deployments to override the value.
|
|
11
|
+
*/
|
|
12
|
+
contract TimelockV8 {
|
|
13
|
+
/// @notice Event emitted when a new admin is accepted
|
|
14
|
+
event NewAdmin(address indexed newAdmin);
|
|
15
|
+
|
|
16
|
+
/// @notice Event emitted when a new admin is proposed
|
|
17
|
+
event NewPendingAdmin(address indexed newPendingAdmin);
|
|
18
|
+
|
|
19
|
+
/// @notice Event emitted when a new admin is proposed
|
|
20
|
+
event NewDelay(uint256 indexed newDelay);
|
|
21
|
+
|
|
22
|
+
/// @notice Event emitted when a proposal transaction has been cancelled
|
|
23
|
+
event CancelTransaction(
|
|
24
|
+
bytes32 indexed txHash,
|
|
25
|
+
address indexed target,
|
|
26
|
+
uint256 value,
|
|
27
|
+
string signature,
|
|
28
|
+
bytes data,
|
|
29
|
+
uint256 eta
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
/// @notice Event emitted when a proposal transaction has been executed
|
|
33
|
+
event ExecuteTransaction(
|
|
34
|
+
bytes32 indexed txHash,
|
|
35
|
+
address indexed target,
|
|
36
|
+
uint256 value,
|
|
37
|
+
string signature,
|
|
38
|
+
bytes data,
|
|
39
|
+
uint256 eta
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
/// @notice Event emitted when a proposal transaction has been queued
|
|
43
|
+
event QueueTransaction(
|
|
44
|
+
bytes32 indexed txHash,
|
|
45
|
+
address indexed target,
|
|
46
|
+
uint256 value,
|
|
47
|
+
string signature,
|
|
48
|
+
bytes data,
|
|
49
|
+
uint256 eta
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
/// @notice Required period to execute a proposal transaction
|
|
53
|
+
uint256 private constant DEFAULT_GRACE_PERIOD = 14 days;
|
|
54
|
+
|
|
55
|
+
/// @notice Minimum amount of time a proposal transaction must be queued
|
|
56
|
+
uint256 private constant DEFAULT_MINIMUM_DELAY = 1 hours;
|
|
57
|
+
|
|
58
|
+
/// @notice Maximum amount of time a proposal transaction must be queued
|
|
59
|
+
uint256 private constant DEFAULT_MAXIMUM_DELAY = 30 days;
|
|
60
|
+
|
|
61
|
+
/// @notice Timelock admin authorized to queue and execute transactions
|
|
62
|
+
address public admin;
|
|
63
|
+
|
|
64
|
+
/// @notice Account proposed as the next admin
|
|
65
|
+
address public pendingAdmin;
|
|
66
|
+
|
|
67
|
+
/// @notice Period for a proposal transaction to be queued
|
|
68
|
+
uint256 public delay;
|
|
69
|
+
|
|
70
|
+
/// @notice Mapping of queued transactions
|
|
71
|
+
mapping(bytes32 => bool) public queuedTransactions;
|
|
72
|
+
|
|
73
|
+
constructor(address admin_, uint256 delay_) {
|
|
74
|
+
require(delay_ >= getMinimumDelay(), "Timelock::constructor: Delay must exceed minimum delay.");
|
|
75
|
+
require(delay_ <= getMaximumDelay(), "Timelock::setDelay: Delay must not exceed maximum delay.");
|
|
76
|
+
ensureNonzeroAddress(admin_);
|
|
77
|
+
|
|
78
|
+
admin = admin_;
|
|
79
|
+
delay = delay_;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
fallback() external payable {}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @notice Setter for the transaction queue delay
|
|
86
|
+
* @param delay_ The new delay period for the transaction queue
|
|
87
|
+
*/
|
|
88
|
+
function setDelay(uint256 delay_) public {
|
|
89
|
+
require(msg.sender == address(this), "Timelock::setDelay: Call must come from Timelock.");
|
|
90
|
+
require(delay_ >= getMinimumDelay(), "Timelock::setDelay: Delay must exceed minimum delay.");
|
|
91
|
+
require(delay_ <= getMaximumDelay(), "Timelock::setDelay: Delay must not exceed maximum delay.");
|
|
92
|
+
delay = delay_;
|
|
93
|
+
|
|
94
|
+
emit NewDelay(delay);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function getGracePeriod() public view virtual returns (uint256) {
|
|
98
|
+
return DEFAULT_GRACE_PERIOD;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function getMinimumDelay() public view virtual returns (uint256) {
|
|
102
|
+
return DEFAULT_MINIMUM_DELAY;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function getMaximumDelay() public view virtual returns (uint256) {
|
|
106
|
+
return DEFAULT_MAXIMUM_DELAY;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @notice Method for accepting a proposed admin
|
|
111
|
+
*/
|
|
112
|
+
function acceptAdmin() public {
|
|
113
|
+
require(msg.sender == pendingAdmin, "Timelock::acceptAdmin: Call must come from pendingAdmin.");
|
|
114
|
+
admin = msg.sender;
|
|
115
|
+
pendingAdmin = address(0);
|
|
116
|
+
|
|
117
|
+
emit NewAdmin(admin);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @notice Method to propose a new admin authorized to call timelock functions. This should be the Governor Contract
|
|
122
|
+
* @param pendingAdmin_ Address of the proposed admin
|
|
123
|
+
*/
|
|
124
|
+
function setPendingAdmin(address pendingAdmin_) public {
|
|
125
|
+
require(msg.sender == address(this), "Timelock::setPendingAdmin: Call must come from Timelock.");
|
|
126
|
+
ensureNonzeroAddress(pendingAdmin_);
|
|
127
|
+
pendingAdmin = pendingAdmin_;
|
|
128
|
+
|
|
129
|
+
emit NewPendingAdmin(pendingAdmin);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @notice Called for each action when queuing a proposal
|
|
134
|
+
* @param target Address of the contract with the method to be called
|
|
135
|
+
* @param value Native token amount sent with the transaction
|
|
136
|
+
* @param signature Ssignature of the function to be called
|
|
137
|
+
* @param data Arguments to be passed to the function when called
|
|
138
|
+
* @param eta Timestamp after which the transaction can be executed
|
|
139
|
+
* @return Hash of the queued transaction
|
|
140
|
+
*/
|
|
141
|
+
function queueTransaction(
|
|
142
|
+
address target,
|
|
143
|
+
uint256 value,
|
|
144
|
+
string memory signature,
|
|
145
|
+
bytes memory data,
|
|
146
|
+
uint256 eta
|
|
147
|
+
) public returns (bytes32) {
|
|
148
|
+
require(msg.sender == admin, "Timelock::queueTransaction: Call must come from admin.");
|
|
149
|
+
require(
|
|
150
|
+
eta >= getBlockTimestamp() + delay,
|
|
151
|
+
"Timelock::queueTransaction: Estimated execution block must satisfy delay."
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
|
|
155
|
+
queuedTransactions[txHash] = true;
|
|
156
|
+
|
|
157
|
+
emit QueueTransaction(txHash, target, value, signature, data, eta);
|
|
158
|
+
return txHash;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @notice Called to cancel a queued transaction
|
|
163
|
+
* @param target Address of the contract with the method to be called
|
|
164
|
+
* @param value Native token amount sent with the transaction
|
|
165
|
+
* @param signature Ssignature of the function to be called
|
|
166
|
+
* @param data Arguments to be passed to the function when called
|
|
167
|
+
* @param eta Timestamp after which the transaction can be executed
|
|
168
|
+
*/
|
|
169
|
+
function cancelTransaction(
|
|
170
|
+
address target,
|
|
171
|
+
uint256 value,
|
|
172
|
+
string memory signature,
|
|
173
|
+
bytes memory data,
|
|
174
|
+
uint256 eta
|
|
175
|
+
) public {
|
|
176
|
+
require(msg.sender == admin, "Timelock::cancelTransaction: Call must come from admin.");
|
|
177
|
+
|
|
178
|
+
bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
|
|
179
|
+
queuedTransactions[txHash] = false;
|
|
180
|
+
|
|
181
|
+
emit CancelTransaction(txHash, target, value, signature, data, eta);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @notice Called to execute a queued transaction
|
|
186
|
+
* @param target Address of the contract with the method to be called
|
|
187
|
+
* @param value Native token amount sent with the transaction
|
|
188
|
+
* @param signature Ssignature of the function to be called
|
|
189
|
+
* @param data Arguments to be passed to the function when called
|
|
190
|
+
* @param eta Timestamp after which the transaction can be executed
|
|
191
|
+
*/
|
|
192
|
+
function executeTransaction(
|
|
193
|
+
address target,
|
|
194
|
+
uint256 value,
|
|
195
|
+
string memory signature,
|
|
196
|
+
bytes memory data,
|
|
197
|
+
uint256 eta
|
|
198
|
+
) public payable returns (bytes memory) {
|
|
199
|
+
require(msg.sender == admin, "Timelock::executeTransaction: Call must come from admin.");
|
|
200
|
+
|
|
201
|
+
bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
|
|
202
|
+
require(queuedTransactions[txHash], "Timelock::executeTransaction: Transaction hasn't been queued.");
|
|
203
|
+
require(getBlockTimestamp() >= eta, "Timelock::executeTransaction: Transaction hasn't surpassed time lock.");
|
|
204
|
+
require(getBlockTimestamp() <= eta + getGracePeriod(), "Timelock::executeTransaction: Transaction is stale.");
|
|
205
|
+
|
|
206
|
+
queuedTransactions[txHash] = false;
|
|
207
|
+
|
|
208
|
+
bytes memory callData;
|
|
209
|
+
|
|
210
|
+
if (bytes(signature).length == 0) {
|
|
211
|
+
callData = data;
|
|
212
|
+
} else {
|
|
213
|
+
callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// solium-disable-next-line security/no-call-value
|
|
217
|
+
(bool success, bytes memory returnData) = target.call{ value: value }(callData);
|
|
218
|
+
require(success, "Timelock::executeTransaction: Transaction execution reverted.");
|
|
219
|
+
|
|
220
|
+
emit ExecuteTransaction(txHash, target, value, signature, data, eta);
|
|
221
|
+
|
|
222
|
+
return returnData;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function getBlockTimestamp() internal view returns (uint256) {
|
|
226
|
+
// solium-disable-next-line security/no-block-members
|
|
227
|
+
return block.timestamp;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
pragma solidity 0.8.13;
|
|
3
|
+
import { TimelockV8 } from "../Governance/TimelockV8.sol";
|
|
4
|
+
|
|
5
|
+
contract TestTimelockV8 is TimelockV8 {
|
|
6
|
+
constructor(address admin_, uint256 delay_) public TimelockV8(admin_, delay_) {}
|
|
7
|
+
|
|
8
|
+
function getGracePeriod() public view override returns (uint256) {
|
|
9
|
+
return 1;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getMinimumDelay() public view override returns (uint256) {
|
|
13
|
+
return 1;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getMaximumDelay() public view override returns (uint256) {
|
|
17
|
+
return 1 hours;
|
|
18
|
+
}
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venusprotocol/governance-contracts",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "1.4.0-dev.
|
|
4
|
+
"version": "1.4.0-dev.3",
|
|
5
5
|
"author": "",
|
|
6
6
|
"files": [
|
|
7
7
|
"artifacts",
|
|
@@ -38,6 +38,9 @@
|
|
|
38
38
|
"docgen": "hardhat docgen",
|
|
39
39
|
"prepare": "husky install"
|
|
40
40
|
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@venusprotocol/solidity-utilities": "^1.1.0"
|
|
43
|
+
},
|
|
41
44
|
"devDependencies": {
|
|
42
45
|
"@commitlint/cli": "^17.4.4",
|
|
43
46
|
"@commitlint/config-conventional": "^17.4.4",
|