@injectivelabs/utils 1.20.15 → 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
|
@@ -1,56 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
-
__defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
1
|
+
const require_BigNumber = require('./BigNumber-DbDA4_xA.cjs');
|
|
26
2
|
|
|
27
|
-
//#endregion
|
|
28
|
-
let bignumber_js = require("bignumber.js");
|
|
29
|
-
bignumber_js = __toESM(bignumber_js);
|
|
30
|
-
|
|
31
|
-
//#region src/classes/BigNumber.ts
|
|
32
|
-
var BigNumber_default = bignumber_js.default;
|
|
33
|
-
/**
|
|
34
|
-
* Converts a value to BigNumber if it isn't already
|
|
35
|
-
*/
|
|
36
|
-
const toBigNumber = (value) => {
|
|
37
|
-
if (value instanceof bignumber_js.default) return value;
|
|
38
|
-
return new bignumber_js.default(value);
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Converts a value to Wei (multiplies by 10^decimals) default to 18 decimals
|
|
42
|
-
*/
|
|
43
|
-
const toChainFormat = (value, decimals = 18) => {
|
|
44
|
-
return toBigNumber(value).multipliedBy(new bignumber_js.default(10).pow(decimals));
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Converts a value from Wei to Base (divides by 10^decimals) default to 18 decimals
|
|
48
|
-
*/
|
|
49
|
-
const toHumanReadable = (value, decimals = 18) => {
|
|
50
|
-
return toBigNumber(value).dividedBy(new bignumber_js.default(10).pow(decimals));
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
3
|
//#region src/constants.ts
|
|
55
4
|
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
56
5
|
const INJ_DENOM = "inj";
|
|
@@ -76,7 +25,7 @@ const DEFAULT_TX_POLL_CALL_TIMEOUT_MS = 3e3;
|
|
|
76
25
|
const DEFAULT_TIMESTAMP_TIMEOUT_MS = 60 * 1e3 * 3;
|
|
77
26
|
const getDefaultStdFee = () => ({
|
|
78
27
|
amount: [{
|
|
79
|
-
amount: new BigNumber_default(DEFAULT_GAS_LIMIT).times(DEFAULT_GAS_PRICE).toString(),
|
|
28
|
+
amount: new require_BigNumber.BigNumber_default(DEFAULT_GAS_LIMIT).times(DEFAULT_GAS_PRICE).toString(),
|
|
80
29
|
denom: "inj"
|
|
81
30
|
}],
|
|
82
31
|
gas: DEFAULT_GAS_LIMIT.toString(),
|
|
@@ -87,18 +36,12 @@ const getDefaultStdFee = () => ({
|
|
|
87
36
|
const DEFAULT_STD_FEE_BY_DENOM = (denom = "inj") => ({
|
|
88
37
|
amount: [{
|
|
89
38
|
denom,
|
|
90
|
-
amount: new BigNumber_default(DEFAULT_GAS_LIMIT).times(DEFAULT_GAS_PRICE).toString()
|
|
39
|
+
amount: new require_BigNumber.BigNumber_default(DEFAULT_GAS_LIMIT).times(DEFAULT_GAS_PRICE).toString()
|
|
91
40
|
}],
|
|
92
41
|
gas: DEFAULT_GAS_LIMIT.toString()
|
|
93
42
|
});
|
|
94
43
|
|
|
95
44
|
//#endregion
|
|
96
|
-
Object.defineProperty(exports, 'BigNumber_default', {
|
|
97
|
-
enumerable: true,
|
|
98
|
-
get: function () {
|
|
99
|
-
return BigNumber_default;
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
45
|
Object.defineProperty(exports, 'DEFAULT_BLOCK_TIMEOUT_HEIGHT', {
|
|
103
46
|
enumerable: true,
|
|
104
47
|
get: function () {
|
|
@@ -207,33 +150,9 @@ Object.defineProperty(exports, 'ZERO_ADDRESS', {
|
|
|
207
150
|
return ZERO_ADDRESS;
|
|
208
151
|
}
|
|
209
152
|
});
|
|
210
|
-
Object.defineProperty(exports, '__toESM', {
|
|
211
|
-
enumerable: true,
|
|
212
|
-
get: function () {
|
|
213
|
-
return __toESM;
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
153
|
Object.defineProperty(exports, 'getDefaultStdFee', {
|
|
217
154
|
enumerable: true,
|
|
218
155
|
get: function () {
|
|
219
156
|
return getDefaultStdFee;
|
|
220
157
|
}
|
|
221
|
-
});
|
|
222
|
-
Object.defineProperty(exports, 'toBigNumber', {
|
|
223
|
-
enumerable: true,
|
|
224
|
-
get: function () {
|
|
225
|
-
return toBigNumber;
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
Object.defineProperty(exports, 'toChainFormat', {
|
|
229
|
-
enumerable: true,
|
|
230
|
-
get: function () {
|
|
231
|
-
return toChainFormat;
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
Object.defineProperty(exports, 'toHumanReadable', {
|
|
235
|
-
enumerable: true,
|
|
236
|
-
get: function () {
|
|
237
|
-
return toHumanReadable;
|
|
238
|
-
}
|
|
239
158
|
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require('./BigNumber-DbDA4_xA.cjs');
|
|
2
|
+
const require_constants = require('./constants-BdaegCnI.cjs');
|
|
3
|
+
|
|
4
|
+
exports.DEFAULT_BLOCK_TIMEOUT_HEIGHT = require_constants.DEFAULT_BLOCK_TIMEOUT_HEIGHT;
|
|
5
|
+
exports.DEFAULT_BLOCK_TIME_IN_SECONDS = require_constants.DEFAULT_BLOCK_TIME_IN_SECONDS;
|
|
6
|
+
exports.DEFAULT_BRIDGE_FEE_AMOUNT = require_constants.DEFAULT_BRIDGE_FEE_AMOUNT;
|
|
7
|
+
exports.DEFAULT_BRIDGE_FEE_DENOM = require_constants.DEFAULT_BRIDGE_FEE_DENOM;
|
|
8
|
+
exports.DEFAULT_BRIDGE_FEE_PRICE = require_constants.DEFAULT_BRIDGE_FEE_PRICE;
|
|
9
|
+
exports.DEFAULT_EXCHANGE_LIMIT = require_constants.DEFAULT_EXCHANGE_LIMIT;
|
|
10
|
+
exports.DEFAULT_FEE_DENOM = require_constants.DEFAULT_FEE_DENOM;
|
|
11
|
+
exports.DEFAULT_GAS_LIMIT = require_constants.DEFAULT_GAS_LIMIT;
|
|
12
|
+
exports.DEFAULT_GAS_PRICE = require_constants.DEFAULT_GAS_PRICE;
|
|
13
|
+
exports.DEFAULT_IBC_GAS_LIMIT = require_constants.DEFAULT_IBC_GAS_LIMIT;
|
|
14
|
+
exports.DEFAULT_STD_FEE_BY_DENOM = require_constants.DEFAULT_STD_FEE_BY_DENOM;
|
|
15
|
+
exports.DEFAULT_TIMESTAMP_TIMEOUT_MS = require_constants.DEFAULT_TIMESTAMP_TIMEOUT_MS;
|
|
16
|
+
exports.DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS = require_constants.DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS;
|
|
17
|
+
exports.DEFAULT_TX_POLL_CALL_TIMEOUT_MS = require_constants.DEFAULT_TX_POLL_CALL_TIMEOUT_MS;
|
|
18
|
+
exports.DEFAULT_TX_POLL_INTERVAL_MS = require_constants.DEFAULT_TX_POLL_INTERVAL_MS;
|
|
19
|
+
exports.INJECTIVE_DENOM = require_constants.INJECTIVE_DENOM;
|
|
20
|
+
exports.INJ_DENOM = require_constants.INJ_DENOM;
|
|
21
|
+
exports.ZERO_ADDRESS = require_constants.ZERO_ADDRESS;
|
|
22
|
+
exports.getDefaultStdFee = require_constants.getDefaultStdFee;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
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-BRub-WIk.cjs";
|
|
2
|
+
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, ZERO_ADDRESS, getDefaultStdFee };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
|
|
2
|
+
//#region \0@oxc-project+runtime@0.99.0/helpers/typeof.js
|
|
3
|
+
function _typeof(o) {
|
|
4
|
+
"@babel/helpers - typeof";
|
|
5
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
6
|
+
return typeof o$1;
|
|
7
|
+
} : function(o$1) {
|
|
8
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
9
|
+
}, _typeof(o);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region \0@oxc-project+runtime@0.99.0/helpers/toPrimitive.js
|
|
14
|
+
function toPrimitive(t, r) {
|
|
15
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
16
|
+
var e = t[Symbol.toPrimitive];
|
|
17
|
+
if (void 0 !== e) {
|
|
18
|
+
var i = e.call(t, r || "default");
|
|
19
|
+
if ("object" != _typeof(i)) return i;
|
|
20
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
21
|
+
}
|
|
22
|
+
return ("string" === r ? String : Number)(t);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region \0@oxc-project+runtime@0.99.0/helpers/toPropertyKey.js
|
|
27
|
+
function toPropertyKey(t) {
|
|
28
|
+
var i = toPrimitive(t, "string");
|
|
29
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region \0@oxc-project+runtime@0.99.0/helpers/defineProperty.js
|
|
34
|
+
function _defineProperty(e, r, t) {
|
|
35
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
36
|
+
value: t,
|
|
37
|
+
enumerable: !0,
|
|
38
|
+
configurable: !0,
|
|
39
|
+
writable: !0
|
|
40
|
+
}) : e[r] = t, e;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
Object.defineProperty(exports, '_defineProperty', {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function () {
|
|
47
|
+
return _defineProperty;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/formatters.ts
|
|
3
|
+
const formatWalletAddress = (address, substrLength = 6) => {
|
|
4
|
+
if (address.length <= 10) return address;
|
|
5
|
+
return `${address.slice(0, substrLength)}...${address.slice(address.length - substrLength, address.length)}`;
|
|
6
|
+
};
|
|
7
|
+
const toPascalCase = (str) => {
|
|
8
|
+
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());
|
|
9
|
+
};
|
|
10
|
+
const snakeToPascal = (str) => {
|
|
11
|
+
return str.split("/").map((snake) => snake.split("_").map((substr) => substr.charAt(0).toUpperCase() + substr.slice(1)).join("")).join("/");
|
|
12
|
+
};
|
|
13
|
+
const capitalize = (str) => {
|
|
14
|
+
if (!str) return str;
|
|
15
|
+
return str[0].toUpperCase() + str.slice(1);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
Object.defineProperty(exports, 'capitalize', {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return capitalize;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, 'formatWalletAddress', {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return formatWalletAddress;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, 'snakeToPascal', {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () {
|
|
34
|
+
return snakeToPascal;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, 'toPascalCase', {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return toPascalCase;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AccountAddress } from "@injectivelabs/ts-types";
|
|
2
|
+
|
|
3
|
+
//#region src/formatters.d.ts
|
|
4
|
+
declare const formatWalletAddress: (address: AccountAddress, substrLength?: number) => string;
|
|
5
|
+
declare const toPascalCase: (str: string) => string;
|
|
6
|
+
declare const snakeToPascal: (str: string) => string;
|
|
7
|
+
declare const capitalize: (str: string) => string;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { toPascalCase as i, formatWalletAddress as n, snakeToPascal as r, capitalize as t };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const require_formatters = require('./formatters-CBhRviK1.cjs');
|
|
2
|
+
|
|
3
|
+
exports.capitalize = require_formatters.capitalize;
|
|
4
|
+
exports.formatWalletAddress = require_formatters.formatWalletAddress;
|
|
5
|
+
exports.snakeToPascal = require_formatters.snakeToPascal;
|
|
6
|
+
exports.toPascalCase = require_formatters.toPascalCase;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
const require_BigNumber = require('./BigNumber-DbDA4_xA.cjs');
|
|
2
|
+
const require_constants = require('./constants-BdaegCnI.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/helpers.ts
|
|
5
|
+
const sleep = (timeout) => new Promise((resolve) => setTimeout(resolve, timeout));
|
|
6
|
+
/**
|
|
7
|
+
* When we want to execute the promises in batch
|
|
8
|
+
*/
|
|
9
|
+
const awaitAll = async (array, callback) => await Promise.all(array.map(async (item) => await callback(item)));
|
|
10
|
+
/**
|
|
11
|
+
* When we want to execute the promises one by one
|
|
12
|
+
* and not all in batch as with await Promise.all()
|
|
13
|
+
*/
|
|
14
|
+
const awaitForAll = async (array, callback, onError) => {
|
|
15
|
+
const result = [];
|
|
16
|
+
for (let i = 0; i < array.length; i += 1) try {
|
|
17
|
+
result.push(await callback(array[i]));
|
|
18
|
+
} catch (e) {
|
|
19
|
+
if (onError) onError(e, array[i], i);
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
const splitArrayToChunksThrow = ({ array, filter, chunkSize }) => {
|
|
24
|
+
const chunks = [];
|
|
25
|
+
const chunkSizeInNumber = Number(chunkSize);
|
|
26
|
+
if (!Number.isFinite(chunkSizeInNumber) || !Number.isInteger(chunkSizeInNumber) || chunkSizeInNumber <= 0) throw new Error("Invalid chunk size, must be a positive integer");
|
|
27
|
+
for (let i = 0; i < array.length; i += chunkSizeInNumber) {
|
|
28
|
+
const chunk = array.slice(i, i + chunkSizeInNumber);
|
|
29
|
+
if (filter) chunks.push(chunk.filter(filter));
|
|
30
|
+
else chunks.push(chunk);
|
|
31
|
+
}
|
|
32
|
+
return chunks;
|
|
33
|
+
};
|
|
34
|
+
const splitArrayToChunks = ({ array, filter, chunkSize }) => {
|
|
35
|
+
try {
|
|
36
|
+
return splitArrayToChunksThrow({
|
|
37
|
+
array,
|
|
38
|
+
chunkSize,
|
|
39
|
+
filter
|
|
40
|
+
});
|
|
41
|
+
} catch (_unused) {
|
|
42
|
+
return [array];
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const getStdFeeForToken = (token = {
|
|
46
|
+
denom: "inj",
|
|
47
|
+
decimals: 18
|
|
48
|
+
}, gasPrice, gasLimit) => {
|
|
49
|
+
const gasPriceScaled = require_BigNumber.toChainFormat(gasPrice || require_BigNumber.toHumanReadable(require_constants.DEFAULT_GAS_PRICE, 18), token.decimals).toFixed(0);
|
|
50
|
+
const gasNormalized = new require_BigNumber.BigNumber_default(gasLimit || require_constants.DEFAULT_GAS_LIMIT).toFixed(0);
|
|
51
|
+
return {
|
|
52
|
+
amount: [{
|
|
53
|
+
denom: token.denom,
|
|
54
|
+
amount: new require_BigNumber.BigNumber_default(gasPriceScaled).times(gasNormalized).toFixed()
|
|
55
|
+
}],
|
|
56
|
+
gas: (gasLimit || require_constants.DEFAULT_GAS_LIMIT).toString()
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
const getStdFeeFromObject = (args) => {
|
|
60
|
+
if (!args) return require_constants.getDefaultStdFee();
|
|
61
|
+
const { payer, granter, feePayer, gasPrice = require_constants.DEFAULT_GAS_PRICE, gas = require_constants.DEFAULT_GAS_LIMIT.toString() } = args;
|
|
62
|
+
const gasNormalized = require_BigNumber.toBigNumber(gas).toFixed(0);
|
|
63
|
+
const gasPriceNormalized = require_BigNumber.toBigNumber(gasPrice).toFixed(0);
|
|
64
|
+
return {
|
|
65
|
+
amount: [{
|
|
66
|
+
denom: "inj",
|
|
67
|
+
amount: require_BigNumber.toBigNumber(gasNormalized).times(gasPriceNormalized).toFixed()
|
|
68
|
+
}],
|
|
69
|
+
gas: require_BigNumber.toBigNumber(gasNormalized).toFixed(),
|
|
70
|
+
payer,
|
|
71
|
+
granter,
|
|
72
|
+
feePayer
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
const getStdFeeFromString = (gasPrice) => {
|
|
76
|
+
const matchResult = gasPrice.match(/^([0-9.]+)([a-zA-Z][a-zA-Z0-9/:._-]*)$/);
|
|
77
|
+
if (!matchResult) throw new Error("Invalid gas price string");
|
|
78
|
+
const [_, amount] = matchResult;
|
|
79
|
+
return getStdFeeFromObject({
|
|
80
|
+
gas: require_BigNumber.toChainFormat(amount, 18).dividedBy(require_constants.DEFAULT_GAS_PRICE).toFixed(0),
|
|
81
|
+
gasPrice: require_constants.DEFAULT_GAS_PRICE
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
const getStdFee = (args) => {
|
|
85
|
+
if (!args) return require_constants.getDefaultStdFee();
|
|
86
|
+
if (typeof args === "string") return getStdFeeFromString(args);
|
|
87
|
+
return getStdFeeFromObject({ ...args });
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
Object.defineProperty(exports, 'awaitAll', {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: function () {
|
|
94
|
+
return awaitAll;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(exports, 'awaitForAll', {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: function () {
|
|
100
|
+
return awaitForAll;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(exports, 'getStdFee', {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: function () {
|
|
106
|
+
return getStdFee;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(exports, 'getStdFeeForToken', {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () {
|
|
112
|
+
return getStdFeeForToken;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(exports, 'getStdFeeFromObject', {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
get: function () {
|
|
118
|
+
return getStdFeeFromObject;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
Object.defineProperty(exports, 'getStdFeeFromString', {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
get: function () {
|
|
124
|
+
return getStdFeeFromString;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
Object.defineProperty(exports, 'sleep', {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
get: function () {
|
|
130
|
+
return sleep;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
Object.defineProperty(exports, 'splitArrayToChunks', {
|
|
134
|
+
enumerable: true,
|
|
135
|
+
get: function () {
|
|
136
|
+
return splitArrayToChunks;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
Object.defineProperty(exports, 'splitArrayToChunksThrow', {
|
|
140
|
+
enumerable: true,
|
|
141
|
+
get: function () {
|
|
142
|
+
return splitArrayToChunksThrow;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type Awaited<T> = T extends null | undefined ? T : T extends object & {
|
|
3
|
+
then(onfulfilled: infer F, ...args: infer _): any;
|
|
4
|
+
} ? F extends ((value: infer V, ...args: infer _) => any) ? Awaited<V> : never : T;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/helpers.d.ts
|
|
7
|
+
declare const sleep: (timeout: number) => Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* When we want to execute the promises in batch
|
|
10
|
+
*/
|
|
11
|
+
declare const awaitAll: <T, S>(array: Array<T>, callback: (item: T) => Promise<S>) => Promise<Awaited<S>[]>;
|
|
12
|
+
/**
|
|
13
|
+
* When we want to execute the promises one by one
|
|
14
|
+
* and not all in batch as with await Promise.all()
|
|
15
|
+
*/
|
|
16
|
+
declare const awaitForAll: <T, S>(array: Array<T>, callback: (item: T) => Promise<S>, onError?: (error: unknown, item: T, index: number) => void) => Promise<S[]>;
|
|
17
|
+
declare const splitArrayToChunksThrow: <T>({
|
|
18
|
+
array,
|
|
19
|
+
filter,
|
|
20
|
+
chunkSize
|
|
21
|
+
}: {
|
|
22
|
+
array: Array<T>;
|
|
23
|
+
chunkSize: number;
|
|
24
|
+
filter?: (item: T) => boolean;
|
|
25
|
+
}) => T[][];
|
|
26
|
+
declare const splitArrayToChunks: <T>({
|
|
27
|
+
array,
|
|
28
|
+
filter,
|
|
29
|
+
chunkSize
|
|
30
|
+
}: {
|
|
31
|
+
array: Array<T>;
|
|
32
|
+
chunkSize: number;
|
|
33
|
+
filter?: (item: T) => boolean;
|
|
34
|
+
}) => T[][];
|
|
35
|
+
declare const getStdFeeForToken: (token?: {
|
|
36
|
+
denom: string;
|
|
37
|
+
decimals: number;
|
|
38
|
+
}, gasPrice?: string, gasLimit?: string) => {
|
|
39
|
+
amount: {
|
|
40
|
+
denom: string;
|
|
41
|
+
amount: string;
|
|
42
|
+
}[];
|
|
43
|
+
gas: string;
|
|
44
|
+
};
|
|
45
|
+
declare const getStdFeeFromObject: (args?: {
|
|
46
|
+
gas?: string | number;
|
|
47
|
+
payer?: string;
|
|
48
|
+
granter?: string;
|
|
49
|
+
gasPrice?: string | number;
|
|
50
|
+
feePayer?: string;
|
|
51
|
+
}) => {
|
|
52
|
+
amount: {
|
|
53
|
+
denom: string;
|
|
54
|
+
amount: string;
|
|
55
|
+
}[];
|
|
56
|
+
gas: string;
|
|
57
|
+
payer: string | undefined; /** for Web3Gateway fee delegation */
|
|
58
|
+
granter: string | undefined;
|
|
59
|
+
feePayer: string | undefined;
|
|
60
|
+
};
|
|
61
|
+
declare const getStdFeeFromString: (gasPrice: string) => {
|
|
62
|
+
amount: {
|
|
63
|
+
denom: string;
|
|
64
|
+
amount: string;
|
|
65
|
+
}[];
|
|
66
|
+
gas: string;
|
|
67
|
+
payer: string | undefined; /** for Web3Gateway fee delegation */
|
|
68
|
+
granter: string | undefined;
|
|
69
|
+
feePayer: string | undefined;
|
|
70
|
+
};
|
|
71
|
+
declare const getStdFee: (args?: string | {
|
|
72
|
+
payer?: string;
|
|
73
|
+
granter?: string;
|
|
74
|
+
feePayer?: string;
|
|
75
|
+
gas?: string | number;
|
|
76
|
+
gasPrice?: string | number;
|
|
77
|
+
}) => {
|
|
78
|
+
amount: {
|
|
79
|
+
denom: string;
|
|
80
|
+
amount: string;
|
|
81
|
+
}[];
|
|
82
|
+
gas: string;
|
|
83
|
+
payer: string | undefined; /** for Web3Gateway fee delegation */
|
|
84
|
+
granter: string | undefined;
|
|
85
|
+
feePayer: string | undefined;
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
export { getStdFeeFromObject as a, splitArrayToChunks as c, getStdFeeForToken as i, splitArrayToChunksThrow as l, awaitForAll as n, getStdFeeFromString as o, getStdFee as r, sleep as s, awaitAll as t };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require('./BigNumber-DbDA4_xA.cjs');
|
|
2
|
+
require('./constants-BdaegCnI.cjs');
|
|
3
|
+
const require_helpers = require('./helpers-BW4oKV4e.cjs');
|
|
4
|
+
|
|
5
|
+
exports.awaitAll = require_helpers.awaitAll;
|
|
6
|
+
exports.awaitForAll = require_helpers.awaitForAll;
|
|
7
|
+
exports.getStdFee = require_helpers.getStdFee;
|
|
8
|
+
exports.getStdFeeForToken = require_helpers.getStdFeeForToken;
|
|
9
|
+
exports.getStdFeeFromObject = require_helpers.getStdFeeFromObject;
|
|
10
|
+
exports.getStdFeeFromString = require_helpers.getStdFeeFromString;
|
|
11
|
+
exports.sleep = require_helpers.sleep;
|
|
12
|
+
exports.splitArrayToChunks = require_helpers.splitArrayToChunks;
|
|
13
|
+
exports.splitArrayToChunksThrow = require_helpers.splitArrayToChunksThrow;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
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-BmH3TkaY.cjs";
|
|
2
|
+
export { awaitAll, awaitForAll, getStdFee, getStdFeeForToken, getStdFeeFromObject, getStdFeeFromString, sleep, splitArrayToChunks, splitArrayToChunksThrow };
|