-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathisAnyTrust.ts
More file actions
59 lines (50 loc) · 1.62 KB
/
isAnyTrust.ts
File metadata and controls
59 lines (50 loc) · 1.62 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Address, Chain, PublicClient, Transport, decodeFunctionData, getAbiItem } from 'viem';
import { createRollupFetchTransactionHash } from './createRollupFetchTransactionHash';
import { rollupCreatorABI } from './contracts/RollupCreator';
import { rollupCreatorABI as rollupCreatorV1Dot1ABI } from './contracts/RollupCreator/v1.1';
const createRollupABI = getAbiItem({ abi: rollupCreatorABI, name: 'createRollup' });
const createRollupV1Dot1ABI = getAbiItem({ abi: rollupCreatorV1Dot1ABI, name: 'createRollup' });
function parseConfig(config: { chainConfig: string }): boolean {
return JSON.parse(config.chainConfig).arbitrum.DataAvailabilityCommittee;
}
export async function isAnyTrust<TChain extends Chain | undefined>({
rollup,
publicClient,
}: {
rollup: Address;
publicClient: PublicClient<Transport, TChain>;
}) {
const createRollupTransactionHash = await createRollupFetchTransactionHash({
rollup,
publicClient,
});
const transaction = await publicClient.getTransaction({
hash: createRollupTransactionHash,
});
let result: boolean | null = null;
// try parsing from multiple RollupCreator versions
[
// v2.1
createRollupABI,
// v1.1
createRollupV1Dot1ABI,
].forEach((abi) => {
try {
const {
args: [{ config }],
} = decodeFunctionData({
abi: [abi],
data: transaction.input,
});
result = parseConfig(config);
} catch (error) {
// do nothing
}
});
if (result === null) {
throw new Error(
`[isAnyTrust] failed to decode input data for transaction ${createRollupTransactionHash}`,
);
}
return result;
}