PythAdapter
Price oracle adapter that uses Pyth price feeds (https://pyth.network)
Events
PythContractAddressSet
event PythContractAddressSet(address sender, address pythContractAddress)
PriceFeedRegistered
event PriceFeedRegistered(address sender, address asset, bytes32 priceFeedId)
PriceFeedUnregistered
event PriceFeedUnregistered(address sender, address asset)
PriceMaxAgeSet
event PriceMaxAgeSet(address sender, uint256 newPriceMaxAge)
PriceMinConfidenceRatioSet
event PriceMinConfidenceRatioSet(address owner, address asset, uint256 oldPriceMinConfidenceRatio, uint256 newPriceMinConfidenceRatio)
PriceFeedsUpdated
event PriceFeedsUpdated(address sender, uint256 updateFee)
Functions
updatePriceFeeds
function updatePriceFeeds(bytes[] _priceUpdateData) external payable returns (bool success_)
Updates one or more Pyth price feeds
This function needs to be called right before calling getAssetPrice()
Parameters
_priceUpdateData
bytes[]
Pyth price update data
Return Values
success_
bool
Confirmation of success
getAssetPrice
function getAssetPrice(address _asset) external view returns (uint256 assetPrice_)
Returns the asset price
This function reverts with a StalePrice error if the on-chain price has not been updated within the last getValidTimePeriod() seconds via updatePriceFeeds()
Parameters
_asset
address
ERC-20 token address
Return Values
assetPrice_
uint256
Asset price in USD with 18 decimal places
getPythContractAddress
function getPythContractAddress() external view returns (address pythContractAddress_)
Returns the Pyth contract address
Return Values
pythContractAddress_
address
Pyth contract address
isPriceFeedRegistered
function isPriceFeedRegistered(address _asset) public view returns (bool isRegistered_)
Check if Pyth price feed is registered
Parameters
_asset
address
ERC-20 token address
Return Values
isRegistered_
bool
Confirmation of registration
getPriceFeedIdByAsset
function getPriceFeedIdByAsset(address _asset) public view returns (bytes32 priceFeedId_)
Returns the Pyth price feed id for an asset
Parameters
_asset
address
ERC-20 token address
Return Values
priceFeedId_
bytes32
Pyth price feed id
getUpdateFee
function getUpdateFee(bytes[] _updateData) public view returns (uint256 updateFee_)
Returns the required fee to update an array of price updates
Parameters
_updateData
bytes[]
Array of price update data
Return Values
updateFee_
uint256
Update fee in Wei
getValidTimePeriod
function getValidTimePeriod() external view returns (uint256 validTimePeriod_)
Returns the period (in seconds) that a price feed is considered valid since its publish time
Return Values
validTimePeriod_
uint256
Valid time period in seconds
getPriceMaxAge
function getPriceMaxAge() external view returns (uint256)
Returns the maximum age of a price feed in seconds
Return Values
[0]
uint256
priceMaxAge Maximum age of a price feed in seconds
getPriceMinConfidenceRatio
function getPriceMinConfidenceRatio(address _asset) external view returns (uint256 priceMinConfidenceRatio_)
Returns the minimum confidence ratio for an asset
Parameters
_asset
address
ERC-20 token address
Return Values
priceMinConfidenceRatio_
uint256
Minimum confidence ratio for the asset
Last updated