@raydium-io/raydium-sdk-v2
Version:
An SDK for building applications on top of Raydium.
1 lines • 82.5 kB
JavaScript
var Wn=Object.create;var Be=Object.defineProperty,qn=Object.defineProperties,Gn=Object.getOwnPropertyDescriptor,Hn=Object.getOwnPropertyDescriptors,jn=Object.getOwnPropertyNames,Fe=Object.getOwnPropertySymbols,zn=Object.getPrototypeOf,ft=Object.prototype.hasOwnProperty,Ut=Object.prototype.propertyIsEnumerable;var Vt=(e,t,n)=>t in e?Be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))ft.call(t,n)&&Vt(e,n,t[n]);if(Fe)for(var n of Fe(t))Ut.call(t,n)&&Vt(e,n,t[n]);return e},ae=(e,t)=>qn(e,Hn(t));var be=(e,t)=>{var n={};for(var r in e)ft.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Fe)for(var r of Fe(e))t.indexOf(r)<0&&Ut.call(e,r)&&(n[r]=e[r]);return n};var Zn=(e,t)=>{for(var n in t)Be(e,n,{get:t[n],enumerable:!0})},Wt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of jn(t))!ft.call(e,o)&&o!==n&&Be(e,o,{get:()=>t[o],enumerable:!(r=Gn(t,o))||r.enumerable});return e};var J=(e,t,n)=>(n=e!=null?Wn(zn(e)):{},Wt(t||!e||!e.__esModule?Be(n,"default",{value:e,enumerable:!0}):n,e)),Yn=e=>Wt(Be({},"__esModule",{value:!0}),e);var fo={};Zn(fo,{default:()=>lt});module.exports=Yn(fo);var K=require("@solana/spl-token"),we=require("@solana/web3.js");var Se=require("lodash");var pt=class{constructor(t){this.logLevel=t.logLevel!==void 0?t.logLevel:0,this.name=t.name}set level(t){this.logLevel=t}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(t){return t<=this.logLevel}error(...t){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...t),this):this}logWithError(...t){let n=t.map(r=>typeof r=="object"?JSON.stringify(r):r).join(", ");throw new Error(n)}warning(...t){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...t),this):this}info(...t){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...t),this):this}debug(...t){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...t),this):this}},qt={},Jn={};function j(e){let t=(0,Se.get)(qt,e);if(!t){let n=(0,Se.get)(Jn,e);t=new pt({name:e,logLevel:n}),(0,Se.set)(qt,e,t)}return t}var Xr=require("@solana/web3.js"),Qr=J(require("bn.js"));var yn=J(require("big.js")),Jr=J(require("bn.js"));var Y=J(require("bn.js"));var Te=9e15,fe=1e9,mt="0123456789abcdef",Ue="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",We="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",dt={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Te,maxE:Te,crypto:!1},zt,ie,S=!0,Ge="[DecimalError] ",le=Ge+"Invalid argument: ",Zt=Ge+"Precision limit exceeded",Yt=Ge+"crypto unavailable",Jt="[object Decimal]",z=Math.floor,F=Math.pow,Xn=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Qn=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,$n=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Xt=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,te=1e7,A=7,er=9007199254740991,tr=Ue.length-1,ht=We.length-1,d={toStringTag:Jt};d.absoluteValue=d.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),P(e)};d.ceil=function(){return P(new this.constructor(this),this.e+1,2)};d.clampedTo=d.clamp=function(e,t){var n,r=this,o=r.constructor;if(e=new o(e),t=new o(t),!e.s||!t.s)return new o(NaN);if(e.gt(t))throw Error(le+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new o(r)};d.comparedTo=d.cmp=function(e){var t,n,r,o,i=this,s=i.d,a=(e=new i.constructor(e)).d,c=i.s,u=e.s;if(!s||!a)return!c||!u?NaN:c!==u?c:s===a?0:!s^c<0?1:-1;if(!s[0]||!a[0])return s[0]?c:a[0]?-u:0;if(c!==u)return c;if(i.e!==e.e)return i.e>e.e^c<0?1:-1;for(r=s.length,o=a.length,t=0,n=r<o?r:o;t<n;++t)if(s[t]!==a[t])return s[t]>a[t]^c<0?1:-1;return r===o?0:r>o^c<0?1:-1};d.cosine=d.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+A,r.rounding=1,n=nr(r,nn(r,n)),r.precision=e,r.rounding=t,P(ie==2||ie==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)};d.cubeRoot=d.cbrt=function(){var e,t,n,r,o,i,s,a,c,u,l=this,f=l.constructor;if(!l.isFinite()||l.isZero())return new f(l);for(S=!1,i=l.s*F(l.s*l,1/3),!i||Math.abs(i)==1/0?(n=G(l.d),e=l.e,(i=(e-n.length+1)%3)&&(n+=i==1||i==-2?"0":"00"),i=F(n,1/3),e=z((e+1)/3)-(e%3==(e<0?-1:2)),i==1/0?n="5e"+e:(n=i.toExponential(),n=n.slice(0,n.indexOf("e")+1)+e),r=new f(n),r.s=l.s):r=new f(i.toString()),s=(e=f.precision)+3;;)if(a=r,c=a.times(a).times(a),u=c.plus(l),r=R(u.plus(l).times(a),u.plus(c),s+2,1),G(a.d).slice(0,s)===(n=G(r.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!o&&n=="4999"){if(!o&&(P(a,e+1,0),a.times(a).times(a).eq(l))){r=a;break}s+=4,o=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(P(r,e+1,1),t=!r.times(r).times(r).eq(l));break}return S=!0,P(r,e,f.rounding,t)};d.decimalPlaces=d.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-z(this.e/A))*A,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n};d.dividedBy=d.div=function(e){return R(this,new this.constructor(e))};d.dividedToIntegerBy=d.divToInt=function(e){var t=this,n=t.constructor;return P(R(t,new n(e),0,1,1),n.precision,n.rounding)};d.equals=d.eq=function(e){return this.cmp(e)===0};d.floor=function(){return P(new this.constructor(this),this.e+1,3)};d.greaterThan=d.gt=function(e){return this.cmp(e)>0};d.greaterThanOrEqualTo=d.gte=function(e){var t=this.cmp(e);return t==1||t===0};d.hyperbolicCosine=d.cosh=function(){var e,t,n,r,o,i=this,s=i.constructor,a=new s(1);if(!i.isFinite())return new s(i.s?1/0:NaN);if(i.isZero())return a;n=s.precision,r=s.rounding,s.precision=n+Math.max(i.e,i.sd())+4,s.rounding=1,o=i.d.length,o<32?(e=Math.ceil(o/3),t=(1/je(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),i=Pe(s,1,i.times(t),new s(1),!0);for(var c,u=e,l=new s(8);u--;)c=i.times(i),i=a.minus(c.times(l.minus(c.times(l))));return P(i,s.precision=n,s.rounding=r,!0)};d.hyperbolicSine=d.sinh=function(){var e,t,n,r,o=this,i=o.constructor;if(!o.isFinite()||o.isZero())return new i(o);if(t=i.precision,n=i.rounding,i.precision=t+Math.max(o.e,o.sd())+4,i.rounding=1,r=o.d.length,r<3)o=Pe(i,2,o,o,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,o=o.times(1/je(5,e)),o=Pe(i,2,o,o,!0);for(var s,a=new i(5),c=new i(16),u=new i(20);e--;)s=o.times(o),o=o.times(a.plus(s.times(c.times(s).plus(u))))}return i.precision=t,i.rounding=n,P(o,t,n,!0)};d.hyperbolicTangent=d.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,R(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)};d.inverseCosine=d.acos=function(){var e,t=this,n=t.constructor,r=t.abs().cmp(1),o=n.precision,i=n.rounding;return r!==-1?r===0?t.isNeg()?ee(n,o,i):new n(0):new n(NaN):t.isZero()?ee(n,o+4,i).times(.5):(n.precision=o+6,n.rounding=1,t=t.asin(),e=ee(n,o+4,i).times(.5),n.precision=o,n.rounding=i,e.minus(t))};d.inverseHyperbolicCosine=d.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,S=!1,n=n.times(n).minus(1).sqrt().plus(n),S=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)};d.inverseHyperbolicSine=d.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,S=!1,n=n.times(n).plus(1).sqrt().plus(n),S=!0,r.precision=e,r.rounding=t,n.ln())};d.inverseHyperbolicTangent=d.atanh=function(){var e,t,n,r,o=this,i=o.constructor;return o.isFinite()?o.e>=0?new i(o.abs().eq(1)?o.s/0:o.isZero()?o:NaN):(e=i.precision,t=i.rounding,r=o.sd(),Math.max(r,e)<2*-o.e-1?P(new i(o),e,t,!0):(i.precision=n=r-o.e,o=R(o.plus(1),new i(1).minus(o),n+e,1),i.precision=e+4,i.rounding=1,o=o.ln(),i.precision=e,i.rounding=t,o.times(.5))):new i(NaN)};d.inverseSine=d.asin=function(){var e,t,n,r,o=this,i=o.constructor;return o.isZero()?new i(o):(t=o.abs().cmp(1),n=i.precision,r=i.rounding,t!==-1?t===0?(e=ee(i,n+4,r).times(.5),e.s=o.s,e):new i(NaN):(i.precision=n+6,i.rounding=1,o=o.div(new i(1).minus(o.times(o)).sqrt().plus(1)).atan(),i.precision=n,i.rounding=r,o.times(2)))};d.inverseTangent=d.atan=function(){var e,t,n,r,o,i,s,a,c,u=this,l=u.constructor,f=l.precision,p=l.rounding;if(u.isFinite()){if(u.isZero())return new l(u);if(u.abs().eq(1)&&f+4<=ht)return s=ee(l,f+4,p).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(f+4<=ht)return s=ee(l,f+4,p).times(.5),s.s=u.s,s}for(l.precision=a=f+10,l.rounding=1,n=Math.min(28,a/A+2|0),e=n;e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(S=!1,t=Math.ceil(a/A),r=1,c=u.times(u),s=new l(u),o=u;e!==-1;)if(o=o.times(c),i=s.minus(o.div(r+=2)),o=o.times(c),s=i.plus(o.div(r+=2)),s.d[t]!==void 0)for(e=t;s.d[e]===i.d[e]&&e--;);return n&&(s=s.times(2<<n-1)),S=!0,P(s,l.precision=f,l.rounding=p,!0)};d.isFinite=function(){return!!this.d};d.isInteger=d.isInt=function(){return!!this.d&&z(this.e/A)>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(e){return this.cmp(e)<0};d.lessThanOrEqualTo=d.lte=function(e){return this.cmp(e)<1};d.logarithm=d.log=function(e){var t,n,r,o,i,s,a,c,u=this,l=u.constructor,f=l.precision,p=l.rounding,m=5;if(e==null)e=new l(10),t=!0;else{if(e=new l(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new l(NaN);t=e.eq(10)}if(n=u.d,u.s<0||!n||!n[0]||u.eq(1))return new l(n&&!n[0]?-1/0:u.s!=1?NaN:n?0:1/0);if(t)if(n.length>1)i=!0;else{for(o=n[0];o%10===0;)o/=10;i=o!==1}if(S=!1,a=f+m,s=ue(u,a),r=t?qe(l,a+10):ue(e,a),c=R(s,r,a,1),Ce(c.d,o=f,p))do if(a+=10,s=ue(u,a),r=t?qe(l,a+10):ue(e,a),c=R(s,r,a,1),!i){+G(c.d).slice(o+1,o+15)+1==1e14&&(c=P(c,f+1,0));break}while(Ce(c.d,o+=10,p));return S=!0,P(c,f,p)};d.minus=d.sub=function(e){var t,n,r,o,i,s,a,c,u,l,f,p,m=this,w=m.constructor;if(e=new w(e),!m.d||!e.d)return!m.s||!e.s?e=new w(NaN):m.d?e.s=-e.s:e=new w(e.d||m.s!==e.s?m:NaN),e;if(m.s!=e.s)return e.s=-e.s,m.plus(e);if(u=m.d,p=e.d,a=w.precision,c=w.rounding,!u[0]||!p[0]){if(p[0])e.s=-e.s;else if(u[0])e=new w(m);else return new w(c===3?-0:0);return S?P(e,a,c):e}if(n=z(e.e/A),l=z(m.e/A),u=u.slice(),i=l-n,i){for(f=i<0,f?(t=u,i=-i,s=p.length):(t=p,n=l,s=u.length),r=Math.max(Math.ceil(a/A),s)+2,i>r&&(i=r,t.length=1),t.reverse(),r=i;r--;)t.push(0);t.reverse()}else{for(r=u.length,s=p.length,f=r<s,f&&(s=r),r=0;r<s;r++)if(u[r]!=p[r]){f=u[r]<p[r];break}i=0}for(f&&(t=u,u=p,p=t,e.s=-e.s),s=u.length,r=p.length-s;r>0;--r)u[s++]=0;for(r=p.length;r>i;){if(u[--r]<p[r]){for(o=r;o&&u[--o]===0;)u[o]=te-1;--u[o],u[r]+=te}u[r]-=p[r]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--n;return u[0]?(e.d=u,e.e=He(u,n),S?P(e,a,c):e):new w(c===3?-0:0)};d.modulo=d.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?P(new r(n),r.precision,r.rounding):(S=!1,r.modulo==9?(t=R(n,e.abs(),0,3,1),t.s*=e.s):t=R(n,e,0,r.modulo,1),t=t.times(e),S=!0,n.minus(t))};d.naturalExponential=d.exp=function(){return gt(this)};d.naturalLogarithm=d.ln=function(){return ue(this)};d.negated=d.neg=function(){var e=new this.constructor(this);return e.s=-e.s,P(e)};d.plus=d.add=function(e){var t,n,r,o,i,s,a,c,u,l,f=this,p=f.constructor;if(e=new p(e),!f.d||!e.d)return!f.s||!e.s?e=new p(NaN):f.d||(e=new p(e.d||f.s===e.s?f:NaN)),e;if(f.s!=e.s)return e.s=-e.s,f.minus(e);if(u=f.d,l=e.d,a=p.precision,c=p.rounding,!u[0]||!l[0])return l[0]||(e=new p(f)),S?P(e,a,c):e;if(i=z(f.e/A),r=z(e.e/A),u=u.slice(),o=i-r,o){for(o<0?(n=u,o=-o,s=l.length):(n=l,r=i,s=u.length),i=Math.ceil(a/A),s=i>s?i+1:s+1,o>s&&(o=s,n.length=1),n.reverse();o--;)n.push(0);n.reverse()}for(s=u.length,o=l.length,s-o<0&&(o=s,n=l,l=u,u=n),t=0;o;)t=(u[--o]=u[o]+l[o]+t)/te|0,u[o]%=te;for(t&&(u.unshift(t),++r),s=u.length;u[--s]==0;)u.pop();return e.d=u,e.e=He(u,r),S?P(e,a,c):e};d.precision=d.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(le+e);return n.d?(t=Qt(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t};d.round=function(){var e=this,t=e.constructor;return P(new t(e),e.e+1,t.rounding)};d.sine=d.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+A,r.rounding=1,n=or(r,nn(r,n)),r.precision=e,r.rounding=t,P(ie>2?n.neg():n,e,t,!0)):new r(NaN)};d.squareRoot=d.sqrt=function(){var e,t,n,r,o,i,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(S=!1,u=Math.sqrt(+s),u==0||u==1/0?(t=G(a),(t.length+c)%2==0&&(t+="0"),u=Math.sqrt(t),c=z((c+1)/2)-(c<0||c%2),u==1/0?t="5e"+c:(t=u.toExponential(),t=t.slice(0,t.indexOf("e")+1)+c),r=new l(t)):r=new l(u.toString()),n=(c=l.precision)+3;;)if(i=r,r=i.plus(R(s,i,n+2,1)).times(.5),G(i.d).slice(0,n)===(t=G(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!o&&t=="4999"){if(!o&&(P(i,c+1,0),i.times(i).eq(s))){r=i;break}n+=4,o=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(P(r,c+1,1),e=!r.times(r).eq(s));break}return S=!0,P(r,c,l.rounding,e)};d.tangent=d.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=R(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,P(ie==2||ie==4?n.neg():n,e,t,!0)):new r(NaN)};d.times=d.mul=function(e){var t,n,r,o,i,s,a,c,u,l=this,f=l.constructor,p=l.d,m=(e=new f(e)).d;if(e.s*=l.s,!p||!p[0]||!m||!m[0])return new f(!e.s||p&&!p[0]&&!m||m&&!m[0]&&!p?NaN:!p||!m?e.s/0:e.s*0);for(n=z(l.e/A)+z(e.e/A),c=p.length,u=m.length,c<u&&(i=p,p=m,m=i,s=c,c=u,u=s),i=[],s=c+u,r=s;r--;)i.push(0);for(r=u;--r>=0;){for(t=0,o=c+r;o>r;)a=i[o]+m[r]*p[o-r-1]+t,i[o--]=a%te|0,t=a/te|0;i[o]=(i[o]+t)%te|0}for(;!i[--s];)i.pop();return t?++n:i.shift(),e.d=i,e.e=He(i,n),S?P(e,f.precision,f.rounding):e};d.toBinary=function(e,t){return yt(this,2,e,t)};d.toDecimalPlaces=d.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(X(e,0,fe),t===void 0?t=r.rounding:X(t,0,8),P(n,e+n.e+1,t))};d.toExponential=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=re(r,!0):(X(e,0,fe),t===void 0?t=o.rounding:X(t,0,8),r=P(new o(r),e+1,t),n=re(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+n:n};d.toFixed=function(e,t){var n,r,o=this,i=o.constructor;return e===void 0?n=re(o):(X(e,0,fe),t===void 0?t=i.rounding:X(t,0,8),r=P(new i(o),e+o.e+1,t),n=re(r,!1,e+r.e+1)),o.isNeg()&&!o.isZero()?"-"+n:n};d.toFraction=function(e){var t,n,r,o,i,s,a,c,u,l,f,p,m=this,w=m.d,g=m.constructor;if(!w)return new g(m);if(u=n=new g(1),r=c=new g(0),t=new g(r),i=t.e=Qt(w)-m.e-1,s=i%A,t.d[0]=F(10,s<0?A+s:s),e==null)e=i>0?t:u;else{if(a=new g(e),!a.isInt()||a.lt(u))throw Error(le+a);e=a.gt(t)?i>0?t:u:a}for(S=!1,a=new g(G(w)),l=g.precision,g.precision=i=w.length*A*2;f=R(a,t,0,1,1),o=n.plus(f.times(r)),o.cmp(e)!=1;)n=r,r=o,o=u,u=c.plus(f.times(o)),c=o,o=t,t=a.minus(f.times(o)),a=o;return o=R(e.minus(n),r,0,1,1),c=c.plus(o.times(u)),n=n.plus(o.times(r)),c.s=u.s=m.s,p=R(u,r,i,1).minus(m).abs().cmp(R(c,n,i,1).minus(m).abs())<1?[u,r]:[c,n],g.precision=l,S=!0,p};d.toHexadecimal=d.toHex=function(e,t){return yt(this,16,e,t)};d.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:X(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&(e.s=n.s),e}return e.d[0]?(S=!1,n=R(n,e,0,t,1).times(e),S=!0,P(n)):(e.s=n.s,n=e),n};d.toNumber=function(){return+this};d.toOctal=function(e,t){return yt(this,8,e,t)};d.toPower=d.pow=function(e){var t,n,r,o,i,s,a=this,c=a.constructor,u=+(e=new c(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new c(F(+a,u));if(a=new c(a),a.eq(1))return a;if(r=c.precision,i=c.rounding,e.eq(1))return P(a,r,i);if(t=z(e.e/A),t>=e.d.length-1&&(n=u<0?-u:u)<=er)return o=$t(c,a,n,r),e.s<0?new c(1).div(o):P(o,r,i);if(s=a.s,s<0){if(t<e.d.length-1)return new c(NaN);if((e.d[t]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return n=F(+a,u),t=n==0||!isFinite(n)?z(u*(Math.log("0."+G(a.d))/Math.LN10+a.e+1)):new c(n+"").e,t>c.maxE+1||t<c.minE-1?new c(t>0?s/0:0):(S=!1,c.rounding=a.s=1,n=Math.min(12,(t+"").length),o=gt(e.times(ue(a,r+n)),r),o.d&&(o=P(o,r+5,1),Ce(o.d,r,i)&&(t=r+10,o=P(gt(e.times(ue(a,t+n)),t),t+5,1),+G(o.d).slice(r+1,r+15)+1==1e14&&(o=P(o,r+1,0)))),o.s=s,S=!0,c.rounding=i,P(o,r,i))};d.toPrecision=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=re(r,r.e<=o.toExpNeg||r.e>=o.toExpPos):(X(e,1,fe),t===void 0?t=o.rounding:X(t,0,8),r=P(new o(r),e,t),n=re(r,e<=r.e||r.e<=o.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+n:n};d.toSignificantDigits=d.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(X(e,1,fe),t===void 0?t=r.rounding:X(t,0,8)),P(new r(n),e,t)};d.toString=function(){var e=this,t=e.constructor,n=re(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n};d.truncated=d.trunc=function(){return P(new this.constructor(this),this.e+1,1)};d.valueOf=d.toJSON=function(){var e=this,t=e.constructor,n=re(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function G(e){var t,n,r,o=e.length-1,i="",s=e[0];if(o>0){for(i+=s,t=1;t<o;t++)r=e[t]+"",n=A-r.length,n&&(i+=ce(n)),i+=r;s=e[t],r=s+"",n=A-r.length,n&&(i+=ce(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return i+s}function X(e,t,n){if(e!==~~e||e<t||e>n)throw Error(le+e)}function Ce(e,t,n,r){var o,i,s,a;for(i=e[0];i>=10;i/=10)--t;return--t<0?(t+=A,o=0):(o=Math.ceil((t+1)/A),t%=A),i=F(10,A-t),a=e[o]%i|0,r==null?t<3?(t==0?a=a/100|0:t==1&&(a=a/10|0),s=n<4&&a==99999||n>3&&a==49999||a==5e4||a==0):s=(n<4&&a+1==i||n>3&&a+1==i/2)&&(e[o+1]/i/100|0)==F(10,t-2)-1||(a==i/2||a==0)&&(e[o+1]/i/100|0)==0:t<4?(t==0?a=a/1e3|0:t==1?a=a/100|0:t==2&&(a=a/10|0),s=(r||n<4)&&a==9999||!r&&n>3&&a==4999):s=((r||n<4)&&a+1==i||!r&&n>3&&a+1==i/2)&&(e[o+1]/i/1e3|0)==F(10,t-3)-1,s}function Ve(e,t,n){for(var r,o=[0],i,s=0,a=e.length;s<a;){for(i=o.length;i--;)o[i]*=t;for(o[0]+=mt.indexOf(e.charAt(s++)),r=0;r<o.length;r++)o[r]>n-1&&(o[r+1]===void 0&&(o[r+1]=0),o[r+1]+=o[r]/n|0,o[r]%=n)}return o.reverse()}function nr(e,t){var n,r,o;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),o=(1/je(4,n)).toString()):(n=16,o="2.3283064365386962890625e-10"),e.precision+=n,t=Pe(e,1,t.times(o),new e(1));for(var i=n;i--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return e.precision-=n,t}var R=function(){function e(r,o,i){var s,a=0,c=r.length;for(r=r.slice();c--;)s=r[c]*o+a,r[c]=s%i|0,a=s/i|0;return a&&r.unshift(a),r}function t(r,o,i,s){var a,c;if(i!=s)c=i>s?1:-1;else for(a=c=0;a<i;a++)if(r[a]!=o[a]){c=r[a]>o[a]?1:-1;break}return c}function n(r,o,i,s){for(var a=0;i--;)r[i]-=a,a=r[i]<o[i]?1:0,r[i]=a*s+r[i]-o[i];for(;!r[0]&&r.length>1;)r.shift()}return function(r,o,i,s,a,c){var u,l,f,p,m,w,g,T,x,b,h,y,L,B,V,_,O,H,U,$,ge=r.constructor,xe=r.s==o.s?1:-1,W=r.d,D=o.d;if(!W||!W[0]||!D||!D[0])return new ge(!r.s||!o.s||(W?D&&W[0]==D[0]:!D)?NaN:W&&W[0]==0||!D?xe*0:xe/0);for(c?(m=1,l=r.e-o.e):(c=te,m=A,l=z(r.e/m)-z(o.e/m)),U=D.length,O=W.length,x=new ge(xe),b=x.d=[],f=0;D[f]==(W[f]||0);f++);if(D[f]>(W[f]||0)&&l--,i==null?(B=i=ge.precision,s=ge.rounding):a?B=i+(r.e-o.e)+1:B=i,B<0)b.push(1),w=!0;else{if(B=B/m+2|0,f=0,U==1){for(p=0,D=D[0],B++;(f<O||p)&&B--;f++)V=p*c+(W[f]||0),b[f]=V/D|0,p=V%D|0;w=p||f<O}else{for(p=c/(D[0]+1)|0,p>1&&(D=e(D,p,c),W=e(W,p,c),U=D.length,O=W.length),_=U,h=W.slice(0,U),y=h.length;y<U;)h[y++]=0;$=D.slice(),$.unshift(0),H=D[0],D[1]>=c/2&&++H;do p=0,u=t(D,h,U,y),u<0?(L=h[0],U!=y&&(L=L*c+(h[1]||0)),p=L/H|0,p>1?(p>=c&&(p=c-1),g=e(D,p,c),T=g.length,y=h.length,u=t(g,h,T,y),u==1&&(p--,n(g,U<T?$:D,T,c))):(p==0&&(u=p=1),g=D.slice()),T=g.length,T<y&&g.unshift(0),n(h,g,y,c),u==-1&&(y=h.length,u=t(D,h,U,y),u<1&&(p++,n(h,U<y?$:D,y,c))),y=h.length):u===0&&(p++,h=[0]),b[f++]=p,u&&h[0]?h[y++]=W[_]||0:(h=[W[_]],y=1);while((_++<O||h[0]!==void 0)&&B--);w=h[0]!==void 0}b[0]||b.shift()}if(m==1)x.e=l,zt=w;else{for(f=1,p=b[0];p>=10;p/=10)f++;x.e=f+l*m-1,P(x,a?i+x.e+1:i,s,w)}return x}}();function P(e,t,n,r){var o,i,s,a,c,u,l,f,p,m=e.constructor;e:if(t!=null){if(f=e.d,!f)return e;for(o=1,a=f[0];a>=10;a/=10)o++;if(i=t-o,i<0)i+=A,s=t,l=f[p=0],c=l/F(10,o-s-1)%10|0;else if(p=Math.ceil((i+1)/A),a=f.length,p>=a)if(r){for(;a++<=p;)f.push(0);l=c=0,o=1,i%=A,s=i-A+1}else break e;else{for(l=a=f[p],o=1;a>=10;a/=10)o++;i%=A,s=i-A+o,c=s<0?0:l/F(10,o-s-1)%10|0}if(r=r||t<0||f[p+1]!==void 0||(s<0?l:l%F(10,o-s-1)),u=n<4?(c||r)&&(n==0||n==(e.s<0?3:2)):c>5||c==5&&(n==4||r||n==6&&(i>0?s>0?l/F(10,o-s):0:f[p-1])%10&1||n==(e.s<0?8:7)),t<1||!f[0])return f.length=0,u?(t-=e.e+1,f[0]=F(10,(A-t%A)%A),e.e=-t||0):f[0]=e.e=0,e;if(i==0?(f.length=p,a=1,p--):(f.length=p+1,a=F(10,A-i),f[p]=s>0?(l/F(10,o-s)%F(10,s)|0)*a:0),u)for(;;)if(p==0){for(i=1,s=f[0];s>=10;s/=10)i++;for(s=f[0]+=a,a=1;s>=10;s/=10)a++;i!=a&&(e.e++,f[0]==te&&(f[0]=1));break}else{if(f[p]+=a,f[p]!=te)break;f[p--]=0,a=1}for(i=f.length;f[--i]===0;)f.pop()}return S&&(e.e>m.maxE?(e.d=null,e.e=NaN):e.e<m.minE&&(e.e=0,e.d=[0])),e}function re(e,t,n){if(!e.isFinite())return tn(e);var r,o=e.e,i=G(e.d),s=i.length;return t?(n&&(r=n-s)>0?i=i.charAt(0)+"."+i.slice(1)+ce(r):s>1&&(i=i.charAt(0)+"."+i.slice(1)),i=i+(e.e<0?"e":"e+")+e.e):o<0?(i="0."+ce(-o-1)+i,n&&(r=n-s)>0&&(i+=ce(r))):o>=s?(i+=ce(o+1-s),n&&(r=n-o-1)>0&&(i=i+"."+ce(r))):((r=o+1)<s&&(i=i.slice(0,r)+"."+i.slice(r)),n&&(r=n-s)>0&&(o+1===s&&(i+="."),i+=ce(r))),i}function He(e,t){var n=e[0];for(t*=A;n>=10;n/=10)t++;return t}function qe(e,t,n){if(t>tr)throw S=!0,n&&(e.precision=n),Error(Zt);return P(new e(Ue),t,1,!0)}function ee(e,t,n){if(t>ht)throw Error(Zt);return P(new e(We),t,n,!0)}function Qt(e){var t=e.length-1,n=t*A+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function ce(e){for(var t="";e--;)t+="0";return t}function $t(e,t,n,r){var o,i=new e(1),s=Math.ceil(r/A+4);for(S=!1;;){if(n%2&&(i=i.times(t),Ht(i.d,s)&&(o=!0)),n=z(n/2),n===0){n=i.d.length-1,o&&i.d[n]===0&&++i.d[n];break}t=t.times(t),Ht(t.d,s)}return S=!0,i}function Gt(e){return e.d[e.d.length-1]&1}function en(e,t,n){for(var r,o=new e(t[0]),i=0;++i<t.length;)if(r=new e(t[i]),r.s)o[n](r)&&(o=r);else{o=r;break}return o}function gt(e,t){var n,r,o,i,s,a,c,u=0,l=0,f=0,p=e.constructor,m=p.rounding,w=p.precision;if(!e.d||!e.d[0]||e.e>17)return new p(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:0/0);for(t==null?(S=!1,c=w):c=t,a=new p(.03125);e.e>-2;)e=e.times(a),f+=5;for(r=Math.log(F(2,f))/Math.LN10*2+5|0,c+=r,n=i=s=new p(1),p.precision=c;;){if(i=P(i.times(e),c,1),n=n.times(++l),a=s.plus(R(i,n,c,1)),G(a.d).slice(0,c)===G(s.d).slice(0,c)){for(o=f;o--;)s=P(s.times(s),c,1);if(t==null)if(u<3&&Ce(s.d,c-r,m,u))p.precision=c+=10,n=i=a=new p(1),l=0,u++;else return P(s,p.precision=w,m,S=!0);else return p.precision=w,s}s=a}}function ue(e,t){var n,r,o,i,s,a,c,u,l,f,p,m=1,w=10,g=e,T=g.d,x=g.constructor,b=x.rounding,h=x.precision;if(g.s<0||!T||!T[0]||!g.e&&T[0]==1&&T.length==1)return new x(T&&!T[0]?-1/0:g.s!=1?NaN:T?0:g);if(t==null?(S=!1,l=h):l=t,x.precision=l+=w,n=G(T),r=n.charAt(0),Math.abs(i=g.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)g=g.times(e),n=G(g.d),r=n.charAt(0),m++;i=g.e,r>1?(g=new x("0."+n),i++):g=new x(r+"."+n.slice(1))}else return u=qe(x,l+2,h).times(i+""),g=ue(new x(r+"."+n.slice(1)),l-w).plus(u),x.precision=h,t==null?P(g,h,b,S=!0):g;for(f=g,c=s=g=R(g.minus(1),g.plus(1),l,1),p=P(g.times(g),l,1),o=3;;){if(s=P(s.times(p),l,1),u=c.plus(R(s,new x(o),l,1)),G(u.d).slice(0,l)===G(c.d).slice(0,l))if(c=c.times(2),i!==0&&(c=c.plus(qe(x,l+2,h).times(i+""))),c=R(c,new x(m),l,1),t==null)if(Ce(c.d,l-w,b,a))x.precision=l+=w,u=s=g=R(f.minus(1),f.plus(1),l,1),p=P(g.times(g),l,1),o=a=1;else return P(c,x.precision=h,b,S=!0);else return x.precision=h,c;c=u,o+=2}}function tn(e){return String(e.s*e.s/0)}function bt(e,t){var n,r,o;for((n=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(n<0&&(n=r),n+=+t.slice(r+1),t=t.substring(0,r)):n<0&&(n=t.length),r=0;t.charCodeAt(r)===48;r++);for(o=t.length;t.charCodeAt(o-1)===48;--o);if(t=t.slice(r,o),t){if(o-=r,e.e=n=n-r-1,e.d=[],r=(n+1)%A,n<0&&(r+=A),r<o){for(r&&e.d.push(+t.slice(0,r)),o-=A;r<o;)e.d.push(+t.slice(r,r+=A));t=t.slice(r),r=A-t.length}else r-=o;for(;r--;)t+="0";e.d.push(+t),S&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function rr(e,t){var n,r,o,i,s,a,c,u,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Xt.test(t))return bt(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Qn.test(t))n=16,t=t.toLowerCase();else if(Xn.test(t))n=2;else if($n.test(t))n=8;else throw Error(le+t);for(i=t.search(/p/i),i>0?(c=+t.slice(i+1),t=t.substring(2,i)):t=t.slice(2),i=t.indexOf("."),s=i>=0,r=e.constructor,s&&(t=t.replace(".",""),a=t.length,i=a-i,o=$t(r,new r(n),i,i*2)),u=Ve(t,n,te),l=u.length-1,i=l;u[i]===0;--i)u.pop();return i<0?new r(e.s*0):(e.e=He(u,l),e.d=u,S=!1,s&&(e=R(e,o,a*4)),c&&(e=e.times(Math.abs(c)<54?F(2,c):ze.pow(2,c))),S=!0,e)}function or(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:Pe(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/je(5,n)),t=Pe(e,2,t,t);for(var o,i=new e(5),s=new e(16),a=new e(20);n--;)o=t.times(t),t=t.times(i.plus(o.times(s.times(o).minus(a))));return t}function Pe(e,t,n,r,o){var i,s,a,c,u=1,l=e.precision,f=Math.ceil(l/A);for(S=!1,c=n.times(n),a=new e(r);;){if(s=R(a.times(c),new e(t++*t++),l,1),a=o?r.plus(s):r.minus(s),r=R(s.times(c),new e(t++*t++),l,1),s=a.plus(r),s.d[f]!==void 0){for(i=f;s.d[i]===a.d[i]&&i--;);if(i==-1)break}i=a,a=r,r=s,s=i,u++}return S=!0,s.d.length=f+1,s}function je(e,t){for(var n=e;--t;)n*=e;return n}function nn(e,t){var n,r=t.s<0,o=ee(e,e.precision,1),i=o.times(.5);if(t=t.abs(),t.lte(i))return ie=r?4:1,t;if(n=t.divToInt(o),n.isZero())ie=r?3:2;else{if(t=t.minus(n.times(o)),t.lte(i))return ie=Gt(n)?r?2:3:r?4:1,t;ie=Gt(n)?r?1:4:r?3:2}return t.minus(o).abs()}function yt(e,t,n,r){var o,i,s,a,c,u,l,f,p,m=e.constructor,w=n!==void 0;if(w?(X(n,1,fe),r===void 0?r=m.rounding:X(r,0,8)):(n=m.precision,r=m.rounding),!e.isFinite())l=tn(e);else{for(l=re(e),s=l.indexOf("."),w?(o=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):o=t,s>=0&&(l=l.replace(".",""),p=new m(1),p.e=l.length-s,p.d=Ve(re(p),10,o),p.e=p.d.length),f=Ve(l,10,o),i=c=f.length;f[--c]==0;)f.pop();if(!f[0])l=w?"0p+0":"0";else{if(s<0?i--:(e=new m(e),e.d=f,e.e=i,e=R(e,p,n,r,0,o),f=e.d,i=e.e,u=zt),s=f[n],a=o/2,u=u||f[n+1]!==void 0,u=r<4?(s!==void 0||u)&&(r===0||r===(e.s<0?3:2)):s>a||s===a&&(r===4||u||r===6&&f[n-1]&1||r===(e.s<0?8:7)),f.length=n,u)for(;++f[--n]>o-1;)f[n]=0,n||(++i,f.unshift(1));for(c=f.length;!f[c-1];--c);for(s=0,l="";s<c;s++)l+=mt.charAt(f[s]);if(w){if(c>1)if(t==16||t==8){for(s=t==16?4:3,--c;c%s;c++)l+="0";for(f=Ve(l,o,t),c=f.length;!f[c-1];--c);for(s=1,l="1.";s<c;s++)l+=mt.charAt(f[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(i<0?"p":"p+")+i}else if(i<0){for(;++i;)l="0"+l;l="0."+l}else if(++i>c)for(i-=c;i--;)l+="0";else i<c&&(l=l.slice(0,i)+"."+l.slice(i))}l=(t==16?"0x":t==2?"0b":t==8?"0o":"")+l}return e.s<0?"-"+l:l}function Ht(e,t){if(e.length>t)return e.length=t,!0}function ir(e){return new this(e).abs()}function sr(e){return new this(e).acos()}function ar(e){return new this(e).acosh()}function cr(e,t){return new this(e).plus(t)}function ur(e){return new this(e).asin()}function lr(e){return new this(e).asinh()}function fr(e){return new this(e).atan()}function pr(e){return new this(e).atanh()}function mr(e,t){e=new this(e),t=new this(t);var n,r=this.precision,o=this.rounding,i=r+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=ee(this,i,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?ee(this,r,o):new this(0),n.s=e.s):!e.d||t.isZero()?(n=ee(this,i,1).times(.5),n.s=e.s):t.s<0?(this.precision=i,this.rounding=1,n=this.atan(R(e,t,i,1)),t=ee(this,i,1),this.precision=r,this.rounding=o,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(R(e,t,i,1)),n}function dr(e){return new this(e).cbrt()}function hr(e){return P(e=new this(e),e.e+1,2)}function gr(e,t,n){return new this(e).clamp(t,n)}function br(e){if(!e||typeof e!="object")throw Error(Ge+"Object expected");var t,n,r,o=e.defaults===!0,i=["precision",1,fe,"rounding",0,8,"toExpNeg",-Te,0,"toExpPos",0,Te,"maxE",0,Te,"minE",-Te,0,"modulo",0,9];for(t=0;t<i.length;t+=3)if(n=i[t],o&&(this[n]=dt[n]),(r=e[n])!==void 0)if(z(r)===r&&r>=i[t+1]&&r<=i[t+2])this[n]=r;else throw Error(le+n+": "+r);if(n="crypto",o&&(this[n]=dt[n]),(r=e[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(Yt);else this[n]=!1;else throw Error(le+n+": "+r);return this}function yr(e){return new this(e).cos()}function wr(e){return new this(e).cosh()}function rn(e){var t,n,r;function o(i){var s,a,c,u=this;if(!(u instanceof o))return new o(i);if(u.constructor=o,jt(i)){u.s=i.s,S?!i.d||i.e>o.maxE?(u.e=NaN,u.d=null):i.e<o.minE?(u.e=0,u.d=[0]):(u.e=i.e,u.d=i.d.slice()):(u.e=i.e,u.d=i.d?i.d.slice():i.d);return}if(c=typeof i,c==="number"){if(i===0){u.s=1/i<0?-1:1,u.e=0,u.d=[0];return}if(i<0?(i=-i,u.s=-1):u.s=1,i===~~i&&i<1e7){for(s=0,a=i;a>=10;a/=10)s++;S?s>o.maxE?(u.e=NaN,u.d=null):s<o.minE?(u.e=0,u.d=[0]):(u.e=s,u.d=[i]):(u.e=s,u.d=[i]);return}else if(i*0!==0){i||(u.s=NaN),u.e=NaN,u.d=null;return}return bt(u,i.toString())}else if(c!=="string")throw Error(le+i);return(a=i.charCodeAt(0))===45?(i=i.slice(1),u.s=-1):(a===43&&(i=i.slice(1)),u.s=1),Xt.test(i)?bt(u,i):rr(u,i)}if(o.prototype=d,o.ROUND_UP=0,o.ROUND_DOWN=1,o.ROUND_CEIL=2,o.ROUND_FLOOR=3,o.ROUND_HALF_UP=4,o.ROUND_HALF_DOWN=5,o.ROUND_HALF_EVEN=6,o.ROUND_HALF_CEIL=7,o.ROUND_HALF_FLOOR=8,o.EUCLID=9,o.config=o.set=br,o.clone=rn,o.isDecimal=jt,o.abs=ir,o.acos=sr,o.acosh=ar,o.add=cr,o.asin=ur,o.asinh=lr,o.atan=fr,o.atanh=pr,o.atan2=mr,o.cbrt=dr,o.ceil=hr,o.clamp=gr,o.cos=yr,o.cosh=wr,o.div=xr,o.exp=Tr,o.floor=Pr,o.hypot=Ar,o.ln=kr,o.log=Br,o.log10=Cr,o.log2=Sr,o.max=Ir,o.min=Lr,o.mod=Nr,o.mul=Er,o.pow=Rr,o.random=_r,o.round=Dr,o.sign=Mr,o.sin=Or,o.sinh=Kr,o.sqrt=vr,o.sub=Fr,o.sum=Vr,o.tan=Ur,o.tanh=Wr,o.trunc=qr,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(n=r[t++])||(e[n]=this[n]);return o.config(e),o}function xr(e,t){return new this(e).div(t)}function Tr(e){return new this(e).exp()}function Pr(e){return P(e=new this(e),e.e+1,3)}function Ar(){var e,t,n=new this(0);for(S=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return S=!0,new this(1/0);n=t}return S=!0,n.sqrt()}function jt(e){return e instanceof ze||e&&e.toStringTag===Jt||!1}function kr(e){return new this(e).ln()}function Br(e,t){return new this(e).log(t)}function Sr(e){return new this(e).log(2)}function Cr(e){return new this(e).log(10)}function Ir(){return en(this,arguments,"lt")}function Lr(){return en(this,arguments,"gt")}function Nr(e,t){return new this(e).mod(t)}function Er(e,t){return new this(e).mul(t)}function Rr(e,t){return new this(e).pow(t)}function _r(e){var t,n,r,o,i=0,s=new this(1),a=[];if(e===void 0?e=this.precision:X(e,1,fe),r=Math.ceil(e/A),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));i<r;)o=t[i],o>=429e7?t[i]=crypto.getRandomValues(new Uint32Array(1))[0]:a[i++]=o%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);i<r;)o=t[i]+(t[i+1]<<8)+(t[i+2]<<16)+((t[i+3]&127)<<24),o>=214e7?crypto.randomBytes(4).copy(t,i):(a.push(o%1e7),i+=4);i=r/4}else throw Error(Yt);else for(;i<r;)a[i++]=Math.random()*1e7|0;for(r=a[--i],e%=A,r&&e&&(o=F(10,A-e),a[i]=(r/o|0)*o);a[i]===0;i--)a.pop();if(i<0)n=0,a=[0];else{for(n=-1;a[0]===0;n-=A)a.shift();for(r=1,o=a[0];o>=10;o/=10)r++;r<A&&(n-=A-r)}return s.e=n,s.d=a,s}function Dr(e){return P(e=new this(e),e.e+1,this.rounding)}function Mr(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Or(e){return new this(e).sin()}function Kr(e){return new this(e).sinh()}function vr(e){return new this(e).sqrt()}function Fr(e,t){return new this(e).sub(t)}function Vr(){var e=0,t=arguments,n=new this(t[e]);for(S=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return S=!0,P(n,this.precision,this.rounding)}function Ur(e){return new this(e).tan()}function Wr(e){return new this(e).tanh()}function qr(e){return P(e=new this(e),e.e+1,1)}d[Symbol.for("nodejs.util.inspect.custom")]=d.toString;d[Symbol.toStringTag]="Decimal";var ze=d.constructor=rn(dt);Ue=new ze(Ue);We=new ze(We);var Ze=require("@solana/web3.js");var on=require("@solana/spl-token"),N=require("@solana/web3.js");function wt({pubkey:e,isSigner:t=!1,isWritable:n=!0}){return{pubkey:e,isWritable:n,isSigner:t}}var bo=[wt({pubkey:on.TOKEN_PROGRAM_ID,isWritable:!1}),wt({pubkey:N.SystemProgram.programId,isWritable:!1}),wt({pubkey:N.SYSVAR_RENT_PUBKEY,isWritable:!1})];function sn({publicKey:e,transformSol:t}){let n=an(e.toString());if(n instanceof N.PublicKey)return t&&n.equals(Ie)?pe:n;if(t&&n.toString()===Ie.toBase58())return pe;if(typeof n=="string"){if(n===N.PublicKey.default.toBase58())return N.PublicKey.default;try{return new N.PublicKey(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function an(e){try{return new N.PublicKey(e)}catch{return e}}var yo=new N.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),wo=new N.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),xo=new N.PublicKey("SysvarRent111111111111111111111111111111111"),To=new N.PublicKey("SysvarC1ock11111111111111111111111111111111"),Po=new N.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Ao=new N.PublicKey("Sysvar1nstructions1111111111111111111111111"),ko=N.SystemProgram.programId,Bo=new N.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),So=new N.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Co=new N.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Io=new N.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Lo=new N.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),No=new N.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Eo=new N.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Ro=new N.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),_o=new N.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Do=new N.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Mo=new N.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),pe=new N.PublicKey("So11111111111111111111111111111111111111112"),Ie=N.PublicKey.default;var cn=require("@solana/web3.js"),xt=require("@solana/spl-token"),un={chainId:101,address:cn.PublicKey.default.toBase58(),programId:xt.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},se={chainId:101,address:"So11111111111111111111111111111111111111112",programId:xt.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}};var Tt=class{constructor({mint:t,decimals:n,symbol:r,name:o,skipMint:i=!1,isToken2022:s=!1}){if(t===Ie.toBase58()||t instanceof Ze.PublicKey&&Ie.equals(t)){this.decimals=se.decimals,this.symbol=se.symbol,this.name=se.name,this.mint=new Ze.PublicKey(se.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||t.toString().substring(0,6),this.name=o||t.toString().substring(0,6),this.mint=i?Ze.PublicKey.default:sn({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},Ae=Tt;Ae.WSOL=new Tt(ae(v({},se),{mint:se.address}));var Ne=J(require("big.js")),fn=J(require("bn.js")),pn=J(require("decimal.js-light"));var ln=J(require("toformat")),Gr=ln.default,Le=Gr;var Ye=j("module/fraction"),Pt=Le(Ne.default),Ee=Le(pn.default),Hr={[0]:Ee.ROUND_DOWN,[1]:Ee.ROUND_HALF_UP,[2]:Ee.ROUND_UP},jr={[0]:Ne.default.roundDown,[1]:Ne.default.roundHalfUp,[2]:Ne.default.roundUp},M=class{constructor(t,n=new fn.default(1)){this.numerator=oe(t),this.denominator=oe(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new M(this.denominator,this.numerator)}add(t){let n=t instanceof M?t:new M(oe(t));return this.denominator.eq(n.denominator)?new M(this.numerator.add(n.numerator),this.denominator):new M(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(t){let n=t instanceof M?t:new M(oe(t));return this.denominator.eq(n.denominator)?new M(this.numerator.sub(n.numerator),this.denominator):new M(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(t){let n=t instanceof M?t:new M(oe(t));return new M(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(t){let n=t instanceof M?t:new M(oe(t));return new M(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(t,n={groupSeparator:""},r=1){Number.isInteger(t)||Ye.logWithError(`${t} is not an integer.`),t<=0&&Ye.logWithError(`${t} is not positive.`),Ee.set({precision:t+1,rounding:Hr[r]});let o=new Ee(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return o.toFormat(o.decimalPlaces(),n)}toFixed(t,n={groupSeparator:""},r=1){return Number.isInteger(t)||Ye.logWithError(`${t} is not an integer.`),t<0&&Ye.logWithError(`${t} is negative.`),Pt.DP=t,Pt.RM=jr[r]||1,new Pt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,n)}isZero(){return this.numerator.isZero()}};var ei=j("Raydium_price");var At=class{constructor({decimals:t,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=t,this.symbol=n,this.name=r}equals(t){return this===t}},Je=At;Je.SOL=new At(un);var mn=J(require("bn.js"));var ai=new M(new mn.default(100));var Zr=new Y.default(0),Si=new Y.default(1),Ci=new Y.default(2),Ii=new Y.default(3),Li=new Y.default(5),Yr=new Y.default(10),Ni=new Y.default(100),Ei=new Y.default(1e3),Ri=new Y.default(1e4),bn=9007199254740991;function oe(e){let t=j("Raydium_parseBigNumberish");if(e instanceof Y.default)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new Y.default(e);t.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&t.logWithError(`BigNumberish number underflow: ${e}`),(e>=bn||e<=-bn)&&t.logWithError(`BigNumberish number overflow: ${e}`),new Y.default(String(e))):typeof e=="bigint"?new Y.default(e.toString()):(t.error(`invalid BigNumberish value: ${e}`),new Y.default(0))}var qi=j("Raydium_amount"),Gi=Le(yn.default);var E=require("@solana/web3.js"),Bn=J(require("axios"));var q={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",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",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"};var Z=require("@solana/web3.js"),xn=require("@solana/spl-token");var wn=j("Raydium_txUtil"),Tn=1644;function Xe(e){let t=[],n=[];return e.microLamports&&(t.push(Z.ComputeBudgetProgram.setComputeUnitPrice({microLamports:e.microLamports})),n.push(q.SetComputeUnitPrice)),e.units&&(t.push(Z.ComputeBudgetProgram.setComputeUnitLimit({units:e.units})),n.push(q.SetComputeUnitLimit)),{instructions:t,instructionTypes:n}}async function ke(e,t){var r,o;let n=t!=null?t:"confirmed";try{return((o=await((r=e.getLatestBlockhash)==null?void 0:r.call(e,{commitment:n})))==null?void 0:o.blockhash)||(await e.getRecentBlockhash(n)).blockhash}catch{return(await e.getRecentBlockhash(n)).blockhash}}function $r(e,t){e.length<1&&wn.logWithError(`no instructions provided: ${e.toString()}`),t.length<1&&wn.logWithError(`no signers provided:, ${t.toString()}`);let n=new Z.Transaction;n.recentBlockhash="11111111111111111111111111111111",n.feePayer=t[0],n.add(...e);try{return Buffer.from(n.serialize({verifySignatures:!1})).toString("base64").length<Tn}catch{return!1}}function Pn(e,t){let[n,r]=Z.PublicKey.findProgramAddressSync(e,t);return{publicKey:n,nonce:r}}function Re({instructions:e,payer:t,signers:n}){return $r(e,[t,...n])}function _e({instructions:e,payer:t,lookupTableAddressAccount:n,recentBlockhash:r=Z.Keypair.generate().publicKey.toString()}){let i=new Z.TransactionMessage({payerKey:t,recentBlockhash:r,instructions:e}).compileToV0Message(Object.values(n!=null?n:{}));try{return Buffer.from(new Z.VersionedTransaction(i).serialize()).toString("base64").length<Tn}catch{return!1}}var eo=e=>Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e.buffer,e.byteOffset,e.byteLength):Buffer.from(e),to=e=>{let t=e.serialize({requireAllSignatures:!1,verifySignatures:!1});e instanceof Z.VersionedTransaction&&(t=eo(t));try{return t instanceof Buffer?t.toString("base64"):Buffer.from(t).toString("base64")}catch{return t.toString("base64")}};function ye(e){let t=[];return e.forEach(n=>{n instanceof Z.Transaction&&(n.recentBlockhash||(n.recentBlockhash=xn.TOKEN_PROGRAM_ID.toBase58()),n.feePayer||(n.feePayer=Z.Keypair.generate().publicKey)),t.push(to(n))}),console.log("simulate tx string:",t),t}var me=require("@solana/web3.js");var An=require("@solana/web3.js"),Qe=require("@solana/spl-token");var kt=j("Raydium_accountInfo_util");async function kn(e,t,n){let{batchRequest:r,commitment:o="confirmed",chunkCount:i=100}=v({batchRequest:!1},n),s=Bt(t,i),a=new Array(s.length).fill([]);if(r){let c=s.map(f=>{let p=e._buildArgs([f.map(m=>m.toBase58())],o,"base64");return{methodName:"getMultipleAccounts",args:p}}),u=Bt(c,10);a=(await(await Promise.all(u.map(async f=>await e._rpcBatchRequest(f)))).flat()).map(f=>(f.error&&kt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${f.error.message}`),f.result.value.map(p=>{if(p){let{data:m,executable:w,lamports:g,owner:T,rentEpoch:x}=p;return m.length!==2&&m[1]!=="base64"&&kt.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(m[0],"base64"),executable:w,lamports:g,owner:new An.PublicKey(T),rentEpoch:x}}return null})))}else try{a=await Promise.all(s.map(c=>e.getMultipleAccountsInfo(c,o)))}catch(c){c instanceof Error&&kt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return a.flat()}async function St({connection:e,address:t}){let n=await kn(e,[...new Set(t.map(o=>o.toString()))].map(o=>new me.PublicKey(o))),r={};for(let o=0;o<t.length;o++){let i=n[o],s=t[o];if(!i)continue;let a=new me.AddressLookupTableAccount({key:s,state:me.AddressLookupTableAccount.deserialize(i.data)});r[s.toString()]=a,$e[s.toString()]=a}return r}var $e={"2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17":new me.AddressLookupTableAccount({key:new me.PublicKey("2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17"),state:me.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 et=class{constructor(t){this.instructions=[];this.endInstructions=[];this.lookupTableAddress=[];this.signers=[];this.instructionTypes=[];this.endInstructionTypes=[];this.connection=t.connection,this.feePayer=t.feePayer,this.signAllTransactions=t.signAllTransactions,this.owner=t.owner,this.cluster=t.cluster,this.blockhashCommitment=t.blockhashCommitment,this.api=t.api}get AllTxData(){return{instructions:this.instructions,endInstructions:this.endInstructions,signers:this.signers,instructionTypes:this.instructionTypes,endInstructionTypes:this.endInstructionTypes,lookupTableAddress:this.lookupTableAddress}}get allInstructions(){return[...this.instructions,...this.endInstructions]}async getComputeBudgetConfig(){var r;let t=(await Bn.default.get(`https://solanacompass.com/api/fees?cacheFreshTime=${3e5}`)).data,{avg:n}=(r=t==null?void 0:t[15])!=null?r:{};if(!!n)return{units:6e5,microLamports:Math.min(Math.ceil(n*1e6/6e5),25e3)}}addCustomComputeBudget(t){if(t){let{instructions:n,instructionTypes:r}=Xe(t);return this.instructions.unshift(...n),this.instructionTypes.unshift(...r),!0}return!1}async calComputeBudget({config:t,defaultIns:n}){try{let r=t||await this.getComputeBudgetConfig();if(this.addCustomComputeBudget(r))return;n&&this.instructions.unshift(...n)}catch{n&&this.instructions.unshift(...n)}}addInstruction({instructions:t=[],endInstructions:n=[],signers:r=[],instructionTypes:o=[],endInstructionTypes:i=[],lookupTableAddress:s=[]}){return this.instructions.push(...t),this.endInstructions.push(...n),this.signers.push(...r),this.instructionTypes.push(...o),this.endInstructionTypes.push(...i),this.lookupTableAddress.push(...s.filter(a=>a!==E.PublicKey.default.toString())),this}async versionBuild({txVersion:t,extInfo:n}){return t===0?await this.buildV0(v({},n||{})):this.build(n)}build(t){var r;let n=new E.Transaction;return this.allInstructions.length&&n.add(...this.allInstructions),n.feePayer=this.feePayer,((r=this.owner)==null?void 0:r.signer)&&!this.signers.some(o=>o.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 o=>{var u;let{recentBlockHash:i,skipPreflight:s=!0,sendAndConfirm:a}=o||{},c=i!=null?i:await ke(this.connection,this.blockhashCommitment);if(n.recentBlockhash=c,this.signers.length&&n.sign(...this.signers),ye([n]),(u=this.owner)!=null&&u.isKeyPair)return{txId:a?await(0,E.sendAndConfirmTransaction)(this.connection,n,this.signers.find(f=>f.publicKey.equals(this.owner.publicKey))?t