envio 3.0.0-alpha.21 → 3.0.0-alpha.22

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 (219) hide show
  1. package/bin.mjs +2 -48
  2. package/evm.schema.json +67 -0
  3. package/fuel.schema.json +67 -0
  4. package/index.d.ts +822 -38
  5. package/index.js +5 -3
  6. package/package.json +10 -8
  7. package/rescript.json +5 -9
  8. package/src/Address.res +4 -5
  9. package/src/Address.res.mjs +9 -12
  10. package/src/Api.res +15 -0
  11. package/src/Api.res.mjs +20 -0
  12. package/src/Batch.res +32 -34
  13. package/src/Batch.res.mjs +172 -187
  14. package/src/Bin.res +89 -0
  15. package/src/Bin.res.mjs +97 -0
  16. package/src/ChainFetcher.res +33 -57
  17. package/src/ChainFetcher.res.mjs +197 -227
  18. package/src/ChainManager.res +6 -14
  19. package/src/ChainManager.res.mjs +74 -85
  20. package/src/ChainMap.res +14 -16
  21. package/src/ChainMap.res.mjs +38 -38
  22. package/src/Config.res +193 -135
  23. package/src/Config.res.mjs +566 -592
  24. package/src/Core.res +182 -0
  25. package/src/Core.res.mjs +207 -0
  26. package/src/Ecosystem.res +25 -4
  27. package/src/Ecosystem.res.mjs +12 -13
  28. package/src/Env.res +20 -13
  29. package/src/Env.res.mjs +124 -113
  30. package/src/EnvSafe.res +269 -0
  31. package/src/EnvSafe.res.mjs +296 -0
  32. package/src/EnvSafe.resi +18 -0
  33. package/src/Envio.res +37 -26
  34. package/src/Envio.res.mjs +59 -60
  35. package/src/ErrorHandling.res +2 -2
  36. package/src/ErrorHandling.res.mjs +15 -15
  37. package/src/EventConfigBuilder.res +219 -81
  38. package/src/EventConfigBuilder.res.mjs +259 -202
  39. package/src/EventProcessing.res +27 -38
  40. package/src/EventProcessing.res.mjs +165 -183
  41. package/src/EventUtils.res +11 -11
  42. package/src/EventUtils.res.mjs +21 -22
  43. package/src/EvmTypes.res +0 -1
  44. package/src/EvmTypes.res.mjs +5 -5
  45. package/src/FetchState.res +360 -256
  46. package/src/FetchState.res.mjs +958 -914
  47. package/src/GlobalState.res +365 -351
  48. package/src/GlobalState.res.mjs +958 -992
  49. package/src/GlobalStateManager.res +1 -2
  50. package/src/GlobalStateManager.res.mjs +36 -44
  51. package/src/HandlerLoader.res +107 -23
  52. package/src/HandlerLoader.res.mjs +128 -38
  53. package/src/HandlerRegister.res +127 -103
  54. package/src/HandlerRegister.res.mjs +164 -164
  55. package/src/HandlerRegister.resi +12 -4
  56. package/src/Hasura.res +35 -22
  57. package/src/Hasura.res.mjs +158 -167
  58. package/src/InMemoryStore.res +20 -27
  59. package/src/InMemoryStore.res.mjs +64 -80
  60. package/src/InMemoryTable.res +34 -39
  61. package/src/InMemoryTable.res.mjs +165 -170
  62. package/src/Internal.res +52 -33
  63. package/src/Internal.res.mjs +84 -81
  64. package/src/LazyLoader.res.mjs +55 -61
  65. package/src/LoadLayer.res +77 -78
  66. package/src/LoadLayer.res.mjs +160 -189
  67. package/src/LoadManager.res +16 -21
  68. package/src/LoadManager.res.mjs +79 -84
  69. package/src/LogSelection.res +236 -68
  70. package/src/LogSelection.res.mjs +211 -141
  71. package/src/Logging.res +13 -9
  72. package/src/Logging.res.mjs +130 -143
  73. package/src/Main.res +428 -51
  74. package/src/Main.res.mjs +528 -271
  75. package/src/Persistence.res +77 -84
  76. package/src/Persistence.res.mjs +131 -132
  77. package/src/PgStorage.res +291 -167
  78. package/src/PgStorage.res.mjs +797 -817
  79. package/src/Prometheus.res +50 -58
  80. package/src/Prometheus.res.mjs +345 -373
  81. package/src/ReorgDetection.res +22 -24
  82. package/src/ReorgDetection.res.mjs +100 -106
  83. package/src/SafeCheckpointTracking.res +7 -7
  84. package/src/SafeCheckpointTracking.res.mjs +40 -43
  85. package/src/SimulateItems.res +41 -49
  86. package/src/SimulateItems.res.mjs +257 -272
  87. package/src/Sink.res +2 -2
  88. package/src/Sink.res.mjs +22 -26
  89. package/src/TableIndices.res +1 -2
  90. package/src/TableIndices.res.mjs +42 -48
  91. package/src/TestIndexer.res +196 -189
  92. package/src/TestIndexer.res.mjs +536 -536
  93. package/src/TestIndexerProxyStorage.res +15 -16
  94. package/src/TestIndexerProxyStorage.res.mjs +98 -122
  95. package/src/TestIndexerWorker.res +4 -0
  96. package/src/TestIndexerWorker.res.mjs +7 -0
  97. package/src/Throttler.res +3 -3
  98. package/src/Throttler.res.mjs +23 -24
  99. package/src/Time.res +1 -1
  100. package/src/Time.res.mjs +18 -21
  101. package/src/TopicFilter.res +3 -3
  102. package/src/TopicFilter.res.mjs +29 -30
  103. package/src/UserContext.res +93 -54
  104. package/src/UserContext.res.mjs +197 -182
  105. package/src/Utils.res +141 -86
  106. package/src/Utils.res.mjs +334 -295
  107. package/src/bindings/BigDecimal.res +0 -2
  108. package/src/bindings/BigDecimal.res.mjs +19 -23
  109. package/src/bindings/ClickHouse.res +28 -27
  110. package/src/bindings/ClickHouse.res.mjs +243 -240
  111. package/src/bindings/DateFns.res +11 -11
  112. package/src/bindings/DateFns.res.mjs +7 -7
  113. package/src/bindings/EventSource.res.mjs +2 -2
  114. package/src/bindings/Express.res +2 -5
  115. package/src/bindings/Hrtime.res +2 -2
  116. package/src/bindings/Hrtime.res.mjs +30 -32
  117. package/src/bindings/Lodash.res.mjs +1 -1
  118. package/src/bindings/NodeJs.res +14 -9
  119. package/src/bindings/NodeJs.res.mjs +20 -20
  120. package/src/bindings/Pino.res +8 -10
  121. package/src/bindings/Pino.res.mjs +40 -43
  122. package/src/bindings/Postgres.res +2 -5
  123. package/src/bindings/Postgres.res.mjs +9 -9
  124. package/src/bindings/PromClient.res +17 -2
  125. package/src/bindings/PromClient.res.mjs +30 -7
  126. package/src/bindings/SDSL.res.mjs +2 -2
  127. package/src/bindings/Viem.res +4 -4
  128. package/src/bindings/Viem.res.mjs +20 -22
  129. package/src/bindings/Vitest.res +1 -1
  130. package/src/bindings/Vitest.res.mjs +2 -2
  131. package/src/bindings/WebSocket.res +1 -1
  132. package/src/db/EntityHistory.res +9 -3
  133. package/src/db/EntityHistory.res.mjs +84 -59
  134. package/src/db/InternalTable.res +62 -60
  135. package/src/db/InternalTable.res.mjs +271 -203
  136. package/src/db/Schema.res +1 -2
  137. package/src/db/Schema.res.mjs +28 -32
  138. package/src/db/Table.res +28 -27
  139. package/src/db/Table.res.mjs +276 -292
  140. package/src/sources/EventRouter.res +21 -16
  141. package/src/sources/EventRouter.res.mjs +55 -57
  142. package/src/sources/Evm.res +17 -1
  143. package/src/sources/Evm.res.mjs +16 -8
  144. package/src/sources/EvmChain.res +15 -17
  145. package/src/sources/EvmChain.res.mjs +40 -42
  146. package/src/sources/Fuel.res +14 -1
  147. package/src/sources/Fuel.res.mjs +16 -8
  148. package/src/sources/FuelSDK.res +1 -1
  149. package/src/sources/FuelSDK.res.mjs +6 -8
  150. package/src/sources/HyperFuel.res +8 -10
  151. package/src/sources/HyperFuel.res.mjs +113 -123
  152. package/src/sources/HyperFuelClient.res.mjs +6 -7
  153. package/src/sources/HyperFuelSource.res +19 -20
  154. package/src/sources/HyperFuelSource.res.mjs +339 -356
  155. package/src/sources/HyperSync.res +11 -13
  156. package/src/sources/HyperSync.res.mjs +206 -220
  157. package/src/sources/HyperSyncClient.res +5 -7
  158. package/src/sources/HyperSyncClient.res.mjs +70 -75
  159. package/src/sources/HyperSyncHeightStream.res +8 -9
  160. package/src/sources/HyperSyncHeightStream.res.mjs +78 -86
  161. package/src/sources/HyperSyncJsonApi.res +18 -15
  162. package/src/sources/HyperSyncJsonApi.res.mjs +201 -231
  163. package/src/sources/HyperSyncSource.res +17 -21
  164. package/src/sources/HyperSyncSource.res.mjs +268 -290
  165. package/src/sources/Rpc.res +5 -5
  166. package/src/sources/Rpc.res.mjs +168 -192
  167. package/src/sources/RpcSource.res +166 -167
  168. package/src/sources/RpcSource.res.mjs +972 -1046
  169. package/src/sources/RpcWebSocketHeightStream.res +10 -11
  170. package/src/sources/RpcWebSocketHeightStream.res.mjs +131 -145
  171. package/src/sources/SimulateSource.res +1 -1
  172. package/src/sources/SimulateSource.res.mjs +35 -38
  173. package/src/sources/Source.res +1 -1
  174. package/src/sources/Source.res.mjs +3 -3
  175. package/src/sources/SourceManager.res +39 -20
  176. package/src/sources/SourceManager.res.mjs +340 -371
  177. package/src/sources/SourceManager.resi +2 -1
  178. package/src/sources/Svm.res +12 -5
  179. package/src/sources/Svm.res.mjs +44 -41
  180. package/src/tui/Tui.res +23 -12
  181. package/src/tui/Tui.res.mjs +292 -290
  182. package/src/tui/bindings/Ink.res +2 -4
  183. package/src/tui/bindings/Ink.res.mjs +35 -41
  184. package/src/tui/components/BufferedProgressBar.res +7 -7
  185. package/src/tui/components/BufferedProgressBar.res.mjs +46 -46
  186. package/src/tui/components/CustomHooks.res +1 -2
  187. package/src/tui/components/CustomHooks.res.mjs +102 -122
  188. package/src/tui/components/Messages.res +1 -2
  189. package/src/tui/components/Messages.res.mjs +38 -42
  190. package/src/tui/components/SyncETA.res +10 -11
  191. package/src/tui/components/SyncETA.res.mjs +178 -196
  192. package/src/tui/components/TuiData.res +1 -1
  193. package/src/tui/components/TuiData.res.mjs +7 -6
  194. package/src/vendored/Rest.res +52 -66
  195. package/src/vendored/Rest.res.mjs +324 -364
  196. package/svm.schema.json +67 -0
  197. package/src/Address.gen.ts +0 -8
  198. package/src/Config.gen.ts +0 -19
  199. package/src/Envio.gen.ts +0 -55
  200. package/src/EvmTypes.gen.ts +0 -6
  201. package/src/InMemoryStore.gen.ts +0 -6
  202. package/src/Internal.gen.ts +0 -64
  203. package/src/PgStorage.gen.ts +0 -10
  204. package/src/PgStorage.res.d.mts +0 -5
  205. package/src/Types.ts +0 -56
  206. package/src/bindings/BigDecimal.gen.ts +0 -14
  207. package/src/bindings/BigDecimal.res.d.mts +0 -5
  208. package/src/bindings/BigInt.gen.ts +0 -10
  209. package/src/bindings/BigInt.res +0 -70
  210. package/src/bindings/BigInt.res.d.mts +0 -5
  211. package/src/bindings/BigInt.res.mjs +0 -154
  212. package/src/bindings/Ethers.res.d.mts +0 -5
  213. package/src/bindings/Pino.gen.ts +0 -17
  214. package/src/bindings/Postgres.gen.ts +0 -8
  215. package/src/bindings/Postgres.res.d.mts +0 -5
  216. package/src/bindings/Promise.res +0 -67
  217. package/src/bindings/Promise.res.mjs +0 -26
  218. package/src/db/InternalTable.gen.ts +0 -36
  219. package/src/sources/HyperSyncClient.gen.ts +0 -19
