UNPKG

test-pkg-ngn

Version:

A library containing helper functions that facilitate scripting for keepers of the Keep3r Network

35 lines 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.calculateKP3RNetProfitV2 = void 0; const tslib_1 = require("tslib"); const ethers_1 = require("ethers"); const KP3RV2_KEEPER_WORK_EVENT_TOPIC = '0x46f2180879a7123a197cc3828c28955d70d661c70acbdc02450daf5f9a9c1cfa'; /** * @notice Calculates the net profit in KP3R a keeper would get for working a job registered in Keep3rV2. * * @dev This function should only be used for mainnet jobs that pay in KP3R or bonded KP3R. The main use of this * function is to use it after a simulation and before sending the bundles to gauge whether working would be * profitable or not with that priority fee. * * @param txHash Hash of the transaction in which the keeper worked the job. * @param keep3rHelper Instance of the keep3rHelper contract. * @param provider The provider to use to make a call to the keep3rHelper contract. * * @return The net profit for working a job denominated in KP3R. */ const calculateKP3RNetProfitV2 = (txHash, keep3rHelper, provider) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const txReceipt = yield provider.getTransactionReceipt(txHash); const gasPrice = txReceipt.effectiveGasPrice; const gasUsed = txReceipt.gasUsed; const txCostInEth = gasPrice.mul(gasUsed); const txCostInKp3r = yield keep3rHelper.quote(txCostInEth); const tx = txReceipt.logs.find((log) => log.topics[0] === KP3RV2_KEEPER_WORK_EVENT_TOPIC); if (!tx) return console.log('Could not find a matching event. Are you certain this job is registered in Keep3rV2?'); const paymentString = tx.data.substring(0, 66); const parsedPayment = ethers_1.BigNumber.from(paymentString); const netProfit = parsedPayment.sub(txCostInKp3r); return netProfit; }); exports.calculateKP3RNetProfitV2 = calculateKP3RNetProfitV2; //# sourceMappingURL=calculateKP3RNetProfitV2.js.map