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 9c602fe
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 37 deletions.
2 changes: 0 additions & 2 deletions subgraphs/venus-governance/config/bsc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"governorAlpha2StartBlock": "11934064",
"governorBravoDelegateAddress": "0x2d56dC077072B53571b8252008C60e945108c75a",
"governorBravoDelegateStartBlock": "13729317",
"governorBravoDelegate2Address": "",
"governorBravoDelegate2StartBlock": "",
"xvsVaultAddress": "0x6eF49b4e0772Fe78128F981d42D54172b55eCF9F",
"xvsVaultStartBlock": "13018718"
}
4 changes: 1 addition & 3 deletions subgraphs/venus-governance/config/chapel.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"governorAlpha2Address": "0x7116894ed34FC4B27D5b84f46B70Af48397a6C24",
"governorAlpha2StartBlock": "13584539",
"governorBravoDelegateAddress": "0x5573422a1a59385c247ec3a66b93b7c08ec2f8f2",
"governorBravoDelegateStartBlock": "16002994 ",
"governorBravoDelegate2Address": "",
"governorBravoDelegate2StartBlock": "",
"governorBravoDelegateStartBlock": "16002994",
"xvsVaultAddress": "0xa4Fd54cACdA379FB7CaA783B83Cc846f8ac0Faa6",
"xvsVaultStartBlock": "13937802"
}
2 changes: 0 additions & 2 deletions subgraphs/venus-governance/config/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"governorAlpha2StartBlock": "0",
"governorBravoDelegateAddress": "0x1c9fD50dF7a4f066884b58A05D91e4b55005876A",
"governorBravoDelegateStartBlock": "0",
"governorBravoDelegate2Address": "0x1c9fD50dF7a4f066884b58A05D91e4b55005876A",
"governorBravoDelegate2StartBlock": "0",
"xvsVaultAddress": "0xe1708FA6bb2844D5384613ef0846F9Bc1e8eC55E",
"xvsVaultStartBlock": "0"
}
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 governorBravoDelegateAddress = '{{ governorBravoDelegateAddress }}';
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 { governorBravoDelegateAddress } 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(governorBravoDelegateAddress);
if (!governance) {
governance = new Governance(GOVERNANCE);
const governorBravoDelegate2 = GovernorBravoDelegate2.bind(
Address.fromString(governorBravoDelegateAddress),
);
governance = new Governance(governorBravoDelegateAddress);
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
6 changes: 5 additions & 1 deletion subgraphs/venus-governance/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ dataSources:
name: GovernorBravoDelegate2
network: {{ network }}
source:
address: "{{ governorBravoDelegate2Address }}"
address: "{{ governorBravoDelegateAddress }}"
abi: GovernorBravoDelegate2
startBlock: {{ governorBravoDelegate2StartBlock }}
mapping:
Expand All @@ -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 Expand Up @@ -183,6 +185,8 @@ dataSources:
- name: XVSVault
file: ../../packages/venus-governance-abis/XVSVault.json
eventHandlers:
- event: Deposit(indexed address,indexed address,indexed uint256,uint256)
handler: handleDeposit
- event: DelegateChangedV2(indexed address,indexed address,indexed address)
handler: handleDelegateChanged
- event: DelegateVotesChangedV2(indexed address,uint256,uint256)
Expand Down

0 comments on commit 9c602fe

Please sign in to comment.