ethereum-input-data-decode 0.4.2

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.

Potentially problematic release.


This version of ethereum-input-data-decode might be problematic. Click here for more details.

Files changed (46) hide show
  1. package/.editorconfig +23 -0
  2. package/.gitattributes +2 -0
  3. package/.github/FUNDING.yml +2 -0
  4. package/.travis.yml +10 -0
  5. package/CHANGELOG.md +5 -0
  6. package/LICENSE +21 -0
  7. package/README.md +283 -0
  8. package/bin/ethereum_input_data_decoder +3 -0
  9. package/cli.js +85 -0
  10. package/dist/index.d.ts +19 -0
  11. package/dist/index.js +396 -0
  12. package/example/bundle.js +33425 -0
  13. package/example/index.html +1213 -0
  14. package/example/main.js +35 -0
  15. package/example/style.css +28 -0
  16. package/index.d.ts +19 -0
  17. package/index.js +362 -0
  18. package/package.json +60 -0
  19. package/test/cli_test.js +1 -0
  20. package/test/data/0x_exchange.json +882 -0
  21. package/test/data/0x_exchange_data.txt +1 -0
  22. package/test/data/1inch_exchange_v2_abi.json +404 -0
  23. package/test/data/1inch_exchange_v2_abi_no_eth.txt +1 -0
  24. package/test/data/1inch_exchange_v2_abi_with_eth.txt +1 -0
  25. package/test/data/PayableProxyForSoloMargin_abi.json +134 -0
  26. package/test/data/PayableProxyForSoloMargin_tx_data.txt +1 -0
  27. package/test/data/abi1.json +1171 -0
  28. package/test/data/abi1_input_data.txt +1 -0
  29. package/test/data/abi2.json +1 -0
  30. package/test/data/abi3.json +1 -0
  31. package/test/data/abi3_data.txt +1 -0
  32. package/test/data/abi4.json +2 -0
  33. package/test/data/abi4_data.txt +1 -0
  34. package/test/data/abi5.json +1 -0
  35. package/test/data/abi5_data.txt +1 -0
  36. package/test/data/abi6.json +1 -0
  37. package/test/data/abi6_data.txt +1 -0
  38. package/test/data/abi7.json +1 -0
  39. package/test/data/abi7_data.txt +1 -0
  40. package/test/data/contract_creation_data.txt +2 -0
  41. package/test/data/erc721_abi.json +1 -0
  42. package/test/data/erc721_transferfrom_tx_data.txt +1 -0
  43. package/test/data/set_exchange_issuance_lib.json +195 -0
  44. package/test/data/set_issuance.txt +1 -0
  45. package/test/index.js +628 -0
  46. package/tsconfig.json +27 -0
