envio 3.3.0-alpha.1 → 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 (143) hide show
  1. package/evm.schema.json +10 -0
  2. package/index.d.ts +45 -25
  3. package/licenses/CLA.md +35 -0
  4. package/licenses/EULA.md +67 -0
  5. package/licenses/LICENSE.md +45 -0
  6. package/licenses/README.md +35 -0
  7. package/package.json +10 -9
  8. package/src/Address.res +5 -2
  9. package/src/Address.res.mjs +3 -1
  10. package/src/Api.res +1 -1
  11. package/src/Api.res.mjs +1 -1
  12. package/src/Batch.res +0 -6
  13. package/src/Batch.res.mjs +1 -12
  14. package/src/BatchProcessing.res +7 -12
  15. package/src/BatchProcessing.res.mjs +8 -7
  16. package/src/Bin.res +3 -0
  17. package/src/Bin.res.mjs +4 -0
  18. package/src/ChainFetching.res +53 -16
  19. package/src/ChainFetching.res.mjs +37 -19
  20. package/src/ChainMetadata.res +1 -11
  21. package/src/ChainMetadata.res.mjs +1 -10
  22. package/src/ChainState.res +630 -161
  23. package/src/ChainState.res.mjs +438 -101
  24. package/src/ChainState.resi +77 -4
  25. package/src/Config.res +70 -38
  26. package/src/Config.res.mjs +52 -12
  27. package/src/ContractRegisterContext.res +2 -12
  28. package/src/ContractRegisterContext.res.mjs +3 -5
  29. package/src/Core.res +34 -3
  30. package/src/Core.res.mjs +12 -0
  31. package/src/CrossChainState.res +130 -89
  32. package/src/CrossChainState.res.mjs +66 -61
  33. package/src/CrossChainState.resi +1 -1
  34. package/src/Ecosystem.res +5 -6
  35. package/src/Ecosystem.res.mjs +3 -3
  36. package/src/Envio.res +17 -11
  37. package/src/EnvioGlobal.res +53 -0
  38. package/src/EnvioGlobal.res.mjs +31 -0
  39. package/src/EventConfigBuilder.res +191 -127
  40. package/src/EventConfigBuilder.res.mjs +116 -66
  41. package/src/EventProcessing.res +77 -28
  42. package/src/EventProcessing.res.mjs +56 -29
  43. package/src/ExitOnCaughtUp.res +10 -2
  44. package/src/ExitOnCaughtUp.res.mjs +10 -1
  45. package/src/FetchState.res +684 -415
  46. package/src/FetchState.res.mjs +505 -486
  47. package/src/HandlerLoader.res +8 -104
  48. package/src/HandlerLoader.res.mjs +2 -81
  49. package/src/HandlerRegister.res +520 -144
  50. package/src/HandlerRegister.res.mjs +286 -133
  51. package/src/HandlerRegister.resi +24 -8
  52. package/src/IndexerState.res +10 -3
  53. package/src/IndexerState.res.mjs +11 -4
  54. package/src/IndexerState.resi +2 -1
  55. package/src/IndexingAddresses.res +108 -0
  56. package/src/IndexingAddresses.res.mjs +101 -0
  57. package/src/IndexingAddresses.resi +34 -0
  58. package/src/Internal.res +166 -48
  59. package/src/Internal.res.mjs +30 -2
  60. package/src/LoadLayer.res +5 -5
  61. package/src/LoadLayer.res.mjs +6 -6
  62. package/src/LogSelection.res +92 -217
  63. package/src/LogSelection.res.mjs +95 -184
  64. package/src/Main.res +71 -236
  65. package/src/Main.res.mjs +60 -145
  66. package/src/Metrics.res +74 -0
  67. package/src/Metrics.res.mjs +75 -0
  68. package/src/PgStorage.res +4 -4
  69. package/src/PgStorage.res.mjs +5 -5
  70. package/src/Prometheus.res +10 -63
  71. package/src/Prometheus.res.mjs +124 -171
  72. package/src/PruneStaleHistory.res +2 -2
  73. package/src/PruneStaleHistory.res.mjs +3 -3
  74. package/src/RawEvent.res +7 -2
  75. package/src/RawEvent.res.mjs +4 -4
  76. package/src/Rollback.res +3 -3
  77. package/src/Rollback.res.mjs +4 -4
  78. package/src/RollbackCommit.res +4 -1
  79. package/src/RollbackCommit.res.mjs +3 -2
  80. package/src/SimulateDeadInputTracker.res +85 -0
  81. package/src/SimulateDeadInputTracker.res.mjs +73 -0
  82. package/src/SimulateDeadInputTracker.resi +12 -0
  83. package/src/SimulateItems.res +128 -28
  84. package/src/SimulateItems.res.mjs +82 -40
  85. package/src/TestIndexer.res +55 -41
  86. package/src/TestIndexer.res.mjs +39 -32
  87. package/src/TopicFilter.res +1 -25
  88. package/src/TopicFilter.res.mjs +0 -74
  89. package/src/bindings/Performance.res +7 -0
  90. package/src/bindings/Performance.res.mjs +21 -0
  91. package/src/bindings/Performance.resi +7 -0
  92. package/src/bindings/Viem.res +0 -46
  93. package/src/bindings/Viem.res.mjs +1 -43
  94. package/src/sources/BlockStore.res +46 -0
  95. package/src/sources/BlockStore.res.mjs +24 -0
  96. package/src/sources/EventRouter.res +31 -49
  97. package/src/sources/EventRouter.res.mjs +12 -25
  98. package/src/sources/Evm.res +83 -72
  99. package/src/sources/Evm.res.mjs +53 -69
  100. package/src/sources/EvmChain.res +7 -34
  101. package/src/sources/EvmChain.res.mjs +6 -27
  102. package/src/sources/EvmRpcClient.res +71 -5
  103. package/src/sources/EvmRpcClient.res.mjs +13 -4
  104. package/src/sources/FieldMask.res +39 -0
  105. package/src/sources/FieldMask.res.mjs +42 -0
  106. package/src/sources/Fuel.res +9 -6
  107. package/src/sources/Fuel.res.mjs +5 -10
  108. package/src/sources/HyperFuelSource.res +46 -50
  109. package/src/sources/HyperFuelSource.res.mjs +64 -54
  110. package/src/sources/HyperSync.res +45 -42
  111. package/src/sources/HyperSync.res.mjs +68 -60
  112. package/src/sources/HyperSync.resi +14 -4
  113. package/src/sources/HyperSyncClient.res +107 -119
  114. package/src/sources/HyperSyncClient.res.mjs +36 -31
  115. package/src/sources/HyperSyncHeightStream.res +1 -8
  116. package/src/sources/HyperSyncHeightStream.res.mjs +0 -2
  117. package/src/sources/HyperSyncSource.res +60 -254
  118. package/src/sources/HyperSyncSource.res.mjs +57 -180
  119. package/src/sources/Rpc.res +15 -79
  120. package/src/sources/Rpc.res.mjs +25 -101
  121. package/src/sources/RpcSource.res +221 -514
  122. package/src/sources/RpcSource.res.mjs +216 -411
  123. package/src/sources/RpcWebSocketHeightStream.res +0 -5
  124. package/src/sources/RpcWebSocketHeightStream.res.mjs +0 -2
  125. package/src/sources/SimulateSource.res +44 -20
  126. package/src/sources/SimulateSource.res.mjs +41 -14
  127. package/src/sources/Source.res +34 -6
  128. package/src/sources/SourceManager.res +77 -19
  129. package/src/sources/SourceManager.res.mjs +63 -21
  130. package/src/sources/SourceManager.resi +10 -0
  131. package/src/sources/Svm.res +31 -16
  132. package/src/sources/Svm.res.mjs +36 -13
  133. package/src/sources/SvmHyperSyncClient.res +5 -32
  134. package/src/sources/SvmHyperSyncSource.res +159 -134
  135. package/src/sources/SvmHyperSyncSource.res.mjs +164 -129
  136. package/src/sources/TransactionStore.res +49 -0
  137. package/src/sources/TransactionStore.res.mjs +30 -0
  138. package/src/tui/Tui.res +13 -16
  139. package/src/tui/Tui.res.mjs +12 -14
  140. package/svm.schema.json +49 -37
  141. package/src/bindings/Hrtime.res +0 -58
  142. package/src/bindings/Hrtime.res.mjs +0 -90
  143. package/src/bindings/Hrtime.resi +0 -30
