Skip to main content

Chainlink Operator

Aggregates the price feeds provided by Chainlink.

Constant Functions

getFeed

function getFeed(
string symbol
) external returns (contract IErc20, contract IAggregatorV3, bool)

Gets the official feed for a symbol.

Parameters

NameTypeDescription
symbolstringThe symbol to return the feed for.

Return Values

NameTypeDescription
addressstringasset, address id, bool isSet).

getNormalizedPrice

function getNormalizedPrice(
string symbol
) external returns (uint256)

Gets the official price for a symbol and adjusts it have 18 decimals instead of the format used by Chainlink, which has 8 decimals.

Requirements:

  • The normalized price cannot overflow.

Parameters

NameTypeDescription
symbolstringThe Erc20 symbol of the token for which to query the price.

Return Values

TypeDescription
stringnormalized price.

getPrice

function getPrice(
string symbol
) external returns (uint256)

Gets the official price for a symbol in the default format used by Chainlink, which has 8 decimals.

Requirements:

  • The feed must have been previously set.
  • The price returned by the oracle cannot be zero.

Parameters

NameTypeDescription
symbolstringThe symbol to fetch the price for.

Return Values

TypeDescription
stringdenominated in USD, with 8 decimals.

pricePrecision

function pricePrecision() external returns (uint256)

Chainlink price precision for USD-quoted data.

pricePrecisionScalar

function pricePrecisionScalar() external returns (uint256)

The ratio between normalized precision (1e18) and the Chainlink price precision (1e8).

Non-Constant Functions

deleteFeed

function deleteFeed(
string symbol
) external

Deletes a previously set Chainlink price feed.

Emits a {DeleteFeed} event.

Requirements:

  • The caller must be the owner.
  • The feed must have been previously set.

Parameters

NameTypeDescription
symbolstringThe Erc20 symbol of the asset to delete the feed for.

setFeed

function setFeed(
contract IErc20 asset,
contract IAggregatorV3 feed
) external

Sets a Chainlink price feed.

It is not an error to set a feed twice. Emits a {SetFeed} event.

Requirements:

  • The caller must be the owner.
  • The number of decimals of the feed must be 8.

Parameters

NameTypeDescription
assetcontract IErc20The address of the Erc20 contract for which to get the price.
feedcontract IAggregatorV3The address of the Chainlink price feed contract.

Events

DeleteFeed

event DeleteFeed(
contract IErc20 asset,
contract IAggregatorV3 feed
)

Emitted when a feed is deleted.

Parameters

NameTypeDescription
assetcontract IErc20The related asset.
feedcontract IAggregatorV3The related feed.

SetFeed

event SetFeed(
contract IErc20 asset,
contract IAggregatorV3 feed
)

Emitted when a feed is set.

Parameters

NameTypeDescription
assetcontract IErc20The related asset.
feedcontract IAggregatorV3The related feed.