Options
All
• Public
• Public/Protected
• All

# Class PriceMath

A collection of utility functions to convert between price, tickIndex and sqrtPrice.

• PriceMath

## Methods

• invertPrice(price: Decimal, decimalsA: number, decimalsB: number): Decimal
• Utility to invert the price Pb/Pa to Pa/Pb NOTE: precision is lost in this conversion

#### Parameters

Pb / Pa

• ##### decimalsA: number

Decimals of original token A (i.e. token A in the given Pb / Pa price)

• ##### decimalsB: number

Decimals of original token B (i.e. token B in the given Pb / Pa price)

#### Returns Decimal

inverted price, i.e. Pa / Pb

• invertSqrtPriceX64(sqrtPriceX64: BN): BN
• Utility to invert the sqrtPriceX64 from X64 repr. of sqrt(Pb/Pa) to X64 repr. of sqrt(Pa/Pb) NOTE: precision is lost in this conversion

#### Parameters

• ##### sqrtPriceX64: BN

X64 representation of sqrt(Pb / Pa)

#### Returns BN

inverted sqrtPriceX64, i.e. X64 representation of sqrt(Pa / Pb)

• priceToInitializableTickIndex(price: Decimal, decimalsA: number, decimalsB: number, tickSpacing: number): number

#### Returns number

• priceToSqrtPriceX64(price: Decimal, decimalsA: number, decimalsB: number): BN

#### Returns BN

• priceToTickIndex(price: Decimal, decimalsA: number, decimalsB: number): number

#### Returns number

• sqrtPriceX64ToPrice(sqrtPriceX64: BN, decimalsA: number, decimalsB: number): Decimal

#### Returns Decimal

• sqrtPriceX64ToTickIndex(sqrtPriceX64: BN): number

#### Returns number

• tickIndexToPrice(tickIndex: number, decimalsA: number, decimalsB: number): Decimal

#### Returns Decimal

• tickIndexToSqrtPriceX64(tickIndex: number): BN

#### Returns BN

Generated using TypeDoc