@curvefi/api 2.70.3 → 2.70.4
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/lib/utils.d.ts +3 -3
- package/lib/utils.js +9 -14
- package/package.json +1 -1
package/lib/utils.d.ts
CHANGED
|
@@ -6,14 +6,14 @@ import { Curve } from "./curve.js";
|
|
|
6
6
|
export declare const ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
7
7
|
export declare const MAX_ALLOWANCE: bigint;
|
|
8
8
|
export declare const abiInfoBuild: (address: string, method: string, abi: any) => IMethodInfo;
|
|
9
|
-
export declare const _cutZeros: (strn: string) => string;
|
|
10
9
|
export declare const checkNumber: (n: number | string) => number | string;
|
|
11
|
-
export declare const formatNumber: (n: number | string, decimals?: number) => string;
|
|
12
|
-
export declare function parseUnits(n: number | string, decimals?: number): bigint;
|
|
13
10
|
export declare const BN: (val: number | string) => BigNumber;
|
|
14
11
|
export declare const toBN: (n: bigint, decimals?: number) => BigNumber;
|
|
15
12
|
export declare const toStringFromBN: (bn: BigNumber, decimals?: number) => string;
|
|
16
13
|
export declare const fromBN: (bn: BigNumber, decimals?: number) => bigint;
|
|
14
|
+
export declare const _cutZeros: (strn: string) => string;
|
|
15
|
+
export declare const formatNumber: (n: number | string, decimals?: number) => string;
|
|
16
|
+
export declare function parseUnits(n: number | string, decimals?: number): bigint;
|
|
17
17
|
export declare const mulBy1_3: (n: bigint) => bigint;
|
|
18
18
|
export declare const smartNumber: (abstractNumber: bigint | bigint[]) => number | number[];
|
|
19
19
|
export declare const DIGas: (gas: bigint | Array<bigint>) => bigint;
|
package/lib/utils.js
CHANGED
|
@@ -28,25 +28,12 @@ export const abiInfoBuild = (address, method, abi) => ({
|
|
|
28
28
|
method,
|
|
29
29
|
abi,
|
|
30
30
|
});
|
|
31
|
-
//
|
|
32
|
-
export const _cutZeros = (strn) => {
|
|
33
|
-
return strn.replace(/(\.\d*[1-9])0+$/gi, '$1').replace(/\.0+$/gi, '');
|
|
34
|
-
};
|
|
31
|
+
// bignumber.js
|
|
35
32
|
export const checkNumber = (n) => {
|
|
36
33
|
if (Number(n) !== Number(n))
|
|
37
34
|
throw Error(`${n} is not a number`); // NaN
|
|
38
35
|
return n;
|
|
39
36
|
};
|
|
40
|
-
export const formatNumber = (n, decimals = 18) => {
|
|
41
|
-
if (Number(n) !== Number(n))
|
|
42
|
-
throw Error(`${n} is not a number`); // NaN
|
|
43
|
-
const [integer, fractional] = String(n).split(".");
|
|
44
|
-
return !fractional ? integer : integer + "." + fractional.slice(0, decimals);
|
|
45
|
-
};
|
|
46
|
-
export function parseUnits(n, decimals = 18) {
|
|
47
|
-
return ethers.parseUnits(formatNumber(n, decimals), decimals);
|
|
48
|
-
}
|
|
49
|
-
// bignumber.js
|
|
50
37
|
export const BN = (val) => new BigNumber(checkNumber(val));
|
|
51
38
|
export const toBN = (n, decimals = 18) => {
|
|
52
39
|
return BN(formatUnits(n, decimals));
|
|
@@ -57,6 +44,14 @@ export const toStringFromBN = (bn, decimals = 18) => {
|
|
|
57
44
|
export const fromBN = (bn, decimals = 18) => {
|
|
58
45
|
return parseUnits(toStringFromBN(bn, decimals), decimals);
|
|
59
46
|
};
|
|
47
|
+
// Formatting numbers
|
|
48
|
+
export const _cutZeros = (strn) => {
|
|
49
|
+
return strn.replace(/(\.\d*[1-9])0+$/gi, '$1').replace(/\.0+$/gi, '');
|
|
50
|
+
};
|
|
51
|
+
export const formatNumber = (n, decimals = 18) => BN(n).toFixed(decimals, BigNumber.ROUND_DOWN);
|
|
52
|
+
export function parseUnits(n, decimals = 18) {
|
|
53
|
+
return ethers.parseUnits(formatNumber(n, decimals), decimals);
|
|
54
|
+
}
|
|
60
55
|
// -------------------
|
|
61
56
|
export const mulBy1_3 = (n) => n * parseUnits("130", 0) / parseUnits("100", 0);
|
|
62
57
|
export const smartNumber = (abstractNumber) => {
|