@injectivelabs/utils 0.0.52 → 0.0.56
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/classes/BigNumberInBase.js +1 -0
- package/dist/classes/BigNumberInBase.js.map +1 -1
- package/dist/classes/BigNumberInWei.js +1 -0
- package/dist/classes/BigNumberInWei.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/numbers.d.ts +96 -0
- package/dist/numbers.d.ts.map +1 -0
- package/dist/numbers.js +79 -0
- package/dist/numbers.js.map +1 -0
- package/dist/time.d.ts +0 -5
- package/dist/time.d.ts.map +1 -1
- package/dist/time.js +1 -55
- package/dist/time.js.map +1 -1
- package/package.json +2 -3
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// eslint-disable-next-line import/no-cycle
|
|
6
7
|
const BigNumberInWei_1 = __importDefault(require("./BigNumberInWei"));
|
|
7
8
|
const BigNumber_1 = __importDefault(require("./BigNumber"));
|
|
8
9
|
class BigNumberInBase extends BigNumber_1.default {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BigNumberInBase.js","sourceRoot":"","sources":["../../src/classes/BigNumberInBase.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"BigNumberInBase.js","sourceRoot":"","sources":["../../src/classes/BigNumberInBase.ts"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAC3C,sEAA6C;AAC7C,4DAAmC;AAEnC,MAAqB,eAAgB,SAAQ,mBAAS;IACpD,MAAM,CAAC,IAAI,CAAC,MAAuB;QACjC,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAA;IACpC,CAAC;I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|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// eslint-disable-next-line import/no-cycle
|
|
6
7
|
const BigNumberInBase_1 = __importDefault(require("./BigNumberInBase"));
|
|
7
8
|
const BigNumber_1 = __importDefault(require("./BigNumber"));
|
|
8
9
|
class BigNumberInWei extends BigNumber_1.default {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BigNumberInWei.js","sourceRoot":"","sources":["../../src/classes/BigNumberInWei.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"BigNumberInWei.js","sourceRoot":"","sources":["../../src/classes/BigNumberInWei.ts"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAC3C,wEAA+C;AAC/C,4DAAmC;AAEnC,MAAqB,cAAe,SAAQ,mBAAS;IACnD,MAAM,CAAC,IAAI,CAAC,MAAuB;QACjC,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC,CAAA;IACnC,CAAC;IAED,KAAK,CAAC,CAAkB,EAAE,IAAa;QACrC,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAA;IACjD,CAAC;IAED,IAAI,CAAC,CAAkB,EAAE,IAAa;QACpC,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAA;IAChD,CAAC;IAED,SAAS,CAAC,CAAkB,EAAE,IAAa;QACzC,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAA;IACrD,CAAC;IAED,GAAG,CAAC,CAAkB,EAAE,IAAa;QACnC,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAA;IAC/C,CAAC;IAED,YAAY,CAAC,CAAkB,EAAE,IAAa;QAC5C,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAA;IACxD,CAAC;IAED,KAAK,CAAC,CAAkB,EAAE,IAAa;QACrC,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAA;IACjD,CAAC;IAED,GAAG,CAAC,CAAkB,EAAE,IAAa;QACnC,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAA;IAC/C,CAAC;IAED,MAAM,CAAC,QAAQ,GAAG,EAAE;QAClB,OAAO,IAAI,yBAAe,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,mBAAS,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC9E,CAAC;CACF;AApCD,iCAoCC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,QAAQ,CAAA;AACtB,cAAc,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,QAAQ,CAAA;AACtB,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -15,4 +15,5 @@ __exportStar(require("./helpers"), exports);
|
|
|
15
15
|
__exportStar(require("./formatters"), exports);
|
|
16
16
|
__exportStar(require("./time"), exports);
|
|
17
17
|
__exportStar(require("./constants"), exports);
|
|
18
|
+
__exportStar(require("./numbers"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA+B;AAC/B,4CAAyB;AACzB,+CAA4B;AAC5B,yCAAsB;AACtB,8CAA2B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA+B;AAC/B,4CAAyB;AACzB,+CAA4B;AAC5B,yCAAsB;AACtB,8CAA2B;AAC3B,4CAAyB"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { BigNumber } from './classes';
|
|
2
|
+
/**
|
|
3
|
+
* On chain amounts queried from a sentry using the
|
|
4
|
+
* gRPC API are returned with an extra decimal point
|
|
5
|
+
* 18 places from the beginning, so we need to remove it
|
|
6
|
+
* to get a workable amount
|
|
7
|
+
*/
|
|
8
|
+
export declare const denomAmountFromGrpcChainDenomAmount: (value: string | number | BigNumber) => BigNumber;
|
|
9
|
+
/**
|
|
10
|
+
* Amount that the chain requires is in the x * 10^(quoteDecimals) format
|
|
11
|
+
* where x is a human readable number
|
|
12
|
+
*/
|
|
13
|
+
export declare const denomAmountToChainDenomAmount: ({ value, decimals, }: {
|
|
14
|
+
value: number | string | BigNumber;
|
|
15
|
+
decimals?: string | number | undefined;
|
|
16
|
+
}) => BigNumber;
|
|
17
|
+
/**
|
|
18
|
+
* Amount that the chain returns is in the x * 10^(quoteDecimals) format
|
|
19
|
+
* where x is a human readable number
|
|
20
|
+
*/
|
|
21
|
+
export declare const denomAmountFromChainDenomAmount: ({ value, decimals, }: {
|
|
22
|
+
value: number | string | BigNumber;
|
|
23
|
+
decimals?: string | number | undefined;
|
|
24
|
+
}) => BigNumber;
|
|
25
|
+
/**
|
|
26
|
+
* Amount that the chain requires is in the x * 10^(quoteDecimals) format
|
|
27
|
+
* where x is a human readable number
|
|
28
|
+
*/
|
|
29
|
+
export declare const derivativeMarginToChainMargin: ({ value, quoteDecimals, }: {
|
|
30
|
+
value: number | string | BigNumber;
|
|
31
|
+
quoteDecimals?: string | number | undefined;
|
|
32
|
+
}) => BigNumber;
|
|
33
|
+
/**
|
|
34
|
+
* Amount that the chain returns is in the x * 10^(quoteDecimals) format
|
|
35
|
+
* where x is a human readable number
|
|
36
|
+
*/
|
|
37
|
+
export declare const derivativeMarginFromChainMargin: ({ value, quoteDecimals, }: {
|
|
38
|
+
value: number | string | BigNumber;
|
|
39
|
+
quoteDecimals?: string | number | undefined;
|
|
40
|
+
}) => BigNumber;
|
|
41
|
+
/**
|
|
42
|
+
* Amount that the chain requires is in the x * 10^(quoteDecimals) format
|
|
43
|
+
* where x is a human readable number
|
|
44
|
+
*/
|
|
45
|
+
export declare const derivativePriceToChainPrice: ({ value, quoteDecimals, }: {
|
|
46
|
+
value: number | string | BigNumber;
|
|
47
|
+
quoteDecimals?: string | number | undefined;
|
|
48
|
+
}) => BigNumber;
|
|
49
|
+
/**
|
|
50
|
+
* Amount that the chain returns is in the x * 10^(quoteDecimals) format
|
|
51
|
+
* where x is a human readable number
|
|
52
|
+
*/
|
|
53
|
+
export declare const derivativePriceFromChainPrice: ({ value, quoteDecimals, }: {
|
|
54
|
+
value: number | string | BigNumber;
|
|
55
|
+
quoteDecimals?: string | number | undefined;
|
|
56
|
+
}) => BigNumber;
|
|
57
|
+
/**
|
|
58
|
+
* Amount that the chain requires is in the x format
|
|
59
|
+
* where x is a human readable number
|
|
60
|
+
*/
|
|
61
|
+
export declare const derivativeQuantityToChainQuantity: (value: number | string | BigNumber) => BigNumber;
|
|
62
|
+
/**
|
|
63
|
+
* Amount that the chain requires is in the x / 10^(quoteDecimals - baseDecimals) format
|
|
64
|
+
* where x is a human readable number
|
|
65
|
+
*/
|
|
66
|
+
export declare const spotPriceToChainPrice: ({ value, baseDecimals, quoteDecimals, }: {
|
|
67
|
+
value: number | string | BigNumber;
|
|
68
|
+
quoteDecimals?: string | number | undefined;
|
|
69
|
+
baseDecimals?: string | number | undefined;
|
|
70
|
+
}) => BigNumber;
|
|
71
|
+
/**
|
|
72
|
+
* Amount that the chain returns is in the x / 10^(quoteDecimals - baseDecimals) format
|
|
73
|
+
* where x is a human readable number
|
|
74
|
+
*/
|
|
75
|
+
export declare const spotPriceFromChainPrice: ({ value, baseDecimals, quoteDecimals, }: {
|
|
76
|
+
value: number | string | BigNumber;
|
|
77
|
+
quoteDecimals?: string | number | undefined;
|
|
78
|
+
baseDecimals?: string | number | undefined;
|
|
79
|
+
}) => BigNumber;
|
|
80
|
+
/**
|
|
81
|
+
* Amount that the chain requires is in the x * 10^(baseDecimals) format
|
|
82
|
+
* where x is a human readable number
|
|
83
|
+
*/
|
|
84
|
+
export declare const spotQuantityToChainQuantity: ({ value, baseDecimals, }: {
|
|
85
|
+
value: number | string | BigNumber;
|
|
86
|
+
baseDecimals?: string | number | undefined;
|
|
87
|
+
}) => BigNumber;
|
|
88
|
+
/**
|
|
89
|
+
* Amount that the chain returns is in the x * 10^(baseDecimals) format
|
|
90
|
+
* where x is a human readable number
|
|
91
|
+
*/
|
|
92
|
+
export declare const spotQuantityFromChainQuantity: ({ value, baseDecimals, }: {
|
|
93
|
+
value: number | string | BigNumber;
|
|
94
|
+
baseDecimals?: string | number | undefined;
|
|
95
|
+
}) => BigNumber;
|
|
96
|
+
//# sourceMappingURL=numbers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../src/numbers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC;;;;;GAKG;AACH,eAAO,MAAM,mCAAmC,UACvC,MAAM,GAAG,MAAM,GAAG,SAAS,cAC0B,CAAA;AAE9D;;;GAGG;AACH,eAAO,MAAM,6BAA6B;WAIjC,MAAM,GAAG,MAAM,GAAG,SAAS;;eAEoC,CAAA;AAExE;;;GAGG;AACH,eAAO,MAAM,+BAA+B;WAInC,MAAM,GAAG,MAAM,GAAG,SAAS;;eAEiC,CAAA;AAErE;;;GAGG;AACH,eAAO,MAAM,6BAA6B;WAIjC,MAAM,GAAG,MAAM,GAAG,SAAS;;eAEyC,CAAA;AAE7E;;;GAGG;AACH,eAAO,MAAM,+BAA+B;WAInC,MAAM,GAAG,MAAM,GAAG,SAAS;;eAEsC,CAAA;AAE1E;;;GAGG;AACH,eAAO,MAAM,2BAA2B;WAI/B,MAAM,GAAG,MAAM,GAAG,SAAS;;eAEyC,CAAA;AAE7E;;;GAGG;AACH,eAAO,MAAM,6BAA6B;WAIjC,MAAM,GAAG,MAAM,GAAG,SAAS;;eAEsC,CAAA;AAE1E;;;GAGG;AACH,eAAO,MAAM,iCAAiC,UACrC,MAAM,GAAG,MAAM,GAAG,SAAS,cACX,CAAA;AAEzB;;;GAGG;AACH,eAAO,MAAM,qBAAqB;WAKzB,MAAM,GAAG,MAAM,GAAG,SAAS;;;eAMjC,CAAA;AAEH;;;GAGG;AACH,eAAO,MAAM,uBAAuB;WAK3B,MAAM,GAAG,MAAM,GAAG,SAAS;;;eAMjC,CAAA;AAEH;;;GAGG;AACH,eAAO,MAAM,2BAA2B;WAI/B,MAAM,GAAG,MAAM,GAAG,SAAS;;eAEwC,CAAA;AAE5E;;;GAGG;AACH,eAAO,MAAM,6BAA6B;WAIjC,MAAM,GAAG,MAAM,GAAG,SAAS;;eAEwC,CAAA"}
|
package/dist/numbers.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.spotQuantityFromChainQuantity = exports.spotQuantityToChainQuantity = exports.spotPriceFromChainPrice = exports.spotPriceToChainPrice = exports.derivativeQuantityToChainQuantity = exports.derivativePriceFromChainPrice = exports.derivativePriceToChainPrice = exports.derivativeMarginFromChainMargin = exports.derivativeMarginToChainMargin = exports.denomAmountFromChainDenomAmount = exports.denomAmountToChainDenomAmount = exports.denomAmountFromGrpcChainDenomAmount = void 0;
|
|
4
|
+
const classes_1 = require("./classes");
|
|
5
|
+
/**
|
|
6
|
+
* On chain amounts queried from a sentry using the
|
|
7
|
+
* gRPC API are returned with an extra decimal point
|
|
8
|
+
* 18 places from the beginning, so we need to remove it
|
|
9
|
+
* to get a workable amount
|
|
10
|
+
*/
|
|
11
|
+
const denomAmountFromGrpcChainDenomAmount = (value) => new classes_1.BigNumber(value).dividedBy(new classes_1.BigNumber(10).pow(18));
|
|
12
|
+
exports.denomAmountFromGrpcChainDenomAmount = denomAmountFromGrpcChainDenomAmount;
|
|
13
|
+
/**
|
|
14
|
+
* Amount that the chain requires is in the x * 10^(quoteDecimals) format
|
|
15
|
+
* where x is a human readable number
|
|
16
|
+
*/
|
|
17
|
+
const denomAmountToChainDenomAmount = ({ value, decimals = 18, }) => new classes_1.BigNumber(value).multipliedBy(new classes_1.BigNumber(10).pow(decimals));
|
|
18
|
+
exports.denomAmountToChainDenomAmount = denomAmountToChainDenomAmount;
|
|
19
|
+
/**
|
|
20
|
+
* Amount that the chain returns is in the x * 10^(quoteDecimals) format
|
|
21
|
+
* where x is a human readable number
|
|
22
|
+
*/
|
|
23
|
+
const denomAmountFromChainDenomAmount = ({ value, decimals = 18, }) => new classes_1.BigNumber(value).dividedBy(new classes_1.BigNumber(10).pow(decimals));
|
|
24
|
+
exports.denomAmountFromChainDenomAmount = denomAmountFromChainDenomAmount;
|
|
25
|
+
/**
|
|
26
|
+
* Amount that the chain requires is in the x * 10^(quoteDecimals) format
|
|
27
|
+
* where x is a human readable number
|
|
28
|
+
*/
|
|
29
|
+
const derivativeMarginToChainMargin = ({ value, quoteDecimals = 18, }) => new classes_1.BigNumber(value).multipliedBy(new classes_1.BigNumber(10).pow(quoteDecimals));
|
|
30
|
+
exports.derivativeMarginToChainMargin = derivativeMarginToChainMargin;
|
|
31
|
+
/**
|
|
32
|
+
* Amount that the chain returns is in the x * 10^(quoteDecimals) format
|
|
33
|
+
* where x is a human readable number
|
|
34
|
+
*/
|
|
35
|
+
const derivativeMarginFromChainMargin = ({ value, quoteDecimals = 18, }) => new classes_1.BigNumber(value).dividedBy(new classes_1.BigNumber(10).pow(quoteDecimals));
|
|
36
|
+
exports.derivativeMarginFromChainMargin = derivativeMarginFromChainMargin;
|
|
37
|
+
/**
|
|
38
|
+
* Amount that the chain requires is in the x * 10^(quoteDecimals) format
|
|
39
|
+
* where x is a human readable number
|
|
40
|
+
*/
|
|
41
|
+
const derivativePriceToChainPrice = ({ value, quoteDecimals = 18, }) => new classes_1.BigNumber(value).multipliedBy(new classes_1.BigNumber(10).pow(quoteDecimals));
|
|
42
|
+
exports.derivativePriceToChainPrice = derivativePriceToChainPrice;
|
|
43
|
+
/**
|
|
44
|
+
* Amount that the chain returns is in the x * 10^(quoteDecimals) format
|
|
45
|
+
* where x is a human readable number
|
|
46
|
+
*/
|
|
47
|
+
const derivativePriceFromChainPrice = ({ value, quoteDecimals = 18, }) => new classes_1.BigNumber(value).dividedBy(new classes_1.BigNumber(10).pow(quoteDecimals));
|
|
48
|
+
exports.derivativePriceFromChainPrice = derivativePriceFromChainPrice;
|
|
49
|
+
/**
|
|
50
|
+
* Amount that the chain requires is in the x format
|
|
51
|
+
* where x is a human readable number
|
|
52
|
+
*/
|
|
53
|
+
const derivativeQuantityToChainQuantity = (value) => new classes_1.BigNumber(value);
|
|
54
|
+
exports.derivativeQuantityToChainQuantity = derivativeQuantityToChainQuantity;
|
|
55
|
+
/**
|
|
56
|
+
* Amount that the chain requires is in the x / 10^(quoteDecimals - baseDecimals) format
|
|
57
|
+
* where x is a human readable number
|
|
58
|
+
*/
|
|
59
|
+
const spotPriceToChainPrice = ({ value, baseDecimals = 18, quoteDecimals = 6, }) => new classes_1.BigNumber(value).multipliedBy(new classes_1.BigNumber(10).pow(new classes_1.BigNumber(quoteDecimals).minus(baseDecimals)));
|
|
60
|
+
exports.spotPriceToChainPrice = spotPriceToChainPrice;
|
|
61
|
+
/**
|
|
62
|
+
* Amount that the chain returns is in the x / 10^(quoteDecimals - baseDecimals) format
|
|
63
|
+
* where x is a human readable number
|
|
64
|
+
*/
|
|
65
|
+
const spotPriceFromChainPrice = ({ value, baseDecimals = 18, quoteDecimals = 6, }) => new classes_1.BigNumber(value).dividedBy(new classes_1.BigNumber(10).pow(new classes_1.BigNumber(quoteDecimals).minus(baseDecimals)));
|
|
66
|
+
exports.spotPriceFromChainPrice = spotPriceFromChainPrice;
|
|
67
|
+
/**
|
|
68
|
+
* Amount that the chain requires is in the x * 10^(baseDecimals) format
|
|
69
|
+
* where x is a human readable number
|
|
70
|
+
*/
|
|
71
|
+
const spotQuantityToChainQuantity = ({ value, baseDecimals = 18, }) => new classes_1.BigNumber(value).multipliedBy(new classes_1.BigNumber(10).pow(baseDecimals));
|
|
72
|
+
exports.spotQuantityToChainQuantity = spotQuantityToChainQuantity;
|
|
73
|
+
/**
|
|
74
|
+
* Amount that the chain returns is in the x * 10^(baseDecimals) format
|
|
75
|
+
* where x is a human readable number
|
|
76
|
+
*/
|
|
77
|
+
const spotQuantityFromChainQuantity = ({ value, baseDecimals = 18, }) => new classes_1.BigNumber(value).multipliedBy(new classes_1.BigNumber(10).pow(baseDecimals));
|
|
78
|
+
exports.spotQuantityFromChainQuantity = spotQuantityFromChainQuantity;
|
|
79
|
+
//# sourceMappingURL=numbers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numbers.js","sourceRoot":"","sources":["../src/numbers.ts"],"names":[],"mappings":";;;AAAA,uCAAqC;AAErC;;;;;GAKG;AACI,MAAM,mCAAmC,GAAG,CACjD,KAAkC,EAClC,EAAE,CAAC,IAAI,mBAAS,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,IAAI,mBAAS,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,C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AAK,EACL,YAAY,GAAG,EAAE,GAIlB,EAAE,EAAE,CAAC,IAAI,mBAAS,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,IAAI,mBAAS,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAA;AAN/D,QAAA,2BAA2B,+BAMoC;AAE5E;;;GAGG;AACI,MAAM,6BAA6B,GAAG,CAAC,EAC5C,KAAK,EACL,YAAY,GAAG,EAAE,GAIlB,EAAE,EAAE,CAAC,IAAI,mBAAS,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,IAAI,mBAAS,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAA;AAN/D,QAAA,6BAA6B,iCAMkC"}
|
package/dist/time.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { BigNumberInBase, BigNumber } from './classes';
|
|
2
2
|
export declare const SECONDS_IN_A_DAY: BigNumber;
|
|
3
|
-
export declare const formatDurationFromSecondsToString: (seconds: number) => string;
|
|
4
|
-
export declare const formatDurationFromSeconds: ({ duration, fullSuffix, }: {
|
|
5
|
-
duration: number;
|
|
6
|
-
fullSuffix?: boolean | undefined;
|
|
7
|
-
}) => string;
|
|
8
3
|
export declare const convertTimestampToMilliseconds: (timestamp: number) => number;
|
|
9
4
|
export declare const getUTCDateFromTimestamp: (timestamp: number) => string;
|
|
10
5
|
export declare const tomorrow: () => BigNumber;
|
package/dist/time.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAEtD,eAAO,MAAM,gBAAgB,EAAE,SAAuC,CAAA;AAEtE,eAAO,MAAM,8BAA8B,cAAe,MAAM,WAa/D,CAAA;AAED,eAAO,MAAM,uBAAuB,cAAe,MAAM,WAMxD,CAAA;AAED,eAAO,MAAM,QAAQ,QAAO,SAC8C,CAAA;AAE1E,eAAO,MAAM,cAAc,QAAO,MAAuC,CAAA;AAEzE,eAAO,MAAM,WAAW,QAAO,MAC2C,CAAA;AAE1E,eAAO,MAAM,QAAQ,oBAAc,MAGpB,CAAA;AAEf,eAAO,MAAM,iCAAiC,kBAC7B,eAAe,KAC7B,MAIF,CAAA"}
|
package/dist/time.js
CHANGED
|
@@ -1,62 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEndDateStringFromTimeInSeconds = exports.pastDays = exports.past24Hours = exports.todayInSeconds = exports.tomorrow = exports.getUTCDateFromTimestamp = exports.convertTimestampToMilliseconds = exports.
|
|
4
|
-
const date_fns_1 = require("date-fns");
|
|
3
|
+
exports.getEndDateStringFromTimeInSeconds = exports.pastDays = exports.past24Hours = exports.todayInSeconds = exports.tomorrow = exports.getUTCDateFromTimestamp = exports.convertTimestampToMilliseconds = exports.SECONDS_IN_A_DAY = void 0;
|
|
5
4
|
const classes_1 = require("./classes");
|
|
6
5
|
exports.SECONDS_IN_A_DAY = new classes_1.BigNumber(60 * 60 * 24);
|
|
7
|
-
const formatDurationFromSecondsToString = (seconds) => {
|
|
8
|
-
const duration = (0, date_fns_1.intervalToDuration)({ start: 0, end: seconds * 1000 });
|
|
9
|
-
const countDownDisplaySuffix = {
|
|
10
|
-
xDays: 'd',
|
|
11
|
-
xHours: 'h',
|
|
12
|
-
xMinutes: 'm',
|
|
13
|
-
xSeconds: 's',
|
|
14
|
-
};
|
|
15
|
-
return (0, date_fns_1.formatDuration)(duration, {
|
|
16
|
-
format: ['days', 'hours', 'minutes', 'seconds'],
|
|
17
|
-
locale: {
|
|
18
|
-
formatDistance: (type, count) => {
|
|
19
|
-
const formattedCount = count < 10 ? `0${count}` : count;
|
|
20
|
-
return `${formattedCount}${countDownDisplaySuffix[type]}`;
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
exports.formatDurationFromSecondsToString = formatDurationFromSecondsToString;
|
|
26
|
-
const formatDurationFromSeconds = ({ duration, fullSuffix, }) => {
|
|
27
|
-
const { days, hours, minutes, seconds } = (0, date_fns_1.intervalToDuration)({
|
|
28
|
-
start: 0,
|
|
29
|
-
end: duration * 1000,
|
|
30
|
-
});
|
|
31
|
-
const suffix = fullSuffix
|
|
32
|
-
? ['day', 'hour', 'min', 'sec']
|
|
33
|
-
: ['d', 'h', 'm', 's'];
|
|
34
|
-
let removeLeadingZeroDuration = true;
|
|
35
|
-
return ([days, hours, minutes, seconds]
|
|
36
|
-
.map((duration, index) => {
|
|
37
|
-
if (duration !== 0) {
|
|
38
|
-
removeLeadingZeroDuration = false;
|
|
39
|
-
}
|
|
40
|
-
if (fullSuffix) {
|
|
41
|
-
const durationSuffix = duration && duration > 1 ? 's' : '';
|
|
42
|
-
return removeLeadingZeroDuration && duration === 0
|
|
43
|
-
? undefined
|
|
44
|
-
: `${duration} ${suffix[index]}${durationSuffix}`;
|
|
45
|
-
}
|
|
46
|
-
return removeLeadingZeroDuration && duration === 0
|
|
47
|
-
? undefined
|
|
48
|
-
: `${duration}${suffix[index]}`;
|
|
49
|
-
})
|
|
50
|
-
.filter((duration) => duration)
|
|
51
|
-
.join(' ')
|
|
52
|
-
.replace(' 0h 0m 0s', '')
|
|
53
|
-
.replace(' 0m 0s', '')
|
|
54
|
-
.replace(' 0s', '')
|
|
55
|
-
.replace(' 0 hour 0 minute 0 second', '')
|
|
56
|
-
.replace(' 0 minute 0 second', '')
|
|
57
|
-
.replace(' 0 second', ''));
|
|
58
|
-
};
|
|
59
|
-
exports.formatDurationFromSeconds = formatDurationFromSeconds;
|
|
60
6
|
const convertTimestampToMilliseconds = (timestamp) => {
|
|
61
7
|
if (timestamp.toString().length > 13) {
|
|
62
8
|
return parseInt(timestamp.toString().slice(0, 13), 10);
|
package/dist/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":";;;AAAA,uCAAsD;AAEzC,QAAA,gBAAgB,GAAc,IAAI,mBAAS,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAA;AAE/D,MAAM,8BAA8B,GAAG,CAAC,SAAiB,EAAE,EAAE;IAClE,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC,MAAM,GAAG,EAAE,EAAE;QACpC,OAAO,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;KACvD;IAED,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC,MAAM,GAAG,EAAE,EAAE;QACpC,OAAO,QAAQ,CACb,GAAG,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,EAC7D,EAAE,CACH,CAAA;KACF;IAED,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAbY,QAAA,8BAA8B,kCAa1C;AAEM,MAAM,uBAAuB,GAAG,CAAC,SAAiB,EAAE,EAAE;IAC3D,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,IAAA,sCAA8B,EAAC,SAAS,CAAC,CAAC,CAAA;IAEhE,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,IACzB,IAAI,CAAC,WAAW,EAAE,GAAG,CACvB,IAAI,IAAI,CAAC,cAAc,EAAE,EAAE,CAAA;AAC7B,CAAC,CAAA;AANY,QAAA,uBAAuB,2BAMnC;AAEM,MAAM,QAAQ,GAAG,GAAc,EAAE,CACtC,IAAI,yBAAe,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC,CAAA;AAD7D,QAAA,QAAQ,YACqD;AAEnE,MAAM,cAAc,GAAG,GAAW,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;AAA5D,QAAA,cAAc,kBAA8C;AAElE,MAAM,WAAW,GAAG,GAAW,EAAE,CACtC,IAAI,yBAAe,CAAC,IAAA,sBAAc,GAAE,CAAC,CAAC,KAAK,CAAC,wBAAgB,CAAC,CAAC,QAAQ,EAAE,CAAA;AAD7D,QAAA,WAAW,eACkD;AAEnE,MAAM,QAAQ,GAAG,CAAC,GAAG,GAAG,CAAC,EAAU,EAAE,CAC1C,IAAI,yBAAe,CAAC,IAAA,sBAAc,GAAE,CAAC;KAClC,KAAK,CAAC,wBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;KAClC,QAAQ,EAAE,CAAA;AAHF,QAAA,QAAQ,YAGN;AAER,MAAM,iCAAiC,GAAG,CAC/C,aAA8B,EACtB,EAAE;IACV,MAAM,WAAW,GAAG,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,CAAA;IAE7D,OAAO,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;AAC5C,CAAC,CAAA;AANY,QAAA,iCAAiC,qCAM7C"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/utils",
|
|
3
3
|
"description": "List of utils and helper functions that can be reused throughout Injective's projects.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.56",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -31,10 +31,9 @@
|
|
|
31
31
|
"@injectivelabs/ts-types": "^0.0.38",
|
|
32
32
|
"axios": "^0.21.1",
|
|
33
33
|
"bignumber.js": "^9.0.1",
|
|
34
|
-
"date-fns": "^2.28.0",
|
|
35
34
|
"link-module-alias": "^1.2.0",
|
|
36
35
|
"shx": "^0.3.2",
|
|
37
36
|
"store2": "^2.12.0"
|
|
38
37
|
},
|
|
39
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "fb71ba9559719bf67a73881e268a5b3cbdeb9fa3"
|
|
40
39
|
}
|