@@ -2,263 +2,253 @@
2
2
 
3
3
  import * as Rest from "../vendored/Rest.res.mjs";
4
4
  import * as Hrtime from "../bindings/Hrtime.res.mjs";
5
- import * as Js_exn from "rescript/lib/es6/js_exn.js";
6
5
  import * as Source from "./Source.res.mjs";
7
6
  import * as Logging from "../Logging.res.mjs";
8
- import * as $$Promise from "../bindings/Promise.res.mjs";
9
7
  import * as HyperFuel from "./HyperFuel.res.mjs";
10
8
  import * as HyperSync from "./HyperSync.res.mjs";
11
- import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
9
+ import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
12
10
  import * as Prometheus from "../Prometheus.res.mjs";
13
- import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
14
11
  import * as EventRouter from "./EventRouter.res.mjs";
15
12
  import * as ErrorHandling from "../ErrorHandling.res.mjs";
16
- import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js";
17
- import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
13
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
14
+ import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
15
+ import * as Stdlib_Promise from "@rescript/runtime/lib/es6/Stdlib_Promise.js";
16
+ import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
18
17
 
19
- var EventRoutingFailed = /* @__PURE__ */Caml_exceptions.create("HyperFuelSource.EventRoutingFailed");
18
+ let EventRoutingFailed = /* @__PURE__ */Primitive_exceptions.create("HyperFuelSource.EventRoutingFailed");
20
19
 
