@sentio/sdk 1.23.0 → 1.24.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 (44) hide show
  1. package/lib/aptos/aptos-processor.js +6 -18
  2. package/lib/aptos/aptos-processor.js.map +1 -1
  3. package/lib/aptos/context.d.ts +1 -1
  4. package/lib/aptos/context.js +1 -0
  5. package/lib/aptos/context.js.map +1 -1
  6. package/lib/core/base-processor.js +6 -25
  7. package/lib/core/base-processor.js.map +1 -1
  8. package/lib/core/context.d.ts +7 -5
  9. package/lib/core/context.js +15 -0
  10. package/lib/core/context.js.map +1 -1
  11. package/lib/core/event-tracker.d.ts +22 -0
  12. package/lib/core/event-tracker.js +53 -0
  13. package/lib/core/event-tracker.js.map +1 -0
  14. package/lib/core/index.d.ts +1 -0
  15. package/lib/core/index.js +4 -1
  16. package/lib/core/index.js.map +1 -1
  17. package/lib/core/solana-processor.js +1 -5
  18. package/lib/core/solana-processor.js.map +1 -1
  19. package/lib/core/sui-processor.js +1 -5
  20. package/lib/core/sui-processor.js.map +1 -1
  21. package/lib/gen/processor/protos/processor.d.ts +72 -0
  22. package/lib/gen/processor/protos/processor.js +481 -2
  23. package/lib/gen/processor/protos/processor.js.map +1 -1
  24. package/lib/processor-state.d.ts +4 -0
  25. package/lib/processor-state.js +2 -0
  26. package/lib/processor-state.js.map +1 -1
  27. package/lib/service.d.ts +2 -0
  28. package/lib/service.js +24 -1
  29. package/lib/service.js.map +1 -1
  30. package/lib/tests/erc20.js +3 -0
  31. package/lib/tests/erc20.js.map +1 -1
  32. package/package.json +1 -1
  33. package/src/aptos/aptos-processor.ts +6 -18
  34. package/src/aptos/context.ts +2 -1
  35. package/src/core/base-processor.ts +5 -25
  36. package/src/core/context.ts +29 -5
  37. package/src/core/event-tracker.ts +66 -0
  38. package/src/core/index.ts +1 -0
  39. package/src/core/solana-processor.ts +1 -5
  40. package/src/core/sui-processor.ts +1 -5
  41. package/src/gen/processor/protos/processor.ts +600 -1
  42. package/src/processor-state.ts +6 -0
  43. package/src/service.ts +28 -1
  44. package/src/tests/erc20.ts +4 -0
@@ -12,6 +12,8 @@ import { AptosBaseProcessor } from './aptos'
12
12
  import { BaseContract } from 'ethers'
13
13
  import { TemplateInstance } from './gen'
14
14
  import { Provider } from '@ethersproject/providers'
15
+ import { EventTracker } from './core'
16
+ import { Metric } from './core/meter'
15
17
 
16
18
  export class ProcessorState {
17
19
  // from abiName_address_chainId => contract wrapper
@@ -32,4 +34,8 @@ export class ProcessorState {
32
34
  suiProcessors: SuiBaseProcessor[] = []
33
35
 
34
36
  aptosProcessors: AptosBaseProcessor[] = []
37
+
38
+ eventTrackers: EventTracker[] = []
39
+
40
+ metrics: Metric[] = []
35
41
  }
package/src/service.ts CHANGED
@@ -8,9 +8,11 @@ import {
8
8
  BlockBinding,
9
9
  ContractConfig,
10
10
  DataBinding,
11
+ EventTrackingConfig,
11
12
  HandlerType,
12
13
  LogFilter,
13
14
  LogHandlerConfig,
15
+ MetricConfig,
14
16
  ProcessBindingResponse,
15
17
  ProcessBindingsRequest,
16
18
  ProcessBlocksRequest,
@@ -48,6 +50,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
48
50
  private started = false
49
51
  private contractConfigs: ContractConfig[]
50
52
  private templateInstances: TemplateInstance[]
53
+ private metricConfigs: MetricConfig[]
54
+ private eventTrackingConfigs: EventTrackingConfig[]
51
55
  private readonly loader: () => void
52
56
 
53
57
  private readonly shutdownHandler?: () => void
@@ -66,6 +70,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
66
70
  config: undefined,
67
71
  contractConfigs: this.contractConfigs,
68
72
  templateInstances: this.templateInstances,
73
+ eventTrackingConfigs: this.eventTrackingConfigs,
74
+ metricConfigs: this.metricConfigs,
69
75
  accountConfigs: [],
70
76
  }
71
77
  }
