Skip to content
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

treasury: Delta Governor v1 #615

Merged
merged 32 commits into from
Aug 25, 2023
Merged

treasury: Delta Governor v1 #615

merged 32 commits into from
Aug 25, 2023

Conversation

victorges
Copy link
Member

@victorges victorges commented Jul 17, 2023

What does this pull request do? Explain your changes. (required)
This is the implementation for the LivepeerGovernor specified in LIP-89.
It depends on the BondingVotes contract implementation from #614.

The higher level output of this PR is a LivepeerGovernor contract compatible with
the OZ Governor framework, whose participants bonding power is derived from their
staked LPT in the same way as LIP-16).

Specific updates (required)

  • Create governance contracts described in LIP-89 apart from BondingVotes.
  • Unit tests for GovernorCountingOverridable
  • Integration tests to LivepeerGovernor incl deployment scripts

How did you test each of these updates (required)

Does this pull request close any open issues?
Implements PRO-31

Checklist:

  • README and other documentation updated
  • All tests using yarn test pass

Will be required for new checkpoints code and later governor
implementation.
Used for checkpointing logic in bonding state checkpoints
Handles historic checkpointing ("snapshotting") and lookup
of the bonding state.
 - unit tests
 - integration tests
 - gas-report
 - fork test for upgrade
This will provide a cleaner experience using governance
tools, since users that don't have any stake won't get
errors when querying their voting power. For users that
do have stake, we will make sure to checkpoint them on
first deploy.
@victorges victorges changed the base branch from confluence to vg/feat/bonding-checkpoints July 17, 2023 17:41
@victorges victorges force-pushed the vg/feat/onchain-governor branch 5 times, most recently from 80cf668 to 109d0b1 Compare July 19, 2023 04:32
@victorges victorges changed the title Vg/feat/onchain governor treasury: Delta Governor v1 Jul 20, 2023
@victorges victorges marked this pull request as ready for review July 20, 2023 14:14
"Harness" seems to make more sense, I could only think
of that now.
Copy link
Contributor

@0xcadams 0xcadams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preliminary review of code quality & gas improvements, no deep checks of logic

contracts/treasury/BondingCheckpointsVotes.sol Outdated Show resolved Hide resolved
contracts/treasury/BondingCheckpointsVotes.sol Outdated Show resolved Hide resolved
contracts/treasury/BondingCheckpointsVotes.sol Outdated Show resolved Hide resolved
contracts/treasury/BondingCheckpointsVotes.sol Outdated Show resolved Hide resolved
contracts/treasury/GovernorCountingOverridable.sol Outdated Show resolved Hide resolved
contracts/treasury/LivepeerGovernor.sol Outdated Show resolved Hide resolved
contracts/treasury/LivepeerGovernor.sol Show resolved Hide resolved
contracts/treasury/LivepeerGovernor.sol Show resolved Hide resolved
contracts/treasury/GovernorCountingOverridable.sol Outdated Show resolved Hide resolved
contracts/treasury/LivepeerGovernor.sol Outdated Show resolved Hide resolved
contracts/treasury/LivepeerGovernor.sol Outdated Show resolved Hide resolved
contracts/treasury/GovernorCountingOverridable.sol Outdated Show resolved Hide resolved
contracts/treasury/GovernorCountingOverridable.sol Outdated Show resolved Hide resolved
contracts/treasury/GovernorCountingOverridable.sol Outdated Show resolved Hide resolved
Meaning the start of next round instead of the
current round. This is more compatible with the
way OZ expects the timepoints to work in the clock
and snapshots on the Governor framework.
This changes the BondingVotes implementation to
stop having so many reverts on supposedly invalid states.

Instead, redefine the voting power (and checkpointed stake)
as being zero before the first round to be checkpointed.

This had other implications in the code like removing
changes in BondingManager to make the state complete
(always having an earnings pool on lastClaimRound).
Instead, the BondingVotes implementaiton is resilient
to that as well and just assumes reward() had never
been called.

This also fixed the redundant reverts between BondingVotes
and SortedArrays, as now there are almost no reverts.
@victorges
Copy link
Member Author

victorges commented Aug 17, 2023

@yondonfu Also ready for another round! 😁

Notice that I made a "merge" with the parent branch just to avoid rebasing and losing all history. Let me know if you'd prefer a clean rebase. When merging, my plan is to either do the full linearization of the branches or squash&merge them instead not to keep the non-linear git history.

This is to increase compatibility with some tools
out there like Tally, which require only these
functions from the ERC20 spec, not the full implementation.

