@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
42 lines • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.prepareKey = exports.getClUrls = exports.getChunks = exports.getKeysPerChunk = void 0;
const index_js_1 = require("../common/index.js");
const MAX_URL_LENGTH = 2048 - 66;
const METHOD = '/eth/v1/beacon/states/head/validators';
const getKeysPerChunk = (url, keyLength = 0) => {
const maxKeysQueryLength = MAX_URL_LENGTH - url.length - 4;
return Math.floor((maxKeysQueryLength + 3) / (keyLength + 3));
};
exports.getKeysPerChunk = getKeysPerChunk;
const getChunks = (arr = [], max) => Array.from({ length: Math.ceil(arr.length / max) })
.fill(null)
.map((_, index) => arr.slice(index * max, (index + 1) * max));
exports.getChunks = getChunks;
const getClUrls = (keys = [], base) => {
const url = `${base}${METHOD}`;
const maxKeyPerChunk = (0, exports.getKeysPerChunk)(url, keys?.[0]?.length);
const chunks = (0, exports.getChunks)(keys, maxKeyPerChunk);
return chunks.map((keys) => `${url}?id=${keys.join(encodeURIComponent(','))}`);
};
exports.getClUrls = getClUrls;
const prepareKey = (key) => ({
validatorIndex: key.index,
pubkey: key.validator.pubkey,
slashed: key.validator.slashed,
status: StatusMap[key.status],
activationEpoch: BigInt(key.validator.activation_epoch),
});
exports.prepareKey = prepareKey;
const StatusMap = {
pending_initialized: index_js_1.KEY_STATUS.DEPOSITABLE,
pending_queued: index_js_1.KEY_STATUS.ACTIVATION_PENDING,
active_ongoing: index_js_1.KEY_STATUS.ACTIVE,
active_exiting: index_js_1.KEY_STATUS.EXITING,
active_slashed: index_js_1.KEY_STATUS.EXITING,
exited_unslashed: index_js_1.KEY_STATUS.WITHDRAWAL_PENDING,
exited_slashed: index_js_1.KEY_STATUS.WITHDRAWAL_PENDING,
withdrawal_possible: index_js_1.KEY_STATUS.WITHDRAWAL_PENDING,
withdrawal_done: index_js_1.KEY_STATUS.WITHDRAWN,
};
//# sourceMappingURL=cl-chunks.js.map