@bitpay-labs/crypto-wallet-core 11.11.4 → 11.11.6
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.
- package/package.json +9 -3
- package/ts_build/src/constants/index.d.ts +18 -1
- package/ts_build/src/constants/index.d.ts.map +1 -1
- package/ts_build/src/constants/tokens.d.ts +14 -2
- package/ts_build/src/constants/tokens.d.ts.map +1 -1
- package/ts_build/src/constants/tokens.js +8 -2
- package/ts_build/src/constants/tokens.js.map +1 -1
- package/ts_build/src/constants/units.d.ts +11 -0
- package/ts_build/src/constants/units.d.ts.map +1 -1
- package/ts_build/src/constants/units.js +11 -0
- package/ts_build/src/constants/units.js.map +1 -1
- package/ts_build/src/transactions/index.d.ts +1 -1
- package/ts_build/src/transactions/index.d.ts.map +1 -1
- package/ts_build/src/transactions/index.js.map +1 -1
- package/ts_build/src/types/derivation.d.ts +1 -0
- package/ts_build/src/types/derivation.d.ts.map +1 -1
- package/.mocharc.json +0 -6
- package/LICENSE +0 -21
- package/mcr.config.js +0 -17
- package/src/constants/address.ts +0 -7
- package/src/constants/algorithms.ts +0 -9
- package/src/constants/arc.ts +0 -4
- package/src/constants/chains.ts +0 -68
- package/src/constants/feeMinimums.ts +0 -23
- package/src/constants/index.ts +0 -40
- package/src/constants/tokens.ts +0 -227
- package/src/constants/units.ts +0 -300
- package/src/derivation/arb/index.ts +0 -3
- package/src/derivation/base/index.ts +0 -3
- package/src/derivation/bch/index.ts +0 -11
- package/src/derivation/btc/index.ts +0 -68
- package/src/derivation/doge/index.ts +0 -6
- package/src/derivation/eth/index.ts +0 -86
- package/src/derivation/index.ts +0 -140
- package/src/derivation/ltc/index.ts +0 -6
- package/src/derivation/matic/index.ts +0 -3
- package/src/derivation/op/index.ts +0 -3
- package/src/derivation/paths.ts +0 -45
- package/src/derivation/sol/index.ts +0 -81
- package/src/derivation/xrp/index.ts +0 -63
- package/src/index.ts +0 -48
- package/src/message/btc.ts +0 -28
- package/src/message/eth.ts +0 -47
- package/src/message/index.ts +0 -71
- package/src/message/sol.ts +0 -3
- package/src/message/xrp.ts +0 -4
- package/src/transactions/arb/index.ts +0 -14
- package/src/transactions/base/index.ts +0 -13
- package/src/transactions/bch/index.ts +0 -25
- package/src/transactions/btc/index.ts +0 -316
- package/src/transactions/doge/index.ts +0 -31
- package/src/transactions/erc20/abi.ts +0 -418
- package/src/transactions/erc20/index.ts +0 -57
- package/src/transactions/eth/index.ts +0 -192
- package/src/transactions/eth-multisig/abi.ts +0 -724
- package/src/transactions/eth-multisig/index.ts +0 -172
- package/src/transactions/index.ts +0 -85
- package/src/transactions/ltc/index.ts +0 -31
- package/src/transactions/matic/index.ts +0 -14
- package/src/transactions/matic-multisig/index.ts +0 -172
- package/src/transactions/op/index.ts +0 -14
- package/src/transactions/sol/index.ts +0 -306
- package/src/transactions/spl/index.ts +0 -192
- package/src/transactions/xrp/index.ts +0 -167
- package/src/types/derivation.ts +0 -34
- package/src/types/index.ts +0 -3
- package/src/types/message.ts +0 -15
- package/src/types/utils.ts +0 -1
- package/src/types/validation.ts +0 -4
- package/src/utils/bigint.ts +0 -238
- package/src/utils/index.ts +0 -188
- package/src/validation/arb/index.ts +0 -8
- package/src/validation/arc/index.ts +0 -8
- package/src/validation/base/index.ts +0 -8
- package/src/validation/bch/index.ts +0 -17
- package/src/validation/btc/index.ts +0 -17
- package/src/validation/doge/index.ts +0 -16
- package/src/validation/eth/index.ts +0 -29
- package/src/validation/index.ts +0 -45
- package/src/validation/ltc/index.ts +0 -16
- package/src/validation/matic/index.ts +0 -8
- package/src/validation/op/index.ts +0 -8
- package/src/validation/sol/index.ts +0 -34
- package/src/validation/xrp/index.ts +0 -50
- package/test/address.test.ts +0 -190
- package/test/bigint.test.ts +0 -373
- package/test/deriver.test.ts +0 -126
- package/test/transactions.test.ts +0 -2103
- package/test/utils.test.ts +0 -446
- package/test/validation.test.ts +0 -282
- package/tsconfig.json +0 -29
|
@@ -1,418 +0,0 @@
|
|
|
1
|
-
export { ERC20Abi, MULTISENDAbi };
|
|
2
|
-
|
|
3
|
-
const ERC20Abi = [
|
|
4
|
-
{
|
|
5
|
-
constant: true,
|
|
6
|
-
inputs: [],
|
|
7
|
-
name: 'name',
|
|
8
|
-
outputs: [
|
|
9
|
-
{
|
|
10
|
-
name: '',
|
|
11
|
-
type: 'string'
|
|
12
|
-
}
|
|
13
|
-
],
|
|
14
|
-
payable: false,
|
|
15
|
-
stateMutability: 'view',
|
|
16
|
-
type: 'function'
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
constant: false,
|
|
20
|
-
inputs: [
|
|
21
|
-
{
|
|
22
|
-
name: '_spender',
|
|
23
|
-
type: 'address'
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: '_value',
|
|
27
|
-
type: 'uint256'
|
|
28
|
-
}
|
|
29
|
-
],
|
|
30
|
-
name: 'approve',
|
|
31
|
-
outputs: [
|
|
32
|
-
{
|
|
33
|
-
name: '',
|
|
34
|
-
type: 'bool'
|
|
35
|
-
}
|
|
36
|
-
],
|
|
37
|
-
payable: false,
|
|
38
|
-
stateMutability: 'nonpayable',
|
|
39
|
-
type: 'function'
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
constant: true,
|
|
43
|
-
inputs: [],
|
|
44
|
-
name: 'totalSupply',
|
|
45
|
-
outputs: [
|
|
46
|
-
{
|
|
47
|
-
name: '',
|
|
48
|
-
type: 'uint256'
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
|
-
payable: false,
|
|
52
|
-
stateMutability: 'view',
|
|
53
|
-
type: 'function'
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
constant: false,
|
|
57
|
-
inputs: [
|
|
58
|
-
{
|
|
59
|
-
name: '_from',
|
|
60
|
-
type: 'address'
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
name: '_to',
|
|
64
|
-
type: 'address'
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: '_value',
|
|
68
|
-
type: 'uint256'
|
|
69
|
-
}
|
|
70
|
-
],
|
|
71
|
-
name: 'transferFrom',
|
|
72
|
-
outputs: [
|
|
73
|
-
{
|
|
74
|
-
name: '',
|
|
75
|
-
type: 'bool'
|
|
76
|
-
}
|
|
77
|
-
],
|
|
78
|
-
payable: false,
|
|
79
|
-
stateMutability: 'nonpayable',
|
|
80
|
-
type: 'function'
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
constant: true,
|
|
84
|
-
inputs: [],
|
|
85
|
-
name: 'decimals',
|
|
86
|
-
outputs: [
|
|
87
|
-
{
|
|
88
|
-
name: '',
|
|
89
|
-
type: 'uint8'
|
|
90
|
-
}
|
|
91
|
-
],
|
|
92
|
-
payable: false,
|
|
93
|
-
stateMutability: 'view',
|
|
94
|
-
type: 'function'
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
constant: true,
|
|
98
|
-
inputs: [
|
|
99
|
-
{
|
|
100
|
-
name: '_owner',
|
|
101
|
-
type: 'address'
|
|
102
|
-
}
|
|
103
|
-
],
|
|
104
|
-
name: 'balanceOf',
|
|
105
|
-
outputs: [
|
|
106
|
-
{
|
|
107
|
-
name: 'balance',
|
|
108
|
-
type: 'uint256'
|
|
109
|
-
}
|
|
110
|
-
],
|
|
111
|
-
payable: false,
|
|
112
|
-
stateMutability: 'view',
|
|
113
|
-
type: 'function'
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
constant: true,
|
|
117
|
-
inputs: [],
|
|
118
|
-
name: 'symbol',
|
|
119
|
-
outputs: [
|
|
120
|
-
{
|
|
121
|
-
name: '',
|
|
122
|
-
type: 'string'
|
|
123
|
-
}
|
|
124
|
-
],
|
|
125
|
-
payable: false,
|
|
126
|
-
stateMutability: 'view',
|
|
127
|
-
type: 'function'
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
constant: false,
|
|
131
|
-
inputs: [
|
|
132
|
-
{
|
|
133
|
-
name: '_to',
|
|
134
|
-
type: 'address'
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
name: '_value',
|
|
138
|
-
type: 'uint256'
|
|
139
|
-
}
|
|
140
|
-
],
|
|
141
|
-
name: 'transfer',
|
|
142
|
-
outputs: [
|
|
143
|
-
{
|
|
144
|
-
name: '',
|
|
145
|
-
type: 'bool'
|
|
146
|
-
}
|
|
147
|
-
],
|
|
148
|
-
payable: false,
|
|
149
|
-
stateMutability: 'nonpayable',
|
|
150
|
-
type: 'function'
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
constant: true,
|
|
154
|
-
inputs: [
|
|
155
|
-
{
|
|
156
|
-
name: '_owner',
|
|
157
|
-
type: 'address'
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
name: '_spender',
|
|
161
|
-
type: 'address'
|
|
162
|
-
}
|
|
163
|
-
],
|
|
164
|
-
name: 'allowance',
|
|
165
|
-
outputs: [
|
|
166
|
-
{
|
|
167
|
-
name: '',
|
|
168
|
-
type: 'uint256'
|
|
169
|
-
}
|
|
170
|
-
],
|
|
171
|
-
payable: false,
|
|
172
|
-
stateMutability: 'view',
|
|
173
|
-
type: 'function'
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
payable: true,
|
|
177
|
-
stateMutability: 'payable',
|
|
178
|
-
type: 'fallback'
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
anonymous: false,
|
|
182
|
-
inputs: [
|
|
183
|
-
{
|
|
184
|
-
indexed: true,
|
|
185
|
-
name: 'owner',
|
|
186
|
-
type: 'address'
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
indexed: true,
|
|
190
|
-
name: 'spender',
|
|
191
|
-
type: 'address'
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
indexed: false,
|
|
195
|
-
name: 'value',
|
|
196
|
-
type: 'uint256'
|
|
197
|
-
}
|
|
198
|
-
],
|
|
199
|
-
name: 'Approval',
|
|
200
|
-
type: 'event'
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
anonymous: false,
|
|
204
|
-
inputs: [
|
|
205
|
-
{
|
|
206
|
-
indexed: true,
|
|
207
|
-
name: 'from',
|
|
208
|
-
type: 'address'
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
indexed: true,
|
|
212
|
-
name: 'to',
|
|
213
|
-
type: 'address'
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
indexed: false,
|
|
217
|
-
name: 'value',
|
|
218
|
-
type: 'uint256'
|
|
219
|
-
}
|
|
220
|
-
],
|
|
221
|
-
name: 'Transfer',
|
|
222
|
-
type: 'event'
|
|
223
|
-
}
|
|
224
|
-
];
|
|
225
|
-
|
|
226
|
-
const MULTISENDAbi = [
|
|
227
|
-
{
|
|
228
|
-
constant: true,
|
|
229
|
-
inputs: [
|
|
230
|
-
{
|
|
231
|
-
name: '',
|
|
232
|
-
type: 'address'
|
|
233
|
-
}
|
|
234
|
-
],
|
|
235
|
-
name: 'admins',
|
|
236
|
-
outputs: [
|
|
237
|
-
{
|
|
238
|
-
name: '',
|
|
239
|
-
type: 'bool'
|
|
240
|
-
}
|
|
241
|
-
],
|
|
242
|
-
payable: false,
|
|
243
|
-
stateMutability: 'view',
|
|
244
|
-
type: 'function'
|
|
245
|
-
},
|
|
246
|
-
{
|
|
247
|
-
inputs: [],
|
|
248
|
-
payable: false,
|
|
249
|
-
stateMutability: 'nonpayable',
|
|
250
|
-
type: 'constructor'
|
|
251
|
-
},
|
|
252
|
-
{
|
|
253
|
-
anonymous: false,
|
|
254
|
-
inputs: [
|
|
255
|
-
{
|
|
256
|
-
indexed: true,
|
|
257
|
-
name: 'newAdmin',
|
|
258
|
-
type: 'address'
|
|
259
|
-
}
|
|
260
|
-
],
|
|
261
|
-
name: 'AdminSet',
|
|
262
|
-
type: 'event'
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
anonymous: false,
|
|
266
|
-
inputs: [
|
|
267
|
-
{
|
|
268
|
-
indexed: true,
|
|
269
|
-
name: 'oldAdmin',
|
|
270
|
-
type: 'address'
|
|
271
|
-
}
|
|
272
|
-
],
|
|
273
|
-
name: 'AdminRemoved',
|
|
274
|
-
type: 'event'
|
|
275
|
-
},
|
|
276
|
-
{
|
|
277
|
-
anonymous: false,
|
|
278
|
-
inputs: [
|
|
279
|
-
{
|
|
280
|
-
indexed: true,
|
|
281
|
-
name: 'from',
|
|
282
|
-
type: 'address'
|
|
283
|
-
},
|
|
284
|
-
{
|
|
285
|
-
indexed: true,
|
|
286
|
-
name: 'to',
|
|
287
|
-
type: 'address'
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
indexed: true,
|
|
291
|
-
name: 'tokenAddress',
|
|
292
|
-
type: 'address'
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
indexed: false,
|
|
296
|
-
name: 'tokens',
|
|
297
|
-
type: 'uint256'
|
|
298
|
-
}
|
|
299
|
-
],
|
|
300
|
-
name: 'Transfer',
|
|
301
|
-
type: 'event'
|
|
302
|
-
},
|
|
303
|
-
{
|
|
304
|
-
constant: false,
|
|
305
|
-
inputs: [
|
|
306
|
-
{
|
|
307
|
-
name: 'admin',
|
|
308
|
-
type: 'address'
|
|
309
|
-
}
|
|
310
|
-
],
|
|
311
|
-
name: 'setAdmin',
|
|
312
|
-
outputs: [
|
|
313
|
-
{
|
|
314
|
-
name: 'success',
|
|
315
|
-
type: 'bool'
|
|
316
|
-
}
|
|
317
|
-
],
|
|
318
|
-
payable: false,
|
|
319
|
-
stateMutability: 'nonpayable',
|
|
320
|
-
type: 'function'
|
|
321
|
-
},
|
|
322
|
-
{
|
|
323
|
-
constant: false,
|
|
324
|
-
inputs: [
|
|
325
|
-
{
|
|
326
|
-
name: 'admin',
|
|
327
|
-
type: 'address'
|
|
328
|
-
}
|
|
329
|
-
],
|
|
330
|
-
name: 'removeAdmin',
|
|
331
|
-
outputs: [
|
|
332
|
-
{
|
|
333
|
-
name: 'success',
|
|
334
|
-
type: 'bool'
|
|
335
|
-
}
|
|
336
|
-
],
|
|
337
|
-
payable: false,
|
|
338
|
-
stateMutability: 'nonpayable',
|
|
339
|
-
type: 'function'
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
constant: false,
|
|
343
|
-
inputs: [
|
|
344
|
-
{
|
|
345
|
-
name: 'returnee',
|
|
346
|
-
type: 'address'
|
|
347
|
-
},
|
|
348
|
-
{
|
|
349
|
-
name: 'tokenAddress',
|
|
350
|
-
type: 'address'
|
|
351
|
-
},
|
|
352
|
-
{
|
|
353
|
-
name: 'amount',
|
|
354
|
-
type: 'uint256'
|
|
355
|
-
}
|
|
356
|
-
],
|
|
357
|
-
name: 'withdraw',
|
|
358
|
-
outputs: [
|
|
359
|
-
{
|
|
360
|
-
name: 'success',
|
|
361
|
-
type: 'bool'
|
|
362
|
-
}
|
|
363
|
-
],
|
|
364
|
-
payable: false,
|
|
365
|
-
stateMutability: 'nonpayable',
|
|
366
|
-
type: 'function'
|
|
367
|
-
},
|
|
368
|
-
{
|
|
369
|
-
constant: false,
|
|
370
|
-
inputs: [
|
|
371
|
-
{
|
|
372
|
-
name: 'recipients',
|
|
373
|
-
type: 'address[]'
|
|
374
|
-
},
|
|
375
|
-
{
|
|
376
|
-
name: 'amounts',
|
|
377
|
-
type: 'uint256[]'
|
|
378
|
-
}
|
|
379
|
-
],
|
|
380
|
-
name: 'sendEth',
|
|
381
|
-
outputs: [
|
|
382
|
-
{
|
|
383
|
-
name: '',
|
|
384
|
-
type: 'bool'
|
|
385
|
-
}
|
|
386
|
-
],
|
|
387
|
-
payable: true,
|
|
388
|
-
stateMutability: 'payable',
|
|
389
|
-
type: 'function'
|
|
390
|
-
},
|
|
391
|
-
{
|
|
392
|
-
constant: false,
|
|
393
|
-
inputs: [
|
|
394
|
-
{
|
|
395
|
-
name: 'tokenAddress',
|
|
396
|
-
type: 'address'
|
|
397
|
-
},
|
|
398
|
-
{
|
|
399
|
-
name: 'recipients',
|
|
400
|
-
type: 'address[]'
|
|
401
|
-
},
|
|
402
|
-
{
|
|
403
|
-
name: 'amounts',
|
|
404
|
-
type: 'uint256[]'
|
|
405
|
-
}
|
|
406
|
-
],
|
|
407
|
-
name: 'sendErc20',
|
|
408
|
-
outputs: [
|
|
409
|
-
{
|
|
410
|
-
name: '',
|
|
411
|
-
type: 'bool'
|
|
412
|
-
}
|
|
413
|
-
],
|
|
414
|
-
payable: false,
|
|
415
|
-
stateMutability: 'nonpayable',
|
|
416
|
-
type: 'function'
|
|
417
|
-
}
|
|
418
|
-
];
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import Web3 from 'web3';
|
|
2
|
-
import { AbiItem } from 'web3-utils';
|
|
3
|
-
import { ETHTxProvider } from '../eth';
|
|
4
|
-
import { ERC20Abi } from './abi';
|
|
5
|
-
|
|
6
|
-
export class ERC20TxProvider extends ETHTxProvider {
|
|
7
|
-
getERC20Contract(tokenContractAddress: string) {
|
|
8
|
-
const web3 = new Web3();
|
|
9
|
-
const contract = new web3.eth.Contract(ERC20Abi as AbiItem[], tokenContractAddress);
|
|
10
|
-
return contract;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
create(params: {
|
|
14
|
-
recipients: Array<{ address: string; amount: string }>;
|
|
15
|
-
nonce: number;
|
|
16
|
-
gasPrice?: number;
|
|
17
|
-
data: string;
|
|
18
|
-
gasLimit: number;
|
|
19
|
-
tokenAddress: string;
|
|
20
|
-
network: string;
|
|
21
|
-
chainId?: number;
|
|
22
|
-
contractAddress?: string;
|
|
23
|
-
maxGasFee?: number;
|
|
24
|
-
priorityGasFee?: number;
|
|
25
|
-
}) {
|
|
26
|
-
const { tokenAddress, contractAddress } = params;
|
|
27
|
-
const data = this.encodeData(params);
|
|
28
|
-
const recipients = [{ address: contractAddress || tokenAddress, amount: '0' }];
|
|
29
|
-
const newParams = { ...params, recipients, data };
|
|
30
|
-
return super.create(newParams);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
encodeData(params: {
|
|
34
|
-
recipients: Array<{ address: string; amount: string }>;
|
|
35
|
-
tokenAddress: string;
|
|
36
|
-
contractAddress?: string;
|
|
37
|
-
}) {
|
|
38
|
-
const { tokenAddress, recipients, contractAddress } = params;
|
|
39
|
-
if (recipients.length > 1) {
|
|
40
|
-
const addresses = [];
|
|
41
|
-
const amounts = [];
|
|
42
|
-
for (const recipient of recipients) {
|
|
43
|
-
addresses.push(recipient.address);
|
|
44
|
-
amounts.push(BigInt(recipient.amount));
|
|
45
|
-
}
|
|
46
|
-
const multisendContract = this.getMultiSendContract(contractAddress);
|
|
47
|
-
return multisendContract.methods.sendErc20(tokenAddress, addresses, amounts).encodeABI();
|
|
48
|
-
} else {
|
|
49
|
-
const [{ address, amount }] = params.recipients;
|
|
50
|
-
const amountBI = BigInt(amount);
|
|
51
|
-
const data = this.getERC20Contract(tokenAddress)
|
|
52
|
-
.methods.transfer(address, amountBI)
|
|
53
|
-
.encodeABI();
|
|
54
|
-
return data;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import Web3 from 'web3';
|
|
3
|
-
import { AbiItem } from 'web3-utils';
|
|
4
|
-
import { Constants } from '../../constants';
|
|
5
|
-
import {
|
|
6
|
-
EVM_CHAIN_NETWORK_TO_CHAIN_ID as chainIds,
|
|
7
|
-
EVM_CHAIN_DEFAULT_TESTNET as defaultTestnet
|
|
8
|
-
} from '../../constants/chains';
|
|
9
|
-
import { MULTISENDAbi } from '../erc20/abi';
|
|
10
|
-
import type { Key } from '../../types/derivation';
|
|
11
|
-
|
|
12
|
-
export class ETHTxProvider {
|
|
13
|
-
chain: string;
|
|
14
|
-
|
|
15
|
-
constructor(chain = 'ETH') {
|
|
16
|
-
this.chain = chain;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
create(params: {
|
|
20
|
-
recipients: Array<{ address: string; amount: string }>;
|
|
21
|
-
nonce: number;
|
|
22
|
-
gasPrice?: number;
|
|
23
|
-
data: string;
|
|
24
|
-
gasLimit: number;
|
|
25
|
-
network: string;
|
|
26
|
-
chainId?: number;
|
|
27
|
-
contractAddress?: string;
|
|
28
|
-
maxGasFee?: number;
|
|
29
|
-
priorityGasFee?: number;
|
|
30
|
-
txType?: number;
|
|
31
|
-
}) {
|
|
32
|
-
const { recipients, nonce, gasPrice, gasLimit, network, contractAddress, maxGasFee, priorityGasFee, txType } = params;
|
|
33
|
-
let { data } = params;
|
|
34
|
-
let to;
|
|
35
|
-
let amount: bigint;
|
|
36
|
-
if (recipients.length > 1) {
|
|
37
|
-
if (!contractAddress) {
|
|
38
|
-
throw new Error('Multiple recipients requires use of multi-send contract, please specify contractAddress');
|
|
39
|
-
}
|
|
40
|
-
const addresses = [];
|
|
41
|
-
const amounts = [];
|
|
42
|
-
amount = 0n;
|
|
43
|
-
for (const recipient of recipients) {
|
|
44
|
-
addresses.push(recipient.address);
|
|
45
|
-
amounts.push(BigInt(this._valueToString(recipient.amount)));
|
|
46
|
-
amount += BigInt(this._valueToString(recipient.amount));
|
|
47
|
-
}
|
|
48
|
-
const multisendContract = this.getMultiSendContract(contractAddress);
|
|
49
|
-
data = data || multisendContract.methods.sendEth(addresses, amounts).encodeABI();
|
|
50
|
-
to = contractAddress;
|
|
51
|
-
} else {
|
|
52
|
-
to = recipients[0].address;
|
|
53
|
-
amount = BigInt(this._valueToString(recipients[0].amount));
|
|
54
|
-
}
|
|
55
|
-
let { chainId } = params;
|
|
56
|
-
chainId = chainId || this.getChainId(network);
|
|
57
|
-
const txData: any = {
|
|
58
|
-
nonce: this._toHex(nonce),
|
|
59
|
-
gasLimit: this._toHex(gasLimit),
|
|
60
|
-
to,
|
|
61
|
-
data,
|
|
62
|
-
value: this._toHex(amount),
|
|
63
|
-
chainId
|
|
64
|
-
};
|
|
65
|
-
if (maxGasFee && (txType == null || txType >= 2)) {
|
|
66
|
-
txData.maxFeePerGas = this._toHex(maxGasFee);
|
|
67
|
-
txData.maxPriorityFeePerGas = this._toHex(priorityGasFee || this.getPriorityFeeMinimum(chainId));
|
|
68
|
-
txData.type = 2;
|
|
69
|
-
} else {
|
|
70
|
-
txData.gasPrice = this._toHex(gasPrice);
|
|
71
|
-
txData.type = txType || 0;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return ethers.Transaction.from(txData).unsignedSerialized;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
_valueToString(value) {
|
|
78
|
-
const type = typeof value;
|
|
79
|
-
if (type === 'number') {
|
|
80
|
-
return (value).toLocaleString('fullwide', { useGrouping: false });
|
|
81
|
-
} else if (type === 'bigint') {
|
|
82
|
-
return value.toString();
|
|
83
|
-
} else if (type === 'string') {
|
|
84
|
-
return value;
|
|
85
|
-
} else {
|
|
86
|
-
throw new Error(`Unexpected type of: ${type}`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
getMultiSendContract(tokenContractAddress: string) {
|
|
91
|
-
const web3 = new Web3();
|
|
92
|
-
return new web3.eth.Contract(MULTISENDAbi as AbiItem[], tokenContractAddress);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
getPriorityFeeMinimum(chainId: number) {
|
|
96
|
-
const chain = Constants.EVM_CHAIN_ID_TO_CHAIN[chainId];
|
|
97
|
-
return Constants.FEE_MINIMUMS[chain]?.priority || 0;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
getChainId(network: string) {
|
|
101
|
-
if (network === 'testnet') {
|
|
102
|
-
network = defaultTestnet[this.chain];
|
|
103
|
-
}
|
|
104
|
-
return chainIds[`${this.chain}_${network}`] || chainIds[`${this.chain}_mainnet`];
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
getSignatureObject(params: { tx: string; key: Key }) {
|
|
108
|
-
const { tx, key } = params;
|
|
109
|
-
// To comply with new ethers
|
|
110
|
-
let k = key.privKey;
|
|
111
|
-
if (k.substring(0, 2) != '0x') {
|
|
112
|
-
k = '0x' + k;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const signingKey = new ethers.SigningKey(k);
|
|
116
|
-
return signingKey.sign(ethers.keccak256(tx));
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
getSignature(params: { tx: string; key: Key }) {
|
|
120
|
-
const signatureHex = this.getSignatureObject(params).serialized;
|
|
121
|
-
return signatureHex;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
getHash(params: { tx: string }) {
|
|
125
|
-
const { tx } = params;
|
|
126
|
-
// tx must be signed for hash to exist
|
|
127
|
-
return ethers.Transaction.from(tx).hash;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Reads the fields BWS may mutate between proposal creation and publish out of a raw tx, to bind
|
|
132
|
-
* txp.prePublishRaw to the proposal. For EVM that is only the account nonce (deferred-nonce proposals).
|
|
133
|
-
*/
|
|
134
|
-
getMutableFields(rawTx: string): { nonce?: number } {
|
|
135
|
-
const parsed = ethers.Transaction.from(rawTx);
|
|
136
|
-
return { nonce: parsed.nonce != null ? Number(parsed.nonce) : undefined };
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
applySignature(params: { tx: string; signature: any }) {
|
|
140
|
-
const { tx, signature } = params;
|
|
141
|
-
const parsedTx = ethers.Transaction.from(tx);
|
|
142
|
-
const { gasPrice, maxFeePerGas, maxPriorityFeePerGas } = parsedTx;
|
|
143
|
-
// backwards compatibility
|
|
144
|
-
if (maxFeePerGas) {
|
|
145
|
-
parsedTx.maxFeePerGas = maxFeePerGas;
|
|
146
|
-
parsedTx.maxPriorityFeePerGas = maxPriorityFeePerGas;
|
|
147
|
-
parsedTx.type = 2;
|
|
148
|
-
} else if (!gasPrice) {
|
|
149
|
-
throw new Error('either gasPrice or maxFeePerGas is required');
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Verify the signature
|
|
153
|
-
let valid = false;
|
|
154
|
-
let signedTx;
|
|
155
|
-
try {
|
|
156
|
-
parsedTx.signature = ethers.Signature.from(signature);
|
|
157
|
-
signedTx = ethers.Transaction.from(parsedTx);
|
|
158
|
-
|
|
159
|
-
if (signedTx.hash) {
|
|
160
|
-
const recoveredAddress = ethers.recoverAddress(ethers.keccak256(tx), signature);
|
|
161
|
-
const expectedAddress = parsedTx.from;
|
|
162
|
-
valid = recoveredAddress === expectedAddress;
|
|
163
|
-
}
|
|
164
|
-
} catch {/** no op */}
|
|
165
|
-
if (!valid) {
|
|
166
|
-
throw new Error('invalid signature');
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return signedTx.serialized;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
sign(params: { tx: string; key: Key }) {
|
|
173
|
-
const { tx, key } = params;
|
|
174
|
-
const signature = this.getSignatureObject({ tx, key });
|
|
175
|
-
return this.applySignature({ tx, signature });
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
private _toHex(value: string | number | bigint) {
|
|
179
|
-
// Convert to BigInt first to normalize behavior across types.
|
|
180
|
-
// Web3.utils.toHex('20000') -> '0x323030303030' because it calls utf8ToHex for strings
|
|
181
|
-
return value != null ? Web3.utils.toHex(BigInt(value)) : undefined;
|
|
182
|
-
}
|
|
183
|
-
transformSignatureObject(params: { obj: any }) {
|
|
184
|
-
const { obj } = params;
|
|
185
|
-
return ethers.Signature.from(obj).serialized;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
getSighash(params: { tx: string }): string {
|
|
189
|
-
const { tx } = params;
|
|
190
|
-
return ethers.keccak256(tx).slice(2); // remove 0x prefix
|
|
191
|
-
}
|
|
192
|
-
}
|