@hairy/ether-lib 1.46.0 → 1.49.0

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/LICENSE.md CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025-PRESENT Hairyf <https://github.com/antfu>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025-PRESENT Hairyf <https://github.com/antfu>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,36 +1,36 @@
1
- # @hairy/ether-lib
2
-
3
- [![npm version][npm-version-src]][npm-version-href]
4
- [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
- [![bundle][bundle-src]][bundle-href]
6
- [![JSDocs][jsdocs-src]][jsdocs-href]
7
- [![License][license-src]][license-href]
8
-
9
- ## Install
10
-
11
- ```
12
- ni @hairy/ether-lib
13
- ```
14
-
15
- ## CDN
16
-
17
- ```html
18
- <script src="https://unpkg.com/@hairy/ether-lib"></script>
19
- ```
20
-
21
- ## License
22
-
23
- [MIT](./LICENSE) License © [Hairyf](https://github.com/hairyf)
24
-
25
- <!-- Badges -->
26
-
27
- [npm-version-src]: https://img.shields.io/npm/v/@hairy/ether-lib?style=flat&colorA=080f12&colorB=1fa669
28
- [npm-version-href]: https://npmjs.com/package/@hairy/ether-lib
29
- [npm-downloads-src]: https://img.shields.io/npm/dm/@hairy/ether-lib?style=flat&colorA=080f12&colorB=1fa669
30
- [npm-downloads-href]: https://npmjs.com/package/@hairy/ether-lib
31
- [bundle-src]: https://img.shields.io/bundlephobia/minzip/@hairy/ether-lib?style=flat&colorA=080f12&colorB=1fa669&label=minzip
32
- [bundle-href]: https://bundlephobia.com/result?p=@hairy/ether-lib
33
- [license-src]: https://img.shields.io/github/license/hairyf/hairylib.svg?style=flat&colorA=080f12&colorB=1fa669
34
- [license-href]: https://github.com/hairyf/hairylib/blob/main/LICENSE
35
- [jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
36
- [jsdocs-href]: https://www.jsdocs.io/package/@hairy/ether-lib
1
+ # @hairy/ether-lib
2
+
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+ [![bundle][bundle-src]][bundle-href]
6
+ [![JSDocs][jsdocs-src]][jsdocs-href]
7
+ [![License][license-src]][license-href]
8
+
9
+ ## Install
10
+
11
+ ```
12
+ ni @hairy/ether-lib
13
+ ```
14
+
15
+ ## CDN
16
+
17
+ ```html
18
+ <script src="https://unpkg.com/@hairy/ether-lib"></script>
19
+ ```
20
+
21
+ ## License
22
+
23
+ [MIT](./LICENSE) License © [Hairyf](https://github.com/hairyf)
24
+
25
+ <!-- Badges -->
26
+
27
+ [npm-version-src]: https://img.shields.io/npm/v/@hairy/ether-lib?style=flat&colorA=080f12&colorB=1fa669
28
+ [npm-version-href]: https://npmjs.com/package/@hairy/ether-lib
29
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@hairy/ether-lib?style=flat&colorA=080f12&colorB=1fa669
30
+ [npm-downloads-href]: https://npmjs.com/package/@hairy/ether-lib
31
+ [bundle-src]: https://img.shields.io/bundlephobia/minzip/@hairy/ether-lib?style=flat&colorA=080f12&colorB=1fa669&label=minzip
32
+ [bundle-href]: https://bundlephobia.com/result?p=@hairy/ether-lib
33
+ [license-src]: https://img.shields.io/github/license/hairyf/hairylib.svg?style=flat&colorA=080f12&colorB=1fa669
34
+ [license-href]: https://github.com/hairyf/hairylib/blob/main/LICENSE
35
+ [jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
36
+ [jsdocs-href]: https://www.jsdocs.io/package/@hairy/ether-lib
package/dist/index.cjs CHANGED
@@ -1,113 +1,108 @@
1
- "use strict";
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region \0rolldown/runtime.js
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __getProtoOf = Object.getPrototypeOf;
7
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
9
  var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) {
14
+ __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ }
20
+ }
21
+ return to;
19
22
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
29
27
 
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- Errors: () => Errors,
34
- formatEther: () => formatEther,
35
- idprefix: () => idprefix,
36
- wait: () => wait
37
- });
38
- module.exports = __toCommonJS(index_exports);
28
+ //#endregion
29
+ let ethers = require("ethers");
30
+ let _hairy_utils = require("@hairy/utils");
31
+ let mitt = require("mitt");
32
+ mitt = __toESM(mitt);
39
33
 
40
- // src/constants.ts
41
- var Errors = /* @__PURE__ */ ((Errors2) => {
42
- Errors2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
43
- Errors2["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
44
- Errors2["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
45
- Errors2["NETWORK_ERROR"] = "NETWORK_ERROR";
46
- Errors2["SERVER_ERROR"] = "SERVER_ERROR";
47
- Errors2["TIMEOUT"] = "TIMEOUT";
48
- Errors2["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
49
- Errors2["NUMERIC_FAULT"] = "NUMERIC_FAULT";
50
- Errors2["MISSING_NEW"] = "MISSING_NEW";
51
- Errors2["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
52
- Errors2["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
53
- Errors2["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
54
- Errors2["CALL_EXCEPTION"] = "CALL_EXCEPTION";
55
- Errors2["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
56
- Errors2["NONCE_EXPIRED"] = "NONCE_EXPIRED";
57
- Errors2["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
58
- Errors2["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
59
- Errors2["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
60
- Errors2["ACTION_REJECTED"] = "ACTION_REJECTED";
61
- return Errors2;
62
- })(Errors || {});
34
+ //#region src/constants.ts
35
+ let Errors = /* @__PURE__ */ function(Errors) {
36
+ Errors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
37
+ Errors["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
38
+ Errors["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
39
+ Errors["NETWORK_ERROR"] = "NETWORK_ERROR";
40
+ Errors["SERVER_ERROR"] = "SERVER_ERROR";
41
+ Errors["TIMEOUT"] = "TIMEOUT";
42
+ Errors["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
43
+ Errors["NUMERIC_FAULT"] = "NUMERIC_FAULT";
44
+ Errors["MISSING_NEW"] = "MISSING_NEW";
45
+ Errors["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
46
+ Errors["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
47
+ Errors["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
48
+ Errors["CALL_EXCEPTION"] = "CALL_EXCEPTION";
49
+ Errors["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
50
+ Errors["NONCE_EXPIRED"] = "NONCE_EXPIRED";
51
+ Errors["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
52
+ Errors["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
53
+ Errors["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
54
+ Errors["ACTION_REJECTED"] = "ACTION_REJECTED";
55
+ return Errors;
56
+ }({});
63
57
 
64
- // src/hash.ts
65
- var import_ethers = require("ethers");
58
+ //#endregion
59
+ //#region src/hash.ts
66
60
  function idprefix(errorCallString) {
67
- return (0, import_ethers.id)(errorCallString).slice(0, 10);
61
+ return (0, ethers.id)(errorCallString).slice(0, 10);
68
62
  }
69
63
 
70
- // src/number.ts
71
- var import_utils = require("@hairy/utils");
72
- var import_ethers2 = require("ethers");
64
+ //#endregion
65
+ //#region src/number.ts
73
66
  function formatEther(value = "0", options = {}) {
74
- const { separator = false, decimals, delimiters = false, rounding, decimalsZero = true, default: _default } = options;
75
- const number = (0, import_ethers2.formatEther)((0, import_utils.bignumber)(value).toFixed(0));
76
- const groupSeparator = separator === false ? "" : ",";
77
- return (0, import_utils.formatNumeric)(number, {
78
- format: { groupSeparator, ...options.format },
79
- delimiters: typeof delimiters === "boolean" ? delimiters && ["m", "b", "t"] : delimiters,
80
- default: _default,
81
- decimals,
82
- rounding,
83
- decimalsZero
84
- });
67
+ const { separator = false, decimals, delimiters = false, rounding, decimalsZero = true, default: _default } = options;
68
+ return (0, _hairy_utils.formatNumeric)((0, ethers.formatEther)((0, _hairy_utils.bignumber)(value).toFixed(0)), {
69
+ format: {
70
+ groupSeparator: separator === false ? "" : ",",
71
+ ...options.format
72
+ },
73
+ delimiters: typeof delimiters === "boolean" ? delimiters && [
74
+ "m",
75
+ "b",
76
+ "t"
77
+ ] : delimiters,
78
+ default: _default,
79
+ decimals,
80
+ rounding,
81
+ decimalsZero
82
+ });
85
83
  }
86
84
 
87
- // src/wait.ts
88
- var import_mitt = __toESM(require("mitt"), 1);
89
- var emitter = (0, import_mitt.default)();
85
+ //#endregion
86
+ //#region src/wait.ts
87
+ const emitter = (0, mitt.default)();
90
88
  async function wait(transaction) {
91
- try {
92
- emitter.emit("before");
93
- if (typeof transaction === "function")
94
- transaction = await transaction();
95
- if (transaction instanceof Promise)
96
- transaction = await transaction;
97
- const receipt = await transaction.getTransaction().then((transaction2) => transaction2?.wait());
98
- emitter.emit("after", receipt);
99
- return receipt;
100
- } catch (error) {
101
- emitter.emit("after", null);
102
- emitter.emit("error", error);
103
- throw error;
104
- }
89
+ try {
90
+ emitter.emit("before");
91
+ if (typeof transaction === "function") transaction = await transaction();
92
+ if (transaction instanceof Promise) transaction = await transaction;
93
+ const receipt = await transaction.getTransaction().then((transaction) => transaction?.wait());
94
+ emitter.emit("after", receipt);
95
+ return receipt;
96
+ } catch (error) {
97
+ emitter.emit("after", null);
98
+ emitter.emit("error", error);
99
+ throw error;
100
+ }
105
101
  }
106
102
  wait.subscribe = emitter.on.bind(emitter);
107
- // Annotate the CommonJS export names for ESM import in node:
108
- 0 && (module.exports = {
109
- Errors,
110
- formatEther,
111
- idprefix,
112
- wait
113
- });
103
+
104
+ //#endregion
105
+ exports.Errors = Errors;
106
+ exports.formatEther = formatEther;
107
+ exports.idprefix = idprefix;
108
+ exports.wait = wait;
@@ -0,0 +1,61 @@
1
+ import { Bignumber, Delimiter, Numberish } from "@hairy/utils";
2
+ import * as mitt from "mitt";
3
+ import { ContractTransactionResponse, TransactionReceipt, TransactionResponse } from "ethers";
4
+
5
+ //#region src/constants.d.ts
6
+ declare enum Errors {
7
+ UNKNOWN_ERROR = "UNKNOWN_ERROR",
8
+ NOT_IMPLEMENTED = "NOT_IMPLEMENTED",
9
+ UNSUPPORTED_OPERATION = "UNSUPPORTED_OPERATION",
10
+ NETWORK_ERROR = "NETWORK_ERROR",
11
+ SERVER_ERROR = "SERVER_ERROR",
12
+ TIMEOUT = "TIMEOUT",
13
+ BUFFER_OVERRUN = "BUFFER_OVERRUN",
14
+ NUMERIC_FAULT = "NUMERIC_FAULT",
15
+ MISSING_NEW = "MISSING_NEW",
16
+ INVALID_ARGUMENT = "INVALID_ARGUMENT",
17
+ MISSING_ARGUMENT = "MISSING_ARGUMENT",
18
+ UNEXPECTED_ARGUMENT = "UNEXPECTED_ARGUMENT",
19
+ CALL_EXCEPTION = "CALL_EXCEPTION",
20
+ INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
21
+ NONCE_EXPIRED = "NONCE_EXPIRED",
22
+ REPLACEMENT_UNDERPRICED = "REPLACEMENT_UNDERPRICED",
23
+ UNPREDICTABLE_GAS_LIMIT = "UNPREDICTABLE_GAS_LIMIT",
24
+ TRANSACTION_REPLACED = "TRANSACTION_REPLACED",
25
+ ACTION_REJECTED = "ACTION_REJECTED"
26
+ }
27
+ //#endregion
28
+ //#region src/hash.d.ts
29
+ declare function idprefix(errorCallString: string): string;
30
+ //#endregion
31
+ //#region src/number.d.ts
32
+ interface FormatEtherOptions {
33
+ delimiters?: Delimiter[] | boolean;
34
+ separator?: boolean;
35
+ rounding?: Bignumber.RoundingMode;
36
+ decimalsZero?: boolean;
37
+ decimals?: number;
38
+ format?: Bignumber.Format;
39
+ default?: string;
40
+ }
41
+ declare function formatEther(value?: Numberish, options?: FormatEtherOptions): string;
42
+ //#endregion
43
+ //#region src/wait.d.ts
44
+ type GenericTransactionResponse = TransactionResponse | ContractTransactionResponse | Promise<TransactionResponse | ContractTransactionResponse> | (() => TransactionResponse | ContractTransactionResponse) | (() => Promise<TransactionResponse | ContractTransactionResponse>);
45
+ declare function wait(transaction: GenericTransactionResponse): Promise<TransactionReceipt | null | undefined>;
46
+ declare namespace wait {
47
+ var subscribe: {
48
+ <Key extends "before" | "after" | "error">(type: Key, handler: mitt.Handler<{
49
+ before: void;
50
+ after: TransactionReceipt | null | undefined;
51
+ error: Error;
52
+ }[Key]>): void;
53
+ (type: "*", handler: mitt.WildcardHandler<{
54
+ before: void;
55
+ after: TransactionReceipt | null | undefined;
56
+ error: Error;
57
+ }>): void;
58
+ };
59
+ }
60
+ //#endregion
61
+ export { Errors, FormatEtherOptions, GenericTransactionResponse, formatEther, idprefix, wait };
@@ -0,0 +1,61 @@
1
+ import { ContractTransactionResponse, TransactionReceipt, TransactionResponse } from "ethers";
2
+ import { Bignumber, Delimiter, Numberish } from "@hairy/utils";
3
+ import * as mitt$1 from "mitt";
4
+
5
+ //#region src/constants.d.ts
6
+ declare enum Errors {
7
+ UNKNOWN_ERROR = "UNKNOWN_ERROR",
8
+ NOT_IMPLEMENTED = "NOT_IMPLEMENTED",
9
+ UNSUPPORTED_OPERATION = "UNSUPPORTED_OPERATION",
10
+ NETWORK_ERROR = "NETWORK_ERROR",
11
+ SERVER_ERROR = "SERVER_ERROR",
12
+ TIMEOUT = "TIMEOUT",
13
+ BUFFER_OVERRUN = "BUFFER_OVERRUN",
14
+ NUMERIC_FAULT = "NUMERIC_FAULT",
15
+ MISSING_NEW = "MISSING_NEW",
16
+ INVALID_ARGUMENT = "INVALID_ARGUMENT",
17
+ MISSING_ARGUMENT = "MISSING_ARGUMENT",
18
+ UNEXPECTED_ARGUMENT = "UNEXPECTED_ARGUMENT",
19
+ CALL_EXCEPTION = "CALL_EXCEPTION",
20
+ INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
21
+ NONCE_EXPIRED = "NONCE_EXPIRED",
22
+ REPLACEMENT_UNDERPRICED = "REPLACEMENT_UNDERPRICED",
23
+ UNPREDICTABLE_GAS_LIMIT = "UNPREDICTABLE_GAS_LIMIT",
24
+ TRANSACTION_REPLACED = "TRANSACTION_REPLACED",
25
+ ACTION_REJECTED = "ACTION_REJECTED"
26
+ }
27
+ //#endregion
28
+ //#region src/hash.d.ts
29
+ declare function idprefix(errorCallString: string): string;
30
+ //#endregion
31
+ //#region src/number.d.ts
32
+ interface FormatEtherOptions {
33
+ delimiters?: Delimiter[] | boolean;
34
+ separator?: boolean;
35
+ rounding?: Bignumber.RoundingMode;
36
+ decimalsZero?: boolean;
37
+ decimals?: number;
38
+ format?: Bignumber.Format;
39
+ default?: string;
40
+ }
41
+ declare function formatEther(value?: Numberish, options?: FormatEtherOptions): string;
42
+ //#endregion
43
+ //#region src/wait.d.ts
44
+ type GenericTransactionResponse = TransactionResponse | ContractTransactionResponse | Promise<TransactionResponse | ContractTransactionResponse> | (() => TransactionResponse | ContractTransactionResponse) | (() => Promise<TransactionResponse | ContractTransactionResponse>);
45
+ declare function wait(transaction: GenericTransactionResponse): Promise<TransactionReceipt | null | undefined>;
46
+ declare namespace wait {
47
+ var subscribe: {
48
+ <Key extends "before" | "after" | "error">(type: Key, handler: mitt$1.Handler<{
49
+ before: void;
50
+ after: TransactionReceipt | null | undefined;
51
+ error: Error;
52
+ }[Key]>): void;
53
+ (type: "*", handler: mitt$1.WildcardHandler<{
54
+ before: void;
55
+ after: TransactionReceipt | null | undefined;
56
+ error: Error;
57
+ }>): void;
58
+ };
59
+ }
60
+ //#endregion
61
+ export { Errors, FormatEtherOptions, GenericTransactionResponse, formatEther, idprefix, wait };
package/dist/index.mjs ADDED
@@ -0,0 +1,76 @@
1
+ import { formatEther as formatEther$1, id } from "ethers";
2
+ import { bignumber, formatNumeric } from "@hairy/utils";
3
+ import mitt from "mitt";
4
+
5
+ //#region src/constants.ts
6
+ let Errors = /* @__PURE__ */ function(Errors) {
7
+ Errors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
8
+ Errors["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
9
+ Errors["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
10
+ Errors["NETWORK_ERROR"] = "NETWORK_ERROR";
11
+ Errors["SERVER_ERROR"] = "SERVER_ERROR";
12
+ Errors["TIMEOUT"] = "TIMEOUT";
13
+ Errors["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
14
+ Errors["NUMERIC_FAULT"] = "NUMERIC_FAULT";
15
+ Errors["MISSING_NEW"] = "MISSING_NEW";
16
+ Errors["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
17
+ Errors["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
18
+ Errors["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
19
+ Errors["CALL_EXCEPTION"] = "CALL_EXCEPTION";
20
+ Errors["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
21
+ Errors["NONCE_EXPIRED"] = "NONCE_EXPIRED";
22
+ Errors["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
23
+ Errors["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
24
+ Errors["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
25
+ Errors["ACTION_REJECTED"] = "ACTION_REJECTED";
26
+ return Errors;
27
+ }({});
28
+
29
+ //#endregion
30
+ //#region src/hash.ts
31
+ function idprefix(errorCallString) {
32
+ return id(errorCallString).slice(0, 10);
33
+ }
34
+
35
+ //#endregion
36
+ //#region src/number.ts
37
+ function formatEther(value = "0", options = {}) {
38
+ const { separator = false, decimals, delimiters = false, rounding, decimalsZero = true, default: _default } = options;
39
+ return formatNumeric(formatEther$1(bignumber(value).toFixed(0)), {
40
+ format: {
41
+ groupSeparator: separator === false ? "" : ",",
42
+ ...options.format
43
+ },
44
+ delimiters: typeof delimiters === "boolean" ? delimiters && [
45
+ "m",
46
+ "b",
47
+ "t"
48
+ ] : delimiters,
49
+ default: _default,
50
+ decimals,
51
+ rounding,
52
+ decimalsZero
53
+ });
54
+ }
55
+
56
+ //#endregion
57
+ //#region src/wait.ts
58
+ const emitter = mitt();
59
+ async function wait(transaction) {
60
+ try {
61
+ emitter.emit("before");
62
+ if (typeof transaction === "function") transaction = await transaction();
63
+ if (transaction instanceof Promise) transaction = await transaction;
64
+ const receipt = await transaction.getTransaction().then((transaction) => transaction?.wait());
65
+ emitter.emit("after", receipt);
66
+ return receipt;
67
+ } catch (error) {
68
+ emitter.emit("after", null);
69
+ emitter.emit("error", error);
70
+ throw error;
71
+ }
72
+ }
73
+ wait.subscribe = emitter.on.bind(emitter);
74
+
75
+ //#endregion
76
+ export { Errors, formatEther, idprefix, wait };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hairy/ether-lib",
3
3
  "type": "module",
4
- "version": "1.46.0",
4
+ "version": "1.49.0",
5
5
  "description": "Library for ether",
6
6
  "author": "Hairyf <wwu710632@gmail.com>",
7
7
  "license": "MIT",
@@ -14,37 +14,36 @@
14
14
  "bugs": "https://github.com/hairyf/hairylib/issues",
15
15
  "keywords": [],
16
16
  "sideEffects": false,
17
- "main": "./dist/index.js",
18
- "publishConfig": {
19
- "jsdelivr": "./dist/index.global.js"
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/index.mjs",
20
+ "require": "./dist/index.cjs"
21
+ },
22
+ "./package.json": "./package.json"
20
23
  },
24
+ "main": "./dist/index.mjs",
25
+ "module": "./dist/index.mjs",
26
+ "types": "./dist/index.d.mts",
21
27
  "files": [
22
28
  "dist"
23
29
  ],
30
+ "publishConfig": {
31
+ "jsdelivr": "./dist/index.iife.js"
32
+ },
24
33
  "peerDependencies": {
25
34
  "ethers": ">=6"
26
35
  },
27
36
  "dependencies": {
28
37
  "mitt": "^3.0.1",
29
- "@hairy/utils": "1.46.0"
38
+ "@hairy/utils": "1.49.0"
30
39
  },
31
40
  "devDependencies": {
32
41
  "ethers": "^6"
33
42
  },
34
43
  "scripts": {
35
- "build": "tsup",
36
- "dev": "tsup --watch",
44
+ "build": "tsdown",
45
+ "dev": "tsdown --watch",
37
46
  "start": "tsx src/index.ts"
38
47
  },
39
- "module": "./dist/index.js",
40
- "types": "./dist/index.d.ts",
41
- "unpkg": "./dist/index.global.js",
42
- "exports": {
43
- ".": {
44
- "import": "./dist/index.js",
45
- "require": "./dist/index.cjs",
46
- "types": "./dist/index.d.ts"
47
- },
48
- "./*": "./*"
49
- }
48
+ "unpkg": "./dist/index.iife.js"
50
49
  }
package/dist/index.d.ts DELETED
@@ -1,57 +0,0 @@
1
- import { Delimiter, Bignumber, Numberish } from '@hairy/utils';
2
- import * as mitt from 'mitt';
3
- import { TransactionResponse, ContractTransactionResponse, TransactionReceipt } from 'ethers';
4
-
5
- declare enum Errors {
6
- UNKNOWN_ERROR = "UNKNOWN_ERROR",
7
- NOT_IMPLEMENTED = "NOT_IMPLEMENTED",
8
- UNSUPPORTED_OPERATION = "UNSUPPORTED_OPERATION",
9
- NETWORK_ERROR = "NETWORK_ERROR",
10
- SERVER_ERROR = "SERVER_ERROR",
11
- TIMEOUT = "TIMEOUT",
12
- BUFFER_OVERRUN = "BUFFER_OVERRUN",
13
- NUMERIC_FAULT = "NUMERIC_FAULT",
14
- MISSING_NEW = "MISSING_NEW",
15
- INVALID_ARGUMENT = "INVALID_ARGUMENT",
16
- MISSING_ARGUMENT = "MISSING_ARGUMENT",
17
- UNEXPECTED_ARGUMENT = "UNEXPECTED_ARGUMENT",
18
- CALL_EXCEPTION = "CALL_EXCEPTION",
19
- INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
20
- NONCE_EXPIRED = "NONCE_EXPIRED",
21
- REPLACEMENT_UNDERPRICED = "REPLACEMENT_UNDERPRICED",
22
- UNPREDICTABLE_GAS_LIMIT = "UNPREDICTABLE_GAS_LIMIT",
23
- TRANSACTION_REPLACED = "TRANSACTION_REPLACED",
24
- ACTION_REJECTED = "ACTION_REJECTED"
25
- }
26
-
27
- declare function idprefix(errorCallString: string): string;
28
-
29
- interface FormatEtherOptions {
30
- delimiters?: Delimiter[] | boolean;
31
- separator?: boolean;
32
- rounding?: Bignumber.RoundingMode;
33
- decimalsZero?: boolean;
34
- decimals?: number;
35
- format?: Bignumber.Format;
36
- default?: string;
37
- }
38
- declare function formatEther(value?: Numberish, options?: FormatEtherOptions): string;
39
-
40
- type GenericTransactionResponse = TransactionResponse | ContractTransactionResponse | Promise<TransactionResponse | ContractTransactionResponse> | (() => TransactionResponse | ContractTransactionResponse) | (() => Promise<TransactionResponse | ContractTransactionResponse>);
41
- declare function wait(transaction: GenericTransactionResponse): Promise<TransactionReceipt | null | undefined>;
42
- declare namespace wait {
43
- var subscribe: {
44
- <Key extends "error" | "after" | "before">(type: Key, handler: mitt.Handler<{
45
- before: void;
46
- after: TransactionReceipt | null | undefined;
47
- error: Error;
48
- }[Key]>): void;
49
- (type: "*", handler: mitt.WildcardHandler<{
50
- before: void;
51
- after: TransactionReceipt | null | undefined;
52
- error: Error;
53
- }>): void;
54
- };
55
- }
56
-
57
- export { Errors, type FormatEtherOptions, type GenericTransactionResponse, formatEther, idprefix, wait };
@@ -1,205 +0,0 @@
1
- "use strict";
2
- (() => {
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __commonJS = (cb, mod) => function __require() {
10
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
-
29
- // globals:ethers
30
- var require_ethers = __commonJS({
31
- "globals:ethers"(exports, module) {
32
- "use strict";
33
- module.exports = ethers;
34
- }
35
- });
36
-
37
- // globals:bignumber.js
38
- var require_bignumber = __commonJS({
39
- "globals:bignumber.js"(exports, module) {
40
- "use strict";
41
- module.exports = BigNumber;
42
- }
43
- });
44
-
45
- // src/constants.ts
46
- var Errors = /* @__PURE__ */ ((Errors2) => {
47
- Errors2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
48
- Errors2["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
49
- Errors2["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
50
- Errors2["NETWORK_ERROR"] = "NETWORK_ERROR";
51
- Errors2["SERVER_ERROR"] = "SERVER_ERROR";
52
- Errors2["TIMEOUT"] = "TIMEOUT";
53
- Errors2["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
54
- Errors2["NUMERIC_FAULT"] = "NUMERIC_FAULT";
55
- Errors2["MISSING_NEW"] = "MISSING_NEW";
56
- Errors2["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
57
- Errors2["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
58
- Errors2["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
59
- Errors2["CALL_EXCEPTION"] = "CALL_EXCEPTION";
60
- Errors2["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
61
- Errors2["NONCE_EXPIRED"] = "NONCE_EXPIRED";
62
- Errors2["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
63
- Errors2["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
64
- Errors2["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
65
- Errors2["ACTION_REJECTED"] = "ACTION_REJECTED";
66
- return Errors2;
67
- })(Errors || {});
68
-
69
- // src/hash.ts
70
- var import_ethers = __toESM(require_ethers(), 1);
71
- function idprefix(errorCallString) {
72
- return (0, import_ethers.id)(errorCallString).slice(0, 10);
73
- }
74
-
75
- // ../util-core/src/number/index.ts
76
- var import_bignumber = __toESM(require_bignumber(), 1);
77
-
78
- // ../util-core/src/util/serialized.ts
79
- function numberish(value) {
80
- if (value === void 0 || value === null)
81
- return "0";
82
- if (Number.isNaN(Number(value)))
83
- return "0";
84
- return value.toString();
85
- }
86
-
87
- // ../util-core/src/number/index.ts
88
- var DEFAULT_BIGNUM_CONFIG = {
89
- ROUNDING_MODE: import_bignumber.default.ROUND_UP,
90
- DECIMAL_PLACES: 6
91
- };
92
- var Bignumber = import_bignumber.default.clone(DEFAULT_BIGNUM_CONFIG);
93
- var BIG_INTS = {
94
- t: { v: 10 ** 12, d: 13, n: "t" },
95
- b: { v: 10 ** 9, d: 10, n: "b" },
96
- m: { v: 10 ** 6, d: 7, n: "m" },
97
- k: { v: 10 ** 3, d: 4, n: "k" }
98
- };
99
- function bignumber(n = "0", base) {
100
- return new Bignumber(numberish(n), base);
101
- }
102
- bignumber.clone = function(config) {
103
- return Bignumber.clone({ ...DEFAULT_BIGNUM_CONFIG, ...config });
104
- };
105
- function gte(a, b) {
106
- return bignumber(a).gte(bignumber(b));
107
- }
108
- function lt(a, b) {
109
- return bignumber(a).lt(bignumber(b));
110
- }
111
- function zeroRemove(value, convert = true) {
112
- const _value = convert ? numberish(value) : value || "";
113
- return _value.toString().replace(/\.?0+$/, "");
114
- }
115
- function parseNumeric(num, delimiters = ["t", "b", "m"]) {
116
- const mappings = [
117
- delimiters.includes("t") && ((n) => gte(n, BIG_INTS.t.v) && BIG_INTS.t),
118
- delimiters.includes("b") && ((n) => gte(n, BIG_INTS.b.v) && lt(n, BIG_INTS.t.v) && BIG_INTS.b),
119
- delimiters.includes("m") && ((n) => gte(n, BIG_INTS.m.v) && lt(n, BIG_INTS.b.v) && BIG_INTS.m),
120
- delimiters.includes("k") && ((n) => gte(n, BIG_INTS.k.v) && lt(n, BIG_INTS.m.v) && BIG_INTS.k)
121
- ];
122
- let options;
123
- for (const analy of mappings) {
124
- const opts = analy && analy(bignumber(num).toFixed(0));
125
- opts && (options = opts);
126
- }
127
- return options || { v: 1, d: 0, n: "" };
128
- }
129
- function formatNumeric(value = "0", options) {
130
- if (options?.default && bignumber(value).isZero())
131
- return options?.default;
132
- const {
133
- rounding = Bignumber.ROUND_DOWN,
134
- delimiters,
135
- format,
136
- decimals = 2
137
- } = options || {};
138
- const config = parseNumeric(value, delimiters || []);
139
- let number = bignumber(value).div(config.v).toFormat(decimals, rounding, {
140
- decimalSeparator: ".",
141
- groupSeparator: ",",
142
- groupSize: 3,
143
- secondaryGroupSize: 0,
144
- fractionGroupSeparator: " ",
145
- fractionGroupSize: 0,
146
- ...format
147
- });
148
- number = options?.decimalsZero === false ? zeroRemove(number, false) : number;
149
- return `${number}${config.n}`;
150
- }
151
-
152
- // src/number.ts
153
- var import_ethers2 = __toESM(require_ethers(), 1);
154
- function formatEther(value = "0", options = {}) {
155
- const { separator = false, decimals, delimiters = false, rounding, decimalsZero = true, default: _default } = options;
156
- const number = (0, import_ethers2.formatEther)(bignumber(value).toFixed(0));
157
- const groupSeparator = separator === false ? "" : ",";
158
- return formatNumeric(number, {
159
- format: { groupSeparator, ...options.format },
160
- delimiters: typeof delimiters === "boolean" ? delimiters && ["m", "b", "t"] : delimiters,
161
- default: _default,
162
- decimals,
163
- rounding,
164
- decimalsZero
165
- });
166
- }
167
-
168
- // ../../node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.mjs
169
- function mitt_default(n) {
170
- return { all: n = n || /* @__PURE__ */ new Map(), on: function(t, e) {
171
- var i = n.get(t);
172
- i ? i.push(e) : n.set(t, [e]);
173
- }, off: function(t, e) {
174
- var i = n.get(t);
175
- i && (e ? i.splice(i.indexOf(e) >>> 0, 1) : n.set(t, []));
176
- }, emit: function(t, e) {
177
- var i = n.get(t);
178
- i && i.slice().map(function(n2) {
179
- n2(e);
180
- }), (i = n.get("*")) && i.slice().map(function(n2) {
181
- n2(t, e);
182
- });
183
- } };
184
- }
185
-
186
- // src/wait.ts
187
- var emitter = mitt_default();
188
- async function wait(transaction) {
189
- try {
190
- emitter.emit("before");
191
- if (typeof transaction === "function")
192
- transaction = await transaction();
193
- if (transaction instanceof Promise)
194
- transaction = await transaction;
195
- const receipt = await transaction.getTransaction().then((transaction2) => transaction2?.wait());
196
- emitter.emit("after", receipt);
197
- return receipt;
198
- } catch (error) {
199
- emitter.emit("after", null);
200
- emitter.emit("error", error);
201
- throw error;
202
- }
203
- }
204
- wait.subscribe = emitter.on.bind(emitter);
205
- })();
package/dist/index.js DELETED
@@ -1,73 +0,0 @@
1
- // src/constants.ts
2
- var Errors = /* @__PURE__ */ ((Errors2) => {
3
- Errors2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
4
- Errors2["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
5
- Errors2["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
6
- Errors2["NETWORK_ERROR"] = "NETWORK_ERROR";
7
- Errors2["SERVER_ERROR"] = "SERVER_ERROR";
8
- Errors2["TIMEOUT"] = "TIMEOUT";
9
- Errors2["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
10
- Errors2["NUMERIC_FAULT"] = "NUMERIC_FAULT";
11
- Errors2["MISSING_NEW"] = "MISSING_NEW";
12
- Errors2["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
13
- Errors2["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
14
- Errors2["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
15
- Errors2["CALL_EXCEPTION"] = "CALL_EXCEPTION";
16
- Errors2["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
17
- Errors2["NONCE_EXPIRED"] = "NONCE_EXPIRED";
18
- Errors2["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
19
- Errors2["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
20
- Errors2["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
21
- Errors2["ACTION_REJECTED"] = "ACTION_REJECTED";
22
- return Errors2;
23
- })(Errors || {});
24
-
25
- // src/hash.ts
26
- import { id } from "ethers";
27
- function idprefix(errorCallString) {
28
- return id(errorCallString).slice(0, 10);
29
- }
30
-
31
- // src/number.ts
32
- import { bignumber, formatNumeric } from "@hairy/utils";
33
- import { formatEther as _formatEther } from "ethers";
34
- function formatEther(value = "0", options = {}) {
35
- const { separator = false, decimals, delimiters = false, rounding, decimalsZero = true, default: _default } = options;
36
- const number = _formatEther(bignumber(value).toFixed(0));
37
- const groupSeparator = separator === false ? "" : ",";
38
- return formatNumeric(number, {
39
- format: { groupSeparator, ...options.format },
40
- delimiters: typeof delimiters === "boolean" ? delimiters && ["m", "b", "t"] : delimiters,
41
- default: _default,
42
- decimals,
43
- rounding,
44
- decimalsZero
45
- });
46
- }
47
-
48
- // src/wait.ts
49
- import mitt from "mitt";
50
- var emitter = mitt();
51
- async function wait(transaction) {
52
- try {
53
- emitter.emit("before");
54
- if (typeof transaction === "function")
55
- transaction = await transaction();
56
- if (transaction instanceof Promise)
57
- transaction = await transaction;
58
- const receipt = await transaction.getTransaction().then((transaction2) => transaction2?.wait());
59
- emitter.emit("after", receipt);
60
- return receipt;
61
- } catch (error) {
62
- emitter.emit("after", null);
63
- emitter.emit("error", error);
64
- throw error;
65
- }
66
- }
67
- wait.subscribe = emitter.on.bind(emitter);
68
- export {
69
- Errors,
70
- formatEther,
71
- idprefix,
72
- wait
73
- };