Skip to content

Feat/relayer envio#457

Open
mani99brar wants to merge 4 commits into
devfrom
feat/relayer-envio
Open

Feat/relayer envio#457
mani99brar wants to merge 4 commits into
devfrom
feat/relayer-envio

Conversation

@mani99brar
Copy link
Copy Markdown
Contributor

@mani99brar mani99brar commented May 25, 2026

PR-Codex overview

This PR introduces the relayer-envio-inbox, a new indexer for the Envio platform. It includes configuration files, a decoding utility, event handlers for blockchain events, and a GraphQL schema for message handling.

Detailed summary

  • Added .env file with ENVIO_API_TOKEN.
  • Created relayer-envio-inbox folder structure.
  • Implemented decodeNodeData function in decoder.ts.
  • Created event handlers in EventHandlers.ts for MessageSent, SnapshotSaved, and SnapshotSent events.
  • Defined GraphQL schema in schema.graphql.
  • Configured Jest testing in jest.config.ts.
  • Updated TypeScript configuration in tsconfig.json.
  • Added README with setup instructions.
  • Expanded .gitignore for build artifacts and environment files.

The following files were skipped due to too many changes: yarn.lock

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Added an Envio Indexer service exposing GraphQL types for inbox messages, snapshots, and related entities.
  • Chores

    • Workspace, package and build scripts added; local dev/start/codegen commands provided.
    • .gitignore updated to exclude generated and env files.
  • Documentation

    • README added with run instructions, prerequisites, and GraphQL playground details.
    • .env example documents ENVIO_API_TOKEN.
  • Tests

    • Unit tests added for decoder and Merkle utilities.

Review Change Stack

@netlify
Copy link
Copy Markdown

netlify Bot commented May 25, 2026

Deploy Preview for veascan failed. Why did it fail? →

Name Link
🔨 Latest commit ad094f5
🔍 Latest deploy log https://app.netlify.com/projects/veascan/deploys/6a14240c12dda00009fdae16

@netlify
Copy link
Copy Markdown

netlify Bot commented May 25, 2026

Deploy Preview for veashi-scan failed. Why did it fail? →

Name Link
🔨 Latest commit ad094f5
🔍 Latest deploy log https://app.netlify.com/projects/veashi-scan/deploys/6a14240c51793a0008b670ff

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1adeba91-9942-454d-8e90-ab39ec1cacdb

📥 Commits

Reviewing files that changed from the base of the PR and between 0d07a13 and ad094f5.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (3)
  • relayer-envio-inbox/.env.example
  • relayer-envio-inbox/README.md
  • relayer-envio-inbox/src/EventHandlers.ts
✅ Files skipped from review due to trivial changes (1)
  • relayer-envio-inbox/.env.example

Walkthrough

This pull request introduces relayer-envio-inbox, a new Envio indexer workspace that monitors the VeaInboxArbToEth contract on Arbitrum chain 421614. The indexer decodes event data, reconstructs Merkle tree state incrementally from MessageSent and SnapshotSaved events, and exposes indexed entities via GraphQL.

Changes

Envio Indexer Implementation

Layer / File(s) Summary
Workspace setup and project configuration
package.json, .gitignore, relayer-envio-inbox/package.json, relayer-envio-inbox/.env.example, relayer-envio-inbox/.gitignore, relayer-envio-inbox/README.md, relayer-envio-inbox/tsconfig.json, relayer-envio-inbox/jest.config.ts, relayer-envio-inbox/envio-env.d.ts
Monorepo workspace registration and complete project scaffolding: build tools (TypeScript, Jest with ESM support), dependencies (Envio 3.0.0, Ethers v6), and configuration files for development and testing.
GraphQL schema definition
relayer-envio-inbox/schema.graphql
SDL schema defining indexed entity types: MessageSent records relay messages with metadata, SnapshotSaved and SnapshotSent track snapshots and cross-chain tickets, MerkleNode represents tree nodes, and supporting entity types Inbox, Sender, Receiver.
Merkle hashing and decoder utilities
relayer-envio-inbox/src/utils/merkle.ts, relayer-envio-inbox/src/utils/decoder.ts
Cryptographic and parsing helpers: hexToBuffer, concatAndSort (deterministic byte-wise ordering), leafHash (double-keccak256), hashPair (keccak256 of sorted pair), and decodeNodeData (extract nonce and addresses from hex event data).
Event handlers and indexer configuration
relayer-envio-inbox/config.yaml, relayer-envio-inbox/src/EventHandlers.ts
Configuration wiring three contract events to their handlers and event handler implementations: MessageSent decodes data and incrementally reconstructs changed Merkle nodes using XOR bitmap, SnapshotSaved materializes missing upper Merkle nodes by folding snapshot metadata, SnapshotSent records cross-chain events.
Utility function tests
relayer-envio-inbox/test/Test.ts
Jest test suite validating all utility functions: decodeNodeData correctly parses nonce and addresses, leafHash is deterministic, concatAndSort enforces byte-wise lexicographic ordering, and hashPair is order-independent.

