> For the complete documentation index, see [llms.txt](https://rwapact.gitbook.io/whitepaper/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rwapact.gitbook.io/whitepaper/integrations-and-standards/uniswap-v4.md).

# Uniswap v4

## Uniswap v4 execution integration

Uniswap v4 provides the swap and execution environment. RWAPACT adds a Pact decision layer around that execution path.

The defined integration uses a Uniswap v4 hook. The hook evaluates the five-layer Pact before the relevant swap proceeds. It does not replace Uniswap or introduce a separate trading venue.

```
Agent calls pool.swap()
        |
        v
Hook.beforeSwap()
        |
        v
KRO risk check → KSO session check → KPV policy check → KGR execution check
        |
        v
Allow swap
        |
        v
Hook.afterSwap() → KAR attestation with execution transaction hash
```

### Before the swap

`Hook.beforeSwap()` is the integration point for the decision boundary. It receives the proposed execution before the swap is allowed through the Pact.

KRO evaluates RWA-specific risk for the proposed trade. KSO confirms that the agent has an active, in-scope session. KPV tests the asset and trade conditions against policy. KGR evaluates gas and execution-path conditions.

All required checks must pass. If any required check fails, the swap is not allowed to proceed through the Pact.

### After the swap

When the swap succeeds, `Hook.afterSwap()` handles the post-execution stage. KAR can record the Pact decision and associate it with the execution transaction hash.

This separates responsibilities cleanly:

* **Uniswap v4** supplies pool-based swap execution.
* **RWAPACT** evaluates risk, session authority, policy, and execution conditions.
* **KAR** records the resulting decision and execution context.

The same Pact logic can sit before other execution environments. The hook makes that decision model available at the Uniswap v4 swap boundary.


---

# 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://rwapact.gitbook.io/whitepaper/integrations-and-standards/uniswap-v4.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.
