snapper-sdk
Version:
An SDK for building applications on top of Snapper.
1 lines • 94.8 kB
JavaScript
import S from"bn.js";var je=9e15,De=1e9,Nt="0123456789abcdef",ft="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",pt="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Ct={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-je,maxE:je,crypto:!1},an,Ce,B=!0,ht="[DecimalError] ",Oe=ht+"Invalid argument: ",un=ht+"Precision limit exceeded",cn=ht+"crypto unavailable",mn="[object Decimal]",oe=Math.floor,ee=Math.pow,Yn=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Zn=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Qn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,ln=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Te=1e7,P=7,Jn=9007199254740991,$n=ft.length-1,St=pt.length-1,h={toStringTag:mn};h.absoluteValue=h.abs=function(){var r=new this.constructor(this);return r.s<0&&(r.s=1),A(r)};h.ceil=function(){return A(new this.constructor(this),this.e+1,2)};h.clampedTo=h.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(Oe+e);return t=n.cmp(r),t<0?r:n.cmp(e)>0?e:new i(n)};h.comparedTo=h.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};h.cosine=h.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())+P,n.rounding=1,t=er(n,hn(n,t)),n.precision=r,n.rounding=e,A(Ce==2||Ce==3?t.neg():t,r,e,!0)):new n(1):new n(NaN)};h.cubeRoot=h.cbrt=function(){var r,e,t,n,i,o,s,a,u,c,m=this,l=m.constructor;if(!m.isFinite()||m.isZero())return new l(m);for(B=!1,o=m.s*ee(m.s*m,1/3),!o||Math.abs(o)==1/0?(t=re(m.d),r=m.e,(o=(r-t.length+1)%3)&&(t+=o==1||o==-2?"0":"00"),o=ee(t,1/3),r=oe((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 l(t),n.s=m.s):n=new l(o.toString()),s=(r=l.precision)+3;;)if(a=n,u=a.times(a).times(a),c=u.plus(m),n=V(c.plus(m).times(a),c.plus(u),s+2,1),re(a.d).slice(0,s)===(t=re(n.d)).slice(0,s))if(t=t.slice(s-3,s+1),t=="9999"||!i&&t=="4999"){if(!i&&(A(a,r+1,0),a.times(a).times(a).eq(m))){n=a;break}s+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(A(n,r+1,1),e=!n.times(n).times(n).eq(m));break}return B=!0,A(n,r,l.rounding,e)};h.decimalPlaces=h.dp=function(){var r,e=this.d,t=NaN;if(e){if(r=e.length-1,t=(r-oe(this.e/P))*P,r=e[r],r)for(;r%10==0;r/=10)t--;t<0&&(t=0)}return t};h.dividedBy=h.div=function(r){return V(this,new this.constructor(r))};h.dividedToIntegerBy=h.divToInt=function(r){var e=this,t=e.constructor;return A(V(e,new t(r),0,1,1),t.precision,t.rounding)};h.equals=h.eq=function(r){return this.cmp(r)===0};h.floor=function(){return A(new this.constructor(this),this.e+1,3)};h.greaterThan=h.gt=function(r){return this.cmp(r)>0};h.greaterThanOrEqualTo=h.gte=function(r){var e=this.cmp(r);return e==1||e===0};h.hyperbolicCosine=h.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/wt(4,r)).toString()):(r=16,e="2.3283064365386962890625e-10"),o=Ye(s,1,o.times(e),new s(1),!0);for(var u,c=r,m=new s(8);c--;)u=o.times(o),o=a.minus(u.times(m.minus(u.times(m))));return A(o,s.precision=t,s.rounding=n,!0)};h.hyperbolicSine=h.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=Ye(o,2,i,i,!0);else{r=1.4*Math.sqrt(n),r=r>16?16:r|0,i=i.times(1/wt(5,r)),i=Ye(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,A(i,e,t,!0)};h.hyperbolicTangent=h.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)};h.inverseCosine=h.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()?ye(t,i,o):new t(0):new t(NaN):e.isZero()?ye(t,i+4,o).times(.5):(t.precision=i+6,t.rounding=1,e=e.asin(),r=ye(t,i+4,o).times(.5),t.precision=i,t.rounding=o,r.minus(e))};h.inverseHyperbolicCosine=h.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)};h.inverseHyperbolicSine=h.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())};h.inverseHyperbolicTangent=h.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?A(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)};h.inverseSine=h.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=ye(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)))};h.inverseTangent=h.atan=function(){var r,e,t,n,i,o,s,a,u,c=this,m=c.constructor,l=m.precision,d=m.rounding;if(c.isFinite()){if(c.isZero())return new m(c);if(c.abs().eq(1)&&l+4<=St)return s=ye(m,l+4,d).times(.25),s.s=c.s,s}else{if(!c.s)return new m(NaN);if(l+4<=St)return s=ye(m,l+4,d).times(.5),s.s=c.s,s}for(m.precision=a=l+10,m.rounding=1,t=Math.min(28,a/P+2|0),r=t;r;--r)c=c.div(c.times(c).plus(1).sqrt().plus(1));for(B=!1,e=Math.ceil(a/P),n=1,u=c.times(c),s=new m(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,A(s,m.precision=l,m.rounding=d,!0)};h.isFinite=function(){return!!this.d};h.isInteger=h.isInt=function(){return!!this.d&&oe(this.e/P)>this.d.length-2};h.isNaN=function(){return!this.s};h.isNegative=h.isNeg=function(){return this.s<0};h.isPositive=h.isPos=function(){return this.s>0};h.isZero=function(){return!!this.d&&this.d[0]===0};h.lessThan=h.lt=function(r){return this.cmp(r)<0};h.lessThanOrEqualTo=h.lte=function(r){return this.cmp(r)<1};h.logarithm=h.log=function(r){var e,t,n,i,o,s,a,u,c=this,m=c.constructor,l=m.precision,d=m.rounding,f=5;if(r==null)r=new m(10),e=!0;else{if(r=new m(r),t=r.d,r.s<0||!t||!t[0]||r.eq(1))return new m(NaN);e=r.eq(10)}if(t=c.d,c.s<0||!t||!t[0]||c.eq(1))return new m(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=l+f,s=Fe(c,a),n=e?gt(m,a+10):Fe(r,a),u=V(s,n,a,1),Je(u.d,i=l,d))do if(a+=10,s=Fe(c,a),n=e?gt(m,a+10):Fe(r,a),u=V(s,n,a,1),!o){+re(u.d).slice(i+1,i+15)+1==1e14&&(u=A(u,l+1,0));break}while(Je(u.d,i+=10,d));return B=!0,A(u,l,d)};h.minus=h.sub=function(r){var e,t,n,i,o,s,a,u,c,m,l,d,f=this,b=f.constructor;if(r=new b(r),!f.d||!r.d)return!f.s||!r.s?r=new b(NaN):f.d?r.s=-r.s:r=new b(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=b.precision,u=b.rounding,!c[0]||!d[0]){if(d[0])r.s=-r.s;else if(c[0])r=new b(f);else return new b(u===3?-0:0);return B?A(r,a,u):r}if(t=oe(r.e/P),m=oe(f.e/P),c=c.slice(),o=m-t,o){for(l=o<0,l?(e=c,o=-o,s=d.length):(e=d,t=m,s=c.length),n=Math.max(Math.ceil(a/P),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,l=n<s,l&&(s=n),n=0;n<s;n++)if(c[n]!=d[n]){l=c[n]<d[n];break}o=0}for(l&&(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]=Te-1;--c[i],c[n]+=Te}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=bt(c,t),B?A(r,a,u):r):new b(u===3?-0:0)};h.modulo=h.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]?A(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))};h.naturalExponential=h.exp=function(){return Lt(this)};h.naturalLogarithm=h.ln=function(){return Fe(this)};h.negated=h.neg=function(){var r=new this.constructor(this);return r.s=-r.s,A(r)};h.plus=h.add=function(r){var e,t,n,i,o,s,a,u,c,m,l=this,d=l.constructor;if(r=new d(r),!l.d||!r.d)return!l.s||!r.s?r=new d(NaN):l.d||(r=new d(r.d||l.s===r.s?l:NaN)),r;if(l.s!=r.s)return r.s=-r.s,l.minus(r);if(c=l.d,m=r.d,a=d.precision,u=d.rounding,!c[0]||!m[0])return m[0]||(r=new d(l)),B?A(r,a,u):r;if(o=oe(l.e/P),n=oe(r.e/P),c=c.slice(),i=o-n,i){for(i<0?(t=c,i=-i,s=m.length):(t=m,n=o,s=c.length),o=Math.ceil(a/P),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=m.length,s-i<0&&(i=s,t=m,m=c,c=t),e=0;i;)e=(c[--i]=c[i]+m[i]+e)/Te|0,c[i]%=Te;for(e&&(c.unshift(e),++n),s=c.length;c[--s]==0;)c.pop();return r.d=c,r.e=bt(c,n),B?A(r,a,u):r};h.precision=h.sd=function(r){var e,t=this;if(r!==void 0&&r!==!!r&&r!==1&&r!==0)throw Error(Oe+r);return t.d?(e=dn(t.d),r&&t.e+1>e&&(e=t.e+1)):e=NaN,e};h.round=function(){var r=this,e=r.constructor;return A(new e(r),r.e+1,e.rounding)};h.sine=h.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())+P,n.rounding=1,t=nr(n,hn(n,t)),n.precision=r,n.rounding=e,A(Ce>2?t.neg():t,r,e,!0)):new n(NaN)};h.squareRoot=h.sqrt=function(){var r,e,t,n,i,o,s=this,a=s.d,u=s.e,c=s.s,m=s.constructor;if(c!==1||!a||!a[0])return new m(!c||c<0&&(!a||a[0])?NaN:a?s:1/0);for(B=!1,c=Math.sqrt(+s),c==0||c==1/0?(e=re(a),(e.length+u)%2==0&&(e+="0"),c=Math.sqrt(e),u=oe((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 m(e)):n=new m(c.toString()),t=(u=m.precision)+3;;)if(o=n,n=o.plus(V(s,o,t+2,1)).times(.5),re(o.d).slice(0,t)===(e=re(n.d)).slice(0,t))if(e=e.slice(t-3,t+1),e=="9999"||!i&&e=="4999"){if(!i&&(A(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")&&(A(n,u+1,1),r=!n.times(n).eq(s));break}return B=!0,A(n,u,m.rounding,r)};h.tangent=h.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,A(Ce==2||Ce==4?t.neg():t,r,e,!0)):new n(NaN)};h.times=h.mul=function(r){var e,t,n,i,o,s,a,u,c,m=this,l=m.constructor,d=m.d,f=(r=new l(r)).d;if(r.s*=m.s,!d||!d[0]||!f||!f[0])return new l(!r.s||d&&!d[0]&&!f||f&&!f[0]&&!d?NaN:!d||!f?r.s/0:r.s*0);for(t=oe(m.e/P)+oe(r.e/P),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%Te|0,e=a/Te|0;o[i]=(o[i]+e)%Te|0}for(;!o[--s];)o.pop();return e?++t:o.shift(),r.d=o,r.e=bt(o,t),B?A(r,l.precision,l.rounding):r};h.toBinary=function(r,e){return Rt(this,2,r,e)};h.toDecimalPlaces=h.toDP=function(r,e){var t=this,n=t.constructor;return t=new n(t),r===void 0?t:(de(r,0,De),e===void 0?e=n.rounding:de(e,0,8),A(t,r+t.e+1,e))};h.toExponential=function(r,e){var t,n=this,i=n.constructor;return r===void 0?t=Be(n,!0):(de(r,0,De),e===void 0?e=i.rounding:de(e,0,8),n=A(new i(n),r+1,e),t=Be(n,!0,r+1)),n.isNeg()&&!n.isZero()?"-"+t:t};h.toFixed=function(r,e){var t,n,i=this,o=i.constructor;return r===void 0?t=Be(i):(de(r,0,De),e===void 0?e=o.rounding:de(e,0,8),n=A(new o(i),r+i.e+1,e),t=Be(n,!1,r+n.e+1)),i.isNeg()&&!i.isZero()?"-"+t:t};h.toFraction=function(r){var e,t,n,i,o,s,a,u,c,m,l,d,f=this,b=f.d,g=f.constructor;if(!b)return new g(f);if(c=t=new g(1),n=u=new g(0),e=new g(n),o=e.e=dn(b)-f.e-1,s=o%P,e.d[0]=ee(10,s<0?P+s:s),r==null)r=o>0?e:c;else{if(a=new g(r),!a.isInt()||a.lt(c))throw Error(Oe+a);r=a.gt(e)?o>0?e:c:a}for(B=!1,a=new g(re(b)),m=g.precision,g.precision=o=b.length*P*2;l=V(a,e,0,1,1),i=t.plus(l.times(n)),i.cmp(r)!=1;)t=n,n=i,i=c,c=u.plus(l.times(i)),u=i,i=e,e=a.minus(l.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=m,B=!0,d};h.toHexadecimal=h.toHex=function(r,e){return Rt(this,16,r,e)};h.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:de(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,A(t)):(r.s=t.s,t=r),t};h.toNumber=function(){return+this};h.toOctal=function(r,e){return Rt(this,8,r,e)};h.toPower=h.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(ee(+a,c));if(a=new u(a),a.eq(1))return a;if(n=u.precision,o=u.rounding,r.eq(1))return A(a,n,o);if(e=oe(r.e/P),e>=r.d.length-1&&(t=c<0?-c:c)<=Jn)return i=fn(u,a,t,n),r.s<0?new u(1).div(i):A(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=ee(+a,c),e=t==0||!isFinite(t)?oe(c*(Math.log("0."+re(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=Lt(r.times(Fe(a,n+t)),n),i.d&&(i=A(i,n+5,1),Je(i.d,n,o)&&(e=n+10,i=A(Lt(r.times(Fe(a,e+t)),e),e+5,1),+re(i.d).slice(n+1,n+15)+1==1e14&&(i=A(i,n+1,0)))),i.s=s,B=!0,u.rounding=o,A(i,n,o))};h.toPrecision=function(r,e){var t,n=this,i=n.constructor;return r===void 0?t=Be(n,n.e<=i.toExpNeg||n.e>=i.toExpPos):(de(r,1,De),e===void 0?e=i.rounding:de(e,0,8),n=A(new i(n),r,e),t=Be(n,r<=n.e||n.e<=i.toExpNeg,r)),n.isNeg()&&!n.isZero()?"-"+t:t};h.toSignificantDigits=h.toSD=function(r,e){var t=this,n=t.constructor;return r===void 0?(r=n.precision,e=n.rounding):(de(r,1,De),e===void 0?e=n.rounding:de(e,0,8)),A(new n(t),r,e)};h.toString=function(){var r=this,e=r.constructor,t=Be(r,r.e<=e.toExpNeg||r.e>=e.toExpPos);return r.isNeg()&&!r.isZero()?"-"+t:t};h.truncated=h.trunc=function(){return A(new this.constructor(this),this.e+1,1)};h.valueOf=h.toJSON=function(){var r=this,e=r.constructor,t=Be(r,r.e<=e.toExpNeg||r.e>=e.toExpPos);return r.isNeg()?"-"+t:t};function re(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=P-n.length,t&&(o+=Me(t)),o+=n;s=r[e],n=s+"",t=P-n.length,t&&(o+=Me(t))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function de(r,e,t){if(r!==~~r||r<e||r>t)throw Error(Oe+r)}function Je(r,e,t,n){var i,o,s,a;for(o=r[0];o>=10;o/=10)--e;return--e<0?(e+=P,i=0):(i=Math.ceil((e+1)/P),e%=P),o=ee(10,P-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)==ee(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)==ee(10,e-3)-1,s}function dt(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]+=Nt.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 er(r,e){var t,n,i;if(e.isZero())return e;n=e.d.length,n<32?(t=Math.ceil(n/3),i=(1/wt(4,t)).toString()):(t=16,i="2.3283064365386962890625e-10"),r.precision+=t,e=Ye(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,m,l,d,f,b,g,w,p,k,y,_,W,T,Z,K,J,Q,M,le,ie=n.constructor,_e=n.s==i.s?1:-1,$=n.d,q=i.d;if(!$||!$[0]||!q||!q[0])return new ie(!n.s||!i.s||($?q&&$[0]==q[0]:!q)?NaN:$&&$[0]==0||!q?_e*0:_e/0);for(u?(f=1,m=n.e-i.e):(u=Te,f=P,m=oe(n.e/f)-oe(i.e/f)),M=q.length,J=$.length,p=new ie(_e),k=p.d=[],l=0;q[l]==($[l]||0);l++);if(q[l]>($[l]||0)&&m--,o==null?(T=o=ie.precision,s=ie.rounding):a?T=o+(n.e-i.e)+1:T=o,T<0)k.push(1),b=!0;else{if(T=T/f+2|0,l=0,M==1){for(d=0,q=q[0],T++;(l<J||d)&&T--;l++)Z=d*u+($[l]||0),k[l]=Z/q|0,d=Z%q|0;b=d||l<J}else{for(d=u/(q[0]+1)|0,d>1&&(q=r(q,d,u),$=r($,d,u),M=q.length,J=$.length),K=M,y=$.slice(0,M),_=y.length;_<M;)y[_++]=0;le=q.slice(),le.unshift(0),Q=q[0],q[1]>=u/2&&++Q;do d=0,c=e(q,y,M,_),c<0?(W=y[0],M!=_&&(W=W*u+(y[1]||0)),d=W/Q|0,d>1?(d>=u&&(d=u-1),g=r(q,d,u),w=g.length,_=y.length,c=e(g,y,w,_),c==1&&(d--,t(g,M<w?le:q,w,u))):(d==0&&(c=d=1),g=q.slice()),w=g.length,w<_&&g.unshift(0),t(y,g,_,u),c==-1&&(_=y.length,c=e(q,y,M,_),c<1&&(d++,t(y,M<_?le:q,_,u))),_=y.length):c===0&&(d++,y=[0]),k[l++]=d,c&&y[0]?y[_++]=$[K]||0:(y=[$[K]],_=1);while((K++<J||y[0]!==void 0)&&T--);b=y[0]!==void 0}k[0]||k.shift()}if(f==1)p.e=m,an=b;else{for(l=1,d=k[0];d>=10;d/=10)l++;p.e=l+m*f-1,A(p,a?o+p.e+1:o,s,b)}return p}}();function A(r,e,t,n){var i,o,s,a,u,c,m,l,d,f=r.constructor;e:if(e!=null){if(l=r.d,!l)return r;for(i=1,a=l[0];a>=10;a/=10)i++;if(o=e-i,o<0)o+=P,s=e,m=l[d=0],u=m/ee(10,i-s-1)%10|0;else if(d=Math.ceil((o+1)/P),a=l.length,d>=a)if(n){for(;a++<=d;)l.push(0);m=u=0,i=1,o%=P,s=o-P+1}else break e;else{for(m=a=l[d],i=1;a>=10;a/=10)i++;o%=P,s=o-P+i,u=s<0?0:m/ee(10,i-s-1)%10|0}if(n=n||e<0||l[d+1]!==void 0||(s<0?m:m%ee(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?m/ee(10,i-s):0:l[d-1])%10&1||t==(r.s<0?8:7)),e<1||!l[0])return l.length=0,c?(e-=r.e+1,l[0]=ee(10,(P-e%P)%P),r.e=-e||0):l[0]=r.e=0,r;if(o==0?(l.length=d,a=1,d--):(l.length=d+1,a=ee(10,P-o),l[d]=s>0?(m/ee(10,i-s)%ee(10,s)|0)*a:0),c)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&&(r.e++,l[0]==Te&&(l[0]=1));break}else{if(l[d]+=a,l[d]!=Te)break;l[d--]=0,a=1}for(o=l.length;l[--o]===0;)l.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 Be(r,e,t){if(!r.isFinite())return gn(r);var n,i=r.e,o=re(r.d),s=o.length;return e?(t&&(n=t-s)>0?o=o.charAt(0)+"."+o.slice(1)+Me(n):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(r.e<0?"e":"e+")+r.e):i<0?(o="0."+Me(-i-1)+o,t&&(n=t-s)>0&&(o+=Me(n))):i>=s?(o+=Me(i+1-s),t&&(n=t-i-1)>0&&(o=o+"."+Me(n))):((n=i+1)<s&&(o=o.slice(0,n)+"."+o.slice(n)),t&&(n=t-s)>0&&(i+1===s&&(o+="."),o+=Me(n))),o}function bt(r,e){var t=r[0];for(e*=P;t>=10;t/=10)e++;return e}function gt(r,e,t){if(e>$n)throw B=!0,t&&(r.precision=t),Error(un);return A(new r(ft),e,1,!0)}function ye(r,e,t){if(e>St)throw Error(un);return A(new r(pt),e,t,!0)}function dn(r){var e=r.length-1,t=e*P+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 Me(r){for(var e="";r--;)e+="0";return e}function fn(r,e,t,n){var i,o=new r(1),s=Math.ceil(n/P+4);for(B=!1;;){if(t%2&&(o=o.times(e),on(o.d,s)&&(i=!0)),t=oe(t/2),t===0){t=o.d.length-1,i&&o.d[t]===0&&++o.d[t];break}e=e.times(e),on(e.d,s)}return B=!0,o}function rn(r){return r.d[r.d.length-1]&1}function pn(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 Lt(r,e){var t,n,i,o,s,a,u,c=0,m=0,l=0,d=r.constructor,f=d.rounding,b=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=b):u=e,a=new d(.03125);r.e>-2;)r=r.times(a),l+=5;for(n=Math.log(ee(2,l))/Math.LN10*2+5|0,u+=n,t=o=s=new d(1),d.precision=u;;){if(o=A(o.times(r),u,1),t=t.times(++m),a=s.plus(V(o,t,u,1)),re(a.d).slice(0,u)===re(s.d).slice(0,u)){for(i=l;i--;)s=A(s.times(s),u,1);if(e==null)if(c<3&&Je(s.d,u-n,f,c))d.precision=u+=10,t=o=a=new d(1),m=0,c++;else return A(s,d.precision=b,f,B=!0);else return d.precision=b,s}s=a}}function Fe(r,e){var t,n,i,o,s,a,u,c,m,l,d,f=1,b=10,g=r,w=g.d,p=g.constructor,k=p.rounding,y=p.precision;if(g.s<0||!w||!w[0]||!g.e&&w[0]==1&&w.length==1)return new p(w&&!w[0]?-1/0:g.s!=1?NaN:w?0:g);if(e==null?(B=!1,m=y):m=e,p.precision=m+=b,t=re(w),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=re(g.d),n=t.charAt(0),f++;o=g.e,n>1?(g=new p("0."+t),o++):g=new p(n+"."+t.slice(1))}else return c=gt(p,m+2,y).times(o+""),g=Fe(new p(n+"."+t.slice(1)),m-b).plus(c),p.precision=y,e==null?A(g,y,k,B=!0):g;for(l=g,u=s=g=V(g.minus(1),g.plus(1),m,1),d=A(g.times(g),m,1),i=3;;){if(s=A(s.times(d),m,1),c=u.plus(V(s,new p(i),m,1)),re(c.d).slice(0,m)===re(u.d).slice(0,m))if(u=u.times(2),o!==0&&(u=u.plus(gt(p,m+2,y).times(o+""))),u=V(u,new p(f),m,1),e==null)if(Je(u.d,m-b,k,a))p.precision=m+=b,c=s=g=V(l.minus(1),l.plus(1),m,1),d=A(g.times(g),m,1),i=a=1;else return A(u,p.precision=y,k,B=!0);else return p.precision=y,u;u=c,i+=2}}function gn(r){return String(r.s*r.s/0)}function Et(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)%P,t<0&&(n+=P),n<i){for(n&&r.d.push(+e.slice(0,n)),i-=P;n<i;)r.d.push(+e.slice(n,n+=P));e=e.slice(n),n=P-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 tr(r,e){var t,n,i,o,s,a,u,c,m;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),ln.test(e))return Et(r,e)}else if(e==="Infinity"||e==="NaN")return+e||(r.s=NaN),r.e=NaN,r.d=null,r;if(Zn.test(e))t=16,e=e.toLowerCase();else if(Yn.test(e))t=2;else if(Qn.test(e))t=8;else throw Error(Oe+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=fn(n,new n(t),o,o*2)),c=dt(e,t,Te),m=c.length-1,o=m;c[o]===0;--o)c.pop();return o<0?new n(r.s*0):(r.e=bt(c,m),r.d=c,B=!1,s&&(r=V(r,i,a*4)),u&&(r=r.times(Math.abs(u)<54?ee(2,u):$e.pow(2,u))),B=!0,r)}function nr(r,e){var t,n=e.d.length;if(n<3)return e.isZero()?e:Ye(r,2,e,e);t=1.4*Math.sqrt(n),t=t>16?16:t|0,e=e.times(1/wt(5,t)),e=Ye(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 Ye(r,e,t,n,i){var o,s,a,u,c=1,m=r.precision,l=Math.ceil(m/P);for(B=!1,u=t.times(t),a=new r(n);;){if(s=V(a.times(u),new r(e++*e++),m,1),a=i?n.plus(s):n.minus(s),n=V(s.times(u),new r(e++*e++),m,1),s=a.plus(n),s.d[l]!==void 0){for(o=l;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=l+1,s}function wt(r,e){for(var t=r;--e;)t*=r;return t}function hn(r,e){var t,n=e.s<0,i=ye(r,r.precision,1),o=i.times(.5);if(e=e.abs(),e.lte(o))return Ce=n?4:1,e;if(t=e.divToInt(i),t.isZero())Ce=n?3:2;else{if(e=e.minus(t.times(i)),e.lte(o))return Ce=rn(t)?n?2:3:n?4:1,e;Ce=rn(t)?n?1:4:n?3:2}return e.minus(i).abs()}function Rt(r,e,t,n){var i,o,s,a,u,c,m,l,d,f=r.constructor,b=t!==void 0;if(b?(de(t,1,De),n===void 0?n=f.rounding:de(n,0,8)):(t=f.precision,n=f.rounding),!r.isFinite())m=gn(r);else{for(m=Be(r),s=m.indexOf("."),b?(i=2,e==16?t=t*4-3:e==8&&(t=t*3-2)):i=e,s>=0&&(m=m.replace(".",""),d=new f(1),d.e=m.length-s,d.d=dt(Be(d),10,i),d.e=d.d.length),l=dt(m,10,i),o=u=l.length;l[--u]==0;)l.pop();if(!l[0])m=b?"0p+0":"0";else{if(s<0?o--:(r=new f(r),r.d=l,r.e=o,r=V(r,d,t,n,0,i),l=r.d,o=r.e,c=an),s=l[t],a=i/2,c=c||l[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&&l[t-1]&1||n===(r.s<0?8:7)),l.length=t,c)for(;++l[--t]>i-1;)l[t]=0,t||(++o,l.unshift(1));for(u=l.length;!l[u-1];--u);for(s=0,m="";s<u;s++)m+=Nt.charAt(l[s]);if(b){if(u>1)if(e==16||e==8){for(s=e==16?4:3,--u;u%s;u++)m+="0";for(l=dt(m,i,e),u=l.length;!l[u-1];--u);for(s=1,m="1.";s<u;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>u)for(o-=u;o--;)m+="0";else o<u&&(m=m.slice(0,o)+"."+m.slice(o))}m=(e==16?"0x":e==2?"0b":e==8?"0o":"")+m}return r.s<0?"-"+m:m}function on(r,e){if(r.length>e)return r.length=e,!0}function rr(r){return new this(r).abs()}function ir(r){return new this(r).acos()}function or(r){return new this(r).acosh()}function sr(r,e){return new this(r).plus(e)}function ar(r){return new this(r).asin()}function ur(r){return new this(r).asinh()}function cr(r){return new this(r).atan()}function mr(r){return new this(r).atanh()}function lr(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=ye(this,o,1).times(e.s>0?.25:.75),t.s=r.s):!e.d||r.isZero()?(t=e.s<0?ye(this,n,i):new this(0),t.s=r.s):!r.d||e.isZero()?(t=ye(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=ye(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 dr(r){return new this(r).cbrt()}function fr(r){return A(r=new this(r),r.e+1,2)}function pr(r,e,t){return new this(r).clamp(e,t)}function gr(r){if(!r||typeof r!="object")throw Error(ht+"Object expected");var e,t,n,i=r.defaults===!0,o=["precision",1,De,"rounding",0,8,"toExpNeg",-je,0,"toExpPos",0,je,"maxE",0,je,"minE",-je,0,"modulo",0,9];for(e=0;e<o.length;e+=3)if(t=o[e],i&&(this[t]=Ct[t]),(n=r[t])!==void 0)if(oe(n)===n&&n>=o[e+1]&&n<=o[e+2])this[t]=n;else throw Error(Oe+t+": "+n);if(t="crypto",i&&(this[t]=Ct[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(cn);else this[t]=!1;else throw Error(Oe+t+": "+n);return this}function hr(r){return new this(r).cos()}function br(r){return new this(r).cosh()}function bn(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,sn(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 Et(c,o.toString())}else if(u!=="string")throw Error(Oe+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)?Et(c,o):tr(c,o)}if(i.prototype=h,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=gr,i.clone=bn,i.isDecimal=sn,i.abs=rr,i.acos=ir,i.acosh=or,i.add=sr,i.asin=ar,i.asinh=ur,i.atan=cr,i.atanh=mr,i.atan2=lr,i.cbrt=dr,i.ceil=fr,i.clamp=pr,i.cos=hr,i.cosh=br,i.div=wr,i.exp=yr,i.floor=Tr,i.hypot=xr,i.ln=Ar,i.log=Pr,i.log10=Br,i.log2=kr,i.max=Ir,i.min=Nr,i.mod=Cr,i.mul=Sr,i.pow=Lr,i.random=Er,i.round=Rr,i.sign=_r,i.sin=Mr,i.sinh=Fr,i.sqrt=Or,i.sub=Dr,i.sum=vr,i.tan=Kr,i.tanh=qr,i.trunc=Gr,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 wr(r,e){return new this(r).div(e)}function yr(r){return new this(r).exp()}function Tr(r){return A(r=new this(r),r.e+1,3)}function xr(){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 sn(r){return r instanceof $e||r&&r.toStringTag===mn||!1}function Ar(r){return new this(r).ln()}function Pr(r,e){return new this(r).log(e)}function kr(r){return new this(r).log(2)}function Br(r){return new this(r).log(10)}function Ir(){return pn(this,arguments,"lt")}function Nr(){return pn(this,arguments,"gt")}function Cr(r,e){return new this(r).mod(e)}function Sr(r,e){return new this(r).mul(e)}function Lr(r,e){return new this(r).pow(e)}function Er(r){var e,t,n,i,o=0,s=new this(1),a=[];if(r===void 0?r=this.precision:de(r,1,De),n=Math.ceil(r/P),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(cn);else for(;o<n;)a[o++]=Math.random()*1e7|0;for(n=a[--o],r%=P,n&&r&&(i=ee(10,P-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-=P)a.shift();for(n=1,i=a[0];i>=10;i/=10)n++;n<P&&(t-=P-n)}return s.e=t,s.d=a,s}function Rr(r){return A(r=new this(r),r.e+1,this.rounding)}function _r(r){return r=new this(r),r.d?r.d[0]?r.s:0*r.s:r.s||NaN}function Mr(r){return new this(r).sin()}function Fr(r){return new this(r).sinh()}function Or(r){return new this(r).sqrt()}function Dr(r,e){return new this(r).sub(e)}function vr(){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,A(t,this.precision,this.rounding)}function Kr(r){return new this(r).tan()}function qr(r){return new this(r).tanh()}function Gr(r){return A(r=new this(r),r.e+1,1)}h[Symbol.for("nodejs.util.inspect.custom")]=h.toString;h[Symbol.toStringTag]="Decimal";var $e=h.constructor=bn(Ct);ft=new $e(ft);pt=new $e(pt);var x=$e;import xe from"bn.js";var et=1e4;function j(r,e,t,n){if(e===void 0)return{amount:r,fee:void 0,expirationTime:void 0};let i={...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 xe(o.maximumFee.toString()),a=t.epoch<i.newerTransferFee.epoch?(Number(i.newerTransferFee.epoch)*t.slotsInEpoch-t.absoluteSlot)*400/1e3:void 0;if(n)if(o.transferFeeBasisPoints===et){let u=new xe(o.maximumFee.toString());return{amount:r.add(u),fee:u,expirationTime:a}}else{let u=_t(r.mul(new xe(et)),new xe(et-o.transferFeeBasisPoints)),c=new xe(o.maximumFee.toString()),m=u.sub(r).gt(c)?r.add(c):u,l=_t(m.mul(new xe(o.transferFeeBasisPoints)),new xe(et)),d=l.gt(s)?s:l;return{amount:m,fee:d,expirationTime:a}}else{let u=_t(r.mul(new xe(o.transferFeeBasisPoints)),new xe(et)),c=u.gt(s)?s:u;return{amount:r,fee:c,expirationTime:a}}}function ve(r,e){return r===void 0?e:e===void 0?r:Math.min(r,e)}function _t(r,e){let{div:t,mod:n}=r.divmod(e);return n.gt(new xe(0))?t.add(new xe(1)):t}import we from"bn.js";var Y=new we(0),Ie=new we(1),Se=new we(-1),pe=new we(1).shln(64),yt=new we(1).shln(128),Mt=pe.sub(Ie),tt=64,wn=yt.subn(1),se=-443636,ue=-se,Ve=new we("4295048016"),Ue=new we("79226673521066979257578248091"),Gi=new we("4295048017"),Vi=new we("79226673521066979257578248090"),yn=16,Tn="59543866431248",xn="184467440737095516",An="15793534762490258745",Tt=new we(10).pow(new we(6));var Ui=new we("18446744073700000000");import{PublicKey as Wr}from"@solana/web3.js";import{get as Pn,set as Vr}from"lodash";var Ft=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 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}},kn={},Ur={};function ge(r){let e=Pn(kn,r);if(!e){let t=Pn(Ur,r);e=new Ft({name:r,logLevel:t}),Vr(kn,r,e)}return e}import{MINT_SIZE as eo,TOKEN_PROGRAM_ID as to,getTransferFeeConfig as no,unpackMint as ro}from"@solana/spl-token";var Ot=ge("Raydium_accountInfo_util");async function Ke(r,e,t){let{batchRequest:n,commitment:i="confirmed",chunkCount:o=100}={batchRequest:!1,...t},s=Dt(e,o),a=new Array(s.length).fill([]);if(n){let u=s.map(l=>{let d=r._buildArgs([l.map(f=>f.toBase58())],i,"base64");return{methodName:"getMultipleAccounts",args:d}}),c=Dt(u,10);a=(await(await Promise.all(c.map(async l=>await r._rpcBatchRequest(l)))).flat()).map(l=>(l.error&&Ot.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${l.error.message}`),l.result.value.map(d=>{if(d){let{data:f,executable:b,lamports:g,owner:w,rentEpoch:p}=d;return f.length!==2&&f[1]!=="base64"&&Ot.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(f[0],"base64"),executable:b,lamports:g,owner:new Wr(w),rentEpoch:p}}return null})))}else try{a=await Promise.all(s.map(u=>r.getMultipleAccountsInfo(u,i)))}catch(u){u instanceof Error&&Ot.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${u.message}`)}return a.flat()}async function vt(r,e,t){let n=await Ke(r,e.map(i=>i.pubkey),t);return e.map((i,o)=>({...i,accountInfo:n[o]}))}import Ee from"bn.js";import Jr from"big.js";import kt from"bn.js";import Xr from"toformat";var zr=Xr,nt=zr;import Pt from"big.js";import jr from"bn.js";import Yr from"decimal.js-light";import rt from"bn.js";var Bn=9007199254740991;function he(r){let e=ge("Raydium_parseBigNumberish");if(r instanceof rt)return r;if(typeof r=="string"){if(r.match(/^-?[0-9]+$/))return new rt(r);e.logWithError(`invalid BigNumberish string: ${r}`)}return typeof r=="number"?(r%1&&e.logWithError(`BigNumberish number underflow: ${r}`),(r>=Bn||r<=-Bn)&&e.logWithError(`BigNumberish number overflow: ${r}`),new rt(String(r))):typeof r=="bigint"?new rt(r.toString()):(e.error(`invalid BigNumberish value: ${r}`),new rt(0))}var At=ge("module/fraction"),qt=nt(Pt),it=nt(Yr),Zr={[0]:it.ROUND_DOWN,[1]:it.ROUND_HALF_UP,[2]:it.ROUND_UP},Qr={[0]:Pt.roundDown,[1]:Pt.roundHalfUp,[2]:Pt.roundUp},v=class{constructor(e,t=new jr(1)){this.numerator=he(e),this.denominator=he(t)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new v(this.denominator,this.numerator)}add(e){let t=e instanceof v?e:new v(he(e));return this.denominator.eq(t.denominator)?new v(this.numerator.add(t.numerator),this.denominator):new v(this.numerator.mul(t.denominator).add(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}sub(e){let t=e instanceof v?e:new v(he(e));return this.denominator.eq(t.denominator)?new v(this.numerator.sub(t.numerator),this.denominator):new v(this.numerator.mul(t.denominator).sub(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}mul(e){let t=e instanceof v?e:new v(he(e));return new v(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof v?e:new v(he(e));return new v(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},n=1){Number.isInteger(e)||At.logWithError(`${e} is not an integer.`),e<=0&&At.logWithError(`${e} is not positive.`),it.set({precision:e+1,rounding:Zr[n]});let i=new it(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)||At.logWithError(`${e} is not an integer.`),e<0&&At.logWithError(`${e} is negative.`),qt.DP=e,qt.RM=Qr[n]||1,new qt(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};var $r=ge("Raydium_amount"),In=nt(Jr);function ei(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")):$r.logWithError(`invalid number string, num: ${r}`)}else t=r;return[t,n.slice(0,e)||n]}var ae=class extends v{constructor(t,n,i=!0,o){let s=new kt(0),a=Gt.pow(new kt(t.decimals));if(i)s=he(n);else{let u=new kt(0),c=new kt(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[m,l]=ei(n.toString(),t.decimals);u=he(m),c=he(l)}u=u.mul(a),s=u.add(c)}super(s,a);this.logger=ge(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 ae(this.token,this.raw.add(t.raw))}subtract(t){return this.token.equals(t.token)||this.logger.logWithError("sub token not equals"),new ae(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 In.DP=this.token.decimals,new In(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)}};import{PublicKey as ti}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Nn}from"@solana/spl-token";var Cn={chainId:101,address:ti.default.toBase58(),programId:Nn.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img.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.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}};import{PublicKey as Wt}from"@solana/web3.js";import{PublicKey as X,SystemProgram as Sn,SYSVAR_RENT_PUBKEY as ni}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ri}from"@solana/spl-token";function Vt({pubkey:r,isSigner:e=!1,isWritable:t=!0}){return{pubkey:r,isWritable:t,isSigner:e}}var Oo=[Vt({pubkey:ri,isWritable:!1}),Vt({pubkey:Sn.programId,isWritable:!1}),Vt({pubkey:ni,isWritable:!1})];function Ut({publicKey:r,transformSol:e}){let t=Ln(r.toString());if(t instanceof X)return e&&t.equals(ot)?Kt:t;if(e&&t.toString()===ot.toBase58())return Kt;if(typeof t=="string"){if(t===X.default.toBase58())return X.default;try{return new X(t)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function Ln(r){try{return new X(r)}catch{return r}}var Do=new X("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),vo=new X("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Ko=new X("SysvarRent111111111111111111111111111111111"),qo=new X("SysvarC1ock11111111111111111111111111111111"),ii=new X("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Go=new X("Sysvar1nstructions1111111111111111111111111"),Vo=Sn.programId,Uo=new X("2cpMA1jNS4obgRz8XNg38QuSP83L1AXpUgfxPNcvnAGj"),Wo=new X("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Xo=new X("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),zo=new X("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Ho=new X("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),jo=new X("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Yo=new X("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Zo=new X("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Qo=new X("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Jo=new X("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),$o=new X("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),Kt=new X("So11111111111111111111111111111111111111112"),ot=X.default;function xt(r){return Ut({publicKey:r,transformSol:!0})}var Xt=class{constructor({mint:e,decimals:t,symbol:n,name:i,skipMint:o=!1,isToken2022:s=!1}){if(e===ot.toBase58()||e instanceof Wt&&ot.equals(e)){this.decimals=We.decimals,this.symbol=We.symbol,this.name=We.name,this.mint=new Wt(We.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?Wt.default:Ut({publicKey:e}),this.isToken2022=s}equals(e){return this===e?!0:this.mint.equals(e.mint)}},Le=Xt;Le.WSOL=new Xt({...We,mint:We.address});var zt=class{constructor({decimals:e,symbol:t="UNKNOWN",name:n="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=n}equals(e){return this===e}},Bt=zt;Bt.SOL=new zt(Cn);import oi from"bn.js";var En=new v(new oi(100)),qe=class extends v{toSignificant(e=5,t,n){return this.mul(En).toSignificant(e,t,n)}toFixed(e=2,t,n){return this.mul(En).toFixed(e,t,n)}};var si=ge("Raydium_price"),Ae=class extends v{constructor(t){let{baseToken:n,quoteToken:i,numerator:o,denominator:s}=t;super(o,s);this.baseToken=n,this.quoteToken=i,this.scalar=new v(Ht(n.decimals),Ht(i.decimals))}get raw(){return new v(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new Ae({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numerator,numerator:this.denominator})}mul(t){this.quoteToken!==t.baseToken&&si.logWithError("mul token not equals");let n=super.mul(t);return new Ae({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)}};import{PublicKey as Es}from"@solana/web3.js";import _s from"bn.js";var ai=new Ee(0),Qs=new Ee(1),Js=new Ee(2),$s=new Ee(3),ea=new Ee(5),Gt=new Ee(10),ta=new Ee(100),na=new Ee(1e3),ra=new Ee(1e4);function Ht(r){return Gt.pow(he(r))}function Dt(r,e=1,t=[]){let n=[...r];if(e<=0)return t;for(;n.length;)t.push(n.splice(0,e));return t}import{PublicKey as Ca}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as La}from"@solana/spl-token";import{ComputeBudgetProgram as da,Keypair as ga,PublicKey as ui,Transaction as ba,TransactionMessage as ya,VersionedTransaction as Ta}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ka}from"@solana/spl-token";var Ba=ge("Raydium_txUtil");function st(r,e){let[t,n]=ui.findProgramAddressSync(r,e);return{publicKey:t,nonce:n}}import{PublicKey as L}from"@solana/web3.js";var Ma=new L("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),Fa=new L("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),Oa=new L("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Da=new L("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),va=new L("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),Ka=new L("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),qa=new L("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Ga=new L("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Va=new L("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),Ua=new L("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),Wa=new L("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),Xa=new L("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),za=new L("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Ha=new L("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),ja=new L("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Ya=new L("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),Za=new L("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),Qa=new L("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),Ja=new L("SNaPnpKUY656VPwbKmKT8FG4T85g4VWhRH1B4TQUfKs"),$a=new L("9pR79Lqe6wDNjag3v8MeVYUostoXjY2ognTydor6AtEZ"),eu=new L("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),ci=new L("4AscABy58S62owbByjUUkQfZsP7fxYH1rDYb69V58HPM"),mi=new L("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),li=new L("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),tu=new L("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),di=new L("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),nu=new L("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),fi=new L("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix");var ru={SERUM_MARKET:L.default,OPENBOOK_MARKET:new L("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:L.default,FarmV3:new L("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new L("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new L("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new L("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new L("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new L("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),CLMM_LOCK_PROGRAM_ID:new L("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),CLMM_LOCK_AUTH_ID:new L("8qmHNvu2Kr2C7U8mJL4Vz1vTDxMhVuXKREwU7TNoaVEo"),Router:new L("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:ci,CREATE_CPMM_POOL_AUTH:mi,CREATE_CPMM_POOL_FEE_ACC:li,FEE_DESTINATION_ID:new L("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),LOCK_CPMM_PROGRAM:di,LCOK_CPMM_AUTH:fi};import{PublicKey as pi,AddressLookupTableAccount as Rn}from"@solana/web3.js";var gi={"2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17":new Rn({key:new pi("2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17"),state:Rn.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"))})};import{PublicKey as Tu,sendAndConfirmTransaction as xu,Transaction as Pu,TransactionMessage as Bu,VersionedTransaction as Iu}from"@solana/web3.js";import Cu from"axios";function _n(r){let e=new ArrayBuffer(4);return new DataView(e).setInt32(0,r,!1),new Uint8Array(e)}function jt(r,e){let t=0;for(let n=r-1;n>=0&&!e.testn(n);n--)t++;return t}function Yt(r,e){let t=0;for(let n=0;n<r&&!e.testn(n);n++)t++;return t}function at(r,e){for(let t=0;t<r;t++)if(e.testn(t))return!1;return!0}function Mn(r,e){return at(r,e)?null:jt(r,e)}function Fn(r,e){return at(r,e)?null:Yt(r,e)}var nc=Buffer.from("amm_config","utf8"),rc=Buffer.from("pool","utf8"),ic=Buffer.from("pool_vault","utf8"),oc=Buffer.from("pool_reward_vault","utf8"),hi=Buffer.from("position","utf8"),bi=Buffer.from("tick_array","utf8"),sc=Buffer.from("operation","utf8"),wi=Buffer.from("pool_tick_array_bitmap_extension","utf8"),ac=Buffer.from("observation","utf8");function ce(r,e,t){return st([bi,e.toBuffer(),_n(t)],r)}function On(r,e){return st([hi,e.toBuffer()],r)}function Zt(r,e){return st([wi,e.toBuffer()],r)}var uc=Buffer.from("locked_posit