VolatilityOracle

Git Source

Author: Aloe Labs, Inc.

"Test everything; hold fast what is good." - 1 Thessalonians 5:21

State Variables

cachedMetadata

mapping(IUniswapV3Pool => Volatility.PoolMetadata) public cachedMetadata;

feeGrowthGlobals

mapping(IUniswapV3Pool => Volatility.FeeGrowthGlobals[FEE_GROWTH_ARRAY_LENGTH]) public feeGrowthGlobals;

lastWrites

mapping(IUniswapV3Pool => LastWrite) public lastWrites;

Functions

prepare

function prepare(IUniswapV3Pool pool) external;

update

function update(IUniswapV3Pool pool, uint40 seed) external returns (uint56, uint160, uint256);

consult

function consult(IUniswapV3Pool pool, uint40 seed) external view returns (uint56, uint160, uint256);

_ema

function _ema(int256 oldIV, int256 estimate) private pure returns (uint104);

_interpolateIV

function _interpolateIV(LastWrite memory lastWrite) private view returns (uint256);

_getPoolMetadata

function _getPoolMetadata(IUniswapV3Pool pool) private view returns (Volatility.PoolMetadata memory metadata);

_getFeeGrowthGlobalsNow

function _getFeeGrowthGlobalsNow(IUniswapV3Pool pool) private view returns (Volatility.FeeGrowthGlobals memory);

_getFeeGrowthGlobalsOld

function _getFeeGrowthGlobalsOld(
    Volatility.FeeGrowthGlobals[FEE_GROWTH_ARRAY_LENGTH] storage arr,
    uint256 index
) private view returns (Volatility.FeeGrowthGlobals memory);

_binarySearch

function _binarySearch(
    Volatility.FeeGrowthGlobals[FEE_GROWTH_ARRAY_LENGTH] storage arr,
    uint256 l,
    uint256 target
) private view returns (Volatility.FeeGrowthGlobals memory);

_isInInterval

function _isInInterval(uint256 min, uint256 x, uint256 max) private pure returns (bool);

Events

Update

event Update(IUniswapV3Pool indexed pool, uint160 sqrtMeanPriceX96, uint104 iv);

Structs

LastWrite

struct LastWrite {
    uint8 index;
    uint40 time;
    uint104 oldIV;
    uint104 newIV;
}