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.
Files changed (184) hide show
  1. package/README.md +164 -30
  2. package/bin.mjs +49 -0
  3. package/evm.schema.json +79 -169
  4. package/fuel.schema.json +50 -21
  5. package/index.d.ts +578 -1
  6. package/index.js +4 -0
  7. package/package.json +47 -31
  8. package/rescript.json +4 -1
  9. package/src/Batch.res +11 -8
  10. package/src/Batch.res.mjs +11 -9
  11. package/src/ChainFetcher.res +531 -0
  12. package/src/ChainFetcher.res.mjs +339 -0
  13. package/src/ChainManager.res +190 -0
  14. package/src/ChainManager.res.mjs +166 -0
  15. package/src/Change.res +3 -3
  16. package/src/Config.gen.ts +19 -0
  17. package/src/Config.res +725 -25
  18. package/src/Config.res.mjs +692 -26
  19. package/src/{Indexer.res → Ctx.res} +1 -1
  20. package/src/Ecosystem.res +9 -124
  21. package/src/Ecosystem.res.mjs +19 -160
  22. package/src/Env.res +33 -73
  23. package/src/Env.res.mjs +29 -85
  24. package/src/Envio.gen.ts +3 -1
  25. package/src/Envio.res +77 -9
  26. package/src/Envio.res.mjs +39 -1
  27. package/src/EventConfigBuilder.res +408 -0
  28. package/src/EventConfigBuilder.res.mjs +376 -0
  29. package/src/EventProcessing.res +469 -0
  30. package/src/EventProcessing.res.mjs +337 -0
  31. package/src/EvmTypes.gen.ts +6 -0
  32. package/src/EvmTypes.res +1 -0
  33. package/src/FetchState.res +1256 -639
  34. package/src/FetchState.res.mjs +1135 -612
  35. package/src/GlobalState.res +1224 -0
  36. package/src/GlobalState.res.mjs +1291 -0
  37. package/src/GlobalStateManager.res +68 -0
  38. package/src/GlobalStateManager.res.mjs +75 -0
  39. package/src/GlobalStateManager.resi +7 -0
  40. package/src/HandlerLoader.res +89 -0
  41. package/src/HandlerLoader.res.mjs +79 -0
  42. package/src/HandlerRegister.res +357 -0
  43. package/src/HandlerRegister.res.mjs +299 -0
  44. package/src/HandlerRegister.resi +30 -0
  45. package/src/Hasura.res +111 -175
  46. package/src/Hasura.res.mjs +88 -150
  47. package/src/InMemoryStore.res +1 -1
  48. package/src/InMemoryStore.res.mjs +3 -3
  49. package/src/InMemoryTable.res +1 -1
  50. package/src/InMemoryTable.res.mjs +1 -1
  51. package/src/Internal.gen.ts +6 -0
  52. package/src/Internal.res +265 -12
  53. package/src/Internal.res.mjs +115 -1
  54. package/src/LoadLayer.res +444 -0
  55. package/src/LoadLayer.res.mjs +296 -0
  56. package/src/LoadLayer.resi +32 -0
  57. package/src/LogSelection.res +33 -27
  58. package/src/LogSelection.res.mjs +6 -0
  59. package/src/Logging.res +21 -7
  60. package/src/Logging.res.mjs +16 -8
  61. package/src/Main.res +390 -0
  62. package/src/Main.res.mjs +341 -0
  63. package/src/Persistence.res +7 -21
  64. package/src/Persistence.res.mjs +3 -3
  65. package/src/PgStorage.gen.ts +10 -0
  66. package/src/PgStorage.res +116 -69
  67. package/src/PgStorage.res.d.mts +5 -0
  68. package/src/PgStorage.res.mjs +93 -50
  69. package/src/Prometheus.res +294 -224
  70. package/src/Prometheus.res.mjs +353 -340
  71. package/src/ReorgDetection.res +6 -10
  72. package/src/ReorgDetection.res.mjs +6 -6
  73. package/src/SafeCheckpointTracking.res +4 -4
  74. package/src/SafeCheckpointTracking.res.mjs +2 -2
  75. package/src/SimulateItems.res +353 -0
  76. package/src/SimulateItems.res.mjs +335 -0
  77. package/src/Sink.res +4 -2
  78. package/src/Sink.res.mjs +2 -1
  79. package/src/TableIndices.res +0 -1
  80. package/src/TestIndexer.res +913 -0
  81. package/src/TestIndexer.res.mjs +698 -0
  82. package/src/TestIndexerProxyStorage.res +205 -0
  83. package/src/TestIndexerProxyStorage.res.mjs +151 -0
  84. package/src/TopicFilter.res +1 -1
  85. package/src/Types.ts +1 -1
  86. package/src/UserContext.res +424 -0
  87. package/src/UserContext.res.mjs +279 -0
  88. package/src/Utils.res +97 -26
  89. package/src/Utils.res.mjs +91 -44
  90. package/src/bindings/BigInt.res +10 -0
  91. package/src/bindings/BigInt.res.mjs +15 -0
  92. package/src/bindings/ClickHouse.res +120 -23
  93. package/src/bindings/ClickHouse.res.mjs +118 -28
  94. package/src/bindings/DateFns.res +74 -0
  95. package/src/bindings/DateFns.res.mjs +22 -0
  96. package/src/bindings/EventSource.res +11 -2
  97. package/src/bindings/EventSource.res.mjs +8 -1
  98. package/src/bindings/Express.res +1 -0
  99. package/src/bindings/Hrtime.res +14 -1
  100. package/src/bindings/Hrtime.res.mjs +22 -2
  101. package/src/bindings/Hrtime.resi +4 -0
  102. package/src/bindings/Lodash.res +0 -1
  103. package/src/bindings/NodeJs.res +49 -3
  104. package/src/bindings/NodeJs.res.mjs +11 -3
  105. package/src/bindings/Pino.res +24 -10
  106. package/src/bindings/Pino.res.mjs +14 -8
  107. package/src/bindings/Postgres.gen.ts +8 -0
  108. package/src/bindings/Postgres.res +5 -1
  109. package/src/bindings/Postgres.res.d.mts +5 -0
  110. package/src/bindings/PromClient.res +0 -10
  111. package/src/bindings/PromClient.res.mjs +0 -3
  112. package/src/bindings/Vitest.res +144 -0
  113. package/src/bindings/Vitest.res.mjs +9 -0
  114. package/src/bindings/WebSocket.res +27 -0
  115. package/src/bindings/WebSocket.res.mjs +2 -0
  116. package/src/bindings/Yargs.res +8 -0
  117. package/src/bindings/Yargs.res.mjs +2 -0
  118. package/src/db/EntityHistory.res +7 -7
  119. package/src/db/EntityHistory.res.mjs +9 -9
  120. package/src/db/InternalTable.res +59 -111
  121. package/src/db/InternalTable.res.mjs +73 -104
  122. package/src/db/Table.res +27 -8
  123. package/src/db/Table.res.mjs +25 -14
  124. package/src/sources/Evm.res +84 -0
  125. package/src/sources/Evm.res.mjs +105 -0
  126. package/src/sources/EvmChain.res +94 -0
  127. package/src/sources/EvmChain.res.mjs +60 -0
  128. package/src/sources/Fuel.res +19 -34
  129. package/src/sources/Fuel.res.mjs +34 -16
  130. package/src/sources/FuelSDK.res +38 -0
  131. package/src/sources/FuelSDK.res.mjs +29 -0
  132. package/src/sources/HyperFuel.res +2 -2
  133. package/src/sources/HyperFuel.resi +1 -1
  134. package/src/sources/HyperFuelClient.res +2 -2
  135. package/src/sources/HyperFuelSource.res +35 -13
  136. package/src/sources/HyperFuelSource.res.mjs +26 -16
  137. package/src/sources/HyperSync.res +61 -60
  138. package/src/sources/HyperSync.res.mjs +53 -67
  139. package/src/sources/HyperSync.resi +6 -4
  140. package/src/sources/HyperSyncClient.res +29 -2
  141. package/src/sources/HyperSyncClient.res.mjs +9 -0
  142. package/src/sources/HyperSyncHeightStream.res +76 -118
  143. package/src/sources/HyperSyncHeightStream.res.mjs +68 -75
  144. package/src/sources/HyperSyncSource.res +122 -143
  145. package/src/sources/HyperSyncSource.res.mjs +106 -121
  146. package/src/sources/Rpc.res +86 -14
  147. package/src/sources/Rpc.res.mjs +101 -9
  148. package/src/sources/RpcSource.res +731 -364
  149. package/src/sources/RpcSource.res.mjs +845 -410
  150. package/src/sources/RpcWebSocketHeightStream.res +181 -0
  151. package/src/sources/RpcWebSocketHeightStream.res.mjs +196 -0
  152. package/src/sources/SimulateSource.res +59 -0
  153. package/src/sources/SimulateSource.res.mjs +50 -0
  154. package/src/sources/Source.res +7 -5
  155. package/src/sources/SourceManager.res +358 -221
  156. package/src/sources/SourceManager.res.mjs +346 -171
  157. package/src/sources/SourceManager.resi +17 -6
  158. package/src/sources/Svm.res +81 -0
  159. package/src/sources/Svm.res.mjs +90 -0
  160. package/src/tui/Tui.res +247 -0
  161. package/src/tui/Tui.res.mjs +337 -0
  162. package/src/tui/bindings/Ink.res +371 -0
  163. package/src/tui/bindings/Ink.res.mjs +72 -0
  164. package/src/tui/bindings/Style.res +123 -0
  165. package/src/tui/bindings/Style.res.mjs +2 -0
  166. package/src/tui/components/BufferedProgressBar.res +40 -0
  167. package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
  168. package/src/tui/components/CustomHooks.res +122 -0
  169. package/src/tui/components/CustomHooks.res.mjs +179 -0
  170. package/src/tui/components/Messages.res +41 -0
  171. package/src/tui/components/Messages.res.mjs +75 -0
  172. package/src/tui/components/SyncETA.res +174 -0
  173. package/src/tui/components/SyncETA.res.mjs +263 -0
  174. package/src/tui/components/TuiData.res +47 -0
  175. package/src/tui/components/TuiData.res.mjs +34 -0
  176. package/svm.schema.json +112 -0
  177. package/bin.js +0 -48
  178. package/src/EventRegister.res +0 -241
  179. package/src/EventRegister.res.mjs +0 -240
  180. package/src/EventRegister.resi +0 -30
  181. package/src/bindings/Ethers.gen.ts +0 -14
  182. package/src/bindings/Ethers.res +0 -204
  183. package/src/bindings/Ethers.res.mjs +0 -130
  184. /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 */
