Skip to content

Topic Filter Template#1078

Open
nikbhintade wants to merge 5 commits into
mainfrom
nb/topic-filter-template
Open

Topic Filter Template#1078
nikbhintade wants to merge 5 commits into
mainfrom
nb/topic-filter-template

Conversation

@nikbhintade

@nikbhintade nikbhintade commented Apr 2, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added a "Topic Filter" template option in the CLI init flow, including a TypeScript template with wildcard contract support for Ethereum and Polygon and a sample handler.
  • Documentation

    • Added README, example .env, .gitignore, YAML config, GraphQL Transfer schema, and TypeScript project config; updated CLI help to list the new template.
  • Tests

    • Added unit tests validating topic-filter behavior and included the template in end-to-end template tests.

@nikbhintade nikbhintade self-assigned this Apr 2, 2026
@coderabbitai

coderabbitai Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 65b6d745-ef79-4eee-9239-dd7d51d63b9e

📥 Commits

Reviewing files that changed from the base of the PR and between 9011de0 and b507053.

📒 Files selected for processing (3)
  • packages/cli/templates/static/feature_filter_template/typescript/config.yaml
  • packages/cli/templates/static/feature_filter_template/typescript/src/handlers/ERC20.ts
  • packages/cli/templates/static/feature_filter_template/typescript/src/indexer.test.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/cli/templates/static/feature_filter_template/typescript/src/indexer.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/cli/templates/static/feature_filter_template/typescript/src/handlers/ERC20.ts
  • packages/cli/templates/static/feature_filter_template/typescript/config.yaml

📝 Walkthrough

Walkthrough

Adds a new EVM template "Feature: Topic Filter", wires it into CLI/init (args and interactive), maps it to a template directory, supplies TypeScript template scaffolding (schema, config, handler, tests, docs, env/gitignore), and registers the template in e2e tests. (47 words)

Changes

Cohort / File(s) Summary
CLI Template Registration
packages/cli/src/cli_args/init_config.rs, packages/cli/src/cli_args/interactive_init/mod.rs, packages/cli/src/template_dirs.rs
Added FeatureTopicFilter template variant/option (serializes as Feature: Topic Filtering), included in interactive EVM options and mapped to template dir feature_filter.
Template Shared Files
packages/cli/templates/static/feature_filter_template/shared/.env.example, packages/cli/templates/static/feature_filter_template/shared/.gitignore, packages/cli/templates/static/feature_filter_template/shared/README.md, packages/cli/templates/static/feature_filter_template/shared/schema.graphql
Added shared assets: .env.example (ENVIO_API_TOKEN), .gitignore, README describing wildcard & topic filtering, and GraphQL Transfer type.
Template TypeScript Config & Metadata
packages/cli/templates/static/feature_filter_template/typescript/config.yaml, packages/cli/templates/static/feature_filter_template/typescript/tsconfig.json
Added template config.yaml declaring ERC20 Transfer event and chains (Mainnet, Polygon) and TypeScript tsconfig.json.
Template Implementation & Tests
packages/cli/templates/static/feature_filter_template/typescript/src/handlers/ERC20.ts, packages/cli/templates/static/feature_filter_template/typescript/src/indexer.test.ts
Added ERC20 handler using wildcard: true with eventFilters (mint/burn via ZERO_ADDRESS) writing Transfer entities, plus Vitest suite asserting mint/burn indexing and exclusion of regular transfers.
E2E Test Registration
packages/e2e-tests/src/template-tests/templates.test.ts
Registered new evm-feature-filter template in e2e TEMPLATES with hasTests: true so CI runs init/install/codegen/tests.
Docs / CLI Help
packages/cli/CommandLineHelp.md
Updated CLI help to include feature-topic-filter as a valid envio init -t value.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Dev (user)
    participant CLI as CLI
    participant Scaffold as Template Scaffold
    participant Indexer as Indexer Runtime
    participant Envio as Envio API/Store

    Dev->>CLI: run `envio init -t feature-topic-filter -l typescript`
    CLI->>Scaffold: create `feature_filter` files (config, handlers, schema, tests)
    Dev->>CLI: run `pnpm codegen` / `pnpm dev` / tests
    CLI->>Indexer: start indexer with template config (wildcard + eventFilters)
    Indexer->>Envio: subscribe/process chain events using topic filters
    Indexer->>Envio: write Transfer records to GraphQL store
    Dev->>Envio: query results via GraphQL Playground
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • DZakh
  • JonoPrest
  • JasoonS

Poem

🐰 A topic filter hops into view,
Wildcards listen where the logs ensue,
Mints and burns caught by chain and cue,
Handlers nibble data, tests chase the clue,
Hooray — indexers hum, and green checks too! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Topic Filter Template' directly summarizes the main change: adding a new template for topic filtering to the CLI, which is evident across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nb/topic-filter-template

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
packages/cli/templates/static/feature_filter_template/shared/.gitignore (1)

1-36: Deduplicate repeated ignore patterns.

*.obj and *.annot are listed twice; trimming duplicates keeps this file easier to maintain.

