@sentio/sdk 1.39.0 → 1.40.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/builtin/internal/eacaggregatorproxy_processor.d.ts +32 -31
- package/lib/builtin/internal/eacaggregatorproxy_processor.js +62 -62
- package/lib/builtin/internal/eacaggregatorproxy_processor.js.map +1 -1
- package/lib/builtin/internal/erc1155_processor.d.ts +17 -16
- package/lib/builtin/internal/erc1155_processor.js +32 -32
- package/lib/builtin/internal/erc1155_processor.js.map +1 -1
- package/lib/builtin/internal/erc20_processor.d.ts +25 -24
- package/lib/builtin/internal/erc20_processor.js +48 -48
- package/lib/builtin/internal/erc20_processor.js.map +1 -1
- package/lib/builtin/internal/erc20bytes_processor.d.ts +14 -13
- package/lib/builtin/internal/erc20bytes_processor.js +26 -26
- package/lib/builtin/internal/erc20bytes_processor.js.map +1 -1
- package/lib/builtin/internal/erc721_processor.d.ts +21 -20
- package/lib/builtin/internal/erc721_processor.js +40 -40
- package/lib/builtin/internal/erc721_processor.js.map +1 -1
- package/lib/builtin/internal/weth9_processor.d.ts +20 -19
- package/lib/builtin/internal/weth9_processor.js +38 -38
- package/lib/builtin/internal/weth9_processor.js.map +1 -1
- package/lib/core/account-processor.d.ts +14 -7
- package/lib/core/account-processor.js +27 -20
- package/lib/core/account-processor.js.map +1 -1
- package/lib/core/base-processor-template.d.ts +4 -2
- package/lib/core/base-processor-template.js +6 -2
- package/lib/core/base-processor-template.js.map +1 -1
- package/lib/core/base-processor.d.ts +5 -3
- package/lib/core/base-processor.js +9 -5
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/context.d.ts +8 -6
- package/lib/core/context.js +10 -6
- package/lib/core/context.js.map +1 -1
- package/lib/core/eth-plugin.js +4 -0
- package/lib/core/eth-plugin.js.map +1 -1
- package/lib/core/sui-plugin.js +1 -0
- package/lib/core/sui-plugin.js.map +1 -1
- package/lib/target-ethers-sentio/event-handler.js +3 -2
- package/lib/target-ethers-sentio/event-handler.js.map +1 -1
- package/lib/target-ethers-sentio/file.js +1 -0
- package/lib/target-ethers-sentio/file.js.map +1 -1
- package/lib/target-ethers-sentio/functions-handler.js +3 -2
- package/lib/target-ethers-sentio/functions-handler.js.map +1 -1
- package/lib/utils/price.js +1 -5
- package/lib/utils/price.js.map +1 -1
- package/package.json +4 -4
- package/src/builtin/internal/eacaggregatorproxy_processor.ts +101 -62
- package/src/builtin/internal/erc1155_processor.ts +54 -32
- package/src/builtin/internal/erc20_processor.ts +89 -48
- package/src/builtin/internal/erc20bytes_processor.ts +42 -26
- package/src/builtin/internal/erc721_processor.ts +69 -40
- package/src/builtin/internal/weth9_processor.ts +66 -38
- package/src/core/account-processor.ts +76 -28
- package/src/core/base-processor-template.ts +10 -3
- package/src/core/base-processor.ts +30 -11
- package/src/core/context.ts +25 -9
- package/src/core/eth-plugin.ts +4 -1
- package/src/core/sui-plugin.ts +1 -0
- package/src/target-ethers-sentio/event-handler.ts +3 -2
- package/src/target-ethers-sentio/file.ts +1 -0
- package/src/target-ethers-sentio/functions-handler.ts +3 -2
- package/src/utils/price.ts +1 -5
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
TypedCallTrace,
|
|
21
21
|
toBlockTag,
|
|
22
22
|
} from "@sentio/sdk";
|
|
23
|
+
import { EthFetchConfig } from "@sentio/protos";
|
|
23
24
|
import { PromiseOrValue } from "./common";
|
|
24
25
|
import { WETH9, WETH9__factory } from "./index";
|
|
25
26
|
import {
|
|
@@ -326,7 +327,8 @@ export class WETH9ProcessorTemplate extends BaseProcessorTemplate<
|
|
|
326
327
|
|
|
327
328
|
onEventApproval(
|
|
328
329
|
handler: (event: ApprovalEvent, ctx: WETH9Context) => void,
|
|
329
|
-
filter?: ApprovalEventFilter | ApprovalEventFilter[]
|
|
330
|
+
filter?: ApprovalEventFilter | ApprovalEventFilter[],
|
|
331
|
+
fetchConfig?: EthFetchConfig
|
|
330
332
|
) {
|
|
331
333
|
if (!filter) {
|
|
332
334
|
// @ts-ignore
|
|
@@ -335,12 +337,13 @@ export class WETH9ProcessorTemplate extends BaseProcessorTemplate<
|
|
|
335
337
|
"Approval(address,address,uint256)"
|
|
336
338
|
](null, null, null);
|
|
337
339
|
}
|
|
338
|
-
return super.onEvent(handler, filter
|
|
340
|
+
return super.onEvent(handler, filter!, fetchConfig);
|
|
339
341
|
}
|
|
340
342
|
|
|
341
343
|
onEventTransfer(
|
|
342
344
|
handler: (event: TransferEvent, ctx: WETH9Context) => void,
|
|
343
|
-
filter?: TransferEventFilter | TransferEventFilter[]
|
|
345
|
+
filter?: TransferEventFilter | TransferEventFilter[],
|
|
346
|
+
fetchConfig?: EthFetchConfig
|
|
344
347
|
) {
|
|
345
348
|
if (!filter) {
|
|
346
349
|
// @ts-ignore
|
|
@@ -349,12 +352,13 @@ export class WETH9ProcessorTemplate extends BaseProcessorTemplate<
|
|
|
349
352
|
"Transfer(address,address,uint256)"
|
|
350
353
|
](null, null, null);
|
|
351
354
|
}
|
|
352
|
-
return super.onEvent(handler, filter
|
|
355
|
+
return super.onEvent(handler, filter!, fetchConfig);
|
|
353
356
|
}
|
|
354
357
|
|
|
355
358
|
onEventDeposit(
|
|
356
359
|
handler: (event: DepositEvent, ctx: WETH9Context) => void,
|
|
357
|
-
filter?: DepositEventFilter | DepositEventFilter[]
|
|
360
|
+
filter?: DepositEventFilter | DepositEventFilter[],
|
|
361
|
+
fetchConfig?: EthFetchConfig
|
|
358
362
|
) {
|
|
359
363
|
if (!filter) {
|
|
360
364
|
// @ts-ignore
|
|
@@ -363,12 +367,13 @@ export class WETH9ProcessorTemplate extends BaseProcessorTemplate<
|
|
|
363
367
|
"Deposit(address,uint256)"
|
|
364
368
|
](null, null);
|
|
365
369
|
}
|
|
366
|
-
return super.onEvent(handler, filter
|
|
370
|
+
return super.onEvent(handler, filter!, fetchConfig);
|
|
367
371
|
}
|
|
368
372
|
|
|
369
373
|
onEventWithdrawal(
|
|
370
374
|
handler: (event: WithdrawalEvent, ctx: WETH9Context) => void,
|
|
371
|
-
filter?: WithdrawalEventFilter | WithdrawalEventFilter[]
|
|
375
|
+
filter?: WithdrawalEventFilter | WithdrawalEventFilter[],
|
|
376
|
+
fetchConfig?: EthFetchConfig
|
|
372
377
|
) {
|
|
373
378
|
if (!filter) {
|
|
374
379
|
// @ts-ignore
|
|
@@ -377,7 +382,7 @@ export class WETH9ProcessorTemplate extends BaseProcessorTemplate<
|
|
|
377
382
|
"Withdrawal(address,uint256)"
|
|
378
383
|
](null, null);
|
|
379
384
|
}
|
|
380
|
-
return super.onEvent(handler, filter
|
|
385
|
+
return super.onEvent(handler, filter!, fetchConfig);
|
|
381
386
|
}
|
|
382
387
|
}
|
|
383
388
|
|
|
@@ -387,7 +392,8 @@ export class WETH9Processor extends BaseProcessor<
|
|
|
387
392
|
> {
|
|
388
393
|
onEventApproval(
|
|
389
394
|
handler: (event: ApprovalEvent, ctx: WETH9Context) => void,
|
|
390
|
-
filter?: ApprovalEventFilter | ApprovalEventFilter[]
|
|
395
|
+
filter?: ApprovalEventFilter | ApprovalEventFilter[],
|
|
396
|
+
fetchConfig?: EthFetchConfig
|
|
391
397
|
) {
|
|
392
398
|
if (!filter) {
|
|
393
399
|
// @ts-ignore
|
|
@@ -396,12 +402,13 @@ export class WETH9Processor extends BaseProcessor<
|
|
|
396
402
|
"Approval(address,address,uint256)"
|
|
397
403
|
](null, null, null);
|
|
398
404
|
}
|
|
399
|
-
return super.onEvent(handler, filter
|
|
405
|
+
return super.onEvent(handler, filter!, fetchConfig);
|
|
400
406
|
}
|
|
401
407
|
|
|
402
408
|
onEventTransfer(
|
|
403
409
|
handler: (event: TransferEvent, ctx: WETH9Context) => void,
|
|
404
|
-
filter?: TransferEventFilter | TransferEventFilter[]
|
|
410
|
+
filter?: TransferEventFilter | TransferEventFilter[],
|
|
411
|
+
fetchConfig?: EthFetchConfig
|
|
405
412
|
) {
|
|
406
413
|
if (!filter) {
|
|
407
414
|
// @ts-ignore
|
|
@@ -410,12 +417,13 @@ export class WETH9Processor extends BaseProcessor<
|
|
|
410
417
|
"Transfer(address,address,uint256)"
|
|
411
418
|
](null, null, null);
|
|
412
419
|
}
|
|
413
|
-
return super.onEvent(handler, filter
|
|
420
|
+
return super.onEvent(handler, filter!, fetchConfig);
|
|
414
421
|
}
|
|
415
422
|
|
|
416
423
|
onEventDeposit(
|
|
417
424
|
handler: (event: DepositEvent, ctx: WETH9Context) => void,
|
|
418
|
-
filter?: DepositEventFilter | DepositEventFilter[]
|
|
425
|
+
filter?: DepositEventFilter | DepositEventFilter[],
|
|
426
|
+
fetchConfig?: EthFetchConfig
|
|
419
427
|
) {
|
|
420
428
|
if (!filter) {
|
|
421
429
|
// @ts-ignore
|
|
@@ -424,12 +432,13 @@ export class WETH9Processor extends BaseProcessor<
|
|
|
424
432
|
"Deposit(address,uint256)"
|
|
425
433
|
](null, null);
|
|
426
434
|
}
|
|
427
|
-
return super.onEvent(handler, filter
|
|
435
|
+
return super.onEvent(handler, filter!, fetchConfig);
|
|
428
436
|
}
|
|
429
437
|
|
|
430
438
|
onEventWithdrawal(
|
|
431
439
|
handler: (event: WithdrawalEvent, ctx: WETH9Context) => void,
|
|
432
|
-
filter?: WithdrawalEventFilter | WithdrawalEventFilter[]
|
|
440
|
+
filter?: WithdrawalEventFilter | WithdrawalEventFilter[],
|
|
441
|
+
fetchConfig?: EthFetchConfig
|
|
433
442
|
) {
|
|
434
443
|
if (!filter) {
|
|
435
444
|
// @ts-ignore
|
|
@@ -438,65 +447,84 @@ export class WETH9Processor extends BaseProcessor<
|
|
|
438
447
|
"Withdrawal(address,uint256)"
|
|
439
448
|
](null, null);
|
|
440
449
|
}
|
|
441
|
-
return super.onEvent(handler, filter
|
|
450
|
+
return super.onEvent(handler, filter!, fetchConfig);
|
|
442
451
|
}
|
|
443
452
|
|
|
444
|
-
onCallName(
|
|
445
|
-
|
|
453
|
+
onCallName(
|
|
454
|
+
handler: (call: NameCallTrace, ctx: WETH9Context) => void,
|
|
455
|
+
fetchConfig?: EthFetchConfig
|
|
456
|
+
) {
|
|
457
|
+
return super.onTrace("0x06fdde03", handler, fetchConfig);
|
|
446
458
|
}
|
|
447
459
|
|
|
448
|
-
onCallApprove(
|
|
449
|
-
|
|
460
|
+
onCallApprove(
|
|
461
|
+
handler: (call: ApproveCallTrace, ctx: WETH9Context) => void,
|
|
462
|
+
fetchConfig?: EthFetchConfig
|
|
463
|
+
) {
|
|
464
|
+
return super.onTrace("0x095ea7b3", handler, fetchConfig);
|
|
450
465
|
}
|
|
451
466
|
|
|
452
467
|
onCallTotalSupply(
|
|
453
|
-
handler: (call: TotalSupplyCallTrace, ctx: WETH9Context) => void
|
|
468
|
+
handler: (call: TotalSupplyCallTrace, ctx: WETH9Context) => void,
|
|
469
|
+
fetchConfig?: EthFetchConfig
|
|
454
470
|
) {
|
|
455
|
-
return super.onTrace("0x18160ddd", handler);
|
|
471
|
+
return super.onTrace("0x18160ddd", handler, fetchConfig);
|
|
456
472
|
}
|
|
457
473
|
|
|
458
474
|
onCallTransferFrom(
|
|
459
|
-
handler: (call: TransferFromCallTrace, ctx: WETH9Context) => void
|
|
475
|
+
handler: (call: TransferFromCallTrace, ctx: WETH9Context) => void,
|
|
476
|
+
fetchConfig?: EthFetchConfig
|
|
460
477
|
) {
|
|
461
|
-
return super.onTrace("0x23b872dd", handler);
|
|
478
|
+
return super.onTrace("0x23b872dd", handler, fetchConfig);
|
|
462
479
|
}
|
|
463
480
|
|
|
464
481
|
onCallWithdraw(
|
|
465
|
-
handler: (call: WithdrawCallTrace, ctx: WETH9Context) => void
|
|
482
|
+
handler: (call: WithdrawCallTrace, ctx: WETH9Context) => void,
|
|
483
|
+
fetchConfig?: EthFetchConfig
|
|
466
484
|
) {
|
|
467
|
-
return super.onTrace("0x2e1a7d4d", handler);
|
|
485
|
+
return super.onTrace("0x2e1a7d4d", handler, fetchConfig);
|
|
468
486
|
}
|
|
469
487
|
|
|
470
488
|
onCallDecimals(
|
|
471
|
-
handler: (call: DecimalsCallTrace, ctx: WETH9Context) => void
|
|
489
|
+
handler: (call: DecimalsCallTrace, ctx: WETH9Context) => void,
|
|
490
|
+
fetchConfig?: EthFetchConfig
|
|
472
491
|
) {
|
|
473
|
-
return super.onTrace("0x313ce567", handler);
|
|
492
|
+
return super.onTrace("0x313ce567", handler, fetchConfig);
|
|
474
493
|
}
|
|
475
494
|
|
|
476
495
|
onCallBalanceOf(
|
|
477
|
-
handler: (call: BalanceOfCallTrace, ctx: WETH9Context) => void
|
|
496
|
+
handler: (call: BalanceOfCallTrace, ctx: WETH9Context) => void,
|
|
497
|
+
fetchConfig?: EthFetchConfig
|
|
478
498
|
) {
|
|
479
|
-
return super.onTrace("0x70a08231", handler);
|
|
499
|
+
return super.onTrace("0x70a08231", handler, fetchConfig);
|
|
480
500
|
}
|
|
481
501
|
|
|
482
|
-
onCallSymbol(
|
|
483
|
-
|
|
502
|
+
onCallSymbol(
|
|
503
|
+
handler: (call: SymbolCallTrace, ctx: WETH9Context) => void,
|
|
504
|
+
fetchConfig?: EthFetchConfig
|
|
505
|
+
) {
|
|
506
|
+
return super.onTrace("0x95d89b41", handler, fetchConfig);
|
|
484
507
|
}
|
|
485
508
|
|
|
486
509
|
onCallTransfer(
|
|
487
|
-
handler: (call: TransferCallTrace, ctx: WETH9Context) => void
|
|
510
|
+
handler: (call: TransferCallTrace, ctx: WETH9Context) => void,
|
|
511
|
+
fetchConfig?: EthFetchConfig
|
|
488
512
|
) {
|
|
489
|
-
return super.onTrace("0xa9059cbb", handler);
|
|
513
|
+
return super.onTrace("0xa9059cbb", handler, fetchConfig);
|
|
490
514
|
}
|
|
491
515
|
|
|
492
|
-
onCallDeposit(
|
|
493
|
-
|
|
516
|
+
onCallDeposit(
|
|
517
|
+
handler: (call: DepositCallTrace, ctx: WETH9Context) => void,
|
|
518
|
+
fetchConfig?: EthFetchConfig
|
|
519
|
+
) {
|
|
520
|
+
return super.onTrace("0xd0e30db0", handler, fetchConfig);
|
|
494
521
|
}
|
|
495
522
|
|
|
496
523
|
onCallAllowance(
|
|
497
|
-
handler: (call: AllowanceCallTrace, ctx: WETH9Context) => void
|
|
524
|
+
handler: (call: AllowanceCallTrace, ctx: WETH9Context) => void,
|
|
525
|
+
fetchConfig?: EthFetchConfig
|
|
498
526
|
) {
|
|
499
|
-
return super.onTrace("0xdd62ed3e", handler);
|
|
527
|
+
return super.onTrace("0xdd62ed3e", handler, fetchConfig);
|
|
500
528
|
}
|
|
501
529
|
|
|
502
530
|
public static filters = templateContract.filters;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ListStateStorage } from '@sentio/runtime'
|
|
2
2
|
import { ERC20__factory, ERC721__factory } from '../builtin/internal'
|
|
3
|
-
import { AddressType, DummyProvider, ProcessResult } from '@sentio/sdk'
|
|
3
|
+
import { AddressType, DummyProvider, EthFetchConfig, ProcessResult } from '@sentio/sdk'
|
|
4
4
|
import { AccountBindOptions } from './bind-options'
|
|
5
|
-
import { getNetwork } from '@ethersproject/providers'
|
|
5
|
+
import { getNetwork, TransactionReceipt } from '@ethersproject/providers'
|
|
6
6
|
import { TransferEvent as ERC20TransferEvent } from '../builtin/internal/ERC20'
|
|
7
7
|
import { TransferEvent as ERC721TransferEvent } from '../builtin/internal/ERC721'
|
|
8
8
|
import { AccountContext } from './context'
|
|
@@ -10,6 +10,8 @@ import { PromiseOrVoid } from '../promise-or-void'
|
|
|
10
10
|
import { Event } from '@ethersproject/contracts'
|
|
11
11
|
import { BytesLike } from '@ethersproject/bytes'
|
|
12
12
|
import { AddressOrTypeEventFilter, EventsHandler } from './base-processor'
|
|
13
|
+
import { Block } from '@ethersproject/abstract-provider'
|
|
14
|
+
import { Transaction } from 'ethers'
|
|
13
15
|
|
|
14
16
|
export class AccountProcessorState extends ListStateStorage<AccountProcessor> {
|
|
15
17
|
static INSTANCE = new AccountProcessorState()
|
|
@@ -40,13 +42,18 @@ export class AccountProcessor {
|
|
|
40
42
|
* Register custom handler function to process erc20 transfer event to this account
|
|
41
43
|
* @param handler custom handler function
|
|
42
44
|
* @param tokensAddresses all the erc20 token address to watch
|
|
45
|
+
* @param fetchConfig
|
|
43
46
|
*/
|
|
44
47
|
onERC20TransferIn(
|
|
45
48
|
handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,
|
|
46
|
-
tokensAddresses: string[] = []
|
|
49
|
+
tokensAddresses: string[] = [],
|
|
50
|
+
fetchConfig?: EthFetchConfig
|
|
47
51
|
) {
|
|
48
|
-
return this.onERC20(
|
|
49
|
-
|
|
52
|
+
return this.onERC20(
|
|
53
|
+
handler,
|
|
54
|
+
tokensAddresses,
|
|
55
|
+
(address: string) => ERC20_CONTRACT.filters.Transfer(null, this.config.address),
|
|
56
|
+
fetchConfig
|
|
50
57
|
)
|
|
51
58
|
}
|
|
52
59
|
|
|
@@ -54,13 +61,18 @@ export class AccountProcessor {
|
|
|
54
61
|
* Register custom handler function to process erc20 transfer event from this account
|
|
55
62
|
* @param handler custom handler function
|
|
56
63
|
* @param tokensAddresses all the erc20 token address to watch
|
|
64
|
+
* @param fetchConfig
|
|
57
65
|
*/
|
|
58
66
|
onERC20TransferOut(
|
|
59
67
|
handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,
|
|
60
|
-
tokensAddresses: string[] = []
|
|
68
|
+
tokensAddresses: string[] = [],
|
|
69
|
+
fetchConfig?: EthFetchConfig
|
|
61
70
|
) {
|
|
62
|
-
return this.onERC20(
|
|
63
|
-
|
|
71
|
+
return this.onERC20(
|
|
72
|
+
handler,
|
|
73
|
+
tokensAddresses,
|
|
74
|
+
(address: string) => ERC20_CONTRACT.filters.Transfer(this.config.address),
|
|
75
|
+
fetchConfig
|
|
64
76
|
)
|
|
65
77
|
}
|
|
66
78
|
|
|
@@ -68,35 +80,47 @@ export class AccountProcessor {
|
|
|
68
80
|
* Register custom handler function to process erc20 mint for this account
|
|
69
81
|
* @param handler custom handler function
|
|
70
82
|
* @param tokensAddresses all the erc20 token address to watch
|
|
83
|
+
* @param fetchConfig
|
|
71
84
|
*/
|
|
72
85
|
onERC20Minted(
|
|
73
86
|
handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,
|
|
74
|
-
tokensAddresses: string[] = []
|
|
87
|
+
tokensAddresses: string[] = [],
|
|
88
|
+
fetchConfig?: EthFetchConfig
|
|
75
89
|
) {
|
|
76
|
-
return this.onERC20(
|
|
77
|
-
|
|
90
|
+
return this.onERC20(
|
|
91
|
+
handler,
|
|
92
|
+
tokensAddresses,
|
|
93
|
+
(address: string) =>
|
|
94
|
+
ERC20_CONTRACT.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address),
|
|
95
|
+
fetchConfig
|
|
78
96
|
)
|
|
79
97
|
}
|
|
80
98
|
|
|
81
99
|
private onERC20(
|
|
82
100
|
handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,
|
|
83
101
|
tokensAddresses: string[] = [],
|
|
84
|
-
defaultFilter: (address: string) => AddressOrTypeEventFilter
|
|
102
|
+
defaultFilter: (address: string) => AddressOrTypeEventFilter,
|
|
103
|
+
fetchConfig?: EthFetchConfig
|
|
85
104
|
) {
|
|
86
|
-
return this.onERC(handler, tokensAddresses, defaultFilter, AddressType.ERC20)
|
|
105
|
+
return this.onERC(handler, tokensAddresses, defaultFilter, AddressType.ERC20, fetchConfig)
|
|
87
106
|
}
|
|
88
107
|
|
|
89
108
|
/**
|
|
90
109
|
* Register custom handler function to process ERC721 transfer event to this account
|
|
91
110
|
* @param handler custom handler function
|
|
92
111
|
* @param collections all the ERC721 token address to watch, if not provided then watch all ERC721
|
|
112
|
+
* @param fetchConfig
|
|
93
113
|
*/
|
|
94
114
|
onERC721TransferIn(
|
|
95
115
|
handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,
|
|
96
|
-
collections: string[]
|
|
116
|
+
collections: string[],
|
|
117
|
+
fetchConfig?: EthFetchConfig
|
|
97
118
|
) {
|
|
98
|
-
return this.onERC721(
|
|
99
|
-
|
|
119
|
+
return this.onERC721(
|
|
120
|
+
handler,
|
|
121
|
+
collections,
|
|
122
|
+
(address: string) => ERC721_CONTRACT.filters.Transfer(null, this.config.address),
|
|
123
|
+
fetchConfig
|
|
100
124
|
)
|
|
101
125
|
}
|
|
102
126
|
|
|
@@ -104,13 +128,18 @@ export class AccountProcessor {
|
|
|
104
128
|
* Register custom handler function to process ERC721 transfer event from this account
|
|
105
129
|
* @param handler custom handler function
|
|
106
130
|
* @param collections all the ERC721 token address to watch, if not provided then watch all ERC721
|
|
131
|
+
* @param fetchConfig
|
|
107
132
|
*/
|
|
108
133
|
onERC721TransferOut(
|
|
109
134
|
handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,
|
|
110
|
-
collections: string[]
|
|
135
|
+
collections: string[],
|
|
136
|
+
fetchConfig?: EthFetchConfig
|
|
111
137
|
) {
|
|
112
|
-
return this.onERC721(
|
|
113
|
-
|
|
138
|
+
return this.onERC721(
|
|
139
|
+
handler,
|
|
140
|
+
collections,
|
|
141
|
+
(address: string) => ERC721_CONTRACT.filters.Transfer(this.config.address),
|
|
142
|
+
fetchConfig
|
|
114
143
|
)
|
|
115
144
|
}
|
|
116
145
|
|
|
@@ -118,29 +147,37 @@ export class AccountProcessor {
|
|
|
118
147
|
* Register custom handler function to process ERC721 mint for this account
|
|
119
148
|
* @param handler custom handler function
|
|
120
149
|
* @param collections all the ERC721 token address to watch, if not provided then watch all ERC721
|
|
150
|
+
* @param fetchConfig
|
|
121
151
|
*/
|
|
122
152
|
onERC721Minted(
|
|
123
153
|
handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,
|
|
124
|
-
collections: string[] = []
|
|
154
|
+
collections: string[] = [],
|
|
155
|
+
fetchConfig?: EthFetchConfig
|
|
125
156
|
) {
|
|
126
|
-
return this.onERC721(
|
|
127
|
-
|
|
157
|
+
return this.onERC721(
|
|
158
|
+
handler,
|
|
159
|
+
collections,
|
|
160
|
+
(address: string) =>
|
|
161
|
+
ERC721_CONTRACT.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address),
|
|
162
|
+
fetchConfig
|
|
128
163
|
)
|
|
129
164
|
}
|
|
130
165
|
|
|
131
166
|
private onERC721(
|
|
132
167
|
handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,
|
|
133
168
|
collections: string[],
|
|
134
|
-
defaultFilter: (address: string) => AddressOrTypeEventFilter
|
|
169
|
+
defaultFilter: (address: string) => AddressOrTypeEventFilter,
|
|
170
|
+
fetchConfig?: EthFetchConfig
|
|
135
171
|
) {
|
|
136
|
-
return this.onERC(handler, collections, defaultFilter, AddressType.ERC721)
|
|
172
|
+
return this.onERC(handler, collections, defaultFilter, AddressType.ERC721, fetchConfig)
|
|
137
173
|
}
|
|
138
174
|
|
|
139
175
|
private onERC(
|
|
140
176
|
handler: (event: any, ctx: AccountContext) => PromiseOrVoid,
|
|
141
177
|
contractAddresses: string[],
|
|
142
178
|
defaultFilter: (address: string) => AddressOrTypeEventFilter,
|
|
143
|
-
addressType: AddressType
|
|
179
|
+
addressType: AddressType,
|
|
180
|
+
fetchConfig?: EthFetchConfig
|
|
144
181
|
) {
|
|
145
182
|
const filters = []
|
|
146
183
|
for (const token of contractAddresses) {
|
|
@@ -154,12 +191,13 @@ export class AccountProcessor {
|
|
|
154
191
|
filter.addressType = addressType
|
|
155
192
|
filters.push(filter)
|
|
156
193
|
}
|
|
157
|
-
return this.onEvent(handler, filters)
|
|
194
|
+
return this.onEvent(handler, filters, fetchConfig)
|
|
158
195
|
}
|
|
159
196
|
|
|
160
197
|
protected onEvent(
|
|
161
198
|
handler: (event: Event, ctx: AccountContext) => PromiseOrVoid,
|
|
162
|
-
filter: AddressOrTypeEventFilter | AddressOrTypeEventFilter[]
|
|
199
|
+
filter: AddressOrTypeEventFilter | AddressOrTypeEventFilter[],
|
|
200
|
+
fetchConfig?: EthFetchConfig
|
|
163
201
|
) {
|
|
164
202
|
const chainId = this.getChainId()
|
|
165
203
|
|
|
@@ -191,9 +229,19 @@ export class AccountProcessor {
|
|
|
191
229
|
|
|
192
230
|
this.eventHandlers.push({
|
|
193
231
|
filters: _filters,
|
|
232
|
+
fetchConfig: fetchConfig || EthFetchConfig.fromPartial({}),
|
|
194
233
|
handler: async function (data) {
|
|
195
234
|
const log = data.log as Event
|
|
196
|
-
const ctx = new AccountContext(
|
|
235
|
+
const ctx = new AccountContext(
|
|
236
|
+
chainId,
|
|
237
|
+
config.address,
|
|
238
|
+
data.timestamp,
|
|
239
|
+
data.block as Block,
|
|
240
|
+
log,
|
|
241
|
+
undefined,
|
|
242
|
+
data.transaction as Transaction,
|
|
243
|
+
data.transactionReceipt as TransactionReceipt
|
|
244
|
+
)
|
|
197
245
|
const event: Event = log
|
|
198
246
|
const parsed = ERC20_CONTRACT.interface.parseLog(log)
|
|
199
247
|
if (parsed) {
|
|
@@ -4,7 +4,7 @@ import { BaseContract, EventFilter } from 'ethers'
|
|
|
4
4
|
import { Event } from '@ethersproject/contracts'
|
|
5
5
|
import { BaseProcessor } from './base-processor'
|
|
6
6
|
import { BindOptions, getOptionsSignature } from './bind-options'
|
|
7
|
-
import { HandleInterval, TemplateInstance } from '@sentio/protos'
|
|
7
|
+
import { EthFetchConfig, HandleInterval, TemplateInstance } from '@sentio/protos'
|
|
8
8
|
import { getNetwork } from '@ethersproject/providers'
|
|
9
9
|
import { PromiseOrVoid } from '../promise-or-void'
|
|
10
10
|
import { Trace } from './trace'
|
|
@@ -34,10 +34,12 @@ export abstract class BaseProcessorTemplate<
|
|
|
34
34
|
traceHandlers: {
|
|
35
35
|
signature: string
|
|
36
36
|
handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid
|
|
37
|
+
fetchConfig?: EthFetchConfig
|
|
37
38
|
}[] = []
|
|
38
39
|
eventHandlers: {
|
|
39
40
|
handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid
|
|
40
41
|
filter: EventFilter | EventFilter[]
|
|
42
|
+
fetchConfig?: EthFetchConfig
|
|
41
43
|
}[] = []
|
|
42
44
|
|
|
43
45
|
constructor() {
|
|
@@ -55,7 +57,10 @@ export abstract class BaseProcessorTemplate<
|
|
|
55
57
|
const processor = this.bindInternal(options)
|
|
56
58
|
|
|
57
59
|
for (const eh of this.eventHandlers) {
|
|
58
|
-
processor.onEvent(eh.handler, eh.filter)
|
|
60
|
+
processor.onEvent(eh.handler, eh.filter, eh.fetchConfig)
|
|
61
|
+
}
|
|
62
|
+
for (const th of this.traceHandlers) {
|
|
63
|
+
processor.onTrace(th.signature, th.handler, th.fetchConfig)
|
|
59
64
|
}
|
|
60
65
|
for (const bh of this.blockHandlers) {
|
|
61
66
|
processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval)
|
|
@@ -84,11 +89,13 @@ export abstract class BaseProcessorTemplate<
|
|
|
84
89
|
|
|
85
90
|
public onEvent(
|
|
86
91
|
handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
|
|
87
|
-
filter: EventFilter | EventFilter[]
|
|
92
|
+
filter: EventFilter | EventFilter[],
|
|
93
|
+
fetchConfig?: EthFetchConfig
|
|
88
94
|
) {
|
|
89
95
|
this.eventHandlers.push({
|
|
90
96
|
handler: handler,
|
|
91
97
|
filter: filter,
|
|
98
|
+
fetchConfig: fetchConfig,
|
|
92
99
|
})
|
|
93
100
|
return this
|
|
94
101
|
}
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import { BytesLike } from '@ethersproject/bytes'
|
|
2
|
-
import { Block, Log, getNetwork } from '@ethersproject/providers'
|
|
2
|
+
import { Block, Log, getNetwork, TransactionReceipt } from '@ethersproject/providers'
|
|
3
3
|
import { BaseContract, Event, EventFilter } from '@ethersproject/contracts'
|
|
4
4
|
|
|
5
5
|
import { BoundContractView, ContractContext, ContractView } from './context'
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
AddressType,
|
|
8
|
+
Data_EthBlock,
|
|
9
|
+
Data_EthLog,
|
|
10
|
+
Data_EthTrace,
|
|
11
|
+
EthFetchConfig,
|
|
12
|
+
HandleInterval,
|
|
13
|
+
ProcessResult,
|
|
14
|
+
} from '@sentio/protos'
|
|
7
15
|
import { BindInternalOptions, BindOptions } from './bind-options'
|
|
8
16
|
import { PromiseOrVoid } from '../promise-or-void'
|
|
9
17
|
import { Trace } from './trace'
|
|
10
18
|
import { ServerError, Status } from 'nice-grpc'
|
|
19
|
+
import { Transaction } from 'ethers'
|
|
11
20
|
|
|
12
21
|
export interface AddressOrTypeEventFilter extends EventFilter {
|
|
13
22
|
addressType?: AddressType
|
|
@@ -16,11 +25,13 @@ export interface AddressOrTypeEventFilter extends EventFilter {
|
|
|
16
25
|
export class EventsHandler {
|
|
17
26
|
filters: AddressOrTypeEventFilter[]
|
|
18
27
|
handler: (event: Data_EthLog) => Promise<ProcessResult>
|
|
28
|
+
fetchConfig: EthFetchConfig
|
|
19
29
|
}
|
|
20
30
|
|
|
21
31
|
export class TraceHandler {
|
|
22
32
|
signature: string
|
|
23
33
|
handler: (trace: Data_EthTrace) => Promise<ProcessResult>
|
|
34
|
+
fetchConfig: EthFetchConfig
|
|
24
35
|
}
|
|
25
36
|
|
|
26
37
|
export class BlockHandlder {
|
|
@@ -62,7 +73,8 @@ export abstract class BaseProcessor<
|
|
|
62
73
|
|
|
63
74
|
public onEvent(
|
|
64
75
|
handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
|
|
65
|
-
filter: EventFilter | EventFilter[]
|
|
76
|
+
filter: EventFilter | EventFilter[],
|
|
77
|
+
fetchConfig?: EthFetchConfig
|
|
66
78
|
) {
|
|
67
79
|
const chainId = this.getChainId()
|
|
68
80
|
|
|
@@ -78,6 +90,7 @@ export abstract class BaseProcessor<
|
|
|
78
90
|
const processor = this
|
|
79
91
|
this.eventHandlers.push({
|
|
80
92
|
filters: _filters,
|
|
93
|
+
fetchConfig: fetchConfig || EthFetchConfig.fromPartial({}),
|
|
81
94
|
handler: async function (data: Data_EthLog) {
|
|
82
95
|
if (!data.log) {
|
|
83
96
|
throw new ServerError(Status.INVALID_ARGUMENT, 'Log is empty')
|
|
@@ -90,10 +103,12 @@ export abstract class BaseProcessor<
|
|
|
90
103
|
contractName,
|
|
91
104
|
contractView,
|
|
92
105
|
chainId,
|
|
93
|
-
|
|
106
|
+
data.timestamp,
|
|
107
|
+
data.block as Block,
|
|
94
108
|
log,
|
|
95
109
|
undefined,
|
|
96
|
-
data.
|
|
110
|
+
data.transaction as Transaction,
|
|
111
|
+
data.transactionReceipt as TransactionReceipt
|
|
97
112
|
)
|
|
98
113
|
// let event: Event = <Event>deepCopy(log);
|
|
99
114
|
const event: Event = <Event>log
|
|
@@ -165,10 +180,10 @@ export abstract class BaseProcessor<
|
|
|
165
180
|
contractName,
|
|
166
181
|
contractView,
|
|
167
182
|
chainId,
|
|
183
|
+
new Date(block.timestamp * 1000),
|
|
168
184
|
block,
|
|
169
185
|
undefined,
|
|
170
|
-
undefined
|
|
171
|
-
new Date(block.timestamp * 1000)
|
|
186
|
+
undefined
|
|
172
187
|
)
|
|
173
188
|
await handler(block, ctx)
|
|
174
189
|
return ctx.getProcessResult()
|
|
@@ -191,9 +206,10 @@ export abstract class BaseProcessor<
|
|
|
191
206
|
}, _filters)
|
|
192
207
|
}
|
|
193
208
|
|
|
194
|
-
|
|
209
|
+
public onTrace(
|
|
195
210
|
signature: string,
|
|
196
|
-
handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid
|
|
211
|
+
handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
|
|
212
|
+
fetchConfig?: EthFetchConfig
|
|
197
213
|
) {
|
|
198
214
|
const chainId = this.getChainId()
|
|
199
215
|
const contractName = this.config.name
|
|
@@ -201,6 +217,7 @@ export abstract class BaseProcessor<
|
|
|
201
217
|
|
|
202
218
|
this.traceHandlers.push({
|
|
203
219
|
signature,
|
|
220
|
+
fetchConfig: fetchConfig || EthFetchConfig.fromPartial({}),
|
|
204
221
|
handler: async function (data: Data_EthTrace) {
|
|
205
222
|
const contractView = processor.CreateBoundContractView()
|
|
206
223
|
const contractInterface = contractView.rawContract.interface
|
|
@@ -219,10 +236,12 @@ export abstract class BaseProcessor<
|
|
|
219
236
|
contractName,
|
|
220
237
|
contractView,
|
|
221
238
|
chainId,
|
|
222
|
-
|
|
239
|
+
data.timestamp,
|
|
240
|
+
data.block as Block,
|
|
223
241
|
undefined,
|
|
224
242
|
trace,
|
|
225
|
-
data.
|
|
243
|
+
data.transaction as Transaction,
|
|
244
|
+
data.transactionReceipt as TransactionReceipt
|
|
226
245
|
)
|
|
227
246
|
await handler(trace, ctx)
|
|
228
247
|
return ctx.getProcessResult()
|