UNPKG

@cobaltx/sdk-v2

Version:

An SDK for building applications on top of CobaltX.

9 lines 113 kB
"use strict";var qi=Object.create;var bt=Object.defineProperty;var Ui=Object.getOwnPropertyDescriptor;var Gi=Object.getOwnPropertyNames;var Xi=Object.getPrototypeOf,Hi=Object.prototype.hasOwnProperty;var zi=(t,e)=>{for(var n in e)bt(t,n,{get:e[n],enumerable:!0})},Sn=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Gi(e))!Hi.call(t,r)&&r!==n&&bt(t,r,{get:()=>e[r],enumerable:!(i=Ui(e,r))||i.enumerable});return t};var j=(t,e,n)=>(n=t!=null?qi(Xi(t)):{},Sn(e||!t||!t.__esModule?bt(n,"default",{value:t,enumerable:!0}):n,t)),Yi=t=>Sn(bt({},"__esModule",{value:!0}),t);var es={};zi(es,{default:()=>Ht});module.exports=Yi(es);var he=j(require("bn.js"));var ve=9e15,Ne=1e9,zt="0123456789abcdef",wt="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",At="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Yt={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ve,maxE:ve,crypto:!1},Ln,Be,R=!0,kt="[DecimalError] ",Ke=kt+"Invalid argument: ",Rn=kt+"Precision limit exceeded",Mn=kt+"crypto unavailable",On="[object Decimal]",oe=Math.floor,$=Math.pow,ji=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Zi=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Qi=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,En=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,fe=1e7,L=7,Ji=9007199254740991,$i=wt.length-1,jt=At.length-1,w={toStringTag:On};w.absoluteValue=w.abs=function(){var t=new this.constructor(this);return t.s<0&&(t.s=1),C(t)};w.ceil=function(){return C(new this.constructor(this),this.e+1,2)};w.clampedTo=w.clamp=function(t,e){var n,i=this,r=i.constructor;if(t=new r(t),e=new r(e),!t.s||!e.s)return new r(NaN);if(t.gt(e))throw Error(Ke+e);return n=i.cmp(t),n<0?t:i.cmp(e)>0?e:new r(i)};w.comparedTo=w.cmp=function(t){var e,n,i,r,o=this,s=o.d,a=(t=new o.constructor(t)).d,c=o.s,u=t.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!==t.e)return o.e>t.e^c<0?1:-1;for(i=s.length,r=a.length,e=0,n=i<r?i:r;e<n;++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};w.cosine=w.cos=function(){var t,e,n=this,i=n.constructor;return n.d?n.d[0]?(t=i.precision,e=i.rounding,i.precision=t+Math.max(n.e,n.sd())+L,i.rounding=1,n=er(i,Wn(i,n)),i.precision=t,i.rounding=e,C(Be==2||Be==3?n.neg():n,t,e,!0)):new i(1):new i(NaN)};w.cubeRoot=w.cbrt=function(){var t,e,n,i,r,o,s,a,c,u,l=this,m=l.constructor;if(!l.isFinite()||l.isZero())return new m(l);for(R=!1,o=l.s*$(l.s*l,1/3),!o||Math.abs(o)==1/0?(n=re(l.d),t=l.e,(o=(t-n.length+1)%3)&&(n+=o==1||o==-2?"0":"00"),o=$(n,1/3),t=oe((t+1)/3)-(t%3==(t<0?-1:2)),o==1/0?n="5e"+t:(n=o.toExponential(),n=n.slice(0,n.indexOf("e")+1)+t),i=new m(n),i.s=l.s):i=new m(o.toString()),s=(t=m.precision)+3;;)if(a=i,c=a.times(a).times(a),u=c.plus(l),i=H(u.plus(l).times(a),u.plus(c),s+2,1),re(a.d).slice(0,s)===(n=re(i.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!r&&n=="4999"){if(!r&&(C(a,t+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")&&(C(i,t+1,1),e=!i.times(i).times(i).eq(l));break}return R=!0,C(i,t,m.rounding,e)};w.decimalPlaces=w.dp=function(){var t,e=this.d,n=NaN;if(e){if(t=e.length-1,n=(t-oe(this.e/L))*L,t=e[t],t)for(;t%10==0;t/=10)n--;n<0&&(n=0)}return n};w.dividedBy=w.div=function(t){return H(this,new this.constructor(t))};w.dividedToIntegerBy=w.divToInt=function(t){var e=this,n=e.constructor;return C(H(e,new n(t),0,1,1),n.precision,n.rounding)};w.equals=w.eq=function(t){return this.cmp(t)===0};w.floor=function(){return C(new this.constructor(this),this.e+1,3)};w.greaterThan=w.gt=function(t){return this.cmp(t)>0};w.greaterThanOrEqualTo=w.gte=function(t){var e=this.cmp(t);return e==1||e===0};w.hyperbolicCosine=w.cosh=function(){var t,e,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?(t=Math.ceil(r/3),e=(1/ht(4,t)).toString()):(t=16,e="2.3283064365386962890625e-10"),o=We(s,1,o.times(e),new s(1),!0);for(var c,u=t,l=new s(8);u--;)c=o.times(o),o=a.minus(c.times(l.minus(c.times(l))));return C(o,s.precision=n,s.rounding=i,!0)};w.hyperbolicSine=w.sinh=function(){var t,e,n,i,r=this,o=r.constructor;if(!r.isFinite()||r.isZero())return new o(r);if(e=o.precision,n=o.rounding,o.precision=e+Math.max(r.e,r.sd())+4,o.rounding=1,i=r.d.length,i<3)r=We(o,2,r,r,!0);else{t=1.4*Math.sqrt(i),t=t>16?16:t|0,r=r.times(1/ht(5,t)),r=We(o,2,r,r,!0);for(var s,a=new o(5),c=new o(16),u=new o(20);t--;)s=r.times(r),r=r.times(a.plus(s.times(c.times(s).plus(u))))}return o.precision=e,o.rounding=n,C(r,e,n,!0)};w.hyperbolicTangent=w.tanh=function(){var t,e,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(t=i.precision,e=i.rounding,i.precision=t+7,i.rounding=1,H(n.sinh(),n.cosh(),i.precision=t,i.rounding=e)):new i(n.s)};w.inverseCosine=w.acos=function(){var t=this,e=t.constructor,n=t.abs().cmp(1),i=e.precision,r=e.rounding;return n!==-1?n===0?t.isNeg()?ye(e,i,r):new e(0):new e(NaN):t.isZero()?ye(e,i+4,r).times(.5):(e.precision=i+6,e.rounding=1,t=new e(1).minus(t).div(t.plus(1)).sqrt().atan(),e.precision=i,e.rounding=r,t.times(2))};w.inverseHyperbolicCosine=w.acosh=function(){var t,e,n=this,i=n.constructor;return n.lte(1)?new i(n.eq(1)?0:NaN):n.isFinite()?(t=i.precision,e=i.rounding,i.precision=t+Math.max(Math.abs(n.e),n.sd())+4,i.rounding=1,R=!1,n=n.times(n).minus(1).sqrt().plus(n),R=!0,i.precision=t,i.rounding=e,n.ln()):new i(n)};w.inverseHyperbolicSine=w.asinh=function(){var t,e,n=this,i=n.constructor;return!n.isFinite()||n.isZero()?new i(n):(t=i.precision,e=i.rounding,i.precision=t+2*Math.max(Math.abs(n.e),n.sd())+6,i.rounding=1,R=!1,n=n.times(n).plus(1).sqrt().plus(n),R=!0,i.precision=t,i.rounding=e,n.ln())};w.inverseHyperbolicTangent=w.atanh=function(){var t,e,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):(t=o.precision,e=o.rounding,i=r.sd(),Math.max(i,t)<2*-r.e-1?C(new o(r),t,e,!0):(o.precision=n=i-r.e,r=H(r.plus(1),new o(1).minus(r),n+t,1),o.precision=t+4,o.rounding=1,r=r.ln(),o.precision=t,o.rounding=e,r.times(.5))):new o(NaN)};w.inverseSine=w.asin=function(){var t,e,n,i,r=this,o=r.constructor;return r.isZero()?new o(r):(e=r.abs().cmp(1),n=o.precision,i=o.rounding,e!==-1?e===0?(t=ye(o,n+4,i).times(.5),t.s=r.s,t):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)))};w.inverseTangent=w.atan=function(){var t,e,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<=jt)return s=ye(l,m+4,d).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(m+4<=jt)return s=ye(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/L+2|0),t=n;t;--t)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(R=!1,e=Math.ceil(a/L),i=1,c=u.times(u),s=new l(u),r=u;t!==-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(t=e;s.d[t]===o.d[t]&&t--;);return n&&(s=s.times(2<<n-1)),R=!0,C(s,l.precision=m,l.rounding=d,!0)};w.isFinite=function(){return!!this.d};w.isInteger=w.isInt=function(){return!!this.d&&oe(this.e/L)>this.d.length-2};w.isNaN=function(){return!this.s};w.isNegative=w.isNeg=function(){return this.s<0};w.isPositive=w.isPos=function(){return this.s>0};w.isZero=function(){return!!this.d&&this.d[0]===0};w.lessThan=w.lt=function(t){return this.cmp(t)<0};w.lessThanOrEqualTo=w.lte=function(t){return this.cmp(t)<1};w.logarithm=w.log=function(t){var e,n,i,r,o,s,a,c,u=this,l=u.constructor,m=l.precision,d=l.rounding,p=5;if(t==null)t=new l(10),e=!0;else{if(t=new l(t),n=t.d,t.s<0||!n||!n[0]||t.eq(1))return new l(NaN);e=t.eq(10)}if(n=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(e)if(n.length>1)o=!0;else{for(r=n[0];r%10===0;)r/=10;o=r!==1}if(R=!1,a=m+p,s=Ce(u,a),i=e?Pt(l,a+10):Ce(t,a),c=H(s,i,a,1),$e(c.d,r=m,d))do if(a+=10,s=Ce(u,a),i=e?Pt(l,a+10):Ce(t,a),c=H(s,i,a,1),!o){+re(c.d).slice(r+1,r+15)+1==1e14&&(c=C(c,m+1,0));break}while($e(c.d,r+=10,d));return R=!0,C(c,m,d)};w.minus=w.sub=function(t){var e,n,i,r,o,s,a,c,u,l,m,d,p=this,b=p.constructor;if(t=new b(t),!p.d||!t.d)return!p.s||!t.s?t=new b(NaN):p.d?t.s=-t.s:t=new b(t.d||p.s!==t.s?p:NaN),t;if(p.s!=t.s)return t.s=-t.s,p.plus(t);if(u=p.d,d=t.d,a=b.precision,c=b.rounding,!u[0]||!d[0]){if(d[0])t.s=-t.s;else if(u[0])t=new b(p);else return new b(c===3?-0:0);return R?C(t,a,c):t}if(n=oe(t.e/L),l=oe(p.e/L),u=u.slice(),o=l-n,o){for(m=o<0,m?(e=u,o=-o,s=d.length):(e=d,n=l,s=u.length),i=Math.max(Math.ceil(a/L),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,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&&(e=u,u=d,d=e,t.s=-t.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]=fe-1;--u[r],u[i]+=fe}u[i]-=d[i]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--n;return u[0]?(t.d=u,t.e=Tt(u,n),R?C(t,a,c):t):new b(c===3?-0:0)};w.modulo=w.mod=function(t){var e,n=this,i=n.constructor;return t=new i(t),!n.d||!t.s||t.d&&!t.d[0]?new i(NaN):!t.d||n.d&&!n.d[0]?C(new i(n),i.precision,i.rounding):(R=!1,i.modulo==9?(e=H(n,t.abs(),0,3,1),e.s*=t.s):e=H(n,t,0,i.modulo,1),e=e.times(t),R=!0,n.minus(e))};w.naturalExponential=w.exp=function(){return Zt(this)};w.naturalLogarithm=w.ln=function(){return Ce(this)};w.negated=w.neg=function(){var t=new this.constructor(this);return t.s=-t.s,C(t)};w.plus=w.add=function(t){var e,n,i,r,o,s,a,c,u,l,m=this,d=m.constructor;if(t=new d(t),!m.d||!t.d)return!m.s||!t.s?t=new d(NaN):m.d||(t=new d(t.d||m.s===t.s?m:NaN)),t;if(m.s!=t.s)return t.s=-t.s,m.minus(t);if(u=m.d,l=t.d,a=d.precision,c=d.rounding,!u[0]||!l[0])return l[0]||(t=new d(m)),R?C(t,a,c):t;if(o=oe(m.e/L),i=oe(t.e/L),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/L),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),e=0;r;)e=(u[--r]=u[r]+l[r]+e)/fe|0,u[r]%=fe;for(e&&(u.unshift(e),++i),s=u.length;u[--s]==0;)u.pop();return t.d=u,t.e=Tt(u,i),R?C(t,a,c):t};w.precision=w.sd=function(t){var e,n=this;if(t!==void 0&&t!==!!t&&t!==1&&t!==0)throw Error(Ke+t);return n.d?(e=_n(n.d),t&&n.e+1>e&&(e=n.e+1)):e=NaN,e};w.round=function(){var t=this,e=t.constructor;return C(new e(t),t.e+1,e.rounding)};w.sine=w.sin=function(){var t,e,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(t=i.precision,e=i.rounding,i.precision=t+Math.max(n.e,n.sd())+L,i.rounding=1,n=nr(i,Wn(i,n)),i.precision=t,i.rounding=e,C(Be>2?n.neg():n,t,e,!0)):new i(NaN)};w.squareRoot=w.sqrt=function(){var t,e,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(R=!1,u=Math.sqrt(+s),u==0||u==1/0?(e=re(a),(e.length+c)%2==0&&(e+="0"),u=Math.sqrt(e),c=oe((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 l(e)):i=new l(u.toString()),n=(c=l.precision)+3;;)if(o=i,i=o.plus(H(s,o,n+2,1)).times(.5),re(o.d).slice(0,n)===(e=re(i.d)).slice(0,n))if(e=e.slice(n-3,n+1),e=="9999"||!r&&e=="4999"){if(!r&&(C(o,c+1,0),o.times(o).eq(s))){i=o;break}n+=4,r=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(C(i,c+1,1),t=!i.times(i).eq(s));break}return R=!0,C(i,c,l.rounding,t)};w.tangent=w.tan=function(){var t,e,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(t=i.precision,e=i.rounding,i.precision=t+10,i.rounding=1,n=n.sin(),n.s=1,n=H(n,new i(1).minus(n.times(n)).sqrt(),t+10,0),i.precision=t,i.rounding=e,C(Be==2||Be==4?n.neg():n,t,e,!0)):new i(NaN)};w.times=w.mul=function(t){var e,n,i,r,o,s,a,c,u,l=this,m=l.constructor,d=l.d,p=(t=new m(t)).d;if(t.s*=l.s,!d||!d[0]||!p||!p[0])return new m(!t.s||d&&!d[0]&&!p||p&&!p[0]&&!d?NaN:!d||!p?t.s/0:t.s*0);for(n=oe(l.e/L)+oe(t.e/L),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%fe|0,e=a/fe|0;o[r]=(o[r]+e)%fe|0}for(;!o[--s];)o.pop();return e?++n:o.shift(),t.d=o,t.e=Tt(o,n),R?C(t,m.precision,m.rounding):t};w.toBinary=function(t,e){return Qt(this,2,t,e)};w.toDecimalPlaces=w.toDP=function(t,e){var n=this,i=n.constructor;return n=new i(n),t===void 0?n:(ce(t,0,Ne),e===void 0?e=i.rounding:ce(e,0,8),C(n,t+n.e+1,e))};w.toExponential=function(t,e){var n,i=this,r=i.constructor;return t===void 0?n=we(i,!0):(ce(t,0,Ne),e===void 0?e=r.rounding:ce(e,0,8),i=C(new r(i),t+1,e),n=we(i,!0,t+1)),i.isNeg()&&!i.isZero()?"-"+n:n};w.toFixed=function(t,e){var n,i,r=this,o=r.constructor;return t===void 0?n=we(r):(ce(t,0,Ne),e===void 0?e=o.rounding:ce(e,0,8),i=C(new o(r),t+r.e+1,e),n=we(i,!1,t+i.e+1)),r.isNeg()&&!r.isZero()?"-"+n:n};w.toFraction=function(t){var e,n,i,r,o,s,a,c,u,l,m,d,p=this,b=p.d,f=p.constructor;if(!b)return new f(p);if(u=n=new f(1),i=c=new f(0),e=new f(i),o=e.e=_n(b)-p.e-1,s=o%L,e.d[0]=$(10,s<0?L+s:s),t==null)t=o>0?e:u;else{if(a=new f(t),!a.isInt()||a.lt(u))throw Error(Ke+a);t=a.gt(e)?o>0?e:u:a}for(R=!1,a=new f(re(b)),l=f.precision,f.precision=o=b.length*L*2;m=H(a,e,0,1,1),r=n.plus(m.times(i)),r.cmp(t)!=1;)n=i,i=r,r=u,u=c.plus(m.times(r)),c=r,r=e,e=a.minus(m.times(r)),a=r;return r=H(t.minus(n),i,0,1,1),c=c.plus(r.times(u)),n=n.plus(r.times(i)),c.s=u.s=p.s,d=H(u,i,o,1).minus(p).abs().cmp(H(c,n,o,1).minus(p).abs())<1?[u,i]:[c,n],f.precision=l,R=!0,d};w.toHexadecimal=w.toHex=function(t,e){return Qt(this,16,t,e)};w.toNearest=function(t,e){var n=this,i=n.constructor;if(n=new i(n),t==null){if(!n.d)return n;t=new i(1),e=i.rounding}else{if(t=new i(t),e===void 0?e=i.rounding:ce(e,0,8),!n.d)return t.s?n:t;if(!t.d)return t.s&&(t.s=n.s),t}return t.d[0]?(R=!1,n=H(n,t,0,e,1).times(t),R=!0,C(n)):(t.s=n.s,n=t),n};w.toNumber=function(){return+this};w.toOctal=function(t,e){return Qt(this,8,t,e)};w.toPower=w.pow=function(t){var e,n,i,r,o,s,a=this,c=a.constructor,u=+(t=new c(t));if(!a.d||!t.d||!a.d[0]||!t.d[0])return new c($(+a,u));if(a=new c(a),a.eq(1))return a;if(i=c.precision,o=c.rounding,t.eq(1))return C(a,i,o);if(e=oe(t.e/L),e>=t.d.length-1&&(n=u<0?-u:u)<=Ji)return r=Dn(c,a,n,i),t.s<0?new c(1).div(r):C(r,i,o);if(s=a.s,s<0){if(e<t.d.length-1)return new c(NaN);if((t.d[e]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return n=$(+a,u),e=n==0||!isFinite(n)?oe(u*(Math.log("0."+re(a.d))/Math.LN10+a.e+1)):new c(n+"").e,e>c.maxE+1||e<c.minE-1?new c(e>0?s/0:0):(R=!1,c.rounding=a.s=1,n=Math.min(12,(e+"").length),r=Zt(t.times(Ce(a,i+n)),i),r.d&&(r=C(r,i+5,1),$e(r.d,i,o)&&(e=i+10,r=C(Zt(t.times(Ce(a,e+n)),e),e+5,1),+re(r.d).slice(i+1,i+15)+1==1e14&&(r=C(r,i+1,0)))),r.s=s,R=!0,c.rounding=o,C(r,i,o))};w.toPrecision=function(t,e){var n,i=this,r=i.constructor;return t===void 0?n=we(i,i.e<=r.toExpNeg||i.e>=r.toExpPos):(ce(t,1,Ne),e===void 0?e=r.rounding:ce(e,0,8),i=C(new r(i),t,e),n=we(i,t<=i.e||i.e<=r.toExpNeg,t)),i.isNeg()&&!i.isZero()?"-"+n:n};w.toSignificantDigits=w.toSD=function(t,e){var n=this,i=n.constructor;return t===void 0?(t=i.precision,e=i.rounding):(ce(t,1,Ne),e===void 0?e=i.rounding:ce(e,0,8)),C(new i(n),t,e)};w.toString=function(){var t=this,e=t.constructor,n=we(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()&&!t.isZero()?"-"+n:n};w.truncated=w.trunc=function(){return C(new this.constructor(this),this.e+1,1)};w.valueOf=w.toJSON=function(){var t=this,e=t.constructor,n=we(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()?"-"+n:n};function re(t){var e,n,i,r=t.length-1,o="",s=t[0];if(r>0){for(o+=s,e=1;e<r;e++)i=t[e]+"",n=L-i.length,n&&(o+=Se(n)),o+=i;s=t[e],i=s+"",n=L-i.length,n&&(o+=Se(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function ce(t,e,n){if(t!==~~t||t<e||t>n)throw Error(Ke+t)}function $e(t,e,n,i){var r,o,s,a;for(o=t[0];o>=10;o/=10)--e;return--e<0?(e+=L,r=0):(r=Math.ceil((e+1)/L),e%=L),o=$(10,L-e),a=t[r]%o|0,i==null?e<3?(e==0?a=a/100|0:e==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)&&(t[r+1]/o/100|0)==$(10,e-2)-1||(a==o/2||a==0)&&(t[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||n<4)&&a==9999||!i&&n>3&&a==4999):s=((i||n<4)&&a+1==o||!i&&n>3&&a+1==o/2)&&(t[r+1]/o/1e3|0)==$(10,e-3)-1,s}function gt(t,e,n){for(var i,r=[0],o,s=0,a=t.length;s<a;){for(o=r.length;o--;)r[o]*=e;for(r[0]+=zt.indexOf(t.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 er(t,e){var n,i,r;if(e.isZero())return e;i=e.d.length,i<32?(n=Math.ceil(i/3),r=(1/ht(4,n)).toString()):(n=16,r="2.3283064365386962890625e-10"),t.precision+=n,e=We(t,1,e.times(r),new t(1));for(var o=n;o--;){var s=e.times(e);e=s.times(s).minus(s).times(8).plus(1)}return t.precision-=n,e}var H=function(){function t(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 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,p,b,f,y,g,P,k,A,h,T,S,K,_,U,M,D,v=i.constructor,W=i.s==r.s?1:-1,G=i.d,F=r.d;if(!G||!G[0]||!F||!F[0])return new v(!i.s||!r.s||(G?F&&G[0]==F[0]:!F)?NaN:G&&G[0]==0||!F?W*0:W/0);for(c?(p=1,l=i.e-r.e):(c=fe,p=L,l=oe(i.e/p)-oe(r.e/p)),M=F.length,_=G.length,g=new v(W),P=g.d=[],m=0;F[m]==(G[m]||0);m++);if(F[m]>(G[m]||0)&&l--,o==null?(T=o=v.precision,s=v.rounding):a?T=o+(i.e-r.e)+1:T=o,T<0)P.push(1),b=!0;else{if(T=T/p+2|0,m=0,M==1){for(d=0,F=F[0],T++;(m<_||d)&&T--;m++)S=d*c+(G[m]||0),P[m]=S/F|0,d=S%F|0;b=d||m<_}else{for(d=c/(F[0]+1)|0,d>1&&(F=t(F,d,c),G=t(G,d,c),M=F.length,_=G.length),K=M,k=G.slice(0,M),A=k.length;A<M;)k[A++]=0;D=F.slice(),D.unshift(0),U=F[0],F[1]>=c/2&&++U;do d=0,u=e(F,k,M,A),u<0?(h=k[0],M!=A&&(h=h*c+(k[1]||0)),d=h/U|0,d>1?(d>=c&&(d=c-1),f=t(F,d,c),y=f.length,A=k.length,u=e(f,k,y,A),u==1&&(d--,n(f,M<y?D:F,y,c))):(d==0&&(u=d=1),f=F.slice()),y=f.length,y<A&&f.unshift(0),n(k,f,A,c),u==-1&&(A=k.length,u=e(F,k,M,A),u<1&&(d++,n(k,M<A?D:F,A,c))),A=k.length):u===0&&(d++,k=[0]),P[m++]=d,u&&k[0]?k[A++]=G[K]||0:(k=[G[K]],A=1);while((K++<_||k[0]!==void 0)&&T--);b=k[0]!==void 0}P[0]||P.shift()}if(p==1)g.e=l,Ln=b;else{for(m=1,d=P[0];d>=10;d/=10)m++;g.e=m+l*p-1,C(g,a?o+g.e+1:o,s,b)}return g}}();function C(t,e,n,i){var r,o,s,a,c,u,l,m,d,p=t.constructor;e:if(e!=null){if(m=t.d,!m)return t;for(r=1,a=m[0];a>=10;a/=10)r++;if(o=e-r,o<0)o+=L,s=e,l=m[d=0],c=l/$(10,r-s-1)%10|0;else if(d=Math.ceil((o+1)/L),a=m.length,d>=a)if(i){for(;a++<=d;)m.push(0);l=c=0,r=1,o%=L,s=o-L+1}else break e;else{for(l=a=m[d],r=1;a>=10;a/=10)r++;o%=L,s=o-L+r,c=s<0?0:l/$(10,r-s-1)%10|0}if(i=i||e<0||m[d+1]!==void 0||(s<0?l:l%$(10,r-s-1)),u=n<4?(c||i)&&(n==0||n==(t.s<0?3:2)):c>5||c==5&&(n==4||i||n==6&&(o>0?s>0?l/$(10,r-s):0:m[d-1])%10&1||n==(t.s<0?8:7)),e<1||!m[0])return m.length=0,u?(e-=t.e+1,m[0]=$(10,(L-e%L)%L),t.e=-e||0):m[0]=t.e=0,t;if(o==0?(m.length=d,a=1,d--):(m.length=d+1,a=$(10,L-o),m[d]=s>0?(l/$(10,r-s)%$(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&&(t.e++,m[0]==fe&&(m[0]=1));break}else{if(m[d]+=a,m[d]!=fe)break;m[d--]=0,a=1}for(o=m.length;m[--o]===0;)m.pop()}return R&&(t.e>p.maxE?(t.d=null,t.e=NaN):t.e<p.minE&&(t.e=0,t.d=[0])),t}function we(t,e,n){if(!t.isFinite())return vn(t);var i,r=t.e,o=re(t.d),s=o.length;return e?(n&&(i=n-s)>0?o=o.charAt(0)+"."+o.slice(1)+Se(i):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(t.e<0?"e":"e+")+t.e):r<0?(o="0."+Se(-r-1)+o,n&&(i=n-s)>0&&(o+=Se(i))):r>=s?(o+=Se(r+1-s),n&&(i=n-r-1)>0&&(o=o+"."+Se(i))):((i=r+1)<s&&(o=o.slice(0,i)+"."+o.slice(i)),n&&(i=n-s)>0&&(r+1===s&&(o+="."),o+=Se(i))),o}function Tt(t,e){var n=t[0];for(e*=L;n>=10;n/=10)e++;return e}function Pt(t,e,n){if(e>$i)throw R=!0,n&&(t.precision=n),Error(Rn);return C(new t(wt),e,1,!0)}function ye(t,e,n){if(e>jt)throw Error(Rn);return C(new t(At),e,n,!0)}function _n(t){var e=t.length-1,n=e*L+1;if(e=t[e],e){for(;e%10==0;e/=10)n--;for(e=t[0];e>=10;e/=10)n++}return n}function Se(t){for(var e="";t--;)e+="0";return e}function Dn(t,e,n,i){var r,o=new t(1),s=Math.ceil(i/L+4);for(R=!1;;){if(n%2&&(o=o.times(e),Kn(o.d,s)&&(r=!0)),n=oe(n/2),n===0){n=o.d.length-1,r&&o.d[n]===0&&++o.d[n];break}e=e.times(e),Kn(e.d,s)}return R=!0,o}function Cn(t){return t.d[t.d.length-1]&1}function Fn(t,e,n){for(var i,r,o=new t(e[0]),s=0;++s<e.length;){if(r=new t(e[s]),!r.s){o=r;break}i=o.cmp(r),(i===n||i===0&&o.s===n)&&(o=r)}return o}function Zt(t,e){var n,i,r,o,s,a,c,u=0,l=0,m=0,d=t.constructor,p=d.rounding,b=d.precision;if(!t.d||!t.d[0]||t.e>17)return new d(t.d?t.d[0]?t.s<0?0:1/0:1:t.s?t.s<0?0:t:0/0);for(e==null?(R=!1,c=b):c=e,a=new d(.03125);t.e>-2;)t=t.times(a),m+=5;for(i=Math.log($(2,m))/Math.LN10*2+5|0,c+=i,n=o=s=new d(1),d.precision=c;;){if(o=C(o.times(t),c,1),n=n.times(++l),a=s.plus(H(o,n,c,1)),re(a.d).slice(0,c)===re(s.d).slice(0,c)){for(r=m;r--;)s=C(s.times(s),c,1);if(e==null)if(u<3&&$e(s.d,c-i,p,u))d.precision=c+=10,n=o=a=new d(1),l=0,u++;else return C(s,d.precision=b,p,R=!0);else return d.precision=b,s}s=a}}function Ce(t,e){var n,i,r,o,s,a,c,u,l,m,d,p=1,b=10,f=t,y=f.d,g=f.constructor,P=g.rounding,k=g.precision;if(f.s<0||!y||!y[0]||!f.e&&y[0]==1&&y.length==1)return new g(y&&!y[0]?-1/0:f.s!=1?NaN:y?0:f);if(e==null?(R=!1,l=k):l=e,g.precision=l+=b,n=re(y),i=n.charAt(0),Math.abs(o=f.e)<15e14){for(;i<7&&i!=1||i==1&&n.charAt(1)>3;)f=f.times(t),n=re(f.d),i=n.charAt(0),p++;o=f.e,i>1?(f=new g("0."+n),o++):f=new g(i+"."+n.slice(1))}else return u=Pt(g,l+2,k).times(o+""),f=Ce(new g(i+"."+n.slice(1)),l-b).plus(u),g.precision=k,e==null?C(f,k,P,R=!0):f;for(m=f,c=s=f=H(f.minus(1),f.plus(1),l,1),d=C(f.times(f),l,1),r=3;;){if(s=C(s.times(d),l,1),u=c.plus(H(s,new g(r),l,1)),re(u.d).slice(0,l)===re(c.d).slice(0,l))if(c=c.times(2),o!==0&&(c=c.plus(Pt(g,l+2,k).times(o+""))),c=H(c,new g(p),l,1),e==null)if($e(c.d,l-b,P,a))g.precision=l+=b,u=s=f=H(m.minus(1),m.plus(1),l,1),d=C(f.times(f),l,1),r=a=1;else return C(c,g.precision=k,P,R=!0);else return g.precision=k,c;c=u,r+=2}}function vn(t){return String(t.s*t.s/0)}function yt(t,e){var n,i,r;for((n=e.indexOf("."))>-1&&(e=e.replace(".","")),(i=e.search(/e/i))>0?(n<0&&(n=i),n+=+e.slice(i+1),e=e.substring(0,i)):n<0&&(n=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,t.e=n=n-i-1,t.d=[],i=(n+1)%L,n<0&&(i+=L),i<r){for(i&&t.d.push(+e.slice(0,i)),r-=L;i<r;)t.d.push(+e.slice(i,i+=L));e=e.slice(i),i=L-e.length}else i-=r;for(;i--;)e+="0";t.d.push(+e),R&&(t.e>t.constructor.maxE?(t.d=null,t.e=NaN):t.e<t.constructor.minE&&(t.e=0,t.d=[0]))}else t.e=0,t.d=[0];return t}function tr(t,e){var n,i,r,o,s,a,c,u,l;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),En.test(e))return yt(t,e)}else if(e==="Infinity"||e==="NaN")return+e||(t.s=NaN),t.e=NaN,t.d=null,t;if(Zi.test(e))n=16,e=e.toLowerCase();else if(ji.test(e))n=2;else if(Qi.test(e))n=8;else throw Error(Ke+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=t.constructor,s&&(e=e.replace(".",""),a=e.length,o=a-o,r=Dn(i,new i(n),o,o*2)),u=gt(e,n,fe),l=u.length-1,o=l;u[o]===0;--o)u.pop();return o<0?new i(t.s*0):(t.e=Tt(u,l),t.d=u,R=!1,s&&(t=H(t,r,a*4)),c&&(t=t.times(Math.abs(c)<54?$(2,c):et.pow(2,c))),R=!0,t)}function nr(t,e){var n,i=e.d.length;if(i<3)return e.isZero()?e:We(t,2,e,e);n=1.4*Math.sqrt(i),n=n>16?16:n|0,e=e.times(1/ht(5,n)),e=We(t,2,e,e);for(var r,o=new t(5),s=new t(16),a=new t(20);n--;)r=e.times(e),e=e.times(o.plus(r.times(s.times(r).minus(a))));return e}function We(t,e,n,i,r){var o,s,a,c,u=1,l=t.precision,m=Math.ceil(l/L);for(R=!1,c=n.times(n),a=new t(i);;){if(s=H(a.times(c),new t(e++*e++),l,1),a=r?i.plus(s):i.minus(s),i=H(s.times(c),new t(e++*e++),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 R=!0,s.d.length=m+1,s}function ht(t,e){for(var n=t;--e;)n*=t;return n}function Wn(t,e){var n,i=e.s<0,r=ye(t,t.precision,1),o=r.times(.5);if(e=e.abs(),e.lte(o))return Be=i?4:1,e;if(n=e.divToInt(r),n.isZero())Be=i?3:2;else{if(e=e.minus(n.times(r)),e.lte(o))return Be=Cn(n)?i?2:3:i?4:1,e;Be=Cn(n)?i?1:4:i?3:2}return e.minus(r).abs()}function Qt(t,e,n,i){var r,o,s,a,c,u,l,m,d,p=t.constructor,b=n!==void 0;if(b?(ce(n,1,Ne),i===void 0?i=p.rounding:ce(i,0,8)):(n=p.precision,i=p.rounding),!t.isFinite())l=vn(t);else{for(l=we(t),s=l.indexOf("."),b?(r=2,e==16?n=n*4-3:e==8&&(n=n*3-2)):r=e,s>=0&&(l=l.replace(".",""),d=new p(1),d.e=l.length-s,d.d=gt(we(d),10,r),d.e=d.d.length),m=gt(l,10,r),o=c=m.length;m[--c]==0;)m.pop();if(!m[0])l=b?"0p+0":"0";else{if(s<0?o--:(t=new p(t),t.d=m,t.e=o,t=H(t,d,n,i,0,r),m=t.d,o=t.e,u=Ln),s=m[n],a=r/2,u=u||m[n+1]!==void 0,u=i<4?(s!==void 0||u)&&(i===0||i===(t.s<0?3:2)):s>a||s===a&&(i===4||u||i===6&&m[n-1]&1||i===(t.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+=zt.charAt(m[s]);if(b){if(c>1)if(e==16||e==8){for(s=e==16?4:3,--c;c%s;c++)l+="0";for(m=gt(l,r,e),c=m.length;!m[c-1];--c);for(s=1,l="1.";s<c;s++)l+=zt.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=(e==16?"0x":e==2?"0b":e==8?"0o":"")+l}return t.s<0?"-"+l:l}function Kn(t,e){if(t.length>e)return t.length=e,!0}function ir(t){return new this(t).abs()}function rr(t){return new this(t).acos()}function or(t){return new this(t).acosh()}function sr(t,e){return new this(t).plus(e)}function ar(t){return new this(t).asin()}function ur(t){return new this(t).asinh()}function cr(t){return new this(t).atan()}function lr(t){return new this(t).atanh()}function mr(t,e){t=new this(t),e=new this(e);var n,i=this.precision,r=this.rounding,o=i+4;return!t.s||!e.s?n=new this(NaN):!t.d&&!e.d?(n=ye(this,o,1).times(e.s>0?.25:.75),n.s=t.s):!e.d||t.isZero()?(n=e.s<0?ye(this,i,r):new this(0),n.s=t.s):!t.d||e.isZero()?(n=ye(this,o,1).times(.5),n.s=t.s):e.s<0?(this.precision=o,this.rounding=1,n=this.atan(H(t,e,o,1)),e=ye(this,o,1),this.precision=i,this.rounding=r,n=t.s<0?n.minus(e):n.plus(e)):n=this.atan(H(t,e,o,1)),n}function dr(t){return new this(t).cbrt()}function pr(t){return C(t=new this(t),t.e+1,2)}function fr(t,e,n){return new this(t).clamp(e,n)}function br(t){if(!t||typeof t!="object")throw Error(kt+"Object expected");var e,n,i,r=t.defaults===!0,o=["precision",1,Ne,"rounding",0,8,"toExpNeg",-ve,0,"toExpPos",0,ve,"maxE",0,ve,"minE",-ve,0,"modulo",0,9];for(e=0;e<o.length;e+=3)if(n=o[e],r&&(this[n]=Yt[n]),(i=t[n])!==void 0)if(oe(i)===i&&i>=o[e+1]&&i<=o[e+2])this[n]=i;else throw Error(Ke+n+": "+i);if(n="crypto",r&&(this[n]=Yt[n]),(i=t[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(Mn);else this[n]=!1;else throw Error(Ke+n+": "+i);return this}function gr(t){return new this(t).cos()}function yr(t){return new this(t).cosh()}function Vn(t){var e,n,i;function r(o){var s,a,c,u=this;if(!(u instanceof r))return new r(o);if(u.constructor=r,Nn(o)){u.s=o.s,R?!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++;R?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}if(o*0!==0){o||(u.s=NaN),u.e=NaN,u.d=null;return}return yt(u,o.toString())}if(c==="string")return(a=o.charCodeAt(0))===45?(o=o.slice(1),u.s=-1):(a===43&&(o=o.slice(1)),u.s=1),En.test(o)?yt(u,o):tr(u,o);if(c==="bigint")return o<0?(o=-o,u.s=-1):u.s=1,yt(u,o.toString());throw Error(Ke+o)}if(r.prototype=w,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=br,r.clone=Vn,r.isDecimal=Nn,r.abs=ir,r.acos=rr,r.acosh=or,r.add=sr,r.asin=ar,r.asinh=ur,r.atan=cr,r.atanh=lr,r.atan2=mr,r.cbrt=dr,r.ceil=pr,r.clamp=fr,r.cos=gr,r.cosh=yr,r.div=wr,r.exp=Ar,r.floor=Pr,r.hypot=kr,r.ln=Tr,r.log=hr,r.log10=Ir,r.log2=Br,r.max=xr,r.min=Sr,r.mod=Cr,r.mul=Kr,r.pow=Nr,r.random=Lr,r.round=Rr,r.sign=Mr,r.sin=Or,r.sinh=Er,r.sqrt=_r,r.sub=Dr,r.sum=Fr,r.tan=vr,r.tanh=Wr,r.trunc=Vr,t===void 0&&(t={}),t&&t.defaults!==!0)for(i=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<i.length;)t.hasOwnProperty(n=i[e++])||(t[n]=this[n]);return r.config(t),r}function wr(t,e){return new this(t).div(e)}function Ar(t){return new this(t).exp()}function Pr(t){return C(t=new this(t),t.e+1,3)}function kr(){var t,e,n=new this(0);for(R=!1,t=0;t<arguments.length;)if(e=new this(arguments[t++]),e.d)n.d&&(n=n.plus(e.times(e)));else{if(e.s)return R=!0,new this(1/0);n=e}return R=!0,n.sqrt()}function Nn(t){return t instanceof et||t&&t.toStringTag===On||!1}function Tr(t){return new this(t).ln()}function hr(t,e){return new this(t).log(e)}function Br(t){return new this(t).log(2)}function Ir(t){return new this(t).log(10)}function xr(){return Fn(this,arguments,-1)}function Sr(){return Fn(this,arguments,1)}function Cr(t,e){return new this(t).mod(e)}function Kr(t,e){return new this(t).mul(e)}function Nr(t,e){return new this(t).pow(e)}function Lr(t){var e,n,i,r,o=0,s=new this(1),a=[];if(t===void 0?t=this.precision:ce(t,1,Ne),i=Math.ceil(t/L),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(Mn);else for(;o<i;)a[o++]=Math.random()*1e7|0;for(i=a[--o],t%=L,i&&t&&(r=$(10,L-t),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-=L)a.shift();for(i=1,r=a[0];r>=10;r/=10)i++;i<L&&(n-=L-i)}return s.e=n,s.d=a,s}function Rr(t){return C(t=new this(t),t.e+1,this.rounding)}function Mr(t){return t=new this(t),t.d?t.d[0]?t.s:0*t.s:t.s||NaN}function Or(t){return new this(t).sin()}function Er(t){return new this(t).sinh()}function _r(t){return new this(t).sqrt()}function Dr(t,e){return new this(t).sub(e)}function Fr(){var t=0,e=arguments,n=new this(e[t]);for(R=!1;n.s&&++t<e.length;)n=n.plus(e[t]);return R=!0,C(n,this.precision,this.rounding)}function vr(t){return new this(t).tan()}function Wr(t){return new this(t).tanh()}function Vr(t){return C(t=new this(t),t.e+1,1)}w[Symbol.for("nodejs.util.inspect.custom")]=w.toString;w[Symbol.toStringTag]="Decimal";var et=w.constructor=Vn(Yt);wt=new et(wt);At=new et(At);var ee=et;var ui=j(require("big.js")),po=j(require("bn.js"));var tt=require("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 n=e.map(i=>typeof i=="object"?JSON.stringify(i):i).join(", ");throw new Error(n)}warning(...e){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...e),this):this}info(...e){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...e),this):this}debug(...e){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...e),this):this}},qn={},qr={};function ne(t){let e=(0,tt.get)(qn,t);if(!e){let n=(0,tt.get)(qr,t);e=new Jt({name:t,logLevel:n}),(0,tt.set)(qn,t,e)}return e}var Le=require("@solana/spl-token"),tn=require("@solana/web3.js");var $t=ne("CobaltX_accountInfo_util");async function nt(t,e,n){let{batchRequest:i,commitment:r="confirmed",chunkCount:o=100}={batchRequest:!1,...n},s=en(e,o),a=new Array(s.length).fill([]);if(i){let c=s.map(m=>{let d=t._buildArgs([m.map(p=>p.toBase58())],r,"base64");return{methodName:"getMultipleAccounts",args:d}}),u=en(c,10);a=(await(await Promise.all(u.map(async m=>await t._rpcBatchRequest(m)))).flat()).map(m=>(m.error&&$t.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${m.error.message}`),m.result.value.map(d=>{if(d){let{data:p,executable:b,lamports:f,owner:y,rentEpoch:g}=d;return p.length!==2&&p[1]!=="base64"&&$t.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(p[0],"base64"),executable:b,lamports:f,owner:new tn.PublicKey(y),rentEpoch:g}}return null})))}else try{a=await Promise.all(s.map(c=>t.getMultipleAccountsInfo(c,r)))}catch(c){c instanceof Error&&$t.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return a.flat()}async function Me(t,e,n){let i=await nt(t,e.map(r=>r.pubkey),n);return e.map((r,o)=>({...r,accountInfo:i[o]}))}async function nn({connection:t,mints:e,network:n,config:i}){var s,a,c;if(e.length===0)return{};let r=await Me(t,e.map(u=>({pubkey:it(u,n)})),i),o={};for(let u of r){if(!u.accountInfo||u.accountInfo.data.length<Le.MINT_SIZE){console.log("invalid mint account",u.pubkey.toBase58());continue}let l=(0,Le.unpackMint)(u.pubkey,u.accountInfo,(s=u.accountInfo)==null?void 0:s.owner);o[u.pubkey.toString()]={...l,programId:((a=u.accountInfo)==null?void 0:a.owner)||Le.TOKEN_PROGRAM_ID,feeConfig:(c=(0,Le.getTransferFeeConfig)(l))!=null?c:void 0}}return o[tn.PublicKey.default.toBase58()]=o[be(n).WSOLMint.toBase58()],o}var Ve=j(require("bn.js"));var Un=9007199254740991;function Ae(t){let e=ne("CobaltX_parseBigNumberish");if(t instanceof Ve.default)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new Ve.default(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=Un||t<=-Un)&&e.logWithError(`BigNumberish number overflow: ${t}`),new Ve.default(String(t))):typeof t=="bigint"?new Ve.default(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new Ve.default(0))}var Gr=require("@solana/spl-token"),Xr=require("@solana/web3.js");var Pe=require("@solana/web3.js");var Ur={["sooneth"]:{NATIVE_TOKEN_SYMBOL:"ETH",SWAP_HOST:"https://trade-api.cobaltx.io",BASE_HOST:"https://api.cobaltx.io",OWNER_BASE_HOST:"https://api.cobaltx.io",SERVICE_BASE_HOST:"https://api.cobaltx.io",MONITOR_BASE_HOST:"https://api.cobaltx.io",SERVICE_1_BASE_HOST:"https://api.cobaltx.io",ANALYTICS_BASE_HOST:"https://api.cobaltx.io",GITHUB_TOKEN_LIST_URL:"https://raw.githubusercontent.com/cobaltx-io/tokens/main/tokens.json",WSOL_MINT_ADDRESS:"So11111111111111111111111111111111111111112",GITHUB_LOGO_URL:"https://raw.githubusercontent.com/cobaltx-io/tokens/main/logo/So11111111111111111111111111111111111111112.png",LOOKUP_TABLE_CACHE:"6fa5xTGwoYJPMLMXaQ4tQFKMoYvXuvsJFLigMJ9a5QeB",CLMM_PROGRAMM_ID:"2TnjBuwqyBB9to5jURagDT7jLmBPefGRiKL2yh1zPZ4V",BONK_MINT_ADDRESS:"71kRXzJMvSeArtXYNEWa8KAjpRJosdMQ7Dpgy5Jt5zfd",SOL_MINT_ADDRESS:"ERFzpDteGNo8LTDKW1WwVGrkRMmA2y9WZHXNHxMA6BSV",USDC_MINT_ADDRESS:"ExYxyorY2x3h8gLcuypnHFQV3F36rmMkQVn7HHV8mUy9",USDT_MINT_ADDRESS:"742wcXVzkhNuEePAot7L3GvPseh93pvYFPgyHLX8mUy9",FULL_TOKEN_NAME:"Wrapped Ethereum",ETH_MINT_ADDRESS:"71kRXzJMvSeArtXYNEWa8KAjpRJosdMQ7Dpgy5Jt5zfd",WRAPPED_TOKEN_SYMBOL:"WETH",INPUT_MINT_ADDRESS:Pe.PublicKey.default.toString(),OUTPUT_MINT_ADDRESS:"742wcXVzkhNuEePAot7L3GvPseh93pvYFPgyHLX8mUy9",POPULAR_TOKENS:{SOL:Pe.PublicKey.default.toString(),ETH:"71kRXzJMvSeArtXYNEWa8KAjpRJosdMQ7Dpgy5Jt5zfd",USDC:"ExYxyorY2x3h8gLcuypnHFQV3F36rmMkQVn7HHV8KjtA",USDT:"742wcXVzkhNuEePAot7L3GvPseh93pvYFPgyHLX8mUy9"},WSOL_DECIMALS:9},["svmbnb"]:{NATIVE_TOKEN_SYMBOL:"BNB",SWAP_HOST:"https://trade-api.svmbnb.cobaltx.io",BASE_HOST:"https://api.svmbnb.cobaltx.io",OWNER_BASE_HOST:"https://api.svmbnb.cobaltx.io",SERVICE_BASE_HOST:"https://api.svmbnb.cobaltx.io",MONITOR_BASE_HOST:"https://api.svmbnb.cobaltx.io",SERVICE_1_BASE_HOST:"https://api.svmbnb.cobaltx.io",ANALYTICS_BASE_HOST:"https://api.svmbnb.cobaltx.io",GITHUB_TOKEN_LIST_URL:"https://raw.githubusercontent.com/cobaltx-io/svmbnb-tokens/main/tokens.json",WSOL_MINT_ADDRESS:"So11111111111111111111111111111111111111112",GITHUB_LOGO_URL:"https://raw.githubusercontent.com/cobaltx-io/svmbnb-tokens/main/logo/So11111111111111111111111111111111111111112.svg",LOOKUP_TABLE_CACHE:"GSR5XQGWhpzV9TTduBJR6qPNjYsepMQSGkpaqfrbrW9w",CLMM_PROGRAMM_ID:"6f1b3xyVZbnWMHXBjgW1KPwxmPAgXcRdrvKNn4Nmf1Cn",ETH_MINT_ADDRESS:"H3xpFH1yN5E1zFdAoBrC9Y7m7RfJUeQNLvkHi8kNf9Qu",USDC_MINT_ADDRESS:"5odzAHDpDETYhupMkc6kjiYen3K2nrf8oPmvqmsoNW4L",USDT_MINT_ADDRESS:"s8cRDxnp3VxjB6khRnGDdxv6QbCUPyY9Vn1bgSQQsnG",SOL_MINT_ADDRESS:"So11111111111111111111111111111111111111112",FULL_TOKEN_NAME:"Wrapped BNB",WRAPPED_TOKEN_SYMBOL:"WBNB",INPUT_MINT_ADDRESS:Pe.PublicKey.default.toBase58(),OUTPUT_MINT_ADDRESS:"ABoT7umUXnx8RtJTeRqKB6myebVjP2wdJGQuV23jVVH3",POPULAR_TOKENS:{SOL:Pe.PublicKey.default.toString(),ETH:"H3xpFH1yN5E1zFdAoBrC9Y7m7RfJUeQNLvkHi8kNf9Qu",USDC:"5odzAHDpDETYhupMkc6kjiYen3K2nrf8oPmvqmsoNW4L",USDT:"s8cRDxnp3VxjB6khRnGDdxv6QbCUPyY9Vn1bgSQQsnG"},WSOL_DECIMALS:9},["svmbnb_testnet"]:{NATIVE_TOKEN_SYMBOL:"BNB",SWAP_HOST:"https://trade-api.svmbnb.cobaltx.io",BASE_HOST:"https://api.testnet.svmbnb.cobaltx.io",OWNER_BASE_HOST:"https://api.testnet.svmbnb.cobaltx.io",SERVICE_BASE_HOST:"https://api.testnet.svmbnb.cobaltx.io",MONITOR_BASE_HOST:"https://api.testnet.svmbnb.cobaltx.io",SERVICE_1_BASE_HOST:"https://api.testnet.svmbnb.cobaltx.io",ANALYTICS_BASE_HOST:"https://api.testnet.svmbnb.cobaltx.io",GITHUB_TOKEN_LIST_URL:"https://raw.githubusercontent.com/cobaltx-io/svmbnb-testnet-tokens/main/tokens.json",WSOL_MINT_ADDRESS:"So11111111111111111111111111111111111111112",GITHUB_LOGO_URL:"https://raw.githubusercontent.com/cobaltx-io/svmbnb-testnet-tokens/main/logo/So11111111111111111111111111111111111111112.svg",LOOKUP_TABLE_CACHE:"D79gSiTNV9pyLPJyscW5yZYwdPVDrtKsamL3ZfQi6JiM",CLMM_PROGRAMM_ID:"FgycD57kcCZsjpoTAi2u67GTPxm59bPEhycL2Lw1icm1",ETH_MINT_ADDRESS:"5aLr3sV4UNVcMB6CiA3PZTWbgVBRNyMdEp1s5LNfhR95",USDC_MINT_ADDRESS:"jrhUNRxEDpFmGV3sqaWyveS7bVtRQgtHsfBTCdjfMBw",USDT_MINT_ADDRESS:"Ex86C4gmdjvPRNrfyvsyejbjkP6RstNaBC5g3itZw2iv",FULL_TOKEN_NAME:"Wrapped BNB",WRAPPED_TOKEN_SYMBOL:"WBNB",INPUT_MINT_ADDRESS:"bnb",OUTPUT_MINT_ADDRESS:"jrhUNRxEDpFmGV3sqaWyveS7bVtRQgtHsfBTCdjfMBw",POPULAR_TOKENS:{SOL:Pe.PublicKey.default.toString(),ETH:"5aLr3sV4UNVcMB6CiA3PZTWbgVBRNyMdEp1s5LNfhR95",USDC:"jrhUNRxEDpFmGV3sqaWyveS7bVtRQgtHsfBTCdjfMBw",USDT:"Ex86C4gmdjvPRNrfyvsyejbjkP6RstNaBC5g3itZw2iv"},WSOL_DECIMALS:9},["svmbase_testnet"]:{NATIVE_TOKEN_SYMBOL:"ETH",SWAP_HOST:"https://trade-api.testnet.svmbase.cobaltx.io",BASE_HOST:"https://api.testnet.svmbase.cobaltx.io",OWNER_BASE_HOST:"https://api.testnet.svmbase.cobaltx.io",SERVICE_BASE_HOST:"https://api.testnet.svmbase.cobaltx.io",MONITOR_BASE_HOST:"https://api.testnet.svmbase.cobaltx.io",SERVICE_1_BASE_HOST:"https://api.testnet.svmbase.cobaltx.io",ANALYTICS_BASE_HOST:"https://api.testnet.svmbase.cobaltx.io",GITHUB_TOKEN_LIST_URL:"https://raw.githubusercontent.com/cobaltx-io/svmbase-testnet-tokens/main/tokens.json",WSOL_MINT_ADDRESS:"So11111111111111111111111111111111111111112",GITHUB_LOGO_URL:"https://raw.githubusercontent.com/cobaltx-io/svmbase-testnet-tokens/main/logo/So11111111111111111111111111111111111111112.png",LOOKUP_TABLE_CACHE:"AyPMvNmUUY2jwZ75NxhkLYPraQGNk5DssVfP4TnMcPJF",CLMM_PROGRAMM_ID:"DnZnBqJKiGSYHUHYvkXAbQmkMbwrjfgo4orR7jWyMsik",ETH_MINT_ADDRESS:"71kRXzJMvSeArtXYNEWa8KAjpRJosdMQ7Dpgy5Jt5zfd",USDC_MINT_ADDRESS:"63tPXWPnYeZ9hA3dJsAY5RcQ8YbwEz8uZ5nKu3uFD1aK",USDT_MINT_ADDRESS:"4fyX7hSmPetQC2wRS3YVAhWeFzif7WStarKwTvCXrBtD",FULL_TOKEN_NAME:"Wrapped Ethereum",WRAPPED_TOKEN_SYMBOL:"WETH",INPUT_MINT_ADDRESS:Pe.PublicKey.default.toString(),OUTPUT_MINT_ADDRESS:"63tPXWPnYeZ9hA3dJsAY5RcQ8YbwEz8uZ5nKu3uFD1aK",POPULAR_TOKENS:{SOL:Pe.PublicKey.default.toString(),ETH:"So11111111111111111111111111111111111111112",USDC:"63tPXWPnYeZ9hA3dJsAY5RcQ8YbwEz8uZ5nKu3uFD1aK",USDT:"4fyX7hSmPetQC2wRS3YVAhWeFzif7WStarKwTvCXrBtD"},WSOL_DECIMALS:9},["soonbase_mainnet"]:{NATIVE_TOKEN_SYMBOL:"ETH",SWAP_HOST:"https://trade-api.soonbase.cobaltx.io",BASE_HOST:"https://api.soonbase.cobaltx.io",OWNER_BASE_HOST:"https://api.soonbase.cobaltx.io",SERVICE_BASE_HOST:"https://api.soonbase.cobaltx.io",MONITOR_BASE_HOST:"https://api.soonbase.cobaltx.io",SERVICE_1_BASE_HOST:"https://api.soonbase.cobaltx.io",ANALYTICS_BASE_HOST:"https://api.soonbase.cobaltx.io",GITHUB_TOKEN_LIST_URL:"https://raw.githubusercontent.com/cobaltx-io/soonbase-tokens/main/tokens.json",WSOL_MINT_ADDRESS:"So11111111111111111111111111111111111111112",GITHUB_LOGO_URL:"https://raw.githubusercontent.com/cobaltx-io/soonbase-tokens/main/logo/So11111111111111111111111111111111111111112.png",LOOKUP_TABLE_CACHE:"FGRusuLycV6nhSPQc9VX55YjT6DCzJFc59mvTTarSTjK",CLMM_PROGRAMM_ID:"6f1b3xyVZbnWMHXBjgW1KPwxmPAgXcRdrvKNn4Nmf1Cn",ETH_MINT_ADDRESS:"71kRXzJMvSeArtXYNEWa8KAjpRJosdMQ7Dpgy5Jt5zfd",USDC_MINT_ADDRESS:"BoYN2f2gLQS4jpvMSV9dAZwfzKJiKGk4NPck5BjXfujo",USDT_MINT_ADDRESS:"J87bysZjwfS3n6KR21cwbdPZVJWNSFcXpWF5kiChAwQH",FULL_TOKEN_NAME:"Wrapped Ethereum",WRAPPED_TOKEN_SYMBOL:"WETH",INPUT_MINT_ADDRESS:Pe.PublicKey.default.toString(),OUTPUT_MINT_ADDRESS:"BoYN2f2gLQS4jpvMSV9dAZwfzKJiKGk4NPck5BjXfujo",POPULAR_TOKENS:{SOL:Pe.PublicKey.default.toString(),ETH:"FkvCG5DcuYCQ1BnPH4ZzTkCdk3VzutgyDAFBec4qAjhh",USDC:"BoYN2f2gLQS4jpvMSV9dAZwfzKJiKGk4NPck5BjXfujo",USDT:"J87bysZjwfS3n6KR21cwbdPZVJWNSFcXpWF5kiChAwQH"},WSOL_DECIMALS:9}},qe=t=>Ur[t];var zr=require("@solana/web3.js");var Gn=require("@solana/spl-token"),V=require("@solana/web3.js");function rn({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var As=[rn({pubkey:Gn.TOKEN_PROGRAM_ID,isWritable:!1}),rn({pubkey:V.SystemProgram.programId,isWritable:!1}),rn({pubkey:V.SYSVAR_RENT_PUBKEY,isWritable:!1})];function Xn({publicKey:t,transformSol:e,network:n}){let i=Hn(t.toString());if(e&&n){let{WSOLMint:r}=be(n);if(i instanceof V.PublicKey)return e&&i.equals(on)?r:i;if(e&&i.toString()===on.toBase58())return r}else if(i instanceof V.PublicKey)return i;if(typeof i=="string"){if(i===V.PublicKey.default.toBase58())return V.PublicKey.default;try{return new V.PublicKey(i)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function Hn(t){try{return new V.PublicKey(t)}catch{return t}}var Hr=new V.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Bt=new V.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),It=new V.PublicKey("SysvarRent111111111111111111111111111111111"),Ps=new V.PublicKey("SysvarC1ock11111111111111111111111111111111"),Ue=new V.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),ks=new V.PublicKey("Sysvar1nstructions1111111111111111111111111"),zn=V.SystemProgram.programId,on=V.PublicKey.default;function be(t){let e=qe(t);return{USDCMint:new V.PublicKey(e.USDC_MINT_ADDRESS),USDTMint:new V.PublicKey(e.USDT_MINT_ADDRESS),WSOLMint:new V.PublicKey(e.WSOL_MINT_ADDRESS),ETHMint:new V.PublicKey(e.ETH_MINT_ADDRESS),BONK_Mint:e.BONK_MINT_ADDRESS?new V.PublicKey(e.BONK_MINT_ADDRESS):V.PublicKey.default,SOL_Mint:e.SOL_MINT_ADDRESS?new V.PublicKey(e.SOL_MINT_ADDRESS):V.PublicKey.default,INPUT_MINT:new V.PublicKey(e.INPUT_MINT_ADDRESS),OUTPUT_MINT:new V.PublicKey(e.OUTPUT_MINT_ADDRESS)}}function it(t,e){return Xn({publicKey:t,transformSol:!0,network:e})}var jn=j(require("toformat")),jr=jn.default,rt=jr;var ot=j(require("big.js")),Zn=j(require("bn.js")),Qn=j(require("decimal.js-light"));var St=ne("module/fraction"),sn=rt(ot.default),st=rt(Qn.default),Qr={[0]:st.ROUND_DOWN,[1]:st.ROUND_HALF_UP,[2]:st.ROUND_UP},Jr={[0]:ot.default.roundDown,[1]:ot.default.roundHalfUp,[2]:ot.default.roundUp},Y=class{constructor(e,n=new Zn.default(1)){this.numerator=Ae(e),this.denominator=Ae(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new Y(this.denominator,this.numerator)}add(e){let n=e instanceof Y?e:new Y(Ae(e));return this.denominator.eq(n.denominator)?new Y(this.numerator.add(n.numerator),this.denominator):new Y(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(e){let n=e instanceof Y?e:new Y(Ae(e));return this.denominator.eq(n.denominator)?new Y(this.numerator.sub(n.numerator),this.denominator):new Y(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(e){let n=e instanceof Y?e:new Y(Ae(e));return new Y(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(e){let n=e instanceof Y?e:new Y(Ae(e));return new Y(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(e,n={groupSeparator:""},i=1){Number.isInteger(e)||St.logWithError(`${e} is not an integer.`),e<=0&&St.logWithError(`${e} is not positive.`),st.set({precision:e+1,rounding:Qr[i]});let r=new st(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return r.toFormat(r.decimalPlaces(),n)}toFixed(e,n={groupSeparator:""},i=1){return Number.isInteger(e)||St.logWithError(`${e} is not an integer.`),e<0&&St.logWithError(`${e} is negative.`),sn.DP=e,sn.RM=Jr[i]||1,new sn(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};var $n=j(require("bn.js"));var Jn=new Y(new $n.default(100)),de=class extends Y{toSignificant(e=5,n,i){return this.mul(Jn).toSignificant(e,n,i)}toFixed(e=2,n,i){return this.mul(Jn).toFixed(e,n,i)}};var qs=ne("CobaltX_price");function en(t,e=1,n=[]){let i=[...t];if(e<=0)return n;for(;i.length;)n.push(i.splice(0,e));return n}var ii=require("@solana/web3.js"),ri=require("@solana/spl-token");var se=require("@solana/web3.js");var le={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"};var ti=require("@solana/spl-token"),ei=ne("CobaltX_txUtil"),ni=1644;function Kt(t){let e=[],n=[];return t.microLamports&&(e.push(se.ComputeBudgetProgram.setComputeUnitPrice({microLamports:t.microLamports})),n.push(le.SetComputeUnitPrice)),t.units&&(e.push(se.ComputeBudgetProgram.setComputeUnitLimit({units:t.units})),n.push(le.SetComputeUnitLimit)),{instructions:e,instructionTypes:n}}async function Ge(t,e){var i,r;let n=e!=null?e:"confirmed";return(r=await((i=t.getLatestBlockhash)==null?void 0:i.call(t,{commitment:n})))==null?void 0:r.blockhash}async function Nt(t,e){return t.getSignatureStatuses([e]),new Promise((n,i)=>{let r=setTimeout(i,6e4);t.onSignature(e,o=>{if(clearTimeout(r),!o.err){n("");return}i(o.err.toString())},"confirmed")})}function $r(t,e){t.length<1&&ei.logWithError(`no instructions provided: ${t.toString()}`),e.length<1&&ei.logWithError(`no signers provided:, ${e.toString()}`);let n=new se.Transaction;n.recentBlockhash="11111111111111111111111111111111",n.feePayer=e[0],n.add(...t);try{return Buffer.from(n.serialize({verifySignatures:!1})).toString("base64").length<ni}catch{return!1}}function ge(t,e){let[n,i]=se.PublicKey.findProgramAddressSync(t,e);return{publicKey:n,nonce:i}}function at({instructions:t,payer:e,signers:n}){return $r(t,[e,...n])}function ut({instructions:t,payer:e,lookupTableAddressAccount:n,recentBlockhash:i=se.Keypair.generate().publicKey.toString()}){let o=new se.TransactionMessage({payerKey:e,recentBlockhash:i,instructions:t}).compileToV0Message(Object.values(n!=null?n:{}));try{return Buffer.from(new se.VersionedTransaction(o).serialize()).toString("base64").length<ni}catch{return!1}}var eo=t=>Buffer.isBuffer(t)?t:t instanceof Uint8Array?Buffer.from(t.buffer,t.byteOffset,t.byteLength):Buffer.from(t),to=t=>{let e=t.serialize({requireAllSignatures:!1,verifySignatures:!1});t instanceof se.VersionedTransaction&&(e=eo(e));try{return e instanceof Buffer?e.toString("base64"):Buffer.from(e).toString("base64")}catch{return e.toString("base64")}};function Oe(t){let e=[];return t.forEach(n=>{n instanceof se.Transaction&&(n.recentBlockhash||(n.recentBlockhash=ti.TOKEN_PROGRAM_ID.toBase58()),n.feePayer||(n.feePayer=se.Keypair.generate().publicKey)),e.push(to(n))}),console.log("simulate tx string:",e),e}function ke(t,e,n){return ge([t.toBuffer(),(n!=null?n:ri.TOKEN_PROGRAM_ID).toBuffer(),e.toBuffer()],new ii.PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}var E=require("@solana/web3.js"),wa=new E.PublicKey("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),Aa=new E.PublicKey("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),Pa=new E.PublicKey("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),ka=new E.PublicKey("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Ta=new E.PublicKey("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),ha=new E.PublicKey("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),Ba=new E.PublicKey("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Ia=new E.PublicKey("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),xa=new E.PublicKey("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Sa=new E.PublicKey("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo");var no=new E.PublicKey("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),io=new E.PublicKey("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),Ca=new E.PublicKey("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Ka=new E.PublicKey("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Na=new E.PublicKey("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),La=new E.PublicKey("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),Ra=new E.PublicKey("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),Ma=new E.PublicKey("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),oi=new E.PublicKey("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),si=new E.PublicKey("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Oa=new E.PublicKey("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),ro=new E.PublicKey("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),oo=new E.PublicKey("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),so=new E.PublicKey("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),Lt=new E.PublicKey("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),ao=new E.PublicKey("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),Rt=new E.PublicKey("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),uo=new E.PublicKey("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix");var Ea={SERUM_MARKET:E.PublicKey.default,OPENBOOK_MARKET:new E.PublicKey("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:E.PublicKey.default,FarmV3:new E.PublicKey("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new E.PublicKey("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new E.PublicKey("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new E.PublicKey("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new E.PublicKey("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new E.PublicKey("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),CLMM_LOCK_PROGRAM_ID:new E.PublicKey("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),CLMM_LOCK_AUTH_ID:new E.PublicKey("8qmHNvu2Kr2C7U8mJL4Vz1vTDxMhVuXKREwU7TNoaVEo"),Router:new E.PublicKey("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:ro,CREATE_CPMM_POOL_AUTH:oo,CREATE_CPMM_POOL_FEE_ACC:so,FEE_DESTINATION_ID:new E.PublicKey("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),LOCK_CPMM_PROGRAM:ao,LCOK_CPMM_AUTH:uo};var pe=j(require("bn.js")),ct=1e4;function Te(t,e,n,i){if(e===void 0)return{amount:t,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=n.epoch<r.newerTransferFee.epoch?r.olderTransferFee:r.newerTransferFee,s=new pe.default(o.maximumFee.toString()),a=n.epoch<r.newerTransferFee.epoch?(Number(r.newerTransferFee.epoch)*n.slotsInEpoch-n.absoluteSlot)*400/1e3:void 0;if(i)if(o.transferFeeBasisPoints===ct){let c=new pe.default(o.maximumFee.toString());return{amount:t.add(c),fee:c,expirationTime:a}}else{let c=Xe(t.mul(new pe.default(ct)),new pe.default(ct-o.transferFeeBasisPoints)),u=new pe.default(o.maximumFee.toString()),l=c.sub(t).gt(u)?t.add(u):c,m=Xe(l.mul(new pe.default(o.transferFeeBasisPoints)),new pe.default(ct)),d=m.gt(s)?s:m;return{amount:l,fee:d,expirationTime:a}}else{let c=Xe(t.mul(new pe.default(o.transferFeeBasisPoints)),new pe.default(ct)),u=c.gt(s)?s:c;return{amount:t,fee:u,expirationTime:a}}}function Xe(t,e){let{div:n,mod:i}=t.divmod(e);return i.gt(new pe.default(0))?n.add(new pe.default(1)):n}var Re=require("@solana/web3.js");async function cn({connection:t,address:e,network:n}){let i=await nt(t,[...new Set(e.map(o=>o.toString()))].map(o=>new Re.PublicKey(o))),r={};for(let o=0;o<e.length;o++){let s=i[o],a=e[o];if(!s)continue;let c=new Re.AddressLookupTableAccount({key:a,state:Re.AddressLookupTableAccount.deserialize(s.data)});r[a.toString()]=c,Mt(n)[a.toString()]=c}return r}function Mt(t){let e=qe(t);return{[e.LOOKUP_TABLE_CACHE]:new Re.AddressLookupTableAccount({key:new Re.PublicKey(e.LOOKUP_TABLE_CACHE),state:Re.AddressLookupTableAccount.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"))})}}var X=require("@solana/web3.js"),ai=j(require("axios"));var Ot=class{constructor(e){this.instructions=[];this.endInstructions=[];this.lookupTableAddress=[];this.signers=[];this.instructionTypes=[];this.endInstructionTypes=[];this.connection=e.connection,this.feePayer=e.feePayer,this.signAllTransactions=e.signAllTransactions,this.owner=e.owner,this.cluster=e.cluster,this.blockhashCommitment=e.blockhashCommitment,this.api=e.api,this.network=e.network}get AllTxData(){return{instructions:this.instructions,endInstructions:this.endInstructions,signers:this.signers,instructionTypes:this.instructionTypes,endInstructionTypes:this.endInstructionTypes,lookupTableAddress:this.lookupTableAddress}}get allInstructions(){return[...this.instructions,...this.endInstructions]}async getComputeBudgetConfig(){var i;let e=(await ai.default.get(`https://solanacompass.com/api/fees?cacheFreshTime=${3e5}`)).data,{avg:n}=(i=e==null?void 0:e[15])!=null?i:{};if(!!n)return{units:6e5,microLamports:Math.min(Math.ceil(n*1e6/6e5),25e3)}}addCustomComputeBudget(e){if(e){let{instructions:n,instructionTypes:i}=Kt(e);return this.instructions.unshift(...n),this.instructionTypes.unshift(...i),!0}return!1}async calComputeBudget({config:e,defaultIns:n}){try{let i=e||await this.getComputeBudgetConfig();if(this.addCustomComputeBudget(i))return;n&&this.instructions.unshift(...n)}catch{n&&this.instructions.unshift(...n)}}addInstruction({instructions:e=[],endInstructions:n=[],signers:i=[],instructionTypes:r=[],endInstructionTypes:o=[],lookupTableAddress:s=[]}){return this.instructions.push(...e),this.endInstructions.push(...n),this.signers.push(...i),this.instructionTypes.push(...r),this.endInstructionTypes.push(...o),this.lookupTableAddress.push(...s.filter(a=>a!==X.PublicKey.default.toString())),this}async versionBuild({txVersion:e,extInfo:n}){return e===0?await this.buildV0({...n||{}}):this.build(n)}build(e){var i;let n=new X.Transaction;return this.allInstructions.length&&n.add(...this.allInstructions),n.feePayer=this.feePayer,((i=this.owner)==null?void 0:i.signer)&&!this.signers.some(r=>r.publicKey.equals(this.owner.publicKey))&&this.signers.push(this.owner.signer),{builder:this,transaction:n,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async r=>{var u;let{recentBlockHash:o,skipPreflight:s=!0,sendAndConfirm:a}=r||{},c=o!=null?o:await Ge(this.connection,this.blockhashCommitment);if(n.recentBlockhash=c,this.signers.length&&n.sign(...this.signers),Oe([n]),(u=this.owner)!=null&&u.isKeyPair)return{txId:a?await(0,X.sendAndConfirmTransaction)(this.connection,n,this.signers.find(m=>m.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:s}):await this.connection.sendRawTransaction(n.serialize(),{skipPreflight:s}),signedTx:n};if(this.signAllTransactions){let l=await this.signAllTransactions([n]);return{txId:await this.connection.sendRawTransaction(l[0].serialize(),{skipPreflight:s}),signedTx:l[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:e||{}}}buildMultiTx(e){var u;let{extraPreBuildData:n=[],extInfo:i}=e,{transaction:r}=this.build(i),o=n.filter(l=>l.transaction.instructions.length>0),s=[r,...o.map(l=>l.transaction)],a=[this.signers,...o.map(l=>l.signers)],c=[...this.instructionTypes,...o.map(l=>l.instructionTypes).flat()];return(u=this.owner)!=null&&u.signer&&a.forEach(l=>{l.some(m=>m.publicKey.equals(this.owner.publicKey))||this.signers.push(this.owner.signer)}),{builder:this,transactions:s,signers:a,instructionTypes:c,execute:async l=>{var g;let{sequentially:m,onTxUpdate:d,skipTxCount:p=0,recentBlockHash:b,skipPreflight:f=!0}=l||{},y=b!=null?b:await Ge(this.connection,this.blockhashCommitment);if((g=this.owner)!=null&&g.isKeyPair){if(m){let P=[],k=0;for(let A of s){if(++k,k<=p)continue;let h=await(0,X.sendAndConfirmTransaction)(this.connection,A,this.signers.find(T=>T.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:f});P.push(h)}return{txIds:P,signedTxs:s}}return{txIds:await await Promise.all(s.map(async P=>(P.recentBlockhash=y,await this.connection.sendRawTransaction(P.serialize(),{skipPreflight:f})))),signedTxs:s}}if(this.signAllTransactions){let P=s.map((A,h)=>(A.recentBlockhash=y,a[h].length&&A.sign(...a[h]),A));Oe(P);let k=await this.signAllTransactions(P);if(m){let A=0,h=[],T=async()=>{if(!k[A])return;let S=await this.connection.sendRawTransaction(k[A].serialize(),{skipPreflight:f});h.push({txId:S,status:"sent",signedTx:k[A]}),d==null||d([...h]),A++,this.connection.onSignature(S,K=>{let _=h.findIndex(U=>U.txId===S);_>-1&&(h[_].status=K.err?"error":"success"),d==null||d([...h]),K.err||T()},"processed"),this.connection.getSignatureStatus(S)};return await T(),{txIds:h.map(S=>S.txId),signedTxs:k}}else{let A=[];for(let h=0;h<k.length;h+=1){let T=await this.connection.sendRawTransaction(k[h].serialize(),{skipPreflight:f});A.push(T)}return{txIds:A,signedTxs:k}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}async versionMultiBuild({extraPreBuildData:e,txVersion:n,extInfo:i}){return n===0?await this.buildV0MultiTx({extraPreBuildData:e,buildProps:i||{}}):this.buildMultiTx({extraPreBuildData:e,extInfo:i})}async buildV0(e){var f;let{lookupTableCache:n={},lookupTableAddress:i=[],forerunCreate:r,recentBlockhash:o,network:s=this.network,...a}=e||{},c={...this.cluster==="devnet"?{}:Mt(s),...n},u=Array.from(new Set([...i,...this.lookupTableAddress])),l=[];for(let y of u)c[y]===void 0&&l.push(new X.PublicKey(y));let m=await cn({connection:this.connection,address:l,network:s});for(let[y,g]of Object.entries(m))c[y]=g;let d=r?X.PublicKey.default.toBase58():o!=null?o:await Ge(this.connection,this.blockhashCommitment),p=new X.TransactionMessage({payerKey:this.feePayer,recentBlockhash:d,instructions:[...this.allInstructions]}).compileToV0Message();((f=this.owner)==null?void 0:f.signer)&&!this.signers.some(y=>y.publicKey.equals(this.owner.publicKey))&&this.signers.push(this.owner.signer);let b=new X.VersionedTransaction(p);return b.sign(this.signers),{builder:this,transaction:b,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async y=>{var k;let{skipPreflight:g=!0,sendAndConfirm:P}=y||{};if(Oe([b]),(k=this.owner)!=null&&k.isKeyPair){let A=await this.connection.sendTransaction(b,{skipPreflight:g});return P&&await Nt(this.connection,A),{txId:A,signedTx:b}}if(this.signAllTransactions){let A=await this.signAllTransactions([b]);return{txId:await this.connection.sendTransaction(A[0],{skipPreflight:g}),signedTx:A[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:a||{}}}async buildV0MultiTx(e){var u;let{extraPreBuildData:n=[],buildProps:i}=e,{transaction:r}=await this.buildV0(i),o=n.filter(l=>l.builder.instructions.length>0),s=[r,...o.map(l=>l.transaction)],a=[this.signers,...o.map(l=>l.signers)],c=[...this.instructionTypes,...o.map(l=>l.instructionTypes).flat()];return(u=this.owner)!=null&&u.signer&&a.forEach(l=>{l.some(m=>m.publicKey.equals(this.owner.publicKey))||this.signers.push(this.owner.signer)}),s.forEach(async(l,m)=>{l.sign(a[m])}),{builder:this,transactions:s,signers:a,instructionTypes:c,buildProps:i,execute:async l=>{var f;let{sequentially:m,onTxUpdate:d,recentBlockHash:p,skipPreflight:b=!0}=l||{};if(p&&s.forEach(y=>y.message.recentBlockhash=p),Oe(s),(f=this.owner)!=null&&f.isKeyPair){if(m){let y=[];for(let g of s){let P=await this.connection.sendTransaction(g,{skipPreflight:b});await Nt(this.connection,P),y.push(P)}return{txIds:y,signedTxs:s}}return{txIds:await Promise.all(s.map(async y=>await this.connection.sendTransaction(y,{skipPreflight:b}))),signedTxs:s}}if(this.signAllTransactions){let y=await this.signAllTransactions(s);if(m){let g=0,P=[],k=async()=>{if(!y[g])return;let A=await this.connection.sendTransaction(y[g],{skipPreflight:b});P.push({txId:A,status:"sent",signedTx:y[g]}),d==null||d([...P]),g++,this.connection.onSignature(A,h=>{let T=P.findIndex(S=>S.txId===A);T>-1&&(P[T].status=h.err?"error":"success"),d==null||d([...P]),h.err||k()},"processed"),this.connection.getSignatureStatus(A)};return k(),{txIds:[],signedTxs:y}}else{let g=[];for(let P=0;P<y.length;P+=1){let k=await this.connection.sendTransaction(y[P],{skipPreflight:b});g.push(k)}return{txIds:g,signedTxs:y}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}async sizeCheckBuild(e){var m;let{splitIns:n=[],computeBudgetConfig:i,...r}=e||{},o=i?Kt(i):{instructions:[],instructionTypes:[]},s=this.signers.reduce((d,p)=>({...d,[p.publicKey.toBase58()]:p}),{}),a=[],c=[],u=[],l=0;if(this.allInstructions.forEach(d=>{let p=[...u,d],b=i?[...o.instructions,...p]:p,y=[...new Set(p.map(g=>g.keys.filter(P=>P.isSigner).map(P=>P.pubkey.toString())).flat()).values()].map(g=>new X.PublicKey(g));if(d!==n[l]&&u.length<12&&(at({instructions:b,payer:this.feePayer,signers:y})||at({instructions:p,payer:this.feePayer,signers:y})))u.push(d);else{if(u.length===0)throw Error("item ins too big");l+=d===n[l]?1:0,at({instructions:i?[...o.instructions,...u]:[...u],payer:this.feePayer,signers:y})?a.push(new X.Transaction().add(...o.instructions,...u)):a.push(new X.Transaction().add(...u)),c.push(Array.from(new Set(u.map(g=>g.keys.filter(P=>P.isSigner).map(P=>P.pubkey.toString())).flat())).map(g=>s[g]).filter(g=>g!==void 0)),u=[d]}}),u.length>0){let p=[...new Set(u.map(b=>b.keys.filter(f=>f.isSigner).map(f=>f.pubkey.toString())).flat()).values()].map(b=>s[b]).filter(b=>b!==void 0);at({instructions:i?[...o.instructions,...u]:[...u],payer:this.feePayer,signers:p.map(b=>b.publicKey)})?a.push(new X.Transaction().add(...o.instructions,...u)):a.push(new X.Transaction().add(...u)),c.push(p)}return a.forEach(d=>d.feePayer=this.feePayer),(m=this.owner)!=null&&m.signer&&c.forEach(d=>{d.some(p=>p.publicKey.equals(this.owner.publicKey))||d.push(this.owner.signer)}),{builder:this,transactions:a,signers:c,instructionTypes:this.instructionTypes,execute:async d=>{var k;let{sequentially:p,onTxUpdate:b,skipTxCount:f=0,recentBlockHash:y,skipPreflight:g=!0}=d||{},P=y!=null?y:await Ge(this.connection,this.blockhashCommitment);if(a.forEach(async(A,h)=>{A.recentBlockhash=P,c[h].length&&A.sign(...c[h])}),Oe(a),(k=this.owner)!=null&&k.isKeyPair){if(p){let A=0,h=[];for(let T of a){if(++A,A<=f){h.push("tx skipped");continue}let S=await(0,X.sendAndConfirmTransaction)(this.connection,T,this.signers.find(K=>K.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:g});h.push(S)}return{txIds:h,signedTxs:a}}return{txIds:await Promise.all(a.map(async A=>await this.connection.sendRawTransaction(A.serialize(),{skipPreflight:g}))),signedTxs:a}}if(this.signAllTransactions){let A=await this.signAllTransactions(a.slice(f,a.length)),h=[...a.slice(0,f),...A];if(p){let T=0,S=[],K=async()=>{if(!h[T])return;T<f&&(S.push({txId:"",status:"success",signedTx:h[T]}),b==null||b([...S]),T++,K());let _=await this.connection.sendRawTransaction(h[T].serialize(),{skipPreflight:g});S.push({txId:_,status:"sent",signedTx:h[T]}),b==null||b([...S]),T++,this.connection.onSignature(_,U=>{let M=S.findIndex(D=>D.txId===_);M>-1&&(S[M].status=U.err?"error":"success"),b==null||b([...S]),U.err||K()},"processed"),this.connection.getSignatureStatus(_)};return await K(),{txIds:S.map(_=>_.txId),signedTxs:h}}else{let T=[];for(let S=0;S<h.length;S+=1){let K=await this.connection.sendRawTransaction(h[S].serialize(),{skipPreflight:g});T.push(K)}return{txIds:T,signedTxs:h}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async sizeCheckBuildV0(e){var k;let{computeBudgetConfig:n,splitIns:i=[],lookupTableCache:r={},lookupTableAddress:o=[],network:s=this.network,...a}=e||{},c={...this.cluster==="devnet"?{}:Mt(s),...r},u=Array.from(new Set([...this.lookupTableAddress,...o])),l=[];for(let A of u)c[A]===void 0&&l.push(new X.PublicKey(A));let m=await cn({connection:this.connection,address:l,network:s});for(let[A,h]of Object.entries(m))c[A]=h;let d=n?Kt(n):{instructions:[],instructionTypes:[]},p=await Ge(this.connection,this.blockhashCommitment),b=this.signers.reduce((A,h)=>({...A,[h.publicKey.toBase58()]:h}),{}),f=[],y=[],g=[],P=0;if(this.allInstructions.forEach(A=>{let h=[...g,A],T=n?[...d.instructions,...h]:h;if(A!==i[P]&&g.length<12&&(ut({instructions:T,payer:this.feePayer,lookupTableAddressAccount:c})||ut({instructions:h,payer:this.feePayer,lookupTableAddressAccount:c})))g.push(A);else{if(g.length===0)throw Error("item ins too big");P+=A===i[P]?1:0;let S={};for(let K of[...new Set(u)])c[K]!==void 0&&(S[K]=c[K]);if(n&&ut({instructions:[...d.instructions,...g],payer:this.feePayer,lookupTableAddressAccount:c,recentBlockhash:p})){let K=new X.TransactionMessage({payerKey:this.feePayer,recentBlockhash:p,instructions:[...d.instructions,...g]}).compileToV0Message(Object.values(c));f.push(new X.VersionedTransaction(K))}else{let K=new X.TransactionMessage({payerKey:this.feePayer,recentBlockhash:p,instructions:[...g]}).compileToV0Message(Object.values(c));f.push(new X.VersionedTransaction(K))}y.push(Array.from(new Set(g.map(K=>K.keys.filter(_=>_.isSigner).map(_=>_.pubkey.toString())).flat())).map(K=>b[K]).filter(K=>K!==void 0)),g=[A]}}),g.length>0){let h=[...new Set(g.map(T=>T.keys.filter(S=>S.isSigner).map(S=>S.pubkey.toString())).flat()).values()].map(T=>b[T]).filter(T=>T!==void 0);if(n&&ut({instructions:[...d.instructions,...g],payer:this.feePayer,lookupTableAddressAccount:c,recentBlockhash:p})){let T=new X.TransactionMessage({payerKey:this.feePayer,recentBlockhash:p,instructions:[...d.instructions,...g]}).compileToV0Message(Object.values(c));f.push(new X.VersionedTransaction(T))}else{let T=new X.TransactionMessage({payerKey:this.feePayer,recentBlockhash:p,instructions:[...g]}).compileToV0Message(Object.values(c));f.push(new X.VersionedTransaction(T))}y.push(h)}return(k=this.owner)!=null&&k.signer&&y.forEach(A=>{A.some(h=>h.publicKey.equals(this.owner.publicKey))||A.push(this.owner.signer)}),{builder:this,transactions:f,buildProps:e,signers:y,instructionTypes:this.instructionTypes,execute:async A=>{var U;let{sequentially:h,onTxUpdate:T,skipTxCount:S=0,recentBlockHash:K,skipPreflight:_=!0}=A||{};if(f.map(async(M,D)=>{y[D].length&&M.sign(y[D]),K&&(M.message.recentBlockhash=K)}),Oe(f),(U=this.owner)!=null&&U.isKeyPair){if(h){let M=0,D=[];for(let v of f){if(++M,M<=S){console.log("skip tx: ",M),D.push("tx skipped");continue}let W=await this.connection.sendTransaction(v,{skipPreflight:_});await Nt(this.connection,W),D.push(W)}return{txIds:D,signedTxs:f}}return{txIds:await Promise.all(f.map(async M=>await this.connection.sendTransaction(M,{skipPreflight:_}))),signedTxs:f}}if(this.signAllTransactions){let M=await this.signAllTransactions(f.slice(S,f.length)),D=[...f.slice(0,S),...M];if(h){let v=0,W=[],G=async()=>{if(!D[v])return;if(v<S){W.push({txId:"",status:"success",signedTx:D[v]}),T==null||T([...W]),v++,G();return}let F=await this.connection.sendTransaction(D[v],{skipPreflight:_});W.push({txId:F,status:"sent",signedTx:D[v]}),T==null||T([...W]),v++,this.connection.onSignature(F,In=>{let xn=W.findIndex(Vi=>Vi.txId===F);xn>-1&&(W[xn].status=In.err?"error":"success"),T==null||T([...W]),In.err||G()},"processed"),this.connection.getSignatureStatus(F)};return G(),{txIds:[],signedTxs:D}}else{let v=[];for(let W=0;W<D.length;W+=1){let G=await this.connection.sendTransaction(D[W],{skipPreflight:_});v.push(G)}return{txIds:v,signedTxs:D}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:a||{}}}};var lo=require("@solana/web3.js"),mo=j(require("bn.js"));var Su=ne("CobaltX_amount"),Cu=rt(ui.default);var un=new he.default(0),Gu=new he.default(1),Xu=new he.default(2),Hu=new he.default(3),zu=new he.default(5),fo=new he.default(10),Yu=new he.default(100),ju=new he.default(1e3),Zu=new he.default(1e4);var te=require("@solana/spl-token"),B=require("@solana/web3.js");var Ft=j(require("bn.js")),lt=j(require("decimal.js-light"));var ze=j(require("bn.js"));function Et(t,e){if(e.isZero())throw Error("divisor is zero");return t.mod(e)}function bo(t,e){if(e.isZero())throw Error("rhs is zero");let n=t.div(e);if(n.isZero())throw Error("quotient is zero");let i=Et(t,e);return i.gt(He)&&(n=n.add(new ze.default(1)),e=t.div(n),i=Et(t,n),i.gt(He)&&(e=e.add(new ze.default(1)))),[n,e]}var He=new ze.default(0),_t=class{static swapWithoutFees(e,n,i){let r=n.mul(i),o=n.add(e),[s,a]=bo(r,o),c=a.sub(n),u=i.sub(s);if(u.isZero())throw Error("destinationAmountSwapped is zero");return{sourceAmountSwapped:c,destinationAmountSwapped:u}}static lpTokensToTradingTokens(e,n,i,r,o){let s=e.mul(i).div(n),a=e.mul(r).div(n);if(o===0)return{tokenAmount0:s,tokenAmount1:a};if(o===1)return Et(e.mul(i),n).gt(He)&&s.gt(He)&&(s=s.add(new ze.default(1))),Et(e.mul(r),n).gt(He)&&a.gt(He)&&(a=a.add(new ze.default(1))),{tokenAmount0:s,tokenAmount1:a};throw Error("roundDirection value error")}};var mn=j(require("bn.js")),ln=new mn.default(1e6);function go(t,e,n){return t.mul(e).add(n).sub(new mn.default(1)).div(n)}function ci(t,e,n){return t.mul(e).div(n)}var Dt=class{static tradingFee(e,n){return go(e,n,ln)}static protocolFee(e,n){return ci(e,n,ln)}static fundFee(e,n){return ci(e,n,ln)}};var vt=class{static validate_supply(e,n){if(e.isZero())throw Error("tokenAmount0 is zero");if(n.isZero())throw Error("tokenAmount1 is zero")}static swap(e,n,i,r){let o=Dt.tradingFee(e,r),s=e.sub(o),{sourceAmountSwapped:a,destinationAmountSwapped:c}=_t.swapWithoutFees(s,n,i),u=a.add(o);return{newSwapSourceAmount:n.add(u),newSwapDestinationAmount:i.sub(c),sourceAmountSwapped:u,destinationAmountSwapped:c,tradeFee:o}}static swapBaseOut({poolMintA:e,poolMintB:n,tradeFeeRate:i,baseReserve:r,quoteReserve:o,outputMint:s,outputAmount:a}){let[c,u,l,m,d]=n.address===s.toString()?[r,o,e.decimals,n.decimals,e.address]:[o,r,n.decimals,e.decimals,n.address],p=new lt.default(u.toString()).div(10**m).div(new lt.default(c.toString()).div(10**l)),b=a.gte(u)?u.sub(new Ft.default(1)):a,f=u.sub(b),y=Xe(c.mul(b),f),g=Xe(y.mul(new Ft.default(1e6)),new Ft.default(1e6).sub(i)),P=g.sub(y),k=new lt.default(b.toString()).div(10**m).div(new lt.default(g.toString()).div(10**l)),A=p.isZero()?0:k.sub(p).div(p).abs().toNumber();return{amountRealOut:b,amountIn:g,amountInWithoutFee:y,tradeFee:P,priceImpact:A}}};var J=j(require("bn.js"));var dn=(...t)=>t.map(e=>{try{return typeof e=="object"?JSON.stringify(e):e}catch{return e}}).join(", "),Ye=class{constructor({scope:e,moduleName:n,network:i}){this.disabled=!1;this.scope=e,this.logger=ne(n),this.network=i}createTxBuilder(e){return this.scope.checkOwner(),new Ot({connection:this.scope.connection,feePayer:e||this.scope.ownerPubKey,cluster:this.scope.cluster,owner:this.scope.owner,blockhashCommitment:this.scope.blockhashCommitment,api:this.scope.api,signAllTransactions:this.scope.signAllTransactions,network:this.network})}logDebug(...e){this.logger.debug(dn(e))}logInfo(...e){this.logger.info(dn(e))}logAndCreateError(...e){let n=dn(e);throw new Error(n)}checkDisabled(){(this.disabled||!this.scope)&&this.logAndCreateError("module not working")}};var pi=require("@solana/web3.js"),je=j(require("bn.js"));var N=require("@solana/buffer-layout"),pn=N.Layout,li=N.Structure;var fn=N.UInt;var mi=N.u8,Ee=N.u16;var Ie=N.s32;var di=N.seq;var ae=N.blob;var Ze=class extends pn{constructor(n,i,r){super(n,r);this.blob=ae(n),this.signed=i}decode(n,i=0){let r=new je.default(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 je.default(n)),this.signed&&(n=n.toTwos(this.span*8)),this.blob.encode(n.toArrayLike(Buffer,"le",this.span),i,r)}};function Z(t){return new fn(1,t)}function xe(t){return new fn(4,t)}function I(t){return new Ze(8,!1,t)}function Q(t){return new Ze(16,!1,t)}function fi(t){return new Ze(8,!0,t)}function bi(t){return new Ze(16,!0,t)}var Wt=class extends pn{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 O(t){return new Wt(ae(32),e=>new pi.PublicKey(e),e=>e.toBuffer(),t)}function _e(t){return new Wt(mi(),yo,wo,t)}function yo(t){if(t===0)return!1;if(t===1)return!0;throw new Error("Invalid bool: "+t)}function wo(t){return t?1:0}var bn=class extends li{decode(e,n){return super.decode(e,n)}};function q(t,e,n){return new bn(t,e,n)}function z(t,e,n){let i,r=typeof e=="number"?e:(0,je.isBN)(e)?e.toNumber():new Proxy(e,{get(o,s){if(!i){let a=Reflect.get(o,"count");i=(0,je.isBN)(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 di(t,r,n)}var hc=q([xe("mintAuthorityOption"),O("mintAuthority"),I("supply"),Z("decimals"),Z("isInitialized"),xe("freezeAuthorityOption"),O("freezeAuthority")]);var Ao=require("@solana/web3.js"),gi=require("@solana/spl-token");var De=({address:t,programId:e,decimals:n,network:i,...r})=>({chainId:101,address:it(t,i).toBase58(),programId:e,logoURI:"",symbol:"",name:"",decimals:n,tags:[],extensions:r.extensions||{},...r}),Qe=t=>t?{...t,transferFeeConfigAuthority:t.transferFeeConfigAuthority.toBase58(),withdrawWithheldAuthority:t.withdrawWithheldAuthority.toBase58(),withheldAmount:t.withheldAmount.toString(),olderTransferFee:{...t.olderTransferFee,epoch:t.olderTransferFee.epoch.toString(),maximumFee:t.olderTransferFee.maximumFee.toString()},newerTransferFee:{...t.newerTransferFee,epoch:t.newerTransferFee.epoch.toString(),maximumFee:t.newerTransferFee.maximumFee.toString()}}:void 0;var ue=require("@solana/spl-token"),ie=require("@solana/web3.js");var Po=Buffer.from("vault_and_lp_mint_auth_seed","utf8"),Fc=Buffer.from("amm_config","utf8"),ko=Buffer.from("pool","utf8"),To=Buffer.from("pool_lp_mint","utf8"),ho=Buffer.from("pool_vault","utf8"),Bo=Buffer.from("observation","utf8");function Vt(t){return ge([Po],t)}function gn(t,e,n,i){return ge([ko,e.toBuffer(),n.toBuffer(),i.toBuffer()],t)}function Io(t,e){return ge([To,e.toBuffer()],t)}function yi(t,e,n){return ge([ho,e.toBuffer(),n.toBuffer()],t)}function mt(t,e){return ge([Bo,e.toBuffer()],t)}function wi({poolId:t,programId:e,configId:n,mintA:i,mintB:r}){let o=Vt(e).publicKey,s=t||gn(e,n,i,r).publicKey,a=Io(e,s).publicKey,c=yi(e,s,i).publicKey,u=yi(e,s,r).publicKey,l=mt(e,s).publicKey;return{poolId:s,configId:n,authority:o,lpMint:a,vaultA:c,vaultB:u,observationId:l}}var xo=Buffer.from("locked_liquidity","utf8");function qt(t,e){return ge([xo,e.toBuffer()],t)}var Bn=require("@solana/spl-token"),jo=require("@solana/web3.js"),Zo=j(require("bn.js"));var hn=require("@solana/spl-token"),Xt=require("@solana/web3.js"),Yo=j(require("bn.js"));var Fo=j(require("bn.js"));var me=j(require("bn.js")),Ai=new me.default(0),Pi=new me.default(1),ki=new me.default(-1),Ut=new me.default(1).shln(64),Ti=new me.default(1).shln(128),So=Ut.sub(Pi);var Co=Ti.subn(1),Je=-443636,dt=-Je,yn=new me.default("4295048016"),wn=new me.default("79226673521066979257578248091"),Wc=new me.default("4295048017"),Vc=new me.default("79226673521066979257578248090");var Ko=new me.default(10).pow(new me.default(6));var qc=new me.default("18446744073700000000");var Do=j(require("bn.js"));var jc=Buffer.from("amm_config","utf8"),Zc=Buffer.from("pool","utf8"),Qc=Buffer.from("pool_vault","utf8"),Jc=Buffer.from("pool_reward_vault","utf8"),$c=Buffer.from("position","utf8"),el=Buffer.from("tick_array","utf8"),tl=Buffer.from("operation","utf8"),nl=Buffer.from("pool_tick_array_bitmap_extension","utf8"),il=Buffer.from("observation","utf8");function An(t){return ge([Buffer.from("metadata","utf8"),Ue.toBuffer(),t.toBuffer()],Ue)}var rl=Buffer.from("locked_position","utf8");var Mo=require("@solana/spl-token"),Oo=require("@solana/web3.js"),Eo=j(require("bn.js"));var No=j(require("bn.js"));var Tn=14;var Gt=60;var vo=q([ae(8),Z("bump"),Ee("index"),O(""),xe("protocolFeeRate"),xe("tradeFeeRate"),Ee("tickSpacing"),z(I(),8,"")]),Wo=q([xe("blockTimestamp"),fi("tickCumulative"),z(I(),4)]),Li=q([ae(8),_e("initialized"),I("recentEpoch"),Ee("observationIndex"),O("poolId"),z(Wo,100,"observations"),z(I(),4)]),Vo=q([Z("rewardState"),I("openTime"),I("endTime"),I("lastUpdateTime"),Q("emissionsPerSecondX64"),I("rewardTotalEmissioned"),I("rewardClaimed"),O("tokenMint"),O("tokenVault"),O("creator"),Q("rewardGrowthGlobalX64")]),Ci=q([ae(8),Z("bump"),O("ammConfig"),O("creator"),O("mintA"),O("mintB"),O("vaultA"),O("vaultB"),O("observationId"),Z("mintDecimalsA"),Z("mintDecimalsB"),Ee("tickSpacing"),Q("liquidity"),Q("sqrtPriceX64"),Ie("tickCurrent"),xe(),Q("feeGrowthGlobalX64A"),Q("feeGrowthGlobalX64B"),I("protocolFeesTokenA"),I("protocolFeesTokenB"),Q("swapInAmountTokenA"),Q("swapOutAmountTokenB"),Q("swapInAmountTokenB"),Q("swapOutAmountTokenA"),Z("status"),z(Z(),7,""),z(Vo,3,"rewardInfos"),z(I(),16,"tickArrayBitmap"),I("totalFeesTokenA"),I("totalFeesClaimedTokenA"),I("totalFeesTokenB"),I("totalFeesClaimedTokenB"),I("fundFeesTokenA"),I("fundFeesTokenB"),I("startTime"),z(I(),15*4-3,"padding")]),qo=q([Q("growthInsideLastX64"),I("rewardAmountOwed")]),Ki=q([ae(8),Z("bump"),O("nftMint"),O("poolId"),Ie("tickLower"),Ie("tickUpper"),Q("liquidity"),Q("feeGrowthInsideLastX64A"),Q("feeGrowthInsideLastX64B"),I("tokenFeesOwedA"),I("tokenFeesOwedB"),z(qo,3,"rewardInfos"),z(I(),8,"")]),km=q([ae(8),Z("bump"),O("poolId"),Ie("tickLowerIndex"),Ie("tickUpperIndex"),Q("liquidity"),Q("feeGrowthInsideLastX64A"),Q("feeGrowthInsideLastX64B"),I("tokenFeesOwedA"),I("tokenFeesOwedB"),z(Q(),3,"rewardGrowthInside"),z(I(),8,"")]),Uo=q([Ie("tick"),bi("liquidityNet"),Q("liquidityGross"),Q("feeGrowthOutsideX64A"),Q("feeGrowthOutsideX64B"),z(Q(),3,"rewardGrowthsOutsideX64"),z(xe(),13,"")]),Ii=q([ae(8),O("poolId"),Ie("startTickIndex"),z(Uo,Gt,"ticks"),Z("initializedTickCount"),z(Z(),115,"")]),Go=q([ae(329),z(O(),100,"whitelistMints")]),_o=q([ae(8),O("poolId"),z(z(I(),8),Tn,"positiveTickArrayBitmap"),z(z(I(),8),Tn,"negativeTickArrayBitmap")]),Tm=q([I(),Z("bump"),O("owner"),O("poolId"),O("positionId"),O("nftAccount"),z(I(),8)]),hm=q([ae(8),Z("bump"),O("lockOwner"),O("poolId"),O("positionId"),O("nftAccount"),O("lockNftMint"),I("recentEpoch"),z(I(),8)]);Li.span;var vm=ne("CobaltX_Clmm");var Qo=ne("CobaltX_cpmm"),Fe={initialize:[175,175,109,31,13,152,155,237],deposit:[242,35,198,137,82,225,242,182],withdraw:[183,18,70,156,148,109,161,34],swapBaseInput:[143,190,90,218,196,30,51,222],swapBaseOutput:[55,217,98,86,163,74,180,173],lockCpLiquidity:[216,157,29,78,38,51,31,26],collectCpFee:[8,30,51,199,209,184,247,133]};function Ri(t,e,n,i,r,o,s,a,c,u,l,m,d,p,b,f,y,g,P,k){let A=q([I("amountMaxA"),I("amountMaxB"),I("openTime")]),h=gn(t,n,o,s).publicKey,T=[{pubkey:e,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!r.equals(h),isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:m,isSigner:!1,isWritable:!0},{pubkey:d,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:y,isSigner:!1,isWritable:!0},{pubkey:ue.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:b,isSigner:!1,isWritable:!1},{pubkey:f,isSigner:!1,isWritable:!1},{pubkey:ue.ASSOCIATED_TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:zn,isSigner:!1,isWritable:!1},{pubkey:It,isSigner:!1,isWritable:!1}],S=Buffer.alloc(A.span);return A.encode({amountMaxA:g,amountMaxB:P,openTime:k},S),new ie.TransactionInstruction({keys:T,programId:t,data:Buffer.from([...Fe.initialize,...S])})}function Mi(t,e,n,i,r,o,s,a,c,u,l,m,d,p,b){let f=q([I("lpAmount"),I("amountMaxA"),I("amountMaxB")]),y=[{pubkey:e,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:ue.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:ue.TOKEN_2022_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:m,isSigner:!1,isWritable:!0}],g=Buffer.alloc(f.span);return Qo.debug("cpmm deposit data",{lpAmount:d.toString(),amountMaxA:p.toString(),amountMaxB:b.toString()}),f.encode({lpAmount:d,amountMaxA:p,amountMaxB:b},g),new ie.TransactionInstruction({keys:y,programId:t,data:Buffer.from([...Fe.deposit,...g])})}function Oi(t,e,n,i,r,o,s,a,c,u,l,m,d,p,b){let f=q([I("lpAmount"),I("amountMinA"),I("amountMinB")]),y=[{pubkey:e,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:ue.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:ue.TOKEN_2022_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:m,isSigner:!1,isWritable:!0},{pubkey:Bt,isSigner:!1,isWritable:!1}],g=Buffer.alloc(f.span);return f.encode({lpAmount:d,amountMinA:p,amountMinB:b},g),new ie.TransactionInstruction({keys:y,programId:t,data:Buffer.from([...Fe.withdraw,...g])})}function Ei(t,e,n,i,r,o,s,a,c,u,l,m,d,p,b,f){let y=q([I("amountIn"),I("amounOutMin")]),g=[{pubkey:e,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:m,isSigner:!1,isWritable:!1},{pubkey:d,isSigner:!1,isWritable:!1},{pubkey:p,isSigner:!1,isWritable:!0}],P=Buffer.alloc(y.span);return y.encode({amountIn:b,amounOutMin:f},P),new ie.TransactionInstruction({keys:g,programId:t,data:Buffer.from([...Fe.swapBaseInput,...P])})}function _i(t,e,n,i,r,o,s,a,c,u,l,m,d,p,b,f){let y=q([I("amountInMax"),I("amountOut")]),g=[{pubkey:e,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:m,isSigner:!1,isWritable:!1},{pubkey:d,isSigner:!1,isWritable:!1},{pubkey:p,isSigner:!1,isWritable:!0}],P=Buffer.alloc(y.span);return y.encode({amountInMax:b,amountOut:f},P),new ie.TransactionInstruction({keys:g,programId:t,data:Buffer.from([...Fe.swapBaseOutput,...P])})}async function Di(t){var f;let{ownerInfo:e,poolInfo:n,poolKeys:i,getEphemeralSigners:r}=t,o=[],[s,a]=[new ie.PublicKey(n.id),new ie.PublicKey(n.lpMint.address)],c;if(r)c=new ie.PublicKey((await r(1))[0]);else{let y=ie.Keypair.generate();o.push(y),c=y.publicKey}let{publicKey:u}=ke(e.feePayer,c,ue.TOKEN_PROGRAM_ID),{publicKey:l}=An(c),{publicKey:m}=qt(t.lockProgram,c),{publicKey:d}=ke(e.feePayer,a,ue.TOKEN_PROGRAM_ID),{publicKey:p}=ke(t.lockAuthProgram,a,ue.TOKEN_PROGRAM_ID),b=Jo({programId:t.lockProgram,auth:t.lockAuthProgram,payer:e.feePayer,nftOwner:e.feePayer,liquidityOwner:e.feePayer,nftMint:c,nftAccount:u,poolId:s,lockPda:m,mintLp:a,userLpVault:d,lockLpVault:p,poolVaultA:new ie.PublicKey(i.vault.A),poolVaultB:new ie.PublicKey(i.vault.B),metadataAccount:l,lpAmount:t.lpAmount,withMetadata:(f=t.withMetadata)!=null?f:!0});return{address:{nftMint:c,nftAccount:u,metadataAccount:l,lockPda:m,userLpVault:d,lockLpVault:p},instructions:[b],signers:o,instructionTypes:[le.CpmmLockLp],lookupTableAddress:[]}}function Jo({programId:t,auth:e,payer:n,liquidityOwner:i,nftOwner:r,nftMint:o,nftAccount:s,poolId:a,lockPda:c,mintLp:u,userLpVault:l,lockLpVault:m,poolVaultA:d,poolVaultB:p,metadataAccount:b,lpAmount:f,withMetadata:y}){let g=[{pubkey:e,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!0},{pubkey:i,isSigner:!0,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!0,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:m,isSigner:!1,isWritable:!0},{pubkey:d,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:b,isSigner:!1,isWritable:!0},{pubkey:It,isSigner:!1,isWritable:!1},{pubkey:ie.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:ue.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:ue.ASSOCIATED_TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:Ue,isSigner:!1,isWritable:!1}],P=q([I("lpAmount"),_e("withMetadata")]),k=Buffer.alloc(P.span);P.encode({lpAmount:f,withMetadata:y},k);let A=Buffer.from([...Fe.lockCpLiquidity,...k]);return new ie.TransactionInstruction({keys:g,programId:t,data:A})}function Fi({programId:t,nftOwner:e,auth:n,nftAccount:i,lockPda:r,poolId:o,mintLp:s,userVaultA:a,userVaultB:c,poolVaultA:u,poolVaultB:l,mintA:m,mintB:d,lockLpVault:p,lpFeeAmount:b,cpmmProgram:f,cpmmAuthProgram:y}){let g=[{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:e,isSigner:!0,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:f!=null?f:oi,isSigner:!1,isWritable:!1},{pubkey:y!=null?y:si,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:m,isSigner:!1,isWritable:!1},{pubkey:d,isSigner:!1,isWritable:!1},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:ue.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:ue.TOKEN_2022_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:Bt,isSigner:!1,isWritable:!1}],P=q([I("lpFeeAmount")]),k=Buffer.alloc(P.span);P.encode({lpFeeAmount:b},k);let A=Buffer.from([...Fe.collectCpFee,...k]);return new ie.TransactionInstruction({keys:g,programId:t,data:A})}var vi=q([ae(8),Z("bump"),_e("disableCreatePool"),Ee("index"),I("tradeFeeRate"),I("protocolFeeRate"),I("fundFeeRate"),I("createPoolFee"),O("protocolOwner"),O("fundOwner"),z(I(),16)]),Wi=q([ae(8),O("configId"),O("poolCreator"),O("vaultA"),O("vaultB"),O("mintLp"),O("mintA"),O("mintB"),O("mintProgramA"),O("mintProgramB"),O("observationId"),Z("bump"),Z("status"),Z("lpDecimals"),Z("mintDecimalA"),Z("mintDecimalB"),I("lpAmount"),I("protocolFeesMintA"),I("protocolFeesMintB"),I("fundFeesMintA"),I("fundFeesMintB"),I("openTime"),z(I(),32)]);var Ht=class extends Ye{constructor(e){super(e)}async load(){this.checkDisabled()}async getCpmmPoolKeys(e){return(await this.scope.api.fetchPoolKeysById({idList:[e]}))[0]}async getRpcPoolInfo(e,n){return(await this.getRpcPoolInfos([e],n))[e]}async getRpcPoolInfos(e,n){let i=await Me(this.scope.connection,e.map(m=>({pubkey:new B.PublicKey(m)}))),r={},o=new Set,s=[];for(let m=0;m<e.length;m++){let d=i[m];if(d.accountInfo===null)throw Error("fetch pool info error: "+String(e[m]));let p=Wi.decode(d.accountInfo.data);r[String(e[m])]={...p,programId:d.accountInfo.owner},o.add(String(p.configId)),s.push(p.vaultA,p.vaultB)}let a={};if(n){let m=[...o],d=await Me(this.scope.connection,m.map(p=>({pubkey:new B.PublicKey(p)})));for(let p=0;p<m.length;p++){let b=d[p].accountInfo;if(b===null)throw Error("fetch pool config error: "+m[p]);a[m[p]]=vi.decode(b.data)}}let c={},u=await Me(this.scope.connection,s.map(m=>({pubkey:new B.PublicKey(m)})));for(let m=0;m<s.length;m++){let d=u[m].accountInfo;if(d===null)throw Error("fetch vault info error: "+s[m]);c[String(s[m])]=new J.default(te.AccountLayout.decode(d.data).amount.toString())}let l={};for(let[m,d]of Object.entries(r)){let p=c[d.vaultA.toString()].sub(d.protocolFeesMintA).sub(d.fundFeesMintA),b=c[d.vaultB.toString()].sub(d.protocolFeesMintB).sub(d.fundFeesMintB);l[m]={...d,baseReserve:p,quoteReserve:b,vaultAAmount:c[d.vaultA.toString()],vaultBAmount:c[d.vaultB.toString()],configInfo:a[d.configId.toString()],poolPrice:new ee(b.toString()).div(new ee(10).pow(d.mintDecimalB)).div(new ee(p.toString()).div(new ee(10).pow(d.mintDecimalA)))}}return l}toComputePoolInfos({pools:e,mintInfos:n}){return Object.keys(e).reduce((i,r)=>{var c,u,l,m;let o=e[r],[s,a]=[o.mintA.toBase58(),o.mintB.toBase58()];return{...i,[r]:{...o,id:new B.PublicKey(r),configInfo:o.configInfo,version:7,authority:Vt(o.programId).publicKey,mintA:De({address:s,decimals:o.mintDecimalA,programId:o.mintProgramA.toBase58(),extensions:{feeConfig:(c=n[s])!=null&&c.feeConfig?Qe((u=n[s])==null?void 0:u.feeConfig):void 0},network:this.network}),mintB:De({address:a,decimals:o.mintDecimalB,programId:o.mintProgramB.toBase58(),extensions:{feeConfig:(l=n[a])!=null&&l.feeConfig?Qe((m=n[a])==null?void 0:m.feeConfig):void 0},network:this.network})}}},{})}async getPoolInfoFromRpc(e){let n=await this.getRpcPoolInfo(e,!0),i=await nn({connection:this.scope.connection,mints:[n.mintA,n.mintB],network:this.network}),r=De({address:n.mintA.toBase58(),decimals:n.mintDecimalA,programId:n.mintProgramA.toBase58(),extensions:{feeConfig:i[n.mintA.toBase58()].feeConfig?Qe(i[n.mintA.toBase58()].feeConfig):void 0},network:this.network}),o=De({address:n.mintB.toBase58(),decimals:n.mintDecimalB,programId:n.mintProgramB.toBase58(),extensions:{feeConfig:i[n.mintB.toBase58()].feeConfig?Qe(i[n.mintB.toBase58()].feeConfig):void 0},network:this.network}),s=De({address:n.mintLp.toBase58(),decimals:n.lpDecimals,programId:te.TOKEN_PROGRAM_ID.toBase58(),network:this.network}),a={id:n.configId.toBase58(),index:n.configInfo.index,protocolFeeRate:n.configInfo.protocolFeeRate.toNumber(),tradeFeeRate:n.configInfo.tradeFeeRate.toNumber(),fundFeeRate:n.configInfo.fundFeeRate.toNumber(),createPoolFee:n.configInfo.createPoolFee.toString()},c={volume:0,volumeQuote:0,volumeFee:0,apr:0,feeApr:0,priceMin:0,priceMax:0,rewardApr:[]};return{poolInfo:{programId:n.programId.toBase58(),id:e,type:"Standard",lpMint:s,lpPrice:0,lpAmount:n.lpAmount.toNumber(),config:a,mintA:r,mintB:o,rewardDefaultInfos:[],rewardDefaultPoolInfos:"Ecosystem",price:n.poolPrice.toNumber(),mintAmountA:new ee(n.vaultAAmount.toString()).div(10**r.decimals).toNumber(),mintAmountB:new ee(n.vaultBAmount.toString()).div(10**o.decimals).toNumber(),feeRate:n.configInfo.tradeFeeRate.toNumber(),openTime:n.openTime.toString(),tvl:0,burnPercent:0,day:c,week:c,month:c,pooltype:[],farmUpcomingCount:0,farmOngoingCount:0,farmFinishedCount:0},poolKeys:{programId:n.programId.toBase58(),id:e,mintA:r,mintB:o,openTime:n.openTime.toString(),vault:{A:n.vaultA.toBase58(),B:n.vaultB.toBase58()},authority:Vt(n.programId).publicKey.toBase58(),mintLp:s,config:a,observationId:mt(n.programId,new B.PublicKey(e)).publicKey.toBase58()},rpcData:n}}async createPool({poolId:e,programId:n,poolFeeAccount:i,startTime:r,ownerInfo:o,associatedOnly:s=!1,checkCreateATAOwner:a=!1,txVersion:c,feeConfig:u,computeBudgetConfig:l,...m}){var D,v,W;let d=o.feePayer||((D=this.scope.owner)==null?void 0:D.publicKey),p=new J.default(new B.PublicKey(m.mintA.address).toBuffer()).lte(new J.default(new B.PublicKey(m.mintB.address).toBuffer())),[b,f]=p?[m.mintA,m.mintB]:[m.mintB,m.mintA],[y,g]=p?[m.mintAAmount,m.mintBAmount]:[m.mintBAmount,m.mintAAmount],P=o.useSOLBalance&&b.address===te.NATIVE_MINT.toBase58(),k=o.useSOLBalance&&f.address===te.NATIVE_MINT.toBase58(),[A,h]=[new B.PublicKey(b.address),new B.PublicKey(f.address)],T=this.createTxBuilder(),{account:S,instructionParams:K}=await this.scope.account.getOrCreateTokenAccount({mint:A,tokenProgram:b.programId,owner:this.scope.ownerPubKey,createInfo:P?{payer:d,amount:y}:void 0,notUseTokenAccount:P,skipCloseAccount:!P,associatedOnly:P?!1:s,checkCreateATAOwner:a});T.addInstruction(K||{});let{account:_,instructionParams:U}=await this.scope.account.getOrCreateTokenAccount({mint:new B.PublicKey(f.address),tokenProgram:f.programId,owner:this.scope.ownerPubKey,createInfo:k?{payer:d,amount:g}:void 0,notUseTokenAccount:k,skipCloseAccount:!k,associatedOnly:k?!1:s,checkCreateATAOwner:a});if(T.addInstruction(U||{}),S===void 0||_===void 0)throw Error("you don't has some token account");let M=wi({poolId:e,programId:n,configId:new B.PublicKey(u.id),mintA:A,mintB:h});return T.addInstruction({instructions:[Ri(n,this.scope.ownerPubKey,new B.PublicKey(u.id),M.authority,M.poolId,A,h,M.lpMint,S,_,ke(this.scope.ownerPubKey,M.lpMint).publicKey,M.vaultA,M.vaultB,i,new B.PublicKey((v=b.programId)!=null?v:te.TOKEN_PROGRAM_ID),new B.PublicKey((W=f.programId)!=null?W:te.TOKEN_PROGRAM_ID),M.observationId,y,g,r)],instructionTypes:[le.CpmmCreatePool]}),T.addCustomComputeBudget(l),T.versionBuild({txVersion:c,extInfo:{address:{...M,mintA:b,mintB:f,programId:n,poolFeeAccount:i,feeConfig:u}}})}async addLiquidity(e){let{poolInfo:n,poolKeys:i,inputAmount:r,baseIn:o,slippage:s,computeResult:a,computeBudgetConfig:c,config:u,txVersion:l}=e;this.scope.availability.addStandardPosition===!1&&this.logAndCreateError("add liquidity feature disabled in your region"),r.isZero()&&this.logAndCreateError("amounts must greater than zero","amountInA",{amountInA:r.toString()});let{account:m}=this.scope,{bypassAssociatedCheck:d,checkCreateATAOwner:p}={bypassAssociatedCheck:!1,checkCreateATAOwner:!1,...u},b=a?void 0:await this.getRpcPoolInfo(n.id),{liquidity:f,inputAmountFee:y,anotherAmount:g}=a||this.computePairAmount({poolInfo:{...n,lpAmount:new ee(b.lpAmount.toString()).div(10**n.lpMint.decimals).toNumber()},baseReserve:b.baseReserve,quoteReserve:b.quoteReserve,slippage:new de(0),baseIn:o,epochInfo:await this.scope.fetchEpochInfo(),amount:new ee(r.toString()).div(10**(o?n.mintA.decimals:n.mintB.decimals))}),P=g.amount,k=n.mintA.address===te.NATIVE_MINT.toString(),A=n.mintB.address===te.NATIVE_MINT.toString(),h=this.createTxBuilder(),[T,S]=[new B.PublicKey(n.mintA.address),new B.PublicKey(n.mintB.address)],{account:K,instructionParams:_}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:n.mintA.programId,mint:new B.PublicKey(n.mintA.address),owner:this.scope.ownerPubKey,createInfo:k||(o?r:P).isZero()?{payer:this.scope.ownerPubKey,amount:o?r:P}:void 0,skipCloseAccount:!k,notUseTokenAccount:k,associatedOnly:!1,checkCreateATAOwner:p});h.addInstruction(_||{});let{account:U,instructionParams:M}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:n.mintB.programId,mint:new B.PublicKey(n.mintB.address),owner:this.scope.ownerPubKey,createInfo:A||(o?P:r).isZero()?{payer:this.scope.ownerPubKey,amount:o?P:r}:void 0,skipCloseAccount:!A,notUseTokenAccount:A,associatedOnly:!1,checkCreateATAOwner:p});h.addInstruction(M||{}),!K&&!U&&this.logAndCreateError("cannot found target token accounts","tokenAccounts",m.tokenAccounts);let D=await m.getCreatedTokenAccount({mint:new B.PublicKey(n.lpMint.address)}),{tokenAccount:v,...W}=await m.handleTokenAccount({side:"out",amount:0,mint:new B.PublicKey(n.lpMint.address),tokenAccount:D,bypassAssociatedCheck:d,checkCreateATAOwner:p});h.addInstruction(W);let G=i!=null?i:await this.getCpmmPoolKeys(n.id),F=new de(new J.default(1)).sub(s);return h.addInstruction({instructions:[Mi(new B.PublicKey(n.programId),this.scope.ownerPubKey,new B.PublicKey(G.authority),new B.PublicKey(n.id),v,K,U,new B.PublicKey(G.vault.A),new B.PublicKey(G.vault.B),T,S,new B.PublicKey(n.lpMint.address),a?a==null?void 0:a.liquidity:F.mul(f).quotient,o?y.amount:P,o?P:y.amount)],instructionTypes:[le.CpmmAddLiquidity],lookupTableAddress:G.lookupTableAccount?[G.lookupTableAccount]:[]}),h.addCustomComputeBudget(c),h.versionBuild({txVersion:l})}async withdrawLiquidity(e){var v,W;let{poolInfo:n,poolKeys:i,lpAmount:r,slippage:o,computeBudgetConfig:s,txVersion:a}=e;this.scope.availability.addStandardPosition===!1&&this.logAndCreateError("add liquidity feature disabled in your region");let c=new de(new J.default(1)).sub(o),u=await this.getRpcPoolInfo(n.id),[l,m]=[c.mul(r.mul(u.baseReserve).div(u.lpAmount)).quotient,c.mul(r.mul(u.quoteReserve).div(u.lpAmount)).quotient],d=await this.scope.fetchEpochInfo(),[p,b]=[Te(l,n.mintA.extensions.feeConfig,d,!1),Te(m,n.mintB.extensions.feeConfig,d,!1)],{account:f}=this.scope,y=this.createTxBuilder(),[g,P]=[new B.PublicKey(n.mintA.address),new B.PublicKey(n.mintB.address)],k=g.equals(be(this.network).WSOLMint),A=P.equals(be(this.network).WSOLMint),h,T,{account:S,instructionParams:K}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:n.mintA.programId,mint:new B.PublicKey(n.mintA.address),notUseTokenAccount:k,owner:this.scope.ownerPubKey,createInfo:{payer:this.scope.ownerPubKey,amount:0},skipCloseAccount:!k,associatedOnly:!k,checkCreateATAOwner:!1});h=S,K&&y.addInstruction(K);let{account:_,instructionParams:U}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:n.mintB.programId,mint:new B.PublicKey(n.mintB.address),notUseTokenAccount:A,owner:this.scope.ownerPubKey,createInfo:{payer:this.scope.ownerPubKey,amount:0},skipCloseAccount:!A,associatedOnly:!A,checkCreateATAOwner:!1});T=_,U&&y.addInstruction(U),(!h||!T)&&this.logAndCreateError("cannot found target token accounts","tokenAccounts",f.tokenAccounts);let M=await f.getCreatedTokenAccount({mint:new B.PublicKey(n.lpMint.address)});M||this.logAndCreateError("cannot found lp token account","tokenAccounts",f.tokenAccounts);let D=i!=null?i:await this.getCpmmPoolKeys(n.id);return y.addInstruction({instructions:[Oi(new B.PublicKey(n.programId),this.scope.ownerPubKey,new B.PublicKey(D.authority),new B.PublicKey(n.id),M,h,T,new B.PublicKey(D.vault.A),new B.PublicKey(D.vault.B),g,P,new B.PublicKey(n.lpMint.address),r,l.sub((v=p.fee)!=null?v:new J.default(0)),m.sub((W=b.fee)!=null?W:new J.default(0)))],instructionTypes:[le.CpmmWithdrawLiquidity],lookupTableAddress:D.lookupTableAccount?[D.lookupTableAccount]:[]}),y.addCustomComputeBudget(s),y.versionBuild({txVersion:a})}async swap(e){var _,U,M,D,v,W;let{poolInfo:n,poolKeys:i,baseIn:r,fixedOut:o,inputAmount:s,swapResult:a,slippage:c=0,config:u,computeBudgetConfig:l,txVersion:m}=e,{bypassAssociatedCheck:d,checkCreateATAOwner:p,associatedOnly:b}={bypassAssociatedCheck:!1,checkCreateATAOwner:!1,associatedOnly:!0,...u},f=this.createTxBuilder(),[y,g]=[new B.PublicKey(n.mintA.address),new B.PublicKey(n.mintB.address)];o?a.sourceAmountSwapped=a.sourceAmountSwapped.mul(new J.default((1+c)*1e4)).div(new J.default(1e4)):a.destinationAmountSwapped=a.destinationAmountSwapped.mul(new J.default((1-c)*1e4)).div(new J.default(1e4));let P=n.mintA.address===be(this.network).WSOLMint.toBase58(),k=n.mintB.address===be(this.network).WSOLMint.toBase58(),{account:A,instructionParams:h}=await this.scope.account.getOrCreateTokenAccount({mint:y,tokenProgram:new B.PublicKey((_=n.mintA.programId)!=null?_:te.TOKEN_PROGRAM_ID),owner:this.scope.ownerPubKey,createInfo:P||!r?{payer:this.scope.ownerPubKey,amount:r?a.sourceAmountSwapped:0}:void 0,notUseTokenAccount:P,skipCloseAccount:!P,associatedOnly:P?!1:b,checkCreateATAOwner:p});h&&f.addInstruction(h);let{account:T,instructionParams:S}=await this.scope.account.getOrCreateTokenAccount({mint:g,tokenProgram:new B.PublicKey((U=n.mintB.programId)!=null?U:te.TOKEN_PROGRAM_ID),owner:this.scope.ownerPubKey,createInfo:k||r?{payer:this.scope.ownerPubKey,amount:r?0:a.sourceAmountSwapped}:void 0,notUseTokenAccount:k,skipCloseAccount:!k,associatedOnly:k?!1:b,checkCreateATAOwner:p});S&&f.addInstruction(S),(!A||!T)&&this.logAndCreateError("user do not have token account",{mintA:n.mintA.symbol||n.mintA.address,mintB:n.mintB.symbol||n.mintB.address,mintATokenAcc:A,mintBTokenAcc:T,mintAUseSOLBalance:P,mintBUseSOLBalance:k,associatedOnly:b});let K=i!=null?i:await this.getCpmmPoolKeys(n.id);return f.addInstruction({instructions:[o?_i(new B.PublicKey(n.programId),this.scope.ownerPubKey,new B.PublicKey(K.authority),new B.PublicKey(K.config.id),new B.PublicKey(n.id),r?A:T,r?T:A,new B.PublicKey(K.vault[r?"A":"B"]),new B.PublicKey(K.vault[r?"B":"A"]),new B.PublicKey((v=n[r?"mintA":"mintB"].programId)!=null?v:te.TOKEN_PROGRAM_ID),new B.PublicKey((W=n[r?"mintB":"mintA"].programId)!=null?W:te.TOKEN_PROGRAM_ID),r?y:g,r?g:y,mt(new B.PublicKey(n.programId),new B.PublicKey(n.id)).publicKey,a.sourceAmountSwapped,a.destinationAmountSwapped):Ei(new B.PublicKey(n.programId),this.scope.ownerPubKey,new B.PublicKey(K.authority),new B.PublicKey(K.config.id),new B.PublicKey(n.id),r?A:T,r?T:A,new B.PublicKey(K.vault[r?"A":"B"]),new B.PublicKey(K.vault[r?"B":"A"]),new B.PublicKey((M=n[r?"mintA":"mintB"].programId)!=null?M:te.TOKEN_PROGRAM_ID),new B.PublicKey((D=n[r?"mintB":"mintA"].programId)!=null?D:te.TOKEN_PROGRAM_ID),r?y:g,r?g:y,mt(new B.PublicKey(n.programId),new B.PublicKey(n.id)).publicKey,s,a.destinationAmountSwapped)],instructionTypes:[o?le.CpmmSwapBaseOut:le.ClmmSwapBaseIn]}),f.addCustomComputeBudget(l),f.versionBuild({txVersion:m})}async lockLp(e){var u,l,m,d,p;let{poolInfo:n,lpAmount:i,computeBudgetConfig:r,txVersion:o}=e;i.isZero()&&this.logAndCreateError("lpAmount must greater than zero",{lpAmount:i.toString()});let s=this.createTxBuilder(),a=(u=e.poolKeys)!=null?u:await this.getCpmmPoolKeys(n.id),c=await Di({poolInfo:n,poolKeys:a,ownerInfo:{wallet:this.scope.ownerPubKey,feePayer:(l=e.feePayer)!=null?l:this.scope.ownerPubKey},lockProgram:(m=e.programId)!=null?m:Lt,lockAuthProgram:(d=e.authProgram)!=null?d:Rt,lpAmount:i,withMetadata:(p=e.withMetadata)!=null?p:!0,getEphemeralSigners:e.getEphemeralSigners});return s.addInstruction(c),s.addCustomComputeBudget(r),s.versionBuild({txVersion:o,extInfo:c.address})}async harvestLockLp(e){var U;let{poolInfo:n,lpFeeAmount:i,nftMint:r,programId:o=Lt,authProgram:s=Rt,cpmmProgram:a,computeBudgetConfig:c,txVersion:u}=e;i.isZero()&&this.logAndCreateError("lpFeeAmount must greater than zero",{lpAmount:i.toString()});let l=e.feePayer||this.scope.ownerPubKey,m=this.createTxBuilder(),[d,p]=[new B.PublicKey(n.mintA.address),new B.PublicKey(n.mintB.address)],b=d.equals(be(this.network).WSOLMint),f=p.equals(be(this.network).WSOLMint),y,g,{account:P,instructionParams:k}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:n.mintA.programId,mint:new B.PublicKey(n.mintA.address),notUseTokenAccount:b,owner:this.scope.ownerPubKey,createInfo:{payer:this.scope.ownerPubKey,amount:0},skipCloseAccount:!b,associatedOnly:!b,checkCreateATAOwner:!1});y=P,k&&m.addInstruction(k);let{account:A,instructionParams:h}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:n.mintB.programId,mint:new B.PublicKey(n.mintB.address),notUseTokenAccount:f,owner:this.scope.ownerPubKey,createInfo:{payer:this.scope.ownerPubKey,amount:0},skipCloseAccount:!f,associatedOnly:!f,checkCreateATAOwner:!1});g=A,h&&m.addInstruction(h),(!y||!g)&&this.logAndCreateError("cannot found target token accounts",{tokenAccountA:y,tokenAccountB:g});let T=(U=e.poolKeys)!=null?U:await this.getCpmmPoolKeys(n.id),{publicKey:S}=ke(l,r,te.TOKEN_PROGRAM_ID),{publicKey:K}=qt(o,r),{publicKey:_}=ke(s,new B.PublicKey(n.lpMint.address),te.TOKEN_PROGRAM_ID);return m.addInstruction({instructions:[Fi({programId:o!=null?o:Lt,nftOwner:this.scope.ownerPubKey,auth:s!=null?s:Rt,nftMint:r,nftAccount:S,lockPda:K,poolId:new B.PublicKey(n.id),mintLp:new B.PublicKey(T.mintLp.address),userVaultA:y,userVaultB:g,poolVaultA:new B.PublicKey(T.vault.A),poolVaultB:new B.PublicKey(T.vault.B),mintA:d,mintB:p,lockLpVault:_,lpFeeAmount:i,cpmmProgram:a==null?void 0:a.programId,cpmmAuthProgram:a==null?void 0:a.authProgram})],instructionTypes:[le.CpmmCollectLockFee]}),m.addCustomComputeBudget(c),m.versionBuild({txVersion:u})}computeSwapAmount({pool:e,amountIn:n,outputMint:i,slippage:r}){let o=i.toString()===e.mintB.address,s=vt.swap(n,o?e.baseReserve:e.quoteReserve,o?e.quoteReserve:e.baseReserve,e.configInfo.tradeFeeRate),a=new ee(s.destinationAmountSwapped.toString()).div(s.sourceAmountSwapped.toString()),c=s.destinationAmountSwapped.mul(new J.default((1-r)*1e4)).div(new J.default(1e4));return{allTrade:s.sourceAmountSwapped.eq(n),amountIn:n,amountOut:s.destinationAmountSwapped,minAmountOut:c,executionPrice:a,fee:s.tradeFee,priceImpact:e.poolPrice.sub(a).div(e.poolPrice)}}computePairAmount({poolInfo:e,baseReserve:n,quoteReserve:i,amount:r,slippage:o,epochInfo:s,baseIn:a}){var A,h,T,S,K,_,U,M,D;let c=1-Number(o.toSignificant())/100,u=new J.default(new ee(r).mul(10**e[a?"mintA":"mintB"].decimals).mul(c).toFixed(0)),l=Te(u,e[a?"mintA":"mintB"].extensions.feeConfig,s,!1),m=u.sub((A=l.fee)!=null?A:new J.default(0)),d=new J.default(new ee(e.lpAmount).mul(10**e.lpMint.decimals).toFixed(0,ee.ROUND_DOWN));this.logDebug("baseReserve:",n.toString(),"quoteReserve:",i.toString()),this.logDebug("tokenIn:",a?e.mintA.symbol:e.mintB.symbol,"amountIn:",u.toString(),"amountInFee:",(T=(h=l.fee)==null?void 0:h.toString())!=null?T:0,"anotherToken:",a?e.mintB.symbol:e.mintA.symbol,"slippage:",`${o.toSignificant()}%`);let p=a?"base":"quote";this.logDebug("input side:",p);let b=m.mul(d).div(p==="base"?n:i),f={amount:un,fee:void 0,expirationTime:void 0};if(!m.isZero()){let v=$o(b,n,i,d);this.logDebug("lpAmountData:",{amountA:v.amountA.toString(),amountB:v.amountB.toString()}),f=Te(v[a?"amountB":"amountA"],e[a?"mintB":"mintA"].extensions.feeConfig,s,!0)}let y=new de(new J.default(1)).add(o),g=new de(new J.default(1)).sub(o),P=Te(y.mul(f.amount.sub((S=f.fee)!=null?S:new J.default(0))).quotient,e[a?"mintB":"mintA"].extensions.feeConfig,s,!0),k=Te(g.mul(f.amount.sub((K=f.fee)!=null?K:new J.default(0))).quotient,e[a?"mintB":"mintA"].extensions.feeConfig,s,!0);return this.logDebug("anotherAmount:",f.amount.toString(),"anotherAmountFee:",(U=(_=f.fee)==null?void 0:_.toString())!=null?U:0,"maxAnotherAmount:",P.amount.toString(),"maxAnotherAmountFee:",(D=(M=P.fee)==null?void 0:M.toString())!=null?D:0),{inputAmountFee:l,anotherAmount:f,maxAnotherAmount:P,minAnotherAmount:k,liquidity:b}}};function $o(t,e,n,i){let r=t.mul(e).div(i);!r.isZero()&&!t.mul(e).mod(i).isZero()&&(r=r.add(new J.default(1)));let o=t.mul(n).div(i);return!o.isZero()&&!t.mul(n).mod(i).isZero()&&(o=o.add(new J.default(1))),{amountA:r,amountB:o}}0&&(module.exports={});
/*!
 *  decimal.js v10.5.0
 *  An arbitrary-precision Decimal type for JavaScript.
 *  https://github.com/MikeMcl/decimal.js
 *  Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
 *  MIT Licence
 */
//# sourceMappingURL=cpmm.js.map