envio 3.3.0-alpha.9 → 3.3.0
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.
- package/index.d.ts +19 -0
- package/licenses/CLA.md +35 -0
- package/licenses/EULA.md +67 -0
- package/licenses/LICENSE.md +45 -0
- package/licenses/README.md +35 -0
- package/package.json +9 -8
- package/src/Batch.res.mjs +1 -1
- package/src/BatchProcessing.res +0 -7
- package/src/BatchProcessing.res.mjs +1 -8
- package/src/ChainFetching.res +30 -18
- package/src/ChainFetching.res.mjs +23 -13
- package/src/ChainState.res +134 -55
- package/src/ChainState.res.mjs +78 -36
- package/src/ChainState.resi +14 -2
- package/src/Config.res +9 -5
- package/src/Config.res.mjs +2 -2
- package/src/Core.res +20 -0
- package/src/Core.res.mjs +12 -0
- package/src/CrossChainState.res +115 -34
- package/src/CrossChainState.res.mjs +37 -14
- package/src/EffectState.res +100 -0
- package/src/EffectState.res.mjs +74 -0
- package/src/EffectState.resi +32 -0
- package/src/Envio.res +25 -7
- package/src/Envio.res.mjs +15 -19
- package/src/EventConfigBuilder.res +21 -46
- package/src/EventConfigBuilder.res.mjs +18 -25
- package/src/EventProcessing.res +8 -5
- package/src/EventProcessing.res.mjs +2 -1
- package/src/FetchState.res +814 -467
- package/src/FetchState.res.mjs +541 -369
- package/src/HandlerRegister.res +3 -1
- package/src/HandlerRegister.res.mjs +3 -2
- package/src/InMemoryStore.res +14 -26
- package/src/InMemoryStore.res.mjs +6 -19
- package/src/IndexerState.res +15 -39
- package/src/IndexerState.res.mjs +18 -29
- package/src/IndexerState.resi +2 -10
- package/src/Internal.res +98 -14
- package/src/Internal.res.mjs +96 -2
- package/src/LoadLayer.res +44 -24
- package/src/LoadLayer.res.mjs +43 -20
- package/src/LoadLayer.resi +1 -0
- package/src/LogSelection.res +0 -62
- package/src/LogSelection.res.mjs +0 -74
- package/src/Metrics.res +1 -1
- package/src/Metrics.res.mjs +1 -1
- package/src/Persistence.res +12 -3
- package/src/PgStorage.res +155 -82
- package/src/PgStorage.res.mjs +130 -77
- package/src/Prometheus.res +20 -10
- package/src/Prometheus.res.mjs +22 -10
- package/src/PruneStaleHistory.res +146 -35
- package/src/PruneStaleHistory.res.mjs +114 -20
- package/src/RawEvent.res +2 -2
- package/src/Rollback.res +32 -13
- package/src/Rollback.res.mjs +24 -11
- package/src/SimulateDeadInputTracker.res +1 -1
- package/src/SimulateItems.res +38 -6
- package/src/SimulateItems.res.mjs +28 -9
- package/src/TestIndexer.res +2 -2
- package/src/TestIndexer.res.mjs +2 -2
- package/src/TopicFilter.res +1 -25
- package/src/TopicFilter.res.mjs +0 -74
- package/src/UserContext.res +62 -23
- package/src/UserContext.res.mjs +26 -6
- package/src/Writing.res +60 -21
- package/src/Writing.res.mjs +27 -9
- package/src/bindings/NodeJs.res +5 -0
- package/src/bindings/Viem.res +0 -5
- package/src/sources/EventRouter.res +0 -21
- package/src/sources/EventRouter.res.mjs +0 -12
- package/src/sources/EvmChain.res +2 -27
- package/src/sources/EvmChain.res.mjs +2 -23
- package/src/sources/EvmRpcClient.res +58 -23
- package/src/sources/EvmRpcClient.res.mjs +11 -5
- package/src/sources/HyperSync.res +9 -38
- package/src/sources/HyperSync.res.mjs +16 -28
- package/src/sources/HyperSync.resi +2 -2
- package/src/sources/HyperSyncClient.res +88 -11
- package/src/sources/HyperSyncClient.res.mjs +39 -6
- package/src/sources/HyperSyncSource.res +18 -199
- package/src/sources/HyperSyncSource.res.mjs +9 -128
- package/src/sources/Rpc.res +0 -32
- package/src/sources/Rpc.res.mjs +1 -46
- package/src/sources/RpcSource.res +129 -522
- package/src/sources/RpcSource.res.mjs +161 -366
- package/src/sources/SimulateSource.res +37 -19
- package/src/sources/SimulateSource.res.mjs +27 -10
- package/src/sources/SourceManager.res +3 -7
- package/src/sources/SourceManager.res.mjs +2 -7
- package/src/sources/SourceManager.resi +0 -2
- package/src/sources/SvmHyperSyncSource.res +13 -3
- package/src/sources/SvmHyperSyncSource.res.mjs +1 -1
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as Utils from "../Utils.res.mjs";
|
|
4
3
|
import * as Source from "./Source.res.mjs";
|
|
5
4
|
import * as Logging from "../Logging.res.mjs";
|
|
6
5
|
import * as HyperSync from "./HyperSync.res.mjs";
|
|
7
|
-
import * as EventRouter from "./EventRouter.res.mjs";
|
|
8
6
|
import * as Performance from "../bindings/Performance.res.mjs";
|
|
9
|
-
import * as LogSelection from "../LogSelection.res.mjs";
|
|
10
7
|
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
11
8
|
import * as ErrorHandling from "../ErrorHandling.res.mjs";
|
|
12
9
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
@@ -16,109 +13,27 @@ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js
|
|
|
16
13
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
17
14
|
import * as HyperSyncHeightStream from "./HyperSyncHeightStream.res.mjs";
|
|
18
15
|
|
|
19
|
-
function getSelectionConfig(selection) {
|
|
20
|
-
let capitalizedBlockFields = new Set();
|
|
21
|
-
let capitalizedTransactionFields = new Set();
|
|
22
|
-
let topicSelectionsByContract = {};
|
|
23
|
-
let wildcardTopicSelectionsByContract = {};
|
|
24
|
-
let noAddressesTopicSelections = [];
|
|
25
|
-
let contractNames = new Set();
|
|
26
|
-
selection.onEventRegistrations.forEach(reg => {
|
|
27
|
-
let eventConfig = reg.eventConfig;
|
|
28
|
-
let contractName = eventConfig.contractName;
|
|
29
|
-
let resolvedWhere = reg.resolvedWhere;
|
|
30
|
-
Array.from(eventConfig.selectedBlockFields).forEach(name => {
|
|
31
|
-
capitalizedBlockFields.add(Utils.$$String.capitalize(name));
|
|
32
|
-
});
|
|
33
|
-
Array.from(eventConfig.selectedTransactionFields).forEach(name => {
|
|
34
|
-
if (name !== "transactionIndex") {
|
|
35
|
-
capitalizedTransactionFields.add(Utils.$$String.capitalize(name));
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
if (reg.dependsOnAddresses) {
|
|
40
|
-
contractNames.add(contractName);
|
|
41
|
-
return Utils.Dict.pushMany(reg.isWildcard ? wildcardTopicSelectionsByContract : topicSelectionsByContract, contractName, resolvedWhere.topicSelections);
|
|
42
|
-
} else {
|
|
43
|
-
noAddressesTopicSelections.push(...LogSelection.materializeTopicSelections(resolvedWhere.topicSelections, []));
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
let fieldSelection_block = Array.from(capitalizedBlockFields);
|
|
48
|
-
let fieldSelection_transaction = Array.from(capitalizedTransactionFields);
|
|
49
|
-
let fieldSelection_log = [
|
|
50
|
-
"Address",
|
|
51
|
-
"Data",
|
|
52
|
-
"LogIndex",
|
|
53
|
-
"Topic0",
|
|
54
|
-
"Topic1",
|
|
55
|
-
"Topic2",
|
|
56
|
-
"Topic3"
|
|
57
|
-
];
|
|
58
|
-
let fieldSelection = {
|
|
59
|
-
block: fieldSelection_block,
|
|
60
|
-
transaction: fieldSelection_transaction,
|
|
61
|
-
log: fieldSelection_log
|
|
62
|
-
};
|
|
63
|
-
let noAddressesLogSelection = LogSelection.make([], noAddressesTopicSelections);
|
|
64
|
-
let getLogSelectionOrThrow = addressesByContractName => {
|
|
65
|
-
let logSelections = [];
|
|
66
|
-
if (!Utils.$$Array.isEmpty(noAddressesLogSelection.topicSelections)) {
|
|
67
|
-
logSelections.push(noAddressesLogSelection);
|
|
68
|
-
}
|
|
69
|
-
contractNames.forEach(contractName => {
|
|
70
|
-
let addresses = addressesByContractName[contractName];
|
|
71
|
-
if (addresses === undefined) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (addresses.length === 0) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
let topicSelections = topicSelectionsByContract[contractName];
|
|
78
|
-
if (topicSelections !== undefined) {
|
|
79
|
-
logSelections.push(LogSelection.make(addresses, LogSelection.materializeTopicSelections(topicSelections, addresses)));
|
|
80
|
-
}
|
|
81
|
-
let topicSelections$1 = wildcardTopicSelectionsByContract[contractName];
|
|
82
|
-
if (topicSelections$1 !== undefined) {
|
|
83
|
-
logSelections.push(LogSelection.make([], LogSelection.materializeTopicSelections(topicSelections$1, addresses)));
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
return logSelections;
|
|
88
|
-
};
|
|
89
|
-
return {
|
|
90
|
-
getLogSelectionOrThrow: getLogSelectionOrThrow,
|
|
91
|
-
fieldSelection: fieldSelection
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function memoGetSelectionConfig() {
|
|
96
|
-
return Utils.$$WeakMap.memoize(getSelectionConfig);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
16
|
function isUnauthorizedError(message) {
|
|
100
17
|
return message.includes("401 Unauthorized");
|
|
101
18
|
}
|
|
102
19
|
|
|
103
20
|
function make(param) {
|
|
104
21
|
let apiToken = param.apiToken;
|
|
105
|
-
let
|
|
22
|
+
let onEventRegistrations = param.onEventRegistrations;
|
|
106
23
|
let endpointUrl = param.endpointUrl;
|
|
107
24
|
let chain = param.chain;
|
|
108
25
|
let name = "HyperSync";
|
|
109
|
-
let getSelectionConfig$1 = Utils.$$WeakMap.memoize(getSelectionConfig);
|
|
110
26
|
let apiToken$1 = apiToken !== undefined ? apiToken : Stdlib_JsError.throwWithMessage(`An Envio API token is required for using HyperSync as a data-source.
|
|
111
27
|
Set the ENVIO_API_TOKEN environment variable in your .env file.
|
|
112
28
|
Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
113
29
|
let client;
|
|
114
30
|
try {
|
|
115
|
-
client = HyperSyncClient.make(endpointUrl, apiToken$1, param.clientTimeoutMillis,
|
|
31
|
+
client = HyperSyncClient.make(endpointUrl, apiToken$1, param.clientTimeoutMillis, HyperSyncClient.Registration.fromOnEventRegistrations(onEventRegistrations), !param.lowercaseAddresses, param.serializationFormat, param.enableQueryCaching, undefined, undefined, undefined, param.logLevel);
|
|
116
32
|
} catch (raw_exn) {
|
|
117
33
|
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
118
34
|
client = ErrorHandling.mkLogAndRaise(undefined, "Failed to instantiate the hypersync client, please double check your ABI", exn);
|
|
119
35
|
}
|
|
120
|
-
let
|
|
121
|
-
let makeEventBatchQueueItem = (item, params, onEventRegistration) => {
|
|
36
|
+
let makeEventBatchQueueItem = (item, onEventRegistration) => {
|
|
122
37
|
let logIndex = item.logIndex;
|
|
123
38
|
return {
|
|
124
39
|
kind: 0,
|
|
@@ -130,27 +45,19 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
130
45
|
payload: {
|
|
131
46
|
contractName: onEventRegistration.eventConfig.contractName,
|
|
132
47
|
eventName: onEventRegistration.eventConfig.name,
|
|
133
|
-
params: params,
|
|
48
|
+
params: item.params,
|
|
134
49
|
chainId: chain,
|
|
135
50
|
srcAddress: item.srcAddress,
|
|
136
51
|
logIndex: logIndex
|
|
137
52
|
}
|
|
138
53
|
};
|
|
139
54
|
};
|
|
140
|
-
let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName,
|
|
55
|
+
let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName, param, knownHeight, param$1, selection, itemsTarget, retry, param$2) => {
|
|
141
56
|
let totalTimeRef = Performance.now();
|
|
142
|
-
let selectionConfig = getSelectionConfig$1(selection);
|
|
143
|
-
let logSelections;
|
|
144
|
-
try {
|
|
145
|
-
logSelections = selectionConfig.getLogSelectionOrThrow(addressesByContractName);
|
|
146
|
-
} catch (raw_exn) {
|
|
147
|
-
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
148
|
-
logSelections = ErrorHandling.mkLogAndRaise(logger, "Failed getting log selection for the query", exn);
|
|
149
|
-
}
|
|
150
57
|
let startFetchingBatchTimeRef = Performance.now();
|
|
151
58
|
let pageUnsafe;
|
|
152
59
|
try {
|
|
153
|
-
pageUnsafe = await HyperSync.GetLogs.query(client, fromBlock, toBlock,
|
|
60
|
+
pageUnsafe = await HyperSync.GetLogs.query(client, fromBlock, toBlock, itemsTarget, selection.onEventRegistrations.map(reg => reg.index), addressesByContractName);
|
|
154
61
|
} catch (raw_error) {
|
|
155
62
|
let error = Primitive_exceptions.internalToException(raw_error);
|
|
156
63
|
if (error.RE_EXN_ID === HyperSync.GetLogs.$$Error) {
|
|
@@ -212,32 +119,8 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
212
119
|
blocksByNumber.set(block.number, block);
|
|
213
120
|
});
|
|
214
121
|
pageUnsafe.items.forEach(item => {
|
|
215
|
-
let
|
|
216
|
-
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
let params = Stdlib_Option.flatMap(Primitive_option.fromNullable(item.params), __x => __x[maybeEventConfig.eventConfig.contractName]);
|
|
220
|
-
if (params !== undefined) {
|
|
221
|
-
parsedQueueItems.push(makeEventBatchQueueItem(item, Primitive_option.valFromOption(params), maybeEventConfig));
|
|
222
|
-
return;
|
|
223
|
-
} else {
|
|
224
|
-
let logIndex = item.logIndex;
|
|
225
|
-
let blockNumber = item.blockNumber;
|
|
226
|
-
let exn = {
|
|
227
|
-
RE_EXN_ID: UndefinedValue
|
|
228
|
-
};
|
|
229
|
-
if (maybeEventConfig.isWildcard) {
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
let msg = `Event ` + maybeEventConfig.eventConfig.name + ` was unexpectedly parsed as undefined`;
|
|
233
|
-
let logger$1 = Logging.createChildFrom(logger, {
|
|
234
|
-
chainId: chain,
|
|
235
|
-
blockNumber: blockNumber,
|
|
236
|
-
logIndex: logIndex,
|
|
237
|
-
decoder: "hypersync-client"
|
|
238
|
-
});
|
|
239
|
-
return ErrorHandling.mkLogAndRaise(logger$1, msg, exn);
|
|
240
|
-
}
|
|
122
|
+
let onEventRegistration = onEventRegistrations[item.onEventRegistrationIndex];
|
|
123
|
+
parsedQueueItems.push(makeEventBatchQueueItem(item, onEventRegistration));
|
|
241
124
|
});
|
|
242
125
|
let parsingTimeElapsed = Performance.secondsSince(parsingTimeRef);
|
|
243
126
|
let blockHashes = [];
|
|
@@ -346,9 +229,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
346
229
|
}
|
|
347
230
|
|
|
348
231
|
export {
|
|
349
|
-
getSelectionConfig,
|
|
350
|
-
memoGetSelectionConfig,
|
|
351
232
|
isUnauthorizedError,
|
|
352
233
|
make,
|
|
353
234
|
}
|
|
354
|
-
/*
|
|
235
|
+
/* Logging Not a pure module */
|
package/src/sources/Rpc.res
CHANGED
|
@@ -82,38 +82,6 @@ let decimalFloatSchema: S.schema<float> = S.string->S.transform(s => {
|
|
|
82
82
|
})
|
|
83
83
|
|
|
84
84
|
module GetLogs = {
|
|
85
|
-
@unboxed
|
|
86
|
-
type topicFilter = Single(hex) | Multiple(array<hex>) | @as(null) Null
|
|
87
|
-
type topicQuery = array<topicFilter>
|
|
88
|
-
|
|
89
|
-
let makeTopicQuery = (~topic0=[], ~topic1=[], ~topic2=[], ~topic3=[]) => {
|
|
90
|
-
let topics = [topic0, topic1, topic2, topic3]
|
|
91
|
-
|
|
92
|
-
let isLastTopicEmpty = () =>
|
|
93
|
-
switch topics->Utils.Array.last {
|
|
94
|
-
| Some([]) => true
|
|
95
|
-
| _ => false
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
//Remove all empty topics from the end of the array
|
|
99
|
-
while isLastTopicEmpty() {
|
|
100
|
-
topics->Array.pop->ignore
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
let toTopicFilter = topic => {
|
|
104
|
-
switch topic {
|
|
105
|
-
| [] => Null
|
|
106
|
-
| [single] => Single(single->EvmTypes.Hex.toString)
|
|
107
|
-
| multiple => Multiple(multiple->EvmTypes.Hex.toStrings)
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
topics->Array.map(toTopicFilter)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
let mapTopicQuery = ({topic0, topic1, topic2, topic3}: Internal.topicSelection): topicQuery =>
|
|
115
|
-
makeTopicQuery(~topic0, ~topic1, ~topic2, ~topic3)
|
|
116
|
-
|
|
117
85
|
type log = {
|
|
118
86
|
address: Address.t,
|
|
119
87
|
topics: array<hex>,
|
package/src/sources/Rpc.res.mjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import * as Rest from "../vendored/Rest.res.mjs";
|
|
4
4
|
import * as Viem from "viem";
|
|
5
|
-
import * as Utils from "../Utils.res.mjs";
|
|
6
5
|
import * as Address from "../Address.res.mjs";
|
|
7
6
|
import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
|
|
8
7
|
import * as Stdlib_BigInt from "@rescript/runtime/lib/es6/Stdlib_BigInt.js";
|
|
@@ -95,51 +94,7 @@ let decimalFloatSchema = S$RescriptSchema.transform(S$RescriptSchema.string, s =
|
|
|
95
94
|
}
|
|
96
95
|
}));
|
|
97
96
|
|
|
98
|
-
|
|
99
|
-
let topic0 = topic0Opt !== undefined ? topic0Opt : [];
|
|
100
|
-
let topic1 = topic1Opt !== undefined ? topic1Opt : [];
|
|
101
|
-
let topic2 = topic2Opt !== undefined ? topic2Opt : [];
|
|
102
|
-
let topic3 = topic3Opt !== undefined ? topic3Opt : [];
|
|
103
|
-
let topics = [
|
|
104
|
-
topic0,
|
|
105
|
-
topic1,
|
|
106
|
-
topic2,
|
|
107
|
-
topic3
|
|
108
|
-
];
|
|
109
|
-
let isLastTopicEmpty = () => {
|
|
110
|
-
let match = Utils.$$Array.last(topics);
|
|
111
|
-
if (match !== undefined) {
|
|
112
|
-
return match.length === 0;
|
|
113
|
-
} else {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
while (isLastTopicEmpty()) {
|
|
118
|
-
topics.pop();
|
|
119
|
-
};
|
|
120
|
-
let toTopicFilter = topic => {
|
|
121
|
-
let len = topic.length;
|
|
122
|
-
if (len !== 1) {
|
|
123
|
-
if (len !== 0) {
|
|
124
|
-
return topic;
|
|
125
|
-
} else {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
let single = topic[0];
|
|
130
|
-
return single;
|
|
131
|
-
};
|
|
132
|
-
return topics.map(toTopicFilter);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function mapTopicQuery(param) {
|
|
136
|
-
return makeTopicQuery(param.topic0, param.topic1, param.topic2, param.topic3);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
let GetLogs = {
|
|
140
|
-
makeTopicQuery: makeTopicQuery,
|
|
141
|
-
mapTopicQuery: mapTopicQuery
|
|
142
|
-
};
|
|
97
|
+
let GetLogs = {};
|
|
143
98
|
|
|
144
99
|
let blockSchema = S$RescriptSchema.object(s => ({
|
|
145
100
|
difficulty: s.f("difficulty", S$RescriptSchema.$$null(hexBigintSchema)),
|