Skip to main content

ChainlinkPriceAdapter

ChainlinkPriceAdapter

Price adapter for assets using Chainlink oracle feeds. Supports an optional quote feed for cross-rate normalisation (e.g. ETH/USD / USDC/USD to obtain ETH/USDC).

FeedConfig

Per-asset feed configuration.

Parameters

NameTypeDescription
struct FeedConfig {
address feed;
address quoteFeed;
bool isInverse;
uint256 maxStaleness;
uint256 minPrice;
uint256 maxPrice;
uint256 scaleFactor;
}

feedConfigOf

mapping(address => struct ChainlinkPriceAdapter.FeedConfig) feedConfigOf

Per-asset feed configuration store.

INVERSE_DECIMALS

uint8 INVERSE_DECIMALS

Precision used for inverse-feed output (1/price scaled to 10^INVERSE_DECIMALS).

PRICE_DECIMALS

uint8 PRICE_DECIMALS

Precision of the cross-rate output when a quoteFeed is configured.

FeedConfigured

event FeedConfigured(address asset, address feed, bool inverse, uint256 maxStaleness, uint256 minPrice, uint256 maxPrice, address quoteFeed)

Emitted when a Chainlink feed is configured for an asset

Parameters

NameTypeDescription
assetaddressThe asset address
feedaddressThe Chainlink base aggregator address
inverseboolWhether this feed returns inverse pricing
maxStalenessuint256Maximum acceptable staleness in seconds
minPriceuint256Minimum acceptable price
maxPriceuint256Maximum acceptable price
quoteFeedaddressThe optional quote aggregator address (address(0) if not set)

constructor

constructor() public

configureFeed

function configureFeed(address asset, address feed, bool inverse, uint256 _maxStaleness, uint256 _minPrice, uint256 _maxPrice, address quoteFeed) external

Configure Chainlink feed for an asset.

Parameters

NameTypeDescription
assetaddressThe asset address.
feedaddressThe Chainlink base aggregator address.
inverseboolWhether this feed returns inverse pricing. Cannot be combined with quoteFeed.
_maxStalenessuint256Maximum acceptable staleness in seconds for both feeds.
_minPriceuint256Minimum acceptable base feed answer (in base feed decimals).
_maxPriceuint256Maximum acceptable base feed answer (in base feed decimals).
quoteFeedaddressOptional second Chainlink aggregator used as the quote denominator. Pass address(0) for single-feed behaviour. When set, getPriceData returns baseFeedPrice * scaleFactor / quoteFeedPrice with output decimals equal to PRICE_DECIMALS (18).

validatePriceAdapter

function validatePriceAdapter(address asset) external view

Validates that the given asset is compatible with this adapter

Reverts with InvalidAdapter if the asset is not compatible

Parameters

NameTypeDescription
assetaddressThe address of the asset to validate

getPriceData

function getPriceData(address asset) external view returns (uint256 price, uint8 decimals)

Get the price data for an asset

The asset shall be whitelisted in the OrionConfig contract. The registry will handle normalization to priceAdapterDecimals.

Parameters

NameTypeDescription
assetaddressThe address of the asset to get the price for

Return Values

NameTypeDescription
priceuint256The raw price of the asset
decimalsuint8The number of decimals for the returned price