@metamask-previews/perps-controller 22.3.0-preview-13e241f7f → 22.3.0-preview-693aef2bf

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/PerpsController-method-action-types.d.ts +14 -1
  3. package/dist/PerpsController-method-action-types.d.ts.map +1 -1
  4. package/dist/PerpsController-method-action-types.js.map +1 -1
  5. package/dist/PerpsController.d.ts +11 -1
  6. package/dist/PerpsController.d.ts.map +1 -1
  7. package/dist/PerpsController.js +24 -0
  8. package/dist/PerpsController.js.map +1 -1
  9. package/dist/constants/perpsConfig.d.ts +16 -0
  10. package/dist/constants/perpsConfig.d.ts.map +1 -1
  11. package/dist/constants/perpsConfig.js +24 -0
  12. package/dist/constants/perpsConfig.js.map +1 -1
  13. package/dist/errors.d.ts +7 -0
  14. package/dist/errors.d.ts.map +1 -1
  15. package/dist/errors.js +9 -0
  16. package/dist/errors.js.map +1 -1
  17. package/dist/index.d.ts +4 -4
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/perpsErrorCodes.d.ts +1 -0
  22. package/dist/perpsErrorCodes.d.ts.map +1 -1
  23. package/dist/perpsErrorCodes.js +1 -0
  24. package/dist/perpsErrorCodes.js.map +1 -1
  25. package/dist/providers/AggregatedPerpsProvider.d.ts +2 -1
  26. package/dist/providers/AggregatedPerpsProvider.d.ts.map +1 -1
  27. package/dist/providers/AggregatedPerpsProvider.js +9 -0
  28. package/dist/providers/AggregatedPerpsProvider.js.map +1 -1
  29. package/dist/providers/HyperLiquidProvider.d.ts +19 -1
  30. package/dist/providers/HyperLiquidProvider.d.ts.map +1 -1
  31. package/dist/providers/HyperLiquidProvider.js +120 -26
  32. package/dist/providers/HyperLiquidProvider.js.map +1 -1
  33. package/dist/providers/LighterProvider.d.ts +10 -1
  34. package/dist/providers/LighterProvider.d.ts.map +1 -1
  35. package/dist/providers/LighterProvider.js +12 -0
  36. package/dist/providers/LighterProvider.js.map +1 -1
  37. package/dist/services/TradingService.d.ts +17 -1
  38. package/dist/services/TradingService.d.ts.map +1 -1
  39. package/dist/services/TradingService.js +60 -4
  40. package/dist/services/TradingService.js.map +1 -1
  41. package/dist/types/index.d.ts +39 -0
  42. package/dist/types/index.d.ts.map +1 -1
  43. package/dist/types/index.js.map +1 -1
  44. package/dist/utils/orderCalculations.d.ts +2 -0
  45. package/dist/utils/orderCalculations.d.ts.map +1 -1
  46. package/dist/utils/orderCalculations.js +3 -1
  47. package/dist/utils/orderCalculations.js.map +1 -1
  48. package/dist/utils/perpsFormatters.d.ts +125 -53
  49. package/dist/utils/perpsFormatters.d.ts.map +1 -1
  50. package/dist/utils/perpsFormatters.js +345 -202
  51. package/dist/utils/perpsFormatters.js.map +1 -1
  52. package/dist/utils/positionProtection.d.ts +10 -1
  53. package/dist/utils/positionProtection.d.ts.map +1 -1
  54. package/dist/utils/positionProtection.js +13 -0
  55. package/dist/utils/positionProtection.js.map +1 -1
  56. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"perpsFormatters.js","sourceRoot":"","sources":["../../src/utils/perpsFormatters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,eAAe,GAChB,MAAM,6BAA6B,CAAC;AAErC,sEAAsE;AACtE,MAAM,SAAS,GAAG,IAAI,GAAG,EAA6B,CAAC;AAEvD,SAAS,eAAe,CACtB,KAAa,EACb,QAAgB,EAChB,IAAsE;IAEtE,MAAM,GAAG,GAAG,GAAG,QAAQ,IAAI,IAAI,CAAC,qBAAqB,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;IACtF,IAAI,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,SAAS,GAAG,IAAI,IAAI,CAA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,EAAE,QAAQ,IAAI,IAAI,CAAC;IAE3C,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAC1C,OAAO,QAAQ,CAAC,CAAC,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;IACzD,CAAC;IAED,MAAM,UAAU,GAAG,KAAK,GAAG,mBAAmB,CAAC,oBAAoB,CAAC;IACpE,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IACnE,MAAM,wBAAwB,GAAG,EAAE,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC;IAErE,IAAI,KAAK,KAAK,CAAC,IAAI,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/C,MAAM,SAAS,GAAG,wBAAwB,CAAC,OAAO,CAChD,mBAAmB,CAAC,QAAQ,CAC7B,CAAC;QACF,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,GAAG,CAAC;IAC1D,CAAC;IAED,0CAA0C;IAC1C,IAAI,QAAQ,IAAI,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5C,OAAO,mBAAmB,CAAC,WAAW,CAAC;IACzC,CAAC;IAED,OAAO,GAAG,SAAS,GAAG,CAAC;AACzB,CAAC,CAAC","sourcesContent":["/**\n * Portable perps decimal formatters.\n *\n * These are the canonical implementations, exported from the controller so\n * extension and any future consumer can import them directly.\n * No mobile-specific imports — safe to sync to Core.\n *\n * Intl.NumberFormat instances are cached in a module-level Map keyed by\n * serialized options, avoiding repeated construction costs.\n */\nimport {\n DECIMAL_PRECISION_CONFIG,\n FUNDING_RATE_CONFIG,\n PERPS_CONSTANTS,\n} from '../constants/perpsConfig.js';\n\n// Module-level Intl.NumberFormat cache (keyed by serialized options).\nconst _fmtCache = new Map<string, Intl.NumberFormat>();\n\nfunction _formatCurrency(\n value: number,\n currency: string,\n opts: { minimumFractionDigits: number; maximumFractionDigits: number },\n): string {\n const key = `${currency}:${opts.minimumFractionDigits}:${opts.maximumFractionDigits}`;\n let formatter = _fmtCache.get(key);\n if (!formatter) {\n formatter = new Intl.NumberFormat('en-US', {\n style: 'currency',\n currency,\n currencyDisplay: 'narrowSymbol',\n minimumFractionDigits: opts.minimumFractionDigits,\n maximumFractionDigits: opts.maximumFractionDigits,\n });\n _fmtCache.set(key, formatter);\n }\n return formatter.format(value);\n}\n\n/**\n * Internal equivalent of the mobile formatWithThreshold utility.\n * Formats a currency value, returning \"<$X.XX\" for values below threshold.\n *\n * @param amount - The numeric amount to format.\n * @param threshold - The threshold below which the \"<\" prefix is shown.\n * @param options - Intl 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 * @returns Formatted currency string.\n */\nfunction _formatWithThreshold(\n amount: number,\n threshold: number,\n options: {\n currency: string;\n minimumFractionDigits: number;\n maximumFractionDigits: number;\n },\n): string {\n const formatOpts = {\n minimumFractionDigits: options.minimumFractionDigits,\n maximumFractionDigits: options.maximumFractionDigits,\n currencyDisplay: 'narrowSymbol' as const,\n };\n if (amount === 0) {\n return _formatCurrency(0, options.currency, formatOpts);\n }\n return Math.abs(amount) < threshold\n ? `<${_formatCurrency(threshold, options.currency, formatOpts)}`\n : _formatCurrency(amount, options.currency, formatOpts);\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 * This is the minimum value for formatWithThreshold and should align with\n * the 6 decimal maximum (0.000001 is the smallest representable value)\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.000001 (<$0.01: 4 sig figs, rounds with max 6 decimals)\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.000001\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 * Formats a balance value as USD currency with appropriate decimal places\n *\n * @param balance - Raw numeric balance value (e.g., 1234.56, not token minimal denomination)\n * @param options - Optional formatting options\n * @param options.minimumDecimals - Global minimum decimal places (overrides range configs)\n * @param options.maximumDecimals - Global maximum decimal places (overrides 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.locale - Locale for formatting (default: 'en-US')\n * @param options.stripTrailingZeros - Strip trailing zeros from output (default: false via PRICE_RANGES_MINIMAL_VIEW). When true, overrides minimumDecimals constraint.\n * @returns Formatted currency string with variable decimals based on configured ranges\n * @example\n * // Using defaults (preserves trailing zeros for fiat)\n * formatPerpsFiat(1234.56) => \"$1,234.56\"\n * formatPerpsFiat(1250.00) => \"$1,250.00\" // Trailing zeros preserved\n * formatPerpsFiat(50000) => \"$50,000.00\" // Trailing zeros preserved\n *\n * // Stripping trailing zeros when needed (e.g., for crypto)\n * formatPerpsFiat(1250, { stripTrailingZeros: true }) => \"$1,250\"\n *\n * // With custom ranges\n * formatPerpsFiat(0.00001, {\n * ranges: [\n * { condition: (v) => v < 0.001, minimumDecimals: 6, maximumDecimals: 8 },\n * { condition: () => true, minimumDecimals: 2, maximumDecimals: 2 }\n * ]\n * }) => \"$0.00001\" // Trailing zero stripped\n *\n * // With significant digits\n * formatPerpsFiat(1234.56789, { significantDigits: 5 }) => \"$1,234.6\"\n * formatPerpsFiat(0.0001234, { significantDigits: 3 }) => \"$0.000123\"\n */\nexport const formatPerpsFiat = (\n balance: string | number,\n options?: {\n minimumDecimals?: number;\n maximumDecimals?: number;\n significantDigits?: number;\n ranges?: FiatRangeConfig[];\n currency?: string;\n locale?: string;\n stripTrailingZeros?: boolean;\n },\n): string => {\n const value = typeof balance === 'string' ? parseFloat(balance) : balance;\n const currency = options?.currency ?? 'USD';\n\n let formatted: string;\n\n if (isNaN(value)) {\n // Return placeholder for invalid values to avoid confusion with actual $0 values\n return PERPS_CONSTANTS.FallbackPriceDisplay;\n }\n\n // Use custom ranges or defaults\n const ranges = options?.ranges ?? PRICE_RANGES_MINIMAL_VIEW;\n\n // Find the first matching range configuration\n const rangeConfig = ranges.find((range) => range.condition(value));\n\n if (rangeConfig) {\n // Check for significant digits (global or range-specific)\n const sigDigits =\n options?.significantDigits ?? rangeConfig.significantDigits;\n\n // If significant digits are specified, use them\n if (sigDigits) {\n // Get min/max decimals (global overrides range, range overrides default)\n const minDecimals =\n options?.minimumDecimals ?? rangeConfig.minimumDecimals;\n const maxDecimals =\n options?.maximumDecimals ?? rangeConfig.maximumDecimals;\n\n // Calculate appropriate formatting based on significant digits\n const { value: formattedValue, decimals } = formatWithSignificantDigits(\n value,\n sigDigits,\n minDecimals,\n maxDecimals,\n );\n\n // Format with the calculated decimal places\n formatted = _formatWithThreshold(\n formattedValue,\n rangeConfig.threshold ?? 0.01,\n {\n currency,\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n },\n );\n } else {\n // Standard decimal-based formatting (existing logic)\n const minDecimals =\n options?.minimumDecimals ?? rangeConfig.minimumDecimals;\n const maxDecimals =\n options?.maximumDecimals ?? rangeConfig.maximumDecimals;\n\n // Use custom formatting if provided\n if (rangeConfig.customFormat) {\n formatted = rangeConfig.customFormat(\n value,\n options?.locale ?? 'en-US',\n currency,\n );\n } else {\n // Use standard formatting with threshold\n formatted = _formatWithThreshold(value, rangeConfig.threshold ?? 0.01, {\n currency,\n minimumFractionDigits: minDecimals,\n maximumFractionDigits: maxDecimals,\n });\n }\n }\n } else {\n // Fallback if no range matches (shouldn't happen with proper default config)\n const fallbackMin = options?.minimumDecimals ?? 2;\n const fallbackMax = options?.maximumDecimals ?? 2;\n formatted = _formatWithThreshold(value, 0.01, {\n currency,\n minimumFractionDigits: fallbackMin,\n maximumFractionDigits: fallbackMax,\n });\n }\n\n // Post-process: strip trailing zeros unless explicitly disabled\n // Priority: explicit options.stripTrailingZeros false > rangeConfig > options default > true\n // If options.stripTrailingZeros is explicitly false, skip stripping entirely\n if (options?.stripTrailingZeros === false) {\n return formatted;\n }\n\n // Otherwise check range config or default to true\n const shouldStrip =\n rangeConfig?.stripTrailingZeros ?? options?.stripTrailingZeros ?? true;\n\n if (shouldStrip) {\n // Check if fiat-style stripping is enabled (only strips .00)\n const useFiatStyle = rangeConfig?.fiatStyleStripping ?? false;\n\n if (useFiatStyle) {\n // Fiat-style: Only strip .00 (no meaningful decimals), preserve 2-decimal format\n // Examples: $1,250.00 → $1,250 | $1,000.10 → $1,000.10 | $13.40 → $13.40\n return formatted.replace(/\\.00$/u, '');\n }\n // Standard: Strip all trailing zeros after decimal point\n // Examples: $1,250.00 → $1,250 | $100.0 → $100 | $10.5 → $10.5 | $1.234 → $1.234\n return formatted.replace(/(\\.\\d*?)0+$/u, '$1').replace(/\\.$/u, '');\n }\n\n return formatted;\n};\n\n/**\n * Formats position size with variable decimal precision based on magnitude or asset-specific decimals\n * Removes trailing zeros to match task requirements\n *\n * @param size - Raw position size value\n * @param szDecimals - Optional asset-specific decimal precision from Hyperliquid metadata (e.g., BTC=5, ETH=4, DOGE=1)\n * @returns Format varies by size or uses asset-specific decimals, with trailing zeros removed:\n * If szDecimals provided: Uses exact 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 * @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(44.00) => \"44\" (no szDecimals, uses magnitude logic)\n */\nexport const formatPositionSize = (\n size: string | number,\n szDecimals?: number,\n): string => {\n const value = typeof size === 'string' ? parseFloat(size) : size;\n\n if (isNaN(value) || value === 0) {\n return '0';\n }\n\n // Use asset-specific decimals if provided (Hyperliquid metadata)\n if (szDecimals !== undefined) {\n const fixed = value.toFixed(szDecimals);\n // Only strip trailing zeros when a decimal point is present; toFixed(0)\n // returns an integer string and the regex would otherwise eat valid zeros\n // on whole-unit assets (szDecimals=0), e.g. \"100\" -> \"1\".\n return fixed.includes('.') ? fixed.replace(/\\.?0+$/u, '') : fixed;\n }\n\n // Fallback: magnitude-based decimal logic for backwards compatibility\n const abs = Math.abs(value);\n let formatted: string;\n\n if (abs < 0.01) {\n // For very small numbers, use more decimal places\n formatted = value.toFixed(6);\n } else if (abs < 1) {\n // For small numbers, use 4 decimal places\n formatted = value.toFixed(4);\n } else {\n // For normal numbers, use 2 decimal places\n formatted = value.toFixed(2);\n }\n\n // Remove trailing zeros and unnecessary decimal point\n return formatted.replace(/\\.?0+$/u, '');\n};\n\n/**\n * Formats a PnL (Profit and Loss) value with sign prefix\n *\n * @param pnl - Raw numeric PnL value (positive for profit, negative for loss)\n * @returns Format: \"+$X,XXX.XX\" or \"-$X,XXX.XX\" (always shows sign, 2 decimals)\n * @example formatPnl(1234.56) => \"+$1,234.56\"\n * @example formatPnl(-500) => \"-$500.00\"\n * @example formatPnl(0) => \"+$0.00\"\n */\nexport const formatPnl = (pnl: string | number): string => {\n const value = typeof pnl === 'string' ? parseFloat(pnl) : pnl;\n\n if (isNaN(value)) {\n return PERPS_CONSTANTS.ZeroAmountDetailedDisplay;\n }\n\n const formatted = _formatCurrency(Math.abs(value), 'USD', {\n minimumFractionDigits: 2,\n maximumFractionDigits: 2,\n });\n\n return value >= 0 ? `+${formatted}` : `-${formatted}`;\n};\n\n/**\n * Formats a percentage value with sign prefix\n *\n * @param value - Raw percentage value (e.g., 5.25 for 5.25%, not 0.0525)\n * @param decimals - Number of decimal places to show (default: 2)\n * @returns Format: \"+X.XX%\" or \"-X.XX%\" (always shows sign, 2 decimals)\n * @example formatPercentage(5.25) => \"+5.25%\"\n * @example formatPercentage(-2.75) => \"-2.75%\"\n * @example formatPercentage(0) => \"+0.00%\"\n */\nexport const formatPercentage = (\n value: string | number,\n decimals: number = 2,\n): string => {\n const parsed = typeof value === 'string' ? parseFloat(value) : value;\n\n if (isNaN(parsed)) {\n return '0.00%';\n }\n\n return `${parsed >= 0 ? '+' : ''}${parsed.toFixed(decimals)}%`;\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 - Whether to return zero display value for zero/undefined (default: true)\n * @returns Formatted funding rate as percentage string\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(undefined) => \"0.0000%\"\n */\nexport const formatFundingRate = (\n value?: number | null,\n options?: { showZero?: boolean },\n): string => {\n const showZero = options?.showZero ?? true;\n\n if (value === undefined || value === null) {\n return showZero ? FUNDING_RATE_CONFIG.ZeroDisplay : '';\n }\n\n const percentage = value * FUNDING_RATE_CONFIG.PercentageMultiplier;\n const formatted = percentage.toFixed(FUNDING_RATE_CONFIG.Decimals);\n const minimumDisplayPercentage = 10 ** -FUNDING_RATE_CONFIG.Decimals;\n\n if (value !== 0 && parseFloat(formatted) === 0) {\n const threshold = minimumDisplayPercentage.toFixed(\n FUNDING_RATE_CONFIG.Decimals,\n );\n return value > 0 ? `<${threshold}%` : `-<${threshold}%`;\n }\n\n // Check if the result is effectively zero\n if (showZero && parseFloat(formatted) === 0) {\n return FUNDING_RATE_CONFIG.ZeroDisplay;\n }\n\n return `${formatted}%`;\n};\n"]}
