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

30 lines 1.4 kB
/** * Gets the operator's curve ID that was active at a specific block number. * * This function looks through the historical curve ID changes and finds the most recent * curve ID change that occurred at or before the specified block number. * * @param blockNumber - The block number to find the curve ID for * @param curveIdChanges - Array of historical curve ID changes, should be sorted by block number * @param defaultCurveId - The default curve ID to use if no changes found * @returns The curve ID that was active at the specified block * * @example * ```ts * const curveIdChanges = [ * { curveId: 1n, blockNumber: 100n }, * { curveId: 2n, blockNumber: 200n }, * ]; * * getOperatorCurveIdByBlock(150n, curveIdChanges, 0n); // Returns 1n * getOperatorCurveIdByBlock(250n, curveIdChanges, 0n); // Returns 2n * getOperatorCurveIdByBlock(50n, curveIdChanges, 0n); // Returns 0n (default) * ``` */ export const getOperatorCurveIdByBlock = (blockNumber, curveIdChanges, defaultCurveId) => { // Find the last curve ID change that occurred at or before the given block const curveIdChange = curveIdChanges.findLast((change) => blockNumber >= change.blockNumber); // Return the found curve ID, or the provided default if no changes occurred before this block return curveIdChange?.curveId ?? defaultCurveId; }; //# sourceMappingURL=get-operator-curve-id.js.map