@sentio/sdk 2.59.0-rc.2 → 2.59.0-rc.20

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 (144) hide show
  1. package/lib/aptos/api.d.ts +1 -0
  2. package/lib/aptos/api.d.ts.map +1 -1
  3. package/lib/aptos/api.js +13 -1
  4. package/lib/aptos/api.js.map +1 -1
  5. package/lib/aptos/aptos-plugin.d.ts.map +1 -1
  6. package/lib/aptos/aptos-plugin.js +11 -5
  7. package/lib/aptos/aptos-plugin.js.map +1 -1
  8. package/lib/aptos/aptos-processor.d.ts +1 -0
  9. package/lib/aptos/aptos-processor.d.ts.map +1 -1
  10. package/lib/aptos/aptos-processor.js +1 -0
  11. package/lib/aptos/aptos-processor.js.map +1 -1
  12. package/lib/aptos/builtin/0x1.d.ts +485 -0
  13. package/lib/aptos/builtin/0x1.d.ts.map +1 -1
  14. package/lib/aptos/builtin/0x1.js +824 -1
  15. package/lib/aptos/builtin/0x1.js.map +1 -1
  16. package/lib/aptos/builtin/0x3.d.ts.map +1 -1
  17. package/lib/aptos/builtin/0x3.js +1 -1
  18. package/lib/aptos/builtin/0x3.js.map +1 -1
  19. package/lib/aptos/builtin/0x4.d.ts.map +1 -1
  20. package/lib/aptos/builtin/0x4.js +1 -1
  21. package/lib/aptos/builtin/0x4.js.map +1 -1
  22. package/lib/aptos/codegen/codegen.js +7 -7
  23. package/lib/aptos/codegen/codegen.js.map +1 -1
  24. package/lib/aptos/move-coder.d.ts +8 -2
  25. package/lib/aptos/move-coder.d.ts.map +1 -1
  26. package/lib/aptos/move-coder.js +84 -1
  27. package/lib/aptos/move-coder.js.map +1 -1
  28. package/lib/aptos/network.d.ts +1 -0
  29. package/lib/aptos/network.d.ts.map +1 -1
  30. package/lib/aptos/network.js +1 -0
  31. package/lib/aptos/network.js.map +1 -1
  32. package/lib/core/base-context.d.ts +2 -1
  33. package/lib/core/base-context.d.ts.map +1 -1
  34. package/lib/core/base-context.js +5 -2
  35. package/lib/core/base-context.js.map +1 -1
  36. package/lib/core/event-logger.d.ts +5 -0
  37. package/lib/core/event-logger.d.ts.map +1 -1
  38. package/lib/core/event-logger.js +36 -1
  39. package/lib/core/event-logger.js.map +1 -1
  40. package/lib/core/meter.d.ts +31 -3
  41. package/lib/core/meter.d.ts.map +1 -1
  42. package/lib/core/meter.js +93 -2
  43. package/lib/core/meter.js.map +1 -1
  44. package/lib/core/numberish.d.ts +2 -1
  45. package/lib/core/numberish.d.ts.map +1 -1
  46. package/lib/core/numberish.js +35 -1
  47. package/lib/core/numberish.js.map +1 -1
  48. package/lib/eth/base-processor.d.ts +3 -3
  49. package/lib/eth/base-processor.d.ts.map +1 -1
  50. package/lib/eth/base-processor.js +22 -8
  51. package/lib/eth/base-processor.js.map +1 -1
  52. package/lib/eth/bind-options.d.ts +6 -0
  53. package/lib/eth/bind-options.d.ts.map +1 -1
  54. package/lib/eth/bind-options.js +2 -0
  55. package/lib/eth/bind-options.js.map +1 -1
  56. package/lib/eth/eth-plugin.d.ts.map +1 -1
  57. package/lib/eth/eth-plugin.js +12 -5
  58. package/lib/eth/eth-plugin.js.map +1 -1
  59. package/lib/fuel/fuel-processor.d.ts.map +1 -1
  60. package/lib/fuel/fuel-processor.js +1 -9
  61. package/lib/fuel/fuel-processor.js.map +1 -1
  62. package/lib/stark/starknet-processor.d.ts.map +1 -1
  63. package/lib/stark/starknet-processor.js +5 -12
  64. package/lib/stark/starknet-processor.js.map +1 -1
  65. package/lib/store/codegen.d.ts.map +1 -1
  66. package/lib/store/codegen.js +36 -2
  67. package/lib/store/codegen.js.map +1 -1
  68. package/lib/store/schema.d.ts.map +1 -1
  69. package/lib/store/schema.js +3 -1
  70. package/lib/store/schema.js.map +1 -1
  71. package/lib/store/store.d.ts +4 -3
  72. package/lib/store/store.d.ts.map +1 -1
  73. package/lib/store/store.js +41 -1
  74. package/lib/store/store.js.map +1 -1
  75. package/lib/store/types.d.ts +20 -1
  76. package/lib/store/types.d.ts.map +1 -1
  77. package/lib/store/types.js +22 -0
  78. package/lib/store/types.js.map +1 -1
  79. package/lib/sui/builtin/0x1.d.ts +4 -0
  80. package/lib/sui/builtin/0x1.d.ts.map +1 -1
  81. package/lib/sui/builtin/0x1.js +1 -1
  82. package/lib/sui/builtin/0x1.js.map +1 -1
  83. package/lib/sui/builtin/0x2.d.ts +63 -0
  84. package/lib/sui/builtin/0x2.d.ts.map +1 -1
  85. package/lib/sui/builtin/0x2.js +279 -1
  86. package/lib/sui/builtin/0x2.js.map +1 -1
  87. package/lib/sui/builtin/0x3.d.ts +41 -14
  88. package/lib/sui/builtin/0x3.d.ts.map +1 -1
  89. package/lib/sui/builtin/0x3.js +128 -10
  90. package/lib/sui/builtin/0x3.js.map +1 -1
  91. package/lib/sui/sui-object-processor-template.js +1 -1
  92. package/lib/sui/sui-object-processor-template.js.map +1 -1
  93. package/lib/sui/sui-object-processor.d.ts +2 -0
  94. package/lib/sui/sui-object-processor.d.ts.map +1 -1
  95. package/lib/sui/sui-object-processor.js +4 -0
  96. package/lib/sui/sui-object-processor.js.map +1 -1
  97. package/lib/sui/sui-plugin.d.ts.map +1 -1
  98. package/lib/sui/sui-plugin.js +9 -4
  99. package/lib/sui/sui-plugin.js.map +1 -1
  100. package/lib/sui/sui-processor.d.ts +1 -0
  101. package/lib/sui/sui-processor.d.ts.map +1 -1
  102. package/lib/sui/sui-processor.js +1 -0
  103. package/lib/sui/sui-processor.js.map +1 -1
  104. package/lib/utils/block.d.ts +2 -0
  105. package/lib/utils/block.d.ts.map +1 -1
  106. package/lib/utils/block.js +13 -0
  107. package/lib/utils/block.js.map +1 -1
  108. package/package.json +9 -8
  109. package/src/aptos/abis/0x1.json +9650 -5284
  110. package/src/aptos/abis/0x3.json +13 -13
  111. package/src/aptos/abis/0x4.json +42 -42
  112. package/src/aptos/api.ts +13 -1
  113. package/src/aptos/aptos-plugin.ts +11 -5
  114. package/src/aptos/aptos-processor.ts +2 -0
  115. package/src/aptos/builtin/0x1.ts +1566 -67
  116. package/src/aptos/builtin/0x3.ts +2 -1
  117. package/src/aptos/builtin/0x4.ts +2 -1
  118. package/src/aptos/codegen/codegen.ts +9 -7
  119. package/src/aptos/move-coder.ts +96 -3
  120. package/src/aptos/network.ts +1 -0
  121. package/src/core/base-context.ts +5 -2
  122. package/src/core/event-logger.ts +45 -1
  123. package/src/core/meter.ts +120 -5
  124. package/src/core/numberish.ts +34 -1
  125. package/src/eth/base-processor.ts +23 -9
  126. package/src/eth/bind-options.ts +7 -0
  127. package/src/eth/eth-plugin.ts +22 -5
  128. package/src/fuel/fuel-processor.ts +1 -9
  129. package/src/stark/starknet-processor.ts +4 -12
  130. package/src/store/codegen.ts +50 -2
  131. package/src/store/schema.ts +3 -1
  132. package/src/store/store.ts +57 -4
  133. package/src/store/types.ts +30 -1
  134. package/src/sui/abis/0x1.json +8 -0
  135. package/src/sui/abis/0x2.json +437 -0
  136. package/src/sui/abis/0x3.json +116 -5
  137. package/src/sui/builtin/0x1.ts +6 -1
  138. package/src/sui/builtin/0x2.ts +413 -1
  139. package/src/sui/builtin/0x3.ts +211 -22
  140. package/src/sui/sui-object-processor-template.ts +1 -1
  141. package/src/sui/sui-object-processor.ts +6 -0
  142. package/src/sui/sui-plugin.ts +9 -4
  143. package/src/sui/sui-processor.ts +2 -0
  144. package/src/utils/block.ts +15 -0
