diff --git a/subgraphs/venus-governance/config/bsc.json b/subgraphs/venus-governance/config/bsc.json index e55d30f1..692e5e72 100644 --- a/subgraphs/venus-governance/config/bsc.json +++ b/subgraphs/venus-governance/config/bsc.json @@ -8,8 +8,6 @@ "governorAlpha2StartBlock": "11934064", "governorBravoDelegateAddress": "0x2d56dC077072B53571b8252008C60e945108c75a", "governorBravoDelegateStartBlock": "13729317", - "governorBravoDelegate2Address": "", - "governorBravoDelegate2StartBlock": "", "xvsVaultAddress": "0x6eF49b4e0772Fe78128F981d42D54172b55eCF9F", "xvsVaultStartBlock": "13018718" } diff --git a/subgraphs/venus-governance/config/chapel.json b/subgraphs/venus-governance/config/chapel.json index 198065f6..cdbb9e43 100644 --- a/subgraphs/venus-governance/config/chapel.json +++ b/subgraphs/venus-governance/config/chapel.json @@ -7,9 +7,7 @@ "governorAlpha2Address": "0x7116894ed34FC4B27D5b84f46B70Af48397a6C24", "governorAlpha2StartBlock": "13584539", "governorBravoDelegateAddress": "0x5573422a1a59385c247ec3a66b93b7c08ec2f8f2", - "governorBravoDelegateStartBlock": "16002994 ", - "governorBravoDelegate2Address": "", - "governorBravoDelegate2StartBlock": "", + "governorBravoDelegateStartBlock": "16002994", "xvsVaultAddress": "0xa4Fd54cACdA379FB7CaA783B83Cc846f8ac0Faa6", "xvsVaultStartBlock": "13937802" } diff --git a/subgraphs/venus-governance/config/local.json b/subgraphs/venus-governance/config/local.json index 374bbc20..62654900 100644 --- a/subgraphs/venus-governance/config/local.json +++ b/subgraphs/venus-governance/config/local.json @@ -8,8 +8,6 @@ "governorAlpha2StartBlock": "0", "governorBravoDelegateAddress": "0x1c9fD50dF7a4f066884b58A05D91e4b55005876A", "governorBravoDelegateStartBlock": "0", - "governorBravoDelegate2Address": "0x1c9fD50dF7a4f066884b58A05D91e4b55005876A", - "governorBravoDelegate2StartBlock": "0", "xvsVaultAddress": "0xe1708FA6bb2844D5384613ef0846F9Bc1e8eC55E", "xvsVaultStartBlock": "0" } diff --git a/subgraphs/venus-governance/schema.graphql b/subgraphs/venus-governance/schema.graphql index 0fb61acc..342f12c5 100644 --- a/subgraphs/venus-governance/schema.graphql +++ b/subgraphs/venus-governance/schema.graphql @@ -116,20 +116,14 @@ 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! + "Total number of votes delegated expressed in the smallest unit of XVS" + totalVotesMantissa: BigInt! "Number of proposals currently queued for execution" proposalsQueued: BigInt! @@ -140,11 +134,14 @@ type Governance @entity { "The duration of voting on a proposal, in blocks" votingPeriod: BigInt! + "The number of votes required to reach quorum" + quorumVotesMantissa: BigInt! + "Active brains of Governor" implementation: Bytes! "The number of votes required in order for a voter to become a proposer" - proposalThreshold: BigInt! + proposalThresholdMantissa: BigInt! "Pending administrator for this contract" pendingAdmin: Bytes @@ -157,7 +154,23 @@ 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! + "Governor implementation the route belongs to" + governor: Bytes! + "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 { diff --git a/subgraphs/venus-governance/src/constants/addresses.ts b/subgraphs/venus-governance/src/constants/addresses.ts new file mode 100644 index 00000000..a30fd3e4 --- /dev/null +++ b/subgraphs/venus-governance/src/constants/addresses.ts @@ -0,0 +1,9 @@ +import { Address } from '@graphprotocol/graph-ts'; + +import { + governorBravoDelegateAddress as governorBravoDelegateAddressString, +} from './config'; + +export const governorBravoDelegateAddress = Address.fromString(governorBravoDelegateAddressString); + +export const nullAddress = Address.fromString('0x0000000000000000000000000000000000000000'); \ No newline at end of file diff --git a/subgraphs/venus-governance/src/constants/config-template b/subgraphs/venus-governance/src/constants/config-template new file mode 100644 index 00000000..f6c7395a --- /dev/null +++ b/subgraphs/venus-governance/src/constants/config-template @@ -0,0 +1,3 @@ +// Use yarn prepare commands to generate config typescript file per env + +export const governorBravoDelegateAddress = '{{ governorBravoDelegateAddress }}'; diff --git a/subgraphs/venus-governance/src/constants/index.ts b/subgraphs/venus-governance/src/constants/index.ts index 3e71edce..da672190 100644 --- a/subgraphs/venus-governance/src/constants/index.ts +++ b/subgraphs/venus-governance/src/constants/index.ts @@ -1,6 +1,6 @@ import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'; -export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; + export const BIGINT_ZERO = BigInt.fromI32(0); export const BIGINT_ONE = BigInt.fromI32(1); export const BIGDECIMAL_ZERO = new BigDecimal(BIGINT_ZERO); @@ -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'; diff --git a/subgraphs/venus-governance/src/mappings/bravo.ts b/subgraphs/venus-governance/src/mappings/bravo.ts index 7891be93..c96ae24e 100644 --- a/subgraphs/venus-governance/src/mappings/bravo.ts +++ b/subgraphs/venus-governance/src/mappings/bravo.ts @@ -79,7 +79,7 @@ export function handleNewImplementation(event: NewImplementation): void { export function handleProposalThresholdSet(event: ProposalThresholdSet): void { const governance = getGovernanceEntity(); - governance.proposalThreshold = event.params.newProposalThreshold; + governance.proposalThresholdMantissa = event.params.newProposalThreshold; governance.save(); } diff --git a/subgraphs/venus-governance/src/operations/get.ts b/subgraphs/venus-governance/src/operations/get.ts index 8bf38ba9..c93e9147 100644 --- a/subgraphs/venus-governance/src/operations/get.ts +++ b/subgraphs/venus-governance/src/operations/get.ts @@ -1,31 +1,72 @@ -import { Address, BigInt, log } from '@graphprotocol/graph-ts'; +import { 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/addresses'; /** - * 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.toHex()); if (!governance) { - governance = new Governance(GOVERNANCE); + const governorBravoDelegate2 = GovernorBravoDelegate2.bind(governorBravoDelegateAddress); + governance = new Governance(governorBravoDelegateAddress.toHex()); 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.totalVoters = BIGINT_ZERO; + governance.totalVotesMantissa = 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.proposalThresholdMantissa = governorBravoDelegate2.proposalThreshold(); + governance.admin = governorBravoDelegate2.admin(); + governance.implementation = governorBravoDelegate2.implementation(); + governance.guardian = governorBravoDelegate2.guardian(); + governance.quorumVotesMantissa = 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.governor = governorBravoDelegateAddress; + normalGovernanceRoute.timelock = normalTimelockAddress; + normalGovernanceRoute.queDelay = normalTimelock.delay(); + normalGovernanceRoute.votingDelay = normalProposalConfig.getVotingDelay(); + normalGovernanceRoute.votingPeriod = normalProposalConfig.getVotingPeriod(); + normalGovernanceRoute.proposalThreshold = normalProposalConfig.getProposalThreshold(); + normalGovernanceRoute.save(); + // 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.governor = governorBravoDelegateAddress; + fastTrackGovernanceRoute.timelock = fastTrackTimelockAddress; + fastTrackGovernanceRoute.queDelay = fastTrackTimelock.delay(); + fastTrackGovernanceRoute.votingDelay = fastTrackProposalConfig.getVotingDelay(); + fastTrackGovernanceRoute.votingPeriod = fastTrackProposalConfig.getVotingPeriod(); + fastTrackGovernanceRoute.proposalThreshold = fastTrackProposalConfig.getProposalThreshold(); + fastTrackGovernanceRoute.save(); + // 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.governor = governorBravoDelegateAddress; + criticalGovernanceRoute.timelock = criticalTimelockAddress; + criticalGovernanceRoute.queDelay = criticalTimelock.delay(); + criticalGovernanceRoute.votingDelay = criticalProposalConfig.getVotingDelay(); + criticalGovernanceRoute.votingPeriod = criticalProposalConfig.getVotingPeriod(); + criticalGovernanceRoute.proposalThreshold = criticalProposalConfig.getProposalThreshold(); + criticalGovernanceRoute.save(); } return governance as Governance; diff --git a/subgraphs/venus-governance/src/operations/getOrCreate.ts b/subgraphs/venus-governance/src/operations/getOrCreate.ts index db185575..af3beec2 100644 --- a/subgraphs/venus-governance/src/operations/getOrCreate.ts +++ b/subgraphs/venus-governance/src/operations/getOrCreate.ts @@ -46,6 +46,7 @@ export const getOrCreateDelegate = (id: string): GetOrCreateDelegateReturn => { if (id != ZERO_ADDRESS) { const governance = getGovernanceEntity(); governance.totalDelegates = governance.totalDelegates.plus(BIGINT_ONE); + governance.totalVoters = governance.totalVoters.plus(BIGINT_ONE); governance.save(); } diff --git a/subgraphs/venus-governance/src/operations/update.ts b/subgraphs/venus-governance/src/operations/update.ts index 87faa324..bf9f4bad 100644 --- a/subgraphs/venus-governance/src/operations/update.ts +++ b/subgraphs/venus-governance/src/operations/update.ts @@ -73,10 +73,10 @@ export function updateDelegateVoteChanged(event: E): void { delegate.save(); if (previousBalance == BIGINT_ZERO && newBalance > BIGINT_ZERO) { - governance.currentDelegates = governance.currentDelegates.plus(BIGINT_ONE); + governance.totalDelegates = governance.totalDelegates.plus(BIGINT_ONE); } if (newBalance == BIGINT_ZERO) { - governance.currentDelegates = governance.currentDelegates.minus(BIGINT_ONE); + governance.totalDelegates = governance.totalDelegates.minus(BIGINT_ONE); } governance.delegatedVotes = governance.delegatedVotes.plus(votesDifference); governance.save(); diff --git a/subgraphs/venus-governance/template.yaml b/subgraphs/venus-governance/template.yaml index e0694a3a..ae34253b 100644 --- a/subgraphs/venus-governance/template.yaml +++ b/subgraphs/venus-governance/template.yaml @@ -120,7 +120,7 @@ dataSources: name: GovernorBravoDelegate2 network: {{ network }} source: - address: "{{ governorBravoDelegate2Address }}" + address: "{{ governorBravoDelegateAddress }}" abi: GovernorBravoDelegate2 startBlock: {{ governorBravoDelegate2StartBlock }} mapping: @@ -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 @@ -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) diff --git a/subgraphs/venus-governance/tests/Alpha/index.test.ts b/subgraphs/venus-governance/tests/Alpha/index.test.ts index 8d610897..2eb0726a 100644 --- a/subgraphs/venus-governance/tests/Alpha/index.test.ts +++ b/subgraphs/venus-governance/tests/Alpha/index.test.ts @@ -2,6 +2,7 @@ import { Address, BigInt, Bytes } from '@graphprotocol/graph-ts'; import { afterEach, assert, + beforeAll, beforeEach, clearStore, describe, @@ -14,7 +15,7 @@ import { ProposalExecuted, ProposalQueued, } from '../../generated/GovernorAlpha/GovernorAlpha'; -import { GOVERNANCE } from '../../src/constants'; +import { governorBravoDelegateAddress } from '../../src/constants/addresses'; import { handleProposalCanceled, handleProposalCreated, @@ -32,6 +33,7 @@ import { createProposalQueuedEvent, createVoteCastAlphaEvent, } from '../common/events'; +import { createGovernorBravoMocks } from '../common/mocks'; const cleanup = (): void => { clearStore(); @@ -41,6 +43,10 @@ const startBlock = 4563820; const endBlock = 4593820; const description = 'Very creative Proposal'; +beforeAll(() => { + createGovernorBravoMocks(); +}) + beforeEach(() => { getOrCreateDelegate(user1.toHexString()); const proposalCreatedEvent = createProposalCreatedEvent( @@ -111,7 +117,7 @@ describe('Alpha', () => { }; const assertGovernanceDocument = (key: string, value: string): void => { - assert.fieldEquals('Governance', GOVERNANCE, key, value); + assert.fieldEquals('Governance', governorBravoDelegateAddress.toHex(), key, value); }; assertProposalDocument('status', 'QUEUED'); @@ -134,7 +140,7 @@ describe('Alpha', () => { }; const assertGovernanceDocument = (key: string, value: string): void => { - assert.fieldEquals('Governance', GOVERNANCE, key, value); + assert.fieldEquals('Governance', governorBravoDelegateAddress.toHex(), key, value); }; assertProposalDocument('status', 'EXECUTED'); diff --git a/subgraphs/venus-governance/tests/Bravo/index.test.ts b/subgraphs/venus-governance/tests/Bravo/index.test.ts index 63fcd357..55b8ef0c 100644 --- a/subgraphs/venus-governance/tests/Bravo/index.test.ts +++ b/subgraphs/venus-governance/tests/Bravo/index.test.ts @@ -2,6 +2,7 @@ import { Address, BigInt } from '@graphprotocol/graph-ts'; import { afterEach, assert, + beforeAll, beforeEach, clearStore, describe, @@ -15,7 +16,7 @@ import { ProposalExecuted, ProposalQueued, } from '../../generated/GovernorBravoDelegate/GovernorBravoDelegate'; -import { GOVERNANCE } from '../../src/constants/index'; +import { governorBravoDelegateAddress } from '../../src/constants/addresses'; import { handleBravoVoteCast, handleNewAdmin, @@ -53,6 +54,7 @@ import { createNewVotingDelayEvent, createNewVotingPeriodEvent, } from './events'; +import { createGovernorBravoMocks } from '../common/mocks'; const startBlock = 4563820; const endBlock = 4593820; @@ -63,6 +65,10 @@ const cleanup = (): void => { clearStore(); }; +beforeAll(() => { + createGovernorBravoMocks(); +}) + beforeEach(() => { /** setup test */ getOrCreateDelegate(user1.toHexString()); @@ -209,7 +215,7 @@ describe('Bravo', () => { }; const assertGovernanceDocument = (key: string, value: string): void => { - assert.fieldEquals('Governance', GOVERNANCE, key, value); + assert.fieldEquals('Governance', governorBravoDelegateAddress.toHex(), key, value); }; assertProposalDocument('status', 'QUEUED'); @@ -232,7 +238,7 @@ describe('Bravo', () => { }; const assertGovernanceDocument = (key: string, value: string): void => { - assert.fieldEquals('Governance', GOVERNANCE, key, value); + assert.fieldEquals('Governance', governorBravoDelegateAddress.toHex(), key, value); }; assertProposalDocument('status', 'EXECUTED'); @@ -273,7 +279,7 @@ describe('Bravo', () => { ); handleVotingDelaySet(votingDelayEvent); - assert.fieldEquals('Governance', GOVERNANCE, 'votingDelay', newVotingDelay.toString()); + assert.fieldEquals('Governance', governorBravoDelegateAddress.toHex(), 'votingDelay', newVotingDelay.toString()); }); test('registers new voting period', () => { @@ -286,7 +292,7 @@ describe('Bravo', () => { ); handleVotingPeriodSet(votingPeriodEvent); - assert.fieldEquals('Governance', GOVERNANCE, 'votingPeriod', newVotingPeriod.toString()); + assert.fieldEquals('Governance', governorBravoDelegateAddress.toHex(), 'votingPeriod', newVotingPeriod.toString()); }); test('registers new implementation', () => { @@ -299,7 +305,7 @@ describe('Bravo', () => { ); handleNewImplementation(newImplementationEvent); - assert.fieldEquals('Governance', GOVERNANCE, 'implementation', newImplementation.toHexString()); + assert.fieldEquals('Governance', governorBravoDelegateAddress.toHex(), 'implementation', newImplementation.toHexString()); }); test('registers new proposal threshold', () => { @@ -314,8 +320,8 @@ describe('Bravo', () => { handleProposalThresholdSet(proposalThresholdEvent); assert.fieldEquals( 'Governance', - GOVERNANCE, - 'proposalThreshold', + governorBravoDelegateAddress.toHex(), + 'proposalThresholdMantissa', newProposalThreshold.toString(), ); }); @@ -330,7 +336,7 @@ describe('Bravo', () => { ); handleNewPendingAdmin(pendingAdminEvent); - assert.fieldEquals('Governance', GOVERNANCE, 'pendingAdmin', newPendingAdmin.toHexString()); + assert.fieldEquals('Governance', governorBravoDelegateAddress.toHex(), 'pendingAdmin', newPendingAdmin.toHexString()); }); test('registers new admin', () => { @@ -339,8 +345,8 @@ describe('Bravo', () => { const newAdminEvent = createNewAdminEvent(governanceAddress, oldAdmin, newAdmin); handleNewAdmin(newAdminEvent); - assert.fieldEquals('Governance', GOVERNANCE, 'admin', newAdmin.toHexString()); - assert.fieldEquals('Governance', GOVERNANCE, 'pendingAdmin', 'null'); + assert.fieldEquals('Governance', governorBravoDelegateAddress.toHex(), 'admin', newAdmin.toHexString()); + assert.fieldEquals('Governance', governorBravoDelegateAddress.toHex(), 'pendingAdmin', 'null'); }); test('registers new guardian', () => { @@ -349,7 +355,7 @@ describe('Bravo', () => { const newGuardianEvent = createNewGuardianEvent(governanceAddress, oldGuardian, newGuardian); handleNewGuardian(newGuardianEvent); - assert.fieldEquals('Governance', GOVERNANCE, 'guardian', newGuardian.toHexString()); + assert.fieldEquals('Governance', governorBravoDelegateAddress.toHex(), 'guardian', newGuardian.toHexString()); }); test('registers new proposal max operations', () => { @@ -364,7 +370,7 @@ describe('Bravo', () => { handleProposalMaxOperationsUpdated(newProposalMaxOperationsEvent); assert.fieldEquals( 'Governance', - GOVERNANCE, + governorBravoDelegateAddress.toHex(), 'proposalMaxOperations', newProposalMaxOperations.toString(), ); diff --git a/subgraphs/venus-governance/tests/common/constants.ts b/subgraphs/venus-governance/tests/common/constants.ts index e8214b0a..f9c7478a 100644 --- a/subgraphs/venus-governance/tests/common/constants.ts +++ b/subgraphs/venus-governance/tests/common/constants.ts @@ -6,3 +6,11 @@ export const user3 = Address.fromString('0x0000000000000000000000000000000000000 export const mockContractAddress = Address.fromString('0x0000000000000000000000000000000000000999'); export const mockFunctionSig = 'mockFunc()'; + +// Mocked Governor return values +export const mockImplementationAddress = Address.fromString('0x000000000000000000000000000000000000c0DE'); +export const mockAdminAddress = Address.fromString('0x000000000000000000000000000000000000ad53'); +export const mockGuardianAddress = Address.fromString('0x000000000000000000000000000000000000536d'); +export const timelockAddress0 = Address.fromString('0x0000000000000000000000000000000000070c50'); +export const timelockAddress1 = Address.fromString('0x0000000000000000000000000000000000070c51'); +export const timelockAddress2 = Address.fromString('0x0000000000000000000000000000000000070c52'); diff --git a/subgraphs/venus-governance/tests/common/mocks.ts b/subgraphs/venus-governance/tests/common/mocks.ts new file mode 100644 index 00000000..81e4a317 --- /dev/null +++ b/subgraphs/venus-governance/tests/common/mocks.ts @@ -0,0 +1,83 @@ +import { BigInt, ethereum } from '@graphprotocol/graph-ts'; +import { createMockedFunction } from "matchstick-as"; +import { governorBravoDelegateAddress } from '../../src/constants/addresses'; +import { mockImplementationAddress, mockAdminAddress, mockGuardianAddress, timelockAddress0, timelockAddress1, timelockAddress2 } from './constants'; + +export const createGovernorBravoMocks = (): void => { + createMockedFunction(governorBravoDelegateAddress, 'votingDelay', 'votingDelay():(uint256)') + .returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('1'))]); + + createMockedFunction(governorBravoDelegateAddress, 'votingPeriod', 'votingPeriod():(uint256)') + .returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('28800'))]); + + createMockedFunction(governorBravoDelegateAddress, 'implementation', 'implementation():(address)') + .returns([ethereum.Value.fromAddress(mockImplementationAddress)]); + + createMockedFunction(governorBravoDelegateAddress, 'proposalThreshold', 'proposalThreshold():(uint256)') + .returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('300000000000000000000000'))]); + + createMockedFunction(governorBravoDelegateAddress, 'admin', 'admin():(address)') + .returns([ethereum.Value.fromAddress(mockAdminAddress)]); + + createMockedFunction(governorBravoDelegateAddress, 'guardian', 'guardian():(address)') + .returns([ethereum.Value.fromAddress(mockGuardianAddress)]); + + createMockedFunction(governorBravoDelegateAddress, 'quorumVotes', 'quorumVotes():(uint256)') + .returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('0'))]); + + createMockedFunction(governorBravoDelegateAddress, 'proposalMaxOperations', 'proposalMaxOperations():(uint256)') + .returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('0'))]); + + // Proposal Configs + createMockedFunction(governorBravoDelegateAddress, 'proposalConfigs', 'proposalConfigs(uint256):(uint256,uint256,uint256)') + .withArgs([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('0'))]) + .returns([ + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('1')), + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('28800')), + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('300000000000000000000000')), + ]); + createMockedFunction(governorBravoDelegateAddress, 'proposalConfigs', 'proposalConfigs(uint256):(uint256,uint256,uint256)') + .withArgs([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('1'))]) + .returns([ + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('1')), + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('28800')), + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('300000000000000000000000')), + ]); + createMockedFunction(governorBravoDelegateAddress, 'proposalConfigs', 'proposalConfigs(uint256):(uint256,uint256,uint256)') + .withArgs([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('2'))]) + .returns([ + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('1')), + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('7200')), + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('300000000000000000000000')), + ]); + + createMockedFunction(governorBravoDelegateAddress, 'proposalTimelocks', 'proposalTimelocks(uint256):(address)') + .withArgs([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('0'))]) + .returns([ + ethereum.Value.fromAddress(timelockAddress0), + ]); + createMockedFunction(governorBravoDelegateAddress, 'proposalTimelocks', 'proposalTimelocks(uint256):(address)') + .withArgs([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('1'))]) + .returns([ + ethereum.Value.fromAddress(timelockAddress1), + ]); + createMockedFunction(governorBravoDelegateAddress, 'proposalTimelocks', 'proposalTimelocks(uint256):(address)') + .withArgs([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('2'))]) + .returns([ + ethereum.Value.fromAddress(timelockAddress2), + ]); + + // Timelocks + createMockedFunction(timelockAddress0, 'delay', 'delay():(uint256)') + .returns([ + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('172800')), + ]); + createMockedFunction(timelockAddress1, 'delay', 'delay():(uint256)') + .returns([ + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('21600')), + ]); + createMockedFunction(timelockAddress2, 'delay', 'delay():(uint256)') + .returns([ + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('3600')), + ]); +} \ No newline at end of file