# RedirectingDepositHook

### Overview

`RedirectingDepositHook` is a deposit-time liquidity allocation hook implementing the `IHook` interface. It is designed to **redirect newly deposited assets** from a vault into its underlying **subvaults**, based on per-subvault risk and capacity constraints defined by a `RiskManager`.

This hook helps distribute liquidity optimally during deposit flows.

### Purpose

* Automatically **forwards newly deposited assets** from the main vault into eligible subvaults.
* Delegates decision-making to the vault’s configured `RiskManager`, which determines per-subvault deposit limits.
* Ensures that **subvaults do not exceed their capacity constraints**.

### Key Function

### `callHook(address asset, uint256 assets)`

Distributes a given amount of `asset` across available subvaults based on their individual deposit capacity.

**Execution Logic:**

1. Retrieves:
   * Active `vault` context via `IVaultModule(address(this))`
   * Configured `RiskManager` via `vault.riskManager()`
   * Number of subvaults via `vault.subvaults()`
2. Iterates over each subvault:
   * Fetches max allowed deposit via `riskManager.maxDeposit(subvault, asset)`
   * If allowed amount is zero → skip
   * Otherwise:
     * Pushes `min(assets, allowed)` via `vault.hookPushAssets()`
     * Decrements `assets` accordingly
     * Stops early if full amount has been distributed

### Components and Assumptions

* **Vault:** Must implement `IVaultModule`:
  * `subvaults()` → number of subvaults
  * `subvaultAt(index)` → returns subvault address
  * `hookPushAssets(subvault, asset, amount)` → transfers tokens to subvault
  * `riskManager()` → returns associated `IRiskManager`
* **Risk Manager:** Must implement:
  * `maxDeposit(subvault, asset)` → returns max allowed deposit into that subvault


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mellow.finance/core-vaults/architecture/hooks/redirectingdeposithook.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
