Skip to content

LightmNFT/lightm-squid

Repository files navigation

Lightm Squid

Lightm Squid is used for index related data on chain, just like The Graph but more flexible and allowing for more complex query structures, this is why Lightm migrated from The Graph to Subsquid.

Starting the local environment

Before doing this, make sure you have Node.js and Docker installed.

And you have to clone Lightm-evm and check the README in it.

Then

  1. Run npm i;
  2. Run make build to compile files in src to lib;
  3. Run make up-local-archive to start db to collecting local test net data (make sure you start local test net on localhost:8545);
  4. Run make up to start db for processor;
  5. Run make process to start the processor, index and aggregate event data on chain;
  6. Open a new terminal window, run make serve to start graphql server;

Minimal EVM squid

This is a starter template of a squid indexer for EVM networks (Ethereum, Polygon, BSC, etc.). See

To extract EVM logs and transactions by a topic or a contract address, use EvmBatchProcessor.addLog() and EvmBatchProcessor.addTransaction() methods of EvmBatchProcessor, defined in src/processor.ts.

The requested data is transformed in batches by a single handler provided by the processor.run() method.

For a full list of supported networks and config options, check the EvmBatchProcessor overview and the configuration page.

For a step-by-step migration guide from TheGraph, see the dedicated docs page.

Quickstart

Install Squid CLI:

npm i -g @subsquid/cli

Run the indexer and the GraphQL API:

# 1. Update the Squid SDK and install dependencies
npm run update
npm ci

# 2. Compile typescript files
sqd build

# 3. Start target Postgres database and detach
sqd up

# 4. Start the processor
sqd process

# 5. The command above will block the terminal
#    being busy with fetching the chain data, 
#    transforming and storing it in the target database.
#
#    To start the graphql server open the separate terminal
#    and run. The GraphQL playground will be available at localhost:4350graphl
sqd serve

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 sqd codegen command.

3. Generate database migrations

All database changes are applied through migration files located at db/migrations. squid-typeorm-migration(1) tool provides several commands to drive the process.

## delete all migrations
rm -rf db/migrations/*.js

## drop create the database
make down
make up

## create a new schema migration from the entities
npx squid-typeorm-migration generate      

See docs on schema updates 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.

To generate a type-safe facade class to decode EVM logs, place the ABI in the assets folder and use squid-evm-typegen(1), e.g.:

npx squid-evm-typegen src/abi assets/ERC721.json#erc721

For more details about squid-evm-typegen read the docs 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 a number of environment variables.

GraphQL server extensions

It is possible to extend squid-graphql-server(1) with custom type-graphql resolvers and to add request validation. See the docs for more details.

Releases

No releases published

Packages

No packages published

Languages