> ## 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.

# Withdrawal Previews

> Calculate withdrawal fees, asset claims, and Senior self-liquidation bonuses

Withdrawals burn LP shares and return SY through [`ixWithdraw`](/developer-tranching/typescript/instructions/ix-withdraw), or return base assets through [`ixWrapperWithdraw`](/developer-tranching/typescript/instructions/ix-wrapper-withdraw).

For raw/display units and fee-rate scale, see [Units and Fees](/developer-tranching/defi-integrations/pricing-units-and-fees).

## Withdrawal Preview Math

Withdrawal fees are charged before the redemption claim is calculated:

$$
\text{withdrawFeeLpShares} = \left\lceil \text{lpAmountIn} \times \text{withdrawFeeRate} \right\rceil
$$

$$
\text{redeemLpShares} = \text{lpAmountIn} - \text{withdrawFeeLpShares}
$$

Only `redeemLpShares` back the user's asset claim:

$$
\text{totalLpSupply}_{\text{next}} = \text{currentLpSupply} - \text{redeemLpShares}
$$

The full `lpAmountIn` is burned from the user. The fee portion remains as pending protocol LP shares and is minted later through `mintProtocolFeeShares`.

In the simple case where the selected tranche only claims its own SY side, the SY output is:

$$
\text{amountOutSY} =
\left\lfloor
\frac{\text{trancheSyAmount} \times \text{redeemLpShares}}
{\text{totalLpSupply} + 1}
\right\rfloor
$$

When the market has cross-tranche claims from loss or recovery accounting, the program first decomposes the selected tranche's effective NAV into Senior-source and Junior-source SY claims, scales each claim by `redeemLpShares / (totalLpSupply + 1)`, then sums the resulting SY amounts. See [Loss and Gain Waterfalls](/developer-tranching/concepts#loss-and-gain-waterfalls).

`lpAmountIn`, `withdrawFeeLpShares`, and `redeemLpShares` are raw LP units. `amountOutSY` is raw SY units. If the integration uses [`ixWrapperWithdraw`](/developer-tranching/typescript/instructions/ix-wrapper-withdraw), `minBaseOut` is raw base token units after the SY redemption step.

## Senior Self-Liquidation Bonus

This branch applies only to Senior withdrawals. It is triggered when the market utilization has reached the configured liquidation threshold:

$$
\text{state.financials.utilization} \ge \text{state.riskConfig.liquidationUtilization}
$$

Read `state.financials.utilization`, `state.riskConfig.liquidationUtilization`, and `state.riskConfig.srSelfLiquidationBonus`. The bonus is based on the Senior user's claim after withdrawal fees and before the bonus is added.

The program first computes the desired bonus in raw fixed-point NAV:

$$
\text{desiredBonusNAV} =
\left\lfloor
\text{baseClaimNAV} \times \text{srSelfLiquidationBonus}
\right\rfloor
$$

Then it caps the result:

$$
\text{nominalBonusNAV} =
\min(
\text{desiredBonusNAV},
\text{jrEffectiveNAV},
\text{maxUtilizationNeutralBonusNAV}
)
$$

`maxUtilizationNeutralBonusNAV` is the internal cap that prevents the bonus from increasing post-withdraw utilization. With:

$$
E = \text{srRawNAV} + \operatorname{ceilFixed}(\text{jrRawNAV} \times \beta)
$$

$$
W =
\text{seniorClaimFromSeniorNAV}
+ \left\lfloor \text{seniorClaimFromJuniorNAV} \times \beta \right\rfloor
$$

$$
C_s = \text{juniorClaimOnSeniorRawNAV}
$$

the first cap is:

$$
\text{seniorSourceCap} =
\left\lfloor
\frac{W \times \text{jrEffectiveNAV}}
{E - \text{jrEffectiveNAV}}
\right\rfloor
$$

If `seniorSourceCap <= C_s`, the program uses `seniorSourceCap`. Otherwise it uses the mixed-source cap:

$$
\text{mixedSourceCap} =
\left\lfloor
\frac{
\left(W + \left\lfloor C_s \times (1 - \beta) \right\rfloor\right)
\times \text{jrEffectiveNAV}
}
{E - \left\lfloor \text{jrEffectiveNAV} \times \beta \right\rfloor}
\right\rfloor
$$

If either cap denominator is zero, the program treats that cap as zero.

After the cap is selected, the bonus NAV is converted back into raw SY units with floor rounding:

$$
\text{bonusSeniorSY} =
\left\lfloor
\frac{\min(\text{nominalBonusNAV}, C_s)}
{\text{syExchangeRate}}
\right\rfloor
$$

$$
\text{bonusJuniorSY} =
\left\lfloor
\frac{\text{nominalBonusNAV} - \min(\text{nominalBonusNAV}, C_s)}
{\text{syExchangeRate}}
\right\rfloor
$$

The Senior withdrawal output becomes:

$$
\text{amountOutSY} =
\text{baseAmountOutSY} + \text{bonusSeniorSY} + \text{bonusJuniorSY}
$$

## Withdrawal Example

Assume a Junior withdrawal in a market with no cross-tranche claims:

| Input                       | Value              |
| --------------------------- | ------------------ |
| `lpAmountIn`                | `1,000` Junior LP  |
| `juniorWithdrawProtocolFee` | `0.10%`            |
| `totalJuniorLpSupply`       | `10,000` Junior LP |
| `juniorSyAmount`            | `10,000` SY        |

Then:

$$
\text{withdrawFeeLpShares} = \left\lceil 1{,}000 \times 0.001 \right\rceil = 1
$$

$$
\text{redeemLpShares} = 1{,}000 - 1 = 999
$$

$$
\text{amountOutSY} =
\left\lfloor
\frac{10{,}000 \times 999}{10{,}000 + 1}
\right\rfloor
= 998
$$

The user burns `1,000` Junior LP and receives `998` SY before any wrapper redemption into the base asset. Market accounting total Junior LP supply decreases by `999`, from `10,000` to `9,001`, and `1` Junior LP share is added to pending withdrawal protocol fees.

If using [`ixWrapperWithdraw`](/developer-tranching/typescript/instructions/ix-wrapper-withdraw), the SY is redeemed through the linked SY program after the tranching withdrawal.

<Warning>
  Senior withdrawals can include a [self-liquidation bonus](#senior-self-liquidation-bonus) when utilization is at or above `liquidationUtilization`. Do not approximate this path for liquidation or lending logic from the simplified formula alone. Read `state.financials.utilization`, `state.riskConfig.liquidationUtilization`, and use conservative `minAmountOut` or `minBaseOut` bounds.
</Warning>
