Skip to content

Conversation

@DZakh
Copy link
Member

@DZakh DZakh commented Dec 5, 2025

  • Add Solana ecosystem (wip) (no plans to finish in the PR)
  • Rename Network to Chain in config reference
  • Remove ContractType enum
  • Rename Prom Metric from chain_block_height to envio_indexing_known_height
  • Fix incorrect entry to reorg threshold bug
  • Support for Block Handlers usage without events
  • Make contracts optional in config.yaml
  • Moved more modules from static codegen to npm package

Summary by CodeRabbit

  • New Features

    • Solana ecosystem support and a new block-handler scenario.
    • Field-based query operators added (eq, gt, lt).
  • API Changes

    • Terminology unified: "Network" → "Chain".
    • Chain contract lists are now optional.
    • Public height field renamed/exposed as knownHeight (replaces currentBlockHeight).
  • Dependencies

    • Added date-fns.
  • Improvements

    • Prometheus now reports an indexing "known height".
    • Simplified test/build scripts and added Solana schema and CLI schema output.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 5, 2025

Walkthrough

Renames Network→Chain and threads a new knownHeight through fetch/sources/metrics/state; adds Solana ecosystem and schema generation; threads Config into event handling and user-entities mapping; updates templates, generated types (whereOperations), Prometheus metric, and many tests/scripts.

Changes

Cohort / File(s) Change Summary
Height refactor (currentBlockHeight → knownHeight)
codegenerator/cli/npm/envio/src/FetchState.res, codegenerator/cli/npm/envio/src/ChainFetcher.res, codegenerator/cli/npm/envio/src/GlobalState.res, codegenerator/cli/npm/envio/src/sources/..., codegenerator/cli/npm/envio/src/sources/SourceManager.res, codegenerator/cli/npm/envio/src/sources/SourceManager.resi, codegenerator/cli/templates/static/codegen/src/Index.res, codegenerator/cli/templates/static/codegen/src/ink/components/..., scenarios/**, scenarios/test_codegen/**
Replaced currentBlockHeight with knownHeight across types, function signatures, payloads and templates; added knownHeight to FetchState and propagated through Sources, SourceManager, ChainFetcher, GlobalState, templates and tests; preserved public aliases where needed.
Config & type renames (Network → Chain)
codegenerator/cli/npm/envio/evm.schema.json, codegenerator/cli/npm/envio/fuel.schema.json, codegenerator/cli/src/config_parsing/human_config.rs, codegenerator/cli/src/config_parsing/init_config.rs, codegenerator/cli/src/config_parsing/graph_migration/mod.rs, codegenerator/cli/src/config_parsing/validation.rs, codegenerator/cli/src/config_parsing/system_config.rs
Renamed Network/NetworkContract/NetworkId → Chain/ChainContract/ChainId; made chain.contracts optional (nullable/Option) and updated construction/iteration to handle Option; adjusted descriptions from “network” → “chain”; added Solana HumanConfig support.
Solana support & schema generation
codegenerator/cli/npm/envio/solana.schema.json, codegenerator/cli/src/cli_args/clap_definitions.rs, codegenerator/cli/src/executor/mod.rs, codegenerator/cli/src/hbs_templating/codegen_templates.rs, codegenerator/cli/Makefile, scenarios/block_handler/*
Added Solana HumanConfig and new schema file, new JsonSchema::Solana option and executor printing path, Makefile step to generate ./npm/envio/solana.schema.json, template flag is_solana_ecosystem, and a block_handler scenario scaffold.
Event processing & config threading
codegenerator/cli/npm/envio/src/EventProcessing.res, codegenerator/cli/npm/envio/src/Config.res, codegenerator/cli/npm/envio/src/UserContext.res, codegenerator/cli/templates/dynamic/codegen/src/Generated.res.hbs
Threaded ~config: Config.t through runEventHandlerOrThrow/runHandlerOrThrow/preloadBatchOrThrow/processEventBatch; added userEntitiesByName to Config.t and pass ~userEntities=Entities.userEntities in generated Config.make; UserContext now uses config.userEntitiesByName.
Prometheus metrics rename
codegenerator/cli/npm/envio/src/Prometheus.res
Replaced chain_block_height gauge / setSourceChainHeight with envio_indexing_known_height gauge / setKnownHeight.
Public API additions (Envio)
codegenerator/cli/npm/envio/src/Envio.res, codegenerator/cli/npm/envio/src/Envio.gen.ts, codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs
Added generic whereOperations<entity,fieldType> type with eq/gt/lt methods; removed locally-generated whereOperations and updated generated Entities to reference Envio.whereOperations.
Sources & SourceManager response shape
codegenerator/cli/npm/envio/src/sources/Source.res, codegenerator/cli/npm/envio/src/sources/RpcSource.res, codegenerator/cli/npm/envio/src/sources/HyperSyncSource.res, codegenerator/cli/npm/envio/src/sources/HyperFuelSource.res, codegenerator/cli/npm/envio/src/sources/SourceManager.res, codegenerator/cli/npm/envio/src/sources/SourceManager.resi
getItemsOrThrow signatures and blockRangeFetchResponse now expose knownHeight; added latestFetchedBlockNumber, latestFetchedBlockTimestamp, and stats to response shape; SourceManager removed old currentBlockHeight parameter and now accepts/passes knownHeight.
Reorg detection & related helpers
codegenerator/cli/npm/envio/src/ReorgDetection.res, codegenerator/cli/npm/envio/src/ChainManager.res
Internal reorg/prune helpers now accept knownHeight and derive thresholds from it; ChainManager uses fetchState.knownHeight for sourceBlockNumber and safe-checkpoint logic.
Templates, tests, scripts & miscellaneous
codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs, codegenerator/cli/templates/dynamic/codegen/src/TestHelpers_MockDb.res.hbs, codegenerator/cli/templates/dynamic/codegen/src/db/Enums.res.hbs, codegenerator/cli/templates/static/codegen/src/Index.res, codegenerator/integration_tests/**/package.json, .github/workflows/build_and_test.yml, various scenario/test files
Removed/adjusted TypeScript build/watch/clean scripts, consolidated mocha/tsc checks, updated templates to pass ~userEntities, removed generated ContractType enum, updated mocks and tests to use knownHeight and new response shapes, added .gitignore entries and scenario scaffolds.
Dependency & package updates
codegenerator/cli/npm/envio/package.json, codegenerator/cli/npm/envio/package.json.tmpl
Added dependency [email protected] to package.json and package.json.tmpl.
Makefile
codegenerator/cli/Makefile
Added Makefile step to generate Solana schema via cargo run targeting ./npm/envio/solana.schema.json.

