@argent/x-shared 1.57.0 → 1.59.0
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/_virtual/numeral.cjs +1 -0
- package/dist/_virtual/numeral.js +7 -0
- package/dist/_virtual/numeral2.cjs +1 -0
- package/dist/_virtual/numeral2.js +4 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +289 -285
- package/dist/node_modules/.pnpm/numeral@2.0.6/node_modules/numeral/numeral.cjs +7 -0
- package/dist/node_modules/.pnpm/numeral@2.0.6/node_modules/numeral/numeral.js +424 -0
- package/dist/src/tokens/convertCurrencyValueToTokenAmount.cjs +1 -0
- package/dist/src/tokens/convertCurrencyValueToTokenAmount.d.ts +14 -0
- package/dist/src/tokens/convertCurrencyValueToTokenAmount.js +11 -0
- package/dist/src/tokens/index.d.ts +1 -0
- package/dist/src/tokens/service/types/defiPosition.model.cjs +1 -1
- package/dist/src/tokens/service/types/defiPosition.model.d.ts +290 -264
- package/dist/src/tokens/service/types/defiPosition.model.js +12 -11
- package/dist/src/tokens/service/types/webToken.model.d.ts +4 -4
- package/dist/src/utils/number/abbreviateNumber.cjs +1 -0
- package/dist/src/utils/number/abbreviateNumber.d.ts +13 -0
- package/dist/src/utils/number/abbreviateNumber.js +15 -0
- package/dist/src/utils/number/index.d.ts +1 -0
- package/dist/src/utils/number/prettifyNumber.cjs +1 -1
- package/dist/src/utils/number/prettifyNumber.d.ts +12 -6
- package/dist/src/utils/number/prettifyNumber.js +54 -30
- package/package.json +3 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z as t } from "zod";
|
|
2
2
|
import { addressSchema as o } from "../../../chains/starknet/address.js";
|
|
3
3
|
import { apiTokenInfoSchema as p, apiStrkDelegatedStakingSchema as g } from "./backend.model.js";
|
|
4
|
-
import { defiPositionTypeSchema as
|
|
4
|
+
import { defiPositionTypeSchema as u } from "./defiPositionType.model.js";
|
|
5
5
|
import { webTokenWithBalanceAndPriceSchema as e } from "./webToken.model.js";
|
|
6
6
|
const i = e.extend({
|
|
7
7
|
accruedFees: t.string(),
|
|
@@ -51,7 +51,8 @@ const i = e.extend({
|
|
|
51
51
|
total: a,
|
|
52
52
|
apy: t.number(),
|
|
53
53
|
totalApy: t.number(),
|
|
54
|
-
token: e
|
|
54
|
+
token: e,
|
|
55
|
+
liquidTokenAddress: o
|
|
55
56
|
}), V = t.array(l), d = n.extend({
|
|
56
57
|
id: t.string(),
|
|
57
58
|
accruedRewards: a,
|
|
@@ -61,23 +62,23 @@ const i = e.extend({
|
|
|
61
62
|
totalApy: t.number(),
|
|
62
63
|
stakerInfo: g.shape.data.shape.stakerInfo,
|
|
63
64
|
token: e
|
|
64
|
-
}), C = t.array(d),
|
|
65
|
+
}), C = t.array(d), m = r.or(s).or(c).or(d).or(l), h = t.record(t.object({
|
|
65
66
|
name: t.string().optional(),
|
|
66
67
|
healthRatio: t.string().optional(),
|
|
67
68
|
accountAddress: o.optional()
|
|
68
|
-
})),
|
|
69
|
-
type:
|
|
69
|
+
})), k = t.object({
|
|
70
|
+
type: u,
|
|
70
71
|
manageUrl: t.string().url().optional(),
|
|
71
72
|
name: t.string(),
|
|
72
|
-
positions: t.array(
|
|
73
|
+
positions: t.array(m),
|
|
73
74
|
// other types will be added when available from be
|
|
74
75
|
positionsTotalValue: t.string(),
|
|
75
76
|
brandColor: t.string().optional(),
|
|
76
77
|
groups: h.optional(),
|
|
77
78
|
accountAddress: o
|
|
78
|
-
}),
|
|
79
|
+
}), S = t.array(k), I = t.object({
|
|
79
80
|
dappId: t.string(),
|
|
80
|
-
products:
|
|
81
|
+
products: S
|
|
81
82
|
});
|
|
82
83
|
export {
|
|
83
84
|
x as collateralizedDebtGroupSchema,
|
|
@@ -86,9 +87,9 @@ export {
|
|
|
86
87
|
r as concentratedLiquidityPositionSchema,
|
|
87
88
|
T as concentratedLiquidityPositionsSchema,
|
|
88
89
|
I as defiDappsProductsSchema,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
m as defiPositionSchema,
|
|
91
|
+
k as defiProductSchema,
|
|
92
|
+
S as defiProductsSchema,
|
|
92
93
|
j as delegatedTokensArraySchema,
|
|
93
94
|
c as delegatedTokensSchema,
|
|
94
95
|
h as productGroupsSchema,
|
|
@@ -197,8 +197,8 @@ export declare const webTokenWithBalanceAndPriceSchema: z.ZodObject<z.objectUtil
|
|
|
197
197
|
}>, "strip", z.ZodTypeAny, {
|
|
198
198
|
address: `0x${string}`;
|
|
199
199
|
networkId: string;
|
|
200
|
-
balance: string;
|
|
201
200
|
currencyValue: string;
|
|
201
|
+
balance: string;
|
|
202
202
|
symbol?: string | undefined;
|
|
203
203
|
name?: string | undefined;
|
|
204
204
|
decimals?: number | undefined;
|
|
@@ -215,8 +215,8 @@ export declare const webTokenWithBalanceAndPriceSchema: z.ZodObject<z.objectUtil
|
|
|
215
215
|
}, {
|
|
216
216
|
address: string;
|
|
217
217
|
networkId: string;
|
|
218
|
-
balance: string;
|
|
219
218
|
currencyValue: string;
|
|
219
|
+
balance: string;
|
|
220
220
|
symbol?: string | undefined;
|
|
221
221
|
name?: string | undefined;
|
|
222
222
|
decimals?: number | undefined;
|
|
@@ -267,8 +267,8 @@ export declare const webTokensWithBalanceAndPriceSchema: z.ZodArray<z.ZodObject<
|
|
|
267
267
|
}>, "strip", z.ZodTypeAny, {
|
|
268
268
|
address: `0x${string}`;
|
|
269
269
|
networkId: string;
|
|
270
|
-
balance: string;
|
|
271
270
|
currencyValue: string;
|
|
271
|
+
balance: string;
|
|
272
272
|
symbol?: string | undefined;
|
|
273
273
|
name?: string | undefined;
|
|
274
274
|
decimals?: number | undefined;
|
|
@@ -285,8 +285,8 @@ export declare const webTokensWithBalanceAndPriceSchema: z.ZodArray<z.ZodObject<
|
|
|
285
285
|
}, {
|
|
286
286
|
address: string;
|
|
287
287
|
networkId: string;
|
|
288
|
-
balance: string;
|
|
289
288
|
currencyValue: string;
|
|
289
|
+
balance: string;
|
|
290
290
|
symbol?: string | undefined;
|
|
291
291
|
name?: string | undefined;
|
|
292
292
|
decimals?: number | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../../../_virtual/numeral.cjs"),o=require("./isNumeric.cjs"),b=(e,i=",",a=2)=>{let r=e;if(typeof e=="string"&&(r=e.replaceAll(i,"")),!o.isNumeric(r))return;const t=Number(r);if(Math.abs(t)<1e3)return t.toString();const u=`0.[${"0".repeat(a)}]a`;return n.default(t).format(u).toUpperCase()};exports.abbreviateNumber=b;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BigNumberish } from 'starknet';
|
|
2
|
+
/**
|
|
3
|
+
* Abbreviates large numbers into a more readable format with metric prefixes (K, M, B, etc.)
|
|
4
|
+
* @param value - The number to abbreviate. Can be a number, string, or bigint
|
|
5
|
+
* @param groupSeparator - The separator used for grouping digits in string input (default: ",")
|
|
6
|
+
* @param digitsAfterDecimal - Number of decimal places to show in abbreviated result (default: 2)
|
|
7
|
+
* @returns Abbreviated number as string (e.g. "1.23K", "45.6M") or undefined if input is invalid
|
|
8
|
+
* @example
|
|
9
|
+
* abbreviateNumber(1234) // "1.23K"
|
|
10
|
+
* abbreviateNumber("1,234,567") // "1.23M"
|
|
11
|
+
* abbreviateNumber(1234567890) // "1.23B"
|
|
12
|
+
*/
|
|
13
|
+
export declare const abbreviateNumber: (value?: BigNumberish, groupSeparator?: string, digitsAfterDecimal?: number) => string | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import m from "../../../_virtual/numeral.js";
|
|
2
|
+
import { isNumeric as n } from "./isNumeric.js";
|
|
3
|
+
const p = (r, o = ",", a = 2) => {
|
|
4
|
+
let e = r;
|
|
5
|
+
if (typeof r == "string" && (e = r.replaceAll(o, "")), !n(e))
|
|
6
|
+
return;
|
|
7
|
+
const t = Number(e);
|
|
8
|
+
if (Math.abs(t) < 1e3)
|
|
9
|
+
return t.toString();
|
|
10
|
+
const i = `0.[${"0".repeat(a)}]a`;
|
|
11
|
+
return m(t).format(i).toUpperCase();
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
p as abbreviateNumber
|
|
15
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../../../node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.cjs"),x=require("./isNumeric.cjs"),u={CURRENCY:{minDecimalPlaces:2,maxDecimalPlaces:10,minDecimalSignificantDigits:2,decimalPlacesWhenZero:2,allowLeadingZerosInDecimalPart:!0,groupSeparator:",",decimalSeparator:"."},TOKEN:{minDecimalPlaces:4,maxDecimalPlaces:16,minDecimalSignificantDigits:2,decimalPlacesWhenZero:1,allowLeadingZerosInDecimalPart:!0,groupSeparator:",",decimalSeparator:"."}},E=(r,e)=>D(r,{...u.CURRENCY,...e||{}}),T=(r,e)=>D(r,{...u.TOKEN,...e||{}}),R={groupSize:3,decimalSeparator:".",groupSeparator:","},D=(r,{minDecimalPlaces:e,maxDecimalPlaces:y,minDecimalSignificantDigits:C,decimalPlacesWhenZero:p,allowLeadingZerosInDecimalPart:S,groupSeparator:N,decimalSeparator:o=R.decimalSeparator,maxNrDigits:g,roundingMode:s}=u.CURRENCY)=>{if(!x.isNumeric(r))return null;const c={...R,groupSeparator:N,decimalSeparator:o},i=new h.BigNumber(typeof r=="bigint"?r.toString():r);let a;const F=`0.${"".padStart(p-1,"0")}1`;if(i.lt(new h.BigNumber(F))&&!S)a=`0.${"".padStart(p,"0")}`;else if(i.gte(1))a=e!==0?s?i.toFormat(e,s,c):i.toFormat(e,c):i.toFormat(e,h.BigNumber.ROUND_FLOOR,c);else{const l=(s?i.toFormat(y,s,c):i.toFormat(y,c)).split(o)[1].match(/^0+/),m=S&&l&&l.length?l[0].length:0,f=Math.max(m+C,e);a=s?i.toFormat(f,s,c):i.toFormat(f,c)}const[b,O]=a.split(o);let t=b;if(O){const n=O.replace(/0+$/,"");t+=n?`.${n}`:""}const P=1+a.indexOf(".")+p;if(t.length<P&&(t=a.substring(0,P)),g){const n=t.replace(new RegExp(`[${N}${o}]`,"g"),"").length;if(b.replace(new RegExp(`[${N}]`,"g"),"").length>g)t=b;else if(n>g){const l=n-g,m=t.indexOf(o);if(m!==-1){const f=Math.max(0,t.length-m-1-l);t=t.substring(0,m+1+f)}}}return t};exports.prettifyCurrencyNumber=E;exports.prettifyNumber=D;exports.prettifyNumberConfig=u;exports.prettifyTokenNumber=T;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BigNumber } from 'big-decimal-number';
|
|
1
2
|
import { BigNumberish } from 'starknet';
|
|
2
3
|
export interface IPrettifyNumberConfig {
|
|
3
4
|
minDecimalPlaces: number;
|
|
@@ -8,13 +9,18 @@ export interface IPrettifyNumberConfig {
|
|
|
8
9
|
decimalPlacesWhenZero: number;
|
|
9
10
|
/** allow leading zeros in the decimal part e.g. 0.0123 -> 0.012 */
|
|
10
11
|
allowLeadingZerosInDecimalPart: boolean;
|
|
12
|
+
/** group separator for the number e.g. 123456 -> 123,456 */
|
|
13
|
+
groupSeparator: string;
|
|
14
|
+
/** decimal separator for the number e.g. 123456 -> 123.456 */
|
|
15
|
+
decimalSeparator: string;
|
|
16
|
+
/** maximum number of digits to display. Does not override the other decimal places config.It is applied as a last step.
|
|
17
|
+
* If the number has more integer digits than maxNrDigits, it will keep only the integer part.
|
|
18
|
+
* If the number has more digits than maxNrDigits, it will trim the decimal part. */
|
|
19
|
+
maxNrDigits?: number;
|
|
20
|
+
/** rounding mode for the number */
|
|
21
|
+
roundingMode?: BigNumber.RoundingMode;
|
|
11
22
|
}
|
|
12
23
|
export declare const prettifyNumberConfig: Record<string, IPrettifyNumberConfig>;
|
|
13
24
|
export declare const prettifyCurrencyNumber: (number: BigNumberish, overrides?: Partial<IPrettifyNumberConfig>) => string | null;
|
|
14
25
|
export declare const prettifyTokenNumber: (number: BigNumberish, overrides?: Partial<IPrettifyNumberConfig>) => string | null;
|
|
15
|
-
|
|
16
|
-
* Prettify an input number for display according to the config
|
|
17
|
-
*
|
|
18
|
-
* @see test suite for examples
|
|
19
|
-
*/
|
|
20
|
-
export declare const prettifyNumber: (number: BigNumberish, { minDecimalPlaces, maxDecimalPlaces, minDecimalSignificantDigits, decimalPlacesWhenZero, allowLeadingZerosInDecimalPart, }?: IPrettifyNumberConfig) => string | null;
|
|
26
|
+
export declare const prettifyNumber: (number: BigNumberish, { minDecimalPlaces, maxDecimalPlaces, minDecimalSignificantDigits, decimalPlacesWhenZero, allowLeadingZerosInDecimalPart, groupSeparator, decimalSeparator, maxNrDigits, roundingMode, }?: IPrettifyNumberConfig) => string | null;
|
|
@@ -1,52 +1,76 @@
|
|
|
1
|
-
import { BigNumber as
|
|
2
|
-
import { isNumeric as
|
|
3
|
-
const
|
|
1
|
+
import { BigNumber as u } from "../../../node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.js";
|
|
2
|
+
import { isNumeric as y } from "./isNumeric.js";
|
|
3
|
+
const N = {
|
|
4
4
|
CURRENCY: {
|
|
5
5
|
minDecimalPlaces: 2,
|
|
6
6
|
maxDecimalPlaces: 10,
|
|
7
7
|
minDecimalSignificantDigits: 2,
|
|
8
8
|
decimalPlacesWhenZero: 2,
|
|
9
|
-
allowLeadingZerosInDecimalPart: !0
|
|
9
|
+
allowLeadingZerosInDecimalPart: !0,
|
|
10
|
+
groupSeparator: ",",
|
|
11
|
+
decimalSeparator: "."
|
|
10
12
|
},
|
|
11
13
|
TOKEN: {
|
|
12
14
|
minDecimalPlaces: 4,
|
|
13
15
|
maxDecimalPlaces: 16,
|
|
14
16
|
minDecimalSignificantDigits: 2,
|
|
15
17
|
decimalPlacesWhenZero: 1,
|
|
16
|
-
allowLeadingZerosInDecimalPart: !0
|
|
18
|
+
allowLeadingZerosInDecimalPart: !0,
|
|
19
|
+
groupSeparator: ",",
|
|
20
|
+
decimalSeparator: "."
|
|
17
21
|
}
|
|
18
|
-
},
|
|
19
|
-
...
|
|
22
|
+
}, T = (r, e) => x(r, {
|
|
23
|
+
...N.CURRENCY,
|
|
20
24
|
...e || {}
|
|
21
|
-
}),
|
|
22
|
-
...
|
|
25
|
+
}), d = (r, e) => x(r, {
|
|
26
|
+
...N.TOKEN,
|
|
23
27
|
...e || {}
|
|
24
|
-
}),
|
|
25
|
-
|
|
28
|
+
}), F = {
|
|
29
|
+
groupSize: 3,
|
|
30
|
+
decimalSeparator: ".",
|
|
31
|
+
groupSeparator: ","
|
|
32
|
+
}, x = (r, { minDecimalPlaces: e, maxDecimalPlaces: O, minDecimalSignificantDigits: w, decimalPlacesWhenZero: p, allowLeadingZerosInDecimalPart: P, groupSeparator: h, decimalSeparator: s = F.decimalSeparator, maxNrDigits: g, roundingMode: c } = N.CURRENCY) => {
|
|
33
|
+
if (!y(r))
|
|
26
34
|
return null;
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
const a = {
|
|
36
|
+
...F,
|
|
37
|
+
groupSeparator: h,
|
|
38
|
+
decimalSeparator: s
|
|
39
|
+
}, i = new u(typeof r == "bigint" ? r.toString() : r);
|
|
40
|
+
let o;
|
|
41
|
+
const C = `0.${"".padStart(p - 1, "0")}1`;
|
|
42
|
+
if (i.lt(new u(C)) && !P)
|
|
43
|
+
o = `0.${"".padStart(p, "0")}`;
|
|
32
44
|
else if (i.gte(1))
|
|
33
|
-
|
|
45
|
+
o = e !== 0 ? c ? i.toFormat(e, c, a) : i.toFormat(e, a) : i.toFormat(e, u.ROUND_FLOOR, a);
|
|
34
46
|
else {
|
|
35
|
-
const
|
|
36
|
-
|
|
47
|
+
const l = (c ? i.toFormat(O, c, a) : i.toFormat(O, a)).split(s)[1].match(/^0+/), m = P && l && l.length ? l[0].length : 0, f = Math.max(m + w, e);
|
|
48
|
+
o = c ? i.toFormat(f, c, a) : i.toFormat(f, a);
|
|
37
49
|
}
|
|
38
|
-
const [
|
|
39
|
-
let
|
|
40
|
-
if (
|
|
41
|
-
const
|
|
42
|
-
|
|
50
|
+
const [D, R] = o.split(s);
|
|
51
|
+
let t = D;
|
|
52
|
+
if (R) {
|
|
53
|
+
const n = R.replace(/0+$/, "");
|
|
54
|
+
t += n ? `.${n}` : "";
|
|
43
55
|
}
|
|
44
|
-
const
|
|
45
|
-
|
|
56
|
+
const S = 1 + o.indexOf(".") + p;
|
|
57
|
+
if (t.length < S && (t = o.substring(0, S)), g) {
|
|
58
|
+
const n = t.replace(new RegExp(`[${h}${s}]`, "g"), "").length;
|
|
59
|
+
if (D.replace(new RegExp(`[${h}]`, "g"), "").length > g)
|
|
60
|
+
t = D;
|
|
61
|
+
else if (n > g) {
|
|
62
|
+
const l = n - g, m = t.indexOf(s);
|
|
63
|
+
if (m !== -1) {
|
|
64
|
+
const f = Math.max(0, t.length - m - 1 - l);
|
|
65
|
+
t = t.substring(0, m + 1 + f);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return t;
|
|
46
70
|
};
|
|
47
71
|
export {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
72
|
+
T as prettifyCurrencyNumber,
|
|
73
|
+
x as prettifyNumber,
|
|
74
|
+
N as prettifyNumberConfig,
|
|
75
|
+
d as prettifyTokenNumber
|
|
52
76
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argent/x-shared",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.59.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/argentlabs/x-shared.git"
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"@semantic-release/git": "10.0.1",
|
|
51
51
|
"@types/async-retry": "1.4.9",
|
|
52
52
|
"@types/lodash-es": "4.17.12",
|
|
53
|
+
"@types/numeral": "2.0.5",
|
|
53
54
|
"@types/ua-parser-js": "0.7.39",
|
|
54
55
|
"@typescript-eslint/eslint-plugin": "8.18.0",
|
|
55
56
|
"@typescript-eslint/parser": "8.18.0",
|
|
@@ -73,6 +74,7 @@
|
|
|
73
74
|
"@starknet-io/types-js": "^0.7.7",
|
|
74
75
|
"big-decimal-number": "npm:bignumber.js@^9.1.2",
|
|
75
76
|
"micro-starknet": "^0.2.3",
|
|
77
|
+
"numeral": "2.0.6",
|
|
76
78
|
"starknet": "6.21.1",
|
|
77
79
|
"starknet4-deprecated": "npm:starknet@4.4.0",
|
|
78
80
|
"starknet5": "npm:starknet@5.25.0"
|