@metamask-previews/perps-controller 25.0.0-preview-4046c2f69 → 26.0.0-preview-203750488
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +105 -9
- package/dist/PerpsController-method-action-types.d.ts +149 -3
- package/dist/PerpsController-method-action-types.d.ts.map +1 -1
- package/dist/PerpsController-method-action-types.js.map +1 -1
- package/dist/PerpsController.d.ts +125 -3
- package/dist/PerpsController.d.ts.map +1 -1
- package/dist/PerpsController.js +787 -31
- package/dist/PerpsController.js.map +1 -1
- package/dist/constants/eventNames.d.ts +69 -9
- package/dist/constants/eventNames.d.ts.map +1 -1
- package/dist/constants/eventNames.js +82 -11
- package/dist/constants/eventNames.js.map +1 -1
- package/dist/constants/hyperLiquidConfig.d.ts +15 -0
- package/dist/constants/hyperLiquidConfig.d.ts.map +1 -1
- package/dist/constants/hyperLiquidConfig.js +14 -0
- package/dist/constants/hyperLiquidConfig.js.map +1 -1
- package/dist/constants/perpsConfig.d.ts +10 -2
- package/dist/constants/perpsConfig.d.ts.map +1 -1
- package/dist/constants/perpsConfig.js +11 -3
- package/dist/constants/perpsConfig.js.map +1 -1
- package/dist/index.d.ts +10 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/internal/accountReturnOnEquity.d.ts +12 -0
- package/dist/internal/accountReturnOnEquity.d.ts.map +1 -0
- package/dist/internal/accountReturnOnEquity.js +18 -0
- package/dist/internal/accountReturnOnEquity.js.map +1 -0
- package/dist/internal/hyperLiquidHip3Rebalance.d.ts +14 -0
- package/dist/internal/hyperLiquidHip3Rebalance.d.ts.map +1 -0
- package/dist/internal/hyperLiquidHip3Rebalance.js +18 -0
- package/dist/internal/hyperLiquidHip3Rebalance.js.map +1 -0
- package/dist/internal/marketNumericValues.d.ts +10 -0
- package/dist/internal/marketNumericValues.d.ts.map +1 -0
- package/dist/internal/marketNumericValues.js +9 -0
- package/dist/internal/marketNumericValues.js.map +1 -0
- package/dist/internal/perpsDisplaySymbol.d.ts +12 -0
- package/dist/internal/perpsDisplaySymbol.d.ts.map +1 -0
- package/dist/internal/perpsDisplaySymbol.js +21 -0
- package/dist/internal/perpsDisplaySymbol.js.map +1 -0
- package/dist/perpsErrorCodes.d.ts +1 -0
- package/dist/perpsErrorCodes.d.ts.map +1 -1
- package/dist/perpsErrorCodes.js +1 -0
- package/dist/perpsErrorCodes.js.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.ts +47 -1
- package/dist/providers/AggregatedPerpsProvider.d.ts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.js +140 -0
- package/dist/providers/AggregatedPerpsProvider.js.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.ts +72 -4
- package/dist/providers/HyperLiquidProvider.d.ts.map +1 -1
- package/dist/providers/HyperLiquidProvider.js +751 -159
- package/dist/providers/HyperLiquidProvider.js.map +1 -1
- package/dist/providers/LighterProvider.d.ts +2 -1
- package/dist/providers/LighterProvider.d.ts.map +1 -1
- package/dist/providers/LighterProvider.js +11 -6
- package/dist/providers/LighterProvider.js.map +1 -1
- package/dist/selectors.d.ts +15 -5
- package/dist/selectors.d.ts.map +1 -1
- package/dist/selectors.js +23 -5
- package/dist/selectors.js.map +1 -1
- package/dist/services/AggregatedOrderBookConnection.d.ts.map +1 -1
- package/dist/services/AggregatedOrderBookConnection.js +8 -10
- package/dist/services/AggregatedOrderBookConnection.js.map +1 -1
- package/dist/services/HyperLiquidClientService.d.ts +8 -0
- package/dist/services/HyperLiquidClientService.d.ts.map +1 -1
- package/dist/services/HyperLiquidClientService.js +65 -0
- package/dist/services/HyperLiquidClientService.js.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.ts +30 -1
- package/dist/services/HyperLiquidSubscriptionService.d.ts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.js +117 -30
- package/dist/services/HyperLiquidSubscriptionService.js.map +1 -1
- package/dist/services/MarketDataService.d.ts +20 -3
- package/dist/services/MarketDataService.d.ts.map +1 -1
- package/dist/services/MarketDataService.js +55 -3
- package/dist/services/MarketDataService.js.map +1 -1
- package/dist/services/StreamChannelManager.d.ts +139 -0
- package/dist/services/StreamChannelManager.d.ts.map +1 -0
- package/dist/services/StreamChannelManager.js +475 -0
- package/dist/services/StreamChannelManager.js.map +1 -0
- package/dist/services/TerminalMarketService.d.ts.map +1 -1
- package/dist/services/TerminalMarketService.js +7 -0
- package/dist/services/TerminalMarketService.js.map +1 -1
- package/dist/services/agentSigner.d.ts +8 -0
- package/dist/services/agentSigner.d.ts.map +1 -1
- package/dist/services/agentSigner.js +13 -0
- package/dist/services/agentSigner.js.map +1 -1
- package/dist/types/hyperliquid-types.d.ts +9 -1
- package/dist/types/hyperliquid-types.d.ts.map +1 -1
- package/dist/types/hyperliquid-types.js +10 -0
- package/dist/types/hyperliquid-types.js.map +1 -1
- package/dist/types/index.d.ts +434 -17
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/accountAggregation.d.ts +17 -0
- package/dist/utils/accountAggregation.d.ts.map +1 -1
- package/dist/utils/accountAggregation.js +21 -5
- package/dist/utils/accountAggregation.js.map +1 -1
- package/dist/utils/accountUtils.d.ts +31 -10
- package/dist/utils/accountUtils.d.ts.map +1 -1
- package/dist/utils/accountUtils.js +68 -28
- package/dist/utils/accountUtils.js.map +1 -1
- package/dist/utils/closeCalculations.d.ts +17 -4
- package/dist/utils/closeCalculations.d.ts.map +1 -1
- package/dist/utils/closeCalculations.js +23 -7
- package/dist/utils/closeCalculations.js.map +1 -1
- package/dist/utils/hyperLiquidAdapter.d.ts +10 -1
- package/dist/utils/hyperLiquidAdapter.d.ts.map +1 -1
- package/dist/utils/hyperLiquidAdapter.js +17 -1
- package/dist/utils/hyperLiquidAdapter.js.map +1 -1
- package/dist/utils/hyperLiquidPositionPreview.d.ts +133 -9
- package/dist/utils/hyperLiquidPositionPreview.d.ts.map +1 -1
- package/dist/utils/hyperLiquidPositionPreview.js +264 -29
- package/dist/utils/hyperLiquidPositionPreview.js.map +1 -1
- package/dist/utils/index.d.ts +4 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/lighterAdapter.d.ts.map +1 -1
- package/dist/utils/lighterAdapter.js +46 -9
- package/dist/utils/lighterAdapter.js.map +1 -1
- package/dist/utils/marketDataTransform.d.ts.map +1 -1
- package/dist/utils/marketDataTransform.js +13 -8
- package/dist/utils/marketDataTransform.js.map +1 -1
- package/dist/utils/marketUtils.d.ts +1 -2
- package/dist/utils/marketUtils.d.ts.map +1 -1
- package/dist/utils/marketUtils.js +7 -17
- package/dist/utils/marketUtils.js.map +1 -1
- package/dist/utils/orderBookGrouping.d.ts +35 -5
- package/dist/utils/orderBookGrouping.d.ts.map +1 -1
- package/dist/utils/orderBookGrouping.js +62 -6
- package/dist/utils/orderBookGrouping.js.map +1 -1
- package/dist/utils/perpsClientCopy.d.ts.map +1 -1
- package/dist/utils/perpsClientCopy.js +4 -0
- package/dist/utils/perpsClientCopy.js.map +1 -1
- package/dist/utils/perpsDiskPersistence.d.ts.map +1 -1
- package/dist/utils/perpsDiskPersistence.js +10 -0
- package/dist/utils/perpsDiskPersistence.js.map +1 -1
- package/dist/utils/perpsFormatters.d.ts +31 -0
- package/dist/utils/perpsFormatters.d.ts.map +1 -1
- package/dist/utils/perpsFormatters.js +26 -0
- package/dist/utils/perpsFormatters.js.map +1 -1
- package/dist/utils/priceDeviation.d.ts +9 -6
- package/dist/utils/priceDeviation.d.ts.map +1 -1
- package/dist/utils/priceDeviation.js +17 -26
- package/dist/utils/priceDeviation.js.map +1 -1
- package/dist/utils/sortMarkets.d.ts +13 -5
- package/dist/utils/sortMarkets.d.ts.map +1 -1
- package/dist/utils/sortMarkets.js +60 -38
- package/dist/utils/sortMarkets.js.map +1 -1
- package/docs/architecture.md +54 -24
- package/docs/client-contract.md +52 -27
- package/docs/contracts/events.md +38 -32
- package/docs/contracts/feature-flags.md +4 -4
- package/docs/formatting.md +2 -0
- package/docs/venues/lighter/capabilities.md +18 -15
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perpsFormatters.js","sourceRoot":"","sources":["../../src/utils/perpsFormatters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,eAAe,EACf,uBAAuB,GACxB,MAAM,6BAA6B,CAAC;AAgDrC;;;;GAIG;AACH,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAA6B,CAAC;AAElE,SAAS,kBAAkB,CACzB,OAAiC;IAEjC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,SAAS,GAAG,oBAAoB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACpD,oBAAoB,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;GAGG;AACH,MAAM,mBAAmB,GAAwB;IAC/C,YAAY,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE,CACpC,kBAAkB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;IAC3C,cAAc,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE,CAChD,kBAAkB,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,MAAM,CACpE,KAAK,CACN;CACJ,C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V,MAAM,EAAE,UAAU,GAAG,mBAAmB,EAAE,WAAW,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5E,MAAM,KAAK,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC9C,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACrC,OAAO,eAAe,CAAC,mBAAmB,CAAC;IAC7C,CAAC;IACD,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IACzC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,cAAc,EAAE,CAAC;QAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,OAAO,CAAC,CAAC;QAC9C,SAAS,IAAI,KAAK,GAAG,OAAO,CAAC;QAC7B,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACd,KAAK,CAAC,IAAI,CACR,UAAU,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CACrE,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC;QACrB,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;QACjB,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,EAAE;YACzB,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,QAAQ;YACd,WAAW;SACZ,CAAC,CAAC;AACT,CAAC,CAAC","sourcesContent":["/**\n * Portable perps display formatters.\n *\n * These are the canonical perps display rules, exported from the controller\n * so Mobile, Extension and Terminal format every displayed perps value the\n * same way: price ranges, precision constants, sign and placeholder rules.\n * Each formatter takes one options object (`formatters`, `decimals`, `sign`)\n * and renders the shared placeholder from `PERPS_CONSTANTS` for a missing\n * value.\n *\n * The locale-aware `Intl` formatting comes from the client: pass\n * `createFormatters({ locale })` from `@metamask/client-utils` (built once per\n * locale) as `formatters`. This package does not depend on client-utils; it\n * only needs the `PerpsIntlFormatters` shape. Without `formatters`, an\n * `en-US` fallback keeps the legacy call signatures working.\n */\nimport { BASIS_POINTS_DIVISOR } from '../constants/hyperLiquidConfig.js';\nimport {\n DECIMAL_PRECISION_CONFIG,\n FUNDING_RATE_CONFIG,\n PERPS_CONSTANTS,\n PERPS_DISPLAY_PRECISION,\n} from '../constants/perpsConfig.js';\n\n/**\n * Locale-bound number formatting the perps rules run on. The `Formatters`\n * returned by `createFormatters({ locale })` from `@metamask/client-utils`\n * satisfy it, with a cached `Intl.NumberFormat` per locale and options.\n */\nexport type PerpsIntlFormatters = {\n /** Formats a number with `Intl.NumberFormat` options. */\n formatNumber(value: number, options?: Intl.NumberFormatOptions): string;\n /** Formats a currency amount with `Intl.NumberFormat` options. */\n formatCurrency(\n value: number,\n currency: string,\n options?: Intl.NumberFormatOptions,\n ): string;\n};\n\n/**\n * When a formatter prefixes a sign, using the `Intl.NumberFormat`\n * `signDisplay` names. A value that rounds to zero at the displayed precision\n * counts as zero, so no mode shows `-0.00`.\n *\n * - `auto`: `-` for negative values only.\n * - `always`: `+` for positive values and zero, `-` for negative values.\n * - `exceptZero`: `+` for positive, `-` for negative, nothing for zero.\n * - `never`: no sign.\n */\nexport type PerpsSignDisplay = 'auto' | 'always' | 'exceptZero' | 'never';\n\n/**\n * Options shared by every perps display formatter.\n */\nexport type PerpsDisplayFormatOptions = {\n /**\n * Locale-bound formatters from the client, e.g.\n * `createFormatters({ locale })` from `@metamask/client-utils`, built once\n * per locale. Default: `en-US`.\n */\n formatters?: PerpsIntlFormatters;\n /** Fraction digits to show; pass a `PERPS_DISPLAY_PRECISION` value. */\n decimals?: number;\n /** When to show a sign; each formatter documents its default. */\n sign?: PerpsSignDisplay;\n};\n\ntype StripMode = 'none' | 'fiat' | 'all';\n\n/**\n * `Intl.NumberFormat` cache of the `en-US` fallback, keyed by options.\n * Constructing a formatter costs far more than formatting, so none is built\n * per call. Bounded by the option sets the formatters use.\n */\nconst _fallbackFormatCache = new Map<string, Intl.NumberFormat>();\n\nfunction _getFallbackFormat(\n options: Intl.NumberFormatOptions,\n): Intl.NumberFormat {\n const key = JSON.stringify(options);\n let formatter = _fallbackFormatCache.get(key);\n if (!formatter) {\n formatter = new Intl.NumberFormat('en-US', options);\n _fallbackFormatCache.set(key, formatter);\n }\n return formatter;\n}\n\n/**\n * `en-US` formatters used when the caller passes no `formatters`, so the\n * legacy call signatures keep their output.\n */\nconst _fallbackFormatters: PerpsIntlFormatters = {\n formatNumber: (value, options = {}) =>\n _getFallbackFormat(options).format(value),\n formatCurrency: (value, currency, options = {}) =>\n _getFallbackFormat({ style: 'currency', currency, ...options }).format(\n value,\n ),\n};\n\n/**\n * Parses a displayable number. Missing input (`undefined`, `null`, an empty or\n * non-numeric string, `NaN` or an infinite value) returns `undefined`.\n *\n * @param value - The raw value.\n * @returns The finite number, or `undefined` when the value is missing.\n */\nfunction _parseDisplayNumber(value: unknown): number | undefined {\n let parsed = Number.NaN;\n if (typeof value === 'number') {\n parsed = value;\n } else if (typeof value === 'string') {\n parsed = Number.parseFloat(value);\n }\n return Number.isFinite(parsed) ? parsed : undefined;\n}\n\n/**\n * Returns the sign prefix for a value.\n *\n * @param value - The signed value.\n * @param isZero - Whether the value rounds to zero at the displayed precision.\n * @param sign - The sign display mode.\n * @returns `+`, `-` or an empty string.\n */\nfunction _signPrefix(\n value: number,\n isZero: boolean,\n sign: PerpsSignDisplay,\n): string {\n if (sign === 'never') {\n return '';\n }\n if (isZero) {\n return sign === 'always' ? '+' : '';\n }\n if (value < 0) {\n return '-';\n }\n return sign === 'auto' ? '' : '+';\n}\n\n/**\n * Formats a non-negative number with the locale's separators. Callers that\n * must keep `toFixed` rounding pass a value already rounded with it.\n *\n * @param formatters - Locale-bound formatters.\n * @param value - Non-negative value.\n * @param minimumFractionDigits - Fraction digits always shown.\n * @param maximumFractionDigits - Fraction digits at most shown.\n * @param useGrouping - Whether to group thousands as the locale does.\n * @returns The formatted number.\n */\nfunction _formatDecimal(\n formatters: PerpsIntlFormatters,\n value: number,\n minimumFractionDigits: number,\n maximumFractionDigits: number,\n useGrouping: boolean,\n): string {\n return formatters.formatNumber(value, {\n minimumFractionDigits,\n maximumFractionDigits,\n // Omitted keeps the locale's own grouping rule (es: \"1234,5\", \"12.345,7\")\n ...(useGrouping ? {} : { useGrouping: false }),\n });\n}\n\n/**\n * The magnitude of `value` rounded with `toFixed`, as the decimal formatters\n * (size, percentage, funding) display it.\n *\n * @param value - The signed value.\n * @param decimals - Fraction digits shown.\n * @returns The rounded non-negative value.\n */\nfunction _roundedMagnitude(value: number, decimals: number): number {\n return Number(Math.abs(value).toFixed(decimals));\n}\n\n/**\n * Formats a signed number with `toFixed` rounding and the locale's\n * separators. A value that rounds to zero is zero for the sign.\n *\n * @param formatters - Locale-bound formatters.\n * @param value - The signed value.\n * @param options - Formatting options.\n * @param options.minimumFractionDigits - Fraction digits always shown.\n * @param options.maximumFractionDigits - Fraction digits at most shown.\n * @param options.useGrouping - Whether to group thousands as the locale does.\n * @param options.sign - The sign display mode.\n * @returns The sign prefix and formatted magnitude.\n */\nfunction _formatSignedDecimal(\n formatters: PerpsIntlFormatters,\n value: number,\n options: {\n minimumFractionDigits: number;\n maximumFractionDigits: number;\n useGrouping: boolean;\n sign: PerpsSignDisplay;\n },\n): string {\n const rounded = _roundedMagnitude(value, options.maximumFractionDigits);\n return `${_signPrefix(value, rounded === 0, options.sign)}${_formatDecimal(\n formatters,\n rounded,\n options.minimumFractionDigits,\n options.maximumFractionDigits,\n options.useGrouping,\n )}`;\n}\n\n/**\n * Whether a currency amount shows as zero at `decimals`, with the half away\n * from zero rounding `Intl` applies.\n *\n * @param amount - Non-negative amount.\n * @param decimals - Fraction digits shown.\n * @returns True when the displayed amount is zero.\n */\nfunction _currencyShowsZero(amount: number, decimals: number): boolean {\n return Math.round(amount * 10 ** decimals) === 0;\n}\n\n/**\n * Whether `amount` rounded to `maximumFractionDigits` has an all-zero\n * fraction, decided without an `Intl` call.\n *\n * `Intl.NumberFormat` rounds the shortest decimal form of a number\n * (`String(amount)`) half away from zero, so this reads that form's digits as\n * text: exact for any magnitude, including exponent forms such as `1.5e+21`\n * and `5e-7`.\n *\n * @param amount - Non-negative amount.\n * @param maximumFractionDigits - Fraction digits the amount is rounded to.\n * @returns True when the rounded amount is a whole number.\n */\nfunction _roundsToWhole(\n amount: number,\n maximumFractionDigits: number,\n): boolean {\n const [mantissa, exponentText = '0'] = String(amount).split('e');\n const [integerPart, fractionPart = ''] = mantissa.split('.');\n // Fraction digits once the exponent is applied\n const shift = Number(exponentText);\n // An exponent form has one integer digit: \"1.23e-7\" → \"000000123\"\n const fraction =\n shift >= 0\n ? fractionPart.slice(shift)\n : `${'0'.repeat(-shift - 1)}${integerPart}${fractionPart}`;\n const kept = fraction.slice(0, maximumFractionDigits);\n const roundsUp = (fraction[maximumFractionDigits] ?? '0') >= '5';\n return roundsUp ? /^9*$/u.test(kept) : /^0*$/u.test(kept);\n}\n\n/**\n * Formats a non-negative currency amount, stripping trailing fraction zeros.\n *\n * Stripping is done through the fraction-digit options, so the amount is\n * formatted once. This works for any decimal separator or digit set and does\n * not rely on `formatToParts`, which some Hermes builds return as one literal\n * part.\n *\n * @param formatters - Locale-bound formatters.\n * @param amount - Non-negative amount.\n * @param options - Formatting options.\n * @param options.currency - ISO 4217 currency code.\n * @param options.minimumFractionDigits - Minimum decimal digits.\n * @param options.maximumFractionDigits - Maximum decimal digits.\n * @param options.strip - `fiat` drops an all-zero two-digit fraction (`.00`),\n * `all` drops every trailing fraction zero, `none` keeps them.\n * @param options.symbol - `false` formats the number without the currency\n * symbol, for chart labels (default `true`).\n * @returns Formatted currency string.\n */\nfunction _formatCurrency(\n formatters: PerpsIntlFormatters,\n amount: number,\n options: {\n currency: string;\n minimumFractionDigits: number;\n maximumFractionDigits: number;\n strip: StripMode;\n symbol?: boolean;\n },\n): string {\n let { minimumFractionDigits, maximumFractionDigits } = options;\n if (options.strip === 'all') {\n // Intl drops trailing fraction zeros down to the minimum\n minimumFractionDigits = 0;\n } else if (options.strip === 'fiat' && minimumFractionDigits === 2) {\n if (_roundsToWhole(amount, maximumFractionDigits)) {\n // Fiat-style: only an all-zero \".00\" fraction is dropped\n minimumFractionDigits = 0;\n maximumFractionDigits = 0;\n }\n }\n\n if (options.symbol === false) {\n return formatters.formatNumber(amount, {\n minimumFractionDigits,\n maximumFractionDigits,\n });\n }\n return formatters.formatCurrency(amount, options.currency, {\n currencyDisplay: 'narrowSymbol',\n minimumFractionDigits,\n maximumFractionDigits,\n });\n}\n\n/**\n * Formats a non-negative USD amount with fixed decimals and appends a\n * magnitude suffix (`K`, `M`, `B`, `T`) right after the number, wherever the\n * locale puts the currency symbol: `$1.23M`, `1,23M $`.\n *\n * The suffix is placed by finding the formatted number in the currency\n * output, not through `formatToParts` or `notation: 'compact'`, which Hermes\n * does not reliably support.\n *\n * @param formatters - Locale-bound formatters.\n * @param amount - Non-negative amount, already divided by the scale.\n * @param options - Formatting options.\n * @param options.decimals - Fraction digits always shown.\n * @param options.suffix - Magnitude suffix, or an empty string.\n * @param options.symbol - `false` formats without the currency symbol.\n * @returns The formatted amount.\n */\nfunction _formatScaledUsd(\n formatters: PerpsIntlFormatters,\n amount: number,\n options: { decimals: number; suffix: string; symbol: boolean },\n): string {\n const { decimals, suffix, symbol } = options;\n if (!symbol) {\n return `${_formatDecimal(formatters, amount, decimals, decimals, true)}${suffix}`;\n }\n const money = _formatCurrency(formatters, amount, {\n currency: 'USD',\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n strip: 'none',\n });\n if (!suffix) {\n return money;\n }\n const number = _formatDecimal(formatters, amount, decimals, decimals, true);\n const index = money.indexOf(number);\n if (index === -1) {\n return `${money}${suffix}`;\n }\n const end = index + number.length;\n return `${money.slice(0, end)}${suffix}${money.slice(end)}`;\n}\n\n/**\n * Price threshold constants for PRICE_RANGES_UNIVERSAL\n * These define the boundaries between different formatting ranges\n */\nexport const PRICE_THRESHOLD = {\n /** Very high values boundary (> $100k) */\n VERY_HIGH: 100_000,\n /** High values boundary (> $10k) */\n HIGH: 10_000,\n /** Large values boundary (> $1k) */\n LARGE: 1_000,\n /** Medium values boundary (> $100) */\n MEDIUM: 100,\n /** Medium-low values boundary (> $10) */\n MEDIUM_LOW: 10,\n /** Low values boundary (>= $0.01) */\n LOW: 0.01,\n /**\n * Very small values threshold (< $0.01).\n * A non-zero value below this floor renders as `<` plus the formatted\n * threshold (e.g. `<$0` under `PRICE_RANGES_UNIVERSAL`); the floor aligns\n * with the 6-decimal price maximum.\n */\n VERY_SMALL: 0.000001,\n} as const;\n\n/**\n * Configuration for a specific number range formatting\n */\nexport type FiatRangeConfig = {\n /**\n * The condition to match for this range (e.g., < 0.0001, < 1, >= 1000)\n * Function should return true if this config should be applied\n */\n condition: (value: number) => boolean;\n /** Minimum decimal places for this range */\n minimumDecimals: number;\n /** Maximum decimal places for this range */\n maximumDecimals: number;\n /** Optional threshold for formatWithThreshold (defaults to the range boundary) */\n threshold?: number;\n /** Optional significant digits for this range (overrides decimal places when set) */\n significantDigits?: number;\n /** Optional custom formatting logic for this range */\n customFormat?: (value: number, locale: string, currency: string) => string;\n /** Optional flag to strip trailing zeros for this range (overrides global stripTrailingZeros option) */\n stripTrailingZeros?: boolean;\n /**\n * Optional flag for fiat-style stripping (only strips .00, preserves meaningful decimals like .10, .40)\n * When true, \"$1,250.00\" → \"$1,250\" but \"$1,250.10\" stays \"$1,250.10\"\n * When false (default), strips all trailing zeros: \"$1,250.10\" → \"$1,250.1\"\n */\n fiatStyleStripping?: boolean;\n};\n\n/**\n * Formats a number to a specific number of significant digits\n * Strips trailing zeros unless minDecimals requires them\n *\n * @param value - The numeric value to format\n * @param significantDigits - Number of significant digits to maintain\n * @param minDecimals - Minimum decimal places to show (may add zeros)\n * @param maxDecimals - Maximum decimal places allowed\n * @returns Formatted number with appropriate precision, trailing zeros removed\n */\nexport function formatWithSignificantDigits(\n value: number,\n significantDigits: number,\n minDecimals?: number,\n maxDecimals?: number,\n): { value: number; decimals: number } {\n // Handle special cases\n if (value === 0) {\n // Return zero with no trailing decimals by default (matches stripTrailingZeros behavior)\n // Can be overridden by explicit minDecimals if needed\n return { value: 0, decimals: minDecimals ?? 0 };\n }\n\n const absValue = Math.abs(value);\n\n // For numbers >= 1, calculate decimals based on magnitude to achieve target significant figures\n // This ensures consistent precision across different price ranges:\n // Examples with 4 significant figures:\n // $123,456.78 → $123,456.78 (≥$1000: 2 decimals minimum, 8 sig figs)\n // $456.12 → $456.12 (≥$10: 2 decimals minimum, 5 sig figs)\n // $56.123 → $56.123 (≥$10: 2 decimals minimum, 5 sig figs)\n // $5.123 → $5.123 ($1-$10: 3 decimals = 4 sig figs)\n // $2.801 → $2.801 ($1-$10: 3 decimals = 4 sig figs)\n // $1.234 → $1.234 ($1-$10: 3 decimals = 4 sig figs)\n if (absValue >= 1) {\n let targetDecimals: number;\n\n // Calculate decimals needed based on integer digits to achieve target significant figures\n // For $38.388 with 5 sig figs: 2 integer digits, need 3 decimals (3,8,3,8,8)\n // For $123.45 with 5 sig figs: 3 integer digits, need 2 decimals (1,2,3,4,5)\n const integerDigits = Math.floor(Math.log10(absValue)) + 1;\n const decimalsNeeded = significantDigits - integerDigits;\n targetDecimals = Math.max(decimalsNeeded, 0); // Can't have negative decimals\n\n // Apply explicit minimum decimals constraint if provided (for special cases)\n if (minDecimals !== undefined && targetDecimals < minDecimals) {\n targetDecimals = minDecimals;\n }\n\n // Apply maximum decimals constraint if specified\n const finalDecimals =\n maxDecimals === undefined\n ? targetDecimals\n : Math.min(targetDecimals, maxDecimals);\n\n // Round to prevent floating-point artifacts (e.g., 2.820000000000003 → 2.82)\n const roundedValue = Number(value.toFixed(finalDecimals));\n\n return {\n value: roundedValue,\n decimals: finalDecimals,\n };\n }\n\n // For numbers < 1, use toPrecision to limit to significantDigits\n // Examples: 0.1234, 0.01234 should show exactly 4 sig figs\n const precisionStr = absValue.toPrecision(significantDigits);\n const precisionNum = parseFloat(precisionStr);\n\n // Convert to string to count actual decimals after trailing zeros are removed\n const valueStr = precisionNum.toString();\n const [, decPart = ''] = valueStr.split('.');\n let actualDecimals = decPart.length;\n\n // Apply min/max decimal constraints\n if (minDecimals !== undefined && actualDecimals < minDecimals) {\n actualDecimals = minDecimals; // Will add zeros if needed\n }\n if (maxDecimals !== undefined && actualDecimals > maxDecimals) {\n actualDecimals = maxDecimals;\n }\n\n // Return the value with sign restored and decimal count\n return {\n value: value < 0 ? -precisionNum : precisionNum,\n decimals: actualDecimals,\n };\n}\n\n/**\n * Minimal view fiat range configuration\n * Uses fiat-style stripping for clean currency display\n * Strips only .00 to avoid partial decimals like $1,250.1\n */\nexport const PRICE_RANGES_MINIMAL_VIEW: FiatRangeConfig[] = [\n {\n // Large values (>= $1000): Strip .00 only ($5,000 not $5,000.00, but $5,000.10 stays)\n condition: (val: number) => Math.abs(val) >= PRICE_THRESHOLD.LARGE,\n minimumDecimals: 2,\n maximumDecimals: 2,\n threshold: PRICE_THRESHOLD.LARGE,\n stripTrailingZeros: true,\n fiatStyleStripping: true,\n },\n {\n // Small values (< $1000): Also use fiat-style stripping ($100 not $100.00, but $13.40 stays)\n condition: () => true,\n minimumDecimals: 2,\n maximumDecimals: 2,\n threshold: PRICE_THRESHOLD.LOW,\n stripTrailingZeros: true,\n fiatStyleStripping: true,\n },\n];\n\n/**\n * Universal price range configuration following comprehensive rules from rules-decimals.md\n *\n * Rules:\n * - Max 6 decimals across all ranges (Hyperliquid limit)\n * - Strip trailing zeros by default\n * - Use |v| (absolute value) for conditions\n *\n * Significant digits by range:\n * - > $100,000: 6 sig digs\n * - $100,000 > x > $0.01: 5 sig digs\n * - < $0.01: 4 sig digs\n *\n * Decimal limits by price range:\n * - |v| > 10,000: min 0, max 0 decimals; 5 sig digs (6 if >100k)\n * - |v| > 1,000: min 0, max 1 decimal; 5 sig digs\n * - |v| > 100: min 0, max 2 decimals; 5 sig digs\n * - |v| > 10: min 0, max 4 decimals; 5 sig digs\n * - |v| ≥ 0.01: 5 sig digs, min 2, max 6 decimals\n * - |v| < 0.01: 4 sig digs, min 2, max 6 decimals\n *\n * Examples:\n * - $123,456.78 → $123,457 (>$10k: 0 decimals, 6 sig figs)\n * - $12,345.67 → $12,346 (>$10k: 0 decimals, 5 sig figs)\n * - $1,234.56 → $1,234.6 ($1k-$10k: 1 decimal, 5 sig figs)\n * - $123.456 → $123.46 ($100-$1k: 2 decimals, 5 sig figs)\n * - $12.34567 → $12.346 ($10-$100: 4 decimals, 5 sig figs)\n * - $1.3445555 → $1.3446 (≥$0.01: 5 sig figs)\n * - $0.333333 → $0.33333 (≥$0.01: 5 sig figs)\n * - $0.004236 → $0.004236 (<$0.01: 4 sig figs, max 6 decimals)\n * - $0.0000006 → <$0 (<$0.01: 4 sig figs; below the $0.000001 floor)\n */\nexport const PRICE_RANGES_UNIVERSAL: FiatRangeConfig[] = [\n {\n // Very high values (> $100,000): No decimals, 6 significant figures\n // Ex: $123,456.78 → $123,457\n condition: (val) => Math.abs(val) > PRICE_THRESHOLD.VERY_HIGH,\n minimumDecimals: 0,\n maximumDecimals: 0,\n significantDigits: 6,\n threshold: PRICE_THRESHOLD.VERY_HIGH,\n },\n {\n // High values ($10,000-$100,000]: No decimals, 5 significant figures\n // Ex: $12,345.67 → $12,346\n condition: (val) => Math.abs(val) > PRICE_THRESHOLD.HIGH,\n minimumDecimals: 0,\n maximumDecimals: 0,\n significantDigits: 5,\n threshold: PRICE_THRESHOLD.HIGH,\n },\n {\n // Large values ($1,000-$10,000]: Max 1 decimal, 5 significant figures\n // Ex: $1,234.56 → $1,234.6\n condition: (val) => Math.abs(val) > PRICE_THRESHOLD.LARGE,\n minimumDecimals: 0,\n maximumDecimals: 1,\n significantDigits: 5,\n threshold: PRICE_THRESHOLD.LARGE,\n },\n {\n // Medium values ($100-$1,000]: Max 2 decimals, 5 significant figures\n // Ex: $123.456 → $123.46\n condition: (val) => Math.abs(val) > PRICE_THRESHOLD.MEDIUM,\n minimumDecimals: 0,\n maximumDecimals: 2,\n significantDigits: 5,\n threshold: PRICE_THRESHOLD.MEDIUM,\n },\n {\n // Medium-low values ($10-$100]: Max 4 decimals, 5 significant figures\n // Ex: $12.34567 → $12.346\n condition: (val) => Math.abs(val) > PRICE_THRESHOLD.MEDIUM_LOW,\n minimumDecimals: 0,\n maximumDecimals: 4,\n significantDigits: 5,\n threshold: PRICE_THRESHOLD.MEDIUM_LOW,\n },\n {\n // Low values ($0.01-$10]: 5 significant figures, min 2 max MAX_PRICE_DECIMALS decimals\n // Ex: $1.3445555 → $1.3446 | $0.333333 → $0.33333\n condition: (val) => Math.abs(val) >= PRICE_THRESHOLD.LOW,\n significantDigits: 5,\n minimumDecimals: 2,\n maximumDecimals: DECIMAL_PRECISION_CONFIG.MaxPriceDecimals,\n threshold: PRICE_THRESHOLD.LOW,\n },\n {\n // Very small values (< $0.01): 4 significant figures, min 2 max MAX_PRICE_DECIMALS decimals\n // Ex: $0.004236 → $0.004236 | $0.0000006 → <$0\n condition: () => true,\n significantDigits: 4,\n minimumDecimals: 2,\n maximumDecimals: DECIMAL_PRECISION_CONFIG.MaxPriceDecimals,\n threshold: PRICE_THRESHOLD.VERY_SMALL,\n },\n];\n\n/**\n * Options for `formatPerpsFiat`.\n */\nexport type PerpsFiatFormatOptions = PerpsDisplayFormatOptions & {\n /** Global minimum decimal places (overrides `decimals` and range configs). */\n minimumDecimals?: number;\n /** Global maximum decimal places (overrides `decimals` and range configs). */\n maximumDecimals?: number;\n /** Global significant digits (overrides decimal settings when set). */\n significantDigits?: number;\n /** Range configurations (default `PRICE_RANGES_MINIMAL_VIEW`). */\n ranges?: FiatRangeConfig[];\n /** ISO 4217 currency code (default `USD`). */\n currency?: string;\n /** Strip trailing zeros; `false` keeps them whatever the range says. */\n stripTrailingZeros?: boolean;\n /**\n * Locale passed to a range's `customFormat` (default `en-US`). The output\n * locale comes from `formatters`.\n */\n locale?: string;\n /**\n * `false` formats the number without the currency symbol, e.g. chart axis\n * and crosshair labels: `87,123` (default `true`).\n */\n symbol?: boolean;\n};\n\n/**\n * Formats a fiat value (balance, price, fee, position value) as currency with\n * decimal places chosen by the matching range.\n *\n * @param balance - Raw numeric value (e.g., 1234.56, not token minimal denomination).\n * @param options - Formatting options.\n * @param options.formatters - Locale-bound formatters, e.g. `createFormatters({ locale: 'de' })` from `@metamask/client-utils` (default `en-US`).\n * @param options.decimals - Fixed decimal places (e.g. `PERPS_DISPLAY_PRECISION.Fee`), overriding the range.\n * @param options.sign - Sign display (default `auto`: `-` for negative values only).\n * @param options.minimumDecimals - Global minimum decimal places (overrides `decimals` and range configs).\n * @param options.maximumDecimals - Global maximum decimal places (overrides `decimals` and range configs).\n * @param options.significantDigits - Global significant digits (overrides decimal settings when set).\n * @param options.ranges - Custom range configurations (defaults to PRICE_RANGES_MINIMAL_VIEW).\n * @param options.currency - Currency code (default: 'USD').\n * @param options.stripTrailingZeros - Strip trailing zeros from output. `false` keeps them; otherwise the range decides (default: strip).\n * @param options.locale - Locale passed to a range's `customFormat` only (default `en-US`).\n * @param options.symbol - `false` omits the currency symbol, for chart labels (default `true`).\n * @returns Formatted currency string, or `PERPS_CONSTANTS.FallbackPriceDisplay`\n * (`$---`) for a missing value (`PERPS_CONSTANTS.FallbackDataDisplay`, `--`,\n * without the symbol).\n * @example\n * formatPerpsFiat(1234.56) => \"$1,234.56\"\n * formatPerpsFiat(1250) => \"$1,250\" // fiat-style stripping of .00\n * formatPerpsFiat(-0.004) => \"-<$0.01\" // below the range threshold\n * formatPerpsFiat(1234.5, { formatters: createFormatters({ locale: 'de' }) }) => \"1.234,50 $\"\n * formatPerpsFiat(12345.67, { ranges: PRICE_RANGES_UNIVERSAL }) => \"$12,346\"\n * formatPerpsFiat(2480.37, { ranges: PRICE_RANGES_UNIVERSAL, symbol: false }) => \"2,480.4\"\n * formatPerpsFiat(undefined) => \"$---\"\n */\nexport const formatPerpsFiat = (\n balance: string | number | null | undefined,\n options?: PerpsFiatFormatOptions,\n): string => {\n const value = _parseDisplayNumber(balance);\n if (value === undefined) {\n // Placeholder for missing values to avoid confusion with actual $0 values\n return options?.symbol === false\n ? PERPS_CONSTANTS.FallbackDataDisplay\n : PERPS_CONSTANTS.FallbackPriceDisplay;\n }\n\n const currency = options?.currency ?? 'USD';\n const ranges = options?.ranges ?? PRICE_RANGES_MINIMAL_VIEW;\n // Find the first matching range configuration\n const rangeConfig = ranges.find((range) => range.condition(value));\n\n const sigDigits =\n options?.significantDigits ?? rangeConfig?.significantDigits;\n if (rangeConfig?.customFormat && !sigDigits) {\n return rangeConfig.customFormat(\n value,\n options?.locale ?? 'en-US',\n currency,\n );\n }\n\n // Strip trailing zeros unless explicitly disabled. Priority: explicit\n // `stripTrailingZeros: false` > range config > option > true.\n let strip: StripMode = 'none';\n if (\n options?.stripTrailingZeros !== false &&\n (rangeConfig?.stripTrailingZeros ?? options?.stripTrailingZeros ?? true)\n ) {\n // Fiat-style only strips .00: \"$1,250.00\" → \"$1,250\", \"$13.40\" stays\n strip = rangeConfig?.fiatStyleStripping ? 'fiat' : 'all';\n }\n\n let minDecimals =\n options?.minimumDecimals ??\n options?.decimals ??\n rangeConfig?.minimumDecimals ??\n 2;\n let maxDecimals =\n options?.maximumDecimals ??\n options?.decimals ??\n rangeConfig?.maximumDecimals ??\n 2;\n let amount = Math.abs(value);\n if (rangeConfig && sigDigits) {\n // Calculate appropriate formatting based on significant digits\n const significant = formatWithSignificantDigits(\n value,\n sigDigits,\n minDecimals,\n maxDecimals,\n );\n amount = Math.abs(significant.value);\n minDecimals = significant.decimals;\n maxDecimals = significant.decimals;\n }\n\n // A non-zero amount below the threshold shows \"<$threshold\"\n const threshold = rangeConfig?.threshold ?? PRICE_THRESHOLD.LOW;\n const isBelowThreshold = amount !== 0 && amount < threshold;\n const body = _formatCurrency(\n options?.formatters ?? _fallbackFormatters,\n isBelowThreshold ? threshold : amount,\n {\n currency,\n minimumFractionDigits: minDecimals,\n maximumFractionDigits: maxDecimals,\n strip,\n symbol: options?.symbol,\n },\n );\n const isZero = !isBelowThreshold && _currencyShowsZero(amount, maxDecimals);\n\n return `${_signPrefix(value, isZero, options?.sign ?? 'auto')}${\n isBelowThreshold ? '<' : ''\n }${body}`;\n};\n\n/**\n * Formats position size with variable decimal precision based on magnitude or asset-specific decimals\n * Removes trailing zeros and never groups thousands.\n *\n * @param size - Raw position size value\n * @param szDecimalsOrOptions - Asset-specific decimal precision from Hyperliquid metadata\n * (e.g., BTC=5, ETH=4, DOGE=1), or options:\n * `decimals` (the same precision), `formatters` (default `en-US`) and `sign` (default `auto`).\n * @returns Format varies by size or uses asset-specific decimals, with trailing zeros removed:\n * If decimals are provided: Uses at most those decimals (e.g., 0.00009 BTC with szDecimals=5 => \"0.00009\")\n * Otherwise falls back to magnitude-based logic:\n * - Size < 0.01: Up to 6 decimals (e.g., \"0.00009\" not \"0.000090\")\n * - Size < 1: Up to 4 decimals (e.g., \"0.0024\" not \"0.002400\")\n * - Size >= 1: Up to 2 decimals (e.g., \"44\" not \"44.00\")\n * A missing value returns `PERPS_CONSTANTS.FallbackDataDisplay` (`--`).\n * @example formatPositionSize(0.00009, 5) => \"0.00009\" (uses szDecimals)\n * @example formatPositionSize(44.00, 1) => \"44\" (uses szDecimals, trailing zeros removed)\n * @example formatPositionSize(0.0024) => \"0.0024\" (no szDecimals, uses magnitude logic)\n * @example formatPositionSize(-1234.5, { decimals: 2, formatters: createFormatters({ locale: 'es' }) }) => \"-1234,5\"\n * @example formatPositionSize(undefined) => \"--\"\n */\nexport const formatPositionSize = (\n size: string | number | null | undefined,\n szDecimalsOrOptions?: number | PerpsDisplayFormatOptions,\n): string => {\n const {\n formatters = _fallbackFormatters,\n decimals,\n sign = 'auto',\n } = typeof szDecimalsOrOptions === 'number'\n ? { decimals: szDecimalsOrOptions }\n : (szDecimalsOrOptions ?? {});\n const value = _parseDisplayNumber(size);\n if (value === undefined) {\n return PERPS_CONSTANTS.FallbackDataDisplay;\n }\n\n const abs = Math.abs(value);\n let maxDecimals = decimals;\n // Fallback: magnitude-based decimal logic for backwards compatibility\n if (maxDecimals === undefined) {\n if (abs < 0.01) {\n maxDecimals = 6;\n } else if (abs < 1) {\n maxDecimals = 4;\n } else {\n maxDecimals = 2;\n }\n }\n return _formatSignedDecimal(formatters, value, {\n minimumFractionDigits: 0,\n maximumFractionDigits: maxDecimals,\n useGrouping: false,\n sign,\n });\n};\n\n/**\n * Formats a PnL (Profit and Loss) value as USD with a sign prefix\n *\n * @param pnl - Raw numeric PnL value (positive for profit, negative for loss)\n * @param options - `formatters` (default `en-US`), `decimals` (default\n * `PERPS_DISPLAY_PRECISION.Pnl`, 2) and `sign` (default `always`).\n * @returns Format: \"+$X,XXX.XX\" or \"-$X,XXX.XX\", or\n * `PERPS_CONSTANTS.FallbackPriceDisplay` (`$---`) for a missing value.\n * @example formatPnl(1234.56) => \"+$1,234.56\"\n * @example formatPnl(-500) => \"-$500.00\"\n * @example formatPnl(0) => \"+$0.00\"\n * @example formatPnl(0, { sign: 'exceptZero' }) => \"$0.00\"\n * @example formatPnl(1234.5, { formatters: createFormatters({ locale: 'es' }) }) => \"+1234,50 $\"\n * @example formatPnl(undefined) => \"$---\"\n */\nexport const formatPnl = (\n pnl: string | number | null | undefined,\n options: PerpsDisplayFormatOptions = {},\n): string => {\n const {\n formatters = _fallbackFormatters,\n decimals = PERPS_DISPLAY_PRECISION.Pnl,\n sign = 'always',\n } = options;\n const value = _parseDisplayNumber(pnl);\n if (value === undefined) {\n return PERPS_CONSTANTS.FallbackPriceDisplay;\n }\n\n const amount = Math.abs(value);\n const formatted = _formatCurrency(formatters, amount, {\n currency: 'USD',\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n strip: 'none',\n });\n return `${_signPrefix(value, _currencyShowsZero(amount, decimals), sign)}${formatted}`;\n};\n\n/**\n * Options for `formatPercentage`.\n */\nexport type PerpsPercentageFormatOptions = PerpsDisplayFormatOptions & {\n /**\n * Drop trailing fraction zeros, showing at most `decimals`: TWAP progress\n * `25%`, `33.33%` (default `false`: always `decimals`).\n */\n stripTrailingZeros?: boolean;\n};\n\n/**\n * Formats a percentage value (change, RoE, fee rate, slippage) with a sign\n * prefix and locale separators. Pick the precision from\n * `PERPS_DISPLAY_PRECISION`.\n *\n * @param value - Raw percentage value (e.g., 5.25 for 5.25%, not 0.0525)\n * @param decimalsOrOptions - Decimal places (default:\n * `PERPS_DISPLAY_PRECISION.Percentage`, 2), or options: `decimals`,\n * `formatters` (default `en-US`), `sign` (default `always`) and\n * `stripTrailingZeros` (default `false`).\n * @returns Format: \"+X.XX%\" or \"-X.XX%\", or\n * `PERPS_CONSTANTS.FallbackPercentageDisplay` (`--%`) for a missing value.\n * @example formatPercentage(5.25) => \"+5.25%\"\n * @example formatPercentage(-2.75) => \"-2.75%\"\n * @example formatPercentage(0) => \"+0.00%\"\n * @example formatPercentage(10.25, { decimals: PERPS_DISPLAY_PRECISION.RoePercent }) => \"+10.3%\"\n * @example formatPercentage(0.0021, { decimals: PERPS_DISPLAY_PRECISION.SlippageEstimatePercent, sign: 'never' }) => \"0.0021%\"\n * @example formatPercentage(-12345.67, { decimals: 1, formatters: createFormatters({ locale: 'es' }) }) => \"-12.345,7%\"\n * @example formatPercentage(25, { decimals: PERPS_DISPLAY_PRECISION.TwapProgressPercent, stripTrailingZeros: true, sign: 'never' }) => \"25%\"\n * @example formatPercentage(undefined) => \"--%\"\n */\nexport const formatPercentage = (\n value: string | number | null | undefined,\n decimalsOrOptions?: number | PerpsPercentageFormatOptions,\n): string => {\n const {\n formatters = _fallbackFormatters,\n decimals = PERPS_DISPLAY_PRECISION.Percentage,\n sign = 'always',\n stripTrailingZeros = false,\n } = typeof decimalsOrOptions === 'number'\n ? { decimals: decimalsOrOptions }\n : (decimalsOrOptions ?? {});\n const parsed = _parseDisplayNumber(value);\n if (parsed === undefined) {\n return PERPS_CONSTANTS.FallbackPercentageDisplay;\n }\n\n return `${_formatSignedDecimal(formatters, parsed, {\n minimumFractionDigits: stripTrailingZeros ? 0 : decimals,\n maximumFractionDigits: decimals,\n useGrouping: true,\n sign,\n })}%`;\n};\n\n/**\n * Formats a 0..1 cross margin ratio (account ratio or cross margin usage)\n * as an unsigned percentage with at most one decimal. A positive value has\n * no `+` prefix and a whole number has no trailing zero.\n *\n * The input is a ratio, not a percentage: `0.174` is `17.4%`. A ratio\n * outside 0..1 still formats, so usage above 100% shows `150%`.\n *\n * @param ratio - The ratio (`0.174` for 17.4%).\n * @param options - `formatters` (default `en-US`), `decimals` (at most,\n * default `PERPS_DISPLAY_PRECISION.CrossMarginRatioPercent`, 1; trailing\n * zeros are dropped) and `sign` (default `auto`: a minus for a negative\n * ratio, no plus).\n * The locale's percent style renders the number and the `%` symbol, so a\n * locale that spaces or prefixes the symbol (`17,4 %`, `%17,4`) does.\n * @returns Format: \"X%\" or \"X.X%\" in `en-US`, or\n * `PERPS_CONSTANTS.FallbackPercentageDisplay` (`--%`) for a missing ratio.\n * @example formatCrossMarginRatio(0.174) => \"17.4%\"\n * @example formatCrossMarginRatio(0.63) => \"63%\"\n * @example formatCrossMarginRatio(0) => \"0%\"\n * @example formatCrossMarginRatio(-0.174) => \"-17.4%\"\n * @example formatCrossMarginRatio(0.0255) => \"2.6%\"\n * @example formatCrossMarginRatio(0.174, { formatters: createFormatters({ locale: 'de' }) }) => \"17,4 %\"\n * @example formatCrossMarginRatio(undefined) => \"--%\"\n */\nexport const formatCrossMarginRatio = (\n ratio: string | number | null | undefined,\n options: PerpsDisplayFormatOptions = {},\n): string => {\n const {\n formatters = _fallbackFormatters,\n decimals = PERPS_DISPLAY_PRECISION.CrossMarginRatioPercent,\n sign = 'auto',\n } = options;\n const parsed = _parseDisplayNumber(ratio);\n if (parsed === undefined) {\n return PERPS_CONSTANTS.FallbackPercentageDisplay;\n }\n\n // The locale's percent style owns the rounding, the `%` symbol and its\n // placement (`17.4%`, `17,4 %`, `%17,4`), so the ratio is passed as is.\n // Shifting it by 100 and rounding with `toFixed` first would round binary\n // ties differently (`0.0255` is `2.6%`, not `2.5%`).\n const percentOptions: Intl.NumberFormatOptions = {\n style: 'percent',\n minimumFractionDigits: 0,\n maximumFractionDigits: decimals,\n };\n const magnitude = Math.abs(parsed);\n // A ratio that rounds to 0 at the shown precision has no sign, so a tiny\n // negative ratio is `0%`, not `-0%`. The threshold is half of the last\n // shown digit, with the half rounded away from zero as `Intl` does.\n // The sign itself is the shared prefix, not the locale's minus glyph.\n const isZero = magnitude < Number(`5e-${decimals + 3}`);\n return `${_signPrefix(parsed, isZero, sign)}${formatters.formatNumber(\n isZero ? 0 : magnitude,\n percentOptions,\n )}`;\n};\n\n/**\n * Options for `formatFundingRate`.\n */\nexport type PerpsFundingRateFormatOptions = PerpsDisplayFormatOptions & {\n /** `false` returns an empty string for a missing rate (default `true`). */\n showZero?: boolean;\n};\n\n/**\n * Formats funding rate for display\n *\n * @param value - Raw funding rate value (decimal, not percentage)\n * @param options - Optional formatting options\n * @param options.showZero - `false` returns an empty string instead of the placeholder for a missing rate (default: true)\n * @param options.formatters - Locale-bound formatters, e.g. `createFormatters({ locale })` from `@metamask/client-utils` (default `en-US`)\n * @param options.decimals - Decimal places (default `PERPS_DISPLAY_PRECISION.FundingRatePercent`, 4)\n * @param options.sign - Sign display (default `auto`: `-` for negative rates only)\n * @returns Formatted funding rate as percentage string, or\n * `PERPS_CONSTANTS.FallbackPercentageDisplay` (`--%`) for a missing rate.\n * @example formatFundingRate(0.0005) => \"0.0500%\"\n * @example formatFundingRate(-0.0001) => \"-0.0100%\"\n * @example formatFundingRate(0.000000059) => \"<0.0001%\"\n * @example formatFundingRate(-0.000000059) => \"-<0.0001%\"\n * @example formatFundingRate(0.0005, { sign: 'always', formatters: createFormatters({ locale: 'es' }) }) => \"+0,0500%\"\n * @example formatFundingRate(undefined) => \"--%\"\n */\nexport const formatFundingRate = (\n value?: string | number | null,\n options: PerpsFundingRateFormatOptions = {},\n): string => {\n const {\n showZero = true,\n formatters = _fallbackFormatters,\n decimals = PERPS_DISPLAY_PRECISION.FundingRatePercent,\n sign = 'auto',\n } = options;\n const rate = _parseDisplayNumber(value);\n if (rate === undefined) {\n return showZero ? PERPS_CONSTANTS.FallbackPercentageDisplay : '';\n }\n\n const percentage = rate * FUNDING_RATE_CONFIG.PercentageMultiplier;\n // A non-zero rate below the display precision shows \"<0.0001%\"\n if (rate !== 0 && _roundedMagnitude(percentage, decimals) === 0) {\n const minimum = _formatDecimal(\n formatters,\n 10 ** -decimals,\n decimals,\n decimals,\n true,\n );\n return `${_signPrefix(rate, false, sign)}<${minimum}%`;\n }\n\n return `${_formatSignedDecimal(formatters, percentage, {\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n useGrouping: true,\n sign,\n })}%`;\n};\n\n/**\n * Funding since open below this magnitude shows as zero: under half a cent.\n */\nconst FUNDING_SINCE_OPEN_ZERO_THRESHOLD = 0.005;\n\n/**\n * A single funding payment below this magnitude shows its sub-cent digits\n * instead of the fiat ranges, which would round it to `<$0.01`.\n */\nconst FUNDING_PAYMENT_CENT_THRESHOLD = 0.01;\n\n/** Most fraction digits of a funding payment below a cent. */\nconst FUNDING_PAYMENT_SUB_CENT_DECIMALS = 6;\n\n/**\n * How funding since open reads for the trader: `cost` (paid), `payment`\n * (received) or `none` (under half a cent, or missing).\n */\nexport type PerpsFundingDirection = 'cost' | 'payment' | 'none';\n\n/**\n * Formats a zero USD amount with two decimals: `$0.00`, `0,00 $`.\n *\n * @param formatters - Locale-bound formatters.\n * @returns The formatted zero.\n */\nfunction _formatZeroUsd(formatters: PerpsIntlFormatters): string {\n return _formatCurrency(formatters, 0, {\n currency: 'USD',\n minimumFractionDigits: 2,\n maximumFractionDigits: 2,\n strip: 'none',\n });\n}\n\n/**\n * Classifies funding since a position opened, with the venue's sign\n * (positive = the trader paid), so clients colour it without copying the\n * half-cent threshold.\n *\n * @param sinceOpen - Funding since open (venue field `cumulativeFunding.sinceOpen`).\n * @returns `cost` from $0.005 up, `payment` from -$0.005 down, `none`\n * otherwise or for a missing value.\n * @example getPositionFundingDirection('1.25') => \"cost\"\n * @example getPositionFundingDirection(-0.8) => \"payment\"\n * @example getPositionFundingDirection(0.004) => \"none\"\n * @example getPositionFundingDirection(undefined) => \"none\"\n */\nexport const getPositionFundingDirection = (\n sinceOpen: string | number | null | undefined,\n): PerpsFundingDirection => {\n const value = _parseDisplayNumber(sinceOpen);\n if (\n value === undefined ||\n Math.abs(value) < FUNDING_SINCE_OPEN_ZERO_THRESHOLD\n ) {\n return 'none';\n }\n return value > 0 ? 'cost' : 'payment';\n};\n\n/**\n * Formats funding since a position opened, as Mobile and Extension show it.\n * The venue reports funding the trader paid as a positive number, so a cost\n * shows with `-` and a payment received with `+`. Under half a cent it shows\n * as zero.\n *\n * @param sinceOpen - Funding since open (venue field `cumulativeFunding.sinceOpen`).\n * @param options - `formatters` (default `en-US`) and `sign` (default\n * `exceptZero`). The amount's precision comes from\n * `PRICE_RANGES_MINIMAL_VIEW`.\n * @returns `-` or `+` with the amount on `PRICE_RANGES_MINIMAL_VIEW`, `$0.00`\n * under half a cent, or `PERPS_CONSTANTS.FallbackPriceDisplay` (`$---`) for a\n * missing value.\n * @example formatPositionFunding('1.2345') => \"-$1.23\"\n * @example formatPositionFunding(-1234.5) => \"+$1,234.50\"\n * @example formatPositionFunding(0.005) => \"-<$0.01\"\n * @example formatPositionFunding(0.0049) => \"$0.00\"\n * @example formatPositionFunding(1234.5, { formatters: createFormatters({ locale: 'de' }) }) => \"-1.234,50 $\"\n * @example formatPositionFunding(-1.2345, { sign: 'never' }) => \"$1.23\"\n * @example formatPositionFunding(undefined) => \"$---\"\n */\nexport const formatPositionFunding = (\n sinceOpen: string | number | null | undefined,\n options: Omit<PerpsDisplayFormatOptions, 'decimals'> = {},\n): string => {\n const { formatters = _fallbackFormatters, sign = 'exceptZero' } = options;\n const value = _parseDisplayNumber(sinceOpen);\n if (value === undefined) {\n return PERPS_CONSTANTS.FallbackPriceDisplay;\n }\n if (getPositionFundingDirection(value) === 'none') {\n return `${_signPrefix(0, true, sign)}${_formatZeroUsd(formatters)}`;\n }\n // A cost (venue-positive) reads as money out: \"-\"\n return `${_signPrefix(-value, false, sign)}${formatPerpsFiat(\n Math.abs(value),\n { ranges: PRICE_RANGES_MINIMAL_VIEW, formatters },\n )}`;\n};\n\n/**\n * Formats a single funding payment (a history row or its detail), with the\n * trader's sign: positive = received. From a cent up it matches Mobile's\n * `formatPerpsFiat`; below a cent it keeps up to 6 fraction digits, trailing\n * zeros dropped and never in exponent notation.\n *\n * @param amount - Funding payment in USD (positive = received).\n * @param options - `formatters` (default `en-US`) and `sign` (default\n * `exceptZero`). The precision is fixed by the rules above.\n * @returns The signed amount, `$0.00` without a sign when it rounds to zero\n * at 6 digits, or `PERPS_CONSTANTS.FallbackPriceDisplay` (`$---`) for a\n * missing value.\n * @example formatFundingPayment(1.234) => \"+$1.23\"\n * @example formatFundingPayment(-12.5) => \"-$12.50\"\n * @example formatFundingPayment(0.003421) => \"+$0.003421\"\n * @example formatFundingPayment(0.0000004) => \"$0.00\"\n * @example formatFundingPayment(0.003421, { formatters: createFormatters({ locale: 'de' }) }) => \"+0,003421 $\"\n * @example formatFundingPayment(undefined) => \"$---\"\n */\nexport const formatFundingPayment = (\n amount: string | number | null | undefined,\n options: Omit<PerpsDisplayFormatOptions, 'decimals'> = {},\n): string => {\n const { formatters = _fallbackFormatters, sign = 'exceptZero' } = options;\n const value = _parseDisplayNumber(amount);\n if (value === undefined) {\n return PERPS_CONSTANTS.FallbackPriceDisplay;\n }\n const magnitude = Math.abs(value);\n if (magnitude >= FUNDING_PAYMENT_CENT_THRESHOLD) {\n return `${_signPrefix(value, false, sign)}${formatPerpsFiat(magnitude, {\n formatters,\n })}`;\n }\n // Below a cent, a value that rounds to zero at 6 digits shows as zero\n if (_roundsToWhole(magnitude, FUNDING_PAYMENT_SUB_CENT_DECIMALS)) {\n return `${_signPrefix(value, true, sign)}${_formatZeroUsd(formatters)}`;\n }\n return `${_signPrefix(value, false, sign)}${_formatCurrency(\n formatters,\n magnitude,\n {\n currency: 'USD',\n minimumFractionDigits: 0,\n maximumFractionDigits: FUNDING_PAYMENT_SUB_CENT_DECIMALS,\n strip: 'all',\n },\n )}`;\n};\n\n/**\n * Formats a fee rate in basis points with the locale's separators.\n *\n * @param rate - Fee rate as a decimal (0.00045 for 0.045%).\n * @param options - `formatters` (default `en-US`), `decimals` (at most,\n * default `PERPS_DISPLAY_PRECISION.FeeBps`, 2; trailing zeros are dropped) and\n * `sign` (default `auto`).\n * @returns Format: \"X.XX bps\", or `PERPS_CONSTANTS.FallbackDataDisplay` (`--`)\n * for a missing rate.\n * @example formatFeeBps(0.00045) => \"4.5 bps\"\n * @example formatFeeBps(0.000144) => \"1.44 bps\"\n * @example formatFeeBps(0.0007) => \"7 bps\"\n * @example formatFeeBps(0.00045, { formatters: createFormatters({ locale: 'de' }) }) => \"4,5 bps\"\n * @example formatFeeBps(undefined) => \"--\"\n */\nexport const formatFeeBps = (\n rate: string | number | null | undefined,\n options: PerpsDisplayFormatOptions = {},\n): string => {\n const {\n formatters = _fallbackFormatters,\n decimals = PERPS_DISPLAY_PRECISION.FeeBps,\n sign = 'auto',\n } = options;\n const parsed = _parseDisplayNumber(rate);\n if (parsed === undefined) {\n return PERPS_CONSTANTS.FallbackDataDisplay;\n }\n\n return `${_formatSignedDecimal(formatters, parsed * BASIS_POINTS_DIVISOR, {\n minimumFractionDigits: 0,\n maximumFractionDigits: decimals,\n useGrouping: true,\n sign,\n })} bps`;\n};\n\n/**\n * Formats how far, in percent of the entry price, the price must move to\n * reach the liquidation price.\n *\n * @param entryPrice - Entry (or mark) price.\n * @param liquidationPrice - Liquidation price.\n * @param options - `formatters` (default `en-US`), `decimals` (default\n * `PERPS_DISPLAY_PRECISION.LiquidationDistancePercent`, 2) and `sign`\n * (default `never`).\n * @returns Format: \"X.XX%\", or `PERPS_CONSTANTS.FallbackPercentageDisplay`\n * (`--%`) when either price is missing or not positive.\n * @example formatLiquidationDistance(100, 70) => \"30.00%\"\n * @example formatLiquidationDistance(100, '130') => \"30.00%\"\n * @example formatLiquidationDistance(100, 70, { formatters: createFormatters({ locale: 'de' }) }) => \"30,00%\"\n * @example formatLiquidationDistance(100, undefined) => \"--%\"\n */\nexport const formatLiquidationDistance = (\n entryPrice: string | number | null | undefined,\n liquidationPrice: string | number | null | undefined,\n options: PerpsDisplayFormatOptions = {},\n): string => {\n const entry = _parseDisplayNumber(entryPrice);\n const liquidation = _parseDisplayNumber(liquidationPrice);\n if (\n entry === undefined ||\n liquidation === undefined ||\n entry <= 0 ||\n liquidation <= 0\n ) {\n return PERPS_CONSTANTS.FallbackPercentageDisplay;\n }\n\n return formatPercentage((Math.abs(entry - liquidation) / entry) * 100, {\n formatters: options.formatters,\n decimals:\n options.decimals ?? PERPS_DISPLAY_PRECISION.LiquidationDistancePercent,\n sign: options.sign ?? 'never',\n });\n};\n\n/** Each magnitude scale is this many times the next smaller one. */\nconst SCALE_STEP = 1000;\n\n/** Magnitude scales of compact values, largest first. */\nconst COMPACT_SCALES = [\n { divisor: 1_000_000_000_000, suffix: 'T' },\n { divisor: 1_000_000_000, suffix: 'B' },\n { divisor: 1_000_000, suffix: 'M' },\n { divisor: SCALE_STEP, suffix: 'K' },\n { divisor: 1, suffix: '' },\n] as const;\n\n/**\n * Picks the magnitude scale of a non-negative amount and rounds it. A\n * mantissa that rounds up to 1000 moves to the next scale, so 999999 shows as\n * `1.00M`, not `1000K`.\n *\n * @param amount - Non-negative amount.\n * @param decimalsFor - Fraction digits shown at a scale divisor.\n * @returns The rounded mantissa, its decimals and suffix.\n */\nfunction _scaleCompact(\n amount: number,\n decimalsFor: (divisor: number) => number,\n): { mantissa: number; decimals: number; suffix: string } {\n let index = COMPACT_SCALES.findIndex(({ divisor }) => amount >= divisor);\n if (index === -1) {\n index = COMPACT_SCALES.length - 1;\n }\n for (;;) {\n const { divisor, suffix } = COMPACT_SCALES[index];\n const decimals = decimalsFor(divisor);\n const mantissa = _roundedMagnitude(amount / divisor, decimals);\n if (mantissa < SCALE_STEP || index === 0) {\n return { mantissa, decimals, suffix };\n }\n index -= 1;\n }\n}\n\n/**\n * The value a compact number stands for, which sets its unit and precision.\n *\n * - `volume`: USD volume or open interest: `$1.23M`, `$123K`, `$999.50`.\n * - `orderBookUsd`: USD order book size or total: `$2.1K` from 1,000 up,\n * `PRICE_RANGES_UNIVERSAL` below.\n * - `orderBookSize`: base-asset order book size or total: `604.9K` from 1,000\n * up, `formatPositionSize` with `szDecimals` below.\n */\nexport type PerpsCompactField = 'volume' | 'orderBookUsd' | 'orderBookSize';\n\n/**\n * Options for `formatPerpsCompact`.\n */\nexport type PerpsCompactFormatOptions = PerpsDisplayFormatOptions & {\n /** The value being shown, which sets the unit and precision. */\n field: PerpsCompactField;\n /** Asset size decimals for an `orderBookSize` value below 1,000. */\n szDecimals?: number;\n};\n\n/**\n * Formats a large number with a magnitude suffix (`K`, `M`, `B`, `T`), with\n * the unit and precision of the field it shows.\n *\n * @param value - Raw value (USD for `volume` and `orderBookUsd`, base asset\n * for `orderBookSize`).\n * @param options - Formatting options.\n * @param options.field - `volume`, `orderBookUsd` or `orderBookSize`.\n * @param options.formatters - Locale-bound formatters, e.g. `createFormatters({ locale })` from `@metamask/client-utils` (default `en-US`).\n * @param options.decimals - Decimals of abbreviated values, overriding the\n * field's `PERPS_DISPLAY_PRECISION` (`VolumeCompact`, `VolumeCompactThousands`\n * or `OrderBookCompact`).\n * @param options.sign - Sign display (default `auto`).\n * @param options.szDecimals - Asset size decimals for an `orderBookSize` value below 1,000.\n * @returns The compact value, or `PERPS_CONSTANTS.FallbackPriceDisplay`\n * (`$---`, `--` for `orderBookSize`) for a missing value.\n * @example formatPerpsCompact(1234567, { field: 'volume' }) => \"$1.23M\"\n * @example formatPerpsCompact(123456, { field: 'volume' }) => \"$123K\"\n * @example formatPerpsCompact(999.5, { field: 'volume' }) => \"$999.50\"\n * @example formatPerpsCompact(1234567, { field: 'volume', formatters: createFormatters({ locale: 'de' }) }) => \"1,23M $\"\n * @example formatPerpsCompact(2100, { field: 'orderBookUsd' }) => \"$2.1K\"\n * @example formatPerpsCompact(604900, { field: 'orderBookSize' }) => \"604.9K\"\n */\nexport const formatPerpsCompact = (\n value: string | number | null | undefined,\n options: PerpsCompactFormatOptions,\n): string => {\n const {\n field,\n formatters = _fallbackFormatters,\n decimals,\n sign = 'auto',\n szDecimals,\n } = options;\n const isUsd = field !== 'orderBookSize';\n const parsed = _parseDisplayNumber(value);\n if (parsed === undefined) {\n return isUsd\n ? PERPS_CONSTANTS.FallbackPriceDisplay\n : PERPS_CONSTANTS.FallbackDataDisplay;\n }\n\n const amount = Math.abs(parsed);\n if (field !== 'volume' && amount < SCALE_STEP) {\n return field === 'orderBookUsd'\n ? formatPerpsFiat(parsed, {\n ranges: PRICE_RANGES_UNIVERSAL,\n formatters,\n sign,\n })\n : formatPositionSize(parsed, { decimals: szDecimals, formatters, sign });\n }\n\n const scaled = _scaleCompact(amount, (divisor) => {\n if (decimals !== undefined) {\n return decimals;\n }\n if (field !== 'volume') {\n return PERPS_DISPLAY_PRECISION.OrderBookCompact;\n }\n return divisor === SCALE_STEP\n ? PERPS_DISPLAY_PRECISION.VolumeCompactThousands\n : PERPS_DISPLAY_PRECISION.VolumeCompact;\n });\n return `${_signPrefix(parsed, scaled.mantissa === 0, sign)}${_formatScaledUsd(\n formatters,\n scaled.mantissa,\n { decimals: scaled.decimals, suffix: scaled.suffix, symbol: isUsd },\n )}`;\n};\n\n/**\n * How every price of an order book ladder renders: divided by `divisor`, with\n * `decimals` fixed decimals and `suffix` after the number.\n */\nexport type PerpsOrderBookPriceFormat = {\n /** Value each price is divided by before formatting. */\n divisor: number;\n /** Magnitude suffix appended after the number, or an empty string. */\n suffix: string;\n /** Fixed decimals shown after dividing. */\n decimals: number;\n};\n\n/**\n * Options for `getPerpsOrderBookPriceFormat`.\n */\nexport type PerpsOrderBookLadderOptions = {\n /** Ladder mid price, which sets the magnitude of an abbreviation. */\n midPrice?: number | null;\n /** Asset size decimals from the market metadata. */\n szDecimals?: number;\n};\n\n/**\n * Exact decimal places of a number, read from its exponential form so values\n * such as `1e-7` and `0.002` do not depend on a rounded `Math.log10`.\n *\n * @param value - The number.\n * @returns Its decimal places.\n */\nfunction _countDecimalPlaces(value: number): number {\n const [mantissa, exponent] = Math.abs(value).toExponential().split('e');\n return Math.max(0, (mantissa.split('.')[1] ?? '').length - Number(exponent));\n}\n\n/**\n * Options for `formatPerpsOrderBookPrice`.\n */\nexport type PerpsOrderBookPriceFormatOptions = {\n /**\n * Locale-bound formatters, e.g. `createFormatters({ locale })` from\n * `@metamask/client-utils`. Default: `en-US`.\n */\n formatters?: PerpsIntlFormatters;\n /** `false` omits the currency symbol (default `true`). */\n symbol?: boolean;\n};\n\n/**\n * Formats an order book price with the ladder format from\n * `getPerpsOrderBookPriceFormat`, keeping trailing zeros so every row has the\n * same width.\n *\n * @param price - Raw price.\n * @param format - Ladder format, or null for `PRICE_RANGES_UNIVERSAL`.\n * @param options - `formatters` (default `en-US`) and `symbol` (default `true`).\n * @returns The price, or `PERPS_CONSTANTS.FallbackPriceDisplay` (`$---`; `--`\n * without the symbol) for a missing price.\n * @example formatPerpsOrderBookPrice(87000, { divisor: 1000, suffix: 'K', decimals: 0 }) => \"$87K\"\n * @example formatPerpsOrderBookPrice(33.1, { divisor: 1, suffix: '', decimals: 3 }) => \"$33.100\"\n * @example formatPerpsOrderBookPrice(87000, { divisor: 1, suffix: '', decimals: 0 }, { symbol: false }) => \"87,000\"\n */\nexport const formatPerpsOrderBookPrice = (\n price: string | number | null | undefined,\n format: PerpsOrderBookPriceFormat | null,\n options: PerpsOrderBookPriceFormatOptions = {},\n): string => {\n const { formatters = _fallbackFormatters, symbol = true } = options;\n const value = _parseDisplayNumber(price);\n if (value === undefined) {\n return symbol\n ? PERPS_CONSTANTS.FallbackPriceDisplay\n : PERPS_CONSTANTS.FallbackDataDisplay;\n }\n if (format === null) {\n return formatPerpsFiat(value, {\n ranges: PRICE_RANGES_UNIVERSAL,\n formatters,\n symbol,\n });\n }\n\n const amount = Math.abs(value) / format.divisor;\n return `${_signPrefix(\n value,\n _currencyShowsZero(amount, format.decimals),\n 'auto',\n )}${_formatScaledUsd(formatters, amount, {\n decimals: format.decimals,\n suffix: format.suffix,\n symbol,\n })}`;\n};\n\n/**\n * Resolves the one price format an order book ladder renders with, from the\n * selected price grouping (tick) increment.\n *\n * Decimals match the grouping, capped at the asset's price precision\n * (`PERPS_DISPLAY_PRECISION.MaxPriceDecimals − szDecimals`), so neighbouring\n * levels never collapse into the same string and every row has the same\n * width. The ladder is abbreviated (`$87K`) at the magnitude of `midPrice`\n * only when that needs at most\n * `PERPS_DISPLAY_PRECISION.OrderBookAbbreviatedPriceMax` decimals and is no\n * longer than the plain form.\n *\n * @param grouping - Selected price grouping increment, or null when unknown.\n * @param options - Ladder context.\n * @param options.midPrice - Ladder mid price, which sets the magnitude.\n * @param options.szDecimals - Asset size decimals from the market metadata.\n * @returns The ladder format, or null to use `PRICE_RANGES_UNIVERSAL`.\n * @example getPerpsOrderBookPriceFormat(1000, { midPrice: 87000, szDecimals: 5 }) => { divisor: 1000, suffix: 'K', decimals: 0 }\n * @example getPerpsOrderBookPriceFormat(1, { midPrice: 87000, szDecimals: 5 }) => { divisor: 1, suffix: '', decimals: 0 }\n * @example getPerpsOrderBookPriceFormat(0.001, { midPrice: 33.1, szDecimals: 2 }) => { divisor: 1, suffix: '', decimals: 3 }\n */\nexport const getPerpsOrderBookPriceFormat = (\n grouping: number | null | undefined,\n options: PerpsOrderBookLadderOptions = {},\n): PerpsOrderBookPriceFormat | null => {\n const { midPrice, szDecimals } = options;\n if (\n typeof grouping !== 'number' ||\n !Number.isFinite(grouping) ||\n grouping <= 0\n ) {\n return null;\n }\n\n const maxDecimals =\n typeof szDecimals === 'number' && Number.isFinite(szDecimals)\n ? Math.max(0, PERPS_DISPLAY_PRECISION.MaxPriceDecimals - szDecimals)\n : PERPS_DISPLAY_PRECISION.MaxPriceDecimals;\n const plain: PerpsOrderBookPriceFormat = {\n divisor: 1,\n suffix: '',\n decimals: Math.min(_countDecimalPlaces(grouping), maxDecimals),\n };\n if (typeof midPrice !== 'number' || !Number.isFinite(midPrice)) {\n return plain;\n }\n\n const magnitude = Math.abs(midPrice);\n const scale = COMPACT_SCALES.find(\n ({ divisor }) =>\n divisor > 1 && magnitude >= divisor && magnitude < divisor * SCALE_STEP,\n );\n if (!scale) {\n return plain;\n }\n const decimals = _countDecimalPlaces(grouping / scale.divisor);\n if (decimals > PERPS_DISPLAY_PRECISION.OrderBookAbbreviatedPriceMax) {\n return plain;\n }\n\n const abbreviated: PerpsOrderBookPriceFormat = {\n divisor: scale.divisor,\n suffix: scale.suffix,\n decimals,\n };\n return formatPerpsOrderBookPrice(midPrice, abbreviated).length <=\n formatPerpsOrderBookPrice(midPrice, plain).length\n ? abbreviated\n : plain;\n};\n\n/**\n * Options for `formatPerpsUsdInput`.\n */\nexport type PerpsUsdInputFormatOptions = {\n /**\n * Locale-bound formatters, e.g. `createFormatters({ locale })` from\n * `@metamask/client-utils`. Default: `en-US`.\n */\n formatters?: PerpsIntlFormatters;\n /** Most fraction digits (default `PERPS_DISPLAY_PRECISION.UsdInput`, 2). */\n decimals?: number;\n /**\n * Most digits, integer and fraction together (default\n * `PERPS_DISPLAY_PRECISION.UsdInputMaxDigits`, 9; at most 15).\n */\n maxDigits?: number;\n /**\n * What `input` is: `typed` text in the locale's format, e.g. the field's\n * display plus a keystroke (default), a stored canonical `value` with a\n * `.` decimal separator, e.g. a preset amount, or `pasted` clipboard text,\n * whose decimal point may be `.` or `,` whatever the locale.\n */\n source?: 'typed' | 'value' | 'pasted';\n};\n\n/**\n * Separators splitting 1-3 digits from groups of exactly 3: `12.345`,\n * `1.234.567`, `$1,234`. A USD amount has 2 decimals, so these group\n * thousands; uneven groups (`1.234.5`) end with a decimal point.\n */\nconst PASTED_THOUSANDS_GROUPING = /^\\D*[1-9]\\d{0,2}(?:[.,]\\d{3})+\\D*$/u;\n\n/**\n * Rewrites pasted text with a `.` decimal point and no grouping, for a locale\n * whose decimal separator is not `.`. The decimal point is the last `.` or\n * `,` followed by a digit, unless every separator is that same character and\n * they group thousands (`1.234.567`, `12.345`). A separator not followed by a\n * digit is dropped.\n *\n * @param text - Pasted text, digits already in ASCII.\n * @returns The text with `.` as its only separator, or none.\n */\nfunction _normalizePastedDecimal(text: string): string {\n const separators = [...text.matchAll(/[.,](?=\\d)/gu)];\n const last = separators[separators.length - 1];\n let point = -1;\n if (last !== undefined) {\n const alike = separators.filter(([char]) => char === last[0]).length;\n const isGrouping =\n alike === separators.length && PASTED_THOUSANDS_GROUPING.test(text);\n point = isGrouping ? -1 : last.index;\n }\n return text.replace(/[.,]/gu, (_char, index: number) =>\n index === point ? '.' : '',\n );\n}\n\n/** Most digits a USD input keeps exact when grouped through a number. */\nconst MAX_EXACT_INPUT_DIGITS = 15;\n\n/**\n * A masked USD input: `value` to store and parse, `display` to show.\n */\nexport type PerpsUsdInput = {\n /** Canonical amount with a `.` decimal separator: `1234567.5`. */\n value: string;\n /** The amount with the locale's grouping and decimal separator. */\n display: string;\n};\n\ntype LocaleNumberSymbols = {\n decimal: string;\n grouping: string;\n // The locale's glyphs for 0-9\n digits: string[];\n};\n\n/** Separators and digits per formatter set, read once. */\nconst _localeSymbolsCache = new WeakMap<\n PerpsIntlFormatters,\n LocaleNumberSymbols\n>();\n\n/**\n * Reads the decimal separator, grouping separator and digits of a locale from\n * formatted samples, without `formatToParts`.\n *\n * @param formatters - Locale-bound formatters.\n * @returns The locale's number symbols.\n */\nfunction _getLocaleNumberSymbols(\n formatters: PerpsIntlFormatters,\n): LocaleNumberSymbols {\n let symbols = _localeSymbolsCache.get(formatters);\n if (!symbols) {\n // \"1234567890\" in the locale's digits: glyph of 1, 2, ..., 9, 0\n const sample = Array.from(\n formatters.formatNumber(1234567890, { useGrouping: false }),\n );\n symbols = {\n decimal: Array.from(\n formatters.formatNumber(1.5, {\n minimumFractionDigits: 1,\n maximumFractionDigits: 1,\n }),\n )\n .slice(1, -1)\n .join(''),\n grouping: Array.from(formatters.formatNumber(10000))\n .slice(2, -3)\n .join(''),\n digits:\n sample.length === 10\n ? [sample[9], ...sample.slice(0, 9)]\n : Array.from('0123456789'),\n };\n _localeSymbolsCache.set(formatters, symbols);\n }\n return symbols;\n}\n\n/**\n * Masks a USD amount input: keeps digits and one decimal separator, drops\n * leading zeros, caps the decimals and the number of digits, and groups the\n * integer part for the locale. Passing `display` back in with the next\n * keystroke returns the same amount.\n *\n * Typed text reads the locale's decimal separator as the decimal. A `.` also\n * reads as the decimal where the locale uses `.` for neither (`fr`: `12.5` is\n * 12.5); where `.` groups thousands (`de`, `es`), it stays a separator, so\n * `1.2345` is 12345.\n *\n * Pasted text (`source: 'pasted'`) is often written with a `.` decimal point\n * whatever the locale. Where the locale's decimal is not `.`, the last `.` or\n * `,` followed by a digit is the decimal point, so `1234.56` and `1.234,56`\n * are both 1234.56. Separators group thousands instead when they repeat\n * (`1.234.567`), or when one splits 1-3 digits from exactly 3 (`12.345`,\n * `$1,234`). Where the locale's decimal is `.`, pasted text reads as typed.\n *\n * @param input - Typed text, a stored canonical value with `source: 'value'`,\n * or clipboard text with `source: 'pasted'`.\n * @param options - `formatters` (default `en-US`), `decimals` (default\n * `PERPS_DISPLAY_PRECISION.UsdInput`, 2), `maxDigits` (default\n * `PERPS_DISPLAY_PRECISION.UsdInputMaxDigits`, 9) and `source` (default\n * `typed`).\n * @returns The canonical `value` and the locale `display`; both are empty for\n * input without digits.\n * @example formatPerpsUsdInput('0012.345') => { value: '12.34', display: '12.34' }\n * @example formatPerpsUsdInput('1234.') => { value: '1234.', display: '1,234.' }\n * @example formatPerpsUsdInput('1.2345', { formatters: createFormatters({ locale: 'de' }) }) => { value: '12345', display: '12.345' }\n * @example formatPerpsUsdInput('1234567.5', { formatters: createFormatters({ locale: 'de' }), source: 'value' }) => { value: '1234567.5', display: '1.234.567,5' }\n * @example formatPerpsUsdInput('1234.56', { formatters: createFormatters({ locale: 'es' }), source: 'pasted' }) => { value: '1234.56', display: '1234,56' }\n */\nexport const formatPerpsUsdInput = (\n input: string,\n options: PerpsUsdInputFormatOptions = {},\n): PerpsUsdInput => {\n const {\n formatters = _fallbackFormatters,\n decimals = PERPS_DISPLAY_PRECISION.UsdInput,\n maxDigits: requestedMaxDigits = PERPS_DISPLAY_PRECISION.UsdInputMaxDigits,\n source = 'typed',\n } = options;\n const maxDigits = Math.min(requestedMaxDigits, MAX_EXACT_INPUT_DIGITS);\n const symbols = _getLocaleNumberSymbols(formatters);\n let text = Array.from(input, (character) => {\n const digit = symbols.digits.indexOf(character);\n return digit === -1 ? character : String(digit);\n }).join('');\n // Pasted text reads as typed where \".\" is the locale's decimal, or where it\n // holds the locale's own decimal that is neither \".\" nor \",\" (\"٫\")\n const isPastedElsewhere =\n source === 'pasted' &&\n symbols.decimal !== '.' &&\n (symbols.decimal === ',' || !text.includes(symbols.decimal));\n if (isPastedElsewhere) {\n text = _normalizePastedDecimal(text);\n }\n\n let decimalSeparator: string | undefined;\n if (source === 'value' || isPastedElsewhere) {\n decimalSeparator = '.';\n } else if (symbols.decimal && text.includes(symbols.decimal)) {\n decimalSeparator = symbols.decimal;\n } else if (symbols.grouping !== '.') {\n decimalSeparator = '.';\n }\n\n let integer = '';\n let fraction = '';\n let seenDecimal = false;\n for (const character of text) {\n if (character === decimalSeparator && !seenDecimal) {\n seenDecimal = true;\n } else if (character >= '0' && character <= '9') {\n if (seenDecimal) {\n fraction += character;\n } else {\n integer += character;\n }\n }\n }\n const hasDecimal = seenDecimal && decimals > 0;\n if (!integer && !hasDecimal) {\n return { value: '', display: '' };\n }\n\n integer = integer.replace(/^0+(?=\\d)/u, '') || '0';\n integer = integer.slice(0, maxDigits);\n fraction = fraction.slice(\n 0,\n Math.max(0, Math.min(decimals, maxDigits - integer.length)),\n );\n const fractionText = hasDecimal ? `.${fraction}` : '';\n const localizedFraction = Array.from(\n fraction,\n (digit) => symbols.digits[Number(digit)],\n ).join('');\n return {\n value: `${integer}${fractionText}`,\n display: `${formatters.formatNumber(Number(integer), {\n maximumFractionDigits: 0,\n })}${hasDecimal ? `${symbols.decimal}${localizedFraction}` : ''}`,\n };\n};\n\n/**\n * Options for `formatPerpsDuration`.\n */\nexport type PerpsDurationFormatOptions = Pick<\n PerpsDisplayFormatOptions,\n 'formatters'\n> & {\n /** `Intl.NumberFormat` unit style. Default: `short` (\"1 hr 30 min\"). */\n unitDisplay?: 'short' | 'long' | 'narrow';\n};\n\nconst DURATION_UNITS = [\n { unit: 'day', seconds: 86_400 },\n { unit: 'hour', seconds: 3_600 },\n { unit: 'minute', seconds: 60 },\n { unit: 'second', seconds: 1 },\n] as const;\n\n/**\n * Formats a duration as its non-zero days, hours, minutes and seconds, in the\n * client's locale: TWAP running time and elapsed time, slice intervals, chase\n * windows and poll intervals.\n *\n * @param durationMs - Duration in milliseconds, rounded to whole seconds.\n * @param options - `formatters` (default `en-US`) and `unitDisplay` (default\n * `short`).\n * @returns The duration, or `PERPS_CONSTANTS.FallbackDataDisplay` (`--`) for a\n * missing or negative value.\n * @example formatPerpsDuration(90 * 60_000) => \"1 hr 30 min\"\n * @example formatPerpsDuration(1440 * 60_000) => \"1 day\"\n * @example formatPerpsDuration(30_000) => \"30 sec\"\n * @example formatPerpsDuration(0) => \"0 sec\"\n * @example formatPerpsDuration(5 * 60_000, { unitDisplay: 'long' }) => \"5 minutes\"\n */\nexport const formatPerpsDuration = (\n durationMs: string | number | null | undefined,\n options: PerpsDurationFormatOptions = {},\n): string => {\n const { formatters = _fallbackFormatters, unitDisplay = 'short' } = options;\n const value = _parseDisplayNumber(durationMs);\n if (value === undefined || value < 0) {\n return PERPS_CONSTANTS.FallbackDataDisplay;\n }\n let remaining = Math.round(value / 1000);\n const parts: string[] = [];\n for (const { unit, seconds } of DURATION_UNITS) {\n const count = Math.floor(remaining / seconds);\n remaining -= count * seconds;\n if (count > 0) {\n parts.push(\n formatters.formatNumber(count, { style: 'unit', unit, unitDisplay }),\n );\n }\n }\n return parts.length > 0\n ? parts.join(' ')\n : formatters.formatNumber(0, {\n style: 'unit',\n unit: 'second',\n unitDisplay,\n });\n};\n"]}
|
|
1
|
+
{"version":3,"file":"perpsFormatters.js","sourceRoot":"","sources":["../../src/utils/perpsFormatters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,eAAe,EACf,uBAAuB,GACxB,MAAM,6BAA6B,CAAC;AAgDrC;;;;GAIG;AACH,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAA6B,CAAC;AAElE,SAAS,kBAAkB,CACzB,OAAiC;IAEjC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,SAAS,GAAG,oBAAoB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACpD,oBAAoB,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;GAGG;AACH,MAAM,mBAAmB,GAAwB;IAC/C,YAAY,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE,CACpC,kBAAkB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;IAC3C,cAAc,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE,CAChD,kBAAkB,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,MAAM,CACpE,KAAK,CACN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C;QAC7B,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACd,KAAK,CAAC,IAAI,CACR,UAAU,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CACrE,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC;QACrB,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;QACjB,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,EAAE;YACzB,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,QAAQ;YACd,WAAW;SACZ,CAAC,CAAC;AACT,CAAC,CAAC","sourcesContent":["/**\n * Portable perps display formatters.\n *\n * These are the canonical perps display rules, exported from the controller\n * so Mobile, Extension and Terminal format every displayed perps value the\n * same way: price ranges, precision constants, sign and placeholder rules.\n * Each formatter takes one options object (`formatters`, `decimals`, `sign`)\n * and renders the shared placeholder from `PERPS_CONSTANTS` for a missing\n * value.\n *\n * The locale-aware `Intl` formatting comes from the client: pass\n * `createFormatters({ locale })` from `@metamask/client-utils` (built once per\n * locale) as `formatters`. This package does not depend on client-utils; it\n * only needs the `PerpsIntlFormatters` shape. Without `formatters`, an\n * `en-US` fallback keeps the legacy call signatures working.\n */\nimport { BASIS_POINTS_DIVISOR } from '../constants/hyperLiquidConfig.js';\nimport {\n DECIMAL_PRECISION_CONFIG,\n FUNDING_RATE_CONFIG,\n PERPS_CONSTANTS,\n PERPS_DISPLAY_PRECISION,\n} from '../constants/perpsConfig.js';\n\n/**\n * Locale-bound number formatting the perps rules run on. The `Formatters`\n * returned by `createFormatters({ locale })` from `@metamask/client-utils`\n * satisfy it, with a cached `Intl.NumberFormat` per locale and options.\n */\nexport type PerpsIntlFormatters = {\n /** Formats a number with `Intl.NumberFormat` options. */\n formatNumber(value: number, options?: Intl.NumberFormatOptions): string;\n /** Formats a currency amount with `Intl.NumberFormat` options. */\n formatCurrency(\n value: number,\n currency: string,\n options?: Intl.NumberFormatOptions,\n ): string;\n};\n\n/**\n * When a formatter prefixes a sign, using the `Intl.NumberFormat`\n * `signDisplay` names. A value that rounds to zero at the displayed precision\n * counts as zero, so no mode shows `-0.00`.\n *\n * - `auto`: `-` for negative values only.\n * - `always`: `+` for positive values and zero, `-` for negative values.\n * - `exceptZero`: `+` for positive, `-` for negative, nothing for zero.\n * - `never`: no sign.\n */\nexport type PerpsSignDisplay = 'auto' | 'always' | 'exceptZero' | 'never';\n\n/**\n * Options shared by every perps display formatter.\n */\nexport type PerpsDisplayFormatOptions = {\n /**\n * Locale-bound formatters from the client, e.g.\n * `createFormatters({ locale })` from `@metamask/client-utils`, built once\n * per locale. Default: `en-US`.\n */\n formatters?: PerpsIntlFormatters;\n /** Fraction digits to show; pass a `PERPS_DISPLAY_PRECISION` value. */\n decimals?: number;\n /** When to show a sign; each formatter documents its default. */\n sign?: PerpsSignDisplay;\n};\n\ntype StripMode = 'none' | 'fiat' | 'all';\n\n/**\n * `Intl.NumberFormat` cache of the `en-US` fallback, keyed by options.\n * Constructing a formatter costs far more than formatting, so none is built\n * per call. Bounded by the option sets the formatters use.\n */\nconst _fallbackFormatCache = new Map<string, Intl.NumberFormat>();\n\nfunction _getFallbackFormat(\n options: Intl.NumberFormatOptions,\n): Intl.NumberFormat {\n const key = JSON.stringify(options);\n let formatter = _fallbackFormatCache.get(key);\n if (!formatter) {\n formatter = new Intl.NumberFormat('en-US', options);\n _fallbackFormatCache.set(key, formatter);\n }\n return formatter;\n}\n\n/**\n * `en-US` formatters used when the caller passes no `formatters`, so the\n * legacy call signatures keep their output.\n */\nconst _fallbackFormatters: PerpsIntlFormatters = {\n formatNumber: (value, options = {}) =>\n _getFallbackFormat(options).format(value),\n formatCurrency: (value, currency, options = {}) =>\n _getFallbackFormat({ style: 'currency', currency, ...options }).format(\n value,\n ),\n};\n\n/**\n * Parses a displayable number. Missing input (`undefined`, `null`, an empty or\n * non-numeric string, `NaN` or an infinite value) returns `undefined`.\n *\n * @param value - The raw value.\n * @returns The finite number, or `undefined` when the value is missing.\n */\nfunction _parseDisplayNumber(value: unknown): number | undefined {\n let parsed = Number.NaN;\n if (typeof value === 'number') {\n parsed = value;\n } else if (typeof value === 'string') {\n parsed = Number.parseFloat(value);\n }\n return Number.isFinite(parsed) ? parsed : undefined;\n}\n\n/**\n * Returns the sign prefix for a value.\n *\n * @param value - The signed value.\n * @param isZero - Whether the value rounds to zero at the displayed precision.\n * @param sign - The sign display mode.\n * @returns `+`, `-` or an empty string.\n */\nfunction _signPrefix(\n value: number,\n isZero: boolean,\n sign: PerpsSignDisplay,\n): string {\n if (sign === 'never') {\n return '';\n }\n if (isZero) {\n return sign === 'always' ? '+' : '';\n }\n if (value < 0) {\n return '-';\n }\n return sign === 'auto' ? '' : '+';\n}\n\n/**\n * Formats a non-negative number with the locale's separators. Callers that\n * must keep `toFixed` rounding pass a value already rounded with it.\n *\n * @param formatters - Locale-bound formatters.\n * @param value - Non-negative value.\n * @param minimumFractionDigits - Fraction digits always shown.\n * @param maximumFractionDigits - Fraction digits at most shown.\n * @param useGrouping - Whether to group thousands as the locale does.\n * @returns The formatted number.\n */\nfunction _formatDecimal(\n formatters: PerpsIntlFormatters,\n value: number,\n minimumFractionDigits: number,\n maximumFractionDigits: number,\n useGrouping: boolean,\n): string {\n return formatters.formatNumber(value, {\n minimumFractionDigits,\n maximumFractionDigits,\n // Omitted keeps the locale's own grouping rule (es: \"1234,5\", \"12.345,7\")\n ...(useGrouping ? {} : { useGrouping: false }),\n });\n}\n\n/**\n * The magnitude of `value` rounded with `toFixed`, as the decimal formatters\n * (size, percentage, funding) display it.\n *\n * @param value - The signed value.\n * @param decimals - Fraction digits shown.\n * @returns The rounded non-negative value.\n */\nfunction _roundedMagnitude(value: number, decimals: number): number {\n return Number(Math.abs(value).toFixed(decimals));\n}\n\n/**\n * Formats a signed number with `toFixed` rounding and the locale's\n * separators. A value that rounds to zero is zero for the sign.\n *\n * @param formatters - Locale-bound formatters.\n * @param value - The signed value.\n * @param options - Formatting options.\n * @param options.minimumFractionDigits - Fraction digits always shown.\n * @param options.maximumFractionDigits - Fraction digits at most shown.\n * @param options.useGrouping - Whether to group thousands as the locale does.\n * @param options.sign - The sign display mode.\n * @returns The sign prefix and formatted magnitude.\n */\nfunction _formatSignedDecimal(\n formatters: PerpsIntlFormatters,\n value: number,\n options: {\n minimumFractionDigits: number;\n maximumFractionDigits: number;\n useGrouping: boolean;\n sign: PerpsSignDisplay;\n },\n): string {\n const rounded = _roundedMagnitude(value, options.maximumFractionDigits);\n return `${_signPrefix(value, rounded === 0, options.sign)}${_formatDecimal(\n formatters,\n rounded,\n options.minimumFractionDigits,\n options.maximumFractionDigits,\n options.useGrouping,\n )}`;\n}\n\n/**\n * Whether a currency amount shows as zero at `decimals`, with the half away\n * from zero rounding `Intl` applies.\n *\n * @param amount - Non-negative amount.\n * @param decimals - Fraction digits shown.\n * @returns True when the displayed amount is zero.\n */\nfunction _currencyShowsZero(amount: number, decimals: number): boolean {\n return Math.round(amount * 10 ** decimals) === 0;\n}\n\n/**\n * Whether `amount` rounded to `maximumFractionDigits` has an all-zero\n * fraction, decided without an `Intl` call.\n *\n * `Intl.NumberFormat` rounds the shortest decimal form of a number\n * (`String(amount)`) half away from zero, so this reads that form's digits as\n * text: exact for any magnitude, including exponent forms such as `1.5e+21`\n * and `5e-7`.\n *\n * @param amount - Non-negative amount.\n * @param maximumFractionDigits - Fraction digits the amount is rounded to.\n * @returns True when the rounded amount is a whole number.\n */\nfunction _roundsToWhole(\n amount: number,\n maximumFractionDigits: number,\n): boolean {\n const [mantissa, exponentText = '0'] = String(amount).split('e');\n const [integerPart, fractionPart = ''] = mantissa.split('.');\n // Fraction digits once the exponent is applied\n const shift = Number(exponentText);\n // An exponent form has one integer digit: \"1.23e-7\" → \"000000123\"\n const fraction =\n shift >= 0\n ? fractionPart.slice(shift)\n : `${'0'.repeat(-shift - 1)}${integerPart}${fractionPart}`;\n const kept = fraction.slice(0, maximumFractionDigits);\n const roundsUp = (fraction[maximumFractionDigits] ?? '0') >= '5';\n return roundsUp ? /^9*$/u.test(kept) : /^0*$/u.test(kept);\n}\n\n/**\n * Formats a non-negative currency amount, stripping trailing fraction zeros.\n *\n * Stripping is done through the fraction-digit options, so the amount is\n * formatted once. This works for any decimal separator or digit set and does\n * not rely on `formatToParts`, which some Hermes builds return as one literal\n * part.\n *\n * @param formatters - Locale-bound formatters.\n * @param amount - Non-negative amount.\n * @param options - Formatting options.\n * @param options.currency - ISO 4217 currency code.\n * @param options.minimumFractionDigits - Minimum decimal digits.\n * @param options.maximumFractionDigits - Maximum decimal digits.\n * @param options.strip - `fiat` drops an all-zero two-digit fraction (`.00`),\n * `all` drops every trailing fraction zero, `none` keeps them.\n * @param options.symbol - `false` formats the number without the currency\n * symbol, for chart labels (default `true`).\n * @returns Formatted currency string.\n */\nfunction _formatCurrency(\n formatters: PerpsIntlFormatters,\n amount: number,\n options: {\n currency: string;\n minimumFractionDigits: number;\n maximumFractionDigits: number;\n strip: StripMode;\n symbol?: boolean;\n },\n): string {\n let { minimumFractionDigits, maximumFractionDigits } = options;\n if (options.strip === 'all') {\n // Intl drops trailing fraction zeros down to the minimum\n minimumFractionDigits = 0;\n } else if (options.strip === 'fiat' && minimumFractionDigits === 2) {\n if (_roundsToWhole(amount, maximumFractionDigits)) {\n // Fiat-style: only an all-zero \".00\" fraction is dropped\n minimumFractionDigits = 0;\n maximumFractionDigits = 0;\n }\n }\n\n if (options.symbol === false) {\n return formatters.formatNumber(amount, {\n minimumFractionDigits,\n maximumFractionDigits,\n });\n }\n return formatters.formatCurrency(amount, options.currency, {\n currencyDisplay: 'narrowSymbol',\n minimumFractionDigits,\n maximumFractionDigits,\n });\n}\n\n/**\n * Formats a non-negative USD amount with fixed decimals and appends a\n * magnitude suffix (`K`, `M`, `B`, `T`) right after the number, wherever the\n * locale puts the currency symbol: `$1.23M`, `1,23M $`.\n *\n * The suffix is placed by finding the formatted number in the currency\n * output, not through `formatToParts` or `notation: 'compact'`, which Hermes\n * does not reliably support.\n *\n * @param formatters - Locale-bound formatters.\n * @param amount - Non-negative amount, already divided by the scale.\n * @param options - Formatting options.\n * @param options.decimals - Fraction digits always shown.\n * @param options.suffix - Magnitude suffix, or an empty string.\n * @param options.symbol - `false` formats without the currency symbol.\n * @returns The formatted amount.\n */\nfunction _formatScaledUsd(\n formatters: PerpsIntlFormatters,\n amount: number,\n options: { decimals: number; suffix: string; symbol: boolean },\n): string {\n const { decimals, suffix, symbol } = options;\n if (!symbol) {\n return `${_formatDecimal(formatters, amount, decimals, decimals, true)}${suffix}`;\n }\n const money = _formatCurrency(formatters, amount, {\n currency: 'USD',\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n strip: 'none',\n });\n if (!suffix) {\n return money;\n }\n const number = _formatDecimal(formatters, amount, decimals, decimals, true);\n const index = money.indexOf(number);\n if (index === -1) {\n return `${money}${suffix}`;\n }\n const end = index + number.length;\n return `${money.slice(0, end)}${suffix}${money.slice(end)}`;\n}\n\n/**\n * Price threshold constants for PRICE_RANGES_UNIVERSAL\n * These define the boundaries between different formatting ranges\n */\nexport const PRICE_THRESHOLD = {\n /** Very high values boundary (> $100k) */\n VERY_HIGH: 100_000,\n /** High values boundary (> $10k) */\n HIGH: 10_000,\n /** Large values boundary (> $1k) */\n LARGE: 1_000,\n /** Medium values boundary (> $100) */\n MEDIUM: 100,\n /** Medium-low values boundary (> $10) */\n MEDIUM_LOW: 10,\n /** Low values boundary (>= $0.01) */\n LOW: 0.01,\n /**\n * Very small values threshold (< $0.01).\n * A non-zero value below this floor renders as `<` plus the formatted\n * threshold (e.g. `<$0` under `PRICE_RANGES_UNIVERSAL`); the floor aligns\n * with the 6-decimal price maximum.\n */\n VERY_SMALL: 0.000001,\n} as const;\n\n/**\n * Configuration for a specific number range formatting\n */\nexport type FiatRangeConfig = {\n /**\n * The condition to match for this range (e.g., < 0.0001, < 1, >= 1000)\n * Function should return true if this config should be applied\n */\n condition: (value: number) => boolean;\n /** Minimum decimal places for this range */\n minimumDecimals: number;\n /** Maximum decimal places for this range */\n maximumDecimals: number;\n /** Optional threshold for formatWithThreshold (defaults to the range boundary) */\n threshold?: number;\n /** Optional significant digits for this range (overrides decimal places when set) */\n significantDigits?: number;\n /** Optional custom formatting logic for this range */\n customFormat?: (value: number, locale: string, currency: string) => string;\n /** Optional flag to strip trailing zeros for this range (overrides global stripTrailingZeros option) */\n stripTrailingZeros?: boolean;\n /**\n * Optional flag for fiat-style stripping (only strips .00, preserves meaningful decimals like .10, .40)\n * When true, \"$1,250.00\" → \"$1,250\" but \"$1,250.10\" stays \"$1,250.10\"\n * When false (default), strips all trailing zeros: \"$1,250.10\" → \"$1,250.1\"\n */\n fiatStyleStripping?: boolean;\n};\n\n/**\n * Formats a number to a specific number of significant digits\n * Strips trailing zeros unless minDecimals requires them\n *\n * @param value - The numeric value to format\n * @param significantDigits - Number of significant digits to maintain\n * @param minDecimals - Minimum decimal places to show (may add zeros)\n * @param maxDecimals - Maximum decimal places allowed\n * @returns Formatted number with appropriate precision, trailing zeros removed\n */\nexport function formatWithSignificantDigits(\n value: number,\n significantDigits: number,\n minDecimals?: number,\n maxDecimals?: number,\n): { value: number; decimals: number } {\n // Handle special cases\n if (value === 0) {\n // Return zero with no trailing decimals by default (matches stripTrailingZeros behavior)\n // Can be overridden by explicit minDecimals if needed\n return { value: 0, decimals: minDecimals ?? 0 };\n }\n\n const absValue = Math.abs(value);\n\n // For numbers >= 1, calculate decimals based on magnitude to achieve target significant figures\n // This ensures consistent precision across different price ranges:\n // Examples with 4 significant figures:\n // $123,456.78 → $123,456.78 (≥$1000: 2 decimals minimum, 8 sig figs)\n // $456.12 → $456.12 (≥$10: 2 decimals minimum, 5 sig figs)\n // $56.123 → $56.123 (≥$10: 2 decimals minimum, 5 sig figs)\n // $5.123 → $5.123 ($1-$10: 3 decimals = 4 sig figs)\n // $2.801 → $2.801 ($1-$10: 3 decimals = 4 sig figs)\n // $1.234 → $1.234 ($1-$10: 3 decimals = 4 sig figs)\n if (absValue >= 1) {\n let targetDecimals: number;\n\n // Calculate decimals needed based on integer digits to achieve target significant figures\n // For $38.388 with 5 sig figs: 2 integer digits, need 3 decimals (3,8,3,8,8)\n // For $123.45 with 5 sig figs: 3 integer digits, need 2 decimals (1,2,3,4,5)\n const integerDigits = Math.floor(Math.log10(absValue)) + 1;\n const decimalsNeeded = significantDigits - integerDigits;\n targetDecimals = Math.max(decimalsNeeded, 0); // Can't have negative decimals\n\n // Apply explicit minimum decimals constraint if provided (for special cases)\n if (minDecimals !== undefined && targetDecimals < minDecimals) {\n targetDecimals = minDecimals;\n }\n\n // Apply maximum decimals constraint if specified\n const finalDecimals =\n maxDecimals === undefined\n ? targetDecimals\n : Math.min(targetDecimals, maxDecimals);\n\n // Round to prevent floating-point artifacts (e.g., 2.820000000000003 → 2.82)\n const roundedValue = Number(value.toFixed(finalDecimals));\n\n return {\n value: roundedValue,\n decimals: finalDecimals,\n };\n }\n\n // For numbers < 1, use toPrecision to limit to significantDigits\n // Examples: 0.1234, 0.01234 should show exactly 4 sig figs\n const precisionStr = absValue.toPrecision(significantDigits);\n const precisionNum = parseFloat(precisionStr);\n\n // Convert to string to count actual decimals after trailing zeros are removed\n const valueStr = precisionNum.toString();\n const [, decPart = ''] = valueStr.split('.');\n let actualDecimals = decPart.length;\n\n // Apply min/max decimal constraints\n if (minDecimals !== undefined && actualDecimals < minDecimals) {\n actualDecimals = minDecimals; // Will add zeros if needed\n }\n if (maxDecimals !== undefined && actualDecimals > maxDecimals) {\n actualDecimals = maxDecimals;\n }\n\n // Return the value with sign restored and decimal count\n return {\n value: value < 0 ? -precisionNum : precisionNum,\n decimals: actualDecimals,\n };\n}\n\n/**\n * Minimal view fiat range configuration\n * Uses fiat-style stripping for clean currency display\n * Strips only .00 to avoid partial decimals like $1,250.1\n */\nexport const PRICE_RANGES_MINIMAL_VIEW: FiatRangeConfig[] = [\n {\n // Large values (>= $1000): Strip .00 only ($5,000 not $5,000.00, but $5,000.10 stays)\n condition: (val: number) => Math.abs(val) >= PRICE_THRESHOLD.LARGE,\n minimumDecimals: 2,\n maximumDecimals: 2,\n threshold: PRICE_THRESHOLD.LARGE,\n stripTrailingZeros: true,\n fiatStyleStripping: true,\n },\n {\n // Small values (< $1000): Also use fiat-style stripping ($100 not $100.00, but $13.40 stays)\n condition: () => true,\n minimumDecimals: 2,\n maximumDecimals: 2,\n threshold: PRICE_THRESHOLD.LOW,\n stripTrailingZeros: true,\n fiatStyleStripping: true,\n },\n];\n\n/**\n * Universal price range configuration following comprehensive rules from rules-decimals.md\n *\n * Rules:\n * - Max 6 decimals across all ranges (Hyperliquid limit)\n * - Strip trailing zeros by default\n * - Use |v| (absolute value) for conditions\n *\n * Significant digits by range:\n * - > $100,000: 6 sig digs\n * - $100,000 > x > $0.01: 5 sig digs\n * - < $0.01: 4 sig digs\n *\n * Decimal limits by price range:\n * - |v| > 10,000: min 0, max 0 decimals; 5 sig digs (6 if >100k)\n * - |v| > 1,000: min 0, max 1 decimal; 5 sig digs\n * - |v| > 100: min 0, max 2 decimals; 5 sig digs\n * - |v| > 10: min 0, max 4 decimals; 5 sig digs\n * - |v| ≥ 0.01: 5 sig digs, min 2, max 6 decimals\n * - |v| < 0.01: 4 sig digs, min 2, max 6 decimals\n *\n * Examples:\n * - $123,456.78 → $123,457 (>$10k: 0 decimals, 6 sig figs)\n * - $12,345.67 → $12,346 (>$10k: 0 decimals, 5 sig figs)\n * - $1,234.56 → $1,234.6 ($1k-$10k: 1 decimal, 5 sig figs)\n * - $123.456 → $123.46 ($100-$1k: 2 decimals, 5 sig figs)\n * - $12.34567 → $12.346 ($10-$100: 4 decimals, 5 sig figs)\n * - $1.3445555 → $1.3446 (≥$0.01: 5 sig figs)\n * - $0.333333 → $0.33333 (≥$0.01: 5 sig figs)\n * - $0.004236 → $0.004236 (<$0.01: 4 sig figs, max 6 decimals)\n * - $0.0000006 → <$0 (<$0.01: 4 sig figs; below the $0.000001 floor)\n */\nexport const PRICE_RANGES_UNIVERSAL: FiatRangeConfig[] = [\n {\n // Very high values (> $100,000): No decimals, 6 significant figures\n // Ex: $123,456.78 → $123,457\n condition: (val) => Math.abs(val) > PRICE_THRESHOLD.VERY_HIGH,\n minimumDecimals: 0,\n maximumDecimals: 0,\n significantDigits: 6,\n threshold: PRICE_THRESHOLD.VERY_HIGH,\n },\n {\n // High values ($10,000-$100,000]: No decimals, 5 significant figures\n // Ex: $12,345.67 → $12,346\n condition: (val) => Math.abs(val) > PRICE_THRESHOLD.HIGH,\n minimumDecimals: 0,\n maximumDecimals: 0,\n significantDigits: 5,\n threshold: PRICE_THRESHOLD.HIGH,\n },\n {\n // Large values ($1,000-$10,000]: Max 1 decimal, 5 significant figures\n // Ex: $1,234.56 → $1,234.6\n condition: (val) => Math.abs(val) > PRICE_THRESHOLD.LARGE,\n minimumDecimals: 0,\n maximumDecimals: 1,\n significantDigits: 5,\n threshold: PRICE_THRESHOLD.LARGE,\n },\n {\n // Medium values ($100-$1,000]: Max 2 decimals, 5 significant figures\n // Ex: $123.456 → $123.46\n condition: (val) => Math.abs(val) > PRICE_THRESHOLD.MEDIUM,\n minimumDecimals: 0,\n maximumDecimals: 2,\n significantDigits: 5,\n threshold: PRICE_THRESHOLD.MEDIUM,\n },\n {\n // Medium-low values ($10-$100]: Max 4 decimals, 5 significant figures\n // Ex: $12.34567 → $12.346\n condition: (val) => Math.abs(val) > PRICE_THRESHOLD.MEDIUM_LOW,\n minimumDecimals: 0,\n maximumDecimals: 4,\n significantDigits: 5,\n threshold: PRICE_THRESHOLD.MEDIUM_LOW,\n },\n {\n // Low values ($0.01-$10]: 5 significant figures, min 2 max MAX_PRICE_DECIMALS decimals\n // Ex: $1.3445555 → $1.3446 | $0.333333 → $0.33333\n condition: (val) => Math.abs(val) >= PRICE_THRESHOLD.LOW,\n significantDigits: 5,\n minimumDecimals: 2,\n maximumDecimals: DECIMAL_PRECISION_CONFIG.MaxPriceDecimals,\n threshold: PRICE_THRESHOLD.LOW,\n },\n {\n // Very small values (< $0.01): 4 significant figures, min 2 max MAX_PRICE_DECIMALS decimals\n // Ex: $0.004236 → $0.004236 | $0.0000006 → <$0\n condition: () => true,\n significantDigits: 4,\n minimumDecimals: 2,\n maximumDecimals: DECIMAL_PRECISION_CONFIG.MaxPriceDecimals,\n threshold: PRICE_THRESHOLD.VERY_SMALL,\n },\n];\n\n/**\n * Options for `formatPerpsFiat`.\n */\nexport type PerpsFiatFormatOptions = PerpsDisplayFormatOptions & {\n /** Global minimum decimal places (overrides `decimals` and range configs). */\n minimumDecimals?: number;\n /** Global maximum decimal places (overrides `decimals` and range configs). */\n maximumDecimals?: number;\n /** Global significant digits (overrides decimal settings when set). */\n significantDigits?: number;\n /** Range configurations (default `PRICE_RANGES_MINIMAL_VIEW`). */\n ranges?: FiatRangeConfig[];\n /** ISO 4217 currency code (default `USD`). */\n currency?: string;\n /** Strip trailing zeros; `false` keeps them whatever the range says. */\n stripTrailingZeros?: boolean;\n /**\n * Locale passed to a range's `customFormat` (default `en-US`). The output\n * locale comes from `formatters`.\n */\n locale?: string;\n /**\n * `false` formats the number without the currency symbol, e.g. chart axis\n * and crosshair labels: `87,123` (default `true`).\n */\n symbol?: boolean;\n};\n\n/**\n * Formats a fiat value (balance, price, fee, position value) as currency with\n * decimal places chosen by the matching range.\n *\n * @param balance - Raw numeric value (e.g., 1234.56, not token minimal denomination).\n * @param options - Formatting options.\n * @param options.formatters - Locale-bound formatters, e.g. `createFormatters({ locale: 'de' })` from `@metamask/client-utils` (default `en-US`).\n * @param options.decimals - Fixed decimal places (e.g. `PERPS_DISPLAY_PRECISION.Fee`), overriding the range.\n * @param options.sign - Sign display (default `auto`: `-` for negative values only).\n * @param options.minimumDecimals - Global minimum decimal places (overrides `decimals` and range configs).\n * @param options.maximumDecimals - Global maximum decimal places (overrides `decimals` and range configs).\n * @param options.significantDigits - Global significant digits (overrides decimal settings when set).\n * @param options.ranges - Custom range configurations (defaults to PRICE_RANGES_MINIMAL_VIEW).\n * @param options.currency - Currency code (default: 'USD').\n * @param options.stripTrailingZeros - Strip trailing zeros from output. `false` keeps them; otherwise the range decides (default: strip).\n * @param options.locale - Locale passed to a range's `customFormat` only (default `en-US`).\n * @param options.symbol - `false` omits the currency symbol, for chart labels (default `true`).\n * @returns Formatted currency string, or `PERPS_CONSTANTS.FallbackPriceDisplay`\n * (`$---`) for a missing value (`PERPS_CONSTANTS.FallbackDataDisplay`, `--`,\n * without the symbol).\n * @example\n * formatPerpsFiat(1234.56) => \"$1,234.56\"\n * formatPerpsFiat(1250) => \"$1,250\" // fiat-style stripping of .00\n * formatPerpsFiat(-0.004) => \"-<$0.01\" // below the range threshold\n * formatPerpsFiat(1234.5, { formatters: createFormatters({ locale: 'de' }) }) => \"1.234,50 $\"\n * formatPerpsFiat(12345.67, { ranges: PRICE_RANGES_UNIVERSAL }) => \"$12,346\"\n * formatPerpsFiat(2480.37, { ranges: PRICE_RANGES_UNIVERSAL, symbol: false }) => \"2,480.4\"\n * formatPerpsFiat(undefined) => \"$---\"\n */\nexport const formatPerpsFiat = (\n balance: string | number | null | undefined,\n options?: PerpsFiatFormatOptions,\n): string => {\n const value = _parseDisplayNumber(balance);\n if (value === undefined) {\n // Placeholder for missing values to avoid confusion with actual $0 values\n return options?.symbol === false\n ? PERPS_CONSTANTS.FallbackDataDisplay\n : PERPS_CONSTANTS.FallbackPriceDisplay;\n }\n\n const currency = options?.currency ?? 'USD';\n const ranges = options?.ranges ?? PRICE_RANGES_MINIMAL_VIEW;\n // Find the first matching range configuration\n const rangeConfig = ranges.find((range) => range.condition(value));\n\n const sigDigits =\n options?.significantDigits ?? rangeConfig?.significantDigits;\n if (rangeConfig?.customFormat && !sigDigits) {\n return rangeConfig.customFormat(\n value,\n options?.locale ?? 'en-US',\n currency,\n );\n }\n\n // Strip trailing zeros unless explicitly disabled. Priority: explicit\n // `stripTrailingZeros: false` > range config > option > true.\n let strip: StripMode = 'none';\n if (\n options?.stripTrailingZeros !== false &&\n (rangeConfig?.stripTrailingZeros ?? options?.stripTrailingZeros ?? true)\n ) {\n // Fiat-style only strips .00: \"$1,250.00\" → \"$1,250\", \"$13.40\" stays\n strip = rangeConfig?.fiatStyleStripping ? 'fiat' : 'all';\n }\n\n let minDecimals =\n options?.minimumDecimals ??\n options?.decimals ??\n rangeConfig?.minimumDecimals ??\n 2;\n let maxDecimals =\n options?.maximumDecimals ??\n options?.decimals ??\n rangeConfig?.maximumDecimals ??\n 2;\n let amount = Math.abs(value);\n if (rangeConfig && sigDigits) {\n // Calculate appropriate formatting based on significant digits\n const significant = formatWithSignificantDigits(\n value,\n sigDigits,\n minDecimals,\n maxDecimals,\n );\n amount = Math.abs(significant.value);\n minDecimals = significant.decimals;\n maxDecimals = significant.decimals;\n }\n\n // A non-zero amount below the threshold shows \"<$threshold\"\n const threshold = rangeConfig?.threshold ?? PRICE_THRESHOLD.LOW;\n const isBelowThreshold = amount !== 0 && amount < threshold;\n const body = _formatCurrency(\n options?.formatters ?? _fallbackFormatters,\n isBelowThreshold ? threshold : amount,\n {\n currency,\n minimumFractionDigits: minDecimals,\n maximumFractionDigits: maxDecimals,\n strip,\n symbol: options?.symbol,\n },\n );\n const isZero = !isBelowThreshold && _currencyShowsZero(amount, maxDecimals);\n\n return `${_signPrefix(value, isZero, options?.sign ?? 'auto')}${\n isBelowThreshold ? '<' : ''\n }${body}`;\n};\n\n/**\n * Formats position size with variable decimal precision based on magnitude or asset-specific decimals\n * Removes trailing zeros and never groups thousands.\n *\n * @param size - Raw position size value\n * @param szDecimalsOrOptions - Asset-specific decimal precision from Hyperliquid metadata\n * (e.g., BTC=5, ETH=4, DOGE=1), or options:\n * `decimals` (the same precision), `formatters` (default `en-US`) and `sign` (default `auto`).\n * @returns Format varies by size or uses asset-specific decimals, with trailing zeros removed:\n * If decimals are provided: Uses at most those decimals (e.g., 0.00009 BTC with szDecimals=5 => \"0.00009\")\n * Otherwise falls back to magnitude-based logic:\n * - Size < 0.01: Up to 6 decimals (e.g., \"0.00009\" not \"0.000090\")\n * - Size < 1: Up to 4 decimals (e.g., \"0.0024\" not \"0.002400\")\n * - Size >= 1: Up to 2 decimals (e.g., \"44\" not \"44.00\")\n * A missing value returns `PERPS_CONSTANTS.FallbackDataDisplay` (`--`).\n * @example formatPositionSize(0.00009, 5) => \"0.00009\" (uses szDecimals)\n * @example formatPositionSize(44.00, 1) => \"44\" (uses szDecimals, trailing zeros removed)\n * @example formatPositionSize(0.0024) => \"0.0024\" (no szDecimals, uses magnitude logic)\n * @example formatPositionSize(-1234.5, { decimals: 2, formatters: createFormatters({ locale: 'es' }) }) => \"-1234,5\"\n * @example formatPositionSize(undefined) => \"--\"\n */\nexport const formatPositionSize = (\n size: string | number | null | undefined,\n szDecimalsOrOptions?: number | PerpsDisplayFormatOptions,\n): string => {\n const {\n formatters = _fallbackFormatters,\n decimals,\n sign = 'auto',\n } = typeof szDecimalsOrOptions === 'number'\n ? { decimals: szDecimalsOrOptions }\n : (szDecimalsOrOptions ?? {});\n const value = _parseDisplayNumber(size);\n if (value === undefined) {\n return PERPS_CONSTANTS.FallbackDataDisplay;\n }\n\n const abs = Math.abs(value);\n let maxDecimals = decimals;\n // Fallback: magnitude-based decimal logic for backwards compatibility\n if (maxDecimals === undefined) {\n if (abs < 0.01) {\n maxDecimals = 6;\n } else if (abs < 1) {\n maxDecimals = 4;\n } else {\n maxDecimals = 2;\n }\n }\n return _formatSignedDecimal(formatters, value, {\n minimumFractionDigits: 0,\n maximumFractionDigits: maxDecimals,\n useGrouping: false,\n sign,\n });\n};\n\n/**\n * Formats a PnL (Profit and Loss) value as USD with a sign prefix\n *\n * @param pnl - Raw numeric PnL value (positive for profit, negative for loss)\n * @param options - `formatters` (default `en-US`), `decimals` (default\n * `PERPS_DISPLAY_PRECISION.Pnl`, 2) and `sign` (default `always`).\n * @returns Format: \"+$X,XXX.XX\" or \"-$X,XXX.XX\", or\n * `PERPS_CONSTANTS.FallbackPriceDisplay` (`$---`) for a missing value.\n * @example formatPnl(1234.56) => \"+$1,234.56\"\n * @example formatPnl(-500) => \"-$500.00\"\n * @example formatPnl(0) => \"+$0.00\"\n * @example formatPnl(0, { sign: 'exceptZero' }) => \"$0.00\"\n * @example formatPnl(1234.5, { formatters: createFormatters({ locale: 'es' }) }) => \"+1234,50 $\"\n * @example formatPnl(undefined) => \"$---\"\n */\nexport const formatPnl = (\n pnl: string | number | null | undefined,\n options: PerpsDisplayFormatOptions = {},\n): string => {\n const {\n formatters = _fallbackFormatters,\n decimals = PERPS_DISPLAY_PRECISION.Pnl,\n sign = 'always',\n } = options;\n const value = _parseDisplayNumber(pnl);\n if (value === undefined) {\n return PERPS_CONSTANTS.FallbackPriceDisplay;\n }\n\n const amount = Math.abs(value);\n const formatted = _formatCurrency(formatters, amount, {\n currency: 'USD',\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n strip: 'none',\n });\n return `${_signPrefix(value, _currencyShowsZero(amount, decimals), sign)}${formatted}`;\n};\n\n/**\n * Options for `formatPercentage`.\n */\nexport type PerpsPercentageFormatOptions = PerpsDisplayFormatOptions & {\n /**\n * Drop trailing fraction zeros, showing at most `decimals`: TWAP progress\n * `25%`, `33.33%` (default `false`: always `decimals`).\n */\n stripTrailingZeros?: boolean;\n};\n\n/**\n * Formats a percentage value (change, RoE, fee rate, slippage) with a sign\n * prefix and locale separators. Pick the precision from\n * `PERPS_DISPLAY_PRECISION`.\n *\n * @param value - Raw percentage value (e.g., 5.25 for 5.25%, not 0.0525)\n * @param decimalsOrOptions - Decimal places (default:\n * `PERPS_DISPLAY_PRECISION.Percentage`, 2), or options: `decimals`,\n * `formatters` (default `en-US`), `sign` (default `always`) and\n * `stripTrailingZeros` (default `false`).\n * @returns Format: \"+X.XX%\" or \"-X.XX%\", or\n * `PERPS_CONSTANTS.FallbackPercentageDisplay` (`--%`) for a missing value.\n * @example formatPercentage(5.25) => \"+5.25%\"\n * @example formatPercentage(-2.75) => \"-2.75%\"\n * @example formatPercentage(0) => \"+0.00%\"\n * @example formatPercentage(10.25, { decimals: PERPS_DISPLAY_PRECISION.RoePercent }) => \"+10.3%\"\n * @example formatPercentage(0.0021, { decimals: PERPS_DISPLAY_PRECISION.SlippageEstimatePercent, sign: 'never' }) => \"0.0021%\"\n * @example formatPercentage(-12345.67, { decimals: 1, formatters: createFormatters({ locale: 'es' }) }) => \"-12.345,7%\"\n * @example formatPercentage(25, { decimals: PERPS_DISPLAY_PRECISION.TwapProgressPercent, stripTrailingZeros: true, sign: 'never' }) => \"25%\"\n * @example formatPercentage(undefined) => \"--%\"\n */\nexport const formatPercentage = (\n value: string | number | null | undefined,\n decimalsOrOptions?: number | PerpsPercentageFormatOptions,\n): string => {\n const {\n formatters = _fallbackFormatters,\n decimals = PERPS_DISPLAY_PRECISION.Percentage,\n sign = 'always',\n stripTrailingZeros = false,\n } = typeof decimalsOrOptions === 'number'\n ? { decimals: decimalsOrOptions }\n : (decimalsOrOptions ?? {});\n const parsed = _parseDisplayNumber(value);\n if (parsed === undefined) {\n return PERPS_CONSTANTS.FallbackPercentageDisplay;\n }\n\n return `${_formatSignedDecimal(formatters, parsed, {\n minimumFractionDigits: stripTrailingZeros ? 0 : decimals,\n maximumFractionDigits: decimals,\n useGrouping: true,\n sign,\n })}%`;\n};\n\n/**\n * Formats a 0..1 cross margin ratio (account ratio or cross margin usage)\n * as an unsigned percentage with at most one decimal. A positive value has\n * no `+` prefix and a whole number has no trailing zero.\n *\n * The input is a ratio, not a percentage: `0.174` is `17.4%`. A ratio\n * outside 0..1 still formats, so usage above 100% shows `150%`.\n *\n * @param ratio - The ratio (`0.174` for 17.4%).\n * @param options - `formatters` (default `en-US`), `decimals` (at most,\n * default `PERPS_DISPLAY_PRECISION.CrossMarginRatioPercent`, 1; trailing\n * zeros are dropped) and `sign` (default `auto`: a minus for a negative\n * ratio, no plus).\n * The locale's percent style renders the number and the `%` symbol, so a\n * locale that spaces or prefixes the symbol (`17,4 %`, `%17,4`) does.\n * @returns Format: \"X%\" or \"X.X%\" in `en-US`, or\n * `PERPS_CONSTANTS.FallbackPercentageDisplay` (`--%`) for a missing ratio.\n * @example formatCrossMarginRatio(0.174) => \"17.4%\"\n * @example formatCrossMarginRatio(0.63) => \"63%\"\n * @example formatCrossMarginRatio(0) => \"0%\"\n * @example formatCrossMarginRatio(-0.174) => \"-17.4%\"\n * @example formatCrossMarginRatio(0.0255) => \"2.6%\"\n * @example formatCrossMarginRatio(0.174, { formatters: createFormatters({ locale: 'de' }) }) => \"17,4 %\"\n * @example formatCrossMarginRatio(undefined) => \"--%\"\n */\nexport const formatCrossMarginRatio = (\n ratio: string | number | null | undefined,\n options: PerpsDisplayFormatOptions = {},\n): string => {\n const {\n formatters = _fallbackFormatters,\n decimals = PERPS_DISPLAY_PRECISION.CrossMarginRatioPercent,\n sign = 'auto',\n } = options;\n const parsed = _parseDisplayNumber(ratio);\n if (parsed === undefined) {\n return PERPS_CONSTANTS.FallbackPercentageDisplay;\n }\n\n // The locale's percent style owns the rounding, the `%` symbol and its\n // placement (`17.4%`, `17,4 %`, `%17,4`), so the ratio is passed as is.\n // Shifting it by 100 and rounding with `toFixed` first would round binary\n // ties differently (`0.0255` is `2.6%`, not `2.5%`).\n const percentOptions: Intl.NumberFormatOptions = {\n style: 'percent',\n minimumFractionDigits: 0,\n maximumFractionDigits: decimals,\n };\n const magnitude = Math.abs(parsed);\n // A ratio that rounds to 0 at the shown precision has no sign, so a tiny\n // negative ratio is `0%`, not `-0%`. The threshold is half of the last\n // shown digit, with the half rounded away from zero as `Intl` does.\n // The sign itself is the shared prefix, not the locale's minus glyph.\n const isZero = magnitude < Number(`5e-${decimals + 3}`);\n return `${_signPrefix(parsed, isZero, sign)}${formatters.formatNumber(\n isZero ? 0 : magnitude,\n percentOptions,\n )}`;\n};\n\n/**\n * Options for `formatFundingRate`.\n */\nexport type PerpsFundingRateFormatOptions = PerpsDisplayFormatOptions & {\n /** `false` returns an empty string for a missing rate (default `true`). */\n showZero?: boolean;\n};\n\n/**\n * Formats funding rate for display\n *\n * @param value - Raw funding rate value (decimal, not percentage)\n * @param options - Optional formatting options\n * @param options.showZero - `false` returns an empty string instead of the placeholder for a missing rate (default: true)\n * @param options.formatters - Locale-bound formatters, e.g. `createFormatters({ locale })` from `@metamask/client-utils` (default `en-US`)\n * @param options.decimals - Decimal places (default `PERPS_DISPLAY_PRECISION.FundingRatePercent`, 4)\n * @param options.sign - Sign display (default `auto`: `-` for negative rates only)\n * @returns Formatted funding rate as percentage string, or\n * `PERPS_CONSTANTS.FallbackPercentageDisplay` (`--%`) for a missing rate.\n * @example formatFundingRate(0.0005) => \"0.0500%\"\n * @example formatFundingRate(-0.0001) => \"-0.0100%\"\n * @example formatFundingRate(0.000000059) => \"<0.0001%\"\n * @example formatFundingRate(-0.000000059) => \"-<0.0001%\"\n * @example formatFundingRate(0.0005, { sign: 'always', formatters: createFormatters({ locale: 'es' }) }) => \"+0,0500%\"\n * @example formatFundingRate(undefined) => \"--%\"\n */\nexport const formatFundingRate = (\n value?: string | number | null,\n options: PerpsFundingRateFormatOptions = {},\n): string => {\n const {\n showZero = true,\n formatters = _fallbackFormatters,\n decimals = PERPS_DISPLAY_PRECISION.FundingRatePercent,\n sign = 'auto',\n } = options;\n const rate = _parseDisplayNumber(value);\n if (rate === undefined) {\n return showZero ? PERPS_CONSTANTS.FallbackPercentageDisplay : '';\n }\n\n const percentage = rate * FUNDING_RATE_CONFIG.PercentageMultiplier;\n // A non-zero rate below the display precision shows \"<0.0001%\"\n if (rate !== 0 && _roundedMagnitude(percentage, decimals) === 0) {\n const minimum = _formatDecimal(\n formatters,\n 10 ** -decimals,\n decimals,\n decimals,\n true,\n );\n return `${_signPrefix(rate, false, sign)}<${minimum}%`;\n }\n\n return `${_formatSignedDecimal(formatters, percentage, {\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n useGrouping: true,\n sign,\n })}%`;\n};\n\n/**\n * Funding since open below this magnitude shows as zero: under half a cent.\n */\nconst FUNDING_SINCE_OPEN_ZERO_THRESHOLD = 0.005;\n\n/**\n * A single funding payment below this magnitude shows its sub-cent digits\n * instead of the fiat ranges, which would round it to `<$0.01`.\n */\nconst FUNDING_PAYMENT_CENT_THRESHOLD = 0.01;\n\n/** Most fraction digits of a funding payment below a cent. */\nconst FUNDING_PAYMENT_SUB_CENT_DECIMALS = 6;\n\n/**\n * How funding since open reads for the trader: `cost` (paid), `payment`\n * (received) or `none` (under half a cent, or missing).\n */\nexport type PerpsFundingDirection = 'cost' | 'payment' | 'none';\n\n/**\n * Formats a zero USD amount with two decimals: `$0.00`, `0,00 $`.\n *\n * @param formatters - Locale-bound formatters.\n * @returns The formatted zero.\n */\nfunction _formatZeroUsd(formatters: PerpsIntlFormatters): string {\n return _formatCurrency(formatters, 0, {\n currency: 'USD',\n minimumFractionDigits: 2,\n maximumFractionDigits: 2,\n strip: 'none',\n });\n}\n\n/**\n * Classifies funding since a position opened, with the venue's sign\n * (positive = the trader paid), so clients colour it without copying the\n * half-cent threshold.\n *\n * @param sinceOpen - Funding since open (venue field `cumulativeFunding.sinceOpen`).\n * @returns `cost` from $0.005 up, `payment` from -$0.005 down, `none`\n * otherwise or for a missing value.\n * @example getPositionFundingDirection('1.25') => \"cost\"\n * @example getPositionFundingDirection(-0.8) => \"payment\"\n * @example getPositionFundingDirection(0.004) => \"none\"\n * @example getPositionFundingDirection(undefined) => \"none\"\n */\nexport const getPositionFundingDirection = (\n sinceOpen: string | number | null | undefined,\n): PerpsFundingDirection => {\n const value = _parseDisplayNumber(sinceOpen);\n if (\n value === undefined ||\n Math.abs(value) < FUNDING_SINCE_OPEN_ZERO_THRESHOLD\n ) {\n return 'none';\n }\n return value > 0 ? 'cost' : 'payment';\n};\n\n/**\n * Formats funding since a position opened, as Mobile and Extension show it.\n * The venue reports funding the trader paid as a positive number, so a cost\n * shows with `-` and a payment received with `+`. Under half a cent it shows\n * as zero.\n *\n * @param sinceOpen - Funding since open (venue field `cumulativeFunding.sinceOpen`).\n * @param options - `formatters` (default `en-US`) and `sign` (default\n * `exceptZero`). The amount's precision comes from\n * `PRICE_RANGES_MINIMAL_VIEW`.\n * @returns `-` or `+` with the amount on `PRICE_RANGES_MINIMAL_VIEW`, `$0.00`\n * under half a cent, or `PERPS_CONSTANTS.FallbackPriceDisplay` (`$---`) for a\n * missing value.\n * @example formatPositionFunding('1.2345') => \"-$1.23\"\n * @example formatPositionFunding(-1234.5) => \"+$1,234.50\"\n * @example formatPositionFunding(0.005) => \"-<$0.01\"\n * @example formatPositionFunding(0.0049) => \"$0.00\"\n * @example formatPositionFunding(1234.5, { formatters: createFormatters({ locale: 'de' }) }) => \"-1.234,50 $\"\n * @example formatPositionFunding(-1.2345, { sign: 'never' }) => \"$1.23\"\n * @example formatPositionFunding(undefined) => \"$---\"\n */\nexport const formatPositionFunding = (\n sinceOpen: string | number | null | undefined,\n options: Omit<PerpsDisplayFormatOptions, 'decimals'> = {},\n): string => {\n const { formatters = _fallbackFormatters, sign = 'exceptZero' } = options;\n const value = _parseDisplayNumber(sinceOpen);\n if (value === undefined) {\n return PERPS_CONSTANTS.FallbackPriceDisplay;\n }\n if (getPositionFundingDirection(value) === 'none') {\n return `${_signPrefix(0, true, sign)}${_formatZeroUsd(formatters)}`;\n }\n // A cost (venue-positive) reads as money out: \"-\"\n return `${_signPrefix(-value, false, sign)}${formatPerpsFiat(\n Math.abs(value),\n { ranges: PRICE_RANGES_MINIMAL_VIEW, formatters },\n )}`;\n};\n\n/**\n * Formats a single funding payment (a history row or its detail), with the\n * trader's sign: positive = received. From a cent up it matches Mobile's\n * `formatPerpsFiat`; below a cent it keeps up to 6 fraction digits, trailing\n * zeros dropped and never in exponent notation.\n *\n * @param amount - Funding payment in USD (positive = received).\n * @param options - `formatters` (default `en-US`) and `sign` (default\n * `exceptZero`). The precision is fixed by the rules above.\n * @returns The signed amount, `$0.00` without a sign when it rounds to zero\n * at 6 digits, or `PERPS_CONSTANTS.FallbackPriceDisplay` (`$---`) for a\n * missing value.\n * @example formatFundingPayment(1.234) => \"+$1.23\"\n * @example formatFundingPayment(-12.5) => \"-$12.50\"\n * @example formatFundingPayment(0.003421) => \"+$0.003421\"\n * @example formatFundingPayment(0.0000004) => \"$0.00\"\n * @example formatFundingPayment(0.003421, { formatters: createFormatters({ locale: 'de' }) }) => \"+0,003421 $\"\n * @example formatFundingPayment(undefined) => \"$---\"\n */\nexport const formatFundingPayment = (\n amount: string | number | null | undefined,\n options: Omit<PerpsDisplayFormatOptions, 'decimals'> = {},\n): string => {\n const { formatters = _fallbackFormatters, sign = 'exceptZero' } = options;\n const value = _parseDisplayNumber(amount);\n if (value === undefined) {\n return PERPS_CONSTANTS.FallbackPriceDisplay;\n }\n const magnitude = Math.abs(value);\n if (magnitude >= FUNDING_PAYMENT_CENT_THRESHOLD) {\n return `${_signPrefix(value, false, sign)}${formatPerpsFiat(magnitude, {\n formatters,\n })}`;\n }\n // Below a cent, a value that rounds to zero at 6 digits shows as zero\n if (_roundsToWhole(magnitude, FUNDING_PAYMENT_SUB_CENT_DECIMALS)) {\n return `${_signPrefix(value, true, sign)}${_formatZeroUsd(formatters)}`;\n }\n return `${_signPrefix(value, false, sign)}${_formatCurrency(\n formatters,\n magnitude,\n {\n currency: 'USD',\n minimumFractionDigits: 0,\n maximumFractionDigits: FUNDING_PAYMENT_SUB_CENT_DECIMALS,\n strip: 'all',\n },\n )}`;\n};\n\n/**\n * Formats a fee rate in basis points with the locale's separators.\n *\n * @param rate - Fee rate as a decimal (0.00045 for 0.045%).\n * @param options - `formatters` (default `en-US`), `decimals` (at most,\n * default `PERPS_DISPLAY_PRECISION.FeeBps`, 2; trailing zeros are dropped) and\n * `sign` (default `auto`).\n * @returns Format: \"X.XX bps\", or `PERPS_CONSTANTS.FallbackDataDisplay` (`--`)\n * for a missing rate.\n * @example formatFeeBps(0.00045) => \"4.5 bps\"\n * @example formatFeeBps(0.000144) => \"1.44 bps\"\n * @example formatFeeBps(0.0007) => \"7 bps\"\n * @example formatFeeBps(0.00045, { formatters: createFormatters({ locale: 'de' }) }) => \"4,5 bps\"\n * @example formatFeeBps(undefined) => \"--\"\n */\nexport const formatFeeBps = (\n rate: string | number | null | undefined,\n options: PerpsDisplayFormatOptions = {},\n): string => {\n const {\n formatters = _fallbackFormatters,\n decimals = PERPS_DISPLAY_PRECISION.FeeBps,\n sign = 'auto',\n } = options;\n const parsed = _parseDisplayNumber(rate);\n if (parsed === undefined) {\n return PERPS_CONSTANTS.FallbackDataDisplay;\n }\n\n return `${_formatSignedDecimal(formatters, parsed * BASIS_POINTS_DIVISOR, {\n minimumFractionDigits: 0,\n maximumFractionDigits: decimals,\n useGrouping: true,\n sign,\n })} bps`;\n};\n\n/**\n * Formats how far, in percent of the entry price, the price must move to\n * reach the liquidation price.\n *\n * @param entryPrice - Entry (or mark) price.\n * @param liquidationPrice - Liquidation price.\n * @param options - `formatters` (default `en-US`), `decimals` (default\n * `PERPS_DISPLAY_PRECISION.LiquidationDistancePercent`, 2) and `sign`\n * (default `never`).\n * @returns Format: \"X.XX%\", or `PERPS_CONSTANTS.FallbackPercentageDisplay`\n * (`--%`) when either price is missing or not positive.\n * @example formatLiquidationDistance(100, 70) => \"30.00%\"\n * @example formatLiquidationDistance(100, '130') => \"30.00%\"\n * @example formatLiquidationDistance(100, 70, { formatters: createFormatters({ locale: 'de' }) }) => \"30,00%\"\n * @example formatLiquidationDistance(100, undefined) => \"--%\"\n */\nexport const formatLiquidationDistance = (\n entryPrice: string | number | null | undefined,\n liquidationPrice: string | number | null | undefined,\n options: PerpsDisplayFormatOptions = {},\n): string => {\n const entry = _parseDisplayNumber(entryPrice);\n const liquidation = _parseDisplayNumber(liquidationPrice);\n if (\n entry === undefined ||\n liquidation === undefined ||\n entry <= 0 ||\n liquidation <= 0\n ) {\n return PERPS_CONSTANTS.FallbackPercentageDisplay;\n }\n\n return formatPercentage((Math.abs(entry - liquidation) / entry) * 100, {\n formatters: options.formatters,\n decimals:\n options.decimals ?? PERPS_DISPLAY_PRECISION.LiquidationDistancePercent,\n sign: options.sign ?? 'never',\n });\n};\n\n/**\n * Options for `formatLeverage`.\n */\nexport type PerpsLeverageFormatOptions = Pick<\n PerpsDisplayFormatOptions,\n 'formatters'\n> & {\n /** Fraction digits always shown (default 0). */\n minimumFractionDigits?: number;\n /**\n * Fraction digits at most shown (default\n * `PERPS_DISPLAY_PRECISION.Leverage`, 2). Raised to `minimumFractionDigits`\n * when lower.\n */\n maximumFractionDigits?: number;\n};\n\n/**\n * Formats a leverage multiplier, such as account or position leverage, with\n * an `x` suffix and locale separators.\n *\n * @param value - The leverage multiplier (`0.2` for 0.2x).\n * @param options - `formatters` (default `en-US`), `minimumFractionDigits`\n * (default 0) and `maximumFractionDigits` (default\n * `PERPS_DISPLAY_PRECISION.Leverage`, 2).\n * @returns Format: \"X.XXx\", or `PERPS_CONSTANTS.FallbackDataDisplay` (`--`)\n * for a missing or negative value.\n * @example formatLeverage(0.2) => \"0.2x\"\n * @example formatLeverage(0.2, { minimumFractionDigits: 2 }) => \"0.20x\"\n * @example formatLeverage(1.2149) => \"1.21x\"\n * @example formatLeverage(2.5, { minimumFractionDigits: 1, maximumFractionDigits: 1 }) => \"2.5x\"\n * @example formatLeverage(1.2149, { formatters: createFormatters({ locale: 'de' }) }) => \"1,21x\"\n * @example formatLeverage(undefined) => \"--\"\n */\nexport const formatLeverage = (\n value: string | number | null | undefined,\n options: PerpsLeverageFormatOptions = {},\n): string => {\n const {\n formatters = _fallbackFormatters,\n minimumFractionDigits = 0,\n maximumFractionDigits = PERPS_DISPLAY_PRECISION.Leverage,\n } = options;\n const parsed = _parseDisplayNumber(value);\n if (parsed === undefined || parsed < 0) {\n return PERPS_CONSTANTS.FallbackDataDisplay;\n }\n\n const maximum = Math.max(minimumFractionDigits, maximumFractionDigits);\n return `${_formatDecimal(\n formatters,\n _roundedMagnitude(parsed, maximum),\n minimumFractionDigits,\n maximum,\n true,\n )}x`;\n};\n\n/** Each magnitude scale is this many times the next smaller one. */\nconst SCALE_STEP = 1000;\n\n/** Magnitude scales of compact values, largest first. */\nconst COMPACT_SCALES = [\n { divisor: 1_000_000_000_000, suffix: 'T' },\n { divisor: 1_000_000_000, suffix: 'B' },\n { divisor: 1_000_000, suffix: 'M' },\n { divisor: SCALE_STEP, suffix: 'K' },\n { divisor: 1, suffix: '' },\n] as const;\n\n/**\n * Picks the magnitude scale of a non-negative amount and rounds it. A\n * mantissa that rounds up to 1000 moves to the next scale, so 999999 shows as\n * `1.00M`, not `1000K`.\n *\n * @param amount - Non-negative amount.\n * @param decimalsFor - Fraction digits shown at a scale divisor.\n * @returns The rounded mantissa, its decimals and suffix.\n */\nfunction _scaleCompact(\n amount: number,\n decimalsFor: (divisor: number) => number,\n): { mantissa: number; decimals: number; suffix: string } {\n let index = COMPACT_SCALES.findIndex(({ divisor }) => amount >= divisor);\n if (index === -1) {\n index = COMPACT_SCALES.length - 1;\n }\n for (;;) {\n const { divisor, suffix } = COMPACT_SCALES[index];\n const decimals = decimalsFor(divisor);\n const mantissa = _roundedMagnitude(amount / divisor, decimals);\n if (mantissa < SCALE_STEP || index === 0) {\n return { mantissa, decimals, suffix };\n }\n index -= 1;\n }\n}\n\n/**\n * The value a compact number stands for, which sets its unit and precision.\n *\n * - `volume`: USD volume or open interest: `$1.23M`, `$123K`, `$999.50`.\n * - `orderBookUsd`: USD order book size or total: `$2.1K` from 1,000 up,\n * `PRICE_RANGES_UNIVERSAL` below.\n * - `orderBookSize`: base-asset order book size or total: `604.9K` from 1,000\n * up, `formatPositionSize` with `szDecimals` below.\n */\nexport type PerpsCompactField = 'volume' | 'orderBookUsd' | 'orderBookSize';\n\n/**\n * Options for `formatPerpsCompact`.\n */\nexport type PerpsCompactFormatOptions = PerpsDisplayFormatOptions & {\n /** The value being shown, which sets the unit and precision. */\n field: PerpsCompactField;\n /** Asset size decimals for an `orderBookSize` value below 1,000. */\n szDecimals?: number;\n};\n\n/**\n * Formats a large number with a magnitude suffix (`K`, `M`, `B`, `T`), with\n * the unit and precision of the field it shows.\n *\n * @param value - Raw value (USD for `volume` and `orderBookUsd`, base asset\n * for `orderBookSize`).\n * @param options - Formatting options.\n * @param options.field - `volume`, `orderBookUsd` or `orderBookSize`.\n * @param options.formatters - Locale-bound formatters, e.g. `createFormatters({ locale })` from `@metamask/client-utils` (default `en-US`).\n * @param options.decimals - Decimals of abbreviated values, overriding the\n * field's `PERPS_DISPLAY_PRECISION` (`VolumeCompact`, `VolumeCompactThousands`\n * or `OrderBookCompact`).\n * @param options.sign - Sign display (default `auto`).\n * @param options.szDecimals - Asset size decimals for an `orderBookSize` value below 1,000.\n * @returns The compact value, or `PERPS_CONSTANTS.FallbackPriceDisplay`\n * (`$---`, `--` for `orderBookSize`) for a missing value.\n * @example formatPerpsCompact(1234567, { field: 'volume' }) => \"$1.23M\"\n * @example formatPerpsCompact(123456, { field: 'volume' }) => \"$123K\"\n * @example formatPerpsCompact(999.5, { field: 'volume' }) => \"$999.50\"\n * @example formatPerpsCompact(1234567, { field: 'volume', formatters: createFormatters({ locale: 'de' }) }) => \"1,23M $\"\n * @example formatPerpsCompact(2100, { field: 'orderBookUsd' }) => \"$2.1K\"\n * @example formatPerpsCompact(604900, { field: 'orderBookSize' }) => \"604.9K\"\n */\nexport const formatPerpsCompact = (\n value: string | number | null | undefined,\n options: PerpsCompactFormatOptions,\n): string => {\n const {\n field,\n formatters = _fallbackFormatters,\n decimals,\n sign = 'auto',\n szDecimals,\n } = options;\n const isUsd = field !== 'orderBookSize';\n const parsed = _parseDisplayNumber(value);\n if (parsed === undefined) {\n return isUsd\n ? PERPS_CONSTANTS.FallbackPriceDisplay\n : PERPS_CONSTANTS.FallbackDataDisplay;\n }\n\n const amount = Math.abs(parsed);\n if (field !== 'volume' && amount < SCALE_STEP) {\n return field === 'orderBookUsd'\n ? formatPerpsFiat(parsed, {\n ranges: PRICE_RANGES_UNIVERSAL,\n formatters,\n sign,\n })\n : formatPositionSize(parsed, { decimals: szDecimals, formatters, sign });\n }\n\n const scaled = _scaleCompact(amount, (divisor) => {\n if (decimals !== undefined) {\n return decimals;\n }\n if (field !== 'volume') {\n return PERPS_DISPLAY_PRECISION.OrderBookCompact;\n }\n return divisor === SCALE_STEP\n ? PERPS_DISPLAY_PRECISION.VolumeCompactThousands\n : PERPS_DISPLAY_PRECISION.VolumeCompact;\n });\n return `${_signPrefix(parsed, scaled.mantissa === 0, sign)}${_formatScaledUsd(\n formatters,\n scaled.mantissa,\n { decimals: scaled.decimals, suffix: scaled.suffix, symbol: isUsd },\n )}`;\n};\n\n/**\n * How every price of an order book ladder renders: divided by `divisor`, with\n * `decimals` fixed decimals and `suffix` after the number.\n */\nexport type PerpsOrderBookPriceFormat = {\n /** Value each price is divided by before formatting. */\n divisor: number;\n /** Magnitude suffix appended after the number, or an empty string. */\n suffix: string;\n /** Fixed decimals shown after dividing. */\n decimals: number;\n};\n\n/**\n * Options for `getPerpsOrderBookPriceFormat`.\n */\nexport type PerpsOrderBookLadderOptions = {\n /** Ladder mid price, which sets the magnitude of an abbreviation. */\n midPrice?: number | null;\n /** Asset size decimals from the market metadata. */\n szDecimals?: number;\n};\n\n/**\n * Exact decimal places of a number, read from its exponential form so values\n * such as `1e-7` and `0.002` do not depend on a rounded `Math.log10`.\n *\n * @param value - The number.\n * @returns Its decimal places.\n */\nfunction _countDecimalPlaces(value: number): number {\n const [mantissa, exponent] = Math.abs(value).toExponential().split('e');\n return Math.max(0, (mantissa.split('.')[1] ?? '').length - Number(exponent));\n}\n\n/**\n * Options for `formatPerpsOrderBookPrice`.\n */\nexport type PerpsOrderBookPriceFormatOptions = {\n /**\n * Locale-bound formatters, e.g. `createFormatters({ locale })` from\n * `@metamask/client-utils`. Default: `en-US`.\n */\n formatters?: PerpsIntlFormatters;\n /** `false` omits the currency symbol (default `true`). */\n symbol?: boolean;\n};\n\n/**\n * Formats an order book price with the ladder format from\n * `getPerpsOrderBookPriceFormat`, keeping trailing zeros so every row has the\n * same width.\n *\n * @param price - Raw price.\n * @param format - Ladder format, or null for `PRICE_RANGES_UNIVERSAL`.\n * @param options - `formatters` (default `en-US`) and `symbol` (default `true`).\n * @returns The price, or `PERPS_CONSTANTS.FallbackPriceDisplay` (`$---`; `--`\n * without the symbol) for a missing price.\n * @example formatPerpsOrderBookPrice(87000, { divisor: 1000, suffix: 'K', decimals: 0 }) => \"$87K\"\n * @example formatPerpsOrderBookPrice(33.1, { divisor: 1, suffix: '', decimals: 3 }) => \"$33.100\"\n * @example formatPerpsOrderBookPrice(87000, { divisor: 1, suffix: '', decimals: 0 }, { symbol: false }) => \"87,000\"\n */\nexport const formatPerpsOrderBookPrice = (\n price: string | number | null | undefined,\n format: PerpsOrderBookPriceFormat | null,\n options: PerpsOrderBookPriceFormatOptions = {},\n): string => {\n const { formatters = _fallbackFormatters, symbol = true } = options;\n const value = _parseDisplayNumber(price);\n if (value === undefined) {\n return symbol\n ? PERPS_CONSTANTS.FallbackPriceDisplay\n : PERPS_CONSTANTS.FallbackDataDisplay;\n }\n if (format === null) {\n return formatPerpsFiat(value, {\n ranges: PRICE_RANGES_UNIVERSAL,\n formatters,\n symbol,\n });\n }\n\n const amount = Math.abs(value) / format.divisor;\n return `${_signPrefix(\n value,\n _currencyShowsZero(amount, format.decimals),\n 'auto',\n )}${_formatScaledUsd(formatters, amount, {\n decimals: format.decimals,\n suffix: format.suffix,\n symbol,\n })}`;\n};\n\n/**\n * Resolves the one price format an order book ladder renders with, from the\n * selected price grouping (tick) increment.\n *\n * Decimals match the grouping, capped at the asset's price precision\n * (`PERPS_DISPLAY_PRECISION.MaxPriceDecimals − szDecimals`), so neighbouring\n * levels never collapse into the same string and every row has the same\n * width. The ladder is abbreviated (`$87K`) at the magnitude of `midPrice`\n * only when that needs at most\n * `PERPS_DISPLAY_PRECISION.OrderBookAbbreviatedPriceMax` decimals and is no\n * longer than the plain form.\n *\n * @param grouping - Selected price grouping increment, or null when unknown.\n * @param options - Ladder context.\n * @param options.midPrice - Ladder mid price, which sets the magnitude.\n * @param options.szDecimals - Asset size decimals from the market metadata.\n * @returns The ladder format, or null to use `PRICE_RANGES_UNIVERSAL`.\n * @example getPerpsOrderBookPriceFormat(1000, { midPrice: 87000, szDecimals: 5 }) => { divisor: 1000, suffix: 'K', decimals: 0 }\n * @example getPerpsOrderBookPriceFormat(1, { midPrice: 87000, szDecimals: 5 }) => { divisor: 1, suffix: '', decimals: 0 }\n * @example getPerpsOrderBookPriceFormat(0.001, { midPrice: 33.1, szDecimals: 2 }) => { divisor: 1, suffix: '', decimals: 3 }\n */\nexport const getPerpsOrderBookPriceFormat = (\n grouping: number | null | undefined,\n options: PerpsOrderBookLadderOptions = {},\n): PerpsOrderBookPriceFormat | null => {\n const { midPrice, szDecimals } = options;\n if (\n typeof grouping !== 'number' ||\n !Number.isFinite(grouping) ||\n grouping <= 0\n ) {\n return null;\n }\n\n const maxDecimals =\n typeof szDecimals === 'number' && Number.isFinite(szDecimals)\n ? Math.max(0, PERPS_DISPLAY_PRECISION.MaxPriceDecimals - szDecimals)\n : PERPS_DISPLAY_PRECISION.MaxPriceDecimals;\n const plain: PerpsOrderBookPriceFormat = {\n divisor: 1,\n suffix: '',\n decimals: Math.min(_countDecimalPlaces(grouping), maxDecimals),\n };\n if (typeof midPrice !== 'number' || !Number.isFinite(midPrice)) {\n return plain;\n }\n\n const magnitude = Math.abs(midPrice);\n const scale = COMPACT_SCALES.find(\n ({ divisor }) =>\n divisor > 1 && magnitude >= divisor && magnitude < divisor * SCALE_STEP,\n );\n if (!scale) {\n return plain;\n }\n const decimals = _countDecimalPlaces(grouping / scale.divisor);\n if (decimals > PERPS_DISPLAY_PRECISION.OrderBookAbbreviatedPriceMax) {\n return plain;\n }\n\n const abbreviated: PerpsOrderBookPriceFormat = {\n divisor: scale.divisor,\n suffix: scale.suffix,\n decimals,\n };\n return formatPerpsOrderBookPrice(midPrice, abbreviated).length <=\n formatPerpsOrderBookPrice(midPrice, plain).length\n ? abbreviated\n : plain;\n};\n\n/**\n * Options for `formatPerpsUsdInput`.\n */\nexport type PerpsUsdInputFormatOptions = {\n /**\n * Locale-bound formatters, e.g. `createFormatters({ locale })` from\n * `@metamask/client-utils`. Default: `en-US`.\n */\n formatters?: PerpsIntlFormatters;\n /** Most fraction digits (default `PERPS_DISPLAY_PRECISION.UsdInput`, 2). */\n decimals?: number;\n /**\n * Most digits, integer and fraction together (default\n * `PERPS_DISPLAY_PRECISION.UsdInputMaxDigits`, 9; at most 15).\n */\n maxDigits?: number;\n /**\n * What `input` is: `typed` text in the locale's format, e.g. the field's\n * display plus a keystroke (default), a stored canonical `value` with a\n * `.` decimal separator, e.g. a preset amount, or `pasted` clipboard text,\n * whose decimal point may be `.` or `,` whatever the locale.\n */\n source?: 'typed' | 'value' | 'pasted';\n};\n\n/**\n * Separators splitting 1-3 digits from groups of exactly 3: `12.345`,\n * `1.234.567`, `$1,234`. A USD amount has 2 decimals, so these group\n * thousands; uneven groups (`1.234.5`) end with a decimal point.\n */\nconst PASTED_THOUSANDS_GROUPING = /^\\D*[1-9]\\d{0,2}(?:[.,]\\d{3})+\\D*$/u;\n\n/**\n * Rewrites pasted text with a `.` decimal point and no grouping, for a locale\n * whose decimal separator is not `.`. The decimal point is the last `.` or\n * `,` followed by a digit, unless every separator is that same character and\n * they group thousands (`1.234.567`, `12.345`). A separator not followed by a\n * digit is dropped.\n *\n * @param text - Pasted text, digits already in ASCII.\n * @returns The text with `.` as its only separator, or none.\n */\nfunction _normalizePastedDecimal(text: string): string {\n const separators = [...text.matchAll(/[.,](?=\\d)/gu)];\n const last = separators[separators.length - 1];\n let point = -1;\n if (last !== undefined) {\n const alike = separators.filter(([char]) => char === last[0]).length;\n const isGrouping =\n alike === separators.length && PASTED_THOUSANDS_GROUPING.test(text);\n point = isGrouping ? -1 : last.index;\n }\n return text.replace(/[.,]/gu, (_char, index: number) =>\n index === point ? '.' : '',\n );\n}\n\n/** Most digits a USD input keeps exact when grouped through a number. */\nconst MAX_EXACT_INPUT_DIGITS = 15;\n\n/**\n * A masked USD input: `value` to store and parse, `display` to show.\n */\nexport type PerpsUsdInput = {\n /** Canonical amount with a `.` decimal separator: `1234567.5`. */\n value: string;\n /** The amount with the locale's grouping and decimal separator. */\n display: string;\n};\n\ntype LocaleNumberSymbols = {\n decimal: string;\n grouping: string;\n // The locale's glyphs for 0-9\n digits: string[];\n};\n\n/** Separators and digits per formatter set, read once. */\nconst _localeSymbolsCache = new WeakMap<\n PerpsIntlFormatters,\n LocaleNumberSymbols\n>();\n\n/**\n * Reads the decimal separator, grouping separator and digits of a locale from\n * formatted samples, without `formatToParts`.\n *\n * @param formatters - Locale-bound formatters.\n * @returns The locale's number symbols.\n */\nfunction _getLocaleNumberSymbols(\n formatters: PerpsIntlFormatters,\n): LocaleNumberSymbols {\n let symbols = _localeSymbolsCache.get(formatters);\n if (!symbols) {\n // \"1234567890\" in the locale's digits: glyph of 1, 2, ..., 9, 0\n const sample = Array.from(\n formatters.formatNumber(1234567890, { useGrouping: false }),\n );\n symbols = {\n decimal: Array.from(\n formatters.formatNumber(1.5, {\n minimumFractionDigits: 1,\n maximumFractionDigits: 1,\n }),\n )\n .slice(1, -1)\n .join(''),\n grouping: Array.from(formatters.formatNumber(10000))\n .slice(2, -3)\n .join(''),\n digits:\n sample.length === 10\n ? [sample[9], ...sample.slice(0, 9)]\n : Array.from('0123456789'),\n };\n _localeSymbolsCache.set(formatters, symbols);\n }\n return symbols;\n}\n\n/**\n * Masks a USD amount input: keeps digits and one decimal separator, drops\n * leading zeros, caps the decimals and the number of digits, and groups the\n * integer part for the locale. Passing `display` back in with the next\n * keystroke returns the same amount.\n *\n * Typed text reads the locale's decimal separator as the decimal. A `.` also\n * reads as the decimal where the locale uses `.` for neither (`fr`: `12.5` is\n * 12.5); where `.` groups thousands (`de`, `es`), it stays a separator, so\n * `1.2345` is 12345.\n *\n * Pasted text (`source: 'pasted'`) is often written with a `.` decimal point\n * whatever the locale. Where the locale's decimal is not `.`, the last `.` or\n * `,` followed by a digit is the decimal point, so `1234.56` and `1.234,56`\n * are both 1234.56. Separators group thousands instead when they repeat\n * (`1.234.567`), or when one splits 1-3 digits from exactly 3 (`12.345`,\n * `$1,234`). Where the locale's decimal is `.`, pasted text reads as typed.\n *\n * @param input - Typed text, a stored canonical value with `source: 'value'`,\n * or clipboard text with `source: 'pasted'`.\n * @param options - `formatters` (default `en-US`), `decimals` (default\n * `PERPS_DISPLAY_PRECISION.UsdInput`, 2), `maxDigits` (default\n * `PERPS_DISPLAY_PRECISION.UsdInputMaxDigits`, 9) and `source` (default\n * `typed`).\n * @returns The canonical `value` and the locale `display`; both are empty for\n * input without digits.\n * @example formatPerpsUsdInput('0012.345') => { value: '12.34', display: '12.34' }\n * @example formatPerpsUsdInput('1234.') => { value: '1234.', display: '1,234.' }\n * @example formatPerpsUsdInput('1.2345', { formatters: createFormatters({ locale: 'de' }) }) => { value: '12345', display: '12.345' }\n * @example formatPerpsUsdInput('1234567.5', { formatters: createFormatters({ locale: 'de' }), source: 'value' }) => { value: '1234567.5', display: '1.234.567,5' }\n * @example formatPerpsUsdInput('1234.56', { formatters: createFormatters({ locale: 'es' }), source: 'pasted' }) => { value: '1234.56', display: '1234,56' }\n */\nexport const formatPerpsUsdInput = (\n input: string,\n options: PerpsUsdInputFormatOptions = {},\n): PerpsUsdInput => {\n const {\n formatters = _fallbackFormatters,\n decimals = PERPS_DISPLAY_PRECISION.UsdInput,\n maxDigits: requestedMaxDigits = PERPS_DISPLAY_PRECISION.UsdInputMaxDigits,\n source = 'typed',\n } = options;\n const maxDigits = Math.min(requestedMaxDigits, MAX_EXACT_INPUT_DIGITS);\n const symbols = _getLocaleNumberSymbols(formatters);\n let text = Array.from(input, (character) => {\n const digit = symbols.digits.indexOf(character);\n return digit === -1 ? character : String(digit);\n }).join('');\n // Pasted text reads as typed where \".\" is the locale's decimal, or where it\n // holds the locale's own decimal that is neither \".\" nor \",\" (\"٫\")\n const isPastedElsewhere =\n source === 'pasted' &&\n symbols.decimal !== '.' &&\n (symbols.decimal === ',' || !text.includes(symbols.decimal));\n if (isPastedElsewhere) {\n text = _normalizePastedDecimal(text);\n }\n\n let decimalSeparator: string | undefined;\n if (source === 'value' || isPastedElsewhere) {\n decimalSeparator = '.';\n } else if (symbols.decimal && text.includes(symbols.decimal)) {\n decimalSeparator = symbols.decimal;\n } else if (symbols.grouping !== '.') {\n decimalSeparator = '.';\n }\n\n let integer = '';\n let fraction = '';\n let seenDecimal = false;\n for (const character of text) {\n if (character === decimalSeparator && !seenDecimal) {\n seenDecimal = true;\n } else if (character >= '0' && character <= '9') {\n if (seenDecimal) {\n fraction += character;\n } else {\n integer += character;\n }\n }\n }\n const hasDecimal = seenDecimal && decimals > 0;\n if (!integer && !hasDecimal) {\n return { value: '', display: '' };\n }\n\n integer = integer.replace(/^0+(?=\\d)/u, '') || '0';\n integer = integer.slice(0, maxDigits);\n fraction = fraction.slice(\n 0,\n Math.max(0, Math.min(decimals, maxDigits - integer.length)),\n );\n const fractionText = hasDecimal ? `.${fraction}` : '';\n const localizedFraction = Array.from(\n fraction,\n (digit) => symbols.digits[Number(digit)],\n ).join('');\n return {\n value: `${integer}${fractionText}`,\n display: `${formatters.formatNumber(Number(integer), {\n maximumFractionDigits: 0,\n })}${hasDecimal ? `${symbols.decimal}${localizedFraction}` : ''}`,\n };\n};\n\n/**\n * Options for `formatPerpsDuration`.\n */\nexport type PerpsDurationFormatOptions = Pick<\n PerpsDisplayFormatOptions,\n 'formatters'\n> & {\n /** `Intl.NumberFormat` unit style. Default: `short` (\"1 hr 30 min\"). */\n unitDisplay?: 'short' | 'long' | 'narrow';\n};\n\nconst DURATION_UNITS = [\n { unit: 'day', seconds: 86_400 },\n { unit: 'hour', seconds: 3_600 },\n { unit: 'minute', seconds: 60 },\n { unit: 'second', seconds: 1 },\n] as const;\n\n/**\n * Formats a duration as its non-zero days, hours, minutes and seconds, in the\n * client's locale: TWAP running time and elapsed time, slice intervals, chase\n * windows and poll intervals.\n *\n * @param durationMs - Duration in milliseconds, rounded to whole seconds.\n * @param options - `formatters` (default `en-US`) and `unitDisplay` (default\n * `short`).\n * @returns The duration, or `PERPS_CONSTANTS.FallbackDataDisplay` (`--`) for a\n * missing or negative value.\n * @example formatPerpsDuration(90 * 60_000) => \"1 hr 30 min\"\n * @example formatPerpsDuration(1440 * 60_000) => \"1 day\"\n * @example formatPerpsDuration(30_000) => \"30 sec\"\n * @example formatPerpsDuration(0) => \"0 sec\"\n * @example formatPerpsDuration(5 * 60_000, { unitDisplay: 'long' }) => \"5 minutes\"\n */\nexport const formatPerpsDuration = (\n durationMs: string | number | null | undefined,\n options: PerpsDurationFormatOptions = {},\n): string => {\n const { formatters = _fallbackFormatters, unitDisplay = 'short' } = options;\n const value = _parseDisplayNumber(durationMs);\n if (value === undefined || value < 0) {\n return PERPS_CONSTANTS.FallbackDataDisplay;\n }\n let remaining = Math.round(value / 1000);\n const parts: string[] = [];\n for (const { unit, seconds } of DURATION_UNITS) {\n const count = Math.floor(remaining / seconds);\n remaining -= count * seconds;\n if (count > 0) {\n parts.push(\n formatters.formatNumber(count, { style: 'unit', unit, unitDisplay }),\n );\n }\n }\n return parts.length > 0\n ? parts.join(' ')\n : formatters.formatNumber(0, {\n style: 'unit',\n unit: 'second',\n unitDisplay,\n });\n};\n"]}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Prices a venue accepts around a reference price under a deviation limit
|
|
3
|
-
* such as `PerpsOrderLimits.maxOraclePriceDeviation`:
|
|
4
|
-
* times the reference
|
|
3
|
+
* such as `PerpsOrderLimits.maxOraclePriceDeviation`: up to `maxDeviation`
|
|
4
|
+
* times the reference away from it on either side, so a price `p` is inside
|
|
5
|
+
* when `|p - reference| / reference <= maxDeviation`. HyperLiquid's rule
|
|
6
|
+
* ("Order price cannot be more than 95% away from the reference price") and
|
|
7
|
+
* `isMarketTradable` use this band. The lower bound never goes below 0.
|
|
8
|
+
* Bounds are computed in exact decimals, so `1 - 0.95` is exactly 0.05.
|
|
5
9
|
*
|
|
6
10
|
* @param referencePrice - Oracle price, or the mark price when the oracle is unknown.
|
|
7
|
-
* @param maxDeviation - Deviation limit as a fraction
|
|
11
|
+
* @param maxDeviation - Deviation limit as a positive fraction.
|
|
8
12
|
* @returns The inclusive band, or undefined when either input is unusable.
|
|
9
13
|
*/
|
|
10
14
|
export declare function getPriceDeviationBand(referencePrice: number, maxDeviation: number): {
|
|
@@ -13,10 +17,9 @@ export declare function getPriceDeviationBand(referencePrice: number, maxDeviati
|
|
|
13
17
|
} | undefined;
|
|
14
18
|
/**
|
|
15
19
|
* Whether a price is outside the inclusive band {@link getPriceDeviationBand}
|
|
16
|
-
* returns
|
|
17
|
-
* reference divided by it.
|
|
20
|
+
* returns, i.e. more than `maxDeviation` times the reference away from it.
|
|
18
21
|
*
|
|
19
|
-
* @param price - Order price.
|
|
22
|
+
* @param price - Order or market price.
|
|
20
23
|
* @param referencePrice - Oracle price, or the mark price when the oracle is unknown.
|
|
21
24
|
* @param maxDeviation - Deviation limit as a fraction, such as
|
|
22
25
|
* `PerpsOrderLimits.maxOraclePriceDeviation`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"priceDeviation.d.ts","sourceRoot":"","sources":["../../src/utils/priceDeviation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"priceDeviation.d.ts","sourceRoot":"","sources":["../../src/utils/priceDeviation.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,MAAM,GACnB;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAe1C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,MAAM,EACb,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,MAAM,GACnB,OAAO,CAQT"}
|
|
@@ -1,45 +1,36 @@
|
|
|
1
1
|
import { BigNumber } from 'bignumber.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Prices a venue accepts around a reference price under a deviation limit
|
|
4
|
+
* such as `PerpsOrderLimits.maxOraclePriceDeviation`: up to `maxDeviation`
|
|
5
|
+
* times the reference away from it on either side, so a price `p` is inside
|
|
6
|
+
* when `|p - reference| / reference <= maxDeviation`. HyperLiquid's rule
|
|
7
|
+
* ("Order price cannot be more than 95% away from the reference price") and
|
|
8
|
+
* `isMarketTradable` use this band. The lower bound never goes below 0.
|
|
9
|
+
* Bounds are computed in exact decimals, so `1 - 0.95` is exactly 0.05.
|
|
4
10
|
*
|
|
5
|
-
* @param referencePrice -
|
|
6
|
-
* @param maxDeviation - Deviation limit as a fraction.
|
|
7
|
-
* @returns The
|
|
11
|
+
* @param referencePrice - Oracle price, or the mark price when the oracle is unknown.
|
|
12
|
+
* @param maxDeviation - Deviation limit as a positive fraction.
|
|
13
|
+
* @returns The inclusive band, or undefined when either input is unusable.
|
|
8
14
|
*/
|
|
9
|
-
function
|
|
15
|
+
export function getPriceDeviationBand(referencePrice, maxDeviation) {
|
|
10
16
|
if (!Number.isFinite(referencePrice) ||
|
|
11
17
|
referencePrice <= 0 ||
|
|
12
18
|
!Number.isFinite(maxDeviation) ||
|
|
13
|
-
maxDeviation <= 0
|
|
14
|
-
maxDeviation >= 1) {
|
|
19
|
+
maxDeviation <= 0) {
|
|
15
20
|
return undefined;
|
|
16
21
|
}
|
|
17
22
|
const reference = new BigNumber(referencePrice);
|
|
18
|
-
const
|
|
23
|
+
const offset = reference.multipliedBy(maxDeviation);
|
|
19
24
|
return {
|
|
20
|
-
min: reference.
|
|
21
|
-
max: reference.
|
|
25
|
+
min: BigNumber.max(reference.minus(offset), 0).toNumber(),
|
|
26
|
+
max: reference.plus(offset).toNumber(),
|
|
22
27
|
};
|
|
23
28
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Prices a venue accepts around a reference price under a deviation limit
|
|
26
|
-
* such as `PerpsOrderLimits.maxOraclePriceDeviation`: from `1 - maxDeviation`
|
|
27
|
-
* times the reference up to the reference divided by it.
|
|
28
|
-
*
|
|
29
|
-
* @param referencePrice - Oracle price, or the mark price when the oracle is unknown.
|
|
30
|
-
* @param maxDeviation - Deviation limit as a fraction, above 0 and below 1.
|
|
31
|
-
* @returns The inclusive band, or undefined when either input is unusable.
|
|
32
|
-
*/
|
|
33
|
-
export function getPriceDeviationBand(referencePrice, maxDeviation) {
|
|
34
|
-
const bounds = deviationBounds(referencePrice, maxDeviation);
|
|
35
|
-
return bounds && { min: bounds.min.toNumber(), max: bounds.max.toNumber() };
|
|
36
|
-
}
|
|
37
29
|
/**
|
|
38
30
|
* Whether a price is outside the inclusive band {@link getPriceDeviationBand}
|
|
39
|
-
* returns
|
|
40
|
-
* reference divided by it.
|
|
31
|
+
* returns, i.e. more than `maxDeviation` times the reference away from it.
|
|
41
32
|
*
|
|
42
|
-
* @param price - Order price.
|
|
33
|
+
* @param price - Order or market price.
|
|
43
34
|
* @param referencePrice - Oracle price, or the mark price when the oracle is unknown.
|
|
44
35
|
* @param maxDeviation - Deviation limit as a fraction, such as
|
|
45
36
|
* `PerpsOrderLimits.maxOraclePriceDeviation`.
|