# AMM

LPs passively pool both X and Y tokens in liquidity pools to make the perpetual market for the pair. Traders leverage this liquidity by borrowing from the pooled reserves, facilitating derivative positions. Subsequently, they seamlessly exchange one side of the borrowed liquidity for additional tokens on the other side of the borrowed liquidity, thus increasing their exposure to the desired asset while also maintaining a secure overcollateralization level.

At settlement, each trader delivers the debt needed to return the owed liquidity back to the pool and then receive the originally longed token in return.

In the event that the value of the margin token falls below the maintenance threshold, positions can be permissionlessly liquidated. This process involves returning the entirety of the collateral, minus applicable fees, back to the liquidity pool.

[Math Plots](https://www.desmos.com/calculator/dhw3xwuwei): the sliders allow you to play with it to see robustness in all cases (deterministic safety).


---

# 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://marginal.gitbook.io/docs/protocol/amm.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.
