Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(subgraph): add subgraph module for indexing data #1203

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
7d52882
feat: add subgraph module for indexing data
hangleang Feb 18, 2024
53557cd
fix(subgraph): update
hangleang Feb 18, 2024
11f4ef0
feat: eslint, abis, generation scripts
hangleang Feb 20, 2024
1199951
fix: remove eslint disable rules
hangleang Feb 21, 2024
368e4be
Merge branch 'dev' into feat/subgraph
hangleang Feb 21, 2024
9439e57
fix: eslint
hangleang Feb 22, 2024
1ef5d72
chore: ignore generated dir for prettier
hangleang Feb 26, 2024
2e5341e
Merge branch 'dev' into feat/subgraph
hangleang Feb 26, 2024
b7c194c
Merge remote-tracking branch 'upstream/dev' into feat/subgraph
hangleang Mar 7, 2024
a15c4af
feat: add numMessages, count numSignups in Poll
hangleang Mar 19, 2024
9fe2072
Merge branch 'dev' into feat/subgraph
hangleang Mar 19, 2024
ed12ff8
fix: update lock-file due to conflict pkg
hangleang Mar 19, 2024
60a206a
fix: change subgrah network path constant
hangleang Mar 20, 2024
7337a89
Merge remote-tracking branch 'upstream/dev' into feat/subgraph
hangleang Mar 21, 2024
7343dd3
fix: resolve lock file
hangleang Mar 21, 2024
5afc791
Update subgraph/src/poll.ts
hangleang Mar 22, 2024
d438166
Update subgraph/src/poll.ts
hangleang Mar 22, 2024
b2a2c0e
Update subgraph/src/maci.ts
hangleang Mar 22, 2024
66a2597
Update subgraph/src/poll.ts
hangleang Mar 22, 2024
5758434
fix: typecasting error in
hangleang Mar 22, 2024
98a50a0
Merge remote-tracking branch 'upstream/dev' into feat/subgraph
hangleang Mar 27, 2024
c6d800a
fix: change to bigint
hangleang Apr 23, 2024
a936a71
Merge remote-tracking branch 'upstream/dev' into feat/subgraph
hangleang Apr 23, 2024
b8c14d5
fix: changed manifest based on contract update
hangleang Apr 24, 2024
3a03c0e
fix: remove unused files
hangleang Apr 25, 2024
6a95734
Merge branch 'dev' into feat/subgraph
hangleang Jun 4, 2024
67271c8
feat: add subgraph module for indexing data
hangleang Feb 18, 2024
5111611
fix(subgraph): update
hangleang Feb 18, 2024
e042065
feat: eslint, abis, generation scripts
hangleang Feb 20, 2024
70c8ef7
fix: remove eslint disable rules
hangleang Feb 21, 2024
14177f8
fix: eslint
hangleang Feb 22, 2024
88a2ed6
chore: ignore generated dir for prettier
hangleang Feb 26, 2024
264ccbe
feat: add numMessages, count numSignups in Poll
hangleang Mar 19, 2024
c1bcf1d
fix: change subgrah network path constant
hangleang Mar 20, 2024
72606a6
fix: resolve changes
hangleang Mar 21, 2024
0e27868
fix: typecasting error in
hangleang Mar 22, 2024
9886581
fix: change to bigint
hangleang Apr 23, 2024
4453163
fix: changed manifest based on contract update
hangleang Apr 24, 2024
4ac70fb
Merge branch 'old-commit' into feat/subgraph
hangleang Jun 4, 2024
80467e4
fix: update lock file
hangleang Jun 4, 2024
dbbeb36
Merge branch 'privacy-scaling-explorations:dev' into feat/subgraph
hangleang Jun 4, 2024
5d25d3a
Merge branch 'feat/subgraph-pr' into feat/subgraph
ctrlc03 Jun 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ build
typechain-types
.eslintrc.js
commitlint.config.js

# subgraph
subgraph.template.yaml
generated
subgraph/scripts
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ website/.docusaurus/
website/src/pages/solidity-docs/index.md
**/deployed-contracts.json
**/deploy-config.json
subgraph/generated/
hangleang marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 10 additions & 1 deletion cli/testScript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ node build/ts/index.js setVerifyingKeys \
--process-messages-zkey ./zkeys/ProcessMessages_10-2-1-2_test/ProcessMessages_10-2-1-2_test.0.zkey \
--tally-votes-zkey ./zkeys/TallyVotes_10-1-2_test/TallyVotes_10-1-2_test.0.zkey
node build/ts/index.js create -s 10

