UniRef

A reference to a Uniswap pair holding FEI

Contract

UniRef.sol implements IUniRef, OracleRef

Description

UniRef is an abstract contract which references a Uniswap pool. It defines basic utilities for contracts referencing Uniswap. It leverages the OracleRef contract to calculate various quantities relating to spot vs peg price. Let R be the reserves of the referenced Uniswap pair, FEI/ETH for example. The UniRef calculates the price at the start and end of a hypothetical trade of size x via the below formulas. It can then calculate the magnitude of the distance from the peg m given an oracle price O:

Formula for start and end price of a trade of size x, and distance from peg m

It has other utilities relating to the peg O:

  • Check whether below peg or not

  • Get amount of a certain asset (fei or other) to trade to bring back to peg. This can be done by setting the end price in the above formula to O and solving for x, replacing the FEI reserves with the target asset reserves and ETH reserves with the other asset reserves. We take the absolute value here and infer the direction based on whether above or below peg.

Formula for amount of assets to trade to the peg on Uniswap

When calculating the magnitude distance from the peg, the protocol only needs to know the deviation when underpegged. Therefore at or above the peg UniRef returns 0 for the deviation.

Events

PairUpdate
PairUpdate

Referenced Uniswap pair contract update

type

param

description

address indexed

_pair

new Uniswap pair contract

Read-Only Functions

router

function router() external view returns (IUniswapV2Router02);

Returns the address of the UniswapV2Router as an interface.

pair

function pair() external view returns (IUniswapV2Pair);

Returns the referenced UniswapV2Pair contract as an interface.

token

function token() external view returns (address);

Returns the address of the ERC-20 token held in the UniswapV2Pair that is not FEI.

getReserves

function getReserves()
external
view
returns (uint256 feiReserves, uint256 tokenReserves);

Returns the reserves of the referenced UniswapV2Pair contract, ordered as FEI, and the other token.

liquidityOwned

function liquidityOwned() external view returns (uint256);

Returns the amount of UniswapV2Pair liquidity provider tokens owned by this contract.

deviationBelowPeg

function deviationBelowPeg(
Decimal.D256 calldata price,
Decimal.D256 calldata peg
) external pure returns (Decimal.D256 memory);

Returns the percent deviation from the peg "m" in the above formulas. Assumes prices are reported as FEI per X e.g. 1720.95 FEI per ETH and pegs are reported as USD per X.

If the price of FEI is above the peg (meaning the input value is below the input peg), then the function returns 0;

Governor-Only⚖️ State-Changing Functions

setPair

function setPair(address _pair) external;

Sets the referenced Uniswap pair contract to _pair

emits PairUpdate

ABIs