# VaultAdmin

**Inherits:** IVaultAdmin, Initializable, AccessControl, ReentrancyGuardUpgradeable, VaultAssetRegistryAdmin, VaultFundraiseAdmin, VaultWhitelistAdmin, Pausable

Contains the admin functions, constructor, initializer, immutable variables and state checking for AriaIPRWAVault.

## Functions

### initFundraise

Initializes the vault for fundraise.

*Can not initialize both a fundraise and a whitelist vault.*

```solidity
function initFundraise(
    address admin,
    StoryAddrs memory storyAddrs,
    AriaIPRWAVaultStorage.FractionalTokenDetails memory tokenDetails,
    VaultFundraiseStorage.Setup memory fundraiseSetup,
    uint48 mintTimelockDuration,
    uint256 claimDeadline,
    address legal
) public override initializer;
```

**Parameters**

| Name                   | Type                                           | Description                                                                                        |
| ---------------------- | ---------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| `admin`                | `address`                                      | The address of the admin of the vault                                                              |
| `storyAddrs`           | `StoryAddrs`                                   | The addresses of the Story Protocol's contracts - zero addr check is done in the factory contract. |
| `tokenDetails`         | `AriaIPRWAVaultStorage.FractionalTokenDetails` | The details of the fractional token to be deployed                                                 |
| `fundraiseSetup`       | `VaultFundraiseStorage.Setup`                  | The setup of the fundraise                                                                         |
| `mintTimelockDuration` | `uint48`                                       | The timelock duration (in seconds) for admin fractional token mints.                               |
| `claimDeadline`        | `uint256`                                      | The deadline for the users to claim the fractional token.                                          |
| `legal`                | `address`                                      | The address of the legal contract that checks blacklist and license.                               |

### initWhitelist

Initializes the vault for whitelist.

*Can not initialize both a fundraise and a whitelist vault.*

```solidity
function initWhitelist(
    address admin,
    StoryAddrs memory storyAddrs,
    AriaIPRWAVaultStorage.FractionalTokenDetails memory tokenDetails,
    bytes32 merkleRoot,
    uint48 mintTimelockDuration,
    uint256 claimDeadline,
    address legal
) public override initializer;
```

**Parameters**

| Name                   | Type                                           | Description                                                                                        |
| ---------------------- | ---------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| `admin`                | `address`                                      | The address of the admin of the vault                                                              |
| `storyAddrs`           | `StoryAddrs`                                   | The addresses of the Story Protocol's contracts - zero addr check is done in the factory contract. |
| `tokenDetails`         | `AriaIPRWAVaultStorage.FractionalTokenDetails` | The details of the fractional token to be deployed                                                 |
| `merkleRoot`           | `bytes32`                                      | The merkle root of the whitelist                                                                   |
| `mintTimelockDuration` | `uint48`                                       | The timelock duration (in seconds) for admin fractional token mints.                               |
| `claimDeadline`        | `uint256`                                      | The deadline for the users to claim the fractional token.                                          |
| `legal`                | `address`                                      | The address of the legal contract that checks blacklist and license.                               |

### amIAdmin

*Simplest self admin check*

```solidity
function amIAdmin() external view returns (bool);
```

### execFractionalTokenMint

Executes a previously initiated fractional token mint after the timelock duration.

*Can be triggered by anyone. Checks if the timelock has passed and transfers the tokens. Resets the pending mint state. Reverts if no mint is pending or the timelock has not been reached.*

```solidity
function execFractionalTokenMint() external override nonReentrant;
```

### execTimelockUpdate

Executes a previously initiated update to the admin fractional token mint duration.

*Can only be called by anyone. Checks if the timelock has passed and updates the duration. Resets the pending duration update state. Reverts if no duration update is pending or the timelock has not been reached.*

```solidity
function execTimelockUpdate() external nonReentrant;
```

### initFractionalTokenMint

Initiates a timelocked mint of the vault's fractional tokens by the admin.

*Can only be called by the owner. Records the mint details and sets the unlock timestamp. A mint must be executed via `execFractionalTokenMint` at/after the timelock passes. Reverts if there is already a pending mint.*

```solidity
function initFractionalTokenMint(address recipient, uint256 amount)
    external
    override
    onlyRole(AccessControlStorage.DEFAULT_ADMIN_ROLE)
    nonReentrant;
```

**Parameters**

| Name        | Type      | Description                               |
| ----------- | --------- | ----------------------------------------- |
| `recipient` | `address` | The address to receive the minted tokens. |
| `amount`    | `uint256` | The amount of fractional tokens to mint.  |

### initTimelockUpdate

Initiates a timelocked update for the admin fractional token mint duration.

*Can only be called by the owner. Uses the current timelock duration for the delay. A duration update must be executed via `execTimelockUpdate` after the timelock passes. Reverts if there is already a duration update pending.*

```solidity
function initTimelockUpdate(uint48 newDuration)
    external
    onlyRole(AccessControlStorage.DEFAULT_ADMIN_ROLE)
    nonReentrant;
```

**Parameters**

| Name          | Type     | Description                           |
| ------------- | -------- | ------------------------------------- |
| `newDuration` | `uint48` | The proposed new duration in seconds. |

### recoverLostTokens

Recovers lost tokens

*Only the admin can recover lost tokens, including fractional tokens as they are minted not sent to the vault.*

```solidity
function recoverLostTokens(address token, address to)
    external
    override
    onlyRole(AccessControlStorage.DEFAULT_ADMIN_ROLE);
```

**Parameters**

| Name    | Type      | Description                              |
| ------- | --------- | ---------------------------------------- |
| `token` | `address` | The address of the token to be recovered |
| `to`    | `address` | The address of the recipient             |

### setClaimDeadline

```solidity
function setClaimDeadline(uint256 newClaimDeadline) external onlyRole(AccessControlStorage.DEFAULT_ADMIN_ROLE);
```

### setPauseState

```solidity
function setPauseState(bool paused_) external;
```

### \_initVault

```solidity
function _initVault(
    address admin,
    StoryAddrs memory storyAddrs,
    AriaIPRWAVaultStorage.FractionalTokenDetails memory tokenDetails,
    VaultType vaultType,
    uint48 mintTimelockDuration,
    uint256 claimDeadline,
    address legal
) internal;
```

### \_execTimelockUpdate

Internal function to execute a pending timelock duration update if the timelock has passed.

```solidity
function _execTimelockUpdate() internal;
```

### \_isTimelockUpdateReady

```solidity
function _isTimelockUpdateReady(uint48 updatemintExec) internal view returns (bool);
```

### \_getAdjustedMintAmount

Calculates the mint amount adjusted to token's cap.

```solidity
function _getAdjustedMintAmount(address fractionalTokenAddress, uint256 requestedAmount)
    internal
    view
    returns (uint256);
```

**Parameters**

| Name                     | Type      | Description                                      |
| ------------------------ | --------- | ------------------------------------------------ |
| `fractionalTokenAddress` | `address` | The address of the ERC20Capped fractional token. |
| `requestedAmount`        | `uint256` | The amount of tokens requested to be minted.     |

**Returns**

| Name     | Type      | Description                                                                                                               |
| -------- | --------- | ------------------------------------------------------------------------------------------------------------------------- |
| `<none>` | `uint256` | The actual amount that can be minted, respecting the cap. Returns 0 if the cap is already met or if requestedAmount is 0. |


---

# 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.ariaprotocol.xyz/technical-docs/contract-docs/iprwa/vault/admin/vaultadmin.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.
