@cobaltx/sdk-v2
Version:
An SDK for building applications on top of CobaltX.
1 lines • 104 kB
JavaScript
import we from"bn.js";var Fe=9e15,Be=1e9,Gt="0123456789abcdef",pt="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",ft="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Ut={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Fe,maxE:Fe,crypto:!1},Nn,ge,M=!0,yt="[DecimalError] ",Te=yt+"Invalid argument: ",Ln=yt+"Precision limit exceeded",Rn=yt+"crypto unavailable",Mn="[object Decimal]",te=Math.floor,Y=Math.pow,Wi=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Vi=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,qi=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,On=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,ce=1e7,N=7,Gi=9007199254740991,Ui=pt.length-1,Xt=ft.length-1,g={toStringTag:Mn};g.absoluteValue=g.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),S(n)};g.ceil=function(){return S(new this.constructor(this),this.e+1,2)};g.clampedTo=g.clamp=function(n,e){var t,i=this,r=i.constructor;if(n=new r(n),e=new r(e),!n.s||!e.s)return new r(NaN);if(n.gt(e))throw Error(Te+e);return t=i.cmp(n),t<0?n:i.cmp(e)>0?e:new r(i)};g.comparedTo=g.cmp=function(n){var e,t,i,r,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(i=s.length,r=a.length,e=0,t=i<r?i:r;e<t;++e)if(s[e]!==a[e])return s[e]>a[e]^c<0?1:-1;return i===r?0:i>r^c<0?1:-1};g.cosine=g.cos=function(){var n,e,t=this,i=t.constructor;return t.d?t.d[0]?(n=i.precision,e=i.rounding,i.precision=n+Math.max(t.e,t.sd())+N,i.rounding=1,t=Xi(i,_n(i,t)),i.precision=n,i.rounding=e,S(ge==2||ge==3?t.neg():t,n,e,!0)):new i(1):new i(NaN)};g.cubeRoot=g.cbrt=function(){var n,e,t,i,r,o,s,a,c,u,m=this,l=m.constructor;if(!m.isFinite()||m.isZero())return new l(m);for(M=!1,o=m.s*Y(m.s*m,1/3),!o||Math.abs(o)==1/0?(t=$(m.d),n=m.e,(o=(n-t.length+1)%3)&&(t+=o==1||o==-2?"0":"00"),o=Y(t,1/3),n=te((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),i=new l(t),i.s=m.s):i=new l(o.toString()),s=(n=l.precision)+3;;)if(a=i,c=a.times(a).times(a),u=c.plus(m),i=G(u.plus(m).times(a),u.plus(c),s+2,1),$(a.d).slice(0,s)===(t=$(i.d)).slice(0,s))if(t=t.slice(s-3,s+1),t=="9999"||!r&&t=="4999"){if(!r&&(S(a,n+1,0),a.times(a).times(a).eq(m))){i=a;break}s+=4,r=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(S(i,n+1,1),e=!i.times(i).times(i).eq(m));break}return M=!0,S(i,n,l.rounding,e)};g.decimalPlaces=g.dp=function(){var n,e=this.d,t=NaN;if(e){if(n=e.length-1,t=(n-te(this.e/N))*N,n=e[n],n)for(;n%10==0;n/=10)t--;t<0&&(t=0)}return t};g.dividedBy=g.div=function(n){return G(this,new this.constructor(n))};g.dividedToIntegerBy=g.divToInt=function(n){var e=this,t=e.constructor;return S(G(e,new t(n),0,1,1),t.precision,t.rounding)};g.equals=g.eq=function(n){return this.cmp(n)===0};g.floor=function(){return S(new this.constructor(this),this.e+1,3)};g.greaterThan=g.gt=function(n){return this.cmp(n)>0};g.greaterThanOrEqualTo=g.gte=function(n){var e=this.cmp(n);return e==1||e===0};g.hyperbolicCosine=g.cosh=function(){var n,e,t,i,r,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,i=s.rounding,s.precision=t+Math.max(o.e,o.sd())+4,s.rounding=1,r=o.d.length,r<32?(n=Math.ceil(r/3),e=(1/wt(4,n)).toString()):(n=16,e="2.3283064365386962890625e-10"),o=Ee(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 S(o,s.precision=t,s.rounding=i,!0)};g.hyperbolicSine=g.sinh=function(){var n,e,t,i,r=this,o=r.constructor;if(!r.isFinite()||r.isZero())return new o(r);if(e=o.precision,t=o.rounding,o.precision=e+Math.max(r.e,r.sd())+4,o.rounding=1,i=r.d.length,i<3)r=Ee(o,2,r,r,!0);else{n=1.4*Math.sqrt(i),n=n>16?16:n|0,r=r.times(1/wt(5,n)),r=Ee(o,2,r,r,!0);for(var s,a=new o(5),c=new o(16),u=new o(20);n--;)s=r.times(r),r=r.times(a.plus(s.times(c.times(s).plus(u))))}return o.precision=e,o.rounding=t,S(r,e,t,!0)};g.hyperbolicTangent=g.tanh=function(){var n,e,t=this,i=t.constructor;return t.isFinite()?t.isZero()?new i(t):(n=i.precision,e=i.rounding,i.precision=n+7,i.rounding=1,G(t.sinh(),t.cosh(),i.precision=n,i.rounding=e)):new i(t.s)};g.inverseCosine=g.acos=function(){var n,e=this,t=e.constructor,i=e.abs().cmp(1),r=t.precision,o=t.rounding;return i!==-1?i===0?e.isNeg()?ue(t,r,o):new t(0):new t(NaN):e.isZero()?ue(t,r+4,o).times(.5):(t.precision=r+6,t.rounding=1,e=e.asin(),n=ue(t,r+4,o).times(.5),t.precision=r,t.rounding=o,n.minus(e))};g.inverseHyperbolicCosine=g.acosh=function(){var n,e,t=this,i=t.constructor;return t.lte(1)?new i(t.eq(1)?0:NaN):t.isFinite()?(n=i.precision,e=i.rounding,i.precision=n+Math.max(Math.abs(t.e),t.sd())+4,i.rounding=1,M=!1,t=t.times(t).minus(1).sqrt().plus(t),M=!0,i.precision=n,i.rounding=e,t.ln()):new i(t)};g.inverseHyperbolicSine=g.asinh=function(){var n,e,t=this,i=t.constructor;return!t.isFinite()||t.isZero()?new i(t):(n=i.precision,e=i.rounding,i.precision=n+2*Math.max(Math.abs(t.e),t.sd())+6,i.rounding=1,M=!1,t=t.times(t).plus(1).sqrt().plus(t),M=!0,i.precision=n,i.rounding=e,t.ln())};g.inverseHyperbolicTangent=g.atanh=function(){var n,e,t,i,r=this,o=r.constructor;return r.isFinite()?r.e>=0?new o(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(n=o.precision,e=o.rounding,i=r.sd(),Math.max(i,n)<2*-r.e-1?S(new o(r),n,e,!0):(o.precision=t=i-r.e,r=G(r.plus(1),new o(1).minus(r),t+n,1),o.precision=n+4,o.rounding=1,r=r.ln(),o.precision=n,o.rounding=e,r.times(.5))):new o(NaN)};g.inverseSine=g.asin=function(){var n,e,t,i,r=this,o=r.constructor;return r.isZero()?new o(r):(e=r.abs().cmp(1),t=o.precision,i=o.rounding,e!==-1?e===0?(n=ue(o,t+4,i).times(.5),n.s=r.s,n):new o(NaN):(o.precision=t+6,o.rounding=1,r=r.div(new o(1).minus(r.times(r)).sqrt().plus(1)).atan(),o.precision=t,o.rounding=i,r.times(2)))};g.inverseTangent=g.atan=function(){var n,e,t,i,r,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<=Xt)return s=ue(m,l+4,d).times(.25),s.s=u.s,s}else{if(!u.s)return new m(NaN);if(l+4<=Xt)return s=ue(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/N+2|0),n=t;n;--n)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(M=!1,e=Math.ceil(a/N),i=1,c=u.times(u),s=new m(u),r=u;n!==-1;)if(r=r.times(c),o=s.minus(r.div(i+=2)),r=r.times(c),s=o.plus(r.div(i+=2)),s.d[e]!==void 0)for(n=e;s.d[n]===o.d[n]&&n--;);return t&&(s=s.times(2<<t-1)),M=!0,S(s,m.precision=l,m.rounding=d,!0)};g.isFinite=function(){return!!this.d};g.isInteger=g.isInt=function(){return!!this.d&&te(this.e/N)>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(n){return this.cmp(n)<0};g.lessThanOrEqualTo=g.lte=function(n){return this.cmp(n)<1};g.logarithm=g.log=function(n){var e,t,i,r,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(r=t[0];r%10===0;)r/=10;o=r!==1}if(M=!1,a=l+p,s=he(u,a),i=e?bt(m,a+10):he(n,a),c=G(s,i,a,1),Xe(c.d,r=l,d))do if(a+=10,s=he(u,a),i=e?bt(m,a+10):he(n,a),c=G(s,i,a,1),!o){+$(c.d).slice(r+1,r+15)+1==1e14&&(c=S(c,l+1,0));break}while(Xe(c.d,r+=10,d));return M=!0,S(c,l,d)};g.minus=g.sub=function(n){var e,t,i,r,o,s,a,c,u,m,l,d,p=this,b=p.constructor;if(n=new b(n),!p.d||!n.d)return!p.s||!n.s?n=new b(NaN):p.d?n.s=-n.s:n=new b(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=b.precision,c=b.rounding,!u[0]||!d[0]){if(d[0])n.s=-n.s;else if(u[0])n=new b(p);else return new b(c===3?-0:0);return M?S(n,a,c):n}if(t=te(n.e/N),m=te(p.e/N),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),i=Math.max(Math.ceil(a/N),s)+2,o>i&&(o=i,e.length=1),e.reverse(),i=o;i--;)e.push(0);e.reverse()}else{for(i=u.length,s=d.length,l=i<s,l&&(s=i),i=0;i<s;i++)if(u[i]!=d[i]){l=u[i]<d[i];break}o=0}for(l&&(e=u,u=d,d=e,n.s=-n.s),s=u.length,i=d.length-s;i>0;--i)u[s++]=0;for(i=d.length;i>o;){if(u[--i]<d[i]){for(r=i;r&&u[--r]===0;)u[r]=ce-1;--u[r],u[i]+=ce}u[i]-=d[i]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--t;return u[0]?(n.d=u,n.e=gt(u,t),M?S(n,a,c):n):new b(c===3?-0:0)};g.modulo=g.mod=function(n){var e,t=this,i=t.constructor;return n=new i(n),!t.d||!n.s||n.d&&!n.d[0]?new i(NaN):!n.d||t.d&&!t.d[0]?S(new i(t),i.precision,i.rounding):(M=!1,i.modulo==9?(e=G(t,n.abs(),0,3,1),e.s*=n.s):e=G(t,n,0,i.modulo,1),e=e.times(n),M=!0,t.minus(e))};g.naturalExponential=g.exp=function(){return zt(this)};g.naturalLogarithm=g.ln=function(){return he(this)};g.negated=g.neg=function(){var n=new this.constructor(this);return n.s=-n.s,S(n)};g.plus=g.add=function(n){var e,t,i,r,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)),M?S(n,a,c):n;if(o=te(l.e/N),i=te(n.e/N),u=u.slice(),r=o-i,r){for(r<0?(t=u,r=-r,s=m.length):(t=m,i=o,s=u.length),o=Math.ceil(a/N),s=o>s?o+1:s+1,r>s&&(r=s,t.length=1),t.reverse();r--;)t.push(0);t.reverse()}for(s=u.length,r=m.length,s-r<0&&(r=s,t=m,m=u,u=t),e=0;r;)e=(u[--r]=u[r]+m[r]+e)/ce|0,u[r]%=ce;for(e&&(u.unshift(e),++i),s=u.length;u[--s]==0;)u.pop();return n.d=u,n.e=gt(u,i),M?S(n,a,c):n};g.precision=g.sd=function(n){var e,t=this;if(n!==void 0&&n!==!!n&&n!==1&&n!==0)throw Error(Te+n);return t.d?(e=Fn(t.d),n&&t.e+1>e&&(e=t.e+1)):e=NaN,e};g.round=function(){var n=this,e=n.constructor;return S(new e(n),n.e+1,e.rounding)};g.sine=g.sin=function(){var n,e,t=this,i=t.constructor;return t.isFinite()?t.isZero()?new i(t):(n=i.precision,e=i.rounding,i.precision=n+Math.max(t.e,t.sd())+N,i.rounding=1,t=Hi(i,_n(i,t)),i.precision=n,i.rounding=e,S(ge>2?t.neg():t,n,e,!0)):new i(NaN)};g.squareRoot=g.sqrt=function(){var n,e,t,i,r,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(M=!1,u=Math.sqrt(+s),u==0||u==1/0?(e=$(a),(e.length+c)%2==0&&(e+="0"),u=Math.sqrt(e),c=te((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),i=new m(e)):i=new m(u.toString()),t=(c=m.precision)+3;;)if(o=i,i=o.plus(G(s,o,t+2,1)).times(.5),$(o.d).slice(0,t)===(e=$(i.d)).slice(0,t))if(e=e.slice(t-3,t+1),e=="9999"||!r&&e=="4999"){if(!r&&(S(o,c+1,0),o.times(o).eq(s))){i=o;break}t+=4,r=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(S(i,c+1,1),n=!i.times(i).eq(s));break}return M=!0,S(i,c,m.rounding,n)};g.tangent=g.tan=function(){var n,e,t=this,i=t.constructor;return t.isFinite()?t.isZero()?new i(t):(n=i.precision,e=i.rounding,i.precision=n+10,i.rounding=1,t=t.sin(),t.s=1,t=G(t,new i(1).minus(t.times(t)).sqrt(),n+10,0),i.precision=n,i.rounding=e,S(ge==2||ge==4?t.neg():t,n,e,!0)):new i(NaN)};g.times=g.mul=function(n){var e,t,i,r,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=te(m.e/N)+te(n.e/N),c=d.length,u=p.length,c<u&&(o=d,d=p,p=o,s=c,c=u,u=s),o=[],s=c+u,i=s;i--;)o.push(0);for(i=u;--i>=0;){for(e=0,r=c+i;r>i;)a=o[r]+p[i]*d[r-i-1]+e,o[r--]=a%ce|0,e=a/ce|0;o[r]=(o[r]+e)%ce|0}for(;!o[--s];)o.pop();return e?++t:o.shift(),n.d=o,n.e=gt(o,t),M?S(n,l.precision,l.rounding):n};g.toBinary=function(n,e){return Zt(this,2,n,e)};g.toDecimalPlaces=g.toDP=function(n,e){var t=this,i=t.constructor;return t=new i(t),n===void 0?t:(ie(n,0,Be),e===void 0?e=i.rounding:ie(e,0,8),S(t,n+t.e+1,e))};g.toExponential=function(n,e){var t,i=this,r=i.constructor;return n===void 0?t=pe(i,!0):(ie(n,0,Be),e===void 0?e=r.rounding:ie(e,0,8),i=S(new r(i),n+1,e),t=pe(i,!0,n+1)),i.isNeg()&&!i.isZero()?"-"+t:t};g.toFixed=function(n,e){var t,i,r=this,o=r.constructor;return n===void 0?t=pe(r):(ie(n,0,Be),e===void 0?e=o.rounding:ie(e,0,8),i=S(new o(r),n+r.e+1,e),t=pe(i,!1,n+i.e+1)),r.isNeg()&&!r.isZero()?"-"+t:t};g.toFraction=function(n){var e,t,i,r,o,s,a,c,u,m,l,d,p=this,b=p.d,f=p.constructor;if(!b)return new f(p);if(u=t=new f(1),i=c=new f(0),e=new f(i),o=e.e=Fn(b)-p.e-1,s=o%N,e.d[0]=Y(10,s<0?N+s:s),n==null)n=o>0?e:u;else{if(a=new f(n),!a.isInt()||a.lt(u))throw Error(Te+a);n=a.gt(e)?o>0?e:u:a}for(M=!1,a=new f($(b)),m=f.precision,f.precision=o=b.length*N*2;l=G(a,e,0,1,1),r=t.plus(l.times(i)),r.cmp(n)!=1;)t=i,i=r,r=u,u=c.plus(l.times(r)),c=r,r=e,e=a.minus(l.times(r)),a=r;return r=G(n.minus(t),i,0,1,1),c=c.plus(r.times(u)),t=t.plus(r.times(i)),c.s=u.s=p.s,d=G(u,i,o,1).minus(p).abs().cmp(G(c,t,o,1).minus(p).abs())<1?[u,i]:[c,t],f.precision=m,M=!0,d};g.toHexadecimal=g.toHex=function(n,e){return Zt(this,16,n,e)};g.toNearest=function(n,e){var t=this,i=t.constructor;if(t=new i(t),n==null){if(!t.d)return t;n=new i(1),e=i.rounding}else{if(n=new i(n),e===void 0?e=i.rounding:ie(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]?(M=!1,t=G(t,n,0,e,1).times(n),M=!0,S(t)):(n.s=t.s,t=n),t};g.toNumber=function(){return+this};g.toOctal=function(n,e){return Zt(this,8,n,e)};g.toPower=g.pow=function(n){var e,t,i,r,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(Y(+a,u));if(a=new c(a),a.eq(1))return a;if(i=c.precision,o=c.rounding,n.eq(1))return S(a,i,o);if(e=te(n.e/N),e>=n.d.length-1&&(t=u<0?-u:u)<=Gi)return r=En(c,a,t,i),n.s<0?new c(1).div(r):S(r,i,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=Y(+a,u),e=t==0||!isFinite(t)?te(u*(Math.log("0."+$(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):(M=!1,c.rounding=a.s=1,t=Math.min(12,(e+"").length),r=zt(n.times(he(a,i+t)),i),r.d&&(r=S(r,i+5,1),Xe(r.d,i,o)&&(e=i+10,r=S(zt(n.times(he(a,e+t)),e),e+5,1),+$(r.d).slice(i+1,i+15)+1==1e14&&(r=S(r,i+1,0)))),r.s=s,M=!0,c.rounding=o,S(r,i,o))};g.toPrecision=function(n,e){var t,i=this,r=i.constructor;return n===void 0?t=pe(i,i.e<=r.toExpNeg||i.e>=r.toExpPos):(ie(n,1,Be),e===void 0?e=r.rounding:ie(e,0,8),i=S(new r(i),n,e),t=pe(i,n<=i.e||i.e<=r.toExpNeg,n)),i.isNeg()&&!i.isZero()?"-"+t:t};g.toSignificantDigits=g.toSD=function(n,e){var t=this,i=t.constructor;return n===void 0?(n=i.precision,e=i.rounding):(ie(n,1,Be),e===void 0?e=i.rounding:ie(e,0,8)),S(new i(t),n,e)};g.toString=function(){var n=this,e=n.constructor,t=pe(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()&&!n.isZero()?"-"+t:t};g.truncated=g.trunc=function(){return S(new this.constructor(this),this.e+1,1)};g.valueOf=g.toJSON=function(){var n=this,e=n.constructor,t=pe(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()?"-"+t:t};function $(n){var e,t,i,r=n.length-1,o="",s=n[0];if(r>0){for(o+=s,e=1;e<r;e++)i=n[e]+"",t=N-i.length,t&&(o+=ke(t)),o+=i;s=n[e],i=s+"",t=N-i.length,t&&(o+=ke(t))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function ie(n,e,t){if(n!==~~n||n<e||n>t)throw Error(Te+n)}function Xe(n,e,t,i){var r,o,s,a;for(o=n[0];o>=10;o/=10)--e;return--e<0?(e+=N,r=0):(r=Math.ceil((e+1)/N),e%=N),o=Y(10,N-e),a=n[r]%o|0,i==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[r+1]/o/100|0)==Y(10,e-2)-1||(a==o/2||a==0)&&(n[r+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=(i||t<4)&&a==9999||!i&&t>3&&a==4999):s=((i||t<4)&&a+1==o||!i&&t>3&&a+1==o/2)&&(n[r+1]/o/1e3|0)==Y(10,e-3)-1,s}function dt(n,e,t){for(var i,r=[0],o,s=0,a=n.length;s<a;){for(o=r.length;o--;)r[o]*=e;for(r[0]+=Gt.indexOf(n.charAt(s++)),i=0;i<r.length;i++)r[i]>t-1&&(r[i+1]===void 0&&(r[i+1]=0),r[i+1]+=r[i]/t|0,r[i]%=t)}return r.reverse()}function Xi(n,e){var t,i,r;if(e.isZero())return e;i=e.d.length,i<32?(t=Math.ceil(i/3),r=(1/wt(4,t)).toString()):(t=16,r="2.3283064365386962890625e-10"),n.precision+=t,e=Ee(n,1,e.times(r),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 G=function(){function n(i,r,o){var s,a=0,c=i.length;for(i=i.slice();c--;)s=i[c]*r+a,i[c]=s%o|0,a=s/o|0;return a&&i.unshift(a),i}function e(i,r,o,s){var a,c;if(o!=s)c=o>s?1:-1;else for(a=c=0;a<o;a++)if(i[a]!=r[a]){c=i[a]>r[a]?1:-1;break}return c}function t(i,r,o,s){for(var a=0;o--;)i[o]-=a,a=i[o]<r[o]?1:0,i[o]=a*s+i[o]-r[o];for(;!i[0]&&i.length>1;)i.shift()}return function(i,r,o,s,a,c){var u,m,l,d,p,b,f,y,A,k,w,P,h,T,I,R,_,E,L,v,D=i.constructor,j=i.s==r.s?1:-1,q=i.d,W=r.d;if(!q||!q[0]||!W||!W[0])return new D(!i.s||!r.s||(q?W&&q[0]==W[0]:!W)?NaN:q&&q[0]==0||!W?j*0:j/0);for(c?(p=1,m=i.e-r.e):(c=ce,p=N,m=te(i.e/p)-te(r.e/p)),L=W.length,_=q.length,A=new D(j),k=A.d=[],l=0;W[l]==(q[l]||0);l++);if(W[l]>(q[l]||0)&&m--,o==null?(T=o=D.precision,s=D.rounding):a?T=o+(i.e-r.e)+1:T=o,T<0)k.push(1),b=!0;else{if(T=T/p+2|0,l=0,L==1){for(d=0,W=W[0],T++;(l<_||d)&&T--;l++)I=d*c+(q[l]||0),k[l]=I/W|0,d=I%W|0;b=d||l<_}else{for(d=c/(W[0]+1)|0,d>1&&(W=n(W,d,c),q=n(q,d,c),L=W.length,_=q.length),R=L,w=q.slice(0,L),P=w.length;P<L;)w[P++]=0;v=W.slice(),v.unshift(0),E=W[0],W[1]>=c/2&&++E;do d=0,u=e(W,w,L,P),u<0?(h=w[0],L!=P&&(h=h*c+(w[1]||0)),d=h/E|0,d>1?(d>=c&&(d=c-1),f=n(W,d,c),y=f.length,P=w.length,u=e(f,w,y,P),u==1&&(d--,t(f,L<y?v:W,y,c))):(d==0&&(u=d=1),f=W.slice()),y=f.length,y<P&&f.unshift(0),t(w,f,P,c),u==-1&&(P=w.length,u=e(W,w,L,P),u<1&&(d++,t(w,L<P?v:W,P,c))),P=w.length):u===0&&(d++,w=[0]),k[l++]=d,u&&w[0]?w[P++]=q[R]||0:(w=[q[R]],P=1);while((R++<_||w[0]!==void 0)&&T--);b=w[0]!==void 0}k[0]||k.shift()}if(p==1)A.e=m,Nn=b;else{for(l=1,d=k[0];d>=10;d/=10)l++;A.e=l+m*p-1,S(A,a?o+A.e+1:o,s,b)}return A}}();function S(n,e,t,i){var r,o,s,a,c,u,m,l,d,p=n.constructor;e:if(e!=null){if(l=n.d,!l)return n;for(r=1,a=l[0];a>=10;a/=10)r++;if(o=e-r,o<0)o+=N,s=e,m=l[d=0],c=m/Y(10,r-s-1)%10|0;else if(d=Math.ceil((o+1)/N),a=l.length,d>=a)if(i){for(;a++<=d;)l.push(0);m=c=0,r=1,o%=N,s=o-N+1}else break e;else{for(m=a=l[d],r=1;a>=10;a/=10)r++;o%=N,s=o-N+r,c=s<0?0:m/Y(10,r-s-1)%10|0}if(i=i||e<0||l[d+1]!==void 0||(s<0?m:m%Y(10,r-s-1)),u=t<4?(c||i)&&(t==0||t==(n.s<0?3:2)):c>5||c==5&&(t==4||i||t==6&&(o>0?s>0?m/Y(10,r-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]=Y(10,(N-e%N)%N),n.e=-e||0):l[0]=n.e=0,n;if(o==0?(l.length=d,a=1,d--):(l.length=d+1,a=Y(10,N-o),l[d]=s>0?(m/Y(10,r-s)%Y(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]==ce&&(l[0]=1));break}else{if(l[d]+=a,l[d]!=ce)break;l[d--]=0,a=1}for(o=l.length;l[--o]===0;)l.pop()}return M&&(n.e>p.maxE?(n.d=null,n.e=NaN):n.e<p.minE&&(n.e=0,n.d=[0])),n}function pe(n,e,t){if(!n.isFinite())return Dn(n);var i,r=n.e,o=$(n.d),s=o.length;return e?(t&&(i=t-s)>0?o=o.charAt(0)+"."+o.slice(1)+ke(i):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(n.e<0?"e":"e+")+n.e):r<0?(o="0."+ke(-r-1)+o,t&&(i=t-s)>0&&(o+=ke(i))):r>=s?(o+=ke(r+1-s),t&&(i=t-r-1)>0&&(o=o+"."+ke(i))):((i=r+1)<s&&(o=o.slice(0,i)+"."+o.slice(i)),t&&(i=t-s)>0&&(r+1===s&&(o+="."),o+=ke(i))),o}function gt(n,e){var t=n[0];for(e*=N;t>=10;t/=10)e++;return e}function bt(n,e,t){if(e>Ui)throw M=!0,t&&(n.precision=t),Error(Ln);return S(new n(pt),e,1,!0)}function ue(n,e,t){if(e>Xt)throw Error(Ln);return S(new n(ft),e,t,!0)}function Fn(n){var e=n.length-1,t=e*N+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 ke(n){for(var e="";n--;)e+="0";return e}function En(n,e,t,i){var r,o=new n(1),s=Math.ceil(i/N+4);for(M=!1;;){if(t%2&&(o=o.times(e),Cn(o.d,s)&&(r=!0)),t=te(t/2),t===0){t=o.d.length-1,r&&o.d[t]===0&&++o.d[t];break}e=e.times(e),Cn(e.d,s)}return M=!0,o}function Sn(n){return n.d[n.d.length-1]&1}function vn(n,e,t){for(var i,r=new n(e[0]),o=0;++o<e.length;)if(i=new n(e[o]),i.s)r[t](i)&&(r=i);else{r=i;break}return r}function zt(n,e){var t,i,r,o,s,a,c,u=0,m=0,l=0,d=n.constructor,p=d.rounding,b=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?(M=!1,c=b):c=e,a=new d(.03125);n.e>-2;)n=n.times(a),l+=5;for(i=Math.log(Y(2,l))/Math.LN10*2+5|0,c+=i,t=o=s=new d(1),d.precision=c;;){if(o=S(o.times(n),c,1),t=t.times(++m),a=s.plus(G(o,t,c,1)),$(a.d).slice(0,c)===$(s.d).slice(0,c)){for(r=l;r--;)s=S(s.times(s),c,1);if(e==null)if(u<3&&Xe(s.d,c-i,p,u))d.precision=c+=10,t=o=a=new d(1),m=0,u++;else return S(s,d.precision=b,p,M=!0);else return d.precision=b,s}s=a}}function he(n,e){var t,i,r,o,s,a,c,u,m,l,d,p=1,b=10,f=n,y=f.d,A=f.constructor,k=A.rounding,w=A.precision;if(f.s<0||!y||!y[0]||!f.e&&y[0]==1&&y.length==1)return new A(y&&!y[0]?-1/0:f.s!=1?NaN:y?0:f);if(e==null?(M=!1,m=w):m=e,A.precision=m+=b,t=$(y),i=t.charAt(0),Math.abs(o=f.e)<15e14){for(;i<7&&i!=1||i==1&&t.charAt(1)>3;)f=f.times(n),t=$(f.d),i=t.charAt(0),p++;o=f.e,i>1?(f=new A("0."+t),o++):f=new A(i+"."+t.slice(1))}else return u=bt(A,m+2,w).times(o+""),f=he(new A(i+"."+t.slice(1)),m-b).plus(u),A.precision=w,e==null?S(f,w,k,M=!0):f;for(l=f,c=s=f=G(f.minus(1),f.plus(1),m,1),d=S(f.times(f),m,1),r=3;;){if(s=S(s.times(d),m,1),u=c.plus(G(s,new A(r),m,1)),$(u.d).slice(0,m)===$(c.d).slice(0,m))if(c=c.times(2),o!==0&&(c=c.plus(bt(A,m+2,w).times(o+""))),c=G(c,new A(p),m,1),e==null)if(Xe(c.d,m-b,k,a))A.precision=m+=b,u=s=f=G(l.minus(1),l.plus(1),m,1),d=S(f.times(f),m,1),r=a=1;else return S(c,A.precision=w,k,M=!0);else return A.precision=w,c;c=u,r+=2}}function Dn(n){return String(n.s*n.s/0)}function Ht(n,e){var t,i,r;for((t=e.indexOf("."))>-1&&(e=e.replace(".","")),(i=e.search(/e/i))>0?(t<0&&(t=i),t+=+e.slice(i+1),e=e.substring(0,i)):t<0&&(t=e.length),i=0;e.charCodeAt(i)===48;i++);for(r=e.length;e.charCodeAt(r-1)===48;--r);if(e=e.slice(i,r),e){if(r-=i,n.e=t=t-i-1,n.d=[],i=(t+1)%N,t<0&&(i+=N),i<r){for(i&&n.d.push(+e.slice(0,i)),r-=N;i<r;)n.d.push(+e.slice(i,i+=N));e=e.slice(i),i=N-e.length}else i-=r;for(;i--;)e+="0";n.d.push(+e),M&&(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 zi(n,e){var t,i,r,o,s,a,c,u,m;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),On.test(e))return Ht(n,e)}else if(e==="Infinity"||e==="NaN")return+e||(n.s=NaN),n.e=NaN,n.d=null,n;if(Vi.test(e))t=16,e=e.toLowerCase();else if(Wi.test(e))t=2;else if(qi.test(e))t=8;else throw Error(Te+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,i=n.constructor,s&&(e=e.replace(".",""),a=e.length,o=a-o,r=En(i,new i(t),o,o*2)),u=dt(e,t,ce),m=u.length-1,o=m;u[o]===0;--o)u.pop();return o<0?new i(n.s*0):(n.e=gt(u,m),n.d=u,M=!1,s&&(n=G(n,r,a*4)),c&&(n=n.times(Math.abs(c)<54?Y(2,c):ze.pow(2,c))),M=!0,n)}function Hi(n,e){var t,i=e.d.length;if(i<3)return e.isZero()?e:Ee(n,2,e,e);t=1.4*Math.sqrt(i),t=t>16?16:t|0,e=e.times(1/wt(5,t)),e=Ee(n,2,e,e);for(var r,o=new n(5),s=new n(16),a=new n(20);t--;)r=e.times(e),e=e.times(o.plus(r.times(s.times(r).minus(a))));return e}function Ee(n,e,t,i,r){var o,s,a,c,u=1,m=n.precision,l=Math.ceil(m/N);for(M=!1,c=t.times(t),a=new n(i);;){if(s=G(a.times(c),new n(e++*e++),m,1),a=r?i.plus(s):i.minus(s),i=G(s.times(c),new n(e++*e++),m,1),s=a.plus(i),s.d[l]!==void 0){for(o=l;s.d[o]===a.d[o]&&o--;);if(o==-1)break}o=a,a=i,i=s,s=o,u++}return M=!0,s.d.length=l+1,s}function wt(n,e){for(var t=n;--e;)t*=n;return t}function _n(n,e){var t,i=e.s<0,r=ue(n,n.precision,1),o=r.times(.5);if(e=e.abs(),e.lte(o))return ge=i?4:1,e;if(t=e.divToInt(r),t.isZero())ge=i?3:2;else{if(e=e.minus(t.times(r)),e.lte(o))return ge=Sn(t)?i?2:3:i?4:1,e;ge=Sn(t)?i?1:4:i?3:2}return e.minus(r).abs()}function Zt(n,e,t,i){var r,o,s,a,c,u,m,l,d,p=n.constructor,b=t!==void 0;if(b?(ie(t,1,Be),i===void 0?i=p.rounding:ie(i,0,8)):(t=p.precision,i=p.rounding),!n.isFinite())m=Dn(n);else{for(m=pe(n),s=m.indexOf("."),b?(r=2,e==16?t=t*4-3:e==8&&(t=t*3-2)):r=e,s>=0&&(m=m.replace(".",""),d=new p(1),d.e=m.length-s,d.d=dt(pe(d),10,r),d.e=d.d.length),l=dt(m,10,r),o=c=l.length;l[--c]==0;)l.pop();if(!l[0])m=b?"0p+0":"0";else{if(s<0?o--:(n=new p(n),n.d=l,n.e=o,n=G(n,d,t,i,0,r),l=n.d,o=n.e,u=Nn),s=l[t],a=r/2,u=u||l[t+1]!==void 0,u=i<4?(s!==void 0||u)&&(i===0||i===(n.s<0?3:2)):s>a||s===a&&(i===4||u||i===6&&l[t-1]&1||i===(n.s<0?8:7)),l.length=t,u)for(;++l[--t]>r-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+=Gt.charAt(l[s]);if(b){if(c>1)if(e==16||e==8){for(s=e==16?4:3,--c;c%s;c++)m+="0";for(l=dt(m,r,e),c=l.length;!l[c-1];--c);for(s=1,m="1.";s<c;s++)m+=Gt.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 Cn(n,e){if(n.length>e)return n.length=e,!0}function Zi(n){return new this(n).abs()}function ji(n){return new this(n).acos()}function Yi(n){return new this(n).acosh()}function Qi(n,e){return new this(n).plus(e)}function Ji(n){return new this(n).asin()}function $i(n){return new this(n).asinh()}function er(n){return new this(n).atan()}function tr(n){return new this(n).atanh()}function nr(n,e){n=new this(n),e=new this(e);var t,i=this.precision,r=this.rounding,o=i+4;return!n.s||!e.s?t=new this(NaN):!n.d&&!e.d?(t=ue(this,o,1).times(e.s>0?.25:.75),t.s=n.s):!e.d||n.isZero()?(t=e.s<0?ue(this,i,r):new this(0),t.s=n.s):!n.d||e.isZero()?(t=ue(this,o,1).times(.5),t.s=n.s):e.s<0?(this.precision=o,this.rounding=1,t=this.atan(G(n,e,o,1)),e=ue(this,o,1),this.precision=i,this.rounding=r,t=n.s<0?t.minus(e):t.plus(e)):t=this.atan(G(n,e,o,1)),t}function ir(n){return new this(n).cbrt()}function rr(n){return S(n=new this(n),n.e+1,2)}function or(n,e,t){return new this(n).clamp(e,t)}function sr(n){if(!n||typeof n!="object")throw Error(yt+"Object expected");var e,t,i,r=n.defaults===!0,o=["precision",1,Be,"rounding",0,8,"toExpNeg",-Fe,0,"toExpPos",0,Fe,"maxE",0,Fe,"minE",-Fe,0,"modulo",0,9];for(e=0;e<o.length;e+=3)if(t=o[e],r&&(this[t]=Ut[t]),(i=n[t])!==void 0)if(te(i)===i&&i>=o[e+1]&&i<=o[e+2])this[t]=i;else throw Error(Te+t+": "+i);if(t="crypto",r&&(this[t]=Ut[t]),(i=n[t])!==void 0)if(i===!0||i===!1||i===0||i===1)if(i)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[t]=!0;else throw Error(Rn);else this[t]=!1;else throw Error(Te+t+": "+i);return this}function ar(n){return new this(n).cos()}function ur(n){return new this(n).cosh()}function Wn(n){var e,t,i;function r(o){var s,a,c,u=this;if(!(u instanceof r))return new r(o);if(u.constructor=r,Kn(o)){u.s=o.s,M?!o.d||o.e>r.maxE?(u.e=NaN,u.d=null):o.e<r.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++;M?s>r.maxE?(u.e=NaN,u.d=null):s<r.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 Ht(u,o.toString())}else if(c!=="string")throw Error(Te+o);return(a=o.charCodeAt(0))===45?(o=o.slice(1),u.s=-1):(a===43&&(o=o.slice(1)),u.s=1),On.test(o)?Ht(u,o):zi(u,o)}if(r.prototype=g,r.ROUND_UP=0,r.ROUND_DOWN=1,r.ROUND_CEIL=2,r.ROUND_FLOOR=3,r.ROUND_HALF_UP=4,r.ROUND_HALF_DOWN=5,r.ROUND_HALF_EVEN=6,r.ROUND_HALF_CEIL=7,r.ROUND_HALF_FLOOR=8,r.EUCLID=9,r.config=r.set=sr,r.clone=Wn,r.isDecimal=Kn,r.abs=Zi,r.acos=ji,r.acosh=Yi,r.add=Qi,r.asin=Ji,r.asinh=$i,r.atan=er,r.atanh=tr,r.atan2=nr,r.cbrt=ir,r.ceil=rr,r.clamp=or,r.cos=ar,r.cosh=ur,r.div=cr,r.exp=lr,r.floor=mr,r.hypot=dr,r.ln=pr,r.log=fr,r.log10=yr,r.log2=br,r.max=gr,r.min=wr,r.mod=Ar,r.mul=Pr,r.pow=kr,r.random=hr,r.round=Tr,r.sign=Br,r.sin=xr,r.sinh=Ir,r.sqrt=Sr,r.sub=Cr,r.sum=Kr,r.tan=Nr,r.tanh=Lr,r.trunc=Rr,n===void 0&&(n={}),n&&n.defaults!==!0)for(i=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<i.length;)n.hasOwnProperty(t=i[e++])||(n[t]=this[t]);return r.config(n),r}function cr(n,e){return new this(n).div(e)}function lr(n){return new this(n).exp()}function mr(n){return S(n=new this(n),n.e+1,3)}function dr(){var n,e,t=new this(0);for(M=!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 M=!0,new this(1/0);t=e}return M=!0,t.sqrt()}function Kn(n){return n instanceof ze||n&&n.toStringTag===Mn||!1}function pr(n){return new this(n).ln()}function fr(n,e){return new this(n).log(e)}function br(n){return new this(n).log(2)}function yr(n){return new this(n).log(10)}function gr(){return vn(this,arguments,"lt")}function wr(){return vn(this,arguments,"gt")}function Ar(n,e){return new this(n).mod(e)}function Pr(n,e){return new this(n).mul(e)}function kr(n,e){return new this(n).pow(e)}function hr(n){var e,t,i,r,o=0,s=new this(1),a=[];if(n===void 0?n=this.precision:ie(n,1,Be),i=Math.ceil(n/N),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(i));o<i;)r=e[o],r>=429e7?e[o]=crypto.getRandomValues(new Uint32Array(1))[0]:a[o++]=r%1e7;else if(crypto.randomBytes){for(e=crypto.randomBytes(i*=4);o<i;)r=e[o]+(e[o+1]<<8)+(e[o+2]<<16)+((e[o+3]&127)<<24),r>=214e7?crypto.randomBytes(4).copy(e,o):(a.push(r%1e7),o+=4);o=i/4}else throw Error(Rn);else for(;o<i;)a[o++]=Math.random()*1e7|0;for(i=a[--o],n%=N,i&&n&&(r=Y(10,N-n),a[o]=(i/r|0)*r);a[o]===0;o--)a.pop();if(o<0)t=0,a=[0];else{for(t=-1;a[0]===0;t-=N)a.shift();for(i=1,r=a[0];r>=10;r/=10)i++;i<N&&(t-=N-i)}return s.e=t,s.d=a,s}function Tr(n){return S(n=new this(n),n.e+1,this.rounding)}function Br(n){return n=new this(n),n.d?n.d[0]?n.s:0*n.s:n.s||NaN}function xr(n){return new this(n).sin()}function Ir(n){return new this(n).sinh()}function Sr(n){return new this(n).sqrt()}function Cr(n,e){return new this(n).sub(e)}function Kr(){var n=0,e=arguments,t=new this(e[n]);for(M=!1;t.s&&++n<e.length;)t=t.plus(e[n]);return M=!0,S(t,this.precision,this.rounding)}function Nr(n){return new this(n).tan()}function Lr(n){return new this(n).tanh()}function Rr(n){return S(n=new this(n),n.e+1,1)}g[Symbol.for("nodejs.util.inspect.custom")]=g.toString;g[Symbol.toStringTag]="Decimal";var ze=g.constructor=Wn(Ut);pt=new ze(pt);ft=new ze(ft);var Q=ze;import yo from"big.js";import Zu from"bn.js";import{get as Vn,set as Mr}from"lodash";var jt=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(i=>typeof i=="object"?JSON.stringify(i):i).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}},qn={},Or={};function J(n){let e=Vn(qn,n);if(!e){let t=Vn(Or,n);e=new jt({name:n,logLevel:t}),Mr(qn,n,e)}return e}import{MINT_SIZE as Fr,TOKEN_PROGRAM_ID as Er,getTransferFeeConfig as vr,unpackMint as Dr}from"@solana/spl-token";import{PublicKey as Gn}from"@solana/web3.js";var Yt=J("CobaltX_accountInfo_util");async function He(n,e,t){let{batchRequest:i,commitment:r="confirmed",chunkCount:o=100}={batchRequest:!1,...t},s=Qt(e,o),a=new Array(s.length).fill([]);if(i){let c=s.map(l=>{let d=n._buildArgs([l.map(p=>p.toBase58())],r,"base64");return{methodName:"getMultipleAccounts",args:d}}),u=Qt(c,10);a=(await(await Promise.all(u.map(async l=>await n._rpcBatchRequest(l)))).flat()).map(l=>(l.error&&Yt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${l.error.message}`),l.result.value.map(d=>{if(d){let{data:p,executable:b,lamports:f,owner:y,rentEpoch:A}=d;return p.length!==2&&p[1]!=="base64"&&Yt.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(p[0],"base64"),executable:b,lamports:f,owner:new Gn(y),rentEpoch:A}}return null})))}else try{a=await Promise.all(s.map(c=>n.getMultipleAccountsInfo(c,r)))}catch(c){c instanceof Error&&Yt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return a.flat()}async function Ce(n,e,t){let i=await He(n,e.map(r=>r.pubkey),t);return e.map((r,o)=>({...r,accountInfo:i[o]}))}async function Jt({connection:n,mints:e,config:t}){var o,s,a;if(e.length===0)return{};let i=await Ce(n,e.map(c=>({pubkey:Ze(c)})),t),r={};for(let c of i){if(!c.accountInfo||c.accountInfo.data.length<Fr){console.log("invalid mint account",c.pubkey.toBase58());continue}let u=Dr(c.pubkey,c.accountInfo,(o=c.accountInfo)==null?void 0:o.owner);r[c.pubkey.toString()]={...u,programId:((s=c.accountInfo)==null?void 0:s.owner)||Er,feeConfig:(a=vr(u))!=null?a:void 0}}return r[Gn.default.toBase58()]=r[oe.toBase58()],r}import je from"bn.js";var Un=9007199254740991;function fe(n){let e=J("CobaltX_parseBigNumberish");if(n instanceof je)return n;if(typeof n=="string"){if(n.match(/^-?[0-9]+$/))return new je(n);e.logWithError(`invalid BigNumberish string: ${n}`)}return typeof n=="number"?(n%1&&e.logWithError(`BigNumberish number underflow: ${n}`),(n>=Un||n<=-Un)&&e.logWithError(`BigNumberish number overflow: ${n}`),new je(String(n))):typeof n=="bigint"?new je(n.toString()):(e.error(`invalid BigNumberish value: ${n}`),new je(0))}import{TOKEN_PROGRAM_ID as Xn}from"@solana/spl-token";import{PublicKey as _r}from"@solana/web3.js";var $t={chainId:101,address:_r.default.toBase58(),programId:Xn.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"}},xe={chainId:101,address:"So11111111111111111111111111111111111111112",programId:Xn.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 nn}from"@solana/web3.js";import{PublicKey as ee,SystemProgram as zn,SYSVAR_RENT_PUBKEY as Wr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Vr}from"@solana/spl-token";function en({pubkey:n,isSigner:e=!1,isWritable:t=!0}){return{pubkey:n,isWritable:t,isSigner:e}}var Is=[en({pubkey:Vr,isWritable:!1}),en({pubkey:zn.programId,isWritable:!1}),en({pubkey:Wr,isWritable:!1})];function tn({publicKey:n,transformSol:e}){let t=Hn(n.toString());if(t instanceof ee)return e&&t.equals(Ye)?oe:t;if(e&&t.toString()===Ye.toBase58())return oe;if(typeof t=="string"){if(t===ee.default.toBase58())return ee.default;try{return new ee(t)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function Hn(n){try{return new ee(n)}catch{return n}}var qr=new ee("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),At=new ee("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Pt=new ee("SysvarRent111111111111111111111111111111111"),Ss=new ee("SysvarC1ock11111111111111111111111111111111"),ve=new ee("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Cs=new ee("Sysvar1nstructions1111111111111111111111111"),Zn=zn.programId,Ks=new ee("a2Gt18uJC8puJT9JRYQLU6rPi6okxQb4WqCjwtYshZB"),Ns=new ee("bXSKiFqYrALF9gJy1KqHm8tv4QXk8nCgbLN8WRsGEbh"),oe=new ee("So11111111111111111111111111111111111111112"),Ye=ee.default,Ls=new ee("71kRXzJMvSeArtXYNEWa8KAjpRJosdMQ7Dpgy5Jt5zfd"),Rs=new ee("ERFzpDteGNo8LTDKW1WwVGrkRMmA2y9WZHXNHxMA6BSV");function Ze(n){return tn({publicKey:n,transformSol:!0})}var rn=class{constructor({mint:e,decimals:t,symbol:i,name:r,skipMint:o=!1,isToken2022:s=!1}){if(e===Ye.toBase58()||e instanceof nn&&Ye.equals(e)){this.decimals=xe.decimals,this.symbol=xe.symbol,this.name=xe.name,this.mint=new nn(xe.address),this.isToken2022=!1;return}this.decimals=t,this.symbol=i||e.toString().substring(0,6),this.name=r||e.toString().substring(0,6),this.mint=o?nn.default:tn({publicKey:e}),this.isToken2022=s}equals(e){return this===e?!0:this.mint.equals(e.mint)}},Ie=rn;Ie.WSOL=new rn({...xe,mint:xe.address});var on=class{constructor({decimals:e,symbol:t="UNKNOWN",name:i="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=i}equals(e){return this===e}},kt=on;kt.SOL=new on($t);import Gr from"toformat";var Ur=Gr,Qe=Ur;import Tt from"big.js";import zr from"bn.js";import Hr from"decimal.js-light";var ht=J("module/fraction"),sn=Qe(Tt),Je=Qe(Hr),Zr={[0]:Je.ROUND_DOWN,[1]:Je.ROUND_HALF_UP,[2]:Je.ROUND_UP},jr={[0]:Tt.roundDown,[1]:Tt.roundHalfUp,[2]:Tt.roundUp},X=class{constructor(e,t=new zr(1)){this.numerator=fe(e),this.denominator=fe(t)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new X(this.denominator,this.numerator)}add(e){let t=e instanceof X?e:new X(fe(e));return this.denominator.eq(t.denominator)?new X(this.numerator.add(t.numerator),this.denominator):new X(this.numerator.mul(t.denominator).add(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}sub(e){let t=e instanceof X?e:new X(fe(e));return this.denominator.eq(t.denominator)?new X(this.numerator.sub(t.numerator),this.denominator):new X(this.numerator.mul(t.denominator).sub(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}mul(e){let t=e instanceof X?e:new X(fe(e));return new X(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof X?e:new X(fe(e));return new X(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},i=1){Number.isInteger(e)||ht.logWithError(`${e} is not an integer.`),e<=0&&ht.logWithError(`${e} is not positive.`),Je.set({precision:e+1,rounding:Zr[i]});let r=new Je(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return r.toFormat(r.decimalPlaces(),t)}toFixed(e,t={groupSeparator:""},i=1){return Number.isInteger(e)||ht.logWithError(`${e} is not an integer.`),e<0&&ht.logWithError(`${e} is negative.`),sn.DP=e,sn.RM=jr[i]||1,new sn(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};import Yr from"bn.js";var jn=new X(new Yr(100)),se=class extends X{toSignificant(e=5,t,i){return this.mul(jn).toSignificant(e,t,i)}toFixed(e=2,t,i){return this.mul(jn).toFixed(e,t,i)}};var oa=J("CobaltX_price");function Qt(n,e=1,t=[]){let i=[...n];if(e<=0)return t;for(;i.length;)t.push(i.splice(0,e));return t}import{PublicKey as io}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ro}from"@solana/spl-token";import{ComputeBudgetProgram as Yn,Keypair as Jn,PublicKey as Qr,Transaction as $n,TransactionMessage as Jr,VersionedTransaction as ei}from"@solana/web3.js";var re={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 $r}from"@solana/spl-token";var Qn=J("CobaltX_txUtil"),ti=1644;function xt(n){let e=[],t=[];return n.microLamports&&(e.push(Yn.setComputeUnitPrice({microLamports:n.microLamports})),t.push(re.SetComputeUnitPrice)),n.units&&(e.push(Yn.setComputeUnitLimit({units:n.units})),t.push(re.SetComputeUnitLimit)),{instructions:e,instructionTypes:t}}async function De(n,e){var i,r;let t=e!=null?e:"confirmed";return(r=await((i=n.getLatestBlockhash)==null?void 0:i.call(n,{commitment:t})))==null?void 0:r.blockhash}async function It(n,e){return n.getSignatureStatuses([e]),new Promise((t,i)=>{let r=setTimeout(i,6e4);n.onSignature(e,o=>{if(clearTimeout(r),!o.err){t("");return}i(o.err.toString())},"confirmed")})}function eo(n,e){n.length<1&&Qn.logWithError(`no instructions provided: ${n.toString()}`),e.length<1&&Qn.logWithError(`no signers provided:, ${e.toString()}`);let t=new $n;t.recentBlockhash="11111111111111111111111111111111",t.feePayer=e[0],t.add(...n);try{return Buffer.from(t.serialize({verifySignatures:!1})).toString("base64").length<ti}catch{return!1}}function le(n,e){let[t,i]=Qr.findProgramAddressSync(n,e);return{publicKey:t,nonce:i}}function $e({instructions:n,payer:e,signers:t}){return eo(n,[e,...t])}function et({instructions:n,payer:e,lookupTableAddressAccount:t,recentBlockhash:i=Jn.generate().publicKey.toString()}){let o=new Jr({payerKey:e,recentBlockhash:i,instructions:n}).compileToV0Message(Object.values(t!=null?t:{}));try{return Buffer.from(new ei(o).serialize()).toString("base64").length<ti}catch{return!1}}var to=n=>Buffer.isBuffer(n)?n:n instanceof Uint8Array?Buffer.from(n.buffer,n.byteOffset,n.byteLength):Buffer.from(n),no=n=>{let e=n.serialize({requireAllSignatures:!1,verifySignatures:!1});n instanceof ei&&(e=to(e));try{return e instanceof Buffer?e.toString("base64"):Buffer.from(e).toString("base64")}catch{return e.toString("base64")}};function Ke(n){let e=[];return n.forEach(t=>{t instanceof $n&&(t.recentBlockhash||(t.recentBlockhash=$r.toBase58()),t.feePayer||(t.feePayer=Jn.generate().publicKey)),e.push(no(t))}),console.log("simulate tx string:",e),e}function be(n,e,t){return le([n.toBuffer(),(t!=null?t:ro).toBuffer(),e.toBuffer()],new io("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}import{PublicKey as F}from"@solana/web3.js";var _a=new F("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),Wa=new F("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),Va=new F("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),qa=new F("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Ga=new F("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),Ua=new F("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),Xa=new F("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),za=new F("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Ha=new F("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Za=new F("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),oo=new F("2TnjBuwqyBB9to5jURagDT7jLmBPefGRiKL2yh1zPZ4V"),so=new F("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),ao=new F("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),ja=new F("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Ya=new F("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Qa=new F("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Ja=new F("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),$a=new F("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),eu=new F("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),ni=new F("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),ii=new F("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),tu=new F("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),uo=new F("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),co=new F("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),lo=new F("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),St=new F("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),mo=new F("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),Ct=new F("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),po=new F("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix");var nu={SERUM_MARKET:F.default,OPENBOOK_MARKET:new F("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:F.default,FarmV3:new F("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new F("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new F("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new F("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new F("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new F("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),CLMM_LOCK_PROGRAM_ID:new F("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),CLMM_LOCK_AUTH_ID:new F("8qmHNvu2Kr2C7U8mJL4Vz1vTDxMhVuXKREwU7TNoaVEo"),Router:new F("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:uo,CREATE_CPMM_POOL_AUTH:co,CREATE_CPMM_POOL_FEE_ACC:lo,FEE_DESTINATION_ID:new F("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),LOCK_CPMM_PROGRAM:mo,LCOK_CPMM_AUTH:po};import me from"bn.js";var tt=1e4;function ye(n,e,t,i){if(e===void 0)return{amount:n,fee:void 0,expirationTime:void 0};let r={...e,olderTransferFee:{epoch:BigInt(e.olderTransferFee.epoch),maximumFee:BigInt(e.olderTransferFee.maximumFee),transferFeeBasisPoints:e.olderTransferFee.transferFeeBasisPoints},newerTransferFee:{epoch:BigInt(e.newerTransferFee.epoch),maximumFee:BigInt(e.newerTransferFee.maximumFee),transferFeeBasisPoints:e.newerTransferFee.transferFeeBasisPoints}},o=t.epoch<r.newerTransferFee.epoch?r.olderTransferFee:r.newerTransferFee,s=new me(o.maximumFee.toString()),a=t.epoch<r.newerTransferFee.epoch?(Number(r.newerTransferFee.epoch)*t.slotsInEpoch-t.absoluteSlot)*400/1e3:void 0;if(i)if(o.transferFeeBasisPoints===tt){let c=new me(o.maximumFee.toString());return{amount:n.add(c),fee:c,expirationTime:a}}else{let c=_e(n.mul(new me(tt)),new me(tt-o.transferFeeBasisPoints)),u=new me(o.maximumFee.toString()),m=c.sub(n).gt(u)?n.add(u):c,l=_e(m.mul(new me(o.transferFeeBasisPoints)),new me(tt)),d=l.gt(s)?s:l;return{amount:m,fee:d,expirationTime:a}}else{let c=_e(n.mul(new me(o.transferFeeBasisPoints)),new me(tt)),u=c.gt(s)?s:c;return{amount:n,fee:u,expirationTime:a}}}function _e(n,e){let{div:t,mod:i}=n.divmod(e);return i.gt(new me(0))?t.add(new me(1)):t}import{PublicKey as ri,AddressLookupTableAccount as Kt}from"@solana/web3.js";async function cn({connection:n,address:e}){let t=await He(n,[...new Set(e.map(r=>r.toString()))].map(r=>new ri(r))),i={};for(let r=0;r<e.length;r++){let o=t[r],s=e[r];if(!o)continue;let a=new Kt({key:s,state:Kt.deserialize(o.data)});i[s.toString()]=a,Nt[s.toString()]=a}return i}var Nt={AiAibtFJts8e4W1FjWYRH34aBJkJqghdmXiJozK7MvTM:new Kt({key:new ri("AiAibtFJts8e4W1FjWYRH34aBJkJqghdmXiJozK7MvTM"),state:Kt.deserialize(Buffer.from("AQAAAP//////////d49+DAAAAAAAAQZMWvw7GUNJdaccNBVnb57OKakxL2BHLYvhRwVILRsgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMGRm/lIRcy/+ytunLDm+e8jOW7xfcSayxDmzpAAAAABt324ddloZPZy+FGzut5rBy0he1fWzeROoz1hX7/AKkG3fbh7nWP3hhCXbzkbM3athr8TYO5DSf+vfko2KGL/AVKU1D4XciC1hSlVnJ4iilt3x6rq9CmBniISTL07vagBqfVFxksXFEhjMlMPUrxf1ja7gibof1E49vZigAAAAAGp9UXGMd0yShWY5hpHV62i164o5tLbVxzVVshAAAAAIyXJY9OJInxuz0QKRSODYMLWhOZ2v8QhASOe9jb6fhZC3BlsePRfEU4nVJ/awTDzVi4bHMaoP21SbbRvAP4KUbIScv+6Yw2LHF/6K0ZjUPibbSWXCirYPGuuVl7zT789IUPLW4CpHr4JNCatp3ELXDLKMv6JJ+37le50lbBJ2LvDQdRqCgtphMF/imcN7mY5YRx2xE1A3MQ+L4QRaYK9u4GRfZP3LsAd00a+IkCpA22UNQMKdq5BFbJuwuOLqc8zxCTDlqxBG8J0HcxtfogQHDK0