Chainlink Oracle

This contract is in charge or reading the information from a Chainlink Oracle. TCAP contracts read the price directly from this contract. More information can be found on Chainlink Documentation.

Code

ChainlinkOracle.sol

Contract Addresses

Mainnet

PairAddress
ETH/USD0x2cFeaf282FE9ae050b210e7BDa65D288C40c6104
DAI/USD0x6b5a75f38BeA1Ef59Bc43A5d9602e77Bcbe65e46
Total Market Cap0xa4e581BD159B869e8290707A7FBF841fe7FE97b6

Rinkeby

PairAddress
ETH/USD0xc122B95f6Bcd2ba83fEfDcAD84f57e38Ca9daecf
WBTC/USD0xFC3481aFaD6686f557dbbDA909492C5Ae8dBeb51
DAI/USD0x71263D4DBd31e57E334c7045e46eB781B9Db3386
Total Market Cap0x199e26325b1ebC1F736536f4FaeeddC4bb4D10a2

ERC165 Introspection

setReferenceContract.selector ^
getLatestAnswer.selector ^
getLatestTimestamp.selector ^
getPreviousAnswer.selector ^
getPreviousTimestamp.selector => 0x85be402b

The computed interface ID according to ERC-165. The interface ID is a XOR of all interface method selectors.

Private Variables

AggregatorV3Interface internal aggregatorContract;

The address of the chainlink aggregator contract.

bytes4 private constant _INTERFACE_ID_CHAINLINK_ORACLE = 0x85be402b;

The computed interface ID according to ERC-165. Indicates if this contract supports the chainlink oracle functions.

bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;

The computed interface ID according to ERC-165. Indicates if this contract supports the ERC165 interface.

Read-Only Functions

getLatestAnswer

function getLatestAnswer() public view returns (uint256);

Returns the latest answer from the reference contract.

getLatestTimestamp

function getLatestTimestamp() public view returns (uint256);

Returns the last time the Oracle was updated.

getLatestRound

function getLatestRound()
public
view
returns (
uint80,
int256,
uint256,
uint256,
uint80
);

Returns the all the information from the latest round update on aggregator.

getPreviousAnswer

function getPreviousAnswer(uint256 _id) public view returns (int256);

Returns a previous answer updated on the Oracle with given _id.

getPreviousTimestamp

function getPreviousTimestamp(uint256 _id) public view returns (uint256);

Returns a previous time the Oracle was updated.

getRound

function getRound(uint80 _id)
public
view
returns (
uint80,
int256,
uint256,
uint256,
uint80
);

Returns a given round from the reference contract with the _id.

supportsInterface

function supportsInterface(bytes4 interfaceId)
external
override
view
returns (bool);

ERC165 Standard for support of interfaces.

State-Changing Functions

constructor

constructor(address _aggregator) public;

Called once the contract it's deployed. Set the Chainlink Oracle as an aggregator.

setReferenceContract

function setReferenceContract(address _aggregator) public onlyOwner();

Changes the reference contract used to read the information from Chainlink Oracle. Only owner can call it.