defituna-core 3.6.6

DefiTuna core library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
use crate::math::Fixed128;
use fixed::types::U64F64;
use fusionamm_core::{CoreError, ARITHMETIC_OVERFLOW};

pub fn sqrt_price_x64_to_price_fixed(sqrt_price_x64: u128) -> Result<Fixed128, CoreError> {
    let sqrt_price = Fixed128::from_bits(sqrt_price_x64 >> (64 - Fixed128::FRAC_NBITS));
    sqrt_price.checked_mul(sqrt_price).ok_or(ARITHMETIC_OVERFLOW)
}

pub fn sqrt_price_x64_to_price_x64(sqrt_price_x64: u128) -> Result<U64F64, CoreError> {
    let sqrt_price = U64F64::from_bits(sqrt_price_x64);
    sqrt_price.checked_mul(sqrt_price).ok_or(ARITHMETIC_OVERFLOW)
}