# Vault

## Overview

The `Vault` contract is the central entry point in the Flexible Vault system. It composes three foundational modules:

* `ACLModule`: Role-based access control.
* `ShareModule`: Management of user-facing shares, including deposit and redemption processes.
* `VaultModule`: Subvault management.

This contract allows secure, extensible, and upgradeable vault implementations by coordinating all external and internal interactions within the system. It is typically instantiated through `Factory` or `VaultConfigurator` and initialized with all the required components and role assignments in a single atomic transaction.

## Inheritance Structure

```solidity
contract Vault is IFactoryEntity, VaultModule, ShareModule, ACLModule
```

The contract inherits three modules:

* `ACLModule`: Admin and permission management
* `ShareModule`: Deposits, redemptions, share management
* `VaultModule`: Subvault delegation control

It also implements the `IFactoryEntity` interface for standard factory-based deployment patterns.

## Constructor

```solidity
constructor(
    string memory name_,
    uint256 version_,
    address depositQueueFactory_,
    address redeemQueueFactory_,
    address subvaultFactory_,
    address verifierFactory_
)
```

### Parameters:

* `name_`: Unique name identifier for the vault instance
* `version_`: Configuration version of the vault
* `depositQueueFactory_`: Address of the factory used to deploy deposit queues
* `redeemQueueFactory_`: Address of the factory used to deploy redemption queues
* `subvaultFactory_`: Address of the factory used to deploy subvaults
* `verifierFactory_`: Address of the factory for deploying verifier contracts

### Behavior:

Passes these arguments to the parent module constructors:

* `ACLModule(name_, version_)`
* `ShareModule(name_, version_, depositQueueFactory_, redeemQueueFactory_)`
* `VaultModule(name_, version_, subvaultFactory_, verifierFactory_)`

## Structs

### `RoleHolder`

```solidity
struct RoleHolder {
    bytes32 role;
    address holder;
}
```

Used to batch-assign multiple roles during initialization. Each entry maps a role identifier to a designated address.

## External Functions

### `initialize`

```solidity
function initialize(bytes calldata initParams) external initializer
```

Initializes the vault instance. Can only be called once due to the `initializer` modifier.

### `initParams` structure (ABI-encoded):

```solidity
(
    address admin_,
    address shareManager_,
    address feeManager_,
    address riskManager_,
    address oracle_,
    address defaultDepositHook_,
    address defaultRedeemHook_,
    uint256 queueLimit_,
    RoleHolder[] roleHolders
)
```

### Initialization Logic:

* Calls `__ACLModule_init(admin_)` to configure the default admin.
* Calls `__ShareModule_init(...)` to link share management and hook modules.
* Calls `__VaultModule_init(riskManager_)` to initialize risk management.
* Iterates over `roleHolders` and grants each role using `_grantRole(...)`.
* Emits `Initialized(initParams)`.

## Design Notes

* **Modular Composition**: The vault is composed by inheriting three upgradeable modules, enabling reuse and flexible configuration.
* **Factory-Compatible**: The contract is factory-deployable and supports atomic configuration during creation.
* **Centralized Control Layer**: Acts as a trusted coordinator for hooks, queues, shares, and strategy logic.
* **Role Assignment**: Enables full delegation of operational control via batched `RoleHolder` entries.
* **Upgradeable and Isolated**: Each module manages its own storage via deterministic slots (`SlotLibrary`) to support safe upgrades.

## Events

### `Initialized(bytes data)`

Emitted after successful initialization. Includes all parameters passed for transparency.


---

# 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://metavaults.mellow.finance/architecture/vaults/vault.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.
