> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bitrune.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Swapping

> How to swap BTC and Runes through Bitrune's constant-product AMM pools.

Bitrune supports atomic swaps between BTC and Runes through constant-product (x × y = k) liquidity pools. Two swap directions exist, each with slightly different signing requirements.

## BTC to Rune (AToB)

<Steps>
  <Step title="Request a quote">
    Provide the target liquidity pool, swap direction (BTC to Rune), BTC amount in satoshis, and maximum acceptable slippage in basis points (default 100).
  </Step>

  <Step title="Review the quote">
    The quote includes estimated Rune units received, price impact, minimum output after slippage tolerance, and swap fee deducted.
  </Step>

  <Step title="Sign the transaction">
    The platform locks the relevant BTC UTXOs and presents BIP-340 sighashes for the user to partially sign using MuSig2. The user computes Schnorr partial signatures over each sighash using their private key and matching nonces.
  </Step>

  <Step title="Submit the signature">
    The user submits their public nonces and partial signatures. The platform aggregates the MuSig2 partial signatures into a single valid Schnorr signature per input, constructs the final transaction, and broadcasts it to the Bitcoin network.
  </Step>

  <Step title="Confirmation">
    Once the transaction confirms on-chain, the Rune balance is credited to the user's account.
  </Step>
</Steps>

## Rune to BTC (BToA)

The signing flow depends on whether the pool holds an etched Rune (a Rune created through Bitrune's etching feature).

### Pools without an etched Rune

The platform holds the Rune UTXOs under its own key, so no user signature is required.

1. Request a swap with the same parameters as the quote step above (specifying the Rune-to-BTC direction).
2. The platform signs the pool spend directly, broadcasts the transaction, and returns the txid.
3. BTC is credited to the user once the transaction confirms.

### Pools with an etched Rune

The Rune UTXO is held under a 2-of-2 MuSig2 key, so the same sign-and-submit flow as BTC-to-Rune applies:

1. Request the swap (specifying the Rune-to-BTC direction).
2. Sign the returned sighashes.
3. Submit public nonces and partial signatures.
4. The platform aggregates, broadcasts, and BTC is credited on confirmation.

## Notes

<Note>
  **Swap fee.** The default fee is 0.3% (30 bps) of the input amount. Pool creators may configure a different fee rate at pool creation time.
</Note>

* **Deflationary Runes.** Runes with a tax configuration may impose additional buy and/or sell taxes. These are deducted on top of the swap fee. The effective output is reduced accordingly.
* **Slippage protection.** The minimum output value included in every quote acts as an on-chain minimum. If the trade would produce fewer tokens than this minimum, the transaction is not constructed.
* **Quote expiry.** Quotes are not permanently valid. The user should proceed to the signing step promptly after receiving a quote.
