Skip to content

Instantly share code, notes, and snippets.

@ajb413
Last active October 5, 2021 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ajb413/4ddd33cd78eba5bc1bb1b69818da2e0d to your computer and use it in GitHub Desktop.
Save ajb413/4ddd33cd78eba5bc1bb1b69818da2e0d to your computer and use it in GitHub Desktop.
The Compound Protocol's Testnet version of Governor Bravo. Deploy using the README.md file below.

Testnet Upgrade to Governor Bravo

Using a Compound Protocol commit later than 1243a5e7498f943a6061a4dbf3b71041ec7c6c70, deploy Governor Bravo to the testnet.

Copy the GovernorBravoHarness.sol file (below, in this Gist) into the /contracts/ directory of compound-protocol. This version is only to be used on testnets.

cd compound-protocol/
npx saddle deploy GovernorBravoDelegateTestnetHarness -n ropsten

After the instance deploy, copy the contract address. Next we'll deploy the delegator.

The deploy parameters are timelock_address, comp_address, timelock_address, instance_address, voting_period_blocks, voting_delay_blocks, proposal_threshold, followed by -n network_name.

npx saddle deploy GovernorBravoDelegator 0x2079a734292094702f4d7d64a59e980c20652cae 0xf76d4a441e4ba86a923ce32b89aff89dbccaa075 0x2079a734292094702f4d7d64a59e980c20652cae 0xc5597F42620005bDccB5088e65438376c72B3604 60 1 100000000000000000000000 -n ropsten

Go to the Delegator Etherscan page, click contract, click more options, click "is this a proxy?" and mark the contract a proxy.

Go back to the terminal for compound-protocol, and run this command with the specific testnet name (other than ropsten)

yarn console -n ropsten

Copy the addresses:

governorBravoDelegator: 0x087e98B40f988E0E1D1de476b2b8d2271Ac84B33
governorBravoDelegateTestnetHarness: 0xc5597F42620005bDccB5088e65438376c72B3604

Make a governance proposal on the testnet if you have >100k testnet COMP (https://app.compound.finance/vote).

Ther actions are:

Timelock.setPendingAdmin(GovernorBravoDelegator)
GovernorBravoDelegator._initiate(GovernorAlphaAddress)

Grab the ABI for governorBravoDelegateTestnetHarness and use it in the proposal UI when you go to select the _initiate function.

pragma solidity ^0.5.16;
pragma experimental ABIEncoderV2;
import "../../contracts/Governance/GovernorBravoDelegate.sol";
// @notice Only use this contract for internal testing
contract GovernorBravoDelegateHarness is GovernorBravoDelegate {
// @notice Harness initiate the GovenorBravo contract
// @dev This function bypasses the need to initiate the GovernorBravo contract from an existing GovernorAlpha for testing.
// Actual use will only use the _initiate(address) function
function _initiate() public {
proposalCount = 1;
initialProposalId = 1;
}
function initialize(address timelock_, address comp_, uint votingPeriod_, uint votingDelay_, uint proposalThreshold_) public {
require(msg.sender == admin, "GovernorBravo::initialize: admin only");
require(address(timelock) == address(0), "GovernorBravo::initialize: can only initialize once");
timelock = TimelockInterface(timelock_);
comp = CompInterface(comp_);
votingPeriod = votingPeriod_;
votingDelay = votingDelay_;
proposalThreshold = proposalThreshold_;
}
}
// @notice Use this contract for testnet usage. It doesn't need to be initiated and it will allow any parameters on initialization
contract GovernorBravoDelegateTestnetHarness is GovernorBravoDelegate {
/**
* @notice Harness initiate the GovenorBravo contract
* @dev This function bypasses the need to initiate the GovernorBravo contract from an existing GovernorAlpha for testnet usage.
* @param acceptAdmin - should accept admin be called
*/
function _initiate(bool acceptAdmin) external {
require(msg.sender == admin, "GovernorBravo::_initiate: admin only");
require(initialProposalId == 0, "GovernorBravo::_initiate: can only initiate once");
proposalCount = 1;
initialProposalId = 1;
// Timelock admin may already be set to GovernorBravo
if(acceptAdmin) {
timelock.acceptAdmin();
}
}
/**
* @notice normal GovernorBravo initialize function without input validation
*/
function initialize(address timelock_, address comp_, uint votingPeriod_, uint votingDelay_, uint proposalThreshold_) public {
require(msg.sender == admin, "GovernorBravo::initialize: admin only");
require(address(timelock) == address(0), "GovernorBravo::initialize: can only initialize once");
timelock = TimelockInterface(timelock_);
comp = CompInterface(comp_);
votingPeriod = votingPeriod_;
votingDelay = votingDelay_;
proposalThreshold = proposalThreshold_;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment