Skip to content

Commit d3c62a3

Browse files
authored
Remove GovernorCountingFractional (Bump OZ to v5.1) (#79)
OpenZeppelin included an implementation of `GovernorCountingFractional` in release [v5.1.0](https://github.com/OpenZeppelin/openzeppelin-contracts/releases/tag/v5.1.0). This PR bumps our OZ dependency to that version and accordingly removes the implementation of `GovernorCountingFractional` which originated in this repo. This PR additionally bumps foundry to v1.9.5.
1 parent 37e12d4 commit d3c62a3

15 files changed

+92
-1472
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ jobs:
108108
uses: zgosalvez/github-actions-report-lcov@v2
109109
with:
110110
coverage-files: ./lcov.info
111-
minimum-coverage: 91 # Set coverage threshold.
111+
minimum-coverage: 88 # Set coverage threshold.
112112

113113
slither-analyze:
114114
runs-on: ubuntu-latest

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ To add Flexible Voting to your own Foundry project, use [forge install](https://
3131
$ forge install scopelift/flexible-voting
3232
```
3333

34-
If you're using a developer framework other than Foundry, we recommend vendoring the code by adding `src/GovernorCountingFractional.sol` and/or `src/FlexVotingClient.sol` to your repo directly. In the future, we may offer an npm package for use with other frameworks.
34+
If you're using a developer framework other than Foundry, we recommend vendoring the code by adding files like `src/FlexVotingClient.sol` to your repo directly. In the future, we may offer an npm package for use with other frameworks.
3535

3636
### Constructing a Governor
3737

@@ -41,13 +41,11 @@ If you're constructing a new Governor with Flexible Voting—either to upgrade a
4141
// SPDX-License-Identifier: MIT
4242
pragma solidity ^0.8.20;
4343
44+
import {Governor} from "@openzeppelin/contracts/governance/Governor.sol";
4445
import {GovernorVotes} from "@openzeppelin/contracts/governance/extensions/GovernorVotes.sol";
4546
import {GovernorSettings} from "@openzeppelin/contracts/governance/extensions/GovernorSettings.sol";
46-
import {GovernorTimelockControl} from
47-
"@openzeppelin/contracts/governance/extensions/GovernorTimelockControl.sol";
48-
import {
49-
Governor, GovernorCountingFractional
50-
} from "flexible-voting/src/GovernorCountingFractional.sol";
47+
import {GovernorTimelockControl} from "@openzeppelin/contracts/governance/extensions/GovernorTimelockControl.sol";
48+
import {GovernorCountingFractional} from "@openzeppelin/contracts/governance/extensions/GovernorCountingFractional.sol";
5149
5250
contract FlexibleVotingGovernor is
5351
GovernorCountingFractional,
@@ -98,11 +96,19 @@ To read more about Flexible Voting adoption, read the documentation pages on [co
9896

9997
## Repo Contents
10098

101-
* [`src/GovernorCountingFractional.sol`](https://github.com/ScopeLift/flexible-voting/blob/master/src/GovernorCountingFractional.sol) - The Governor extension which enables Flexible Voting. A DAO adopting Flexible Voting would deploy a new Governor which used this extension.
10299
* [`src/FlexVotingClient.sol`](https://github.com/ScopeLift/flexible-voting/blob/master/src/FlexVotingClient.sol) - An abstract contract designed to make it easy to build clients for Flexible Voting governors. Inherit from this contract if you're building an integration or voting scheme for DAO(s) that use Flexible Voting.
103100
* [`src/FractionalPool.sol`](https://github.com/ScopeLift/flexible-voting/blob/master/src/FractionalPool.sol) - A proof-of-concept contract demonstrating how Flexible Voting can be used. It implements a simple token pool that allows holders to express their votes on proposals even when their tokens are deposited in the pool.
104101
* [`test/`](https://github.com/ScopeLift/flexible-voting/tree/master/test) - A full suite of unit and fuzz tests exercising the contracts.
105102

103+
Note that `GovernorCountingFractional` has been removed from this repo.
104+
[It has since been
105+
incorporated](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/7b74442c5e87ea51dde41c7f18a209fa5154f1a4/contracts/governance/extensions/GovernorCountingFractional.sol) into [OpenZeppelin's
106+
contracts library](https://github.com/OpenZeppelin/openzeppelin-contracts)
107+
as of [v5.1.0](https://github.com/OpenZeppelin/openzeppelin-contracts/releases/tag/v5.1.0).
108+
If you are unable to use v5.1.0 or later of OpenZeppelin's contracts, you can find the original
109+
`GovernorCountingFractional` implementation in previous releases of this repo,
110+
e.g. [`v1.2.0`](https://github.com/ScopeLift/flexible-voting/releases/tag/v1.2.0).
111+
106112
## Development
107113

108114
This repo is built using [Foundry](https://github.com/foundry-rs/foundry)
@@ -130,4 +136,4 @@ Code contributions to this repo are also welcome! Fork the project, create a new
130136

131137
Fractional Voting is available under the [MIT](LICENSE.txt) license.
132138

133-
Copyright (c) 2023 ScopeLift
139+
Copyright (c) 2025 ScopeLift

foundry.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121

2222
[fmt]
2323
bracket_spacing = false
24-
ignore = [
25-
'src/GovernorCountingFractional.sol', # Ignored b/c it follows OZ's styleguide.
26-
]
2724
int_types = "long"
2825
line_length = 100
2926
multiline_func_header = "attributes_first"

lib/openzeppelin-contracts

src/FlexVotingClient.sol

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ abstract contract FlexVotingClient {
8888
/// given time.
8989
Checkpoints.Trace208 internal totalBalanceCheckpoints;
9090

91+
// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/7b74442c5e87ea51dde41c7f18a209fa5154f1a4/contracts/governance/extensions/GovernorCountingFractional.sol#L37
92+
uint8 internal constant VOTE_TYPE_FRACTIONAL = 255;
93+
9194
error FlexVotingClient__NoVotingWeight();
9295
error FlexVotingClient__AlreadyVoted();
9396
error FlexVotingClient__InvalidSupportValue();
@@ -188,17 +191,13 @@ abstract contract FlexVotingClient {
188191
(_votingWeightAtSnapshot * _proposalVote.abstainVotes) / _totalRawBalanceAtSnapshot
189192
);
190193

191-
// This param is ignored by the governor when voting with fractional
192-
// weights. It makes no difference what vote type this is.
193-
uint8 unusedSupportParam = uint8(VoteType.Abstain);
194-
195194
// Clear the stored votes so that we don't double-cast them.
196195
delete proposalVotes[proposalId];
197196

198197
bytes memory fractionalizedVotes =
199198
abi.encodePacked(_againstVotesToCast, _forVotesToCast, _abstainVotesToCast);
200199
GOVERNOR.castVoteWithReasonAndParams(
201-
proposalId, unusedSupportParam, _castVoteReasonString(), fractionalizedVotes
200+
proposalId, VOTE_TYPE_FRACTIONAL, _castVoteReasonString(), fractionalizedVotes
202201
);
203202
}
204203

src/FractionalPool.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ contract FractionalPool {
5454
/// @notice Map proposalId to vote totals expressed on this proposal.
5555
mapping(uint256 => ProposalVote) public proposalVotes;
5656

57+
// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/7b74442c5e87ea51dde41c7f18a209fa5154f1a4/contracts/governance/extensions/GovernorCountingFractional.sol#L37
58+
uint8 internal constant VOTE_TYPE_FRACTIONAL = 255;
59+
5760
/// @param _token The governance token held and lent by this pool.
5861
/// @param _governor The governor contract associated with this governance token.
5962
constructor(IVotingToken _token, IFractionalGovernor _governor) {
@@ -122,7 +125,6 @@ contract FractionalPool {
122125
/// @param proposalId The ID of the proposal which the Pool will now vote on.
123126
function castVote(uint256 proposalId) external {
124127
if (internalVotingPeriodEnd(proposalId) > block.number) revert("cannot castVote yet");
125-
uint8 unusedSupportParam = uint8(VoteType.Abstain);
126128
ProposalVote memory _proposalVote = proposalVotes[proposalId];
127129

128130
uint256 _proposalSnapshotBlockNumber = GOVERNOR.proposalSnapshot(proposalId);
@@ -154,7 +156,7 @@ contract FractionalPool {
154156
bytes memory fractionalizedVotes =
155157
abi.encodePacked(_againstVotesToCast, _forVotesToCast, _abstainVotesToCast);
156158
GOVERNOR.castVoteWithReasonAndParams(
157-
proposalId, unusedSupportParam, "crowd-sourced vote", fractionalizedVotes
159+
proposalId, VOTE_TYPE_FRACTIONAL, "crowd-sourced vote", fractionalizedVotes
158160
);
159161
}
160162

0 commit comments

Comments
 (0)