21
- var mintEventTag = "mint";
20
+ let mintEventTag = "mint";
22
21
 
23
- var burnEventTag = "burn";
22
+ let burnEventTag = "burn";
24
23
 
25
- var transferEventTag = "transfer";
24
+ let transferEventTag = "transfer";
26
25
 
27
- var callEventTag = "call";
26
+ let callEventTag = "call";
28
27
 
29
- var logDataReceiptTypeSelection = [6];
28
+ let logDataReceiptTypeSelection = [6];
30
29
 
31
- var txStatusSelection = [1];
30
+ let txStatusSelection = [1];
32
31
 
33
32
  function makeGetNormalRecieptsSelection(nonWildcardLogDataRbsByContract, nonLogDataReceiptTypesByContract, contractNames) {
34
- return function (addressesByContractName) {
35
- var selection = [];
36
- contractNames.forEach(function (contractName) {
37
- var addresses = addressesByContractName[contractName];
38
- if (addresses === undefined) {
39
- return ;
40
- }
41
- if (addresses.length === 0) {
42
- return ;
43
- }
44
- var receiptTypes = nonLogDataReceiptTypesByContract[contractName];
45
- if (receiptTypes !== undefined) {
46
- selection.push({
47
- rootContractId: addresses,
48
- receiptType: receiptTypes,
49
- txStatus: txStatusSelection
50
- });
51
- }
52
- var nonWildcardLogDataRbs = nonWildcardLogDataRbsByContract[contractName];
53
- if (nonWildcardLogDataRbs !== undefined && nonWildcardLogDataRbs.length !== 0) {
54
- selection.push({
55
- rootContractId: addresses,
56
- receiptType: logDataReceiptTypeSelection,
57
- rb: nonWildcardLogDataRbs,
58
- txStatus: txStatusSelection
59
- });
60
- return ;
61
- }
62
-
33
+ return addressesByContractName => {
34
+ let selection = [];
35
+ contractNames.forEach(contractName => {
36
+ let addresses = addressesByContractName[contractName];
37
+ if (addresses === undefined) {
38
+ return;
39
+ }
40
+ if (addresses.length === 0) {
41
+ return;
42
+ }
43
+ let receiptTypes = nonLogDataReceiptTypesByContract[contractName];
44
+ if (receiptTypes !== undefined) {
45
+ selection.push({
46
+ rootContractId: addresses,
47
+ receiptType: receiptTypes,
48
+ txStatus: txStatusSelection
49
+ });
50
+ }
51
+ let nonWildcardLogDataRbs = nonWildcardLogDataRbsByContract[contractName];
52
+ if (nonWildcardLogDataRbs !== undefined && nonWildcardLogDataRbs.length !== 0) {
53
+ selection.push({
54
+ rootContractId: addresses,
55
+ receiptType: logDataReceiptTypeSelection,
56
+ rb: nonWildcardLogDataRbs,
57
+ txStatus: txStatusSelection
63
58
  });
59
+ return;
60
+ }
61
+ });
64
62
  return selection;
65
63
  };
66
64
  }
67
65
 
68
66
  function makeWildcardRecieptsSelection(wildcardLogDataRbs, nonLogDataWildcardReceiptTypes) {
69
- var selection = [];
67
+ let selection = [];
70
68
  if (nonLogDataWildcardReceiptTypes.length !== 0) {
71
69
  selection.push({
72
- receiptType: nonLogDataWildcardReceiptTypes,
73
- txStatus: txStatusSelection
74
- });
70
+ receiptType: nonLogDataWildcardReceiptTypes,
71
+ txStatus: txStatusSelection
72
+ });
75
73
  }
76
74
  if (wildcardLogDataRbs.length !== 0) {
77
75
  selection.push({
78
- receiptType: logDataReceiptTypeSelection,
79
- rb: wildcardLogDataRbs,
80
- txStatus: txStatusSelection
81
- });
76
+ receiptType: logDataReceiptTypeSelection,
77
+ rb: wildcardLogDataRbs,
78
+ txStatus: txStatusSelection
79
+ });
82
80
  }
83
81
  return selection;
84
82
  }
85
83
 
86
84
  function getSelectionConfig(selection, chain) {
87
- var eventRouter = EventRouter.empty();
88
- var nonWildcardLogDataRbsByContract = {};
89
- var wildcardLogDataRbs = [];
90
- var nonLogDataReceiptTypesByContract = {};
91
- var nonLogDataWildcardReceiptTypes = [];
92
- var addNonLogDataWildcardReceiptTypes = function (receiptType) {
85
+ let eventRouter = EventRouter.empty();
86
+ let nonWildcardLogDataRbsByContract = {};
87
+ let wildcardLogDataRbs = [];
88
+ let nonLogDataReceiptTypesByContract = {};
89
+ let nonLogDataWildcardReceiptTypes = [];
90
+ let addNonLogDataWildcardReceiptTypes = receiptType => {
93
91
  nonLogDataWildcardReceiptTypes.push(receiptType);
94
92
  };
95
- var addNonLogDataReceiptType = function (contractName, receiptType) {
96
- var receiptTypes = nonLogDataReceiptTypesByContract[contractName];
93
+ let addNonLogDataReceiptType = (contractName, receiptType) => {
94
+ let receiptTypes = nonLogDataReceiptTypesByContract[contractName];
97
95
  if (receiptTypes !== undefined) {
98
96
  receiptTypes.push(receiptType);
99
97
  } else {
100
98
  nonLogDataReceiptTypesByContract[contractName] = [receiptType];
101
99
  }
102
100
  };
103
- var contractNames = new Set();
104
- Belt_Array.forEach(selection.eventConfigs, (function (eventConfig) {
105
- var contractName = eventConfig.contractName;
106
- if (!eventConfig.isWildcard) {
107
- contractNames.add(contractName);
108
- }
109
- EventRouter.addOrThrow(eventRouter, eventConfig.id, eventConfig, contractName, eventConfig.isWildcard, eventConfig.name, chain);
110
- var isWildcard = eventConfig.isWildcard;
111
- if (isWildcard) {
112
- var tmp = eventConfig.kind;
113
- if (typeof tmp !== "object") {
114
- switch (tmp) {
115
- case "Mint" :
116
- return addNonLogDataWildcardReceiptTypes(11);
117
- case "Burn" :
118
- return addNonLogDataWildcardReceiptTypes(12);
119
- case "Transfer" :
120
- addNonLogDataWildcardReceiptTypes(7);
121
- return addNonLogDataWildcardReceiptTypes(8);
122
- case "Call" :
123
- return addNonLogDataWildcardReceiptTypes(0);
124
-
125
- }
126
- }
127
-
128
- }
129
- var match = eventConfig.kind;
130
- if (typeof match !== "object") {
131
- switch (match) {
132
- case "Mint" :
133
- return addNonLogDataReceiptType(contractName, 11);
134
- case "Burn" :
135
- return addNonLogDataReceiptType(contractName, 12);
136
- case "Transfer" :
137
- addNonLogDataReceiptType(contractName, 7);
138
- return addNonLogDataReceiptType(contractName, 8);
139
- case "Call" :
140
- return Js_exn.raiseError("Call receipt indexing currently supported only in wildcard mode");
141
-
142
- }
143
- } else {
144
- var rb = BigInt(match.logId);
145
- if (isWildcard) {
146
- wildcardLogDataRbs.push(rb);
147
- return ;
148
- }
149
- var arr = nonWildcardLogDataRbsByContract[contractName];
150
- if (arr !== undefined) {
151
- arr.push(rb);
152
- } else {
153
- nonWildcardLogDataRbsByContract[contractName] = [rb];
154
- }
155
- return ;
156
- }
157
- }));
158
- var tmp;
101
+ let contractNames = new Set();
102
+ selection.eventConfigs.forEach(eventConfig => {
103
+ let contractName = eventConfig.contractName;
104
+ if (!eventConfig.isWildcard) {
105
+ contractNames.add(contractName);
106
+ }
107
+ EventRouter.addOrThrow(eventRouter, eventConfig.id, eventConfig, contractName, eventConfig.isWildcard, eventConfig.name, chain);
108
+ let isWildcard = eventConfig.isWildcard;
109
+ if (isWildcard) {
110
+ let tmp = eventConfig.kind;
111
+ if (typeof tmp !== "object") {
112
+ switch (tmp) {
113
+ case "Mint" :
114
+ return addNonLogDataWildcardReceiptTypes(11);
115
+ case "Burn" :
116
+ return addNonLogDataWildcardReceiptTypes(12);
117
+ case "Transfer" :
118
+ addNonLogDataWildcardReceiptTypes(7);
119
+ return addNonLogDataWildcardReceiptTypes(8);
120
+ case "Call" :
121
+ return addNonLogDataWildcardReceiptTypes(0);
122
+ }
123
+ }
124
+ }
125
+ let match = eventConfig.kind;
126
+ if (typeof match !== "object") {
127
+ switch (match) {
128
+ case "Mint" :
129
+ return addNonLogDataReceiptType(contractName, 11);
130
+ case "Burn" :
131
+ return addNonLogDataReceiptType(contractName, 12);
132
+ case "Transfer" :
133
+ addNonLogDataReceiptType(contractName, 7);
134
+ return addNonLogDataReceiptType(contractName, 8);
135
+ case "Call" :
136
+ return Stdlib_JsError.throwWithMessage("Call receipt indexing currently supported only in wildcard mode");
137
+ }
138
+ } else {
139
+ let rb = BigInt(match.logId);
140
+ if (isWildcard) {
141
+ wildcardLogDataRbs.push(rb);
142
+ return;
143
+ }
144
+ let arr = nonWildcardLogDataRbsByContract[contractName];
145
+ if (arr !== undefined) {
146
+ arr.push(rb);
147
+ } else {
148
+ nonWildcardLogDataRbsByContract[contractName] = [rb];
149
+ }
150
+ return;
151
+ }
152
+ });
153
+ let tmp;
159
154
  if (selection.dependsOnAddresses) {
160
155
  tmp = makeGetNormalRecieptsSelection(nonWildcardLogDataRbsByContract, nonLogDataReceiptTypesByContract, contractNames);
161
156
  } else {
162
- var recieptsSelection = makeWildcardRecieptsSelection(wildcardLogDataRbs, nonLogDataWildcardReceiptTypes);
163
- tmp = (function (param) {
164
- return recieptsSelection;
165
- });
157
+ let recieptsSelection = makeWildcardRecieptsSelection(wildcardLogDataRbs, nonLogDataWildcardReceiptTypes);
158
+ tmp = param => recieptsSelection;
166
159
  }
167
160
  return {
168
- getRecieptsSelection: tmp,
169
- eventRouter: eventRouter
170
- };
161
+ getRecieptsSelection: tmp,
162
+ eventRouter: eventRouter
163
+ };
171
164
  }
172
165
 
173
166
  function memoGetSelectionConfig(chain) {
174
- var cache = new WeakMap();
175
- return function (selection) {
176
- var c = cache.get(selection);
167
+ let cache = new WeakMap();
168
+ return selection => {
169
+ let c = cache.get(selection);
177
170
  if (c !== undefined) {
178
171
  return c;
179
172
  }
180
- var c$1 = getSelectionConfig(selection, chain);
173
+ let c$1 = getSelectionConfig(selection, chain);
181
174
  cache.set(selection, c$1);
182
175
  return c$1;
183
176
  };
184
177
  }
185
178
 
186
179
  function make(param) {
187
- var endpointUrl = param.endpointUrl;
188
- var chain = param.chain;
189
- var name = "HyperFuel";
190
- var getSelectionConfig = memoGetSelectionConfig(chain);
191
- var getItemsOrThrow = async function (fromBlock, toBlock, addressesByContractName, indexingContracts, knownHeight, param, selection, retry, logger) {
192
- var mkLogAndRaise = function (extra, extra$1) {
193
- return ErrorHandling.mkLogAndRaise(logger, extra, extra$1);
194
- };
195
- var totalTimeRef = Hrtime.makeTimer();
196
- var selectionConfig = getSelectionConfig(selection);
197
- var recieptsSelection = selectionConfig.getRecieptsSelection(addressesByContractName);
198
- var startFetchingBatchTimeRef = Hrtime.makeTimer();
180
+ let endpointUrl = param.endpointUrl;
181
+ let chain = param.chain;
182
+ let name = "HyperFuel";
183
+ let getSelectionConfig = memoGetSelectionConfig(chain);
184
+ let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName, indexingAddresses, knownHeight, param, selection, retry, logger) => {
185
+ let mkLogAndRaise = (extra, extra$1) => ErrorHandling.mkLogAndRaise(logger, extra, extra$1);
186
+ let totalTimeRef = Hrtime.makeTimer();
187
+ let selectionConfig = getSelectionConfig(selection);
188
+ let recieptsSelection = selectionConfig.getRecieptsSelection(addressesByContractName);
189
+ let startFetchingBatchTimeRef = Hrtime.makeTimer();
199
190
  Prometheus.SourceRequestCount.increment(name, chain, "getLogs");
200
- var pageUnsafe;
191
+ let pageUnsafe;
201
192
  try {
202
193
  pageUnsafe = await HyperFuel.GetLogs.query(endpointUrl, fromBlock, toBlock, recieptsSelection);
203
- }
204
- catch (raw_error){
205
- var error = Caml_js_exceptions.internalToOCamlException(raw_error);
194
+ } catch (raw_error) {
195
+ let error = Primitive_exceptions.internalToException(raw_error);
206
196
  if (error.RE_EXN_ID === HyperSync.GetLogs.$$Error) {
207
- var error$1 = error._1;
208
- var tmp;
197
+ let error$1 = error._1;
198
+ let tmp;
209
199
  if (typeof error$1 !== "object") {
210
- var backoffMillis = retry !== 0 ? Math.imul(500, retry) : 100;
200
+ let backoffMillis = retry !== 0 ? 500 * retry | 0 : 100;
211
201
  tmp = {
212
202
  TAG: "WithBackoff",
213
- message: "Block #" + String(fromBlock) + " not found in HyperFuel. HyperFuel has multiple instances and it's possible that they drift independently slightly from the head. Indexing should continue correctly after retrying the query in " + String(backoffMillis) + "ms.",
203
+ message: `Block #` + fromBlock.toString() + ` not found in HyperFuel. HyperFuel has multiple instances and it's possible that they drift independently slightly from the head. Indexing should continue correctly after retrying the query in ` + backoffMillis.toString() + `ms.`,
214
204
  backoffMillis: backoffMillis
215
205
  };
216
206
  } else {
217
207
  tmp = {
218
208
  TAG: "ImpossibleForTheQuery",
219
- message: "Source returned invalid data with missing required fields: " + error$1.missingParams.join(", ")
209
+ message: `Source returned invalid data with missing required fields: ` + error$1.missingParams.join(", ")
220
210
  };
221
211
  }
222
212
  throw {
223
- RE_EXN_ID: Source.GetItemsError,
224
- _1: {
225
- TAG: "FailedGettingItems",
226
- exn: null,
227
- attemptedToBlock: Belt_Option.getWithDefault(toBlock, knownHeight),
228
- retry: tmp
229
- },
230
- Error: new Error()
231
- };
213
+ RE_EXN_ID: Source.GetItemsError,
214
+ _1: {
215
+ TAG: "FailedGettingItems",
216
+ exn: null,
217
+ attemptedToBlock: Stdlib_Option.getOr(toBlock, knownHeight),
218
+ retry: tmp
219
+ },
220
+ Error: new Error()
221
+ };
232
222
  }
233
223
  throw {
234
- RE_EXN_ID: Source.GetItemsError,
235
- _1: {
236
- TAG: "FailedGettingItems",
237
- exn: error,
238
- attemptedToBlock: Belt_Option.getWithDefault(toBlock, knownHeight),
239
- retry: {
240
- TAG: "WithBackoff",
241
- message: "Unexpected issue while fetching events from HyperFuel client. Attempt a retry.",
242
- backoffMillis: retry !== 0 ? Math.imul(1000, retry) : 500
243
- }
244
- },
245
- Error: new Error()
246
- };
224
+ RE_EXN_ID: Source.GetItemsError,
225
+ _1: {
226
+ TAG: "FailedGettingItems",
227
+ exn: error,
228
+ attemptedToBlock: Stdlib_Option.getOr(toBlock, knownHeight),
229
+ retry: {
230
+ TAG: "WithBackoff",
231
+ message: `Unexpected issue while fetching events from HyperFuel client. Attempt a retry.`,
232
+ backoffMillis: retry !== 0 ? 1000 * retry | 0 : 500
233
+ }
234
+ },
235
+ Error: new Error()
236
+ };
247
237
  }
248
- var pageFetchTime = Hrtime.toSecondsFloat(Hrtime.timeSince(startFetchingBatchTimeRef));
249
- var knownHeight$1 = pageUnsafe.archiveHeight;
250
- var heighestBlockQueried = pageUnsafe.nextBlock - 1 | 0;
251
- var match = Belt_Array.get(pageUnsafe.items, pageUnsafe.items.length - 1 | 0);
252
- var lastBlockQueriedPromise;
253
- var exit = 0;
238
+ let pageFetchTime = Hrtime.toSecondsFloat(Hrtime.timeSince(startFetchingBatchTimeRef));
239
+ let knownHeight$1 = pageUnsafe.archiveHeight;
240
+ let heighestBlockQueried = pageUnsafe.nextBlock - 1 | 0;
241
+ let match = Belt_Array.get(pageUnsafe.items, pageUnsafe.items.length - 1 | 0);
242
+ let lastBlockQueriedPromise;
243
+ let exit = 0;
254
244
  if (match !== undefined) {
255
- var block = match.block;
245
+ let block = match.block;
256
246
  if (block.height === heighestBlockQueried) {
257
247
  lastBlockQueriedPromise = Promise.resolve({
258
- blockHash: block.id,
259
- blockNumber: block.height,
260
- blockTimestamp: block.time
261
- });
248
+ blockHash: block.id,
249
+ blockNumber: block.height,
250
+ blockTimestamp: block.time
251
+ });
262
252
  } else {
263
253
  exit = 1;
264
254
  }
@@ -266,196 +256,189 @@ function make(param) {
266
256
  exit = 1;
267
257
  }
268
258
  if (exit === 1) {
269
- lastBlockQueriedPromise = $$Promise.$$catch(HyperFuel.queryBlockData(endpointUrl, heighestBlockQueried, logger).then(function (res) {
270
- if (res !== undefined) {
271
- return res;
272
- } else {
273
- return mkLogAndRaise("Failure, blockData for block " + String(heighestBlockQueried) + " unexpectedly returned None", {
274
- RE_EXN_ID: "Not_found"
275
- });
276
- }
277
- }), (function (exn) {
278
- return mkLogAndRaise("Failed to query blockData for block " + String(heighestBlockQueried), exn);
279
- }));
259
+ lastBlockQueriedPromise = Stdlib_Promise.$$catch(HyperFuel.queryBlockData(endpointUrl, heighestBlockQueried, logger).then(res => {
260
+ if (res !== undefined) {
261
+ return res;
262
+ } else {
263
+ return mkLogAndRaise(`Failure, blockData for block ` + heighestBlockQueried.toString() + ` unexpectedly returned None`, {
264
+ RE_EXN_ID: "Not_found"
265
+ });
266
+ }
267
+ }), exn => mkLogAndRaise(`Failed to query blockData for block ` + heighestBlockQueried.toString(), exn));
280
268
  }
281
- var parsingTimeRef = Hrtime.makeTimer();
282
- var parsedQueueItems = Belt_Array.map(pageUnsafe.items, (function (item) {
283
- var block = item.block;
284
- var receiptIndex = item.receiptIndex;
285
- var receipt = item.receipt;
286
- var contractAddress = item.contractId;
287
- var eventId;
288
- switch (receipt.receiptType) {
289
- case 0 :
290
- eventId = callEventTag;
291
- break;
292
- case 6 :
293
- eventId = receipt.rb.toString();
294
- break;
295
- case 7 :
296
- case 8 :
297
- eventId = transferEventTag;
298
- break;
299
- case 11 :
300
- eventId = mintEventTag;
301
- break;
302
- case 12 :
303
- eventId = burnEventTag;
304
- break;
305
-
306
- }
307
- var eventConfig = EventRouter.get(selectionConfig.eventRouter, eventId, contractAddress, block.height, indexingContracts);
308
- var eventConfig$1;
309
- if (eventConfig !== undefined) {
310
- eventConfig$1 = eventConfig;
311
- } else {
312
- var logger$1 = Logging.createChildFrom(logger, {
313
- chainId: chain,
314
- blockNumber: block.height,
315
- logIndex: receiptIndex,
316
- contractAddress: contractAddress,
317
- eventId: eventId
318
- });
319
- eventConfig$1 = ErrorHandling.mkLogAndRaise(logger$1, "Failed to route registered event", {
320
- RE_EXN_ID: EventRoutingFailed
321
- });
322
- }
323
- var match = eventConfig$1.kind;
324
- var params;
325
- var exit = 0;
326
- if (typeof match !== "object" || receipt.receiptType !== 6) {
327
- exit = 1;
328
- } else {
329
- try {
330
- params = match.decode(receipt.data);
331
- }
332
- catch (raw_exn){
333
- var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
334
- var params$1 = {
335
- chainId: chain,
336
- blockNumber: block.height,
337
- logIndex: receiptIndex
338
- };
339
- var logger$2 = Logging.createChildFrom(logger, params$1);
340
- params = ErrorHandling.mkLogAndRaise(logger$2, "Failed to decode Fuel LogData receipt, please double check your ABI.", exn);
341
- }
342
- }
343
- if (exit === 1) {
344
- switch (receipt.receiptType) {
345
- case 0 :
346
- params = {
347
- to: receipt.to,
348
- assetId: receipt.assetId,
349
- amount: receipt.amount
350
- };
351
- break;
352
- case 6 :
353
- params = Js_exn.raiseError("Unexpected bug in the event routing logic");
354
- break;
355
- case 7 :
356
- params = {
357
- to: receipt.to,
358
- assetId: receipt.assetId,
359
- amount: receipt.amount
360
- };
361
- break;
362
- case 8 :
363
- params = {
364
- to: receipt.toAddress,
365
- assetId: receipt.assetId,
366
- amount: receipt.amount
367
- };
368
- break;
369
- case 11 :
370
- case 12 :
371
- params = {
372
- subId: receipt.subId,
373
- amount: receipt.val
374
- };
375
- break;
376
-
377
- }
378
- }
379
- return {
380
- kind: 0,
381
- eventConfig: eventConfig$1,
382
- timestamp: block.time,
383
- chain: chain,
384
- blockNumber: block.height,
385
- logIndex: receiptIndex,
386
- event: {
387
- contractName: eventConfig$1.contractName,
388
- eventName: eventConfig$1.name,
389
- params: params,
390
- chainId: chain,
391
- srcAddress: contractAddress,
392
- logIndex: receiptIndex,
393
- transaction: {
394
- id: item.transactionId
395
- },
396
- block: block
397
- }
398
- };
399
- }));
400
- var parsingTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(parsingTimeRef));
401
- var rangeLastBlock = await lastBlockQueriedPromise;
402
- var reorgGuard = {
269
+ let parsingTimeRef = Hrtime.makeTimer();
270
+ let parsedQueueItems = pageUnsafe.items.map(item => {
271
+ let block = item.block;
272
+ let receiptIndex = item.receiptIndex;
273
+ let receipt = item.receipt;
274
+ let contractAddress = item.contractId;
275
+ let eventId;
276
+ switch (receipt.receiptType) {
277
+ case 0 :
278
+ eventId = callEventTag;
279
+ break;
280
+ case 6 :
281
+ eventId = receipt.rb.toString();
282
+ break;
283
+ case 7 :
284
+ case 8 :
285
+ eventId = transferEventTag;
286
+ break;
287
+ case 11 :
288
+ eventId = mintEventTag;
289
+ break;
290
+ case 12 :
291
+ eventId = burnEventTag;
292
+ break;
293
+ }
294
+ let eventConfig = EventRouter.get(selectionConfig.eventRouter, eventId, contractAddress, block.height, indexingAddresses);
295
+ let eventConfig$1;
296
+ if (eventConfig !== undefined) {
297
+ eventConfig$1 = eventConfig;
298
+ } else {
299
+ let logger$1 = Logging.createChildFrom(logger, {
300
+ chainId: chain,
301
+ blockNumber: block.height,
302
+ logIndex: receiptIndex,
303
+ contractAddress: contractAddress,
304
+ eventId: eventId
305
+ });
306
+ eventConfig$1 = ErrorHandling.mkLogAndRaise(logger$1, "Failed to route registered event", {
307
+ RE_EXN_ID: EventRoutingFailed
308
+ });
309
+ }
310
+ let match = eventConfig$1.kind;
311
+ let params;
312
+ let exit = 0;
313
+ if (typeof match !== "object" || receipt.receiptType !== 6) {
314
+ exit = 1;
315
+ } else {
316
+ try {
317
+ params = match.decode(receipt.data);
318
+ } catch (raw_exn) {
319
+ let exn = Primitive_exceptions.internalToException(raw_exn);
320
+ let params$1 = {
321
+ chainId: chain,
322
+ blockNumber: block.height,
323
+ logIndex: receiptIndex
324
+ };
325
+ let logger$2 = Logging.createChildFrom(logger, params$1);
326
+ params = ErrorHandling.mkLogAndRaise(logger$2, "Failed to decode Fuel LogData receipt, please double check your ABI.", exn);
327
+ }
328
+ }
329
+ if (exit === 1) {
330
+ switch (receipt.receiptType) {
331
+ case 0 :
332
+ params = {
333
+ to: receipt.to,
334
+ assetId: receipt.assetId,
335
+ amount: receipt.amount
336
+ };
337
+ break;
338
+ case 6 :
339
+ params = Stdlib_JsError.throwWithMessage("Unexpected bug in the event routing logic");
340
+ break;
341
+ case 7 :
342
+ params = {
343
+ to: receipt.to,
344
+ assetId: receipt.assetId,
345
+ amount: receipt.amount
346
+ };
347
+ break;
348
+ case 8 :
349
+ params = {
350
+ to: receipt.toAddress,
351
+ assetId: receipt.assetId,
352
+ amount: receipt.amount
353
+ };
354
+ break;
355
+ case 11 :
356
+ case 12 :
357
+ params = {
358
+ subId: receipt.subId,
359
+ amount: receipt.val
360
+ };
361
+ break;
362
+ }
363
+ }
364
+ return {
365
+ kind: 0,
366
+ eventConfig: eventConfig$1,
367
+ timestamp: block.time,
368
+ chain: chain,
369
+ blockNumber: block.height,
370
+ logIndex: receiptIndex,
371
+ event: {
372
+ contractName: eventConfig$1.contractName,
373
+ eventName: eventConfig$1.name,
374
+ params: params,
375
+ chainId: chain,
376
+ srcAddress: contractAddress,
377
+ logIndex: receiptIndex,
378
+ transaction: {
379
+ id: item.transactionId
380
+ },
381
+ block: block
382
+ }
383
+ };
384
+ });
385
+ let parsingTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(parsingTimeRef));
386
+ let rangeLastBlock = await lastBlockQueriedPromise;
387
+ let reorgGuard = {
403
388
  rangeLastBlock: rangeLastBlock,
404
389
  prevRangeLastBlock: undefined
405
390
  };
