Skip to content

Commit

Permalink
fix: DXO-02 v2
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbeny committed Jul 31, 2024
1 parent 263cfcd commit 0296936
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 50 deletions.
85 changes: 38 additions & 47 deletions packages/contracts/src/DaofinPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ contract DaofinPlugin is BaseDaofinPlugin {
// The incremental ID for proposal types.
CountersUpgradeable.Counter private proposalTypeCounter;

uint256 public masternodeCountSnapshot;
/*
proposalTypeID => committeeID => (VotingSettings struct)
NOTE: holds proposal type id voting information per committee
Expand Down Expand Up @@ -82,27 +83,7 @@ contract DaofinPlugin is BaseDaofinPlugin {
_settings.xdcValidator = IXDCValidator(xdcValidatorContract_);

// Assign and check Election period
for (uint256 i; i < electionPeriod_.length; ) {
uint64 _startDate = electionPeriod_[i];
uint64 _endDate = electionPeriod_[i + 1];

if (_startDate + 1 weeks >= _endDate) revert InValidDate();
_electionPeriods.push(ElectionPeriod(_startDate, _endDate));

emit ElectionPeriodUpdated(_startDate, _endDate);
unchecked {
/*
Receives election periods
in an array
[
startDate1,endDate1,
startDate2,endDate2,
...
]
*/
i = i + 2;
}
}
_updateElectionPeriod(electionPeriod_);

// Assign Proposal Creation costs
proposalCosts = proposalCosts_;
Expand All @@ -116,28 +97,14 @@ contract DaofinPlugin is BaseDaofinPlugin {
// 0 = proposalType - Grants
_createOrModifyProposalType(_createProposalTypeId(), grantSettings_);

// 1 = proposalType - Creation of proposalType
_createOrModifyProposalType(_createProposalTypeId(), generalSettings_);

// 2 = proposalType - Changing voting settings
_createOrModifyProposalType(_createProposalTypeId(), generalSettings_);

// 3 = proposalType - ElectionPeriods
_createOrModifyProposalType(_createProposalTypeId(), generalSettings_);

// 4 = proposalType - Judiciary Replacement
_createOrModifyProposalType(_createProposalTypeId(), generalSettings_);

// 5 = proposalCosts - Proposal Costs
_createOrModifyProposalType(_createProposalTypeId(), generalSettings_);

// set up minimum house deposit amount
_settings.houseMinAmount = allowedAmount_;

// Assign memory to storage
_daofinGlobalSettings = _settings;

_addJudiciaryMember(judiciaries_);
syncXdcValidatorSnapshot();
}

function createProposal(
Expand Down Expand Up @@ -521,19 +488,37 @@ contract DaofinPlugin is BaseDaofinPlugin {
emit JudiciaryChanged(_member, 1);
}

function updateElectionPeriod(
ElectionPeriod[] calldata _periods
) public auth(UPDATE_ELECTION_PERIOD_PERMISSION) {
for (uint256 i; i < _periods.length; i++) {
uint64 _startDate = _periods[i].startDate;
uint64 _endDate = _periods[i].endDate;
if (_startDate > _endDate) revert InValidDate();
function _updateElectionPeriod(uint64[] memory _periods) private {
for (uint256 i; i < _periods.length; ) {
uint64 _startDate = _periods[i];
uint64 _endDate = _periods[i + 1];

if (_startDate + 1 weeks >= _endDate) revert InValidDate();
_electionPeriods.push(ElectionPeriod(_startDate, _endDate));

emit ElectionPeriodUpdated(_startDate, _endDate);
unchecked {
/*
Receives election periods
in an array
[
startDate1,endDate1,
startDate2,endDate2,
...
]
*/
i = i + 2;
}
}
}

function updateElectionPeriod(
uint64[] calldata _periods
) external auth(UPDATE_ELECTION_PERIOD_PERMISSION) {
if (_periods.length == 0) revert();
_updateElectionPeriod(_periods);
}

function updateAllowedAmounts(
uint256 _allowedAmount
) external auth(UPDATE_MIN_HOUSE_AMOUNT_PERMISSION) {
Expand Down Expand Up @@ -591,6 +576,15 @@ contract DaofinPlugin is BaseDaofinPlugin {
emit MasterNodeDelegateeUpdated(masterNode_, delegatee);
}

function syncXdcValidatorSnapshot() public {
if (isWithinProposalSession()) revert InValidTime();

uint256 xdcValidatorCount = _daofinGlobalSettings.xdcValidator.candidateCount();
if (masternodeCountSnapshot != xdcValidatorCount) {
masternodeCountSnapshot = xdcValidatorCount;
}
}

function _createOrUpdateMasterNodeDelegatee(address masterNode_, address delegatee_) private {
address _cachedMasterNode = _masterNodeDelegatee.delegateeToMasterNode[delegatee_];
address _cachedDelegatee = _masterNodeDelegatee.masterNodeToDelegatee[masterNode_];
Expand Down Expand Up @@ -775,10 +769,7 @@ contract DaofinPlugin is BaseDaofinPlugin {

function getTotalNumberOfMembersByCommittee(bytes32 committee_) public view returns (uint256) {
if (committee_ == MasterNodeCommittee) {
(uint256 xdcValidatorCount, uint256 joinedCandidateCount) = getTotalNumberOfMN();
if (isWithinProposalSession() && joinedCandidateCount > xdcValidatorCount)
return joinedCandidateCount;
else return xdcValidatorCount;
return masternodeCountSnapshot;
} else if (committee_ == JudiciaryCommittee) {
return getTotalNumberOfJudiciary();
} else if (committee_ == PeoplesHouseCommittee) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe(PLUGIN_CONTRACT_NAME, function () {
],
[
BigNumber.from(now + 60 * 60 * 24 * 3),
BigNumber.from(now + 60 * 60 * 24 * 5),
BigNumber.from(now + 60 * 60 * 24 * 15),
],
[Bob.address],
parseEther('1'),
Expand Down Expand Up @@ -215,14 +215,20 @@ describe(PLUGIN_CONTRACT_NAME, function () {
])
).to.not.reverted;
const after = await daofinPlugin.proposalTypeCount();
const settings = await daofinPlugin.getCommitteesToVotingSettings(
before,
JudiciaryCommittee
);

expect(100000).eq(settings.supportThreshold);
expect(100001).not.eq(settings.supportThreshold);
expect(before.add(1)).eq(after);
});
});
describe('Modify ProposalType', async () => {
it('Modify Proposal Type', async () => {
const before = await daofinPlugin.proposalTypeCount();
const proposalType = '1';
const proposalType = '0';

await expect(
daofinPlugin.modifyProposalType(proposalType, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe(PLUGIN_CONTRACT_NAME, function () {
],
[
BigNumber.from(now + 60 * 60 * 24 * 3),
BigNumber.from(now + 60 * 60 * 24 * 5),
BigNumber.from(now + 60 * 60 * 24 * 15),
],
[ADDRESS_ONE],
'10',
Expand Down

0 comments on commit 0296936

Please sign in to comment.