@@ -40,8 +40,6 @@ abstract contract Checkpoints {
40
40
uint256 newBalance
41
41
);
42
42
43
- function delegate (address delegator , address delegatee ) internal virtual ;
44
-
45
43
function checkpoints (address account , uint32 pos )
46
44
public
47
45
view
@@ -105,88 +103,8 @@ abstract contract Checkpoints {
105
103
return lookupCheckpoint (_totalSupplyCheckpoints, blockNumber);
106
104
}
107
105
108
- /// @notice Encodes a `blockNumber` and `value` into a single `uint128`
109
- /// checkpoint.
110
- /// @dev `blockNumber` is stored in the first 32 bits, while `value` in the
111
- /// remaining 96 bits.
112
- function encodeCheckpoint (uint32 blockNumber , uint96 value )
113
- internal
114
- pure
115
- returns (uint128 )
116
- {
117
- return (uint128 (blockNumber) << 96 ) | uint128 (value);
118
- }
119
-
120
- /// @notice Decodes a block number from a `uint128` `checkpoint`.
121
- function decodeBlockNumber (uint128 checkpoint )
122
- internal
123
- pure
124
- returns (uint32 )
125
- {
126
- return uint32 (bytes4 (bytes16 (checkpoint)));
127
- }
128
-
129
- /// @notice Decodes a voting value from a `uint128` `checkpoint`.
130
- function decodeValue (uint128 checkpoint ) internal pure returns (uint96 ) {
131
- return uint96 (checkpoint);
132
- }
133
-
134
- /// @notice Decodes a block number and voting value from a `uint128`
135
- /// `checkpoint`.
136
- function decodeCheckpoint (uint128 checkpoint )
137
- internal
138
- pure
139
- returns (uint32 blockNumber , uint96 value )
140
- {
141
- blockNumber = decodeBlockNumber (checkpoint);
142
- value = decodeValue (checkpoint);
143
- }
144
-
145
- /// @notice Lookup a value in a list of (sorted) checkpoints.
146
- /// @param ckpts The checkpoints array to use
147
- /// @param blockNumber Block number when we want to get the checkpoint at
148
- function lookupCheckpoint (uint128 [] storage ckpts , uint256 blockNumber )
149
- internal
150
- view
151
- returns (uint96 )
152
- {
153
- // We run a binary search to look for the earliest checkpoint taken
154
- // after `blockNumber`. During the loop, the index of the wanted
155
- // checkpoint remains in the range [low-1, high). With each iteration,
156
- // either `low` or `high` is moved towards the middle of the range to
157
- // maintain the invariant.
158
- // - If the middle checkpoint is after `blockNumber`,
159
- // we look in [low, mid)
160
- // - If the middle checkpoint is before or equal to `blockNumber`,
161
- // we look in [mid+1, high)
162
- // Once we reach a single value (when low == high), we've found the
163
- // right checkpoint at the index high-1, if not out of bounds (in that
164
- // case we're looking too far in the past and the result is 0).
165
- // Note that if the latest checkpoint available is exactly for
166
- // `blockNumber`, we end up with an index that is past the end of the
167
- // array, so we technically don't find a checkpoint after
168
- // `blockNumber`, but it works out the same.
169
- require (blockNumber < block .number , "Block not yet determined " );
170
-
171
- uint256 high = ckpts.length ;
172
- uint256 low = 0 ;
173
- while (low < high) {
174
- uint256 mid = Math.average (low, high);
175
- uint32 midBlock = decodeBlockNumber (ckpts[mid]);
176
- if (midBlock > blockNumber) {
177
- high = mid;
178
- } else {
179
- low = mid + 1 ;
180
- }
181
- }
182
-
183
- return high == 0 ? 0 : decodeValue (ckpts[high - 1 ]);
184
- }
185
-
186
- /// @notice Maximum token supply. Defaults to `type(uint96).max` (2^96 - 1)
187
- function maxSupply () internal view virtual returns (uint96 ) {
188
- return type (uint96 ).max;
189
- }
106
+ /// @notice Change delegation for `delegator` to `delegatee`.
107
+ function delegate (address delegator , address delegatee ) internal virtual ;
190
108
191
109
/// @notice Moves voting power from one delegate to another
192
110
/// @param src Address of old delegate
@@ -254,6 +172,89 @@ abstract contract Checkpoints {
254
172
);
255
173
}
256
174
175
+ /// @notice Lookup a value in a list of (sorted) checkpoints.
176
+ /// @param ckpts The checkpoints array to use
177
+ /// @param blockNumber Block number when we want to get the checkpoint at
178
+ function lookupCheckpoint (uint128 [] storage ckpts , uint256 blockNumber )
179
+ internal
180
+ view
181
+ returns (uint96 )
182
+ {
183
+ // We run a binary search to look for the earliest checkpoint taken
184
+ // after `blockNumber`. During the loop, the index of the wanted
185
+ // checkpoint remains in the range [low-1, high). With each iteration,
186
+ // either `low` or `high` is moved towards the middle of the range to
187
+ // maintain the invariant.
188
+ // - If the middle checkpoint is after `blockNumber`,
189
+ // we look in [low, mid)
190
+ // - If the middle checkpoint is before or equal to `blockNumber`,
191
+ // we look in [mid+1, high)
192
+ // Once we reach a single value (when low == high), we've found the
193
+ // right checkpoint at the index high-1, if not out of bounds (in that
194
+ // case we're looking too far in the past and the result is 0).
195
+ // Note that if the latest checkpoint available is exactly for
196
+ // `blockNumber`, we end up with an index that is past the end of the
197
+ // array, so we technically don't find a checkpoint after
198
+ // `blockNumber`, but it works out the same.
199
+ require (blockNumber < block .number , "Block not yet determined " );
200
+
201
+ uint256 high = ckpts.length ;
202
+ uint256 low = 0 ;
203
+ while (low < high) {
204
+ uint256 mid = Math.average (low, high);
205
+ uint32 midBlock = decodeBlockNumber (ckpts[mid]);
206
+ if (midBlock > blockNumber) {
207
+ high = mid;
208
+ } else {
209
+ low = mid + 1 ;
210
+ }
211
+ }
212
+
213
+ return high == 0 ? 0 : decodeValue (ckpts[high - 1 ]);
214
+ }
215
+
216
+ /// @notice Maximum token supply. Defaults to `type(uint96).max` (2^96 - 1)
217
+ function maxSupply () internal view virtual returns (uint96 ) {
218
+ return type (uint96 ).max;
219
+ }
220
+
221
+ /// @notice Encodes a `blockNumber` and `value` into a single `uint128`
222
+ /// checkpoint.
223
+ /// @dev `blockNumber` is stored in the first 32 bits, while `value` in the
224
+ /// remaining 96 bits.
225
+ function encodeCheckpoint (uint32 blockNumber , uint96 value )
226
+ internal
227
+ pure
228
+ returns (uint128 )
229
+ {
230
+ return (uint128 (blockNumber) << 96 ) | uint128 (value);
231
+ }
232
+
233
+ /// @notice Decodes a block number from a `uint128` `checkpoint`.
234
+ function decodeBlockNumber (uint128 checkpoint )
235
+ internal
236
+ pure
237
+ returns (uint32 )
238
+ {
239
+ return uint32 (bytes4 (bytes16 (checkpoint)));
240
+ }
241
+
242
+ /// @notice Decodes a voting value from a `uint128` `checkpoint`.
243
+ function decodeValue (uint128 checkpoint ) internal pure returns (uint96 ) {
244
+ return uint96 (checkpoint);
245
+ }
246
+
247
+ /// @notice Decodes a block number and voting value from a `uint128`
248
+ /// `checkpoint`.
249
+ function decodeCheckpoint (uint128 checkpoint )
250
+ internal
251
+ pure
252
+ returns (uint32 blockNumber , uint96 value )
253
+ {
254
+ blockNumber = decodeBlockNumber (checkpoint);
255
+ value = decodeValue (checkpoint);
256
+ }
257
+
257
258
// slither-disable-next-line dead-code
258
259
function add (uint256 a , uint256 b ) internal pure returns (uint256 ) {
259
260
return a + b;
0 commit comments