@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
83 lines • 3.53 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isRewardsReportV2Array = exports.isRewardsReportV2 = exports.isRewardsReportV1 = exports.parseReport = void 0;
const json_with_bigint_1 = require("json-with-bigint");
const zod_1 = require("zod");
const BlockstampSchema = zod_1.z.object({
block_hash: zod_1.z.string(),
block_number: zod_1.z.coerce.bigint(),
block_timestamp: zod_1.z.number(),
ref_epoch: zod_1.z.coerce.bigint(),
ref_slot: zod_1.z.coerce.bigint(),
slot_number: zod_1.z.coerce.bigint(),
state_root: zod_1.z.string(),
});
const RewardsReportV1Schema = zod_1.z.object({
blockstamp: BlockstampSchema,
distributable: zod_1.z.coerce.bigint(),
frame: zod_1.z.tuple([zod_1.z.number(), zod_1.z.number()]),
threshold: zod_1.z.number(),
operators: zod_1.z.record(zod_1.z.templateLiteral([zod_1.z.bigint()]), zod_1.z.object({
distributed: zod_1.z.coerce.bigint(),
validators: zod_1.z.record(zod_1.z.templateLiteral([zod_1.z.bigint()]), zod_1.z.object({
perf: zod_1.z.object({
assigned: zod_1.z.number(),
included: zod_1.z.number(),
}),
slashed: zod_1.z.boolean(),
})),
})),
});
const RewardsReportV2Schema = zod_1.z.object({
blockstamp: BlockstampSchema,
distributable: zod_1.z.coerce.bigint(),
distributed_rewards: zod_1.z.coerce.bigint(),
rebate_to_protocol: zod_1.z.coerce.bigint(),
frame: zod_1.z.tuple([zod_1.z.number(), zod_1.z.number()]),
operators: zod_1.z.record(zod_1.z.templateLiteral([zod_1.z.bigint()]), zod_1.z.object({
distributed_rewards: zod_1.z.coerce.bigint(),
performance_coefficients: zod_1.z.object({
attestations_weight: zod_1.z.number(),
blocks_weight: zod_1.z.number(),
sync_weight: zod_1.z.number(),
}),
validators: zod_1.z.record(zod_1.z.templateLiteral([zod_1.z.bigint()]), zod_1.z.object({
attestation_duty: zod_1.z.object({
assigned: zod_1.z.number(),
included: zod_1.z.number(),
}),
distributed_rewards: zod_1.z.coerce.bigint(),
performance: zod_1.z.number(),
proposal_duty: zod_1.z.object({
assigned: zod_1.z.number(),
included: zod_1.z.number(),
}),
rewards_share: zod_1.z.number(),
slashed: zod_1.z.boolean(),
strikes: zod_1.z.number(),
sync_duty: zod_1.z.object({ assigned: zod_1.z.number(), included: zod_1.z.number() }),
threshold: zod_1.z.number(),
})),
})),
});
const RewardsReportV2ArraySchema = zod_1.z.array(RewardsReportV2Schema);
const RewardsReportSchema = zod_1.z.union([
RewardsReportV1Schema,
RewardsReportV2Schema,
RewardsReportV2ArraySchema,
]);
const parseReport = (data) => RewardsReportSchema.parse((0, json_with_bigint_1.JSONParse)(data));
exports.parseReport = parseReport;
const isRewardsReportV1 = (report) => {
return RewardsReportV1Schema.safeParse(report).success;
};
exports.isRewardsReportV1 = isRewardsReportV1;
const isRewardsReportV2 = (report) => {
return RewardsReportV2Schema.safeParse(report).success;
};
exports.isRewardsReportV2 = isRewardsReportV2;
const isRewardsReportV2Array = (report) => {
return RewardsReportV2ArraySchema.safeParse(report).success;
};
exports.isRewardsReportV2Array = isRewardsReportV2Array;
//# sourceMappingURL=parse-report.js.map