Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kodadot/basick


https://github.com/kodadot/basick

evm kodadot nft subsquid

Last synced: 24 days ago
JSON representation

Awesome Lists containing this project

README

        

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/kodadot/basick)

# Basick

Basick is a squid indexer for Generative art utilized by
[@kodadot](https://github.com/kodadot).

Dependencies: Node.js, Docker.

## Contract deployments

> [!TIP] The following table lists the deployed contracts on the respective
> networks. Make sure that contract addresses are always lowercased,

| | REGISTRY | BASE-DEV |
| -------- | ------------------------------------------- | -------- |
| BASE | 0xcacfe59736172a192c2518f0f83b825b984cc399 | |
| BASE-DEV | 0x672c524543454a5ffb0840131158a26296b0426c | |
| MANTLE | 0x1b60a7ee6bba284a6aafa1eca0a1f7ea42099373% | |

## Quickstart

```bash
# 0. Install @subsquid/cli a.k.a. the sqd command globally
npm i -g @subsquid/cli

# 1. Retrieve the template
sqd init my_squid_name -t evm
cd my_squid_name

# 2. Install dependencies
npm ci

# 3. Start a Postgres database container and detach
sqd up

# 4. Build and 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
sqd serve
```

A GraphiQL playground will be available at
[localhost:4350/graphql](http://localhost:4350/graphql).

## 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](https://docs.subsquid.io/basics/schema-file).

### 2. Generate TypeORM classes

Mapping developers use TypeORM
[EntityManager](https://typeorm.io/#/working-with-entity-manager) 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.

```bash
## drop create the database
sqd down
sqd up

## replace any old schemas with a new one made from the entities
sqd migration:generate
```

See [docs on database migrations](https://docs.subsquid.io/basics/db-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:

```bash
sqd typegen
```

See more details on the
[`squid-evm-typegen` doc page](https://docs.subsquid.io/evm-indexing/squid-evm-typegen).

## Project conventions

Squid tools assume a certain
[project layout](https://docs.subsquid.io/basics/squid-structure):

- 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.

## DEV hacks

1. EVM contract address needs to be all lowercase

```bash
pbpaste | tr '[:upper:]' '[:lower:]'
```

2. [Indexing proxy contracts](https://docs.subsquid.io/sdk/resources/evm/proxy-contracts/)

3. Extracting new event / transaction

- use `EvmBatchProcessor.addLog()` for events
- use `EvmBatchProcessor.addTransaction()` for transactions

> [!NOTE] instance of `EvmBatchProcessor` is defined in `src/processor.ts`.
> [`EvmBatchProcessor` overview](https://docs.subsquid.io/develop-a-squid/evm-processor/)
> check the and the
> [configuration page](https://docs.subsquid.io/develop-a-squid/evm-processor/configuration/)

4. Setting up `.env` for particular network

You always have defined correct variables in the Squid config
`.yaml` under `processor.env`. Copy them to `.env` file in the root
of the project.

> [!TIP] Example of `.env` file for `base-mainnet` network

```bash
SQD_DEBUG=squid:log
CHAIN=base-mainnet
STARTING_BLOCK=14717520
CONTRACT_REGISTRY=0xcacfe59736172a192c2518f0f83b825b984cc399
```