@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
@@ -0,0 +1,66 @@
1
+ import { BaseContext } from './context'
2
+ import { DataDescriptor, EventTrackingResult } from '@sentio/sdk'
3
+
4
+ export interface Event {
5
+ // The unique identifier of main identity associate with an event
6
+ // .e.g user id / toekn address / account address / contract address id
7
+ //
8
+ distinctId: string
9
+ payload?: Record<string, string>
10
+ }
11
+
12
+ export interface TrackerOptions {
13
+ totalByDay?: boolean
14
+ unique?: boolean
15
+ distinctByDays?: number[]
16
+ }
17
+
18
+ // Track Event with an identity associate with it
19
+ export class EventTracker {
20
+ static DEFAULT_OPTIONS: TrackerOptions = {
21
+ totalByDay: true,
22
+ unique: true,
23
+ }
24
+
25
+ static register(eventName: string, options?: TrackerOptions) {
26
+ const tracker = new EventTracker(eventName, { ...EventTracker.DEFAULT_OPTIONS, ...options })
27
+ global.PROCESSOR_STATE.eventTrackers.push(tracker)
28
+ return tracker
29
+ }
30
+
31
+ eventName: string
32
+ options: TrackerOptions
33
+ protected constructor(eventName: string, options: TrackerOptions) {
34
+ this.eventName = eventName
35
+ this.options = options
36
+ }
37
+
38
+ trackEvent(ctx: BaseContext, event: Event) {
39
+ const res: EventTrackingResult = {
40
+ metadata: ctx.getMetaData(DataDescriptor.fromPartial({ name: this.eventName }), {}),
41
+ distinctEntityId: event.distinctId,
42
+ attributes: JSON.stringify({}),
43
+ runtimeInfo: undefined,
44
+ }
45
+ ctx.events.push(res)
46
+ }
47
+ }
48
+
49
+ export class AccountEventTracker extends EventTracker {
50
+ static DEFAULT_OPTIONS: TrackerOptions = {
51
+ totalByDay: true,
52
+ unique: true,
53
+ distinctByDays: [1, 7, 30],
54
+ }
55
+
56
+ static register(eventName?: string, options?: TrackerOptions) {
57
+ if (eventName) {
58
+ ;['user', eventName].join('.')
59
+ } else {
60
+ eventName = 'user'
61
+ }
62
+ const tracker = new AccountEventTracker(eventName, { ...AccountEventTracker.DEFAULT_OPTIONS, ...options })
63
+ global.PROCESSOR_STATE.eventTrackers.push(tracker)
64
+ return tracker
65
+ }
66
+ }
package/src/core/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { BigDecimal } from './big-decimal'
2
2
  export { ContractContext, ContractView, BoundContractView, SolanaContext } from './context'
3
3
  export { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOptions } from './meter'
4
+ export { EventTracker, AccountEventTracker } from './event-tracker'
4
5
  export { type Numberish, toBigInteger, toMetricValue } from './numberish'
5
6
 
6
7
  export { BindOptions, SolanaBindOptions } from './bind-options'
@@ -80,11 +80,7 @@ export class SolanaBaseProcessor {
80
80
  ): ProcessResult {
81
81
  const ctx = new SolanaContext(this.contractName, this.address, slot)
82
82
  handler(parsedInstruction, ctx, accounts)
83
- return {
84
- gauges: ctx.gauges,
85
- counters: ctx.counters,
86
- logs: ctx.logs,
87
- }
83
+ return ctx.getProcessResult()
88
84
  }
89
85
 
90
86
  public isBind() {
@@ -39,11 +39,7 @@ export class SuiBaseProcessor {
39
39
  if (txn) {
40
40
  this.transactionHanlder(txn, ctx)
41
41
  }
42
- return {
43
- gauges: ctx.gauges,
44
- counters: ctx.counters,
45
- logs: ctx.logs,
46
- }
42
+ return ctx.getProcessResult()
47
43
  }
48
44
 
49
45
  public startSlot(startSlot: Long | number) {