Log In

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.



npm install ezswap_math
import { mathLib } from 'ezswap_math'
Method call

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

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
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](
Return parameters

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

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.