# The TWOB Model

## Continuous Streaming of Trades

The TWOB mechanism breaks large orders into infinitely small sub-orders that stream into the market continuously, reducing the price impact of large trades and preventing toxic order flow strategies like sandwich attacks.

{% embed url="<https://youtu.be/HmrV8OFqH7Q>" %}

***

The Time-Weighted Order Book (TWOB) introduces a time dimension to traditional limit orders, allowing traders to set both the price and the duration for their orders. Rather than executing a single order, the TWOB splits it into infinitely many small sub-orders that flow continuously into the market. This structure reduces price impacts from large orders and mitigates sandwich attacks, as trades are streamed continuously, even in between blocks.

<figure><img src="/files/3VNRTfrE1inMYnbmcTD4" alt="Visual explanation of the Time Weighted Order Book"><figcaption></figcaption></figure>

### **Streaming Swaps**

The concept of streaming swaps is similar to streaming payments. For example, Alice hires Bob for a one-week project worth $3,024, and instead of paying the full amount upfront, she could make daily or hourly payments. In theory, she could break the payments down into infinitesimal transactions. This is inefficient, so we use a mathematical formula to calculate the cumulative effect and only process the necessary withdrawals.

Similarly, with streaming swaps, Alice can make a large trade (e.g., 108 million USDC for SOL) by splitting her order into smaller, continuous orders streamed into the market. By doing this, Alice avoids large price impacts and reduces the risk of sandwich attacks.

### **Market Price Calculation**

The TWOB mechanism calculates the market clearing price dynamically, adjusting according to the flow of supply and demand. Each trade’s price updates in real-time based on the amount of USDC and SOL flowing through the market.

The TWOB structure ensures that trading happens at a time-weighted average price, which reduces volatility and ensures fair execution for traders.

### Example:

A buy order for 485,792 USDC over 16 slots (30,362 USDC per slot) enters the book. At slot 10, a sell order for 1,900 SOL over 25 slots enters, and trading begins at the market price of 399.5 USDC per SOL. As demand increases, the market price adjusts, and trades occur at the updated price.

### Conclusion

The TWOB introduces time-weighted trading that ensures fairness by mitigating slippage and sandwich attacks while offering efficient trade execution. Each order is executed gradually, based on its time-weighted average price, making it a powerful tool for decentralized exchanges.


---

# 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://mato-docs-1.gitbook.io/mato-docs/publish-your-docs.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.
