Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed conditional in reset but moved state setting higher to reduce… #13

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions src/voting/SimpleGaugeVoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -188,39 +188,40 @@ contract SimpleGaugeVoter is
}

function _reset(uint256 _tokenId) internal {
// get what we need
TokenVoteData storage voteData = tokenVoteData[_tokenId];
address[] storage pastVotes = voteData.gaugesVotedFor;
uint256 votingPowerToRemove = 0;

// reset the global state variables we don't need
voteData.usedVotingPower = 0;
voteData.lastVoted = 0;

// iterate over all the gauges voted for and reset the votes
uint256 votingPowerToRemove = 0;
for (uint256 i = 0; i < pastVotes.length; i++) {
address gauge = pastVotes[i];
uint256 _votes = voteData.votes[gauge];

if (_votes != 0) {
// remove from the total weight and globals
gaugeVotes[gauge] -= _votes;
votingPowerToRemove += _votes;

delete voteData.votes[gauge];

emit Reset({
voter: _msgSender(),
gauge: gauge,
epoch: epochId(),
tokenId: _tokenId,
votingPower: _votes,
totalVotingPower: totalVotingPowerCast - _votes,
timestamp: block.timestamp
});
}
// remove from the total weight and globals
gaugeVotes[gauge] -= _votes;
votingPowerToRemove += _votes;

delete voteData.votes[gauge];

emit Reset({
voter: _msgSender(),
gauge: gauge,
epoch: epochId(),
tokenId: _tokenId,
votingPower: _votes,
totalVotingPower: totalVotingPowerCast - _votes,
timestamp: block.timestamp
});
}

// scrub the global state for the token
// clear the remaining state
voteData.gaugesVotedFor = new address[](0);
totalVotingPowerCast -= votingPowerToRemove;
voteData.usedVotingPower = 0;
voteData.lastVoted = 0;
}

/*///////////////////////////////////////////////////////////////
Expand Down