-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from Giveth/develop
Support organisation start block
- Loading branch information
Showing
21 changed files
with
221 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,20 @@ | ||
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/subsquid/squid-evm-template) | ||
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Giveth/DeVouch-BE) | ||
|
||
# Minimal EVM squid | ||
# Introduction | ||
|
||
This is a starter template of a squid indexer for EVM networks (Ethereum, Polygon, BSC, etc.). See [Squid SDK docs](https://docs.subsquid.io/) for a complete reference. | ||
Devouch is a decentralized application that allows users to attest to projects credibility by their vouches or flags. The backend is built on Subsquid and uses a Postgres database. | ||
|
||
To extract EVM logs and transactions by a topic or a contract address, use [`.addLog()`](https://docs.subsquid.io/evm-indexing/configuration/evm-logs/), [`.addTransaction()`](https://docs.subsquid.io/evm-indexing/configuration/transactions/), [`.addTrace()`](https://docs.subsquid.io/evm-indexing/configuration/traces/) or [`.addStateDiff()`](https://docs.subsquid.io/evm-indexing/configuration/state-diffs/) methods of the `EvmBatchProcessor` instance defined in `src/processor.ts`. Select data fields with [`.setFields()`](https://docs.subsquid.io/evm-indexing/configuration/data-selection/). | ||
# Getting Started | ||
|
||
The requested data is transformed in batches by a single handler provided to the `processor.run()` method. | ||
|
||
For a full list of supported networks and config options, | ||
check the [`EvmBatchProcessor` overview](https://docs.subsquid.io/evm-indexing/evm-processor/) and the [setup section](https://docs.subsquid.io/evm-indexing/configuration/). | ||
|
||
For a step-by-step migration guide from TheGraph, see [the dedicated docs page](https://docs.subsquid.io/migrate/migrate-subgraph/). | ||
|
||
Dependencies: Node.js v16 or newer, Git, Docker. | ||
|
||
## 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 the squid | ||
sqd build | ||
|
||
# 5. Start both the squid processor and the GraphQL server | ||
sqd run . | ||
``` | ||
A GraphiQL playground will be available at [localhost:4350/graphql](http://localhost:4350/graphql). | ||
|
||
You can also start squid services one by one: | ||
```bash | ||
sqd process | ||
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](https://docs.subsquid.io/store/postgres/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. | ||
## Add new organisation | ||
|
||
```bash | ||
## drop create the database | ||
sqd down | ||
sqd up | ||
# 0. Copy the org-config.template.json to org-config.json | ||
cp org-config.template.json org-config.json | ||
|
||
## replace any old schemas with a new one made from the entities | ||
sqd migration:generate | ||
# 1. Fill the config with your organisation data | ||
# 2. Run the script to add your organisation data to migrations | ||
npm run add-organisation | ||
``` | ||
See [docs on database migrations](https://docs.subsquid.io/store/postgres/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. | ||
Then create a PR to the main branch to be reviewed and merged. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = class Data1718184531403 { | ||
name = 'Data1718184531403' | ||
|
||
async up(db) { | ||
await db.query(`ALTER TABLE "organisation" ADD "start_block" integer`) | ||
} | ||
|
||
async down(db) { | ||
await db.query(`ALTER TABLE "organisation" DROP COLUMN "start_block"`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "Organization Configuration", | ||
"description": "Schema for the organization configuration file.", | ||
"type": "object", | ||
|
||
"properties": { | ||
"$schema": { | ||
"description": "The schema version.", | ||
"type": "string" | ||
}, | ||
"name": { | ||
"description": "The name of the organization.", | ||
"type": "string" | ||
}, | ||
"schemaId": { | ||
"description": "The UID for the attestation schema.", | ||
"type": "string", | ||
"pattern": "^0x[A-Fa-f0-9]{64}$" | ||
}, | ||
"authorizedAttestor": { | ||
"description": "The address of the authorized attestor.", | ||
"type": "string", | ||
"pattern": "^0x[A-Fa-f0-9]{40}$" | ||
}, | ||
|
||
"network": { | ||
"description": "The network for the organization.", | ||
"type": "string", | ||
"enum": ["eth-sepolia", "optimism-mainnet"] | ||
}, | ||
|
||
"color": { | ||
"description": "The organisaiton color in UI.", | ||
"type": "string", | ||
"pattern": "^#[A-Fa-f0-9]{6}$" | ||
}, | ||
"startBlock": { | ||
"description": "The block number at which the organization was created.", | ||
"type": "integer" | ||
} | ||
}, | ||
"required": ["name", "schemaId", "authorizedAttestor", "network"], | ||
"additionalProperties": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "./org-config.schema.json", | ||
|
||
"name": "Giveth Verifier", | ||
"schemaId": "0xf63f2a7159ee674aa6fce42196a8bb0605eafcf20c19e91a7eafba8d39fa0404", | ||
"authorizedAttestor": "0x93E79499b00a2fdAAC38e6005B0ad8E88b177346", | ||
|
||
"network": "optimism-mainnet", | ||
|
||
// Optional | ||
"color": "#FFFFFF", | ||
"startBlock": 999999999999, | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
interface SourceConfig { | ||
export interface SourceConfig { | ||
source: string; | ||
idField: string; | ||
titleField: string; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
import { TypeormDatabase } from "@subsquid/typeorm-store"; | ||
import { processor } from "./processor"; | ||
import { Processor } from "./processor"; | ||
import * as EASContract from "./abi/EAS"; | ||
import { processAttest } from "./mappings/attest"; | ||
import { processRevokeLog } from "./mappings/revoke"; | ||
import { importProjects } from "./features/import-projects/index"; | ||
|
||
processor.run(new TypeormDatabase({ supportHotBlocks: false }), async (ctx) => { | ||
for (let _block of ctx.blocks) { | ||
for (let _log of _block.logs) { | ||
switch (_log.topics[0]) { | ||
case EASContract.events.Attested.topic: | ||
await processAttest(ctx, _log); | ||
break; | ||
Processor.getInstance().then(async (processor) => { | ||
processor.run( | ||
new TypeormDatabase({ supportHotBlocks: false }), | ||
async (ctx) => { | ||
for (let _block of ctx.blocks) { | ||
for (let _log of _block.logs) { | ||
switch (_log.topics[0]) { | ||
case EASContract.events.Attested.topic: | ||
await processAttest(ctx, _log); | ||
break; | ||
|
||
case EASContract.events.Revoked.topic: | ||
await processRevokeLog(ctx, _log); | ||
case EASContract.events.Revoked.topic: | ||
await processRevokeLog(ctx, _log); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
); | ||
}); | ||
|
||
importProjects(); |
Oops, something went wrong.