Submitted by cmichel
The CompositeMultiOracle.peek/get functions seem to return wrong prices.
Its unclear what decimals source.decimals refers to in this case. Does it refer to source.source token decimals?
It chains the price arguments through _peek function calls and a single price is computed as:
Assume all oracles use 18 decimals (oracle.decimals() returns 18) and source.decimals refers to the token decimals of source.source.
Then going from USDC -> DAI -> USDT (path = [DAI]) starts with a price of 1e18 in peek:
It then uses 1e30 as the price to go from USDC to USDT: value = price * amount / 1e18 = 1e30 * (1.0 USDC) / 1e18 = 1e30 * 1e6 / 1e18 = 1e18 = 1e12 * 1e6 = 1_000_000_000_000.0 USDT. Inflating the actual USDT amount.
The issue is that peek assumes that the final price is in 18 decimals in the value = price * amount / 1e18 division by 1e18.
But _peek (and _get) dont enforce this.
Recommend that _peek should scale the prices to 1e18 by doing:
It does not need to divide by the source.source token precision (source.decimals), but by the oracle precision (IOracle(source.source).decimals()).
alcueca (Yield) acknowledged:
alcueca (Yield) patched:
alcueca (Yield) further patched:
