Skip to content

Commit

Permalink
feat: add flush to delegate set
Browse files Browse the repository at this point in the history
  • Loading branch information
agusduha committed Jan 5, 2024
1 parent d4e993f commit df91918
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions solidity/contracts/governance/utils/DelegateSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,15 @@ library DelegateSet {
function values(Set storage set) internal view returns (IWonderVotes.Delegate[] memory) {
return set._delegates;
}

/**
* @dev Removes all delegates from a set. O(n).
*/
function flush(Set storage set) internal {
for (uint256 i = 0; i < set._delegates.length; i++) {
delete set._positions[set._delegates[i].account];
}

delete set._delegates;
}
}
5 changes: 3 additions & 2 deletions solidity/contracts/governance/utils/WonderVotes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ abstract contract WonderVotes is Context, EIP712, Nonces, IERC6372, IWonderVotes
if (_weightSum != _weightNormalizer()) revert VotesInvalidWeightSum(_weightSum);

Delegate[] memory _oldDelegates = delegates(account, proposalType);
for (uint256 i = 0; i < _oldDelegates.length; i++) {
_delegatees[account][proposalType].remove(_oldDelegates[i]);

if (_oldDelegates.length > 0) {
_delegatees[account][proposalType].flush();
}

for (uint256 i = 0; i < delegatees.length; i++) {
Expand Down

0 comments on commit df91918

Please sign in to comment.