@filoz/ponder 0.0.0-bootstrap.0 → 0.17.4-filecoin.4

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 (616) hide show
  1. package/CHANGELOG.md +3537 -0
  2. package/LICENSE +21 -0
  3. package/README.md +88 -0
  4. package/dist/esm/bin/commands/codegen.js +37 -0
  5. package/dist/esm/bin/commands/codegen.js.map +1 -0
  6. package/dist/esm/bin/commands/createViews.js +171 -0
  7. package/dist/esm/bin/commands/createViews.js.map +1 -0
  8. package/dist/esm/bin/commands/dev.js +412 -0
  9. package/dist/esm/bin/commands/dev.js.map +1 -0
  10. package/dist/esm/bin/commands/list.js +144 -0
  11. package/dist/esm/bin/commands/list.js.map +1 -0
  12. package/dist/esm/bin/commands/prune.js +219 -0
  13. package/dist/esm/bin/commands/prune.js.map +1 -0
  14. package/dist/esm/bin/commands/serve.js +183 -0
  15. package/dist/esm/bin/commands/serve.js.map +1 -0
  16. package/dist/esm/bin/commands/start.js +237 -0
  17. package/dist/esm/bin/commands/start.js.map +1 -0
  18. package/dist/esm/bin/isolatedController.js +200 -0
  19. package/dist/esm/bin/isolatedController.js.map +1 -0
  20. package/dist/esm/bin/isolatedWorker.js +141 -0
  21. package/dist/esm/bin/isolatedWorker.js.map +1 -0
  22. package/dist/esm/bin/ponder.js +137 -0
  23. package/dist/esm/bin/ponder.js.map +1 -0
  24. package/dist/esm/bin/utils/codegen.js +25 -0
  25. package/dist/esm/bin/utils/codegen.js.map +1 -0
  26. package/dist/esm/bin/utils/exit.js +96 -0
  27. package/dist/esm/bin/utils/exit.js.map +1 -0
  28. package/dist/esm/build/config.js +745 -0
  29. package/dist/esm/build/config.js.map +1 -0
  30. package/dist/esm/build/factory.js +82 -0
  31. package/dist/esm/build/factory.js.map +1 -0
  32. package/dist/esm/build/index.js +570 -0
  33. package/dist/esm/build/index.js.map +1 -0
  34. package/dist/esm/build/plugin.js +53 -0
  35. package/dist/esm/build/plugin.js.map +1 -0
  36. package/dist/esm/build/pre.js +83 -0
  37. package/dist/esm/build/pre.js.map +1 -0
  38. package/dist/esm/build/schema.js +195 -0
  39. package/dist/esm/build/schema.js.map +1 -0
  40. package/dist/esm/build/stacktrace.js +137 -0
  41. package/dist/esm/build/stacktrace.js.map +1 -0
  42. package/dist/esm/client/index.js +440 -0
  43. package/dist/esm/client/index.js.map +1 -0
  44. package/dist/esm/config/address.js +2 -0
  45. package/dist/esm/config/address.js.map +1 -0
  46. package/dist/esm/config/eventFilter.js +2 -0
  47. package/dist/esm/config/eventFilter.js.map +1 -0
  48. package/dist/esm/config/index.js +2 -0
  49. package/dist/esm/config/index.js.map +1 -0
  50. package/dist/esm/config/utilityTypes.js +2 -0
  51. package/dist/esm/config/utilityTypes.js.map +1 -0
  52. package/dist/esm/database/actions.js +395 -0
  53. package/dist/esm/database/actions.js.map +1 -0
  54. package/dist/esm/database/index.js +604 -0
  55. package/dist/esm/database/index.js.map +1 -0
  56. package/dist/esm/database/queryBuilder.js +311 -0
  57. package/dist/esm/database/queryBuilder.js.map +1 -0
  58. package/dist/esm/drizzle/bigint.js +36 -0
  59. package/dist/esm/drizzle/bigint.js.map +1 -0
  60. package/dist/esm/drizzle/bytes.js +45 -0
  61. package/dist/esm/drizzle/bytes.js.map +1 -0
  62. package/dist/esm/drizzle/hex.js +38 -0
  63. package/dist/esm/drizzle/hex.js.map +1 -0
  64. package/dist/esm/drizzle/index.js +28 -0
  65. package/dist/esm/drizzle/index.js.map +1 -0
  66. package/dist/esm/drizzle/json.js +119 -0
  67. package/dist/esm/drizzle/json.js.map +1 -0
  68. package/dist/esm/drizzle/kit/index.js +913 -0
  69. package/dist/esm/drizzle/kit/index.js.map +1 -0
  70. package/dist/esm/drizzle/onchain.js +226 -0
  71. package/dist/esm/drizzle/onchain.js.map +1 -0
  72. package/dist/esm/drizzle/text.js +59 -0
  73. package/dist/esm/drizzle/text.js.map +1 -0
  74. package/dist/esm/graphql/graphiql.html.js +59 -0
  75. package/dist/esm/graphql/graphiql.html.js.map +1 -0
  76. package/dist/esm/graphql/index.js +964 -0
  77. package/dist/esm/graphql/index.js.map +1 -0
  78. package/dist/esm/graphql/json.js +42 -0
  79. package/dist/esm/graphql/json.js.map +1 -0
  80. package/dist/esm/graphql/middleware.js +83 -0
  81. package/dist/esm/graphql/middleware.js.map +1 -0
  82. package/dist/esm/index.js +9 -0
  83. package/dist/esm/index.js.map +1 -0
  84. package/dist/esm/indexing/addStackTrace.js +54 -0
  85. package/dist/esm/indexing/addStackTrace.js.map +1 -0
  86. package/dist/esm/indexing/client.js +674 -0
  87. package/dist/esm/indexing/client.js.map +1 -0
  88. package/dist/esm/indexing/index.js +665 -0
  89. package/dist/esm/indexing/index.js.map +1 -0
  90. package/dist/esm/indexing/profile.js +584 -0
  91. package/dist/esm/indexing/profile.js.map +1 -0
  92. package/dist/esm/indexing-store/cache.js +657 -0
  93. package/dist/esm/indexing-store/cache.js.map +1 -0
  94. package/dist/esm/indexing-store/index.js +457 -0
  95. package/dist/esm/indexing-store/index.js.map +1 -0
  96. package/dist/esm/indexing-store/profile.js +428 -0
  97. package/dist/esm/indexing-store/profile.js.map +1 -0
  98. package/dist/esm/indexing-store/utils.js +131 -0
  99. package/dist/esm/indexing-store/utils.js.map +1 -0
  100. package/dist/esm/internal/common.js +2 -0
  101. package/dist/esm/internal/common.js.map +1 -0
  102. package/dist/esm/internal/errors.js +300 -0
  103. package/dist/esm/internal/errors.js.map +1 -0
  104. package/dist/esm/internal/logger.js +178 -0
  105. package/dist/esm/internal/logger.js.map +1 -0
  106. package/dist/esm/internal/metrics.js +1117 -0
  107. package/dist/esm/internal/metrics.js.map +1 -0
  108. package/dist/esm/internal/options.js +70 -0
  109. package/dist/esm/internal/options.js.map +1 -0
  110. package/dist/esm/internal/shutdown.js +24 -0
  111. package/dist/esm/internal/shutdown.js.map +1 -0
  112. package/dist/esm/internal/types.js +2 -0
  113. package/dist/esm/internal/types.js.map +1 -0
  114. package/dist/esm/rpc/actions.js +1051 -0
  115. package/dist/esm/rpc/actions.js.map +1 -0
  116. package/dist/esm/rpc/http.js +134 -0
  117. package/dist/esm/rpc/http.js.map +1 -0
  118. package/dist/esm/rpc/index.js +767 -0
  119. package/dist/esm/rpc/index.js.map +1 -0
  120. package/dist/esm/runtime/events.js +662 -0
  121. package/dist/esm/runtime/events.js.map +1 -0
  122. package/dist/esm/runtime/filter.js +443 -0
  123. package/dist/esm/runtime/filter.js.map +1 -0
  124. package/dist/esm/runtime/fragments.js +478 -0
  125. package/dist/esm/runtime/fragments.js.map +1 -0
  126. package/dist/esm/runtime/historical.js +941 -0
  127. package/dist/esm/runtime/historical.js.map +1 -0
  128. package/dist/esm/runtime/index.js +335 -0
  129. package/dist/esm/runtime/index.js.map +1 -0
  130. package/dist/esm/runtime/isolated.js +471 -0
  131. package/dist/esm/runtime/isolated.js.map +1 -0
  132. package/dist/esm/runtime/multichain.js +518 -0
  133. package/dist/esm/runtime/multichain.js.map +1 -0
  134. package/dist/esm/runtime/omnichain.js +553 -0
  135. package/dist/esm/runtime/omnichain.js.map +1 -0
  136. package/dist/esm/runtime/realtime.js +724 -0
  137. package/dist/esm/runtime/realtime.js.map +1 -0
  138. package/dist/esm/server/error.js +56 -0
  139. package/dist/esm/server/error.js.map +1 -0
  140. package/dist/esm/server/index.js +121 -0
  141. package/dist/esm/server/index.js.map +1 -0
  142. package/dist/esm/sync-historical/index.js +731 -0
  143. package/dist/esm/sync-historical/index.js.map +1 -0
  144. package/dist/esm/sync-realtime/bloom.js +76 -0
  145. package/dist/esm/sync-realtime/bloom.js.map +1 -0
  146. package/dist/esm/sync-realtime/index.js +972 -0
  147. package/dist/esm/sync-realtime/index.js.map +1 -0
  148. package/dist/esm/sync-store/encode.js +105 -0
  149. package/dist/esm/sync-store/encode.js.map +1 -0
  150. package/dist/esm/sync-store/index.js +864 -0
  151. package/dist/esm/sync-store/index.js.map +1 -0
  152. package/dist/esm/sync-store/migrations.js +1595 -0
  153. package/dist/esm/sync-store/migrations.js.map +1 -0
  154. package/dist/esm/sync-store/schema.js +181 -0
  155. package/dist/esm/sync-store/schema.js.map +1 -0
  156. package/dist/esm/types/db.js +2 -0
  157. package/dist/esm/types/db.js.map +1 -0
  158. package/dist/esm/types/eth.js +2 -0
  159. package/dist/esm/types/eth.js.map +1 -0
  160. package/dist/esm/types/utils.js +2 -0
  161. package/dist/esm/types/utils.js.map +1 -0
  162. package/dist/esm/types/virtual.js +2 -0
  163. package/dist/esm/types/virtual.js.map +1 -0
  164. package/dist/esm/ui/app.js +157 -0
  165. package/dist/esm/ui/app.js.map +1 -0
  166. package/dist/esm/ui/index.js +29 -0
  167. package/dist/esm/ui/index.js.map +1 -0
  168. package/dist/esm/ui/patch.js +139 -0
  169. package/dist/esm/ui/patch.js.map +1 -0
  170. package/dist/esm/utils/abi.js +55 -0
  171. package/dist/esm/utils/abi.js.map +1 -0
  172. package/dist/esm/utils/bigint.js +37 -0
  173. package/dist/esm/utils/bigint.js.map +1 -0
  174. package/dist/esm/utils/chains.js +21 -0
  175. package/dist/esm/utils/chains.js.map +1 -0
  176. package/dist/esm/utils/checkpoint.js +139 -0
  177. package/dist/esm/utils/checkpoint.js.map +1 -0
  178. package/dist/esm/utils/chunk.js +8 -0
  179. package/dist/esm/utils/chunk.js.map +1 -0
  180. package/dist/esm/utils/copy.js +140 -0
  181. package/dist/esm/utils/copy.js.map +1 -0
  182. package/dist/esm/utils/date.js +27 -0
  183. package/dist/esm/utils/date.js.map +1 -0
  184. package/dist/esm/utils/debug.js +2 -0
  185. package/dist/esm/utils/debug.js.map +1 -0
  186. package/dist/esm/utils/decodeAbiParameters.js +289 -0
  187. package/dist/esm/utils/decodeAbiParameters.js.map +1 -0
  188. package/dist/esm/utils/decodeEventLog.js +75 -0
  189. package/dist/esm/utils/decodeEventLog.js.map +1 -0
  190. package/dist/esm/utils/dedupe.js +29 -0
  191. package/dist/esm/utils/dedupe.js.map +1 -0
  192. package/dist/esm/utils/duplicates.js +19 -0
  193. package/dist/esm/utils/duplicates.js.map +1 -0
  194. package/dist/esm/utils/estimate.js +6 -0
  195. package/dist/esm/utils/estimate.js.map +1 -0
  196. package/dist/esm/utils/finality.js +49 -0
  197. package/dist/esm/utils/finality.js.map +1 -0
  198. package/dist/esm/utils/format.js +20 -0
  199. package/dist/esm/utils/format.js.map +1 -0
  200. package/dist/esm/utils/generators.js +121 -0
  201. package/dist/esm/utils/generators.js.map +1 -0
  202. package/dist/esm/utils/getLogsRetryHelper.js +40 -0
  203. package/dist/esm/utils/getLogsRetryHelper.js.map +1 -0
  204. package/dist/esm/utils/hash.js +11 -0
  205. package/dist/esm/utils/hash.js.map +1 -0
  206. package/dist/esm/utils/interval.js +171 -0
  207. package/dist/esm/utils/interval.js.map +1 -0
  208. package/dist/esm/utils/lowercase.js +7 -0
  209. package/dist/esm/utils/lowercase.js.map +1 -0
  210. package/dist/esm/utils/mutex.js +26 -0
  211. package/dist/esm/utils/mutex.js.map +1 -0
  212. package/dist/esm/utils/never.js +4 -0
  213. package/dist/esm/utils/never.js.map +1 -0
  214. package/dist/esm/utils/offset.js +101 -0
  215. package/dist/esm/utils/offset.js.map +1 -0
  216. package/dist/esm/utils/order.js +18 -0
  217. package/dist/esm/utils/order.js.map +1 -0
  218. package/dist/esm/utils/partition.js +46 -0
  219. package/dist/esm/utils/partition.js.map +1 -0
  220. package/dist/esm/utils/pg.js +175 -0
  221. package/dist/esm/utils/pg.js.map +1 -0
  222. package/dist/esm/utils/pglite.js +78 -0
  223. package/dist/esm/utils/pglite.js.map +1 -0
  224. package/dist/esm/utils/port.js +30 -0
  225. package/dist/esm/utils/port.js.map +1 -0
  226. package/dist/esm/utils/print.js +24 -0
  227. package/dist/esm/utils/print.js.map +1 -0
  228. package/dist/esm/utils/promiseAllSettledWithThrow.js +19 -0
  229. package/dist/esm/utils/promiseAllSettledWithThrow.js.map +1 -0
  230. package/dist/esm/utils/promiseWithResolvers.js +13 -0
  231. package/dist/esm/utils/promiseWithResolvers.js.map +1 -0
  232. package/dist/esm/utils/queue.js +150 -0
  233. package/dist/esm/utils/queue.js.map +1 -0
  234. package/dist/esm/utils/range.js +8 -0
  235. package/dist/esm/utils/range.js.map +1 -0
  236. package/dist/esm/utils/result.js +10 -0
  237. package/dist/esm/utils/result.js.map +1 -0
  238. package/dist/esm/utils/sql-parse.js +1326 -0
  239. package/dist/esm/utils/sql-parse.js.map +1 -0
  240. package/dist/esm/utils/timer.js +9 -0
  241. package/dist/esm/utils/timer.js.map +1 -0
  242. package/dist/esm/utils/truncate.js +15 -0
  243. package/dist/esm/utils/truncate.js.map +1 -0
  244. package/dist/esm/utils/wait.js +10 -0
  245. package/dist/esm/utils/wait.js.map +1 -0
  246. package/dist/esm/utils/zipper.js +67 -0
  247. package/dist/esm/utils/zipper.js.map +1 -0
  248. package/dist/types/bin/commands/codegen.d.ts +5 -0
  249. package/dist/types/bin/commands/codegen.d.ts.map +1 -0
  250. package/dist/types/bin/commands/createViews.d.ts +8 -0
  251. package/dist/types/bin/commands/createViews.d.ts.map +1 -0
  252. package/dist/types/bin/commands/dev.d.ts +5 -0
  253. package/dist/types/bin/commands/dev.d.ts.map +1 -0
  254. package/dist/types/bin/commands/list.d.ts +5 -0
  255. package/dist/types/bin/commands/list.d.ts.map +1 -0
  256. package/dist/types/bin/commands/prune.d.ts +5 -0
  257. package/dist/types/bin/commands/prune.d.ts.map +1 -0
  258. package/dist/types/bin/commands/serve.d.ts +5 -0
  259. package/dist/types/bin/commands/serve.d.ts.map +1 -0
  260. package/dist/types/bin/commands/start.d.ts +19 -0
  261. package/dist/types/bin/commands/start.d.ts.map +1 -0
  262. package/dist/types/bin/isolatedController.d.ts +13 -0
  263. package/dist/types/bin/isolatedController.d.ts.map +1 -0
  264. package/dist/types/bin/isolatedWorker.d.ts +9 -0
  265. package/dist/types/bin/isolatedWorker.d.ts.map +1 -0
  266. package/dist/types/bin/ponder.d.ts +37 -0
  267. package/dist/types/bin/ponder.d.ts.map +1 -0
  268. package/dist/types/bin/utils/codegen.d.ts +6 -0
  269. package/dist/types/bin/utils/codegen.d.ts.map +1 -0
  270. package/dist/types/bin/utils/exit.d.ts +10 -0
  271. package/dist/types/bin/utils/exit.d.ts.map +1 -0
  272. package/dist/types/build/config.d.ts +97 -0
  273. package/dist/types/build/config.d.ts.map +1 -0
  274. package/dist/types/build/factory.d.ts +9 -0
  275. package/dist/types/build/factory.d.ts.map +1 -0
  276. package/dist/types/build/index.d.ts +84 -0
  277. package/dist/types/build/index.d.ts.map +1 -0
  278. package/dist/types/build/plugin.d.ts +4 -0
  279. package/dist/types/build/plugin.d.ts.map +1 -0
  280. package/dist/types/build/pre.d.ts +29 -0
  281. package/dist/types/build/pre.d.ts.map +1 -0
  282. package/dist/types/build/schema.d.ts +20 -0
  283. package/dist/types/build/schema.d.ts.map +1 -0
  284. package/dist/types/build/stacktrace.d.ts +13 -0
  285. package/dist/types/build/stacktrace.d.ts.map +1 -0
  286. package/dist/types/client/index.d.ts +27 -0
  287. package/dist/types/client/index.d.ts.map +1 -0
  288. package/dist/types/config/address.d.ts +35 -0
  289. package/dist/types/config/address.d.ts.map +1 -0
  290. package/dist/types/config/eventFilter.d.ts +18 -0
  291. package/dist/types/config/eventFilter.d.ts.map +1 -0
  292. package/dist/types/config/index.d.ts +144 -0
  293. package/dist/types/config/index.d.ts.map +1 -0
  294. package/dist/types/config/utilityTypes.d.ts +43 -0
  295. package/dist/types/config/utilityTypes.d.ts.map +1 -0
  296. package/dist/types/database/actions.d.ts +99 -0
  297. package/dist/types/database/actions.d.ts.map +1 -0
  298. package/dist/types/database/index.d.ts +493 -0
  299. package/dist/types/database/index.d.ts.map +1 -0
  300. package/dist/types/database/queryBuilder.d.ts +65 -0
  301. package/dist/types/database/queryBuilder.d.ts.map +1 -0
  302. package/dist/types/drizzle/bigint.d.ts +25 -0
  303. package/dist/types/drizzle/bigint.d.ts.map +1 -0
  304. package/dist/types/drizzle/bytes.d.ts +32 -0
  305. package/dist/types/drizzle/bytes.d.ts.map +1 -0
  306. package/dist/types/drizzle/hex.d.ts +25 -0
  307. package/dist/types/drizzle/hex.d.ts.map +1 -0
  308. package/dist/types/drizzle/index.d.ts +6 -0
  309. package/dist/types/drizzle/index.d.ts.map +1 -0
  310. package/dist/types/drizzle/json.d.ts +51 -0
  311. package/dist/types/drizzle/json.d.ts.map +1 -0
  312. package/dist/types/drizzle/kit/index.d.ts +187 -0
  313. package/dist/types/drizzle/kit/index.d.ts.map +1 -0
  314. package/dist/types/drizzle/onchain.d.ts +302 -0
  315. package/dist/types/drizzle/onchain.d.ts.map +1 -0
  316. package/dist/types/drizzle/text.d.ts +29 -0
  317. package/dist/types/drizzle/text.d.ts.map +1 -0
  318. package/dist/types/graphql/graphiql.html.d.ts +2 -0
  319. package/dist/types/graphql/graphiql.html.d.ts.map +1 -0
  320. package/dist/types/graphql/index.d.ts +12 -0
  321. package/dist/types/graphql/index.d.ts.map +1 -0
  322. package/dist/types/graphql/json.d.ts +3 -0
  323. package/dist/types/graphql/json.d.ts.map +1 -0
  324. package/dist/types/graphql/middleware.d.ts +29 -0
  325. package/dist/types/graphql/middleware.d.ts.map +1 -0
  326. package/dist/types/index.d.ts +23 -0
  327. package/dist/types/index.d.ts.map +1 -0
  328. package/dist/types/indexing/addStackTrace.d.ts +3 -0
  329. package/dist/types/indexing/addStackTrace.d.ts.map +1 -0
  330. package/dist/types/indexing/client.d.ts +153 -0
  331. package/dist/types/indexing/client.d.ts.map +1 -0
  332. package/dist/types/indexing/index.d.ts +72 -0
  333. package/dist/types/indexing/index.d.ts.map +1 -0
  334. package/dist/types/indexing/profile.d.ts +16 -0
  335. package/dist/types/indexing/profile.d.ts.map +1 -0
  336. package/dist/types/indexing-store/cache.d.ts +115 -0
  337. package/dist/types/indexing-store/cache.d.ts.map +1 -0
  338. package/dist/types/indexing-store/index.d.ts +23 -0
  339. package/dist/types/indexing-store/index.d.ts.map +1 -0
  340. package/dist/types/indexing-store/profile.d.ts +7 -0
  341. package/dist/types/indexing-store/profile.d.ts.map +1 -0
  342. package/dist/types/indexing-store/utils.d.ts +24 -0
  343. package/dist/types/indexing-store/utils.d.ts.map +1 -0
  344. package/dist/types/internal/common.d.ts +13 -0
  345. package/dist/types/internal/common.d.ts.map +1 -0
  346. package/dist/types/internal/errors.d.ts +101 -0
  347. package/dist/types/internal/errors.d.ts.map +1 -0
  348. package/dist/types/internal/logger.d.ts +37 -0
  349. package/dist/types/internal/logger.d.ts.map +1 -0
  350. package/dist/types/internal/metrics.d.ts +133 -0
  351. package/dist/types/internal/metrics.d.ts.map +1 -0
  352. package/dist/types/internal/options.d.ts +56 -0
  353. package/dist/types/internal/options.d.ts.map +1 -0
  354. package/dist/types/internal/shutdown.d.ts +8 -0
  355. package/dist/types/internal/shutdown.d.ts.map +1 -0
  356. package/dist/types/internal/types.d.ts +433 -0
  357. package/dist/types/internal/types.d.ts.map +1 -0
  358. package/dist/types/rpc/actions.d.ts +378 -0
  359. package/dist/types/rpc/actions.d.ts.map +1 -0
  360. package/dist/types/rpc/http.d.ts +17 -0
  361. package/dist/types/rpc/http.d.ts.map +1 -0
  362. package/dist/types/rpc/index.d.ts +43 -0
  363. package/dist/types/rpc/index.d.ts.map +1 -0
  364. package/dist/types/runtime/events.d.ts +40 -0
  365. package/dist/types/runtime/events.d.ts.map +1 -0
  366. package/dist/types/runtime/filter.d.ts +87 -0
  367. package/dist/types/runtime/filter.d.ts.map +1 -0
  368. package/dist/types/runtime/fragments.d.ts +30 -0
  369. package/dist/types/runtime/fragments.d.ts.map +1 -0
  370. package/dist/types/runtime/historical.d.ts +123 -0
  371. package/dist/types/runtime/historical.d.ts.map +1 -0
  372. package/dist/types/runtime/index.d.ts +88 -0
  373. package/dist/types/runtime/index.d.ts.map +1 -0
  374. package/dist/types/runtime/isolated.d.ts +14 -0
  375. package/dist/types/runtime/isolated.d.ts.map +1 -0
  376. package/dist/types/runtime/multichain.d.ts +13 -0
  377. package/dist/types/runtime/multichain.d.ts.map +1 -0
  378. package/dist/types/runtime/omnichain.d.ts +23 -0
  379. package/dist/types/runtime/omnichain.d.ts.map +1 -0
  380. package/dist/types/runtime/realtime.d.ts +93 -0
  381. package/dist/types/runtime/realtime.d.ts.map +1 -0
  382. package/dist/types/server/error.d.ts +5 -0
  383. package/dist/types/server/error.d.ts.map +1 -0
  384. package/dist/types/server/index.d.ts +13 -0
  385. package/dist/types/server/index.d.ts.map +1 -0
  386. package/dist/types/sync-historical/index.d.ts +36 -0
  387. package/dist/types/sync-historical/index.d.ts.map +1 -0
  388. package/dist/types/sync-realtime/bloom.d.ts +18 -0
  389. package/dist/types/sync-realtime/bloom.d.ts.map +1 -0
  390. package/dist/types/sync-realtime/index.d.ts +47 -0
  391. package/dist/types/sync-realtime/index.d.ts.map +1 -0
  392. package/dist/types/sync-store/encode.d.ts +25 -0
  393. package/dist/types/sync-store/encode.d.ts.map +1 -0
  394. package/dist/types/sync-store/index.d.ts +146 -0
  395. package/dist/types/sync-store/index.d.ts.map +1 -0
  396. package/dist/types/sync-store/migrations.d.ts +8 -0
  397. package/dist/types/sync-store/migrations.d.ts.map +1 -0
  398. package/dist/types/sync-store/schema.d.ts +1828 -0
  399. package/dist/types/sync-store/schema.d.ts.map +1 -0
  400. package/dist/types/types/db.d.ts +213 -0
  401. package/dist/types/types/db.d.ts.map +1 -0
  402. package/dist/types/types/eth.d.ts +196 -0
  403. package/dist/types/types/eth.d.ts.map +1 -0
  404. package/dist/types/types/utils.d.ts +38 -0
  405. package/dist/types/types/utils.d.ts.map +1 -0
  406. package/dist/types/types/virtual.d.ts +99 -0
  407. package/dist/types/types/virtual.d.ts.map +1 -0
  408. package/dist/types/ui/app.d.ts +22 -0
  409. package/dist/types/ui/app.d.ts.map +1 -0
  410. package/dist/types/ui/index.d.ts +5 -0
  411. package/dist/types/ui/index.d.ts.map +1 -0
  412. package/dist/types/ui/patch.d.ts +7 -0
  413. package/dist/types/ui/patch.d.ts.map +1 -0
  414. package/dist/types/utils/abi.d.ts +23 -0
  415. package/dist/types/utils/abi.d.ts.map +1 -0
  416. package/dist/types/utils/bigint.d.ts +15 -0
  417. package/dist/types/utils/bigint.d.ts.map +1 -0
  418. package/dist/types/utils/chains.d.ts +44 -0
  419. package/dist/types/utils/chains.d.ts.map +1 -0
  420. package/dist/types/utils/checkpoint.d.ts +52 -0
  421. package/dist/types/utils/checkpoint.d.ts.map +1 -0
  422. package/dist/types/utils/chunk.d.ts +2 -0
  423. package/dist/types/utils/chunk.d.ts.map +1 -0
  424. package/dist/types/utils/copy.d.ts +16 -0
  425. package/dist/types/utils/copy.d.ts.map +1 -0
  426. package/dist/types/utils/date.d.ts +7 -0
  427. package/dist/types/utils/date.d.ts.map +1 -0
  428. package/dist/types/utils/debug.d.ts +105 -0
  429. package/dist/types/utils/debug.d.ts.map +1 -0
  430. package/dist/types/utils/decodeAbiParameters.d.ts +28 -0
  431. package/dist/types/utils/decodeAbiParameters.d.ts.map +1 -0
  432. package/dist/types/utils/decodeEventLog.d.ts +12 -0
  433. package/dist/types/utils/decodeEventLog.d.ts.map +1 -0
  434. package/dist/types/utils/dedupe.d.ts +20 -0
  435. package/dist/types/utils/dedupe.d.ts.map +1 -0
  436. package/dist/types/utils/duplicates.d.ts +7 -0
  437. package/dist/types/utils/duplicates.d.ts.map +1 -0
  438. package/dist/types/utils/estimate.d.ts +11 -0
  439. package/dist/types/utils/estimate.d.ts.map +1 -0
  440. package/dist/types/utils/finality.d.ts +15 -0
  441. package/dist/types/utils/finality.d.ts.map +1 -0
  442. package/dist/types/utils/format.d.ts +3 -0
  443. package/dist/types/utils/format.d.ts.map +1 -0
  444. package/dist/types/utils/generators.d.ts +42 -0
  445. package/dist/types/utils/generators.d.ts.map +1 -0
  446. package/dist/types/utils/getLogsRetryHelper.d.ts +3 -0
  447. package/dist/types/utils/getLogsRetryHelper.d.ts.map +1 -0
  448. package/dist/types/utils/hash.d.ts +11 -0
  449. package/dist/types/utils/hash.d.ts.map +1 -0
  450. package/dist/types/utils/interval.d.ts +53 -0
  451. package/dist/types/utils/interval.d.ts.map +1 -0
  452. package/dist/types/utils/lowercase.d.ts +5 -0
  453. package/dist/types/utils/lowercase.d.ts.map +1 -0
  454. package/dist/types/utils/mutex.d.ts +5 -0
  455. package/dist/types/utils/mutex.d.ts.map +1 -0
  456. package/dist/types/utils/never.d.ts +2 -0
  457. package/dist/types/utils/never.d.ts.map +1 -0
  458. package/dist/types/utils/offset.d.ts +8 -0
  459. package/dist/types/utils/offset.d.ts.map +1 -0
  460. package/dist/types/utils/order.d.ts +2 -0
  461. package/dist/types/utils/order.d.ts.map +1 -0
  462. package/dist/types/utils/partition.d.ts +22 -0
  463. package/dist/types/utils/partition.d.ts.map +1 -0
  464. package/dist/types/utils/pg.d.ts +8 -0
  465. package/dist/types/utils/pg.d.ts.map +1 -0
  466. package/dist/types/utils/pglite.d.ts +25 -0
  467. package/dist/types/utils/pglite.d.ts.map +1 -0
  468. package/dist/types/utils/port.d.ts +5 -0
  469. package/dist/types/utils/port.d.ts.map +1 -0
  470. package/dist/types/utils/print.d.ts +4 -0
  471. package/dist/types/utils/print.d.ts.map +1 -0
  472. package/dist/types/utils/promiseAllSettledWithThrow.d.ts +8 -0
  473. package/dist/types/utils/promiseAllSettledWithThrow.d.ts.map +1 -0
  474. package/dist/types/utils/promiseWithResolvers.d.ts +10 -0
  475. package/dist/types/utils/promiseWithResolvers.d.ts.map +1 -0
  476. package/dist/types/utils/queue.d.ts +33 -0
  477. package/dist/types/utils/queue.d.ts.map +1 -0
  478. package/dist/types/utils/range.d.ts +8 -0
  479. package/dist/types/utils/range.d.ts.map +1 -0
  480. package/dist/types/utils/result.d.ts +17 -0
  481. package/dist/types/utils/result.d.ts.map +1 -0
  482. package/dist/types/utils/sql-parse.d.ts +21 -0
  483. package/dist/types/utils/sql-parse.d.ts.map +1 -0
  484. package/dist/types/utils/timer.d.ts +6 -0
  485. package/dist/types/utils/timer.d.ts.map +1 -0
  486. package/dist/types/utils/truncate.d.ts +9 -0
  487. package/dist/types/utils/truncate.d.ts.map +1 -0
  488. package/dist/types/utils/wait.d.ts +6 -0
  489. package/dist/types/utils/wait.d.ts.map +1 -0
  490. package/dist/types/utils/zipper.d.ts +36 -0
  491. package/dist/types/utils/zipper.d.ts.map +1 -0
  492. package/package.json +121 -1
  493. package/src/bin/commands/codegen.ts +46 -0
  494. package/src/bin/commands/createViews.ts +295 -0
  495. package/src/bin/commands/dev.ts +470 -0
  496. package/src/bin/commands/list.ts +205 -0
  497. package/src/bin/commands/prune.ts +319 -0
  498. package/src/bin/commands/serve.ts +220 -0
  499. package/src/bin/commands/start.ts +302 -0
  500. package/src/bin/isolatedController.ts +300 -0
  501. package/src/bin/isolatedWorker.ts +186 -0
  502. package/src/bin/ponder.ts +208 -0
  503. package/src/bin/utils/codegen.ts +32 -0
  504. package/src/bin/utils/exit.ts +104 -0
  505. package/src/build/config.ts +1146 -0
  506. package/src/build/factory.ts +125 -0
  507. package/src/build/index.ts +800 -0
  508. package/src/build/plugin.ts +58 -0
  509. package/src/build/pre.ts +114 -0
  510. package/src/build/schema.ts +353 -0
  511. package/src/build/stacktrace.ts +137 -0
  512. package/src/client/index.ts +553 -0
  513. package/src/config/address.ts +46 -0
  514. package/src/config/eventFilter.ts +33 -0
  515. package/src/config/index.ts +240 -0
  516. package/src/config/utilityTypes.ts +152 -0
  517. package/src/database/actions.ts +825 -0
  518. package/src/database/index.ts +1029 -0
  519. package/src/database/queryBuilder.ts +535 -0
  520. package/src/drizzle/bigint.ts +57 -0
  521. package/src/drizzle/bytes.ts +68 -0
  522. package/src/drizzle/hex.ts +58 -0
  523. package/src/drizzle/index.ts +40 -0
  524. package/src/drizzle/json.ts +159 -0
  525. package/src/drizzle/kit/index.ts +1334 -0
  526. package/src/drizzle/onchain.ts +528 -0
  527. package/src/drizzle/text.ts +77 -0
  528. package/src/graphql/graphiql.html.ts +59 -0
  529. package/src/graphql/index.ts +1392 -0
  530. package/src/graphql/json.ts +62 -0
  531. package/src/graphql/middleware.ts +117 -0
  532. package/src/index.ts +131 -0
  533. package/src/indexing/addStackTrace.ts +69 -0
  534. package/src/indexing/client.ts +1187 -0
  535. package/src/indexing/index.ts +976 -0
  536. package/src/indexing/profile.ts +771 -0
  537. package/src/indexing-store/cache.ts +1059 -0
  538. package/src/indexing-store/index.ts +673 -0
  539. package/src/indexing-store/profile.ts +557 -0
  540. package/src/indexing-store/utils.ts +192 -0
  541. package/src/internal/common.ts +13 -0
  542. package/src/internal/errors.ts +228 -0
  543. package/src/internal/logger.ts +255 -0
  544. package/src/internal/metrics.ts +1111 -0
  545. package/src/internal/options.ts +122 -0
  546. package/src/internal/shutdown.ts +32 -0
  547. package/src/internal/types.ts +596 -0
  548. package/src/rpc/actions.ts +1423 -0
  549. package/src/rpc/http.ts +168 -0
  550. package/src/rpc/index.ts +980 -0
  551. package/src/runtime/events.ts +876 -0
  552. package/src/runtime/filter.ts +670 -0
  553. package/src/runtime/fragments.ts +674 -0
  554. package/src/runtime/historical.ts +1497 -0
  555. package/src/runtime/index.ts +594 -0
  556. package/src/runtime/isolated.ts +785 -0
  557. package/src/runtime/multichain.ts +867 -0
  558. package/src/runtime/omnichain.ts +927 -0
  559. package/src/runtime/realtime.ts +1164 -0
  560. package/src/server/error.ts +68 -0
  561. package/src/server/index.ts +173 -0
  562. package/src/sync-historical/index.ts +1094 -0
  563. package/src/sync-realtime/bloom.ts +102 -0
  564. package/src/sync-realtime/index.ts +1366 -0
  565. package/src/sync-store/encode.ts +153 -0
  566. package/src/sync-store/index.ts +1616 -0
  567. package/src/sync-store/migrations.ts +1801 -0
  568. package/src/sync-store/schema.ts +248 -0
  569. package/src/types/db.ts +292 -0
  570. package/src/types/eth.ts +216 -0
  571. package/src/types/utils.ts +47 -0
  572. package/src/types/virtual.ts +244 -0
  573. package/src/types.d.ts +40 -0
  574. package/src/ui/app.ts +207 -0
  575. package/src/ui/index.ts +37 -0
  576. package/src/ui/patch.ts +203 -0
  577. package/src/utils/abi.ts +106 -0
  578. package/src/utils/bigint.ts +41 -0
  579. package/src/utils/chains.ts +22 -0
  580. package/src/utils/checkpoint.ts +203 -0
  581. package/src/utils/chunk.ts +7 -0
  582. package/src/utils/copy.ts +165 -0
  583. package/src/utils/date.ts +26 -0
  584. package/src/utils/debug.ts +110 -0
  585. package/src/utils/decodeAbiParameters.ts +426 -0
  586. package/src/utils/decodeEventLog.ts +100 -0
  587. package/src/utils/dedupe.ts +32 -0
  588. package/src/utils/duplicates.ts +19 -0
  589. package/src/utils/estimate.ts +27 -0
  590. package/src/utils/finality.ts +54 -0
  591. package/src/utils/format.ts +22 -0
  592. package/src/utils/generators.ts +157 -0
  593. package/src/utils/getLogsRetryHelper.ts +46 -0
  594. package/src/utils/hash.ts +22 -0
  595. package/src/utils/interval.ts +212 -0
  596. package/src/utils/lowercase.ts +6 -0
  597. package/src/utils/mutex.ts +33 -0
  598. package/src/utils/never.ts +3 -0
  599. package/src/utils/offset.ts +133 -0
  600. package/src/utils/order.ts +16 -0
  601. package/src/utils/partition.ts +53 -0
  602. package/src/utils/pg.ts +230 -0
  603. package/src/utils/pglite.ts +96 -0
  604. package/src/utils/port.ts +34 -0
  605. package/src/utils/print.ts +34 -0
  606. package/src/utils/promiseAllSettledWithThrow.ts +27 -0
  607. package/src/utils/promiseWithResolvers.ts +20 -0
  608. package/src/utils/queue.ts +258 -0
  609. package/src/utils/range.ts +8 -0
  610. package/src/utils/result.ts +26 -0
  611. package/src/utils/sql-parse.ts +1477 -0
  612. package/src/utils/timer.ts +8 -0
  613. package/src/utils/truncate.ts +15 -0
  614. package/src/utils/wait.ts +8 -0
  615. package/src/utils/zipper.ts +80 -0
  616. package/tsconfig.json +12 -0
