Skip to content

Commit

Permalink
feat: base processors package (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnigir1 authored Oct 11, 2024
1 parent 1ed426f commit 8113bcb
Show file tree
Hide file tree
Showing 21 changed files with 323 additions and 4 deletions.
35 changes: 35 additions & 0 deletions packages/processors/README.md
Original file line number Diff line number Diff line change
@@ -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.
37 changes: 37 additions & 0 deletions packages/processors/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
11 changes: 11 additions & 0 deletions packages/processors/src/allo/allo.processor.ts
Original file line number Diff line number Diff line change
@@ -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<Changeset> {
throw new Error("Method not implemented.");
}
}
1 change: 1 addition & 0 deletions packages/processors/src/allo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./allo.processor.js";
3 changes: 3 additions & 0 deletions packages/processors/src/external.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Add your external exports here
export { StrategyProcessor, AlloProcessor } from "./internal.js";
export type { IProcessor } from "./internal.js";
1 change: 1 addition & 0 deletions packages/processors/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./external.js";
1 change: 1 addition & 0 deletions packages/processors/src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./processor.interface.js";
11 changes: 11 additions & 0 deletions packages/processors/src/interfaces/processor.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Changeset } from "@grants-stack-indexer/repository";
import { ContractName, ContractToEventName, ProtocolEvent } from "@grants-stack-indexer/shared";

export interface IProcessor<C extends ContractName, E extends ContractToEventName<C>> {
/**
* Processes an event from the Allo protocol.
* @param event - The event to process.
* @returns A promise that resolves to a changeset.
*/
process(event: ProtocolEvent<C, E>): Promise<Changeset>;
}
4 changes: 4 additions & 0 deletions packages/processors/src/internal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Add your internal exports here
export * from "./interfaces/index.js";
export * from "./allo/index.js";
export * from "./strategy/index.js";
1 change: 1 addition & 0 deletions packages/processors/src/strategy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./strategy.processor.js";
11 changes: 11 additions & 0 deletions packages/processors/src/strategy/strategy.processor.ts
Original file line number Diff line number Diff line change
@@ -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<Changeset> {
//TODO: Implement
throw new Error("Method not implemented.");
}
}
5 changes: 5 additions & 0 deletions packages/processors/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { describe, it } from "vitest";

describe("dummy", () => {
it.skip("dummy", () => {});
});
11 changes: 11 additions & 0 deletions packages/processors/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"composite": true,
"declarationMap": true,
"declaration": true,
"outDir": "dist"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "test"]
}
4 changes: 4 additions & 0 deletions packages/processors/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*"]
}
21 changes: 21 additions & 0 deletions packages/processors/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -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"),
},
},
});
2 changes: 2 additions & 0 deletions packages/repository/src/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
4 changes: 1 addition & 3 deletions packages/repository/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export * from "./db/connection.js";
export * from "./repositories/kysely/index.js";
export * from "./interfaces/index.js";
export * from "./external.js";
142 changes: 142 additions & 0 deletions packages/repository/src/types/changeset.types.ts
Original file line number Diff line number Diff line change
@@ -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<ProjectRole, "chainId" | "projectId" | "role">;
};
}
| {
type: "DeleteAllProjectRolesByRoleAndAddress";
args: {
projectRole: Pick<ProjectRole, "chainId" | "projectId" | "role" | "address">;
};
}
| {
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<RoundRole, "chainId" | "roundId" | "role" | "address">;
};
};
1 change: 1 addition & 0 deletions packages/repository/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./project.types.js";
export * from "./round.types.js";
export * from "./changeset.types.js";
3 changes: 2 additions & 1 deletion packages/shared/src/external.ts
Original file line number Diff line number Diff line change
@@ -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";
18 changes: 18 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8113bcb

Please sign in to comment.