envio 3.0.0-alpha.2 → 3.0.0-alpha.3

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 (60) hide show
  1. package/evm.schema.json +44 -33
  2. package/fuel.schema.json +32 -21
  3. package/index.d.ts +1 -0
  4. package/package.json +7 -6
  5. package/src/Batch.res.mjs +1 -1
  6. package/src/Benchmark.res +394 -0
  7. package/src/Benchmark.res.mjs +398 -0
  8. package/src/ChainFetcher.res +459 -0
  9. package/src/ChainFetcher.res.mjs +281 -0
  10. package/src/ChainManager.res +179 -0
  11. package/src/ChainManager.res.mjs +139 -0
  12. package/src/Config.res +15 -1
  13. package/src/Config.res.mjs +27 -4
  14. package/src/Ecosystem.res +9 -124
  15. package/src/Ecosystem.res.mjs +19 -160
  16. package/src/Env.res +0 -1
  17. package/src/Env.res.mjs +0 -3
  18. package/src/Envio.gen.ts +9 -1
  19. package/src/Envio.res +12 -9
  20. package/src/EventProcessing.res +476 -0
  21. package/src/EventProcessing.res.mjs +341 -0
  22. package/src/FetchState.res +54 -29
  23. package/src/FetchState.res.mjs +62 -35
  24. package/src/GlobalState.res +1169 -0
  25. package/src/GlobalState.res.mjs +1196 -0
  26. package/src/Internal.res +2 -1
  27. package/src/LoadLayer.res +444 -0
  28. package/src/LoadLayer.res.mjs +296 -0
  29. package/src/LoadLayer.resi +32 -0
  30. package/src/Prometheus.res +8 -8
  31. package/src/Prometheus.res.mjs +10 -10
  32. package/src/ReorgDetection.res +6 -10
  33. package/src/ReorgDetection.res.mjs +6 -6
  34. package/src/UserContext.res +356 -0
  35. package/src/UserContext.res.mjs +238 -0
  36. package/src/bindings/DateFns.res +71 -0
  37. package/src/bindings/DateFns.res.mjs +22 -0
  38. package/src/sources/Evm.res +87 -0
  39. package/src/sources/Evm.res.mjs +105 -0
  40. package/src/sources/EvmChain.res +95 -0
  41. package/src/sources/EvmChain.res.mjs +61 -0
  42. package/src/sources/Fuel.res +19 -34
  43. package/src/sources/Fuel.res.mjs +34 -16
  44. package/src/sources/FuelSDK.res +37 -0
  45. package/src/sources/FuelSDK.res.mjs +29 -0
  46. package/src/sources/HyperFuel.res +2 -2
  47. package/src/sources/HyperFuel.resi +1 -1
  48. package/src/sources/HyperFuelClient.res +2 -2
  49. package/src/sources/HyperFuelSource.res +8 -8
  50. package/src/sources/HyperFuelSource.res.mjs +5 -5
  51. package/src/sources/HyperSyncSource.res +5 -5
  52. package/src/sources/HyperSyncSource.res.mjs +5 -5
  53. package/src/sources/RpcSource.res +4 -4
  54. package/src/sources/RpcSource.res.mjs +3 -3
  55. package/src/sources/Solana.res +59 -0
  56. package/src/sources/Solana.res.mjs +79 -0
  57. package/src/sources/Source.res +2 -2
  58. package/src/sources/SourceManager.res +24 -32
  59. package/src/sources/SourceManager.res.mjs +20 -20
  60. package/src/sources/SourceManager.resi +4 -5
@@ -1,12 +1,15 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
+ import * as Evm from "./sources/Evm.res.mjs";
4
+ import * as Fuel from "./sources/Fuel.res.mjs";
3
5
  import * as Utils from "./Utils.res.mjs";
4
6
  import * as Js_exn from "rescript/lib/es6/js_exn.js";
7
+ import * as Solana from "./sources/Solana.res.mjs";
8
+ import * as Js_dict from "rescript/lib/es6/js_dict.js";
5
9
  import * as ChainMap from "./ChainMap.res.mjs";
6
- import * as Ecosystem from "./Ecosystem.res.mjs";
7
10
  import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
8
11
 
9
- function make(shouldRollbackOnReorgOpt, shouldSaveFullHistoryOpt, chainsOpt, enableRawEventsOpt, ecosystemOpt, batchSizeOpt, lowercaseAddressesOpt, multichainOpt, shouldUseHypersyncClientDecoderOpt, maxAddrInPartitionOpt) {
12
+ function make(shouldRollbackOnReorgOpt, shouldSaveFullHistoryOpt, chainsOpt, enableRawEventsOpt, ecosystemOpt, batchSizeOpt, lowercaseAddressesOpt, multichainOpt, shouldUseHypersyncClientDecoderOpt, maxAddrInPartitionOpt, userEntitiesOpt) {
10
13
  var shouldRollbackOnReorg = shouldRollbackOnReorgOpt !== undefined ? shouldRollbackOnReorgOpt : true;
11
14
  var shouldSaveFullHistory = shouldSaveFullHistoryOpt !== undefined ? shouldSaveFullHistoryOpt : false;
12
15
  var chains = chainsOpt !== undefined ? chainsOpt : [];
@@ -17,6 +20,7 @@ function make(shouldRollbackOnReorgOpt, shouldSaveFullHistoryOpt, chainsOpt, ena
17
20
  var multichain = multichainOpt !== undefined ? multichainOpt : "unordered";
18
21
  var shouldUseHypersyncClientDecoder = shouldUseHypersyncClientDecoderOpt !== undefined ? shouldUseHypersyncClientDecoderOpt : true;
19
22
  var maxAddrInPartition = maxAddrInPartitionOpt !== undefined ? maxAddrInPartitionOpt : 5000;
23
+ var userEntities = userEntitiesOpt !== undefined ? userEntitiesOpt : [];
20
24
  if (lowercaseAddresses && !shouldUseHypersyncClientDecoder) {
21
25
  Js_exn.raiseError("lowercase addresses is not supported when event_decoder is 'viem'. Please set event_decoder to 'hypersync-client' or change address_format to 'checksum'.");
22
26
  }
@@ -33,7 +37,25 @@ function make(shouldRollbackOnReorgOpt, shouldSaveFullHistoryOpt, chainsOpt, ena
33
37
  addContractNameToContractNameMapping[addKey] = contract.name;
34
38
  }));
35
39
  }));
36
- var ecosystem$1 = Ecosystem.fromName(ecosystem);
40
+ var ecosystem$1;
41
+ switch (ecosystem) {
42
+ case "evm" :
43
+ ecosystem$1 = Evm.ecosystem;
44
+ break;
45
+ case "fuel" :
46
+ ecosystem$1 = Fuel.ecosystem;
47
+ break;
48
+ case "solana" :
49
+ ecosystem$1 = Solana.ecosystem;
50
+ break;
51
+
52
+ }
53
+ var userEntitiesByName = Js_dict.fromArray(userEntities.map(function (entityConfig) {
54
+ return [
55
+ entityConfig.name,
56
+ entityConfig
57
+ ];
58
+ }));
37
59
  return {
38
60
  shouldRollbackOnReorg: shouldRollbackOnReorg,
39
61
  shouldSaveFullHistory: shouldSaveFullHistory,
@@ -45,7 +67,8 @@ function make(shouldRollbackOnReorgOpt, shouldSaveFullHistoryOpt, chainsOpt, ena
45
67
  maxAddrInPartition: maxAddrInPartition,
46
68
  batchSize: batchSize,
47
69
  lowercaseAddresses: lowercaseAddresses,
48
- addContractNameToContractNameMapping: addContractNameToContractNameMapping
70
+ addContractNameToContractNameMapping: addContractNameToContractNameMapping,
71
+ userEntitiesByName: userEntitiesByName
49
72
  };
50
73
  }
