envio 3.3.0-alpha.1 → 3.3.0-alpha.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 (136) hide show
  1. package/evm.schema.json +10 -0
  2. package/index.d.ts +45 -25
  3. package/package.json +7 -7
  4. package/src/Address.res +5 -2
  5. package/src/Address.res.mjs +3 -1
  6. package/src/Api.res +1 -1
  7. package/src/Api.res.mjs +1 -1
  8. package/src/Batch.res +0 -6
  9. package/src/Batch.res.mjs +1 -12
  10. package/src/BatchProcessing.res +7 -12
  11. package/src/BatchProcessing.res.mjs +8 -7
  12. package/src/Bin.res +3 -0
  13. package/src/Bin.res.mjs +4 -0
  14. package/src/ChainFetching.res +43 -9
  15. package/src/ChainFetching.res.mjs +34 -15
  16. package/src/ChainMetadata.res +1 -11
  17. package/src/ChainMetadata.res.mjs +1 -10
  18. package/src/ChainState.res +605 -151
  19. package/src/ChainState.res.mjs +427 -104
  20. package/src/ChainState.resi +72 -4
  21. package/src/Config.res +61 -33
  22. package/src/Config.res.mjs +50 -10
  23. package/src/ContractRegisterContext.res +2 -12
  24. package/src/ContractRegisterContext.res.mjs +3 -5
  25. package/src/Core.res +14 -3
  26. package/src/CrossChainState.res +113 -89
  27. package/src/CrossChainState.res.mjs +64 -60
  28. package/src/CrossChainState.resi +1 -1
  29. package/src/Ecosystem.res +5 -6
  30. package/src/Ecosystem.res.mjs +3 -3
  31. package/src/Envio.res +17 -11
  32. package/src/EnvioGlobal.res +53 -0
  33. package/src/EnvioGlobal.res.mjs +31 -0
  34. package/src/EventConfigBuilder.res +177 -88
  35. package/src/EventConfigBuilder.res.mjs +99 -42
  36. package/src/EventProcessing.res +74 -28
  37. package/src/EventProcessing.res.mjs +55 -29
  38. package/src/ExitOnCaughtUp.res +10 -2
  39. package/src/ExitOnCaughtUp.res.mjs +10 -1
  40. package/src/FetchState.res +544 -356
  41. package/src/FetchState.res.mjs +412 -471
  42. package/src/HandlerLoader.res +8 -104
  43. package/src/HandlerLoader.res.mjs +2 -81
  44. package/src/HandlerRegister.res +518 -144
  45. package/src/HandlerRegister.res.mjs +285 -133
  46. package/src/HandlerRegister.resi +24 -8
  47. package/src/IndexerState.res +10 -3
  48. package/src/IndexerState.res.mjs +11 -4
  49. package/src/IndexerState.resi +2 -1
  50. package/src/IndexingAddresses.res +108 -0
  51. package/src/IndexingAddresses.res.mjs +101 -0
  52. package/src/IndexingAddresses.resi +34 -0
  53. package/src/Internal.res +155 -46
  54. package/src/Internal.res.mjs +30 -2
  55. package/src/LoadLayer.res +5 -5
  56. package/src/LoadLayer.res.mjs +6 -6
  57. package/src/LogSelection.res +102 -165
  58. package/src/LogSelection.res.mjs +101 -116
  59. package/src/Main.res +71 -236
  60. package/src/Main.res.mjs +60 -145
  61. package/src/Metrics.res +74 -0
  62. package/src/Metrics.res.mjs +75 -0
  63. package/src/PgStorage.res +4 -4
  64. package/src/PgStorage.res.mjs +5 -5
  65. package/src/Prometheus.res +10 -63
  66. package/src/Prometheus.res.mjs +124 -171
  67. package/src/PruneStaleHistory.res +2 -2
  68. package/src/PruneStaleHistory.res.mjs +3 -3
  69. package/src/RawEvent.res +7 -2
  70. package/src/RawEvent.res.mjs +4 -4
  71. package/src/Rollback.res +3 -3
  72. package/src/Rollback.res.mjs +4 -4
  73. package/src/RollbackCommit.res +4 -1
  74. package/src/RollbackCommit.res.mjs +3 -2
  75. package/src/SimulateDeadInputTracker.res +85 -0
  76. package/src/SimulateDeadInputTracker.res.mjs +73 -0
  77. package/src/SimulateDeadInputTracker.resi +12 -0
  78. package/src/SimulateItems.res +91 -23
  79. package/src/SimulateItems.res.mjs +55 -32
  80. package/src/TestIndexer.res +54 -40
  81. package/src/TestIndexer.res.mjs +37 -30
  82. package/src/bindings/Performance.res +7 -0
  83. package/src/bindings/Performance.res.mjs +21 -0
  84. package/src/bindings/Performance.resi +7 -0
  85. package/src/bindings/Viem.res +0 -41
  86. package/src/bindings/Viem.res.mjs +1 -43
  87. package/src/sources/BlockStore.res +46 -0
  88. package/src/sources/BlockStore.res.mjs +24 -0
  89. package/src/sources/EventRouter.res +36 -33
  90. package/src/sources/EventRouter.res.mjs +13 -14
  91. package/src/sources/Evm.res +83 -72
  92. package/src/sources/Evm.res.mjs +53 -69
  93. package/src/sources/EvmChain.res +18 -20
  94. package/src/sources/EvmChain.res.mjs +15 -15
  95. package/src/sources/EvmRpcClient.res +74 -5
  96. package/src/sources/EvmRpcClient.res.mjs +13 -4
  97. package/src/sources/FieldMask.res +39 -0
  98. package/src/sources/FieldMask.res.mjs +42 -0
  99. package/src/sources/Fuel.res +9 -6
  100. package/src/sources/Fuel.res.mjs +5 -10
  101. package/src/sources/HyperFuelSource.res +46 -50
  102. package/src/sources/HyperFuelSource.res.mjs +64 -54
  103. package/src/sources/HyperSync.res +39 -7
  104. package/src/sources/HyperSync.res.mjs +57 -37
  105. package/src/sources/HyperSync.resi +12 -2
  106. package/src/sources/HyperSyncClient.res +22 -111
  107. package/src/sources/HyperSyncClient.res.mjs +2 -30
  108. package/src/sources/HyperSyncHeightStream.res +1 -8
  109. package/src/sources/HyperSyncHeightStream.res.mjs +0 -2
  110. package/src/sources/HyperSyncSource.res +94 -107
  111. package/src/sources/HyperSyncSource.res.mjs +82 -86
  112. package/src/sources/Rpc.res +15 -47
  113. package/src/sources/Rpc.res.mjs +25 -56
  114. package/src/sources/RpcSource.res +320 -467
  115. package/src/sources/RpcSource.res.mjs +268 -385
  116. package/src/sources/RpcWebSocketHeightStream.res +0 -5
  117. package/src/sources/RpcWebSocketHeightStream.res.mjs +0 -2
  118. package/src/sources/SimulateSource.res +10 -4
  119. package/src/sources/SimulateSource.res.mjs +16 -6
  120. package/src/sources/Source.res +34 -6
  121. package/src/sources/SourceManager.res +77 -19
  122. package/src/sources/SourceManager.res.mjs +63 -21
  123. package/src/sources/SourceManager.resi +10 -0
  124. package/src/sources/Svm.res +31 -16
  125. package/src/sources/Svm.res.mjs +36 -13
  126. package/src/sources/SvmHyperSyncClient.res +5 -32
  127. package/src/sources/SvmHyperSyncSource.res +159 -134
  128. package/src/sources/SvmHyperSyncSource.res.mjs +164 -129
  129. package/src/sources/TransactionStore.res +49 -0
  130. package/src/sources/TransactionStore.res.mjs +30 -0
  131. package/src/tui/Tui.res +13 -16
  132. package/src/tui/Tui.res.mjs +12 -14
  133. package/svm.schema.json +49 -37
  134. package/src/bindings/Hrtime.res +0 -58
  135. package/src/bindings/Hrtime.res.mjs +0 -90
  136. package/src/bindings/Hrtime.resi +0 -30
