Bonsaiswap Docs
  • 🌿Bonsaiswap Intro
  • Get Started
    • Create a Wallet
    • Get ERC20 Tokens
  • Roadmap
  • Products
    • 🔄Exchange
      • Swapping Tokens
      • Providing Liquidity
    • 🔮Coming Soon!
  • Tokenomics
    • 🎍AKADAMA
  • Developers
    • 🛠️Technical Reference
      • Core
        • BonsaiswapV3Factory
        • BonsaiswapV3Pool
        • BonsaiswapV3PoolDeployer
        • Interfaces
          • IERC20Minimal
          • IBonsaiswapV3Factory
          • IBonsaiswapV3Pool
          • IBonsaiswapV3PoolDeployer
          • callback
            • IBonsaiswapV3FlashCallback
            • IBonsaiswapV3MintCallback
            • IBonsaiswapV3SwapCallback
          • Pool
            • IBonsaiswapV3PoolActions
            • IBonsaiswapV3PoolDerivedState
            • IBonsaiswapV3PoolEvents
            • IBonsaiswapV3PoolImmutables
            • IBonsaiswapV3PoolOwnerActions
            • IBonsaiswapV3PoolState
        • Libraries
          • BitMath
          • FixedPoint128
          • FixedPoint96
          • FullMath
          • LiquidityMath
          • LowGasSafeMath
          • Oracle
          • Position
          • SafeCast
          • SecondsOutside
          • SqrtPriceMath
          • SwapMath
          • Tick
          • TickBitmap
          • TickMath
          • TransferHelper
          • UnsafeMath
      • Periphery
        • Base
          • BlockTimestamp
          • ERC721Permit
          • LiquidityManagement
          • Multicall
          • PeripheryImmutableState
          • PeripheryPayments
          • PeripheryPaymentsWithFee
          • PoolInitializer
          • SelfPermit
        • Interfaces
          • IERC20Metadata
          • IERC721Permit
          • IMulticall
          • INonfungiblePositionManager
          • INonfungibleTokenPositionDescriptor
          • IPeripheryImmutableState
          • IPeripheryPayments
          • IPeripheryPaymentsWithFee
          • IPoolInitializer
          • IQuoter
          • IQuoterV2
          • ISelfPermit
          • ISwapRouter
          • ITickLens
          • external
            • IERC1271
            • IERC20PermitAllowed
            • IWETH9
        • Lens
          • Quoter
          • QuoterV2
          • TickLens
        • Libraries
          • Base64
          • BytesLib
          • CallbackValidation
          • ChainId
          • HexStrings
          • LiquidityAmounts
          • NFTDescriptor
          • NFTSVG
          • OracleLibrary
          • Path
          • PoolAddress
          • PoolTicksCounter
          • PositionKey
          • TokenRatioSortOrder
          • TransferHelper
          • WeightedOracleLibrary
        • NonfungiblePositionManager
        • NonfungibleTokenPositionDescriptor
        • SwapRouter
        • V3Migrator
      • Deployment Addresses
      • Error Codes
Powered by GitBook
On this page
  1. Developers
  2. Technical Reference
  3. Core
  4. Libraries

TickMath

PreviousTickBitmapNextTransferHelper

Last updated 2 years ago

Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports prices between 2-128 and 2128

Functions

getSqrtRatioAtTick

  function getSqrtRatioAtTick(
    int24 tick
  ) internal pure returns (uint160 sqrtPriceX96)

Calculates sqrt(1.0001^tick) * 2^96

Throws if |tick| > max tick

Parameters:

Name
Type
Description

tick

int24

The input tick for the above formula

Return Values:

Name
Type
Description

sqrtPriceX96

uint160

A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)

at the given tick

getTickAtSqrtRatio

  function getTickAtSqrtRatio(
    uint160 sqrtPriceX96
  ) internal pure returns (int24 tick)

Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio

Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may ever return.

Name
Type
Description

sqrtPriceX96

uint160

The sqrt ratio for which to compute the tick as a Q64.96

Name
Type
Description

tick

int24

The greatest tick for which the ratio is less than or equal to the input ratio

Parameters:

Return Values:

🛠️
​
​
​
​
​
​
​