51
74
 
package/src/Ecosystem.res CHANGED
@@ -1,4 +1,4 @@
1
- type name = | @as("evm") Evm | @as("fuel") Fuel
1
+ type name = | @as("evm") Evm | @as("fuel") Fuel | @as("solana") Solana
2
2
 
3
3
  type t = {
4
4
  name: name,
@@ -13,128 +13,13 @@ type t = {
13
13
  cleanUpRawEventFieldsInPlace: Js.Json.t => unit,
14
14
  }
15
15
 
16
- module Evm = {
17
- @get external getNumber: Internal.eventBlock => int = "number"
18
- @get external getTimestamp: Internal.eventBlock => int = "timestamp"
19
- @get external getId: Internal.eventBlock => string = "hash"
20
-
21
- let cleanUpRawEventFieldsInPlace: Js.Json.t => unit = %raw(`fields => {
22
- delete fields.hash
23
- delete fields.number
24
- delete fields.timestamp
25
- }`)
26
- }
27
-
28
- let evm: t = {
29
- name: Evm,
30
- blockFields: [
31
- "number",
32
- "timestamp",
33
- "hash",
34
- "parentHash",
35
- "nonce",
36
- "sha3Uncles",
37
- "logsBloom",
38
- "transactionsRoot",
39
- "stateRoot",
40
- "receiptsRoot",
41
- "miner",
42
- "difficulty",
43
- "totalDifficulty",
44
- "extraData",
45
- "size",
46
- "gasLimit",
47
- "gasUsed",
48
- "uncles",
49
- "baseFeePerGas",
50
- "blobGasUsed",
51
- "excessBlobGas",
52
- "parentBeaconBlockRoot",
53
- "withdrawalsRoot",
54
- "l1BlockNumber",
55
- "sendCount",
56
- "sendRoot",
57
- "mixHash",
58
- ],
59
- transactionFields: [
60
- "transactionIndex",
61
- "hash",
62
- "from",
63
- "to",
64
- "gas",
65
- "gasPrice",
66
- "maxPriorityFeePerGas",
67
- "maxFeePerGas",
68
- "cumulativeGasUsed",
69
- "effectiveGasPrice",
70
- "gasUsed",
71
- "input",
72
- "nonce",
73
- "value",
74
- "v",
75
- "r",
76
- "s",
77
- "contractAddress",
78
- "logsBloom",
79
- "root",
80
- "status",
81
- "yParity",
82
- "chainId",
83
- "maxFeePerBlobGas",
84
- "blobVersionedHashes",
85
- "type",
86
- "l1Fee",
87
- "l1GasPrice",
88
- "l1GasUsed",
89
- "l1FeeScalar",
90
- "gasUsedForL1",
91
- "accessList",
92
- "authorizationList",
93
- ],
94
- blockNumberName: "number",
95
- blockTimestampName: "timestamp",
96
- blockHashName: "hash",
97
- getNumber: Evm.getNumber,
98
- getTimestamp: Evm.getTimestamp,
99
- getId: Evm.getId,
100
- cleanUpRawEventFieldsInPlace: Evm.cleanUpRawEventFieldsInPlace,
101
- }
102
-
103
- module Fuel = {
104
- @get external getNumber: Internal.eventBlock => int = "height"
105
- @get external getTimestamp: Internal.eventBlock => int = "time"
106
- @get external getId: Internal.eventBlock => string = "id"
107
-
108
- let cleanUpRawEventFieldsInPlace: Js.Json.t => unit = %raw(`fields => {
109
- delete fields.id
110
- delete fields.height
111
- delete fields.time
112
- }`)
113
- }
114
-
115
- let fuel: t = {
116
- name: Fuel,
117
- blockFields: ["id", "height", "time"],
118
- transactionFields: ["id"],
119
- blockNumberName: "height",
120
- blockTimestampName: "time",
121
- blockHashName: "id",
122
- getNumber: Fuel.getNumber,
123
- getTimestamp: Fuel.getTimestamp,
124
- getId: Fuel.getId,
125
- cleanUpRawEventFieldsInPlace: Fuel.cleanUpRawEventFieldsInPlace,
126
- }
127
-
128
- let fromName = (name: name): t => {
129
- switch name {
130
- | Evm => evm
131
- | Fuel => fuel
16
+ let makeOnBlockArgs = (~blockNumber: int, ~ecosystem: t, ~context): Internal.onBlockArgs => {
17
+ switch ecosystem.name {
18
+ | Solana => {slot: blockNumber, context}
19
+ | _ => {
20
+ let blockEvent = Js.Dict.empty()
21
+ blockEvent->Js.Dict.set(ecosystem.blockNumberName, blockNumber->Utils.magic)
22
+ {block: blockEvent->Utils.magic, context}
23
+ }
132
24
  }
133
25
  }
134
-
135
- // Create a block event object for block handlers based on ecosystem
136
- let makeBlockEvent = (~blockNumber: int, ecosystem: t): Internal.blockEvent => {
137
- let blockEvent = Js.Dict.empty()
138
- blockEvent->Js.Dict.set(ecosystem.blockNumberName, blockNumber->Utils.magic)
139
- blockEvent->Utils.magic
140
- }
@@ -1,170 +1,29 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
-
4
- var cleanUpRawEventFieldsInPlace = (fields => {
5
- delete fields.hash
6
- delete fields.number
7
- delete fields.timestamp
8
- });
9
-
10
- var Evm = {
11
- cleanUpRawEventFieldsInPlace: cleanUpRawEventFieldsInPlace
12
- };
13
-
14
- var evm_blockFields = [
15
- "number",
16
- "timestamp",
17
- "hash",
18
- "parentHash",
19
- "nonce",
20
- "sha3Uncles",
21
- "logsBloom",
22
- "transactionsRoot",
23
- "stateRoot",
24
- "receiptsRoot",
25
- "miner",
26
- "difficulty",
27
- "totalDifficulty",
28
- "extraData",
29
- "size",
30
- "gasLimit",
31
- "gasUsed",
32
- "uncles",
33
- "baseFeePerGas",
34
- "blobGasUsed",
35
- "excessBlobGas",
36
- "parentBeaconBlockRoot",
37
- "withdrawalsRoot",
38
- "l1BlockNumber",
39
- "sendCount",
40
- "sendRoot",
41
- "mixHash"
42
- ];
43
-
44
- var evm_transactionFields = [
45
- "transactionIndex",
46
- "hash",
47
- "from",
48
- "to",
49
- "gas",
50
- "gasPrice",
51
- "maxPriorityFeePerGas",
52
- "maxFeePerGas",
53
- "cumulativeGasUsed",
54
- "effectiveGasPrice",
55
- "gasUsed",
56
- "input",
57
- "nonce",
58
- "value",
59
- "v",
60
- "r",
61
- "s",
62
- "contractAddress",
63
- "logsBloom",
64
- "root",
65
- "status",
66
- "yParity",
67
- "chainId",
68
- "maxFeePerBlobGas",
69
- "blobVersionedHashes",
70
- "type",
71
- "l1Fee",
72
- "l1GasPrice",
73
- "l1GasUsed",
74
- "l1FeeScalar",
75
- "gasUsedForL1",
76
- "accessList",
77
- "authorizationList"
78
- ];
79
-
80
- function evm_getNumber(prim) {
81
- return prim.number;
82
- }
83
-
84
- function evm_getTimestamp(prim) {
85
- return prim.timestamp;
86
- }
87
-
88
- function evm_getId(prim) {
89
- return prim.hash;
90
- }
91
-
92
- var evm = {
93
- name: "evm",
94
- blockFields: evm_blockFields,
95
- transactionFields: evm_transactionFields,
96
- blockNumberName: "number",
97
- blockTimestampName: "timestamp",
98
- blockHashName: "hash",
99
- getNumber: evm_getNumber,
100
- getTimestamp: evm_getTimestamp,
101
- getId: evm_getId,
102
- cleanUpRawEventFieldsInPlace: cleanUpRawEventFieldsInPlace
103
- };
104
-
105
- var cleanUpRawEventFieldsInPlace$1 = (fields => {
106
- delete fields.id
107
- delete fields.height
108
- delete fields.time
109
- });
110
-
111
- var Fuel = {
112
- cleanUpRawEventFieldsInPlace: cleanUpRawEventFieldsInPlace$1
113
- };
114
-
115
- var fuel_blockFields = [
116
- "id",
117
- "height",
118
- "time"
119
- ];
120
-
121
- var fuel_transactionFields = ["id"];
122
-
123
- function fuel_getNumber(prim) {
124
- return prim.height;
125
- }
126
-
127
- function fuel_getTimestamp(prim) {
128
- return prim.time;
129
- }
130
-
131
- function fuel_getId(prim) {
132
- return prim.id;
133
- }
134
-
135
- var fuel = {
136
- name: "fuel",
137
- blockFields: fuel_blockFields,
138
- transactionFields: fuel_transactionFields,
139
- blockNumberName: "height",
140
- blockTimestampName: "time",
141
- blockHashName: "id",
142
- getNumber: fuel_getNumber,
143
- getTimestamp: fuel_getTimestamp,
144
- getId: fuel_getId,
145
- cleanUpRawEventFieldsInPlace: cleanUpRawEventFieldsInPlace$1
146
- };
147
-
148
- function fromName(name) {
149
- if (name === "evm") {
150
- return evm;
151
- } else {
152
- return fuel;
3
+ import * as Caml_option from "rescript/lib/es6/caml_option.js";
4
+
5
+ function makeOnBlockArgs(blockNumber, ecosystem, context) {
6
+ var match = ecosystem.name;
7
+ switch (match) {
8
+ case "evm" :
9
+ case "fuel" :
10
+ break;
11
+ case "solana" :
12
+ return {
13
+ slot: blockNumber,
14
+ context: context
15
+ };
16
+
153
17
  }
154
- }
155
-
156
- function makeBlockEvent(blockNumber, ecosystem) {
157
18
  var blockEvent = {};
158
19
  blockEvent[ecosystem.blockNumberName] = blockNumber;
159
- return blockEvent;
20
+ return {
21
+ block: Caml_option.some(blockEvent),
22
+ context: context
23
+ };
160
24
  }
161
25
 
162
26
  export {
163
- Evm ,
164
- evm ,
165
- Fuel ,
166
- fuel ,
167
- fromName ,
168
- makeBlockEvent ,
27
+ makeOnBlockArgs ,
169
28
  }
170
29
  /* No side effect */
package/src/Env.res CHANGED
@@ -15,7 +15,6 @@
15
15
  // resets the timestampCaughtUpToHeadOrEndblock after a restart when true
16
16
  let updateSyncTimeOnRestart =
17
17
  envSafe->EnvSafe.get("UPDATE_SYNC_TIME_ON_RESTART", S.bool, ~fallback=true)
18
- let batchSize = envSafe->EnvSafe.get("MAX_BATCH_SIZE", S.option(S.int))
19
18
  let targetBufferSize = envSafe->EnvSafe.get("ENVIO_INDEXING_MAX_BUFFER_SIZE", S.option(S.int))
20
19
  let maxAddrInPartition = envSafe->EnvSafe.get("MAX_PARTITION_SIZE", S.int, ~fallback=5_000)
21
20
  let maxPartitionConcurrency =
package/src/Env.res.mjs CHANGED
@@ -29,8 +29,6 @@ function getLogLevelConfig(name, $$default) {
29
29
 
30
30
  var updateSyncTimeOnRestart = EnvSafe.get(envSafe, "UPDATE_SYNC_TIME_ON_RESTART", S$RescriptSchema.bool, undefined, true, undefined, undefined);
31
31
 
32
- var batchSize = EnvSafe.get(envSafe, "MAX_BATCH_SIZE", S$RescriptSchema.option(S$RescriptSchema.$$int), undefined, undefined, undefined, undefined);
33
-
34
32
  var targetBufferSize = EnvSafe.get(envSafe, "ENVIO_INDEXING_MAX_BUFFER_SIZE", S$RescriptSchema.option(S$RescriptSchema.$$int), undefined, undefined, undefined, undefined);
35
33
 
36
34
  var maxAddrInPartition = EnvSafe.get(envSafe, "MAX_PARTITION_SIZE", S$RescriptSchema.$$int, undefined, 5000, undefined, undefined);
@@ -245,7 +243,6 @@ EnvSafe.close(envSafe);
245
243
 
246
244
  export {
247
245
  updateSyncTimeOnRestart ,
248
- batchSize ,
249
246
  targetBufferSize ,
250
247
  maxAddrInPartition ,
251
248
  maxPartitionConcurrency ,
package/src/Envio.gen.ts CHANGED
@@ -13,7 +13,9 @@ import type {S_t as RescriptSchema_S_t} from 'rescript-schema/RescriptSchema.gen
13
13
 
14
14
  export type blockEvent = { readonly number: number };
15
15
 
16
- export type fuelBlockEvent = { readonly height: number; readonly chainId: number };
16
+ export type fuelBlockEvent = { readonly height: number };
17
+
18
+ export type solanaOnBlockArgs<context> = { readonly slot: number; readonly context: context };
17
19
 
18
20
  export type onBlockArgs<block,context> = { readonly block: block; readonly context: context };
19
21
 
@@ -25,6 +27,12 @@ export type onBlockOptions<chain> = {
25
27
  readonly endBlock?: number
26
28
  };
27
29
 
30
+ export type whereOperations<entity,fieldType> = {
31
+ readonly eq: (_1:fieldType) => Promise<entity[]>;
32
+ readonly gt: (_1:fieldType) => Promise<entity[]>;
33
+ readonly lt: (_1:fieldType) => Promise<entity[]>
34
+ };
35
+
28
36
  export type logger = $$logger;
29
37
 
30
38
  export type effect<input,output> = $$effect<input,output>;
package/src/Envio.res CHANGED
@@ -2,18 +2,14 @@
2
2
  // Should be an entry point after we get rid of the generated project.
3
3
  // Don't forget to keep index.d.ts in sync with this file.
4
4
 
5
- // EVM block event with 'number' field for backward compatibility
6
5
  @genType
7
- type blockEvent = {
8
- number: int,
9
- }
6
+ type blockEvent = {number: int}
10
7
 
11
- // Fuel block event with 'height' field
12
8
  @genType
13
- type fuelBlockEvent = {
14
- height: int,
15
- chainId: int,
16
- }
9
+ type fuelBlockEvent = {height: int}
10
+
11
+ @genType
12
+ type solanaOnBlockArgs<'context> = {slot: int, context: 'context}
17
13
 
18
14
  @genType
19
15
  type onBlockArgs<'block, 'context> = {
@@ -30,6 +26,13 @@ type onBlockOptions<'chain> = {
30
26
  endBlock?: int,
31
27
  }
32
28
 
29
+ @genType
30
+ type whereOperations<'entity, 'fieldType> = {
31
+ eq: 'fieldType => promise<array<'entity>>,
32
+ gt: 'fieldType => promise<array<'entity>>,
33
+ lt: 'fieldType => promise<array<'entity>>,
34
+ }
35
+
33
36
  @genType.import(("./Types.ts", "Logger"))
34
37
  type logger = {
35
38
  debug: 'params. (string, ~params: {..} as 'params=?) => unit,