-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathgetDisputeRequestParamsFromTxn.ts
35 lines (30 loc) · 1.18 KB
/
getDisputeRequestParamsFromTxn.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
import { getPublicClient } from "@wagmi/core";
import { type GetTransactionReceiptReturnType, decodeEventLog, getEventSelector } from "viem";
import { iArbitrableV2Abi } from "hooks/contracts/generated";
import { isUndefined } from "utils/isUndefined";
import { wagmiConfig } from "utils/wagmiConfig";
export const getDisputeRequestParamsFromTxn = async (hash: `0x${string}`, chainId: number) => {
try {
const publicClient = getPublicClient(wagmiConfig, { chainId });
if (!publicClient) return;
const txn: GetTransactionReceiptReturnType = await publicClient.getTransactionReceipt({
hash,
});
const selector = getEventSelector("DisputeRequest(address,uint256,uint256,uint256,string)");
const disputeRequestEvent = txn.logs.find((log) => log.topics[0] === selector);
if (isUndefined(disputeRequestEvent)) return undefined;
const topics = decodeEventLog({
abi: iArbitrableV2Abi,
eventName: "DisputeRequest",
topics: disputeRequestEvent?.topics,
data: disputeRequestEvent?.data,
});
return {
...topics?.args,
_arbitrable: disputeRequestEvent.address,
};
} catch (e) {
console.error(e);
return undefined;
}
};