1
+ {"version":3,"file":"perpsFormatters.js","sourceRoot":"","sources":["../../src/utils/perpsFormatters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,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,cA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;;;GAiBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,KAA8B,EAC9B,OAAO,GAAkC,EAAE,EACnC,EAAE;IACV,MAAM,EACJ,QAAQ,GAAG,IAAI,EACf,UAAU,GAAG,mBAAmB,EAChC,QAAQ,GAAG,uBAAuB,CAAC,kBAAkB,EACrD,IAAI,GAAG,MAAM,GACd,GAAG,OAAO,CAAC;IACZ,MAAM,IAAI,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IACxC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,yBAAyB,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,GAAG,mBAAmB,CAAC,oBAAoB,CAAC;IACnE,+DAA+D;IAC/D,IAAI,IAAI,KAAK,CAAC,IAAI,iBAAiB,CAAC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAChE,MAAM,OAAO,GAAG,cAAc,CAC5B,UAAU,EACV,EAAE,IAAI,CAAC,QAAQ,EACf,QAAQ,EACR,QAAQ,EACR,IAAI,CACL,CAAC;QACF,OAAO,GAAG,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,OAAO,GAAG,CAAC;IACzD,CAAC;IAED,OAAO,GAAG,oBAAoB,CAAC,UAAU,EAAE,UAAU,EAAE;QACrD,qBAAqB,EAAE,QAAQ;QAC/B,qBAAqB,EAAE,QAAQ;QAC/B,WAAW,EAAE,IAAI;QACjB,IAAI;KACL,CAAC,GAAG,CAAC;AACR,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 {\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 * @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 },\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 return formatters.formatCurrency(amount, options.currency, {\n currencyDisplay: 'narrowSymbol',\n minimumFractionDigits,\n maximumFractionDigits,\n });\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 * This is the minimum value for formatWithThreshold and should align with\n * the 6 decimal maximum (0.000001 is the smallest representable value)\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.000001 (<$0.01: 4 sig figs, rounds with max 6 decimals)\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.000001\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\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 * @returns Formatted currency string, or `PERPS_CONSTANTS.FallbackPriceDisplay`\n * (`$---`) for a missing value.\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(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 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 },\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 * 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`) and `sign` (default `always`).\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(undefined) => \"--%\"\n */\nexport const formatPercentage = (\n value: string | number | null | undefined,\n decimalsOrOptions?: number | PerpsDisplayFormatOptions,\n): string => {\n const {\n formatters = _fallbackFormatters,\n decimals = PERPS_DISPLAY_PRECISION.Percentage,\n sign = 'always',\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: decimals,\n maximumFractionDigits: decimals,\n useGrouping: true,\n sign,\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"]}
@@ -1,4 +1,4 @@
1
- import type { UpdatePositionTPSLParams } from '../types/index.js';
1
+ import type { ReplacePositionTPSLLegParams, UpdatePositionTPSLParams } from '../types/index.js';
2
2
  /**
3
3
  * Reject a protection mutation whose caller-owned position no longer matches.
4
4
  *
@@ -9,4 +9,13 @@ export declare function assertExpectedPosition(expected: UpdatePositionTPSLParam
9
9
  size: string;
10
10
  entryPrice: string;
11
11
  } | undefined): void;
12
+ /**
13
+ * Express a single-leg replace as the TP/SL price of a whole-position update.
14
+ *
15
+ * @param params - The leg replacement.
16
+ * @param params.leg - 'tp' or 'sl'.
17
+ * @param params.triggerPrice - New trigger price for that leg.
18
+ * @returns The take profit or stop loss price field for that leg.
19
+ */
20
+ export declare function toPositionTpslLegPrices({ leg, triggerPrice, }: Pick<ReplacePositionTPSLLegParams, 'leg' | 'triggerPrice'>): Pick<UpdatePositionTPSLParams, 'takeProfitPrice' | 'stopLossPrice'>;
12
21
  //# sourceMappingURL=positionProtection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"positionProtection.d.ts","sourceRoot":"","sources":["../../src/utils/positionProtection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAElE;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,wBAAwB,CAAC,kBAAkB,CAAC,EACtD,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,GACvD,IAAI,CAyBN"}