Sequence Diagram

sequenceDiagram
  participant VeaInboxArbToEth as VeaInboxArbToEth Contract
  participant MessageSentHandler as MessageSent Handler
  participant SnapshotSavedHandler as SnapshotSaved Handler
  participant MerkleUtils as Merkle Utils
  participant IndexStore as Envio Store
  VeaInboxArbToEth->>MessageSentHandler: emit MessageSent event
  MessageSentHandler->>MerkleUtils: decodeNodeData(nodeData)
  MerkleUtils->>MessageSentHandler: nonce, addresses, data
  MessageSentHandler->>MerkleUtils: leafHash(nodeData)
  MerkleUtils->>MessageSentHandler: leaf hash (32 bytes)
  MessageSentHandler->>MessageSentHandler: compute XOR bitmap for changed Merkle nodes
  MessageSentHandler->>MerkleUtils: hashPair(siblingHash, nodeHash) for each level
  MerkleUtils->>MessageSentHandler: updated internal node hash
  MessageSentHandler->>IndexStore: upsert Inbox, Sender, Receiver, MessageSent, MerkleNode
  VeaInboxArbToEth->>SnapshotSavedHandler: emit SnapshotSaved event
  SnapshotSavedHandler->>MerkleUtils: iterate snapshot count bit positions
  MerkleUtils->>SnapshotSavedHandler: subtree root hashes
  SnapshotSavedHandler->>MerkleUtils: hashPair for accumulated Merkle reconstruction
  MerkleUtils->>SnapshotSavedHandler: reconstructed upper node hash
  SnapshotSavedHandler->>IndexStore: write SnapshotSaved, persist reconstructed MerkleNode
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • jaybuidl

Poem

🐰 A new indexer hops into view,
Merkle leaves and nodes stitched true,
Messages counted, snapshots sewn tight,
Events become a chain of light,
Envio sings the ledger bright ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Feat/relayer envio' is vague and generic, using a feature prefix without clearly describing what the indexer does or its primary purpose. Consider a more descriptive title like 'Add Envio indexer for VeaInbox message processing' to clearly communicate the PR's main objective.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 feat/relayer-envio

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed due to a network error.


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

Copy link
Copy Markdown
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: 4

🧹 Nitpick comments (1)
relayer-envio-inbox/test/Test.ts (1)

12-85: ⚡ Quick win

Consider adding error case tests.

The test suite provides good coverage of expected behavior but doesn't test error conditions such as:

  • Malformed hex input (invalid characters, missing 0x prefix)
  • Wrong input lengths (too short or too long)
  • Invalid address formats
  • Boundary values (e.g., max nonce value)

If the utility functions are expected to handle these cases gracefully, adding negative tests would improve robustness.

🧪 Example error case tests
describe("decodeNodeData - error cases", () => {
  it("handles invalid hex input", () => {
    expect(() => decodeNodeData("not-hex")).toThrow();
  });

  it("handles input that is too short", () => {
    expect(() => decodeNodeData("0x1234")).toThrow();
  });
});

describe("leafHash - edge cases", () => {
  it("handles empty input", () => {
    expect(() => leafHash("0x")).not.toThrow();
  });
});

Note: Adjust expectations based on whether functions should throw or handle gracefully.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@relayer-envio-inbox/test/Test.ts` around lines 12 - 85, Add negative and
edge-case tests to cover malformed and boundary inputs: add a new
"decodeNodeData - error cases" suite that asserts decodeNodeData throws or
handles invalid hex (e.g., missing "0x" or non-hex chars) and inputs that are
too short/too long or have invalid address lengths; add tests for extreme nonce
values (max uint64) and for when trailing data is absent; also add tests for
leafHash, concatAndSort, and hashPair that check behavior on empty input,
invalid hex, and unexpected lengths (assert throw or notThrow based on intended
behavior) so the functions decodeNodeData, leafHash, concatAndSort, and hashPair
are covered for error and boundary conditions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@relayer-envio-inbox/.env.example`:
- Line 2: The ENVIO_API_TOKEN placeholder in .env.example is quoted; remove the
surrounding double quotes so the line reads ENVIO_API_TOKEN=<YOUR-API-TOKEN> to
match typical .env formatting and avoid accidental quoted secrets; update any
related documentation or README references that show the example so they also
use the unquoted placeholder string.

In `@relayer-envio-inbox/README.md`:
- Line 22: Update the README entry that currently references "Yarn (use v1 or
newer)" to require the repo's pinned version by changing the text to "Yarn (use
v4.6.0)" and, if desired, update the link target to the modern Yarn installation
guidance (or a short note about enabling Corepack) so contributors install Yarn
4.6.0 instead of Yarn 1; locate and modify the exact line containing the current
"[Yarn (use v1 or newer)]" text in README.md.

In `@relayer-envio-inbox/src/EventHandlers.ts`:
- Around line 103-143: The Merkle reconstruction loop corrupts large uint64
`count` by coercing it to JS Number and using 32-bit bitwise ops; change `size`,
`oldCount`, `height`, and `index` to bigint (initialize e.g. size =
BigInt(count)), and replace all numeric bit ops with bigint ops: use `& 1n`
instead of `& 1`, `>>= 1n` instead of `>>= 1`, and `2n ** height` instead of `2
** height`; update uses in the loop (variables `size`, `oldCount`, `height`,
`index`, and the `if ((size & 1) === 1)` branch and index calculations) so
template ids like `${inbox}-${index}` still stringify correctly and ensure
comparisons use bigint where needed.

In `@relayer-envio-inbox/src/utils/decoder.ts`:
- Around line 9-13: decodeNodeData currently calls hexToBuffer(...) and performs
fixed-offset reads (bytes.readBigUInt64BE(0), subarray(8,28), subarray(28,48))
without validating length; add a minimum-length guard that validates
bytes.length >= 48 before any fixed reads and handle insufficient length by
returning a safe value (e.g., null/undefined) or throwing a descriptive error so
callers (like EventHandlers.ts using event.params._nodeData) don't break; update
decodeNodeData to perform the length check right after hexToBuffer and ensure
downstream callers handle the null/error case appropriately.

---

Nitpick comments:
In `@relayer-envio-inbox/test/Test.ts`:
- Around line 12-85: Add negative and edge-case tests to cover malformed and
boundary inputs: add a new "decodeNodeData - error cases" suite that asserts
decodeNodeData throws or handles invalid hex (e.g., missing "0x" or non-hex
chars) and inputs that are too short/too long or have invalid address lengths;
add tests for extreme nonce values (max uint64) and for when trailing data is
absent; also add tests for leafHash, concatAndSort, and hashPair that check
behavior on empty input, invalid hex, and unexpected lengths (assert throw or
notThrow based on intended behavior) so the functions decodeNodeData, leafHash,
concatAndSort, and hashPair are covered for error and boundary conditions.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 958bba1f-d5a6-4269-bafc-6ab1c27cf89f

📥 Commits

Reviewing files that changed from the base of the PR and between 8911800 and 0d07a13.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (15)
  • .gitignore
  • package.json
  • relayer-envio-inbox/.env.example
  • relayer-envio-inbox/.gitignore
  • relayer-envio-inbox/README.md
  • relayer-envio-inbox/config.yaml
  • relayer-envio-inbox/envio-env.d.ts
  • relayer-envio-inbox/jest.config.ts
  • relayer-envio-inbox/package.json
  • relayer-envio-inbox/schema.graphql
  • relayer-envio-inbox/src/EventHandlers.ts
  • relayer-envio-inbox/src/utils/decoder.ts
  • relayer-envio-inbox/src/utils/merkle.ts
  • relayer-envio-inbox/test/Test.ts
  • relayer-envio-inbox/tsconfig.json

Comment thread relayer-envio-inbox/.env.example Outdated
Comment thread relayer-envio-inbox/README.md Outdated
Comment thread relayer-envio-inbox/src/EventHandlers.ts Outdated
Comment thread relayer-envio-inbox/src/utils/decoder.ts
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@mani99brar mani99brar marked this pull request as ready for review May 25, 2026 14:01
@mani99brar mani99brar requested a review from jaybuidl as a code owner May 25, 2026 14:01
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.

1 participant