@sentio/sdk 1.20.2 → 1.21.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 (189) hide show
  1. package/lib/aptos/aptos-processor.d.ts +10 -10
  2. package/lib/aptos/aptos-processor.js +65 -13
  3. package/lib/aptos/aptos-processor.js.map +1 -1
  4. package/lib/aptos/bind-options.d.ts +0 -6
  5. package/lib/aptos/bind-options.js +1 -8
  6. package/lib/aptos/bind-options.js.map +1 -1
  7. package/lib/aptos/context.d.ts +5 -4
  8. package/lib/aptos/context.js +9 -6
  9. package/lib/aptos/context.js.map +1 -1
  10. package/lib/aptos/index.d.ts +3 -2
  11. package/lib/aptos/index.js +1 -2
  12. package/lib/aptos/index.js.map +1 -1
  13. package/lib/aptos/runtime.d.ts +2 -0
  14. package/lib/aptos/runtime.js +16 -0
  15. package/lib/aptos/runtime.js.map +1 -0
  16. package/lib/aptos/types.d.ts +28 -0
  17. package/lib/aptos/types.js +159 -0
  18. package/lib/aptos/types.js.map +1 -0
  19. package/lib/aptos/utils.d.ts +6 -0
  20. package/lib/aptos/utils.js +19 -0
  21. package/lib/aptos/utils.js.map +1 -0
  22. package/lib/aptos-codegen/codegen.d.ts +5 -2
  23. package/lib/aptos-codegen/codegen.js +194 -17
  24. package/lib/aptos-codegen/codegen.js.map +1 -1
  25. package/lib/aptos-codegen/typegen.d.ts +18 -0
  26. package/lib/aptos-codegen/typegen.js +196 -0
  27. package/lib/aptos-codegen/typegen.js.map +1 -0
  28. package/lib/binds.d.ts +2 -3
  29. package/lib/binds.js +6 -33
  30. package/lib/binds.js.map +1 -1
  31. package/lib/builtin/aptos/0x1.d.ts +1624 -0
  32. package/lib/builtin/aptos/0x1.js +2502 -0
  33. package/lib/builtin/aptos/0x1.js.map +1 -0
  34. package/lib/builtin/aptos/0x3.d.ts +414 -0
  35. package/lib/builtin/aptos/0x3.js +461 -0
  36. package/lib/builtin/aptos/0x3.js.map +1 -0
  37. package/lib/builtin/internal/eacaggregatorproxy_processor.d.ts +2 -2
  38. package/lib/builtin/internal/eacaggregatorproxy_processor.js +12 -11
  39. package/lib/builtin/internal/eacaggregatorproxy_processor.js.map +1 -1
  40. package/lib/builtin/internal/erc20_processor.d.ts +2 -2
  41. package/lib/builtin/internal/erc20_processor.js +12 -11
  42. package/lib/builtin/internal/erc20_processor.js.map +1 -1
  43. package/lib/builtin/internal/erc20bytes_processor.d.ts +2 -2
  44. package/lib/builtin/internal/erc20bytes_processor.js +12 -11
  45. package/lib/builtin/internal/erc20bytes_processor.js.map +1 -1
  46. package/lib/builtin/internal/weth9_processor.d.ts +2 -2
  47. package/lib/builtin/internal/weth9_processor.js +12 -11
  48. package/lib/builtin/internal/weth9_processor.js.map +1 -1
  49. package/lib/builtin/solana/types.d.ts +5 -5
  50. package/lib/builtin/solana/wormhole-processor.d.ts +6 -6
  51. package/lib/builtin/solana/wormhole-processor.js +15 -12
  52. package/lib/builtin/solana/wormhole-processor.js.map +1 -1
  53. package/lib/cli/build.js +17 -16
  54. package/lib/cli/build.js.map +1 -1
  55. package/lib/core/base-processor-template.d.ts +7 -7
  56. package/lib/core/base-processor-template.js.map +1 -1
  57. package/lib/core/base-processor.d.ts +5 -6
  58. package/lib/core/base-processor.js +6 -4
  59. package/lib/core/base-processor.js.map +1 -1
  60. package/lib/core/big-decimal.d.ts +1 -0
  61. package/lib/core/big-decimal.js +6 -0
  62. package/lib/core/big-decimal.js.map +1 -0
  63. package/lib/core/bind-options.d.ts +0 -2
  64. package/lib/core/bind-options.js +4 -4
  65. package/lib/core/bind-options.js.map +1 -1
  66. package/lib/core/context.d.ts +14 -11
  67. package/lib/core/context.js +28 -19
  68. package/lib/core/context.js.map +1 -1
  69. package/lib/core/generic-processor.js +5 -5
  70. package/lib/core/generic-processor.js.map +1 -1
  71. package/lib/core/index.d.ts +5 -5
  72. package/lib/core/index.js +6 -6
  73. package/lib/core/index.js.map +1 -1
  74. package/lib/core/logger.d.ts +2 -3
  75. package/lib/core/logger.js +6 -6
  76. package/lib/core/logger.js.map +1 -1
  77. package/lib/core/metadata.d.ts +7 -4
  78. package/lib/core/metadata.js +13 -10
  79. package/lib/core/metadata.js.map +1 -1
  80. package/lib/core/meter.d.ts +4 -7
  81. package/lib/core/meter.js +12 -13
  82. package/lib/core/meter.js.map +1 -1
  83. package/lib/core/solana-processor.d.ts +7 -4
  84. package/lib/core/solana-processor.js +14 -20
  85. package/lib/core/solana-processor.js.map +1 -1
  86. package/lib/core/sui-processor.d.ts +5 -4
  87. package/lib/core/sui-processor.js +10 -17
  88. package/lib/core/sui-processor.js.map +1 -1
  89. package/lib/error.d.ts +2 -2
  90. package/lib/error.js.map +1 -1
  91. package/lib/gen/processor/protos/processor.d.ts +23 -12
  92. package/lib/gen/processor/protos/processor.js +129 -57
  93. package/lib/gen/processor/protos/processor.js.map +1 -1
  94. package/lib/index.d.ts +1 -2
  95. package/lib/index.js +1 -4
  96. package/lib/index.js.map +1 -1
  97. package/lib/processor-state.d.ts +1 -1
  98. package/lib/processor-state.js.map +1 -1
  99. package/lib/service.js +13 -12
  100. package/lib/service.js.map +1 -1
  101. package/lib/target-ethers-sentio/codegen.js +14 -15
  102. package/lib/target-ethers-sentio/codegen.js.map +1 -1
  103. package/lib/test-abi-code-gen.js.map +1 -1
  104. package/lib/testing/metric-utils.js +2 -2
  105. package/lib/testing/metric-utils.js.map +1 -1
  106. package/lib/tests/aptos.test.js +95 -2
  107. package/lib/tests/aptos.test.js.map +1 -1
  108. package/lib/tests/erc20.js +1 -1
  109. package/lib/tests/erc20.js.map +1 -1
  110. package/lib/tests/erc20.test.js +3 -4
  111. package/lib/tests/erc20.test.js.map +1 -1
  112. package/lib/tests/solana.test.js +5 -1
  113. package/lib/tests/solana.test.js.map +1 -1
  114. package/lib/tests/souffl3.js +17 -4
  115. package/lib/tests/souffl3.js.map +1 -1
  116. package/lib/tests/sui.test.js +1 -4
  117. package/lib/tests/sui.test.js.map +1 -1
  118. package/lib/tests/types/aptos/souffle.d.ts +311 -22
  119. package/lib/tests/types/aptos/souffle.js +140 -4
  120. package/lib/tests/types/aptos/souffle.js.map +1 -1
  121. package/lib/tests/types/solana/basic_1_processor.d.ts +2 -2
  122. package/lib/tests/types/solana/basic_1_processor.js +4 -4
  123. package/lib/tests/types/solana/basic_1_processor.js.map +1 -1
  124. package/lib/tests/wormhole-token-bridge.js +2 -1
  125. package/lib/tests/wormhole-token-bridge.js.map +1 -1
  126. package/lib/utils/chain.d.ts +1 -0
  127. package/lib/utils/chain.js +15 -1
  128. package/lib/utils/chain.js.map +1 -1
  129. package/lib/utils/conversion.d.ts +1 -1
  130. package/lib/utils/conversion.js.map +1 -1
  131. package/package.json +3 -2
  132. package/src/abis/aptos/0x1.json +9205 -0
  133. package/src/abis/aptos/0x3.json +1515 -0
  134. package/src/aptos/aptos-processor.ts +79 -18
  135. package/src/aptos/bind-options.ts +0 -7
  136. package/src/aptos/context.ts +11 -8
  137. package/src/aptos/index.ts +3 -2
  138. package/src/aptos/runtime.ts +13 -0
  139. package/src/aptos/types.ts +203 -0
  140. package/src/aptos/utils.ts +18 -0
  141. package/src/aptos-codegen/codegen.ts +221 -18
  142. package/src/aptos-codegen/typegen.test.ts +29 -0
  143. package/src/aptos-codegen/typegen.ts +216 -0
  144. package/src/binds.ts +5 -39
  145. package/src/builtin/aptos/0x1.ts +3760 -0
  146. package/src/builtin/aptos/0x3.ts +798 -0
  147. package/src/builtin/internal/eacaggregatorproxy_processor.ts +14 -31
  148. package/src/builtin/internal/erc20_processor.ts +14 -25
  149. package/src/builtin/internal/erc20bytes_processor.ts +14 -25
  150. package/src/builtin/internal/weth9_processor.ts +14 -25
  151. package/src/builtin/solana/wormhole-processor.ts +21 -18
  152. package/src/cli/build.ts +19 -17
  153. package/src/core/base-processor-template.ts +7 -7
  154. package/src/core/base-processor.ts +30 -9
  155. package/src/core/big-decimal.ts +1 -0
  156. package/src/core/bind-options.ts +3 -2
  157. package/src/core/context.ts +40 -24
  158. package/src/core/generic-processor.ts +6 -7
  159. package/src/core/index.ts +5 -5
  160. package/src/core/logger.ts +7 -7
  161. package/src/core/metadata.ts +14 -12
  162. package/src/core/meter.ts +12 -14
  163. package/src/core/solana-processor.ts +24 -21
  164. package/src/core/sui-processor.ts +10 -21
  165. package/src/error.ts +2 -2
  166. package/src/gen/processor/protos/processor.ts +158 -68
  167. package/src/index.ts +1 -2
  168. package/src/processor-state.ts +1 -1
  169. package/src/service.ts +22 -15
  170. package/src/target-ethers-sentio/codegen.ts +14 -15
  171. package/src/test-abi-code-gen.ts +1 -0
  172. package/src/testing/metric-utils.ts +2 -2
  173. package/src/tests/aptos.test.ts +102 -3
  174. package/src/tests/erc20.test.ts +3 -4
  175. package/src/tests/erc20.ts +1 -1
  176. package/src/tests/solana.test.ts +5 -1
  177. package/src/tests/souffl3.ts +21 -6
  178. package/src/tests/sui.test.ts +1 -4
  179. package/src/tests/types/aptos/souffle.ts +422 -40
  180. package/src/tests/types/solana/basic_1_processor.ts +6 -6
  181. package/src/tests/wormhole-token-bridge.ts +2 -1
  182. package/src/types/global.d.ts +1 -1
  183. package/src/utils/chain.ts +14 -0
  184. package/src/utils/conversion.ts +1 -1
  185. package/lib/contract-namer.d.ts +0 -6
  186. package/lib/contract-namer.js +0 -20
  187. package/lib/contract-namer.js.map +0 -1
  188. package/src/aptos-codegen/codgen.test.ts +0 -11
  189. package/src/contract-namer.ts +0 -17
