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
@@ -1,6 +1,7 @@
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";
@@ -76,6 +77,23 @@ function make(addresses, topicSelections) {
76
77
  };
77
78
  }
78
79
 
80
+ function materializeTopicFilter(filter, addresses) {
81
+ if (filter.TAG === "Values") {
82
+ return filter._0;
83
+ } else {
84
+ return addresses.map(TopicFilter.fromAddress);
85
+ }
86
+ }
87
+
88
+ function materializeTopicSelections(topicSelections, addresses) {
89
+ return topicSelections.map(param => ({
90
+ topic0: param.topic0,
91
+ topic1: materializeTopicFilter(param.topic1, addresses),
92
+ topic2: materializeTopicFilter(param.topic2, addresses),
93
+ topic3: materializeTopicFilter(param.topic3, addresses)
94
+ }));
95
+ }
96
+
79
97
  let eventBlockRangeSchema = S$RescriptSchema.strict(S$RescriptSchema.object(s => ({
80
98
  _gte: s.f("_gte", S$RescriptSchema.option(S$RescriptSchema.int))
81
99
  })));
@@ -100,16 +118,7 @@ function extractStartBlock(where, onEventBlockFilterSchema, contractName) {
100
118
  }
101
119
  }
102
120
 
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) {
121
+ function makeChainArg(contractName, chainId, getAddresses) {
113
122
  let contractObj = Object.create(null);
114
123
  Object.defineProperty(contractObj, "addresses", {
115
124
  enumerable: true,
@@ -133,85 +142,78 @@ let makeAddressesProbe = (function (contractName) {
133
142
  return new Proxy([], {get: trap});
134
143
  });
135
144
 
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
145
  let emptyTopics = [];
177
146
 
178
147
  function noopGetter(param) {
179
148
  return emptyTopics;
180
149
  }
181
150
 
182
- function parseEventFiltersOrThrow(eventFilters, sighash, params, contractName, probeChainId, onEventBlockFilterSchema, topic1Opt, topic2Opt, topic3Opt) {
151
+ function parseWhereOrThrow(where, sighash, params, contractName, chainId, onEventBlockFilterSchema, topic1Opt, topic2Opt, topic3Opt) {
183
152
  let topic1 = topic1Opt !== undefined ? topic1Opt : noopGetter;
184
153
  let topic2 = topic2Opt !== undefined ? topic2Opt : noopGetter;
185
154
  let topic3 = topic3Opt !== undefined ? topic3Opt : noopGetter;
186
- let filterByAddresses = {
155
+ let addressFilterParamGroups = [];
156
+ let readAddresses = {
187
157
  contents: false
188
158
  };
189
- let addressFilterParamGroups = [];
190
- let startBlock;
159
+ let addressesSentinel = makeAddressesProbe(contractName);
191
160
  let topic0 = [sighash];
161
+ let default_topic1 = {
162
+ TAG: "Values",
163
+ _0: emptyTopics
164
+ };
165
+ let default_topic2 = {
166
+ TAG: "Values",
167
+ _0: emptyTopics
168
+ };
169
+ let default_topic3 = {
170
+ TAG: "Values",
171
+ _0: emptyTopics
172
+ };
192
173
  let $$default = {
193
174
  topic0: topic0,
194
- topic1: emptyTopics,
195
- topic2: emptyTopics,
196
- topic3: emptyTopics
175
+ topic1: default_topic1,
176
+ topic2: default_topic2,
177
+ topic3: default_topic3
197
178
  };
198
- let paramsRecordToTopicSelection = paramsFilter => {
199
- if (Utils.Dict.isEmpty(paramsFilter)) {
200
- return $$default;
179
+ let topicFilterAt = (paramsFilter, index, getter) => {
180
+ let value = Stdlib_Option.flatMap(params[index], name => paramsFilter[name]);
181
+ if (value !== undefined && value === addressesSentinel) {
182
+ return {
183
+ TAG: "ContractAddresses",
184
+ contractName: contractName
185
+ };
201
186
  } 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
187
  return {
208
- topic0: topic0,
209
- topic1: topic1(paramsFilter),
210
- topic2: topic2(paramsFilter),
211
- topic3: topic3(paramsFilter)
188
+ TAG: "Values",
189
+ _0: getter(paramsFilter)
212
190
  };
213
191
  }
214
192
  };
193
+ let paramsRecordToTopicSelection = paramsFilter => {
194
+ if (Utils.Dict.isEmpty(paramsFilter)) {
195
+ return $$default;
196
+ }
197
+ let sentinelParamNames = [];
198
+ Utils.Dict.forEachWithKey(paramsFilter, (value, key) => {
199
+ if (!params.includes(key)) {
200
+ Stdlib_JsError.throwWithMessage(`Invalid where configuration. The event doesn't have an indexed parameter "` + key + `" and can't use it for filtering`);
201
+ }
202
+ if (value === addressesSentinel) {
203
+ sentinelParamNames.push(key);
204
+ return;
205
+ }
206
+ });
207
+ if (!Utils.$$Array.isEmpty(sentinelParamNames)) {
208
+ addressFilterParamGroups.push(sentinelParamNames);
209
+ }
210
+ return {
211
+ topic0: topic0,
212
+ topic1: topicFilterAt(paramsFilter, 0, topic1),
213
+ topic2: topicFilterAt(paramsFilter, 1, topic2),
214
+ topic3: topicFilterAt(paramsFilter, 2, topic3)
215
+ };
216
+ };
215
217
  let acceptedWhereKeys = [
216
218
  "params",
217
219
  "block"
@@ -258,58 +260,41 @@ function parseEventFiltersOrThrow(eventFilters, sighash, params, contractName, p
258
260
  return Stdlib_JsError.throwWithMessage("Invalid where configuration. Expected `params` to be an object or an array of objects");
259
261
  }
260
262
  };
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;
263
+ let match;
264
+ if (where !== undefined) {
265
+ let whereValue;
266
+ if (typeof where === "function") {
267
+ let chain = makeChainArg(contractName, chainId, () => {
268
+ readAddresses.contents = true;
269
+ return addressesSentinel;
268
270
  });
269
- let probedResult = eventFilters({
271
+ whereValue = where({
270
272
  chain: chain
271
273
  });
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
274
  } else {
294
- startBlock = extractStartBlock(eventFilters, onEventBlockFilterSchema, contractName);
295
- let $$static = {
296
- TAG: "Static",
297
- _0: parse(eventFilters)
298
- };
299
- getEventFiltersOrThrow = param => $$static;
275
+ whereValue = where;
276
+ }
277
+ let topicSelections = parse(whereValue);
278
+ if (readAddresses.contents && Utils.$$Array.isEmpty(addressFilterParamGroups)) {
279
+ 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 } }.`);
300
280
  }
281
+ match = [
282
+ topicSelections,
283
+ extractStartBlock(whereValue, onEventBlockFilterSchema, contractName)
284
+ ];
301
285
  } else {
302
- let $$static$1 = {
303
- TAG: "Static",
304
- _0: [$$default]
305
- };
306
- getEventFiltersOrThrow = param => $$static$1;
286
+ match = [
287
+ [$$default],
288
+ undefined
289
+ ];
307
290
  }
308
291
  return {
309
- getEventFiltersOrThrow: getEventFiltersOrThrow,
310
- filterByAddresses: filterByAddresses.contents,
311
- addressFilterParamGroups: addressFilterParamGroups,
312
- startBlock: startBlock
292
+ resolvedWhere: {
293
+ topicSelections: match[0],
294
+ startBlock: match[1]
295
+ },
296
+ filterByAddresses: !Utils.$$Array.isEmpty(addressFilterParamGroups),
297
+ addressFilterParamGroups: addressFilterParamGroups
313
298
  };
314
299
  }
315
300
 
@@ -319,12 +304,12 @@ export {
319
304
  hasFilters,
320
305
  compressTopicSelections,
321
306
  make,
307
+ materializeTopicFilter,
308
+ materializeTopicSelections,
322
309
  eventBlockRangeSchema,
323
310
  extractStartBlock,
324
311
  makeChainArg,
325
- makeDetectionChainArg,
326
312
  makeAddressesProbe,
327
- extractAddressFilterGroupsOrThrow,
328
- parseEventFiltersOrThrow,
313
+ parseWhereOrThrow,
329
314
  }
330
315
  /* eventBlockRangeSchema Not a pure module */