Skip to main content

ERC7726OracleCloneable

Git Source

Inherits: IERC7726Oracle, IERC7726OraclePriceCache, Clone

Title: ERC7726OracleCloneable

Author: OlympusDAO

forge-lint: disable-start(mixed-case-function,mixed-case-variable)

Cloneable ERC7726 oracle that quotes any base/quote pair from cached pair snapshots

Functions

factory

The factory address

Does not revert.

function factory() public pure returns (IERC7726OracleFactory);

maxAge

The maximum allowed age for cached prices

Does not revert.

function maxAge() public pure override returns (uint48);

name

Get the name of the oracle.

Does not revert.

function name() external pure override returns (string memory);

Returns

NameTypeDescription
<none>stringThe name of the oracle.

_getEnabledPriceCache

Returns the enabled price cache policy for this oracle.

Calls factory().getOracleContext(address(this)) to read the enabled state and price cache address for the current contract. Reverts with ERC7726Oracle_NotEnabled() when the returned enabled flag is false. Assumes the factory returns a valid IPriceCache address.

function _getEnabledPriceCache() internal view returns (IPriceCache priceCache_);

Returns

NameTypeDescription
priceCache_IPriceCacheThe enabled price cache policy for this oracle.

getQuote

One-sided price: How much quote token you would get for inAmount of base token, assuming no price spread.

Uses cached pair snapshots only. Reverts if:

  • The oracle is disabled in the factory or the factory is deactivated in Kernel
  • The IPriceCache.getCachedPrice() call reverts because the cache policy is deactivated in Kernel or the cache contract is disabled
  • The base/quote pair is invalid for the configured cache policy
  • The shared cached timestamp is stale
  • Base/quote cached prices are zero
  • The price cache cannot resolve amount decimals for either asset If callers encounter a feed-state revert, they should cache prices then retry. A caller can alternatively call isStale(), call cachePrice() (if the result is true), and then this function.
function getQuote(uint256 inAmount, address base, address quote)
external
view
override
returns (uint256 outAmount);

Parameters

NameTypeDescription
inAmountuint256The amount of base to convert.
baseaddressThe token that is being priced.
quoteaddressThe token that is the unit of account.

Returns

NameTypeDescription
outAmountuint256The amount of quote that is equivalent to inAmount of base.

_getQuoteInternal

function _getQuoteInternal(uint256 inAmount_, address base_, address quote_)
internal
view
returns (uint256 outAmount_);

getQuotes

Two-sided price: How much quote token you would get/spend for selling/buying inAmount of base token.

Returns symmetric bid/ask using the same quote value. Reverts if:

  • The oracle is disabled in the factory or the factory is deactivated in Kernel
  • The cache policy is deactivated in Kernel or the cache contract is disabled
  • The base/quote pair is invalid for the configured cache policy
  • The shared cached timestamp is stale
  • Base/quote cached prices are zero
  • The price cache cannot resolve amount decimals for either asset
function getQuotes(uint256 inAmount, address base, address quote)
external
view
override
returns (uint256 bidOutAmount, uint256 askOutAmount);

Parameters

NameTypeDescription
inAmountuint256The amount of base to convert.
baseaddressThe token that is being priced.
quoteaddressThe token that is the unit of account.

Returns

NameTypeDescription
bidOutAmountuint256The amount of quote you would get for selling inAmount of base.
askOutAmountuint256The amount of quote you would spend for buying inAmount of base.

cachePrice

Updates the cached direct pair unconditionally

Reverts if:

  • The factory is disabled
  • This contract is not a deployed oracle from the factory
  • This contract is not enabled in the factory
  • The active price cache rejects the pair
function cachePrice(address base_, address quote_) external override;

Parameters

NameTypeDescription
base_addressThe base asset address
quote_addressThe quote asset address

cachePriceIfNecessary

Updates the cached direct pair only if stale or unset

Reverts if:

  • The factory is disabled
  • This contract is not a deployed oracle from the factory
  • This contract is not enabled in the factory
  • The active price cache rejects the pair
  • The active price cache reverts while evaluating staleness or caching
function cachePriceIfNecessary(address base_, address quote_) external override;

Parameters

NameTypeDescription
base_addressThe base asset address
quote_addressThe quote asset address

_isStaleFromTimestamp

function _isStaleFromTimestamp(uint48 timestamp_, uint48 maxAge_) internal view returns (bool);

_latestPermissibleTimestamp

Computes the oldest timestamp that is still permissible for freshness checks.

Returns 0 when block.timestamp <= maxAge_; otherwise returns block.timestamp - uint256(maxAge_).

Does not revert.

A zero return value means every non-zero timestamp is permissible at the current block timestamp. Callers can use this value in stale revert payloads to report the lower freshness bound without implying that timestamp 0 is valid cached data.

function _latestPermissibleTimestamp(uint48 maxAge_) internal view returns (uint256);

Parameters

NameTypeDescription
maxAge_uint48Maximum acceptable age, in seconds.

Returns

NameTypeDescription
<none>uint256latestPermissible_ Oldest acceptable timestamp, or 0 if no positive lower bound exists.

isStale

Returns whether the direct pair cache is stale for a given pair.

Reverts if:

  • The oracle is disabled in the factory or the factory is deactivated in Kernel
  • The IPriceCache.isStale() call reverts because the cache policy is deactivated in Kernel or the cache contract is disabled
  • The active cache policy rejects (base, quote)
function isStale(address base, address quote) external view override returns (bool);

Parameters

NameTypeDescription
baseaddressThe address of the base token
quoteaddressThe address of the quote token

Returns

NameTypeDescription
<none>boolisStale_ Returns true if the pair cache is unset or older than maxAge.

timestamp

Returns the cached timestamp used for a given base/quote pair.

Returns 0 if the pair price has not been cached. Reverts if:

  • The oracle is disabled in the factory or the factory is deactivated in Kernel
  • The cache policy is deactivated in Kernel or the cache contract is disabled
  • The active cache policy rejects (base, quote)
function timestamp(address base, address quote) external view override returns (uint48);

Parameters

NameTypeDescription
baseaddressThe address of the base token
quoteaddressThe address of the quote token

Returns

NameTypeDescription
<none>uint48timestamp_ The cached UNIX timestamp (uint48) for this base/quote pair used to judge staleness.

supportsInterface

Query if a contract implements an interface

Does not revert.

function supportsInterface(bytes4 interfaceId_) public pure returns (bool);

Parameters

NameTypeDescription
interfaceId_bytes4The interface identifier, as specified in ERC-165

Returns

NameTypeDescription
<none>boolbool True if the contract implements interfaceId_