envio 3.0.0-alpha.2 → 3.0.0-alpha.21
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/README.md +164 -30
- package/bin.mjs +49 -0
- package/evm.schema.json +79 -169
- package/fuel.schema.json +50 -21
- package/index.d.ts +578 -1
- package/index.js +4 -0
- package/package.json +47 -31
- package/rescript.json +4 -1
- package/src/Batch.res +11 -8
- package/src/Batch.res.mjs +11 -9
- package/src/ChainFetcher.res +531 -0
- package/src/ChainFetcher.res.mjs +339 -0
- package/src/ChainManager.res +190 -0
- package/src/ChainManager.res.mjs +166 -0
- package/src/Change.res +3 -3
- package/src/Config.gen.ts +19 -0
- package/src/Config.res +725 -25
- package/src/Config.res.mjs +692 -26
- package/src/{Indexer.res → Ctx.res} +1 -1
- package/src/Ecosystem.res +9 -124
- package/src/Ecosystem.res.mjs +19 -160
- package/src/Env.res +33 -73
- package/src/Env.res.mjs +29 -85
- package/src/Envio.gen.ts +3 -1
- package/src/Envio.res +77 -9
- package/src/Envio.res.mjs +39 -1
- package/src/EventConfigBuilder.res +408 -0
- package/src/EventConfigBuilder.res.mjs +376 -0
- package/src/EventProcessing.res +469 -0
- package/src/EventProcessing.res.mjs +337 -0
- package/src/EvmTypes.gen.ts +6 -0
- package/src/EvmTypes.res +1 -0
- package/src/FetchState.res +1256 -639
- package/src/FetchState.res.mjs +1135 -612
- package/src/GlobalState.res +1224 -0
- package/src/GlobalState.res.mjs +1291 -0
- package/src/GlobalStateManager.res +68 -0
- package/src/GlobalStateManager.res.mjs +75 -0
- package/src/GlobalStateManager.resi +7 -0
- package/src/HandlerLoader.res +89 -0
- package/src/HandlerLoader.res.mjs +79 -0
- package/src/HandlerRegister.res +357 -0
- package/src/HandlerRegister.res.mjs +299 -0
- package/src/HandlerRegister.resi +30 -0
- package/src/Hasura.res +111 -175
- package/src/Hasura.res.mjs +88 -150
- package/src/InMemoryStore.res +1 -1
- package/src/InMemoryStore.res.mjs +3 -3
- package/src/InMemoryTable.res +1 -1
- package/src/InMemoryTable.res.mjs +1 -1
- package/src/Internal.gen.ts +6 -0
- package/src/Internal.res +265 -12
- package/src/Internal.res.mjs +115 -1
- package/src/LoadLayer.res +444 -0
- package/src/LoadLayer.res.mjs +296 -0
- package/src/LoadLayer.resi +32 -0
- package/src/LogSelection.res +33 -27
- package/src/LogSelection.res.mjs +6 -0
- package/src/Logging.res +21 -7
- package/src/Logging.res.mjs +16 -8
- package/src/Main.res +390 -0
- package/src/Main.res.mjs +341 -0
- package/src/Persistence.res +7 -21
- package/src/Persistence.res.mjs +3 -3
- package/src/PgStorage.gen.ts +10 -0
- package/src/PgStorage.res +116 -69
- package/src/PgStorage.res.d.mts +5 -0
- package/src/PgStorage.res.mjs +93 -50
- package/src/Prometheus.res +294 -224
- package/src/Prometheus.res.mjs +353 -340
- package/src/ReorgDetection.res +6 -10
- package/src/ReorgDetection.res.mjs +6 -6
- package/src/SafeCheckpointTracking.res +4 -4
- package/src/SafeCheckpointTracking.res.mjs +2 -2
- package/src/SimulateItems.res +353 -0
- package/src/SimulateItems.res.mjs +335 -0
- package/src/Sink.res +4 -2
- package/src/Sink.res.mjs +2 -1
- package/src/TableIndices.res +0 -1
- package/src/TestIndexer.res +913 -0
- package/src/TestIndexer.res.mjs +698 -0
- package/src/TestIndexerProxyStorage.res +205 -0
- package/src/TestIndexerProxyStorage.res.mjs +151 -0
- package/src/TopicFilter.res +1 -1
- package/src/Types.ts +1 -1
- package/src/UserContext.res +424 -0
- package/src/UserContext.res.mjs +279 -0
- package/src/Utils.res +97 -26
- package/src/Utils.res.mjs +91 -44
- package/src/bindings/BigInt.res +10 -0
- package/src/bindings/BigInt.res.mjs +15 -0
- package/src/bindings/ClickHouse.res +120 -23
- package/src/bindings/ClickHouse.res.mjs +118 -28
- package/src/bindings/DateFns.res +74 -0
- package/src/bindings/DateFns.res.mjs +22 -0
- package/src/bindings/EventSource.res +11 -2
- package/src/bindings/EventSource.res.mjs +8 -1
- package/src/bindings/Express.res +1 -0
- package/src/bindings/Hrtime.res +14 -1
- package/src/bindings/Hrtime.res.mjs +22 -2
- package/src/bindings/Hrtime.resi +4 -0
- package/src/bindings/Lodash.res +0 -1
- package/src/bindings/NodeJs.res +49 -3
- package/src/bindings/NodeJs.res.mjs +11 -3
- package/src/bindings/Pino.res +24 -10
- package/src/bindings/Pino.res.mjs +14 -8
- package/src/bindings/Postgres.gen.ts +8 -0
- package/src/bindings/Postgres.res +5 -1
- package/src/bindings/Postgres.res.d.mts +5 -0
- package/src/bindings/PromClient.res +0 -10
- package/src/bindings/PromClient.res.mjs +0 -3
- package/src/bindings/Vitest.res +144 -0
- package/src/bindings/Vitest.res.mjs +9 -0
- package/src/bindings/WebSocket.res +27 -0
- package/src/bindings/WebSocket.res.mjs +2 -0
- package/src/bindings/Yargs.res +8 -0
- package/src/bindings/Yargs.res.mjs +2 -0
- package/src/db/EntityHistory.res +7 -7
- package/src/db/EntityHistory.res.mjs +9 -9
- package/src/db/InternalTable.res +59 -111
- package/src/db/InternalTable.res.mjs +73 -104
- package/src/db/Table.res +27 -8
- package/src/db/Table.res.mjs +25 -14
- package/src/sources/Evm.res +84 -0
- package/src/sources/Evm.res.mjs +105 -0
- package/src/sources/EvmChain.res +94 -0
- package/src/sources/EvmChain.res.mjs +60 -0
- package/src/sources/Fuel.res +19 -34
- package/src/sources/Fuel.res.mjs +34 -16
- package/src/sources/FuelSDK.res +38 -0
- package/src/sources/FuelSDK.res.mjs +29 -0
- package/src/sources/HyperFuel.res +2 -2
- package/src/sources/HyperFuel.resi +1 -1
- package/src/sources/HyperFuelClient.res +2 -2
- package/src/sources/HyperFuelSource.res +35 -13
- package/src/sources/HyperFuelSource.res.mjs +26 -16
- package/src/sources/HyperSync.res +61 -60
- package/src/sources/HyperSync.res.mjs +53 -67
- package/src/sources/HyperSync.resi +6 -4
- package/src/sources/HyperSyncClient.res +29 -2
- package/src/sources/HyperSyncClient.res.mjs +9 -0
- package/src/sources/HyperSyncHeightStream.res +76 -118
- package/src/sources/HyperSyncHeightStream.res.mjs +68 -75
- package/src/sources/HyperSyncSource.res +122 -143
- package/src/sources/HyperSyncSource.res.mjs +106 -121
- package/src/sources/Rpc.res +86 -14
- package/src/sources/Rpc.res.mjs +101 -9
- package/src/sources/RpcSource.res +731 -364
- package/src/sources/RpcSource.res.mjs +845 -410
- package/src/sources/RpcWebSocketHeightStream.res +181 -0
- package/src/sources/RpcWebSocketHeightStream.res.mjs +196 -0
- package/src/sources/SimulateSource.res +59 -0
- package/src/sources/SimulateSource.res.mjs +50 -0
- package/src/sources/Source.res +7 -5
- package/src/sources/SourceManager.res +358 -221
- package/src/sources/SourceManager.res.mjs +346 -171
- package/src/sources/SourceManager.resi +17 -6
- package/src/sources/Svm.res +81 -0
- package/src/sources/Svm.res.mjs +90 -0
- package/src/tui/Tui.res +247 -0
- package/src/tui/Tui.res.mjs +337 -0
- package/src/tui/bindings/Ink.res +371 -0
- package/src/tui/bindings/Ink.res.mjs +72 -0
- package/src/tui/bindings/Style.res +123 -0
- package/src/tui/bindings/Style.res.mjs +2 -0
- package/src/tui/components/BufferedProgressBar.res +40 -0
- package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
- package/src/tui/components/CustomHooks.res +122 -0
- package/src/tui/components/CustomHooks.res.mjs +179 -0
- package/src/tui/components/Messages.res +41 -0
- package/src/tui/components/Messages.res.mjs +75 -0
- package/src/tui/components/SyncETA.res +174 -0
- package/src/tui/components/SyncETA.res.mjs +263 -0
- package/src/tui/components/TuiData.res +47 -0
- package/src/tui/components/TuiData.res.mjs +34 -0
- package/svm.schema.json +112 -0
- package/bin.js +0 -48
- package/src/EventRegister.res +0 -241
- package/src/EventRegister.res.mjs +0 -240
- package/src/EventRegister.resi +0 -30
- package/src/bindings/Ethers.gen.ts +0 -14
- package/src/bindings/Ethers.res +0 -204
- package/src/bindings/Ethers.res.mjs +0 -130
- /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var cleanUpRawEventFieldsInPlace = (fields => {
|
|
5
|
+
delete fields.hash
|
|
6
|
+
delete fields.number
|
|
7
|
+
delete fields.timestamp
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
var ecosystem_blockFields = [
|
|
11
|
+
"number",
|
|
12
|
+
"timestamp",
|
|
13
|
+
"hash",
|
|
14
|
+
"parentHash",
|
|
15
|
+
"nonce",
|
|
16
|
+
"sha3Uncles",
|
|
17
|
+
"logsBloom",
|
|
18
|
+
"transactionsRoot",
|
|
19
|
+
"stateRoot",
|
|
20
|
+
"receiptsRoot",
|
|
21
|
+
"miner",
|
|
22
|
+
"difficulty",
|
|
23
|
+
"totalDifficulty",
|
|
24
|
+
"extraData",
|
|
25
|
+
"size",
|
|
26
|
+
"gasLimit",
|
|
27
|
+
"gasUsed",
|
|
28
|
+
"uncles",
|
|
29
|
+
"baseFeePerGas",
|
|
30
|
+
"blobGasUsed",
|
|
31
|
+
"excessBlobGas",
|
|
32
|
+
"parentBeaconBlockRoot",
|
|
33
|
+
"withdrawalsRoot",
|
|
34
|
+
"l1BlockNumber",
|
|
35
|
+
"sendCount",
|
|
36
|
+
"sendRoot",
|
|
37
|
+
"mixHash"
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
var ecosystem_transactionFields = [
|
|
41
|
+
"transactionIndex",
|
|
42
|
+
"hash",
|
|
43
|
+
"from",
|
|
44
|
+
"to",
|
|
45
|
+
"gas",
|
|
46
|
+
"gasPrice",
|
|
47
|
+
"maxPriorityFeePerGas",
|
|
48
|
+
"maxFeePerGas",
|
|
49
|
+
"cumulativeGasUsed",
|
|
50
|
+
"effectiveGasPrice",
|
|
51
|
+
"gasUsed",
|
|
52
|
+
"input",
|
|
53
|
+
"nonce",
|
|
54
|
+
"value",
|
|
55
|
+
"v",
|
|
56
|
+
"r",
|
|
57
|
+
"s",
|
|
58
|
+
"contractAddress",
|
|
59
|
+
"logsBloom",
|
|
60
|
+
"root",
|
|
61
|
+
"status",
|
|
62
|
+
"yParity",
|
|
63
|
+
"chainId",
|
|
64
|
+
"maxFeePerBlobGas",
|
|
65
|
+
"blobVersionedHashes",
|
|
66
|
+
"type",
|
|
67
|
+
"l1Fee",
|
|
68
|
+
"l1GasPrice",
|
|
69
|
+
"l1GasUsed",
|
|
70
|
+
"l1FeeScalar",
|
|
71
|
+
"gasUsedForL1",
|
|
72
|
+
"accessList",
|
|
73
|
+
"authorizationList"
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
function ecosystem_getNumber(prim) {
|
|
77
|
+
return prim.number;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function ecosystem_getTimestamp(prim) {
|
|
81
|
+
return prim.timestamp;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function ecosystem_getId(prim) {
|
|
85
|
+
return prim.hash;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
var ecosystem = {
|
|
89
|
+
name: "evm",
|
|
90
|
+
blockFields: ecosystem_blockFields,
|
|
91
|
+
transactionFields: ecosystem_transactionFields,
|
|
92
|
+
blockNumberName: "number",
|
|
93
|
+
blockTimestampName: "timestamp",
|
|
94
|
+
blockHashName: "hash",
|
|
95
|
+
getNumber: ecosystem_getNumber,
|
|
96
|
+
getTimestamp: ecosystem_getTimestamp,
|
|
97
|
+
getId: ecosystem_getId,
|
|
98
|
+
cleanUpRawEventFieldsInPlace: cleanUpRawEventFieldsInPlace
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export {
|
|
102
|
+
cleanUpRawEventFieldsInPlace ,
|
|
103
|
+
ecosystem ,
|
|
104
|
+
}
|
|
105
|
+
/* No side effect */
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
open Belt
|
|
2
|
+
|
|
3
|
+
type rpc = {
|
|
4
|
+
url: string,
|
|
5
|
+
sourceFor: Source.sourceFor,
|
|
6
|
+
syncConfig?: Config.sourceSyncOptions,
|
|
7
|
+
ws?: string,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let getSyncConfig = (
|
|
11
|
+
{
|
|
12
|
+
?initialBlockInterval,
|
|
13
|
+
?backoffMultiplicative,
|
|
14
|
+
?accelerationAdditive,
|
|
15
|
+
?intervalCeiling,
|
|
16
|
+
?backoffMillis,
|
|
17
|
+
?queryTimeoutMillis,
|
|
18
|
+
?fallbackStallTimeout,
|
|
19
|
+
?pollingInterval,
|
|
20
|
+
}: Config.sourceSyncOptions,
|
|
21
|
+
): Config.sourceSync => {
|
|
22
|
+
let queryTimeoutMillis = queryTimeoutMillis->Option.getWithDefault(20_000)
|
|
23
|
+
{
|
|
24
|
+
initialBlockInterval: Env.Configurable.SyncConfig.initialBlockInterval->Option.getWithDefault(
|
|
25
|
+
initialBlockInterval->Option.getWithDefault(10_000),
|
|
26
|
+
),
|
|
27
|
+
// After an RPC error, how much to scale back the number of blocks requested at once
|
|
28
|
+
backoffMultiplicative: Env.Configurable.SyncConfig.backoffMultiplicative->Option.getWithDefault(
|
|
29
|
+
backoffMultiplicative->Option.getWithDefault(0.8),
|
|
30
|
+
),
|
|
31
|
+
// Without RPC errors or timeouts, how much to increase the number of blocks requested by for the next batch
|
|
32
|
+
accelerationAdditive: Env.Configurable.SyncConfig.accelerationAdditive->Option.getWithDefault(
|
|
33
|
+
accelerationAdditive->Option.getWithDefault(500),
|
|
34
|
+
),
|
|
35
|
+
// Do not further increase the block interval past this limit
|
|
36
|
+
intervalCeiling: Env.Configurable.SyncConfig.intervalCeiling->Option.getWithDefault(
|
|
37
|
+
intervalCeiling->Option.getWithDefault(10_000),
|
|
38
|
+
),
|
|
39
|
+
// After an error, how long to wait before retrying
|
|
40
|
+
backoffMillis: backoffMillis->Option.getWithDefault(5000),
|
|
41
|
+
// How long to wait before cancelling an RPC request
|
|
42
|
+
queryTimeoutMillis,
|
|
43
|
+
fallbackStallTimeout: fallbackStallTimeout->Option.getWithDefault(queryTimeoutMillis / 2),
|
|
44
|
+
// How frequently to check for new blocks in realtime (default: 1000ms)
|
|
45
|
+
pollingInterval: pollingInterval->Option.getWithDefault(1000),
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let makeSources = (
|
|
50
|
+
~chain,
|
|
51
|
+
~contracts: array<Internal.evmContractConfig>,
|
|
52
|
+
~hyperSync,
|
|
53
|
+
~allEventSignatures,
|
|
54
|
+
~rpcs: array<rpc>,
|
|
55
|
+
~lowercaseAddresses,
|
|
56
|
+
) => {
|
|
57
|
+
let eventRouter =
|
|
58
|
+
contracts
|
|
59
|
+
->Belt.Array.flatMap(contract => contract.events)
|
|
60
|
+
->EventRouter.fromEvmEventModsOrThrow(~chain)
|
|
61
|
+
|
|
62
|
+
let sources = switch hyperSync {
|
|
63
|
+
| Some(endpointUrl) => [
|
|
64
|
+
HyperSyncSource.make({
|
|
65
|
+
chain,
|
|
66
|
+
endpointUrl,
|
|
67
|
+
allEventSignatures,
|
|
68
|
+
eventRouter,
|
|
69
|
+
apiToken: Env.envioApiToken,
|
|
70
|
+
clientMaxRetries: Env.hyperSyncClientMaxRetries,
|
|
71
|
+
clientTimeoutMillis: Env.hyperSyncClientTimeoutMillis,
|
|
72
|
+
lowercaseAddresses,
|
|
73
|
+
serializationFormat: Env.hypersyncClientSerializationFormat,
|
|
74
|
+
enableQueryCaching: Env.hypersyncClientEnableQueryCaching,
|
|
75
|
+
}),
|
|
76
|
+
]
|
|
77
|
+
| _ => []
|
|
78
|
+
}
|
|
79
|
+
rpcs->Js.Array2.forEach(({?syncConfig, url, sourceFor, ?ws}) => {
|
|
80
|
+
let source = RpcSource.make({
|
|
81
|
+
chain,
|
|
82
|
+
sourceFor,
|
|
83
|
+
syncConfig: getSyncConfig(syncConfig->Option.getWithDefault({})),
|
|
84
|
+
url,
|
|
85
|
+
eventRouter,
|
|
86
|
+
allEventSignatures,
|
|
87
|
+
lowercaseAddresses,
|
|
88
|
+
?ws,
|
|
89
|
+
})
|
|
90
|
+
let _ = sources->Js.Array2.push(source)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
sources
|
|
94
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Env from "../Env.res.mjs";
|
|
4
|
+
import * as RpcSource from "./RpcSource.res.mjs";
|
|
5
|
+
import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
|
|
6
|
+
import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
|
|
7
|
+
import * as EventRouter from "./EventRouter.res.mjs";
|
|
8
|
+
import * as HyperSyncSource from "./HyperSyncSource.res.mjs";
|
|
9
|
+
|
|
10
|
+
function getSyncConfig(param) {
|
|
11
|
+
var queryTimeoutMillis = Belt_Option.getWithDefault(param.queryTimeoutMillis, 20000);
|
|
12
|
+
return {
|
|
13
|
+
initialBlockInterval: Belt_Option.getWithDefault(Env.Configurable.SyncConfig.initialBlockInterval, Belt_Option.getWithDefault(param.initialBlockInterval, 10000)),
|
|
14
|
+
backoffMultiplicative: Belt_Option.getWithDefault(Env.Configurable.SyncConfig.backoffMultiplicative, Belt_Option.getWithDefault(param.backoffMultiplicative, 0.8)),
|
|
15
|
+
accelerationAdditive: Belt_Option.getWithDefault(Env.Configurable.SyncConfig.accelerationAdditive, Belt_Option.getWithDefault(param.accelerationAdditive, 500)),
|
|
16
|
+
intervalCeiling: Belt_Option.getWithDefault(Env.Configurable.SyncConfig.intervalCeiling, Belt_Option.getWithDefault(param.intervalCeiling, 10000)),
|
|
17
|
+
backoffMillis: Belt_Option.getWithDefault(param.backoffMillis, 5000),
|
|
18
|
+
queryTimeoutMillis: queryTimeoutMillis,
|
|
19
|
+
fallbackStallTimeout: Belt_Option.getWithDefault(param.fallbackStallTimeout, queryTimeoutMillis / 2 | 0),
|
|
20
|
+
pollingInterval: Belt_Option.getWithDefault(param.pollingInterval, 1000)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function makeSources(chain, contracts, hyperSync, allEventSignatures, rpcs, lowercaseAddresses) {
|
|
25
|
+
var eventRouter = EventRouter.fromEvmEventModsOrThrow(Belt_Array.flatMap(contracts, (function (contract) {
|
|
26
|
+
return contract.events;
|
|
27
|
+
})), chain);
|
|
28
|
+
var sources = hyperSync !== undefined ? [HyperSyncSource.make({
|
|
29
|
+
chain: chain,
|
|
30
|
+
endpointUrl: hyperSync,
|
|
31
|
+
allEventSignatures: allEventSignatures,
|
|
32
|
+
eventRouter: eventRouter,
|
|
33
|
+
apiToken: Env.envioApiToken,
|
|
34
|
+
clientMaxRetries: Env.hyperSyncClientMaxRetries,
|
|
35
|
+
clientTimeoutMillis: Env.hyperSyncClientTimeoutMillis,
|
|
36
|
+
lowercaseAddresses: lowercaseAddresses,
|
|
37
|
+
serializationFormat: Env.hypersyncClientSerializationFormat,
|
|
38
|
+
enableQueryCaching: Env.hypersyncClientEnableQueryCaching
|
|
39
|
+
})] : [];
|
|
40
|
+
rpcs.forEach(function (param) {
|
|
41
|
+
var source = RpcSource.make({
|
|
42
|
+
sourceFor: param.sourceFor,
|
|
43
|
+
syncConfig: getSyncConfig(Belt_Option.getWithDefault(param.syncConfig, {})),
|
|
44
|
+
url: param.url,
|
|
45
|
+
chain: chain,
|
|
46
|
+
eventRouter: eventRouter,
|
|
47
|
+
allEventSignatures: allEventSignatures,
|
|
48
|
+
lowercaseAddresses: lowercaseAddresses,
|
|
49
|
+
ws: param.ws
|
|
50
|
+
});
|
|
51
|
+
sources.push(source);
|
|
52
|
+
});
|
|
53
|
+
return sources;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
getSyncConfig ,
|
|
58
|
+
makeSources ,
|
|
59
|
+
}
|
|
60
|
+
/* Env Not a pure module */
|
package/src/sources/Fuel.res
CHANGED
|
@@ -1,37 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
| @as(2) ReturnData
|
|
5
|
-
| @as(3) Panic
|
|
6
|
-
| @as(4) Revert
|
|
7
|
-
| @as(5) Log
|
|
8
|
-
| @as(6) LogData
|
|
9
|
-
// Transfer is to another contract, TransferOut is to wallet address
|
|
10
|
-
| @as(7) Transfer
|
|
11
|
-
| @as(8) TransferOut
|
|
12
|
-
| @as(9) ScriptResult
|
|
13
|
-
| @as(10) MessageOut
|
|
14
|
-
| @as(11) Mint
|
|
15
|
-
| @as(12) Burn
|
|
1
|
+
@get external getNumber: Internal.eventBlock => int = "height"
|
|
2
|
+
@get external getTimestamp: Internal.eventBlock => int = "time"
|
|
3
|
+
@get external getId: Internal.eventBlock => string = "id"
|
|
16
4
|
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
let cleanUpRawEventFieldsInPlace: Js.Json.t => unit = %raw(`fields => {
|
|
6
|
+
delete fields.id
|
|
7
|
+
delete fields.height
|
|
8
|
+
delete fields.time
|
|
9
|
+
}`)
|
|
19
10
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
| @as(12) Burn({val: bigint, subId: string})
|
|
32
|
-
|
|
33
|
-
let getLogDataDecoder = (~abi: Ethers.abi, ~logId: string) => {
|
|
34
|
-
let decode = getLogDecoder(~abi, ~logId)
|
|
35
|
-
data => data->decode->Utils.magic
|
|
36
|
-
}
|
|
11
|
+
let ecosystem: Ecosystem.t = {
|
|
12
|
+
name: Fuel,
|
|
13
|
+
blockFields: ["id", "height", "time"],
|
|
14
|
+
transactionFields: ["id"],
|
|
15
|
+
blockNumberName: "height",
|
|
16
|
+
blockTimestampName: "time",
|
|
17
|
+
blockHashName: "id",
|
|
18
|
+
getNumber,
|
|
19
|
+
getTimestamp,
|
|
20
|
+
getId,
|
|
21
|
+
cleanUpRawEventFieldsInPlace,
|
|
37
22
|
}
|
package/src/sources/Fuel.res.mjs
CHANGED
|
@@ -1,29 +1,47 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as VendoredFuelAbiCoderJs from "./vendored-fuel-abi-coder.js";
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
var cleanUpRawEventFieldsInPlace = (fields => {
|
|
5
|
+
delete fields.id
|
|
6
|
+
delete fields.height
|
|
7
|
+
delete fields.time
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
var ecosystem_blockFields = [
|
|
11
|
+
"id",
|
|
12
|
+
"height",
|
|
13
|
+
"time"
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
var ecosystem_transactionFields = ["id"];
|
|
17
|
+
|
|
18
|
+
function ecosystem_getNumber(prim) {
|
|
19
|
+
return prim.height;
|
|
7
20
|
}
|
|
8
21
|
|
|
9
|
-
function
|
|
10
|
-
return
|
|
22
|
+
function ecosystem_getTimestamp(prim) {
|
|
23
|
+
return prim.time;
|
|
11
24
|
}
|
|
12
25
|
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
return function (data) {
|
|
16
|
-
return decode(data);
|
|
17
|
-
};
|
|
26
|
+
function ecosystem_getId(prim) {
|
|
27
|
+
return prim.id;
|
|
18
28
|
}
|
|
19
29
|
|
|
20
|
-
var
|
|
21
|
-
|
|
30
|
+
var ecosystem = {
|
|
31
|
+
name: "fuel",
|
|
32
|
+
blockFields: ecosystem_blockFields,
|
|
33
|
+
transactionFields: ecosystem_transactionFields,
|
|
34
|
+
blockNumberName: "height",
|
|
35
|
+
blockTimestampName: "time",
|
|
36
|
+
blockHashName: "id",
|
|
37
|
+
getNumber: ecosystem_getNumber,
|
|
38
|
+
getTimestamp: ecosystem_getTimestamp,
|
|
39
|
+
getId: ecosystem_getId,
|
|
40
|
+
cleanUpRawEventFieldsInPlace: cleanUpRawEventFieldsInPlace
|
|
22
41
|
};
|
|
23
42
|
|
|
24
43
|
export {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Receipt ,
|
|
44
|
+
cleanUpRawEventFieldsInPlace ,
|
|
45
|
+
ecosystem ,
|
|
28
46
|
}
|
|
29
|
-
/*
|
|
47
|
+
/* No side effect */
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
type receiptType =
|
|
2
|
+
| @as(0) Call
|
|
3
|
+
| @as(1) Return
|
|
4
|
+
| @as(2) ReturnData
|
|
5
|
+
| @as(3) Panic
|
|
6
|
+
| @as(4) Revert
|
|
7
|
+
| @as(5) Log
|
|
8
|
+
| @as(6) LogData
|
|
9
|
+
// Transfer is to another contract, TransferOut is to wallet address
|
|
10
|
+
| @as(7) Transfer
|
|
11
|
+
| @as(8) TransferOut
|
|
12
|
+
| @as(9) ScriptResult
|
|
13
|
+
| @as(10) MessageOut
|
|
14
|
+
| @as(11) Mint
|
|
15
|
+
| @as(12) Burn
|
|
16
|
+
|
|
17
|
+
@module("./vendored-fuel-abi-coder.js")
|
|
18
|
+
external transpileAbi: Js.Json.t => EvmTypes.Abi.t = "transpileAbi"
|
|
19
|
+
|
|
20
|
+
@module("./vendored-fuel-abi-coder.js") @scope("AbiCoder")
|
|
21
|
+
external getLogDecoder: (~abi: EvmTypes.Abi.t, ~logId: string) => string => unknown =
|
|
22
|
+
"getLogDecoder"
|
|
23
|
+
|
|
24
|
+
module Receipt = {
|
|
25
|
+
@tag("receiptType")
|
|
26
|
+
type t =
|
|
27
|
+
| @as(0) Call({assetId: string, amount: bigint, to: string})
|
|
28
|
+
| @as(6) LogData({data: string, rb: bigint})
|
|
29
|
+
| @as(7) Transfer({amount: bigint, assetId: string, to: string})
|
|
30
|
+
| @as(8) TransferOut({amount: bigint, assetId: string, toAddress: string})
|
|
31
|
+
| @as(11) Mint({val: bigint, subId: string})
|
|
32
|
+
| @as(12) Burn({val: bigint, subId: string})
|
|
33
|
+
|
|
34
|
+
let getLogDataDecoder = (~abi: EvmTypes.Abi.t, ~logId: string) => {
|
|
35
|
+
let decode = getLogDecoder(~abi, ~logId)
|
|
36
|
+
data => data->decode->(Utils.magic: 'a => Internal.eventParams)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as VendoredFuelAbiCoderJs from "./vendored-fuel-abi-coder.js";
|
|
4
|
+
|
|
5
|
+
function transpileAbi(prim) {
|
|
6
|
+
return VendoredFuelAbiCoderJs.transpileAbi(prim);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function getLogDecoder(prim0, prim1) {
|
|
10
|
+
return VendoredFuelAbiCoderJs.AbiCoder.getLogDecoder(prim0, prim1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getLogDataDecoder(abi, logId) {
|
|
14
|
+
var decode = VendoredFuelAbiCoderJs.AbiCoder.getLogDecoder(abi, logId);
|
|
15
|
+
return function (data) {
|
|
16
|
+
return decode(data);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var Receipt = {
|
|
21
|
+
getLogDataDecoder: getLogDataDecoder
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
transpileAbi ,
|
|
26
|
+
getLogDecoder ,
|
|
27
|
+
Receipt ,
|
|
28
|
+
}
|
|
29
|
+
/* ./vendored-fuel-abi-coder.js Not a pure module */
|
|
@@ -33,7 +33,7 @@ type block = {
|
|
|
33
33
|
type item = {
|
|
34
34
|
transactionId: string,
|
|
35
35
|
contractId: Address.t,
|
|
36
|
-
receipt:
|
|
36
|
+
receipt: FuelSDK.Receipt.t,
|
|
37
37
|
receiptIndex: int,
|
|
38
38
|
block: block,
|
|
39
39
|
}
|
|
@@ -148,7 +148,7 @@ module GetLogs = {
|
|
|
148
148
|
time: block.time,
|
|
149
149
|
},
|
|
150
150
|
contractId,
|
|
151
|
-
receipt: receipt->(Utils.magic: HyperFuelClient.FuelTypes.receipt =>
|
|
151
|
+
receipt: receipt->(Utils.magic: HyperFuelClient.FuelTypes.receipt => FuelSDK.Receipt.t),
|
|
152
152
|
receiptIndex: receipt.receiptIndex,
|
|
153
153
|
})
|
|
154
154
|
->ignore
|
|
@@ -106,7 +106,7 @@ module QueryTypes = {
|
|
|
106
106
|
rootContractId?: array<Address.t>,
|
|
107
107
|
toAddress?: array<string>,
|
|
108
108
|
assetId?: array<string>,
|
|
109
|
-
receiptType?: array<
|
|
109
|
+
receiptType?: array<FuelSDK.receiptType>,
|
|
110
110
|
sender?: array<string>,
|
|
111
111
|
recipient?: array<string>,
|
|
112
112
|
contractId?: array<Address.t>,
|
|
@@ -290,7 +290,7 @@ module FuelTypes = {
|
|
|
290
290
|
/** The length of the receipt. */
|
|
291
291
|
len?: bigint,
|
|
292
292
|
/** The type of receipt. */
|
|
293
|
-
receiptType:
|
|
293
|
+
receiptType: FuelSDK.receiptType,
|
|
294
294
|
/** 0 if script exited successfully, any otherwise. */
|
|
295
295
|
result?: int,
|
|
296
296
|
/** The amount of gas consumed by the script. */
|
|
@@ -15,7 +15,7 @@ type selectionConfig = {
|
|
|
15
15
|
eventRouter: EventRouter.t<Internal.fuelEventConfig>,
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
let logDataReceiptTypeSelection: array<
|
|
18
|
+
let logDataReceiptTypeSelection: array<FuelSDK.receiptType> = [LogData]
|
|
19
19
|
|
|
20
20
|
// only transactions with status 1 (success)
|
|
21
21
|
let txStatusSelection = [1]
|
|
@@ -114,10 +114,10 @@ let getSelectionConfig = (selection: FetchState.selection, ~chain) => {
|
|
|
114
114
|
let nonLogDataReceiptTypesByContract = Js.Dict.empty()
|
|
115
115
|
let nonLogDataWildcardReceiptTypes = []
|
|
116
116
|
|
|
117
|
-
let addNonLogDataWildcardReceiptTypes = (receiptType:
|
|
117
|
+
let addNonLogDataWildcardReceiptTypes = (receiptType: FuelSDK.receiptType) => {
|
|
118
118
|
nonLogDataWildcardReceiptTypes->Array.push(receiptType)->ignore
|
|
119
119
|
}
|
|
120
|
-
let addNonLogDataReceiptType = (contractName, receiptType:
|
|
120
|
+
let addNonLogDataReceiptType = (contractName, receiptType: FuelSDK.receiptType) => {
|
|
121
121
|
switch nonLogDataReceiptTypesByContract->Utils.Dict.dangerouslyGetNonOption(contractName) {
|
|
122
122
|
| None => nonLogDataReceiptTypesByContract->Js.Dict.set(contractName, [receiptType])
|
|
123
123
|
| Some(receiptTypes) => receiptTypes->Array.push(receiptType)->ignore // Duplication prevented by EventRouter
|
|
@@ -220,7 +220,7 @@ let make = ({chain, endpointUrl}: options): t => {
|
|
|
220
220
|
~toBlock,
|
|
221
221
|
~addressesByContractName,
|
|
222
222
|
~indexingContracts,
|
|
223
|
-
~
|
|
223
|
+
~knownHeight,
|
|
224
224
|
~partitionId as _,
|
|
225
225
|
~selection: FetchState.selection,
|
|
226
226
|
~retry,
|
|
@@ -235,6 +235,11 @@ let make = ({chain, endpointUrl}: options): t => {
|
|
|
235
235
|
let startFetchingBatchTimeRef = Hrtime.makeTimer()
|
|
236
236
|
|
|
237
237
|
//fetch batch
|
|
238
|
+
Prometheus.SourceRequestCount.increment(
|
|
239
|
+
~sourceName=name,
|
|
240
|
+
~chainId=chain->ChainMap.Chain.toChainId,
|
|
241
|
+
~method="getLogs",
|
|
242
|
+
)
|
|
238
243
|
let pageUnsafe = try await HyperFuel.GetLogs.query(
|
|
239
244
|
~serverUrl=endpointUrl,
|
|
240
245
|
~fromBlock,
|
|
@@ -246,7 +251,7 @@ let make = ({chain, endpointUrl}: options): t => {
|
|
|
246
251
|
Source.GetItemsError(
|
|
247
252
|
Source.FailedGettingItems({
|
|
248
253
|
exn: %raw(`null`),
|
|
249
|
-
attemptedToBlock: toBlock->Option.getWithDefault(
|
|
254
|
+
attemptedToBlock: toBlock->Option.getWithDefault(knownHeight),
|
|
250
255
|
retry: switch error {
|
|
251
256
|
| WrongInstance =>
|
|
252
257
|
let backoffMillis = switch retry {
|
|
@@ -272,7 +277,7 @@ let make = ({chain, endpointUrl}: options): t => {
|
|
|
272
277
|
Source.GetItemsError(
|
|
273
278
|
Source.FailedGettingItems({
|
|
274
279
|
exn,
|
|
275
|
-
attemptedToBlock: toBlock->Option.getWithDefault(
|
|
280
|
+
attemptedToBlock: toBlock->Option.getWithDefault(knownHeight),
|
|
276
281
|
retry: WithBackoff({
|
|
277
282
|
message: `Unexpected issue while fetching events from HyperFuel client. Attempt a retry.`,
|
|
278
283
|
backoffMillis: switch retry {
|
|
@@ -285,11 +290,10 @@ let make = ({chain, endpointUrl}: options): t => {
|
|
|
285
290
|
)
|
|
286
291
|
}
|
|
287
292
|
|
|
288
|
-
let pageFetchTime =
|
|
289
|
-
startFetchingBatchTimeRef->Hrtime.timeSince->Hrtime.toMillis->Hrtime.intFromMillis
|
|
293
|
+
let pageFetchTime = startFetchingBatchTimeRef->Hrtime.timeSince->Hrtime.toSecondsFloat
|
|
290
294
|
|
|
291
295
|
//set height and next from block
|
|
292
|
-
let
|
|
296
|
+
let knownHeight = pageUnsafe.archiveHeight
|
|
293
297
|
|
|
294
298
|
//The heighest (biggest) blocknumber that was accounted for in
|
|
295
299
|
//Our query. Not necessarily the blocknumber of the last log returned
|
|
@@ -444,6 +448,8 @@ let make = ({chain, endpointUrl}: options): t => {
|
|
|
444
448
|
blockNumber: block.height,
|
|
445
449
|
logIndex: receiptIndex,
|
|
446
450
|
event: {
|
|
451
|
+
contractName: eventConfig.contractName,
|
|
452
|
+
eventName: eventConfig.name,
|
|
447
453
|
chainId,
|
|
448
454
|
params,
|
|
449
455
|
transaction: {
|
|
@@ -456,7 +462,7 @@ let make = ({chain, endpointUrl}: options): t => {
|
|
|
456
462
|
})
|
|
457
463
|
})
|
|
458
464
|
|
|
459
|
-
let parsingTimeElapsed = parsingTimeRef->Hrtime.timeSince->Hrtime.
|
|
465
|
+
let parsingTimeElapsed = parsingTimeRef->Hrtime.timeSince->Hrtime.toSecondsFloat
|
|
460
466
|
|
|
461
467
|
let rangeLastBlock = await lastBlockQueriedPromise
|
|
462
468
|
|
|
@@ -465,7 +471,7 @@ let make = ({chain, endpointUrl}: options): t => {
|
|
|
465
471
|
prevRangeLastBlock: None,
|
|
466
472
|
}
|
|
467
473
|
|
|
468
|
-
let totalTimeElapsed = totalTimeRef->Hrtime.timeSince->Hrtime.
|
|
474
|
+
let totalTimeElapsed = totalTimeRef->Hrtime.timeSince->Hrtime.toSecondsFloat
|
|
469
475
|
|
|
470
476
|
let stats = {
|
|
471
477
|
totalTimeElapsed,
|
|
@@ -478,7 +484,7 @@ let make = ({chain, endpointUrl}: options): t => {
|
|
|
478
484
|
parsedQueueItems,
|
|
479
485
|
latestFetchedBlockNumber: rangeLastBlock.blockNumber,
|
|
480
486
|
stats,
|
|
481
|
-
|
|
487
|
+
knownHeight,
|
|
482
488
|
reorgGuard,
|
|
483
489
|
fromBlockQueried: fromBlock,
|
|
484
490
|
}
|
|
@@ -496,7 +502,23 @@ let make = ({chain, endpointUrl}: options): t => {
|
|
|
496
502
|
getBlockHashes,
|
|
497
503
|
pollingInterval: 100,
|
|
498
504
|
poweredByHyperSync: true,
|
|
499
|
-
getHeightOrThrow: () =>
|
|
505
|
+
getHeightOrThrow: async () => {
|
|
506
|
+
let timerRef = Hrtime.makeTimer()
|
|
507
|
+
let height = await HyperFuel.heightRoute->Rest.fetch((), ~client=jsonApiClient)
|
|
508
|
+
let seconds = timerRef->Hrtime.timeSince->Hrtime.toSecondsFloat
|
|
509
|
+
Prometheus.SourceRequestCount.increment(
|
|
510
|
+
~sourceName=name,
|
|
511
|
+
~chainId=chain->ChainMap.Chain.toChainId,
|
|
512
|
+
~method="getHeight",
|
|
513
|
+
)
|
|
514
|
+
Prometheus.SourceRequestCount.addSeconds(
|
|
515
|
+
~sourceName=name,
|
|
516
|
+
~chainId=chain->ChainMap.Chain.toChainId,
|
|
517
|
+
~method="getHeight",
|
|
518
|
+
~seconds,
|
|
519
|
+
)
|
|
520
|
+
height
|
|
521
|
+
},
|
|
500
522
|
getItemsOrThrow,
|
|
501
523
|
}
|
|
502
524
|
}
|