From 66c10790efcc77c9789a969c2c76bff81812187d Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Tue, 14 Jun 2022 09:55:03 +0200 Subject: [PATCH 1/3] index vote casted with params --- generated/all.schema.graphql | 2 ++ generated/governor.schema.graphql | 2 ++ src/datasources/governor.gql.json | 4 ++- src/datasources/governor.ts | 41 ++++++++++++++++++++++++++----- src/datasources/governor.yaml | 2 ++ src/fetch/governor.ts | 5 ++++ 6 files changed, 49 insertions(+), 7 deletions(-) diff --git a/generated/all.schema.graphql b/generated/all.schema.graphql index 70f358b..96d7706 100644 --- a/generated/all.schema.graphql +++ b/generated/all.schema.graphql @@ -301,6 +301,7 @@ type ProposalSupport @entity(immutable: true) { id: ID! proposal: Proposal! support: Int! + weight: BigInt! votes: [VoteReceipt!]! @derivedFrom(field: "support") } type VoteReceipt @entity(immutable: true) { @@ -310,6 +311,7 @@ type VoteReceipt @entity(immutable: true) { support: ProposalSupport! weight: BigInt! reason: String! + params: Bytes } type ProposalCreated implements Event @entity(immutable: true) { id: ID! diff --git a/generated/governor.schema.graphql b/generated/governor.schema.graphql index b601144..56e9a35 100644 --- a/generated/governor.schema.graphql +++ b/generated/governor.schema.graphql @@ -51,6 +51,7 @@ type ProposalSupport @entity(immutable: true) { id: ID! proposal: Proposal! support: Int! + weight: BigInt! votes: [VoteReceipt!]! @derivedFrom(field: "support") } type VoteReceipt @entity(immutable: true) { @@ -60,6 +61,7 @@ type VoteReceipt @entity(immutable: true) { support: ProposalSupport! weight: BigInt! reason: String! + params: Bytes } type ProposalCreated implements Event @entity(immutable: true) { id: ID! diff --git a/src/datasources/governor.gql.json b/src/datasources/governor.gql.json index 08e0909..3372d2e 100644 --- a/src/datasources/governor.gql.json +++ b/src/datasources/governor.gql.json @@ -60,6 +60,7 @@ "fields": [ { "name": "proposal", "type": "Proposal!" }, { "name": "support", "type": "Int!" }, + { "name": "weight", "type": "BigInt!" }, { "name": "votes", "type": "VoteReceipt!", "derived": "support" } ] },{ @@ -70,7 +71,8 @@ { "name": "voter", "type": "Account!" }, { "name": "support", "type": "ProposalSupport!" }, { "name": "weight", "type": "BigInt!" }, - { "name": "reason", "type": "String!" } + { "name": "reason", "type": "String!" }, + { "name": "params", "type": "Bytes" } ] },{ "name": "ProposalCreated", diff --git a/src/datasources/governor.ts b/src/datasources/governor.ts index 704fd25..de80e7b 100644 --- a/src/datasources/governor.ts +++ b/src/datasources/governor.ts @@ -11,12 +11,13 @@ import { } from '../../generated/schema' import { - Governor as GovernorContract, - ProposalCreated as ProposalCreatedEvent, - ProposalQueued as ProposalQueuedEvent, - ProposalExecuted as ProposalExecutedEvent, - ProposalCanceled as ProposalCanceledEvent, - VoteCast as VoteCastEvent, + Governor as GovernorContract, + ProposalCreated as ProposalCreatedEvent, + ProposalQueued as ProposalQueuedEvent, + ProposalExecuted as ProposalExecutedEvent, + ProposalCanceled as ProposalCanceledEvent, + VoteCast as VoteCastEvent, + VoteCastWithParams as VoteCastWithParamsEvent } from '../../generated/governor/Governor' import { @@ -146,3 +147,31 @@ export function handleVoteCast(event: VoteCastEvent): void { ev.voter = receipt.voter ev.save() } + +export function handleVoteCastWithParams(event: VoteCastWithParamsEvent): void { + let governor = fetchGovernor(event.address) + + let proposal = fetchProposal(governor, event.params.proposalId) + + let support = fetchProposalSupport(proposal, event.params.support) + support.weight += event.params.weight + support.save() + + let receipt = fetchVoteReceipt(proposal, event.params.voter) + receipt.support = support.id + receipt.weight = event.params.weight + receipt.reason = event.params.reason + receipt.params = event.params.params + receipt.save() + + let ev = new VoteCast(events.id(event)) + ev.emitter = governor.id + ev.transaction = transactions.log(event).id + ev.timestamp = event.block.timestamp + ev.governor = governor.id + ev.proposal = receipt.proposal + ev.support = receipt.support + ev.receipt = receipt.id + ev.voter = receipt.voter + ev.save() +} diff --git a/src/datasources/governor.yaml b/src/datasources/governor.yaml index 3117e85..9878396 100644 --- a/src/datasources/governor.yaml +++ b/src/datasources/governor.yaml @@ -25,4 +25,6 @@ handler: handleProposalQueued - event: VoteCast(indexed address,uint256,uint8,uint256,string) handler: handleVoteCast + - event: VoteCastWithParams(indexed address,uint256,uint8,uint256,string,bytes) + handler: handleVoteCastWithParams file: {file} diff --git a/src/fetch/governor.ts b/src/fetch/governor.ts index d2dc523..e87b457 100644 --- a/src/fetch/governor.ts +++ b/src/fetch/governor.ts @@ -20,6 +20,10 @@ import { fetchAccount } from './account' +import { + constants, +} from '@amxx/graphprotocol-utils' + export function fetchGovernor(address: Address): Governor { let contract = Governor.load(address) @@ -78,6 +82,7 @@ export function fetchProposalSupport(proposal: Proposal, support: i32): Proposal proposalSupport = new ProposalSupport(id) proposalSupport.proposal = proposal.id proposalSupport.support = support + proposalSupport.weight = constants.BIGINT_ZERO } return proposalSupport as ProposalSupport From 7102a8abf804f396d88b33bf387ec0db99918965 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Tue, 14 Jun 2022 10:23:30 +0200 Subject: [PATCH 2/3] add changelog entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77df044..8fadf74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +### Unreleased + * `Governor`: add handler for `VoteCastWithParams` events + ### 0.1.8-1 (2022-07-11) * `Governor`: improve indexing of proposal queeing From 8cd96a05fa23eaa6344a9b3d0e76b296bd90c572 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Tue, 14 Jun 2022 10:33:05 +0200 Subject: [PATCH 3/3] add cahngelog links --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fadf74..72c36ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,16 @@ # Changelog ### Unreleased - * `Governor`: add handler for `VoteCastWithParams` events + * `Governor`: add handler for `VoteCastWithParams` events ([#30](https://github.com/OpenZeppelin/openzeppelin-subgraphs/pull/30)) ### 0.1.8-1 (2022-07-11) - * `Governor`: improve indexing of proposal queeing + * `Governor`: improve indexing of proposal queeing ([#29](https://github.com/OpenZeppelin/openzeppelin-subgraphs/pull/29)) ### 0.1.8 (2022-05-18) * Update dependency to @graphprotocol/graph-cli version 0.29.x * Update dependency to @graphprotocol/graph-ts version 0.26.x * Update dependency to @amxx/graphprotocol-utils version 1.1.0 - * Use Bytes for some entities ID + * Use Bytes for some entities ID ([#25](https://github.com/OpenZeppelin/openzeppelin-subgraphs/pull/25)) * Make events and some other entites immutable * `Governor`: index the "counting mode" for OZ governors @@ -18,8 +18,8 @@ * `Governor`: fix vulnerability to ill-formed ProposalCreated events ### 0.1.7 (2022-01-27) - * `ERC1155`: fetch token uri on minting. - * `ERC1155`: fix vulnerability to ill-formed TransferBatch events + * `ERC1155`: fetch token uri on minting. ([#14](https://github.com/OpenZeppelin/openzeppelin-subgraphs/pull/14)) + * `ERC1155`: fix vulnerability to ill-formed TransferBatch events ([#16](https://github.com/OpenZeppelin/openzeppelin-subgraphs/pull/16)) ### 0.1.6 (2021-11-23) * Include emmiter address (Account) to all Event objects