1
+ {"version":3,"file":"positionProtection.d.ts","sourceRoot":"","sources":["../../src/utils/positionProtection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,4BAA4B,EAC5B,wBAAwB,EACzB,MAAM,mBAAmB,CAAC;AAE3B;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,wBAAwB,CAAC,kBAAkB,CAAC,EACtD,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,GACvD,IAAI,CAyBN;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,GAAG,EACH,YAAY,GACb,EAAE,IAAI,CAAC,4BAA4B,EAAE,KAAK,GAAG,cAAc,CAAC,GAAG,IAAI,CAClE,wBAAwB,EACxB,iBAAiB,GAAG,eAAe,CACpC,CAIA"}
@@ -26,4 +26,17 @@ export function assertExpectedPosition(expected, actual) {
26
26
  throw new Error(PERPS_ERROR_CODES.TPSL_UPDATE_FAILED);
27
27
  }
28
28
  }
29
+ /**
30
+ * Express a single-leg replace as the TP/SL price of a whole-position update.
31
+ *
32
+ * @param params - The leg replacement.
33
+ * @param params.leg - 'tp' or 'sl'.
34
+ * @param params.triggerPrice - New trigger price for that leg.
35
+ * @returns The take profit or stop loss price field for that leg.
36
+ */
37
+ export function toPositionTpslLegPrices({ leg, triggerPrice, }) {
38
+ return leg === 'tp'
39
+ ? { takeProfitPrice: triggerPrice }
40
+ : { stopLossPrice: triggerPrice };
41
+ }
29
42
  //# sourceMappingURL=positionProtection.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"positionProtection.js","sourceRoot":"","sources":["../../src/utils/positionProtection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG1D;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,QAAsD,EACtD,MAAwD;IAExD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO;IACT,CAAC;IACD,MAAM,OAAO,GAAG,8BAA8B,CAAC;IAC/C,IACE,CAAC,MAAM;QACP,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,CACzE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAC5D,EACD,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,YAAY,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAClD,MAAM,kBAAkB,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC9D,IACE,CAAC,YAAY,CAAC,QAAQ,EAAE;QACxB,YAAY,CAAC,MAAM,EAAE;QACrB,CAAC,kBAAkB,CAAC,QAAQ,EAAE;QAC9B,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,CAAC;QACzB,CAAC,YAAY,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;QAC7B,CAAC,kBAAkB,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,EACzC,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;IACxD,CAAC;AACH,CAAC","sourcesContent":["import { BigNumber } from 'bignumber.js';\n\nimport { PERPS_ERROR_CODES } from '../perpsErrorCodes.js';\nimport type { UpdatePositionTPSLParams } from '../types/index.js';\n\n/**\n * Reject a protection mutation whose caller-owned position no longer matches.\n *\n * @param expected - Optional immutable caller precondition.\n * @param actual - Authoritative current position, if any.\n */\nexport function assertExpectedPosition(\n expected: UpdatePositionTPSLParams['expectedPosition'],\n actual: { size: string; entryPrice: string } | undefined,\n): void {\n if (expected === undefined) {\n return;\n }\n const decimal = /^-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)$/u;\n if (\n !actual ||\n ![expected.size, expected.entryPrice, actual.size, actual.entryPrice].every(\n (value) => typeof value === 'string' && decimal.test(value),\n )\n ) {\n throw new Error(PERPS_ERROR_CODES.TPSL_UPDATE_FAILED);\n }\n const expectedSize = new BigNumber(expected.size);\n const expectedEntryPrice = new BigNumber(expected.entryPrice);\n if (\n !expectedSize.isFinite() ||\n expectedSize.isZero() ||\n !expectedEntryPrice.isFinite() ||\n !expectedEntryPrice.gt(0) ||\n !expectedSize.eq(actual.size) ||\n !expectedEntryPrice.eq(actual.entryPrice)\n ) {\n throw new Error(PERPS_ERROR_CODES.TPSL_UPDATE_FAILED);\n }\n}\n"]}
