UNPKG

goosefx-amm-sdk

Version:

SDK for the GooseFx AMM

2 lines 1.38 kB
import v from"bn.js";import D from"bn.js";import m from"bn.js";import O from"decimal.js-light";import b from"bn.js";var c=new b(0);function d(s,e){if(e.isZero())throw Error("divisor is zero");return s.mod(e)}function u(s,e){if(e.isZero())throw Error("rhs is zero");let t=s.div(e);return t.isZero()?[t,e]:s.sub(t.mul(e)).isZero()?[t,e]:[t.add(new b(1)),e]}var R=new m(100),h=new m(1e6);var k=new m(3600),x=new m(1e5),A=new m(3e5);var N=class{static swapWithoutFees(e,t,n){let a=t.mul(n),r=t.add(e),[o,i]=u(a,r),B=i.sub(t),l=n.sub(o);if(l.isZero())throw Error("destinationAmountSwapped is zero");return{sourceAmountSwapped:B,destinationAmountSwapped:l}}static swapWithoutFeesBaseOut(e,t,n){if(e.isZero())throw new Error("destinationAmount is zero");if(e.gt(n))throw new Error("destinationAmount exceeds available destination reserve");let a=t.mul(e),r=n.sub(e);if(r.isZero())throw new Error("denominator is zero");let[o]=u(a,r);return{sourceAmountSwapped:o,destinationAmountSwapped:e}}static lpTokensToTradingTokens(e,t,n,a,r){let o=e.mul(n).div(t),i=e.mul(a).div(t);if(r===0)return{tokenAmount0:o,tokenAmount1:i};if(r===1)return d(e.mul(n),t).gt(c)&&o.gt(c)&&(o=o.add(new v(1))),d(e.mul(a),t).gt(c)&&i.gt(c)&&(i=i.add(new v(1))),{tokenAmount0:o,tokenAmount1:i};throw Error("roundDirection value error")}};export{N as ConstantProductCurve}; //# sourceMappingURL=constantProduct.mjs.map