# TermPriceConsumerV3.sol

## TermPriceConsumerV3

This contract is a centralized price oracle contract that feeds pricing data to all Term Repos

*This contract operates at the protocol level and governs all instances of a Term Repo*

### DEVOPS\_ROLE

```solidity
bytes32 DEVOPS_ROLE
```

### priceFeeds

```solidity
mapping(address => struct TermPriceFeedConfig) priceFeeds
```

### fallbackPriceFeeds

```solidity
mapping(address => struct TermPriceFeedConfig) fallbackPriceFeeds
```

### constructor

```solidity
constructor() public
```

### initialize

```solidity
function initialize(address devopsWallet_) external
```

Intializes with an array of token addresses, followed with an array of Chainlink aggregator addresses <https://docs.chain.link/docs/ethereum-addresses/>

### addNewTokenPriceFeedAndFallbackPriceFeed

```solidity
function addNewTokenPriceFeedAndFallbackPriceFeed(address token, address tokenPriceAggregator, uint256 tokenPriceAggregatorRefreshRateThreshold, address fallbackPriceAggregator, uint256 fallbackPriceAggregatorRefreshRateThreshold) external
```

#### Parameters

| Name                                        | Type    | Description                                                                             |
| ------------------------------------------- | ------- | --------------------------------------------------------------------------------------- |
| token                                       | address | The address of the token to add a price feed for                                        |
| tokenPriceAggregator                        | address | The price aggregator address for token to be added                                      |
| tokenPriceAggregatorRefreshRateThreshold    | uint256 | Refresh threshold in seconds for primary price feed updates beyond which price is stale |
| fallbackPriceAggregator                     | address | The fallback price aggregator address for token to be added                             |
| fallbackPriceAggregatorRefreshRateThreshold | uint256 | Refresh threshold for fallback price feed updates beyond which price is stale           |

### addNewTokenPriceFeed

```solidity
function addNewTokenPriceFeed(address token, address tokenPriceAggregator, uint256 refreshRateThreshold) external
```

#### Parameters

| Name                 | Type    | Description                                                                             |
| -------------------- | ------- | --------------------------------------------------------------------------------------- |
| token                | address | The address of the token to add a price feed for                                        |
| tokenPriceAggregator | address | The proxy price aggregator address for token to be added                                |
| refreshRateThreshold | uint256 | Refresh threshold in seconds for primary price feed updates beyond which price is stale |

### addNewTokenFallbackPriceFeed

```solidity
function addNewTokenFallbackPriceFeed(address token, address tokenPriceAggregator, uint256 refreshRateThreshold) external
```

#### Parameters

| Name                 | Type    | Description                                                                              |
| -------------------- | ------- | ---------------------------------------------------------------------------------------- |
| token                | address | The address of the token to add a price feed for                                         |
| tokenPriceAggregator | address | The proxy price aggregator address for token to be added                                 |
| refreshRateThreshold | uint256 | Refresh threshold in seconds for fallback price feed updates beyond which price is stale |

### removeTokenPriceFeed

```solidity
function removeTokenPriceFeed(address token) external
```

#### Parameters

| Name  | Type    | Description                                                   |
| ----- | ------- | ------------------------------------------------------------- |
| token | address | The address of the token whose price feed needs to be removed |

### removeFallbackTokenPriceFeed

```solidity
function removeFallbackTokenPriceFeed(address token) external
```

#### Parameters

| Name  | Type    | Description                                                   |
| ----- | ------- | ------------------------------------------------------------- |
| token | address | The address of the token whose price feed needs to be removed |

### usdValueOfTokens

```solidity
function usdValueOfTokens(address token, uint256 amount) external view returns (struct ExponentialNoError.Exp)
```

A function to return current market value given a token address and an amount

#### Parameters

| Name   | Type    | Description                       |
| ------ | ------- | --------------------------------- |
| token  | address | The address of the token to query |
| amount | uint256 | The amount tokens to value        |

#### Return Values

| Name | Type                          | Description                                                        |
| ---- | ----------------------------- | ------------------------------------------------------------------ |
| \[0] | struct ExponentialNoError.Exp | The current market value of tokens at the specified amount, in USD |

### \_addNewTokenPriceFeed

```solidity
function _addNewTokenPriceFeed(address token, address tokenPriceAggregator, uint256 refreshRateThreshold) internal
```

#### Parameters

| Name                 | Type    | Description                                                                             |
| -------------------- | ------- | --------------------------------------------------------------------------------------- |
| token                | address | The address of the token to add a price feed for                                        |
| tokenPriceAggregator | address | The proxy price aggregator address for token to be added                                |
| refreshRateThreshold | uint256 | Refresh threshold in seconds for primary price feed updates beyond which price is stale |

### \_addNewTokenFallbackPriceFeed

```solidity
function _addNewTokenFallbackPriceFeed(address token, address tokenPriceAggregator, uint256 refreshRateThreshold) internal
```

#### Parameters

| Name                 | Type    | Description                                                                              |
| -------------------- | ------- | ---------------------------------------------------------------------------------------- |
| token                | address | The address of the token to add a price feed for                                         |
| tokenPriceAggregator | address | The proxy price aggregator address for token to be added                                 |
| refreshRateThreshold | uint256 | Refresh threshold in seconds for fallback price feed updates beyond which price is stale |

### \_getLatestPrice

```solidity
function _getLatestPrice(address token) internal view returns (int256, uint8)
```

#### Return Values

| Name | Type   | Description                                                          |
| ---- | ------ | -------------------------------------------------------------------- |
| \[0] | int256 | The latest price from price aggregator and the decimals in the price |
| \[1] | uint8  |                                                                      |

### \_authorizeUpgrade

```solidity
function _authorizeUpgrade(address) internal view
```

*required override by the OpenZeppelin UUPS module*
