Skip to content

Commit

Permalink
feat: governor without OZ timelock. Default governor executer
Browse files Browse the repository at this point in the history
  • Loading branch information
DuBento committed Jul 19, 2023
1 parent 3446729 commit 99a161e
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 197 deletions.
60 changes: 1 addition & 59 deletions blockchain/contracts/DAO/GovernorContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@ import "../OpenZeppelin/governance/Governor.sol";
import "../OpenZeppelin/governance/extensions/GovernorCountingSimple.sol";
import "../OpenZeppelin/governance/extensions/GovernorVotes.sol";
import "../OpenZeppelin/governance/extensions/GovernorVotesQuorumFraction.sol";
import "../OpenZeppelin/governance/extensions/GovernorTimelockControl.sol";
import "../OpenZeppelin/governance/extensions/GovernorSettings.sol";

contract GovernorContract is
Governor,
GovernorSettings,
GovernorCountingSimple,
GovernorVotes,
GovernorVotesQuorumFraction,
GovernorTimelockControl
GovernorVotesQuorumFraction
{
constructor(
IVotes _token,
TimelockController _timelock,
uint256 _votingDelay,
uint256 _votingPeriod,
uint256 _quorumFraction
Expand All @@ -27,7 +24,6 @@ contract GovernorContract is
GovernorSettings(_votingDelay, _votingPeriod, 0)
GovernorVotes(_token)
GovernorVotesQuorumFraction(_quorumFraction)
GovernorTimelockControl(_timelock)
{}

// The following functions are overrides required by Solidity.
Expand Down Expand Up @@ -61,26 +57,6 @@ contract GovernorContract is
return super.quorum(blockNumber);
}

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

function propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description
) public override(Governor, IGovernor) returns (uint256) {
return super.propose(targets, values, calldatas, description);
}

function proposalThreshold()
public
view
Expand All @@ -89,38 +65,4 @@ contract GovernorContract is
{
return super.proposalThreshold();
}

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

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

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

function supportsInterface(
bytes4 interfaceId
) public view override(Governor, GovernorTimelockControl) returns (bool) {
return super.supportsInterface(interfaceId);
}
}
18 changes: 0 additions & 18 deletions blockchain/contracts/DAO/GovernorTimelock.sol

This file was deleted.

32 changes: 0 additions & 32 deletions blockchain/deploy/01_timelock.ts

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await getNamedAccounts();

const governorToken = await get("GovernorToken");
const governorTimelock = await get("GovernorTimelock");

log(padCenter(scriptName(__filename), 50));
log("Deploying GovernorContract...");

