Skip to content

Commit 692d8c8

Browse files
ToonVanHoveAmxx
andauthored
Fix lookup documentation in ERC20Votes and Checkpoints (OpenZeppelin#4218)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
1 parent 72ed4ca commit 692d8c8

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

contracts/token/ERC20/extensions/ERC20Votes.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ abstract contract ERC20Votes is ERC20Permit, IERC5805 {
114114
* @dev Lookup a value in a list of (sorted) checkpoints.
115115
*/
116116
function _checkpointsLookup(Checkpoint[] storage ckpts, uint256 timepoint) private view returns (uint256) {
117-
// We run a binary search to look for the earliest checkpoint taken after `timepoint`.
117+
// We run a binary search to look for the last (most recent) checkpoint taken before (or at) `timepoint`.
118118
//
119119
// Initially we check if the block is recent to narrow the search range.
120120
// During the loop, the index of the wanted checkpoint remains in the range [low-1, high).

contracts/utils/Checkpoints.sol

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ library Checkpoints {
151151
}
152152

153153
/**
154-
* @dev Return the index of the oldest checkpoint whose key is greater than the search key, or `high` if there is none.
154+
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high` if there is none.
155155
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive `high`.
156156
*
157157
* WARNING: `high` should not be greater than the array's length.
@@ -174,7 +174,7 @@ library Checkpoints {
174174
}
175175

176176
/**
177-
* @dev Return the index of the oldest checkpoint whose key is greater or equal than the search key, or `high` if there is none.
177+
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or `high` if there is none.
178178
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive `high`.
179179
*
180180
* WARNING: `high` should not be greater than the array's length.
@@ -225,7 +225,7 @@ library Checkpoints {
225225
}
226226

227227
/**
228-
* @dev Returns the value in the oldest checkpoint with key greater or equal than the search key, or zero if there is none.
228+
* @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if there is none.
229229
*/
230230
function lowerLookup(Trace224 storage self, uint32 key) internal view returns (uint224) {
231231
uint256 len = self._checkpoints.length;
@@ -234,7 +234,7 @@ library Checkpoints {
234234
}
235235

236236
/**
237-
* @dev Returns the value in the most recent checkpoint with key lower or equal than the search key.
237+
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key.
238238
*/
239239
function upperLookup(Trace224 storage self, uint32 key) internal view returns (uint224) {
240240
uint256 len = self._checkpoints.length;
@@ -243,7 +243,7 @@ library Checkpoints {
243243
}
244244

245245
/**
246-
* @dev Returns the value in the most recent checkpoint with key lower or equal than the search key.
246+
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key.
247247
*
248248
* NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint (checkpoints with high keys).
249249
*/
@@ -324,7 +324,7 @@ library Checkpoints {
324324
}
325325

326326
/**
327-
* @dev Return the index of the oldest checkpoint whose key is greater than the search key, or `high` if there is none.
327+
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high` if there is none.
328328
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive `high`.
329329
*
330330
* WARNING: `high` should not be greater than the array's length.
@@ -347,7 +347,7 @@ library Checkpoints {
347347
}
348348

349349
/**
350-
* @dev Return the index of the oldest checkpoint whose key is greater or equal than the search key, or `high` if there is none.
350+
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or `high` if there is none.
351351
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive `high`.
352352
*
353353
* WARNING: `high` should not be greater than the array's length.
@@ -401,7 +401,7 @@ library Checkpoints {
401401
}
402402

403403
/**
404-
* @dev Returns the value in the oldest checkpoint with key greater or equal than the search key, or zero if there is none.
404+
* @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if there is none.
405405
*/
406406
function lowerLookup(Trace160 storage self, uint96 key) internal view returns (uint160) {
407407
uint256 len = self._checkpoints.length;
@@ -410,7 +410,7 @@ library Checkpoints {
410410
}
411411

412412
/**
413-
* @dev Returns the value in the most recent checkpoint with key lower or equal than the search key.
413+
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key.
414414
*/
415415
function upperLookup(Trace160 storage self, uint96 key) internal view returns (uint160) {
416416
uint256 len = self._checkpoints.length;
@@ -419,7 +419,7 @@ library Checkpoints {
419419
}
420420

421421
/**
422-
* @dev Returns the value in the most recent checkpoint with key lower or equal than the search key.
422+
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key.
423423
*
424424
* NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint (checkpoints with high keys).
425425
*/
@@ -500,7 +500,7 @@ library Checkpoints {
500500
}
501501

502502
/**
503-
* @dev Return the index of the oldest checkpoint whose key is greater than the search key, or `high` if there is none.
503+
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high` if there is none.
504504
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive `high`.
505505
*
506506
* WARNING: `high` should not be greater than the array's length.
@@ -523,7 +523,7 @@ library Checkpoints {
523523
}
524524

525525
/**
526-
* @dev Return the index of the oldest checkpoint whose key is greater or equal than the search key, or `high` if there is none.
526+
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or `high` if there is none.
527527
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive `high`.
528528
*
529529
* WARNING: `high` should not be greater than the array's length.

scripts/generate/templates/Checkpoints.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function push(
4646
}
4747
4848
/**
49-
* @dev Returns the value in the oldest checkpoint with key greater or equal than the search key, or zero if there is none.
49+
* @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if there is none.
5050
*/
5151
function lowerLookup(${opts.historyTypeName} storage self, ${opts.keyTypeName} key) internal view returns (${opts.valueTypeName}) {
5252
uint256 len = self.${opts.checkpointFieldName}.length;
@@ -55,7 +55,7 @@ function lowerLookup(${opts.historyTypeName} storage self, ${opts.keyTypeName} k
5555
}
5656
5757
/**
58-
* @dev Returns the value in the most recent checkpoint with key lower or equal than the search key.
58+
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key.
5959
*/
6060
function upperLookup(${opts.historyTypeName} storage self, ${opts.keyTypeName} key) internal view returns (${opts.valueTypeName}) {
6161
uint256 len = self.${opts.checkpointFieldName}.length;
@@ -64,7 +64,7 @@ function upperLookup(${opts.historyTypeName} storage self, ${opts.keyTypeName} k
6464
}
6565
6666
/**
67-
* @dev Returns the value in the most recent checkpoint with key lower or equal than the search key.
67+
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key.
6868
*
6969
* NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint (checkpoints with high keys).
7070
*/
@@ -227,7 +227,7 @@ function _insert(
227227
}
228228
229229
/**
230-
* @dev Return the index of the oldest checkpoint whose key is greater than the search key, or \`high\` if there is none.
230+
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or \`high\` if there is none.
231231
* \`low\` and \`high\` define a section where to do the search, with inclusive \`low\` and exclusive \`high\`.
232232
*
233233
* WARNING: \`high\` should not be greater than the array's length.
@@ -250,7 +250,7 @@ function _upperBinaryLookup(
250250
}
251251
252252
/**
253-
* @dev Return the index of the oldest checkpoint whose key is greater or equal than the search key, or \`high\` if there is none.
253+
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or \`high\` if there is none.
254254
* \`low\` and \`high\` define a section where to do the search, with inclusive \`low\` and exclusive \`high\`.
255255
*
256256
* WARNING: \`high\` should not be greater than the array's length.

0 commit comments

Comments
 (0)