cfmms-rs icon indicating copy to clipboard operation
cfmms-rs copied to clipboard

`BigFloat` panics

Open 0xOsiris opened this issue 2 years ago • 2 comments

Remove num-bigfloat crate from all price calculations because of unexpected panic in division.

Panic Example:

use num_bigfloat::BigFloat;

fn main() {
    let x = BigFloat::from(1);
    let y = BigFloat::from(2);
    let z = x / y;
    println!("{z:?}");
}

Addresses #7

This affects the calculate_price functions in uniswap_v2.rs & uniswap_v3.rs

0xOsiris avatar Feb 03 '23 02:02 0xOsiris

Just dropping a note here from our conversation.

Lets strip out the num-bigfloat and calculate the price without floats. Then we can have a function for each pool that returns the price as an f64 and another function that returns a fixed point number.

0xKitsune avatar Feb 03 '23 15:02 0xKitsune

Right now, we are going to use div_uu to compute a 64_x_64 value when calculating price. We will have function to convert this to f64 as well.

We are also going to look into the pros and cons of using rug instead.

0xKitsune avatar Feb 03 '23 17:02 0xKitsune