forked from subsquid-quests/single-chain-squid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31d29e3
commit 2f4ee6e
Showing
1 changed file
with
138 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,151 @@ | ||
# Squid tracking USDC transfers on Ethereum | ||
<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> | ||
</p> | ||
|
||
This [squid](https://docs.subsquid.io/) captures USDC Transfer events on ETH, stores them in a database and serves the data over a GraphQL API. | ||
[![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) | ||
|
||
The Ethereum data ingester ("processor") is located in `src/main.ts`. It can be started with `sqd process`. GraphQL server runs as a separate process started by `sqd serve`. You can also use `sqd run` to run all the services at once. | ||
[Website](https://subsquid.io) | [Docs](https://docs.subsquid.io/) | [Discord](https://discord.gg/subsquid) | ||
|
||
The squid uses [Subsquid Network](https://docs.subsquid.io/subsquid-network) as its primary data source. | ||
# Deploy a single processor squid | ||
|
||
This is a quest to run a squid with a single processor. Here is how to run it: | ||
|
||
### I. Install dependencies: Node.js, Docker, Git. | ||
|
||
<details> | ||
<summary>On Windows</summary> | ||
|
||
Dependencies: Node.js, Docker, Git. | ||
1. Enable [Hyper-V](https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v). | ||
2. Install [Docker for Windows](https://docs.docker.com/desktop/install/windows-install/). | ||
3. Install NodeJS LTS using the [official installer](https://nodejs.org/en/download). | ||
4. Install [Git for Windows](https://git-scm.com/download/win). | ||
|
||
## Quickstart | ||
In all installs it is OK to leave all the options at their default values. You will need a terminal to complete this tutorial - [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) bash is the preferred option. | ||
|
||
</details> | ||
<details> | ||
<summary>On Mac</summary> | ||
|
||
1. Install [Docker for Mac](https://docs.docker.com/desktop/install/mac-install/). | ||
2. Install Git using the [installer](https://sourceforge.net/projects/git-osx-installer/) or by [other means](https://git-scm.com/download/mac). | ||
3. Install NodeJS LTS using the [official installer](https://nodejs.org/en/download). | ||
|
||
We recommend configuring NodeJS to install global packages to a folder owned by an unprivileged account. Create the folder by running | ||
```bash | ||
# 0. Install @subsquid/cli a.k.a. the sqd command globally | ||
npm i -g @subsquid/cli | ||
mkdir ~/global-node-packages | ||
``` | ||
then configure NodeJS to use it | ||
```bash | ||
npm config set prefix ~/global-node-packages | ||
``` | ||
Make sure that the folder `~/global-node-packages/bin` is in `PATH`. That allows running globally installed NodeJS executables from any terminal. Here is a one-liner that detects your shell and takes care of setting `PATH`: | ||
``` | ||
CURSHELL=`ps -hp $$ | awk '{print $5}'`; case `basename $CURSHELL` in 'bash') DEST="$HOME/.bash_profile";; 'zsh') DEST="$HOME/.zshenv";; esac; echo 'export PATH="${HOME}/global-node-packages/bin:$PATH"' >> "$DEST" | ||
``` | ||
Alternatively you can add the following line to `~/.zshenv` (if you are using zsh) or `~/.bash_profile` (if you are using bash) manually: | ||
``` | ||
export PATH="${HOME}/global-node-packages/bin:$PATH" | ||
``` | ||
|
||
Re-open the terminal to apply the changes. | ||
|
||
# 1. Clone the repo | ||
git clone https://github.com/subsquid-labs/quest-single-chain-squid | ||
cd quest-single-chain-squid | ||
</details> | ||
<details> | ||
<summary>On Linux</summary> | ||
|
||
# 2. Install dependencies | ||
npm ci | ||
Install NodeJS (v16 or newer), Git and Docker using your distro's package manager. | ||
|
||
# 3. Start containers for the Postgres database and the network query gateway | ||
sqd up | ||
We recommend configuring NodeJS to install global packages to a folder owned by an unprivileged account. Create the folder by running | ||
```bash | ||
mkdir ~/global-node-packages | ||
``` | ||
then configure NodeJS to use it | ||
```bash | ||
npm config set prefix ~/global-node-packages | ||
``` | ||
Make sure that any executables globally installed by NodeJS are in `PATH`. That allows running them from any terminal. Open the `~/.bashrc` file in a text editor and add the following line at the end: | ||
``` | ||
export PATH="${HOME}/global-node-packages/bin:$PATH" | ||
``` | ||
Re-open the terminal to apply the changes. | ||
|
||
# 4. Build and start the processor | ||
sqd process | ||
</details> | ||
|
||
# 5. Start the GraphQL server by running in yet another terminal | ||
sqd serve | ||
### II. Install Subsquid CLI | ||
|
||
Open a terminal and run | ||
```bash | ||
npm install --global @subsquid/cli@latest | ||
``` | ||
This adds the [`sqd` command](/squid-cli). Verify that the installation was successful by running | ||
```bash | ||
sqd --version | ||
``` | ||
A healthy response should look similar to | ||
``` | ||
@subsquid/cli/2.5.0 linux-x64 node-v20.5.1 | ||
``` | ||
A GraphiQL playground will be available at [localhost:4350/graphql](http://localhost:4350/graphql). | ||
|
||
### III. Run the squid | ||
|
||
1. Open a terminal and run the following commands to create the squid and enter its folder: | ||
```bash | ||
sqd init my-awesome-squid -t https://github.com/subsquid-quests/single-chain-squid | ||
``` | ||
```bash | ||
cd my-awesome-squid | ||
``` | ||
You can replace `my-awesome-squid` with any name you choose for your squid. If a squid with that name already exists, the first command will throw an error; if that happens simply think of another name and repeat the commands. | ||
|
||
2. Press "Get Key" button in the quest card to obtain the `singleProc.key` key file. Save it to the `./query-gateway/keys` subfolder of the squid folder. The file will be used by the query gateway container. | ||
|
||
3. The template squid uses a PostgreSQL database and a query gateway. Start Docker containers that run these with | ||
```bash | ||
sqd up | ||
``` | ||
4. Prepare the squid for running by installing dependencies, building the source code and creating all the necessary database tables: | ||
```bash | ||
npm ci | ||
sqd build | ||
sqd migration:apply | ||
``` | ||
5. Start your squid with | ||
```bash | ||
sqd run . | ||
``` | ||
The command should output lines like these: | ||
``` | ||
[api] 09:56:02 WARN sqd:graphql-server enabling dumb in-memory cache (size: 100mb, ttl: 1000ms, max-age: 1000ms) | ||
[api] 09:56:02 INFO sqd:graphql-server listening on port 4350 | ||
[processor] 09:56:04 INFO sqd:processor processing blocks from 6000000 | ||
[processor] 09:56:05 INFO sqd:processor using archive data source | ||
[processor] 09:56:05 INFO sqd:processor prometheus metrics are served at port 33097 | ||
[processor] 09:56:08 INFO sqd:processor:mapping Burned 59865654 Gwei from 6000000 to 6016939 | ||
[processor] 09:56:08 INFO sqd:processor 6016939 / 17743832, rate: 5506 blocks/sec, mapping: 304 blocks/sec, 182 items/sec, eta: 36m | ||
``` | ||
The squid should sync in 10-15 minutes. When it's done, stop it with Ctrl-C, then stop and remove the auxiliary containers with | ||
```bash | ||
sqd down | ||
``` | ||
|
||
# Quest Info | ||
|
||
| Category | Skill Level | Time required (minutes) | Max Participants | Reward | Status | | ||
| ---------------- | ------------------------------------ | ----------------------- | ---------------- | ----------------------------------- | ------ | | ||
| Squid Deployment | $\textcolor{green}{\textsf{Simple}}$ | ~40 | - | $\textcolor{red}{\textsf{750tSQD}}$ | open | | ||
|
||
# Acceptance critera | ||
|
||
Sync this squid using the key from the quest card. The syncing progress is tracked by the amount of data the squid has retrieved from [Subsquid Network](https://docs.subsquid.io/subsquid-network). | ||
|
||
# About this squid | ||
|
||
This [squid](https://docs.subsquid.io/) captures USDC Transfer events on ETH, stores them in a database and serves the data over a GraphQL API. | ||
|
||
The Ethereum data ingester ("processor") is located in `src/main.ts`. It can be started with `sqd process`. GraphQL server runs as a separate process started by `sqd serve`. You can also use `sqd run` to run all the services at once. | ||
|
||
The squid uses [Subsquid Network](https://docs.subsquid.io/subsquid-network) as its primary data source. |