Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniswap TWAP on-chain price oracle #176

Open
lukaskiss222 opened this issue Jul 15, 2022 · 0 comments
Open

Uniswap TWAP on-chain price oracle #176

lukaskiss222 opened this issue Jul 15, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@lukaskiss222
Copy link
Contributor

Instead of using chainlink as price oracle, we can try to use uniswap v3 pools as price oracle using TWAP.
(Based on this whitepaper https://uniswap.org/whitepaper-v3.pdf, chapter 5)
(https://docs.uniswap.org/protocol/concepts/V3-overview/oracle)

Idea:
Tick Accumulator -> The tick accumulator stores the cumulative sum of the active tick at the time of the observation. The tick accumulator value increases monotonically and grows by the value of the current tick - per second.

To derive the arithmetic mean tick over an interval, the caller needs to retrieve two observations, one after the other, take the delta of the two values, and divide by the time elapsed between them. Calculating a TWAP from the tick accumulator is also covered in the whitepaper. Note that using an arithmetic mean tick to derive a price corresponds to a geometric mean price.

We can use: https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/OracleLibrary.sol
especially consult function.

@lukaskiss222 lukaskiss222 added the enhancement New feature or request label Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant