Integrate Oracles

This guide walks through integrating Mento's on-chain price feeds into your application. The SortedOracles contract aggregates FX rates from multiple oracle providers (Chainlink, Redstone) to provide reliable exchange rates for stable asset pairs. Mento relayers continuously push these rates on-chain to ensure fresh pricing data.

Common Use Cases

DeFi Protocols

Use real-time FX rates for cross-currency calculations, collateral valuation, and liquidation thresholds.

Price Feed Aggregators

Aggregate Mento's FX rates with other sources to provide comprehensive currency data.

Cross-Border Applications

Build remittance calculators, multi-currency wallets, or international payment systems using accurate FX rates.

Stable Asset Pricing

Understand how Mento pools price swaps between stable assets using these oracle rates.

Integration Steps

Step 1: Connect to SortedOracles Contract

Mento oracle data is available through the SortedOracles contract:

See Smart Contracts > Deployments for testnet addresses.

Step 2: Query Exchange Rates

Get FX rates from the sorted oracles contract. Note that rate feed IDs can be either:

  • Stable token addresses (legacy format, e.g., USDm address for CELO/USD)

  • Derived addresses for specific currency pairs (e.g., keccak256("NGNUSD") for NGN/USD)

Note: For the full list of rate feed IDs check out the Oracles & Price Feeds page

For cross-currency rates:

Step 3: Implement Rate Conversion

Use the FX rates for currency conversions. Note that rates in SortedOracles represent various currency pairs:

These rates are crucial for Mento's pools - they determine the exchange ratios between stable assets (e.g., USDm/NGNm uses the NGN/USD rate).

Step 4: Check Oracle Health

Verify that oracle data is fresh and reliable:

Working with Oracle Data

Rate Format

  • Rates use 24 decimal fixed-point precision (1e24)

  • numerator / denominator gives the exchange rate

  • For FX pairs, the rate represents Quote per 1 Base:

    • NGN/USD: How much USD per 1 NGN (e.g., 0.000654 USD = 1 NGN)

    • GBP/USD: How much USD per 1 GBP

    • EUR/XOF: How much XOF per 1 EUR

  • For CELO pairs (legacy format), the rate represents Base per 1 Quote:

    • CELO/USD: How much CELO per 1 USD

Report Expiry

Oracle reports expire after a configured time period. Expired reports are automatically excluded from median calculations.

Best Practices

Rate Validation

Always validate oracle data before use:

  • Verify rate is within expected bounds

  • Consider implementing circuit breakers for extreme values

Gas Optimization

Cache oracle results when multiple operations use the same rate within a transaction.

Error Handling

Handle cases where:

  • No oracle reports exist for a token

  • All reports have expired

  • Rate calculation results in zero denominator

Advanced Usage

Historical Data

While the contract stores current reports, historical data analysis requires:

  • Monitoring MedianUpdated events

  • Maintaining off-chain data stores

  • Using indexing services like The Graph

JavaScript Integration

Using ethers

Using viem

Support

Next Steps

Last updated