Onyx Protocol
  • 📖Onyx Documentation
  • ☕Getting Started
    • 🔬Networks
    • 📒Protocol Math
      • oToken and Underlying Decimals
      • Interpreting Exchange Rates
      • Calculating Accrued Interest
      • Calculating the APY Using Rate Per Block
    • 💹Gas Costs
  • 🧑‍💻OTokens
    • Mint
    • Redeem
    • Redeem Underlying
    • Borrow
    • Repay Borrow
    • Repay Borrow Behalf
    • Transfer
    • Liquidate Borrow
    • Key Events
    • Error Codes
    • Failure Info
    • Exchange Rate
    • Get Cash
    • Total Borrow
    • Borrow Balance
    • Borrow Rate
    • Total Supply
    • Underlying Balance
    • Supply Rate
    • Total Reserves
    • Reserve Factor
  • ⚙️Comptroller
    • Enter Markets
    • Exit Market
    • Get Assets In
    • Collateral Factor
    • Get Account Liquidity
    • Close Factor
    • Liquidation Incentive
    • Key Events
    • Error Codes
    • Failure Info
    • XCN Distribution Speeds
    • Claim XCN
    • Market Metadata
  • 👨‍👩‍👦Governance
    • Governor Alpha
    • Quorum Votes
    • Proposal Threshold
    • Proposal Max Operations
    • Voting Delay
    • Voting Period
    • Propose
    • Queue
    • Execute
    • Cancel
    • Get Actions
    • Get Receipt
    • State
    • Cast Vote
    • Cast Vote By Signature
    • Timelock
    • Pause Guardian
  • 🔡API
    • Basic API
      • GET: /otoken
      • GET: /market_history/graph
      • GET: /user/history
      • GET: /get_liquidators
      • GET: /get_liquidator:account
      • GET: /get_liquidator_detail:account
      • GET: /liquidator
    • GraphQL API
      • oTokens Subgraph
      • History Subgraph
      • Governance Subgraph
    • Governance API
      • GET: /proposal
      • GET: /proposal/:proposalId
      • GET: /voter/:proposalId
      • GET: /voter/accounts
      • GET: /voter/history/:address
    • Shared Data Types
  • 📖Onyx.js
    • Onyx Constructor
    • API Methods
      • Account
      • oToken
      • Market History
      • Governance
    • oToken Methods
      • Supply
      • Redeem
      • Borrow
      • Repay Borrow
    • XCN Methods
      • To Checksum Address
      • Get XCN Balance
      • Get XCN Accrued
      • Claim XCN
      • Delegate
      • Delegate By Sig
      • Create Delegate Signature
    • Comptroller Methods
      • Enter Markets
      • Exit Market
    • Ethereum Methods
      • Read
      • Trx
      • Get Balance
    • Governance Methods
      • Cast Vote
      • Cast Vote By Sig
      • Create Vote Signature
    • Price Feed Methods
      • Get Price
    • Utility Methods
      • Get Address
      • Get ABI
      • Get Network Name With Chain ID
  • 🔒Security
    • Bug Bounty Program
  • 📄Terms of Service
Powered by GitBook
On this page
  1. Getting Started
  2. Protocol Math

Interpreting Exchange Rates

PreviousoToken and Underlying DecimalsNextCalculating Accrued Interest

Last updated 1 year ago

The oToken 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
☕
📒
Exchange Rate