@injectivelabs/utils 1.16.38-alpha.5 → 1.16.38

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.
Files changed (89) hide show
  1. package/dist/cjs/classes/BigNumber.d.ts +14 -0
  2. package/dist/cjs/classes/BigNumber.js +33 -0
  3. package/dist/cjs/classes/BigNumberInBase.d.ts +16 -0
  4. package/dist/cjs/classes/BigNumberInBase.js +39 -0
  5. package/dist/cjs/classes/BigNumberInWei.d.ts +16 -0
  6. package/dist/cjs/classes/BigNumberInWei.js +39 -0
  7. package/dist/cjs/classes/HttpClient.d.ts +11 -0
  8. package/dist/cjs/classes/HttpClient.js +39 -0
  9. package/dist/cjs/classes/HttpRestClient.d.ts +14 -0
  10. package/dist/cjs/classes/HttpRestClient.js +110 -0
  11. package/dist/cjs/classes/LocalStorage.d.ts +9 -0
  12. package/dist/cjs/classes/LocalStorage.js +25 -0
  13. package/dist/cjs/classes/Status.d.ts +22 -0
  14. package/dist/cjs/classes/Status.js +61 -0
  15. package/dist/cjs/classes/StreamManager.d.ts +9 -0
  16. package/dist/cjs/classes/StreamManager.js +41 -0
  17. package/dist/cjs/classes/index.d.ts +10 -0
  18. package/dist/cjs/classes/index.js +60 -0
  19. package/dist/cjs/constants.d.ts +37 -0
  20. package/dist/cjs/constants.js +54 -0
  21. package/dist/cjs/enum.d.ts +8 -0
  22. package/dist/cjs/enum.js +10 -0
  23. package/dist/cjs/formatters.d.ts +5 -0
  24. package/dist/cjs/formatters.js +31 -0
  25. package/dist/cjs/helpers.d.ts +73 -0
  26. package/dist/cjs/helpers.js +145 -0
  27. package/dist/cjs/index.d.ts +6 -0
  28. package/dist/cjs/index.js +22 -0
  29. package/dist/cjs/numbers.d.ts +4 -0
  30. package/dist/cjs/numbers.js +37 -0
  31. package/dist/cjs/package.json +2 -2
  32. package/dist/cjs/test-utils/index.d.ts +2 -0
  33. package/dist/cjs/test-utils/index.js +18 -0
  34. package/dist/cjs/test-utils/mocks/index.d.ts +153 -0
  35. package/dist/cjs/test-utils/mocks/index.js +106 -0
  36. package/dist/cjs/test-utils/msgs.d.ts +44 -0
  37. package/dist/cjs/test-utils/msgs.js +54 -0
  38. package/dist/cjs/time.d.ts +9 -0
  39. package/dist/cjs/time.js +41 -0
  40. package/dist/cjs/types.d.ts +3 -0
  41. package/dist/cjs/types.js +2 -0
  42. package/dist/esm/classes/BigNumber.d.ts +14 -0
  43. package/dist/esm/classes/BigNumber.js +27 -0
  44. package/dist/esm/classes/BigNumberInBase.d.ts +16 -0
  45. package/dist/esm/classes/BigNumberInBase.js +33 -0
  46. package/dist/esm/classes/BigNumberInWei.d.ts +16 -0
  47. package/dist/esm/classes/BigNumberInWei.js +33 -0
  48. package/dist/esm/classes/HttpClient.d.ts +11 -0
  49. package/dist/esm/classes/HttpClient.js +33 -0
  50. package/dist/esm/classes/HttpRestClient.d.ts +14 -0
  51. package/dist/esm/classes/HttpRestClient.js +104 -0
  52. package/dist/esm/classes/LocalStorage.d.ts +9 -0
  53. package/dist/esm/classes/LocalStorage.js +22 -0
  54. package/dist/esm/classes/Status.d.ts +22 -0
  55. package/dist/esm/classes/Status.js +58 -0
  56. package/dist/esm/classes/StreamManager.d.ts +9 -0
  57. package/dist/esm/classes/StreamManager.js +38 -0
  58. package/dist/esm/classes/index.d.ts +10 -0
  59. package/dist/esm/classes/index.js +10 -0
  60. package/dist/esm/constants.d.ts +37 -0
  61. package/dist/esm/constants.js +46 -0
  62. package/dist/esm/enum.d.ts +8 -0
  63. package/dist/esm/enum.js +7 -0
  64. package/dist/esm/formatters.d.ts +5 -0
  65. package/dist/esm/formatters.js +24 -0
  66. package/dist/esm/helpers.d.ts +73 -0
  67. package/dist/esm/helpers.js +100 -0
  68. package/dist/esm/index.d.ts +6 -279
  69. package/dist/esm/index.js +6 -509
  70. package/dist/esm/numbers.d.ts +4 -0
  71. package/dist/esm/numbers.js +28 -0
  72. package/dist/esm/package.json +2 -2
  73. package/dist/esm/test-utils/index.d.ts +2 -218
  74. package/dist/esm/test-utils/index.js +2 -157
  75. package/dist/esm/test-utils/mocks/index.d.ts +153 -0
  76. package/dist/esm/test-utils/mocks/index.js +103 -0
  77. package/dist/esm/test-utils/msgs.d.ts +44 -0
  78. package/dist/esm/test-utils/msgs.js +47 -0
  79. package/dist/esm/time.d.ts +9 -0
  80. package/dist/esm/time.js +27 -0
  81. package/dist/esm/types.d.ts +3 -0
  82. package/dist/esm/types.js +1 -0
  83. package/package.json +50 -49
  84. package/dist/cjs/constants-DEbTiKzu.cjs +0 -192
  85. package/dist/cjs/index.cjs +0 -590
  86. package/dist/cjs/index.d.cts +0 -279
  87. package/dist/cjs/test-utils/index.cjs +0 -161
  88. package/dist/cjs/test-utils/index.d.cts +0 -218
  89. package/dist/esm/constants-BxcSsKjm.js +0 -66
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DEFAULT_STD_FEE_BY_DENOM = exports.getDefaultStdFee = exports.DEFAULT_TIMESTAMP_TIMEOUT_MS = exports.DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS = exports.DEFAULT_BLOCK_TIME_IN_SECONDS = exports.DEFAULT_BLOCK_TIMEOUT_HEIGHT = exports.DEFAULT_BRIDGE_FEE_AMOUNT = exports.DEFAULT_BRIDGE_FEE_PRICE = exports.DEFAULT_BRIDGE_FEE_DENOM = exports.DEFAULT_EXCHANGE_LIMIT = exports.DEFAULT_GAS_PRICE = exports.DEFAULT_IBC_GAS_LIMIT = exports.DEFAULT_GAS_LIMIT = exports.DEFAULT_FEE_DENOM = exports.INJECTIVE_DENOM = exports.INJ_DENOM = exports.ZERO_ADDRESS = void 0;
7
+ const BigNumber_js_1 = __importDefault(require("./classes/BigNumber.js"));
8
+ exports.ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
9
+ exports.INJ_DENOM = 'inj';
10
+ exports.INJECTIVE_DENOM = 'inj';
11
+ exports.DEFAULT_FEE_DENOM = 'inj';
12
+ exports.DEFAULT_GAS_LIMIT = 400000;
13
+ exports.DEFAULT_IBC_GAS_LIMIT = 300000;
14
+ exports.DEFAULT_GAS_PRICE = 160000000;
15
+ exports.DEFAULT_EXCHANGE_LIMIT = 200000;
16
+ exports.DEFAULT_BRIDGE_FEE_DENOM = 'inj';
17
+ exports.DEFAULT_BRIDGE_FEE_PRICE = '160000000';
18
+ exports.DEFAULT_BRIDGE_FEE_AMOUNT = '200000000000000';
19
+ exports.DEFAULT_BLOCK_TIMEOUT_HEIGHT = 120;
20
+ exports.DEFAULT_BLOCK_TIME_IN_SECONDS = 0.7;
21
+ /**
22
+ * Default timeout for transaction block inclusion polling.
23
+ *
24
+ * Calculation: 120 blocks × 0.7 seconds/block = 84 seconds = 84,000ms
25
+ */
26
+ exports.DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS = Math.floor(exports.DEFAULT_BLOCK_TIMEOUT_HEIGHT * exports.DEFAULT_BLOCK_TIME_IN_SECONDS * 1000);
27
+ exports.DEFAULT_TIMESTAMP_TIMEOUT_MS = 60 * 1000 * 3;
28
+ const getDefaultStdFee = () => ({
29
+ amount: [
30
+ {
31
+ amount: new BigNumber_js_1.default(exports.DEFAULT_GAS_LIMIT)
32
+ .times(exports.DEFAULT_GAS_PRICE)
33
+ .toString(),
34
+ denom: 'inj',
35
+ },
36
+ ],
37
+ gas: exports.DEFAULT_GAS_LIMIT.toString(),
38
+ payer: '',
39
+ granter: '',
40
+ feePayer: '',
41
+ });
42
+ exports.getDefaultStdFee = getDefaultStdFee;
43
+ const DEFAULT_STD_FEE_BY_DENOM = (denom = 'inj') => ({
44
+ amount: [
45
+ {
46
+ denom,
47
+ amount: new BigNumber_js_1.default(exports.DEFAULT_GAS_LIMIT)
48
+ .times(exports.DEFAULT_GAS_PRICE)
49
+ .toString(),
50
+ },
51
+ ],
52
+ gas: exports.DEFAULT_GAS_LIMIT.toString(),
53
+ });
54
+ exports.DEFAULT_STD_FEE_BY_DENOM = DEFAULT_STD_FEE_BY_DENOM;
@@ -0,0 +1,8 @@
1
+ export declare const StatusType: {
2
+ readonly Idle: "idle";
3
+ readonly Loading: "loading";
4
+ readonly Completed: "completed";
5
+ readonly Error: "error";
6
+ readonly Confirmed: "confirmed";
7
+ };
8
+ export type StatusType = (typeof StatusType)[keyof typeof StatusType];
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StatusType = void 0;
4
+ exports.StatusType = {
5
+ Idle: 'idle',
6
+ Loading: 'loading',
7
+ Completed: 'completed',
8
+ Error: 'error',
9
+ Confirmed: 'confirmed',
10
+ };
@@ -0,0 +1,5 @@
1
+ import type { AccountAddress } from '@injectivelabs/ts-types';
2
+ export declare const formatWalletAddress: (address: AccountAddress, substrLength?: number) => string;
3
+ export declare const toPascalCase: (str: string) => string;
4
+ export declare const snakeToPascal: (str: string) => string;
5
+ export declare const capitalize: (str: string) => string;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.capitalize = exports.snakeToPascal = exports.toPascalCase = exports.formatWalletAddress = void 0;
4
+ const formatWalletAddress = (address, substrLength = 6) => {
5
+ if (address.length <= 10) {
6
+ return address;
7
+ }
8
+ return `${address.slice(0, substrLength)}...${address.slice(address.length - substrLength, address.length)}`;
9
+ };
10
+ exports.formatWalletAddress = formatWalletAddress;
11
+ const toPascalCase = (str) => {
12
+ return `${str}`
13
+ .toLowerCase()
14
+ .replace(new RegExp(/[-_]+/, 'g'), ' ')
15
+ .replace(new RegExp(/[^\w\s]/, 'g'), '')
16
+ .replace(new RegExp(/\s+(.)(\w*)/, 'g'), (_$1, $2, $3) => `${$2.toUpperCase() + $3}`)
17
+ .replace(new RegExp(/\w/), (s) => s.toUpperCase());
18
+ };
19
+ exports.toPascalCase = toPascalCase;
20
+ const snakeToPascal = (str) => {
21
+ return str
22
+ .split('/')
23
+ .map((snake) => snake
24
+ .split('_')
25
+ .map((substr) => substr.charAt(0).toUpperCase() + substr.slice(1))
26
+ .join(''))
27
+ .join('/');
28
+ };
29
+ exports.snakeToPascal = snakeToPascal;
30
+ const capitalize = (str) => str[0].toUpperCase() + str.slice(1);
31
+ exports.capitalize = capitalize;
@@ -0,0 +1,73 @@
1
+ import type { Awaited } from './types.js';
2
+ export declare const sleep: (timeout: number) => Promise<void>;
3
+ /**
4
+ * When we want to execute the promises in batch
5
+ */
6
+ export declare const awaitAll: <T, S>(array: Array<T>, callback: (item: T) => Promise<S>) => Promise<Awaited<S>[]>;
7
+ /**
8
+ * When we want to execute the promises one by one
9
+ * and not all in batch as with await Promise.all()
10
+ */
11
+ export declare const awaitForAll: <T, S>(array: Array<T>, callback: (item: T) => Promise<S>) => Promise<S[]>;
12
+ export declare const splitArrayToChunksThrow: <T>({ array, filter, chunkSize, }: {
13
+ array: Array<T>;
14
+ chunkSize: number;
15
+ filter?: (item: T) => boolean;
16
+ }) => T[][];
17
+ export declare const splitArrayToChunks: <T>({ array, filter, chunkSize, }: {
18
+ array: Array<T>;
19
+ chunkSize: number;
20
+ filter?: (item: T) => boolean;
21
+ }) => T[][];
22
+ export declare const getStdFeeForToken: (token?: {
23
+ denom: string;
24
+ decimals: number;
25
+ }, gasPrice?: string, gasLimit?: string) => {
26
+ amount: {
27
+ denom: string;
28
+ amount: string;
29
+ }[];
30
+ gas: string;
31
+ };
32
+ export declare const getStdFeeFromObject: (args?: {
33
+ gas?: string | number;
34
+ payer?: string;
35
+ granter?: string;
36
+ gasPrice?: string | number;
37
+ feePayer?: string;
38
+ }) => {
39
+ amount: {
40
+ denom: string;
41
+ amount: string;
42
+ }[];
43
+ gas: string;
44
+ payer: string | undefined; /** for Web3Gateway fee delegation */
45
+ granter: string | undefined;
46
+ feePayer: string | undefined;
47
+ };
48
+ export declare const getStdFeeFromString: (gasPrice: string) => {
49
+ amount: {
50
+ denom: string;
51
+ amount: string;
52
+ }[];
53
+ gas: string;
54
+ payer: string | undefined; /** for Web3Gateway fee delegation */
55
+ granter: string | undefined;
56
+ feePayer: string | undefined;
57
+ };
58
+ export declare const getStdFee: (args?: string | {
59
+ payer?: string;
60
+ granter?: string;
61
+ feePayer?: string;
62
+ gas?: string | number;
63
+ gasPrice?: string | number;
64
+ }) => {
65
+ amount: {
66
+ denom: string;
67
+ amount: string;
68
+ }[];
69
+ gas: string;
70
+ payer: string | undefined; /** for Web3Gateway fee delegation */
71
+ granter: string | undefined;
72
+ feePayer: string | undefined;
73
+ };
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.getStdFee = exports.getStdFeeFromString = exports.getStdFeeFromObject = exports.getStdFeeForToken = exports.splitArrayToChunks = exports.splitArrayToChunksThrow = exports.awaitForAll = exports.awaitAll = exports.sleep = void 0;
37
+ const constants_js_1 = require("./constants.js");
38
+ const BigNumber_js_1 = __importStar(require("./classes/BigNumber.js"));
39
+ const sleep = (timeout) => new Promise((resolve) => setTimeout(resolve, timeout));
40
+ exports.sleep = sleep;
41
+ /**
42
+ * When we want to execute the promises in batch
43
+ */
44
+ const awaitAll = async (array, callback) => await Promise.all(array.map(async (item) => await callback(item)));
45
+ exports.awaitAll = awaitAll;
46
+ /**
47
+ * When we want to execute the promises one by one
48
+ * and not all in batch as with await Promise.all()
49
+ */
50
+ const awaitForAll = async (array, callback) => {
51
+ const result = [];
52
+ for (let i = 0; i < array.length; i += 1) {
53
+ try {
54
+ result.push(await callback(array[i]));
55
+ }
56
+ catch {
57
+ //
58
+ }
59
+ }
60
+ return result;
61
+ };
62
+ exports.awaitForAll = awaitForAll;
63
+ const splitArrayToChunksThrow = ({ array, filter, chunkSize, }) => {
64
+ const chunks = [];
65
+ const chunkSizeInNumber = Number(chunkSize);
66
+ if (isNaN(chunkSizeInNumber)) {
67
+ throw new Error('Invalid chunk size, must be a valid number');
68
+ }
69
+ for (let i = 0; i < array.length; i += chunkSizeInNumber) {
70
+ const chunk = array.slice(i, i + chunkSizeInNumber);
71
+ if (filter) {
72
+ chunks.push(chunk.filter(filter));
73
+ }
74
+ else {
75
+ chunks.push(chunk);
76
+ }
77
+ }
78
+ return chunks;
79
+ };
80
+ exports.splitArrayToChunksThrow = splitArrayToChunksThrow;
81
+ const splitArrayToChunks = ({ array, filter, chunkSize, }) => {
82
+ try {
83
+ return (0, exports.splitArrayToChunksThrow)({ array, chunkSize, filter });
84
+ }
85
+ catch {
86
+ return [array];
87
+ }
88
+ };
89
+ exports.splitArrayToChunks = splitArrayToChunks;
90
+ const getStdFeeForToken = (token = { denom: 'inj', decimals: 18 }, gasPrice, gasLimit) => {
91
+ const gasPriceInBase = gasPrice || (0, BigNumber_js_1.toHumanReadable)(constants_js_1.DEFAULT_GAS_PRICE, 18);
92
+ const gasPriceScaled = (0, BigNumber_js_1.toChainFormat)(gasPriceInBase, token.decimals).toFixed(0);
93
+ const gasNormalized = new BigNumber_js_1.default(gasLimit || constants_js_1.DEFAULT_GAS_LIMIT).toFixed(0);
94
+ return {
95
+ amount: [
96
+ {
97
+ denom: token.denom,
98
+ amount: new BigNumber_js_1.default(gasPriceScaled).times(gasNormalized).toFixed(),
99
+ },
100
+ ],
101
+ gas: (gasLimit || constants_js_1.DEFAULT_GAS_LIMIT).toString(),
102
+ };
103
+ };
104
+ exports.getStdFeeForToken = getStdFeeForToken;
105
+ const getStdFeeFromObject = (args) => {
106
+ if (!args) {
107
+ return (0, constants_js_1.getDefaultStdFee)();
108
+ }
109
+ const { payer, granter, feePayer, gasPrice = constants_js_1.DEFAULT_GAS_PRICE, gas = constants_js_1.DEFAULT_GAS_LIMIT.toString(), } = args;
110
+ const gasNormalized = (0, BigNumber_js_1.toBigNumber)(gas).toFixed(0);
111
+ const gasPriceNormalized = (0, BigNumber_js_1.toBigNumber)(gasPrice).toFixed(0);
112
+ return {
113
+ amount: [
114
+ {
115
+ denom: 'inj',
116
+ amount: (0, BigNumber_js_1.toBigNumber)(gasNormalized).times(gasPriceNormalized).toFixed(),
117
+ },
118
+ ],
119
+ gas: (0, BigNumber_js_1.toBigNumber)(gasNormalized).toFixed(),
120
+ payer /** for Web3Gateway fee delegation */,
121
+ granter,
122
+ feePayer,
123
+ };
124
+ };
125
+ exports.getStdFeeFromObject = getStdFeeFromObject;
126
+ const getStdFeeFromString = (gasPrice) => {
127
+ const matchResult = gasPrice.match(/^([0-9.]+)([a-zA-Z][a-zA-Z0-9/:._-]*)$/);
128
+ if (!matchResult) {
129
+ throw new Error('Invalid gas price string');
130
+ }
131
+ const [_, amount] = matchResult;
132
+ const gas = (0, BigNumber_js_1.toChainFormat)(amount, 18).dividedBy(constants_js_1.DEFAULT_GAS_PRICE).toFixed(0);
133
+ return (0, exports.getStdFeeFromObject)({ gas, gasPrice: constants_js_1.DEFAULT_GAS_PRICE });
134
+ };
135
+ exports.getStdFeeFromString = getStdFeeFromString;
136
+ const getStdFee = (args) => {
137
+ if (!args) {
138
+ return (0, constants_js_1.getDefaultStdFee)();
139
+ }
140
+ if (typeof args === 'string') {
141
+ return (0, exports.getStdFeeFromString)(args);
142
+ }
143
+ return (0, exports.getStdFeeFromObject)({ ...args });
144
+ };
145
+ exports.getStdFee = getStdFee;
@@ -0,0 +1,6 @@
1
+ export * from './time.js';
2
+ export * from './helpers.js';
3
+ export * from './numbers.js';
4
+ export * from './constants.js';
5
+ export * from './formatters.js';
6
+ export * from './classes/index.js';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./time.js"), exports);
18
+ __exportStar(require("./helpers.js"), exports);
19
+ __exportStar(require("./numbers.js"), exports);
20
+ __exportStar(require("./constants.js"), exports);
21
+ __exportStar(require("./formatters.js"), exports);
22
+ __exportStar(require("./classes/index.js"), exports);
@@ -0,0 +1,4 @@
1
+ import BigNumber from './classes/BigNumber.js';
2
+ export declare const getBigNumberWithRounding: () => typeof BigNumber;
3
+ export declare const getSignificantDecimalsFromNumber: (number: BigNumber | number | string) => number;
4
+ export declare const getExactDecimalsFromNumber: (number: number | string) => number;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getExactDecimalsFromNumber = exports.getSignificantDecimalsFromNumber = exports.getBigNumberWithRounding = void 0;
7
+ const BigNumber_js_1 = __importDefault(require("./classes/BigNumber.js"));
8
+ const getBigNumberWithRounding = () => BigNumber_js_1.default.clone({ ROUNDING_MODE: BigNumber_js_1.default.ROUND_DOWN });
9
+ exports.getBigNumberWithRounding = getBigNumberWithRounding;
10
+ const getSignificantDecimalsFromNumber = (number) => {
11
+ const $BigNumber = (0, exports.getBigNumberWithRounding)();
12
+ if (Math.floor(new $BigNumber(number).toNumber()) === number) {
13
+ return 0;
14
+ }
15
+ const parts = new $BigNumber(number).toFixed().split('.');
16
+ const [, decimals] = parts;
17
+ /** Number doesn't have decimals */
18
+ if (!decimals) {
19
+ return 0;
20
+ }
21
+ return decimals.length;
22
+ };
23
+ exports.getSignificantDecimalsFromNumber = getSignificantDecimalsFromNumber;
24
+ const getExactDecimalsFromNumber = (number) => {
25
+ if (!number.toString().includes('.')) {
26
+ return 0;
27
+ }
28
+ if (Number(number) % 1 === 0) {
29
+ return 0;
30
+ }
31
+ const [, decimals] = number.toString().split('.');
32
+ if (!decimals) {
33
+ return 0;
34
+ }
35
+ return decimals.length;
36
+ };
37
+ exports.getExactDecimalsFromNumber = getExactDecimalsFromNumber;
@@ -1,3 +1,3 @@
1
1
  {
2
- "type": "commonjs"
3
- }
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,2 @@
1
+ export * from './mocks/index.js';
2
+ export * from './msgs.js';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./mocks/index.js"), exports);
18
+ __exportStar(require("./msgs.js"), exports);
@@ -0,0 +1,153 @@
1
+ import { ChainId, EvmChainId } from '@injectivelabs/ts-types';
2
+ import type { ChainId as ChainIdType, EvmChainId as EvmChainIdType } from '@injectivelabs/ts-types';
3
+ export declare const injUsdtSpotMarket: {
4
+ marketId: string;
5
+ marketStatus: string;
6
+ ticker: string;
7
+ baseDenom: string;
8
+ quoteDenom: string;
9
+ quoteToken: {
10
+ name: string;
11
+ address: string;
12
+ symbol: string;
13
+ logo: string;
14
+ decimals: number;
15
+ coinGeckoId: string;
16
+ };
17
+ baseToken: {
18
+ name: string;
19
+ address: string;
20
+ symbol: string;
21
+ logo: string;
22
+ decimals: number;
23
+ coinGeckoId: string;
24
+ };
25
+ makerFeeRate: string;
26
+ takerFeeRate: string;
27
+ serviceProviderFee: string;
28
+ minPriceTickSize: string;
29
+ minQuantityTickSize: string;
30
+ };
31
+ export declare const injUsdtDerivativeMarket: {
32
+ oracleBase: string;
33
+ oracleQuote: string;
34
+ oracleType: string;
35
+ initialMarginRatio: string;
36
+ maintenanceMarginRatio: string;
37
+ isPerpetual: boolean;
38
+ marketId: string;
39
+ marketStatus: string;
40
+ ticker: string;
41
+ quoteDenom: string;
42
+ makerFeeRate: string;
43
+ takerFeeRate: string;
44
+ serviceProviderFee: string;
45
+ minPriceTickSize: number;
46
+ minQuantityTickSize: number;
47
+ perpetualMarketInfo: {
48
+ hourlyFundingRateCap: string;
49
+ hourlyInterestRate: string;
50
+ nextFundingTimestamp: number;
51
+ fundingInterval: number;
52
+ };
53
+ perpetualMarketFunding: {
54
+ cumulativeFunding: string;
55
+ cumulativePrice: string;
56
+ lastTimestamp: number;
57
+ };
58
+ };
59
+ export declare const mockFactory: {
60
+ ethereumAddress: string;
61
+ injectiveAddress: string;
62
+ injectiveAddress2: string;
63
+ validatorAddress: string;
64
+ validatorAddress2: string;
65
+ derivativeMarketId: string;
66
+ spotMarketId: string;
67
+ subaccountId: string;
68
+ subaccountId2: string;
69
+ injUsdtSpotMarket: {
70
+ marketId: string;
71
+ marketStatus: string;
72
+ ticker: string;
73
+ baseDenom: string;
74
+ quoteDenom: string;
75
+ quoteToken: {
76
+ name: string;
77
+ address: string;
78
+ symbol: string;
79
+ logo: string;
80
+ decimals: number;
81
+ coinGeckoId: string;
82
+ };
83
+ baseToken: {
84
+ name: string;
85
+ address: string;
86
+ symbol: string;
87
+ logo: string;
88
+ decimals: number;
89
+ coinGeckoId: string;
90
+ };
91
+ makerFeeRate: string;
92
+ takerFeeRate: string;
93
+ serviceProviderFee: string;
94
+ minPriceTickSize: string;
95
+ minQuantityTickSize: string;
96
+ };
97
+ injUsdtDerivativeMarket: {
98
+ oracleBase: string;
99
+ oracleQuote: string;
100
+ oracleType: string;
101
+ initialMarginRatio: string;
102
+ maintenanceMarginRatio: string;
103
+ isPerpetual: boolean;
104
+ marketId: string;
105
+ marketStatus: string;
106
+ ticker: string;
107
+ quoteDenom: string;
108
+ makerFeeRate: string;
109
+ takerFeeRate: string;
110
+ serviceProviderFee: string;
111
+ minPriceTickSize: number;
112
+ minQuantityTickSize: number;
113
+ perpetualMarketInfo: {
114
+ hourlyFundingRateCap: string;
115
+ hourlyInterestRate: string;
116
+ nextFundingTimestamp: number;
117
+ fundingInterval: number;
118
+ };
119
+ perpetualMarketFunding: {
120
+ cumulativeFunding: string;
121
+ cumulativePrice: string;
122
+ lastTimestamp: number;
123
+ };
124
+ };
125
+ orderHash: string;
126
+ orderHash2: string;
127
+ MAX_TIMEOUT_HEIGHT: number;
128
+ eip712Tx: ({ chainId, evmChainId, accountNumber, sequence, timeoutHeight, memo, }: {
129
+ chainId?: ChainIdType;
130
+ evmChainId?: EvmChainIdType;
131
+ accountNumber?: number;
132
+ sequence?: number;
133
+ timeoutHeight?: number;
134
+ memo?: string;
135
+ }) => {
136
+ tx: {
137
+ memo: string;
138
+ chainId: ChainId;
139
+ sequence: number;
140
+ evmChainId: EvmChainId;
141
+ accountNumber: number;
142
+ timeoutHeight: number;
143
+ };
144
+ eip712: {
145
+ memo: string;
146
+ chainId: ChainId;
147
+ sequence: number;
148
+ accountNumber: number;
149
+ evmChainId: EvmChainId;
150
+ timeoutHeight: number;
151
+ };
152
+ };
153
+ };