UNPKG

@raydium-io/raydium-sdk-v2

Version:

An SDK for building applications on top of Raydium.

1 lines 487 kB
var Vm=Object.defineProperty,Wm=Object.defineProperties;var Dm=Object.getOwnPropertyDescriptors;var pr=Object.getOwnPropertySymbols;var ec=Object.prototype.hasOwnProperty,tc=Object.prototype.propertyIsEnumerable;var Ju=(r,e,t)=>e in r?Vm(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,_=(r,e)=>{for(var t in e||(e={}))ec.call(e,t)&&Ju(r,t,e[t]);if(pr)for(var t of pr(e))tc.call(e,t)&&Ju(r,t,e[t]);return r},U=(r,e)=>Wm(r,Dm(e));var He=(r,e)=>{var t={};for(var n in r)ec.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(r!=null&&pr)for(var n of pr(r))e.indexOf(n)<0&&tc.call(r,n)&&(t[n]=r[n]);return t};import{merge as ub}from"lodash";import _c from"axios";import{PublicKey as ic}from"@solana/web3.js";import{get as nc,set as qm}from"lodash";var Os=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}},oc={},Um={};function ke(r){let e=nc(oc,r);if(!e){let t=nc(Um,r);e=new Os({name:r,logLevel:t}),qm(oc,r,e)}return e}import{MINT_SIZE as Gm,TOKEN_PROGRAM_ID as Xm,getTransferFeeConfig as zm,unpackMint as Ym}from"@solana/spl-token";var Ms=ke("Raydium_accountInfo_util");async function cn(r,e,t){let{batchRequest:n,commitment:o="confirmed",chunkCount:i=100}=_({batchRequest:!1},t),s=vs(e,i),a=new Array(s.length).fill([]);if(n){let c=s.map(m=>{let d=r._buildArgs([m.map(p=>p.toBase58())],o,"base64");return{methodName:"getMultipleAccounts",args:d}}),u=vs(c,10);a=(await(await Promise.all(u.map(async m=>await r._rpcBatchRequest(m)))).flat()).map(m=>(m.error&&Ms.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"&&Ms.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(p[0],"base64"),executable:f,lamports:y,owner:new ic(b),rentEpoch:g}}return null})))}else try{a=await Promise.all(s.map(c=>r.getMultipleAccountsInfo(c,o)))}catch(c){c instanceof Error&&Ms.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return a.flat()}async function Ve(r,e,t){let n=await cn(r,e.map(o=>o.pubkey),t);return e.map((o,i)=>U(_({},o),{accountInfo:n[i]}))}async function Oo({connection:r,mints:e,config:t}){var i,s,a;if(e.length===0)return{};let n=await Ve(r,e.map(c=>({pubkey:wt(c)})),t),o={};for(let c of n){if(!c.accountInfo||c.accountInfo.data.length<Gm){console.log("invalid mint account",c.pubkey.toBase58());continue}let u=Ym(c.pubkey,c.accountInfo,(i=c.accountInfo)==null?void 0:i.owner);o[c.pubkey.toString()]=U(_({},u),{programId:((s=c.accountInfo)==null?void 0:s.owner)||Xm,feeConfig:(a=zm(u))!=null?a:void 0})}return o[ic.default.toBase58()]=o[$.toBase58()],o}import Tn from"bn.js";var Mo=9e15,Yn=1e9,Fs="0123456789abcdef",yr="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",br="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",_s={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Mo,maxE:Mo,crypto:!1},uc,Kn,ge=!0,Pr="[DecimalError] ",zn=Pr+"Invalid argument: ",cc=Pr+"Precision limit exceeded",lc=Pr+"crypto unavailable",mc="[object Decimal]",kt=Math.floor,st=Math.pow,Hm=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Qm=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,jm=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,dc=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,mn=1e7,pe=7,Zm=9007199254740991,$m=yr.length-1,Es=br.length-1,X={toStringTag:mc};X.absoluteValue=X.abs=function(){var r=new this.constructor(this);return r.s<0&&(r.s=1),se(r)};X.ceil=function(){return se(new this.constructor(this),this.e+1,2)};X.clampedTo=X.clamp=function(r,e){var t,n=this,o=n.constructor;if(r=new o(r),e=new o(e),!r.s||!e.s)return new o(NaN);if(r.gt(e))throw Error(zn+e);return t=n.cmp(r),t<0?r:n.cmp(e)>0?e:new o(n)};X.comparedTo=X.cmp=function(r){var e,t,n,o,i=this,s=i.d,a=(r=new i.constructor(r)).d,c=i.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(i.e!==r.e)return i.e>r.e^c<0?1:-1;for(n=s.length,o=a.length,e=0,t=n<o?n:o;e<t;++e)if(s[e]!==a[e])return s[e]>a[e]^c<0?1:-1;return n===o?0:n>o^c<0?1:-1};X.cosine=X.cos=function(){var r,e,t=this,n=t.constructor;return t.d?t.d[0]?(r=n.precision,e=n.rounding,n.precision=r+Math.max(t.e,t.sd())+pe,n.rounding=1,t=Jm(n,gc(n,t)),n.precision=r,n.rounding=e,se(Kn==2||Kn==3?t.neg():t,r,e,!0)):new n(1):new n(NaN)};X.cubeRoot=X.cbrt=function(){var r,e,t,n,o,i,s,a,c,u,l=this,m=l.constructor;if(!l.isFinite()||l.isZero())return new m(l);for(ge=!1,i=l.s*st(l.s*l,1/3),!i||Math.abs(i)==1/0?(t=bt(l.d),r=l.e,(i=(r-t.length+1)%3)&&(t+=i==1||i==-2?"0":"00"),i=st(t,1/3),r=kt((r+1)/3)-(r%3==(r<0?-1:2)),i==1/0?t="5e"+r:(t=i.toExponential(),t=t.slice(0,t.indexOf("e")+1)+r),n=new m(t),n.s=l.s):n=new m(i.toString()),s=(r=m.precision)+3;;)if(a=n,c=a.times(a).times(a),u=c.plus(l),n=We(u.plus(l).times(a),u.plus(c),s+2,1),bt(a.d).slice(0,s)===(t=bt(n.d)).slice(0,s))if(t=t.slice(s-3,s+1),t=="9999"||!o&&t=="4999"){if(!o&&(se(a,r+1,0),a.times(a).times(a).eq(l))){n=a;break}s+=4,o=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(se(n,r+1,1),e=!n.times(n).times(n).eq(l));break}return ge=!0,se(n,r,m.rounding,e)};X.decimalPlaces=X.dp=function(){var r,e=this.d,t=NaN;if(e){if(r=e.length-1,t=(r-kt(this.e/pe))*pe,r=e[r],r)for(;r%10==0;r/=10)t--;t<0&&(t=0)}return t};X.dividedBy=X.div=function(r){return We(this,new this.constructor(r))};X.dividedToIntegerBy=X.divToInt=function(r){var e=this,t=e.constructor;return se(We(e,new t(r),0,1,1),t.precision,t.rounding)};X.equals=X.eq=function(r){return this.cmp(r)===0};X.floor=function(){return se(new this.constructor(this),this.e+1,3)};X.greaterThan=X.gt=function(r){return this.cmp(r)>0};X.greaterThanOrEqualTo=X.gte=function(r){var e=this.cmp(r);return e==1||e===0};X.hyperbolicCosine=X.cosh=function(){var r,e,t,n,o,i=this,s=i.constructor,a=new s(1);if(!i.isFinite())return new s(i.s?1/0:NaN);if(i.isZero())return a;t=s.precision,n=s.rounding,s.precision=t+Math.max(i.e,i.sd())+4,s.rounding=1,o=i.d.length,o<32?(r=Math.ceil(o/3),e=(1/wr(4,r)).toString()):(r=16,e="2.3283064365386962890625e-10"),i=vo(s,1,i.times(e),new s(1),!0);for(var c,u=r,l=new s(8);u--;)c=i.times(i),i=a.minus(c.times(l.minus(c.times(l))));return se(i,s.precision=t,s.rounding=n,!0)};X.hyperbolicSine=X.sinh=function(){var r,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=vo(i,2,o,o,!0);else{r=1.4*Math.sqrt(n),r=r>16?16:r|0,o=o.times(1/wr(5,r)),o=vo(i,2,o,o,!0);for(var s,a=new i(5),c=new i(16),u=new i(20);r--;)s=o.times(o),o=o.times(a.plus(s.times(c.times(s).plus(u))))}return i.precision=e,i.rounding=t,se(o,e,t,!0)};X.hyperbolicTangent=X.tanh=function(){var r,e,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(r=n.precision,e=n.rounding,n.precision=r+7,n.rounding=1,We(t.sinh(),t.cosh(),n.precision=r,n.rounding=e)):new n(t.s)};X.inverseCosine=X.acos=function(){var r,e=this,t=e.constructor,n=e.abs().cmp(1),o=t.precision,i=t.rounding;return n!==-1?n===0?e.isNeg()?ln(t,o,i):new t(0):new t(NaN):e.isZero()?ln(t,o+4,i).times(.5):(t.precision=o+6,t.rounding=1,e=e.asin(),r=ln(t,o+4,i).times(.5),t.precision=o,t.rounding=i,r.minus(e))};X.inverseHyperbolicCosine=X.acosh=function(){var r,e,t=this,n=t.constructor;return t.lte(1)?new n(t.eq(1)?0:NaN):t.isFinite()?(r=n.precision,e=n.rounding,n.precision=r+Math.max(Math.abs(t.e),t.sd())+4,n.rounding=1,ge=!1,t=t.times(t).minus(1).sqrt().plus(t),ge=!0,n.precision=r,n.rounding=e,t.ln()):new n(t)};X.inverseHyperbolicSine=X.asinh=function(){var r,e,t=this,n=t.constructor;return!t.isFinite()||t.isZero()?new n(t):(r=n.precision,e=n.rounding,n.precision=r+2*Math.max(Math.abs(t.e),t.sd())+6,n.rounding=1,ge=!1,t=t.times(t).plus(1).sqrt().plus(t),ge=!0,n.precision=r,n.rounding=e,t.ln())};X.inverseHyperbolicTangent=X.atanh=function(){var r,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):(r=i.precision,e=i.rounding,n=o.sd(),Math.max(n,r)<2*-o.e-1?se(new i(o),r,e,!0):(i.precision=t=n-o.e,o=We(o.plus(1),new i(1).minus(o),t+r,1),i.precision=r+4,i.rounding=1,o=o.ln(),i.precision=r,i.rounding=e,o.times(.5))):new i(NaN)};X.inverseSine=X.asin=function(){var r,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?(r=ln(i,t+4,n).times(.5),r.s=o.s,r):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 r,e,t,n,o,i,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<=Es)return s=ln(l,m+4,d).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(m+4<=Es)return s=ln(l,m+4,d).times(.5),s.s=u.s,s}for(l.precision=a=m+10,l.rounding=1,t=Math.min(28,a/pe+2|0),r=t;r;--r)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(ge=!1,e=Math.ceil(a/pe),n=1,c=u.times(u),s=new l(u),o=u;r!==-1;)if(o=o.times(c),i=s.minus(o.div(n+=2)),o=o.times(c),s=i.plus(o.div(n+=2)),s.d[e]!==void 0)for(r=e;s.d[r]===i.d[r]&&r--;);return t&&(s=s.times(2<<t-1)),ge=!0,se(s,l.precision=m,l.rounding=d,!0)};X.isFinite=function(){return!!this.d};X.isInteger=X.isInt=function(){return!!this.d&&kt(this.e/pe)>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(r){return this.cmp(r)<0};X.lessThanOrEqualTo=X.lte=function(r){return this.cmp(r)<1};X.logarithm=X.log=function(r){var e,t,n,o,i,s,a,c,u=this,l=u.constructor,m=l.precision,d=l.rounding,p=5;if(r==null)r=new l(10),e=!0;else{if(r=new l(r),t=r.d,r.s<0||!t||!t[0]||r.eq(1))return new l(NaN);e=r.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(ge=!1,a=m+p,s=Xn(u,a),n=e?gr(l,a+10):Xn(r,a),c=We(s,n,a,1),ri(c.d,o=m,d))do if(a+=10,s=Xn(u,a),n=e?gr(l,a+10):Xn(r,a),c=We(s,n,a,1),!i){+bt(c.d).slice(o+1,o+15)+1==1e14&&(c=se(c,m+1,0));break}while(ri(c.d,o+=10,d));return ge=!0,se(c,m,d)};X.minus=X.sub=function(r){var e,t,n,o,i,s,a,c,u,l,m,d,p=this,f=p.constructor;if(r=new f(r),!p.d||!r.d)return!p.s||!r.s?r=new f(NaN):p.d?r.s=-r.s:r=new f(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=f.precision,c=f.rounding,!u[0]||!d[0]){if(d[0])r.s=-r.s;else if(u[0])r=new f(p);else return new f(c===3?-0:0);return ge?se(r,a,c):r}if(t=kt(r.e/pe),l=kt(p.e/pe),u=u.slice(),i=l-t,i){for(m=i<0,m?(e=u,i=-i,s=d.length):(e=d,t=l,s=u.length),n=Math.max(Math.ceil(a/pe),s)+2,i>n&&(i=n,e.length=1),e.reverse(),n=i;n--;)e.push(0);e.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}i=0}for(m&&(e=u,u=d,d=e,r.s=-r.s),s=u.length,n=d.length-s;n>0;--n)u[s++]=0;for(n=d.length;n>i;){if(u[--n]<d[n]){for(o=n;o&&u[--o]===0;)u[o]=mn-1;--u[o],u[n]+=mn}u[n]-=d[n]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--t;return u[0]?(r.d=u,r.e=Ar(u,t),ge?se(r,a,c):r):new f(c===3?-0:0)};X.modulo=X.mod=function(r){var e,t=this,n=t.constructor;return r=new n(r),!t.d||!r.s||r.d&&!r.d[0]?new n(NaN):!r.d||t.d&&!t.d[0]?se(new n(t),n.precision,n.rounding):(ge=!1,n.modulo==9?(e=We(t,r.abs(),0,3,1),e.s*=r.s):e=We(t,r,0,n.modulo,1),e=e.times(r),ge=!0,t.minus(e))};X.naturalExponential=X.exp=function(){return Vs(this)};X.naturalLogarithm=X.ln=function(){return Xn(this)};X.negated=X.neg=function(){var r=new this.constructor(this);return r.s=-r.s,se(r)};X.plus=X.add=function(r){var e,t,n,o,i,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)),ge?se(r,a,c):r;if(i=kt(m.e/pe),n=kt(r.e/pe),u=u.slice(),o=i-n,o){for(o<0?(t=u,o=-o,s=l.length):(t=l,n=i,s=u.length),i=Math.ceil(a/pe),s=i>s?i+1:s+1,o>s&&(o=s,t.length=1),t.reverse();o--;)t.push(0);t.reverse()}for(s=u.length,o=l.length,s-o<0&&(o=s,t=l,l=u,u=t),e=0;o;)e=(u[--o]=u[o]+l[o]+e)/mn|0,u[o]%=mn;for(e&&(u.unshift(e),++n),s=u.length;u[--s]==0;)u.pop();return r.d=u,r.e=Ar(u,n),ge?se(r,a,c):r};X.precision=X.sd=function(r){var e,t=this;if(r!==void 0&&r!==!!r&&r!==1&&r!==0)throw Error(zn+r);return t.d?(e=pc(t.d),r&&t.e+1>e&&(e=t.e+1)):e=NaN,e};X.round=function(){var r=this,e=r.constructor;return se(new e(r),r.e+1,e.rounding)};X.sine=X.sin=function(){var r,e,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(r=n.precision,e=n.rounding,n.precision=r+Math.max(t.e,t.sd())+pe,n.rounding=1,t=td(n,gc(n,t)),n.precision=r,n.rounding=e,se(Kn>2?t.neg():t,r,e,!0)):new n(NaN)};X.squareRoot=X.sqrt=function(){var r,e,t,n,o,i,s=this,a=s.d,c=s.e,u=s.s,l=s.constructor;if(u!==1||!a||!a[0])return new l(!u||u<0&&(!a||a[0])?NaN:a?s:1/0);for(ge=!1,u=Math.sqrt(+s),u==0||u==1/0?(e=bt(a),(e.length+c)%2==0&&(e+="0"),u=Math.sqrt(e),c=kt((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(We(s,i,t+2,1)).times(.5),bt(i.d).slice(0,t)===(e=bt(n.d)).slice(0,t))if(e=e.slice(t-3,t+1),e=="9999"||!o&&e=="4999"){if(!o&&(se(i,c+1,0),i.times(i).eq(s))){n=i;break}t+=4,o=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(se(n,c+1,1),r=!n.times(n).eq(s));break}return ge=!0,se(n,c,l.rounding,r)};X.tangent=X.tan=function(){var r,e,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(r=n.precision,e=n.rounding,n.precision=r+10,n.rounding=1,t=t.sin(),t.s=1,t=We(t,new n(1).minus(t.times(t)).sqrt(),r+10,0),n.precision=r,n.rounding=e,se(Kn==2||Kn==4?t.neg():t,r,e,!0)):new n(NaN)};X.times=X.mul=function(r){var e,t,n,o,i,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(t=kt(l.e/pe)+kt(r.e/pe),c=d.length,u=p.length,c<u&&(i=d,d=p,p=i,s=c,c=u,u=s),i=[],s=c+u,n=s;n--;)i.push(0);for(n=u;--n>=0;){for(e=0,o=c+n;o>n;)a=i[o]+p[n]*d[o-n-1]+e,i[o--]=a%mn|0,e=a/mn|0;i[o]=(i[o]+e)%mn|0}for(;!i[--s];)i.pop();return e?++t:i.shift(),r.d=i,r.e=Ar(i,t),ge?se(r,m.precision,m.rounding):r};X.toBinary=function(r,e){return Ds(this,2,r,e)};X.toDecimalPlaces=X.toDP=function(r,e){var t=this,n=t.constructor;return t=new n(t),r===void 0?t:(Et(r,0,Yn),e===void 0?e=n.rounding:Et(e,0,8),se(t,r+t.e+1,e))};X.toExponential=function(r,e){var t,n=this,o=n.constructor;return r===void 0?t=wn(n,!0):(Et(r,0,Yn),e===void 0?e=o.rounding:Et(e,0,8),n=se(new o(n),r+1,e),t=wn(n,!0,r+1)),n.isNeg()&&!n.isZero()?"-"+t:t};X.toFixed=function(r,e){var t,n,o=this,i=o.constructor;return r===void 0?t=wn(o):(Et(r,0,Yn),e===void 0?e=i.rounding:Et(e,0,8),n=se(new i(o),r+o.e+1,e),t=wn(n,!1,r+n.e+1)),o.isNeg()&&!o.isZero()?"-"+t:t};X.toFraction=function(r){var e,t,n,o,i,s,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=pc(f)-p.e-1,s=i%pe,e.d[0]=st(10,s<0?pe+s:s),r==null)r=i>0?e:u;else{if(a=new y(r),!a.isInt()||a.lt(u))throw Error(zn+a);r=a.gt(e)?i>0?e:u:a}for(ge=!1,a=new y(bt(f)),l=y.precision,y.precision=i=f.length*pe*2;m=We(a,e,0,1,1),o=t.plus(m.times(n)),o.cmp(r)!=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=We(r.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=We(u,n,i,1).minus(p).abs().cmp(We(c,t,i,1).minus(p).abs())<1?[u,n]:[c,t],y.precision=l,ge=!0,d};X.toHexadecimal=X.toHex=function(r,e){return Ds(this,16,r,e)};X.toNearest=function(r,e){var t=this,n=t.constructor;if(t=new n(t),r==null){if(!t.d)return t;r=new n(1),e=n.rounding}else{if(r=new n(r),e===void 0?e=n.rounding:Et(e,0,8),!t.d)return r.s?t:r;if(!r.d)return r.s&&(r.s=t.s),r}return r.d[0]?(ge=!1,t=We(t,r,0,e,1).times(r),ge=!0,se(t)):(r.s=t.s,t=r),t};X.toNumber=function(){return+this};X.toOctal=function(r,e){return Ds(this,8,r,e)};X.toPower=X.pow=function(r){var e,t,n,o,i,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(st(+a,u));if(a=new c(a),a.eq(1))return a;if(n=c.precision,i=c.rounding,r.eq(1))return se(a,n,i);if(e=kt(r.e/pe),e>=r.d.length-1&&(t=u<0?-u:u)<=Zm)return o=fc(c,a,t,n),r.s<0?new c(1).div(o):se(o,n,i);if(s=a.s,s<0){if(e<r.d.length-1)return new c(NaN);if((r.d[e]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return t=st(+a,u),e=t==0||!isFinite(t)?kt(u*(Math.log("0."+bt(a.d))/Math.LN10+a.e+1)):new c(t+"").e,e>c.maxE+1||e<c.minE-1?new c(e>0?s/0:0):(ge=!1,c.rounding=a.s=1,t=Math.min(12,(e+"").length),o=Vs(r.times(Xn(a,n+t)),n),o.d&&(o=se(o,n+5,1),ri(o.d,n,i)&&(e=n+10,o=se(Vs(r.times(Xn(a,e+t)),e),e+5,1),+bt(o.d).slice(n+1,n+15)+1==1e14&&(o=se(o,n+1,0)))),o.s=s,ge=!0,c.rounding=i,se(o,n,i))};X.toPrecision=function(r,e){var t,n=this,o=n.constructor;return r===void 0?t=wn(n,n.e<=o.toExpNeg||n.e>=o.toExpPos):(Et(r,1,Yn),e===void 0?e=o.rounding:Et(e,0,8),n=se(new o(n),r,e),t=wn(n,r<=n.e||n.e<=o.toExpNeg,r)),n.isNeg()&&!n.isZero()?"-"+t:t};X.toSignificantDigits=X.toSD=function(r,e){var t=this,n=t.constructor;return r===void 0?(r=n.precision,e=n.rounding):(Et(r,1,Yn),e===void 0?e=n.rounding:Et(e,0,8)),se(new n(t),r,e)};X.toString=function(){var r=this,e=r.constructor,t=wn(r,r.e<=e.toExpNeg||r.e>=e.toExpPos);return r.isNeg()&&!r.isZero()?"-"+t:t};X.truncated=X.trunc=function(){return se(new this.constructor(this),this.e+1,1)};X.valueOf=X.toJSON=function(){var r=this,e=r.constructor,t=wn(r,r.e<=e.toExpNeg||r.e>=e.toExpPos);return r.isNeg()?"-"+t:t};function bt(r){var e,t,n,o=r.length-1,i="",s=r[0];if(o>0){for(i+=s,e=1;e<o;e++)n=r[e]+"",t=pe-n.length,t&&(i+=Gn(t)),i+=n;s=r[e],n=s+"",t=pe-n.length,t&&(i+=Gn(t))}else if(s===0)return"0";for(;s%10===0;)s/=10;return i+s}function Et(r,e,t){if(r!==~~r||r<e||r>t)throw Error(zn+r)}function ri(r,e,t,n){var o,i,s,a;for(i=r[0];i>=10;i/=10)--e;return--e<0?(e+=pe,o=0):(o=Math.ceil((e+1)/pe),e%=pe),i=st(10,pe-e),a=r[o]%i|0,n==null?e<3?(e==0?a=a/100|0:e==1&&(a=a/10|0),s=t<4&&a==99999||t>3&&a==49999||a==5e4||a==0):s=(t<4&&a+1==i||t>3&&a+1==i/2)&&(r[o+1]/i/100|0)==st(10,e-2)-1||(a==i/2||a==0)&&(r[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),s=(n||t<4)&&a==9999||!n&&t>3&&a==4999):s=((n||t<4)&&a+1==i||!n&&t>3&&a+1==i/2)&&(r[o+1]/i/1e3|0)==st(10,e-3)-1,s}function fr(r,e,t){for(var n,o=[0],i,s=0,a=r.length;s<a;){for(i=o.length;i--;)o[i]*=e;for(o[0]+=Fs.indexOf(r.charAt(s++)),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 Jm(r,e){var t,n,o;if(e.isZero())return e;n=e.d.length,n<32?(t=Math.ceil(n/3),o=(1/wr(4,t)).toString()):(t=16,o="2.3283064365386962890625e-10"),r.precision+=t,e=vo(r,1,e.times(o),new r(1));for(var i=t;i--;){var s=e.times(e);e=s.times(s).minus(s).times(8).plus(1)}return r.precision-=t,e}var We=function(){function r(n,o,i){var s,a=0,c=n.length;for(n=n.slice();c--;)s=n[c]*o+a,n[c]=s%i|0,a=s/i|0;return a&&n.unshift(a),n}function e(n,o,i,s){var a,c;if(i!=s)c=i>s?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,s){for(var a=0;i--;)n[i]-=a,a=n[i]<o[i]?1:0,n[i]=a*s+n[i]-o[i];for(;!n[0]&&n.length>1;)n.shift()}return function(n,o,i,s,a,c){var u,l,m,d,p,f,y,b,g,P,h,I,T,k,S,x,K,B,C,L,N=n.constructor,O=n.s==o.s?1:-1,R=n.d,v=o.d;if(!R||!R[0]||!v||!v[0])return new N(!n.s||!o.s||(R?v&&R[0]==v[0]:!v)?NaN:R&&R[0]==0||!v?O*0:O/0);for(c?(p=1,l=n.e-o.e):(c=mn,p=pe,l=kt(n.e/p)-kt(o.e/p)),C=v.length,K=R.length,g=new N(O),P=g.d=[],m=0;v[m]==(R[m]||0);m++);if(v[m]>(R[m]||0)&&l--,i==null?(k=i=N.precision,s=N.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,v=v[0],k++;(m<K||d)&&k--;m++)S=d*c+(R[m]||0),P[m]=S/v|0,d=S%v|0;f=d||m<K}else{for(d=c/(v[0]+1)|0,d>1&&(v=r(v,d,c),R=r(R,d,c),C=v.length,K=R.length),x=C,h=R.slice(0,C),I=h.length;I<C;)h[I++]=0;L=v.slice(),L.unshift(0),B=v[0],v[1]>=c/2&&++B;do d=0,u=e(v,h,C,I),u<0?(T=h[0],C!=I&&(T=T*c+(h[1]||0)),d=T/B|0,d>1?(d>=c&&(d=c-1),y=r(v,d,c),b=y.length,I=h.length,u=e(y,h,b,I),u==1&&(d--,t(y,C<b?L:v,b,c))):(d==0&&(u=d=1),y=v.slice()),b=y.length,b<I&&y.unshift(0),t(h,y,I,c),u==-1&&(I=h.length,u=e(v,h,C,I),u<1&&(d++,t(h,C<I?L:v,I,c))),I=h.length):u===0&&(d++,h=[0]),P[m++]=d,u&&h[0]?h[I++]=R[x]||0:(h=[R[x]],I=1);while((x++<K||h[0]!==void 0)&&k--);f=h[0]!==void 0}P[0]||P.shift()}if(p==1)g.e=l,uc=f;else{for(m=1,d=P[0];d>=10;d/=10)m++;g.e=m+l*p-1,se(g,a?i+g.e+1:i,s,f)}return g}}();function se(r,e,t,n){var o,i,s,a,c,u,l,m,d,p=r.constructor;e:if(e!=null){if(m=r.d,!m)return r;for(o=1,a=m[0];a>=10;a/=10)o++;if(i=e-o,i<0)i+=pe,s=e,l=m[d=0],c=l/st(10,o-s-1)%10|0;else if(d=Math.ceil((i+1)/pe),a=m.length,d>=a)if(n){for(;a++<=d;)m.push(0);l=c=0,o=1,i%=pe,s=i-pe+1}else break e;else{for(l=a=m[d],o=1;a>=10;a/=10)o++;i%=pe,s=i-pe+o,c=s<0?0:l/st(10,o-s-1)%10|0}if(n=n||e<0||m[d+1]!==void 0||(s<0?l:l%st(10,o-s-1)),u=t<4?(c||n)&&(t==0||t==(r.s<0?3:2)):c>5||c==5&&(t==4||n||t==6&&(i>0?s>0?l/st(10,o-s):0:m[d-1])%10&1||t==(r.s<0?8:7)),e<1||!m[0])return m.length=0,u?(e-=r.e+1,m[0]=st(10,(pe-e%pe)%pe),r.e=-e||0):m[0]=r.e=0,r;if(i==0?(m.length=d,a=1,d--):(m.length=d+1,a=st(10,pe-i),m[d]=s>0?(l/st(10,o-s)%st(10,s)|0)*a:0),u)for(;;)if(d==0){for(i=1,s=m[0];s>=10;s/=10)i++;for(s=m[0]+=a,a=1;s>=10;s/=10)a++;i!=a&&(r.e++,m[0]==mn&&(m[0]=1));break}else{if(m[d]+=a,m[d]!=mn)break;m[d--]=0,a=1}for(i=m.length;m[--i]===0;)m.pop()}return ge&&(r.e>p.maxE?(r.d=null,r.e=NaN):r.e<p.minE&&(r.e=0,r.d=[0])),r}function wn(r,e,t){if(!r.isFinite())return bc(r);var n,o=r.e,i=bt(r.d),s=i.length;return e?(t&&(n=t-s)>0?i=i.charAt(0)+"."+i.slice(1)+Gn(n):s>1&&(i=i.charAt(0)+"."+i.slice(1)),i=i+(r.e<0?"e":"e+")+r.e):o<0?(i="0."+Gn(-o-1)+i,t&&(n=t-s)>0&&(i+=Gn(n))):o>=s?(i+=Gn(o+1-s),t&&(n=t-o-1)>0&&(i=i+"."+Gn(n))):((n=o+1)<s&&(i=i.slice(0,n)+"."+i.slice(n)),t&&(n=t-s)>0&&(o+1===s&&(i+="."),i+=Gn(n))),i}function Ar(r,e){var t=r[0];for(e*=pe;t>=10;t/=10)e++;return e}function gr(r,e,t){if(e>$m)throw ge=!0,t&&(r.precision=t),Error(cc);return se(new r(yr),e,1,!0)}function ln(r,e,t){if(e>Es)throw Error(cc);return se(new r(br),e,t,!0)}function pc(r){var e=r.length-1,t=e*pe+1;if(e=r[e],e){for(;e%10==0;e/=10)t--;for(e=r[0];e>=10;e/=10)t++}return t}function Gn(r){for(var e="";r--;)e+="0";return e}function fc(r,e,t,n){var o,i=new r(1),s=Math.ceil(n/pe+4);for(ge=!1;;){if(t%2&&(i=i.times(e),sc(i.d,s)&&(o=!0)),t=kt(t/2),t===0){t=i.d.length-1,o&&i.d[t]===0&&++i.d[t];break}e=e.times(e),sc(e.d,s)}return ge=!0,i}function rc(r){return r.d[r.d.length-1]&1}function yc(r,e,t){for(var n,o=new r(e[0]),i=0;++i<e.length;)if(n=new r(e[i]),n.s)o[t](n)&&(o=n);else{o=n;break}return o}function Vs(r,e){var t,n,o,i,s,a,c,u=0,l=0,m=0,d=r.constructor,p=d.rounding,f=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(e==null?(ge=!1,c=f):c=e,a=new d(.03125);r.e>-2;)r=r.times(a),m+=5;for(n=Math.log(st(2,m))/Math.LN10*2+5|0,c+=n,t=i=s=new d(1),d.precision=c;;){if(i=se(i.times(r),c,1),t=t.times(++l),a=s.plus(We(i,t,c,1)),bt(a.d).slice(0,c)===bt(s.d).slice(0,c)){for(o=m;o--;)s=se(s.times(s),c,1);if(e==null)if(u<3&&ri(s.d,c-n,p,u))d.precision=c+=10,t=i=a=new d(1),l=0,u++;else return se(s,d.precision=f,p,ge=!0);else return d.precision=f,s}s=a}}function Xn(r,e){var t,n,o,i,s,a,c,u,l,m,d,p=1,f=10,y=r,b=y.d,g=y.constructor,P=g.rounding,h=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?(ge=!1,l=h):l=e,g.precision=l+=f,t=bt(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(r),t=bt(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=gr(g,l+2,h).times(i+""),y=Xn(new g(n+"."+t.slice(1)),l-f).plus(u),g.precision=h,e==null?se(y,h,P,ge=!0):y;for(m=y,c=s=y=We(y.minus(1),y.plus(1),l,1),d=se(y.times(y),l,1),o=3;;){if(s=se(s.times(d),l,1),u=c.plus(We(s,new g(o),l,1)),bt(u.d).slice(0,l)===bt(c.d).slice(0,l))if(c=c.times(2),i!==0&&(c=c.plus(gr(g,l+2,h).times(i+""))),c=We(c,new g(p),l,1),e==null)if(ri(c.d,l-f,P,a))g.precision=l+=f,u=s=y=We(m.minus(1),m.plus(1),l,1),d=se(y.times(y),l,1),o=a=1;else return se(c,g.precision=h,P,ge=!0);else return g.precision=h,c;c=u,o+=2}}function bc(r){return String(r.s*r.s/0)}function Ws(r,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,r.e=t=t-n-1,r.d=[],n=(t+1)%pe,t<0&&(n+=pe),n<o){for(n&&r.d.push(+e.slice(0,n)),o-=pe;n<o;)r.d.push(+e.slice(n,n+=pe));e=e.slice(n),n=pe-e.length}else n-=o;for(;n--;)e+="0";r.d.push(+e),ge&&(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 ed(r,e){var t,n,o,i,s,a,c,u,l;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),dc.test(e))return Ws(r,e)}else if(e==="Infinity"||e==="NaN")return+e||(r.s=NaN),r.e=NaN,r.d=null,r;if(Qm.test(e))t=16,e=e.toLowerCase();else if(Hm.test(e))t=2;else if(jm.test(e))t=8;else throw Error(zn+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("."),s=i>=0,n=r.constructor,s&&(e=e.replace(".",""),a=e.length,i=a-i,o=fc(n,new n(t),i,i*2)),u=fr(e,t,mn),l=u.length-1,i=l;u[i]===0;--i)u.pop();return i<0?new n(r.s*0):(r.e=Ar(u,l),r.d=u,ge=!1,s&&(r=We(r,o,a*4)),c&&(r=r.times(Math.abs(c)<54?st(2,c):si.pow(2,c))),ge=!0,r)}function td(r,e){var t,n=e.d.length;if(n<3)return e.isZero()?e:vo(r,2,e,e);t=1.4*Math.sqrt(n),t=t>16?16:t|0,e=e.times(1/wr(5,t)),e=vo(r,2,e,e);for(var o,i=new r(5),s=new r(16),a=new r(20);t--;)o=e.times(e),e=e.times(i.plus(o.times(s.times(o).minus(a))));return e}function vo(r,e,t,n,o){var i,s,a,c,u=1,l=r.precision,m=Math.ceil(l/pe);for(ge=!1,c=t.times(t),a=new r(n);;){if(s=We(a.times(c),new r(e++*e++),l,1),a=o?n.plus(s):n.minus(s),n=We(s.times(c),new r(e++*e++),l,1),s=a.plus(n),s.d[m]!==void 0){for(i=m;s.d[i]===a.d[i]&&i--;);if(i==-1)break}i=a,a=n,n=s,s=i,u++}return ge=!0,s.d.length=m+1,s}function wr(r,e){for(var t=r;--e;)t*=r;return t}function gc(r,e){var t,n=e.s<0,o=ln(r,r.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=rc(t)?n?2:3:n?4:1,e;Kn=rc(t)?n?1:4:n?3:2}return e.minus(o).abs()}function Ds(r,e,t,n){var o,i,s,a,c,u,l,m,d,p=r.constructor,f=t!==void 0;if(f?(Et(t,1,Yn),n===void 0?n=p.rounding:Et(n,0,8)):(t=p.precision,n=p.rounding),!r.isFinite())l=bc(r);else{for(l=wn(r),s=l.indexOf("."),f?(o=2,e==16?t=t*4-3:e==8&&(t=t*3-2)):o=e,s>=0&&(l=l.replace(".",""),d=new p(1),d.e=l.length-s,d.d=fr(wn(d),10,o),d.e=d.d.length),m=fr(l,10,o),i=c=m.length;m[--c]==0;)m.pop();if(!m[0])l=f?"0p+0":"0";else{if(s<0?i--:(r=new p(r),r.d=m,r.e=i,r=We(r,d,t,n,0,o),m=r.d,i=r.e,u=uc),s=m[t],a=o/2,u=u||m[t+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[t-1]&1||n===(r.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(s=0,l="";s<c;s++)l+=Fs.charAt(m[s]);if(f){if(c>1)if(e==16||e==8){for(s=e==16?4:3,--c;c%s;c++)l+="0";for(m=fr(l,o,e),c=m.length;!m[c-1];--c);for(s=1,l="1.";s<c;s++)l+=Fs.charAt(m[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(i<0?"p":"p+")+i}else if(i<0){for(;++i;)l="0"+l;l="0."+l}else if(++i>c)for(i-=c;i--;)l+="0";else i<c&&(l=l.slice(0,i)+"."+l.slice(i))}l=(e==16?"0x":e==2?"0b":e==8?"0o":"")+l}return r.s<0?"-"+l:l}function sc(r,e){if(r.length>e)return r.length=e,!0}function nd(r){return new this(r).abs()}function od(r){return new this(r).acos()}function id(r){return new this(r).acosh()}function rd(r,e){return new this(r).plus(e)}function sd(r){return new this(r).asin()}function ad(r){return new this(r).asinh()}function ud(r){return new this(r).atan()}function cd(r){return new this(r).atanh()}function ld(r,e){r=new this(r),e=new this(e);var t,n=this.precision,o=this.rounding,i=n+4;return!r.s||!e.s?t=new this(NaN):!r.d&&!e.d?(t=ln(this,i,1).times(e.s>0?.25:.75),t.s=r.s):!e.d||r.isZero()?(t=e.s<0?ln(this,n,o):new this(0),t.s=r.s):!r.d||e.isZero()?(t=ln(this,i,1).times(.5),t.s=r.s):e.s<0?(this.precision=i,this.rounding=1,t=this.atan(We(r,e,i,1)),e=ln(this,i,1),this.precision=n,this.rounding=o,t=r.s<0?t.minus(e):t.plus(e)):t=this.atan(We(r,e,i,1)),t}function md(r){return new this(r).cbrt()}function dd(r){return se(r=new this(r),r.e+1,2)}function pd(r,e,t){return new this(r).clamp(e,t)}function fd(r){if(!r||typeof r!="object")throw Error(Pr+"Object expected");var e,t,n,o=r.defaults===!0,i=["precision",1,Yn,"rounding",0,8,"toExpNeg",-Mo,0,"toExpPos",0,Mo,"maxE",0,Mo,"minE",-Mo,0,"modulo",0,9];for(e=0;e<i.length;e+=3)if(t=i[e],o&&(this[t]=_s[t]),(n=r[t])!==void 0)if(kt(n)===n&&n>=i[e+1]&&n<=i[e+2])this[t]=n;else throw Error(zn+t+": "+n);if(t="crypto",o&&(this[t]=_s[t]),(n=r[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(lc);else this[t]=!1;else throw Error(zn+t+": "+n);return this}function yd(r){return new this(r).cos()}function bd(r){return new this(r).cosh()}function Pc(r){var e,t,n;function o(i){var s,a,c,u=this;if(!(u instanceof o))return new o(i);if(u.constructor=o,ac(i)){u.s=i.s,ge?!i.d||i.e>o.maxE?(u.e=NaN,u.d=null):i.e<o.minE?(u.e=0,u.d=[0]):(u.e=i.e,u.d=i.d.slice()):(u.e=i.e,u.d=i.d?i.d.slice():i.d);return}if(c=typeof i,c==="number"){if(i===0){u.s=1/i<0?-1:1,u.e=0,u.d=[0];return}if(i<0?(i=-i,u.s=-1):u.s=1,i===~~i&&i<1e7){for(s=0,a=i;a>=10;a/=10)s++;ge?s>o.maxE?(u.e=NaN,u.d=null):s<o.minE?(u.e=0,u.d=[0]):(u.e=s,u.d=[i]):(u.e=s,u.d=[i]);return}else if(i*0!==0){i||(u.s=NaN),u.e=NaN,u.d=null;return}return Ws(u,i.toString())}else if(c!=="string")throw Error(zn+i);return(a=i.charCodeAt(0))===45?(i=i.slice(1),u.s=-1):(a===43&&(i=i.slice(1)),u.s=1),dc.test(i)?Ws(u,i):ed(u,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=fd,o.clone=Pc,o.isDecimal=ac,o.abs=nd,o.acos=od,o.acosh=id,o.add=rd,o.asin=sd,o.asinh=ad,o.atan=ud,o.atanh=cd,o.atan2=ld,o.cbrt=md,o.ceil=dd,o.clamp=pd,o.cos=yd,o.cosh=bd,o.div=gd,o.exp=Pd,o.floor=Ad,o.hypot=wd,o.ln=kd,o.log=hd,o.log10=Id,o.log2=Td,o.max=Bd,o.min=xd,o.mod=Sd,o.mul=Kd,o.pow=Cd,o.random=Rd,o.round=Ld,o.sign=Nd,o.sin=Od,o.sinh=Md,o.sqrt=vd,o.sub=Fd,o.sum=_d,o.tan=Ed,o.tanh=Vd,o.trunc=Wd,r===void 0&&(r={}),r&&r.defaults!==!0)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<n.length;)r.hasOwnProperty(t=n[e++])||(r[t]=this[t]);return o.config(r),o}function gd(r,e){return new this(r).div(e)}function Pd(r){return new this(r).exp()}function Ad(r){return se(r=new this(r),r.e+1,3)}function wd(){var r,e,t=new this(0);for(ge=!1,r=0;r<arguments.length;)if(e=new this(arguments[r++]),e.d)t.d&&(t=t.plus(e.times(e)));else{if(e.s)return ge=!0,new this(1/0);t=e}return ge=!0,t.sqrt()}function ac(r){return r instanceof si||r&&r.toStringTag===mc||!1}function kd(r){return new this(r).ln()}function hd(r,e){return new this(r).log(e)}function Td(r){return new this(r).log(2)}function Id(r){return new this(r).log(10)}function Bd(){return yc(this,arguments,"lt")}function xd(){return yc(this,arguments,"gt")}function Sd(r,e){return new this(r).mod(e)}function Kd(r,e){return new this(r).mul(e)}function Cd(r,e){return new this(r).pow(e)}function Rd(r){var e,t,n,o,i=0,s=new this(1),a=[];if(r===void 0?r=this.precision:Et(r,1,Yn),n=Math.ceil(r/pe),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(lc);else for(;i<n;)a[i++]=Math.random()*1e7|0;for(n=a[--i],r%=pe,n&&r&&(o=st(10,pe-r),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-=pe)a.shift();for(n=1,o=a[0];o>=10;o/=10)n++;n<pe&&(t-=pe-n)}return s.e=t,s.d=a,s}function Ld(r){return se(r=new this(r),r.e+1,this.rounding)}function Nd(r){return r=new this(r),r.d?r.d[0]?r.s:0*r.s:r.s||NaN}function Od(r){return new this(r).sin()}function Md(r){return new this(r).sinh()}function vd(r){return new this(r).sqrt()}function Fd(r,e){return new this(r).sub(e)}function _d(){var r=0,e=arguments,t=new this(e[r]);for(ge=!1;t.s&&++r<e.length;)t=t.plus(e[r]);return ge=!0,se(t,this.precision,this.rounding)}function Ed(r){return new this(r).tan()}function Vd(r){return new this(r).tanh()}function Wd(r){return se(r=new this(r),r.e+1,1)}X[Symbol.for("nodejs.util.inspect.custom")]=X.toString;X[Symbol.toStringTag]="Decimal";var si=X.constructor=Pc(_s);yr=new si(yr);br=new si(br);var M=si;import Hd from"big.js";import Tr from"bn.js";import Dd from"toformat";var qd=Dd,ai=qd;import hr from"big.js";import Gd from"bn.js";import Xd from"decimal.js-light";import ui from"bn.js";var Ac=9007199254740991;function ne(r){let e=ke("Raydium_parseBigNumberish");if(r instanceof ui)return r;if(typeof r=="string"){if(r.match(/^-?[0-9]+$/))return new ui(r);e.logWithError(`invalid BigNumberish string: ${r}`)}return typeof r=="number"?(r%1&&e.logWithError(`BigNumberish number underflow: ${r}`),(r>=Ac||r<=-Ac)&&e.logWithError(`BigNumberish number overflow: ${r}`),new ui(String(r))):typeof r=="bigint"?new ui(r.toString()):(e.error(`invalid BigNumberish value: ${r}`),new ui(0))}var kr=ke("module/fraction"),qs=ai(hr),ci=ai(Xd),zd={[0]:ci.ROUND_DOWN,[1]:ci.ROUND_HALF_UP,[2]:ci.ROUND_UP},Yd={[0]:hr.roundDown,[1]:hr.roundHalfUp,[2]:hr.roundUp},Re=class{constructor(e,t=new Gd(1)){this.numerator=ne(e),this.denominator=ne(t)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new Re(this.denominator,this.numerator)}add(e){let t=e instanceof Re?e:new Re(ne(e));return this.denominator.eq(t.denominator)?new Re(this.numerator.add(t.numerator),this.denominator):new Re(this.numerator.mul(t.denominator).add(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}sub(e){let t=e instanceof Re?e:new Re(ne(e));return this.denominator.eq(t.denominator)?new Re(this.numerator.sub(t.numerator),this.denominator):new Re(this.numerator.mul(t.denominator).sub(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}mul(e){let t=e instanceof Re?e:new Re(ne(e));return new Re(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof Re?e:new Re(ne(e));return new Re(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},n=1){Number.isInteger(e)||kr.logWithError(`${e} is not an integer.`),e<=0&&kr.logWithError(`${e} is not positive.`),ci.set({precision:e+1,rounding:zd[n]});let o=new ci(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)||kr.logWithError(`${e} is not an integer.`),e<0&&kr.logWithError(`${e} is negative.`),qs.DP=e,qs.RM=Yd[n]||1,new qs(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};var Qd=ke("Raydium_amount"),wc=ai(Hd);function jd(r,e){let t="0",n="0";if(r.includes(".")){let o=r.split(".");o.length===2?([t,n]=o,n=n.padEnd(e,"0")):Qd.logWithError(`invalid number string, num: ${r}`)}else t=r;return[t,n.slice(0,e)||n]}var Oe=class extends Re{constructor(t,n,o=!0,i){let s=new Tr(0),a=Us.pow(new Tr(t.decimals));if(o)s=ne(n);else{let c=new Tr(0),u=new Tr(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[l,m]=jd(n.toString(),t.decimals);c=ne(l),u=ne(m)}c=c.mul(a),s=c.add(u)}super(s,a);this.logger=ke(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 Oe(this.token,this.raw.add(t.raw))}subtract(t){return this.token.equals(t.token)||this.logger.logWithError("sub token not equals"),new Oe(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 wc.DP=this.token.decimals,new wc(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)}};import{PublicKey as Zd}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as kc}from"@solana/spl-token";var kn={chainId:101,address:Zd.default.toBase58(),programId:kc.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},mt={chainId:101,address:"So11111111111111111111111111111111111111112",programId:kc.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 Hs}from"@solana/web3.js";import{PublicKey as Qe,SystemProgram as hc,SYSVAR_RENT_PUBKEY as $d}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Jd}from"@solana/spl-token";function w({pubkey:r,isSigner:e=!1,isWritable:t=!0}){return{pubkey:r,isWritable:t,isSigner:e}}var Gs=[w({pubkey:Jd,isWritable:!1}),w({pubkey:hc.programId,isWritable:!1}),w({pubkey:$d,isWritable:!1})];function Xs({publicKey:r,transformSol:e}){let t=zs(r.toString());if(t instanceof Qe)return e&&t.equals(dt)?$:t;if(e&&t.toString()===dt.toBase58())return $;if(typeof t=="string"){if(t===Qe.default.toBase58())return Qe.default;try{return new Qe(t)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function zs(r){try{return new Qe(r)}catch{return r}}var Ir=new Qe("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),hn=new Qe("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),ot=new Qe("SysvarRent111111111111111111111111111111111"),Ys=new Qe("SysvarC1ock11111111111111111111111111111111"),on=new Qe("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Br=new Qe("Sysvar1nstructions1111111111111111111111111"),xr=hc.programId,Zb=new Qe("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),$b=new Qe("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Jb=new Qe("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),eg=new Qe("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),tg=new Qe("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),ng=new Qe("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),og=new Qe("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),ig=new Qe("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),rg=new Qe("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),sg=new Qe("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),ag=new Qe("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),$=new Qe("So11111111111111111111111111111111111111112"),dt=Qe.default;function wt(r){return Xs({publicKey:r,transformSol:!0})}var Qs=class{constructor({mint:e,decimals:t,symbol:n,name:o,skipMint:i=!1,isToken2022:s=!1}){if(e===dt.toBase58()||e instanceof Hs&&dt.equals(e)){this.decimals=mt.decimals,this.symbol=mt.symbol,this.name=mt.name,this.mint=new Hs(mt.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?Hs.default:Xs({publicKey:e}),this.isToken2022=s}equals(e){return this===e?!0:this.mint.equals(e.mint)}},je=Qs;je.WSOL=new Qs(U(_({},mt),{mint:mt.address}));var js=class{constructor({decimals:e,symbol:t="UNKNOWN",name:n="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=n}equals(e){return this===e}},Sr=js;Sr.SOL=new js(kn);import ep from"bn.js";var Tc=new Re(new ep(100)),pt=class extends Re{toSignificant(e=5,t,n){return this.mul(Tc).toSignificant(e,t,n)}toFixed(e=2,t,n){return this.mul(Tc).toFixed(e,t,n)}};var tp=ke("Raydium_price"),Vt=class extends Re{constructor(t){let{baseToken:n,quoteToken:o,numerator:i,denominator:s}=t;super(i,s);this.baseToken=n,this.quoteToken=o,this.scalar=new Re(Zs(n.decimals),Zs(o.decimals))}get raw(){return new Re(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new Vt({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numerator,numerator:this.denominator})}mul(t){this.quoteToken!==t.baseToken&&tp.logWithError("mul token not equals");let n=super.mul(t);return new Vt({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 Wt=new Tn(0),Ic=new Tn(1),jg=new Tn(2),Zg=new Tn(3),$g=new Tn(5),Us=new Tn(10),Jg=new Tn(100),eP=new Tn(1e3),tP=new Tn(1e4);function Zs(r){return Us.pow(ne(r))}function Kr(r,e){let t=r.divmod(e);return t.mod.isZero()?t.div:t.div.isNeg()?t.div.isubn(1):t.div.iaddn(1)}function li(r,e,t){return r.mul(e).add(t).sub(new Tn(1)).div(t)}function Cr(r,e,t){return r.mul(e).div(t)}var Bc=r=>typeof r=="number";function xc(r,e,t){let n=Bc(e)?e*((t==null?void 0:t.unit)==="s"?1e3:1):e;return new Date(r).getTime()<=n}function Sc(r,e,t){let n=Bc(e)?e*((t==null?void 0:t.unit)==="s"?1e3:1):e;return new Date(r).getTime()>n}function vs(r,e=1,t=[]){let n=[...r];if(e<=0)return t;for(;n.length;)t.push(n.splice(0,e));return t}var dn=class{constructor(e){this._owner=e}get publicKey(){return dn.isKeyPair(this._owner)?this._owner.publicKey:this._owner}get signer(){return dn.isKeyPair(this._owner)?this._owner:void 0}get isKeyPair(){return dn.isKeyPair(this._owner)}get isPublicKey(){return dn.isPublicKey(this._owner)}static isKeyPair(e){return e.secretKey!==void 0}static isPublicKey(e){return!dn.isKeyPair(e)}};import{PublicKey as ap}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as up}from"@solana/spl-token";import{ComputeBudgetProgram as Kc,Keypair as Cc,PublicKey as Rc,Transaction as Rr,TransactionMessage as np,VersionedTransaction as Lc}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 op}from"@solana/spl-token";var Cn=ke("Raydium_txUtil"),Nc=1644;function Lr(r){let e=[],t=[];return r.microLamports&&(e.push(Kc.setComputeUnitPrice({microLamports:r.microLamports})),t.push(z.SetComputeUnitPrice)),r.units&&(e.push(Kc.setComputeUnitLimit({units:r.units})),t.push(z.SetComputeUnitLimit)),{instructions:e,instructionTypes:t}}async function Fo(r,e){var n,o;let t=e!=null?e:"confirmed";return(o=await((n=r.getLatestBlockhash)==null?void 0:n.call(r,{commitment:t})))==null?void 0:o.blockhash}async function Nr(r,e){return r.getSignatureStatuses([e]),new Promise((t,n)=>{let o=setTimeout(n,6e4);r.onSignature(e,i=>{if(clearTimeout(o),!i.err){t("");return}n(Object.assign(i.err,{txId:e}))},"confirmed")})}function Or(r,e){r.length<1&&Cn.logWithError(`no instructions provided: ${r.toString()}`),e.length<1&&Cn.logWithError(`no signers provided:, ${e.toString()}`);let t=new Rr;t.recentBlockhash="11111111111111111111111111111111",t.feePayer=e[0],t.add(...r);try{return Buffer.from(t.serialize({verifySignatures:!1})).toString("base64").length<Nc}catch{return!1}}async function Oc(r,e,t,n=!0){let o=new Rc("RaydiumSimuLateTransaction11111111111111111"),i=[],s=new Rr;s.feePayer=o;for(let u of e)Or([...s.instructions,u],[o])||(i.push(s),s=new Rr,s.feePayer=o),s.add(u);s.instructions.length>0&&i.push(s);let a=[];try{if(a=await ip(r,i,n),a.find(u=>u.err!==null))throw Error("rpc simulateTransaction error")}catch(u){u instanceof Error&&Cn.logWithError("failed to simulate for instructions","RPC_ERROR",{message:u.message})}let c=[];for(let u of a)if(Cn.debug("simulate result:",u),u.logs){let l=u.logs.filter(m=>m&&m.includes(t));Cn.debug("filteredLog:",c),l.length||Cn.logWithError("simulate log not match keyword","keyword",t),c.push(...l)}return c}function Mc(r,e){let t=r.match(/{["\w:,]+}/g);return!t||t.length!==1?Cn.logWithError(`simulate log fail to match json, keyword: ${e}`):t[0]}function Rn(r,e){let n=new RegExp(`"${e}":(\\d+)`,"g").exec(r);return!n||n.length!==2?Cn.logWithError(`simulate log fail to match key", key: ${e}`):n[1]}function ie(r,e){let[t,n]=Rc.findProgramAddressSync(r,e);return{publicKey:t,nonce:n}}async function ip(r,e,t){let n=[];if(t){let o=await r.getLatestBlockhash(),i=[];for(let u of e){u.recentBlockhash=o.blockhash,u.lastValidBlockHeight=o.lastValidBlockHeight;let m=u._compile().serialize(),p=u._serialize(m).toString("base64");i.push(p)}let s=i.map(u=>{let l=r._buildArgs([u],void 0,"base64");return{methodName:"simulateTransaction",args:l}}),a=[],c=20;for(let u=0;u<Math.ceil(s.length/c);u++)a.push(s.slice(u*c,(u+1)*c));n=await(await Promise.all(a.map(async u=>(await r._rpcBatchRequest(u)).map(l=>l.result.value)))).flat()}else try{n=a