@@ -0,0 +1,42 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+
4
+ function fieldCodes(fields) {
5
+ let codes = {};
6
+ fields.forEach((name, i) => {
7
+ codes[name] = i;
8
+ });
9
+ return codes;
10
+ }
11
+
12
+ let pow2 = (c => Math.pow(2, c));
13
+
14
+ function maskFromFields(selectedFields, codes) {
15
+ let mask = {
16
+ contents: 0
17
+ };
18
+ selectedFields.forEach(name => {
19
+ let code = codes[name];
20
+ if (code !== undefined) {
21
+ mask.contents = mask.contents + pow2(code);
22
+ return;
23
+ }
24
+ });
25
+ return mask.contents;
26
+ }
27
+
28
+ function makeMaskFn(fields) {
29
+ let codes = fieldCodes(fields);
30
+ return selectedFields => maskFromFields(selectedFields, codes);
31
+ }
32
+
33
+ let orMask = ((a, b) => (a | b) >>> 0);
34
+
35
+ export {
36
+ fieldCodes,
37
+ pow2,
38
+ maskFromFields,
39
+ makeMaskFn,
40
+ orMask,
41
+ }
42
+ /* No side effect */
@@ -21,8 +21,6 @@ let cleanUpRawEventFieldsInPlace: JSON.t => unit = %raw(`fields => {
21
21
 
22
22
  let make = (~logger: Pino.t): Ecosystem.t => {
23
23
  name: Fuel,
24
- blockFields: ["id", "height", "time"],
25
- transactionFields: ["id"],
26
24
  blockNumberName: "height",
27
25
  blockTimestampName: "time",
28
26
  blockHashName: "id",
@@ -37,17 +35,19 @@ let make = (~logger: Pino.t): Ecosystem.t => {
37
35
  // Analogous to EVM, but keyed by `block.height` instead of
38
36
  // `block.number`. See `Evm.res` for the rationale on the two-stage
39
37
  // parse and the `_lte`/`_every` rejection.
38
+ // `S.strict` on the inner object rejects unknown `block` fields — including
39
+ // `block.number`, which is EVM-only; Fuel filters by `block.height`.
40
40
  onEventBlockFilterSchema: S.object(s =>
41
- s.field("block", S.option(S.object(s2 => s2.field("height", S.unknown))))
41
+ s.field("block", S.option(S.object(s2 => s2.field("height", S.unknown))->S.strict))
42
42
  ),
43
43
  logger,
44
- toEvent: eventItem => eventItem.payload->Internal.payloadToEvent,
44
+ toEvent: eventItem => eventItem.payload->(Utils.magic: Internal.eventPayload => Internal.event),
45
45
  toEventLogger: eventItem =>
46
46
  Logging.createChildFrom(
47
47
  ~logger,
48
48
  ~params={
49
- "contract": eventItem.eventConfig.contractName,
50
- "event": eventItem.eventConfig.name,
49
+ "contract": eventItem.onEventRegistration.eventConfig.contractName,
50
+ "event": eventItem.onEventRegistration.eventConfig.name,
51
51
  "chainId": eventItem.chain->ChainMap.Chain.toChainId,
52
52
  "block": eventItem.blockNumber,
53
53
  "logIndex": eventItem.logIndex,
@@ -56,11 +56,14 @@ let make = (~logger: Pino.t): Ecosystem.t => {
56
56
  ),
57
57
  toRawEvent: eventItem => {
58
58
  let payload = eventItem.payload->toPayload
59
+ let header = payload.block->(Utils.magic: Internal.eventBlock => {"id": string, "time": int})
59
60
  eventItem->RawEvent.make(
60
61
  ~block=payload.block,
61
62
  ~transaction=payload.transaction,
62
63
  ~params=payload.params,
63
64
  ~srcAddress=payload.srcAddress,
65
+ ~blockHash=header["id"],
66
+ ~blockTimestamp=header["time"],
64
67
  ~cleanUpRawEventFieldsInPlace,
65
68
  )
66
69
  },
@@ -13,24 +13,18 @@ let cleanUpRawEventFieldsInPlace = (fields => {
13
13
  function make(logger) {
14
14
  return {
15
15
  name: "fuel",
16
- blockFields: [
17
- "id",
18
- "height",
19
- "time"
20
- ],
21
- transactionFields: ["id"],
22
16
  blockNumberName: "height",
23
17
  blockTimestampName: "time",
24
18
  blockHashName: "id",
25
19
  cleanUpRawEventFieldsInPlace: cleanUpRawEventFieldsInPlace,
26
20
  onBlockMethodName: "onBlock",
27
21
  onBlockFilterSchema: S$RescriptSchema.object(s => s.f("block", S$RescriptSchema.option(S$RescriptSchema.object(s2 => s2.f("height", S$RescriptSchema.unknown))))),
28
- onEventBlockFilterSchema: S$RescriptSchema.object(s => s.f("block", S$RescriptSchema.option(S$RescriptSchema.object(s2 => s2.f("height", S$RescriptSchema.unknown))))),
22
+ onEventBlockFilterSchema: S$RescriptSchema.object(s => s.f("block", S$RescriptSchema.option(S$RescriptSchema.strict(S$RescriptSchema.object(s2 => s2.f("height", S$RescriptSchema.unknown)))))),
29
23
  logger: logger,
30
24
  toEvent: eventItem => eventItem.payload,
31
25
  toEventLogger: eventItem => Logging.createChildFrom(logger, {
32
- contract: eventItem.eventConfig.contractName,
33
- event: eventItem.eventConfig.name,
26
+ contract: eventItem.onEventRegistration.eventConfig.contractName,
27
+ event: eventItem.onEventRegistration.eventConfig.name,
34
28
  chainId: eventItem.chain,
35
29
  block: eventItem.blockNumber,
36
30
  logIndex: eventItem.logIndex,
@@ -38,7 +32,8 @@ function make(logger) {
38
32
  }),
39
33
  toRawEvent: eventItem => {
40
34
  let payload = eventItem.payload;
41
- return RawEvent.make(eventItem, payload.block, payload.transaction, payload.params, payload.srcAddress, cleanUpRawEventFieldsInPlace);
35
+ let header = payload.block;
36
+ return RawEvent.make(eventItem, payload.block, payload.transaction, payload.params, payload.srcAddress, header.id, header.time, cleanUpRawEventFieldsInPlace);
42
37
  }
43
38
  };
44
39
  }
@@ -13,7 +13,7 @@ type selectionConfig = {
13
13
  getRecieptsSelection: (
14
14
  ~addressesByContractName: dict<array<Address.t>>,
15
15
  ) => array<HyperFuelClient.QueryTypes.receiptSelection>,
16
- eventRouter: EventRouter.t<Internal.fuelEventConfig>,
16
+ eventRouter: EventRouter.t<Internal.fuelOnEventRegistration>,
17
17
  }
18
18
 
19
19
  let logDataReceiptTypeSelection: array<FuelSDK.receiptType> = [LogData]
@@ -127,39 +127,40 @@ let getSelectionConfig = (selection: FetchState.selection, ~chain) => {
127
127
 
128
128
  let contractNames = Utils.Set.make()
129
129
 
130
- selection.eventConfigs
131
- ->(Utils.magic: array<Internal.eventConfig> => array<Internal.fuelEventConfig>)
132
- ->Array.forEach(eventConfig => {
130
+ selection.onEventRegistrations->Array.forEach(reg => {
131
+ let eventConfig =
132
+ reg.eventConfig->(Utils.magic: Internal.eventConfig => Internal.fuelEventConfig)
133
133
  let contractName = eventConfig.contractName
134
- if !eventConfig.isWildcard {
134
+ let isWildcard = reg.isWildcard
135
+ if !isWildcard {
135
136
  let _ = contractNames->Utils.Set.add(contractName)
136
137
  }
137
138
  eventRouter->EventRouter.addOrThrow(
138
139
  eventConfig.id,
139
- eventConfig,
140
+ reg,
140
141
  ~contractName,
141
142
  ~eventName=eventConfig.name,
142
143
  ~chain,
143
- ~isWildcard=eventConfig.isWildcard,
144
+ ~isWildcard,
144
145
  )
145
146
 
146
- switch eventConfig {
147
- | {kind: Mint, isWildcard: true} => addNonLogDataWildcardReceiptTypes(Mint)
148
- | {kind: Mint} => addNonLogDataReceiptType(contractName, Mint)
149
- | {kind: Burn, isWildcard: true} => addNonLogDataWildcardReceiptTypes(Burn)
150
- | {kind: Burn} => addNonLogDataReceiptType(contractName, Burn)
151
- | {kind: Transfer, isWildcard: true} => {
147
+ switch (eventConfig.kind, isWildcard) {
148
+ | (Mint, true) => addNonLogDataWildcardReceiptTypes(Mint)
149
+ | (Mint, false) => addNonLogDataReceiptType(contractName, Mint)
150
+ | (Burn, true) => addNonLogDataWildcardReceiptTypes(Burn)
151
+ | (Burn, false) => addNonLogDataReceiptType(contractName, Burn)
152
+ | (Transfer, true) => {
152
153
  addNonLogDataWildcardReceiptTypes(Transfer)
153
154
  addNonLogDataWildcardReceiptTypes(TransferOut)
154
155
  }
155
- | {kind: Transfer} => {
156
+ | (Transfer, false) => {
156
157
  addNonLogDataReceiptType(contractName, Transfer)
157
158
  addNonLogDataReceiptType(contractName, TransferOut)
158
159
  }
159
- | {kind: Call, isWildcard: true} => addNonLogDataWildcardReceiptTypes(Call)
160
- | {kind: Call} =>
160
+ | (Call, true) => addNonLogDataWildcardReceiptTypes(Call)
161
+ | (Call, false) =>
161
162
  JsError.throwWithMessage("Call receipt indexing currently supported only in wildcard mode")
162
- | {kind: LogData({logId}), isWildcard} => {
163
+ | (LogData({logId}), _) => {
163
164
  let rb = logId->BigInt.fromStringOrThrow
164
165
  if isWildcard {
165
166
  wildcardLogDataRbs->Array.push(rb)->ignore
@@ -235,26 +236,22 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
235
236
  ~fromBlock,
236
237
  ~toBlock,
237
238
  ~addressesByContractName,
238
- ~indexingAddresses,
239
+ ~contractNameByAddress,
239
240
  ~knownHeight,
240
241
  ~partitionId as _,
241
242
  ~selection: FetchState.selection,
243
+ ~itemsTarget as _,
242
244
  ~retry,
243
245
  ~logger,
244
246
  ) => {
245
- let totalTimeRef = Hrtime.makeTimer()
247
+ let totalTimeRef = Performance.now()
246
248
 
247
249
  let selectionConfig = getSelectionConfig(selection)
248
250
  let recieptsSelection = selectionConfig.getRecieptsSelection(~addressesByContractName)
249
251
 
250
- let startFetchingBatchTimeRef = Hrtime.makeTimer()
252
+ let startFetchingBatchTimeRef = Performance.now()
251
253
 
252
254
  //fetch batch
253
- Prometheus.SourceRequestCount.increment(
254
- ~sourceName=name,
255
- ~chainId=chain->ChainMap.Chain.toChainId,
256
- ~method="getLogs",
257
- )
258
255
  let pageUnsafe = try await HyperFuel.GetLogs.query(
259
256
  ~client,
260
257
  ~fromBlock,
@@ -305,7 +302,8 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
305
302
  )
306
303
  }
307
304
 
308
- let pageFetchTime = startFetchingBatchTimeRef->Hrtime.timeSince->Hrtime.toSecondsFloat
305
+ let pageFetchTime = startFetchingBatchTimeRef->Performance.secondsSince
306
+ let requestStats = [{Source.method: "getLogs", seconds: pageFetchTime}]
309
307
 
310
308
  //set height and next from block
311
309
  let knownHeight = pageUnsafe.archiveHeight
@@ -315,7 +313,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
315
313
  //In the query
316
314
  let heighestBlockQueried = pageUnsafe.nextBlock - 1
317
315
 
318
- let parsingTimeRef = Hrtime.makeTimer()
316
+ let parsingTimeRef = Performance.now()
319
317
 
320
318
  let parsedQueueItems = pageUnsafe.items->Array.map(item => {
321
319
  let {contractId: contractAddress, receipt, block, receiptIndex} = item
@@ -330,11 +328,10 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
330
328
  | Call(_) => callEventTag
331
329
  }
332
330
 
333
- let eventConfig = switch selectionConfig.eventRouter->EventRouter.get(
331
+ let onEventRegistration = switch selectionConfig.eventRouter->EventRouter.get(
334
332
  ~tag=eventId,
335
- ~indexingAddresses,
333
+ ~contractNameByAddress,
336
334
  ~contractAddress,
337
- ~blockNumber=block.height,
338
335
  ) {
339
336
  | None => {
340
337
  let logger = Logging.createChildFrom(
@@ -352,9 +349,14 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
352
349
  ~logger,
353
350
  )
354
351
  }
355
- | Some(eventConfig) => eventConfig
352
+ | Some(onEventRegistration) => onEventRegistration
356
353
  }
357
354
 
355
+ let eventConfig =
356
+ onEventRegistration.eventConfig->(
357
+ Utils.magic: Internal.eventConfig => Internal.fuelEventConfig
358
+ )
359
+
358
360
  let params = switch (eventConfig, receipt) {
359
361
  | ({kind: LogData({decode})}, LogData({data})) =>
360
362
  try decode(data) catch {
@@ -408,12 +410,13 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
408
410
  }
409
411
 
410
412
  Internal.Event({
411
- eventConfig: (eventConfig :> Internal.eventConfig),
412
- timestamp: block.time,
413
+ onEventRegistration: (onEventRegistration :> Internal.onEventRegistration),
413
414
  chain,
414
415
  blockNumber: block.height,
415
- blockHash: block.id,
416
416
  logIndex: receiptIndex,
417
+ // Fuel carries the transaction inline on the payload; the store key is
418
+ // unused (Fuel identifies transactions by hash, kept on the payload).
419
+ transactionIndex: 0,
417
420
  payload: {
418
421
  contractName: eventConfig.contractName,
419
422
  eventName: eventConfig.name,
@@ -429,7 +432,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
429
432
  })
430
433
  })
431
434
 
432
- let parsingTimeElapsed = parsingTimeRef->Hrtime.timeSince->Hrtime.toSecondsFloat
435
+ let parsingTimeElapsed = parsingTimeRef->Performance.secondsSince
433
436
 
434
437
  // Fuel never rolls back on reorg, so block hashes here are purely informational
435
438
  // for detect-only logging via ReorgDetection.
@@ -445,7 +448,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
445
448
  | _ => 0
446
449
  }
447
450
 
448
- let totalTimeElapsed = totalTimeRef->Hrtime.timeSince->Hrtime.toSecondsFloat
451
+ let totalTimeElapsed = totalTimeRef->Performance.secondsSince
449
452
 
450
453
  let stats = {
451
454
  totalTimeElapsed,
@@ -456,11 +459,15 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
456
459
  {
457
460
  latestFetchedBlockTimestamp,
458
461
  parsedQueueItems,
462
+ // Fuel keeps transaction and block on the payload; no store pages.
463
+ transactionStore: None,
464
+ blockStore: None,
459
465
  latestFetchedBlockNumber: heighestBlockQueried,
460
466
  stats,
461
467
  knownHeight,
462
468
  blockHashes,
463
469
  fromBlockQueried: fromBlock,
470
+ requestStats,
464
471
  }
465
472
  }
466
473
 
@@ -475,7 +482,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
475
482
  pollingInterval: 100,
476
483
  poweredByHyperSync: true,
477
484
  getHeightOrThrow: async () => {
478
- let timerRef = Hrtime.makeTimer()
485
+ let timerRef = Performance.now()
479
486
  let height = try await client->HyperFuelClient.getHeight catch {
480
487
  | JsExn(e) =>
481
488
  switch e->JsExn.message {
@@ -487,19 +494,8 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
487
494
  | _ => throw(JsExn(e))
488
495
  }
489
496
  }
490
- let seconds = timerRef->Hrtime.timeSince->Hrtime.toSecondsFloat
491
- Prometheus.SourceRequestCount.increment(
492
- ~sourceName=name,
493
- ~chainId=chain->ChainMap.Chain.toChainId,
494
- ~method="getHeight",
495
- )
496
- Prometheus.SourceRequestCount.addSeconds(
497
- ~sourceName=name,
498
- ~chainId=chain->ChainMap.Chain.toChainId,
499
- ~method="getHeight",
500
- ~seconds,
501
- )
502
- height
497
+ let seconds = timerRef->Performance.secondsSince
498
+ {height, requestStats: [{method: "getHeight", seconds}]}
503
499
  },
504
500
  getItemsOrThrow,
505
501
  }
@@ -1,11 +1,10 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
- import * as Hrtime from "../bindings/Hrtime.res.mjs";
4
3
  import * as Source from "./Source.res.mjs";
5
4
  import * as Logging from "../Logging.res.mjs";
6
5
  import * as HyperFuel from "./HyperFuel.res.mjs";
7
- import * as Prometheus from "../Prometheus.res.mjs";
8
6
  import * as EventRouter from "./EventRouter.res.mjs";
7
+ import * as Performance from "../bindings/Performance.res.mjs";
9
8
  import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
10
9
  import * as ErrorHandling from "../ErrorHandling.res.mjs";
11
10
  import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
@@ -101,41 +100,43 @@ function getSelectionConfig(selection, chain) {
101
100
  }
102
101
  };
103
102
  let contractNames = new Set();
104
- selection.eventConfigs.forEach(eventConfig => {
103
+ selection.onEventRegistrations.forEach(reg => {
104
+ let eventConfig = reg.eventConfig;
105
105
  let contractName = eventConfig.contractName;
106
- if (!eventConfig.isWildcard) {
106
+ let isWildcard = reg.isWildcard;
107
+ if (!isWildcard) {
107
108
  contractNames.add(contractName);
108
109
  }
109
- EventRouter.addOrThrow(eventRouter, eventConfig.id, eventConfig, contractName, eventConfig.isWildcard, eventConfig.name, chain);
110
- let isWildcard = eventConfig.isWildcard;
111
- if (isWildcard) {
112
- let tmp = eventConfig.kind;
113
- if (typeof tmp !== "object") {
114
- switch (tmp) {
115
- case "Mint" :
116
- return addNonLogDataWildcardReceiptTypes(11);
117
- case "Burn" :
118
- return addNonLogDataWildcardReceiptTypes(12);
119
- case "Transfer" :
120
- addNonLogDataWildcardReceiptTypes(7);
121
- return addNonLogDataWildcardReceiptTypes(8);
122
- case "Call" :
123
- return addNonLogDataWildcardReceiptTypes(0);
124
- }
125
- }
126
- }
110
+ EventRouter.addOrThrow(eventRouter, eventConfig.id, reg, contractName, isWildcard, eventConfig.name, chain);
127
111
  let match = eventConfig.kind;
128
112
  if (typeof match !== "object") {
129
113
  switch (match) {
130
114
  case "Mint" :
131
- return addNonLogDataReceiptType(contractName, 11);
115
+ if (isWildcard) {
116
+ return addNonLogDataWildcardReceiptTypes(11);
117
+ } else {
118
+ return addNonLogDataReceiptType(contractName, 11);
119
+ }
132
120
  case "Burn" :
133
- return addNonLogDataReceiptType(contractName, 12);
121
+ if (isWildcard) {
122
+ return addNonLogDataWildcardReceiptTypes(12);
123
+ } else {
124
+ return addNonLogDataReceiptType(contractName, 12);
125
+ }
134
126
  case "Transfer" :
135
- addNonLogDataReceiptType(contractName, 7);
136
- return addNonLogDataReceiptType(contractName, 8);
127
+ if (isWildcard) {
128
+ addNonLogDataWildcardReceiptTypes(7);
129
+ return addNonLogDataWildcardReceiptTypes(8);
130
+ } else {
131
+ addNonLogDataReceiptType(contractName, 7);
132
+ return addNonLogDataReceiptType(contractName, 8);
133
+ }
137
134
  case "Call" :
138
- return Stdlib_JsError.throwWithMessage("Call receipt indexing currently supported only in wildcard mode");
135
+ if (isWildcard) {
136
+ return addNonLogDataWildcardReceiptTypes(0);
137
+ } else {
138
+ return Stdlib_JsError.throwWithMessage("Call receipt indexing currently supported only in wildcard mode");
139
+ }
139
140
  }
140
141
  } else {
141
142
  let rb = BigInt(match.logId);
@@ -181,7 +182,6 @@ function memoGetSelectionConfig(chain) {
181
182
  function make(param) {
182
183
  let apiToken = param.apiToken;
183
184
  let chain = param.chain;
184
- let name = "HyperFuel";
185
185
  let apiToken$1 = apiToken !== undefined ? apiToken : Stdlib_JsError.throwWithMessage(`An Envio API token is required for using HyperFuel as a data-source.
186
186
  Set the ENVIO_API_TOKEN environment variable in your .env file.
187
187
  Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
@@ -196,12 +196,11 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
196
196
  client = ErrorHandling.mkLogAndRaise(undefined, "Failed to instantiate the HyperFuel client", exn);
197
197
  }
