# MasterPriceOracle

[Git Source](https://github.com/Sperax/USDs-v2/blob/ff71faf9d7e40d2b2764e5e8f2acc631f31489aa/contracts/oracle/MasterPriceOracle.sol)

**Inherits:** Ownable, IOracle

**Author:** Sperax Foundation

Communicates with different price feeds to get the price

## **State Variables**

### **tokenPriceFeed**

Store price feed data for tokens.

```solidity
mapping(address => PriceFeedData) public tokenPriceFeed;

```

## **Functions**

### **updateTokenPriceFeed**

Add/Update price feed for `_token`

*Have to be extra cautious while updating the price feed.*

```solidity
function updateTokenPriceFeed(address _token, address _source, bytes memory _data) external onlyOwner;

```

**Parameters**

| Name     | Type    | Description                            |
| -------- | ------- | -------------------------------------- |
| \_token  | address | address of the desired token.          |
| \_source | address | price feed source.                     |
| \_data   | bytes   | call data for fetching the price feed. |

### **removeTokenPriceFeed**

Remove an existing price feed for `_token`.

```solidity
function removeTokenPriceFeed(address _token) external onlyOwner;

```

**Parameters**

| Name    | Type    | Description           |
| ------- | ------- | --------------------- |
| \_token | address | address of the token. |

### **getPrice**

Gets the price feed for `_token`.

*Function reverts if the price feed does not exists.*

```solidity
function getPrice(address _token) external view returns (PriceData memory);

```

**Parameters**

| Name    | Type    | Description                   |
| ------- | ------- | ----------------------------- |
| \_token | address | address of the desired token. |

**Returns**

| Name | Type      | Description                         |
| ---- | --------- | ----------------------------------- |
|      | PriceData | (uint256 price, uint256 precision). |

### **priceFeedExists**

Validates if price feed exists for a `_token`

*Function reverts if price feed not set.*

```solidity
function priceFeedExists(address _token) external view returns (bool);

```

**Parameters**

| Name    | Type    | Description                   |
| ------- | ------- | ----------------------------- |
| \_token | address | address of the desired token. |

**Returns**

| Name | Type | Description                |
| ---- | ---- | -------------------------- |
|      | bool | bool if price feed exists. |

### **\_getPriceFeed**

Gets the price feed for a `_token` given the feed data.

```solidity
function _getPriceFeed(address _token, address _source, bytes memory _msgData)
    private
    view
    returns (PriceData memory priceData);

```

**Parameters**

| Name      | Type    | Description                   |
| --------- | ------- | ----------------------------- |
| \_token   | address | address of the desired token. |
| \_source  | address | price feed source.            |
| \_msgData | bytes   | call data for fetching feed.  |

**Returns**

| Name      | Type      | Description                         |
| --------- | --------- | ----------------------------------- |
| priceData | PriceData | (uint256 price, uint256 precision). |

## **Events**

### **PriceFeedUpdated**

```solidity
event PriceFeedUpdated(address indexed token, address indexed source, bytes msgData);

```

### **PriceFeedRemoved**

```solidity
event PriceFeedRemoved(address indexed token);

```

## **Errors**

### **InvalidAddress**

```solidity
error InvalidAddress();

```

### **UnableToFetchPriceFeed**

```solidity
error UnableToFetchPriceFeed(address token);

```

### **InvalidPriceFeed**

```solidity
error InvalidPriceFeed(address token);

```

### **PriceFeedNotFound**

```solidity
error PriceFeedNotFound(address token);
```