406
- var totalTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(totalTimeRef));
407
- var stats_parsing$unknowntime$unknown$lpars$rpar = parsingTimeElapsed;
408
- var stats_page$unknownfetch$unknowntime$unknown$lpars$rpar = pageFetchTime;
409
- var stats = {
391
+ let totalTimeElapsed = Hrtime.toSecondsFloat(Hrtime.timeSince(totalTimeRef));
392
+ let stats_parsing$unknowntime$unknown$lpars$rpar = parsingTimeElapsed;
393
+ let stats_page$unknownfetch$unknowntime$unknown$lpars$rpar = pageFetchTime;
394
+ let stats = {
410
395
  "total time elapsed (s)": totalTimeElapsed,
411
396
  "parsing time (s)": stats_parsing$unknowntime$unknown$lpars$rpar,
412
397
  "page fetch time (s)": stats_page$unknownfetch$unknowntime$unknown$lpars$rpar
413
398
  };
414
399
  return {
415
- knownHeight: knownHeight$1,
416
- reorgGuard: reorgGuard,
417
- parsedQueueItems: parsedQueueItems,
418
- fromBlockQueried: fromBlock,
419
- latestFetchedBlockNumber: rangeLastBlock.blockNumber,
420
- latestFetchedBlockTimestamp: rangeLastBlock.blockTimestamp,
421
- stats: stats
422
- };
423
- };
424
- var getBlockHashes = function (param, param$1) {
425
- return Js_exn.raiseError("HyperFuel does not support getting block hashes");
400
+ knownHeight: knownHeight$1,
401
+ reorgGuard: reorgGuard,
402
+ parsedQueueItems: parsedQueueItems,
403
+ fromBlockQueried: fromBlock,
404
+ latestFetchedBlockNumber: rangeLastBlock.blockNumber,
405
+ latestFetchedBlockTimestamp: rangeLastBlock.blockTimestamp,
406
+ stats: stats
407
+ };
426
408
  };
427
- var jsonApiClient = Rest.client(endpointUrl, undefined);
409
+ let getBlockHashes = (param, param$1) => Stdlib_JsError.throwWithMessage("HyperFuel does not support getting block hashes");
410
+ let jsonApiClient = Rest.client(endpointUrl, undefined);
428
411
  return {
429
- name: name,
430
- sourceFor: "Sync",
431
- chain: chain,
432
- poweredByHyperSync: true,
433
- pollingInterval: 100,
434
- getBlockHashes: getBlockHashes,
435
- getHeightOrThrow: (async function () {
436
- var timerRef = Hrtime.makeTimer();
437
- var height = await Rest.$$fetch(HyperFuel.heightRoute, undefined, jsonApiClient);
438
- var seconds = Hrtime.toSecondsFloat(Hrtime.timeSince(timerRef));
439
- Prometheus.SourceRequestCount.increment(name, chain, "getHeight");
440
- Prometheus.SourceRequestCount.addSeconds(name, chain, "getHeight", seconds);
441
- return height;
442
- }),
443
- getItemsOrThrow: getItemsOrThrow
444
- };
412
+ name: name,
413
+ sourceFor: "Sync",
414
+ chain: chain,
415
+ poweredByHyperSync: true,
416
+ pollingInterval: 100,
417
+ getBlockHashes: getBlockHashes,
418
+ getHeightOrThrow: async () => {
419
+ let timerRef = Hrtime.makeTimer();
420
+ let height = await Rest.fetch(HyperFuel.heightRoute, undefined, jsonApiClient);
421
+ let seconds = Hrtime.toSecondsFloat(Hrtime.timeSince(timerRef));
422
+ Prometheus.SourceRequestCount.increment(name, chain, "getHeight");
423
+ Prometheus.SourceRequestCount.addSeconds(name, chain, "getHeight", seconds);
424
+ return height;
425
+ },
426
+ getItemsOrThrow: getItemsOrThrow
427
+ };
445
428
  }
446
429
 
447
430
  export {
448
- EventRoutingFailed ,
449
- mintEventTag ,
450
- burnEventTag ,
451
- transferEventTag ,
452
- callEventTag ,
453
- logDataReceiptTypeSelection ,
454
- txStatusSelection ,
455
- makeGetNormalRecieptsSelection ,
456
- makeWildcardRecieptsSelection ,
457
- getSelectionConfig ,
458
- memoGetSelectionConfig ,
459
- make ,
431
+ EventRoutingFailed,
432
+ mintEventTag,
433
+ burnEventTag,
434
+ transferEventTag,
435
+ callEventTag,
436
+ logDataReceiptTypeSelection,
437
+ txStatusSelection,
438
+ makeGetNormalRecieptsSelection,
439
+ makeWildcardRecieptsSelection,
440
+ getSelectionConfig,
441
+ memoGetSelectionConfig,
442
+ make,
460
443
  }
461
444
  /* Rest Not a pure module */