Fei Protocol
Search…
UniswapOracle
An ETH/USDC Uniswap TWAP snapshot oracle

Contract

Description

The UniswapOracle contract maintains a uniswap TWAP.
It maintains a pair contract to reference and a flag for whether the target price is token0 or token1 of the pair. Has a timestamp duration that must be exceeded between oracle updates. The duration is set to 10 minutes at launch.
Updates should:
  • take the difference between the current and prior timestamp and make sure it exceeds the duration
  • get the cumulative price difference between Eth and USDC and normalize by 10**12 (the decimal difference between them)
  • divide the ratio between the cumulative price and timestamp to get a peg price, then divide by 2^112 to resolve an integer from the stored fixed point 112x112 that Uniswap uses.
  • update the peg and prior cumulative and timestamp
The Governor ⚖️can change the duration.

Events

Update
DurationUpdate
new reported peg
type
param
description
uint256
_peg
new peg value
New TWAP duration
type
param
description
uint256
_duration
new value of the TWAP duration

Read-Only Functions

read

1
function read() external view returns (Decimal.D256 memory, bool);
Copied!
Reads the oracle value and reports the peg as FEI per underlying. The boolean value returned informs whether the reported value is valid. Invalid means the oracle is uninitialized or the contract is paused.
This method is pausable. If paused, it won't revert but it will return valid as false

isOutdated

1
function isOutdated() external view returns (bool);
Copied!
Returns true, if the oracle is still within the duration window. If false, then most read functions relying on the oracle would be inaccurate.

priorTimestamp

1
function priorTimestamp() external returns (uint32);
Copied!
Returns the prior timestamp used in the time-weighted average price calculation from the Uniswap pair.

priorCumulative

1
function priorCumulative() external returns (uint256);
Copied!
Returns the prior cumulative price used in the time-weighted average price calculation from the Uniswap pair.

duration

1
function duration() external returns (uint256);
Copied!
Returns the duration of the time-weighted average price.

pair

1
function pair() external returns (IUniswapV2Pair);
Copied!
Returns the referenced Uniswap pair for the oracle.

Public State-Changing Functions

update

1
function update() external returns (bool);
Copied!
Updates the oracle with new time-weighted average price data from Uniswap if the duration window has passed since the last update. Returns true if updated, and false otherwise.
emits Update
This method is pausable

Governor-Only⚖️ State-Changing Functions

setDuration

1
function setDuration(uint256 _duration) external;
Copied!
Changes the time-weighted average price to _duration second snapshots
emits DurationUpdate

ABIs

UniswapOracle.json
3KB
Code
Uniswap Oracle ABI
IUniswapOracle.json
2KB
Code
Uniswap Oracle Interface ABI
IOracle.json
682B
Code
Oracle Interface ABI
Last modified 10mo ago