Skip to main content
The SDK provides several utility functions for calculations and type conversions.

Math Functions


divRem

Performs division and returns the quotient and remainder. Parameters
number
required
The numerator.
number
required
The denominator.
Returns
[number, number]
An array containing the quotient and remainder.

mulDiv

Multiplies two numbers and then divides by a denominator, with rounding. Parameters
number
required
The first number.
number
required
The second number.
number
required
The denominator.
'up' | 'down'
required
The rounding direction.
Returns
number
The result of the calculation.

mulShr

Multiplies two numbers and then right-shifts the result. Parameters
number
required
The first number.
number
required
The second number.
number
required
The number of bits to shift.
'up' | 'down'
required
The rounding direction.
Returns
number
The result of the calculation.

shlDiv

Left-shifts a number and then divides by another number. Parameters
number
required
The number to shift.
number
required
The divisor.
number
required
The number of bits to shift.
'up' | 'down'
required
The rounding direction.
Returns
number
The result of the calculation.

Price Functions


getPriceFromId

Calculates the price from a bin ID. Parameters
number
required
The bin step of the liquidity pool.
number
required
The ID of the bin.
number
required
The decimals of the base token.
number
required
The decimals of the quote token.
Returns
number
The price.

getIdFromPrice

Calculates the bin ID from a price. Parameters
number
required
The price.
number
required
The bin step of the liquidity pool.
number
required
The decimals of the base token.
number
required
The decimals of the quote token.
Returns
number
The bin ID.

Type Conversion Functions


pairAccountToPair

Converts a PairAccount object to a Pair object. Parameters
PairAccount
required
The PairAccount object.
Returns
Pair
The Pair object.