CL Aggregator Adapter
The CL Aggregator Adapter is a smart contract that acts as a proxy for a Blocksense feed. It provides easy access to the latest round data and historical round data for a given feed. The CL Aggregator Adapter is responsible for a single feed associated with a specific token pair on a given network. It exposes a part of Chainlink’s aggregator interface, hence the name.
For a complete list of functions and parameters for the CLAggregatorAdapter contract, see the CL Aggregator Adapter Reference Documentation.
Code Examples
Solidity
To consume price data from the CL Aggregator Adapter, your smart contract should reference ICLAggregatorAdapter
, which defines the external functions implemented by the CL Aggregator Adapter.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {IChainlinkAggregator} from 'interfaces/chainlink/IChainlinkAggregator.sol';
/**
* THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY.
* THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE.
* DO NOT USE THIS CODE IN PRODUCTION.
*/
contract CLAggregatorAdapterConsumer {
IChainlinkAggregator public immutable feed;
constructor(address feedAddress) {
feed = IChainlinkAggregator(feedAddress);
}
function getDecimals() external view returns (uint8 decimals_) {
return feed.decimals();
}
function getDescription() external view returns (string memory description_) {
return feed.description();
}
function getLatestAnswer() external view returns (uint256 answer) {
return uint256(feed.latestAnswer());
}
function getLatestRound() external view returns (uint256 roundId) {
return feed.latestRound();
}
function getRoundData(
uint80 roundId
)
external
view
returns (
uint80 roundId_,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
)
{
return feed.getRoundData(roundId);
}
function getLatestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
)
{
return feed.latestRoundData();
}
}
Solidity Hardhat Example
Ethers.js v6.x
To get latest price:
const aggregator = new ethers.Contract(contractAddress, abiJson, provider);
const price = await aggregator.latestAnswer();
To get round data:
const aggregator = new ethers.Contract(contractAddress, abiJson, provider);
const [roundID, answer, startedAt, updatedAt, answeredInRound] =
await aggregator.getRoundData(roundId);
To get the feed key the CL Aggregator Adapter is responsible for:
const aggregator = new ethers.Contract(contractAddress, abiJson, provider);
const id = await aggregator.id();