> For the complete documentation index, see [llms.txt](https://mobius-exchange.gitbook.io/mobius-exchange/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mobius-exchange.gitbook.io/mobius-exchange/whitepaper/swap-formula.md).

# Swap Formula

Similar to other AMMs, Möbius Exchange’s swap mechanism is designed to encourage trades that move the system towards equilibrium and discourage trades that move it away from equilibrium. The difference lies in the fact that Möbius Exchange's equilibrium is defined as the coverage ratios of all assets are equal.

Without loss of generality, assume token A has a higher coverage ratio than token B, $$r\_a > r\_b$$. If a trader exchanges token B for token A, this action increases the under-covered $$r\_b$$ and decreases the over-covered $$r\_a$$ , hence bringing the pool closer to equilibrium. The pool would therefore offer a favorable rate in incentivize trades in this direction.

Conversely, if a trader exchanges token A for token B, this action further increases the over-covered $$r\_a$$ and further decreases the under-covered $$r\_b$$ , hence further diverging the pool from the equilibrium. The pool would therefore offer a worse rate to penalize the trades in this direction.

This dynamic rate can be expressed mathematically in terms of coverage ratios.

Recall from the previous section, the penalty function is defined as,

$$
p(r) =
\begin{cases}
1, & 0 \le r \le r\_t,\\\[6pt]
\left(\frac{1 - r}{1 - r\_t}\right)^4, & r\_t < r < 1,\\\[6pt]
0, & r \ge 1.
\end{cases}
$$

As the trader swaps token A to token B, the amount of token A in the pool would increase while the amount of token B would decrease. The coverage ratio of A increases from $$r\_A$$ to $$r\_A'$$ while B decreases from $$r\_B$$ to $$r\_B'$$.&#x20;

The swap rate is given by

***Definition - 4.1***

$$
\text{Exchange rate}*{A->B} = 1  + \int*{r\_A}^{r\_A'} p(r) , dr\* \frac{1}{r\_A'-r\_A} - \int\_{r\_B'}^{r\_B} p(r) , dr \* \frac{1}{r\_B-r\_B'}
$$

To evaluate the integral of −p(s) over the interval $$\[r,r']$$, we define the function $$F(r) = \int\_r^1 -p(s) ds.$$

Since F(r) is a monotonically decreasing function, it attains its minimum at r=1. This boundary condition F(1)=0 follows naturally from the definition of the integral, as the integral over an interval of zero width vanishes. The closed-form solution for F(r) is derived as follows:

***Formula - 4.2***

$$
F(r) =
\begin{cases}
\displaystyle \frac{1 + 4r\_t}{5} - r, & 0 \le r \le r\_t, \\
\displaystyle \frac{(1 - r)^5}{5(1 - r\_t)^4}, & r\_t < r < 1, \\
0, & r \ge 1.
\end{cases}
$$

As the system would penalize the action for reducing token B's coverage ratio, while at the same time, reward it for increasing token A's coverage ratio. The value of $$p(r)$$ ensures that only when increasing the coverage ratio of an under-covered asset would be rewarded, and further amount that increases the over-covered asset would not be rewarded as $$p(r) = 0$$ for $$r \ge 1$$. Similarly, decreasing an under-covered asset will be penalized, while decreasing an over-covered asset would not be penalized.

### Scenario 1: Coverage Ratios within normal range

Under normal market conditions, when both coverage ratios of the two assets to be traded remain above 80% (or a configurable threshold), the value of $$p(r\_a)$$ and $$p(r\_b)$$ **stays near zero**. This ensures that swap rates remain stable and attractive to traders, preventing unnecessary slippage while optimizing liquidity efficiency.

### Scenario 2: Extreme Coverage Ratios

In abnormal situations, such as when **Token A's coverage ratio falls below 60%** while **Token B's rises to 150%**. This implies that Token B is unwanted due to depegging or an increase in Token A's demand.

To safeguard Token A's solvency, the value of $$p(r\_a)$$ would become larger as $$r\_a$$ begins to fall under 60%. Thus penalizing traders for further reducing Token A's coverage ratio. Conversely, the  $$p(r)$$  would be lower for trades from Token A to Token B as a reward for bringing the pool back from extreme to equilibrium coverage ratio.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://mobius-exchange.gitbook.io/mobius-exchange/whitepaper/swap-formula.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
