EIPs Explained

ERC-7726 · Draft · ERC · 2024-06-20

ERC-7726: Common Quote Oracle

A one-function oracle interface, getQuote(amount, base, quote), that returns how much of one asset another amount is worth, so protocols can swap price feeds without custom adapters or decimal math.

What problem does it solve?

Valuing assets on-chain means integrating price sources that each have their own API, decimals convention and security model. Over the years many protocols built their own oracle adapter layers to hide this, duplicating a lot of work and repeating the same decimal-scaling bugs.

ERC-7726 defines a common, minimal API for "how much is X of asset A worth in asset B". It deliberately returns token amounts, not decimal price factors, which the authors say leads to safer integrations and faster shipping.

How it works

There is a single view function:

getQuote(uint256 baseAmount, address base, address quote) returns (uint256 quoteAmount)
  • base: the asset being valued. quote: the asset to value it in.
  • The result is an amount of quote in its own smallest units. For example, asking for 1000e6 USDC in ETH terms returns an ETH amount in wei. The caller never has to know either token's decimals.
  • It must round down toward zero and must revert if the result would overflow uint256.

Assets without an address get conventional ones:

Asset Address
ETH 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE (ERC-7528)
BTC 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB
Fiat with an ISO 4217 code address(code), e.g. address(840) for USD

There is no getPrice. If you want "price of one whole unit", request a quote for 10 ** decimals of the base token.

Sample code

Interface and a consumer that values collateral:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IERC7726 {
    function getQuote(uint256 baseAmount, address base, address quote)
        external view returns (uint256 quoteAmount);
}

contract CollateralCheck {
    address constant USD = address(840);
    IERC7726 public immutable oracle;

    constructor(IERC7726 _oracle) { oracle = _oracle; }

    // Value of `amount` units of `token`, expressed in the oracle's USD units.
    function valueInUsd(address token, uint256 amount) external view returns (uint256) {
        return oracle.getQuote(amount, token, USD);
    }
}

Things to know

  • Status: Draft. Function names and special addresses may still change.
  • The interface intentionally has no way to check freshness, confidence or validity of the data. Each implementation is expected to publish its own guarantees (staleness, when it stops serving data), and consumers must review them before integrating.
  • Because results are rounded down, chained quotes (A to B to C) can lose precision; design for that when composing adapters.
  • Most existing feeds (Chainlink-style, TWAPs, ERC-4626 vault rates) can be wrapped behind this interface with an adapter.
  • The ETH address convention comes from ERC-7528; the BTC and ISO 4217 conventions are defined in this ERC.

#oracle #defi #price-feed #interface

Details

Authors
alcueca (@alcueca), ruvaag (@ruvaag), totomanov (@totomanov), r0ohafza (@r0ohafza)
Status
Draft
Type
Standards Track / ERC
Created
2024-06-20
Requires
Required by

Machine-readable: Markdown · JSON