-
Notifications
You must be signed in to change notification settings - Fork 33
/
getImplementation.ts
46 lines (42 loc) · 1.25 KB
/
getImplementation.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
40
41
42
43
44
45
46
import {
getProviderForNetworkId,
getRpcBatchProviderForNetworkId,
} from "./getProvider";
import { NetworkId } from "./types";
export async function getImplementation(
addresses: string[],
networkId: NetworkId
) {
const multicall = getRpcBatchProviderForNetworkId(networkId);
const implementationAnswers = await Promise.allSettled(
addresses.map(async (address) => {
const get_implementation = await multicall.callContract({
contractAddress: address,
entrypoint: "get_implementation",
});
if (get_implementation !== undefined) {
return get_implementation;
}
try {
const provider = getProviderForNetworkId(networkId);
const classHash = await provider.getClassHashAt(address);
return classHash;
} catch (e) {
console.warn("Assuming tx V1 implementation");
const TXV1_ACCOUNT_CLASS_HASH =
"0x1a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003";
return TXV1_ACCOUNT_CLASS_HASH;
}
})
);
const implementations = implementationAnswers
.map((answer) => {
if (answer.status === "fulfilled") {
return answer.value;
} else {
return null;
}
})
.flat();
return implementations;
}