@sentio/sdk 2.60.0-rc.1 → 2.60.0-rc.10

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 (190) hide show
  1. package/lib/aptos/aptos-processor.d.ts +1 -0
  2. package/lib/aptos/aptos-processor.d.ts.map +1 -1
  3. package/lib/aptos/aptos-processor.js +11 -3
  4. package/lib/aptos/aptos-processor.js.map +1 -1
  5. package/lib/aptos/builtin/0x1.d.ts +211 -0
  6. package/lib/aptos/builtin/0x1.d.ts.map +1 -1
  7. package/lib/aptos/builtin/0x1.js +328 -1
  8. package/lib/aptos/builtin/0x1.js.map +1 -1
  9. package/lib/aptos/builtin/0x3.js +1 -1
  10. package/lib/aptos/builtin/0x3.js.map +1 -1
  11. package/lib/aptos/builtin/0x4.js +1 -1
  12. package/lib/aptos/builtin/0x4.js.map +1 -1
  13. package/lib/core/core-plugin.d.ts +1 -0
  14. package/lib/core/core-plugin.d.ts.map +1 -1
  15. package/lib/core/core-plugin.js +6 -2
  16. package/lib/core/core-plugin.js.map +1 -1
  17. package/lib/core/handler-options.d.ts +6 -0
  18. package/lib/core/handler-options.d.ts.map +1 -1
  19. package/lib/core/handler-options.js.map +1 -1
  20. package/lib/eth/base-processor.d.ts +3 -1
  21. package/lib/eth/base-processor.d.ts.map +1 -1
  22. package/lib/eth/base-processor.js +26 -0
  23. package/lib/eth/base-processor.js.map +1 -1
  24. package/lib/eth/eth-plugin.d.ts.map +1 -1
  25. package/lib/eth/eth-plugin.js +45 -3
  26. package/lib/eth/eth-plugin.js.map +1 -1
  27. package/lib/eth/eth.d.ts.map +1 -1
  28. package/lib/eth/eth.js +30 -24
  29. package/lib/eth/eth.js.map +1 -1
  30. package/lib/iota/builtin/0x1.d.ts +817 -0
  31. package/lib/iota/builtin/0x1.d.ts.map +1 -0
  32. package/lib/iota/builtin/0x1.js +4385 -0
  33. package/lib/iota/builtin/0x1.js.map +1 -0
  34. package/lib/iota/builtin/0x2.d.ts +4529 -0
  35. package/lib/iota/builtin/0x2.d.ts.map +1 -0
  36. package/lib/iota/builtin/0x2.js +17109 -0
  37. package/lib/iota/builtin/0x2.js.map +1 -0
  38. package/lib/iota/builtin/0x3.d.ts +2293 -0
  39. package/lib/iota/builtin/0x3.d.ts.map +1 -0
  40. package/lib/iota/builtin/0x3.js +6522 -0
  41. package/lib/iota/builtin/0x3.js.map +1 -0
  42. package/lib/iota/builtin/index.d.ts +4 -0
  43. package/lib/iota/builtin/index.d.ts.map +1 -0
  44. package/lib/iota/builtin/index.js +7 -0
  45. package/lib/iota/builtin/index.js.map +1 -0
  46. package/lib/iota/codegen/codegen.d.ts +2 -0
  47. package/lib/iota/codegen/codegen.d.ts.map +1 -0
  48. package/lib/iota/codegen/codegen.js +94 -0
  49. package/lib/iota/codegen/codegen.js.map +1 -0
  50. package/lib/iota/codegen/index.d.ts +2 -0
  51. package/lib/iota/codegen/index.d.ts.map +1 -0
  52. package/lib/iota/codegen/index.js +2 -0
  53. package/lib/iota/codegen/index.js.map +1 -0
  54. package/lib/iota/codegen/run.d.ts +2 -0
  55. package/lib/iota/codegen/run.d.ts.map +1 -0
  56. package/lib/iota/codegen/run.js +12 -0
  57. package/lib/iota/codegen/run.js.map +1 -0
  58. package/lib/iota/context.d.ts +50 -0
  59. package/lib/iota/context.d.ts.map +1 -0
  60. package/lib/iota/context.js +134 -0
  61. package/lib/iota/context.js.map +1 -0
  62. package/lib/iota/ext/coin.d.ts +17 -0
  63. package/lib/iota/ext/coin.d.ts.map +1 -0
  64. package/lib/iota/ext/coin.js +532 -0
  65. package/lib/iota/ext/coin.js.map +1 -0
  66. package/lib/iota/ext/index.d.ts +3 -0
  67. package/lib/iota/ext/index.d.ts.map +1 -0
  68. package/lib/iota/ext/index.js +3 -0
  69. package/lib/iota/ext/index.js.map +1 -0
  70. package/lib/iota/ext/move-dex.d.ts +19 -0
  71. package/lib/iota/ext/move-dex.d.ts.map +1 -0
  72. package/lib/iota/ext/move-dex.js +24 -0
  73. package/lib/iota/ext/move-dex.js.map +1 -0
  74. package/lib/iota/index.d.ts +11 -0
  75. package/lib/iota/index.d.ts.map +1 -0
  76. package/lib/iota/index.js +12 -0
  77. package/lib/iota/index.js.map +1 -0
  78. package/lib/iota/iota-object-processor-template.d.ts +44 -0
  79. package/lib/iota/iota-object-processor-template.d.ts.map +1 -0
  80. package/lib/iota/iota-object-processor-template.js +171 -0
  81. package/lib/iota/iota-object-processor-template.js.map +1 -0
  82. package/lib/iota/iota-object-processor.d.ts +83 -0
  83. package/lib/iota/iota-object-processor.d.ts.map +1 -0
  84. package/lib/iota/iota-object-processor.js +193 -0
  85. package/lib/iota/iota-object-processor.js.map +1 -0
  86. package/lib/iota/iota-plugin-part.d.ts +12 -0
  87. package/lib/iota/iota-plugin-part.d.ts.map +1 -0
  88. package/lib/iota/iota-plugin-part.js +178 -0
  89. package/lib/iota/iota-plugin-part.js.map +1 -0
  90. package/lib/iota/iota-plugin.d.ts +3 -0
  91. package/lib/iota/iota-plugin.d.ts.map +1 -0
  92. package/lib/iota/iota-plugin.js +4 -0
  93. package/lib/iota/iota-plugin.js.map +1 -0
  94. package/lib/iota/iota-processor.d.ts +47 -0
  95. package/lib/iota/iota-processor.d.ts.map +1 -0
  96. package/lib/iota/iota-processor.js +223 -0
  97. package/lib/iota/iota-processor.js.map +1 -0
  98. package/lib/iota/models.d.ts +12 -0
  99. package/lib/iota/models.d.ts.map +1 -0
  100. package/lib/iota/models.js +2 -0
  101. package/lib/iota/models.js.map +1 -0
  102. package/lib/iota/move-coder.d.ts +4 -0
  103. package/lib/iota/move-coder.d.ts.map +1 -0
  104. package/lib/iota/move-coder.js +12 -0
  105. package/lib/iota/move-coder.js.map +1 -0
  106. package/lib/iota/network.d.ts +10 -0
  107. package/lib/iota/network.d.ts.map +1 -0
  108. package/lib/iota/network.js +24 -0
  109. package/lib/iota/network.js.map +1 -0
  110. package/lib/iota/utils.d.ts +3 -0
  111. package/lib/iota/utils.d.ts.map +1 -0
  112. package/lib/iota/utils.js +41 -0
  113. package/lib/iota/utils.js.map +1 -0
  114. package/lib/store/schema.d.ts.map +1 -1
  115. package/lib/store/schema.js +1 -0
  116. package/lib/store/schema.js.map +1 -1
  117. package/lib/sui/builtin/0x2.d.ts +73 -0
  118. package/lib/sui/builtin/0x2.d.ts.map +1 -1
  119. package/lib/sui/builtin/0x2.js +237 -1
  120. package/lib/sui/builtin/0x2.js.map +1 -1
  121. package/lib/sui/builtin/0x3.d.ts +2 -0
  122. package/lib/sui/builtin/0x3.d.ts.map +1 -1
  123. package/lib/sui/builtin/0x3.js +21 -1
  124. package/lib/sui/builtin/0x3.js.map +1 -1
  125. package/lib/sui/network.d.ts.map +1 -1
  126. package/lib/sui/network.js +0 -3
  127. package/lib/sui/network.js.map +1 -1
  128. package/lib/sui/sui-plugin-part.d.ts +12 -0
  129. package/lib/sui/sui-plugin-part.d.ts.map +1 -0
  130. package/lib/sui/sui-plugin-part.js +178 -0
  131. package/lib/sui/sui-plugin-part.js.map +1 -0
  132. package/lib/sui/sui-plugin.d.ts +4 -0
  133. package/lib/sui/sui-plugin.d.ts.map +1 -1
  134. package/lib/sui/sui-plugin.js +12 -159
  135. package/lib/sui/sui-plugin.js.map +1 -1
  136. package/lib/testing/iota-facet.d.ts +14 -0
  137. package/lib/testing/iota-facet.d.ts.map +1 -0
  138. package/lib/testing/iota-facet.js +124 -0
  139. package/lib/testing/iota-facet.js.map +1 -0
  140. package/lib/testing/test-processor-server.d.ts +2 -0
  141. package/lib/testing/test-processor-server.d.ts.map +1 -1
  142. package/lib/testing/test-processor-server.js +3 -0
  143. package/lib/testing/test-processor-server.js.map +1 -1
  144. package/package.json +21 -9
  145. package/src/aptos/abis/0x1.json +1040 -45
  146. package/src/aptos/abis/0x3.json +2 -2
  147. package/src/aptos/abis/0x4.json +17 -17
  148. package/src/aptos/aptos-processor.ts +15 -3
  149. package/src/aptos/builtin/0x1.ts +615 -1
  150. package/src/aptos/builtin/0x3.ts +1 -1
  151. package/src/aptos/builtin/0x4.ts +1 -1
  152. package/src/core/core-plugin.ts +8 -3
  153. package/src/core/handler-options.ts +7 -0
  154. package/src/eth/base-processor.ts +43 -1
  155. package/src/eth/eth-plugin.ts +49 -3
  156. package/src/eth/eth.ts +31 -26
  157. package/src/iota/abis/0x1.json +4213 -0
  158. package/src/iota/abis/0x2.json +26692 -0
  159. package/src/iota/abis/0x3.json +10598 -0
  160. package/src/iota/builtin/0x1.ts +6292 -0
  161. package/src/iota/builtin/0x2.ts +26198 -0
  162. package/src/iota/builtin/0x3.ts +11144 -0
  163. package/src/iota/builtin/index.ts +6 -0
  164. package/src/iota/codegen/codegen.ts +118 -0
  165. package/src/iota/codegen/index.ts +1 -0
  166. package/src/iota/codegen/run.ts +13 -0
  167. package/src/iota/context.ts +200 -0
  168. package/src/iota/ext/coin.ts +565 -0
  169. package/src/iota/ext/index.ts +2 -0
  170. package/src/iota/ext/move-dex.ts +52 -0
  171. package/src/iota/index.ts +29 -0
  172. package/src/iota/iota-object-processor-template.ts +277 -0
  173. package/src/iota/iota-object-processor.ts +386 -0
  174. package/src/iota/iota-plugin-part.ts +211 -0
  175. package/src/iota/iota-plugin.ts +2 -0
  176. package/src/iota/iota-processor.ts +339 -0
  177. package/src/iota/models.ts +14 -0
  178. package/src/iota/move-coder.ts +15 -0
  179. package/src/iota/network.ts +27 -0
  180. package/src/iota/utils.ts +52 -0
  181. package/src/store/schema.ts +1 -0
  182. package/src/sui/abis/0x2.json +269 -0
  183. package/src/sui/abis/0x3.json +29 -0
  184. package/src/sui/builtin/0x2.ts +367 -1
  185. package/src/sui/builtin/0x3.ts +29 -1
  186. package/src/sui/network.ts +0 -3
  187. package/src/sui/sui-plugin-part.ts +211 -0
  188. package/src/sui/sui-plugin.ts +12 -178
  189. package/src/testing/iota-facet.ts +143 -0
  190. package/src/testing/test-processor-server.ts +3 -0
