# AeraVaultHooks

## AeraVaultHooks

**Inherits:** IHooks, IAeraVaultHooksEvents, Sweepable, ERC165

Default hooks contract which implements several safeguards.

*Connected vault MUST only call submit with tokens that can increase allowances with approve and increaseAllowance.*

### State Variables

#### \_LOWEST\_MIN\_DAILY\_VALUE

Min bound on minimum fraction of vault value that the vault has to retain between submissions during a single day.

*Loose bound to mitigate initialization error.*

```solidity
uint256 private constant _LOWEST_MIN_DAILY_VALUE = ONE / 2;
```

#### minDailyValue

The minimum fraction of vault value that the vault has to retain per day during submit transactions. e.g. 0.9 (in 18-decimal form) allows the vault to lose up to 10% in value across consecutive submissions.

```solidity
uint256 public immutable minDailyValue;
```

#### vault

STORAGE ///

The address of the vault.

```solidity
address public vault;
```

#### currentDay

Current day (UTC).

```solidity
uint256 public currentDay;
```

#### cumulativeDailyMultiplier

Accumulated value multiplier during submit transactions.

```solidity
uint256 public cumulativeDailyMultiplier;
```

#### \_targetSighashAllowed

Allowed target contract and sighash combinations.

```solidity
mapping(TargetSighash => bool) internal _targetSighashAllowed;
```

#### \_beforeValue

Total value of assets in vault before submission.

*Assigned in `beforeSubmit` and used in `afterSubmit`.*

```solidity
uint256 internal _beforeValue;
```

### Functions

#### onlyVault

MODIFIERS ///

*Throws if called by any account other than the vault.*

```solidity
modifier onlyVault();
```

#### constructor

FUNCTIONS ///

```solidity
constructor(
    address owner_,
    address vault_,
    uint256 minDailyValue_,
    TargetSighashData[] memory targetSighashAllowlist
) Ownable;
```

**Parameters**

| Name                     | Type                  | Description                                                                                             |
| ------------------------ | --------------------- | ------------------------------------------------------------------------------------------------------- |
| `owner_`                 | `address`             | Initial owner address.                                                                                  |
| `vault_`                 | `address`             | Vault address.                                                                                          |
| `minDailyValue_`         | `uint256`             | The minimum fraction of value that the vault has to retain during the day in the course of submissions. |
| `targetSighashAllowlist` | `TargetSighashData[]` | Array of target contract and sighash combinations to allow.                                             |

#### addTargetSighash

Add targetSighash pair to allowlist.

```solidity
function addTargetSighash(
    address target,
    bytes4 selector
) external onlyOwner;
```

**Parameters**

| Name       | Type      | Description           |
| ---------- | --------- | --------------------- |
| `target`   | `address` | Address of target.    |
| `selector` | `bytes4`  | Selector of function. |

#### removeTargetSighash

Remove targetSighash pair from allowlist.

```solidity
function removeTargetSighash(
    address target,
    bytes4 selector
) external onlyOwner;
```

**Parameters**

| Name       | Type      | Description           |
| ---------- | --------- | --------------------- |
| `target`   | `address` | Address of target.    |
| `selector` | `bytes4`  | Selector of function. |

#### beforeDeposit

Hook that runs before deposit.

*MUST revert if not called by vault.*

```solidity
function beforeDeposit(AssetValue[] memory amounts)
    external
    override
    onlyVault;
```

**Parameters**

| Name      | Type           | Description                                       |
| --------- | -------------- | ------------------------------------------------- |
| `amounts` | `AssetValue[]` | Struct details for assets and amounts to deposit. |

#### afterDeposit

Hook that runs after deposit.

*MUST revert if not called by vault.*

```solidity
function afterDeposit(AssetValue[] memory amounts)
    external
    override
    onlyVault;
```

**Parameters**

| Name      | Type           | Description                                       |
| --------- | -------------- | ------------------------------------------------- |
| `amounts` | `AssetValue[]` | Struct details for assets and amounts to deposit. |

#### beforeWithdraw

Hook that runs before withdraw.

*MUST revert if not called by vault.*

```solidity
function beforeWithdraw(AssetValue[] memory amounts)
    external
    override
    onlyVault;
```

**Parameters**

| Name      | Type           | Description                                        |
| --------- | -------------- | -------------------------------------------------- |
| `amounts` | `AssetValue[]` | Struct details for assets and amounts to withdraw. |

#### afterWithdraw

Hook that runs after withdraw.

*MUST revert if not called by vault.*

```solidity
function afterWithdraw(AssetValue[] memory amounts)
    external
    override
    onlyVault;
```

**Parameters**

| Name      | Type           | Description                                        |
| --------- | -------------- | -------------------------------------------------- |
| `amounts` | `AssetValue[]` | Struct details for assets and amounts to withdraw. |

#### beforeSubmit

Hook that runs before submit.

*MUST revert if not called by vault.*

```solidity
function beforeSubmit(Operation[] calldata operations)
    external
    override
    onlyVault;
```

