Skip to content

About

Envio HyperIndex indexer for OCR asset contracts on Sepolia

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

ocr-indexer

Please refer to the documentation website for a thorough guide on all Envio indexer features.

This indexer tracks:

  • AssetRegistry: deployment and configuration of Asset contracts.
  • Asset: subscription-gated assets and their subscribers.

It exposes convenient entities to answer questions like:

  • Which assets exist and who owns them?
  • Which assets is a user subscribed to?
  • Which users are subscribed to a given asset?

Data model

  • AssetEntity
    One row per Asset contract.

    • id: asset contract address (lowercased).
    • assetId: bytes32 id in the registry.
    • registryAddress: address of the AssetRegistry that created it.
    • owner: current Asset owner (creator or transferee), always lowercased.
  • Subscription
    One row per (asset, user) pair.

    • id: ${assetAddress}_${user} (both lowercased).
    • asset_id: foreign key to AssetEntity.id.
    • user: subscriber address (lowercased).
    • expiresAt: subscription expiry timestamp (BigInt).
    • isActive: whether the subscription is currently active.
  • Event entities
    These mirror contract events for history / debugging:

    • AssetContract_AssetCreated
    • AssetContract_OwnershipTransferred
    • AssetContract_CreatorFeeShareUpdated
    • AssetContract_RegistryFeeShareUpdated
    • Asset_SubscriptionAdded
    • Asset_SubscriptionPriceUpdated
    • Asset_SubscriptionRevoked
    • Asset_OwnershipTransferred

GraphQL API

All GraphQL types and fields are defined in schema.graphql. After running pnpm dev, open the Playground at http://localhost:8080 (password testing).

For a full list of ready‑to‑use queries (with variables and explanations) targeted at external builders, see:

  • docs-query-api.md – GraphQL API reference and examples

Running the indexer

  • Start the dev stack
pnpm dev

This will:

  • Start Postgres and the Envio runtime via Docker.
  • Run the indexer against the configured network(s).
  • Expose GraphQL at http://localhost:8080 (password testing).

Local Anvil deployment (example workflow)

For a ready-made local setup that deploys GameToken, AssetRegistry, and an Asset to Anvil and emits example events for this indexer, you can use:

Typical flow:

  1. In the open-creator-rails repo:

    • Start Anvil:

      anvil --chain-id 31337
    • Export the default Anvil private key and run the deploy script:

      export PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
      forge script script/DeployForLocalIndexerTest.s.sol:DeployForLocalIndexerTest \
        --rpc-url http://127.0.0.1:8545 \
        --broadcast -vvv
    • Note the deployed addresses printed in the logs:

      • AssetRegistry address
      • Asset (GameAsset) address
  2. In this ocr-indexer repo:

    • Update config.yaml networks[0].contracts with those deployed addresses (in lowercase).

    • Regenerate code:

      pnpm codegen
    • Run the indexer:

      TUI_OFF=true pnpm dev
    • Open http://localhost:8080 and query AssetEntity / Subscription to explore the data generated by the deploy script.

  3. (Optional) Add another subscriber to the Asset

    In the open-creator-rails repo (or wherever SubscribeOtherUserToAsset.s.sol lives), you can run an additional script that mints GameToken to a second user and subscribes them to the Asset using EIP‑2612 permit. This will emit another SubscriptionAdded event for the indexer to pick up.

    First, export the required environment variables (adjust addresses if they differ in your setup):

    export RPC_URL=http://127.0.0.1:8545
    export PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
    export SUBSCRIBER_PRIVATE_KEY=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
    export ASSET_ADDRESS=0x from DeployForLocalIndexerTest result
    export GAME_TOKEN_ADDRESS=0x from DeployForLocalIndexerTest result

    Then run the script:

    forge script script/SubscribeOtherUserToAsset.s.sol:SubscribeOtherUserToAsset \
      --rpc-url "$RPC_URL" --broadcast -vvv

    After it completes, the indexer will ingest the new SubscriptionAdded event and you should see an additional active Subscription row for the second user in the GraphQL API.

Code generation & type-checking

  • Regenerate code after changing config.yaml or schema.graphql:
pnpm codegen
  • Type-check the handlers (recommended after TypeScript changes):
pnpm tsc --noEmit

Tests

The indexer includes a mocha test suite under test/test.ts using Envio TestHelpers:

  • Validates that:
    • AssetRegistry.AssetCreated populates AssetContract_AssetCreated, AssetEntity, and AssetIdToAddress.
    • Subscription add / revoke keep Subscription.isActive in sync.
    • Ownership and fee-share events from AssetRegistry are indexed.
    • Asset.OwnershipTransferred keeps AssetEntity.owner in sync.

Run the tests with:

pnpm test

Deploying to Envio Hosted Service

  1. Push your code to a GitHub repository.
  2. Go to envio.dev and log in with GitHub.
  3. Select the GitHub organization/account that owns the repo.
  4. Install the Envio Deployments GitHub App and grant access to the repo.
  5. Click Add Indexer and select the repo.
  6. Configure:
    • Config file: config.yaml
    • Root directory: /
    • Deployment branch: master (or your preferred branch)
  7. Push to the deployment branch to trigger a build.
  8. Monitor sync progress on the Envio dashboard.

The current hosted instance is deployed from alexandreext-lab/ocr-indexer at:

Pre-requisites

  • Node.js: v20 (required by Envio / HyperIndex setup).
  • pnpm: v8 or newer.
  • Docker (Docker Desktop or compatible CLI).

About

Envio HyperIndex indexer for OCR asset contracts on Sepolia

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages