essential-eth 0.9.0 → 0.9.1-next.1

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 (134) hide show
  1. package/dist/cjs/classes/Contract.js +66 -307
  2. package/dist/cjs/classes/test/Contract/crv-abi.js +256 -252
  3. package/dist/cjs/classes/test/Contract/ens-abi.d.ts +1 -1
  4. package/dist/cjs/classes/test/Contract/ens-abi.js +212 -497
  5. package/dist/cjs/classes/test/Contract/fei-abi.js +284 -605
  6. package/dist/cjs/classes/test/Contract/foo-abi.d.ts +1 -1
  7. package/dist/cjs/classes/test/Contract/foo-abi.js +21 -44
  8. package/dist/cjs/classes/test/Contract/uniswap-abi.js +68 -64
  9. package/dist/cjs/classes/utils/clean-block.js +30 -52
  10. package/dist/cjs/classes/utils/clean-log.js +20 -42
  11. package/dist/cjs/classes/utils/clean-transaction-receipt.js +30 -51
  12. package/dist/cjs/classes/utils/clean-transaction.js +30 -52
  13. package/dist/cjs/classes/utils/encode-decode-transaction.js +107 -148
  14. package/dist/cjs/classes/utils/fetchers.d.ts +8 -2
  15. package/dist/cjs/classes/utils/fetchers.js +52 -166
  16. package/dist/cjs/classes/utils/hex-to-decimal.js +6 -1
  17. package/dist/cjs/classes/utils/prepare-transaction.js +36 -59
  18. package/dist/cjs/index.d.ts +21 -22
  19. package/dist/cjs/index.js +56 -26
  20. package/dist/cjs/index.umd.js +1 -1
  21. package/dist/cjs/index.umd.js.map +1 -1
  22. package/dist/cjs/logger/logger.js +23 -79
  23. package/dist/cjs/logger/package-version.d.ts +1 -1
  24. package/dist/cjs/logger/package-version.js +4 -1
  25. package/dist/cjs/providers/AlchemyProvider.js +9 -82
  26. package/dist/cjs/providers/BaseProvider.js +511 -882
  27. package/dist/cjs/providers/FallthroughProvider.js +46 -123
  28. package/dist/cjs/providers/JsonRpcProvider.js +28 -93
  29. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
  30. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +152 -0
  31. package/dist/cjs/providers/test/mock-of.js +6 -8
  32. package/dist/cjs/providers/test/rpc-urls.d.ts +1 -0
  33. package/dist/cjs/providers/test/rpc-urls.js +23 -14
  34. package/dist/cjs/providers/utils/chains-info.d.ts +5 -448
  35. package/dist/cjs/providers/utils/chains-info.js +16 -1345
  36. package/dist/cjs/shared/tiny-big/helpers.js +42 -93
  37. package/dist/cjs/shared/tiny-big/tiny-big.js +72 -161
  38. package/dist/cjs/shared/validate-type.d.ts +1 -1
  39. package/dist/cjs/shared/validate-type.js +7 -7
  40. package/dist/cjs/types/Block.types.d.ts +3 -3
  41. package/dist/cjs/types/Block.types.js +2 -1
  42. package/dist/cjs/types/Contract.types.d.ts +4 -4
  43. package/dist/cjs/types/Contract.types.js +2 -1
  44. package/dist/cjs/types/FeeData.types.js +2 -1
  45. package/dist/cjs/types/Filter.types.js +2 -1
  46. package/dist/cjs/types/Network.types.js +2 -3
  47. package/dist/cjs/types/Transaction.types.d.ts +5 -5
  48. package/dist/cjs/types/Transaction.types.js +2 -1
  49. package/dist/cjs/utils/bytes.d.ts +4 -4
  50. package/dist/cjs/utils/bytes.js +318 -286
  51. package/dist/cjs/utils/compute-address.js +15 -8
  52. package/dist/cjs/utils/compute-public-key.js +10 -5
  53. package/dist/cjs/utils/ether-to-gwei.js +11 -10
  54. package/dist/cjs/utils/ether-to-wei.js +11 -10
  55. package/dist/cjs/utils/gwei-to-ether.js +11 -10
  56. package/dist/cjs/utils/hash-message.js +16 -11
  57. package/dist/cjs/utils/is-address.js +12 -8
  58. package/dist/cjs/utils/keccak256.js +14 -8
  59. package/dist/cjs/utils/solidity-keccak256.js +60 -49
  60. package/dist/cjs/utils/split-signature.js +73 -55
  61. package/dist/cjs/utils/to-checksum-address.js +20 -15
  62. package/dist/cjs/utils/to-utf8-bytes.js +6 -1
  63. package/dist/cjs/utils/wei-to-ether.js +15 -13
  64. package/dist/esm/classes/test/Contract/ens-abi.d.ts +1 -1
  65. package/dist/esm/classes/test/Contract/foo-abi.d.ts +1 -1
  66. package/dist/esm/classes/utils/fetchers.d.ts +8 -2
  67. package/dist/esm/classes/utils/fetchers.js +6 -3
  68. package/dist/esm/index.d.ts +21 -22
  69. package/dist/esm/index.js +16 -17
  70. package/dist/esm/logger/package-version.d.ts +1 -1
  71. package/dist/esm/logger/package-version.js +1 -1
  72. package/dist/esm/providers/FallthroughProvider.js +3 -3
  73. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
  74. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +142 -0
  75. package/dist/esm/providers/test/rpc-urls.d.ts +1 -0
  76. package/dist/esm/providers/test/rpc-urls.js +7 -4
  77. package/dist/esm/providers/utils/chains-info.d.ts +5 -448
  78. package/dist/esm/providers/utils/chains-info.js +13 -1344
  79. package/dist/esm/shared/validate-type.d.ts +1 -1
  80. package/dist/esm/types/Block.types.d.ts +3 -3
  81. package/dist/esm/types/Contract.types.d.ts +4 -4
  82. package/dist/esm/types/Transaction.types.d.ts +5 -5
  83. package/dist/esm/utils/bytes.d.ts +4 -4
  84. package/package.json +23 -51
  85. package/readme.md +15 -38
  86. package/dist/cjs/classes/test/Contract/crv.test.js +0 -690
  87. package/dist/cjs/classes/test/Contract/ens.test.js +0 -217
  88. package/dist/cjs/classes/test/Contract/fei.test.js +0 -224
  89. package/dist/cjs/classes/test/Contract/foo.test.js +0 -33
  90. package/dist/cjs/classes/test/Contract/uni.test.js +0 -387
  91. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +0 -228
  92. package/dist/cjs/providers/test/get-transaction-count.test.js +0 -276
  93. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +0 -436
  94. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +0 -288
  95. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +0 -261
  96. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +0 -159
  97. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +0 -477
  98. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +0 -311
  99. package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +0 -212
  100. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +0 -164
  101. package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +0 -361
  102. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +0 -274
  103. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +0 -301
  104. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +0 -307
  105. package/dist/cjs/providers/test/test-alchemy-provider.test.js +0 -151
  106. package/dist/cjs/shared/tiny-big/helpers.test.js +0 -29
  107. package/dist/cjs/shared/tiny-big/tiny-big.test.js +0 -34
  108. package/dist/cjs/utils/tests/bytes/arrayify.test.js +0 -40
  109. package/dist/cjs/utils/tests/bytes/concat.test.js +0 -15
  110. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +0 -63
  111. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +0 -49
  112. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +0 -52
  113. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +0 -58
  114. package/dist/cjs/utils/tests/bytes/hex-value.test.js +0 -85
  115. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +0 -62
  116. package/dist/cjs/utils/tests/bytes/hexlify.test.js +0 -62
  117. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +0 -69
  118. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +0 -33
  119. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +0 -88
  120. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +0 -57
  121. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +0 -80
  122. package/dist/cjs/utils/tests/compute-address.test.js +0 -27
  123. package/dist/cjs/utils/tests/compute-public-key.test.js +0 -15
  124. package/dist/cjs/utils/tests/ether-to-gwei.test.js +0 -26
  125. package/dist/cjs/utils/tests/ether-to-wei.test.js +0 -44
  126. package/dist/cjs/utils/tests/gwei-to-ether.test.js +0 -28
  127. package/dist/cjs/utils/tests/hash-message.test.js +0 -21
  128. package/dist/cjs/utils/tests/is-address.test.js +0 -55
  129. package/dist/cjs/utils/tests/keccak256.test.js +0 -97
  130. package/dist/cjs/utils/tests/solidity-keccak256.test.js +0 -310
  131. package/dist/cjs/utils/tests/split-signature.test.js +0 -25
  132. package/dist/cjs/utils/tests/to-checksum-address.test.js +0 -42
  133. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +0 -14
  134. package/dist/cjs/utils/tests/wei-to-ether.test.js +0 -51
