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