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

# Calculate Vault & Loop Metrics

This guide walks through how to compute Vault TVL, Vault APY, rewards APY, and Loop APY using Loopscale's data endpoints. These are the key metrics for building dashboards, portfolio trackers, or any integration that displays Loopscale yield data.

## Vault Metrics

Use the [Get Vaults](/api-reference/data/vaults/get-vaults) endpoint to retrieve Vault data. You can also query the [Get Vault Depositors](/api-reference/data/user/get-vault-depositors) endpoint for depositor-level breakdowns.

All of the fields referenced below are located in the `vaultStrategy` object of the response.

**Example request:**

```bash Example theme={null}
curl -X POST https://tars.loopscale.com/v1/markets/lending_vaults/info \
  -H "Content-Type: application/json" \
  -d '{
    "page": 0,
    "pageSize": 10,
    "includeRewards": true
  }'
```

### Computing Vault TVL

Sum the following fields from `vaultStrategy.strategy`:

```javascript Example theme={null}
const SECONDS_PER_YEAR = 31_536_000;

const vaultTvl =
  strategy.tokenBalance
  + strategy.externalYieldAmount
  + strategy.currentDeployedAmount
  + strategy.outstandingInterestAmount;
```

| <div className="lg-cell">Field</div> | <div className="grow-cell">Description</div>     |
| :----------------------------------- | :----------------------------------------------- |
| `tokenBalance`                       | Idle tokens held in the Vault                    |
| `externalYieldAmount`                | Tokens deployed to external yield sources        |
| `currentDeployedAmount`              | Tokens currently lent out through the order book |
| `outstandingInterestAmount`          | Accrued interest not yet repaid                  |

### Computing Vault APY

The total Vault APY that a depositor earns is the sum of two components, the **lending APY** from order-book interest, and the **rewards APY** from any active token incentive schedules.

<Tabs>
  <Tab title="Lending APY">
    This blends the interest earned from order-book lending with the yield from any external yield source, normalized over the total TVL.

    ```javascript Example theme={null}
    const orderBookInterest = strategy.interestPerSecond * SECONDS_PER_YEAR;
    const externalYield = externalYieldInfo.apy * strategy.externalYieldAmount;

    const lendingApy = (orderBookInterest + externalYield) / vaultTvl;
    ```
  </Tab>

  <Tab title="Rewards APY">
    If the Vault has active reward emissions, they are available in the `vaultRewardsSchedule` array on the response. Each entry represents a token emission schedule.

    For each schedule:

    1. Verify the schedule is active by checking that the current time falls between `rewardStartTime` and `rewardEndTime`.
    2. Compute the annualized value of emissions. Since rewards can be denominated in various tokens, you will need to source the token price externally.

    ```javascript Example theme={null}
    // For each active reward schedule
    const isActive =
      now >= schedule.rewardStartTime
      && now <= schedule.rewardEndTime;

    if (isActive) {
      // Convert from lamports
      const emissionsPerSecond = Number(schedule.emissionsPerSecond) / 1e9;
      const annualRewardValue = emissionsPerSecond * SECONDS_PER_YEAR * rewardTokenPrice;
      const rewardsApy = annualRewardValue / vaultTvl;
    }
    ```

    <Note>
      If multiple reward schedules are active, sum their individual APYs to get the total rewards APY.
    </Note>
  </Tab>
</Tabs>

#### Calculating Total APY

The following combines both components into a single calculation:

```javascript Example highlight={21-22} theme={null}
// 1. Lending APY from order-book interest + external yield
const orderBookInterest = strategy.interestPerSecond * SECONDS_PER_YEAR;
const externalYield = externalYieldInfo.apy * strategy.externalYieldAmount;
const lendingApy = (orderBookInterest + externalYield) / vaultTvl;

// 2. Rewards APY from all active incentive schedules
let totalRewardsApy = 0;

for (const schedule of vaultRewardsSchedule) {
  const isActive =
    now >= schedule.rewardStartTime
    && now <= schedule.rewardEndTime;

  if (isActive) {
    const emissionsPerSecond = Number(schedule.emissionsPerSecond) / 1e9;
    const annualRewardValue = emissionsPerSecond * SECONDS_PER_YEAR * rewardTokenPrice;
    totalRewardsApy += annualRewardValue / vaultTvl;
  }
}

// 3. Total Vault APY
const totalVaultApy = lendingApy + totalRewardsApy;
```

## Loop Metrics

Use the [Get Loop Info](/api-reference/data/loops/get-loop-info) endpoint to retrieve Loop data. You can filter by:

* **Loop identifiers** — either the slug (e.g. `acred-usdg`) or the mints formatted as `{PRINCIPAL_MINT}-{COLLATERAL_MINT}`
* **Tags** — e.g. `Stablecoin`, `Exponent`, `Hylo`, etc.

**Example request:**

```bash Example  theme={null}
curl -X POST https://tars.loopscale.com/v1/markets/loop/info \
  -H "Content-Type: application/json" \
  -d '{
    "identifiers": ["acred-usdg"]
  }'
```

### Total Looped Assets

The `collateralDeposited` field returns the total assets deposited into the Loop, in decimal-scaled value.

```javascript Example  theme={null}
const totalLoopedAssets = loopInfo.collateralDeposited;
```

### Computing Loop APY

Use the `wAvgApy` field, which represents the current weighted-average APY across all active positions, weighted by size.

```javascript Example  theme={null}
// Prefer wAvgApy over maxApy for display
const loopApy = loopInfo.wAvgApy;
```

<Warning>
  Avoid using `maxApy` for display purposes. If borrow liquidity is exhausted, `maxApy` may be empty or pull from a small strategy with an unrealistically high or low yield. `wAvgApy` is more reliable and representative of actual user returns.
</Warning>
