@cobaltx/sdk-v2
Version:
An SDK for building applications on top of CobaltX.
1 lines • 79.2 kB
JavaScript
import re from"bn.js";var me=9e15,ue=1e9,it="0123456789abcdef",Ie="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",ve="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",ot={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-me,maxE:me,crypto:!1},Ot,te,L=!0,Fe="[DecimalError] ",se=Fe+"Invalid argument: ",Ft=Fe+"Precision limit exceeded",Vt=Fe+"crypto unavailable",qt="[object Decimal]",H=Math.floor,W=Math.pow,Nn=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Mn=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,En=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Wt=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Y=1e7,B=7,Rn=9007199254740991,Dn=Ie.length-1,st=ve.length-1,g={toStringTag:qt};g.absoluteValue=g.abs=function(){var t=new this.constructor(this);return t.s<0&&(t.s=1),P(t)};g.ceil=function(){return P(new this.constructor(this),this.e+1,2)};g.clampedTo=g.clamp=function(t,e){var n,r=this,i=r.constructor;if(t=new i(t),e=new i(e),!t.s||!e.s)return new i(NaN);if(t.gt(e))throw Error(se+e);return n=r.cmp(t),n<0?t:r.cmp(e)>0?e:new i(r)};g.comparedTo=g.cmp=function(t){var e,n,r,i,o=this,s=o.d,u=(t=new o.constructor(t)).d,c=o.s,a=t.s;if(!s||!u)return!c||!a?NaN:c!==a?c:s===u?0:!s^c<0?1:-1;if(!s[0]||!u[0])return s[0]?c:u[0]?-a:0;if(c!==a)return c;if(o.e!==t.e)return o.e>t.e^c<0?1:-1;for(r=s.length,i=u.length,e=0,n=r<i?r:i;e<n;++e)if(s[e]!==u[e])return s[e]>u[e]^c<0?1:-1;return r===i?0:r>i^c<0?1:-1};g.cosine=g.cos=function(){var t,e,n=this,r=n.constructor;return n.d?n.d[0]?(t=r.precision,e=r.rounding,r.precision=t+Math.max(n.e,n.sd())+B,r.rounding=1,n=_n(r,Qt(r,n)),r.precision=t,r.rounding=e,P(te==2||te==3?n.neg():n,t,e,!0)):new r(1):new r(NaN)};g.cubeRoot=g.cbrt=function(){var t,e,n,r,i,o,s,u,c,a,l=this,f=l.constructor;if(!l.isFinite()||l.isZero())return new f(l);for(L=!1,o=l.s*W(l.s*l,1/3),!o||Math.abs(o)==1/0?(n=U(l.d),t=l.e,(o=(t-n.length+1)%3)&&(n+=o==1||o==-2?"0":"00"),o=W(n,1/3),t=H((t+1)/3)-(t%3==(t<0?-1:2)),o==1/0?n="5e"+t:(n=o.toExponential(),n=n.slice(0,n.indexOf("e")+1)+t),r=new f(n),r.s=l.s):r=new f(o.toString()),s=(t=f.precision)+3;;)if(u=r,c=u.times(u).times(u),a=c.plus(l),r=_(a.plus(l).times(u),a.plus(c),s+2,1),U(u.d).slice(0,s)===(n=U(r.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!i&&n=="4999"){if(!i&&(P(u,t+1,0),u.times(u).times(u).eq(l))){r=u;break}s+=4,i=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(P(r,t+1,1),e=!r.times(r).times(r).eq(l));break}return L=!0,P(r,t,f.rounding,e)};g.decimalPlaces=g.dp=function(){var t,e=this.d,n=NaN;if(e){if(t=e.length-1,n=(t-H(this.e/B))*B,t=e[t],t)for(;t%10==0;t/=10)n--;n<0&&(n=0)}return n};g.dividedBy=g.div=function(t){return _(this,new this.constructor(t))};g.dividedToIntegerBy=g.divToInt=function(t){var e=this,n=e.constructor;return P(_(e,new n(t),0,1,1),n.precision,n.rounding)};g.equals=g.eq=function(t){return this.cmp(t)===0};g.floor=function(){return P(new this.constructor(this),this.e+1,3)};g.greaterThan=g.gt=function(t){return this.cmp(t)>0};g.greaterThanOrEqualTo=g.gte=function(t){var e=this.cmp(t);return e==1||e===0};g.hyperbolicCosine=g.cosh=function(){var t,e,n,r,i,o=this,s=o.constructor,u=new s(1);if(!o.isFinite())return new s(o.s?1/0:NaN);if(o.isZero())return u;n=s.precision,r=s.rounding,s.precision=n+Math.max(o.e,o.sd())+4,s.rounding=1,i=o.d.length,i<32?(t=Math.ceil(i/3),e=(1/qe(4,t)).toString()):(t=16,e="2.3283064365386962890625e-10"),o=ge(s,1,o.times(e),new s(1),!0);for(var c,a=t,l=new s(8);a--;)c=o.times(o),o=u.minus(c.times(l.minus(c.times(l))));return P(o,s.precision=n,s.rounding=r,!0)};g.hyperbolicSine=g.sinh=function(){var t,e,n,r,i=this,o=i.constructor;if(!i.isFinite()||i.isZero())return new o(i);if(e=o.precision,n=o.rounding,o.precision=e+Math.max(i.e,i.sd())+4,o.rounding=1,r=i.d.length,r<3)i=ge(o,2,i,i,!0);else{t=1.4*Math.sqrt(r),t=t>16?16:t|0,i=i.times(1/qe(5,t)),i=ge(o,2,i,i,!0);for(var s,u=new o(5),c=new o(16),a=new o(20);t--;)s=i.times(i),i=i.times(u.plus(s.times(c.times(s).plus(a))))}return o.precision=e,o.rounding=n,P(i,e,n,!0)};g.hyperbolicTangent=g.tanh=function(){var t,e,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(t=r.precision,e=r.rounding,r.precision=t+7,r.rounding=1,_(n.sinh(),n.cosh(),r.precision=t,r.rounding=e)):new r(n.s)};g.inverseCosine=g.acos=function(){var t,e=this,n=e.constructor,r=e.abs().cmp(1),i=n.precision,o=n.rounding;return r!==-1?r===0?e.isNeg()?X(n,i,o):new n(0):new n(NaN):e.isZero()?X(n,i+4,o).times(.5):(n.precision=i+6,n.rounding=1,e=e.asin(),t=X(n,i+4,o).times(.5),n.precision=i,n.rounding=o,t.minus(e))};g.inverseHyperbolicCosine=g.acosh=function(){var t,e,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(t=r.precision,e=r.rounding,r.precision=t+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,L=!1,n=n.times(n).minus(1).sqrt().plus(n),L=!0,r.precision=t,r.rounding=e,n.ln()):new r(n)};g.inverseHyperbolicSine=g.asinh=function(){var t,e,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(t=r.precision,e=r.rounding,r.precision=t+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,L=!1,n=n.times(n).plus(1).sqrt().plus(n),L=!0,r.precision=t,r.rounding=e,n.ln())};g.inverseHyperbolicTangent=g.atanh=function(){var t,e,n,r,i=this,o=i.constructor;return i.isFinite()?i.e>=0?new o(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(t=o.precision,e=o.rounding,r=i.sd(),Math.max(r,t)<2*-i.e-1?P(new o(i),t,e,!0):(o.precision=n=r-i.e,i=_(i.plus(1),new o(1).minus(i),n+t,1),o.precision=t+4,o.rounding=1,i=i.ln(),o.precision=t,o.rounding=e,i.times(.5))):new o(NaN)};g.inverseSine=g.asin=function(){var t,e,n,r,i=this,o=i.constructor;return i.isZero()?new o(i):(e=i.abs().cmp(1),n=o.precision,r=o.rounding,e!==-1?e===0?(t=X(o,n+4,r).times(.5),t.s=i.s,t):new o(NaN):(o.precision=n+6,o.rounding=1,i=i.div(new o(1).minus(i.times(i)).sqrt().plus(1)).atan(),o.precision=n,o.rounding=r,i.times(2)))};g.inverseTangent=g.atan=function(){var t,e,n,r,i,o,s,u,c,a=this,l=a.constructor,f=l.precision,p=l.rounding;if(a.isFinite()){if(a.isZero())return new l(a);if(a.abs().eq(1)&&f+4<=st)return s=X(l,f+4,p).times(.25),s.s=a.s,s}else{if(!a.s)return new l(NaN);if(f+4<=st)return s=X(l,f+4,p).times(.5),s.s=a.s,s}for(l.precision=u=f+10,l.rounding=1,n=Math.min(28,u/B+2|0),t=n;t;--t)a=a.div(a.times(a).plus(1).sqrt().plus(1));for(L=!1,e=Math.ceil(u/B),r=1,c=a.times(a),s=new l(a),i=a;t!==-1;)if(i=i.times(c),o=s.minus(i.div(r+=2)),i=i.times(c),s=o.plus(i.div(r+=2)),s.d[e]!==void 0)for(t=e;s.d[t]===o.d[t]&&t--;);return n&&(s=s.times(2<<n-1)),L=!0,P(s,l.precision=f,l.rounding=p,!0)};g.isFinite=function(){return!!this.d};g.isInteger=g.isInt=function(){return!!this.d&&H(this.e/B)>this.d.length-2};g.isNaN=function(){return!this.s};g.isNegative=g.isNeg=function(){return this.s<0};g.isPositive=g.isPos=function(){return this.s>0};g.isZero=function(){return!!this.d&&this.d[0]===0};g.lessThan=g.lt=function(t){return this.cmp(t)<0};g.lessThanOrEqualTo=g.lte=function(t){return this.cmp(t)<1};g.logarithm=g.log=function(t){var e,n,r,i,o,s,u,c,a=this,l=a.constructor,f=l.precision,p=l.rounding,d=5;if(t==null)t=new l(10),e=!0;else{if(t=new l(t),n=t.d,t.s<0||!n||!n[0]||t.eq(1))return new l(NaN);e=t.eq(10)}if(n=a.d,a.s<0||!n||!n[0]||a.eq(1))return new l(n&&!n[0]?-1/0:a.s!=1?NaN:n?0:1/0);if(e)if(n.length>1)o=!0;else{for(i=n[0];i%10===0;)i/=10;o=i!==1}if(L=!1,u=f+d,s=oe(a,u),r=e?Oe(l,u+10):oe(t,u),c=_(s,r,u,1),Te(c.d,i=f,p))do if(u+=10,s=oe(a,u),r=e?Oe(l,u+10):oe(t,u),c=_(s,r,u,1),!o){+U(c.d).slice(i+1,i+15)+1==1e14&&(c=P(c,f+1,0));break}while(Te(c.d,i+=10,p));return L=!0,P(c,f,p)};g.minus=g.sub=function(t){var e,n,r,i,o,s,u,c,a,l,f,p,d=this,m=d.constructor;if(t=new m(t),!d.d||!t.d)return!d.s||!t.s?t=new m(NaN):d.d?t.s=-t.s:t=new m(t.d||d.s!==t.s?d:NaN),t;if(d.s!=t.s)return t.s=-t.s,d.plus(t);if(a=d.d,p=t.d,u=m.precision,c=m.rounding,!a[0]||!p[0]){if(p[0])t.s=-t.s;else if(a[0])t=new m(d);else return new m(c===3?-0:0);return L?P(t,u,c):t}if(n=H(t.e/B),l=H(d.e/B),a=a.slice(),o=l-n,o){for(f=o<0,f?(e=a,o=-o,s=p.length):(e=p,n=l,s=a.length),r=Math.max(Math.ceil(u/B),s)+2,o>r&&(o=r,e.length=1),e.reverse(),r=o;r--;)e.push(0);e.reverse()}else{for(r=a.length,s=p.length,f=r<s,f&&(s=r),r=0;r<s;r++)if(a[r]!=p[r]){f=a[r]<p[r];break}o=0}for(f&&(e=a,a=p,p=e,t.s=-t.s),s=a.length,r=p.length-s;r>0;--r)a[s++]=0;for(r=p.length;r>o;){if(a[--r]<p[r]){for(i=r;i&&a[--i]===0;)a[i]=Y-1;--a[i],a[r]+=Y}a[r]-=p[r]}for(;a[--s]===0;)a.pop();for(;a[0]===0;a.shift())--n;return a[0]?(t.d=a,t.e=Ve(a,n),L?P(t,u,c):t):new m(c===3?-0:0)};g.modulo=g.mod=function(t){var e,n=this,r=n.constructor;return t=new r(t),!n.d||!t.s||t.d&&!t.d[0]?new r(NaN):!t.d||n.d&&!n.d[0]?P(new r(n),r.precision,r.rounding):(L=!1,r.modulo==9?(e=_(n,t.abs(),0,3,1),e.s*=t.s):e=_(n,t,0,r.modulo,1),e=e.times(t),L=!0,n.minus(e))};g.naturalExponential=g.exp=function(){return ut(this)};g.naturalLogarithm=g.ln=function(){return oe(this)};g.negated=g.neg=function(){var t=new this.constructor(this);return t.s=-t.s,P(t)};g.plus=g.add=function(t){var e,n,r,i,o,s,u,c,a,l,f=this,p=f.constructor;if(t=new p(t),!f.d||!t.d)return!f.s||!t.s?t=new p(NaN):f.d||(t=new p(t.d||f.s===t.s?f:NaN)),t;if(f.s!=t.s)return t.s=-t.s,f.minus(t);if(a=f.d,l=t.d,u=p.precision,c=p.rounding,!a[0]||!l[0])return l[0]||(t=new p(f)),L?P(t,u,c):t;if(o=H(f.e/B),r=H(t.e/B),a=a.slice(),i=o-r,i){for(i<0?(n=a,i=-i,s=l.length):(n=l,r=o,s=a.length),o=Math.ceil(u/B),s=o>s?o+1:s+1,i>s&&(i=s,n.length=1),n.reverse();i--;)n.push(0);n.reverse()}for(s=a.length,i=l.length,s-i<0&&(i=s,n=l,l=a,a=n),e=0;i;)e=(a[--i]=a[i]+l[i]+e)/Y|0,a[i]%=Y;for(e&&(a.unshift(e),++r),s=a.length;a[--s]==0;)a.pop();return t.d=a,t.e=Ve(a,r),L?P(t,u,c):t};g.precision=g.sd=function(t){var e,n=this;if(t!==void 0&&t!==!!t&&t!==1&&t!==0)throw Error(se+t);return n.d?(e=Ut(n.d),t&&n.e+1>e&&(e=n.e+1)):e=NaN,e};g.round=function(){var t=this,e=t.constructor;return P(new e(t),t.e+1,e.rounding)};g.sine=g.sin=function(){var t,e,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(t=r.precision,e=r.rounding,r.precision=t+Math.max(n.e,n.sd())+B,r.rounding=1,n=In(r,Qt(r,n)),r.precision=t,r.rounding=e,P(te>2?n.neg():n,t,e,!0)):new r(NaN)};g.squareRoot=g.sqrt=function(){var t,e,n,r,i,o,s=this,u=s.d,c=s.e,a=s.s,l=s.constructor;if(a!==1||!u||!u[0])return new l(!a||a<0&&(!u||u[0])?NaN:u?s:1/0);for(L=!1,a=Math.sqrt(+s),a==0||a==1/0?(e=U(u),(e.length+c)%2==0&&(e+="0"),a=Math.sqrt(e),c=H((c+1)/2)-(c<0||c%2),a==1/0?e="5e"+c:(e=a.toExponential(),e=e.slice(0,e.indexOf("e")+1)+c),r=new l(e)):r=new l(a.toString()),n=(c=l.precision)+3;;)if(o=r,r=o.plus(_(s,o,n+2,1)).times(.5),U(o.d).slice(0,n)===(e=U(r.d)).slice(0,n))if(e=e.slice(n-3,n+1),e=="9999"||!i&&e=="4999"){if(!i&&(P(o,c+1,0),o.times(o).eq(s))){r=o;break}n+=4,i=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(P(r,c+1,1),t=!r.times(r).eq(s));break}return L=!0,P(r,c,l.rounding,t)};g.tangent=g.tan=function(){var t,e,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(t=r.precision,e=r.rounding,r.precision=t+10,r.rounding=1,n=n.sin(),n.s=1,n=_(n,new r(1).minus(n.times(n)).sqrt(),t+10,0),r.precision=t,r.rounding=e,P(te==2||te==4?n.neg():n,t,e,!0)):new r(NaN)};g.times=g.mul=function(t){var e,n,r,i,o,s,u,c,a,l=this,f=l.constructor,p=l.d,d=(t=new f(t)).d;if(t.s*=l.s,!p||!p[0]||!d||!d[0])return new f(!t.s||p&&!p[0]&&!d||d&&!d[0]&&!p?NaN:!p||!d?t.s/0:t.s*0);for(n=H(l.e/B)+H(t.e/B),c=p.length,a=d.length,c<a&&(o=p,p=d,d=o,s=c,c=a,a=s),o=[],s=c+a,r=s;r--;)o.push(0);for(r=a;--r>=0;){for(e=0,i=c+r;i>r;)u=o[i]+d[r]*p[i-r-1]+e,o[i--]=u%Y|0,e=u/Y|0;o[i]=(o[i]+e)%Y|0}for(;!o[--s];)o.pop();return e?++n:o.shift(),t.d=o,t.e=Ve(o,n),L?P(t,f.precision,f.rounding):t};g.toBinary=function(t,e){return ct(this,2,t,e)};g.toDecimalPlaces=g.toDP=function(t,e){var n=this,r=n.constructor;return n=new r(n),t===void 0?n:(Z(t,0,ue),e===void 0?e=r.rounding:Z(e,0,8),P(n,t+n.e+1,e))};g.toExponential=function(t,e){var n,r=this,i=r.constructor;return t===void 0?n=ee(r,!0):(Z(t,0,ue),e===void 0?e=i.rounding:Z(e,0,8),r=P(new i(r),t+1,e),n=ee(r,!0,t+1)),r.isNeg()&&!r.isZero()?"-"+n:n};g.toFixed=function(t,e){var n,r,i=this,o=i.constructor;return t===void 0?n=ee(i):(Z(t,0,ue),e===void 0?e=o.rounding:Z(e,0,8),r=P(new o(i),t+i.e+1,e),n=ee(r,!1,t+r.e+1)),i.isNeg()&&!i.isZero()?"-"+n:n};g.toFraction=function(t){var e,n,r,i,o,s,u,c,a,l,f,p,d=this,m=d.d,h=d.constructor;if(!m)return new h(d);if(a=n=new h(1),r=c=new h(0),e=new h(r),o=e.e=Ut(m)-d.e-1,s=o%B,e.d[0]=W(10,s<0?B+s:s),t==null)t=o>0?e:a;else{if(u=new h(t),!u.isInt()||u.lt(a))throw Error(se+u);t=u.gt(e)?o>0?e:a:u}for(L=!1,u=new h(U(m)),l=h.precision,h.precision=o=m.length*B*2;f=_(u,e,0,1,1),i=n.plus(f.times(r)),i.cmp(t)!=1;)n=r,r=i,i=a,a=c.plus(f.times(i)),c=i,i=e,e=u.minus(f.times(i)),u=i;return i=_(t.minus(n),r,0,1,1),c=c.plus(i.times(a)),n=n.plus(i.times(r)),c.s=a.s=d.s,p=_(a,r,o,1).minus(d).abs().cmp(_(c,n,o,1).minus(d).abs())<1?[a,r]:[c,n],h.precision=l,L=!0,p};g.toHexadecimal=g.toHex=function(t,e){return ct(this,16,t,e)};g.toNearest=function(t,e){var n=this,r=n.constructor;if(n=new r(n),t==null){if(!n.d)return n;t=new r(1),e=r.rounding}else{if(t=new r(t),e===void 0?e=r.rounding:Z(e,0,8),!n.d)return t.s?n:t;if(!t.d)return t.s&&(t.s=n.s),t}return t.d[0]?(L=!1,n=_(n,t,0,e,1).times(t),L=!0,P(n)):(t.s=n.s,n=t),n};g.toNumber=function(){return+this};g.toOctal=function(t,e){return ct(this,8,t,e)};g.toPower=g.pow=function(t){var e,n,r,i,o,s,u=this,c=u.constructor,a=+(t=new c(t));if(!u.d||!t.d||!u.d[0]||!t.d[0])return new c(W(+u,a));if(u=new c(u),u.eq(1))return u;if(r=c.precision,o=c.rounding,t.eq(1))return P(u,r,o);if(e=H(t.e/B),e>=t.d.length-1&&(n=a<0?-a:a)<=Rn)return i=Gt(c,u,n,r),t.s<0?new c(1).div(i):P(i,r,o);if(s=u.s,s<0){if(e<t.d.length-1)return new c(NaN);if((t.d[e]&1)==0&&(s=1),u.e==0&&u.d[0]==1&&u.d.length==1)return u.s=s,u}return n=W(+u,a),e=n==0||!isFinite(n)?H(a*(Math.log("0."+U(u.d))/Math.LN10+u.e+1)):new c(n+"").e,e>c.maxE+1||e<c.minE-1?new c(e>0?s/0:0):(L=!1,c.rounding=u.s=1,n=Math.min(12,(e+"").length),i=ut(t.times(oe(u,r+n)),r),i.d&&(i=P(i,r+5,1),Te(i.d,r,o)&&(e=r+10,i=P(ut(t.times(oe(u,e+n)),e),e+5,1),+U(i.d).slice(r+1,r+15)+1==1e14&&(i=P(i,r+1,0)))),i.s=s,L=!0,c.rounding=o,P(i,r,o))};g.toPrecision=function(t,e){var n,r=this,i=r.constructor;return t===void 0?n=ee(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(Z(t,1,ue),e===void 0?e=i.rounding:Z(e,0,8),r=P(new i(r),t,e),n=ee(r,t<=r.e||r.e<=i.toExpNeg,t)),r.isNeg()&&!r.isZero()?"-"+n:n};g.toSignificantDigits=g.toSD=function(t,e){var n=this,r=n.constructor;return t===void 0?(t=r.precision,e=r.rounding):(Z(t,1,ue),e===void 0?e=r.rounding:Z(e,0,8)),P(new r(n),t,e)};g.toString=function(){var t=this,e=t.constructor,n=ee(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()&&!t.isZero()?"-"+n:n};g.truncated=g.trunc=function(){return P(new this.constructor(this),this.e+1,1)};g.valueOf=g.toJSON=function(){var t=this,e=t.constructor,n=ee(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()?"-"+n:n};function U(t){var e,n,r,i=t.length-1,o="",s=t[0];if(i>0){for(o+=s,e=1;e<i;e++)r=t[e]+"",n=B-r.length,n&&(o+=ie(n)),o+=r;s=t[e],r=s+"",n=B-r.length,n&&(o+=ie(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function Z(t,e,n){if(t!==~~t||t<e||t>n)throw Error(se+t)}function Te(t,e,n,r){var i,o,s,u;for(o=t[0];o>=10;o/=10)--e;return--e<0?(e+=B,i=0):(i=Math.ceil((e+1)/B),e%=B),o=W(10,B-e),u=t[i]%o|0,r==null?e<3?(e==0?u=u/100|0:e==1&&(u=u/10|0),s=n<4&&u==99999||n>3&&u==49999||u==5e4||u==0):s=(n<4&&u+1==o||n>3&&u+1==o/2)&&(t[i+1]/o/100|0)==W(10,e-2)-1||(u==o/2||u==0)&&(t[i+1]/o/100|0)==0:e<4?(e==0?u=u/1e3|0:e==1?u=u/100|0:e==2&&(u=u/10|0),s=(r||n<4)&&u==9999||!r&&n>3&&u==4999):s=((r||n<4)&&u+1==o||!r&&n>3&&u+1==o/2)&&(t[i+1]/o/1e3|0)==W(10,e-3)-1,s}function Ke(t,e,n){for(var r,i=[0],o,s=0,u=t.length;s<u;){for(o=i.length;o--;)i[o]*=e;for(i[0]+=it.indexOf(t.charAt(s++)),r=0;r<i.length;r++)i[r]>n-1&&(i[r+1]===void 0&&(i[r+1]=0),i[r+1]+=i[r]/n|0,i[r]%=n)}return i.reverse()}function _n(t,e){var n,r,i;if(e.isZero())return e;r=e.d.length,r<32?(n=Math.ceil(r/3),i=(1/qe(4,n)).toString()):(n=16,i="2.3283064365386962890625e-10"),t.precision+=n,e=ge(t,1,e.times(i),new t(1));for(var o=n;o--;){var s=e.times(e);e=s.times(s).minus(s).times(8).plus(1)}return t.precision-=n,e}var _=function(){function t(r,i,o){var s,u=0,c=r.length;for(r=r.slice();c--;)s=r[c]*i+u,r[c]=s%o|0,u=s/o|0;return u&&r.unshift(u),r}function e(r,i,o,s){var u,c;if(o!=s)c=o>s?1:-1;else for(u=c=0;u<o;u++)if(r[u]!=i[u]){c=r[u]>i[u]?1:-1;break}return c}function n(r,i,o,s){for(var u=0;o--;)r[o]-=u,u=r[o]<i[o]?1:0,r[o]=u*s+r[o]-i[o];for(;!r[0]&&r.length>1;)r.shift()}return function(r,i,o,s,u,c){var a,l,f,p,d,m,h,y,T,A,b,w,x,k,S,K,V,F,E,O,v=r.constructor,j=r.s==i.s?1:-1,D=r.d,R=i.d;if(!D||!D[0]||!R||!R[0])return new v(!r.s||!i.s||(D?R&&D[0]==R[0]:!R)?NaN:D&&D[0]==0||!R?j*0:j/0);for(c?(d=1,l=r.e-i.e):(c=Y,d=B,l=H(r.e/d)-H(i.e/d)),E=R.length,V=D.length,T=new v(j),A=T.d=[],f=0;R[f]==(D[f]||0);f++);if(R[f]>(D[f]||0)&&l--,o==null?(k=o=v.precision,s=v.rounding):u?k=o+(r.e-i.e)+1:k=o,k<0)A.push(1),m=!0;else{if(k=k/d+2|0,f=0,E==1){for(p=0,R=R[0],k++;(f<V||p)&&k--;f++)S=p*c+(D[f]||0),A[f]=S/R|0,p=S%R|0;m=p||f<V}else{for(p=c/(R[0]+1)|0,p>1&&(R=t(R,p,c),D=t(D,p,c),E=R.length,V=D.length),K=E,b=D.slice(0,E),w=b.length;w<E;)b[w++]=0;O=R.slice(),O.unshift(0),F=R[0],R[1]>=c/2&&++F;do p=0,a=e(R,b,E,w),a<0?(x=b[0],E!=w&&(x=x*c+(b[1]||0)),p=x/F|0,p>1?(p>=c&&(p=c-1),h=t(R,p,c),y=h.length,w=b.length,a=e(h,b,y,w),a==1&&(p--,n(h,E<y?O:R,y,c))):(p==0&&(a=p=1),h=R.slice()),y=h.length,y<w&&h.unshift(0),n(b,h,w,c),a==-1&&(w=b.length,a=e(R,b,E,w),a<1&&(p++,n(b,E<w?O:R,w,c))),w=b.length):a===0&&(p++,b=[0]),A[f++]=p,a&&b[0]?b[w++]=D[K]||0:(b=[D[K]],w=1);while((K++<V||b[0]!==void 0)&&k--);m=b[0]!==void 0}A[0]||A.shift()}if(d==1)T.e=l,Ot=m;else{for(f=1,p=A[0];p>=10;p/=10)f++;T.e=f+l*d-1,P(T,u?o+T.e+1:o,s,m)}return T}}();function P(t,e,n,r){var i,o,s,u,c,a,l,f,p,d=t.constructor;e:if(e!=null){if(f=t.d,!f)return t;for(i=1,u=f[0];u>=10;u/=10)i++;if(o=e-i,o<0)o+=B,s=e,l=f[p=0],c=l/W(10,i-s-1)%10|0;else if(p=Math.ceil((o+1)/B),u=f.length,p>=u)if(r){for(;u++<=p;)f.push(0);l=c=0,i=1,o%=B,s=o-B+1}else break e;else{for(l=u=f[p],i=1;u>=10;u/=10)i++;o%=B,s=o-B+i,c=s<0?0:l/W(10,i-s-1)%10|0}if(r=r||e<0||f[p+1]!==void 0||(s<0?l:l%W(10,i-s-1)),a=n<4?(c||r)&&(n==0||n==(t.s<0?3:2)):c>5||c==5&&(n==4||r||n==6&&(o>0?s>0?l/W(10,i-s):0:f[p-1])%10&1||n==(t.s<0?8:7)),e<1||!f[0])return f.length=0,a?(e-=t.e+1,f[0]=W(10,(B-e%B)%B),t.e=-e||0):f[0]=t.e=0,t;if(o==0?(f.length=p,u=1,p--):(f.length=p+1,u=W(10,B-o),f[p]=s>0?(l/W(10,i-s)%W(10,s)|0)*u:0),a)for(;;)if(p==0){for(o=1,s=f[0];s>=10;s/=10)o++;for(s=f[0]+=u,u=1;s>=10;s/=10)u++;o!=u&&(t.e++,f[0]==Y&&(f[0]=1));break}else{if(f[p]+=u,f[p]!=Y)break;f[p--]=0,u=1}for(o=f.length;f[--o]===0;)f.pop()}return L&&(t.e>d.maxE?(t.d=null,t.e=NaN):t.e<d.minE&&(t.e=0,t.d=[0])),t}function ee(t,e,n){if(!t.isFinite())return zt(t);var r,i=t.e,o=U(t.d),s=o.length;return e?(n&&(r=n-s)>0?o=o.charAt(0)+"."+o.slice(1)+ie(r):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(t.e<0?"e":"e+")+t.e):i<0?(o="0."+ie(-i-1)+o,n&&(r=n-s)>0&&(o+=ie(r))):i>=s?(o+=ie(i+1-s),n&&(r=n-i-1)>0&&(o=o+"."+ie(r))):((r=i+1)<s&&(o=o.slice(0,r)+"."+o.slice(r)),n&&(r=n-s)>0&&(i+1===s&&(o+="."),o+=ie(r))),o}function Ve(t,e){var n=t[0];for(e*=B;n>=10;n/=10)e++;return e}function Oe(t,e,n){if(e>Dn)throw L=!0,n&&(t.precision=n),Error(Ft);return P(new t(Ie),e,1,!0)}function X(t,e,n){if(e>st)throw Error(Ft);return P(new t(ve),e,n,!0)}function Ut(t){var e=t.length-1,n=e*B+1;if(e=t[e],e){for(;e%10==0;e/=10)n--;for(e=t[0];e>=10;e/=10)n++}return n}function ie(t){for(var e="";t--;)e+="0";return e}function Gt(t,e,n,r){var i,o=new t(1),s=Math.ceil(r/B+4);for(L=!1;;){if(n%2&&(o=o.times(e),It(o.d,s)&&(i=!0)),n=H(n/2),n===0){n=o.d.length-1,i&&o.d[n]===0&&++o.d[n];break}e=e.times(e),It(e.d,s)}return L=!0,o}function Kt(t){return t.d[t.d.length-1]&1}function Ht(t,e,n){for(var r,i=new t(e[0]),o=0;++o<e.length;)if(r=new t(e[o]),r.s)i[n](r)&&(i=r);else{i=r;break}return i}function ut(t,e){var n,r,i,o,s,u,c,a=0,l=0,f=0,p=t.constructor,d=p.rounding,m=p.precision;if(!t.d||!t.d[0]||t.e>17)return new p(t.d?t.d[0]?t.s<0?0:1/0:1:t.s?t.s<0?0:t:0/0);for(e==null?(L=!1,c=m):c=e,u=new p(.03125);t.e>-2;)t=t.times(u),f+=5;for(r=Math.log(W(2,f))/Math.LN10*2+5|0,c+=r,n=o=s=new p(1),p.precision=c;;){if(o=P(o.times(t),c,1),n=n.times(++l),u=s.plus(_(o,n,c,1)),U(u.d).slice(0,c)===U(s.d).slice(0,c)){for(i=f;i--;)s=P(s.times(s),c,1);if(e==null)if(a<3&&Te(s.d,c-r,d,a))p.precision=c+=10,n=o=u=new p(1),l=0,a++;else return P(s,p.precision=m,d,L=!0);else return p.precision=m,s}s=u}}function oe(t,e){var n,r,i,o,s,u,c,a,l,f,p,d=1,m=10,h=t,y=h.d,T=h.constructor,A=T.rounding,b=T.precision;if(h.s<0||!y||!y[0]||!h.e&&y[0]==1&&y.length==1)return new T(y&&!y[0]?-1/0:h.s!=1?NaN:y?0:h);if(e==null?(L=!1,l=b):l=e,T.precision=l+=m,n=U(y),r=n.charAt(0),Math.abs(o=h.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)h=h.times(t),n=U(h.d),r=n.charAt(0),d++;o=h.e,r>1?(h=new T("0."+n),o++):h=new T(r+"."+n.slice(1))}else return a=Oe(T,l+2,b).times(o+""),h=oe(new T(r+"."+n.slice(1)),l-m).plus(a),T.precision=b,e==null?P(h,b,A,L=!0):h;for(f=h,c=s=h=_(h.minus(1),h.plus(1),l,1),p=P(h.times(h),l,1),i=3;;){if(s=P(s.times(p),l,1),a=c.plus(_(s,new T(i),l,1)),U(a.d).slice(0,l)===U(c.d).slice(0,l))if(c=c.times(2),o!==0&&(c=c.plus(Oe(T,l+2,b).times(o+""))),c=_(c,new T(d),l,1),e==null)if(Te(c.d,l-m,A,u))T.precision=l+=m,a=s=h=_(f.minus(1),f.plus(1),l,1),p=P(h.times(h),l,1),i=u=1;else return P(c,T.precision=b,A,L=!0);else return T.precision=b,c;c=a,i+=2}}function zt(t){return String(t.s*t.s/0)}function at(t,e){var n,r,i;for((n=e.indexOf("."))>-1&&(e=e.replace(".","")),(r=e.search(/e/i))>0?(n<0&&(n=r),n+=+e.slice(r+1),e=e.substring(0,r)):n<0&&(n=e.length),r=0;e.charCodeAt(r)===48;r++);for(i=e.length;e.charCodeAt(i-1)===48;--i);if(e=e.slice(r,i),e){if(i-=r,t.e=n=n-r-1,t.d=[],r=(n+1)%B,n<0&&(r+=B),r<i){for(r&&t.d.push(+e.slice(0,r)),i-=B;r<i;)t.d.push(+e.slice(r,r+=B));e=e.slice(r),r=B-e.length}else r-=i;for(;r--;)e+="0";t.d.push(+e),L&&(t.e>t.constructor.maxE?(t.d=null,t.e=NaN):t.e<t.constructor.minE&&(t.e=0,t.d=[0]))}else t.e=0,t.d=[0];return t}function Kn(t,e){var n,r,i,o,s,u,c,a,l;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),Wt.test(e))return at(t,e)}else if(e==="Infinity"||e==="NaN")return+e||(t.s=NaN),t.e=NaN,t.d=null,t;if(Mn.test(e))n=16,e=e.toLowerCase();else if(Nn.test(e))n=2;else if(En.test(e))n=8;else throw Error(se+e);for(o=e.search(/p/i),o>0?(c=+e.slice(o+1),e=e.substring(2,o)):e=e.slice(2),o=e.indexOf("."),s=o>=0,r=t.constructor,s&&(e=e.replace(".",""),u=e.length,o=u-o,i=Gt(r,new r(n),o,o*2)),a=Ke(e,n,Y),l=a.length-1,o=l;a[o]===0;--o)a.pop();return o<0?new r(t.s*0):(t.e=Ve(a,l),t.d=a,L=!1,s&&(t=_(t,i,u*4)),c&&(t=t.times(Math.abs(c)<54?W(2,c):We.pow(2,c))),L=!0,t)}function In(t,e){var n,r=e.d.length;if(r<3)return e.isZero()?e:ge(t,2,e,e);n=1.4*Math.sqrt(r),n=n>16?16:n|0,e=e.times(1/qe(5,n)),e=ge(t,2,e,e);for(var i,o=new t(5),s=new t(16),u=new t(20);n--;)i=e.times(e),e=e.times(o.plus(i.times(s.times(i).minus(u))));return e}function ge(t,e,n,r,i){var o,s,u,c,a=1,l=t.precision,f=Math.ceil(l/B);for(L=!1,c=n.times(n),u=new t(r);;){if(s=_(u.times(c),new t(e++*e++),l,1),u=i?r.plus(s):r.minus(s),r=_(s.times(c),new t(e++*e++),l,1),s=u.plus(r),s.d[f]!==void 0){for(o=f;s.d[o]===u.d[o]&&o--;);if(o==-1)break}o=u,u=r,r=s,s=o,a++}return L=!0,s.d.length=f+1,s}function qe(t,e){for(var n=t;--e;)n*=t;return n}function Qt(t,e){var n,r=e.s<0,i=X(t,t.precision,1),o=i.times(.5);if(e=e.abs(),e.lte(o))return te=r?4:1,e;if(n=e.divToInt(i),n.isZero())te=r?3:2;else{if(e=e.minus(n.times(i)),e.lte(o))return te=Kt(n)?r?2:3:r?4:1,e;te=Kt(n)?r?1:4:r?3:2}return e.minus(i).abs()}function ct(t,e,n,r){var i,o,s,u,c,a,l,f,p,d=t.constructor,m=n!==void 0;if(m?(Z(n,1,ue),r===void 0?r=d.rounding:Z(r,0,8)):(n=d.precision,r=d.rounding),!t.isFinite())l=zt(t);else{for(l=ee(t),s=l.indexOf("."),m?(i=2,e==16?n=n*4-3:e==8&&(n=n*3-2)):i=e,s>=0&&(l=l.replace(".",""),p=new d(1),p.e=l.length-s,p.d=Ke(ee(p),10,i),p.e=p.d.length),f=Ke(l,10,i),o=c=f.length;f[--c]==0;)f.pop();if(!f[0])l=m?"0p+0":"0";else{if(s<0?o--:(t=new d(t),t.d=f,t.e=o,t=_(t,p,n,r,0,i),f=t.d,o=t.e,a=Ot),s=f[n],u=i/2,a=a||f[n+1]!==void 0,a=r<4?(s!==void 0||a)&&(r===0||r===(t.s<0?3:2)):s>u||s===u&&(r===4||a||r===6&&f[n-1]&1||r===(t.s<0?8:7)),f.length=n,a)for(;++f[--n]>i-1;)f[n]=0,n||(++o,f.unshift(1));for(c=f.length;!f[c-1];--c);for(s=0,l="";s<c;s++)l+=it.charAt(f[s]);if(m){if(c>1)if(e==16||e==8){for(s=e==16?4:3,--c;c%s;c++)l+="0";for(f=Ke(l,i,e),c=f.length;!f[c-1];--c);for(s=1,l="1.";s<c;s++)l+=it.charAt(f[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)l="0"+l;l="0."+l}else if(++o>c)for(o-=c;o--;)l+="0";else o<c&&(l=l.slice(0,o)+"."+l.slice(o))}l=(e==16?"0x":e==2?"0b":e==8?"0o":"")+l}return t.s<0?"-"+l:l}function It(t,e){if(t.length>e)return t.length=e,!0}function vn(t){return new this(t).abs()}function On(t){return new this(t).acos()}function Fn(t){return new this(t).acosh()}function Vn(t,e){return new this(t).plus(e)}function qn(t){return new this(t).asin()}function Wn(t){return new this(t).asinh()}function Un(t){return new this(t).atan()}function Gn(t){return new this(t).atanh()}function Hn(t,e){t=new this(t),e=new this(e);var n,r=this.precision,i=this.rounding,o=r+4;return!t.s||!e.s?n=new this(NaN):!t.d&&!e.d?(n=X(this,o,1).times(e.s>0?.25:.75),n.s=t.s):!e.d||t.isZero()?(n=e.s<0?X(this,r,i):new this(0),n.s=t.s):!t.d||e.isZero()?(n=X(this,o,1).times(.5),n.s=t.s):e.s<0?(this.precision=o,this.rounding=1,n=this.atan(_(t,e,o,1)),e=X(this,o,1),this.precision=r,this.rounding=i,n=t.s<0?n.minus(e):n.plus(e)):n=this.atan(_(t,e,o,1)),n}function zn(t){return new this(t).cbrt()}function Qn(t){return P(t=new this(t),t.e+1,2)}function jn(t,e,n){return new this(t).clamp(e,n)}function Zn(t){if(!t||typeof t!="object")throw Error(Fe+"Object expected");var e,n,r,i=t.defaults===!0,o=["precision",1,ue,"rounding",0,8,"toExpNeg",-me,0,"toExpPos",0,me,"maxE",0,me,"minE",-me,0,"modulo",0,9];for(e=0;e<o.length;e+=3)if(n=o[e],i&&(this[n]=ot[n]),(r=t[n])!==void 0)if(H(r)===r&&r>=o[e+1]&&r<=o[e+2])this[n]=r;else throw Error(se+n+": "+r);if(n="crypto",i&&(this[n]=ot[n]),(r=t[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(Vt);else this[n]=!1;else throw Error(se+n+": "+r);return this}function Jn(t){return new this(t).cos()}function Xn(t){return new this(t).cosh()}function jt(t){var e,n,r;function i(o){var s,u,c,a=this;if(!(a instanceof i))return new i(o);if(a.constructor=i,vt(o)){a.s=o.s,L?!o.d||o.e>i.maxE?(a.e=NaN,a.d=null):o.e<i.minE?(a.e=0,a.d=[0]):(a.e=o.e,a.d=o.d.slice()):(a.e=o.e,a.d=o.d?o.d.slice():o.d);return}if(c=typeof o,c==="number"){if(o===0){a.s=1/o<0?-1:1,a.e=0,a.d=[0];return}if(o<0?(o=-o,a.s=-1):a.s=1,o===~~o&&o<1e7){for(s=0,u=o;u>=10;u/=10)s++;L?s>i.maxE?(a.e=NaN,a.d=null):s<i.minE?(a.e=0,a.d=[0]):(a.e=s,a.d=[o]):(a.e=s,a.d=[o]);return}else if(o*0!==0){o||(a.s=NaN),a.e=NaN,a.d=null;return}return at(a,o.toString())}else if(c!=="string")throw Error(se+o);return(u=o.charCodeAt(0))===45?(o=o.slice(1),a.s=-1):(u===43&&(o=o.slice(1)),a.s=1),Wt.test(o)?at(a,o):Kn(a,o)}if(i.prototype=g,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=Zn,i.clone=jt,i.isDecimal=vt,i.abs=vn,i.acos=On,i.acosh=Fn,i.add=Vn,i.asin=qn,i.asinh=Wn,i.atan=Un,i.atanh=Gn,i.atan2=Hn,i.cbrt=zn,i.ceil=Qn,i.clamp=jn,i.cos=Jn,i.cosh=Xn,i.div=Yn,i.exp=$n,i.floor=er,i.hypot=tr,i.ln=nr,i.log=rr,i.log10=or,i.log2=ir,i.max=sr,i.min=ur,i.mod=ar,i.mul=cr,i.pow=lr,i.random=fr,i.round=pr,i.sign=dr,i.sin=mr,i.sinh=gr,i.sqrt=hr,i.sub=br,i.sum=yr,i.tan=wr,i.tanh=xr,i.trunc=Tr,t===void 0&&(t={}),t&&t.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<r.length;)t.hasOwnProperty(n=r[e++])||(t[n]=this[n]);return i.config(t),i}function Yn(t,e){return new this(t).div(e)}function $n(t){return new this(t).exp()}function er(t){return P(t=new this(t),t.e+1,3)}function tr(){var t,e,n=new this(0);for(L=!1,t=0;t<arguments.length;)if(e=new this(arguments[t++]),e.d)n.d&&(n=n.plus(e.times(e)));else{if(e.s)return L=!0,new this(1/0);n=e}return L=!0,n.sqrt()}function vt(t){return t instanceof We||t&&t.toStringTag===qt||!1}function nr(t){return new this(t).ln()}function rr(t,e){return new this(t).log(e)}function ir(t){return new this(t).log(2)}function or(t){return new this(t).log(10)}function sr(){return Ht(this,arguments,"lt")}function ur(){return Ht(this,arguments,"gt")}function ar(t,e){return new this(t).mod(e)}function cr(t,e){return new this(t).mul(e)}function lr(t,e){return new this(t).pow(e)}function fr(t){var e,n,r,i,o=0,s=new this(1),u=[];if(t===void 0?t=this.precision:Z(t,1,ue),r=Math.ceil(t/B),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(r));o<r;)i=e[o],i>=429e7?e[o]=crypto.getRandomValues(new Uint32Array(1))[0]:u[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):(u.push(i%1e7),o+=4);o=r/4}else throw Error(Vt);else for(;o<r;)u[o++]=Math.random()*1e7|0;for(r=u[--o],t%=B,r&&t&&(i=W(10,B-t),u[o]=(r/i|0)*i);u[o]===0;o--)u.pop();if(o<0)n=0,u=[0];else{for(n=-1;u[0]===0;n-=B)u.shift();for(r=1,i=u[0];i>=10;i/=10)r++;r<B&&(n-=B-r)}return s.e=n,s.d=u,s}function pr(t){return P(t=new this(t),t.e+1,this.rounding)}function dr(t){return t=new this(t),t.d?t.d[0]?t.s:0*t.s:t.s||NaN}function mr(t){return new this(t).sin()}function gr(t){return new this(t).sinh()}function hr(t){return new this(t).sqrt()}function br(t,e){return new this(t).sub(e)}function yr(){var t=0,e=arguments,n=new this(e[t]);for(L=!1;n.s&&++t<e.length;)n=n.plus(e[t]);return L=!0,P(n,this.precision,this.rounding)}function wr(t){return new this(t).tan()}function xr(t){return new this(t).tanh()}function Tr(t){return P(t=new this(t),t.e+1,1)}g[Symbol.for("nodejs.util.inspect.custom")]=g.toString;g[Symbol.toStringTag]="Decimal";var We=g.constructor=jt(ot);Ie=new We(Ie);ve=new We(ve);import jr from"big.js";import Mu from"bn.js";import{get as Zt,set as Pr}from"lodash";var lt=class{constructor(e){this.logLevel=e.logLevel!==void 0?e.logLevel:0,this.name=e.name}set level(e){this.logLevel=e}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(e){return e<=this.logLevel}error(...e){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...e),this):this}logWithError(...e){let n=e.map(r=>typeof r=="object"?JSON.stringify(r):r).join(", ");throw new Error(n)}warning(...e){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...e),this):this}info(...e){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...e),this):this}debug(...e){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...e),this):this}},Jt={},Ar={};function z(t){let e=Zt(Jt,t);if(!e){let n=Zt(Ar,t);e=new lt({name:t,logLevel:n}),Pr(Jt,t,e)}return e}import{MINT_SIZE as Ti,TOKEN_PROGRAM_ID as Pi,getTransferFeeConfig as Ai,unpackMint as Bi}from"@solana/spl-token";import{PublicKey as Br}from"@solana/web3.js";var ft=z("CobaltX_accountInfo_util");async function Xt(t,e,n){let{batchRequest:r,commitment:i="confirmed",chunkCount:o=100}={batchRequest:!1,...n},s=pt(e,o),u=new Array(s.length).fill([]);if(r){let c=s.map(f=>{let p=t._buildArgs([f.map(d=>d.toBase58())],i,"base64");return{methodName:"getMultipleAccounts",args:p}}),a=pt(c,10);u=(await(await Promise.all(a.map(async f=>await t._rpcBatchRequest(f)))).flat()).map(f=>(f.error&&ft.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${f.error.message}`),f.result.value.map(p=>{if(p){let{data:d,executable:m,lamports:h,owner:y,rentEpoch:T}=p;return d.length!==2&&d[1]!=="base64"&&ft.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(d[0],"base64"),executable:m,lamports:h,owner:new Br(y),rentEpoch:T}}return null})))}else try{u=await Promise.all(s.map(c=>t.getMultipleAccountsInfo(c,i)))}catch(c){c instanceof Error&&ft.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return u.flat()}import Pe from"bn.js";var Yt=9007199254740991;function ne(t){let e=z("CobaltX_parseBigNumberish");if(t instanceof Pe)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new Pe(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=Yt||t<=-Yt)&&e.logWithError(`BigNumberish number overflow: ${t}`),new Pe(String(t))):typeof t=="bigint"?new Pe(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new Pe(0))}import{TOKEN_PROGRAM_ID as $t}from"@solana/spl-token";import{PublicKey as Sr}from"@solana/web3.js";var en={chainId:101,address:Sr.default.toBase58(),programId:$t.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"}},fe={chainId:101,address:"So11111111111111111111111111111111111111112",programId:$t.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 gt}from"@solana/web3.js";import{PublicKey as G,SystemProgram as tn,SYSVAR_RENT_PUBKEY as Lr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as kr}from"@solana/spl-token";function mt({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var Ui=[mt({pubkey:kr,isWritable:!1}),mt({pubkey:tn.programId,isWritable:!1}),mt({pubkey:Lr,isWritable:!1})];function nn({publicKey:t,transformSol:e}){let n=rn(t.toString());if(n instanceof G)return e&&n.equals(Ae)?dt:n;if(e&&n.toString()===Ae.toBase58())return dt;if(typeof n=="string"){if(n===G.default.toBase58())return G.default;try{return new G(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function rn(t){try{return new G(t)}catch{return t}}var Gi=new G("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Hi=new G("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),zi=new G("SysvarRent111111111111111111111111111111111"),Qi=new G("SysvarC1ock11111111111111111111111111111111"),ji=new G("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Zi=new G("Sysvar1nstructions1111111111111111111111111"),Ji=tn.programId,Xi=new G("a2Gt18uJC8puJT9JRYQLU6rPi6okxQb4WqCjwtYshZB"),Yi=new G("bXSKiFqYrALF9gJy1KqHm8tv4QXk8nCgbLN8WRsGEbh"),dt=new G("So11111111111111111111111111111111111111112"),Ae=G.default,$i=new G("71kRXzJMvSeArtXYNEWa8KAjpRJosdMQ7Dpgy5Jt5zfd"),eo=new G("ERFzpDteGNo8LTDKW1WwVGrkRMmA2y9WZHXNHxMA6BSV");var ht=class{constructor({mint:e,decimals:n,symbol:r,name:i,skipMint:o=!1,isToken2022:s=!1}){if(e===Ae.toBase58()||e instanceof gt&&Ae.equals(e)){this.decimals=fe.decimals,this.symbol=fe.symbol,this.name=fe.name,this.mint=new gt(fe.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||e.toString().substring(0,6),this.name=i||e.toString().substring(0,6),this.mint=o?gt.default:nn({publicKey:e}),this.isToken2022=s}equals(e){return this===e?!0:this.mint.equals(e.mint)}},he=ht;he.WSOL=new ht({...fe,mint:fe.address});var bt=class{constructor({decimals:e,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=r}equals(e){return this===e}},Ue=bt;Ue.SOL=new bt(en);import Cr from"toformat";var Nr=Cr,Be=Nr;import He from"big.js";import Er from"bn.js";import Rr from"decimal.js-light";var Ge=z("module/fraction"),yt=Be(He),Se=Be(Rr),Dr={[0]:Se.ROUND_DOWN,[1]:Se.ROUND_HALF_UP,[2]:Se.ROUND_UP},_r={[0]:He.roundDown,[1]:He.roundHalfUp,[2]:He.roundUp},I=class{constructor(e,n=new Er(1)){this.numerator=ne(e),this.denominator=ne(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new I(this.denominator,this.numerator)}add(e){let n=e instanceof I?e:new I(ne(e));return this.denominator.eq(n.denominator)?new I(this.numerator.add(n.numerator),this.denominator):new I(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(e){let n=e instanceof I?e:new I(ne(e));return this.denominator.eq(n.denominator)?new I(this.numerator.sub(n.numerator),this.denominator):new I(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(e){let n=e instanceof I?e:new I(ne(e));return new I(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(e){let n=e instanceof I?e:new I(ne(e));return new I(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(e,n={groupSeparator:""},r=1){Number.isInteger(e)||Ge.logWithError(`${e} is not an integer.`),e<=0&&Ge.logWithError(`${e} is not positive.`),Se.set({precision:e+1,rounding:Dr[r]});let i=new Se(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return i.toFormat(i.decimalPlaces(),n)}toFixed(e,n={groupSeparator:""},r=1){return Number.isInteger(e)||Ge.logWithError(`${e} is not an integer.`),e<0&&Ge.logWithError(`${e} is negative.`),yt.DP=e,yt.RM=_r[r]||1,new yt(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};import Kr from"bn.js";var Ao=new I(new Kr(100));var No=z("CobaltX_price");function pt(t,e=1,n=[]){let r=[...t];if(e<=0)return n;for(;r.length;)n.push(r.splice(0,e));return n}import{PublicKey as us}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as cs}from"@solana/spl-token";import{ComputeBudgetProgram as an,Keypair as ln,PublicKey as Yo,Transaction as fn,TransactionMessage as Ir,VersionedTransaction as pn}from"@solana/web3.js";var J={CreateAccount:"CreateAccount",InitAccount:"InitAccount",CreateATA:"CreateATA",CloseAccount:"CloseAccount",TransferAmount:"TransferAmount",InitMint:"InitMint",MintTo:"MintTo",InitMarket:"InitMarket",Util1216OwnerClaim:"Util1216OwnerClaim",SetComputeUnitPrice:"SetComputeUnitPrice",SetComputeUnitLimit:"SetComputeUnitLimit",ClmmCreatePool:"ClmmCreatePool",ClmmOpenPosition:"ClmmOpenPosition",ClmmIncreasePosition:"ClmmIncreasePosition",ClmmDecreasePosition:"ClmmDecreasePosition",ClmmClosePosition:"ClmmClosePosition",ClmmSwapBaseIn:"ClmmSwapBaseIn",ClmmSwapBaseOut:"ClmmSwapBaseOut",ClmmInitReward:"ClmmInitReward",ClmmSetReward:"ClmmSetReward",ClmmCollectReward:"ClmmCollectReward",ClmmLockPosition:"ClmmLockPosition",ClmmHarvestLockPosition:"ClmmHarvestLockPosition",AmmV4Swap:"AmmV4Swap",AmmV4AddLiquidity:"AmmV4AddLiquidity",AmmV4RemoveLiquidity:"AmmV4RemoveLiquidity",AmmV4SimulatePoolInfo:"AmmV4SimulatePoolInfo",AmmV4SwapBaseIn:"AmmV4SwapBaseIn",AmmV4SwapBaseOut:"AmmV4SwapBaseOut",AmmV4CreatePool:"AmmV4CreatePool",AmmV4InitPool:"AmmV4InitPool",AmmV5AddLiquidity:"AmmV5AddLiquidity",AmmV5RemoveLiquidity:"AmmV5RemoveLiquidity",AmmV5SimulatePoolInfo:"AmmV5SimulatePoolInfo",AmmV5SwapBaseIn:"AmmV5SwapBaseIn",AmmV5SwapBaseOut:"AmmV5SwapBaseOut",RouteSwap:"RouteSwap",RouteSwap1:"RouteSwap1",RouteSwap2:"RouteSwap2",FarmV3Deposit:"FarmV3Deposit",FarmV3Withdraw:"FarmV3Withdraw",FarmV3CreateLedger:"FarmV3CreateLedger",FarmV4Withdraw:"FarmV4Withdraw",FarmV5Deposit:"FarmV5Deposit",FarmV5Withdraw:"FarmV5Withdraw",FarmV5CreateLedger:"FarmV5CreateLedger",FarmV6Deposit:"FarmV6Deposit",FarmV6Withdraw:"FarmV6Withdraw",FarmV6Create:"FarmV6Create",FarmV6Restart:"FarmV6Restart",FarmV6CreatorAddReward:"FarmV6CreatorAddReward",FarmV6CreatorWithdraw:"FarmV6CreatorWithdraw",CpmmCreatePool:"CpmmCreatePool",CpmmAddLiquidity:"CpmmAddLiquidity",CpmmWithdrawLiquidity:"CpmmWithdrawLiquidity",CpmmSwapBaseIn:"CpmmSwapBaseIn",CpmmSwapBaseOut:"CpmmSwapBaseOut",CpmmLockLp:"CpmmLockLp",CpmmCollectLockFee:"CpmmCollectLockFee"};import{TOKEN_PROGRAM_ID as vr}from"@solana/spl-token";var cn=z("CobaltX_txUtil"),dn=1644;function Qe(t){let e=[],n=[];return t.microLamports&&(e.push(an.setComputeUnitPrice({microLamports:t.microLamports})),n.push(J.SetComputeUnitPrice)),t.units&&(e.push(an.setComputeUnitLimit({units:t.units})),n.push(J.SetComputeUnitLimit)),{instructions:e,instructionTypes:n}}async function be(t,e){var r,i;let n=e!=null?e:"confirmed";return(i=await((r=t.getLatestBlockhash)==null?void 0:r.call(t,{commitment:n})))==null?void 0:i.blockhash}async function je(t,e){return t.getSignatureStatuses([e]),new Promise((n,r)=>{let i=setTimeout(r,6e4);t.onSignature(e,o=>{if(clearTimeout(i),!o.err){n("");return}r(o.err.toString())},"confirmed")})}function Or(t,e){t.length<1&&cn.logWithError(`no instructions provided: ${t.toString()}`),e.length<1&&cn.logWithError(`no signers provided:, ${e.toString()}`);let n=new fn;n.recentBlockhash="11111111111111111111111111111111",n.feePayer=e[0],n.add(...t);try{return Buffer.from(n.serialize({verifySignatures:!1})).toString("base64").length<dn}catch{return!1}}function Le({instructions:t,payer:e,signers:n}){return Or(t,[e,...n])}function ke({instructions:t,payer:e,lookupTableAddressAccount:n,recentBlockhash:r=ln.generate().publicKey.toString()}){let o=new Ir({payerKey:e,recentBlockhash:r,instructions:t}).compileToV0Message(Object.values(n!=null?n:{}));try{return Buffer.from(new pn(o).serialize()).toString("base64").length<dn}catch{return!1}}var Fr=t=>Buffer.isBuffer(t)?t:t instanceof Uint8Array?Buffer.from(t.buffer,t.byteOffset,t.byteLength):Buffer.from(t),Vr=t=>{let e=t.serialize({requireAllSignatures:!1,verifySignatures:!1});t instanceof pn&&(e=Fr(e));try{return e instanceof Buffer?e.toString("base64"):Buffer.from(e).toString("base64")}catch{return e.toString("base64")}};function pe(t){let e=[];return t.forEach(n=>{n instanceof fn&&(n.recentBlockhash||(n.recentBlockhash=vr.toBase58()),n.feePayer||(n.feePayer=ln.generate().publicKey)),e.push(Vr(n))}),console.log("simulate tx string:",e),e}import{PublicKey as C}from"@solana/web3.js";var ds=new C("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),ms=new C("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),gs=new C("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),hs=new C("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),bs=new C("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),ys=new C("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),ws=new C("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),xs=new C("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Ts=new C("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Ps=new C("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),As=new C("2TnjBuwqyBB9to5jURagDT7jLmBPefGRiKL2yh1zPZ4V"),Bs=new C("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),Ss=new C("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),Ls=new C("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),ks=new C("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Cs=new C("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Ns=new C("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),Ms=new C("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),Es=new C("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),Rs=new C("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),Ds=new C("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),_s=new C("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),qr=new C("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),Wr=new C("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),Ur=new C("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),Ks=new C("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),Gr=new C("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),Is=new C("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),Hr=new C("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix");var vs={SERUM_MARKET:C.default,OPENBOOK_MARKET:new C("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:C.default,FarmV3:new C("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new C("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new C("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new C("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new C("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new C("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),CLMM_LOCK_PROGRAM_ID:new C("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),CLMM_LOCK_AUTH_ID:new C("8qmHNvu2Kr2C7U8mJL4Vz1vTDxMhVuXKREwU7TNoaVEo"),Router:new C("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:qr,CREATE_CPMM_POOL_AUTH:Wr,CREATE_CPMM_POOL_FEE_ACC:Ur,FEE_DESTINATION_ID:new C("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),LOCK_CPMM_PROGRAM:Gr,LCOK_CPMM_AUTH:Hr};import Vs from"bn.js";import{PublicKey as mn,AddressLookupTableAccount as Ze}from"@solana/web3.js";async function wt({connection:t,address:e}){let n=await Xt(t,[...new Set(e.map(i=>i.toString()))].map(i=>new mn(i))),r={};for(let i=0;i<e.length;i++){let o=n[i],s=e[i];if(!o)continue;let u=new Ze({key:s,state:Ze.deserialize(o.data)});r[s.toString()]=u,Je[s.toString()]=u}return r}var Je={AiAibtFJts8e4W1FjWYRH34aBJkJqghdmXiJozK7MvTM:new Ze({key:new mn("AiAibtFJts8e4W1FjWYRH34aBJkJqghdmXiJozK7MvTM"),state:Ze.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 Ce,sendAndConfirmTransaction as xt,Transaction as Ne,TransactionMessage as Me,VersionedTransaction as Ee}from"@solana/web3.js";import Qr from"axios";var Xe=class{constructor(e){this.instructions=[];this.endInstructions=[];this.lookupTableAddress=[];this.signers=[];this.instructionTypes=[];this.endInstructionTypes=[];this.connection=e.connection,this.feePayer=e.feePayer,this.signAllTransactions=e.signAllTransactions,this.owner=e.owner,this.cluster=e.cluster,this.blockhashCommitment=e.blockhashCommitment,this.api=e.api}get AllTxData(){return{instructions:this.instructions,endInstructions:this.endInstructions,signers:this.signers,instructionTypes:this.instructionTypes,endInstructionTypes:this.endInstructionTypes,lookupTableAddress:this.lookupTableAddress}}get allInstructions(){return[...this.instructions,...this.endInstructions]}async getComputeBudgetConfig(){var r;let e=(await Qr.get(`https://solanacompass.com/api/fees?cacheFreshTime=${3e5}`)).data,{avg:n}=(r=e==null?void 0:e[15])!=null?r:{};if(!!n)return{units:6e5,microLamports:Math.min(Math.ceil(n*1e6/6e5),25e3)}}addCustomComputeBudget(e){if(e){let{instructions:n,instructionTypes:r}=Qe(e);return this.instructions.unshift(...n),this.instructionTypes.unshift(...r),!0}return!1}async calComputeBudget({config:e,defaultIns:n}){try{let r=e||await this.getComputeBudgetConfig();if(this.addCustomComputeBudget(r))return;n&&this.instructions.unshift(...n)}catch{n&&this.instructions.unshift(...n)}}addInstruction({instructions:e=[],endInstructions:n=[],signers:r=[],instructionTypes:i=[],endInstructionTypes:o=[],lookupTableAddress:s=[]}){return this.instructions.push(...e),this.endInstructions.push(...n),this.signers.push(...r),this.instructionTypes.push(...i),this.endInstructionTypes.push(...o),this.lookupTableAddress.push(...s.filter(u=>u!==Ce.default.toString())),this}async versionBuild({txVersion:e,extInfo:n}){return e==