PythPriceProvider
Overview
License: MIT
The PythPriceProvider contract is the contract that provides the functionality of getting the latest price from PythNetwork.
Contract that provides the functionality of getting the latest price from PythNetwork. Inherit from PriceProvider.
Structs info
PythMetadata
Events info
SetTokenAndPriceIdPath
Emitted when the token and its corresponding price ID path are set.
Parameters:
SetPythOracle
Emitted when a new Pyth oracle address is set.
Parameters:
ChangeActive
Emitted when the active status of a token changes.
Parameters:
SetTokenDecimals
Emitted when the token decimals is set.
Parameters:
Constants info
MODERATOR_ROLE (0x797669c9)
DESCRIPTION (0xf1ae8856)
MAX_LENGTH_PRICE_ID_PATH (0x4e253e91)
State variables info
tokenDecimals (0x3b97e856)
pythOracle (0xf5d6ac90)
validTimePeriod (0xcbdaeaba)
pythMetadata (0xbe3fd070)
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 default values for tokenDecimals and validTimePeriod.
setTokenDecimals (0xf2cf47be)
Sets the number of decimals used by the token. Only the moderator can call this function.
Parameters:
setTokenAndPriceIdPath (0x970d6b21)
Sets token and priceIdPath.
Parameters:
setPythOracle (0x622bd118)
Sets PythOracle contract.
Requirements:
Only the moderator can call this function.
The address of PythOracle contract must not be zero.
Parameters:
setValidTimePeriod (0x9bd92cad)
Sets ValidTimePeriod is used to check if price is older than ValidTimePeriod to perform price update. Only the moderator can call this function.
Parameters:
changeActive (0x258a4532)
Changes the active status of a token in the Pyth price provider.
Requirements:
The token must be listed in the Pyth price provider.
Only the moderator can call this function.
Parameters:
updatePrices (0x0aa9adbc)
Perform a price update if the price is no longer valid.
Parameters:
isListed (0xf794062e)
Returns a boolean indicating whether the given token is listed in the Pyth price provider.
Parameters:
Return values:
isActive (0x9f8a13d7)
Returns a boolean indicating whether the specified token is active or not.
Parameters:
Return values:
getPrice (0x41976e09)
Returns the latest price of a given token in USD.
Requirements:
This function retrieves the price of a token from the Pyth oracle and calculates the price in USD.
If the retrieved price is too old, the function reverts.
If the number of decimal places in the retrieved price is greater than the number of decimal places in the token, the function adjusts the price accordingly.
This function is view-only and does not modify the state of the contract.
Parameters:
Return values:
getPriceDecimals (0x1b30aafc)
Returns the number of decimals used by the token.
Return values:
getExpiredPriceFeeds (0xe1f67b13)
Returns the priceId array to update the price before expiration and the update fee.
Parameters:
Return values:
getPythMetadata (0xed043fa8)
Returns the metadata set up for token.
Parameters:
Return values:
Last updated