@@ -1,37 +1,22 @@
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
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
- @module("./vendored-fuel-abi-coder.js")
18
- external transpileAbi: Js.Json.t => Ethers.abi = "transpileAbi"
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
- @module("./vendored-fuel-abi-coder.js") @scope("AbiCoder")
21
- external getLogDecoder: (~abi: Ethers.abi, ~logId: string) => string => unknown = "getLogDecoder"
22
-
23
- module Receipt = {
24
- @tag("receiptType")
25
- type t =
26
- | @as(0) Call({assetId: string, amount: bigint, to: string})
27
- | @as(6) LogData({data: string, rb: bigint})
28
- | @as(7) Transfer({amount: bigint, assetId: string, to: string})
29
- | @as(8) TransferOut({amount: bigint, assetId: string, toAddress: string})
30
- | @as(11) Mint({val: bigint, subId: string})
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
  }
@@ -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
- function transpileAbi(prim) {
6
- return VendoredFuelAbiCoderJs.transpileAbi(prim);
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 getLogDecoder(prim0, prim1) {
10
- return VendoredFuelAbiCoderJs.AbiCoder.getLogDecoder(prim0, prim1);
22
+ function ecosystem_getTimestamp(prim) {
23
+ return prim.time;
11
24
  }
12
25
 
13
- function getLogDataDecoder(abi, logId) {
14
- var decode = VendoredFuelAbiCoderJs.AbiCoder.getLogDecoder(abi, logId);
15
- return function (data) {
16
- return decode(data);
17
- };
26
+ function ecosystem_getId(prim) {
27
+ return prim.id;
18
28
  }
19
29
 
20
- var Receipt = {
21
- getLogDataDecoder: getLogDataDecoder
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
- transpileAbi ,
26
- getLogDecoder ,
27
- Receipt ,
44
+ cleanUpRawEventFieldsInPlace ,
45
+ ecosystem ,
28
46
  }
29
- /* ./vendored-fuel-abi-coder.js Not a pure module */
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: Fuel.Receipt.t,
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 => Fuel.Receipt.t),
151
+ receipt: receipt->(Utils.magic: HyperFuelClient.FuelTypes.receipt => FuelSDK.Receipt.t),
152
152
  receiptIndex: receipt.receiptIndex,
153
153
  })
154
154
  ->ignore
@@ -13,7 +13,7 @@ type block = {
13
13
  type item = {
14
14
  transactionId: string,
15
15
  contractId: Address.t,
16
- receipt: Fuel.Receipt.t,
16
+ receipt: FuelSDK.Receipt.t,
17
17
  receiptIndex: int,
18
18
  block: block,
19
19
  }
@@ -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<Fuel.receiptType>,
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: Fuel.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<Fuel.receiptType> = [LogData]
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: Fuel.receiptType) => {
117
+ let addNonLogDataWildcardReceiptTypes = (receiptType: FuelSDK.receiptType) => {
118
118
  nonLogDataWildcardReceiptTypes->Array.push(receiptType)->ignore
119
119
  }
120
- let addNonLogDataReceiptType = (contractName, receiptType: Fuel.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
- ~currentBlockHeight,
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(currentBlockHeight),
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(currentBlockHeight),
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 currentBlockHeight = pageUnsafe.archiveHeight
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.toMillis->Hrtime.intFromMillis
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.toMillis->Hrtime.intFromMillis
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
- currentBlockHeight,
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: () => HyperFuel.heightRoute->Rest.fetch((), ~client=jsonApiClient),
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
  }