# THE WORKING OF DOPEX PRICE ORACLES

We currently use Dopex Powered Oracles for the DPX and rDPX SSOVs.

These are secure oracles that account for heavy price fluctuations and cannot be easily manipulated. They use a TWAP (Time-Weighted Average Price) algorithm to calculate the average price over time to avoid any flashloan attacks.

TWAP which stands for Time-Weighted Average Price is a strategy to algorithmically calculate the average price of an asset over a certain period. Our oracles use a period of 30 minutes with an interval of 1-minute snapshots of prices to calculate the TWAP.

TWAP = Sum of prices of all snapshots / No. of snapshots

The snapshot of the price of DPX and rDPX is taken every minute from the DPX/ETH Sushiswap Arbitrum Pool and the USD price is computed using the ETH Chainlink feed (Ensuring a fair price of ETH/USD is taken).

So what now? We take this TWAP of DPX or rDPX, calculate it and check the deviation from the price stored in the oracle contract. If the deviation is larger than 1.5% then we update the oracle with the newly calculated TWAP.

On Top of that, we also have a check for when the last update was made. If it is larger than 15 minutes, we update the oracle contract regardless of the deviation. Both of these parameters ensure that a fair price is always stored within the oracle contract.

Now let's take an example of how deviation is calculated for the TWAPs. Let's assume the newly calculated TWAP for DPX is \$1515 and the TWAP stored in the oracle contract is \$1540. Deviation for the above is calculated like the following:

Deviation = (Absolute Difference in Price / TWAP stored in the oracle contract) * 100

Absolute Difference in Price = Absolute(1515 - 1540) = Absolute(-25) = 25

Deviation = (25/1540) * 100 = 0.016 * 100 = 1.6%

Since the deviation exceeds 1.5%, an update will be made to the oracle contract to update the price.

We continually monitor the price oracle and change these parameters (the deviation and the mandatory minimum update time) accordingly.

This structure of updating prices is very similar to how Chainlink updates their feeds (They call them deviation threshold and heartbeat thresholds, read more here).The only difference being, that Chainlink uses an aggregation of prices from off chain sources, which does not make sense for DPX or rDPX as the only pool DPX or rDPX is heavily traded on with deep liquidity is the Sushiwap DPX/ETH or rDPX/ETH pool on Arbitrum.

You can visit the newly developed oracles page here https://app.dopex.io/oracles to check the status of our oracles.