EthPerTokenRateProvider

Git Source

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.

PriceFeedType public immutable PRICE_FEED_TYPE;

DESCRIPTION

The asset pair the rate provider queries.

string public DESCRIPTION;

PRICE_FEED

The underlying price feed that this rate provider reads from.

IPriceFeed public immutable PRICE_FEED;

MAX_TIME_FROM_LAST_UPDATE

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

uint256 public immutable MAX_TIME_FROM_LAST_UPDATE;

RATE_DECIMALS

The preicision of the rate returned by this contract.

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.

uint8 public immutable DECIMALS_OFFSET;

Functions

constructor

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

Parameters

NameTypeDescription

_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.

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

Returns

NameTypeDescription

ethPerToken

uint256

price of token in ETH.

_validityCheck

To revert upon custom checks such as sequencer liveness.

function _validityCheck() internal view virtual;

_isEqual

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

_isEqual

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

Errors

MaxTimeFromLastUpdatePassed

error MaxTimeFromLastUpdatePassed(uint256 blockTimestamp, uint256 lastUpdated);

InvalidPriceFeedDecimals

error InvalidPriceFeedDecimals(uint8 rateDecimals, uint8 priceFeedDecimals);

InvalidDescription

error InvalidDescription();

InvalidPriceFeedType

error InvalidPriceFeedType();

Enums

PriceFeedType

enum PriceFeedType {
    CHAINLINK,
    REDSTONE
}