Skip to content

Commit d7b304e

Browse files
alexkeatingdavidlapradeapbendi
authored
Upgrade to OZ v5 (#66)
* WIP * Can compile * Fix tests and remove signature override * Format code * Cleanup pr * Remove additional nonce code * Fix compilation * Lower test coverage * Convert GovernorCountingFractional to use error types * Improve natspec * Add SPDX license identifier to FlexVotingClient * Update the compiler version to the latest, and match pragmas to OpenZeppelin * Switch to Checkpoints.Trace208 * Make IFractionalGovernor.token a view function * Create mock FlexVotingClient for testing * Add boilerplate for FlexVotingClient tests * Implement deposit and withdraw for the mock * Fix balance checkpointing in MockFlexVotingClient * Add a voting test for FlexVotingClient * Implement borrowing in MockFlexVotingClient * Add a bunch more voting tests * Add more voting tests * Add a basic borrow test * hodler -> user * Test that castVote can be called multiple times * Add tests for `borrow` and `withdraw` * Test that users can't expressVote with bogus support types * holder --> user * Test casting without any votes expressed * Assume lender is not borrower * forge fmt * Fix test name for scopelint conventions * Bump to latest solc * Bump coverage threshold * Use existing enums * Use absolute paths for imports * forge fmt --------- Co-authored-by: David Laprade <[email protected]> Co-authored-by: Ben DiFrancesco <[email protected]>
1 parent d81f597 commit d7b304e

17 files changed

+1110
-460
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ jobs:
106106
uses: zgosalvez/github-actions-report-lcov@v2
107107
with:
108108
coverage-files: ./lcov.info
109-
minimum-coverage: 70 # Set coverage threshold.
109+
minimum-coverage: 92 # Set coverage threshold.
110110

111111
slither-analyze:
112112
runs-on: ubuntu-latest

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
url = https://github.com/foundry-rs/forge-std
77
[submodule "lib/openzeppelin-contracts"]
88
path = lib/openzeppelin-contracts
9-
url = https://github.com/openzeppelin/openzeppelin-contracts
9+
url = https://github.com/OpenZeppelin/openzeppelin-contracts

foundry.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
[profile.default]
2-
# We don't specify a solc version because Aave contracts are pinned to 0.8.10,
3-
# but we use more recent solc versions for other contracts, so we let forge
4-
# auto-detect solc versions.
52
optimizer = true
63
optimizer_runs = 10_000_000
74
remappings = ["@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts"]
5+
solc_version = '0.8.28'
86
verbosity = 3
97

108
[profile.ci]

lib/openzeppelin-contracts

script/Deploy.s.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
3-
pragma solidity ^0.8.10;
2+
pragma solidity ^0.8.20;
43

54
import "forge-std/Script.sol";
65

src/FlexVotingClient.sol

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// SPDX-License-Identifier: UNLICENSED
2-
pragma solidity >=0.8.10;
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
33

44
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
5-
import {Checkpoints} from "@openzeppelin/contracts/utils/Checkpoints.sol";
5+
import {Checkpoints} from "@openzeppelin/contracts/utils/structs/Checkpoints.sol";
66
import {IFractionalGovernor} from "./interfaces/IFractionalGovernor.sol";
77
import {IVotingToken} from "./interfaces/IVotingToken.sol";
88

@@ -48,7 +48,12 @@ import {IVotingToken} from "./interfaces/IVotingToken.sol";
4848
/// of the rest.
4949
abstract contract FlexVotingClient {
5050
using SafeCast for uint256;
51-
using Checkpoints for Checkpoints.History;
51+
52+
// @dev Trace208 is used instead of Trace224 because the former allocates 48
53+
// bits to its _key. We need at least 48 bits because the _key is going to be
54+
// a block number. And EIP-6372 specifies that when block numbers are used for
55+
// internal clocks (as they are for ERC20Votes) they need to be uint48s.
56+
using Checkpoints for Checkpoints.Trace208;
5257

5358
/// @notice The voting options corresponding to those used in the Governor.
5459
enum VoteType {
@@ -76,12 +81,12 @@ abstract contract FlexVotingClient {
7681

7782
/// @dev Mapping from address to the checkpoint history of raw balances
7883
/// of that address.
79-
mapping(address => Checkpoints.History) private balanceCheckpoints;
84+
mapping(address => Checkpoints.Trace208) private balanceCheckpoints;
8085

8186
/// @dev History of the sum total of raw balances in the system. May or may
8287
/// not be equivalent to this contract's balance of `GOVERNOR`s token at a
8388
/// given time.
84-
Checkpoints.History internal totalBalanceCheckpoints;
89+
Checkpoints.Trace208 internal totalBalanceCheckpoints;
8590

8691
/// @param _governor The address of the flex-voting-compatible governance contract.
8792
constructor(address _governor) {
@@ -92,7 +97,7 @@ abstract contract FlexVotingClient {
9297
/// token that `_user` has claim to in this system. It may or may not be
9398
/// equivalent to the withdrawable balance of `GOVERNOR`s token for `user`,
9499
/// e.g. if the internal representation of balance has been scaled down.
95-
function _rawBalanceOf(address _user) internal view virtual returns (uint256);
100+
function _rawBalanceOf(address _user) internal view virtual returns (uint208);
96101

97102
/// @dev Used as the `reason` param when submitting a vote to `GOVERNOR`.
98103
function _castVoteReasonString() internal virtual returns (string memory) {
@@ -194,19 +199,21 @@ abstract contract FlexVotingClient {
194199

195200
/// @dev Checkpoints the _user's current raw balance.
196201
function _checkpointRawBalanceOf(address _user) internal {
197-
balanceCheckpoints[_user].push(_rawBalanceOf(_user));
202+
balanceCheckpoints[_user].push(SafeCast.toUint48(block.number), _rawBalanceOf(_user));
198203
}
199204

200205
/// @notice Returns the `_user`'s raw balance at `_blockNumber`.
201206
/// @param _user The account that's historical raw balance will be looked up.
202207
/// @param _blockNumber The block at which to lookup the _user's raw balance.
203208
function getPastRawBalance(address _user, uint256 _blockNumber) public view returns (uint256) {
204-
return balanceCheckpoints[_user].getAtProbablyRecentBlock(_blockNumber);
209+
uint48 key = SafeCast.toUint48(_blockNumber);
210+
return balanceCheckpoints[_user].upperLookup(key);
205211
}
206212

207213
/// @notice Returns the sum total of raw balances of all users at `_blockNumber`.
208214
/// @param _blockNumber The block at which to lookup the total balance.
209215
function getPastTotalBalance(uint256 _blockNumber) public view returns (uint256) {
210-
return totalBalanceCheckpoints.getAtProbablyRecentBlock(_blockNumber);
216+
uint48 key = SafeCast.toUint48(_blockNumber);
217+
return totalBalanceCheckpoints.upperLookup(key);
211218
}
212219
}

src/FractionalPool.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
pragma solidity ^0.8.10;
2+
pragma solidity ^0.8.20;
33

44
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
55
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";

0 commit comments

Comments
 (0)