essential-eth 0.9.1-next.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 (104) hide show
  1. package/dist/cjs/classes/Contract.js +66 -311
  2. package/dist/cjs/classes/test/Contract/crv-abi.js +256 -252
  3. package/dist/cjs/classes/test/Contract/ens-abi.js +212 -497
  4. package/dist/cjs/classes/test/Contract/fei-abi.js +284 -605
  5. package/dist/cjs/classes/test/Contract/foo-abi.js +21 -44
  6. package/dist/cjs/classes/test/Contract/uniswap-abi.js +68 -64
  7. package/dist/cjs/classes/utils/clean-block.js +30 -52
  8. package/dist/cjs/classes/utils/clean-log.js +20 -42
  9. package/dist/cjs/classes/utils/clean-transaction-receipt.js +30 -51
  10. package/dist/cjs/classes/utils/clean-transaction.js +30 -52
  11. package/dist/cjs/classes/utils/encode-decode-transaction.js +107 -148
  12. package/dist/cjs/classes/utils/fetchers.js +44 -166
  13. package/dist/cjs/classes/utils/hex-to-decimal.js +6 -1
  14. package/dist/cjs/classes/utils/prepare-transaction.js +36 -59
  15. package/dist/cjs/index.js +56 -25
  16. package/dist/cjs/index.umd.js +1 -1
  17. package/dist/cjs/index.umd.js.map +1 -1
  18. package/dist/cjs/logger/logger.js +29 -123
  19. package/dist/cjs/logger/package-version.d.ts +1 -1
  20. package/dist/cjs/logger/package-version.js +4 -1
  21. package/dist/cjs/providers/AlchemyProvider.js +9 -82
  22. package/dist/cjs/providers/BaseProvider.js +520 -958
  23. package/dist/cjs/providers/FallthroughProvider.js +47 -156
  24. package/dist/cjs/providers/JsonRpcProvider.js +28 -114
  25. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +104 -101
  26. package/dist/cjs/providers/test/mock-of.js +6 -3
  27. package/dist/cjs/providers/test/rpc-urls.js +23 -15
  28. package/dist/cjs/providers/utils/chains-info.js +3 -1
  29. package/dist/cjs/shared/tiny-big/helpers.js +42 -93
  30. package/dist/cjs/shared/tiny-big/tiny-big.js +81 -210
  31. package/dist/cjs/shared/validate-type.js +7 -7
  32. package/dist/cjs/types/Block.types.js +2 -1
  33. package/dist/cjs/types/Contract.types.js +2 -1
  34. package/dist/cjs/types/FeeData.types.js +2 -1
  35. package/dist/cjs/types/Filter.types.js +2 -1
  36. package/dist/cjs/types/Network.types.js +2 -3
  37. package/dist/cjs/types/Transaction.types.js +2 -1
  38. package/dist/cjs/utils/bytes.js +318 -286
  39. package/dist/cjs/utils/compute-address.js +15 -8
  40. package/dist/cjs/utils/compute-public-key.js +10 -5
  41. package/dist/cjs/utils/ether-to-gwei.js +11 -10
  42. package/dist/cjs/utils/ether-to-wei.js +11 -10
  43. package/dist/cjs/utils/gwei-to-ether.js +11 -10
  44. package/dist/cjs/utils/hash-message.js +16 -11
  45. package/dist/cjs/utils/is-address.js +12 -8
  46. package/dist/cjs/utils/keccak256.js +14 -8
  47. package/dist/cjs/utils/solidity-keccak256.js +60 -49
  48. package/dist/cjs/utils/split-signature.js +73 -55
  49. package/dist/cjs/utils/to-checksum-address.js +20 -15
  50. package/dist/cjs/utils/to-utf8-bytes.js +6 -1
  51. package/dist/cjs/utils/wei-to-ether.js +15 -13
  52. package/dist/esm/logger/package-version.d.ts +1 -1
  53. package/dist/esm/logger/package-version.js +1 -1
  54. package/package.json +2 -2
  55. package/readme.md +1 -1
  56. package/dist/cjs/classes/test/Contract/crv.test.js +0 -497
  57. package/dist/cjs/classes/test/Contract/ens.test.js +0 -160
  58. package/dist/cjs/classes/test/Contract/fei.test.js +0 -224
  59. package/dist/cjs/classes/test/Contract/foo.test.js +0 -33
  60. package/dist/cjs/classes/test/Contract/uni.test.js +0 -289
  61. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +0 -228
  62. package/dist/cjs/providers/test/get-transaction-count.test.js +0 -239
  63. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +0 -375
  64. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +0 -217
  65. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +0 -223
  66. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +0 -163
  67. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +0 -414
  68. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +0 -282
  69. package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +0 -187
  70. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +0 -167
  71. package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +0 -219
  72. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +0 -232
  73. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +0 -280
  74. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +0 -266
  75. package/dist/cjs/providers/test/test-alchemy-provider.test.js +0 -151
  76. package/dist/cjs/shared/tiny-big/helpers.test.js +0 -29
  77. package/dist/cjs/shared/tiny-big/tiny-big.test.js +0 -34
  78. package/dist/cjs/utils/tests/bytes/arrayify.test.js +0 -64
  79. package/dist/cjs/utils/tests/bytes/concat.test.js +0 -17
  80. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +0 -65
  81. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +0 -66
  82. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +0 -51
  83. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +0 -75
  84. package/dist/cjs/utils/tests/bytes/hex-value.test.js +0 -141
  85. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +0 -100
  86. package/dist/cjs/utils/tests/bytes/hexlify.test.js +0 -78
  87. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +0 -68
  88. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +0 -76
  89. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +0 -97
  90. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +0 -106
  91. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +0 -144
  92. package/dist/cjs/utils/tests/compute-address.test.js +0 -49
  93. package/dist/cjs/utils/tests/compute-public-key.test.js +0 -26
  94. package/dist/cjs/utils/tests/ether-to-gwei.test.js +0 -26
  95. package/dist/cjs/utils/tests/ether-to-wei.test.js +0 -36
  96. package/dist/cjs/utils/tests/gwei-to-ether.test.js +0 -28
  97. package/dist/cjs/utils/tests/hash-message.test.js +0 -32
  98. package/dist/cjs/utils/tests/is-address.test.js +0 -48
  99. package/dist/cjs/utils/tests/keccak256.test.js +0 -121
  100. package/dist/cjs/utils/tests/solidity-keccak256.test.js +0 -311
  101. package/dist/cjs/utils/tests/split-signature.test.js +0 -46
  102. package/dist/cjs/utils/tests/to-checksum-address.test.js +0 -39
  103. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +0 -34
  104. package/dist/cjs/utils/tests/wei-to-ether.test.js +0 -41
@@ -1,228 +0,0 @@
1
- // performance polyfill required to support node <= 14
2
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
3
- try {
4
- var info = gen[key](arg);
5
- var value = info.value;
6
- } catch (error) {
7
- reject(error);
8
- return;
9
- }
10
- if (info.done) {
11
- resolve(value);
12
- } else {
13
- Promise.resolve(value).then(_next, _throw);
14
- }
15
- }
16
- function _async_to_generator(fn) {
17
- return function() {
18
- var self = this, args = arguments;
19
- return new Promise(function(resolve, reject) {
20
- var gen = fn.apply(self, args);
21
- function _next(value) {
22
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
23
- }
24
- function _throw(err) {
25
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
26
- }
27
- _next(undefined);
28
- });
29
- };
30
- }
31
- function _ts_generator(thisArg, body) {
32
- var f, y, t, g, _ = {
33
- label: 0,
34
- sent: function() {
35
- if (t[0] & 1) throw t[1];
36
- return t[1];
37
- },
38
- trys: [],
39
- ops: []
40
- };
41
- return g = {
42
- next: verb(0),
43
- "throw": verb(1),
44
- "return": verb(2)
45
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
46
- return this;
47
- }), g;
48
- function verb(n) {
49
- return function(v) {
50
- return step([
51
- n,
52
- v
53
- ]);
54
- };
55
- }
56
- function step(op) {
57
- if (f) throw new TypeError("Generator is already executing.");
58
- while(_)try {
59
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
60
- if (y = 0, t) op = [
61
- op[0] & 2,
62
- t.value
63
- ];
64
- switch(op[0]){
65
- case 0:
66
- case 1:
67
- t = op;
68
- break;
69
- case 4:
70
- _.label++;
71
- return {
72
- value: op[1],
73
- done: false
74
- };
75
- case 5:
76
- _.label++;
77
- y = op[1];
78
- op = [
79
- 0
80
- ];
81
- continue;
82
- case 7:
83
- op = _.ops.pop();
84
- _.trys.pop();
85
- continue;
86
- default:
87
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
88
- _ = 0;
89
- continue;
90
- }
91
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
92
- _.label = op[1];
93
- break;
94
- }
95
- if (op[0] === 6 && _.label < t[1]) {
96
- _.label = t[1];
97
- t = op;
98
- break;
99
- }
100
- if (t && _.label < t[2]) {
101
- _.label = t[2];
102
- _.ops.push(op);
103
- break;
104
- }
105
- if (t[2]) _.ops.pop();
106
- _.trys.pop();
107
- continue;
108
- }
109
- op = body.call(thisArg, _);
110
- } catch (e) {
111
- op = [
112
- 6,
113
- e
114
- ];
115
- y = 0;
116
- } finally{
117
- f = t = 0;
118
- }
119
- if (op[0] & 5) throw op[1];
120
- return {
121
- value: op[0] ? op[1] : void 0,
122
- done: true
123
- };
124
- }
125
- }
126
- import { performance } from "perf_hooks";
127
- import { FallthroughProvider } from "../../../index";
128
- import { rpcUrls } from "../rpc-urls";
129
- var rpcUrl = rpcUrls.mainnet;
130
- function timePromise(fn) {
131
- var onPromiseDone = function() {
132
- return performance.now() - start;
133
- };
134
- var start = performance.now();
135
- return fn().then(onPromiseDone, onPromiseDone);
136
- }
137
- describe("provider.getGasPrice", function() {
138
- it("should fallthrough on several types of invalid urls", /*#__PURE__*/ _async_to_generator(function() {
139
- var essentialEthProvider, block;
140
- return _ts_generator(this, function(_state) {
141
- switch(_state.label){
142
- case 0:
143
- essentialEthProvider = new FallthroughProvider([
144
- "https://bad-123123123123.com",
145
- "https://bad-523123123123.com",
146
- rpcUrl
147
- ]);
148
- return [
149
- 4,
150
- essentialEthProvider.getBlock(14631185)
151
- ];
152
- case 1:
153
- block = _state.sent();
154
- expect(block.gasUsed.toString()).toBe("2429588");
155
- return [
156
- 2
157
- ];
158
- }
159
- });
160
- }));
161
- it("should fallthrough after timeout linearly", /*#__PURE__*/ _async_to_generator(function() {
162
- var essentialEthProvider;
163
- return _ts_generator(this, function(_state) {
164
- switch(_state.label){
165
- case 0:
166
- essentialEthProvider = new FallthroughProvider([
167
- "https://flash-the-slow-api.herokuapp.com/delay/10000",
168
- // url with request delayed by 20 seconds
169
- "https://flash-the-slow-api.herokuapp.com/delay/10000",
170
- "https://bad-523123123123.com",
171
- rpcUrl
172
- ], {
173
- timeoutDuration: 1000
174
- });
175
- return [
176
- 4,
177
- timePromise(function() {
178
- return essentialEthProvider.getBlock(14631000);
179
- }).then(function(duration) {
180
- // times out the first two requests in 1200 ms each
181
- // expect(duration).toBeGreaterThan(1200);
182
- // finished the last valid request within two seconds
183
- expect(duration).toBeLessThan(4000);
184
- })
185
- ];
186
- case 1:
187
- _state.sent();
188
- return [
189
- 2
190
- ];
191
- }
192
- });
193
- }));
194
- it("should mutex the current rpc selection properly", /*#__PURE__*/ _async_to_generator(function() {
195
- var providers, allBlocks;
196
- return _ts_generator(this, function(_state) {
197
- switch(_state.label){
198
- case 0:
199
- providers = [
200
- 1,
201
- 2,
202
- 3
203
- ].map(function() {
204
- return new FallthroughProvider([
205
- "https://flash-sgkl.onrender.com/delay/10000",
206
- rpcUrl
207
- ], {
208
- timeoutDuration: 2500
209
- });
210
- });
211
- return [
212
- 4,
213
- Promise.all(providers.map(function(provider) {
214
- return provider.getBlock(123456);
215
- }))
216
- ];
217
- case 1:
218
- allBlocks = _state.sent();
219
- allBlocks.forEach(function(blockNumber) {
220
- expect(blockNumber.difficulty.toString()).toBe("4505282870523");
221
- });
222
- return [
223
- 2
224
- ];
225
- }
226
- });
227
- }));
228
- });
@@ -1,239 +0,0 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
- try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
14
- }
15
- function _async_to_generator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(undefined);
27
- });
28
- };
29
- }
30
- function _ts_generator(thisArg, body) {
31
- var f, y, t, g, _ = {
32
- label: 0,
33
- sent: function() {
34
- if (t[0] & 1) throw t[1];
35
- return t[1];
36
- },
37
- trys: [],
38
- ops: []
39
- };
40
- return g = {
41
- next: verb(0),
42
- "throw": verb(1),
43
- "return": verb(2)
44
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
- return this;
46
- }), g;
47
- function verb(n) {
48
- return function(v) {
49
- return step([
50
- n,
51
- v
52
- ]);
53
- };
54
- }
55
- function step(op) {
56
- if (f) throw new TypeError("Generator is already executing.");
57
- while(_)try {
58
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
- if (y = 0, t) op = [
60
- op[0] & 2,
61
- t.value
62
- ];
63
- switch(op[0]){
64
- case 0:
65
- case 1:
66
- t = op;
67
- break;
68
- case 4:
69
- _.label++;
70
- return {
71
- value: op[1],
72
- done: false
73
- };
74
- case 5:
75
- _.label++;
76
- y = op[1];
77
- op = [
78
- 0
79
- ];
80
- continue;
81
- case 7:
82
- op = _.ops.pop();
83
- _.trys.pop();
84
- continue;
85
- default:
86
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
- _ = 0;
88
- continue;
89
- }
90
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
- _.label = op[1];
92
- break;
93
- }
94
- if (op[0] === 6 && _.label < t[1]) {
95
- _.label = t[1];
96
- t = op;
97
- break;
98
- }
99
- if (t && _.label < t[2]) {
100
- _.label = t[2];
101
- _.ops.push(op);
102
- break;
103
- }
104
- if (t[2]) _.ops.pop();
105
- _.trys.pop();
106
- continue;
107
- }
108
- op = body.call(thisArg, _);
109
- } catch (e) {
110
- op = [
111
- 6,
112
- e
113
- ];
114
- y = 0;
115
- } finally{
116
- f = t = 0;
117
- }
118
- if (op[0] & 5) throw op[1];
119
- return {
120
- value: op[0] ? op[1] : void 0,
121
- done: true
122
- };
123
- }
124
- }
125
- import * as unfetch from "isomorphic-unfetch";
126
- import { jsonRpcProvider, tinyBig } from "../..";
127
- import { buildFetchInit, buildRPCPostBody } from "../../classes/utils/fetchers";
128
- import { mockOf } from "./mock-of";
129
- import { rpcUrls } from "./rpc-urls";
130
- jest.mock("isomorphic-unfetch");
131
- var address = "0x71660c4005ba85c37ccec55d0c4493e66fe775d3";
132
- function testGetTC(rpcUrl, blockTag) {
133
- return _testGetTC.apply(this, arguments);
134
- }
135
- function _testGetTC() {
136
- _testGetTC = _async_to_generator(function(rpcUrl, blockTag) {
137
- var provider, mockPostResponse, spy, transactionCount, expectedBlockTag;
138
- return _ts_generator(this, function(_state) {
139
- switch(_state.label){
140
- case 0:
141
- provider = jsonRpcProvider(rpcUrl);
142
- mockPostResponse = JSON.stringify({
143
- jsonrpc: "2.0",
144
- id: 1,
145
- result: "0xa"
146
- });
147
- mockOf(unfetch.default).mockResolvedValueOnce({
148
- text: function() {
149
- return Promise.resolve(mockPostResponse);
150
- }
151
- });
152
- spy = jest.spyOn(unfetch, "default");
153
- return [
154
- 4,
155
- provider.getTransactionCount(address, blockTag)
156
- ];
157
- case 1:
158
- transactionCount = _state.sent();
159
- expect(transactionCount.toString()).toBe("10");
160
- expectedBlockTag = typeof blockTag === "number" ? tinyBig(blockTag).toHexString() : blockTag !== null && blockTag !== void 0 ? blockTag : "latest";
161
- expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody("eth_getTransactionCount", [
162
- address,
163
- expectedBlockTag
164
- ])));
165
- return [
166
- 2
167
- ];
168
- }
169
- });
170
- });
171
- return _testGetTC.apply(this, arguments);
172
- }
173
- describe("provider.getTransactionCount matic", function() {
174
- var rpcUrl = rpcUrls.matic;
175
- it("should get the latest by the latest block", /*#__PURE__*/ _async_to_generator(function() {
176
- return _ts_generator(this, function(_state) {
177
- switch(_state.label){
178
- case 0:
179
- return [
180
- 4,
181
- testGetTC(rpcUrl, "latest")
182
- ];
183
- case 1:
184
- _state.sent();
185
- return [
186
- 2
187
- ];
188
- }
189
- });
190
- }));
191
- it("should get transaction count by default latest block", /*#__PURE__*/ _async_to_generator(function() {
192
- return _ts_generator(this, function(_state) {
193
- switch(_state.label){
194
- case 0:
195
- return [
196
- 4,
197
- testGetTC(rpcUrl)
198
- ];
199
- case 1:
200
- _state.sent();
201
- return [
202
- 2
203
- ];
204
- }
205
- });
206
- }));
207
- it("should get transaction count by earliest block", /*#__PURE__*/ _async_to_generator(function() {
208
- return _ts_generator(this, function(_state) {
209
- switch(_state.label){
210
- case 0:
211
- return [
212
- 4,
213
- testGetTC(rpcUrl, "earliest")
214
- ];
215
- case 1:
216
- _state.sent();
217
- return [
218
- 2
219
- ];
220
- }
221
- });
222
- }));
223
- it("should get TC by block number", /*#__PURE__*/ _async_to_generator(function() {
224
- return _ts_generator(this, function(_state) {
225
- switch(_state.label){
226
- case 0:
227
- return [
228
- 4,
229
- testGetTC(rpcUrl, 14649390)
230
- ];
231
- case 1:
232
- _state.sent();
233
- return [
234
- 2
235
- ];
236
- }
237
- });
238
- }));
239
- });