Aloe Protocol
Search…
⌃K

VolatilityOracle.sol

https://github.com/aloelabs/aloe-blend/blob/master/contracts/VolatilityOracle.sol
The information provided by Aloe Labs, Inc. (“we,” “us” or “our”) on docs.aloe.capital (the “Site”) is for general informational purposes only. All information on the Site is provided in good faith, however we make no representation or warranty of any kind, express or implied, regarding the accuracy, adequacy, validity, reliability, availability or completeness of any information on the Site.
Under no circumstance shall we have any liability to you for any loss or damage of any kind incurred as a result of the use of the site or reliance on any information provided on the site. Your use of the site and your reliance on any information on the site is solely at your own risk.

Actions

Updates cached metadata for a Uniswap pool.
Must be called at least once in order for volatility to be determined. To maintain volatility accuracy, this should also be called whenever Uniswap's protocol fee changes.
This method gets the age (in seconds) of the oldest observation in the Uniswap pool's circular buffer. When fetching data later on, the Volatility Oracle tries to look back either to the oldest observation or 86400 seconds, whichever is younger. Since block times vary, the exact age of the oldest observation also varies. To minimize reverts, the code stores 0.6 * maxSecondsAgo instead of the raw value. On the off chance that you do get an OLD error, re-caching pool metadata will fix things.

Arguments

  • pool The Uniswap pool to poke
function cacheMetadataFor(IUniswapV3Pool pool) external;
Estimates 24-hour implied volatility for a Uniswap pool. Must call cacheMetadataFor(pool) before this will work.

Arguments

  • pool The pool to use for volatility estimate

Return Values

  • IV The estimated implied volatility, scaled by 1e18. For annualized IV, multiply by
    365\sqrt{365}
function estimate24H(IUniswapV3Pool pool) external returns (uint256 IV);

Derived State

Provides multiple estimates of IV using all stored feeGrowthGlobals entries for pool.
This is not meant to be used on-chain because it doesn't contribute to the oracle's knowledge. Please use estimate24H(pool) instead.

Arguments

  • pool The pool to use for volatility estimate

Return Values

  • IV The array of volatility estimates, scaled by 1e18.
function lens(IUniswapV3Pool pool) external returns (uint256[25] memory IV);

State

Accesses the most recently stored metadata for a given Uniswap pool.
These values may or may not have been initialized and may or may not be up to date. tickSpacing will be non-zero if they've been initialized.

Arguments

  • pool The Uniswap pool for which metadata should be retrieved

Return Values

  • maxSecondsAgo The age of the oldest observation in the pool's oracle
  • gamma0 The pool fee minus the protocol fee on TOKEN0, scaled by 1e6
  • gamma1 The pool fee minus the protocol fee on TOKEN1, scaled by 1e6
function cachedPoolMetadata(IUniswapV3Pool pool)
external
view
returns (
uint32 maxSecondsAgo,
uint24 gamma0,
uint24 gamma1,
int24 tickSpacing
);
Accesses any of the 25 most recently stored fee growth structs.
The full array (idx=0,1,2...24) has data that spans at least 24 hours.

Arguments

  • pool The Uniswap pool for which fee growth should be retrieved
  • idx The index into the storage array

Return Values

  • feeGrowthGlobal0X128 Total pool revenue in TOKEN0, as of timestamp
  • feeGrowthGlobal1X128 Total pool revenue in TOKEN1, as of timestamp
  • timestamp The time at which snapshot was taken and stored
function feeGrowthGlobals(IUniswapV3Pool pool, uint256 idx)
external
view
returns (
uint256 feeGrowthGlobal0X128,
uint256 feeGrowthGlobal1X128,
uint32 timestamp
);
Returns indices that the contract will use to access feeGrowthGlobals

Arguments

  • pool The Uniswap pool for which array indices should be fetched

Return Values

  • read The index that was closest to 24 hours old last time estimate24H(pool) was called
  • write The index that was written to last time estimate24H(pool) was called
function feeGrowthGlobalsIndices(IUniswapV3Pool pool) external view returns (uint8 read, uint8 write);