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
@@ -0,0 +1,224 @@
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 _asyncToGenerator(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
+ var __generator = this && this.__generator || function(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 { JsonRpcProvider } from "../../../index";
126
+ import { Contract as EssentialEthContract } from "../../Contract";
127
+ import { rpcUrls } from "./../../../providers/test/rpc-urls";
128
+ import { feiABI } from "./fei-abi";
129
+ // The JSONABI
130
+ var JSONABI = feiABI;
131
+ var rpcURL = rpcUrls.mainnet;
132
+ var essentialEthProvider = new JsonRpcProvider(rpcURL);
133
+ // https://etherscan.io/address/0xBFfB152b9392e38CdDc275D818a3Db7FE364596b
134
+ var contractAddress = "0xBFfB152b9392e38CdDc275D818a3Db7FE364596b";
135
+ var smartContractGetFeiAmountsToRedeem = function() {
136
+ var _ref = _asyncToGenerator(function(contract, address) {
137
+ var merkleRoot;
138
+ return __generator(this, function(_state) {
139
+ switch(_state.label){
140
+ case 0:
141
+ return [
142
+ 4,
143
+ contract.getAmountsToRedeem(address)
144
+ ];
145
+ case 1:
146
+ merkleRoot = _state.sent();
147
+ return [
148
+ 2,
149
+ merkleRoot
150
+ ];
151
+ }
152
+ });
153
+ });
154
+ return function smartContractGetFeiAmountsToRedeem(contract, address) {
155
+ return _ref.apply(this, arguments);
156
+ };
157
+ }();
158
+ var essentialEthContract = new EssentialEthContract(contractAddress, JSONABI, essentialEthProvider);
159
+ describe("fEI contract", function() {
160
+ it('should fetch unclaimed amounts "[uint256, uint256, uint256]" data-type', /*#__PURE__*/ _asyncToGenerator(function() {
161
+ var essentialEthResponse;
162
+ return __generator(this, function(_state) {
163
+ switch(_state.label){
164
+ case 0:
165
+ return [
166
+ 4,
167
+ smartContractGetFeiAmountsToRedeem(essentialEthContract, "0xf5dBA31743ea341057280bb3AdD5c2Fb505BDC4C")
168
+ ];
169
+ case 1:
170
+ essentialEthResponse = _state.sent();
171
+ expect(essentialEthResponse[0].toString()).toBe("0");
172
+ expect(essentialEthResponse[1].toString()).toBe("0");
173
+ expect(essentialEthResponse[2].toString()).toBe("0");
174
+ expect(essentialEthResponse[2].toNumber()).toBe(0);
175
+ return [
176
+ 2
177
+ ];
178
+ }
179
+ });
180
+ }));
181
+ it('should fetch "uint8" data-type', /*#__PURE__*/ _asyncToGenerator(function() {
182
+ var essentialEthResponse;
183
+ return __generator(this, function(_state) {
184
+ switch(_state.label){
185
+ case 0:
186
+ return [
187
+ 4,
188
+ essentialEthContract.decimals()
189
+ ];
190
+ case 1:
191
+ essentialEthResponse = _state.sent();
192
+ expect(essentialEthResponse).toBe(18);
193
+ return [
194
+ 2
195
+ ];
196
+ }
197
+ });
198
+ }));
199
+ it('should fetch "string" name data-type', /*#__PURE__*/ _asyncToGenerator(function() {
200
+ var essentialEthResponse, essential2EthResponse;
201
+ return __generator(this, function(_state) {
202
+ switch(_state.label){
203
+ case 0:
204
+ return [
205
+ 4,
206
+ essentialEthContract.symbol()
207
+ ];
208
+ case 1:
209
+ essentialEthResponse = _state.sent();
210
+ expect(essentialEthResponse).toBe("FGEN");
211
+ return [
212
+ 4,
213
+ essentialEthContract.name()
214
+ ];
215
+ case 2:
216
+ essential2EthResponse = _state.sent();
217
+ expect(essential2EthResponse).toBe("Fei Genesis Group");
218
+ return [
219
+ 2
220
+ ];
221
+ }
222
+ });
223
+ }));
224
+ });
@@ -1,42 +1,65 @@
1
- "use strict";
2
1
  // https://docs.soliditylang.org/en/v0.6.8/abi-spec.html#examples
3
2
  // contract Foo {
4
3
  // function bar(bytes3[2] memory) public pure {}
5
4
  // function baz(uint32 x, bool y) public pure returns (bool r) { r = x > 32 || y; }
6
5
  // function sam(bytes memory, bool, uint[] memory) public pure {}
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.fooABI = void 0;
9
6
  // }
10
- exports.fooABI = [
7
+ export var fooABI = [
11
8
  {
12
9
  inputs: [
13
10
  {
14
- internalType: 'bytes3[2]',
15
- name: 'memory',
16
- type: 'bytes3[2]',
17
- },
11
+ internalType: "bytes3[2]",
12
+ name: "memory",
13
+ type: "bytes3[2]"
14
+ }
18
15
  ],
19
- name: 'bar',
16
+ name: "bar",
20
17
  outputs: [],
21
- type: 'function',
18
+ type: "function"
22
19
  },
23
20
  {
24
21
  inputs: [
25
- { internalType: 'uint32', name: 'x', type: 'uint32' },
26
- { internalType: 'bool', name: 'y', type: 'bool' },
22
+ {
23
+ internalType: "uint32",
24
+ name: "x",
25
+ type: "uint32"
26
+ },
27
+ {
28
+ internalType: "bool",
29
+ name: "y",
30
+ type: "bool"
31
+ }
32
+ ],
33
+ name: "baz",
34
+ outputs: [
35
+ {
36
+ internalType: "bool",
37
+ name: "r",
38
+ type: "bool"
39
+ }
27
40
  ],
28
- name: 'baz',
29
- outputs: [{ internalType: 'bool', name: 'r', type: 'bool' }],
30
- type: 'function',
41
+ type: "function"
31
42
  },
32
43
  {
33
44
  inputs: [
34
- { internalType: 'bytes', name: 'memory', type: 'bytes' },
35
- { internalType: 'bool', name: '', type: 'bool' },
36
- { internalType: 'uint[]', name: 'memory', type: 'uint[]' },
45
+ {
46
+ internalType: "bytes",
47
+ name: "memory",
48
+ type: "bytes"
49
+ },
50
+ {
51
+ internalType: "bool",
52
+ name: "",
53
+ type: "bool"
54
+ },
55
+ {
56
+ internalType: "uint[]",
57
+ name: "memory",
58
+ type: "uint[]"
59
+ }
37
60
  ],
38
- name: 'sam',
61
+ name: "sam",
39
62
  outputs: [],
40
- type: 'function',
41
- },
63
+ type: "function"
64
+ }
42
65
  ];
@@ -0,0 +1,33 @@
1
+ import { encodeData } from "../../utils/encode-decode-transaction";
2
+ import { fooABI } from "./foo-abi";
3
+ describe("foo encode", function() {
4
+ it('encodes "baz" function', function() {
5
+ var jsonABIArgument = fooABI.find(function(abi) {
6
+ return abi.name === "baz";
7
+ });
8
+ var encoded = encodeData(jsonABIArgument, [
9
+ 69,
10
+ true
11
+ ]);
12
+ expect(encoded).toBe("0xcdcd77c000000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001");
13
+ });
14
+ it('encodes "bar" function', function() {
15
+ var jsonABIArgument = fooABI.find(function(abi) {
16
+ return abi.name === "bar";
17
+ });
18
+ var encoded = encodeData(jsonABIArgument, [
19
+ "abc",
20
+ "def"
21
+ ]);
22
+ expect(encoded).toBe("0xfce353f661626300000000000000000000000000000000000000000000000000000000006465660000000000000000000000000000000000000000000000000000000000");
23
+ });
24
+ // it('encodes "sam" function', () => {
25
+ // const jsonABIArgument = fooABI.find(
26
+ // (abi) => abi.name === 'sam',
27
+ // ) as JSONABIArgument;
28
+ // const encoded = encodeData(jsonABIArgument, ['dave', true, [1, 2, 3]]);
29
+ // expect(encoded).toBe(
30
+ // '0xa5643bf20000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000464617665000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003',
31
+ // );
32
+ // });
33
+ });