sequenceDiagram
Note: the following diagram visualizes the primary runtime interactions affected by knownHeight propagation.

sequenceDiagram
  autonumber
  participant SM as SourceManager
  participant Source as Source (Rpc/HyperSync/HyperFuel)
  participant CF as ChainFetcher
  participant FS as FetchState
  participant GS as GlobalState
  participant PM as Prometheus

  SM->>Source: executeQuery(~knownHeight)
  Source-->>SM: blockRangeFetchResponse{items, knownHeight, latestFetchedBlock...}
  SM->>CF: submitPartitionQueryResponse(..., knownHeight)
  CF->>FS: handleQueryResult(..., ~knownHeight)
  FS->>FS: updateKnownHeight(~knownHeight)
  FS->>PM: setKnownHeight(blockNumber, chainId)
  CF->>GS: enqueue ProcessEventBatch (uses fetchState.knownHeight)
  GS->>EventProcessing: processEventBatch(~config, using knownHeight)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Areas requiring extra attention:

  • FetchState ↔ SourceManager ↔ Sources ↔ ChainFetcher propagation of knownHeight (head vs known semantics, boundary conditions).
  • ReorgDetection threshold calculations now derived from knownHeight.
  • Optional chain.contracts handling (get_or_insert / unwrap_or_default correctness).
  • EventProcessing/UserContext config threading and generated Config.make changes (ensure handlers receive expected config shape).
  • Solana schema generation and executor printing path in CLI/Makefile.

Possibly related PRs

Suggested reviewers

  • JonoPrest

Poem

🐰 I hopped through code with nimble feet,
Known heights now guide each fetching beat.
Chains were renamed and Solana sprung near,
Metrics hum softly — the logs give a cheer. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.43% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Block Handler only indexer' directly reflects the main objective of enabling block handler functionality without requiring events, which is a primary focus of the PR changes.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dz/no-events-indexer

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
scenarios/test_codegen/test/lib_tests/FetchState_test.res (1)

2182-2182: Remove debug logging.

This Js.log statement appears to be debug output that should be removed before merging.

-    Js.log(updatedFetchState)
-
🧹 Nitpick comments (5)
scenarios/helpers/src/ChainMocking.res (1)

248-248: Optional: fix heighstBlock spelling for readability

Tiny nit: consider renaming the local heighstBlock to highestBlock (or similar) for clarity and to avoid propagating the typo in future refactors.

codegenerator/cli/templates/static/codegen/src/Index.res (1)

239-290: Consider extracting the inline state construction function.

The getState callback has grown significantly and is now a complex inline function with nested pattern matching. Extracting it into a separate named function would improve:

  • Maintainability: Easier to understand and modify
  • Testability: Can be unit tested independently
  • Readability: Reduces nesting and clarifies intent

Consider refactoring to:

let getStateForConsole = (gsManagerRef, envioVersion, indexer) => {
  switch gsManagerRef.contents {
  | None => Initializing({})
  | Some(gsManager) => {
      let state = gsManager->GlobalStateManager.getState
      let appState = state->makeAppState
      Active({
        envioVersion,
        chains: appState.chains->Js.Array2.map(c => {
          // ... existing mapping logic
        }),
        indexerStartTime: appState.indexerStartTime,
        isPreRegisteringDynamicContracts: false,
        rollbackOnReorg: indexer.config.shouldRollbackOnReorg,
        isUnorderedMultichainMode: switch indexer.config.multichain {
        | Unordered => true
        | Ordered => false
        },
      })
    }
  }
}

// Then use it:
startServer(~indexer, ~isDevelopmentMode, ~getState=() => 
  getStateForConsole(gsManagerRef, envioVersion, indexer)
)
codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs (1)

6-19: Avoid potential duplicate mocha script keys for hybrid TS+ReScript projects

The new scripts cleanly separate TS (test/**/*.ts) and ReScript (test/**/*.res.mjs) runs. One caveat: if a project ever sets both is_typescript and is_rescript to true, this template will emit two "mocha" entries and only the last one will take effect. If hybrid setups are in scope, consider renaming to mocha:ts / mocha:rescript and having "test" delegate to both; otherwise this change is fine as-is.

If you expect any projects to enable both flags, generate a sample package.json with both is_typescript and is_rescript set and confirm the resulting scripts match your intent.

codegenerator/cli/npm/envio/src/LoadLayer.res (1)

31-45: Direct use of entity.id is fine; consider centralizing ID access

Keying both entitiesMap and InMemoryTable.Entity.initValue by entity.id is consistent with how IDs are loaded from storage and should behave the same as any thin accessor that previously wrapped .id.

If you expect Internal.entity’s ID representation to evolve, it may be worth routing these call sites through the same helper used elsewhere (e.g., InMemoryTable.Entity.getEntityIdUnsafe) to keep the ID logic centralized.

Also applies to: 399-405

codegenerator/cli/src/config_parsing/human_config.rs (1)

61-85: Consider reusing BaseConfig in evm and fuel modules.

The BaseConfig struct captures shared fields (name, description, schema, output, handlers) that are duplicated in evm::HumanConfig (lines 166-246) and fuel::HumanConfig (lines 597-640). While this may be intentional for schema generation purposes, using #[serde(flatten)] as done in solana::HumanConfig could reduce duplication.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5b18b1f and d32f9d9.

