-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathcheck-if-job-exists.ts
122 lines (101 loc) · 3.39 KB
/
check-if-job-exists.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import fs from 'fs';
import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
import { config } from 'dotenv';
import { Environment } from '@holographxyz/environment';
import { parseAbi, getContract, PublicClient } from 'viem';
import { Config, Providers, HolographConfig } from '@holographxyz/sdk';
config();
/**
* This check if a list of jobs exists.
*
* Usage:
* 1. set HOLOGRAPH_ENVIRONMENT=mainnet
* 2. set the environmental rpc variables
* 3. create a json file that contains the following format: {jobHash: string; chainId: number}[]
* 4. run: `ts-node scripts/find-job-info.ts <JSON_FILE.json>`
*
* Example:
* `ts-node scripts/check-if-job-exists.ts jobs-list.json
*
*/
type Hex = `0x${string}`;
type Job = {
jobHash: Hex;
chainId: number;
};
type JobExists = Job & {
doesOperatorJobExists: boolean;
doesFailedJobExists: boolean;
};
const protocolConfig: HolographConfig = {
networks: {
ethereum: process.env.ETHEREUM_RPC_URL,
polygon: process.env.POLYGON_RPC_URL, // 137
avalanche: process.env.AVALANCHE_RPC_URL, // 43114
binanceSmartChain: process.env.BINANCE_SMART_CHAIN_RPC_URL, // 56
arbitrumOne: process.env.ARBITRUM_ONE_RPC_URL, // 42161
optimism: process.env.OPTIMISM_RPC_URL, // 10
mantle: process.env.MANTLE_RPC_URL, // 5000
zora: process.env.ZORA_RPC_URL, // 7777777
base: process.env.BASE_RPC_URL, // 8453
linea: process.env.LINEA_RPC_URL,
},
environment: Environment.mainnet,
};
// @ts-ignore
const abi = parseAbi([
'function operatorJobExists(bytes32 jobHash) view returns (bool)',
'function failedJobExists(bytes32 jobHash) view returns (bool)',
]);
const OPERATOR_CONTRACT_ADDRESS = '0xE1dD53589c001982d06247E1259DCC366b8DdB1B';
async function main() {
const args = yargs(hideBin(process.argv)).options({
file: {
type: 'string',
describe: 'file path',
usage: 'Usage: ts-node scripts/check-if-job-exists.ts --file [JSON_FILE.json]',
require: true,
},
chainId: {
type: 'number',
describe: 'chain ID to filter jobs',
usage: 'Usage: ts-node scripts/check-if-job-exists.ts --chainId [CHAIN_ID]',
require: true,
},
}).argv;
const { file, chainId } = args as {
file: string;
chainId: number;
};
let rawData = fs.readFileSync(file);
const jobHashes = JSON.parse(rawData.toString()) as Job[];
const _ = Config.getInstance(protocolConfig);
const providers = new Providers();
let jobExistsList: JobExists[] = [];
for (const job of jobHashes) {
if (job.chainId !== chainId) continue; // filter by chainId
const { jobHash } = job;
try {
const provider = providers.byChainId(chainId) as PublicClient;
// @ts-ignore
const operatorContract = getContract({ abi, address: OPERATOR_CONTRACT_ADDRESS, client: provider });
const doesOperatorJobExists = await operatorContract.read.operatorJobExists([jobHash]);
const doesFailedJobExists = await operatorContract.read.failedJobExists([jobHash]);
const jobExistsLog = {
chainId,
jobHash,
doesOperatorJobExists,
doesFailedJobExists,
};
jobExistsList.push(jobExistsLog);
console.log(`Job ${jobHash} on chain ${chainId} exists: ${doesOperatorJobExists} failed: ${doesFailedJobExists}`);
} catch (error) {
console.error(error);
}
}
}
main().catch(async (e) => {
console.error(e);
process.exit(1);
});