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

# Units and Fees

> Understand raw token units, fixed-point values, and fee formulas

This page covers the raw units used by tranching preview math and the fee formulas that affect LP output or pending protocol LP shares.

## Units and Display Values

The examples in this section use normalized values when they say so. The program and SDK operate on raw values.

| Term                                                                        | Raw dimension                                                    | Display guidance                                                                   |
| --------------------------------------------------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| `amountBase`, `minBaseOut`                                                  | Base token smallest units                                        | Divide by the base token mint decimals                                             |
| `amountIn`, `amountInSY`, `amountOutSY`, `seniorSyAmount`, `juniorSyAmount` | SY token smallest units                                          | Divide by the SY mint decimals                                                     |
| `lpAmountIn`, `grossLpOut`, `netLpOut`, `totalLpSupply`, pending fee shares | Selected-tranche LP mint units                                   | Divide by the LP mint decimals. LP mints are initialized with the SY mint decimals |
| `syExchangeRate`                                                            | `Number` fixed-point exchange rate applied to raw SY units       | `1_000_000_000_000` means `1.0`                                                    |
| NAV values, `valueAllocated`, `lpPrice`, capacity helpers                   | `Number` fixed-point values with `1_000_000_000_000` as one unit | Convert the fixed-point scale, then apply the relevant token-decimal display rule  |
| Fee rates, utilization, coverage, `beta`, return shares                     | `Number` fixed-point ratios                                      | `1_000_000_000_000` means `1.0`; display as decimals or percentages                |

`tranchingFromNumber` removes the fixed-point scale only. It does not divide by token decimals. For example, if a 9-decimal SY amount is valued at an exchange rate of `1.0`, the raw NAV for `1` displayed SY is `1_000_000_000 * 1_000_000_000_000`. After fixed-point conversion, it is still `1_000_000_000` raw token units and should be divided by `10^9` for UI display.

## Fee Scope

Deposit and withdrawal previews apply transfer fees only. Market-update fees such as `srProtocolFee`, `jrProtocolFee`, and `juniorReturnProtocolFee` are charged during market sync, converted into pending protocol LP shares, and reflected in the market state before the deposit or withdrawal quote is calculated.

Do not subtract market-update fees again in an integration preview. Reload the market, use the current effective NAV and LP supply, then apply only the selected deposit or withdrawal fee.

All fee fields are `Number` fixed-point rates. After `tranchingNumberToRaw`, a raw fee rate of `2_000_000_000` means `0.002`, or `0.20%`.

| Flow              | Fee field used in the preview | Fee base     |
| ----------------- | ----------------------------- | ------------ |
| Senior deposit    | `seniorDepositProtocolFee`    | `grossLpOut` |
| Junior deposit    | `juniorDepositProtocolFee`    | `grossLpOut` |
| Senior withdrawal | `seniorWithdrawProtocolFee`   | `lpAmountIn` |
| Junior withdrawal | `juniorWithdrawProtocolFee`   | `lpAmountIn` |

Transfer fee rates must be less than `1.0`. If rounding makes the user's net LP output or asset output zero, the transaction fails its minimum-output check.

## Market-Update Fees

Market-update fees use NAV bases before they become LP shares:

$$
\text{seniorFeeNAV} =
\left\lfloor \text{seniorReturnShare} \times \text{srProtocolFee} \right\rfloor
$$

$$
\text{juniorGainFeeNAV} =
\left\lfloor \text{juniorNetGainAfterRecovery} \times \text{jrProtocolFee} \right\rfloor
$$

$$
\text{juniorReturnFeeNAV} =
\left\lfloor \text{juniorReturnShare} \times \text{juniorReturnProtocolFee} \right\rfloor
$$

The `*FeeNAV` values are raw fixed-point NAV values. The program converts each tranche's NAV fee into pending raw LP shares:

$$
\text{protocolFeeLpShares} =
\left\lfloor
\frac{\text{protocolFeeNAV} \times (\text{totalLpSupply} + 1)}
{\text{feeExcludedNAV} + 1_{\text{NAV}}}
\right\rfloor
$$

These market-update fees accrue only when the resulting market state is `Active`. The Junior gain fee is skipped when the net Junior gain is at or below `jrNetAssetDustTolerance`, and Senior return fees are skipped when the distributable Senior gain is at or below `srNetAssetDustTolerance`.

For deposit and withdrawal transfer-fee formulas, see [Deposit Previews](/developer-tranching/defi-integrations/deposit-previews) and [Withdrawal Previews](/developer-tranching/defi-integrations/withdrawal-previews).
