goosefx-amm-sdk
Version:
SDK for the GooseFx AMM
2 lines • 3.6 kB
JavaScript
import v from"bn.js";import c from"big.js";import y from"bn.js";import F from"decimal.js-light";import i from"bn.js";import{get as h,set as w}from"lodash";var d=class{constructor(r){this.logLevel=r.logLevel!==void 0?r.logLevel:0,this.name=r.name}set level(r){this.logLevel=r}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(r){return r<=this.logLevel}error(...r){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...r),this):this}logWithError(...r){let e=r.map(n=>typeof n=="object"?JSON.stringify(n):n).join(", ");throw new Error(e)}warning(...r){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...r),this):this}info(...r){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...r),this):this}debug(...r){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...r),this):this}},N={},L={};function u(o){let r=h(N,o);if(!r){let e=h(L,o);r=new d({name:o,logLevel:e}),w(N,o,r)}return r}var C=new i(0),P=new i(1),T=new i(2),A=new i(3),$=new i(5),H=new i(10),q=new i(100),I=new i(1e3),M=new i(1e4),B=9007199254740991;function m(o){let r=u("Gfx_parseBigNumberish");if(o instanceof i)return o;if(typeof o=="string"){if(o.match(/^-?[0-9]+$/))return new i(o);r.logWithError(`invalid BigNumberish string: ${o}`)}return typeof o=="number"?(o%1&&r.logWithError(`BigNumberish number underflow: ${o}`),(o>=B||o<=-B)&&r.logWithError(`BigNumberish number overflow: ${o}`),new i(String(o))):typeof o=="bigint"?new i(o.toString()):(r.error(`invalid BigNumberish value: ${o}`),new i(0))}import x from"toformat";var S=x,l=S;var g=u("module/fraction"),f=l(c),a=l(F),O={[0]:a.ROUND_DOWN,[1]:a.ROUND_HALF_UP,[2]:a.ROUND_UP},U={[0]:c.roundDown,[1]:c.roundHalfUp,[2]:c.roundUp},t=class{constructor(r,e=new y(1)){this.numerator=m(r),this.denominator=m(e)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new t(this.denominator,this.numerator)}add(r){let e=r instanceof t?r:new t(m(r));return this.denominator.eq(e.denominator)?new t(this.numerator.add(e.numerator),this.denominator):new t(this.numerator.mul(e.denominator).add(e.numerator.mul(this.denominator)),this.denominator.mul(e.denominator))}sub(r){let e=r instanceof t?r:new t(m(r));return this.denominator.eq(e.denominator)?new t(this.numerator.sub(e.numerator),this.denominator):new t(this.numerator.mul(e.denominator).sub(e.numerator.mul(this.denominator)),this.denominator.mul(e.denominator))}mul(r){let e=r instanceof t?r:new t(m(r));return new t(this.numerator.mul(e.numerator),this.denominator.mul(e.denominator))}div(r){let e=r instanceof t?r:new t(m(r));return new t(this.numerator.mul(e.denominator),this.denominator.mul(e.numerator))}toSignificant(r,e={groupSeparator:""},n=1){Number.isInteger(r)||g.logWithError(`${r} is not an integer.`),r<=0&&g.logWithError(`${r} is not positive.`),a.set({precision:r+1,rounding:O[n]});let b=new a(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(r);return b.toFormat(b.decimalPlaces(),e)}toFixed(r,e={groupSeparator:""},n=1){return Number.isInteger(r)||g.logWithError(`${r} is not an integer.`),r<0&&g.logWithError(`${r} is negative.`),f.DP=r,f.RM=U[n]||1,new f(this.numerator.toString()).div(this.denominator.toString()).toFormat(r,e)}isZero(){return this.numerator.isZero()}};var W=new t(new v(100)),D=class extends t{toSignificant(r=5,e,n){return this.mul(W).toSignificant(r,e,n)}toFixed(r=2,e,n){return this.mul(W).toFixed(r,e,n)}};export{D as Percent,W as _100_PERCENT};
//# sourceMappingURL=percent.mjs.map