@raydium-io/raydium-sdk-v2
Version:
An SDK for building applications on top of Raydium.
2 lines • 61.5 kB
JavaScript
var wn=Object.defineProperty,Tn=Object.defineProperties;var xn=Object.getOwnPropertyDescriptors;var Rt=Object.getOwnPropertySymbols;var An=Object.prototype.hasOwnProperty,Pn=Object.prototype.propertyIsEnumerable;var Et=(t,e,n)=>e in t?wn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ee=(t,e)=>{for(var n in e||(e={}))An.call(e,n)&&Et(t,n,e[n]);if(Rt)for(var n of Rt(e))Pn.call(e,n)&&Et(t,n,e[n]);return t},ae=(t,e)=>Tn(t,xn(e));import ci from"bn.js";var Ae=9e15,he=1e9,nt="0123456789abcdef",qe="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Ge="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",rt={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Ae,maxE:Ae,crypto:!1},vt,ue,w=!0,Ue="[DecimalError] ",ge=Ue+"Invalid argument: ",Dt=Ue+"Precision limit exceeded",Ot=Ue+"crypto unavailable",Kt="[object Decimal]",U=Math.floor,v=Math.pow,kn=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Bn=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,In=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,qt=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,ne=1e7,b=7,Nn=9007199254740991,Sn=qe.length-1,it=Ge.length-1,f={toStringTag:Kt};f.absoluteValue=f.abs=function(){var t=new this.constructor(this);return t.s<0&&(t.s=1),g(t)};f.ceil=function(){return g(new this.constructor(this),this.e+1,2)};f.clampedTo=f.clamp=function(t,e){var n,r=this,i=r.constructor;if(t=new i(t),e=new i(e),!t.s||!e.s)return new i(NaN);if(t.gt(e))throw Error(ge+e);return n=r.cmp(t),n<0?t:r.cmp(e)>0?e:new i(r)};f.comparedTo=f.cmp=function(t){var e,n,r,i,o=this,s=o.d,a=(t=new o.constructor(t)).d,c=o.s,u=t.s;if(!s||!a)return!c||!u?NaN:c!==u?c:s===a?0:!s^c<0?1:-1;if(!s[0]||!a[0])return s[0]?c:a[0]?-u:0;if(c!==u)return c;if(o.e!==t.e)return o.e>t.e^c<0?1:-1;for(r=s.length,i=a.length,e=0,n=r<i?r:i;e<n;++e)if(s[e]!==a[e])return s[e]>a[e]^c<0?1:-1;return r===i?0:r>i^c<0?1:-1};f.cosine=f.cos=function(){var t,e,n=this,r=n.constructor;return n.d?n.d[0]?(t=r.precision,e=r.rounding,r.precision=t+Math.max(n.e,n.sd())+b,r.rounding=1,n=Cn(r,Xt(r,n)),r.precision=t,r.rounding=e,g(ue==2||ue==3?n.neg():n,t,e,!0)):new r(1):new r(NaN)};f.cubeRoot=f.cbrt=function(){var t,e,n,r,i,o,s,a,c,u,m=this,l=m.constructor;if(!m.isFinite()||m.isZero())return new l(m);for(w=!1,o=m.s*v(m.s*m,1/3),!o||Math.abs(o)==1/0?(n=K(m.d),t=m.e,(o=(t-n.length+1)%3)&&(n+=o==1||o==-2?"0":"00"),o=v(n,1/3),t=U((t+1)/3)-(t%3==(t<0?-1:2)),o==1/0?n="5e"+t:(n=o.toExponential(),n=n.slice(0,n.indexOf("e")+1)+t),r=new l(n),r.s=m.s):r=new l(o.toString()),s=(t=l.precision)+3;;)if(a=r,c=a.times(a).times(a),u=c.plus(m),r=N(u.plus(m).times(a),u.plus(c),s+2,1),K(a.d).slice(0,s)===(n=K(r.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!i&&n=="4999"){if(!i&&(g(a,t+1,0),a.times(a).times(a).eq(m))){r=a;break}s+=4,i=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(g(r,t+1,1),e=!r.times(r).times(r).eq(m));break}return w=!0,g(r,t,l.rounding,e)};f.decimalPlaces=f.dp=function(){var t,e=this.d,n=NaN;if(e){if(t=e.length-1,n=(t-U(this.e/b))*b,t=e[t],t)for(;t%10==0;t/=10)n--;n<0&&(n=0)}return n};f.dividedBy=f.div=function(t){return N(this,new this.constructor(t))};f.dividedToIntegerBy=f.divToInt=function(t){var e=this,n=e.constructor;return g(N(e,new n(t),0,1,1),n.precision,n.rounding)};f.equals=f.eq=function(t){return this.cmp(t)===0};f.floor=function(){return g(new this.constructor(this),this.e+1,3)};f.greaterThan=f.gt=function(t){return this.cmp(t)>0};f.greaterThanOrEqualTo=f.gte=function(t){var e=this.cmp(t);return e==1||e===0};f.hyperbolicCosine=f.cosh=function(){var t,e,n,r,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;n=s.precision,r=s.rounding,s.precision=n+Math.max(o.e,o.sd())+4,s.rounding=1,i=o.d.length,i<32?(t=Math.ceil(i/3),e=(1/Xe(4,t)).toString()):(t=16,e="2.3283064365386962890625e-10"),o=Pe(s,1,o.times(e),new s(1),!0);for(var c,u=t,m=new s(8);u--;)c=o.times(o),o=a.minus(c.times(m.minus(c.times(m))));return g(o,s.precision=n,s.rounding=r,!0)};f.hyperbolicSine=f.sinh=function(){var t,e,n,r,i=this,o=i.constructor;if(!i.isFinite()||i.isZero())return new o(i);if(e=o.precision,n=o.rounding,o.precision=e+Math.max(i.e,i.sd())+4,o.rounding=1,r=i.d.length,r<3)i=Pe(o,2,i,i,!0);else{t=1.4*Math.sqrt(r),t=t>16?16:t|0,i=i.times(1/Xe(5,t)),i=Pe(o,2,i,i,!0);for(var s,a=new o(5),c=new o(16),u=new o(20);t--;)s=i.times(i),i=i.times(a.plus(s.times(c.times(s).plus(u))))}return o.precision=e,o.rounding=n,g(i,e,n,!0)};f.hyperbolicTangent=f.tanh=function(){var t,e,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(t=r.precision,e=r.rounding,r.precision=t+7,r.rounding=1,N(n.sinh(),n.cosh(),r.precision=t,r.rounding=e)):new r(n.s)};f.inverseCosine=f.acos=function(){var t,e=this,n=e.constructor,r=e.abs().cmp(1),i=n.precision,o=n.rounding;return r!==-1?r===0?e.isNeg()?te(n,i,o):new n(0):new n(NaN):e.isZero()?te(n,i+4,o).times(.5):(n.precision=i+6,n.rounding=1,e=e.asin(),t=te(n,i+4,o).times(.5),n.precision=i,n.rounding=o,t.minus(e))};f.inverseHyperbolicCosine=f.acosh=function(){var t,e,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(t=r.precision,e=r.rounding,r.precision=t+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,w=!1,n=n.times(n).minus(1).sqrt().plus(n),w=!0,r.precision=t,r.rounding=e,n.ln()):new r(n)};f.inverseHyperbolicSine=f.asinh=function(){var t,e,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(t=r.precision,e=r.rounding,r.precision=t+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,w=!1,n=n.times(n).plus(1).sqrt().plus(n),w=!0,r.precision=t,r.rounding=e,n.ln())};f.inverseHyperbolicTangent=f.atanh=function(){var t,e,n,r,i=this,o=i.constructor;return i.isFinite()?i.e>=0?new o(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(t=o.precision,e=o.rounding,r=i.sd(),Math.max(r,t)<2*-i.e-1?g(new o(i),t,e,!0):(o.precision=n=r-i.e,i=N(i.plus(1),new o(1).minus(i),n+t,1),o.precision=t+4,o.rounding=1,i=i.ln(),o.precision=t,o.rounding=e,i.times(.5))):new o(NaN)};f.inverseSine=f.asin=function(){var t,e,n,r,i=this,o=i.constructor;return i.isZero()?new o(i):(e=i.abs().cmp(1),n=o.precision,r=o.rounding,e!==-1?e===0?(t=te(o,n+4,r).times(.5),t.s=i.s,t):new o(NaN):(o.precision=n+6,o.rounding=1,i=i.div(new o(1).minus(i.times(i)).sqrt().plus(1)).atan(),o.precision=n,o.rounding=r,i.times(2)))};f.inverseTangent=f.atan=function(){var t,e,n,r,i,o,s,a,c,u=this,m=u.constructor,l=m.precision,d=m.rounding;if(u.isFinite()){if(u.isZero())return new m(u);if(u.abs().eq(1)&&l+4<=it)return s=te(m,l+4,d).times(.25),s.s=u.s,s}else{if(!u.s)return new m(NaN);if(l+4<=it)return s=te(m,l+4,d).times(.5),s.s=u.s,s}for(m.precision=a=l+10,m.rounding=1,n=Math.min(28,a/b+2|0),t=n;t;--t)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(w=!1,e=Math.ceil(a/b),r=1,c=u.times(u),s=new m(u),i=u;t!==-1;)if(i=i.times(c),o=s.minus(i.div(r+=2)),i=i.times(c),s=o.plus(i.div(r+=2)),s.d[e]!==void 0)for(t=e;s.d[t]===o.d[t]&&t--;);return n&&(s=s.times(2<<n-1)),w=!0,g(s,m.precision=l,m.rounding=d,!0)};f.isFinite=function(){return!!this.d};f.isInteger=f.isInt=function(){return!!this.d&&U(this.e/b)>this.d.length-2};f.isNaN=function(){return!this.s};f.isNegative=f.isNeg=function(){return this.s<0};f.isPositive=f.isPos=function(){return this.s>0};f.isZero=function(){return!!this.d&&this.d[0]===0};f.lessThan=f.lt=function(t){return this.cmp(t)<0};f.lessThanOrEqualTo=f.lte=function(t){return this.cmp(t)<1};f.logarithm=f.log=function(t){var e,n,r,i,o,s,a,c,u=this,m=u.constructor,l=m.precision,d=m.rounding,p=5;if(t==null)t=new m(10),e=!0;else{if(t=new m(t),n=t.d,t.s<0||!n||!n[0]||t.eq(1))return new m(NaN);e=t.eq(10)}if(n=u.d,u.s<0||!n||!n[0]||u.eq(1))return new m(n&&!n[0]?-1/0:u.s!=1?NaN:n?0:1/0);if(e)if(n.length>1)o=!0;else{for(i=n[0];i%10===0;)i/=10;o=i!==1}if(w=!1,a=l+p,s=pe(u,a),r=e?Ve(m,a+10):pe(t,a),c=N(s,r,a,1),Se(c.d,i=l,d))do if(a+=10,s=pe(u,a),r=e?Ve(m,a+10):pe(t,a),c=N(s,r,a,1),!o){+K(c.d).slice(i+1,i+15)+1==1e14&&(c=g(c,l+1,0));break}while(Se(c.d,i+=10,d));return w=!0,g(c,l,d)};f.minus=f.sub=function(t){var e,n,r,i,o,s,a,c,u,m,l,d,p=this,T=p.constructor;if(t=new T(t),!p.d||!t.d)return!p.s||!t.s?t=new T(NaN):p.d?t.s=-t.s:t=new T(t.d||p.s!==t.s?p:NaN),t;if(p.s!=t.s)return t.s=-t.s,p.plus(t);if(u=p.d,d=t.d,a=T.precision,c=T.rounding,!u[0]||!d[0]){if(d[0])t.s=-t.s;else if(u[0])t=new T(p);else return new T(c===3?-0:0);return w?g(t,a,c):t}if(n=U(t.e/b),m=U(p.e/b),u=u.slice(),o=m-n,o){for(l=o<0,l?(e=u,o=-o,s=d.length):(e=d,n=m,s=u.length),r=Math.max(Math.ceil(a/b),s)+2,o>r&&(o=r,e.length=1),e.reverse(),r=o;r--;)e.push(0);e.reverse()}else{for(r=u.length,s=d.length,l=r<s,l&&(s=r),r=0;r<s;r++)if(u[r]!=d[r]){l=u[r]<d[r];break}o=0}for(l&&(e=u,u=d,d=e,t.s=-t.s),s=u.length,r=d.length-s;r>0;--r)u[s++]=0;for(r=d.length;r>o;){if(u[--r]<d[r]){for(i=r;i&&u[--i]===0;)u[i]=ne-1;--u[i],u[r]+=ne}u[r]-=d[r]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--n;return u[0]?(t.d=u,t.e=We(u,n),w?g(t,a,c):t):new T(c===3?-0:0)};f.modulo=f.mod=function(t){var e,n=this,r=n.constructor;return t=new r(t),!n.d||!t.s||t.d&&!t.d[0]?new r(NaN):!t.d||n.d&&!n.d[0]?g(new r(n),r.precision,r.rounding):(w=!1,r.modulo==9?(e=N(n,t.abs(),0,3,1),e.s*=t.s):e=N(n,t,0,r.modulo,1),e=e.times(t),w=!0,n.minus(e))};f.naturalExponential=f.exp=function(){return ot(this)};f.naturalLogarithm=f.ln=function(){return pe(this)};f.negated=f.neg=function(){var t=new this.constructor(this);return t.s=-t.s,g(t)};f.plus=f.add=function(t){var e,n,r,i,o,s,a,c,u,m,l=this,d=l.constructor;if(t=new d(t),!l.d||!t.d)return!l.s||!t.s?t=new d(NaN):l.d||(t=new d(t.d||l.s===t.s?l:NaN)),t;if(l.s!=t.s)return t.s=-t.s,l.minus(t);if(u=l.d,m=t.d,a=d.precision,c=d.rounding,!u[0]||!m[0])return m[0]||(t=new d(l)),w?g(t,a,c):t;if(o=U(l.e/b),r=U(t.e/b),u=u.slice(),i=o-r,i){for(i<0?(n=u,i=-i,s=m.length):(n=m,r=o,s=u.length),o=Math.ceil(a/b),s=o>s?o+1:s+1,i>s&&(i=s,n.length=1),n.reverse();i--;)n.push(0);n.reverse()}for(s=u.length,i=m.length,s-i<0&&(i=s,n=m,m=u,u=n),e=0;i;)e=(u[--i]=u[i]+m[i]+e)/ne|0,u[i]%=ne;for(e&&(u.unshift(e),++r),s=u.length;u[--s]==0;)u.pop();return t.d=u,t.e=We(u,r),w?g(t,a,c):t};f.precision=f.sd=function(t){var e,n=this;if(t!==void 0&&t!==!!t&&t!==1&&t!==0)throw Error(ge+t);return n.d?(e=Gt(n.d),t&&n.e+1>e&&(e=n.e+1)):e=NaN,e};f.round=function(){var t=this,e=t.constructor;return g(new e(t),t.e+1,e.rounding)};f.sine=f.sin=function(){var t,e,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(t=r.precision,e=r.rounding,r.precision=t+Math.max(n.e,n.sd())+b,r.rounding=1,n=Rn(r,Xt(r,n)),r.precision=t,r.rounding=e,g(ue>2?n.neg():n,t,e,!0)):new r(NaN)};f.squareRoot=f.sqrt=function(){var t,e,n,r,i,o,s=this,a=s.d,c=s.e,u=s.s,m=s.constructor;if(u!==1||!a||!a[0])return new m(!u||u<0&&(!a||a[0])?NaN:a?s:1/0);for(w=!1,u=Math.sqrt(+s),u==0||u==1/0?(e=K(a),(e.length+c)%2==0&&(e+="0"),u=Math.sqrt(e),c=U((c+1)/2)-(c<0||c%2),u==1/0?e="5e"+c:(e=u.toExponential(),e=e.slice(0,e.indexOf("e")+1)+c),r=new m(e)):r=new m(u.toString()),n=(c=m.precision)+3;;)if(o=r,r=o.plus(N(s,o,n+2,1)).times(.5),K(o.d).slice(0,n)===(e=K(r.d)).slice(0,n))if(e=e.slice(n-3,n+1),e=="9999"||!i&&e=="4999"){if(!i&&(g(o,c+1,0),o.times(o).eq(s))){r=o;break}n+=4,i=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(g(r,c+1,1),t=!r.times(r).eq(s));break}return w=!0,g(r,c,m.rounding,t)};f.tangent=f.tan=function(){var t,e,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(t=r.precision,e=r.rounding,r.precision=t+10,r.rounding=1,n=n.sin(),n.s=1,n=N(n,new r(1).minus(n.times(n)).sqrt(),t+10,0),r.precision=t,r.rounding=e,g(ue==2||ue==4?n.neg():n,t,e,!0)):new r(NaN)};f.times=f.mul=function(t){var e,n,r,i,o,s,a,c,u,m=this,l=m.constructor,d=m.d,p=(t=new l(t)).d;if(t.s*=m.s,!d||!d[0]||!p||!p[0])return new l(!t.s||d&&!d[0]&&!p||p&&!p[0]&&!d?NaN:!d||!p?t.s/0:t.s*0);for(n=U(m.e/b)+U(t.e/b),c=d.length,u=p.length,c<u&&(o=d,d=p,p=o,s=c,c=u,u=s),o=[],s=c+u,r=s;r--;)o.push(0);for(r=u;--r>=0;){for(e=0,i=c+r;i>r;)a=o[i]+p[r]*d[i-r-1]+e,o[i--]=a%ne|0,e=a/ne|0;o[i]=(o[i]+e)%ne|0}for(;!o[--s];)o.pop();return e?++n:o.shift(),t.d=o,t.e=We(o,n),w?g(t,l.precision,l.rounding):t};f.toBinary=function(t,e){return at(this,2,t,e)};f.toDecimalPlaces=f.toDP=function(t,e){var n=this,r=n.constructor;return n=new r(n),t===void 0?n:(H(t,0,he),e===void 0?e=r.rounding:H(e,0,8),g(n,t+n.e+1,e))};f.toExponential=function(t,e){var n,r=this,i=r.constructor;return t===void 0?n=re(r,!0):(H(t,0,he),e===void 0?e=i.rounding:H(e,0,8),r=g(new i(r),t+1,e),n=re(r,!0,t+1)),r.isNeg()&&!r.isZero()?"-"+n:n};f.toFixed=function(t,e){var n,r,i=this,o=i.constructor;return t===void 0?n=re(i):(H(t,0,he),e===void 0?e=o.rounding:H(e,0,8),r=g(new o(i),t+i.e+1,e),n=re(r,!1,t+r.e+1)),i.isNeg()&&!i.isZero()?"-"+n:n};f.toFraction=function(t){var e,n,r,i,o,s,a,c,u,m,l,d,p=this,T=p.d,y=p.constructor;if(!T)return new y(p);if(u=n=new y(1),r=c=new y(0),e=new y(r),o=e.e=Gt(T)-p.e-1,s=o%b,e.d[0]=v(10,s<0?b+s:s),t==null)t=o>0?e:u;else{if(a=new y(t),!a.isInt()||a.lt(u))throw Error(ge+a);t=a.gt(e)?o>0?e:u:a}for(w=!1,a=new y(K(T)),m=y.precision,y.precision=o=T.length*b*2;l=N(a,e,0,1,1),i=n.plus(l.times(r)),i.cmp(t)!=1;)n=r,r=i,i=u,u=c.plus(l.times(i)),c=i,i=e,e=a.minus(l.times(i)),a=i;return i=N(t.minus(n),r,0,1,1),c=c.plus(i.times(u)),n=n.plus(i.times(r)),c.s=u.s=p.s,d=N(u,r,o,1).minus(p).abs().cmp(N(c,n,o,1).minus(p).abs())<1?[u,r]:[c,n],y.precision=m,w=!0,d};f.toHexadecimal=f.toHex=function(t,e){return at(this,16,t,e)};f.toNearest=function(t,e){var n=this,r=n.constructor;if(n=new r(n),t==null){if(!n.d)return n;t=new r(1),e=r.rounding}else{if(t=new r(t),e===void 0?e=r.rounding:H(e,0,8),!n.d)return t.s?n:t;if(!t.d)return t.s&&(t.s=n.s),t}return t.d[0]?(w=!1,n=N(n,t,0,e,1).times(t),w=!0,g(n)):(t.s=n.s,n=t),n};f.toNumber=function(){return+this};f.toOctal=function(t,e){return at(this,8,t,e)};f.toPower=f.pow=function(t){var e,n,r,i,o,s,a=this,c=a.constructor,u=+(t=new c(t));if(!a.d||!t.d||!a.d[0]||!t.d[0])return new c(v(+a,u));if(a=new c(a),a.eq(1))return a;if(r=c.precision,o=c.rounding,t.eq(1))return g(a,r,o);if(e=U(t.e/b),e>=t.d.length-1&&(n=u<0?-u:u)<=Nn)return i=Vt(c,a,n,r),t.s<0?new c(1).div(i):g(i,r,o);if(s=a.s,s<0){if(e<t.d.length-1)return new c(NaN);if((t.d[e]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return n=v(+a,u),e=n==0||!isFinite(n)?U(u*(Math.log("0."+K(a.d))/Math.LN10+a.e+1)):new c(n+"").e,e>c.maxE+1||e<c.minE-1?new c(e>0?s/0:0):(w=!1,c.rounding=a.s=1,n=Math.min(12,(e+"").length),i=ot(t.times(pe(a,r+n)),r),i.d&&(i=g(i,r+5,1),Se(i.d,r,o)&&(e=r+10,i=g(ot(t.times(pe(a,e+n)),e),e+5,1),+K(i.d).slice(r+1,r+15)+1==1e14&&(i=g(i,r+1,0)))),i.s=s,w=!0,c.rounding=o,g(i,r,o))};f.toPrecision=function(t,e){var n,r=this,i=r.constructor;return t===void 0?n=re(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(H(t,1,he),e===void 0?e=i.rounding:H(e,0,8),r=g(new i(r),t,e),n=re(r,t<=r.e||r.e<=i.toExpNeg,t)),r.isNeg()&&!r.isZero()?"-"+n:n};f.toSignificantDigits=f.toSD=function(t,e){var n=this,r=n.constructor;return t===void 0?(t=r.precision,e=r.rounding):(H(t,1,he),e===void 0?e=r.rounding:H(e,0,8)),g(new r(n),t,e)};f.toString=function(){var t=this,e=t.constructor,n=re(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()&&!t.isZero()?"-"+n:n};f.truncated=f.trunc=function(){return g(new this.constructor(this),this.e+1,1)};f.valueOf=f.toJSON=function(){var t=this,e=t.constructor,n=re(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()?"-"+n:n};function K(t){var e,n,r,i=t.length-1,o="",s=t[0];if(i>0){for(o+=s,e=1;e<i;e++)r=t[e]+"",n=b-r.length,n&&(o+=fe(n)),o+=r;s=t[e],r=s+"",n=b-r.length,n&&(o+=fe(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function H(t,e,n){if(t!==~~t||t<e||t>n)throw Error(ge+t)}function Se(t,e,n,r){var i,o,s,a;for(o=t[0];o>=10;o/=10)--e;return--e<0?(e+=b,i=0):(i=Math.ceil((e+1)/b),e%=b),o=v(10,b-e),a=t[i]%o|0,r==null?e<3?(e==0?a=a/100|0:e==1&&(a=a/10|0),s=n<4&&a==99999||n>3&&a==49999||a==5e4||a==0):s=(n<4&&a+1==o||n>3&&a+1==o/2)&&(t[i+1]/o/100|0)==v(10,e-2)-1||(a==o/2||a==0)&&(t[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=(r||n<4)&&a==9999||!r&&n>3&&a==4999):s=((r||n<4)&&a+1==o||!r&&n>3&&a+1==o/2)&&(t[i+1]/o/1e3|0)==v(10,e-3)-1,s}function Ke(t,e,n){for(var r,i=[0],o,s=0,a=t.length;s<a;){for(o=i.length;o--;)i[o]*=e;for(i[0]+=nt.indexOf(t.charAt(s++)),r=0;r<i.length;r++)i[r]>n-1&&(i[r+1]===void 0&&(i[r+1]=0),i[r+1]+=i[r]/n|0,i[r]%=n)}return i.reverse()}function Cn(t,e){var n,r,i;if(e.isZero())return e;r=e.d.length,r<32?(n=Math.ceil(r/3),i=(1/Xe(4,n)).toString()):(n=16,i="2.3283064365386962890625e-10"),t.precision+=n,e=Pe(t,1,e.times(i),new t(1));for(var o=n;o--;){var s=e.times(e);e=s.times(s).minus(s).times(8).plus(1)}return t.precision-=n,e}var N=function(){function t(r,i,o){var s,a=0,c=r.length;for(r=r.slice();c--;)s=r[c]*i+a,r[c]=s%o|0,a=s/o|0;return a&&r.unshift(a),r}function e(r,i,o,s){var a,c;if(o!=s)c=o>s?1:-1;else for(a=c=0;a<o;a++)if(r[a]!=i[a]){c=r[a]>i[a]?1:-1;break}return c}function n(r,i,o,s){for(var a=0;o--;)r[o]-=a,a=r[o]<i[o]?1:0,r[o]=a*s+r[o]-i[o];for(;!r[0]&&r.length>1;)r.shift()}return function(r,i,o,s,a,c){var u,m,l,d,p,T,y,O,C,Q,I,G,Me,se,$e,ve,Ne,et,$,De,Oe=r.constructor,tt=r.s==i.s?1:-1,V=r.d,S=i.d;if(!V||!V[0]||!S||!S[0])return new Oe(!r.s||!i.s||(V?S&&V[0]==S[0]:!S)?NaN:V&&V[0]==0||!S?tt*0:tt/0);for(c?(p=1,m=r.e-i.e):(c=ne,p=b,m=U(r.e/p)-U(i.e/p)),$=S.length,Ne=V.length,C=new Oe(tt),Q=C.d=[],l=0;S[l]==(V[l]||0);l++);if(S[l]>(V[l]||0)&&m--,o==null?(se=o=Oe.precision,s=Oe.rounding):a?se=o+(r.e-i.e)+1:se=o,se<0)Q.push(1),T=!0;else{if(se=se/p+2|0,l=0,$==1){for(d=0,S=S[0],se++;(l<Ne||d)&&se--;l++)$e=d*c+(V[l]||0),Q[l]=$e/S|0,d=$e%S|0;T=d||l<Ne}else{for(d=c/(S[0]+1)|0,d>1&&(S=t(S,d,c),V=t(V,d,c),$=S.length,Ne=V.length),ve=$,I=V.slice(0,$),G=I.length;G<$;)I[G++]=0;De=S.slice(),De.unshift(0),et=S[0],S[1]>=c/2&&++et;do d=0,u=e(S,I,$,G),u<0?(Me=I[0],$!=G&&(Me=Me*c+(I[1]||0)),d=Me/et|0,d>1?(d>=c&&(d=c-1),y=t(S,d,c),O=y.length,G=I.length,u=e(y,I,O,G),u==1&&(d--,n(y,$<O?De:S,O,c))):(d==0&&(u=d=1),y=S.slice()),O=y.length,O<G&&y.unshift(0),n(I,y,G,c),u==-1&&(G=I.length,u=e(S,I,$,G),u<1&&(d++,n(I,$<G?De:S,G,c))),G=I.length):u===0&&(d++,I=[0]),Q[l++]=d,u&&I[0]?I[G++]=V[ve]||0:(I=[V[ve]],G=1);while((ve++<Ne||I[0]!==void 0)&&se--);T=I[0]!==void 0}Q[0]||Q.shift()}if(p==1)C.e=m,vt=T;else{for(l=1,d=Q[0];d>=10;d/=10)l++;C.e=l+m*p-1,g(C,a?o+C.e+1:o,s,T)}return C}}();function g(t,e,n,r){var i,o,s,a,c,u,m,l,d,p=t.constructor;e:if(e!=null){if(l=t.d,!l)return t;for(i=1,a=l[0];a>=10;a/=10)i++;if(o=e-i,o<0)o+=b,s=e,m=l[d=0],c=m/v(10,i-s-1)%10|0;else if(d=Math.ceil((o+1)/b),a=l.length,d>=a)if(r){for(;a++<=d;)l.push(0);m=c=0,i=1,o%=b,s=o-b+1}else break e;else{for(m=a=l[d],i=1;a>=10;a/=10)i++;o%=b,s=o-b+i,c=s<0?0:m/v(10,i-s-1)%10|0}if(r=r||e<0||l[d+1]!==void 0||(s<0?m:m%v(10,i-s-1)),u=n<4?(c||r)&&(n==0||n==(t.s<0?3:2)):c>5||c==5&&(n==4||r||n==6&&(o>0?s>0?m/v(10,i-s):0:l[d-1])%10&1||n==(t.s<0?8:7)),e<1||!l[0])return l.length=0,u?(e-=t.e+1,l[0]=v(10,(b-e%b)%b),t.e=-e||0):l[0]=t.e=0,t;if(o==0?(l.length=d,a=1,d--):(l.length=d+1,a=v(10,b-o),l[d]=s>0?(m/v(10,i-s)%v(10,s)|0)*a:0),u)for(;;)if(d==0){for(o=1,s=l[0];s>=10;s/=10)o++;for(s=l[0]+=a,a=1;s>=10;s/=10)a++;o!=a&&(t.e++,l[0]==ne&&(l[0]=1));break}else{if(l[d]+=a,l[d]!=ne)break;l[d--]=0,a=1}for(o=l.length;l[--o]===0;)l.pop()}return w&&(t.e>p.maxE?(t.d=null,t.e=NaN):t.e<p.minE&&(t.e=0,t.d=[0])),t}function re(t,e,n){if(!t.isFinite())return Wt(t);var r,i=t.e,o=K(t.d),s=o.length;return e?(n&&(r=n-s)>0?o=o.charAt(0)+"."+o.slice(1)+fe(r):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(t.e<0?"e":"e+")+t.e):i<0?(o="0."+fe(-i-1)+o,n&&(r=n-s)>0&&(o+=fe(r))):i>=s?(o+=fe(i+1-s),n&&(r=n-i-1)>0&&(o=o+"."+fe(r))):((r=i+1)<s&&(o=o.slice(0,r)+"."+o.slice(r)),n&&(r=n-s)>0&&(i+1===s&&(o+="."),o+=fe(r))),o}function We(t,e){var n=t[0];for(e*=b;n>=10;n/=10)e++;return e}function Ve(t,e,n){if(e>Sn)throw w=!0,n&&(t.precision=n),Error(Dt);return g(new t(qe),e,1,!0)}function te(t,e,n){if(e>it)throw Error(Dt);return g(new t(Ge),e,n,!0)}function Gt(t){var e=t.length-1,n=e*b+1;if(e=t[e],e){for(;e%10==0;e/=10)n--;for(e=t[0];e>=10;e/=10)n++}return n}function fe(t){for(var e="";t--;)e+="0";return e}function Vt(t,e,n,r){var i,o=new t(1),s=Math.ceil(r/b+4);for(w=!1;;){if(n%2&&(o=o.times(e),Ft(o.d,s)&&(i=!0)),n=U(n/2),n===0){n=o.d.length-1,i&&o.d[n]===0&&++o.d[n];break}e=e.times(e),Ft(e.d,s)}return w=!0,o}function _t(t){return t.d[t.d.length-1]&1}function Ut(t,e,n){for(var r,i=new t(e[0]),o=0;++o<e.length;)if(r=new t(e[o]),r.s)i[n](r)&&(i=r);else{i=r;break}return i}function ot(t,e){var n,r,i,o,s,a,c,u=0,m=0,l=0,d=t.constructor,p=d.rounding,T=d.precision;if(!t.d||!t.d[0]||t.e>17)return new d(t.d?t.d[0]?t.s<0?0:1/0:1:t.s?t.s<0?0:t:0/0);for(e==null?(w=!1,c=T):c=e,a=new d(.03125);t.e>-2;)t=t.times(a),l+=5;for(r=Math.log(v(2,l))/Math.LN10*2+5|0,c+=r,n=o=s=new d(1),d.precision=c;;){if(o=g(o.times(t),c,1),n=n.times(++m),a=s.plus(N(o,n,c,1)),K(a.d).slice(0,c)===K(s.d).slice(0,c)){for(i=l;i--;)s=g(s.times(s),c,1);if(e==null)if(u<3&&Se(s.d,c-r,p,u))d.precision=c+=10,n=o=a=new d(1),m=0,u++;else return g(s,d.precision=T,p,w=!0);else return d.precision=T,s}s=a}}function pe(t,e){var n,r,i,o,s,a,c,u,m,l,d,p=1,T=10,y=t,O=y.d,C=y.constructor,Q=C.rounding,I=C.precision;if(y.s<0||!O||!O[0]||!y.e&&O[0]==1&&O.length==1)return new C(O&&!O[0]?-1/0:y.s!=1?NaN:O?0:y);if(e==null?(w=!1,m=I):m=e,C.precision=m+=T,n=K(O),r=n.charAt(0),Math.abs(o=y.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)y=y.times(t),n=K(y.d),r=n.charAt(0),p++;o=y.e,r>1?(y=new C("0."+n),o++):y=new C(r+"."+n.slice(1))}else return u=Ve(C,m+2,I).times(o+""),y=pe(new C(r+"."+n.slice(1)),m-T).plus(u),C.precision=I,e==null?g(y,I,Q,w=!0):y;for(l=y,c=s=y=N(y.minus(1),y.plus(1),m,1),d=g(y.times(y),m,1),i=3;;){if(s=g(s.times(d),m,1),u=c.plus(N(s,new C(i),m,1)),K(u.d).slice(0,m)===K(c.d).slice(0,m))if(c=c.times(2),o!==0&&(c=c.plus(Ve(C,m+2,I).times(o+""))),c=N(c,new C(p),m,1),e==null)if(Se(c.d,m-T,Q,a))C.precision=m+=T,u=s=y=N(l.minus(1),l.plus(1),m,1),d=g(y.times(y),m,1),i=a=1;else return g(c,C.precision=I,Q,w=!0);else return C.precision=I,c;c=u,i+=2}}function Wt(t){return String(t.s*t.s/0)}function st(t,e){var n,r,i;for((n=e.indexOf("."))>-1&&(e=e.replace(".","")),(r=e.search(/e/i))>0?(n<0&&(n=r),n+=+e.slice(r+1),e=e.substring(0,r)):n<0&&(n=e.length),r=0;e.charCodeAt(r)===48;r++);for(i=e.length;e.charCodeAt(i-1)===48;--i);if(e=e.slice(r,i),e){if(i-=r,t.e=n=n-r-1,t.d=[],r=(n+1)%b,n<0&&(r+=b),r<i){for(r&&t.d.push(+e.slice(0,r)),i-=b;r<i;)t.d.push(+e.slice(r,r+=b));e=e.slice(r),r=b-e.length}else r-=i;for(;r--;)e+="0";t.d.push(+e),w&&(t.e>t.constructor.maxE?(t.d=null,t.e=NaN):t.e<t.constructor.minE&&(t.e=0,t.d=[0]))}else t.e=0,t.d=[0];return t}function Ln(t,e){var n,r,i,o,s,a,c,u,m;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),qt.test(e))return st(t,e)}else if(e==="Infinity"||e==="NaN")return+e||(t.s=NaN),t.e=NaN,t.d=null,t;if(Bn.test(e))n=16,e=e.toLowerCase();else if(kn.test(e))n=2;else if(In.test(e))n=8;else throw Error(ge+e);for(o=e.search(/p/i),o>0?(c=+e.slice(o+1),e=e.substring(2,o)):e=e.slice(2),o=e.indexOf("."),s=o>=0,r=t.constructor,s&&(e=e.replace(".",""),a=e.length,o=a-o,i=Vt(r,new r(n),o,o*2)),u=Ke(e,n,ne),m=u.length-1,o=m;u[o]===0;--o)u.pop();return o<0?new r(t.s*0):(t.e=We(u,m),t.d=u,w=!1,s&&(t=N(t,i,a*4)),c&&(t=t.times(Math.abs(c)<54?v(2,c):Ce.pow(2,c))),w=!0,t)}function Rn(t,e){var n,r=e.d.length;if(r<3)return e.isZero()?e:Pe(t,2,e,e);n=1.4*Math.sqrt(r),n=n>16?16:n|0,e=e.times(1/Xe(5,n)),e=Pe(t,2,e,e);for(var i,o=new t(5),s=new t(16),a=new t(20);n--;)i=e.times(e),e=e.times(o.plus(i.times(s.times(i).minus(a))));return e}function Pe(t,e,n,r,i){var o,s,a,c,u=1,m=t.precision,l=Math.ceil(m/b);for(w=!1,c=n.times(n),a=new t(r);;){if(s=N(a.times(c),new t(e++*e++),m,1),a=i?r.plus(s):r.minus(s),r=N(s.times(c),new t(e++*e++),m,1),s=a.plus(r),s.d[l]!==void 0){for(o=l;s.d[o]===a.d[o]&&o--;);if(o==-1)break}o=a,a=r,r=s,s=o,u++}return w=!0,s.d.length=l+1,s}function Xe(t,e){for(var n=t;--e;)n*=t;return n}function Xt(t,e){var n,r=e.s<0,i=te(t,t.precision,1),o=i.times(.5);if(e=e.abs(),e.lte(o))return ue=r?4:1,e;if(n=e.divToInt(i),n.isZero())ue=r?3:2;else{if(e=e.minus(n.times(i)),e.lte(o))return ue=_t(n)?r?2:3:r?4:1,e;ue=_t(n)?r?1:4:r?3:2}return e.minus(i).abs()}function at(t,e,n,r){var i,o,s,a,c,u,m,l,d,p=t.constructor,T=n!==void 0;if(T?(H(n,1,he),r===void 0?r=p.rounding:H(r,0,8)):(n=p.precision,r=p.rounding),!t.isFinite())m=Wt(t);else{for(m=re(t),s=m.indexOf("."),T?(i=2,e==16?n=n*4-3:e==8&&(n=n*3-2)):i=e,s>=0&&(m=m.replace(".",""),d=new p(1),d.e=m.length-s,d.d=Ke(re(d),10,i),d.e=d.d.length),l=Ke(m,10,i),o=c=l.length;l[--c]==0;)l.pop();if(!l[0])m=T?"0p+0":"0";else{if(s<0?o--:(t=new p(t),t.d=l,t.e=o,t=N(t,d,n,r,0,i),l=t.d,o=t.e,u=vt),s=l[n],a=i/2,u=u||l[n+1]!==void 0,u=r<4?(s!==void 0||u)&&(r===0||r===(t.s<0?3:2)):s>a||s===a&&(r===4||u||r===6&&l[n-1]&1||r===(t.s<0?8:7)),l.length=n,u)for(;++l[--n]>i-1;)l[n]=0,n||(++o,l.unshift(1));for(c=l.length;!l[c-1];--c);for(s=0,m="";s<c;s++)m+=nt.charAt(l[s]);if(T){if(c>1)if(e==16||e==8){for(s=e==16?4:3,--c;c%s;c++)m+="0";for(l=Ke(m,i,e),c=l.length;!l[c-1];--c);for(s=1,m="1.";s<c;s++)m+=nt.charAt(l[s])}else m=m.charAt(0)+"."+m.slice(1);m=m+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)m="0"+m;m="0."+m}else if(++o>c)for(o-=c;o--;)m+="0";else o<c&&(m=m.slice(0,o)+"."+m.slice(o))}m=(e==16?"0x":e==2?"0b":e==8?"0o":"")+m}return t.s<0?"-"+m:m}function Ft(t,e){if(t.length>e)return t.length=e,!0}function En(t){return new this(t).abs()}function _n(t){return new this(t).acos()}function Fn(t){return new this(t).acosh()}function Mn(t,e){return new this(t).plus(e)}function vn(t){return new this(t).asin()}function Dn(t){return new this(t).asinh()}function On(t){return new this(t).atan()}function Kn(t){return new this(t).atanh()}function qn(t,e){t=new this(t),e=new this(e);var n,r=this.precision,i=this.rounding,o=r+4;return!t.s||!e.s?n=new this(NaN):!t.d&&!e.d?(n=te(this,o,1).times(e.s>0?.25:.75),n.s=t.s):!e.d||t.isZero()?(n=e.s<0?te(this,r,i):new this(0),n.s=t.s):!t.d||e.isZero()?(n=te(this,o,1).times(.5),n.s=t.s):e.s<0?(this.precision=o,this.rounding=1,n=this.atan(N(t,e,o,1)),e=te(this,o,1),this.precision=r,this.rounding=i,n=t.s<0?n.minus(e):n.plus(e)):n=this.atan(N(t,e,o,1)),n}function Gn(t){return new this(t).cbrt()}function Vn(t){return g(t=new this(t),t.e+1,2)}function Un(t,e,n){return new this(t).clamp(e,n)}function Wn(t){if(!t||typeof t!="object")throw Error(Ue+"Object expected");var e,n,r,i=t.defaults===!0,o=["precision",1,he,"rounding",0,8,"toExpNeg",-Ae,0,"toExpPos",0,Ae,"maxE",0,Ae,"minE",-Ae,0,"modulo",0,9];for(e=0;e<o.length;e+=3)if(n=o[e],i&&(this[n]=rt[n]),(r=t[n])!==void 0)if(U(r)===r&&r>=o[e+1]&&r<=o[e+2])this[n]=r;else throw Error(ge+n+": "+r);if(n="crypto",i&&(this[n]=rt[n]),(r=t[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(Ot);else this[n]=!1;else throw Error(ge+n+": "+r);return this}function Xn(t){return new this(t).cos()}function Hn(t){return new this(t).cosh()}function Ht(t){var e,n,r;function i(o){var s,a,c,u=this;if(!(u instanceof i))return new i(o);if(u.constructor=i,Mt(o)){u.s=o.s,w?!o.d||o.e>i.maxE?(u.e=NaN,u.d=null):o.e<i.minE?(u.e=0,u.d=[0]):(u.e=o.e,u.d=o.d.slice()):(u.e=o.e,u.d=o.d?o.d.slice():o.d);return}if(c=typeof o,c==="number"){if(o===0){u.s=1/o<0?-1:1,u.e=0,u.d=[0];return}if(o<0?(o=-o,u.s=-1):u.s=1,o===~~o&&o<1e7){for(s=0,a=o;a>=10;a/=10)s++;w?s>i.maxE?(u.e=NaN,u.d=null):s<i.minE?(u.e=0,u.d=[0]):(u.e=s,u.d=[o]):(u.e=s,u.d=[o]);return}else if(o*0!==0){o||(u.s=NaN),u.e=NaN,u.d=null;return}return st(u,o.toString())}else if(c!=="string")throw Error(ge+o);return(a=o.charCodeAt(0))===45?(o=o.slice(1),u.s=-1):(a===43&&(o=o.slice(1)),u.s=1),qt.test(o)?st(u,o):Ln(u,o)}if(i.prototype=f,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=Wn,i.clone=Ht,i.isDecimal=Mt,i.abs=En,i.acos=_n,i.acosh=Fn,i.add=Mn,i.asin=vn,i.asinh=Dn,i.atan=On,i.atanh=Kn,i.atan2=qn,i.cbrt=Gn,i.ceil=Vn,i.clamp=Un,i.cos=Xn,i.cosh=Hn,i.div=zn,i.exp=Zn,i.floor=Yn,i.hypot=jn,i.ln=Jn,i.log=Qn,i.log10=er,i.log2=$n,i.max=tr,i.min=nr,i.mod=rr,i.mul=ir,i.pow=or,i.random=sr,i.round=ar,i.sign=ur,i.sin=cr,i.sinh=mr,i.sqrt=lr,i.sub=dr,i.sum=fr,i.tan=pr,i.tanh=gr,i.trunc=hr,t===void 0&&(t={}),t&&t.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<r.length;)t.hasOwnProperty(n=r[e++])||(t[n]=this[n]);return i.config(t),i}function zn(t,e){return new this(t).div(e)}function Zn(t){return new this(t).exp()}function Yn(t){return g(t=new this(t),t.e+1,3)}function jn(){var t,e,n=new this(0);for(w=!1,t=0;t<arguments.length;)if(e=new this(arguments[t++]),e.d)n.d&&(n=n.plus(e.times(e)));else{if(e.s)return w=!0,new this(1/0);n=e}return w=!0,n.sqrt()}function Mt(t){return t instanceof Ce||t&&t.toStringTag===Kt||!1}function Jn(t){return new this(t).ln()}function Qn(t,e){return new this(t).log(e)}function $n(t){return new this(t).log(2)}function er(t){return new this(t).log(10)}function tr(){return Ut(this,arguments,"lt")}function nr(){return Ut(this,arguments,"gt")}function rr(t,e){return new this(t).mod(e)}function ir(t,e){return new this(t).mul(e)}function or(t,e){return new this(t).pow(e)}function sr(t){var e,n,r,i,o=0,s=new this(1),a=[];if(t===void 0?t=this.precision:H(t,1,he),r=Math.ceil(t/b),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(r));o<r;)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(r*=4);o<r;)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=r/4}else throw Error(Ot);else for(;o<r;)a[o++]=Math.random()*1e7|0;for(r=a[--o],t%=b,r&&t&&(i=v(10,b-t),a[o]=(r/i|0)*i);a[o]===0;o--)a.pop();if(o<0)n=0,a=[0];else{for(n=-1;a[0]===0;n-=b)a.shift();for(r=1,i=a[0];i>=10;i/=10)r++;r<b&&(n-=b-r)}return s.e=n,s.d=a,s}function ar(t){return g(t=new this(t),t.e+1,this.rounding)}function ur(t){return t=new this(t),t.d?t.d[0]?t.s:0*t.s:t.s||NaN}function cr(t){return new this(t).sin()}function mr(t){return new this(t).sinh()}function lr(t){return new this(t).sqrt()}function dr(t,e){return new this(t).sub(e)}function fr(){var t=0,e=arguments,n=new this(e[t]);for(w=!1;n.s&&++t<e.length;)n=n.plus(e[t]);return w=!0,g(n,this.precision,this.rounding)}function pr(t){return new this(t).tan()}function gr(t){return new this(t).tanh()}function hr(t){return g(t=new this(t),t.e+1,1)}f[Symbol.for("nodejs.util.inspect.custom")]=f.toString;f[Symbol.toStringTag]="Decimal";var Ce=f.constructor=Ht(rt);qe=new Ce(qe);Ge=new Ce(Ge);var W=Ce;import j from"bn.js";var ie=new j(0),ke=new j(1),zt=new j(-1),He=new j(1).shln(64),ze=new j(1).shln(128),br=He.sub(ke),ut=64,Zt=ze.subn(1),ce=-443636,be=-ce,ct=new j("4295048016"),mt=new j("79226673521066979257578248091"),fi=new j("4295048017"),pi=new j("79226673521066979257578248090"),Yt=16,jt="59543866431248",Jt="184467440737095516",Qt="15793534762490258745",yr=new j(10).pow(new j(6));var gi=new j("18446744073700000000");import B from"bn.js";import yi from"bn.js";import{PublicKey as xr}from"@solana/web3.js";import{get as $t,set as wr}from"lodash";var lt=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 n=e.map(r=>typeof r=="object"?JSON.stringify(r):r).join(", ");throw new Error(n)}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}},en={},Tr={};function J(t){let e=$t(en,t);if(!e){let n=$t(Tr,t);e=new lt({name:t,logLevel:n}),wr(en,t,e)}return e}import{MINT_SIZE as Ci,TOKEN_PROGRAM_ID as Li,getTransferFeeConfig as Ri,unpackMint as Ei}from"@solana/spl-token";var dt=J("Raydium_accountInfo_util");async function Ze(t,e,n){let{batchRequest:r,commitment:i="confirmed",chunkCount:o=100}=ee({batchRequest:!1},n),s=ft(e,o),a=new Array(s.length).fill([]);if(r){let c=s.map(l=>{let d=t._buildArgs([l.map(p=>p.toBase58())],i,"base64");return{methodName:"getMultipleAccounts",args:d}}),u=ft(c,10);a=(await(await Promise.all(u.map(async l=>await t._rpcBatchRequest(l)))).flat()).map(l=>(l.error&&dt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${l.error.message}`),l.result.value.map(d=>{if(d){let{data:p,executable:T,lamports:y,owner:O,rentEpoch:C}=d;return p.length!==2&&p[1]!=="base64"&&dt.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(p[0],"base64"),executable:T,lamports:y,owner:new xr(O),rentEpoch:C}}return null})))}else try{a=await Promise.all(s.map(c=>t.getMultipleAccountsInfo(c,i)))}catch(c){c instanceof Error&&dt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return a.flat()}import le from"bn.js";import Lr from"big.js";import Yi from"bn.js";import Pr from"toformat";var kr=Pr,Le=kr;import je from"big.js";import Ir from"bn.js";import Nr from"decimal.js-light";import Re from"bn.js";var tn=9007199254740991;function me(t){let e=J("Raydium_parseBigNumberish");if(t instanceof Re)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new Re(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=tn||t<=-tn)&&e.logWithError(`BigNumberish number overflow: ${t}`),new Re(String(t))):typeof t=="bigint"?new Re(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new Re(0))}var Ye=J("module/fraction"),gt=Le(je),Ee=Le(Nr),Sr={[0]:Ee.ROUND_DOWN,[1]:Ee.ROUND_HALF_UP,[2]:Ee.ROUND_UP},Cr={[0]:je.roundDown,[1]:je.roundHalfUp,[2]:je.roundUp},L=class{constructor(e,n=new Ir(1)){this.numerator=me(e),this.denominator=me(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new L(this.denominator,this.numerator)}add(e){let n=e instanceof L?e:new L(me(e));return this.denominator.eq(n.denominator)?new L(this.numerator.add(n.numerator),this.denominator):new L(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(e){let n=e instanceof L?e:new L(me(e));return this.denominator.eq(n.denominator)?new L(this.numerator.sub(n.numerator),this.denominator):new L(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(e){let n=e instanceof L?e:new L(me(e));return new L(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(e){let n=e instanceof L?e:new L(me(e));return new L(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(e,n={groupSeparator:""},r=1){Number.isInteger(e)||Ye.logWithError(`${e} is not an integer.`),e<=0&&Ye.logWithError(`${e} is not positive.`),Ee.set({precision:e+1,rounding:Sr[r]});let i=new Ee(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return i.toFormat(i.decimalPlaces(),n)}toFixed(e,n={groupSeparator:""},r=1){return Number.isInteger(e)||Ye.logWithError(`${e} is not an integer.`),e<0&&Ye.logWithError(`${e} is negative.`),gt.DP=e,gt.RM=Cr[r]||1,new gt(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};var io=J("Raydium_amount"),oo=Le(Lr);import{PublicKey as Er}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as nn}from"@solana/spl-token";var rn={chainId:101,address:Er.default.toBase58(),programId:nn.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},we={chainId:101,address:"So11111111111111111111111111111111111111112",programId:nn.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}};import{PublicKey as bt}from"@solana/web3.js";import{PublicKey as R,SystemProgram as on,SYSVAR_RENT_PUBKEY as _r}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Fr}from"@solana/spl-token";function ht({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var po=[ht({pubkey:Fr,isWritable:!1}),ht({pubkey:on.programId,isWritable:!1}),ht({pubkey:_r,isWritable:!1})];function sn({publicKey:t,transformSol:e}){let n=an(t.toString());if(n instanceof R)return e&&n.equals(_e)?pt:n;if(e&&n.toString()===_e.toBase58())return pt;if(typeof n=="string"){if(n===R.default.toBase58())return R.default;try{return new R(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function an(t){try{return new R(t)}catch{return t}}var go=new R("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),ho=new R("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),bo=new R("SysvarRent111111111111111111111111111111111"),yo=new R("SysvarC1ock11111111111111111111111111111111"),Mr=new R("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),wo=new R("Sysvar1nstructions1111111111111111111111111"),To=on.programId,xo=new R("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Ao=new R("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Po=new R("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),ko=new R("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Bo=new R("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Io=new R("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),No=new R("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),So=new R("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Co=new R("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Lo=new R("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Ro=new R("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),pt=new R("So11111111111111111111111111111111111111112"),_e=R.default;var yt=class{constructor({mint:e,decimals:n,symbol:r,name:i,skipMint:o=!1,isToken2022:s=!1}){if(e===_e.toBase58()||e instanceof bt&&_e.equals(e)){this.decimals=we.decimals,this.symbol=we.symbol,this.name=we.name,this.mint=new bt(we.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||e.toString().substring(0,6),this.name=i||e.toString().substring(0,6),this.mint=o?bt.default:sn({publicKey:e}),this.isToken2022=s}equals(e){return this===e?!0:this.mint.equals(e.mint)}},Te=yt;Te.WSOL=new yt(ae(ee({},we),{mint:we.address}));var wt=class{constructor({decimals:e,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=r}equals(e){return this===e}},Je=wt;Je.SOL=new wt(rn);import vr from"bn.js";var Uo=new L(new vr(100));var Yo=J("Raydium_price");var Dr=new le(0),Ps=new le(1),ks=new le(2),Bs=new le(3),Is=new le(5),Rr=new le(10),Ns=new le(100),Ss=new le(1e3),Cs=new le(1e4);function ft(t,e=1,n=[]){let r=[...t];if(e<=0)return n;for(;r.length;)n.push(r.splice(0,e));return n}import{PublicKey as $s}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ta}from"@solana/spl-token";import{ComputeBudgetProgram as Ds,Keypair as qs,PublicKey as Kr,Transaction as Vs,TransactionMessage as Ws,VersionedTransaction as Xs}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Ys}from"@solana/spl-token";var js=J("Raydium_txUtil");function Pt(t,e){let[n,r]=Kr.findProgramAddressSync(t,e);return{publicKey:n,nonce:r}}import{PublicKey as h}from"@solana/web3.js";var oa=new h("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),sa=new h("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),aa=new h("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),ua=new h("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),ca=new h("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),ma=new h("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),la=new h("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),da=new h("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),fa=new h("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),pa=new h("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),ga=new h("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),ha=new h("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),ba=new h("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),ya=new h("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),wa=new h("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Ta=new h("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),xa=new h("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Aa=new h("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),Pa=new h("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),ka=new h("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),Ba=new h("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),Ia=new h("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Na=new h("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),Sa=new h("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),Ca=new h("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),La=new h("LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj"),Ra=new h("WLHv2UAZm6z4KyaaELi5pjdbJh6RESMva1Rnn8pJVVh"),Ea=new h("DRay6fNdQ5J82H7xV6uq2aV3mNrUZ1J4PgSKsWgptcm6"),_a=new h("5xqNaZXX5eUi4p5HU4oz9i5QnwRNT2y6oN7yyn4qENeq"),Fa=new h("4Bu96XjU84XjPDSpveTVf6LYGCkfW5FK7SNkREWcEfV4"),Ma=new h("6s1xP3hpbAfFoNtUNF8mfHsjr2Bd97JxFJRWLbL6aHuX");var va={OPEN_BOOK_PROGRAM:new h("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),SERUM_PROGRAM_ID_V3:new h("Ray1111111111111111111111111111111111111111"),AMM_V4:new h("DRaya7Kj3aMWQSy19kSjvmuwq9docCHofyP9kanQGaav"),AMM_STABLE:new h("DRayDdXc1NZQ9C3hRWmoSf8zK4iapgMnjdNZWrfwsP8m"),CLMM_PROGRAM_ID:new h("DRayAUgENGQBKVaX8owNhgzkEDyoHTGVEGHVJT1E9pfH"),CLMM_LOCK_PROGRAM_ID:new h("DRay25Usp3YJAi7beckgpGUC7mGJ2cR1AVPxhYfwVCUX"),CLMM_LOCK_AUTH_ID:new h("6Aoh8h2Lw2m5UGxYR8AdAL87jTWYeKoxM52mJRzfYwN"),CREATE_CPMM_POOL_PROGRAM:new h("DRaycpLY18LhpbydsBWbVJtxpNv9oXPgjRSfpF2bWpYb"),CREATE_CPMM_POOL_AUTH:new h("CXniRufdq5xL8t8jZAPxsPZDpuudwuJSPWnbcD5Y5Nxq"),CREATE_CPMM_POOL_FEE_ACC:new h("3oE58BKVt8KuYkGxx8zBojugnymWmBiyafWgMrnb6eYy"),LOCK_CPMM_PROGRAM:new h("DRay25Usp3YJAi7beckgpGUC7mGJ2cR1AVPxhYfwVCUX"),LOCK_CPMM_AUTH:new h("7qWVV8UY2bRJfDLP4s37YzBPKUkVB46DStYJBpYbQzu3"),UTIL1216:h.default,Router:new h("DRaybByLpbUL57LJARs3j8BitTxVfzBg351EaMr5UTCd"),FARM_PROGRAM_ID_V3:new h("DRayWyrLmEW5KEeqs8kdTMMaBabapqagaBC7KWpGtJeZ"),FARM_PROGRAM_ID_V4:new h("Ray1111111111111111111111111111111111111111"),FARM_PROGRAM_ID_V5:new h("DRayiCGSZgku1GTK6rXD6mVDdingXy6APAH1R6R5L2LC"),FARM_PROGRAM_ID_V6:new h("DRayzbYakXs45ELHkzH6vC3fuhQqTAnv5A68gdFuvZyZ"),LAUNCHPAD_PROGRAM:new h("DRay6fNdQ5J82H7xV6uq2aV3mNrUZ1J4PgSKsWgptcm6"),LAUNCHPAD_AUTH:new h("5xqNaZXX5eUi4p5HU4oz9i5QnwRNT2y6oN7yyn4qENeq"),LAUNCHPAD_PLATFORM:new h("2Jx4KTDrVSdWNazuGpcA8n3ZLTRGGBDxAWhuKe2Xcj2a"),LAUNCHPAD_CONFIG:new h("7ZR4zD7PYfY2XxoG1Gxcy2EgEeGYrpxrwzPuwdUBssEt"),FEE_DESTINATION_ID:new h("9y8ENuuZ3b19quffx9hQvRVygG5ky6snHfRvGpuSfeJy"),MODEL_DATA_PUBKEY:new h("Ray1111111111111111111111111111111111111111")};import{PublicKey as qa,AddressLookupTableAccount as Ga}from"@solana/web3.js";import{PublicKey as iu,sendAndConfirmTransaction as ou,SystemProgram as uu,Transaction as cu,TransactionMessage as lu,VersionedTransaction as du}from"@solana/web3.js";import pu from"axios";import{PublicKey as xu}from"@solana/web3.js";import Pu from"bn.js";import qr from"bn.js";var Su=new qr(1e6);function un(t){let e=new ArrayBuffer(4);return new DataView(e).setInt32(0,t,!1),new Uint8Array(e)}var $u=Buffer.from("amm_config","utf8"),ec=Buffer.from("pool","utf8"),tc=Buffer.from("pool_vault","utf8"),nc=Buffer.from("pool_reward_vault","utf8"),rc=Buffer.from("position","utf8"),Gr=Buffer.from("tick_array","utf8"),ic=Buffer.from("operation","utf8"),oc=Buffer.from("pool_tick_array_bitmap_extension","utf8"),sc=Buffer.from("observation","utf8");function de(t,e,n){return Pt([Gr,e.toBuffer(),un(n)],t)}var ac=Buffer.from("locked_position","utf8");var uc=Buffer.from("support_mint","utf8");import{PublicKey as Jm}from"@solana/web3.js";import{TOKEN_2022_PROGRAM_ID as $m}from"@solana/spl-token";import tl from"bn.js";import{PublicKey as jr}from"@solana/web3.js";import dn,{isBN as fn}from"bn.js";import{bits as lc,BitStructure as dc,blob as Vr,Blob as fc,cstr as pc,f32 as gc,f32be as hc,f64 as bc,f64be as yc,greedy as wc,Layout as Ur,ns64 as Tc,ns64be as xc,nu64 as Ac,nu64be as Pc,offset as kc,s16 as Bc,s16be as Ic,s24 as Nc,s24be as Sc,s32 as Wr,s32be as Cc,s40 as Lc,s40be as Rc,s48 as Ec,s48be as _c,s8 as Fc,seq as Xr,struct as Mc,Structure as Hr,u16 as zr,u16be as vc,u24 as Dc,u24be as Oc,u32 as Kc,u32be as qc,u40 as Gc,u40be as Vc,u48 as Uc,u48be as Wc,u8 as Zr,UInt as Yr,union as Xc,Union as Hc,unionLayoutDiscriminator as zc,utf8 as Zc}from"@solana/buffer-layout";var kt=Ur,cn=Hr;var Bt=Yr;var mn=Zr,Fe=zr;var ye=Wr;var ln=Xr;var Z=Vr;var Be=class extends kt{constructor(n,r,i){super(n,i);this.blob=Z(n),this.signed=r}decode(n,r=0){let i=new dn(this.blob.decode(n,r),10,"le");return this.signed?i.fromTwos(this.span*8).clone():i}encode(n,r,i=0){return typeof n=="number"&&(n=new dn(n)),this.signed&&(n=n.toTwos(this.span*8)),this.blob.encode(n.toArrayLike(Buffer,"le",this.span),r,i)}};function z(t){return new Bt(1,t)}function Ie(t){return new Bt(4,t)}function P(t){return new Be(8,!1,t)}function _(t){return new Be(16,!1,t)}function pn(t){return new Be(8,!0,t)}function gn(t){return new Be(16,!0,t)}var Qe=class extends kt{constructor(n,r,i,o){super(n.span,o);this.layout=n,this.decoder=r,this.encoder=i}decode(n,r){return this.decoder(this.layout.decode(n,r))}encode(n,r,i){return this.layout.encode(this.encoder(n),r,i)}getSpan(n,r){return this.layout.getSpan(n,r)}};function k(t){return new Qe(Z(32),e=>new jr(e),e=>e.toBuffer(),t)}function hn(t){return new Qe(mn(),Jr,Qr,t)}function Jr(t){if(t===0)return!1;if(t===1)return!0;throw new Error("Invalid bool: "+t)}function Qr(t){return t?1:0}var It=class extends cn{decode(e,n){return super.decode(e,n)}};function X(t,e,n){return new It(t,e,n)}function E(t,e,n){let r,i=typeof e=="number"?e:fn(e)?e.toNumber():new Proxy(e,{get(o,s){if(!r){let a=Reflect.get(o,"count");r=fn(a)?a.toNumber():a,Reflect.set(o,"count",r)}return Reflect.get(o,s)},set(o,s,a){return s==="count"&&(r=a),Reflect.set(o,s,a)}});return ln(t,i,n)}var $r=15,Y=class{static async getTickArrays(e,n,r,i,o,s,a){let c=[],u=F.getTickArrayStartIndexByTick(i,o),m=F.getInitializedTickArrayInRange(s,a,o,u,Math.floor($r/2));for(let p=0;p<m.length;p++){let{publicKey:T}=de(n,r,m[p]);c.push(T)}let l=(await Ze(e,c)).map(p=>p!==null?Nt.decode(p.data):null),d={};for(let p=0;p<c.length;p++){let T=l[p];T!==null&&(d[T.startTickIndex]=ae(ee({},T),{address:c[p]}))}return d}static nextInitializedTick(e,n,r,i,o,s){let{initializedTick:a,tickArrayAddress:c,tickArrayStartTickIndex:u}=this.nextInitializedTickInOneArray(e,n,r,i,o,s);for(;a==null||a.liquidityGross.lten(0);){if(u=F.getNextTickArrayStartIndex(u,o,s),this.checkIsValidStartIndex(u,o))throw new Error("No enough initialized tickArray");let m=r[u];if(m===void 0)continue;let{nextTick:l,tickArrayAddress:d,tickArrayStartTickIndex:p}=this.firstInitializedTickInOneArray(e,n,m,s);[a,c,u]=[l,d,p]}if(a==null)throw new Error("No invaild tickArray cache");return{nextTick:a,tickArrayAddress:c,tickArrayStartTickIndex:u}}static nextInitializedTickArray(e,n,r,i,o){let s=Math.floor(e/Y.tickCount(n)),a=r?F.searchLowBitFromStart(i,o,s-1,1,n):F.searchHightBitFromStart(i,o,s+1,1,n);return a.length>0?{isExist:!0,nextStartIndex:a[0]}:{isExist:!1,nextStartIndex:0}}static firstInitializedTickInOneArray(e,n,r,i){let o;if(i){let a=q-1;for(;a>=0;){let c=r.ticks[a];if(c.liquidityGross.gtn(0)){o=c;break}a=a-1}}else{let a=0;for(;a<q;){let c=r.ticks[a];if(c.liquidityGross.gtn(0)){o=c;break}a=a+1}}let{publicKey:s}=de(e,n,r.startTickIndex);return{nextTick:o,tickArrayAddress:s,tickArrayStartTickIndex:r.startTickIndex}}static nextInitializedTickInOneArray(e,n,r,i,o,s){let a=F.getTickArrayStartIndexByTick(i,o),c=Math.floor((i-a)/o),u=r[a];if(u==null)return{initializedTick:void 0,tickArrayAddress:void 0,tickArrayStartTickIndex:a};let m;if(s)for(;c>=0;){let d=u.ticks[c];if(d.liquidityGross.gtn(0)){m=d;break}c=c-1}else for(c=c+1;c<q;){let d=u.ticks[c];if(d.liquidityGross.gtn(0)){m=d;break}c=c+1}let{publicKey:l}=de(e,n,a);return{initializedTick:m,tickArrayAddress:l,tickArrayStartTickIndex:u.startTickIndex}}static getArrayStartIndex(e,n){let r=this.tickCount(n);return Math.floor(e/r)*r}static checkIsValidStartIndex(e,n){if(F.checkIsOutOfBoundary(e)){if(e>be)return!1;let r=F.getTickArrayStartIndexByTick(ce,n);return e==r}return e%this.tickCount(n)==0}static tickCount(e){return q*e}};var St=14;var Sm=X([Z(8),z("bump"),Fe("index"),k(""),Ie("protocolFeeRate"),Ie("tradeFeeRate"),Fe("tickSpacing"),E(P(),8,"")]),ei=X([Ie("blockTimestamp"),pn("tickCumulative"),E(P(),4)]),Cm=X([Z(8),hn("initialized"),P("recentEpoch"),Fe("observationIndex"),k("poolId"),E(ei,100,"observations"),E(P(),4)]),ti=X([z("rewardState"),P("openTime"),P("endTime"),P("lastUpdateTime"),_("emissionsPerSecondX64"),P("rewardTotalEmissioned"),P("rewardClaimed"),k("tokenMint"),k("tokenVault"),k("creator"),_("rewardGrowthGlobalX64")]),ni=X([Z(8),z("bump"),k("ammConfig"),k("creator"),k("mintA"),k("mintB"),k("vaultA"),k("vaultB"),k("observationId"),z("mintDecimalsA"),z("mintDecimalsB"),Fe("tickSpacing"),_("liquidity"),_("sqrtPriceX64"),ye("tickCurrent"),Ie(),_("feeGrowthGlobalX64A"),_("feeGrowthGlobalX64B"),P("protocolFeesTokenA"),P("protocolFeesTokenB"),_("swapInAmountTokenA"),_("swapOutAmountTokenB"),_("swapInAmountTokenB"),_("swapOutAmountTokenA"),z("status"),E(z(),7,""),E(ti,3,"rewardInfos"),E(P(),16,"tickArrayBitmap"),P("totalFeesTokenA"),P("totalFeesClaimedTokenA"),P("totalFeesTokenB"),P("totalFeesClaimedTokenB"),P("fundFeesTokenA"),P("fundFeesTokenB"),P("startTime"),E(P(),15*4-3,"padding")]),ri=X([_("growthInsideLastX64"),P("rewardAmountOwed")]),ii=X([Z(8),z("bump"),k("nftMint"),k("poolId"),ye("tickLower"),ye("tickUpper"),_("liquidity"),_("feeGrowthInsideLastX64A"),_("feeGrowthInsideLastX64B"),P("tokenFeesOwedA"),P("tokenFeesOwedB"),E(ri,3,"rewardInfos"),E(P(),8,"")]),Lm=X([Z(8),z("bump"),k("poolId"),ye("tickLowerIndex"),ye("tickUpperIndex"),_("liquidity"),_("feeGrowthInsideLastX64A"),_("feeGrowthInsideLastX64B"),P("tokenFeesOwedA"),P("tokenFeesOwedB"),E(_(),3,"rewardGrowthInside"),E(P(),8,"")]),oi=X([ye("tick"),gn("liquidityNet"),_("liquidityGross"),_("feeGrowthOutsideX64A"),_("feeGrowthOutsideX64B"),E(_(),3,"rewardGrowthsOutsideX64"),E(Ie(),13,"")]),Nt=X([Z(8),k("poolId"),ye("startTickIndex"),E(oi,q,"ticks"),z("initializedTickCount"),E(z(),115,"")]),Rm=X([Z(329),E(k(),100,"whitelistMints")]),si=X([Z(8),k("poolId"),E(E(P(),8),St,"positiveTickArrayBitmap"),E(E(P(),8),St,"negativeTickArrayBitmap")]),Em=X([P(),z("bump"),k("owner"),k("poolId"),k("positionId"),k("nftAccount"),E(P(),8)]),_m=X([Z(8),z("bump"),k("lockOwner"),k("poolId"),k("positionId"),k("nftAccount"),k("lockNftMint"),P("recentEpoch"),E(P(),8)]);import vm from"bn.js";var oe=class{static mulDivRoundingUp(e,n,r){let i=e.mul(n),o=i.div(r);return i.mod(r).eq(ie)||(o=o.add(ke)),o}static mulDivFloor(e,n,r){if(r.eq(ie))throw new Error("division by 0");return e.mul(n).div(r)}static mulDivCeil(e,n,r){if(r.eq(ie))throw new Error("division by 0");return e.mul(n).add(r.sub(ke)).div(r)}static x64ToDecimal(e,n){return new W(e.toString()).div(W.pow(2,64)).toDecimalPlaces(n)}static decimalToX64(e){return new B(e.mul(W.pow(2,64)).floor().toFixed())}static wrappingSubU128(e,n){return e.add(ze).sub(n).mod(ze)}};function D(t,e){return Lt(t.mul(e),64,256)}function ui(t,e,n){let r=t.toTwos(n).shln(e);return r.imaskn(n+1),r.fromTwos(n)}function Lt(t,e,n){let r=t.toTwos(n).shrn(e);return r.imaskn(n-e+1),r.fromTwos(n-e)}var M=class{static sqrtPriceX64ToPrice(e,n,r){return oe.x64ToDecimal(e).pow(2).mul(W.pow(10,n-r))}static priceToSqrtPriceX64(e,n,r){return oe.decimalToX64(e.mul(W.pow(10,r-n)).sqrt())}static getNextSqrtPriceX64FromInput(e,n,r,i){if(!e.gt(ie))throw new Error("sqrtPriceX64 must greater than 0");if(!n.gt(ie))throw new Error("liquidity must greater than 0");return i?this.getNextSqrtPriceFromTokenAmountARoundingUp(e,n,r,!0):this.getNextSqrtPriceFromTokenAmountBRoundingDown(e,n,r,!0)}static getNextSqrtPriceX64FromOutput(e,n,r,i){if(!e.gt(ie))throw new Error("sqrtPriceX64 must greater than 0");if(!n.gt(ie))throw new Error("liquidity must greater than 0");return i?this.getNextSqrtPriceFromTokenAmountBRoundingDown(e,n,r,!1):this.getNextSqrtPriceFromTokenAmountARoundingUp(e,n,r,!1)}static getNextSqrtPriceFromTokenAmountARoundingUp(e,n,r,i){if(r.eq(ie))return e;let o=n.shln(ut);if(i){let s=o,a=o.add(r.mul(e));return a.gte(s)?oe.mulDivCeil(s,e,a):oe.mulDivRoundingUp(s,ke,s.div(e).add(r))}else{let s=r.mul(e);if(!o.gt(s))throw new Error("getNextSqrtPriceFromTokenAmountARoundingUp,liquidityLeftShift must gt amountMulSqrtPrice");let a=o.sub(s);return oe.mulDivCeil(o,e,a)}}static getNextSqrtPriceFromTokenAmountBRoundingDown(e,n,r,i){let o=r.shln(ut);if(i)return e.add(o.div(n));{let s=oe.mulDivRoundingUp(o,ke,n);if(!e.gt(s))throw new Error("getNextSqrtPriceFromTokenAmountBRoundingDown sqrtPriceX64 must gt amountDivLiquidity");return e.sub(s)}}static getSqrtPriceX64FromTick(e){if(!Number.isInteger(e))throw new Error("tick must be integer");if(e<ce||e>be)throw new Error("tick must be in MIN_TICK and MAX_TICK");let n=e<0?e*-1:e,r=(n&1)!=0?new B("18445821805675395072"):new B("18446744073709551616");return(n&2)!=0&&(r=D(r,new B("18444899583751176192"))),(n&4)!=0&&(r=D(r,new B("18443055278223355904"))),(n&8)!=0&&(r=D(r,new B("18439367220385607680"))),(n&16)!=0&&(r=D(r,new B("18431993317065453568"))),(n&32)!=0&&(r=D(r,new B("18417254355718170624"))),(n&64)!=0&&(r=D(r,new B("18387811781193609216"))),(n&128)!=0&&(r=D(r,new B("18329067761203558400"))),(n&256)!=0&&(r=D(r,new B("18212142134806163456"))),(n&512)!=0&&(r=D(r,new B("17980523815641700352"))),(n&1024)!=0&&(r=D(r,new B("17526086738831433728"))),(n&2048)!=0&&(r=D(r,new B("16651378430235570176"))),(n&4096)!=0&&(r=D(r,new B("15030750278694412288"))),(n&8192)!=0&&(r=D(r,new B("12247334978884435968"))),(n&16384)!=0&&(r=D(r,new B("8131365268886854656"))),(n&32768)!=0&&(r=D(r,new B("3584323654725218816"))),(n&65536)!=0&&(r=D(r,new B("696457651848324352"))),(n&131072)!=0&&(r=D(r,new B("26294789957507116"))),(n&262144)!=0&&(r=D(r,new B("37481735321082"))),e>0&&(r=Zt.div(r)),r}static getTickFromPrice(e,n,r){return M.getTickFromSqrtPriceX64(M.priceToSqrtPriceX64(e,n,r))}static getTickFromSqrtPriceX64(e){if(e.gt(mt)||e.lt(ct))throw new Error("Provided sqrtPrice is not within the supported sqrtPrice range.");let n=e.bitLength()-1,r=new B(n-64),i=ui(r,32,128),o=new B("8000000000000000","hex"),s=0,a=new B(0),c=n>=64?e.shrn(n-63):e.shln(63-n);for(;o.gt(new B(0))&&s<Yt;){c=c.mul(c);let T=c.shrn(127);c=c.shrn(63+T.toNumber()),a=a.add(o.mul(T)),o=o.shrn(1),s+=1}let u=a.shrn(32),l=i.add(u).mul(new B(jt)),d=Lt(l.sub(new B(Jt)),64,128).toNumber(),p=Lt(l.add(new B(Qt)),64,128).toNumber();return d==p?d:M.getSqrtPriceX64FromTick(p).lte(e)?p:d}},xe=class{static getTickWithPriceAndTickspacing(e,n,r,i){let s=M.getTickFromSqrtPriceX64(M.priceToSqrtPriceX64(e,r,i))/n;return s<0?s=Math.floor(s):s=Math.ceil(s),s*n}static roundPriceWithTickspacing(e,n,r,i){let o=xe.getTickWithPriceAndTickspacing(e,n,r,i),s=M.getSqrtPriceX64FromTick(o);return M.sqrtPriceX64ToPrice(s,r,i)}};var q=60,Ct=512,F=class{static getTickArrayAddressByTick(e,n,r,i){let o=F.getTickArrayStartIndexByTick(r,i),{publicKey:s}=de(e,n,o);return s}static getTickOffsetInArray(e,n){if(e%n!=0)throw new Error("tickIndex % tickSpacing not equal 0");let r=F.getTickArrayStartIndexByTick(e,n),i=Math.floor((e-r)/n);if(i<0||i>=q)throw new Error("tick offset in array overflow");return i}static getTickArrayBitIndex(e,n){let r=Y.tickCount(n),i=e/r;return e<0&&e%r!=0?i=Math.ceil(i)-1:i=Math.floor(i),i}static getTickArrayStartIndexByTick(e,n){return this.getTickArrayBitIndex(e,n)*Y.tickCount(n)}static getTickArrayOffsetInBitmapByTick(e,n){let r=n*q,i=Math.floor(e/r)+512;return Math.abs(i)}static checkTickArrayIsInitialized(e,n,r){let i=r*q,o=Math.floor(n/i)+512,s=Math.abs(o);return{isInitialized:e.testn(s),startIndex:(s-512)*i}}static getNextTickArrayStartIndex(e,n,r){return r?e-n*q:e+n*q}static mergeTickArrayBitmap(e){let n=new ci(0);for(let r=0;r<e.length;r++)n=n.add(e[r].shln(64*r));return n}static getInitializedTickArrayInRange(e,n,r,i,o){let s=Math.floor(i/(r*q));return[...F.searchLowBitFromStart(e,n,s-1,o,r),...F.searchHightBitFromStart(e,n,s,o,r)]}static getAllInitializedTickArrayStartIndex(e,n,r){return F.searchHightBitFromStart(e,n,-7680,Ct,r)}static getAllInitializedTickArrayInfo(e,n,r,i,o){let s=[],a=F.getAllInitializedTickArrayStartIndex(r,i,o);for(let c of a){let{publicKey:u}=de(e,n,c);s.push({tickArrayStartIndex:c,tickArrayAddress:u})}return s}static getAllInitializedTickInTickArray(e){return e.ticks.filter(n=>n.liquidityGross.gtn(0))}static searchLowBitFromStart(e,n,r,i,o){let s=[...[...n.negativeTickArrayBitmap].reverse(),e.slice(0,8),e.slice(8,16),...n.positiveTickArrayBitmap].map(u=>F.mergeTickArrayBitmap(u)),a=[];for(;r>=-7680;){let u=Math.floor((r+7680)/512),m=(r+7680)%512;if(s[u].testn(m)&&a.push(r),r--,a.length===i)break}let c=Y.tickCount(o);return a.map(u=>u*c)}static searchHightBitFromStart(e,n,r,i,o){let s=[...[...n.negativeTickArrayBitmap].reverse(),e.slice(0,8),e.slice(8,16),...n.positiveTickArrayBitmap].map(u=>F.mergeTickArrayBitmap(u)),a=[];for(;r<7680;){let u=Math.floor((r+7680)/512),m=(r+7680)%512;if(s[u].testn(m)&&a.push(r),r++,a.length===i)break}let c=Y.tickCount(o);return a.map(u=>u*c)}static checkIsOutOfBoundary(e){return e<ce||e>be}static nextInitTick(e,n,r,i,o){if(Y.getArrayStartIndex(n,r)!=e.startTickIndex)return null;let a=Math.floor((n-e.startTickIndex)/r);if(i)for(;a>=0;){if(e.ticks[a].liquidityGross.gtn(0))return e.ticks[a];a=a-1}else for(o||(a=a+1);a<q;){if(e.ticks[a].liquidityGross.gtn(0))return e.ticks[a];a=a+1}return null}static firstInitializedTick(e,n){if(n){let r=q-1;for(;r>=0;){if(e.ticks[r].liquidityGross.gtn(0))return e.ticks[r];r=r-1}}else{let r=0;for(;r<q;){if(e.ticks[r].liquidityGross.gtn(0))return e.ticks[r];r=r+1}}throw Error(`firstInitializedTick check error: ${e} - ${n}`)}static _getTickPriceLegacy({poolInfo:e,tick:n,baseIn:r}){let i=M.getSqrtPriceX64FromTick(n),o=M.sqrtPriceX64ToPrice(i,e.mintA.decimals,e.mintB.decimals);return r?{tick:n,price:o,tickSqrtPriceX64:i}:{tick:n,price:new W(1).div(o),tickSqrtPriceX64:i}}static _getPriceAndTickLegacy({poolInfo:e,price:n,baseIn:r}){let i=r?n:new W(1).div(n),o=xe.getTickWithPriceAndTickspacing(i,e.ammConfig.tickSpacing,e.mintA.decimals,e.mintB.decimals),s=M.getSqrtPriceX64FromTick(o),a=M.sqrtPriceX64ToPrice(s,e.mintA.decimals,e.mintB.decimals);return r?{tick:o,price:a}:{tick:o,price:new W(1).div(a)}}static getTickPrice({poolInfo:e,tick:n,baseIn:r}){let i=M.getSqrtPriceX64FromTick(n),o=M.sqrtPriceX64ToPrice(i,e.mintA.decimals,e.mintB.decimals);return r?{tick:n,price:o,tickSqrtPriceX64:i}:{tick:n,price:new W(1).div(o),tickSqrtPriceX64:i}}static getPriceAndTick({poolInfo:e,price:n,baseIn:r}){let i=r?n:new W(1).div(n),o=xe.getTickWithPriceAndTickspacing(i,e.config.tickSpacing,e.mintA.decimals,e.mintB.decimals),s=M.getSqrtPriceX64FromTick(o),a=M.sqrtPriceX64ToPrice(s,e.mintA.decimals,e.mintB.decimals);return r?{tick:o,price:a}:{tick:o,price:new W(1).div(a)}}};export{Ct as TICK_ARRAY_BITMAP_SIZE,q as TICK_ARRAY_SIZE,F as TickUtils};
//# sourceMappingURL=tick.mjs.map