ChainlinkPriceProvider
Overview
License: MIT
The ChainlinkPriceProvider contract is the contract that provides the functionality for getting the price of a token using Chainlink.
Structs info
ChainlinkMetadata
Events info
SetTokenAndAggregator
Emitted when a token and its corresponding Chainlink aggregator path are set.
Parameters:
Name | Type | Description |
---|---|---|
token | address | The address of the token. |
aggregatorPath | address[] | The array of Chainlink aggregator addresses used to get the price of the token. |
ChangeActive
Emitted when the active status of a token is changed.
Parameters:
Name | Type | Description |
---|---|---|
token | address | The address of the token whose active status is changed. |
active | bool | The new active status of the token. |
SetTimeOut
Emitted when the time out for a Chainlink aggregator path is set.
Parameters:
Name | Type | Description |
---|---|---|
aggregatorPath | address | The address of the Chainlink aggregator path. |
newTimeOut | uint256 | The new time out value in seconds. |
SetTokenDecimals
Emitted when the token decimals is set.
Parameters:
Name | Type | Description |
---|---|---|
newTokenDecimals | uint8 | The new token decimals. |
Constants info
MODERATOR_ROLE (0x797669c9)
DESCRIPTION (0xf1ae8856)
MAX_PRICE_PATH_LENGTH (0x01a9a5d3)
State variables info
tokenDecimals (0x3b97e856)
timeOuts (0x2a6377a9)
chainlinkMetadata (0x8cc19163)
Modifiers info
onlyModerator
Modifier to restrict access to functions to only the contract's moderator.
Functions info
initialize (0x8129fc1c)
Initializes the contract by setting up the access control roles and assigning them to the contract deployer. The DEFAULT_ADMIN_ROLE
and MODERATOR_ROLE
roles are set up with the contract deployer as the initial role bearer. decimals
is set to 8.
setTokenDecimals (0xf2cf47be)
Sets the number of decimals used by the token. Only the moderator can call this function.
Parameters:
Name | Type | Description |
---|---|---|
newTokenDecimals | uint8 | The new number of decimals used by the token. |
setTimeOut (0x60c74154)
Sets the timeout value corresponding to the aggregatorPath.
Example: ETH/USD have a new answer is written when the off-chain data moves more than the 0.5% deviation threshold or 3600 seconds have passed since the last answer was written on-chain. So, the timeOut value for each aggregator will be equal to the heartbeat threshold value plus a period of time to make the transaction update the price, that time period can be 60s or a little more.
Parameters:
Name | Type | Description |
---|---|---|
aggregatorPath | address | The address of chainlink aggregator contract. |
newTimeOut | uint256 | It is the amount of time it takes for a new round of aggregation to start after a specified |
amount of time since the last update plus a period of time waiting for new price update transactions to execute. |
setTokenAndAggregator (0xedc607b0)
Set token and aggregator path.
Parameters:
Name | Type | Description |
---|---|---|
token | address | The address of the token. |
aggregatorPath | address[] | The address of the aggregator path. |
changeActive (0x258a4532)
Change active status of token.
Parameters:
Name | Type | Description |
---|---|---|
token | address | The address of the token. |
active | bool | The active status of token. |
isListed (0xf794062e)
Returns the is listed status of token.
Parameters:
Name | Type | Description |
---|---|---|
token | address | the address of token. |
Return values:
Name | Type | Description |
---|---|---|
[0] | bool | isListed the is listed status of token. |
isActive (0x9f8a13d7)
Returns the is active status of token.
Parameters:
Name | Type | Description |
---|---|---|
token | address | the address of token. |
Return values:
Name | Type | Description |
---|---|---|
[0] | bool | isActive the is active status of token. |
getLatestPrice (0x16345f18)
ReturnS the latest price after performing sanity check and staleness check.
Parameters:
Name | Type | Description |
---|---|---|
aggregatorPath | address | The address of chainlink aggregator contract. |
Return values:
Name | Type | Description |
---|---|---|
[0] | uint256 | The latest price (answer). |
getPrice (0x41976e09)
Returns the latest asset price mantissa and price decimals.
[price] = USD/token
First step is get priceMantissa with priceDecimals by this formula: price = 1 * 10 ** tokenDecimals * (chainlinkPrice_1 / 10 ** priceDecimals_1) * ... * (chainlinkPrice_n / 10 ** priceDecimals_n) = = 10 ** tokenDecimals (chainlinkPrice_1 * ... * chainlinkPrice_n) / 10 ** (priceDecimals_1 + ... + priceDecimals_n)
Second step is scale priceMantissa to usdDecimals.
Parameters:
Name | Type | Description |
---|---|---|
token | address | the token address. |
getPriceDecimals (0x1b30aafc)
Returns the number of decimals used for the price provided by the Chainlink oracle.
Return values:
Name | Type | Description |
---|---|---|
[0] | uint8 | The number of decimals used for the price. |
getChainlinkMetadata (0xd718fc11)
Returns the metadata set up for token.
Parameters:
Name | Type | Description |
---|---|---|
token | address | The address of the token. |
Return values:
Name | Type | Description |
---|---|---|
[0] | struct ChainlinkPriceProvider.ChainlinkMetadata | metadata The metadata includes active status of token and array of Chainlink aggregator addresses used to get the price of the token. |
Last updated