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