Replace `overriden` with `overridden` in GovernorCountingOverridable.sol (#5446)

Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com>
Co-authored-by: ernestognw <ernestognw@gmail.com>
pull/5459/head
planetBoy 1 week ago committed by GitHub
parent 332bcb5f4d
commit 9e66e2f9f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      CHANGELOG.md
  2. 34
      contracts/governance/extensions/GovernorCountingOverridable.sol
  3. 2
      test/governance/extensions/GovernorCountingOverridable.test.js

@ -1,5 +1,13 @@
# Changelog # 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) ## 5.2.0 (2025-01-08)
### Breaking Changes ### Breaking Changes

@ -27,8 +27,8 @@ abstract contract GovernorCountingOverridable is GovernorVotes {
struct VoteReceipt { struct VoteReceipt {
uint8 casted; // 0 if vote was not casted. Otherwise: support + 1 uint8 casted; // 0 if vote was not casted. Otherwise: support + 1
bool hasOverriden; bool hasOverridden;
uint208 overridenWeight; uint208 overriddenWeight;
} }
struct ProposalVote { struct ProposalVote {
@ -42,7 +42,7 @@ abstract contract GovernorCountingOverridable is GovernorVotes {
/// @dev A delegated vote on `proposalId` was overridden by `weight` /// @dev A delegated vote on `proposalId` was overridden by `weight`
event OverrideVoteCast(address indexed voter, uint256 proposalId, uint8 support, uint256 weight, string reason); 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; mapping(uint256 proposalId => ProposalVote) private _proposalVotes;
@ -70,7 +70,7 @@ abstract contract GovernorCountingOverridable is GovernorVotes {
* @dev Check if an `account` has overridden their delegate for a proposal. * @dev Check if an `account` has overridden their delegate for a proposal.
*/ */
function hasVotedOverride(uint256 proposalId, address account) public view virtual returns (bool) { function hasVotedOverride(uint256 proposalId, address account) public view virtual returns (bool) {
return _proposalVotes[proposalId].voteReceipt[account].hasOverriden; return _proposalVotes[proposalId].voteReceipt[account].hasOverridden;
} }
/** /**
@ -122,7 +122,7 @@ abstract contract GovernorCountingOverridable is GovernorVotes {
revert GovernorAlreadyCastVote(account); revert GovernorAlreadyCastVote(account);
} }
totalWeight -= proposalVote.voteReceipt[account].overridenWeight; totalWeight -= proposalVote.voteReceipt[account].overriddenWeight;
proposalVote.votes[support] += totalWeight; proposalVote.votes[support] += totalWeight;
proposalVote.voteReceipt[account].casted = support + 1; proposalVote.voteReceipt[account].casted = support + 1;
@ -141,26 +141,26 @@ abstract contract GovernorCountingOverridable is GovernorVotes {
revert GovernorInvalidVoteType(); revert GovernorInvalidVoteType();
} }
if (proposalVote.voteReceipt[account].hasOverriden) { if (proposalVote.voteReceipt[account].hasOverridden) {
revert GovernorAlreadyOverridenVote(account); revert GovernorAlreadyOverriddenVote(account);
} }
uint256 snapshot = proposalSnapshot(proposalId); 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); address delegate = VotesExtended(address(token())).getPastDelegate(account, snapshot);
uint8 delegateCasted = proposalVote.voteReceipt[delegate].casted; uint8 delegateCasted = proposalVote.voteReceipt[delegate].casted;
proposalVote.voteReceipt[account].hasOverriden = true; proposalVote.voteReceipt[account].hasOverridden = true;
proposalVote.votes[support] += overridenWeight; proposalVote.votes[support] += overriddenWeight;
if (delegateCasted == 0) { if (delegateCasted == 0) {
proposalVote.voteReceipt[delegate].overridenWeight += SafeCast.toUint208(overridenWeight); proposalVote.voteReceipt[delegate].overriddenWeight += SafeCast.toUint208(overriddenWeight);
} else { } else {
uint8 delegateSupport = delegateCasted - 1; uint8 delegateSupport = delegateCasted - 1;
proposalVote.votes[delegateSupport] -= overridenWeight; proposalVote.votes[delegateSupport] -= overriddenWeight;
emit VoteReduced(delegate, proposalId, delegateSupport, overridenWeight); emit VoteReduced(delegate, proposalId, delegateSupport, overriddenWeight);
} }
return overridenWeight; return overriddenWeight;
} }
/// @dev Variant of {Governor-_castVote} that deals with vote overrides. Returns the overridden weight. /// @dev Variant of {Governor-_castVote} that deals with vote overrides. Returns the overridden weight.
@ -172,13 +172,13 @@ abstract contract GovernorCountingOverridable is GovernorVotes {
) internal virtual returns (uint256) { ) internal virtual returns (uint256) {
_validateStateBitmap(proposalId, _encodeStateBitmap(ProposalState.Active)); _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); _tallyUpdated(proposalId);
return overridenWeight; return overriddenWeight;
} }
/// @dev Public function for casting an override vote. Returns the overridden weight. /// @dev Public function for casting an override vote. Returns the overridden weight.

@ -264,7 +264,7 @@ describe('GovernorCountingOverridable', function () {
.to.emit(this.mock, 'OverrideVoteCast') .to.emit(this.mock, 'OverrideVoteCast')
.withArgs(this.voter1, this.helper.id, VoteType.Against, ethers.parseEther('10'), ''); .withArgs(this.voter1, this.helper.id, VoteType.Against, ethers.parseEther('10'), '');
await expect(this.mock.connect(this.voter1).castOverrideVote(this.helper.id, VoteType.Abstain, '')) 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); .withArgs(this.voter1.address);
}); });

Loading…
Cancel
Save