UNPKG

@raydium-io/raydium-sdk-v2

Version:

An SDK for building applications on top of Raydium.

1 lines 458 kB
var tm=Object.defineProperty,nm=Object.defineProperties;var om=Object.getOwnPropertyDescriptors;var $i=Object.getOwnPropertySymbols;var yu=Object.prototype.hasOwnProperty,bu=Object.prototype.propertyIsEnumerable;var fu=(s,e,t)=>e in s?tm(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,V=(s,e)=>{for(var t in e||(e={}))yu.call(e,t)&&fu(s,t,e[t]);if($i)for(var t of $i(e))bu.call(e,t)&&fu(s,t,e[t]);return s},q=(s,e)=>nm(s,om(e));var Xe=(s,e)=>{var t={};for(var n in s)yu.call(s,n)&&e.indexOf(n)<0&&(t[n]=s[n]);if(s!=null&&$i)for(var n of $i(s))e.indexOf(n)<0&&bu.call(s,n)&&(t[n]=s[n]);return t};import{merge as ly}from"lodash";import nc from"axios";import{PublicKey as Au}from"@solana/web3.js";import{get as gu,set as im}from"lodash";var ps=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}},Pu={},rm={};function he(s){let e=gu(Pu,s);if(!e){let t=gu(rm,s);e=new ps({name:s,logLevel:t}),im(Pu,s,e)}return e}import{MINT_SIZE as sm,TOKEN_PROGRAM_ID as am,getTransferFeeConfig as um,unpackMint as cm}from"@solana/spl-token";var fs=he("Raydium_accountInfo_util");async function on(s,e,t){let{batchRequest:n,commitment:o="confirmed",chunkCount:i=100}=V({batchRequest:!1},t),r=ys(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=ys(c,10);a=(await(await Promise.all(u.map(async m=>await s._rpcBatchRequest(m)))).flat()).map(m=>(m.error&&fs.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"&&fs.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(p[0],"base64"),executable:f,lamports:y,owner:new Au(b),rentEpoch:g}}return null})))}else try{a=await Promise.all(r.map(c=>s.getMultipleAccountsInfo(c,o)))}catch(c){c instanceof Error&&fs.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return a.flat()}async function Ee(s,e,t){let n=await on(s,e.map(o=>o.pubkey),t);return e.map((o,i)=>q(V({},o),{accountInfo:n[i]}))}async function xo({connection:s,mints:e,config:t}){var i,r,a;if(e.length===0)return{};let n=await Ee(s,e.map(c=>({pubkey:Pt(c)})),t),o={};for(let c of n){if(!c.accountInfo||c.accountInfo.data.length<sm){console.log("invalid mint account",c.pubkey.toBase58());continue}let u=cm(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)||am,feeConfig:(a=um(u))!=null?a:void 0})}return o[Au.default.toBase58()]=o[$.toBase58()],o}import gn from"bn.js";var So=9e15,Vn=1e9,bs="0123456789abcdef",er="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",tr="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",gs={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-So,maxE:So,crypto:!1},Tu,kn,Pe=!0,or="[DecimalError] ",Fn=or+"Invalid argument: ",Iu=or+"Precision limit exceeded",Bu=or+"crypto unavailable",xu="[object Decimal]",At=Math.floor,rt=Math.pow,lm=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,mm=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,dm=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Su=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,rn=1e7,fe=7,pm=9007199254740991,fm=er.length-1,Ps=tr.length-1,X={toStringTag:xu};X.absoluteValue=X.abs=function(){var s=new this.constructor(this);return s.s<0&&(s.s=1),ae(s)};X.ceil=function(){return ae(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(Fn+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())+fe,n.rounding=1,t=ym(n,Nu(n,t)),n.precision=s,n.rounding=e,ae(kn==2||kn==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(Pe=!1,i=l.s*rt(l.s*l,1/3),!i||Math.abs(i)==1/0?(t=pt(l.d),s=l.e,(i=(s-t.length+1)%3)&&(t+=i==1||i==-2?"0":"00"),i=rt(t,1/3),s=At((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=_e(u.plus(l).times(a),u.plus(c),r+2,1),pt(a.d).slice(0,r)===(t=pt(n.d)).slice(0,r))if(t=t.slice(r-3,r+1),t=="9999"||!o&&t=="4999"){if(!o&&(ae(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")&&(ae(n,s+1,1),e=!n.times(n).times(n).eq(l));break}return Pe=!0,ae(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-At(this.e/fe))*fe,s=e[s],s)for(;s%10==0;s/=10)t--;t<0&&(t=0)}return t};X.dividedBy=X.div=function(s){return _e(this,new this.constructor(s))};X.dividedToIntegerBy=X.divToInt=function(s){var e=this,t=e.constructor;return ae(_e(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 ae(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/rr(4,s)).toString()):(s=16,e="2.3283064365386962890625e-10"),i=Ko(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 ae(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=Ko(i,2,o,o,!0);else{s=1.4*Math.sqrt(n),s=s>16?16:s|0,o=o.times(1/rr(5,s)),o=Ko(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,ae(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,_e(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()?yn(e,n,o):new e(0):new e(NaN):s.isZero()?yn(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,Pe=!1,t=t.times(t).minus(1).sqrt().plus(t),Pe=!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,Pe=!1,t=t.times(t).plus(1).sqrt().plus(t),Pe=!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?ae(new i(o),s,e,!0):(i.precision=t=n-o.e,o=_e(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=yn(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<=Ps)return r=yn(l,m+4,d).times(.25),r.s=u.s,r}else{if(!u.s)return new l(NaN);if(m+4<=Ps)return r=yn(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/fe+2|0),s=t;s;--s)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(Pe=!1,e=Math.ceil(a/fe),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)),Pe=!0,ae(r,l.precision=m,l.rounding=d,!0)};X.isFinite=function(){return!!this.d};X.isInteger=X.isInt=function(){return!!this.d&&At(this.e/fe)>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(Pe=!1,a=m+p,r=Mn(u,a),n=e?nr(l,a+10):Mn(s,a),c=_e(r,n,a,1),Ho(c.d,o=m,d))do if(a+=10,r=Mn(u,a),n=e?nr(l,a+10):Mn(s,a),c=_e(r,n,a,1),!i){+pt(c.d).slice(o+1,o+15)+1==1e14&&(c=ae(c,m+1,0));break}while(Ho(c.d,o+=10,d));return Pe=!0,ae(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 Pe?ae(s,a,c):s}if(t=At(s.e/fe),l=At(p.e/fe),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/fe),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]=rn-1;--u[o],u[n]+=rn}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=ir(u,t),Pe?ae(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]?ae(new n(t),n.precision,n.rounding):(Pe=!1,n.modulo==9?(e=_e(t,s.abs(),0,3,1),e.s*=s.s):e=_e(t,s,0,n.modulo,1),e=e.times(s),Pe=!0,t.minus(e))};X.naturalExponential=X.exp=function(){return As(this)};X.naturalLogarithm=X.ln=function(){return Mn(this)};X.negated=X.neg=function(){var s=new this.constructor(this);return s.s=-s.s,ae(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)),Pe?ae(s,a,c):s;if(i=At(m.e/fe),n=At(s.e/fe),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/fe),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)/rn|0,u[o]%=rn;for(e&&(u.unshift(e),++n),r=u.length;u[--r]==0;)u.pop();return s.d=u,s.e=ir(u,n),Pe?ae(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(Fn+s);return t.d?(e=Ku(t.d),s&&t.e+1>e&&(e=t.e+1)):e=NaN,e};X.round=function(){var s=this,e=s.constructor;return ae(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())+fe,n.rounding=1,t=gm(n,Nu(n,t)),n.precision=s,n.rounding=e,ae(kn>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(Pe=!1,u=Math.sqrt(+r),u==0||u==1/0?(e=pt(a),(e.length+c)%2==0&&(e+="0"),u=Math.sqrt(e),c=At((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(_e(r,i,t+2,1)).times(.5),pt(i.d).slice(0,t)===(e=pt(n.d)).slice(0,t))if(e=e.slice(t-3,t+1),e=="9999"||!o&&e=="4999"){if(!o&&(ae(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")&&(ae(n,c+1,1),s=!n.times(n).eq(r));break}return Pe=!0,ae(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=_e(t,new n(1).minus(t.times(t)).sqrt(),s+10,0),n.precision=s,n.rounding=e,ae(kn==2||kn==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=At(l.e/fe)+At(s.e/fe),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%rn|0,e=a/rn|0;i[o]=(i[o]+e)%rn|0}for(;!i[--r];)i.pop();return e?++t:i.shift(),s.d=i,s.e=ir(i,t),Pe?ae(s,m.precision,m.rounding):s};X.toBinary=function(s,e){return ws(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:(vt(s,0,Vn),e===void 0?e=n.rounding:vt(e,0,8),ae(t,s+t.e+1,e))};X.toExponential=function(s,e){var t,n=this,o=n.constructor;return s===void 0?t=bn(n,!0):(vt(s,0,Vn),e===void 0?e=o.rounding:vt(e,0,8),n=ae(new o(n),s+1,e),t=bn(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=bn(o):(vt(s,0,Vn),e===void 0?e=i.rounding:vt(e,0,8),n=ae(new i(o),s+o.e+1,e),t=bn(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=Ku(f)-p.e-1,r=i%fe,e.d[0]=rt(10,r<0?fe+r:r),s==null)s=i>0?e:u;else{if(a=new y(s),!a.isInt()||a.lt(u))throw Error(Fn+a);s=a.gt(e)?i>0?e:u:a}for(Pe=!1,a=new y(pt(f)),l=y.precision,y.precision=i=f.length*fe*2;m=_e(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=_e(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=_e(u,n,i,1).minus(p).abs().cmp(_e(c,t,i,1).minus(p).abs())<1?[u,n]:[c,t],y.precision=l,Pe=!0,d};X.toHexadecimal=X.toHex=function(s,e){return ws(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:vt(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]?(Pe=!1,t=_e(t,s,0,e,1).times(s),Pe=!0,ae(t)):(s.s=t.s,t=s),t};X.toNumber=function(){return+this};X.toOctal=function(s,e){return ws(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(rt(+a,u));if(a=new c(a),a.eq(1))return a;if(n=c.precision,i=c.rounding,s.eq(1))return ae(a,n,i);if(e=At(s.e/fe),e>=s.d.length-1&&(t=u<0?-u:u)<=pm)return o=Cu(c,a,t,n),s.s<0?new c(1).div(o):ae(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=rt(+a,u),e=t==0||!isFinite(t)?At(u*(Math.log("0."+pt(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):(Pe=!1,c.rounding=a.s=1,t=Math.min(12,(e+"").length),o=As(s.times(Mn(a,n+t)),n),o.d&&(o=ae(o,n+5,1),Ho(o.d,n,i)&&(e=n+10,o=ae(As(s.times(Mn(a,e+t)),e),e+5,1),+pt(o.d).slice(n+1,n+15)+1==1e14&&(o=ae(o,n+1,0)))),o.s=r,Pe=!0,c.rounding=i,ae(o,n,i))};X.toPrecision=function(s,e){var t,n=this,o=n.constructor;return s===void 0?t=bn(n,n.e<=o.toExpNeg||n.e>=o.toExpPos):(vt(s,1,Vn),e===void 0?e=o.rounding:vt(e,0,8),n=ae(new o(n),s,e),t=bn(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):(vt(s,1,Vn),e===void 0?e=n.rounding:vt(e,0,8)),ae(new n(t),s,e)};X.toString=function(){var s=this,e=s.constructor,t=bn(s,s.e<=e.toExpNeg||s.e>=e.toExpPos);return s.isNeg()&&!s.isZero()?"-"+t:t};X.truncated=X.trunc=function(){return ae(new this.constructor(this),this.e+1,1)};X.valueOf=X.toJSON=function(){var s=this,e=s.constructor,t=bn(s,s.e<=e.toExpNeg||s.e>=e.toExpPos);return s.isNeg()?"-"+t:t};function pt(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=fe-n.length,t&&(i+=vn(t)),i+=n;r=s[e],n=r+"",t=fe-n.length,t&&(i+=vn(t))}else if(r===0)return"0";for(;r%10===0;)r/=10;return i+r}function vt(s,e,t){if(s!==~~s||s<e||s>t)throw Error(Fn+s)}function Ho(s,e,t,n){var o,i,r,a;for(i=s[0];i>=10;i/=10)--e;return--e<0?(e+=fe,o=0):(o=Math.ceil((e+1)/fe),e%=fe),i=rt(10,fe-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)==rt(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)==rt(10,e-3)-1,r}function Zi(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]+=bs.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 ym(s,e){var t,n,o;if(e.isZero())return e;n=e.d.length,n<32?(t=Math.ceil(n/3),o=(1/rr(4,t)).toString()):(t=16,o="2.3283064365386962890625e-10"),s.precision+=t,e=Ko(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 _e=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=rn,p=fe,l=At(n.e/p)-At(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,Tu=f;else{for(m=1,d=P[0];d>=10;d/=10)m++;g.e=m+l*p-1,ae(g,a?i+g.e+1:i,r,f)}return g}}();function ae(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+=fe,r=e,l=m[d=0],c=l/rt(10,o-r-1)%10|0;else if(d=Math.ceil((i+1)/fe),a=m.length,d>=a)if(n){for(;a++<=d;)m.push(0);l=c=0,o=1,i%=fe,r=i-fe+1}else break e;else{for(l=a=m[d],o=1;a>=10;a/=10)o++;i%=fe,r=i-fe+o,c=r<0?0:l/rt(10,o-r-1)%10|0}if(n=n||e<0||m[d+1]!==void 0||(r<0?l:l%rt(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/rt(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]=rt(10,(fe-e%fe)%fe),s.e=-e||0):m[0]=s.e=0,s;if(i==0?(m.length=d,a=1,d--):(m.length=d+1,a=rt(10,fe-i),m[d]=r>0?(l/rt(10,o-r)%rt(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]==rn&&(m[0]=1));break}else{if(m[d]+=a,m[d]!=rn)break;m[d--]=0,a=1}for(i=m.length;m[--i]===0;)m.pop()}return Pe&&(s.e>p.maxE?(s.d=null,s.e=NaN):s.e<p.minE&&(s.e=0,s.d=[0])),s}function bn(s,e,t){if(!s.isFinite())return Lu(s);var n,o=s.e,i=pt(s.d),r=i.length;return e?(t&&(n=t-r)>0?i=i.charAt(0)+"."+i.slice(1)+vn(n):r>1&&(i=i.charAt(0)+"."+i.slice(1)),i=i+(s.e<0?"e":"e+")+s.e):o<0?(i="0."+vn(-o-1)+i,t&&(n=t-r)>0&&(i+=vn(n))):o>=r?(i+=vn(o+1-r),t&&(n=t-o-1)>0&&(i=i+"."+vn(n))):((n=o+1)<r&&(i=i.slice(0,n)+"."+i.slice(n)),t&&(n=t-r)>0&&(o+1===r&&(i+="."),i+=vn(n))),i}function ir(s,e){var t=s[0];for(e*=fe;t>=10;t/=10)e++;return e}function nr(s,e,t){if(e>fm)throw Pe=!0,t&&(s.precision=t),Error(Iu);return ae(new s(er),e,1,!0)}function yn(s,e,t){if(e>Ps)throw Error(Iu);return ae(new s(tr),e,t,!0)}function Ku(s){var e=s.length-1,t=e*fe+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 vn(s){for(var e="";s--;)e+="0";return e}function Cu(s,e,t,n){var o,i=new s(1),r=Math.ceil(n/fe+4);for(Pe=!1;;){if(t%2&&(i=i.times(e),ku(i.d,r)&&(o=!0)),t=At(t/2),t===0){t=i.d.length-1,o&&i.d[t]===0&&++i.d[t];break}e=e.times(e),ku(e.d,r)}return Pe=!0,i}function wu(s){return s.d[s.d.length-1]&1}function Ru(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 As(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?(Pe=!1,c=f):c=e,a=new d(.03125);s.e>-2;)s=s.times(a),m+=5;for(n=Math.log(rt(2,m))/Math.LN10*2+5|0,c+=n,t=i=r=new d(1),d.precision=c;;){if(i=ae(i.times(s),c,1),t=t.times(++l),a=r.plus(_e(i,t,c,1)),pt(a.d).slice(0,c)===pt(r.d).slice(0,c)){for(o=m;o--;)r=ae(r.times(r),c,1);if(e==null)if(u<3&&Ho(r.d,c-n,p,u))d.precision=c+=10,t=i=a=new d(1),l=0,u++;else return ae(r,d.precision=f,p,Pe=!0);else return d.precision=f,r}r=a}}function Mn(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?(Pe=!1,l=w):l=e,g.precision=l+=f,t=pt(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=pt(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=nr(g,l+2,w).times(i+""),y=Mn(new g(n+"."+t.slice(1)),l-f).plus(u),g.precision=w,e==null?ae(y,w,P,Pe=!0):y;for(m=y,c=r=y=_e(y.minus(1),y.plus(1),l,1),d=ae(y.times(y),l,1),o=3;;){if(r=ae(r.times(d),l,1),u=c.plus(_e(r,new g(o),l,1)),pt(u.d).slice(0,l)===pt(c.d).slice(0,l))if(c=c.times(2),i!==0&&(c=c.plus(nr(g,l+2,w).times(i+""))),c=_e(c,new g(p),l,1),e==null)if(Ho(c.d,l-f,P,a))g.precision=l+=f,u=r=y=_e(m.minus(1),m.plus(1),l,1),d=ae(y.times(y),l,1),o=a=1;else return ae(c,g.precision=w,P,Pe=!0);else return g.precision=w,c;c=u,o+=2}}function Lu(s){return String(s.s*s.s/0)}function Ji(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)%fe,t<0&&(n+=fe),n<o){for(n&&s.d.push(+e.slice(0,n)),o-=fe;n<o;)s.d.push(+e.slice(n,n+=fe));e=e.slice(n),n=fe-e.length}else n-=o;for(;n--;)e+="0";s.d.push(+e),Pe&&(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 bm(s,e){var t,n,o,i,r,a,c,u,l;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),Su.test(e))return Ji(s,e)}else if(e==="Infinity"||e==="NaN")return+e||(s.s=NaN),s.e=NaN,s.d=null,s;if(mm.test(e))t=16,e=e.toLowerCase();else if(lm.test(e))t=2;else if(dm.test(e))t=8;else throw Error(Fn+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=Cu(n,new n(t),i,i*2)),u=Zi(e,t,rn),l=u.length-1,i=l;u[i]===0;--i)u.pop();return i<0?new n(s.s*0):(s.e=ir(u,l),s.d=u,Pe=!1,r&&(s=_e(s,o,a*4)),c&&(s=s.times(Math.abs(c)<54?rt(2,c):Qo.pow(2,c))),Pe=!0,s)}function gm(s,e){var t,n=e.d.length;if(n<3)return e.isZero()?e:Ko(s,2,e,e);t=1.4*Math.sqrt(n),t=t>16?16:t|0,e=e.times(1/rr(5,t)),e=Ko(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 Ko(s,e,t,n,o){var i,r,a,c,u=1,l=s.precision,m=Math.ceil(l/fe);for(Pe=!1,c=t.times(t),a=new s(n);;){if(r=_e(a.times(c),new s(e++*e++),l,1),a=o?n.plus(r):n.minus(r),n=_e(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 Pe=!0,r.d.length=m+1,r}function rr(s,e){for(var t=s;--e;)t*=s;return t}function Nu(s,e){var t,n=e.s<0,o=yn(s,s.precision,1),i=o.times(.5);if(e=e.abs(),e.lte(i))return kn=n?4:1,e;if(t=e.divToInt(o),t.isZero())kn=n?3:2;else{if(e=e.minus(t.times(o)),e.lte(i))return kn=wu(t)?n?2:3:n?4:1,e;kn=wu(t)?n?1:4:n?3:2}return e.minus(o).abs()}function ws(s,e,t,n){var o,i,r,a,c,u,l,m,d,p=s.constructor,f=t!==void 0;if(f?(vt(t,1,Vn),n===void 0?n=p.rounding:vt(n,0,8)):(t=p.precision,n=p.rounding),!s.isFinite())l=Lu(s);else{for(l=bn(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=Zi(bn(d),10,o),d.e=d.d.length),m=Zi(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=_e(s,d,t,n,0,o),m=s.d,i=s.e,u=Tu),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+=bs.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=Zi(l,o,e),c=m.length;!m[c-1];--c);for(r=1,l="1.";r<c;r++)l+=bs.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 ku(s,e){if(s.length>e)return s.length=e,!0}function Pm(s){return new this(s).abs()}function Am(s){return new this(s).acos()}function wm(s){return new this(s).acosh()}function km(s,e){return new this(s).plus(e)}function hm(s){return new this(s).asin()}function Tm(s){return new this(s).asinh()}function Im(s){return new this(s).atan()}function Bm(s){return new this(s).atanh()}function xm(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=yn(this,i,1).times(e.s>0?.25:.75),t.s=s.s):!e.d||s.isZero()?(t=e.s<0?yn(this,n,o):new this(0),t.s=s.s):!s.d||e.isZero()?(t=yn(this,i,1).times(.5),t.s=s.s):e.s<0?(this.precision=i,this.rounding=1,t=this.atan(_e(s,e,i,1)),e=yn(this,i,1),this.precision=n,this.rounding=o,t=s.s<0?t.minus(e):t.plus(e)):t=this.atan(_e(s,e,i,1)),t}function Sm(s){return new this(s).cbrt()}function Km(s){return ae(s=new this(s),s.e+1,2)}function Cm(s,e,t){return new this(s).clamp(e,t)}function Rm(s){if(!s||typeof s!="object")throw Error(or+"Object expected");var e,t,n,o=s.defaults===!0,i=["precision",1,Vn,"rounding",0,8,"toExpNeg",-So,0,"toExpPos",0,So,"maxE",0,So,"minE",-So,0,"modulo",0,9];for(e=0;e<i.length;e+=3)if(t=i[e],o&&(this[t]=gs[t]),(n=s[t])!==void 0)if(At(n)===n&&n>=i[e+1]&&n<=i[e+2])this[t]=n;else throw Error(Fn+t+": "+n);if(t="crypto",o&&(this[t]=gs[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(Bu);else this[t]=!1;else throw Error(Fn+t+": "+n);return this}function Lm(s){return new this(s).cos()}function Nm(s){return new this(s).cosh()}function Ou(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,hu(i)){u.s=i.s,Pe?!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++;Pe?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 Ji(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),Su.test(i)?Ji(u,i):bm(u,i);if(c==="bigint")return i<0?(i=-i,u.s=-1):u.s=1,Ji(u,i.toString());throw Error(Fn+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=Rm,o.clone=Ou,o.isDecimal=hu,o.abs=Pm,o.acos=Am,o.acosh=wm,o.add=km,o.asin=hm,o.asinh=Tm,o.atan=Im,o.atanh=Bm,o.atan2=xm,o.cbrt=Sm,o.ceil=Km,o.clamp=Cm,o.cos=Lm,o.cosh=Nm,o.div=Om,o.exp=vm,o.floor=Mm,o.hypot=Fm,o.ln=Vm,o.log=_m,o.log10=Wm,o.log2=Em,o.max=Dm,o.min=qm,o.mod=Um,o.mul=Gm,o.pow=Xm,o.random=zm,o.round=Ym,o.sign=Hm,o.sin=Qm,o.sinh=jm,o.sqrt=$m,o.sub=Zm,o.sum=Jm,o.tan=ed,o.tanh=td,o.trunc=nd,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 Om(s,e){return new this(s).div(e)}function vm(s){return new this(s).exp()}function Mm(s){return ae(s=new this(s),s.e+1,3)}function Fm(){var s,e,t=new this(0);for(Pe=!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 Pe=!0,new this(1/0);t=e}return Pe=!0,t.sqrt()}function hu(s){return s instanceof Qo||s&&s.toStringTag===xu||!1}function Vm(s){return new this(s).ln()}function _m(s,e){return new this(s).log(e)}function Em(s){return new this(s).log(2)}function Wm(s){return new this(s).log(10)}function Dm(){return Ru(this,arguments,-1)}function qm(){return Ru(this,arguments,1)}function Um(s,e){return new this(s).mod(e)}function Gm(s,e){return new this(s).mul(e)}function Xm(s,e){return new this(s).pow(e)}function zm(s){var e,t,n,o,i=0,r=new this(1),a=[];if(s===void 0?s=this.precision:vt(s,1,Vn),n=Math.ceil(s/fe),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(Bu);else for(;i<n;)a[i++]=Math.random()*1e7|0;for(n=a[--i],s%=fe,n&&s&&(o=rt(10,fe-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-=fe)a.shift();for(n=1,o=a[0];o>=10;o/=10)n++;n<fe&&(t-=fe-n)}return r.e=t,r.d=a,r}function Ym(s){return ae(s=new this(s),s.e+1,this.rounding)}function Hm(s){return s=new this(s),s.d?s.d[0]?s.s:0*s.s:s.s||NaN}function Qm(s){return new this(s).sin()}function jm(s){return new this(s).sinh()}function $m(s){return new this(s).sqrt()}function Zm(s,e){return new this(s).sub(e)}function Jm(){var s=0,e=arguments,t=new this(e[s]);for(Pe=!1;t.s&&++s<e.length;)t=t.plus(e[s]);return Pe=!0,ae(t,this.precision,this.rounding)}function ed(s){return new this(s).tan()}function td(s){return new this(s).tanh()}function nd(s){return ae(s=new this(s),s.e+1,1)}X[Symbol.for("nodejs.util.inspect.custom")]=X.toString;X[Symbol.toStringTag]="Decimal";var Qo=X.constructor=Ou(gs);er=new Qo(er);tr=new Qo(tr);var O=Qo;import ld from"big.js";import ur from"bn.js";import od from"toformat";var id=od,jo=id;import ar from"big.js";import sd from"bn.js";import ad from"decimal.js-light";import $o from"bn.js";var vu=9007199254740991;function se(s){let e=he("Raydium_parseBigNumberish");if(s instanceof $o)return s;if(typeof s=="string"){if(s.match(/^-?[0-9]+$/))return new $o(s);e.logWithError(`invalid BigNumberish string: ${s}`)}return typeof s=="number"?(s%1&&e.logWithError(`BigNumberish number underflow: ${s}`),(s>=vu||s<=-vu)&&e.logWithError(`BigNumberish number overflow: ${s}`),new $o(String(s))):typeof s=="bigint"?new $o(s.toString()):(e.error(`invalid BigNumberish value: ${s}`),new $o(0))}var sr=he("module/fraction"),ks=jo(ar),Zo=jo(ad),ud={[0]:Zo.ROUND_DOWN,[1]:Zo.ROUND_HALF_UP,[2]:Zo.ROUND_UP},cd={[0]:ar.roundDown,[1]:ar.roundHalfUp,[2]:ar.roundUp},Ne=class{constructor(e,t=new sd(1)){this.numerator=se(e),this.denominator=se(t)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new Ne(this.denominator,this.numerator)}add(e){let t=e instanceof Ne?e:new Ne(se(e));return this.denominator.eq(t.denominator)?new Ne(this.numerator.add(t.numerator),this.denominator):new Ne(this.numerator.mul(t.denominator).add(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}sub(e){let t=e instanceof Ne?e:new Ne(se(e));return this.denominator.eq(t.denominator)?new Ne(this.numerator.sub(t.numerator),this.denominator):new Ne(this.numerator.mul(t.denominator).sub(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}mul(e){let t=e instanceof Ne?e:new Ne(se(e));return new Ne(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof Ne?e:new Ne(se(e));return new Ne(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},n=1){Number.isInteger(e)||sr.logWithError(`${e} is not an integer.`),e<=0&&sr.logWithError(`${e} is not positive.`),Zo.set({precision:e+1,rounding:ud[n]});let o=new Zo(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)||sr.logWithError(`${e} is not an integer.`),e<0&&sr.logWithError(`${e} is negative.`),ks.DP=e,ks.RM=cd[n]||1,new ks(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};var md=he("Raydium_amount"),Mu=jo(ld);function dd(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")):md.logWithError(`invalid number string, num: ${s}`)}else t=s;return[t,n.slice(0,e)||n]}var Me=class extends Ne{constructor(t,n,o=!0,i){let r=new ur(0),a=hs.pow(new ur(t.decimals));if(o)r=se(n);else{let c=new ur(0),u=new ur(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[l,m]=dd(n.toString(),t.decimals);c=se(l),u=se(m)}c=c.mul(a),r=c.add(u)}super(r,a);this.logger=he(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 Me(this.token,this.raw.add(t.raw))}subtract(t){return this.token.equals(t.token)||this.logger.logWithError("sub token not equals"),new Me(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 Mu.DP=this.token.decimals,new Mu(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)}};import{PublicKey as pd}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Fu}from"@solana/spl-token";var _n={chainId:101,address:pd.default.toBase58(),programId:Fu.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},wt={chainId:101,address:"So11111111111111111111111111111111111111112",programId:Fu.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"}};import{PublicKey as Ss}from"@solana/web3.js";import{PublicKey as ze,SystemProgram as Vu,SYSVAR_RENT_PUBKEY as fd}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as yd}from"@solana/spl-token";function K({pubkey:s,isSigner:e=!1,isWritable:t=!0}){return{pubkey:s,isWritable:t,isSigner:e}}var Ts=[K({pubkey:yd,isWritable:!1}),K({pubkey:Vu.programId,isWritable:!1}),K({pubkey:fd,isWritable:!1})];function Is({publicKey:s,transformSol:e}){let t=Bs(s.toString());if(t instanceof ze)return e&&t.equals(ct)?$:t;if(e&&t.toString()===ct.toBase58())return $;if(typeof t=="string"){if(t===ze.default.toBase58())return ze.default;try{return new ze(t)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function Bs(s){try{return new ze(s)}catch{return s}}var cr=new ze("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),En=new ze("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),ft=new ze("SysvarRent111111111111111111111111111111111"),_u=new ze("SysvarC1ock11111111111111111111111111111111"),sn=new ze("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),bd=new ze("Sysvar1nstructions1111111111111111111111111"),xs=Vu.programId,Jy=new ze("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),eb=new ze("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),tb=new ze("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),nb=new ze("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),ob=new ze("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),ib=new ze("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),rb=new ze("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),sb=new ze("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),ab=new ze("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),ub=new ze("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),cb=new ze("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),$=new ze("So11111111111111111111111111111111111111112"),ct=ze.default;function Pt(s){return Is({publicKey:s,transformSol:!0})}var Ks=class{constructor({mint:e,decimals:t,symbol:n,name:o,skipMint:i=!1,isToken2022:r=!1}){if(e===ct.toBase58()||e instanceof Ss&&ct.equals(e)){this.decimals=wt.decimals,this.symbol=wt.symbol,this.name=wt.name,this.mint=new Ss(wt.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?Ss.default:Is({publicKey:e}),this.isToken2022=r}equals(e){return this===e?!0:this.mint.equals(e.mint)}},Ye=Ks;Ye.WSOL=new Ks(q(V({},wt),{mint:wt.address}));var Cs=class{constructor({decimals:e,symbol:t="UNKNOWN",name:n="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=n}equals(e){return this===e}},lr=Cs;lr.SOL=new Cs(_n);import gd from"bn.js";var Eu=new Ne(new gd(100)),lt=class extends Ne{toSignificant(e=5,t,n){return this.mul(Eu).toSignificant(e,t,n)}toFixed(e=2,t,n){return this.mul(Eu).toFixed(e,t,n)}};var Pd=he("Raydium_price"),Mt=class extends Ne{constructor(t){let{baseToken:n,quoteToken:o,numerator:i,denominator:r}=t;super(i,r);this.baseToken=n,this.quoteToken=o,this.scalar=new Ne(Rs(n.decimals),Rs(o.decimals))}get raw(){return new Ne(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new Mt({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numerator,numerator:this.denominator})}mul(t){this.quoteToken!==t.baseToken&&Pd.logWithError("mul token not equals");let n=super.mul(t);return new Mt({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 Ft=new gn(0),Wu=new gn(1),Zb=new gn(2),Jb=new gn(3),eg=new gn(5),hs=new gn(10),tg=new gn(100),ng=new gn(1e3),og=new gn(1e4);function Rs(s){return hs.pow(se(s))}function mr(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 Jo(s,e,t){return s.mul(e).add(t).sub(new gn(1)).div(t)}function dr(s,e,t){return s.mul(e).div(t)}function ys(s,e=1,t=[]){let n=[...s];if(e<=0)return t;for(;n.length;)t.push(n.splice(0,e));return t}var an=class{constructor(e){this._owner=e}get publicKey(){return an.isKeyPair(this._owner)?this._owner.publicKey:this._owner}get signer(){return an.isKeyPair(this._owner)?this._owner:void 0}get isKeyPair(){return an.isKeyPair(this._owner)}get isPublicKey(){return an.isPublicKey(this._owner)}static isKeyPair(e){return e.secretKey!==void 0}static isPublicKey(e){return!an.isKeyPair(e)}};import{PublicKey as Id}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Bd}from"@solana/spl-token";import{ComputeBudgetProgram as Du,Keypair as Uu,PublicKey as Ad,Transaction as Gu,TransactionMessage as wd,VersionedTransaction as Xu}from"@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"};import{TOKEN_PROGRAM_ID as kd}from"@solana/spl-token";var qu=he("Raydium_txUtil"),zu=1644;function pr(s){let e=[],t=[];return s.microLamports&&(e.push(Du.setComputeUnitPrice({microLamports:s.microLamports})),t.push(z.SetComputeUnitPrice)),s.units&&(e.push(Du.setComputeUnitLimit({units:s.units})),t.push(z.SetComputeUnitLimit)),{instructions:e,instructionTypes:t}}async function Co(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 fr(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 Ls(s,e){s.length<1&&qu.logWithError(`no instructions provided: ${s.toString()}`),e.length<1&&qu.logWithError(`no signers provided:, ${e.toString()}`);let t=new Gu;t.recentBlockhash="11111111111111111111111111111111",t.feePayer=e[0],t.add(...s);try{return Buffer.from(t.serialize({verifySignatures:!1})).toString("base64").length<zu}catch{return!1}}function be(s,e){let[t,n]=Ad.findProgramAddressSync(s,e);return{publicKey:t,nonce:n}}function ei({instructions:s,payer:e,signers:t}){return Ls(s,[e,...t])}function ti({instructions:s,payer:e,lookupTableAddressAccount:t,recentBlockhash:n=Uu.generate().publicKey.toString()}){let i=new wd({payerKey:e,recentBlockhash:n,instructions:s}).compileToV0Message(Object.values(t!=null?t:{}));try{return Buffer.from(new Xu(i).serialize()).toString("base64").length<zu}catch{return!1}}var hd=s=>Buffer.isBuffer(s)?s:s instanceof Uint8Array?Buffer.from(s.buffer,s.byteOffset,s.byteLength):Buffer.from(s),Td=s=>{let e=s.serialize({requireAllSignatures:!1,verifySignatures:!1});s instanceof Xu&&(e=hd(e));try{return e instanceof Buffer?e.toString("base64"):Buffer.from(e).toString("base64")}catch{return e.toString("base64")}};function to(s){let e=[];return s.forEach(t=>{t instanceof Gu&&(t.recentBlockhash||(t.recentBlockhash=kd.toBase58()),t.feePayer||(t.feePayer=Uu.generate().publicKey)),e.push(Td(t))}),console.log("simulate tx string:",e),e}function re(s,e,t){return be([s.toBuffer(),(t!=null?t:Bd).toBuffer(),e.toBuffer()],new Id("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}import{PublicKey as ce}from"@solana/web3.js";var Yu=new ce("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),Hu=new ce("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),Qu=new ce("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),ni=new ce("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Ig=new ce("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),ju=new ce("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),Ns=new ce("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),yr=new ce("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Bg=new ce("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),$u=new ce("CDSr3ssLcRB6X