@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
54 lines • 2.13 kB
JavaScript
;
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