UNPKG

@exromany/lido-csm-sdk

Version:

[![GitHub license](https://img.shields.io/github/license/lidofinance/lido-csm-sdk?color=limegreen)](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [![Version npm](https://img.shields.io/npm/v/@lidofinance/lido-csm-sdk?label=version)](h

35 lines 1.55 kB
import { KEY_STATUS } from '../common/index.js'; const MAX_URL_LENGTH = 2048 - 66; // proxy gap const METHOD = '/eth/v1/beacon/states/head/validators'; export const getKeysPerChunk = (url, keyLength = 0) => { const maxKeysQueryLength = MAX_URL_LENGTH - url.length - 4; // '?id='.length return Math.floor((maxKeysQueryLength + 3) / (keyLength + 3)); }; export const getChunks = (arr = [], max) => Array.from({ length: Math.ceil(arr.length / max) }) .fill(null) .map((_, index) => arr.slice(index * max, (index + 1) * max)); export const getClUrls = (keys = [], base) => { const url = `${base}${METHOD}`; const maxKeyPerChunk = getKeysPerChunk(url, keys?.[0]?.length); const chunks = getChunks(keys, maxKeyPerChunk); return chunks.map((keys) => `${url}?id=${keys.join(encodeURIComponent(','))}`); }; export const prepareKey = (key) => ({ validatorIndex: key.index, pubkey: key.validator.pubkey, slashed: key.validator.slashed, status: StatusMap[key.status], activationEpoch: BigInt(key.validator.activation_epoch), }); const StatusMap = { pending_initialized: KEY_STATUS.DEPOSITABLE, pending_queued: KEY_STATUS.ACTIVATION_PENDING, active_ongoing: KEY_STATUS.ACTIVE, active_exiting: KEY_STATUS.EXITING, active_slashed: KEY_STATUS.EXITING, exited_unslashed: KEY_STATUS.WITHDRAWAL_PENDING, exited_slashed: KEY_STATUS.WITHDRAWAL_PENDING, withdrawal_possible: KEY_STATUS.WITHDRAWAL_PENDING, withdrawal_done: KEY_STATUS.WITHDRAWN, }; //# sourceMappingURL=cl-chunks.js.map