1
+ {"version":3,"file":"positionProtection.js","sourceRoot":"","sources":["../../src/utils/positionProtection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAM1D;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,QAAsD,EACtD,MAAwD;IAExD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO;IACT,CAAC;IACD,MAAM,OAAO,GAAG,8BAA8B,CAAC;IAC/C,IACE,CAAC,MAAM;QACP,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,CACzE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAC5D,EACD,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,YAAY,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAClD,MAAM,kBAAkB,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC9D,IACE,CAAC,YAAY,CAAC,QAAQ,EAAE;QACxB,YAAY,CAAC,MAAM,EAAE;QACrB,CAAC,kBAAkB,CAAC,QAAQ,EAAE;QAC9B,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,CAAC;QACzB,CAAC,YAAY,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;QAC7B,CAAC,kBAAkB,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,EACzC,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;IACxD,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAC,EACtC,GAAG,EACH,YAAY,GAC+C;IAI3D,OAAO,GAAG,KAAK,IAAI;QACjB,CAAC,CAAC,EAAE,eAAe,EAAE,YAAY,EAAE;QACnC,CAAC,CAAC,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;AACtC,CAAC","sourcesContent":["import { BigNumber } from 'bignumber.js';\n\nimport { PERPS_ERROR_CODES } from '../perpsErrorCodes.js';\nimport type {\n ReplacePositionTPSLLegParams,\n UpdatePositionTPSLParams,\n} from '../types/index.js';\n\n/**\n * Reject a protection mutation whose caller-owned position no longer matches.\n *\n * @param expected - Optional immutable caller precondition.\n * @param actual - Authoritative current position, if any.\n */\nexport function assertExpectedPosition(\n expected: UpdatePositionTPSLParams['expectedPosition'],\n actual: { size: string; entryPrice: string } | undefined,\n): void {\n if (expected === undefined) {\n return;\n }\n const decimal = /^-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)$/u;\n if (\n !actual ||\n ![expected.size, expected.entryPrice, actual.size, actual.entryPrice].every(\n (value) => typeof value === 'string' && decimal.test(value),\n )\n ) {\n throw new Error(PERPS_ERROR_CODES.TPSL_UPDATE_FAILED);\n }\n const expectedSize = new BigNumber(expected.size);\n const expectedEntryPrice = new BigNumber(expected.entryPrice);\n if (\n !expectedSize.isFinite() ||\n expectedSize.isZero() ||\n !expectedEntryPrice.isFinite() ||\n !expectedEntryPrice.gt(0) ||\n !expectedSize.eq(actual.size) ||\n !expectedEntryPrice.eq(actual.entryPrice)\n ) {\n throw new Error(PERPS_ERROR_CODES.TPSL_UPDATE_FAILED);\n }\n}\n\n/**\n * Express a single-leg replace as the TP/SL price of a whole-position update.\n *\n * @param params - The leg replacement.\n * @param params.leg - 'tp' or 'sl'.\n * @param params.triggerPrice - New trigger price for that leg.\n * @returns The take profit or stop loss price field for that leg.\n */\nexport function toPositionTpslLegPrices({\n leg,\n triggerPrice,\n}: Pick<ReplacePositionTPSLLegParams, 'leg' | 'triggerPrice'>): Pick<\n UpdatePositionTPSLParams,\n 'takeProfitPrice' | 'stopLossPrice'\n> {\n return leg === 'tp'\n ? { takeProfitPrice: triggerPrice }\n : { stopLossPrice: triggerPrice };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/perps-controller",
3
- "version": "22.3.0-preview-13e241f7f",
3
+ "version": "22.3.0-preview-693aef2bf",
4
4
  "description": "Controller for perpetual trading functionality in MetaMask",
5
5
  "keywords": [
6
6
  "Ethereum",