Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

04-oracles.md fails to mention the Cumulative price is in UQ112 format and how to parse the number. #209

Open
zimmah opened this issue Nov 30, 2020 · 0 comments

Comments

@zimmah
Copy link

zimmah commented Nov 30, 2020

It took quite some effort to figure out how to parse the number into something sensible.

The article makes it seem like when you calculate (price0CumulativeLast2 - price0CumulativeLast1) / (timestamp2 - timestamp1) you will get the price of token 0 in terms of token 1 as an integer.

This is however not the case, and instead you get back an UQ112 representation, which you then need to divide by 2**(112-Math.log2(1e18)) or alternatively divide by 2**(112)/1e18.

This is not at all clear from reading the guide.

Note: I assume the 18 is only because of the token having 18 decimals. So in fact it should probably be 2**(112-Math.log2(10**d)) where d is the number of decimals the token has.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant