The exported calculation library is a mathLib object, which consists of two types: Linear and Exponential.

Each type contains three pool types: buy, sell, and trade.

There are three different methods corresponding to price calculation of each pool type. The parameters of these methods are the same and the return values are almost the same. Therefore, understanding one of them is enough.

install package

yarn add ezswap_math
export const mathLib = {
  Linear: {
    buy: (startprice, delta, tfee, pfee, n, gfee = 0, action = 'read') => {
      pfee = Number(pfee + gfee)
      return {
        priceData: BuyPoolLiner(startprice, delta, tfee, pfee, n, action),
        currentPrice: getBuyPoolLinerPrice(startprice, delta, tfee, pfee),
        nextPrice: getBuyPoolLinerNextPrice(startprice, delta, tfee, pfee, n)
      }
    },
    sell: (startprice, delta, tfee, pfee, n, gfee = 0, action = 'read') => {
      pfee = Number(pfee + gfee)
      return {
        priceData: SellPoolLiner(startprice, delta, tfee, pfee, n, action),
        currentPrice: getSellPoolLinerPrice(startprice, delta, tfee, pfee),
        nextPrice: getSellPoolLinerNextPrice(startprice, delta, tfee, pfee, n)
      }
    },
    trade: (startprice, delta, tfee, pfee, n, gfee = 0, action = 'read') => {
      pfee = Number(pfee + gfee)
      return {
        priceData: TradePoolLiner(startprice, delta, tfee, pfee, n, action),
        currentPrice: getTradePoolLinerPrice(startprice, delta, tfee, pfee),
        nextPrice: getTradePoolLinerNextPrice(startprice, delta, tfee, pfee, n)
      }
    }
  },
  Exponential: {
    buy: (startprice, delta, tfee, pfee, n, gfee = 0, action = 'read') => {
      pfee = Number(pfee + gfee)
      return {
        priceData: BuyPoolExpone(startprice, delta, tfee, pfee, n, action),
        currentPrice: getBuyPoolExponePrice(startprice, delta, tfee, pfee),
        nextPrice: getBuyPoolExponeNextPrice(startprice, delta, tfee, pfee, n)
      }
    },
    sell: (startprice, delta, tfee, pfee, n, gfee = 0, action = 'read') => {
      pfee = Number(pfee + gfee)
      return {
        priceData: SellPoolExpone(startprice, delta, tfee, pfee, n, action),
        currentPrice: getSellPoolExponePrice(startprice, delta, tfee, pfee),
        nextPrice: getSellPoolExponeNextPrice(startprice, delta, tfee, pfee, n)
      }
    },
    trade: (startprice, delta, tfee, pfee, n, gfee = 0, action = 'read') => {
      pfee = Number(pfee + gfee)
      return {
        priceData: TradePoolExpone(startprice, delta, tfee, pfee, n, action),
        currentPrice: getTradePoolExponePrice(startprice, delta, tfee, pfee),
        nextPrice: getTradePoolExponeNextPrice(startprice, delta, tfee, pfee, n)
      }
    }
  }
}