> For the complete documentation index, see [llms.txt](https://docs.idle.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.idle.finance/developers/yield-tranches/subgraph.md).

# Subgraph

Developers > Yield Tranches > Subgraph

Idle uses a [subgraph](https://thegraph.com/docs/about/introduction#what-the-graph-is) for indexing and organizing data from the Yield Tranches `IdleCDO` smart contract. This subgraph can be found on The Graph hosted service and can be used to query Idle YTs data:

* **YTs subgraph** <https://thegraph.com/hosted-service/subgraph/samster91/idle-tranches>
* **Graphql endpoint**
  * Ethereum <https://api.thegraph.com/subgraphs/name/samster91/idle-tranches>
  * Polygon zkEVM [https://api.studio.thegraph.com/query/12583/idle-tranches-zkevm/version/latest ](<https://api.studio.thegraph.com/query/12583/idle-tranches-zkevm/version/latest >)
  * Optimism <https://api.thegraph.com/subgraphs/name/samster91/idle-tranches-optimism>
* **Code** <https://github.com/Idle-Labs/idle-tranches-subgraph>

<figure><img src="https://4022236167-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lw-v0NTae0RVW1spR9R%2Fuploads%2Fs3MiQTbkntfgCFfoszTg%2Fimage.png?alt=media&amp;token=be978ffa-c14c-46e8-a2d3-d5b1608fdf24" alt=""><figcaption></figcaption></figure>

### Useful entities

* ***TrancheInfos*****:** contains the data of each YTs tranche (type, apr, `virtualPrice`, `totalSupply`) updated every hour
* ***Tranche*****:** all deployed YTs tranches (id, type)

### Querying YTs

{% hint style="info" %}
Subgraph is case-sensitive. Remember to use all lowercase when inputting tranches' addresses.&#x20;
{% endhint %}

#### Example 1

To obtain the latest *TrancheInfos* you can use the following query

```graphql
{ 
    trancheInfos(orderBy:"timeStamp", orderDirection:"desc") { 
        id
        apr
        Tranche { 
            id 
        }
        timeStamp
        blockNumber
        totalSupply
        virtualPrice
    }
}
```

#### Example 2

To obtain the latest *TrancheInfos* for a specific tranche add a `where` filter. Let's query for example the Clearpool Portofino DAI Senior tranche `0xfc96989b3df087c96c806318436b16e44c697102`

```graphql
{ 
    trancheInfos(orderBy:"timeStamp", orderDirection:"desc", 
                 where:{ Tranche:"0xfc96989b3df087c96c806318436b16e44c697102" }) { 
        id
        apr
        Tranche { 
            id 
            CDO {
              id
            }
        }
        timeStamp
        blockNumber
        totalSupply
        virtualPrice
    }
}
```

For more info about GraphQL API, check [TheGraph Documentation](https://thegraph.com/docs/en/developer/graphql-api/).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.idle.finance/developers/yield-tranches/subgraph.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
