> For the complete documentation index, see [llms.txt](https://docs.tren.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tren.finance/protocol/hooks/router.md).

# Router

<figure><img src="/files/pR4RQm1QaF1K7JTXKRor" alt=""><figcaption></figcaption></figure>

We’ll take a look at how the Router Hook works in the example used for the Looping Leverage Hook. In the step where the FlashBorrowed XY is used to acquire PT-USDe, the Router Hook kicks in. Here, the Router Hook finds the optimal pathway for wapping XY to PT-USDe. It’s easy to think of the Router Hook as an aggregator, in that it analyses pathways to find the best and most cost-efficient pathway before executing the transaction.

A key difference from a typical aggregator however, is the Router Hook’s ability to determine and execute the groundwork necessary before making a swap. For example, if there was a request to swap aUSDT to XY:

1. Check if there is sufficent liquidity to directly swap from aUSDT
2. If not, go to Aave to withdraw USDT from the aUSDT
3. Swap USDT to XY

### **Benefits**

**Dynamic Flexibility**: The Router Hook allows for real-time decision-making, optimizing routes and execution paths based on evolving market conditions and liquidity depth

**Improved Efficiency**: Automating routing decisions and optimizing transaction pathways reduces operational complexity and potentially minimizes gas costs.

**Composability**: The Router Hook facilitates seamless integrations across protocols, enabling complex multi-step workflows and enhancing interoperability within DeFi.

**User-Friendly Automation**: Users benefit from streamlined processes where optimal pathways are executed without requiring manual intervention or technical expertise.


---

# 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.tren.finance/protocol/hooks/router.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.
