@venusprotocol/governance-contracts 1.0.1-dev.6 → 1.1.0-dev.2

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.
Files changed (70) hide show
  1. package/artifacts/build-info/4b74a981a83b37e1de5123f7f9359ad5.json +1 -0
  2. package/artifacts/build-info/5ef7ba07b1e4b96d9b02042d36d229c2.json +1 -0
  3. package/artifacts/build-info/97a3124320e74f843bc59439c75c258d.json +1 -0
  4. package/artifacts/contracts/Governance/GovernorBravoDelegate.sol/GovernorBravoDelegate.dbg.json +1 -1
  5. package/artifacts/contracts/Governance/GovernorBravoDelegate.sol/GovernorBravoDelegate.json +3 -3
  6. package/artifacts/contracts/Governance/GovernorBravoDelegator.sol/GovernorBravoDelegator.dbg.json +1 -1
  7. package/artifacts/contracts/Governance/GovernorBravoDelegator.sol/GovernorBravoDelegator.json +25 -18
  8. package/artifacts/contracts/Governance/GovernorBravoInterfaces.sol/GovernorAlphaInterface.dbg.json +1 -1
  9. package/artifacts/contracts/Governance/GovernorBravoInterfaces.sol/GovernorBravoDelegateInterface.dbg.json +4 -0
  10. package/artifacts/contracts/Governance/GovernorBravoInterfaces.sol/GovernorBravoDelegateInterface.json +58 -0
  11. package/artifacts/contracts/Governance/GovernorBravoInterfaces.sol/GovernorBravoDelegateStorageV1.dbg.json +1 -1
  12. package/artifacts/contracts/Governance/GovernorBravoInterfaces.sol/GovernorBravoDelegateStorageV1.json +2 -2
  13. package/artifacts/contracts/Governance/GovernorBravoInterfaces.sol/GovernorBravoDelegateStorageV2.dbg.json +1 -1
  14. package/artifacts/contracts/Governance/GovernorBravoInterfaces.sol/GovernorBravoDelegateStorageV2.json +2 -2
  15. package/artifacts/contracts/Governance/GovernorBravoInterfaces.sol/GovernorBravoDelegatorStorage.dbg.json +1 -1
  16. package/artifacts/contracts/Governance/GovernorBravoInterfaces.sol/GovernorBravoDelegatorStorage.json +2 -2
  17. package/artifacts/contracts/Governance/GovernorBravoInterfaces.sol/GovernorBravoEvents.dbg.json +1 -1
  18. package/artifacts/contracts/Governance/GovernorBravoInterfaces.sol/GovernorBravoEvents.json +2 -2
  19. package/artifacts/contracts/Governance/GovernorBravoInterfaces.sol/TimelockInterface.dbg.json +1 -1
  20. package/artifacts/contracts/Governance/GovernorBravoInterfaces.sol/XvsVaultInterface.dbg.json +1 -1
  21. package/artifacts/contracts/legacy/GovernorAlpha.sol/GovernorAlpha.dbg.json +4 -0
  22. package/artifacts/contracts/legacy/GovernorAlpha.sol/GovernorAlpha.json +731 -0
  23. package/artifacts/contracts/legacy/GovernorAlpha.sol/TimelockInterface.dbg.json +4 -0
  24. package/artifacts/contracts/legacy/GovernorAlpha.sol/TimelockInterface.json +188 -0
  25. package/artifacts/contracts/legacy/GovernorAlpha.sol/XVSInterface.dbg.json +4 -0
  26. package/artifacts/contracts/legacy/GovernorAlpha.sol/XVSInterface.json +37 -0
  27. package/artifacts/contracts/legacy/GovernorAlpha2.sol/GovernorAlpha2.dbg.json +4 -0
  28. package/artifacts/contracts/legacy/GovernorAlpha2.sol/GovernorAlpha2.json +736 -0
  29. package/artifacts/contracts/legacy/GovernorAlpha2.sol/TimelockInterface.dbg.json +4 -0
  30. package/artifacts/contracts/legacy/GovernorAlpha2.sol/TimelockInterface.json +188 -0
  31. package/artifacts/contracts/legacy/GovernorAlpha2.sol/XVSInterface.dbg.json +4 -0
  32. package/artifacts/contracts/legacy/GovernorAlpha2.sol/XVSInterface.json +37 -0
  33. package/contracts/Governance/GovernorBravoDelegate.sol +1 -1
  34. package/contracts/Governance/GovernorBravoDelegator.sol +6 -10
  35. package/contracts/Governance/GovernorBravoInterfaces.sol +19 -5
  36. package/contracts/legacy/GovernorAlpha.sol +426 -0
  37. package/contracts/legacy/GovernorAlpha2.sol +427 -0
  38. package/deployments/bscmainnet/.chainId +1 -0
  39. package/deployments/bscmainnet/CriticalTimelock.json +463 -0
  40. package/deployments/bscmainnet/FastTrackTimelock.json +463 -0
  41. package/deployments/bscmainnet/GovernorAlpha.json +726 -0
  42. package/deployments/bscmainnet/GovernorAlpha2.json +731 -0
  43. package/deployments/bscmainnet/GovernorBravoDelegate.json +1168 -0
  44. package/deployments/bscmainnet/GovernorBravoDelegator.json +1576 -0
  45. package/deployments/bscmainnet/GovernorBravoDelegator_Implementation.json +1168 -0
  46. package/deployments/bscmainnet/GovernorBravoDelegator_Proxy.json +413 -0
  47. package/deployments/bscmainnet/NormalTimelock.json +463 -0
  48. package/deployments/bsctestnet/.chainId +1 -0
  49. package/deployments/bsctestnet/CriticalTimelock.json +463 -0
  50. package/deployments/bsctestnet/FastTrackTimelock.json +463 -0
  51. package/deployments/bsctestnet/GovernorAlpha.json +726 -0
  52. package/deployments/bsctestnet/GovernorBravoDelegate.json +1168 -0
  53. package/deployments/bsctestnet/GovernorBravoDelegator.json +1576 -0
  54. package/deployments/bsctestnet/GovernorBravoDelegator_Implementation.json +1168 -0
  55. package/deployments/bsctestnet/GovernorBravoDelegator_Proxy.json +413 -0
  56. package/deployments/bsctestnet/NormalTimelock.json +463 -0
  57. package/deployments/deployments.json +13981 -0
  58. package/dist/deploy/001-access-control.d.ts.map +1 -1
  59. package/dist/deploy/001-access-control.js +7 -2
  60. package/dist/deploy/001-access-control.js.map +1 -1
  61. package/dist/deploy/helpers/constants.d.ts +2 -0
  62. package/dist/deploy/helpers/constants.d.ts.map +1 -1
  63. package/dist/deploy/helpers/constants.js +1 -0
  64. package/dist/deploy/helpers/constants.js.map +1 -1
  65. package/dist/deploy/helpers/deploymentUtils.d.ts +2 -0
  66. package/dist/deploy/helpers/deploymentUtils.d.ts.map +1 -1
  67. package/dist/deploy/helpers/deploymentUtils.js +1 -0
  68. package/dist/deploy/helpers/deploymentUtils.js.map +1 -1
  69. package/package.json +1 -1
  70. package/artifacts/build-info/e5638231ea42ec29d0230b1b013f1a57.json +0 -1