So we can have these from the get-go to make things
easier if we want to make something with them.
Copy link
Member

@yondonfu yondonfu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Base automatically changed from vg/feat/bonding-checkpoints to delta August 25, 2023 22:08
@victorges victorges merged commit ad48642 into delta Aug 25, 2023
2 checks passed
@victorges victorges deleted the vg/feat/onchain-governor branch August 25, 2023 22:11
victorges added a commit that referenced this pull request Oct 11, 2023
* package.json: Update @OpenZeppelin libraries

Will be required for new checkpoints code and later governor
implementation.

* bonding: Create SortedArrays library

Used for checkpointing logic in bonding state checkpoints

* bonding: Create BondingCheckpoints contract

Handles historic checkpointing ("snapshotting") and lookup
of the bonding state.

* bonding: Checkpoint bonding state on changes

* test/bonding: Test BondingManager and Checkpoints

 - unit tests
 - integration tests
 - gas-report
 - fork test for upgrade

* bonding: Migrate to custom error types

* bonding: Allow querying unbonded+uncheckpointed accounts

This will provide a cleaner experience using governance
tools, since users that don't have any stake won't get
errors when querying their voting power. For users that
do have stake, we will make sure to checkpoint them on
first deploy.

* treasury: Create treasury governance contracts

* test/treasury: Add unit test fro BondingCheckpointsVotes

* test/treasury: Test GovernorCountingOverridable

* test/treasury: Test LivepeerGovernor

* test/treasury: A couple additional Governor tests

100% coverage 😎

* test/treasury: Rename Counting unit test mock

"Harness" seems to make more sense, I could only think
of that now.

* Apply suggestions from code review

Co-authored-by: Chase Adams <[email protected]>

* treasury: Fix storage layout situation

* treasury: Move governor initial params to configs

* bonding: Make sure we checkpoint up to once per op

* bonding: Make bonding checkpoints implement IVotes

* bonding: Read votes from the end of the round

Meaning the start of next round instead of the
current round. This is more compatible with the
way OZ expects the timepoints to work in the clock
and snapshots on the Governor framework.

* bonding: Make checkpoint reading revert-free

This changes the BondingVotes implementation to
stop having so many reverts on supposedly invalid states.

Instead, redefine the voting power (and checkpointed stake)
as being zero before the first round to be checkpointed.

This had other implications in the code like removing
changes in BondingManager to make the state complete
(always having an earnings pool on lastClaimRound).
Instead, the BondingVotes implementaiton is resilient
to that as well and just assumes reward() had never
been called.

This also fixed the redundant reverts between BondingVotes
and SortedArrays, as now there are almost no reverts.

* bonding: Address minor code review comments

* treasury: Migrate to the new BondingVotes contract

* treasury: Address PR comments

* bonding: Move constructor to after modifiers

Just for consistency with other contracts.
Some docs as a bonus

* test/mocks: Remove mock functions that moved to other mock

* bonding: Implement ERC20 metadata on votes

This is to increase compatibility with some tools
out there like Tally, which require only these
functions from the ERC20 spec, not the full implementation.

So we can have these from the get-go to make things
easier if we want to make something with them.

* bonding: Address PR comments

* bonding: Address BondingVotes review comments

* treasury: Merge BondingCheckpoints and nits

---------

Co-authored-by: Chase Adams <[email protected]>
victorges added a commit that referenced this pull request Oct 11, 2023
* package.json: Update @OpenZeppelin libraries

Will be required for new checkpoints code and later governor
implementation.

* bonding: Create SortedArrays library

Used for checkpointing logic in bonding state checkpoints

* bonding: Create BondingCheckpoints contract

Handles historic checkpointing ("snapshotting") and lookup
of the bonding state.

* bonding: Checkpoint bonding state on changes

* test/bonding: Test BondingManager and Checkpoints

 - unit tests
 - integration tests
 - gas-report
 - fork test for upgrade

* bonding: Migrate to custom error types

* bonding: Allow querying unbonded+uncheckpointed accounts

This will provide a cleaner experience using governance
tools, since users that don't have any stake won't get
errors when querying their voting power. For users that
do have stake, we will make sure to checkpoint them on
first deploy.

* treasury: Create treasury governance contracts

* test/treasury: Add unit test fro BondingCheckpointsVotes

* test/treasury: Test GovernorCountingOverridable

* test/treasury: Test LivepeerGovernor

* test/treasury: A couple additional Governor tests

100% coverage 😎

* test/treasury: Rename Counting unit test mock

"Harness" seems to make more sense, I could only think
of that now.

* Apply suggestions from code review