@@ -1,4 +1,4 @@
1
- import { BaseContract, DeferredTopicFilter, LogDescription, TransactionResponseParams } from 'ethers'
1
+ import { BaseContract, DeferredTopicFilter, LogDescription, LogParams, TransactionResponseParams } from 'ethers'
2
2
 
3
3
  import { BoundContractView, ContractContext, ContractView, GlobalContext } from './context.js'
4
4
  import {
@@ -93,6 +93,7 @@ export class GlobalProcessor {
93
93
  blockHandlers: BlockHandler[] = proxyHandlers([])
94
94
  transactionHandler: TransactionHandler[] = proxyHandlers([])
95
95
  traceHandlers: TraceHandler[] = proxyHandlers([])
96
+ eventHandlers: EventsHandler[] = []
96
97
 
97
98
  static bind(config: Omit<BindOptions, 'address'>): GlobalProcessor {
98
99
  const processor = new GlobalProcessor(config)
@@ -333,6 +334,47 @@ export class GlobalProcessor {
333
334
  return this
334
335
  }
335
336
 
337
+ public onEvent(
338
+ handler: (rawLog: LogParams, ctx: GlobalContext) => PromiseOrVoid,
339
+ filter?: AddressOrTypeEventFilter | AddressOrTypeEventFilter[],
340
+ handlerOptions?: HandlerOptions<EthFetchConfig, TypedEvent>
341
+ ): this {
342
+ let _filters: AddressOrTypeEventFilter[] = []
343
+
344
+ if (Array.isArray(filter)) {
345
+ _filters = filter
346
+ } else if (filter) {
347
+ _filters.push(filter)
348
+ }
349
+ const chainId = this.getChainId()
350
+
351
+ this.eventHandlers.push({
352
+ filters: _filters,
353
+ fetchConfig: EthFetchConfig.fromPartial(handlerOptions || {}),
354
+ handlerName: getHandlerName(),
355
+ handler: async function (data) {
356
+ const { log, block, transaction, transactionReceipt } = formatEthData(data)
357
+ if (!log) {
358
+ throw new ServerError(Status.INVALID_ARGUMENT, 'Log is empty')
359
+ }
360
+ const ctx = new GlobalContext(
361
+ chainId,
362
+ transaction?.to || '*',
363
+ data.timestamp,
364
+ block,
365
+ log,
366
+ undefined,
367
+ transaction,
368
+ transactionReceipt
369
+ )
370
+
371
+ await handler(log, ctx)
372
+ return ctx.stopAndGetResult()
373
+ }
374
+ })
375
+ return this
376
+ }
377
+
336
378
  public onTrace(
337
379
  signatures: string | string[],
338
380
  handler: (trace: Trace, ctx: GlobalContext) => PromiseOrVoid,
@@ -212,6 +212,53 @@ export class EthPlugin extends Plugin {
212
212
  })
213
213
  }
214
214
  }
215
+
216
+ for (const eventsHandler of processor.eventHandlers) {
217
+ // associate id with filter
218
+ const handlerId = this.handlerRegister.register(eventsHandler.handler, processor.getChainId())
219
+ const logConfig: LogHandlerConfig = {
220
+ handlerId: handlerId,
221
+ handlerName: eventsHandler.handlerName,
222
+ filters: [],
223
+ fetchConfig: eventsHandler.fetchConfig
224
+ }
225
+
226
+ if (!eventsHandler.filters || eventsHandler.filters.length === 0) {
227
+ // if no filter, then we assume all logs
228
+ logConfig.filters.push({
229
+ topics: []
230
+ })
231
+ } else {
232
+ for (const filter of eventsHandler.filters) {
233
+ const topics = await filter.getTopicFilter()
234
+ // if (!filter.topics) {
235
+ // throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')
236
+ // }
237
+ let address = undefined
238
+ if (filter.address) {
239
+ address = filter.address.toString()
240
+ }
241
+ const logFilter: LogFilter = {
242
+ addressType: filter.addressType,
243
+ address: address && validateAndNormalizeAddress(address),
244
+ topics: []
245
+ }
246
+
247
+ for (const ts of topics) {
248
+ let hashes: string[] = []
249
+ if (Array.isArray(ts)) {
250
+ hashes = hashes.concat(ts)
251
+ } else if (ts) {
252
+ hashes.push(ts)
253
+ }
254
+ logFilter.topics.push({ hashes: hashes })
255
+ }
256
+ logConfig.filters.push(logFilter)
257
+ }
258
+ }
259
+ contractConfig.logConfigs.push(logConfig)
260
+ }
261
+
215
262
  config.contractConfigs.push(contractConfig)
216
263
  }