@@ -0,0 +1,1423 @@
1
+ import {
2
+ BlockNotFoundError,
3
+ type Hex,
4
+ hexToBigInt,
5
+ hexToNumber,
6
+ isHex,
7
+ numberToHex,
8
+ TransactionReceiptNotFoundError,
9
+ zeroAddress,
10
+ zeroHash,
11
+ } from "viem";
12
+ import { RpcProviderError } from "@/internal/errors.js";
13
+ import type {
14
+ LightBlock,
15
+ SyncBlock,
16
+ SyncBlockHeader,
17
+ SyncLog,
18
+ SyncTrace,
19
+ SyncTransaction,
20
+ SyncTransactionReceipt,
21
+ } from "@/internal/types.js";
22
+ import type { RequestParameters, Rpc } from "@/rpc/index.js";
23
+ import { zeroLogsBloom } from "@/sync-realtime/bloom.js";
24
+ import { isFilecoinChain } from "@/utils/finality.js";
25
+ import { PG_BIGINT_MAX, PG_INTEGER_MAX } from "@/utils/pg.js";
26
+
27
+ /**
28
+ * Returns true if the error indicates a null round (an epoch with no block).
29
+ * Matches RPC error code 12 or a "null round" error message.
30
+ */
31
+ export function isNullRoundError(error: unknown): boolean {
32
+ if (error && typeof error === "object") {
33
+ // Filecoin null rounds return RPC error code 12
34
+ if (
35
+ "cause" in error &&
36
+ error.cause &&
37
+ typeof error.cause === "object" &&
38
+ "code" in error.cause &&
39
+ error.cause.code === 12
40
+ ) {
41
+ return true;
42
+ }
43
+ // Check the error message as a fallback
44
+ if (
45
+ "message" in error &&
46
+ typeof error.message === "string" &&
47
+ error.message.includes("null round")
48
+ ) {
49
+ return true;
50
+ }
51
+ }
52
+ return false;
53
+ }
54
+
55
+ /**
56
+ * Returns true if the error indicates that a block does not exist.
57
+ * Handles both viem's BlockNotFoundError (null response) and Filecoin's
58
+ * RPC error code 12 ("requested epoch was a null round").
59
+ */
60
+ export function isBlockNotFoundError(error: unknown): boolean {
61
+ if (error instanceof BlockNotFoundError) return true;
62
+ if (error && typeof error === "object") {
63
+ if ("cause" in error && error.cause instanceof BlockNotFoundError) {
64
+ return true;
65
+ }
66
+ }
67
+ return isNullRoundError(error);
68
+ }
69
+
70
+ /**
71
+ * Helper function for "eth_getBlockByNumber" request.
72
+ */
73
+ export const eth_getBlockByNumber = <
74
+ params extends Extract<
75
+ RequestParameters,
76
+ { method: "eth_getBlockByNumber" }
77
+ >["params"],
78
+ >(
79
+ rpc: Rpc,
80
+ params: params,
81
+ context?: Parameters<Rpc["request"]>[1],
82
+ ): Promise<params[1] extends true ? SyncBlock : LightBlock> =>
83
+ rpc
84
+ .request({ method: "eth_getBlockByNumber", params }, context)
85
+ .then((_block) => {
86
+ if (!_block) {
87
+ let blockNumber: bigint;
88
+ if (isHex(params[0])) {
89
+ blockNumber = hexToBigInt(params[0]);
90
+ } else {
91
+ // @ts-expect-error `BlockNotFoundError` expects a bigint, but it also just passes
92
+ // the `blockNumber` directly to the error message, so breaking the type constraint is fine.
93
+ blockNumber = params[0];
94
+ }
95
+
96
+ throw new BlockNotFoundError({ blockNumber });
97
+ }
98
+ return standardizeBlock(_block as SyncBlock, {
99
+ method: "eth_getBlockByNumber",
100
+ params,
101
+ });
102
+ });
103
+
104
+ // Null rounds come in short runs; a longer run means the RPC is unhealthy.
105
+ const MAX_NULL_ROUNDS = 1_000;
106
+
107
+ /**
108
+ * The block at `blockNumber`, or the nearest block below it when that height is
109
+ * a null round (a Filecoin epoch without a block).
110
+ */
111
+ export const eth_getBlockAtOrBelow = async (
112
+ rpc: Rpc,
113
+ blockNumber: number,
114
+ context?: Parameters<Rpc["request"]>[1],
115
+ ): Promise<LightBlock> => {
116
+ for (let n = blockNumber; ; n--) {
117
+ try {
118
+ return await eth_getBlockByNumber(rpc, [numberToHex(n), false], context);
119
+ } catch (error) {
120
+ if (
121
+ !isNullRoundError(error) ||
122
+ n === 0 ||
123
+ blockNumber - n >= MAX_NULL_ROUNDS
124
+ ) {
125
+ throw error;
126
+ }
127
+ }
128
+ }
129
+ };
130
+
131
+ /**
132
+ * Helper function for "eth_getBlockByHash" request.
133
+ */
134
+ export const eth_getBlockByHash = <
135
+ params extends Extract<
136
+ RequestParameters,
137
+ { method: "eth_getBlockByHash" }
138
+ >["params"],
139
+ >(
140
+ rpc: Rpc,
141
+ params: params,
142
+ context?: Parameters<Rpc["request"]>[1],
143
+ ): Promise<params[1] extends true ? SyncBlock : LightBlock> =>
144
+ rpc
145
+ .request({ method: "eth_getBlockByHash", params }, context)
146
+ .then((_block) => {
147
+ if (!_block) throw new BlockNotFoundError({ blockHash: params[0] });
148
+ return standardizeBlock(_block as SyncBlock, {
149
+ method: "eth_getBlockByHash",
150
+ params,
151
+ });
152
+ });
153
+
154
+ /**
155
+ * Helper function for "eth_getLogs" rpc request.
156
+ * Handles different error types and retries the request if applicable.
157
+ */
158
+ export const eth_getLogs = async (
159
+ rpc: Rpc,
160
+ params: Extract<RequestParameters, { method: "eth_getLogs" }>["params"],
161
+ context?: Parameters<Rpc["request"]>[1],
162
+ ): Promise<SyncLog[]> => {
163
+ const request: Extract<RequestParameters, { method: "eth_getLogs" }> = {
164
+ method: "eth_getLogs",
165
+ params,
166
+ };
167
+
168
+ return rpc.request(request, context).then((logs) => {
169
+ if (logs === null || logs === undefined) {
170
+ throw new Error("Received invalid empty eth_getLogs response.");
171
+ }
172
+
173
+ return standardizeLogs(logs as SyncLog[], request);
174
+ });
175
+ };
176
+
177
+ /**
178
+ * Helper function for "eth_getTransactionReceipt" request.
179
+ */
180
+ export const eth_getTransactionReceipt = (
181
+ rpc: Rpc,
182
+ params: Extract<
183
+ RequestParameters,
184
+ { method: "eth_getTransactionReceipt" }
185
+ >["params"],
186
+ context?: Parameters<Rpc["request"]>[1],
187
+ ): Promise<SyncTransactionReceipt> =>
188
+ rpc
189
+ .request({ method: "eth_getTransactionReceipt", params }, context)
190
+ .then((receipt) => {
191
+ if (!receipt) {
192
+ throw new TransactionReceiptNotFoundError({
193
+ hash: params[0],
194
+ });
195
+ }
196
+
197
+ return standardizeTransactionReceipts([receipt], {
198
+ method: "eth_getTransactionReceipt",
199
+ params,
200
+ })[0]!;
201
+ });
202
+
203
+ /**
204
+ * Helper function for "eth_getBlockReceipts" request.
205
+ */
206
+ export const eth_getBlockReceipts = (
207
+ rpc: Rpc,
208
+ params: Extract<
209
+ RequestParameters,
210
+ { method: "eth_getBlockReceipts" }
211
+ >["params"],
212
+ context?: Parameters<Rpc["request"]>[1],
213
+ ): Promise<SyncTransactionReceipt[]> =>
214
+ rpc
215
+ .request({ method: "eth_getBlockReceipts", params }, context)
216
+ .then((receipts) => {
217
+ if (receipts === null || receipts === undefined) {
218
+ throw new Error(
219
+ "Received invalid empty eth_getBlockReceipts response.",
220
+ );
221
+ }
222
+
223
+ return standardizeTransactionReceipts(receipts, {
224
+ method: "eth_getBlockReceipts",
225
+ params,
226
+ });
227
+ });
228
+
229
+ /**
230
+ * Helper function for "debug_traceBlockByNumber" request.
231
+ */
232
+ export const debug_traceBlockByNumber = (
233
+ rpc: Rpc,
234
+ params: Extract<
235
+ RequestParameters,
236
+ { method: "debug_traceBlockByNumber" }
237
+ >["params"],
238
+ context?: Parameters<Rpc["request"]>[1],
239
+ ): Promise<SyncTrace[]> =>
240
+ rpc
241
+ .request({ method: "debug_traceBlockByNumber", params }, context)
242
+ .then((traces) => {
243
+ if (traces === null || traces === undefined) {
244
+ throw new Error(
245
+ "Received invalid empty debug_traceBlockByNumber response.",
246
+ );
247
+ }
248
+
249
+ const result: SyncTrace[] = [];
250
+ let index = 0;
251
+ // all traces that weren't included because the trace has an error
252
+ // or the trace's parent has an error, mapped to the error string
253
+ const failedTraces = new Map<
254
+ (typeof traces)[number]["result"],
255
+ { error?: string; revertReason?: string }
256
+ >();
257
+
258
+ const dfs = (
259
+ frames: (typeof traces)[number]["result"][],
260
+ transactionHash: Hex,
261
+ parentFrame: (typeof traces)[number]["result"] | undefined,
262
+ ) => {
263
+ for (const frame of frames) {
264
+ if (frame.error !== undefined) {
265
+ failedTraces.set(frame, {
266
+ error: frame.error,
267
+ revertReason: frame.revertReason,
268
+ });
269
+ } else if (parentFrame && failedTraces.has(parentFrame)) {
270
+ const error = failedTraces.get(parentFrame)!;
271
+
272
+ frame.error = error.error;
273
+ frame.revertReason = error.revertReason;
274
+
275
+ failedTraces.set(frame, error);
276
+ }
277
+
278
+ // @ts-expect-error
279
+ frame.index = index;
280
+ // @ts-expect-error
281
+ frame.subcalls = frame.calls?.length ?? 0;
282
+
283
+ result.push({ trace: frame as SyncTrace["trace"], transactionHash });
284
+
285
+ index++;
286
+
287
+ if (frame.calls) {
288
+ dfs(frame.calls, transactionHash, frame);
289
+ }
290
+ }
291
+ };
292
+
293
+ for (const trace of traces) {
294
+ index = 0;
295
+ dfs([trace.result], trace.txHash, undefined);
296
+ }
297
+
298
+ return result.map((trace) =>
299
+ standardizeTrace(trace, {
300
+ method: "debug_traceBlockByNumber",
301
+ params,
302
+ }),
303
+ );
304
+ });
305
+
306
+ /**
307
+ * Helper function for "debug_traceBlockByHash" request.
308
+ */
309
+ export const debug_traceBlockByHash = (
310
+ rpc: Rpc,
311
+ params: Extract<
312
+ RequestParameters,
313
+ { method: "debug_traceBlockByHash" }
314
+ >["params"],
315
+ context?: Parameters<Rpc["request"]>[1],
316
+ ): Promise<SyncTrace[]> =>
317
+ rpc
318
+ .request({ method: "debug_traceBlockByHash", params }, context)
319
+ .then((traces) => {
320
+ if (traces === null || traces === undefined) {
321
+ throw new Error(
322
+ "Received invalid empty debug_traceBlockByHash response.",
323
+ );
324
+ }
325
+
326
+ const result: SyncTrace[] = [];
327
+ let index = 0;
328
+ // all traces that weren't included because the trace has an error
329
+ // or the trace's parent has an error, mapped to the error string
330
+ const failedTraces = new Map<
331
+ (typeof traces)[number]["result"],
332
+ { error?: string; revertReason?: string }
333
+ >();
334
+
335
+ const dfs = (
336
+ frames: (typeof traces)[number]["result"][],
337
+ transactionHash: Hex,
338
+ parentFrame: (typeof traces)[number]["result"] | undefined,
339
+ ) => {
340
+ for (const frame of frames) {
341
+ if (frame.error !== undefined) {
342
+ failedTraces.set(frame, {
343
+ error: frame.error,
344
+ revertReason: frame.revertReason,
345
+ });
346
+ } else if (parentFrame && failedTraces.has(parentFrame)) {
347
+ const error = failedTraces.get(parentFrame)!;
348
+
349
+ frame.error = error.error;
350
+ frame.revertReason = error.revertReason;
351
+
352
+ failedTraces.set(frame, error);
353
+ }
354
+
355
+ // @ts-expect-error
356
+ frame.index = index;
357
+ // @ts-expect-error
358
+ frame.subcalls = frame.calls?.length ?? 0;
359
+
360
+ result.push({ trace: frame as SyncTrace["trace"], transactionHash });
361
+
362
+ index++;
363
+
364
+ if (frame.calls) {
365
+ dfs(frame.calls, transactionHash, frame);
366
+ }
367
+ }
368
+ };
369
+
370
+ for (const trace of traces) {
371
+ index = 0;
372
+ dfs([trace.result], trace.txHash, undefined);
373
+ }
374
+
375
+ return result.map((trace) =>
376
+ standardizeTrace(trace, {
377
+ method: "debug_traceBlockByHash",
378
+ params,
379
+ }),
380
+ );
381
+ });
382
+
383
+ /**
384
+ * Validate that the transactions are consistent with the block.
385
+ */
386
+ export const validateTransactionsAndBlock = (
387
+ block: SyncBlock,
388
+ request: Extract<
389
+ RequestParameters,
390
+ { method: "eth_getBlockByNumber" | "eth_getBlockByHash" }
391
+ >,
392
+ ) => {
393
+ for (const [index, transaction] of block.transactions.entries()) {
394
+ if (block.hash !== transaction.blockHash) {
395
+ const error = new RpcProviderError(
396
+ `Inconsistent RPC response data. The transaction at index ${index} of the 'block.transactions' array has a 'transaction.blockHash' of ${transaction.blockHash}, but the block itself has a 'block.hash' of ${block.hash}.`,
397
+ );
398
+ error.meta = [
399
+ "Please report this error to the RPC operator.",
400
+ requestText(request),
401
+ ];
402
+ error.stack = undefined;
403
+ throw error;
404
+ }
405
+
406
+ if (block.number !== transaction.blockNumber) {
407
+ const error = new RpcProviderError(
408
+ `Inconsistent RPC response data. The transaction at index ${index} of the 'block.transactions' array has a 'transaction.blockNumber' of ${transaction.blockNumber} (${hexToNumber(transaction.blockNumber)}), but the block itself has a 'block.number' of ${block.number} (${hexToNumber(block.number)}).`,
409
+ );
410
+ error.meta = [
411
+ "Please report this error to the RPC operator.",
412
+ requestText(request),
413
+ ];
414
+ error.stack = undefined;
415
+ throw error;
416
+ }
417
+ }
418
+ };
419
+
420
+ /**
421
+ * Validate that the logs are consistent with the block.
422
+ *
423
+ * @dev Allows `log.transactionHash` to be `zeroHash`.
424
+ * @dev Allows `block.logsBloom` to be `zeroLogsBloom`.
425
+ * @dev Filecoin FVM fills all logsBloom bits regardless of actual logs.
426
+ * The logsBloom vs empty-logs check is skipped for Filecoin chains.
427
+ */
428
+ export const validateLogsAndBlock = (
429
+ logs: SyncLog[],
430
+ block: SyncBlock,
431
+ logsRequest: Extract<RequestParameters, { method: "eth_getLogs" }>,
432
+ blockRequest: Extract<
433
+ RequestParameters,
434
+ { method: "eth_getBlockByNumber" | "eth_getBlockByHash" }
435
+ >,
436
+ chainId?: number,
437
+ ) => {
438
+ // Filecoin FVM sets all logsBloom bits to 1, defeating bloom filter
439
+ // optimizations. A non-zero logsBloom with zero logs is normal on Filecoin.
440
+ if (
441
+ block.logsBloom !== zeroLogsBloom &&
442
+ logs.length === 0 &&
443
+ !(chainId !== undefined && isFilecoinChain(chainId))
444
+ ) {
445
+ const error = new RpcProviderError(
446
+ `Inconsistent RPC response data. The logs array has length 0, but the associated block has a non-empty 'block.logsBloom'.`,
447
+ );
448
+ error.meta = [
449
+ "Please report this error to the RPC operator.",
450
+ requestText(blockRequest),
451
+ requestText(logsRequest),
452
+ ];
453
+ error.stack = undefined;
454
+ throw error;
455
+ }
456
+
457
+ const transactionByIndex = new Map<Hex, SyncTransaction>(
458
+ block.transactions.map((transaction) => [
459
+ transaction.transactionIndex,
460
+ transaction,
461
+ ]),
462
+ );
463
+
464
+ for (const log of logs) {
465
+ if (block.hash !== log.blockHash) {
466
+ const error = new RpcProviderError(
467
+ `Inconsistent RPC response data. The log with 'logIndex' ${log.logIndex} (${hexToNumber(log.logIndex)}) has a 'log.blockHash' of ${log.blockHash}, but the associated block has a 'block.hash' of ${block.hash}.`,
468
+ );
469
+ error.meta = [
470
+ "Please report this error to the RPC operator.",
471
+ requestText(blockRequest),
472
+ requestText(logsRequest),
473
+ ];
474
+ error.stack = undefined;
475
+ throw error;
476
+ }
477
+
478
+ if (block.number !== log.blockNumber) {
479
+ const error = new RpcProviderError(
480
+ `Inconsistent RPC response data. The log with 'logIndex' ${log.logIndex} (${hexToNumber(log.logIndex)}) has a 'log.blockNumber' of ${log.blockNumber} (${hexToNumber(log.blockNumber)}), but the associated block has a 'block.number' of ${block.number} (${hexToNumber(block.number)}).`,
481
+ );
482
+ error.meta = [
483
+ "Please report this error to the RPC operator.",
484
+ requestText(blockRequest),
485
+ requestText(logsRequest),
486
+ ];
487
+ error.stack = undefined;
488
+ throw error;
489
+ }
490
+
491
+ if (log.transactionHash !== zeroHash) {
492
+ const transaction = transactionByIndex.get(log.transactionIndex);
493
+ if (transaction === undefined) {
494
+ const error = new RpcProviderError(
495
+ `Inconsistent RPC response data. The log with 'logIndex' ${log.logIndex} (${hexToNumber(log.logIndex)}) has a 'log.transactionIndex' of ${log.transactionIndex} (${hexToNumber(log.transactionIndex)}), but the associated 'block.transactions' array does not contain a transaction matching that 'transactionIndex'.`,
496
+ );
497
+ error.meta = [
498
+ "Please report this error to the RPC operator.",
499
+ requestText(blockRequest),
500
+ requestText(logsRequest),
501
+ ];
502
+ error.stack = undefined;
503
+ throw error;
504
+ } else if (transaction.hash !== log.transactionHash) {
505
+ const error = new RpcProviderError(
506
+ `Inconsistent RPC response data. The log with 'logIndex' ${log.logIndex} (${hexToNumber(log.logIndex)}) matches a transaction in the associated 'block.transactions' array by 'transactionIndex' ${log.transactionIndex} (${hexToNumber(log.transactionIndex)}), but the log has a 'log.transactionHash' of ${log.transactionHash} while the transaction has a 'transaction.hash' of ${transaction.hash}.`,
507
+ );
508
+ error.meta = [
509
+ "Please report this error to the RPC operator.",
510
+ requestText(blockRequest),
511
+ requestText(logsRequest),
512
+ ];
513
+ error.stack = undefined;
514
+ throw error;
515
+ }
516
+ }
517
+ }
518
+ };
519
+
520
+ /**
521
+ * Validate that the traces are consistent with the block.
522
+ */
523
+ export const validateTracesAndBlock = (
524
+ traces: SyncTrace[],
525
+ block: SyncBlock,
526
+ tracesRequest: Extract<
527
+ RequestParameters,
528
+ { method: "debug_traceBlockByNumber" | "debug_traceBlockByHash" }
529
+ >,
530
+ blockRequest: Extract<
531
+ RequestParameters,
532
+ { method: "eth_getBlockByNumber" | "eth_getBlockByHash" }
533
+ >,
534
+ ) => {
535
+ const transactionHashes = new Set(block.transactions.map((t) => t.hash));
536
+ for (const [index, trace] of traces.entries()) {
537
+ if (transactionHashes.has(trace.transactionHash) === false) {
538
+ const error = new RpcProviderError(
539
+ `Inconsistent RPC response data. The top-level trace at array index ${index} has a 'transactionHash' of ${trace.transactionHash}, but the associated 'block.transactions' array does not contain a transaction matching that hash.`,
540
+ );
541
+ error.meta = [
542
+ "Please report this error to the RPC operator.",
543
+ requestText(blockRequest),
544
+ requestText(tracesRequest),
545
+ ];
546
+ error.stack = undefined;
547
+ throw error;
548
+ }
549
+ }
550
+
551
+ // Use the fact that any transaction produces a trace to validate.
552
+ if (block.transactions.length !== 0 && traces.length === 0) {
553
+ const error = new RpcProviderError(
554
+ `Inconsistent RPC response data. The traces array has length 0, but the associated 'block.transactions' array has length ${block.transactions.length}.`,
555
+ );
556
+ error.meta = [
557
+ "Please report this error to the RPC operator.",
558
+ requestText(blockRequest),
559
+ requestText(tracesRequest),
560
+ ];
561
+ error.stack = undefined;
562
+ throw error;
563
+ }
564
+ };
565
+
566
+ /**
567
+ * Validate that the receipts are consistent with the block.
568
+ */
569
+ export const validateReceiptsAndBlock = (
570
+ receipts: SyncTransactionReceipt[],
571
+ block: SyncBlock,
572
+ receiptsRequest: Extract<
573
+ RequestParameters,
574
+ { method: "eth_getBlockReceipts" | "eth_getTransactionReceipt" }
575
+ >,
576
+ blockRequest: Extract<
577
+ RequestParameters,
578
+ { method: "eth_getBlockByNumber" | "eth_getBlockByHash" }
579
+ >,
580
+ ) => {
581
+ const transactionByIndex = new Map<Hex, SyncTransaction>(
582
+ block.transactions.map((transaction) => [
583
+ transaction.transactionIndex,
584
+ transaction,
585
+ ]),
586
+ );
587
+
588
+ for (const [index, receipt] of receipts.entries()) {
589
+ if (block.hash !== receipt.blockHash) {
590
+ const error = new RpcProviderError(
591
+ `Inconsistent RPC response data. The receipt at array index ${index} has a 'receipt.blockHash' of ${receipt.blockHash}, but the associated block has a 'block.hash' of ${block.hash}.`,
592
+ );
593
+ error.meta = [
594
+ "Please report this error to the RPC operator.",
595
+ requestText(blockRequest),
596
+ requestText(receiptsRequest),
597
+ ];
598
+ error.stack = undefined;
599
+ throw error;
600
+ }
601
+
602
+ if (block.number !== receipt.blockNumber) {
603
+ const error = new RpcProviderError(
604
+ `Inconsistent RPC response data. The receipt at array index ${index} has a 'receipt.blockNumber' of ${receipt.blockNumber} (${hexToNumber(receipt.blockNumber)}), but the associated block has a 'block.number' of ${block.number} (${hexToNumber(block.number)}).`,
605
+ );
606
+ error.meta = [
607
+ "Please report this error to the RPC operator.",
608
+ requestText(blockRequest),
609
+ requestText(receiptsRequest),
610
+ ];
611
+ error.stack = undefined;
612
+ throw error;
613
+ }
614
+
615
+ const transaction = transactionByIndex.get(receipt.transactionIndex);
616
+ if (transaction === undefined) {
617
+ const error = new RpcProviderError(
618
+ `Inconsistent RPC response data. The receipt at array index ${index} has a 'receipt.transactionIndex' of ${receipt.transactionIndex} (${hexToNumber(receipt.transactionIndex)}), but the associated 'block.transactions' array does not contain a transaction matching that 'transactionIndex'.`,
619
+ );
620
+ error.meta = [
621
+ "Please report this error to the RPC operator.",
622
+ requestText(blockRequest),
623
+ requestText(receiptsRequest),
624
+ ];
625
+ error.stack = undefined;
626
+ throw error;
627
+ } else if (transaction.hash !== receipt.transactionHash) {
628
+ const error = new RpcProviderError(
629
+ `Inconsistent RPC response data. The receipt at array index ${index} matches a transaction in the associated 'block.transactions' array by 'transactionIndex' ${receipt.transactionIndex} (${hexToNumber(receipt.transactionIndex)}), but the receipt has a 'receipt.transactionHash' of ${receipt.transactionHash} while the transaction has a 'transaction.hash' of ${transaction.hash}.`,
630
+ );
631
+ error.meta = [
632
+ "Please report this error to the RPC operator.",
633
+ requestText(blockRequest),
634
+ requestText(receiptsRequest),
635
+ ];
636
+ error.stack = undefined;
637
+ throw error;
638
+ }
639
+ }
640
+
641
+ if (
642
+ receiptsRequest.method === "eth_getBlockReceipts" &&
643
+ block.transactions.length !== receipts.length
644
+ ) {
645
+ const error = new RpcProviderError(
646
+ `Inconsistent RPC response data. The receipts array has length ${receipts.length}, but the associated 'block.transactions' array has length ${block.transactions.length}.`,
647
+ );
648
+ error.meta = [
649
+ "Please report this error to the RPC operator.",
650
+ requestText(blockRequest),
651
+ requestText(receiptsRequest),
652
+ ];
653
+ error.stack = undefined;
654
+ throw error;
655
+ }
656
+ };
657
+
658
+ /**
659
+ * Validate required block properties and set non-required properties.
660
+ *
661
+ * Required properties:
662
+ * - hash
663
+ * - number
664
+ * - timestamp
665
+ * - logsBloom
666
+ * - parentHash
667
+ * - transactions
668
+ *
669
+ * Non-required properties:
670
+ * - miner
671
+ * - gasUsed
672
+ * - gasLimit
673
+ * - baseFeePerGas
674
+ * - nonce
675
+ * - mixHash
676
+ * - stateRoot
677
+ * - transactionsRoot
678
+ * - sha3Uncles
679
+ * - size
680
+ * - difficulty
681
+ * - totalDifficulty
682
+ * - extraData
683
+ */
684
+ export const standardizeBlock = <
685
+ block extends
686
+ | SyncBlock
687
+ | (Omit<SyncBlock, "transactions"> & {
688
+ transactions: string[] | undefined;
689
+ }),
690
+ >(
691
+ block: block,
692
+ request:
693
+ | Extract<
694
+ RequestParameters,
695
+ { method: "eth_getBlockByNumber" | "eth_getBlockByHash" }
696
+ >
697
+ | { method: "eth_subscribe"; params: ["newHeads"] },
698
+ ): block extends SyncBlock ? SyncBlock : SyncBlockHeader => {
699
+ // required properties
700
+ if (block.hash === undefined) {
701
+ const error = new RpcProviderError(
702
+ "Invalid RPC response: 'block.hash' is a required property",
703
+ );
704
+ error.meta = [
705
+ "Please report this error to the RPC operator.",
706
+ requestText(request),
707
+ ];
708
+ error.stack = undefined;
709
+ throw error;
710
+ }
711
+ if (block.number === undefined) {
712
+ const error = new RpcProviderError(
713
+ "Invalid RPC response: 'block.number' is a required property",
714
+ );
715
+ error.meta = [
716
+ "Please report this error to the RPC operator.",
717
+ requestText(request),
718
+ ];
719
+ error.stack = undefined;
720
+ throw error;
721
+ }
722
+ if (block.timestamp === undefined) {
723
+ const error = new RpcProviderError(
724
+ "Invalid RPC response: 'block.timestamp' is a required property",
725
+ );
726
+ error.meta = [
727
+ "Please report this error to the RPC operator.",
728
+ requestText(request),
729
+ ];
730
+ error.stack = undefined;
731
+ throw error;
732
+ }
733
+ if (block.logsBloom === undefined) {
734
+ const error = new RpcProviderError(
735
+ "Invalid RPC response: 'block.logsBloom' is a required property",
736
+ );
737
+ error.meta = [
738
+ "Please report this error to the RPC operator.",
739
+ requestText(request),
740
+ ];
741
+ error.stack = undefined;
742
+ throw error;
743
+ }
744
+ if (block.parentHash === undefined) {
745
+ const error = new RpcProviderError(
746
+ "Invalid RPC response: 'block.parentHash' is a required property",
747
+ );
748
+ error.meta = [
749
+ "Please report this error to the RPC operator.",
750
+ requestText(request),
751
+ ];
752
+ error.stack = undefined;
753
+ throw error;
754
+ }
755
+
756
+ // non-required properties
757
+ if (block.miner === undefined) {
758
+ block.miner = zeroAddress;
759
+ }
760
+ if (block.gasUsed === undefined) {
761
+ block.gasUsed = "0x0";
762
+ }
763
+ if (block.gasLimit === undefined) {
764
+ block.gasLimit = "0x0";
765
+ }
766
+ if (block.baseFeePerGas === undefined) {
767
+ block.baseFeePerGas = "0x0";
768
+ }
769
+ if (block.nonce === undefined) {
770
+ block.nonce = "0x0";
771
+ }
772
+ if (block.mixHash === undefined) {
773
+ block.mixHash = zeroHash;
774
+ }
775
+ if (block.stateRoot === undefined) {
776
+ block.stateRoot = zeroHash;
777
+ }
778
+ if (block.transactionsRoot === undefined) {
779
+ block.transactionsRoot = zeroHash;
780
+ }
781
+ if (block.sha3Uncles === undefined) {
782
+ block.sha3Uncles = zeroHash;
783
+ }
784
+ if (block.size === undefined) {
785
+ block.size = "0x0";
786
+ }
787
+ if (block.difficulty === undefined) {
788
+ block.difficulty = "0x0";
789
+ }
790
+ if (block.totalDifficulty === undefined) {
791
+ block.totalDifficulty = "0x0";
792
+ }
793
+ if (block.extraData === undefined) {
794
+ block.extraData = "0x";
795
+ }
796
+
797
+ if (hexToBigInt(block.number) > PG_BIGINT_MAX) {
798
+ const error = new RpcProviderError(
799
+ `Invalid RPC response: 'block.number' (${hexToBigInt(block.number)}) is larger than the maximum allowed value (${PG_BIGINT_MAX}).`,
800
+ );
801
+ error.meta = [
802
+ "Please report this error to the RPC operator.",
803
+ requestText(request),
804
+ ];
805
+ error.stack = undefined;
806
+ throw error;
807
+ }
808
+ if (hexToBigInt(block.timestamp) > PG_BIGINT_MAX) {
809
+ const error = new RpcProviderError(
810
+ `Invalid RPC response: 'block.timestamp' (${hexToBigInt(block.timestamp)}) is larger than the maximum allowed value (${PG_BIGINT_MAX}).`,
811
+ );
812
+ error.meta = [
813
+ "Please report this error to the RPC operator.",
814
+ requestText(request),
815
+ ];
816
+ error.stack = undefined;
817
+ throw error;
818
+ }
819
+
820
+ // Note: block headers for some providers may contain transactions hashes,
821
+ // but Ponder coerces the transactions property to undefined.
822
+
823
+ if (request.method === "eth_subscribe" || request.params[1] === false) {
824
+ block.transactions = undefined;
825
+
826
+ return block as block extends SyncBlock ? SyncBlock : SyncBlockHeader;
827
+ } else {
828
+ if (block.transactions === undefined) {
829
+ throw new Error(
830
+ "Invalid RPC response: 'block.transactions' is a required property",
831
+ );
832
+ }
833
+
834
+ block.transactions = standardizeTransactions(
835
+ (block as SyncBlock).transactions,
836
+ request,
837
+ );
838
+
839
+ return block as block extends SyncBlock ? SyncBlock : SyncBlockHeader;
840
+ }
841
+ };
842
+
843
+ /**
844
+ * Validate required transaction properties and set non-required properties.
845
+ *
846
+ * Required properties:
847
+ * - hash
848
+ * - transactionIndex
849
+ * - blockNumber
850
+ * - blockHash
851
+ * - from
852
+ * - to
853
+ *
854
+ * Non-required properties:
855
+ * - input
856
+ * - value
857
+ * - nonce
858
+ * - r
859
+ * - s
860
+ * - v
861
+ * - type
862
+ * - gas
863
+ */
864
+ export const standardizeTransactions = (
865
+ transactions: SyncTransaction[],
866
+ request: Extract<
867
+ RequestParameters,
868
+ { method: "eth_getBlockByNumber" | "eth_getBlockByHash" }
869
+ >,
870
+ ): SyncTransaction[] => {
871
+ const transactionIds = new Set<Hex>();
872
+
873
+ for (const transaction of transactions) {
874
+ if (transactionIds.has(transaction.transactionIndex)) {
875
+ const error = new RpcProviderError(
876
+ `Inconsistent RPC response data. The 'block.transactions' array contains two objects with a 'transactionIndex' of ${transaction.transactionIndex} (${hexToNumber(transaction.transactionIndex)}).`,
877
+ );
878
+ error.meta = [
879
+ "Please report this error to the RPC operator.",
880
+ requestText(request),
881
+ ];
882
+ error.stack = undefined;
883
+ throw error;
884
+ } else {
885
+ transactionIds.add(transaction.transactionIndex);
886
+ }
887
+
888
+ // required properties
889
+ if (transaction.hash === undefined) {
890
+ const error = new RpcProviderError(
891
+ "Invalid RPC response: 'transaction.hash' is a required property",
892
+ );
893
+ error.meta = [
894
+ "Please report this error to the RPC operator.",
895
+ requestText(request),
896
+ ];
897
+ error.stack = undefined;
898
+ throw error;
899
+ }
900
+ if (transaction.transactionIndex === undefined) {
901
+ const error = new RpcProviderError(
902
+ "Invalid RPC response: 'transaction.transactionIndex' is a required property",
903
+ );
904
+ error.meta = [
905
+ "Please report this error to the RPC operator.",
906
+ requestText(request),
907
+ ];
908
+ error.stack = undefined;
909
+ throw error;
910
+ }
911
+ if (transaction.blockNumber === undefined) {
912
+ const error = new RpcProviderError(
913
+ "Invalid RPC response: 'transaction.blockNumber' is a required property",
914
+ );
915
+ error.meta = [
916
+ "Please report this error to the RPC operator.",
917
+ requestText(request),
918
+ ];
919
+ error.stack = undefined;
920
+ throw error;
921
+ }
922
+ if (transaction.blockHash === undefined) {
923
+ const error = new RpcProviderError(
924
+ "Invalid RPC response: 'transaction.blockHash' is a required property",
925
+ );
926
+ error.meta = [
927
+ "Please report this error to the RPC operator.",
928
+ requestText(request),
929
+ ];
930
+ error.stack = undefined;
931
+ throw error;
932
+ }
933
+ if (transaction.from === undefined) {
934
+ const error = new RpcProviderError(
935
+ "Invalid RPC response: 'transaction.from' is a required property",
936
+ );
937
+ error.meta = [
938
+ "Please report this error to the RPC operator.",
939
+ requestText(request),
940
+ ];
941
+ error.stack = undefined;
942
+ throw error;
943
+ }
944
+
945
+ // Note: `to` is a required property but can be coerced to `null`.
946
+ if (transaction.to === undefined) {
947
+ transaction.to = null;
948
+ }
949
+
950
+ // non-required properties
951
+ if (transaction.input === undefined) {
952
+ transaction.input = "0x";
953
+ }
954
+ if (transaction.value === undefined) {
955
+ transaction.value = "0x0";
956
+ }
957
+ if (transaction.nonce === undefined) {
958
+ transaction.nonce = "0x0";
959
+ }
960
+ if (transaction.r === undefined) {
961
+ transaction.r = "0x0";
962
+ }
963
+ if (transaction.s === undefined) {
964
+ transaction.s = "0x0";
965
+ }
966
+ if (transaction.v === undefined) {
967
+ transaction.v = "0x0";
968
+ }
969
+ if (transaction.type === undefined) {
970
+ // @ts-expect-error
971
+ transaction.type = "0x0";
972
+ }
973
+ if (transaction.gas === undefined) {
974
+ transaction.gas = "0x0";
975
+ }
976
+
977
+ if (hexToBigInt(transaction.blockNumber) > PG_BIGINT_MAX) {
978
+ const error = new RpcProviderError(
979
+ `Invalid RPC response: 'transaction.blockNumber' (${hexToBigInt(transaction.blockNumber)}) is larger than the maximum allowed value (${PG_BIGINT_MAX}).`,
980
+ );
981
+ error.meta = [
982
+ "Please report this error to the RPC operator.",
983
+ requestText(request),
984
+ ];
985
+ error.stack = undefined;
986
+ throw error;
987
+ }
988
+ if (hexToBigInt(transaction.transactionIndex) > BigInt(PG_INTEGER_MAX)) {
989
+ const error = new RpcProviderError(
990
+ `Invalid RPC response: 'transaction.transactionIndex' (${hexToBigInt(transaction.transactionIndex)}) is larger than the maximum allowed value (${PG_INTEGER_MAX}).`,
991
+ );
992
+ error.meta = [
993
+ "Please report this error to the RPC operator.",
994
+ requestText(request),
995
+ ];
996
+ error.stack = undefined;
997
+ throw error;
998
+ }
999
+ if (hexToBigInt(transaction.nonce) > BigInt(PG_INTEGER_MAX)) {
1000
+ const error = new RpcProviderError(
1001
+ `Invalid RPC response: 'transaction.nonce' (${hexToBigInt(transaction.nonce)}) is larger than the maximum allowed value (${PG_INTEGER_MAX}).`,
1002
+ );
1003
+ error.meta = [
1004
+ "Please report this error to the RPC operator.",
1005
+ requestText(request),
1006
+ ];
1007
+ error.stack = undefined;
1008
+ throw error;
1009
+ }
1010
+ }
1011
+ return transactions;
1012
+ };
1013
+
1014
+ /**
1015
+ * Validate required log properties and set properties.
1016
+ *
1017
+ * Required properties:
1018
+ * - blockNumber
1019
+ * - logIndex
1020
+ * - blockHash
1021
+ * - address
1022
+ * - topics
1023
+ * - data
1024
+ * - transactionHash
1025
+ * - transactionIndex
1026
+ *
1027
+ * Non-required properties:
1028
+ * - removed
1029
+ */
1030
+ export const standardizeLogs = (
1031
+ logs: SyncLog[],
1032
+ request: Extract<RequestParameters, { method: "eth_getLogs" }>,
1033
+ ): SyncLog[] => {
1034
+ const logIds = new Set<string>();
1035
+ for (const log of logs) {
1036
+ if (logIds.has(`${log.blockNumber}_${log.logIndex}`)) {
1037
+ const error = new RpcProviderError(
1038
+ `Inconsistent RPC response data. The logs array contains two objects with 'blockNumber' ${log.blockNumber} (${hexToNumber(log.blockNumber)}) and 'logIndex' ${log.logIndex} (${hexToNumber(log.logIndex)}).`,
1039
+ );
1040
+ error.meta = [
1041
+ "Please report this error to the RPC operator.",
1042
+ requestText(request),
1043
+ ];
1044
+
1045
+ error.stack = undefined;
1046
+ throw error;
1047
+ } else {
1048
+ logIds.add(`${log.blockNumber}_${log.logIndex}`);
1049
+ }
1050
+
1051
+ // required properties
1052
+ if (log.blockNumber === undefined) {
1053
+ const error = new RpcProviderError(
1054
+ "Invalid RPC response: 'log.blockNumber' is a required property",
1055
+ );
1056
+ error.meta = [
1057
+ "Please report this error to the RPC operator.",
1058
+ requestText(request),
1059
+ ];
1060
+ error.stack = undefined;
1061
+ throw error;
1062
+ }
1063
+ if (log.logIndex === undefined) {
1064
+ const error = new RpcProviderError(
1065
+ "Invalid RPC response: 'log.logIndex' is a required property",
1066
+ );
1067
+ error.meta = [
1068
+ "Please report this error to the RPC operator.",
1069
+ requestText(request),
1070
+ ];
1071
+ error.stack = undefined;
1072
+ throw error;
1073
+ }
1074
+ if (log.blockHash === undefined) {
1075
+ const error = new RpcProviderError(
1076
+ "Invalid RPC response: 'log.blockHash' is a required property",
1077
+ );
1078
+ error.meta = [
1079
+ "Please report this error to the RPC operator.",
1080
+ requestText(request),
1081
+ ];
1082
+ error.stack = undefined;
1083
+ throw error;
1084
+ }
1085
+ if (log.address === undefined) {
1086
+ const error = new RpcProviderError(
1087
+ "Invalid RPC response: 'log.address' is a required property",
1088
+ );
1089
+ error.meta = [
1090
+ "Please report this error to the RPC operator.",
1091
+ requestText(request),
1092
+ ];
1093
+ error.stack = undefined;
1094
+ throw error;
1095
+ }
1096
+ if (log.topics === undefined) {
1097
+ const error = new RpcProviderError(
1098
+ "Invalid RPC response: 'log.topics' is a required property",
1099
+ );
1100
+ error.meta = [
1101
+ "Please report this error to the RPC operator.",
1102
+ requestText(request),
1103
+ ];
1104
+ error.stack = undefined;
1105
+ throw error;
1106
+ }
1107
+ if (log.data === undefined) {
1108
+ const error = new RpcProviderError(
1109
+ "Invalid RPC response: 'log.data' is a required property",
1110
+ );
1111
+ error.meta = [
1112
+ "Please report this error to the RPC operator.",
1113
+ requestText(request),
1114
+ ];
1115
+ error.stack = undefined;
1116
+ throw error;
1117
+ }
1118
+ if (log.transactionHash === undefined) {
1119
+ log.transactionHash = zeroHash;
1120
+ }
1121
+ if (log.transactionIndex === undefined) {
1122
+ log.transactionIndex = "0x0";
1123
+ }
1124
+
1125
+ // non-required properties
1126
+ if (log.removed === undefined) {
1127
+ log.removed = false;
1128
+ }
1129
+
1130
+ if (hexToBigInt(log.blockNumber) > PG_BIGINT_MAX) {
1131
+ const error = new RpcProviderError(
1132
+ `Invalid RPC response: 'log.blockNumber' (${hexToBigInt(log.blockNumber)}) is larger than the maximum allowed value (${PG_BIGINT_MAX}).`,
1133
+ );
1134
+ error.meta = [
1135
+ "Please report this error to the RPC operator.",
1136
+ requestText(request),
1137
+ ];
1138
+ error.stack = undefined;
1139
+ throw error;
1140
+ }
1141
+ if (hexToBigInt(log.transactionIndex) > BigInt(PG_INTEGER_MAX)) {
1142
+ const error = new RpcProviderError(
1143
+ `Invalid RPC response: 'log.transactionIndex' (${hexToBigInt(log.transactionIndex)}) is larger than the maximum allowed value (${PG_INTEGER_MAX}).`,
1144
+ );
1145
+ error.meta = [
1146
+ "Please report this error to the RPC operator.",
1147
+ requestText(request),
1148
+ ];
1149
+ error.stack = undefined;
1150
+ throw error;
1151
+ }
1152
+ if (hexToBigInt(log.logIndex) > BigInt(PG_INTEGER_MAX)) {
1153
+ const error = new RpcProviderError(
1154
+ `Invalid RPC response: 'log.logIndex' (${hexToBigInt(log.logIndex)}) is larger than the maximum allowed value (${PG_INTEGER_MAX}).`,
1155
+ );
1156
+ error.meta = [
1157
+ "Please report this error to the RPC operator.",
1158
+ requestText(request),
1159
+ ];
1160
+ error.stack = undefined;
1161
+ throw error;
1162
+ }
1163
+ }
1164
+
1165
+ return logs;
1166
+ };
1167
+
1168
+ /**
1169
+ * Validate required trace properties and set non-required properties.
1170
+ *
1171
+ * Required properties:
1172
+ * - transactionHash
1173
+ * - type
1174
+ * - from
1175
+ * - input
1176
+ *
1177
+ * Non-required properties:
1178
+ * - gas
1179
+ * - gasUsed
1180
+ */
1181
+ export const standardizeTrace = (
1182
+ trace: SyncTrace,
1183
+ request: Extract<
1184
+ RequestParameters,
1185
+ { method: "debug_traceBlockByNumber" | "debug_traceBlockByHash" }
1186
+ >,
1187
+ ): SyncTrace => {
1188
+ // required properties
1189
+ if (trace.transactionHash === undefined) {
1190
+ const error = new RpcProviderError(
1191
+ "Invalid RPC response: 'trace.transactionHash' is a required property",
1192
+ );
1193
+ error.meta = [
1194
+ "Please report this error to the RPC operator.",
1195
+ requestText(request),
1196
+ ];
1197
+ error.stack = undefined;
1198
+ throw error;
1199
+ }
1200
+ if (trace.trace.type === undefined) {
1201
+ const error = new RpcProviderError(
1202
+ "Invalid RPC response: 'trace.type' is a required property",
1203
+ );
1204
+ error.meta = [
1205
+ "Please report this error to the RPC operator.",
1206
+ requestText(request),
1207
+ ];
1208
+ error.stack = undefined;
1209
+ throw error;
1210
+ }
1211
+ if (trace.trace.from === undefined) {
1212
+ const error = new RpcProviderError(
1213
+ "Invalid RPC response: 'trace.from' is a required property",
1214
+ );
1215
+ error.meta = [
1216
+ "Please report this error to the RPC operator.",
1217
+ requestText(request),
1218
+ ];
1219
+ error.stack = undefined;
1220
+ throw error;
1221
+ }
1222
+ if (trace.trace.input === undefined) {
1223
+ const error = new RpcProviderError(
1224
+ "Invalid RPC response: 'trace.input' is a required property",
1225
+ );
1226
+ error.meta = [
1227
+ "Please report this error to the RPC operator.",
1228
+ requestText(request),
1229
+ ];
1230
+ error.stack = undefined;
1231
+ throw error;
1232
+ }
1233
+
1234
+ // non-required properties
1235
+ if (trace.trace.gas === undefined) {
1236
+ trace.trace.gas = "0x0";
1237
+ }
1238
+ if (trace.trace.gasUsed === undefined) {
1239
+ trace.trace.gasUsed = "0x0";
1240
+ }
1241
+
1242
+ // Note: All INTEGER and BIGINT `trace` columns are generated, not derived from
1243
+ // RPC responses.
1244
+
1245
+ return trace;
1246
+ };
1247
+
1248
+ /**
1249
+ * Validate required transaction receipt properties and set non-required properties.
1250
+ *
1251
+ * Required properties:
1252
+ * - blockHash
1253
+ * - blockNumber
1254
+ * - transactionHash
1255
+ * - transactionIndex
1256
+ * - from
1257
+ * - to
1258
+ * - status
1259
+ *
1260
+ * Non-required properties:
1261
+ * - logs
1262
+ * - logsBloom
1263
+ * - gasUsed
1264
+ * - cumulativeGasUsed
1265
+ * - effectiveGasPrice
1266
+ * - root
1267
+ * - type
1268
+ */
1269
+ export const standardizeTransactionReceipts = (
1270
+ receipts: SyncTransactionReceipt[],
1271
+ request: Extract<
1272
+ RequestParameters,
1273
+ { method: "eth_getBlockReceipts" | "eth_getTransactionReceipt" }
1274
+ >,
1275
+ ): SyncTransactionReceipt[] => {
1276
+ const receiptIds = new Set<string>();
1277
+ for (const receipt of receipts) {
1278
+ if (receiptIds.has(receipt.transactionHash)) {
1279
+ const error = new RpcProviderError(
1280
+ `Inconsistent RPC response data. The receipts array contains two objects with a 'transactionHash' of ${receipt.transactionHash}.`,
1281
+ );
1282
+ error.meta = [
1283
+ "Please report this error to the RPC operator.",
1284
+ requestText(request),
1285
+ ];
1286
+ error.stack = undefined;
1287
+ throw error;
1288
+ } else {
1289
+ receiptIds.add(receipt.transactionHash);
1290
+ }
1291
+
1292
+ // required properties
1293
+ if (receipt.blockHash === undefined) {
1294
+ const error = new RpcProviderError(
1295
+ "Invalid RPC response: 'receipt.blockHash' is a required property",
1296
+ );
1297
+ error.meta = [
1298
+ "Please report this error to the RPC operator.",
1299
+ requestText(request),
1300
+ ];
1301
+ error.stack = undefined;
1302
+ throw error;
1303
+ }
1304
+ if (receipt.blockNumber === undefined) {
1305
+ const error = new RpcProviderError(
1306
+ "Invalid RPC response: 'receipt.blockNumber' is a required property",
1307
+ );
1308
+ error.meta = [
1309
+ "Please report this error to the RPC operator.",
1310
+ requestText(request),
1311
+ ];
1312
+ error.stack = undefined;
1313
+ throw error;
1314
+ }
1315
+ if (receipt.transactionHash === undefined) {
1316
+ const error = new RpcProviderError(
1317
+ "Invalid RPC response: 'receipt.transactionHash' is a required property",
1318
+ );
1319
+ error.meta = [
1320
+ "Please report this error to the RPC operator.",
1321
+ requestText(request),
1322
+ ];
1323
+ error.stack = undefined;
1324
+ throw error;
1325
+ }
1326
+ if (receipt.transactionIndex === undefined) {
1327
+ const error = new RpcProviderError(
1328
+ "Invalid RPC response: 'receipt.transactionIndex' is a required property",
1329
+ );
1330
+ error.meta = [
1331
+ "Please report this error to the RPC operator.",
1332
+ requestText(request),
1333
+ ];
1334
+ error.stack = undefined;
1335
+ throw error;
1336
+ }
1337
+ if (receipt.from === undefined) {
1338
+ const error = new RpcProviderError(
1339
+ "Invalid RPC response: 'receipt.from' is a required property",
1340
+ );
1341
+ error.meta = [
1342
+ "Please report this error to the RPC operator.",
1343
+ requestText(request),
1344
+ ];
1345
+ error.stack = undefined;
1346
+ throw error;
1347
+ }
1348
+ if (receipt.status === undefined) {
1349
+ const error = new RpcProviderError(
1350
+ "Invalid RPC response: 'receipt.status' is a required property",
1351
+ );
1352
+ error.meta = [
1353
+ "Please report this error to the RPC operator.",
1354
+ requestText(request),
1355
+ ];
1356
+ error.stack = undefined;
1357
+ throw error;
1358
+ }
1359
+
1360
+ // Note: `to` is a required property but can be coerced to `null`.
1361
+ if (receipt.to === undefined) {
1362
+ receipt.to = null;
1363
+ }
1364
+
1365
+ // non-required properties
1366
+ if (receipt.logs === undefined) {
1367
+ receipt.logs = [];
1368
+ }
1369
+ if (receipt.logsBloom === undefined) {
1370
+ receipt.logsBloom = zeroLogsBloom;
1371
+ }
1372
+ if (receipt.gasUsed === undefined) {
1373
+ receipt.gasUsed = "0x0";
1374
+ }
1375
+ if (receipt.cumulativeGasUsed === undefined) {
1376
+ receipt.cumulativeGasUsed = "0x0";
1377
+ }
1378
+ if (receipt.effectiveGasPrice === undefined) {
1379
+ receipt.effectiveGasPrice = "0x0";
1380
+ }
1381
+ if (receipt.root === undefined) {
1382
+ receipt.root = zeroHash;
1383
+ }
1384
+ if (receipt.type === undefined) {
1385
+ receipt.type = "0x0";
1386
+ }
1387
+
1388
+ if (hexToBigInt(receipt.blockNumber) > PG_BIGINT_MAX) {
1389
+ const error = new RpcProviderError(
1390
+ `Invalid RPC response: 'receipt.blockNumber' (${hexToBigInt(receipt.blockNumber)}) is larger than the maximum allowed value (${PG_BIGINT_MAX}).`,
1391
+ );
1392
+ error.meta = [
1393
+ "Please report this error to the RPC operator.",
1394
+ requestText(request),
1395
+ ];
1396
+ error.stack = undefined;
1397
+ throw error;
1398
+ }
1399
+ if (hexToBigInt(receipt.transactionIndex) > BigInt(PG_INTEGER_MAX)) {
1400
+ const error = new RpcProviderError(
1401
+ `Invalid RPC response: 'receipt.transactionIndex' (${hexToBigInt(receipt.transactionIndex)}) is larger than the maximum allowed value (${PG_INTEGER_MAX}).`,
1402
+ );
1403
+ error.meta = [
1404
+ "Please report this error to the RPC operator.",
1405
+ requestText(request),
1406
+ ];
1407
+ error.stack = undefined;
1408
+ throw error;
1409
+ }
1410
+ }
1411
+ return receipts;
1412
+ };
1413
+
1414
+ function requestText(request: { method: string; params: any[] }): string {
1415
+ return `Request: ${JSON.stringify(
1416
+ {
1417
+ method: request.method,
1418
+ params: request.params,
1419
+ },
1420
+ null,
1421
+ 2,
1422
+ )}`;
1423
+ }