Interpreting Exchange Rates

The oToken Exchange Rate is scaled by the difference in decimals between the oToken and the underlying asset.

const oneOTokenInUnderlying = exchangeRateCurrent / (1 * 10 ^ (18 + underlyingDecimals - oTokenDecimals))

Here is an example of finding the value of 1 oUSDP in USDP with Web3.js JavaScript.

const oTokenDecimals = 8; // all oTokens have 8 decimal places
const underlying = new web3.eth.Contract(erc20Abi, usdpAddress);
const oToken = new web3.eth.Contract(oTokenAbi, oUsdpAddress);
const underlyingDecimals = await underlying.methods.decimals().call();
const exchangeRateCurrent = await oToken.methods.exchangeRateCurrent().call();
const mantissa = 18 + parseInt(underlyingDecimals) - oTokenDecimals;
const oneOTokenInUnderlying = exchangeRateCurrent / Math.pow(10, mantissa);
console.log('1 oUSDP can be redeemed for', oneOTokenInUnderlying, 'USDP');

There is no underlying contract for ETH, so to do this with oETH, set underlyingDecimals to 18.

To find the number of underlying tokens that can be redeemed for oTokens, multiply the number of oTokens by the above value oneOTokenInUnderlying.

const underlyingTokens = oTokenAmount * oneOTokenInUnderlying

Last updated