{"id":19563275,"url":"https://github.com/kodadot/snek","last_synced_at":"2025-04-27T00:32:08.673Z","repository":{"id":37027959,"uuid":"473576122","full_name":"kodadot/snek","owner":"kodadot","description":"Implementation of Basilisk NFT pallet","archived":true,"fork":false,"pushed_at":"2023-09-27T19:51:45.000Z","size":932,"stargazers_count":3,"open_issues_count":36,"forks_count":11,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-14T13:43:00.390Z","etag":null,"topics":["basilisk","graphql","subsquid"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kodadot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-03-24T11:26:12.000Z","updated_at":"2024-07-01T10:46:40.000Z","dependencies_parsed_at":"2023-02-13T00:00:42.539Z","dependency_job_id":null,"html_url":"https://github.com/kodadot/snek","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":"subsquid-labs/squid-substrate-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodadot%2Fsnek","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodadot%2Fsnek/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodadot%2Fsnek/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodadot%2Fsnek/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kodadot","download_url":"https://codeload.github.com/kodadot/snek/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251072279,"owners_count":21532004,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["basilisk","graphql","subsquid"],"created_at":"2024-11-11T05:17:10.721Z","updated_at":"2025-04-27T00:32:08.317Z","avatar_url":"https://github.com/kodadot.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Snek\n\n**Implementation of the best NFT marketplace with locked balances.**\n\n![image](https://user-images.githubusercontent.com/5887929/217077078-b0469706-1348-48ae-a4dc-9ee7598d8a3c.png)\n\n\n## Prerequisites\n\n* node 16.x\n* docker\n\n## Quickly running the sample\n\nExample commands below use [make(1)](https://www.gnu.org/software/make/).\nPlease, have a look at commands in [Makefile](Makefile) if your platform doesn't support it.\nOn Windows we recommend to use [WSL](https://docs.microsoft.com/en-us/windows/wsl/).\n\n```bash\n# 1. Install dependencies\nnpm ci\n\n# 2. Compile typescript files\nmake build\n\n# 3. Start target Postgres database and detach\nmake up\n\n# 4. Apply database migrations from db/migrations\nmake migrate\n\n# 5. Start the processor\nmake process\n\n# 6. The command above will block the terminal\n#    being busy with fetching the chain data, \n#    transforming and storing it in the target database.\n#\n#    To start the graphql server open the separate terminal\n#    and run\nmake serve\n\n# 7. Now you can see the results by visiting the localhost:4350/graphql\n```\n\n## Dev flow\n\n### 1. Define database schema\n\nStart development by defining the schema of the target database via `schema.graphql`.\nSchema definition consists of regular graphql type declarations annotated with custom directives.\nFull description of `schema.graphql` dialect is available [here](https://docs.subsquid.io/docs/develop-a-squid/define-a-squid-schema).\n\n### 2. Generate TypeORM classes\n\nMapping developers use [TypeORM](https://typeorm.io) entities\nto interact with the target database during data processing. All necessary entity classes are\ngenerated by the squid framework from `schema.graphql`. This is done by running `npx squid-typeorm-codegen`\ncommand.\n\n### 3. Generate database migration\n\nAll database changes are applied through migration files located at `db/migrations`.\n`squid-typeorm-migration(1)` tool provides several commands to drive the process.\nIt is all [TypeORM](https://typeorm.io/#/migrations) under the hood.\n\n```bash\n# Connect to database, analyze its state and generate migration to match the target schema.\n# The target schema is derived from entity classes generated earlier.\n# Don't forget to compile your entity classes beforehand!\nnpx squid-typeorm-migration generate\n\n# Create template file for custom database changes\nnpx squid-typeorm-migration create\n\n# Apply database migrations from `db/migrations`\nnpx squid-typeorm-migration apply\n\n# Revert the last performed migration\nnpx squid-typeorm-migration revert         \n```\n\n### 4. Generate TypeScript definitions for substrate events, calls and storage \n\nThis is an optional part, but it is very advisable. \n\nEvent, call and runtime storage data come to mapping handlers as raw untyped json. \nWhile it is possible to work with raw untyped json data, \nit's extremely error-prone and the json structure may change over time due to runtime upgrades.\n\nSquid framework provides tools for generating type-safe wrappers around events, calls and runtime storage items for\neach historical change in the spec version.\n\nThe end result looks like this:\n\n```typescript\n/**\n * Normalized `balances.Transfer` event data\n */\ninterface TransferEvent {\n    from: Uint8Array\n    to: Uint8Array\n    amount: bigint\n}\n\nfunction getTransferEvent(ctx: EventHandlerContext): TransferEvent {\n    // instanciate type-safe facade around event data\n    let event = new BalancesTransferEvent(ctx)\n    if (event.isV1020) {\n        let [from, to, amount, fee] = event.asV1020\n        return {from, to, amount}\n    } else if (event.isV1050) {\n        let [from, to, amount] = event.asV1050\n        return {from, to, amount}\n    } else {\n        // This cast will assert, \n        // that the type of a given event matches\n        // the type of generated facade.\n        return event.asLatest\n    }\n}\n```\n\nGeneration of type-safe wrappers for events and calls is currently a two-step process.\n\nFirst, you need to explore the chain to find blocks which introduce new spec version and\nfetch corresponding metadata. \n\n```bash\nnpx squid-substrate-metadata-explorer \\\n  --chain wss://kusama-rpc.polkadot.io \\\n  --archive https://kusama.indexer.gc.subsquid.io/v4/graphql \\\n  --out kusamaVersions.json\n```\n\nIn the above command `--archive` parameter is optional, but it speeds up the process\nsignificantly. From scratch exploration of kusama network without archive takes 20-30 minutes.\n\nYou can pass the result of previous exploration to `--out` parameter. In that case exploration will\nstart from the last known block and thus will take much less time.\n\nAfter chain exploration is complete you can use `squid-substrate-typegen(1)` to generate \nrequired wrappers.\n\n```bash\nnpx squid-substrate-typegen typegen.json\n```\n\nWhere `typegen.json` config file has the following structure:\n\n```json5\n{\n  \"outDir\": \"src/types\",\n  \"chainVersions\": \"kusamaVersions.json\", // the result of chain exploration\n  \"typesBundle\": \"kusama\", // see types bundle section below\n  \"events\": [ // list of events to generate\n    \"balances.Transfer\"\n  ],\n  \"calls\": [ // list of calls to generate\n    \"timestamp.set\"\n  ]\n}\n```\n\n## Project conventions\n\nSquid tools assume a certain project layout.\n\n* All compiled js files must reside in `lib` and all TypeScript sources in `src`. \nThe layout of `lib` must reflect `src`.\n* All TypeORM classes must be exported by `src/model/index.ts` (`lib/model` module).\n* Database schema must be defined in `schema.graphql`.\n* Database migrations must reside in `db/migrations` and must be plain js files.\n* `sqd(1)` and `squid-*(1)` executables consult `.env` file for a number of environment variables.\n\n## Types bundle\n\nSubstrate chains which have blocks with metadata versions below 14 don't provide enough \ninformation to decode their data. For those chains external \n[type definitions](https://polkadot.js.org/docs/api/start/types.extend) are required.\n\nType definitions (`typesBundle`) can be given to squid tools in two forms:\n\n1. as a name of a known chain (currently only `kusama`)\n2. as a json file of a structure described below.\n\n```json5\n{\n  \"types\": {\n    \"AccountId\": \"[u8; 32]\"\n  },\n  \"typesAlias\": {\n    \"assets\": {\n      \"Balance\": \"u64\"\n    }\n  },\n  \"versions\": [\n    {\n      \"minmax\": [0, 1000], // block range with inclusive boundaries\n      \"types\": {\n        \"AccountId\": \"[u8; 16]\"\n      },\n      \"typesAlias\": {\n        \"assets\": {\n          \"Balance\": \"u32\"\n        }\n      }\n    }\n  ]\n}\n```\n\n* `.types` - scale type definitions similar to [polkadot.js types](https://polkadot.js.org/docs/api/start/types.extend#extension)\n* `.typesAlias` - similar to [polkadot.js type aliases](https://polkadot.js.org/docs/api/start/types.extend#type-clashes)\n* `.versions` - per-block range overrides/patches for above fields.\n\nAll fields in types bundle are optional and applied on top of a fixed set of well known\nframe types.\n\n## Differences from polkadot.js\n\nPolkadot.js provides lots of [specialized classes](https://polkadot.js.org/docs/api/start/types.basics) for various types of data. \nEven primitives like `u32` are exposed through special classes.\nIn contrast, squid framework works only with plain js primitives and objects.\nThis allows to decrease coupling and also simply dictated by the fact, that\nthere is not enough information in substrate metadata to distinguish between \ninteresting cases.\n\nAccount addresses is one example where such difference shows up.\nFrom substrate metadata (and squid framework) point of view account address is simply a fixed length\nsequence of bytes. On other hand, polkadot.js creates special wrapper for account addresses which \naware not only of address value, but also of its \n[ss58](https://docs.substrate.io/v3/advanced/ss58/) formatting rules.\nMapping developers should handle such cases themselves.\n\n## Graphql server extensions\n\nIt is possible to extend `squid-graphql-server(1)` with custom\n[type-graphql](https://typegraphql.com) resolvers and to add request validation.\nMore details will be added later.\n\n## Archival nodes\n\nBecause subsquid requires an archival indexer to be fast, there are currently 3 options how to do it:\n\n1. Leave it as it is\n\nthere is already indexer for base basilisk\n\n2. using archival node for Koda BSX Sandbox :snake:\n\n```.env\nARCHIVE_URL=https://basilisk-test.indexer.gc.subsquid.io/v4/graphql\n```\n\n3. running your own\n\n```bash\ngit clone git@github.com:subsquid/squid-archive-setup.git;\ncd squid-archive-setup/basilisk\n```\n\nin `docker-compose.yml` set url for the chain\n\n```\n-      - WS_PROVIDER_ENDPOINT_URI=wss://basilisk.api.onfinality.io/public-ws\n+      - WS_PROVIDER_ENDPOINT_URI=wss://basilisk-kodadot.hydration.cloud\n```\n\nthen just\n\n```bash\ndocker compose up\n```\n\nand set \n\n```.env\nARCHIVE_URL=http://localhost:4010/v1/graphql\n```\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkodadot%2Fsnek","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkodadot%2Fsnek","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkodadot%2Fsnek/lists"}