UNPKG

@exromany/lido-csm-sdk

Version:

[![GitHub license](https://img.shields.io/github/license/lidofinance/lido-csm-sdk?color=limegreen)](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [![Version npm](https://img.shields.io/npm/v/@lidofinance/lido-csm-sdk?label=version)](h

54 lines 2.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findOperatorRewards = void 0; const parse_report_js_1 = require("./parse-report.js"); const EMPTY_REWARDS = { shares: 0n, validatorsCount: 0, validatorsOverThresholdCount: 0, threshold: 0, }; const findOperatorRewardsV1 = (nodeOperatorId, report) => { const threshold = report.threshold; const operator = report.operators[`${nodeOperatorId}`]; if (!operator) return { ...EMPTY_REWARDS, threshold }; const validators = Object.values(operator.validators); const overThreshold = validators.filter(({ perf, slashed }) => !slashed && perf.assigned && perf.included / perf.assigned >= threshold); return { shares: operator.distributed, validatorsCount: validators.length, validatorsOverThresholdCount: overThreshold.length, threshold, }; }; const findOperatorRewardsV2 = (nodeOperatorId, reports) => { const report = reports.at(-1); const operator = report?.operators[`${nodeOperatorId}`]; if (!operator) return EMPTY_REWARDS; const validators = Object.values(operator.validators); const overThreshold = validators.filter(({ slashed, performance, threshold }) => !slashed && performance >= threshold); return { shares: operator.distributed_rewards, validatorsCount: validators.length, validatorsOverThresholdCount: overThreshold.length, threshold: 0, }; }; const findOperatorRewards = (nodeOperatorId, report) => { if ((0, parse_report_js_1.isRewardsReportV1)(report)) { return findOperatorRewardsV1(nodeOperatorId, report); } else if ((0, parse_report_js_1.isRewardsReportV2)(report)) { return findOperatorRewardsV2(nodeOperatorId, [report]); } else if ((0, parse_report_js_1.isRewardsReportV2Array)(report)) { return findOperatorRewardsV2(nodeOperatorId, report); } else { throw new Error('Unknown rewards report version'); } }; exports.findOperatorRewards = findOperatorRewards; //# sourceMappingURL=find-operator-rewards.js.map