@liberfi.io/utils 0.2.27 → 0.2.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -140,118 +140,195 @@ declare class SafeBigNumber extends BigNumber {
140
140
  */
141
141
  declare const isValidNumber: (num: unknown) => boolean;
142
142
  type FormatAmountOptions = {
143
- showPlusGtThanZero: boolean;
143
+ showPlusGtThanZero?: boolean;
144
144
  };
145
145
  /**
146
146
  * Format a raw token / asset amount (no currency symbol).
147
147
  *
148
- * Precision tiers (ROUND_DOWN):
149
- * | Range | Format | Example input → output |
150
- * |---------------|-------------------------|------------------------------|
151
- * | < 0.001 | 5 decimal places | 0.0001234 → "0.00012" |
152
- * | < 1 | 3 decimal places | 0.56789 → "0.567" |
153
- * | < 100 | 2 decimal places | 42.678 → "42.67" |
154
- * | < 100 000 | grouped, 2 dp | 12345.6 → "12,345.60" |
155
- * | 100 000 | abbreviated (K/M/B/T) | 1_500_000 → "1.5M" |
148
+ * Use cases:
149
+ * - Activity-list quantity column from `base_amount`.
150
+ * - Activity-list total in native token mode before the UI appends a symbol.
151
+ * - Holder, trader, transaction, and token balance counts where compact
152
+ * K/M/B/T output is acceptable.
153
+ *
154
+ * Examples:
155
+ * - `41.8701` -> `"41.87"`
156
+ * - `1.087` -> `"1.087"`
157
+ * - `0.000032564` -> `"0.0₄3256"`
158
+ * - `12345.6` -> `"12.3K"`
159
+ * - `2089491826.331852` -> `"2.08B"`
156
160
  *
157
161
  * @param num - The numeric value.
158
162
  * @param options.showPlusGtThanZero - Prefix positive values with "+".
159
163
  */
160
164
  declare const formatAmount: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
161
165
  /**
162
- * Format a USD dollar amount with "$" prefix (standard precision).
166
+ * Format an amount with "$" prefix.
163
167
  *
164
- * Precision tiers (ROUND_DOWN):
165
- * | Range | Format | Example input output |
166
- * |---------------|-------------------------|------------------------------|
167
- * | < 0.001 | "$0" | 0.00001 → "$0" |
168
- * | < 1 | 3 decimal places | 0.56789 → "$0.567" |
169
- * | < 100 | 2 decimal places | 42.678 → "$42.67" |
170
- * | < 10 000 | grouped, 2 dp | 1234.5 → "$1,234.50" |
171
- * | ≥ 10 000 | abbreviated (K/M/B/T) | 1_500_000 → "$1.5M" |
168
+ * Use cases:
169
+ * - Activity-list total in USD mode from `amount_usd`.
170
+ * - USD notional amount displays where the numeric body should match
171
+ * `formatSignificantCompactNumber`.
172
+ * - Compact USD volume / liquidity text when 4 significant digits are enough.
172
173
  *
173
- * Use this for standard financial displays (volume, market cap, liquidity).
174
+ * Examples:
175
+ * - `96.32167791184` -> `"$96.32"`
176
+ * - `0.000032564` -> `"$0.0₄3256"`
177
+ * - `12345.6` -> `"$12.3K"`
178
+ * - `2089491826.331852` -> `"$2.08B"`
179
+ * - `-42.678` -> `"-$42.67"`
174
180
  *
175
181
  * @param num - The numeric value.
176
182
  * @param options.showPlusGtThanZero - Prefix positive values with "+".
177
183
  */
178
- declare const formatAmountUSD: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
184
+ declare const formatAmountInUsd: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
185
+ type FormatDecimalCompactNumberOptions = {
186
+ /** Prefix to prepend after sign handling. Use "$" for USD displays. */
187
+ prefix?: string;
188
+ /** Abbreviate values >= 1_000 with K/M/B/T suffixes. Default: true. */
189
+ short?: boolean;
190
+ /**
191
+ * Decimal precision after scaling. This is the practical equivalent of the
192
+ * GMGN `$num` call sites that pass explicit formatting options.
193
+ */
194
+ precision?: number;
195
+ /**
196
+ * Minimum decimal places when `pad` is true. For example, GMGN token prices
197
+ * pass `pad: true` and use 3 decimals for values > 1.
198
+ */
199
+ minPrecision?: number;
200
+ /** Keep trailing zeros up to `max(precision, minPrecision)`. */
201
+ pad?: boolean;
202
+ /** String returned when the input is invalid. */
203
+ invalidPlaceholder?: string;
204
+ /** BigNumber rounding mode. GMGN display numbers truncate by default. */
205
+ rounding?: BigNumber.RoundingMode;
206
+ };
179
207
  /**
180
- * Format a raw token / asset amount (no currency symbol) — **compact** variant.
181
- *
182
- * Same tier ladder as {@link formatAmountUSDCompact} but without the `"$"`
183
- * prefix. Suited for space-constrained UIs that need to render an amount
184
- * alongside a token symbol (e.g. `"15K SOL"`) inside narrow buttons or
185
- * badges.
186
- *
187
- * | Range | Format | Example input output |
188
- * |---------------|-------------------------|------------------------------|
189
- * | < 0.001 | "0" | 0.00001 → "0" |
190
- * | < 1 | 3 decimal places | 0.56789 → "0.567" |
191
- * | < 100 | 2 decimal places | 42.678 → "42.67" |
192
- * | < 1 000 | 0 decimal places | 567.89 → "567" |
193
- * | ≥ 1 000 | abbreviated, 0 dp, | 15 678 → "15K" |
194
- * | | rounded to nearest 100 | 1 234 567 → "1M" |
195
- *
196
- * @param num - The numeric value.
197
- * @param options.showPlusGtThanZero - Prefix positive values with "+".
208
+ * Format numbers with the GMGN `$num`-style display rules.
209
+ *
210
+ * This is the configurable formatter behind GMGN's token price and activity
211
+ * price / market-cap displays:
212
+ *
213
+ * | GMGN field / scenario | Call pattern | Example output |
214
+ * |---------------------------------------|------------------------------------------------------------------------|----------------|
215
+ * | Token header price | `formatDecimalCompactNumber(price, { prefix: "$", precision: 3, pad: true })` | `"$2.089"` |
216
+ * | Activity price column in price mode | `formatDecimalCompactNumber(price, { prefix: "$", precision: 3, pad: true })` | `"$2.092"` |
217
+ * | Activity price column in market-cap mode | `formatDecimalCompactNumber(price * totalSupply, { prefix: "$", precision: 2 })` | `"$2.09B"` |
218
+ * | Basic metric market cap | `formatDecimalCompactNumber(marketCap, { prefix: "$", precision: 2 })` | `"$2.08B"` |
219
+ * | Tiny token price | `formatDecimalCompactNumber(0.00003, { prefix: "$" })` | `"$0.0₄3"` |
220
+ *
221
+ * Notes:
222
+ * - Values are truncated by default, matching the observed GMGN production
223
+ * bundle behavior.
224
+ * - `short` defaults to true and applies K/M/B/T after scaling.
225
+ * - For market-cap displays, callers should multiply `price * totalSupply`
226
+ * before calling this function; this keeps the formatter single-purpose.
198
227
  */
199
- declare const formatAmountCompact: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
228
+ declare const formatDecimalCompactNumber: (num?: BigNumber.Value, options?: FormatDecimalCompactNumberOptions) => string;
200
229
  /**
201
- * Format a USD dollar amount with "$" prefix — **compact** variant.
202
- *
203
- * Compared to {@link formatAmountUSD}, this variant is more aggressively
204
- * rounded and suited for space-constrained UIs (cards, badges, list items):
205
- *
206
- * | Range | Format | Example input → output |
207
- * |---------------|-------------------------|------------------------------|
208
- * | < 0.001 | "$0" | 0.00001 → "$0" |
209
- * | < 1 | 3 decimal places | 0.56789 → "$0.567" |
210
- * | < 100 | 2 decimal places | 42.678 → "$42.67" |
211
- * | < 1 000 | 0 decimal places | 567.89 → "$567" |
212
- * | 1 000 | abbreviated, 0 dp, | 15 678 → "$15.6K" |
213
- * | | rounded to nearest 100 | 1 234 567 → "$1.2M" |
214
- *
215
- * Key differences from `formatAmountUSD`:
216
- * - 100–1 000: shows 0 dp instead of 2 dp
217
- * - ≥ 1 000: abbreviates earlier (1K vs 10K) with 0 precision, rounded to 100s
218
- *
219
- * @param num - The numeric value.
220
- * @param options.showPlusGtThanZero - Prefix positive values with "+".
230
+ * Format a non-negative token price without a currency symbol.
231
+ *
232
+ * Use cases:
233
+ * - Token price text when the surrounding UI already renders the currency.
234
+ * - Activity-list price mode when the column header or cell chrome supplies
235
+ * the unit separately.
236
+ * - Token rows where values should match the GMGN-style 3-decimal padded
237
+ * price display and compact K/M/B/T behavior.
238
+ *
239
+ * Examples:
240
+ * - `2.089` -> `"2.089"`
241
+ * - `2.1` -> `"2.100"`
242
+ * - `0.00003` -> `"0.0₄3"`
243
+ * - `1234.567` -> `"1.234K"`
221
244
  */
222
- declare const formatAmountUSDCompact: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
223
- type FormatPriceOptions = {
224
- isHighPrecise: boolean;
225
- };
245
+ declare const formatPrice: (num?: BigNumber.Value) => string;
226
246
  /**
227
- * Format a token price (no currency symbol). Negative inputs render as `"--"`.
228
- *
229
- * Same precision tiers as {@link formatPriceUSD} but without the "$" prefix.
230
- *
231
- * @param num - The price value.
232
- * @param options.isHighPrecise - Use high-precision mode (default: true).
247
+ * Format a non-negative token price with a "$" prefix.
248
+ *
249
+ * Use cases:
250
+ * - Token header price in USD.
251
+ * - Activity-list price column in price mode.
252
+ * - Any USD price display that should keep exactly 3 decimals after the
253
+ * scaled value, except zero and subscript-zero tiny values.
254
+ *
255
+ * Examples:
256
+ * - `2.089` -> `"$2.089"`
257
+ * - `2.1` -> `"$2.100"`
258
+ * - `0.00003` -> `"$0.0₄3"`
259
+ * - `1234.567` -> `"$1.234K"`
233
260
  */
234
- declare const formatPrice: (num?: BigNumber.Value, options?: FormatPriceOptions) => string;
261
+ declare const formatPriceInUsd: (num?: BigNumber.Value) => string;
262
+ /**
263
+ * Format a non-negative market-cap or fully diluted valuation number without a
264
+ * currency symbol.
265
+ *
266
+ * Use cases:
267
+ * - Market-cap column text when the surrounding UI already renders the unit.
268
+ * - Activity-list price column in market-cap mode after the caller multiplies
269
+ * `price * totalSupply`.
270
+ * - Metrics that should use compact K/M/B/T notation with 2 decimal places.
271
+ *
272
+ * Examples:
273
+ * - `2089491826.331852` -> `"2.08B"`
274
+ * - `2092491826.331852` -> `"2.09B"`
275
+ * - `1234567` -> `"1.23M"`
276
+ * - `999.999` -> `"999.99"`
277
+ */
278
+ declare const formatMCap: (num?: BigNumber.Value) => string;
279
+ /**
280
+ * Format a non-negative market-cap or fully diluted valuation number with a
281
+ * "$" prefix.
282
+ *
283
+ * Use cases:
284
+ * - Token header market-cap / FDV metrics.
285
+ * - Activity-list price column in market-cap mode.
286
+ * - USD market-cap displays that should compact large values with K/M/B/T.
287
+ *
288
+ * Examples:
289
+ * - `2089491826.331852` -> `"$2.08B"`
290
+ * - `2092491826.331852` -> `"$2.09B"`
291
+ * - `1234567` -> `"$1.23M"`
292
+ * - `999.999` -> `"$999.99"`
293
+ */
294
+ declare const formatMCapInUsd: (num?: BigNumber.Value) => string;
295
+ type FormatSignificantCompactNumberOptions = {
296
+ /** Abbreviate values >= 1_000 with K/M/B/T suffixes. Default: true. */
297
+ short?: boolean;
298
+ /**
299
+ * Number of significant digits retained before truncation. GMGN's activity
300
+ * amount formatter uses 4 significant digits for normal values and 3 after
301
+ * K/M/B/T scaling.
302
+ */
303
+ significantDigits?: number;
304
+ /** String returned when the input is invalid. */
305
+ invalidPlaceholder?: string;
306
+ };
235
307
  /**
236
- * Format a token price with "$" prefix. Negative inputs render as `"--"`.
237
- *
238
- * Two precision modes controlled by `isHighPrecise` (default: `true`):
239
- *
240
- * | Range | High precision (default) | Low precision |
241
- * |---------------|-------------------------------|------------------------------|
242
- * | < 0.0001 | subscript notation, 4 sig | subscript notation, 2 sig |
243
- * | | 0.0000382 "$0.0₄382" | 0.0000382 "$0.0₄38" |
244
- * | < 1 | 4 dp, grouped | 2 significant dp |
245
- * | | 0.12345 "$0.1234" | 0.12345 "$0.12" |
246
- * | < 10 000 | 4 dp, grouped | 2 dp, grouped |
247
- * | | 1234.567 "$1,234.5670" | 1234.567 "$1,234.56" |
248
- * | < 100 000 | 2 dp, grouped | 2 dp, grouped |
249
- * | 100 000 | abbreviated (K/M/B/T) | abbreviated (K/M/B/T) |
250
- *
251
- * @param num - The price value.
252
- * @param options.isHighPrecise - Use high-precision mode (default: true).
308
+ * Format numbers with the GMGN `ej`-style activity amount rules.
309
+ *
310
+ * This is the formatter GMGN uses for activity-list amount-like cells:
311
+ *
312
+ * | GMGN field / scenario | Source value | Call pattern | Example output |
313
+ * |-----------------------------------|--------------------------------------------------|------------------------------------|----------------|
314
+ * | Activity quantity column | `record.base_amount` | `formatSignificantCompactNumber(value)` | `"41.87"` |
315
+ * | Activity quantity in mempool buy | `record.amount_out` | `formatSignificantCompactNumber(value)` | token amount |
316
+ * | Activity quantity in mempool sell | `record.amount_in` | `formatSignificantCompactNumber(value)` | token amount |
317
+ * | Activity total in SOL/native mode | native quote `record.quote_amount` | `formatSignificantCompactNumber(value)` | `"1.087"` |
318
+ * | Activity total in USD mode | `record.amount_usd`, then prepend `"$"` in UI | `formatSignificantCompactNumber(value)` | `"96.32"` |
319
+ * | Activity total via non-native quote | `record.amount_usd / nativeTokenUsdPrice` | `formatSignificantCompactNumber(value)` | native amount |
320
+ * | Tiny gas/native amount | native amount below 0.0001 | `formatSignificantCompactNumber(value)` | `"0.0₄3"` |
321
+ * | Large notional value | any amount >= 1_000 | `formatSignificantCompactNumber(value)` | `"2.08B"` |
322
+ *
323
+ * Notes:
324
+ * - The function returns the numeric text only. Add `$`, token symbols, SOL,
325
+ * or other unit labels at the call site.
326
+ * - Values are truncated, not rounded, matching the observed GMGN bundle.
327
+ * - GMGN's separate gas column often uses a threshold display such as
328
+ * `"<0.0001"`; use this function when you want the `ej` amount behavior,
329
+ * and add threshold handling outside when the UI contract requires it.
253
330
  */
254
- declare const formatPriceUSD: (num?: BigNumber.Value, options?: FormatPriceOptions) => string;
331
+ declare const formatSignificantCompactNumber: (num?: BigNumber.Value, options?: FormatSignificantCompactNumberOptions) => string;
255
332
  type FormatPercentOptions = {
256
333
  showPlusGtThanZero?: boolean;
257
334
  precision?: number;
@@ -378,4 +455,4 @@ declare function groupBy<T>(array: T[], iteratee: Iteratee<T, string>): Record<s
378
455
  declare function mapKeys<T>(obj: Record<string, T>, iteratee: (value: T, key: string) => string): Record<string, T>;
379
456
  declare function mapValues<T, R>(obj: Record<string, T>, iteratee: (value: T, key: string) => R): Record<string, R>;
380
457
 
381
- export { ARBITRUM_TOKENS, AVALANCHE_TOKENS, ApiError, BSC_TOKENS, CHAIN_REGISTRY, CHAIN_TOKENS, type ChainMetadata, type ChainPredefinedTokens, ETHEREUM_TOKENS, type FormatAgeOptions, type FormatAmountOptions, type FormatPercentOptions, type FormatPriceOptions, OPTIMISM_TOKENS, type PredefinedToken, SOLANA_TOKENS, SafeBigNumber, accountExplorerUrl, capitalize, chainColor, chainDisplayName, chainIcon, chainIdBySlug, chainSlug, chainToNamespace, debounce, formatAge, formatAgeInSeconds, formatAmount, formatAmountCompact, formatAmountUSD, formatAmountUSDCompact, formatPercent, formatPrice, formatPriceUSD, formatSymbol, formatTokenProtocolName, getCommonTokenAddresses, getCommonTokenSymbolsMap, getNativeToken, getStablecoins, getWrappedToken, groupBy, httpDelete, httpGet, httpMutate, httpPost, httpPut, httpRequest, intersectionBy, isBinanceChain, isEthereumChain, isSolanaChain, isValidEvmAddress, isValidNumber, isValidSolanaAddress, isValidWalletAddress, keyBy, mapKeys, mapValues, parseTokenProtocolFamily, searchImageUrl, searchTwitterUrl, throttle, truncateAddress, twitterTweetUrl, twitterUserUrl, txExplorerUrl, uniqBy };
458
+ export { ARBITRUM_TOKENS, AVALANCHE_TOKENS, ApiError, BSC_TOKENS, CHAIN_REGISTRY, CHAIN_TOKENS, type ChainMetadata, type ChainPredefinedTokens, ETHEREUM_TOKENS, type FormatAgeOptions, type FormatAmountOptions, type FormatDecimalCompactNumberOptions, type FormatPercentOptions, type FormatSignificantCompactNumberOptions, OPTIMISM_TOKENS, type PredefinedToken, SOLANA_TOKENS, SafeBigNumber, accountExplorerUrl, capitalize, chainColor, chainDisplayName, chainIcon, chainIdBySlug, chainSlug, chainToNamespace, debounce, formatAge, formatAgeInSeconds, formatAmount, formatAmountInUsd, formatDecimalCompactNumber, formatMCap, formatMCapInUsd, formatPercent, formatPrice, formatPriceInUsd, formatSignificantCompactNumber, formatSymbol, formatTokenProtocolName, getCommonTokenAddresses, getCommonTokenSymbolsMap, getNativeToken, getStablecoins, getWrappedToken, groupBy, httpDelete, httpGet, httpMutate, httpPost, httpPut, httpRequest, intersectionBy, isBinanceChain, isEthereumChain, isSolanaChain, isValidEvmAddress, isValidNumber, isValidSolanaAddress, isValidWalletAddress, keyBy, mapKeys, mapValues, parseTokenProtocolFamily, searchImageUrl, searchTwitterUrl, throttle, truncateAddress, twitterTweetUrl, twitterUserUrl, txExplorerUrl, uniqBy };
package/dist/index.d.ts CHANGED
@@ -140,118 +140,195 @@ declare class SafeBigNumber extends BigNumber {
140
140
  */
141
141
  declare const isValidNumber: (num: unknown) => boolean;
142
142
  type FormatAmountOptions = {
143
- showPlusGtThanZero: boolean;
143
+ showPlusGtThanZero?: boolean;
144
144
  };
145
145
  /**
146
146
  * Format a raw token / asset amount (no currency symbol).
147
147
  *
148
- * Precision tiers (ROUND_DOWN):
149
- * | Range | Format | Example input → output |
150
- * |---------------|-------------------------|------------------------------|
151
- * | < 0.001 | 5 decimal places | 0.0001234 → "0.00012" |
152
- * | < 1 | 3 decimal places | 0.56789 → "0.567" |
153
- * | < 100 | 2 decimal places | 42.678 → "42.67" |
154
- * | < 100 000 | grouped, 2 dp | 12345.6 → "12,345.60" |
155
- * | 100 000 | abbreviated (K/M/B/T) | 1_500_000 → "1.5M" |
148
+ * Use cases:
149
+ * - Activity-list quantity column from `base_amount`.
150
+ * - Activity-list total in native token mode before the UI appends a symbol.
151
+ * - Holder, trader, transaction, and token balance counts where compact
152
+ * K/M/B/T output is acceptable.
153
+ *
154
+ * Examples:
155
+ * - `41.8701` -> `"41.87"`
156
+ * - `1.087` -> `"1.087"`
157
+ * - `0.000032564` -> `"0.0₄3256"`
158
+ * - `12345.6` -> `"12.3K"`
159
+ * - `2089491826.331852` -> `"2.08B"`
156
160
  *
157
161
  * @param num - The numeric value.
158
162
  * @param options.showPlusGtThanZero - Prefix positive values with "+".
159
163
  */
160
164
  declare const formatAmount: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
161
165
  /**
162
- * Format a USD dollar amount with "$" prefix (standard precision).
166
+ * Format an amount with "$" prefix.
163
167
  *
164
- * Precision tiers (ROUND_DOWN):
165
- * | Range | Format | Example input output |
166
- * |---------------|-------------------------|------------------------------|
167
- * | < 0.001 | "$0" | 0.00001 → "$0" |
168
- * | < 1 | 3 decimal places | 0.56789 → "$0.567" |
169
- * | < 100 | 2 decimal places | 42.678 → "$42.67" |
170
- * | < 10 000 | grouped, 2 dp | 1234.5 → "$1,234.50" |
171
- * | ≥ 10 000 | abbreviated (K/M/B/T) | 1_500_000 → "$1.5M" |
168
+ * Use cases:
169
+ * - Activity-list total in USD mode from `amount_usd`.
170
+ * - USD notional amount displays where the numeric body should match
171
+ * `formatSignificantCompactNumber`.
172
+ * - Compact USD volume / liquidity text when 4 significant digits are enough.
172
173
  *
173
- * Use this for standard financial displays (volume, market cap, liquidity).
174
+ * Examples:
175
+ * - `96.32167791184` -> `"$96.32"`
176
+ * - `0.000032564` -> `"$0.0₄3256"`
177
+ * - `12345.6` -> `"$12.3K"`
178
+ * - `2089491826.331852` -> `"$2.08B"`
179
+ * - `-42.678` -> `"-$42.67"`
174
180
  *
175
181
  * @param num - The numeric value.
176
182
  * @param options.showPlusGtThanZero - Prefix positive values with "+".
177
183
  */
178
- declare const formatAmountUSD: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
184
+ declare const formatAmountInUsd: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
185
+ type FormatDecimalCompactNumberOptions = {
186
+ /** Prefix to prepend after sign handling. Use "$" for USD displays. */
187
+ prefix?: string;
188
+ /** Abbreviate values >= 1_000 with K/M/B/T suffixes. Default: true. */
189
+ short?: boolean;
190
+ /**
191
+ * Decimal precision after scaling. This is the practical equivalent of the
192
+ * GMGN `$num` call sites that pass explicit formatting options.
193
+ */
194
+ precision?: number;
195
+ /**
196
+ * Minimum decimal places when `pad` is true. For example, GMGN token prices
197
+ * pass `pad: true` and use 3 decimals for values > 1.
198
+ */
199
+ minPrecision?: number;
200
+ /** Keep trailing zeros up to `max(precision, minPrecision)`. */
201
+ pad?: boolean;
202
+ /** String returned when the input is invalid. */
203
+ invalidPlaceholder?: string;
204
+ /** BigNumber rounding mode. GMGN display numbers truncate by default. */
205
+ rounding?: BigNumber.RoundingMode;
206
+ };
179
207
  /**
180
- * Format a raw token / asset amount (no currency symbol) — **compact** variant.
181
- *
182
- * Same tier ladder as {@link formatAmountUSDCompact} but without the `"$"`
183
- * prefix. Suited for space-constrained UIs that need to render an amount
184
- * alongside a token symbol (e.g. `"15K SOL"`) inside narrow buttons or
185
- * badges.
186
- *
187
- * | Range | Format | Example input output |
188
- * |---------------|-------------------------|------------------------------|
189
- * | < 0.001 | "0" | 0.00001 → "0" |
190
- * | < 1 | 3 decimal places | 0.56789 → "0.567" |
191
- * | < 100 | 2 decimal places | 42.678 → "42.67" |
192
- * | < 1 000 | 0 decimal places | 567.89 → "567" |
193
- * | ≥ 1 000 | abbreviated, 0 dp, | 15 678 → "15K" |
194
- * | | rounded to nearest 100 | 1 234 567 → "1M" |
195
- *
196
- * @param num - The numeric value.
197
- * @param options.showPlusGtThanZero - Prefix positive values with "+".
208
+ * Format numbers with the GMGN `$num`-style display rules.
209
+ *
210
+ * This is the configurable formatter behind GMGN's token price and activity
211
+ * price / market-cap displays:
212
+ *
213
+ * | GMGN field / scenario | Call pattern | Example output |
214
+ * |---------------------------------------|------------------------------------------------------------------------|----------------|
215
+ * | Token header price | `formatDecimalCompactNumber(price, { prefix: "$", precision: 3, pad: true })` | `"$2.089"` |
216
+ * | Activity price column in price mode | `formatDecimalCompactNumber(price, { prefix: "$", precision: 3, pad: true })` | `"$2.092"` |
217
+ * | Activity price column in market-cap mode | `formatDecimalCompactNumber(price * totalSupply, { prefix: "$", precision: 2 })` | `"$2.09B"` |
218
+ * | Basic metric market cap | `formatDecimalCompactNumber(marketCap, { prefix: "$", precision: 2 })` | `"$2.08B"` |
219
+ * | Tiny token price | `formatDecimalCompactNumber(0.00003, { prefix: "$" })` | `"$0.0₄3"` |
220
+ *
221
+ * Notes:
222
+ * - Values are truncated by default, matching the observed GMGN production
223
+ * bundle behavior.
224
+ * - `short` defaults to true and applies K/M/B/T after scaling.
225
+ * - For market-cap displays, callers should multiply `price * totalSupply`
226
+ * before calling this function; this keeps the formatter single-purpose.
198
227
  */
199
- declare const formatAmountCompact: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
228
+ declare const formatDecimalCompactNumber: (num?: BigNumber.Value, options?: FormatDecimalCompactNumberOptions) => string;
200
229
  /**
201
- * Format a USD dollar amount with "$" prefix — **compact** variant.
202
- *
203
- * Compared to {@link formatAmountUSD}, this variant is more aggressively
204
- * rounded and suited for space-constrained UIs (cards, badges, list items):
205
- *
206
- * | Range | Format | Example input → output |
207
- * |---------------|-------------------------|------------------------------|
208
- * | < 0.001 | "$0" | 0.00001 → "$0" |
209
- * | < 1 | 3 decimal places | 0.56789 → "$0.567" |
210
- * | < 100 | 2 decimal places | 42.678 → "$42.67" |
211
- * | < 1 000 | 0 decimal places | 567.89 → "$567" |
212
- * | 1 000 | abbreviated, 0 dp, | 15 678 → "$15.6K" |
213
- * | | rounded to nearest 100 | 1 234 567 → "$1.2M" |
214
- *
215
- * Key differences from `formatAmountUSD`:
216
- * - 100–1 000: shows 0 dp instead of 2 dp
217
- * - ≥ 1 000: abbreviates earlier (1K vs 10K) with 0 precision, rounded to 100s
218
- *
219
- * @param num - The numeric value.
220
- * @param options.showPlusGtThanZero - Prefix positive values with "+".
230
+ * Format a non-negative token price without a currency symbol.
231
+ *
232
+ * Use cases:
233
+ * - Token price text when the surrounding UI already renders the currency.
234
+ * - Activity-list price mode when the column header or cell chrome supplies
235
+ * the unit separately.
236
+ * - Token rows where values should match the GMGN-style 3-decimal padded
237
+ * price display and compact K/M/B/T behavior.
238
+ *
239
+ * Examples:
240
+ * - `2.089` -> `"2.089"`
241
+ * - `2.1` -> `"2.100"`
242
+ * - `0.00003` -> `"0.0₄3"`
243
+ * - `1234.567` -> `"1.234K"`
221
244
  */
222
- declare const formatAmountUSDCompact: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
223
- type FormatPriceOptions = {
224
- isHighPrecise: boolean;
225
- };
245
+ declare const formatPrice: (num?: BigNumber.Value) => string;
226
246
  /**
227
- * Format a token price (no currency symbol). Negative inputs render as `"--"`.
228
- *
229
- * Same precision tiers as {@link formatPriceUSD} but without the "$" prefix.
230
- *
231
- * @param num - The price value.
232
- * @param options.isHighPrecise - Use high-precision mode (default: true).
247
+ * Format a non-negative token price with a "$" prefix.
248
+ *
249
+ * Use cases:
250
+ * - Token header price in USD.
251
+ * - Activity-list price column in price mode.
252
+ * - Any USD price display that should keep exactly 3 decimals after the
253
+ * scaled value, except zero and subscript-zero tiny values.
254
+ *
255
+ * Examples:
256
+ * - `2.089` -> `"$2.089"`
257
+ * - `2.1` -> `"$2.100"`
258
+ * - `0.00003` -> `"$0.0₄3"`
259
+ * - `1234.567` -> `"$1.234K"`
233
260
  */
234
- declare const formatPrice: (num?: BigNumber.Value, options?: FormatPriceOptions) => string;
261
+ declare const formatPriceInUsd: (num?: BigNumber.Value) => string;
262
+ /**
263
+ * Format a non-negative market-cap or fully diluted valuation number without a
264
+ * currency symbol.
265
+ *
266
+ * Use cases:
267
+ * - Market-cap column text when the surrounding UI already renders the unit.
268
+ * - Activity-list price column in market-cap mode after the caller multiplies
269
+ * `price * totalSupply`.
270
+ * - Metrics that should use compact K/M/B/T notation with 2 decimal places.
271
+ *
272
+ * Examples:
273
+ * - `2089491826.331852` -> `"2.08B"`
274
+ * - `2092491826.331852` -> `"2.09B"`
275
+ * - `1234567` -> `"1.23M"`
276
+ * - `999.999` -> `"999.99"`
277
+ */
278
+ declare const formatMCap: (num?: BigNumber.Value) => string;
279
+ /**
280
+ * Format a non-negative market-cap or fully diluted valuation number with a
281
+ * "$" prefix.
282
+ *
283
+ * Use cases:
284
+ * - Token header market-cap / FDV metrics.
285
+ * - Activity-list price column in market-cap mode.
286
+ * - USD market-cap displays that should compact large values with K/M/B/T.
287
+ *
288
+ * Examples:
289
+ * - `2089491826.331852` -> `"$2.08B"`
290
+ * - `2092491826.331852` -> `"$2.09B"`
291
+ * - `1234567` -> `"$1.23M"`
292
+ * - `999.999` -> `"$999.99"`
293
+ */
294
+ declare const formatMCapInUsd: (num?: BigNumber.Value) => string;
295
+ type FormatSignificantCompactNumberOptions = {
296
+ /** Abbreviate values >= 1_000 with K/M/B/T suffixes. Default: true. */
297
+ short?: boolean;
298
+ /**
299
+ * Number of significant digits retained before truncation. GMGN's activity
300
+ * amount formatter uses 4 significant digits for normal values and 3 after
301
+ * K/M/B/T scaling.
302
+ */
303
+ significantDigits?: number;
304
+ /** String returned when the input is invalid. */
305
+ invalidPlaceholder?: string;
306
+ };
235
307
  /**
236
- * Format a token price with "$" prefix. Negative inputs render as `"--"`.
237
- *
238
- * Two precision modes controlled by `isHighPrecise` (default: `true`):
239
- *
240
- * | Range | High precision (default) | Low precision |
241
- * |---------------|-------------------------------|------------------------------|
242
- * | < 0.0001 | subscript notation, 4 sig | subscript notation, 2 sig |
243
- * | | 0.0000382 "$0.0₄382" | 0.0000382 "$0.0₄38" |
244
- * | < 1 | 4 dp, grouped | 2 significant dp |
245
- * | | 0.12345 "$0.1234" | 0.12345 "$0.12" |
246
- * | < 10 000 | 4 dp, grouped | 2 dp, grouped |
247
- * | | 1234.567 "$1,234.5670" | 1234.567 "$1,234.56" |
248
- * | < 100 000 | 2 dp, grouped | 2 dp, grouped |
249
- * | 100 000 | abbreviated (K/M/B/T) | abbreviated (K/M/B/T) |
250
- *
251
- * @param num - The price value.
252
- * @param options.isHighPrecise - Use high-precision mode (default: true).
308
+ * Format numbers with the GMGN `ej`-style activity amount rules.
309
+ *
310
+ * This is the formatter GMGN uses for activity-list amount-like cells:
311
+ *
312
+ * | GMGN field / scenario | Source value | Call pattern | Example output |
313
+ * |-----------------------------------|--------------------------------------------------|------------------------------------|----------------|
314
+ * | Activity quantity column | `record.base_amount` | `formatSignificantCompactNumber(value)` | `"41.87"` |
315
+ * | Activity quantity in mempool buy | `record.amount_out` | `formatSignificantCompactNumber(value)` | token amount |
316
+ * | Activity quantity in mempool sell | `record.amount_in` | `formatSignificantCompactNumber(value)` | token amount |
317
+ * | Activity total in SOL/native mode | native quote `record.quote_amount` | `formatSignificantCompactNumber(value)` | `"1.087"` |
318
+ * | Activity total in USD mode | `record.amount_usd`, then prepend `"$"` in UI | `formatSignificantCompactNumber(value)` | `"96.32"` |
319
+ * | Activity total via non-native quote | `record.amount_usd / nativeTokenUsdPrice` | `formatSignificantCompactNumber(value)` | native amount |
320
+ * | Tiny gas/native amount | native amount below 0.0001 | `formatSignificantCompactNumber(value)` | `"0.0₄3"` |
321
+ * | Large notional value | any amount >= 1_000 | `formatSignificantCompactNumber(value)` | `"2.08B"` |
322
+ *
323
+ * Notes:
324
+ * - The function returns the numeric text only. Add `$`, token symbols, SOL,
325
+ * or other unit labels at the call site.
326
+ * - Values are truncated, not rounded, matching the observed GMGN bundle.
327
+ * - GMGN's separate gas column often uses a threshold display such as
328
+ * `"<0.0001"`; use this function when you want the `ej` amount behavior,
329
+ * and add threshold handling outside when the UI contract requires it.
253
330
  */
254
- declare const formatPriceUSD: (num?: BigNumber.Value, options?: FormatPriceOptions) => string;
331
+ declare const formatSignificantCompactNumber: (num?: BigNumber.Value, options?: FormatSignificantCompactNumberOptions) => string;
255
332
  type FormatPercentOptions = {
256
333
  showPlusGtThanZero?: boolean;
257
334
  precision?: number;
@@ -378,4 +455,4 @@ declare function groupBy<T>(array: T[], iteratee: Iteratee<T, string>): Record<s
378
455
  declare function mapKeys<T>(obj: Record<string, T>, iteratee: (value: T, key: string) => string): Record<string, T>;
379
456
  declare function mapValues<T, R>(obj: Record<string, T>, iteratee: (value: T, key: string) => R): Record<string, R>;
380
457
 
381
- export { ARBITRUM_TOKENS, AVALANCHE_TOKENS, ApiError, BSC_TOKENS, CHAIN_REGISTRY, CHAIN_TOKENS, type ChainMetadata, type ChainPredefinedTokens, ETHEREUM_TOKENS, type FormatAgeOptions, type FormatAmountOptions, type FormatPercentOptions, type FormatPriceOptions, OPTIMISM_TOKENS, type PredefinedToken, SOLANA_TOKENS, SafeBigNumber, accountExplorerUrl, capitalize, chainColor, chainDisplayName, chainIcon, chainIdBySlug, chainSlug, chainToNamespace, debounce, formatAge, formatAgeInSeconds, formatAmount, formatAmountCompact, formatAmountUSD, formatAmountUSDCompact, formatPercent, formatPrice, formatPriceUSD, formatSymbol, formatTokenProtocolName, getCommonTokenAddresses, getCommonTokenSymbolsMap, getNativeToken, getStablecoins, getWrappedToken, groupBy, httpDelete, httpGet, httpMutate, httpPost, httpPut, httpRequest, intersectionBy, isBinanceChain, isEthereumChain, isSolanaChain, isValidEvmAddress, isValidNumber, isValidSolanaAddress, isValidWalletAddress, keyBy, mapKeys, mapValues, parseTokenProtocolFamily, searchImageUrl, searchTwitterUrl, throttle, truncateAddress, twitterTweetUrl, twitterUserUrl, txExplorerUrl, uniqBy };
458
+ export { ARBITRUM_TOKENS, AVALANCHE_TOKENS, ApiError, BSC_TOKENS, CHAIN_REGISTRY, CHAIN_TOKENS, type ChainMetadata, type ChainPredefinedTokens, ETHEREUM_TOKENS, type FormatAgeOptions, type FormatAmountOptions, type FormatDecimalCompactNumberOptions, type FormatPercentOptions, type FormatSignificantCompactNumberOptions, OPTIMISM_TOKENS, type PredefinedToken, SOLANA_TOKENS, SafeBigNumber, accountExplorerUrl, capitalize, chainColor, chainDisplayName, chainIcon, chainIdBySlug, chainSlug, chainToNamespace, debounce, formatAge, formatAgeInSeconds, formatAmount, formatAmountInUsd, formatDecimalCompactNumber, formatMCap, formatMCapInUsd, formatPercent, formatPrice, formatPriceInUsd, formatSignificantCompactNumber, formatSymbol, formatTokenProtocolName, getCommonTokenAddresses, getCommonTokenSymbolsMap, getNativeToken, getStablecoins, getWrappedToken, groupBy, httpDelete, httpGet, httpMutate, httpPost, httpPut, httpRequest, intersectionBy, isBinanceChain, isEthereumChain, isSolanaChain, isValidEvmAddress, isValidNumber, isValidSolanaAddress, isValidWalletAddress, keyBy, mapKeys, mapValues, parseTokenProtocolFamily, searchImageUrl, searchTwitterUrl, throttle, truncateAddress, twitterTweetUrl, twitterUserUrl, txExplorerUrl, uniqBy };