A contract implementing PushAdapter that integrates with chainlink price feeds.
In previous versions, AspisLiquidityCalculatorV2 directly interacted with chainlink price feeds, we have separated the chainlink-specific logic into this dedicated adapter.
Configuring Token Price Feeds:
Each token must be configured with a DataFeed object:
struct DataFeed {
address priceFeedAddress;
uint8 baseDecimals;
uint8 quoteDecimals;
}
The quoteDecimals represents the token’s decimal places, baseDecimals represents decimals of chainlink price feed. priceFeedAddress is the address of the chainlink price feed for the token.
To configure a DataFeed for a token we use updatePriceFeeds function (limited to Guardian)
function updatePriceFeeds(
address[] calldata _tokens,
DataFeed[] calldata _dataFeeds) external onlyGuardian {}
_tokens: ERC-20 token addresses_dataFeeds: An array of DataFeed objects that correspond to each tokenThe function iterates through all tokens and updates tokenToPriceFeed mappings then calls _verifyPriceFeed to verify validity of the provided price feed:
decimals on price feed must return baseDecimalsThe function emits an event to notify off-chain services of the updates:
event PriceFeedUpdated(address token, address _priceFeed);
You can also use removePriceFeeds to delete a token’s assigned DataFeed:
function removePriceFeeds(address[] calldata _tokens) external onlyGuardian {}
Fetching the price of a token in USD:
The getPrice function retrieves a token’s price given a chainlink price feed address: