Skip to content

Commit

Permalink
treasury: Add timelock and fix dependency errors
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed Jul 7, 2023
1 parent 218a9c5 commit db5b9f6
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 27 deletions.
5 changes: 2 additions & 3 deletions contracts/bonding/BondingCheckpoints.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,8 @@ contract BondingCheckpoints is ManagerProxyTarget, IBondingCheckpoints {

/**
* @notice Returns whether an account already has any checkpoint.
* @dev This is used in BondingManager logic to initialize the checkpointing of existing accounts. It is meant to be
* called once we deploy the checkpointing logic for the first time, so we have a starting checkpoint from all
* accounts in the system.
* @dev This is meant to be called by a checkpoint initialization script once we deploy the checkpointing logic for
* the first time, so we can efficiently initialize the checkpoint state for all accounts in the system.
*/
function hasCheckpoint(address _account) external virtual returns (bool) {
return bondingCheckpoints[_account].startRounds.length > 0;
Expand Down
5 changes: 2 additions & 3 deletions contracts/bonding/BondingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import "../token/IMinter.sol";
import "../rounds/IRoundsManager.sol";
import "../snapshots/IMerkleSnapshot.sol";
import "./IBondingCheckpoints.sol";
import "../treasury/LivepeerGovernor.sol";

import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/governance/IGovernor.sol";
Expand Down Expand Up @@ -1626,8 +1625,8 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
return IRoundsManager(controller.getContract(keccak256("RoundsManager")));
}

function treasury() internal view returns (LivepeerGovernor) {
return LivepeerGovernor(payable(controller.getContract(keccak256("LivepeerGovernor"))));
function treasury() internal view returns (address payable) {
return payable(controller.getContract(keccak256("Treasury")));
}

function bondingCheckpoints() internal view returns (IBondingCheckpoints) {
Expand Down
14 changes: 8 additions & 6 deletions contracts/treasury/BondingCheckpointsVotes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ contract BondingCheckpointsVotes is Manager, IVotes {
* @notice Returns the current amount of votes that `account` has.
*/
function getVotes(address _account) external view returns (uint256) {
return bondingCheckpoints().getAccountStakeAt(_account, clock());
return getPastVotes(_account, clock());
}

/**
* @notice Returns the amount of votes that `account` had at a specific moment in the past. If the `clock()` is
* configured to use block numbers, this will return the value at the end of the corresponding block.
*/
function getPastVotes(address _account, uint256 _timepoint) external view returns (uint256) {
return bondingCheckpoints().getAccountStakeAt(_account, _timepoint);
function getPastVotes(address _account, uint256 _round) public view returns (uint256) {
(uint256 amount, ) = bondingCheckpoints().getBondingStateAt(_account, _round);
return amount;
}

/**
Expand All @@ -48,8 +49,8 @@ contract BondingCheckpointsVotes is Manager, IVotes {
* Bonded stake that is not part of the top 100 active transcoder set is still given voting power, but is not
* considered here.
*/
function getPastTotalSupply(uint256 _timepoint) external view returns (uint256) {
return bondingCheckpoints().getTotalActiveStakeAt(_timepoint);
function getPastTotalSupply(uint256 _round) external view returns (uint256) {
return bondingCheckpoints().getTotalActiveStakeAt(_round);
}

/**
Expand All @@ -67,7 +68,8 @@ contract BondingCheckpointsVotes is Manager, IVotes {
* delegators to override their transcoders votes. See {GovernorVotesBondingCheckpoints-_handleVoteOverrides}.
*/
function delegatedAt(address _account, uint256 _round) public view returns (address) {
return bondingCheckpoints().getDelegateAddressAt(_account, _round);
(, address delegateAddress) = bondingCheckpoints().getBondingStateAt(_account, _round);
return delegateAddress;
}

/**
Expand Down
93 changes: 78 additions & 15 deletions contracts/treasury/LivepeerGovernor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "@openzeppelin/contracts-upgradeable/governance/GovernorUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorVotesUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorVotesQuorumFractionUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorSettingsUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorTimelockControlUpgradeable.sol";

import "../bonding/libraries/EarningsPool.sol";
import "../bonding/libraries/EarningsPoolLIP36.sol";
Expand All @@ -22,25 +23,37 @@ contract LivepeerGovernor is
ManagerProxyTarget,
GovernorUpgradeable,
GovernorSettingsUpgradeable,
GovernorTimelockControlUpgradeable,
GovernorVotesUpgradeable,
GovernorVotesQuorumFractionUpgradeable,
GovernorCountingOverridable
{
/**
* @notice TreasuryGovernor constructor. Only invokes constructor of base Manager contract with provided Controller address
* @dev This constructor will not initialize any state variables besides `controller`. The `initialize` function must be called
* after construction to initialize the contract's state.
* @notice TreasuryGovernor constructor. Only invokes constructor of base Manager contract with provided Controller.
* @dev This constructor will not initialize any state variables besides `controller`. The `initialize` function
* must be called through the proxy after construction to initialize the contract's state in the proxy contract.
* @param _controller Address of Controller that this contract will be registered with
*/
constructor(address _controller) Manager(_controller) {}
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(address _controller) Manager(_controller) {
_disableInitializers();
}

/**
* Initializes the LivepeerGovernor instance. This requires the following contracts to have already been deployed
* and registered on the controller:
* - "Treasury" (TimelockControllerUpgradeable)
* - "BondingCheckpointsVotes"
* - "PollCreator"
*/
function initialize() public initializer {
__Governor_init("LivepeerGovernor");
__GovernorSettings_init(
1, /* 1 round/day voting delay */
10, /* 10 rounds/days voting period */
100e18 /* 100 LPT min proposal threshold */
);
__GovernorTimelockControl_init(treasury());

// The GovernorVotes module will hold a fixed reference to the votes contract. If we ever change its address we
// need to call the {bumpVotesAddress} function to update it in here as well.
Expand All @@ -61,17 +74,6 @@ contract LivepeerGovernor is
return MathUtils.PERC_DIVISOR;
}

// The following functions are overrides required by Solidity.

function proposalThreshold()
public
view
override(GovernorUpgradeable, GovernorSettingsUpgradeable)
returns (uint256)
{
return super.proposalThreshold();
}

/**
* @dev See {GovernorCountingOverridable-votes}.
*/
Expand Down Expand Up @@ -104,4 +106,65 @@ contract LivepeerGovernor is
function pollCreator() internal view returns (PollCreator) {
return PollCreator(controller.getContract(keccak256("PollCreator")));
}

function treasury() internal view returns (TimelockControllerUpgradeable) {
return TimelockControllerUpgradeable(payable(controller.getContract(keccak256("Treasury"))));
}

// The following functions are overrides required by Solidity.

function proposalThreshold()
public
view
override(GovernorUpgradeable, GovernorSettingsUpgradeable)
returns (uint256)
{
return super.proposalThreshold();
}

function state(uint256 proposalId)
public
view
override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
returns (ProposalState)
{
return super.state(proposalId);
}

function _execute(
uint256 proposalId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal override(GovernorUpgradeable, GovernorTimelockControlUpgradeable) {
super._execute(proposalId, targets, values, calldatas, descriptionHash);
}

function _cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal override(GovernorUpgradeable, GovernorTimelockControlUpgradeable) returns (uint256) {
return super._cancel(targets, values, calldatas, descriptionHash);
}

function _executor()
internal
view
override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
returns (address)
{
return super._executor();
}

function supportsInterface(bytes4 interfaceId)
public
view
override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}

0 comments on commit db5b9f6

Please sign in to comment.