From c6906b07a12e0a6bec70f2119af16597e30ab3f8 Mon Sep 17 00:00:00 2001 From: 0xmad <0xmad@users.noreply.github.com> Date: Tue, 17 Sep 2024 14:22:38 -0500 Subject: [PATCH] fix(subgraph): remove call handler and use events for poll init --- packages/contracts/contracts/maci/Poll.sol | 3 +++ packages/subgraph/config/network.json | 8 ++++---- packages/subgraph/src/poll.ts | 8 ++++---- packages/subgraph/templates/subgraph.template.yaml | 3 +-- packages/subgraph/tests/poll/poll.test.ts | 10 +++++----- packages/subgraph/tests/poll/utils.ts | 12 ++++++------ 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/packages/contracts/contracts/maci/Poll.sol b/packages/contracts/contracts/maci/Poll.sol index 9b27b922..9389234d 100644 --- a/packages/contracts/contracts/maci/Poll.sol +++ b/packages/contracts/contracts/maci/Poll.sol @@ -20,6 +20,7 @@ contract Poll is Ownable, BasePoll, ICommon { /// @notice events event SetRegistry(address indexed registry); + event PollInit(); /// @notice custom errors error RegistryAlreadyInitialized(); @@ -113,6 +114,8 @@ contract Poll is Ownable, BasePoll, ICommon { function init() public override onlyOwner isRegistryInitialized { initTime = block.timestamp; super.init(); + + emit PollInit(); } /// @inheritdoc BasePoll diff --git a/packages/subgraph/config/network.json b/packages/subgraph/config/network.json index 5874a4d3..3b588300 100644 --- a/packages/subgraph/config/network.json +++ b/packages/subgraph/config/network.json @@ -1,7 +1,7 @@ { "network": "optimism-sepolia", - "maciContractAddress": "0xbE6e250bf8B5F689c65Cc79667589A9EBF6Fe8E3", - "registryManagerContractAddress": "0xbE6e250bf8B5F689c65Cc79667589A9EBF6Fe8E3", - "registryManagerContractStartBlock": 13160483, - "maciContractStartBlock": 13160483 + "maciContractAddress": "0xac4d16D0541ca7255579b501A2F1D6F3a436521E", + "registryManagerContractAddress": "0xed5875D05DebcDdDbd902f471447dA97c6d26d7E", + "registryManagerContractStartBlock": 17396799, + "maciContractStartBlock": 17396799 } diff --git a/packages/subgraph/src/poll.ts b/packages/subgraph/src/poll.ts index 360ac73f..cd6be511 100644 --- a/packages/subgraph/src/poll.ts +++ b/packages/subgraph/src/poll.ts @@ -2,10 +2,10 @@ import { Poll, Vote, MACI } from "../generated/schema"; import { - InitCall, MergeMaciState as MergeMaciStateEvent, MergeMessageAq as MergeMessageAqEvent, MergeMessageAqSubRoots as MergeMessageAqSubRootsEvent, + PollInit as PollInitEvent, PublishMessage as PublishMessageEvent, SetRegistry as SetRegistryEvent, } from "../generated/templates/Poll/Poll"; @@ -84,13 +84,13 @@ export function handleSetRegistry(event: SetRegistryEvent): void { poll.save(); } -export function handleInitPoll(call: InitCall): void { - const poll = Poll.load(call.to); +export function handleInitPoll(event: PollInitEvent): void { + const poll = Poll.load(event.address); if (!poll) { return; } - poll.initTime = call.block.timestamp; + poll.initTime = event.block.timestamp; poll.save(); } diff --git a/packages/subgraph/templates/subgraph.template.yaml b/packages/subgraph/templates/subgraph.template.yaml index fc692489..d533a3e4 100644 --- a/packages/subgraph/templates/subgraph.template.yaml +++ b/packages/subgraph/templates/subgraph.template.yaml @@ -84,8 +84,7 @@ templates: handler: handlePublishMessage - event: SetRegistry(indexed address) handler: handleSetRegistry - callHandlers: - - function: init() + - event: PollInit() handler: handleInitPoll file: ./src/poll.ts diff --git a/packages/subgraph/tests/poll/poll.test.ts b/packages/subgraph/tests/poll/poll.test.ts index e250c193..ffd83487 100644 --- a/packages/subgraph/tests/poll/poll.test.ts +++ b/packages/subgraph/tests/poll/poll.test.ts @@ -21,7 +21,7 @@ import { createMergeMessageAqSubRootsEvent, createPublishMessageEvent, createSetRegistryEvent, - createInitPollCall, + createInitPollEvent, } from "./utils"; export { @@ -49,13 +49,13 @@ describe("Poll", () => { }); test("should handle merge maci state properly", () => { - const call = createInitPollCall(DEFAULT_POLL_ADDRESS); + const event = createInitPollEvent(DEFAULT_POLL_ADDRESS); - handleInitPoll(call); + handleInitPoll(event); - const poll = Poll.load(call.to)!; + const poll = Poll.load(event.address)!; - assert.fieldEquals("Poll", poll.id.toHex(), "initTime", call.block.timestamp.toString()); + assert.fieldEquals("Poll", poll.id.toHex(), "initTime", event.block.timestamp.toString()); }); test("should handle poll initialization properly", () => { diff --git a/packages/subgraph/tests/poll/utils.ts b/packages/subgraph/tests/poll/utils.ts index 0a3f5222..18bce199 100644 --- a/packages/subgraph/tests/poll/utils.ts +++ b/packages/subgraph/tests/poll/utils.ts @@ -1,21 +1,21 @@ import { Address, BigInt as GraphBN, ethereum } from "@graphprotocol/graph-ts"; // eslint-disable-next-line import/no-extraneous-dependencies -import { newMockEvent, newMockCall } from "matchstick-as"; +import { newMockEvent } from "matchstick-as"; import { - InitCall, MergeMaciState, MergeMessageAq, MergeMessageAqSubRoots, PublishMessage, SetRegistry, + PollInit, } from "../../generated/templates/Poll/Poll"; -export function createInitPollCall(address: Address): InitCall { - const call = changetype(newMockCall()); - call.to = address; +export function createInitPollEvent(address: Address): PollInit { + const event = changetype(newMockEvent()); + event.address = address; - return call; + return event; } export function createMergeMaciStateEvent(address: Address, stateRoot: GraphBN, numSignups: GraphBN): MergeMaciState {