# PythAdapter

## Events

### PythContractAddressSet

```solidity
event PythContractAddressSet(address sender, address pythContractAddress)
```

### PriceFeedRegistered

```solidity
event PriceFeedRegistered(address sender, address asset, bytes32 priceFeedId)
```

### PriceFeedUnregistered

```solidity
event PriceFeedUnregistered(address sender, address asset)
```

### PriceMaxAgeSet

```solidity
event PriceMaxAgeSet(address sender, uint256 newPriceMaxAge)
```

### PriceMinConfidenceRatioSet

```solidity
event PriceMinConfidenceRatioSet(address owner, address asset, uint256 oldPriceMinConfidenceRatio, uint256 newPriceMinConfidenceRatio)
```

### PriceFeedsUpdated

```solidity
event PriceFeedsUpdated(address sender, uint256 updateFee)
```

## Functions

### updatePriceFeeds

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

| Name              | Type     | Description            |
| ----------------- | -------- | ---------------------- |
| \_priceUpdateData | bytes\[] | Pyth price update data |

#### **Return Values**

| Name      | Type | Description             |
| --------- | ---- | ----------------------- |
| success\_ | bool | Confirmation of success |

### getAssetPrice

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

| Name    | Type    | Description          |
| ------- | ------- | -------------------- |
| \_asset | address | ERC-20 token address |

#### **Return Values**

| Name         | Type    | Description                               |
| ------------ | ------- | ----------------------------------------- |
| assetPrice\_ | uint256 | Asset price in USD with 18 decimal places |

### getPythContractAddress

```solidity
function getPythContractAddress() external view returns (address pythContractAddress_)
```

Returns the Pyth contract address

#### **Return Values**

| Name                  | Type    | Description           |
| --------------------- | ------- | --------------------- |
| pythContractAddress\_ | address | Pyth contract address |

### isPriceFeedRegistered

```solidity
function isPriceFeedRegistered(address _asset) public view returns (bool isRegistered_)
```

Check if Pyth price feed is registered

#### **Parameters**

| Name    | Type    | Description          |
| ------- | ------- | -------------------- |
| \_asset | address | ERC-20 token address |

#### **Return Values**

| Name           | Type | Description                  |
| -------------- | ---- | ---------------------------- |
| isRegistered\_ | bool | Confirmation of registration |

### getPriceFeedIdByAsset

```solidity
function getPriceFeedIdByAsset(address _asset) public view returns (bytes32 priceFeedId_)
```

Returns the Pyth price feed id for an asset

#### **Parameters**

| Name    | Type    | Description          |
| ------- | ------- | -------------------- |
| \_asset | address | ERC-20 token address |

#### **Return Values**

| Name          | Type    | Description        |
| ------------- | ------- | ------------------ |
| priceFeedId\_ | bytes32 | Pyth price feed id |

### getUpdateFee

```solidity
function getUpdateFee(bytes[] _updateData) public view returns (uint256 updateFee_)
```

Returns the required fee to update an array of price updates

#### **Parameters**

| Name         | Type     | Description                |
| ------------ | -------- | -------------------------- |
| \_updateData | bytes\[] | Array of price update data |

#### **Return Values**

| Name        | Type    | Description       |
| ----------- | ------- | ----------------- |
| updateFee\_ | uint256 | Update fee in Wei |

### getValidTimePeriod

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

| Name              | Type    | Description                  |
| ----------------- | ------- | ---------------------------- |
| validTimePeriod\_ | uint256 | Valid time period in seconds |

### getPriceMaxAge

```solidity
function getPriceMaxAge() external view returns (uint256)
```

Returns the maximum age of a price feed in seconds

#### **Return Values**

| Name | Type    | Description                                        |
| ---- | ------- | -------------------------------------------------- |
| \[0] | uint256 | priceMaxAge Maximum age of a price feed in seconds |

### getPriceMinConfidenceRatio

```solidity
function getPriceMinConfidenceRatio(address _asset) external view returns (uint256 priceMinConfidenceRatio_)
```

Returns the minimum confidence ratio for an asset

#### **Parameters**

| Name    | Type    | Description          |
| ------- | ------- | -------------------- |
| \_asset | address | ERC-20 token address |

#### **Return Values**

| Name                      | Type    | Description                            |
| ------------------------- | ------- | -------------------------------------- |
| priceMinConfidenceRatio\_ | uint256 | Minimum confidence ratio for the asset |


---

# 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.nabla.fi/developers/contract-interfaces/pythadapter.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.
