|
1 | | -import { isAddress, isHex } from "viem"; |
| 1 | +import { isAddress, isHex, parseEventLogs } from "viem"; |
2 | 2 | import { z } from "zod"; |
3 | 3 | import { Claim, ClaimSchema } from "@/storage/storeClaimStored.js"; |
4 | 4 | import { ParserMethod } from "@/indexer/LogParser.js"; |
5 | 5 | import { ZERO_ADDRESS } from "@/utils/constants.js"; |
6 | 6 | import { getEvmClient } from "@/clients/evmClient.js"; |
| 7 | +import { HypercertMinterAbi } from "@hypercerts-org/contracts"; |
7 | 8 |
|
8 | 9 | export const ClaimStoredEventSchema = z.object({ |
9 | 10 | address: z.string().refine(isAddress, { |
@@ -32,18 +33,33 @@ export const parseClaimStoredEvent: ParserMethod<Claim> = async ({ |
32 | 33 | context: { chain_id, contracts_id }, |
33 | 34 | }) => { |
34 | 35 | const { params, transactionHash } = ClaimStoredEventSchema.parse(event); |
35 | | - const client = getEvmClient(chain_id); |
| 36 | + const client = getEvmClient(Number(chain_id)); |
36 | 37 |
|
37 | 38 | try { |
38 | | - const transaction = await client.getTransaction({ |
| 39 | + // get the operator from the transferSingle event, this is necessary for safe support |
| 40 | + // otherwise transaction.from is the address of the last signer in safe |
| 41 | + const receipt = await client.getTransactionReceipt({ |
39 | 42 | hash: transactionHash, |
40 | 43 | }); |
| 44 | + const parsedLogs = parseEventLogs({ |
| 45 | + abi: HypercertMinterAbi, |
| 46 | + logs: receipt.logs, |
| 47 | + }); |
| 48 | + const transferSingleEvent = parsedLogs.find( |
| 49 | + // @ts-expect-error eventName is missing in the type |
| 50 | + (log) => log.eventName === "TransferSingle", |
| 51 | + ); |
| 52 | + if (!transferSingleEvent) { |
| 53 | + throw new Error("TransferSingle event not found"); |
| 54 | + } |
| 55 | + // @ts-expect-error args is missing in the type |
| 56 | + const operator = transferSingleEvent.args.operator; |
41 | 57 |
|
42 | 58 | return [ |
43 | 59 | ClaimSchema.parse({ |
44 | 60 | contracts_id: contracts_id, |
45 | 61 | owner_address: ZERO_ADDRESS, |
46 | | - creator_address: transaction.from, |
| 62 | + creator_address: operator, |
47 | 63 | token_id: params.claimID, |
48 | 64 | uri: params.uri, |
49 | 65 | units: params.totalUnits, |
|
0 commit comments