@@ -1,34 +1,9 @@
1
- function _defineProperty(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value: value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
13
- }
14
- function _objectSpread(target) {
15
- for(var i = 1; i < arguments.length; i++){
16
- var source = arguments[i] != null ? arguments[i] : {};
17
- var ownKeys = Object.keys(source);
18
- if (typeof Object.getOwnPropertySymbols === "function") {
19
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
20
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
21
- }));
22
- }
23
- ownKeys.forEach(function(key) {
24
- _defineProperty(target, key, source[key]);
25
- });
26
- }
27
- return target;
28
- }
29
- import { tinyBig } from "../../shared/tiny-big/tiny-big";
30
- import { toChecksumAddress } from "../../utils/to-checksum-address";
31
- import { hexToDecimal } from "./hex-to-decimal";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cleanTransaction = void 0;
4
+ const tiny_big_1 = require("../../shared/tiny-big/tiny-big");
5
+ const to_checksum_address_1 = require("../../utils/to-checksum-address");
6
+ const hex_to_decimal_1 = require("./hex-to-decimal");
32
7
  /**
33
8
  * Converts RPC transaction response to more JS-friendly format
34
9
  *
@@ -40,35 +15,38 @@ import { hexToDecimal } from "./hex-to-decimal";
40
15
  * cleanTransaction(RPCTransaction);
41
16
  * // { accessList: [], blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: 14847842, chainId: 1, from: '0x642824FaB1D0141073ed74326332950bEc4701e3', gas: Big { s: 1, e: 5, c: [ 1, 6, 0, 9, 5, 1 ], constructor: { [λ: Big] DP: 20, RM: 1, NE: -7, PE: 21, strict: false, roundDown: 0, roundHalfUp: 1, roundHalfEven: 2, roundUp: 3, Big: [Circular], default: [Circular] }, padAndChop: [λ] }, gasPrice: Big { s: 1, e: 10, c: [ 2, 6, 5, 4, 0, 6, 2, 3, 4, 0, 4 ], constructor: { [λ: Big] DP: 20, RM: 1, NE: -7, PE: 21, strict: false, roundDown: 0, roundHalfUp: 1, roundHalfEven: 2, roundUp: 3, Big: [Circular], default: [Circular] }, padAndChop: [λ] }, hash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', input: '0xa0712d68000000000000000000000000000000000000000000000000000000000000000a', maxFeePerGas: Big { s: 1, e: 10, c: [ 4, 0, 9, 3, 6, 9, 8, 9, 6, 8 ], constructor: { [λ: Big] DP: 20, RM: 1, NE: -7, PE: 21, strict: false, roundDown: 0, roundHalfUp: 1, roundHalfEven: 2, roundUp: 3, Big: [Circular], default: [Circular] }, padAndChop: [λ] }, maxPriorityFeePerGas: Big { s: 1, e: 9, c: [ 1 ], constructor: { [λ: Big] DP: 20, RM: 1, NE: -7, PE: 21, strict: false, roundDown: 0, roundHalfUp: 1, roundHalfEven: 2, roundUp: 3, Big: [Circular], default: [Circular] }, padAndChop: [λ] }, nonce: 66, r: '0x304682f8b22006dd1347c3722f6e43a5ad8e3a1ae51939cc0d6f07981602f5c0', s: '0x207ad110eb5c014cb628814b92396785fabfbe74542293300eeadf156f50f105', to: '0x84F80EA01e26B7C11bdd241970982C7EEAb6DdcC', transactionIndex: 41, type: 2, v: 1, value: Big { s: 1, e: 16, c: [ 2 ], constructor: { [λ: Big] DP: 20, RM: 1, NE: -7, PE: 21, strict: false, roundDown: 0, roundHalfUp: 1, roundHalfEven: 2, roundUp: 3, Big: [Circular], default: [Circular] }, padAndChop: [λ] }, confirmations: 53 }
42
17
  * ```
43
- */ export function cleanTransaction(transaction) {
44
- var cleanedTransaction = _objectSpread({}, transaction);
45
- Object.keys(transaction).forEach(function(key) {
18
+ */
19
+ function cleanTransaction(transaction) {
20
+ const cleanedTransaction = Object.assign({}, transaction);
21
+ Object.keys(transaction).forEach((key) => {
46
22
  // pending blocks have null instead of a difficulty
47
23
  // pending blocks have null instead of a miner address
48
- if (!transaction[key]) return;
49
- switch(key){
50
- case "blockNumber":
51
- case "chainId":
52
- case "transactionIndex":
53
- case "type":
54
- case "v":
55
- cleanedTransaction[key] = Number(hexToDecimal(transaction[key]));
24
+ if (!transaction[key])
25
+ return;
26
+ switch (key) {
27
+ case 'blockNumber':
28
+ case 'chainId':
29
+ case 'transactionIndex':
30
+ case 'type':
31
+ case 'v':
32
+ cleanedTransaction[key] = Number((0, hex_to_decimal_1.hexToDecimal)(transaction[key]));
56
33
  break;
57
- case "from":
58
- case "to":
34
+ case 'from':
35
+ case 'to':
59
36
  if (transaction[key]) {
60
- cleanedTransaction[key] = toChecksumAddress(transaction[key]);
37
+ cleanedTransaction[key] = (0, to_checksum_address_1.toChecksumAddress)(transaction[key]);
61
38
  }
62
39
  break;
63
- case "value":
64
- case "gas":
65
- case "gasPrice":
66
- case "maxFeePerGas":
67
- case "maxPriorityFeePerGas":
68
- case "nonce":
69
- cleanedTransaction[key] = tinyBig(hexToDecimal(transaction[key]));
40
+ case 'value':
41
+ case 'gas':
42
+ case 'gasPrice':
43
+ case 'maxFeePerGas':
44
+ case 'maxPriorityFeePerGas':
45
+ case 'nonce':
46
+ cleanedTransaction[key] = (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(transaction[key]));
70
47
  break;
71
48
  }
72
49
  });
73
50
  return cleanedTransaction;
74
51
  }
52
+ exports.cleanTransaction = cleanTransaction;
@@ -1,73 +1,33 @@
1
- function _arrayLikeToArray(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _arrayWithHoles(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
- function _iterableToArrayLimit(arr, i) {
10
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
11
- if (_i == null) return;
12
- var _arr = [];
13
- var _n = true;
14
- var _d = false;
15
- var _s, _e;
16
- try {
17
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
18
- _arr.push(_s.value);
19
- if (i && _arr.length === i) break;
20
- }
21
- } catch (err) {
22
- _d = true;
23
- _e = err;
24
- } finally{
25
- try {
26
- if (!_n && _i["return"] != null) _i["return"]();
27
- } finally{
28
- if (_d) throw _e;
29
- }
30
- }
31
- return _arr;
32
- }
33
- function _nonIterableRest() {
34
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35
- }
36
- function _slicedToArray(arr, i) {
37
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
38
- }
39
- function _unsupportedIterableToArray(o, minLen) {
40
- if (!o) return;
41
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
42
- var n = Object.prototype.toString.call(o).slice(8, -1);
43
- if (n === "Object" && o.constructor) n = o.constructor.name;
44
- if (n === "Map" || n === "Set") return Array.from(n);
45
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
46
- }
47
- import { Keccak } from "sha3";
48
- import { tinyBig } from "../../shared/tiny-big/tiny-big";
49
- import { toChecksumAddress } from "../../utils/to-checksum-address";
50
- import { hexToDecimal } from "./hex-to-decimal";
51
- export var hexFalse = "0".repeat(64);
52
- var hexTrue = "0".repeat(63) + "1";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeRPCResponse = exports.encodeData = exports.hexFalse = void 0;
4
+ const sha3_1 = require("sha3");
5
+ const tiny_big_1 = require("../../shared/tiny-big/tiny-big");
6
+ const to_checksum_address_1 = require("../../utils/to-checksum-address");
7
+ const hex_to_decimal_1 = require("./hex-to-decimal");
8
+ exports.hexFalse = '0'.repeat(64);
9
+ const hexTrue = '0'.repeat(63) + '1';
53
10
  /**
54
11
  * @param hex
55
12
  * @example
56
- */ function hexToUtf8(hex) {
57
- var str = "";
58
- var i = 0;
59
- var l = hex.length;
60
- if (hex.substring(0, 2) === "0x") {
13
+ */
14
+ function hexToUtf8(hex) {
15
+ let str = '';
16
+ let i = 0;
17
+ const l = hex.length;
18
+ if (hex.substring(0, 2) === '0x') {
61
19
  i = 2;
62
20
  }
63
- for(; i < l; i += 2){
64
- var code = parseInt(hex.substr(i, 2), 16);
65
- if (code === 0) continue; // Skip null bytes
21
+ for (; i < l; i += 2) {
22
+ const code = parseInt(hex.substr(i, 2), 16);
23
+ if (code === 0)
24
+ continue; // Skip null bytes
66
25
  str += String.fromCharCode(code);
67
26
  }
68
27
  try {
69
28
  return decodeURIComponent(escape(str)); // Convert UTF-8 to Unicode
70
- } catch (e) {
29
+ }
30
+ catch (e) {
71
31
  return str; // Return original string if conversion fails
72
32
  }
73
33
  }
@@ -82,12 +42,14 @@ var hexTrue = "0".repeat(63) + "1";
82
42
  * expandType('uint[]');
83
43
  * // 'uint256[]'
84
44
  * ```
85
- */ function expandType(type) {
45
+ */
46
+ function expandType(type) {
86
47
  // https://docs.soliditylang.org/en/v0.8.7/types.html#integers
87
- if (type === "uint[]") {
88
- return "uint256[]";
89
- } else if (type === "int[]") {
90
- return "int256[]";
48
+ if (type === 'uint[]') {
49
+ return 'uint256[]';
50
+ }
51
+ else if (type === 'int[]') {
52
+ return 'int256[]';
91
53
  }
92
54
  return type;
93
55
  }
@@ -96,123 +58,120 @@ var hexTrue = "0".repeat(63) + "1";
96
58
  * @param jsonABIArgument
97
59
  * @param args
98
60
  * @example
99
- */ export function encodeData(jsonABIArgument, args) {
100
- var hash = new Keccak(256);
101
- /* first 4 bytes will create the data parameter */ var functionString = "".concat(jsonABIArgument.name, "(").concat(jsonABIArgument.inputs.map(function(input) {
102
- return expandType(input.type);
103
- }), ")");
61
+ */
62
+ function encodeData(jsonABIArgument, args) {
63
+ const hash = new sha3_1.Keccak(256);
64
+ /* first 4 bytes will create the data parameter */
65
+ const functionString = `${jsonABIArgument.name}(${jsonABIArgument.inputs.map((input) => expandType(input.type))})`;
104
66
  // encoding learnt from https://ethereum.stackexchange.com/questions/3514/how-to-call-a-contract-method-using-the-eth-call-json-rpc-api
105
- var functionHash = hash.update(functionString).digest("hex");
67
+ const functionHash = hash.update(functionString).digest('hex');
106
68
  // no arrays
107
- var jsonABIInputsLength = jsonABIArgument.inputs.length;
108
- var shouldValidateInputLength = true;
69
+ const jsonABIInputsLength = jsonABIArgument.inputs.length;
70
+ let shouldValidateInputLength = true;
109
71
  // inputs contains 1 or more arrays
110
- if (jsonABIArgument.inputs.find(function(input) {
111
- return input.type.includes("[");
112
- })) {
72
+ if (jsonABIArgument.inputs.find((input) => input.type.includes('['))) {
113
73
  shouldValidateInputLength = false;
114
74
  }
115
75
  if (shouldValidateInputLength && args.length !== jsonABIInputsLength) {
116
- throw new Error('args inputs of "'.concat(args.length, '" does not match expected length of "').concat(jsonABIArgument.inputs.length, '"'));
76
+ throw new Error(`args inputs of "${args.length}" does not match expected length of "${jsonABIArgument.inputs.length}"`);
117
77
  }
118
- var argsWithTypes = (jsonABIArgument.inputs || []).reduce(function(acc, input, i) {
119
- if (input.type.includes("[")) {
120
- var _exec;
78
+ const argsWithTypes = (jsonABIArgument.inputs || []).reduce((acc, input, i) => {
79
+ var _a;
80
+ if (input.type.includes('[')) {
121
81
  // strip array and length like "[2]" from type
122
- var basicType = (_exec = /([^[]*)\[.*$/g.exec(input.type)) === null || _exec === void 0 ? void 0 : _exec[1];
123
- args.forEach(function(arg) {
124
- acc = acc.concat([
125
- [
126
- arg,
127
- basicType
128
- ]
129
- ]);
82
+ const basicType = (_a = /([^[]*)\[.*$/g.exec(input.type)) === null || _a === void 0 ? void 0 : _a[1];
83
+ args.forEach((arg) => {
84
+ acc = acc.concat([[arg, basicType]]);
130
85
  });
131
86
  return acc;
132
- } else {
133
- return acc.concat([
134
- [
135
- args[i],
136
- input.type
137
- ]
138
- ]);
87
+ }
88
+ else {
89
+ return acc.concat([[args[i], input.type]]);
139
90
  }
140
91
  }, []);
141
- var encodedArgs = argsWithTypes.map(function(param) {
142
- var _param = _slicedToArray(param, 2), arg = _param[0], inputType = _param[1];
143
- var rawArg = arg;
144
- switch(inputType){
145
- case "bool":
146
- return arg ? hexTrue : hexFalse;
147
- case "address":
92
+ const encodedArgs = argsWithTypes.map(([arg, inputType]) => {
93
+ let rawArg = arg;
94
+ switch (inputType) {
95
+ case 'bool':
96
+ return arg ? hexTrue : exports.hexFalse;
97
+ case 'address':
148
98
  // remove leading "0x"
149
- rawArg = arg.replace(/^0x/g, "").toLowerCase();
99
+ rawArg = arg.replace(/^0x/g, '').toLowerCase();
150
100
  break;
151
101
  default:
152
- if (inputType.startsWith("bytes")) {
102
+ if (inputType.startsWith('bytes')) {
153
103
  // encode each character to hex
154
- var argEncoded = rawArg.split("").map(function(character) {
155
- return character.charCodeAt(0).toString(16);
156
- }).join("");
157
- var paddedEncodedArg = argEncoded.padEnd(64, "0");
104
+ const argEncoded = rawArg
105
+ .split('')
106
+ .map((character) => character.charCodeAt(0).toString(16))
107
+ .join('');
108
+ const paddedEncodedArg = argEncoded.padEnd(64, '0');
158
109
  return paddedEncodedArg;
159
- } else if (inputType === "uint256") {
160
- var argEncoded1 = BigInt(arg).toString(16);
161
- var paddedEncodedArg1 = argEncoded1.padStart(64, "0");
162
- return paddedEncodedArg1;
163
- } else if (inputType.startsWith("uint")) {
110
+ }
111
+ else if (inputType === 'uint256') {
112
+ const argEncoded = BigInt(arg).toString(16);
113
+ const paddedEncodedArg = argEncoded.padStart(64, '0');
114
+ return paddedEncodedArg;
115
+ }
116
+ else if (inputType.startsWith('uint')) {
164
117
  break;
165
- } else {
166
- throw new Error('essential-eth does not yet support "'.concat(inputType, '" inputs. Make a PR today!"'));
118
+ }
119
+ else {
120
+ throw new Error(`essential-eth does not yet support "${inputType}" inputs. Make a PR today!"`);
167
121
  }
168
122
  }
169
- var argEncoded2 = rawArg.toString(16);
170
- var paddedEncodedArg2 = argEncoded2.padStart(64, "0");
171
- return paddedEncodedArg2;
123
+ const argEncoded = rawArg.toString(16);
124
+ const paddedEncodedArg = argEncoded.padStart(64, '0');
125
+ return paddedEncodedArg;
172
126
  });
173
- var functionEncoded = functionHash.slice(0, 8);
174
- var data = "0x".concat(functionEncoded).concat(encodedArgs.join(""));
127
+ const functionEncoded = functionHash.slice(0, 8);
128
+ const data = `0x${functionEncoded}${encodedArgs.join('')}`;
175
129
  return data;
176
130
  }
131
+ exports.encodeData = encodeData;
177
132
  /**
178
133
  * @internal
179
134
  * @param jsonABIArgument
180
135
  * @param nodeResponse
181
136
  * @example
182
- */ export function decodeRPCResponse(jsonABIArgument, nodeResponse) {
183
- var _jsonABIArgument_outputs;
184
- var rawOutputs = jsonABIArgument.outputs;
185
- var slicedResponse = nodeResponse.slice(2);
186
- if ((jsonABIArgument === null || jsonABIArgument === void 0 ? void 0 : (_jsonABIArgument_outputs = jsonABIArgument.outputs) === null || _jsonABIArgument_outputs === void 0 ? void 0 : _jsonABIArgument_outputs.length) === 1 && jsonABIArgument.outputs[0].type === "string") {
187
- var _ref = [
137
+ */
138
+ function decodeRPCResponse(jsonABIArgument, nodeResponse) {
139
+ var _a;
140
+ const rawOutputs = jsonABIArgument.outputs;
141
+ const slicedResponse = nodeResponse.slice(2);
142
+ if (((_a = jsonABIArgument === null || jsonABIArgument === void 0 ? void 0 : jsonABIArgument.outputs) === null || _a === void 0 ? void 0 : _a.length) === 1 &&
143
+ jsonABIArgument.outputs[0].type === 'string') {
144
+ const [hexOffset, responseData] = [
188
145
  slicedResponse.slice(0, 64),
189
- slicedResponse.slice(64)
190
- ], hexOffset = _ref[0], responseData = _ref[1];
191
- var decimalOffset = Number(hexToDecimal("0x".concat(hexOffset)));
192
- var hexLength = responseData.slice(0, decimalOffset * 2);
193
- var decimalLength = Number(hexToDecimal("0x".concat(hexLength)));
194
- var hexToDecode = responseData.slice(decimalOffset * 2, decimalOffset * 2 + decimalLength * 2);
146
+ slicedResponse.slice(64),
147
+ ];
148
+ const decimalOffset = Number((0, hex_to_decimal_1.hexToDecimal)(`0x${hexOffset}`));
149
+ const hexLength = responseData.slice(0, decimalOffset * 2);
150
+ const decimalLength = Number((0, hex_to_decimal_1.hexToDecimal)(`0x${hexLength}`));
151
+ const hexToDecode = responseData.slice(decimalOffset * 2, decimalOffset * 2 + decimalLength * 2);
195
152
  return hexToUtf8(hexToDecode);
196
153
  }
197
154
  // chunk response every 64 characters
198
- var encodedOutputs = slicedResponse.match(/.{1,64}/g);
199
- var outputs = (encodedOutputs || []).map(function(output, i) {
200
- var outputType = (rawOutputs || [])[i].type;
201
- switch(outputType){
202
- case "bool":
155
+ const encodedOutputs = slicedResponse.match(/.{1,64}/g);
156
+ const outputs = (encodedOutputs || []).map((output, i) => {
157
+ const outputType = (rawOutputs || [])[i].type;
158
+ switch (outputType) {
159
+ case 'bool':
203
160
  return output === hexTrue;
204
- case "address":
205
- /* address types have 24 leading zeroes to remove */ return toChecksumAddress("0x".concat(output.slice(24)));
206
- case "uint256":
207
- case "uint120":
208
- return tinyBig(hexToDecimal("0x".concat(output)));
209
- case "bytes32":
210
- return "0x".concat(output);
211
- case "uint8":
212
- return Number(hexToDecimal("0x".concat(output)));
161
+ case 'address':
162
+ /* address types have 24 leading zeroes to remove */
163
+ return (0, to_checksum_address_1.toChecksumAddress)(`0x${output.slice(24)}`);
164
+ case 'uint256':
165
+ case 'uint120':
166
+ return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(`0x${output}`));
167
+ case 'bytes32':
168
+ return `0x${output}`;
169
+ case 'uint8':
170
+ return Number((0, hex_to_decimal_1.hexToDecimal)(`0x${output}`));
213
171
  default:
214
- throw new Error('essential-eth does not yet support "'.concat(outputType, '" outputs. Make a PR today!"'));
172
+ throw new Error(`essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`);
215
173
  }
216
174
  });
217
175
  return outputs.length === 1 ? outputs[0] : outputs;
218
176
  }
177
+ exports.decodeRPCResponse = decodeRPCResponse;
@@ -1,9 +1,15 @@
1
+ export declare function buildFetchInit<T>(body: T): {
2
+ method: string;
3
+ headers: {
4
+ 'Content-Type': string;
5
+ };
6
+ body: string;
7
+ };
1
8
  export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
2
- declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount' | 'eth_getCode' | 'eth_blockNumber' | 'eth_estimateGas' | 'eth_getLogs';
9
+ export type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount' | 'eth_getCode' | 'eth_blockNumber' | 'eth_estimateGas' | 'eth_getLogs';
3
10
  export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
4
11
  jsonrpc: string;
5
12
  id: number;
6
13
  method: RPCMethodName;
7
14
  params: unknown[];
8
15
  };
9
- export {};