> For the complete documentation index, see [llms.txt](https://docs.nucleusearn.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nucleusearn.io/nucleus-architecture/smart-contracts/contracts/oracles/ethpertokenrateprovider.md).

# 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
}
```