@@ -26,9 +26,9 @@ class AptosNetworkCodegen extends BaseAptosCodegen {
26
26
  moduleGenerator: SharedNetworkCodegen<AptosNetwork, MoveModuleBytecode, Event | MoveResource>
27
27
  SYSTEM_PACKAGE = '@sentio/sdk/aptos'
28
28
 
29
- constructor(network: AptosNetwork) {
29
+ constructor(network: AptosNetwork, useViewJson = false) {
30
30
  const endpoint = getRpcEndpoint(network)
31
- super(endpoint)
31
+ super(endpoint, useViewJson)
32
32
  const generator = this
33
33
 
34
34
  this.moduleGenerator = new (class extends SharedNetworkCodegen<
@@ -54,6 +54,7 @@ class AptosNetworkCodegen extends BaseAptosCodegen {
54
54
  protected getGetDefaultCoder() {
55
55
  return `defaultMoveCoderForClient(client)`
56
56
  }
57
+
57
58
  generateModule(module: InternalMoveModule, allEventStructs: Map<string, InternalMoveStruct>) {
58
59
  return this.moduleGenerator.generateModule(module, allEventStructs)
59
60
  }
@@ -67,9 +68,10 @@ class AptosNetworkCodegen extends BaseAptosCodegen {
67
68
  MoveCoder, TypedEventInstance } from "@typemove/${this.PREFIX.toLowerCase()}"
68
69
 
69
70
  import { defaultMoveCoder, defaultMoveCoderForClient } from "${this.defaultCoderPackage()}"
70
- import { Aptos, Account as AptosAccount, MoveAddressType, PendingTransactionResponse, InputGenerateTransactionOptions, MoveStructId, InputViewFunctionData } from '@aptos-labs/ts-sdk'`
71
+ import { Aptos, Account as AptosAccount, MoveAddressType, PendingTransactionResponse, InputGenerateTransactionOptions, MoveStructId, InputViewFunctionData, InputViewFunctionJsonData } from '@aptos-labs/ts-sdk'`
71
72
  )
72
73
  }
74
+
73
75
  generateLoadAll(isSystem: boolean): string {
74
76
  return this.moduleGenerator.generateLoadAll(isSystem)
75
77
  }
@@ -79,13 +81,13 @@ const ADDRESS_LENGTH = 64
79
81
 
80
82
  class InitiaAptosNetworkCodegen extends AptosNetworkCodegen {
81
83
  constructor(network: AptosNetwork) {
82
- super(network)
84
+ super(network, true)
83
85
 
84
- const oldFetchModules = this.chainAdapter.fetchModules
86
+ const oldFetchModules = this.chainAdapter.fetchModules.bind(this.chainAdapter)
85
87
  this.chainAdapter.fetchModules = async (address: string) => {
86
88
  return oldFetchModules(this.padZero(address))
87
89
  }
88
- const oldFetchModule = this.chainAdapter.fetchModule
90
+ const oldFetchModule = this.chainAdapter.fetchModule.bind(this.chainAdapter)
89
91
  this.chainAdapter.fetchModule = async (address: string, moduleName: string) => {
90
92
  return oldFetchModule(this.padZero(address), moduleName)
91
93
  }
@@ -117,7 +119,7 @@ class AptosCodegen {
117
119
  ]
118
120
 
119
121
  for (const [network, gen] of generators) {
120
- const exclude = network ? [] : ['testnet', 'movement-mainnet', 'movement-testnet']
122
+ const exclude = network ? [] : ['testnet', 'movement-mainnet', 'movement-testnet', 'initia-echelon']
121
123
  numFiles += await recursiveCodegen(
122
124
  path.join(srcDir, network),
123
125
  path.join(outputDir, network),
@@ -1,6 +1,7 @@
1
1
  import { AptosNetwork, getClient } from './network.js'
2
- import { MoveCoder } from '@typemove/aptos'
3
- import { Aptos } from '@aptos-labs/ts-sdk'
2
+ import { MoveCoder, TypedFunctionPayload } from '@typemove/aptos'
3
+ import { Aptos, EntryFunctionPayloadResponse } from '@aptos-labs/ts-sdk'
4
+ import { TypeDescriptor, VECTOR_STR } from '@typemove/move'
4
5
 
5
6
  const CODERS = new Map<AptosNetwork, MoveCoder>()
6
7
  const URL_CODERS = new Map<string, MoveCoder>()
@@ -9,7 +10,8 @@ export function defaultMoveCoder(network: AptosNetwork = AptosNetwork.MAIN_NET):
9
10
  let coder = CODERS.get(network)
10
11
  if (!coder) {
11
12
  const client = getClient(network)
12
- coder = new MoveCoder(getClient(network))
13
+
14
+ coder = network == AptosNetwork.INITIA_ECHELON ? new InitiaMoveCoder(client) : new MoveCoder(client)
13
15
  CODERS.set(network, coder)
14
16
  URL_CODERS.set(client.config.fullnode || '', coder)
15
17
  }
@@ -29,3 +31,94 @@ export function defaultMoveCoderForClient(client: Aptos): MoveCoder {
29
31
  }
30
32
  return coder
31
33
  }
34
+
35
+ export class InitiaMoveCoder extends MoveCoder {
36
+ constructor(client: Aptos) {
37
+ super(client, true)
38
+ }
39
+
40
+ async decodeFunctionPayload<T extends Array<any>>(
41
+ payload: EntryFunctionPayloadResponse
42
+ ): Promise<TypedFunctionPayload<T>> {
43
+ const func = await this.getMoveFunction(payload.function)
44
+ const paramsTypes = this.adapter.getMeaningfulFunctionParams(func.params)
45
+ const argumentsDecoded = []
46
+
47
+ for (let i = 0; i < paramsTypes.length; i++) {
48
+ const arg = payload.arguments[i]
49
+ const paramType = paramsTypes[i]
50
+ if (arg == null) {
51
+ argumentsDecoded.push(null)
52
+ } else {
53
+ argumentsDecoded.push(await this.decodeBase64(Buffer.from(arg, 'base64'), paramType))
54
+ }
55
+ }
56
+
57
+ return {
58
+ ...payload,
59
+ arguments_decoded: argumentsDecoded
60
+ } as TypedFunctionPayload<T>
61
+ }
62
+
63
+ protected async decodeBase64(b: Buffer, type: TypeDescriptor): Promise<any> {
64
+ switch (type.qname.toLowerCase()) {
65
+ case 'signer': // TODO check this, aptos only
66
+ case 'address':
67
+ case '0x1::string::String':
68
+ return b.toString()
69
+ case 'bool':
70
+ return b.readUInt8() !== 0 // Convert first byte to boolean
71
+ case 'u8':
72
+ return b.readUInt8()
73
+ case 'u16':
74
+ return b.readUInt16LE()
75
+ case 'u32':
76
+ return b.readUInt32LE()
77
+ case 'u64':
78
+ return b.readBigUInt64LE()
79
+ case 'u128':
80
+ case 'u256':
81
+ const hex = b.toString('hex')
82
+ const reversedHex = hex.match(/.{2}/g)?.reverse().join('') || ''
83
+ return BigInt('0x' + reversedHex)
84
+ case '0x1::object::object':
85
+ return b.toString('hex')
86
+ case VECTOR_STR:
87
+ // vector<u8> as hex string
88
+ if (type.typeArgs[0].qname === 'u8' || type.typeArgs[0].qname === 'U8') {
89
+ return b.toString('hex')
90
+ }
91
+
92
+ console.warn(`can't decode vector type: ${type.qname}, data: ${b.toString('base64')}`)
93
+ return b.toString('base64')
94
+ default:
95
+ // try enum type first
96
+ const enumType = await this.maybeGetMoveEnum(type.qname)
97
+ if (enumType) {
98
+ return b.toString('utf-8')
99
+ }
100
+
101
+ // Process complex type
102
+ /*const struct = await this.getMoveStruct(type.qname)
103
+
104
+ const typeCtx = new Map<string, TypeDescriptor>()
105
+ for (const [idx, typeArg] of type.typeArgs.entries()) {
106
+ typeCtx.set('T' + idx, typeArg)
107
+ }
108
+
109
+ const typedData: any = {}
110
+
111
+ for (const field of struct.fields) {
112
+ let filedType = field.type
113
+ filedType = filedType.applyTypeArgs(typeCtx)
114
+ const fieldValue = this.adapter.getData(data)[field.name]
115
+ const value = await this.decode(fieldValue, filedType)
116
+ typedData[field.name] = value
117
+ }*/
118
+
119
+ // todo: how to decode complex type?
120
+ console.warn(`can't decode type:${type.qname}, data: ${b.toString('base64')}`)
121
+ return b.toString('hex')
122
+ }
123
+ }
124
+ }
@@ -25,6 +25,7 @@ export class AptosBindOptions {
25
25
  network?: AptosNetwork = AptosNetwork.MAIN_NET
26
26
  client?: Aptos
27
27
  startVersion?: bigint | number
28
+ endVersion?: bigint | number
28
29
  baseLabels?: Labels
29
30
  }
30
31
 
@@ -1,5 +1,5 @@
1
1
  import { ProcessResult, RecordMetaData } from '@sentio/protos'
2
- import { EventLoggerBinding } from './event-logger.js'
2
+ import { EventLoggerBinding, EventLoggerBindingNew } from './event-logger.js'
3
3
  import { Meter, Labels } from './meter.js'
4
4
  import { ChainId } from '@sentio/chain'
5
5
  import { mergeProcessResults, PluginManager } from '@sentio/runtime'
@@ -10,6 +10,7 @@ import { Store } from '../store/store.js'
10
10
  export abstract class BaseContext {
11
11
  meter: Meter
12
12
  eventLogger: EventLoggerBinding
13
+ eventLoggerNew: EventLoggerBindingNew
13
14
  private _store: Store
14
15
  baseLabels: Labels
15
16
  private active: boolean
@@ -21,7 +22,8 @@ export abstract class BaseContext {
21
22
  gauges: [],
22
23
  states: {
23
24
  configUpdated: false
24
- }
25
+ },
26
+ timeseriesResult: []
25
27
  }
26
28
 
27
29
  public update(res: Partial<ProcessResult>) {
@@ -35,6 +37,7 @@ export abstract class BaseContext {
35
37
  protected constructor(baseLabels: Labels | undefined) {
36
38
  this.meter = new Meter(this)
37
39
  this.eventLogger = new EventLoggerBinding(this)
40
+ this.eventLoggerNew = new EventLoggerBindingNew(this)
38
41
  this.baseLabels = baseLabels || {}
39
42
  this.active = true
40
43
  this.initStore()
@@ -6,7 +6,10 @@ import {
6
6
  EventLogConfig_Field,
7
7
  EventLogConfig_StructFieldType,
8
8
  EventTrackingResult,
9
- LogLevel
9
+ LogLevel,
10
+ RichStruct,
11
+ TimeseriesResult,
12
+ TimeseriesResult_TimeseriesType
10
13
  } from '@sentio/protos'
11
14
  import { normalizeAttribute, normalizeLabels, normalizeToRichStruct } from './normalization.js'
12
15
  import { MapStateStorage, processMetrics } from '@sentio/runtime'
@@ -141,3 +144,44 @@ function checkEventName(eventName: string) {
141
144
  throw new Error(`Event name ${eventName} is already used in the database schema`)
142
145
  }
143
146
  }
147
+
148
+ function emitNew<T>(ctx: BaseContext, eventName: string, event: Event<T>) {
149
+ const { distinctId, severity, message, ...payload } = event
150
+
151
+ const data: RichStruct = {
152
+ fields: {
153
+ severity: {
154
+ stringValue: (severity || LogLevel.INFO).toString()
155
+ },
156
+ message: {
157
+ stringValue: message || ''
158
+ },
159
+ distinctEntityId: {
160
+ stringValue: distinctId || ''
161
+ },
162
+ ...normalizeToRichStruct(ctx.baseLabels, payload).fields
163
+ }
164
+ }
165
+ const res: TimeseriesResult = {
166
+ metadata: ctx.getMetaData(eventName, {}),
167
+ type: TimeseriesResult_TimeseriesType.EVENT,
168
+ data,
169
+ runtimeInfo: undefined
170
+ }
171
+
172
+ processMetrics.process_eventemit_count.add(1)
173
+ ctx.update({ timeseriesResult: [res] })
174
+ }
175
+
176
+ export class EventLoggerBindingNew {
177
+ private readonly ctx: BaseContext
178
+
179
+ constructor(ctx: BaseContext) {
180
+ this.ctx = ctx
181
+ }
182
+
183
+ emit<T>(eventName: string, event: Event<T>) {
184
+ checkEventName(eventName)
185
+ emitNew(this.ctx, eventName, event)
186
+ }
187
+ }
package/src/core/meter.ts CHANGED
@@ -1,7 +1,13 @@
1
1
  import { BaseContext } from './base-context.js'
2
- import { Numberish, toMetricValue } from './numberish.js'
2
+ import { Numberish, toMetricValue, toTimeSeriesData } from './numberish.js'
3
3
  import { NamedResultDescriptor } from './metadata.js'
4
- import { AggregationConfig, AggregationType, MetricConfig, MetricType } from '@sentio/protos'
4
+ import {
5
+ AggregationConfig,
6
+ AggregationType,
7
+ MetricConfig,
8
+ MetricType,
9
+ TimeseriesResult_TimeseriesType
10
+ } from '@sentio/protos'
5
11
  import { MapStateStorage, processMetrics } from '@sentio/runtime'
6
12
 
7
13
  export type Labels = { [key: string]: string }
@@ -30,6 +36,7 @@ export class CounterOptions {
30
36
 
31
37
  export class Metric extends NamedResultDescriptor {
32
38
  config: MetricConfig
39
+
33
40
  constructor(type: MetricType, name: string, option?: MetricConfig) {
34
41
  super(name)
35
42
  this.config = MetricConfig.fromPartial({ ...option, name: this.name, type })
@@ -67,6 +74,28 @@ export class MetricState extends MapStateStorage<Metric> {
67
74
  }
68
75
  }
69
76
 
77
+ export class MetricStateNew extends MapStateStorage<Metric> {
78
+ static INSTANCE = new MetricState()
79
+
80
+ getOrRegisterMetric(type: MetricType, name: string, option?: CounterOptions | MetricOptions): Metric {
81
+ const metricMap = this.getOrRegister()
82
+ let metric = metricMap.get(name)
83
+ if (metric && metric.config.type !== type) {
84
+ throw Error(`redefine ${name} of metric type ${type} that is previously ${metric.config.type}`)
85
+ }
86
+
87
+ if (!metric) {
88
+ if (type === MetricType.COUNTER) {
89
+ metric = CounterNew._create(name, option)
90
+ } else {
91
+ metric = GaugeNew._create(name, option)
92
+ }
93
+ }
94
+ metricMap.set(name, metric)
95
+ return metric
96
+ }
97
+ }
98
+
70
99
  export class Counter extends Metric {
71
100
  static register(name: string, option?: CounterOptions): Counter {
72
101
  return MetricState.INSTANCE.getOrRegisterMetric(MetricType.COUNTER, name, option) as Counter
@@ -79,7 +108,7 @@ export class Counter extends Metric {
79
108
  return new Counter(name, option)
80
109
  }
81
110
 
82
- private constructor(name: string, option?: CounterOptions) {
111
+ protected constructor(name: string, option?: CounterOptions) {
83
112
  super(
84
113
  MetricType.COUNTER,
85
114
  name,
@@ -100,7 +129,7 @@ export class Counter extends Metric {
100
129
  this.record(ctx, value, labels, false)
101
130
  }
102
131
 
103
- private record(ctx: BaseContext, value: Numberish, labels: Labels, add: boolean) {
132
+ protected record(ctx: BaseContext, value: Numberish, labels: Labels, add: boolean) {
104
133
  processMetrics.process_metricrecord_count.add(1)
105
134
  ctx.update({
106
135
  counters: [
@@ -145,7 +174,7 @@ export class Gauge extends Metric {
145
174
  return new Gauge(name, option)
146
175
  }
147
176
 
148
- private constructor(name: string, option?: MetricOptions) {
177
+ protected constructor(name: string, option?: MetricOptions) {
149
178
  super(MetricType.GAUGE, name, MetricConfig.fromPartial({ ...option }))
150
179
  }
151
180
 
@@ -192,3 +221,89 @@ export class Meter {
192
221
  return new GaugeBinding(name, this.ctx)
193
222
  }
194
223
  }
224
+
225
+ export class MeterNew {
226
+ private readonly ctx: BaseContext
227
+
228
+ constructor(ctx: BaseContext) {
229
+ this.ctx = ctx
230
+ }
231
+
232
+ Counter(name: string, option?: CounterOptions): CounterNew {
233
+ return CounterNew.register(name, option)
234
+ }
235
+
236
+ Gauge(name: string, option?: MetricOptions): GaugeNew {
237
+ return GaugeNew.register(name, option)
238
+ }
239
+ }
240
+
241
+ export class CounterNew extends Counter {
242
+ static register(name: string, option?: CounterOptions): CounterNew {
243
+ return MetricStateNew.INSTANCE.getOrRegisterMetric(MetricType.COUNTER, name, option) as CounterNew
244
+ }
245
+
246
+ /**
247
+ * internal use only, to create a metric use {@link register} instead
248
+ */
249
+ static _create(name: string, option?: CounterOptions): CounterNew {
250
+ return new CounterNew(name, option)
251
+ }
252
+
253
+ private constructor(name: string, option?: CounterOptions) {
254
+ super(
255
+ name,
256
+ MetricConfig.fromPartial({
257
+ ...option,
258
+ aggregationConfig: {
259
+ intervalInMinutes: option?.resolutionConfig ? [option?.resolutionConfig?.intervalInMinutes] : []
260
+ }
261
+ })
262
+ )
263
+ }
264
+
265
+ protected record(ctx: BaseContext, value: Numberish, labels: Labels, add: boolean) {
266
+ processMetrics.process_metricrecord_count.add(1)
267
+ ctx.update({
268
+ timeseriesResult: [
269
+ {
270
+ metadata: ctx.getMetaData(this.name, labels),
271
+ type: TimeseriesResult_TimeseriesType.COUNTER,
272
+ data: toTimeSeriesData(value, labels, !add),
273
+ runtimeInfo: undefined
274
+ }
275
+ ]
276
+ })
277
+ }
278
+ }
279
+
280
+ export class GaugeNew extends Gauge {
281
+ static register(name: string, option?: MetricOptions): Gauge {
282
+ return MetricStateNew.INSTANCE.getOrRegisterMetric(MetricType.GAUGE, name, option) as Gauge
283
+ }
284
+
285
+ /**
286
+ * internal use only, to create a metric use {@link register} instead
287
+ */
288
+ static _create(name: string, option?: MetricOptions): GaugeNew {
289
+ return new GaugeNew(name, option)
290
+ }
291
+
292
+ private constructor(name: string, option?: MetricOptions) {
293
+ super(name, MetricConfig.fromPartial({ ...option }))
294
+ }
295
+
296
+ record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {
297
+ processMetrics.process_metricrecord_count.add(1)
298
+ ctx.update({
299
+ timeseriesResult: [
300
+ {
301
+ metadata: ctx.getMetaData(this.name, labels),
302
+ type: TimeseriesResult_TimeseriesType.GAUGE,
303
+ data: toTimeSeriesData(value, labels, false),
304
+ runtimeInfo: undefined
305
+ }
306
+ ]
307
+ })
308
+ }
309
+ }
@@ -1,4 +1,4 @@
1
- import { BigDecimalRichValue, BigInteger, MetricValue } from '@sentio/protos'
1
+ import { BigDecimalRichValue, BigInteger, MetricValue, RichStruct, RichValue_NullValue } from '@sentio/protos'
2
2
  import { BigDecimal } from './big-decimal.js'
3
3
 
4
4
  export type Numberish = number | bigint | BigDecimal | string
@@ -120,3 +120,36 @@ export function toBigDecimal(value: BigDecimal): BigDecimalRichValue {
120
120
  exp: exp
121
121
  }
122
122
  }
123
+
124
+ export function toTimeSeriesData(value: Numberish, labels: Record<string, string>, neg: boolean) {
125
+ const mv = toMetricValue(value)
126
+ const data: RichStruct = {
127
+ fields: {
128
+ value: {}
129
+ }
130
+ }
131
+
132
+ for (const key in labels) {
133
+ if (labels[key] == null) {
134
+ data.fields[key] = { nullValue: RichValue_NullValue.NULL_VALUE }
135
+ } else {
136
+ data.fields[key] = { stringValue: labels[key] }
137
+ }
138
+ }
139
+
140
+ if (mv.bigInteger != null) {
141
+ mv.bigInteger.negative = neg ? !mv.bigInteger.negative : mv.bigInteger.negative
142
+ data.fields.value.bigintValue = mv.bigInteger
143
+ } else if (mv.bigDecimal != null) {
144
+ let v = new BigDecimal(mv.bigDecimal)
145
+ if (neg) {
146
+ v = v.negated()
147
+ }
148
+ data.fields.value.bigdecimalValue = toBigDecimal(v)
149
+ } else if (mv.doubleValue != null) {
150
+ data.fields.value.floatValue = neg ? -mv.doubleValue : mv.doubleValue
151
+ } else {
152
+ data.fields.value.nullValue = RichValue_NullValue.NULL_VALUE
153
+ }
154
+ return data
155
+ }
@@ -13,7 +13,7 @@ import {
13
13
  PreprocessResult,
14
14
  ProcessResult
15
15
  } from '@sentio/protos'
16
- import { BindOptions } from './bind-options.js'
16
+ import { BindOptions, TimeOrBlock } from './bind-options.js'
17
17
  import { PromiseOrVoid } from '../core/promises.js'
18
18
  import { ServerError, Status } from 'nice-grpc'
19
19
  import {
@@ -75,8 +75,8 @@ class BindInternalOptions {
75
75
  address: string
76
76
  network: EthChainId
77
77
  name: string
78
- startBlock: bigint
79
- endBlock?: bigint
78
+ start: TimeOrBlock
79
+ end?: TimeOrBlock
80
80
  baseLabels?: { [key: string]: string }
81
81
  }
82
82
 
@@ -101,13 +101,20 @@ export class GlobalProcessor {
101
101
  address: ALL_ADDRESS,
102
102
  name: config.name || 'Global',
103
103
  network: config.network || EthChainId.ETHEREUM,
104
- startBlock: 0n
104
+ start: config.start || {
105
+ block: 0
106
+ },
107
+ end: config.end
105
108
  }
106
109
  if (config.startBlock) {
107
- this.config.startBlock = BigInt(config.startBlock)
110
+ this.config.start = {
111
+ block: config.startBlock
112
+ }
108
113
  }
109
114
  if (config.endBlock) {
110
- this.config.endBlock = BigInt(config.endBlock)
115
+ this.config.end = {
116
+ block: config.endBlock
117
+ }
111
118
  }
112
119
 
113
120
  return proxyProcessor(this)
@@ -390,14 +397,21 @@ export abstract class BaseProcessor<
390
397
  address: validateAndNormalizeAddress(config.address),
391
398
  name: config.name || '',
392
399
  network: config.network || EthChainId.ETHEREUM,
393
- startBlock: 0n,
400
+ start: config.start || {
401
+ block: 0
402
+ },
403
+ end: config.end,
394
404
  baseLabels: config.baseLabels
395
405
  }
396
406
  if (config.startBlock) {
397
- this.config.startBlock = BigInt(config.startBlock)
407
+ this.config.start = {
408
+ block: config.startBlock
409
+ }
398
410
  }
399
411
  if (config.endBlock) {
400
- this.config.endBlock = BigInt(config.endBlock)
412
+ this.config.end = {
413
+ block: config.endBlock
414
+ }
401
415
  }
402
416
 
403
417
  return proxyProcessor(this)
@@ -7,11 +7,18 @@ export class BindOptions {
7
7
  network?: EthChainId = EthChainId.ETHEREUM
8
8
  // Optional, override default contract name
9
9
  name?: string
10
+ start?: TimeOrBlock
11
+ end?: TimeOrBlock
10
12
  startBlock?: bigint | number
11
13
  endBlock?: bigint | number
12
14
  baseLabels?: { [key: string]: string }
13
15
  }
14
16
 
17
+ export interface TimeOrBlock {
18
+ block?: bigint | number
19
+ time?: Date
20
+ }
21
+
15
22
  export function getOptionsSignature(opts: BindOptions): string {
16
23
  const sig = [opts.address]
17
24
  if (opts.network) {
@@ -1,4 +1,12 @@
1
- import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR, GLOBAL_CONFIG } from '@sentio/runtime'
1
+ import {
2
+ errorString,
3
+ mergeProcessResults,
4
+ Plugin,
5
+ PluginManager,
6
+ USER_PROCESSOR,
7
+ GLOBAL_CONFIG,
8
+ getProvider
9
+ } from '@sentio/runtime'
2
10
  import {
3
11
  AccountConfig,
4
12
  ContractConfig,
@@ -26,6 +34,7 @@ import { validateAndNormalizeAddress } from './eth.js'
26
34
  import { EthChainId } from '@sentio/chain'
27
35
  import { EthContext } from './context.js'
28
36
  import { TemplateInstanceState } from '../core/template.js'
37
+ import { timeOrBlockToBlockNumber } from '@sentio/sdk/utils'
29
38
 
30
39
  interface Handlers {
31
40
  eventHandlers: ((event: Data_EthLog, preparedData?: PreparedData) => Promise<ProcessResult>)[]
@@ -79,6 +88,10 @@ export class EthPlugin extends Plugin {
79
88
  const chainId = processor.getChainId()
80
89
  // this.processorsByChainId.set(chainId, processor)
81
90
 
91
+ const provider = getProvider(chainId)
92
+ const startBlock = await timeOrBlockToBlockNumber(provider, processor.config.start)
93
+ const endBlock = processor.config.end ? await timeOrBlockToBlockNumber(provider, processor.config.end) : undefined
94
+
82
95
  const contractConfig = ContractConfig.fromPartial({
83
96
  processorType: USER_PROCESSOR,
84
97
  contract: {
@@ -87,8 +100,8 @@ export class EthPlugin extends Plugin {
87
100
  address: validateAndNormalizeAddress(processor.config.address),
88
101
  abi: ''
89
102
  },
90
- startBlock: processor.config.startBlock,
91
- endBlock: processor.config.endBlock
103
+ startBlock,
104
+ endBlock
92
105
  })
93
106
 
94
107
  // Step 1. Prepare all the block handlers
@@ -167,6 +180,10 @@ export class EthPlugin extends Plugin {
167
180
  for (const processor of GlobalProcessorState.INSTANCE.getValues()) {
168
181
  const chainId = processor.getChainId()
169
182
 
183
+ const provider = getProvider(chainId)
184
+ const startBlock = await timeOrBlockToBlockNumber(provider, processor.config.start)
185
+ const endBlock = processor.config.end ? await timeOrBlockToBlockNumber(provider, processor.config.end) : undefined
186
+
170
187
  const contractConfig = ContractConfig.fromPartial({
171
188
  processorType: USER_PROCESSOR,
172
189
  contract: {
@@ -175,8 +192,8 @@ export class EthPlugin extends Plugin {
175
192
  address: processor.config.address, // can only be *
176
193
  abi: ''
177
194
  },
178
- startBlock: processor.config.startBlock,
179
- endBlock: processor.config.endBlock
195
+ startBlock,
196
+ endBlock
180
197
  })
181
198
 
182
199
  for (const blockHandler of processor.blockHandlers) {
@@ -184,15 +184,7 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
184
184
  return ctx.stopAndGetResult()
185
185
  } catch (e) {
186
186
  console.error(e)
187
- return {
188
- gauges: [],
189
- counters: [],
190
- events: [],
191
- exports: [],
192
- states: {
193
- configUpdated: false
194
- }
195
- }
187
+ return ProcessResult.fromPartial({})
196
188
  }
197
189
  },
198
190
  fetchConfig: {
@@ -1,6 +1,6 @@
1
1
  import { Data_StarknetEvent, ProcessResult } from '@sentio/protos'
2
2
  import { StarknetChainId } from '@sentio/chain'
3
- import { CallData, constants, events, ParsedEvent, RpcProvider } from 'starknet'
3
+ import { CallData, events, ParsedEvent, RpcProvider } from 'starknet'
4
4
  import { StarknetContext } from './context.js'
5
5
  import { StarknetEvent } from './event.js'
6
6
  import { ListStateStorage, mergeProcessResults } from '@sentio/runtime'
@@ -83,15 +83,7 @@ export class StarknetProcessor {
83
83
  return mergeProcessResults(results)
84
84
  } catch (e) {
85
85
  console.error(e)
86
- return {
87
- gauges: [],
88
- counters: [],
89
- events: [],
90
- exports: [],
91
- states: {
92
- configUpdated: false
93
- }
94
- }
86
+ return ProcessResult.fromPartial({})
95
87
  }
96
88
  },
97
89
  eventFilter
@@ -110,9 +102,9 @@ export type CallHandler<T> = {
110
102
  function getRpcEndpoint(chainId: StarknetChainId | string) {
111
103
  switch (chainId) {
112
104
  case StarknetChainId.STARKNET_MAINNET:
113
- return constants.NetworkName.SN_MAIN
105
+ return 'https://starknet-mainnet.g.alchemy.com/starknet/version/rpc/v0_8/8sD5yitBslIYCPFzSq_Q1ObJHqPlZxFw'
114
106
  default:
115
- return constants.NetworkName.SN_SEPOLIA
107
+ return 'https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_8/8sD5yitBslIYCPFzSq_Q1ObJHqPlZxFw'
116
108
  }
117
109
  }
118
110