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