@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
55 lines • 2.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.findOperatorRewards = void 0;
const types_js_1 = require("./types.js");
const findOperatorRewardsV1 = (nodeOperatorId, report) => {
const threshold = report.threshold;
const operator = report.operators[nodeOperatorId.toString()];
if (!operator)
return {
distributed: 0n,
validatorsCount: 0,
validatorsOverThresholdCount: 0,
threshold,
};
const validators = Object.values(operator.validators);
const overThreshold = validators.filter(({ perf, slashed }) => !slashed && perf.assigned && perf.included / perf.assigned >= threshold);
return {
distributed: BigInt(operator.distributed.toString()),
validatorsCount: validators.length,
validatorsOverThresholdCount: overThreshold.length,
threshold,
};
};
const findOperatorRewardsV2 = (nodeOperatorId, reports) => {
const report = reports.at(-1);
const operator = report?.operators[nodeOperatorId.toString()];
if (!operator)
return {
distributed: 0n,
validatorsCount: 0,
validatorsOverThresholdCount: 0,
threshold: 0,
};
const validators = Object.values(operator.validators);
const overThreshold = validators.filter(({ slashed, performance, threshold }) => !slashed && performance >= threshold);
return {
distributed: BigInt(operator.distributed_rewards.toString()),
validatorsCount: validators.length,
validatorsOverThresholdCount: overThreshold.length,
threshold: 0,
};
};
const findOperatorRewards = (nodeOperatorId, report) => {
if ((0, types_js_1.isRewardsReportV1)(report)) {
return findOperatorRewardsV1(nodeOperatorId, report);
}
else if ((0, types_js_1.isRewardsReportV2)(report)) {
return findOperatorRewardsV2(nodeOperatorId, report);
}
else {
throw new Error('Unknown rewards report version');
}
};
exports.findOperatorRewards = findOperatorRewards;
//# sourceMappingURL=find-operator-rewards.js.map