@web3dotorg/evm-slc-core-contracts 0.3.5 → 0.3.8
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/governance/Governance.sol +80 -151
- package/package.json +1 -1
@@ -86,6 +86,21 @@ contract Governance is IGovernance, GovernorUpgradeable, UUPSUpgradeable {
|
|
86
86
|
uint256 serviceFee;
|
87
87
|
uint256 neutralsNumber;
|
88
88
|
string additionalLink;
|
89
|
+
EnumerableSet.AddressSet selectedNeutrals;
|
90
|
+
bytes data;
|
91
|
+
VotingPhase votingPhase;
|
92
|
+
bytes32 leadingOperationHash;
|
93
|
+
// Proposals
|
94
|
+
uint256 requestNonce;
|
95
|
+
uint256[] proposalIds;
|
96
|
+
}
|
97
|
+
|
98
|
+
struct ServiceRequestStateView {
|
99
|
+
address requester;
|
100
|
+
uint256 serviceFee;
|
101
|
+
uint256 neutralsNumber;
|
102
|
+
string additionalLink;
|
103
|
+
address[] selectedNeutrals;
|
89
104
|
bytes data;
|
90
105
|
VotingPhase votingPhase;
|
91
106
|
bytes32 leadingOperationHash;
|
@@ -101,8 +116,6 @@ contract Governance is IGovernance, GovernorUpgradeable, UUPSUpgradeable {
|
|
101
116
|
// Voting parameters
|
102
117
|
uint256 neutralsThreshold;
|
103
118
|
uint256 executorsThreshold;
|
104
|
-
// Service request data
|
105
|
-
EnumerableSet.AddressSet selectedNeutrals;
|
106
119
|
// Voting data
|
107
120
|
OperationBundle[] operationBundles;
|
108
121
|
mapping(bytes32 operationHash => uint256 position) operationBundlePosition;
|
@@ -118,7 +131,6 @@ contract Governance is IGovernance, GovernorUpgradeable, UUPSUpgradeable {
|
|
118
131
|
uint256 neutralsThreshold;
|
119
132
|
uint256 executorsThreshold;
|
120
133
|
// Service request data
|
121
|
-
address[] selectedNeutrals;
|
122
134
|
bytes32[] neutralToOperationHashes;
|
123
135
|
// Voting data
|
124
136
|
OperationBundle[] operationBundles;
|
@@ -129,16 +141,16 @@ contract Governance is IGovernance, GovernorUpgradeable, UUPSUpgradeable {
|
|
129
141
|
event RejectedByExecutors(uint256 proposalId, uint256 newProposalId);
|
130
142
|
|
131
143
|
error Unreachable();
|
132
|
-
error AccountAlreadyVoted(address account);
|
133
|
-
error NeutralsThresholdTooHigh(uint256 threshold);
|
134
|
-
error ExecutorsThresholdTooHigh(uint256 threshold);
|
135
144
|
error InvalidTimepoint(uint256 timepoint);
|
136
145
|
error AccountNotSelected(address account);
|
137
146
|
error AccountNotExecutor(address account);
|
147
|
+
error AccountAlreadyVoted(address account);
|
148
|
+
error InvalidSharesTotal(uint256 totalShares);
|
149
|
+
error NeutralsThresholdTooHigh(uint256 threshold);
|
150
|
+
error ExecutorsThresholdTooHigh(uint256 threshold);
|
138
151
|
error InvalidServiceFee(uint256 serviceFee, uint256 msgValue);
|
139
152
|
error InvalidVotingPhaseForExecutorVote(VotingPhase votingPhase);
|
140
153
|
error InvalidVotingPhaseForProposeOperations(VotingPhase votingPhase);
|
141
|
-
error InvalidSharesTotal(uint256 totalShares);
|
142
154
|
error ServiceFeeTooLow(uint256 serviceFee, uint256 minServiceFee);
|
143
155
|
error MinServiceFeeNotSet(address parametersRegistry);
|
144
156
|
|
@@ -184,6 +196,8 @@ contract Governance is IGovernance, GovernorUpgradeable, UUPSUpgradeable {
|
|
184
196
|
requester_
|
185
197
|
);
|
186
198
|
|
199
|
+
address[] memory selectedNeutrals_ = $.neutralsRegistry.getNeutralsSlice(neutralsNumber_);
|
200
|
+
|
187
201
|
ServiceRequestState storage requestState = $.slcGovernanceState[slcCore_].requestState[
|
188
202
|
requestCounter_
|
189
203
|
];
|
@@ -192,9 +206,11 @@ contract Governance is IGovernance, GovernorUpgradeable, UUPSUpgradeable {
|
|
192
206
|
requestState.neutralsNumber = neutralsNumber_;
|
193
207
|
requestState.additionalLink = additionalLink_;
|
194
208
|
requestState.data = data_;
|
209
|
+
for (uint256 i = 0; i < selectedNeutrals_.length; ++i) {
|
210
|
+
requestState.selectedNeutrals.add(selectedNeutrals_[i]);
|
211
|
+
}
|
195
212
|
|
196
|
-
|
197
|
-
_fillProposalState(selectedNeutrals_, proposalId_);
|
213
|
+
_fillProposalState(proposalId_);
|
198
214
|
|
199
215
|
_distributeServiceFeeRewards(proposalId_, selectedNeutrals_);
|
200
216
|
|
@@ -217,7 +233,7 @@ contract Governance is IGovernance, GovernorUpgradeable, UUPSUpgradeable {
|
|
217
233
|
);
|
218
234
|
|
219
235
|
require(
|
220
|
-
|
236
|
+
requestState.selectedNeutrals.contains(msg.sender),
|
221
237
|
AccountNotSelected(msg.sender)
|
222
238
|
);
|
223
239
|
|
@@ -270,7 +286,7 @@ contract Governance is IGovernance, GovernorUpgradeable, UUPSUpgradeable {
|
|
270
286
|
address slcCore_,
|
271
287
|
uint256 offset_,
|
272
288
|
uint256 limit_
|
273
|
-
) external view returns (
|
289
|
+
) external view returns (ServiceRequestStateView[] memory) {
|
274
290
|
GovernanceStorage storage $ = _getGovernanceStorage();
|
275
291
|
|
276
292
|
uint256 to_ = Paginator.getTo(
|
@@ -279,10 +295,24 @@ contract Governance is IGovernance, GovernorUpgradeable, UUPSUpgradeable {
|
|
279
295
|
limit_
|
280
296
|
);
|
281
297
|
|
282
|
-
|
298
|
+
ServiceRequestStateView[] memory requests_ = new ServiceRequestStateView[](to_ - offset_);
|
283
299
|
|
284
300
|
for (uint256 i = offset_; i < to_; ++i) {
|
285
|
-
|
301
|
+
ServiceRequestState storage requestState_ = $
|
302
|
+
.slcGovernanceState[slcCore_]
|
303
|
+
.requestState[i];
|
304
|
+
requests_[i - offset_] = ServiceRequestStateView({
|
305
|
+
requester: requestState_.requester,
|
306
|
+
serviceFee: requestState_.serviceFee,
|
307
|
+
neutralsNumber: requestState_.neutralsNumber,
|
308
|
+
additionalLink: requestState_.additionalLink,
|
309
|
+
selectedNeutrals: requestState_.selectedNeutrals.values(),
|
310
|
+
data: requestState_.data,
|
311
|
+
votingPhase: requestState_.votingPhase,
|
312
|
+
leadingOperationHash: requestState_.leadingOperationHash,
|
313
|
+
requestNonce: requestState_.requestNonce,
|
314
|
+
proposalIds: requestState_.proposalIds
|
315
|
+
});
|
286
316
|
}
|
287
317
|
|
288
318
|
return requests_;
|
@@ -323,21 +353,21 @@ contract Governance is IGovernance, GovernorUpgradeable, UUPSUpgradeable {
|
|
323
353
|
|
324
354
|
SLCProposalState storage proposalState = $.proposalState[proposalId];
|
325
355
|
|
326
|
-
|
327
|
-
proposalState.
|
328
|
-
|
356
|
+
ServiceRequestState storage requestState = $
|
357
|
+
.slcGovernanceState[proposalState.slcCore]
|
358
|
+
.requestState[proposalState.requestNumber];
|
359
|
+
|
360
|
+
uint256 selectedNeutralsLength_ = requestState.selectedNeutrals.length();
|
361
|
+
bytes32[] memory neutralToOperationHashes_ = new bytes32[](selectedNeutralsLength_);
|
329
362
|
|
330
|
-
uint256 selectedNeutralsLength_ = proposalState.selectedNeutrals.length();
|
331
363
|
for (uint256 i = 0; i < selectedNeutralsLength_; ++i) {
|
332
|
-
|
333
|
-
|
334
|
-
];
|
364
|
+
address neutral_ = requestState.selectedNeutrals.at(i);
|
365
|
+
neutralToOperationHashes_[i] = proposalState.neutralToOperation[neutral_];
|
335
366
|
}
|
336
367
|
|
337
368
|
SLCProposalStateView memory proposalData = SLCProposalStateView({
|
338
369
|
neutralsThreshold: proposalState.neutralsThreshold,
|
339
370
|
executorsThreshold: proposalState.executorsThreshold,
|
340
|
-
selectedNeutrals: proposalState.selectedNeutrals.values(),
|
341
371
|
neutralToOperationHashes: neutralToOperationHashes_,
|
342
372
|
operationBundles: proposalState.operationBundles,
|
343
373
|
positiveExecutorVotes: proposalState.positiveExecutorVotes.values(),
|
@@ -379,13 +409,11 @@ contract Governance is IGovernance, GovernorUpgradeable, UUPSUpgradeable {
|
|
379
409
|
}
|
380
410
|
|
381
411
|
function getSystemToken() external view returns (address) {
|
382
|
-
|
383
|
-
return address($.token);
|
412
|
+
return address(_getGovernanceStorage().token);
|
384
413
|
}
|
385
414
|
|
386
415
|
function getParametersRegistry() external view returns (address) {
|
387
|
-
|
388
|
-
return address($.parametersRegistry);
|
416
|
+
return address(_getGovernanceStorage().parametersRegistry);
|
389
417
|
}
|
390
418
|
|
391
419
|
/**
|
@@ -424,77 +452,43 @@ contract Governance is IGovernance, GovernorUpgradeable, UUPSUpgradeable {
|
|
424
452
|
}
|
425
453
|
|
426
454
|
function getNeutralsVotingPeriod() public view returns (uint256) {
|
427
|
-
|
428
|
-
|
429
|
-
try $.parametersRegistry.getUint(NEUTRALS_VOTING_PERIOD_PARAM_NAME) returns (
|
430
|
-
uint256 neutralsVotingPeriod_
|
431
|
-
) {
|
432
|
-
return neutralsVotingPeriod_;
|
433
|
-
} catch {
|
434
|
-
revert Errors.ParameterIsNotSet(
|
435
|
-
address($.parametersRegistry),
|
436
|
-
NEUTRALS_VOTING_PERIOD_PARAM_NAME
|
437
|
-
);
|
438
|
-
}
|
455
|
+
return
|
456
|
+
_getGovernanceStorage().parametersRegistry.getUint(NEUTRALS_VOTING_PERIOD_PARAM_NAME);
|
439
457
|
}
|
440
458
|
|
441
459
|
function getExecutorsVotingPeriod() public view returns (uint256) {
|
442
|
-
|
443
|
-
|
444
|
-
try $.parametersRegistry.getUint(EXECUTORS_VOTING_PERIOD_PARAM_NAME) returns (
|
445
|
-
uint256 executorsVotingPeriod_
|
446
|
-
) {
|
447
|
-
return executorsVotingPeriod_;
|
448
|
-
} catch {
|
449
|
-
revert Errors.ParameterIsNotSet(
|
450
|
-
address($.parametersRegistry),
|
451
|
-
EXECUTORS_VOTING_PERIOD_PARAM_NAME
|
452
|
-
);
|
453
|
-
}
|
460
|
+
return
|
461
|
+
_getGovernanceStorage().parametersRegistry.getUint(EXECUTORS_VOTING_PERIOD_PARAM_NAME);
|
454
462
|
}
|
455
463
|
|
456
464
|
/**
|
457
465
|
* @notice Returns the threshold for the neutrals voting phase. Expected value is in range [0, 100].
|
458
466
|
*/
|
459
467
|
function getNeutralsThreshold() public view returns (uint256) {
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
uint256 neutralsThreshold_
|
464
|
-
) {
|
465
|
-
if (neutralsThreshold_ > 100) {
|
466
|
-
revert NeutralsThresholdTooHigh(neutralsThreshold_);
|
467
|
-
}
|
468
|
+
uint256 neutralsThreshold_ = _getGovernanceStorage().parametersRegistry.getUint(
|
469
|
+
NEUTRALS_THRESHOLD_PARAM_NAME
|
470
|
+
);
|
468
471
|
|
469
|
-
|
470
|
-
|
471
|
-
revert Errors.ParameterIsNotSet(
|
472
|
-
address($.parametersRegistry),
|
473
|
-
NEUTRALS_THRESHOLD_PARAM_NAME
|
474
|
-
);
|
472
|
+
if (neutralsThreshold_ > 100) {
|
473
|
+
revert NeutralsThresholdTooHigh(neutralsThreshold_);
|
475
474
|
}
|
475
|
+
|
476
|
+
return neutralsThreshold_;
|
476
477
|
}
|
477
478
|
|
478
479
|
/**
|
479
480
|
* @notice Returns the threshold for the executors voting phase. Expected value is in range [0, 100].
|
480
481
|
*/
|
481
482
|
function getExecutorsThreshold() public view returns (uint256) {
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
uint256 executorsThreshold_
|
486
|
-
) {
|
487
|
-
if (executorsThreshold_ > 100) {
|
488
|
-
revert ExecutorsThresholdTooHigh(executorsThreshold_);
|
489
|
-
}
|
483
|
+
uint256 executorsThreshold_ = _getGovernanceStorage().parametersRegistry.getUint(
|
484
|
+
EXECUTORS_THRESHOLD_PARAM_NAME
|
485
|
+
);
|
490
486
|
|
491
|
-
|
492
|
-
|
493
|
-
revert Errors.ParameterIsNotSet(
|
494
|
-
address($.parametersRegistry),
|
495
|
-
EXECUTORS_THRESHOLD_PARAM_NAME
|
496
|
-
);
|
487
|
+
if (executorsThreshold_ > 100) {
|
488
|
+
revert ExecutorsThresholdTooHigh(executorsThreshold_);
|
497
489
|
}
|
490
|
+
|
491
|
+
return executorsThreshold_;
|
498
492
|
}
|
499
493
|
|
500
494
|
/**
|
@@ -646,10 +640,7 @@ contract Governance is IGovernance, GovernorUpgradeable, UUPSUpgradeable {
|
|
646
640
|
requestState.additionalLink,
|
647
641
|
requestState.requester
|
648
642
|
);
|
649
|
-
_fillProposalState(
|
650
|
-
$.proposalState[proposalId].selectedNeutrals.values(),
|
651
|
-
newProposalId_
|
652
|
-
);
|
643
|
+
_fillProposalState(newProposalId_);
|
653
644
|
|
654
645
|
emit RejectedByExecutors(proposalId, newProposalId_);
|
655
646
|
}
|
@@ -697,86 +688,27 @@ contract Governance is IGovernance, GovernorUpgradeable, UUPSUpgradeable {
|
|
697
688
|
}
|
698
689
|
|
699
690
|
function _getDAOSLC() internal view returns (address) {
|
700
|
-
|
701
|
-
|
702
|
-
try $.parametersRegistry.getAddr(DAOSLC_PARAM_NAME) returns (address daoslc_) {
|
703
|
-
return daoslc_;
|
704
|
-
} catch {
|
705
|
-
revert Errors.ParameterIsNotSet(address($.parametersRegistry), DAOSLC_PARAM_NAME);
|
706
|
-
}
|
691
|
+
return _getGovernanceStorage().parametersRegistry.getAddr(DAOSLC_PARAM_NAME);
|
707
692
|
}
|
708
693
|
|
709
694
|
function _getExecutorsShare() internal view returns (uint256) {
|
710
|
-
|
711
|
-
|
712
|
-
try $.parametersRegistry.getUint(EXECUTORS_SHARE_PARAM_NAME) returns (
|
713
|
-
uint256 executorsShare_
|
714
|
-
) {
|
715
|
-
return executorsShare_;
|
716
|
-
} catch {
|
717
|
-
revert Errors.ParameterIsNotSet(
|
718
|
-
address($.parametersRegistry),
|
719
|
-
EXECUTORS_SHARE_PARAM_NAME
|
720
|
-
);
|
721
|
-
}
|
695
|
+
return _getGovernanceStorage().parametersRegistry.getUint(EXECUTORS_SHARE_PARAM_NAME);
|
722
696
|
}
|
723
697
|
|
724
698
|
function _getNeutralsShare() internal view returns (uint256) {
|
725
|
-
|
726
|
-
|
727
|
-
try $.parametersRegistry.getUint(NEUTRALS_SHARE_PARAM_NAME) returns (
|
728
|
-
uint256 neutralsShare_
|
729
|
-
) {
|
730
|
-
return neutralsShare_;
|
731
|
-
} catch {
|
732
|
-
revert Errors.ParameterIsNotSet(
|
733
|
-
address($.parametersRegistry),
|
734
|
-
NEUTRALS_SHARE_PARAM_NAME
|
735
|
-
);
|
736
|
-
}
|
699
|
+
return _getGovernanceStorage().parametersRegistry.getUint(NEUTRALS_SHARE_PARAM_NAME);
|
737
700
|
}
|
738
701
|
|
739
702
|
function _getTreasuryShare() internal view returns (uint256) {
|
740
|
-
|
741
|
-
|
742
|
-
try $.parametersRegistry.getUint(TREASURY_SHARE_PARAM_NAME) returns (
|
743
|
-
uint256 treasuryShare_
|
744
|
-
) {
|
745
|
-
return treasuryShare_;
|
746
|
-
} catch {
|
747
|
-
revert Errors.ParameterIsNotSet(
|
748
|
-
address($.parametersRegistry),
|
749
|
-
TREASURY_SHARE_PARAM_NAME
|
750
|
-
);
|
751
|
-
}
|
703
|
+
return _getGovernanceStorage().parametersRegistry.getUint(TREASURY_SHARE_PARAM_NAME);
|
752
704
|
}
|
753
705
|
|
754
706
|
function _getTreasuryAddress() internal view returns (address) {
|
755
|
-
|
756
|
-
|
757
|
-
try $.parametersRegistry.getAddr(TREASURY_ADDRESS_PARAM_NAME) returns (address treasury_) {
|
758
|
-
return treasury_;
|
759
|
-
} catch {
|
760
|
-
revert Errors.ParameterIsNotSet(
|
761
|
-
address($.parametersRegistry),
|
762
|
-
TREASURY_ADDRESS_PARAM_NAME
|
763
|
-
);
|
764
|
-
}
|
707
|
+
return _getGovernanceStorage().parametersRegistry.getAddr(TREASURY_ADDRESS_PARAM_NAME);
|
765
708
|
}
|
766
709
|
|
767
710
|
function _getMinServiceFee() internal view returns (uint256) {
|
768
|
-
|
769
|
-
|
770
|
-
try $.parametersRegistry.getUint(MIN_SERVICE_FEE_PARAM_NAME) returns (
|
771
|
-
uint256 minServiceFee_
|
772
|
-
) {
|
773
|
-
return minServiceFee_;
|
774
|
-
} catch {
|
775
|
-
revert Errors.ParameterIsNotSet(
|
776
|
-
address($.parametersRegistry),
|
777
|
-
MIN_SERVICE_FEE_PARAM_NAME
|
778
|
-
);
|
779
|
-
}
|
711
|
+
return _getGovernanceStorage().parametersRegistry.getUint(MIN_SERVICE_FEE_PARAM_NAME);
|
780
712
|
}
|
781
713
|
|
782
714
|
function _makeProposal(
|
@@ -833,17 +765,14 @@ contract Governance is IGovernance, GovernorUpgradeable, UUPSUpgradeable {
|
|
833
765
|
);
|
834
766
|
}
|
835
767
|
|
836
|
-
function _fillProposalState(
|
768
|
+
function _fillProposalState(uint256 proposalId_) private {
|
837
769
|
GovernanceStorage storage $ = _getGovernanceStorage();
|
838
770
|
|
839
771
|
ServiceRequestState storage requestState = $
|
840
772
|
.slcGovernanceState[$.proposalState[proposalId_].slcCore]
|
841
773
|
.requestState[$.proposalState[proposalId_].requestNumber];
|
842
774
|
|
843
|
-
uint256 neutralsLength_ =
|
844
|
-
for (uint256 i = 0; i < neutralsLength_; ++i) {
|
845
|
-
$.proposalState[proposalId_].selectedNeutrals.add(selectedNeutrals_[i]);
|
846
|
-
}
|
775
|
+
uint256 neutralsLength_ = requestState.selectedNeutrals.length();
|
847
776
|
|
848
777
|
$.proposalState[proposalId_].neutralsThreshold = Math.mulDiv(
|
849
778
|
neutralsLength_,
|