ponder-with-flashblocks 0.16.3

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