Oracles
ThunderCore oracle provides a series of asset prices on the chain to make your smart contract connect with real world.
For projects already integrated with Chainlink data feed , we are providing the same function interfaces to make your project cross-chain onto ThunderCore instantly.
Pending for Review
This is pre-release version section. Contents can be changed anytime, please use in your caution.
Get Started
You can get the latest contract interfaces and ABIs through npm:
$ npm install @thundercore/oracleor Yarn:
$ yarn add @thundercore/oracleAnd just a few lines of code, so you can get the latest price:
import { FeedRegistryConsumerInterface } from '@thundercore/oracle/TTOracle.sol';
contract MyProject {
address public constant TT_ORACLE = 0xD477d4d8132C6fce38f0bf38f46FcB62D6c5ddaE;
function getThunderTokenPrice() public view returns (int256) {
(
/* uint80 roundId */,
int256 answer,
/* uint256 startedAt */,
/* uint256 updatedAt */,
/* uint80 answeredInRound */
) = FeedRegistryConsumerInterface(TT_ORACLE)
.latestRoundData('TT/USDT');
return answer;
}
}import { FeedRegistryInterface } from "@chainlink/contracts/src/v0.8/interfaces/FeedRegistryInterface.sol";
import { Denominations } from '@thundercore/oracle/TTOracle.sol';
contract MyProject {
address public constant TT_ORACLE = 0xD477d4d8132C6fce38f0bf38f46FcB62D6c5ddaE;
function getThunderTokenPrice() public view returns (int256) {
(
/* uint80 roundId */,
int256 answer,
/* uint256 startedAt */,
/* uint256 updatedAt */,
/* uint80 answeredInRound */
) = FeedRegistryInterface(TT_ORACLE)
.latestRoundData(
Denominations.TT,
Denominations.USDT
);
return answer;
}
}You can try it on ThunderCore testnet:
Using Data Feeds
Data Feeds are the quickest way to connect with the real-world asset prices.
Solidity
To consume price data, your smart contract should reference DataFeedConsumerInterface, which defines the external functions implemented by Data Feeds.
The latestRoundData function returns five values representing information about the latest price data. See the Data Feeds API Reference for more details.
ECMAScript (JavaScript)
Python
This example uses Web3.py to retrieve feed data from the TT/USDT feed on the ThunderCore testnet network.
Getting a different price denomination
If you require a denomination other than what we have provided, you can use two data feeds to derive the pair that you need. For example, if you need a TT/ETH price, you could take the TT/USDT feed and the ETH/USDT feed and derive TT/ETH using division.
Historical Price Data
The most common use case for data feeds is to get the latest price. However, we also exposes functions which can be used to retrieve price data of a previous round ID.
Never over rely on previous round data of oracle
If your project requires price before one week or longer ago, always store those prices inside your smart contract.
In ThunderCore oracle, we guarantee to keeps one recent week prices. And after one week, those data could be purged anytime.
Solidity
ECMAScript (JavaScript)
Python
Feed Registry
The Feed Registry is an on-chain mapping of assets to feeds. It enables you to query data feeds from asset addresses directly, without needing to know the feed contract addresses.
Base and Quote
You are free to choose querying feeds from their pair names, e.g. TT/USDT; or you can keep Chainlink style by token addresses.
Solidity example code
ECMAScript (JavaScript) example
API Reference
API reference for DataFeedConsumerInterface.
Decimals of "answer" in responsed round data
Feed pair name, format "${BASE}/${QUOTE}"
The code version of the feed proxy points to
Check if the round data existed
Get data from a specific round
Get data from the latest round
Get previous data existed round ID
Get next data existed round ID
decimals
Get the decimals of "answer" in responsed round data
RETURN: The number of decimals.
description
Get the feed pair name, format "${BASE}/${QUOTE}"
RETURN: The pair name of data feed.
version
Get the code version of the feed proxy points to
RETURN: The code version.
hasRoundData
Check if the round data existed
Petermeters
roundId: The round ID to check if round data existed in data feed.
Return Values
RETURN: Round data exists or not.
getRoundData
Get data from a specific round
Petermeters
roundId: The round ID
Return Values
roundId: The round ID.answer: The price.startedAt: Timestamp of when the round started.updatedAt: Timestamp of when the round was last updated.answeredInRound: The round ID of the round in which the answer was computed.
latestRoundData
Get data from the latest round
Return Values
roundId: The round ID.answer: The price.startedAt: Timestamp of when the round started.updatedAt: Timestamp of when the round was last updated.answeredInRound: The round ID of the round in which the answer was computed.
getPreviousRoundId
Get previous data existed round ID
Petermeters
roundId: The round ID to look up closest previous valid round ID.
Return Values
RETURN: The previous valid round ID to parameter specified round ID; return 0 if no valid round ID before.
getNextRoundId
Get next data existed round ID
Petermeters
roundId: The round ID to look up closest next valid round ID.
Return Values
RETURN: The next valid round ID to parameter specified round ID; return 0 if no valid round ID after.
Contract Addresses
FeedRegistry: 0x70B3B30066b4F7B927f26C408461b3F176AA07Dc
TT/USDT
18
0x0808Ac0b6f4B502C59e40D147dDA7Bfa1AE7BD6C
ETH/USDT
18
0x1Cc8dE741C6d32c321B46a23D8289F337aBEf4D9
WBTC/USDT
18
0x632Ce66C7C973eE2662F207cBbA04A6E2d9B91bb
BNB/USDT
18
0xFB19d0dC0194A99913Daaa3d11f8d00ff4affa81
HT/USDT
18
0x53BD5eB3fF53F19F1eD7871D48B200f3312E8017
FeedRegistry: 0xD477d4d8132C6fce38f0bf38f46FcB62D6c5ddaE
TT/USDT
18
0x1Ce18a95C56Db619C070AeF58918EaB09FE2634c
ETH/USDT
18
0x555Ad57b0EA33e2ac49D267C96eF98aa254a54c4
WBTC/USDT
18
0x83Ac10Bc6dC02E07c71dfBF45ca7355675D340B5
BNB/USDT
18
0xcE6bd682263F58e1e2828ccA5AEc6A671FFfd739
HT/USDT
18
0xB6FEB586A86b4C542295E1232B45DE5F80961a16
Last updated