> For the complete documentation index, see [llms.txt](https://docs.metric.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.metric.xyz/how-pools-work/extensions-and-permissions.md).

# Extensions

Extensions add rules before or after pool actions: they can control access, check a trade's effect on liquidity, record trades for future pricing, block all trading and more.

Curators can reuse existing extensions or build their own.

**Extensions can't change the pool's quote; they can only reject a trade.** A custom extension therefore can't manipulate the quote of the current trade.

## Where extensions run

| Pool action | Extension points                   |
| ----------- | ---------------------------------- |
| Swap        | Before or after the swap           |
| Deposit     | Before or after adding liquidity   |
| Withdrawal  | Before or after removing liquidity |

For swaps for example, quote validation comes **before** the before-swap extensions; extensions cannot replace that quote for the current swap. After-swap extensions can inspect token amounts and pool state.

A rejection at either stage reverts the pool action, including token transfers.

<figure><img src="https://2762670563-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyvQVWzbfEJJ8Aelwvxmj%2Fuploads%2FLxPBKG9Yt5rZ0zu6suvf%2Fmetric_swap_lifecycle_extensions.png?alt=media&#x26;token=a720ccc3-577b-405d-9f77-69249d3bd77e" alt=""><figcaption></figcaption></figure>

## Standard extensions

| Extension         | What it controls                                                                                              |
| ----------------- | ------------------------------------------------------------------------------------------------------------- |
| StopLoss          | Rejects swaps when a bin's value per LP share, in tokens rather than USD, drops too far within a time window. |
| Velocity Guard    | Rejects swaps when the reference price moves too fast.                                                        |
| Deposit allowlist | Limits who can deposit into a pool.                                                                           |

## Settings matter

**StopLoss** values each bin at the Price Provider's bid and ask and tracks its peak: the highest value per LP share it has recorded. The drawdown setting decides how far below the peak a swap may take the bin; decay lowers the peak over time, so an old peak doesn't block the bin forever.

If a bin has no baseline, its first monitored trade initializes one without this drawdown check.

StopLoss rejects trades; it does not sell an LP's position or cap all losses. Ordinary market movements can trigger it.

**Velocity Guard** checks changes in the supplied reference, not ordinary price impact from crossing bins. Its allowance and comparison anchor can be changed by the pool admin.

Attaching a guard does not prove it is enabled. Check its settings and who can change them.

## Fixed addresses, changeable behavior

Extension addresses and execution order are fixed at pool creation. Settings or code may remain changeable unless restricted.

A custom withdrawal extension can block LP exits. Before depositing, review its code and who can change it.

[Risks and safeguards](/use-metric/provide-and-manage-liquidity/risks-and-safeguards.md) · [Pool tiers](/use-metric/provide-and-manage-liquidity/pool-tiers.md) · [Build an extension](/run-a-pool/build-an-extension.md)
