Skip to content

Commit

Permalink
Fix DMDcoin#49: Ensure quorum uses snapshot of total stake during fin…
Browse files Browse the repository at this point in the history
…alization
  • Loading branch information
MSalman6 committed Jan 2, 2025
1 parent ddc3f87 commit db44659
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions contracts/DiamondDao.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ contract DiamondDao is IDiamondDao, Initializable, ReentrancyGuardUpgradeable, V
/// @dev To keep track of the last DAO phase count for unfinalized proposals check
uint256 public lastDaoPhaseCount;

/// @dev daoEpoch => totalStakeSnapshot - Total stake amount snapshot on voting finalization
mapping(uint256 => uint256) public daoEpochTotalStakeSnapshot;

modifier exists(uint256 proposalId) {
if (!proposalExists(proposalId)) {
revert ProposalNotExist(proposalId);
Expand Down Expand Up @@ -454,9 +457,11 @@ contract DiamondDao is IDiamondDao, Initializable, ReentrancyGuardUpgradeable, V
*/
function quorumReached(uint256 proposalId, ProposalType _type, VotingResult memory result) public view returns (bool) {
uint256 requiredExceeding;
uint256 totalStakedAmount = _getTotalStakedAmount();
uint256 totalVotes = _proposalVoters[proposalId].length();

uint256 daoEpoch = proposals[proposalId].votingDaoEpoch;
uint256 totalStakedAmount = daoEpochTotalStakeSnapshot[daoEpoch];

if (_type == ProposalType.ContractUpgrade) {
requiredExceeding = totalStakedAmount * (50 * 100) / 10000;
} else {
Expand Down Expand Up @@ -490,9 +495,10 @@ contract DiamondDao is IDiamondDao, Initializable, ReentrancyGuardUpgradeable, V
for (uint256 i = 0; i < daoEpochVoters.length; ++i) {
address voter = daoEpochVoters[i];
uint256 stakeAmount = stakingHbbft.stakeAmountTotal(voter);

daoEpochStakeSnapshot[daoEpoch][voter] = stakeAmount;
}

daoEpochTotalStakeSnapshot[daoEpoch] = stakingHbbft.totalStakedAmount();
}

function _submitVote(
Expand Down Expand Up @@ -656,8 +662,4 @@ contract DiamondDao is IDiamondDao, Initializable, ReentrancyGuardUpgradeable, V
}
}
}

function _getTotalStakedAmount() private view returns (uint256) {
return stakingHbbft.totalStakedAmount();
}
}

0 comments on commit db44659

Please sign in to comment.