From 632c776950d3b527fabd1c7f0766d1d54849050d Mon Sep 17 00:00:00 2001 From: nigiri <168690269+0xnigir1@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:32:05 -0300 Subject: [PATCH 1/3] feat: base processors package --- packages/processors/README.md | 35 ++++++++++++++++++ packages/processors/package.json | 37 +++++++++++++++++++ .../processors/src/allo/allo.processor.ts | 10 +++++ packages/processors/src/allo/index.ts | 1 + packages/processors/src/external.ts | 3 ++ packages/processors/src/index.ts | 1 + packages/processors/src/interfaces/index.ts | 1 + .../src/interfaces/processor.interface.ts | 10 +++++ packages/processors/src/internal.ts | 4 ++ packages/processors/src/strategy/index.ts | 1 + .../src/strategy/strategy.processor.ts | 10 +++++ packages/processors/test/index.spec.ts | 5 +++ packages/processors/tsconfig.build.json | 11 ++++++ packages/processors/tsconfig.json | 4 ++ packages/processors/vitest.config.ts | 21 +++++++++++ packages/shared/src/external.ts | 3 +- pnpm-lock.yaml | 18 +++++++++ 17 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 packages/processors/README.md create mode 100644 packages/processors/package.json create mode 100644 packages/processors/src/allo/allo.processor.ts create mode 100644 packages/processors/src/allo/index.ts create mode 100644 packages/processors/src/external.ts create mode 100644 packages/processors/src/index.ts create mode 100644 packages/processors/src/interfaces/index.ts create mode 100644 packages/processors/src/interfaces/processor.interface.ts create mode 100644 packages/processors/src/internal.ts create mode 100644 packages/processors/src/strategy/index.ts create mode 100644 packages/processors/src/strategy/strategy.processor.ts create mode 100644 packages/processors/test/index.spec.ts create mode 100644 packages/processors/tsconfig.build.json create mode 100644 packages/processors/tsconfig.json create mode 100644 packages/processors/vitest.config.ts diff --git a/packages/processors/README.md b/packages/processors/README.md new file mode 100644 index 0000000..94b07b4 --- /dev/null +++ b/packages/processors/README.md @@ -0,0 +1,35 @@ +# grants-stack-indexer: processors package + +Description of your package goes here. + +## Setup + +1. Install dependencies running `pnpm install` + +## Available Scripts + +Available scripts that can be run using `pnpm`: + +| Script | Description | +| ------------- | ------------------------------------------------------- | +| `build` | Build library using tsc | +| `check-types` | Check types issues using tsc | +| `clean` | Remove `dist` folder | +| `lint` | Run ESLint to check for coding standards | +| `lint:fix` | Run linter and automatically fix code formatting issues | +| `format` | Check code formatting and style using Prettier | +| `format:fix` | Run formatter and automatically fix issues | +| `test` | Run tests using vitest | +| `test:cov` | Run tests with coverage report | + +## Usage + +Describe how to use your package here. + +## API + +Describe your package's API here. + +## References + +Add any relevant references here. diff --git a/packages/processors/package.json b/packages/processors/package.json new file mode 100644 index 0000000..5fec498 --- /dev/null +++ b/packages/processors/package.json @@ -0,0 +1,37 @@ +{ + "name": "@grants-stack-indexer/processors", + "version": "0.0.1", + "private": true, + "description": "", + "license": "MIT", + "author": "Wonderland", + "type": "module", + "main": "./dist/src/index.js", + "types": "./dist/src/index.d.ts", + "directories": { + "src": "src" + }, + "files": [ + "dist/*", + "package.json", + "!**/*.tsbuildinfo" + ], + "scripts": { + "build": "tsc -p tsconfig.build.json", + "check-types": "tsc --noEmit -p ./tsconfig.json", + "clean": "rm -rf dist/", + "format": "prettier --check \"{src,test}/**/*.{js,ts,json}\"", + "format:fix": "prettier --write \"{src,test}/**/*.{js,ts,json}\"", + "lint": "eslint \"{src,test}/**/*.{js,ts,json}\"", + "lint:fix": "pnpm lint --fix", + "test": "vitest run --config vitest.config.ts --passWithNoTests", + "test:cov": "vitest run --config vitest.config.ts --coverage" + }, + "dependencies": { + "@grants-stack-indexer/metadata": "workspace:*", + "@grants-stack-indexer/pricing": "workspace:*", + "@grants-stack-indexer/repository": "workspace:*", + "@grants-stack-indexer/shared": "workspace:*", + "viem": "2.21.19" + } +} diff --git a/packages/processors/src/allo/allo.processor.ts b/packages/processors/src/allo/allo.processor.ts new file mode 100644 index 0000000..01f8aea --- /dev/null +++ b/packages/processors/src/allo/allo.processor.ts @@ -0,0 +1,10 @@ +import { AlloEvent, ProtocolEvent } from "@grants-stack-indexer/shared"; + +import type { IProcessor } from "../internal.js"; + +export class AlloProcessor implements IProcessor<"Allo", AlloEvent> { + //TODO: Implement + process(_event: ProtocolEvent<"Allo", AlloEvent>): Promise { + throw new Error("Method not implemented."); + } +} diff --git a/packages/processors/src/allo/index.ts b/packages/processors/src/allo/index.ts new file mode 100644 index 0000000..a440273 --- /dev/null +++ b/packages/processors/src/allo/index.ts @@ -0,0 +1 @@ +export * from "./allo.processor.js"; diff --git a/packages/processors/src/external.ts b/packages/processors/src/external.ts new file mode 100644 index 0000000..a898320 --- /dev/null +++ b/packages/processors/src/external.ts @@ -0,0 +1,3 @@ +// Add your external exports here +export { StrategyProcessor, AlloProcessor } from "./internal.js"; +export type { IProcessor } from "./internal.js"; diff --git a/packages/processors/src/index.ts b/packages/processors/src/index.ts new file mode 100644 index 0000000..a5a2748 --- /dev/null +++ b/packages/processors/src/index.ts @@ -0,0 +1 @@ +export * from "./external.js"; diff --git a/packages/processors/src/interfaces/index.ts b/packages/processors/src/interfaces/index.ts new file mode 100644 index 0000000..d9d3380 --- /dev/null +++ b/packages/processors/src/interfaces/index.ts @@ -0,0 +1 @@ +export * from "./processor.interface.js"; diff --git a/packages/processors/src/interfaces/processor.interface.ts b/packages/processors/src/interfaces/processor.interface.ts new file mode 100644 index 0000000..2c6c5d1 --- /dev/null +++ b/packages/processors/src/interfaces/processor.interface.ts @@ -0,0 +1,10 @@ +import { ContractName, ContractToEventName, ProtocolEvent } from "@grants-stack-indexer/shared"; + +export interface IProcessor> { + /** + * Processes an event from the Allo protocol. + * @param event - The event to process. + * @returns A promise that resolves when the event is processed. + */ + process(event: ProtocolEvent): Promise; +} diff --git a/packages/processors/src/internal.ts b/packages/processors/src/internal.ts new file mode 100644 index 0000000..10f9b05 --- /dev/null +++ b/packages/processors/src/internal.ts @@ -0,0 +1,4 @@ +// Add your internal exports here +export * from "./interfaces/index.js"; +export * from "./allo/index.js"; +export * from "./strategy/index.js"; diff --git a/packages/processors/src/strategy/index.ts b/packages/processors/src/strategy/index.ts new file mode 100644 index 0000000..3bc73f5 --- /dev/null +++ b/packages/processors/src/strategy/index.ts @@ -0,0 +1 @@ +export * from "./strategy.processor.js"; diff --git a/packages/processors/src/strategy/strategy.processor.ts b/packages/processors/src/strategy/strategy.processor.ts new file mode 100644 index 0000000..e24a9b4 --- /dev/null +++ b/packages/processors/src/strategy/strategy.processor.ts @@ -0,0 +1,10 @@ +import { ProtocolEvent, StrategyEvent } from "@grants-stack-indexer/shared"; + +import type { IProcessor } from "../internal.js"; + +export class StrategyProcessor implements IProcessor<"Strategy", StrategyEvent> { + process(_event: ProtocolEvent<"Strategy", StrategyEvent>): Promise { + //TODO: Implement + throw new Error("Method not implemented."); + } +} diff --git a/packages/processors/test/index.spec.ts b/packages/processors/test/index.spec.ts new file mode 100644 index 0000000..e383c0a --- /dev/null +++ b/packages/processors/test/index.spec.ts @@ -0,0 +1,5 @@ +import { describe, it } from "vitest"; + +describe("dummy", () => { + it.skip("dummy", () => {}); +}); diff --git a/packages/processors/tsconfig.build.json b/packages/processors/tsconfig.build.json new file mode 100644 index 0000000..32768e3 --- /dev/null +++ b/packages/processors/tsconfig.build.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.build.json", + "compilerOptions": { + "composite": true, + "declarationMap": true, + "declaration": true, + "outDir": "dist" + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist", "test"] +} diff --git a/packages/processors/tsconfig.json b/packages/processors/tsconfig.json new file mode 100644 index 0000000..66bb87a --- /dev/null +++ b/packages/processors/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*"] +} diff --git a/packages/processors/vitest.config.ts b/packages/processors/vitest.config.ts new file mode 100644 index 0000000..36aeafb --- /dev/null +++ b/packages/processors/vitest.config.ts @@ -0,0 +1,21 @@ +import path from "path"; +import { configDefaults, defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + globals: true, + environment: "node", + include: ["test/**/*.spec.ts"], + exclude: ["node_modules", "dist"], + coverage: { + provider: "v8", + reporter: ["text", "json", "html"], + exclude: ["node_modules", "dist", "src/index.ts", ...configDefaults.exclude], + }, + }, + resolve: { + alias: { + "@": path.resolve(__dirname, "src"), + }, + }, +}); diff --git a/packages/shared/src/external.ts b/packages/shared/src/external.ts index 6663453..6547286 100644 --- a/packages/shared/src/external.ts +++ b/packages/shared/src/external.ts @@ -1,2 +1,3 @@ -export type { AnyProtocolEvent, Address, Branded, ChainId } from "./internal.js"; +export type * from "./types/index.js"; +export type { Address } from "./internal.js"; export { NATIVE_TOKEN_ADDRESS, isNativeToken } from "./constants/index.js"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ad23043..442ab68 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -146,6 +146,24 @@ importers: specifier: 2.0.0 version: 2.0.0(axios@1.7.7) + packages/processors: + dependencies: + "@grants-stack-indexer/metadata": + specifier: workspace:* + version: link:../metadata + "@grants-stack-indexer/pricing": + specifier: workspace:* + version: link:../pricing + "@grants-stack-indexer/repository": + specifier: workspace:* + version: link:../repository + "@grants-stack-indexer/shared": + specifier: workspace:* + version: link:../shared + viem: + specifier: 2.21.19 + version: 2.21.19(typescript@5.5.4)(zod@3.23.8) + packages/repository: dependencies: "@grants-stack-indexer/shared": From b9db5478accf1f4857ee3ec036e420de71768651 Mon Sep 17 00:00:00 2001 From: nigiri <168690269+0xnigir1@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:39:57 -0300 Subject: [PATCH 2/3] feat: add changeset type --- .../processors/src/allo/allo.processor.ts | 3 +- .../src/interfaces/processor.interface.ts | 5 +- .../src/strategy/strategy.processor.ts | 3 +- packages/repository/src/external.ts | 2 + packages/repository/src/index.ts | 4 +- .../repository/src/types/changeset.types.ts | 143 ++++++++++++++++++ packages/repository/src/types/index.ts | 1 + 7 files changed, 154 insertions(+), 7 deletions(-) create mode 100644 packages/repository/src/types/changeset.types.ts diff --git a/packages/processors/src/allo/allo.processor.ts b/packages/processors/src/allo/allo.processor.ts index 01f8aea..b59e1ef 100644 --- a/packages/processors/src/allo/allo.processor.ts +++ b/packages/processors/src/allo/allo.processor.ts @@ -1,10 +1,11 @@ +import { Changeset } from "@grants-stack-indexer/repository"; import { AlloEvent, ProtocolEvent } from "@grants-stack-indexer/shared"; import type { IProcessor } from "../internal.js"; export class AlloProcessor implements IProcessor<"Allo", AlloEvent> { //TODO: Implement - process(_event: ProtocolEvent<"Allo", AlloEvent>): Promise { + process(_event: ProtocolEvent<"Allo", AlloEvent>): Promise { throw new Error("Method not implemented."); } } diff --git a/packages/processors/src/interfaces/processor.interface.ts b/packages/processors/src/interfaces/processor.interface.ts index 2c6c5d1..f8aeb02 100644 --- a/packages/processors/src/interfaces/processor.interface.ts +++ b/packages/processors/src/interfaces/processor.interface.ts @@ -1,10 +1,11 @@ +import type { Changeset } from "@grants-stack-indexer/repository"; import { ContractName, ContractToEventName, ProtocolEvent } from "@grants-stack-indexer/shared"; export interface IProcessor> { /** * Processes an event from the Allo protocol. * @param event - The event to process. - * @returns A promise that resolves when the event is processed. + * @returns A promise that resolves to a changeset. */ - process(event: ProtocolEvent): Promise; + process(event: ProtocolEvent): Promise; } diff --git a/packages/processors/src/strategy/strategy.processor.ts b/packages/processors/src/strategy/strategy.processor.ts index e24a9b4..6f4d499 100644 --- a/packages/processors/src/strategy/strategy.processor.ts +++ b/packages/processors/src/strategy/strategy.processor.ts @@ -1,9 +1,10 @@ +import { Changeset } from "@grants-stack-indexer/repository"; import { ProtocolEvent, StrategyEvent } from "@grants-stack-indexer/shared"; import type { IProcessor } from "../internal.js"; export class StrategyProcessor implements IProcessor<"Strategy", StrategyEvent> { - process(_event: ProtocolEvent<"Strategy", StrategyEvent>): Promise { + process(_event: ProtocolEvent<"Strategy", StrategyEvent>): Promise { //TODO: Implement throw new Error("Method not implemented."); } diff --git a/packages/repository/src/external.ts b/packages/repository/src/external.ts index 95d48eb..a37b59b 100644 --- a/packages/repository/src/external.ts +++ b/packages/repository/src/external.ts @@ -25,6 +25,8 @@ export type { PendingRoundRole, } from "./types/round.types.js"; +export type { Changeset } from "./types/index.js"; + export { KyselyRoundRepository, KyselyProjectRepository } from "./repositories/kysely/index.js"; export { createKyselyPostgresDb as createKyselyDatabase } from "./internal.js"; diff --git a/packages/repository/src/index.ts b/packages/repository/src/index.ts index 7cdcc00..a5a2748 100644 --- a/packages/repository/src/index.ts +++ b/packages/repository/src/index.ts @@ -1,3 +1 @@ -export * from "./db/connection.js"; -export * from "./repositories/kysely/index.js"; -export * from "./interfaces/index.js"; +export * from "./external.js"; diff --git a/packages/repository/src/types/changeset.types.ts b/packages/repository/src/types/changeset.types.ts new file mode 100644 index 0000000..dee4d38 --- /dev/null +++ b/packages/repository/src/types/changeset.types.ts @@ -0,0 +1,143 @@ +import { ChainId } from "@grants-stack-indexer/shared"; +import { Address } from "@grants-stack-indexer/shared/dist/src/internal.js"; + +import { + NewPendingProjectRole, + NewProject, + NewProjectRole, + PartialProject, + ProjectRole, +} from "./project.types.js"; +import { + NewPendingRoundRole, + NewRound, + NewRoundRole, + PartialRound, + RoundRole, +} from "./round.types.js"; + +export type Changeset = + | { + type: "InsertProject"; + args: { + project: NewProject; + }; + } + | { + type: "UpdateProject"; + args: { + chainId: ChainId; + projectId: string; + project: PartialProject; + }; + } + | { + type: "InsertPendingProjectRole"; + args: { + pendingProjectRole: NewPendingProjectRole; + }; + } + | { + type: "DeletePendingProjectRoles"; + args: { + ids: number[]; + }; + } + | { + type: "InsertProjectRole"; + args: { + projectRole: NewProjectRole; + }; + } + | { + type: "DeleteAllProjectRolesByRole"; + args: { + projectRole: Pick; + }; + } + | { + type: "DeleteAllProjectRolesByRoleAndAddress"; + args: { + projectRole: Pick; + }; + } + | { + type: "InsertRound"; + args: { + round: NewRound; + }; + } + | { + type: "UpdateRound"; + args: { + chainId: ChainId; + roundId: string; + round: PartialRound; + }; + } + | { + type: "UpdateRoundByStrategyAddress"; + args: { + chainId: ChainId; + strategyAddress: Address; + round: PartialRound; + }; + } + | { + type: "IncrementRoundFundedAmount"; + args: { + chainId: ChainId; + roundId: string; + fundedAmount: bigint; + fundedAmountInUsd: number; + }; + } + | { + type: "IncrementRoundDonationStats"; + args: { + chainId: ChainId; + roundId: Address; + amountInUsd: number; + }; + } + | { + type: "IncrementRoundTotalDistributed"; + args: { + chainId: ChainId; + roundId: string; + amount: bigint; + }; + } + | { + type: "IncrementApplicationDonationStats"; + args: { + chainId: ChainId; + roundId: Address; + applicationId: string; + amountInUsd: number; + }; + } + | { + type: "InsertPendingRoundRole"; + args: { + pendingRoundRole: NewPendingRoundRole; + }; + } + | { + type: "DeletePendingRoundRoles"; + args: { + ids: number[]; + }; + } + | { + type: "InsertRoundRole"; + args: { + roundRole: NewRoundRole; + }; + } + | { + type: "DeleteAllRoundRolesByRoleAndAddress"; + args: { + roundRole: Pick; + }; + }; diff --git a/packages/repository/src/types/index.ts b/packages/repository/src/types/index.ts index 977b72a..b183e3c 100644 --- a/packages/repository/src/types/index.ts +++ b/packages/repository/src/types/index.ts @@ -1,2 +1,3 @@ export * from "./project.types.js"; export * from "./round.types.js"; +export * from "./changeset.types.js"; From 847e4aa38680c61af0361e70943625f6bd211258 Mon Sep 17 00:00:00 2001 From: nigiri <168690269+0xnigir1@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:12:34 -0300 Subject: [PATCH 3/3] fix: import path --- packages/repository/src/types/changeset.types.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/repository/src/types/changeset.types.ts b/packages/repository/src/types/changeset.types.ts index dee4d38..ee012e7 100644 --- a/packages/repository/src/types/changeset.types.ts +++ b/packages/repository/src/types/changeset.types.ts @@ -1,5 +1,4 @@ -import { ChainId } from "@grants-stack-indexer/shared"; -import { Address } from "@grants-stack-indexer/shared/dist/src/internal.js"; +import type { Address, ChainId } from "@grants-stack-indexer/shared"; import { NewPendingProjectRole,