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..b59e1ef --- /dev/null +++ b/packages/processors/src/allo/allo.processor.ts @@ -0,0 +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 { + 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..f8aeb02 --- /dev/null +++ b/packages/processors/src/interfaces/processor.interface.ts @@ -0,0 +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 to a changeset. + */ + 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..6f4d499 --- /dev/null +++ b/packages/processors/src/strategy/strategy.processor.ts @@ -0,0 +1,11 @@ +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 { + //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/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..ee012e7 --- /dev/null +++ b/packages/repository/src/types/changeset.types.ts @@ -0,0 +1,142 @@ +import type { Address, ChainId } from "@grants-stack-indexer/shared"; + +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"; 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":