# Using the Subgraph

## Using the Vaults Subgraph

The MORE Vaults subgraph exposes on‑chain vault activity and performance via GraphQL. It tracks the factory, all vaults, deposits/withdrawals, user share balances (with cost basis and PnL), and daily/weekly performance snapshots.

#### Endpoints

* Flow network: [`https://graph.more.markets/flow/subgraphs/name/flow-vaults/graphql`](https://graph.more.markets/flow/subgraphs/name/flow-vaults/graphql)
* Ethereum network: Open a support ticket on [Discord](https://discord.gg/MmpBdPMQt8) for access to the Ethereum subgraph URL.

#### Quickstart queries

* Latest vaults with performance

```graphql
{
  vaults(first: 5, orderBy: totalAssetsUSD, orderDirection: desc) {
    id
    name
    symbol
    totalAssets
    totalAssetsUSD
    apyPriceTrailing
    apyDailyReturnTrailing
    apyWeeklyReturnTrailing
  }
}
```

* A wallet’s balance and PnL in a vault

```graphql
query($user: Bytes!, $vault: String!) {
  userVaultBalances(where: { user: $user, vault: $vault }) {
    sharesBalance
    shareBalanceUSD
    weightedAverageCostBasis
    realizedPnLUSD
    unrealizedPnLUSD
    lastUpdatedTimestamp
  }
}
```

* Daily performance for a vault (recent 7 days)

```graphql
query($vault: String!) {
  vaultDailySnapshots(
    first: 7
    orderBy: dayTimestamp
    orderDirection: desc
    where: { vault: $vault }
  ) {
    dayTimestamp
    sharePrice
    dailyReturn
    apr
    apyDailyProjected
  }
}
```

## Schema and behaviors

* **Vaults and factory**
  * `VaultFactory` tracks the factory and derived `vaults`.
  * `Vault` stores `totalAssets`, `totalSupply`, `totalAssetsUSD`, creation timestamp, and return/apy fields:
    * Returns: `return1Days`, `return7Days`, `return30Days`, `return90Days`, `return180Days`, `return365Days`, `returnInception`.
    * APYs: price‑based `apyPriceTrailing`, naive daily `apyDailyReturnTrailing` (+ 1/7/30/90/180/365 windows), and weekly `apyWeeklyReturnTrailing` (+ 1/4/13/26/52 weeks).
* **Events and user state**
  * `DepositEvent` and `WithdrawEvent` mirror vault actions.
  * `UserVaultBalance` maintains shares, USD value, weighted average cost basis, and realized/unrealized PnL.
  * `UserVaultTransaction` records every user‑level action including P2P share transfers.
* **Snapshots and pricing**
  * `VaultDailySnapshot` is created once per UTC day per vault; includes share/asset USD prices, dailyReturn, APR (= dailyReturn × 365), and projected APY (= (1+dailyReturn)^365 − 1).
  * `VaultWeeklySnapshot` aggregates weekly totals and `weeklyReturn`.
  * Price entities: `VaultPriceOracle` (current oracle) and `VaultAssetPrice` (last asset USD price with 8‑decimals), used to compute USD values.
* **Update cadence**
  * On each deposit/withdraw: updates vault totals, USD values, user balances, cost basis, PnL, creates events and transactions, and refreshes daily/weekly snapshots and APYs for that block’s UTC day.
  * On P2P share `Transfer`: adjusts sender/receiver balances, cost basis (receiver), and unrealized PnL; does not change vault totals.
  * Once per UTC day per vault: first block that lands in a new day bucket creates/updates `VaultDailySnapshot` and recomputes trailing APYs; weekly buckets are maintained similarly.
* **GraphQL tips**
  * All list fields support `where`, `orderBy`, `orderDirection`, `first/skip`, and `block` for historical queries.
  * IDs: snapshots use `vaultAddress-<dayTimestamp|weekTimestamp>`.


---

# 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://docs.more.markets/more-vaults/developer-workflows/using-the-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.
