Skip to content
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

feat: index UpdatedRegistration #520

Merged
merged 7 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 89 additions & 4 deletions src/indexer/allo/v2/handleEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
DGApplicationData,
DGTimeStampUpdatedData,
DVMDApplicationData,
DVMDExtendedApplicationData,
DVMDTimeStampUpdatedData,
} from "../../types.js";
import { fetchPoolMetadata } from "./poolMetadata.js";
Expand Down Expand Up @@ -79,7 +80,9 @@ function getProjectTypeFromMetadata(metadata: ProjectMetadata) {
}

// Decode the application data from DonationVotingMerkleDistribution
function decodeDVMDApplicationData(encodedData: Hex): DVMDApplicationData {
function decodeDVMDExtendedApplicationData(
encodedData: Hex
): DVMDExtendedApplicationData {
const values = decodeAbiParameters(
[
{ name: "data", type: "bytes" },
Expand All @@ -88,6 +91,15 @@ function decodeDVMDApplicationData(encodedData: Hex): DVMDApplicationData {
encodedData
);

const encodededDVMD = decodeDVMDApplicationData(values[0]);

return {
...encodededDVMD,
recipientsCounter: values[1].toString(),
};
}

function decodeDVMDApplicationData(encodedData: Hex): DVMDApplicationData {
const decodedData = decodeAbiParameters(
[
{ name: "registryAnchor", type: "address" },
Expand All @@ -101,11 +113,10 @@ function decodeDVMDApplicationData(encodedData: Hex): DVMDApplicationData {
],
},
],
values[0]
encodedData
);

const results: DVMDApplicationData = {
recipientsCounter: values[1].toString(),
anchorAddress: decodedData[0],
recipientAddress: decodedData[1],
metadata: {
Expand Down Expand Up @@ -797,7 +808,7 @@ export async function handleEvent(

case "allov2.DonationVotingMerkleDistributionDirectTransferStrategy":
case "allov2.DirectGrantsLiteStrategy":
values = decodeDVMDApplicationData(encodedData);
values = decodeDVMDExtendedApplicationData(encodedData);
id = (Number(values.recipientsCounter) - 1).toString();
break;

Expand Down Expand Up @@ -843,6 +854,80 @@ export async function handleEvent(
];
}

case "UpdatedRegistration": {
const anchorAddress = parseAddress(event.params.recipientId);
const project = await db.getProjectByAnchor(chainId, anchorAddress);

if (!project) {
throw new Error("Project not found");
}

const encodedData = event.params.data;
const strategyAddress = parseAddress(event.address);
const round = await db.getRoundByStrategyAddress(
chainId,
strategyAddress
);

if (!round) {
throw new Error("Round not found");
}

let values;

switch (round.strategyName) {
case "allov2.DirectGrantsSimpleStrategy":
values = decodeDGApplicationData(encodedData);
break;

case "allov2.DirectGrantsLiteStrategy":
case "allov2.DonationVotingMerkleDistributionDirectTransferStrategy":
values = decodeDVMDApplicationData(encodedData);
break;

default:
throw new Error("Invalid strategy name");
}

const metadata = await ipfsGet(values.metadata.pointer);

const statusString = ApplicationStatus[
event.params.status
] as ApplicationTable["status"];

const application = await db.getApplicationByAnchorAddress(
chainId,
round.id,
anchorAddress
);

if (application === null) {
return [];
}

const statusUpdates = await updateApplicationStatus(
application,
statusString,
event.blockNumber,
getBlock
);

return [
{
type: "UpdateApplication",
chainId,
roundId: round.id,
applicationId: application.id,
application: {
...application,
...statusUpdates,
metadataCid: values.metadata.pointer,
metadata: metadata ?? null,
},
},
];
}

case "TimestampsUpdated": {
const strategyAddress = parseAddress(event.address);
const round = await db.getRoundByStrategyAddress(
Expand Down
5 changes: 4 additions & 1 deletion src/indexer/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export type DVMDApplicationData = {
recipientsCounter: string;
anchorAddress: string;
recipientAddress: string;
metadata: {
Expand All @@ -8,6 +7,10 @@ export type DVMDApplicationData = {
};
};

export type DVMDExtendedApplicationData = DVMDApplicationData & {
recipientsCounter: string;
};

export type DGApplicationData = {
recipientAddress: string;
anchorAddress: string;
Expand Down