Skip to content

Commit

Permalink
fix: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
0xkenj1 committed Oct 22, 2024
1 parent ac86f6f commit fab3bc2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions apps/indexer/src/handlers/Registry.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/processors/src/registry/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./profileCreated.hanlder.js";
export * from "./profileCreated.handler.js";
export * from "./roleGranted.handler.js";
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ 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">,
readonly chainId: ChainId,
private dependencies: Dependencies,
) {}
async handle(): Promise<Changeset[]> {
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);

Expand All @@ -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[] = [
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions packages/processors/src/registry/handlers/roleGranted.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@ 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">,
readonly chainId: ChainId,
private readonly dependencies: ProcessorDependencies,
) {}
async handle(): Promise<Changeset[]> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
4 changes: 3 additions & 1 deletion packages/shared/src/types/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Hex } from "viem";

import { Branded } from "../internal.js";

export type ChainId = Branded<number, "ChainId">;

export type Bytes32String = Branded<`0x${string}`, "Bytes32String">;
export type Bytes32String = Branded<Hex, "Bytes32String">;

0 comments on commit fab3bc2

Please sign in to comment.