diff --git a/apps/indexer/src/handlers/Registry.ts b/apps/indexer/src/handlers/Registry.ts index f597722..78e19b5 100644 --- a/apps/indexer/src/handlers/Registry.ts +++ b/apps/indexer/src/handlers/Registry.ts @@ -1,10 +1,10 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ import { Registry } from "../../generated"; -// Handler for ProfileNameUpdated event +// Handler for RoleGranted event Registry.RoleGranted.handler(async ({}) => {}); -// Handler for ProfileOwnerUpdated event +// Handler for RoleRevoked event Registry.RoleRevoked.handler(async ({}) => {}); // Handler for ProfileCreated event diff --git a/packages/processors/src/registry/handlers/index.ts b/packages/processors/src/registry/handlers/index.ts index 79e1e8b..59fea08 100644 --- a/packages/processors/src/registry/handlers/index.ts +++ b/packages/processors/src/registry/handlers/index.ts @@ -1,2 +1,2 @@ -export * from "./profileCreated.hanlder.js"; +export * from "./profileCreated.handler.js"; export * from "./roleGranted.handler.js"; diff --git a/packages/processors/src/registry/handlers/profileCreated.hanlder.ts b/packages/processors/src/registry/handlers/profileCreated.handler.ts similarity index 87% rename from packages/processors/src/registry/handlers/profileCreated.hanlder.ts rename to packages/processors/src/registry/handlers/profileCreated.handler.ts index c463e0f..9d89c83 100644 --- a/packages/processors/src/registry/handlers/profileCreated.hanlder.ts +++ b/packages/processors/src/registry/handlers/profileCreated.handler.ts @@ -8,9 +8,11 @@ import { ProjectMetadata, ProjectMetadataSchema } from "../../schemas/projectMet type Dependencies = Pick< ProcessorDependencies, - "projectRepository" | "evmProvider" | "pricingProvider" | "metadataProvider" + "projectRepository" | "evmProvider" | "metadataProvider" >; - +/** + * Handles the ProfileCreated event for the Registry contract from Allo protocol. + */ export class ProfileCreatedHandler implements IEventHandler<"Registry", "ProfileCreated"> { constructor( readonly event: ProtocolEvent<"Registry", "ProfileCreated">, @@ -18,9 +20,10 @@ export class ProfileCreatedHandler implements IEventHandler<"Registry", "Profile private dependencies: Dependencies, ) {} async handle(): Promise { + const { metadataProvider, evmProvider, projectRepository } = this.dependencies; const profileId = this.event.params.profileId; const metadataCid = this.event.params.metadata[1]; - const metadata = await this.dependencies.metadataProvider.getMetadata(metadataCid); + const metadata = await metadataProvider.getMetadata(metadataCid); const parsedMetadata = ProjectMetadataSchema.safeParse(metadata); @@ -42,11 +45,9 @@ export class ProfileCreatedHandler implements IEventHandler<"Registry", "Profile }); } - const tx = await this.dependencies.evmProvider.getTransaction( - this.event.transactionFields.hash, - ); - - const createdBy = tx.from; + const createdBy = + this.event.transactionFields.from ?? + (await evmProvider.getTransaction(this.event.transactionFields.hash)).from; const programTags = isProgram ? ["program"] : []; const changes: Changeset[] = [ @@ -85,11 +86,10 @@ export class ProfileCreatedHandler implements IEventHandler<"Registry", "Profile }, ]; - const pendingProjectRoles = - await this.dependencies.projectRepository.getPendingProjectRolesByRole( - this.chainId, - profileId, - ); + const pendingProjectRoles = await projectRepository.getPendingProjectRolesByRole( + this.chainId, + profileId, + ); if (pendingProjectRoles.length !== 0) { for (const role of pendingProjectRoles) { diff --git a/packages/processors/src/registry/handlers/roleGranted.handler.ts b/packages/processors/src/registry/handlers/roleGranted.handler.ts index f035040..5c246c8 100644 --- a/packages/processors/src/registry/handlers/roleGranted.handler.ts +++ b/packages/processors/src/registry/handlers/roleGranted.handler.ts @@ -6,6 +6,9 @@ import { ALLO_OWNER_ROLE, ChainId, ProtocolEvent } from "@grants-stack-indexer/s import { IEventHandler } from "../../internal.js"; import { ProcessorDependencies } from "../../types/processor.types.js"; +/** + * Handles the RoleGranted event for the Registry contract from Allo protocol. + */ export class RoleGrantedHandler implements IEventHandler<"Registry", "RoleGranted"> { constructor( readonly event: ProtocolEvent<"Registry", "RoleGranted">, @@ -13,16 +16,15 @@ export class RoleGrantedHandler implements IEventHandler<"Registry", "RoleGrante private readonly dependencies: ProcessorDependencies, ) {} async handle(): Promise { + const { projectRepository } = this.dependencies; const role = this.event.params.role.toLocaleLowerCase(); if (role === ALLO_OWNER_ROLE) { return []; } const account = getAddress(this.event.params.account); - const project = await this.dependencies.projectRepository.getProjectById( - this.chainId, - role, - ); + const project = await projectRepository.getProjectById(this.chainId, role); + // The member role for an Allo V2 profile, is the profileId itself. // If a project exists with that id, we create the member role // If it doesn't exists we create a pending project role. This can happens diff --git a/packages/processors/test/registry/handlers/roleGranted.handler.spec.ts b/packages/processors/test/registry/handlers/roleGranted.handler.spec.ts index 32b4a32..30f460a 100644 --- a/packages/processors/test/registry/handlers/roleGranted.handler.spec.ts +++ b/packages/processors/test/registry/handlers/roleGranted.handler.spec.ts @@ -82,7 +82,7 @@ describe("RoleGrantedHandler", () => { mockedEvent["params"]["role"] = "0x1231231234" as Bytes32String; const event = mockedEvent; - mockProjectRepository.getProjectById.mockResolvedValueOnce(null); + mockProjectRepository.getProjectById.mockResolvedValueOnce(undefined); const handler = new RoleGrantedHandler(event, chainId, dependencies); @@ -112,7 +112,7 @@ describe("RoleGrantedHandler", () => { await expect(handler.handle()).rejects.toThrow(InvalidAddressError); }); - it("should throw an error if projectRepository throws an error", async () => { + it("throws an error if projectRepository throws an error", async () => { mockedEvent["params"]["role"] = "0x1231231234" as Bytes32String; const event = mockedEvent; diff --git a/packages/processors/test/registry/registry.processor.spec.ts b/packages/processors/test/registry/registry.processor.spec.ts index bc5a252..06dc730 100644 --- a/packages/processors/test/registry/registry.processor.spec.ts +++ b/packages/processors/test/registry/registry.processor.spec.ts @@ -3,7 +3,7 @@ import { afterEach, describe, expect, it, vi } from "vitest"; import type { ChainId, ProtocolEvent, RegistryEvent } from "@grants-stack-indexer/shared"; import { ProcessorDependencies, UnsupportedEventException } from "../../src/internal.js"; -import { ProfileCreatedHandler } from "../../src/registry/handlers/profileCreated.hanlder.js"; +import { ProfileCreatedHandler } from "../../src/registry/handlers/profileCreated.handler.js"; import { RoleGrantedHandler } from "../../src/registry/handlers/roleGranted.handler.js"; import { RegistryProcessor } from "../../src/registry/registry.processor.js"; diff --git a/packages/shared/src/types/common.ts b/packages/shared/src/types/common.ts index ca5e528..4bd7ee2 100644 --- a/packages/shared/src/types/common.ts +++ b/packages/shared/src/types/common.ts @@ -1,5 +1,7 @@ +import { Hex } from "viem"; + import { Branded } from "../internal.js"; export type ChainId = Branded; -export type Bytes32String = Branded<`0x${string}`, "Bytes32String">; +export type Bytes32String = Branded;