UNPKG

@morpho-org/midnight-sdk

Version:

Viem-based package for Morpho Midnight that exports protocol utilities, fetch helpers, and Midnight API utilities under a dedicated API subpath.

23 lines (22 loc) • 860 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.requireTreeItem = requireTreeItem; exports.isPowerOfTwo = isPowerOfTwo; exports.nextPowerOfTwo = nextPowerOfTwo; const errors_js_1 = require("../errors.js"); /** @internal Reads a tree item at a required index, rejecting missing entries. */ function requireTreeItem(items, index) { const item = items[index]; if (item == null) { throw new errors_js_1.InvalidTreeError(`Tree item at index "${index}" is missing.`); } return item; } /** @internal Returns whether `value` is a positive power of two. */ function isPowerOfTwo(value) { return value > 0 && (value & (value - 1)) === 0; } /** @internal Returns the smallest power of two greater than or equal to `value`. */ function nextPowerOfTwo(value) { return 2 ** Math.ceil(Math.log2(value)); }