Formulas
Low-level price math for swap.alcor pools.
For applications, use the Alcor SDK. The formulas below are for working with the contract directly.
Pool price
sqrtPriceX64 is in the currSlot field of the pool row. precisionA and precisionB are the token precisions.
Price of tokenA in tokenB:
sqrtPriceX64 ** 2 / 2 ** 128 * 10 ** (precisionA - precisionB)
Price of tokenB in tokenA:
2 ** 128 / sqrtPriceX64 ** 2 * 10 ** (precisionB - precisionA)sqrtPriceX64 is a 128-bit integer. Square it with big integers (e.g. BigInt) to avoid losing precision.