lynx-client 0.0.22 → 0.0.23
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.
|
@@ -16,12 +16,32 @@ function floatToEtherBn(units, precisionDecimals) {
|
|
|
16
16
|
return floatToUnitsBn(units, 18, precisionDecimals);
|
|
17
17
|
}
|
|
18
18
|
function floatToUnitsBn(units, decimals, precisionDecimals) {
|
|
19
|
-
// Use toFixed to control decimal precision
|
|
20
|
-
// When precisionDecimals is specified, limit to that many decimals
|
|
21
|
-
// Otherwise use the full decimals value to prevent overflow errors
|
|
22
19
|
const precision = precisionDecimals !== undefined ? precisionDecimals : decimals;
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
// First convert to string to see what we're working with
|
|
21
|
+
let str = units.toString();
|
|
22
|
+
// Handle scientific notation by converting to fixed
|
|
23
|
+
if (str.includes('e') || str.includes('E')) {
|
|
24
|
+
// Use a reasonable precision that won't introduce errors
|
|
25
|
+
str = units.toFixed(Math.min(precision, 15));
|
|
26
|
+
}
|
|
27
|
+
// Now work with the string directly
|
|
28
|
+
const isNegative = str.startsWith('-');
|
|
29
|
+
if (isNegative)
|
|
30
|
+
str = str.slice(1);
|
|
31
|
+
const parts = str.split('.');
|
|
32
|
+
let integerPart = parts[0];
|
|
33
|
+
let decimalPart = parts[1] || '';
|
|
34
|
+
// Truncate decimal part to desired precision
|
|
35
|
+
if (precision === 0) {
|
|
36
|
+
decimalPart = '';
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
decimalPart = decimalPart.slice(0, precision);
|
|
40
|
+
}
|
|
41
|
+
// Reconstruct the number string
|
|
42
|
+
const finalStr = decimalPart ? `${integerPart}.${decimalPart}` : integerPart;
|
|
43
|
+
const result = ethers_1.ethers.parseUnits(finalStr, decimals);
|
|
44
|
+
return isNegative ? -result : result;
|
|
25
45
|
}
|
|
26
46
|
function bigintToHumanNumber(value, decimals, decimalsToShow, useCommas = true) {
|
|
27
47
|
const decimalValue = (value / BigInt(10 ** decimals)).toString();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bignumbers.d.ts","sourceRoot":"","sources":["../../../../lib/utils/bignumbers.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,MAAM,GAAG,MAAM,CAEhF;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,iBAAiB,CAAC,EAAE,MAAM,GACzB,MAAM,
|
|
1
|
+
{"version":3,"file":"bignumbers.d.ts","sourceRoot":"","sources":["../../../../lib/utils/bignumbers.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,MAAM,GAAG,MAAM,CAEhF;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,iBAAiB,CAAC,EAAE,MAAM,GACzB,MAAM,CAgCR;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EACtB,SAAS,GAAE,OAAc,GACxB,MAAM,CAkBR"}
|
|
@@ -16,12 +16,32 @@ function floatToEtherBn(units, precisionDecimals) {
|
|
|
16
16
|
return floatToUnitsBn(units, 18, precisionDecimals);
|
|
17
17
|
}
|
|
18
18
|
function floatToUnitsBn(units, decimals, precisionDecimals) {
|
|
19
|
-
// Use toFixed to control decimal precision
|
|
20
|
-
// When precisionDecimals is specified, limit to that many decimals
|
|
21
|
-
// Otherwise use the full decimals value to prevent overflow errors
|
|
22
19
|
const precision = precisionDecimals !== undefined ? precisionDecimals : decimals;
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
// First convert to string to see what we're working with
|
|
21
|
+
let str = units.toString();
|
|
22
|
+
// Handle scientific notation by converting to fixed
|
|
23
|
+
if (str.includes('e') || str.includes('E')) {
|
|
24
|
+
// Use a reasonable precision that won't introduce errors
|
|
25
|
+
str = units.toFixed(Math.min(precision, 15));
|
|
26
|
+
}
|
|
27
|
+
// Now work with the string directly
|
|
28
|
+
const isNegative = str.startsWith('-');
|
|
29
|
+
if (isNegative)
|
|
30
|
+
str = str.slice(1);
|
|
31
|
+
const parts = str.split('.');
|
|
32
|
+
let integerPart = parts[0];
|
|
33
|
+
let decimalPart = parts[1] || '';
|
|
34
|
+
// Truncate decimal part to desired precision
|
|
35
|
+
if (precision === 0) {
|
|
36
|
+
decimalPart = '';
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
decimalPart = decimalPart.slice(0, precision);
|
|
40
|
+
}
|
|
41
|
+
// Reconstruct the number string
|
|
42
|
+
const finalStr = decimalPart ? `${integerPart}.${decimalPart}` : integerPart;
|
|
43
|
+
const result = ethers_1.ethers.parseUnits(finalStr, decimals);
|
|
44
|
+
return isNegative ? -result : result;
|
|
25
45
|
}
|
|
26
46
|
function bigintToHumanNumber(value, decimals, decimalsToShow, useCommas = true) {
|
|
27
47
|
const decimalValue = (value / BigInt(10 ** decimals)).toString();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bignumbers.d.ts","sourceRoot":"","sources":["../../../../lib/utils/bignumbers.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,MAAM,GAAG,MAAM,CAEhF;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,iBAAiB,CAAC,EAAE,MAAM,GACzB,MAAM,
|
|
1
|
+
{"version":3,"file":"bignumbers.d.ts","sourceRoot":"","sources":["../../../../lib/utils/bignumbers.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,MAAM,GAAG,MAAM,CAEhF;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,iBAAiB,CAAC,EAAE,MAAM,GACzB,MAAM,CAgCR;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EACtB,SAAS,GAAE,OAAc,GACxB,MAAM,CAkBR"}
|