ERC-7726 - Common Quote Oracle

Created 2024-06-20
Status Draft
Category ERC
Type Standards Track
Authors
Requires

Abstract

The following allows for the implementation of a standard API for data feeds providing the relative value of assets, forcing compliant contracts to use explicit token amounts instead of price factors. This approach has been shown to lead to better security and time-to-market outcomes.

Motivation

The information required to value assets is scattered over a number of major and minor sources, each one with their own integration API and security considerations. Many protocols over the years have implemented oracle adapter layers for their own use to abstract this complexity away from their core implementations, leading to much duplicated effort.

This specification provides a standard API aimed to serve the majority of use cases. Preference is given to ease of integration and serving the needs of product teams with less knowledge, requirements and resources.

Specification

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 and RFC 8174.

Definitions

Methods

getQuote

Returns the value of baseAmount of base in quote terms.

MUST round down towards 0.

MUST revert if the value of baseAmount of base in quote terms would overflow in a uint256.

- name: getQuote
  type: function
  stateMutability: view

  inputs:
    - name: baseAmount
      type: uint256
    - name: base
      type: address
    - name: quote
      type: address

  outputs:
    - name: quoteAmount
      type: uint256

Special Addresses

Some assets under the scope of this specification don't have an address, such as ETH, BTC and national currencies.

For ETH, the address will be 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE as per ERC-7528.

For BTC, the address will be 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB.

For assets without an address, but with an ISO 4217 code, the code will be used (e.g. address(840) for USD).

Rationale

The use of getQuote doesn't require the consumer to be aware of any decimal partitions that might have been defined for the base or quote and should be preferred in most data processing cases.

The spec doesn't include a getPrice function because it is rarely needed on-chain, and it would be a decimal number of difficult representation. The popular option for representing prices can be implemented for ERC-20 with decimals as `oracle.getQuote(base, quote, 10**base.decimals()) and will give the value of a whole unit of base in quote terms.

Backwards Compatibility

Most existing data feeds related to the relative value of pairs of assets should be representable using this standard.

Security Considerations

This specification purposefully provides no methods for data consumers to assess the validity of the data they receive. It is expected of individual implementations using this specification to decide and publish the quality of the data that they provide, including the conditions in which they will stop providing it.

Consumers should review these guarantees and use them to decide whether to integrate or not with a data provider.

Copyright

Copyright and related rights waived via CC0.