Skip to content

Commit

Permalink
Replace overriden with overridden in GovernorCountingOverridable.…
Browse files Browse the repository at this point in the history
…sol (#5446)

Co-authored-by: Arr00 <[email protected]>
Co-authored-by: ernestognw <[email protected]>
  • Loading branch information
3 people authored Jan 22, 2025
1 parent 332bcb5 commit 9e66e2f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

### Breaking Changes

- Replace `GovernorCountingOverridable.VoteReceipt` struct parameter member names `hasOverriden` and `overridenWeight` for `hasOverridden` and `overriddenWeight` respectively.

#### Custom error changes

- Replace `GovernorAlreadyOverridenVote` with `GovernorAlreadyOverriddenVote`.

## 5.2.0 (2025-01-08)

### Breaking Changes
Expand Down
34 changes: 17 additions & 17 deletions contracts/governance/extensions/GovernorCountingOverridable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ abstract contract GovernorCountingOverridable is GovernorVotes {

struct VoteReceipt {
uint8 casted; // 0 if vote was not casted. Otherwise: support + 1
bool hasOverriden;
uint208 overridenWeight;
bool hasOverridden;
uint208 overriddenWeight;
}

struct ProposalVote {
Expand All @@ -42,7 +42,7 @@ abstract contract GovernorCountingOverridable is GovernorVotes {
/// @dev A delegated vote on `proposalId` was overridden by `weight`
event OverrideVoteCast(address indexed voter, uint256 proposalId, uint8 support, uint256 weight, string reason);

error GovernorAlreadyOverridenVote(address account);
error GovernorAlreadyOverriddenVote(address account);

mapping(uint256 proposalId => ProposalVote) private _proposalVotes;

Expand Down Expand Up @@ -70,7 +70,7 @@ abstract contract GovernorCountingOverridable is GovernorVotes {
* @dev Check if an `account` has overridden their delegate for a proposal.
*/
function hasVotedOverride(uint256 proposalId, address account) public view virtual returns (bool) {
return _proposalVotes[proposalId].voteReceipt[account].hasOverriden;
return _proposalVotes[proposalId].voteReceipt[account].hasOverridden;
}

/**
Expand Down Expand Up @@ -122,7 +122,7 @@ abstract contract GovernorCountingOverridable is GovernorVotes {
revert GovernorAlreadyCastVote(account);
}

totalWeight -= proposalVote.voteReceipt[account].overridenWeight;
totalWeight -= proposalVote.voteReceipt[account].overriddenWeight;
proposalVote.votes[support] += totalWeight;
proposalVote.voteReceipt[account].casted = support + 1;

Expand All @@ -141,26 +141,26 @@ abstract contract GovernorCountingOverridable is GovernorVotes {
revert GovernorInvalidVoteType();
}

if (proposalVote.voteReceipt[account].hasOverriden) {
revert GovernorAlreadyOverridenVote(account);
if (proposalVote.voteReceipt[account].hasOverridden) {
revert GovernorAlreadyOverriddenVote(account);
}

uint256 snapshot = proposalSnapshot(proposalId);
uint256 overridenWeight = VotesExtended(address(token())).getPastBalanceOf(account, snapshot);
uint256 overriddenWeight = VotesExtended(address(token())).getPastBalanceOf(account, snapshot);
address delegate = VotesExtended(address(token())).getPastDelegate(account, snapshot);
uint8 delegateCasted = proposalVote.voteReceipt[delegate].casted;

proposalVote.voteReceipt[account].hasOverriden = true;
proposalVote.votes[support] += overridenWeight;
proposalVote.voteReceipt[account].hasOverridden = true;
proposalVote.votes[support] += overriddenWeight;
if (delegateCasted == 0) {
proposalVote.voteReceipt[delegate].overridenWeight += SafeCast.toUint208(overridenWeight);
proposalVote.voteReceipt[delegate].overriddenWeight += SafeCast.toUint208(overriddenWeight);
} else {
uint8 delegateSupport = delegateCasted - 1;
proposalVote.votes[delegateSupport] -= overridenWeight;
emit VoteReduced(delegate, proposalId, delegateSupport, overridenWeight);
proposalVote.votes[delegateSupport] -= overriddenWeight;
emit VoteReduced(delegate, proposalId, delegateSupport, overriddenWeight);
}

return overridenWeight;
return overriddenWeight;
}

/// @dev Variant of {Governor-_castVote} that deals with vote overrides. Returns the overridden weight.
Expand All @@ -172,13 +172,13 @@ abstract contract GovernorCountingOverridable is GovernorVotes {
) internal virtual returns (uint256) {
_validateStateBitmap(proposalId, _encodeStateBitmap(ProposalState.Active));

uint256 overridenWeight = _countOverride(proposalId, account, support);
uint256 overriddenWeight = _countOverride(proposalId, account, support);

emit OverrideVoteCast(account, proposalId, support, overridenWeight, reason);
emit OverrideVoteCast(account, proposalId, support, overriddenWeight, reason);

_tallyUpdated(proposalId);

return overridenWeight;
return overriddenWeight;
}

/// @dev Public function for casting an override vote. Returns the overridden weight.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ describe('GovernorCountingOverridable', function () {
.to.emit(this.mock, 'OverrideVoteCast')
.withArgs(this.voter1, this.helper.id, VoteType.Against, ethers.parseEther('10'), '');
await expect(this.mock.connect(this.voter1).castOverrideVote(this.helper.id, VoteType.Abstain, ''))
.to.be.revertedWithCustomError(this.mock, 'GovernorAlreadyOverridenVote')
.to.be.revertedWithCustomError(this.mock, 'GovernorAlreadyOverriddenVote')
.withArgs(this.voter1.address);
});

Expand Down

0 comments on commit 9e66e2f

Please sign in to comment.