goosefx-amm-sdk
Version:
SDK for the GooseFx AMM
2 lines • 5.06 kB
JavaScript
"use strict";var F=Object.create;var l=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var R=(o,e)=>{for(var r in e)l(o,r,{get:e[r],enumerable:!0})},D=(o,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of U(e))!E.call(o,i)&&i!==r&&l(o,i,{get:()=>e[i],enumerable:!(n=O(e,i))||n.enumerable});return o};var p=(o,e,r)=>(r=o!=null?F(v(o)):{},D(e||!o||!o.__esModule?l(r,"default",{value:o,enumerable:!0}):r,o)),q=o=>D(l({},"__esModule",{value:!0}),o);var H={};R(H,{Price:()=>u});module.exports=q(H);var a=p(require("bn.js"));var g=require("lodash");var h=class{constructor(e){this.logLevel=e.logLevel!==void 0?e.logLevel:0,this.name=e.name}set level(e){this.logLevel=e}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(e){return e<=this.logLevel}error(...e){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...e),this):this}logWithError(...e){let r=e.map(n=>typeof n=="object"?JSON.stringify(n):n).join(", ");throw new Error(r)}warning(...e){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...e),this):this}info(...e){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...e),this):this}debug(...e){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...e),this):this}},w={},P={};function s(o){let e=(0,g.get)(w,o);if(!e){let r=(0,g.get)(P,o);e=new h({name:o,logLevel:r}),(0,g.set)(w,o,e)}return e}var Z=new a.default(0),z=new a.default(1),V=new a.default(2),J=new a.default(3),X=new a.default(5),_=new a.default(10),K=new a.default(100),Q=new a.default(1e3),Y=new a.default(1e4),L=9007199254740991;function m(o){let e=s("Gfx_parseBigNumberish");if(o instanceof a.default)return o;if(typeof o=="string"){if(o.match(/^-?[0-9]+$/))return new a.default(o);e.logWithError(`invalid BigNumberish string: ${o}`)}return typeof o=="number"?(o%1&&e.logWithError(`BigNumberish number underflow: ${o}`),(o>=L||o<=-L)&&e.logWithError(`BigNumberish number overflow: ${o}`),new a.default(String(o))):typeof o=="bigint"?new a.default(o.toString()):(e.error(`invalid BigNumberish value: ${o}`),new a.default(0))}function B(o){return _.pow(m(o))}var c=p(require("big.js")),x=p(require("bn.js")),y=p(require("decimal.js-light"));var k=p(require("toformat")),C=k.default,N=C;var f=s("module/fraction"),W=N(c.default),d=N(y.default),j={[0]:d.ROUND_DOWN,[1]:d.ROUND_HALF_UP,[2]:d.ROUND_UP},A={[0]:c.default.roundDown,[1]:c.default.roundHalfUp,[2]:c.default.roundUp},t=class{constructor(e,r=new x.default(1)){this.numerator=m(e),this.denominator=m(r)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new t(this.denominator,this.numerator)}add(e){let r=e instanceof t?e:new t(m(e));return this.denominator.eq(r.denominator)?new t(this.numerator.add(r.numerator),this.denominator):new t(this.numerator.mul(r.denominator).add(r.numerator.mul(this.denominator)),this.denominator.mul(r.denominator))}sub(e){let r=e instanceof t?e:new t(m(e));return this.denominator.eq(r.denominator)?new t(this.numerator.sub(r.numerator),this.denominator):new t(this.numerator.mul(r.denominator).sub(r.numerator.mul(this.denominator)),this.denominator.mul(r.denominator))}mul(e){let r=e instanceof t?e:new t(m(e));return new t(this.numerator.mul(r.numerator),this.denominator.mul(r.denominator))}div(e){let r=e instanceof t?e:new t(m(e));return new t(this.numerator.mul(r.denominator),this.denominator.mul(r.numerator))}toSignificant(e,r={groupSeparator:""},n=1){Number.isInteger(e)||f.logWithError(`${e} is not an integer.`),e<=0&&f.logWithError(`${e} is not positive.`),d.set({precision:e+1,rounding:j[n]});let i=new d(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return i.toFormat(i.decimalPlaces(),r)}toFixed(e,r={groupSeparator:""},n=1){return Number.isInteger(e)||f.logWithError(`${e} is not an integer.`),e<0&&f.logWithError(`${e} is negative.`),W.DP=e,W.RM=A[n]||1,new W(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,r)}isZero(){return this.numerator.isZero()}};var $=s("Ray_price"),u=class extends t{constructor(r){let{baseToken:n,quoteToken:i,numerator:S,denominator:T}=r;super(S,T);this.baseToken=n,this.quoteToken=i,this.scalar=new t(B(n.decimals),B(i.decimals))}get raw(){return new t(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new u({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numerator,numerator:this.denominator})}mul(r){this.quoteToken!==r.baseToken&&$.logWithError("mul token not equals");let n=super.mul(r);return new u({baseToken:this.baseToken,quoteToken:r.quoteToken,denominator:n.denominator,numerator:n.numerator})}toSignificant(r=this.quoteToken.decimals,n,i){return this.adjusted.toSignificant(r,n,i)}toFixed(r=this.quoteToken.decimals,n,i){return this.adjusted.toFixed(r,n,i)}};0&&(module.exports={Price});
//# sourceMappingURL=price.js.map