# EthPerTokenRateProvider

[Git Source](https://github.com/Ion-Protocol/nucleus-boring-vault/blob/cc0b494b83e17b9b169a73b96050d2810b690477/src/oracles/EthPerTokenRateProvider.sol)

**Inherits:** IRateProvider

Reports the price of a token in terms of ETH. The underlying price feed must be compatible with the Chainlink interface.

## State Variables

### PRICE\_FEED\_TYPE

The type of price feed providers.

```solidity
PriceFeedType public immutable PRICE_FEED_TYPE;
```

### DESCRIPTION

The asset pair the rate provider queries.

```solidity
string public DESCRIPTION;
```

### PRICE\_FEED

The underlying price feed that this rate provider reads from.

```solidity
IPriceFeed public immutable PRICE_FEED;
```

### MAX\_TIME\_FROM\_LAST\_UPDATE

Number of seconds since last update to determine whether the price feed is stale.

```solidity
uint256 public immutable MAX_TIME_FROM_LAST_UPDATE;
```

### RATE\_DECIMALS

The preicision of the rate returned by this contract.

```solidity
uint8 public immutable RATE_DECIMALS;
```

### DECIMALS\_OFFSET

The offset between the intended return decimals and the price feed decimals.

*Based on the `PriceFeedType`, the price feed's asset pair label is retrieved differently.*

```solidity
uint8 public immutable DECIMALS_OFFSET;
```

## Functions

### constructor

```solidity
constructor(
    string memory _description,
    IPriceFeed _priceFeed,
    uint256 _maxTimeFromLastUpdate,
    uint8 _rateDecimals,
    PriceFeedType _priceFeedType
);
```

**Parameters**

| Name                     | Type            | Description                   |
| ------------------------ | --------------- | ----------------------------- |
| `_description`           | `string`        | The asset pair. ex) stETH/ETH |
| `_priceFeed`             | `IPriceFeed`    |                               |
| `_maxTimeFromLastUpdate` | `uint256`       |                               |
| `_rateDecimals`          | `uint8`         |                               |
| `_priceFeedType`         | `PriceFeedType` |                               |

### getRate

Gets the price of token in terms of ETH.

```solidity
function getRate() public view returns (uint256 ethPerToken);
```

**Returns**

| Name          | Type      | Description            |
| ------------- | --------- | ---------------------- |
| `ethPerToken` | `uint256` | price of token in ETH. |

### \_validityCheck

*To revert upon custom checks such as sequencer liveness.*

```solidity
function _validityCheck() internal view virtual;
```

### \_isEqual

```solidity
function _isEqual(string memory a, string memory b) internal pure returns (bool);
```

### \_isEqual

```solidity
function _isEqual(string memory a, bytes32 b) internal pure returns (bool);
```

## Errors

### MaxTimeFromLastUpdatePassed

```solidity
error MaxTimeFromLastUpdatePassed(uint256 blockTimestamp, uint256 lastUpdated);
```

### InvalidPriceFeedDecimals

```solidity
error InvalidPriceFeedDecimals(uint8 rateDecimals, uint8 priceFeedDecimals);
```

### InvalidDescription

```solidity
error InvalidDescription();
```

### InvalidPriceFeedType

```solidity
error InvalidPriceFeedType();
```

## Enums

### PriceFeedType

```solidity
enum PriceFeedType {
    CHAINLINK,
    REDSTONE
}
```


---

# 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.nucleusearn.io/nucleus-architecture/smart-contracts/contracts/oracles/ethpertokenrateprovider.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.
