UNPKG

raydium-sdk-v2-custody

Version:

An SDK for building applications on top of Raydium.

3 lines 85.3 kB
var Yn=Object.create;var De=Object.defineProperty,Zn=Object.defineProperties,Jn=Object.getOwnPropertyDescriptor,Xn=Object.getOwnPropertyDescriptors,$n=Object.getOwnPropertyNames,Qe=Object.getOwnPropertySymbols,er=Object.getPrototypeOf,Pt=Object.prototype.hasOwnProperty,en=Object.prototype.propertyIsEnumerable;var $t=(t,e,n)=>e in t?De(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,z=(t,e)=>{for(var n in e||(e={}))Pt.call(e,n)&&$t(t,n,e[n]);if(Qe)for(var n of Qe(e))en.call(e,n)&&$t(t,n,e[n]);return t},pe=(t,e)=>Zn(t,Xn(e));var je=(t,e)=>{var n={};for(var r in t)Pt.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&Qe)for(var r of Qe(t))e.indexOf(r)<0&&en.call(t,r)&&(n[r]=t[r]);return n};var tr=(t,e)=>{for(var n in e)De(t,n,{get:e[n],enumerable:!0})},tn=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of $n(e))!Pt.call(t,i)&&i!==n&&De(t,i,{get:()=>e[i],enumerable:!(r=Jn(e,i))||r.enumerable});return t};var X=(t,e,n)=>(n=t!=null?Yn(er(t)):{},tn(e||!t||!t.__esModule?De(n,"default",{value:t,enumerable:!0}):n,t)),nr=t=>tn(De({},"__esModule",{value:!0}),t);var Bi={};tr(Bi,{MARKET_STATE_LAYOUT_V2:()=>Tt,default:()=>He,initializeMarket:()=>Qn,makeCreateMarketInstruction:()=>Zt});module.exports=nr(Bi);var Ie=require("@solana/web3.js"),ve=X(require("bn.js")),Jt=require("@solana/spl-token");var ue=X(require("bn.js"));var Se=9e15,he=1e9,At="0123456789abcdef",Ze="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Je="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",St={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Se,maxE:Se,crypto:!1},sn,ce,M=!0,$e="[DecimalError] ",ge=$e+"Invalid argument: ",un=$e+"Precision limit exceeded",an=$e+"crypto unavailable",cn="[object Decimal]",Y=Math.floor,H=Math.pow,rr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,ir=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,or=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,ln=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,ie=1e7,L=7,sr=9007199254740991,ur=Ze.length-1,Bt=Je.length-1,d={toStringTag:cn};d.absoluteValue=d.abs=function(){var t=new this.constructor(this);return t.s<0&&(t.s=1),S(t)};d.ceil=function(){return S(new this.constructor(this),this.e+1,2)};d.clampedTo=d.clamp=function(t,e){var n,r=this,i=r.constructor;if(t=new i(t),e=new i(e),!t.s||!e.s)return new i(NaN);if(t.gt(e))throw Error(ge+e);return n=r.cmp(t),n<0?t:r.cmp(e)>0?e:new i(r)};d.comparedTo=d.cmp=function(t){var e,n,r,i,o=this,s=o.d,u=(t=new o.constructor(t)).d,c=o.s,a=t.s;if(!s||!u)return!c||!a?NaN:c!==a?c:s===u?0:!s^c<0?1:-1;if(!s[0]||!u[0])return s[0]?c:u[0]?-a:0;if(c!==a)return c;if(o.e!==t.e)return o.e>t.e^c<0?1:-1;for(r=s.length,i=u.length,e=0,n=r<i?r:i;e<n;++e)if(s[e]!==u[e])return s[e]>u[e]^c<0?1:-1;return r===i?0:r>i^c<0?1:-1};d.cosine=d.cos=function(){var t,e,n=this,r=n.constructor;return n.d?n.d[0]?(t=r.precision,e=r.rounding,r.precision=t+Math.max(n.e,n.sd())+L,r.rounding=1,n=ar(r,gn(r,n)),r.precision=t,r.rounding=e,S(ce==2||ce==3?n.neg():n,t,e,!0)):new r(1):new r(NaN)};d.cubeRoot=d.cbrt=function(){var t,e,n,r,i,o,s,u,c,a,l=this,f=l.constructor;if(!l.isFinite()||l.isZero())return new f(l);for(M=!1,o=l.s*H(l.s*l,1/3),!o||Math.abs(o)==1/0?(n=Q(l.d),t=l.e,(o=(t-n.length+1)%3)&&(n+=o==1||o==-2?"0":"00"),o=H(n,1/3),t=Y((t+1)/3)-(t%3==(t<0?-1:2)),o==1/0?n="5e"+t:(n=o.toExponential(),n=n.slice(0,n.indexOf("e")+1)+t),r=new f(n),r.s=l.s):r=new f(o.toString()),s=(t=f.precision)+3;;)if(u=r,c=u.times(u).times(u),a=c.plus(l),r=W(a.plus(l).times(u),a.plus(c),s+2,1),Q(u.d).slice(0,s)===(n=Q(r.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!i&&n=="4999"){if(!i&&(S(u,t+1,0),u.times(u).times(u).eq(l))){r=u;break}s+=4,i=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(S(r,t+1,1),e=!r.times(r).times(r).eq(l));break}return M=!0,S(r,t,f.rounding,e)};d.decimalPlaces=d.dp=function(){var t,e=this.d,n=NaN;if(e){if(t=e.length-1,n=(t-Y(this.e/L))*L,t=e[t],t)for(;t%10==0;t/=10)n--;n<0&&(n=0)}return n};d.dividedBy=d.div=function(t){return W(this,new this.constructor(t))};d.dividedToIntegerBy=d.divToInt=function(t){var e=this,n=e.constructor;return S(W(e,new n(t),0,1,1),n.precision,n.rounding)};d.equals=d.eq=function(t){return this.cmp(t)===0};d.floor=function(){return S(new this.constructor(this),this.e+1,3)};d.greaterThan=d.gt=function(t){return this.cmp(t)>0};d.greaterThanOrEqualTo=d.gte=function(t){var e=this.cmp(t);return e==1||e===0};d.hyperbolicCosine=d.cosh=function(){var t,e,n,r,i,o=this,s=o.constructor,u=new s(1);if(!o.isFinite())return new s(o.s?1/0:NaN);if(o.isZero())return u;n=s.precision,r=s.rounding,s.precision=n+Math.max(o.e,o.sd())+4,s.rounding=1,i=o.d.length,i<32?(t=Math.ceil(i/3),e=(1/tt(4,t)).toString()):(t=16,e="2.3283064365386962890625e-10"),o=Be(s,1,o.times(e),new s(1),!0);for(var c,a=t,l=new s(8);a--;)c=o.times(o),o=u.minus(c.times(l.minus(c.times(l))));return S(o,s.precision=n,s.rounding=r,!0)};d.hyperbolicSine=d.sinh=function(){var t,e,n,r,i=this,o=i.constructor;if(!i.isFinite()||i.isZero())return new o(i);if(e=o.precision,n=o.rounding,o.precision=e+Math.max(i.e,i.sd())+4,o.rounding=1,r=i.d.length,r<3)i=Be(o,2,i,i,!0);else{t=1.4*Math.sqrt(r),t=t>16?16:t|0,i=i.times(1/tt(5,t)),i=Be(o,2,i,i,!0);for(var s,u=new o(5),c=new o(16),a=new o(20);t--;)s=i.times(i),i=i.times(u.plus(s.times(c.times(s).plus(a))))}return o.precision=e,o.rounding=n,S(i,e,n,!0)};d.hyperbolicTangent=d.tanh=function(){var t,e,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(t=r.precision,e=r.rounding,r.precision=t+7,r.rounding=1,W(n.sinh(),n.cosh(),r.precision=t,r.rounding=e)):new r(n.s)};d.inverseCosine=d.acos=function(){var t,e=this,n=e.constructor,r=e.abs().cmp(1),i=n.precision,o=n.rounding;return r!==-1?r===0?e.isNeg()?re(n,i,o):new n(0):new n(NaN):e.isZero()?re(n,i+4,o).times(.5):(n.precision=i+6,n.rounding=1,e=e.asin(),t=re(n,i+4,o).times(.5),n.precision=i,n.rounding=o,t.minus(e))};d.inverseHyperbolicCosine=d.acosh=function(){var t,e,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(t=r.precision,e=r.rounding,r.precision=t+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,M=!1,n=n.times(n).minus(1).sqrt().plus(n),M=!0,r.precision=t,r.rounding=e,n.ln()):new r(n)};d.inverseHyperbolicSine=d.asinh=function(){var t,e,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(t=r.precision,e=r.rounding,r.precision=t+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,M=!1,n=n.times(n).plus(1).sqrt().plus(n),M=!0,r.precision=t,r.rounding=e,n.ln())};d.inverseHyperbolicTangent=d.atanh=function(){var t,e,n,r,i=this,o=i.constructor;return i.isFinite()?i.e>=0?new o(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(t=o.precision,e=o.rounding,r=i.sd(),Math.max(r,t)<2*-i.e-1?S(new o(i),t,e,!0):(o.precision=n=r-i.e,i=W(i.plus(1),new o(1).minus(i),n+t,1),o.precision=t+4,o.rounding=1,i=i.ln(),o.precision=t,o.rounding=e,i.times(.5))):new o(NaN)};d.inverseSine=d.asin=function(){var t,e,n,r,i=this,o=i.constructor;return i.isZero()?new o(i):(e=i.abs().cmp(1),n=o.precision,r=o.rounding,e!==-1?e===0?(t=re(o,n+4,r).times(.5),t.s=i.s,t):new o(NaN):(o.precision=n+6,o.rounding=1,i=i.div(new o(1).minus(i.times(i)).sqrt().plus(1)).atan(),o.precision=n,o.rounding=r,i.times(2)))};d.inverseTangent=d.atan=function(){var t,e,n,r,i,o,s,u,c,a=this,l=a.constructor,f=l.precision,p=l.rounding;if(a.isFinite()){if(a.isZero())return new l(a);if(a.abs().eq(1)&&f+4<=Bt)return s=re(l,f+4,p).times(.25),s.s=a.s,s}else{if(!a.s)return new l(NaN);if(f+4<=Bt)return s=re(l,f+4,p).times(.5),s.s=a.s,s}for(l.precision=u=f+10,l.rounding=1,n=Math.min(28,u/L+2|0),t=n;t;--t)a=a.div(a.times(a).plus(1).sqrt().plus(1));for(M=!1,e=Math.ceil(u/L),r=1,c=a.times(a),s=new l(a),i=a;t!==-1;)if(i=i.times(c),o=s.minus(i.div(r+=2)),i=i.times(c),s=o.plus(i.div(r+=2)),s.d[e]!==void 0)for(t=e;s.d[t]===o.d[t]&&t--;);return n&&(s=s.times(2<<n-1)),M=!0,S(s,l.precision=f,l.rounding=p,!0)};d.isFinite=function(){return!!this.d};d.isInteger=d.isInt=function(){return!!this.d&&Y(this.e/L)>this.d.length-2};d.isNaN=function(){return!this.s};d.isNegative=d.isNeg=function(){return this.s<0};d.isPositive=d.isPos=function(){return this.s>0};d.isZero=function(){return!!this.d&&this.d[0]===0};d.lessThan=d.lt=function(t){return this.cmp(t)<0};d.lessThanOrEqualTo=d.lte=function(t){return this.cmp(t)<1};d.logarithm=d.log=function(t){var e,n,r,i,o,s,u,c,a=this,l=a.constructor,f=l.precision,p=l.rounding,m=5;if(t==null)t=new l(10),e=!0;else{if(t=new l(t),n=t.d,t.s<0||!n||!n[0]||t.eq(1))return new l(NaN);e=t.eq(10)}if(n=a.d,a.s<0||!n||!n[0]||a.eq(1))return new l(n&&!n[0]?-1/0:a.s!=1?NaN:n?0:1/0);if(e)if(n.length>1)o=!0;else{for(i=n[0];i%10===0;)i/=10;o=i!==1}if(M=!1,u=f+m,s=me(a,u),r=e?Xe(l,u+10):me(t,u),c=W(s,r,u,1),_e(c.d,i=f,p))do if(u+=10,s=me(a,u),r=e?Xe(l,u+10):me(t,u),c=W(s,r,u,1),!o){+Q(c.d).slice(i+1,i+15)+1==1e14&&(c=S(c,f+1,0));break}while(_e(c.d,i+=10,p));return M=!0,S(c,f,p)};d.minus=d.sub=function(t){var e,n,r,i,o,s,u,c,a,l,f,p,m=this,b=m.constructor;if(t=new b(t),!m.d||!t.d)return!m.s||!t.s?t=new b(NaN):m.d?t.s=-t.s:t=new b(t.d||m.s!==t.s?m:NaN),t;if(m.s!=t.s)return t.s=-t.s,m.plus(t);if(a=m.d,p=t.d,u=b.precision,c=b.rounding,!a[0]||!p[0]){if(p[0])t.s=-t.s;else if(a[0])t=new b(m);else return new b(c===3?-0:0);return M?S(t,u,c):t}if(n=Y(t.e/L),l=Y(m.e/L),a=a.slice(),o=l-n,o){for(f=o<0,f?(e=a,o=-o,s=p.length):(e=p,n=l,s=a.length),r=Math.max(Math.ceil(u/L),s)+2,o>r&&(o=r,e.length=1),e.reverse(),r=o;r--;)e.push(0);e.reverse()}else{for(r=a.length,s=p.length,f=r<s,f&&(s=r),r=0;r<s;r++)if(a[r]!=p[r]){f=a[r]<p[r];break}o=0}for(f&&(e=a,a=p,p=e,t.s=-t.s),s=a.length,r=p.length-s;r>0;--r)a[s++]=0;for(r=p.length;r>o;){if(a[--r]<p[r]){for(i=r;i&&a[--i]===0;)a[i]=ie-1;--a[i],a[r]+=ie}a[r]-=p[r]}for(;a[--s]===0;)a.pop();for(;a[0]===0;a.shift())--n;return a[0]?(t.d=a,t.e=et(a,n),M?S(t,u,c):t):new b(c===3?-0:0)};d.modulo=d.mod=function(t){var e,n=this,r=n.constructor;return t=new r(t),!n.d||!t.s||t.d&&!t.d[0]?new r(NaN):!t.d||n.d&&!n.d[0]?S(new r(n),r.precision,r.rounding):(M=!1,r.modulo==9?(e=W(n,t.abs(),0,3,1),e.s*=t.s):e=W(n,t,0,r.modulo,1),e=e.times(t),M=!0,n.minus(e))};d.naturalExponential=d.exp=function(){return Lt(this)};d.naturalLogarithm=d.ln=function(){return me(this)};d.negated=d.neg=function(){var t=new this.constructor(this);return t.s=-t.s,S(t)};d.plus=d.add=function(t){var e,n,r,i,o,s,u,c,a,l,f=this,p=f.constructor;if(t=new p(t),!f.d||!t.d)return!f.s||!t.s?t=new p(NaN):f.d||(t=new p(t.d||f.s===t.s?f:NaN)),t;if(f.s!=t.s)return t.s=-t.s,f.minus(t);if(a=f.d,l=t.d,u=p.precision,c=p.rounding,!a[0]||!l[0])return l[0]||(t=new p(f)),M?S(t,u,c):t;if(o=Y(f.e/L),r=Y(t.e/L),a=a.slice(),i=o-r,i){for(i<0?(n=a,i=-i,s=l.length):(n=l,r=o,s=a.length),o=Math.ceil(u/L),s=o>s?o+1:s+1,i>s&&(i=s,n.length=1),n.reverse();i--;)n.push(0);n.reverse()}for(s=a.length,i=l.length,s-i<0&&(i=s,n=l,l=a,a=n),e=0;i;)e=(a[--i]=a[i]+l[i]+e)/ie|0,a[i]%=ie;for(e&&(a.unshift(e),++r),s=a.length;a[--s]==0;)a.pop();return t.d=a,t.e=et(a,r),M?S(t,u,c):t};d.precision=d.sd=function(t){var e,n=this;if(t!==void 0&&t!==!!t&&t!==1&&t!==0)throw Error(ge+t);return n.d?(e=fn(n.d),t&&n.e+1>e&&(e=n.e+1)):e=NaN,e};d.round=function(){var t=this,e=t.constructor;return S(new e(t),t.e+1,e.rounding)};d.sine=d.sin=function(){var t,e,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(t=r.precision,e=r.rounding,r.precision=t+Math.max(n.e,n.sd())+L,r.rounding=1,n=lr(r,gn(r,n)),r.precision=t,r.rounding=e,S(ce>2?n.neg():n,t,e,!0)):new r(NaN)};d.squareRoot=d.sqrt=function(){var t,e,n,r,i,o,s=this,u=s.d,c=s.e,a=s.s,l=s.constructor;if(a!==1||!u||!u[0])return new l(!a||a<0&&(!u||u[0])?NaN:u?s:1/0);for(M=!1,a=Math.sqrt(+s),a==0||a==1/0?(e=Q(u),(e.length+c)%2==0&&(e+="0"),a=Math.sqrt(e),c=Y((c+1)/2)-(c<0||c%2),a==1/0?e="5e"+c:(e=a.toExponential(),e=e.slice(0,e.indexOf("e")+1)+c),r=new l(e)):r=new l(a.toString()),n=(c=l.precision)+3;;)if(o=r,r=o.plus(W(s,o,n+2,1)).times(.5),Q(o.d).slice(0,n)===(e=Q(r.d)).slice(0,n))if(e=e.slice(n-3,n+1),e=="9999"||!i&&e=="4999"){if(!i&&(S(o,c+1,0),o.times(o).eq(s))){r=o;break}n+=4,i=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(S(r,c+1,1),t=!r.times(r).eq(s));break}return M=!0,S(r,c,l.rounding,t)};d.tangent=d.tan=function(){var t,e,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(t=r.precision,e=r.rounding,r.precision=t+10,r.rounding=1,n=n.sin(),n.s=1,n=W(n,new r(1).minus(n.times(n)).sqrt(),t+10,0),r.precision=t,r.rounding=e,S(ce==2||ce==4?n.neg():n,t,e,!0)):new r(NaN)};d.times=d.mul=function(t){var e,n,r,i,o,s,u,c,a,l=this,f=l.constructor,p=l.d,m=(t=new f(t)).d;if(t.s*=l.s,!p||!p[0]||!m||!m[0])return new f(!t.s||p&&!p[0]&&!m||m&&!m[0]&&!p?NaN:!p||!m?t.s/0:t.s*0);for(n=Y(l.e/L)+Y(t.e/L),c=p.length,a=m.length,c<a&&(o=p,p=m,m=o,s=c,c=a,a=s),o=[],s=c+a,r=s;r--;)o.push(0);for(r=a;--r>=0;){for(e=0,i=c+r;i>r;)u=o[i]+m[r]*p[i-r-1]+e,o[i--]=u%ie|0,e=u/ie|0;o[i]=(o[i]+e)%ie|0}for(;!o[--s];)o.pop();return e?++n:o.shift(),t.d=o,t.e=et(o,n),M?S(t,f.precision,f.rounding):t};d.toBinary=function(t,e){return kt(this,2,t,e)};d.toDecimalPlaces=d.toDP=function(t,e){var n=this,r=n.constructor;return n=new r(n),t===void 0?n:(ne(t,0,he),e===void 0?e=r.rounding:ne(e,0,8),S(n,t+n.e+1,e))};d.toExponential=function(t,e){var n,r=this,i=r.constructor;return t===void 0?n=se(r,!0):(ne(t,0,he),e===void 0?e=i.rounding:ne(e,0,8),r=S(new i(r),t+1,e),n=se(r,!0,t+1)),r.isNeg()&&!r.isZero()?"-"+n:n};d.toFixed=function(t,e){var n,r,i=this,o=i.constructor;return t===void 0?n=se(i):(ne(t,0,he),e===void 0?e=o.rounding:ne(e,0,8),r=S(new o(i),t+i.e+1,e),n=se(r,!1,t+r.e+1)),i.isNeg()&&!i.isZero()?"-"+n:n};d.toFraction=function(t){var e,n,r,i,o,s,u,c,a,l,f,p,m=this,b=m.d,g=m.constructor;if(!b)return new g(m);if(a=n=new g(1),r=c=new g(0),e=new g(r),o=e.e=fn(b)-m.e-1,s=o%L,e.d[0]=H(10,s<0?L+s:s),t==null)t=o>0?e:a;else{if(u=new g(t),!u.isInt()||u.lt(a))throw Error(ge+u);t=u.gt(e)?o>0?e:a:u}for(M=!1,u=new g(Q(b)),l=g.precision,g.precision=o=b.length*L*2;f=W(u,e,0,1,1),i=n.plus(f.times(r)),i.cmp(t)!=1;)n=r,r=i,i=a,a=c.plus(f.times(i)),c=i,i=e,e=u.minus(f.times(i)),u=i;return i=W(t.minus(n),r,0,1,1),c=c.plus(i.times(a)),n=n.plus(i.times(r)),c.s=a.s=m.s,p=W(a,r,o,1).minus(m).abs().cmp(W(c,n,o,1).minus(m).abs())<1?[a,r]:[c,n],g.precision=l,M=!0,p};d.toHexadecimal=d.toHex=function(t,e){return kt(this,16,t,e)};d.toNearest=function(t,e){var n=this,r=n.constructor;if(n=new r(n),t==null){if(!n.d)return n;t=new r(1),e=r.rounding}else{if(t=new r(t),e===void 0?e=r.rounding:ne(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]?(M=!1,n=W(n,t,0,e,1).times(t),M=!0,S(n)):(t.s=n.s,n=t),n};d.toNumber=function(){return+this};d.toOctal=function(t,e){return kt(this,8,t,e)};d.toPower=d.pow=function(t){var e,n,r,i,o,s,u=this,c=u.constructor,a=+(t=new c(t));if(!u.d||!t.d||!u.d[0]||!t.d[0])return new c(H(+u,a));if(u=new c(u),u.eq(1))return u;if(r=c.precision,o=c.rounding,t.eq(1))return S(u,r,o);if(e=Y(t.e/L),e>=t.d.length-1&&(n=a<0?-a:a)<=sr)return i=pn(c,u,n,r),t.s<0?new c(1).div(i):S(i,r,o);if(s=u.s,s<0){if(e<t.d.length-1)return new c(NaN);if((t.d[e]&1)==0&&(s=1),u.e==0&&u.d[0]==1&&u.d.length==1)return u.s=s,u}return n=H(+u,a),e=n==0||!isFinite(n)?Y(a*(Math.log("0."+Q(u.d))/Math.LN10+u.e+1)):new c(n+"").e,e>c.maxE+1||e<c.minE-1?new c(e>0?s/0:0):(M=!1,c.rounding=u.s=1,n=Math.min(12,(e+"").length),i=Lt(t.times(me(u,r+n)),r),i.d&&(i=S(i,r+5,1),_e(i.d,r,o)&&(e=r+10,i=S(Lt(t.times(me(u,e+n)),e),e+5,1),+Q(i.d).slice(r+1,r+15)+1==1e14&&(i=S(i,r+1,0)))),i.s=s,M=!0,c.rounding=o,S(i,r,o))};d.toPrecision=function(t,e){var n,r=this,i=r.constructor;return t===void 0?n=se(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(ne(t,1,he),e===void 0?e=i.rounding:ne(e,0,8),r=S(new i(r),t,e),n=se(r,t<=r.e||r.e<=i.toExpNeg,t)),r.isNeg()&&!r.isZero()?"-"+n:n};d.toSignificantDigits=d.toSD=function(t,e){var n=this,r=n.constructor;return t===void 0?(t=r.precision,e=r.rounding):(ne(t,1,he),e===void 0?e=r.rounding:ne(e,0,8)),S(new r(n),t,e)};d.toString=function(){var t=this,e=t.constructor,n=se(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()&&!t.isZero()?"-"+n:n};d.truncated=d.trunc=function(){return S(new this.constructor(this),this.e+1,1)};d.valueOf=d.toJSON=function(){var t=this,e=t.constructor,n=se(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()?"-"+n:n};function Q(t){var e,n,r,i=t.length-1,o="",s=t[0];if(i>0){for(o+=s,e=1;e<i;e++)r=t[e]+"",n=L-r.length,n&&(o+=de(n)),o+=r;s=t[e],r=s+"",n=L-r.length,n&&(o+=de(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function ne(t,e,n){if(t!==~~t||t<e||t>n)throw Error(ge+t)}function _e(t,e,n,r){var i,o,s,u;for(o=t[0];o>=10;o/=10)--e;return--e<0?(e+=L,i=0):(i=Math.ceil((e+1)/L),e%=L),o=H(10,L-e),u=t[i]%o|0,r==null?e<3?(e==0?u=u/100|0:e==1&&(u=u/10|0),s=n<4&&u==99999||n>3&&u==49999||u==5e4||u==0):s=(n<4&&u+1==o||n>3&&u+1==o/2)&&(t[i+1]/o/100|0)==H(10,e-2)-1||(u==o/2||u==0)&&(t[i+1]/o/100|0)==0:e<4?(e==0?u=u/1e3|0:e==1?u=u/100|0:e==2&&(u=u/10|0),s=(r||n<4)&&u==9999||!r&&n>3&&u==4999):s=((r||n<4)&&u+1==o||!r&&n>3&&u+1==o/2)&&(t[i+1]/o/1e3|0)==H(10,e-3)-1,s}function Ye(t,e,n){for(var r,i=[0],o,s=0,u=t.length;s<u;){for(o=i.length;o--;)i[o]*=e;for(i[0]+=At.indexOf(t.charAt(s++)),r=0;r<i.length;r++)i[r]>n-1&&(i[r+1]===void 0&&(i[r+1]=0),i[r+1]+=i[r]/n|0,i[r]%=n)}return i.reverse()}function ar(t,e){var n,r,i;if(e.isZero())return e;r=e.d.length,r<32?(n=Math.ceil(r/3),i=(1/tt(4,n)).toString()):(n=16,i="2.3283064365386962890625e-10"),t.precision+=n,e=Be(t,1,e.times(i),new t(1));for(var o=n;o--;){var s=e.times(e);e=s.times(s).minus(s).times(8).plus(1)}return t.precision-=n,e}var W=function(){function t(r,i,o){var s,u=0,c=r.length;for(r=r.slice();c--;)s=r[c]*i+u,r[c]=s%o|0,u=s/o|0;return u&&r.unshift(u),r}function e(r,i,o,s){var u,c;if(o!=s)c=o>s?1:-1;else for(u=c=0;u<o;u++)if(r[u]!=i[u]){c=r[u]>i[u]?1:-1;break}return c}function n(r,i,o,s){for(var u=0;o--;)r[o]-=u,u=r[o]<i[o]?1:0,r[o]=u*s+r[o]-i[o];for(;!r[0]&&r.length>1;)r.shift()}return function(r,i,o,s,u,c){var a,l,f,p,m,b,g,h,T,A,x,y,P,w,N,C,I,O,D,v,_=r.constructor,q=r.s==i.s?1:-1,K=r.d,k=i.d;if(!K||!K[0]||!k||!k[0])return new _(!r.s||!i.s||(K?k&&K[0]==k[0]:!k)?NaN:K&&K[0]==0||!k?q*0:q/0);for(c?(m=1,l=r.e-i.e):(c=ie,m=L,l=Y(r.e/m)-Y(i.e/m)),D=k.length,I=K.length,T=new _(q),A=T.d=[],f=0;k[f]==(K[f]||0);f++);if(k[f]>(K[f]||0)&&l--,o==null?(w=o=_.precision,s=_.rounding):u?w=o+(r.e-i.e)+1:w=o,w<0)A.push(1),b=!0;else{if(w=w/m+2|0,f=0,D==1){for(p=0,k=k[0],w++;(f<I||p)&&w--;f++)N=p*c+(K[f]||0),A[f]=N/k|0,p=N%k|0;b=p||f<I}else{for(p=c/(k[0]+1)|0,p>1&&(k=t(k,p,c),K=t(K,p,c),D=k.length,I=K.length),C=D,x=K.slice(0,D),y=x.length;y<D;)x[y++]=0;v=k.slice(),v.unshift(0),O=k[0],k[1]>=c/2&&++O;do p=0,a=e(k,x,D,y),a<0?(P=x[0],D!=y&&(P=P*c+(x[1]||0)),p=P/O|0,p>1?(p>=c&&(p=c-1),g=t(k,p,c),h=g.length,y=x.length,a=e(g,x,h,y),a==1&&(p--,n(g,D<h?v:k,h,c))):(p==0&&(a=p=1),g=k.slice()),h=g.length,h<y&&g.unshift(0),n(x,g,y,c),a==-1&&(y=x.length,a=e(k,x,D,y),a<1&&(p++,n(x,D<y?v:k,y,c))),y=x.length):a===0&&(p++,x=[0]),A[f++]=p,a&&x[0]?x[y++]=K[C]||0:(x=[K[C]],y=1);while((C++<I||x[0]!==void 0)&&w--);b=x[0]!==void 0}A[0]||A.shift()}if(m==1)T.e=l,sn=b;else{for(f=1,p=A[0];p>=10;p/=10)f++;T.e=f+l*m-1,S(T,u?o+T.e+1:o,s,b)}return T}}();function S(t,e,n,r){var i,o,s,u,c,a,l,f,p,m=t.constructor;e:if(e!=null){if(f=t.d,!f)return t;for(i=1,u=f[0];u>=10;u/=10)i++;if(o=e-i,o<0)o+=L,s=e,l=f[p=0],c=l/H(10,i-s-1)%10|0;else if(p=Math.ceil((o+1)/L),u=f.length,p>=u)if(r){for(;u++<=p;)f.push(0);l=c=0,i=1,o%=L,s=o-L+1}else break e;else{for(l=u=f[p],i=1;u>=10;u/=10)i++;o%=L,s=o-L+i,c=s<0?0:l/H(10,i-s-1)%10|0}if(r=r||e<0||f[p+1]!==void 0||(s<0?l:l%H(10,i-s-1)),a=n<4?(c||r)&&(n==0||n==(t.s<0?3:2)):c>5||c==5&&(n==4||r||n==6&&(o>0?s>0?l/H(10,i-s):0:f[p-1])%10&1||n==(t.s<0?8:7)),e<1||!f[0])return f.length=0,a?(e-=t.e+1,f[0]=H(10,(L-e%L)%L),t.e=-e||0):f[0]=t.e=0,t;if(o==0?(f.length=p,u=1,p--):(f.length=p+1,u=H(10,L-o),f[p]=s>0?(l/H(10,i-s)%H(10,s)|0)*u:0),a)for(;;)if(p==0){for(o=1,s=f[0];s>=10;s/=10)o++;for(s=f[0]+=u,u=1;s>=10;s/=10)u++;o!=u&&(t.e++,f[0]==ie&&(f[0]=1));break}else{if(f[p]+=u,f[p]!=ie)break;f[p--]=0,u=1}for(o=f.length;f[--o]===0;)f.pop()}return M&&(t.e>m.maxE?(t.d=null,t.e=NaN):t.e<m.minE&&(t.e=0,t.d=[0])),t}function se(t,e,n){if(!t.isFinite())return mn(t);var r,i=t.e,o=Q(t.d),s=o.length;return e?(n&&(r=n-s)>0?o=o.charAt(0)+"."+o.slice(1)+de(r):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(t.e<0?"e":"e+")+t.e):i<0?(o="0."+de(-i-1)+o,n&&(r=n-s)>0&&(o+=de(r))):i>=s?(o+=de(i+1-s),n&&(r=n-i-1)>0&&(o=o+"."+de(r))):((r=i+1)<s&&(o=o.slice(0,r)+"."+o.slice(r)),n&&(r=n-s)>0&&(i+1===s&&(o+="."),o+=de(r))),o}function et(t,e){var n=t[0];for(e*=L;n>=10;n/=10)e++;return e}function Xe(t,e,n){if(e>ur)throw M=!0,n&&(t.precision=n),Error(un);return S(new t(Ze),e,1,!0)}function re(t,e,n){if(e>Bt)throw Error(un);return S(new t(Je),e,n,!0)}function fn(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 de(t){for(var e="";t--;)e+="0";return e}function pn(t,e,n,r){var i,o=new t(1),s=Math.ceil(r/L+4);for(M=!1;;){if(n%2&&(o=o.times(e),rn(o.d,s)&&(i=!0)),n=Y(n/2),n===0){n=o.d.length-1,i&&o.d[n]===0&&++o.d[n];break}e=e.times(e),rn(e.d,s)}return M=!0,o}function nn(t){return t.d[t.d.length-1]&1}function dn(t,e,n){for(var r,i=new t(e[0]),o=0;++o<e.length;)if(r=new t(e[o]),r.s)i[n](r)&&(i=r);else{i=r;break}return i}function Lt(t,e){var n,r,i,o,s,u,c,a=0,l=0,f=0,p=t.constructor,m=p.rounding,b=p.precision;if(!t.d||!t.d[0]||t.e>17)return new p(t.d?t.d[0]?t.s<0?0:1/0:1:t.s?t.s<0?0:t:0/0);for(e==null?(M=!1,c=b):c=e,u=new p(.03125);t.e>-2;)t=t.times(u),f+=5;for(r=Math.log(H(2,f))/Math.LN10*2+5|0,c+=r,n=o=s=new p(1),p.precision=c;;){if(o=S(o.times(t),c,1),n=n.times(++l),u=s.plus(W(o,n,c,1)),Q(u.d).slice(0,c)===Q(s.d).slice(0,c)){for(i=f;i--;)s=S(s.times(s),c,1);if(e==null)if(a<3&&_e(s.d,c-r,m,a))p.precision=c+=10,n=o=u=new p(1),l=0,a++;else return S(s,p.precision=b,m,M=!0);else return p.precision=b,s}s=u}}function me(t,e){var n,r,i,o,s,u,c,a,l,f,p,m=1,b=10,g=t,h=g.d,T=g.constructor,A=T.rounding,x=T.precision;if(g.s<0||!h||!h[0]||!g.e&&h[0]==1&&h.length==1)return new T(h&&!h[0]?-1/0:g.s!=1?NaN:h?0:g);if(e==null?(M=!1,l=x):l=e,T.precision=l+=b,n=Q(h),r=n.charAt(0),Math.abs(o=g.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)g=g.times(t),n=Q(g.d),r=n.charAt(0),m++;o=g.e,r>1?(g=new T("0."+n),o++):g=new T(r+"."+n.slice(1))}else return a=Xe(T,l+2,x).times(o+""),g=me(new T(r+"."+n.slice(1)),l-b).plus(a),T.precision=x,e==null?S(g,x,A,M=!0):g;for(f=g,c=s=g=W(g.minus(1),g.plus(1),l,1),p=S(g.times(g),l,1),i=3;;){if(s=S(s.times(p),l,1),a=c.plus(W(s,new T(i),l,1)),Q(a.d).slice(0,l)===Q(c.d).slice(0,l))if(c=c.times(2),o!==0&&(c=c.plus(Xe(T,l+2,x).times(o+""))),c=W(c,new T(m),l,1),e==null)if(_e(c.d,l-b,A,u))T.precision=l+=b,a=s=g=W(f.minus(1),f.plus(1),l,1),p=S(g.times(g),l,1),i=u=1;else return S(c,T.precision=x,A,M=!0);else return T.precision=x,c;c=a,i+=2}}function mn(t){return String(t.s*t.s/0)}function Ct(t,e){var n,r,i;for((n=e.indexOf("."))>-1&&(e=e.replace(".","")),(r=e.search(/e/i))>0?(n<0&&(n=r),n+=+e.slice(r+1),e=e.substring(0,r)):n<0&&(n=e.length),r=0;e.charCodeAt(r)===48;r++);for(i=e.length;e.charCodeAt(i-1)===48;--i);if(e=e.slice(r,i),e){if(i-=r,t.e=n=n-r-1,t.d=[],r=(n+1)%L,n<0&&(r+=L),r<i){for(r&&t.d.push(+e.slice(0,r)),i-=L;r<i;)t.d.push(+e.slice(r,r+=L));e=e.slice(r),r=L-e.length}else r-=i;for(;r--;)e+="0";t.d.push(+e),M&&(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 cr(t,e){var n,r,i,o,s,u,c,a,l;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),ln.test(e))return Ct(t,e)}else if(e==="Infinity"||e==="NaN")return+e||(t.s=NaN),t.e=NaN,t.d=null,t;if(ir.test(e))n=16,e=e.toLowerCase();else if(rr.test(e))n=2;else if(or.test(e))n=8;else throw Error(ge+e);for(o=e.search(/p/i),o>0?(c=+e.slice(o+1),e=e.substring(2,o)):e=e.slice(2),o=e.indexOf("."),s=o>=0,r=t.constructor,s&&(e=e.replace(".",""),u=e.length,o=u-o,i=pn(r,new r(n),o,o*2)),a=Ye(e,n,ie),l=a.length-1,o=l;a[o]===0;--o)a.pop();return o<0?new r(t.s*0):(t.e=et(a,l),t.d=a,M=!1,s&&(t=W(t,i,u*4)),c&&(t=t.times(Math.abs(c)<54?H(2,c):nt.pow(2,c))),M=!0,t)}function lr(t,e){var n,r=e.d.length;if(r<3)return e.isZero()?e:Be(t,2,e,e);n=1.4*Math.sqrt(r),n=n>16?16:n|0,e=e.times(1/tt(5,n)),e=Be(t,2,e,e);for(var i,o=new t(5),s=new t(16),u=new t(20);n--;)i=e.times(e),e=e.times(o.plus(i.times(s.times(i).minus(u))));return e}function Be(t,e,n,r,i){var o,s,u,c,a=1,l=t.precision,f=Math.ceil(l/L);for(M=!1,c=n.times(n),u=new t(r);;){if(s=W(u.times(c),new t(e++*e++),l,1),u=i?r.plus(s):r.minus(s),r=W(s.times(c),new t(e++*e++),l,1),s=u.plus(r),s.d[f]!==void 0){for(o=f;s.d[o]===u.d[o]&&o--;);if(o==-1)break}o=u,u=r,r=s,s=o,a++}return M=!0,s.d.length=f+1,s}function tt(t,e){for(var n=t;--e;)n*=t;return n}function gn(t,e){var n,r=e.s<0,i=re(t,t.precision,1),o=i.times(.5);if(e=e.abs(),e.lte(o))return ce=r?4:1,e;if(n=e.divToInt(i),n.isZero())ce=r?3:2;else{if(e=e.minus(n.times(i)),e.lte(o))return ce=nn(n)?r?2:3:r?4:1,e;ce=nn(n)?r?1:4:r?3:2}return e.minus(i).abs()}function kt(t,e,n,r){var i,o,s,u,c,a,l,f,p,m=t.constructor,b=n!==void 0;if(b?(ne(n,1,he),r===void 0?r=m.rounding:ne(r,0,8)):(n=m.precision,r=m.rounding),!t.isFinite())l=mn(t);else{for(l=se(t),s=l.indexOf("."),b?(i=2,e==16?n=n*4-3:e==8&&(n=n*3-2)):i=e,s>=0&&(l=l.replace(".",""),p=new m(1),p.e=l.length-s,p.d=Ye(se(p),10,i),p.e=p.d.length),f=Ye(l,10,i),o=c=f.length;f[--c]==0;)f.pop();if(!f[0])l=b?"0p+0":"0";else{if(s<0?o--:(t=new m(t),t.d=f,t.e=o,t=W(t,p,n,r,0,i),f=t.d,o=t.e,a=sn),s=f[n],u=i/2,a=a||f[n+1]!==void 0,a=r<4?(s!==void 0||a)&&(r===0||r===(t.s<0?3:2)):s>u||s===u&&(r===4||a||r===6&&f[n-1]&1||r===(t.s<0?8:7)),f.length=n,a)for(;++f[--n]>i-1;)f[n]=0,n||(++o,f.unshift(1));for(c=f.length;!f[c-1];--c);for(s=0,l="";s<c;s++)l+=At.charAt(f[s]);if(b){if(c>1)if(e==16||e==8){for(s=e==16?4:3,--c;c%s;c++)l+="0";for(f=Ye(l,i,e),c=f.length;!f[c-1];--c);for(s=1,l="1.";s<c;s++)l+=At.charAt(f[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)l="0"+l;l="0."+l}else if(++o>c)for(o-=c;o--;)l+="0";else o<c&&(l=l.slice(0,o)+"."+l.slice(o))}l=(e==16?"0x":e==2?"0b":e==8?"0o":"")+l}return t.s<0?"-"+l:l}function rn(t,e){if(t.length>e)return t.length=e,!0}function fr(t){return new this(t).abs()}function pr(t){return new this(t).acos()}function dr(t){return new this(t).acosh()}function mr(t,e){return new this(t).plus(e)}function gr(t){return new this(t).asin()}function hr(t){return new this(t).asinh()}function br(t){return new this(t).atan()}function yr(t){return new this(t).atanh()}function wr(t,e){t=new this(t),e=new this(e);var n,r=this.precision,i=this.rounding,o=r+4;return!t.s||!e.s?n=new this(NaN):!t.d&&!e.d?(n=re(this,o,1).times(e.s>0?.25:.75),n.s=t.s):!e.d||t.isZero()?(n=e.s<0?re(this,r,i):new this(0),n.s=t.s):!t.d||e.isZero()?(n=re(this,o,1).times(.5),n.s=t.s):e.s<0?(this.precision=o,this.rounding=1,n=this.atan(W(t,e,o,1)),e=re(this,o,1),this.precision=r,this.rounding=i,n=t.s<0?n.minus(e):n.plus(e)):n=this.atan(W(t,e,o,1)),n}function xr(t){return new this(t).cbrt()}function Tr(t){return S(t=new this(t),t.e+1,2)}function Pr(t,e,n){return new this(t).clamp(e,n)}function Ar(t){if(!t||typeof t!="object")throw Error($e+"Object expected");var e,n,r,i=t.defaults===!0,o=["precision",1,he,"rounding",0,8,"toExpNeg",-Se,0,"toExpPos",0,Se,"maxE",0,Se,"minE",-Se,0,"modulo",0,9];for(e=0;e<o.length;e+=3)if(n=o[e],i&&(this[n]=St[n]),(r=t[n])!==void 0)if(Y(r)===r&&r>=o[e+1]&&r<=o[e+2])this[n]=r;else throw Error(ge+n+": "+r);if(n="crypto",i&&(this[n]=St[n]),(r=t[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(an);else this[n]=!1;else throw Error(ge+n+": "+r);return this}function Sr(t){return new this(t).cos()}function Br(t){return new this(t).cosh()}function hn(t){var e,n,r;function i(o){var s,u,c,a=this;if(!(a instanceof i))return new i(o);if(a.constructor=i,on(o)){a.s=o.s,M?!o.d||o.e>i.maxE?(a.e=NaN,a.d=null):o.e<i.minE?(a.e=0,a.d=[0]):(a.e=o.e,a.d=o.d.slice()):(a.e=o.e,a.d=o.d?o.d.slice():o.d);return}if(c=typeof o,c==="number"){if(o===0){a.s=1/o<0?-1:1,a.e=0,a.d=[0];return}if(o<0?(o=-o,a.s=-1):a.s=1,o===~~o&&o<1e7){for(s=0,u=o;u>=10;u/=10)s++;M?s>i.maxE?(a.e=NaN,a.d=null):s<i.minE?(a.e=0,a.d=[0]):(a.e=s,a.d=[o]):(a.e=s,a.d=[o]);return}else if(o*0!==0){o||(a.s=NaN),a.e=NaN,a.d=null;return}return Ct(a,o.toString())}else if(c!=="string")throw Error(ge+o);return(u=o.charCodeAt(0))===45?(o=o.slice(1),a.s=-1):(u===43&&(o=o.slice(1)),a.s=1),ln.test(o)?Ct(a,o):cr(a,o)}if(i.prototype=d,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=Ar,i.clone=hn,i.isDecimal=on,i.abs=fr,i.acos=pr,i.acosh=dr,i.add=mr,i.asin=gr,i.asinh=hr,i.atan=br,i.atanh=yr,i.atan2=wr,i.cbrt=xr,i.ceil=Tr,i.clamp=Pr,i.cos=Sr,i.cosh=Br,i.div=Lr,i.exp=Cr,i.floor=kr,i.hypot=Nr,i.ln=Mr,i.log=Er,i.log10=Ir,i.log2=Rr,i.max=vr,i.min=Dr,i.mod=_r,i.mul=Kr,i.pow=Or,i.random=Fr,i.round=Vr,i.sign=qr,i.sin=Wr,i.sinh=Ur,i.sqrt=Gr,i.sub=Hr,i.sum=zr,i.tan=Qr,i.tanh=jr,i.trunc=Yr,t===void 0&&(t={}),t&&t.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<r.length;)t.hasOwnProperty(n=r[e++])||(t[n]=this[n]);return i.config(t),i}function Lr(t,e){return new this(t).div(e)}function Cr(t){return new this(t).exp()}function kr(t){return S(t=new this(t),t.e+1,3)}function Nr(){var t,e,n=new this(0);for(M=!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 M=!0,new this(1/0);n=e}return M=!0,n.sqrt()}function on(t){return t instanceof nt||t&&t.toStringTag===cn||!1}function Mr(t){return new this(t).ln()}function Er(t,e){return new this(t).log(e)}function Rr(t){return new this(t).log(2)}function Ir(t){return new this(t).log(10)}function vr(){return dn(this,arguments,"lt")}function Dr(){return dn(this,arguments,"gt")}function _r(t,e){return new this(t).mod(e)}function Kr(t,e){return new this(t).mul(e)}function Or(t,e){return new this(t).pow(e)}function Fr(t){var e,n,r,i,o=0,s=new this(1),u=[];if(t===void 0?t=this.precision:ne(t,1,he),r=Math.ceil(t/L),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(r));o<r;)i=e[o],i>=429e7?e[o]=crypto.getRandomValues(new Uint32Array(1))[0]:u[o++]=i%1e7;else if(crypto.randomBytes){for(e=crypto.randomBytes(r*=4);o<r;)i=e[o]+(e[o+1]<<8)+(e[o+2]<<16)+((e[o+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(e,o):(u.push(i%1e7),o+=4);o=r/4}else throw Error(an);else for(;o<r;)u[o++]=Math.random()*1e7|0;for(r=u[--o],t%=L,r&&t&&(i=H(10,L-t),u[o]=(r/i|0)*i);u[o]===0;o--)u.pop();if(o<0)n=0,u=[0];else{for(n=-1;u[0]===0;n-=L)u.shift();for(r=1,i=u[0];i>=10;i/=10)r++;r<L&&(n-=L-r)}return s.e=n,s.d=u,s}function Vr(t){return S(t=new this(t),t.e+1,this.rounding)}function qr(t){return t=new this(t),t.d?t.d[0]?t.s:0*t.s:t.s||NaN}function Wr(t){return new this(t).sin()}function Ur(t){return new this(t).sinh()}function Gr(t){return new this(t).sqrt()}function Hr(t,e){return new this(t).sub(e)}function zr(){var t=0,e=arguments,n=new this(e[t]);for(M=!1;n.s&&++t<e.length;)n=n.plus(e[t]);return M=!0,S(n,this.precision,this.rounding)}function Qr(t){return new this(t).tan()}function jr(t){return new this(t).tanh()}function Yr(t){return S(t=new this(t),t.e+1,1)}d[Symbol.for("nodejs.util.inspect.custom")]=d.toString;d[Symbol.toStringTag]="Decimal";var nt=d.constructor=hn(St);Ze=new nt(Ze);Je=new nt(Je);var Kn=X(require("big.js")),gi=X(require("bn.js"));var Ke=require("lodash");var Nt=class{constructor(e){this.logLevel=e.logLevel!==void 0?e.logLevel:0,this.name=e.name}set level(e){this.logLevel=e}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(e){return e<=this.logLevel}error(...e){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...e),this):this}logWithError(...e){let n=e.map(r=>typeof r=="object"?JSON.stringify(r):r).join(", ");throw new Error(n)}warning(...e){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...e),this):this}info(...e){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...e),this):this}debug(...e){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...e),this):this}},bn={},Zr={};function Z(t){let e=(0,Ke.get)(bn,t);if(!e){let n=(0,Ke.get)(Zr,t);e=new Nt({name:t,logLevel:n}),(0,Ke.set)(bn,t,e)}return e}var yn=require("@solana/web3.js");var rt=require("@solana/spl-token"),Mt=Z("Raydium_accountInfo_util");async function wn(t,e,n){let{batchRequest:r,commitment:i="confirmed",chunkCount:o=100}=z({batchRequest:!1},n),s=Et(e,o),u=new Array(s.length).fill([]);if(r){let c=s.map(f=>{let p=t._buildArgs([f.map(m=>m.toBase58())],i,"base64");return{methodName:"getMultipleAccounts",args:p}}),a=Et(c,10);u=(await(await Promise.all(a.map(async f=>await t._rpcBatchRequest(f)))).flat()).map(f=>(f.error&&Mt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${f.error.message}`),f.result.value.map(p=>{if(p){let{data:m,executable:b,lamports:g,owner:h,rentEpoch:T}=p;return m.length!==2&&m[1]!=="base64"&&Mt.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(m[0],"base64"),executable:b,lamports:g,owner:new yn.PublicKey(h),rentEpoch:T}}return null})))}else try{u=await Promise.all(s.map(c=>t.getMultipleAccountsInfo(c,i)))}catch(c){c instanceof Error&&Mt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return u.flat()}var Le=X(require("bn.js"));var xn=9007199254740991;function le(t){let e=Z("Raydium_parseBigNumberish");if(t instanceof Le.default)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new Le.default(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=xn||t<=-xn)&&e.logWithError(`BigNumberish number overflow: ${t}`),new Le.default(String(t))):typeof t=="bigint"?new Le.default(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new Le.default(0))}var Tn=require("@solana/web3.js"),It=require("@solana/spl-token"),Pn={chainId:101,address:Tn.PublicKey.default.toBase58(),programId:It.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},Pe={chainId:101,address:"So11111111111111111111111111111111111111112",programId:It.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}};var it=require("@solana/web3.js");var V=require("@solana/web3.js"),An=require("@solana/spl-token");function vt({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var qi=[vt({pubkey:An.TOKEN_PROGRAM_ID,isWritable:!1}),vt({pubkey:V.SystemProgram.programId,isWritable:!1}),vt({pubkey:V.SYSVAR_RENT_PUBKEY,isWritable:!1})];function Sn({publicKey:t,transformSol:e}){let n=Bn(t.toString());if(n instanceof V.PublicKey)return e&&n.equals(Oe)?Rt:n;if(e&&n.toString()===Oe.toBase58())return Rt;if(typeof n=="string"){if(n===V.PublicKey.default.toBase58())return V.PublicKey.default;try{return new V.PublicKey(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function Bn(t){try{return new V.PublicKey(t)}catch{return t}}var Wi=new V.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Ui=new V.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Gi=new V.PublicKey("SysvarRent111111111111111111111111111111111"),Hi=new V.PublicKey("SysvarC1ock11111111111111111111111111111111"),zi=new V.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Qi=new V.PublicKey("Sysvar1nstructions1111111111111111111111111"),ji=V.SystemProgram.programId,Yi=new V.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Zi=new V.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Ji=new V.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Xi=new V.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),$i=new V.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),eo=new V.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),to=new V.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),no=new V.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),ro=new V.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),io=new V.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),oo=new V.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),Rt=new V.PublicKey("So11111111111111111111111111111111111111112"),Oe=V.PublicKey.default;var Dt=class{constructor({mint:e,decimals:n,symbol:r,name:i,skipMint:o=!1,isToken2022:s=!1}){if(e===Oe.toBase58()||e instanceof it.PublicKey&&Oe.equals(e)){this.decimals=Pe.decimals,this.symbol=Pe.symbol,this.name=Pe.name,this.mint=new it.PublicKey(Pe.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||e.toString().substring(0,6),this.name=i||e.toString().substring(0,6),this.mint=o?it.PublicKey.default:Sn({publicKey:e}),this.isToken2022=s}equals(e){return this===e?!0:this.mint.equals(e.mint)}},Ce=Dt;Ce.WSOL=new Dt(pe(z({},Pe),{mint:Pe.address}));var _t=class{constructor({decimals:e,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=r}equals(e){return this===e}},ot=_t;ot.SOL=new _t(Pn);var Ln=X(require("toformat")),Jr=Ln.default,Fe=Jr;var Ve=X(require("big.js")),Cn=X(require("bn.js")),kn=X(require("decimal.js-light"));var st=Z("module/fraction"),Kt=Fe(Ve.default),qe=Fe(kn.default),$r={[0]:qe.ROUND_DOWN,[1]:qe.ROUND_HALF_UP,[2]:qe.ROUND_UP},ei={[0]:Ve.default.roundDown,[1]:Ve.default.roundHalfUp,[2]:Ve.default.roundUp},U=class{constructor(e,n=new Cn.default(1)){this.numerator=le(e),this.denominator=le(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new U(this.denominator,this.numerator)}add(e){let n=e instanceof U?e:new U(le(e));return this.denominator.eq(n.denominator)?new U(this.numerator.add(n.numerator),this.denominator):new U(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(e){let n=e instanceof U?e:new U(le(e));return this.denominator.eq(n.denominator)?new U(this.numerator.sub(n.numerator),this.denominator):new U(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(e){let n=e instanceof U?e:new U(le(e));return new U(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(e){let n=e instanceof U?e:new U(le(e));return new U(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(e,n={groupSeparator:""},r=1){Number.isInteger(e)||st.logWithError(`${e} is not an integer.`),e<=0&&st.logWithError(`${e} is not positive.`),qe.set({precision:e+1,rounding:$r[r]});let i=new qe(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return i.toFormat(i.decimalPlaces(),n)}toFixed(e,n={groupSeparator:""},r=1){return Number.isInteger(e)||st.logWithError(`${e} is not an integer.`),e<0&&st.logWithError(`${e} is negative.`),Kt.DP=e,Kt.RM=ei[r]||1,new Kt(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};var Nn=X(require("bn.js"));var Po=new U(new Nn.default(100));var ko=Z("Raydium_price");function Et(t,e=1,n=[]){let r=[...t];if(e<=0)return n;for(;r.length;)n.push(r.splice(0,e));return n}var ii=require("@solana/web3.js"),oi=require("@solana/spl-token");var $=require("@solana/web3.js");var J={CreateAccount:"CreateAccount",InitAccount:"InitAccount",CreateATA:"CreateATA",CloseAccount:"CloseAccount",TransferAmount:"TransferAmount",InitMint:"InitMint",MintTo:"MintTo",InitMarket:"InitMarket",Util1216OwnerClaim:"Util1216OwnerClaim",SetComputeUnitPrice:"SetComputeUnitPrice",SetComputeUnitLimit:"SetComputeUnitLimit",ClmmCreatePool:"ClmmCreatePool",ClmmOpenPosition:"ClmmOpenPosition",ClmmIncreasePosition:"ClmmIncreasePosition",ClmmDecreasePosition:"ClmmDecreasePosition",ClmmClosePosition:"ClmmClosePosition",ClmmSwapBaseIn:"ClmmSwapBaseIn",ClmmSwapBaseOut:"ClmmSwapBaseOut",ClmmInitReward:"ClmmInitReward",ClmmSetReward:"ClmmSetReward",ClmmCollectReward:"ClmmCollectReward",ClmmLockPosition:"ClmmLockPosition",ClmmHarvestLockPosition:"ClmmHarvestLockPosition",CustodyInitializeUser:"CustodyInitializeUser",CustodyDeposit:"CustodyDeposit",CustodyWithdraw:"CustodyWithdraw",CustodyOpenPosition:"CustodyOpenPosition",CustodyClosePosition:"CustodyClosePosition",CustodyIncreasePosition:"CustodyIncreasePosition",CustodyDecreasePosition:"CustodyDecreasePosition",CustodySwapBaseIn:"CustodySwapBaseIn",CustodySwapBaseOut:"CustodySwapBaseOut",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",TransferTip:"TransferTip"};var vn=require("@solana/spl-token"),In=Z("Raydium_txUtil"),Dn=1644;function at(t){let e=[],n=[];return t.microLamports&&(e.push($.ComputeBudgetProgram.setComputeUnitPrice({microLamports:t.microLamports})),n.push(J.SetComputeUnitPrice)),t.units&&(e.push($.ComputeBudgetProgram.setComputeUnitLimit({units:t.units})),n.push(J.SetComputeUnitLimit)),{instructions:e,instructionTypes:n}}async function ke(t,e){var r,i;let n=e!=null?e:"confirmed";return(i=await((r=t.getLatestBlockhash)==null?void 0:r.call(t,{commitment:n})))==null?void 0:i.blockhash}async function ct(t,e){return t.getSignatureStatuses([e]),new Promise((n,r)=>{let i=setTimeout(r,6e4);t.onSignature(e,o=>{if(clearTimeout(i),!o.err){n("");return}r(Object.assign(o.err,{txId:e}))},"confirmed")})}function ti(t,e){t.length<1&&In.logWithError(`no instructions provided: ${t.toString()}`),e.length<1&&In.logWithError(`no signers provided:, ${e.toString()}`);let n=new $.Transaction;n.recentBlockhash="11111111111111111111111111111111",n.feePayer=e[0],n.add(...t);try{return Buffer.from(n.serialize({verifySignatures:!1})).toString("base64").length<Dn}catch{return!1}}function We({instructions:t,payer:e,signers:n}){return ti(t,[e,...n])}function Ue({instructions:t,payer:e,lookupTableAddressAccount:n,recentBlockhash:r=$.Keypair.generate().publicKey.toString()}){let o=new $.TransactionMessage({payerKey:e,recentBlockhash:r,instructions:t}).compileToV0Message(Object.values(n!=null?n:{}));try{return Buffer.from(new $.VersionedTransaction(o).serialize()).toString("base64").length<Dn}catch{return!1}}var ni=t=>Buffer.isBuffer(t)?t:t instanceof Uint8Array?Buffer.from(t.buffer,t.byteOffset,t.byteLength):Buffer.from(t),ri=t=>{let e=t.serialize({requireAllSignatures:!1,verifySignatures:!1});t instanceof $.VersionedTransaction&&(e=ni(e));try{return e instanceof Buffer?e.toString("base64"):Buffer.from(e).toString("base64")}catch{return e.toString("base64")}};function Ae(t){let e=[];return t.forEach(n=>{n instanceof $.Transaction&&(n.recentBlockhash||(n.recentBlockhash=vn.TOKEN_PROGRAM_ID.toBase58()),n.feePayer||(n.feePayer=$.Keypair.generate().publicKey)),e.push(ri(n))}),console.log("simulate tx string:",e),e}var E=require("@solana/web3.js"),is=new E.PublicKey("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),os=new E.PublicKey("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),ss=new E.PublicKey("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),us=new E.PublicKey("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),as=new E.PublicKey("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),cs=new E.PublicKey("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),ls=new E.PublicKey("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),fs=new E.PublicKey("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),ps=new E.PublicKey("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),ds=new E.PublicKey("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),ms=new E.PublicKey("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),gs=new E.PublicKey("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),hs=new E.PublicKey("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),bs=new E.PublicKey("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),ys=new E.PublicKey("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),ws=new E.PublicKey("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),xs=new E.PublicKey("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),Ts=new E.PublicKey("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),Ps=new E.PublicKey("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),As=new E.PublicKey("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),Ss=new E.PublicKey("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Bs=new E.PublicKey("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),si=new E.PublicKey("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),ui=new E.PublicKey("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),ai=new E.PublicKey("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),Ls=new E.PublicKey("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),ci=new E.PublicKey("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),Cs=new E.PublicKey("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),li=new E.PublicKey("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix");var ks={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:si,CREATE_CPMM_POOL_AUTH:ui,CREATE_CPMM_POOL_FEE_ACC:ai,FEE_DESTINATION_ID:new E.PublicKey("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),LOCK_CPMM_PROGRAM:ci,LCOK_CPMM_AUTH:li};var fi=X(require("bn.js"));var be=require("@solana/web3.js");async function Ot({connection:t,address:e}){let n=await wn(t,[...new Set(e.map(i=>i.toString()))].map(i=>new be.PublicKey(i))),r={};for(let i=0;i<e.length;i++){let o=n[i],s=e[i];if(!o)continue;let u=new be.AddressLookupTableAccount({key:s,state:be.AddressLookupTableAccount.deserialize(o.data)});r[s.toString()]=u,lt[s.toString()]=u}return r}var lt={"2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17":new be.AddressLookupTableAccount({key:new be.PublicKey("2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17"),state:be.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 F=require("@solana/web3.js"),_n=X(require("axios"));var ft=2e3,pt=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.loopMultiTxStatus=!!e.loopMultiTxStatus}get AllTxData(){return{instructions:this.instructions,endInstructions:this.endInstructions,signers:this.signers,instructionTypes:this.instructionTypes,endInstructionTypes:this.endInstructionTypes,lookupTableAddress:this.lookupTableAddress}}get allInstructions(){return[...this.instructions,...this.endInstructions]}async getComputeBudgetConfig(){var r;let e=(await _n.default.get(`https://solanacompass.com/api/fees?cacheFreshTime=${3e5}`)).data,{avg:n}=(r=e==null?void 0:e[15])!=null?r:{};if(!!n)return{units:6e5,microLamports:Math.min(Math.ceil(n*1e6/6e5),25e3)}}addCustomComputeBudget(e){if(e){let{instructions:n,instructionTypes:r}=at(e);return this.instructions.unshift(...n),this.instructionTypes.unshift(...r),!0}return!1}addTipInstruction(e){var n;return e?(this.endInstructions.push(F.SystemProgram.transfer({fromPubkey:(n=e.feePayer)!=null?n:this.feePayer,toPubkey:new F.PublicKey(e.address),lamports:BigInt(e.amount.toString())})),this.endInstructionTypes.push(J.TransferTip),!0):!1}async calComputeBudget({config:e,defaultIns:n}){try{let r=e||await this.getComputeBudgetConfig();if(this.addCustomComputeBudget(r))return;n&&this.instructions.unshift(...n)}catch{n&&this.instructions.unshift(...n)}}addInstruction({instructions:e=[],endInstructions:n=[],signers:r=[],instructionTypes:i=[],endInstructionTypes:o=[],lookupTableAddress:s=[]}){return this.instructions.push(...e),this.endInstructions.push(...n),this.signers.push(...r),this.instructionTypes.push(...i),this.endInstructionTypes.push(...o),this.lookupTableAddress.push(...s.filter(u=>u!==F.PublicKey.default.toString())),this}async versionBuild({txVersion:e,extInfo:n}){return e===0?await this.buildV0(z({},n||{})):this.build(n)}build(e){var r;let n=new F.Transaction;return this.allInstructions.length&&n.add(...this.allInstructions),n.feePayer=this.feePayer,((r=this.owner)==null?void 0:r.signer)&&!this.signers.some(i=>i.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 i=>{var a;let{recentBlockHash:o,skipPreflight:s=!0,sendAndConfirm:u}=i||{},c=o!=null?o:await ke(this.connection,this.blockhashCommitment);if(n.recentBlockhash=c,this.signers.length&&n.sign(...this.signers),Ae([n]),(a=this.owner)!=null&&a.isKeyPair)return{txId:u?await(0,F.sendAndConfirmTransaction)(this.connection,n,this.signers.find(f=>f.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]);if(this.signers.length)for(let f of l)try{f.sign(...this.signers)}catch{}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 a;let{extraPreBuildData:n=[],extInfo:r}=e,{transaction:i}=this.build(r),o=n.filter(l=>l.transaction.instructions.length>0),s=[i,...o.map(l=>l.transaction)],u=[this.signers,...o.map(l=>l.signers)],c=[...this.instructionTypes,...o.map(l=>l.instructionTypes).flat()];return(a=this.owner)!=null&&a.signer&&u.forEach(l=>{l.some(f=>f.publicKey.equals(this.owner.publicKey))||this.signers.push(this.owner.signer)}),{builder:this,transactions:s,signers:u,instructionTypes:c,execute:async l=>{var T;let{sequentially:f,onTxUpdate:p,skipTxCount:m=0,recentBlockHash:b,skipPreflight:g=!0}=l||{},h=b!=null?b:await ke(this.connection,this.blockhashCommitment);if((T=this.owner)!=null&&T.isKeyPair){if(f){let A=[],x=0;for(let y of s){if(++x,x<=m)continue;let P=await(0,F.sendAndConfirmTransaction)(this.connection,y,this.signers.find(w=>w.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:g});A.push(P)}return{txIds:A,signedTxs:s}}return{txIds:await await Promise.all(s.map(async A=>(A.recentBlockhash=h,await this.connection.sendRawTransaction(A.serialize(),{skipPreflight:g})))),signedTxs:s}}if(this.signAllTransactions){let A=s.map((y,P)=>(y.recentBlockhash=h,u[P].length&&y.sign(...u[P]),y));Ae(A);let x=await this.signAllTransactions(A);if(f){let y=0,P=[],w=async()=>{if(!x[y])return;let N=await this.connection.sendRawTransaction(x[y].serialize(),{skipPreflight:g});P.push({txId:N,status:"sent",signedTx:x[y]}),p==null||p([...P]),y++;let C=!1,I=null,O=null,D=v=>{I!==null&&clearInterval(I),O!==null&&this.connection.removeSignatureListener(O);let _=P.findIndex(q=>q.txId===N);if(_>-1){if(P[_].status==="error"||P[_].status==="success")return;P[_].status=v.err?"error":"success"}p==null||p([...P]),v.err||w()};this.loopMultiTxStatus&&(I=setInterval(async()=>{var v;if(C){clearInterval(I);return}try{let _=await this.connection.getTransaction(N,{commitment:"confirmed",maxSupportedTransactionVersion:0});_&&(C=!0,clearInterval(I),D({err:((v=_.meta)==null?void 0:v.err)||null}),console.log("tx status from getTransaction:",N))}catch(_){C=!0,clearInterval(I),console.error("getTransaction timeout:",_,N)}},ft)),O=this.connection.onSignature(N,v=>{if(C){this.connection.removeSignatureListener(O);return}C=!0,D(v)},"confirmed"),this.connection.getSignatureStatus(N)};return await w(),{txIds:P.map(N=>N.txId),signedTxs:x}}else{let y=[];for(let P=0;P<x.length;P+=1){let w=await this.connection.sendRawTransaction(x[P].serialize(),{skipPreflight:g});y.push(w)}return{txIds:y,signedTxs:x}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async versionMultiBuild({extraPreBuildData:e,txVersion:n,extInfo:r}){return n===0?await this.buildV0MultiTx({extraPreBuildData:e,buildProps:r||{}}):this.buildMultiTx({extraPreBuildData:e,extInfo:r})}async buildV0(e){var g;let b=e||{},{lookupTableCache:n={},lookupTableAddress:r=[],forerunCreate:i,recentBlockhash:o}=b,s=je(b,["lookupTableCache","lookupTableAddress","forerunCreate","recentBlockhash"]),u=z(z({},this.cluster==="devnet"?{}:lt),n),c=Array.from(new Set([...r,...this.lookupTableAddress])),a=[];for(let h of c)u[h]===void 0&&a.push(new F.PublicKey(h));let l=await Ot({connection:this.connection,address:a});for(let[h,T]of Object.entries(l))u[h]=T;let f=i?F.PublicKey.default.toBase58():o!=null?o:await ke(this.connection,this.blockhashCommitment),p=new F.TransactionMessage({payerKey:this.feePayer,recentBlockhash:f,instructions:[...this.allInstructions]}).compileToV0Message(Object.values(u));((g=this.owner)==null?void 0:g.signer)&&!this.signers.some(h=>h.publicKey.equals(this.owner.publicKey))&&this.signers.push(this.owner.signer);let m=new F.VersionedTransaction(p);return m.sign(this.signers),{builder:this,transaction:m,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async h=>{var x;let{skipPreflight:T=!0,sendAndConfirm:A}=h||{};if(Ae([m]),(x=this.owner)!=null&&x.isKeyPair){let y=await this.connection.sendTransaction(m,{skipPreflight:T});return A&&await ct(this.connection,y),{txId:y,signedTx:m}}if(this.signAllTransactions){let y=await this.signAllTransactions([m]);if(this.signers.length)for(let P of y)try{P.sign(this.signers)}catch{}return{txId:await this.connection.sendTransaction(y[0],{skipPreflight:T}),signedTx:y[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:s||{}}}async buildV0MultiTx(e){var a;let{extraPreBuildData:n=[],buildProps:r}=e,{transaction:i}=await this.buildV0(r),o=n.filter(l=>l.builder.instructions.length>0),s=[i,...o.map(l=>l.transaction)],u=[this.signers,...o.map(l=>l.signers)],c=[...this.instructionTypes,...o.map(l=>l.instructionTypes).flat()];return(a=this.owner)!=null&&a.signer&&u.forEach(l=>{l.some(f=>f.publicKey.equals(this.owner.publicKey))||this.signers.push(this.owner.signer)}),s.forEach(async(l,f)=>{l.sign(u[f])}),{builder:this,transactions:s,signers:u,instructionTypes:c,buildProps:r,execute:async l=>{var g;let{sequentially:f,onTxUpdate:p,recentBlockHash:m,skipPreflight:b=!0}=l||{};if(m&&s.forEach(h=>h.message.recentBlockhash=m),Ae(s),(g=this.owner)!=null&&g.isKeyPair){if(f){let h=[];for(let T of s){let A=await this.connection.sendTransaction(T,{skipPreflight:b});await ct(this.connection,A),h.push(A)}return{txIds:h,signedTxs:s}}return{txIds:await Promise.all(s.map(async h=>await this.connection.sendTransaction(h,{skipPreflight:b}))),signedTxs:s}}if(this.signAllTransactions){let h=await this.signAllTransactions(s);if(f){let T=0,A=[],x=async()=>{if(!h[T])return;let y=await this.connection.sendTransaction(h[T],{skipPreflight:b});A.push({txId:y,status:"sent",signedTx:h[T]}),p==null||p([...A]),T++;let P=!1,w=null,N=null,C=I=>{w!==null&&clearInterval(w),N!==null&&this.connection.removeSignatureListener(N);let O=A.findIndex(D=>D.txId===y);if(O>-1){if(A[O].status==="error"||A[O].status==="success")return;A[O].status=I.err?"error":"success"}p==null||p([...A]),I.err||x()};this.loopMultiTxStatus&&(w=setInterval(async()=>{var I;if(P){clearInterval(w);return}try{let O=await this.connection.getTransaction(y,{commitment:"confirmed",maxSupportedTransactionVersion:0});O&&(P=!0,clearInterval(w),C({err:((I=O.meta)==null?void 0:I.err)||null}),console.log("tx status from getTransaction:",y))}catch(O){P=!0,clearInterval(w),console.error("getTransaction timeout:",O,y)}},ft)),N=this.connection.onSignature(y,I=>{if(P){this.connection.removeSignatureListener(N);return}P=!0,C(I)},"confirmed"),this.connection.getSignatureStatus(y)};return x(),{txIds:[],signedTxs:h}}else{let T=[];for(let A=0;A<h.length;A+=1){let x=await this.connection.sendTransaction(h[A],{skipPreflight:b});T.push(x)}return{txIds:T,signedTxs:h}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async sizeCheckBuild(e){var p;let f=e||{},{splitIns:n=[],computeBudgetConfig:r}=f,i=je(f,["splitIns","computeBudgetConfig"]),o=r?at(r):{instructions:[],instructionTypes:[]},s=this.signers.reduce((m,b)=>pe(z({},m),{[b.publicKey.toBase58()]:b}),{}),u=[],c=[],a=[],l=0;if(this.allInstructions.forEach(m=>{let b=[...a,m],g=r?[...o.instructions,...b]:b,T=[...new Set(b.map(A=>A.keys.filter(x=>x.isSigner).map(x=>x.pubkey.toString())).flat()).values()].map(A=>new F.PublicKey(A));if(m!==n[l]&&a.length<12&&(We({instructions:g,payer:this.feePayer,signers:T})||We({instructions:b,payer:this.feePayer,signers:T})))a.push(m);else{if(a.length===0)throw Error("item ins too big");l+=m===n[l]?1:0,We({instructions:r?[...o.instructions,...a]:[...a],payer:this.feePayer,signers:T})?u.push(new F.Transaction().add(...o.instructions,...a)):u.push(new F.Transaction().add(...a)),c.push(Array.from(new Set(a.map(A=>A.keys.filter(x=>x.isSigner).map(x=>x.pubkey.toString())).flat())).map(A=>s[A]).filter(A=>A!==void 0)),a=[m]}}),a.length>0){let b=[...new Set(a.map(g=>g.keys.filter(h=>h.isSigner).map(h=>h.pubkey.toString())).flat()).values()].map(g=>s[g]).filter(g=>g!==void 0);We({instructions:r?[...o.instructions,...a]:[...a],payer:this.feePayer,signers:b.map(g=>g.publicKey)})?u.push(new F.Transaction().add(...o.instructions,...a)):u.push(new F.Transaction().add(...a)),c.push(b)}return u.forEach(m=>m.feePayer=this.feePayer),(p=this.owner)!=null&&p.signer&&c.forEach(m=>{m.some(b=>b.publicKey.equals(this.owner.publicKey))||m.push(this.owner.signer)}),{builder:this,transactions:u,signers:c,instructionTypes:this.instructionTypes,execute:async m=>{var y;let{sequentially:b,onTxUpdate:g,skipTxCount:h=0,recentBlockHash:T,skipPreflight:A=!0}=m||{},x=T!=null?T:await ke(this.connection,this.blockhashCommitment);if(u.forEach(async(P,w)=>{P.recentBlockhash=x,c[w].length&&P.sign(...c[w])}),Ae(u),(y=this.owner)!=null&&y.isKeyPair){if(b){let P=0,w=[];for(let N of u){if(++P,P<=h){w.push("tx skipped");continue}let C=await(0,F.sendAndConfirmTransaction)(this.connection,N,this.signers.find(I=>I.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:A});w.push(C)}return{txIds:w,signedTxs:u}}return{txIds:await Promise.all(u.map(async P=>await this.connection.sendRawTransaction(P.serialize(),{skipPreflight:A}))),signedTxs:u}}if(this.signAllTransactions){let P=await this.signAllTransactions(u.slice(h,u.length)),w=[...u.slice(0,h),...P];if(b){let N=0,C=[],I=async()=>{if(!w[N])return;N<h&&(C.push({txId:"",status:"success",signedTx:w[N]}),g==null||g([...C]),N++,I());let O=await this.connection.sendRawTransaction(w[N].serialize(),{skipPreflight:A});C.push({txId:O,status:"sent",signedTx:w[N]}),g==null||g([...C]),N++;let D=!1,v=null,_=null,q=K=>{v!==null&&clearInterval(v),_!==null&&this.connection.removeSignatureListener(_);let k=C.findIndex(j=>j.txId===O);if(k>-1){if(C[k].status==="error"||C[k].status==="success")return;C[k].status=K.err?"error":"success"}g==null||g([...C]),K.err||I()};this.loopMultiTxStatus&&(v=setInterval(async()=>{var K;if(D){clearInterval(v);return}try{let k=await this.connection.getTransaction(O,{commitment:"confirmed",maxSupportedTransactionVersion:0});k&&(D=!0,clearInterval(v),q({err:((K=k.meta)==null?void 0:K.err)||null}),console.log("tx status from getTransaction:",O))}catch(k){D=!0,clearInterval(v),console.error("getTransaction timeout:",k,O)}},ft)),_=this.connection.onSignature(O,K=>{if(D){this.connection.removeSignatureListener(_);return}D=!0,q(K)},"confirmed"),this.connection.getSignatureStatus(O)};return await I(),{txIds:C.map(O=>O.txId),signedTxs:w}}else{let N=[];for(let C=0;C<w.length;C+=1){let I=await this.connection.sendRawTransaction(w[C].serialize(),{skipPreflight:A});N.push(I)}return{txIds:N,signedTxs:w}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}async sizeCheckBuildV0(e){var x;let A=e||{},{computeBudgetConfig:n,splitIns:r=[],lookupTableCache:i={},lookupTableAddress:o=[]}=A,s=je(A,["computeBudgetConfig","splitIns","lookupTableCache","lookupTableAddress"]),u=z(z({},this.cluster==="devnet"?{}:lt),i),c=Array.from(new Set([...this.lookupTableAddress,...o])),a=[];for(let y of c)u[y]===void 0&&a.push(new F.PublicKey(y));let l=await Ot({connection:this.connection,address:a});for(let[y,P]of Object.entries(l))u[y]=P;let f=n?at(n):{instructions:[],instructionTypes:[]},p=await ke(this.connection,this.blockhashCommitment),m=this.signers.reduce((y,P)=>pe(z({},y),{[P.publicKey.toBase58()]:P}),{}),b=[],g=[],h=[],T=0;if(this.allInstructions.forEach(y=>{let P=[...h,y],w=n?[...f.instructions,...P]:P;if(y!==r[T]&&h.length<12&&(Ue({instructions:w,payer:this.feePayer,lookupTableAddressAccount:u})||Ue({instructions:P,payer:this.feePayer,lookupTableAddressAccount:u})))h.push(y);else{if(h.length===0)throw Error("item ins too big");T+=y===r[T]?1:0;let N={};for(let C of[...new Set(c)])u[C]!==void 0&&(N[C]=u[C]);if(n&&Ue({instructions:[...f.instructions,...h],payer:this.feePayer,lookupTableAddressAccount:u,recentBlockhash:p})){let C=new F.TransactionMessage({payerKey:this.feePayer,recentBlockhash:p,instructions:[...f.instructions,...h]}).compileToV0Message(Object.values(u));b.push(new F.VersionedTransaction(C))}else{let C=new F.TransactionMessage({payerKey:this.feePayer,recentBlockhash:p,instructions:[...h]}).compileToV0Message(Object.values(u));b.push(new F.VersionedTransaction(C))}g.push(Array.from(new Set(h.map(C=>C.keys.filter(I=>I.isSigner).map(I=>I.pubkey.toString())).flat())).map(C=>m[C]).filter(C=>C!==void 0)),h=[y]}}),h.length>0){let P=[...new Set(h.map(w=>w.keys.filter(N=>N.isSigner).map(N=>N.pubkey.toString())).flat()).values()].map(w=>m[w]).filter(w=>w!==void 0);if(n&&Ue({instructions:[...f.instructions,...h],payer:this.feePayer,lookupTableAddressAccount:u,recentBlockhash:p})){let w=new F.TransactionMessage({payerKey:this.feePayer,recentBlockhash:p,instructions:[...f.instructions,...h]}).compileToV0Message(Object.values(u));b.push(new F.VersionedTransaction(w))}else{let w=new F.TransactionMessage({payerKey:this.feePayer,recentBlockhash:p,instructions:[...h]}).compileToV0Message(Object.values(u));b.push(new F.VersionedTransaction(w))}g.push(P)}return(x=this.owner)!=null&&x.signer&&g.forEach(y=>{y.some(P=>P.publicKey.equals(this.owner.publicKey))||y.push(this.owner.signer)}),{builder:this,transactions:b,buildProps:e,signers:g,instructionTypes:this.instructionTypes,execute:async y=>{var O;let{sequentially:P,onTxUpdate:w,skipTxCount:N=0,recentBlockHash:C,skipPreflight:I=!0}=y||{};if(b.map(async(D,v)=>{g[v].length&&D.sign(g[v]),C&&(D.message.recentBlockhash=C)}),Ae(b),(O=this.owner)!=null&&O.isKeyPair){if(P){let D=0,v=[];for(let _ of b){if(++D,D<=N){console.log("skip tx: ",D),v.push("tx skipped");continue}let q=await this.connection.sendTransaction(_,{skipPreflight:I});await ct(this.connection,q),v.push(q)}return{txIds:v,signedTxs:b}}return{txIds:await Promise.all(b.map(async D=>await this.connection.sendTransaction(D,{skipPreflight:I}))),signedTxs:b}}if(this.signAllTransactions){let D=await this.signAllTransactions(b.slice(N,b.length)),v=[...b.slice(0,N),...D];if(P){let _=0,q=[],K=async()=>{if(!v[_])return;if(_<N){q.push({txId:"",status:"success",signedTx:v[_]}),w==null||w([...q]),_++,K();return}let k=await this.connection.sendTransaction(v[_],{skipPreflight:I});q.push({txId:k,status:"sent",signedTx:v[_]}),w==null||w([...q]),_++;let j=!1,fe=null,ze=null,Xt=Te=>{fe!==null&&clearInterval(fe),ze!==null&&this.connection.removeSignatureListener(ze);let ae=q.findIndex(jn=>jn.txId===k);if(ae>-1){if(q[ae].status==="error"||q[ae].status==="success")return;q[ae].status=Te.err?"error":"success"}w==null||w([...q]),Te.err||K()};this.loopMultiTxStatus&&(fe=setInterval(async()=>{var Te;if(j){clearInterval(fe);return}try{let ae=await this.connection.getTransaction(k,{commitment:"confirmed",maxSupportedTransactionVersion:0});ae&&(j=!0,clearInterval(fe),Xt({err:((Te=ae.meta)==null?void 0:Te.err)||null}),console.log("tx status from getTransaction:",k))}catch(ae){j=!0,clearInterval(fe),console.error("getTransaction timeout:",ae,k)}},ft)),ze=this.connection.onSignature(k,Te=>{if(j){this.connection.removeSignatureListener(ze);return}j=!0,Xt(Te)},"confirmed"),this.connection.getSignatureStatus(k)};return K(),{txIds:[],signedTxs:v}}else{let _=[];for(let q=0;q<v.length;q+=1){let K=await this.connection.sendTransaction(v[q],{skipPreflight:I});_.push(K)}return{txIds:_,signedTxs:v}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:s||{}}}};var di=require("@solana/web3.js"),mi=X(require("bn.js"));var wu=Z("Raydium_amount"),xu=Fe(Kn.default);var ut=new ue.default(0),_u=new ue.default(1),Ku=new ue.default(2),Ou=new ue.default(3),Fu=new ue.default(5),hi=new ue.default(10),Vu=new ue.default(100),qu=new ue.default(1e3),Wu=new ue.default(1e4);var xt=require("@solana/web3.js"),Pi=X(require("bn.js"));var zn=require("@solana/spl-token");function bi(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Ft(t,...e){if(!bi(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function Vt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function On(t,e){Ft(t);let n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}var mt=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),oe=(t,e)=>t<<32-e|t>>>e;var zu=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function yi(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function qt(t){return typeof t=="string"&&(t=yi(t)),Ft(t),t}var dt=class{clone(){return this._cloneInto()}},Qu={}.toString;function Fn(t){let e=r=>t().update(qt(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function wi(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);let i=BigInt(32),o=BigInt(4294967295),s=Number(n>>i&o),u=Number(n&o),c=r?4:0,a=r?0:4;t.setUint32(e+c,s,r),t.setUint32(e+a,u,r)}var Vn=(t,e,n)=>t&e^~t&n,qn=(t,e,n)=>t&e^t&n^e&n,gt=class extends dt{constructor(e,n,r,i){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=mt(this.buffer)}update(e){Vt(this);let{view:n,buffer:r,blockLen:i}=this;e=qt(e);let o=e.length;for(let s=0;s<o;){let u=Math.min(i-this.pos,o-s);if(u===i){let c=mt(e);for(;i<=o-s;s+=i)this.process(c,s);continue}r.set(e.subarray(s,s+u),this.pos),this.pos+=u,s+=u,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Vt(this),On(e,this),this.finished=!0;let{buffer:n,view:r,blockLen:i,isLE:o}=this,{pos:s}=this;n[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(r,0),s=0);for(let f=s;f<i;f++)n[f]=0;wi(r,i-8,BigInt(this.length*8),o),this.process(r,0);let u=mt(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let a=c/4,l=this.get();if(a>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<a;f++)u.setUint32(4*f,l[f],o)}digest(){let{buffer:e,outputLen:n}=this;this.digestInto(e);let r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:n,buffer:r,length:i,finished:o,destroyed:s,pos:u}=this;return e.length=i,e.pos=u,e.finished=o,e.destroyed=s,i%n&&e.buffer.set(r),e}};var xi=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ye=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),we=new Uint32Array(64),Wt=class extends gt{constructor(){super(64,32,8,!1),this.A=ye[0]|0,this.B=ye[1]|0,this.C=ye[2]|0,this.D=ye[3]|0,this.E=ye[4]|0,this.F=ye[5]|0,this.G=ye[6]|0,this.H=ye[7]|0}get(){let{A:e,B:n,C:r,D:i,E:o,F:s,G:u,H:c}=this;return[e,n,r,i,o,s,u,c]}set(e,n,r,i,o,s,u,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=u|0,this.H=c|0}process(e,n){for(let f=0;f<16;f++,n+=4)we[f]=e.getUint32(n,!1);for(let f=16;f<64;f++){let p=we[f-15],m=we[f-2],b=oe(p,7)^oe(p,18)^p>>>3,g=oe(m,17)^oe(m,19)^m>>>10;we[f]=g+we[f-7]+b+we[f-16]|0}let{A:r,B:i,C:o,D:s,E:u,F:c,G:a,H:l}=this;for(let f=0;f<64;f++){let p=oe(u,6)^oe(u,11)^oe(u,25),m=l+p+Vn(u,c,a)+xi[f]+we[f]|0,g=(oe(r,2)^oe(r,13)^oe(r,22))+qn(r,i,o)|0;l=a,a=c,c=u,u=s+m|0,s=o,o=i,i=r,r=m+g|0}r=r+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,u=u+this.E|0,c=c+this.F|0,a=a+this.G|0,l=l+this.H|0,this.set(r,i,o,s,u,c,a,l)}roundClean(){we.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Wn=Fn(()=>new Wt);var Hn=require("@solana/web3.js"),bt=X(require("bn.js"));var B=require("@solana/buffer-layout"),ht=B.Layout,Un=B.Structure;var Ut=B.UInt;var Gn=B.u16;var Gt=B.u32;var Ne=B.blob;var Ht=B.bits;var zt=class extends ht{constructor(n,r,i){super(n,i);this.blob=Ne(n),this.signed=r}decode(n,r=0){let i=new bt.default(this.blob.decode(n,r),10,"le");return this.signed?i.fromTwos(this.span*8).clone():i}encode(n,r,i=0){return typeof n=="number"&&(n=new bt.default(n)),this.signed&&(n=n.toTwos(this.span*8)),this.blob.encode(n.toArrayLike(Buffer,"le",this.span),r,i)}},yt=class extends ht{constructor(n){super(8,n);this._lower=Ht(Gt(),!1),this._upper=Ht(Gt(),!1)}addBoolean(n){this._lower.fields.length<32?this._lower.addBoolean(n):this._upper.addBoolean(n)}decode(n,r=0){let i=this._lower.decode(n,r),o=this._upper.decode(n,r+this._lower.span);return z(z({},i),o)}encode(n,r,i=0){return this._lower.encode(n,r,i)+this._upper.encode(n,r,i+this._lower.span)}};function wt(t){return new Ut(1,t)}function Me(t){return new Ut(4,t)}function G(t){return new zt(8,!1,t)}var Qt=class extends ht{constructor(n,r,i,o){super(n.span,o);this.layout=n,this.decoder=r,this.encoder=i}decode(n,r){return this.decoder(this.layout.decode(n,r))}encode(n,r,i){return this.layout.encode(this.encoder(n),r,i)}getSpan(n,r){return this.layout.getSpan(n,r)}};function ee(t){return new Qt(Ne(32),e=>new Hn.PublicKey(e),e=>e.toBuffer(),t)}var jt=class extends Un{decode(e,n){return super.decode(e,n)}};function Ee(t,e,n){return new jt(t,e,n)}var Ti=Ee([ee("mint"),ee("owner"),G("amount"),Me("delegateOption"),ee("delegate"),wt("state"),Me("isNativeOption"),G("isNative"),G("delegatedAmount"),Me("closeAuthorityOption"),ee("closeAuthority")]);var xa=Z("Raydium_Util");function xe({fromPublicKey:t,programId:e=zn.TOKEN_PROGRAM_ID,assignSeed:n}){let r=n?btoa(n).slice(0,32):xt.Keypair.generate().publicKey.toBase58().slice(0,32);return{publicKey:Ai(t,r,e),seed:r}}function Ai(t,e,n){let r=Buffer.concat([t.toBuffer(),Buffer.from(e),n.toBuffer()]),i=Wn(r);return new xt.PublicKey(i)}var Yt=(...t)=>t.map(e=>{try{return typeof e=="object"?JSON.stringify(e):e}catch{return e}}).join(", "),Ge=class{constructor({scope:e,moduleName:n}){this.disabled=!1;this.scope=e,this.logger=Z(n)}createTxBuilder(e){return this.scope.checkOwner(),new pt({connection:this.scope.connection,feePayer:e||this.scope.ownerPubKey,cluster:this.scope.cluster,owner:this.scope.owner,blockhashCommitment:this.scope.blockhashCommitment,loopMultiTxStatus:this.scope.loopMultiTxStatus,api:this.scope.api,signAllTransactions:this.scope.signAllTransactions})}logDebug(...e){this.logger.debug(Yt(e))}logInfo(...e){this.logger.info(Yt(e))}logAndCreateError(...e){let n=Yt(e);throw new Error(n)}checkDisabled(){(this.disabled||!this.scope)&&this.logAndCreateError("module not working")}};var te=require("@solana/web3.js"),Re=require("@solana/spl-token");function Si(t="accountFlags"){let e=new yt(t);return e.addBoolean("initialized"),e.addBoolean("market"),e.addBoolean("openOrders"),e.addBoolean("requestQueue"),e.addBoolean("eventQueue"),e.addBoolean("bids"),e.addBoolean("asks"),e}var Tt=Ee([Ne(5),Si("accountFlags"),ee("ownAddress"),G("vaultSignerNonce"),ee("baseMint"),ee("quoteMint"),ee("baseVault"),G("baseDepositsTotal"),G("baseFeesAccrued"),ee("quoteVault"),G("quoteDepositsTotal"),G("quoteFeesAccrued"),G("quoteDustThreshold"),ee("requestQueue"),ee("eventQueue"),ee("bids"),ee("asks"),G("baseLotSize"),G("quoteLotSize"),G("feeRateBps"),G("referrerRebatesAccrued"),Ne(7)]);function Qn({programId:t,marketInfo:e}){let n=Ee([wt("version"),Me("instruction"),G("baseLotSize"),G("quoteLotSize"),Gn("feeRateBps"),G("vaultSignerNonce"),G("quoteDustThreshold")]),r=[{pubkey:e.id,isSigner:!1,isWritable:!0},{pubkey:e.requestQueue,isSigner:!1,isWritable:!0},{pubkey:e.eventQueue,isSigner:!1,isWritable:!0},{pubkey:e.bids,isSigner:!1,isWritable:!0},{pubkey:e.asks,isSigner:!1,isWritable:!0},{pubkey:e.baseVault,isSigner:!1,isWritable:!0},{pubkey:e.quoteVault,isSigner:!1,isWritable:!0},{pubkey:e.baseMint,isSigner:!1,isWritable:!1},{pubkey:e.quoteMint,isSigner:!1,isWritable:!1},{pubkey:e.authority?e.quoteMint:te.SYSVAR_RENT_PUBKEY,isSigner:!1,isWritable:!1}].concat(e.authority?{pubkey:e.authority,isSigner:!1,isWritable:!1}:[]).concat(e.authority&&e.pruneAuthority?{pubkey:e.pruneAuthority,isSigner:!1,isWritable:!1}:[]),i=Buffer.alloc(n.span);return n.encode({version:0,instruction:0,baseLotSize:e.baseLotSize,quoteLotSize:e.quoteLotSize,feeRateBps:e.feeRateBps,vaultSignerNonce:e.vaultSignerNonce,quoteDustThreshold:e.quoteDustThreshold},i),new te.TransactionInstruction({keys:r,programId:t,data:i})}async function Zt({connection:t,wallet:e,marketInfo:n}){var s,u,c,a,l,f,p,m;let r=new te.Transaction,i=await t.getMinimumBalanceForRentExemption(165);r.add(te.SystemProgram.createAccountWithSeed({fromPubkey:e,basePubkey:e,seed:n.baseVault.seed,newAccountPubkey:n.baseVault.publicKey,lamports:i,space:165,programId:Re.TOKEN_PROGRAM_ID}),te.SystemProgram.createAccountWithSeed({fromPubkey:e,basePubkey:e,seed:n.quoteVault.seed,newAccountPubkey:n.quoteVault.publicKey,lamports:i,space:165,programId:Re.TOKEN_PROGRAM_ID}),(0,Re.createInitializeAccountInstruction)(n.baseVault.publicKey,n.baseMint,n.vaultOwner),(0,Re.createInitializeAccountInstruction)(n.quoteVault.publicKey,n.quoteMint,n.vaultOwner),te.SystemProgram.createAccountWithSeed({fromPubkey:e,basePubkey:e,seed:n.id.seed,newAccountPubkey:n.id.publicKey,lamports:await t.getMinimumBalanceForRentExemption(Tt.span),space:Tt.span,programId:n.programId}));let o=new te.Transaction;return o.add(te.SystemProgram.createAccountWithSeed({fromPubkey:e,basePubkey:e,seed:n.requestQueue.seed,newAccountPubkey:n.requestQueue.publicKey,lamports:n.lowestFeeMarket?6208320:await t.getMinimumBalanceForRentExemption((s=n.requestQueueSpace)!=null?s:5120+12),space:n.lowestFeeMarket?764:(u=n.requestQueueSpace)!=null?u:5120+12,programId:n.programId}),te.SystemProgram.createAccountWithSeed({fromPubkey:e,basePubkey:e,seed:n.eventQueue.seed,newAccountPubkey:n.eventQueue.publicKey,lamports:n.lowestFeeMarket?79594560:await t.getMinimumBalanceForRentExemption((c=n.eventQueueSpace)!=null?c:262144+12),space:n.lowestFeeMarket?11308:(a=n.eventQueueSpace)!=null?a:262144+12,programId:n.programId}),te.SystemProgram.createAccountWithSeed({fromPubkey:e,basePubkey:e,seed:n.bids.seed,newAccountPubkey:n.bids.publicKey,lamports:n.lowestFeeMarket?101977920:await t.getMinimumBalanceForRentExemption((l=n.orderbookQueueSpace)!=null?l:65536+12),space:n.lowestFeeMarket?14524:(f=n.orderbookQueueSpace)!=null?f:65536+12,programId:n.programId}),te.SystemProgram.createAccountWithSeed({fromPubkey:e,basePubkey:e,seed:n.asks.seed,newAccountPubkey:n.asks.publicKey,lamports:n.lowestFeeMarket?101977920:await t.getMinimumBalanceForRentExemption((p=n.orderbookQueueSpace)!=null?p:65536+12),space:n.lowestFeeMarket?14524:(m=n.orderbookQueueSpace)!=null?m:65536+12,programId:n.programId}),Qn({programId:n.programId,marketInfo:{id:n.id.publicKey,requestQueue:n.requestQueue.publicKey,eventQueue:n.eventQueue.publicKey,bids:n.bids.publicKey,asks:n.asks.publicKey,baseVault:n.baseVault.publicKey,quoteVault:n.quoteVault.publicKey,baseMint:n.baseMint,quoteMint:n.quoteMint,baseLotSize:n.baseLotSize,quoteLotSize:n.quoteLotSize,feeRateBps:n.feeRateBps,vaultSignerNonce:n.vaultSignerNonce,quoteDustThreshold:n.quoteDustThreshold}})),[{transaction:r,signer:[],instructionTypes:[J.CreateAccount,J.CreateAccount,J.InitAccount,J.InitAccount]},{transaction:o,signer:[],instructionTypes:[J.CreateAccount,J.CreateAccount,J.CreateAccount,J.CreateAccount,J.CreateAccount,J.InitMarket]}]}var He=class extends Ge{async create({baseInfo:e,quoteInfo:n,lotSize:r,tickSize:i,dexProgramId:o,requestQueueSpace:s,eventQueueSpace:u,orderbookQueueSpace:c,lowestFeeMarket:a,assignSeed:l,txVersion:f,computeBudgetConfig:p,txTipConfig:m,feePayer:b}){let g=this.scope.ownerPubKey,h=l?`${e.mint.toBase58().slice(0,10)}-${n.mint.toBase58().slice(0,10)}-${l}`:void 0,T=xe({fromPublicKey:g,programId:o,assignSeed:h&&`${h}-market`}),A=xe({fromPublicKey:g,programId:o,assignSeed:h&&`${h}-request`}),x=xe({fromPublicKey:g,programId:o,assignSeed:h&&`${h}-event`}),y=xe({fromPublicKey:g,programId:o,assignSeed:h&&`${h}-bids`}),P=xe({fromPublicKey:g,programId:o,assignSeed:h&&`${h}-asks`}),w=xe({fromPublicKey:g,programId:Jt.TOKEN_PROGRAM_ID,assignSeed:h&&`${h}-baseVault`}),N=xe({fromPublicKey:g,programId:Jt.TOKEN_PROGRAM_ID,assignSeed:h&&`${h}-quoteVault`}),C=0,I=new ve.default(100);function O(){let j=new ve.default(0);for(;;)try{return{vaultOwner:Ie.PublicKey.createProgramAddressSync([T.publicKey.toBuffer(),j.toArrayLike(Buffer,"le",8)],o),vaultSignerNonce:j}}catch{if(j.iaddn(1),j.gt(new ve.default(25555)))throw Error("find vault owner error")}}let{vaultOwner:D,vaultSignerNonce:v}=O(),_=new ve.default(Math.round(10**e.decimals*r)),q=new ve.default(Math.round(r*10**n.decimals*i));if(_.eq(ut))throw Error("lot size is too small");if(q.eq(ut))throw Error("tick size or lot size is too small");let K=await Zt({connection:this.scope.connection,wallet:this.scope.ownerPubKey,marketInfo:{programId:o,id:T,baseMint:e.mint,quoteMint:n.mint,baseVault:w,quoteVault:N,vaultOwner:D,requestQueue:A,eventQueue:x,bids:y,asks:P,feeRateBps:C,quoteDustThreshold:I,vaultSignerNonce:v,baseLotSize:_,quoteLotSize:q,requestQueueSpace:s,eventQueueSpace:u,orderbookQueueSpace:c,lowestFeeMarket:a}}),k=this.createTxBuilder(b);k.addInstruction({instructions:K[0].transaction.instructions,signers:K[0].signer});for await(let j of K.slice(1,K.length))k.addInstruction({instructions:j.transaction.instructions,signers:j.signer,instructionTypes:j.instructionTypes});return f===0?k.sizeCheckBuildV0({computeBudgetConfig:p,address:{marketId:T.publicKey,requestQueue:A.publicKey,eventQueue:x.publicKey,bids:y.publicKey,asks:P.publicKey,baseVault:w.publicKey,quoteVault:N.publicKey,baseMint:new Ie.PublicKey(e.mint),quoteMint:new Ie.PublicKey(n.mint)}}):k.sizeCheckBuild({computeBudgetConfig:p,address:{marketId:T.publicKey,requestQueue:A.publicKey,eventQueue:x.publicKey,bids:y.publicKey,asks:P.publicKey,baseVault:w.publicKey,quoteVault:N.publicKey,baseMint:new Ie.PublicKey(e.mint),quoteMint:new Ie.PublicKey(n.mint)}})}};0&&(module.exports={MARKET_STATE_LAYOUT_V2,initializeMarket,makeCreateMarketInstruction});
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
//# sourceMappingURL=index.js.map