# switch to subgraph module
cd ../subgraph
pnpm codegen
pnpm create-local
pnpm deploy-local -l v0.1.2

# switch back to cli module
cd ../cli
node build/ts/index.js deployPoll \
--pubkey macipk.ea638a3366ed91f2e955110888573861f7c0fc0bb5fb8b8dca9cd7a08d7d6b93 \
-t 30 -i 1 -m 2 -b 1 -v 2 -se false
-t 100 -i 1 -m 2 -b 1 -v 2 -se false
node build/ts/index.js getPoll \
--quiet false
node build/ts/index.js signup \
Expand Down
6 changes: 6 additions & 0 deletions cli/ts/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
type DeployedContracts,
type DeployArgs,
} from "../utils";
import { storeSubgraphNetworks } from "../utils/storage";

/**
* Deploy MACI and related contracts
Expand Down Expand Up @@ -118,6 +119,11 @@ export const deploy = async ({
storeContractAddress("PoseidonT5", poseidonAddrs.poseidonT5, network?.name);
storeContractAddress("PoseidonT6", poseidonAddrs.poseidonT6, network?.name);

// save to the subgraph networks.json file
await maciContract.waitForDeployment();
const txn = maciContract.deploymentTransaction();
storeSubgraphNetworks("MACI", maciContractAddress, txn?.blockNumber ?? 0, network?.name);

logGreen(quiet, success(`MACI deployed at: ${maciContractAddress}`));

// return all addresses
Expand Down
12 changes: 12 additions & 0 deletions cli/ts/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@ export const oldContractAddressStoreName = "contractAddresses.old.json";
export const contractAddressesStore = path.resolve(__dirname, "..", "..", contractAddressStoreName);
// local file path where we are storing a previous deployment's contract addresses
export const oldContractAddressesStore = path.resolve(__dirname, "..", "..", oldContractAddressStoreName);
// local file name in subgraph module where we are storing the MACI contract address and block number
export const subgraphNetworkStoreName = "networks.json";
// local file path in subgraph module where we are storing the MACI contract address and block number
export const subgraphNetworkStore = path.resolve(
__dirname,
"..",
"..",
"..",
"..",
"subgraph",
subgraphNetworkStoreName,
);
46 changes: 45 additions & 1 deletion cli/ts/utils/storage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "fs";

import { contractAddressesStore } from "./constants";
import { contractAddressesStore, subgraphNetworkStore } from "./constants";
import { logError } from "./theme";

/**
Expand Down Expand Up @@ -69,3 +69,47 @@ export const doesPathExist = (paths: string[]): [boolean, string | null] => {

return notFoundPath ? [false, notFoundPath] : [true, null];
};

/**
* Read a networks.json file from disk
* @param path - the path of the file
* @returns the JSON object
*/
export const readNetworksJSONFile = (
path: string,
): Record<string, Record<string, { address: string; startBlock: number } | undefined>> => {
if (!fs.existsSync(path)) {
logError(`File ${path} does not exist`);
}

return JSON.parse(fs.readFileSync(path).toString()) as Record<
string,
Record<string, { address: string; startBlock: number } | undefined>
>;
};

/**
* Store a contract address to the local address store file in subgraph module
* @param contractName - the name of the contract
* @param address - the address of the contract
* @param blockNumber - the block number of the deployment contract
*/
export const storeSubgraphNetworks = (
contractName: string,
address: string,
startBlock = 0,
network = "default",
): void => {
// if it does not exist yet, then create it
if (!fs.existsSync(subgraphNetworkStore)) {
fs.writeFileSync(subgraphNetworkStore, "{}");
}

const networks = readNetworksJSONFile(subgraphNetworkStore);
networks[network][contractName] = {
address,
startBlock,
};

fs.writeFileSync(subgraphNetworkStore, JSON.stringify(networks, null, 2));
};
12 changes: 11 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"packages": ["circuits", "cli", "contracts", "core", "crypto", "domainobjs", "integrationTests", "website"],
"packages": [
"circuits",
"cli",
"contracts",
"core",
"crypto",
"domainobjs",
"integrationTests",
"website",
"subgraph"
],
"version": "1.2.0",
"npmClient": "pnpm",
"changelogPreset": {
Expand Down
Loading
Loading