⛔ Files ignored due to path filters (3)
  • codegenerator/cli/npm/envio/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • scenarios/block_handler/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • scenarios/test_codegen/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (63)
  • codegenerator/cli/Makefile (1 hunks)
  • codegenerator/cli/npm/envio/evm.schema.json (6 hunks)
  • codegenerator/cli/npm/envio/fuel.schema.json (5 hunks)
  • codegenerator/cli/npm/envio/package.json (1 hunks)
  • codegenerator/cli/npm/envio/package.json.tmpl (1 hunks)
  • codegenerator/cli/npm/envio/solana.schema.json (1 hunks)
  • codegenerator/cli/npm/envio/src/ChainFetcher.res (6 hunks)
  • codegenerator/cli/npm/envio/src/ChainManager.res (2 hunks)
  • codegenerator/cli/npm/envio/src/Config.res (4 hunks)
  • codegenerator/cli/npm/envio/src/Envio.gen.ts (1 hunks)
  • codegenerator/cli/npm/envio/src/Envio.res (2 hunks)
  • codegenerator/cli/npm/envio/src/EventProcessing.res (10 hunks)
  • codegenerator/cli/npm/envio/src/FetchState.res (14 hunks)
  • codegenerator/cli/npm/envio/src/GlobalState.res (15 hunks)
  • codegenerator/cli/npm/envio/src/LoadLayer.res (1 hunks)
  • codegenerator/cli/npm/envio/src/Prometheus.res (1 hunks)
  • codegenerator/cli/npm/envio/src/ReorgDetection.res (3 hunks)
  • codegenerator/cli/npm/envio/src/UserContext.res (6 hunks)
  • codegenerator/cli/npm/envio/src/sources/HyperFuelSource.res (5 hunks)
  • codegenerator/cli/npm/envio/src/sources/HyperSyncSource.res (5 hunks)
  • codegenerator/cli/npm/envio/src/sources/RpcSource.res (3 hunks)
  • codegenerator/cli/npm/envio/src/sources/Source.res (2 hunks)
  • codegenerator/cli/npm/envio/src/sources/SourceManager.res (8 hunks)
  • codegenerator/cli/npm/envio/src/sources/SourceManager.resi (1 hunks)
  • codegenerator/cli/src/cli_args/clap_definitions.rs (1 hunks)
  • codegenerator/cli/src/cli_args/init_config.rs (6 hunks)
  • codegenerator/cli/src/config_parsing/graph_migration/mod.rs (7 hunks)
  • codegenerator/cli/src/config_parsing/human_config.rs (23 hunks)
  • codegenerator/cli/src/config_parsing/system_config.rs (17 hunks)
  • codegenerator/cli/src/config_parsing/validation.rs (2 hunks)
  • codegenerator/cli/src/executor/mod.rs (1 hunks)
  • codegenerator/cli/src/hbs_templating/codegen_templates.rs (2 hunks)
  • codegenerator/cli/templates/dynamic/codegen/src/Generated.res.hbs (1 hunks)
  • codegenerator/cli/templates/dynamic/codegen/src/TestHelpers_MockDb.res.hbs (2 hunks)
  • codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs (1 hunks)
  • codegenerator/cli/templates/dynamic/codegen/src/db/Enums.res.hbs (0 hunks)
  • codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs (1 hunks)
  • codegenerator/cli/templates/static/codegen/src/Index.res (6 hunks)
  • codegenerator/cli/templates/static/codegen/src/ink/components/ChainData.res (6 hunks)
  • codegenerator/cli/templates/static/codegen/src/ink/components/SyncETA.res (1 hunks)
  • codegenerator/integration_tests/tests/test_indexers/dynamic_contracts/package.json (0 hunks)
  • codegenerator/integration_tests/tests/test_indexers/test_exits/package.json (0 hunks)
  • codegenerator/integration_tests/tests/test_indexers/wildcard-uni-factory/package.json (0 hunks)
  • scenarios/block_handler/.gitignore (1 hunks)
  • scenarios/block_handler/config.yaml (1 hunks)
  • scenarios/block_handler/package.json (1 hunks)
  • scenarios/block_handler/schema.graphql (1 hunks)
  • scenarios/block_handler/src/handlers/BlockHandler.ts (1 hunks)
  • scenarios/block_handler/tsconfig.json (1 hunks)
  • scenarios/fuel_test/package.json (0 hunks)
  • scenarios/helpers/src/ChainMocking.res (2 hunks)
  • scenarios/test_codegen/package.json (0 hunks)
  • scenarios/test_codegen/test/ChainManager_test.res (1 hunks)
  • scenarios/test_codegen/test/E2E_test.res (2 hunks)
  • scenarios/test_codegen/test/EventOrigin_test.res (1 hunks)
  • scenarios/test_codegen/test/ReorgDetection_test.res (12 hunks)
  • scenarios/test_codegen/test/helpers/Mock.res (5 hunks)
  • scenarios/test_codegen/test/lib_tests/FetchState_onBlock_test.res (1 hunks)
  • scenarios/test_codegen/test/lib_tests/FetchState_test.res (53 hunks)
  • scenarios/test_codegen/test/lib_tests/SourceManager_test.res (37 hunks)
  • scenarios/test_codegen/test/rollback/Rollback_test.res (3 hunks)
  • scenarios/test_codegen/test/schema_types/BigDecimal_test.res (1 hunks)
  • scenarios/test_codegen/test/schema_types/Timestamp_test.res (1 hunks)
💤 Files with no reviewable changes (6)
  • codegenerator/cli/templates/dynamic/codegen/src/db/Enums.res.hbs
  • codegenerator/integration_tests/tests/test_indexers/test_exits/package.json
  • scenarios/test_codegen/package.json
  • scenarios/fuel_test/package.json
  • codegenerator/integration_tests/tests/test_indexers/dynamic_contracts/package.json
  • codegenerator/integration_tests/tests/test_indexers/wildcard-uni-factory/package.json
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{res,resi}

📄 CodeRabbit inference engine (.cursor/rules/rescript.mdc)

