UNPKG

@ocap/util

Version:

utils shared across multiple forge js libs, works in both node.js and browser

113 lines (112 loc) 2.48 kB
import { BN } from "./bn.cjs"; import * as bn_js0 from "bn.js"; //#region src/curve.d.ts declare enum Direction { Mint = "mint", Burn = "burn", } /** * Constant Curve * Price = fixedPrice */ declare function calcConstantPrice({ fixedPrice }: { fixedPrice: string; }): BN; /** * Constant Curve * Cost = amount * fixedPrice */ declare function calcConstantCost({ amount, fixedPrice, decimal }: { amount: string; fixedPrice: string; decimal: number; }): bn_js0; /** * linear Curve * Price = basePrice + slope * currentSupply */ declare function calcLinearPrice({ basePrice, slope, currentSupply, decimal }: { basePrice: string; slope: string; currentSupply: string; decimal: number; }): bn_js0; /** * Linear Curve * mint Cost = (slope / 2) * ( (currentSupply + amount) ** 2 - currentSupply ** 2 ) + basePrice * amount; * burn Cost = (slope / 2) * ( currentSupply ** 2 - (currentSupply - amount) ** 2 ) + basePrice * amount; */ declare function calcLinearCost(params: { amount: string; currentSupply: string; basePrice: string; slope: string; decimal: number; direction: Direction; }): bn_js0; /** * Quadratic Curve * Price = basePrice + currentSupply ** 2 / constant */ declare function calcQuadraticPrice(params: { basePrice: string; currentSupply: string; constant: string; decimal: number; }): bn_js0; /** * Quadratic Curve * Price = basePrice + currentSupply ** 2 / constant * mint Cost = ( (currentSupply + amount)^3 / 3 - currentSupply^3 / 3 ) / constant + basePrice * amount; * burn Cost = ( currentSupply^3 / 3 - (currentSupply - amount)^3 / 3 ) / constant + basePrice * amount; */ declare function calcQuadraticCost(params: { amount: string; currentSupply: string; basePrice: string; constant: string; decimal: number; direction: Direction; }): bn_js0; declare function calcFee({ reserveAmount, feeRate }: { reserveAmount: string; feeRate: string; }): bn_js0; declare function calcPrice({ currentSupply, decimal, curve }: { currentSupply: string; decimal: number; curve: any; }): bn_js0; declare function calcCost({ amount, decimal, currentSupply, direction, curve }: { amount: string; decimal: number; currentSupply: string; curve: any; direction: Direction; }): bn_js0; //#endregion export { Direction, calcConstantCost, calcConstantPrice, calcCost, calcFee, calcLinearCost, calcLinearPrice, calcPrice, calcQuadraticCost, calcQuadraticPrice };