openzeppelin-contracts
openzeppelin-contracts copied to clipboard
Refactor the Checkpoint library, with new key/value balances and new lookup mechanisms
This PR includes quite a few things:
- Procedural generation of the Checkpoint library, automating the support for various key/value lengths
Checkpoints.Checkpoint224: key is uint32 and value is uint224. Usecase: history checkpoints for votingCheckpoints.Checkpoint160: key is uint96 and value is uint160. Usecase: Address sequence (for NFT batch minting)
- For each Checkpoint type, functions availables are:
latest()push(key, value)lowerLookup(key): returns thec.valueof the first checkpoint for whichkey <= c.key(or 0 if no such checkpoint exists)upperLookup(key): returns thec.valueof the last checkpoint for whichkey >= c.key(or 0 if no such checkpoint exists)upperLookupRecent(key): same asupperLookupbut optimised to look in recent checkpoints.
Checkpoint.Historynow uses theCheckpoints.Checkpoint224structure, with block.number for keys.- ~~
getAtBlocknow usesupperLookupRecent, optimizing for recent value lookup~~ → delayed to further PR
- ~~
Fixes #3585
PR Checklist
- [x] Tests
- [ ] Documentation
- [ ] Changelog entry
Uses https://github.com/ethereum/solidity/issues/9117#issuecomment-1198003153 to skip checks