# Subgraph

We have subgraphs available for all supported chains, mainnet and testnet. Our Ethereum Mainnet runs on Graph Protocol's decentralized network, all others are on their hosted service.

Documentation is available for all entities and their fields, to access it, follow one of the links at the bottom of this page, then in GraphiQL:

<figure><img src="/files/DwtUqTDC72F1TBiN3yOW" alt=""><figcaption><p>Click the <code>Query</code> link in the Document Explorer</p></figcaption></figure>

<figure><img src="/files/H6OAgPtUUdIwXGFGi7k7" alt=""><figcaption><p>Click the link for the entity you are interested in</p></figcaption></figure>

<figure><img src="/files/lMO7mDtANGiWOlACDXPZ" alt=""><figcaption><p>A description of the entity and each field will be available</p></figcaption></figure>

{% hint style="warning" %}
The documentation is usually identical across all subgraphs, so it does not matter which one you use.

However, if changes are being made, the updates may appear on testnet or backup subgraphs before they appear in production.
{% endhint %}

#### Mainnet Subgraphs

* <https://gateway.thegraph.com/api/{API\\_KEY}/subgraphs/id/9F8K4UDnrQEzXsVmHoJxs5qBVDJB5jEKtU9EVsXNTzZZ[> ]\(<https://gateway.thegraph.com/api/17f8839a7d9c7f990a93cb221bf4248b/subgraphs/id/9F8K4UDnrQEzXsVmHoJxs5qBVDJB5jEKtU9EVsXNTzZZ)(Mainnet> Production - paid, requires API key)
* <https://api.studio.thegraph.com/query/41517/bond-protocol-ethereum-mainnet/v1.0.6> (Mainnet Development - version number at the end of the URL may change)
* <https://api.thegraph.com/subgraphs/name/bond-protocol/bond-protocol-arbitrum-mainnet> (Arbitrum Production)
* <https://thegraph.com/hosted-service/subgraph/bond-protocol/bond-protocol-mainnet> (Mainnet Backup)

#### Testnet Subgraphs

* <https://api.thegraph.com/subgraphs/name/bond-protocol/bond-protocol-goerli>
* <https://api.thegraph.com/subgraphs/name/bond-protocol/bond-protocol-goerli-arbitrum>
* <https://api.thegraph.com/subgraphs/name/bond-protocol/bond-protocol-optimism-goerli>
* <https://api.thegraph.com/subgraphs/name/bond-protocol/bond-protocol-polygon-mumbai>
* <https://api.thegraph.com/subgraphs/name/bond-protocol/bond-protocol-avalanche-fuji>

#### Example Queries

{% hint style="warning" %}
NOTES

* Each subgraph only returns data for the chain it is indexing. You cannot filter by fields such as "network" or "chainId", they have only been added to allow the dApp to do so, once the results from multiple subgraphs have been merged.
* String searches are case sensitive, unless you add `_nocase` for example `owner_contains_nocase` as seen in the vesting token balance example.
* The `hasClosed` field on the `Market` entity is not fully trustworthy, markets can sometimes close without triggering an event which updates this. We use it to filter out the majority which do trigger an event, then on the dApp, filter the rest manually.
* By default, a request returns a maximum of 100 results. You can request up to 1000 using `first: 1000`, for example: `ownerTokenTbvs(first: 1000)`. If more than 1000 results are required, you will have to use pagination (<https://thegraph.com/docs/en/querying/graphql-api/#pagination>).
  {% endhint %}

List markets, including all data loaded by dApp on initial load:

```
{
    markets(where: { hasClosed: false }) {
      id
      name
      network
      auctioneer
      teller
      marketId
      owner
      callbackAddress
      capacity
      capacityInQuote
      chainId
      minPrice
      scale
      start
      conclusion
      payoutToken {
        id
        address
        symbol
        decimals
        name
      }
      quoteToken {
        id
        address
        symbol
        decimals
        name
        lpPair {
          token0 {
            id
            address
            symbol
            decimals
            name
            typeName
          }
          token1 {
            id
            address
            symbol
            decimals
            name
            typeName
          }
        }
        balancerWeightedPool {
          id
          vaultAddress
          poolId
          constituentTokens {
            id
            address
            symbol
            decimals
            name
            typeName
          }
        }
      }
      vesting
      vestingType
      isInstantSwap
      hasClosed
      totalBondedAmount
      totalPayoutAmount
      creationBlockTimestamp
    }
  }
```

List all tokens:

```
{
    tokens {
      id
      network
      chainId
      address
      decimals
      symbol
      name
      lpPair {
        token0 {
          id
        }
        token1 {
          id
        }
      }
      balancerWeightedPool {
        constituentTokens {
          id
        }
      }
    }
  }
```

Show vesting token balances for a given user:

```
{
    ownerBalances(where: { owner_contains_nocase: OWNER_ADDRESS, balance_gt: 0 }) {
      id
      tokenId
      owner
      balance
      network
      chainId
      bondToken {
        id
        symbol
        decimals
        expiry
        network
        chainId
        type
        teller
        underlying {
          id
          symbol
          decimals
        }
      }
    }
  }
```

TBV per owner/token combination:

```
{
    ownerTokenTbvs(first: 1000) {
      owner
      token
      tbv
      network
      chainId
    }
  }
```

Bond purchases per market:

```
{
    bondPurchases(
      first: 1000
      where: { marketId: MARKET_ID }
      orderBy: timestamp
    ) {
      id
      recipient
      payout
      amount
      timestamp
      purchasePrice
      postPurchasePrice
      quoteToken {
        id
        name
        symbol
        address
      }
      payoutToken {
        id
        name
        symbol
        address
      }
    }
  }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev.bondprotocol.finance/developers/subgraph.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
