# ActionSwapBT

{% hint style="info" %}
**Source:** `src/fira_bonding/router/ActionSwapBTV3.sol`
{% endhint %}

## Functions

* **`swapExactTokenForBt`** — User token → FW (mint) → FW sent to market → swap for BT
* **`swapExactFwForBt`** — FW → BT via market swap
* **`swapExactBtForToken`** — BT → FW (market swap) → redeem to user token
* **`swapExactBtForFw`** — BT → FW via market swap

## Swap amount calculation

The FW→BT direction uses `MarketApproxBtOutLibV2.approxSwapExactFwForBtV2` with binary search and an off-chain hint (`guessOffchain`). This is needed because the market only supports exact-output BT swaps (`swapFwForExactBt`), so the approximation library finds the BT amount that uses exactly the available FW.

## On-chain fallback

If `guessOffchain == 0` and no limit orders are present, the facet delegates to `ActionSimple` which uses `MarketApproxLibOnchain` for a closed-form approximation instead.