198
198
  let getSelectionConfig = memoGetSelectionConfig(chain);
199
- let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName, indexingAddresses, knownHeight, param, selection, retry, logger) => {
200
- let totalTimeRef = Hrtime.makeTimer();
199
+ let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName, contractNameByAddress, knownHeight, param, selection, param$1, retry, logger) => {
200
+ let totalTimeRef = Performance.now();
201
201
  let selectionConfig = getSelectionConfig(selection);
202
202
  let recieptsSelection = selectionConfig.getRecieptsSelection(addressesByContractName);
203
- let startFetchingBatchTimeRef = Hrtime.makeTimer();
204
- Prometheus.SourceRequestCount.increment(name, chain, "getLogs");
203
+ let startFetchingBatchTimeRef = Performance.now();
205
204
  let pageUnsafe;
206
205
  try {
207
206
  pageUnsafe = await HyperFuel.GetLogs.query(client, fromBlock, toBlock, recieptsSelection);
@@ -249,10 +248,14 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
249
248
  Error: new Error()
250
249
  };
251
250
  }
252
- let pageFetchTime = Hrtime.toSecondsFloat(Hrtime.timeSince(startFetchingBatchTimeRef));
251
+ let pageFetchTime = Performance.secondsSince(startFetchingBatchTimeRef);
252
+ let requestStats = [{
253
+ method: "getLogs",
254
+ seconds: pageFetchTime
255
+ }];
253
256
  let knownHeight$1 = pageUnsafe.archiveHeight;
