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

# Risk Manager

> RiskManager enforces deposit/redeem guardrails for a fund. Both queues route every user request through Fund.checkDeposit / Fund.checkRedeem, which the Fund proxies here; a violate

> Source: [`src/RiskManager.sol`](https://github.com/zentryHQ/red-potion-contract/blob/main/src/RiskManager.sol)

## Responsibility

`RiskManager` enforces **deposit/redeem guardrails** for a fund. Both queues route every user request through `Fund.checkDeposit` / `Fund.checkRedeem`, which the Fund proxies here; a violated limit reverts the whole request.

All value comparisons are made **in the fee base asset**: a deposit of asset X is first converted to shares at X's last accepted price, then valued at the base asset's price (`value = amount × 1e18 / assetPrice × basePrice / 1e18`). The valuation context comes from `Fund.getRiskContext`.

Every limit is **optional — a zero value disables that check**. If no valuation-based check is enabled, price lookups are skipped entirely (so deposits work even without prices, e.g. the very first batch).

| Control                                    | Check applied                                                                                                          |
| ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- |
| `isEmergencyPaused`                        | Blocks **all** deposits and redemptions immediately.                                                                   |
| `merkleRoot` (whitelist)                   | Depositor must prove membership: leaf = `keccak256(keccak256(abi.encode(depositor)))` (OZ double-hash). Deposits only. |
| `maxDrawdownBps`                           | Blocks deposits when the base price has fallen more than this far below the HWM.                                       |
| `minDepositAmount` / `minRedeemAmount`     | Minimum request size, valued in the base asset.                                                                        |
| `maxBatchDepositCap` / `maxBatchRedeemCap` | Cap on total value queued per batch (existing total + this request).                                                   |
| `tvlCap`                                   | Cap on fund TVL (`shareSupply × basePrice / 1e18` + this deposit). Deposits only.                                      |

Checks run at **request time** against `lastAcceptedPrice`; the batch settles at the *next* accepted price. Admin functions authorize against the **Fund's** access control.

## Function reference

### Validation

| Function                                                 | Description                                                                                                                                                                                                                                                                                                                                |
| -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `checkDeposit(depositor, asset, batchId, amount, proof)` | Runs, in order: emergency pause → merkle whitelist → drawdown → min deposit → batch deposit cap → TVL cap. Reverts on the first violation (`EmergencyPausedError`, `NotWhitelisted`, `DrawdownBreached`, `DepositBelowMinimum`, `BatchDepositCapExceeded`, `TvlCapExceeded`, `BaseAssetPriceUnavailable`, `DepositAssetPriceUnavailable`). |
| `checkRedeem(batchId, shares)`                           | Runs: emergency pause → min redeem → batch redeem cap (`RedeemBelowMinimum`, `BatchRedeemCapExceeded`).                                                                                                                                                                                                                                    |

### Estimates

| Function                         | Description                                                                             |
| -------------------------------- | --------------------------------------------------------------------------------------- |
| `estimateDeposit(asset, amount)` | Shares the user would receive at current prices after entry fee. Returns 0 if no price. |
| `estimateRedeem(asset, shares)`  | Assets the user would receive at current prices after exit fee. Returns 0 if no price.  |

<Info>
  Both are estimates only — actual settlement uses the next accepted report's price.
</Info>

### Admin setters

All roles are checked on the Fund. A value of `0` disables the corresponding check.

| Function                                                   | Role                          | Description                                                   |
| ---------------------------------------------------------- | ----------------------------- | ------------------------------------------------------------- |
| `setTvlCap(cap)`                                           | `SET_TVL_CAP_ROLE`            | Max TVL in base-asset value.                                  |
| `setMaxBatchDepositCap(cap)` / `setMaxBatchRedeemCap(cap)` | `SET_BATCH_CAPS_ROLE`         | Per-batch value caps.                                         |
| `setMinDepositAmount(amount)`                              | `SET_MIN_DEPOSIT_AMOUNT_ROLE` | Minimum deposit value.                                        |
| `setMinRedeemAmount(amount)`                               | `SET_MIN_REDEEM_AMOUNT_ROLE`  | Minimum redemption value.                                     |
| `setMaxDrawdown(bps)`                                      | `SET_MAX_DRAWDOWN_ROLE`       | Max drawdown below HWM before deposits are blocked (≤ 10000). |
| `setMerkleRoot(root)`                                      | `SET_WHITELIST_ROLE`          | Depositor whitelist root (`bytes32(0)` disables).             |
| `emergencyPause()` / `emergencyUnpause()`                  | `EMERGENCY_PAUSE_ROLE`        | Instant kill switch for deposits and redemptions.             |

## Views

`tvlCap`, `maxBatchDepositCap`, `maxBatchRedeemCap`, `minDepositAmount`, `minRedeemAmount`, `maxDrawdownBps`, `isEmergencyPaused`, `merkleRoot`, `fund()` — all public state.

## Related

[Fund](/developers/contract-reference/fund) · [Risk Controls (user guide)](/using-redpotion/risk-controls)
