Skip to content

Commit

Permalink
Add Allo v1 Custom Fields
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc committed Nov 6, 2024
1 parent 43ff8de commit b1b2319
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions src/indexer/allo/v1/handleEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,9 +797,46 @@ export async function handleEvent(
}

const strategyAddress = parseAddress(event.address);
const rawDistribution = await ipfsGet(

const roundId = parseAddress(
await readContract({
contract: "AlloV1/MerklePayoutStrategyImplementation/V2",
address: strategyAddress,
functionName: "roundAddress",
})
);

const round = await db.getRoundById(
chainId,
roundId
);

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

const rawDistribution = (await ipfsGet(
event.params.distributionMetaPtr.pointer
)) as Record<string, unknown>;

const usdAmount = await convertToUSD(
priceProvider,
chainId,
round?.matchTokenAddress,
BigInt(1),
event.blockNumber
);

const blockTimestamp = getDateFromTimestamp(
BigInt((await blockTimestampInMs(chainId, event.blockNumber)) / 1000)
);
rawDistribution["blockNumber"] = Number(event.blockNumber);
if (blockTimestamp) {
rawDistribution["blockTimestamp"] = blockTimestamp;
}
rawDistribution["usdPrice"] = usdAmount.price;
rawDistribution["usdPriceTimestampAt"] = usdAmount.timestamp;

const distribution =
MatchingDistributionSchema.safeParse(rawDistribution);

Expand All @@ -817,7 +854,7 @@ export async function handleEvent(
{
type: "UpdateRoundByStrategyAddress",
chainId,
strategyAddress,
strategyAddress: strategyAddress,
round: {
matchingDistribution: distribution.data,
},
Expand Down

0 comments on commit b1b2319

Please sign in to comment.