Skip to content

Commit

Permalink
Merge pull request #542 from semaphore-protocol/chore/subgraph
Browse files Browse the repository at this point in the history
Semaphore subgraph in main repository
  • Loading branch information
cedoor authored Jan 11, 2024
2 parents 58878af + d023855 commit 2ecb726
Show file tree
Hide file tree
Showing 22 changed files with 3,268 additions and 98 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ dist
build
/docs

# subgraph
subgraph.template.yaml
generated

# Docusaurus cache and generated files
.docusaurus
.cache-loader
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,48 @@ jobs:
- name: Build libraries
run: yarn build:libraries

- name: Build subgraph
run: yarn build:subgraph

- name: Run Prettier
run: yarn prettier

- name: Run Eslint
run: yarn lint

test-subgraph:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install Node.js
uses: actions/setup-node@v1
with:
node-version: 16.x

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"

- name: Restore yarn cache
uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn

- name: Build subgraph
run: yarn build:subgraph

- name: Test subgraph
run: yarn test:subgraph

test:
runs-on: ubuntu-latest
strategy:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
- name: Build libraries
run: yarn build:libraries

- name: Build subgraph
run: yarn build:subgraph

- name: Run Prettier
run: yarn prettier

Expand Down Expand Up @@ -77,5 +80,8 @@ jobs:
- name: Build libraries
run: yarn build:libraries

- name: Test contracts and libraries
- name: Build subgraph
run: yarn build:subgraph

- name: Test contracts, libraries and subgraph
run: yarn test
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ dist
build
/docs

# subgraph
subgraph.template.yaml
generated

# github
.github/ISSUE_TEMPLATE

Expand Down
8 changes: 8 additions & 0 deletions apps/subgraph/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Generate output
generated

# The Graph
subgraph.yaml

# Tests
tests/.bin/semaphore.wasm
137 changes: 137 additions & 0 deletions apps/subgraph/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<h1 align="center">
Semaphore Subgraph
</h1>

<p align="center">
<a href="https://github.com/semaphore-protocol" target="_blank">
<img src="https://img.shields.io/badge/project-Semaphore-blue.svg?style=flat-square">
</a>
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/LICENSE">
<img alt="Github license" src="https://img.shields.io/github/license/semaphore-protocol/semaphore.svg?style=flat-square">
</a>
<a href="https://eslint.org/" target="_blank">
<img alt="Linter eslint" src="https://img.shields.io/badge/linter-eslint-8080f2?style=flat-square&logo=eslint">
</a>
<a href="https://prettier.io/" target="_blank">
<img alt="Code style prettier" src="https://img.shields.io/badge/code%20style-prettier-f8bc45?style=flat-square&logo=prettier">
</a>
</p>

<div align="center">
<h4>
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/CONTRIBUTING.md">
👥 Contributing
</a>
<span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/CODE_OF_CONDUCT.md">
🤝 Code of conduct
</a>
<span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>
<a href="https://github.com/semaphore-protocol/semaphore/issues/new/choose">
🔎 Issues
</a>
<span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>
<a href="https://semaphore.pse.dev/discord">
🗣️ Chat &amp; Support
</a>
</h4>
</div>

| The Graph is an indexing protocol for querying networks like Ethereum and IPFS. Our subgraphs allow you to get data from the [`Semaphore.sol`](https://github.com/semaphore-protocol/semaphore/blob/main/contracts/Semaphore.sol) smart contract. |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

## Networks

| Semaphore version | Sepolia | Goerli | Mumbai | Optimism Goerli | Arbitrum Goerli | Arbitrum One |
| ----------------- | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| v2.0 | N/A | N/A | N/A | N/A | N/A | [semaphore-protocol/arbitrum](https://thegraph.com/hosted-service/subgraph/semaphore-protocol/arbitrum) |
| v2.5 | N/A | [semaphore-protocol/goerli](https://thegraph.com/hosted-service/subgraph/semaphore-protocol/goerli) | N/A | N/A | N/A | N/A |
| v2.6 | N/A | [semaphore-protocol/goerli-5259d3](https://thegraph.com/hosted-service/subgraph/semaphore-protocol/goerli-5259d3) | N/A | N/A | N/A | [semaphore-protocol/arbitrum-86337c](https://thegraph.com/hosted-service/subgraph/semaphore-protocol/arbitrum-86337c) |
| v3.0 - v3.1 | N/A | [semaphore-protocol/goerli-89490c](https://thegraph.com/hosted-service/subgraph/semaphore-protocol/goerli-89490c) | N/A | N/A | N/A | [semaphore-protocol/arbitrum-72dca3](https://thegraph.com/hosted-service/subgraph/semaphore-protocol/arbitrum-72dca3) |
| >= v3.2 | [semaphore-sepolia](https://api.studio.thegraph.com/query/14377/semaphore-sepolia/v3.6.1) | [semaphore-goerli](https://api.studio.thegraph.com/query/14377/semaphore-goerli/v3.6.1) | [semaphore-mumbai](https://api.studio.thegraph.com/query/14377/semaphore-mumbai/v3.6.1) | [semaphore-optimism-goerli](https://api.studio.thegraph.com/query/14377/semaphore-optimism-goerli/v3.6.1) | [semaphore-arbitrum-goerli](https://api.studio.thegraph.com/query/14377/semaphore-arbitrum-goerli/v3.6.1) | [semaphore-arbitrum](https://api.studio.thegraph.com/query/14377/semaphore-arbitrum/v3.6.1) |

## 🛠 Install

Clone this repository:

```bash
git clone https://github.com/semaphore-protocol/semaphore.git
```

and install the dependencies:

```bash
cd semaphore/apps/subgraph && yarn
```

## Usage

The subgraph definition consists of a few files:

- `subgraph.template.yaml`: a YAML file containing the subgraph manifest,
- `schema.graphql`: a GraphQL schema that defines what data is stored for the subgraph, and how to query it via GraphQL,
- `src/semaphore.ts`: AssemblyScript code that translates from the event data to the entities defined in the schema.

### Code generation

Generate AssemblyScript types for the subgraph (required every time the schema changes):

```bash
yarn codegen <network>
```

It also generates a `subgraph.yaml` file for your specific network.

### Testing

After generating the types and `subgraph.yaml` file, test your subgraph:

```bash
yarn test
```

### Deployment

#### TheGraph Studio

Set the authorization code that links your account on thegraph.com:

```bash
yarn auth <access-token>
```

Deploy the subgraph to the [TheGraph Studio](https://thegraph.com/studio/):

```bash
yarn deploy <subgraph-name>
```

#### Local

Start services required for TheGraph node by running:

```bash
docker compose -f docker-compose-graph.yml up
```

Start a local Hardhat node and deploy the [Semaphore contract](https://github.com/semaphore-protocol/semaphore/tree/main/packages/contracts):

```bash
# CWD = /semaphore/packages/contracts
yarn start
yarn deploy:semaphore --network localhost
```

Create the `subgraph.yaml` file for your local network and create/deploy your subgraph:

```bash
yarn codegen localhost
yarn create-local
yarn deploy-local
```

Once the subgraph is published it will start indexing. You can query the subgraph using the following GraphQL endpoint:

```
http://127.0.0.1:8000/subgraphs/name/sempahore/graphql
```
Loading

0 comments on commit 2ecb726

Please sign in to comment.