@cobaltx/sdk-v2
Version:
An SDK for building applications on top of CobaltX.
1 lines • 64.3 kB
JavaScript
import Q from"bn.js";var re=new Q(0),xe=new Q(1),Mt=new Q(-1),qe=new Q(1).shln(64),Ge=new Q(1).shln(128),Pn=qe.sub(xe),rt=64,Ft=Ge.subn(1),ee=-443636,ie=-ee,it=new Q("4295048016"),ot=new Q("79226673521066979257578248091"),gi=new Q("4295048017"),hi=new Q("79226673521066979257578248090"),Ot=16,Dt="59543866431248",vt="184467440737095516",Kt="15793534762490258745",kn=new Q(10).pow(new Q(6));var bi=new Q("18446744073700000000");import fi from"bn.js";var Ae=9e15,ge=1e9,st="0123456789abcdef",Ue="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Xe="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",at={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Ae,maxE:Ae,crypto:!1},Ut,ue,w=!0,ze="[DecimalError] ",pe=ze+"Invalid argument: ",Xt=ze+"Precision limit exceeded",Wt=ze+"crypto unavailable",zt="[object Decimal]",X=Math.floor,O=Math.pow,Bn=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,In=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Nn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Ht=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,ne=1e7,h=7,Cn=9007199254740991,Sn=Ue.length-1,ut=Xe.length-1,f={toStringTag:zt};f.absoluteValue=f.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),g(n)};f.ceil=function(){return g(new this.constructor(this),this.e+1,2)};f.clampedTo=f.clamp=function(n,e){var t,r=this,i=r.constructor;if(n=new i(n),e=new i(e),!n.s||!e.s)return new i(NaN);if(n.gt(e))throw Error(pe+e);return t=r.cmp(n),t<0?n:r.cmp(e)>0?e:new i(r)};f.comparedTo=f.cmp=function(n){var e,t,r,i,o=this,s=o.d,a=(n=new o.constructor(n)).d,c=o.s,u=n.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!==n.e)return o.e>n.e^c<0?1:-1;for(r=s.length,i=a.length,e=0,t=r<i?r:i;e<t;++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 n,e,t=this,r=t.constructor;return t.d?t.d[0]?(n=r.precision,e=r.rounding,r.precision=n+Math.max(t.e,t.sd())+h,r.rounding=1,t=Ln(r,Jt(r,t)),r.precision=n,r.rounding=e,g(ue==2||ue==3?t.neg():t,n,e,!0)):new r(1):new r(NaN)};f.cubeRoot=f.cbrt=function(){var n,e,t,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*O(m.s*m,1/3),!o||Math.abs(o)==1/0?(t=q(m.d),n=m.e,(o=(n-t.length+1)%3)&&(t+=o==1||o==-2?"0":"00"),o=O(t,1/3),n=X((n+1)/3)-(n%3==(n<0?-1:2)),o==1/0?t="5e"+n:(t=o.toExponential(),t=t.slice(0,t.indexOf("e")+1)+n),r=new l(t),r.s=m.s):r=new l(o.toString()),s=(n=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),q(a.d).slice(0,s)===(t=q(r.d)).slice(0,s))if(t=t.slice(s-3,s+1),t=="9999"||!i&&t=="4999"){if(!i&&(g(a,n+1,0),a.times(a).times(a).eq(m))){r=a;break}s+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(g(r,n+1,1),e=!r.times(r).times(r).eq(m));break}return w=!0,g(r,n,l.rounding,e)};f.decimalPlaces=f.dp=function(){var n,e=this.d,t=NaN;if(e){if(n=e.length-1,t=(n-X(this.e/h))*h,n=e[n],n)for(;n%10==0;n/=10)t--;t<0&&(t=0)}return t};f.dividedBy=f.div=function(n){return N(this,new this.constructor(n))};f.dividedToIntegerBy=f.divToInt=function(n){var e=this,t=e.constructor;return g(N(e,new t(n),0,1,1),t.precision,t.rounding)};f.equals=f.eq=function(n){return this.cmp(n)===0};f.floor=function(){return g(new this.constructor(this),this.e+1,3)};f.greaterThan=f.gt=function(n){return this.cmp(n)>0};f.greaterThanOrEqualTo=f.gte=function(n){var e=this.cmp(n);return e==1||e===0};f.hyperbolicCosine=f.cosh=function(){var n,e,t,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;t=s.precision,r=s.rounding,s.precision=t+Math.max(o.e,o.sd())+4,s.rounding=1,i=o.d.length,i<32?(n=Math.ceil(i/3),e=(1/Ze(4,n)).toString()):(n=16,e="2.3283064365386962890625e-10"),o=Pe(s,1,o.times(e),new s(1),!0);for(var c,u=n,m=new s(8);u--;)c=o.times(o),o=a.minus(c.times(m.minus(c.times(m))));return g(o,s.precision=t,s.rounding=r,!0)};f.hyperbolicSine=f.sinh=function(){var n,e,t,r,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,r=i.d.length,r<3)i=Pe(o,2,i,i,!0);else{n=1.4*Math.sqrt(r),n=n>16?16:n|0,i=i.times(1/Ze(5,n)),i=Pe(o,2,i,i,!0);for(var s,a=new o(5),c=new o(16),u=new o(20);n--;)s=i.times(i),i=i.times(a.plus(s.times(c.times(s).plus(u))))}return o.precision=e,o.rounding=t,g(i,e,t,!0)};f.hyperbolicTangent=f.tanh=function(){var n,e,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,e=r.rounding,r.precision=n+7,r.rounding=1,N(t.sinh(),t.cosh(),r.precision=n,r.rounding=e)):new r(t.s)};f.inverseCosine=f.acos=function(){var n,e=this,t=e.constructor,r=e.abs().cmp(1),i=t.precision,o=t.rounding;return r!==-1?r===0?e.isNeg()?te(t,i,o):new t(0):new t(NaN):e.isZero()?te(t,i+4,o).times(.5):(t.precision=i+6,t.rounding=1,e=e.asin(),n=te(t,i+4,o).times(.5),t.precision=i,t.rounding=o,n.minus(e))};f.inverseHyperbolicCosine=f.acosh=function(){var n,e,t=this,r=t.constructor;return t.lte(1)?new r(t.eq(1)?0:NaN):t.isFinite()?(n=r.precision,e=r.rounding,r.precision=n+Math.max(Math.abs(t.e),t.sd())+4,r.rounding=1,w=!1,t=t.times(t).minus(1).sqrt().plus(t),w=!0,r.precision=n,r.rounding=e,t.ln()):new r(t)};f.inverseHyperbolicSine=f.asinh=function(){var n,e,t=this,r=t.constructor;return!t.isFinite()||t.isZero()?new r(t):(n=r.precision,e=r.rounding,r.precision=n+2*Math.max(Math.abs(t.e),t.sd())+6,r.rounding=1,w=!1,t=t.times(t).plus(1).sqrt().plus(t),w=!0,r.precision=n,r.rounding=e,t.ln())};f.inverseHyperbolicTangent=f.atanh=function(){var n,e,t,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):(n=o.precision,e=o.rounding,r=i.sd(),Math.max(r,n)<2*-i.e-1?g(new o(i),n,e,!0):(o.precision=t=r-i.e,i=N(i.plus(1),new o(1).minus(i),t+n,1),o.precision=n+4,o.rounding=1,i=i.ln(),o.precision=n,o.rounding=e,i.times(.5))):new o(NaN)};f.inverseSine=f.asin=function(){var n,e,t,r,i=this,o=i.constructor;return i.isZero()?new o(i):(e=i.abs().cmp(1),t=o.precision,r=o.rounding,e!==-1?e===0?(n=te(o,t+4,r).times(.5),n.s=i.s,n):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=r,i.times(2)))};f.inverseTangent=f.atan=function(){var n,e,t,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<=ut)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<=ut)return s=te(m,l+4,d).times(.5),s.s=u.s,s}for(m.precision=a=l+10,m.rounding=1,t=Math.min(28,a/h+2|0),n=t;n;--n)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(w=!1,e=Math.ceil(a/h),r=1,c=u.times(u),s=new m(u),i=u;n!==-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(n=e;s.d[n]===o.d[n]&&n--;);return t&&(s=s.times(2<<t-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&&X(this.e/h)>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(n){return this.cmp(n)<0};f.lessThanOrEqualTo=f.lte=function(n){return this.cmp(n)<1};f.logarithm=f.log=function(n){var e,t,r,i,o,s,a,c,u=this,m=u.constructor,l=m.precision,d=m.rounding,p=5;if(n==null)n=new m(10),e=!0;else{if(n=new m(n),t=n.d,n.s<0||!t||!t[0]||n.eq(1))return new m(NaN);e=n.eq(10)}if(t=u.d,u.s<0||!t||!t[0]||u.eq(1))return new m(t&&!t[0]?-1/0:u.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(w=!1,a=l+p,s=fe(u,a),r=e?We(m,a+10):fe(n,a),c=N(s,r,a,1),Ce(c.d,i=l,d))do if(a+=10,s=fe(u,a),r=e?We(m,a+10):fe(n,a),c=N(s,r,a,1),!o){+q(c.d).slice(i+1,i+15)+1==1e14&&(c=g(c,l+1,0));break}while(Ce(c.d,i+=10,d));return w=!0,g(c,l,d)};f.minus=f.sub=function(n){var e,t,r,i,o,s,a,c,u,m,l,d,p=this,y=p.constructor;if(n=new y(n),!p.d||!n.d)return!p.s||!n.s?n=new y(NaN):p.d?n.s=-n.s:n=new y(n.d||p.s!==n.s?p:NaN),n;if(p.s!=n.s)return n.s=-n.s,p.plus(n);if(u=p.d,d=n.d,a=y.precision,c=y.rounding,!u[0]||!d[0]){if(d[0])n.s=-n.s;else if(u[0])n=new y(p);else return new y(c===3?-0:0);return w?g(n,a,c):n}if(t=X(n.e/h),m=X(p.e/h),u=u.slice(),o=m-t,o){for(l=o<0,l?(e=u,o=-o,s=d.length):(e=d,t=m,s=u.length),r=Math.max(Math.ceil(a/h),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,n.s=-n.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())--t;return u[0]?(n.d=u,n.e=He(u,t),w?g(n,a,c):n):new y(c===3?-0:0)};f.modulo=f.mod=function(n){var e,t=this,r=t.constructor;return n=new r(n),!t.d||!n.s||n.d&&!n.d[0]?new r(NaN):!n.d||t.d&&!t.d[0]?g(new r(t),r.precision,r.rounding):(w=!1,r.modulo==9?(e=N(t,n.abs(),0,3,1),e.s*=n.s):e=N(t,n,0,r.modulo,1),e=e.times(n),w=!0,t.minus(e))};f.naturalExponential=f.exp=function(){return ct(this)};f.naturalLogarithm=f.ln=function(){return fe(this)};f.negated=f.neg=function(){var n=new this.constructor(this);return n.s=-n.s,g(n)};f.plus=f.add=function(n){var e,t,r,i,o,s,a,c,u,m,l=this,d=l.constructor;if(n=new d(n),!l.d||!n.d)return!l.s||!n.s?n=new d(NaN):l.d||(n=new d(n.d||l.s===n.s?l:NaN)),n;if(l.s!=n.s)return n.s=-n.s,l.minus(n);if(u=l.d,m=n.d,a=d.precision,c=d.rounding,!u[0]||!m[0])return m[0]||(n=new d(l)),w?g(n,a,c):n;if(o=X(l.e/h),r=X(n.e/h),u=u.slice(),i=o-r,i){for(i<0?(t=u,i=-i,s=m.length):(t=m,r=o,s=u.length),o=Math.ceil(a/h),s=o>s?o+1:s+1,i>s&&(i=s,t.length=1),t.reverse();i--;)t.push(0);t.reverse()}for(s=u.length,i=m.length,s-i<0&&(i=s,t=m,m=u,u=t),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 n.d=u,n.e=He(u,r),w?g(n,a,c):n};f.precision=f.sd=function(n){var e,t=this;if(n!==void 0&&n!==!!n&&n!==1&&n!==0)throw Error(pe+n);return t.d?(e=Zt(t.d),n&&t.e+1>e&&(e=t.e+1)):e=NaN,e};f.round=function(){var n=this,e=n.constructor;return g(new e(n),n.e+1,e.rounding)};f.sine=f.sin=function(){var n,e,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,e=r.rounding,r.precision=n+Math.max(t.e,t.sd())+h,r.rounding=1,t=Rn(r,Jt(r,t)),r.precision=n,r.rounding=e,g(ue>2?t.neg():t,n,e,!0)):new r(NaN)};f.squareRoot=f.sqrt=function(){var n,e,t,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=q(a),(e.length+c)%2==0&&(e+="0"),u=Math.sqrt(e),c=X((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()),t=(c=m.precision)+3;;)if(o=r,r=o.plus(N(s,o,t+2,1)).times(.5),q(o.d).slice(0,t)===(e=q(r.d)).slice(0,t))if(e=e.slice(t-3,t+1),e=="9999"||!i&&e=="4999"){if(!i&&(g(o,c+1,0),o.times(o).eq(s))){r=o;break}t+=4,i=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(g(r,c+1,1),n=!r.times(r).eq(s));break}return w=!0,g(r,c,m.rounding,n)};f.tangent=f.tan=function(){var n,e,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,e=r.rounding,r.precision=n+10,r.rounding=1,t=t.sin(),t.s=1,t=N(t,new r(1).minus(t.times(t)).sqrt(),n+10,0),r.precision=n,r.rounding=e,g(ue==2||ue==4?t.neg():t,n,e,!0)):new r(NaN)};f.times=f.mul=function(n){var e,t,r,i,o,s,a,c,u,m=this,l=m.constructor,d=m.d,p=(n=new l(n)).d;if(n.s*=m.s,!d||!d[0]||!p||!p[0])return new l(!n.s||d&&!d[0]&&!p||p&&!p[0]&&!d?NaN:!d||!p?n.s/0:n.s*0);for(t=X(m.e/h)+X(n.e/h),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?++t:o.shift(),n.d=o,n.e=He(o,t),w?g(n,l.precision,l.rounding):n};f.toBinary=function(n,e){return lt(this,2,n,e)};f.toDecimalPlaces=f.toDP=function(n,e){var t=this,r=t.constructor;return t=new r(t),n===void 0?t:(H(n,0,ge),e===void 0?e=r.rounding:H(e,0,8),g(t,n+t.e+1,e))};f.toExponential=function(n,e){var t,r=this,i=r.constructor;return n===void 0?t=oe(r,!0):(H(n,0,ge),e===void 0?e=i.rounding:H(e,0,8),r=g(new i(r),n+1,e),t=oe(r,!0,n+1)),r.isNeg()&&!r.isZero()?"-"+t:t};f.toFixed=function(n,e){var t,r,i=this,o=i.constructor;return n===void 0?t=oe(i):(H(n,0,ge),e===void 0?e=o.rounding:H(e,0,8),r=g(new o(i),n+i.e+1,e),t=oe(r,!1,n+r.e+1)),i.isNeg()&&!i.isZero()?"-"+t:t};f.toFraction=function(n){var e,t,r,i,o,s,a,c,u,m,l,d,p=this,y=p.d,b=p.constructor;if(!y)return new b(p);if(u=t=new b(1),r=c=new b(0),e=new b(r),o=e.e=Zt(y)-p.e-1,s=o%h,e.d[0]=O(10,s<0?h+s:s),n==null)n=o>0?e:u;else{if(a=new b(n),!a.isInt()||a.lt(u))throw Error(pe+a);n=a.gt(e)?o>0?e:u:a}for(w=!1,a=new b(q(y)),m=b.precision,b.precision=o=y.length*h*2;l=N(a,e,0,1,1),i=t.plus(l.times(r)),i.cmp(n)!=1;)t=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(n.minus(t),r,0,1,1),c=c.plus(i.times(u)),t=t.plus(i.times(r)),c.s=u.s=p.s,d=N(u,r,o,1).minus(p).abs().cmp(N(c,t,o,1).minus(p).abs())<1?[u,r]:[c,t],b.precision=m,w=!0,d};f.toHexadecimal=f.toHex=function(n,e){return lt(this,16,n,e)};f.toNearest=function(n,e){var t=this,r=t.constructor;if(t=new r(t),n==null){if(!t.d)return t;n=new r(1),e=r.rounding}else{if(n=new r(n),e===void 0?e=r.rounding:H(e,0,8),!t.d)return n.s?t:n;if(!n.d)return n.s&&(n.s=t.s),n}return n.d[0]?(w=!1,t=N(t,n,0,e,1).times(n),w=!0,g(t)):(n.s=t.s,t=n),t};f.toNumber=function(){return+this};f.toOctal=function(n,e){return lt(this,8,n,e)};f.toPower=f.pow=function(n){var e,t,r,i,o,s,a=this,c=a.constructor,u=+(n=new c(n));if(!a.d||!n.d||!a.d[0]||!n.d[0])return new c(O(+a,u));if(a=new c(a),a.eq(1))return a;if(r=c.precision,o=c.rounding,n.eq(1))return g(a,r,o);if(e=X(n.e/h),e>=n.d.length-1&&(t=u<0?-u:u)<=Cn)return i=jt(c,a,t,r),n.s<0?new c(1).div(i):g(i,r,o);if(s=a.s,s<0){if(e<n.d.length-1)return new c(NaN);if((n.d[e]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return t=O(+a,u),e=t==0||!isFinite(t)?X(u*(Math.log("0."+q(a.d))/Math.LN10+a.e+1)):new c(t+"").e,e>c.maxE+1||e<c.minE-1?new c(e>0?s/0:0):(w=!1,c.rounding=a.s=1,t=Math.min(12,(e+"").length),i=ct(n.times(fe(a,r+t)),r),i.d&&(i=g(i,r+5,1),Ce(i.d,r,o)&&(e=r+10,i=g(ct(n.times(fe(a,e+t)),e),e+5,1),+q(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(n,e){var t,r=this,i=r.constructor;return n===void 0?t=oe(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(H(n,1,ge),e===void 0?e=i.rounding:H(e,0,8),r=g(new i(r),n,e),t=oe(r,n<=r.e||r.e<=i.toExpNeg,n)),r.isNeg()&&!r.isZero()?"-"+t:t};f.toSignificantDigits=f.toSD=function(n,e){var t=this,r=t.constructor;return n===void 0?(n=r.precision,e=r.rounding):(H(n,1,ge),e===void 0?e=r.rounding:H(e,0,8)),g(new r(t),n,e)};f.toString=function(){var n=this,e=n.constructor,t=oe(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()&&!n.isZero()?"-"+t:t};f.truncated=f.trunc=function(){return g(new this.constructor(this),this.e+1,1)};f.valueOf=f.toJSON=function(){var n=this,e=n.constructor,t=oe(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()?"-"+t:t};function q(n){var e,t,r,i=n.length-1,o="",s=n[0];if(i>0){for(o+=s,e=1;e<i;e++)r=n[e]+"",t=h-r.length,t&&(o+=de(t)),o+=r;s=n[e],r=s+"",t=h-r.length,t&&(o+=de(t))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function H(n,e,t){if(n!==~~n||n<e||n>t)throw Error(pe+n)}function Ce(n,e,t,r){var i,o,s,a;for(o=n[0];o>=10;o/=10)--e;return--e<0?(e+=h,i=0):(i=Math.ceil((e+1)/h),e%=h),o=O(10,h-e),a=n[i]%o|0,r==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)&&(n[i+1]/o/100|0)==O(10,e-2)-1||(a==o/2||a==0)&&(n[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||t<4)&&a==9999||!r&&t>3&&a==4999):s=((r||t<4)&&a+1==o||!r&&t>3&&a+1==o/2)&&(n[i+1]/o/1e3|0)==O(10,e-3)-1,s}function Ve(n,e,t){for(var r,i=[0],o,s=0,a=n.length;s<a;){for(o=i.length;o--;)i[o]*=e;for(i[0]+=st.indexOf(n.charAt(s++)),r=0;r<i.length;r++)i[r]>t-1&&(i[r+1]===void 0&&(i[r+1]=0),i[r+1]+=i[r]/t|0,i[r]%=t)}return i.reverse()}function Ln(n,e){var t,r,i;if(e.isZero())return e;r=e.d.length,r<32?(t=Math.ceil(r/3),i=(1/Ze(4,t)).toString()):(t=16,i="2.3283064365386962890625e-10"),n.precision+=t,e=Pe(n,1,e.times(i),new n(1));for(var o=t;o--;){var s=e.times(e);e=s.times(s).minus(s).times(8).plus(1)}return n.precision-=t,e}var N=function(){function n(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 t(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,y,b,K,L,J,I,V,Oe,ae,et,De,Ne,tt,$,ve,Ke=r.constructor,nt=r.s==i.s?1:-1,U=r.d,C=i.d;if(!U||!U[0]||!C||!C[0])return new Ke(!r.s||!i.s||(U?C&&U[0]==C[0]:!C)?NaN:U&&U[0]==0||!C?nt*0:nt/0);for(c?(p=1,m=r.e-i.e):(c=ne,p=h,m=X(r.e/p)-X(i.e/p)),$=C.length,Ne=U.length,L=new Ke(nt),J=L.d=[],l=0;C[l]==(U[l]||0);l++);if(C[l]>(U[l]||0)&&m--,o==null?(ae=o=Ke.precision,s=Ke.rounding):a?ae=o+(r.e-i.e)+1:ae=o,ae<0)J.push(1),y=!0;else{if(ae=ae/p+2|0,l=0,$==1){for(d=0,C=C[0],ae++;(l<Ne||d)&&ae--;l++)et=d*c+(U[l]||0),J[l]=et/C|0,d=et%C|0;y=d||l<Ne}else{for(d=c/(C[0]+1)|0,d>1&&(C=n(C,d,c),U=n(U,d,c),$=C.length,Ne=U.length),De=$,I=U.slice(0,$),V=I.length;V<$;)I[V++]=0;ve=C.slice(),ve.unshift(0),tt=C[0],C[1]>=c/2&&++tt;do d=0,u=e(C,I,$,V),u<0?(Oe=I[0],$!=V&&(Oe=Oe*c+(I[1]||0)),d=Oe/tt|0,d>1?(d>=c&&(d=c-1),b=n(C,d,c),K=b.length,V=I.length,u=e(b,I,K,V),u==1&&(d--,t(b,$<K?ve:C,K,c))):(d==0&&(u=d=1),b=C.slice()),K=b.length,K<V&&b.unshift(0),t(I,b,V,c),u==-1&&(V=I.length,u=e(C,I,$,V),u<1&&(d++,t(I,$<V?ve:C,V,c))),V=I.length):u===0&&(d++,I=[0]),J[l++]=d,u&&I[0]?I[V++]=U[De]||0:(I=[U[De]],V=1);while((De++<Ne||I[0]!==void 0)&&ae--);y=I[0]!==void 0}J[0]||J.shift()}if(p==1)L.e=m,Ut=y;else{for(l=1,d=J[0];d>=10;d/=10)l++;L.e=l+m*p-1,g(L,a?o+L.e+1:o,s,y)}return L}}();function g(n,e,t,r){var i,o,s,a,c,u,m,l,d,p=n.constructor;e:if(e!=null){if(l=n.d,!l)return n;for(i=1,a=l[0];a>=10;a/=10)i++;if(o=e-i,o<0)o+=h,s=e,m=l[d=0],c=m/O(10,i-s-1)%10|0;else if(d=Math.ceil((o+1)/h),a=l.length,d>=a)if(r){for(;a++<=d;)l.push(0);m=c=0,i=1,o%=h,s=o-h+1}else break e;else{for(m=a=l[d],i=1;a>=10;a/=10)i++;o%=h,s=o-h+i,c=s<0?0:m/O(10,i-s-1)%10|0}if(r=r||e<0||l[d+1]!==void 0||(s<0?m:m%O(10,i-s-1)),u=t<4?(c||r)&&(t==0||t==(n.s<0?3:2)):c>5||c==5&&(t==4||r||t==6&&(o>0?s>0?m/O(10,i-s):0:l[d-1])%10&1||t==(n.s<0?8:7)),e<1||!l[0])return l.length=0,u?(e-=n.e+1,l[0]=O(10,(h-e%h)%h),n.e=-e||0):l[0]=n.e=0,n;if(o==0?(l.length=d,a=1,d--):(l.length=d+1,a=O(10,h-o),l[d]=s>0?(m/O(10,i-s)%O(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&&(n.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&&(n.e>p.maxE?(n.d=null,n.e=NaN):n.e<p.minE&&(n.e=0,n.d=[0])),n}function oe(n,e,t){if(!n.isFinite())return Yt(n);var r,i=n.e,o=q(n.d),s=o.length;return e?(t&&(r=t-s)>0?o=o.charAt(0)+"."+o.slice(1)+de(r):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(n.e<0?"e":"e+")+n.e):i<0?(o="0."+de(-i-1)+o,t&&(r=t-s)>0&&(o+=de(r))):i>=s?(o+=de(i+1-s),t&&(r=t-i-1)>0&&(o=o+"."+de(r))):((r=i+1)<s&&(o=o.slice(0,r)+"."+o.slice(r)),t&&(r=t-s)>0&&(i+1===s&&(o+="."),o+=de(r))),o}function He(n,e){var t=n[0];for(e*=h;t>=10;t/=10)e++;return e}function We(n,e,t){if(e>Sn)throw w=!0,t&&(n.precision=t),Error(Xt);return g(new n(Ue),e,1,!0)}function te(n,e,t){if(e>ut)throw Error(Xt);return g(new n(Xe),e,t,!0)}function Zt(n){var e=n.length-1,t=e*h+1;if(e=n[e],e){for(;e%10==0;e/=10)t--;for(e=n[0];e>=10;e/=10)t++}return t}function de(n){for(var e="";n--;)e+="0";return e}function jt(n,e,t,r){var i,o=new n(1),s=Math.ceil(r/h+4);for(w=!1;;){if(t%2&&(o=o.times(e),Gt(o.d,s)&&(i=!0)),t=X(t/2),t===0){t=o.d.length-1,i&&o.d[t]===0&&++o.d[t];break}e=e.times(e),Gt(e.d,s)}return w=!0,o}function qt(n){return n.d[n.d.length-1]&1}function Qt(n,e,t){for(var r,i=new n(e[0]),o=0;++o<e.length;)if(r=new n(e[o]),r.s)i[t](r)&&(i=r);else{i=r;break}return i}function ct(n,e){var t,r,i,o,s,a,c,u=0,m=0,l=0,d=n.constructor,p=d.rounding,y=d.precision;if(!n.d||!n.d[0]||n.e>17)return new d(n.d?n.d[0]?n.s<0?0:1/0:1:n.s?n.s<0?0:n:0/0);for(e==null?(w=!1,c=y):c=e,a=new d(.03125);n.e>-2;)n=n.times(a),l+=5;for(r=Math.log(O(2,l))/Math.LN10*2+5|0,c+=r,t=o=s=new d(1),d.precision=c;;){if(o=g(o.times(n),c,1),t=t.times(++m),a=s.plus(N(o,t,c,1)),q(a.d).slice(0,c)===q(s.d).slice(0,c)){for(i=l;i--;)s=g(s.times(s),c,1);if(e==null)if(u<3&&Ce(s.d,c-r,p,u))d.precision=c+=10,t=o=a=new d(1),m=0,u++;else return g(s,d.precision=y,p,w=!0);else return d.precision=y,s}s=a}}function fe(n,e){var t,r,i,o,s,a,c,u,m,l,d,p=1,y=10,b=n,K=b.d,L=b.constructor,J=L.rounding,I=L.precision;if(b.s<0||!K||!K[0]||!b.e&&K[0]==1&&K.length==1)return new L(K&&!K[0]?-1/0:b.s!=1?NaN:K?0:b);if(e==null?(w=!1,m=I):m=e,L.precision=m+=y,t=q(K),r=t.charAt(0),Math.abs(o=b.e)<15e14){for(;r<7&&r!=1||r==1&&t.charAt(1)>3;)b=b.times(n),t=q(b.d),r=t.charAt(0),p++;o=b.e,r>1?(b=new L("0."+t),o++):b=new L(r+"."+t.slice(1))}else return u=We(L,m+2,I).times(o+""),b=fe(new L(r+"."+t.slice(1)),m-y).plus(u),L.precision=I,e==null?g(b,I,J,w=!0):b;for(l=b,c=s=b=N(b.minus(1),b.plus(1),m,1),d=g(b.times(b),m,1),i=3;;){if(s=g(s.times(d),m,1),u=c.plus(N(s,new L(i),m,1)),q(u.d).slice(0,m)===q(c.d).slice(0,m))if(c=c.times(2),o!==0&&(c=c.plus(We(L,m+2,I).times(o+""))),c=N(c,new L(p),m,1),e==null)if(Ce(c.d,m-y,J,a))L.precision=m+=y,u=s=b=N(l.minus(1),l.plus(1),m,1),d=g(b.times(b),m,1),i=a=1;else return g(c,L.precision=I,J,w=!0);else return L.precision=I,c;c=u,i+=2}}function Yt(n){return String(n.s*n.s/0)}function mt(n,e){var t,r,i;for((t=e.indexOf("."))>-1&&(e=e.replace(".","")),(r=e.search(/e/i))>0?(t<0&&(t=r),t+=+e.slice(r+1),e=e.substring(0,r)):t<0&&(t=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,n.e=t=t-r-1,n.d=[],r=(t+1)%h,t<0&&(r+=h),r<i){for(r&&n.d.push(+e.slice(0,r)),i-=h;r<i;)n.d.push(+e.slice(r,r+=h));e=e.slice(r),r=h-e.length}else r-=i;for(;r--;)e+="0";n.d.push(+e),w&&(n.e>n.constructor.maxE?(n.d=null,n.e=NaN):n.e<n.constructor.minE&&(n.e=0,n.d=[0]))}else n.e=0,n.d=[0];return n}function En(n,e){var t,r,i,o,s,a,c,u,m;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),Ht.test(e))return mt(n,e)}else if(e==="Infinity"||e==="NaN")return+e||(n.s=NaN),n.e=NaN,n.d=null,n;if(In.test(e))t=16,e=e.toLowerCase();else if(Bn.test(e))t=2;else if(Nn.test(e))t=8;else throw Error(pe+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=n.constructor,s&&(e=e.replace(".",""),a=e.length,o=a-o,i=jt(r,new r(t),o,o*2)),u=Ve(e,t,ne),m=u.length-1,o=m;u[o]===0;--o)u.pop();return o<0?new r(n.s*0):(n.e=He(u,m),n.d=u,w=!1,s&&(n=N(n,i,a*4)),c&&(n=n.times(Math.abs(c)<54?O(2,c):Se.pow(2,c))),w=!0,n)}function Rn(n,e){var t,r=e.d.length;if(r<3)return e.isZero()?e:Pe(n,2,e,e);t=1.4*Math.sqrt(r),t=t>16?16:t|0,e=e.times(1/Ze(5,t)),e=Pe(n,2,e,e);for(var i,o=new n(5),s=new n(16),a=new n(20);t--;)i=e.times(e),e=e.times(o.plus(i.times(s.times(i).minus(a))));return e}function Pe(n,e,t,r,i){var o,s,a,c,u=1,m=n.precision,l=Math.ceil(m/h);for(w=!1,c=t.times(t),a=new n(r);;){if(s=N(a.times(c),new n(e++*e++),m,1),a=i?r.plus(s):r.minus(s),r=N(s.times(c),new n(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 Ze(n,e){for(var t=n;--e;)t*=n;return t}function Jt(n,e){var t,r=e.s<0,i=te(n,n.precision,1),o=i.times(.5);if(e=e.abs(),e.lte(o))return ue=r?4:1,e;if(t=e.divToInt(i),t.isZero())ue=r?3:2;else{if(e=e.minus(t.times(i)),e.lte(o))return ue=qt(t)?r?2:3:r?4:1,e;ue=qt(t)?r?1:4:r?3:2}return e.minus(i).abs()}function lt(n,e,t,r){var i,o,s,a,c,u,m,l,d,p=n.constructor,y=t!==void 0;if(y?(H(t,1,ge),r===void 0?r=p.rounding:H(r,0,8)):(t=p.precision,r=p.rounding),!n.isFinite())m=Yt(n);else{for(m=oe(n),s=m.indexOf("."),y?(i=2,e==16?t=t*4-3:e==8&&(t=t*3-2)):i=e,s>=0&&(m=m.replace(".",""),d=new p(1),d.e=m.length-s,d.d=Ve(oe(d),10,i),d.e=d.d.length),l=Ve(m,10,i),o=c=l.length;l[--c]==0;)l.pop();if(!l[0])m=y?"0p+0":"0";else{if(s<0?o--:(n=new p(n),n.d=l,n.e=o,n=N(n,d,t,r,0,i),l=n.d,o=n.e,u=Ut),s=l[t],a=i/2,u=u||l[t+1]!==void 0,u=r<4?(s!==void 0||u)&&(r===0||r===(n.s<0?3:2)):s>a||s===a&&(r===4||u||r===6&&l[t-1]&1||r===(n.s<0?8:7)),l.length=t,u)for(;++l[--t]>i-1;)l[t]=0,t||(++o,l.unshift(1));for(c=l.length;!l[c-1];--c);for(s=0,m="";s<c;s++)m+=st.charAt(l[s]);if(y){if(c>1)if(e==16||e==8){for(s=e==16?4:3,--c;c%s;c++)m+="0";for(l=Ve(m,i,e),c=l.length;!l[c-1];--c);for(s=1,m="1.";s<c;s++)m+=st.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 n.s<0?"-"+m:m}function Gt(n,e){if(n.length>e)return n.length=e,!0}function _n(n){return new this(n).abs()}function Mn(n){return new this(n).acos()}function Fn(n){return new this(n).acosh()}function On(n,e){return new this(n).plus(e)}function Dn(n){return new this(n).asin()}function vn(n){return new this(n).asinh()}function Kn(n){return new this(n).atan()}function qn(n){return new this(n).atanh()}function Gn(n,e){n=new this(n),e=new this(e);var t,r=this.precision,i=this.rounding,o=r+4;return!n.s||!e.s?t=new this(NaN):!n.d&&!e.d?(t=te(this,o,1).times(e.s>0?.25:.75),t.s=n.s):!e.d||n.isZero()?(t=e.s<0?te(this,r,i):new this(0),t.s=n.s):!n.d||e.isZero()?(t=te(this,o,1).times(.5),t.s=n.s):e.s<0?(this.precision=o,this.rounding=1,t=this.atan(N(n,e,o,1)),e=te(this,o,1),this.precision=r,this.rounding=i,t=n.s<0?t.minus(e):t.plus(e)):t=this.atan(N(n,e,o,1)),t}function Vn(n){return new this(n).cbrt()}function Un(n){return g(n=new this(n),n.e+1,2)}function Xn(n,e,t){return new this(n).clamp(e,t)}function Wn(n){if(!n||typeof n!="object")throw Error(ze+"Object expected");var e,t,r,i=n.defaults===!0,o=["precision",1,ge,"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(t=o[e],i&&(this[t]=at[t]),(r=n[t])!==void 0)if(X(r)===r&&r>=o[e+1]&&r<=o[e+2])this[t]=r;else throw Error(pe+t+": "+r);if(t="crypto",i&&(this[t]=at[t]),(r=n[t])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[t]=!0;else throw Error(Wt);else this[t]=!1;else throw Error(pe+t+": "+r);return this}function zn(n){return new this(n).cos()}function Hn(n){return new this(n).cosh()}function $t(n){var e,t,r;function i(o){var s,a,c,u=this;if(!(u instanceof i))return new i(o);if(u.constructor=i,Vt(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 mt(u,o.toString())}else if(c!=="string")throw Error(pe+o);return(a=o.charCodeAt(0))===45?(o=o.slice(1),u.s=-1):(a===43&&(o=o.slice(1)),u.s=1),Ht.test(o)?mt(u,o):En(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=$t,i.isDecimal=Vt,i.abs=_n,i.acos=Mn,i.acosh=Fn,i.add=On,i.asin=Dn,i.asinh=vn,i.atan=Kn,i.atanh=qn,i.atan2=Gn,i.cbrt=Vn,i.ceil=Un,i.clamp=Xn,i.cos=zn,i.cosh=Hn,i.div=Zn,i.exp=jn,i.floor=Qn,i.hypot=Yn,i.ln=Jn,i.log=$n,i.log10=tr,i.log2=er,i.max=nr,i.min=rr,i.mod=ir,i.mul=or,i.pow=sr,i.random=ar,i.round=ur,i.sign=cr,i.sin=mr,i.sinh=lr,i.sqrt=dr,i.sub=fr,i.sum=pr,i.tan=gr,i.tanh=hr,i.trunc=br,n===void 0&&(n={}),n&&n.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<r.length;)n.hasOwnProperty(t=r[e++])||(n[t]=this[t]);return i.config(n),i}function Zn(n,e){return new this(n).div(e)}function jn(n){return new this(n).exp()}function Qn(n){return g(n=new this(n),n.e+1,3)}function Yn(){var n,e,t=new this(0);for(w=!1,n=0;n<arguments.length;)if(e=new this(arguments[n++]),e.d)t.d&&(t=t.plus(e.times(e)));else{if(e.s)return w=!0,new this(1/0);t=e}return w=!0,t.sqrt()}function Vt(n){return n instanceof Se||n&&n.toStringTag===zt||!1}function Jn(n){return new this(n).ln()}function $n(n,e){return new this(n).log(e)}function er(n){return new this(n).log(2)}function tr(n){return new this(n).log(10)}function nr(){return Qt(this,arguments,"lt")}function rr(){return Qt(this,arguments,"gt")}function ir(n,e){return new this(n).mod(e)}function or(n,e){return new this(n).mul(e)}function sr(n,e){return new this(n).pow(e)}function ar(n){var e,t,r,i,o=0,s=new this(1),a=[];if(n===void 0?n=this.precision:H(n,1,ge),r=Math.ceil(n/h),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(Wt);else for(;o<r;)a[o++]=Math.random()*1e7|0;for(r=a[--o],n%=h,r&&n&&(i=O(10,h-n),a[o]=(r/i|0)*i);a[o]===0;o--)a.pop();if(o<0)t=0,a=[0];else{for(t=-1;a[0]===0;t-=h)a.shift();for(r=1,i=a[0];i>=10;i/=10)r++;r<h&&(t-=h-r)}return s.e=t,s.d=a,s}function ur(n){return g(n=new this(n),n.e+1,this.rounding)}function cr(n){return n=new this(n),n.d?n.d[0]?n.s:0*n.s:n.s||NaN}function mr(n){return new this(n).sin()}function lr(n){return new this(n).sinh()}function dr(n){return new this(n).sqrt()}function fr(n,e){return new this(n).sub(e)}function pr(){var n=0,e=arguments,t=new this(e[n]);for(w=!1;t.s&&++n<e.length;)t=t.plus(e[n]);return w=!0,g(t,this.precision,this.rounding)}function gr(n){return new this(n).tan()}function hr(n){return new this(n).tanh()}function br(n){return g(n=new this(n),n.e+1,1)}f[Symbol.for("nodejs.util.inspect.custom")]=f.toString;f[Symbol.toStringTag]="Decimal";var Se=f.constructor=$t(at);Ue=new Se(Ue);Xe=new Se(Xe);var W=Se;import B from"bn.js";import xi from"bn.js";import{MINT_SIZE as Ii,TOKEN_PROGRAM_ID as Ni,getTransferFeeConfig as Ci,unpackMint as Si}from"@solana/spl-token";import{PublicKey as Tr}from"@solana/web3.js";import{get as en,set as wr}from"lodash";var dt=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(r=>typeof r=="object"?JSON.stringify(r):r).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}},tn={},yr={};function Y(n){let e=en(tn,n);if(!e){let t=en(yr,n);e=new dt({name:n,logLevel:t}),wr(tn,n,e)}return e}var ft=Y("CobaltX_accountInfo_util");async function je(n,e,t){let{batchRequest:r,commitment:i="confirmed",chunkCount:o=100}={batchRequest:!1,...t},s=pt(e,o),a=new Array(s.length).fill([]);if(r){let c=s.map(l=>{let d=n._buildArgs([l.map(p=>p.toBase58())],i,"base64");return{methodName:"getMultipleAccounts",args:d}}),u=pt(c,10);a=(await(await Promise.all(u.map(async l=>await n._rpcBatchRequest(l)))).flat()).map(l=>(l.error&&ft.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${l.error.message}`),l.result.value.map(d=>{if(d){let{data:p,executable:y,lamports:b,owner:K,rentEpoch:L}=d;return p.length!==2&&p[1]!=="base64"&&ft.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(p[0],"base64"),executable:y,lamports:b,owner:new Tr(K),rentEpoch:L}}return null})))}else try{a=await Promise.all(s.map(c=>n.getMultipleAccountsInfo(c,i)))}catch(c){c instanceof Error&&ft.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return a.flat()}import me from"bn.js";import Sr from"big.js";import Ji from"bn.js";import Ar from"toformat";var Pr=Ar,Le=Pr;import Ye from"big.js";import Br from"bn.js";import Ir from"decimal.js-light";import Ee from"bn.js";var nn=9007199254740991;function ce(n){let e=Y("CobaltX_parseBigNumberish");if(n instanceof Ee)return n;if(typeof n=="string"){if(n.match(/^-?[0-9]+$/))return new Ee(n);e.logWithError(`invalid BigNumberish string: ${n}`)}return typeof n=="number"?(n%1&&e.logWithError(`BigNumberish number underflow: ${n}`),(n>=nn||n<=-nn)&&e.logWithError(`BigNumberish number overflow: ${n}`),new Ee(String(n))):typeof n=="bigint"?new Ee(n.toString()):(e.error(`invalid BigNumberish value: ${n}`),new Ee(0))}var Qe=Y("module/fraction"),ht=Le(Ye),Re=Le(Ir),Nr={[0]:Re.ROUND_DOWN,[1]:Re.ROUND_HALF_UP,[2]:Re.ROUND_UP},Cr={[0]:Ye.roundDown,[1]:Ye.roundHalfUp,[2]:Ye.roundUp},E=class{constructor(e,t=new Br(1)){this.numerator=ce(e),this.denominator=ce(t)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new E(this.denominator,this.numerator)}add(e){let t=e instanceof E?e:new E(ce(e));return this.denominator.eq(t.denominator)?new E(this.numerator.add(t.numerator),this.denominator):new E(this.numerator.mul(t.denominator).add(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}sub(e){let t=e instanceof E?e:new E(ce(e));return this.denominator.eq(t.denominator)?new E(this.numerator.sub(t.numerator),this.denominator):new E(this.numerator.mul(t.denominator).sub(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}mul(e){let t=e instanceof E?e:new E(ce(e));return new E(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof E?e:new E(ce(e));return new E(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},r=1){Number.isInteger(e)||Qe.logWithError(`${e} is not an integer.`),e<=0&&Qe.logWithError(`${e} is not positive.`),Re.set({precision:e+1,rounding:Nr[r]});let i=new Re(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return i.toFormat(i.decimalPlaces(),t)}toFixed(e,t={groupSeparator:""},r=1){return Number.isInteger(e)||Qe.logWithError(`${e} is not an integer.`),e<0&&Qe.logWithError(`${e} is negative.`),ht.DP=e,ht.RM=Cr[r]||1,new ht(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};var ao=Y("CobaltX_amount"),uo=Le(Sr);import{TOKEN_PROGRAM_ID as rn}from"@solana/spl-token";import{PublicKey as Er}from"@solana/web3.js";var on={chainId:101,address:Er.default.toBase58(),programId:rn.toBase58(),decimals:9,symbol:"ETH",name:"Ethereum",logoURI:"https://raw.githubusercontent.com/cobaltx-io/tokens/main/logo/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"cobaltx",extensions:{coingeckoId:"solana"}},be={chainId:101,address:"So11111111111111111111111111111111111111112",programId:rn.toBase58(),decimals:9,symbol:"WETH",name:"Wrapped ETH",logoURI:"https://raw.githubusercontent.com/cobaltx-io/tokens/main/logo/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"cobaltx",extensions:{coingeckoId:"solana"}};import{PublicKey as wt}from"@solana/web3.js";import{PublicKey as G,SystemProgram as sn,SYSVAR_RENT_PUBKEY as Rr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as _r}from"@solana/spl-token";function bt({pubkey:n,isSigner:e=!1,isWritable:t=!0}){return{pubkey:n,isWritable:t,isSigner:e}}var bo=[bt({pubkey:_r,isWritable:!1}),bt({pubkey:sn.programId,isWritable:!1}),bt({pubkey:Rr,isWritable:!1})];function an({publicKey:n,transformSol:e}){let t=un(n.toString());if(t instanceof G)return e&&t.equals(_e)?gt:t;if(e&&t.toString()===_e.toBase58())return gt;if(typeof t=="string"){if(t===G.default.toBase58())return G.default;try{return new G(t)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function un(n){try{return new G(n)}catch{return n}}var wo=new G("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),yo=new G("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),To=new G("SysvarRent111111111111111111111111111111111"),xo=new G("SysvarC1ock11111111111111111111111111111111"),Mr=new G("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Ao=new G("Sysvar1nstructions1111111111111111111111111"),Po=sn.programId,ko=new G("a2Gt18uJC8puJT9JRYQLU6rPi6okxQb4WqCjwtYshZB"),Bo=new G("bXSKiFqYrALF9gJy1KqHm8tv4QXk8nCgbLN8WRsGEbh"),gt=new G("So11111111111111111111111111111111111111112"),_e=G.default,Io=new G("71kRXzJMvSeArtXYNEWa8KAjpRJosdMQ7Dpgy5Jt5zfd"),No=new G("ERFzpDteGNo8LTDKW1WwVGrkRMmA2y9WZHXNHxMA6BSV");var yt=class{constructor({mint:e,decimals:t,symbol:r,name:i,skipMint:o=!1,isToken2022:s=!1}){if(e===_e.toBase58()||e instanceof wt&&_e.equals(e)){this.decimals=be.decimals,this.symbol=be.symbol,this.name=be.name,this.mint=new wt(be.address),this.isToken2022=!1;return}this.decimals=t,this.symbol=r||e.toString().substring(0,6),this.name=i||e.toString().substring(0,6),this.mint=o?wt.default:an({publicKey:e}),this.isToken2022=s}equals(e){return this===e?!0:this.mint.equals(e.mint)}},we=yt;we.WSOL=new yt({...be,mint:be.address});var Tt=class{constructor({decimals:e,symbol:t="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=r}equals(e){return this===e}},Je=Tt;Je.SOL=new Tt(on);import Fr from"bn.js";var Ko=new E(new Fr(100));var Wo=Y("CobaltX_price");import{PublicKey as us}from"@solana/web3.js";import ms from"bn.js";var Or=new me(0),Cs=new me(1),Ss=new me(2),Ls=new me(3),Es=new me(5),Lr=new me(10),Rs=new me(100),_s=new me(1e3),Ms=new me(1e4);function pt(n,e=1,t=[]){let r=[...n];if(e<=0)return t;for(;r.length;)t.push(r.splice(0,e));return t}import{PublicKey as oa}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as aa}from"@solana/spl-token";import{ComputeBudgetProgram as Us,Keypair as zs,PublicKey as Dr,Transaction as Zs,TransactionMessage as Qs,VersionedTransaction as Ys}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ta}from"@solana/spl-token";var na=Y("CobaltX_txUtil");function kt(n,e){let[t,r]=Dr.findProgramAddressSync(n,e);return{publicKey:t,nonce:r}}import{PublicKey as T}from"@solana/web3.js";var la=new T("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),da=new T("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),fa=new T("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),pa=new T("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),ga=new T("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),ha=new T("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),ba=new T("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),wa=new T("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),ya=new T("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Ta=new T("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),xa=new T("2TnjBuwqyBB9to5jURagDT7jLmBPefGRiKL2yh1zPZ4V"),Aa=new T("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),Pa=new T("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),ka=new T("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Ba=new T("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Ia=new T("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Na=new T("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),Ca=new T("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),Sa=new T("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),La=new T("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),Ea=new T("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Ra=new T("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),vr=new T("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),Kr=new T("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),qr=new T("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),_a=new T("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),Gr=new T("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),Ma=new T("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),Vr=new T("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix");var Fa={SERUM_MARKET:T.default,OPENBOOK_MARKET:new T("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:T.default,FarmV3:new T("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new T("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new T("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new T("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new T("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new T("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),CLMM_LOCK_PROGRAM_ID:new T("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),CLMM_LOCK_AUTH_ID:new T("8qmHNvu2Kr2C7U8mJL4Vz1vTDxMhVuXKREwU7TNoaVEo"),Router:new T("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:vr,CREATE_CPMM_POOL_AUTH:Kr,CREATE_CPMM_POOL_FEE_ACC:qr,FEE_DESTINATION_ID:new T("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),LOCK_CPMM_PROGRAM:Gr,LCOK_CPMM_AUTH:Vr};import{PublicKey as Ur,AddressLookupTableAccount as cn}from"@solana/web3.js";var Xr={AiAibtFJts8e4W1FjWYRH34aBJkJqghdmXiJozK7MvTM:new cn({key:new Ur("AiAibtFJts8e4W1FjWYRH34aBJkJqghdmXiJozK7MvTM"),state:cn.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 Ja,sendAndConfirmTransaction as $a,Transaction as tu,TransactionMessage as ru,VersionedTransaction as iu}from"@solana/web3.js";import su from"axios";function mn(n){let e=new ArrayBuffer(4);return new DataView(e).setInt32(0,n,!1),new Uint8Array(e)}function Bt(n,e){let t=0;for(let r=n-1;r>=0&&!e.testn(r);r--)t++;return t}function It(n,e){let t=0;for(let r=0;r<n&&!e.testn(r);r++)t++;return t}function Me(n,e){for(let t=0;t<n;t++)if(e.testn(t))return!1;return!0}function ln(n,e){return Me(n,e)?null:Bt(n,e)}function dn(n,e){return Me(n,e)?null:It(n,e)}var Mu=Buffer.from("amm_config","utf8"),Fu=Buffer.from("pool","utf8"),Ou=Buffer.from("pool_vault","utf8"),Du=Buffer.from("pool_reward_vault","utf8"),vu=Buffer.from("position","utf8"),Wr=Buffer.from("tick_array","utf8"),Ku=Buffer.from("operation","utf8"),qu=Buffer.from("pool_tick_array_bitmap_extension","utf8"),Gu=Buffer.from("observation","utf8");function le(n,e,t){return kt([Wr,e.toBuffer(),mn(t)],n)}var Vu=Buffer.from("locked_position","utf8");import{TOKEN_2022_PROGRAM_ID as bm}from"@solana/spl-token";import{PublicKey as xm}from"@solana/web3.js";import Pm from"bn.js";import{PublicKey as ei}from"@solana/web3.js";import hn,{isBN as bn}from"bn.js";import{bits as Wu,BitStructure as zu,blob as zr,Blob as Hu,cstr as Zu,f32 as ju,f32be as Qu,f64 as Yu,f64be as Ju,greedy as $u,Layout as Hr,ns64 as ec,ns64be as tc,nu64 as nc,nu64be as rc,offset as ic,s16 as oc,s16be as sc,s24 as ac,s24be as uc,s32 as Zr,s32be as cc,s40 as mc,s40be as lc,s48 as dc,s48be as fc,s8 as pc,seq as jr,struct as gc,Structure as Qr,u16 as Yr,u16be as hc,u24 as bc,u24be as wc,u32 as yc,u32be as Tc,u40 as xc,u40be as Ac,u48 as Pc,u48be as kc,u8 as Jr,UInt as $r,union as Bc,Union as Ic,unionLayoutDiscriminator as Nc,utf8 as Cc}from"@solana/buffer-layout";var Nt=Hr,fn=Qr;var Ct=$r;var pn=Jr,Fe=Yr;var he=Zr;var gn=jr;var j=zr;var ke=class extends Nt{constructor(t,r,i){super(t,i);this.blob=j(t),this.signed=r}decode(t,r=0){let i=new hn(this.blob.decode(t,r),10,"le");return this.signed?i.fromTwos(this.span*8).clone():i}encode(t,r,i=0){return typeof t=="number"&&(t=new hn(t)),this.signed&&(t=t.toTwos(this.span*8)),this.blob.encode(t.toArrayLike(Buffer,"le",this.span),r,i)}};function Z(n){return new Ct(1,n)}function Be(n){return new Ct(4,n)}function P(n){return new ke(8,!1,n)}function _(n){return new ke(16,!1,n)}function wn(n){return new ke(8,!0,n)}function yn(n){return new ke(16,!0,n)}var $e=class extends Nt{constructor(t,r,i,o){super(t.span,o);this.layout=t,this.decoder=r,this.encoder=i}decode(t,r){return this.decoder(this.layout.decode(t,r))}encode(t,r,i){return this.layout.encode(this.encoder(t),r,i)}getSpan(t,r){return this.layout.getSpan(t,r)}};function k(n){return new $e(j(32),e=>new ei(e),e=>e.toBuffer(),n)}function Tn(n){return new $e(pn(),ti,ni,n)}function ti(n){if(n===0)return!1;if(n===1)return!0;throw new Error("Invalid bool: "+n)}function ni(n){return n?1:0}var St=class extends fn{decode(e,t){return super.decode(e,t)}};function z(n,e,t){return new St(n,e,t)}function R(n,e,t){let r,i=typeof e=="number"?e:bn(e)?e.toNumber():new Proxy(e,{get(o,s){if(!r){let a=Reflect.get(o,"count");r=bn(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 gn(n,i,t)}var Xc=z([j(8),Z("bump"),Fe("index"),k(""),Be("protocolFeeRate"),Be("tradeFeeRate"),Fe("tickSpacing"),R(P(),8,"")]),ri=z([Be("blockTimestamp"),wn("tickCumulative"),R(P(),4)]),Wc=z([j(8),Tn("initialized"),P("recentEpoch"),Fe("observationIndex"),k("poolId"),R(ri,100,"observations"),R(P(),4)]),ii=z([Z("rewardState"),P("openTime"),P("endTime"),P("lastUpdateTime"),_("emissionsPerSecondX64"),P("rewardTotalEmissioned"),P("rewardClaimed"),k("tokenMint"),k("tokenVault"),k("creator"),_("rewardGrowthGlobalX64")]),oi=z([j(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"),he("tickCurrent"),Be(),_("feeGrowthGlobalX64A"),_("feeGrowthGlobalX64B"),P("protocolFeesTokenA"),P("protocolFeesTokenB"),_("swapInAmountTokenA"),_("swapOutAmountTokenB"),_("swapInAmountTokenB"),_("swapOutAmountTokenA"),Z("status"),R(Z(),7,""),R(ii,3,"rewardInfos"),R(P(),16,"tickArrayBitmap"),P("totalFeesTokenA"),P("totalFeesClaimedTokenA"),P("totalFeesTokenB"),P("totalFeesClaimedTokenB"),P("fundFeesTokenA"),P("fundFeesTokenB"),P("startTime"),R(P(),15*4-3,"padding")]),si=z([_("growthInsideLastX64"),P("rewardAmountOwed")]),ai=z([j(8),Z("bump"),k("nftMint"),k("poolId"),he("tickLower"),he("tickUpper"),_("liquidity"),_("feeGrowthInsideLastX64A"),_("feeGrowthInsideLastX64B"),P("tokenFeesOwedA"),P("tokenFeesOwedB"),R(si,3,"rewardInfos"),R(P(),8,"")]),zc=z([j(8),Z("bump"),k("poolId"),he("tickLowerIndex"),he("tickUpperIndex"),_("liquidity"),_("feeGrowthInsideLastX64A"),_("feeGrowthInsideLastX64B"),P("tokenFeesOwedA"),P("tokenFeesOwedB"),R(_(),3,"rewardGrowthInside"),R(P(),8,"")]),ui=z([he("tick"),yn("liquidityNet"),_("liquidityGross"),_("feeGrowthOutsideX64A"),_("feeGrowthOutsideX64B"),R(_(),3,"rewardGrowthsOutsideX64"),R(Be(),13,"")]),Et=z([j(8),k("poolId"),he("startTickIndex"),R(ui,D,"ticks"),Z("initializedTickCount"),R(Z(),115,"")]),Hc=z([j(329),R(k(),100