Price Manager

This contract implements functionality related to managing asset prices, conversions between tokens and USD, and retrieving asset-related information.

Initialize

This function initializes the PriceManager contract with the addresses of the operators and pyth contracts.

initialize(address _operators, address _pyth) public

Set Asset

This function sets the details of an asset, such as its symbol, Pyth ID, price, allowed staleness, allowed deviation, and maximum leverage.

setAsset(
uint256 _assetId, 
string calldata _symbol, 
bytes32 _pythId, 
uint256 _price, 
uint256 _allowedStaleness, 
uint256 _allowedDeviation, 
uint256 _maxLeverage
)

Set Usd Asset

This function sets the details of a USD stablecoin asset, including its token address, symbol, Pyth ID, price, allowed staleness, allowed deviation, and token decimals.

setUsdAsset(
address _tokenAddress, 
uint256 _assetId, 
string calldata _symbol, 
bytes32 _pythId, 
uint256 _price, 
uint256 _allowedStaleness, 
uint256 _allowedDeviation, 
uint256 _tokenDecimals
)

Get Pyth Last Price

This function retrieves the last price of an asset from the Pyth network. It takes the asset ID and a flag indicating whether freshness is required. It returns the last price as a uint256 value.

getPythLastPrice(
uint256 _assetId, 
bool _requireFreshness
) public view returns (uint256)

Get Last Price

This function returns the last price of an asset. If the price is still fresh (within the allowed staleness), it returns the stored price. Otherwise, it queries the Pyth network for the last price.

getLastPrice(uint256 _assetId) public view override returns (uint256)

Set Price

This function sets the price of an asset. If the asset has a Pyth ID, it checks the deviation between the proposed price and the price from the Pyth network.

setPrice(uint256 _assetId, uint256 _price, uint256 _ts) public

Token To Usd

This function converts the specified amount of tokens to an equivalent USD value. It takes the token address and the token amount and returns the USD value as a uint256 value.

tokenToUsd(
address _token, 
uint256 _tokenAmount
) external view override returns (uint256)

Usd To Token

This function converts the specified USD amount to an equivalent amount of tokens. It takes the token address and the USD amount and returns the token amount as a uint256 value.

usdToToken(
address _token, 
uint256 _usdAmount
) external view override returns (uint256)

Get Current Time

This function returns the current timestamp as a uint256 value.

getCurrentTime() external view returns (uint256)

Max Leverage

This function returns the maximum leverage allowed for the specified asset ID.

maxLeverage(uint256 _assetId) external view override returns (uint256)

Get Valid Asset Ids

This function returns an array of valid asset IDs.

getValidAssetIds() external view returns (uint256[] memory)

Last updated