Mento Protocol
  • Overview
    • Getting Started
      • What Is Mento?
      • Quick Start Guides
      • Analytics & Dashboards
    • Core Concepts
      • Stability Mechanisms
      • The Reserve
      • Oracles & Price Feeds
      • Trading Limits & Circuit Breakers
      • The Broker & Virtual AMMs
      • Fixed-Price Market Makers (FPMMs)
      • Research & Economics
    • Governance & the MENTO Token
      • Understanding Mento Governance
      • Participating in Governance
        • veMENTO & Voting Power
        • Creating Proposals
        • Voting Process
      • MENTO Tokenomics
      • Watchdogs & Safety
    • Security & Risk
      • Overview
      • Audit Reports
  • Build On Mento
    • Integration Overview
      • Integrate Stables
      • Integrate the Broker
      • Integrate Oracles
    • Mento SDK
      • Installation
      • Guides
        • Getting Exchange Pairs
        • Getting a Quote
        • Initiating a Swap
    • Smart Contracts
      • Broker
      • TradingLimits
      • BiPoolManager
      • Pricing Modules
      • SortedOracles
      • BreakerBox
      • Reserve
      • StableToken
      • Audits
    • Deployments
      • Addresses
      • Verification
  • Use Mento
    • Getting Mento Stables
      • On Celo
      • On Mobile
      • From Other Chains
      • Via Centralized Exchanges
Powered by GitBook
On this page
Edit on GitHub
  1. Build On Mento
  2. Smart Contracts

SortedOracles

PreviousPricing ModulesNextBreakerBox

Last updated 12 months ago

CtrlK

SortedOracles stores and maintains the state of oracle reports. Oracle clients insert their rates into a sorted linked list and the contract checks newly inserted rates against the on-chain circuit breaker BreakerBox.sol. If valid, the rate can be used by the protocol to price swaps, otherwise, trading will be halted.

Unique Rate Feed Identifiers

Each oracle rate, internally called rate feed, is uniquely identified by a rateFeedID. It is used when adding oracle rates to the SortedOracles smart contract by calling the addOracle function in a Celo governance proposal:

addOracle(address token, address oracleAddress)

For CELO/cStable rate feeds, the unique identifier is the address of the stable token. Since this doesn't work for more than one pair including the same stable token, which was not initially planned, a new formula is used to create unique rate feed identifiers for rate feeds other than CELO/cStable.

These identifiers can be derived using the following formula:

address(uint160(uint256(keccak256(${asset0asset1}))))

For example, USDCUSD inserted gives the following formula:

address(uint160(uint256(keccak256("USDCUSD"))))
// == 0xA1A8003936862E7a15092A91898D69fa8bCE290c

Rates that are relayed from Chainlink price feeds have the prefix "relayed:" added to the pair.

address(uint160(uint256(keccak256("relayed:PHPUSD"))))
// == 0xab921d6ab1057601A9ae19879b111fC381a2a8E9

An example can be found in this Celo Governance Proposal.