@@ -1,4 +1,4 @@
1
- import { CounterResult, GaugeResult, LogResult, MetricDescriptor, RecordMetaData } from '../gen'
1
+ import { CounterResult, GaugeResult, LogResult, DataDescriptor, RecordMetaData } from '../gen'
2
2
  import { BaseContract, EventFilter } from 'ethers'
3
3
  import { Block, Log } from '@ethersproject/abstract-provider'
4
4
  import { Meter, normalizeLabels } from './meter'
@@ -20,18 +20,19 @@ export abstract class BaseContext {
20
20
  this.logger = new Logger(this)
21
21
  }
22
22
 
23
- abstract getMetaData(descriptor: MetricDescriptor | undefined, labels: Labels): RecordMetaData
23
+ abstract getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData
24
24
  }
25
25
 
26
26
  export abstract class EthContext extends BaseContext {
27
27
  chainId: number
28
+ address: string
28
29
  log?: Log
29
30
  block?: Block
30
31
  trace?: Trace
31
32
  blockNumber: Long
32
33
  transactionHash?: string
33
34
 
34
- protected constructor(chainId: number, block?: Block, log?: Log, trace?: Trace) {
35
+ protected constructor(chainId: number, address: string, block?: Block, log?: Log, trace?: Trace) {
35
36
  super()
36
37
  this.chainId = chainId
37
38
  this.log = log
@@ -49,54 +50,64 @@ export abstract class EthContext extends BaseContext {
49
50
  }
50
51
  }
51
52
 
52
- export class Context<
53
+ export class ContractContext<
53
54
  TContract extends BaseContract,
54
55
  TContractBoundView extends BoundContractView<TContract, ContractView<TContract>>
55
56
  > extends EthContext {
56
57
  contract: TContractBoundView
57
- address: string
58
-
59
- constructor(view: TContractBoundView, chainId: number, block?: Block, log?: Log, trace?: Trace) {
60
- super(chainId, block, log, trace)
58
+ contractName: string
59
+
60
+ constructor(
61
+ contractName: string,
62
+ view: TContractBoundView,
63
+ chainId: number,
64
+ block?: Block,
65
+ log?: Log,
66
+ trace?: Trace
67
+ ) {
68
+ super(chainId, view.rawContract.address, block, log, trace)
61
69
  view.context = this
70
+ this.contractName = contractName
62
71
  this.contract = view
63
- this.address = view.rawContract.address
64
72
  }
65
73
 
66
- getMetaData(descriptor: MetricDescriptor | undefined, labels: Labels): RecordMetaData {
74
+ getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData {
67
75
  if (this.log) {
68
76
  return {
69
- contractAddress: this.contract.rawContract.address,
77
+ address: this.contract.rawContract.address,
78
+ contractName: this.contractName,
70
79
  blockNumber: this.blockNumber,
71
80
  transactionIndex: this.log.transactionIndex,
72
81
  transactionHash: this.transactionHash || '',
73
82
  logIndex: this.log.logIndex,
74
83
  chainId: this.chainId.toString(),
75
- descriptor: descriptor,
84
+ dataDescriptor: descriptor,
76
85
  labels: normalizeLabels(labels),
77
86
  }
78
87
  }
79
88
  if (this.block) {
80
89
  return {
81
- contractAddress: this.contract.rawContract.address,
90
+ address: this.contract.rawContract.address,
91
+ contractName: this.contractName,
82
92
  blockNumber: this.blockNumber,
83
93
  transactionIndex: -1,
84
94
  transactionHash: '',
85
95
  logIndex: -1,
86
96
  chainId: this.chainId.toString(),
87
- descriptor: descriptor,
97
+ dataDescriptor: descriptor,
88
98
  labels: normalizeLabels(labels),
89
99
  }
90
100
  }
91
101
  if (this.trace) {
92
102
  return {
93
- contractAddress: this.contract.rawContract.address,
103
+ address: this.contract.rawContract.address,
104
+ contractName: this.contractName,
94
105
  blockNumber: this.blockNumber,
95
106
  transactionIndex: this.trace.transactionPosition,
96
107
  transactionHash: this.transactionHash || '',
97
108
  logIndex: -1,
98
109
  chainId: this.chainId.toString(),
99
- descriptor: descriptor,
110
+ dataDescriptor: descriptor,
100
111
  labels: normalizeLabels(labels),
101
112
  }
102
113
  }
@@ -125,7 +136,7 @@ export class ContractView<TContract extends BaseContract> {
125
136
  export class BoundContractView<TContract extends BaseContract, TContractView extends ContractView<TContract>> {
126
137
  protected view: TContractView
127
138
  // context will be set right after context creation (in context's constructor)
128
- context: Context<TContract, BoundContractView<TContract, TContractView>>
139
+ context: ContractContext<TContract, BoundContractView<TContract, TContractView>>
129
140
 
130
141
  constructor(view: TContractView) {
131
142
  this.view = view
@@ -146,23 +157,26 @@ export class BoundContractView<TContract extends BaseContract, TContractView ext
146
157
 
147
158
  export class SolanaContext extends BaseContext {
148
159
  address: string
160
+ programName: string
149
161
  blockNumber: Long
150
162
 
151
- constructor(address: string, slot: Long) {
163
+ constructor(programName: string, address: string, slot: Long) {
152
164
  super()
165
+ this.programName = programName
153
166
  this.address = address
154
167
  this.blockNumber = slot
155
168
  }
156
169
 
157
- getMetaData(descriptor: MetricDescriptor | undefined, labels: Labels): RecordMetaData {
170
+ getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData {
158
171
  return {
159
- contractAddress: this.address,
172
+ address: this.address,
173
+ contractName: this.programName,
160
174
  blockNumber: this.blockNumber,
161
175
  transactionIndex: 0,
162
176
  transactionHash: '', // TODO add
163
177
  logIndex: 0,
164
178
  chainId: SOL_MAINMET_ID, // TODO set in context
165
- descriptor: descriptor,
179
+ dataDescriptor: descriptor,
166
180
  labels: normalizeLabels(labels),
167
181
  }
168
182
  }
@@ -170,6 +184,7 @@ export class SolanaContext extends BaseContext {
170
184
 
171
185
  export class SuiContext extends BaseContext {
172
186
  address: string
187
+ moduleName: string
173
188
  blockNumber: Long
174
189
 
175
190
  constructor(address: string, slot: Long) {
@@ -178,15 +193,16 @@ export class SuiContext extends BaseContext {
178
193
  this.blockNumber = slot
179
194
  }
180
195
 
181
- getMetaData(descriptor: MetricDescriptor | undefined, labels: Labels): RecordMetaData {
196
+ getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData {
182
197
  return {
183
- contractAddress: this.address,
198
+ address: this.address,
199
+ contractName: this.moduleName,
184
200
  blockNumber: this.blockNumber,
185
201
  transactionIndex: 0,
186
202
  transactionHash: '', // TODO
187
203
  logIndex: 0,
188
204
  chainId: SUI_DEVNET_ID, // TODO set in context
189
- descriptor: descriptor,
205
+ dataDescriptor: descriptor,
190
206
  labels: normalizeLabels(labels),
191
207
  }
192
208
  }
@@ -3,7 +3,7 @@ import { BoundContractView, ContractView } from './context'
3
3
  import { BindOptions } from './bind-options'
4
4
  import { BaseProcessor } from './base-processor'
5
5
  import { getProvider } from '../provider'
6
- import { addProcessor, getContractName } from '../binds'
6
+ import { addProcessor } from '../binds'
7
7
 
8
8
  export class GenericProcessor extends BaseProcessor<
9
9
  BaseContract,
@@ -21,15 +21,14 @@ export class GenericProcessor extends BaseProcessor<
21
21
  }
22
22
 
23
23
  public static bind(eventABI: string[] | string, options: BindOptions): GenericProcessor {
24
- const AbiName = 'Generic'
25
24
  if (!Array.isArray(eventABI)) {
26
25
  eventABI = [eventABI]
27
26
  }
28
-
29
- const finalOptions = Object.assign({}, options)
30
- finalOptions.name = getContractName(AbiName, options.name, options.address, options.network)
31
- const processor = new GenericProcessor(eventABI, finalOptions)
32
- addProcessor(AbiName, options, processor)
27
+ if (!options.name) {
28
+ options.name = 'Generic'
29
+ }
30
+ const processor = new GenericProcessor(eventABI, options)
31
+ addProcessor(options, processor)
33
32
  return processor
34
33
  }
35
34
  }
package/src/core/index.ts CHANGED
@@ -1,15 +1,15 @@
1
- export { BigNumber as BigDecimal } from 'bignumber.js'
2
- export { Context, ContractView, BoundContractView, SolanaContext } from './context'
3
- export { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOption } from './meter'
1
+ export { BigDecimal } from './big-decimal'
2
+ export { ContractContext, ContractView, BoundContractView, SolanaContext } from './context'
3
+ export { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOptions } from './meter'
4
4
  export { type Numberish, toBigInteger, toMetricValue } from './numberish'
5
5
 
6
- export { BindOptions, SolanaBindOptions, SuiBindOptions } from './bind-options'
6
+ export { BindOptions, SolanaBindOptions } from './bind-options'
7
7
 
8
8
  export { BaseProcessor } from './base-processor'
9
9
  export { GenericProcessor } from './generic-processor'
10
10
  export { BaseProcessorTemplate } from './base-processor-template'
11
11
  export { SolanaBaseProcessor } from './solana-processor'
12
- export { SuiBaseProcessor } from './sui-processor'
12
+ export { SuiBaseProcessor, SuiBindOptions } from './sui-processor'
13
13
  // export * from '../aptos'
14
14
 
15
15
  export type { TypedCallTrace, Trace } from './trace'
@@ -1,16 +1,15 @@
1
1
  import { BaseContext } from './context'
2
- import { Labels, GetRecordMetaData } from './metadata'
3
- import { LogLevel } from '../gen'
2
+ import { DataDescriptor, LogLevel } from '../gen'
3
+ import { DescriptorWithUsage, Labels } from './metadata'
4
4
 
5
5
  export type Attributes = Record<string, any>
6
6
 
7
- export class Logger {
7
+ export class Logger extends DescriptorWithUsage {
8
8
  private readonly ctx: BaseContext
9
- private readonly name: string
10
9
 
11
10
  constructor(ctx: BaseContext, name = '') {
11
+ super(DataDescriptor.fromPartial({ name }))
12
12
  this.ctx = ctx
13
- this.name = name
14
13
  }
15
14
 
16
15
  withName(name: string) {
@@ -22,9 +21,10 @@ export class Logger {
22
21
  message = message.toString()
23
22
  }
24
23
 
24
+ this.usage++
25
25
  this.ctx.logs.push({
26
- name: this.name,
27
- metadata: GetRecordMetaData(this.ctx, undefined, {}),
26
+ // name: this.name,
27
+ metadata: this.ctx.getMetaData(this.getShortDescriptor(), {}), // GetRecordMetaData(this.ctx, this, {}),
28
28
  level,
29
29
  message,
30
30
  attributes: JSON.stringify(attributes),
@@ -1,20 +1,22 @@
1
- import { BaseContext } from './context'
2
- import { MetricDescriptor, RecordMetaData } from '../gen'
3
- import { Metric, normalizeName } from './meter'
1
+ import { DataDescriptor } from '../gen'
2
+ import { normalizeName } from './meter'
4
3
 
5
4
  export type Labels = { [key: string]: string }
6
5
 
7
- export function GetRecordMetaData(ctx: BaseContext, metric: Metric | undefined, labels: Labels): RecordMetaData {
8
- let descriptor = undefined
9
- if (metric) {
10
- descriptor = metric.descriptor
11
- if (metric.usage > 0) {
6
+ export class DescriptorWithUsage {
7
+ descriptor: DataDescriptor
8
+ usage = 0
9
+ constructor(descriptor: DataDescriptor) {
10
+ this.descriptor = descriptor
11
+ this.descriptor.name = normalizeName(descriptor.name)
12
+ }
13
+
14
+ getShortDescriptor(): DataDescriptor {
15
+ if (this.usage > 0) {
12
16
  // Other setting don't need to be write multiple times
13
- descriptor = MetricDescriptor.fromPartial({ name: descriptor.name })
17
+ return DataDescriptor.fromPartial({ name: this.descriptor.name })
14
18
  }
15
19
 
16
- descriptor.name = normalizeName(descriptor.name)
20
+ return this.descriptor
17
21
  }
18
-
19
- return ctx.getMetaData(descriptor, labels)
20
22
  }
package/src/core/meter.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { MetricDescriptor } from '../gen'
2
1
  import { BaseContext } from './context'
3
2
  import { toMetricValue, Numberish } from './numberish'
4
- import { GetRecordMetaData, Labels } from './metadata'
3
+ import { DescriptorWithUsage, Labels } from './metadata'
4
+ import { DataDescriptor } from '../gen'
5
5
 
6
6
  export function normalizeName(name: string): string {
7
7
  const regex = new RegExp('![_.a-zA-Z0-9]')
@@ -27,29 +27,27 @@ export function normalizeLabels(labels: Labels): Labels {
27
27
  return normLabels
28
28
  }
29
29
 
30
- export class MetricDescriptorOption {
30
+ export class MetricDescriptorOptions {
31
31
  unit?: string
32
32
  description?: string
33
33
  sparse?: boolean
34
34
  }
35
35
 
36
- export class Metric {
37
- descriptor: MetricDescriptor = MetricDescriptor.fromPartial({})
38
- usage = 0
39
-
40
- constructor(name: string, option?: MetricDescriptorOption) {
41
- this.descriptor.name = name
36
+ export class Metric extends DescriptorWithUsage {
37
+ constructor(name: string, option?: MetricDescriptorOptions) {
38
+ const descriptor = DataDescriptor.fromPartial({ name })
42
39
  if (option) {
43
40
  if (option.unit) {
44
- this.descriptor.unit = option.unit
41
+ descriptor.unit = option.unit
45
42
  }
46
43
  if (option.description) {
47
- this.descriptor.description = option.description
44
+ descriptor.description = option.description
48
45
  }
49
46
  if (option.sparse) {
50
- this.descriptor.sparse = option.sparse
47
+ descriptor.sparse = option.sparse
51
48
  }
52
49
  }
50
+ super(descriptor)
53
51
  }
54
52
  }
55
53
 
@@ -64,7 +62,7 @@ export class Counter extends Metric {
64
62
 
65
63
  private record(ctx: BaseContext, value: Numberish, labels: Labels, add: boolean) {
66
64
  ctx.counters.push({
67
- metadata: GetRecordMetaData(ctx, this, labels),
65
+ metadata: ctx.getMetaData(this.getShortDescriptor(), labels),
68
66
  metricValue: toMetricValue(value),
69
67
  add: add,
70
68
  runtimeInfo: undefined,
@@ -94,7 +92,7 @@ export class CounterBinding {
94
92
  export class Gauge extends Metric {
95
93
  record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {
96
94
  ctx.gauges.push({
97
- metadata: GetRecordMetaData(ctx, this, labels),
95
+ metadata: ctx.getMetaData(this.getShortDescriptor(), labels),
98
96
  metricValue: toMetricValue(value),
99
97
  runtimeInfo: undefined,
100
98
  })
@@ -9,8 +9,10 @@ type IndexConfigure = {
9
9
  endSlot?: Long
10
10
  }
11
11
 
12
+ export type SolanaInstructionHandler = (instruction: Instruction, ctx: SolanaContext, accounts?: string[]) => void
13
+
12
14
  export class SolanaBaseProcessor {
13
- public instructionHanlderMap: Map<string, (instruction: Instruction, ctx: SolanaContext) => void> = new Map()
15
+ public instructionHandlerMap: Map<string, SolanaInstructionHandler> = new Map()
14
16
  address: string
15
17
  endpoint: string
16
18
  contractName: string
@@ -44,39 +46,40 @@ export class SolanaBaseProcessor {
44
46
  return this
45
47
  }
46
48
 
47
- public onInstruction(instructionName: string, handler: (instruction: Instruction, ctx: SolanaContext) => void) {
49
+ public onInstruction(instructionName: string, handler: SolanaInstructionHandler) {
48
50
  if (!this.isBind()) {
49
51
  throw new Error("Processor doesn't bind to an address")
50
52
  }
51
53
 
52
- this.instructionHanlderMap.set(instructionName, handler)
54
+ this.instructionHandlerMap.set(instructionName, handler)
53
55
 
54
56
  return this
55
57
  }
56
58
 
57
- public handleInstruction(ins: string | { type: string; info: any }, slot: Long): ProcessResult | null {
58
- const ctx = new SolanaContext(this.address, slot)
59
- let parsedInstruction: Instruction | null = null
60
-
59
+ public getParsedInstruction(ins: string | { type: string; info: any }): Instruction | null {
61
60
  if (ins) {
62
61
  if ((ins as { type: string; info: any }).info) {
63
- if (this.fromParsedInstruction == null) {
64
- return null
65
- }
66
- parsedInstruction = this.fromParsedInstruction(ins as { type: string; info: any })
67
- } else {
68
- if (this.decodeInstruction == null) {
69
- return null
70
- }
71
- parsedInstruction = this.decodeInstruction(ins as string)
62
+ return this.fromParsedInstruction ? this.fromParsedInstruction(ins as { type: string; info: any }) : null
72
63
  }
73
- if (parsedInstruction) {
74
- const handler = this.instructionHanlderMap.get(parsedInstruction.name)
75
- if (handler) {
76
- handler(parsedInstruction, ctx)
77
- }
64
+ if (this.decodeInstruction != null) {
65
+ return this.decodeInstruction(ins as string)
78
66
  }
79
67
  }
68
+ return null
69
+ }
70
+
71
+ public getInstructionHandler(parsedInstruction: Instruction): SolanaInstructionHandler | undefined {
72
+ return this.instructionHandlerMap.get(parsedInstruction.name)
73
+ }
74
+
75
+ public handleInstruction(
76
+ parsedInstruction: Instruction,
77
+ accounts: string[],
78
+ handler: SolanaInstructionHandler,
79
+ slot: Long
80
+ ): ProcessResult {
81
+ const ctx = new SolanaContext(this.contractName, this.address, slot)
82
+ handler(parsedInstruction, ctx, accounts)
80
83
  return {
81
84
  gauges: ctx.gauges,
82
85
  counters: ctx.counters,
@@ -1,4 +1,3 @@
1
- import { SuiBindOptions } from './bind-options'
2
1
  import { SuiContext } from './context'
3
2
  import { ProcessResult } from '../gen'
4
3
  import Long from 'long'
@@ -8,35 +7,29 @@ type IndexConfigure = {
8
7
  endSeqNumber?: Long
9
8
  }
10
9
 
10
+ export class SuiBindOptions {
11
+ address: string
12
+ // network?: Networkish = 1
13
+ // name?: string
14
+ startBlock?: Long | number
15
+ // endBlock?: Long | number
16
+ }
17
+
11
18
  export class SuiBaseProcessor {
12
19
  public transactionHanlder: (transaction: any, ctx: SuiContext) => void
13
20
  address: string
14
21
  config: IndexConfigure = { startSeqNumber: new Long(0) }
15
22
 
16
- constructor(options: SuiBindOptions) {
17
- if (options) {
18
- this.bind(options)
19
- }
20
- global.PROCESSOR_STATE.suiProcessors.push(this)
21
- }
22
-
23
- bind(options: SuiBindOptions) {
23
+ constructor(name: string, options: SuiBindOptions) {
24
24
  this.address = options.address
25
25
  if (options.startBlock) {
26
26
  this.startSlot(options.startBlock)
27
27
  }
28
- if (options.endBlock) {
29
- this.endBlock(options.endBlock)
30
- }
28
+ global.PROCESSOR_STATE.suiProcessors.push(this)
31
29
  }
32
30
 
33
31
  public onTransaction(handler: (transaction: any, ctx: SuiContext) => void) {
34
- if (!this.isBind()) {
35
- throw new Error("Processor doesn't bind to an address")
36
- }
37
-
38
32
  this.transactionHanlder = handler
39
-
40
33
  return this
41
34
  }
42
35
 
@@ -53,10 +46,6 @@ export class SuiBaseProcessor {
53
46
  }
54
47
  }
55
48
 
56
- public isBind() {
57
- return this.address !== null
58
- }
59
-
60
49
  public startSlot(startSlot: Long | number) {
61
50
  if (typeof startSlot === 'number') {
62
51
  startSlot = Long.fromNumber(startSlot)
package/src/error.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // Transform error in more readable format
2
- import { Context } from './core/context'
2
+ import { ContractContext } from './core/context'
3
3
  import { errors } from 'ethers'
4
4
 
5
5
  export class EthersError extends Error {
@@ -15,7 +15,7 @@ export class EthersError extends Error {
15
15
  }
16
16
  }
17
17
 
18
- export function transformEtherError(e: Error, ctx: Context<any, any> | undefined): Error {
18
+ export function transformEtherError(e: Error, ctx: ContractContext<any, any> | undefined): Error {
19
19
  let msg = ''
20
20
  // @ts-ignore expected error fields
21
21
  if (e.code === errors.CALL_EXCEPTION) {