-
Notifications
You must be signed in to change notification settings - Fork 32
Topic Filtering Template (Template 4/6) #829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughAdds 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
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
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. Comment |
There was a problem hiding this 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
📒 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.graphqlcodegenerator/cli/templates/static/topic_filtering_template/typescript/tsconfig.jsoncodegenerator/cli/src/cli_args/init_config.rscodegenerator/cli/templates/static/topic_filtering_template/typescript/config.yamlcodegenerator/cli/templates/static/topic_filtering_template/typescript/src/EventHandlers.tscodegenerator/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/.gitignorecodegenerator/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.rscodegenerator/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.
codegenerator/cli/templates/static/topic_filtering_template/shared/.env.example
Show resolved
Hide resolved
DZakh
left a comment
There was a problem hiding this 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
| #[strum(serialize = "Feature: Topic Filtering")] | ||
| TopicFiltering, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FeatureTopicFilter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a suggestion
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
| 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, | ||
| }, | ||
| ], | ||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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 (
fromandto) 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
📒 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", |
There was a problem hiding this comment.
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
Summary by CodeRabbit
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.