envio 3.0.0-alpha.0 → 3.0.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/README.md +2 -2
  2. package/evm.schema.json +53 -57
  3. package/fuel.schema.json +35 -31
  4. package/index.d.ts +446 -1
  5. package/index.js +4 -0
  6. package/package.json +23 -11
  7. package/rescript.json +4 -1
  8. package/src/Batch.res.mjs +1 -1
  9. package/src/Benchmark.res +394 -0
  10. package/src/Benchmark.res.mjs +398 -0
  11. package/src/ChainFetcher.res +526 -0
  12. package/src/ChainFetcher.res.mjs +343 -0
  13. package/src/ChainManager.res +182 -0
  14. package/src/ChainManager.res.mjs +150 -0
  15. package/src/Config.res +367 -27
  16. package/src/Config.res.mjs +338 -28
  17. package/src/{Indexer.res → Ctx.res} +1 -1
  18. package/src/Ecosystem.res +25 -0
  19. package/src/Ecosystem.res.mjs +29 -0
  20. package/src/Env.res +252 -0
  21. package/src/Env.res.mjs +271 -0
  22. package/src/Envio.gen.ts +9 -1
  23. package/src/Envio.res +12 -9
  24. package/src/EventProcessing.res +476 -0
  25. package/src/EventProcessing.res.mjs +341 -0
  26. package/src/EventRegister.res +4 -15
  27. package/src/EventRegister.res.mjs +3 -9
  28. package/src/EventRegister.resi +2 -8
  29. package/src/FetchState.res +54 -29
  30. package/src/FetchState.res.mjs +62 -35
  31. package/src/GlobalState.res +1163 -0
  32. package/src/GlobalState.res.mjs +1196 -0
  33. package/src/GlobalStateManager.res +68 -0
  34. package/src/GlobalStateManager.res.mjs +75 -0
  35. package/src/GlobalStateManager.resi +7 -0
  36. package/src/HandlerLoader.res +89 -0
  37. package/src/HandlerLoader.res.mjs +79 -0
  38. package/src/Internal.gen.ts +3 -14
  39. package/src/Internal.res +45 -13
  40. package/src/LoadLayer.res +444 -0
  41. package/src/LoadLayer.res.mjs +296 -0
  42. package/src/LoadLayer.resi +32 -0
  43. package/src/LogSelection.res +33 -27
  44. package/src/LogSelection.res.mjs +6 -0
  45. package/src/Logging.res +11 -4
  46. package/src/Logging.res.mjs +14 -6
  47. package/src/Main.res +351 -0
  48. package/src/Main.res.mjs +312 -0
  49. package/src/Persistence.res +1 -2
  50. package/src/PgStorage.gen.ts +10 -0
  51. package/src/PgStorage.res +28 -34
  52. package/src/PgStorage.res.d.mts +5 -0
  53. package/src/PgStorage.res.mjs +27 -27
  54. package/src/Prometheus.res +8 -8
  55. package/src/Prometheus.res.mjs +10 -10
  56. package/src/ReorgDetection.res +6 -10
  57. package/src/ReorgDetection.res.mjs +6 -6
  58. package/src/TestIndexer.res +536 -0
  59. package/src/TestIndexer.res.mjs +412 -0
  60. package/src/TestIndexerProxyStorage.res +210 -0
  61. package/src/TestIndexerProxyStorage.res.mjs +157 -0
  62. package/src/Types.ts +1 -1
  63. package/src/UserContext.res +355 -0
  64. package/src/UserContext.res.mjs +236 -0
  65. package/src/Utils.res +28 -0
  66. package/src/Utils.res.mjs +18 -0
  67. package/src/bindings/ClickHouse.res +31 -1
  68. package/src/bindings/ClickHouse.res.mjs +27 -1
  69. package/src/bindings/DateFns.res +71 -0
  70. package/src/bindings/DateFns.res.mjs +22 -0
  71. package/src/bindings/Ethers.res +27 -67
  72. package/src/bindings/Ethers.res.mjs +18 -70
  73. package/src/bindings/EventSource.res +13 -0
  74. package/src/bindings/EventSource.res.mjs +2 -0
  75. package/src/bindings/NodeJs.res +44 -3
  76. package/src/bindings/NodeJs.res.mjs +11 -3
  77. package/src/bindings/Pino.res +21 -7
  78. package/src/bindings/Pino.res.mjs +11 -5
  79. package/src/bindings/Postgres.gen.ts +8 -0
  80. package/src/bindings/Postgres.res +3 -0
  81. package/src/bindings/Postgres.res.d.mts +5 -0
  82. package/src/bindings/RescriptMocha.res +123 -0
  83. package/src/bindings/RescriptMocha.res.mjs +18 -0
  84. package/src/bindings/Vitest.res +134 -0
  85. package/src/bindings/Vitest.res.mjs +9 -0
  86. package/src/bindings/Yargs.res +8 -0
  87. package/src/bindings/Yargs.res.mjs +2 -0
  88. package/src/db/InternalTable.res +2 -0
  89. package/src/db/InternalTable.res.mjs +1 -1
  90. package/src/sources/Evm.res +87 -0
  91. package/src/sources/Evm.res.mjs +105 -0
  92. package/src/sources/EvmChain.res +90 -0
  93. package/src/sources/EvmChain.res.mjs +57 -0
  94. package/src/sources/Fuel.res +19 -34
  95. package/src/sources/Fuel.res.mjs +34 -16
  96. package/src/sources/FuelSDK.res +38 -0
  97. package/src/sources/FuelSDK.res.mjs +29 -0
  98. package/src/sources/HyperFuel.res +2 -2
  99. package/src/sources/HyperFuel.resi +1 -1
  100. package/src/sources/HyperFuelClient.res +2 -2
  101. package/src/sources/HyperFuelSource.res +8 -8
  102. package/src/sources/HyperFuelSource.res.mjs +5 -5
  103. package/src/sources/HyperSyncHeightStream.res +97 -0
  104. package/src/sources/HyperSyncHeightStream.res.mjs +94 -0
  105. package/src/sources/HyperSyncSource.res +64 -172
  106. package/src/sources/HyperSyncSource.res.mjs +73 -155
  107. package/src/sources/Rpc.res +43 -0
  108. package/src/sources/Rpc.res.mjs +31 -0
  109. package/src/sources/RpcSource.res +32 -130
  110. package/src/sources/RpcSource.res.mjs +47 -121
  111. package/src/sources/Source.res +3 -2
  112. package/src/sources/SourceManager.res +183 -108
  113. package/src/sources/SourceManager.res.mjs +162 -99
  114. package/src/sources/SourceManager.resi +4 -5
  115. package/src/sources/Svm.res +59 -0
  116. package/src/sources/Svm.res.mjs +79 -0
  117. package/src/tui/Tui.res +266 -0
  118. package/src/tui/Tui.res.mjs +342 -0
  119. package/src/tui/bindings/Ink.res +376 -0
  120. package/src/tui/bindings/Ink.res.mjs +75 -0
  121. package/src/tui/bindings/Style.res +123 -0
  122. package/src/tui/bindings/Style.res.mjs +2 -0
  123. package/src/tui/components/BufferedProgressBar.res +40 -0
  124. package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
  125. package/src/tui/components/CustomHooks.res +122 -0
  126. package/src/tui/components/CustomHooks.res.mjs +179 -0
  127. package/src/tui/components/Messages.res +41 -0
  128. package/src/tui/components/Messages.res.mjs +75 -0
  129. package/src/tui/components/SyncETA.res +193 -0
  130. package/src/tui/components/SyncETA.res.mjs +269 -0
  131. package/src/tui/components/TuiData.res +46 -0
  132. package/src/tui/components/TuiData.res.mjs +29 -0
  133. package/src/Platform.res +0 -140
  134. package/src/Platform.res.mjs +0 -170
  135. package/src/bindings/Ethers.gen.ts +0 -14
  136. /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
