0

I implemented a constant price curve using the following formula

(initialDeposit/totalSupply) * 1 + log(1 + initialDeposit)

But this is not fair and don't increase price until initialDeposit increases by 10.10^decimals

use std::ops::{Add, Div, Mul};

use super::calculator::{CurveCalculator, TradeDirection};

pub struct ConstantPriceCurve {
    token_a_total_supply: u128,
    token_b_initial_deposit: u128,
    token_a_denominator: u128,
    token_b_denominator: u128,
}

impl ConstantPriceCurve {
    pub fn normalize_price(&self, price: u128, trade_direction: TradeDirection) -> u64 {
        let price = match trade_direction {
            TradeDirection::AtoB => price.div(self.token_b_denominator),
            TradeDirection::BtoA => price.div(self.token_a_denominator),
        } as u64;

        price
    }
}

impl CurveCalculator for ConstantPriceCurve {
    fn calculate_initial_price(&self) -> u128 {
        let offset = 1;
        let adjustment_factor = self.token_b_denominator.div(10);
        let base_price = self.token_b_initial_deposit.div(self.token_a_total_supply);

        base_price.add(
            offset.add(
                adjustment_factor.mul(offset.add(self.token_b_initial_deposit).ilog10() as u128),
            ),
        )
    }

    fn calculate_price(initial_price: u128, amount: u128, trade_direction: TradeDirection) -> u128 {
        match trade_direction {
            TradeDirection::AtoB => amount.mul(initial_price),
            TradeDirection::BtoA => amount.div(initial_price),
        }
    }
}

What formula can i use to make it more fair and maybe an improvement to this code or formula. I only need an initial price which is constant for all buy and sell.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.