-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade to OZ v5 #66
base: master
Are you sure you want to change the base?
Upgrade to OZ v5 #66
Changes from all commits
eb3d234
415b8c8
20435ac
01337bb
f7df59d
bf77d88
9306f84
e4a7c46
c9aecc4
8f0185f
8ad67a7
4a71532
6e4f417
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.10; | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; | ||
import {Checkpoints} from "@openzeppelin/contracts/utils/Checkpoints.sol"; | ||
import {Checkpoints} from "@openzeppelin/contracts/utils/structs/Checkpoints.sol"; | ||
import {IFractionalGovernor} from "./interfaces/IFractionalGovernor.sol"; | ||
import {IVotingToken} from "./interfaces/IVotingToken.sol"; | ||
|
||
|
@@ -48,7 +48,7 @@ import {IVotingToken} from "./interfaces/IVotingToken.sol"; | |
/// of the rest. | ||
abstract contract FlexVotingClient { | ||
using SafeCast for uint256; | ||
using Checkpoints for Checkpoints.History; | ||
using Checkpoints for Checkpoints.Trace224; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be a 208? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to allign with ERC-5805, then yes |
||
/// @notice The voting options corresponding to those used in the Governor. | ||
enum VoteType { | ||
|
@@ -76,12 +76,12 @@ abstract contract FlexVotingClient { | |
|
||
/// @dev Mapping from address to the checkpoint history of raw balances | ||
/// of that address. | ||
mapping(address => Checkpoints.History) private balanceCheckpoints; | ||
mapping(address => Checkpoints.Trace224) private balanceCheckpoints; | ||
|
||
/// @dev History of the sum total of raw balances in the system. May or may | ||
/// not be equivalent to this contract's balance of `GOVERNOR`s token at a | ||
/// given time. | ||
Checkpoints.History internal totalBalanceCheckpoints; | ||
Checkpoints.Trace224 internal totalBalanceCheckpoints; | ||
|
||
/// @param _governor The address of the flex-voting-compatible governance contract. | ||
constructor(address _governor) { | ||
|
@@ -92,7 +92,7 @@ abstract contract FlexVotingClient { | |
/// token that `_user` has claim to in this system. It may or may not be | ||
/// equivalent to the withdrawable balance of `GOVERNOR`s token for `user`, | ||
/// e.g. if the internal representation of balance has been scaled down. | ||
function _rawBalanceOf(address _user) internal view virtual returns (uint256); | ||
function _rawBalanceOf(address _user) internal view virtual returns (uint224); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed because there is no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Traces are a list of checkpoint. Each checkpoint contains:
such that sizeof(key) + sizeof(value) = 256
|
||
|
||
/// @dev Used as the `reason` param when submitting a vote to `GOVERNOR`. | ||
function _castVoteReasonString() internal virtual returns (string memory) { | ||
|
@@ -194,19 +194,21 @@ abstract contract FlexVotingClient { | |
|
||
/// @dev Checkpoints the _user's current raw balance. | ||
function _checkpointRawBalanceOf(address _user) internal { | ||
balanceCheckpoints[_user].push(_rawBalanceOf(_user)); | ||
balanceCheckpoints[_user].push(SafeCast.toUint32(block.number), _rawBalanceOf(_user)); | ||
} | ||
|
||
/// @notice Returns the `_user`'s raw balance at `_blockNumber`. | ||
/// @param _user The account that's historical raw balance will be looked up. | ||
/// @param _blockNumber The block at which to lookup the _user's raw balance. | ||
function getPastRawBalance(address _user, uint256 _blockNumber) public view returns (uint256) { | ||
return balanceCheckpoints[_user].getAtProbablyRecentBlock(_blockNumber); | ||
uint32 key = SafeCast.toUint32(_blockNumber); | ||
return balanceCheckpoints[_user].upperLookup(key); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
/// @notice Returns the sum total of raw balances of all users at `_blockNumber`. | ||
/// @param _blockNumber The block at which to lookup the total balance. | ||
function getPastTotalBalance(uint256 _blockNumber) public view returns (uint256) { | ||
return totalBalanceCheckpoints.getAtProbablyRecentBlock(_blockNumber); | ||
uint32 key = SafeCast.toUint32(_blockNumber); | ||
return totalBalanceCheckpoints.upperLookup(key); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add more tests