essential-eth 0.6.2 → 0.8.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.
Files changed (119) hide show
  1. package/dist/cjs/classes/Contract.js +307 -66
  2. package/dist/cjs/classes/test/Contract/crv-abi.js +252 -256
  3. package/dist/cjs/classes/test/Contract/crv.test.js +690 -0
  4. package/dist/cjs/classes/test/Contract/ens-abi.js +497 -212
  5. package/dist/cjs/classes/test/Contract/ens.test.js +217 -0
  6. package/dist/cjs/classes/test/Contract/fei-abi.js +605 -284
  7. package/dist/cjs/classes/test/Contract/fei.test.js +224 -0
  8. package/dist/cjs/classes/test/Contract/foo-abi.js +44 -21
  9. package/dist/cjs/classes/test/Contract/foo.test.js +33 -0
  10. package/dist/cjs/classes/test/Contract/uni.test.js +387 -0
  11. package/dist/cjs/classes/test/Contract/uniswap-abi.js +64 -68
  12. package/dist/cjs/classes/utils/clean-block.d.ts +1 -2
  13. package/dist/cjs/classes/utils/clean-block.js +52 -30
  14. package/dist/cjs/classes/utils/clean-log.js +42 -20
  15. package/dist/cjs/classes/utils/clean-transaction-receipt.js +51 -29
  16. package/dist/cjs/classes/utils/clean-transaction.js +52 -29
  17. package/dist/cjs/classes/utils/encode-decode-transaction.d.ts +1 -1
  18. package/dist/cjs/classes/utils/encode-decode-transaction.js +163 -83
  19. package/dist/cjs/classes/utils/fetchers.js +165 -41
  20. package/dist/cjs/classes/utils/hex-to-decimal.js +1 -6
  21. package/dist/cjs/classes/utils/prepare-transaction.js +59 -36
  22. package/dist/cjs/index.js +25 -54
  23. package/dist/cjs/index.umd.js +1 -1
  24. package/dist/cjs/index.umd.js.map +1 -1
  25. package/dist/cjs/logger/logger.js +79 -23
  26. package/dist/cjs/logger/package-version.d.ts +1 -1
  27. package/dist/cjs/logger/package-version.js +1 -4
  28. package/dist/cjs/providers/BaseProvider.d.ts +2 -0
  29. package/dist/cjs/providers/BaseProvider.js +883 -475
  30. package/dist/cjs/providers/FallthroughProvider.js +118 -37
  31. package/dist/cjs/providers/JsonRpcProvider.js +93 -28
  32. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +228 -0
  33. package/dist/cjs/providers/test/get-transaction-count.test.js +276 -0
  34. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +436 -0
  35. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +288 -0
  36. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +261 -0
  37. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +230 -0
  38. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +501 -0
  39. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +311 -0
  40. package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +212 -0
  41. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +202 -0
  42. package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +361 -0
  43. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +274 -0
  44. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +301 -0
  45. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +307 -0
  46. package/dist/cjs/providers/test/rpc-urls.js +9 -12
  47. package/dist/cjs/providers/utils/chains-info.js +1 -3
  48. package/dist/cjs/shared/tiny-big/helpers.js +93 -42
  49. package/dist/cjs/shared/tiny-big/helpers.test.js +29 -0
  50. package/dist/cjs/shared/tiny-big/tiny-big.js +161 -72
  51. package/dist/cjs/shared/tiny-big/tiny-big.test.js +34 -0
  52. package/dist/cjs/shared/validate-type.js +7 -7
  53. package/dist/cjs/types/Block.types.js +1 -2
  54. package/dist/cjs/types/Contract.types.js +1 -2
  55. package/dist/cjs/types/FeeData.types.d.ts +7 -0
  56. package/dist/cjs/types/FeeData.types.js +1 -0
  57. package/dist/cjs/types/Filter.types.js +1 -2
  58. package/dist/cjs/types/Network.types.js +3 -2
  59. package/dist/cjs/types/Transaction.types.js +1 -2
  60. package/dist/cjs/utils/bytes.js +286 -318
  61. package/dist/cjs/utils/compute-address.js +8 -14
  62. package/dist/cjs/utils/compute-public-key.js +5 -10
  63. package/dist/cjs/utils/ether-to-gwei.js +10 -11
  64. package/dist/cjs/utils/ether-to-wei.js +10 -11
  65. package/dist/cjs/utils/gwei-to-ether.js +10 -11
  66. package/dist/cjs/utils/hash-message.d.ts +1 -1
  67. package/dist/cjs/utils/hash-message.js +11 -14
  68. package/dist/cjs/utils/is-address.js +8 -12
  69. package/dist/cjs/utils/keccak256.js +8 -14
  70. package/dist/cjs/utils/solidity-keccak256.js +49 -60
  71. package/dist/cjs/utils/split-signature.js +55 -73
  72. package/dist/cjs/utils/tests/bytes/arrayify.test.js +40 -0
  73. package/dist/cjs/utils/tests/bytes/concat.test.js +15 -0
  74. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +63 -0
  75. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +49 -0
  76. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +52 -0
  77. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +58 -0
  78. package/dist/cjs/utils/tests/bytes/hex-value.test.js +85 -0
  79. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +62 -0
  80. package/dist/cjs/utils/tests/bytes/hexlify.test.js +62 -0
  81. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +69 -0
  82. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +33 -0
  83. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +88 -0
  84. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +57 -0
  85. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +80 -0
  86. package/dist/cjs/utils/tests/compute-address.test.js +27 -0
  87. package/dist/cjs/utils/tests/compute-public-key.test.js +15 -0
  88. package/dist/cjs/utils/tests/ether-to-gwei.test.js +26 -0
  89. package/dist/cjs/utils/tests/ether-to-wei.test.js +44 -0
  90. package/dist/cjs/utils/tests/gwei-to-ether.test.js +28 -0
  91. package/dist/cjs/utils/tests/hash-message.test.js +21 -0
  92. package/dist/cjs/utils/tests/is-address.test.js +55 -0
  93. package/dist/cjs/utils/tests/keccak256.test.js +97 -0
  94. package/dist/cjs/utils/tests/solidity-keccak256.test.js +310 -0
  95. package/dist/cjs/utils/tests/split-signature.test.js +25 -0
  96. package/dist/cjs/utils/tests/to-checksum-address.test.js +42 -0
  97. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +14 -0
  98. package/dist/cjs/utils/tests/wei-to-ether.test.js +51 -0
  99. package/dist/cjs/utils/to-checksum-address.js +15 -20
  100. package/dist/cjs/utils/to-utf8-bytes.js +1 -6
  101. package/dist/cjs/utils/wei-to-ether.js +13 -15
  102. package/dist/esm/classes/utils/clean-block.d.ts +1 -2
  103. package/dist/esm/classes/utils/clean-block.js +1 -1
  104. package/dist/esm/classes/utils/clean-transaction-receipt.js +2 -1
  105. package/dist/esm/classes/utils/clean-transaction.js +2 -1
  106. package/dist/esm/classes/utils/encode-decode-transaction.d.ts +1 -1
  107. package/dist/esm/classes/utils/encode-decode-transaction.js +37 -2
  108. package/dist/esm/logger/package-version.d.ts +1 -1
  109. package/dist/esm/logger/package-version.js +1 -1
  110. package/dist/esm/providers/BaseProvider.d.ts +2 -0
  111. package/dist/esm/providers/BaseProvider.js +15 -0
  112. package/dist/esm/types/FeeData.types.d.ts +7 -0
  113. package/dist/esm/types/FeeData.types.js +1 -0
  114. package/dist/esm/utils/compute-address.js +2 -1
  115. package/dist/esm/utils/hash-message.d.ts +1 -1
  116. package/dist/esm/utils/hash-message.js +3 -1
  117. package/dist/esm/utils/is-address.js +1 -1
  118. package/package.json +10 -8
  119. package/readme.md +63 -3
