@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
50 lines • 1.96 kB
JavaScript
import { isRewardsReportV1, isRewardsReportV2, isRewardsReportV2Array, } from './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, // V2 uses threshold 0
};
};
export const findOperatorRewards = (nodeOperatorId, report) => {
if (isRewardsReportV1(report)) {
return findOperatorRewardsV1(nodeOperatorId, report);
}
else if (isRewardsReportV2(report)) {
return findOperatorRewardsV2(nodeOperatorId, [report]);
}
else if (isRewardsReportV2Array(report)) {
return findOperatorRewardsV2(nodeOperatorId, report);
}
else {
throw new Error('Unknown rewards report version');
}
};
//# sourceMappingURL=find-operator-rewards.js.map