Skip to content

Effects API Template (Template 2/6)#826

Open
nikbhintade wants to merge 2 commits intomainfrom
nb/effects-api
Open

Effects API Template (Template 2/6)#826
nikbhintade wants to merge 2 commits intomainfrom
nb/effects-api

Conversation

@nikbhintade
Copy link
Member

@nikbhintade nikbhintade commented Nov 19, 2025

Template for showing Effects API usage

Current issue:

  • I am not sure how I can automatically push a dependency in package.json as this template uses viem, right I have added that step in the README file

Summary by CodeRabbit

  • New Features

    • Added an Effects API template option to the code generator for scaffolding projects, including example handlers, TypeScript project config, environment example and ignore patterns, and a sample GraphQL schema and config for an Ethereum-based indexer.
  • Documentation

    • New README with setup steps, running instructions, example effect patterns (e.g., token-decimal fetching), and guidance for local development and GraphQL playground access.

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

coderabbitai bot commented Nov 19, 2025

Walkthrough

Added a new "Effects API" template variant: new EffectsApi enum variant and directory mapping, plus a complete static template implementation (config, schema, TypeScript handlers, docs, env and build files) under codegenerator/cli/templates/static/effects_api_template.

Changes

Cohort / File(s) Summary
Enum & routing
codegenerator/cli/src/cli_args/init_config.rs, codegenerator/cli/src/template_dirs.rs
Added EffectsApi variant to evm::Template and mapped it to directory name "effects_api" in to_dir_name.
Template config & schema
codegenerator/cli/templates/static/effects_api_template/typescript/config.yaml, codegenerator/cli/templates/static/effects_api_template/shared/schema.graphql
Added project YAML defining effects-api, UniswapV3Factory contract with PoolCreated event, and GraphQL type UniswapV3Factory_PoolCreated with token, decimals, fee, tickSpacing, and pool fields.
Env & ignore files
codegenerator/cli/templates/static/effects_api_template/shared/.env.example, codegenerator/cli/templates/static/effects_api_template/shared/.gitignore
Added example environment variables (API token, Ethereum RPC) and .gitignore covering build artifacts, caches, generated files, and editor/tooling files.
TypeScript template & build config
codegenerator/cli/templates/static/effects_api_template/typescript/src/EventHandlers.ts, codegenerator/cli/templates/static/effects_api_template/typescript/tsconfig.json
Added EventHandlers implementing an effect to fetch token decimals (with fallback) and handler for PoolCreated that constructs and stores the entity; added tsconfig targeting ES2020 with strict checks.
Documentation
codegenerator/cli/templates/static/effects_api_template/shared/README.md
Added README documenting the Effects API concept, effect usage/options, example effect, prerequisites, local run instructions, and regeneration guidance.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Event as UniswapV3Factory.PoolCreated
    participant Handler as EventHandler
    participant Effect as fetchTokenDetails
    participant RPC as Ethereum RPC
    participant Store as Indexer Context

    Event->>Handler: Invoke with token0, token1, fee, tickSpacing
    par Concurrent decimals fetch
        Handler->>Effect: fetch token0 decimals
        Handler->>Effect: fetch token1 decimals
    end
    Effect->>RPC: call ERC20.decimals
    RPC-->>Effect: decimals | error
    Note right of Effect: on error -> return fallback 18
    Effect-->>Handler: decimals result
    Handler->>Handler: compose UniswapV3Factory_PoolCreated entity
    Handler->>Store: set UniswapV3Factory_PoolCreated(entity)
    Store-->>Handler: ack
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

  • Areas to focus on:
    • EventHandlers.ts: concurrent fetch logic, error/fallback behavior, Viem client usage and ERC20 ABI.
    • schema.graphql vs handler field types/naming alignment.
    • config.yaml event field/index mapping and network/contract address correctness.
    • .env example values and README instructions clarity.

Suggested reviewers

  • JonoPrest
  • moose-code

Poem

🐇 A rabbit scurries to code and play,
New Effects API hops into the day.
Tokens, decimals, RPC calls bright —
Handlers gather pools into light.
Indexer hums as effects take flight.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies that this PR adds an Effects API template. It accurately describes the main change and includes a serial number indicating this is part of a multi-part template series.
✨ 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/effects-api

📜 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 d353d29 and c66ed17.

📒 Files selected for processing (3)
  • codegenerator/cli/src/cli_args/init_config.rs (1 hunks)
  • codegenerator/cli/templates/static/effects_api_template/shared/.gitignore (1 hunks)
  • codegenerator/cli/templates/static/effects_api_template/typescript/src/EventHandlers.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • codegenerator/cli/src/cli_args/init_config.rs
  • codegenerator/cli/templates/static/effects_api_template/typescript/src/EventHandlers.ts
  • codegenerator/cli/templates/static/effects_api_template/shared/.gitignore
⏰ 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: 0

🧹 Nitpick comments (4)
codegenerator/cli/templates/static/effects_api_template/shared/.env.example (1)

1-3: Tidy up .env example to satisfy dotenv-linter (optional).

