Skip to content

feat: builder integration #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Feb 27, 2025
Merged
59 changes: 35 additions & 24 deletions apps/indexer/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ contracts:
- event: PoolFunded(uint256 indexed poolId, uint256 amount, uint256 fee)
- event: RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
- event: RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

- name: Registry
handler: src/handlers/Registry.ts
events:
Expand All @@ -29,6 +30,11 @@ contracts:
- event: RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
- event: RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

- name: AlloV1ToV2ProfileMigration
handler: src/handlers/AlloV1ToV2ProfileMigration.ts
events:
- event: ProfileMigrated(bytes32 indexed alloV1, uint256 alloV1ChainId, bytes32 indexed alloV2, uint256 nonce)

- name: Strategy
handler: src/handlers/Strategy.ts
events:
Expand Down Expand Up @@ -155,16 +161,19 @@ networks:
# address:
# - 0x1133eA7Af70876e64665ecD07C0A0476d09465a1

# - id: 42161 # arbitrum
# start_block: 146489425
# contracts:
# - name: Registry
# address:
# - 0x4AAcca72145e1dF2aeC137E1f3C5E3D75DB8b5f3
# - name: Strategy
# - name: Allo
# address:
# - 0x1133eA7Af70876e64665ecD07C0A0476d09465a1
- id: 42161 # arbitrum
start_block: 146489425
contracts:
- name: Registry
address:
- 0x4AAcca72145e1dF2aeC137E1f3C5E3D75DB8b5f3
- name: Strategy
- name: Allo
address:
- 0x1133eA7Af70876e64665ecD07C0A0476d09465a1
- name: AlloV1ToV2ProfileMigration
address:
- 0x1bFda15Ad5FC82E74Da81F0B8DcA486b3Ad14c71

# - id: 137 # polygon
# start_block: 49466006
Expand Down Expand Up @@ -274,21 +283,23 @@ networks:
- name: Allo
address:
- 0x1133eA7Af70876e64665ecD07C0A0476d09465a1
#######################
# TESTNET #
#######################

# - id: 11155111 # sepolia
# start_block: 4617051
# contracts:
# - name: Registry
# address:
# - 0x4AAcca72145e1dF2aeC137E1f3C5E3D75DB8b5f3
# - name: Strategy
# - name: Allo
# address:
# - 0x1133eA7Af70876e64665ecD07C0A0476d09465a1
#######################
# TESTNET #
#######################

- id: 11155111 # sepolia
start_block: 4617051
contracts:
- name: Registry
address:
- 0x4AAcca72145e1dF2aeC137E1f3C5E3D75DB8b5f3
- name: Strategy
- name: Allo
address:
- 0x1133eA7Af70876e64665ecD07C0A0476d09465a1
- name: AlloV1ToV2ProfileMigration
address:
- 0xCd5AbD09ee34BA604795F7f69413caf20ee0Ab60
# - id: 80001 # polygon-mumbai
# start_block: 41939383
# contracts:
Expand Down
6 changes: 6 additions & 0 deletions apps/indexer/src/handlers/AlloV1ToV2ProfileMigration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// /*
// * Please refer to https://docs.envio.dev for a thorough guide on all Envio indexer features
// */
import { AlloV1ToV2ProfileMigration } from "../../generated";

AlloV1ToV2ProfileMigration.ProfileMigrated.handler(async ({}) => {});
Copy link

@coderabbitai coderabbitai bot Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Empty handler implementation needs proper parameter destructuring

The handler function has an empty parameter destructuring pattern and an empty function body. According to the static analysis tool, this is a correctness issue. You should explicitly define the expected parameters and implement the handler logic.

- AlloV1ToV2ProfileMigration.ProfileMigrated.handler(async ({}) => {});
+ AlloV1ToV2ProfileMigration.ProfileMigrated.handler(async ({ event, context }) => {
+   // TODO: Implement migration logic
+ });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
AlloV1ToV2ProfileMigration.ProfileMigrated.handler(async ({}) => {});
AlloV1ToV2ProfileMigration.ProfileMigrated.handler(async ({ event, context }) => {
// TODO: Implement migration logic
});
🧰 Tools
🪛 Biome (1.9.4)

[error] 6-6: Unexpected empty object pattern.

(lint/correctness/noEmptyPattern)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're fine with the empty handler for the handlers of the Indexer app

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0xnigir1 Understood! I'll remember that empty handlers are acceptable for the Indexer app in your codebase. Thanks for clarifying your team's preference.


✏️ Learnings added
Learnt from: 0xnigir1
PR: defi-wonderland/grants-stack-indexer-v2#78
File: apps/indexer/src/handlers/AlloV1ToV2ProfileMigration.ts:6-6
Timestamp: 2025-02-26T21:54:46.207Z
Learning: Empty handlers (both empty parameter destructuring patterns and empty function bodies) are acceptable in the handlers of the Indexer app.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

