# The f(x) Invariant

The f(x) Invariant is the core mechanism behind both V1 and V2. It enables on-chain leverage while delivering 100% capital efficiency for the stablecoins.\
\
f(x) Protocol ensures that the total value of all fxUSD combined with the total value of all xPOSITIONs is always equal to the total value of the collateral reserves. Dynamic adjustments to the leverage ratio of xPOSITION and the peg ratio of fxUSD enable seamless collaboration between low-volatility stablecoins and high-leverage trading tools.

The relationship is represented as:

<img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXchdsHtOfLmBKidgm_bD95kHTUF0OBdfRALofMxDEajA5z6BSoHX42FOpRY4HQcw4wfneOcxrwd58b4ZgEujgCjc7HNuZREDkDMCSmZj2185By90016vCQ8T5zDSuLICDQb0rQI?key=qZd1xwlrsRmRqxNUnTlo-b4A" alt="" data-size="original">

Where:

* 𝑛 is the number of TOKEN collateral,&#x20;
* 𝑠 is the TOKEN price in USD,&#x20;
* nf is the number of fxUSD,&#x20;
* 𝑓  is the fxUSD NAV in USD,&#x20;
* nx is the number of xPOSITION units, and&#x20;
* 𝑥 represents the NAV of xPOSITION in USD.

This formula ensures that the system remains balanced, maintaining integrity and stability across its decentralized financial tools.

WIth the addition of sPOSITION, the invariant evolved to ensure every fxUSD, xPOSITION and sPOSITION remained fully backed and that the protocol maintaines internal solvency across both long and short positions.\
\
The new invariant is:

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

Where:<br>

* 𝑛 is the number of TOKEN collateral,&#x20;
* $$n^{-}$$ is the amount of TOKEN collateral borrowed for short positions,
* 𝑠 is the TOKEN price in USD,&#x20;
* nf is the number of fxUSD minted (longs),&#x20;
* $$n^{-}$$f is the number of fxUSD locked (shorts),
* X represents the NAV of xPOSITIONs in USD,
* SP represents the total NAV of sPOSITIONs in USD.


---

# 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://fxprotocol.gitbook.io/fx-docs/f-x-protocol-mechanisms/the-f-x-invariant.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.
