> ## Documentation Index
> Fetch the complete documentation index at: https://docs.signalium.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Subgraph

> Goldsky subgraph that indexes the factory + per-market events including yield snapshots.

Source: [`packages/subgraph/`](https://github.com/rstfulzz/signalium/tree/main/packages/subgraph)

Indexes:

* `MarketCreated` and `MarketYieldDeployed` from `MarketFactory` → creates a `Market` entity, attaches `treasury` + `gimoAdapter`.
* `PositionTaken`, `Claimed`, `MarketResolved`, `MarketVoided`, `ResolutionPending` from each `PredictionMarket` clone (template).
* `YieldSnapshotted` and `HouseWithdrawn` for per-market and protocol-wide yield totals.
* `ResolutionSubmitted` from `AIResolver` for audit trails.

The API (`apps/api`) prefers the subgraph for `/markets` reads (one round-trip per page, fully hydrated, with rolling counters) and falls back to direct chain reads when `GOLDSKY_GRAPHQL_URL` is unset.

## Deploy

```bash theme={null}
cd packages/subgraph
goldsky login
pnpm deploy:goldsky
pnpm tag:goldsky-prod
```

The `prod` tag is what `GOLDSKY_GRAPHQL_URL` points at. Bump `version` in `package.json` before each deploy so older versions aren't overwritten.

## Querying

Production endpoint: `https://api.goldsky.com/api/public/project_cmioox8y90t7401znbgia8tcm/subgraphs/signalium/prod/gn`.

Example — list the 5 most recent yield-enabled markets:

```graphql theme={null}
{
  markets(first: 5, orderBy: createdAt, orderDirection: desc) {
    id
    question
    treasury
    gimoAdapter
    yesPool
    noPool
    yieldSnapshotted
    bettorsYieldShare
    protocolYieldShare
  }
  protocolStats(id: "protocol") {
    marketCount
    totalYieldEarned
    totalProtocolYieldShare
    totalHouseWithdrawn
  }
}
```

See [`packages/subgraph/README.md`](https://github.com/rstfulzz/signalium/blob/main/packages/subgraph/README.md) for the full schema reference.
