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