> For the complete documentation index, see [llms.txt](https://docs.henjin.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.henjin.xyz/henjinai-protocol/hooks-v4/how-do-v4-hooks-work.md).

# How do v4 hooks work ?

With hooks in Henjin v4, developers can create custom logic for various pool actions throughout the pool action lifecycle. For example, custom fee structures, such as dynamic fees based on market conditions or user-specific discounts, can be implemented. Hooks also allow for advanced order types like limit orders, time-weighted average market maker (TWAP) orders, and orders over time, enabling more sophisticated trading strategies.

Moreover, hooks facilitate automated strategies, such as rebalancing or arbitrage bots, directly integrated into the liquidity pool operations. They can enhance security by adding custom withdrawal restrictions or preventing front-running attacks. Additionally, hooks support the creation of incentive programs, rewarding liquidity providers based on market volatility or specific criteria.

The hook contract within the Henjin v4 architecture is designed to be gas efficient, minimizing transaction costs for users. By utilizing hooks, developers can manage large orders and chain limit orders more effectively, ensuring better execution in various market conditions. The pool manager can leverage these hooks to create custom solutions tailored to specific needs, ultimately driving innovation and adoption within the Henjin ecosystem. This modular and adaptable framework empowers developers to build more robust and versatile decentralized finance (DeFi) applications on Henjin v4.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.henjin.xyz/henjinai-protocol/hooks-v4/how-do-v4-hooks-work.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
