# Monitoring and reporting

> The on-chain views and events that show a vault's current rates, accrued fees and fee income, and how to report fee income from them.

Source: https://docs.trusslabs.io/vaults/fees/monitoring-and-reporting

Everything about a vault's fees can be read on chain: the rates in force, their ceilings, what has accrued, and
every fee share paid. This page lists the views and events to read, and a simple way to report fee income from
them.

> **Key points**
>
> - Four views give the current rates, their ceilings, the fee recipient and the fees owed but not yet minted.
> - Fee income arrives as share transfers to the fee recipient, each tied to an event that says what it was for.
> - Value each fee at the share price when it arrived, and add what is accrued but not yet minted.
> - Prices read as whole USDC per whole share at 18 decimals, so `1e18` is 1 USDC a share.

## Views

| View | What it returns |
|---|---|
| `feeRates()` | The five rates in force, in bps, with management per year |
| `feeCeilings()` | Each rate's ceiling and the round-trip ceiling, fixed at deployment |
| `feeRecipient()` | The address fee shares are paid to |
| `accruedFees()` | Fees owed but not yet minted, in USDC. It reverts while the NAV is stale |
| `queuedFeeAssets()` | The part of that set aside by instant redemptions, in USDC |
| `highWaterMark()` | The performance fee's mark, in USDC per share at 18 decimals |

`totalAssets()` and `convertToAssets` are already net of every fee owed. On the factory, `delaysOf(vault)` gives the
seconds each delay tier lasts on that vault.

## Events

| Event | Emitted when | What it tells you |
|---|---|---|
| `FeesCrystallised(liveAssets, queuedAssets, shares)` | Accrued fees are turned into shares, if any had accrued | `shares` minted to the recipient for `liveAssets + queuedAssets` USDC of fees |
| `RequestFilled(..., feeShares, ...)` | Each fill in a settlement or an instant redemption | The entry or exit fee shares on that fill |
| `Settled(kind, priceWad, requestIds, feeShares)` | Each settlement batch | The batch's price and its entry or exit fee shares |
| `InstantRedeemed(..., feeShares, ..., priceWad)` | Each instant redemption | The exit and instant fee shares together, and the price |
| `FeeRateChanged(rateIndex, oldBps, newBps)` | A rate is raised or lowered | `rateIndex` is 0 entry, 1 exit, 2 management, 3 performance, 4 instant redemption |
| `FeeRecipientSet(previous, current)` | The recipient changes | Where fees go from now |
| `HighWaterMarkReset(oldMarkWad, newMarkWad)` | The mark is reset | The mark before and after |

A raise waiting its delay shows first as `OperationScheduled` on the vault's AccessManager, with the full call. A
cancelled request emits `RequestCancelled(requestId, controller, returned)` and carries no fee, since cancelling
is free. `VaultInitialized` records every ceiling the vault was deployed with.

## Reporting fee income

1. Index the ERC-20 `Transfer` events to the fee recipient. A mint from the zero address is an entry fee or a
   crystallisation; a transfer from the vault is an exit fee.
2. Value each one in USDC. `FeesCrystallised` gives the USDC value directly. Value entry and exit fees at the
   `priceWad` of the `Settled` or `InstantRedeemed` event in the same transaction.
3. At the end of the period, add `accruedFees()` for what is owed but not yet minted.
4. The recipient's shares are worth `convertToAssets(balanceOf(feeRecipient))` today. Fee shares gain and lose
   with the vault after they arrive, so that differs from the sum of what was paid.

The instant fee never reaches the recipient. Its shares are burned, so it shows only in `InstantRedeemed.feeShares`
less the exit fee's transfer.

## Where to read more

| Page | What it covers |
|---|---|
| [How you get paid](https://docs.trusslabs.io/vaults/fees/how-you-get-paid.md) | When each fee arrives and how to redeem it |
| [Reading vault state](https://docs.trusslabs.io/vaults/developers/reading-state.md) | Every view an integration reads |
| [How to update fees](https://docs.trusslabs.io/vaults/overview/updating-fees.md) | The changes behind `FeeRateChanged` and the other events |
