@injectivelabs/utils 1.16.38 → 1.16.39-alpha.0
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/cjs/constants-DEbTiKzu.cjs +192 -0
- package/dist/cjs/index.cjs +591 -0
- package/dist/cjs/index.d.cts +279 -0
- package/dist/cjs/package.json +2 -2
- package/dist/cjs/test-utils/index.cjs +161 -0
- package/dist/cjs/test-utils/index.d.cts +218 -0
- package/dist/esm/constants-BxcSsKjm.js +66 -0
- package/dist/esm/index.d.ts +279 -6
- package/dist/esm/index.js +509 -6
- package/dist/esm/package.json +2 -2
- package/dist/esm/test-utils/index.d.ts +218 -2
- package/dist/esm/test-utils/index.js +157 -2
- package/package.json +49 -50
- package/dist/cjs/classes/BigNumber.d.ts +0 -14
- package/dist/cjs/classes/BigNumber.js +0 -33
- package/dist/cjs/classes/BigNumberInBase.d.ts +0 -16
- package/dist/cjs/classes/BigNumberInBase.js +0 -39
- package/dist/cjs/classes/BigNumberInWei.d.ts +0 -16
- package/dist/cjs/classes/BigNumberInWei.js +0 -39
- package/dist/cjs/classes/HttpClient.d.ts +0 -11
- package/dist/cjs/classes/HttpClient.js +0 -39
- package/dist/cjs/classes/HttpRestClient.d.ts +0 -14
- package/dist/cjs/classes/HttpRestClient.js +0 -110
- package/dist/cjs/classes/LocalStorage.d.ts +0 -9
- package/dist/cjs/classes/LocalStorage.js +0 -25
- package/dist/cjs/classes/Status.d.ts +0 -22
- package/dist/cjs/classes/Status.js +0 -61
- package/dist/cjs/classes/StreamManager.d.ts +0 -9
- package/dist/cjs/classes/StreamManager.js +0 -41
- package/dist/cjs/classes/index.d.ts +0 -10
- package/dist/cjs/classes/index.js +0 -60
- package/dist/cjs/constants.d.ts +0 -37
- package/dist/cjs/constants.js +0 -54
- package/dist/cjs/enum.d.ts +0 -8
- package/dist/cjs/enum.js +0 -10
- package/dist/cjs/formatters.d.ts +0 -5
- package/dist/cjs/formatters.js +0 -31
- package/dist/cjs/helpers.d.ts +0 -73
- package/dist/cjs/helpers.js +0 -145
- package/dist/cjs/index.d.ts +0 -6
- package/dist/cjs/index.js +0 -22
- package/dist/cjs/numbers.d.ts +0 -4
- package/dist/cjs/numbers.js +0 -37
- package/dist/cjs/test-utils/index.d.ts +0 -2
- package/dist/cjs/test-utils/index.js +0 -18
- package/dist/cjs/test-utils/mocks/index.d.ts +0 -153
- package/dist/cjs/test-utils/mocks/index.js +0 -106
- package/dist/cjs/test-utils/msgs.d.ts +0 -44
- package/dist/cjs/test-utils/msgs.js +0 -54
- package/dist/cjs/time.d.ts +0 -9
- package/dist/cjs/time.js +0 -41
- package/dist/cjs/types.d.ts +0 -3
- package/dist/cjs/types.js +0 -2
- package/dist/esm/classes/BigNumber.d.ts +0 -14
- package/dist/esm/classes/BigNumber.js +0 -27
- package/dist/esm/classes/BigNumberInBase.d.ts +0 -16
- package/dist/esm/classes/BigNumberInBase.js +0 -33
- package/dist/esm/classes/BigNumberInWei.d.ts +0 -16
- package/dist/esm/classes/BigNumberInWei.js +0 -33
- package/dist/esm/classes/HttpClient.d.ts +0 -11
- package/dist/esm/classes/HttpClient.js +0 -33
- package/dist/esm/classes/HttpRestClient.d.ts +0 -14
- package/dist/esm/classes/HttpRestClient.js +0 -104
- package/dist/esm/classes/LocalStorage.d.ts +0 -9
- package/dist/esm/classes/LocalStorage.js +0 -22
- package/dist/esm/classes/Status.d.ts +0 -22
- package/dist/esm/classes/Status.js +0 -58
- package/dist/esm/classes/StreamManager.d.ts +0 -9
- package/dist/esm/classes/StreamManager.js +0 -38
- package/dist/esm/classes/index.d.ts +0 -10
- package/dist/esm/classes/index.js +0 -10
- package/dist/esm/constants.d.ts +0 -37
- package/dist/esm/constants.js +0 -46
- package/dist/esm/enum.d.ts +0 -8
- package/dist/esm/enum.js +0 -7
- package/dist/esm/formatters.d.ts +0 -5
- package/dist/esm/formatters.js +0 -24
- package/dist/esm/helpers.d.ts +0 -73
- package/dist/esm/helpers.js +0 -100
- package/dist/esm/numbers.d.ts +0 -4
- package/dist/esm/numbers.js +0 -28
- package/dist/esm/test-utils/mocks/index.d.ts +0 -153
- package/dist/esm/test-utils/mocks/index.js +0 -103
- package/dist/esm/test-utils/msgs.d.ts +0 -44
- package/dist/esm/test-utils/msgs.js +0 -47
- package/dist/esm/time.d.ts +0 -9
- package/dist/esm/time.js +0 -27
- package/dist/esm/types.d.ts +0 -3
- package/dist/esm/types.js +0 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,509 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { _ as getDefaultStdFee, a as DEFAULT_BRIDGE_FEE_PRICE, b as toChainFormat, c as DEFAULT_GAS_LIMIT, d as DEFAULT_STD_FEE_BY_DENOM, f as DEFAULT_TIMESTAMP_TIMEOUT_MS, g as ZERO_ADDRESS, h as INJ_DENOM, i as DEFAULT_BRIDGE_FEE_DENOM, l as DEFAULT_GAS_PRICE, m as INJECTIVE_DENOM, n as DEFAULT_BLOCK_TIME_IN_SECONDS, o as DEFAULT_EXCHANGE_LIMIT, p as DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS, r as DEFAULT_BRIDGE_FEE_AMOUNT, s as DEFAULT_FEE_DENOM, t as DEFAULT_BLOCK_TIMEOUT_HEIGHT, u as DEFAULT_IBC_GAS_LIMIT, v as BigNumber_default, x as toHumanReadable, y as toBigNumber } from "./constants-BxcSsKjm.js";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import store from "store2";
|
|
4
|
+
import { StatusCodes } from "http-status-codes";
|
|
5
|
+
import { HttpRequestException, HttpRequestMethod, UnspecifiedErrorCode } from "@injectivelabs/exceptions";
|
|
6
|
+
|
|
7
|
+
//#region src/time.ts
|
|
8
|
+
const getSecondsInDay = () => new BigNumber_default(3600 * 24);
|
|
9
|
+
const convertTimestampToMilliseconds = (timestamp) => {
|
|
10
|
+
const timestampInBigNumber = new BigNumber_default(timestamp);
|
|
11
|
+
if (timestamp.toString().length > 13) return timestampInBigNumber.precision(13, BigNumber_default.ROUND_HALF_UP).toNumber();
|
|
12
|
+
if (timestamp.toString().length < 13) {
|
|
13
|
+
const trailingZeros = 13 - timestamp.toString().length;
|
|
14
|
+
return timestampInBigNumber.times(10 ** trailingZeros).toNumber();
|
|
15
|
+
}
|
|
16
|
+
return timestampInBigNumber.toNumber();
|
|
17
|
+
};
|
|
18
|
+
const getUTCDateFromTimestamp = (timestamp) => {
|
|
19
|
+
const date = new Date(convertTimestampToMilliseconds(timestamp));
|
|
20
|
+
return `${date.getUTCDate()}-${date.getUTCMonth() + 1}-${date.getUTCFullYear()}`;
|
|
21
|
+
};
|
|
22
|
+
const tomorrow = () => new BigNumber_default(Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3) + 3600 * 24);
|
|
23
|
+
const todayInSeconds = () => Math.floor(Date.now() / 1e3);
|
|
24
|
+
const past24Hours = () => new BigNumber_default(todayInSeconds()).minus(getSecondsInDay()).toNumber();
|
|
25
|
+
const pastDays = (day = 1) => new BigNumber_default(todayInSeconds()).minus(getSecondsInDay().times(day)).toNumber();
|
|
26
|
+
const getEndDateStringFromTimeInSeconds = (timeInSeconds) => {
|
|
27
|
+
return (/* @__PURE__ */ new Date(timeInSeconds.toNumber() * 1e3)).toLocaleString("en-us");
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/helpers.ts
|
|
32
|
+
const sleep = (timeout) => new Promise((resolve) => setTimeout(resolve, timeout));
|
|
33
|
+
/**
|
|
34
|
+
* When we want to execute the promises in batch
|
|
35
|
+
*/
|
|
36
|
+
const awaitAll = async (array, callback) => await Promise.all(array.map(async (item) => await callback(item)));
|
|
37
|
+
/**
|
|
38
|
+
* When we want to execute the promises one by one
|
|
39
|
+
* and not all in batch as with await Promise.all()
|
|
40
|
+
*/
|
|
41
|
+
const awaitForAll = async (array, callback) => {
|
|
42
|
+
const result = [];
|
|
43
|
+
for (let i = 0; i < array.length; i += 1) try {
|
|
44
|
+
result.push(await callback(array[i]));
|
|
45
|
+
} catch (_unused) {}
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
const splitArrayToChunksThrow = ({ array, filter, chunkSize }) => {
|
|
49
|
+
const chunks = [];
|
|
50
|
+
const chunkSizeInNumber = Number(chunkSize);
|
|
51
|
+
if (isNaN(chunkSizeInNumber)) throw new Error("Invalid chunk size, must be a valid number");
|
|
52
|
+
for (let i = 0; i < array.length; i += chunkSizeInNumber) {
|
|
53
|
+
const chunk = array.slice(i, i + chunkSizeInNumber);
|
|
54
|
+
if (filter) chunks.push(chunk.filter(filter));
|
|
55
|
+
else chunks.push(chunk);
|
|
56
|
+
}
|
|
57
|
+
return chunks;
|
|
58
|
+
};
|
|
59
|
+
const splitArrayToChunks = ({ array, filter, chunkSize }) => {
|
|
60
|
+
try {
|
|
61
|
+
return splitArrayToChunksThrow({
|
|
62
|
+
array,
|
|
63
|
+
chunkSize,
|
|
64
|
+
filter
|
|
65
|
+
});
|
|
66
|
+
} catch (_unused2) {
|
|
67
|
+
return [array];
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const getStdFeeForToken = (token = {
|
|
71
|
+
denom: "inj",
|
|
72
|
+
decimals: 18
|
|
73
|
+
}, gasPrice, gasLimit) => {
|
|
74
|
+
const gasPriceScaled = toChainFormat(gasPrice || toHumanReadable(DEFAULT_GAS_PRICE, 18), token.decimals).toFixed(0);
|
|
75
|
+
const gasNormalized = new BigNumber_default(gasLimit || DEFAULT_GAS_LIMIT).toFixed(0);
|
|
76
|
+
return {
|
|
77
|
+
amount: [{
|
|
78
|
+
denom: token.denom,
|
|
79
|
+
amount: new BigNumber_default(gasPriceScaled).times(gasNormalized).toFixed()
|
|
80
|
+
}],
|
|
81
|
+
gas: (gasLimit || DEFAULT_GAS_LIMIT).toString()
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
const getStdFeeFromObject = (args) => {
|
|
85
|
+
if (!args) return getDefaultStdFee();
|
|
86
|
+
const { payer, granter, feePayer, gasPrice = DEFAULT_GAS_PRICE, gas = DEFAULT_GAS_LIMIT.toString() } = args;
|
|
87
|
+
const gasNormalized = toBigNumber(gas).toFixed(0);
|
|
88
|
+
const gasPriceNormalized = toBigNumber(gasPrice).toFixed(0);
|
|
89
|
+
return {
|
|
90
|
+
amount: [{
|
|
91
|
+
denom: "inj",
|
|
92
|
+
amount: toBigNumber(gasNormalized).times(gasPriceNormalized).toFixed()
|
|
93
|
+
}],
|
|
94
|
+
gas: toBigNumber(gasNormalized).toFixed(),
|
|
95
|
+
payer,
|
|
96
|
+
granter,
|
|
97
|
+
feePayer
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
const getStdFeeFromString = (gasPrice) => {
|
|
101
|
+
const matchResult = gasPrice.match(/^([0-9.]+)([a-zA-Z][a-zA-Z0-9/:._-]*)$/);
|
|
102
|
+
if (!matchResult) throw new Error("Invalid gas price string");
|
|
103
|
+
const [_, amount] = matchResult;
|
|
104
|
+
return getStdFeeFromObject({
|
|
105
|
+
gas: toChainFormat(amount, 18).dividedBy(DEFAULT_GAS_PRICE).toFixed(0),
|
|
106
|
+
gasPrice: DEFAULT_GAS_PRICE
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
const getStdFee = (args) => {
|
|
110
|
+
if (!args) return getDefaultStdFee();
|
|
111
|
+
if (typeof args === "string") return getStdFeeFromString(args);
|
|
112
|
+
return getStdFeeFromObject({ ...args });
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/numbers.ts
|
|
117
|
+
const getBigNumberWithRounding = () => BigNumber_default.clone({ ROUNDING_MODE: BigNumber_default.ROUND_DOWN });
|
|
118
|
+
const getSignificantDecimalsFromNumber = (number) => {
|
|
119
|
+
const $BigNumber = getBigNumberWithRounding();
|
|
120
|
+
if (Math.floor(new $BigNumber(number).toNumber()) === number) return 0;
|
|
121
|
+
const [, decimals] = new $BigNumber(number).toFixed().split(".");
|
|
122
|
+
/** Number doesn't have decimals */
|
|
123
|
+
if (!decimals) return 0;
|
|
124
|
+
return decimals.length;
|
|
125
|
+
};
|
|
126
|
+
const getExactDecimalsFromNumber = (number) => {
|
|
127
|
+
if (!number.toString().includes(".")) return 0;
|
|
128
|
+
if (Number(number) % 1 === 0) return 0;
|
|
129
|
+
const [, decimals] = number.toString().split(".");
|
|
130
|
+
if (!decimals) return 0;
|
|
131
|
+
return decimals.length;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/formatters.ts
|
|
136
|
+
const formatWalletAddress = (address, substrLength = 6) => {
|
|
137
|
+
if (address.length <= 10) return address;
|
|
138
|
+
return `${address.slice(0, substrLength)}...${address.slice(address.length - substrLength, address.length)}`;
|
|
139
|
+
};
|
|
140
|
+
const toPascalCase = (str) => {
|
|
141
|
+
return `${str}`.toLowerCase().replace(new RegExp(/[-_]+/, "g"), " ").replace(new RegExp(/[^\w\s]/, "g"), "").replace(new RegExp(/\s+(.)(\w*)/, "g"), (_$1, $2, $3) => `${$2.toUpperCase() + $3}`).replace(/* @__PURE__ */ new RegExp(/\w/), (s) => s.toUpperCase());
|
|
142
|
+
};
|
|
143
|
+
const snakeToPascal = (str) => {
|
|
144
|
+
return str.split("/").map((snake) => snake.split("_").map((substr) => substr.charAt(0).toUpperCase() + substr.slice(1)).join("")).join("/");
|
|
145
|
+
};
|
|
146
|
+
const capitalize = (str) => str[0].toUpperCase() + str.slice(1);
|
|
147
|
+
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region src/enum.ts
|
|
150
|
+
const StatusType = {
|
|
151
|
+
Idle: "idle",
|
|
152
|
+
Loading: "loading",
|
|
153
|
+
Completed: "completed",
|
|
154
|
+
Error: "error",
|
|
155
|
+
Confirmed: "confirmed"
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/typeof.js
|
|
160
|
+
function _typeof(o) {
|
|
161
|
+
"@babel/helpers - typeof";
|
|
162
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
163
|
+
return typeof o$1;
|
|
164
|
+
} : function(o$1) {
|
|
165
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
166
|
+
}, _typeof(o);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/toPrimitive.js
|
|
171
|
+
function toPrimitive(t, r) {
|
|
172
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
173
|
+
var e = t[Symbol.toPrimitive];
|
|
174
|
+
if (void 0 !== e) {
|
|
175
|
+
var i = e.call(t, r || "default");
|
|
176
|
+
if ("object" != _typeof(i)) return i;
|
|
177
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
178
|
+
}
|
|
179
|
+
return ("string" === r ? String : Number)(t);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/toPropertyKey.js
|
|
184
|
+
function toPropertyKey(t) {
|
|
185
|
+
var i = toPrimitive(t, "string");
|
|
186
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/defineProperty.js
|
|
191
|
+
function _defineProperty(e, r, t) {
|
|
192
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
193
|
+
value: t,
|
|
194
|
+
enumerable: !0,
|
|
195
|
+
configurable: !0,
|
|
196
|
+
writable: !0
|
|
197
|
+
}) : e[r] = t, e;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/classes/Status.ts
|
|
202
|
+
var Status = class {
|
|
203
|
+
constructor(status = StatusType.Idle) {
|
|
204
|
+
_defineProperty(this, "status", void 0);
|
|
205
|
+
this.status = status;
|
|
206
|
+
}
|
|
207
|
+
get() {
|
|
208
|
+
return this.status;
|
|
209
|
+
}
|
|
210
|
+
set(status) {
|
|
211
|
+
this.status = status;
|
|
212
|
+
}
|
|
213
|
+
is(status) {
|
|
214
|
+
return this.status === status;
|
|
215
|
+
}
|
|
216
|
+
isLoading() {
|
|
217
|
+
return this.is(StatusType.Loading);
|
|
218
|
+
}
|
|
219
|
+
isNotLoading() {
|
|
220
|
+
return !this.is(StatusType.Loading);
|
|
221
|
+
}
|
|
222
|
+
isCompleted() {
|
|
223
|
+
return this.is(StatusType.Completed);
|
|
224
|
+
}
|
|
225
|
+
isConfirmed() {
|
|
226
|
+
return this.is(StatusType.Confirmed);
|
|
227
|
+
}
|
|
228
|
+
isIdle() {
|
|
229
|
+
return this.is(StatusType.Idle);
|
|
230
|
+
}
|
|
231
|
+
isError() {
|
|
232
|
+
return this.is(StatusType.Error);
|
|
233
|
+
}
|
|
234
|
+
setLoading() {
|
|
235
|
+
this.set(StatusType.Loading);
|
|
236
|
+
}
|
|
237
|
+
setCompleted() {
|
|
238
|
+
this.set(StatusType.Completed);
|
|
239
|
+
}
|
|
240
|
+
setConfirmed() {
|
|
241
|
+
this.set(StatusType.Confirmed);
|
|
242
|
+
}
|
|
243
|
+
setError() {
|
|
244
|
+
this.set(StatusType.Error);
|
|
245
|
+
}
|
|
246
|
+
setIdle() {
|
|
247
|
+
this.set(StatusType.Idle);
|
|
248
|
+
}
|
|
249
|
+
toggle() {
|
|
250
|
+
this.set(this.status === StatusType.Idle ? StatusType.Loading : StatusType.Idle);
|
|
251
|
+
}
|
|
252
|
+
toString() {
|
|
253
|
+
return this.get();
|
|
254
|
+
}
|
|
255
|
+
valueOf() {
|
|
256
|
+
return this.get();
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/classes/HttpClient.ts
|
|
262
|
+
var HttpClient = class {
|
|
263
|
+
constructor(endpoint, options = { headers: { "Content-Type": "application/json" } }) {
|
|
264
|
+
_defineProperty(this, "client", void 0);
|
|
265
|
+
_defineProperty(this, "config", {});
|
|
266
|
+
this.client = axios.create({
|
|
267
|
+
baseURL: endpoint,
|
|
268
|
+
timeout: 15e3,
|
|
269
|
+
...options
|
|
270
|
+
});
|
|
271
|
+
this.config = {};
|
|
272
|
+
}
|
|
273
|
+
setConfig(config) {
|
|
274
|
+
this.config = config;
|
|
275
|
+
return this;
|
|
276
|
+
}
|
|
277
|
+
get(endpoint, params = {}) {
|
|
278
|
+
return this.client.get(endpoint, {
|
|
279
|
+
params,
|
|
280
|
+
...this.config
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
post(endpoint, data = {}) {
|
|
284
|
+
return this.client.post(endpoint, data, this.config);
|
|
285
|
+
}
|
|
286
|
+
put(endpoint, data = {}) {
|
|
287
|
+
return this.client.put(endpoint, data, this.config);
|
|
288
|
+
}
|
|
289
|
+
delete(endpoint, params = {}) {
|
|
290
|
+
return this.client.delete(endpoint, {
|
|
291
|
+
params,
|
|
292
|
+
...this.config
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/classes/LocalStorage.ts
|
|
299
|
+
var LocalStorage = class {
|
|
300
|
+
constructor(namespace) {
|
|
301
|
+
_defineProperty(this, "storage", void 0);
|
|
302
|
+
this.storage = store.namespace(namespace);
|
|
303
|
+
}
|
|
304
|
+
get(key, defaultValue = {}) {
|
|
305
|
+
return this.storage.get(key) || defaultValue;
|
|
306
|
+
}
|
|
307
|
+
has(key) {
|
|
308
|
+
return this.storage.has(key);
|
|
309
|
+
}
|
|
310
|
+
set(key, value) {
|
|
311
|
+
this.storage.set(key, value);
|
|
312
|
+
}
|
|
313
|
+
remove(key) {
|
|
314
|
+
this.storage.remove(key);
|
|
315
|
+
}
|
|
316
|
+
clear() {
|
|
317
|
+
this.storage.clear();
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
//#endregion
|
|
322
|
+
//#region src/classes/StreamManager.ts
|
|
323
|
+
var StreamManager = class {
|
|
324
|
+
constructor() {
|
|
325
|
+
_defineProperty(this, "streams", /* @__PURE__ */ new Map());
|
|
326
|
+
}
|
|
327
|
+
set(stream, streamKey) {
|
|
328
|
+
if (this.streams.has(streamKey)) throw new Error(`Stream ${streamKey} already exists`);
|
|
329
|
+
this.streams.set(streamKey, stream);
|
|
330
|
+
}
|
|
331
|
+
get(streamKey) {
|
|
332
|
+
if (!this.streams.has(streamKey)) throw new Error(`Stream ${streamKey} is not found`);
|
|
333
|
+
return this.streams.get(streamKey);
|
|
334
|
+
}
|
|
335
|
+
exists(streamKey) {
|
|
336
|
+
return this.streams.has(streamKey);
|
|
337
|
+
}
|
|
338
|
+
cancelAll() {
|
|
339
|
+
this.streams.forEach((stream) => {
|
|
340
|
+
stream.cancel();
|
|
341
|
+
});
|
|
342
|
+
this.streams = /* @__PURE__ */ new Map();
|
|
343
|
+
}
|
|
344
|
+
cancel(streamKey) {
|
|
345
|
+
if (!this.streams.has(streamKey)) throw new Error(`Stream ${streamKey} is not found`);
|
|
346
|
+
this.streams.get(streamKey).cancel();
|
|
347
|
+
this.streams.delete(streamKey);
|
|
348
|
+
}
|
|
349
|
+
cancelIfExists(streamKey) {
|
|
350
|
+
if (!this.streams.has(streamKey)) return;
|
|
351
|
+
this.streams.get(streamKey).cancel();
|
|
352
|
+
this.streams.delete(streamKey);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/classes/BigNumberInWei.ts
|
|
358
|
+
/**
|
|
359
|
+
* @deprecated - use toChainFormat instead
|
|
360
|
+
*/
|
|
361
|
+
var BigNumberInWei = class BigNumberInWei extends BigNumber_default {
|
|
362
|
+
static make(number) {
|
|
363
|
+
return new BigNumberInWei(number);
|
|
364
|
+
}
|
|
365
|
+
minus(n, base) {
|
|
366
|
+
return new BigNumberInWei(super.minus(n, base));
|
|
367
|
+
}
|
|
368
|
+
plus(n, base) {
|
|
369
|
+
return new BigNumberInWei(super.plus(n, base));
|
|
370
|
+
}
|
|
371
|
+
dividedBy(n, base) {
|
|
372
|
+
return new BigNumberInWei(super.dividedBy(n, base));
|
|
373
|
+
}
|
|
374
|
+
div(n, base) {
|
|
375
|
+
return new BigNumberInWei(super.div(n, base));
|
|
376
|
+
}
|
|
377
|
+
multipliedBy(n, base) {
|
|
378
|
+
return new BigNumberInWei(super.multipliedBy(n, base));
|
|
379
|
+
}
|
|
380
|
+
times(n, base) {
|
|
381
|
+
return new BigNumberInWei(super.times(n, base));
|
|
382
|
+
}
|
|
383
|
+
pow(n, base) {
|
|
384
|
+
return new BigNumberInWei(super.pow(n, base));
|
|
385
|
+
}
|
|
386
|
+
toBase(decimals = 18) {
|
|
387
|
+
return new BigNumber_default(this).dividedBy(new BigNumber_default(10).pow(decimals));
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
//#endregion
|
|
392
|
+
//#region src/classes/HttpRestClient.ts
|
|
393
|
+
const getErrorMessage = (error, endpoint) => {
|
|
394
|
+
if (!error.response) return `The request to ${endpoint} has failed.`;
|
|
395
|
+
return error.response.data ? error.response.data.message || error.response.data.statusMessage || error.response.data : error.response.statusText;
|
|
396
|
+
};
|
|
397
|
+
/**
|
|
398
|
+
* @hidden
|
|
399
|
+
*/
|
|
400
|
+
var HttpRestClient = class {
|
|
401
|
+
constructor(endpoint, options = {}) {
|
|
402
|
+
_defineProperty(this, "client", void 0);
|
|
403
|
+
_defineProperty(this, "endpoint", void 0);
|
|
404
|
+
this.client = new HttpClient(endpoint, options);
|
|
405
|
+
this.endpoint = endpoint;
|
|
406
|
+
}
|
|
407
|
+
setConfig(config) {
|
|
408
|
+
this.client.setConfig(config);
|
|
409
|
+
return this;
|
|
410
|
+
}
|
|
411
|
+
async get(endpoint, params = {}) {
|
|
412
|
+
try {
|
|
413
|
+
return await this.client.get(endpoint, params);
|
|
414
|
+
} catch (e) {
|
|
415
|
+
const error = e;
|
|
416
|
+
if (axios.isAxiosError(error)) {
|
|
417
|
+
if (error.code === "ECONNABORTED") throw new HttpRequestException(new Error(error.message), {
|
|
418
|
+
code: StatusCodes.REQUEST_TOO_LONG,
|
|
419
|
+
context: endpoint
|
|
420
|
+
});
|
|
421
|
+
const message = getErrorMessage(error, endpoint);
|
|
422
|
+
throw new HttpRequestException(new Error(message), {
|
|
423
|
+
context: endpoint,
|
|
424
|
+
code: error.response ? error.response.status : StatusCodes.BAD_REQUEST
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
throw new HttpRequestException(new Error(error.message), {
|
|
428
|
+
code: UnspecifiedErrorCode,
|
|
429
|
+
context: endpoint
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
async retry(httpCall, retries = 3, delay = 1e3) {
|
|
434
|
+
const retryHttpCall = async (attempt = 1) => {
|
|
435
|
+
try {
|
|
436
|
+
return await httpCall();
|
|
437
|
+
} catch (e) {
|
|
438
|
+
if (e instanceof HttpRequestException) {
|
|
439
|
+
if (e.code === StatusCodes.REQUEST_TOO_LONG) throw e;
|
|
440
|
+
}
|
|
441
|
+
if (attempt >= retries) throw e;
|
|
442
|
+
return new Promise((resolve) => setTimeout(() => resolve(retryHttpCall(attempt + 1)), delay * attempt));
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
return retryHttpCall();
|
|
446
|
+
}
|
|
447
|
+
async post(endpoint, params = {}) {
|
|
448
|
+
try {
|
|
449
|
+
return await this.client.post(endpoint, params);
|
|
450
|
+
} catch (e) {
|
|
451
|
+
const error = e;
|
|
452
|
+
if (axios.isAxiosError(error)) {
|
|
453
|
+
if (error.code === "ECONNABORTED") throw new HttpRequestException(new Error(error.message), {
|
|
454
|
+
code: StatusCodes.REQUEST_TOO_LONG,
|
|
455
|
+
method: HttpRequestMethod.Post
|
|
456
|
+
});
|
|
457
|
+
const message = getErrorMessage(error, endpoint);
|
|
458
|
+
throw new HttpRequestException(new Error(message), {
|
|
459
|
+
code: error.response ? error.response.status : StatusCodes.BAD_REQUEST,
|
|
460
|
+
context: endpoint,
|
|
461
|
+
contextModule: HttpRequestMethod.Post
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
throw new HttpRequestException(new Error(error.message), {
|
|
465
|
+
code: UnspecifiedErrorCode,
|
|
466
|
+
context: endpoint,
|
|
467
|
+
contextModule: HttpRequestMethod.Post
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
//#endregion
|
|
474
|
+
//#region src/classes/BigNumberInBase.ts
|
|
475
|
+
/**
|
|
476
|
+
* @deprecated - use toHumanReadable instead
|
|
477
|
+
*/
|
|
478
|
+
var BigNumberInBase = class BigNumberInBase extends BigNumber_default {
|
|
479
|
+
static make(number) {
|
|
480
|
+
return new BigNumberInBase(number);
|
|
481
|
+
}
|
|
482
|
+
minus(n, base) {
|
|
483
|
+
return new BigNumberInBase(super.minus(n, base));
|
|
484
|
+
}
|
|
485
|
+
plus(n, base) {
|
|
486
|
+
return new BigNumberInBase(super.plus(n, base));
|
|
487
|
+
}
|
|
488
|
+
dividedBy(n, base) {
|
|
489
|
+
return new BigNumberInBase(super.dividedBy(n, base));
|
|
490
|
+
}
|
|
491
|
+
div(n, base) {
|
|
492
|
+
return new BigNumberInBase(super.div(n, base));
|
|
493
|
+
}
|
|
494
|
+
multipliedBy(n, base) {
|
|
495
|
+
return new BigNumberInBase(super.multipliedBy(n, base));
|
|
496
|
+
}
|
|
497
|
+
times(n, base) {
|
|
498
|
+
return new BigNumberInBase(super.times(n, base));
|
|
499
|
+
}
|
|
500
|
+
pow(n, base) {
|
|
501
|
+
return new BigNumberInBase(super.pow(n, base));
|
|
502
|
+
}
|
|
503
|
+
toWei(decimals = 18) {
|
|
504
|
+
return new BigNumber_default(this).multipliedBy(new BigNumber_default(10).pow(decimals));
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
//#endregion
|
|
509
|
+
export { BigNumber_default as BigNumber, BigNumberInBase, BigNumberInWei, DEFAULT_BLOCK_TIMEOUT_HEIGHT, DEFAULT_BLOCK_TIME_IN_SECONDS, DEFAULT_BRIDGE_FEE_AMOUNT, DEFAULT_BRIDGE_FEE_DENOM, DEFAULT_BRIDGE_FEE_PRICE, DEFAULT_EXCHANGE_LIMIT, DEFAULT_FEE_DENOM, DEFAULT_GAS_LIMIT, DEFAULT_GAS_PRICE, DEFAULT_IBC_GAS_LIMIT, DEFAULT_STD_FEE_BY_DENOM, DEFAULT_TIMESTAMP_TIMEOUT_MS, DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS, HttpClient, HttpRestClient, INJECTIVE_DENOM, INJ_DENOM, LocalStorage, Status, StatusType, StreamManager, ZERO_ADDRESS, awaitAll, awaitForAll, capitalize, convertTimestampToMilliseconds, formatWalletAddress, getBigNumberWithRounding, getDefaultStdFee, getEndDateStringFromTimeInSeconds, getExactDecimalsFromNumber, getSecondsInDay, getSignificantDecimalsFromNumber, getStdFee, getStdFeeForToken, getStdFeeFromObject, getStdFeeFromString, getUTCDateFromTimestamp, past24Hours, pastDays, sleep, snakeToPascal, splitArrayToChunks, splitArrayToChunksThrow, toBigNumber, toChainFormat, toHumanReadable, toPascalCase, todayInSeconds, tomorrow };
|
package/dist/esm/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
}
|
|
2
|
+
"type": "module"
|
|
3
|
+
}
|