Skip to content

Commit f63e189

Browse files
committed
Rename all the things
1 parent 58248db commit f63e189

9 files changed

+119
-124
lines changed

src/FlexVotingClient.sol

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/FlexVotingDelegatable.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ abstract contract FlexVotingDelegatable is Context, FlexVotingClient {
4848
_updateDelegateBalance(oldDelegate, delegatee, _delta);
4949
}
5050

51-
function _checkpointRawBalanceOf(
51+
function _checkpointVoteWeightOf(
5252
address _user,
5353
int256 _delta
5454
) internal virtual override {
5555
address _proxy = delegates(_user);
56-
_applyDeltaToCheckpoint(balanceCheckpoints[_proxy], _delta);
56+
_applyDeltaToCheckpoint(voteWeightCheckpoints[_proxy], _delta);
5757
}
5858

5959
// @dev Moves delegated votes from one delegate to another.
@@ -62,12 +62,12 @@ abstract contract FlexVotingDelegatable is Context, FlexVotingClient {
6262

6363
// Decrement old delegate's weight.
6464
(uint208 _oldFrom, uint208 _newFrom) =
65-
_applyDeltaToCheckpoint(balanceCheckpoints[from], -_delta);
65+
_applyDeltaToCheckpoint(voteWeightCheckpoints[from], -_delta);
6666
emit DelegateWeightChanged(from, _oldFrom, _newFrom);
6767

6868
// Increment new delegate's weight.
6969
(uint208 _oldTo, uint208 _newTo) =
70-
_applyDeltaToCheckpoint(balanceCheckpoints[to], _delta);
70+
_applyDeltaToCheckpoint(voteWeightCheckpoints[to], _delta);
7171
emit DelegateWeightChanged(to, _oldTo, _newTo);
7272
}
7373
}

test/FlexVotingClient.invariants.t.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,17 @@ contract FlexVotingInvariantTest is FlexVotingInvariantSetup {
107107
uint256 _checkpoint = block.number;
108108
vm.roll(_checkpoint + 1);
109109
assertEq(
110-
flexClient.getPastTotalBalance(_checkpoint),
110+
flexClient.getPastTotalVoteWeight(_checkpoint),
111111
handler.ghost_depositSum() - handler.ghost_withdrawSum()
112112
);
113113

114114
uint256 _sum;
115115
address[] memory _depositors = handler.getActors();
116116
for (uint256 d; d < _depositors.length; d++) {
117117
address _depositor = _depositors[d];
118-
_sum += flexClient.getPastRawBalance(_depositor, _checkpoint);
118+
_sum += flexClient.getPastVoteWeight(_depositor, _checkpoint);
119119
}
120-
assertEq(flexClient.getPastTotalBalance(_checkpoint), _sum);
120+
assertEq(flexClient.getPastTotalVoteWeight(_checkpoint), _sum);
121121
}
122122

123123
function invariant_SumOfDepositsIsGTEProposalVotes() public view {

test/FlexVotingClient.t.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
_RawBalanceOf,
99
_CastVoteReasonString,
1010
_SelfDelegate,
11-
_CheckpointRawBalanceOf,
12-
_CheckpointTotalBalance,
11+
_CheckpointVoteWeightOf,
12+
_CheckpointTotalVoteWeight,
1313
GetPastRawBalance,
1414
GetPastTotalBalance,
1515
Withdraw,
@@ -70,7 +70,7 @@ contract BlockNumberClock__SelfDelegate is _SelfDelegate {
7070
}
7171
}
7272

