UNPKG

goosefx-amm-sdk

Version:

SDK for the GooseFx AMM

2 lines 4.22 kB
"use strict";var S=Object.create;var c=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var v=(e,r)=>{for(var o in r)c(e,o,{get:r[o],enumerable:!0})},N=(e,r,o,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let m of O(r))!F.call(e,m)&&m!==o&&c(e,m,{get:()=>r[m],enumerable:!(n=y(r,m))||n.enumerable});return e};var p=(e,r,o)=>(o=e!=null?S(U(e)):{},N(r||!e||!e.__esModule?c(o,"default",{value:e,enumerable:!0}):o,e)),E=e=>N(c({},"__esModule",{value:!0}),e);var P={};v(P,{Fraction:()=>t});module.exports=E(P);var u=p(require("big.js")),L=p(require("bn.js")),x=p(require("decimal.js-light"));var i=p(require("bn.js"));var s=require("lodash");var f=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 o=r.map(n=>typeof n=="object"?JSON.stringify(n):n).join(", ");throw new Error(o)}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}},W={},k={};function d(e){let r=(0,s.get)(W,e);if(!r){let o=(0,s.get)(k,e);r=new f({name:e,logLevel:o}),(0,s.set)(W,e,r)}return r}var H=new i.default(0),q=new i.default(1),I=new i.default(2),M=new i.default(3),j=new i.default(5),G=new i.default(10),Z=new i.default(100),z=new i.default(1e3),V=new i.default(1e4),D=9007199254740991;function a(e){let r=d("Gfx_parseBigNumberish");if(e instanceof i.default)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new i.default(e);r.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&r.logWithError(`BigNumberish number underflow: ${e}`),(e>=D||e<=-D)&&r.logWithError(`BigNumberish number overflow: ${e}`),new i.default(String(e))):typeof e=="bigint"?new i.default(e.toString()):(r.error(`invalid BigNumberish value: ${e}`),new i.default(0))}var w=p(require("toformat")),R=w.default,h=R;var l=d("module/fraction"),B=h(u.default),g=h(x.default),_={[0]:g.ROUND_DOWN,[1]:g.ROUND_HALF_UP,[2]:g.ROUND_UP},C={[0]:u.default.roundDown,[1]:u.default.roundHalfUp,[2]:u.default.roundUp},t=class{constructor(r,o=new L.default(1)){this.numerator=a(r),this.denominator=a(o)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new t(this.denominator,this.numerator)}add(r){let o=r instanceof t?r:new t(a(r));return this.denominator.eq(o.denominator)?new t(this.numerator.add(o.numerator),this.denominator):new t(this.numerator.mul(o.denominator).add(o.numerator.mul(this.denominator)),this.denominator.mul(o.denominator))}sub(r){let o=r instanceof t?r:new t(a(r));return this.denominator.eq(o.denominator)?new t(this.numerator.sub(o.numerator),this.denominator):new t(this.numerator.mul(o.denominator).sub(o.numerator.mul(this.denominator)),this.denominator.mul(o.denominator))}mul(r){let o=r instanceof t?r:new t(a(r));return new t(this.numerator.mul(o.numerator),this.denominator.mul(o.denominator))}div(r){let o=r instanceof t?r:new t(a(r));return new t(this.numerator.mul(o.denominator),this.denominator.mul(o.numerator))}toSignificant(r,o={groupSeparator:""},n=1){Number.isInteger(r)||l.logWithError(`${r} is not an integer.`),r<=0&&l.logWithError(`${r} is not positive.`),g.set({precision:r+1,rounding:_[n]});let m=new g(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(r);return m.toFormat(m.decimalPlaces(),o)}toFixed(r,o={groupSeparator:""},n=1){return Number.isInteger(r)||l.logWithError(`${r} is not an integer.`),r<0&&l.logWithError(`${r} is negative.`),B.DP=r,B.RM=C[n]||1,new B(this.numerator.toString()).div(this.denominator.toString()).toFormat(r,o)}isZero(){return this.numerator.isZero()}};0&&(module.exports={Fraction}); //# sourceMappingURL=fraction.js.map