Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Snapshot subgraph migration quest - Ricqcodes #11

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_NAME=squid
DB_PORT=23798
GQL_PORT=4350
# JSON-RPC node endpoint, both wss and https endpoints are accepted
RPC_ENDPOINT=
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_NAME=squid
DB_PORT=23798
GQL_PORT=4350
# JSON-RPC node endpoint, both wss and https endpoints are accepted
RPC_ENDPOINT=
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.DS_Store
.env
node_modules
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Subsquid Labs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
113 changes: 88 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,103 @@
<p align="center">
<picture>
<source srcset="https://uploads-ssl.webflow.com/63b5a9958fccedcf67d716ac/64662df3a5a568fd99e3600c_Squid_Pose_1_White-transparent-slim%201.png" media="(prefers-color-scheme: dark)">
<img src="https://uploads-ssl.webflow.com/63b5a9958fccedcf67d716ac/64662df3a5a568fd99e3600c_Squid_Pose_1_White-transparent-slim%201.png" alt="Subsquid Logo">
</picture>
<picture>
<source srcset="https://uploads-ssl.webflow.com/63b5a9958fccedcf67d716ac/64662df3a5a568fd99e3600c_Squid_Pose_1_White-transparent-slim%201.png" media="(prefers-color-scheme: dark)">
<img src="https://uploads-ssl.webflow.com/63b5a9958fccedcf67d716ac/64662df3a5a568fd99e3600c_Squid_Pose_1_White-transparent-slim%201.png" alt="Subsquid Logo">
</picture>
</p>

[![docs.rs](https://docs.rs/leptos/badge.svg)](https://docs.subsquid.io/)
[![Discord](https://img.shields.io/discord/1031524867910148188?color=%237289DA&label=discord)](https://discord.gg/subsquid)
# Snapshot Squid

[Website](https://subsquid.io) | [Docs](https://docs.subsquid.io/) | [Discord](https://discord.gg/subsquid)
Snapshot Squid is an implementation of the [Snapshot Subgraph](https://thegraph.com/hosted-service/subgraph/snapshot-labs/snapshot) using the [Squid SDK](https://docs.subsquid.io/), migrating the snapshot subgraph to the squid SDK. It provides a powerful and flexible way to interact with on-chain data and query information from the Ethereum blockchain.

# Snapshot Subgraph migration
## Prerequisites

This quest is to migrate the [Snapshot Subgraph](https://thegraph.com/hosted-service/subgraph/snapshot-labs/snapshot) to Squid SDK. The resulting squid should match the GraphQL API of the subgraph as close as possible, by migrating `schema.graphql`. The judges reserve the right to request improvements afther the initial review of the submission. Reach out to the [Discord Channel]( https://discord.com/channels/857105545135390731/1155812879770058783) for any tech questions regarding this quest.
Before getting started, ensure you have the following dependencies installed on your machine:

# Quest Info
- [Node.js](https://nodejs.org/): JavaScript runtime for running JavaScript applications.
- [Docker](https://www.docker.com/): Used to manage containers for PostgreSQL.

| Category | Skill Level | Time required (hours) | Max Participants | Reward | Status |
| ---------------- | ------------------------------------ | --------------------- | ---------------- | ---------------------------------- | ------ |
| Squid Deployment | $\textcolor{green}{\textsf{Intermediate}}$ | ~40 | 5 | $\textcolor{red}{\textsf{2000tSQD}}$ | open |
## Quickstart

# Acceptance critera
Follow these steps to set up and run Snapshot Squid migration on your local machine:

Each quest should be submitted as a private repo and will be reviewed manually. To submit, create an issue with url to your repo and invite the following github accounts: [@dariaag](https://github.com/dariaag), [@belopash](https://github.com/belopash), [@abernatskiy](https://github.com/abernatskiy) and [@dzhelezov](https://github.com/dzhelezov). The repo should contain `README.MD` with
```bash
# 0. Install @subsquid/cli globally (the sqd command)
npm i -g @subsquid/cli

- Insturctions how to run the squid locally
- Sample Squid queries and the corresponding Subgraph queries
# 1. Clone the repository
git clone https://github.com/RicqCodes/snapshot-subgraph-migration.git

The code should be well documented. The judges will access:
# 2. Navigate to the project folder
cd snapshot-squid

- In-line commends where necessary
- Clarity of the code
- Performance and optimization (if [batching](https://docs.subsquid.io/basics/batch-processing/) and [Multicall queries](https://docs.subsquid.io/tutorials/bayc/step-four-optimizations/#using-multicall-for-aggregating-state-queries) are used whenever appropriate)
# 3. Rename .env.example to .env and configure environment variables

# Useful links
# 4. Install project dependencies
npm i

- [Quickstart](https://docs.subsquid.io/deploy-squid/quickstart/)
- [TheGraph Migration guide](https://docs.subsquid.io/migrate/migrate-subgraph/)
- [Snapshot Subgraph source code](https://github.com/snapshot-labs/snapshot-subgraph)
# 5. Build the project
sqd build

# 6. Start a PostgreSQL database container and detach
sqd up

# 7. Run migrations
sqd migration:generate
sqd migration:run

# 8. Start the processor
sqd process

# 9. The processor command will block the terminal while fetching chain data,
# transforming it, and storing it in the target database.
# To start the GraphQL server, open a separate terminal and run
sqd serve
```

A GraphiQL playground will be available at [localhost:4350/graphql](http://localhost:4350/graphql).

## Query Examples

### Squid Query

```
query MyQuery {
delegations(limit: 5) {
id
delegator
space
delegate
}
blocks(limit: 5) {
id
number
timestamp
}
}
```

#### Output

![Screenshot from 2023-10-02 00-41-39](https://github.com/0xNomind/snapshot-squid/assets/140236074/b02b0a50-00c7-442b-8e64-8ecea8fa8ad5)

## Graph Query

```
{
delegations(first: 5) {
id
delegator
space
delegate
}
blocks(first: 5) {
id
number
timestamp
}
}
```

#### Output

![Screenshot from 2023-10-02 00-46-42](https://github.com/0xNomind/snapshot-squid/assets/140236074/5c3a4505-de51-4041-b504-56743b792dcf)
Loading