# FMM vs AMM Trading Example

**AMM Trading Model Case Description:**

In the AMM (Automated Market Maker) model example, the trading process is direct and straightforward.

1. **Initial State**:
   * The liquidity pool initially contains an equal number of two types of tokens, specifically 100 tokenA and 100 tokenB.
2. **Trading Process**:
   * A user decides to trade on the AMM platform and inputs 10 tokenA.
   * The AMM platform calculates the amount of tokenB that can be exchanged for 10 tokenA based on its core algorithm, the constant product formula (x\*y=k).
   * As a result of the formula, the user obtains 9.1 tokenB from the liquidity pool, incurring a slippage loss of 0.9 tokenA.
3. **After the Trade**:
   * Upon completing the trade, the liquidity pool updates to 110 tokenA and 90.9 tokenB, reflecting the result of the user's trade.

**FMM Trading Model Case Description:**

The FMM (Future Matching Market) model offers a more complex trading structure, including time slicing and slippage compensation mechanisms.

1. **Initial State**:
   * The liquidity pool also contains 100 tokenA and 100 tokenB.
   * The system's time slicing rule is set for 5 slices, each lasting 20 seconds.
2. **Trading Process**:
   * User A inputs 10 tokenA on the FMM platform, expecting to exchange for 10 tokenB at the current exchange rate (1 tokenA/tokenB).
   * The system receives user A's trade request, initially returning the same amount of tokens as in the AMM situation, meaning user A receives 9.1 tokenB, incurring a slippage loss of 0.9 tokenA.
   * The system further processes user A's trading intention through time slicing, dividing it into 5 slices.
3. **Time-Sliced Trade Matching**:
   * At time slice number 0, user B inputs 3 tokenB and receives 3 tokenA, while the system records a slippage compensation of 0.5 tokenA for user A. The system also processes user B's trading intention through time slicing.
   * At time slice number 1, the system dynamically adjusts prices based on current and future trading intentions. At this point, the system considers the trading intentions of user A and user B, calculating the remaining trade intentions after time slice 0 and the impact of the remaining unmatched trade intentions on the price. As a result, the liquidity pool's state changes to 101.3 tokenA and 98.7 tokenB, with 4 more unbalanced trade slices remaining.
   * User C inputs 4.8 tokenB and receives 4.92 tokenA at the new exchange rate, while the system records a slippage compensation of 0.26 tokenA for user A. The system also processes user C's trading intention through time slicing.
4. **Slippage Loss Compensation**:
   * Through trades with users B and C, user A receives slippage compensation of 0.5 tokenA and 0.26 tokenA respectively in time slices, totaling 0.76 tokenA in slippage loss compensation.
5. **After the Trade**:
   * User A successfully reduces slippage loss and completes the trade through the FMM model's system matching and time slicing processing mechanisms.

Comparing these two models, it's evident that the FMM model provides a more complex but potentially more optimized trading solution for users, especially in reducing slippage losses and addressing market fluctuations, showcasing its unique advantages.


---

# Agent Instructions: 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:

```
GET https://rille-protocol.gitbook.io/rille-swap-document-v1/fmm-vs-amm-trading-example.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
