Skip to main content
Library to abstract liquidity pool operations such as fetching observations, calculating TWAP, etc. Currently supports Uniswap V3 and Algebra V1.9 liquidity pools

getLiquidityPoolInfo

function getLiquidityPoolInfo(struct IPriceAggregator.LiquidityPoolInput _input) internal view returns (struct IPriceAggregator.LiquidityPoolInfo)
Returns a LiquidityPoolInfo struct for LiquidityPoolInput _input

Parameters

NameTypeDescription
_inputIPriceAggregator.LiquidityPoolInputLiquidityPoolInput struct with pool address and type

getTimeWeightedAveragePrice

function getTimeWeightedAveragePrice(struct IPriceAggregator.LiquidityPoolInfo _poolInfo, uint32 _twapInterval, uint256 _precisionDelta) internal view returns (uint256)
Calculates the time-weighted average price of a liquidity pool over a given interval

Parameters

NameTypeDescription
_poolInfoIPriceAggregator.LiquidityPoolInfoLiquidity pool info
_twapIntervaluint32TWAP interval in seconds
_precisionDeltauint256precision delta of collateral

_getPoolTickCumulatives

function _getPoolTickCumulatives(struct IPriceAggregator.LiquidityPoolInfo _poolInfo, uint32 _twapInterval) internal view returns (int56[])
Fetches tickCumulatives data from the pool. Calls the appropriate oracle function based on the pool type

Parameters

NameTypeDescription
_poolInfoIPriceAggregator.LiquidityPoolInfoLiquidity pool info
_twapIntervaluint32TWAP interval

_tickCumulativesToTokenPrice

function _tickCumulativesToTokenPrice(int56[] _tickCumulatives, uint32 _twapInterval, uint256 _precisionDelta, bool _isGnsToken0InLp) internal pure returns (uint256)
Returns TWAP price (1e10 precision) from tickCumulatives data

Parameters

NameTypeDescription
_tickCumulativesint56[]array of tickCumulatives
_twapIntervaluint32TWAP interval
_precisionDeltauint256precision delta of collateral
_isGnsToken0InLpbooltrue if GNS is token0 in LP Inspired from https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/OracleLibrary.sol