generated from defi-wonderland/ts-turborepo-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# 🤖 Linear Closes GIT-138 GIT-145 GIT-146 GIT-147 GIT-148 ## Description All Registry contract event handlers. ## Checklist before requesting a review - [x] I have conducted a self-review of my code. - [x] I have conducted a QA. - [x] If it is a core feature, I have included comprehensive tests.
- Loading branch information
Showing
51 changed files
with
799 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ges/processors/src/allo/allo.processor.ts → ...ors/src/processors/allo/allo.processor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
packages/processors/src/processors/registry/handlers/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export * from "./profileCreated.handler.js"; | ||
export * from "./profileMetadataUpdated.handler.js"; | ||
export * from "./profileNameUpdated.handler.js"; | ||
export * from "./profileOwnerUpdated.handler.js"; | ||
export * from "./roleGranted.handler.js"; | ||
export * from "./roleRevoked.handler.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/processors/src/processors/registry/handlers/profileMetadataUpdated.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Changeset, ProjectType } from "@grants-stack-indexer/repository"; | ||
import { ChainId, ProcessorEvent } from "@grants-stack-indexer/shared"; | ||
|
||
import { IEventHandler, ProcessorDependencies } from "../../../internal.js"; | ||
import { ProjectMetadata, ProjectMetadataSchema } from "../../../schemas/index.js"; | ||
|
||
type Dependencies = Pick< | ||
ProcessorDependencies, | ||
"projectRepository" | "evmProvider" | "metadataProvider" | "logger" | ||
>; | ||
|
||
/** | ||
* Handles the ProfileMetadataUpdated event for the Registry contract from Allo protocol. | ||
* | ||
* This handler performs the following steps: | ||
* - Fetches the metadata for the profile from the metadata provider | ||
* - Parses the metadata to extract the project type | ||
* - Returns the changeset to update the project with the metadata | ||
*/ | ||
export class ProfileMetadataUpdatedHandler | ||
implements IEventHandler<"Registry", "ProfileMetadataUpdated"> | ||
{ | ||
constructor( | ||
readonly event: ProcessorEvent<"Registry", "ProfileMetadataUpdated">, | ||
readonly chainId: ChainId, | ||
private dependencies: Dependencies, | ||
) {} | ||
/* @inheritdoc */ | ||
async handle(): Promise<Changeset[]> { | ||
const { metadataProvider } = this.dependencies; | ||
|
||
const metadataCid = this.event.params.metadata[1]; | ||
const metadata = await metadataProvider.getMetadata(metadataCid); | ||
const parsedMetadata = ProjectMetadataSchema.safeParse(metadata); | ||
|
||
if (!parsedMetadata.success) { | ||
return [ | ||
{ | ||
type: "UpdateProject", | ||
args: { | ||
chainId: this.chainId, | ||
projectId: this.event.params.profileId, | ||
project: { | ||
metadataCid: metadataCid, | ||
metadata: null, | ||
projectType: "canonical", | ||
}, | ||
}, | ||
}, | ||
]; | ||
} | ||
|
||
const projectType = this.getProjectTypeFromMetadata(parsedMetadata.data); | ||
|
||
return [ | ||
{ | ||
type: "UpdateProject", | ||
args: { | ||
chainId: this.chainId, | ||
projectId: this.event.params.profileId, | ||
project: { | ||
metadataCid: metadataCid, | ||
metadata: metadata, | ||
projectType, | ||
}, | ||
}, | ||
}, | ||
]; | ||
} | ||
private getProjectTypeFromMetadata(metadata: ProjectMetadata): ProjectType { | ||
// if the metadata contains a canonical reference, it's a linked project | ||
if ("canonical" in metadata) { | ||
return "linked"; | ||
} | ||
|
||
return "canonical"; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/processors/src/processors/registry/handlers/profileNameUpdated.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { getAddress } from "viem"; | ||
|
||
import { Changeset } from "@grants-stack-indexer/repository"; | ||
import { ChainId, ProcessorEvent } from "@grants-stack-indexer/shared"; | ||
|
||
import { IEventHandler, ProcessorDependencies } from "../../../internal.js"; | ||
|
||
type Dependencies = Pick<ProcessorDependencies, "logger">; | ||
/** | ||
* Handles the ProfileNameUpdated event for the Registry contract from Allo protocol. | ||
* | ||
* This handler performs the following steps: | ||
* - Returns the changeset to update the project with the new name | ||
*/ | ||
export class ProfileNameUpdatedHandler implements IEventHandler<"Registry", "ProfileNameUpdated"> { | ||
constructor( | ||
readonly event: ProcessorEvent<"Registry", "ProfileNameUpdated">, | ||
readonly chainId: ChainId, | ||
private dependencies: Dependencies, | ||
) {} | ||
/* @inheritdoc */ | ||
async handle(): Promise<Changeset[]> { | ||
return [ | ||
{ | ||
type: "UpdateProject", | ||
args: { | ||
chainId: this.chainId, | ||
projectId: this.event.params.profileId, | ||
project: { | ||
name: this.event.params.name, | ||
anchorAddress: getAddress(this.event.params.anchor), | ||
}, | ||
}, | ||
}, | ||
]; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
packages/processors/src/processors/registry/handlers/profileOwnerUpdated.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { getAddress } from "viem"; | ||
|
||
import { Changeset } from "@grants-stack-indexer/repository"; | ||
import { ChainId, ProcessorEvent } from "@grants-stack-indexer/shared"; | ||
|
||
import { IEventHandler, ProcessorDependencies } from "../../../internal.js"; | ||
|
||
type Dependencies = Pick<ProcessorDependencies, "logger">; | ||
/** | ||
* Handles the ProfileOwnerUpdated event for the Registry contract from Allo protocol. | ||
* | ||
* This handler performs the following steps: | ||
* | ||
* - Returns the changeset to delete all project roles with the role "owner" | ||
* for the profile and insert a new project role with the new owner address. | ||
*/ | ||
export class ProfileOwnerUpdatedHandler | ||
implements IEventHandler<"Registry", "ProfileOwnerUpdated"> | ||
{ | ||
constructor( | ||
readonly event: ProcessorEvent<"Registry", "ProfileOwnerUpdated">, | ||
readonly chainId: ChainId, | ||
private dependencies: Dependencies, | ||
) {} | ||
/* @inheritdoc */ | ||
async handle(): Promise<Changeset[]> { | ||
return [ | ||
{ | ||
type: "DeleteAllProjectRolesByRole", | ||
args: { | ||
projectRole: { | ||
chainId: this.chainId, | ||
projectId: this.event.params.profileId, | ||
role: "owner", | ||
}, | ||
}, | ||
}, | ||
{ | ||
type: "InsertProjectRole", | ||
args: { | ||
projectRole: { | ||
chainId: this.chainId, | ||
projectId: this.event.params.profileId, | ||
address: getAddress(this.event.params.owner), | ||
role: "owner", | ||
createdAtBlock: BigInt(this.event.blockNumber), | ||
}, | ||
}, | ||
}, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/processors/src/processors/registry/handlers/roleRevoked.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { getAddress } from "viem"; | ||
|
||
import { Changeset } from "@grants-stack-indexer/repository"; | ||
import { ChainId, ProcessorEvent } from "@grants-stack-indexer/shared"; | ||
|
||
import { IEventHandler, ProcessorDependencies, ProjectByRoleNotFound } from "../../../internal.js"; | ||
|
||
type Dependencies = Pick<ProcessorDependencies, "projectRepository" | "logger">; | ||
/** | ||
* Handles the RoleRevoked event for the Registry contract from Allo protocol. | ||
* | ||
* This handler performs the following steps: | ||
* | ||
* - Returns the changeset to delete all project roles with the role "member" | ||
* for the profile and address. | ||
* | ||
* If the project with the role id doesn't exist, it throws an error. | ||
*/ | ||
export class RoleRevokedHandler implements IEventHandler<"Registry", "RoleRevoked"> { | ||
constructor( | ||
readonly event: ProcessorEvent<"Registry", "RoleRevoked">, | ||
readonly chainId: ChainId, | ||
private dependencies: Dependencies, | ||
) {} | ||
/* @inheritdoc */ | ||
async handle(): Promise<Changeset[]> { | ||
const { projectRepository } = this.dependencies; | ||
const account = getAddress(this.event.params.account); | ||
const role = this.event.params.role.toLowerCase(); | ||
const project = await projectRepository.getProjectById(this.chainId, role); | ||
|
||
// The role value for a member is the profileId in Allo V1 | ||
// which is the project id in this database. | ||
// If we don't find a project with that id we can't remove the role. | ||
if (!project) { | ||
throw new ProjectByRoleNotFound(this.chainId, role); | ||
} | ||
|
||
return [ | ||
{ | ||
type: "DeleteAllProjectRolesByRoleAndAddress", | ||
args: { | ||
projectRole: { | ||
chainId: this.chainId, | ||
projectId: project.id, | ||
address: account, | ||
role: "member", | ||
}, | ||
}, | ||
}, | ||
]; | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.