@raydium-io/raydium-sdk-v2
Version:
An SDK for building applications on top of Raydium.
1 lines • 475 kB
JavaScript
var Ul=Object.create;var Qo=Object.defineProperty,Gl=Object.defineProperties,Xl=Object.getOwnPropertyDescriptor,zl=Object.getOwnPropertyDescriptors,Yl=Object.getOwnPropertyNames,Ji=Object.getOwnPropertySymbols,Hl=Object.getPrototypeOf,is=Object.prototype.hasOwnProperty,cu=Object.prototype.propertyIsEnumerable;var uu=(s,e,t)=>e in s?Qo(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,V=(s,e)=>{for(var t in e||(e={}))is.call(e,t)&&uu(s,t,e[t]);if(Ji)for(var t of Ji(e))cu.call(e,t)&&uu(s,t,e[t]);return s},q=(s,e)=>Gl(s,zl(e));var Ze=(s,e)=>{var t={};for(var n in s)is.call(s,n)&&e.indexOf(n)<0&&(t[n]=s[n]);if(s!=null&&Ji)for(var n of Ji(s))e.indexOf(n)<0&&cu.call(s,n)&&(t[n]=s[n]);return t};var Ql=(s,e)=>{for(var t in e)Qo(s,t,{get:e[t],enumerable:!0})},lu=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Yl(e))!is.call(s,o)&&o!==t&&Qo(s,o,{get:()=>e[o],enumerable:!(n=Xl(e,o))||n.enumerable});return s};var he=(s,e,t)=>(t=s!=null?Ul(Hl(s)):{},lu(e||!s||!s.__esModule?Qo(t,"default",{value:s,enumerable:!0}):t,s)),jl=s=>lu(Qo({},"__esModule",{value:!0}),s);var Fp={};Ql(Fp,{Raydium:()=>Hi});module.exports=jl(Fp);var Dl=require("lodash");var vs=he(require("axios"));var us=require("@solana/web3.js");var jo=require("lodash");var rs=class{constructor(e){this.logLevel=e.logLevel!==void 0?e.logLevel:0,this.name=e.name}set level(e){this.logLevel=e}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(e){return e<=this.logLevel}error(...e){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...e),this):this}logWithError(...e){let t=e.map(n=>typeof n=="object"?JSON.stringify(n):n).join(", ");throw new Error(t)}warning(...e){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...e),this):this}info(...e){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...e),this):this}debug(...e){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...e),this):this}},mu={},$l={};function xe(s){let e=(0,jo.get)(mu,s);if(!e){let t=(0,jo.get)($l,s);e=new rs({name:s,logLevel:t}),(0,jo.set)(mu,s,e)}return e}var Wn=require("@solana/spl-token"),ss=xe("Raydium_accountInfo_util");async function ln(s,e,t){let{batchRequest:n,commitment:o="confirmed",chunkCount:i=100}=V({batchRequest:!1},t),r=as(e,i),a=new Array(r.length).fill([]);if(n){let c=r.map(m=>{let d=s._buildArgs([m.map(p=>p.toBase58())],o,"base64");return{methodName:"getMultipleAccounts",args:d}}),u=as(c,10);a=(await(await Promise.all(u.map(async m=>await s._rpcBatchRequest(m)))).flat()).map(m=>(m.error&&ss.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${m.error.message}`),m.result.value.map(d=>{if(d){let{data:p,executable:f,lamports:y,owner:b,rentEpoch:g}=d;return p.length!==2&&p[1]!=="base64"&&ss.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(p[0],"base64"),executable:f,lamports:y,owner:new us.PublicKey(b),rentEpoch:g}}return null})))}else try{a=await Promise.all(r.map(c=>s.getMultipleAccountsInfo(c,o)))}catch(c){c instanceof Error&&ss.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return a.flat()}async function ze(s,e,t){let n=await ln(s,e.map(o=>o.pubkey),t);return e.map((o,i)=>q(V({},o),{accountInfo:n[i]}))}async function So({connection:s,mints:e,config:t}){var i,r,a;if(e.length===0)return{};let n=await ze(s,e.map(c=>({pubkey:It(c)})),t),o={};for(let c of n){if(!c.accountInfo||c.accountInfo.data.length<Wn.MINT_SIZE){console.log("invalid mint account",c.pubkey.toBase58());continue}let u=(0,Wn.unpackMint)(c.pubkey,c.accountInfo,(i=c.accountInfo)==null?void 0:i.owner);o[c.pubkey.toString()]=q(V({},u),{programId:((r=c.accountInfo)==null?void 0:r.owner)||Wn.TOKEN_PROGRAM_ID,feeConfig:(a=(0,Wn.getTransferFeeConfig)(u))!=null?a:void 0})}return o[us.PublicKey.default.toBase58()]=o[j.toBase58()],o}var pn=he(require("bn.js"));var Ko=9e15,Gn=1e9,cs="0123456789abcdef",nr="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",or="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",ls={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Ko,maxE:Ko,crypto:!1},yu,Ln,Te=!0,rr="[DecimalError] ",Un=rr+"Invalid argument: ",bu=rr+"Precision limit exceeded",gu=rr+"crypto unavailable",Pu="[object Decimal]",Bt=Math.floor,mt=Math.pow,Zl=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Jl=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,em=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Au=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,mn=1e7,Ae=7,tm=9007199254740991,nm=nr.length-1,ms=or.length-1,X={toStringTag:Pu};X.absoluteValue=X.abs=function(){var s=new this.constructor(this);return s.s<0&&(s.s=1),pe(s)};X.ceil=function(){return pe(new this.constructor(this),this.e+1,2)};X.clampedTo=X.clamp=function(s,e){var t,n=this,o=n.constructor;if(s=new o(s),e=new o(e),!s.s||!e.s)return new o(NaN);if(s.gt(e))throw Error(Un+e);return t=n.cmp(s),t<0?s:n.cmp(e)>0?e:new o(n)};X.comparedTo=X.cmp=function(s){var e,t,n,o,i=this,r=i.d,a=(s=new i.constructor(s)).d,c=i.s,u=s.s;if(!r||!a)return!c||!u?NaN:c!==u?c:r===a?0:!r^c<0?1:-1;if(!r[0]||!a[0])return r[0]?c:a[0]?-u:0;if(c!==u)return c;if(i.e!==s.e)return i.e>s.e^c<0?1:-1;for(n=r.length,o=a.length,e=0,t=n<o?n:o;e<t;++e)if(r[e]!==a[e])return r[e]>a[e]^c<0?1:-1;return n===o?0:n>o^c<0?1:-1};X.cosine=X.cos=function(){var s,e,t=this,n=t.constructor;return t.d?t.d[0]?(s=n.precision,e=n.rounding,n.precision=s+Math.max(t.e,t.sd())+Ae,n.rounding=1,t=om(n,Iu(n,t)),n.precision=s,n.rounding=e,pe(Ln==2||Ln==3?t.neg():t,s,e,!0)):new n(1):new n(NaN)};X.cubeRoot=X.cbrt=function(){var s,e,t,n,o,i,r,a,c,u,l=this,m=l.constructor;if(!l.isFinite()||l.isZero())return new m(l);for(Te=!1,i=l.s*mt(l.s*l,1/3),!i||Math.abs(i)==1/0?(t=wt(l.d),s=l.e,(i=(s-t.length+1)%3)&&(t+=i==1||i==-2?"0":"00"),i=mt(t,1/3),s=Bt((s+1)/3)-(s%3==(s<0?-1:2)),i==1/0?t="5e"+s:(t=i.toExponential(),t=t.slice(0,t.indexOf("e")+1)+s),n=new m(t),n.s=l.s):n=new m(i.toString()),r=(s=m.precision)+3;;)if(a=n,c=a.times(a).times(a),u=c.plus(l),n=Xe(u.plus(l).times(a),u.plus(c),r+2,1),wt(a.d).slice(0,r)===(t=wt(n.d)).slice(0,r))if(t=t.slice(r-3,r+1),t=="9999"||!o&&t=="4999"){if(!o&&(pe(a,s+1,0),a.times(a).times(a).eq(l))){n=a;break}r+=4,o=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(pe(n,s+1,1),e=!n.times(n).times(n).eq(l));break}return Te=!0,pe(n,s,m.rounding,e)};X.decimalPlaces=X.dp=function(){var s,e=this.d,t=NaN;if(e){if(s=e.length-1,t=(s-Bt(this.e/Ae))*Ae,s=e[s],s)for(;s%10==0;s/=10)t--;t<0&&(t=0)}return t};X.dividedBy=X.div=function(s){return Xe(this,new this.constructor(s))};X.dividedToIntegerBy=X.divToInt=function(s){var e=this,t=e.constructor;return pe(Xe(e,new t(s),0,1,1),t.precision,t.rounding)};X.equals=X.eq=function(s){return this.cmp(s)===0};X.floor=function(){return pe(new this.constructor(this),this.e+1,3)};X.greaterThan=X.gt=function(s){return this.cmp(s)>0};X.greaterThanOrEqualTo=X.gte=function(s){var e=this.cmp(s);return e==1||e===0};X.hyperbolicCosine=X.cosh=function(){var s,e,t,n,o,i=this,r=i.constructor,a=new r(1);if(!i.isFinite())return new r(i.s?1/0:NaN);if(i.isZero())return a;t=r.precision,n=r.rounding,r.precision=t+Math.max(i.e,i.sd())+4,r.rounding=1,o=i.d.length,o<32?(s=Math.ceil(o/3),e=(1/ar(4,s)).toString()):(s=16,e="2.3283064365386962890625e-10"),i=Co(r,1,i.times(e),new r(1),!0);for(var c,u=s,l=new r(8);u--;)c=i.times(i),i=a.minus(c.times(l.minus(c.times(l))));return pe(i,r.precision=t,r.rounding=n,!0)};X.hyperbolicSine=X.sinh=function(){var s,e,t,n,o=this,i=o.constructor;if(!o.isFinite()||o.isZero())return new i(o);if(e=i.precision,t=i.rounding,i.precision=e+Math.max(o.e,o.sd())+4,i.rounding=1,n=o.d.length,n<3)o=Co(i,2,o,o,!0);else{s=1.4*Math.sqrt(n),s=s>16?16:s|0,o=o.times(1/ar(5,s)),o=Co(i,2,o,o,!0);for(var r,a=new i(5),c=new i(16),u=new i(20);s--;)r=o.times(o),o=o.times(a.plus(r.times(c.times(r).plus(u))))}return i.precision=e,i.rounding=t,pe(o,e,t,!0)};X.hyperbolicTangent=X.tanh=function(){var s,e,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(s=n.precision,e=n.rounding,n.precision=s+7,n.rounding=1,Xe(t.sinh(),t.cosh(),n.precision=s,n.rounding=e)):new n(t.s)};X.inverseCosine=X.acos=function(){var s=this,e=s.constructor,t=s.abs().cmp(1),n=e.precision,o=e.rounding;return t!==-1?t===0?s.isNeg()?Bn(e,n,o):new e(0):new e(NaN):s.isZero()?Bn(e,n+4,o).times(.5):(e.precision=n+6,e.rounding=1,s=new e(1).minus(s).div(s.plus(1)).sqrt().atan(),e.precision=n,e.rounding=o,s.times(2))};X.inverseHyperbolicCosine=X.acosh=function(){var s,e,t=this,n=t.constructor;return t.lte(1)?new n(t.eq(1)?0:NaN):t.isFinite()?(s=n.precision,e=n.rounding,n.precision=s+Math.max(Math.abs(t.e),t.sd())+4,n.rounding=1,Te=!1,t=t.times(t).minus(1).sqrt().plus(t),Te=!0,n.precision=s,n.rounding=e,t.ln()):new n(t)};X.inverseHyperbolicSine=X.asinh=function(){var s,e,t=this,n=t.constructor;return!t.isFinite()||t.isZero()?new n(t):(s=n.precision,e=n.rounding,n.precision=s+2*Math.max(Math.abs(t.e),t.sd())+6,n.rounding=1,Te=!1,t=t.times(t).plus(1).sqrt().plus(t),Te=!0,n.precision=s,n.rounding=e,t.ln())};X.inverseHyperbolicTangent=X.atanh=function(){var s,e,t,n,o=this,i=o.constructor;return o.isFinite()?o.e>=0?new i(o.abs().eq(1)?o.s/0:o.isZero()?o:NaN):(s=i.precision,e=i.rounding,n=o.sd(),Math.max(n,s)<2*-o.e-1?pe(new i(o),s,e,!0):(i.precision=t=n-o.e,o=Xe(o.plus(1),new i(1).minus(o),t+s,1),i.precision=s+4,i.rounding=1,o=o.ln(),i.precision=s,i.rounding=e,o.times(.5))):new i(NaN)};X.inverseSine=X.asin=function(){var s,e,t,n,o=this,i=o.constructor;return o.isZero()?new i(o):(e=o.abs().cmp(1),t=i.precision,n=i.rounding,e!==-1?e===0?(s=Bn(i,t+4,n).times(.5),s.s=o.s,s):new i(NaN):(i.precision=t+6,i.rounding=1,o=o.div(new i(1).minus(o.times(o)).sqrt().plus(1)).atan(),i.precision=t,i.rounding=n,o.times(2)))};X.inverseTangent=X.atan=function(){var s,e,t,n,o,i,r,a,c,u=this,l=u.constructor,m=l.precision,d=l.rounding;if(u.isFinite()){if(u.isZero())return new l(u);if(u.abs().eq(1)&&m+4<=ms)return r=Bn(l,m+4,d).times(.25),r.s=u.s,r}else{if(!u.s)return new l(NaN);if(m+4<=ms)return r=Bn(l,m+4,d).times(.5),r.s=u.s,r}for(l.precision=a=m+10,l.rounding=1,t=Math.min(28,a/Ae+2|0),s=t;s;--s)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(Te=!1,e=Math.ceil(a/Ae),n=1,c=u.times(u),r=new l(u),o=u;s!==-1;)if(o=o.times(c),i=r.minus(o.div(n+=2)),o=o.times(c),r=i.plus(o.div(n+=2)),r.d[e]!==void 0)for(s=e;r.d[s]===i.d[s]&&s--;);return t&&(r=r.times(2<<t-1)),Te=!0,pe(r,l.precision=m,l.rounding=d,!0)};X.isFinite=function(){return!!this.d};X.isInteger=X.isInt=function(){return!!this.d&&Bt(this.e/Ae)>this.d.length-2};X.isNaN=function(){return!this.s};X.isNegative=X.isNeg=function(){return this.s<0};X.isPositive=X.isPos=function(){return this.s>0};X.isZero=function(){return!!this.d&&this.d[0]===0};X.lessThan=X.lt=function(s){return this.cmp(s)<0};X.lessThanOrEqualTo=X.lte=function(s){return this.cmp(s)<1};X.logarithm=X.log=function(s){var e,t,n,o,i,r,a,c,u=this,l=u.constructor,m=l.precision,d=l.rounding,p=5;if(s==null)s=new l(10),e=!0;else{if(s=new l(s),t=s.d,s.s<0||!t||!t[0]||s.eq(1))return new l(NaN);e=s.eq(10)}if(t=u.d,u.s<0||!t||!t[0]||u.eq(1))return new l(t&&!t[0]?-1/0:u.s!=1?NaN:t?0:1/0);if(e)if(t.length>1)i=!0;else{for(o=t[0];o%10===0;)o/=10;i=o!==1}if(Te=!1,a=m+p,r=qn(u,a),n=e?ir(l,a+10):qn(s,a),c=Xe(r,n,a,1),$o(c.d,o=m,d))do if(a+=10,r=qn(u,a),n=e?ir(l,a+10):qn(s,a),c=Xe(r,n,a,1),!i){+wt(c.d).slice(o+1,o+15)+1==1e14&&(c=pe(c,m+1,0));break}while($o(c.d,o+=10,d));return Te=!0,pe(c,m,d)};X.minus=X.sub=function(s){var e,t,n,o,i,r,a,c,u,l,m,d,p=this,f=p.constructor;if(s=new f(s),!p.d||!s.d)return!p.s||!s.s?s=new f(NaN):p.d?s.s=-s.s:s=new f(s.d||p.s!==s.s?p:NaN),s;if(p.s!=s.s)return s.s=-s.s,p.plus(s);if(u=p.d,d=s.d,a=f.precision,c=f.rounding,!u[0]||!d[0]){if(d[0])s.s=-s.s;else if(u[0])s=new f(p);else return new f(c===3?-0:0);return Te?pe(s,a,c):s}if(t=Bt(s.e/Ae),l=Bt(p.e/Ae),u=u.slice(),i=l-t,i){for(m=i<0,m?(e=u,i=-i,r=d.length):(e=d,t=l,r=u.length),n=Math.max(Math.ceil(a/Ae),r)+2,i>n&&(i=n,e.length=1),e.reverse(),n=i;n--;)e.push(0);e.reverse()}else{for(n=u.length,r=d.length,m=n<r,m&&(r=n),n=0;n<r;n++)if(u[n]!=d[n]){m=u[n]<d[n];break}i=0}for(m&&(e=u,u=d,d=e,s.s=-s.s),r=u.length,n=d.length-r;n>0;--n)u[r++]=0;for(n=d.length;n>i;){if(u[--n]<d[n]){for(o=n;o&&u[--o]===0;)u[o]=mn-1;--u[o],u[n]+=mn}u[n]-=d[n]}for(;u[--r]===0;)u.pop();for(;u[0]===0;u.shift())--t;return u[0]?(s.d=u,s.e=sr(u,t),Te?pe(s,a,c):s):new f(c===3?-0:0)};X.modulo=X.mod=function(s){var e,t=this,n=t.constructor;return s=new n(s),!t.d||!s.s||s.d&&!s.d[0]?new n(NaN):!s.d||t.d&&!t.d[0]?pe(new n(t),n.precision,n.rounding):(Te=!1,n.modulo==9?(e=Xe(t,s.abs(),0,3,1),e.s*=s.s):e=Xe(t,s,0,n.modulo,1),e=e.times(s),Te=!0,t.minus(e))};X.naturalExponential=X.exp=function(){return ds(this)};X.naturalLogarithm=X.ln=function(){return qn(this)};X.negated=X.neg=function(){var s=new this.constructor(this);return s.s=-s.s,pe(s)};X.plus=X.add=function(s){var e,t,n,o,i,r,a,c,u,l,m=this,d=m.constructor;if(s=new d(s),!m.d||!s.d)return!m.s||!s.s?s=new d(NaN):m.d||(s=new d(s.d||m.s===s.s?m:NaN)),s;if(m.s!=s.s)return s.s=-s.s,m.minus(s);if(u=m.d,l=s.d,a=d.precision,c=d.rounding,!u[0]||!l[0])return l[0]||(s=new d(m)),Te?pe(s,a,c):s;if(i=Bt(m.e/Ae),n=Bt(s.e/Ae),u=u.slice(),o=i-n,o){for(o<0?(t=u,o=-o,r=l.length):(t=l,n=i,r=u.length),i=Math.ceil(a/Ae),r=i>r?i+1:r+1,o>r&&(o=r,t.length=1),t.reverse();o--;)t.push(0);t.reverse()}for(r=u.length,o=l.length,r-o<0&&(o=r,t=l,l=u,u=t),e=0;o;)e=(u[--o]=u[o]+l[o]+e)/mn|0,u[o]%=mn;for(e&&(u.unshift(e),++n),r=u.length;u[--r]==0;)u.pop();return s.d=u,s.e=sr(u,n),Te?pe(s,a,c):s};X.precision=X.sd=function(s){var e,t=this;if(s!==void 0&&s!==!!s&&s!==1&&s!==0)throw Error(Un+s);return t.d?(e=wu(t.d),s&&t.e+1>e&&(e=t.e+1)):e=NaN,e};X.round=function(){var s=this,e=s.constructor;return pe(new e(s),s.e+1,e.rounding)};X.sine=X.sin=function(){var s,e,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(s=n.precision,e=n.rounding,n.precision=s+Math.max(t.e,t.sd())+Ae,n.rounding=1,t=rm(n,Iu(n,t)),n.precision=s,n.rounding=e,pe(Ln>2?t.neg():t,s,e,!0)):new n(NaN)};X.squareRoot=X.sqrt=function(){var s,e,t,n,o,i,r=this,a=r.d,c=r.e,u=r.s,l=r.constructor;if(u!==1||!a||!a[0])return new l(!u||u<0&&(!a||a[0])?NaN:a?r:1/0);for(Te=!1,u=Math.sqrt(+r),u==0||u==1/0?(e=wt(a),(e.length+c)%2==0&&(e+="0"),u=Math.sqrt(e),c=Bt((c+1)/2)-(c<0||c%2),u==1/0?e="5e"+c:(e=u.toExponential(),e=e.slice(0,e.indexOf("e")+1)+c),n=new l(e)):n=new l(u.toString()),t=(c=l.precision)+3;;)if(i=n,n=i.plus(Xe(r,i,t+2,1)).times(.5),wt(i.d).slice(0,t)===(e=wt(n.d)).slice(0,t))if(e=e.slice(t-3,t+1),e=="9999"||!o&&e=="4999"){if(!o&&(pe(i,c+1,0),i.times(i).eq(r))){n=i;break}t+=4,o=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(pe(n,c+1,1),s=!n.times(n).eq(r));break}return Te=!0,pe(n,c,l.rounding,s)};X.tangent=X.tan=function(){var s,e,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(s=n.precision,e=n.rounding,n.precision=s+10,n.rounding=1,t=t.sin(),t.s=1,t=Xe(t,new n(1).minus(t.times(t)).sqrt(),s+10,0),n.precision=s,n.rounding=e,pe(Ln==2||Ln==4?t.neg():t,s,e,!0)):new n(NaN)};X.times=X.mul=function(s){var e,t,n,o,i,r,a,c,u,l=this,m=l.constructor,d=l.d,p=(s=new m(s)).d;if(s.s*=l.s,!d||!d[0]||!p||!p[0])return new m(!s.s||d&&!d[0]&&!p||p&&!p[0]&&!d?NaN:!d||!p?s.s/0:s.s*0);for(t=Bt(l.e/Ae)+Bt(s.e/Ae),c=d.length,u=p.length,c<u&&(i=d,d=p,p=i,r=c,c=u,u=r),i=[],r=c+u,n=r;n--;)i.push(0);for(n=u;--n>=0;){for(e=0,o=c+n;o>n;)a=i[o]+p[n]*d[o-n-1]+e,i[o--]=a%mn|0,e=a/mn|0;i[o]=(i[o]+e)%mn|0}for(;!i[--r];)i.pop();return e?++t:i.shift(),s.d=i,s.e=sr(i,t),Te?pe(s,m.precision,m.rounding):s};X.toBinary=function(s,e){return ps(this,2,s,e)};X.toDecimalPlaces=X.toDP=function(s,e){var t=this,n=t.constructor;return t=new n(t),s===void 0?t:(Ut(s,0,Gn),e===void 0?e=n.rounding:Ut(e,0,8),pe(t,s+t.e+1,e))};X.toExponential=function(s,e){var t,n=this,o=n.constructor;return s===void 0?t=xn(n,!0):(Ut(s,0,Gn),e===void 0?e=o.rounding:Ut(e,0,8),n=pe(new o(n),s+1,e),t=xn(n,!0,s+1)),n.isNeg()&&!n.isZero()?"-"+t:t};X.toFixed=function(s,e){var t,n,o=this,i=o.constructor;return s===void 0?t=xn(o):(Ut(s,0,Gn),e===void 0?e=i.rounding:Ut(e,0,8),n=pe(new i(o),s+o.e+1,e),t=xn(n,!1,s+n.e+1)),o.isNeg()&&!o.isZero()?"-"+t:t};X.toFraction=function(s){var e,t,n,o,i,r,a,c,u,l,m,d,p=this,f=p.d,y=p.constructor;if(!f)return new y(p);if(u=t=new y(1),n=c=new y(0),e=new y(n),i=e.e=wu(f)-p.e-1,r=i%Ae,e.d[0]=mt(10,r<0?Ae+r:r),s==null)s=i>0?e:u;else{if(a=new y(s),!a.isInt()||a.lt(u))throw Error(Un+a);s=a.gt(e)?i>0?e:u:a}for(Te=!1,a=new y(wt(f)),l=y.precision,y.precision=i=f.length*Ae*2;m=Xe(a,e,0,1,1),o=t.plus(m.times(n)),o.cmp(s)!=1;)t=n,n=o,o=u,u=c.plus(m.times(o)),c=o,o=e,e=a.minus(m.times(o)),a=o;return o=Xe(s.minus(t),n,0,1,1),c=c.plus(o.times(u)),t=t.plus(o.times(n)),c.s=u.s=p.s,d=Xe(u,n,i,1).minus(p).abs().cmp(Xe(c,t,i,1).minus(p).abs())<1?[u,n]:[c,t],y.precision=l,Te=!0,d};X.toHexadecimal=X.toHex=function(s,e){return ps(this,16,s,e)};X.toNearest=function(s,e){var t=this,n=t.constructor;if(t=new n(t),s==null){if(!t.d)return t;s=new n(1),e=n.rounding}else{if(s=new n(s),e===void 0?e=n.rounding:Ut(e,0,8),!t.d)return s.s?t:s;if(!s.d)return s.s&&(s.s=t.s),s}return s.d[0]?(Te=!1,t=Xe(t,s,0,e,1).times(s),Te=!0,pe(t)):(s.s=t.s,t=s),t};X.toNumber=function(){return+this};X.toOctal=function(s,e){return ps(this,8,s,e)};X.toPower=X.pow=function(s){var e,t,n,o,i,r,a=this,c=a.constructor,u=+(s=new c(s));if(!a.d||!s.d||!a.d[0]||!s.d[0])return new c(mt(+a,u));if(a=new c(a),a.eq(1))return a;if(n=c.precision,i=c.rounding,s.eq(1))return pe(a,n,i);if(e=Bt(s.e/Ae),e>=s.d.length-1&&(t=u<0?-u:u)<=tm)return o=ku(c,a,t,n),s.s<0?new c(1).div(o):pe(o,n,i);if(r=a.s,r<0){if(e<s.d.length-1)return new c(NaN);if((s.d[e]&1)==0&&(r=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=r,a}return t=mt(+a,u),e=t==0||!isFinite(t)?Bt(u*(Math.log("0."+wt(a.d))/Math.LN10+a.e+1)):new c(t+"").e,e>c.maxE+1||e<c.minE-1?new c(e>0?r/0:0):(Te=!1,c.rounding=a.s=1,t=Math.min(12,(e+"").length),o=ds(s.times(qn(a,n+t)),n),o.d&&(o=pe(o,n+5,1),$o(o.d,n,i)&&(e=n+10,o=pe(ds(s.times(qn(a,e+t)),e),e+5,1),+wt(o.d).slice(n+1,n+15)+1==1e14&&(o=pe(o,n+1,0)))),o.s=r,Te=!0,c.rounding=i,pe(o,n,i))};X.toPrecision=function(s,e){var t,n=this,o=n.constructor;return s===void 0?t=xn(n,n.e<=o.toExpNeg||n.e>=o.toExpPos):(Ut(s,1,Gn),e===void 0?e=o.rounding:Ut(e,0,8),n=pe(new o(n),s,e),t=xn(n,s<=n.e||n.e<=o.toExpNeg,s)),n.isNeg()&&!n.isZero()?"-"+t:t};X.toSignificantDigits=X.toSD=function(s,e){var t=this,n=t.constructor;return s===void 0?(s=n.precision,e=n.rounding):(Ut(s,1,Gn),e===void 0?e=n.rounding:Ut(e,0,8)),pe(new n(t),s,e)};X.toString=function(){var s=this,e=s.constructor,t=xn(s,s.e<=e.toExpNeg||s.e>=e.toExpPos);return s.isNeg()&&!s.isZero()?"-"+t:t};X.truncated=X.trunc=function(){return pe(new this.constructor(this),this.e+1,1)};X.valueOf=X.toJSON=function(){var s=this,e=s.constructor,t=xn(s,s.e<=e.toExpNeg||s.e>=e.toExpPos);return s.isNeg()?"-"+t:t};function wt(s){var e,t,n,o=s.length-1,i="",r=s[0];if(o>0){for(i+=r,e=1;e<o;e++)n=s[e]+"",t=Ae-n.length,t&&(i+=Dn(t)),i+=n;r=s[e],n=r+"",t=Ae-n.length,t&&(i+=Dn(t))}else if(r===0)return"0";for(;r%10===0;)r/=10;return i+r}function Ut(s,e,t){if(s!==~~s||s<e||s>t)throw Error(Un+s)}function $o(s,e,t,n){var o,i,r,a;for(i=s[0];i>=10;i/=10)--e;return--e<0?(e+=Ae,o=0):(o=Math.ceil((e+1)/Ae),e%=Ae),i=mt(10,Ae-e),a=s[o]%i|0,n==null?e<3?(e==0?a=a/100|0:e==1&&(a=a/10|0),r=t<4&&a==99999||t>3&&a==49999||a==5e4||a==0):r=(t<4&&a+1==i||t>3&&a+1==i/2)&&(s[o+1]/i/100|0)==mt(10,e-2)-1||(a==i/2||a==0)&&(s[o+1]/i/100|0)==0:e<4?(e==0?a=a/1e3|0:e==1?a=a/100|0:e==2&&(a=a/10|0),r=(n||t<4)&&a==9999||!n&&t>3&&a==4999):r=((n||t<4)&&a+1==i||!n&&t>3&&a+1==i/2)&&(s[o+1]/i/1e3|0)==mt(10,e-3)-1,r}function er(s,e,t){for(var n,o=[0],i,r=0,a=s.length;r<a;){for(i=o.length;i--;)o[i]*=e;for(o[0]+=cs.indexOf(s.charAt(r++)),n=0;n<o.length;n++)o[n]>t-1&&(o[n+1]===void 0&&(o[n+1]=0),o[n+1]+=o[n]/t|0,o[n]%=t)}return o.reverse()}function om(s,e){var t,n,o;if(e.isZero())return e;n=e.d.length,n<32?(t=Math.ceil(n/3),o=(1/ar(4,t)).toString()):(t=16,o="2.3283064365386962890625e-10"),s.precision+=t,e=Co(s,1,e.times(o),new s(1));for(var i=t;i--;){var r=e.times(e);e=r.times(r).minus(r).times(8).plus(1)}return s.precision-=t,e}var Xe=function(){function s(n,o,i){var r,a=0,c=n.length;for(n=n.slice();c--;)r=n[c]*o+a,n[c]=r%i|0,a=r/i|0;return a&&n.unshift(a),n}function e(n,o,i,r){var a,c;if(i!=r)c=i>r?1:-1;else for(a=c=0;a<i;a++)if(n[a]!=o[a]){c=n[a]>o[a]?1:-1;break}return c}function t(n,o,i,r){for(var a=0;i--;)n[i]-=a,a=n[i]<o[i]?1:0,n[i]=a*r+n[i]-o[i];for(;!n[0]&&n.length>1;)n.shift()}return function(n,o,i,r,a,c){var u,l,m,d,p,f,y,b,g,P,w,T,h,k,B,x,S,I,C,N,L=n.constructor,v=n.s==o.s?1:-1,R=n.d,M=o.d;if(!R||!R[0]||!M||!M[0])return new L(!n.s||!o.s||(R?M&&R[0]==M[0]:!M)?NaN:R&&R[0]==0||!M?v*0:v/0);for(c?(p=1,l=n.e-o.e):(c=mn,p=Ae,l=Bt(n.e/p)-Bt(o.e/p)),C=M.length,S=R.length,g=new L(v),P=g.d=[],m=0;M[m]==(R[m]||0);m++);if(M[m]>(R[m]||0)&&l--,i==null?(k=i=L.precision,r=L.rounding):a?k=i+(n.e-o.e)+1:k=i,k<0)P.push(1),f=!0;else{if(k=k/p+2|0,m=0,C==1){for(d=0,M=M[0],k++;(m<S||d)&&k--;m++)B=d*c+(R[m]||0),P[m]=B/M|0,d=B%M|0;f=d||m<S}else{for(d=c/(M[0]+1)|0,d>1&&(M=s(M,d,c),R=s(R,d,c),C=M.length,S=R.length),x=C,w=R.slice(0,C),T=w.length;T<C;)w[T++]=0;N=M.slice(),N.unshift(0),I=M[0],M[1]>=c/2&&++I;do d=0,u=e(M,w,C,T),u<0?(h=w[0],C!=T&&(h=h*c+(w[1]||0)),d=h/I|0,d>1?(d>=c&&(d=c-1),y=s(M,d,c),b=y.length,T=w.length,u=e(y,w,b,T),u==1&&(d--,t(y,C<b?N:M,b,c))):(d==0&&(u=d=1),y=M.slice()),b=y.length,b<T&&y.unshift(0),t(w,y,T,c),u==-1&&(T=w.length,u=e(M,w,C,T),u<1&&(d++,t(w,C<T?N:M,T,c))),T=w.length):u===0&&(d++,w=[0]),P[m++]=d,u&&w[0]?w[T++]=R[x]||0:(w=[R[x]],T=1);while((x++<S||w[0]!==void 0)&&k--);f=w[0]!==void 0}P[0]||P.shift()}if(p==1)g.e=l,yu=f;else{for(m=1,d=P[0];d>=10;d/=10)m++;g.e=m+l*p-1,pe(g,a?i+g.e+1:i,r,f)}return g}}();function pe(s,e,t,n){var o,i,r,a,c,u,l,m,d,p=s.constructor;e:if(e!=null){if(m=s.d,!m)return s;for(o=1,a=m[0];a>=10;a/=10)o++;if(i=e-o,i<0)i+=Ae,r=e,l=m[d=0],c=l/mt(10,o-r-1)%10|0;else if(d=Math.ceil((i+1)/Ae),a=m.length,d>=a)if(n){for(;a++<=d;)m.push(0);l=c=0,o=1,i%=Ae,r=i-Ae+1}else break e;else{for(l=a=m[d],o=1;a>=10;a/=10)o++;i%=Ae,r=i-Ae+o,c=r<0?0:l/mt(10,o-r-1)%10|0}if(n=n||e<0||m[d+1]!==void 0||(r<0?l:l%mt(10,o-r-1)),u=t<4?(c||n)&&(t==0||t==(s.s<0?3:2)):c>5||c==5&&(t==4||n||t==6&&(i>0?r>0?l/mt(10,o-r):0:m[d-1])%10&1||t==(s.s<0?8:7)),e<1||!m[0])return m.length=0,u?(e-=s.e+1,m[0]=mt(10,(Ae-e%Ae)%Ae),s.e=-e||0):m[0]=s.e=0,s;if(i==0?(m.length=d,a=1,d--):(m.length=d+1,a=mt(10,Ae-i),m[d]=r>0?(l/mt(10,o-r)%mt(10,r)|0)*a:0),u)for(;;)if(d==0){for(i=1,r=m[0];r>=10;r/=10)i++;for(r=m[0]+=a,a=1;r>=10;r/=10)a++;i!=a&&(s.e++,m[0]==mn&&(m[0]=1));break}else{if(m[d]+=a,m[d]!=mn)break;m[d--]=0,a=1}for(i=m.length;m[--i]===0;)m.pop()}return Te&&(s.e>p.maxE?(s.d=null,s.e=NaN):s.e<p.minE&&(s.e=0,s.d=[0])),s}function xn(s,e,t){if(!s.isFinite())return Tu(s);var n,o=s.e,i=wt(s.d),r=i.length;return e?(t&&(n=t-r)>0?i=i.charAt(0)+"."+i.slice(1)+Dn(n):r>1&&(i=i.charAt(0)+"."+i.slice(1)),i=i+(s.e<0?"e":"e+")+s.e):o<0?(i="0."+Dn(-o-1)+i,t&&(n=t-r)>0&&(i+=Dn(n))):o>=r?(i+=Dn(o+1-r),t&&(n=t-o-1)>0&&(i=i+"."+Dn(n))):((n=o+1)<r&&(i=i.slice(0,n)+"."+i.slice(n)),t&&(n=t-r)>0&&(o+1===r&&(i+="."),i+=Dn(n))),i}function sr(s,e){var t=s[0];for(e*=Ae;t>=10;t/=10)e++;return e}function ir(s,e,t){if(e>nm)throw Te=!0,t&&(s.precision=t),Error(bu);return pe(new s(nr),e,1,!0)}function Bn(s,e,t){if(e>ms)throw Error(bu);return pe(new s(or),e,t,!0)}function wu(s){var e=s.length-1,t=e*Ae+1;if(e=s[e],e){for(;e%10==0;e/=10)t--;for(e=s[0];e>=10;e/=10)t++}return t}function Dn(s){for(var e="";s--;)e+="0";return e}function ku(s,e,t,n){var o,i=new s(1),r=Math.ceil(n/Ae+4);for(Te=!1;;){if(t%2&&(i=i.times(e),pu(i.d,r)&&(o=!0)),t=Bt(t/2),t===0){t=i.d.length-1,o&&i.d[t]===0&&++i.d[t];break}e=e.times(e),pu(e.d,r)}return Te=!0,i}function du(s){return s.d[s.d.length-1]&1}function hu(s,e,t){for(var n,o,i=new s(e[0]),r=0;++r<e.length;){if(o=new s(e[r]),!o.s){i=o;break}n=i.cmp(o),(n===t||n===0&&i.s===t)&&(i=o)}return i}function ds(s,e){var t,n,o,i,r,a,c,u=0,l=0,m=0,d=s.constructor,p=d.rounding,f=d.precision;if(!s.d||!s.d[0]||s.e>17)return new d(s.d?s.d[0]?s.s<0?0:1/0:1:s.s?s.s<0?0:s:0/0);for(e==null?(Te=!1,c=f):c=e,a=new d(.03125);s.e>-2;)s=s.times(a),m+=5;for(n=Math.log(mt(2,m))/Math.LN10*2+5|0,c+=n,t=i=r=new d(1),d.precision=c;;){if(i=pe(i.times(s),c,1),t=t.times(++l),a=r.plus(Xe(i,t,c,1)),wt(a.d).slice(0,c)===wt(r.d).slice(0,c)){for(o=m;o--;)r=pe(r.times(r),c,1);if(e==null)if(u<3&&$o(r.d,c-n,p,u))d.precision=c+=10,t=i=a=new d(1),l=0,u++;else return pe(r,d.precision=f,p,Te=!0);else return d.precision=f,r}r=a}}function qn(s,e){var t,n,o,i,r,a,c,u,l,m,d,p=1,f=10,y=s,b=y.d,g=y.constructor,P=g.rounding,w=g.precision;if(y.s<0||!b||!b[0]||!y.e&&b[0]==1&&b.length==1)return new g(b&&!b[0]?-1/0:y.s!=1?NaN:b?0:y);if(e==null?(Te=!1,l=w):l=e,g.precision=l+=f,t=wt(b),n=t.charAt(0),Math.abs(i=y.e)<15e14){for(;n<7&&n!=1||n==1&&t.charAt(1)>3;)y=y.times(s),t=wt(y.d),n=t.charAt(0),p++;i=y.e,n>1?(y=new g("0."+t),i++):y=new g(n+"."+t.slice(1))}else return u=ir(g,l+2,w).times(i+""),y=qn(new g(n+"."+t.slice(1)),l-f).plus(u),g.precision=w,e==null?pe(y,w,P,Te=!0):y;for(m=y,c=r=y=Xe(y.minus(1),y.plus(1),l,1),d=pe(y.times(y),l,1),o=3;;){if(r=pe(r.times(d),l,1),u=c.plus(Xe(r,new g(o),l,1)),wt(u.d).slice(0,l)===wt(c.d).slice(0,l))if(c=c.times(2),i!==0&&(c=c.plus(ir(g,l+2,w).times(i+""))),c=Xe(c,new g(p),l,1),e==null)if($o(c.d,l-f,P,a))g.precision=l+=f,u=r=y=Xe(m.minus(1),m.plus(1),l,1),d=pe(y.times(y),l,1),o=a=1;else return pe(c,g.precision=w,P,Te=!0);else return g.precision=w,c;c=u,o+=2}}function Tu(s){return String(s.s*s.s/0)}function tr(s,e){var t,n,o;for((t=e.indexOf("."))>-1&&(e=e.replace(".","")),(n=e.search(/e/i))>0?(t<0&&(t=n),t+=+e.slice(n+1),e=e.substring(0,n)):t<0&&(t=e.length),n=0;e.charCodeAt(n)===48;n++);for(o=e.length;e.charCodeAt(o-1)===48;--o);if(e=e.slice(n,o),e){if(o-=n,s.e=t=t-n-1,s.d=[],n=(t+1)%Ae,t<0&&(n+=Ae),n<o){for(n&&s.d.push(+e.slice(0,n)),o-=Ae;n<o;)s.d.push(+e.slice(n,n+=Ae));e=e.slice(n),n=Ae-e.length}else n-=o;for(;n--;)e+="0";s.d.push(+e),Te&&(s.e>s.constructor.maxE?(s.d=null,s.e=NaN):s.e<s.constructor.minE&&(s.e=0,s.d=[0]))}else s.e=0,s.d=[0];return s}function im(s,e){var t,n,o,i,r,a,c,u,l;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),Au.test(e))return tr(s,e)}else if(e==="Infinity"||e==="NaN")return+e||(s.s=NaN),s.e=NaN,s.d=null,s;if(Jl.test(e))t=16,e=e.toLowerCase();else if(Zl.test(e))t=2;else if(em.test(e))t=8;else throw Error(Un+e);for(i=e.search(/p/i),i>0?(c=+e.slice(i+1),e=e.substring(2,i)):e=e.slice(2),i=e.indexOf("."),r=i>=0,n=s.constructor,r&&(e=e.replace(".",""),a=e.length,i=a-i,o=ku(n,new n(t),i,i*2)),u=er(e,t,mn),l=u.length-1,i=l;u[i]===0;--i)u.pop();return i<0?new n(s.s*0):(s.e=sr(u,l),s.d=u,Te=!1,r&&(s=Xe(s,o,a*4)),c&&(s=s.times(Math.abs(c)<54?mt(2,c):Zo.pow(2,c))),Te=!0,s)}function rm(s,e){var t,n=e.d.length;if(n<3)return e.isZero()?e:Co(s,2,e,e);t=1.4*Math.sqrt(n),t=t>16?16:t|0,e=e.times(1/ar(5,t)),e=Co(s,2,e,e);for(var o,i=new s(5),r=new s(16),a=new s(20);t--;)o=e.times(e),e=e.times(i.plus(o.times(r.times(o).minus(a))));return e}function Co(s,e,t,n,o){var i,r,a,c,u=1,l=s.precision,m=Math.ceil(l/Ae);for(Te=!1,c=t.times(t),a=new s(n);;){if(r=Xe(a.times(c),new s(e++*e++),l,1),a=o?n.plus(r):n.minus(r),n=Xe(r.times(c),new s(e++*e++),l,1),r=a.plus(n),r.d[m]!==void 0){for(i=m;r.d[i]===a.d[i]&&i--;);if(i==-1)break}i=a,a=n,n=r,r=i,u++}return Te=!0,r.d.length=m+1,r}function ar(s,e){for(var t=s;--e;)t*=s;return t}function Iu(s,e){var t,n=e.s<0,o=Bn(s,s.precision,1),i=o.times(.5);if(e=e.abs(),e.lte(i))return Ln=n?4:1,e;if(t=e.divToInt(o),t.isZero())Ln=n?3:2;else{if(e=e.minus(t.times(o)),e.lte(i))return Ln=du(t)?n?2:3:n?4:1,e;Ln=du(t)?n?1:4:n?3:2}return e.minus(o).abs()}function ps(s,e,t,n){var o,i,r,a,c,u,l,m,d,p=s.constructor,f=t!==void 0;if(f?(Ut(t,1,Gn),n===void 0?n=p.rounding:Ut(n,0,8)):(t=p.precision,n=p.rounding),!s.isFinite())l=Tu(s);else{for(l=xn(s),r=l.indexOf("."),f?(o=2,e==16?t=t*4-3:e==8&&(t=t*3-2)):o=e,r>=0&&(l=l.replace(".",""),d=new p(1),d.e=l.length-r,d.d=er(xn(d),10,o),d.e=d.d.length),m=er(l,10,o),i=c=m.length;m[--c]==0;)m.pop();if(!m[0])l=f?"0p+0":"0";else{if(r<0?i--:(s=new p(s),s.d=m,s.e=i,s=Xe(s,d,t,n,0,o),m=s.d,i=s.e,u=yu),r=m[t],a=o/2,u=u||m[t+1]!==void 0,u=n<4?(r!==void 0||u)&&(n===0||n===(s.s<0?3:2)):r>a||r===a&&(n===4||u||n===6&&m[t-1]&1||n===(s.s<0?8:7)),m.length=t,u)for(;++m[--t]>o-1;)m[t]=0,t||(++i,m.unshift(1));for(c=m.length;!m[c-1];--c);for(r=0,l="";r<c;r++)l+=cs.charAt(m[r]);if(f){if(c>1)if(e==16||e==8){for(r=e==16?4:3,--c;c%r;c++)l+="0";for(m=er(l,o,e),c=m.length;!m[c-1];--c);for(r=1,l="1.";r<c;r++)l+=cs.charAt(m[r])}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=(e==16?"0x":e==2?"0b":e==8?"0o":"")+l}return s.s<0?"-"+l:l}function pu(s,e){if(s.length>e)return s.length=e,!0}function sm(s){return new this(s).abs()}function am(s){return new this(s).acos()}function um(s){return new this(s).acosh()}function cm(s,e){return new this(s).plus(e)}function lm(s){return new this(s).asin()}function mm(s){return new this(s).asinh()}function dm(s){return new this(s).atan()}function pm(s){return new this(s).atanh()}function fm(s,e){s=new this(s),e=new this(e);var t,n=this.precision,o=this.rounding,i=n+4;return!s.s||!e.s?t=new this(NaN):!s.d&&!e.d?(t=Bn(this,i,1).times(e.s>0?.25:.75),t.s=s.s):!e.d||s.isZero()?(t=e.s<0?Bn(this,n,o):new this(0),t.s=s.s):!s.d||e.isZero()?(t=Bn(this,i,1).times(.5),t.s=s.s):e.s<0?(this.precision=i,this.rounding=1,t=this.atan(Xe(s,e,i,1)),e=Bn(this,i,1),this.precision=n,this.rounding=o,t=s.s<0?t.minus(e):t.plus(e)):t=this.atan(Xe(s,e,i,1)),t}function ym(s){return new this(s).cbrt()}function bm(s){return pe(s=new this(s),s.e+1,2)}function gm(s,e,t){return new this(s).clamp(e,t)}function Pm(s){if(!s||typeof s!="object")throw Error(rr+"Object expected");var e,t,n,o=s.defaults===!0,i=["precision",1,Gn,"rounding",0,8,"toExpNeg",-Ko,0,"toExpPos",0,Ko,"maxE",0,Ko,"minE",-Ko,0,"modulo",0,9];for(e=0;e<i.length;e+=3)if(t=i[e],o&&(this[t]=ls[t]),(n=s[t])!==void 0)if(Bt(n)===n&&n>=i[e+1]&&n<=i[e+2])this[t]=n;else throw Error(Un+t+": "+n);if(t="crypto",o&&(this[t]=ls[t]),(n=s[t])!==void 0)if(n===!0||n===!1||n===0||n===1)if(n)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[t]=!0;else throw Error(gu);else this[t]=!1;else throw Error(Un+t+": "+n);return this}function Am(s){return new this(s).cos()}function wm(s){return new this(s).cosh()}function Bu(s){var e,t,n;function o(i){var r,a,c,u=this;if(!(u instanceof o))return new o(i);if(u.constructor=o,fu(i)){u.s=i.s,Te?!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(r=0,a=i;a>=10;a/=10)r++;Te?r>o.maxE?(u.e=NaN,u.d=null):r<o.minE?(u.e=0,u.d=[0]):(u.e=r,u.d=[i]):(u.e=r,u.d=[i]);return}if(i*0!==0){i||(u.s=NaN),u.e=NaN,u.d=null;return}return tr(u,i.toString())}if(c==="string")return(a=i.charCodeAt(0))===45?(i=i.slice(1),u.s=-1):(a===43&&(i=i.slice(1)),u.s=1),Au.test(i)?tr(u,i):im(u,i);if(c==="bigint")return i<0?(i=-i,u.s=-1):u.s=1,tr(u,i.toString());throw Error(Un+i)}if(o.prototype=X,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=Pm,o.clone=Bu,o.isDecimal=fu,o.abs=sm,o.acos=am,o.acosh=um,o.add=cm,o.asin=lm,o.asinh=mm,o.atan=dm,o.atanh=pm,o.atan2=fm,o.cbrt=ym,o.ceil=bm,o.clamp=gm,o.cos=Am,o.cosh=wm,o.div=km,o.exp=hm,o.floor=Tm,o.hypot=Im,o.ln=Bm,o.log=xm,o.log10=Km,o.log2=Sm,o.max=Cm,o.min=Rm,o.mod=Lm,o.mul=Nm,o.pow=Om,o.random=vm,o.round=Mm,o.sign=Fm,o.sin=Vm,o.sinh=_m,o.sqrt=Em,o.sub=Wm,o.sum=Dm,o.tan=qm,o.tanh=Um,o.trunc=Gm,s===void 0&&(s={}),s&&s.defaults!==!0)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<n.length;)s.hasOwnProperty(t=n[e++])||(s[t]=this[t]);return o.config(s),o}function km(s,e){return new this(s).div(e)}function hm(s){return new this(s).exp()}function Tm(s){return pe(s=new this(s),s.e+1,3)}function Im(){var s,e,t=new this(0);for(Te=!1,s=0;s<arguments.length;)if(e=new this(arguments[s++]),e.d)t.d&&(t=t.plus(e.times(e)));else{if(e.s)return Te=!0,new this(1/0);t=e}return Te=!0,t.sqrt()}function fu(s){return s instanceof Zo||s&&s.toStringTag===Pu||!1}function Bm(s){return new this(s).ln()}function xm(s,e){return new this(s).log(e)}function Sm(s){return new this(s).log(2)}function Km(s){return new this(s).log(10)}function Cm(){return hu(this,arguments,-1)}function Rm(){return hu(this,arguments,1)}function Lm(s,e){return new this(s).mod(e)}function Nm(s,e){return new this(s).mul(e)}function Om(s,e){return new this(s).pow(e)}function vm(s){var e,t,n,o,i=0,r=new this(1),a=[];if(s===void 0?s=this.precision:Ut(s,1,Gn),n=Math.ceil(s/Ae),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(n));i<n;)o=e[i],o>=429e7?e[i]=crypto.getRandomValues(new Uint32Array(1))[0]:a[i++]=o%1e7;else if(crypto.randomBytes){for(e=crypto.randomBytes(n*=4);i<n;)o=e[i]+(e[i+1]<<8)+(e[i+2]<<16)+((e[i+3]&127)<<24),o>=214e7?crypto.randomBytes(4).copy(e,i):(a.push(o%1e7),i+=4);i=n/4}else throw Error(gu);else for(;i<n;)a[i++]=Math.random()*1e7|0;for(n=a[--i],s%=Ae,n&&s&&(o=mt(10,Ae-s),a[i]=(n/o|0)*o);a[i]===0;i--)a.pop();if(i<0)t=0,a=[0];else{for(t=-1;a[0]===0;t-=Ae)a.shift();for(n=1,o=a[0];o>=10;o/=10)n++;n<Ae&&(t-=Ae-n)}return r.e=t,r.d=a,r}function Mm(s){return pe(s=new this(s),s.e+1,this.rounding)}function Fm(s){return s=new this(s),s.d?s.d[0]?s.s:0*s.s:s.s||NaN}function Vm(s){return new this(s).sin()}function _m(s){return new this(s).sinh()}function Em(s){return new this(s).sqrt()}function Wm(s,e){return new this(s).sub(e)}function Dm(){var s=0,e=arguments,t=new this(e[s]);for(Te=!1;t.s&&++s<e.length;)t=t.plus(e[s]);return Te=!0,pe(t,this.precision,this.rounding)}function qm(s){return new this(s).tan()}function Um(s){return new this(s).tanh()}function Gm(s){return pe(s=new this(s),s.e+1,1)}X[Symbol.for("nodejs.util.inspect.custom")]=X.toString;X[Symbol.toStringTag]="Decimal";var Zo=X.constructor=Bu(ls);nr=new Zo(nr);or=new Zo(or);var O=Zo;var Lu=he(require("big.js")),ni=he(require("bn.js"));var xu=he(require("toformat")),Xm=xu.default,Jo=Xm;var ei=he(require("big.js")),Ku=he(require("bn.js")),Cu=he(require("decimal.js-light"));var Ro=he(require("bn.js"));var Su=9007199254740991;function ue(s){let e=xe("Raydium_parseBigNumberish");if(s instanceof Ro.default)return s;if(typeof s=="string"){if(s.match(/^-?[0-9]+$/))return new Ro.default(s);e.logWithError(`invalid BigNumberish string: ${s}`)}return typeof s=="number"?(s%1&&e.logWithError(`BigNumberish number underflow: ${s}`),(s>=Su||s<=-Su)&&e.logWithError(`BigNumberish number overflow: ${s}`),new Ro.default(String(s))):typeof s=="bigint"?new Ro.default(s.toString()):(e.error(`invalid BigNumberish value: ${s}`),new Ro.default(0))}var ur=xe("module/fraction"),fs=Jo(ei.default),ti=Jo(Cu.default),Ym={[0]:ti.ROUND_DOWN,[1]:ti.ROUND_HALF_UP,[2]:ti.ROUND_UP},Hm={[0]:ei.default.roundDown,[1]:ei.default.roundHalfUp,[2]:ei.default.roundUp},Ve=class{constructor(e,t=new Ku.default(1)){this.numerator=ue(e),this.denominator=ue(t)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new Ve(this.denominator,this.numerator)}add(e){let t=e instanceof Ve?e:new Ve(ue(e));return this.denominator.eq(t.denominator)?new Ve(this.numerator.add(t.numerator),this.denominator):new Ve(this.numerator.mul(t.denominator).add(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}sub(e){let t=e instanceof Ve?e:new Ve(ue(e));return this.denominator.eq(t.denominator)?new Ve(this.numerator.sub(t.numerator),this.denominator):new Ve(this.numerator.mul(t.denominator).sub(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}mul(e){let t=e instanceof Ve?e:new Ve(ue(e));return new Ve(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof Ve?e:new Ve(ue(e));return new Ve(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},n=1){Number.isInteger(e)||ur.logWithError(`${e} is not an integer.`),e<=0&&ur.logWithError(`${e} is not positive.`),ti.set({precision:e+1,rounding:Ym[n]});let o=new ti(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return o.toFormat(o.decimalPlaces(),t)}toFixed(e,t={groupSeparator:""},n=1){return Number.isInteger(e)||ur.logWithError(`${e} is not an integer.`),e<0&&ur.logWithError(`${e} is negative.`),fs.DP=e,fs.RM=Hm[n]||1,new fs(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};var Qm=xe("Raydium_amount"),Ru=Jo(Lu.default);function jm(s,e){let t="0",n="0";if(s.includes(".")){let o=s.split(".");o.length===2?([t,n]=o,n=n.padEnd(e,"0")):Qm.logWithError(`invalid number string, num: ${s}`)}else t=s;return[t,n.slice(0,e)||n]}var qe=class extends Ve{constructor(t,n,o=!0,i){let r=new ni.default(0),a=ys.pow(new ni.default(t.decimals));if(o)r=ue(n);else{let c=new ni.default(0),u=new ni.default(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[l,m]=jm(n.toString(),t.decimals);c=ue(l),u=ue(m)}c=c.mul(a),r=c.add(u)}super(r,a);this.logger=xe(i||"TokenAmount"),this.token=t}get raw(){return this.numerator}isZero(){return this.raw.isZero()}gt(t){return this.token.equals(t.token)||this.logger.logWithError("gt token not equals"),this.raw.gt(t.raw)}lt(t){return this.token.equals(t.token)||this.logger.logWithError("lt token not equals"),this.raw.lt(t.raw)}add(t){return this.token.equals(t.token)||this.logger.logWithError("add token not equals"),new qe(this.token,this.raw.add(t.raw))}subtract(t){return this.token.equals(t.token)||this.logger.logWithError("sub token not equals"),new qe(this.token,this.raw.sub(t.raw))}toSignificant(t=this.token.decimals,n,o=0){return super.toSignificant(t,n,o)}toFixed(t=this.token.decimals,n,o=0){return t>this.token.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(t,n,o)}toExact(t={groupSeparator:""}){return Ru.DP=this.token.decimals,new Ru(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)}};var Nu=require("@solana/web3.js"),bs=require("@solana/spl-token"),Xn={chainId:101,address:Nu.PublicKey.default.toBase58(),programId:bs.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"}},xt={chainId:101,address:"So11111111111111111111111111111111111111112",programId:bs.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 lr=require("@solana/web3.js");var Ee=require("@solana/web3.js"),Ou=require("@solana/spl-token");function K({pubkey:s,isSigner:e=!1,isWritable:t=!0}){return{pubkey:s,isWritable:t,isSigner:e}}var gs=[K({pubkey:Ou.TOKEN_PROGRAM_ID,isWritable:!1}),K({pubkey:Ee.SystemProgram.programId,isWritable:!1}),K({pubkey:Ee.SYSVAR_RENT_PUBKEY,isWritable:!1})];function Ps({publicKey:s,transformSol:e}){let t=As(s.toString());if(t instanceof Ee.PublicKey)return e&&t.equals(bt)?j:t;if(e&&t.toString()===bt.toBase58())return j;if(typeof t=="string"){if(t===Ee.PublicKey.default.toBase58())return Ee.PublicKey.default;try{return new Ee.PublicKey(t)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function As(s){try{return new Ee.PublicKey(s)}catch{return s}}var cr=new Ee.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),zn=new Ee.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),kt=new Ee.PublicKey("SysvarRent111111111111111111111111111111111"),vu=new Ee.PublicKey("SysvarC1ock11111111111111111111111111111111"),dn=new Ee.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),$m=new Ee.PublicKey("Sysvar1nstructions1111111111111111111111111"),ws=Ee.SystemProgram.programId,df=new Ee.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),pf=new Ee.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),ff=new Ee.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),yf=new Ee.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),bf=new Ee.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),gf=new Ee.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Pf=new Ee.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Af=new Ee.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),wf=new Ee.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),kf=new Ee.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),hf=new Ee.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),j=new Ee.PublicKey("So11111111111111111111111111111111111111112"),bt=Ee.PublicKey.default;function It(s){return Ps({publicKey:s,transformSol:!0})}var ks=class{constructor({mint:e,decimals:t,symbol:n,name:o,skipMint:i=!1,isToken2022:r=!1}){if(e===bt.toBase58()||e instanceof lr.PublicKey&&bt.equals(e)){this.decimals=xt.decimals,this.symbol=xt.symbol,this.name=xt.name,this.mint=new lr.PublicKey(xt.address),this.isToken2022=!1;return}this.decimals=t,this.symbol=n||e.toString().substring(0,6),this.name=o||e.toString().substring(0,6),this.mint=i?lr.PublicKey.default:Ps({publicKey:e}),this.isToken2022=r}equals(e){return this===e?!0:this.mint.equals(e.mint)}},Je=ks;Je.WSOL=new ks(q(V({},xt),{mint:xt.address}));var hs=class{constructor({decimals:e,symbol:t="UNKNOWN",name:n="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=n}equals(e){return this===e}},mr=hs;mr.SOL=new hs(Xn);var Fu=he(require("bn.js"));var Mu=new Ve(new Fu.default(100)),gt=class extends Ve{toSignificant(e=5,t,n){return this.mul(Mu).toSignificant(e,t,n)}toFixed(e=2,t,n){return this.mul(Mu).toFixed(e,t,n)}};var Zm=xe("Raydium_price"),Gt=class extends Ve{constructor(t){let{baseToken:n,quoteToken:o,numerator:i,denominator:r}=t;super(i,r);this.baseToken=n,this.quoteToken=o,this.scalar=new Ve(Ts(n.decimals),Ts(o.decimals))}get raw(){return new Ve(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new Gt({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numerator,numerator:this.denominator})}mul(t){this.quoteToken!==t.baseToken&&Zm.logWithError("mul token not equals");let n=super.mul(t);return new Gt({baseToken:this.baseToken,quoteToken:t.quoteToken,denominator:n.denominator,numerator:n.numerator})}toSignificant(t=this.quoteToken.decimals,n,o){return this.adjusted.toSignificant(t,n,o)}toFixed(t=this.quoteToken.decimals,n,o){return this.adjusted.toFixed(t,n,o)}};var Xt=new pn.default(0),Vu=new pn.default(1),uy=new pn.default(2),cy=new pn.default(3),ly=new pn.default(5),ys=new pn.default(10),my=new pn.default(100),dy=new pn.default(1e3),py=new pn.default(1e4);function Ts(s){return ys.pow(ue(s))}function dr(s,e){let t=s.divmod(e);return t.mod.isZero()?t.div:t.div.isNeg()?t.div.isubn(1):t.div.iaddn(1)}function oi(s,e,t){return s.mul(e).add(t).sub(new pn.default(1)).div(t)}function pr(s,e,t){return s.mul(e).div(t)}function as(s,e=1,t=[]){let n=[...s];if(e<=0)return t;for(;n.length;)t.push(n.splice(0,e));return t}var fn=class{constructor(e){this._owner=e}get publicKey(){return fn.isKeyPair(this._owner)?this._owner.publicKey:this._owner}get signer(){return fn.isKeyPair(this._owner)?this._owner:void 0}get isKeyPair(){return fn.isKeyPair(this._owner)}get isPublicKey(){return fn.isPublicKey(this._owner)}static isKeyPair(e){return e.secretKey!==void 0}static isPublicKey(e){return!fn.isKeyPair(e)}};var Du=require("@solana/web3.js"),qu=require("@solana/spl-token");var St=require("@solana/web3.js");var z={CreateAccount:"CreateAccount",InitAccount:"InitAccount",CreateATA:"CreateATA",CloseAccount:"CloseAccount",TransferAmount:"TransferAmount",InitMint:"InitMint",MintTo:"MintTo",InitMarket:"InitMarket",Util1216OwnerClaim:"Util1216OwnerClaim",SetComputeUnitPrice:"SetComputeUnitPrice",SetComputeUnitLimit:"SetComputeUnitLimit",ClmmCreatePool:"ClmmCreatePool",ClmmOpenPosition:"ClmmOpenPosition",ClmmIncreasePosition:"ClmmIncreasePosition",ClmmDecreasePosition:"ClmmDecreasePosition",ClmmClosePosition:"ClmmClosePosition",ClmmSwapBaseIn:"ClmmSwapBaseIn",ClmmSwapBaseOut:"ClmmSwapBaseOut",ClmmInitReward:"ClmmInitReward",ClmmSetReward:"ClmmSetReward",ClmmCollectReward:"ClmmCollectReward",ClmmLockPosition:"ClmmLockPosition",ClmmHarvestLockPosition:"ClmmHarvestLockPosition",AmmV4Swap:"AmmV4Swap",AmmV4AddLiquidity:"AmmV4AddLiquidity",AmmV4RemoveLiquidity:"AmmV4RemoveLiquidity",AmmV4SimulatePoolInfo:"AmmV4SimulatePoolInfo",AmmV4SwapBaseIn:"AmmV4SwapBaseIn",AmmV4SwapBaseOut:"AmmV4SwapBaseOut",AmmV4CreatePool:"AmmV4CreatePool",AmmV4InitPool:"AmmV4InitPool",AmmV5AddLiquidity:"AmmV5AddLiquidity",AmmV5RemoveLiquidity:"AmmV5RemoveLiquidity",AmmV5SimulatePoolInfo:"AmmV5SimulatePoolInfo",AmmV5SwapBaseIn:"AmmV5SwapBaseIn",AmmV5SwapBaseOut:"AmmV5SwapBaseOut",RouteSwap:"RouteSwap",RouteSwap1:"RouteSwap1",RouteSwap2:"RouteSwap2",FarmV3Deposit:"FarmV3Deposit",FarmV3Withdraw:"FarmV3Withdraw",FarmV3CreateLedger:"FarmV3CreateLedger",FarmV4Withdraw:"FarmV4Withdraw",FarmV5Deposit:"FarmV5Deposit",FarmV5Withdraw:"FarmV5Withdraw",FarmV5CreateLedger:"FarmV5CreateLedger",FarmV6Deposit:"FarmV6Deposit",FarmV6Withdraw:"FarmV6Withdraw",FarmV6Create:"FarmV6Create",FarmV6Restart:"FarmV6Restart",FarmV6CreatorAddReward:"FarmV6CreatorAddReward",FarmV6CreatorWithdraw:"FarmV6CreatorWithdraw",CpmmCreatePool:"CpmmCreatePool",CpmmAddLiquidity:"CpmmAddLiquidity",CpmmWithdrawLiquidity:"CpmmWithdrawLiquidity",CpmmSwapBaseIn:"CpmmSwapBaseIn",CpmmSwapBaseOut:"CpmmSwapBaseOut",CpmmLockLp:"CpmmLockLp",CpmmCollectLockFee:"CpmmCollectLockFee",TransferTip:"TransferTip"};var Eu=require("@solana/spl-token"),_u=xe("Raydium_txUtil"),Wu=1644;function fr(s){let e=[],t=[];return s.microLamports&&(e.push(St.ComputeBudgetProgram.setComputeUnitPrice({microLamports:s.microLamports})),t.push(z.SetComputeUnitPrice)),s.units&&(e.push(St.ComputeBudgetProgram.setComputeUnitLimit({units:s.units})),t.push(z.SetComputeUnitLimit)),{instructions:e,instructionTypes:t}}async function Lo(s,e){var n,o;let t=e!=null?e:"confirmed";return(o=await((n=s.getLatestBlockhash)==null?void 0:n.call(s,{commitment:t})))==null?void 0:o.blockhash}async function yr(s,e){return s.getSignatureStatuses([e]),new Promise((t,n)=>{let o=setTimeout(n,6e4);s.onSignature(e,i=>{if(clearTimeout(o),!i.err){t("");return}n(Object.assign(i.err,{txId:e}))},"confirmed")})}function Is(s,e){s.length<1&&_u.logWithError(`no instructions provided: ${s.toString()}`),e.length<1&&_u.logWithError(`no signers provided:, ${e.toString()}`);let t=new St.Transaction;t.recentBlockhash="11111111111111111111111111111111",t.feePayer=e[0],t.add(...s);try{return Buffer.from(t.serialize({verifySignatures:!1})).toString("base64").length<Wu}catch{return!1}}function we(s,e){let[t,n]=St.PublicKey.findProgramAddressSync(s,e);return{publicKey:t,nonce:n}}function ii({instructions:s,payer:e,signers:t}){return Is(s,[e,...t])}function ri({instructions:s,payer:e,lookupTableAddressAccount:t,recentBlockhash:n=St.Keypair.generate().publicKey.toString()}){let i=new St.TransactionMessage({payerKey:e,recentBlockhash:n,instructions:s}).compileToV0Message(Object.values(t!=null?t:{}));try{return Buffer.from(new St.VersionedTransaction(i).serialize()).toString("base64").length<Wu}catch{return!1}}var Jm=s=>Buffer.isBuffer(s)?s:s instanceof Uint8Array?Buffer.from(s.buffer,s.byteOffset,s.byteLength):Buffer.from(s),ed=s=>{let e=s.serialize({requireAllSignatures:!1,verifySignatures:!1});s instanceof St.VersionedTransaction&&(e=Jm(e));try{return e instanceof Buffer?e.toString("base64"):Buffe