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
  • XCN Speed
  • XCN Distributed Per Block (All Markets)
  • XCN Distributed Per Block (Single Market)
  1. Comptroller

XCN Distribution Speeds

XCN Speed

The "XCN speed" unique to each market is an unsigned integer that specifies the amount of XCN that is distributed, per block, to suppliers and borrowers in each market. This number can be changed for individual markets by calling the _setXcnSpeed method through a successful Onyx Governance proposal.

The following is the formula for calculating the rate that XCN is distributed to each supported market.

utility = oTokenTotalBorrows * assetPrice

utilityFraction = utility / sumOfAllStrikedMarketUtilities

marketXcnSpeed = xcnRate * utilityFraction

XCN Distributed Per Block (All Markets)

The Comptroller contract’s xcnRate is an unsigned integer that indicates the rate at which the protocol distributes XCN to markets’ suppliers or borrowers, every Ethereum block. The value is the amount of XCN (in wei), per block, allocated for the markets. Note that not every market has XCN distributed to its participants (see Market Metadata).

The xcnRate indicates how much XCN goes to the suppliers or borrowers, so doubling this number shows how much XCN goes to all suppliers and borrowers combined. The code examples implement reading the amount of XCN distributed, per Ethereum block, to all markets.

Comptroller

uint public xcnRate;

Solidity

Comptroller troll = Comptroller(0xABCD...);

// XCN issued per block to suppliers OR borrowers * (1 * 10 ^ 18)
uint xcnRate = troll.xcnRate();

// Approximate XCN issued per day to suppliers OR borrowers * (1 * 10 ^ 18)
uint xcnRatePerDay = xcnRate * 4 * 60 * 24;

// Approximate XCN issued per day to suppliers AND borrowers * (1 * 10 ^ 18)
uint xcnRatePerDayTotal = xcnRatePerDay * 2;

Web3 1.2.6

const comptroller = new web3.eth.Contract(comptrollerAbi, comptrollerAddress);

let xcnRate = await comptroller.methods.xcnRate().call();
xcnRate = xcnRate / 1e18;

// XCN issued to suppliers OR borrowers
const xcnRatePerDay = xcnRate * 4 * 60 * 24;

// XCN issued to suppliers AND borrowers
const xcnRatePerDayTotal = xcnRatePerDay * 2;

XCN Distributed Per Block (Single Market)

The Comptroller contract has a mapping called xcnSpeeds. It maps oToken addresses to an integer of each market’s XCN distribution per Ethereum block. The integer indicates the rate at which the protocol distributes XCN to markets’ suppliers or borrowers. The value is the amount of XCN (in wei), per block, allocated for the market. Note that not every market has XCN distributed to its participants (see Market Metadata).

The speed indicates how much XCN goes to the suppliers or the borrowers, so doubling this number shows how much XCN goes to market suppliers and borrowers combined. The code examples implement reading the amount of XCN distributed, per Ethereum block, to a single market.

Comptroller

mapping(address => uint) public xcnSpeeds;

Solidity

Comptroller troll = Comptroller(0x123...);
address oToken = 0xabc...;

// XCN issued per block to suppliers OR borrowers * (1 * 10 ^ 18)
uint xcnSpeed = troll.xcnSpeeds(oToken);

// Approximate XCN issued per day to suppliers OR borrowers * (1 * 10 ^ 18)
uint xcnSpeedPerDay = xcnSpeed * 4 * 60 * 24;

// Approximate XCN issued per day to suppliers AND borrowers * (1 * 10 ^ 18)
uint xcnSpeedPerDayTotal = xcnSpeedPerDay * 2;

Web3 1.2.6

const oTokenAddress = '0xabc...';

const comptroller = new web3.eth.Contract(comptrollerAbi, comptrollerAddress);

let xcnSpeed = await comptroller.methods.xcnSpeeds(oTokenAddress).call();
xcnSpeed = xcnSpeed / 1e18;

// XCN issued to suppliers OR borrowers
const xcnSpeedPerDay = xcnSpeed * 4 * 60 * 24;

// XCN issued to suppliers AND borrowers
const xcnSpeedPerDayTotal = xcnSpeedPerDay * 2;
PreviousFailure InfoNextClaim XCN

Last updated 2 years ago

⚙️