@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 +166 -89
- package/dist/index.d.ts +166 -89
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
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
|
|
143
|
+
showPlusGtThanZero?: boolean;
|
|
144
144
|
};
|
|
145
145
|
/**
|
|
146
146
|
* Format a raw token / asset amount (no currency symbol).
|
|
147
147
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
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
|
|
166
|
+
* Format an amount with "$" prefix.
|
|
163
167
|
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* |
|
|
188
|
-
*
|
|
189
|
-
* |
|
|
190
|
-
* |
|
|
191
|
-
* |
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
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
|
|
228
|
+
declare const formatDecimalCompactNumber: (num?: BigNumber.Value, options?: FormatDecimalCompactNumberOptions) => string;
|
|
200
229
|
/**
|
|
201
|
-
* Format a
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
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
|
|
223
|
-
type FormatPriceOptions = {
|
|
224
|
-
isHighPrecise: boolean;
|
|
225
|
-
};
|
|
245
|
+
declare const formatPrice: (num?: BigNumber.Value) => string;
|
|
226
246
|
/**
|
|
227
|
-
* Format a token price
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
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
|
|
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
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* |
|
|
241
|
-
*
|
|
242
|
-
* |
|
|
243
|
-
* |
|
|
244
|
-
* |
|
|
245
|
-
* |
|
|
246
|
-
* |
|
|
247
|
-
* |
|
|
248
|
-
* |
|
|
249
|
-
* |
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
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
|
|
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
|
|
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
|
|
143
|
+
showPlusGtThanZero?: boolean;
|
|
144
144
|
};
|
|
145
145
|
/**
|
|
146
146
|
* Format a raw token / asset amount (no currency symbol).
|
|
147
147
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
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
|
|
166
|
+
* Format an amount with "$" prefix.
|
|
163
167
|
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* |
|
|
188
|
-
*
|
|
189
|
-
* |
|
|
190
|
-
* |
|
|
191
|
-
* |
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
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
|
|
228
|
+
declare const formatDecimalCompactNumber: (num?: BigNumber.Value, options?: FormatDecimalCompactNumberOptions) => string;
|
|
200
229
|
/**
|
|
201
|
-
* Format a
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
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
|
|
223
|
-
type FormatPriceOptions = {
|
|
224
|
-
isHighPrecise: boolean;
|
|
225
|
-
};
|
|
245
|
+
declare const formatPrice: (num?: BigNumber.Value) => string;
|
|
226
246
|
/**
|
|
227
|
-
* Format a token price
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
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
|
|
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
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* |
|
|
241
|
-
*
|
|
242
|
-
* |
|
|
243
|
-
* |
|
|
244
|
-
* |
|
|
245
|
-
* |
|
|
246
|
-
* |
|
|
247
|
-
* |
|
|
248
|
-
* |
|
|
249
|
-
* |
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
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
|
|
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
|
|
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 };
|