Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸŽ‰ 🏹 πŸ¦‘ Hello #194

Merged
merged 155 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
f300bd4
:arrow_up: almost_all_deps
vikiival Nov 19, 2023
2a02f75
:wrench: CHAIN now relates to the Relay Chain
vikiival Nov 19, 2023
dcdca01
:zap: kinky setup of env
vikiival Nov 19, 2023
b8df3d7
πŸ’˜ πŸ¦‘ is my best friend
vikiival Nov 19, 2023
6e661a1
:loud_sound: :bug: extra dot on legacy handlers
vikiival Nov 19, 2023
75e9d3d
:zap: Processor
vikiival Nov 19, 2023
4cdb8ea
:label: Found 282 errors in 30 files.
vikiival Nov 19, 2023
754915d
:label: :bug: Fields were never
vikiival Nov 20, 2023
6698aa2
:sparkles: will it blend?
vikiival Nov 20, 2023
bc68bee
:bug: mastery of new implementations
vikiival Nov 20, 2023
5ad4e2d
:zap: using mainfreame
vikiival Nov 20, 2023
db573f0
:squid: typegen v2
vikiival Nov 20, 2023
6a3703a
:sparkles: mainframe
vikiival Nov 20, 2023
15c4f96
:squid: typegen v2
vikiival Nov 20, 2023
ed2dae9
:truck: new naming for Asset Hubs
vikiival Nov 20, 2023
67d2d99
:truck: new naming for Asset Hubs
vikiival Nov 20, 2023
80802e5
:construction: change import
vikiival Nov 20, 2023
6e9980b
:construction: remove Event(ctx)
vikiival Nov 20, 2023
b2437e8
:construction: replaced .Uniques with .
vikiival Nov 20, 2023
607b8af
:construction: remove new from events
vikiival Nov 20, 2023
e8c9555
:construction: transform to lowercase
vikiival Nov 20, 2023
b5f326b
:zap: logical replacement
vikiival Nov 20, 2023
d4d3671
--amend
vikiival Nov 20, 2023
d8c9c0c
:zap: logical replacement
vikiival Nov 20, 2023
58d8c66
:zap: magick
vikiival Nov 20, 2023
b53042d
:truck: move according new namings
vikiival Nov 20, 2023
593b38d
:truck: move according new namings in nft pallet
vikiival Nov 20, 2023
5c9433e
:robot: new just
vikiival Nov 20, 2023
cd9036e
:robot: new just
vikiival Nov 20, 2023
bb274d2
:robot: build before process
vikiival Nov 20, 2023
0c58891
:wrench: working stuff
vikiival Nov 20, 2023
791e8bd
:loud_sound: debug from metasquid
vikiival Nov 20, 2023
8429ce7
:zap: correct way of doing things
vikiival Nov 20, 2023
05a750d
:robot: came, saw, conquer
vikiival Nov 20, 2023
5633a11
:robot: supaoptimized quick
vikiival Nov 20, 2023
497f59b
:label: fieldSelection
vikiival Nov 20, 2023
2da7dcf
:zap: very fancy hacking
vikiival Nov 20, 2023
2c5ccda
:zap: cute context
vikiival Nov 20, 2023
ad1a53b
:label: OMG TYPES!!
vikiival Nov 20, 2023
aaf08e1
:zap: types
vikiival Nov 21, 2023
ef6252b
:zap: import store from Store
vikiival Nov 21, 2023
36aa421
πŸ“£ optionally logger
vikiival Nov 21, 2023
6fc2beb
:bug: nft mappings
vikiival Nov 21, 2023
1d1a965
:shrug: probably how to do things
vikiival Nov 21, 2023
f9ab284
Merge remote-tracking branch 'origin/main' into arrow-stick
vikiival Dec 28, 2023
9c84018
:arrow_up: Arrow Stick
vikiival Dec 28, 2023
ab9e104
:arrow_up: Arrow Stick
vikiival Dec 28, 2023
e9c6b53
:wastebasket: remove dummy handler
vikiival Dec 28, 2023
0ed64b1
:boom: @kodadot1/metasquid
vikiival Dec 29, 2023
7b7fb3e
:construction: MVP
vikiival Dec 29, 2023
f38eaa7
:bug: :label: Property 'prototype' is missing in type 'Store' but req…
vikiival Dec 29, 2023
19abfce
:zap: using emOf() for non-compatible queries
vikiival Dec 29, 2023
e324974
:zap: :technologist: emOf saves the day
vikiival Dec 29, 2023
5a7be96
:zap: :technologist: emOf saves the day
vikiival Dec 29, 2023
e53c4be
:label: :technologist: Reexported fields as selections
vikiival Dec 30, 2023
8eca90b
:zap: veeery big handler
vikiival Dec 30, 2023
d077ea1
Merge remote-tracking branch 'origin/main' into arrow-stick
vikiival Jan 12, 2024
55ba59e
:truck: Context is confusing in ksm getters
vikiival Jan 12, 2024
1e15948
:zap: very fake compat
vikiival Jan 12, 2024
516ee07
:bug: emOf
vikiival Jan 12, 2024
9ab8859
⏳ well test time
vikiival Jan 12, 2024
b132a4d
:zap: then you stepped out
vikiival Jan 12, 2024
06bf08a
:tada: typegen for v2 on ahp
vikiival Jan 12, 2024
54c88fb
:boom: polkadot types
vikiival Jan 12, 2024
9abad49
:truck: statemint -> polkadot
vikiival Jan 12, 2024
e1e303f
:tada: uniques @ polkadot
vikiival Jan 12, 2024
01573ff
:tada: nfts @ polkadot
vikiival Jan 12, 2024
f18a487
πŸ¦„ uuu
vikiival Jan 12, 2024
7dd0650
:zap: missing handlers
vikiival Jan 15, 2024
01e1305
:zap: unHex
vikiival Jan 15, 2024
c4584a8
:boom: hex is my best fren
vikiival Jan 15, 2024
3963c0d
:bug: incorrect codec
vikiival Jan 15, 2024
822331d
:robot: dump as you go
vikiival Jan 16, 2024
c6988a1
:zap: unhex values
vikiival Jan 16, 2024
67cda40
:bug: key is hex value too
vikiival Jan 16, 2024
37608ac
:bug: do not hex the value
vikiival Jan 16, 2024
85b41ee
:zap: hexify in the handler
vikiival Jan 16, 2024
ab5ac48
:zap: royalty works!
vikiival Jan 17, 2024
77b18bb
:heavy_plus_sign: @kodadot1/hyperdata
vikiival Jan 17, 2024
253a4c8
:boom: compatible metadata
vikiival Jan 17, 2024
2d8597d
πŸ“– readme
roiLeo Jan 17, 2024
60f58d3
:squid: typegen for assets
vikiival Jan 17, 2024
99a3ddb
:squid: TYPEGEN
vikiival Jan 17, 2024
6ecc325
:squid: TYPEGEN
vikiival Jan 17, 2024
0ad0146
:squid: TYPEGEN On events
vikiival Jan 17, 2024
f839dd5
:squid: Typegen final
vikiival Jan 17, 2024
e00bdf0
:wave: Asset
vikiival Jan 17, 2024
04cdf61
:zap: enable metadata set
vikiival Jan 17, 2024
17cba47
:broom: imports
vikiival Jan 17, 2024
10ff323
:tada: getters for assets
vikiival Jan 17, 2024
e2bf2ef
:tada: assets
vikiival Jan 17, 2024
af864eb
:zap: register assets
vikiival Jan 17, 2024
00f4b1f
:label: Chain type
vikiival Jan 17, 2024
313fe7a
:zap: new ops
vikiival Jan 17, 2024
a2dbb95
:wrench: Start block
vikiival Jan 17, 2024
34a5532
:zap: force create tokens
vikiival Jan 17, 2024
0a48dff
Merge pull request #199 from kodadot/very-nice-assets
vikiival Jan 17, 2024
a2c2107
✨ royalty event
roiLeo Jan 22, 2024
4de9c0f
:wrench: enable typegen of update_mint_settings call
vikiival Jan 22, 2024
8ddaf93
:squid: Typegen for Kusama on call
vikiival Jan 22, 2024
b03a63f
:squid: Typegen for Polkadot on call
vikiival Jan 22, 2024
a49ee50
:wrench: NonFungibleCall are new processables
vikiival Jan 22, 2024
3f57fa0
:zap: update mint settings getter
vikiival Jan 22, 2024
75e7391
:label: update mint settings
vikiival Jan 22, 2024
00fe586
:tada: cool getter
vikiival Jan 22, 2024
b294037
:alien: collection type + settings
vikiival Jan 22, 2024
11e7670
:squid: codgen on collection settings
vikiival Jan 22, 2024
1f93bd1
:zap: collectionSettingOf
vikiival Jan 22, 2024
0d9dbfe
:tada: update mint settings
vikiival Jan 22, 2024
a4a4872
:zap: update mint settings
vikiival Jan 22, 2024
a92e09b
:label: CollectionType on collection.type
vikiival Jan 23, 2024
930cea3
Merge pull request #202 from kodadot/feat/collection-type
vikiival Jan 23, 2024
af8d823
Merge remote-tracking branch 'origin/arrow-stick' into feature/royalt…
roiLeo Jan 23, 2024
efd8533
✨ royalty tips
roiLeo Jan 23, 2024
d88ca4a
:heavy_plus_sign: vitest
vikiival Jan 23, 2024
23c825b
:tada: :test_tube: unit tests
vikiival Jan 23, 2024
1d6461c
:technologist: mark old functions as deprecated
vikiival Jan 23, 2024
6fa93d6
:tada: :test_tube: unit test for unhex
vikiival Jan 23, 2024
9af964c
Merge pull request #203 from kodadot/feat/very-tests
vikiival Jan 23, 2024
1338845
Merge pull request #201 from roiLeo/feature/royalty/event
vikiival Jan 23, 2024
4406072
:alien: CacheStatus
vikiival Jan 23, 2024
b0c85e3
:squid: codgen on CacheStatus
vikiival Jan 23, 2024
cb9750d
:tada: caaaache
vikiival Jan 23, 2024
b2fa71e
:zap: enable cache;
vikiival Jan 23, 2024
e0cc6c8
πŸ“– readme
roiLeo Jan 23, 2024
8bc71d4
Merge pull request #206 from kodadot/feat/retry-ipfs
vikiival Jan 23, 2024
aba270e
Merge pull request #205 from roiLeo/chore/readme/arrow
vikiival Jan 23, 2024
7012c40
πŸ”§ lint code
roiLeo Jan 23, 2024
7511aa4
Merge pull request #210 from roiLeo/chore/linter
vikiival Jan 23, 2024
14cc99f
Add migration for cache_status table
vikiival Jan 23, 2024
6b7af79
:wrench: hacking over docker compose
vikiival Jan 24, 2024
de9506b
:mute: do not process assets
vikiival Jan 24, 2024
86ad9ac
:zap: enable call
vikiival Jan 24, 2024
b1683e9
:pray: test run before submit
vikiival Jan 24, 2024
40012b6
:test_tube: human test
vikiival Jan 24, 2024
e7ab4a1
Add unHex function to handle hex values in asset names and symbols
vikiival Jan 29, 2024
6bd9c29
:wrench: use RPC to finish
vikiival Jan 29, 2024
22d38bd
:mute: disable chache update
vikiival Jan 29, 2024
c241ebe
:wrech: use allowList
vikiival Jan 29, 2024
50b3110
:docs: architecture of the squid
vikiival Jan 29, 2024
959ba52
Merge pull request #212 from kodadot/docs/better-readme
vikiival Jan 29, 2024
3aaf029
:bug: :memo: missing migrate
vikiival Feb 8, 2024
1cda35b
:bug: :memo: incorrect order of running readme
vikiival Feb 13, 2024
5fbdf1f
:memo: :technologist: inline documenting schema
vikiival Feb 16, 2024
88220bb
:memo: :technologist: inline documenting entrypoints
vikiival Feb 16, 2024
fdf4096
:memo: :technologist: inline documenting helpers
vikiival Feb 16, 2024
fe57d4b
:memo: :technologist: inline documenting all helpers
vikiival Feb 17, 2024
d41de34
:memo: :technologist: inline documenting all nfts pallet
vikiival Feb 17, 2024
6bf9fbf
:memo: :technologist: inline documenting all assets
vikiival Feb 17, 2024
a9e9a01
:memo: :technologist: inline documenting all uniques
vikiival Feb 17, 2024
1c80018
:memo: :technologist: inline documenting processable
vikiival Feb 17, 2024
3b628fc
:memo: :test_tub: how to test
vikiival Feb 17, 2024
5cad6f3
:memo: :bug: minor typos
vikiival Feb 17, 2024
f76abd7
Merge pull request #222 from kodadot/chore/inline-docs
vikiival Feb 17, 2024
78f61d3
:memo: :bug: missing annotation in uniques/create
vikiival Feb 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ DB_PORT=23798
PROCESSOR_PROMETHEUS_PORT=3000
GQL_PORT=4350
SQD_DEBUG=squid:log
ALL_SQD_DEBUG=*
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": ["eslint-config-unjs"],
"ignorePatterns": ["tests/**", "src/model", "lib/**"],
"ignorePatterns": ["tests/**", "src/model", "src/server-extension", "src/types", "lib/**"],
"rules": {
"@typescript-eslint/no-inferrable-types": 0,
"@typescript-eslint/no-unused-vars": 0,
Expand All @@ -23,6 +23,7 @@
"unicorn/prefer-code-point": 0,
"unicorn/prefer-math-trunc": 0,
"unicorn/text-encoding-identifier-case": 0,
"no-useless-constructor": 0
"no-useless-constructor": 0,
"semi": ["error", "never"]
}
}
122 changes: 79 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,90 @@

