> For the complete documentation index, see [llms.txt](https://tidal-flats.gitbook.io/tidal-flats-whitepaper-en/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tidal-flats.gitbook.io/tidal-flats-whitepaper-en/whitepaper/black-market-2-road-to-fidelia/black-market-dex/vamm-virtual-amm.md).

# vAMM (Virtual AMM)

## Overview

The Virtual Automated Market Maker (vAMM) system is the core of Black Market's exchange. vAMM facilitates exchange between sSPL and VALOR tokens to ensure price stability and adequate liquidity.

{% hint style="info" %}
The below models can be updated due to the balance update
{% endhint %}

### Key Definitions and Variables

* **Volatility Parameter**: Parameter to control volatility. Calculated with C and k value
* **k**: Constant to give minimum stability to the system
* $$S$$: Total supply of specific sSPL tokens.
* $$S\_{old}$$: Total supply of specific sSPL tokens before the calculation.
* $$S\_{new}$$: Total supply of specific sSPL tokens after the calculation.
* $$\Delta S$$: represents the trade-induced change in supply.
* $$P\_{int}$$: Price of the sSPL when initialized.
* $$P\_{old}$$: Price of the sSPL before calculation.
* $$P\_{new}$$: Price of the sSPL after calculation.
* $$P\_{avg}$$: The price of the sSPL applies to a specific trade.

## Models

The vAMM model dynamically adjusts the token price to provide appropriate stability and volatility while ensuring symmetry in trading.

### Symmetric Model

vAMM calculates the price after the trade using the symmetric model.

* Calculation based on sSPL amount

$$P\_{new} = P\_{old} \times (1 + \frac{\Delta S}{k + S\_{old}} )$$

* Calculate based on VALOR budget

$$\Delta S = \frac{B}{\frac{P\_{old} + P\_{new}}{2}} = \frac{2B}{P\_{old} + P\_{new}}$$

$$\therefore P\_{new} = \sqrt{P\_{old}^2 + \frac{2B \cdot P\_{old}}{k + S\_{old}}}$$

## Average Price Model

vAMM swap transaction works based on the average price before the trade and the adjusted price after the trade.

$$P\_{avg} = \frac{P\_{old} + P\_{new}}{2}$$

## Price Adjustment Due to External Changes

If the supply of sSPL tokens changes outside of vAMM trades, the system adjusts the price using the following equation:

$$P\_{\text{new}} = \begin{cases}  P\_{\text{int}} + \frac{(P\_{\text{old}} - P\_{\text{int}})(2k + S\_{\text{old}})}{2k + S\_{\text{new}}} & \text{if} ,, P\_{\text{old}} > P\_{\text{int}} \ P\_{\text{int}} - \frac{(P\_{\text{int}} - P\_{\text{old}})(2k + S\_{\text{old}})}{2k + S\_{\text{new}}} & \text{if} ,, P\_{\text{old}} \le P\_{\text{int}} \end{cases}$$

$$k = 100000 / P\_{int}$$

### Initial price

| Token                   | Initial Price ($VALOR) |
| ----------------------- | ---------------------- |
| Voodoo Doll ($VD)       | 0.46118                |
| Gold Teeth ($GT)        | 0.72776                |
| JB Whiskey ($JBW)       | 0.94118                |
| Canteen ($CT)           | 1.07882                |
| G Badge ($GB)           | 1.55294                |
| Holy Water ($HW)        | 2.32353                |
| Used Engine ($UE)       | 3.41176                |
| Enhanced Bullet ($EB)   | 3.43529                |
| Oil Lighter Case ($OLC) | 6.82353                |
| Oil ($OIL)              | 0.00750                |
| MRE ($MRE)              | 0.00750                |

## Examples

1. **Swap**:
   1. **Buy**: Paying VALOR to buy 1 sSPL
      * Stability constant $$k = 10$$ sSPL (after buying)
      * Current supply $$S\_{old} = 0$$ sSPL
      * New supply $$S\_{new} = 1$$ sSPL
      * Current price $$P\_{old} = 10$$ VALOR
      * New price $$P\_{new} = 10 \times (1 + \frac{1}{10 + 0} ) = 11$$ VALOR
      * Average price $$P\_{avg} = \frac{10 + 11}{2} = 10.5$$ VALOR
      * Fee: $$10.5 \* 0.0005 = 0.0525$$ VALOR
      * **Result**: Paying 10.5525 VALOR to buy 1 sSPL
   2. **Sell Transaction**: Selling 1 sSPL to get VALOR
      * Stability constant $$k = 10$$ sSPL (after buying)
      * Current supply $$S\_{old} = 1$$ sSPL (after buying)
      * New supply $$S\_{new} = 0$$ sSPL
      * Current price $$P\_{old} = 11$$ VALOR (after buying)
      * New price $$P\_{new} = 11 \times ( 1 - \frac{1}{10 + 1} ) = 10$$ VALOR
      * Average price $$P\_{avg} = \frac{11 + 10}{2} = 10.5$$ VALOR
      * Fee: $$10.5 \* 0.0005 = 0.0525$$ VALOR
      * **Result**: Receiving 10.5525 VALOR for selling 1 sSPL
2. **Price Adjustment**:

   <figure><img src="https://165396892-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fyn01bJhpVHjehvGT4I37%2Fuploads%2FdOsFxUo3Imw5Jn8sH7b8%2FvAMM.png?alt=media&amp;token=17a72064-f1b6-4b7a-bc62-30a29ff98c68" alt=""><figcaption></figcaption></figure>

   1. **On Mint:**
      * Stability constant $$k = 10$$ sSPL (after buying)
        * Current supply $$S\_{old} = 1$$ sSPL
        * Supply after mint $$S\_{new} = 5$$ sSPL
        * Initial price $$P\_{int} = 10$$ VALOR
        * Current price $$P\_{old} = 11$$ VALOR
        * Adjusted price $$P\_{new} = \frac{|11 - 10|(1 + 2 \times 10)}{5 + 2 \times 10} + 10 = 10.84$$ VALOR
   2. **On Burn**:
      * Stability constant $$k = 10$$ sSPL (after buying)
        * Existing supply $$S\_{old} = 5$$ sSPL
        * Supply after burn $$S\_{new} = 1$$ sSPL
        * Initial price $$P\_{int} = 10$$ VALOR
        * Current price $$P\_{old} = 10.84$$ VALOR
        * Adjusted price $$P\_{new} = \frac{|10.84 - 10|(5 + 2 \times 10)}{1 + 2 \times 10} + 10 = 11$$ VALOR


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://tidal-flats.gitbook.io/tidal-flats-whitepaper-en/whitepaper/black-market-2-road-to-fidelia/black-market-dex/vamm-virtual-amm.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
