# 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.


---

# 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://nostraswap.gitbook.io/nostraswap/protocol/price-oracle/formula.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.