![](https://media.tenor.com/eK1dyB3TOLsAAAAC/anime-stick.gif)

KodaDot's [Squid](https://docs.subsquid.io) based data processor for [KodaDot](https://kodadot.xyz) NFT Marketplace.
[Squid](https://docs.subsquid.io) based data used to index, process, and query on top of AssetHub for [KodaDot](https://kodadot.xyz) NFT Marketplace.

## Hosted Squids

* Kusama AssetHub Processor (Statemine -> KSM): https://squid.subsquid.io/stick/graphql
* Polkadot AssetHub Processor (Statemint -> DOT): https://squid.subsquid.io/speck/graphql
* Rococo Testnet Processor: 🚧 WIP 🚧

## Project structure

* `src/generated` - model/server definitions created by `codegen`. Do not alter the contents of this directory manually.
* `src/server-extension` - module with custom `type-graphql` based resolvers.
* `src/types` - data type definitions for chain events and extrinsics created by `typegen`.
* `src/mappings` - mapping module.
* `lib` - compiled js files. The structure of this directory must reflect `src`.
* `.env` - environment variables defined here or supplied by a shell.

## Prerequisites

* node 18.x
* docker
* npm -- note that `yarn` package manager is not supported
* Node 18.x
* Docker
* npm
* [just](https://github.com/casey/just)

## Quickly running the sample

Example commands below use [sqd](https://docs.subsquid.io/squid-cli/).
Please [install](https://docs.subsquid.io/squid-cli/installation/) it before proceeding.

```bash
# 1. Update Squid SDK and install dependencies
npm run update
# 1. Install dependencies
npm ci

# 2. Start target Postgres database and detach
sqd up
# 2. Build project
just build

# 3. Build the project and start the processor
sqd process
# 3. Start target Postgres database container
just upd

# 4. 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 a separate terminal
# and run
sqd serve
```
# 4. Update database with data objects
just migrate

## Project structure
# 5. Start the processor
just process

* `src/generated` - model/server definitions created by `codegen`. Do not alter the contents of this directory manually.
* `src/server-extension` - module with custom `type-graphql` based resolvers
* `src/types` - data type definitions for chain events and extrinsics created by `typegen`.
* `src/mappings` - mapping module.
* `lib` - compiled js files. The structure of this directory must reflect `src`.
* `.env` - hydra tools are heavily driven by environment variables defined here or supplied by a shell.
# 6. Open a separate terminal and launch the graphql server to query the processed data
just serve

# 7. Visit localhost:4350/graphql to see the result
```

## 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/schema-file).
A full description of `schema.graphql` dialect is available [here](https://docs.subsquid.io/schema-file).

### 2. Generate TypeORM classes

Mapping developers use [TypeORM](https://typeorm.io) 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.
Mapping developers use [TypeORM](https://typeorm.io) entities to interact with the target database during data processing. The squid framework generates All necessary entity classes from `schema.graphql`. This is done by running `just 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.
`squid-typeorm-migration` tool provides several commands to drive the process.
It is all [TypeORM](https://typeorm.io/#/migrations) under the hood.

```bash
# 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
# Connect to the database, analyze its state, and generate a migration to match the target schema.
# Launch Docker instance of the database
just upd

# Create template file for custom database changes
npx squid-typeorm-migration create
# The target schema is derived from entity classes generated earlier.
# Remember to compile your entity classes beforehand!
just update-db

# Apply database migrations from `db/migrations`
npx squid-typeorm-migration apply
just migrate

# Revert the last performed migration
npx squid-typeorm-migration revert
just revert-db
```

Available `sqd` shortcuts:

```bash
# Build the project, remove any old migrations, then run `npx squid-typeorm-migration generate`
sqd migration:generate
Expand All @@ -89,7 +94,38 @@ sqd migration:generate
sqd migration:apply
```

### Dev hacks
### Testing

> Unit test early, unit test often

> [!NOTE]
> Any code imported from @kodadot [packages has unit test written in the separated repository](https://github.com/kodadot/packages)

This indexer contains unit tests for utility/parsing functions we wrote.

Tests are located in the `tests/` directory.
To run the tests, use:

```bash
npm run test
```

> [!WARNING]
> Currently, it is impossible to unit test the whole indexer workflow as a dry run. If you encounter some problem, please head over to the telegram group **HydraDevs**

## Architecture

The architecture of this project is following:

* `src/processable.ts` - definition of Events and Extrinsic to be processed by Squid
* `src/processor.ts` - processor definition
* `src/mappings/index` - the main function that is called by the processor to process events and extrinsic
* `src/mappings/<pallet>` - mapping functions for each event and extrinsic
* `src/mappings/<pallet>/types.ts` - types for each event and extrinsic
* `src/mappings/<pallet>/getters/<chain>.ts` - transformation functions for each event and extrinsic
* `src/mappings/utils` - utility functions used by mappings

## Misc

1. fast generate event handlers

Expand Down
13 changes: 13 additions & 0 deletions db/migrations/1706015961189-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = class Data1706015961189 {
name = 'Data1706015961189'

async up(db) {
await db.query(`ALTER TABLE "collection_entity" ADD "type" character varying(8)`)
await db.query(`ALTER TABLE "collection_entity" ADD "settings" jsonb`)
}

async down(db) {
await db.query(`ALTER TABLE "collection_entity" DROP COLUMN "type"`)
await db.query(`ALTER TABLE "collection_entity" DROP COLUMN "settings"`)
}
}
11 changes: 11 additions & 0 deletions db/migrations/1706035705537-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = class Data1706035705537 {
name = 'Data1706035705537'

async up(db) {
await db.query(`CREATE TABLE "cache_status" ("id" character varying NOT NULL, "last_block_timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, CONSTRAINT "PK_1001e39eb0aa38d043d96f7f4fa" PRIMARY KEY ("id"))`)
}

async down(db) {
await db.query(`DROP TABLE "cache_status"`)
}
}
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
ports:
- "${DB_PORT}:5432"
# command: ["postgres", "-c", "log_statement=all"]
# volumes:
# volumes:
# - ./assets/${CHAIN}/init.sql:/docker-entrypoint-initdb.d/init.sql
# - ./data/db:/var/lib/postgresql/data

19 changes: 16 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default := 'squid'
types := 'typegen'

process: build
node -r dotenv/config lib/processor.js
node --require=dotenv/config lib/processor.js

serve:
@npx squid-graphql-server
Expand Down Expand Up @@ -42,9 +42,16 @@ bug: down upd

reset: migrate

slow:
sleep 1
just reset

quickstart: migrate process

quick: build reset process
quick: wipe bug slow process

wipe:
clear

prod TAG:
gh pr create --base release-{{TAG}}
Expand All @@ -55,6 +62,9 @@ migrate:
update-db:
npx squid-typeorm-migration generate

revert-db:
npx squid-typeorm-migration revert

db: update-db migrate

test:
Expand All @@ -79,7 +89,10 @@ update-deps:
npx npm-check-updates -ux

exec:
docker exec -it stick-db-1 psql -U postgres -d squid
docker exec -it subsquid_db psql -U postgres -d squid

dump NAME=default:
docker exec -t subsquid_db pg_dump -U postgres -d squid > {{NAME}}.sql

check: codegen build

Expand Down
Loading