**/*.{res,resi}: Always use ReScript 11 documentation
Never suggest ReasonML syntax
Never use [| item |] to create an array. Use [ item ] instead
Must always use = for setting value to a field. Use := only for ref values created using ref function
Use records when working with structured data, and objects to conveniently pass payload data between functions
Never use %raw to access object fields if you know the type

Files:

  • scenarios/test_codegen/test/EventOrigin_test.res
  • codegenerator/cli/npm/envio/src/Config.res
  • codegenerator/cli/templates/static/codegen/src/ink/components/SyncETA.res
  • scenarios/test_codegen/test/ReorgDetection_test.res
  • codegenerator/cli/npm/envio/src/Envio.res
  • scenarios/helpers/src/ChainMocking.res
  • codegenerator/cli/npm/envio/src/UserContext.res
  • codegenerator/cli/npm/envio/src/sources/Source.res
  • scenarios/test_codegen/test/E2E_test.res
  • codegenerator/cli/npm/envio/src/sources/HyperSyncSource.res
  • codegenerator/cli/templates/static/codegen/src/ink/components/ChainData.res
  • scenarios/test_codegen/test/rollback/Rollback_test.res
  • scenarios/test_codegen/test/schema_types/Timestamp_test.res
  • scenarios/test_codegen/test/lib_tests/SourceManager_test.res
  • codegenerator/cli/npm/envio/src/sources/SourceManager.res
  • codegenerator/cli/templates/static/codegen/src/Index.res
  • codegenerator/cli/npm/envio/src/Prometheus.res
  • codegenerator/cli/npm/envio/src/EventProcessing.res
  • codegenerator/cli/npm/envio/src/ChainManager.res
  • codegenerator/cli/npm/envio/src/ReorgDetection.res
  • codegenerator/cli/npm/envio/src/ChainFetcher.res
  • codegenerator/cli/npm/envio/src/sources/SourceManager.resi
  • codegenerator/cli/npm/envio/src/LoadLayer.res
  • codegenerator/cli/npm/envio/src/GlobalState.res
  • codegenerator/cli/npm/envio/src/sources/RpcSource.res
  • scenarios/test_codegen/test/schema_types/BigDecimal_test.res
  • codegenerator/cli/npm/envio/src/FetchState.res
  • scenarios/test_codegen/test/ChainManager_test.res
  • scenarios/test_codegen/test/lib_tests/FetchState_onBlock_test.res
  • scenarios/test_codegen/test/lib_tests/FetchState_test.res
  • scenarios/test_codegen/test/helpers/Mock.res
  • codegenerator/cli/npm/envio/src/sources/HyperFuelSource.res
codegenerator/cli/templates/static/**/*.res

📄 CodeRabbit inference engine (.cursor/rules/navigation.mdc)

Static ReScript files must be placed in codegenerator/cli/templates/static/

Files:

  • codegenerator/cli/templates/static/codegen/src/ink/components/SyncETA.res
  • codegenerator/cli/templates/static/codegen/src/ink/components/ChainData.res
  • codegenerator/cli/templates/static/codegen/src/Index.res
codegenerator/cli/templates/dynamic/**/*.hbs

📄 CodeRabbit inference engine (.cursor/rules/navigation.mdc)

Handlebars templates must be placed in codegenerator/cli/templates/dynamic/

Files:

  • codegenerator/cli/templates/dynamic/codegen/src/Generated.res.hbs
  • codegenerator/cli/templates/dynamic/codegen/src/TestHelpers_MockDb.res.hbs
  • codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs
  • codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs
🧠 Learnings (35)
📓 Common learnings
Learnt from: nikbhintade
Repo: enviodev/hyperindex PR: 822
File: codegenerator/cli/templates/static/multichain_indexer_template/typescript/src/EventHandlers.ts:10-18
Timestamp: 2025-11-19T05:36:33.975Z
Learning: The multichain_indexer_template in codegenerator/cli/templates/static/ is designed to demonstrate multichain indexing features. It intentionally uses minimal event parameters (e.g., only capturing the `pool` address from Uniswap V3 PoolCreated events) to keep the focus on multichain functionality rather than comprehensive event indexing.
📚 Learning: 2025-12-04T12:12:49.534Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-12-04T12:12:49.534Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.graphql : Use `entity_id` fields for relationships in GraphQL schemas (e.g., `user_id: String!`) instead of direct entity references or entity arrays

Applied to files:

  • scenarios/block_handler/schema.graphql
  • codegenerator/cli/templates/dynamic/codegen/src/Generated.res.hbs
  • codegenerator/cli/npm/envio/src/LoadLayer.res
  • codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs
📚 Learning: 2025-12-04T12:12:49.534Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-12-04T12:12:49.534Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.{yaml,yml} : Use the Envio EVM schema file for YAML validation in config.yaml: `yaml-language-server: $schema=./node_modules/envio/evm.schema.json`

Applied to files:

  • scenarios/block_handler/config.yaml
  • codegenerator/cli/npm/envio/solana.schema.json
  • codegenerator/cli/Makefile
  • codegenerator/cli/npm/envio/evm.schema.json
📚 Learning: 2025-12-04T12:13:23.231Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.231Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/src/**/*.ts : For Step 4 - Implement contract registration for factory events using `contractRegister` above the handler to track dynamically created contracts: `Factory.EventName.contractRegister(({ event, context }) => { context.addContractName(event.params.contractAddress); });`

Applied to files:

  • scenarios/test_codegen/test/EventOrigin_test.res
  • scenarios/block_handler/src/handlers/BlockHandler.ts
  • codegenerator/cli/npm/envio/src/UserContext.res
  • scenarios/test_codegen/test/lib_tests/FetchState_test.res
📚 Learning: 2025-11-25T12:40:19.463Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: .cursor/rules/navigation.mdc:0-0
Timestamp: 2025-11-25T12:40:19.463Z
Learning: Applies to **/generated/src/Config.res : Generated config module must be named `Config.res` and convert environment variables to typed config, setting up persistence

Applied to files:

  • codegenerator/cli/npm/envio/src/Config.res
  • scenarios/block_handler/.gitignore
  • codegenerator/cli/npm/envio/src/EventProcessing.res
📚 Learning: 2025-12-04T12:13:23.231Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.231Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.ts : For entity creation patterns, always include all required fields in a single object literal and use `context.Entity.set(entity)` (without await). Update patterns should spread existing entity data and update only changed fields: `const updated = { ...existing, field: newValue }; context.Entity.set(updated);`

Applied to files:

  • codegenerator/cli/npm/envio/src/Config.res
  • codegenerator/cli/npm/envio/src/Envio.gen.ts
  • codegenerator/cli/npm/envio/src/Envio.res
  • codegenerator/cli/templates/dynamic/codegen/src/Generated.res.hbs
  • codegenerator/cli/npm/envio/src/LoadLayer.res
  • codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs
  • codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs
📚 Learning: 2025-12-04T12:12:49.534Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-12-04T12:12:49.534Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.{ts,js} : In Envio HyperIndex, use `entity_id` fields (e.g., `token_id: string`) instead of direct object references for entity relationships

Applied to files:

  • codegenerator/cli/npm/envio/src/Config.res
  • codegenerator/cli/npm/envio/src/Envio.gen.ts
  • codegenerator/cli/npm/envio/src/Envio.res
  • codegenerator/cli/npm/envio/solana.schema.json
  • codegenerator/cli/templates/dynamic/codegen/src/Generated.res.hbs
  • codegenerator/cli/templates/static/codegen/src/Index.res
  • codegenerator/cli/npm/envio/src/LoadLayer.res
  • codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs
  • codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs
📚 Learning: 2025-12-04T12:12:49.534Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-12-04T12:12:49.534Z
Learning: After any change to TypeScript files, run `pnpm tsc --noEmit` to ensure successful compilation

Applied to files:

  • scenarios/block_handler/tsconfig.json
  • codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs
📚 Learning: 2025-12-04T12:13:23.231Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.231Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/src/**/*.ts : For Step 3 - Refactor file structure to mirror the original subgraph EXACTLY using the same filenames, create separate handler files by contract (e.g., contract1.ts, contract2.ts) instead of a single EventHandlers.ts file, and move handlers from EventHandlers.ts to contract-specific files

Applied to files:

  • scenarios/block_handler/tsconfig.json
  • codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs
📚 Learning: 2025-12-04T12:12:49.534Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-12-04T12:12:49.534Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.{ts,js} : When updating existing entities in HyperIndex handlers, always use the spread operator for immutability since returned objects are read-only

Applied to files:

  • scenarios/block_handler/tsconfig.json
  • codegenerator/cli/npm/envio/src/Envio.gen.ts
  • codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs
  • codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs
📚 Learning: 2025-12-04T12:13:23.231Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.231Z
Learning: Applies to codegenerator/cli/templates/static/shared/{**/*.ts,**/schema.graphql} : Ensure database schema compatibility: verify that the types you're setting in code match the schema entity property types exactly. Compare with schema.graphql - for example, `Int!` in schema requires `number` in code, `BigInt!` requires `BigInt`, `BigDecimal!` requires `BigDecimal`

Applied to files:

  • scenarios/block_handler/tsconfig.json
  • codegenerator/cli/npm/envio/src/Envio.gen.ts
📚 Learning: 2025-12-04T12:13:23.231Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.231Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.ts : Always verify entity type field names match exactly with the generated entity types. For example, use `token0_id` not `token0`, and `transaction_id` not `transaction`. Run `pnpm tsc --noEmit` to catch type mismatches

Applied to files:

  • scenarios/block_handler/tsconfig.json
  • codegenerator/cli/npm/envio/src/Envio.gen.ts
  • codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs
📚 Learning: 2025-12-04T12:12:49.534Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-12-04T12:12:49.534Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.ts : Use `string | undefined` for optional string fields in Envio types, not `string | null`, as generated types are strict about null vs undefined

Applied to files:

  • scenarios/block_handler/tsconfig.json
  • codegenerator/cli/npm/envio/src/Envio.gen.ts
📚 Learning: 2025-12-04T12:12:49.534Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-12-04T12:12:49.534Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.{ts,js} : Import and use the Effect API (`S`, `createEffect`) from 'envio' package for external calls in HyperIndex handlers

Applied to files:

  • scenarios/block_handler/tsconfig.json
📚 Learning: 2025-12-04T12:13:23.231Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.231Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.ts : `derivedFrom` arrays in Envio are VIRTUAL fields that exist only when querying the API, not in handlers. You CANNOT access them in handlers (e.g., `transaction.mints` will not work). Use `context.Entity.getWhere.fieldName.eq(value)` to query related entities instead

Applied to files:

  • codegenerator/cli/npm/envio/src/Envio.gen.ts
  • codegenerator/cli/npm/envio/src/Envio.res
  • codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs
📚 Learning: 2025-12-04T12:13:23.231Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.231Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.ts : Import entity types from `generated/src/db/Entities.gen` for type annotations (e.g., `Pair_t`, `Token_t`), NOT from `generated` which exports contract handlers. Use the correct entity type imports to prevent TypeScript errors like 'refers to a value, but is being used as a type'

Applied to files:

  • codegenerator/cli/npm/envio/src/Envio.gen.ts
  • codegenerator/cli/templates/dynamic/codegen/src/Generated.res.hbs
  • codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs
📚 Learning: 2025-12-04T12:13:23.231Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.231Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.ts : All TypeScript handler and utility files must have proper async/await for database operations. Use `await` for `context.Entity.get()`, `context.Entity.getWhere().field.eq()` calls. Note: `context.Entity.set()` does NOT need `await` - it's synchronous

Applied to files:

  • codegenerator/cli/npm/envio/src/Envio.gen.ts
  • codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs
📚 Learning: 2025-12-04T12:13:23.231Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.231Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/schema.graphql : For Step 2 - Migrate GraphQL schema from TheGraph format to Envio format: remove `entity` decorators, convert `Bytes!` to `String!`, convert `ID!` to `ID!` (keep as is), and ensure ALL entity arrays have `derivedFrom(field: "fieldName")` directives to prevent 'EE211: Arrays of entities is unsupported' error

Applied to files:

  • codegenerator/cli/npm/envio/src/Envio.gen.ts
  • codegenerator/cli/npm/envio/src/Envio.res
  • codegenerator/cli/npm/envio/solana.schema.json
  • codegenerator/cli/Makefile
  • codegenerator/cli/npm/envio/src/LoadLayer.res
  • codegenerator/cli/npm/envio/evm.schema.json
  • codegenerator/cli/npm/envio/fuel.schema.json
  • codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs
📚 Learning: 2025-12-04T12:12:49.534Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-12-04T12:12:49.534Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.{ts,js} : Always cast timestamps to BigInt using `BigInt(event.block.timestamp)` instead of using raw timestamps from events

Applied to files:

  • codegenerator/cli/templates/static/codegen/src/ink/components/SyncETA.res
  • scenarios/block_handler/src/handlers/BlockHandler.ts
  • codegenerator/cli/templates/dynamic/codegen/src/TestHelpers_MockDb.res.hbs
📚 Learning: 2025-05-27T17:07:12.878Z
Learnt from: JonoPrest
Repo: enviodev/hyperindex PR: 555
File: scenarios/test_codegen/test/lib_tests/EntityHistory_test.res:631-659
Timestamp: 2025-05-27T17:07:12.878Z
Learning: In isolated tests for EntityHistory rollbacks with controlled mock data setup, the ordering of getRollbackDiff results is deterministic and doesn't require sorting before comparison with deepStrictEqual.

Applied to files:

  • scenarios/test_codegen/test/ReorgDetection_test.res
📚 Learning: 2025-12-04T12:13:23.231Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.231Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/schema.graphql : CRITICAL ENVIO REQUIREMENT: All entity arrays like `[Mint!]!` MUST have `derivedFrom` directives. Without this, codegen will fail with error 'EE211: Arrays of entities is unsupported'

