Gains Network
  • 📚Home
  • Gains Network
    • 🔎Overview
    • 🍏GNS Token
    • 📔Contract Addresses
      • Apechain Mainnet
      • Arbitrum Mainnet
      • Base Mainnet
      • Polygon Mainnet
  • gTrade (Leveraged Trading)
    • 🔎Overview
    • 🎛️Setting up to trade
      • 🟣Polygon Network Setup
      • 🔵Arbitrum Network Setup
    • 🏦Opening / Closing trades
    • 💲Trade Collaterals
      • Spotlight: WETH
    • 📖Asset classes
      • 🪙Cryptocurrencies
      • 💵Forex
      • 🛢️Commodities
    • 🎫Fees & Spread
    • 📰Pair List
    • 🧒How to use Practice Mode
    • ⚡One-Click Trading (1CT)
    • 🌌gTrade Solana
    • 📺Video tutorials
  • Loyalty Programs
    • Prime Trader
    • gTrade Credits
  • Community
    • gTrade Guardians
    • Governance forum
  • Reward Pools
    • 💚GNS Staking
    • 👛gToken Vaults
      • 👷Staker Functions
      • ❔Staker FAQ
      • ⏳Upgrades, updates, and timelocks
    • 🔼Active Pools & Incentives
  • Help
    • ❓FAQ
    • ⏳Chain congestion
  • Bridges
    • 🪐Arbitrum <-> Polygon Bridge
    • 🪐ERC20 Bridge (Polygon)
    • 🪐NFT Bridge (Polygon)
  • Developer
    • Integrators
      • Trading Contracts
      • Backend
      • Price Feed
      • Guides
        • v9 migration
        • Calculating borrowing fees
        • Calculating liquidation price
    • Technical Reference
      • Contracts
        • Changelogs
          • v9.2.1 Update
          • v9.1 Update
          • v9.1.1 Update
          • v9 Update
        • Core
          • Abstract
            • GNSAddressStore
            • GNSDiamondCut
            • GNSDiamondLoupe
            • GNSDiamondStorage
          • Facets
            • GNSBorrowingFees
            • GNSOtc
            • GNSPriceAggregator
            • GNSTradingInteractions
            • GNSTriggerRewards
            • GNSFeeTiers
            • GNSPairsStorage
            • GNSPriceImpact
            • GNSReferrals
            • GNSTradingCallbacks
            • GNSTradingStorage
          • GNSMultiCollatDiamond
          • GNSStaking
          • GToken
          • GTokenOpenPnlFeed
        • Interfaces
          • Libraries
            • IBorrowingFeesUtils
            • IOtcUtils
            • IPriceAggregatorUtils
            • ITriggerRewardsUtils
            • IFeeTiersUtils
            • IPairsStorageUtils
            • IPriceImpactUtils
            • IReferralsUtils
            • ITradingCallbacksUtils
            • ITradingCommonUtils
            • ITradingInteractionsUtils
            • ITradingStorageUtils
            • IUpdateLeverageUtils
            • IUpdatePositionSizeUtils
          • Types
            • IAddressStore
            • IBorrowingFees
            • IDiamondStorage
            • IOtc
            • IPriceAggregator
            • ITradingStorage
            • ITradingInteractions
            • ITriggerRewards
            • ITypes
            • IUpdateLeverage
            • IPairsStorage
            • IFeeTiers
            • IPriceImpact
            • IReferrals
            • ITradingCallbacks
            • IUpdatePositionSize
          • IChainlinkFeed
          • IArbSys
          • IChainlinkOracle
          • IERC20
          • IERC721
          • IERC721Design
          • IGeneralErrors
          • IGNSAddressStore
          • IGNSDiamond
          • IGNSDiamondCut
          • IGNSMultiCollatDiamond
          • IGNSDiamondLoupe
          • IGNSStaking
          • IGToken
          • IGTokenLockedDepositNft
          • IGTokenOpenPnlFeed
          • IGTokenLockedDepositNftDesign
          • ILiquidityPool
          • IRateProvider
          • IOwnable
        • Libraries
          • updateLeverage
            • UpdateLeverageLifecycles
          • updatePositionSize
            • IncreasePositionSizeUtils
            • DecreasePositionSizeUtils
            • UpdatePositionSizeLifecycles
          • AddressStoreUtils
          • ChainlinkClientUtils
          • ChainUtils
          • ConstantsUtils
          • CollateralUtils
          • DiamondUtils
          • LiquidityPoolUtils
          • OtcUtils
          • PackingUtils
          • StorageUtils
          • TriggerRewardsUtils
          • ArrayGetters
          • BorrowingFeesUtils
          • FeeTiersUtils
          • PriceAggregatorUtils
          • PriceImpactUtils
          • ReferralsUtils
          • TradingCallbacksUtils
          • PairsStorageUtils
          • TradingCommonUtils
          • TradingStorageUtils
          • TradingInteractionsUtils
        • Misc
          • EpochBasedTokenClaim
          • GNSCompensationHandler
          • GTokenRateProvider
          • GTokenLockedDepositNftDesign
          • ManagerTimelock
          • OwnerTimelock
          • VotingDelegator
        • Tokens
          • GainsNetworkToken
          • GTokenLockedDepositNft
      • Backend
        • Backend Types
      • SDK
        • Client Types
  • Archived
    • 🖼️gFARM2 NFTs
Powered by GitBook
On this page
  • getLiquidityPoolInfo
  • Parameters
  • getTimeWeightedAveragePrice
  • Parameters
  • _getPoolTickCumulatives
  • Parameters
  • _tickCumulativesToTokenPrice
  • Parameters

Was this helpful?

  1. Developer
  2. Technical Reference
  3. Contracts
  4. Libraries

LiquidityPoolUtils

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

Name
Type
Description

_input

LiquidityPoolInput 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

Name
Type
Description

_poolInfo

Liquidity pool info

_twapInterval

uint32

TWAP interval in seconds

_precisionDelta

uint256

precision 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

Name
Type
Description

_poolInfo

Liquidity pool info

_twapInterval

uint32

TWAP 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

Name
Type
Description

_tickCumulatives

int56[]

array of tickCumulatives

_twapInterval

uint32

TWAP interval

_precisionDelta

uint256

precision delta of collateral

_isGnsToken0InLp

bool

true if GNS is token0 in LP Inspired from https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/OracleLibrary.sol

PreviousDiamondUtilsNextOtcUtils

Last updated 9 months ago

Was this helpful?

IPriceAggregator.LiquidityPoolInput
IPriceAggregator.LiquidityPoolInfo
IPriceAggregator.LiquidityPoolInfo