@@ -0,0 +1,426 @@
1
+ pragma solidity ^0.5.16;
2
+ pragma experimental ABIEncoderV2;
3
+
4
+ contract GovernorAlpha {
5
+ /// @notice The name of this contract
6
+ string public constant name = "Venus Governor Alpha";
7
+
8
+ /// @notice The number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed
9
+ function quorumVotes() public pure returns (uint) {
10
+ return 600000e18;
11
+ } // 600,000 = 2% of XVS
12
+
13
+ /// @notice The number of votes required in order for a voter to become a proposer
14
+ function proposalThreshold() public pure returns (uint) {
15
+ return 300000e18;
16
+ } // 300,000 = 1% of XVS
17
+
18
+ /// @notice The maximum number of actions that can be included in a proposal
19
+ function proposalMaxOperations() public pure returns (uint) {
20
+ return 10;
21
+ } // 10 actions
22
+
23
+ /// @notice The delay before voting on a proposal may take place, once proposed
24
+ function votingDelay() public pure returns (uint) {
25
+ return 1;
26
+ } // 1 block
27
+
28
+ /// @notice The duration of voting on a proposal, in blocks
29
+ function votingPeriod() public pure returns (uint) {
30
+ return (60 * 60 * 24 * 3) / 3;
31
+ } // ~3 days in blocks (assuming 3s blocks)
32
+
33
+ /// @notice The address of the Venus Protocol Timelock
34
+ TimelockInterface public timelock;
35
+
36
+ /// @notice The address of the Venus governance token
37
+ XVSInterface public xvs;
38
+
39
+ /// @notice The address of the Governor Guardian
40
+ address public guardian;
41
+
42
+ /// @notice The total number of proposals
43
+ uint public proposalCount;
44
+
45
+ struct Proposal {
46
+ /// @notice Unique id for looking up a proposal
47
+ uint id;
48
+ /// @notice Creator of the proposal
49
+ address proposer;
50
+ /// @notice The timestamp that the proposal will be available for execution, set once the vote succeeds
51
+ uint eta;
52
+ /// @notice the ordered list of target addresses for calls to be made
53
+ address[] targets;
54
+ /// @notice The ordered list of values (i.e. msg.value) to be passed to the calls to be made
55
+ uint[] values;
56
+ /// @notice The ordered list of function signatures to be called
57
+ string[] signatures;
58
+ /// @notice The ordered list of calldata to be passed to each call
59
+ bytes[] calldatas;
60
+ /// @notice The block at which voting begins: holders must delegate their votes prior to this block
61
+ uint startBlock;
62
+ /// @notice The block at which voting ends: votes must be cast prior to this block
63
+ uint endBlock;
64
+ /// @notice Current number of votes in favor of this proposal
65
+ uint forVotes;
66
+ /// @notice Current number of votes in opposition to this proposal
67
+ uint againstVotes;
68
+ /// @notice Flag marking whether the proposal has been canceled
69
+ bool canceled;
70
+ /// @notice Flag marking whether the proposal has been executed
71
+ bool executed;
72
+ /// @notice Receipts of ballots for the entire set of voters
73
+ mapping(address => Receipt) receipts;
74
+ }
75
+
76
+ /// @notice Ballot receipt record for a voter
77
+ struct Receipt {
78
+ /// @notice Whether or not a vote has been cast
79
+ bool hasVoted;
80
+ /// @notice Whether or not the voter supports the proposal
81
+ bool support;
82
+ /// @notice The number of votes the voter had, which were cast
83
+ uint96 votes;
84
+ }
85
+
86
+ /// @notice Possible states that a proposal may be in
87
+ enum ProposalState {
88
+ Pending,
89
+ Active,
90
+ Canceled,
91
+ Defeated,
92
+ Succeeded,
93
+ Queued,
94
+ Expired,
95
+ Executed
96
+ }
97
+
98
+ /// @notice The official record of all proposals ever proposed
99
+ mapping(uint => Proposal) public proposals;
100
+
101
+ /// @notice The latest proposal for each proposer
102
+ mapping(address => uint) public latestProposalIds;
103
+
104
+ /// @notice The EIP-712 typehash for the contract's domain
105
+ bytes32 public constant DOMAIN_TYPEHASH =
106
+ keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
107
+
108
+ /// @notice The EIP-712 typehash for the ballot struct used by the contract
109
+ bytes32 public constant BALLOT_TYPEHASH = keccak256("Ballot(uint256 proposalId,bool support)");
110
+
111
+ /// @notice An event emitted when a new proposal is created
112
+ event ProposalCreated(
113
+ uint id,
114
+ address proposer,
115
+ address[] targets,
116
+ uint[] values,
117
+ string[] signatures,
118
+ bytes[] calldatas,
119
+ uint startBlock,
120
+ uint endBlock,
121
+ string description
122
+ );
123
+
124
+ /// @notice An event emitted when a vote has been cast on a proposal
125
+ event VoteCast(address voter, uint proposalId, bool support, uint votes);
126
+
127
+ /// @notice An event emitted when a proposal has been canceled
128
+ event ProposalCanceled(uint id);
129
+
130
+ /// @notice An event emitted when a proposal has been queued in the Timelock
131
+ event ProposalQueued(uint id, uint eta);
132
+
133
+ /// @notice An event emitted when a proposal has been executed in the Timelock
134
+ event ProposalExecuted(uint id);
135
+
136
+ constructor(address timelock_, address xvs_, address guardian_) public {
137
+ timelock = TimelockInterface(timelock_);
138
+ xvs = XVSInterface(xvs_);
139
+ guardian = guardian_;
140
+ }
141
+
142
+ function propose(
143
+ address[] memory targets,
144
+ uint[] memory values,
145
+ string[] memory signatures,
146
+ bytes[] memory calldatas,
147
+ string memory description
148
+ ) public returns (uint) {
149
+ require(
150
+ xvs.getPriorVotes(msg.sender, sub256(block.number, 1)) > proposalThreshold(),
151
+ "GovernorAlpha::propose: proposer votes below proposal threshold"
152
+ );
153
+ require(
154
+ targets.length == values.length &&
155
+ targets.length == signatures.length &&
156
+ targets.length == calldatas.length,
157
+ "GovernorAlpha::propose: proposal function information arity mismatch"
158
+ );
159
+ require(targets.length != 0, "GovernorAlpha::propose: must provide actions");
160
+ require(targets.length <= proposalMaxOperations(), "GovernorAlpha::propose: too many actions");
161
+
162
+ uint latestProposalId = latestProposalIds[msg.sender];
163
+ if (latestProposalId != 0) {
164
+ ProposalState proposersLatestProposalState = state(latestProposalId);
165
+ require(
166
+ proposersLatestProposalState != ProposalState.Active,
167
+ "GovernorAlpha::propose: found an already active proposal"
168
+ );
169
+ require(
170
+ proposersLatestProposalState != ProposalState.Pending,
171
+ "GovernorAlpha::propose: found an already pending proposal"
172
+ );
173
+ }
174
+
175
+ uint startBlock = add256(block.number, votingDelay());
176
+ uint endBlock = add256(startBlock, votingPeriod());
177
+
178
+ proposalCount++;
179
+ Proposal memory newProposal = Proposal({
180
+ id: proposalCount,
181
+ proposer: msg.sender,
182
+ eta: 0,
183
+ targets: targets,
184
+ values: values,
185
+ signatures: signatures,
186
+ calldatas: calldatas,
187
+ startBlock: startBlock,
188
+ endBlock: endBlock,
189
+ forVotes: 0,
190
+ againstVotes: 0,
191
+ canceled: false,
192
+ executed: false
193
+ });
194
+
195
+ proposals[newProposal.id] = newProposal;
196
+ latestProposalIds[newProposal.proposer] = newProposal.id;
197
+
198
+ emit ProposalCreated(
199
+ newProposal.id,
200
+ msg.sender,
201
+ targets,
202
+ values,
203
+ signatures,
204
+ calldatas,
205
+ startBlock,
206
+ endBlock,
207
+ description
208
+ );
209
+ return newProposal.id;
210
+ }
211
+
212
+ function queue(uint proposalId) public {
213
+ require(
214
+ state(proposalId) == ProposalState.Succeeded,
215
+ "GovernorAlpha::queue: proposal can only be queued if it is succeeded"
216
+ );
217
+ Proposal storage proposal = proposals[proposalId];
218
+ uint eta = add256(block.timestamp, timelock.delay());
219
+ for (uint i = 0; i < proposal.targets.length; i++) {
220
+ _queueOrRevert(proposal.targets[i], proposal.values[i], proposal.signatures[i], proposal.calldatas[i], eta);
221
+ }
222
+ proposal.eta = eta;
223
+ emit ProposalQueued(proposalId, eta);
224
+ }
225
+
226
+ function _queueOrRevert(address target, uint value, string memory signature, bytes memory data, uint eta) internal {
227
+ require(
228
+ !timelock.queuedTransactions(keccak256(abi.encode(target, value, signature, data, eta))),
229
+ "GovernorAlpha::_queueOrRevert: proposal action already queued at eta"
230
+ );
231
+ timelock.queueTransaction(target, value, signature, data, eta);
232
+ }
233
+
234
+ function execute(uint proposalId) public payable {
235
+ require(
236
+ state(proposalId) == ProposalState.Queued,
237
+ "GovernorAlpha::execute: proposal can only be executed if it is queued"
238
+ );
239
+ Proposal storage proposal = proposals[proposalId];
240
+ proposal.executed = true;
241
+ for (uint i = 0; i < proposal.targets.length; i++) {
242
+ timelock.executeTransaction.value(proposal.values[i])(
243
+ proposal.targets[i],
244
+ proposal.values[i],
245
+ proposal.signatures[i],
246
+ proposal.calldatas[i],
247
+ proposal.eta
248
+ );
249
+ }
250
+ emit ProposalExecuted(proposalId);
251
+ }
252
+
253
+ function cancel(uint proposalId) public {
254
+ ProposalState state = state(proposalId);
255
+ require(state != ProposalState.Executed, "GovernorAlpha::cancel: cannot cancel executed proposal");
256
+
257
+ Proposal storage proposal = proposals[proposalId];
258
+ require(
259
+ msg.sender == guardian ||
260
+ xvs.getPriorVotes(proposal.proposer, sub256(block.number, 1)) < proposalThreshold(),
261
+ "GovernorAlpha::cancel: proposer above threshold"
262
+ );
263
+
264
+ proposal.canceled = true;
265
+ for (uint i = 0; i < proposal.targets.length; i++) {
266
+ timelock.cancelTransaction(
267
+ proposal.targets[i],
268
+ proposal.values[i],
269
+ proposal.signatures[i],
270
+ proposal.calldatas[i],
271
+ proposal.eta
272
+ );
273
+ }
274
+
275
+ emit ProposalCanceled(proposalId);
276
+ }
277
+
278
+ function getActions(
279
+ uint proposalId
280
+ )
281
+ public
282
+ view
283
+ returns (address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas)
284
+ {
285
+ Proposal storage p = proposals[proposalId];
286
+ return (p.targets, p.values, p.signatures, p.calldatas);
287
+ }
288
+
289
+ function getReceipt(uint proposalId, address voter) public view returns (Receipt memory) {
290
+ return proposals[proposalId].receipts[voter];
291
+ }
292
+
293
+ function state(uint proposalId) public view returns (ProposalState) {
294
+ require(proposalCount >= proposalId && proposalId > 0, "GovernorAlpha::state: invalid proposal id");
295
+ Proposal storage proposal = proposals[proposalId];
296
+ if (proposal.canceled) {
297
+ return ProposalState.Canceled;
298
+ } else if (block.number <= proposal.startBlock) {
299
+ return ProposalState.Pending;
300
+ } else if (block.number <= proposal.endBlock) {
301
+ return ProposalState.Active;
302
+ } else if (proposal.forVotes <= proposal.againstVotes || proposal.forVotes < quorumVotes()) {
303
+ return ProposalState.Defeated;
304
+ } else if (proposal.eta == 0) {
305
+ return ProposalState.Succeeded;
306
+ } else if (proposal.executed) {
307
+ return ProposalState.Executed;
308
+ } else if (block.timestamp >= add256(proposal.eta, timelock.GRACE_PERIOD())) {
309
+ return ProposalState.Expired;
310
+ } else {
311
+ return ProposalState.Queued;
312
+ }
313
+ }
314
+
315
+ function castVote(uint proposalId, bool support) public {
316
+ return _castVote(msg.sender, proposalId, support);
317
+ }
318
+
319
+ function castVoteBySig(uint proposalId, bool support, uint8 v, bytes32 r, bytes32 s) public {
320
+ bytes32 domainSeparator = keccak256(
321
+ abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name)), getChainId(), address(this))
322
+ );
323
+ bytes32 structHash = keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support));
324
+ bytes32 digest = keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
325
+ address signatory = ecrecover(digest, v, r, s);
326
+ require(signatory != address(0), "GovernorAlpha::castVoteBySig: invalid signature");
327
+ return _castVote(signatory, proposalId, support);
328
+ }
329
+
330
+ function _castVote(address voter, uint proposalId, bool support) internal {
331
+ require(state(proposalId) == ProposalState.Active, "GovernorAlpha::_castVote: voting is closed");
332
+ Proposal storage proposal = proposals[proposalId];
333
+ Receipt storage receipt = proposal.receipts[voter];
334
+ require(receipt.hasVoted == false, "GovernorAlpha::_castVote: voter already voted");
335
+ uint96 votes = xvs.getPriorVotes(voter, proposal.startBlock);
336
+
337
+ if (support) {
338
+ proposal.forVotes = add256(proposal.forVotes, votes);
339
+ } else {
340
+ proposal.againstVotes = add256(proposal.againstVotes, votes);
341
+ }
342
+
343
+ receipt.hasVoted = true;
344
+ receipt.support = support;
345
+ receipt.votes = votes;
346
+
347
+ emit VoteCast(voter, proposalId, support, votes);
348
+ }
349
+
350
+ function __acceptAdmin() public {
351
+ require(msg.sender == guardian, "GovernorAlpha::__acceptAdmin: sender must be gov guardian");
352
+ timelock.acceptAdmin();
353
+ }
354
+
355
+ function __abdicate() public {
356
+ require(msg.sender == guardian, "GovernorAlpha::__abdicate: sender must be gov guardian");
357
+ guardian = address(0);
358
+ }
359
+
360
+ function __queueSetTimelockPendingAdmin(address newPendingAdmin, uint eta) public {
361
+ require(msg.sender == guardian, "GovernorAlpha::__queueSetTimelockPendingAdmin: sender must be gov guardian");
362
+ timelock.queueTransaction(address(timelock), 0, "setPendingAdmin(address)", abi.encode(newPendingAdmin), eta);
363
+ }
364
+
365
+ function __executeSetTimelockPendingAdmin(address newPendingAdmin, uint eta) public {
366
+ require(msg.sender == guardian, "GovernorAlpha::__executeSetTimelockPendingAdmin: sender must be gov guardian");
367
+ timelock.executeTransaction(address(timelock), 0, "setPendingAdmin(address)", abi.encode(newPendingAdmin), eta);
368
+ }
369
+
370
+ function add256(uint256 a, uint256 b) internal pure returns (uint) {
371
+ uint c = a + b;
372
+ require(c >= a, "addition overflow");
373
+ return c;
374
+ }
375
+
376
+ function sub256(uint256 a, uint256 b) internal pure returns (uint) {
377
+ require(b <= a, "subtraction underflow");
378
+ return a - b;
379
+ }
380
+
381
+ function getChainId() internal pure returns (uint) {
382
+ uint chainId;
383
+ assembly {
384
+ chainId := chainid()
385
+ }
386
+ return chainId;
387
+ }
388
+ }
389
+
390
+ interface TimelockInterface {
391
+ function delay() external view returns (uint);
392
+
393
+ function GRACE_PERIOD() external view returns (uint);
394
+
395
+ function acceptAdmin() external;
396
+
397
+ function queuedTransactions(bytes32 hash) external view returns (bool);
398
+
399
+ function queueTransaction(
400
+ address target,
401
+ uint value,
402
+ string calldata signature,
403
+ bytes calldata data,
404
+ uint eta
405
+ ) external returns (bytes32);
406
+
407
+ function cancelTransaction(
408
+ address target,
409
+ uint value,
410
+ string calldata signature,
411
+ bytes calldata data,
412
+ uint eta
413
+ ) external;
414
+
415
+ function executeTransaction(
416
+ address target,
417
+ uint value,
418
+ string calldata signature,
419
+ bytes calldata data,
420
+ uint eta
421
+ ) external payable returns (bytes memory);
422
+ }
423
+
424
+ interface XVSInterface {
425
+ function getPriorVotes(address account, uint blockNumber) external view returns (uint96);
426
+ }