@@ -1,89 +1,180 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ function _assertThisInitialized(self) {
2
+ if (self === void 0) {
3
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4
+ }
5
+ return self;
6
+ }
7
+ function _classCallCheck(instance, Constructor) {
8
+ if (!(instance instanceof Constructor)) {
9
+ throw new TypeError("Cannot call a class as a function");
10
+ }
11
+ }
12
+ function _get(target, property, receiver) {
13
+ if (typeof Reflect !== "undefined" && Reflect.get) {
14
+ _get = Reflect.get;
15
+ } else {
16
+ _get = function _get(target, property, receiver) {
17
+ var base = _superPropBase(target, property);
18
+ if (!base) return;
19
+ var desc = Object.getOwnPropertyDescriptor(base, property);
20
+ if (desc.get) {
21
+ return desc.get.call(receiver);
22
+ }
23
+ return desc.value;
24
+ };
25
+ }
26
+ return _get(target, property, receiver || target);
27
+ }
28
+ function _getPrototypeOf(o) {
29
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
30
+ return o.__proto__ || Object.getPrototypeOf(o);
31
+ };
32
+ return _getPrototypeOf(o);
33
+ }
34
+ function _inherits(subClass, superClass) {
35
+ if (typeof superClass !== "function" && superClass !== null) {
36
+ throw new TypeError("Super expression must either be null or a function");
37
+ }
38
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
39
+ constructor: {
40
+ value: subClass,
41
+ writable: true,
42
+ configurable: true
43
+ }
44
+ });
45
+ if (superClass) _setPrototypeOf(subClass, superClass);
46
+ }
47
+ function _possibleConstructorReturn(self, call) {
48
+ if (call && (_typeof(call) === "object" || typeof call === "function")) {
49
+ return call;
50
+ }
51
+ return _assertThisInitialized(self);
52
+ }
53
+ function _setPrototypeOf(o, p) {
54
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
55
+ o.__proto__ = p;
56
+ return o;
57
+ };
58
+ return _setPrototypeOf(o, p);
59
+ }
60
+ function _superPropBase(object, property) {
61
+ while(!Object.prototype.hasOwnProperty.call(object, property)){
62
+ object = _getPrototypeOf(object);
63
+ if (object === null) break;
64
+ }
65
+ return object;
66
+ }
67
+ var _typeof = function(obj) {
68
+ "@swc/helpers - typeof";
69
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
4
70
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.tinyBig = exports.TinyBig = void 0;
7
- const big_js_1 = __importDefault(require("big.js"));
8
- const hex_to_decimal_1 = require("../../classes/utils/hex-to-decimal");
9
- const helpers_1 = require("./helpers");
71
+ function _isNativeReflectConstruct() {
72
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
73
+ if (Reflect.construct.sham) return false;
74
+ if (typeof Proxy === "function") return true;
75
+ try {
76
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
77
+ return true;
78
+ } catch (e) {
79
+ return false;
80
+ }
81
+ }
82
+ function _createSuper(Derived) {
83
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
84
+ return function _createSuperInternal() {
85
+ var Super = _getPrototypeOf(Derived), result;
86
+ if (hasNativeReflectConstruct) {
87
+ var NewTarget = _getPrototypeOf(this).constructor;
88
+ result = Reflect.construct(Super, arguments, NewTarget);
89
+ } else {
90
+ result = Super.apply(this, arguments);
91
+ }
92
+ return _possibleConstructorReturn(this, result);
93
+ };
94
+ }
95
+ import Big from "big.js";
96
+ import { hexToDecimal } from "../../classes/utils/hex-to-decimal";
97
+ import { scientificStrToDecimalStr } from "./helpers";
10
98
  /**
11
99
  * A wrapper around [big.js](https://github.com/MikeMcl/big.js) which expands scientific notation and creates a "toHexString" function.
12
100
  * This is the return type of every operation on ether, wei, etc.
13
- */
14
- class TinyBig extends big_js_1.default {
15
- constructor(value) {
16
- if (typeof value === 'string' && value.startsWith('0x')) {
17
- value = (0, hex_to_decimal_1.hexToDecimal)(value);
101
+ */ export var TinyBig = /*#__PURE__*/ function(Big) {
102
+ "use strict";
103
+ _inherits(TinyBig, Big);
104
+ var _super = _createSuper(TinyBig);
105
+ function TinyBig(value) {
106
+ _classCallCheck(this, TinyBig);
107
+ var _this;
108
+ if (typeof value === "string" && value.startsWith("0x")) {
109
+ value = hexToDecimal(value);
18
110
  }
19
- super(value);
111
+ _this = _super.call(this, value);
20
112
  /**
21
- * Eithers pads or shortens a string to a specified length
22
- *
23
- * @param str the string to pad or chop
24
- * @param padChar the character to pad the string with
25
- * @param length the desired length of the given string
26
- * @returns a string of the desired length, either padded with the specified padChar or with the beginning of the string chopped off
27
- * @example
28
- * ```javascript
29
- * padAndChop('essential-eth', 'a', 8);
30
- * // 'tial-eth'
31
- * ```
32
- * @example
33
- * ```javascript
34
- * padAndChop('essential-eth', 'A', 20);
35
- * // 'AAAAAAAessential-eth'
36
- * ```
37
- */
38
- this.padAndChop = (str, padChar, length) => {
39
- return (Array(length).fill(padChar).join('') + str).slice(length * -1);
113
+ * Eithers pads or shortens a string to a specified length
114
+ *
115
+ * @param str the string to pad or chop
116
+ * @param padChar the character to pad the string with
117
+ * @param length the desired length of the given string
118
+ * @returns a string of the desired length, either padded with the specified padChar or with the beginning of the string chopped off
119
+ * @example
120
+ * ```javascript
121
+ * padAndChop('essential-eth', 'a', 8);
122
+ * // 'tial-eth'
123
+ * ```
124
+ * @example
125
+ * ```javascript
126
+ * padAndChop('essential-eth', 'A', 20);
127
+ * // 'AAAAAAAessential-eth'
128
+ * ```
129
+ */ _this.padAndChop = function(str, padChar, length) {
130
+ return (Array(length).fill(padChar).join("") + str).slice(length * -1);
40
131
  };
132
+ return _this;
41
133
  }
134
+ var _proto = TinyBig.prototype;
42
135
  /**
43
- * Used anytime you're passing in "value" to ethers or web3
44
- * For now, TypeScript will complain that `TinyBig` is not a `BigNumberish`. You can // @ts-ignore or call this
45
- *
46
- * @returns the TinyBig represented as a hex string
47
- * @example
48
- * ```javascript
49
- * tinyBig(293).toHexString();
50
- * // '0x125'
51
- * ```
52
- * @example
53
- * ```javascript
54
- * tinyBig(681365874).toHexString();
55
- * // '0x289cd172'
56
- */
57
- toHexString() {
58
- return `0x${BigInt(this.toString()).toString(16)}`;
59
- }
60
- toNumber() {
61
- return Number((0, helpers_1.scientificStrToDecimalStr)(super.toString()));
62
- }
63
- toString() {
136
+ * Used anytime you're passing in "value" to ethers or web3
137
+ * For now, TypeScript will complain that `TinyBig` is not a `BigNumberish`. You can // @ts-ignore or call this
138
+ *
139
+ * @returns the TinyBig represented as a hex string
140
+ * @example
141
+ * ```javascript
142
+ * tinyBig(293).toHexString();
143
+ * // '0x125'
144
+ * ```
145
+ * @example
146
+ * ```javascript
147
+ * tinyBig(681365874).toHexString();
148
+ * // '0x289cd172'
149
+ */ _proto.toHexString = function toHexString() {
150
+ return "0x".concat(BigInt(this.toString()).toString(16));
151
+ };
152
+ _proto.toNumber = function toNumber() {
153
+ return Number(scientificStrToDecimalStr(_get(_getPrototypeOf(TinyBig.prototype), "toString", this).call(this)));
154
+ };
155
+ _proto.toString = function toString() {
64
156
  if (this.toNumber() === 0) {
65
- return '0';
157
+ return "0";
66
158
  }
67
- return (0, helpers_1.scientificStrToDecimalStr)(super.toString());
68
- }
69
- toTwos(bitCount) {
70
- let binaryStr;
159
+ return scientificStrToDecimalStr(_get(_getPrototypeOf(TinyBig.prototype), "toString", this).call(this));
160
+ };
161
+ _proto.toTwos = function toTwos(bitCount) {
162
+ var binaryStr;
71
163
  if (this.gte(0)) {
72
- const twosComp = this.toNumber().toString(2);
73
- binaryStr = this.padAndChop(twosComp, '0', bitCount || twosComp.length);
74
- }
75
- else {
164
+ var twosComp = this.toNumber().toString(2);
165
+ binaryStr = this.padAndChop(twosComp, "0", bitCount || twosComp.length);
166
+ } else {
76
167
  binaryStr = this.plus(Math.pow(2, bitCount)).toNumber().toString(2);
77
168
  if (Number(binaryStr) < 0) {
78
- throw new Error('Cannot calculate twos complement');
169
+ throw new Error("Cannot calculate twos complement");
79
170
  }
80
171
  }
81
- const binary = `0b${binaryStr}`;
82
- const decimal = Number(binary);
172
+ var binary = "0b".concat(binaryStr);
173
+ var decimal = Number(binary);
83
174
  return tinyBig(decimal);
84
- }
85
- }
86
- exports.TinyBig = TinyBig;
175
+ };
176
+ return TinyBig;
177
+ }(Big);
87
178
  /**
88
179
  * Helper factory function so that you don't have to type "new" when instantiating a new TinyBig
89
180
  *
@@ -94,8 +185,6 @@ exports.TinyBig = TinyBig;
94
185
  * tinyBig(10).times(3).toNumber()
95
186
  * // 30
96
187
  * ```
97
- */
98
- function tinyBig(value) {
188
+ */ export function tinyBig(value) {
99
189
  return new TinyBig(value);
100
190
  }
101
- exports.tinyBig = tinyBig;
@@ -0,0 +1,34 @@
1
+ import { BigNumber } from "ethers";
2
+ import { tinyBig } from "./tiny-big";
3
+ describe("tiny-big", function() {
4
+ it("allows hex string input", function() {
5
+ expect(tinyBig("0xa").toString()).toBe("10");
6
+ expect(tinyBig("10").toString()).toBe("10");
7
+ });
8
+ it("performs toHexString properly", function() {
9
+ expect(tinyBig(0).toHexString()).toBe("0x0");
10
+ expect(tinyBig(1).toHexString()).toBe("0x1");
11
+ expect(tinyBig(15).toHexString()).toBe("0xf");
12
+ expect(tinyBig(16).toHexString()).toBe("0x10");
13
+ });
14
+ it("performs twosComplement", function() {
15
+ var inputs = [
16
+ {
17
+ num: -3,
18
+ bitCount: 3
19
+ },
20
+ {
21
+ num: 0,
22
+ bitCount: 3
23
+ },
24
+ {
25
+ num: 3,
26
+ bitCount: 3
27
+ }
28
+ ];
29
+ inputs.forEach(function(param) {
30
+ var num = param.num, bitCount = param.bitCount;
31
+ expect(tinyBig(num).toTwos(bitCount).toString()).toBe(BigNumber.from(num).toTwos(bitCount).toString());
32
+ });
33
+ });
34
+ });
@@ -1,9 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateType = void 0;
4
- const validateType = (value, allowedTypes) => {
5
- if (!allowedTypes.includes(typeof value)) {
6
- throw new Error(`${allowedTypes.join(' or ')} required. Received ${typeof value}`);
1
+ var _typeof = function(obj) {
2
+ "@swc/helpers - typeof";
3
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
4
+ };
5
+ export var validateType = function(value, allowedTypes) {
6
+ if (!allowedTypes.includes(typeof value === "undefined" ? "undefined" : _typeof(value))) {
7
+ throw new Error("".concat(allowedTypes.join(" or "), " required. Received ").concat(typeof value === "undefined" ? "undefined" : _typeof(value)));
7
8
  }
8
9
  };
9
- exports.validateType = validateType;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export { }; /* block number as hex string '0x0' */
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export { };
@@ -0,0 +1,7 @@
1
+ import type { TinyBig } from '../shared/tiny-big/tiny-big';
2
+ export interface FeeData {
3
+ gasPrice: TinyBig;
4
+ lastBaseFeePerGas: TinyBig | null;
5
+ maxFeePerGas: TinyBig | null;
6
+ maxPriorityFeePerGas: TinyBig | null;
7
+ }
@@ -0,0 +1 @@
1
+ export { };
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export { };
@@ -1,2 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ /**
2
+ * A trimmed version of https://chainid.network/chains.json
3
+ */ export { };
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export { };