# Using Configurable Hooks

### What is a Configurable hook?

Pre-hooks and post-hooks have two important differences:

* **Pre-hooks run before an operation and post-hooks run after an operation**. Generally speaking a pre-hook can be used to check the arguments of the operation whereas a post-hook can be used to validate specific outcomes.
* **Pre-hooks have return values, post-hooks don't**. Merkle leaves in the Merkle tree contain additional arguments that are checked against the return values of a pre-hook. For example, a pre-hook could be defined for a lending protocol to restrict what types of assets can be supplied from the vault. The way to do this would be to extract the asset from the supply function of the given lending protocol and then whitelist acceptable assets in the Merkle tree.

Configurable hooks are pre-hooks that extract information from operation calldata in specific configured positions.

### Why It Matters

They allow the vault owner to define a protocol integration without writing a custom hook contract.

### How to Create a Configurable Hook

Configurable hooks are added in the Merkle tree via a set of configurable hook offsets. These offsets specify indices in calldata from which to extract full words.

If we wanted to use Aera V3 to support depositing and withdrawing from an ERC4626 vault, we could use a pre-hook to do this. Here is the full signature of both operations for reference:

```solidity
function deposit(uint256 assets, address receiver) public returns (uint256 shares)
function withdraw(uint256 assets, address receiver, address owner) public returns (uint256 shares)
```

In order to safely interact with this ERC4626 we can add the following protections:

* Whitelist `deposit` and `withdraw` actions on the specific contract,
* Create a pre-hook for both deposit and withdraw that takes the calldata and returns the `receiver`,
* Create a Merkle leaf that contains a `receiver` that is equal to the address of the vault itself.

Now when a submission happens, it will revert if the guardian tries to send assets to a different recipient than the vault address.

But pre-hooks can be much more complicated and specific than that. For example, a pre-hook could add a daily or total supply cap for each ERC4626 token, it could run integrity checks such as checking whether the corresponding `convert` function agrees with the `preview` function and more depending on the use case.

For that, you need to build a custom hook.

### Caveats

Since configurable hook offsets extract full words, they are not perfectly suited to extract arguments for tightly packed data such as bitmaps. If you need to do so, you will need to develop a custom hook.


---

# 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/using-configurable-hooks.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.
