UNPKG

@raydium-io/raydium-sdk-v2

Version:

An SDK for building applications on top of Raydium.

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