morpho-org / morpho-blue-oracles

Morpho Blue Oracles
https://morpho.org
Other
29 stars 25 forks source link

Oracle Price decimals inconsistencies #101

Closed codekoriko closed 2 weeks ago

codekoriko commented 2 weeks ago

Morpho | Borrow: WBTC / WETH

To get to the correct price it's: WETH Decimals + IOracle.SCALE_FACTOR() Decimals >> 28 + 18 = 46 ethers.utils.formatUnits(231526751276196240000000000000000000000000000000n, 46) >> correctly formatted price: 23.152675127619624

Morpho | Borrow: WBTC / USDT

To get to the correct price it's: WBTC Decimals + IOracle.SCALE_FACTOR() Decimals >> 26 + 8 = 34 ethers.utils.formatUnits(634191901421668523189305629876995670202n, 34) >> correctly formatted price: 63419.1901421668523189305629876995670202

Morpho | Borrow: WBTC / USDT

To get to the correct price it's: WBTC Decimals + IOracle.SCALE_FACTOR() Decimals >> 24 + 0 = 24 ethers.utils.formatUnits(634191901421668523189305629876995670202n, 24) >> correctly formatted price: 64238.890625138135724857677952

Why is there those inconsistencies in the oracle price decimals?

  1. First Market it's the SCALE_FACTOR decimals + Collat token Decimals
  2. Second it's SCALE_FACTOR decimals + loan token Decimals
  3. Last it's just SCALE_FACTOR decimals

How can I reliably get the correct price for every morpho market oracles? cause I suppose than morpho blue is able to do it somehow

codekoriko commented 2 weeks ago

Got it wrong, it's simply

IOracle.price() / (10 ** (loanTokenDecimals - collatTokenDecimals ))

I'm not sure what the IOracle.SCALE_FACTOR() was intended for though