@swapkit/helpers 1.0.0-rc.0 → 1.0.0-rc.10
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.cjs +1 -1
- package/dist/index.d.ts +76 -47
- package/dist/index.es.js +816 -403
- package/package.json +8 -4
- package/src/helpers/asset.ts +25 -13
- package/src/helpers/liquidity.ts +19 -4
- package/src/helpers/others.ts +0 -39
- package/src/helpers/request.ts +16 -0
- package/src/index.ts +5 -4
- package/src/modules/__tests__/assetValue.test.ts +24 -8
- package/src/modules/__tests__/swapKitNumber.test.ts +155 -76
- package/src/modules/assetValue.ts +46 -40
- package/src/modules/bigIntArithmetics.ts +210 -99
- package/src/modules/swapKitNumber.ts +0 -4
- package/dist/index.es-8503fb04.js +0 -34669
- package/dist/index.es-903b9173.cjs +0 -1
- package/src/helpers/number.ts +0 -40
package/src/helpers/number.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// THORChain base amount is 1e8
|
|
2
|
-
export const DEFAULT_DECIMAL = 8;
|
|
3
|
-
|
|
4
|
-
export const formatBigIntToSafeValue = ({
|
|
5
|
-
value,
|
|
6
|
-
bigIntDecimal = DEFAULT_DECIMAL,
|
|
7
|
-
decimal = DEFAULT_DECIMAL,
|
|
8
|
-
}: {
|
|
9
|
-
value: bigint;
|
|
10
|
-
bigIntDecimal?: number;
|
|
11
|
-
decimal?: number;
|
|
12
|
-
}) => {
|
|
13
|
-
const isNegative = value < 0n;
|
|
14
|
-
let valueString = value.toString().substring(isNegative ? 1 : 0);
|
|
15
|
-
|
|
16
|
-
const padLength = decimal - (valueString.length - 1);
|
|
17
|
-
|
|
18
|
-
if (padLength > 0) {
|
|
19
|
-
valueString = '0'.repeat(padLength) + valueString;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const decimalIndex = valueString.length - decimal;
|
|
23
|
-
let decimalString = valueString.slice(-decimal);
|
|
24
|
-
|
|
25
|
-
// Check if we need to round up
|
|
26
|
-
if (parseInt(decimalString[bigIntDecimal]) >= 5) {
|
|
27
|
-
// Increment the last decimal place and slice off the rest
|
|
28
|
-
decimalString = `${decimalString.substring(0, bigIntDecimal - 1)}${(
|
|
29
|
-
parseInt(decimalString[bigIntDecimal - 1]) + 1
|
|
30
|
-
).toString()}`;
|
|
31
|
-
} else {
|
|
32
|
-
// Just slice off the extra digits
|
|
33
|
-
decimalString = decimalString.substring(0, bigIntDecimal);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return `${isNegative ? '-' : ''}${valueString.slice(0, decimalIndex)}.${decimalString}`.replace(
|
|
37
|
-
/\.?0*$/,
|
|
38
|
-
'',
|
|
39
|
-
);
|
|
40
|
-
};
|