raydium-sdk-v2-custody
Version:
An SDK for building applications on top of Raydium.
1 lines • 425 kB
JavaScript
var cl=Object.defineProperty,ll=Object.defineProperties;var ml=Object.getOwnPropertyDescriptors;var ho=Object.getOwnPropertySymbols;var xa=Object.prototype.hasOwnProperty,Ka=Object.prototype.propertyIsEnumerable;var Ba=(r,t,e)=>t in r?cl(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,N=(r,t)=>{for(var e in t||(t={}))xa.call(t,e)&&Ba(r,e,t[e]);if(ho)for(var e of ho(t))Ka.call(t,e)&&Ba(r,e,t[e]);return r},X=(r,t)=>ll(r,ml(t));var Xe=(r,t)=>{var e={};for(var n in r)xa.call(r,n)&&t.indexOf(n)<0&&(e[n]=r[n]);if(r!=null&&ho)for(var n of ho(r))t.indexOf(n)<0&&Ka.call(r,n)&&(e[n]=r[n]);return e};import{merge as yf}from"lodash";import du from"axios";import{PublicKey as La}from"@solana/web3.js";import{get as Sa,set as dl}from"lodash";var vr=class{constructor(t){this.logLevel=t.logLevel!==void 0?t.logLevel:0,this.name=t.name}set level(t){this.logLevel=t}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(t){return t<=this.logLevel}error(...t){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...t),this):this}logWithError(...t){let e=t.map(n=>typeof n=="object"?JSON.stringify(n):n).join(", ");throw new Error(e)}warning(...t){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...t),this):this}info(...t){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...t),this):this}debug(...t){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...t),this):this}},Ca={},pl={};function fe(r){let t=Sa(Ca,r);if(!t){let e=Sa(pl,r);t=new vr({name:r,logLevel:e}),dl(Ca,r,t)}return t}import{MINT_SIZE as fl,TOKEN_PROGRAM_ID as yl,getTransferFeeConfig as bl,unpackMint as gl}from"@solana/spl-token";var Vr=fe("Raydium_accountInfo_util");async function Wt(r,t,e){let{batchRequest:n,commitment:i="confirmed",chunkCount:o=100}=N({batchRequest:!1},e),s=_r(t,o),a=new Array(s.length).fill([]);if(n){let c=s.map(m=>{let d=r._buildArgs([m.map(p=>p.toBase58())],i,"base64");return{methodName:"getMultipleAccounts",args:d}}),u=_r(c,10);a=(await(await Promise.all(u.map(async m=>await r._rpcBatchRequest(m)))).flat()).map(m=>(m.error&&Vr.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${m.error.message}`),m.result.value.map(d=>{if(d){let{data:p,executable:y,lamports:f,owner:b,rentEpoch:g}=d;return p.length!==2&&p[1]!=="base64"&&Vr.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(p[0],"base64"),executable:y,lamports:f,owner:new La(b),rentEpoch:g}}return null})))}else try{a=await Promise.all(s.map(c=>r.getMultipleAccountsInfo(c,i)))}catch(c){c instanceof Error&&Vr.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return a.flat()}async function Ye(r,t,e){let n=await Wt(r,t.map(i=>i.pubkey),e);return t.map((i,o)=>X(N({},i),{accountInfo:n[o]}))}async function $n({connection:r,mints:t,config:e}){var o,s,a;if(t.length===0)return{};let n=await Ye(r,t.map(c=>({pubkey:lt(c)})),e),i={};for(let c of n){if(!c.accountInfo||c.accountInfo.data.length<fl){console.log("invalid mint account",c.pubkey.toBase58());continue}let u=gl(c.pubkey,c.accountInfo,(o=c.accountInfo)==null?void 0:o.owner);i[c.pubkey.toString()]=X(N({},u),{programId:((s=c.accountInfo)==null?void 0:s.owner)||yl,feeConfig:(a=bl(u))!=null?a:void 0})}return i[La.default.toBase58()]=i[$.toBase58()],i}import sn from"bn.js";var Jn=9e15,wn=1e9,Er="0123456789abcdef",Io="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Bo="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Fr={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Jn,maxE:Jn,crypto:!1},Na,on,ue=!0,Ko="[DecimalError] ",An=Ko+"Invalid argument: ",va=Ko+"Precision limit exceeded",Va=Ko+"crypto unavailable",_a="[object Decimal]",mt=Math.floor,je=Math.pow,Pl=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Al=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,wl=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Ea=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,qt=1e7,re=7,kl=9007199254740991,hl=Io.length-1,Wr=Bo.length-1,U={toStringTag:_a};U.absoluteValue=U.abs=function(){var r=new this.constructor(this);return r.s<0&&(r.s=1),ie(r)};U.ceil=function(){return ie(new this.constructor(this),this.e+1,2)};U.clampedTo=U.clamp=function(r,t){var e,n=this,i=n.constructor;if(r=new i(r),t=new i(t),!r.s||!t.s)return new i(NaN);if(r.gt(t))throw Error(An+t);return e=n.cmp(r),e<0?r:n.cmp(t)>0?t:new i(n)};U.comparedTo=U.cmp=function(r){var t,e,n,i,o=this,s=o.d,a=(r=new o.constructor(r)).d,c=o.s,u=r.s;if(!s||!a)return!c||!u?NaN:c!==u?c:s===a?0:!s^c<0?1:-1;if(!s[0]||!a[0])return s[0]?c:a[0]?-u:0;if(c!==u)return c;if(o.e!==r.e)return o.e>r.e^c<0?1:-1;for(n=s.length,i=a.length,t=0,e=n<i?n:i;t<e;++t)if(s[t]!==a[t])return s[t]>a[t]^c<0?1:-1;return n===i?0:n>i^c<0?1:-1};U.cosine=U.cos=function(){var r,t,e=this,n=e.constructor;return e.d?e.d[0]?(r=n.precision,t=n.rounding,n.precision=r+Math.max(e.e,e.sd())+re,n.rounding=1,e=Tl(n,Ua(n,e)),n.precision=r,n.rounding=t,ie(on==2||on==3?e.neg():e,r,t,!0)):new n(1):new n(NaN)};U.cubeRoot=U.cbrt=function(){var r,t,e,n,i,o,s,a,c,u,l=this,m=l.constructor;if(!l.isFinite()||l.isZero())return new m(l);for(ue=!1,o=l.s*je(l.s*l,1/3),!o||Math.abs(o)==1/0?(e=ot(l.d),r=l.e,(o=(r-e.length+1)%3)&&(e+=o==1||o==-2?"0":"00"),o=je(e,1/3),r=mt((r+1)/3)-(r%3==(r<0?-1:2)),o==1/0?e="5e"+r:(e=o.toExponential(),e=e.slice(0,e.indexOf("e")+1)+r),n=new m(e),n.s=l.s):n=new m(o.toString()),s=(r=m.precision)+3;;)if(a=n,c=a.times(a).times(a),u=c.plus(l),n=Re(u.plus(l).times(a),u.plus(c),s+2,1),ot(a.d).slice(0,s)===(e=ot(n.d)).slice(0,s))if(e=e.slice(s-3,s+1),e=="9999"||!i&&e=="4999"){if(!i&&(ie(a,r+1,0),a.times(a).times(a).eq(l))){n=a;break}s+=4,i=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(ie(n,r+1,1),t=!n.times(n).times(n).eq(l));break}return ue=!0,ie(n,r,m.rounding,t)};U.decimalPlaces=U.dp=function(){var r,t=this.d,e=NaN;if(t){if(r=t.length-1,e=(r-mt(this.e/re))*re,r=t[r],r)for(;r%10==0;r/=10)e--;e<0&&(e=0)}return e};U.dividedBy=U.div=function(r){return Re(this,new this.constructor(r))};U.dividedToIntegerBy=U.divToInt=function(r){var t=this,e=t.constructor;return ie(Re(t,new e(r),0,1,1),e.precision,e.rounding)};U.equals=U.eq=function(r){return this.cmp(r)===0};U.floor=function(){return ie(new this.constructor(this),this.e+1,3)};U.greaterThan=U.gt=function(r){return this.cmp(r)>0};U.greaterThanOrEqualTo=U.gte=function(r){var t=this.cmp(r);return t==1||t===0};U.hyperbolicCosine=U.cosh=function(){var r,t,e,n,i,o=this,s=o.constructor,a=new s(1);if(!o.isFinite())return new s(o.s?1/0:NaN);if(o.isZero())return a;e=s.precision,n=s.rounding,s.precision=e+Math.max(o.e,o.sd())+4,s.rounding=1,i=o.d.length,i<32?(r=Math.ceil(i/3),t=(1/Co(4,r)).toString()):(r=16,t="2.3283064365386962890625e-10"),o=ei(s,1,o.times(t),new s(1),!0);for(var c,u=r,l=new s(8);u--;)c=o.times(o),o=a.minus(c.times(l.minus(c.times(l))));return ie(o,s.precision=e,s.rounding=n,!0)};U.hyperbolicSine=U.sinh=function(){var r,t,e,n,i=this,o=i.constructor;if(!i.isFinite()||i.isZero())return new o(i);if(t=o.precision,e=o.rounding,o.precision=t+Math.max(i.e,i.sd())+4,o.rounding=1,n=i.d.length,n<3)i=ei(o,2,i,i,!0);else{r=1.4*Math.sqrt(n),r=r>16?16:r|0,i=i.times(1/Co(5,r)),i=ei(o,2,i,i,!0);for(var s,a=new o(5),c=new o(16),u=new o(20);r--;)s=i.times(i),i=i.times(a.plus(s.times(c.times(s).plus(u))))}return o.precision=t,o.rounding=e,ie(i,t,e,!0)};U.hyperbolicTangent=U.tanh=function(){var r,t,e=this,n=e.constructor;return e.isFinite()?e.isZero()?new n(e):(r=n.precision,t=n.rounding,n.precision=r+7,n.rounding=1,Re(e.sinh(),e.cosh(),n.precision=r,n.rounding=t)):new n(e.s)};U.inverseCosine=U.acos=function(){var r,t=this,e=t.constructor,n=t.abs().cmp(1),i=e.precision,o=e.rounding;return n!==-1?n===0?t.isNeg()?Dt(e,i,o):new e(0):new e(NaN):t.isZero()?Dt(e,i+4,o).times(.5):(e.precision=i+6,e.rounding=1,t=t.asin(),r=Dt(e,i+4,o).times(.5),e.precision=i,e.rounding=o,r.minus(t))};U.inverseHyperbolicCosine=U.acosh=function(){var r,t,e=this,n=e.constructor;return e.lte(1)?new n(e.eq(1)?0:NaN):e.isFinite()?(r=n.precision,t=n.rounding,n.precision=r+Math.max(Math.abs(e.e),e.sd())+4,n.rounding=1,ue=!1,e=e.times(e).minus(1).sqrt().plus(e),ue=!0,n.precision=r,n.rounding=t,e.ln()):new n(e)};U.inverseHyperbolicSine=U.asinh=function(){var r,t,e=this,n=e.constructor;return!e.isFinite()||e.isZero()?new n(e):(r=n.precision,t=n.rounding,n.precision=r+2*Math.max(Math.abs(e.e),e.sd())+6,n.rounding=1,ue=!1,e=e.times(e).plus(1).sqrt().plus(e),ue=!0,n.precision=r,n.rounding=t,e.ln())};U.inverseHyperbolicTangent=U.atanh=function(){var r,t,e,n,i=this,o=i.constructor;return i.isFinite()?i.e>=0?new o(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(r=o.precision,t=o.rounding,n=i.sd(),Math.max(n,r)<2*-i.e-1?ie(new o(i),r,t,!0):(o.precision=e=n-i.e,i=Re(i.plus(1),new o(1).minus(i),e+r,1),o.precision=r+4,o.rounding=1,i=i.ln(),o.precision=r,o.rounding=t,i.times(.5))):new o(NaN)};U.inverseSine=U.asin=function(){var r,t,e,n,i=this,o=i.constructor;return i.isZero()?new o(i):(t=i.abs().cmp(1),e=o.precision,n=o.rounding,t!==-1?t===0?(r=Dt(o,e+4,n).times(.5),r.s=i.s,r):new o(NaN):(o.precision=e+6,o.rounding=1,i=i.div(new o(1).minus(i.times(i)).sqrt().plus(1)).atan(),o.precision=e,o.rounding=n,i.times(2)))};U.inverseTangent=U.atan=function(){var r,t,e,n,i,o,s,a,c,u=this,l=u.constructor,m=l.precision,d=l.rounding;if(u.isFinite()){if(u.isZero())return new l(u);if(u.abs().eq(1)&&m+4<=Wr)return s=Dt(l,m+4,d).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(m+4<=Wr)return s=Dt(l,m+4,d).times(.5),s.s=u.s,s}for(l.precision=a=m+10,l.rounding=1,e=Math.min(28,a/re+2|0),r=e;r;--r)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(ue=!1,t=Math.ceil(a/re),n=1,c=u.times(u),s=new l(u),i=u;r!==-1;)if(i=i.times(c),o=s.minus(i.div(n+=2)),i=i.times(c),s=o.plus(i.div(n+=2)),s.d[t]!==void 0)for(r=t;s.d[r]===o.d[r]&&r--;);return e&&(s=s.times(2<<e-1)),ue=!0,ie(s,l.precision=m,l.rounding=d,!0)};U.isFinite=function(){return!!this.d};U.isInteger=U.isInt=function(){return!!this.d&&mt(this.e/re)>this.d.length-2};U.isNaN=function(){return!this.s};U.isNegative=U.isNeg=function(){return this.s<0};U.isPositive=U.isPos=function(){return this.s>0};U.isZero=function(){return!!this.d&&this.d[0]===0};U.lessThan=U.lt=function(r){return this.cmp(r)<0};U.lessThanOrEqualTo=U.lte=function(r){return this.cmp(r)<1};U.logarithm=U.log=function(r){var t,e,n,i,o,s,a,c,u=this,l=u.constructor,m=l.precision,d=l.rounding,p=5;if(r==null)r=new l(10),t=!0;else{if(r=new l(r),e=r.d,r.s<0||!e||!e[0]||r.eq(1))return new l(NaN);t=r.eq(10)}if(e=u.d,u.s<0||!e||!e[0]||u.eq(1))return new l(e&&!e[0]?-1/0:u.s!=1?NaN:e?0:1/0);if(t)if(e.length>1)o=!0;else{for(i=e[0];i%10===0;)i/=10;o=i!==1}if(ue=!1,a=m+p,s=Pn(u,a),n=t?xo(l,a+10):Pn(r,a),c=Re(s,n,a,1),Ai(c.d,i=m,d))do if(a+=10,s=Pn(u,a),n=t?xo(l,a+10):Pn(r,a),c=Re(s,n,a,1),!o){+ot(c.d).slice(i+1,i+15)+1==1e14&&(c=ie(c,m+1,0));break}while(Ai(c.d,i+=10,d));return ue=!0,ie(c,m,d)};U.minus=U.sub=function(r){var t,e,n,i,o,s,a,c,u,l,m,d,p=this,y=p.constructor;if(r=new y(r),!p.d||!r.d)return!p.s||!r.s?r=new y(NaN):p.d?r.s=-r.s:r=new y(r.d||p.s!==r.s?p:NaN),r;if(p.s!=r.s)return r.s=-r.s,p.plus(r);if(u=p.d,d=r.d,a=y.precision,c=y.rounding,!u[0]||!d[0]){if(d[0])r.s=-r.s;else if(u[0])r=new y(p);else return new y(c===3?-0:0);return ue?ie(r,a,c):r}if(e=mt(r.e/re),l=mt(p.e/re),u=u.slice(),o=l-e,o){for(m=o<0,m?(t=u,o=-o,s=d.length):(t=d,e=l,s=u.length),n=Math.max(Math.ceil(a/re),s)+2,o>n&&(o=n,t.length=1),t.reverse(),n=o;n--;)t.push(0);t.reverse()}else{for(n=u.length,s=d.length,m=n<s,m&&(s=n),n=0;n<s;n++)if(u[n]!=d[n]){m=u[n]<d[n];break}o=0}for(m&&(t=u,u=d,d=t,r.s=-r.s),s=u.length,n=d.length-s;n>0;--n)u[s++]=0;for(n=d.length;n>o;){if(u[--n]<d[n]){for(i=n;i&&u[--i]===0;)u[i]=qt-1;--u[i],u[n]+=qt}u[n]-=d[n]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--e;return u[0]?(r.d=u,r.e=So(u,e),ue?ie(r,a,c):r):new y(c===3?-0:0)};U.modulo=U.mod=function(r){var t,e=this,n=e.constructor;return r=new n(r),!e.d||!r.s||r.d&&!r.d[0]?new n(NaN):!r.d||e.d&&!e.d[0]?ie(new n(e),n.precision,n.rounding):(ue=!1,n.modulo==9?(t=Re(e,r.abs(),0,3,1),t.s*=r.s):t=Re(e,r,0,n.modulo,1),t=t.times(r),ue=!0,e.minus(t))};U.naturalExponential=U.exp=function(){return Dr(this)};U.naturalLogarithm=U.ln=function(){return Pn(this)};U.negated=U.neg=function(){var r=new this.constructor(this);return r.s=-r.s,ie(r)};U.plus=U.add=function(r){var t,e,n,i,o,s,a,c,u,l,m=this,d=m.constructor;if(r=new d(r),!m.d||!r.d)return!m.s||!r.s?r=new d(NaN):m.d||(r=new d(r.d||m.s===r.s?m:NaN)),r;if(m.s!=r.s)return r.s=-r.s,m.minus(r);if(u=m.d,l=r.d,a=d.precision,c=d.rounding,!u[0]||!l[0])return l[0]||(r=new d(m)),ue?ie(r,a,c):r;if(o=mt(m.e/re),n=mt(r.e/re),u=u.slice(),i=o-n,i){for(i<0?(e=u,i=-i,s=l.length):(e=l,n=o,s=u.length),o=Math.ceil(a/re),s=o>s?o+1:s+1,i>s&&(i=s,e.length=1),e.reverse();i--;)e.push(0);e.reverse()}for(s=u.length,i=l.length,s-i<0&&(i=s,e=l,l=u,u=e),t=0;i;)t=(u[--i]=u[i]+l[i]+t)/qt|0,u[i]%=qt;for(t&&(u.unshift(t),++n),s=u.length;u[--s]==0;)u.pop();return r.d=u,r.e=So(u,n),ue?ie(r,a,c):r};U.precision=U.sd=function(r){var t,e=this;if(r!==void 0&&r!==!!r&&r!==1&&r!==0)throw Error(An+r);return e.d?(t=Fa(e.d),r&&e.e+1>t&&(t=e.e+1)):t=NaN,t};U.round=function(){var r=this,t=r.constructor;return ie(new t(r),r.e+1,t.rounding)};U.sine=U.sin=function(){var r,t,e=this,n=e.constructor;return e.isFinite()?e.isZero()?new n(e):(r=n.precision,t=n.rounding,n.precision=r+Math.max(e.e,e.sd())+re,n.rounding=1,e=Bl(n,Ua(n,e)),n.precision=r,n.rounding=t,ie(on>2?e.neg():e,r,t,!0)):new n(NaN)};U.squareRoot=U.sqrt=function(){var r,t,e,n,i,o,s=this,a=s.d,c=s.e,u=s.s,l=s.constructor;if(u!==1||!a||!a[0])return new l(!u||u<0&&(!a||a[0])?NaN:a?s:1/0);for(ue=!1,u=Math.sqrt(+s),u==0||u==1/0?(t=ot(a),(t.length+c)%2==0&&(t+="0"),u=Math.sqrt(t),c=mt((c+1)/2)-(c<0||c%2),u==1/0?t="5e"+c:(t=u.toExponential(),t=t.slice(0,t.indexOf("e")+1)+c),n=new l(t)):n=new l(u.toString()),e=(c=l.precision)+3;;)if(o=n,n=o.plus(Re(s,o,e+2,1)).times(.5),ot(o.d).slice(0,e)===(t=ot(n.d)).slice(0,e))if(t=t.slice(e-3,e+1),t=="9999"||!i&&t=="4999"){if(!i&&(ie(o,c+1,0),o.times(o).eq(s))){n=o;break}e+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(ie(n,c+1,1),r=!n.times(n).eq(s));break}return ue=!0,ie(n,c,l.rounding,r)};U.tangent=U.tan=function(){var r,t,e=this,n=e.constructor;return e.isFinite()?e.isZero()?new n(e):(r=n.precision,t=n.rounding,n.precision=r+10,n.rounding=1,e=e.sin(),e.s=1,e=Re(e,new n(1).minus(e.times(e)).sqrt(),r+10,0),n.precision=r,n.rounding=t,ie(on==2||on==4?e.neg():e,r,t,!0)):new n(NaN)};U.times=U.mul=function(r){var t,e,n,i,o,s,a,c,u,l=this,m=l.constructor,d=l.d,p=(r=new m(r)).d;if(r.s*=l.s,!d||!d[0]||!p||!p[0])return new m(!r.s||d&&!d[0]&&!p||p&&!p[0]&&!d?NaN:!d||!p?r.s/0:r.s*0);for(e=mt(l.e/re)+mt(r.e/re),c=d.length,u=p.length,c<u&&(o=d,d=p,p=o,s=c,c=u,u=s),o=[],s=c+u,n=s;n--;)o.push(0);for(n=u;--n>=0;){for(t=0,i=c+n;i>n;)a=o[i]+p[n]*d[i-n-1]+t,o[i--]=a%qt|0,t=a/qt|0;o[i]=(o[i]+t)%qt|0}for(;!o[--s];)o.pop();return t?++e:o.shift(),r.d=o,r.e=So(o,e),ue?ie(r,m.precision,m.rounding):r};U.toBinary=function(r,t){return Ur(this,2,r,t)};U.toDecimalPlaces=U.toDP=function(r,t){var e=this,n=e.constructor;return e=new n(e),r===void 0?e:(Tt(r,0,wn),t===void 0?t=n.rounding:Tt(t,0,8),ie(e,r+e.e+1,t))};U.toExponential=function(r,t){var e,n=this,i=n.constructor;return r===void 0?e=jt(n,!0):(Tt(r,0,wn),t===void 0?t=i.rounding:Tt(t,0,8),n=ie(new i(n),r+1,t),e=jt(n,!0,r+1)),n.isNeg()&&!n.isZero()?"-"+e:e};U.toFixed=function(r,t){var e,n,i=this,o=i.constructor;return r===void 0?e=jt(i):(Tt(r,0,wn),t===void 0?t=o.rounding:Tt(t,0,8),n=ie(new o(i),r+i.e+1,t),e=jt(n,!1,r+n.e+1)),i.isNeg()&&!i.isZero()?"-"+e:e};U.toFraction=function(r){var t,e,n,i,o,s,a,c,u,l,m,d,p=this,y=p.d,f=p.constructor;if(!y)return new f(p);if(u=e=new f(1),n=c=new f(0),t=new f(n),o=t.e=Fa(y)-p.e-1,s=o%re,t.d[0]=je(10,s<0?re+s:s),r==null)r=o>0?t:u;else{if(a=new f(r),!a.isInt()||a.lt(u))throw Error(An+a);r=a.gt(t)?o>0?t:u:a}for(ue=!1,a=new f(ot(y)),l=f.precision,f.precision=o=y.length*re*2;m=Re(a,t,0,1,1),i=e.plus(m.times(n)),i.cmp(r)!=1;)e=n,n=i,i=u,u=c.plus(m.times(i)),c=i,i=t,t=a.minus(m.times(i)),a=i;return i=Re(r.minus(e),n,0,1,1),c=c.plus(i.times(u)),e=e.plus(i.times(n)),c.s=u.s=p.s,d=Re(u,n,o,1).minus(p).abs().cmp(Re(c,e,o,1).minus(p).abs())<1?[u,n]:[c,e],f.precision=l,ue=!0,d};U.toHexadecimal=U.toHex=function(r,t){return Ur(this,16,r,t)};U.toNearest=function(r,t){var e=this,n=e.constructor;if(e=new n(e),r==null){if(!e.d)return e;r=new n(1),t=n.rounding}else{if(r=new n(r),t===void 0?t=n.rounding:Tt(t,0,8),!e.d)return r.s?e:r;if(!r.d)return r.s&&(r.s=e.s),r}return r.d[0]?(ue=!1,e=Re(e,r,0,t,1).times(r),ue=!0,ie(e)):(r.s=e.s,e=r),e};U.toNumber=function(){return+this};U.toOctal=function(r,t){return Ur(this,8,r,t)};U.toPower=U.pow=function(r){var t,e,n,i,o,s,a=this,c=a.constructor,u=+(r=new c(r));if(!a.d||!r.d||!a.d[0]||!r.d[0])return new c(je(+a,u));if(a=new c(a),a.eq(1))return a;if(n=c.precision,o=c.rounding,r.eq(1))return ie(a,n,o);if(t=mt(r.e/re),t>=r.d.length-1&&(e=u<0?-u:u)<=kl)return i=Wa(c,a,e,n),r.s<0?new c(1).div(i):ie(i,n,o);if(s=a.s,s<0){if(t<r.d.length-1)return new c(NaN);if((r.d[t]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return e=je(+a,u),t=e==0||!isFinite(e)?mt(u*(Math.log("0."+ot(a.d))/Math.LN10+a.e+1)):new c(e+"").e,t>c.maxE+1||t<c.minE-1?new c(t>0?s/0:0):(ue=!1,c.rounding=a.s=1,e=Math.min(12,(t+"").length),i=Dr(r.times(Pn(a,n+e)),n),i.d&&(i=ie(i,n+5,1),Ai(i.d,n,o)&&(t=n+10,i=ie(Dr(r.times(Pn(a,t+e)),t),t+5,1),+ot(i.d).slice(n+1,n+15)+1==1e14&&(i=ie(i,n+1,0)))),i.s=s,ue=!0,c.rounding=o,ie(i,n,o))};U.toPrecision=function(r,t){var e,n=this,i=n.constructor;return r===void 0?e=jt(n,n.e<=i.toExpNeg||n.e>=i.toExpPos):(Tt(r,1,wn),t===void 0?t=i.rounding:Tt(t,0,8),n=ie(new i(n),r,t),e=jt(n,r<=n.e||n.e<=i.toExpNeg,r)),n.isNeg()&&!n.isZero()?"-"+e:e};U.toSignificantDigits=U.toSD=function(r,t){var e=this,n=e.constructor;return r===void 0?(r=n.precision,t=n.rounding):(Tt(r,1,wn),t===void 0?t=n.rounding:Tt(t,0,8)),ie(new n(e),r,t)};U.toString=function(){var r=this,t=r.constructor,e=jt(r,r.e<=t.toExpNeg||r.e>=t.toExpPos);return r.isNeg()&&!r.isZero()?"-"+e:e};U.truncated=U.trunc=function(){return ie(new this.constructor(this),this.e+1,1)};U.valueOf=U.toJSON=function(){var r=this,t=r.constructor,e=jt(r,r.e<=t.toExpNeg||r.e>=t.toExpPos);return r.isNeg()?"-"+e:e};function ot(r){var t,e,n,i=r.length-1,o="",s=r[0];if(i>0){for(o+=s,t=1;t<i;t++)n=r[t]+"",e=re-n.length,e&&(o+=gn(e)),o+=n;s=r[t],n=s+"",e=re-n.length,e&&(o+=gn(e))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function Tt(r,t,e){if(r!==~~r||r<t||r>e)throw Error(An+r)}function Ai(r,t,e,n){var i,o,s,a;for(o=r[0];o>=10;o/=10)--t;return--t<0?(t+=re,i=0):(i=Math.ceil((t+1)/re),t%=re),o=je(10,re-t),a=r[i]%o|0,n==null?t<3?(t==0?a=a/100|0:t==1&&(a=a/10|0),s=e<4&&a==99999||e>3&&a==49999||a==5e4||a==0):s=(e<4&&a+1==o||e>3&&a+1==o/2)&&(r[i+1]/o/100|0)==je(10,t-2)-1||(a==o/2||a==0)&&(r[i+1]/o/100|0)==0:t<4?(t==0?a=a/1e3|0:t==1?a=a/100|0:t==2&&(a=a/10|0),s=(n||e<4)&&a==9999||!n&&e>3&&a==4999):s=((n||e<4)&&a+1==o||!n&&e>3&&a+1==o/2)&&(r[i+1]/o/1e3|0)==je(10,t-3)-1,s}function To(r,t,e){for(var n,i=[0],o,s=0,a=r.length;s<a;){for(o=i.length;o--;)i[o]*=t;for(i[0]+=Er.indexOf(r.charAt(s++)),n=0;n<i.length;n++)i[n]>e-1&&(i[n+1]===void 0&&(i[n+1]=0),i[n+1]+=i[n]/e|0,i[n]%=e)}return i.reverse()}function Tl(r,t){var e,n,i;if(t.isZero())return t;n=t.d.length,n<32?(e=Math.ceil(n/3),i=(1/Co(4,e)).toString()):(e=16,i="2.3283064365386962890625e-10"),r.precision+=e,t=ei(r,1,t.times(i),new r(1));for(var o=e;o--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return r.precision-=e,t}var Re=function(){function r(n,i,o){var s,a=0,c=n.length;for(n=n.slice();c--;)s=n[c]*i+a,n[c]=s%o|0,a=s/o|0;return a&&n.unshift(a),n}function t(n,i,o,s){var a,c;if(o!=s)c=o>s?1:-1;else for(a=c=0;a<o;a++)if(n[a]!=i[a]){c=n[a]>i[a]?1:-1;break}return c}function e(n,i,o,s){for(var a=0;o--;)n[o]-=a,a=n[o]<i[o]?1:0,n[o]=a*s+n[o]-i[o];for(;!n[0]&&n.length>1;)n.shift()}return function(n,i,o,s,a,c){var u,l,m,d,p,y,f,b,g,A,w,k,I,h,x,K,S,B,C,L,O=n.constructor,E=n.s==i.s?1:-1,q=n.d,_=i.d;if(!q||!q[0]||!_||!_[0])return new O(!n.s||!i.s||(q?_&&q[0]==_[0]:!_)?NaN:q&&q[0]==0||!_?E*0:E/0);for(c?(p=1,l=n.e-i.e):(c=qt,p=re,l=mt(n.e/p)-mt(i.e/p)),C=_.length,S=q.length,g=new O(E),A=g.d=[],m=0;_[m]==(q[m]||0);m++);if(_[m]>(q[m]||0)&&l--,o==null?(h=o=O.precision,s=O.rounding):a?h=o+(n.e-i.e)+1:h=o,h<0)A.push(1),y=!0;else{if(h=h/p+2|0,m=0,C==1){for(d=0,_=_[0],h++;(m<S||d)&&h--;m++)x=d*c+(q[m]||0),A[m]=x/_|0,d=x%_|0;y=d||m<S}else{for(d=c/(_[0]+1)|0,d>1&&(_=r(_,d,c),q=r(q,d,c),C=_.length,S=q.length),K=C,w=q.slice(0,C),k=w.length;k<C;)w[k++]=0;L=_.slice(),L.unshift(0),B=_[0],_[1]>=c/2&&++B;do d=0,u=t(_,w,C,k),u<0?(I=w[0],C!=k&&(I=I*c+(w[1]||0)),d=I/B|0,d>1?(d>=c&&(d=c-1),f=r(_,d,c),b=f.length,k=w.length,u=t(f,w,b,k),u==1&&(d--,e(f,C<b?L:_,b,c))):(d==0&&(u=d=1),f=_.slice()),b=f.length,b<k&&f.unshift(0),e(w,f,k,c),u==-1&&(k=w.length,u=t(_,w,C,k),u<1&&(d++,e(w,C<k?L:_,k,c))),k=w.length):u===0&&(d++,w=[0]),A[m++]=d,u&&w[0]?w[k++]=q[K]||0:(w=[q[K]],k=1);while((K++<S||w[0]!==void 0)&&h--);y=w[0]!==void 0}A[0]||A.shift()}if(p==1)g.e=l,Na=y;else{for(m=1,d=A[0];d>=10;d/=10)m++;g.e=m+l*p-1,ie(g,a?o+g.e+1:o,s,y)}return g}}();function ie(r,t,e,n){var i,o,s,a,c,u,l,m,d,p=r.constructor;e:if(t!=null){if(m=r.d,!m)return r;for(i=1,a=m[0];a>=10;a/=10)i++;if(o=t-i,o<0)o+=re,s=t,l=m[d=0],c=l/je(10,i-s-1)%10|0;else if(d=Math.ceil((o+1)/re),a=m.length,d>=a)if(n){for(;a++<=d;)m.push(0);l=c=0,i=1,o%=re,s=o-re+1}else break e;else{for(l=a=m[d],i=1;a>=10;a/=10)i++;o%=re,s=o-re+i,c=s<0?0:l/je(10,i-s-1)%10|0}if(n=n||t<0||m[d+1]!==void 0||(s<0?l:l%je(10,i-s-1)),u=e<4?(c||n)&&(e==0||e==(r.s<0?3:2)):c>5||c==5&&(e==4||n||e==6&&(o>0?s>0?l/je(10,i-s):0:m[d-1])%10&1||e==(r.s<0?8:7)),t<1||!m[0])return m.length=0,u?(t-=r.e+1,m[0]=je(10,(re-t%re)%re),r.e=-t||0):m[0]=r.e=0,r;if(o==0?(m.length=d,a=1,d--):(m.length=d+1,a=je(10,re-o),m[d]=s>0?(l/je(10,i-s)%je(10,s)|0)*a:0),u)for(;;)if(d==0){for(o=1,s=m[0];s>=10;s/=10)o++;for(s=m[0]+=a,a=1;s>=10;s/=10)a++;o!=a&&(r.e++,m[0]==qt&&(m[0]=1));break}else{if(m[d]+=a,m[d]!=qt)break;m[d--]=0,a=1}for(o=m.length;m[--o]===0;)m.pop()}return ue&&(r.e>p.maxE?(r.d=null,r.e=NaN):r.e<p.minE&&(r.e=0,r.d=[0])),r}function jt(r,t,e){if(!r.isFinite())return qa(r);var n,i=r.e,o=ot(r.d),s=o.length;return t?(e&&(n=e-s)>0?o=o.charAt(0)+"."+o.slice(1)+gn(n):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(r.e<0?"e":"e+")+r.e):i<0?(o="0."+gn(-i-1)+o,e&&(n=e-s)>0&&(o+=gn(n))):i>=s?(o+=gn(i+1-s),e&&(n=e-i-1)>0&&(o=o+"."+gn(n))):((n=i+1)<s&&(o=o.slice(0,n)+"."+o.slice(n)),e&&(n=e-s)>0&&(i+1===s&&(o+="."),o+=gn(n))),o}function So(r,t){var e=r[0];for(t*=re;e>=10;e/=10)t++;return t}function xo(r,t,e){if(t>hl)throw ue=!0,e&&(r.precision=e),Error(va);return ie(new r(Io),t,1,!0)}function Dt(r,t,e){if(t>Wr)throw Error(va);return ie(new r(Bo),t,e,!0)}function Fa(r){var t=r.length-1,e=t*re+1;if(t=r[t],t){for(;t%10==0;t/=10)e--;for(t=r[0];t>=10;t/=10)e++}return e}function gn(r){for(var t="";r--;)t+="0";return t}function Wa(r,t,e,n){var i,o=new r(1),s=Math.ceil(n/re+4);for(ue=!1;;){if(e%2&&(o=o.times(t),Oa(o.d,s)&&(i=!0)),e=mt(e/2),e===0){e=o.d.length-1,i&&o.d[e]===0&&++o.d[e];break}t=t.times(t),Oa(t.d,s)}return ue=!0,o}function Ra(r){return r.d[r.d.length-1]&1}function Da(r,t,e){for(var n,i=new r(t[0]),o=0;++o<t.length;)if(n=new r(t[o]),n.s)i[e](n)&&(i=n);else{i=n;break}return i}function Dr(r,t){var e,n,i,o,s,a,c,u=0,l=0,m=0,d=r.constructor,p=d.rounding,y=d.precision;if(!r.d||!r.d[0]||r.e>17)return new d(r.d?r.d[0]?r.s<0?0:1/0:1:r.s?r.s<0?0:r:0/0);for(t==null?(ue=!1,c=y):c=t,a=new d(.03125);r.e>-2;)r=r.times(a),m+=5;for(n=Math.log(je(2,m))/Math.LN10*2+5|0,c+=n,e=o=s=new d(1),d.precision=c;;){if(o=ie(o.times(r),c,1),e=e.times(++l),a=s.plus(Re(o,e,c,1)),ot(a.d).slice(0,c)===ot(s.d).slice(0,c)){for(i=m;i--;)s=ie(s.times(s),c,1);if(t==null)if(u<3&&Ai(s.d,c-n,p,u))d.precision=c+=10,e=o=a=new d(1),l=0,u++;else return ie(s,d.precision=y,p,ue=!0);else return d.precision=y,s}s=a}}function Pn(r,t){var e,n,i,o,s,a,c,u,l,m,d,p=1,y=10,f=r,b=f.d,g=f.constructor,A=g.rounding,w=g.precision;if(f.s<0||!b||!b[0]||!f.e&&b[0]==1&&b.length==1)return new g(b&&!b[0]?-1/0:f.s!=1?NaN:b?0:f);if(t==null?(ue=!1,l=w):l=t,g.precision=l+=y,e=ot(b),n=e.charAt(0),Math.abs(o=f.e)<15e14){for(;n<7&&n!=1||n==1&&e.charAt(1)>3;)f=f.times(r),e=ot(f.d),n=e.charAt(0),p++;o=f.e,n>1?(f=new g("0."+e),o++):f=new g(n+"."+e.slice(1))}else return u=xo(g,l+2,w).times(o+""),f=Pn(new g(n+"."+e.slice(1)),l-y).plus(u),g.precision=w,t==null?ie(f,w,A,ue=!0):f;for(m=f,c=s=f=Re(f.minus(1),f.plus(1),l,1),d=ie(f.times(f),l,1),i=3;;){if(s=ie(s.times(d),l,1),u=c.plus(Re(s,new g(i),l,1)),ot(u.d).slice(0,l)===ot(c.d).slice(0,l))if(c=c.times(2),o!==0&&(c=c.plus(xo(g,l+2,w).times(o+""))),c=Re(c,new g(p),l,1),t==null)if(Ai(c.d,l-y,A,a))g.precision=l+=y,u=s=f=Re(m.minus(1),m.plus(1),l,1),d=ie(f.times(f),l,1),i=a=1;else return ie(c,g.precision=w,A,ue=!0);else return g.precision=w,c;c=u,i+=2}}function qa(r){return String(r.s*r.s/0)}function qr(r,t){var e,n,i;for((e=t.indexOf("."))>-1&&(t=t.replace(".","")),(n=t.search(/e/i))>0?(e<0&&(e=n),e+=+t.slice(n+1),t=t.substring(0,n)):e<0&&(e=t.length),n=0;t.charCodeAt(n)===48;n++);for(i=t.length;t.charCodeAt(i-1)===48;--i);if(t=t.slice(n,i),t){if(i-=n,r.e=e=e-n-1,r.d=[],n=(e+1)%re,e<0&&(n+=re),n<i){for(n&&r.d.push(+t.slice(0,n)),i-=re;n<i;)r.d.push(+t.slice(n,n+=re));t=t.slice(n),n=re-t.length}else n-=i;for(;n--;)t+="0";r.d.push(+t),ue&&(r.e>r.constructor.maxE?(r.d=null,r.e=NaN):r.e<r.constructor.minE&&(r.e=0,r.d=[0]))}else r.e=0,r.d=[0];return r}function Il(r,t){var e,n,i,o,s,a,c,u,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Ea.test(t))return qr(r,t)}else if(t==="Infinity"||t==="NaN")return+t||(r.s=NaN),r.e=NaN,r.d=null,r;if(Al.test(t))e=16,t=t.toLowerCase();else if(Pl.test(t))e=2;else if(wl.test(t))e=8;else throw Error(An+t);for(o=t.search(/p/i),o>0?(c=+t.slice(o+1),t=t.substring(2,o)):t=t.slice(2),o=t.indexOf("."),s=o>=0,n=r.constructor,s&&(t=t.replace(".",""),a=t.length,o=a-o,i=Wa(n,new n(e),o,o*2)),u=To(t,e,qt),l=u.length-1,o=l;u[o]===0;--o)u.pop();return o<0?new n(r.s*0):(r.e=So(u,l),r.d=u,ue=!1,s&&(r=Re(r,i,a*4)),c&&(r=r.times(Math.abs(c)<54?je(2,c):wi.pow(2,c))),ue=!0,r)}function Bl(r,t){var e,n=t.d.length;if(n<3)return t.isZero()?t:ei(r,2,t,t);e=1.4*Math.sqrt(n),e=e>16?16:e|0,t=t.times(1/Co(5,e)),t=ei(r,2,t,t);for(var i,o=new r(5),s=new r(16),a=new r(20);e--;)i=t.times(t),t=t.times(o.plus(i.times(s.times(i).minus(a))));return t}function ei(r,t,e,n,i){var o,s,a,c,u=1,l=r.precision,m=Math.ceil(l/re);for(ue=!1,c=e.times(e),a=new r(n);;){if(s=Re(a.times(c),new r(t++*t++),l,1),a=i?n.plus(s):n.minus(s),n=Re(s.times(c),new r(t++*t++),l,1),s=a.plus(n),s.d[m]!==void 0){for(o=m;s.d[o]===a.d[o]&&o--;);if(o==-1)break}o=a,a=n,n=s,s=o,u++}return ue=!0,s.d.length=m+1,s}function Co(r,t){for(var e=r;--t;)e*=r;return e}function Ua(r,t){var e,n=t.s<0,i=Dt(r,r.precision,1),o=i.times(.5);if(t=t.abs(),t.lte(o))return on=n?4:1,t;if(e=t.divToInt(i),e.isZero())on=n?3:2;else{if(t=t.minus(e.times(i)),t.lte(o))return on=Ra(e)?n?2:3:n?4:1,t;on=Ra(e)?n?1:4:n?3:2}return t.minus(i).abs()}function Ur(r,t,e,n){var i,o,s,a,c,u,l,m,d,p=r.constructor,y=e!==void 0;if(y?(Tt(e,1,wn),n===void 0?n=p.rounding:Tt(n,0,8)):(e=p.precision,n=p.rounding),!r.isFinite())l=qa(r);else{for(l=jt(r),s=l.indexOf("."),y?(i=2,t==16?e=e*4-3:t==8&&(e=e*3-2)):i=t,s>=0&&(l=l.replace(".",""),d=new p(1),d.e=l.length-s,d.d=To(jt(d),10,i),d.e=d.d.length),m=To(l,10,i),o=c=m.length;m[--c]==0;)m.pop();if(!m[0])l=y?"0p+0":"0";else{if(s<0?o--:(r=new p(r),r.d=m,r.e=o,r=Re(r,d,e,n,0,i),m=r.d,o=r.e,u=Na),s=m[e],a=i/2,u=u||m[e+1]!==void 0,u=n<4?(s!==void 0||u)&&(n===0||n===(r.s<0?3:2)):s>a||s===a&&(n===4||u||n===6&&m[e-1]&1||n===(r.s<0?8:7)),m.length=e,u)for(;++m[--e]>i-1;)m[e]=0,e||(++o,m.unshift(1));for(c=m.length;!m[c-1];--c);for(s=0,l="";s<c;s++)l+=Er.charAt(m[s]);if(y){if(c>1)if(t==16||t==8){for(s=t==16?4:3,--c;c%s;c++)l+="0";for(m=To(l,i,t),c=m.length;!m[c-1];--c);for(s=1,l="1.";s<c;s++)l+=Er.charAt(m[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)l="0"+l;l="0."+l}else if(++o>c)for(o-=c;o--;)l+="0";else o<c&&(l=l.slice(0,o)+"."+l.slice(o))}l=(t==16?"0x":t==2?"0b":t==8?"0o":"")+l}return r.s<0?"-"+l:l}function Oa(r,t){if(r.length>t)return r.length=t,!0}function xl(r){return new this(r).abs()}function Kl(r){return new this(r).acos()}function Sl(r){return new this(r).acosh()}function Cl(r,t){return new this(r).plus(t)}function Ll(r){return new this(r).asin()}function Rl(r){return new this(r).asinh()}function Ol(r){return new this(r).atan()}function Ml(r){return new this(r).atanh()}function Nl(r,t){r=new this(r),t=new this(t);var e,n=this.precision,i=this.rounding,o=n+4;return!r.s||!t.s?e=new this(NaN):!r.d&&!t.d?(e=Dt(this,o,1).times(t.s>0?.25:.75),e.s=r.s):!t.d||r.isZero()?(e=t.s<0?Dt(this,n,i):new this(0),e.s=r.s):!r.d||t.isZero()?(e=Dt(this,o,1).times(.5),e.s=r.s):t.s<0?(this.precision=o,this.rounding=1,e=this.atan(Re(r,t,o,1)),t=Dt(this,o,1),this.precision=n,this.rounding=i,e=r.s<0?e.minus(t):e.plus(t)):e=this.atan(Re(r,t,o,1)),e}function vl(r){return new this(r).cbrt()}function Vl(r){return ie(r=new this(r),r.e+1,2)}function _l(r,t,e){return new this(r).clamp(t,e)}function El(r){if(!r||typeof r!="object")throw Error(Ko+"Object expected");var t,e,n,i=r.defaults===!0,o=["precision",1,wn,"rounding",0,8,"toExpNeg",-Jn,0,"toExpPos",0,Jn,"maxE",0,Jn,"minE",-Jn,0,"modulo",0,9];for(t=0;t<o.length;t+=3)if(e=o[t],i&&(this[e]=Fr[e]),(n=r[e])!==void 0)if(mt(n)===n&&n>=o[t+1]&&n<=o[t+2])this[e]=n;else throw Error(An+e+": "+n);if(e="crypto",i&&(this[e]=Fr[e]),(n=r[e])!==void 0)if(n===!0||n===!1||n===0||n===1)if(n)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[e]=!0;else throw Error(Va);else this[e]=!1;else throw Error(An+e+": "+n);return this}function Fl(r){return new this(r).cos()}function Wl(r){return new this(r).cosh()}function Ga(r){var t,e,n;function i(o){var s,a,c,u=this;if(!(u instanceof i))return new i(o);if(u.constructor=i,Ma(o)){u.s=o.s,ue?!o.d||o.e>i.maxE?(u.e=NaN,u.d=null):o.e<i.minE?(u.e=0,u.d=[0]):(u.e=o.e,u.d=o.d.slice()):(u.e=o.e,u.d=o.d?o.d.slice():o.d);return}if(c=typeof o,c==="number"){if(o===0){u.s=1/o<0?-1:1,u.e=0,u.d=[0];return}if(o<0?(o=-o,u.s=-1):u.s=1,o===~~o&&o<1e7){for(s=0,a=o;a>=10;a/=10)s++;ue?s>i.maxE?(u.e=NaN,u.d=null):s<i.minE?(u.e=0,u.d=[0]):(u.e=s,u.d=[o]):(u.e=s,u.d=[o]);return}else if(o*0!==0){o||(u.s=NaN),u.e=NaN,u.d=null;return}return qr(u,o.toString())}else if(c!=="string")throw Error(An+o);return(a=o.charCodeAt(0))===45?(o=o.slice(1),u.s=-1):(a===43&&(o=o.slice(1)),u.s=1),Ea.test(o)?qr(u,o):Il(u,o)}if(i.prototype=U,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=El,i.clone=Ga,i.isDecimal=Ma,i.abs=xl,i.acos=Kl,i.acosh=Sl,i.add=Cl,i.asin=Ll,i.asinh=Rl,i.atan=Ol,i.atanh=Ml,i.atan2=Nl,i.cbrt=vl,i.ceil=Vl,i.clamp=_l,i.cos=Fl,i.cosh=Wl,i.div=Dl,i.exp=ql,i.floor=Ul,i.hypot=Gl,i.ln=Xl,i.log=zl,i.log10=Yl,i.log2=Ql,i.max=Hl,i.min=jl,i.mod=Zl,i.mul=$l,i.pow=Jl,i.random=em,i.round=tm,i.sign=nm,i.sin=im,i.sinh=om,i.sqrt=rm,i.sub=sm,i.sum=am,i.tan=um,i.tanh=cm,i.trunc=lm,r===void 0&&(r={}),r&&r.defaults!==!0)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<n.length;)r.hasOwnProperty(e=n[t++])||(r[e]=this[e]);return i.config(r),i}function Dl(r,t){return new this(r).div(t)}function ql(r){return new this(r).exp()}function Ul(r){return ie(r=new this(r),r.e+1,3)}function Gl(){var r,t,e=new this(0);for(ue=!1,r=0;r<arguments.length;)if(t=new this(arguments[r++]),t.d)e.d&&(e=e.plus(t.times(t)));else{if(t.s)return ue=!0,new this(1/0);e=t}return ue=!0,e.sqrt()}function Ma(r){return r instanceof wi||r&&r.toStringTag===_a||!1}function Xl(r){return new this(r).ln()}function zl(r,t){return new this(r).log(t)}function Ql(r){return new this(r).log(2)}function Yl(r){return new this(r).log(10)}function Hl(){return Da(this,arguments,"lt")}function jl(){return Da(this,arguments,"gt")}function Zl(r,t){return new this(r).mod(t)}function $l(r,t){return new this(r).mul(t)}function Jl(r,t){return new this(r).pow(t)}function em(r){var t,e,n,i,o=0,s=new this(1),a=[];if(r===void 0?r=this.precision:Tt(r,1,wn),n=Math.ceil(r/re),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(n));o<n;)i=t[o],i>=429e7?t[o]=crypto.getRandomValues(new Uint32Array(1))[0]:a[o++]=i%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(n*=4);o<n;)i=t[o]+(t[o+1]<<8)+(t[o+2]<<16)+((t[o+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(t,o):(a.push(i%1e7),o+=4);o=n/4}else throw Error(Va);else for(;o<n;)a[o++]=Math.random()*1e7|0;for(n=a[--o],r%=re,n&&r&&(i=je(10,re-r),a[o]=(n/i|0)*i);a[o]===0;o--)a.pop();if(o<0)e=0,a=[0];else{for(e=-1;a[0]===0;e-=re)a.shift();for(n=1,i=a[0];i>=10;i/=10)n++;n<re&&(e-=re-n)}return s.e=e,s.d=a,s}function tm(r){return ie(r=new this(r),r.e+1,this.rounding)}function nm(r){return r=new this(r),r.d?r.d[0]?r.s:0*r.s:r.s||NaN}function im(r){return new this(r).sin()}function om(r){return new this(r).sinh()}function rm(r){return new this(r).sqrt()}function sm(r,t){return new this(r).sub(t)}function am(){var r=0,t=arguments,e=new this(t[r]);for(ue=!1;e.s&&++r<t.length;)e=e.plus(t[r]);return ue=!0,ie(e,this.precision,this.rounding)}function um(r){return new this(r).tan()}function cm(r){return new this(r).tanh()}function lm(r){return ie(r=new this(r),r.e+1,1)}U[Symbol.for("nodejs.util.inspect.custom")]=U.toString;U[Symbol.toStringTag]="Decimal";var wi=U.constructor=Ga(Fr);Io=new wi(Io);Bo=new wi(Bo);var V=wi;import Pm from"big.js";import Oo from"bn.js";import mm from"toformat";var dm=mm,ki=dm;import Ro from"big.js";import fm from"bn.js";import ym from"decimal.js-light";import hi from"bn.js";var Xa=9007199254740991;function ne(r){let t=fe("Raydium_parseBigNumberish");if(r instanceof hi)return r;if(typeof r=="string"){if(r.match(/^-?[0-9]+$/))return new hi(r);t.logWithError(`invalid BigNumberish string: ${r}`)}return typeof r=="number"?(r%1&&t.logWithError(`BigNumberish number underflow: ${r}`),(r>=Xa||r<=-Xa)&&t.logWithError(`BigNumberish number overflow: ${r}`),new hi(String(r))):typeof r=="bigint"?new hi(r.toString()):(t.error(`invalid BigNumberish value: ${r}`),new hi(0))}var Lo=fe("module/fraction"),Gr=ki(Ro),Ti=ki(ym),bm={[0]:Ti.ROUND_DOWN,[1]:Ti.ROUND_HALF_UP,[2]:Ti.ROUND_UP},gm={[0]:Ro.roundDown,[1]:Ro.roundHalfUp,[2]:Ro.roundUp},ke=class{constructor(t,e=new fm(1)){this.numerator=ne(t),this.denominator=ne(e)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new ke(this.denominator,this.numerator)}add(t){let e=t instanceof ke?t:new ke(ne(t));return this.denominator.eq(e.denominator)?new ke(this.numerator.add(e.numerator),this.denominator):new ke(this.numerator.mul(e.denominator).add(e.numerator.mul(this.denominator)),this.denominator.mul(e.denominator))}sub(t){let e=t instanceof ke?t:new ke(ne(t));return this.denominator.eq(e.denominator)?new ke(this.numerator.sub(e.numerator),this.denominator):new ke(this.numerator.mul(e.denominator).sub(e.numerator.mul(this.denominator)),this.denominator.mul(e.denominator))}mul(t){let e=t instanceof ke?t:new ke(ne(t));return new ke(this.numerator.mul(e.numerator),this.denominator.mul(e.denominator))}div(t){let e=t instanceof ke?t:new ke(ne(t));return new ke(this.numerator.mul(e.denominator),this.denominator.mul(e.numerator))}toSignificant(t,e={groupSeparator:""},n=1){Number.isInteger(t)||Lo.logWithError(`${t} is not an integer.`),t<=0&&Lo.logWithError(`${t} is not positive.`),Ti.set({precision:t+1,rounding:bm[n]});let i=new Ti(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return i.toFormat(i.decimalPlaces(),e)}toFixed(t,e={groupSeparator:""},n=1){return Number.isInteger(t)||Lo.logWithError(`${t} is not an integer.`),t<0&&Lo.logWithError(`${t} is negative.`),Gr.DP=t,Gr.RM=gm[n]||1,new Gr(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,e)}isZero(){return this.numerator.isZero()}};var Am=fe("Raydium_amount"),za=ki(Pm);function wm(r,t){let e="0",n="0";if(r.includes(".")){let i=r.split(".");i.length===2?([e,n]=i,n=n.padEnd(t,"0")):Am.logWithError(`invalid number string, num: ${r}`)}else e=r;return[e,n.slice(0,t)||n]}var xe=class extends ke{constructor(e,n,i=!0,o){let s=new Oo(0),a=Xr.pow(new Oo(e.decimals));if(i)s=ne(n);else{let c=new Oo(0),u=new Oo(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[l,m]=wm(n.toString(),e.decimals);c=ne(l),u=ne(m)}c=c.mul(a),s=c.add(u)}super(s,a);this.logger=fe(o||"TokenAmount"),this.token=e}get raw(){return this.numerator}isZero(){return this.raw.isZero()}gt(e){return this.token.equals(e.token)||this.logger.logWithError("gt token not equals"),this.raw.gt(e.raw)}lt(e){return this.token.equals(e.token)||this.logger.logWithError("lt token not equals"),this.raw.lt(e.raw)}add(e){return this.token.equals(e.token)||this.logger.logWithError("add token not equals"),new xe(this.token,this.raw.add(e.raw))}subtract(e){return this.token.equals(e.token)||this.logger.logWithError("sub token not equals"),new xe(this.token,this.raw.sub(e.raw))}toSignificant(e=this.token.decimals,n,i=0){return super.toSignificant(e,n,i)}toFixed(e=this.token.decimals,n,i=0){return e>this.token.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(e,n,i)}toExact(e={groupSeparator:""}){return za.DP=this.token.decimals,new za(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}};import{PublicKey as km}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Qa}from"@solana/spl-token";var Zt={chainId:101,address:km.default.toBase58(),programId:Qa.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},Je={chainId:101,address:"So11111111111111111111111111111111111111112",programId:Qa.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 jr}from"@solana/web3.js";import{PublicKey as Ne,SystemProgram as Ya,SYSVAR_RENT_PUBKEY as hm}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Tm}from"@solana/spl-token";function P({pubkey:r,isSigner:t=!1,isWritable:e=!0}){return{pubkey:r,isWritable:e,isSigner:t}}var zr=[P({pubkey:Tm,isWritable:!1}),P({pubkey:Ya.programId,isWritable:!1}),P({pubkey:hm,isWritable:!1})];function Qr({publicKey:r,transformSol:t}){let e=Yr(r.toString());if(e instanceof Ne)return t&&e.equals(et)?$:e;if(t&&e.toString()===et.toBase58())return $;if(typeof e=="string"){if(e===Ne.default.toBase58())return Ne.default;try{return new Ne(e)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function Yr(r){try{return new Ne(r)}catch{return r}}var Vn=new Ne("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),$t=new Ne("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),ze=new Ne("SysvarRent111111111111111111111111111111111"),Hr=new Ne("SysvarC1ock11111111111111111111111111111111"),rn=new Ne("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Mo=new Ne("Sysvar1nstructions1111111111111111111111111"),No=Ya.programId,oy=new Ne("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),ry=new Ne("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),sy=new Ne("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),ay=new Ne("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),uy=new Ne("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),cy=new Ne("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),ly=new Ne("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),my=new Ne("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),dy=new Ne("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),py=new Ne("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),fy=new Ne("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),$=new Ne("So11111111111111111111111111111111111111112"),et=Ne.default;function lt(r){return Qr({publicKey:r,transformSol:!0})}var Zr=class{constructor({mint:t,decimals:e,symbol:n,name:i,skipMint:o=!1,isToken2022:s=!1}){if(t===et.toBase58()||t instanceof jr&&et.equals(t)){this.decimals=Je.decimals,this.symbol=Je.symbol,this.name=Je.name,this.mint=new jr(Je.address),this.isToken2022=!1;return}this.decimals=e,this.symbol=n||t.toString().substring(0,6),this.name=i||t.toString().substring(0,6),this.mint=o?jr.default:Qr({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},ve=Zr;ve.WSOL=new Zr(X(N({},Je),{mint:Je.address}));var $r=class{constructor({decimals:t,symbol:e="UNKNOWN",name:n="UNKNOWN"}){this.decimals=t,this.symbol=e,this.name=n}equals(t){return this===t}},vo=$r;vo.SOL=new $r(Zt);import Im from"bn.js";var Ha=new ke(new Im(100)),tt=class extends ke{toSignificant(t=5,e,n){return this.mul(Ha).toSignificant(t,e,n)}toFixed(t=2,e,n){return this.mul(Ha).toFixed(t,e,n)}};var Bm=fe("Raydium_price"),It=class extends ke{constructor(e){let{baseToken:n,quoteToken:i,numerator:o,denominator:s}=e;super(o,s);this.baseToken=n,this.quoteToken=i,this.scalar=new ke(Jr(n.decimals),Jr(i.decimals))}get raw(){return new ke(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new It({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numerator,numerator:this.denominator})}mul(e){this.quoteToken!==e.baseToken&&Bm.logWithError("mul token not equals");let n=super.mul(e);return new It({baseToken:this.baseToken,quoteToken:e.quoteToken,denominator:n.denominator,numerator:n.numerator})}toSignificant(e=this.quoteToken.decimals,n,i){return this.adjusted.toSignificant(e,n,i)}toFixed(e=this.quoteToken.decimals,n,i){return this.adjusted.toFixed(e,n,i)}};import{PublicKey as xm}from"@solana/web3.js";import Km from"bn.js";function ja(r){return typeof r=="object"&&r!==null&&![ve,xe,xm,ke,Km,It,tt].some(t=>typeof t=="object"&&r instanceof t)}function Oe(r){return typeof r=="string"?Yr(r):Array.isArray(r)?r.map(t=>Oe(t)):ja(r)?Object.fromEntries(Object.entries(r).map(([t,e])=>[t,Oe(e)])):r}var Bt=new sn(0),Za=new sn(1),cb=new sn(2),lb=new sn(3),mb=new sn(5),Xr=new sn(10),db=new sn(100),pb=new sn(1e3),fb=new sn(1e4);function Jr(r){return Xr.pow(ne(r))}function Vo(r,t){let e=r.divmod(t);return e.mod.isZero()?e.div:e.div.isNeg()?e.div.isubn(1):e.div.iaddn(1)}var $a=r=>typeof r=="number";function Ja(r,t,e){let n=$a(t)?t*((e==null?void 0:e.unit)==="s"?1e3:1):t;return new Date(r).getTime()<=n}function eu(r,t,e){let n=$a(t)?t*((e==null?void 0:e.unit)==="s"?1e3:1):t;return new Date(r).getTime()>n}function _r(r,t=1,e=[]){let n=[...r];if(t<=0)return e;for(;n.length;)e.push(n.splice(0,t));return e}var Ut=class{constructor(t){this._owner=t}get publicKey(){return Ut.isKeyPair(this._owner)?this._owner.publicKey:this._owner}get signer(){return Ut.isKeyPair(this._owner)?this._owner:void 0}get isKeyPair(){return Ut.isKeyPair(this._owner)}get isPublicKey(){return Ut.isPublicKey(this._owner)}static isKeyPair(t){return t.secretKey!==void 0}static isPublicKey(t){return!Ut.isKeyPair(t)}};import{PublicKey as Mm}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Nm}from"@solana/spl-token";import{ComputeBudgetProgram as tu,Keypair as nu,PublicKey as iu,Transaction as _o,TransactionMessage as Sm,VersionedTransaction as ou}from"@solana/web3.js";var F={CreateAccount:"CreateAccount",InitAccount:"InitAccount",CreateATA:"CreateATA",CloseAccount:"CloseAccount",TransferAmount:"TransferAmount",InitMint:"InitMint",MintTo:"MintTo",InitMarket:"InitMarket",Util1216OwnerClaim:"Util1216OwnerClaim",SetComputeUnitPrice:"SetComputeUnitPrice",SetComputeUnitLimit:"SetComputeUnitLimit",ClmmCreatePool:"ClmmCreatePool",ClmmOpenPosition:"ClmmOpenPosition",ClmmIncreasePosition:"ClmmIncreasePosition",ClmmDecreasePosition:"ClmmDecreasePosition",ClmmClosePosition:"ClmmClosePosition",ClmmSwapBaseIn:"ClmmSwapBaseIn",ClmmSwapBaseOut:"ClmmSwapBaseOut",ClmmInitReward:"ClmmInitReward",ClmmSetReward:"ClmmSetReward",ClmmCollectReward:"ClmmCollectReward",ClmmLockPosition:"ClmmLockPosition",ClmmHarvestLockPosition:"ClmmHarvestLockPosition",CustodyInitializeUser:"CustodyInitializeUser",CustodyDeposit:"CustodyDeposit",CustodyWithdraw:"CustodyWithdraw",CustodyOpenPosition:"CustodyOpenPosition",CustodyClosePosition:"CustodyClosePosition",CustodyIncreasePosition:"CustodyIncreasePosition",CustodyDecreasePosition:"CustodyDecreasePosition",CustodySwapBaseIn:"CustodySwapBaseIn",CustodySwapBaseOut:"CustodySwapBaseOut",AmmV4Swap:"AmmV4Swap",AmmV4AddLiquidity:"AmmV4AddLiquidity",AmmV4RemoveLiquidity:"AmmV4RemoveLiquidity",AmmV4SimulatePoolInfo:"AmmV4SimulatePoolInfo",AmmV4SwapBaseIn:"AmmV4SwapBaseIn",AmmV4SwapBaseOut:"AmmV4SwapBaseOut",AmmV4CreatePool:"AmmV4CreatePool",AmmV4InitPool:"AmmV4InitPool",AmmV5AddLiquidity:"AmmV5AddLiquidity",AmmV5RemoveLiquidity:"AmmV5RemoveLiquidity",AmmV5SimulatePoolInfo:"AmmV5SimulatePoolInfo",AmmV5SwapBaseIn:"AmmV5SwapBaseIn",AmmV5SwapBaseOut:"AmmV5SwapBaseOut",RouteSwap:"RouteSwap",RouteSwap1:"RouteSwap1",RouteSwap2:"RouteSwap2",FarmV3Deposit:"FarmV3Deposit",FarmV3Withdraw:"FarmV3Withdraw",FarmV3CreateLedger:"FarmV3CreateLedger",FarmV4Withdraw:"FarmV4Withdraw",FarmV5Deposit:"FarmV5Deposit",FarmV5Withdraw:"FarmV5Withdraw",FarmV5CreateLedger:"FarmV5CreateLedger",FarmV6Deposit:"FarmV6Deposit",FarmV6Withdraw:"FarmV6Withdraw",FarmV6Create:"FarmV6Create",FarmV6Restart:"FarmV6Restart",FarmV6CreatorAddReward:"FarmV6CreatorAddReward",FarmV6CreatorWithdraw:"FarmV6CreatorWithdraw",CpmmCreatePool:"CpmmCreatePool",CpmmAddLiquidity:"CpmmAddLiquidity",CpmmWithdrawLiquidity:"CpmmWithdrawLiquidity",CpmmSwapBaseIn:"CpmmSwapBaseIn",CpmmSwapBaseOut:"CpmmSwapBaseOut",CpmmLockLp:"CpmmLockLp",CpmmCollectLockFee:"CpmmCollectLockFee",TransferTip:"TransferTip"};import{TOKEN_PROGRAM_ID as Cm}from"@solana/spl-token";var an=fe("Raydium_txUtil"),ru=1644;function Eo(r){let t=[],e=[];return r.microLamports&&(t.push(tu.setComputeUnitPrice({microLamports:r.microLamports})),e.push(F.SetComputeUnitPrice)),r.units&&(t.push(tu.setComputeUnitLimit({units:r.units})),e.push(F.SetComputeUnitLimit)),{instructions:t,instructionTypes:e}}async function ti(r,t){var n,i;let e=t!=null?t:"confirmed";return(i=await((n=r.getLatestBlockhash)==null?void 0:n.call(r,{commitment:e})))==null?void 0:i.blockhash}async function Fo(r,t){return r.getSignatureStatuses([t]),new Promise((e,n)=>{let i=setTimeout(n,6e4);r.onSignature(t,o=>{if(clearTimeout(i),!o.err){e("");return}n(Object.assign(o.err,{txId:t}))},"confirmed")})}function Wo(r,t){r.length<1&&an.logWithError(`no instructions provided: ${r.toString()}`),t.length<1&&an.logWithError(`no signers provided:, ${t.toString()}`);let e=new _o;e.recentBlockhash="11111111111111111111111111111111",e.feePayer=t[0],e.add(...r);try{return Buffer.from(e.serialize({verifySignatures:!1})).toString("base64").length<ru}catch{return!1}}async function su(r,t,e,n=!0){let i=new iu("RaydiumSimuLateTransaction11111111111111111"),o=[],s=new _o;s.feePayer=i;for(let u of t)Wo([...s.instructions,u],[i])||(o.push(s),s=new _o,s.feePayer=i),s.add(u);s.instructions.length>0&&o.push(s);let a=[];try{if(a=await Lm(r,o,n),a.find(u=>u.err!==null))throw Error("rpc simulateTransaction error")}catch(u){u instanceof Error&&an.logWithError("failed to simulate for instructions","RPC_ERROR",{message:u.message})}let c=[];for(let u of a)if(an.debug("simulate result:",u),u.logs){let l=u.logs.filter(m=>m&&m.includes(e));an.debug("filteredLog:",c),l.length||an.logWithError("simulate log not match keyword","keyword",e),c.push(...l)}return c}function au(r,t){let e=r.match(/{["\w:,]+}/g);return!e||e.length!==1?an.logWithError(`simulate log fail to match json, keyword: ${t}`):e[0]}function un(r,t){let n=new RegExp(`"${t}":(\\d+)`,"g").exec(r);return!n||n.length!==2?an.logWithError(`simulate log fail to match key", key: ${t}`):n[1]}function le(r,t){let[e,n]=iu.