Formula

NostraSwap imposes a LimitPriceImpactPerSecond on the oracle price to protect against manipulations. Upon initialization, the oracle price is set to be the market price:

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

For each trade, the oracle price is updated through the following rule:

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

Where

OP OP is the stored oracle price in the contract OP OP' is the new oracle price MP MP is the market price t t is time in seconds since the oracle price was last updated LPIPS LPIPSis 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.

Last updated

Was this helpful?