UniV3Relayer

Git Source

Inherits: IBaseOracle, IUniV3Relayer

This contracts consults a UniswapV3Pool TWAP and transforms the result into a standard IBaseOracle feed

The quote obtained from the pool query is transformed into an 18 decimals format

State Variables

_UNI_V3_FACTORY

Address of the UniswapV3Factory used to fetch the pool address

address internal constant _UNI_V3_FACTORY = address(0x1F98431c8aD98523631AE4a59f267346ea31F984);

uniV3Pool

Address of the UniswapV3Pool used to consult the TWAP

address public uniV3Pool;

baseToken

Address of the base token used to consult the quote from

address public baseToken;

quoteToken

Address of the token used as a quote reference

address public quoteToken;

symbol

Symbol of the quote: token / baseToken (e.g. 'ETH / USD')

string public symbol;

baseAmount

The amount in wei of the base token used to consult the pool for a quote

uint128 public baseAmount;

multiplier

The multiplier used to convert the quote into an 18 decimals format

uint256 public multiplier;

quotePeriod

The length of the TWAP used to consult the pool

uint32 public quotePeriod;

Functions

constructor

constructor(address _baseToken, address _quoteToken, uint24 _feeTier, uint32 _quotePeriod);

Parameters

NameTypeDescription
_baseTokenaddressAddress of the base token used to consult the quote
_quoteTokenaddressAddress of the token used as a quote reference
_feeTieruint24Fee tier of the pool used to consult the quote
_quotePerioduint32Length in seconds of the TWAP used to consult the pool

getResultWithValidity

Fetch the latest oracle result and whether it is valid or not

Method will return invalid if the pool doesn't have enough history

function getResultWithValidity() external view returns (uint256 _result, bool _validity);

read

Fetch the latest oracle result

This method may revert with 'OLD!' if the pool doesn't have enough cardinality or initialized history

function read() external view returns (uint256 _result);

_parseResult

Parses the result from the aggregator into 18 decimals format

function _parseResult(uint256 _quoteResult) internal view returns (uint256 _result);