# API3 - Chainlink adapter ## Chainlink Aggregators The current implementation of AAVE gets the price from Chainlink Aggregators. This is the interface of this contract as seen here: https://github.com/aave/protocol-v2/blob/master/contracts/interfaces/IChainlinkAggregator.sol ``` // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; interface IChainlinkAggregator { function decimals() external view returns (uint8); function latestAnswer() external view returns (int256); function latestTimestamp() external view returns (uint256); function latestRound() external view returns (uint256); function getAnswer(uint256 roundId) external view returns (int256); function getTimestamp(uint256 roundId) external view returns (uint256); event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 timestamp); event NewRound(uint256 indexed roundId, address indexed startedBy); } ``` ## Chainlink Adapter Contract Deploy the following adapter contract with the approriate proxy address as seen on the [API3 market](https://market.api3.org/dapis) (For example the proxy address for ETH/USD is `0x26690F9f17FdC26D419371315bc17950a0FC90eD` on polygon mumbai): ``` // SPDX-License-Identifier: MIT pragma solidity 0.8.17; import "@api3/contracts/v0.8/interfaces/IProxy.sol"; contract Api3AggregatorAdaptor { // Updating the proxy address is a security-critical action which is why // we have made it immutable. address public immutable proxy; constructor(address _proxy) { proxy = _proxy; } function latestAnswer() external view returns (int256 value) { (value, ) = readDataFeed(); } function latestTimestamp() external view returns (uint256 timestamp) { ( , timestamp) = readDataFeed(); } function decimals() external view returns (uint8) { return 18; } function readDataFeed() internal view returns (int224 value, uint256 timestamp) { (value, timestamp) = IProxy(proxy).read(); // If you have any assumptions about `value` and `timestamp`, make sure // to validate them right after reading from the proxy. For example, // if the value you are reading is the spot price of an asset, you may // want to reject non-positive values... // require(value > 0, "Value not positive"); // ...and if the data feed is being updated with a one day-heartbeat // interval, you may want to check for that. // require( // timestamp + 1 days > block.timestamp, // "Timestamp older than one day" // ); // Try to be strict about validations, but be wary of: // (1) Overly strict validation that may invalidate valid values // (2) Mutable validation parameters that are controlled by a trusted // party (eliminates the trust-minimization guarantees of first-party // oracles) // (3) Validation parameters that need to be tuned according to // external conditions (if these are forgotten to be handled, it will // result in (1), look up the Venus Protocol exploit related to LUNA) // After validation, you can implement your contract logic here. } function getTokenType() external pure returns (uint256) { return 1; } } ``` Once the adapter is deployed it can be be called via the ChainlinkInterface to retrieve the oracle values. Please checkout the [API3 documentation](https://docs.api3.org/) on more information about dAPIs and the API3 market.