compound-protocol
compound-protocol copied to clipboard
Clarify the precision of exchangeRate
The documentation in https://compound.finance/docs/ctokens#exchange-rate states the following:

However the source code at CToken intialExchangeRateMantissa, CToken and CErc20Delegator states it is fixed at 18 decimal digits.
exchangeRateStoredInternal
does not seem to take the underlying asset into account (it uses Exponential.getExp
, but that also states 18 decimal precision). Is the documentation just wrong or am I misunderstanding something?
To make the answer short, documentation is correct here.
To clarify, for the case of DAI/cDAI exchangeRateCurrent()
is 28 decimal fixed-point number
18 - 8 + 18 = 28 as in this case Underlying Token Decimals is 18(DAI)
If we read contract here https://etherscan.io/token/0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643?a=0x2ec7947f3ac9aaaa44b53640506cdc9d848d9489#readContract
exchangeRateCurrent
is 216064523443228187636427149
which has 27 digits so this is 0.021...
on 28 decimal precision...
Comments in source code should be fixed