@sentio/sdk 1.8.2 → 1.10.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 (51) hide show
  1. package/lib/base-processor-template.d.ts +6 -0
  2. package/lib/base-processor-template.js +5 -0
  3. package/lib/base-processor-template.js.map +1 -1
  4. package/lib/base-processor.d.ts +1 -1
  5. package/lib/base-processor.js +9 -2
  6. package/lib/base-processor.js.map +1 -1
  7. package/lib/builtin/internal/erc20_processor.d.ts +148 -14
  8. package/lib/builtin/internal/erc20_processor.js +114 -6
  9. package/lib/builtin/internal/erc20_processor.js.map +1 -1
  10. package/lib/builtin/internal/erc20bytes_processor.d.ts +80 -12
  11. package/lib/builtin/internal/erc20bytes_processor.js +58 -4
  12. package/lib/builtin/internal/erc20bytes_processor.js.map +1 -1
  13. package/lib/builtin/internal/weth9_processor.d.ts +92 -16
  14. package/lib/builtin/internal/weth9_processor.js +74 -8
  15. package/lib/builtin/internal/weth9_processor.js.map +1 -1
  16. package/lib/context.js +1 -0
  17. package/lib/context.js.map +1 -1
  18. package/lib/index.d.ts +1 -0
  19. package/lib/index.js.map +1 -1
  20. package/lib/target-ethers-sentio/codegen.js +13 -1
  21. package/lib/target-ethers-sentio/codegen.js.map +1 -1
  22. package/lib/target-ethers-sentio/functions.d.ts +3 -0
  23. package/lib/target-ethers-sentio/functions.js +61 -0
  24. package/lib/target-ethers-sentio/functions.js.map +1 -0
  25. package/lib/test/erc20-template.js +2 -2
  26. package/lib/test/erc20-template.js.map +1 -1
  27. package/lib/test/erc20.js +6 -4
  28. package/lib/test/erc20.js.map +1 -1
  29. package/lib/test/erc20.test.js +25 -0
  30. package/lib/test/erc20.test.js.map +1 -1
  31. package/lib/test/test-processor-server.d.ts +5 -1
  32. package/lib/test/test-processor-server.js +41 -0
  33. package/lib/test/test-processor-server.js.map +1 -1
  34. package/lib/trace.d.ts +5 -5
  35. package/lib/trace.js +21 -0
  36. package/lib/trace.js.map +1 -1
  37. package/package.json +1 -1
  38. package/src/base-processor-template.ts +13 -0
  39. package/src/base-processor.ts +10 -3
  40. package/src/builtin/internal/erc20_processor.ts +330 -7
  41. package/src/builtin/internal/erc20bytes_processor.ts +174 -5
  42. package/src/builtin/internal/weth9_processor.ts +195 -9
  43. package/src/context.ts +1 -0
  44. package/src/index.ts +1 -0
  45. package/src/target-ethers-sentio/codegen.ts +13 -1
  46. package/src/target-ethers-sentio/functions.ts +68 -0
  47. package/src/test/erc20-template.ts +2 -2
  48. package/src/test/erc20.test.ts +29 -0
  49. package/src/test/erc20.ts +6 -4
  50. package/src/test/test-processor-server.ts +47 -0
  51. package/src/trace.ts +27 -5
@@ -1,7 +1,7 @@
1
1
  /* Autogenerated file. Do not edit manually. */
2
2
  /* tslint:disable */
3
3
  /* eslint-disable */
4
- import { CallOverrides } from "ethers";
4
+ import { BigNumber, CallOverrides } from "ethers";
5
5
  import { Networkish } from "@ethersproject/providers";
6
6
  import {
7
7
  addContractByABI,
@@ -18,6 +18,7 @@ import {
18
18
  ContractView,
19
19
  DummyProvider,
20
20
  getContractName,
21
+ TypedCallTrace,
21
22
  } from "@sentio/sdk";
22
23
  import { PromiseOrValue } from "./common";
23
24
  import { ERC20Bytes, ERC20Bytes__factory } from "./index";
@@ -27,6 +28,70 @@ import {
27
28
  TransferEvent,
28
29
  TransferEventFilter,
29
30
  } from "./ERC20Bytes";
31
+
32
+ export interface NameCallObject {}
33
+
34
+ export type NameCallTrace = TypedCallTrace<[], NameCallObject>;
35
+
36
+ export interface ApproveCallObject {
37
+ spender: string;
38
+ value: BigNumber;
39
+ }
40
+
41
+ export type ApproveCallTrace = TypedCallTrace<
42
+ [string, BigNumber],
43
+ ApproveCallObject
44
+ >;
45
+
46
+ export interface TotalSupplyCallObject {}
47
+
48
+ export type TotalSupplyCallTrace = TypedCallTrace<[], TotalSupplyCallObject>;
49
+
50
+ export interface TransferFromCallObject {
51
+ from: string;
52
+ to: string;
53
+ value: BigNumber;
54
+ }
55
+
56
+ export type TransferFromCallTrace = TypedCallTrace<
57
+ [string, string, BigNumber],
58
+ TransferFromCallObject
59
+ >;
60
+
61
+ export interface DecimalsCallObject {}
62
+
63
+ export type DecimalsCallTrace = TypedCallTrace<[], DecimalsCallObject>;
64
+
65
+ export interface BalanceOfCallObject {
66
+ who: string;
67
+ }
68
+
69
+ export type BalanceOfCallTrace = TypedCallTrace<[string], BalanceOfCallObject>;
70
+
71
+ export interface SymbolCallObject {}
72
+
73
+ export type SymbolCallTrace = TypedCallTrace<[], SymbolCallObject>;
74
+
75
+ export interface TransferCallObject {
76
+ to: string;
77
+ value: BigNumber;
78
+ }
79
+
80
+ export type TransferCallTrace = TypedCallTrace<
81
+ [string, BigNumber],
82
+ TransferCallObject
83
+ >;
84
+
85
+ export interface AllowanceCallObject {
86
+ owner: string;
87
+ spender: string;
88
+ }
89
+
90
+ export type AllowanceCallTrace = TypedCallTrace<
91
+ [string, string],
92
+ AllowanceCallObject
93
+ >;
94
+
30
95
  const templateContract = ERC20Bytes__factory.connect("", DummyProvider);
31
96
 
32
97
  export class ERC20BytesContractView extends ContractView<ERC20Bytes> {
@@ -251,7 +316,7 @@ export class ERC20BytesProcessorTemplate extends BaseProcessorTemplate<
251
316
  return processor;
252
317
  }
253
318
 
254
- onApproval(
319
+ onEventApproval(
255
320
  handler: (event: ApprovalEvent, ctx: ERC20BytesContext) => void,
256
321
  filter?: ApprovalEventFilter | ApprovalEventFilter[]
257
322
  ) {
@@ -265,7 +330,7 @@ export class ERC20BytesProcessorTemplate extends BaseProcessorTemplate<
265
330
  return super.onEvent(handler, filter);
266
331
  }
267
332
 
268
- onTransfer(
333
+ onEventTransfer(
269
334
  handler: (event: TransferEvent, ctx: ERC20BytesContext) => void,
270
335
  filter?: TransferEventFilter | TransferEventFilter[]
271
336
  ) {
@@ -278,13 +343,65 @@ export class ERC20BytesProcessorTemplate extends BaseProcessorTemplate<
278
343
  }
279
344
  return super.onEvent(handler, filter);
280
345
  }
346
+
347
+ onCallName(handler: (call: NameCallTrace, ctx: ERC20BytesContext) => void) {
348
+ return super.onTrace("0x06fdde03", handler);
349
+ }
350
+
351
+ onCallApprove(
352
+ handler: (call: ApproveCallTrace, ctx: ERC20BytesContext) => void
353
+ ) {
354
+ return super.onTrace("0x095ea7b3", handler);
355
+ }
356
+
357
+ onCallTotalSupply(
358
+ handler: (call: TotalSupplyCallTrace, ctx: ERC20BytesContext) => void
359
+ ) {
360
+ return super.onTrace("0x18160ddd", handler);
361
+ }
362
+
363
+ onCallTransferFrom(
364
+ handler: (call: TransferFromCallTrace, ctx: ERC20BytesContext) => void
365
+ ) {
366
+ return super.onTrace("0x23b872dd", handler);
367
+ }
368
+
369
+ onCallDecimals(
370
+ handler: (call: DecimalsCallTrace, ctx: ERC20BytesContext) => void
371
+ ) {
372
+ return super.onTrace("0x313ce567", handler);
373
+ }
374
+
375
+ onCallBalanceOf(
376
+ handler: (call: BalanceOfCallTrace, ctx: ERC20BytesContext) => void
377
+ ) {
378
+ return super.onTrace("0x70a08231", handler);
379
+ }
380
+
381
+ onCallSymbol(
382
+ handler: (call: SymbolCallTrace, ctx: ERC20BytesContext) => void
383
+ ) {
384
+ return super.onTrace("0x95d89b41", handler);
385
+ }
386
+
387
+ onCallTransfer(
388
+ handler: (call: TransferCallTrace, ctx: ERC20BytesContext) => void
389
+ ) {
390
+ return super.onTrace("0xa9059cbb", handler);
391
+ }
392
+
393
+ onCallAllowance(
394
+ handler: (call: AllowanceCallTrace, ctx: ERC20BytesContext) => void
395
+ ) {
396
+ return super.onTrace("0xdd62ed3e", handler);
397
+ }
281
398
  }
282
399
 
283
400
  export class ERC20BytesProcessor extends BaseProcessor<
284
401
  ERC20Bytes,
285
402
  ERC20BytesBoundContractView
286
403
  > {
287
- onApproval(
404
+ onEventApproval(
288
405
  handler: (event: ApprovalEvent, ctx: ERC20BytesContext) => void,
289
406
  filter?: ApprovalEventFilter | ApprovalEventFilter[]
290
407
  ) {
@@ -298,7 +415,7 @@ export class ERC20BytesProcessor extends BaseProcessor<
298
415
  return super.onEvent(handler, filter);
299
416
  }
300
417
 
301
- onTransfer(
418
+ onEventTransfer(
302
419
  handler: (event: TransferEvent, ctx: ERC20BytesContext) => void,
303
420
  filter?: TransferEventFilter | TransferEventFilter[]
304
421
  ) {
@@ -312,6 +429,58 @@ export class ERC20BytesProcessor extends BaseProcessor<
312
429
  return super.onEvent(handler, filter);
313
430
  }
314
431
 
432
+ onCallName(handler: (call: NameCallTrace, ctx: ERC20BytesContext) => void) {
433
+ return super.onTrace("0x06fdde03", handler);
434
+ }
435
+
436
+ onCallApprove(
437
+ handler: (call: ApproveCallTrace, ctx: ERC20BytesContext) => void
438
+ ) {
439
+ return super.onTrace("0x095ea7b3", handler);
440
+ }
441
+
442
+ onCallTotalSupply(
443
+ handler: (call: TotalSupplyCallTrace, ctx: ERC20BytesContext) => void
444
+ ) {
445
+ return super.onTrace("0x18160ddd", handler);
446
+ }
447
+
448
+ onCallTransferFrom(
449
+ handler: (call: TransferFromCallTrace, ctx: ERC20BytesContext) => void
450
+ ) {
451
+ return super.onTrace("0x23b872dd", handler);
452
+ }
453
+
454
+ onCallDecimals(
455
+ handler: (call: DecimalsCallTrace, ctx: ERC20BytesContext) => void
456
+ ) {
457
+ return super.onTrace("0x313ce567", handler);
458
+ }
459
+
460
+ onCallBalanceOf(
461
+ handler: (call: BalanceOfCallTrace, ctx: ERC20BytesContext) => void
462
+ ) {
463
+ return super.onTrace("0x70a08231", handler);
464
+ }
465
+
466
+ onCallSymbol(
467
+ handler: (call: SymbolCallTrace, ctx: ERC20BytesContext) => void
468
+ ) {
469
+ return super.onTrace("0x95d89b41", handler);
470
+ }
471
+
472
+ onCallTransfer(
473
+ handler: (call: TransferCallTrace, ctx: ERC20BytesContext) => void
474
+ ) {
475
+ return super.onTrace("0xa9059cbb", handler);
476
+ }
477
+
478
+ onCallAllowance(
479
+ handler: (call: AllowanceCallTrace, ctx: ERC20BytesContext) => void
480
+ ) {
481
+ return super.onTrace("0xdd62ed3e", handler);
482
+ }
483
+
315
484
  public static filters = templateContract.filters;
316
485
 
317
486
  protected CreateBoundContractView(): ERC20BytesBoundContractView {
@@ -1,7 +1,7 @@
1
1
  /* Autogenerated file. Do not edit manually. */
2
2
  /* tslint:disable */
3
3
  /* eslint-disable */
4
- import { CallOverrides } from "ethers";
4
+ import { BigNumber, CallOverrides } from "ethers";
5
5
  import { Networkish } from "@ethersproject/providers";
6
6
  import {
7
7
  addContractByABI,
@@ -18,6 +18,7 @@ import {
18
18
  ContractView,
19
19
  DummyProvider,
20
20
  getContractName,
21
+ TypedCallTrace,
21
22
  } from "@sentio/sdk";
22
23
  import { PromiseOrValue } from "./common";
23
24
  import { WETH9, WETH9__factory } from "./index";
@@ -31,6 +32,75 @@ import {
31
32
  WithdrawalEvent,
32
33
  WithdrawalEventFilter,
33
34
  } from "./WETH9";
35
+
36
+ export interface NameCallObject {}
37
+
38
+ export type NameCallTrace = TypedCallTrace<[], NameCallObject>;
39
+
40
+ export interface ApproveCallObject {
41
+ guy: string;
42
+ wad: BigNumber;
43
+ }
44
+
45
+ export type ApproveCallTrace = TypedCallTrace<
46
+ [string, BigNumber],
47
+ ApproveCallObject
48
+ >;
49
+
50
+ export interface TotalSupplyCallObject {}
51
+
52
+ export type TotalSupplyCallTrace = TypedCallTrace<[], TotalSupplyCallObject>;
53
+
54
+ export interface TransferFromCallObject {
55
+ src: string;
56
+ dst: string;
57
+ wad: BigNumber;
58
+ }
59
+
60
+ export type TransferFromCallTrace = TypedCallTrace<
61
+ [string, string, BigNumber],
62
+ TransferFromCallObject
63
+ >;
64
+
65
+ export interface WithdrawCallObject {
66
+ wad: BigNumber;
67
+ }
68
+
69
+ export type WithdrawCallTrace = TypedCallTrace<[BigNumber], WithdrawCallObject>;
70
+
71
+ export interface DecimalsCallObject {}
72
+
73
+ export type DecimalsCallTrace = TypedCallTrace<[], DecimalsCallObject>;
74
+
75
+ export interface BalanceOfCallObject {}
76
+
77
+ export type BalanceOfCallTrace = TypedCallTrace<[string], BalanceOfCallObject>;
78
+
79
+ export interface SymbolCallObject {}
80
+
81
+ export type SymbolCallTrace = TypedCallTrace<[], SymbolCallObject>;
82
+
83
+ export interface TransferCallObject {
84
+ dst: string;
85
+ wad: BigNumber;
86
+ }
87
+
88
+ export type TransferCallTrace = TypedCallTrace<
89
+ [string, BigNumber],
90
+ TransferCallObject
91
+ >;
92
+
93
+ export interface DepositCallObject {}
94
+
95
+ export type DepositCallTrace = TypedCallTrace<[], DepositCallObject>;
96
+
97
+ export interface AllowanceCallObject {}
98
+
99
+ export type AllowanceCallTrace = TypedCallTrace<
100
+ [string, string],
101
+ AllowanceCallObject
102
+ >;
103
+
34
104
  const templateContract = WETH9__factory.connect("", DummyProvider);
35
105
 
36
106
  export class WETH9ContractView extends ContractView<WETH9> {
@@ -252,7 +322,7 @@ export class WETH9ProcessorTemplate extends BaseProcessorTemplate<
252
322
  return processor;
253
323
  }
254
324
 
255
- onApproval(
325
+ onEventApproval(
256
326
  handler: (event: ApprovalEvent, ctx: WETH9Context) => void,
257
327
  filter?: ApprovalEventFilter | ApprovalEventFilter[]
258
328
  ) {
@@ -266,7 +336,7 @@ export class WETH9ProcessorTemplate extends BaseProcessorTemplate<
266
336
  return super.onEvent(handler, filter);
267
337
  }
268
338
 
269
- onTransfer(
339
+ onEventTransfer(
270
340
  handler: (event: TransferEvent, ctx: WETH9Context) => void,
271
341
  filter?: TransferEventFilter | TransferEventFilter[]
272
342
  ) {
@@ -280,7 +350,7 @@ export class WETH9ProcessorTemplate extends BaseProcessorTemplate<
280
350
  return super.onEvent(handler, filter);
281
351
  }
282
352
 
283
- onDeposit(
353
+ onEventDeposit(
284
354
  handler: (event: DepositEvent, ctx: WETH9Context) => void,
285
355
  filter?: DepositEventFilter | DepositEventFilter[]
286
356
  ) {
@@ -290,7 +360,7 @@ export class WETH9ProcessorTemplate extends BaseProcessorTemplate<
290
360
  return super.onEvent(handler, filter);
291
361
  }
292
362
 
293
- onWithdrawal(
363
+ onEventWithdrawal(
294
364
  handler: (event: WithdrawalEvent, ctx: WETH9Context) => void,
295
365
  filter?: WithdrawalEventFilter | WithdrawalEventFilter[]
296
366
  ) {
@@ -302,13 +372,71 @@ export class WETH9ProcessorTemplate extends BaseProcessorTemplate<
302
372
  }
303
373
  return super.onEvent(handler, filter);
304
374
  }
375
+
376
+ onCallName(handler: (call: NameCallTrace, ctx: WETH9Context) => void) {
377
+ return super.onTrace("0x06fdde03", handler);
378
+ }
379
+
380
+ onCallApprove(handler: (call: ApproveCallTrace, ctx: WETH9Context) => void) {
381
+ return super.onTrace("0x095ea7b3", handler);
382
+ }
383
+
384
+ onCallTotalSupply(
385
+ handler: (call: TotalSupplyCallTrace, ctx: WETH9Context) => void
386
+ ) {
387
+ return super.onTrace("0x18160ddd", handler);
388
+ }
389
+
390
+ onCallTransferFrom(
391
+ handler: (call: TransferFromCallTrace, ctx: WETH9Context) => void
392
+ ) {
393
+ return super.onTrace("0x23b872dd", handler);
394
+ }
395
+
396
+ onCallWithdraw(
397
+ handler: (call: WithdrawCallTrace, ctx: WETH9Context) => void
398
+ ) {
399
+ return super.onTrace("0x2e1a7d4d", handler);
400
+ }
401
+
402
+ onCallDecimals(
403
+ handler: (call: DecimalsCallTrace, ctx: WETH9Context) => void
404
+ ) {
405
+ return super.onTrace("0x313ce567", handler);
406
+ }
407
+
408
+ onCallBalanceOf(
409
+ handler: (call: BalanceOfCallTrace, ctx: WETH9Context) => void
410
+ ) {
411
+ return super.onTrace("0x70a08231", handler);
412
+ }
413
+
414
+ onCallSymbol(handler: (call: SymbolCallTrace, ctx: WETH9Context) => void) {
415
+ return super.onTrace("0x95d89b41", handler);
416
+ }
417
+
418
+ onCallTransfer(
419
+ handler: (call: TransferCallTrace, ctx: WETH9Context) => void
420
+ ) {
421
+ return super.onTrace("0xa9059cbb", handler);
422
+ }
423
+
424
+ onCallDeposit(handler: (call: DepositCallTrace, ctx: WETH9Context) => void) {
425
+ return super.onTrace("0xd0e30db0", handler);
426
+ }
427
+
428
+ onCallAllowance(
429
+ handler: (call: AllowanceCallTrace, ctx: WETH9Context) => void
430
+ ) {
431
+ return super.onTrace("0xdd62ed3e", handler);
432
+ }
305
433
  }
306
434
 
307
435
  export class WETH9Processor extends BaseProcessor<
308
436
  WETH9,
309
437
  WETH9BoundContractView
310
438
  > {
311
- onApproval(
439
+ onEventApproval(
312
440
  handler: (event: ApprovalEvent, ctx: WETH9Context) => void,
313
441
  filter?: ApprovalEventFilter | ApprovalEventFilter[]
314
442
  ) {
@@ -322,7 +450,7 @@ export class WETH9Processor extends BaseProcessor<
322
450
  return super.onEvent(handler, filter);
323
451
  }
324
452
 
325
- onTransfer(
453
+ onEventTransfer(
326
454
  handler: (event: TransferEvent, ctx: WETH9Context) => void,
327
455
  filter?: TransferEventFilter | TransferEventFilter[]
328
456
  ) {
@@ -336,7 +464,7 @@ export class WETH9Processor extends BaseProcessor<
336
464
  return super.onEvent(handler, filter);
337
465
  }
338
466
 
339
- onDeposit(
467
+ onEventDeposit(
340
468
  handler: (event: DepositEvent, ctx: WETH9Context) => void,
341
469
  filter?: DepositEventFilter | DepositEventFilter[]
342
470
  ) {
@@ -346,7 +474,7 @@ export class WETH9Processor extends BaseProcessor<
346
474
  return super.onEvent(handler, filter);
347
475
  }
348
476
 
349
- onWithdrawal(
477
+ onEventWithdrawal(
350
478
  handler: (event: WithdrawalEvent, ctx: WETH9Context) => void,
351
479
  filter?: WithdrawalEventFilter | WithdrawalEventFilter[]
352
480
  ) {
@@ -359,6 +487,64 @@ export class WETH9Processor extends BaseProcessor<
359
487
  return super.onEvent(handler, filter);
360
488
  }
361
489
 
490
+ onCallName(handler: (call: NameCallTrace, ctx: WETH9Context) => void) {
491
+ return super.onTrace("0x06fdde03", handler);
492
+ }
493
+
494
+ onCallApprove(handler: (call: ApproveCallTrace, ctx: WETH9Context) => void) {
495
+ return super.onTrace("0x095ea7b3", handler);
496
+ }
497
+
498
+ onCallTotalSupply(
499
+ handler: (call: TotalSupplyCallTrace, ctx: WETH9Context) => void
500
+ ) {
501
+ return super.onTrace("0x18160ddd", handler);
502
+ }
503
+
504
+ onCallTransferFrom(
505
+ handler: (call: TransferFromCallTrace, ctx: WETH9Context) => void
506
+ ) {
507
+ return super.onTrace("0x23b872dd", handler);
508
+ }
509
+
510
+ onCallWithdraw(
511
+ handler: (call: WithdrawCallTrace, ctx: WETH9Context) => void
512
+ ) {
513
+ return super.onTrace("0x2e1a7d4d", handler);
514
+ }
515
+
516
+ onCallDecimals(
517
+ handler: (call: DecimalsCallTrace, ctx: WETH9Context) => void
518
+ ) {
519
+ return super.onTrace("0x313ce567", handler);
520
+ }
521
+
522
+ onCallBalanceOf(
523
+ handler: (call: BalanceOfCallTrace, ctx: WETH9Context) => void
524
+ ) {
525
+ return super.onTrace("0x70a08231", handler);
526
+ }
527
+
528
+ onCallSymbol(handler: (call: SymbolCallTrace, ctx: WETH9Context) => void) {
529
+ return super.onTrace("0x95d89b41", handler);
530
+ }
531
+
532
+ onCallTransfer(
533
+ handler: (call: TransferCallTrace, ctx: WETH9Context) => void
534
+ ) {
535
+ return super.onTrace("0xa9059cbb", handler);
536
+ }
537
+
538
+ onCallDeposit(handler: (call: DepositCallTrace, ctx: WETH9Context) => void) {
539
+ return super.onTrace("0xd0e30db0", handler);
540
+ }
541
+
542
+ onCallAllowance(
543
+ handler: (call: AllowanceCallTrace, ctx: WETH9Context) => void
544
+ ) {
545
+ return super.onTrace("0xdd62ed3e", handler);
546
+ }
547
+
362
548
  public static filters = templateContract.filters;
363
549
 
364
550
  protected CreateBoundContractView(): WETH9BoundContractView {
package/src/context.ts CHANGED
@@ -28,6 +28,7 @@ export class EthContext extends BaseContext {
28
28
  this.chainId = chainId
29
29
  this.log = log
30
30
  this.block = block
31
+ this.trace = trace
31
32
  if (log) {
32
33
  this.blockNumber = Long.fromNumber(log.blockNumber)
33
34
  } else if (block) {
package/src/index.ts CHANGED
@@ -12,6 +12,7 @@ export { transformEtherError } from './error'
12
12
  export { ProcessorState } from './processor-state'
13
13
  export { BigNumber as BigDecimal } from 'bignumber.js'
14
14
  export { EthersError } from './error'
15
+ export type { TypedCallTrace } from './trace'
15
16
 
16
17
  export { getProcessor, addProcessor, getContractByABI, addContractByABI, getContractName } from './binds'
17
18
 
@@ -9,6 +9,7 @@ import {
9
9
  import { reservedKeywords } from '@typechain/ethers-v5/dist/codegen/reserved-keywords'
10
10
  import { generateInputTypes } from '@typechain/ethers-v5/dist/codegen/types'
11
11
  import { getFullSignatureForEvent } from 'typechain/dist/utils/signatures'
12
+ import { codegenCallTraceTypes, codegenFunctions } from './functions'
12
13
 
13
14
  export function codeGenIndex(contract: Contract): string {
14
15
  return `
@@ -19,6 +20,8 @@ export function codeGenIndex(contract: Contract): string {
19
20
 
20
21
  export function codeGenSentioFile(contract: Contract): string {
21
22
  const source = `
23
+ ${Object.values(contract.functions).map(codegenCallTraceTypes).join('\n')}
24
+
22
25
  const templateContract = ${contract.name}__factory.connect("", DummyProvider)
23
26
 
24
27
  export class ${contract.name}ContractView extends ContractView<${contract.name}> {
@@ -70,6 +73,10 @@ export function codeGenSentioFile(contract: Contract): string {
70
73
  }
71
74
  })
72
75
  .join('\n')}
76
+
77
+ ${Object.values(contract.functions)
78
+ .map((f) => codegenFunctions(f, contract.name))
79
+ .join('\n')}
73
80
  }
74
81
 
75
82
  export class ${contract.name}Processor extends BaseProcessor<${contract.name}, ${contract.name}BoundContractView> {
@@ -83,6 +90,10 @@ export function codeGenSentioFile(contract: Contract): string {
83
90
  })
84
91
  .join('\n')}
85
92
 
93
+ ${Object.values(contract.functions)
94
+ .map((f) => codegenFunctions(f, contract.name))
95
+ .join('\n')}
96
+
86
97
  public static filters = templateContract.filters
87
98
 
88
99
  protected CreateBoundContractView(): ${contract.name}BoundContractView {
@@ -134,6 +145,7 @@ export function codeGenSentioFile(contract: Contract): string {
134
145
  'ContractView',
135
146
  'DummyProvider',
136
147
  'getContractName',
148
+ 'TypedCallTrace',
137
149
  ],
138
150
  './common': ['PromiseOrValue'],
139
151
  './index': [`${contract.name}`, `${contract.name}__factory`],
@@ -208,7 +220,7 @@ function generateOnEventFunction(event: EventDeclaration, contractName: string,
208
220
  const filterName = getFullSignatureForEvent(event)
209
221
 
210
222
  return `
211
- on${eventName}(
223
+ onEvent${eventName}(
212
224
  handler: (event: ${eventName}Event, ctx: ${contractName}Context) => void,
213
225
  filter?: ${eventName}EventFilter | ${eventName}EventFilter[]
214
226
  ) {
@@ -0,0 +1,68 @@
1
+ import {
2
+ generateOutputComplexTypeAsArray,
3
+ generateOutputComplexTypesAsObject,
4
+ } from '@typechain/ethers-v5/dist/codegen/types'
5
+ import { FunctionDeclaration, getSignatureForFn } from 'typechain'
6
+ import { utils } from 'ethers'
7
+
8
+ export function codegenFunctions(fns: FunctionDeclaration[], contractName: string): string {
9
+ if (fns.length === 1) {
10
+ return generateFunction(fns[0], contractName)
11
+ }
12
+
13
+ return fns.map((fn) => generateFunction(fn, contractName, getFullSignatureAsSymbolForFunction(fn))).join('\n')
14
+ }
15
+
16
+ export function codegenCallTraceTypes(fns: FunctionDeclaration[]): string {
17
+ if (fns.length === 1) {
18
+ return codegenCallTraceType(fns[0])
19
+ }
20
+
21
+ return fns.map((fn) => codegenCallTraceType(fn, getFullSignatureAsSymbolForFunction(fn))).join('\n')
22
+ }
23
+
24
+ function codegenCallTraceType(fn: FunctionDeclaration, overloadedName?: string): string {
25
+ const identifier = capitalizeFirstChar(overloadedName ?? fn.name)
26
+
27
+ const components = fn.inputs.map((input, i) => ({ name: input.name ?? `arg${i.toString()}`, type: input.type }))
28
+ const arrayOutput = generateOutputComplexTypeAsArray(components, { useStructs: true })
29
+ const objectOutput = generateOutputComplexTypesAsObject(components, { useStructs: true }) || '{}'
30
+
31
+ return `
32
+ export interface ${identifier}CallObject ${objectOutput}
33
+
34
+ export type ${identifier}CallTrace = TypedCallTrace<${arrayOutput}, ${identifier}CallObject>
35
+ `
36
+ }
37
+
38
+ function generateFunction(fn: FunctionDeclaration, contractName: string, overloadedName?: string): string {
39
+ const signature = getSignatureForFn(fn)
40
+ const sighash = utils.keccak256(utils.toUtf8Bytes(signature)).substring(0, 10)
41
+
42
+ return `
43
+ onCall${capitalizeFirstChar(overloadedName ?? fn.name)}(
44
+ handler: (call: ${capitalizeFirstChar(overloadedName ?? fn.name)}CallTrace, ctx: ${contractName}Context) => void
45
+ ) {
46
+ return super.onTrace("${sighash}", handler);
47
+ }
48
+ `
49
+ }
50
+
51
+ function getFullSignatureAsSymbolForFunction(fn: FunctionDeclaration): string {
52
+ return `${fn.name}_${fn.inputs
53
+ .map((e) => {
54
+ if (e.type.type === 'array') {
55
+ return e.type.itemType.originalType + '_array'
56
+ } else {
57
+ return e.type.originalType
58
+ }
59
+ })
60
+ .join('_')}`
61
+ }
62
+
63
+ function capitalizeFirstChar(input: string): string {
64
+ if (!input) {
65
+ return input
66
+ }
67
+ return input[0].toUpperCase() + (input.length > 1 ? input.substring(1) : '')
68
+ }
@@ -5,7 +5,7 @@ export const filter = ERC20Processor.filters.Transfer(
5
5
  '0xb329e39ebefd16f40d38f07643652ce17ca5bac1'
6
6
  )
7
7
 
8
- const processorTemplate = new ERC20ProcessorTemplate().onTransfer(async function (event, ctx) {
8
+ const processorTemplate = new ERC20ProcessorTemplate().onEventTransfer(async function (event, ctx) {
9
9
  console.log('')
10
10
  })
11
11
 
@@ -14,7 +14,7 @@ ERC20Processor.bind({
14
14
  network: 1,
15
15
  name: 'x2y2',
16
16
  startBlock: 14201940,
17
- }).onTransfer(async function (event, ctx) {
17
+ }).onEventTransfer(async function (event, ctx) {
18
18
  processorTemplate.bind({
19
19
  address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
20
20
  network: 3,