# Zenji Vault

> The core ERC-4626 vault contract. Handles share accounting, collateralized leverage, strategy deployment, and unwind logic for withdrawals.

## Core Components

- **Zenji (ERC-4626)** — deposits, share mint/burn, fee accounting, rebalancing, emergency controls.
- **Loan Manager** — collateral/debt position, health checks, collateral/debt conversion pricing.
- **Yield Strategy** — deploys borrowed debt asset, reports strategy value, harvests rewards.

## Two Forms of Collateral Value

`getTotalCollateral()` exposes value in collateral units from:

1. **Direct collateral inventory** — balances in vault + loan manager.
2. **Debt-side value** — strategy and idle debt assets converted to collateral-equivalent via loan manager pricing.

Shares represent one unified collateral-denominated claim while the strategy side stays in debt-asset form.

## User-Facing Functions

- `deposit(assets, receiver)` — deposit collateral, mint shares.
- `mint(shares, receiver)` — mint exact shares.
- `withdraw(assets, receiver, owner)` — withdraw exact collateral.
- `redeem(shares, receiver, owner)` — burn shares for collateral.

Withdrawals can partially or fully unwind debt/strategy positions depending on size and liquidity.

## Permissionless Maintenance

- `rebalance()` — adjust LTV when outside deadband.
- `harvestYield()` — claim and compound strategy rewards.
- `accrueYieldFees()` — realize protocol fees from strategy profit deltas.

## Strategy Balance vs Debt Balance

- `strategyToDebtRatio()` — ratio in 1e18 precision (÷ 1e16 for %; target ≈ 100%).
- `DEADBAND_SPREAD()` — allowed drift band around 100% (same precision).
- Historical ratio: `GET /api/vault/:address/history`. Pre-borrow snapshots (zero debt and strategy balance) produce extraneous values and are filtered in the UI.

## Bounded Parameters (Owner)

| Parameter | Range |
|-----------|-------|
| Target LTV | 15% – 65% |
| Fee rate | max 20% |
| Rebalance bounty | max 50% |
| Vault max slippage | max 10% |

## Risk Controls

- Deadband rebalancing around target LTV
- Oracle freshness checks on loan-manager pricing
- Reentrancy protection on state-changing entry points
- One-block action delay (anti same-block transfer/redeem bypass)
- Emergency mode one-way latch with staged unwind

Emergency mode is for controlled unwind and pro-rata exits — not a reversible pause switch.