envio 3.3.0-alpha.10 → 3.3.0-alpha.11

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 (57) hide show
  1. package/licenses/CLA.md +35 -0
  2. package/licenses/EULA.md +67 -0
  3. package/licenses/LICENSE.md +45 -0
  4. package/licenses/README.md +35 -0
  5. package/package.json +9 -8
  6. package/src/Batch.res.mjs +1 -1
  7. package/src/ChainFetching.res +13 -10
  8. package/src/ChainFetching.res.mjs +3 -4
  9. package/src/ChainState.res +45 -30
  10. package/src/ChainState.res.mjs +22 -8
  11. package/src/ChainState.resi +5 -0
  12. package/src/Config.res +9 -5
  13. package/src/Config.res.mjs +2 -2
  14. package/src/Core.res +20 -0
  15. package/src/Core.res.mjs +12 -0
  16. package/src/CrossChainState.res +18 -1
  17. package/src/CrossChainState.res.mjs +2 -1
  18. package/src/EventConfigBuilder.res +21 -46
  19. package/src/EventConfigBuilder.res.mjs +18 -25
  20. package/src/EventProcessing.res +8 -5
  21. package/src/EventProcessing.res.mjs +2 -1
  22. package/src/FetchState.res +344 -263
  23. package/src/FetchState.res.mjs +209 -131
  24. package/src/HandlerRegister.res +3 -1
  25. package/src/HandlerRegister.res.mjs +3 -2
  26. package/src/Internal.res +11 -2
  27. package/src/LogSelection.res +0 -62
  28. package/src/LogSelection.res.mjs +0 -74
  29. package/src/RawEvent.res +2 -2
  30. package/src/SimulateDeadInputTracker.res +1 -1
  31. package/src/SimulateItems.res +38 -6
  32. package/src/SimulateItems.res.mjs +28 -9
  33. package/src/TestIndexer.res +2 -2
  34. package/src/TestIndexer.res.mjs +2 -2
  35. package/src/TopicFilter.res +1 -25
  36. package/src/TopicFilter.res.mjs +0 -74
  37. package/src/bindings/Viem.res +0 -5
  38. package/src/sources/EventRouter.res +0 -21
  39. package/src/sources/EventRouter.res.mjs +0 -12
  40. package/src/sources/EvmChain.res +2 -27
  41. package/src/sources/EvmChain.res.mjs +2 -23
  42. package/src/sources/EvmRpcClient.res +12 -15
  43. package/src/sources/EvmRpcClient.res.mjs +3 -3
  44. package/src/sources/HyperSync.res +9 -38
  45. package/src/sources/HyperSync.res.mjs +16 -28
  46. package/src/sources/HyperSync.resi +2 -2
  47. package/src/sources/HyperSyncClient.res +88 -11
  48. package/src/sources/HyperSyncClient.res.mjs +39 -6
  49. package/src/sources/HyperSyncSource.res +18 -199
  50. package/src/sources/HyperSyncSource.res.mjs +9 -128
  51. package/src/sources/Rpc.res +0 -32
  52. package/src/sources/Rpc.res.mjs +1 -46
  53. package/src/sources/RpcSource.res +29 -175
  54. package/src/sources/RpcSource.res.mjs +32 -110
  55. package/src/sources/SimulateSource.res +37 -19
  56. package/src/sources/SimulateSource.res.mjs +27 -10
  57. package/src/sources/SvmHyperSyncSource.res +3 -3
@@ -8,75 +8,6 @@ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js
8
8
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
9
9
  import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
10
10
 