Co-authored-by: Chase Adams <[email protected]>

* treasury: Fix storage layout situation

* treasury: Move governor initial params to configs

* bonding: Make sure we checkpoint up to once per op

* bonding: Make bonding checkpoints implement IVotes

* bonding: Read votes from the end of the round

Meaning the start of next round instead of the
current round. This is more compatible with the
way OZ expects the timepoints to work in the clock
and snapshots on the Governor framework.

* bonding: Make checkpoint reading revert-free

This changes the BondingVotes implementation to
stop having so many reverts on supposedly invalid states.

Instead, redefine the voting power (and checkpointed stake)
as being zero before the first round to be checkpointed.

This had other implications in the code like removing
changes in BondingManager to make the state complete
(always having an earnings pool on lastClaimRound).
Instead, the BondingVotes implementaiton is resilient
to that as well and just assumes reward() had never
been called.

This also fixed the redundant reverts between BondingVotes
and SortedArrays, as now there are almost no reverts.

* bonding: Address minor code review comments

* treasury: Migrate to the new BondingVotes contract

* treasury: Address PR comments

* bonding: Move constructor to after modifiers

Just for consistency with other contracts.
Some docs as a bonus

* test/mocks: Remove mock functions that moved to other mock

* bonding: Implement ERC20 metadata on votes

This is to increase compatibility with some tools
out there like Tally, which require only these
functions from the ERC20 spec, not the full implementation.

So we can have these from the get-go to make things
easier if we want to make something with them.

* bonding: Address PR comments

* bonding: Address BondingVotes review comments

* treasury: Merge BondingCheckpoints and nits

---------

Co-authored-by: Chase Adams <[email protected]>
victorges added a commit that referenced this pull request Oct 11, 2023
* package.json: Update @OpenZeppelin libraries

Will be required for new checkpoints code and later governor
implementation.

* bonding: Create SortedArrays library

Used for checkpointing logic in bonding state checkpoints

* bonding: Create BondingCheckpoints contract

Handles historic checkpointing ("snapshotting") and lookup
of the bonding state.

* bonding: Checkpoint bonding state on changes

* test/bonding: Test BondingManager and Checkpoints

 - unit tests
 - integration tests
 - gas-report
 - fork test for upgrade

* bonding: Migrate to custom error types

* bonding: Allow querying unbonded+uncheckpointed accounts

This will provide a cleaner experience using governance
tools, since users that don't have any stake won't get
errors when querying their voting power. For users that
do have stake, we will make sure to checkpoint them on
first deploy.

* treasury: Create treasury governance contracts

* test/treasury: Add unit test fro BondingCheckpointsVotes

* test/treasury: Test GovernorCountingOverridable

* test/treasury: Test LivepeerGovernor

* test/treasury: A couple additional Governor tests

100% coverage 😎

* test/treasury: Rename Counting unit test mock

"Harness" seems to make more sense, I could only think
of that now.

* Apply suggestions from code review

Co-authored-by: Chase Adams <[email protected]>

* treasury: Fix storage layout situation

* treasury: Move governor initial params to configs

* bonding: Make sure we checkpoint up to once per op

* bonding: Make bonding checkpoints implement IVotes

* bonding: Read votes from the end of the round

Meaning the start of next round instead of the
current round. This is more compatible with the
way OZ expects the timepoints to work in the clock
and snapshots on the Governor framework.

* bonding: Make checkpoint reading revert-free

This changes the BondingVotes implementation to
stop having so many reverts on supposedly invalid states.

Instead, redefine the voting power (and checkpointed stake)
as being zero before the first round to be checkpointed.

This had other implications in the code like removing
changes in BondingManager to make the state complete
(always having an earnings pool on lastClaimRound).
Instead, the BondingVotes implementaiton is resilient
to that as well and just assumes reward() had never
been called.

This also fixed the redundant reverts between BondingVotes
and SortedArrays, as now there are almost no reverts.

* bonding: Address minor code review comments

* treasury: Migrate to the new BondingVotes contract

* treasury: Address PR comments

* bonding: Move constructor to after modifiers

Just for consistency with other contracts.
Some docs as a bonus

* test/mocks: Remove mock functions that moved to other mock

* bonding: Implement ERC20 metadata on votes

This is to increase compatibility with some tools
out there like Tally, which require only these
functions from the ERC20 spec, not the full implementation.

So we can have these from the get-go to make things
easier if we want to make something with them.

* bonding: Address PR comments

* bonding: Address BondingVotes review comments

* treasury: Merge BondingCheckpoints and nits

---------

Co-authored-by: Chase Adams <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants