Skip to content

Commit

Permalink
refactor: instiate updated governor including governance routes
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Oct 2, 2023
1 parent 1d43a36 commit 0435175
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 29 deletions.
31 changes: 21 additions & 10 deletions subgraphs/venus-governance/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,11 @@ type Governance @entity {
"Number of proposals created"
proposals: BigInt!

"Total number of token holders currently"
currentTokenHolders: BigInt!

"Total number of delegates participating on the governance currently"
currentDelegates: BigInt!

"Total number of token holders"
totalTokenHolders: BigInt!

"Total number of delegates that held delegated votes"
"Total number of accounts delegates that can participate in governance by voting or creating proposals"
totalDelegates: BigInt!

"Total number of accounts participating in governance as delegates or by delegating"
totalVoters: BigInt!

"Total number of votes delegated expressed in the smallest unit of the Venus Token"
delegatedVotes: BigInt!
Expand All @@ -140,6 +134,9 @@ type Governance @entity {
"The duration of voting on a proposal, in blocks"
votingPeriod: BigInt!

"The number of votes required to reach quorum"
quorumVotes: BigInt!

"Active brains of Governor"
implementation: Bytes!

Expand All @@ -157,7 +154,21 @@ type Governance @entity {

"The maximum number of actions that can be included in a proposal"
proposalMaxOperations: BigInt!
}

type GovernanceRoute @entity {
"Index of the governance route"
id: ID!
"Address of timelock contract for route"
timelock: Bytes!
"Que execution delay in blocks"
queDelay: BigInt!
"The delay before voting on a proposal may take place, once proposed, in blocks"
votingDelay: BigInt!
"The duration of voting on a proposal, in blocks"
votingPeriod: BigInt!
"The number of votes required in order for a voter to become a proposer"
proposalThreshold: BigInt!
}

enum PermissionStatus {
Expand Down
3 changes: 3 additions & 0 deletions subgraphs/venus-governance/src/constants/config-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Use yarn prepare commands to generate config typescript file per env

export const governorBravoDelegate2Address = '{{ governorBravoDelegate2Address }}';
3 changes: 0 additions & 3 deletions subgraphs/venus-governance/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ export const EXECUTED = 'EXECUTED';
export const QUEUED = 'QUEUED';
export const ACTIVE = 'ACTIVE';

// Ids
export const GOVERNANCE = 'GOVERNANCE';

// Vote support
export const FOR = 'FOR';
export const AGAINST = 'AGAINST';
Expand Down
68 changes: 52 additions & 16 deletions subgraphs/venus-governance/src/operations/get.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,67 @@
import { Address, BigInt, log } from '@graphprotocol/graph-ts';

import { Delegate, Governance, Proposal } from '../../generated/schema';
import { BIGINT_ONE, BIGINT_ZERO, GOVERNANCE } from '../constants';
import { GovernorBravoDelegate2 } from '../../generated/GovernorBravoDelegate2/GovernorBravoDelegate2';
import { Timelock } from '../../generated/GovernorBravoDelegate2/Timelock';
import { Delegate, Governance, GovernanceRoute, Proposal } from '../../generated/schema';
import { BIGINT_ZERO } from '../constants';
import { governorBravoDelegate2Address } from '../constants/config';

/**
* While techinically this function does also create, we don't care because it only happens once as the id is a constant.
* While technically this function does also create, we don't care because it only happens once as the id is a constant.
* @returns Governance
*/
export const getGovernanceEntity = (): Governance => {
let governance = Governance.load(GOVERNANCE);
let governance = Governance.load(governorBravoDelegate2Address);
if (!governance) {
governance = new Governance(GOVERNANCE);
const governorBravoDelegate2 = GovernorBravoDelegate2.bind(
Address.fromString(governorBravoDelegate2Address),
);
governance = new Governance(governorBravoDelegate2Address);
governance.proposals = BIGINT_ZERO;
governance.totalTokenHolders = BIGINT_ZERO;
governance.currentTokenHolders = BIGINT_ZERO;
governance.currentDelegates = BIGINT_ZERO;
governance.totalDelegates = BIGINT_ZERO;
governance.delegatedVotes = BIGINT_ZERO;
governance.proposalsQueued = BIGINT_ZERO;
// defaulting to Governor Bravo constructor defaults
governance.votingDelay = BIGINT_ONE;
governance.votingPeriod = BigInt.fromI64(86400);
governance.implementation = Address.fromString('0x18df46ec843e79d9351b57f85af7d69aec0d7eff');
governance.proposalThreshold = BigInt.fromI64(300000000000000000000000);
governance.admin = Address.fromString('0x1c2cac6ec528c20800b2fe734820d87b581eaa6b');
governance.guardian = Address.fromString('0x1c2cac6ec528c20800b2fe734820d87b581eaa6b');
governance.proposalMaxOperations = BigInt.fromI32(10);

governance.votingDelay = governorBravoDelegate2.votingDelay();

governance.votingPeriod = governorBravoDelegate2.votingPeriod();
governance.implementation = governorBravoDelegate2.implementation();
governance.proposalThreshold = governorBravoDelegate2.proposalThreshold();
governance.admin = governorBravoDelegate2.admin();
governance.guardian = governorBravoDelegate2.guardian();
governance.quorumVotes = governorBravoDelegate2.quorumVotes();
governance.proposalMaxOperations = governorBravoDelegate2.proposalMaxOperations();
// Governance Routes are set in initialization
// Normal
const normalProposalConfig = governorBravoDelegate2.proposalConfigs(new BigInt(0));
const normalTimelockAddress = governorBravoDelegate2.proposalTimelocks(new BigInt(0));
const normalTimelock = Timelock.bind(normalTimelockAddress);
const normalGovernanceRoute = new GovernanceRoute('0');
normalGovernanceRoute.timelock = normalTimelockAddress;
normalGovernanceRoute.queDelay = normalTimelock.delay();
normalGovernanceRoute.votingDelay = normalProposalConfig.getVotingDelay();
normalGovernanceRoute.votingPeriod = normalProposalConfig.getVotingPeriod();
normalGovernanceRoute.proposalThreshold = normalProposalConfig.getProposalThreshold();
// Fast track
const fastTrackProposalConfig = governorBravoDelegate2.proposalConfigs(new BigInt(1));
const fastTrackTimelockAddress = governorBravoDelegate2.proposalTimelocks(new BigInt(1));
const fastTrackTimelock = Timelock.bind(normalTimelockAddress);
const fastTrackGovernanceRoute = new GovernanceRoute('1');
fastTrackGovernanceRoute.timelock = fastTrackTimelockAddress;
fastTrackGovernanceRoute.queDelay = fastTrackTimelock.delay();
fastTrackGovernanceRoute.votingDelay = fastTrackProposalConfig.getVotingDelay();
fastTrackGovernanceRoute.votingPeriod = fastTrackProposalConfig.getVotingPeriod();
fastTrackGovernanceRoute.proposalThreshold = fastTrackProposalConfig.getProposalThreshold();
// Critical
const criticalProposalConfig = governorBravoDelegate2.proposalConfigs(new BigInt(2));
const criticalTimelockAddress = governorBravoDelegate2.proposalTimelocks(new BigInt(2));
const criticalTimelock = Timelock.bind(normalTimelockAddress);
const criticalGovernanceRoute = new GovernanceRoute('2');
criticalGovernanceRoute.timelock = criticalTimelockAddress;
criticalGovernanceRoute.queDelay = criticalTimelock.delay();
criticalGovernanceRoute.votingDelay = criticalProposalConfig.getVotingDelay();
criticalGovernanceRoute.votingPeriod = criticalProposalConfig.getVotingPeriod();
criticalGovernanceRoute.proposalThreshold = criticalProposalConfig.getProposalThreshold();
}

return governance as Governance;
Expand Down
2 changes: 2 additions & 0 deletions subgraphs/venus-governance/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ dataSources:
abis:
- name: GovernorBravoDelegate2
file: ../../packages/venus-governance-abis/GovernorBravoDelegate2.json
- name: Timelock
file: ../../node_modules/@venusprotocol/governance-contracts/artifacts/contracts/Governance/Timelock.sol/Timelock.json
eventHandlers:
- event: ProposalCreated(uint256,address,address[],uint256[],string[],bytes[],uint256,uint256,string,uint8)
handler: handleProposalCreatedV2
Expand Down

0 comments on commit 0435175

Please sign in to comment.