-
Notifications
You must be signed in to change notification settings - Fork 0
/
batchValueTransferEvent.ts
39 lines (35 loc) · 1.21 KB
/
batchValueTransferEvent.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { isAddress } from "viem";
import { z } from "zod";
import { ParsedValueTransfer } from "@/parsing/valueTransferEvent.js";
import { ParserMethod } from "@/indexer/LogParser.js";
const ValueTransferEventSchema = z.object({
address: z.string().refine(isAddress),
params: z.object({
claimIDs: z.array(z.coerce.bigint()),
fromTokenIDs: z.array(z.coerce.bigint()),
toTokenIDs: z.array(z.coerce.bigint()),
values: z.array(z.coerce.bigint()),
}),
blockNumber: z.coerce.bigint(),
});
/*
* Helper method to get the sender, recipient, tokenID and value from the event. Will return undefined when the event is
* missing any of the required fields.
*
* @param event - The event object.
* */
export const parseBatchValueTransfer: ParserMethod<
ParsedValueTransfer
> = async ({ data }) => {
const { params, address } = ValueTransferEventSchema.parse(data);
const transfers = params.claimIDs.map((claimID, index) => {
return {
contract_address: address,
claim_id: claimID,
from_token_id: params.fromTokenIDs[index],
to_token_id: params.toTokenIDs[index],
units: params.values[index],
};
});
return transfers.map((transfer) => ParsedValueTransfer.parse(transfer));
};