1inch/spot-price-aggregator

How to get USD+ price?

Closed this issue · 1 comments

Screenshot 2023-04-03 at 12 43 49 PM

How to transform weightedRate to USD+ price like to image below?
Screenshot 2023-04-03 at 12 46 06 PM

You should scale by the difference in decimals and divide by 1e18. See example here. For your case it'll be like this:

oracleResponse * srcTokenDecimals / dstTokenDecimals / 1e18 =
1963509366702897051261009902073 * 1e6 / 1e18 / 1e18 =
1.9635

Which is also obviously incorrect result as the price should be $1 but not $2. We'll look into that.