UNPKG

test-raydium-sdk-v2

Version:

An SDK for building applications on top of Raydium.

1 lines 93.3 kB
var yr=Object.create;var ot=Object.defineProperty,wr=Object.defineProperties,Tr=Object.getOwnPropertyDescriptor,Ar=Object.getOwnPropertyDescriptors,xr=Object.getOwnPropertyNames,wn=Object.getOwnPropertySymbols,kr=Object.getPrototypeOf,An=Object.prototype.hasOwnProperty,Pr=Object.prototype.propertyIsEnumerable;var Tn=(r,e,t)=>e in r?ot(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Z=(r,e)=>{for(var t in e||(e={}))An.call(e,t)&&Tn(r,t,e[t]);if(wn)for(var t of wn(e))Pr.call(e,t)&&Tn(r,t,e[t]);return r},ne=(r,e)=>wr(r,Ar(e));var Br=(r,e)=>{for(var t in e)ot(r,t,{get:e[t],enumerable:!0})},xn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of xr(e))!An.call(r,i)&&i!==t&&ot(r,i,{get:()=>e[i],enumerable:!(n=Tr(e,i))||n.enumerable});return r};var J=(r,e,t)=>(t=r!=null?yr(kr(r)):{},xn(e||!r||!r.__esModule?ot(t,"default",{value:r,enumerable:!0}):t,r)),Ir=r=>xn(ot({},"__esModule",{value:!0}),r);var zi={};Br(zi,{LiquidityMath:()=>F,MathUtil:()=>S,SqrtPriceMath:()=>N,SwapMath:()=>We,TickMath:()=>Ue});module.exports=Ir(zi);var C=J(require("bn.js"));var Qe=9e15,qe=1e9,Gt="0123456789abcdef",kt="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Pt="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Vt={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Qe,maxE:Qe,crypto:!1},In,Ee,B=!0,It="[DecimalError] ",Ke=It+"Invalid argument: ",Nn=It+"Precision limit exceeded",Sn=It+"crypto unavailable",Cn="[object Decimal]",se=Math.floor,$=Math.pow,Nr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Sr=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Cr=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Ln=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Pe=1e7,x=7,Lr=9007199254740991,Er=kt.length-1,Ut=Pt.length-1,p={toStringTag:Cn};p.absoluteValue=p.abs=function(){var r=new this.constructor(this);return r.s<0&&(r.s=1),T(r)};p.ceil=function(){return T(new this.constructor(this),this.e+1,2)};p.clampedTo=p.clamp=function(r,e){var t,n=this,i=n.constructor;if(r=new i(r),e=new i(e),!r.s||!e.s)return new i(NaN);if(r.gt(e))throw Error(Ke+e);return t=n.cmp(r),t<0?r:n.cmp(e)>0?e:new i(n)};p.comparedTo=p.cmp=function(r){var e,t,n,i,o=this,s=o.d,a=(r=new o.constructor(r)).d,u=o.s,c=r.s;if(!s||!a)return!u||!c?NaN:u!==c?u:s===a?0:!s^u<0?1:-1;if(!s[0]||!a[0])return s[0]?u:a[0]?-c:0;if(u!==c)return u;if(o.e!==r.e)return o.e>r.e^u<0?1:-1;for(n=s.length,i=a.length,e=0,t=n<i?n:i;e<t;++e)if(s[e]!==a[e])return s[e]>a[e]^u<0?1:-1;return n===i?0:n>i^u<0?1:-1};p.cosine=p.cos=function(){var r,e,t=this,n=t.constructor;return t.d?t.d[0]?(r=n.precision,e=n.rounding,n.precision=r+Math.max(t.e,t.sd())+x,n.rounding=1,t=Rr(n,Dn(n,t)),n.precision=r,n.rounding=e,T(Ee==2||Ee==3?t.neg():t,r,e,!0)):new n(1):new n(NaN)};p.cubeRoot=p.cbrt=function(){var r,e,t,n,i,o,s,a,u,c,l=this,m=l.constructor;if(!l.isFinite()||l.isZero())return new m(l);for(B=!1,o=l.s*$(l.s*l,1/3),!o||Math.abs(o)==1/0?(t=ie(l.d),r=l.e,(o=(r-t.length+1)%3)&&(t+=o==1||o==-2?"0":"00"),o=$(t,1/3),r=se((r+1)/3)-(r%3==(r<0?-1:2)),o==1/0?t="5e"+r:(t=o.toExponential(),t=t.slice(0,t.indexOf("e")+1)+r),n=new m(t),n.s=l.s):n=new m(o.toString()),s=(r=m.precision)+3;;)if(a=n,u=a.times(a).times(a),c=u.plus(l),n=v(c.plus(l).times(a),c.plus(u),s+2,1),ie(a.d).slice(0,s)===(t=ie(n.d)).slice(0,s))if(t=t.slice(s-3,s+1),t=="9999"||!i&&t=="4999"){if(!i&&(T(a,r+1,0),a.times(a).times(a).eq(l))){n=a;break}s+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(T(n,r+1,1),e=!n.times(n).times(n).eq(l));break}return B=!0,T(n,r,m.rounding,e)};p.decimalPlaces=p.dp=function(){var r,e=this.d,t=NaN;if(e){if(r=e.length-1,t=(r-se(this.e/x))*x,r=e[r],r)for(;r%10==0;r/=10)t--;t<0&&(t=0)}return t};p.dividedBy=p.div=function(r){return v(this,new this.constructor(r))};p.dividedToIntegerBy=p.divToInt=function(r){var e=this,t=e.constructor;return T(v(e,new t(r),0,1,1),t.precision,t.rounding)};p.equals=p.eq=function(r){return this.cmp(r)===0};p.floor=function(){return T(new this.constructor(this),this.e+1,3)};p.greaterThan=p.gt=function(r){return this.cmp(r)>0};p.greaterThanOrEqualTo=p.gte=function(r){var e=this.cmp(r);return e==1||e===0};p.hyperbolicCosine=p.cosh=function(){var r,e,t,n,i,o=this,s=o.constructor,a=new s(1);if(!o.isFinite())return new s(o.s?1/0:NaN);if(o.isZero())return a;t=s.precision,n=s.rounding,s.precision=t+Math.max(o.e,o.sd())+4,s.rounding=1,i=o.d.length,i<32?(r=Math.ceil(i/3),e=(1/St(4,r)).toString()):(r=16,e="2.3283064365386962890625e-10"),o=Je(s,1,o.times(e),new s(1),!0);for(var u,c=r,l=new s(8);c--;)u=o.times(o),o=a.minus(u.times(l.minus(u.times(l))));return T(o,s.precision=t,s.rounding=n,!0)};p.hyperbolicSine=p.sinh=function(){var r,e,t,n,i=this,o=i.constructor;if(!i.isFinite()||i.isZero())return new o(i);if(e=o.precision,t=o.rounding,o.precision=e+Math.max(i.e,i.sd())+4,o.rounding=1,n=i.d.length,n<3)i=Je(o,2,i,i,!0);else{r=1.4*Math.sqrt(n),r=r>16?16:r|0,i=i.times(1/St(5,r)),i=Je(o,2,i,i,!0);for(var s,a=new o(5),u=new o(16),c=new o(20);r--;)s=i.times(i),i=i.times(a.plus(s.times(u.times(s).plus(c))))}return o.precision=e,o.rounding=t,T(i,e,t,!0)};p.hyperbolicTangent=p.tanh=function(){var r,e,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(r=n.precision,e=n.rounding,n.precision=r+7,n.rounding=1,v(t.sinh(),t.cosh(),n.precision=r,n.rounding=e)):new n(t.s)};p.inverseCosine=p.acos=function(){var r,e=this,t=e.constructor,n=e.abs().cmp(1),i=t.precision,o=t.rounding;return n!==-1?n===0?e.isNeg()?ke(t,i,o):new t(0):new t(NaN):e.isZero()?ke(t,i+4,o).times(.5):(t.precision=i+6,t.rounding=1,e=e.asin(),r=ke(t,i+4,o).times(.5),t.precision=i,t.rounding=o,r.minus(e))};p.inverseHyperbolicCosine=p.acosh=function(){var r,e,t=this,n=t.constructor;return t.lte(1)?new n(t.eq(1)?0:NaN):t.isFinite()?(r=n.precision,e=n.rounding,n.precision=r+Math.max(Math.abs(t.e),t.sd())+4,n.rounding=1,B=!1,t=t.times(t).minus(1).sqrt().plus(t),B=!0,n.precision=r,n.rounding=e,t.ln()):new n(t)};p.inverseHyperbolicSine=p.asinh=function(){var r,e,t=this,n=t.constructor;return!t.isFinite()||t.isZero()?new n(t):(r=n.precision,e=n.rounding,n.precision=r+2*Math.max(Math.abs(t.e),t.sd())+6,n.rounding=1,B=!1,t=t.times(t).plus(1).sqrt().plus(t),B=!0,n.precision=r,n.rounding=e,t.ln())};p.inverseHyperbolicTangent=p.atanh=function(){var r,e,t,n,i=this,o=i.constructor;return i.isFinite()?i.e>=0?new o(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(r=o.precision,e=o.rounding,n=i.sd(),Math.max(n,r)<2*-i.e-1?T(new o(i),r,e,!0):(o.precision=t=n-i.e,i=v(i.plus(1),new o(1).minus(i),t+r,1),o.precision=r+4,o.rounding=1,i=i.ln(),o.precision=r,o.rounding=e,i.times(.5))):new o(NaN)};p.inverseSine=p.asin=function(){var r,e,t,n,i=this,o=i.constructor;return i.isZero()?new o(i):(e=i.abs().cmp(1),t=o.precision,n=o.rounding,e!==-1?e===0?(r=ke(o,t+4,n).times(.5),r.s=i.s,r):new o(NaN):(o.precision=t+6,o.rounding=1,i=i.div(new o(1).minus(i.times(i)).sqrt().plus(1)).atan(),o.precision=t,o.rounding=n,i.times(2)))};p.inverseTangent=p.atan=function(){var r,e,t,n,i,o,s,a,u,c=this,l=c.constructor,m=l.precision,d=l.rounding;if(c.isFinite()){if(c.isZero())return new l(c);if(c.abs().eq(1)&&m+4<=Ut)return s=ke(l,m+4,d).times(.25),s.s=c.s,s}else{if(!c.s)return new l(NaN);if(m+4<=Ut)return s=ke(l,m+4,d).times(.5),s.s=c.s,s}for(l.precision=a=m+10,l.rounding=1,t=Math.min(28,a/x+2|0),r=t;r;--r)c=c.div(c.times(c).plus(1).sqrt().plus(1));for(B=!1,e=Math.ceil(a/x),n=1,u=c.times(c),s=new l(c),i=c;r!==-1;)if(i=i.times(u),o=s.minus(i.div(n+=2)),i=i.times(u),s=o.plus(i.div(n+=2)),s.d[e]!==void 0)for(r=e;s.d[r]===o.d[r]&&r--;);return t&&(s=s.times(2<<t-1)),B=!0,T(s,l.precision=m,l.rounding=d,!0)};p.isFinite=function(){return!!this.d};p.isInteger=p.isInt=function(){return!!this.d&&se(this.e/x)>this.d.length-2};p.isNaN=function(){return!this.s};p.isNegative=p.isNeg=function(){return this.s<0};p.isPositive=p.isPos=function(){return this.s>0};p.isZero=function(){return!!this.d&&this.d[0]===0};p.lessThan=p.lt=function(r){return this.cmp(r)<0};p.lessThanOrEqualTo=p.lte=function(r){return this.cmp(r)<1};p.logarithm=p.log=function(r){var e,t,n,i,o,s,a,u,c=this,l=c.constructor,m=l.precision,d=l.rounding,f=5;if(r==null)r=new l(10),e=!0;else{if(r=new l(r),t=r.d,r.s<0||!t||!t[0]||r.eq(1))return new l(NaN);e=r.eq(10)}if(t=c.d,c.s<0||!t||!t[0]||c.eq(1))return new l(t&&!t[0]?-1/0:c.s!=1?NaN:t?0:1/0);if(e)if(t.length>1)o=!0;else{for(i=t[0];i%10===0;)i/=10;o=i!==1}if(B=!1,a=m+f,s=ve(c,a),n=e?Bt(l,a+10):ve(r,a),u=v(s,n,a,1),st(u.d,i=m,d))do if(a+=10,s=ve(c,a),n=e?Bt(l,a+10):ve(r,a),u=v(s,n,a,1),!o){+ie(u.d).slice(i+1,i+15)+1==1e14&&(u=T(u,m+1,0));break}while(st(u.d,i+=10,d));return B=!0,T(u,m,d)};p.minus=p.sub=function(r){var e,t,n,i,o,s,a,u,c,l,m,d,f=this,h=f.constructor;if(r=new h(r),!f.d||!r.d)return!f.s||!r.s?r=new h(NaN):f.d?r.s=-r.s:r=new h(r.d||f.s!==r.s?f:NaN),r;if(f.s!=r.s)return r.s=-r.s,f.plus(r);if(c=f.d,d=r.d,a=h.precision,u=h.rounding,!c[0]||!d[0]){if(d[0])r.s=-r.s;else if(c[0])r=new h(f);else return new h(u===3?-0:0);return B?T(r,a,u):r}if(t=se(r.e/x),l=se(f.e/x),c=c.slice(),o=l-t,o){for(m=o<0,m?(e=c,o=-o,s=d.length):(e=d,t=l,s=c.length),n=Math.max(Math.ceil(a/x),s)+2,o>n&&(o=n,e.length=1),e.reverse(),n=o;n--;)e.push(0);e.reverse()}else{for(n=c.length,s=d.length,m=n<s,m&&(s=n),n=0;n<s;n++)if(c[n]!=d[n]){m=c[n]<d[n];break}o=0}for(m&&(e=c,c=d,d=e,r.s=-r.s),s=c.length,n=d.length-s;n>0;--n)c[s++]=0;for(n=d.length;n>o;){if(c[--n]<d[n]){for(i=n;i&&c[--i]===0;)c[i]=Pe-1;--c[i],c[n]+=Pe}c[n]-=d[n]}for(;c[--s]===0;)c.pop();for(;c[0]===0;c.shift())--t;return c[0]?(r.d=c,r.e=Nt(c,t),B?T(r,a,u):r):new h(u===3?-0:0)};p.modulo=p.mod=function(r){var e,t=this,n=t.constructor;return r=new n(r),!t.d||!r.s||r.d&&!r.d[0]?new n(NaN):!r.d||t.d&&!t.d[0]?T(new n(t),n.precision,n.rounding):(B=!1,n.modulo==9?(e=v(t,r.abs(),0,3,1),e.s*=r.s):e=v(t,r,0,n.modulo,1),e=e.times(r),B=!0,t.minus(e))};p.naturalExponential=p.exp=function(){return Wt(this)};p.naturalLogarithm=p.ln=function(){return ve(this)};p.negated=p.neg=function(){var r=new this.constructor(this);return r.s=-r.s,T(r)};p.plus=p.add=function(r){var e,t,n,i,o,s,a,u,c,l,m=this,d=m.constructor;if(r=new d(r),!m.d||!r.d)return!m.s||!r.s?r=new d(NaN):m.d||(r=new d(r.d||m.s===r.s?m:NaN)),r;if(m.s!=r.s)return r.s=-r.s,m.minus(r);if(c=m.d,l=r.d,a=d.precision,u=d.rounding,!c[0]||!l[0])return l[0]||(r=new d(m)),B?T(r,a,u):r;if(o=se(m.e/x),n=se(r.e/x),c=c.slice(),i=o-n,i){for(i<0?(t=c,i=-i,s=l.length):(t=l,n=o,s=c.length),o=Math.ceil(a/x),s=o>s?o+1:s+1,i>s&&(i=s,t.length=1),t.reverse();i--;)t.push(0);t.reverse()}for(s=c.length,i=l.length,s-i<0&&(i=s,t=l,l=c,c=t),e=0;i;)e=(c[--i]=c[i]+l[i]+e)/Pe|0,c[i]%=Pe;for(e&&(c.unshift(e),++n),s=c.length;c[--s]==0;)c.pop();return r.d=c,r.e=Nt(c,n),B?T(r,a,u):r};p.precision=p.sd=function(r){var e,t=this;if(r!==void 0&&r!==!!r&&r!==1&&r!==0)throw Error(Ke+r);return t.d?(e=En(t.d),r&&t.e+1>e&&(e=t.e+1)):e=NaN,e};p.round=function(){var r=this,e=r.constructor;return T(new e(r),r.e+1,e.rounding)};p.sine=p.sin=function(){var r,e,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(r=n.precision,e=n.rounding,n.precision=r+Math.max(t.e,t.sd())+x,n.rounding=1,t=Or(n,Dn(n,t)),n.precision=r,n.rounding=e,T(Ee>2?t.neg():t,r,e,!0)):new n(NaN)};p.squareRoot=p.sqrt=function(){var r,e,t,n,i,o,s=this,a=s.d,u=s.e,c=s.s,l=s.constructor;if(c!==1||!a||!a[0])return new l(!c||c<0&&(!a||a[0])?NaN:a?s:1/0);for(B=!1,c=Math.sqrt(+s),c==0||c==1/0?(e=ie(a),(e.length+u)%2==0&&(e+="0"),c=Math.sqrt(e),u=se((u+1)/2)-(u<0||u%2),c==1/0?e="5e"+u:(e=c.toExponential(),e=e.slice(0,e.indexOf("e")+1)+u),n=new l(e)):n=new l(c.toString()),t=(u=l.precision)+3;;)if(o=n,n=o.plus(v(s,o,t+2,1)).times(.5),ie(o.d).slice(0,t)===(e=ie(n.d)).slice(0,t))if(e=e.slice(t-3,t+1),e=="9999"||!i&&e=="4999"){if(!i&&(T(o,u+1,0),o.times(o).eq(s))){n=o;break}t+=4,i=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(T(n,u+1,1),r=!n.times(n).eq(s));break}return B=!0,T(n,u,l.rounding,r)};p.tangent=p.tan=function(){var r,e,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(r=n.precision,e=n.rounding,n.precision=r+10,n.rounding=1,t=t.sin(),t.s=1,t=v(t,new n(1).minus(t.times(t)).sqrt(),r+10,0),n.precision=r,n.rounding=e,T(Ee==2||Ee==4?t.neg():t,r,e,!0)):new n(NaN)};p.times=p.mul=function(r){var e,t,n,i,o,s,a,u,c,l=this,m=l.constructor,d=l.d,f=(r=new m(r)).d;if(r.s*=l.s,!d||!d[0]||!f||!f[0])return new m(!r.s||d&&!d[0]&&!f||f&&!f[0]&&!d?NaN:!d||!f?r.s/0:r.s*0);for(t=se(l.e/x)+se(r.e/x),u=d.length,c=f.length,u<c&&(o=d,d=f,f=o,s=u,u=c,c=s),o=[],s=u+c,n=s;n--;)o.push(0);for(n=c;--n>=0;){for(e=0,i=u+n;i>n;)a=o[i]+f[n]*d[i-n-1]+e,o[i--]=a%Pe|0,e=a/Pe|0;o[i]=(o[i]+e)%Pe|0}for(;!o[--s];)o.pop();return e?++t:o.shift(),r.d=o,r.e=Nt(o,t),B?T(r,m.precision,m.rounding):r};p.toBinary=function(r,e){return zt(this,2,r,e)};p.toDecimalPlaces=p.toDP=function(r,e){var t=this,n=t.constructor;return t=new n(t),r===void 0?t:(pe(r,0,qe),e===void 0?e=n.rounding:pe(e,0,8),T(t,r+t.e+1,e))};p.toExponential=function(r,e){var t,n=this,i=n.constructor;return r===void 0?t=Se(n,!0):(pe(r,0,qe),e===void 0?e=i.rounding:pe(e,0,8),n=T(new i(n),r+1,e),t=Se(n,!0,r+1)),n.isNeg()&&!n.isZero()?"-"+t:t};p.toFixed=function(r,e){var t,n,i=this,o=i.constructor;return r===void 0?t=Se(i):(pe(r,0,qe),e===void 0?e=o.rounding:pe(e,0,8),n=T(new o(i),r+i.e+1,e),t=Se(n,!1,r+n.e+1)),i.isNeg()&&!i.isZero()?"-"+t:t};p.toFraction=function(r){var e,t,n,i,o,s,a,u,c,l,m,d,f=this,h=f.d,g=f.constructor;if(!h)return new g(f);if(c=t=new g(1),n=u=new g(0),e=new g(n),o=e.e=En(h)-f.e-1,s=o%x,e.d[0]=$(10,s<0?x+s:s),r==null)r=o>0?e:c;else{if(a=new g(r),!a.isInt()||a.lt(c))throw Error(Ke+a);r=a.gt(e)?o>0?e:c:a}for(B=!1,a=new g(ie(h)),l=g.precision,g.precision=o=h.length*x*2;m=v(a,e,0,1,1),i=t.plus(m.times(n)),i.cmp(r)!=1;)t=n,n=i,i=c,c=u.plus(m.times(i)),u=i,i=e,e=a.minus(m.times(i)),a=i;return i=v(r.minus(t),n,0,1,1),u=u.plus(i.times(c)),t=t.plus(i.times(n)),u.s=c.s=f.s,d=v(c,n,o,1).minus(f).abs().cmp(v(u,t,o,1).minus(f).abs())<1?[c,n]:[u,t],g.precision=l,B=!0,d};p.toHexadecimal=p.toHex=function(r,e){return zt(this,16,r,e)};p.toNearest=function(r,e){var t=this,n=t.constructor;if(t=new n(t),r==null){if(!t.d)return t;r=new n(1),e=n.rounding}else{if(r=new n(r),e===void 0?e=n.rounding:pe(e,0,8),!t.d)return r.s?t:r;if(!r.d)return r.s&&(r.s=t.s),r}return r.d[0]?(B=!1,t=v(t,r,0,e,1).times(r),B=!0,T(t)):(r.s=t.s,t=r),t};p.toNumber=function(){return+this};p.toOctal=function(r,e){return zt(this,8,r,e)};p.toPower=p.pow=function(r){var e,t,n,i,o,s,a=this,u=a.constructor,c=+(r=new u(r));if(!a.d||!r.d||!a.d[0]||!r.d[0])return new u($(+a,c));if(a=new u(a),a.eq(1))return a;if(n=u.precision,o=u.rounding,r.eq(1))return T(a,n,o);if(e=se(r.e/x),e>=r.d.length-1&&(t=c<0?-c:c)<=Lr)return i=Rn(u,a,t,n),r.s<0?new u(1).div(i):T(i,n,o);if(s=a.s,s<0){if(e<r.d.length-1)return new u(NaN);if((r.d[e]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return t=$(+a,c),e=t==0||!isFinite(t)?se(c*(Math.log("0."+ie(a.d))/Math.LN10+a.e+1)):new u(t+"").e,e>u.maxE+1||e<u.minE-1?new u(e>0?s/0:0):(B=!1,u.rounding=a.s=1,t=Math.min(12,(e+"").length),i=Wt(r.times(ve(a,n+t)),n),i.d&&(i=T(i,n+5,1),st(i.d,n,o)&&(e=n+10,i=T(Wt(r.times(ve(a,e+t)),e),e+5,1),+ie(i.d).slice(n+1,n+15)+1==1e14&&(i=T(i,n+1,0)))),i.s=s,B=!0,u.rounding=o,T(i,n,o))};p.toPrecision=function(r,e){var t,n=this,i=n.constructor;return r===void 0?t=Se(n,n.e<=i.toExpNeg||n.e>=i.toExpPos):(pe(r,1,qe),e===void 0?e=i.rounding:pe(e,0,8),n=T(new i(n),r,e),t=Se(n,r<=n.e||n.e<=i.toExpNeg,r)),n.isNeg()&&!n.isZero()?"-"+t:t};p.toSignificantDigits=p.toSD=function(r,e){var t=this,n=t.constructor;return r===void 0?(r=n.precision,e=n.rounding):(pe(r,1,qe),e===void 0?e=n.rounding:pe(e,0,8)),T(new n(t),r,e)};p.toString=function(){var r=this,e=r.constructor,t=Se(r,r.e<=e.toExpNeg||r.e>=e.toExpPos);return r.isNeg()&&!r.isZero()?"-"+t:t};p.truncated=p.trunc=function(){return T(new this.constructor(this),this.e+1,1)};p.valueOf=p.toJSON=function(){var r=this,e=r.constructor,t=Se(r,r.e<=e.toExpNeg||r.e>=e.toExpPos);return r.isNeg()?"-"+t:t};function ie(r){var e,t,n,i=r.length-1,o="",s=r[0];if(i>0){for(o+=s,e=1;e<i;e++)n=r[e]+"",t=x-n.length,t&&(o+=_e(t)),o+=n;s=r[e],n=s+"",t=x-n.length,t&&(o+=_e(t))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function pe(r,e,t){if(r!==~~r||r<e||r>t)throw Error(Ke+r)}function st(r,e,t,n){var i,o,s,a;for(o=r[0];o>=10;o/=10)--e;return--e<0?(e+=x,i=0):(i=Math.ceil((e+1)/x),e%=x),o=$(10,x-e),a=r[i]%o|0,n==null?e<3?(e==0?a=a/100|0:e==1&&(a=a/10|0),s=t<4&&a==99999||t>3&&a==49999||a==5e4||a==0):s=(t<4&&a+1==o||t>3&&a+1==o/2)&&(r[i+1]/o/100|0)==$(10,e-2)-1||(a==o/2||a==0)&&(r[i+1]/o/100|0)==0:e<4?(e==0?a=a/1e3|0:e==1?a=a/100|0:e==2&&(a=a/10|0),s=(n||t<4)&&a==9999||!n&&t>3&&a==4999):s=((n||t<4)&&a+1==o||!n&&t>3&&a+1==o/2)&&(r[i+1]/o/1e3|0)==$(10,e-3)-1,s}function xt(r,e,t){for(var n,i=[0],o,s=0,a=r.length;s<a;){for(o=i.length;o--;)i[o]*=e;for(i[0]+=Gt.indexOf(r.charAt(s++)),n=0;n<i.length;n++)i[n]>t-1&&(i[n+1]===void 0&&(i[n+1]=0),i[n+1]+=i[n]/t|0,i[n]%=t)}return i.reverse()}function Rr(r,e){var t,n,i;if(e.isZero())return e;n=e.d.length,n<32?(t=Math.ceil(n/3),i=(1/St(4,t)).toString()):(t=16,i="2.3283064365386962890625e-10"),r.precision+=t,e=Je(r,1,e.times(i),new r(1));for(var o=t;o--;){var s=e.times(e);e=s.times(s).minus(s).times(8).plus(1)}return r.precision-=t,e}var v=function(){function r(n,i,o){var s,a=0,u=n.length;for(n=n.slice();u--;)s=n[u]*i+a,n[u]=s%o|0,a=s/o|0;return a&&n.unshift(a),n}function e(n,i,o,s){var a,u;if(o!=s)u=o>s?1:-1;else for(a=u=0;a<o;a++)if(n[a]!=i[a]){u=n[a]>i[a]?1:-1;break}return u}function t(n,i,o,s){for(var a=0;o--;)n[o]-=a,a=n[o]<i[o]?1:0,n[o]=a*s+n[o]-i[o];for(;!n[0]&&n.length>1;)n.shift()}return function(n,i,o,s,a,u){var c,l,m,d,f,h,g,b,y,R,P,w,H,M,Y,G,X,le,V,Ne,ge=n.constructor,Me=n.s==i.s?1:-1,Q=n.d,D=i.d;if(!Q||!Q[0]||!D||!D[0])return new ge(!n.s||!i.s||(Q?D&&Q[0]==D[0]:!D)?NaN:Q&&Q[0]==0||!D?Me*0:Me/0);for(u?(f=1,l=n.e-i.e):(u=Pe,f=x,l=se(n.e/f)-se(i.e/f)),V=D.length,X=Q.length,y=new ge(Me),R=y.d=[],m=0;D[m]==(Q[m]||0);m++);if(D[m]>(Q[m]||0)&&l--,o==null?(M=o=ge.precision,s=ge.rounding):a?M=o+(n.e-i.e)+1:M=o,M<0)R.push(1),h=!0;else{if(M=M/f+2|0,m=0,V==1){for(d=0,D=D[0],M++;(m<X||d)&&M--;m++)Y=d*u+(Q[m]||0),R[m]=Y/D|0,d=Y%D|0;h=d||m<X}else{for(d=u/(D[0]+1)|0,d>1&&(D=r(D,d,u),Q=r(Q,d,u),V=D.length,X=Q.length),G=V,P=Q.slice(0,V),w=P.length;w<V;)P[w++]=0;Ne=D.slice(),Ne.unshift(0),le=D[0],D[1]>=u/2&&++le;do d=0,c=e(D,P,V,w),c<0?(H=P[0],V!=w&&(H=H*u+(P[1]||0)),d=H/le|0,d>1?(d>=u&&(d=u-1),g=r(D,d,u),b=g.length,w=P.length,c=e(g,P,b,w),c==1&&(d--,t(g,V<b?Ne:D,b,u))):(d==0&&(c=d=1),g=D.slice()),b=g.length,b<w&&g.unshift(0),t(P,g,w,u),c==-1&&(w=P.length,c=e(D,P,V,w),c<1&&(d++,t(P,V<w?Ne:D,w,u))),w=P.length):c===0&&(d++,P=[0]),R[m++]=d,c&&P[0]?P[w++]=Q[G]||0:(P=[Q[G]],w=1);while((G++<X||P[0]!==void 0)&&M--);h=P[0]!==void 0}R[0]||R.shift()}if(f==1)y.e=l,In=h;else{for(m=1,d=R[0];d>=10;d/=10)m++;y.e=m+l*f-1,T(y,a?o+y.e+1:o,s,h)}return y}}();function T(r,e,t,n){var i,o,s,a,u,c,l,m,d,f=r.constructor;e:if(e!=null){if(m=r.d,!m)return r;for(i=1,a=m[0];a>=10;a/=10)i++;if(o=e-i,o<0)o+=x,s=e,l=m[d=0],u=l/$(10,i-s-1)%10|0;else if(d=Math.ceil((o+1)/x),a=m.length,d>=a)if(n){for(;a++<=d;)m.push(0);l=u=0,i=1,o%=x,s=o-x+1}else break e;else{for(l=a=m[d],i=1;a>=10;a/=10)i++;o%=x,s=o-x+i,u=s<0?0:l/$(10,i-s-1)%10|0}if(n=n||e<0||m[d+1]!==void 0||(s<0?l:l%$(10,i-s-1)),c=t<4?(u||n)&&(t==0||t==(r.s<0?3:2)):u>5||u==5&&(t==4||n||t==6&&(o>0?s>0?l/$(10,i-s):0:m[d-1])%10&1||t==(r.s<0?8:7)),e<1||!m[0])return m.length=0,c?(e-=r.e+1,m[0]=$(10,(x-e%x)%x),r.e=-e||0):m[0]=r.e=0,r;if(o==0?(m.length=d,a=1,d--):(m.length=d+1,a=$(10,x-o),m[d]=s>0?(l/$(10,i-s)%$(10,s)|0)*a:0),c)for(;;)if(d==0){for(o=1,s=m[0];s>=10;s/=10)o++;for(s=m[0]+=a,a=1;s>=10;s/=10)a++;o!=a&&(r.e++,m[0]==Pe&&(m[0]=1));break}else{if(m[d]+=a,m[d]!=Pe)break;m[d--]=0,a=1}for(o=m.length;m[--o]===0;)m.pop()}return B&&(r.e>f.maxE?(r.d=null,r.e=NaN):r.e<f.minE&&(r.e=0,r.d=[0])),r}function Se(r,e,t){if(!r.isFinite())return On(r);var n,i=r.e,o=ie(r.d),s=o.length;return e?(t&&(n=t-s)>0?o=o.charAt(0)+"."+o.slice(1)+_e(n):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(r.e<0?"e":"e+")+r.e):i<0?(o="0."+_e(-i-1)+o,t&&(n=t-s)>0&&(o+=_e(n))):i>=s?(o+=_e(i+1-s),t&&(n=t-i-1)>0&&(o=o+"."+_e(n))):((n=i+1)<s&&(o=o.slice(0,n)+"."+o.slice(n)),t&&(n=t-s)>0&&(i+1===s&&(o+="."),o+=_e(n))),o}function Nt(r,e){var t=r[0];for(e*=x;t>=10;t/=10)e++;return e}function Bt(r,e,t){if(e>Er)throw B=!0,t&&(r.precision=t),Error(Nn);return T(new r(kt),e,1,!0)}function ke(r,e,t){if(e>Ut)throw Error(Nn);return T(new r(Pt),e,t,!0)}function En(r){var e=r.length-1,t=e*x+1;if(e=r[e],e){for(;e%10==0;e/=10)t--;for(e=r[0];e>=10;e/=10)t++}return t}function _e(r){for(var e="";r--;)e+="0";return e}function Rn(r,e,t,n){var i,o=new r(1),s=Math.ceil(n/x+4);for(B=!1;;){if(t%2&&(o=o.times(e),Pn(o.d,s)&&(i=!0)),t=se(t/2),t===0){t=o.d.length-1,i&&o.d[t]===0&&++o.d[t];break}e=e.times(e),Pn(e.d,s)}return B=!0,o}function kn(r){return r.d[r.d.length-1]&1}function Fn(r,e,t){for(var n,i=new r(e[0]),o=0;++o<e.length;)if(n=new r(e[o]),n.s)i[t](n)&&(i=n);else{i=n;break}return i}function Wt(r,e){var t,n,i,o,s,a,u,c=0,l=0,m=0,d=r.constructor,f=d.rounding,h=d.precision;if(!r.d||!r.d[0]||r.e>17)return new d(r.d?r.d[0]?r.s<0?0:1/0:1:r.s?r.s<0?0:r:0/0);for(e==null?(B=!1,u=h):u=e,a=new d(.03125);r.e>-2;)r=r.times(a),m+=5;for(n=Math.log($(2,m))/Math.LN10*2+5|0,u+=n,t=o=s=new d(1),d.precision=u;;){if(o=T(o.times(r),u,1),t=t.times(++l),a=s.plus(v(o,t,u,1)),ie(a.d).slice(0,u)===ie(s.d).slice(0,u)){for(i=m;i--;)s=T(s.times(s),u,1);if(e==null)if(c<3&&st(s.d,u-n,f,c))d.precision=u+=10,t=o=a=new d(1),l=0,c++;else return T(s,d.precision=h,f,B=!0);else return d.precision=h,s}s=a}}function ve(r,e){var t,n,i,o,s,a,u,c,l,m,d,f=1,h=10,g=r,b=g.d,y=g.constructor,R=y.rounding,P=y.precision;if(g.s<0||!b||!b[0]||!g.e&&b[0]==1&&b.length==1)return new y(b&&!b[0]?-1/0:g.s!=1?NaN:b?0:g);if(e==null?(B=!1,l=P):l=e,y.precision=l+=h,t=ie(b),n=t.charAt(0),Math.abs(o=g.e)<15e14){for(;n<7&&n!=1||n==1&&t.charAt(1)>3;)g=g.times(r),t=ie(g.d),n=t.charAt(0),f++;o=g.e,n>1?(g=new y("0."+t),o++):g=new y(n+"."+t.slice(1))}else return c=Bt(y,l+2,P).times(o+""),g=ve(new y(n+"."+t.slice(1)),l-h).plus(c),y.precision=P,e==null?T(g,P,R,B=!0):g;for(m=g,u=s=g=v(g.minus(1),g.plus(1),l,1),d=T(g.times(g),l,1),i=3;;){if(s=T(s.times(d),l,1),c=u.plus(v(s,new y(i),l,1)),ie(c.d).slice(0,l)===ie(u.d).slice(0,l))if(u=u.times(2),o!==0&&(u=u.plus(Bt(y,l+2,P).times(o+""))),u=v(u,new y(f),l,1),e==null)if(st(u.d,l-h,R,a))y.precision=l+=h,c=s=g=v(m.minus(1),m.plus(1),l,1),d=T(g.times(g),l,1),i=a=1;else return T(u,y.precision=P,R,B=!0);else return y.precision=P,u;u=c,i+=2}}function On(r){return String(r.s*r.s/0)}function Xt(r,e){var t,n,i;for((t=e.indexOf("."))>-1&&(e=e.replace(".","")),(n=e.search(/e/i))>0?(t<0&&(t=n),t+=+e.slice(n+1),e=e.substring(0,n)):t<0&&(t=e.length),n=0;e.charCodeAt(n)===48;n++);for(i=e.length;e.charCodeAt(i-1)===48;--i);if(e=e.slice(n,i),e){if(i-=n,r.e=t=t-n-1,r.d=[],n=(t+1)%x,t<0&&(n+=x),n<i){for(n&&r.d.push(+e.slice(0,n)),i-=x;n<i;)r.d.push(+e.slice(n,n+=x));e=e.slice(n),n=x-e.length}else n-=i;for(;n--;)e+="0";r.d.push(+e),B&&(r.e>r.constructor.maxE?(r.d=null,r.e=NaN):r.e<r.constructor.minE&&(r.e=0,r.d=[0]))}else r.e=0,r.d=[0];return r}function Fr(r,e){var t,n,i,o,s,a,u,c,l;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),Ln.test(e))return Xt(r,e)}else if(e==="Infinity"||e==="NaN")return+e||(r.s=NaN),r.e=NaN,r.d=null,r;if(Sr.test(e))t=16,e=e.toLowerCase();else if(Nr.test(e))t=2;else if(Cr.test(e))t=8;else throw Error(Ke+e);for(o=e.search(/p/i),o>0?(u=+e.slice(o+1),e=e.substring(2,o)):e=e.slice(2),o=e.indexOf("."),s=o>=0,n=r.constructor,s&&(e=e.replace(".",""),a=e.length,o=a-o,i=Rn(n,new n(t),o,o*2)),c=xt(e,t,Pe),l=c.length-1,o=l;c[o]===0;--o)c.pop();return o<0?new n(r.s*0):(r.e=Nt(c,l),r.d=c,B=!1,s&&(r=v(r,i,a*4)),u&&(r=r.times(Math.abs(u)<54?$(2,u):at.pow(2,u))),B=!0,r)}function Or(r,e){var t,n=e.d.length;if(n<3)return e.isZero()?e:Je(r,2,e,e);t=1.4*Math.sqrt(n),t=t>16?16:t|0,e=e.times(1/St(5,t)),e=Je(r,2,e,e);for(var i,o=new r(5),s=new r(16),a=new r(20);t--;)i=e.times(e),e=e.times(o.plus(i.times(s.times(i).minus(a))));return e}function Je(r,e,t,n,i){var o,s,a,u,c=1,l=r.precision,m=Math.ceil(l/x);for(B=!1,u=t.times(t),a=new r(n);;){if(s=v(a.times(u),new r(e++*e++),l,1),a=i?n.plus(s):n.minus(s),n=v(s.times(u),new r(e++*e++),l,1),s=a.plus(n),s.d[m]!==void 0){for(o=m;s.d[o]===a.d[o]&&o--;);if(o==-1)break}o=a,a=n,n=s,s=o,c++}return B=!0,s.d.length=m+1,s}function St(r,e){for(var t=r;--e;)t*=r;return t}function Dn(r,e){var t,n=e.s<0,i=ke(r,r.precision,1),o=i.times(.5);if(e=e.abs(),e.lte(o))return Ee=n?4:1,e;if(t=e.divToInt(i),t.isZero())Ee=n?3:2;else{if(e=e.minus(t.times(i)),e.lte(o))return Ee=kn(t)?n?2:3:n?4:1,e;Ee=kn(t)?n?1:4:n?3:2}return e.minus(i).abs()}function zt(r,e,t,n){var i,o,s,a,u,c,l,m,d,f=r.constructor,h=t!==void 0;if(h?(pe(t,1,qe),n===void 0?n=f.rounding:pe(n,0,8)):(t=f.precision,n=f.rounding),!r.isFinite())l=On(r);else{for(l=Se(r),s=l.indexOf("."),h?(i=2,e==16?t=t*4-3:e==8&&(t=t*3-2)):i=e,s>=0&&(l=l.replace(".",""),d=new f(1),d.e=l.length-s,d.d=xt(Se(d),10,i),d.e=d.d.length),m=xt(l,10,i),o=u=m.length;m[--u]==0;)m.pop();if(!m[0])l=h?"0p+0":"0";else{if(s<0?o--:(r=new f(r),r.d=m,r.e=o,r=v(r,d,t,n,0,i),m=r.d,o=r.e,c=In),s=m[t],a=i/2,c=c||m[t+1]!==void 0,c=n<4?(s!==void 0||c)&&(n===0||n===(r.s<0?3:2)):s>a||s===a&&(n===4||c||n===6&&m[t-1]&1||n===(r.s<0?8:7)),m.length=t,c)for(;++m[--t]>i-1;)m[t]=0,t||(++o,m.unshift(1));for(u=m.length;!m[u-1];--u);for(s=0,l="";s<u;s++)l+=Gt.charAt(m[s]);if(h){if(u>1)if(e==16||e==8){for(s=e==16?4:3,--u;u%s;u++)l+="0";for(m=xt(l,i,e),u=m.length;!m[u-1];--u);for(s=1,l="1.";s<u;s++)l+=Gt.charAt(m[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)l="0"+l;l="0."+l}else if(++o>u)for(o-=u;o--;)l+="0";else o<u&&(l=l.slice(0,o)+"."+l.slice(o))}l=(e==16?"0x":e==2?"0b":e==8?"0o":"")+l}return r.s<0?"-"+l:l}function Pn(r,e){if(r.length>e)return r.length=e,!0}function Dr(r){return new this(r).abs()}function Mr(r){return new this(r).acos()}function _r(r){return new this(r).acosh()}function vr(r,e){return new this(r).plus(e)}function Kr(r){return new this(r).asin()}function qr(r){return new this(r).asinh()}function Gr(r){return new this(r).atan()}function Vr(r){return new this(r).atanh()}function Ur(r,e){r=new this(r),e=new this(e);var t,n=this.precision,i=this.rounding,o=n+4;return!r.s||!e.s?t=new this(NaN):!r.d&&!e.d?(t=ke(this,o,1).times(e.s>0?.25:.75),t.s=r.s):!e.d||r.isZero()?(t=e.s<0?ke(this,n,i):new this(0),t.s=r.s):!r.d||e.isZero()?(t=ke(this,o,1).times(.5),t.s=r.s):e.s<0?(this.precision=o,this.rounding=1,t=this.atan(v(r,e,o,1)),e=ke(this,o,1),this.precision=n,this.rounding=i,t=r.s<0?t.minus(e):t.plus(e)):t=this.atan(v(r,e,o,1)),t}function Wr(r){return new this(r).cbrt()}function Xr(r){return T(r=new this(r),r.e+1,2)}function zr(r,e,t){return new this(r).clamp(e,t)}function Hr(r){if(!r||typeof r!="object")throw Error(It+"Object expected");var e,t,n,i=r.defaults===!0,o=["precision",1,qe,"rounding",0,8,"toExpNeg",-Qe,0,"toExpPos",0,Qe,"maxE",0,Qe,"minE",-Qe,0,"modulo",0,9];for(e=0;e<o.length;e+=3)if(t=o[e],i&&(this[t]=Vt[t]),(n=r[t])!==void 0)if(se(n)===n&&n>=o[e+1]&&n<=o[e+2])this[t]=n;else throw Error(Ke+t+": "+n);if(t="crypto",i&&(this[t]=Vt[t]),(n=r[t])!==void 0)if(n===!0||n===!1||n===0||n===1)if(n)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[t]=!0;else throw Error(Sn);else this[t]=!1;else throw Error(Ke+t+": "+n);return this}function Yr(r){return new this(r).cos()}function Zr(r){return new this(r).cosh()}function Mn(r){var e,t,n;function i(o){var s,a,u,c=this;if(!(c instanceof i))return new i(o);if(c.constructor=i,Bn(o)){c.s=o.s,B?!o.d||o.e>i.maxE?(c.e=NaN,c.d=null):o.e<i.minE?(c.e=0,c.d=[0]):(c.e=o.e,c.d=o.d.slice()):(c.e=o.e,c.d=o.d?o.d.slice():o.d);return}if(u=typeof o,u==="number"){if(o===0){c.s=1/o<0?-1:1,c.e=0,c.d=[0];return}if(o<0?(o=-o,c.s=-1):c.s=1,o===~~o&&o<1e7){for(s=0,a=o;a>=10;a/=10)s++;B?s>i.maxE?(c.e=NaN,c.d=null):s<i.minE?(c.e=0,c.d=[0]):(c.e=s,c.d=[o]):(c.e=s,c.d=[o]);return}else if(o*0!==0){o||(c.s=NaN),c.e=NaN,c.d=null;return}return Xt(c,o.toString())}else if(u!=="string")throw Error(Ke+o);return(a=o.charCodeAt(0))===45?(o=o.slice(1),c.s=-1):(a===43&&(o=o.slice(1)),c.s=1),Ln.test(o)?Xt(c,o):Fr(c,o)}if(i.prototype=p,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=Hr,i.clone=Mn,i.isDecimal=Bn,i.abs=Dr,i.acos=Mr,i.acosh=_r,i.add=vr,i.asin=Kr,i.asinh=qr,i.atan=Gr,i.atanh=Vr,i.atan2=Ur,i.cbrt=Wr,i.ceil=Xr,i.clamp=zr,i.cos=Yr,i.cosh=Zr,i.div=jr,i.exp=Qr,i.floor=Jr,i.hypot=$r,i.ln=ei,i.log=ti,i.log10=ri,i.log2=ni,i.max=ii,i.min=oi,i.mod=si,i.mul=ai,i.pow=ui,i.random=ci,i.round=li,i.sign=mi,i.sin=di,i.sinh=fi,i.sqrt=pi,i.sub=gi,i.sum=hi,i.tan=bi,i.tanh=yi,i.trunc=wi,r===void 0&&(r={}),r&&r.defaults!==!0)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<n.length;)r.hasOwnProperty(t=n[e++])||(r[t]=this[t]);return i.config(r),i}function jr(r,e){return new this(r).div(e)}function Qr(r){return new this(r).exp()}function Jr(r){return T(r=new this(r),r.e+1,3)}function $r(){var r,e,t=new this(0);for(B=!1,r=0;r<arguments.length;)if(e=new this(arguments[r++]),e.d)t.d&&(t=t.plus(e.times(e)));else{if(e.s)return B=!0,new this(1/0);t=e}return B=!0,t.sqrt()}function Bn(r){return r instanceof at||r&&r.toStringTag===Cn||!1}function ei(r){return new this(r).ln()}function ti(r,e){return new this(r).log(e)}function ni(r){return new this(r).log(2)}function ri(r){return new this(r).log(10)}function ii(){return Fn(this,arguments,"lt")}function oi(){return Fn(this,arguments,"gt")}function si(r,e){return new this(r).mod(e)}function ai(r,e){return new this(r).mul(e)}function ui(r,e){return new this(r).pow(e)}function ci(r){var e,t,n,i,o=0,s=new this(1),a=[];if(r===void 0?r=this.precision:pe(r,1,qe),n=Math.ceil(r/x),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(n));o<n;)i=e[o],i>=429e7?e[o]=crypto.getRandomValues(new Uint32Array(1))[0]:a[o++]=i%1e7;else if(crypto.randomBytes){for(e=crypto.randomBytes(n*=4);o<n;)i=e[o]+(e[o+1]<<8)+(e[o+2]<<16)+((e[o+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(e,o):(a.push(i%1e7),o+=4);o=n/4}else throw Error(Sn);else for(;o<n;)a[o++]=Math.random()*1e7|0;for(n=a[--o],r%=x,n&&r&&(i=$(10,x-r),a[o]=(n/i|0)*i);a[o]===0;o--)a.pop();if(o<0)t=0,a=[0];else{for(t=-1;a[0]===0;t-=x)a.shift();for(n=1,i=a[0];i>=10;i/=10)n++;n<x&&(t-=x-n)}return s.e=t,s.d=a,s}function li(r){return T(r=new this(r),r.e+1,this.rounding)}function mi(r){return r=new this(r),r.d?r.d[0]?r.s:0*r.s:r.s||NaN}function di(r){return new this(r).sin()}function fi(r){return new this(r).sinh()}function pi(r){return new this(r).sqrt()}function gi(r,e){return new this(r).sub(e)}function hi(){var r=0,e=arguments,t=new this(e[r]);for(B=!1;t.s&&++r<e.length;)t=t.plus(e[r]);return B=!0,T(t,this.precision,this.rounding)}function bi(r){return new this(r).tan()}function yi(r){return new this(r).tanh()}function wi(r){return T(r=new this(r),r.e+1,1)}p[Symbol.for("nodejs.util.inspect.custom")]=p.toString;p[Symbol.toStringTag]="Decimal";var at=p.constructor=Mn(Vt);kt=new at(kt);Pt=new at(Pt);var k=at;var Be=J(require("bn.js")),j=new Be.default(0),Ce=new Be.default(1),Re=new Be.default(-1),he=new Be.default(1).shln(64),Ct=new Be.default(1).shln(128),Ht=he.sub(Ce),ut=64,_n=Ct.subn(1),ae=-443636,me=-ae,$e=new Be.default("4295048016"),et=new Be.default("79226673521066979257578248091"),vn=16,Kn="59543866431248",qn="184467440737095516",Gn="15793534762490258745",Lt=new Be.default(10).pow(new Be.default(6));var Zi=new Be.default("18446744073700000000");var ct=require("lodash"),Zt=J(require("dayjs")),Un=J(require("dayjs/plugin/utc"));Zt.default.extend(Un.default);var Yt=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(0,Zt.default)().utc().format("YYYY/MM/DD HH:mm:ss UTC")}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 t=e.map(n=>typeof n=="object"?JSON.stringify(n):n).join(", ");throw new Error(t)}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}},Vn={},Ti={};function be(r){let e=(0,ct.get)(Vn,r);if(!e){let t=(0,ct.get)(Ti,r);e=new Yt({name:r,logLevel:t}),(0,ct.set)(Vn,r,e)}return e}var Ci=require("@solana/web3.js"),Li=J(require("bn.js"));var nr=J(require("big.js")),ft=J(require("bn.js"));var ue=J(require("bn.js"));var Ft=require("@solana/web3.js");var Wn=require("@solana/spl-token"),_=require("@solana/web3.js");function jt({pubkey:r,isSigner:e=!1,isWritable:t=!0}){return{pubkey:r,isWritable:t,isSigner:e}}var $i=[jt({pubkey:Wn.TOKEN_PROGRAM_ID,isWritable:!1}),jt({pubkey:_.SystemProgram.programId,isWritable:!1}),jt({pubkey:_.SYSVAR_RENT_PUBKEY,isWritable:!1})];function Qt({publicKey:r,transformSol:e}){let t=Xn(r.toString());if(t instanceof _.PublicKey)return e&&t.equals(Xe)?Et:t;if(e&&t.toString()===Xe.toBase58())return Et;if(typeof t=="string"){if(t===_.PublicKey.default.toBase58())return _.PublicKey.default;try{return new _.PublicKey(t)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function Xn(r){try{return new _.PublicKey(r)}catch{return r}}var eo=new _.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),to=new _.PublicKey("SysvarRent111111111111111111111111111111111"),no=new _.PublicKey("SysvarC1ock11111111111111111111111111111111"),Ai=new _.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),ro=new _.PublicKey("Sysvar1nstructions1111111111111111111111111"),io=new _.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),oo=new _.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),so=new _.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),ao=new _.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),uo=new _.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),co=new _.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),lo=new _.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),mo=new _.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),fo=new _.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),po=new _.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),go=new _.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),Et=new _.PublicKey("So11111111111111111111111111111111111111112"),Xe=_.PublicKey.default;function Jt(r){return Qt({publicKey:r,transformSol:!0})}var zn=require("@solana/web3.js"),$t=require("@solana/spl-token"),Rt={chainId:101,address:zn.PublicKey.default.toBase58(),programId:$t.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},ze={chainId:101,address:"So11111111111111111111111111111111111111112",programId:$t.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}};var en=class{constructor({mint:e,decimals:t,symbol:n,name:i,skipMint:o=!1,isToken2022:s=!1}){if(e===Xe.toBase58()||e instanceof Ft.PublicKey&&Xe.equals(e)){this.decimals=ze.decimals,this.symbol=ze.symbol,this.name=ze.name,this.mint=new Ft.PublicKey(ze.address),this.isToken2022=!1;return}this.decimals=t,this.symbol=n||e.toString().substring(0,6),this.name=i||e.toString().substring(0,6),this.mint=o?Ft.PublicKey.default:Qt({publicKey:e}),this.isToken2022=s}equals(e){return this===e?!0:this.mint.equals(e.mint)}},Fe=en;Fe.WSOL=new en(ne(Z({},ze),{mint:ze.address}));var mt=J(require("big.js")),Yn=J(require("bn.js")),Zn=J(require("decimal.js-light"));var Hn=J(require("toformat")),xi=Hn.default,lt=xi;var Ot=be("module/fraction"),tn=lt(mt.default),dt=lt(Zn.default),ki={[0]:dt.ROUND_DOWN,[1]:dt.ROUND_HALF_UP,[2]:dt.ROUND_UP},Pi={[0]:mt.default.roundDown,[1]:mt.default.roundHalfUp,[2]:mt.default.roundUp},E=class{constructor(e,t=new Yn.default(1)){this.numerator=we(e),this.denominator=we(t)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new E(this.denominator,this.numerator)}add(e){let t=e instanceof E?e:new E(we(e));return this.denominator.eq(t.denominator)?new E(this.numerator.add(t.numerator),this.denominator):new E(this.numerator.mul(t.denominator).add(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}sub(e){let t=e instanceof E?e:new E(we(e));return this.denominator.eq(t.denominator)?new E(this.numerator.sub(t.numerator),this.denominator):new E(this.numerator.mul(t.denominator).sub(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}mul(e){let t=e instanceof E?e:new E(we(e));return new E(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof E?e:new E(we(e));return new E(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},n=1){Number.isInteger(e)||Ot.logWithError(`${e} is not an integer.`),e<=0&&Ot.logWithError(`${e} is not positive.`),dt.set({precision:e+1,rounding:ki[n]});let i=new dt(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return i.toFormat(i.decimalPlaces(),t)}toFixed(e,t={groupSeparator:""},n=1){return Number.isInteger(e)||Ot.logWithError(`${e} is not an integer.`),e<0&&Ot.logWithError(`${e} is negative.`),tn.DP=e,tn.RM=Pi[n]||1,new tn(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};var Ii=be("Raydium_price"),Te=class extends E{constructor(t){let{baseToken:n,quoteToken:i,numerator:o,denominator:s}=t;super(o,s);this.baseToken=n,this.quoteToken=i,this.scalar=new E(nn(n.decimals),nn(i.decimals))}get raw(){return new E(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new Te({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numerator,numerator:this.denominator})}mul(t){this.quoteToken!==t.baseToken&&Ii.logWithError("mul token not equals");let n=super.mul(t);return new Te({baseToken:this.baseToken,quoteToken:t.quoteToken,denominator:n.denominator,numerator:n.numerator})}toSignificant(t=this.quoteToken.decimals,n,i){return this.adjusted.toSignificant(t,n,i)}toFixed(t=this.quoteToken.decimals,n,i){return this.adjusted.toFixed(t,n,i)}};var rn=class{constructor({decimals:e,symbol:t="UNKNOWN",name:n="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=n}equals(e){return this===e}},Dt=rn;Dt.SOL=new rn(Rt);var Qn=J(require("bn.js"));var jn=new E(new Qn.default(100)),Ge=class extends E{toSignificant(e=5,t,n){return this.mul(jn).toSignificant(e,t,n)}toFixed(e=2,t,n){return this.mul(jn).toFixed(e,t,n)}};function tt(r){if(r instanceof Ge)return new E(r.numerator,r.denominator);if(r instanceof Te)return r.adjusted;if(r instanceof oe)try{return tt(r.toExact())}catch{return new E(Mt)}if(r instanceof E)return r;let e=String(r),t=on(e);return new E(t.numerator,t.denominator)}function Jn(r,e){if(r==null||e==null)return!1;let t=tt(r),n=tt(e);return t.sub(n).numerator,t.sub(n).numerator.lt(Mt)}function $n(r,e){if(r==null||e==null)return!1;let t=tt(r),n=tt(e);return t.sub(n).numerator.gt(Mt)}var Mt=new ue.default(0),ts=new ue.default(1),ns=new ue.default(2),rs=new ue.default(3),is=new ue.default(5),sn=new ue.default(10),os=new ue.default(100),ss=new ue.default(1e3),as=new ue.default(1e4),er=9007199254740991;function we(r){let e=be("Raydium_parseBigNumberish");if(r instanceof ue.default)return r;if(typeof r=="string"){if(r.match(/^-?[0-9]+$/))return new ue.default(r);e.logWithError(`invalid BigNumberish string: ${r}`)}return typeof r=="number"?(r%1&&e.logWithError(`BigNumberish number underflow: ${r}`),(r>=er||r<=-er)&&e.logWithError(`BigNumberish number overflow: ${r}`),new ue.default(String(r))):typeof r=="bigint"?new ue.default(r.toString()):(e.error(`invalid BigNumberish value: ${r}`),new ue.default(0))}function nn(r){return sn.pow(we(r))}function on(r){var a;if(r===void 0)return{denominator:"1",numerator:"0"};if(r instanceof ue.default)return{numerator:r.toString(),denominator:"1"};if(r instanceof E)return{denominator:r.denominator.toString(),numerator:r.numerator.toString()};let e=String(r),[,t="",n="",i=""]=(a=e.replace(",","").match(/(-?)(\d*)\.?(\d*)/))!=null?a:[],o="1"+"0".repeat(i.length),s=t+(n==="0"?"":n)+i||"0";return{denominator:o,numerator:s,sign:t,int:n,dec:i}}function _t(r){if(r==null)return;let{numerator:e,denominator:t}=on(r.toString());return new E(e,t)}var Ni=be("Raydium_amount"),tr=lt(nr.default);function Si(r,e){let t="0",n="0";if(r.includes(".")){let i=r.split(".");i.length===2?([t,n]=i,n=n.padEnd(e,"0")):Ni.logWithError(`invalid number string, num: ${r}`)}else t=r;return[t,n.slice(0,e)||n]}var oe=class extends E{constructor(t,n,i=!0,o){let s=new ft.default(0),a=sn.pow(new ft.default(t.decimals));if(i)s=we(n);else{let u=new ft.default(0),c=new ft.default(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[l,m]=Si(n.toString(),t.decimals);u=we(l),c=we(m)}u=u.mul(a),s=u.add(c)}super(s,a);this.logger=be(o||"TokenAmount"),this.token=t}get raw(){return this.numerator}isZero(){return this.raw.isZero()}gt(t){return this.token.equals(t.token)||this.logger.logWithError("gt token not equals"),this.raw.gt(t.raw)}lt(t){return this.token.equals(t.token)||this.logger.logWithError("lt token not equals"),this.raw.lt(t.raw)}add(t){return this.token.equals(t.token)||this.logger.logWithError("add token not equals"),new oe(this.token,this.raw.add(t.raw))}subtract(t){return this.token.equals(t.token)||this.logger.logWithError("sub token not equals"),new oe(this.token,this.raw.sub(t.raw))}toSignificant(t=this.token.decimals,n,i=0){return super.toSignificant(t,n,i)}toFixed(t=this.token.decimals,n,i=0){return t>this.token.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(t,n,i)}toExact(t={groupSeparator:""}){return tr.DP=this.token.decimals,new tr(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)}};var gt=require("@solana/web3.js"),Fi=J(require("axios"));var He=require("@solana/web3.js"),Ei=require("@solana/spl-token");var vs=be("Raydium_txUtil");function vt(r,e){let[t,n]=He.PublicKey.findProgramAddressSync(r,e);return{publicKey:t,nonce:n}}var pt=require("@solana/web3.js");var rr=require("@solana/web3.js"),ir=require("@solana/spl-token");var an=be("Raydium_accountInfo_util");async function Ye(r,e,t){let{batchRequest:n,commitment:i="confirmed"}=Z({batchRequest:!1},t),o=un(e,100),s=new Array(o.length).fill([]);if(n){let a=o.map(l=>{let m=r._buildArgs([l.map(d=>d.toBase58())],i,"base64");return{methodName:"getMultipleAccounts",args:m}}),u=un(a,10);s=(await(await Promise.all(u.map(async l=>await r._rpcBatchRequest(l)))).flat()).map(l=>(l.error&&an.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${l.error.message}`),l.result.value.map(m=>{if(m){let{data:d,executable:f,lamports:h,owner:g,rentEpoch:b}=m;return d.length!==2&&d[1]!=="base64"&&an.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(d[0],"base64"),executable:f,lamports:h,owner:new rr.PublicKey(g),rentEpoch:b}}return null})))}else try{s=await Promise.all(o.map(a=>r.getMultipleAccountsInfo(a,i)))}catch(a){a instanceof Error&&an.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${a.message}`)}return s.flat()}async function cn(r,e,t){let n=await Ye(r,e.map(i=>i.pubkey),t);return e.map((i,o)=>ne(Z({},i),{accountInfo:n[o]}))}var Ri={"2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17":new pt.AddressLookupTableAccount({key:new pt.PublicKey("2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17"),state:pt.AddressLookupTableAccount.deserialize(Buffer.from("AQAAAP//////////d49+DAAAAAAAAQZMWvw7GUNJdaccNBVnb57OKakxL2BHLYvhRwVILRsgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMGRm/lIRcy/+ytunLDm+e8jOW7xfcSayxDmzpAAAAABt324ddloZPZy+FGzut5rBy0he1fWzeROoz1hX7/AKkG3fbh7nWP3hhCXbzkbM3athr8TYO5DSf+vfko2KGL/AVKU1D4XciC1hSlVnJ4iilt3x6rq9CmBniISTL07vagBqfVFxksXFEhjMlMPUrxf1ja7gibof1E49vZigAAAAAGp9UXGMd0yShWY5hpHV62i164o5tLbVxzVVshAAAAAIyXJY9OJInxuz0QKRSODYMLWhOZ2v8QhASOe9jb6fhZC3BlsePRfEU4nVJ/awTDzVi4bHMaoP21SbbRvAP4KUbIScv+6Yw2LHF/6K0ZjUPibbSWXCirYPGuuVl7zT789IUPLW4CpHr4JNCatp3ELXDLKMv6JJ+37le50lbBJ2LvDQdRqCgtphMF/imcN7mY5YRx2xE1A3MQ+L4QRaYK9u4GRfZP3LsAd00a+IkCpA22UNQMKdq5BFbJuwuOLqc8zxCTDlqxBG8J0HcxtfogQHDK06ukzfaXiNDKAob1MqBHS9lJxDYCwz8gd5DtFqNSTKG5l1zxIaKpDP/sffi2is1H9aKveyXSu5StXElYRl9SD5As0DHE4N0GLnf84/siiKXVyp4Ez121kLcUui/jLLFZEz/BwZK3Ilf9B9OcsEAeDMKAy2vjGSxQODgBz0QwGA+eP4ZjIjrIAQaXENv31QfLlOdXSRCkaybRniDHF4C8YcwhcvsqrOVuTP4B2Na+9wLdtrB31uz2rtlFI5kahdsnp/d1SrASDInYCtTYtdoke4kX+hoKWcEWM4Tle8pTUkUVv4BxS6fje/EzKBE4Qu9N9LMnrw/JNO0hqMVB4rk/2ou4AB1loQ7FZoPwut2o4KZB+0p9xnbrQKw038qjpHar+PyDwvxBRcu5hpHw3dguezeWv+IwvgW5icu8EGkhGa9AkFPPJT7VMSFb8xowveU=","base64"))})};function un(r,e=1,t=[]){let n=[...r];if(e<=0)return t;for(;n.length;)t.push(n.splice(0,e));return t}var de=require("@solana/web3.js"),pa=new de.PublicKey("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),ga=new de.PublicKey("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),ha=new de.PublicKey("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),ba=new de.PublicKey("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),ya=new de.PublicKey("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),wa=new de.PublicKey("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Ta=new de.PublicKey("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Aa=new de.PublicKey("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),xa=new de.PublicKey("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),ka=new de.PublicKey("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Pa=new de.PublicKey("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Ba=new de.PublicKey("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),Ia=new de.PublicKey("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),Na=new de.PublicKey("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi");var Oi=require("@solana/web3.js");var Di=require("@solana/spl-token");var z=J(require("bn.js")),Le=1e4;function Kt(r,e,t,n){if(e===void 0)return{amount:r,fee:void 0,expirationTime:void 0};let i=t.epoch<e.newerTransferFee.epoch?e.olderTransferFee:e.newerTransferFee,o=new z.default(i.maximumFee.toString()),s=t.epoch<e.newerTransferFee.epoch?(Number(e.newerTransferFee.epoch)*t.slotsInEpoch-t.absoluteSlot)*400/1e3:void 0;if(n)if(i.transferFeeBasisPoints===Le){let a=new z.default(i.maximumFee.toString());return{amount:r.add(a),fee:a,expirationTime:s}}else{let a=nt(r.mul(new z.default(Le)),new z.default(Le-i.transferFeeBasisPoints)),u=new z.default(i.maximumFee.toString()),c=a.sub(r).gt(u)?r.add(u):a,l=nt(c.mul(new z.default(i.transferFeeBasisPoints)),new z.default(Le)),m=l.gt(o)?o:l;return{amount:c,fee:m,expirationTime:s}}else{let a=nt(r.mul(new z.default(i.transferFeeBasisPoints)),new z.default(Le)),u=a.gt(o)?o:a;return{amount:r,fee:u,expirationTime:s}}}function ce(r,e,t,n){if(e===void 0)return{amount:r,fee:void 0,expirationTime:void 0};let i=ne(Z({},e),{olderTransferFee:{epoch:BigInt(e.olderTransferFee.epoch),maximumFee:BigInt(e.olderTransferFee.maximumFee),transferFeeBasisPoints:e.olderTransferFee.transferFeeBasisPoints},newerTransferFee:{epoch:BigInt(e.newerTransferFee.epoch),maximumFee:BigInt(e.newerTransferFee.maximumFee),transferFeeBasisPoints:e.newerTransferFee.transferFeeBasisPoints}}),o=t.epoch<i.newerTransferFee.epoch?i.olderTransferFee:i.newerTransferFee,s=new z.default(o.maximumFee.toString()),a=t.epoch<i.newerTransferFee.epoch?(Number(i.newerTransferFee.epoch)*t.slotsInEpoch-t.absoluteSlot)*400/1e3:void