Skip to content
This repository was archived by the owner on Nov 23, 2021. It is now read-only.
This repository was 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

@zimmah

Description

@zimmah

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions