Skip to content

Conversation

@nikbhintade
Copy link
Member

@nikbhintade nikbhintade commented Nov 20, 2025

Summary by CodeRabbit

  • New Features

    • Added a "Topic Filtering" template for EVM projects.
    • Starter kit includes ERC20 Transfer handlers that efficiently capture mint/burn transfers via event filtering.
    • Includes GraphQL schema and TypeScript project config for quick local development and deployment.
  • Documentation

    • CLI help updated to list the new template option.
    • Template includes example environment file and repository ignore rules for easier setup.

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

@nikbhintade nikbhintade self-assigned this Nov 20, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 20, 2025

Walkthrough

Adds a new "Topic Filtering" template: registers a Template variant, maps it to a template directory, and adds a full TypeScript template (config, schema, tsconfig, .env example, .gitignore) including an ERC20 Transfer event handler.

Changes

Cohort / File(s) Summary
Template registration
codegenerator/cli/src/cli_args/init_config.rs, codegenerator/cli/src/template_dirs.rs
Added evm::Template::TopicFiltering (serialized as "Feature: Topic Filtering") and a match arm mapping it to the "topic_filtering" directory name.
Template files — shared
codegenerator/cli/templates/static/topic_filtering_template/shared/{.env.example,.gitignore}, codegenerator/cli/templates/static/topic_filtering_template/shared/schema.graphql
New .env.example with ENVIO_API_TOKEN placeholder, .gitignore with common ignores, and GraphQL Transfer type with fields id, amount, from, to, contract.
Template files — typescript config
codegenerator/cli/templates/static/topic_filtering_template/typescript/{config.yaml,tsconfig.json}
New config.yaml describing mainnet, an ERC20 contract, Transfer event filter, unordered_multichain_mode and preload_handlers; new tsconfig.json for the template project.
Template files — handler
codegenerator/cli/templates/static/topic_filtering_template/typescript/src/handlers/ERC20.ts
New TypeScript handler registering a Transfer event handler that builds a unique ID and maps event data to a transfer record; applies filters for zero-address (mint/burn) cases.
Documentation
codegenerator/cli/CommandLineHelp.md
Added topic-filtering as an available init template option.

Sequence Diagram(s)

sequenceDiagram
  participant Chain as Blockchain
  participant Indexer as Indexer Runtime
  participant Handler as ERC20 Handler (template)
  participant Store as Graph Store

  Note over Chain,Indexer: Event emitted on chain
  Chain->>Indexer: Push/log event (Transfer)
  alt Event matches template filter
    Indexer->>Handler: Invoke Transfer handler (with event, metadata)
    Handler->>Store: Upsert `transfer` record (id, amount, from, to, contract)
    Note right of Store: Success/write persisted
  else Event filtered out
    Indexer-->>Handler: Not invoked
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review focus:
    • Ensure TopicFiltering enum serialization string matches CLI help mappings.
    • Confirm template_dirs mapping uses the correct directory name topic_filtering.
    • Validate ERC20.ts handler builds stable unique IDs and maps types consistent with schema.graphql and config.yaml.
    • Quick skim of .gitignore, .env.example, and tsconfig.json for obvious issues.

Poem

🐰 A rabbit taps keys in delight,
A topic filter springs to light.
Transfers caught, records made bright,
Templates hop into the night. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: addition of a Topic Filtering template feature as part of a multi-template implementation series.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 nb/topic-filtering-template

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f46d274 and 8ac76bf.

📒 Files selected for processing (1)
  • codegenerator/cli/src/cli_args/init_config.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • codegenerator/cli/src/cli_args/init_config.rs
⏰ 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

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

🧹 Nitpick comments (1)
codegenerator/cli/templates/static/topic_filtering_template/typescript/src/EventHandlers.ts (1)

5-26: Handler correctly demonstrates topic filtering, but consider adding a usage warning.

The implementation correctly demonstrates topic filtering with wildcard mode and event filters. However, this configuration will index ALL ERC20 mints and burns across ALL contracts on Ethereum mainnet, which could result in very high data volumes.

Based on learnings that templates are designed to demonstrate features with intentionally minimal scope, this is appropriate for a template. However, users might benefit from an inline comment explaining the data volume implications for production use.

Consider adding a comment above the handler:

+// WARNING: This configuration indexes ALL ERC20 mints/burns across ALL contracts.
+// For production use, consider narrowing the scope by:
+// - Removing wildcard to specify contract addresses
+// - Adjusting eventFilters to match your specific use case
+// - Using a more recent start_block to reduce historical data
 ERC20.Transfer.handler(
   async ({ event, context }) => {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3326be7 and c5524e9.

📒 Files selected for processing (8)
  • codegenerator/cli/src/cli_args/init_config.rs (1 hunks)
  • codegenerator/cli/src/template_dirs.rs (1 hunks)
  • codegenerator/cli/templates/static/topic_filtering_template/shared/.env.example (1 hunks)
  • codegenerator/cli/templates/static/topic_filtering_template/shared/.gitignore (1 hunks)
  • codegenerator/cli/templates/static/topic_filtering_template/shared/schema.graphql (1 hunks)
  • codegenerator/cli/templates/static/topic_filtering_template/typescript/config.yaml (1 hunks)
  • codegenerator/cli/templates/static/topic_filtering_template/typescript/src/EventHandlers.ts (1 hunks)
  • codegenerator/cli/templates/static/topic_filtering_template/typescript/tsconfig.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
codegenerator/cli/**

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

The Rust CLI lives in codegenerator/cli

Files:

  • codegenerator/cli/templates/static/topic_filtering_template/shared/schema.graphql
  • codegenerator/cli/templates/static/topic_filtering_template/typescript/tsconfig.json
  • codegenerator/cli/src/cli_args/init_config.rs
  • codegenerator/cli/templates/static/topic_filtering_template/typescript/config.yaml
  • codegenerator/cli/templates/static/topic_filtering_template/typescript/src/EventHandlers.ts
  • codegenerator/cli/src/template_dirs.rs
🧠 Learnings (5)
📚 Learning: 2025-10-21T16:31:22.127Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: .cursor/rules/navigation.mdc:0-0
Timestamp: 2025-10-21T16:31:22.127Z
Learning: Compiled .js artifacts can be ignored

Applied to files:

  • codegenerator/cli/templates/static/topic_filtering_template/shared/.gitignore
📚 Learning: 2025-10-21T16:31:22.127Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: .cursor/rules/navigation.mdc:0-0
Timestamp: 2025-10-21T16:31:22.127Z
Learning: Applies to codegenerator/cli/templates/static/**/*.res : Static templates are raw ReScript files copied verbatim under codegenerator/cli/templates/static

Applied to files:

  • codegenerator/cli/templates/static/topic_filtering_template/shared/.gitignore
  • codegenerator/cli/templates/static/topic_filtering_template/typescript/tsconfig.json
📚 Learning: 2025-10-21T16:31:22.127Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: .cursor/rules/navigation.mdc:0-0
Timestamp: 2025-10-21T16:31:22.127Z
Learning: Applies to **/*.res : Prefer reading ReScript .res modules directly

Applied to files:

  • codegenerator/cli/templates/static/topic_filtering_template/shared/.gitignore
📚 Learning: 2025-10-21T16:31:22.127Z
Learnt from: CR
Repo: enviodev/hyperindex PR: 0
File: .cursor/rules/navigation.mdc:0-0
Timestamp: 2025-10-21T16:31:22.127Z
Learning: Applies to codegenerator/cli/src/hbs_templating/codegen_templates.rs : hbs_templating/codegen_templates.rs feeds templates

Applied to files:

  • codegenerator/cli/src/cli_args/init_config.rs
  • codegenerator/cli/src/template_dirs.rs
📚 Learning: 2025-11-19T05:36:33.975Z
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.

Applied to files:

  • codegenerator/cli/templates/static/topic_filtering_template/typescript/config.yaml
🧬 Code graph analysis (1)
codegenerator/cli/src/cli_args/init_config.rs (2)
codegenerator/cli/src/config_parsing/entity_parsing.rs (2)
  • serialize (1181-1186)
  • serialize (1332-1337)
codegenerator/cli/src/rescript_types.rs (1)
  • serialize (703-709)
🪛 dotenv-linter (4.0.0)
codegenerator/cli/templates/static/topic_filtering_template/shared/.env.example

[warning] 2-2: [QuoteCharacter] The value has quote characters (', ")

(QuoteCharacter)

⏰ 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 (6)
codegenerator/cli/templates/static/topic_filtering_template/typescript/tsconfig.json (1)

1-21: LGTM!

The TypeScript configuration is well-structured with appropriate compiler options for blockchain development, including es2020 target for BigInt support and strict type checking enabled.

codegenerator/cli/templates/static/topic_filtering_template/shared/.gitignore (1)

1-34: LGTM!

The .gitignore file provides comprehensive coverage of build artifacts, temporary files, dependencies, and sensitive files (like .env). The inclusion of ReScript-specific patterns aligns with the codebase conventions.

codegenerator/cli/templates/static/topic_filtering_template/typescript/config.yaml (1)

1-15: LGTM!

The configuration correctly demonstrates the Topic Filtering feature with a standard ERC20 Transfer event. The event signature is accurate, and the multichain mode settings are appropriately configured.

codegenerator/cli/src/cli_args/init_config.rs (1)

33-34: LGTM!

The new TopicFiltering variant is correctly added to the Template enum with appropriate Strum serialization, following the established pattern.

codegenerator/cli/src/template_dirs.rs (1)

20-20: LGTM!

The template directory mapping correctly follows the established pattern and maps to the appropriate directory structure.

codegenerator/cli/templates/static/topic_filtering_template/shared/schema.graphql (1)

1-12: LGTM!

The GraphQL schema is well-defined with clear field types and helpful comments. The Transfer type correctly captures all relevant data from ERC20 transfer events.

@nikbhintade nikbhintade changed the title Topic Filtering Template Topic Filtering Template (Template 4/6) Nov 20, 2025
@nikbhintade nikbhintade requested a review from DZakh November 20, 2025 10:50
Copy link
Member

@DZakh DZakh left a comment

Choose a reason for hiding this comment

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

Looks good, the same comments as for contract factory pr

Comment on lines +33 to +34
#[strum(serialize = "Feature: Topic Filtering")]
TopicFiltering,
Copy link
Member

Choose a reason for hiding this comment

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

FeatureTopicFilter?

Copy link
Member

Choose a reason for hiding this comment

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

Just a suggestion

Copy link
Member Author

Choose a reason for hiding this comment

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

@DZakh is that for enum value?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

Comment on lines +3 to +25
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";

ERC20.Transfer.handler(
async ({ event, context }) => {
context.Transfer.set({
id: `${event.chainId}_${event.block.number}_${event.logIndex}`,
amount: event.params.value,
from: event.params.from,
to: event.params.to,
contract: event.srcAddress,
});
},
{
wildcard: true,
eventFilters: [
{
from: ZERO_ADDRESS,
},
{
to: ZERO_ADDRESS,
},
],
}
Copy link
Member

Choose a reason for hiding this comment

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

I want to make the example multichain and show how it's possible to use chainId for filters as well.

https://docs.envio.dev/docs/HyperIndex/wildcard-indexing#different-filters-per-network

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I will update it. Will update README accordingly too.

updated handler file name according to new naming convention
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: 0

🧹 Nitpick comments (1)
codegenerator/cli/templates/static/topic_filtering_template/typescript/src/handlers/ERC20.ts (1)

5-26: Nice implementation of topic filtering for mint/burn scenarios.

The handler correctly demonstrates topic filtering by using indexed parameters (from and to) in the event filters. The wildcard mode appropriately allows matching Transfer events from any ERC20 contract, while the filters restrict to mint (from zero address) and burn (to zero address) operations. The ID construction using chainId, block number, and logIndex is suitable for multichain scenarios.

Optional enhancement for educational clarity:

Consider adding brief comments to explain the filtering logic for template users:

 ERC20.Transfer.handler(
   async ({ event, context }) => {
     context.Transfer.set({
       id: `${event.chainId}_${event.block.number}_${event.logIndex}`,
       amount: event.params.value,
       from: event.params.from,
       to: event.params.to,
       contract: event.srcAddress,
     });
   },
   {
     wildcard: true,
+    // Filter for mint and burn events only
     eventFilters: [
       {
-        from: ZERO_ADDRESS,
+        from: ZERO_ADDRESS, // Mints: tokens created from zero address
       },
       {
-        to: ZERO_ADDRESS,
+        to: ZERO_ADDRESS, // Burns: tokens destroyed to zero address
       },
     ],
   }
 );
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c5524e9 and f46d274.

📒 Files selected for processing (3)
  • codegenerator/cli/CommandLineHelp.md (1 hunks)
  • codegenerator/cli/templates/static/topic_filtering_template/typescript/config.yaml (1 hunks)
  • codegenerator/cli/templates/static/topic_filtering_template/typescript/src/handlers/ERC20.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • codegenerator/cli/CommandLineHelp.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • codegenerator/cli/templates/static/topic_filtering_template/typescript/config.yaml
🧰 Additional context used
📓 Path-based instructions (1)
codegenerator/cli/**

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

The Rust CLI lives in codegenerator/cli

Files:

  • codegenerator/cli/templates/static/topic_filtering_template/typescript/src/handlers/ERC20.ts
🧠 Learnings (1)
📚 Learning: 2025-11-19T05:36:33.975Z
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.

Applied to files:

  • codegenerator/cli/templates/static/topic_filtering_template/typescript/src/handlers/ERC20.ts
⏰ 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 (1)
codegenerator/cli/templates/static/topic_filtering_template/typescript/src/handlers/ERC20.ts (1)

1-3: LGTM!

The import and zero address constant are correctly defined. The constant will be used appropriately in the event filters below.

match self {
evm::Template::Greeter => "greeter",
evm::Template::Erc20 => "erc20",
evm::Template::TopicFiltering => "topic_filtering",
Copy link
Member

Choose a reason for hiding this comment

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

It'd be nice to have them called similar to enums in init cli - feature_factory, feature_filter, etc

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