> For the complete documentation index, see [llms.txt](https://fxprotocol.gitbook.io/fx-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fxprotocol.gitbook.io/fx-docs/f-x-protocol-mechanisms/the-f-x-invariant.md).

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