# Price Manager

**Initialize**

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

```solidity
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.

```solidity
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.

```solidity
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.

```solidity
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.

```solidity
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.

```solidity
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.

```solidity
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.

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

**Get Current Time**

This function returns the current timestamp as a uint256 value.

```solidity
getCurrentTime() external view returns (uint256)
```

**Max Leverage**

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

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

**Get Valid Asset Ids**

This function returns an array of valid asset IDs.

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.vela.exchange/vela-knowledge-base/developers/contract-functions/price-manager.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
