From 4fc74aa27b99b2f0341f6b060f5144ea4aa0752d Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Fri, 29 Mar 2024 01:22:56 +0530 Subject: [PATCH 1/5] feat: index UpdatedRegistration --- src/indexer/allo/v2/handleEvent.ts | 77 ++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/src/indexer/allo/v2/handleEvent.ts b/src/indexer/allo/v2/handleEvent.ts index ceb89577..5011a7e6 100644 --- a/src/indexer/allo/v2/handleEvent.ts +++ b/src/indexer/allo/v2/handleEvent.ts @@ -843,6 +843,83 @@ 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 id; + let values; + + switch (round.strategyName) { + case "allov2.DirectGrantsSimpleStrategy": + values = decodeDGApplicationData(encodedData); + id = event.params.recipientId; + break; + + case "allov2.DonationVotingMerkleDistributionDirectTransferStrategy": + values = decodeDVMDApplicationData(encodedData); + id = (Number(values.recipientsCounter) - 1).toString(); + 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.getApplicationById( + chainId, + round.id, + id + ); + + if (application === null) { + return []; + } + + const statusUpdates = await updateApplicationStatus( + application, + statusString, + event.blockNumber, + getBlock + ); + + return [ + { + type: "UpdateApplication", + chainId, + roundId: round.id, + applicationId: id, + application: { + metadataCid: values.metadata.pointer, + metadata: metadata ?? null, + distributionTransaction: null, + totalAmountDonatedInUsd: 0, + totalDonationsCount: 0, + uniqueDonorsCount: 0, + ...statusUpdates, + }, + }, + ]; + } + case "TimestampsUpdated": { const strategyAddress = parseAddress(event.address); const round = await db.getRoundByStrategyAddress( From 513609272d5bf76371ecb060ae8829025cc69ae0 Mon Sep 17 00:00:00 2001 From: 0xKurt Date: Tue, 13 Aug 2024 13:53:45 +0200 Subject: [PATCH 2/5] update application object --- src/indexer/allo/v2/handleEvent.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/indexer/allo/v2/handleEvent.ts b/src/indexer/allo/v2/handleEvent.ts index 5011a7e6..80e0d911 100644 --- a/src/indexer/allo/v2/handleEvent.ts +++ b/src/indexer/allo/v2/handleEvent.ts @@ -908,13 +908,10 @@ export async function handleEvent( roundId: round.id, applicationId: id, application: { + ...application, + ...statusUpdates, metadataCid: values.metadata.pointer, metadata: metadata ?? null, - distributionTransaction: null, - totalAmountDonatedInUsd: 0, - totalDonationsCount: 0, - uniqueDonorsCount: 0, - ...statusUpdates, }, }, ]; From 2a95d0ab9b36c4ab198d53c3f3c144109e3d051f Mon Sep 17 00:00:00 2001 From: 0xKurt Date: Tue, 13 Aug 2024 14:29:57 +0200 Subject: [PATCH 3/5] updates --- src/indexer/allo/v2/handleEvent.ts | 91 ++++++++++++++++++++++++++---- src/indexer/types.ts | 5 +- 2 files changed, 85 insertions(+), 11 deletions(-) diff --git a/src/indexer/allo/v2/handleEvent.ts b/src/indexer/allo/v2/handleEvent.ts index 80e0d911..f816c77f 100644 --- a/src/indexer/allo/v2/handleEvent.ts +++ b/src/indexer/allo/v2/handleEvent.ts @@ -24,6 +24,7 @@ import { DGApplicationData, DGTimeStampUpdatedData, DVMDApplicationData, + DVMDExtendedApplicationData, DVMDTimeStampUpdatedData, } from "../../types.js"; import { fetchPoolMetadata } from "./poolMetadata.js"; @@ -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" }, @@ -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" }, @@ -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: { @@ -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; @@ -868,12 +879,11 @@ export async function handleEvent( switch (round.strategyName) { case "allov2.DirectGrantsSimpleStrategy": values = decodeDGApplicationData(encodedData); - id = event.params.recipientId; break; + case "allov2.DirectGrantsLiteStrategy": case "allov2.DonationVotingMerkleDistributionDirectTransferStrategy": values = decodeDVMDApplicationData(encodedData); - id = (Number(values.recipientsCounter) - 1).toString(); break; default: @@ -882,12 +892,14 @@ export async function handleEvent( const metadata = await ipfsGet(values.metadata.pointer); - const statusString = ApplicationStatus[event.params.status] as ApplicationTable["status"]; + const statusString = ApplicationStatus[ + event.params.status + ] as ApplicationTable["status"]; - const application = await db.getApplicationById( + const application = await db.getApplicationByAnchorAddress( chainId, round.id, - id + anchorAddress ); if (application === null) { @@ -901,12 +913,71 @@ export async function handleEvent( getBlock ); + console.log("=================================="); + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("==================================") + console.log("=================================="); + + return [ { type: "UpdateApplication", chainId, roundId: round.id, - applicationId: id, + applicationId: application.id, application: { ...application, ...statusUpdates, diff --git a/src/indexer/types.ts b/src/indexer/types.ts index 29bc812f..b8a8bd5a 100644 --- a/src/indexer/types.ts +++ b/src/indexer/types.ts @@ -1,5 +1,4 @@ export type DVMDApplicationData = { - recipientsCounter: string; anchorAddress: string; recipientAddress: string; metadata: { @@ -8,6 +7,10 @@ export type DVMDApplicationData = { }; }; +export type DVMDExtendedApplicationData = DVMDApplicationData & { + recipientsCounter: string; +}; + export type DGApplicationData = { recipientAddress: string; anchorAddress: string; From b9b7807efb1b7620078e3e8e3e4c8f68a520d610 Mon Sep 17 00:00:00 2001 From: 0xKurt Date: Tue, 13 Aug 2024 14:30:18 +0200 Subject: [PATCH 4/5] updates --- src/indexer/allo/v2/handleEvent.ts | 59 ------------------------------ 1 file changed, 59 deletions(-) diff --git a/src/indexer/allo/v2/handleEvent.ts b/src/indexer/allo/v2/handleEvent.ts index f816c77f..086692a8 100644 --- a/src/indexer/allo/v2/handleEvent.ts +++ b/src/indexer/allo/v2/handleEvent.ts @@ -913,65 +913,6 @@ export async function handleEvent( getBlock ); - console.log("=================================="); - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("==================================") - console.log("=================================="); - - return [ { type: "UpdateApplication", From f7d990f5996e9de2ad247c25711c47d6150af9f2 Mon Sep 17 00:00:00 2001 From: 0xKurt Date: Tue, 13 Aug 2024 14:38:45 +0200 Subject: [PATCH 5/5] remove unused variable --- src/indexer/allo/v2/handleEvent.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/indexer/allo/v2/handleEvent.ts b/src/indexer/allo/v2/handleEvent.ts index 086692a8..303153ba 100644 --- a/src/indexer/allo/v2/handleEvent.ts +++ b/src/indexer/allo/v2/handleEvent.ts @@ -873,7 +873,6 @@ export async function handleEvent( throw new Error("Round not found"); } - let id; let values; switch (round.strategyName) {