dotenv-linter warnings are only about style (quoted values and missing trailing newline). If you care about keeping it clean, you can drop the quotes and add a final newline:

-ENVIO_API_TOKEN="<YOUR-API-TOKEN>"
-ETHEREUM_MAINNET_RPC="<YOUR-ETHEREUM-MAINNET-RPC-URL>"
+ENVIO_API_TOKEN=<YOUR-API-TOKEN>
+ETHEREUM_MAINNET_RPC=<YOUR-ETHEREUM-MAINNET-RPC-URL>
+
codegenerator/cli/templates/static/effects_api_template/shared/.gitignore (1)

1-35: Remove duplicate patterns in .gitignore (nit).

*.obj (Line 16) and *.annot (Line 18) are already listed earlier (Lines 2 and 8). Not a functional issue, but you can drop the duplicates to keep this list a bit cleaner.

-*.obj
-*~
-*.annot
+*~
codegenerator/cli/templates/static/effects_api_template/typescript/src/EventHandlers.ts (1)

1-71: Normalize viem decimals type to match S.number & ensure viem dependency is wired.

Two things to double‑check here:

  1. Effect output vs. viem return type

Depending on your viem version & config, client.readContract for decimals() may return a bigint (even for uint8), while the effect schema declares:

output: {
  decimal: S.number,
}

To avoid any schema/runtime mismatch, it’s safer to coerce explicitly:

