A Squid project to index snowbridge transfers. It accumulates transfer events from multiple chains(i.e. Ethereum, Bridgehub, Assethub) and serves them via GraphQL API.
- node 20.x
- docker
- npm -- note that
yarn
package manager is not supported
Example commands below use sqd. Please install it before proceeding.
# 1. Install dependencies
npm ci
# 2. Copy the env and make change if necessary
cp .env.example .env
# 3. Start target Postgres database and detach
sqd up
# 4. Build the project
sqd build
# 5. Generate database migration
sqd migration:clean && sqd migration && sqd migration:apply
# 6. Start the squid processor for ethereum
sqd process:ethereum
# 7. Start the squid processor for bridgehub
sqd process:bridgehub
# 8. Start the squid processor for assethub
sqd process:assethub
# 9. Start the graphql api
sqd serve
A GraphiQL playground will be available at localhost:4350/graphql.
Start development by defining the schema of the target database via schema.graphql
.
Schema definition consists of regular graphql type declarations annotated with custom directives.
Full description of schema.graphql
dialect is available here.
Mapping developers use TypeORM entities
to interact with the target database during data processing. All necessary entity classes are
generated by the squid framework from schema.graphql
. This is done by running npx squid-typeorm-codegen
or (equivalently) sqd codegen
command.
All database changes are applied through migration files located at db/migrations
.
squid-typeorm-migration(1)
tool provides several commands to drive the process.
It is all TypeORM under the hood.
# Connect to database, analyze its state and generate migration to match the target schema.
# The target schema is derived from entity classes generated earlier.
# Don't forget to compile your entity classes beforehand!
npx squid-typeorm-migration generate
# Create template file for custom database changes
npx squid-typeorm-migration create
# Apply database migrations from `db/migrations`
npx squid-typeorm-migration apply
# Revert the last performed migration
npx squid-typeorm-migration revert
Available sqd
shortcuts:
# Build the project, remove any old migrations, then run `npx squid-typeorm-migration generate`
sqd migration:generate
# Run npx squid-typeorm-migration apply
sqd migration:apply
This is an optional part, but it is very advisable.
Event, call and runtime storage data come to mapping handlers as raw untyped json. While it is possible to work with raw untyped json data, it's extremely error-prone and the json structure may change over time due to runtime upgrades.
Squid framework provides a tool for generating type-safe wrappers around events, calls and runtime storage items for each historical change in the spec version. See the typegen page for different chains.
Squid tools assume a certain project layout.
- All compiled js files must reside in
lib
and all TypeScript sources insrc
. The layout oflib
must reflectsrc
. - All TypeORM classes must be exported by
src/model/index.ts
(lib/model
module). - Database schema must be defined in
schema.graphql
. - Database migrations must reside in
db/migrations
and must be plain js files. squid-*(1)
executables consult.env
file for a number of environment variables.
See the full desription in the documentation.
Basically transfer status should be resolved by these two queries.
- transferStatusToPolkadots
- transferStatusToEthereums
It is possible to extend squid-graphql-server(1)
with custom
type-graphql resolvers and to add request validation.
For more details, consult docs.