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)
| Parameter | Description | Required | Example | 
|---|---|---|---|
| bondingCurve | linear: linear; exponential: exponential | true | linear | 
| type | buy: buy pool; sell: sell pool; trade: both buy and sell pool | true | trade | 
| startprice | When 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  | true | 8.95024875621890700 | 
| delta | The price change of NFT after each buy/sell, unit: ETH | true | 0.1 | 
| tfee | Trade pool can charge handling fee, the other two types cannot, unit: wei | true | 0.1 | 
| pfee | The protocol fee charged by ezswap, unit: ETH | true | 0.1 | 
| gfee | Protocol fee charged by the project manager, unit: ETH | true | 0.1 | 
| n | Query the price of n-th NFT, the initial value is: 1 | true | 1 | 
| action | read: get NFT price; create: create a pool | true | read | 
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.
| Parameter | Description | 
|---|---|
| priceData | The total amount of ETH required for the transaction | 
| priceData.userSellPrice / priceData.userBuyPrice | The total price of NFT sold by the user / the total price of NFT bought by the user | 
| priceData.poolBuyPrice / priceData.poolSellPrice | The total price of NFT purchased by the pool / the total price of NFT sold by the pool | 
| priceData.poolBuyPriceFee / priceData.poolSellPriceFee | The total tax fee of NFT purchased by the pool / the total tax fee of NFT sold by the pool | 
| priceData.userSellPriceFee / priceData.userBuyPriceFee | The total tax fee of NFT sold by the user / the total tax fee of NFT purchased by the user | 
| priceData.delta | The price of NFT rise or fall after each buy/sell | 
| priceData.spotPrice | The starting price that is not deducted by taxes and fees | 
| currentPrice | The price summary of the N-th NFT | 
| currentPrice.userSellPrice | The price for the user to sell the N-th NFT | 
| currentPrice.userBuyPrice | The price for the user to buy the N-th NFT | 
| nextPrice | The price summary of the N+1-th NFT | 
| nextPrice.userSellPrice | The price for the user to sell the N+1-th NFT | 
| nextPrice.userBuyPrice | The price for the user to buy the N+1-th NFT | 
For more details, please refer to Math library.