@hyperlane-xyz/utils 3.1.3 → 3.1.5
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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/src/amount.d.ts +33 -16
- package/dist/src/amount.d.ts.map +1 -1
- package/dist/src/amount.js +54 -59
- package/dist/src/amount.js.map +1 -1
- package/dist/src/amount.test.d.ts +2 -0
- package/dist/src/amount.test.d.ts.map +1 -0
- package/dist/src/amount.test.js +48 -0
- package/dist/src/amount.test.js.map +1 -0
- package/dist/src/big-numbers.d.ts +31 -8
- package/dist/src/big-numbers.d.ts.map +1 -1
- package/dist/src/big-numbers.js +37 -16
- package/dist/src/big-numbers.js.map +1 -1
- package/dist/src/big-numbers.test.js +89 -29
- package/dist/src/big-numbers.test.js.map +1 -1
- package/dist/src/multisig.d.ts.map +1 -1
- package/dist/src/multisig.js +6 -2
- package/dist/src/multisig.js.map +1 -1
- package/package.json +5 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { addressToByteHexString, addressToBytes, addressToBytes32, addressToBytesCosmos, addressToBytesEvm, addressToBytesSol, bytes32ToAddress, bytesToAddressCosmos, bytesToAddressEvm, bytesToAddressSol, bytesToProtocolAddress, capitalizeAddress, convertToProtocolAddress, ensure0x, eqAddress, eqAddressCosmos, eqAddressEvm, eqAddressSol, getAddressProtocolType, isAddressCosmos, isAddressEvm, isAddressSealevel, isValidAddress, isValidAddressCosmos, isValidAddressEvm, isValidAddressSealevel, isValidTransactionHash, isValidTransactionHashCosmos, isValidTransactionHashEvm, isValidTransactionHashSealevel, isZeroishAddress, normalizeAddress, normalizeAddressCosmos, normalizeAddressEvm, normalizeAddressSealevel, shortenAddress, strip0x, } from './src/addresses';
|
|
2
|
-
export { convertDecimals,
|
|
2
|
+
export { convertDecimals, eqAmountApproximate, fromWei, fromWeiRounded, toWei, tryParseAmount, } from './src/amount';
|
|
3
3
|
export { chunk, exclude } from './src/arrays';
|
|
4
4
|
export { pollAsync, retryAsync, runWithTimeout, sleep, timeout, } from './src/async';
|
|
5
5
|
export { base58ToBuffer, bufferToBase58, hexOrBase58ToHex } from './src/base58';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,iBAAiB,EACjB,wBAAwB,EACxB,QAAQ,EACR,SAAS,EACT,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,sBAAsB,EACtB,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,4BAA4B,EAC5B,yBAAyB,EACzB,8BAA8B,EAC9B,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,mBAAmB,EACnB,wBAAwB,EACxB,cAAc,EACd,OAAO,GACR,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,eAAe,EACf,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,iBAAiB,EACjB,wBAAwB,EACxB,QAAQ,EACR,SAAS,EACT,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,sBAAsB,EACtB,eAAe,EACf,Y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ACvD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EACL,+BAA+B,EAC/B,8BAA8B,GAC/B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,OAAO,EACP,aAAa,EACb,UAAU,EACV,mBAAmB,EACnB,QAAQ,EACR,SAAS,EACT,MAAM,EACN,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,EACd,WAAW,EACX,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EACL,OAAO,EACP,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,MAAM,EACN,SAAS,EACT,4BAA4B,EAC5B,WAAW,EACX,aAAa,EACb,+BAA+B,EAC/B,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sleep = exports.runWithTimeout = exports.retryAsync = exports.pollAsync = exports.exclude = exports.chunk = exports.tryParseAmount = exports.toWei = exports.fromWeiRounded = exports.fromWei = exports.eqAmountApproximate = exports.
|
|
4
|
-
exports.sanitizeString = exports.errorToString = exports.symmetricDifference = exports.setEquality = exports.difference = exports.promiseObjAll = exports.pick = exports.objMerge = exports.objMapEntries = exports.objMap = exports.objFilter = exports.isObject = exports.invertKeysAndValues = exports.deepEquals = exports.arrayToObject = exports.parseLegacyMultisigIsmMetadata = exports.formatLegacyMultisigIsmMetadata = exports.parseMessage = exports.messageId = exports.formatMessage = exports.sum = exports.stdDev = exports.median = exports.mean = exports.warn = exports.trace = exports.log = exports.error = exports.debug = exports.evmId = exports.canonizeId = exports.safelyAccessEnvVar = exports.domainHash = exports.isS3CheckpointWithId = exports.isS3Checkpoint = exports.isCheckpoint = exports.formatCallData = exports.mulBigAndFixed = exports.isZeroish = exports.isBigNumberish = exports.fixedToBig = exports.bigToFixed = exports.BigNumberMin = exports.BigNumberMax = exports.toBase64 = exports.fromBase64 = exports.hexOrBase58ToHex = exports.bufferToBase58 = exports.base58ToBuffer =
|
|
5
|
-
exports.BaseValidator = exports.assert = exports.ProtocolType = exports.ProtocolSmallestUnit = exports.MessageStatus = exports.InterchainSecurityModuleType = exports.isNumeric = exports.isNullish = exports.trimToLength = exports.toTitleCase =
|
|
3
|
+
exports.timeout = exports.sleep = exports.runWithTimeout = exports.retryAsync = exports.pollAsync = exports.exclude = exports.chunk = exports.tryParseAmount = exports.toWei = exports.fromWeiRounded = exports.fromWei = exports.eqAmountApproximate = exports.convertDecimals = exports.strip0x = exports.shortenAddress = exports.normalizeAddressSealevel = exports.normalizeAddressEvm = exports.normalizeAddressCosmos = exports.normalizeAddress = exports.isZeroishAddress = exports.isValidTransactionHashSealevel = exports.isValidTransactionHashEvm = exports.isValidTransactionHashCosmos = exports.isValidTransactionHash = exports.isValidAddressSealevel = exports.isValidAddressEvm = exports.isValidAddressCosmos = exports.isValidAddress = exports.isAddressSealevel = exports.isAddressEvm = exports.isAddressCosmos = exports.getAddressProtocolType = exports.eqAddressSol = exports.eqAddressEvm = exports.eqAddressCosmos = exports.eqAddress = exports.ensure0x = exports.convertToProtocolAddress = exports.capitalizeAddress = exports.bytesToProtocolAddress = exports.bytesToAddressSol = exports.bytesToAddressEvm = exports.bytesToAddressCosmos = exports.bytes32ToAddress = exports.addressToBytesSol = exports.addressToBytesEvm = exports.addressToBytesCosmos = exports.addressToBytes32 = exports.addressToBytes = exports.addressToByteHexString = void 0;
|
|
4
|
+
exports.streamToString = exports.sanitizeString = exports.errorToString = exports.symmetricDifference = exports.setEquality = exports.difference = exports.promiseObjAll = exports.pick = exports.objMerge = exports.objMapEntries = exports.objMap = exports.objFilter = exports.isObject = exports.invertKeysAndValues = exports.deepEquals = exports.arrayToObject = exports.parseLegacyMultisigIsmMetadata = exports.formatLegacyMultisigIsmMetadata = exports.parseMessage = exports.messageId = exports.formatMessage = exports.sum = exports.stdDev = exports.median = exports.mean = exports.warn = exports.trace = exports.log = exports.error = exports.debug = exports.evmId = exports.canonizeId = exports.safelyAccessEnvVar = exports.domainHash = exports.isS3CheckpointWithId = exports.isS3Checkpoint = exports.isCheckpoint = exports.formatCallData = exports.mulBigAndFixed = exports.isZeroish = exports.isBigNumberish = exports.fixedToBig = exports.bigToFixed = exports.BigNumberMin = exports.BigNumberMax = exports.toBase64 = exports.fromBase64 = exports.hexOrBase58ToHex = exports.bufferToBase58 = exports.base58ToBuffer = void 0;
|
|
5
|
+
exports.BaseValidator = exports.assert = exports.ProtocolType = exports.ProtocolSmallestUnit = exports.MessageStatus = exports.InterchainSecurityModuleType = exports.isNumeric = exports.isNullish = exports.trimToLength = exports.toTitleCase = void 0;
|
|
6
6
|
var addresses_1 = require("./src/addresses");
|
|
7
7
|
Object.defineProperty(exports, "addressToByteHexString", { enumerable: true, get: function () { return addresses_1.addressToByteHexString; } });
|
|
8
8
|
Object.defineProperty(exports, "addressToBytes", { enumerable: true, get: function () { return addresses_1.addressToBytes; } });
|
|
@@ -43,7 +43,6 @@ Object.defineProperty(exports, "shortenAddress", { enumerable: true, get: functi
|
|
|
43
43
|
Object.defineProperty(exports, "strip0x", { enumerable: true, get: function () { return addresses_1.strip0x; } });
|
|
44
44
|
var amount_1 = require("./src/amount");
|
|
45
45
|
Object.defineProperty(exports, "convertDecimals", { enumerable: true, get: function () { return amount_1.convertDecimals; } });
|
|
46
|
-
Object.defineProperty(exports, "convertDecimalsEthersBigNumber", { enumerable: true, get: function () { return amount_1.convertDecimalsEthersBigNumber; } });
|
|
47
46
|
Object.defineProperty(exports, "eqAmountApproximate", { enumerable: true, get: function () { return amount_1.eqAmountApproximate; } });
|
|
48
47
|
Object.defineProperty(exports, "fromWei", { enumerable: true, get: function () { return amount_1.fromWei; } });
|
|
49
48
|
Object.defineProperty(exports, "fromWeiRounded", { enumerable: true, get: function () { return amount_1.fromWeiRounded; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;AAAA,6CAsCyB;AArCvB,mHAAA,sBAAsB,OAAA;AACtB,2GAAA,cAAc,OAAA;AACd,6GAAA,gBAAgB,OAAA;AAChB,iHAAA,oBAAoB,OAAA;AACpB,8GAAA,iBAAiB,OAAA;AACjB,8GAAA,iBAAiB,OAAA;AACjB,6GAAA,gBAAgB,OAAA;AAChB,iHAAA,oBAAoB,OAAA;AACpB,8GAAA,iBAAiB,OAAA;AACjB,8GAAA,iBAAiB,OAAA;AACjB,mHAAA,sBAAsB,OAAA;AACtB,8GAAA,iBAAiB,OAAA;AACjB,qHAAA,wBAAwB,OAAA;AACxB,qGAAA,QAAQ,OAAA;AACR,sGAAA,SAAS,OAAA;AACT,4GAAA,eAAe,OAAA;AACf,yGAAA,YAAY,OAAA;AACZ,yGAAA,YAAY,OAAA;AACZ,mHAAA,sBAAsB,OAAA;AACtB,4GAAA,eAAe,OAAA;AACf,yGAAA,YAAY,OAAA;AACZ,8GAAA,iBAAiB,OAAA;AACjB,2GAAA,cAAc,OAAA;AACd,iHAAA,oBAAoB,OAAA;AACpB,8GAAA,iBAAiB,OAAA;AACjB,mHAAA,sBAAsB,OAAA;AACtB,mHAAA,sBAAsB,OAAA;AACtB,yHAAA,4BAA4B,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FAAA,IAAI,OAAA;AACvC,mCAAuD;AAA9C,4FAAA,IAAI,OAAA;AAAE,8FAAA,MAAM,OAAA;AAAE,8FAAA,MAAM,OAAA;AAAE,2FAAA,GAAG,OAAA;AAClC,2CAAwE;AAA/D,yGAAA,aAAa,OAAA;AAAE,qGAAA,SAAS,OAAA;AAAE,wGAAA,YAAY,OAAA;AAC/C,2CAGwB;AAFtB,2HAAA,+BAA+B,OAAA;AAC/B,0HAAA,8BAA8B,OAAA;AAEhC,yCAYuB;AAVrB,wGAAA,aAAa,OAAA;AACb,qGAAA,UAAU,OAAA;AACV,8GAAA,mBAAmB,OAAA;AACnB,mGAAA,QAAQ,OAAA;AACR,oGAAA,SAAS,OAAA;AACT,iGAAA,MAAM,OAAA;AACN,wGAAA,aAAa,OAAA;AACb,mGAAA,QAAQ,OAAA;AACR,+FAAA,IAAI,OAAA;AACJ,wGAAA,aAAa,OAAA;AAEf,mCAA0E;AAAjE,kGAAA,UAAU,OAAA;AAAE,mGAAA,WAAW,OAAA;AAAE,2GAAA,mBAAmB,OAAA;AACrD,yCAMuB;AALrB,wGAAA,aAAa,OAAA;AACb,yGAAA,cAAc,OAAA;AACd,yGAAA,cAAc,OAAA;AACd,sGAAA,WAAW,OAAA;AACX,uGAAA,YAAY,OAAA;AAEd,uCAAoD;AAA3C,mGAAA,SAAS,OAAA;AAAE,mGAAA,SAAS,OAAA;AAC7B,qCAoBqB;AAZnB,qHAAA,4BAA4B,OAAA;AAE5B,sGAAA,aAAa,OAAA;AAGb,6GAAA,oBAAoB,OAAA;AACpB,qGAAA,YAAY,OAAA;AAOd,+CAA0C;AAAjC,oGAAA,MAAM,OAAA;AACf,6CAAgD;AAAvC,0GAAA,aAAa,OAAA"}
|
package/dist/src/amount.d.ts
CHANGED
|
@@ -1,28 +1,45 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { ethers } from 'ethers';
|
|
3
|
-
type NumberT = BigNumber.Value;
|
|
4
|
-
export declare function fromWei(value: NumberT | null | undefined, decimals?: number): number;
|
|
5
|
-
export declare function fromWeiRounded(value: NumberT | null | undefined, decimals?: number, roundDownIfSmall?: boolean): string;
|
|
6
|
-
export declare function toWei(value: NumberT | null | undefined, decimals?: number): BigNumber;
|
|
7
|
-
export declare function tryParseAmount(value: NumberT | null | undefined): BigNumber | null;
|
|
8
|
-
export declare function eqAmountApproximate(amountInWei1: BigNumber, amountInWei2: NumberT): boolean;
|
|
9
2
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
13
|
-
|
|
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
|
|
14
11
|
* @param value The value to convert.
|
|
15
|
-
* @
|
|
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.
|
|
16
34
|
*/
|
|
17
|
-
export declare function
|
|
35
|
+
export declare function eqAmountApproximate(amount1: BigNumber.Value, amount2: BigNumber.Value, maxDifference: BigNumber.Value): boolean;
|
|
18
36
|
/**
|
|
19
37
|
* Converts a value with `fromDecimals` decimals to a value with `toDecimals` decimals.
|
|
20
38
|
* Incurs a loss of precision when `fromDecimals` > `toDecimals`.
|
|
21
39
|
* @param fromDecimals The number of decimals `value` has.
|
|
22
40
|
* @param toDecimals The number of decimals to convert `value` to.
|
|
23
41
|
* @param value The value to convert.
|
|
24
|
-
* @returns `value` represented with `toDecimals` decimals.
|
|
42
|
+
* @returns `value` represented with `toDecimals` decimals in string type.
|
|
25
43
|
*/
|
|
26
|
-
export declare function
|
|
27
|
-
export {};
|
|
44
|
+
export declare function convertDecimals(fromDecimals: number, toDecimals: number, value: BigNumber.Value): string;
|
|
28
45
|
//# sourceMappingURL=amount.d.ts.map
|
package/dist/src/amount.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../../src/amount.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,cAAc,CAAC;
|
|
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
CHANGED
|
@@ -3,66 +3,78 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.convertDecimals = exports.eqAmountApproximate = exports.tryParseAmount = exports.toWei = exports.fromWeiRounded = exports.fromWei = void 0;
|
|
7
7
|
const units_1 = require("@ethersproject/units");
|
|
8
8
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
|
-
const ethers_1 = require("ethers");
|
|
10
|
-
const DEFAULT_MIN_ROUNDED_VALUE = 0.00001;
|
|
11
9
|
const DEFAULT_DISPLAY_DECIMALS = 4;
|
|
12
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
|
+
*/
|
|
13
16
|
function fromWei(value, decimals = DEFAULT_TOKEN_DECIMALS) {
|
|
14
17
|
if (!value)
|
|
15
|
-
return 0;
|
|
16
|
-
const valueString = value.toString().trim();
|
|
17
|
-
const flooredValue =
|
|
18
|
-
return parseFloat((0, units_1.formatUnits)(flooredValue, decimals));
|
|
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();
|
|
19
22
|
}
|
|
20
23
|
exports.fromWei = fromWei;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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) {
|
|
24
32
|
if (!value)
|
|
25
33
|
return '0';
|
|
26
|
-
const flooredValue =
|
|
27
|
-
const amount =
|
|
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));
|
|
28
36
|
if (amount.isZero())
|
|
29
37
|
return '0';
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (roundDownIfSmall)
|
|
33
|
-
return '0';
|
|
34
|
-
return amount.toString(10);
|
|
35
|
-
}
|
|
36
|
-
const displayDecimals = amount.gte(10000) ? 2 : DEFAULT_DISPLAY_DECIMALS;
|
|
37
|
-
return amount.toFixed(displayDecimals).toString();
|
|
38
|
+
displayDecimals ?? (displayDecimals = amount.gte(10000) ? 2 : DEFAULT_DISPLAY_DECIMALS);
|
|
39
|
+
return amount.toFixed(displayDecimals, bignumber_js_1.default.ROUND_FLOOR);
|
|
38
40
|
}
|
|
39
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
|
+
*/
|
|
40
47
|
function toWei(value, decimals = DEFAULT_TOKEN_DECIMALS) {
|
|
41
48
|
if (!value)
|
|
42
|
-
return
|
|
49
|
+
return (0, bignumber_js_1.default)(0).toString();
|
|
43
50
|
// First convert to a BigNumber, and then call `toString` with the
|
|
44
51
|
// explicit radix 10 such that the result is formatted as a base-10 string
|
|
45
52
|
// and not in scientific notation.
|
|
46
|
-
const valueBN =
|
|
53
|
+
const valueBN = (0, bignumber_js_1.default)(value);
|
|
47
54
|
const valueString = valueBN.toString(10).trim();
|
|
48
55
|
const components = valueString.split('.');
|
|
49
56
|
if (components.length === 1) {
|
|
50
|
-
return
|
|
57
|
+
return (0, units_1.parseUnits)(valueString, decimals).toString();
|
|
51
58
|
}
|
|
52
59
|
else if (components.length === 2) {
|
|
53
60
|
const trimmedFraction = components[1].substring(0, decimals);
|
|
54
|
-
return
|
|
61
|
+
return (0, units_1.parseUnits)(`${components[0]}.${trimmedFraction}`, decimals).toString();
|
|
55
62
|
}
|
|
56
63
|
else {
|
|
57
64
|
throw new Error(`Cannot convert ${valueString} to wei`);
|
|
58
65
|
}
|
|
59
66
|
}
|
|
60
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
|
+
*/
|
|
61
73
|
function tryParseAmount(value) {
|
|
62
74
|
try {
|
|
63
75
|
if (!value)
|
|
64
76
|
return null;
|
|
65
|
-
const parsed =
|
|
77
|
+
const parsed = (0, bignumber_js_1.default)(value);
|
|
66
78
|
if (!parsed || parsed.isNaN() || !parsed.isFinite())
|
|
67
79
|
return null;
|
|
68
80
|
else
|
|
@@ -73,12 +85,16 @@ function tryParseAmount(value) {
|
|
|
73
85
|
}
|
|
74
86
|
}
|
|
75
87
|
exports.tryParseAmount = tryParseAmount;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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);
|
|
82
98
|
}
|
|
83
99
|
exports.eqAmountApproximate = eqAmountApproximate;
|
|
84
100
|
/**
|
|
@@ -87,45 +103,24 @@ exports.eqAmountApproximate = eqAmountApproximate;
|
|
|
87
103
|
* @param fromDecimals The number of decimals `value` has.
|
|
88
104
|
* @param toDecimals The number of decimals to convert `value` to.
|
|
89
105
|
* @param value The value to convert.
|
|
90
|
-
* @returns `value` represented with `toDecimals` decimals.
|
|
106
|
+
* @returns `value` represented with `toDecimals` decimals in string type.
|
|
91
107
|
*/
|
|
92
108
|
function convertDecimals(fromDecimals, toDecimals, value) {
|
|
93
|
-
const amount =
|
|
109
|
+
const amount = (0, bignumber_js_1.default)(value);
|
|
94
110
|
if (fromDecimals === toDecimals)
|
|
95
|
-
return amount;
|
|
111
|
+
return amount.toString(10);
|
|
96
112
|
else if (fromDecimals > toDecimals) {
|
|
97
113
|
const difference = fromDecimals - toDecimals;
|
|
98
114
|
return amount
|
|
99
|
-
.div(
|
|
100
|
-
.integerValue(bignumber_js_1.default.ROUND_FLOOR)
|
|
115
|
+
.div((0, bignumber_js_1.default)(10).pow(difference))
|
|
116
|
+
.integerValue(bignumber_js_1.default.ROUND_FLOOR)
|
|
117
|
+
.toString(10);
|
|
101
118
|
}
|
|
102
119
|
// fromDecimals < toDecimals
|
|
103
120
|
else {
|
|
104
121
|
const difference = toDecimals - fromDecimals;
|
|
105
|
-
return amount.times(
|
|
122
|
+
return amount.times((0, bignumber_js_1.default)(10).pow(difference)).toString(10);
|
|
106
123
|
}
|
|
107
124
|
}
|
|
108
125
|
exports.convertDecimals = convertDecimals;
|
|
109
|
-
/**
|
|
110
|
-
* Converts a value with `fromDecimals` decimals to a value with `toDecimals` decimals.
|
|
111
|
-
* Incurs a loss of precision when `fromDecimals` > `toDecimals`.
|
|
112
|
-
* @param fromDecimals The number of decimals `value` has.
|
|
113
|
-
* @param toDecimals The number of decimals to convert `value` to.
|
|
114
|
-
* @param value The value to convert.
|
|
115
|
-
* @returns `value` represented with `toDecimals` decimals.
|
|
116
|
-
*/
|
|
117
|
-
function convertDecimalsEthersBigNumber(fromDecimals, toDecimals, value) {
|
|
118
|
-
if (fromDecimals === toDecimals)
|
|
119
|
-
return value;
|
|
120
|
-
else if (fromDecimals > toDecimals) {
|
|
121
|
-
const difference = fromDecimals - toDecimals;
|
|
122
|
-
return value.div(ethers_1.ethers.BigNumber.from('10').pow(difference));
|
|
123
|
-
}
|
|
124
|
-
// fromDecimals < toDecimals
|
|
125
|
-
else {
|
|
126
|
-
const difference = toDecimals - fromDecimals;
|
|
127
|
-
return value.mul(ethers_1.ethers.BigNumber.from('10').pow(difference));
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
exports.convertDecimalsEthersBigNumber = convertDecimalsEthersBigNumber;
|
|
131
126
|
//# sourceMappingURL=amount.js.map
|
package/dist/src/amount.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../src/amount.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA+D;AAC/D,gEAAqC;
|
|
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sources":["../../src/amount.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,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CAAC,CAAC;QAC3D,IAAA,aAAM,EAAC,IAAA,cAAK,EAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACxE,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"}
|
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
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;
|
|
4
15
|
/**
|
|
5
16
|
* Converts a BigNumber to a FixedNumber of the format fixed128x18.
|
|
6
17
|
* @param big The BigNumber to convert.
|
|
7
18
|
* @returns A FixedNumber representation of a BigNumber.
|
|
8
19
|
*/
|
|
9
|
-
export declare function bigToFixed(big: BigNumber): FixedNumber;
|
|
20
|
+
export declare function bigToFixed(big: BigNumber.Value): FixedNumber;
|
|
10
21
|
/**
|
|
11
22
|
* Converts a FixedNumber (of any format) to a BigNumber.
|
|
12
23
|
* @param fixed The FixedNumber to convert.
|
|
@@ -19,9 +30,21 @@ export declare function fixedToBig(fixed: FixedNumber, ceil?: boolean): BigNumbe
|
|
|
19
30
|
* @param big The BigNumber to multiply.
|
|
20
31
|
* @param fixed The FixedNumber to multiply.
|
|
21
32
|
* @param ceil If true, the ceiling of the product is used. Otherwise, the floor is used.
|
|
22
|
-
* @returns The BigNumber product.
|
|
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.
|
|
23
48
|
*/
|
|
24
|
-
export declare function
|
|
25
|
-
export declare function BigNumberMin(bn1: BigNumber, bn2: BigNumber): BigNumber;
|
|
26
|
-
export declare function BigNumberMax(bn1: BigNumber, bn2: BigNumber): BigNumber;
|
|
49
|
+
export declare function BigNumberMax(bn1: BigNumber.Value, bn2: BigNumber.Value): string;
|
|
27
50
|
//# sourceMappingURL=big-numbers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"big-numbers.d.ts","sourceRoot":"","sources":["../../src/big-numbers.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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"}
|
package/dist/src/big-numbers.js
CHANGED
|
@@ -1,27 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.BigNumberMax = exports.BigNumberMin = exports.mulBigAndFixed = exports.fixedToBig = exports.bigToFixed = exports.isZeroish = exports.isBigNumberish = void 0;
|
|
7
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
4
8
|
const ethers_1 = require("ethers");
|
|
5
|
-
|
|
9
|
+
// Use toString(10) on bignumber.js to prevent ethers.js bigNumber error
|
|
10
|
+
// when parsing exponential string over e21
|
|
11
|
+
/**
|
|
12
|
+
* Check if a value is bigNumberish (e.g. valid numbers, bigNumber).
|
|
13
|
+
* @param value The value to check.
|
|
14
|
+
* @returns true/false.
|
|
15
|
+
*/
|
|
6
16
|
function isBigNumberish(value) {
|
|
7
17
|
try {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return ethers_1.BigNumber.from(value)._isBigNumber;
|
|
18
|
+
const val = (0, bignumber_js_1.default)(value);
|
|
19
|
+
return !val.isNaN() && val.isFinite() && bignumber_js_1.default.isBigNumber(val);
|
|
11
20
|
}
|
|
12
21
|
catch (error) {
|
|
13
22
|
return false;
|
|
14
23
|
}
|
|
15
24
|
}
|
|
16
25
|
exports.isBigNumberish = isBigNumberish;
|
|
17
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Check if a value (e.g. hex string or number) is zeroish (0, 0x0, 0x00, etc.).
|
|
28
|
+
* @param value The value to check.
|
|
29
|
+
* @returns true/false.
|
|
30
|
+
*/
|
|
18
31
|
function isZeroish(value) {
|
|
19
32
|
try {
|
|
20
|
-
|
|
21
|
-
value === ethers_1.constants.HashZero ||
|
|
22
|
-
value === ethers_1.constants.AddressZero)
|
|
23
|
-
return true;
|
|
24
|
-
return ethers_1.BigNumber.from(value).isZero();
|
|
33
|
+
return (0, bignumber_js_1.default)(value).isZero();
|
|
25
34
|
}
|
|
26
35
|
catch (error) {
|
|
27
36
|
return false;
|
|
@@ -34,7 +43,7 @@ exports.isZeroish = isZeroish;
|
|
|
34
43
|
* @returns A FixedNumber representation of a BigNumber.
|
|
35
44
|
*/
|
|
36
45
|
function bigToFixed(big) {
|
|
37
|
-
return ethers_1.FixedNumber.from(big.toString());
|
|
46
|
+
return ethers_1.FixedNumber.from(big.toString(10));
|
|
38
47
|
}
|
|
39
48
|
exports.bigToFixed = bigToFixed;
|
|
40
49
|
/**
|
|
@@ -45,7 +54,7 @@ exports.bigToFixed = bigToFixed;
|
|
|
45
54
|
*/
|
|
46
55
|
function fixedToBig(fixed, ceil = false) {
|
|
47
56
|
const fixedAsInteger = ceil ? fixed.ceiling() : fixed.floor();
|
|
48
|
-
return
|
|
57
|
+
return (0, bignumber_js_1.default)(fixedAsInteger.toFormat('fixed256x0').toString());
|
|
49
58
|
}
|
|
50
59
|
exports.fixedToBig = fixedToBig;
|
|
51
60
|
/**
|
|
@@ -53,20 +62,32 @@ exports.fixedToBig = fixedToBig;
|
|
|
53
62
|
* @param big The BigNumber to multiply.
|
|
54
63
|
* @param fixed The FixedNumber to multiply.
|
|
55
64
|
* @param ceil If true, the ceiling of the product is used. Otherwise, the floor is used.
|
|
56
|
-
* @returns The BigNumber product.
|
|
65
|
+
* @returns The BigNumber product in string type.
|
|
57
66
|
*/
|
|
58
67
|
function mulBigAndFixed(big, fixed, ceil = false) {
|
|
59
68
|
// Converts big to a FixedNumber, multiplies it by fixed, and converts the product back
|
|
60
69
|
// to a BigNumber.
|
|
61
|
-
return fixedToBig(fixed.mulUnsafe(bigToFixed(big)), ceil);
|
|
70
|
+
return fixedToBig(fixed.mulUnsafe(bigToFixed(big)), ceil).toString(10);
|
|
62
71
|
}
|
|
63
72
|
exports.mulBigAndFixed = mulBigAndFixed;
|
|
73
|
+
/**
|
|
74
|
+
* Return the smaller in the given two BigNumbers.
|
|
75
|
+
* @param bn1 The BigNumber to compare.
|
|
76
|
+
* @param bn2 The BigNumber to compare.
|
|
77
|
+
* @returns The smaller BigNumber in string type.
|
|
78
|
+
*/
|
|
64
79
|
function BigNumberMin(bn1, bn2) {
|
|
65
|
-
return bn1.gte(bn2) ? bn2 : bn1;
|
|
80
|
+
return (0, bignumber_js_1.default)(bn1).gte(bn2) ? bn2.toString(10) : bn1.toString(10);
|
|
66
81
|
}
|
|
67
82
|
exports.BigNumberMin = BigNumberMin;
|
|
83
|
+
/**
|
|
84
|
+
* Return the bigger in the given two BigNumbers.
|
|
85
|
+
* @param bn1 The BigNumber to compare.
|
|
86
|
+
* @param bn2 The BigNumber to compare.
|
|
87
|
+
* @returns The bigger BigNumber in string type.
|
|
88
|
+
*/
|
|
68
89
|
function BigNumberMax(bn1, bn2) {
|
|
69
|
-
return bn1.lte(bn2) ? bn2 : bn1;
|
|
90
|
+
return (0, bignumber_js_1.default)(bn1).lte(bn2) ? bn2.toString(10) : bn1.toString(10);
|
|
70
91
|
}
|
|
71
92
|
exports.BigNumberMax = BigNumberMax;
|
|
72
93
|
//# sourceMappingURL=big-numbers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"big-numbers.js","sourceRoot":"","sources":["../../src/big-numbers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"big-numbers.js","sourceRoot":"","sources":["../../src/big-numbers.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAqC;AACrC,mCAAqC;AAErC,wEAAwE;AACxE,2CAA2C;AAE3C;;;;GAIG;AACH,SAAgB,cAAc,CAC5B,KAAyC;IAEzC,IAAI;QACF,MAAM,GAAG,GAAG,IAAA,sBAAS,EAAC,KAAM,CAAC,CAAC;QAC9B,O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,sBAAS,EAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AACvE,CAAC;AALD,oCAKC;AAED;;;;;GAKG;AACH,SAAgB,YAAY,CAC1B,GAAoB,EACpB,GAAoB;IAEpB,OAAO,IAAA,sBAAS,EAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AACvE,CAAC;AALD,oCAKC"}
|
|
@@ -1,41 +1,101 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
3
7
|
const chai_1 = require("chai");
|
|
4
8
|
const ethers_1 = require("ethers");
|
|
5
9
|
const big_numbers_1 = require("./big-numbers");
|
|
6
|
-
describe('
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
describe('isBigNumberish', () => {
|
|
11
|
+
const testCases = [
|
|
12
|
+
{ expect: false, context: 'invalid number', case: 'invalidNumber' },
|
|
13
|
+
{ expect: false, context: 'NaN', case: NaN },
|
|
14
|
+
{ expect: false, context: 'undefined', case: undefined },
|
|
15
|
+
{ expect: false, context: 'null', case: null },
|
|
16
|
+
{ expect: true, context: 'decimal', case: 123.123 },
|
|
17
|
+
{ expect: true, context: 'integer', case: 300000 },
|
|
18
|
+
{ expect: true, context: 'hex 0', case: 0x00 },
|
|
19
|
+
{ expect: true, context: 'hex 0', case: 0x000 },
|
|
20
|
+
{
|
|
21
|
+
expect: true,
|
|
22
|
+
context: 'address 0',
|
|
23
|
+
case: 0x0000000000000000000000000000000000000000,
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
testCases.forEach((tc) => {
|
|
27
|
+
it(`returns ${tc.expect} for ${tc.case}`, () => {
|
|
28
|
+
(0, chai_1.expect)((0, big_numbers_1.isBigNumberish)(tc.case)).to.equal(tc.expect);
|
|
12
29
|
});
|
|
13
30
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
});
|
|
32
|
+
describe('isZeroish', () => {
|
|
33
|
+
const testCases = [
|
|
34
|
+
{ expect: false, context: 'invalid number', case: 'invalidNumber' },
|
|
35
|
+
{ expect: false, context: 'NaN', case: NaN },
|
|
36
|
+
{ expect: false, context: 'undefined', case: undefined },
|
|
37
|
+
{ expect: false, context: 'null', case: null },
|
|
38
|
+
{ expect: false, context: 'non 0 decimal', case: 123.123 },
|
|
39
|
+
{ expect: false, context: 'non 0 integer', case: 123 },
|
|
40
|
+
{ expect: true, context: 'hex 0', case: 0x00 },
|
|
41
|
+
{ expect: true, context: 'hex 0', case: 0x000 },
|
|
42
|
+
{
|
|
43
|
+
expect: true,
|
|
44
|
+
context: 'address 0',
|
|
45
|
+
case: 0x0000000000000000000000000000000000000000,
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
testCases.forEach((tc) => {
|
|
49
|
+
it(`returns ${tc.expect} for ${tc.case}`, () => {
|
|
50
|
+
(0, chai_1.expect)((0, big_numbers_1.isZeroish)(tc.case)).to.equal(tc.expect);
|
|
24
51
|
});
|
|
25
52
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
53
|
+
});
|
|
54
|
+
describe('bigToFixed', () => {
|
|
55
|
+
it('converts a BigNumber to a FixedNumber', () => {
|
|
56
|
+
const big = (0, bignumber_js_1.default)('7.5e-10');
|
|
57
|
+
const fixed = (0, big_numbers_1.bigToFixed)(big);
|
|
58
|
+
(0, chai_1.expect)(fixed.toUnsafeFloat()).to.equal(7.5e-10);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
describe('fixedToBig', () => {
|
|
62
|
+
it('converts a FixedNumber to a floored BigNumber', () => {
|
|
63
|
+
const fixed = ethers_1.FixedNumber.from('12.34');
|
|
64
|
+
const big = (0, big_numbers_1.fixedToBig)(fixed);
|
|
65
|
+
(0, chai_1.expect)(big.toNumber()).to.equal(12);
|
|
66
|
+
});
|
|
67
|
+
it('converts a FixedNumber to a ceilinged BigNumber', () => {
|
|
68
|
+
const fixed = ethers_1.FixedNumber.from('12.34');
|
|
69
|
+
const big = (0, big_numbers_1.fixedToBig)(fixed, true);
|
|
70
|
+
(0, chai_1.expect)(big.toNumber()).to.equal(13);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe('mulBigAndFixed', () => {
|
|
74
|
+
it('gets the floored product of a BigNumber and FixedNumber', () => {
|
|
75
|
+
const big = (0, bignumber_js_1.default)('1000');
|
|
76
|
+
const fixed = ethers_1.FixedNumber.from('1.2345');
|
|
77
|
+
const product = (0, big_numbers_1.mulBigAndFixed)(big, fixed);
|
|
78
|
+
(0, chai_1.expect)(product).to.equal((1234).toString());
|
|
79
|
+
});
|
|
80
|
+
it('gets the ceilinged product of a BigNumber and FixedNumber', () => {
|
|
81
|
+
const big = (0, bignumber_js_1.default)('1000');
|
|
82
|
+
const fixed = ethers_1.FixedNumber.from('1.2345');
|
|
83
|
+
const product = (0, big_numbers_1.mulBigAndFixed)(big, fixed, true);
|
|
84
|
+
(0, chai_1.expect)(product).to.equal((1235).toString());
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
describe('BigNumberMin', () => {
|
|
88
|
+
it('gets the min between the two BigNumber', () => {
|
|
89
|
+
const big = (0, bignumber_js_1.default)('1000');
|
|
90
|
+
const bigger = (0, bignumber_js_1.default)('10000');
|
|
91
|
+
(0, chai_1.expect)((0, big_numbers_1.BigNumberMin)(big, bigger)).to.equal(big.toString());
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe('BigNumberMax', () => {
|
|
95
|
+
it('gets the max between the two BigNumber', () => {
|
|
96
|
+
const big = (0, bignumber_js_1.default)('1000');
|
|
97
|
+
const bigger = (0, bignumber_js_1.default)('10000');
|
|
98
|
+
(0, chai_1.expect)((0, big_numbers_1.BigNumberMax)(big, bigger)).to.equal(bigger.toString());
|
|
39
99
|
});
|
|
40
100
|
});
|
|
41
101
|
//# sourceMappingURL=big-numbers.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"big-numbers.test.js","sourceRoot":"","sources":["../../src/big-numbers.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"big-numbers.test.js","sourceRoot":"","sources":["../../src/big-numbers.test.ts"],"names":[],"mappings":";;;;;AAAA,gEAAqC;AACrC,+BAA8B;AAC9B,mCAAqC;AAErC,+CAQuB;AAEvB,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,MAAM,SAAS,GAAG;QAChB,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,eAAe,EAAE;QACnE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE;QAC5C,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;QACxD,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE;QAC9C,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AAE,IAAI,CAAC,CAAC;QAEjD,IAAA,aAAM,EAAC,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAChD,MAAM,GAAG,GAAG,IAAA,sBAAS,EAAC,MAAM,CAAC,CAAC;QAC9B,MAAM,MAAM,GAAG,IAAA,sBAAS,EAAC,OAAO,CAAC,CAAC;QAClC,IAAA,aAAM,EAAC,IAAA,0BAAY,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAChD,MAAM,GAAG,GAAG,IAAA,sBAAS,EAAC,MAAM,CAAC,CAAC;QAC9B,MAAM,MAAM,GAAG,IAAA,sBAAS,EAAC,OAAO,CAAC,CAAC;QAClC,IAAA,aAAM,EAAC,IAAA,0BAAY,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multisig.d.ts","sourceRoot":"","sources":["../../src/multisig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"multisig.d.ts","sourceRoot":"","sources":["../../src/multisig.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAE1D,eAAO,MAAM,8BAA8B,aAC/B,MAAM,KACf,+BA4CF,CAAC;AAEF,eAAO,MAAM,+BAA+B,aAChC,+BAA+B,KACxC,MAqBF,CAAC"}
|
package/dist/src/multisig.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.formatLegacyMultisigIsmMetadata = exports.parseLegacyMultisigIsmMetadata = void 0;
|
|
7
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
4
8
|
const ethers_1 = require("ethers");
|
|
5
9
|
const addresses_1 = require("./addresses");
|
|
6
10
|
const parseLegacyMultisigIsmMetadata = (metadata) => {
|
|
@@ -13,13 +17,13 @@ const parseLegacyMultisigIsmMetadata = (metadata) => {
|
|
|
13
17
|
const SIGNATURE_LENGTH = 65;
|
|
14
18
|
const buf = Buffer.from(ethers_1.utils.arrayify(metadata));
|
|
15
19
|
const checkpointRoot = ethers_1.utils.hexlify(buf.slice(MERKLE_ROOT_OFFSET, MERKLE_INDEX_OFFSET));
|
|
16
|
-
const checkpointIndex =
|
|
20
|
+
const checkpointIndex = (0, bignumber_js_1.default)(ethers_1.utils.hexlify(buf.slice(MERKLE_INDEX_OFFSET, ORIGIN_MAILBOX_OFFSET))).toNumber();
|
|
17
21
|
const originMailbox = ethers_1.utils.hexlify(buf.slice(ORIGIN_MAILBOX_OFFSET, MERKLE_PROOF_OFFSET));
|
|
18
22
|
const parseBytesArray = (start, count, size) => {
|
|
19
23
|
return [...Array(count).keys()].map((i) => ethers_1.utils.hexlify(buf.slice(start + size * i, start + size * (i + 1))));
|
|
20
24
|
};
|
|
21
25
|
const proof = parseBytesArray(MERKLE_PROOF_OFFSET, 32, 32);
|
|
22
|
-
const threshold =
|
|
26
|
+
const threshold = (0, bignumber_js_1.default)(ethers_1.utils.hexlify(buf.slice(THRESHOLD_OFFSET, SIGNATURES_OFFSET))).toNumber();
|
|
23
27
|
const signatures = parseBytesArray(SIGNATURES_OFFSET, threshold, SIGNATURE_LENGTH);
|
|
24
28
|
const VALIDATORS_OFFSET = SIGNATURES_OFFSET + threshold * SIGNATURE_LENGTH;
|
|
25
29
|
const addressesCount = buf.slice(VALIDATORS_OFFSET).length / 32;
|
package/dist/src/multisig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multisig.js","sourceRoot":"","sources":["../../src/multisig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"multisig.js","sourceRoot":"","sources":["../../src/multisig.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAqC;AACrC,mCAA+B;AAE/B,2CAA+C;AAGxC,MAAM,8BAA8B,GAAG,CAC5C,QAAgB,EACiB,EAAE;IACnC,MAAM,kBAAkB,GAAG,CAAC,CAAC;IAC7B,MAAM,mBAAmB,GAAG,EAAE,CAAC;IAC/B,MAAM,qBAAqB,GAAG,EAAE,CAAC;IACjC,MAAM,mBAAmB,GAAG,EAAE,CAAC;IAC/B,MAAM,gBAAgB,GAAG,IAAI,CAAC;IAC9B,MAAM,iBAAiB,GAAG,IAAI,CAAC;IAC/B,MAAM,gBAAgB,GAAG,EAAE,CAAC;IAE5B,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,cAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClD,MAAM,cAAc,GAAG,cAAK,CAAC,OAAO,CAClC,GAAG,CAAC,KAAK,CAAC,kBAAkB,EAAE,mBAAmB,CAAC,CACnD,CAAC;IACF,MAAM,eAAe,GAAG,IAAA,sBAAS,EAC/B,cAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,mBAAmB,EAAE,qBAAqB,CAAC,CAAC,CACrE,CAAC,QAAQ,EAAE,CAAC;IACb,MAAM,aAAa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AAK,CAAC,YAAY,CACvB;QACE,SAAS;QACT,QAAQ;QACR,SAAS;QACT,aAAa;QACb,OAAO;QACP,OAAO;QACP,WAAW;KACZ,EACD;QACE,QAAQ,CAAC,cAAc;QACvB,QAAQ,CAAC,eAAe;QACxB,IAAA,4BAAgB,EAAC,QAAQ,CAAC,aAAa,CAAC;QACxC,QAAQ,CAAC,KAAK;QACd,QAAQ,CAAC,UAAU,CAAC,MAAM;QAC1B,cAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC;QACpC,QAAQ,CAAC,UAAU;KACpB,CACF,CAAC;AACJ,CAAC,CAAC;AAvBW,QAAA,+BAA+B,mCAuB1C"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperlane-xyz/utils",
|
|
3
3
|
"description": "General utilities and types for the Hyperlane network",
|
|
4
|
-
"version": "3.1.
|
|
4
|
+
"version": "3.1.5",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@cosmjs/encoding": "^0.31.3",
|
|
7
7
|
"@solana/web3.js": "^1.78.0",
|
|
8
8
|
"bignumber.js": "^9.1.1",
|
|
9
|
-
"ethers": "^5.7.2"
|
|
9
|
+
"ethers": "^5.7.2",
|
|
10
|
+
"mocha": "^10.2.0"
|
|
10
11
|
},
|
|
11
12
|
"devDependencies": {
|
|
12
13
|
"chai": "^4.3.0",
|
|
@@ -27,7 +28,8 @@
|
|
|
27
28
|
"build": "tsc",
|
|
28
29
|
"clean": "rm -rf ./dist",
|
|
29
30
|
"check": "tsc --noEmit",
|
|
30
|
-
"prettier": "prettier --write ./src"
|
|
31
|
+
"prettier": "prettier --write ./src",
|
|
32
|
+
"test": "mocha --config .mocharc.json './src/**/*.test.ts'"
|
|
31
33
|
},
|
|
32
34
|
"sideEffects": false,
|
|
33
35
|
"types": "dist/index.d.ts",
|