217
264
 
@@ -238,9 +285,7 @@ export class EthPlugin extends Plugin {
238
285
 
239
286
  for (const filter of eventsHandler.filters) {
240
287
  const topics = await filter.getTopicFilter()
241
- // if (!filter.topics) {
242
- // throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')
243
- // }
288
+
244
289
  let address = undefined
245
290
  if (filter.address) {
246
291
  address = filter.address.toString()
@@ -262,6 +307,7 @@ export class EthPlugin extends Plugin {
262
307
  }
263
308
  logConfig.filters.push(logFilter)
264
309
  }
310
+
265
311
  accountConfig.logConfigs.push(logConfig)
266
312
  }
267
313
 
package/src/eth/eth.ts CHANGED
@@ -150,34 +150,39 @@ export function formatEthData(data: {
150
150
  return data.__formattedEthData
151
151
  }
152
152
 
153
- const log = data.log ? formatLog(data.log) : undefined
154
- if (data.block && !data.block.transactions) {
155
- data.block.transactions = []
156
- }
157
- const block = data.block ? formatRichBlock(data.block) : undefined
158
- const trace = data.trace ? (data.trace as Trace) : undefined
159
- let transaction = undefined
160
- if (data.transaction) {
161
- if (!data.transaction.v) {
162
- data.transaction.v = '0x1c'
163
- data.transaction.r = '0x88ff6cf0fefd94db46111149ae4bfc179e9b94721fffd821d38d16464b3f71d0'
164
- data.transaction.s = '0x45e0aff800961cfce805daef7016b9b675c137a6a41a548f7b60a3484c06a33a'
153
+ try {
154
+ const log = data.log ? formatLog(data.log) : undefined
155
+ if (data.block && !data.block.transactions) {
156
+ data.block.transactions = []
157
+ }
158
+ const block = data.block ? formatRichBlock(data.block) : undefined
159
+ const trace = data.trace ? (data.trace as Trace) : undefined
160
+ let transaction = undefined
161
+ if (data.transaction) {
162
+ if (!data.transaction.v) {
163
+ data.transaction.v = '0x1c'
164
+ data.transaction.r = '0x88ff6cf0fefd94db46111149ae4bfc179e9b94721fffd821d38d16464b3f71d0'
165
+ data.transaction.s = '0x45e0aff800961cfce805daef7016b9b675c137a6a41a548f7b60a3484c06a33a'
166
+ }
167
+ transaction = formatTransactionResponse(data.transaction)
168
+ }
169
+ const transactionReceipt = data.transactionReceipt ? formatTransactionReceipt(data.transactionReceipt) : undefined
170
+
171
+ const result = {
172
+ log,
173
+ block,
174
+ trace,
175
+ transaction,
176
+ transactionReceipt
165
177
  }
166
- transaction = formatTransactionResponse(data.transaction)
167
- }
168
- const transactionReceipt = data.transactionReceipt ? formatTransactionReceipt(data.transactionReceipt) : undefined
169
-
170
- const result = {
171
- log,
172
- block,
173
- trace,
174
- transaction,
175
- transactionReceipt
176
- }
177
178
 
178
- // Cache the result on the input data object
179
- data.__formattedEthData = result
180
- return result
179
+ // Cache the result on the input data object
180
+ data.__formattedEthData = result
181
+ return result
182
+ } catch (e) {
183
+ console.error('Error formatting eth data', e)
184
+ return data
185
+ }
181
186
  }
182
187
 
183
188
  export function formatRichBlock(block: RichBlock): RichBlock {