Divergence Protocol
  • OVERVIEW
    • Divergence Protocol
    • Protocol Basics
      • Digital Options
      • Triangular Swaps
      • Convertible Liquidity
      • Options Specs
      • Fees
      • Glossary
      • References
  • User Guide
    • 📈Long Options
      • 🔥Open Longs
      • 🌊Close Longs
      • 👨‍🌾Exercise Options
    • 📉Short Options
      • 💧Open Shorts
      • 🔚Finalize Shorts
      • 📥Close Shorts
      • ⏰Expiry Withdrawal
    • 🍸Dive Bar
  • Technical Reference
    • Smart Contract Architecture
      • Deployment addresses
    • Core
      • Arena
      • Battle
      • Oracle
      • Utils
      • SToken
      • Interface
      • Libraries
        • DiverSqrtPriceMath
        • Position
        • Tick
        • TickMath
        • TradeMath
      • Params
      • Types
    • Periphery
      • Manager
      • Base
      • Interface
      • Quoter
      • Libraries
      • Params
      • Types
    • Audit Reports
  • DIVER Token
    • 🌝Tokenomics
      • Token Distribution
    • 🎃DIVΞR NFT Collections
  • Legal
    • Terms of Service
    • Risk Disclosure
  • MISC. INFO
    • 🔗Official Links
    • 🙌Media Kit
    • 🚢Ditanic Test Coins
Powered by GitBook
On this page
  • getSqrtRatioAtTick
  • getTickAtSqrtRatio

Was this helpful?

  1. Technical Reference
  2. Core
  3. Libraries

TickMath

Math library for computing sqrt prices from ticks and vice versa. Sets the minimum and maximum of ticks and sqrt prices.

As digital calls and puts are priced between [0.01, 0.99] per collateral, per put-call parity, the sqrtPrice is the sqrt ratio of shieldPrice/spearPrice is between [sqrt(1/99), sqrt(99)]. sqrtPrice is computed for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers.

getSqrtRatioAtTick

Calculates and returns the square root ratio at the given tick.

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

Params:

Name

Type

Description

tick

int24

The input tick for the above formula

Returns:

Name

Type

Description

sqrtPriceX96

uint160

A fixed point Q64.96 number representing the sqrt of the ratio of shieldPrice/spearPrice

getTickAtSqrtRatio

Calculates and returns the tick value at the given square root ratio.

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

Params:

Name

Type

Description

sqrtPriceX96

uint160

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

Returns:

Name

Type

Description

tick

int24

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

PreviousTickNextTradeMath

Last updated 1 year ago

Was this helpful?