Skip to main content

IPriceCache

Git Source

Title: IPriceCache

Author: OlympusDAO

Interface for caching explicit asset/quote pair snapshots

Functions

decimals

Return the USD decimal scale used by cached pair legs

function decimals() external view returns (uint8 decimals_);

Returns

NameTypeDescription
decimals_uint8USD decimal scale for cached assetPriceUsd/quotePriceUsd values

cachePrice

Cache an explicit asset/quote pair snapshot

function cachePrice(address asset_, address quote_) external;

Parameters

NameTypeDescription
asset_addressAsset in requested orientation
quote_addressQuote in requested orientation

assetDecimals

Return the amount decimal scale used for asset_ quote conversion

function assetDecimals(address asset_) external view returns (uint8 decimals_);

Parameters

NameTypeDescription
asset_addressAsset identifier

Returns

NameTypeDescription
decimals_uint8Amount decimal scale for asset_

assetSymbol

Return the symbol used for naming and display of asset_

function assetSymbol(address asset_) external view returns (string memory symbol_);

Parameters

NameTypeDescription
asset_addressAsset identifier

Returns

NameTypeDescription
symbol_stringSymbol for asset_

setNonContractAssetMetadata

Set the metadata for a registered non-contract asset

function setNonContractAssetMetadata(address asset_, uint8 decimals_, string calldata symbol_) external;

Parameters

NameTypeDescription
asset_addressNon-contract asset identifier
decimals_uint8Amount decimal scale for asset_
symbol_stringDisplay symbol for asset_

removeNonContractAssetMetadata

Remove the configured metadata for a non-contract asset

function removeNonContractAssetMetadata(address asset_) external;

Parameters

NameTypeDescription
asset_addressNon-contract asset identifier

cachePriceIfNecessary

Cache an explicit pair only when stale for maxAge_

function cachePriceIfNecessary(address asset_, address quote_, uint48 maxAge_) external;

Parameters

NameTypeDescription
asset_addressAsset in requested orientation
quote_addressQuote in requested orientation
maxAge_uint48Maximum acceptable snapshot age in seconds

getCachedPrice

Get the last cached snapshot for a pair in requested orientation

Returns a zeroed snapshot for valid pairs when no snapshot exists in the current cache epoch

function getCachedPrice(address asset_, address quote_) external view returns (CachedPrice memory cachedPrice);

Parameters

NameTypeDescription
asset_addressAsset in requested orientation
quote_addressQuote in requested orientation

Returns

NameTypeDescription
cachedPriceCachedPriceLast cached pair snapshot data; all fields are zero when no snapshot exists

isStale

Return whether pair snapshot is stale for maxAge_

function isStale(address asset_, address quote_, uint48 maxAge_) external view returns (bool stale);

Parameters

NameTypeDescription
asset_addressAsset in requested orientation
quote_addressQuote in requested orientation
maxAge_uint48Maximum acceptable snapshot age in seconds

Returns

NameTypeDescription
staleboolTrue when no cache exists or cache is older than maxAge_

Errors

PriceCache_PolicyNotActive

Thrown when this policy is no longer active in Kernel

error PriceCache_PolicyNotActive();

PriceCache_UnsupportedModuleVersion

Thrown when a required module version is unsupported

error PriceCache_UnsupportedModuleVersion(bytes5 keycode, uint8 major, uint8 minor);

Parameters

NameTypeDescription
keycodebytes5Module keycode
majoruint8Module major version
minoruint8Module minor version

PriceCache_UnsupportedModuleInterface

Thrown when a required module does not implement an interface

error PriceCache_UnsupportedModuleInterface(bytes5 keycode, bytes4 interfaceId);

Parameters

NameTypeDescription
keycodebytes5Module keycode
interfaceIdbytes4Interface identifier, as specified in ERC-165

PriceCache_InvalidPair

Thrown when an asset/quote pair is invalid

error PriceCache_InvalidPair(address asset_, address quote_);

Parameters

NameTypeDescription
asset_addressAsset in requested orientation
quote_addressQuote in requested orientation

PriceCache_NonContractAssetNotRegistered

Thrown when a non-contract asset is not registered in PRICE

error PriceCache_NonContractAssetNotRegistered(address asset_);

Parameters

NameTypeDescription
asset_addressNon-contract asset identifier

PriceCache_NonContractAssetDecimalsNotRegistered

Thrown when a non-contract asset has no cache decimals configured

error PriceCache_NonContractAssetDecimalsNotRegistered(address asset_);

Parameters

NameTypeDescription
asset_addressNon-contract asset identifier

PriceCache_NonContractAssetSymbolNotRegistered

Thrown when a non-contract asset has no cache symbol configured

error PriceCache_NonContractAssetSymbolNotRegistered(address asset_);

Parameters

NameTypeDescription
asset_addressNon-contract asset identifier

PriceCache_InvalidAsset

Thrown when the asset identifier is invalid for the requested cache operation

error PriceCache_InvalidAsset(address asset_);

Parameters

NameTypeDescription
asset_addressAsset identifier

PriceCache_InvalidAssetSymbol

Thrown when a non-contract asset symbol is invalid

error PriceCache_InvalidAssetSymbol();

Structs

CachedPrice

Pair cache snapshot in requested orientation

struct CachedPrice {
uint256 assetPriceUsd;
uint256 quotePriceUsd;
uint48 updatedAt;
uint80 roundId;
}

Properties

NameTypeDescription
assetPriceUsduint256Cached asset USD price
quotePriceUsduint256Cached quote USD price
updatedAtuint48Timestamp of snapshot write
roundIduint80Monotonic pair cache write counter

NonContractAssetMetadata

Stored metadata for a non-contract asset

struct NonContractAssetMetadata {
bool registered;
uint8 decimals;
string symbol;
}

Properties

NameTypeDescription
registeredboolWhether metadata is configured for the asset
decimalsuint8Amount decimal scale for the asset
symbolstringDisplay symbol for the asset

PairSnapshot

Internal pair snapshot storage in canonical token order

struct PairSnapshot {
uint256 token0PriceUsd;
uint256 token1PriceUsd;
uint48 updatedAt;
uint80 roundId;
uint64 token0Epoch;
uint64 token1Epoch;
}

Properties

NameTypeDescription
token0PriceUsduint256Cached USD price for the lower-sorted asset
token1PriceUsduint256Cached USD price for the higher-sorted asset
updatedAtuint48Timestamp of snapshot write
roundIduint80Monotonic pair cache write counter
token0Epochuint64Asset invalidation epoch for token0 at cache time
token1Epochuint64Asset invalidation epoch for token1 at cache time