tmcgroul / mimick

Indexer for PSP34 NFTs for @astarnetwork

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WASM squid template (FireSquid edition)

This is a FireSquid version of the sample squid showcasing WASM log indexing for substrate chains with a Contracts pallete, like Astar. This template indexes a sample ERC-20 smart contract token transfers over the Shibuya network and serves them via graphql API.

Quickstart

# 1. Install dependencies
npm ci

# 2. Compile typescript files
make build

# 3. Start target Postgres database and detach
make up

# 4. Start the processor
make 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
make serve

Setting up env

How to build and run Swanky-node to support pallet_uniques

  1. Clone this repo
git clone git@github.com:AstarNetwork/swanky-node.git
  1. checkout working branch
git checkout feature/uniques-ce
  1. build the node
cargo build --release
  1. run the node
./target/release/swanky-node --dev --tmp -l runtime=trace -lerror,runtime::contracts=debug

To migrate old (v5) Squids to FireSquid, follow the Migration Guide

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

3. Generate database migration

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   

4. Import ABI contract and generate interfaces to decode events

It is necessary to import the respective ABI definition to decode WASM logs. For this template we used standard ERC20 interface, see src/abi/erc20.json.

To generate a type-safe facade class to decode EVM logs, use squid-ink-typegen(1):

npx squid-ink-typegen --abi src/abi/erc20.json --output src/abi/erc20.ts

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. More details will be added later.

Disclaimer

This is alpha-quality software. Expect some bugs and incompatible changes in coming weeks.

Hacks

The following hacks are used to make the template work:

1. Update the storage in ABI

HACK URL

In your ABI replace storage with this

{
    "storage": {
      "cell": {
        "key": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "ty": 0
      }
    }
}

About

Indexer for PSP34 NFTs for @astarnetwork

License:GNU General Public License v3.0


Languages

Language:TypeScript 95.8%Language:JavaScript 2.5%Language:Dockerfile 0.9%Language:Makefile 0.5%Language:Shell 0.3%