-      const decimals = await client.readContract({
+      const decimals = await client.readContract({
         address: input.token as `0x${string}`,
         abi: ERC20_ABI,
         functionName: "decimals",
       });
-
-      return { decimal: decimals };
+      return { decimal: Number(decimals) };
  1. Template dependency on viem

This template imports viem and viem/chains, but generator wiring for package.json isn’t visible here (and per PR description is still in question). Please ensure that:

  • The scaffolded project’s package.json includes viem as a dependency, or
  • The shared README for this template clearly tells users to npm install viem / pnpm add viem after generation.
codegenerator/cli/templates/static/effects_api_template/shared/README.md (1)

1-99: Tweak link text to be more descriptive (markdownlint MD059)

The README is clear, but markdownlint flags bare-URL link text. Consider making the link text descriptive for better accessibility and lint compliance:

-You can learn more about the Effects API in the documentation: [https://docs.envio.dev/docs/HyperIndex/effect-api](https://docs.envio.dev/docs/HyperIndex/effect-api)
+You can learn more about the Effects API in the [Effects API documentation](https://docs.envio.dev/docs/HyperIndex/effect-api).

-While 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.
+While the indexer is running, visit the [Envio Console](https://envio.dev/console) to open the GraphQL Playground and query your indexed data.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fd3d6a0 and d353d29.

📒 Files selected for processing (9)
  • codegenerator/cli/src/cli_args/init_config.rs (1 hunks)
  • codegenerator/cli/src/template_dirs.rs (1 hunks)
  • codegenerator/cli/templates/static/effects_api_template/shared/.env.example (1 hunks)
  • codegenerator/cli/templates/static/effects_api_template/shared/.gitignore (1 hunks)
  • codegenerator/cli/templates/static/effects_api_template/shared/README.md (1 hunks)
  • codegenerator/cli/templates/static/effects_api_template/shared/schema.graphql (1 hunks)
  • codegenerator/cli/templates/static/effects_api_template/typescript/config.yaml (1 hunks)
  • codegenerator/cli/templates/static/effects_api_template/typescript/src/EventHandlers.ts (1 hunks)
  • codegenerator/cli/templates/static/effects_api_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/effects_api_template/shared/schema.graphql
  • codegenerator/cli/src/cli_args/init_config.rs
  • codegenerator/cli/templates/static/effects_api_template/typescript/config.yaml
  • codegenerator/cli/templates/static/effects_api_template/typescript/tsconfig.json
  • codegenerator/cli/templates/static/effects_api_template/typescript/src/EventHandlers.ts
  • codegenerator/cli/src/template_dirs.rs
  • codegenerator/cli/templates/static/effects_api_template/shared/README.md
🧠 Learnings (5)
📚 Learning: 2025-11-19T05:36:33.940Z
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.940Z
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/effects_api_template/shared/schema.graphql
  • codegenerator/cli/templates/static/effects_api_template/typescript/config.yaml
  • codegenerator/cli/templates/static/effects_api_template/typescript/src/EventHandlers.ts
📚 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-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/effects_api_template/typescript/tsconfig.json
  • codegenerator/cli/templates/static/effects_api_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: Compiled .js artifacts can be ignored

Applied to files:

  • codegenerator/cli/templates/static/effects_api_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 **/*.res : Prefer reading ReScript .res modules directly

Applied to files:

  • codegenerator/cli/templates/static/effects_api_template/shared/.gitignore
🧬 Code graph analysis (1)
codegenerator/cli/src/cli_args/init_config.rs (2)
codegenerator/cli/src/config_parsing/entity_parsing.rs (2)
  • serialize (1184-1189)
  • serialize (1335-1340)
codegenerator/cli/src/rescript_types.rs (1)
  • serialize (703-709)
🪛 dotenv-linter (4.0.0)
codegenerator/cli/templates/static/effects_api_template/shared/.env.example

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

(QuoteCharacter)


[warning] 3-3: [EndingBlankLine] No blank line at the end of the file

(EndingBlankLine)


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

(QuoteCharacter)

🪛 markdownlint-cli2 (0.18.1)
codegenerator/cli/templates/static/effects_api_template/shared/README.md

23-23: Link text should be descriptive

(MD059, descriptive-link-text)

⏰ 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 (5)
codegenerator/cli/src/cli_args/init_config.rs (1)

29-35: EffectsApi template variant wiring looks correct.

Adding EffectsApi with a strum(serialize = "Feature: Effects API") label fits the existing enum pattern and will integrate cleanly with InitFlow and iteration/Display usage.

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

1-19: Config wiring for the Effects API template looks consistent.

Contract name, handler path, PoolCreated signature, mainnet factory address, and flags (unordered_multichain_mode, preload_handlers) all line up with the new TS handler and Uniswap V3 factory ABI.

If you haven’t already, verify this config.yaml against evm.schema.json via envio’s own validation to catch any schema drift.

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

15-23: EffectsApi → effects_api mapping looks correct

The new evm::Template::EffectsApi => "effects_api" arm is consistent with existing mappings and aligns with the effects_api_template directory naming used by the static templates.

codegenerator/cli/templates/static/effects_api_template/typescript/tsconfig.json (1)

1-21: TypeScript compiler options are sensible for this template

The tsconfig.json settings (ES2020 target/lib, strict mode, CommonJS, JSON module support) are coherent with a Node 18+ / BigInt / viem-based Effects API template.

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

1-10: PoolCreated GraphQL type is well-structured

The UniswapV3Factory_PoolCreated type cleanly captures the expected event fields (ids, token addresses/decimals, fee, tick spacing, pool) and fits typical indexing patterns; nothing problematic stands out.

@nikbhintade nikbhintade changed the title Effects API Template Effects API Template (Template 2/6) Nov 19, 2025
@nikbhintade nikbhintade requested a review from DZakh November 20, 2025 10:51
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.

Nice, I left a few comments. I didn't expand my thoughts properly everywhere, if you have a question I'll be keen to sync.

Comment on lines +33 to +34
#[strum(serialize = "Feature: External Calls")]
EffectsApi
Copy link
Member

Choose a reason for hiding this comment

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

A suggestion for consistency:

Suggested change
#[strum(serialize = "Feature: External Calls")]
EffectsApi
#[strum(serialize = "Feature: External Calls")]
ExternalCalls

@@ -0,0 +1,3 @@
# To create or update a token visit https://envio.dev/app/api-tokens
ENVIO_API_TOKEN="<YOUR-API-TOKEN>"
ETHEREUM_MAINNET_RPC="<YOUR-ETHEREUM-MAINNET-RPC-URL>" No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

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

Currently it's required on hosted service to have env vars prefixed with ENVIO_ to set them via UI, so let's also do this in the template.

@@ -0,0 +1,99 @@
# Effects API
Copy link
Member

Choose a reason for hiding this comment

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

Needs to be updated


_Please refer to the [documentation website](https://docs.envio.dev) for a thorough guide on all [Envio](https://envio.dev) indexer features_

With HyperIndex, the Effects API allows you to perform external calls from your handlers.
Copy link
Member

Choose a reason for hiding this comment

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

This is Effect API, not Effects API

_Please refer to the [documentation website](https://docs.envio.dev) for a thorough guide on all [Envio](https://envio.dev) indexer features_

With HyperIndex, the Effects API allows you to perform external calls from your handlers.
These calls run in parallel with your handler logic, so they don’t block execution.
Copy link
Member

Choose a reason for hiding this comment

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

This is not really correct.

Add your Envio API key to the .env file, then start the indexer:

```bash
pnpm install viem # install viem to interact with RPC
Copy link
Member

Choose a reason for hiding this comment

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

This should be a part of the template, so we shouldn't require more than pnpm i for the user

Copy link
Member Author

Choose a reason for hiding this comment

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

How can I do that? I am not sure about it.

Copy link
Member

Choose a reason for hiding this comment

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

We usually include it into a package json, which should become a part of the template.

Comment on lines +6 to +10
// Create a Viem client for mainnet RPC reads
const client = createPublicClient({
chain: mainnet,
transport: http(process.env.ETHEREUM_MAINNET_RPC!, { batch: true }),
});
Copy link
Member

Choose a reason for hiding this comment

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

Let's make it multichain as I suggested in the previous PR

Comment on lines +2 to +3
name: effects-api
description: Example indexer showing how to use HyperIndex’s Effects API.
Copy link
Member

Choose a reason for hiding this comment

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

Needs to be updated

Copy link
Member

Choose a reason for hiding this comment

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

Let's also add feature or example to the 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.

2 participants