@mikeatlast/ponder 0.16.1-fork.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3415 -0
- package/README.md +186 -0
- package/dist/esm/bin/commands/codegen.js +46 -0
- package/dist/esm/bin/commands/codegen.js.map +1 -0
- package/dist/esm/bin/commands/createViews.js +196 -0
- package/dist/esm/bin/commands/createViews.js.map +1 -0
- package/dist/esm/bin/commands/dev.js +430 -0
- package/dist/esm/bin/commands/dev.js.map +1 -0
- package/dist/esm/bin/commands/list.js +148 -0
- package/dist/esm/bin/commands/list.js.map +1 -0
- package/dist/esm/bin/commands/prune.js +223 -0
- package/dist/esm/bin/commands/prune.js.map +1 -0
- package/dist/esm/bin/commands/serve.js +198 -0
- package/dist/esm/bin/commands/serve.js.map +1 -0
- package/dist/esm/bin/commands/start.js +253 -0
- package/dist/esm/bin/commands/start.js.map +1 -0
- package/dist/esm/bin/isolatedController.js +200 -0
- package/dist/esm/bin/isolatedController.js.map +1 -0
- package/dist/esm/bin/isolatedWorker.js +146 -0
- package/dist/esm/bin/isolatedWorker.js.map +1 -0
- package/dist/esm/bin/ponder.js +137 -0
- package/dist/esm/bin/ponder.js.map +1 -0
- package/dist/esm/bin/utils/codegen.js +25 -0
- package/dist/esm/bin/utils/codegen.js.map +1 -0
- package/dist/esm/bin/utils/exit.js +100 -0
- package/dist/esm/bin/utils/exit.js.map +1 -0
- package/dist/esm/build/config.js +745 -0
- package/dist/esm/build/config.js.map +1 -0
- package/dist/esm/build/factory.js +82 -0
- package/dist/esm/build/factory.js.map +1 -0
- package/dist/esm/build/index.js +567 -0
- package/dist/esm/build/index.js.map +1 -0
- package/dist/esm/build/plugin.js +53 -0
- package/dist/esm/build/plugin.js.map +1 -0
- package/dist/esm/build/pre.js +83 -0
- package/dist/esm/build/pre.js.map +1 -0
- package/dist/esm/build/schema.js +202 -0
- package/dist/esm/build/schema.js.map +1 -0
- package/dist/esm/build/stacktrace.js +137 -0
- package/dist/esm/build/stacktrace.js.map +1 -0
- package/dist/esm/client/index.js +441 -0
- package/dist/esm/client/index.js.map +1 -0
- package/dist/esm/config/address.js +2 -0
- package/dist/esm/config/address.js.map +1 -0
- package/dist/esm/config/eventFilter.js +2 -0
- package/dist/esm/config/eventFilter.js.map +1 -0
- package/dist/esm/config/index.js +2 -0
- package/dist/esm/config/index.js.map +1 -0
- package/dist/esm/config/utilityTypes.js +2 -0
- package/dist/esm/config/utilityTypes.js.map +1 -0
- package/dist/esm/database/actions.js +445 -0
- package/dist/esm/database/actions.js.map +1 -0
- package/dist/esm/database/index.js +604 -0
- package/dist/esm/database/index.js.map +1 -0
- package/dist/esm/database/queryBuilder.js +314 -0
- package/dist/esm/database/queryBuilder.js.map +1 -0
- package/dist/esm/drizzle/bigint.js +38 -0
- package/dist/esm/drizzle/bigint.js.map +1 -0
- package/dist/esm/drizzle/bytes.js +47 -0
- package/dist/esm/drizzle/bytes.js.map +1 -0
- package/dist/esm/drizzle/hex.js +40 -0
- package/dist/esm/drizzle/hex.js.map +1 -0
- package/dist/esm/drizzle/index.js +28 -0
- package/dist/esm/drizzle/index.js.map +1 -0
- package/dist/esm/drizzle/json.js +123 -0
- package/dist/esm/drizzle/json.js.map +1 -0
- package/dist/esm/drizzle/kit/index.js +927 -0
- package/dist/esm/drizzle/kit/index.js.map +1 -0
- package/dist/esm/drizzle/onchain.js +184 -0
- package/dist/esm/drizzle/onchain.js.map +1 -0
- package/dist/esm/drizzle/text.js +61 -0
- package/dist/esm/drizzle/text.js.map +1 -0
- package/dist/esm/graphql/graphiql.html.js +59 -0
- package/dist/esm/graphql/graphiql.html.js.map +1 -0
- package/dist/esm/graphql/index.js +934 -0
- package/dist/esm/graphql/index.js.map +1 -0
- package/dist/esm/graphql/json.js +42 -0
- package/dist/esm/graphql/json.js.map +1 -0
- package/dist/esm/graphql/middleware.js +83 -0
- package/dist/esm/graphql/middleware.js.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/indexing/addStackTrace.js +54 -0
- package/dist/esm/indexing/addStackTrace.js.map +1 -0
- package/dist/esm/indexing/client.js +675 -0
- package/dist/esm/indexing/client.js.map +1 -0
- package/dist/esm/indexing/index.js +663 -0
- package/dist/esm/indexing/index.js.map +1 -0
- package/dist/esm/indexing/profile.js +584 -0
- package/dist/esm/indexing/profile.js.map +1 -0
- package/dist/esm/indexing-store/cache.js +666 -0
- package/dist/esm/indexing-store/cache.js.map +1 -0
- package/dist/esm/indexing-store/index.js +461 -0
- package/dist/esm/indexing-store/index.js.map +1 -0
- package/dist/esm/indexing-store/profile.js +428 -0
- package/dist/esm/indexing-store/profile.js.map +1 -0
- package/dist/esm/indexing-store/utils.js +111 -0
- package/dist/esm/indexing-store/utils.js.map +1 -0
- package/dist/esm/internal/common.js +2 -0
- package/dist/esm/internal/common.js.map +1 -0
- package/dist/esm/internal/errors.js +300 -0
- package/dist/esm/internal/errors.js.map +1 -0
- package/dist/esm/internal/logger.js +178 -0
- package/dist/esm/internal/logger.js.map +1 -0
- package/dist/esm/internal/metrics.js +1049 -0
- package/dist/esm/internal/metrics.js.map +1 -0
- package/dist/esm/internal/options.js +73 -0
- package/dist/esm/internal/options.js.map +1 -0
- package/dist/esm/internal/shutdown.js +24 -0
- package/dist/esm/internal/shutdown.js.map +1 -0
- package/dist/esm/internal/telemetry.js +200 -0
- package/dist/esm/internal/telemetry.js.map +1 -0
- package/dist/esm/internal/types.js +2 -0
- package/dist/esm/internal/types.js.map +1 -0
- package/dist/esm/rpc/actions.js +988 -0
- package/dist/esm/rpc/actions.js.map +1 -0
- package/dist/esm/rpc/http.js +130 -0
- package/dist/esm/rpc/http.js.map +1 -0
- package/dist/esm/rpc/index.js +749 -0
- package/dist/esm/rpc/index.js.map +1 -0
- package/dist/esm/runtime/events.js +664 -0
- package/dist/esm/runtime/events.js.map +1 -0
- package/dist/esm/runtime/filter.js +476 -0
- package/dist/esm/runtime/filter.js.map +1 -0
- package/dist/esm/runtime/fragments.js +478 -0
- package/dist/esm/runtime/fragments.js.map +1 -0
- package/dist/esm/runtime/historical.js +954 -0
- package/dist/esm/runtime/historical.js.map +1 -0
- package/dist/esm/runtime/index.js +316 -0
- package/dist/esm/runtime/index.js.map +1 -0
- package/dist/esm/runtime/init.js +12 -0
- package/dist/esm/runtime/init.js.map +1 -0
- package/dist/esm/runtime/isolated.js +464 -0
- package/dist/esm/runtime/isolated.js.map +1 -0
- package/dist/esm/runtime/multichain.js +511 -0
- package/dist/esm/runtime/multichain.js.map +1 -0
- package/dist/esm/runtime/omnichain.js +546 -0
- package/dist/esm/runtime/omnichain.js.map +1 -0
- package/dist/esm/runtime/realtime.js +722 -0
- package/dist/esm/runtime/realtime.js.map +1 -0
- package/dist/esm/server/error.js +56 -0
- package/dist/esm/server/error.js.map +1 -0
- package/dist/esm/server/index.js +121 -0
- package/dist/esm/server/index.js.map +1 -0
- package/dist/esm/sync-historical/index.js +703 -0
- package/dist/esm/sync-historical/index.js.map +1 -0
- package/dist/esm/sync-realtime/bloom.js +76 -0
- package/dist/esm/sync-realtime/bloom.js.map +1 -0
- package/dist/esm/sync-realtime/index.js +918 -0
- package/dist/esm/sync-realtime/index.js.map +1 -0
- package/dist/esm/sync-store/encode.js +105 -0
- package/dist/esm/sync-store/encode.js.map +1 -0
- package/dist/esm/sync-store/index.js +885 -0
- package/dist/esm/sync-store/index.js.map +1 -0
- package/dist/esm/sync-store/migrations.js +1595 -0
- package/dist/esm/sync-store/migrations.js.map +1 -0
- package/dist/esm/sync-store/schema.js +181 -0
- package/dist/esm/sync-store/schema.js.map +1 -0
- package/dist/esm/types/db.js +2 -0
- package/dist/esm/types/db.js.map +1 -0
- package/dist/esm/types/eth.js +2 -0
- package/dist/esm/types/eth.js.map +1 -0
- package/dist/esm/types/utils.js +2 -0
- package/dist/esm/types/utils.js.map +1 -0
- package/dist/esm/types/virtual.js +2 -0
- package/dist/esm/types/virtual.js.map +1 -0
- package/dist/esm/ui/app.js +157 -0
- package/dist/esm/ui/app.js.map +1 -0
- package/dist/esm/ui/index.js +29 -0
- package/dist/esm/ui/index.js.map +1 -0
- package/dist/esm/ui/patch.js +140 -0
- package/dist/esm/ui/patch.js.map +1 -0
- package/dist/esm/utils/abi.js +55 -0
- package/dist/esm/utils/abi.js.map +1 -0
- package/dist/esm/utils/bigint.js +37 -0
- package/dist/esm/utils/bigint.js.map +1 -0
- package/dist/esm/utils/chains.js +21 -0
- package/dist/esm/utils/chains.js.map +1 -0
- package/dist/esm/utils/checkpoint.js +139 -0
- package/dist/esm/utils/checkpoint.js.map +1 -0
- package/dist/esm/utils/chunk.js +8 -0
- package/dist/esm/utils/chunk.js.map +1 -0
- package/dist/esm/utils/copy.js +129 -0
- package/dist/esm/utils/copy.js.map +1 -0
- package/dist/esm/utils/date.js +27 -0
- package/dist/esm/utils/date.js.map +1 -0
- package/dist/esm/utils/debug.js +2 -0
- package/dist/esm/utils/debug.js.map +1 -0
- package/dist/esm/utils/decodeAbiParameters.js +290 -0
- package/dist/esm/utils/decodeAbiParameters.js.map +1 -0
- package/dist/esm/utils/decodeEventLog.js +75 -0
- package/dist/esm/utils/decodeEventLog.js.map +1 -0
- package/dist/esm/utils/dedupe.js +29 -0
- package/dist/esm/utils/dedupe.js.map +1 -0
- package/dist/esm/utils/duplicates.js +19 -0
- package/dist/esm/utils/duplicates.js.map +1 -0
- package/dist/esm/utils/estimate.js +6 -0
- package/dist/esm/utils/estimate.js.map +1 -0
- package/dist/esm/utils/finality.js +38 -0
- package/dist/esm/utils/finality.js.map +1 -0
- package/dist/esm/utils/format.js +20 -0
- package/dist/esm/utils/format.js.map +1 -0
- package/dist/esm/utils/generators.js +121 -0
- package/dist/esm/utils/generators.js.map +1 -0
- package/dist/esm/utils/hash.js +11 -0
- package/dist/esm/utils/hash.js.map +1 -0
- package/dist/esm/utils/interval.js +171 -0
- package/dist/esm/utils/interval.js.map +1 -0
- package/dist/esm/utils/lowercase.js +7 -0
- package/dist/esm/utils/lowercase.js.map +1 -0
- package/dist/esm/utils/mutex.js +26 -0
- package/dist/esm/utils/mutex.js.map +1 -0
- package/dist/esm/utils/never.js +4 -0
- package/dist/esm/utils/never.js.map +1 -0
- package/dist/esm/utils/offset.js +101 -0
- package/dist/esm/utils/offset.js.map +1 -0
- package/dist/esm/utils/order.js +18 -0
- package/dist/esm/utils/order.js.map +1 -0
- package/dist/esm/utils/partition.js +46 -0
- package/dist/esm/utils/partition.js.map +1 -0
- package/dist/esm/utils/pg.js +175 -0
- package/dist/esm/utils/pg.js.map +1 -0
- package/dist/esm/utils/pglite.js +80 -0
- package/dist/esm/utils/pglite.js.map +1 -0
- package/dist/esm/utils/port.js +30 -0
- package/dist/esm/utils/port.js.map +1 -0
- package/dist/esm/utils/print.js +23 -0
- package/dist/esm/utils/print.js.map +1 -0
- package/dist/esm/utils/promiseAllSettledWithThrow.js +19 -0
- package/dist/esm/utils/promiseAllSettledWithThrow.js.map +1 -0
- package/dist/esm/utils/promiseWithResolvers.js +13 -0
- package/dist/esm/utils/promiseWithResolvers.js.map +1 -0
- package/dist/esm/utils/queue.js +150 -0
- package/dist/esm/utils/queue.js.map +1 -0
- package/dist/esm/utils/range.js +8 -0
- package/dist/esm/utils/range.js.map +1 -0
- package/dist/esm/utils/result.js +10 -0
- package/dist/esm/utils/result.js.map +1 -0
- package/dist/esm/utils/sql-parse.js +1326 -0
- package/dist/esm/utils/sql-parse.js.map +1 -0
- package/dist/esm/utils/timer.js +9 -0
- package/dist/esm/utils/timer.js.map +1 -0
- package/dist/esm/utils/truncate.js +15 -0
- package/dist/esm/utils/truncate.js.map +1 -0
- package/dist/esm/utils/wait.js +10 -0
- package/dist/esm/utils/wait.js.map +1 -0
- package/dist/esm/utils/zipper.js +67 -0
- package/dist/esm/utils/zipper.js.map +1 -0
- package/dist/types/bin/commands/codegen.d.ts +5 -0
- package/dist/types/bin/commands/codegen.d.ts.map +1 -0
- package/dist/types/bin/commands/createViews.d.ts +8 -0
- package/dist/types/bin/commands/createViews.d.ts.map +1 -0
- package/dist/types/bin/commands/dev.d.ts +5 -0
- package/dist/types/bin/commands/dev.d.ts.map +1 -0
- package/dist/types/bin/commands/list.d.ts +5 -0
- package/dist/types/bin/commands/list.d.ts.map +1 -0
- package/dist/types/bin/commands/prune.d.ts +5 -0
- package/dist/types/bin/commands/prune.d.ts.map +1 -0
- package/dist/types/bin/commands/serve.d.ts +5 -0
- package/dist/types/bin/commands/serve.d.ts.map +1 -0
- package/dist/types/bin/commands/start.d.ts +19 -0
- package/dist/types/bin/commands/start.d.ts.map +1 -0
- package/dist/types/bin/isolatedController.d.ts +13 -0
- package/dist/types/bin/isolatedController.d.ts.map +1 -0
- package/dist/types/bin/isolatedWorker.d.ts +9 -0
- package/dist/types/bin/isolatedWorker.d.ts.map +1 -0
- package/dist/types/bin/ponder.d.ts +37 -0
- package/dist/types/bin/ponder.d.ts.map +1 -0
- package/dist/types/bin/utils/codegen.d.ts +6 -0
- package/dist/types/bin/utils/codegen.d.ts.map +1 -0
- package/dist/types/bin/utils/exit.d.ts +10 -0
- package/dist/types/bin/utils/exit.d.ts.map +1 -0
- package/dist/types/build/config.d.ts +97 -0
- package/dist/types/build/config.d.ts.map +1 -0
- package/dist/types/build/factory.d.ts +15 -0
- package/dist/types/build/factory.d.ts.map +1 -0
- package/dist/types/build/index.d.ts +84 -0
- package/dist/types/build/index.d.ts.map +1 -0
- package/dist/types/build/plugin.d.ts +4 -0
- package/dist/types/build/plugin.d.ts.map +1 -0
- package/dist/types/build/pre.d.ts +29 -0
- package/dist/types/build/pre.d.ts.map +1 -0
- package/dist/types/build/schema.d.ts +20 -0
- package/dist/types/build/schema.d.ts.map +1 -0
- package/dist/types/build/stacktrace.d.ts +13 -0
- package/dist/types/build/stacktrace.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +27 -0
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/config/address.d.ts +34 -0
- package/dist/types/config/address.d.ts.map +1 -0
- package/dist/types/config/eventFilter.d.ts +18 -0
- package/dist/types/config/eventFilter.d.ts.map +1 -0
- package/dist/types/config/index.d.ts +144 -0
- package/dist/types/config/index.d.ts.map +1 -0
- package/dist/types/config/utilityTypes.d.ts +43 -0
- package/dist/types/config/utilityTypes.d.ts.map +1 -0
- package/dist/types/database/actions.d.ts +99 -0
- package/dist/types/database/actions.d.ts.map +1 -0
- package/dist/types/database/index.d.ts +493 -0
- package/dist/types/database/index.d.ts.map +1 -0
- package/dist/types/database/queryBuilder.d.ts +65 -0
- package/dist/types/database/queryBuilder.d.ts.map +1 -0
- package/dist/types/drizzle/bigint.d.ts +25 -0
- package/dist/types/drizzle/bigint.d.ts.map +1 -0
- package/dist/types/drizzle/bytes.d.ts +31 -0
- package/dist/types/drizzle/bytes.d.ts.map +1 -0
- package/dist/types/drizzle/hex.d.ts +25 -0
- package/dist/types/drizzle/hex.d.ts.map +1 -0
- package/dist/types/drizzle/index.d.ts +6 -0
- package/dist/types/drizzle/index.d.ts.map +1 -0
- package/dist/types/drizzle/json.d.ts +51 -0
- package/dist/types/drizzle/json.d.ts.map +1 -0
- package/dist/types/drizzle/kit/index.d.ts +187 -0
- package/dist/types/drizzle/kit/index.d.ts.map +1 -0
- package/dist/types/drizzle/onchain.d.ts +298 -0
- package/dist/types/drizzle/onchain.d.ts.map +1 -0
- package/dist/types/drizzle/text.d.ts +29 -0
- package/dist/types/drizzle/text.d.ts.map +1 -0
- package/dist/types/graphql/graphiql.html.d.ts +2 -0
- package/dist/types/graphql/graphiql.html.d.ts.map +1 -0
- package/dist/types/graphql/index.d.ts +12 -0
- package/dist/types/graphql/index.d.ts.map +1 -0
- package/dist/types/graphql/json.d.ts +3 -0
- package/dist/types/graphql/json.d.ts.map +1 -0
- package/dist/types/graphql/middleware.d.ts +29 -0
- package/dist/types/graphql/middleware.d.ts.map +1 -0
- package/dist/types/index.d.ts +23 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/indexing/addStackTrace.d.ts +3 -0
- package/dist/types/indexing/addStackTrace.d.ts.map +1 -0
- package/dist/types/indexing/client.d.ts +154 -0
- package/dist/types/indexing/client.d.ts.map +1 -0
- package/dist/types/indexing/index.d.ts +72 -0
- package/dist/types/indexing/index.d.ts.map +1 -0
- package/dist/types/indexing/profile.d.ts +16 -0
- package/dist/types/indexing/profile.d.ts.map +1 -0
- package/dist/types/indexing-store/cache.d.ts +115 -0
- package/dist/types/indexing-store/cache.d.ts.map +1 -0
- package/dist/types/indexing-store/index.d.ts +24 -0
- package/dist/types/indexing-store/index.d.ts.map +1 -0
- package/dist/types/indexing-store/profile.d.ts +7 -0
- package/dist/types/indexing-store/profile.d.ts.map +1 -0
- package/dist/types/indexing-store/utils.d.ts +19 -0
- package/dist/types/indexing-store/utils.d.ts.map +1 -0
- package/dist/types/internal/common.d.ts +15 -0
- package/dist/types/internal/common.d.ts.map +1 -0
- package/dist/types/internal/errors.d.ts +101 -0
- package/dist/types/internal/errors.d.ts.map +1 -0
- package/dist/types/internal/logger.d.ts +37 -0
- package/dist/types/internal/logger.d.ts.map +1 -0
- package/dist/types/internal/metrics.d.ts +120 -0
- package/dist/types/internal/metrics.d.ts.map +1 -0
- package/dist/types/internal/options.d.ts +62 -0
- package/dist/types/internal/options.d.ts.map +1 -0
- package/dist/types/internal/shutdown.d.ts +8 -0
- package/dist/types/internal/shutdown.d.ts.map +1 -0
- package/dist/types/internal/telemetry.d.ts +43 -0
- package/dist/types/internal/telemetry.d.ts.map +1 -0
- package/dist/types/internal/types.d.ts +443 -0
- package/dist/types/internal/types.d.ts.map +1 -0
- package/dist/types/rpc/actions.d.ts +360 -0
- package/dist/types/rpc/actions.d.ts.map +1 -0
- package/dist/types/rpc/http.d.ts +17 -0
- package/dist/types/rpc/http.d.ts.map +1 -0
- package/dist/types/rpc/index.d.ts +43 -0
- package/dist/types/rpc/index.d.ts.map +1 -0
- package/dist/types/runtime/events.d.ts +40 -0
- package/dist/types/runtime/events.d.ts.map +1 -0
- package/dist/types/runtime/filter.d.ts +96 -0
- package/dist/types/runtime/filter.d.ts.map +1 -0
- package/dist/types/runtime/fragments.d.ts +30 -0
- package/dist/types/runtime/fragments.d.ts.map +1 -0
- package/dist/types/runtime/historical.d.ts +123 -0
- package/dist/types/runtime/historical.d.ts.map +1 -0
- package/dist/types/runtime/index.d.ts +89 -0
- package/dist/types/runtime/index.d.ts.map +1 -0
- package/dist/types/runtime/init.d.ts +28 -0
- package/dist/types/runtime/init.d.ts.map +1 -0
- package/dist/types/runtime/isolated.d.ts +14 -0
- package/dist/types/runtime/isolated.d.ts.map +1 -0
- package/dist/types/runtime/multichain.d.ts +13 -0
- package/dist/types/runtime/multichain.d.ts.map +1 -0
- package/dist/types/runtime/omnichain.d.ts +23 -0
- package/dist/types/runtime/omnichain.d.ts.map +1 -0
- package/dist/types/runtime/realtime.d.ts +93 -0
- package/dist/types/runtime/realtime.d.ts.map +1 -0
- package/dist/types/server/error.d.ts +5 -0
- package/dist/types/server/error.d.ts.map +1 -0
- package/dist/types/server/index.d.ts +13 -0
- package/dist/types/server/index.d.ts.map +1 -0
- package/dist/types/sync-historical/index.d.ts +36 -0
- package/dist/types/sync-historical/index.d.ts.map +1 -0
- package/dist/types/sync-realtime/bloom.d.ts +18 -0
- package/dist/types/sync-realtime/bloom.d.ts.map +1 -0
- package/dist/types/sync-realtime/index.d.ts +48 -0
- package/dist/types/sync-realtime/index.d.ts.map +1 -0
- package/dist/types/sync-store/encode.d.ts +25 -0
- package/dist/types/sync-store/encode.d.ts.map +1 -0
- package/dist/types/sync-store/index.d.ts +135 -0
- package/dist/types/sync-store/index.d.ts.map +1 -0
- package/dist/types/sync-store/migrations.d.ts +8 -0
- package/dist/types/sync-store/migrations.d.ts.map +1 -0
- package/dist/types/sync-store/schema.d.ts +1828 -0
- package/dist/types/sync-store/schema.d.ts.map +1 -0
- package/dist/types/types/db.d.ts +213 -0
- package/dist/types/types/db.d.ts.map +1 -0
- package/dist/types/types/eth.d.ts +196 -0
- package/dist/types/types/eth.d.ts.map +1 -0
- package/dist/types/types/utils.d.ts +38 -0
- package/dist/types/types/utils.d.ts.map +1 -0
- package/dist/types/types/virtual.d.ts +99 -0
- package/dist/types/types/virtual.d.ts.map +1 -0
- package/dist/types/ui/app.d.ts +22 -0
- package/dist/types/ui/app.d.ts.map +1 -0
- package/dist/types/ui/index.d.ts +5 -0
- package/dist/types/ui/index.d.ts.map +1 -0
- package/dist/types/ui/patch.d.ts +7 -0
- package/dist/types/ui/patch.d.ts.map +1 -0
- package/dist/types/utils/abi.d.ts +23 -0
- package/dist/types/utils/abi.d.ts.map +1 -0
- package/dist/types/utils/bigint.d.ts +15 -0
- package/dist/types/utils/bigint.d.ts.map +1 -0
- package/dist/types/utils/chains.d.ts +42 -0
- package/dist/types/utils/chains.d.ts.map +1 -0
- package/dist/types/utils/checkpoint.d.ts +52 -0
- package/dist/types/utils/checkpoint.d.ts.map +1 -0
- package/dist/types/utils/chunk.d.ts +2 -0
- package/dist/types/utils/chunk.d.ts.map +1 -0
- package/dist/types/utils/copy.d.ts +16 -0
- package/dist/types/utils/copy.d.ts.map +1 -0
- package/dist/types/utils/date.d.ts +7 -0
- package/dist/types/utils/date.d.ts.map +1 -0
- package/dist/types/utils/debug.d.ts +105 -0
- package/dist/types/utils/debug.d.ts.map +1 -0
- package/dist/types/utils/decodeAbiParameters.d.ts +28 -0
- package/dist/types/utils/decodeAbiParameters.d.ts.map +1 -0
- package/dist/types/utils/decodeEventLog.d.ts +12 -0
- package/dist/types/utils/decodeEventLog.d.ts.map +1 -0
- package/dist/types/utils/dedupe.d.ts +20 -0
- package/dist/types/utils/dedupe.d.ts.map +1 -0
- package/dist/types/utils/duplicates.d.ts +7 -0
- package/dist/types/utils/duplicates.d.ts.map +1 -0
- package/dist/types/utils/estimate.d.ts +11 -0
- package/dist/types/utils/estimate.d.ts.map +1 -0
- package/dist/types/utils/finality.d.ts +12 -0
- package/dist/types/utils/finality.d.ts.map +1 -0
- package/dist/types/utils/format.d.ts +3 -0
- package/dist/types/utils/format.d.ts.map +1 -0
- package/dist/types/utils/generators.d.ts +42 -0
- package/dist/types/utils/generators.d.ts.map +1 -0
- package/dist/types/utils/hash.d.ts +11 -0
- package/dist/types/utils/hash.d.ts.map +1 -0
- package/dist/types/utils/interval.d.ts +53 -0
- package/dist/types/utils/interval.d.ts.map +1 -0
- package/dist/types/utils/lowercase.d.ts +5 -0
- package/dist/types/utils/lowercase.d.ts.map +1 -0
- package/dist/types/utils/mutex.d.ts +5 -0
- package/dist/types/utils/mutex.d.ts.map +1 -0
- package/dist/types/utils/never.d.ts +2 -0
- package/dist/types/utils/never.d.ts.map +1 -0
- package/dist/types/utils/offset.d.ts +8 -0
- package/dist/types/utils/offset.d.ts.map +1 -0
- package/dist/types/utils/order.d.ts +2 -0
- package/dist/types/utils/order.d.ts.map +1 -0
- package/dist/types/utils/partition.d.ts +22 -0
- package/dist/types/utils/partition.d.ts.map +1 -0
- package/dist/types/utils/pg.d.ts +8 -0
- package/dist/types/utils/pg.d.ts.map +1 -0
- package/dist/types/utils/pglite.d.ts +25 -0
- package/dist/types/utils/pglite.d.ts.map +1 -0
- package/dist/types/utils/port.d.ts +5 -0
- package/dist/types/utils/port.d.ts.map +1 -0
- package/dist/types/utils/print.d.ts +2 -0
- package/dist/types/utils/print.d.ts.map +1 -0
- package/dist/types/utils/promiseAllSettledWithThrow.d.ts +8 -0
- package/dist/types/utils/promiseAllSettledWithThrow.d.ts.map +1 -0
- package/dist/types/utils/promiseWithResolvers.d.ts +10 -0
- package/dist/types/utils/promiseWithResolvers.d.ts.map +1 -0
- package/dist/types/utils/queue.d.ts +33 -0
- package/dist/types/utils/queue.d.ts.map +1 -0
- package/dist/types/utils/range.d.ts +8 -0
- package/dist/types/utils/range.d.ts.map +1 -0
- package/dist/types/utils/result.d.ts +17 -0
- package/dist/types/utils/result.d.ts.map +1 -0
- package/dist/types/utils/sql-parse.d.ts +21 -0
- package/dist/types/utils/sql-parse.d.ts.map +1 -0
- package/dist/types/utils/timer.d.ts +6 -0
- package/dist/types/utils/timer.d.ts.map +1 -0
- package/dist/types/utils/truncate.d.ts +9 -0
- package/dist/types/utils/truncate.d.ts.map +1 -0
- package/dist/types/utils/wait.d.ts +6 -0
- package/dist/types/utils/wait.d.ts.map +1 -0
- package/dist/types/utils/zipper.d.ts +36 -0
- package/dist/types/utils/zipper.d.ts.map +1 -0
- package/package.json +114 -0
- package/src/bin/commands/codegen.ts +56 -0
- package/src/bin/commands/createViews.ts +318 -0
- package/src/bin/commands/dev.ts +490 -0
- package/src/bin/commands/list.ts +208 -0
- package/src/bin/commands/prune.ts +322 -0
- package/src/bin/commands/serve.ts +236 -0
- package/src/bin/commands/start.ts +319 -0
- package/src/bin/isolatedController.ts +300 -0
- package/src/bin/isolatedWorker.ts +192 -0
- package/src/bin/ponder.ts +208 -0
- package/src/bin/utils/codegen.ts +32 -0
- package/src/bin/utils/exit.ts +112 -0
- package/src/build/config.ts +1141 -0
- package/src/build/factory.ts +147 -0
- package/src/build/index.ts +790 -0
- package/src/build/plugin.ts +58 -0
- package/src/build/pre.ts +114 -0
- package/src/build/schema.ts +358 -0
- package/src/build/stacktrace.ts +137 -0
- package/src/client/index.ts +551 -0
- package/src/config/address.ts +45 -0
- package/src/config/eventFilter.ts +33 -0
- package/src/config/index.ts +240 -0
- package/src/config/utilityTypes.ts +152 -0
- package/src/database/actions.ts +873 -0
- package/src/database/index.ts +1029 -0
- package/src/database/queryBuilder.ts +537 -0
- package/src/drizzle/bigint.ts +57 -0
- package/src/drizzle/bytes.ts +68 -0
- package/src/drizzle/hex.ts +58 -0
- package/src/drizzle/index.ts +40 -0
- package/src/drizzle/json.ts +159 -0
- package/src/drizzle/kit/index.ts +1348 -0
- package/src/drizzle/onchain.ts +476 -0
- package/src/drizzle/text.ts +77 -0
- package/src/graphql/graphiql.html.ts +59 -0
- package/src/graphql/index.ts +1351 -0
- package/src/graphql/json.ts +62 -0
- package/src/graphql/middleware.ts +115 -0
- package/src/index.ts +139 -0
- package/src/indexing/addStackTrace.ts +69 -0
- package/src/indexing/client.ts +1184 -0
- package/src/indexing/index.ts +976 -0
- package/src/indexing/profile.ts +771 -0
- package/src/indexing-store/cache.ts +1057 -0
- package/src/indexing-store/index.ts +628 -0
- package/src/indexing-store/profile.ts +557 -0
- package/src/indexing-store/utils.ts +162 -0
- package/src/internal/common.ts +15 -0
- package/src/internal/errors.ts +228 -0
- package/src/internal/logger.ts +252 -0
- package/src/internal/metrics.ts +1030 -0
- package/src/internal/options.ts +130 -0
- package/src/internal/shutdown.ts +32 -0
- package/src/internal/telemetry.ts +303 -0
- package/src/internal/types.ts +611 -0
- package/src/rpc/actions.ts +1344 -0
- package/src/rpc/http.ts +164 -0
- package/src/rpc/index.ts +959 -0
- package/src/runtime/events.ts +875 -0
- package/src/runtime/filter.ts +705 -0
- package/src/runtime/fragments.ts +674 -0
- package/src/runtime/historical.ts +1522 -0
- package/src/runtime/index.ts +569 -0
- package/src/runtime/init.ts +49 -0
- package/src/runtime/isolated.ts +775 -0
- package/src/runtime/multichain.ts +860 -0
- package/src/runtime/omnichain.ts +920 -0
- package/src/runtime/realtime.ts +1164 -0
- package/src/server/error.ts +68 -0
- package/src/server/index.ts +173 -0
- package/src/sync-historical/index.ts +1065 -0
- package/src/sync-realtime/bloom.ts +102 -0
- package/src/sync-realtime/index.ts +1304 -0
- package/src/sync-store/encode.ts +153 -0
- package/src/sync-store/index.ts +1633 -0
- package/src/sync-store/migrations.ts +1801 -0
- package/src/sync-store/schema.ts +248 -0
- package/src/types/db.ts +292 -0
- package/src/types/eth.ts +216 -0
- package/src/types/utils.ts +47 -0
- package/src/types/virtual.ts +244 -0
- package/src/types.d.ts +38 -0
- package/src/ui/app.ts +207 -0
- package/src/ui/index.ts +37 -0
- package/src/ui/patch.ts +204 -0
- package/src/utils/abi.ts +103 -0
- package/src/utils/bigint.ts +41 -0
- package/src/utils/chains.ts +22 -0
- package/src/utils/checkpoint.ts +203 -0
- package/src/utils/chunk.ts +7 -0
- package/src/utils/copy.ts +151 -0
- package/src/utils/date.ts +26 -0
- package/src/utils/debug.ts +110 -0
- package/src/utils/decodeAbiParameters.ts +428 -0
- package/src/utils/decodeEventLog.ts +100 -0
- package/src/utils/dedupe.ts +32 -0
- package/src/utils/duplicates.ts +19 -0
- package/src/utils/estimate.ts +27 -0
- package/src/utils/finality.ts +40 -0
- package/src/utils/format.ts +22 -0
- package/src/utils/generators.ts +157 -0
- package/src/utils/hash.ts +22 -0
- package/src/utils/interval.ts +212 -0
- package/src/utils/lowercase.ts +6 -0
- package/src/utils/mutex.ts +33 -0
- package/src/utils/never.ts +3 -0
- package/src/utils/offset.ts +133 -0
- package/src/utils/order.ts +16 -0
- package/src/utils/partition.ts +53 -0
- package/src/utils/pg.ts +230 -0
- package/src/utils/pglite.ts +97 -0
- package/src/utils/port.ts +34 -0
- package/src/utils/print.ts +31 -0
- package/src/utils/promiseAllSettledWithThrow.ts +27 -0
- package/src/utils/promiseWithResolvers.ts +20 -0
- package/src/utils/queue.ts +258 -0
- package/src/utils/range.ts +8 -0
- package/src/utils/result.ts +26 -0
- package/src/utils/sql-parse.ts +1477 -0
- package/src/utils/timer.ts +8 -0
- package/src/utils/truncate.ts +15 -0
- package/src/utils/wait.ts +8 -0
- package/src/utils/zipper.ts +80 -0
|
@@ -0,0 +1,1184 @@
|
|
|
1
|
+
import type { Common } from "@/internal/common.js";
|
|
2
|
+
import type { Chain, IndexingBuild, SetupEvent } from "@/internal/types.js";
|
|
3
|
+
import type { Event } from "@/internal/types.js";
|
|
4
|
+
import type { RequestParameters, Rpc } from "@/rpc/index.js";
|
|
5
|
+
import type { SyncStore } from "@/sync-store/index.js";
|
|
6
|
+
import { dedupe } from "@/utils/dedupe.js";
|
|
7
|
+
import { toLowerCase } from "@/utils/lowercase.js";
|
|
8
|
+
import { orderObject } from "@/utils/order.js";
|
|
9
|
+
import { startClock } from "@/utils/timer.js";
|
|
10
|
+
import { wait } from "@/utils/wait.js";
|
|
11
|
+
import {
|
|
12
|
+
type Abi,
|
|
13
|
+
type Account,
|
|
14
|
+
BlockNotFoundError,
|
|
15
|
+
type Client,
|
|
16
|
+
type ContractFunctionArgs,
|
|
17
|
+
type ContractFunctionName,
|
|
18
|
+
type ContractFunctionParameters,
|
|
19
|
+
type GetBlockReturnType,
|
|
20
|
+
type GetTransactionConfirmationsParameters,
|
|
21
|
+
type GetTransactionConfirmationsReturnType,
|
|
22
|
+
type GetTransactionParameters,
|
|
23
|
+
type GetTransactionReceiptParameters,
|
|
24
|
+
type GetTransactionReceiptReturnType,
|
|
25
|
+
type GetTransactionReturnType,
|
|
26
|
+
type Hash,
|
|
27
|
+
type Hex,
|
|
28
|
+
type MulticallParameters,
|
|
29
|
+
type MulticallReturnType,
|
|
30
|
+
type Prettify,
|
|
31
|
+
type PublicActions,
|
|
32
|
+
type PublicRpcSchema,
|
|
33
|
+
type ReadContractParameters,
|
|
34
|
+
type ReadContractReturnType,
|
|
35
|
+
type SimulateContractParameters,
|
|
36
|
+
type SimulateContractReturnType,
|
|
37
|
+
TransactionNotFoundError,
|
|
38
|
+
TransactionReceiptNotFoundError,
|
|
39
|
+
type Transport,
|
|
40
|
+
type Chain as ViemChain,
|
|
41
|
+
createClient,
|
|
42
|
+
custom,
|
|
43
|
+
decodeFunctionData,
|
|
44
|
+
decodeFunctionResult,
|
|
45
|
+
encodeFunctionData,
|
|
46
|
+
encodeFunctionResult,
|
|
47
|
+
getAbiItem,
|
|
48
|
+
hexToNumber,
|
|
49
|
+
multicall3Abi,
|
|
50
|
+
publicActions,
|
|
51
|
+
toFunctionSelector,
|
|
52
|
+
toHex,
|
|
53
|
+
} from "viem";
|
|
54
|
+
import {
|
|
55
|
+
getProfilePatternKey,
|
|
56
|
+
recordProfilePattern,
|
|
57
|
+
recoverProfilePattern,
|
|
58
|
+
} from "./profile.js";
|
|
59
|
+
|
|
60
|
+
export type CachedViemClient = {
|
|
61
|
+
getClient: (chain: Chain) => ReadonlyClient;
|
|
62
|
+
prefetch: (params: {
|
|
63
|
+
events: Event[];
|
|
64
|
+
}) => Promise<void>;
|
|
65
|
+
clear: () => void;
|
|
66
|
+
event: Event | SetupEvent | undefined;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const MULTICALL_SELECTOR = toFunctionSelector(
|
|
70
|
+
getAbiItem({ abi: multicall3Abi, name: "aggregate3" }),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const SAMPLING_RATE = 10;
|
|
74
|
+
const DB_PREDICTION_THRESHOLD = 0.2;
|
|
75
|
+
const RPC_PREDICTION_THRESHOLD = 0.8;
|
|
76
|
+
const MAX_CONSTANT_PATTERN_COUNT = 10;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* RPC responses that are not cached. These are valid responses
|
|
80
|
+
* that are sometimes erroneously returned by the RPC.
|
|
81
|
+
*
|
|
82
|
+
* `"0x"` is returned by `eth_call` and causes the `ContractFunctionZeroDataError`.
|
|
83
|
+
* `null` is returned by `eth_getBlockByNumber` and `eth_getBlockByHash` and causes the `BlockNotFoundError`.
|
|
84
|
+
*/
|
|
85
|
+
const UNCACHED_RESPONSES = ["0x", null] as any[];
|
|
86
|
+
|
|
87
|
+
/** RPC methods that reference a block number. */
|
|
88
|
+
const blockDependentMethods = new Set([
|
|
89
|
+
"eth_getBalance",
|
|
90
|
+
"eth_getTransactionCount",
|
|
91
|
+
"eth_getBlockByNumber",
|
|
92
|
+
"eth_getBlockTransactionCountByNumber",
|
|
93
|
+
"eth_getTransactionByBlockNumberAndIndex",
|
|
94
|
+
"eth_call",
|
|
95
|
+
"eth_estimateGas",
|
|
96
|
+
"eth_feeHistory",
|
|
97
|
+
"eth_getProof",
|
|
98
|
+
"eth_getCode",
|
|
99
|
+
"eth_getStorageAt",
|
|
100
|
+
"eth_getUncleByBlockNumberAndIndex",
|
|
101
|
+
"debug_traceBlockByNumber",
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
/** RPC methods that don't reference a block number. */
|
|
105
|
+
const nonBlockDependentMethods = new Set([
|
|
106
|
+
"eth_getBlockByHash",
|
|
107
|
+
"eth_getTransactionByHash",
|
|
108
|
+
"eth_getBlockTransactionCountByHash",
|
|
109
|
+
"eth_getTransactionByBlockHashAndIndex",
|
|
110
|
+
"eth_getTransactionConfirmations",
|
|
111
|
+
"eth_getTransactionReceipt",
|
|
112
|
+
"eth_getUncleByBlockHashAndIndex",
|
|
113
|
+
"eth_getUncleCountByBlockHash",
|
|
114
|
+
"debug_traceBlockByHash",
|
|
115
|
+
"debug_traceTransaction",
|
|
116
|
+
"debug_traceCall",
|
|
117
|
+
]);
|
|
118
|
+
|
|
119
|
+
/** Viem actions where the `block` property is optional and implicit. */
|
|
120
|
+
const blockDependentActions = [
|
|
121
|
+
"getBalance",
|
|
122
|
+
"call",
|
|
123
|
+
"estimateGas",
|
|
124
|
+
"getFeeHistory",
|
|
125
|
+
"getProof",
|
|
126
|
+
"getCode",
|
|
127
|
+
"getStorageAt",
|
|
128
|
+
"getEnsAddress",
|
|
129
|
+
"getEnsAvatar",
|
|
130
|
+
"getEnsName",
|
|
131
|
+
"getEnsResolver",
|
|
132
|
+
"getEnsText",
|
|
133
|
+
"readContract",
|
|
134
|
+
"multicall",
|
|
135
|
+
"simulateContract",
|
|
136
|
+
] as const satisfies readonly (keyof ReturnType<typeof publicActions>)[];
|
|
137
|
+
|
|
138
|
+
/** Viem actions where the `block` property is required. */
|
|
139
|
+
const blockRequiredActions = [
|
|
140
|
+
"getBlock",
|
|
141
|
+
"getTransactionCount",
|
|
142
|
+
"getBlockTransactionCount",
|
|
143
|
+
] as const satisfies readonly (keyof ReturnType<typeof publicActions>)[];
|
|
144
|
+
|
|
145
|
+
/** Viem actions where the `block` property is non-existent. */
|
|
146
|
+
const nonBlockDependentActions = [
|
|
147
|
+
"getTransaction",
|
|
148
|
+
"getTransactionReceipt",
|
|
149
|
+
"getTransactionConfirmations",
|
|
150
|
+
] as const satisfies readonly (keyof ReturnType<typeof publicActions>)[];
|
|
151
|
+
|
|
152
|
+
/** Viem actions that should be retried if they fail. */
|
|
153
|
+
const retryableActions = [
|
|
154
|
+
"readContract",
|
|
155
|
+
"simulateContract",
|
|
156
|
+
"multicall",
|
|
157
|
+
"getBlock",
|
|
158
|
+
"getTransaction",
|
|
159
|
+
"getTransactionReceipt",
|
|
160
|
+
"getTransactionConfirmations",
|
|
161
|
+
] as const satisfies readonly (keyof ReturnType<typeof publicActions>)[];
|
|
162
|
+
|
|
163
|
+
type BlockOptions =
|
|
164
|
+
| {
|
|
165
|
+
cache?: undefined;
|
|
166
|
+
blockNumber?: undefined;
|
|
167
|
+
}
|
|
168
|
+
| {
|
|
169
|
+
cache: "immutable";
|
|
170
|
+
blockNumber?: undefined;
|
|
171
|
+
}
|
|
172
|
+
| {
|
|
173
|
+
cache?: undefined;
|
|
174
|
+
blockNumber: bigint;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
type RequiredBlockOptions =
|
|
178
|
+
| {
|
|
179
|
+
/** Hash of the block. */
|
|
180
|
+
blockHash: Hash;
|
|
181
|
+
blockNumber?: undefined;
|
|
182
|
+
}
|
|
183
|
+
| {
|
|
184
|
+
blockHash?: undefined;
|
|
185
|
+
/** The block number. */
|
|
186
|
+
blockNumber: bigint;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
type RetryableOptions = {
|
|
190
|
+
/**
|
|
191
|
+
* Whether or not to retry the action if the response is empty.
|
|
192
|
+
*
|
|
193
|
+
* @default true
|
|
194
|
+
*/
|
|
195
|
+
retryEmptyResponse?: boolean;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
type BlockDependentAction<
|
|
199
|
+
fn extends (client: any, args: any) => unknown,
|
|
200
|
+
///
|
|
201
|
+
params = Parameters<fn>[0],
|
|
202
|
+
returnType = ReturnType<fn>,
|
|
203
|
+
> = (
|
|
204
|
+
args: Omit<params, "blockTag" | "blockNumber"> & BlockOptions,
|
|
205
|
+
) => returnType;
|
|
206
|
+
|
|
207
|
+
export type PonderActions = Omit<
|
|
208
|
+
{
|
|
209
|
+
[action in (typeof blockDependentActions)[number]]: BlockDependentAction<
|
|
210
|
+
ReturnType<typeof publicActions>[action]
|
|
211
|
+
>;
|
|
212
|
+
} & Pick<PublicActions, (typeof nonBlockDependentActions)[number]> &
|
|
213
|
+
Pick<PublicActions, (typeof blockRequiredActions)[number]>,
|
|
214
|
+
(typeof retryableActions)[number]
|
|
215
|
+
> & {
|
|
216
|
+
// Types for `retryableActions` are manually defined.
|
|
217
|
+
readContract: <
|
|
218
|
+
const abi extends Abi | readonly unknown[],
|
|
219
|
+
functionName extends ContractFunctionName<abi, "pure" | "view">,
|
|
220
|
+
const args extends ContractFunctionArgs<abi, "pure" | "view", functionName>,
|
|
221
|
+
>(
|
|
222
|
+
args: Omit<
|
|
223
|
+
ReadContractParameters<abi, functionName, args>,
|
|
224
|
+
"blockTag" | "blockNumber"
|
|
225
|
+
> &
|
|
226
|
+
BlockOptions &
|
|
227
|
+
RetryableOptions,
|
|
228
|
+
) => Promise<ReadContractReturnType<abi, functionName, args>>;
|
|
229
|
+
simulateContract: <
|
|
230
|
+
const abi extends Abi | readonly unknown[],
|
|
231
|
+
functionName extends ContractFunctionName<abi, "nonpayable" | "payable">,
|
|
232
|
+
const args extends ContractFunctionArgs<
|
|
233
|
+
abi,
|
|
234
|
+
"nonpayable" | "payable",
|
|
235
|
+
functionName
|
|
236
|
+
>,
|
|
237
|
+
>(
|
|
238
|
+
args: Omit<
|
|
239
|
+
SimulateContractParameters<abi, functionName, args>,
|
|
240
|
+
"blockTag" | "blockNumber"
|
|
241
|
+
> &
|
|
242
|
+
BlockOptions &
|
|
243
|
+
RetryableOptions,
|
|
244
|
+
) => Promise<SimulateContractReturnType<abi, functionName, args>>;
|
|
245
|
+
multicall: <
|
|
246
|
+
const contracts extends readonly unknown[],
|
|
247
|
+
allowFailure extends boolean = true,
|
|
248
|
+
>(
|
|
249
|
+
args: Omit<
|
|
250
|
+
MulticallParameters<contracts, allowFailure>,
|
|
251
|
+
"blockTag" | "blockNumber"
|
|
252
|
+
> &
|
|
253
|
+
BlockOptions &
|
|
254
|
+
RetryableOptions,
|
|
255
|
+
) => Promise<MulticallReturnType<contracts, allowFailure>>;
|
|
256
|
+
getBlock: <includeTransactions extends boolean = false>(
|
|
257
|
+
args: {
|
|
258
|
+
/** Whether or not to include transaction data in the response. */
|
|
259
|
+
includeTransactions?: includeTransactions | undefined;
|
|
260
|
+
} & RequiredBlockOptions &
|
|
261
|
+
RetryableOptions,
|
|
262
|
+
) => Promise<GetBlockReturnType<ViemChain | undefined, includeTransactions>>;
|
|
263
|
+
getTransaction: (
|
|
264
|
+
args: GetTransactionParameters & RetryableOptions,
|
|
265
|
+
) => Promise<GetTransactionReturnType>;
|
|
266
|
+
getTransactionReceipt: (
|
|
267
|
+
args: GetTransactionReceiptParameters & RetryableOptions,
|
|
268
|
+
) => Promise<GetTransactionReceiptReturnType>;
|
|
269
|
+
getTransactionConfirmations: (
|
|
270
|
+
args: GetTransactionConfirmationsParameters & RetryableOptions,
|
|
271
|
+
) => Promise<GetTransactionConfirmationsReturnType>;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
export type ReadonlyClient<
|
|
275
|
+
transport extends Transport = Transport,
|
|
276
|
+
chain extends ViemChain | undefined = ViemChain | undefined,
|
|
277
|
+
> = Prettify<
|
|
278
|
+
Omit<
|
|
279
|
+
Client<transport, chain, undefined, PublicRpcSchema, PonderActions>,
|
|
280
|
+
| "extend"
|
|
281
|
+
| "key"
|
|
282
|
+
| "batch"
|
|
283
|
+
| "cacheTime"
|
|
284
|
+
| "account"
|
|
285
|
+
| "type"
|
|
286
|
+
| "uid"
|
|
287
|
+
| "chain"
|
|
288
|
+
| "name"
|
|
289
|
+
| "pollingInterval"
|
|
290
|
+
| "transport"
|
|
291
|
+
| "ccipRead"
|
|
292
|
+
>
|
|
293
|
+
>;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* RPC request.
|
|
297
|
+
*/
|
|
298
|
+
export type Request = Pick<
|
|
299
|
+
ReadContractParameters,
|
|
300
|
+
"abi" | "address" | "functionName" | "args"
|
|
301
|
+
> & { blockNumber: bigint | "latest"; chainId: number };
|
|
302
|
+
/**
|
|
303
|
+
* Serialized RPC request for uniquely identifying a request.
|
|
304
|
+
*
|
|
305
|
+
* @dev Encoded from {@link Request} using `abi`.
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* "{
|
|
309
|
+
* "method": "eth_call",
|
|
310
|
+
* "params": [{"data": "0x123", "to": "0x456"}, "0x789"]
|
|
311
|
+
* }"
|
|
312
|
+
*/
|
|
313
|
+
type CacheKey = string;
|
|
314
|
+
/**
|
|
315
|
+
* Response of an RPC request.
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* "0x123"
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ""0x123456789""
|
|
322
|
+
*/
|
|
323
|
+
type Response = string;
|
|
324
|
+
/**
|
|
325
|
+
* Recorded RPC request pattern.
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* {
|
|
329
|
+
* "address": ["args", "from"],
|
|
330
|
+
* "abi": [...],
|
|
331
|
+
* "functionName": "balanceOf",
|
|
332
|
+
* "args": ["log", "address"],
|
|
333
|
+
* }
|
|
334
|
+
*/
|
|
335
|
+
export type ProfilePattern = Pick<
|
|
336
|
+
ReadContractParameters,
|
|
337
|
+
"abi" | "functionName"
|
|
338
|
+
> & {
|
|
339
|
+
address:
|
|
340
|
+
| { type: "constant"; value: unknown }
|
|
341
|
+
| { type: "derived"; value: string[] };
|
|
342
|
+
args?: (
|
|
343
|
+
| { type: "constant"; value: unknown }
|
|
344
|
+
| { type: "derived"; value: string[] }
|
|
345
|
+
)[];
|
|
346
|
+
cache?: "immutable";
|
|
347
|
+
};
|
|
348
|
+
/**
|
|
349
|
+
* Serialized {@link ProfilePattern} for unique identification.
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* "{
|
|
353
|
+
* "address": ["args", "from"],
|
|
354
|
+
* "args": ["log", "address"],
|
|
355
|
+
* "functionName": "balanceOf",
|
|
356
|
+
* }"
|
|
357
|
+
*/
|
|
358
|
+
type ProfileKey = string;
|
|
359
|
+
/**
|
|
360
|
+
* Event name.
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* "Erc20:Transfer"
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* "Erc20.mint()"
|
|
367
|
+
*/
|
|
368
|
+
type EventName = string;
|
|
369
|
+
/**
|
|
370
|
+
* Metadata about RPC request patterns for each event.
|
|
371
|
+
*
|
|
372
|
+
* @dev Only profile "eth_call" requests.
|
|
373
|
+
*/
|
|
374
|
+
type Profile = Map<
|
|
375
|
+
EventName,
|
|
376
|
+
Map<
|
|
377
|
+
ProfileKey,
|
|
378
|
+
{ pattern: ProfilePattern; hasConstant: boolean; count: number }
|
|
379
|
+
>
|
|
380
|
+
>;
|
|
381
|
+
/**
|
|
382
|
+
* LRU cache of {@link ProfilePattern} in {@link Profile} with constant args.
|
|
383
|
+
*
|
|
384
|
+
* @dev Used to determine which {@link ProfilePattern} should be evicted.
|
|
385
|
+
*/
|
|
386
|
+
type ProfileConstantLRU = Map<EventName, Set<ProfileKey>>;
|
|
387
|
+
/**
|
|
388
|
+
* Cache of RPC responses.
|
|
389
|
+
*/
|
|
390
|
+
type Cache = Map<number, Map<CacheKey, Promise<Response | Error> | Response>>;
|
|
391
|
+
|
|
392
|
+
export const getCacheKey = (request: RequestParameters) => {
|
|
393
|
+
return toLowerCase(JSON.stringify(orderObject(request)));
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
export const encodeRequest = (request: Request) =>
|
|
397
|
+
({
|
|
398
|
+
method: "eth_call",
|
|
399
|
+
params: [
|
|
400
|
+
{
|
|
401
|
+
to: request.address,
|
|
402
|
+
data: encodeFunctionData({
|
|
403
|
+
abi: request.abi,
|
|
404
|
+
functionName: request.functionName,
|
|
405
|
+
args: request.args,
|
|
406
|
+
}),
|
|
407
|
+
},
|
|
408
|
+
request.blockNumber === "latest" ? "latest" : toHex(request.blockNumber),
|
|
409
|
+
],
|
|
410
|
+
}) satisfies RequestParameters;
|
|
411
|
+
|
|
412
|
+
export const decodeResponse = (response: Response) => {
|
|
413
|
+
// Note: I don't actually remember why we had to add the try catch.
|
|
414
|
+
try {
|
|
415
|
+
return JSON.parse(response);
|
|
416
|
+
} catch (error) {
|
|
417
|
+
return response;
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
export const createCachedViemClient = ({
|
|
422
|
+
common,
|
|
423
|
+
indexingBuild,
|
|
424
|
+
syncStore,
|
|
425
|
+
eventCount,
|
|
426
|
+
}: {
|
|
427
|
+
common: Common;
|
|
428
|
+
indexingBuild: Pick<IndexingBuild, "chains" | "rpcs">;
|
|
429
|
+
syncStore: SyncStore;
|
|
430
|
+
eventCount: { [eventName: string]: number };
|
|
431
|
+
}): CachedViemClient => {
|
|
432
|
+
let event: Event | SetupEvent = undefined!;
|
|
433
|
+
const cache: Cache = new Map();
|
|
434
|
+
const profile: Profile = new Map();
|
|
435
|
+
const profileConstantLRU: ProfileConstantLRU = new Map();
|
|
436
|
+
|
|
437
|
+
for (const chain of indexingBuild.chains) {
|
|
438
|
+
cache.set(chain.id, new Map());
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const ponderActions = <
|
|
442
|
+
TTransport extends Transport = Transport,
|
|
443
|
+
TChain extends ViemChain | undefined = ViemChain | undefined,
|
|
444
|
+
TAccount extends Account | undefined = Account | undefined,
|
|
445
|
+
>(
|
|
446
|
+
client: Client<TTransport, TChain, TAccount>,
|
|
447
|
+
): PonderActions => {
|
|
448
|
+
const actions = {} as PonderActions;
|
|
449
|
+
const _publicActions = publicActions(client);
|
|
450
|
+
|
|
451
|
+
const addProfilePattern = ({
|
|
452
|
+
pattern,
|
|
453
|
+
hasConstant,
|
|
454
|
+
}: { pattern: ProfilePattern; hasConstant: boolean }) => {
|
|
455
|
+
const profilePatternKey = getProfilePatternKey(pattern);
|
|
456
|
+
const eventName = (event as Event).eventCallback.name;
|
|
457
|
+
|
|
458
|
+
if (profile.get(eventName)!.has(profilePatternKey)) {
|
|
459
|
+
profile.get(eventName)!.get(profilePatternKey)!.count++;
|
|
460
|
+
|
|
461
|
+
if (hasConstant) {
|
|
462
|
+
profileConstantLRU.get(eventName)!.delete(profilePatternKey);
|
|
463
|
+
profileConstantLRU.get(eventName)!.add(profilePatternKey);
|
|
464
|
+
}
|
|
465
|
+
} else {
|
|
466
|
+
profile
|
|
467
|
+
.get(eventName)!
|
|
468
|
+
.set(profilePatternKey, { pattern, hasConstant, count: 1 });
|
|
469
|
+
|
|
470
|
+
if (hasConstant) {
|
|
471
|
+
profileConstantLRU.get(eventName)!.add(profilePatternKey);
|
|
472
|
+
if (
|
|
473
|
+
profileConstantLRU.get(eventName)!.size > MAX_CONSTANT_PATTERN_COUNT
|
|
474
|
+
) {
|
|
475
|
+
const firstKey = profileConstantLRU
|
|
476
|
+
.get(eventName)!
|
|
477
|
+
.keys()
|
|
478
|
+
.next().value;
|
|
479
|
+
if (firstKey) {
|
|
480
|
+
profile.get(eventName)!.delete(firstKey);
|
|
481
|
+
profileConstantLRU.get(eventName)!.delete(firstKey);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
const getPonderAction = <
|
|
489
|
+
action extends (typeof blockDependentActions)[number],
|
|
490
|
+
>(
|
|
491
|
+
action: action,
|
|
492
|
+
) => {
|
|
493
|
+
return ({
|
|
494
|
+
cache,
|
|
495
|
+
blockNumber: userBlockNumber,
|
|
496
|
+
...args
|
|
497
|
+
}: Parameters<PonderActions[action]>[0]) => {
|
|
498
|
+
// Note: prediction only possible when block number is managed by Ponder.
|
|
499
|
+
|
|
500
|
+
if (
|
|
501
|
+
event.type !== "setup" &&
|
|
502
|
+
userBlockNumber === undefined &&
|
|
503
|
+
eventCount[event.eventCallback.name]! % SAMPLING_RATE === 1
|
|
504
|
+
) {
|
|
505
|
+
const eventName = event.eventCallback.name;
|
|
506
|
+
|
|
507
|
+
if (profile.has(eventName) === false) {
|
|
508
|
+
profile.set(eventName, new Map());
|
|
509
|
+
profileConstantLRU.set(eventName, new Set());
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// profile "readContract" and "multicall" actions
|
|
513
|
+
if (action === "readContract") {
|
|
514
|
+
const recordPatternResult = recordProfilePattern({
|
|
515
|
+
event: event,
|
|
516
|
+
args: { ...args, cache } as Parameters<
|
|
517
|
+
PonderActions["readContract"]
|
|
518
|
+
>[0],
|
|
519
|
+
hints: Array.from(profile.get(eventName)!.values()),
|
|
520
|
+
});
|
|
521
|
+
if (recordPatternResult) {
|
|
522
|
+
addProfilePattern(recordPatternResult);
|
|
523
|
+
}
|
|
524
|
+
} else if (action === "multicall") {
|
|
525
|
+
const contracts = (
|
|
526
|
+
{ ...args, cache } as Parameters<PonderActions["multicall"]>[0]
|
|
527
|
+
).contracts as ContractFunctionParameters[];
|
|
528
|
+
|
|
529
|
+
if (contracts.length < 10) {
|
|
530
|
+
for (const contract of contracts) {
|
|
531
|
+
const recordPatternResult = recordProfilePattern({
|
|
532
|
+
event: event,
|
|
533
|
+
args: contract,
|
|
534
|
+
hints: Array.from(profile.get(eventName)!.values()),
|
|
535
|
+
});
|
|
536
|
+
if (recordPatternResult) {
|
|
537
|
+
addProfilePattern(recordPatternResult);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
const blockNumber =
|
|
545
|
+
event.type === "setup" ? event.block : event.event.block.number;
|
|
546
|
+
|
|
547
|
+
// @ts-expect-error
|
|
548
|
+
return _publicActions[action]({
|
|
549
|
+
...args,
|
|
550
|
+
...(cache === "immutable"
|
|
551
|
+
? { blockTag: "latest" }
|
|
552
|
+
: { blockNumber: userBlockNumber ?? blockNumber }),
|
|
553
|
+
} as Parameters<ReturnType<typeof publicActions>[action]>[0]);
|
|
554
|
+
};
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
const getRetryAction = (
|
|
558
|
+
action: PonderActions[keyof PonderActions],
|
|
559
|
+
actionName: keyof PonderActions,
|
|
560
|
+
) => {
|
|
561
|
+
return async (...args: Parameters<typeof action>) => {
|
|
562
|
+
const RETRY_COUNT = 9;
|
|
563
|
+
const BASE_DURATION = 125;
|
|
564
|
+
for (let i = 0; i <= RETRY_COUNT; i++) {
|
|
565
|
+
try {
|
|
566
|
+
// @ts-ignore
|
|
567
|
+
return await action(...args);
|
|
568
|
+
} catch (error) {
|
|
569
|
+
const eventName =
|
|
570
|
+
event.type === "setup"
|
|
571
|
+
? event.setupCallback.name
|
|
572
|
+
: event.eventCallback.name;
|
|
573
|
+
if (
|
|
574
|
+
(error instanceof BlockNotFoundError === false &&
|
|
575
|
+
error instanceof TransactionNotFoundError === false &&
|
|
576
|
+
error instanceof TransactionReceiptNotFoundError === false &&
|
|
577
|
+
// Note: Another way to catch this error is:
|
|
578
|
+
// `error instanceof ContractFunctionExecutionError && error.cause instanceOf ContractFunctionZeroDataError`
|
|
579
|
+
(error as Error)?.message?.includes("returned no data") ===
|
|
580
|
+
false) ||
|
|
581
|
+
i === RETRY_COUNT ||
|
|
582
|
+
(args[0] as RetryableOptions).retryEmptyResponse === false
|
|
583
|
+
) {
|
|
584
|
+
const chain = indexingBuild.chains.find(
|
|
585
|
+
(n) => n.id === event.chain.id,
|
|
586
|
+
)!;
|
|
587
|
+
common.logger.warn({
|
|
588
|
+
msg: "Failed 'context.client' action",
|
|
589
|
+
action: actionName,
|
|
590
|
+
event: eventName,
|
|
591
|
+
chain: chain.name,
|
|
592
|
+
chain_id: chain.id,
|
|
593
|
+
retry_count: i,
|
|
594
|
+
error: error as Error,
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
throw error;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
const duration = BASE_DURATION * 2 ** i;
|
|
601
|
+
const chain = indexingBuild.chains.find(
|
|
602
|
+
(n) => n.id === event.chain.id,
|
|
603
|
+
)!;
|
|
604
|
+
common.logger.warn({
|
|
605
|
+
msg: "Failed 'context.client' action",
|
|
606
|
+
action: actionName,
|
|
607
|
+
event: eventName,
|
|
608
|
+
chain: chain.name,
|
|
609
|
+
chain_id: chain.id,
|
|
610
|
+
retry_count: i,
|
|
611
|
+
retry_delay: duration,
|
|
612
|
+
error: error as Error,
|
|
613
|
+
});
|
|
614
|
+
await wait(duration);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
for (const action of blockDependentActions) {
|
|
621
|
+
actions[action] = getPonderAction(action);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
for (const action of nonBlockDependentActions) {
|
|
625
|
+
// @ts-ignore
|
|
626
|
+
actions[action] = _publicActions[action];
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
for (const action of blockRequiredActions) {
|
|
630
|
+
// @ts-ignore
|
|
631
|
+
actions[action] = _publicActions[action];
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
for (const action of retryableActions) {
|
|
635
|
+
// @ts-ignore
|
|
636
|
+
actions[action] = getRetryAction(actions[action], action);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
const actionsWithMetrics = {} as PonderActions;
|
|
640
|
+
|
|
641
|
+
for (const [action, actionFn] of Object.entries(actions)) {
|
|
642
|
+
// @ts-ignore
|
|
643
|
+
actionsWithMetrics[action] = async (
|
|
644
|
+
...args: Parameters<PonderActions[keyof PonderActions]>
|
|
645
|
+
) => {
|
|
646
|
+
const endClock = startClock();
|
|
647
|
+
try {
|
|
648
|
+
// @ts-ignore
|
|
649
|
+
return await actionFn(...args);
|
|
650
|
+
} finally {
|
|
651
|
+
common.metrics.ponder_indexing_rpc_action_duration.observe(
|
|
652
|
+
{ action },
|
|
653
|
+
endClock(),
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
return actionsWithMetrics;
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
return {
|
|
663
|
+
getClient(chain) {
|
|
664
|
+
const rpc =
|
|
665
|
+
indexingBuild.rpcs[indexingBuild.chains.findIndex((n) => n === chain)]!;
|
|
666
|
+
|
|
667
|
+
return createClient({
|
|
668
|
+
transport: cachedTransport({
|
|
669
|
+
common,
|
|
670
|
+
chain,
|
|
671
|
+
rpc,
|
|
672
|
+
syncStore,
|
|
673
|
+
cache,
|
|
674
|
+
event: () => event,
|
|
675
|
+
}),
|
|
676
|
+
chain: chain.viemChain,
|
|
677
|
+
// @ts-expect-error overriding `readContract` is not supported by viem
|
|
678
|
+
}).extend(ponderActions);
|
|
679
|
+
},
|
|
680
|
+
async prefetch({ events }) {
|
|
681
|
+
const context = {
|
|
682
|
+
logger: common.logger.child({ action: "prefetch_rpc_requests" }),
|
|
683
|
+
};
|
|
684
|
+
const prefetchEndClock = startClock();
|
|
685
|
+
|
|
686
|
+
// Use profiling metadata + next event batch to determine which
|
|
687
|
+
// rpc requests are going to be made, and preload them into the cache.
|
|
688
|
+
|
|
689
|
+
const prediction: { ev: number; request: Request }[] = [];
|
|
690
|
+
|
|
691
|
+
for (const event of events) {
|
|
692
|
+
if (profile.has(event.eventCallback.name)) {
|
|
693
|
+
for (const [, { pattern, count }] of profile.get(
|
|
694
|
+
event.eventCallback.name,
|
|
695
|
+
)!) {
|
|
696
|
+
// Expected value of times the prediction will be used.
|
|
697
|
+
const ev =
|
|
698
|
+
(count * SAMPLING_RATE) / eventCount[event.eventCallback.name]!;
|
|
699
|
+
prediction.push({
|
|
700
|
+
ev,
|
|
701
|
+
request: recoverProfilePattern(pattern, event),
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
const chainRequests: Map<
|
|
708
|
+
number,
|
|
709
|
+
{ ev: number; request: RequestParameters }[]
|
|
710
|
+
> = new Map();
|
|
711
|
+
for (const chain of indexingBuild.chains) {
|
|
712
|
+
chainRequests.set(chain.id, []);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
for (const { ev, request } of dedupe(prediction, ({ request }) =>
|
|
716
|
+
getCacheKey(encodeRequest(request)),
|
|
717
|
+
)) {
|
|
718
|
+
chainRequests.get(request.chainId)!.push({
|
|
719
|
+
ev,
|
|
720
|
+
request: encodeRequest(request),
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
await Promise.all(
|
|
725
|
+
Array.from(chainRequests.entries()).map(async ([chainId, requests]) => {
|
|
726
|
+
const i = indexingBuild.chains.findIndex((n) => n.id === chainId);
|
|
727
|
+
const chain = indexingBuild.chains[i]!;
|
|
728
|
+
const rpc = indexingBuild.rpcs[i]!;
|
|
729
|
+
|
|
730
|
+
const dbRequests = requests.filter(
|
|
731
|
+
({ ev }) => ev > DB_PREDICTION_THRESHOLD,
|
|
732
|
+
);
|
|
733
|
+
|
|
734
|
+
common.metrics.ponder_indexing_rpc_prefetch_total.inc(
|
|
735
|
+
{
|
|
736
|
+
chain: chain.name,
|
|
737
|
+
method: "eth_call",
|
|
738
|
+
type: "database",
|
|
739
|
+
},
|
|
740
|
+
dbRequests.length,
|
|
741
|
+
);
|
|
742
|
+
|
|
743
|
+
const cachedResults = await syncStore.getRpcRequestResults(
|
|
744
|
+
{
|
|
745
|
+
requests: dbRequests.map(({ request }) => request),
|
|
746
|
+
chainId,
|
|
747
|
+
},
|
|
748
|
+
context,
|
|
749
|
+
);
|
|
750
|
+
|
|
751
|
+
for (let i = 0; i < dbRequests.length; i++) {
|
|
752
|
+
const request = dbRequests[i]!;
|
|
753
|
+
const cachedResult = cachedResults[i]!;
|
|
754
|
+
|
|
755
|
+
if (cachedResult !== undefined) {
|
|
756
|
+
cache
|
|
757
|
+
.get(chainId)!
|
|
758
|
+
.set(getCacheKey(request.request), cachedResult);
|
|
759
|
+
} else if (request.ev > RPC_PREDICTION_THRESHOLD) {
|
|
760
|
+
const resultPromise = rpc
|
|
761
|
+
.request(request.request, context)
|
|
762
|
+
.then((result) => JSON.stringify(result))
|
|
763
|
+
.catch((error) => error as Error);
|
|
764
|
+
|
|
765
|
+
common.metrics.ponder_indexing_rpc_prefetch_total.inc({
|
|
766
|
+
chain: chain.name,
|
|
767
|
+
method: "eth_call",
|
|
768
|
+
type: "rpc",
|
|
769
|
+
});
|
|
770
|
+
|
|
771
|
+
// Note: Unawaited request added to cache
|
|
772
|
+
cache
|
|
773
|
+
.get(chainId)!
|
|
774
|
+
.set(getCacheKey(request.request), resultPromise);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
if (dbRequests.length > 0) {
|
|
779
|
+
common.logger.debug({
|
|
780
|
+
msg: "Prefetched JSON-RPC requests",
|
|
781
|
+
chain: chain.name,
|
|
782
|
+
chain_id: chain.id,
|
|
783
|
+
request_count: dbRequests.length,
|
|
784
|
+
duration: prefetchEndClock(),
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
}),
|
|
788
|
+
);
|
|
789
|
+
},
|
|
790
|
+
clear() {
|
|
791
|
+
for (const chain of indexingBuild.chains) {
|
|
792
|
+
cache.get(chain.id)!.clear();
|
|
793
|
+
}
|
|
794
|
+
},
|
|
795
|
+
set event(_event: Event | SetupEvent) {
|
|
796
|
+
event = _event;
|
|
797
|
+
},
|
|
798
|
+
};
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
export const cachedTransport =
|
|
802
|
+
({
|
|
803
|
+
common,
|
|
804
|
+
chain,
|
|
805
|
+
rpc,
|
|
806
|
+
syncStore,
|
|
807
|
+
cache,
|
|
808
|
+
event,
|
|
809
|
+
}: {
|
|
810
|
+
common: Common;
|
|
811
|
+
chain: Chain;
|
|
812
|
+
rpc: Rpc;
|
|
813
|
+
syncStore: SyncStore;
|
|
814
|
+
cache: Cache;
|
|
815
|
+
event: () => Event | SetupEvent;
|
|
816
|
+
}): Transport =>
|
|
817
|
+
({ chain: viemChain }) =>
|
|
818
|
+
custom({
|
|
819
|
+
async request({ method, params }) {
|
|
820
|
+
const _event = event();
|
|
821
|
+
const context = {
|
|
822
|
+
logger: common.logger.child({
|
|
823
|
+
action: "cache JSON-RPC request",
|
|
824
|
+
event:
|
|
825
|
+
_event.type === "setup"
|
|
826
|
+
? _event.setupCallback.name
|
|
827
|
+
: _event.eventCallback.name,
|
|
828
|
+
}),
|
|
829
|
+
};
|
|
830
|
+
const body = { method, params };
|
|
831
|
+
|
|
832
|
+
// multicall
|
|
833
|
+
if (
|
|
834
|
+
method === "eth_call" &&
|
|
835
|
+
params[0]?.data?.startsWith(MULTICALL_SELECTOR)
|
|
836
|
+
) {
|
|
837
|
+
let blockNumber: Hex | "latest" | undefined = undefined;
|
|
838
|
+
[, blockNumber] = params;
|
|
839
|
+
|
|
840
|
+
const multicallRequests = decodeFunctionData({
|
|
841
|
+
abi: multicall3Abi,
|
|
842
|
+
data: params[0]!.data,
|
|
843
|
+
}).args[0];
|
|
844
|
+
|
|
845
|
+
if (multicallRequests.length === 0) {
|
|
846
|
+
// empty multicall result
|
|
847
|
+
return "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000";
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
const requests = multicallRequests.map(
|
|
851
|
+
(call) =>
|
|
852
|
+
({
|
|
853
|
+
method: "eth_call",
|
|
854
|
+
params: [
|
|
855
|
+
{
|
|
856
|
+
to: call.target,
|
|
857
|
+
data: call.callData,
|
|
858
|
+
},
|
|
859
|
+
blockNumber ?? "latest",
|
|
860
|
+
],
|
|
861
|
+
}) as const satisfies RequestParameters,
|
|
862
|
+
);
|
|
863
|
+
const results = new Map<
|
|
864
|
+
RequestParameters,
|
|
865
|
+
{
|
|
866
|
+
success: boolean;
|
|
867
|
+
returnData: `0x${string}`;
|
|
868
|
+
}
|
|
869
|
+
>();
|
|
870
|
+
const requestsToInsert = new Set<RequestParameters>();
|
|
871
|
+
|
|
872
|
+
for (const request of requests) {
|
|
873
|
+
const cacheKey = getCacheKey(request);
|
|
874
|
+
|
|
875
|
+
if (cache.get(chain.id)!.has(cacheKey)) {
|
|
876
|
+
const cachedResult = cache.get(chain.id)!.get(cacheKey)!;
|
|
877
|
+
|
|
878
|
+
if (cachedResult instanceof Promise) {
|
|
879
|
+
common.metrics.ponder_indexing_rpc_requests_total.inc({
|
|
880
|
+
chain: chain.name,
|
|
881
|
+
method,
|
|
882
|
+
type: "prefetch_rpc",
|
|
883
|
+
});
|
|
884
|
+
const result = await cachedResult;
|
|
885
|
+
|
|
886
|
+
// Note: we don't attempt to cache or prefetch errors, instead relying on the eventual RPC request.
|
|
887
|
+
|
|
888
|
+
if (result instanceof Error) continue;
|
|
889
|
+
|
|
890
|
+
if (UNCACHED_RESPONSES.includes(result) === false) {
|
|
891
|
+
requestsToInsert.add(request);
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
results.set(request, {
|
|
895
|
+
success: true,
|
|
896
|
+
returnData: decodeResponse(result),
|
|
897
|
+
});
|
|
898
|
+
} else {
|
|
899
|
+
common.metrics.ponder_indexing_rpc_requests_total.inc({
|
|
900
|
+
chain: chain.name,
|
|
901
|
+
method,
|
|
902
|
+
type: "prefetch_database",
|
|
903
|
+
});
|
|
904
|
+
results.set(request, {
|
|
905
|
+
success: true,
|
|
906
|
+
returnData: decodeResponse(cachedResult),
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
const dbRequests = requests.filter(
|
|
913
|
+
(request) => results.has(request) === false,
|
|
914
|
+
);
|
|
915
|
+
|
|
916
|
+
const dbResults = await syncStore.getRpcRequestResults(
|
|
917
|
+
{ requests: dbRequests, chainId: chain.id },
|
|
918
|
+
context,
|
|
919
|
+
);
|
|
920
|
+
|
|
921
|
+
for (let i = 0; i < dbRequests.length; i++) {
|
|
922
|
+
const request = dbRequests[i]!;
|
|
923
|
+
const result = dbResults[i]!;
|
|
924
|
+
|
|
925
|
+
if (result !== undefined) {
|
|
926
|
+
common.metrics.ponder_indexing_rpc_requests_total.inc({
|
|
927
|
+
chain: chain.name,
|
|
928
|
+
method,
|
|
929
|
+
type: "database",
|
|
930
|
+
});
|
|
931
|
+
|
|
932
|
+
results.set(request, {
|
|
933
|
+
success: true,
|
|
934
|
+
returnData: decodeResponse(result),
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
if (results.size < requests.length) {
|
|
940
|
+
const _requests = requests.filter(
|
|
941
|
+
(request) => results.has(request) === false,
|
|
942
|
+
);
|
|
943
|
+
|
|
944
|
+
const multicallResult = await rpc
|
|
945
|
+
.request(
|
|
946
|
+
{
|
|
947
|
+
method: "eth_call",
|
|
948
|
+
params: [
|
|
949
|
+
{
|
|
950
|
+
to: params[0]!.to,
|
|
951
|
+
data: encodeFunctionData({
|
|
952
|
+
abi: multicall3Abi,
|
|
953
|
+
functionName: "aggregate3",
|
|
954
|
+
args: [
|
|
955
|
+
multicallRequests.filter(
|
|
956
|
+
(_, i) => results.has(requests[i]!) === false,
|
|
957
|
+
),
|
|
958
|
+
],
|
|
959
|
+
}),
|
|
960
|
+
},
|
|
961
|
+
blockNumber!,
|
|
962
|
+
],
|
|
963
|
+
},
|
|
964
|
+
context,
|
|
965
|
+
)
|
|
966
|
+
.then((result) =>
|
|
967
|
+
decodeFunctionResult({
|
|
968
|
+
abi: multicall3Abi,
|
|
969
|
+
functionName: "aggregate3",
|
|
970
|
+
data: result,
|
|
971
|
+
}),
|
|
972
|
+
);
|
|
973
|
+
|
|
974
|
+
for (let i = 0; i < _requests.length; i++) {
|
|
975
|
+
const request = _requests[i]!;
|
|
976
|
+
const result = multicallResult[i]!;
|
|
977
|
+
|
|
978
|
+
if (
|
|
979
|
+
result.success &&
|
|
980
|
+
UNCACHED_RESPONSES.includes(result.returnData) === false
|
|
981
|
+
) {
|
|
982
|
+
requestsToInsert.add(request);
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
common.metrics.ponder_indexing_rpc_requests_total.inc({
|
|
986
|
+
chain: chain.name,
|
|
987
|
+
method,
|
|
988
|
+
type: "rpc",
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
results.set(request, result);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
const encodedBlockNumber =
|
|
996
|
+
blockNumber === undefined
|
|
997
|
+
? undefined
|
|
998
|
+
: blockNumber === "latest"
|
|
999
|
+
? 0
|
|
1000
|
+
: hexToNumber(blockNumber);
|
|
1001
|
+
|
|
1002
|
+
// Note: insertRpcRequestResults errors can be ignored and not awaited, since
|
|
1003
|
+
// the response is already fetched.
|
|
1004
|
+
syncStore
|
|
1005
|
+
.insertRpcRequestResults(
|
|
1006
|
+
{
|
|
1007
|
+
requests: Array.from(requestsToInsert).map((request) => ({
|
|
1008
|
+
request,
|
|
1009
|
+
blockNumber: encodedBlockNumber,
|
|
1010
|
+
result: JSON.stringify(results.get(request)!.returnData),
|
|
1011
|
+
})),
|
|
1012
|
+
chainId: chain.id,
|
|
1013
|
+
},
|
|
1014
|
+
context,
|
|
1015
|
+
)
|
|
1016
|
+
.catch(() => {});
|
|
1017
|
+
|
|
1018
|
+
// Note: at this point, it is an invariant that either `allowFailure` is true or
|
|
1019
|
+
// there are no failed requests.
|
|
1020
|
+
|
|
1021
|
+
// Note: viem <= 2.23.6 had a bug with `encodeFunctionResult` which can be worked around by adding
|
|
1022
|
+
// another layer of array nesting.
|
|
1023
|
+
// Fixed by this commit https://github.com/wevm/viem/commit/9c442de0ff38ac1f654b5c751d292e9a9f8d574c
|
|
1024
|
+
|
|
1025
|
+
const resultsToEncode = requests.map(
|
|
1026
|
+
(request) => results.get(request)!,
|
|
1027
|
+
);
|
|
1028
|
+
|
|
1029
|
+
try {
|
|
1030
|
+
return encodeFunctionResult({
|
|
1031
|
+
abi: multicall3Abi,
|
|
1032
|
+
functionName: "aggregate3",
|
|
1033
|
+
result: resultsToEncode,
|
|
1034
|
+
});
|
|
1035
|
+
} catch (e) {
|
|
1036
|
+
return encodeFunctionResult({
|
|
1037
|
+
abi: multicall3Abi,
|
|
1038
|
+
functionName: "aggregate3",
|
|
1039
|
+
result: [
|
|
1040
|
+
// @ts-expect-error known issue in viem <= 2.23.6
|
|
1041
|
+
resultsToEncode,
|
|
1042
|
+
],
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
} else if (
|
|
1046
|
+
blockDependentMethods.has(method) ||
|
|
1047
|
+
nonBlockDependentMethods.has(method)
|
|
1048
|
+
) {
|
|
1049
|
+
const blockNumber = extractBlockNumberParam(body);
|
|
1050
|
+
const encodedBlockNumber =
|
|
1051
|
+
blockNumber === undefined
|
|
1052
|
+
? undefined
|
|
1053
|
+
: blockNumber === "latest"
|
|
1054
|
+
? 0
|
|
1055
|
+
: hexToNumber(blockNumber);
|
|
1056
|
+
|
|
1057
|
+
const cacheKey = getCacheKey(body);
|
|
1058
|
+
|
|
1059
|
+
if (cache.get(chain.id)!.has(cacheKey)) {
|
|
1060
|
+
const cachedResult = cache.get(chain.id)!.get(cacheKey)!;
|
|
1061
|
+
|
|
1062
|
+
// `cachedResult` is a Promise if the request had to be fetched from the RPC.
|
|
1063
|
+
if (cachedResult instanceof Promise) {
|
|
1064
|
+
common.metrics.ponder_indexing_rpc_requests_total.inc({
|
|
1065
|
+
chain: chain.name,
|
|
1066
|
+
method,
|
|
1067
|
+
type: "prefetch_rpc",
|
|
1068
|
+
});
|
|
1069
|
+
const result = await cachedResult;
|
|
1070
|
+
|
|
1071
|
+
if (result instanceof Error) throw result;
|
|
1072
|
+
|
|
1073
|
+
if (UNCACHED_RESPONSES.includes(result) === false) {
|
|
1074
|
+
// Note: insertRpcRequestResults errors can be ignored and not awaited, since
|
|
1075
|
+
// the response is already fetched.
|
|
1076
|
+
syncStore
|
|
1077
|
+
.insertRpcRequestResults(
|
|
1078
|
+
{
|
|
1079
|
+
requests: [
|
|
1080
|
+
{
|
|
1081
|
+
request: body,
|
|
1082
|
+
blockNumber: encodedBlockNumber,
|
|
1083
|
+
result,
|
|
1084
|
+
},
|
|
1085
|
+
],
|
|
1086
|
+
chainId: chain.id,
|
|
1087
|
+
},
|
|
1088
|
+
context,
|
|
1089
|
+
)
|
|
1090
|
+
.catch(() => {});
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
return decodeResponse(result);
|
|
1094
|
+
} else {
|
|
1095
|
+
common.metrics.ponder_indexing_rpc_requests_total.inc({
|
|
1096
|
+
chain: chain.name,
|
|
1097
|
+
method,
|
|
1098
|
+
type: "prefetch_database",
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
return decodeResponse(cachedResult);
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
const [cachedResult] = await syncStore.getRpcRequestResults(
|
|
1106
|
+
{ requests: [body], chainId: chain.id },
|
|
1107
|
+
context,
|
|
1108
|
+
);
|
|
1109
|
+
|
|
1110
|
+
if (cachedResult !== undefined) {
|
|
1111
|
+
common.metrics.ponder_indexing_rpc_requests_total.inc({
|
|
1112
|
+
chain: chain.name,
|
|
1113
|
+
method,
|
|
1114
|
+
type: "database",
|
|
1115
|
+
});
|
|
1116
|
+
|
|
1117
|
+
return decodeResponse(cachedResult);
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
common.metrics.ponder_indexing_rpc_requests_total.inc({
|
|
1121
|
+
chain: chain.name,
|
|
1122
|
+
method,
|
|
1123
|
+
type: "rpc",
|
|
1124
|
+
});
|
|
1125
|
+
|
|
1126
|
+
const response = await rpc.request(body, context);
|
|
1127
|
+
|
|
1128
|
+
if (UNCACHED_RESPONSES.includes(response) === false) {
|
|
1129
|
+
// Note: insertRpcRequestResults errors can be ignored and not awaited, since
|
|
1130
|
+
// the response is already fetched.
|
|
1131
|
+
syncStore
|
|
1132
|
+
.insertRpcRequestResults(
|
|
1133
|
+
{
|
|
1134
|
+
requests: [
|
|
1135
|
+
{
|
|
1136
|
+
request: body,
|
|
1137
|
+
blockNumber: encodedBlockNumber,
|
|
1138
|
+
result: JSON.stringify(response),
|
|
1139
|
+
},
|
|
1140
|
+
],
|
|
1141
|
+
chainId: chain.id,
|
|
1142
|
+
},
|
|
1143
|
+
context,
|
|
1144
|
+
)
|
|
1145
|
+
.catch(() => {});
|
|
1146
|
+
}
|
|
1147
|
+
return response;
|
|
1148
|
+
} else {
|
|
1149
|
+
return rpc.request(body, context);
|
|
1150
|
+
}
|
|
1151
|
+
},
|
|
1152
|
+
})({ chain: viemChain, retryCount: 0 });
|
|
1153
|
+
|
|
1154
|
+
export const extractBlockNumberParam = (request: RequestParameters) => {
|
|
1155
|
+
let blockNumber: Hex | "latest" | undefined = undefined;
|
|
1156
|
+
|
|
1157
|
+
switch (request.method) {
|
|
1158
|
+
case "eth_getBlockByNumber":
|
|
1159
|
+
case "eth_getBlockTransactionCountByNumber":
|
|
1160
|
+
case "eth_getTransactionByBlockNumberAndIndex":
|
|
1161
|
+
case "eth_getUncleByBlockNumberAndIndex":
|
|
1162
|
+
case "debug_traceBlockByNumber":
|
|
1163
|
+
// @ts-expect-error
|
|
1164
|
+
[blockNumber] = request.params;
|
|
1165
|
+
break;
|
|
1166
|
+
case "eth_getBalance":
|
|
1167
|
+
case "eth_call":
|
|
1168
|
+
case "eth_getCode":
|
|
1169
|
+
case "eth_estimateGas":
|
|
1170
|
+
case "eth_feeHistory":
|
|
1171
|
+
case "eth_getTransactionCount":
|
|
1172
|
+
// @ts-expect-error
|
|
1173
|
+
[, blockNumber] = request.params;
|
|
1174
|
+
break;
|
|
1175
|
+
|
|
1176
|
+
case "eth_getProof":
|
|
1177
|
+
case "eth_getStorageAt":
|
|
1178
|
+
// @ts-expect-error
|
|
1179
|
+
[, , blockNumber] = request.params;
|
|
1180
|
+
break;
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
return blockNumber;
|
|
1184
|
+
};
|