> For the complete documentation index, see [llms.txt](https://nostraswap.gitbook.io/nostraswap/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nostraswap.gitbook.io/nostraswap/protocol/price-oracle/formula.md).

# Formula

NostraSwap imposes a LimitPriceImpactPerSecond on the oracle price to protect against manipulations. Upon initialization, the oracle price is set to be the market pric&#x65;**:**

$$
OP = MP = \frac{reserve0}{reserve1}
$$

For each trade, the oracle price is updated through the following rul&#x65;**:**

$$
OP' =
\begin{cases}
min(OP \* (1 + lpips) ^ t, MP) ,& \text{if } OP \leq MP\\
max(OP \* (1 - lpips) ^ t, MP),              & \text{otherwise}
\end{cases}
$$

Where&#x20;

$$OP$$is the stored oracle price in the contract\
$$OP'$$is the new oracle price\
$$MP$$is the market price\
$$t$$ is time in seconds since the oracle price was last updated\
$$LPIPS$$is a hyperparameter initially set to be 0.019% (around 0.25% per block) but can be updated by the factory owner to suit the volatility of different assets.

As opposed to TWAP, this method of calculating oracle price from market price can both provide price security and price freshness.