@@ -1,79 +1,28 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
3
  import * as Utils from "./Utils.res.mjs";
4
+ import * as TopicFilter from "./TopicFilter.res.mjs";
4
5
  import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
5
6
  import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
6
7
  import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
7
8
  import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
8
9
  import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
9
10
 
10
- let MissingRequiredTopic0 = /* @__PURE__ */Primitive_exceptions.create("LogSelection.MissingRequiredTopic0");
11
-
12
- function makeTopicSelection(topic0, topic1Opt, topic2Opt, topic3Opt) {
13
- let topic1 = topic1Opt !== undefined ? topic1Opt : [];
14
- let topic2 = topic2Opt !== undefined ? topic2Opt : [];
15
- let topic3 = topic3Opt !== undefined ? topic3Opt : [];
16
- if (Utils.$$Array.isEmpty(topic0)) {
17
- return {
18
- TAG: "Error",
19
- _0: {
20
- RE_EXN_ID: MissingRequiredTopic0
21
- }
22
- };
11
+ function materializeTopicFilter(filter, addresses) {
12
+ if (filter.TAG === "Values") {
13
+ return filter._0;
23
14
  } else {
24
- return {
25
- TAG: "Ok",
26
- _0: {
27
- topic0: topic0,
28
- topic1: topic1,
29
- topic2: topic2,
30
- topic3: topic3
31
- }
32
- };
15
+ return addresses.map(TopicFilter.fromAddress);
33
16
  }
34
17
  }
35
18
 
36
- function hasFilters(param) {
37
- return Stdlib_Option.isSome([
38
- param.topic1,
39
- param.topic2,
40
- param.topic3
41
- ].find(topic => !Utils.$$Array.isEmpty(topic)));
42
- }
43
-
44
- function compressTopicSelections(topicSelections) {
45
- let topic0sOfSelectionsWithoutFilters = [];
46
- let selectionsWithFilters = [];
47
- topicSelections.forEach(selection => {
48
- if (hasFilters(selection)) {
49
- selectionsWithFilters.push(selection);
50
- } else {
51
- selection.topic0.forEach(topic0 => {
52
- topic0sOfSelectionsWithoutFilters.push(topic0);
53
- });
54
- }
55
- });
56
- if (topic0sOfSelectionsWithoutFilters.length === 0) {
57
- return selectionsWithFilters;
58
- }
59
- let selectionWithoutFilters_topic1 = [];
60
- let selectionWithoutFilters_topic2 = [];
61
- let selectionWithoutFilters_topic3 = [];
62
- let selectionWithoutFilters = {
63
- topic0: topic0sOfSelectionsWithoutFilters,
64
- topic1: selectionWithoutFilters_topic1,
65
- topic2: selectionWithoutFilters_topic2,
66
- topic3: selectionWithoutFilters_topic3
67
- };
68
- return [selectionWithoutFilters].concat(selectionsWithFilters);
69
- }
70
-
71
- function make(addresses, topicSelections) {
72
- let topicSelections$1 = compressTopicSelections(topicSelections);
73
- return {
74
- addresses: addresses,
75
- topicSelections: topicSelections$1
76
- };
19
+ function materializeTopicSelections(topicSelections, addresses) {
20
+ return topicSelections.map(param => ({
21
+ topic0: param.topic0,
22
+ topic1: materializeTopicFilter(param.topic1, addresses),
23
+ topic2: materializeTopicFilter(param.topic2, addresses),
24
+ topic3: materializeTopicFilter(param.topic3, addresses)
25
+ }));
77
26
  }
78
27
 
79
28
  let eventBlockRangeSchema = S$RescriptSchema.strict(S$RescriptSchema.object(s => ({
@@ -100,16 +49,7 @@ function extractStartBlock(where, onEventBlockFilterSchema, contractName) {
100
49
  }
101
50
  }
102
51
 
103
- function makeChainArg(contractName, chainId, addresses) {
104
- let chainObj = {};
105
- chainObj["id"] = chainId;
106
- chainObj[contractName] = {
107
- addresses: addresses
108
- };
109
- return chainObj;
110
- }
111
-
112
- function makeDetectionChainArg(contractName, chainId, getAddresses) {
52
+ function makeChainArg(contractName, chainId, getAddresses) {
113
53
  let contractObj = Object.create(null);
114
54
  Object.defineProperty(contractObj, "addresses", {
115
55
  enumerable: true,
@@ -133,85 +73,78 @@ let makeAddressesProbe = (function (contractName) {
133
73
  return new Proxy([], {get: trap});
134
74
  });
135
75
 
136
- function extractAddressFilterGroupsOrThrow(result, probe, contractName) {
137
- let groups = [];
138
- let scanGroup = paramsObj => {
139
- let names = [];
140
- Utils.Dict.forEachWithKey(paramsObj, (value, key) => {
141
- if (value === probe) {
142
- names.push(key);
143
- paramsObj[key] = [];
144
- return;
145
- }
146
- });
147
- if (!Utils.$$Array.isEmpty(names)) {
148
- groups.push(names);
149
- return;
150
- }
151
- };
152
- if (typeof result === "object" && result !== null && !Array.isArray(result)) {
153
- let match = result["params"];
154
- if (match !== undefined) {
155
- if (Array.isArray(match)) {
156
- match.forEach(item => {
157
- if (typeof item === "object" && item !== null && !Array.isArray(item)) {
158
- return scanGroup(item);
159
- }
160
- });
161
- } else {
162
- switch (typeof match) {
163
- case "object" :
164
- scanGroup(match);
165
- break;
166
- }
167
- }
168
- }
169
- }
170
- if (Utils.$$Array.isEmpty(groups)) {
171
- Stdlib_JsError.throwWithMessage(`Invalid where configuration for ` + contractName + `. The callback reads \`chain.` + contractName + `.addresses\` but doesn't use it as an indexed-param filter value. Use it directly, e.g. { params: { to: chain.` + contractName + `.addresses } }.`);
172
- }
173
- return groups;
174
- }
175
-
176
76
  let emptyTopics = [];
177
77
 
178
78
  function noopGetter(param) {
179
79
  return emptyTopics;
180
80
  }
181
81
 
182
- function parseEventFiltersOrThrow(eventFilters, sighash, params, contractName, probeChainId, onEventBlockFilterSchema, topic1Opt, topic2Opt, topic3Opt) {
82
+ function parseWhereOrThrow(where, sighash, params, contractName, chainId, onEventBlockFilterSchema, topic1Opt, topic2Opt, topic3Opt) {
183
83
  let topic1 = topic1Opt !== undefined ? topic1Opt : noopGetter;
184
84
  let topic2 = topic2Opt !== undefined ? topic2Opt : noopGetter;
185
85
  let topic3 = topic3Opt !== undefined ? topic3Opt : noopGetter;
186
- let filterByAddresses = {
86
+ let addressFilterParamGroups = [];
87
+ let readAddresses = {
187
88
  contents: false
188
89
  };
189
- let addressFilterParamGroups = [];
190
- let startBlock;
90
+ let addressesSentinel = makeAddressesProbe(contractName);
191
91
  let topic0 = [sighash];
92
+ let default_topic1 = {
93
+ TAG: "Values",
94
+ _0: emptyTopics
95
+ };
96
+ let default_topic2 = {
97
+ TAG: "Values",
98
+ _0: emptyTopics
99
+ };
100
+ let default_topic3 = {
101
+ TAG: "Values",
102
+ _0: emptyTopics
103
+ };
192
104
  let $$default = {
193
105
  topic0: topic0,
194
- topic1: emptyTopics,
195
- topic2: emptyTopics,
196
- topic3: emptyTopics
106
+ topic1: default_topic1,
107
+ topic2: default_topic2,
108
+ topic3: default_topic3
197
109
  };
198
- let paramsRecordToTopicSelection = paramsFilter => {
199
- if (Utils.Dict.isEmpty(paramsFilter)) {
200
- return $$default;
110
+ let topicFilterAt = (paramsFilter, index, getter) => {
111
+ let value = Stdlib_Option.flatMap(params[index], name => paramsFilter[name]);
112
+ if (value !== undefined && value === addressesSentinel) {
113
+ return {
114
+ TAG: "ContractAddresses",
115
+ contractName: contractName
116
+ };
201
117
  } else {
202
- Utils.Dict.forEachWithKey(paramsFilter, (param, key) => {
203
- if (!params.includes(key)) {
204
- return Stdlib_JsError.throwWithMessage(`Invalid where configuration. The event doesn't have an indexed parameter "` + key + `" and can't use it for filtering`);
205
- }
206
- });
207
118
  return {
208
- topic0: topic0,
209
- topic1: topic1(paramsFilter),
210
- topic2: topic2(paramsFilter),
211
- topic3: topic3(paramsFilter)
119
+ TAG: "Values",
120
+ _0: getter(paramsFilter)
212
121
  };
213
122
  }
214
123
  };
124
+ let paramsRecordToTopicSelection = paramsFilter => {
125
+ if (Utils.Dict.isEmpty(paramsFilter)) {
126
+ return $$default;
127
+ }
128
+ let sentinelParamNames = [];
129
+ Utils.Dict.forEachWithKey(paramsFilter, (value, key) => {
130
+ if (!params.includes(key)) {
131
+ Stdlib_JsError.throwWithMessage(`Invalid where configuration. The event doesn't have an indexed parameter "` + key + `" and can't use it for filtering`);
132
+ }
133
+ if (value === addressesSentinel) {
134
+ sentinelParamNames.push(key);
135
+ return;
136
+ }
137
+ });
138
+ if (!Utils.$$Array.isEmpty(sentinelParamNames)) {
139
+ addressFilterParamGroups.push(sentinelParamNames);
140
+ }
141
+ return {
142
+ topic0: topic0,
143
+ topic1: topicFilterAt(paramsFilter, 0, topic1),
144
+ topic2: topicFilterAt(paramsFilter, 1, topic2),
145
+ topic3: topicFilterAt(paramsFilter, 2, topic3)
146
+ };
147
+ };
215
148
  let acceptedWhereKeys = [
216
149
  "params",
217
150
  "block"
@@ -258,73 +191,51 @@ function parseEventFiltersOrThrow(eventFilters, sighash, params, contractName, p
258
191
  return Stdlib_JsError.throwWithMessage("Invalid where configuration. Expected `params` to be an object or an array of objects");
259
192
  }
260
193
  };
261
- let getEventFiltersOrThrow;
262
- if (eventFilters !== undefined) {
263
- if (typeof eventFilters === "function") {
264
- let addressesProbe = makeAddressesProbe(contractName);
265
- let chain = makeDetectionChainArg(contractName, probeChainId, () => {
266
- filterByAddresses.contents = true;
267
- return addressesProbe;
194
+ let match;
195
+ if (where !== undefined) {
196
+ let whereValue;
197
+ if (typeof where === "function") {
198
+ let chain = makeChainArg(contractName, chainId, () => {
199
+ readAddresses.contents = true;
200
+ return addressesSentinel;
268
201
  });
269
- let probedResult = eventFilters({
202
+ whereValue = where({
270
203
  chain: chain
271
204
  });
272
- if (filterByAddresses.contents) {
273
- addressFilterParamGroups = extractAddressFilterGroupsOrThrow(probedResult, addressesProbe, contractName);
274
- }
275
- startBlock = extractStartBlock(probedResult, onEventBlockFilterSchema, contractName);
276
- getEventFiltersOrThrow = filterByAddresses.contents ? chain => ({
277
- TAG: "Dynamic",
278
- _0: addresses => {
279
- let chainArg = makeChainArg(contractName, chain, addresses);
280
- return parse(eventFilters({
281
- chain: chainArg
282
- }));
283
- }
284
- }) : chain => {
285
- let chainArg = makeDetectionChainArg(contractName, chain, () => Stdlib_JsError.throwWithMessage(`Invalid where configuration. Event callback for contract "` + contractName + `" read \`chain.` + contractName + `.addresses\` at runtime but the probe didn't detect the access on chainId ` + chain.toString() + `. Move the \`chain.` + contractName + `.addresses\` read above any \`chain.id\` branching so the probe picks up the dependency and switches to the dynamic fetch path.`));
286
- return {
287
- TAG: "Static",
288
- _0: parse(eventFilters({
289
- chain: chainArg
290
- }))
291
- };
292
- };
293
205
  } else {
294
- startBlock = extractStartBlock(eventFilters, onEventBlockFilterSchema, contractName);
295
- let $$static = {
296
- TAG: "Static",
297
- _0: parse(eventFilters)
298
- };
299
- getEventFiltersOrThrow = param => $$static;
206
+ whereValue = where;
300
207
  }
208
+ let topicSelections = parse(whereValue);
209
+ if (readAddresses.contents && Utils.$$Array.isEmpty(addressFilterParamGroups)) {
210
+ Stdlib_JsError.throwWithMessage(`Invalid where configuration for ` + contractName + `. The callback reads \`chain.` + contractName + `.addresses\` but doesn't use it as an indexed-param filter value. Use it directly, e.g. { params: { to: chain.` + contractName + `.addresses } }.`);
211
+ }
212
+ match = [
213
+ topicSelections,
214
+ extractStartBlock(whereValue, onEventBlockFilterSchema, contractName)
215
+ ];
301
216
  } else {
302
- let $$static$1 = {
303
- TAG: "Static",
304
- _0: [$$default]
305
- };
306
- getEventFiltersOrThrow = param => $$static$1;
217
+ match = [
218
+ [$$default],
219
+ undefined
220
+ ];
307
221
  }
308
222
  return {
309
- getEventFiltersOrThrow: getEventFiltersOrThrow,
310
- filterByAddresses: filterByAddresses.contents,
311
- addressFilterParamGroups: addressFilterParamGroups,
312
- startBlock: startBlock
223
+ resolvedWhere: {
224
+ topicSelections: match[0],
225
+ startBlock: match[1]
226
+ },
227
+ filterByAddresses: !Utils.$$Array.isEmpty(addressFilterParamGroups),
228
+ addressFilterParamGroups: addressFilterParamGroups
313
229
  };
314
230
  }
315
231
 
316
232
  export {
317
- MissingRequiredTopic0,
318
- makeTopicSelection,
319
- hasFilters,
320
- compressTopicSelections,
321
- make,
233
+ materializeTopicFilter,
234
+ materializeTopicSelections,
322
235
  eventBlockRangeSchema,
323
236
  extractStartBlock,
324
237
  makeChainArg,
325
- makeDetectionChainArg,
326
238
  makeAddressesProbe,
327
- extractAddressFilterGroupsOrThrow,
328
- parseEventFiltersOrThrow,
239
+ parseWhereOrThrow,
329
240
  }
330
241
  /* eventBlockRangeSchema Not a pure module */