Applied to files:

  • codegenerator/cli/npm/envio/solana.schema.json
  • codegenerator/cli/templates/dynamic/codegen/src/Generated.res.hbs
📚 Learning: 2025-12-04T12:12:49.534Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-12-04T12:12:49.534Z
Learning: After any change to `schema.graphql` or `config.yaml`, run `pnpm codegen`

Applied to files:

  • codegenerator/cli/Makefile
📚 Learning: 2025-11-25T12:40:19.463Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: .cursor/rules/navigation.mdc:0-0
Timestamp: 2025-11-25T12:40:19.463Z
Learning: Verify tests pass by running `pnpm rescript` compiler and `pnpm mocha` test runner

Applied to files:

  • codegenerator/cli/npm/envio/package.json.tmpl
  • codegenerator/cli/npm/envio/package.json
  • codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs
📚 Learning: 2025-12-04T12:12:49.534Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-12-04T12:12:49.534Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.graphql : NEVER use arrays of entities (e.g., `[Enter!]!` or `[User!]!`) in HyperIndex GraphQL schemas - use `entity_id` fields instead

Applied to files:

  • codegenerator/cli/templates/dynamic/codegen/src/Generated.res.hbs
📚 Learning: 2025-12-04T12:13:23.231Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.231Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/config.yaml : When using multichain indexing, ensure contract names in config.yaml are unique across all networks, place contract definitions in the global contracts section (not in network sections), and only define addresses for those contracts in network sections

Applied to files:

  • codegenerator/cli/src/config_parsing/validation.rs
  • codegenerator/cli/npm/envio/evm.schema.json
  • codegenerator/cli/npm/envio/fuel.schema.json
  • codegenerator/cli/src/cli_args/init_config.rs
  • codegenerator/cli/src/config_parsing/human_config.rs
📚 Learning: 2025-11-25T12:40:19.463Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: .cursor/rules/navigation.mdc:0-0
Timestamp: 2025-11-25T12:40:19.463Z
Learning: Applies to **/*.{test.res,spec.res} : Prefer public module APIs for testing in ReScript

Applied to files:

  • scenarios/test_codegen/test/lib_tests/SourceManager_test.res
  • codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs
📚 Learning: 2025-12-04T12:13:23.231Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.231Z
Learning: For multichain indexing, prefix all entity IDs with `event.chainId`: `${event.chainId}-${originalId}`, never hardcode `chainId = 1`, always use `event.chainId`, and use chain-specific Bundle IDs like `${chainId}-1` for accurate pricing per network

Applied to files:

  • codegenerator/cli/npm/envio/src/ChainManager.res
  • codegenerator/cli/npm/envio/src/ChainFetcher.res
📚 Learning: 2025-11-25T12:40:19.463Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: .cursor/rules/navigation.mdc:0-0
Timestamp: 2025-11-25T12:40:19.463Z
Learning: Config parsing pipeline follows: `human_config.rs` → `system_config.rs` → `hbs_templating/codegen_templates.rs`

Applied to files:

  • codegenerator/cli/src/config_parsing/graph_migration/mod.rs
  • codegenerator/cli/src/cli_args/init_config.rs
  • codegenerator/cli/src/config_parsing/system_config.rs
  • codegenerator/cli/src/config_parsing/human_config.rs
📚 Learning: 2025-12-04T12:13:23.231Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.231Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.ts : When accessing entity fields that represent relationships, use the `_id` suffix convention. For example, use `token0_id` not `token0` when storing relationships in entity types

Applied to files:

  • codegenerator/cli/npm/envio/src/LoadLayer.res
  • codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs
📚 Learning: 2025-12-04T12:12:49.534Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-12-04T12:12:49.534Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.graphql : Do not add the entity decorator to GraphQL schema types in HyperIndex

Applied to files:

  • codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs
📚 Learning: 2025-11-25T12:40:19.463Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: .cursor/rules/navigation.mdc:0-0
Timestamp: 2025-11-25T12:40:19.463Z
Learning: Applies to **/*.{test.res,spec.res} : Use `_only` to specify which tests to run in ReScript Mocha tests

Applied to files:

  • codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs
📚 Learning: 2025-11-25T12:40:19.463Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: .cursor/rules/navigation.mdc:0-0
Timestamp: 2025-11-25T12:40:19.463Z
Learning: Applies to codegenerator/cli/templates/static/**/*.res : Static ReScript files must be placed in `codegenerator/cli/templates/static/`

Applied to files:

  • codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs
📚 Learning: 2025-12-04T12:13:23.231Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.231Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.ts : For Step 6 - Final Migration Verification: Go through each handler and helper function systematically, comparing the logic line-by-line to the original subgraph implementation. Iterate multiple times until logic is completely correct, as first pass often misses subtle differences

Applied to files:

  • codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs
📚 Learning: 2025-12-04T12:12:49.534Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-12-04T12:12:49.534Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.{ts,js,yaml,yml} : Ensure case consistency when matching addresses in configuration objects, using lowercase keys to match `address.toLowerCase()` lookups

Applied to files:

  • codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs
📚 Learning: 2025-12-04T12:13:23.231Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.231Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.ts : MAINTAIN BigDecimal precision from the original subgraph. Use BigDecimal and BigInt types for financial calculations, never simplify to JavaScript number type which loses precision. Always use BigDecimal constants (ZERO_BD, ONE_BD) and BigInt constants (ZERO_BI, ONE_BI)

Applied to files:

  • scenarios/test_codegen/test/schema_types/BigDecimal_test.res
🧬 Code graph analysis (1)
codegenerator/cli/src/config_parsing/graph_migration/mod.rs (1)
codegenerator/cli/src/config_parsing/contract_import/converters.rs (2)
  • new (17-27)
  • new (98-103)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test

@DZakh DZakh requested a review from JonoPrest December 8, 2025 09:45
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
codegenerator/cli/npm/envio/src/sources/SourceManager.res (1)

3-3: Typo in enum variant: "Querieng" → "Querying".

-type sourceManagerStatus = Idle | WaitingForNewBlock | Querieng
+type sourceManagerStatus = Idle | WaitingForNewBlock | Querying

Note: This will require updating all references to Querieng throughout the codebase (e.g., lines 82, 138).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d32f9d9 and fec42d3.

