-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathget-job-info-from-available-operator-job.ts
136 lines (116 loc) · 4.01 KB
/
get-job-info-from-available-operator-job.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import fs from 'fs';
import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
import { config } from 'dotenv';
import { Environment } from '@holographxyz/environment';
import {
OperatorContract,
Config,
Providers,
DecodedExecuteJobInput,
HolographConfig,
OperatorJob,
decodeAvailableOperatorJobEvent,
decodeExecuteJobInput,
} from '@holographxyz/sdk';
config();
/**
* This script gets all information about a job from a transaction with theAvailableOperatorJob event
*
* Usage:
* 1. set HOLOGRAPH_ENVIRONMENT=mainnet
* 2. set the environmental rpc variables
* 3. create a json file with the following format: {hash: string; chainId: number}[]
* 4. run: `ts-node scripts/find-job-info.ts <JSON_FILE.json>`
*
* Example:
* `ts-node scripts/find-job-info.ts available-operator-job-txs.json
*
*/
type Hex = `0x${string}`;
type AvailableJobInfo = {
jobHash: Hex;
executeJobInput?: DecodedExecuteJobInput;
jobDetails: OperatorJob;
tx: Hex;
chainId: number;
timestamp: string;
from: Hex;
to?: Hex;
contractAddress?: Hex;
};
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,
};
async function main() {
const args = yargs(hideBin(process.argv)).options({
file: {
type: 'string',
describe: 'file path',
usage: 'Usage: ts-node scripts/get-job-info-from-available-operator-job.ts --file [JSON_FILE.json]',
require: true,
},
}).argv;
const { file } = args as {
file: string;
};
let rawData = fs.readFileSync(file);
const availableOperatorJobTxs = JSON.parse(rawData.toString()) as { hash: Hex; chainId: number }[];
const _ = Config.getInstance(protocolConfig);
const providers = new Providers();
const allAvailableJobsInfo: AvailableJobInfo[] = [];
for (const availableOperatorJobTx of availableOperatorJobTxs) {
const { chainId, hash } = availableOperatorJobTx;
const receipt = await providers.getTransactionReceipt(chainId, hash);
const from = receipt.from.toLowerCase() as Hex;
const to = receipt.to?.toLowerCase() as Hex;
const contractAddress = receipt.contractAddress?.toLowerCase() as Hex;
const blockTime = await providers.getLatestBlockTimestamp(chainId);
const operatorJobPayloadData = decodeAvailableOperatorJobEvent(receipt);
const operatorJobHash = operatorJobPayloadData[0].values[0] as Hex;
const operatorJobPayload = operatorJobPayloadData[0].values[1] as Hex;
const operatorContract = new OperatorContract();
const jobDetails = (await operatorContract.getJobDetails(chainId, operatorJobHash)) as unknown as OperatorJob;
let executeJobInput;
try {
executeJobInput = decodeExecuteJobInput(operatorJobPayload);
} catch (error) {
console.error(`Failed to decode executeJob input for jobHash ${operatorJobHash} on chain ${chainId}`);
}
const availableJobInfo: AvailableJobInfo = {
jobHash: operatorJobHash,
executeJobInput,
jobDetails,
tx: hash,
chainId,
timestamp: new Date(Number(blockTime) * 1000).toUTCString(),
from,
to,
contractAddress,
};
allAvailableJobsInfo.push(availableJobInfo);
//console.log(availableJobInfo)
}
const jsonString = JSON.stringify(allAvailableJobsInfo, (_, value) =>
typeof value === 'bigint' ? value.toString() : value
);
fs.writeFile('./scripts/all-available-jobs-info.json', jsonString, (err) => {
if (err) console.log('Error writing file:', err);
});
}
main().catch(async (e) => {
console.error(e);
process.exit(1);
});