# StableSwap Deep Dive

This page expands StableSwap concepts: **where low slippage comes from**, how `minOut` and deadlines protect you, and how stable‑pool LP risk behaves under stress.

{% hint style="info" %}
**Not investment advice** — DEX swaps and LP positions carry depeg, slippage, and smart contract risk.
{% endhint %}

## At a glance

* StableSwap curves are designed to keep price impact low **when assets stay near the same price**.
* As a pool becomes imbalanced, price impact increases quickly.
* `minOut` is your explicit “worst acceptable outcome” guardrail.
* LP risk is not “small” just because assets are “stable”: depegs can concentrate the worse asset into LP positions.

## Why StableSwap can have lower slippage (conceptual)

StableSwap pools are designed specifically for pairs where:

* both assets are expected to be worth roughly the same (e.g., stable-to-stable), and
* the pool can assume prices stay near 1:1 most of the time

Many implementations use an **amplification** parameter that makes the curve behave “more linear” around the balanced point.

Practical consequence:

* small trades around the peg can have lower price impact than a constant‑product AMM
* large trades, or trades when the pool is imbalanced, can still have significant slippage

## `minOut` and slippage (worked example)

When you submit a swap, you typically include:

* the input amount
* a minimum acceptable output (`minOut`)
* a deadline

If the swap would output less than `minOut`, the transaction reverts.

Example:

* quote says you should receive `995` token out
* you set a slippage tolerance of `0.5%`

A rough mental model is:

$$
minOut \approx quote \times \left(1 - \frac{slippageBps}{10{,}000}\right)
$$

So `minOut ≈ 995 × (1 - 0.005) ≈ 990.025`.

{% hint style="warning" %}
This is a rough model. Exact quoting depends on pool math, fees, and route composition.
{% endhint %}

## Deadlines and why they matter

A deadline limits how long your quote is allowed to be “valid.”

Without a deadline, a transaction can sit in the mempool and be mined later under worse conditions:

* pool state changed
* price moved
* MEV/searcher activity increased

A short deadline reduces the window for stale execution, but it can increase reverts during congestion.

## LP risk in stable pools (what changes during a depeg)

Stable pools behave very differently when one asset deviates from its peg.

If token A depegs downward:

* arbitrage traders swap token B into the pool to buy token A cheaply
* the pool becomes heavily weighted toward token A
* LPs end up holding more token A and less token B

That is the mechanism behind “stablecoin LP losses under depeg”: the pool composition moves toward the weaker asset.

## LP exposure under depeg — two numeric examples

{% hint style="warning" %}
**Illustrative numbers** — Real StableSwap math is not “constant product,” and real outcomes depend on pool parameters, fees, and trade paths. These examples show the *directional* effect: under depeg stress, LPs can end up holding mostly the weaker asset.
{% endhint %}

### Example 1 — USDHN depegs down (LP ends up holding more USDHN)

Assume a pool starts balanced:

* `1,000,000` USDHN and `1,000,000` USDT
* prices: `USDHN = $1.00`, `USDT = $1.00`
* you own `10%` of the pool

So your “starting” underlying exposure is:

* `100,000` USDHN + `100,000` USDT (worth `$200,000`)

Now assume USDHN trades at `$0.90` for a period and the pool becomes very imbalanced:

* pool ends up at `1,800,000` USDHN and `200,000` USDT (illustrative)

Your `10%` share is now:

* `180,000` USDHN + `20,000` USDT

USD value at the new prices:

* `180,000 × $0.90 + 20,000 × $1.00 = $182,000`

Compare to “just holding” the original tokens:

* `100,000 × $0.90 + 100,000 × $1.00 = $190,000`

The gap is the cost of being forced into more of the depegged asset as the pool rebalances.

### Example 2 — USDHN depegs up (LP ends up holding less USDHN)

Assume the same starting pool and `10%` share, but now USDHN trades at `$1.05`.

If the pool becomes imbalanced in the other direction (illustrative):

* pool ends up at `200,000` USDHN and `1,800,000` USDT

Your `10%` share becomes:

* `20,000` USDHN + `180,000` USDT

USD value:

* `20,000 × $1.05 + 180,000 × $1.00 = $201,000`

Compare to “just holding” the original tokens:

* `100,000 × $1.05 + 100,000 × $1.00 = $205,000`

Again, the pool pushes your holdings away from the asset the market is bidding up.

## Practical checklist (swaps + LP)

* Prefer deep liquidity pools and official routes.
* Use realistic `minOut` and short deadlines.
* Start with small sizes to validate routing and token behavior.
* Only LP if you are comfortable holding either asset in the pool, especially under stress.

## Next reads

* Main guide: [StableSwap DEX](https://hann-finance.gitbook.io/hann-finance/protocol/stableswap-dex)
* Automation caveats: [Zapper Guide](https://hann-finance.gitbook.io/hann-finance/protocol/zapper)
* Full risk framing: [Risk Disclosure](https://hann-finance.gitbook.io/hann-finance/risks/risk-disclosure)