6 changes: 6 additions & 0 deletions apps/processing/src/services/sharedDependencies.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
KyselyApplicationRepository,
KyselyDonationRepository,
KyselyEventRegistryRepository,
KyselyLegacyProjectRepository,
KyselyMetadataCache,
KyselyPricingCache,
KyselyProjectRepository,
Expand Down Expand Up @@ -72,6 +73,10 @@ export class SharedDependenciesService {
const transactionManager = new KyselyTransactionManager(kyselyDatabase);

const projectRepository = new KyselyProjectRepository(kyselyDatabase, env.DATABASE_SCHEMA);
const legacyProjectRepository = new KyselyLegacyProjectRepository(
kyselyDatabase,
env.DATABASE_SCHEMA,
);
const roundRepository = new KyselyRoundRepository(kyselyDatabase, env.DATABASE_SCHEMA);
const applicationRepository = new KyselyApplicationRepository(
kyselyDatabase,
Expand Down Expand Up @@ -153,6 +158,7 @@ export class SharedDependenciesService {
metadataProvider,
applicationPayoutRepository,
transactionManager,
legacyProjectRepository,
},
registriesRepositories: {
eventRegistryRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ vi.mock("@grants-stack-indexer/repository", () => ({
KyselyTransactionManager: vi.fn(),
KyselyPricingCache: vi.fn(),
KyselyMetadataCache: vi.fn(),
KyselyLegacyProjectRepository: vi.fn(),
InMemoryPricingCache: vi.fn(),
InMemoryMetadataCache: vi.fn(),
}));
Expand Down
6 changes: 5 additions & 1 deletion packages/data-flow/src/data-loader/dataLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
IApplicationRepository,
IDonationRepository,
IEventRegistryRepository,
ILegacyProjectRepository,
IProjectRepository,
IRoundRepository,
ITransactionManager,
Expand All @@ -15,10 +16,11 @@ import {
createApplicationHandlers,
createApplicationPayoutHandlers,
createDonationHandlers,
createLegacyProjectHandlers,
createProcessedEventHandlers,
createProjectHandlers,
createRoundHandlers,
} from "./handlers/index.js";
import { createProcessedEventHandlers } from "./handlers/processedEvent.handlers.js";
import { ChangesetHandlers } from "./types/index.js";

/**
Expand All @@ -45,6 +47,7 @@ export class DataLoader implements IDataLoader {
donation: IDonationRepository;
applicationPayout: IApplicationPayoutRepository;
eventRegistry: IEventRegistryRepository;
legacyProject: ILegacyProjectRepository;
},
private readonly transactionManager: ITransactionManager,
private readonly logger: ILogger,
Expand All @@ -56,6 +59,7 @@ export class DataLoader implements IDataLoader {
...createDonationHandlers(repositories.donation),
...createApplicationPayoutHandlers(repositories.applicationPayout),
...createProcessedEventHandlers(repositories.eventRegistry),
...createLegacyProjectHandlers(repositories.legacyProject),
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/data-flow/src/data-loader/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from "./round.handlers.js";
export * from "./donation.handlers.js";
export * from "./applicationPayout.handlers.js";
export * from "./processedEvent.handlers.js";
export * from "./legacyProject.handlers.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ILegacyProjectRepository, LegacyProjectChangeset } from "@grants-stack-indexer/repository";

import { ChangesetHandler } from "../types/index.js";

/**
* Collection of handlers for application-related operations.
* Each handler corresponds to a specific Application changeset type.
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix natspec

export type LegacyProjectHandlers = {
[K in LegacyProjectChangeset["type"]]: ChangesetHandler<K>;
};

/**
* Creates handlers for managing application-related operations.
*
* @param repository - The application repository instance used for database operations
* @returns An object containing all application-related handlers
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix natspec

export const createLegacyProjectHandlers = (
repository: ILegacyProjectRepository,
): LegacyProjectHandlers => ({
InsertLegacyProject: (async (changeset, txConnection): Promise<void> => {
await repository.insertLegacyProject(changeset.args.legacyProject, txConnection);
}) satisfies ChangesetHandler<"InsertLegacyProject">,
});
10 changes: 10 additions & 0 deletions packages/data-flow/src/eventsProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Changeset } from "@grants-stack-indexer/repository";
import {
AlloProcessor,
AlloV1ToV2ProfileMigrationProcessor,
ProcessorDependencies,
RegistryProcessor,
StrategyProcessor,
Expand All @@ -10,6 +11,7 @@ import {
ChainId,
ContractName,
isAlloEvent,
isAlloV1ToV2ProfileMigrationEvent,
isRegistryEvent,
isStrategyEvent,
ProcessorEvent,
Expand All @@ -26,11 +28,16 @@ export class EventsProcessor {
alloProcessor: AlloProcessor;
registryProcessor: RegistryProcessor;
strategyProcessor: StrategyProcessor;
alloV1ToV2MigrationProcessor: AlloV1ToV2ProfileMigrationProcessor;

constructor(chainId: ChainId, dependencies: Readonly<ProcessorDependencies>) {
this.alloProcessor = new AlloProcessor(chainId, dependencies);
this.registryProcessor = new RegistryProcessor(chainId, dependencies);
this.strategyProcessor = new StrategyProcessor(chainId, dependencies);
this.alloV1ToV2MigrationProcessor = new AlloV1ToV2ProfileMigrationProcessor(
chainId,
dependencies,
);
}

/**
Expand All @@ -49,6 +56,9 @@ export class EventsProcessor {
if (isStrategyEvent(event)) {
return await this.strategyProcessor.process(event);
}
if (isAlloV1ToV2ProfileMigrationEvent(event)) {
return await this.alloV1ToV2MigrationProcessor.process(event);
}

throw new InvalidEvent(event);
}
Expand Down
1 change: 1 addition & 0 deletions packages/data-flow/src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export class Orchestrator {
donation: this.dependencies.donationRepository,
applicationPayout: this.dependencies.applicationPayoutRepository,
eventRegistry: this.eventsRegistry,
legacyProject: this.dependencies.legacyProjectRepository,
},
this.dependencies.transactionManager,
this.logger,
Expand Down
1 change: 1 addition & 0 deletions packages/data-flow/src/retroactiveProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export class RetroactiveProcessor {
donation: this.dependencies.donationRepository,
applicationPayout: this.dependencies.applicationPayoutRepository,
eventRegistry: this.eventsRegistry,
legacyProject: this.dependencies.legacyProjectRepository,
},
this.dependencies.transactionManager,
this.logger,
Expand Down
2 changes: 2 additions & 0 deletions packages/data-flow/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
IApplicationPayoutRepository,
IApplicationRepository,
IDonationRepository,
ILegacyProjectRepository,
IProjectRepository,
IRoundRepository,
ITransactionManager,
Expand All @@ -30,4 +31,5 @@ export type CoreDependencies = Pick<
donationRepository: IDonationRepository;
applicationPayoutRepository: IApplicationPayoutRepository;
transactionManager: ITransactionManager;
legacyProjectRepository: ILegacyProjectRepository;
};
6 changes: 6 additions & 0 deletions packages/data-flow/test/data-loader/dataLoader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IApplicationRepository,
IDonationRepository,
IEventRegistryRepository,
ILegacyProjectRepository,
IProjectRepository,
IRoundRepository,
ITransactionManager,
Expand Down Expand Up @@ -46,6 +47,10 @@ describe("DataLoader", () => {
saveLastProcessedEvent: vi.fn(),
} as unknown as IEventRegistryRepository;

const mockLegacyProjectRepository = {
insertLegacyProject: vi.fn(),
} as unknown as ILegacyProjectRepository;

const logger: ILogger = {
debug: vi.fn(),
error: vi.fn(),
Expand All @@ -67,6 +72,7 @@ describe("DataLoader", () => {
donation: mockDonationRepository,
applicationPayout: mockApplicationPayoutRepository,
eventRegistry: mockEventRegistryRepository,
legacyProject: mockLegacyProjectRepository,
},
mockTransactionManager,
logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe("Project Handlers", () => {
updatedAtBlock: 100n,
tags: [],
projectType: "canonical",
timestamp: new Date(),
} as NewProject;

await handlers.InsertProject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ describe("Orchestrator Integration - Allo Events Processing", () => {
totalDistributed: 0n,
readyForPayoutTransaction: null,
matchingDistribution: null,
timestamp: new Date(poolCreatedEvent.blockTimestamp),
},
{},
);
Expand Down
4 changes: 4 additions & 0 deletions packages/data-flow/test/integration/helpers/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const createMockRepositories = (): Pick<
| "donationRepository"
| "applicationPayoutRepository"
| "transactionManager"
| "legacyProjectRepository"
> => ({
projectRepository: {
getProjects: vi.fn(),
Expand All @@ -37,6 +38,9 @@ export const createMockRepositories = (): Pick<
getProjectByAnchor: vi.fn(),
getProjectByAnchorOrThrow: vi.fn(),
},
legacyProjectRepository: {
insertLegacyProject: vi.fn(),
},
roundRepository: {
getRounds: vi.fn(),
getRoundById: vi.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ describe("Orchestrator Integration - Registry Events Processing", () => {
createdAtBlock: BigInt(profileCreatedEvent.blockNumber),
updatedAtBlock: BigInt(profileCreatedEvent.blockNumber),
projectType: "canonical",
timestamp: new Date(profileCreatedEvent.blockTimestamp),
},
{},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ describe("Orchestrator Integration - Strategy Events Processing", () => {
totalDonationsCount: 0,
uniqueDonorsCount: 0,
tags: ["allo-v2"],
timestamp: new Date(registeredEvent.blockTimestamp),
},
{},
);
Expand Down
Loading
Loading