📒 Files selected for processing (5)
  • .github/workflows/build_and_test.yml (0 hunks)
  • codegenerator/cli/npm/envio/src/GlobalState.res (14 hunks)
  • codegenerator/cli/npm/envio/src/sources/SourceManager.res (9 hunks)
  • scenarios/block_handler/src/handlers/BlockHandler.ts (1 hunks)
  • scenarios/test_codegen/package.json (1 hunks)
💤 Files with no reviewable changes (1)
  • .github/workflows/build_and_test.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • scenarios/block_handler/src/handlers/BlockHandler.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{res,resi}

📄 CodeRabbit inference engine (.cursor/rules/rescript.mdc)

**/*.{res,resi}: Always use ReScript 11 documentation
Never suggest ReasonML syntax
Never use [| item |] to create an array. Use [ item ] instead
Must always use = for setting value to a field. Use := only for ref values created using ref function
Use records when working with structured data, and objects to conveniently pass payload data between functions
Never use %raw to access object fields if you know the type

Files:

  • codegenerator/cli/npm/envio/src/sources/SourceManager.res
  • codegenerator/cli/npm/envio/src/GlobalState.res
🧠 Learnings (10)
📓 Common learnings
Learnt from: nikbhintade
Repo: enviodev/hyperindex PR: 822
File: codegenerator/cli/templates/static/multichain_indexer_template/typescript/src/EventHandlers.ts:10-18
Timestamp: 2025-11-19T05:36:33.975Z
Learning: The multichain_indexer_template in codegenerator/cli/templates/static/ is designed to demonstrate multichain indexing features. It intentionally uses minimal event parameters (e.g., only capturing the `pool` address from Uniswap V3 PoolCreated events) to keep the focus on multichain functionality rather than comprehensive event indexing.
📚 Learning: 2025-12-04T12:12:49.547Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-12-04T12:12:49.547Z
Learning: After any change to TypeScript files, run `pnpm tsc --noEmit` to ensure successful compilation

Applied to files:

  • scenarios/test_codegen/package.json
📚 Learning: 2025-11-25T12:40:19.463Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: .cursor/rules/navigation.mdc:0-0
Timestamp: 2025-11-25T12:40:19.463Z
Learning: Verify tests pass by running `pnpm rescript` compiler and `pnpm mocha` test runner

Applied to files:

  • scenarios/test_codegen/package.json
📚 Learning: 2025-12-04T12:13:23.246Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.246Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.ts : Always verify entity type field names match exactly with the generated entity types. For example, use `token0_id` not `token0`, and `transaction_id` not `transaction`. Run `pnpm tsc --noEmit` to catch type mismatches

Applied to files:

  • scenarios/test_codegen/package.json
📚 Learning: 2025-12-04T12:13:23.246Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.246Z
Learning: Applies to codegenerator/cli/templates/static/shared/{**/*.ts,**/schema.graphql} : Ensure database schema compatibility: verify that the types you're setting in code match the schema entity property types exactly. Compare with schema.graphql - for example, `Int!` in schema requires `number` in code, `BigInt!` requires `BigInt`, `BigDecimal!` requires `BigDecimal`

Applied to files:

  • scenarios/test_codegen/package.json
📚 Learning: 2025-12-04T12:13:23.246Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.246Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/*.ts : For Step 6 - Final Migration Verification: Go through each handler and helper function systematically, comparing the logic line-by-line to the original subgraph implementation. Iterate multiple times until logic is completely correct, as first pass often misses subtle differences

Applied to files:

  • scenarios/test_codegen/package.json
📚 Learning: 2025-12-04T12:13:23.246Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.246Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/src/**/*.ts : For Step 3 - Refactor file structure to mirror the original subgraph EXACTLY using the same filenames, create separate handler files by contract (e.g., contract1.ts, contract2.ts) instead of a single EventHandlers.ts file, and move handlers from EventHandlers.ts to contract-specific files

Applied to files:

  • scenarios/test_codegen/package.json
📚 Learning: 2025-11-25T12:40:19.463Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: .cursor/rules/navigation.mdc:0-0
Timestamp: 2025-11-25T12:40:19.463Z
Learning: Applies to **/*.{test.res,spec.res} : Prefer public module APIs for testing in ReScript

Applied to files:

  • scenarios/test_codegen/package.json
📚 Learning: 2025-11-25T12:40:19.463Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: .cursor/rules/navigation.mdc:0-0
Timestamp: 2025-11-25T12:40:19.463Z
Learning: Applies to **/*.{test.res,spec.res} : Use `_only` to specify which tests to run in ReScript Mocha tests

Applied to files:

  • scenarios/test_codegen/package.json
📚 Learning: 2025-12-04T12:12:49.547Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-12-04T12:12:49.547Z
Learning: Whitelist the following commands for HyperIndex development: `pnpm codegen` and `pnpm tsc --noEmit`

Applied to files:

  • scenarios/test_codegen/package.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test
🔇 Additional comments (11)
scenarios/test_codegen/package.json (1)

13-13: Add TypeScript type-check to test pipeline.

The addition of tsc --noEmit before Mocha is a good practice that aligns with the broader PR refactoring and ensures type correctness early in the test pipeline. This catches type issues before runtime, which is especially valuable given the configuration/schema changes in this PR. The tsconfig.json file exists in the directory with proper configuration, so the tsc command will execute correctly.

codegenerator/cli/npm/envio/src/sources/SourceManager.res (4)

102-124: The knownHeight rename is applied consistently.

The parameter rename from currentBlockHeight to knownHeight is correctly propagated through fetchNext, including the waitForNewBlock call and onNewBlock callback.


162-211: Height polling logic correctly updated to use knownHeight.

The getSourceNewHeight function properly uses knownHeight in the while-loop condition and comparison, maintaining the original polling semantics.


214-255: waitForNewBlock correctly integrates knownHeight with source selection logic.

The conditional logic for including Live sources only after initial sync (knownHeight === 0 check) is sensible and well-commented.


381-391: Query execution correctly passes knownHeight to getItemsOrThrow.

The parameter is consistently renamed in the call site.

codegenerator/cli/npm/envio/src/GlobalState.res (6)

115-120: LGTM: Action type definitions correctly updated.

The action type definitions have been properly updated to use knownHeight instead of currentBlockHeight. The field names are clear and consistent.


347-382: LGTM: Response validation correctly uses knownHeight.

The validation logic properly destructures knownHeight from the response and uses it for:

  • Prometheus metrics updates
  • Reorg guard registration
  • Comparison with the chain fetcher's current known height