const governorContract = await deploy("GovernorContract", {
from: deployer,
args: [
governorToken.address,
governorTimelock.address,
VOTING_DELAY,
VOTING_PERIOD,
VOTING_QUORUM,
],
args: [governorToken.address, VOTING_DELAY, VOTING_PERIOD, VOTING_QUORUM],
log: true,
// TODO verify if live on network
});
Expand Down
63 changes: 12 additions & 51 deletions blockchain/deploy/91_setup_governance.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import {
GovernorTimelock,
GovernorContract,
GovernorToken,
SupplychainFactory,
UserRegistry,
Expand All @@ -20,58 +19,20 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

const governorContractDeployment = await get("GovernorContract");

const governorTimelock = await utils.getContract<GovernorTimelock>(
"GovernorTimelock",
const governorContract = await utils.getContract<GovernorContract>(
"GovernorContract",
{ signerAddress: deployer }
);

log(padCenter(scriptName(__filename), 50));

await setupTimelock(
governorTimelock,
governorContractDeployment.address,
deployer
);

await setupGovernorToken(governorTimelock, deployer);
await setupUserRegistry(governorTimelock, deployer);
await setupSupplychainFactory(governorTimelock, deployer);
};

const setupTimelock = async function (
governorTimelock: GovernorTimelock,
governorAddress: string,
deployerAddress: string
) {
const proposerRole = await governorTimelock.PROPOSER_ROLE();
const executorRole = await governorTimelock.EXECUTOR_ROLE();
const adminRole = await governorTimelock.DEFAULT_ADMIN_ROLE();

log("Setting up Timelock...");
// Grant proposer to governor contract
const proposerTx = await governorTimelock.grantRole(
proposerRole,
governorAddress
);
await proposerTx.wait();

// Allow all to execute (zero address)
const executorTx = await governorTimelock.grantRole(
executorRole,
ethers.ZeroAddress
);
await executorTx.wait();

// Revoke admin acces from deployer
const revokeAdminTx = await governorTimelock.revokeRole(
adminRole,
deployerAddress
);
await revokeAdminTx.wait();
await setupGovernorToken(governorContract, deployer);
await setupUserRegistry(governorContract, deployer);
await setupSupplychainFactory(governorContract, deployer);
};

const setupGovernorToken = async function (
governorTimelock: GovernorTimelock,
governorContract: GovernorContract,
deployer: string
) {
log("Setting up GovernorToken...");
Expand All @@ -86,7 +47,7 @@ const setupGovernorToken = async function (

// Transfer owner to timelock
const transferOwnershipTx = await governorTokenContract.transferOwnership(
await governorTimelock.getAddress()
await governorContract.getAddress()
);
await transferOwnershipTx.wait();
};
Expand All @@ -106,7 +67,7 @@ const delegateVotingPower = async function (
};

const setupUserRegistry = async function (
governorTimelock: GovernorTimelock,
governorContract: GovernorContract,
deployer: string
) {
log("Setting up UserRegistry...");
Expand All @@ -118,13 +79,13 @@ const setupUserRegistry = async function (
);

const transferOwnershipTx = await userRegistryContract.transferOwnership(
await governorTimelock.getAddress()
await governorContract.getAddress()
);
await transferOwnershipTx.wait();
};

const setupSupplychainFactory = async function (
governorTimelock: GovernorTimelock,
governorContract: GovernorContract,
deployer: string
) {
log("Setting up SupplychainFactory...");
Expand All @@ -137,7 +98,7 @@ const setupSupplychainFactory = async function (

const transferOwnershipTx =
await supplychainFactoryContract.transferOwnership(
await governorTimelock.getAddress()
await governorContract.getAddress()
);
await transferOwnershipTx.wait();
};
Expand Down
17 changes: 1 addition & 16 deletions blockchain/lib/execute.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ethers, network } from "hardhat";
import { ethers } from "hardhat";
import { GovernorContract } from "../artifacts-frontend/typechain";
import * as utils from "../lib/utils";
import { DEVELOPMENT_CHAINS, MIN_DELAY } from "../properties";

export async function execute(
proposalTarget: string,
Expand All @@ -16,20 +15,6 @@ export async function execute(
"GovernorContract"
);

console.log("Queueing...");
const queueTx = await governor.queue(
[proposalTarget],
[0],
[encodedCall],
descriptionHash
);
await queueTx.wait();

if (DEVELOPMENT_CHAINS.includes(network.name)) {
await utils.increaseBlocks(1);
await utils.increaseTime(MIN_DELAY + 1);
}

console.log("Executing...");
// this will fail on a testnet because you need to wait for the MIN_DELAY!
const executeTx = await governor.execute(
Expand Down
15 changes: 2 additions & 13 deletions blockchain/test/GovernorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { expect } from "chai";
import { deployments, ethers, getNamedAccounts } from "hardhat";
import {
GovernorContract,
GovernorTimelock,
GovernorToken,
Supplychain,
SupplychainFactory,
Expand Down Expand Up @@ -35,7 +34,6 @@ import {
describe("Governor", function () {
let governorContract: GovernorContract;
let governorToken: GovernorToken;
let governorTimelock: GovernorTimelock;
let supplychainFactory: SupplychainFactory;
let userRegistry: UserRegistry;

Expand All @@ -45,9 +43,6 @@ describe("Governor", function () {
"GovernorContract"
);
governorToken = await utils.getContract<GovernorToken>("GovernorToken");
governorTimelock = await utils.getContract<GovernorTimelock>(
"GovernorTimelock"
);
supplychainFactory = await utils.getContract<SupplychainFactory>(
"SupplychainFactory"
);
Expand All @@ -56,7 +51,6 @@ describe("Governor", function () {
console.log(`#####
GovernorContract: ${await governorContract.getAddress()}
GovernorToken: ${await governorToken.getAddress()}
GovernorTimelock: ${await governorTimelock.getAddress()}
SupplychainFactory: ${await supplychainFactory.getAddress()}
UserRegistry: ${await userRegistry.getAddress()}
#####`);
Expand All @@ -65,7 +59,7 @@ describe("Governor", function () {
it("Succesfully deploys and Timelock is the correct owner", async function () {
// used to show gas report for deplpoyment
expect(await supplychainFactory.owner()).to.equal(
await governorTimelock.getAddress()
await governorContract.getAddress()
);
});

Expand Down Expand Up @@ -266,13 +260,8 @@ describe("Governor", function () {
});

it("Propose, vote and execute a new supplychain contract", async function () {
console.log("Timelock address:", await governorTimelock.getAddress());
console.log(
"SupplychainFactory address:",
await supplychainFactory.getAddress()
);
expect(await supplychainContractAsManager.owner()).to.equal(
await governorTimelock.getAddress()
await governorContract.getAddress()
);
});

Expand Down

0 comments on commit 99a161e

Please sign in to comment.