-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.ts
42 lines (37 loc) · 1.16 KB
/
utils.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
import fs from "fs";
import { createPublicClient, http, getContract } from "viem";
import { celo } from "viem/chains";
import { registryABI } from "@celo/abis";
export const publicClient = createPublicClient({
chain: celo,
transport: http(),
});
type Address = `0x${string}`;
export async function getCoreContractAddress(
contractName: string
): Promise<Address> {
const registryContract = getContract({
address: "0x000000000000000000000000000000000000ce10",
abi: registryABI,
publicClient,
});
return await registryContract.read.getAddressForStringOrDie([contractName]);
}
export const BLOCKS_PER_EPOCH = 17280n;
export function getEpochBlockNumber(epochNumber: bigint): bigint {
return epochNumber * BLOCKS_PER_EPOCH;
}
export async function writeToJsonFile(fileName: string, data: any) {
fs.writeFileSync(
`./output/${fileName}.json`,
JSON.stringify(
data,
(key, value) =>
typeof value === "bigint" ? value.toString() : value,
2
)
);
}
export async function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}