Suggested cleanup
 *.exe
 *.obj
 *.out
 *.compile
 *.native
 *.byte
 *.cmo
 *.annot
 *.cmi
 *.cmx
 *.cmt
 *.cmti
 *.cma
 *.a
 *.cmxa
-*.obj
 *~
-*.annot
 *.cmj
 *.bak
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/cli/templates/static/feature_filter_template/shared/.gitignore`
around lines 1 - 36, The .gitignore contains duplicate patterns; remove the
repeated entries for "*.obj" and "*.annot" so each ignore pattern appears only
once in the shared .gitignore template (look for the "*.obj" and "*.annot"
entries in the file and remove the duplicates while preserving one occurrence of
each).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/cli/templates/static/feature_filter_template/shared/.env.example`:
- Line 2: The .env.example line ENVIO_API_TOKEN currently uses surrounding
quotes which triggers dotenv-linter QuoteCharacter; open the template file and
remove the surrounding double quotes so the placeholder reads
ENVIO_API_TOKEN=<YOUR-API-TOKEN> (no quotes or extra whitespace), save and
commit the change so the placeholder satisfies dotenv-linter.

In `@packages/cli/templates/static/feature_filter_template/shared/README.md`:
- Line 81: The Markdown link in the README line "While the indexer is running,
visit the Envio Console([https://envio.dev/console](https://envio.dev/console))
to open the GraphQL Playground and query your indexed data." is malformed;
replace the duplicated form with a proper Markdown link like "While the indexer
is running, visit the [Envio Console](https://envio.dev/console) to open the
GraphQL Playground and query your indexed data." by editing that sentence in the
README (search for the exact fragment "Envio
Console([https://envio.dev/console](https://envio.dev/console))").

In
`@packages/cli/templates/static/feature_filter_template/typescript/src/indexer.test.ts`:
- Around line 71-81: The expectedTransfer in the burn test uses contract:
ZERO_ADDRESS which doesn't match what the handler actually saves; update the
expectation to use the real contract value the handler stores (e.g., the
token/contract address used in the test event) instead of ZERO_ADDRESS so that
the object compared in indexer.Transfer.getOrThrow(FIRST_EVENT_ID) matches;
locate the expectedTransfer declaration and replace contract: ZERO_ADDRESS with
the correct contract identifier used when creating the burn event (or derive it
from the test's token/contract variable).

---

Nitpick comments:
In `@packages/cli/templates/static/feature_filter_template/shared/.gitignore`:
- Around line 1-36: The .gitignore contains duplicate patterns; remove the
repeated entries for "*.obj" and "*.annot" so each ignore pattern appears only
once in the shared .gitignore template (look for the "*.obj" and "*.annot"
entries in the file and remove the duplicates while preserving one occurrence of
each).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 91fc5056-6af6-41e7-b36a-0e55a70d9b40

📥 Commits

Reviewing files that changed from the base of the PR and between 89ef12d and bcc1c90.

📒 Files selected for processing (12)
  • packages/cli/src/cli_args/init_config.rs
  • packages/cli/src/cli_args/interactive_init/mod.rs
  • packages/cli/src/template_dirs.rs
  • packages/cli/templates/static/feature_filter_template/shared/.env.example
  • packages/cli/templates/static/feature_filter_template/shared/.gitignore
  • packages/cli/templates/static/feature_filter_template/shared/README.md
  • packages/cli/templates/static/feature_filter_template/shared/schema.graphql
  • packages/cli/templates/static/feature_filter_template/typescript/config.yaml
  • packages/cli/templates/static/feature_filter_template/typescript/src/handlers/ERC20.ts
  • packages/cli/templates/static/feature_filter_template/typescript/src/indexer.test.ts
  • packages/cli/templates/static/feature_filter_template/typescript/tsconfig.json
  • packages/e2e-tests/src/template-tests/templates.test.ts

Comment thread packages/cli/templates/static/feature_filter_template/shared/.env.example Outdated
Comment thread packages/cli/templates/static/feature_filter_template/shared/README.md Outdated
@nikbhintade nikbhintade requested a review from DZakh April 2, 2026 11:11

@DZakh DZakh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nothing critical, just left a few nitpicks. Thank you for leading this project with templates.

Comment thread packages/cli/templates/static/feature_filter_template/typescript/config.yaml Outdated

const result = await indexer.process({
chains: {
1: { startBlock: START_BLOCK, endBlock: END_BLOCK },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd like to wait for alpha 21 release and use the automatic block detection feature. To process only the first block in the test

Comment on lines +36 to +40
const allTransfers = result.changes.flatMap((c) => c.Transfer?.sets ?? []);
const burns = allTransfers.filter((t) => t.to === ZERO_ADDRESS);

expect(burns.length, "Should have indexed at least one burn event").toBeGreaterThan(0);
expect(burns[0]).toMatchObject({ to: ZERO_ADDRESS, chainId: 1 });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, if you want to test that both burn and mint exist, it makes sense to use a hard-coded range. But maybe shrink it to a specific block. Also, instead of validating changes, you can do indexer.Transfer.getAll() or getOrThrow

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.

2 participants