@@ -79,14 +79,15 @@ abstract contract FlexVotingClient {
7979 /// must be one that supports fractional voting, e.g. GovernorCountingFractional.
8080 IFractionalGovernor public immutable GOVERNOR;
8181
82- /// @dev Mapping from address to the checkpoint history of raw balances
83- /// of that address.
84- mapping (address => Checkpoints.Trace208) internal balanceCheckpoints;
82+ /// @dev Mapping from address to the checkpoint history of internal voting
83+ /// weight for that address, i.e. how much weight they can call `expressVote`
84+ /// with at a given time.
85+ mapping (address => Checkpoints.Trace208) internal voteWeightCheckpoints;
8586
86- /// @dev History of the sum total of raw balances in the system. May or may
87+ /// @dev History of the sum total of voting weight in the system. May or may
8788 /// not be equivalent to this contract's balance of `GOVERNOR`s token at a
8889 /// given time.
89- Checkpoints.Trace208 internal totalBalanceCheckpoints ;
90+ Checkpoints.Trace208 internal totalVoteWeightCheckpoints ;
9091
9192 // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/7b74442c5e87ea51dde41c7f18a209fa5154f1a4/contracts/governance/extensions/GovernorCountingFractional.sol#L37
9293 uint8 internal constant VOTE_TYPE_FRACTIONAL = 255 ;
@@ -124,7 +125,7 @@ abstract contract FlexVotingClient {
124125 /// @param support The depositor's vote preferences in accordance with the `VoteType` enum.
125126 function expressVote (uint256 proposalId , uint8 support ) external virtual {
126127 address voter = msg .sender ;
127- uint256 weight = getPastRawBalance (voter, GOVERNOR.proposalSnapshot (proposalId));
128+ uint256 weight = getPastVoteWeight (voter, GOVERNOR.proposalSnapshot (proposalId));
128129 if (weight == 0 ) revert FlexVotingClient__NoVotingWeight ();
129130
130131 if (proposalVotersHasVoted[proposalId][voter]) revert FlexVotingClient__AlreadyVoted ();
@@ -143,10 +144,12 @@ abstract contract FlexVotingClient {
143144 }
144145
145146 /// @notice Causes this contract to cast a vote to the Governor for all of the
146- /// accumulated votes expressed by users. Uses the sum of all raw balances to
147- /// proportionally split its voting weight. Can be called by anyone. Can be
148- /// called multiple times during the lifecycle of a given proposal.
149- /// @param proposalId The ID of the proposal which the Pool will now vote on.
147+ /// accumulated votes expressed by users. Uses the total internal vote weight
148+ /// to proportionally split weight among expressed votes. Can be called by
149+ /// anyone. It is idempotent and can be called multiple times during the
150+ /// lifecycle of a given proposal.
151+ /// @param proposalId The ID of the proposal which the FlexVotingClient will
152+ /// now vote on.
150153 function castVote (uint256 proposalId ) external {
151154 ProposalVote storage _proposalVote = proposalVotes[proposalId];
152155 if (_proposalVote.forVotes + _proposalVote.againstVotes + _proposalVote.abstainVotes == 0 ) {
@@ -155,7 +158,7 @@ abstract contract FlexVotingClient {
155158
156159 uint256 _proposalSnapshot = GOVERNOR.proposalSnapshot (proposalId);
157160
158- // We use the snapshot of total raw balances to determine the weight with
161+ // We use the snapshot of total vote weight to determine the weight with
159162 // which to vote. We do this for two reasons:
160163 // (1) We cannot use the proposalVote numbers alone, since some people with
161164 // balances at the snapshot might never express their preferences. If a
@@ -168,28 +171,28 @@ abstract contract FlexVotingClient {
168171 // earlier call to this function. The weight of those preferences
169172 // should still be taken into consideration when determining how much
170173 // weight to vote with this time.
171- // Using the total raw balance to proportion votes in this way means that in
174+ // Using the total vote weight to proportion votes in this way means that in
172175 // many circumstances this function will not cast votes with all of its
173176 // weight.
174- uint256 _totalRawBalanceAtSnapshot = getPastTotalBalance (_proposalSnapshot);
177+ uint256 _totalVotesInternal = getPastTotalVoteWeight (_proposalSnapshot);
175178
176179 // We need 256 bits because of the multiplication we're about to do.
177- uint256 _votingWeightAtSnapshot =
180+ uint256 _totalTokenWeight =
178181 IVotingToken (address (GOVERNOR.token ())).getPastVotes (address (this ), _proposalSnapshot);
179182
180- // forVotesRaw forVoteWeight
181- // --------------------- = ------------------
182- // totalRawBalance totalVoteWeight
183+ // userVotesInternal userVoteWeight
184+ // ------------------------- = -- ------------------
185+ // totalVotesInternal totalTokenWeight
183186 //
184- // forVoteWeight = forVotesRaw * totalVoteWeight / totalRawBalance
187+ // userVoteWeight = userVotesInternal * totalTokenWeight / totalVotesInternal
185188 uint128 _forVotesToCast = SafeCast.toUint128 (
186- (_votingWeightAtSnapshot * _proposalVote.forVotes) / _totalRawBalanceAtSnapshot
189+ (_totalTokenWeight * _proposalVote.forVotes) / _totalVotesInternal
187190 );
188191 uint128 _againstVotesToCast = SafeCast.toUint128 (
189- (_votingWeightAtSnapshot * _proposalVote.againstVotes) / _totalRawBalanceAtSnapshot
192+ (_totalTokenWeight * _proposalVote.againstVotes) / _totalVotesInternal
190193 );
191194 uint128 _abstainVotesToCast = SafeCast.toUint128 (
192- (_votingWeightAtSnapshot * _proposalVote.abstainVotes) / _totalRawBalanceAtSnapshot
195+ (_totalTokenWeight * _proposalVote.abstainVotes) / _totalVotesInternal
193196 );
194197
195198 // Clear the stored votes so that we don't double-cast them.
@@ -206,11 +209,9 @@ abstract contract FlexVotingClient {
206209 Checkpoints.Trace208 storage _checkpoint ,
207210 int256 _delta
208211 ) internal returns (uint208 _prevTotal , uint208 _newTotal ) {
209-
210212 // The casting in this function is safe since:
211213 // - if oldTotal + delta > int256.max it will panic and revert.
212- // - if |delta| <= oldTotal
213- // * there is no risk of wrapping
214+ // - if |delta| <= oldTotal there is no risk of wrapping
214215 // - if |delta| > oldTotal
215216 // * uint256(oldTotal + delta) will wrap but the wrapped value will
216217 // necessarily be greater than uint208.max, so SafeCast will revert.
@@ -232,35 +233,35 @@ abstract contract FlexVotingClient {
232233 _checkpoint.push (_timepoint, _newTotal);
233234 }
234235
235- /// @dev Checkpoints the _user's current raw balance .
236- function _checkpointRawBalanceOf (
236+ /// @dev Checkpoints internal voting weight of `user` after applying `_delta` .
237+ function _checkpointVoteWeightOf (
237238 address _user ,
238239 int256 _delta
239240 ) internal virtual {
240- _applyDeltaToCheckpoint (balanceCheckpoints [_user], _delta);
241+ _applyDeltaToCheckpoint (voteWeightCheckpoints [_user], _delta);
241242 }
242243
243- /// @dev Checkpoints the total balance after applying `_delta`.
244- function _checkpointTotalBalance (int256 _delta ) internal virtual {
245- _applyDeltaToCheckpoint (totalBalanceCheckpoints , _delta);
244+ /// @dev Checkpoints the total vote weight after applying `_delta`.
245+ function _checkpointTotalVoteWeight (int256 _delta ) internal virtual {
246+ _applyDeltaToCheckpoint (totalVoteWeightCheckpoints , _delta);
246247 }
247248
248- /// @notice Returns the `_user`'s raw balance at `_timepoint`.
249- /// @param _user The account that's historical raw balance will be looked up.
250- /// @param _timepoint The timepoint at which to lookup the _user's raw
251- /// balance , either a block number or a timestamp as determined by
249+ /// @notice Returns the `_user`'s internal voting weight at `_timepoint`.
250+ /// @param _user The account that's historical vote weight will be looked up.
251+ /// @param _timepoint The timepoint at which to lookup the _user's internal
252+ /// voting weight , either a block number or a timestamp as determined by
252253 /// {GOVERNOR.token().clock()}.
253- function getPastRawBalance (address _user , uint256 _timepoint ) public view returns (uint256 ) {
254+ function getPastVoteWeight (address _user , uint256 _timepoint ) public view returns (uint256 ) {
254255 uint48 key = SafeCast.toUint48 (_timepoint);
255- return balanceCheckpoints [_user].upperLookup (key);
256+ return voteWeightCheckpoints [_user].upperLookup (key);
256257 }
257258
258- /// @notice Returns the sum total of raw balances of all users at `_timepoint`.
259- /// @param _timepoint The timepoint at which to lookup the total balance ,
259+ /// @notice Returns the total internal voting weight of all users at `_timepoint`.
260+ /// @param _timepoint The timepoint at which to lookup the total weight ,
260261 /// either a block number or a timestamp as determined by
261262 /// {GOVERNOR.token().clock()}.
262- function getPastTotalBalance (uint256 _timepoint ) public view returns (uint256 ) {
263+ function getPastTotalVoteWeight (uint256 _timepoint ) public view returns (uint256 ) {
263264 uint48 key = SafeCast.toUint48 (_timepoint);
264- return totalBalanceCheckpoints .upperLookup (key);
265+ return totalVoteWeightCheckpoints .upperLookup (key);
265266 }
266267}
0 commit comments