@@ -1,6 +1,6 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
- import * as Viem from "../bindings/Viem.res.mjs";
3
+ import * as Rest from "../vendored/Rest.res.mjs";
4
4
  import * as Utils from "../Utils.res.mjs";
5
5
  import * as Hrtime from "../bindings/Hrtime.res.mjs";
6
6
  import * as Js_exn from "rescript/lib/es6/js_exn.js";
@@ -15,7 +15,9 @@ import * as ErrorHandling from "../ErrorHandling.res.mjs";
15
15
  import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js";
16
16
  import * as HyperSyncClient from "./HyperSyncClient.res.mjs";
17
17
  import * as Caml_splice_call from "rescript/lib/es6/caml_splice_call.js";
18
+ import * as HyperSyncJsonApi from "./HyperSyncJsonApi.res.mjs";
18
19
  import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
20
+ import * as HyperSyncHeightStream from "./HyperSyncHeightStream.res.mjs";
19
21
 
20
22
  function getSelectionConfig(selection, chain) {
21
23
  var nonOptionalBlockFieldNames = new Set();
@@ -120,71 +122,16 @@ function memoGetSelectionConfig(chain) {
120
122
  };
121
123
  }
122
124
 
123
- async function makeInternal(client) {
124
- return {
125
- heightStream: await client.streamHeight(),
126
- currentHeight: 0,
127
- errMessage: undefined
128
- };
129
- }
130
-
131
- async function start(state, chainId) {
132
- while(true) {
133
- var height = await state.heightStream.recv();
134
- if (typeof height !== "object") {
135
- Logging.trace({
136
- msg: "HyperSync height stream is connected",
137
- chainId: chainId
138
- });
139
- state.errMessage = undefined;
140
- } else if (height.type === "Height") {
141
- state.currentHeight = height.height;
142
- } else {
143
- var errorMsg = height.errorMsg;
144
- Logging.trace({
145
- msg: "HyperSync height stream is reconnecting",
146
- err: errorMsg,
147
- delayMillis: height.delayMillis,
148
- chainId: chainId
149
- });
150
- state.errMessage = errorMsg;
151
- }
152
- };
153
- }
154
-
155
- async function make(client, chainId) {
156
- var state = await makeInternal(client);
157
- start(state, chainId);
158
- return state;
159
- }
160
-
161
- async function getHeight(state) {
162
- while(state.currentHeight === 0 && Belt_Option.isNone(state.errMessage)) {
163
- await Utils.delay(200);
164
- };
165
- var errMessage = state.errMessage;
166
- if (errMessage !== undefined) {
167
- return Js_exn.raiseError(errMessage);
168
- } else {
169
- return state.currentHeight;
170
- }
171
- }
172
-
173
- var HeightState = {
174
- make: make,
175
- getHeight: getHeight
176
- };
177
-
178
- function make$1(param) {
125
+ function make(param) {
179
126
  var lowercaseAddresses = param.lowercaseAddresses;
127
+ var apiToken = param.apiToken;
180
128
  var eventRouter = param.eventRouter;
181
- var shouldUseHypersyncClientDecoder = param.shouldUseHypersyncClientDecoder;
182
129
  var allEventSignatures = param.allEventSignatures;
183
130
  var endpointUrl = param.endpointUrl;
184
131
  var chain = param.chain;
185
132
  var getSelectionConfig = memoGetSelectionConfig(chain);
186
- var apiToken = Belt_Option.getWithDefault(param.apiToken, "3dc856dd-b0ea-494f-b27e-017b8b6b7e07");
187
- var client = HyperSyncClient.make(endpointUrl, apiToken, param.clientTimeoutMillis, param.clientMaxRetries, !lowercaseAddresses, param.serializationFormat, param.enableQueryCaching, undefined, undefined, undefined);
133
+ var apiToken$1 = apiToken !== undefined ? apiToken : Js_exn.raiseError("An API token is required for using HyperSync as a data-source.\nSet the ENVIO_API_TOKEN environment variable in your .env file.\nLearn more or get a free API token at: https://envio.dev/app/api-tokens");
134
+ var client = HyperSyncClient.make(endpointUrl, apiToken$1, param.clientTimeoutMillis, param.clientMaxRetries, !lowercaseAddresses, param.serializationFormat, param.enableQueryCaching, undefined, undefined, undefined);
188
135
  var hscDecoder = {
189
136
  contents: undefined
190
137
  };
@@ -199,7 +146,7 @@ function make$1(param) {
199
146
  }
200
147
  catch (raw_exn){
201
148
  var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
202
- return ErrorHandling.mkLogAndRaise(undefined, "Failed to instantiate a decoder from hypersync client, please double check your ABI or try using 'event_decoder: viem' config option", exn);
149
+ return ErrorHandling.mkLogAndRaise(undefined, "Failed to instantiate a decoder from hypersync client, please double check your ABI", exn);
203
150
  }
204
151
  if (lowercaseAddresses) {
205
152
  decoder$1.disableChecksummedAddresses();
@@ -229,11 +176,7 @@ function make$1(param) {
229
176
  }
230
177
  };
231
178
  };
232
- var contractNameAbiMapping = {};
233
- Belt_Array.forEach(param.contracts, (function (contract) {
234
- contractNameAbiMapping[contract.name] = contract.abi;
235
- }));
236
- var getItemsOrThrow = async function (fromBlock, toBlock, addressesByContractName, indexingContracts, currentBlockHeight, param, selection, retry, logger) {
179
+ var getItemsOrThrow = async function (fromBlock, toBlock, addressesByContractName, indexingContracts, knownHeight, param, selection, retry, logger) {
237
180
  var mkLogAndRaise = function (extra, extra$1) {
238
181
  return ErrorHandling.mkLogAndRaise(logger, extra, extra$1);
239
182
  };
@@ -275,7 +218,7 @@ function make$1(param) {
275
218
  _1: {
276
219
  TAG: "FailedGettingItems",
277
220
  exn: null,
278
- attemptedToBlock: Belt_Option.getWithDefault(toBlock, currentBlockHeight),
221
+ attemptedToBlock: Belt_Option.getWithDefault(toBlock, knownHeight),
279
222
  retry: tmp
280
223
  },
281
224
  Error: new Error()
@@ -286,7 +229,7 @@ function make$1(param) {
286
229
  _1: {
287
230
  TAG: "FailedGettingItems",
288
231
  exn: error,
289
- attemptedToBlock: Belt_Option.getWithDefault(toBlock, currentBlockHeight),
232
+ attemptedToBlock: Belt_Option.getWithDefault(toBlock, knownHeight),
290
233
  retry: {
291
234
  TAG: "WithBackoff",
292
235
  message: "Unexpected issue while fetching events from HyperSync client. Attempt a retry.",
@@ -297,7 +240,7 @@ function make$1(param) {
297
240
  };
298
241
  }
299
242
  var pageFetchTime = Hrtime.intFromMillis(Hrtime.toMillis(Hrtime.timeSince(startFetchingBatchTimeRef)));
300
- var currentBlockHeight$1 = pageUnsafe.archiveHeight;
243
+ var knownHeight$1 = pageUnsafe.archiveHeight;
301
244
  var heighestBlockQueried = pageUnsafe.nextBlock - 1 | 0;
302
245
  var match = pageUnsafe.rollbackGuard;
303
246
  var lastBlockQueriedPromise;
@@ -325,7 +268,7 @@ function make$1(param) {
325
268
  exit = 1;
326
269
  }
327
270
  if (exit === 1) {
328
- lastBlockQueriedPromise = HyperSync.queryBlockData(endpointUrl, apiToken, heighestBlockQueried, logger).then(function (res) {
271
+ lastBlockQueriedPromise = HyperSync.queryBlockData(endpointUrl, apiToken$1, heighestBlockQueried, logger).then(function (res) {
329
272
  if (res.TAG !== "Ok") {
330
273
  return mkLogAndRaise("Failed to query blockData for block " + String(heighestBlockQueried), HyperSync.queryErrorToMsq(res._0));
331
274
  }
@@ -343,67 +286,46 @@ function make$1(param) {
343
286
  }
344
287
  var parsingTimeRef = Hrtime.makeTimer();
345
288
  var parsedQueueItems = [];
346
- var handleDecodeFailure = function (eventConfig, decoder, logIndex, blockNumber, chainId, exn) {
347
- if (eventConfig.isWildcard) {
348
- return ;
349
- }
350
- var msg = "Event " + eventConfig.name + " was unexpectedly parsed as undefined";
351
- var logger$1 = Logging.createChildFrom(logger, {
352
- chainId: chainId,
353
- blockNumber: blockNumber,
354
- logIndex: logIndex,
355
- decoder: decoder
356
- });
357
- ErrorHandling.mkLogAndRaise(logger$1, msg, exn);
358
- };
359
- if (shouldUseHypersyncClientDecoder) {
360
- var parsedEvents;
361
- try {
362
- parsedEvents = await getHscDecoder().decodeEvents(pageUnsafe.events);
363
- }
364
- catch (raw_exn$1){
365
- var exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1);
366
- parsedEvents = mkLogAndRaise("Failed to parse events using hypersync client, please double check your ABI.", exn$1);
367
- }
368
- Belt_Array.forEachWithIndex(pageUnsafe.items, (function (index, item) {
369
- var block = item.block;
370
- var log = item.log;
371
- var topic0 = log.topics[0];
372
- var maybeEventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(topic0, log.topics.length), log.address, block.number, indexingContracts);
373
- var maybeDecodedEvent = parsedEvents[index];
374
- if (maybeEventConfig === undefined) {
375
- return ;
376
- }
377
- if (maybeDecodedEvent === null || maybeDecodedEvent === undefined) {
378
- maybeDecodedEvent === null;
379
- } else {
380
- parsedQueueItems.push(makeEventBatchQueueItem(item, maybeEventConfig.convertHyperSyncEventArgs(maybeDecodedEvent), maybeEventConfig));
381
- return ;
382
- }
383
- handleDecodeFailure(maybeEventConfig, "hypersync-client", log.logIndex, block.number, chain, {
384
- RE_EXN_ID: UndefinedValue
385
- });
386
- }));
387
- } else {
388
- Belt_Array.forEach(pageUnsafe.items, (function (item) {
389
- var block = item.block;
390
- var log = item.log;
391
- var topic0 = log.topics[0];
392
- var eventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(topic0, log.topics.length), log.address, block.number, indexingContracts);
393
- if (eventConfig === undefined) {
394
- return ;
395
- }
396
- var decodedEvent;
397
- try {
398
- decodedEvent = Viem.parseLogOrThrow(contractNameAbiMapping, eventConfig.contractName, log.topics, log.data);
399
- }
400
- catch (raw_exn){
401
- var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
402
- return handleDecodeFailure(eventConfig, "viem", log.logIndex, block.number, chain, exn);
403
- }
404
- parsedQueueItems.push(makeEventBatchQueueItem(item, decodedEvent.args, eventConfig));
405
- }));
289
+ var parsedEvents;
290
+ try {
291
+ parsedEvents = await getHscDecoder().decodeEvents(pageUnsafe.events);
292
+ }
293
+ catch (raw_exn$1){
294
+ var exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1);
295
+ parsedEvents = mkLogAndRaise("Failed to parse events using hypersync client, please double check your ABI.", exn$1);
406
296
  }
297
+ Belt_Array.forEachWithIndex(pageUnsafe.items, (function (index, item) {
298
+ var block = item.block;
299
+ var log = item.log;
300
+ var topic0 = log.topics[0];
301
+ var maybeEventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(topic0, log.topics.length), log.address, block.number, indexingContracts);
302
+ var maybeDecodedEvent = parsedEvents[index];
303
+ if (maybeEventConfig === undefined) {
304
+ return ;
305
+ }
306
+ if (maybeDecodedEvent === null || maybeDecodedEvent === undefined) {
307
+ maybeDecodedEvent === null;
308
+ } else {
309
+ parsedQueueItems.push(makeEventBatchQueueItem(item, maybeEventConfig.convertHyperSyncEventArgs(maybeDecodedEvent), maybeEventConfig));
310
+ return ;
311
+ }
312
+ var logIndex = log.logIndex;
313
+ var blockNumber = block.number;
314
+ var exn = {
315
+ RE_EXN_ID: UndefinedValue
316
+ };
317
+ if (maybeEventConfig.isWildcard) {
318
+ return ;
319
+ }
320
+ var msg = "Event " + maybeEventConfig.name + " was unexpectedly parsed as undefined";
321
+ var logger$1 = Logging.createChildFrom(logger, {
322
+ chainId: chain,
323
+ blockNumber: blockNumber,
324
+ logIndex: logIndex,
325
+ decoder: "hypersync-client"
326
+ });
327
+ ErrorHandling.mkLogAndRaise(logger$1, msg, exn);
328
+ }));
407
329
  var parsingTimeElapsed = Hrtime.intFromMillis(Hrtime.toMillis(Hrtime.timeSince(parsingTimeRef)));
408
330
  var rangeLastBlock = await lastBlockQueriedPromise;
409
331
  var reorgGuard_prevRangeLastBlock = Belt_Option.map(pageUnsafe.rollbackGuard, (function (v) {
@@ -425,7 +347,7 @@ function make$1(param) {
425
347
  "page fetch time (ms)": stats_page$unknownfetch$unknowntime$unknown$lparms$rpar
426
348
  };
427
349
  return {
428
- currentBlockHeight: currentBlockHeight$1,
350
+ knownHeight: knownHeight$1,
429
351
  reorgGuard: reorgGuard,
430
352
  parsedQueueItems: parsedQueueItems,
431
353
  fromBlockQueried: fromBlock,
@@ -435,44 +357,40 @@ function make$1(param) {
435
357
  };
436
358
  };
437
359
  var getBlockHashes = function (blockNumbers, logger) {
438
- return HyperSync.queryBlockDataMulti(endpointUrl, apiToken, blockNumbers, logger).then(HyperSync.mapExn);
360
+ return HyperSync.queryBlockDataMulti(endpointUrl, apiToken$1, blockNumbers, logger).then(HyperSync.mapExn);
439
361
  };
440
- var heightStatePromise = make(client, chain);
362
+ var jsonApiClient = Rest.client(endpointUrl, undefined);
441
363
  return {
442
364
  name: "HyperSync",
443
365
  sourceFor: "Sync",
444
366
  chain: chain,
445
367
  poweredByHyperSync: true,
446
- pollingInterval: 32,
368
+ pollingInterval: 100,
447
369
  getBlockHashes: getBlockHashes,
448
370
  getHeightOrThrow: (async function () {
449
- var heightState = await heightStatePromise;
450
- try {
451
- return await getHeight(heightState);
452
- }
453
- catch (raw_exn){
454
- var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
455
- if (exn.RE_EXN_ID === Js_exn.$$Error) {
456
- if (Belt_Option.getWithDefault(exn._1.message, "").includes("Your token is malformed. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens.")) {
457
- Logging.error("Your ENVIO_API_TOKEN is malformed. The indexer will not be able to fetch events. Update the token and restart the indexer using 'pnpm envio start'. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens");
458
- await new Promise((function (param, param$1) {
459
-
460
- }));
461
- return 0;
462
- }
463
- throw exn;
464
- }
465
- throw exn;
371
+ var height = await Rest.$$fetch(HyperSyncJsonApi.heightRoute, apiToken$1, jsonApiClient);
372
+ if (typeof height === "number") {
373
+ return height;
374
+ } else if (height === "Your token is malformed. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens.") {
375
+ Logging.error("Your ENVIO_API_TOKEN is malformed. The indexer will not be able to fetch events. Update the token and restart the indexer using 'pnpm envio start'. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens");
376
+ await new Promise((function (param, param$1) {
377
+
378
+ }));
379
+ return 0;
380
+ } else {
381
+ return Js_exn.raiseError(height);
466
382
  }
467
383
  }),
468
- getItemsOrThrow: getItemsOrThrow
384
+ getItemsOrThrow: getItemsOrThrow,
385
+ createHeightSubscription: (function (onHeight) {
386
+ return HyperSyncHeightStream.subscribe(endpointUrl, apiToken$1, onHeight);
387
+ })
469
388
  };
470
389
  }
471
390
 
472
391
  export {
473
392
  getSelectionConfig ,
474
393
  memoGetSelectionConfig ,
475
- HeightState ,
476
- make$1 as make,
394
+ make ,
477
395
  }
478
- /* Viem Not a pure module */
396
+ /* Rest Not a pure module */
@@ -179,3 +179,46 @@ module GetBlockByNumber = {
179
179
  module GetBlockHeight = {
180
180
  let route = makeRpcRoute("eth_blockNumber", S.tuple(_ => ()), hexIntSchema)
181
181
  }
182
+
183
+ module GetTransactionByHash = {
184
+ let transactionSchema = S.object((s): Internal.evmTransactionFields => {
185
+ // We already know the data so ignore the fields
186
+ // blockHash: ?s.field("blockHash", S.option(S.string)),
187
+ // blockNumber: ?s.field("blockNumber", S.option(hexIntSchema)),
188
+ // chainId: ?s.field("chainId", S.option(hexIntSchema)),
189
+ from: ?s.field("from", S.option(S.string->(Utils.magic: S.t<string> => S.t<Address.t>))),
190
+ to: ?s.field("to", S.option(S.string->(Utils.magic: S.t<string> => S.t<Address.t>))),
191
+ gas: ?s.field("gas", S.option(hexBigintSchema)),
192
+ gasPrice: ?s.field("gasPrice", S.option(hexBigintSchema)),
193
+ hash: ?s.field("hash", S.option(S.string)),
194
+ input: ?s.field("input", S.option(S.string)),
195
+ nonce: ?s.field("nonce", S.option(hexBigintSchema)),
196
+ transactionIndex: ?s.field("transactionIndex", S.option(hexIntSchema)),
197
+ value: ?s.field("value", S.option(hexBigintSchema)),
198
+ type_: ?s.field("type", S.option(hexIntSchema)),
199
+ // Signature fields - optional for ZKSync EIP-712 compatibility
200
+ v: ?s.field("v", S.option(S.string)),
201
+ r: ?s.field("r", S.option(S.string)),
202
+ s: ?s.field("s", S.option(S.string)),
203
+ yParity: ?s.field("yParity", S.option(S.string)),
204
+ // EIP-1559 fields
205
+ maxPriorityFeePerGas: ?s.field("maxPriorityFeePerGas", S.option(hexBigintSchema)),
206
+ maxFeePerGas: ?s.field("maxFeePerGas", S.option(hexBigintSchema)),
207
+ // EIP-4844 blob fields
208
+ maxFeePerBlobGas: ?s.field("maxFeePerBlobGas", S.option(hexBigintSchema)),
209
+ blobVersionedHashes: ?s.field("blobVersionedHashes", S.option(S.array(S.string))),
210
+ // TODO: Fields to add:
211
+ // pub access_list: Option<Vec<AccessList>>,
212
+ // pub authorization_list: Option<Vec<Authorization>>,
213
+ // // OP stack fields
214
+ // pub deposit_receipt_version: Option<Quantity>,
215
+ // pub mint: Option<Quantity>,
216
+ // pub source_hash: Option<Hash>,
217
+ })
218
+
219
+ let route = makeRpcRoute(
220
+ "eth_getTransactionByHash",
221
+ S.tuple1(S.string),
222
+ S.null(transactionSchema),
223
+ )
224
+ }
@@ -187,6 +187,36 @@ var GetBlockHeight = {
187
187
  route: route$2
188
188
  };
189
189
 
190
+ var transactionSchema = S$RescriptSchema.object(function (s) {
191
+ return {
192
+ from: s.f("from", S$RescriptSchema.option(S$RescriptSchema.string)),
193
+ to: s.f("to", S$RescriptSchema.option(S$RescriptSchema.string)),
194
+ gas: s.f("gas", S$RescriptSchema.option(hexBigintSchema)),
195
+ gasPrice: s.f("gasPrice", S$RescriptSchema.option(hexBigintSchema)),
196
+ hash: s.f("hash", S$RescriptSchema.option(S$RescriptSchema.string)),
197
+ input: s.f("input", S$RescriptSchema.option(S$RescriptSchema.string)),
198
+ nonce: s.f("nonce", S$RescriptSchema.option(hexBigintSchema)),
199
+ transactionIndex: s.f("transactionIndex", S$RescriptSchema.option(hexIntSchema)),
200
+ value: s.f("value", S$RescriptSchema.option(hexBigintSchema)),
201
+ v: s.f("v", S$RescriptSchema.option(S$RescriptSchema.string)),
202
+ r: s.f("r", S$RescriptSchema.option(S$RescriptSchema.string)),
203
+ s: s.f("s", S$RescriptSchema.option(S$RescriptSchema.string)),
204
+ yParity: s.f("yParity", S$RescriptSchema.option(S$RescriptSchema.string)),
205
+ maxPriorityFeePerGas: s.f("maxPriorityFeePerGas", S$RescriptSchema.option(hexBigintSchema)),
206
+ maxFeePerGas: s.f("maxFeePerGas", S$RescriptSchema.option(hexBigintSchema)),
207
+ maxFeePerBlobGas: s.f("maxFeePerBlobGas", S$RescriptSchema.option(hexBigintSchema)),
208
+ blobVersionedHashes: s.f("blobVersionedHashes", S$RescriptSchema.option(S$RescriptSchema.array(S$RescriptSchema.string))),
209
+ type: s.f("type", S$RescriptSchema.option(hexIntSchema))
210
+ };
211
+ });
212
+
213
+ var route$3 = makeRpcRoute("eth_getTransactionByHash", S$RescriptSchema.tuple1(S$RescriptSchema.string), S$RescriptSchema.$$null(transactionSchema));
214
+
215
+ var GetTransactionByHash = {
216
+ transactionSchema: transactionSchema,
217
+ route: route$3
218
+ };
219
+
190
220
  export {
191
221
  makeRpcRoute ,
192
222
  makeHexSchema ,
@@ -195,5 +225,6 @@ export {
195
225
  GetLogs ,
196
226
  GetBlockByNumber ,
197
227
  GetBlockHeight ,
228
+ GetTransactionByHash ,
198
229
  }
199
230
  /* hexBigintSchema Not a pure module */
@@ -468,25 +468,13 @@ type options = {
468
468
  syncConfig: Config.sourceSync,
469
469
  url: string,
470
470
  chain: ChainMap.Chain.t,
471
- contracts: array<Internal.evmContractConfig>,
472
471
  eventRouter: EventRouter.t<Internal.evmEventConfig>,
473
472
  allEventSignatures: array<string>,
474
- shouldUseHypersyncClientDecoder: bool,
475
473
  lowercaseAddresses: bool,
476
474
  }
477
475
 
478
476
  let make = (
479
- {
480
- sourceFor,
481
- syncConfig,
482
- url,
483
- chain,
484
- contracts,
485
- eventRouter,
486
- allEventSignatures,
487
- shouldUseHypersyncClientDecoder,
488
- lowercaseAddresses,
489
- }: options,
477
+ {sourceFor, syncConfig, url, chain, eventRouter, allEventSignatures, lowercaseAddresses}: options,
490
478
  ): t => {
491
479
  let urlHost = switch sanitizeUrl(url) {
492
480
  | None =>
@@ -503,10 +491,12 @@ let make = (
503
491
 
504
492
  let mutSuggestedBlockIntervals = Js.Dict.empty()
505
493
 
494
+ let client = Rest.client(url)
495
+
506
496
  let makeTransactionLoader = () =>
507
497
  LazyLoader.make(
508
498
  ~loaderFn=transactionHash =>
509
- provider->Ethers.JsonRpcProvider.getTransaction(~transactionHash),
499
+ Rpc.GetTransactionByHash.route->Rest.fetch(transactionHash, ~client),
510
500
  ~onError=(am, ~exn) => {
511
501
  Logging.error({
512
502
  "err": exn->Utils.prettifyExn,
@@ -560,16 +550,16 @@ let make = (
560
550
  )
561
551
  let getEventTransactionOrThrow = makeThrowingGetEventTransaction(
562
552
  ~getTransactionFields=Ethers.JsonRpcProvider.makeGetTransactionFields(
563
- ~getTransactionByHash=LazyLoader.get(transactionLoader.contents, _),
553
+ ~getTransactionByHash=async transactionHash => {
554
+ switch await transactionLoader.contents->LazyLoader.get(transactionHash) {
555
+ | Some(tx) => tx
556
+ | None => Js.Exn.raiseError(`Transaction not found for hash: ${transactionHash}`)
557
+ }
558
+ },
564
559
  ~lowercaseAddresses,
565
560
  ),
566
561
  )
567
562
 
568
- let contractNameAbiMapping = Js.Dict.empty()
569
- contracts->Belt.Array.forEach(contract => {
570
- contractNameAbiMapping->Js.Dict.set(contract.name, contract.abi)
571
- })
572
-
573
563
  let convertEthersLogToHyperSyncEvent = (log: Ethers.log): HyperSyncClient.ResponseTypes.event => {
574
564
  let hyperSyncLog: HyperSyncClient.ResponseTypes.log = {
575
565
  removed: log.removed->Option.getWithDefault(false),
@@ -601,7 +591,7 @@ let make = (
601
591
  ~toBlock,
602
592
  ~addressesByContractName,
603
593
  ~indexingContracts,
604
- ~currentBlockHeight,
594
+ ~knownHeight,
605
595
  ~partitionId,
606
596
  ~selection: FetchState.selection,
607
597
  ~retry as _,
@@ -621,8 +611,8 @@ let make = (
621
611
 
622
612
  // Always have a toBlock for an RPC worker
623
613
  let toBlock = switch toBlock {
624
- | Some(toBlock) => Pervasives.min(toBlock, currentBlockHeight)
625
- | None => currentBlockHeight
614
+ | Some(toBlock) => Pervasives.min(toBlock, knownHeight)
615
+ | None => knownHeight
626
616
  }
627
617
 
628
618
  let suggestedToBlock = Pervasives.min(fromBlock + suggestedBlockInterval - 1, toBlock)
@@ -669,26 +659,26 @@ let make = (
669
659
  )
670
660
  }
671
661
 
672
- let parsedQueueItems = if shouldUseHypersyncClientDecoder {
673
- // Convert Ethers logs to HyperSync events
674
- let hyperSyncEvents = logs->Belt.Array.map(convertEthersLogToHyperSyncEvent)
675
-
676
- // Decode using HyperSyncClient decoder
677
- let parsedEvents = try await getHscDecoder().decodeEvents(hyperSyncEvents) catch {
678
- | exn =>
679
- raise(
680
- Source.GetItemsError(
681
- FailedGettingItems({
682
- exn,
683
- attemptedToBlock: toBlock,
684
- retry: ImpossibleForTheQuery({
685
- message: "Failed to parse events using hypersync client decoder. Please double-check your ABI.",
686
- }),
662
+ // Convert Ethers logs to HyperSync events
663
+ let hyperSyncEvents = logs->Belt.Array.map(convertEthersLogToHyperSyncEvent)
664
+
665
+ // Decode using HyperSyncClient decoder
666
+ let parsedEvents = try await getHscDecoder().decodeEvents(hyperSyncEvents) catch {
667
+ | exn =>
668
+ raise(
669
+ Source.GetItemsError(
670
+ FailedGettingItems({
671
+ exn,
672
+ attemptedToBlock: toBlock,
673
+ retry: ImpossibleForTheQuery({
674
+ message: "Failed to parse events using hypersync client decoder. Please double-check your ABI.",
687
675
  }),
688
- ),
689
- )
690
- }
676
+ }),
677
+ ),
678
+ )
679
+ }
691
680
 
681
+ let parsedQueueItems =
692
682
  await logs
693
683
  ->Array.zip(parsedEvents)
694
684
  ->Array.keepMap(((
@@ -764,92 +754,6 @@ let make = (
764
754
  }
765
755
  })
766
756
  ->Promise.all
767
- } else {
768
- // Decode using Viem
769
- await logs
770
- ->Belt.Array.keepMap(log => {
771
- let topic0 = log.topics->Js.Array2.unsafe_get(0)
772
-
773
- switch eventRouter->EventRouter.get(
774
- ~tag=EventRouter.getEvmEventId(
775
- ~sighash=topic0->EvmTypes.Hex.toString,
776
- ~topicCount=log.topics->Array.length,
777
- ),
778
- ~indexingContracts,
779
- ~contractAddress=log.address,
780
- ~blockNumber=log.blockNumber,
781
- ) {
782
- | None => None //ignore events that aren't registered
783
- | Some(eventConfig) =>
784
- let blockNumber = log.blockNumber
785
- let logIndex = log.logIndex
786
- Some(
787
- (
788
- async () => {
789
- let (block, transaction) = try await Promise.all2((
790
- log->getEventBlockOrThrow,
791
- log->getEventTransactionOrThrow(~transactionSchema=eventConfig.transactionSchema),
792
- )) catch {
793
- // Promise.catch won't work here, because the error
794
- // might be thrown before a microtask is created
795
- | exn =>
796
- raise(
797
- Source.GetItemsError(
798
- FailedGettingFieldSelection({
799
- message: "Failed getting selected fields. Please double-check your RPC provider returns correct data.",
800
- exn,
801
- blockNumber,
802
- logIndex,
803
- }),
804
- ),
805
- )
806
- }
807
-
808
- let decodedEvent = try contractNameAbiMapping->Viem.parseLogOrThrow(
809
- ~contractName=eventConfig.contractName,
810
- ~topics=log.topics,
811
- ~data=log.data,
812
- ) catch {
813
- | exn =>
814
- raise(
815
- Source.GetItemsError(
816
- FailedGettingItems({
817
- exn,
818
- attemptedToBlock: toBlock,
819
- retry: ImpossibleForTheQuery({
820
- message: `Failed to parse event with viem, please double-check your ABI. Block number: ${blockNumber->Int.toString}, log index: ${logIndex->Int.toString}`,
821
- }),
822
- }),
823
- ),
824
- )
825
- }
826
-
827
- Internal.Event({
828
- eventConfig: (eventConfig :> Internal.eventConfig),
829
- timestamp: block.timestamp,
830
- blockNumber: block.number,
831
- chain,
832
- logIndex: log.logIndex,
833
- event: {
834
- chainId: chain->ChainMap.Chain.toChainId,
835
- params: decodedEvent.args,
836
- transaction,
837
- // Unreliably expect that the Ethers block fields match the types in HyperIndex
838
- // I assume this is wrong in some cases, so we need to fix it in the future
839
- block: block->(
840
- Utils.magic: Ethers.JsonRpcProvider.block => Internal.eventBlock
841
- ),
842
- srcAddress: log.address,
843
- logIndex: log.logIndex,
844
- }->Internal.fromGenericEvent,
845
- })
846
- }
847
- )(),
848
- )
849
- }
850
- })
851
- ->Promise.all
852
- }
853
757
 
854
758
  let optFirstBlockParent = await firstBlockParentPromise
855
759
 
@@ -874,7 +778,7 @@ let make = (
874
778
  stats: {
875
779
  totalTimeElapsed: totalTimeElapsed,
876
780
  },
877
- currentBlockHeight,
781
+ knownHeight,
878
782
  reorgGuard,
879
783
  fromBlockQueried: fromBlock,
880
784
  }
@@ -902,8 +806,6 @@ let make = (
902
806
  ->Promise.catch(exn => exn->Error->Promise.resolve)
903
807
  }
904
808
 
905
- let client = Rest.client(url)
906
-
907
809
  {
908
810
  name,
909
811
  sourceFor,