@metamask-previews/perps-controller 3.0.0-preview-e61cfa5 → 3.1.0-preview-548bdd1d9

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 (90) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/dist/PerpsController-method-action-types.cjs.map +1 -1
  3. package/dist/PerpsController-method-action-types.d.cts +8 -0
  4. package/dist/PerpsController-method-action-types.d.cts.map +1 -1
  5. package/dist/PerpsController-method-action-types.d.mts +8 -0
  6. package/dist/PerpsController-method-action-types.d.mts.map +1 -1
  7. package/dist/PerpsController-method-action-types.mjs.map +1 -1
  8. package/dist/PerpsController.cjs +117 -29
  9. package/dist/PerpsController.cjs.map +1 -1
  10. package/dist/PerpsController.d.cts +14 -2
  11. package/dist/PerpsController.d.cts.map +1 -1
  12. package/dist/PerpsController.d.mts +14 -2
  13. package/dist/PerpsController.d.mts.map +1 -1
  14. package/dist/PerpsController.mjs +118 -30
  15. package/dist/PerpsController.mjs.map +1 -1
  16. package/dist/constants/eventNames.cjs +1 -0
  17. package/dist/constants/eventNames.cjs.map +1 -1
  18. package/dist/constants/eventNames.d.cts +1 -0
  19. package/dist/constants/eventNames.d.cts.map +1 -1
  20. package/dist/constants/eventNames.d.mts +1 -0
  21. package/dist/constants/eventNames.d.mts.map +1 -1
  22. package/dist/constants/eventNames.mjs +1 -0
  23. package/dist/constants/eventNames.mjs.map +1 -1
  24. package/dist/constants/perpsConfig.cjs +46 -1
  25. package/dist/constants/perpsConfig.cjs.map +1 -1
  26. package/dist/constants/perpsConfig.d.cts +35 -0
  27. package/dist/constants/perpsConfig.d.cts.map +1 -1
  28. package/dist/constants/perpsConfig.d.mts +35 -0
  29. package/dist/constants/perpsConfig.d.mts.map +1 -1
  30. package/dist/constants/perpsConfig.mjs +43 -0
  31. package/dist/constants/perpsConfig.mjs.map +1 -1
  32. package/dist/constants/transactionsHistoryConfig.cjs +23 -4
  33. package/dist/constants/transactionsHistoryConfig.cjs.map +1 -1
  34. package/dist/constants/transactionsHistoryConfig.d.cts +23 -4
  35. package/dist/constants/transactionsHistoryConfig.d.cts.map +1 -1
  36. package/dist/constants/transactionsHistoryConfig.d.mts +23 -4
  37. package/dist/constants/transactionsHistoryConfig.d.mts.map +1 -1
  38. package/dist/constants/transactionsHistoryConfig.mjs +23 -4
  39. package/dist/constants/transactionsHistoryConfig.mjs.map +1 -1
  40. package/dist/index.cjs +14 -3
  41. package/dist/index.cjs.map +1 -1
  42. package/dist/index.d.cts +3 -1
  43. package/dist/index.d.cts.map +1 -1
  44. package/dist/index.d.mts +3 -1
  45. package/dist/index.d.mts.map +1 -1
  46. package/dist/index.mjs +2 -1
  47. package/dist/index.mjs.map +1 -1
  48. package/dist/providers/HyperLiquidProvider.cjs +83 -27
  49. package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
  50. package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
  51. package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
  52. package/dist/providers/HyperLiquidProvider.mjs +83 -27
  53. package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
  54. package/dist/services/HyperLiquidSubscriptionService.cjs +6 -0
  55. package/dist/services/HyperLiquidSubscriptionService.cjs.map +1 -1
  56. package/dist/services/HyperLiquidSubscriptionService.d.cts.map +1 -1
  57. package/dist/services/HyperLiquidSubscriptionService.d.mts.map +1 -1
  58. package/dist/services/HyperLiquidSubscriptionService.mjs +6 -0
  59. package/dist/services/HyperLiquidSubscriptionService.mjs.map +1 -1
  60. package/dist/types/index.cjs.map +1 -1
  61. package/dist/types/index.d.cts +6 -0
  62. package/dist/types/index.d.cts.map +1 -1
  63. package/dist/types/index.d.mts +6 -0
  64. package/dist/types/index.d.mts.map +1 -1
  65. package/dist/types/index.mjs.map +1 -1
  66. package/dist/utils/index.cjs +2 -0
  67. package/dist/utils/index.cjs.map +1 -1
  68. package/dist/utils/index.d.cts +2 -0
  69. package/dist/utils/index.d.cts.map +1 -1
  70. package/dist/utils/index.d.mts +2 -0
  71. package/dist/utils/index.d.mts.map +1 -1
  72. package/dist/utils/index.mjs +2 -0
  73. package/dist/utils/index.mjs.map +1 -1
  74. package/dist/utils/perpsDiskPersistence.cjs +252 -0
  75. package/dist/utils/perpsDiskPersistence.cjs.map +1 -0
  76. package/dist/utils/perpsDiskPersistence.d.cts +108 -0
  77. package/dist/utils/perpsDiskPersistence.d.cts.map +1 -0
  78. package/dist/utils/perpsDiskPersistence.d.mts +108 -0
  79. package/dist/utils/perpsDiskPersistence.d.mts.map +1 -0
  80. package/dist/utils/perpsDiskPersistence.mjs +244 -0
  81. package/dist/utils/perpsDiskPersistence.mjs.map +1 -0
  82. package/dist/utils/perpsFormatters.cjs +498 -0
  83. package/dist/utils/perpsFormatters.cjs.map +1 -0
  84. package/dist/utils/perpsFormatters.d.cts +202 -0
  85. package/dist/utils/perpsFormatters.d.cts.map +1 -0
  86. package/dist/utils/perpsFormatters.d.mts +202 -0
  87. package/dist/utils/perpsFormatters.d.mts.map +1 -0
  88. package/dist/utils/perpsFormatters.mjs +489 -0
  89. package/dist/utils/perpsFormatters.mjs.map +1 -0
  90. package/package.json +3 -3
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Price threshold constants for PRICE_RANGES_UNIVERSAL
3
+ * These define the boundaries between different formatting ranges
4
+ */
5
+ export declare const PRICE_THRESHOLD: {
6
+ /** Very high values boundary (> $100k) */
7
+ readonly VERY_HIGH: 100000;
8
+ /** High values boundary (> $10k) */
9
+ readonly HIGH: 10000;
10
+ /** Large values boundary (> $1k) */
11
+ readonly LARGE: 1000;
12
+ /** Medium values boundary (> $100) */
13
+ readonly MEDIUM: 100;
14
+ /** Medium-low values boundary (> $10) */
15
+ readonly MEDIUM_LOW: 10;
16
+ /** Low values boundary (>= $0.01) */
17
+ readonly LOW: 0.01;
18
+ /**
19
+ * Very small values threshold (< $0.01)
20
+ * This is the minimum value for formatWithThreshold and should align with
21
+ * the 6 decimal maximum (0.000001 is the smallest representable value)
22
+ */
23
+ readonly VERY_SMALL: 0.000001;
24
+ };
25
+ /**
26
+ * Configuration for a specific number range formatting
27
+ */
28
+ export type FiatRangeConfig = {
29
+ /**
30
+ * The condition to match for this range (e.g., < 0.0001, < 1, >= 1000)
31
+ * Function should return true if this config should be applied
32
+ */
33
+ condition: (value: number) => boolean;
34
+ /** Minimum decimal places for this range */
35
+ minimumDecimals: number;
36
+ /** Maximum decimal places for this range */
37
+ maximumDecimals: number;
38
+ /** Optional threshold for formatWithThreshold (defaults to the range boundary) */
39
+ threshold?: number;
40
+ /** Optional significant digits for this range (overrides decimal places when set) */
41
+ significantDigits?: number;
42
+ /** Optional custom formatting logic for this range */
43
+ customFormat?: (value: number, locale: string, currency: string) => string;
44
+ /** Optional flag to strip trailing zeros for this range (overrides global stripTrailingZeros option) */
45
+ stripTrailingZeros?: boolean;
46
+ /**
47
+ * Optional flag for fiat-style stripping (only strips .00, preserves meaningful decimals like .10, .40)
48
+ * When true, "$1,250.00" → "$1,250" but "$1,250.10" stays "$1,250.10"
49
+ * When false (default), strips all trailing zeros: "$1,250.10" → "$1,250.1"
50
+ */
51
+ fiatStyleStripping?: boolean;
52
+ };
53
+ /**
54
+ * Formats a number to a specific number of significant digits
55
+ * Strips trailing zeros unless minDecimals requires them
56
+ *
57
+ * @param value - The numeric value to format
58
+ * @param significantDigits - Number of significant digits to maintain
59
+ * @param minDecimals - Minimum decimal places to show (may add zeros)
60
+ * @param maxDecimals - Maximum decimal places allowed
61
+ * @returns Formatted number with appropriate precision, trailing zeros removed
62
+ */
63
+ export declare function formatWithSignificantDigits(value: number, significantDigits: number, minDecimals?: number, maxDecimals?: number): {
64
+ value: number;
65
+ decimals: number;
66
+ };
67
+ /**
68
+ * Minimal view fiat range configuration
69
+ * Uses fiat-style stripping for clean currency display
70
+ * Strips only .00 to avoid partial decimals like $1,250.1
71
+ */
72
+ export declare const PRICE_RANGES_MINIMAL_VIEW: FiatRangeConfig[];
73
+ /**
74
+ * Universal price range configuration following comprehensive rules from rules-decimals.md
75
+ *
76
+ * Rules:
77
+ * - Max 6 decimals across all ranges (Hyperliquid limit)
78
+ * - Strip trailing zeros by default
79
+ * - Use |v| (absolute value) for conditions
80
+ *
81
+ * Significant digits by range:
82
+ * - > $100,000: 6 sig digs
83
+ * - $100,000 > x > $0.01: 5 sig digs
84
+ * - < $0.01: 4 sig digs
85
+ *
86
+ * Decimal limits by price range:
87
+ * - |v| > 10,000: min 0, max 0 decimals; 5 sig digs (6 if >100k)
88
+ * - |v| > 1,000: min 0, max 1 decimal; 5 sig digs
89
+ * - |v| > 100: min 0, max 2 decimals; 5 sig digs
90
+ * - |v| > 10: min 0, max 4 decimals; 5 sig digs
91
+ * - |v| ≥ 0.01: 5 sig digs, min 2, max 6 decimals
92
+ * - |v| < 0.01: 4 sig digs, min 2, max 6 decimals
93
+ *
94
+ * Examples:
95
+ * - $123,456.78 → $123,457 (>$10k: 0 decimals, 6 sig figs)
96
+ * - $12,345.67 → $12,346 (>$10k: 0 decimals, 5 sig figs)
97
+ * - $1,234.56 → $1,234.6 ($1k-$10k: 1 decimal, 5 sig figs)
98
+ * - $123.456 → $123.46 ($100-$1k: 2 decimals, 5 sig figs)
99
+ * - $12.34567 → $12.346 ($10-$100: 4 decimals, 5 sig figs)
100
+ * - $1.3445555 → $1.3446 (≥$0.01: 5 sig figs)
101
+ * - $0.333333 → $0.33333 (≥$0.01: 5 sig figs)
102
+ * - $0.004236 → $0.004236 (<$0.01: 4 sig figs, max 6 decimals)
103
+ * - $0.0000006 → $0.000001 (<$0.01: 4 sig figs, rounds with max 6 decimals)
104
+ */
105
+ export declare const PRICE_RANGES_UNIVERSAL: FiatRangeConfig[];
106
+ /**
107
+ * Formats a balance value as USD currency with appropriate decimal places
108
+ *
109
+ * @param balance - Raw numeric balance value (e.g., 1234.56, not token minimal denomination)
110
+ * @param options - Optional formatting options
111
+ * @param options.minimumDecimals - Global minimum decimal places (overrides range configs)
112
+ * @param options.maximumDecimals - Global maximum decimal places (overrides range configs)
113
+ * @param options.significantDigits - Global significant digits (overrides decimal settings when set)
114
+ * @param options.ranges - Custom range configurations (defaults to PRICE_RANGES_MINIMAL_VIEW)
115
+ * @param options.currency - Currency code (default: 'USD')
116
+ * @param options.locale - Locale for formatting (default: 'en-US')
117
+ * @param options.stripTrailingZeros - Strip trailing zeros from output (default: false via PRICE_RANGES_MINIMAL_VIEW). When true, overrides minimumDecimals constraint.
118
+ * @returns Formatted currency string with variable decimals based on configured ranges
119
+ * @example
120
+ * // Using defaults (preserves trailing zeros for fiat)
121
+ * formatPerpsFiat(1234.56) => "$1,234.56"
122
+ * formatPerpsFiat(1250.00) => "$1,250.00" // Trailing zeros preserved
123
+ * formatPerpsFiat(50000) => "$50,000.00" // Trailing zeros preserved
124
+ *
125
+ * // Stripping trailing zeros when needed (e.g., for crypto)
126
+ * formatPerpsFiat(1250, { stripTrailingZeros: true }) => "$1,250"
127
+ *
128
+ * // With custom ranges
129
+ * formatPerpsFiat(0.00001, {
130
+ * ranges: [
131
+ * { condition: (v) => v < 0.001, minimumDecimals: 6, maximumDecimals: 8 },
132
+ * { condition: () => true, minimumDecimals: 2, maximumDecimals: 2 }
133
+ * ]
134
+ * }) => "$0.00001" // Trailing zero stripped
135
+ *
136
+ * // With significant digits
137
+ * formatPerpsFiat(1234.56789, { significantDigits: 5 }) => "$1,234.6"
138
+ * formatPerpsFiat(0.0001234, { significantDigits: 3 }) => "$0.000123"
139
+ */
140
+ export declare const formatPerpsFiat: (balance: string | number, options?: {
141
+ minimumDecimals?: number;
142
+ maximumDecimals?: number;
143
+ significantDigits?: number;
144
+ ranges?: FiatRangeConfig[];
145
+ currency?: string;
146
+ locale?: string;
147
+ stripTrailingZeros?: boolean;
148
+ }) => string;
149
+ /**
150
+ * Formats position size with variable decimal precision based on magnitude or asset-specific decimals
151
+ * Removes trailing zeros to match task requirements
152
+ *
153
+ * @param size - Raw position size value
154
+ * @param szDecimals - Optional asset-specific decimal precision from Hyperliquid metadata (e.g., BTC=5, ETH=4, DOGE=1)
155
+ * @returns Format varies by size or uses asset-specific decimals, with trailing zeros removed:
156
+ * If szDecimals provided: Uses exact decimals (e.g., 0.00009 BTC with szDecimals=5 => "0.00009")
157
+ * Otherwise falls back to magnitude-based logic:
158
+ * - Size < 0.01: Up to 6 decimals (e.g., "0.00009" not "0.000090")
159
+ * - Size < 1: Up to 4 decimals (e.g., "0.0024" not "0.002400")
160
+ * - Size >= 1: Up to 2 decimals (e.g., "44" not "44.00")
161
+ * @example formatPositionSize(0.00009, 5) => "0.00009" (uses szDecimals)
162
+ * @example formatPositionSize(44.00, 1) => "44" (uses szDecimals, trailing zeros removed)
163
+ * @example formatPositionSize(0.0024) => "0.0024" (no szDecimals, uses magnitude logic)
164
+ * @example formatPositionSize(44.00) => "44" (no szDecimals, uses magnitude logic)
165
+ */
166
+ export declare const formatPositionSize: (size: string | number, szDecimals?: number) => string;
167
+ /**
168
+ * Formats a PnL (Profit and Loss) value with sign prefix
169
+ *
170
+ * @param pnl - Raw numeric PnL value (positive for profit, negative for loss)
171
+ * @returns Format: "+$X,XXX.XX" or "-$X,XXX.XX" (always shows sign, 2 decimals)
172
+ * @example formatPnl(1234.56) => "+$1,234.56"
173
+ * @example formatPnl(-500) => "-$500.00"
174
+ * @example formatPnl(0) => "+$0.00"
175
+ */
176
+ export declare const formatPnl: (pnl: string | number) => string;
177
+ /**
178
+ * Formats a percentage value with sign prefix
179
+ *
180
+ * @param value - Raw percentage value (e.g., 5.25 for 5.25%, not 0.0525)
181
+ * @param decimals - Number of decimal places to show (default: 2)
182
+ * @returns Format: "+X.XX%" or "-X.XX%" (always shows sign, 2 decimals)
183
+ * @example formatPercentage(5.25) => "+5.25%"
184
+ * @example formatPercentage(-2.75) => "-2.75%"
185
+ * @example formatPercentage(0) => "+0.00%"
186
+ */
187
+ export declare const formatPercentage: (value: string | number, decimals?: number) => string;
188
+ /**
189
+ * Formats funding rate for display
190
+ *
191
+ * @param value - Raw funding rate value (decimal, not percentage)
192
+ * @param options - Optional formatting options
193
+ * @param options.showZero - Whether to return zero display value for zero/undefined (default: true)
194
+ * @returns Formatted funding rate as percentage string
195
+ * @example formatFundingRate(0.0005) => "0.0500%"
196
+ * @example formatFundingRate(-0.0001) => "-0.0100%"
197
+ * @example formatFundingRate(undefined) => "0.0000%"
198
+ */
199
+ export declare const formatFundingRate: (value?: number | null, options?: {
200
+ showZero?: boolean;
201
+ }) => string;
202
+ //# sourceMappingURL=perpsFormatters.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perpsFormatters.d.cts","sourceRoot":"","sources":["../../src/utils/perpsFormatters.ts"],"names":[],"mappings":"AAyEA;;;GAGG;AACH,eAAO,MAAM,eAAe;IAC1B,0CAA0C;;IAE1C,oCAAoC;;IAEpC,oCAAoC;;IAEpC,sCAAsC;;IAEtC,yCAAyC;;IAEzC,qCAAqC;;IAErC;;;;OAIG;;CAEK,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;;OAGG;IACH,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IACtC,4CAA4C;IAC5C,eAAe,EAAE,MAAM,CAAC;IACxB,4CAA4C;IAC5C,eAAe,EAAE,MAAM,CAAC;IACxB,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qFAAqF;IACrF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3E,wGAAwG;IACxG,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,MAAM,EACb,iBAAiB,EAAE,MAAM,EACzB,WAAW,CAAC,EAAE,MAAM,EACpB,WAAW,CAAC,EAAE,MAAM,GACnB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAwErC;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,EAAE,eAAe,EAmBtD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,sBAAsB,EAAE,eAAe,EAgEnD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,eAAe,YACjB,MAAM,GAAG,MAAM,YACd;IACR,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,eAAe,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,KACA,MA4GF,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kBAAkB,SACvB,MAAM,GAAG,MAAM,eACR,MAAM,KAClB,MA6BF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,QAAS,MAAM,GAAG,MAAM,KAAG,MAahD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,UACpB,MAAM,GAAG,MAAM,aACZ,MAAM,KACf,MAQF,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,WACpB,MAAM,GAAG,IAAI,YACX;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,KAC/B,MAgBF,CAAC"}
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Price threshold constants for PRICE_RANGES_UNIVERSAL
3
+ * These define the boundaries between different formatting ranges
4
+ */
5
+ export declare const PRICE_THRESHOLD: {
6
+ /** Very high values boundary (> $100k) */
7
+ readonly VERY_HIGH: 100000;
8
+ /** High values boundary (> $10k) */
9
+ readonly HIGH: 10000;
10
+ /** Large values boundary (> $1k) */
11
+ readonly LARGE: 1000;
12
+ /** Medium values boundary (> $100) */
13
+ readonly MEDIUM: 100;
14
+ /** Medium-low values boundary (> $10) */
15
+ readonly MEDIUM_LOW: 10;
16
+ /** Low values boundary (>= $0.01) */
17
+ readonly LOW: 0.01;
18
+ /**
19
+ * Very small values threshold (< $0.01)
20
+ * This is the minimum value for formatWithThreshold and should align with
21
+ * the 6 decimal maximum (0.000001 is the smallest representable value)
22
+ */
23
+ readonly VERY_SMALL: 0.000001;
24
+ };
25
+ /**
26
+ * Configuration for a specific number range formatting
27
+ */
28
+ export type FiatRangeConfig = {
29
+ /**
30
+ * The condition to match for this range (e.g., < 0.0001, < 1, >= 1000)
31
+ * Function should return true if this config should be applied
32
+ */
33
+ condition: (value: number) => boolean;
34
+ /** Minimum decimal places for this range */
35
+ minimumDecimals: number;
36
+ /** Maximum decimal places for this range */
37
+ maximumDecimals: number;
38
+ /** Optional threshold for formatWithThreshold (defaults to the range boundary) */
39
+ threshold?: number;
40
+ /** Optional significant digits for this range (overrides decimal places when set) */
41
+ significantDigits?: number;
42
+ /** Optional custom formatting logic for this range */
43
+ customFormat?: (value: number, locale: string, currency: string) => string;
44
+ /** Optional flag to strip trailing zeros for this range (overrides global stripTrailingZeros option) */
45
+ stripTrailingZeros?: boolean;
46
+ /**
47
+ * Optional flag for fiat-style stripping (only strips .00, preserves meaningful decimals like .10, .40)
48
+ * When true, "$1,250.00" → "$1,250" but "$1,250.10" stays "$1,250.10"
49
+ * When false (default), strips all trailing zeros: "$1,250.10" → "$1,250.1"
50
+ */
51
+ fiatStyleStripping?: boolean;
52
+ };
53
+ /**
54
+ * Formats a number to a specific number of significant digits
55
+ * Strips trailing zeros unless minDecimals requires them
56
+ *
57
+ * @param value - The numeric value to format
58
+ * @param significantDigits - Number of significant digits to maintain
59
+ * @param minDecimals - Minimum decimal places to show (may add zeros)
60
+ * @param maxDecimals - Maximum decimal places allowed
61
+ * @returns Formatted number with appropriate precision, trailing zeros removed
62
+ */
63
+ export declare function formatWithSignificantDigits(value: number, significantDigits: number, minDecimals?: number, maxDecimals?: number): {
64
+ value: number;
65
+ decimals: number;
66
+ };
67
+ /**
68
+ * Minimal view fiat range configuration
69
+ * Uses fiat-style stripping for clean currency display
70
+ * Strips only .00 to avoid partial decimals like $1,250.1
71
+ */
72
+ export declare const PRICE_RANGES_MINIMAL_VIEW: FiatRangeConfig[];
73
+ /**
74
+ * Universal price range configuration following comprehensive rules from rules-decimals.md
75
+ *
76
+ * Rules:
77
+ * - Max 6 decimals across all ranges (Hyperliquid limit)
78
+ * - Strip trailing zeros by default
79
+ * - Use |v| (absolute value) for conditions
80
+ *
81
+ * Significant digits by range:
82
+ * - > $100,000: 6 sig digs
83
+ * - $100,000 > x > $0.01: 5 sig digs
84
+ * - < $0.01: 4 sig digs
85
+ *
86
+ * Decimal limits by price range:
87
+ * - |v| > 10,000: min 0, max 0 decimals; 5 sig digs (6 if >100k)
88
+ * - |v| > 1,000: min 0, max 1 decimal; 5 sig digs
89
+ * - |v| > 100: min 0, max 2 decimals; 5 sig digs
90
+ * - |v| > 10: min 0, max 4 decimals; 5 sig digs
91
+ * - |v| ≥ 0.01: 5 sig digs, min 2, max 6 decimals
92
+ * - |v| < 0.01: 4 sig digs, min 2, max 6 decimals
93
+ *
94
+ * Examples:
95
+ * - $123,456.78 → $123,457 (>$10k: 0 decimals, 6 sig figs)
96
+ * - $12,345.67 → $12,346 (>$10k: 0 decimals, 5 sig figs)
97
+ * - $1,234.56 → $1,234.6 ($1k-$10k: 1 decimal, 5 sig figs)
98
+ * - $123.456 → $123.46 ($100-$1k: 2 decimals, 5 sig figs)
99
+ * - $12.34567 → $12.346 ($10-$100: 4 decimals, 5 sig figs)
100
+ * - $1.3445555 → $1.3446 (≥$0.01: 5 sig figs)
101
+ * - $0.333333 → $0.33333 (≥$0.01: 5 sig figs)
102
+ * - $0.004236 → $0.004236 (<$0.01: 4 sig figs, max 6 decimals)
103
+ * - $0.0000006 → $0.000001 (<$0.01: 4 sig figs, rounds with max 6 decimals)
104
+ */
105
+ export declare const PRICE_RANGES_UNIVERSAL: FiatRangeConfig[];
106
+ /**
107
+ * Formats a balance value as USD currency with appropriate decimal places
108
+ *
109
+ * @param balance - Raw numeric balance value (e.g., 1234.56, not token minimal denomination)
110
+ * @param options - Optional formatting options
111
+ * @param options.minimumDecimals - Global minimum decimal places (overrides range configs)
112
+ * @param options.maximumDecimals - Global maximum decimal places (overrides range configs)
113
+ * @param options.significantDigits - Global significant digits (overrides decimal settings when set)
114
+ * @param options.ranges - Custom range configurations (defaults to PRICE_RANGES_MINIMAL_VIEW)
115
+ * @param options.currency - Currency code (default: 'USD')
116
+ * @param options.locale - Locale for formatting (default: 'en-US')
117
+ * @param options.stripTrailingZeros - Strip trailing zeros from output (default: false via PRICE_RANGES_MINIMAL_VIEW). When true, overrides minimumDecimals constraint.
118
+ * @returns Formatted currency string with variable decimals based on configured ranges
119
+ * @example
120
+ * // Using defaults (preserves trailing zeros for fiat)
121
+ * formatPerpsFiat(1234.56) => "$1,234.56"
122
+ * formatPerpsFiat(1250.00) => "$1,250.00" // Trailing zeros preserved
123
+ * formatPerpsFiat(50000) => "$50,000.00" // Trailing zeros preserved
124
+ *
125
+ * // Stripping trailing zeros when needed (e.g., for crypto)
126
+ * formatPerpsFiat(1250, { stripTrailingZeros: true }) => "$1,250"
127
+ *
128
+ * // With custom ranges
129
+ * formatPerpsFiat(0.00001, {
130
+ * ranges: [
131
+ * { condition: (v) => v < 0.001, minimumDecimals: 6, maximumDecimals: 8 },
132
+ * { condition: () => true, minimumDecimals: 2, maximumDecimals: 2 }
133
+ * ]
134
+ * }) => "$0.00001" // Trailing zero stripped
135
+ *
136
+ * // With significant digits
137
+ * formatPerpsFiat(1234.56789, { significantDigits: 5 }) => "$1,234.6"
138
+ * formatPerpsFiat(0.0001234, { significantDigits: 3 }) => "$0.000123"
139
+ */
140
+ export declare const formatPerpsFiat: (balance: string | number, options?: {
141
+ minimumDecimals?: number;
142
+ maximumDecimals?: number;
143
+ significantDigits?: number;
144
+ ranges?: FiatRangeConfig[];
145
+ currency?: string;
146
+ locale?: string;
147
+ stripTrailingZeros?: boolean;
148
+ }) => string;
149
+ /**
150
+ * Formats position size with variable decimal precision based on magnitude or asset-specific decimals
151
+ * Removes trailing zeros to match task requirements
152
+ *
153
+ * @param size - Raw position size value
154
+ * @param szDecimals - Optional asset-specific decimal precision from Hyperliquid metadata (e.g., BTC=5, ETH=4, DOGE=1)
155
+ * @returns Format varies by size or uses asset-specific decimals, with trailing zeros removed:
156
+ * If szDecimals provided: Uses exact decimals (e.g., 0.00009 BTC with szDecimals=5 => "0.00009")
157
+ * Otherwise falls back to magnitude-based logic:
158
+ * - Size < 0.01: Up to 6 decimals (e.g., "0.00009" not "0.000090")
159
+ * - Size < 1: Up to 4 decimals (e.g., "0.0024" not "0.002400")
160
+ * - Size >= 1: Up to 2 decimals (e.g., "44" not "44.00")
161
+ * @example formatPositionSize(0.00009, 5) => "0.00009" (uses szDecimals)
162
+ * @example formatPositionSize(44.00, 1) => "44" (uses szDecimals, trailing zeros removed)
163
+ * @example formatPositionSize(0.0024) => "0.0024" (no szDecimals, uses magnitude logic)
164
+ * @example formatPositionSize(44.00) => "44" (no szDecimals, uses magnitude logic)
165
+ */
166
+ export declare const formatPositionSize: (size: string | number, szDecimals?: number) => string;
167
+ /**
168
+ * Formats a PnL (Profit and Loss) value with sign prefix
169
+ *
170
+ * @param pnl - Raw numeric PnL value (positive for profit, negative for loss)
171
+ * @returns Format: "+$X,XXX.XX" or "-$X,XXX.XX" (always shows sign, 2 decimals)
172
+ * @example formatPnl(1234.56) => "+$1,234.56"
173
+ * @example formatPnl(-500) => "-$500.00"
174
+ * @example formatPnl(0) => "+$0.00"
175
+ */
176
+ export declare const formatPnl: (pnl: string | number) => string;
177
+ /**
178
+ * Formats a percentage value with sign prefix
179
+ *
180
+ * @param value - Raw percentage value (e.g., 5.25 for 5.25%, not 0.0525)
181
+ * @param decimals - Number of decimal places to show (default: 2)
182
+ * @returns Format: "+X.XX%" or "-X.XX%" (always shows sign, 2 decimals)
183
+ * @example formatPercentage(5.25) => "+5.25%"
184
+ * @example formatPercentage(-2.75) => "-2.75%"
185
+ * @example formatPercentage(0) => "+0.00%"
186
+ */
187
+ export declare const formatPercentage: (value: string | number, decimals?: number) => string;
188
+ /**
189
+ * Formats funding rate for display
190
+ *
191
+ * @param value - Raw funding rate value (decimal, not percentage)
192
+ * @param options - Optional formatting options
193
+ * @param options.showZero - Whether to return zero display value for zero/undefined (default: true)
194
+ * @returns Formatted funding rate as percentage string
195
+ * @example formatFundingRate(0.0005) => "0.0500%"
196
+ * @example formatFundingRate(-0.0001) => "-0.0100%"
197
+ * @example formatFundingRate(undefined) => "0.0000%"
198
+ */
199
+ export declare const formatFundingRate: (value?: number | null, options?: {
200
+ showZero?: boolean;
201
+ }) => string;
202
+ //# sourceMappingURL=perpsFormatters.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perpsFormatters.d.mts","sourceRoot":"","sources":["../../src/utils/perpsFormatters.ts"],"names":[],"mappings":"AAyEA;;;GAGG;AACH,eAAO,MAAM,eAAe;IAC1B,0CAA0C;;IAE1C,oCAAoC;;IAEpC,oCAAoC;;IAEpC,sCAAsC;;IAEtC,yCAAyC;;IAEzC,qCAAqC;;IAErC;;;;OAIG;;CAEK,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;;OAGG;IACH,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IACtC,4CAA4C;IAC5C,eAAe,EAAE,MAAM,CAAC;IACxB,4CAA4C;IAC5C,eAAe,EAAE,MAAM,CAAC;IACxB,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qFAAqF;IACrF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3E,wGAAwG;IACxG,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,MAAM,EACb,iBAAiB,EAAE,MAAM,EACzB,WAAW,CAAC,EAAE,MAAM,EACpB,WAAW,CAAC,EAAE,MAAM,GACnB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAwErC;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,EAAE,eAAe,EAmBtD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,sBAAsB,EAAE,eAAe,EAgEnD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,eAAe,YACjB,MAAM,GAAG,MAAM,YACd;IACR,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,eAAe,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,KACA,MA4GF,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kBAAkB,SACvB,MAAM,GAAG,MAAM,eACR,MAAM,KAClB,MA6BF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,QAAS,MAAM,GAAG,MAAM,KAAG,MAahD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,UACpB,MAAM,GAAG,MAAM,aACZ,MAAM,KACf,MAQF,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,WACpB,MAAM,GAAG,IAAI,YACX;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,KAC/B,MAgBF,CAAC"}