diff --git a/.changeset/young-crabs-rest.md b/.changeset/young-crabs-rest.md new file mode 100644 index 0000000000..d6cc11ce9b --- /dev/null +++ b/.changeset/young-crabs-rest.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/store-indexer": minor +--- + +Added `STORE_ADDRESS` environment variable to index only a specific MUD Store. diff --git a/packages/store-indexer/README.md b/packages/store-indexer/README.md index 26d33ee1d6..bb41d739c3 100644 --- a/packages/store-indexer/README.md +++ b/packages/store-indexer/README.md @@ -28,13 +28,14 @@ Each indexer can be configured with environment variables. ### Common environment variables for indexer -| Variable | Description | Default | -| ------------------ | ---------------------------------------------------------- | ------- | -| `RPC_HTTP_URL` | HTTP URL for Ethereum RPC to fetch data from | | -| `RPC_WS_URL` | WebSocket URL for Ethereum RPC to fetch data from | | -| `START_BLOCK` | Block number to start indexing from | `0` | -| `MAX_BLOCK_RANGE` | Maximum number of blocks to fetch from the RPC per request | `1000` | -| `POLLING_INTERVAL` | How often to poll for new blocks (in milliseconds) | `1000` | +| Variable | Description | Default | +| ------------------ | ------------------------------------------------------------------------------------------------------------- | ------- | +| `RPC_HTTP_URL` | HTTP URL for Ethereum RPC to fetch data from | | +| `RPC_WS_URL` | WebSocket URL for Ethereum RPC to fetch data from | | +| `START_BLOCK` | Block number to start indexing from | `0` | +| `MAX_BLOCK_RANGE` | Maximum number of blocks to fetch from the RPC per request | `1000` | +| `POLLING_INTERVAL` | How often to poll for new blocks (in milliseconds) | `1000` | +| `STORE_ADDRESS` | Optional address of the MUD Store to index. By default, store-indexer will index all MUD Stores on the chain. | | Note that you only need one of `RPC_HTTP_URL` or `RPC_WS_URL`, but we recommend both. The WebSocket URL will be prioritized and fall back to the HTTP URL if there are any connection issues. diff --git a/packages/store-indexer/bin/parseEnv.ts b/packages/store-indexer/bin/parseEnv.ts index cc145a80fe..876e4109c4 100644 --- a/packages/store-indexer/bin/parseEnv.ts +++ b/packages/store-indexer/bin/parseEnv.ts @@ -1,3 +1,4 @@ +import { isHex } from "viem"; import { z, ZodError, ZodTypeAny } from "zod"; export const frontendEnvSchema = z.object({ @@ -10,6 +11,7 @@ export const indexerEnvSchema = z.intersection( START_BLOCK: z.coerce.bigint().nonnegative().default(0n), MAX_BLOCK_RANGE: z.coerce.bigint().positive().default(1000n), POLLING_INTERVAL: z.coerce.number().positive().default(1000), + STORE_ADDRESS: z.string().refine(isHex).optional(), }), z.union([ z.object({ diff --git a/packages/store-indexer/bin/postgres-indexer.ts b/packages/store-indexer/bin/postgres-indexer.ts index 025fe818b0..b6a288d5d1 100644 --- a/packages/store-indexer/bin/postgres-indexer.ts +++ b/packages/store-indexer/bin/postgres-indexer.ts @@ -75,6 +75,7 @@ const { latestBlockNumber$, storedBlockLogs$ } = await createStoreSync({ publicClient, startBlock, maxBlockRange: env.MAX_BLOCK_RANGE, + address: env.STORE_ADDRESS, }); storedBlockLogs$.subscribe(); diff --git a/packages/store-indexer/bin/sqlite-indexer.ts b/packages/store-indexer/bin/sqlite-indexer.ts index b664c9de38..c8afdfeb85 100644 --- a/packages/store-indexer/bin/sqlite-indexer.ts +++ b/packages/store-indexer/bin/sqlite-indexer.ts @@ -71,6 +71,7 @@ const { latestBlockNumber$, storedBlockLogs$ } = await syncToSqlite({ publicClient, startBlock, maxBlockRange: env.MAX_BLOCK_RANGE, + address: env.STORE_ADDRESS, }); let isCaughtUp = false;