**Parameters**

| Name         | Type          | Description                                                |
| ------------ | ------------- | ---------------------------------------------------------- |
| `operations` | `Operation[]` | Array of struct details for target and calldata to submit. |

#### afterSubmit

Hook that runs after submit.

*MUST revert if not called by vault.*

```solidity
function afterSubmit(Operation[] calldata operations)
    external
    override
    onlyVault;
```

**Parameters**

| Name         | Type          | Description                                                |
| ------------ | ------------- | ---------------------------------------------------------- |
| `operations` | `Operation[]` | Array of struct details for target and calldata to submit. |

#### beforeFinalize

Hook that runs before finalize.

*MUST revert if not called by vault.*

```solidity
function beforeFinalize() external override onlyVault;
```

#### afterFinalize

Hook that runs after finalize.

*MUST revert if not called by vault.*

```solidity
function afterFinalize() external override onlyVault;
```

#### decommission

Take hooks out of use.

```solidity
function decommission() external override onlyVault;
```

#### supportsInterface

*Returns true if this contract implements the interface defined by `interfaceId`. See the corresponding <https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified\\[EIP> section] to learn more about how these ids are created. This function call must use less than 30 000 gas.*

```solidity
function supportsInterface(bytes4 interfaceId)
    public
    view
    override
    returns (bool);
```

#### targetSighashAllowed

Check whether target and sighash combination is allowed.

```solidity
function targetSighashAllowed(
    address target,
    bytes4 selector
) external view returns (bool);
```

**Parameters**

| Name       | Type      | Description           |
| ---------- | --------- | --------------------- |
| `target`   | `address` | Address of target.    |
| `selector` | `bytes4`  | Selector of function. |

#### \_addTargetSighash

INTERNAL FUNCTIONS ///

Add targetSighash pair to allowlist.

```solidity
function _addTargetSighash(address target, bytes4 selector) internal;
```

**Parameters**

| Name       | Type      | Description           |
| ---------- | --------- | --------------------- |
| `target`   | `address` | Address of target.    |
| `selector` | `bytes4`  | Selector of function. |

#### \_isAllowanceSelector

Check whether selector is allowance related selector or not.

```solidity
function _isAllowanceSelector(bytes4 selector)
    internal
    pure
    returns (bool isAllowanceSelector);
```

**Parameters**

| Name       | Type     | Description                    |
| ---------- | -------- | ------------------------------ |
| `selector` | `bytes4` | Selector of calldata to check. |

**Returns**

| Name                  | Type   | Description                                     |
| --------------------- | ------ | ----------------------------------------------- |
| `isAllowanceSelector` | `bool` | True if selector is allowance related selector. |

#### \_checkHooksOwner

Check that owner is not the vault or the guardian.

```solidity
function _checkHooksOwner(address owner_, address vault_) internal view;
```

**Parameters**

| Name     | Type      | Description          |
| -------- | --------- | -------------------- |
| `owner_` | `address` | Hooks owner address. |
| `vault_` | `address` | Vault address.       |

#### transferOwnership

*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.*

```solidity
function transferOwnership(address newOwner) public override onlyOwner;
```

### Errors

#### Aera\_\_CallerIsNotVault

ERRORS ///

```solidity
error Aera__CallerIsNotVault();
```

#### Aera\_\_VaultIsZeroAddress

```solidity
error Aera__VaultIsZeroAddress();
```

#### Aera\_\_HooksOwnerIsGuardian

```solidity
error Aera__HooksOwnerIsGuardian();
```

#### Aera\_\_HooksOwnerIsVault

```solidity
error Aera__HooksOwnerIsVault();
```

#### Aera\_\_MinDailyValueTooLow

```solidity
error Aera__MinDailyValueTooLow();
```

#### Aera\_\_MinDailyValueIsNotLessThanOne

```solidity
error Aera__MinDailyValueIsNotLessThanOne();
```

#### Aera\_\_NoCodeAtTarget

```solidity
error Aera__NoCodeAtTarget(address target);
```

#### Aera\_\_CallIsNotAllowed

```solidity
error Aera__CallIsNotAllowed(Operation operation);
```

#### Aera\_\_VaultValueBelowMinDailyValue

```solidity
error Aera__VaultValueBelowMinDailyValue();
```

#### Aera\_\_AllowanceIsNotZero

```solidity
error Aera__AllowanceIsNotZero(address asset, address spender);
```

#### Aera\_\_HooksInitialOwnerIsZeroAddress

```solidity
error Aera__HooksInitialOwnerIsZeroAddress();
```

#### Aera\_\_RemovingNonexistentTargetSighash

```solidity
error Aera__RemovingNonexistentTargetSighash(TargetSighash targetSighash);
```

#### Aera\_\_AddingDuplicateTargetSighash

```solidity
error Aera__AddingDuplicateTargetSighash(TargetSighash targetSighash);
```


---

# 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.aera.finance/v2-archive/contracts/aeravaulthooks.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.
