@cobaltx/sdk-v2
Version:
An SDK for building applications on top of CobaltX.
1 lines • 60.2 kB
JavaScript
import{MINT_SIZE as Rr,TOKEN_PROGRAM_ID as Mr,getTransferFeeConfig as Or,unpackMint as Fr}from"@solana/spl-token";import{PublicKey as vr}from"@solana/web3.js";import{get as Kt,set as In}from"lodash";var it=class{constructor(t){this.logLevel=t.logLevel!==void 0?t.logLevel:0,this.name=t.name}set level(t){this.logLevel=t}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(t){return t<=this.logLevel}error(...t){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...t),this):this}logWithError(...t){let n=t.map(i=>typeof i=="object"?JSON.stringify(i):i).join(", ");throw new Error(n)}warning(...t){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...t),this):this}info(...t){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...t),this):this}debug(...t){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...t),this):this}},Ct={},Sn={};function W(e){let t=Kt(Ct,e);if(!t){let n=Kt(Sn,e);t=new it({name:e,logLevel:n}),In(Ct,e,t)}return t}var Gr=W("CobaltX_accountInfo_util");import $ from"bn.js";var pe=9e15,re=1e9,rt="0123456789abcdef",De="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",ve="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",ot={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-pe,maxE:pe,crypto:!1},Ot,J,h=!0,qe="[DecimalError] ",ie=qe+"Invalid argument: ",Ft=qe+"Precision limit exceeded",Et=qe+"crypto unavailable",Wt="[object Decimal]",V=Math.floor,E=Math.pow,Kn=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Cn=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Nn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,_t=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,j=1e7,g=7,Ln=9007199254740991,Rn=De.length-1,st=ve.length-1,p={toStringTag:Wt};p.absoluteValue=p.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),y(e)};p.ceil=function(){return y(new this.constructor(this),this.e+1,2)};p.clampedTo=p.clamp=function(e,t){var n,i=this,r=i.constructor;if(e=new r(e),t=new r(t),!e.s||!t.s)return new r(NaN);if(e.gt(t))throw Error(ie+t);return n=i.cmp(e),n<0?e:i.cmp(t)>0?t:new r(i)};p.comparedTo=p.cmp=function(e){var t,n,i,r,o=this,s=o.d,a=(e=new o.constructor(e)).d,c=o.s,u=e.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!==e.e)return o.e>e.e^c<0?1:-1;for(i=s.length,r=a.length,t=0,n=i<r?i:r;t<n;++t)if(s[t]!==a[t])return s[t]>a[t]^c<0?1:-1;return i===r?0:i>r^c<0?1:-1};p.cosine=p.cos=function(){var e,t,n=this,i=n.constructor;return n.d?n.d[0]?(e=i.precision,t=i.rounding,i.precision=e+Math.max(n.e,n.sd())+g,i.rounding=1,n=Mn(i,Gt(i,n)),i.precision=e,i.rounding=t,y(J==2||J==3?n.neg():n,e,t,!0)):new i(1):new i(NaN)};p.cubeRoot=p.cbrt=function(){var e,t,n,i,r,o,s,a,c,u,l=this,m=l.constructor;if(!l.isFinite()||l.isZero())return new m(l);for(h=!1,o=l.s*E(l.s*l,1/3),!o||Math.abs(o)==1/0?(n=_(l.d),e=l.e,(o=(e-n.length+1)%3)&&(n+=o==1||o==-2?"0":"00"),o=E(n,1/3),e=V((e+1)/3)-(e%3==(e<0?-1:2)),o==1/0?n="5e"+e:(n=o.toExponential(),n=n.slice(0,n.indexOf("e")+1)+e),i=new m(n),i.s=l.s):i=new m(o.toString()),s=(e=m.precision)+3;;)if(a=i,c=a.times(a).times(a),u=c.plus(l),i=K(u.plus(l).times(a),u.plus(c),s+2,1),_(a.d).slice(0,s)===(n=_(i.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!r&&n=="4999"){if(!r&&(y(a,e+1,0),a.times(a).times(a).eq(l))){i=a;break}s+=4,r=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(y(i,e+1,1),t=!i.times(i).times(i).eq(l));break}return h=!0,y(i,e,m.rounding,t)};p.decimalPlaces=p.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-V(this.e/g))*g,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n};p.dividedBy=p.div=function(e){return K(this,new this.constructor(e))};p.dividedToIntegerBy=p.divToInt=function(e){var t=this,n=t.constructor;return y(K(t,new n(e),0,1,1),n.precision,n.rounding)};p.equals=p.eq=function(e){return this.cmp(e)===0};p.floor=function(){return y(new this.constructor(this),this.e+1,3)};p.greaterThan=p.gt=function(e){return this.cmp(e)>0};p.greaterThanOrEqualTo=p.gte=function(e){var t=this.cmp(e);return t==1||t===0};p.hyperbolicCosine=p.cosh=function(){var e,t,n,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;n=s.precision,i=s.rounding,s.precision=n+Math.max(o.e,o.sd())+4,s.rounding=1,r=o.d.length,r<32?(e=Math.ceil(r/3),t=(1/Ue(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),o=fe(s,1,o.times(t),new s(1),!0);for(var c,u=e,l=new s(8);u--;)c=o.times(o),o=a.minus(c.times(l.minus(c.times(l))));return y(o,s.precision=n,s.rounding=i,!0)};p.hyperbolicSine=p.sinh=function(){var e,t,n,i,r=this,o=r.constructor;if(!r.isFinite()||r.isZero())return new o(r);if(t=o.precision,n=o.rounding,o.precision=t+Math.max(r.e,r.sd())+4,o.rounding=1,i=r.d.length,i<3)r=fe(o,2,r,r,!0);else{e=1.4*Math.sqrt(i),e=e>16?16:e|0,r=r.times(1/Ue(5,e)),r=fe(o,2,r,r,!0);for(var s,a=new o(5),c=new o(16),u=new o(20);e--;)s=r.times(r),r=r.times(a.plus(s.times(c.times(s).plus(u))))}return o.precision=t,o.rounding=n,y(r,t,n,!0)};p.hyperbolicTangent=p.tanh=function(){var e,t,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+7,i.rounding=1,K(n.sinh(),n.cosh(),i.precision=e,i.rounding=t)):new i(n.s)};p.inverseCosine=p.acos=function(){var e,t=this,n=t.constructor,i=t.abs().cmp(1),r=n.precision,o=n.rounding;return i!==-1?i===0?t.isNeg()?Z(n,r,o):new n(0):new n(NaN):t.isZero()?Z(n,r+4,o).times(.5):(n.precision=r+6,n.rounding=1,t=t.asin(),e=Z(n,r+4,o).times(.5),n.precision=r,n.rounding=o,e.minus(t))};p.inverseHyperbolicCosine=p.acosh=function(){var e,t,n=this,i=n.constructor;return n.lte(1)?new i(n.eq(1)?0:NaN):n.isFinite()?(e=i.precision,t=i.rounding,i.precision=e+Math.max(Math.abs(n.e),n.sd())+4,i.rounding=1,h=!1,n=n.times(n).minus(1).sqrt().plus(n),h=!0,i.precision=e,i.rounding=t,n.ln()):new i(n)};p.inverseHyperbolicSine=p.asinh=function(){var e,t,n=this,i=n.constructor;return!n.isFinite()||n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,i.rounding=1,h=!1,n=n.times(n).plus(1).sqrt().plus(n),h=!0,i.precision=e,i.rounding=t,n.ln())};p.inverseHyperbolicTangent=p.atanh=function(){var e,t,n,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):(e=o.precision,t=o.rounding,i=r.sd(),Math.max(i,e)<2*-r.e-1?y(new o(r),e,t,!0):(o.precision=n=i-r.e,r=K(r.plus(1),new o(1).minus(r),n+e,1),o.precision=e+4,o.rounding=1,r=r.ln(),o.precision=e,o.rounding=t,r.times(.5))):new o(NaN)};p.inverseSine=p.asin=function(){var e,t,n,i,r=this,o=r.constructor;return r.isZero()?new o(r):(t=r.abs().cmp(1),n=o.precision,i=o.rounding,t!==-1?t===0?(e=Z(o,n+4,i).times(.5),e.s=r.s,e):new o(NaN):(o.precision=n+6,o.rounding=1,r=r.div(new o(1).minus(r.times(r)).sqrt().plus(1)).atan(),o.precision=n,o.rounding=i,r.times(2)))};p.inverseTangent=p.atan=function(){var e,t,n,i,r,o,s,a,c,u=this,l=u.constructor,m=l.precision,d=l.rounding;if(u.isFinite()){if(u.isZero())return new l(u);if(u.abs().eq(1)&&m+4<=st)return s=Z(l,m+4,d).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(m+4<=st)return s=Z(l,m+4,d).times(.5),s.s=u.s,s}for(l.precision=a=m+10,l.rounding=1,n=Math.min(28,a/g+2|0),e=n;e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(h=!1,t=Math.ceil(a/g),i=1,c=u.times(u),s=new l(u),r=u;e!==-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[t]!==void 0)for(e=t;s.d[e]===o.d[e]&&e--;);return n&&(s=s.times(2<<n-1)),h=!0,y(s,l.precision=m,l.rounding=d,!0)};p.isFinite=function(){return!!this.d};p.isInteger=p.isInt=function(){return!!this.d&&V(this.e/g)>this.d.length-2};p.isNaN=function(){return!this.s};p.isNegative=p.isNeg=function(){return this.s<0};p.isPositive=p.isPos=function(){return this.s>0};p.isZero=function(){return!!this.d&&this.d[0]===0};p.lessThan=p.lt=function(e){return this.cmp(e)<0};p.lessThanOrEqualTo=p.lte=function(e){return this.cmp(e)<1};p.logarithm=p.log=function(e){var t,n,i,r,o,s,a,c,u=this,l=u.constructor,m=l.precision,d=l.rounding,f=5;if(e==null)e=new l(10),t=!0;else{if(e=new l(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new l(NaN);t=e.eq(10)}if(n=u.d,u.s<0||!n||!n[0]||u.eq(1))return new l(n&&!n[0]?-1/0:u.s!=1?NaN:n?0:1/0);if(t)if(n.length>1)o=!0;else{for(r=n[0];r%10===0;)r/=10;o=r!==1}if(h=!1,a=m+f,s=ne(u,a),i=t?Ve(l,a+10):ne(e,a),c=K(s,i,a,1),Ae(c.d,r=m,d))do if(a+=10,s=ne(u,a),i=t?Ve(l,a+10):ne(e,a),c=K(s,i,a,1),!o){+_(c.d).slice(r+1,r+15)+1==1e14&&(c=y(c,m+1,0));break}while(Ae(c.d,r+=10,d));return h=!0,y(c,m,d)};p.minus=p.sub=function(e){var t,n,i,r,o,s,a,c,u,l,m,d,f=this,w=f.constructor;if(e=new w(e),!f.d||!e.d)return!f.s||!e.s?e=new w(NaN):f.d?e.s=-e.s:e=new w(e.d||f.s!==e.s?f:NaN),e;if(f.s!=e.s)return e.s=-e.s,f.plus(e);if(u=f.d,d=e.d,a=w.precision,c=w.rounding,!u[0]||!d[0]){if(d[0])e.s=-e.s;else if(u[0])e=new w(f);else return new w(c===3?-0:0);return h?y(e,a,c):e}if(n=V(e.e/g),l=V(f.e/g),u=u.slice(),o=l-n,o){for(m=o<0,m?(t=u,o=-o,s=d.length):(t=d,n=l,s=u.length),i=Math.max(Math.ceil(a/g),s)+2,o>i&&(o=i,t.length=1),t.reverse(),i=o;i--;)t.push(0);t.reverse()}else{for(i=u.length,s=d.length,m=i<s,m&&(s=i),i=0;i<s;i++)if(u[i]!=d[i]){m=u[i]<d[i];break}o=0}for(m&&(t=u,u=d,d=t,e.s=-e.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]=j-1;--u[r],u[i]+=j}u[i]-=d[i]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--n;return u[0]?(e.d=u,e.e=Ge(u,n),h?y(e,a,c):e):new w(c===3?-0:0)};p.modulo=p.mod=function(e){var t,n=this,i=n.constructor;return e=new i(e),!n.d||!e.s||e.d&&!e.d[0]?new i(NaN):!e.d||n.d&&!n.d[0]?y(new i(n),i.precision,i.rounding):(h=!1,i.modulo==9?(t=K(n,e.abs(),0,3,1),t.s*=e.s):t=K(n,e,0,i.modulo,1),t=t.times(e),h=!0,n.minus(t))};p.naturalExponential=p.exp=function(){return at(this)};p.naturalLogarithm=p.ln=function(){return ne(this)};p.negated=p.neg=function(){var e=new this.constructor(this);return e.s=-e.s,y(e)};p.plus=p.add=function(e){var t,n,i,r,o,s,a,c,u,l,m=this,d=m.constructor;if(e=new d(e),!m.d||!e.d)return!m.s||!e.s?e=new d(NaN):m.d||(e=new d(e.d||m.s===e.s?m:NaN)),e;if(m.s!=e.s)return e.s=-e.s,m.minus(e);if(u=m.d,l=e.d,a=d.precision,c=d.rounding,!u[0]||!l[0])return l[0]||(e=new d(m)),h?y(e,a,c):e;if(o=V(m.e/g),i=V(e.e/g),u=u.slice(),r=o-i,r){for(r<0?(n=u,r=-r,s=l.length):(n=l,i=o,s=u.length),o=Math.ceil(a/g),s=o>s?o+1:s+1,r>s&&(r=s,n.length=1),n.reverse();r--;)n.push(0);n.reverse()}for(s=u.length,r=l.length,s-r<0&&(r=s,n=l,l=u,u=n),t=0;r;)t=(u[--r]=u[r]+l[r]+t)/j|0,u[r]%=j;for(t&&(u.unshift(t),++i),s=u.length;u[--s]==0;)u.pop();return e.d=u,e.e=Ge(u,i),h?y(e,a,c):e};p.precision=p.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(ie+e);return n.d?(t=Dt(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t};p.round=function(){var e=this,t=e.constructor;return y(new t(e),e.e+1,t.rounding)};p.sine=p.sin=function(){var e,t,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+Math.max(n.e,n.sd())+g,i.rounding=1,n=Fn(i,Gt(i,n)),i.precision=e,i.rounding=t,y(J>2?n.neg():n,e,t,!0)):new i(NaN)};p.squareRoot=p.sqrt=function(){var e,t,n,i,r,o,s=this,a=s.d,c=s.e,u=s.s,l=s.constructor;if(u!==1||!a||!a[0])return new l(!u||u<0&&(!a||a[0])?NaN:a?s:1/0);for(h=!1,u=Math.sqrt(+s),u==0||u==1/0?(t=_(a),(t.length+c)%2==0&&(t+="0"),u=Math.sqrt(t),c=V((c+1)/2)-(c<0||c%2),u==1/0?t="5e"+c:(t=u.toExponential(),t=t.slice(0,t.indexOf("e")+1)+c),i=new l(t)):i=new l(u.toString()),n=(c=l.precision)+3;;)if(o=i,i=o.plus(K(s,o,n+2,1)).times(.5),_(o.d).slice(0,n)===(t=_(i.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!r&&t=="4999"){if(!r&&(y(o,c+1,0),o.times(o).eq(s))){i=o;break}n+=4,r=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(y(i,c+1,1),e=!i.times(i).eq(s));break}return h=!0,y(i,c,l.rounding,e)};p.tangent=p.tan=function(){var e,t,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+10,i.rounding=1,n=n.sin(),n.s=1,n=K(n,new i(1).minus(n.times(n)).sqrt(),e+10,0),i.precision=e,i.rounding=t,y(J==2||J==4?n.neg():n,e,t,!0)):new i(NaN)};p.times=p.mul=function(e){var t,n,i,r,o,s,a,c,u,l=this,m=l.constructor,d=l.d,f=(e=new m(e)).d;if(e.s*=l.s,!d||!d[0]||!f||!f[0])return new m(!e.s||d&&!d[0]&&!f||f&&!f[0]&&!d?NaN:!d||!f?e.s/0:e.s*0);for(n=V(l.e/g)+V(e.e/g),c=d.length,u=f.length,c<u&&(o=d,d=f,f=o,s=c,c=u,u=s),o=[],s=c+u,i=s;i--;)o.push(0);for(i=u;--i>=0;){for(t=0,r=c+i;r>i;)a=o[r]+f[i]*d[r-i-1]+t,o[r--]=a%j|0,t=a/j|0;o[r]=(o[r]+t)%j|0}for(;!o[--s];)o.pop();return t?++n:o.shift(),e.d=o,e.e=Ge(o,n),h?y(e,m.precision,m.rounding):e};p.toBinary=function(e,t){return ct(this,2,e,t)};p.toDecimalPlaces=p.toDP=function(e,t){var n=this,i=n.constructor;return n=new i(n),e===void 0?n:(G(e,0,re),t===void 0?t=i.rounding:G(t,0,8),y(n,e+n.e+1,t))};p.toExponential=function(e,t){var n,i=this,r=i.constructor;return e===void 0?n=Y(i,!0):(G(e,0,re),t===void 0?t=r.rounding:G(t,0,8),i=y(new r(i),e+1,t),n=Y(i,!0,e+1)),i.isNeg()&&!i.isZero()?"-"+n:n};p.toFixed=function(e,t){var n,i,r=this,o=r.constructor;return e===void 0?n=Y(r):(G(e,0,re),t===void 0?t=o.rounding:G(t,0,8),i=y(new o(r),e+r.e+1,t),n=Y(i,!1,e+i.e+1)),r.isNeg()&&!r.isZero()?"-"+n:n};p.toFraction=function(e){var t,n,i,r,o,s,a,c,u,l,m,d,f=this,w=f.d,b=f.constructor;if(!w)return new b(f);if(u=n=new b(1),i=c=new b(0),t=new b(i),o=t.e=Dt(w)-f.e-1,s=o%g,t.d[0]=E(10,s<0?g+s:s),e==null)e=o>0?t:u;else{if(a=new b(e),!a.isInt()||a.lt(u))throw Error(ie+a);e=a.gt(t)?o>0?t:u:a}for(h=!1,a=new b(_(w)),l=b.precision,b.precision=o=w.length*g*2;m=K(a,t,0,1,1),r=n.plus(m.times(i)),r.cmp(e)!=1;)n=i,i=r,r=u,u=c.plus(m.times(r)),c=r,r=t,t=a.minus(m.times(r)),a=r;return r=K(e.minus(n),i,0,1,1),c=c.plus(r.times(u)),n=n.plus(r.times(i)),c.s=u.s=f.s,d=K(u,i,o,1).minus(f).abs().cmp(K(c,n,o,1).minus(f).abs())<1?[u,i]:[c,n],b.precision=l,h=!0,d};p.toHexadecimal=p.toHex=function(e,t){return ct(this,16,e,t)};p.toNearest=function(e,t){var n=this,i=n.constructor;if(n=new i(n),e==null){if(!n.d)return n;e=new i(1),t=i.rounding}else{if(e=new i(e),t===void 0?t=i.rounding:G(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&(e.s=n.s),e}return e.d[0]?(h=!1,n=K(n,e,0,t,1).times(e),h=!0,y(n)):(e.s=n.s,n=e),n};p.toNumber=function(){return+this};p.toOctal=function(e,t){return ct(this,8,e,t)};p.toPower=p.pow=function(e){var t,n,i,r,o,s,a=this,c=a.constructor,u=+(e=new c(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new c(E(+a,u));if(a=new c(a),a.eq(1))return a;if(i=c.precision,o=c.rounding,e.eq(1))return y(a,i,o);if(t=V(e.e/g),t>=e.d.length-1&&(n=u<0?-u:u)<=Ln)return r=vt(c,a,n,i),e.s<0?new c(1).div(r):y(r,i,o);if(s=a.s,s<0){if(t<e.d.length-1)return new c(NaN);if((e.d[t]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return n=E(+a,u),t=n==0||!isFinite(n)?V(u*(Math.log("0."+_(a.d))/Math.LN10+a.e+1)):new c(n+"").e,t>c.maxE+1||t<c.minE-1?new c(t>0?s/0:0):(h=!1,c.rounding=a.s=1,n=Math.min(12,(t+"").length),r=at(e.times(ne(a,i+n)),i),r.d&&(r=y(r,i+5,1),Ae(r.d,i,o)&&(t=i+10,r=y(at(e.times(ne(a,t+n)),t),t+5,1),+_(r.d).slice(i+1,i+15)+1==1e14&&(r=y(r,i+1,0)))),r.s=s,h=!0,c.rounding=o,y(r,i,o))};p.toPrecision=function(e,t){var n,i=this,r=i.constructor;return e===void 0?n=Y(i,i.e<=r.toExpNeg||i.e>=r.toExpPos):(G(e,1,re),t===void 0?t=r.rounding:G(t,0,8),i=y(new r(i),e,t),n=Y(i,e<=i.e||i.e<=r.toExpNeg,e)),i.isNeg()&&!i.isZero()?"-"+n:n};p.toSignificantDigits=p.toSD=function(e,t){var n=this,i=n.constructor;return e===void 0?(e=i.precision,t=i.rounding):(G(e,1,re),t===void 0?t=i.rounding:G(t,0,8)),y(new i(n),e,t)};p.toString=function(){var e=this,t=e.constructor,n=Y(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n};p.truncated=p.trunc=function(){return y(new this.constructor(this),this.e+1,1)};p.valueOf=p.toJSON=function(){var e=this,t=e.constructor,n=Y(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function _(e){var t,n,i,r=e.length-1,o="",s=e[0];if(r>0){for(o+=s,t=1;t<r;t++)i=e[t]+"",n=g-i.length,n&&(o+=te(n)),o+=i;s=e[t],i=s+"",n=g-i.length,n&&(o+=te(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function G(e,t,n){if(e!==~~e||e<t||e>n)throw Error(ie+e)}function Ae(e,t,n,i){var r,o,s,a;for(o=e[0];o>=10;o/=10)--t;return--t<0?(t+=g,r=0):(r=Math.ceil((t+1)/g),t%=g),o=E(10,g-t),a=e[r]%o|0,i==null?t<3?(t==0?a=a/100|0:t==1&&(a=a/10|0),s=n<4&&a==99999||n>3&&a==49999||a==5e4||a==0):s=(n<4&&a+1==o||n>3&&a+1==o/2)&&(e[r+1]/o/100|0)==E(10,t-2)-1||(a==o/2||a==0)&&(e[r+1]/o/100|0)==0:t<4?(t==0?a=a/1e3|0:t==1?a=a/100|0:t==2&&(a=a/10|0),s=(i||n<4)&&a==9999||!i&&n>3&&a==4999):s=((i||n<4)&&a+1==o||!i&&n>3&&a+1==o/2)&&(e[r+1]/o/1e3|0)==E(10,t-3)-1,s}function _e(e,t,n){for(var i,r=[0],o,s=0,a=e.length;s<a;){for(o=r.length;o--;)r[o]*=t;for(r[0]+=rt.indexOf(e.charAt(s++)),i=0;i<r.length;i++)r[i]>n-1&&(r[i+1]===void 0&&(r[i+1]=0),r[i+1]+=r[i]/n|0,r[i]%=n)}return r.reverse()}function Mn(e,t){var n,i,r;if(t.isZero())return t;i=t.d.length,i<32?(n=Math.ceil(i/3),r=(1/Ue(4,n)).toString()):(n=16,r="2.3283064365386962890625e-10"),e.precision+=n,t=fe(e,1,t.times(r),new e(1));for(var o=n;o--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return e.precision-=n,t}var K=function(){function e(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 t(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 n(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,l,m,d,f,w,b,x,B,N,I,F,me,H,de,Oe,ke,tt,z,Fe,Ee=i.constructor,nt=i.s==r.s?1:-1,v=i.d,C=r.d;if(!v||!v[0]||!C||!C[0])return new Ee(!i.s||!r.s||(v?C&&v[0]==C[0]:!C)?NaN:v&&v[0]==0||!C?nt*0:nt/0);for(c?(f=1,l=i.e-r.e):(c=j,f=g,l=V(i.e/f)-V(r.e/f)),z=C.length,ke=v.length,B=new Ee(nt),N=B.d=[],m=0;C[m]==(v[m]||0);m++);if(C[m]>(v[m]||0)&&l--,o==null?(H=o=Ee.precision,s=Ee.rounding):a?H=o+(i.e-r.e)+1:H=o,H<0)N.push(1),w=!0;else{if(H=H/f+2|0,m=0,z==1){for(d=0,C=C[0],H++;(m<ke||d)&&H--;m++)de=d*c+(v[m]||0),N[m]=de/C|0,d=de%C|0;w=d||m<ke}else{for(d=c/(C[0]+1)|0,d>1&&(C=e(C,d,c),v=e(v,d,c),z=C.length,ke=v.length),Oe=z,I=v.slice(0,z),F=I.length;F<z;)I[F++]=0;Fe=C.slice(),Fe.unshift(0),tt=C[0],C[1]>=c/2&&++tt;do d=0,u=t(C,I,z,F),u<0?(me=I[0],z!=F&&(me=me*c+(I[1]||0)),d=me/tt|0,d>1?(d>=c&&(d=c-1),b=e(C,d,c),x=b.length,F=I.length,u=t(b,I,x,F),u==1&&(d--,n(b,z<x?Fe:C,x,c))):(d==0&&(u=d=1),b=C.slice()),x=b.length,x<F&&b.unshift(0),n(I,b,F,c),u==-1&&(F=I.length,u=t(C,I,z,F),u<1&&(d++,n(I,z<F?Fe:C,F,c))),F=I.length):u===0&&(d++,I=[0]),N[m++]=d,u&&I[0]?I[F++]=v[Oe]||0:(I=[v[Oe]],F=1);while((Oe++<ke||I[0]!==void 0)&&H--);w=I[0]!==void 0}N[0]||N.shift()}if(f==1)B.e=l,Ot=w;else{for(m=1,d=N[0];d>=10;d/=10)m++;B.e=m+l*f-1,y(B,a?o+B.e+1:o,s,w)}return B}}();function y(e,t,n,i){var r,o,s,a,c,u,l,m,d,f=e.constructor;e:if(t!=null){if(m=e.d,!m)return e;for(r=1,a=m[0];a>=10;a/=10)r++;if(o=t-r,o<0)o+=g,s=t,l=m[d=0],c=l/E(10,r-s-1)%10|0;else if(d=Math.ceil((o+1)/g),a=m.length,d>=a)if(i){for(;a++<=d;)m.push(0);l=c=0,r=1,o%=g,s=o-g+1}else break e;else{for(l=a=m[d],r=1;a>=10;a/=10)r++;o%=g,s=o-g+r,c=s<0?0:l/E(10,r-s-1)%10|0}if(i=i||t<0||m[d+1]!==void 0||(s<0?l:l%E(10,r-s-1)),u=n<4?(c||i)&&(n==0||n==(e.s<0?3:2)):c>5||c==5&&(n==4||i||n==6&&(o>0?s>0?l/E(10,r-s):0:m[d-1])%10&1||n==(e.s<0?8:7)),t<1||!m[0])return m.length=0,u?(t-=e.e+1,m[0]=E(10,(g-t%g)%g),e.e=-t||0):m[0]=e.e=0,e;if(o==0?(m.length=d,a=1,d--):(m.length=d+1,a=E(10,g-o),m[d]=s>0?(l/E(10,r-s)%E(10,s)|0)*a:0),u)for(;;)if(d==0){for(o=1,s=m[0];s>=10;s/=10)o++;for(s=m[0]+=a,a=1;s>=10;s/=10)a++;o!=a&&(e.e++,m[0]==j&&(m[0]=1));break}else{if(m[d]+=a,m[d]!=j)break;m[d--]=0,a=1}for(o=m.length;m[--o]===0;)m.pop()}return h&&(e.e>f.maxE?(e.d=null,e.e=NaN):e.e<f.minE&&(e.e=0,e.d=[0])),e}function Y(e,t,n){if(!e.isFinite())return qt(e);var i,r=e.e,o=_(e.d),s=o.length;return t?(n&&(i=n-s)>0?o=o.charAt(0)+"."+o.slice(1)+te(i):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(e.e<0?"e":"e+")+e.e):r<0?(o="0."+te(-r-1)+o,n&&(i=n-s)>0&&(o+=te(i))):r>=s?(o+=te(r+1-s),n&&(i=n-r-1)>0&&(o=o+"."+te(i))):((i=r+1)<s&&(o=o.slice(0,i)+"."+o.slice(i)),n&&(i=n-s)>0&&(r+1===s&&(o+="."),o+=te(i))),o}function Ge(e,t){var n=e[0];for(t*=g;n>=10;n/=10)t++;return t}function Ve(e,t,n){if(t>Rn)throw h=!0,n&&(e.precision=n),Error(Ft);return y(new e(De),t,1,!0)}function Z(e,t,n){if(t>st)throw Error(Ft);return y(new e(ve),t,n,!0)}function Dt(e){var t=e.length-1,n=t*g+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function te(e){for(var t="";e--;)t+="0";return t}function vt(e,t,n,i){var r,o=new e(1),s=Math.ceil(i/g+4);for(h=!1;;){if(n%2&&(o=o.times(t),Rt(o.d,s)&&(r=!0)),n=V(n/2),n===0){n=o.d.length-1,r&&o.d[n]===0&&++o.d[n];break}t=t.times(t),Rt(t.d,s)}return h=!0,o}function Lt(e){return e.d[e.d.length-1]&1}function Vt(e,t,n){for(var i,r=new e(t[0]),o=0;++o<t.length;)if(i=new e(t[o]),i.s)r[n](i)&&(r=i);else{r=i;break}return r}function at(e,t){var n,i,r,o,s,a,c,u=0,l=0,m=0,d=e.constructor,f=d.rounding,w=d.precision;if(!e.d||!e.d[0]||e.e>17)return new d(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:0/0);for(t==null?(h=!1,c=w):c=t,a=new d(.03125);e.e>-2;)e=e.times(a),m+=5;for(i=Math.log(E(2,m))/Math.LN10*2+5|0,c+=i,n=o=s=new d(1),d.precision=c;;){if(o=y(o.times(e),c,1),n=n.times(++l),a=s.plus(K(o,n,c,1)),_(a.d).slice(0,c)===_(s.d).slice(0,c)){for(r=m;r--;)s=y(s.times(s),c,1);if(t==null)if(u<3&&Ae(s.d,c-i,f,u))d.precision=c+=10,n=o=a=new d(1),l=0,u++;else return y(s,d.precision=w,f,h=!0);else return d.precision=w,s}s=a}}function ne(e,t){var n,i,r,o,s,a,c,u,l,m,d,f=1,w=10,b=e,x=b.d,B=b.constructor,N=B.rounding,I=B.precision;if(b.s<0||!x||!x[0]||!b.e&&x[0]==1&&x.length==1)return new B(x&&!x[0]?-1/0:b.s!=1?NaN:x?0:b);if(t==null?(h=!1,l=I):l=t,B.precision=l+=w,n=_(x),i=n.charAt(0),Math.abs(o=b.e)<15e14){for(;i<7&&i!=1||i==1&&n.charAt(1)>3;)b=b.times(e),n=_(b.d),i=n.charAt(0),f++;o=b.e,i>1?(b=new B("0."+n),o++):b=new B(i+"."+n.slice(1))}else return u=Ve(B,l+2,I).times(o+""),b=ne(new B(i+"."+n.slice(1)),l-w).plus(u),B.precision=I,t==null?y(b,I,N,h=!0):b;for(m=b,c=s=b=K(b.minus(1),b.plus(1),l,1),d=y(b.times(b),l,1),r=3;;){if(s=y(s.times(d),l,1),u=c.plus(K(s,new B(r),l,1)),_(u.d).slice(0,l)===_(c.d).slice(0,l))if(c=c.times(2),o!==0&&(c=c.plus(Ve(B,l+2,I).times(o+""))),c=K(c,new B(f),l,1),t==null)if(Ae(c.d,l-w,N,a))B.precision=l+=w,u=s=b=K(m.minus(1),m.plus(1),l,1),d=y(b.times(b),l,1),r=a=1;else return y(c,B.precision=I,N,h=!0);else return B.precision=I,c;c=u,r+=2}}function qt(e){return String(e.s*e.s/0)}function ut(e,t){var n,i,r;for((n=t.indexOf("."))>-1&&(t=t.replace(".","")),(i=t.search(/e/i))>0?(n<0&&(n=i),n+=+t.slice(i+1),t=t.substring(0,i)):n<0&&(n=t.length),i=0;t.charCodeAt(i)===48;i++);for(r=t.length;t.charCodeAt(r-1)===48;--r);if(t=t.slice(i,r),t){if(r-=i,e.e=n=n-i-1,e.d=[],i=(n+1)%g,n<0&&(i+=g),i<r){for(i&&e.d.push(+t.slice(0,i)),r-=g;i<r;)e.d.push(+t.slice(i,i+=g));t=t.slice(i),i=g-t.length}else i-=r;for(;i--;)t+="0";e.d.push(+t),h&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function On(e,t){var n,i,r,o,s,a,c,u,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),_t.test(t))return ut(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Cn.test(t))n=16,t=t.toLowerCase();else if(Kn.test(t))n=2;else if(Nn.test(t))n=8;else throw Error(ie+t);for(o=t.search(/p/i),o>0?(c=+t.slice(o+1),t=t.substring(2,o)):t=t.slice(2),o=t.indexOf("."),s=o>=0,i=e.constructor,s&&(t=t.replace(".",""),a=t.length,o=a-o,r=vt(i,new i(n),o,o*2)),u=_e(t,n,j),l=u.length-1,o=l;u[o]===0;--o)u.pop();return o<0?new i(e.s*0):(e.e=Ge(u,l),e.d=u,h=!1,s&&(e=K(e,r,a*4)),c&&(e=e.times(Math.abs(c)<54?E(2,c):Xe.pow(2,c))),h=!0,e)}function Fn(e,t){var n,i=t.d.length;if(i<3)return t.isZero()?t:fe(e,2,t,t);n=1.4*Math.sqrt(i),n=n>16?16:n|0,t=t.times(1/Ue(5,n)),t=fe(e,2,t,t);for(var r,o=new e(5),s=new e(16),a=new e(20);n--;)r=t.times(t),t=t.times(o.plus(r.times(s.times(r).minus(a))));return t}function fe(e,t,n,i,r){var o,s,a,c,u=1,l=e.precision,m=Math.ceil(l/g);for(h=!1,c=n.times(n),a=new e(i);;){if(s=K(a.times(c),new e(t++*t++),l,1),a=r?i.plus(s):i.minus(s),i=K(s.times(c),new e(t++*t++),l,1),s=a.plus(i),s.d[m]!==void 0){for(o=m;s.d[o]===a.d[o]&&o--;);if(o==-1)break}o=a,a=i,i=s,s=o,u++}return h=!0,s.d.length=m+1,s}function Ue(e,t){for(var n=e;--t;)n*=e;return n}function Gt(e,t){var n,i=t.s<0,r=Z(e,e.precision,1),o=r.times(.5);if(t=t.abs(),t.lte(o))return J=i?4:1,t;if(n=t.divToInt(r),n.isZero())J=i?3:2;else{if(t=t.minus(n.times(r)),t.lte(o))return J=Lt(n)?i?2:3:i?4:1,t;J=Lt(n)?i?1:4:i?3:2}return t.minus(r).abs()}function ct(e,t,n,i){var r,o,s,a,c,u,l,m,d,f=e.constructor,w=n!==void 0;if(w?(G(n,1,re),i===void 0?i=f.rounding:G(i,0,8)):(n=f.precision,i=f.rounding),!e.isFinite())l=qt(e);else{for(l=Y(e),s=l.indexOf("."),w?(r=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):r=t,s>=0&&(l=l.replace(".",""),d=new f(1),d.e=l.length-s,d.d=_e(Y(d),10,r),d.e=d.d.length),m=_e(l,10,r),o=c=m.length;m[--c]==0;)m.pop();if(!m[0])l=w?"0p+0":"0";else{if(s<0?o--:(e=new f(e),e.d=m,e.e=o,e=K(e,d,n,i,0,r),m=e.d,o=e.e,u=Ot),s=m[n],a=r/2,u=u||m[n+1]!==void 0,u=i<4?(s!==void 0||u)&&(i===0||i===(e.s<0?3:2)):s>a||s===a&&(i===4||u||i===6&&m[n-1]&1||i===(e.s<0?8:7)),m.length=n,u)for(;++m[--n]>r-1;)m[n]=0,n||(++o,m.unshift(1));for(c=m.length;!m[c-1];--c);for(s=0,l="";s<c;s++)l+=rt.charAt(m[s]);if(w){if(c>1)if(t==16||t==8){for(s=t==16?4:3,--c;c%s;c++)l+="0";for(m=_e(l,r,t),c=m.length;!m[c-1];--c);for(s=1,l="1.";s<c;s++)l+=rt.charAt(m[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=(t==16?"0x":t==2?"0b":t==8?"0o":"")+l}return e.s<0?"-"+l:l}function Rt(e,t){if(e.length>t)return e.length=t,!0}function En(e){return new this(e).abs()}function Wn(e){return new this(e).acos()}function _n(e){return new this(e).acosh()}function Dn(e,t){return new this(e).plus(t)}function vn(e){return new this(e).asin()}function Vn(e){return new this(e).asinh()}function qn(e){return new this(e).atan()}function Gn(e){return new this(e).atanh()}function Un(e,t){e=new this(e),t=new this(t);var n,i=this.precision,r=this.rounding,o=i+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=Z(this,o,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?Z(this,i,r):new this(0),n.s=e.s):!e.d||t.isZero()?(n=Z(this,o,1).times(.5),n.s=e.s):t.s<0?(this.precision=o,this.rounding=1,n=this.atan(K(e,t,o,1)),t=Z(this,o,1),this.precision=i,this.rounding=r,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(K(e,t,o,1)),n}function Xn(e){return new this(e).cbrt()}function Hn(e){return y(e=new this(e),e.e+1,2)}function zn(e,t,n){return new this(e).clamp(t,n)}function Zn(e){if(!e||typeof e!="object")throw Error(qe+"Object expected");var t,n,i,r=e.defaults===!0,o=["precision",1,re,"rounding",0,8,"toExpNeg",-pe,0,"toExpPos",0,pe,"maxE",0,pe,"minE",-pe,0,"modulo",0,9];for(t=0;t<o.length;t+=3)if(n=o[t],r&&(this[n]=ot[n]),(i=e[n])!==void 0)if(V(i)===i&&i>=o[t+1]&&i<=o[t+2])this[n]=i;else throw Error(ie+n+": "+i);if(n="crypto",r&&(this[n]=ot[n]),(i=e[n])!==void 0)if(i===!0||i===!1||i===0||i===1)if(i)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(Et);else this[n]=!1;else throw Error(ie+n+": "+i);return this}function jn(e){return new this(e).cos()}function Yn(e){return new this(e).cosh()}function Ut(e){var t,n,i;function r(o){var s,a,c,u=this;if(!(u instanceof r))return new r(o);if(u.constructor=r,Mt(o)){u.s=o.s,h?!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++;h?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 ut(u,o.toString())}else if(c!=="string")throw Error(ie+o);return(a=o.charCodeAt(0))===45?(o=o.slice(1),u.s=-1):(a===43&&(o=o.slice(1)),u.s=1),_t.test(o)?ut(u,o):On(u,o)}if(r.prototype=p,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=Zn,r.clone=Ut,r.isDecimal=Mt,r.abs=En,r.acos=Wn,r.acosh=_n,r.add=Dn,r.asin=vn,r.asinh=Vn,r.atan=qn,r.atanh=Gn,r.atan2=Un,r.cbrt=Xn,r.ceil=Hn,r.clamp=zn,r.cos=jn,r.cosh=Yn,r.div=Qn,r.exp=Jn,r.floor=$n,r.hypot=ei,r.ln=ti,r.log=ni,r.log10=ri,r.log2=ii,r.max=oi,r.min=si,r.mod=ai,r.mul=ui,r.pow=ci,r.random=li,r.round=mi,r.sign=di,r.sin=pi,r.sinh=fi,r.sqrt=bi,r.sub=yi,r.sum=gi,r.tan=Pi,r.tanh=wi,r.trunc=ki,e===void 0&&(e={}),e&&e.defaults!==!0)for(i=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<i.length;)e.hasOwnProperty(n=i[t++])||(e[n]=this[n]);return r.config(e),r}function Qn(e,t){return new this(e).div(t)}function Jn(e){return new this(e).exp()}function $n(e){return y(e=new this(e),e.e+1,3)}function ei(){var e,t,n=new this(0);for(h=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return h=!0,new this(1/0);n=t}return h=!0,n.sqrt()}function Mt(e){return e instanceof Xe||e&&e.toStringTag===Wt||!1}function ti(e){return new this(e).ln()}function ni(e,t){return new this(e).log(t)}function ii(e){return new this(e).log(2)}function ri(e){return new this(e).log(10)}function oi(){return Vt(this,arguments,"lt")}function si(){return Vt(this,arguments,"gt")}function ai(e,t){return new this(e).mod(t)}function ui(e,t){return new this(e).mul(t)}function ci(e,t){return new this(e).pow(t)}function li(e){var t,n,i,r,o=0,s=new this(1),a=[];if(e===void 0?e=this.precision:G(e,1,re),i=Math.ceil(e/g),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(i));o<i;)r=t[o],r>=429e7?t[o]=crypto.getRandomValues(new Uint32Array(1))[0]:a[o++]=r%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(i*=4);o<i;)r=t[o]+(t[o+1]<<8)+(t[o+2]<<16)+((t[o+3]&127)<<24),r>=214e7?crypto.randomBytes(4).copy(t,o):(a.push(r%1e7),o+=4);o=i/4}else throw Error(Et);else for(;o<i;)a[o++]=Math.random()*1e7|0;for(i=a[--o],e%=g,i&&e&&(r=E(10,g-e),a[o]=(i/r|0)*r);a[o]===0;o--)a.pop();if(o<0)n=0,a=[0];else{for(n=-1;a[0]===0;n-=g)a.shift();for(i=1,r=a[0];r>=10;r/=10)i++;i<g&&(n-=g-i)}return s.e=n,s.d=a,s}function mi(e){return y(e=new this(e),e.e+1,this.rounding)}function di(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function pi(e){return new this(e).sin()}function fi(e){return new this(e).sinh()}function bi(e){return new this(e).sqrt()}function yi(e,t){return new this(e).sub(t)}function gi(){var e=0,t=arguments,n=new this(t[e]);for(h=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return h=!0,y(n,this.precision,this.rounding)}function Pi(e){return new this(e).tan()}function wi(e){return new this(e).tanh()}function ki(e){return y(e=new this(e),e.e+1,1)}p[Symbol.for("nodejs.util.inspect.custom")]=p.toString;p[Symbol.toStringTag]="Decimal";var Xe=p.constructor=Ut(ot);De=new Xe(De);ve=new Xe(ve);import Ki from"big.js";import uo from"bn.js";import Ai from"toformat";var hi=Ai,he=hi;import ze from"big.js";import Bi from"bn.js";import xi from"decimal.js-light";import Te from"bn.js";var Xt=9007199254740991;function Q(e){let t=W("CobaltX_parseBigNumberish");if(e instanceof Te)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new Te(e);t.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&t.logWithError(`BigNumberish number underflow: ${e}`),(e>=Xt||e<=-Xt)&&t.logWithError(`BigNumberish number overflow: ${e}`),new Te(String(e))):typeof e=="bigint"?new Te(e.toString()):(t.error(`invalid BigNumberish value: ${e}`),new Te(0))}var He=W("module/fraction"),lt=he(ze),Be=he(xi),Ii={[0]:Be.ROUND_DOWN,[1]:Be.ROUND_HALF_UP,[2]:Be.ROUND_UP},Si={[0]:ze.roundDown,[1]:ze.roundHalfUp,[2]:ze.roundUp},L=class{constructor(t,n=new Bi(1)){this.numerator=Q(t),this.denominator=Q(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new L(this.denominator,this.numerator)}add(t){let n=t instanceof L?t:new L(Q(t));return this.denominator.eq(n.denominator)?new L(this.numerator.add(n.numerator),this.denominator):new L(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(t){let n=t instanceof L?t:new L(Q(t));return this.denominator.eq(n.denominator)?new L(this.numerator.sub(n.numerator),this.denominator):new L(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(t){let n=t instanceof L?t:new L(Q(t));return new L(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(t){let n=t instanceof L?t:new L(Q(t));return new L(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(t,n={groupSeparator:""},i=1){Number.isInteger(t)||He.logWithError(`${t} is not an integer.`),t<=0&&He.logWithError(`${t} is not positive.`),Be.set({precision:t+1,rounding:Ii[i]});let r=new Be(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return r.toFormat(r.decimalPlaces(),n)}toFixed(t,n={groupSeparator:""},i=1){return Number.isInteger(t)||He.logWithError(`${t} is not an integer.`),t<0&&He.logWithError(`${t} is negative.`),lt.DP=t,lt.RM=Si[i]||1,new lt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,n)}isZero(){return this.numerator.isZero()}};var Po=W("CobaltX_amount"),wo=he(Ki);import{TOKEN_PROGRAM_ID as Ht}from"@solana/spl-token";import{PublicKey as Ni}from"@solana/web3.js";var mt={chainId:101,address:Ni.default.toBase58(),programId:Ht.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"}},oe={chainId:101,address:"So11111111111111111111111111111111111111112",programId:Ht.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 pt}from"@solana/web3.js";import{PublicKey as D,SystemProgram as zt,SYSVAR_RENT_PUBKEY as Li}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Ri}from"@solana/spl-token";function dt({pubkey:e,isSigner:t=!1,isWritable:n=!0}){return{pubkey:e,isWritable:n,isSigner:t}}var So=[dt({pubkey:Ri,isWritable:!1}),dt({pubkey:zt.programId,isWritable:!1}),dt({pubkey:Li,isWritable:!1})];function Zt({publicKey:e,transformSol:t}){let n=jt(e.toString());if(n instanceof D)return t&&n.equals(xe)?We:n;if(t&&n.toString()===xe.toBase58())return We;if(typeof n=="string"){if(n===D.default.toBase58())return D.default;try{return new D(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function jt(e){try{return new D(e)}catch{return e}}var Mi=new D("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Ze=new D("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),je=new D("SysvarRent111111111111111111111111111111111"),Ko=new D("SysvarC1ock11111111111111111111111111111111"),be=new D("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Co=new D("Sysvar1nstructions1111111111111111111111111"),Yt=zt.programId,No=new D("a2Gt18uJC8puJT9JRYQLU6rPi6okxQb4WqCjwtYshZB"),Lo=new D("bXSKiFqYrALF9gJy1KqHm8tv4QXk8nCgbLN8WRsGEbh"),We=new D("So11111111111111111111111111111111111111112"),xe=D.default,Ro=new D("71kRXzJMvSeArtXYNEWa8KAjpRJosdMQ7Dpgy5Jt5zfd"),Mo=new D("ERFzpDteGNo8LTDKW1WwVGrkRMmA2y9WZHXNHxMA6BSV");var ft=class{constructor({mint:t,decimals:n,symbol:i,name:r,skipMint:o=!1,isToken2022:s=!1}){if(t===xe.toBase58()||t instanceof pt&&xe.equals(t)){this.decimals=oe.decimals,this.symbol=oe.symbol,this.name=oe.name,this.mint=new pt(oe.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=i||t.toString().substring(0,6),this.name=r||t.toString().substring(0,6),this.mint=o?pt.default:Zt({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},se=ft;se.WSOL=new ft({...oe,mint:oe.address});var bt=class{constructor({decimals:t,symbol:n="UNKNOWN",name:i="UNKNOWN"}){this.decimals=t,this.symbol=n,this.name=i}equals(t){return this===t}},Ye=bt;Ye.SOL=new bt(mt);import Oi from"bn.js";var Xo=new L(new Oi(100));var Qo=W("CobaltX_price");import{PublicKey as fs}from"@solana/web3.js";import ys from"bn.js";var Fi=new $(0),Os=new $(1),Fs=new $(2),Es=new $(3),Ws=new $(5),Ci=new $(10),_s=new $(100),Ds=new $(1e3),vs=new $(1e4);import{PublicKey as Wi}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as _i}from"@solana/spl-token";import{ComputeBudgetProgram as Zs,Keypair as Qs,PublicKey as Ei,Transaction as $s,TransactionMessage as ta,VersionedTransaction as na}from"@solana/web3.js";var Se={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 sa}from"@solana/spl-token";var aa=W("CobaltX_txUtil");function ue(e,t){let[n,i]=Ei.findProgramAddressSync(e,t);return{publicKey:n,nonce:i}}function ye(e,t,n){return ue([e.toBuffer(),(n!=null?n:_i).toBuffer(),t.toBuffer()],new Wi("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}import{PublicKey as T}from"@solana/web3.js";var fa=new T("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),ba=new T("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),ya=new T("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),ga=new T("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Pa=new T("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),wa=new T("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),ka=new T("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Aa=new T("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),ha=new T("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Ta=new T("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),Di=new T("2TnjBuwqyBB9to5jURagDT7jLmBPefGRiKL2yh1zPZ4V"),vi=new T("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),Vi=new T("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),Ba=new T("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),xa=new T("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Ia=new T("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Sa=new T("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),Ka=new T("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),Ca=new T("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),Qt=new T("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),Jt=new T("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Na=new T("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),qi=new T("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),Gi=new T("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),Ui=new T("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),La=new T("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),Xi=new T("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),Ra=new T("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),Hi=new T("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix");var Ma={SERUM_MARKET:T.default,OPENBOOK_MARKET:new T("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:T.default,FarmV3:new T("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new T("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new T("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new T("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new T("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new T("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),CLMM_LOCK_PROGRAM_ID:new T("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),CLMM_LOCK_AUTH_ID:new T("8qmHNvu2Kr2C7U8mJL4Vz1vTDxMhVuXKREwU7TNoaVEo"),Router:new T("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:qi,CREATE_CPMM_POOL_AUTH:Gi,CREATE_CPMM_POOL_FEE_ACC:Ui,FEE_DESTINATION_ID:new T("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),LOCK_CPMM_PROGRAM:Xi,LCOK_CPMM_AUTH:Hi};import Ea from"bn.js";import{PublicKey as zi,AddressLookupTableAccount as $t}from"@solana/web3.js";var Zi={AiAibtFJts8e4W1FjWYRH34aBJkJqghdmXiJozK7MvTM:new $t({key:new zi("AiAibtFJts8e4W1FjWYRH34aBJkJqghdmXiJozK7MvTM"),state:$t.deserialize(Buffer.from("AQAAAP//////////d49+DAAAAAAAAQZMWvw7GUNJdaccNBVnb57OKakxL2BHLYvhRwVILRsgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMGRm/lIRcy/+ytunLDm+e8jOW7xfcSayxDmzpAAAAABt324ddloZPZy+FGzut5rBy0he1fWzeROoz1hX7/AKkG3fbh7nWP3hhCXbzkbM3athr8TYO5DSf+vfko2KGL/AVKU1D4XciC1hSlVnJ4iilt3x6rq9CmBniISTL07vagBqfVFxksXFEhjMlMPUrxf1ja7gibof1E49vZigAAAAAGp9UXGMd0yShWY5hpHV62i164o5tLbVxzVVshAAAAAIyXJY9OJInxuz0QKRSODYMLWhOZ2v8QhASOe9jb6fhZC3BlsePRfEU4nVJ/awTDzVi4bHMaoP21SbbRvAP4KUbIScv+6Yw2LHF/6K0ZjUPibbSWXCirYPGuuVl7zT789IUPLW4CpHr4JNCatp3ELXDLKMv6JJ+37le50lbBJ2LvDQdRqCgtphMF/imcN7mY5YRx2xE1A3MQ+L4QRaYK9u4GRfZP3LsAd00a+IkCpA22UNQMKdq5BFbJuwuOLqc8zxCTDlqxBG8J0HcxtfogQHDK06ukzfaXiNDKAob1MqBHS9lJxDYCwz8gd5DtFqNSTKG5l1zxIaKpDP/sffi2is1H9aKveyXSu5StXElYRl9SD5As0DHE4N0GLnf84/siiKXVyp4Ez121kLcUui/jLLFZEz/BwZK3Ilf9B9OcsEAeDMKAy2vjGSxQODgBz0QwGA+eP4ZjIjrIAQaXENv31QfLlOdXSRCkaybRniDHF4C8YcwhcvsqrOVuTP4B2Na+9wLdtrB31uz2rtlFI5kahdsnp/d1SrASDInYCtTYtdoke4kX+hoKWcEWM4Tle8pTUkUVv4BxS6fje/EzKBE4Qu9N9LMnrw/JNO0hqMVB4rk/2ou4AB1loQ7FZoPwut2o4KZB+0p9xnbrQKw038qjpHar+PyDwvxBRcu5hpHw3dguezeWv+IwvgW5icu8EGkhGa9AkFPPJT7VMSFb8xowveU=","base64"))})};import{PublicKey as Ja,sendAndConfirmTransaction as $a,Transaction as tu,TransactionMessage as iu,VersionedTransaction as ru}from"@solana/web3.js";import su from"axios";import{ASSOCIATED_TOKEN_PROGRAM_ID as xn,TOKEN_2022_PROGRAM_ID as St,TOKEN_PROGRAM_ID as ae}from"@solana/spl-token";import{Keypair as xr,PublicKey as Me,SystemProgram as Ir,TransactionInstruction as ce}from"@solana/web3.js";var Lu=Buffer.from("vault_and_lp_mint_auth_seed","utf8"),Ru=Buffer.from("amm_config","utf8"),Yi=Buffer.from("pool","utf8"),Mu=Buffer.from("pool_lp_mint","utf8"),Ou=Buffer.from("pool_vault","utf8"),Fu=Buffer.from("observation","utf8");function tn(e,t,n,i){return ue([Yi,t.toBuffer(),n.toBuffer(),i.toBuffer()],e)}var Qi=Buffer.from("locked_liquidity","utf8");function nn(e,t){return ue([Qi,t.toBuffer()],e)}import{PublicKey as sr}from"@solana/web3.js";import an,{isBN as un}from"bn.js";import{bits as _u,BitStructure as Du,blob as Ji,Blob as vu,cstr as Vu,f32 as qu,f32be as Gu,f64 as Uu,f64be as Xu,greedy as Hu,Layout as $i,ns64 as zu,ns64be as Zu,nu64 as ju,nu64be as Yu,offset as Qu,s16 as Ju,s16be as $u,s24 as ec,s24be as tc,s32 as er,s32be as nc,s40 as ic,s40be as rc,s48 as oc,s48be as sc,s8 as ac,seq as tr,struct as uc,Structure as nr,u16 as ir,u16be as cc,u24 as lc,u24be as mc,u32 as dc,u32be as pc,u40 as fc,u40be as bc,u48 as yc,u48be as gc,u8 as rr,UInt as or,union as Pc,Union as wc,unionLayoutDiscriminator as kc,utf8 as Ac}from"@solana/buffer-layout";var Pt=$i,rn=nr;var wt=or;var on=rr,Ke=ir;var ee=er;var sn=tr;var U=Ji;var ge=class extends Pt{constructor(n,i,r){super(n,r);this.blob=U(n),this.signed=i}decode(n,i=0){let r=new an(this.blob.decode(n,i),10,"le");return this.signed?r.fromTwos(this.span*8).clone():r}encode(n,i,r=0){return typeof n=="number"&&(n=new an(n)),this.signed&&(n=n.toTwos(this.span*8)),this.blob.encode(n.toArrayLike(Buffer,"le",this.span),i,r)}};function q(e){return new wt(1,e)}function Pe(e){return new wt(4,e)}function P(e){return new ge(8,!1,e)}function R(e){return new ge(16,!1,e)}function cn(e){return new ge(8,!0,e)}function ln(e){return new ge(16,!0,e)}var Je=class extends Pt{constructor(n,i,r,o){super(n.span,o);this.layout=n,this.decoder=i,this.encoder=r}decode(n,i){return this.decoder(this.layout.decode(n,i))}encode(n,i,r){return this.layout.encode(this.encoder(n),i,r)}getSpan(n,i){return this.layout.getSpan(n,i)}};function S(e){return new Je(U(32),t=>new sr(t),t=>t.toBuffer(),e)}function Ce(e){return new Je(on(),ar,ur,e)}function ar(e){if(e===0)return!1;if(e===1)return!0;throw new Error("Invalid bool: "+e)}function ur(e){return e?1:0}var kt=class extends rn{decode(t,n){return super.decode(t,n)}};function M(e,t,n){return new kt(e,t,n)}function O(e,t,n){let i,r=typeof t=="number"?t:un(t)?t.toNumber():new Proxy(t,{get(o,s){if(!i){let a=Reflect.get(o,"count");i=un(a)?a.toNumber():a,Reflect.set(o,"count",i)}return Reflect.get(o,s)},set(o,s,a){return s==="count"&&(i=a),Reflect.set(o,s,a)}});return sn(e,r,n)}import{AccountLayout as Rd,TOKEN_2022_PROGRAM_ID as Md,TOKEN_PROGRAM_ID as Od}from"@solana/spl-token";import{PublicKey as Ed}from"@solana/web3.js";import _d from"bn.js";import{PublicKey as Vc}from"@solana/web3.js";import{MintLayout as Gc,TOKEN_PROGRAM_ID as Xc}from"@solana/spl-token";import{ASSOCIATED_TOKEN_PROGRAM_ID as id,TOKEN_2022_PROGRAM_ID as rd,TOKEN_PROGRAM_ID as od}from"@solana/spl-token";import{Keypair as ud,PublicKey as cd,SystemProgram as md,TransactionInstruction as dd}from"@solana/web3.js";import fd from"bn.js";import Fm from"bn.js";import X from"bn.js";var mn=new X(0),dn=new X(1),pn=new X(-1),$e=new X(1).shln(64),fn=new X(1).shln(128),cr=$e.sub(dn);var lr=fn.subn(1),we=-443636,Ne=-we,At=new X("4295048016"),ht=new X("79226673521066979257578248091"),Jc=new X("4295048017"),$c=new X("79226673521066979257578248090");var mr=new X(10).pow(new X(6));var el=new X("18446744073700000000");import Am from"bn.js";var al=Buffer.from("amm_config","utf8"),ul=Buffer.from("pool","utf8"),cl=Buffer.from("pool_vault","utf8"),ll=Buffer.from("pool_reward_vault","utf8"),ml=Buffer.from("position","utf8"),dl=Buffer.from("tick_array","utf8"),pl=Buffer.from("operation","utf8"),fl=Buffer.from("pool_tick_array_bitmap_extension","utf8"),bl=Buffer.from("observation","utf8");function Tt(e){return ue([Buffer.from("metadata","utf8"),be.toBuffer(),e.toBuffer()],be)}var yl=Buffer.from("locked_position","utf8");import{TOKEN_2022_PROGRAM_ID as zl}from"@solana/spl-token";import{PublicKey as Ql}from"@solana/web3.js";import $l from"bn.js";import wl from"bn.js";var It=14;var et=60;var yr=M([U(8),q("bump"),Ke("index"),S(""),Pe("protocolFeeRate"),Pe("tradeFeeRate"),Ke("tickSpacing"),O(P(),8,"")]),gr=M([Pe("blockTimestamp"),cn("tickCumulative"),O(P(),4)]),Bn=M([U(8),Ce("initialized")