Volatility

Git Source

Author: Aloe Labs, Inc.

Provides functions that use Uniswap v3 to compute price volatility

State Variables

_Q224Div1e18

uint256 private constant _Q224Div1e18 = (uint256(1 << 224) * 1e6) / 1e24;

_Q128Div1e18

uint256 private constant _Q128Div1e18 = (uint256(1 << 128) * 1e6) / 1e24;

Functions

estimate

Estimates implied volatility using this math.

The return value can fit in uint128 if necessary

function estimate(
    PoolMetadata memory metadata,
    uint160 sqrtMeanPriceX96,
    FeeGrowthGlobals memory a,
    FeeGrowthGlobals memory b,
    uint32 scale
) internal pure returns (uint256);

Parameters

NameTypeDescription
metadataPoolMetadataThe pool's metadata (may be cached)
sqrtMeanPriceX96uint160sqrt(TWAP) over some period. Likely from Oracle.consult
aFeeGrowthGlobalsThe pool's cumulative feeGrowthGlobals some time in the past
bFeeGrowthGlobalsThe pool's cumulative feeGrowthGlobals as of the current block
scaleuint32The timescale (in seconds) in which IV should be reported, e.g. hourly, daily, annualized

Returns

NameTypeDescription
<none>uint256An estimate of the implied volatility scaled by 1e12

Structs

PoolMetadata

struct PoolMetadata {
    uint24 gamma0;
    uint24 gamma1;
    int24 tickSpacing;
}

FeeGrowthGlobals

struct FeeGrowthGlobals {
    uint256 feeGrowthGlobal0X128;
    uint256 feeGrowthGlobal1X128;
    uint32 timestamp;
}