73-
contract BlockNumberClock__CheckpointRawBalanceOf is _CheckpointRawBalanceOf {
73+
contract BlockNumberClock__CheckpointVoteWeightOf is _CheckpointVoteWeightOf {
7474
function _timestampClock() internal pure override returns (bool) {
7575
return false;
7676
}
@@ -90,7 +90,7 @@ contract BlockNumberClock_GetPastRawBalance is GetPastRawBalance {
9090
}
9191
}
9292

93-
contract BlockNumber__CheckpointTotalBalance is _CheckpointTotalBalance {
93+
contract BlockNumber__CheckpointTotalVoteWeight is _CheckpointTotalVoteWeight {
9494
function _timestampClock() internal pure override returns (bool) {
9595
return false;
9696
}
@@ -211,7 +211,7 @@ contract TimestampClock__SelfDelegate is _SelfDelegate {
211211
}
212212
}
213213

214-
contract TimestampClock__CheckpointRawBalanceOf is _CheckpointRawBalanceOf {
214+
contract TimestampClock__CheckpointVoteWeightOf is _CheckpointVoteWeightOf {
215215
function _timestampClock() internal pure override returns (bool) {
216216
return true;
217217
}
@@ -231,7 +231,7 @@ contract TimestampClock_GetPastRawBalance is GetPastRawBalance {
231231
}
232232
}
233233

234-
contract TimestampClock__CheckpointTotalBalance is _CheckpointTotalBalance {
234+
contract TimestampClock__CheckpointTotalVoteWeight is _CheckpointTotalVoteWeight {
235235
function _timestampClock() internal pure override returns (bool) {
236236
return true;
237237
}

test/FlexVotingDelegatable.t.sol

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import {
1616
_RawBalanceOf,
1717
_CastVoteReasonString,
1818
_SelfDelegate,
19-
_CheckpointRawBalanceOf,
20-
_CheckpointTotalBalance,
19+
_CheckpointVoteWeightOf,
20+
_CheckpointTotalVoteWeight,
2121
GetPastRawBalance,
2222
GetPastTotalBalance,
2323
Withdraw,
@@ -88,8 +88,8 @@ abstract contract Delegation is FlexVotingClientTest {
8888
_mintGovAndDepositIntoFlexClient(_delegate, _delegateWeight);
8989

9090
_advanceTimeBy(1); // Make past balances retrievable.
91-
assertEq(client().getPastRawBalance(_delegate, _now() - 1), _delegateWeight);
92-
assertEq(client().getPastRawBalance(_delegator, _now() - 1), _delegatorWeight);
91+
assertEq(client().getPastVoteWeight(_delegate, _now() - 1), _delegateWeight);
92+
assertEq(client().getPastVoteWeight(_delegator, _now() - 1), _delegatorWeight);
9393

9494
// Delegate.
9595
vm.expectEmit();
@@ -101,8 +101,8 @@ abstract contract Delegation is FlexVotingClientTest {
101101

102102
uint256 _combined = _delegatorWeight + _delegateWeight;
103103
_advanceTimeBy(1); // Make past balances retrievable.
104-
assertEq(client().getPastRawBalance(_delegator, _now() - 1), 0);
105-
assertEq(client().getPastRawBalance(_delegate, _now() - 1), _combined);
104+
assertEq(client().getPastVoteWeight(_delegator, _now() - 1), 0);
105+
assertEq(client().getPastVoteWeight(_delegate, _now() - 1), _combined);
106106

107107
// Create the proposal.
108108
uint256 _proposalId = _createAndSubmitProposal();
@@ -382,14 +382,14 @@ abstract contract Delegation is FlexVotingClientTest {
382382

383383
// The delegator has no weight to vote with, despite having a deposit balance.
384384
assertEq(client().deposits(_delegator), _weight);
385-
assertEq(client().getPastRawBalance(_delegator, _proposalTimepoint), 0);
385+
assertEq(client().getPastVoteWeight(_delegator, _proposalTimepoint), 0);
386386
vm.expectRevert(FVC.FlexVotingClient__NoVotingWeight.selector);
387387
vm.prank(_delegator);
388388
client().expressVote(_proposalId, uint8(_voteType));
389389

390390
// The delegate *has* weight to vote with, despite having no deposit balance.
391391
assertEq(client().deposits(_delegate), 0);
392-
assertEq(client().getPastRawBalance(_delegate, _proposalTimepoint), _weight);
392+
assertEq(client().getPastVoteWeight(_delegate, _proposalTimepoint), _weight);
393393
vm.prank(_delegate);
394394
client().expressVote(_proposalId, uint8(_voteType));
395395

@@ -451,7 +451,7 @@ contract BlockNumber__SelfDelegate is _SelfDelegate {
451451
}
452452
}
453453

454-
contract BlockNumber__CheckpointRawBalanceOf is _CheckpointRawBalanceOf {
454+
contract BlockNumber__CheckpointVoteWeightOf is _CheckpointVoteWeightOf {
455455
function _timestampClock() internal pure override returns (bool) {
456456
return false;
457457
}
@@ -461,7 +461,7 @@ contract BlockNumber__CheckpointRawBalanceOf is _CheckpointRawBalanceOf {
461461
}
462462
}
463463

464-
contract BlockNumber__CheckpointTotalBalance is _CheckpointTotalBalance {
464+
contract BlockNumber__CheckpointTotalVoteWeight is _CheckpointTotalVoteWeight {
465465
function _timestampClock() internal pure override returns (bool) {
466466
return false;
467467
}
@@ -601,7 +601,7 @@ contract TimestampClock__SelfDelegate is _SelfDelegate {
601601
}
602602
}
603603

604-
contract TimestampClock__CheckpointRawBalanceOf is _CheckpointRawBalanceOf {
604+
contract TimestampClock__CheckpointVoteWeightOf is _CheckpointVoteWeightOf {
605605
function _timestampClock() internal pure override returns (bool) {
606606
return true;
607607
}
@@ -611,7 +611,7 @@ contract TimestampClock__CheckpointRawBalanceOf is _CheckpointRawBalanceOf {
611611
}
612612
}
613613

614-
contract TimestampClock__CheckpointTotalBalance is _CheckpointTotalBalance {
614+
contract TimestampClock__CheckpointTotalVoteWeight is _CheckpointTotalVoteWeight {
615615
function _timestampClock() internal pure override returns (bool) {
616616
return true;
617617
}

test/MockFlexVotingClient.sol

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ contract MockFlexVotingClient is FlexVotingClient {
3535
return _rawBalanceOf(_user);
3636
}
3737

38-
function exposed_latestTotalBalance() external view returns (uint208) {
39-
return totalBalanceCheckpoints.latest();
38+
function exposed_latestTotalWeight() external view returns (uint208) {
39+
return totalVoteWeightCheckpoints.latest();
4040
}
4141

42-
function exposed_checkpointTotalBalance(int256 _delta) external {
43-
return _checkpointTotalBalance(_delta);
42+
function exposed_checkpointTotalVoteWeight(int256 _delta) external {
43+
return _checkpointTotalVoteWeight(_delta);
4444
}
4545

4646
function exposed_castVoteReasonString() external returns (string memory) {
@@ -55,8 +55,8 @@ contract MockFlexVotingClient is FlexVotingClient {
5555
deposits[_user] = _amount;
5656
}
5757

58-
function exposed_checkpointRawBalanceOf(address _user, int256 _delta) external {
59-
_checkpointRawBalanceOf(_user, _delta);
58+
function exposed_checkpointVoteWeightOf(address _user, int256 _delta) external {
59+
_checkpointVoteWeightOf(_user, _delta);
6060
}
6161
// End test hooks
6262
// ---------------------------------------------------------------------------
@@ -67,8 +67,8 @@ contract MockFlexVotingClient is FlexVotingClient {
6767
deposits[msg.sender] += _amount;
6868

6969
int256 _delta = int256(uint256(_amount));
70-
_checkpointRawBalanceOf(msg.sender, _delta);
71-
_checkpointTotalBalance(_delta);
70+
_checkpointVoteWeightOf(msg.sender, _delta);
71+
_checkpointTotalVoteWeight(_delta);
7272

7373
// Assumes revert on failure.
7474
TOKEN.transferFrom(msg.sender, address(this), _amount);
@@ -81,8 +81,8 @@ contract MockFlexVotingClient is FlexVotingClient {
8181
deposits[msg.sender] -= _amount;
8282

8383
int256 _delta = -1 * int256(uint256(_amount));
84-
_checkpointRawBalanceOf(msg.sender, _delta);
85-
_checkpointTotalBalance(_delta);
84+
_checkpointVoteWeightOf(msg.sender, _delta);
85+
_checkpointTotalVoteWeight(_delta);
8686

8787
TOKEN.transfer(msg.sender, _amount); // Assumes revert on failure.
8888
}

0 commit comments

Comments
 (0)