essential-eth 0.5.11-next.1 → 0.5.12

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 (185) hide show
  1. package/lib/cjs/classes/Contract.d.ts +78 -0
  2. package/lib/cjs/classes/Contract.js +140 -0
  3. package/{dist → lib/cjs}/classes/test/Contract/crv-abi.d.ts +2 -2
  4. package/lib/cjs/classes/test/Contract/crv-abi.js +488 -0
  5. package/{dist → lib/cjs}/classes/test/Contract/ens-abi.d.ts +2 -2
  6. package/lib/cjs/classes/test/Contract/ens-abi.js +453 -0
  7. package/{dist → lib/cjs}/classes/test/Contract/fei-abi.d.ts +2 -2
  8. package/lib/cjs/classes/test/Contract/fei-abi.js +526 -0
  9. package/{dist → lib/cjs}/classes/test/Contract/foo-abi.d.ts +2 -2
  10. package/lib/cjs/classes/test/Contract/foo-abi.js +42 -0
  11. package/{dist → lib/cjs}/classes/test/Contract/uniswap-abi.d.ts +2 -2
  12. package/lib/cjs/classes/test/Contract/uniswap-abi.js +121 -0
  13. package/lib/cjs/classes/utils/clean-block.d.ts +121 -0
  14. package/lib/cjs/classes/utils/clean-block.js +160 -0
  15. package/lib/cjs/classes/utils/clean-log.d.ts +9 -0
  16. package/lib/cjs/classes/utils/clean-log.js +37 -0
  17. package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +14 -0
  18. package/lib/cjs/classes/utils/clean-transaction-receipt.js +50 -0
  19. package/lib/cjs/classes/utils/clean-transaction.d.ts +14 -0
  20. package/lib/cjs/classes/utils/clean-transaction.js +51 -0
  21. package/lib/cjs/classes/utils/encode-decode-transaction.d.ts +16 -0
  22. package/lib/cjs/classes/utils/encode-decode-transaction.js +137 -0
  23. package/lib/cjs/classes/utils/fetchers.d.ts +39 -0
  24. package/lib/cjs/classes/utils/fetchers.js +81 -0
  25. package/lib/cjs/classes/utils/hex-to-decimal.d.ts +18 -0
  26. package/lib/cjs/classes/utils/hex-to-decimal.js +24 -0
  27. package/lib/cjs/classes/utils/prepare-transaction.d.ts +6 -0
  28. package/lib/cjs/classes/utils/prepare-transaction.js +45 -0
  29. package/{dist → lib/cjs}/index.d.ts +25 -25
  30. package/lib/cjs/index.js +54 -0
  31. package/{dist → lib/cjs}/logger/logger.d.ts +11 -11
  32. package/lib/cjs/logger/logger.js +36 -0
  33. package/lib/cjs/logger/package-version.d.ts +1 -0
  34. package/lib/cjs/logger/package-version.js +5 -0
  35. package/lib/cjs/providers/BaseProvider.d.ts +353 -0
  36. package/lib/cjs/providers/BaseProvider.js +512 -0
  37. package/lib/cjs/providers/FallthroughProvider.d.ts +24 -0
  38. package/lib/cjs/providers/FallthroughProvider.js +65 -0
  39. package/lib/cjs/providers/JsonRpcProvider.d.ts +33 -0
  40. package/lib/cjs/providers/JsonRpcProvider.js +46 -0
  41. package/{dist → lib/cjs}/providers/test/rpc-urls.d.ts +11 -11
  42. package/lib/cjs/providers/test/rpc-urls.js +14 -0
  43. package/{dist → lib/cjs}/providers/utils/chains-info.d.ts +467 -467
  44. package/lib/cjs/providers/utils/chains-info.js +1402 -0
  45. package/lib/cjs/shared/tiny-big/helpers.d.ts +17 -0
  46. package/lib/cjs/shared/tiny-big/helpers.js +97 -0
  47. package/lib/cjs/shared/tiny-big/tiny-big.d.ts +58 -0
  48. package/lib/cjs/shared/tiny-big/tiny-big.js +101 -0
  49. package/{dist → lib/cjs}/shared/validate-type.d.ts +3 -3
  50. package/lib/cjs/shared/validate-type.js +9 -0
  51. package/{dist → lib/cjs}/types/Block.types.d.ts +41 -40
  52. package/lib/cjs/types/Block.types.js +2 -0
  53. package/{dist → lib/cjs}/types/Contract.types.d.ts +24 -24
  54. package/lib/cjs/types/Contract.types.js +2 -0
  55. package/lib/cjs/types/Filter.types.d.ts +16 -0
  56. package/lib/cjs/types/Filter.types.js +2 -0
  57. package/lib/cjs/types/Network.types.d.ts +8 -0
  58. package/lib/cjs/types/Network.types.js +2 -0
  59. package/lib/cjs/types/Transaction.types.d.ts +123 -0
  60. package/lib/cjs/types/Transaction.types.js +2 -0
  61. package/lib/cjs/utils/bytes.d.ts +289 -0
  62. package/lib/cjs/utils/bytes.js +711 -0
  63. package/lib/cjs/utils/compute-address.d.ts +17 -0
  64. package/lib/cjs/utils/compute-address.js +33 -0
  65. package/lib/cjs/utils/compute-public-key.d.ts +18 -0
  66. package/lib/cjs/utils/compute-public-key.js +26 -0
  67. package/lib/cjs/utils/ether-to-gwei.d.ts +27 -0
  68. package/lib/cjs/utils/ether-to-gwei.js +35 -0
  69. package/lib/cjs/utils/ether-to-wei.d.ts +27 -0
  70. package/lib/cjs/utils/ether-to-wei.js +35 -0
  71. package/lib/cjs/utils/gwei-to-ether.d.ts +27 -0
  72. package/lib/cjs/utils/gwei-to-ether.js +35 -0
  73. package/lib/cjs/utils/hash-message.d.ts +14 -0
  74. package/lib/cjs/utils/hash-message.js +28 -0
  75. package/lib/cjs/utils/is-address.d.ts +24 -0
  76. package/lib/cjs/utils/is-address.js +39 -0
  77. package/lib/cjs/utils/keccak256.d.ts +16 -0
  78. package/lib/cjs/utils/keccak256.js +31 -0
  79. package/lib/cjs/utils/solidity-keccak256.d.ts +39 -0
  80. package/lib/cjs/utils/solidity-keccak256.js +138 -0
  81. package/lib/cjs/utils/split-signature.d.ts +24 -0
  82. package/lib/cjs/utils/split-signature.js +163 -0
  83. package/lib/cjs/utils/to-checksum-address.d.ts +17 -0
  84. package/lib/cjs/utils/to-checksum-address.js +46 -0
  85. package/lib/cjs/utils/to-utf8-bytes.d.ts +15 -0
  86. package/lib/cjs/utils/to-utf8-bytes.js +21 -0
  87. package/lib/cjs/utils/wei-to-ether.d.ts +27 -0
  88. package/lib/cjs/utils/wei-to-ether.js +45 -0
  89. package/{dist → lib/esm}/classes/Contract.d.ts +11 -11
  90. package/lib/esm/classes/Contract.js +65 -0
  91. package/lib/esm/classes/test/Contract/crv-abi.d.ts +2 -0
  92. package/lib/esm/classes/test/Contract/crv-abi.js +470 -0
  93. package/lib/esm/classes/test/Contract/ens-abi.d.ts +2 -0
  94. package/lib/esm/classes/test/Contract/ens-abi.js +435 -0
  95. package/lib/esm/classes/test/Contract/fei-abi.d.ts +2 -0
  96. package/lib/esm/classes/test/Contract/fei-abi.js +521 -0
  97. package/lib/esm/classes/test/Contract/foo-abi.d.ts +2 -0
  98. package/lib/esm/classes/test/Contract/foo-abi.js +33 -0
  99. package/lib/esm/classes/test/Contract/uniswap-abi.d.ts +2 -0
  100. package/lib/esm/classes/test/Contract/uniswap-abi.js +116 -0
  101. package/{dist → lib/esm}/classes/utils/clean-block.d.ts +3 -3
  102. package/lib/esm/classes/utils/clean-block.js +35 -0
  103. package/{dist → lib/esm}/classes/utils/clean-log.d.ts +2 -2
  104. package/lib/esm/classes/utils/clean-log.js +26 -0
  105. package/{dist → lib/esm}/classes/utils/clean-transaction-receipt.d.ts +2 -2
  106. package/lib/esm/classes/utils/clean-transaction-receipt.js +34 -0
  107. package/{dist → lib/esm}/classes/utils/clean-transaction.d.ts +2 -2
  108. package/lib/esm/classes/utils/clean-transaction.js +33 -0
  109. package/{dist → lib/esm}/classes/utils/encode-decode-transaction.d.ts +4 -4
  110. package/lib/esm/classes/utils/encode-decode-transaction.js +98 -0
  111. package/{dist → lib/esm}/classes/utils/fetchers.d.ts +9 -9
  112. package/lib/esm/classes/utils/fetchers.js +43 -0
  113. package/{dist → lib/esm}/classes/utils/hex-to-decimal.d.ts +1 -1
  114. package/lib/esm/classes/utils/hex-to-decimal.js +3 -0
  115. package/{dist → lib/esm}/classes/utils/prepare-transaction.d.ts +2 -2
  116. package/lib/esm/classes/utils/prepare-transaction.js +34 -0
  117. package/lib/esm/index.d.ts +25 -0
  118. package/lib/esm/index.js +20 -0
  119. package/lib/esm/logger/logger.d.ts +11 -0
  120. package/lib/esm/logger/logger.js +33 -0
  121. package/lib/esm/logger/package-version.d.ts +1 -0
  122. package/lib/esm/logger/package-version.js +1 -0
  123. package/{dist → lib/esm}/providers/BaseProvider.d.ts +24 -24
  124. package/lib/esm/providers/BaseProvider.js +157 -0
  125. package/{dist → lib/esm}/providers/FallthroughProvider.d.ts +11 -11
  126. package/lib/esm/providers/FallthroughProvider.js +41 -0
  127. package/{dist → lib/esm}/providers/JsonRpcProvider.d.ts +7 -7
  128. package/lib/esm/providers/JsonRpcProvider.js +15 -0
  129. package/lib/esm/providers/test/rpc-urls.d.ts +11 -0
  130. package/lib/esm/providers/test/rpc-urls.js +11 -0
  131. package/lib/esm/providers/utils/chains-info.d.ts +467 -0
  132. package/lib/esm/providers/utils/chains-info.js +1398 -0
  133. package/{dist → lib/esm}/shared/tiny-big/helpers.d.ts +1 -1
  134. package/lib/esm/shared/tiny-big/helpers.js +58 -0
  135. package/{dist → lib/esm}/shared/tiny-big/tiny-big.d.ts +10 -10
  136. package/lib/esm/shared/tiny-big/tiny-big.js +45 -0
  137. package/lib/esm/shared/validate-type.d.ts +3 -0
  138. package/lib/esm/shared/validate-type.js +5 -0
  139. package/lib/esm/types/Block.types.d.ts +40 -0
  140. package/lib/esm/types/Block.types.js +1 -0
  141. package/lib/esm/types/Contract.types.d.ts +24 -0
  142. package/lib/esm/types/Contract.types.js +1 -0
  143. package/{dist → lib/esm}/types/Filter.types.d.ts +12 -12
  144. package/lib/esm/types/Filter.types.js +1 -0
  145. package/{dist → lib/esm}/types/Network.types.d.ts +5 -5
  146. package/lib/esm/types/Network.types.js +1 -0
  147. package/{dist → lib/esm}/types/Transaction.types.d.ts +113 -113
  148. package/lib/esm/types/Transaction.types.js +1 -0
  149. package/{dist → lib/esm}/utils/bytes.d.ts +40 -40
  150. package/lib/esm/utils/bytes.js +245 -0
  151. package/{dist → lib/esm}/utils/compute-address.d.ts +1 -1
  152. package/lib/esm/utils/compute-address.js +11 -0
  153. package/{dist → lib/esm}/utils/compute-public-key.d.ts +2 -2
  154. package/lib/esm/utils/compute-public-key.js +6 -0
  155. package/{dist → lib/esm}/utils/ether-to-gwei.d.ts +3 -3
  156. package/lib/esm/utils/ether-to-gwei.js +7 -0
  157. package/{dist → lib/esm}/utils/ether-to-wei.d.ts +3 -3
  158. package/lib/esm/utils/ether-to-wei.js +7 -0
  159. package/{dist → lib/esm}/utils/gwei-to-ether.d.ts +3 -3
  160. package/lib/esm/utils/gwei-to-ether.js +7 -0
  161. package/{dist → lib/esm}/utils/hash-message.d.ts +2 -2
  162. package/lib/esm/utils/hash-message.js +12 -0
  163. package/{dist → lib/esm}/utils/is-address.d.ts +1 -1
  164. package/lib/esm/utils/is-address.js +12 -0
  165. package/{dist → lib/esm}/utils/keccak256.d.ts +2 -2
  166. package/lib/esm/utils/keccak256.js +13 -0
  167. package/{dist → lib/esm}/utils/solidity-keccak256.d.ts +2 -2
  168. package/lib/esm/utils/solidity-keccak256.js +85 -0
  169. package/{dist → lib/esm}/utils/split-signature.d.ts +2 -2
  170. package/lib/esm/utils/split-signature.js +126 -0
  171. package/{dist → lib/esm}/utils/to-checksum-address.d.ts +1 -1
  172. package/lib/esm/utils/to-checksum-address.js +25 -0
  173. package/{dist → lib/esm}/utils/to-utf8-bytes.d.ts +1 -1
  174. package/lib/esm/utils/to-utf8-bytes.js +3 -0
  175. package/{dist → lib/esm}/utils/wei-to-ether.d.ts +3 -3
  176. package/lib/esm/utils/wei-to-ether.js +16 -0
  177. package/package.json +14 -26
  178. package/readme.md +51 -66
  179. package/dist/index.js +0 -1904
  180. package/dist/index.js.map +0 -1
  181. package/dist/index.module.js +0 -1865
  182. package/dist/index.module.js.map +0 -1
  183. package/dist/index.umd.js +0 -2
  184. package/dist/index.umd.js.map +0 -1
  185. package/dist/logger/package-version.d.ts +0 -1
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Converts a string in scientific notation formatting to string in decimal format
3
+ *
4
+ * @param scientificString a string in scientific format to convert to decimal
5
+ * @returns a string of a decimal number equivalent to the specified scientificString
6
+ * @example
7
+ * ```javascript
8
+ * scientificStrToDecimalStr('2.3e-5');
9
+ * // '0.000023'
10
+ * ```
11
+ * @example
12
+ * ```javascript
13
+ * scientificStrToDecimalStr('2.3e+5');
14
+ * // '230000'
15
+ * ```
16
+ */
17
+ export declare function scientificStrToDecimalStr(scientificString: string): string;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scientificStrToDecimalStr = void 0;
4
+ /**
5
+ * Strips both leading and trailing zeroes from a number string
6
+ *
7
+ * @param numberString the string of numbers to strip zeros from
8
+ * @returns a string of numbers without leading or trailing zeros
9
+ * @example
10
+ * ```javascript
11
+ * stripTrailingZeros('0005280');
12
+ * // '5280'
13
+ * ```
14
+ */
15
+ function stripTrailingZeroes(numberString) {
16
+ const isNegative = numberString.startsWith('-');
17
+ numberString = numberString.replace('-', '');
18
+ numberString = numberString.replace(/\.0*$/g, '' /* for numbers like "1.0" -> "1" */);
19
+ numberString = numberString.replace(/^0+/, '');
20
+ // for numbers like "1.10" -> "1.1"
21
+ if (numberString.includes('.')) {
22
+ numberString = numberString.replace(/0+$/, '');
23
+ }
24
+ if (numberString.startsWith('.')) {
25
+ // so that ".1" returns as "0.1"
26
+ numberString = `0${numberString}`;
27
+ }
28
+ return `${isNegative ? '-' : ''}${numberString}`;
29
+ }
30
+ /**
31
+ * Converts a string in scientific notation formatting to string in decimal format
32
+ *
33
+ * @param scientificString a string in scientific format to convert to decimal
34
+ * @returns a string of a decimal number equivalent to the specified scientificString
35
+ * @example
36
+ * ```javascript
37
+ * scientificStrToDecimalStr('2.3e-5');
38
+ * // '0.000023'
39
+ * ```
40
+ * @example
41
+ * ```javascript
42
+ * scientificStrToDecimalStr('2.3e+5');
43
+ * // '230000'
44
+ * ```
45
+ */
46
+ function scientificStrToDecimalStr(scientificString) {
47
+ // Does not contain "e" nor "E"
48
+ if (!scientificString.match(/e/i /* lowercase and uppercase E */)) {
49
+ return stripTrailingZeroes(scientificString);
50
+ }
51
+ // eslint-disable-next-line prefer-const
52
+ let [base, power] = scientificString.split(/e/i /* lowercase and uppercase E */);
53
+ // remove the leading "-" if negative
54
+ const isNegative = Number(base) < 0;
55
+ base = base.replace('-', '');
56
+ base = stripTrailingZeroes(base);
57
+ const [wholeNumber, fraction /* move decimal this many places */ = ''] = base.split('.');
58
+ if (Number(power) === 0) {
59
+ return `${isNegative ? '-' : ''}${stripTrailingZeroes(base)}`;
60
+ }
61
+ else {
62
+ const includesDecimal = base.includes('.');
63
+ if (!includesDecimal) {
64
+ base = `${base}.`;
65
+ }
66
+ base = base.replace('.', '');
67
+ const baseLength = base.length;
68
+ let splitPaddedNumber;
69
+ if (Number(power) < 0) {
70
+ // move decimal left
71
+ if (wholeNumber.length < Math.abs(Number(power))) {
72
+ base = base.padStart(baseLength + Math.abs(Number(power)) - wholeNumber.length, '0');
73
+ }
74
+ splitPaddedNumber = base.split('');
75
+ if (wholeNumber.length < Math.abs(Number(power))) {
76
+ // starts with zeroes
77
+ splitPaddedNumber = ['.', ...splitPaddedNumber];
78
+ }
79
+ else {
80
+ splitPaddedNumber.splice(splitPaddedNumber.length - Math.abs(Number(power)), 0, '.');
81
+ }
82
+ }
83
+ else {
84
+ // move decimal right
85
+ if (fraction.length < Math.abs(Number(power))) {
86
+ base = base.padEnd(baseLength + Math.abs(Number(power)) - fraction.length, '0');
87
+ }
88
+ splitPaddedNumber = base.split('');
89
+ if (fraction.length > Math.abs(Number(power))) {
90
+ splitPaddedNumber.splice(splitPaddedNumber.length - Math.abs(Number(power)), 0, '.');
91
+ }
92
+ }
93
+ const toReturn = stripTrailingZeroes(splitPaddedNumber.join(''));
94
+ return `${isNegative ? '-' : ''}${toReturn}`;
95
+ }
96
+ }
97
+ exports.scientificStrToDecimalStr = scientificStrToDecimalStr;
@@ -0,0 +1,58 @@
1
+ import Big from 'big.js';
2
+ /**
3
+ * A wrapper around [big.js](https://github.com/MikeMcl/big.js) which expands scientific notation and creates a "toHexString" function.
4
+ * This is the return type of every operation on ether, wei, etc.
5
+ */
6
+ export declare class TinyBig extends Big {
7
+ constructor(value: string | number | TinyBig | Big);
8
+ /**
9
+ * Used anytime you're passing in "value" to ethers or web3
10
+ * For now, TypeScript will complain that `TinyBig` is not a `BigNumberish`. You can // @ts-ignore or call this
11
+ *
12
+ * @returns the TinyBig represented as a hex string
13
+ * @example
14
+ * ```javascript
15
+ * tinyBig(293).toHexString();
16
+ * // '0x125'
17
+ * ```
18
+ * @example
19
+ * ```javascript
20
+ * tinyBig(681365874).toHexString();
21
+ * // '0x289cd172'
22
+ */
23
+ toHexString(): string;
24
+ toNumber(): number;
25
+ toString(): string;
26
+ /**
27
+ * Eithers pads or shortens a string to a specified length
28
+ *
29
+ * @param str the string to pad or chop
30
+ * @param padChar the character to pad the string with
31
+ * @param length the desired length of the given string
32
+ * @returns a string of the desired length, either padded with the specified padChar or with the beginning of the string chopped off
33
+ * @example
34
+ * ```javascript
35
+ * padAndChop('essential-eth', 'a', 8);
36
+ * // 'tial-eth'
37
+ * ```
38
+ * @example
39
+ * ```javascript
40
+ * padAndChop('essential-eth', 'A', 20);
41
+ * // 'AAAAAAAessential-eth'
42
+ * ```
43
+ */
44
+ private padAndChop;
45
+ toTwos(bitCount: number): Big;
46
+ }
47
+ /**
48
+ * Helper factory function so that you don't have to type "new" when instantiating a new TinyBig
49
+ *
50
+ * @param value the value to initiate the TinyBig with
51
+ * @returns an initiated {@link TinyBig}
52
+ * @example
53
+ * ```javascript
54
+ * tinyBig(10).times(3).toNumber()
55
+ * // 30
56
+ * ```
57
+ */
58
+ export declare function tinyBig(value: string | number | TinyBig | Big): TinyBig;
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.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");
10
+ /**
11
+ * A wrapper around [big.js](https://github.com/MikeMcl/big.js) which expands scientific notation and creates a "toHexString" function.
12
+ * 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);
18
+ }
19
+ super(value);
20
+ /**
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);
40
+ };
41
+ }
42
+ /**
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() {
64
+ if (this.toNumber() === 0) {
65
+ return '0';
66
+ }
67
+ return (0, helpers_1.scientificStrToDecimalStr)(super.toString());
68
+ }
69
+ toTwos(bitCount) {
70
+ let binaryStr;
71
+ if (this.gte(0)) {
72
+ const twosComp = this.toNumber().toString(2);
73
+ binaryStr = this.padAndChop(twosComp, '0', bitCount || twosComp.length);
74
+ }
75
+ else {
76
+ binaryStr = this.plus(Math.pow(2, bitCount)).toNumber().toString(2);
77
+ if (Number(binaryStr) < 0) {
78
+ throw new Error('Cannot calculate twos complement');
79
+ }
80
+ }
81
+ const binary = `0b${binaryStr}`;
82
+ const decimal = Number(binary);
83
+ return tinyBig(decimal);
84
+ }
85
+ }
86
+ exports.TinyBig = TinyBig;
87
+ /**
88
+ * Helper factory function so that you don't have to type "new" when instantiating a new TinyBig
89
+ *
90
+ * @param value the value to initiate the TinyBig with
91
+ * @returns an initiated {@link TinyBig}
92
+ * @example
93
+ * ```javascript
94
+ * tinyBig(10).times(3).toNumber()
95
+ * // 30
96
+ * ```
97
+ */
98
+ function tinyBig(value) {
99
+ return new TinyBig(value);
100
+ }
101
+ exports.tinyBig = tinyBig;
@@ -1,3 +1,3 @@
1
- declare type JSPrimitiveTypes = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function';
2
- export declare const validateType: (value: unknown, allowedTypes: JSPrimitiveTypes[]) => void;
3
- export {};
1
+ declare type JSPrimitiveTypes = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function';
2
+ export declare const validateType: (value: unknown, allowedTypes: JSPrimitiveTypes[]) => void;
3
+ export {};
@@ -0,0 +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}`);
7
+ }
8
+ };
9
+ exports.validateType = validateType;
@@ -1,40 +1,41 @@
1
- import type { TinyBig } from './../shared/tiny-big/tiny-big';
2
- import type { BlockTransactionResponse, RPCTransaction } from './Transaction.types';
3
- declare type Modify<T, R> = Omit<T, keyof R> & R;
4
- export declare type BlockResponse = Modify<RPCBlock, {
5
- baseFeePerGas: TinyBig;
6
- difficulty: TinyBig;
7
- gasLimit: TinyBig;
8
- gasUsed: TinyBig;
9
- nonce: TinyBig;
10
- number: number;
11
- size: TinyBig;
12
- timestamp: TinyBig;
13
- totalDifficulty: TinyBig;
14
- transactions: Array<string | BlockTransactionResponse>;
15
- }>;
16
- export interface RPCBlock {
17
- baseFeePerGas: string;
18
- difficulty: string;
19
- extraData: string;
20
- gasLimit: string;
21
- gasUsed: string;
22
- hash: string;
23
- logsBloom: string;
24
- miner: string;
25
- mixHash: string;
26
- nonce: string;
27
- number: string;
28
- parentHash: string;
29
- receiptsRoot: string;
30
- sha3Uncles: string;
31
- size: string;
32
- stateRoot: string;
33
- timestamp: string;
34
- totalDifficulty: string;
35
- transactions: Array<string | RPCTransaction>;
36
- transactionsRoot: string;
37
- uncles: Array<string>;
38
- }
39
- export declare type BlockTag = 'latest' | 'earliest' | 'pending' | number | string;
40
- export {};
1
+ import type { TinyBig } from './../shared/tiny-big/tiny-big';
2
+ import type { BlockTransactionResponse, RPCTransaction } from './Transaction.types';
3
+ declare type Modify<T, R> = Omit<T, keyof R> & R;
4
+ export declare type BlockResponse = Modify<RPCBlock, {
5
+ baseFeePerGas: TinyBig;
6
+ difficulty: TinyBig;
7
+ gasLimit: TinyBig;
8
+ gasUsed: TinyBig;
9
+ nonce: TinyBig;
10
+ number: number;
11
+ size: TinyBig;
12
+ timestamp: TinyBig;
13
+ totalDifficulty: TinyBig;
14
+ transactions: Array<string | BlockTransactionResponse>;
15
+ }>;
16
+ /** Exact response from backend */
17
+ export interface RPCBlock {
18
+ baseFeePerGas: string;
19
+ difficulty: string;
20
+ extraData: string;
21
+ gasLimit: string;
22
+ gasUsed: string;
23
+ hash: string;
24
+ logsBloom: string;
25
+ miner: string;
26
+ mixHash: string;
27
+ nonce: string;
28
+ number: string;
29
+ parentHash: string;
30
+ receiptsRoot: string;
31
+ sha3Uncles: string;
32
+ size: string;
33
+ stateRoot: string;
34
+ timestamp: string;
35
+ totalDifficulty: string;
36
+ transactions: Array<string | RPCTransaction>;
37
+ transactionsRoot: string;
38
+ uncles: Array<string>;
39
+ }
40
+ export declare type BlockTag = 'latest' | 'earliest' | 'pending' | number | string;
41
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,24 +1,24 @@
1
- export declare type ContractTypes = 'bool' | 'bytes1' | 'bytes2' | 'bytes3' | 'bytes4' | 'bytes5' | 'bytes6' | 'bytes7' | 'bytes8' | 'bytes9' | 'bytes10' | 'bytes11' | 'bytes12' | 'bytes13' | 'bytes14' | 'bytes15' | 'bytes16' | 'bytes17' | 'bytes18' | 'bytes19' | 'bytes20' | 'bytes21' | 'bytes22' | 'bytes23' | 'bytes24' | 'bytes25' | 'bytes26' | 'bytes27' | 'bytes28' | 'bytes29' | 'bytes30' | 'bytes31' | 'bytes32' | 'bytes32[]' | 'address' | 'address payable' | 'address[4]' | 'address[100]' | 'uint256' | 'uint256[100]' | 'uint8' | 'uint32' | string;
2
- export declare type ContractInterface = JSONABI;
3
- export declare type ContractFunction<T = any> = (...args: Array<any>) => Promise<T>;
4
- export interface JSONABIArgument {
5
- anonymous?: false;
6
- inputs: {
7
- internalType?: ContractTypes | string;
8
- name: string;
9
- type: ContractTypes;
10
- indexed?: boolean;
11
- }[];
12
- name?: string;
13
- outputs?: {
14
- internalType?: ContractTypes | string;
15
- name: string;
16
- type: ContractTypes;
17
- }[];
18
- stateMutability?: 'view' | 'nonpayable' | string;
19
- type: 'function' | 'event' | 'constructor' | 'error' | 'fallback';
20
- gas?: number;
21
- constant?: boolean;
22
- payable?: boolean;
23
- }
24
- export declare type JSONABI = JSONABIArgument[];
1
+ export declare type ContractTypes = 'bool' | 'bytes1' | 'bytes2' | 'bytes3' | 'bytes4' | 'bytes5' | 'bytes6' | 'bytes7' | 'bytes8' | 'bytes9' | 'bytes10' | 'bytes11' | 'bytes12' | 'bytes13' | 'bytes14' | 'bytes15' | 'bytes16' | 'bytes17' | 'bytes18' | 'bytes19' | 'bytes20' | 'bytes21' | 'bytes22' | 'bytes23' | 'bytes24' | 'bytes25' | 'bytes26' | 'bytes27' | 'bytes28' | 'bytes29' | 'bytes30' | 'bytes31' | 'bytes32' | 'bytes32[]' | 'address' | 'address payable' | 'address[4]' | 'address[100]' | 'uint256' | 'uint256[100]' | 'uint8' | 'uint32' | string;
2
+ export declare type ContractInterface = JSONABI;
3
+ export declare type ContractFunction<T = any> = (...args: Array<any>) => Promise<T>;
4
+ export interface JSONABIArgument {
5
+ anonymous?: false;
6
+ inputs: {
7
+ internalType?: ContractTypes | string;
8
+ name: string;
9
+ type: ContractTypes;
10
+ indexed?: boolean;
11
+ }[];
12
+ name?: string;
13
+ outputs?: {
14
+ internalType?: ContractTypes | string;
15
+ name: string;
16
+ type: ContractTypes;
17
+ }[];
18
+ stateMutability?: 'view' | 'nonpayable' | string;
19
+ type: 'function' | 'event' | 'constructor' | 'error' | 'fallback';
20
+ gas?: number;
21
+ constant?: boolean;
22
+ payable?: boolean;
23
+ }
24
+ export declare type JSONABI = JSONABIArgument[];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,16 @@
1
+ import type { BlockTag } from './Block.types';
2
+ export interface EventFilter {
3
+ address?: string;
4
+ topics?: Array<string | Array<string> | null>;
5
+ }
6
+ /**
7
+ * @param fromBlock block as starting point for range, inclusive
8
+ * @param toBlock block as ending point for range, inclusive
9
+ */
10
+ export interface Filter extends EventFilter {
11
+ fromBlock?: BlockTag;
12
+ toBlock?: BlockTag;
13
+ }
14
+ export interface FilterByBlockHash extends EventFilter {
15
+ blockHash?: string;
16
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * A trimmed version of https://chainid.network/chains.json
3
+ */
4
+ export interface Network {
5
+ chainId: number;
6
+ ensAddress: string | null;
7
+ name: string;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,123 @@
1
+ import type Big from 'big.js';
2
+ import type { TinyBig } from '../shared/tiny-big/tiny-big';
3
+ import type { BytesLike } from './../utils/bytes';
4
+ declare type Modify<T, R> = Omit<T, keyof R> & R;
5
+ export interface RPCTransaction extends RPCBlockTransaction {
6
+ maxFeePerGas: string;
7
+ maxPriorityFeePerGas: string;
8
+ }
9
+ export declare type TransactionResponse = Modify<RPCTransaction, {
10
+ blockNumber: number;
11
+ chainId: number;
12
+ gas: TinyBig;
13
+ gasLimit: TinyBig;
14
+ gasPrice: TinyBig;
15
+ nonce: TinyBig;
16
+ transactionIndex: number;
17
+ type: number;
18
+ v: number;
19
+ value: TinyBig;
20
+ } & {
21
+ maxFeePerGas: TinyBig;
22
+ maxPriorityFeePerGas: TinyBig;
23
+ confirmations: number;
24
+ }>;
25
+ /**
26
+ * Type that contains information from the receipt of a transaction
27
+ *
28
+ * * Similar to [`Type TransactionReceipt on ethers.providers`](https://docs.ethers.io/v5/api/providers/types/#providers-TransactionReceipt)
29
+ */
30
+ export declare type TransactionReceipt = Modify<RPCTransactionReceipt, {
31
+ blockNumber: number;
32
+ cumulativeGasUsed: TinyBig;
33
+ effectiveGasPrice: TinyBig;
34
+ gasUsed: TinyBig;
35
+ logs: Array<Log>;
36
+ status: number;
37
+ transactionIndex: number;
38
+ type: number;
39
+ } & {
40
+ byzantium: boolean;
41
+ confirmations: number;
42
+ }>;
43
+ export interface RPCTransactionRequest {
44
+ from?: string;
45
+ to: string;
46
+ gas?: string;
47
+ gasPrice?: string;
48
+ value?: string;
49
+ data?: BytesLike;
50
+ nonce?: string;
51
+ maxPriorityFeePerGas?: string;
52
+ maxFeePerGas?: string;
53
+ }
54
+ export interface TransactionRequest {
55
+ to?: string;
56
+ from?: string;
57
+ nonce?: TinyBig | string | Big | number;
58
+ gas?: TinyBig | number | Big | string;
59
+ gasPrice?: TinyBig | Big | string | number;
60
+ data?: BytesLike;
61
+ value?: TinyBig | string | Big | number;
62
+ chainId?: number;
63
+ type?: number;
64
+ maxPriorityFeePerGas?: TinyBig | string | Big | number;
65
+ maxFeePerGas?: TinyBig | string | Big | number;
66
+ }
67
+ /**
68
+ * Type for the logs that are included in transaction receipts
69
+ * Similar to [`Type Log on ethers.providers`](https://docs.ethers.io/v5/api/providers/types/#providers-Log)
70
+ */
71
+ export declare type Log = Modify<RPCLog, {
72
+ blockNumber: number;
73
+ logIndex: number;
74
+ transactionIndex: number;
75
+ }>;
76
+ export declare type BlockTransactionResponse = Omit<TransactionResponse, 'maxFeePerGas' | 'maxPriorityFeePerGas'>;
77
+ /** What JSONRPC responds with in getBlock transaction array */
78
+ export interface RPCBlockTransaction {
79
+ blockHash: string;
80
+ blockNumber: string;
81
+ chainId: string;
82
+ from: string;
83
+ gas: string;
84
+ gasPrice: string;
85
+ hash: string;
86
+ input: string;
87
+ nonce: string;
88
+ r: string;
89
+ s: string;
90
+ to: string;
91
+ transactionIndex: string;
92
+ type: string;
93
+ v: string;
94
+ value: string;
95
+ }
96
+ export interface RPCTransactionReceipt {
97
+ blockHash: string;
98
+ blockNumber: string;
99
+ contractAddress: string;
100
+ cumulativeGasUsed: string;
101
+ effectiveGasPrice: string;
102
+ from: string;
103
+ gasUsed: string;
104
+ logs: Array<RPCLog>;
105
+ logsBloom: string;
106
+ status: string;
107
+ to: string;
108
+ transactionHash: string;
109
+ transactionIndex: string;
110
+ type: string;
111
+ }
112
+ export interface RPCLog {
113
+ address: string;
114
+ blockHash: string;
115
+ blockNumber: string;
116
+ data: string;
117
+ logIndex: string;
118
+ removed?: boolean;
119
+ topics: Array<string>;
120
+ transactionHash: string;
121
+ transactionIndex: string;
122
+ }
123
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });