Skip to content

Commit

Permalink
Merge pull request #438 from privacy-scaling-explorations/fix/subgrap…
Browse files Browse the repository at this point in the history
…h-tally

fix(subgraph): add create tally handler to parse tally events
  • Loading branch information
0xmad authored Nov 5, 2024
2 parents efae081 + da08c0b commit 605b6f8
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 6 deletions.
8 changes: 6 additions & 2 deletions packages/contracts/tasks/deploy/poll/01-poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ deployment.deployTask(EDeploySteps.Poll, "Deploy poll").then((task) =>

const maciContract = await deployment.getContract<MACI>({ name: EContracts.MACI, abi: MACIFactory.abi });
const pollId = await maciContract.nextPollId();
const deployerAddress = await deployment.getDeployer().then((deployer) => deployer.getAddress());

const coordinatorPubkey = deployment.getDeployConfigField<string>(EContracts.Poll, "coordinatorPubkey");
const pollDuration = deployment.getDeployConfigField<number>(EContracts.Poll, "pollDuration");
Expand Down Expand Up @@ -186,6 +187,7 @@ deployment.deployTask(EDeploySteps.Poll, "Deploy poll").then((task) =>
await Promise.all([
storage.register({
id: EContracts.Poll,
name: "contracts/maci/Poll.sol:Poll",
key: `poll-${pollId}`,
contract: pollContract,
args: [
Expand Down Expand Up @@ -215,19 +217,21 @@ deployment.deployTask(EDeploySteps.Poll, "Deploy poll").then((task) =>
id: EContracts.MessageProcessor,
key: `poll-${pollId}`,
contract: messageProcessorContract,
args: [verifierContractAddress, vkRegistryContractAddress, pollContractAddress, mode],
args: [verifierContractAddress, vkRegistryContractAddress, pollContractAddress, deployerAddress, mode],
network: hre.network.name,
}),

storage.register({
id: EContracts.Tally,
key: `poll-${pollId}`,
name: "contracts/maci/Tally.sol:Tally",
contract: tallyContract,
args: [
verifierContractAddress,
vkRegistryContractAddress,
pollContractAddress,
messageProcessorContractAddress,
deployerAddress,
mode,
],
network: hre.network.name,
Expand All @@ -236,7 +240,7 @@ deployment.deployTask(EDeploySteps.Poll, "Deploy poll").then((task) =>
storage.register({
id: EContracts.AccQueueQuinaryMaci,
key: `poll-${pollId}`,
name: "contracts/trees/AccQueueQuinaryMaci.sol:AccQueueQuinaryMaci",
name: "maci-contracts/contracts/trees/AccQueueQuinaryMaci.sol:AccQueueQuinaryMaci",
contract: messageAccQueueContract,
args: [messageTreeSubDepth],
network: hre.network.name,
Expand Down
2 changes: 1 addition & 1 deletion packages/coordinator/scripts/downloadZKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import path from "path";
const ZKEY_PATH = path.resolve(process.argv.slice(3)[0]);
const ZKEYS_URLS = {
test: "https://maci-develop-fra.s3.eu-central-1.amazonaws.com/v2.0.0/maci_artifacts_10-2-1-2_test.tar.gz",
prod: "https://maci-develop-fra.s3.eu-central-1.amazonaws.com/v1.2.0/maci_artifacts_6-9-2-3_prod.tar.gz",
prod: "https://maci-develop-fra.s3.eu-central-1.amazonaws.com/v2.0.0/maci_artifacts_14-9-2-3_prod.tar.gz",
};
const ARCHIVE_NAME = path.resolve(ZKEY_PATH, "maci_keys.tar.gz");

Expand Down
4 changes: 2 additions & 2 deletions packages/subgraph/config/network.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"network": "optimism-sepolia",
"maciContractAddress": "0x47f5C725Cc0C599060242092d918f4F33FdFC90d",
"maciContractAddress": "0xEf02daBaE8B2FFF1062Dc8F127EF8D67C475534e",
"maciContractStartBlock": 18881128,
"registryManagerContractAddress": "0x3951B8CE13183c28Dc49248412f940f64E60774e",
"registryManagerContractAddress": "0xb515a4b36989Fd785e04F760FD489EdcDb89b6d9",
"registryManagerContractStartBlock": 18881137
}
4 changes: 3 additions & 1 deletion packages/subgraph/src/maci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Poll as PollTemplate } from "../generated/templates";
import { Poll as PollContract } from "../generated/templates/Poll/Poll";

import { ONE_BIG_INT, MESSAGE_TREE_ARITY } from "./utils/constants";
import { createOrLoadMACI, createOrLoadUser, createOrLoadAccount } from "./utils/entity";
import { createOrLoadMACI, createOrLoadUser, createOrLoadAccount, createOrLoadTally } from "./utils/entity";

export function handleDeployPoll(event: DeployPollEvent): void {
const maci = createOrLoadMACI(event);
Expand Down Expand Up @@ -47,6 +47,8 @@ export function handleDeployPoll(event: DeployPollEvent): void {
// Start indexing the poll; `event.params.pollAddr.poll` is the
// address of the new poll contract
PollTemplate.create(Address.fromBytes(poll.id));

createOrLoadTally(contracts.tally, poll.id);
}

export function handleSignUp(event: SignUpEvent): void {
Expand Down
13 changes: 13 additions & 0 deletions packages/subgraph/src/utils/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Registry,
RegistryManager,
TallyResult,
Tally,
User,
} from "../../generated/schema";
import { Registry as RegistryTemplate } from "../../generated/templates";
Expand Down Expand Up @@ -110,6 +111,18 @@ export const createOrLoadRecipient = (
return recipient;
};

export const createOrLoadTally = (tally: Bytes, poll: Bytes): Tally => {
let entity = Tally.load(tally);

if (!entity) {
entity = new Tally(tally);
entity.poll = poll;
entity.save();
}

return entity;
};

export const createOrLoadDeposit = (sender: Bytes, amount: GraphBN, tally: Bytes): Deposit => {
let deposit = Deposit.load(sender);

Expand Down
6 changes: 6 additions & 0 deletions packages/subgraph/tests/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ export function mockRegistryManager(): void {
ethereum.Value.fromI32(1),
]);
}

export function mockTallyContract(): void {
createMockedFunction(DEFAULT_TALLY_ADDRESS, "poll", "poll():(address)").returns([
ethereum.Value.fromAddress(DEFAULT_POLL_ADDRESS),
]);
}
2 changes: 2 additions & 0 deletions packages/subgraph/tests/poll/poll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
mockMaciContract,
mockPollContract,
mockRegistryContract,
mockTallyContract,
} from "../common";
import { createDeployPollEvent } from "../maci/utils";

Expand All @@ -44,6 +45,7 @@ describe("Poll", () => {
mockMaciContract();
mockPollContract();
mockRegistryContract();
mockTallyContract();

// mock the deploy poll event with non qv mode set
const event = createDeployPollEvent(BigInt.fromI32(1), BigInt.fromI32(1), BigInt.fromI32(1), BigInt.fromI32(1));
Expand Down

0 comments on commit 605b6f8

Please sign in to comment.