@@ -77,6 +83,26 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
77
83
  this.contractConfigs = []
78
84
 
79
85
  this.templateInstances = [...global.PROCESSOR_STATE.templatesInstances]
86
+ this.eventTrackingConfigs = []
87
+ this.metricConfigs = []
88
+
89
+ // part 0, prepare metrics and event tracking configs
90
+ for (const metric of global.PROCESSOR_STATE.metrics) {
91
+ this.metricConfigs.push({
92
+ ...metric.descriptor,
93
+ })
94
+ }
95
+
96
+ for (const eventTracker of global.PROCESSOR_STATE.eventTrackers) {
97
+ this.eventTrackingConfigs.push({
98
+ distinctAggregationByDays: eventTracker.options.distinctByDays || [],
99
+ eventName: eventTracker.eventName,
100
+ retentionConfig: undefined,
101
+ totalByDay: eventTracker.options.totalByDay || false,
102
+ totalPerEntity: undefined,
103
+ unique: eventTracker.options.unique || false,
104
+ })
105
+ }
80
106
 
81
107
  // Part 1, prepare EVM processors
82
108
  for (const processor of global.PROCESSOR_STATE.processors) {
@@ -208,7 +234,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
208
234
  this.contractConfigs.push(contractConfig)
209
235
  }
210
236
 
211
- // Part 3, prepare aptos constractors
237
+ // Part 4, prepare aptos constractors
212
238
  for (const aptosProcessor of global.PROCESSOR_STATE.aptosProcessors) {
213
239
  const contractConfig: ContractConfig = {
214
240
  processorType: USER_PROCESSOR,
@@ -650,6 +676,7 @@ function mergeProcessResults(results: ProcessResult[]): ProcessResult {
650
676
  res.counters = res.counters.concat(r.counters)
651
677
  res.gauges = res.gauges.concat(r.gauges)
652
678
  res.logs = res.logs.concat(r.logs)
679
+ res.events = res.events.concat(res.events)
653
680
  }
654
681
  return res
655
682
  }
@@ -1,10 +1,13 @@
1
1
  import { ERC20Processor, ERC20ProcessorTemplate } from '../builtin/erc20'
2
+ import { EventTracker } from '../core/event-tracker'
2
3
 
3
4
  export const filter = ERC20Processor.filters.Transfer(
4
5
  '0x0000000000000000000000000000000000000000',
5
6
  '0xb329e39ebefd16f40d38f07643652ce17ca5bac1'
6
7
  )
7
8
 
9
+ const tracker = EventTracker.register('sdf')
10
+
8
11
  const processorTemplate = new ERC20ProcessorTemplate().onEventTransfer(async function (event, ctx) {
9
12
  console.log('')
10
13
  })
@@ -30,6 +33,7 @@ ERC20Processor.bind({
30
33
  ERC20Processor.bind({ address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', network: 56, name: 'usdc' })
31
34
  .onEventTransfer(async function (event, ctx) {
32
35
  ctx.meter.Counter('c2').add(2)
36
+ tracker.trackEvent(ctx, { distinctId: event.args.from })
33
37
  }, filter)
34
38
  .onBlock(async function (block, ctx) {
35
39
  ctx.meter.Gauge('g2').record(20, { k: 'v' })