254
257
  let heighestBlockQueried = pageUnsafe.nextBlock - 1 | 0;
255
- let parsingTimeRef = Hrtime.makeTimer();
258
+ let parsingTimeRef = Performance.now();
256
259
  let parsedQueueItems = pageUnsafe.items.map(item => {
257
260
  let block = item.block;
258
261
  let receiptIndex = item.receiptIndex;
@@ -277,10 +280,10 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
277
280
  eventId = burnEventTag;
278
281
  break;
279
282
  }
280
- let eventConfig = EventRouter.get(selectionConfig.eventRouter, eventId, contractAddress, block.height, indexingAddresses);
281
- let eventConfig$1;
282
- if (eventConfig !== undefined) {
283
- eventConfig$1 = eventConfig;
283
+ let onEventRegistration = EventRouter.get(selectionConfig.eventRouter, eventId, contractAddress, contractNameByAddress);
284
+ let onEventRegistration$1;
285
+ if (onEventRegistration !== undefined) {
286
+ onEventRegistration$1 = onEventRegistration;
284
287
  } else {
285
288
  let logger$1 = Logging.createChildFrom(logger, {
286
289
  chainId: chain,
@@ -289,11 +292,12 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
289
292
  contractAddress: contractAddress,
290
293
  eventId: eventId
291
294
  });
292
- eventConfig$1 = ErrorHandling.mkLogAndRaise(logger$1, "Failed to route registered event", {
295
+ onEventRegistration$1 = ErrorHandling.mkLogAndRaise(logger$1, "Failed to route registered event", {
293
296
  RE_EXN_ID: EventRoutingFailed
294
297
  });
295
298
  }
296
- let match = eventConfig$1.kind;
299
+ let eventConfig = onEventRegistration$1.eventConfig;
300
+ let match = eventConfig.kind;
297
301
  let params;
298
302
  let exit = 0;
299
303
  if (typeof match !== "object" || receipt.receiptType !== 6) {
@@ -349,15 +353,14 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
349
353
  }
350
354
  return {
351
355
  kind: 0,
352
- eventConfig: eventConfig$1,
353
- timestamp: block.time,
356
+ onEventRegistration: onEventRegistration$1,
354
357
  chain: chain,
355
358
  blockNumber: block.height,
356
- blockHash: block.id,
357
359
  logIndex: receiptIndex,
360
+ transactionIndex: 0,
358
361
  payload: {
359
- contractName: eventConfig$1.contractName,
360
- eventName: eventConfig$1.name,
362
+ contractName: eventConfig.contractName,
363
+ eventName: eventConfig.name,
361
364
  params: params,
362
365
  chainId: chain,
363
366
  srcAddress: contractAddress,
@@ -369,7 +372,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
369
372
  }
370
373
  };
371
374
  });
372
- let parsingTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(parsingTimeRef));
375
+ let parsingTimeElapsed = Performance.secondsSince(parsingTimeRef);
373
376
  let blockHashes = pageUnsafe.items.map(param => {
374
377
  let block = param.block;
375
378
  return {
@@ -385,7 +388,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
385
388
  } else {
386
389
  latestFetchedBlockTimestamp = 0;
387
390
  }
388
- let totalTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(totalTimeRef));
391
+ let totalTimeElapsed = Performance.secondsSince(totalTimeRef);
389
392
  let stats_parsing$unknowntime$unknown$lpars$rpar = parsingTimeElapsed;
390
393
  let stats_page$unknownfetch$unknowntime$unknown$lpars$rpar = pageFetchTime;
391
394
  let stats = {
@@ -397,22 +400,25 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
397
400
  knownHeight: knownHeight$1,
398
401
  blockHashes: blockHashes,
399
402
  parsedQueueItems: parsedQueueItems,
403
+ transactionStore: undefined,
404
+ blockStore: undefined,
400
405
  fromBlockQueried: fromBlock,
401
406
  latestFetchedBlockNumber: heighestBlockQueried,
402
407
  latestFetchedBlockTimestamp: latestFetchedBlockTimestamp,
403
- stats: stats
408
+ stats: stats,
409
+ requestStats: requestStats
404
410
  };
405
411
  };
406
412
  let getBlockHashes = (param, param$1) => Stdlib_JsError.throwWithMessage("HyperFuel does not support getting block hashes");
407
413
  return {
408
- name: name,
414
+ name: "HyperFuel",
409
415
  sourceFor: "Sync",
410
416
  chain: chain,
411
417
  poweredByHyperSync: true,
412
418
  pollingInterval: 100,
413
419
  getBlockHashes: getBlockHashes,
414
420
  getHeightOrThrow: async () => {
415
- let timerRef = Hrtime.makeTimer();
421
+ let timerRef = Performance.now();
416
422
  let height;
417
423
  try {
418
424
  height = await client.getHeight();
@@ -444,10 +450,14 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
444
450
  throw e;
445
451
  }
446
452
  }
447
- let seconds = Hrtime.toSecondsFloat(Hrtime.timeSince(timerRef));
448
- Prometheus.SourceRequestCount.increment(name, chain, "getHeight");
449
- Prometheus.SourceRequestCount.addSeconds(name, chain, "getHeight", seconds);
450
- return height;
453
+ let seconds = Performance.secondsSince(timerRef);
454
+ return {
455
+ height: height,
456
+ requestStats: [{
457
+ method: "getHeight",
458
+ seconds: seconds
459
+ }]
460
+ };
451
461
  },
452
462
  getItemsOrThrow: getItemsOrThrow
453
463
  };