@yfi/keep3r-cli-jobs
Version:
Yearn Keep3r CLI Jobs
70 lines • 3 kB
JavaScript
;
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'];
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 { tendJob: 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`);
for (const [index, strategy] of strategies.entries()) {
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;
}
try {
await job.callStatic.work(strategy, {
blockTag: args.advancedBlock,
});
strategyConsole.log(`Strategy #${index} is workable`, { strategy });
const tx = await job.populateTransaction.work(strategy, {
nonce: args.keeperNonce,
gasLimit: 1000000,
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 #${index} failed with unknown error`, {
strategy,
message: err.message,
});
}
else {
strategyConsole.log(`Strategy #${index} is not workable`, { strategy });
}
}
}
args.subject.complete();
};
module.exports = {
getWorkableTxs,
};
//# sourceMappingURL=job.js.map