package/test/index.js ADDED
@@ -0,0 +1,628 @@
1
+ const fs = require('fs')
2
+ const test = require('tape')
3
+ const InputDataDecoder = require('../index')
4
+
5
+ test('decoder', t => {
6
+ // https://etherscan.io/tx/0xa6f019f2fc916bd8df607f1c99148ebb06322999ff08bc88927fe8406acae1b2
7
+ const data = fs.readFileSync(`${__dirname}/data/abi1_input_data.txt`)
8
+ t.test('abi filepath', t => {
9
+ t.plan(6)
10
+ const decoder = new InputDataDecoder(`${__dirname}/data/abi1.json`)
11
+
12
+ const result = decoder.decodeData(data)
13
+ t.equal(result.method, 'registerOffChainDonation')
14
+ t.deepEqual(result.types, [
15
+ 'address',
16
+ 'uint256',
17
+ 'uint256',
18
+ 'string',
19
+ 'bytes32'
20
+ ])
21
+ t.equal(result.inputs[0].toString(16).toLowerCase(), '5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02')
22
+ t.equal(result.inputs[1].toHexString(), '0x58a20230')
23
+ t.equal(result.inputs[2].toHexString(), '0x402934')
24
+ t.equal(result.inputs[3], 'BTC')
25
+ t.end()
26
+ })
27
+
28
+ t.test('abi array object', t => {
29
+ t.plan(7)
30
+ const abi = JSON.parse(fs.readFileSync(`${__dirname}/data/abi1.json`))
31
+ const decoder = new InputDataDecoder(abi)
32
+
33
+ const result = decoder.decodeData(data)
34
+ t.equal(result.method, 'registerOffChainDonation')
35
+ t.deepEqual(result.types, ['address', 'uint256', 'uint256', 'string', 'bytes32'])
36
+ t.equal(result.inputs[0].toString().toLowerCase(), '5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02')
37
+ t.equal(result.inputs[1].toHexString(), '0x58a20230')
38
+ t.equal(result.inputs[2].toHexString(), '0x402934')
39
+ t.equal(result.inputs[3], 'BTC')
40
+ t.deepEqual(result.names, ['addr', 'timestamp', 'chfCents', 'currency', 'memo'])
41
+ t.end()
42
+ })
43
+
44
+ // https://etherscan.io/tx/0xc7add41f6ae5e4fe268f654709f450983510ab7da67812be608faf2133a90b5a
45
+ t.test('contract creation data (constructor)', t => {
46
+ t.plan(4)
47
+
48
+ const abi = JSON.parse(fs.readFileSync(`${__dirname}/data/abi1.json`))
49
+ const decoder = new InputDataDecoder(abi)
50
+
51
+ const data = fs.readFileSync(`${__dirname}/data/contract_creation_data.txt`)
52
+ const result = decoder.decodeData(data)
53
+
54
+ t.equal(result.inputs[0].toString(16), '0xB2Cb826C945D8Df01802b5cf3c4105685D4933A0')
55
+ t.equal(result.inputs[1].toString(16), 'STIFTUNG Dfinity FDC')
56
+
57
+ t.equal(result.names[0].toString(), '_masterAuth')
58
+ t.equal(result.names[1].toString(), '_name')
59
+ })
60
+
61
+ // https://etherscan.io/tx/0x94fadf5f5c7805b8ceb8a13a0a7fbce06054ff08cdfdc2fd555a7902592aebe6
62
+ t.test('erc721 transferFrom', t => {
63
+ t.plan(6)
64
+
65
+ const abi = JSON.parse(fs.readFileSync(`${__dirname}/data/erc721_abi.json`))
66
+ const decoder = new InputDataDecoder(abi)
67
+
68
+ const data = fs.readFileSync(`${__dirname}/data/erc721_transferfrom_tx_data.txt`)
69
+ const result = decoder.decodeData(data)
70
+
71
+ t.equal(result.inputs[0].toString().toLowerCase(), '10017ca37b1257ac0771e24652aa28c758e378eb')
72
+ t.equal(result.inputs[1].toString().toLowerCase(), 'e7a632d89104385bdd3992eeb82cffeb48e4e539')
73
+ t.equal(result.inputs[2].toHexString(), '0x5dc5')
74
+
75
+ t.equal(result.names[0], '_from')
76
+ t.equal(result.names[1], '_to')
77
+ t.equal(result.names[2], '_tokenId')
78
+ })
79
+
80
+ // marketSellOrders call
81
+ // https://etherscan.io/tx/0xc79ee30142e935453eabd57f45e01bb394bff78d05cdf8df97631b03ad6cc0cd
82
+ t.test('0x exchange sell (abiv2 tuple[])', t => {
83
+ t.plan(4)
84
+
85
+ const abi = JSON.parse(fs.readFileSync(`${__dirname}/data/0x_exchange.json`))
86
+ const decoder = new InputDataDecoder(abi)
87
+
88
+ const data = fs.readFileSync(`${__dirname}/data/0x_exchange_data.txt`)
89
+ const result = decoder.decodeData(data)
90
+
91
+ t.deepEqual(result.method, 'marketSellOrders')
92
+
93
+ const expectedInputs = [
94
+ [
95
+ [
96
+ '0x6f02E6d47147B4448Fe2f2eb25B4f534cf110c23',
97
+ '0x0000000000000000000000000000000000000000',
98
+ '0xA258b39954ceF5cB142fd567A46cDdB31a670124',
99
+ '0x0000000000000000000000000000000000000000',
100
+ { 'type': 'BigNumber', 'hex': '0x410d586a20a4bffff5' },
101
+ { 'type': 'BigNumber', 'hex': '0x5e05647aedbbd450' },
102
+ { 'type': 'BigNumber', 'hex': '0x00' },
103
+ { 'type': 'BigNumber', 'hex': '0x00' },
104
+ { 'type': 'BigNumber', 'hex': '0x5d787202' },
105
+ { 'type': 'BigNumber', 'hex': '0x016d1e79ae50' },
106
+ '0xf47261b000000000000000000000000089d24a6b4ccb1b6faa2625fe562bdd9a23260359',
107
+ '0xf47261b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
108
+ ]
109
+ ],
110
+ { 'type': 'BigNumber', 'hex': '0x2386f26fc10000' },
111
+ ['0x1b82e97aa18170e6b81ce3a829d77b7067cf3644c8706e97e7c96d5a92de61eb0c5c5aeb4fbfadca6b9fbc5adff91bfb32964aa9e1bf8309dad7e1bd3e45f0b44c03']
112
+ ]
113
+
114
+ t.deepEqual(JSON.stringify(result.inputs), JSON.stringify(expectedInputs))
115
+
116
+ const expectedTypes = [
117
+ '(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes)[]',
118
+ 'uint256',
119
+ 'bytes[]'
120
+ ]
121
+
122
+ t.deepEqual(result.types, expectedTypes)
123
+
124
+ const expectedNames = [
125
+ [
126
+ 'orders',
127
+ [
128
+ 'makerAddress',
129
+ 'takerAddress',
130
+ 'feeRecipientAddress',
131
+ 'senderAddress',
132
+ 'makerAssetAmount',
133
+ 'takerAssetAmount',
134
+ 'makerFee',
135
+ 'takerFee',
136
+ 'expirationTimeSeconds',
137
+ 'salt',
138
+ 'makerAssetData',
139
+ 'takerAssetData'
140
+ ]
141
+ ],
142
+ 'takerAssetFillAmount',
143
+ 'signatures'
144
+ ]
145
+
146
+ t.deepEqual(result.names, expectedNames)
147
+ })
148
+
149
+ // https://etherscan.io/tx/0xcb0c447659123c5faa2f1e5bc8ac69697688f437c92a8abb4b882bb33cbc661a
150
+ t.test('set issuance (abiv2 tuple)', t => {
151
+ t.plan(4)
152
+
153
+ const abi = JSON.parse(fs.readFileSync(`${__dirname}/data/set_exchange_issuance_lib.json`))
154
+ const decoder = new InputDataDecoder(abi)
155
+
156
+ const data = fs.readFileSync(`${__dirname}/data/set_issuance.txt`)
157
+ const result = decoder.decodeData(data)
158
+
159
+ t.equal(result.method, 'issueRebalancingSetWithEther')
160
+
161
+ const expectedInputs = [
162
+ '0x81c55017F7Ce6E72451cEd49FF7bAB1e3DF64d0C',
163
+ { 'type': 'BigNumber', 'hex': '0x27019ab6af611240' },
164
+ [
165
+ '0xA37dE6790861B5541b0dAa7d0C0e651F44c6f4D9',
166
+ { 'type': 'BigNumber', 'hex': '0x3bf6ab7ba24000' },
167
+ [1],
168
+ ['0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'],
169
+ [{ 'type': 'BigNumber', 'hex': '0x1a04a045412d3457' }],
170
+ [
171
+ '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359',
172
+ '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599'
173
+ ],
174
+ [
175
+ { 'type': 'BigNumber', 'hex': '0x06989640c83ea4a200' },
176
+ { 'type': 'BigNumber', 'hex': '0x19c110' }
177
+ ]
178
+ ],
179
+ '0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000040400000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000000000000000d5a4cdef78c36901bc9ab7c3108c7d7b06f183e7d71c591bb6c677e3fa2958310a2520b916b792c6538b8e43ccb9a1773e94daa441307827c377f3b197d6549f9de54794a806b697a0300000000000000000000000056178a0d5f301baf6cf3e1cd53d9863437345bf90000000000000000000000000acd0b5cf881cd8398ac563872209de1ce15df0f00000000000000000000000055662e225a3376759c24331a9aed764f8f0c9fbb0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006b70202a2f0d520000000000000000000000000000000000000000000000000000d97e20f757ec00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005dfa648800000000000000000000000000000000000000000000000015e187ad8bbe980000000000000000000000000089d24a6b4ccb1b6faa2625fe562bdd9a23260359000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000000000000000caa536649a0fdc71bd88fc3a7ecf72f2082e39783296db7a0236b404ca968873f51ce89b4237ecdcf0da1d3cee4306348664629deacaca7f7961ada746036229c5b161612cdb96bad0300000000000000000000000056178a0d5f301baf6cf3e1cd53d9863437345bf90000000000000000000000000acd0b5cf881cd8398ac563872209de1ce15df0f00000000000000000000000055662e225a3376759c24331a9aed764f8f0c9fbb000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a38050000000000000000000000000000000000000000000000000ce4d38704d0c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005dfa648800000000000000000000000000000000000000000000000015e187ad8bbe98000000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
180
+ true
181
+ ]
182
+
183
+ t.deepEqual(JSON.stringify(result.inputs), JSON.stringify(expectedInputs))
184
+
185
+ const expectedNames = [
186
+ '_rebalancingSetAddress',
187
+ '_rebalancingSetQuantity',
188
+ [
189
+ '_exchangeIssuanceParams',
190
+ [
191
+ 'setAddress',
192
+ 'quantity',
193
+ 'sendTokenExchangeIds',
194
+ 'sendTokens',
195
+ 'sendTokenAmounts',
196
+ 'receiveTokens',
197
+ 'receiveTokenAmounts'
198
+ ]
199
+ ],
200
+ '_orderData',
201
+ '_keepChangeInVault'
202
+ ]
203
+ t.deepEqual(result.names, expectedNames)
204
+
205
+ const expectedTypes = [
206
+ 'address',
207
+ 'uint256',
208
+ '(address,uint256,uint8[],address[],uint256[],address[],uint256[])',
209
+ 'bytes',
210
+ 'bool'
211
+ ]
212
+ t.deepEqual(result.types, expectedTypes)
213
+ })
214
+
215
+ // https://github.com/miguelmota/ethereum-input-data-decoder/issues/8
216
+ t.test('256 address', t => {
217
+ t.plan(2)
218
+ const decoder = new InputDataDecoder(`${__dirname}/data/abi2.json`)
219
+
220
+ const data = '0xa9059cbb85f1150654584d0192059454e9dc1532d9d9cf914926406a02370cea80cf32f600000000000000000000000000000000000000000000000000000000033dc10b'
221
+
222
+ const result = decoder.decodeData(data)
223
+ t.equal(result.inputs[0].toString(16).toLowerCase(), 'e9dc1532d9d9cf914926406a02370cea80cf32f6')
224
+ t.equal(result.inputs[1].toString(10), '54378763')
225
+ })
226
+
227
+ // https://github.com/miguelmota/ethereum-input-data-decoder/issues/23
228
+ t.test('all inputs for operate(), (complex tuple hierarchies)', t => {
229
+ t.plan(3)
230
+ const decoder = new InputDataDecoder(`${__dirname}/data/PayableProxyForSoloMargin_abi.json`)
231
+ const data = fs.readFileSync(`${__dirname}/data/PayableProxyForSoloMargin_tx_data.txt`)
232
+ const result = decoder.decodeData(data)
233
+
234
+ const expectedInputs = [
235
+ [
236
+ [
237
+ '0xb929044aF6a7B7AE12EF0e653ACC59f73cf9577B', // accounts.owner
238
+ { 'type': 'BigNumber', 'hex': '0x00' } // accounts.number
239
+ ]
240
+ ],
241
+ [
242
+ [
243
+ 0,
244
+ { 'type': 'BigNumber', 'hex': '0x00' },
245
+ [true, 0, 0, { 'type': 'BigNumber', 'hex': '0x06c46038fa803f00' }],
246
+ { 'type': 'BigNumber', 'hex': '0x00' }, { 'type': 'BigNumber', 'hex': '0x00' },
247
+ '0xa8b39829cE2246f89B31C013b8Cde15506Fb9A76', // actions.otherAddress
248
+ { 'type': 'BigNumber', 'hex': '0x00' },
249
+ '0x'
250
+ ]
251
+ ],
252
+ '0xb929044aF6a7B7AE12EF0e653ACC59f73cf9577B' // sendEthTo
253
+ ]
254
+ const expectedNames = [
255
+ [
256
+ 'accounts',
257
+ ['owner', 'number']
258
+ ],
259
+ [
260
+ 'actions',
261
+ [
262
+ 'actionType',
263
+ 'accountId',
264
+ 'amount',
265
+ 'primaryMarketId',
266
+ 'secondaryMarketId',
267
+ 'otherAddress',
268
+ 'otherAccountId',
269
+ 'data'
270
+ ]
271
+ ],
272
+ 'sendEthTo'
273
+ ]
274
+ const expectedTypes = [
275
+ '(address,uint256)[]',
276
+ '(uint8,uint256,tuple,uint256,uint256,address,uint256,bytes)[]',
277
+ 'address'
278
+ ]
279
+
280
+ t.deepEqual(JSON.stringify(result.inputs), JSON.stringify(expectedInputs))
281
+ t.deepEqual(result.names, expectedNames)
282
+ t.deepEqual(result.types, expectedTypes)
283
+ })
284
+
285
+ // We found different behaviour for when WETH is used internally, so make sure to test for both cases
286
+ // - Alexander @ Blocknative
287
+ t.test('1inch swap tests, (common tuple[] usage with internalType)', t => {
288
+ t.plan(6)
289
+ const decoder = new InputDataDecoder(`${__dirname}/data/1inch_exchange_v2_abi.json`)
290
+
291
+ // https://etherscan.io/tx/0x4a62d52b5d084476e2cfd6eb4c5dfd8378147aa0186e117ed2710a7e54985ecf
292
+ const dataWithWeth = fs.readFileSync(`${__dirname}/data/1inch_exchange_v2_abi_with_eth.txt`)
293
+ // https://etherscan.io/tx/0x8ac7a9f4f9c8e788b2a4cb29e95f369ba09f0ef4c1bd064e6aa1517ce9247d38
294
+ const dataNoWeth = fs.readFileSync(`${__dirname}/data/1inch_exchange_v2_abi_no_eth.txt`)
295
+
296
+ const resultWithWeth = decoder.decodeData(dataWithWeth)
297
+ const resultNoWeth = decoder.decodeData(dataNoWeth)
298
+
299
+ const expectedTypes = ['address', '(address,address,address,address,uint256,uint256,uint256,uint256,address,bytes)', '(uint256,uint256,uint256,bytes)[]']
300
+
301
+ const expectedNames = [
302
+ 'caller', [
303
+ 'desc', [
304
+ 'srcToken',
305
+ 'dstToken',
306
+ 'srcReceiver',
307
+ 'dstReceiver',
308
+ 'amount',
309
+ 'minReturnAmount',
310
+ 'guaranteedAmount',
311
+ 'flags',
312
+ 'referrer',
313
+ 'permit'
314
+ ]], [
315
+ 'calls', [
316
+ 'targetWithMandatory',
317
+ 'gasLimit',
318
+ 'value',
319
+ 'data'
320
+ ]
321
+ ]
322
+ ]
323
+
324
+ const expectedInputsNoWeth = [
325
+ '0xe069CB01D06bA617bCDf789bf2ff0D5E5ca20C71',
326
+ [
327
+ '0xdAC17F958D2ee523a2206206994597C13D831ec7',
328
+ '0xF970b8E36e23F7fC3FD752EeA86f8Be8D83375A6',
329
+ '0xe069CB01D06bA617bCDf789bf2ff0D5E5ca20C71',
330
+ '0x2C38b7622241958DC0A097D405c468a9176418A3',
331
+ { 'type': 'BigNumber', 'hex': '0x0129c8e900' },
332
+ { 'type': 'BigNumber', 'hex': '0x0b8cfc3e036ef2502538' },
333
+ { 'type': 'BigNumber', 'hex': '0x0be8703fee6d197a3635' },
334
+ { 'type': 'BigNumber', 'hex': '0x04' },
335
+ '0x6884249C226F1443f2b7040A3d6143C170Df34F6',
336
+ '0x'
337
+ ], [
338
+ [
339
+ { 'type': 'BigNumber', 'hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
340
+ { 'type': 'BigNumber', 'hex': '0x00' },
341
+ { 'type': 'BigNumber', 'hex': '0x00' },
342
+ '0xeb5625d9000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb00000000000000000000000000000000000000000000000000000000129c8e900'
343
+ ], [
344
+ { 'type': 'BigNumber', 'hex': '0x8000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0' },
345
+ { 'type': 'BigNumber', 'hex': '0x00' },
346
+ { 'type': 'BigNumber', 'hex': '0x00' },
347
+ '0xc98fefed00000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000129c8e9000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000e069cb01d06ba617bcdf789bf2ff0d5e5ca20c710000000000000000000000000000000000000000000000000000000000000003000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000005365b5bc56493f08a38e5eb08e36cbbe6fcc83060000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c'
348
+ ], [
349
+ { 'type': 'BigNumber', 'hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
350
+ { 'type': 'BigNumber', 'hex': '0x00' },
351
+ { 'type': 'BigNumber', 'hex': '0x00' },
352
+ '0x83f1291f000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000003c00000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c000000000000000000000000000000500000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000064eb5625d90000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c0000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000008000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000104c98fefed000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000e069cb01d06ba617bcdf789bf2ff0d5e5ca20c7100000000000000000000000000000000000000000000000000000000000000030000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c000000000000000000000000f7b9fa01098f22527db205ff9bb6fdf7c7d9f1c5000000000000000000000000f970b8e36e23f7fc3fd752eea86f8be8d83375a600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000448000000000000000000000000000000000000000000000000000000000000024'
353
+ ], [
354
+ { 'type': 'BigNumber', 'hex': '0x00' },
355
+ { 'type': 'BigNumber', 'hex': '0x00' },
356
+ { 'type': 'BigNumber', 'hex': '0x00' },
357
+ '0x7f8fe7a000000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000044000000000000000000000000e069cb01d06ba617bcdf789bf2ff0d5e5ca20c7100000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a405971224000000000000000000000000f970b8e36e23f7fc3fd752eea86f8be8d83375a60000000000000000000000006884249c226f1443f2b7040a3d6143c170df34f600000000000000000000000000000000000000000000000000000000000000010000000000000000042b4998f6b3b8f500000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000004df804219786f1d7f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004470bdb947000000000000000000000000f970b8e36e23f7fc3fd752eea86f8be8d83375a6000000000000000000000000000000000000000000000be8703fee6d197a363500000000000000000000000000000000000000000000000000000000'
358
+ ], [
359
+ { 'type': 'BigNumber', 'hex': '0x00' },
360
+ { 'type': 'BigNumber', 'hex': '0x00' },
361
+ { 'type': 'BigNumber', 'hex': '0x00' },
362
+ '0xb3af37c000000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000024000000000000000000000000f970b8e36e23f7fc3fd752eea86f8be8d83375a60000000000000000000000000000000100000000000000000000000000000001000000000000000000000000f970b8e36e23f7fc3fd752eea86f8be8d83375a60000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000002c38b7622241958dc0a097d405c468a9176418a3000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000'
363
+ ]
364
+ ]
365
+ ]
366
+
367
+ const expectedInputsWithWeth = [
368
+ '0xb3C9669A5706477a2B237D98eDb9B57678926f04',
369
+ [
370
+ '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
371
+ '0x111111111117dC0aa78b770fA6A738034120C302',
372
+ '0xb3C9669A5706477a2B237D98eDb9B57678926f04',
373
+ '0x83B97790c7dA251FAFB24d6CbfC481cFa4AFc4F6',
374
+ { 'type': 'BigNumber', 'hex': '0x010642ac00' },
375
+ { 'type': 'BigNumber', 'hex': '0x34e551bf0ab692275a' },
376
+ { 'type': 'BigNumber', 'hex': '0x35f9ac3b1a9af32d62' },
377
+ { 'type': 'BigNumber', 'hex': '0x04' },
378
+ '0x382fFCe2287252F930E1C8DC9328dac5BF282bA1',
379
+ '0x'
380
+ ], [
381
+ [
382
+ { 'type': 'BigNumber', 'hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
383
+ { 'type': 'BigNumber', 'hex': '0x00' },
384
+ { 'type': 'BigNumber', 'hex': '0x00' },
385
+ '0xeb5625d9000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0000000000000000000000000000000000000000000000000000000010642ac00'
386
+ ], [
387
+ { 'type': 'BigNumber', 'hex': '0x8000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0' },
388
+ { 'type': 'BigNumber', 'hex': '0x00' },
389
+ { 'type': 'BigNumber', 'hex': '0x00' },
390
+ '0xc98fefed0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000010642ac000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000b3c9669a5706477a2b237d98edb9b57678926f040000000000000000000000000000000000000000000000000000000000000003000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000874d8de5b26c9d9f6aa8d7bab283f9a9c6f777f40000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c'
391
+ ], [
392
+ { 'type': 'BigNumber', 'hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
393
+ { 'type': 'BigNumber', 'hex': '0x00' },
394
+ { 'type': 'BigNumber', 'hex': '0x00' },
395
+ '0xb3af37c0000000000000000000000000000000000000000000000000000000000000008080000000000000000000000000000000000000000000000000000000000000240000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c00000000000000000000000000000014000000000000000000000000000000140000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000003fd4cf9303c4bc9e13772618828712c8eac7dd2f000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000'
396
+ ], [
397
+ { 'type': 'BigNumber', 'hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
398
+ { 'type': 'BigNumber', 'hex': '0x00' },
399
+ { 'type': 'BigNumber', 'hex': '0x00' },
400
+ '0xc9f12e9d0000000000000000000000003fd4cf9303c4bc9e13772618828712c8eac7dd2f0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000326aad2da94c59524ac0d93f6d6cbf9071d7086f20000000000000000000000000000000000000000000000000000000000000000'
401
+ ], [
402
+ { 'type': 'BigNumber', 'hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
403
+ { 'type': 'BigNumber', 'hex': '0x00' },
404
+ { 'type': 'BigNumber', 'hex': '0x00' },
405
+ '0xc9f12e9d00000000000000000000000026aad2da94c59524ac0d93f6d6cbf9071d7086f2000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000111111111117dc0aa78b770fa6a738034120c302000000000000000000000003b3c9669a5706477a2b237d98edb9b57678926f040000000000000000000000000000000000000000000000000000000000000000'
406
+ ], [
407
+ { 'type': 'BigNumber', 'hex': '0x00' },
408
+ { 'type': 'BigNumber', 'hex': '0x00' },
409
+ { 'type': 'BigNumber', 'hex': '0x00' },
410
+ '0x7f8fe7a000000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000044000000000000000000000000b3c9669a5706477a2b237d98edb9b57678926f0400000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a405971224000000000000000000000000111111111117dc0aa78b770fa6a738034120c302000000000000000000000000382ffce2287252f930e1c8dc9328dac5bf282ba10000000000000000000000000000000000000000000000000000000000000001000000000000000002b79a9b4d8a5c9300000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000fbc539a31bdf05000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004470bdb947000000000000000000000000111111111117dc0aa78b770fa6a738034120c302000000000000000000000000000000000000000000000035f9ac3b1a9af32d6200000000000000000000000000000000000000000000000000000000'
411
+ ], [
412
+ { 'type': 'BigNumber', 'hex': '0x00' },
413
+ { 'type': 'BigNumber', 'hex': '0x00' },
414
+ { 'type': 'BigNumber', 'hex': '0x00' },
415
+ '0xb3af37c000000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000044000000000000000000000000111111111117dc0aa78b770fa6a738034120c302000000000000000000000000000000010000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000064d1660f99000000000000000000000000111111111117dc0aa78b770fa6a738034120c30200000000000000000000000083b97790c7da251fafb24d6cbfc481cfa4afc4f6000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000'
416
+ ]
417
+ ]
418
+ ]
419
+
420
+ t.deepEquals(resultNoWeth.types, expectedTypes)
421
+ t.deepEquals(resultWithWeth.types, expectedTypes)
422
+ t.deepEquals(resultNoWeth.names, expectedNames)
423
+ t.deepEquals(resultWithWeth.names, expectedNames)
424
+ t.deepEquals(JSON.stringify(resultNoWeth.inputs), JSON.stringify(expectedInputsNoWeth))
425
+ t.deepEquals(JSON.stringify(resultWithWeth.inputs), JSON.stringify(expectedInputsWithWeth))
426
+ })
427
+
428
+ t.test('test abi3.json', t => {
429
+ t.plan(4)
430
+ const decoder = new InputDataDecoder(`${__dirname}/data/abi3.json`)
431
+ const data = fs.readFileSync(`${__dirname}/data/abi3_data.txt`)
432
+ const result = decoder.decodeData(data)
433
+
434
+ const expectedInputs = [
435
+ '0x482bc619eE7662759CDc0685B4E78f464Da39C73',
436
+ '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
437
+ {
438
+ 'type': 'BigNumber',
439
+ 'hex': '0x66299080'
440
+ },
441
+ {
442
+ 'type': 'BigNumber',
443
+ 'hex': '0xe7413e'
444
+ },
445
+ {
446
+ 'type': 'BigNumber',
447
+ 'hex': '0x61f81da8'
448
+ },
449
+ '0xb0CC32190a06f4bA13027E7D6C516217b49E8eb0',
450
+ [
451
+ 27,
452
+ '0xe35fd8994857126c80d25bd1994ba96849fa77556d1360a9e605f04cc8f9d7c1',
453
+ '0x1f2244a355a9ab6ea4864381e5d38d4d9b09a25291d0bf6e61c6f975a4d5b9f7'
454
+ ],
455
+ '0x436c697070657200000000000000000000000000000000000000000000000000'
456
+ ]
457
+ const expectedNames = [
458
+ 'inputToken',
459
+ 'outputToken',
460
+ 'inputAmount',
461
+ 'outputAmount',
462
+ 'goodUntil',
463
+ 'destinationAddress',
464
+ ['theSignature', ['v', 'r', 's']],
465
+ 'auxiliaryData'
466
+ ]
467
+ const expectedTypes = [ 'address', 'address', 'uint256', 'uint256', 'uint256', 'address', '(uint8,bytes32,bytes32)', 'bytes' ]
468
+
469
+ t.deepEqual(result.method, 'transmitAndSwap')
470
+ t.deepEqual(JSON.stringify(result.inputs), JSON.stringify(expectedInputs))
471
+ t.deepEqual(result.names, expectedNames)
472
+ t.deepEqual(result.types, expectedTypes)
473
+ })
474
+
475
+ t.test('test abi4.json', t => {
476
+ t.plan(4)
477
+ const decoder = new InputDataDecoder(`${__dirname}/data/abi4.json`)
478
+ const data = fs.readFileSync(`${__dirname}/data/abi4_data.txt`)
479
+ const result = decoder.decodeData(data)
480
+
481
+ const expectedInputs = [
482
+ '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
483
+ '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
484
+ {
485
+ 'type': 'BigNumber',
486
+ 'hex': '0x77359400'
487
+ },
488
+ [
489
+ [
490
+ '0xe2A1b03Cd5D639377B6D6e48d81A50FbC6C955a8',
491
+ '0x4fcfecd10000000000000000000000000000000000000000000000000000000077359400000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
492
+ ]
493
+ ],
494
+ {
495
+ 'type': 'BigNumber',
496
+ 'hex': '0x06d14b423b3af5fc'
497
+ },
498
+ '0xcd43AaD533e663b726DAe4a08185E9db8eBC9f6F'
499
+ ]
500
+ const expectedNames = [
501
+ 'fromToken',
502
+ 'toToken',
503
+ 'fromAmount',
504
+ [
505
+ 'trades',
506
+ [
507
+ 'moduleAddress',
508
+ 'encodedCalldata'
509
+ ]
510
+ ],
511
+ 'finalAmountMin',
512
+ 'recipient'
513
+ ]
514
+ const expectedTypes = ['address', 'address', 'uint256', '(address,bytes)[]', 'uint256', 'address']
515
+
516
+ t.deepEqual(result.method, 'executeTrades')
517
+ t.deepEqual(JSON.stringify(result.inputs), JSON.stringify(expectedInputs))
518
+ t.deepEqual(result.names, expectedNames)
519
+ t.deepEqual(result.types, expectedTypes)
520
+ })
521
+
522
+ // https://github.com/miguelmota/ethereum-input-data-decoder/issues/28
523
+ t.test('test abi5.json', t => {
524
+ t.plan(4)
525
+ const decoder = new InputDataDecoder(`${__dirname}/data/abi5.json`)
526
+ const data = fs.readFileSync(`${__dirname}/data/abi5_data.txt`)
527
+ const result = decoder.decodeData(data)
528
+
529
+ const expectedInputs = [
530
+ [
531
+ [
532
+ [
533
+ '0x7842792a8471D0f5aE645f513Cc5999b1bB6B182',
534
+ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
535
+ '0x6b785a0322126826d8226d77e173d75DAfb84d11',
536
+ {
537
+ 'type': 'BigNumber',
538
+ 'hex': '0x2386f26fc10000'
539
+ },
540
+ {
541
+ 'type': 'BigNumber',
542
+ 'hex': '0x00'
543
+ },
544
+ {
545
+ 'type': 'BigNumber',
546
+ 'hex': '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
547
+ }
548
+ ],
549
+ [
550
+ '0x5D87Eb9Ac9C107424734F2a95F11649206cCFeA8',
551
+ '0x6b785a0322126826d8226d77e173d75DAfb84d11',
552
+ '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984',
553
+ {
554
+ 'type': 'BigNumber',
555
+ 'hex': '0x01ee30107c0827ea7d'
556
+ },
557
+ {
558
+ 'type': 'BigNumber',
559
+ 'hex': '0x00'
560
+ },
561
+ {
562
+ 'type': 'BigNumber',
563
+ 'hex': '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
564
+ }
565
+ ]
566
+ ]
567
+ ],
568
+ '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
569
+ '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984',
570
+ {
571
+ 'type': 'BigNumber',
572
+ 'hex': '0x2386f26fc10000'
573
+ },
574
+ {
575
+ 'type': 'BigNumber',
576
+ 'hex': '0x1b1bd5bfc01a3688'
577
+ }
578
+ ]
579
+
580
+ const expectedNames = [ [ 'swapSequences', [ 'pool', 'tokenIn', 'tokenOut', 'swapAmount', 'limitReturnAmount', 'maxPrice' ] ], 'tokenIn', 'tokenOut', 'totalAmountIn', 'minTotalAmountOut' ]
581
+ const expectedTypes = [
582
+ '(address,address,address,uint256,uint256,uint256)', 'address', 'address', 'uint256', 'uint256'
583
+ ]
584
+
585
+ t.deepEqual(result.method, 'multihopBatchSwapExactIn')
586
+ t.deepEqual(JSON.stringify(result.inputs), JSON.stringify(expectedInputs))
587
+ t.deepEqual(result.names, expectedNames)
588
+ t.deepEqual(result.types, expectedTypes)
589
+ })
590
+
591
+ // https://github.com/miguelmota/ethereum-input-data-decoder/issues/37
592
+ t.test('test abi6.json', t => {
593
+ t.plan(4)
594
+
595
+ const decoder = new InputDataDecoder(`${__dirname}/data/abi6.json`)
596
+ const data = fs.readFileSync(`${__dirname}/data/abi6_data.txt`)
597
+ const result = decoder.decodeData(data)
598
+
599
+ // not possible to decode:
600
+ // https://github.com/ethers-io/ethers.js/discussions/2656#discussioncomment-2115587
601
+ const expectedInputs = []
602
+ const expectedNames = [ 'amountOutMin', 'path', 'to', 'deadline' ]
603
+ const expectedTypes = [ 'uint256', 'address[]', 'address', 'uint256' ]
604
+
605
+ t.deepEqual(result.method, 'swapExactETHForTokens')
606
+ t.deepEqual(JSON.stringify(result.inputs), JSON.stringify(expectedInputs))
607
+ t.deepEqual(result.names, expectedNames)
608
+ t.deepEqual(result.types, expectedTypes)
609
+ })
610
+
611
+ // https://github.com/miguelmota/ethereum-input-data-decoder/issues/36
612
+ t.test('test abi7.json', t => {
613
+ t.plan(4)
614
+
615
+ const decoder = new InputDataDecoder(`${__dirname}/data/abi7.json`)
616
+ const data = fs.readFileSync(`${__dirname}/data/abi7_data.txt`)
617
+ const result = decoder.decodeData(data)
618
+
619
+ const expectedInputs = [['0xdac17f958d2ee523a2206206994597c13d831ec70001f4c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000bb8aa99199d1e9644b588796f3215089878440d58e0', '0x7a58b76fFD3989dDbCe7BD632fdcF79B50530A69', { 'type': 'BigNumber', 'hex': '0x60ffb75c' }, { 'type': 'BigNumber', 'hex': '0x1dcd6500' }, { 'type': 'BigNumber', 'hex': '0x1f8587609e8c5bc3bf' }]]
620
+ const expectedNames = [['params', ['path', 'recipient', 'deadline', 'amountIn', 'amountOutMinimum']]]
621
+ const expectedTypes = [ '(bytes,address,uint256,uint256,uint256)' ]
622
+
623
+ t.deepEqual(result.method, 'exactInput')
624
+ t.deepEqual(JSON.stringify(result.inputs), JSON.stringify(expectedInputs))
625
+ t.deepEqual(result.names, expectedNames)
626
+ t.deepEqual(result.types, expectedTypes)
627
+ })
628
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "include": [
3
+ "dist/*"
4
+ ],
5
+ "exclude": [],
6
+ "compilerOptions": {
7
+ "lib": [
8
+ "es2015",
9
+ "dom",
10
+ "dom.iterable"
11
+ ],
12
+ "target": "ES2018",
13
+ "declaration": true,
14
+ "declarationDir": ".",
15
+ "noEmitOnError": true,
16
+ "noErrorTruncation": true,
17
+ "module": "CommonJS",
18
+ "moduleResolution": "node",
19
+ "resolveJsonModule": true,
20
+ "allowSyntheticDefaultImports": true,
21
+ "noImplicitThis": true,
22
+ "noUnusedLocals": true,
23
+ "noUnusedParameters": true,
24
+ "baseUrl": ".",
25
+ "declarationMap": true
26
+ }
27
+ }