Skip to content

Commit

Permalink
feat: index UpdatedRegistration
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc committed Mar 28, 2024
1 parent 3354be7 commit 2bfe124
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import os from "node:os";
type ChainId = number;
type CoingeckoSupportedChainId = 1 | 10 | 250 | 42161 | 43114;

const CHAIN_DATA_VERSION = "58";
const CHAIN_DATA_VERSION = "59";

export type Token = {
code: string;
Expand Down
77 changes: 77 additions & 0 deletions src/indexer/allo/v2/handleEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,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(
Expand Down

0 comments on commit 2bfe124

Please sign in to comment.