The logic is sound and the naming is more accurate than the previous currentBlockHeight.


460-475: LGTM: Query result submission correctly threaded.

The knownHeight parameter is properly passed through to ChainFetcher.handleQueryResult. The function signature and call site are consistent.


591-631: LGTM: State update logic correctly handles knownHeight.

The FinishWaitingForNewBlock action handler properly:

  1. Updates fetch state with the new knownHeight (lines 595-596)
  2. Checks reorg threshold readiness using the updated fetchers (lines 612-616)
  3. Dispatches appropriate follow-up actions including ProcessEventBatch (lines 628, 630)

The comment at line 626 about block handlers aligns well with the PR objective of supporting "Block Handlers without events."


832-961: LGTM: InMemoryStore and entity pruning use correct data source.

The entity iteration for pruning (lines 832, 838) and InMemoryStore initialization (line 961) correctly reference state.indexer.persistence.allEntities, which aligns with the updated data flow structure.


788-808: External module functions have been properly updated to accept knownHeight.

The callbacks in GlobalState.res correctly pass knownHeight to:

  • waitForNewBlock (line 792)
  • onNewBlock via the FinishWaitingForNewBlock action (line 793)
  • executeQuery with ~knownHeight=fetchState.knownHeight (line 799)

Verification confirms that SourceManager.waitForNewBlock (line 214) and SourceManager.executeQuery (line 344) have both been updated to accept the ~knownHeight parameter. The code changes are correct.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3898a47 and 79398b2.

📒 Files selected for processing (1)
  • scenarios/test_codegen/test/lib_tests/FetchState_test.res (54 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{res,resi}

📄 CodeRabbit inference engine (.cursor/rules/rescript.mdc)

**/*.{res,resi}: Always use ReScript 11 documentation
Never suggest ReasonML syntax
Never use [| item |] to create an array. Use [ item ] instead
Must always use = for setting value to a field. Use := only for ref values created using ref function
Use records when working with structured data, and objects to conveniently pass payload data between functions
Never use %raw to access object fields if you know the type

Files:

  • scenarios/test_codegen/test/lib_tests/FetchState_test.res
🧠 Learnings (2)
📓 Common learnings
Learnt from: nikbhintade
Repo: enviodev/hyperindex PR: 822
File: codegenerator/cli/templates/static/multichain_indexer_template/typescript/src/EventHandlers.ts:10-18
Timestamp: 2025-11-19T05:36:33.975Z
Learning: The multichain_indexer_template in codegenerator/cli/templates/static/ is designed to demonstrate multichain indexing features. It intentionally uses minimal event parameters (e.g., only capturing the `pool` address from Uniswap V3 PoolCreated events) to keep the focus on multichain functionality rather than comprehensive event indexing.
📚 Learning: 2025-12-04T12:13:23.246Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: codegenerator/cli/templates/static/shared/.cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-12-04T12:13:23.246Z
Learning: Applies to codegenerator/cli/templates/static/shared/**/src/**/*.ts : For Step 4 - Implement contract registration for factory events using `contractRegister` above the handler to track dynamically created contracts: `Factory.EventName.contractRegister(({ event, context }) => { context.addContractName(event.params.contractAddress); });`

Applied to files:

  • scenarios/test_codegen/test/lib_tests/FetchState_test.res
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test
🔇 Additional comments (3)
scenarios/test_codegen/test/lib_tests/FetchState_test.res (3)

6-6: LGTM: knownHeight threading and contractName string conversion.

The mechanical changes replacing currentBlockHeight with knownHeight throughout the test file are consistent and align with the PR objectives. The conversion of contractName to a plain string field (removing the enum) is also correct.

Also applies to: 48-56, 113-114, 179-179, 195-195


199-199: LGTM: Error message updated to reflect onBlock handler support.

The error message now correctly mentions that onBlock handlers are a valid alternative to events or contracts, which aligns with the PR's goal of supporting Block Handler only indexers.


2981-3082: LGTM: Test suite validates Block Handler only indexer feature.

The new test suite correctly validates the core PR feature of supporting indexers with only block handlers and no events. The test logic is sound:

  • Creates FetchState with no event configs but with onBlockConfig
  • Verifies getNextQuery returns WaitingForNewBlock when knownHeight is 0
  • Updates knownHeight and verifies buffer is populated with block items
  • Validates expected block numbers and state transitions

The test provides good coverage for this new capability.

chainFetcher.reorgDetection->ReorgDetection.getThresholdBlockNumbersBelowBlock(
~blockNumber=reorgBlockNumber,
~currentBlockHeight=chainFetcher.currentBlockHeight,
~knownHeight=chainFetcher.fetchState.knownHeight,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is knownHeight essentially current height?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that known height is better since we have multiple sources and also source might have a different height than the one we know in hyperindex. This is why I decided to use the name. It's also internal only

};

chain.contracts.push(contract);
chain.contracts.get_or_insert_with(Vec::new).push(contract);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try run cargo clippy, it will likely suggest you use get_or_default().push(contract) or something like that.

Comment on lines +79 to +85
#[serde(skip_serializing_if = "Option::is_none")]
#[schemars(
description = "Optional relative path to handlers directory for auto-loading. Defaults \
to 'src/handlers' if not specified."
)]
pub handlers: Option<String>,
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A suggestion here, since we are adding new config.

I've found its simpler to have non optional fieilds with defaults like this:
https://github.com/enviodev/hypersync-client-rust/blob/eedeed4544ba44219d5a22e8f319b93e157e96c3/hypersync-client/src/config.rs#L17-L34

And then you can still have skip_serializing_if functions that check if it matches the default. Means the schema gets the actual defaults and there's less parsing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I don't want to have defaults on the rust side. The goal is to serialize the config to json at some point and parse it in ReScript side


/// Base configuration fields shared across all ecosystems
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, JsonSchema)]
pub struct BaseConfig {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth using this in Evm and fuel config?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it in the next pr. I didn't noticed that it didn't happen here

{{/each}}

let allEnums = ([
ContractType.config->Table.fromGenericEnumConfig,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we're just using strings in postgres for this now? I'm sure it's fine 👍🏼, depending on where its used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, from 2.30 or something the enum is unused

Copy link
Collaborator

@JonoPrest JonoPrest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool 👍🏼, non blocking comments only.

Just want to understand is knownHeight the source's height?

Wondering if sourceHeight is a better name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants