> For the complete documentation index, see [llms.txt](https://nitro-finance.gitbook.io/ftl/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nitro-finance.gitbook.io/ftl/core-interactions/swaps-and-pricing.md).

# Swaps & Pricing

Swapping is the process of exchanging tokens, where one token is exchanged for a proportional amount of the desired token, minus the swap fee. This is one of the primary ways to interact with the Nitro Fused Trade Ledger.

## **How it works**

* Users initiate a trade, specifying the token they wish to sell and the token they wish to receive.
* The system computes the output based on the active bin’s price and available reserves.
* If liquidity in the active bin is depleted, the protocol activates the nearest bin with available reserves, ensuring uninterrupted trading.

### **Example:**

* A user sells 2 NAD to receive USDC.
* **Active Bin Price**: 1002 USDC/NAD.
* **Active Bin Reserves**: 7 NAD and 8000 USDC.

**Calculation**:&#x20;

$$\Delta y = P \times \Delta x$$\
\
**Where:**

* $$P$$: Active bin price (1002 USDC/NAD).
* $$\Delta x$$: Amount of NAD being sold (2 ).
* $$\Delta y$$: Amount of USDC received.

$$\Delta y = 1002 \times 2 = 2004 , \text{USDC}$$

{% hint style="success" %}
Swap fees, if applied, are deducted from the final output, slightly reducing the amount received.
{% endhint %}

## **Swap Pricing Dynamics**

Nitro’s bin-based pricing mechanism ensures efficient price adjustments during swaps. Each bin corresponds to a unique price point, and prices adjust as bins are activated through trades.

<figure><img src="/files/Wo2PrCDSbyTWfXyZVxa3" alt="" width="375"><figcaption></figcaption></figure>

### **Case 1: Price Decrease**

**Example: USDC/NAD Pool Setup:**

* **Active Bin**: 1002 USDC/NAD, Reserves: 7 NAD and 8000 USDC.
* **Nearest Bin Below**: 1000 USDC/NAD, Reserves: 0 NAD and 5000 USDC.

A user sells **8 NAD**, depleting all USDC in the active bin before the trade is fully filled.

**Outcome**:

* The protocol activates the nearest bin below (1000 USDC/NAD), which contains USDC reserves to complete the trade.
* This results in a **price decrease** for NAD, reflecting the increased market demand for USDC.

### **Case 2: Price Increase**

**Example: USDC/NAD Pool Setup:**

* **Active Bin**: 1002 USDC/NAD, Reserves: 7 NAD and 8000 USDC.
* **Nearest Bin Above**: 1005 USDC/NAD, Reserves: 12 NAD and 0 USDC.

A user sells 9**000 USDC**, depleting all NAD in the active bin before the trade is fully filled.

**Outcome**:

* The protocol activates the nearest bin above (1005 USDC/NAD), which contains NAD reserves to complete the trade.
* This results in a **price increase** for NAD, reflecting the market demand for NAD.

## SWAP ARCHITECTURE

<figure><img src="/files/Rv2ohL053VCI0ZjKJ6Gi" alt=""><figcaption></figcaption></figure>
