Purpose: All price calculation formulas. Used to calculate the total amount of ETH required when creating a pool, the price and total price of each NFT when buying/selling NFTs.

Installation

https://www.npmjs.com/package/ezswap_math

npm install ezswap_math
Import
import { mathLib } from 'ezswap_math'
Method call
mathLib[bondingCurve][action]  

-- bondingCurve: Function type, can be Exponential or Linear  
 
-- action: Pool type: can be buy, sell or trade (both buy and sell)

ParameterDescriptionRequiredExample
bondingCurvelinear: linear; exponential: exponentialtruelinear
typebuy: buy pool; sell: sell pool; trade: both buy and sell pooltruetrade
startpriceWhen creating a pool: the price entered by the user on the page;
When calculating the NFT price for buying and selling: the spotPrice returned by the interface.
Unit: ETH,the unit returned by the interface is wei, which needs to be divided by 1e18, and the same as follows
true8.95024875621890700
deltaThe price change of NFT after each buy/sell, unit: ETHtrue0.1
tfeeTrade pool can charge handling fee, the other two types cannot, unit: weitrue0.1
pfeeThe protocol fee charged by ezswap, unit: ETHtrue0.1
gfeeProtocol fee charged by the project manager, unit: ETHtrue0.1
nQuery the price of n-th NFT, the initial value is: 1true1
actionread: get NFT price; create: create a pooltrueread

Get the latest price of NFT

import { utils } from 'ethers';

const priceItem = mathLib?.[bondingCurve]?.[type](
  Number(utils.formatEther(spotPrice)),
  Number(utils.formatEther(delta)),
  Number(utils.formatEther(tfee)),
  Number(utils.formatEther(pfee)),
  Number(utils.formatEther(gfee)),
  n,
  action
);
Return parameters

Note: When using the following parameters, please pay attention to the subject + action, otherwise it will be easily confused.

ParameterDescription
priceDataThe total amount of ETH required for the transaction
priceData.userSellPrice / priceData.userBuyPriceThe total price of NFT sold by the user / the total price of NFT bought by the user
priceData.poolBuyPrice / priceData.poolSellPriceThe total price of NFT purchased by the pool / the total price of NFT sold by the pool
priceData.poolBuyPriceFee / priceData.poolSellPriceFeeThe total tax fee of NFT purchased by the pool / the total tax fee of NFT sold by the pool
priceData.userSellPriceFee / priceData.userBuyPriceFeeThe total tax fee of NFT sold by the user / the total tax fee of NFT purchased by the user
priceData.deltaThe price of NFT rise or fall after each buy/sell
priceData.spotPriceThe starting price that is not deducted by taxes and fees
currentPriceThe price summary of the N-th NFT
currentPrice.userSellPriceThe price for the user to sell the N-th NFT
currentPrice.userBuyPriceThe price for the user to buy the N-th NFT
nextPriceThe price summary of the N+1-th NFT
nextPrice.userSellPriceThe price for the user to sell the N+1-th NFT
nextPrice.userBuyPriceThe price for the user to buy the N+1-th NFT

For more details, please refer to Math library.