@hyperlane-xyz/utils 3.10.1-beta1 → 3.20.0-beta0
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/addresses.d.ts +1 -1
- package/dist/addresses.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -1
- package/dist/types.js.map +1 -1
- package/dist/url.d.ts +2 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.js +10 -0
- package/dist/url.js.map +1 -0
- package/package.json +2 -2
- package/dist/src/addresses.d.ts +0 -42
- package/dist/src/addresses.d.ts.map +0 -1
- package/dist/src/addresses.js +0 -335
- package/dist/src/addresses.js.map +0 -1
- package/dist/src/addresses.test.d.ts +0 -2
- package/dist/src/addresses.test.d.ts.map +0 -1
- package/dist/src/addresses.test.js +0 -46
- package/dist/src/addresses.test.js.map +0 -1
- package/dist/src/amount.d.ts +0 -45
- package/dist/src/amount.d.ts.map +0 -1
- package/dist/src/amount.js +0 -126
- package/dist/src/amount.js.map +0 -1
- package/dist/src/amount.test.d.ts +0 -2
- package/dist/src/amount.test.d.ts.map +0 -1
- package/dist/src/amount.test.js +0 -48
- package/dist/src/amount.test.js.map +0 -1
- package/dist/src/arrays.d.ts +0 -8
- package/dist/src/arrays.d.ts.map +0 -1
- package/dist/src/arrays.js +0 -16
- package/dist/src/arrays.js.map +0 -1
- package/dist/src/async.d.ts +0 -47
- package/dist/src/async.d.ts.map +0 -1
- package/dist/src/async.js +0 -101
- package/dist/src/async.js.map +0 -1
- package/dist/src/base58.d.ts +0 -5
- package/dist/src/base58.d.ts.map +0 -1
- package/dist/src/base58.js +0 -21
- package/dist/src/base58.js.map +0 -1
- package/dist/src/base64.d.ts +0 -3
- package/dist/src/base64.d.ts.map +0 -1
- package/dist/src/base64.js +0 -30
- package/dist/src/base64.js.map +0 -1
- package/dist/src/big-numbers.d.ts +0 -50
- package/dist/src/big-numbers.d.ts.map +0 -1
- package/dist/src/big-numbers.js +0 -93
- package/dist/src/big-numbers.js.map +0 -1
- package/dist/src/big-numbers.test.d.ts +0 -2
- package/dist/src/big-numbers.test.d.ts.map +0 -1
- package/dist/src/big-numbers.test.js +0 -101
- package/dist/src/big-numbers.test.js.map +0 -1
- package/dist/src/calldata.d.ts +0 -3
- package/dist/src/calldata.d.ts.map +0 -1
- package/dist/src/calldata.js +0 -8
- package/dist/src/calldata.js.map +0 -1
- package/dist/src/checkpoints.d.ts +0 -5
- package/dist/src/checkpoints.d.ts.map +0 -1
- package/dist/src/checkpoints.js +0 -30
- package/dist/src/checkpoints.js.map +0 -1
- package/dist/src/domains.d.ts +0 -2
- package/dist/src/domains.d.ts.map +0 -1
- package/dist/src/domains.js +0 -10
- package/dist/src/domains.js.map +0 -1
- package/dist/src/env.d.ts +0 -2
- package/dist/src/env.d.ts.map +0 -1
- package/dist/src/env.js +0 -15
- package/dist/src/env.js.map +0 -1
- package/dist/src/ids.d.ts +0 -20
- package/dist/src/ids.d.ts.map +0 -1
- package/dist/src/ids.js +0 -47
- package/dist/src/ids.js.map +0 -1
- package/dist/src/logging.d.ts +0 -20
- package/dist/src/logging.d.ts.map +0 -1
- package/dist/src/logging.js +0 -89
- package/dist/src/logging.js.map +0 -1
- package/dist/src/math.d.ts +0 -5
- package/dist/src/math.d.ts.map +0 -1
- package/dist/src/math.js +0 -25
- package/dist/src/math.js.map +0 -1
- package/dist/src/messages.d.ts +0 -21
- package/dist/src/messages.d.ts.map +0 -1
- package/dist/src/messages.js +0 -58
- package/dist/src/messages.js.map +0 -1
- package/dist/src/multisig.d.ts +0 -4
- package/dist/src/multisig.d.ts.map +0 -1
- package/dist/src/multisig.js +0 -61
- package/dist/src/multisig.js.map +0 -1
- package/dist/src/objects.d.ts +0 -16
- package/dist/src/objects.d.ts.map +0 -1
- package/dist/src/objects.js +0 -93
- package/dist/src/objects.js.map +0 -1
- package/dist/src/sets.d.ts +0 -4
- package/dist/src/sets.d.ts.map +0 -1
- package/dist/src/sets.js +0 -30
- package/dist/src/sets.js.map +0 -1
- package/dist/src/strings.d.ts +0 -7
- package/dist/src/strings.d.ts.map +0 -1
- package/dist/src/strings.js +0 -51
- package/dist/src/strings.js.map +0 -1
- package/dist/src/typeof.d.ts +0 -3
- package/dist/src/typeof.d.ts.map +0 -1
- package/dist/src/typeof.js +0 -12
- package/dist/src/typeof.js.map +0 -1
- package/dist/src/types.d.ts +0 -84
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -25
- package/dist/src/types.js.map +0 -1
- package/dist/src/validation.d.ts +0 -2
- package/dist/src/validation.d.ts.map +0 -1
- package/dist/src/validation.js +0 -10
- package/dist/src/validation.js.map +0 -1
- package/dist/src/validator.d.ts +0 -17
- package/dist/src/validator.d.ts.map +0 -1
- package/dist/src/validator.js +0 -44
- package/dist/src/validator.js.map +0 -1
package/dist/src/amount.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
|
-
/**
|
|
3
|
-
* Convert the given Wei value to Ether value
|
|
4
|
-
* @param value The value to convert.
|
|
5
|
-
* @returns Converted value in string type.
|
|
6
|
-
*/
|
|
7
|
-
export declare function fromWei(value: BigNumber.Value | null | undefined, decimals?: number): string;
|
|
8
|
-
/**
|
|
9
|
-
* Convert the given Wei value to Ether value,
|
|
10
|
-
* round to set number of decimals with a minimum floor, configured per token
|
|
11
|
-
* @param value The value to convert.
|
|
12
|
-
* @param decimals
|
|
13
|
-
* @returns Converted value in string type.
|
|
14
|
-
*/
|
|
15
|
-
export declare function fromWeiRounded(value: BigNumber.Value | null | undefined, decimals?: number, displayDecimals?: number): string;
|
|
16
|
-
/**
|
|
17
|
-
* Convert the given value to Wei value
|
|
18
|
-
* @param value The value to convert.
|
|
19
|
-
* @returns Converted value in string type.
|
|
20
|
-
*/
|
|
21
|
-
export declare function toWei(value: BigNumber.Value | null | undefined, decimals?: number): string;
|
|
22
|
-
/**
|
|
23
|
-
* Try to parse the given value into BigNumber.js BigNumber
|
|
24
|
-
* @param value The value to parse.
|
|
25
|
-
* @returns Parsed value in BigNumber.js BigNumber type.
|
|
26
|
-
*/
|
|
27
|
-
export declare function tryParseAmount(value: BigNumber.Value | null | undefined): BigNumber | null;
|
|
28
|
-
/**
|
|
29
|
-
* Checks if an amount is equal of nearly equal to balance within a small margin of error
|
|
30
|
-
* Necessary because amounts in the UI are often rounded
|
|
31
|
-
* @param amount1 The amount to compare.
|
|
32
|
-
* @param amount2 The amount to compare.
|
|
33
|
-
* @returns true/false.
|
|
34
|
-
*/
|
|
35
|
-
export declare function eqAmountApproximate(amount1: BigNumber.Value, amount2: BigNumber.Value, maxDifference: BigNumber.Value): boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Converts a value with `fromDecimals` decimals to a value with `toDecimals` decimals.
|
|
38
|
-
* Incurs a loss of precision when `fromDecimals` > `toDecimals`.
|
|
39
|
-
* @param fromDecimals The number of decimals `value` has.
|
|
40
|
-
* @param toDecimals The number of decimals to convert `value` to.
|
|
41
|
-
* @param value The value to convert.
|
|
42
|
-
* @returns `value` represented with `toDecimals` decimals in string type.
|
|
43
|
-
*/
|
|
44
|
-
export declare function convertDecimals(fromDecimals: number, toDecimals: number, value: BigNumber.Value): string;
|
|
45
|
-
//# sourceMappingURL=amount.d.ts.map
|
package/dist/src/amount.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../../src/amount.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,cAAc,CAAC;AAKrC;;;;GAIG;AACH,wBAAgB,OAAO,CACrB,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,IAAI,GAAG,SAAS,EACzC,QAAQ,SAAyB,GAChC,MAAM,CAKR;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,IAAI,GAAG,SAAS,EACzC,QAAQ,SAAyB,EACjC,eAAe,CAAC,EAAE,MAAM,GACvB,MAAM,CAOR;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CACnB,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,IAAI,GAAG,SAAS,EACzC,QAAQ,SAAyB,GAChC,MAAM,CAmBR;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,IAAI,GAAG,SAAS,GACxC,SAAS,GAAG,IAAI,CASlB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,SAAS,CAAC,KAAK,EACxB,OAAO,EAAE,SAAS,CAAC,KAAK,EACxB,aAAa,EAAE,SAAS,CAAC,KAAK,GAC7B,OAAO,CAGT;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,SAAS,CAAC,KAAK,GACrB,MAAM,CAgBR"}
|
package/dist/src/amount.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.convertDecimals = exports.eqAmountApproximate = exports.tryParseAmount = exports.toWei = exports.fromWeiRounded = exports.fromWei = void 0;
|
|
7
|
-
const units_1 = require("@ethersproject/units");
|
|
8
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
|
-
const DEFAULT_DISPLAY_DECIMALS = 4;
|
|
10
|
-
const DEFAULT_TOKEN_DECIMALS = 18;
|
|
11
|
-
/**
|
|
12
|
-
* Convert the given Wei value to Ether value
|
|
13
|
-
* @param value The value to convert.
|
|
14
|
-
* @returns Converted value in string type.
|
|
15
|
-
*/
|
|
16
|
-
function fromWei(value, decimals = DEFAULT_TOKEN_DECIMALS) {
|
|
17
|
-
if (!value)
|
|
18
|
-
return (0).toString();
|
|
19
|
-
const valueString = value.toString(10).trim();
|
|
20
|
-
const flooredValue = (0, bignumber_js_1.default)(valueString).toFixed(0, bignumber_js_1.default.ROUND_FLOOR);
|
|
21
|
-
return parseFloat((0, units_1.formatUnits)(flooredValue, decimals)).toString();
|
|
22
|
-
}
|
|
23
|
-
exports.fromWei = fromWei;
|
|
24
|
-
/**
|
|
25
|
-
* Convert the given Wei value to Ether value,
|
|
26
|
-
* round to set number of decimals with a minimum floor, configured per token
|
|
27
|
-
* @param value The value to convert.
|
|
28
|
-
* @param decimals
|
|
29
|
-
* @returns Converted value in string type.
|
|
30
|
-
*/
|
|
31
|
-
function fromWeiRounded(value, decimals = DEFAULT_TOKEN_DECIMALS, displayDecimals) {
|
|
32
|
-
if (!value)
|
|
33
|
-
return '0';
|
|
34
|
-
const flooredValue = (0, bignumber_js_1.default)(value).toFixed(0, bignumber_js_1.default.ROUND_FLOOR);
|
|
35
|
-
const amount = (0, bignumber_js_1.default)((0, units_1.formatUnits)(flooredValue, decimals));
|
|
36
|
-
if (amount.isZero())
|
|
37
|
-
return '0';
|
|
38
|
-
displayDecimals ?? (displayDecimals = amount.gte(10000) ? 2 : DEFAULT_DISPLAY_DECIMALS);
|
|
39
|
-
return amount.toFixed(displayDecimals, bignumber_js_1.default.ROUND_FLOOR);
|
|
40
|
-
}
|
|
41
|
-
exports.fromWeiRounded = fromWeiRounded;
|
|
42
|
-
/**
|
|
43
|
-
* Convert the given value to Wei value
|
|
44
|
-
* @param value The value to convert.
|
|
45
|
-
* @returns Converted value in string type.
|
|
46
|
-
*/
|
|
47
|
-
function toWei(value, decimals = DEFAULT_TOKEN_DECIMALS) {
|
|
48
|
-
if (!value)
|
|
49
|
-
return (0, bignumber_js_1.default)(0).toString();
|
|
50
|
-
// First convert to a BigNumber, and then call `toString` with the
|
|
51
|
-
// explicit radix 10 such that the result is formatted as a base-10 string
|
|
52
|
-
// and not in scientific notation.
|
|
53
|
-
const valueBN = (0, bignumber_js_1.default)(value);
|
|
54
|
-
const valueString = valueBN.toString(10).trim();
|
|
55
|
-
const components = valueString.split('.');
|
|
56
|
-
if (components.length === 1) {
|
|
57
|
-
return (0, units_1.parseUnits)(valueString, decimals).toString();
|
|
58
|
-
}
|
|
59
|
-
else if (components.length === 2) {
|
|
60
|
-
const trimmedFraction = components[1].substring(0, decimals);
|
|
61
|
-
return (0, units_1.parseUnits)(`${components[0]}.${trimmedFraction}`, decimals).toString();
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
throw new Error(`Cannot convert ${valueString} to wei`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
exports.toWei = toWei;
|
|
68
|
-
/**
|
|
69
|
-
* Try to parse the given value into BigNumber.js BigNumber
|
|
70
|
-
* @param value The value to parse.
|
|
71
|
-
* @returns Parsed value in BigNumber.js BigNumber type.
|
|
72
|
-
*/
|
|
73
|
-
function tryParseAmount(value) {
|
|
74
|
-
try {
|
|
75
|
-
if (!value)
|
|
76
|
-
return null;
|
|
77
|
-
const parsed = (0, bignumber_js_1.default)(value);
|
|
78
|
-
if (!parsed || parsed.isNaN() || !parsed.isFinite())
|
|
79
|
-
return null;
|
|
80
|
-
else
|
|
81
|
-
return parsed;
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.tryParseAmount = tryParseAmount;
|
|
88
|
-
/**
|
|
89
|
-
* Checks if an amount is equal of nearly equal to balance within a small margin of error
|
|
90
|
-
* Necessary because amounts in the UI are often rounded
|
|
91
|
-
* @param amount1 The amount to compare.
|
|
92
|
-
* @param amount2 The amount to compare.
|
|
93
|
-
* @returns true/false.
|
|
94
|
-
*/
|
|
95
|
-
function eqAmountApproximate(amount1, amount2, maxDifference) {
|
|
96
|
-
// Is difference btwn amounts less than maxDifference
|
|
97
|
-
return (0, bignumber_js_1.default)(amount1).minus(amount2).abs().lte(maxDifference);
|
|
98
|
-
}
|
|
99
|
-
exports.eqAmountApproximate = eqAmountApproximate;
|
|
100
|
-
/**
|
|
101
|
-
* Converts a value with `fromDecimals` decimals to a value with `toDecimals` decimals.
|
|
102
|
-
* Incurs a loss of precision when `fromDecimals` > `toDecimals`.
|
|
103
|
-
* @param fromDecimals The number of decimals `value` has.
|
|
104
|
-
* @param toDecimals The number of decimals to convert `value` to.
|
|
105
|
-
* @param value The value to convert.
|
|
106
|
-
* @returns `value` represented with `toDecimals` decimals in string type.
|
|
107
|
-
*/
|
|
108
|
-
function convertDecimals(fromDecimals, toDecimals, value) {
|
|
109
|
-
const amount = (0, bignumber_js_1.default)(value);
|
|
110
|
-
if (fromDecimals === toDecimals)
|
|
111
|
-
return amount.toString(10);
|
|
112
|
-
else if (fromDecimals > toDecimals) {
|
|
113
|
-
const difference = fromDecimals - toDecimals;
|
|
114
|
-
return amount
|
|
115
|
-
.div((0, bignumber_js_1.default)(10).pow(difference))
|
|
116
|
-
.integerValue(bignumber_js_1.default.ROUND_FLOOR)
|
|
117
|
-
.toString(10);
|
|
118
|
-
}
|
|
119
|
-
// fromDecimals < toDecimals
|
|
120
|
-
else {
|
|
121
|
-
const difference = toDecimals - fromDecimals;
|
|
122
|
-
return amount.times((0, bignumber_js_1.default)(10).pow(difference)).toString(10);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
exports.convertDecimals = convertDecimals;
|
|
126
|
-
//# sourceMappingURL=amount.js.map
|
package/dist/src/amount.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../src/amount.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA+D;AAC/D,gEAAqC;AAErC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AACnC,MAA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H,CAAC;AAXD,wCAWC;AAED;;;;;;GAMG;AACH,SAAgB,mBAAmB,CACjC,OAAwB,EACxB,OAAwB,EACxB,aAA8B;IAE9B,qDAAqD;IACrD,OAAO,IAAA,sBAAS,EAAC,OAAO,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;AACpE,CAAC;AAPD,kDAOC;AAED;;;;;;;GAOG;AACH,SAAgB,eAAe,CAC7B,YAAoB,EACpB,UAAkB,EAClB,KAAsB;IAEtB,MAAM,MAAM,GAAG,IAAA,sBAAS,EAAC,KAAK,CAAC,CAAC;IAEhC,IAAI,YAAY,KAAK,UAAU;QAAE,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;SACvD,IAAI,YAAY,GAAG,UAAU,EAAE;QAClC,MAAM,UAAU,GAAG,YAAY,GAAG,UAAU,CAAC;QAC7C,OAAO,MAAM;aACV,GAAG,CAAC,IAAA,sBAAS,EAAC,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;aAClC,YAAY,CAAC,sBAAS,CAAC,WAAW,CAAC;aACnC,QAAQ,CAAC,EAAE,CAAC,CAAC;KACjB;IACD,4BAA4B;SACvB;QACH,MAAM,UAAU,GAAG,UAAU,GAAG,YAAY,CAAC;QAC7C,OAAO,MAAM,CAAC,KAAK,CAAC,IAAA,sBAAS,EAAC,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;KACjE;AACH,CAAC;AApBD,0CAoBC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"amount.test.d.ts","sourceRoot":"","sources":["../../src/amount.test.ts"],"names":[],"mappings":""}
|
package/dist/src/amount.test.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const chai_1 = require("chai");
|
|
4
|
-
const amount_1 = require("./amount");
|
|
5
|
-
describe('fromWei', () => {
|
|
6
|
-
it('parses and converts correctly', () => {
|
|
7
|
-
(0, chai_1.expect)((0, amount_1.fromWei)(1, 0)).to.equal('1');
|
|
8
|
-
(0, chai_1.expect)((0, amount_1.fromWei)('1000000', 6)).to.equal('1');
|
|
9
|
-
(0, chai_1.expect)((0, amount_1.fromWei)('1000000000000000000')).to.equal('1');
|
|
10
|
-
(0, chai_1.expect)((0, amount_1.fromWei)('1000000000000000000.1234')).to.equal('1');
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
describe('fromWeiRounded', () => {
|
|
14
|
-
it('parses and converts correctly', () => {
|
|
15
|
-
(0, chai_1.expect)((0, amount_1.fromWeiRounded)(1, 0)).to.equal('1.0000');
|
|
16
|
-
(0, chai_1.expect)((0, amount_1.fromWeiRounded)('1000000', 6)).to.equal('1.0000');
|
|
17
|
-
(0, chai_1.expect)((0, amount_1.fromWeiRounded)('1000000000000000000')).to.equal('1.0000');
|
|
18
|
-
(0, chai_1.expect)((0, amount_1.fromWeiRounded)('1000000000000000000.1234')).to.equal('1.0000');
|
|
19
|
-
});
|
|
20
|
-
it('rounds correctly', () => {
|
|
21
|
-
(0, chai_1.expect)((0, amount_1.fromWeiRounded)(1234567890, 6, 2)).to.equal('1234.56');
|
|
22
|
-
(0, chai_1.expect)((0, amount_1.fromWeiRounded)('1234567890', 6, 4)).to.equal('1234.5678');
|
|
23
|
-
(0, chai_1.expect)((0, amount_1.fromWeiRounded)('10000000000000000000')).to.equal('10.0000');
|
|
24
|
-
(0, chai_1.expect)((0, amount_1.fromWeiRounded)('10000000000000000000', 18, 0)).to.equal('10');
|
|
25
|
-
});
|
|
26
|
-
it('can drop decimals for large numbers', () => {
|
|
27
|
-
(0, chai_1.expect)((0, amount_1.fromWeiRounded)('10001000000000000000000')).to.equal('10001.00');
|
|
28
|
-
(0, chai_1.expect)((0, amount_1.fromWeiRounded)('10001000000000000000', 15, 4)).to.equal('10001.0000');
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
describe('toWei', () => {
|
|
32
|
-
it('parses and converts correctly', () => {
|
|
33
|
-
(0, chai_1.expect)((0, amount_1.toWei)(1, 0)).to.equal('1');
|
|
34
|
-
(0, chai_1.expect)((0, amount_1.toWei)('1', 6)).to.equal('1000000');
|
|
35
|
-
(0, chai_1.expect)((0, amount_1.toWei)('123.456')).to.equal('123456000000000000000');
|
|
36
|
-
(0, chai_1.expect)((0, amount_1.toWei)('1.00000000000000000001')).to.equal('1000000000000000000');
|
|
37
|
-
(0, chai_1.expect)((0, amount_1.toWei)('1.00000000000000000001', 6)).to.equal('1000000');
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
describe('eqAmountApproximate', () => {
|
|
41
|
-
it('compares correctly', () => {
|
|
42
|
-
(0, chai_1.expect)((0, amount_1.eqAmountApproximate)(1, 1.001, 0.001)).to.be.true;
|
|
43
|
-
(0, chai_1.expect)((0, amount_1.eqAmountApproximate)(9, 9.001, 0.01)).to.be.true;
|
|
44
|
-
(0, chai_1.expect)((0, amount_1.eqAmountApproximate)('9876543210', '9876543210', '1')).to.be.true;
|
|
45
|
-
(0, chai_1.expect)((0, amount_1.eqAmountApproximate)('9876543210', '9876543212', '1')).to.be.false;
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
//# sourceMappingURL=amount.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"amount.test.js","sourceRoot":"","sources":["../../src/amount.test.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAE9B,qCAA+E;AAE/E,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACvC,IAAA,aAAM,EAAC,IAAA,gBAAO,EAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;Q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xE,IAAA,aAAM,EAAC,IAAA,cAAK,EAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,EAAE,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAC5B,IAAA,aAAM,EAAC,IAAA,4BAAmB,EAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;QACxD,IAAA,aAAM,EAAC,IAAA,4BAAmB,EAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;QACvD,IAAA,aAAM,EAAC,IAAA,4BAAmB,EAAC,YAAY,EAAE,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;QACxE,IAAA,aAAM,EAAC,IAAA,4BAAmB,EAAC,YAAY,EAAE,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;IAC3E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/src/arrays.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
interface Sliceable {
|
|
2
|
-
length: number;
|
|
3
|
-
slice: (i: number, j: number) => any;
|
|
4
|
-
}
|
|
5
|
-
export declare function chunk<T extends Sliceable>(str: T, size: number): T[];
|
|
6
|
-
export declare function exclude<T>(item: T, list: T[]): T[];
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=arrays.d.ts.map
|
package/dist/src/arrays.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"arrays.d.ts","sourceRoot":"","sources":["../../src/arrays.ts"],"names":[],"mappings":"AAAA,UAAU,SAAS;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,GAAG,CAAC;CACtC;AAED,wBAAgB,KAAK,CAAC,CAAC,SAAS,SAAS,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,OAM9D;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,OAE5C"}
|
package/dist/src/arrays.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.exclude = exports.chunk = void 0;
|
|
4
|
-
function chunk(str, size) {
|
|
5
|
-
const R = [];
|
|
6
|
-
for (let i = 0; i < str.length; i += size) {
|
|
7
|
-
R.push(str.slice(i, i + size));
|
|
8
|
-
}
|
|
9
|
-
return R;
|
|
10
|
-
}
|
|
11
|
-
exports.chunk = chunk;
|
|
12
|
-
function exclude(item, list) {
|
|
13
|
-
return list.filter((i) => i !== item);
|
|
14
|
-
}
|
|
15
|
-
exports.exclude = exclude;
|
|
16
|
-
//# sourceMappingURL=arrays.js.map
|
package/dist/src/arrays.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"arrays.js","sourceRoot":"","sources":["../../src/arrays.ts"],"names":[],"mappings":";;;AAKA,SAAgB,KAAK,CAAsB,GAAM,EAAE,IAAY;IAC7D,MAAM,CAAC,GAAa,EAAE,CAAC;IACvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,IAAI,EAAE;QACzC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;KAChC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAND,sBAMC;AAED,SAAgB,OAAO,CAAI,IAAO,EAAE,IAAS;IAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;AACxC,CAAC;AAFD,0BAEC"}
|
package/dist/src/async.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Return a promise that resolves in ms milliseconds.
|
|
3
|
-
* @param ms Time to wait
|
|
4
|
-
*/
|
|
5
|
-
export declare function sleep(ms: number): Promise<void>;
|
|
6
|
-
/**
|
|
7
|
-
* Wait up to a given amount of time, and throw an error if the promise does not resolve in time.
|
|
8
|
-
* @param promise The promise to timeout on.
|
|
9
|
-
* @param timeoutMs How long to wait for the promise in milliseconds.
|
|
10
|
-
* @param message The error message if a timeout occurs.
|
|
11
|
-
*/
|
|
12
|
-
export declare function timeout<T>(promise: Promise<T>, timeoutMs?: number, message?: string): Promise<T>;
|
|
13
|
-
/**
|
|
14
|
-
* Run a callback with a timeout.
|
|
15
|
-
* @param timeoutMs How long to wait for the promise in milliseconds.
|
|
16
|
-
* @param callback The callback to run.
|
|
17
|
-
* @returns callback return value
|
|
18
|
-
*/
|
|
19
|
-
export declare function runWithTimeout<T>(timeoutMs: number, callback: () => Promise<T>): Promise<T | void>;
|
|
20
|
-
/**
|
|
21
|
-
* Retries an async function if it raises an exception,
|
|
22
|
-
* using exponential backoff.
|
|
23
|
-
* @param runner callback to run
|
|
24
|
-
* @param attempts max number of attempts
|
|
25
|
-
* @param baseRetryMs base delay between attempts
|
|
26
|
-
* @returns runner return value
|
|
27
|
-
*/
|
|
28
|
-
export declare function retryAsync<T>(runner: () => T, attempts?: number, baseRetryMs?: number): Promise<T>;
|
|
29
|
-
/**
|
|
30
|
-
* Run a callback with a timeout, and retry if the callback throws an error.
|
|
31
|
-
* @param runner callback to run
|
|
32
|
-
* @param delayMs base delay between attempts
|
|
33
|
-
* @param maxAttempts maximum number of attempts
|
|
34
|
-
* @returns runner return value
|
|
35
|
-
*/
|
|
36
|
-
export declare function pollAsync<T>(runner: () => Promise<T>, delayMs?: number, maxAttempts?: number | undefined): Promise<T>;
|
|
37
|
-
/**
|
|
38
|
-
* An enhanced Promise.race that returns
|
|
39
|
-
* objects with the promise itself and index
|
|
40
|
-
* instead of just the resolved value.
|
|
41
|
-
*/
|
|
42
|
-
export declare function raceWithContext<T>(promises: Array<Promise<T>>): Promise<{
|
|
43
|
-
resolved: T;
|
|
44
|
-
promise: Promise<T>;
|
|
45
|
-
index: number;
|
|
46
|
-
}>;
|
|
47
|
-
//# sourceMappingURL=async.d.ts.map
|
package/dist/src/async.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../src/async.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACvB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,SAAoB,GAC1B,OAAO,CAAC,CAAC,CAAC,CAQZ;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,CAAC,EACpC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACzB,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAanB;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,MAAM,EAAE,MAAM,CAAC,EACf,QAAQ,SAAI,EACZ,WAAW,SAAK,cAajB;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACxB,OAAO,SAAM,EACb,WAAW,GAAE,MAAM,GAAG,SAAqB,cAe5C;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,CAAC,EACrC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAC1B,OAAO,CAAC;IAAE,QAAQ,EAAE,CAAC,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAK9D"}
|
package/dist/src/async.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.raceWithContext = exports.pollAsync = exports.retryAsync = exports.runWithTimeout = exports.timeout = exports.sleep = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Return a promise that resolves in ms milliseconds.
|
|
6
|
-
* @param ms Time to wait
|
|
7
|
-
*/
|
|
8
|
-
function sleep(ms) {
|
|
9
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
10
|
-
}
|
|
11
|
-
exports.sleep = sleep;
|
|
12
|
-
/**
|
|
13
|
-
* Wait up to a given amount of time, and throw an error if the promise does not resolve in time.
|
|
14
|
-
* @param promise The promise to timeout on.
|
|
15
|
-
* @param timeoutMs How long to wait for the promise in milliseconds.
|
|
16
|
-
* @param message The error message if a timeout occurs.
|
|
17
|
-
*/
|
|
18
|
-
function timeout(promise, timeoutMs, message = 'Timeout reached') {
|
|
19
|
-
if (!timeoutMs || timeoutMs <= 0)
|
|
20
|
-
return promise;
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
setTimeout(() => {
|
|
23
|
-
reject(new Error(message));
|
|
24
|
-
}, timeoutMs);
|
|
25
|
-
promise.then(resolve).catch(reject);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
exports.timeout = timeout;
|
|
29
|
-
/**
|
|
30
|
-
* Run a callback with a timeout.
|
|
31
|
-
* @param timeoutMs How long to wait for the promise in milliseconds.
|
|
32
|
-
* @param callback The callback to run.
|
|
33
|
-
* @returns callback return value
|
|
34
|
-
*/
|
|
35
|
-
async function runWithTimeout(timeoutMs, callback) {
|
|
36
|
-
let timeout;
|
|
37
|
-
const timeoutProm = new Promise((_, reject) => (timeout = setTimeout(() => reject(new Error(`Timed out in ${timeoutMs}ms.`)), timeoutMs)));
|
|
38
|
-
const ret = await Promise.race([callback(), timeoutProm]);
|
|
39
|
-
// @ts-ignore timeout gets set immediately by the promise constructor
|
|
40
|
-
clearTimeout(timeout);
|
|
41
|
-
return ret;
|
|
42
|
-
}
|
|
43
|
-
exports.runWithTimeout = runWithTimeout;
|
|
44
|
-
/**
|
|
45
|
-
* Retries an async function if it raises an exception,
|
|
46
|
-
* using exponential backoff.
|
|
47
|
-
* @param runner callback to run
|
|
48
|
-
* @param attempts max number of attempts
|
|
49
|
-
* @param baseRetryMs base delay between attempts
|
|
50
|
-
* @returns runner return value
|
|
51
|
-
*/
|
|
52
|
-
async function retryAsync(runner, attempts = 5, baseRetryMs = 50) {
|
|
53
|
-
let saveError;
|
|
54
|
-
for (let i = 0; i < attempts; i++) {
|
|
55
|
-
try {
|
|
56
|
-
const result = await runner();
|
|
57
|
-
return result;
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
saveError = error;
|
|
61
|
-
await sleep(baseRetryMs * 2 ** i);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
throw saveError;
|
|
65
|
-
}
|
|
66
|
-
exports.retryAsync = retryAsync;
|
|
67
|
-
/**
|
|
68
|
-
* Run a callback with a timeout, and retry if the callback throws an error.
|
|
69
|
-
* @param runner callback to run
|
|
70
|
-
* @param delayMs base delay between attempts
|
|
71
|
-
* @param maxAttempts maximum number of attempts
|
|
72
|
-
* @returns runner return value
|
|
73
|
-
*/
|
|
74
|
-
async function pollAsync(runner, delayMs = 500, maxAttempts = undefined) {
|
|
75
|
-
let attempts = 0;
|
|
76
|
-
let saveError;
|
|
77
|
-
while (!maxAttempts || attempts < maxAttempts) {
|
|
78
|
-
try {
|
|
79
|
-
const ret = await runner();
|
|
80
|
-
return ret;
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
saveError = error;
|
|
84
|
-
attempts += 1;
|
|
85
|
-
await sleep(delayMs);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
throw saveError;
|
|
89
|
-
}
|
|
90
|
-
exports.pollAsync = pollAsync;
|
|
91
|
-
/**
|
|
92
|
-
* An enhanced Promise.race that returns
|
|
93
|
-
* objects with the promise itself and index
|
|
94
|
-
* instead of just the resolved value.
|
|
95
|
-
*/
|
|
96
|
-
async function raceWithContext(promises) {
|
|
97
|
-
const promisesWithContext = promises.map((p, i) => p.then((resolved) => ({ resolved, promise: p, index: i })));
|
|
98
|
-
return Promise.race(promisesWithContext);
|
|
99
|
-
}
|
|
100
|
-
exports.raceWithContext = raceWithContext;
|
|
101
|
-
//# sourceMappingURL=async.js.map
|
package/dist/src/async.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async.js","sourceRoot":"","sources":["../../src/async.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,SAAgB,KAAK,CAAC,EAAU;IAC9B,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AACjE,CAAC;AAFD,sBAEC;AAED;;;;;GAKG;AACH,SAAgB,OAAO,CACrB,OAAmB,EACnB,SAAkB,EAClB,OAAO,GAAG,iBAAiB;IAE3B,IAAI,CAAC,SAAS,IAAI,SAAS,IAAI,CAAC;QAAE,OAAO,OAAO,CAAC;IACjD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,UAAU,CAAC,GAAG,EAAE;YACd,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7B,CAAC,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AG,EACb,cAAkC,SAAS;IAE3C,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,SAAS,CAAC;IACd,OAAO,CAAC,WAAW,IAAI,QAAQ,GAAG,WAAW,EAAE;QAC7C,IAAI;YACF,MAAM,GAAG,GAAG,MAAM,MAAM,EAAE,CAAC;YAC3B,OAAO,GAAG,CAAC;SACZ;QAAC,OAAO,KAAK,EAAE;YACd,SAAS,GAAG,KAAK,CAAC;YAClB,QAAQ,IAAI,CAAC,CAAC;YACd,MAAM,KAAK,CAAC,OAAO,CAAC,CAAC;SACtB;KACF;IACD,MAAM,SAAS,CAAC;AAClB,CAAC;AAlBD,8BAkBC;AAED;;;;GAIG;AACI,KAAK,UAAU,eAAe,CACnC,QAA2B;IAE3B,MAAM,mBAAmB,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAChD,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAC3D,CAAC;IACF,OAAO,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;AAC3C,CAAC;AAPD,0CAOC"}
|
package/dist/src/base58.d.ts
DELETED
package/dist/src/base58.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base58.d.ts","sourceRoot":"","sources":["../../src/base58.ts"],"names":[],"mappings":";AAEA,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,UAE3C;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,UAE3C;AAID,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,UAI7C"}
|
package/dist/src/base58.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hexOrBase58ToHex = exports.bufferToBase58 = exports.base58ToBuffer = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
function base58ToBuffer(value) {
|
|
6
|
-
return Buffer.from(ethers_1.utils.base58.decode(value));
|
|
7
|
-
}
|
|
8
|
-
exports.base58ToBuffer = base58ToBuffer;
|
|
9
|
-
function bufferToBase58(value) {
|
|
10
|
-
return ethers_1.utils.base58.encode(value);
|
|
11
|
-
}
|
|
12
|
-
exports.bufferToBase58 = bufferToBase58;
|
|
13
|
-
// If the value is already hex (checked by 0x prefix), return it as is.
|
|
14
|
-
// Otherwise, treat it as base58 and convert it to hex.
|
|
15
|
-
function hexOrBase58ToHex(value) {
|
|
16
|
-
if (value.startsWith('0x'))
|
|
17
|
-
return value;
|
|
18
|
-
return ethers_1.utils.hexlify(base58ToBuffer(value));
|
|
19
|
-
}
|
|
20
|
-
exports.hexOrBase58ToHex = hexOrBase58ToHex;
|
|
21
|
-
//# sourceMappingURL=base58.js.map
|
package/dist/src/base58.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base58.js","sourceRoot":"","sources":["../../src/base58.ts"],"names":[],"mappings":";;;AAAA,mCAA+B;AAE/B,SAAgB,cAAc,CAAC,KAAa;IAC1C,OAAO,MAAM,CAAC,IAAI,CAAC,cAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACjD,CAAC;AAFD,wCAEC;AAED,SAAgB,cAAc,CAAC,KAAa;IAC1C,OAAO,cAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACpC,CAAC;AAFD,wCAEC;AAED,uEAAuE;AACvE,uDAAuD;AACvD,SAAgB,gBAAgB,CAAC,KAAa;IAC5C,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAEzC,OAAO,cAAK,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9C,CAAC;AAJD,4CAIC"}
|
package/dist/src/base64.d.ts
DELETED
package/dist/src/base64.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../src/base64.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAQtD;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CASpE"}
|
package/dist/src/base64.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fromBase64 = exports.toBase64 = void 0;
|
|
4
|
-
const logging_1 = require("./logging");
|
|
5
|
-
function toBase64(data) {
|
|
6
|
-
try {
|
|
7
|
-
if (!data)
|
|
8
|
-
throw new Error('No data to encode');
|
|
9
|
-
return btoa(JSON.stringify(data));
|
|
10
|
-
}
|
|
11
|
-
catch (error) {
|
|
12
|
-
logging_1.rootLogger.error('Unable to serialize + encode data to base64', data);
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.toBase64 = toBase64;
|
|
17
|
-
function fromBase64(data) {
|
|
18
|
-
try {
|
|
19
|
-
if (!data)
|
|
20
|
-
throw new Error('No data to decode');
|
|
21
|
-
const msg = Array.isArray(data) ? data[0] : data;
|
|
22
|
-
return JSON.parse(atob(msg));
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
logging_1.rootLogger.error('Unable to decode + deserialize data from base64', data);
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.fromBase64 = fromBase64;
|
|
30
|
-
//# sourceMappingURL=base64.js.map
|
package/dist/src/base64.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/base64.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AAEvC,SAAgB,QAAQ,CAAC,IAAS;IAChC,IAAI;QACF,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAChD,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;KACnC;IAAC,OAAO,KAAK,EAAE;QACd,oBAAU,CAAC,KAAK,CAAC,6CAA6C,EAAE,IAAI,CAAC,CAAC;QACtE,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AARD,4BAQC;AAED,SAAgB,UAAU,CAAI,IAAuB;IACnD,IAAI;QACF,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAChD,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACjD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;KAC9B;IAAC,OAAO,KAAK,EAAE;QACd,oBAAU,CAAC,KAAK,CAAC,iDAAiD,EAAE,IAAI,CAAC,CAAC;QAC1E,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AATD,gCASC"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { FixedNumber } from 'ethers';
|
|
3
|
-
/**
|
|
4
|
-
* Check if a value is bigNumberish (e.g. valid numbers, bigNumber).
|
|
5
|
-
* @param value The value to check.
|
|
6
|
-
* @returns true/false.
|
|
7
|
-
*/
|
|
8
|
-
export declare function isBigNumberish(value: BigNumber.Value | undefined | null): boolean;
|
|
9
|
-
/**
|
|
10
|
-
* Check if a value (e.g. hex string or number) is zeroish (0, 0x0, 0x00, etc.).
|
|
11
|
-
* @param value The value to check.
|
|
12
|
-
* @returns true/false.
|
|
13
|
-
*/
|
|
14
|
-
export declare function isZeroish(value: BigNumber.Value): boolean;
|
|
15
|
-
/**
|
|
16
|
-
* Converts a BigNumber to a FixedNumber of the format fixed128x18.
|
|
17
|
-
* @param big The BigNumber to convert.
|
|
18
|
-
* @returns A FixedNumber representation of a BigNumber.
|
|
19
|
-
*/
|
|
20
|
-
export declare function bigToFixed(big: BigNumber.Value): FixedNumber;
|
|
21
|
-
/**
|
|
22
|
-
* Converts a FixedNumber (of any format) to a BigNumber.
|
|
23
|
-
* @param fixed The FixedNumber to convert.
|
|
24
|
-
* @param ceil If true, the ceiling of fixed is used. Otherwise, the floor is used.
|
|
25
|
-
* @returns A BigNumber representation of a FixedNumber.
|
|
26
|
-
*/
|
|
27
|
-
export declare function fixedToBig(fixed: FixedNumber, ceil?: boolean): BigNumber;
|
|
28
|
-
/**
|
|
29
|
-
* Multiplies a BigNumber by a FixedNumber, returning the BigNumber product.
|
|
30
|
-
* @param big The BigNumber to multiply.
|
|
31
|
-
* @param fixed The FixedNumber to multiply.
|
|
32
|
-
* @param ceil If true, the ceiling of the product is used. Otherwise, the floor is used.
|
|
33
|
-
* @returns The BigNumber product in string type.
|
|
34
|
-
*/
|
|
35
|
-
export declare function mulBigAndFixed(big: BigNumber.Value, fixed: FixedNumber, ceil?: boolean): string;
|
|
36
|
-
/**
|
|
37
|
-
* Return the smaller in the given two BigNumbers.
|
|
38
|
-
* @param bn1 The BigNumber to compare.
|
|
39
|
-
* @param bn2 The BigNumber to compare.
|
|
40
|
-
* @returns The smaller BigNumber in string type.
|
|
41
|
-
*/
|
|
42
|
-
export declare function BigNumberMin(bn1: BigNumber.Value, bn2: BigNumber.Value): string;
|
|
43
|
-
/**
|
|
44
|
-
* Return the bigger in the given two BigNumbers.
|
|
45
|
-
* @param bn1 The BigNumber to compare.
|
|
46
|
-
* @param bn2 The BigNumber to compare.
|
|
47
|
-
* @returns The bigger BigNumber in string type.
|
|
48
|
-
*/
|
|
49
|
-
export declare function BigNumberMax(bn1: BigNumber.Value, bn2: BigNumber.Value): string;
|
|
50
|
-
//# sourceMappingURL=big-numbers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"big-numbers.d.ts","sourceRoot":"","sources":["../../src/big-numbers.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAKrC;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,SAAS,GAAG,IAAI,GACxC,OAAO,CAOT;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,OAAO,CAMzD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,GAAG,WAAW,CAE5D;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,UAAQ,GAAG,SAAS,CAGtE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,SAAS,CAAC,KAAK,EACpB,KAAK,EAAE,WAAW,EAClB,IAAI,UAAQ,GACX,MAAM,CAIR;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,SAAS,CAAC,KAAK,EACpB,GAAG,EAAE,SAAS,CAAC,KAAK,GACnB,MAAM,CAER;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,SAAS,CAAC,KAAK,EACpB,GAAG,EAAE,SAAS,CAAC,KAAK,GACnB,MAAM,CAER"}
|