Skip to content

OriginProtocol/prime-squid

Repository files navigation

Prime Staked ETH Subsquid

Setup

# Install @subsquid/cli - the `sqd` command globally
npm i -g @subsquid/cli

# Install dependencies
npm ci

Frequent Commands

sqd typegen
yarn codegen && yarn migration:generate
yarn setup && yarn process:lrt
sqd serve

With sqd serve a GraphiQL playground will be available at localhost:4350/graphql.

Env Options

BLOCK_FROM=18421105 yarn process:lrt # Start processing at block 18421105
BLOCK_TO=18421105 yarn process:lrt   # Process up to block 18421105

Dev flow

1. Define database schema

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.

2. Generate TypeORM classes

Mapping developers use TypeORM EntityManager to interact with target database during data processing. All necessary entity classes are generated by the squid framework from schema.graphql. This is done by running yarn codegen command.

3. Generate database migrations

All database changes are applied through migration files located at db/migrations. There is only ever one migration.

yarn migration:generate

See docs on database migrations for more details.

4. Import ABI contract and generate interfaces to decode events

It is necessary to import the respective ABI definition to decode EVM logs. One way to generate a type-safe facade class to decode EVM logs is by placing the relevant JSON ABIs to ./abi, then using squid-evm-typegen(1) via an sqd script:

sqd typegen

See more details on the squid-evm-typegen doc page.

Project conventions

Squid tools assume a certain project layout:

  • All compiled js files must reside in lib and all TypeScript sources in src. The layout of lib must reflect src.
  • 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.
  • sqd(1) and squid-*(1) executables consult .env file for environment variables.

Deploy a new version

  • Visit Squid deploy dashboard
  • Auth with sqd auth -k sqd_XXX (key is on squid deploy page)
  • Update squid.yaml to set the correct version
  • Run sqd deploy .
  • Make branch for new version (eg v9) and push to origin
  • Switch back to main branch

Releases

No releases published

Packages

No packages published