11
- let MissingRequiredTopic0 = /* @__PURE__ */Primitive_exceptions.create("LogSelection.MissingRequiredTopic0");
12
-
13
- function makeTopicSelection(topic0, topic1Opt, topic2Opt, topic3Opt) {
14
- let topic1 = topic1Opt !== undefined ? topic1Opt : [];
15
- let topic2 = topic2Opt !== undefined ? topic2Opt : [];
16
- let topic3 = topic3Opt !== undefined ? topic3Opt : [];
17
- if (Utils.$$Array.isEmpty(topic0)) {
18
- return {
19
- TAG: "Error",
20
- _0: {
21
- RE_EXN_ID: MissingRequiredTopic0
22
- }
23
- };
24
- } else {
25
- return {
26
- TAG: "Ok",
27
- _0: {
28
- topic0: topic0,
29
- topic1: topic1,
30
- topic2: topic2,
31
- topic3: topic3
32
- }
33
- };
34
- }
35
- }
36
-
37
- function hasFilters(param) {
38
- return Stdlib_Option.isSome([
39
- param.topic1,
40
- param.topic2,
41
- param.topic3
42
- ].find(topic => !Utils.$$Array.isEmpty(topic)));
43
- }
44
-
45
- function compressTopicSelections(topicSelections) {
46
- let topic0sOfSelectionsWithoutFilters = [];
47
- let selectionsWithFilters = [];
48
- topicSelections.forEach(selection => {
49
- if (hasFilters(selection)) {
50
- selectionsWithFilters.push(selection);
51
- } else {
52
- selection.topic0.forEach(topic0 => {
53
- topic0sOfSelectionsWithoutFilters.push(topic0);
54
- });
55
- }
56
- });
57
- if (topic0sOfSelectionsWithoutFilters.length === 0) {
58
- return selectionsWithFilters;
59
- }
60
- let selectionWithoutFilters_topic1 = [];
61
- let selectionWithoutFilters_topic2 = [];
62
- let selectionWithoutFilters_topic3 = [];
63
- let selectionWithoutFilters = {
64
- topic0: topic0sOfSelectionsWithoutFilters,
65
- topic1: selectionWithoutFilters_topic1,
66
- topic2: selectionWithoutFilters_topic2,
67
- topic3: selectionWithoutFilters_topic3
68
- };
69
- return [selectionWithoutFilters].concat(selectionsWithFilters);
70
- }
71
-
72
- function make(addresses, topicSelections) {
73
- let topicSelections$1 = compressTopicSelections(topicSelections);
74
- return {
75
- addresses: addresses,
76
- topicSelections: topicSelections$1
77
- };
78
- }
79
-
80
11
  function materializeTopicFilter(filter, addresses) {
81
12
  if (filter.TAG === "Values") {
82
13
  return filter._0;
@@ -299,11 +230,6 @@ function parseWhereOrThrow(where, sighash, params, contractName, chainId, onEven
299
230
  }
300
231
 
301
232
  export {
302
- MissingRequiredTopic0,
303
- makeTopicSelection,
304
- hasFilters,
305
- compressTopicSelections,
306
- make,
307
233
  materializeTopicFilter,
308
234
  materializeTopicSelections,
309
235
  eventBlockRangeSchema,
package/src/RawEvent.res CHANGED
@@ -32,8 +32,8 @@ let make = (
32
32
  ~blockTimestamp: int,
33
33
  ~cleanUpRawEventFieldsInPlace: JSON.t => unit,
34
34
  ): Internal.rawEvent => {
35
- let {onEventRegistration, chain, blockNumber, logIndex} = eventItem
36
- let eventConfig = onEventRegistration.eventConfig
35
+ let {chain, blockNumber, logIndex} = eventItem
36
+ let eventConfig = eventItem.onEventRegistration.eventConfig
37
37
  let chainId = chain->ChainMap.Chain.toChainId
38
38
  let eventId = EventUtils.packEventIndex(~logIndex, ~blockNumber)
39
39
  let blockFields =
@@ -10,7 +10,7 @@ let itemKey = (item: Internal.item): string =>
10
10
  `${chain
11
11
  ->ChainMap.Chain.toChainId
12
12
  ->Int.toString}:${blockNumber->Int.toString}:${logIndex->Int.toString}`
13
- | _ => "" // non-event items are never a provided simulate input
13
+ | Internal.Block(_) => ""
14
14
  }
15
15
 
16
16
  // `index` is the item's position in its chain's `simulate` array, reported back
@@ -240,9 +240,12 @@ let deriveSrcAddress = (
240
240
  }
241
241
  }
242
242
 
243
- let parse = (~simulateItems: array<JSON.t>, ~config: Config.t, ~chainConfig: Config.chain): array<
244
- Internal.item,
245
- > => {
243
+ let parse = (
244
+ ~simulateItems: array<JSON.t>,
245
+ ~config: Config.t,
246
+ ~chainConfig: Config.chain,
247
+ ~onEventRegistrations: array<Internal.onEventRegistration>,
248
+ ): array<Internal.item> => {
246
249
  let chain = ChainMap.Chain.makeUnsafe(~chainId=chainConfig.id)
247
250
  let chainId = chainConfig.id
248
251
  let startBlock = chainConfig.startBlock
@@ -345,6 +348,11 @@ let parse = (~simulateItems: array<JSON.t>, ~config: Config.t, ~chainConfig: Con
345
348
  ~chainId,
346
349
  ~eventConfig,
347
350
  )
351
+ // Append into the registration array that the chain state will own and
352
+ // put that same registration object directly on the simulated item.
353
+ let onEventRegistrationIndex = onEventRegistrations->Array.length
354
+ let onEventRegistration = {...onEventRegistration, index: onEventRegistrationIndex}
355
+ onEventRegistrations->Array.push(onEventRegistration)->ignore
348
356
 
349
357
  items
350
358
  ->Array.push(
@@ -382,7 +390,11 @@ let parse = (~simulateItems: array<JSON.t>, ~config: Config.t, ~chainConfig: Con
382
390
 
383
391
  // Apply simulate source config from processConfig JSON to a Config.t
384
392
  // This patches chainMap entries that have simulate items with CustomSources
385
- let patchConfig = (~config: Config.t, ~processConfig: JSON.t): Config.t => {
393
+ let patchConfig = (
394
+ ~config: Config.t,
395
+ ~processConfig: JSON.t,
396
+ ~registrationsByChainId: HandlerRegister.registrationsByChainId,
397
+ ): Config.t => {
386
398
  let processChains: option<dict<JSON.t>> =
387
399
  (processConfig->(Utils.magic: JSON.t => {..}))["chains"]->Nullable.toOption
388
400
  switch processChains {
@@ -395,11 +407,31 @@ let patchConfig = (~config: Config.t, ~processConfig: JSON.t): Config.t => {
395
407
  let simulateRaw: option<array<JSON.t>> = raw["simulate"]->Nullable.toOption
396
408
  switch simulateRaw {
397
409
  | Some(simulateItems) =>
398
- let items = parse(~simulateItems, ~config, ~chainConfig)
410
+ let chainRegistrations = switch registrationsByChainId->Utils.Dict.dangerouslyGetNonOption(
411
+ chainIdStr,
412
+ ) {
413
+ | Some(registrations) => registrations
414
+ | None =>
415
+ let registrations: HandlerRegister.chainRegistrations = {
416
+ onEventRegistrations: [],
417
+ onBlockRegistrations: [],
418
+ }
419
+ registrationsByChainId->Dict.set(chainIdStr, registrations)
420
+ registrations
421
+ }
399
422
  let startBlock: int = raw["startBlock"]->(Utils.magic: 'a => int)
400
423
  let endBlock: int = raw["endBlock"]->(Utils.magic: 'a => int)
424
+ // Parse with the process's startBlock so items default into the range
425
+ // the source will be queried over; the source now filters by range.
426
+ let chainConfig = {...chainConfig, startBlock, endBlock}
427
+ let items = parse(
428
+ ~simulateItems,
429
+ ~config,
430
+ ~chainConfig,
431
+ ~onEventRegistrations=chainRegistrations.onEventRegistrations,
432
+ )
401
433
  let source = SimulateSource.make(~items, ~endBlock, ~chain)
402
- {...chainConfig, startBlock, endBlock, sourceConfig: Config.CustomSources([source])}
434
+ {...chainConfig, sourceConfig: Config.CustomSources([source])}
403
435
  | None => chainConfig
404
436
  }
405
437
  | None => chainConfig
@@ -167,7 +167,7 @@ function deriveSrcAddress(providedSrcAddress, eventConfig, chainConfig, config)
167
167
  }
168
168
  }
169
169
 
170
- function parse(simulateItems, config, chainConfig) {
170
+ function parse(simulateItems, config, chainConfig, onEventRegistrations) {
171
171
  let chain = ChainMap.Chain.makeUnsafe(chainConfig.id);
172
172
  let chainId = chainConfig.id;
173
173
  let startBlock = chainConfig.startBlock;
@@ -254,9 +254,13 @@ function parse(simulateItems, config, chainConfig) {
254
254
  seenCoordinates[coordinate] = itemIndex;
255
255
  }
256
256
  let onEventRegistration = HandlerRegister.buildOnEventRegistration(config, chainId, eventConfig, undefined);
257
+ let onEventRegistrationIndex = onEventRegistrations.length;
258
+ let newrecord = {...onEventRegistration};
259
+ newrecord.index = onEventRegistrationIndex;
260
+ onEventRegistrations.push(newrecord);
257
261
  items.push({
258
262
  kind: 0,
259
- onEventRegistration: onEventRegistration,
263
+ onEventRegistration: newrecord,
260
264
  chain: chain,
261
265
  blockNumber: blockNumber,
262
266
  logIndex: logIndex,
@@ -276,7 +280,7 @@ function parse(simulateItems, config, chainConfig) {
276
280
  return items;
277
281
  }
278
282
 
279
- function patchConfig(config, processConfig) {
283
+ function patchConfig(config, processConfig, registrationsByChainId) {
280
284
  let processChains = processConfig.chains;
281
285
  if (processChains == null) {
282
286
  return config;
@@ -291,18 +295,33 @@ function patchConfig(config, processConfig) {
291
295
  if (simulateRaw == null) {
292
296
  return chainConfig;
293
297
  }
294
- let items = parse(simulateRaw, config, chainConfig);
298
+ let registrations = registrationsByChainId[chainIdStr];
299
+ let chainRegistrations;
300
+ if (registrations !== undefined) {
301
+ chainRegistrations = registrations;
302
+ } else {
303
+ let registrations_onEventRegistrations = [];
304
+ let registrations_onBlockRegistrations = [];
305
+ let registrations$1 = {
306
+ onEventRegistrations: registrations_onEventRegistrations,
307
+ onBlockRegistrations: registrations_onBlockRegistrations
308
+ };
309
+ registrationsByChainId[chainIdStr] = registrations$1;
310
+ chainRegistrations = registrations$1;
311
+ }
295
312
  let startBlock = processChainJson.startBlock;
296
313
  let endBlock = processChainJson.endBlock;
297
- let source = SimulateSource.make(items, endBlock, chain);
298
314
  let newrecord = {...chainConfig};
299
- newrecord.sourceConfig = {
315
+ newrecord.endBlock = endBlock;
316
+ newrecord.startBlock = startBlock;
317
+ let items = parse(simulateRaw, config, newrecord, chainRegistrations.onEventRegistrations);
318
+ let source = SimulateSource.make(items, endBlock, chain);
319
+ let newrecord$1 = {...newrecord};
320
+ newrecord$1.sourceConfig = {
300
321
  TAG: "CustomSources",
301
322
  _0: [source]
302
323
  };
303
- newrecord.endBlock = endBlock;
304
- newrecord.startBlock = startBlock;
305
- return newrecord;
324
+ return newrecord$1;
306
325
  });
307
326
  return {
308
327
  name: config.name,
@@ -863,8 +863,8 @@ let initTestWorker = () => {
863
863
  | Some(_) => ()
864
864
  }
865
865
 
866
- let patchConfig = (config: Config.t, _registrations) => {
867
- let config = SimulateItems.patchConfig(~config, ~processConfig)
866
+ let patchConfig = (config: Config.t, registrationsByChainId) => {
867
+ let config = SimulateItems.patchConfig(~config, ~processConfig, ~registrationsByChainId)
868
868
 
869
869
  // In auto-exit mode, set batchSize=1 to process one block checkpoint at a time
870
870
  if exitAfterFirstEventBlock {
@@ -612,8 +612,8 @@ function initTestWorker() {
612
612
  } else {
613
613
  Logging.setLogLevel("silent");
614
614
  }
615
- let patchConfig = (config, _registrations) => {
616
- let config$1 = SimulateItems.patchConfig(config, processConfig);
615
+ let patchConfig = (config, registrationsByChainId) => {
616
+ let config$1 = SimulateItems.patchConfig(config, processConfig, registrationsByChainId);
617
617
  if (exitAfterFirstEventBlock) {
618
618
  return {
619
619
  name: config$1.name,
@@ -1,27 +1,3 @@
1
- let toTwosComplement = (num: bigint, ~bytesLen: int) => {
2
- let maxValue = 1n->BigInt.shiftLeft(BigInt.fromInt(bytesLen * 8))
3
- let mask = maxValue->BigInt.sub(1n)
4
- num->BigInt.add(maxValue)->BigInt.bitwiseAnd(mask)
5
- }
6
-
7
- let fromSignedBigInt = val => {
8
- let bytesLen = 32
9
- let val = val >= 0n ? val : val->toTwosComplement(~bytesLen)
10
- val->Viem.bigintToHex(~options={size: bytesLen})
11
- }
12
-
13
1
  type hex = EvmTypes.Hex.t
14
- //bytes currently does not work with genType and we also currently generate bytes as a string type
15
- type bytesHex = string
16
- let keccak256 = Viem.keccak256
17
- let bytesToHex = Viem.bytesToHex
18
- let concat = Viem.concat
19
- let castToHexUnsafe: 'a => hex = val => val->(Utils.magic: 'a => hex)
20
- let fromBigInt: bigint => hex = val => val->Viem.bigintToHex(~options={size: 32})
21
- let fromDynamicString: string => hex = val => val->(Utils.magic: string => hex)->keccak256
22
- let fromString: string => hex = val => val->Viem.stringToHex(~options={size: 32})
2
+
23
3
  let fromAddress: Address.t => hex = addr => addr->(Utils.magic: Address.t => hex)->Viem.pad
24
- let fromDynamicBytes: bytesHex => hex = bytes => bytes->(Utils.magic: bytesHex => hex)->keccak256
25
- let fromBytes: bytesHex => hex = bytes =>
26
- bytes->(Utils.magic: bytesHex => Uint8Array.t)->Viem.bytesToHex(~options={size: 32})
27
- let fromBool: bool => hex = b => b->Viem.boolToHex(~options={size: 32})
@@ -1,86 +1,12 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
3
  import * as Viem from "viem";
4
- import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
5
-
6
- function toTwosComplement(num, bytesLen) {
7
- let maxValue = (1n << BigInt((bytesLen << 3)));
8
- let mask = maxValue - 1n;
9
- return num + maxValue & mask;
10
- }
11
-
12
- function fromSignedBigInt(val) {
13
- let val$1 = val >= 0n ? val : toTwosComplement(val, 32);
14
- return Viem.numberToHex(val$1, {
15
- size: 32
16
- });
17
- }
18
-
19
- function keccak256(prim) {
20
- return Viem.keccak256(prim);
21
- }
22
-
23
- function bytesToHex(prim0, prim1) {
24
- return Viem.bytesToHex(prim0, prim1 !== undefined ? Primitive_option.valFromOption(prim1) : undefined);
25
- }
26
-
27
- function concat(prim) {
28
- return Viem.concat(prim);
29
- }
30
-
31
- function castToHexUnsafe(val) {
32
- return val;
33
- }
34
-
35
- function fromBigInt(val) {
36
- return Viem.numberToHex(val, {
37
- size: 32
38
- });
39
- }
40
-
41
- function fromDynamicString(val) {
42
- return Viem.keccak256(val);
43
- }
44
-
45
- function fromString(val) {
46
- return Viem.stringToHex(val, {
47
- size: 32
48
- });
49
- }
50
4
 
51
5
  function fromAddress(addr) {
52
6
  return Viem.pad(addr);
53
7
  }
54
8
 
55
- function fromDynamicBytes(bytes) {
56
- return Viem.keccak256(bytes);
57
- }
58
-
59
- function fromBytes(bytes) {
60
- return Viem.bytesToHex(bytes, {
61
- size: 32
62
- });
63
- }
64
-
65
- function fromBool(b) {
66
- return Viem.boolToHex(b, {
67
- size: 32
68
- });
69
- }
70
-
71
9
  export {
72
- toTwosComplement,
73
- fromSignedBigInt,
74
- keccak256,
75
- bytesToHex,
76
- concat,
77
- castToHexUnsafe,
78
- fromBigInt,
79
- fromDynamicString,
80
- fromString,
81
10
  fromAddress,
82
- fromDynamicBytes,
83
- fromBytes,
84
- fromBool,
85
11
  }
86
12
  /* viem Not a pure module */
@@ -1,11 +1,6 @@
1
1
  type hex = EvmTypes.Hex.t
2
2
  @module("viem") external toHex: 'a => hex = "toHex"
3
- @module("viem") external keccak256: hex => hex = "keccak256"
4
3
  @module("viem") external pad: hex => hex = "pad"
5
4
 
6
5
  type sizeOptions = {size: int}
7
6
  @module("viem") external bigintToHex: (bigint, ~options: sizeOptions=?) => hex = "numberToHex"
8
- @module("viem") external stringToHex: (string, ~options: sizeOptions=?) => hex = "stringToHex"
9
- @module("viem") external boolToHex: (bool, ~options: sizeOptions=?) => hex = "boolToHex"
10
- @module("viem") external bytesToHex: (Uint8Array.t, ~options: sizeOptions=?) => hex = "bytesToHex"
11
- @module("viem") external concat: array<hex> => hex = "concat"
@@ -92,27 +92,6 @@ let get = (router: t<'a>, ~tag, ~contractAddress, ~contractNameByAddress) => {
92
92
  }
93
93
  }
94
94
 
95
- let getEvmEventId = (~sighash, ~topicCount) => {
96
- sighash ++ "_" ++ topicCount->Int.toString
97
- }
98
-
99
- let fromEvmEventModsOrThrow = (events: array<Internal.evmOnEventRegistration>, ~chain): t<
100
- Internal.evmOnEventRegistration,
101
- > => {
102
- let router = empty()
103
- events->Array.forEach(config => {
104
- router->addOrThrow(
105
- config.eventConfig.id,
106
- config,
107
- ~contractName=config.eventConfig.contractName,
108
- ~eventName=config.eventConfig.name,
109
- ~chain,
110
- ~isWildcard=config.isWildcard,
111
- )
112
- })
113
- router
114
- }
115
-
116
95
  /** Dispatch key for SVM instructions. `None` matches any instruction in the
117
96
  program (lowest priority). */
118
97
  let getSvmEventId = (~programId: SvmTypes.Pubkey.t, ~discriminator: option<string>) =>
@@ -97,16 +97,6 @@ function get$1(router, tag, contractAddress, contractNameByAddress) {
97
97
  }
98
98
  }
99
99
 
100
- function getEvmEventId(sighash, topicCount) {
101
- return sighash + "_" + topicCount.toString();
102
- }
103
-
104
- function fromEvmEventModsOrThrow(events, chain) {
105
- let router = {};
106
- events.forEach(config => addOrThrow$1(router, config.eventConfig.id, config, config.eventConfig.contractName, config.isWildcard, config.eventConfig.name, chain));
107
- return router;
108
- }
109
-
110
100
  function getSvmEventId(programId, discriminator) {
111
101
  if (discriminator !== undefined) {
112
102
  return programId + "_" + discriminator;
@@ -157,8 +147,6 @@ export {
157
147
  empty$1 as empty,
158
148
  addOrThrow$1 as addOrThrow,
159
149
  get$1 as get,
160
- getEvmEventId,
161
- fromEvmEventModsOrThrow,
162
150
  getSvmEventId,
163
151
  fromSvmEventConfigsOrThrow,
164
152
  }
@@ -39,25 +39,6 @@ let getSyncConfig = (
39
39
  }
40
40
  }
41
41
 
42
- let collectEventParams = (onEventRegistrations: array<Internal.evmOnEventRegistration>): array<
43
- HyperSyncClient.Decoder.eventParamsInput,
44
- > => {
45
- let result = []
46
- onEventRegistrations->Array.forEach(reg => {
47
- let event = reg.eventConfig->(Utils.magic: Internal.eventConfig => Internal.evmEventConfig)
48
- result
49
- ->Array.push({
50
- HyperSyncClient.Decoder.sighash: event.sighash,
51
- topicCount: event.topicCount,
52
- eventName: event.name,
53
- contractName: event.contractName,
54
- params: event.paramsMetadata,
55
- })
56
- ->ignore
57
- })
58
- result
59
- }
60
-
61
42
  let makeSources = (
62
43
  ~chain,
63
44
  ~onEventRegistrations: array<Internal.evmOnEventRegistration>,
@@ -65,17 +46,12 @@ let makeSources = (
65
46
  ~rpcs: array<rpc>,
66
47
  ~lowercaseAddresses,
67
48
  ) => {
68
- let eventRouter = onEventRegistrations->EventRouter.fromEvmEventModsOrThrow(~chain)
69
-
70
- let allEventParams = collectEventParams(onEventRegistrations)
71
-
72
49
  let sources = switch hyperSync {
73
50
  | Some(endpointUrl) => [
74
51
  HyperSyncSource.make({
75
52
  chain,
76
53
  endpointUrl,
77
- allEventParams,
78
- eventRouter,
54
+ onEventRegistrations,
79
55
  apiToken: Env.envioApiToken,
80
56
  clientTimeoutMillis: Env.hyperSyncClientTimeoutMillis,
81
57
  lowercaseAddresses,
@@ -92,8 +68,7 @@ let makeSources = (
92
68
  sourceFor,
93
69
  syncConfig: getSyncConfig(syncConfig->Option.getOr({})),
94
70
  url,
95
- eventRouter,
96
- allEventParams,
71
+ onEventRegistrations,
97
72
  lowercaseAddresses,
98
73
  ?ws,
99
74
  ?headers,
@@ -2,7 +2,6 @@
2
2
 
3
3
  import * as Env from "../Env.res.mjs";
4
4
  import * as RpcSource from "./RpcSource.res.mjs";
5
- import * as EventRouter from "./EventRouter.res.mjs";
6
5
  import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
7
6
  import * as HyperSyncSource from "./HyperSyncSource.res.mjs";
8
7
 
@@ -20,29 +19,11 @@ function getSyncConfig(param) {
20
19
  };
21
20
  }
22
21
 
23
- function collectEventParams(onEventRegistrations) {
24
- let result = [];
25
- onEventRegistrations.forEach(reg => {
26
- let event = reg.eventConfig;
27
- result.push({
28
- sighash: event.sighash,
29
- topicCount: event.topicCount,
30
- eventName: event.name,
31
- contractName: event.contractName,
32
- params: event.paramsMetadata
33
- });
34
- });
35
- return result;
36
- }
37
-
38
22
  function makeSources(chain, onEventRegistrations, hyperSync, rpcs, lowercaseAddresses) {
39
- let eventRouter = EventRouter.fromEvmEventModsOrThrow(onEventRegistrations, chain);
40
- let allEventParams = collectEventParams(onEventRegistrations);
41
23
  let sources = hyperSync !== undefined ? [HyperSyncSource.make({
42
24
  chain: chain,
43
25
  endpointUrl: hyperSync,
44
- allEventParams: allEventParams,
45
- eventRouter: eventRouter,
26
+ onEventRegistrations: onEventRegistrations,
46
27
  apiToken: Env.envioApiToken,
47
28
  clientTimeoutMillis: Env.hyperSyncClientTimeoutMillis,
48
29
  lowercaseAddresses: lowercaseAddresses,
@@ -56,8 +37,7 @@ function makeSources(chain, onEventRegistrations, hyperSync, rpcs, lowercaseAddr
56
37
  syncConfig: getSyncConfig(Stdlib_Option.getOr(param.syncConfig, {})),
57
38
  url: param.url,
58
39
  chain: chain,
59
- eventRouter: eventRouter,
60
- allEventParams: allEventParams,
40
+ onEventRegistrations: onEventRegistrations,
61
41
  lowercaseAddresses: lowercaseAddresses,
62
42
  ws: param.ws,
63
43
  headers: param.headers
@@ -69,7 +49,6 @@ function makeSources(chain, onEventRegistrations, hyperSync, rpcs, lowercaseAddr
69
49
 
70
50
  export {
71
51
  getSyncConfig,
72
- collectEventParams,
73
52
  makeSources,
74
53
  }
75
54
  /* Env Not a pure module */
@@ -10,26 +10,23 @@ type cfg = {
10
10
  queryTimeoutMillis: int,
11
11
  }
12
12
 
13
- // Decoded `params` keyed by contract name, matching the HyperSync decoder's
14
- // shape so the caller routes by address then picks its contract's params.
13
+ // Only logs that resolved to a registration cross the boundary, each carrying
14
+ // its registration's chain-scoped index.
15
15
  type rpcEventItem = {
16
16
  log: Rpc.GetLogs.log,
17
- params: Nullable.t<dict<Internal.eventParams>>,
18
- }
19
-
20
- // `addresses` omitted matches any address (a wildcard selection). Each `topics`
21
- // position is `null` (match any) or a list of accepted topic hashes; the
22
- // single-match case is a one-element list.
23
- type logSelectionInput = {
24
- addresses?: array<Address.t>,
25
- topics: array<Nullable.t<array<string>>>,
17
+ onEventRegistrationIndex: int,
18
+ params: Internal.eventParams,
26
19
  }
27
20
 
28
21
  type nextPageParams = {
29
22
  fromBlock: int,
30
23
  toBlockCeiling: int,
31
- logSelections: array<logSelectionInput>,
32
24
  partitionId: string,
25
+ // The partition's registration selection, by chain-scoped index. Log
26
+ // selections and the routing index are derived on the Rust side from the
27
+ // registrations passed at construction.
28
+ registrationIndexes: array<int>,
29
+ addressesByContractName: dict<array<Address.t>>,
33
30
  }
34
31
 
35
32
  type nextPageResponse = {
@@ -48,7 +45,7 @@ type t = {
48
45
  external classNew: (
49
46
  Core.evmRpcClientCtor,
50
47
  cfg,
51
- array<HyperSyncClient.Decoder.eventParamsInput>,
48
+ array<HyperSyncClient.Registration.input>,
52
49
  ~checksumAddresses: bool,
53
50
  ) => t = "new"
54
51
 
@@ -87,7 +84,7 @@ let make = (
87
84
  ~syncConfig: Config.sourceSync,
88
85
  ~httpReqTimeoutMillis=?,
89
86
  ~headers=?,
90
- ~allEventParams=[],
87
+ ~eventRegistrations=[],
91
88
  ) => {
92
89
  let client = Core.getAddon().evmRpcClient->classNew(
93
90
  {
@@ -101,7 +98,7 @@ let make = (
101
98
  backoffMillis: syncConfig.backoffMillis,
102
99
  queryTimeoutMillis: syncConfig.queryTimeoutMillis,
103
100
  },
104
- allEventParams,
101
+ eventRegistrations,
105
102
  ~checksumAddresses,
106
103
  )
107
104
  {
@@ -46,8 +46,8 @@ function coerceErrorOrThrow(exn) {
46
46
  throw exn;
47
47
  }
48
48
 
49
- function make(url, checksumAddresses, syncConfig, httpReqTimeoutMillis, headers, allEventParamsOpt) {
50
- let allEventParams = allEventParamsOpt !== undefined ? allEventParamsOpt : [];
49
+ function make(url, checksumAddresses, syncConfig, httpReqTimeoutMillis, headers, eventRegistrationsOpt) {
50
+ let eventRegistrations = eventRegistrationsOpt !== undefined ? eventRegistrationsOpt : [];
51
51
  let client = Core.getAddon().EvmRpcClient.new({
52
52
  url: url,
53
53
  httpReqTimeoutMillis: httpReqTimeoutMillis,
@@ -58,7 +58,7 @@ function make(url, checksumAddresses, syncConfig, httpReqTimeoutMillis, headers,
58
58
  intervalCeiling: syncConfig.intervalCeiling,
59
59
  backoffMillis: syncConfig.backoffMillis,
60
60
  queryTimeoutMillis: syncConfig.queryTimeoutMillis
61
- }, allEventParams, checksumAddresses);
61
+ }, eventRegistrations, checksumAddresses);
62
62
  return {
63
63
  getHeight: () => Stdlib_Promise.$$catch(client.getHeight(), coerceErrorOrThrow),
64
64
  getNextPage: params => Stdlib_Promise.$$catch(client.getNextPage(params), coerceErrorOrThrow)