UNPKG

@raydium-io/raydium-sdk-v2

Version:

An SDK for building applications on top of Raydium.

2 lines 3.5 kB
import x from"bn.js";import c from"big.js";import F from"bn.js";import U from"decimal.js-light";import{get as h,set as L}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(t=>typeof t=="object"?JSON.stringify(t):t).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={},w={};function u(i){let r=h(W,i);if(!r){let e=h(w,i);r=new d({name:i,logLevel:e}),L(W,i,r)}return r}import m from"bn.js";var D=9007199254740991;function n(i){let r=u("Raydium_parseBigNumberish");if(i instanceof m)return i;if(typeof i=="string"){if(i.match(/^-?[0-9]+$/))return new m(i);r.logWithError(`invalid BigNumberish string: ${i}`)}return typeof i=="number"?(i%1&&r.logWithError(`BigNumberish number underflow: ${i}`),(i>=D||i<=-D)&&r.logWithError(`BigNumberish number overflow: ${i}`),new m(String(i))):typeof i=="bigint"?new m(i.toString()):(r.error(`invalid BigNumberish value: ${i}`),new m(0))}import S from"toformat";var y=S,l=y;var g=u("module/fraction"),f=l(c),a=l(U),O={[0]:a.ROUND_DOWN,[1]:a.ROUND_HALF_UP,[2]:a.ROUND_UP},v={[0]:c.roundDown,[1]:c.roundHalfUp,[2]:c.roundUp},o=class{constructor(r,e=new F(1)){this.numerator=n(r),this.denominator=n(e)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new o(this.denominator,this.numerator)}add(r){let e=r instanceof o?r:new o(n(r));return this.denominator.eq(e.denominator)?new o(this.numerator.add(e.numerator),this.denominator):new o(this.numerator.mul(e.denominator).add(e.numerator.mul(this.denominator)),this.denominator.mul(e.denominator))}sub(r){let e=r instanceof o?r:new o(n(r));return this.denominator.eq(e.denominator)?new o(this.numerator.sub(e.numerator),this.denominator):new o(this.numerator.mul(e.denominator).sub(e.numerator.mul(this.denominator)),this.denominator.mul(e.denominator))}mul(r){let e=r instanceof o?r:new o(n(r));return new o(this.numerator.mul(e.numerator),this.denominator.mul(e.denominator))}div(r){let e=r instanceof o?r:new o(n(r));return new o(this.numerator.mul(e.denominator),this.denominator.mul(e.numerator))}toSignificant(r,e={groupSeparator:""},t=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[t]});let b=new a(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(r);return b.toFormat(b.decimalPlaces(),e)}toFixed(r,e={groupSeparator:""},t=1){return Number.isInteger(r)||g.logWithError(`${r} is not an integer.`),r<0&&g.logWithError(`${r} is negative.`),f.DP=r,f.RM=v[t]||1,new f(this.numerator.toString()).div(this.denominator.toString()).toFormat(r,e)}isZero(){return this.numerator.isZero()}};var B=new o(new x(100)),N=class extends o{toSignificant(r=5,e,t){return this.mul(B).toSignificant(r,e,t)}toFixed(r=2,e,t){return this.mul(B).toFixed(r,e,t)}};export{N as Percent,B as _100_PERCENT}; //# sourceMappingURL=percent.mjs.map