UNPKG

@yfi/keep3r-cli-jobs

Version:
83 lines 4.27 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const cli_utils_1 = require("@keep3r-network/cli-utils"); const eth_sdk_build_1 = require("../../eth-sdk-build"); const metadata_json_1 = __importDefault(require("./metadata.json")); const expectedErrors = ['V2Keep3rJob::work:not-workable', '!authorized', '!healthcheck']; const maxStrategiesPerFork = 5; const getWorkableTxs = async (args) => { const logMetadata = { job: metadata_json_1.default.name, block: args.advancedBlock, logId: cli_utils_1.makeid(5), }; const logConsole = cli_utils_1.prelog(logMetadata); logConsole.log(`Trying to work`); const signer = args.fork.ethersProvider.getSigner(args.keeperAddress); const { harvestJob: job } = eth_sdk_build_1.getMainnetSdk(signer); const strategies = args.retryId ? [args.retryId] : await job.strategies(); logConsole.log(args.retryId ? `Retrying strategy` : `Simulating ${strategies.length} strategies`); const forksToCreate = Math.ceil(strategies.length / maxStrategiesPerFork) - 1; const forks = [args.fork, ...(await cli_utils_1.createForks(forksToCreate, args))]; logConsole.debug(`Created ${forks.length} forks in order to work in parellel`); const workPromises = forks.map(async (fork, forkIndex) => { const signer = fork.ethersProvider.getSigner(args.keeperAddress); const { harvestJob: job, stealthRelayer } = eth_sdk_build_1.getMainnetSdk(signer); const forkStrategies = strategies.slice(forkIndex * maxStrategiesPerFork, forkIndex * maxStrategiesPerFork + maxStrategiesPerFork); for (const [index, strategy] of forkStrategies.entries()) { const strategyIndex = forkIndex * maxStrategiesPerFork + index; const strategyLogId = `${logMetadata.logId}-${cli_utils_1.makeid(5)}`; const strategyConsole = cli_utils_1.prelog(Object.assign(Object.assign({}, logMetadata), { logId: strategyLogId })); if (args.skipIds.includes(strategy)) { strategyConsole.info('Skipping strategy', { strategy }); continue; } const workData = job.interface.encodeFunctionData('work', [strategy]); const stealthHash = cli_utils_1.getStealthHash(); try { await stealthRelayer.callStatic.execute(job.address, workData, stealthHash, args.advancedBlock, { blockTag: args.advancedBlock, }); strategyConsole.log(`Strategy #${strategyIndex} is workable`, { strategy }); const tx = await stealthRelayer.populateTransaction.execute(job.address, workData, stealthHash, args.targetBlock + index, { nonce: args.keeperNonce, gasLimit: 5000000, type: 2, }); const workableGroups = new Array(args.bundleBurst).fill(null).map((_, index) => ({ targetBlock: args.targetBlock + index, txs: [tx], logId: `${strategyLogId}-${cli_utils_1.makeid(5)}`, })); args.subject.next({ workableGroups, correlationId: strategy, }); } catch (err) { const isExpectedError = expectedErrors.find((expectedError) => { var _a; return (_a = err.message) === null || _a === void 0 ? void 0 : _a.includes(expectedError); }); if (!isExpectedError) { strategyConsole.warn(`Strategy #${strategyIndex} failed with unknown error`, { strategy, message: err.message, }); } else { strategyConsole.log(`Strategy #${strategyIndex} is not workable`, { strategy }); } } } }); await Promise.all(workPromises); args.subject.complete(); }; module.exports = { getWorkableTxs, }; //# sourceMappingURL=job.js.map