UNPKG

snapper-sdk

Version:

An SDK for building applications on top of Snapper.

1 lines 188 kB
"use strict";var Fr=Object.create;var nn=Object.defineProperty;var Er=Object.getOwnPropertyDescriptor;var Dr=Object.getOwnPropertyNames;var vr=Object.getPrototypeOf,Vr=Object.prototype.hasOwnProperty;var _r=(i,e)=>{for(var t in e)nn(i,t,{get:e[t],enumerable:!0})},Ci=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Dr(e))!Vr.call(i,r)&&r!==t&&nn(i,r,{get:()=>e[r],enumerable:!(n=Er(e,r))||n.enumerable});return i};var fe=(i,e,t)=>(t=i!=null?Fr(vr(i)):{},Ci(e||!i||!i.__esModule?nn(t,"default",{value:i,enumerable:!0}):t,i)),qr=i=>Ci(nn({},"__esModule",{value:!0}),i);var ws={};_r(ws,{AMM_CONFIG_SEED:()=>br,BIT_PRECISION:()=>oi,Clmm:()=>Kn,ClmmConfigLayout:()=>Ti,ClmmInstrument:()=>ae,EXTENSION_TICKARRAY_BITMAP_SIZE:()=>Cn,FEE_RATE_DENOMINATOR:()=>Jt,FETCH_TICKARRAY_COUNT:()=>xr,Fee:()=>gr,LOG_B_2_X32:()=>si,LOG_B_P_ERR_MARGIN_LOWER_X64:()=>ai,LOG_B_P_ERR_MARGIN_UPPER_X64:()=>ci,LiquidityMath:()=>X,LockClPositionLayoutV2:()=>ys,LockPositionLayout:()=>bs,MAX_SQRT_PRICE_X64:()=>ze,MAX_SQRT_PRICE_X64_SUB_ONE:()=>ss,MAX_TICK:()=>Ce,MIN_SQRT_PRICE_X64:()=>Xe,MIN_SQRT_PRICE_X64_ADD_ONE:()=>os,MIN_TICK:()=>Te,MathUtil:()=>v,MaxU64:()=>Tn,MaxUint128:()=>ri,NEGATIVE_ONE:()=>Je,OBSERVATION_SEED:()=>Tr,ONE:()=>Ue,OPERATION_SEED:()=>kr,ObservationInfoLayout:()=>xi,ObservationLayout:()=>Ir,OperationLayout:()=>Bi,POOL_LOCK_ID_SEED:()=>yi,POOL_REWARD_VAULT_SEED:()=>Pr,POOL_SEED:()=>yr,POOL_TICK_ARRAY_BITMAP_SEED:()=>hr,POOL_VAULT_SEED:()=>wr,POSITION_SEED:()=>pi,PoolInfoLayout:()=>en,PoolUtils:()=>pe,PositionInfoLayout:()=>Ft,PositionRewardInfoLayout:()=>Cr,PositionUtils:()=>Rt,ProtocolPositionLayout:()=>gs,Q128:()=>Qt,Q64:()=>Re,RewardInfo:()=>Sr,SqrtPriceMath:()=>O,SwapMath:()=>ft,TICK_ARRAY_BITMAP_SIZE:()=>pt,TICK_ARRAY_SEED:()=>Ar,TICK_ARRAY_SIZE:()=>ge,TICK_SPACINGS:()=>as,TickArrayBitmap:()=>$e,TickArrayBitmapExtensionLayout:()=>ki,TickArrayBitmapExtensionUtils:()=>Ot,TickArrayLayout:()=>Mt,TickLayout:()=>Kr,TickMath:()=>gt,TickQuery:()=>z,TickUtils:()=>K,U64Resolution:()=>St,U64_IGNORE_RANGE:()=>us,ZERO:()=>H,clmmComputeInfoToApiInfo:()=>Ai,getLiquidityFromAmounts:()=>ps,getPdaAmmConfigId:()=>ds,getPdaExBitmapAccount:()=>Fe,getPdaLockClPositionIdV2:()=>Lt,getPdaLockPositionId:()=>Sn,getPdaMetadataKey:()=>Kt,getPdaObservationAccount:()=>bi,getPdaOperationAccount:()=>Nt,getPdaPersonalPositionAddress:()=>Ke,getPdaPoolId:()=>fi,getPdaPoolRewardVaulId:()=>gi,getPdaPoolVaultId:()=>In,getPdaProtocolPositionAddress:()=>De,getPdaTickArrayAddress:()=>U,i16ToBytes:()=>ls,i32ToBytes:()=>$t,isZero:()=>Ct,leadingZeros:()=>xn,leastSignificantBit:()=>di,mockCreatePoolInfo:()=>cs,mockV3CreatePoolInfo:()=>ui,mostSignificantBit:()=>mi,trailingZeros:()=>Bn,u16ToBytes:()=>li,u32ToBytes:()=>ms});module.exports=qr(ws);var C=require("@solana/web3.js"),Ne=fe(require("bn.js"));var Pt=9e15,st=1e9,Ln="0123456789abcdef",on="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",sn="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Rn={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Pt,maxE:Pt,crypto:!1},Ri,et,V=!0,cn="[DecimalError] ",ot=cn+"Invalid argument: ",Mi=cn+"Precision limit exceeded",Oi=cn+"crypto unavailable",Fi="[object Decimal]",xe=Math.floor,be=Math.pow,Wr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Gr=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Ur=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Ei=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,qe=1e7,D=7,Xr=9007199254740991,zr=on.length-1,Mn=sn.length-1,B={toStringTag:Fi};B.absoluteValue=B.abs=function(){var i=new this.constructor(this);return i.s<0&&(i.s=1),R(i)};B.ceil=function(){return R(new this.constructor(this),this.e+1,2)};B.clampedTo=B.clamp=function(i,e){var t,n=this,r=n.constructor;if(i=new r(i),e=new r(e),!i.s||!e.s)return new r(NaN);if(i.gt(e))throw Error(ot+e);return t=n.cmp(i),t<0?i:n.cmp(e)>0?e:new r(n)};B.comparedTo=B.cmp=function(i){var e,t,n,r,o=this,s=o.d,a=(i=new o.constructor(i)).d,c=o.s,u=i.s;if(!s||!a)return!c||!u?NaN:c!==u?c:s===a?0:!s^c<0?1:-1;if(!s[0]||!a[0])return s[0]?c:a[0]?-u:0;if(c!==u)return c;if(o.e!==i.e)return o.e>i.e^c<0?1:-1;for(n=s.length,r=a.length,e=0,t=n<r?n:r;e<t;++e)if(s[e]!==a[e])return s[e]>a[e]^c<0?1:-1;return n===r?0:n>r^c<0?1:-1};B.cosine=B.cos=function(){var i,e,t=this,n=t.constructor;return t.d?t.d[0]?(i=n.precision,e=n.rounding,n.precision=i+Math.max(t.e,t.sd())+D,n.rounding=1,t=Hr(n,qi(n,t)),n.precision=i,n.rounding=e,R(et==2||et==3?t.neg():t,i,e,!0)):new n(1):new n(NaN)};B.cubeRoot=B.cbrt=function(){var i,e,t,n,r,o,s,a,c,u,l=this,m=l.constructor;if(!l.isFinite()||l.isZero())return new m(l);for(V=!1,o=l.s*be(l.s*l,1/3),!o||Math.abs(o)==1/0?(t=Pe(l.d),i=l.e,(o=(i-t.length+1)%3)&&(t+=o==1||o==-2?"0":"00"),o=be(t,1/3),i=xe((i+1)/3)-(i%3==(i<0?-1:2)),o==1/0?t="5e"+i:(t=o.toExponential(),t=t.slice(0,t.indexOf("e")+1)+i),n=new m(t),n.s=l.s):n=new m(o.toString()),s=(i=m.precision)+3;;)if(a=n,c=a.times(a).times(a),u=c.plus(l),n=oe(u.plus(l).times(a),u.plus(c),s+2,1),Pe(a.d).slice(0,s)===(t=Pe(n.d)).slice(0,s))if(t=t.slice(s-3,s+1),t=="9999"||!r&&t=="4999"){if(!r&&(R(a,i+1,0),a.times(a).times(a).eq(l))){n=a;break}s+=4,r=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(R(n,i+1,1),e=!n.times(n).times(n).eq(l));break}return V=!0,R(n,i,m.rounding,e)};B.decimalPlaces=B.dp=function(){var i,e=this.d,t=NaN;if(e){if(i=e.length-1,t=(i-xe(this.e/D))*D,i=e[i],i)for(;i%10==0;i/=10)t--;t<0&&(t=0)}return t};B.dividedBy=B.div=function(i){return oe(this,new this.constructor(i))};B.dividedToIntegerBy=B.divToInt=function(i){var e=this,t=e.constructor;return R(oe(e,new t(i),0,1,1),t.precision,t.rounding)};B.equals=B.eq=function(i){return this.cmp(i)===0};B.floor=function(){return R(new this.constructor(this),this.e+1,3)};B.greaterThan=B.gt=function(i){return this.cmp(i)>0};B.greaterThanOrEqualTo=B.gte=function(i){var e=this.cmp(i);return e==1||e===0};B.hyperbolicCosine=B.cosh=function(){var i,e,t,n,r,o=this,s=o.constructor,a=new s(1);if(!o.isFinite())return new s(o.s?1/0:NaN);if(o.isZero())return a;t=s.precision,n=s.rounding,s.precision=t+Math.max(o.e,o.sd())+4,s.rounding=1,r=o.d.length,r<32?(i=Math.ceil(r/3),e=(1/ln(4,i)).toString()):(i=16,e="2.3283064365386962890625e-10"),o=At(s,1,o.times(e),new s(1),!0);for(var c,u=i,l=new s(8);u--;)c=o.times(o),o=a.minus(c.times(l.minus(c.times(l))));return R(o,s.precision=t,s.rounding=n,!0)};B.hyperbolicSine=B.sinh=function(){var i,e,t,n,r=this,o=r.constructor;if(!r.isFinite()||r.isZero())return new o(r);if(e=o.precision,t=o.rounding,o.precision=e+Math.max(r.e,r.sd())+4,o.rounding=1,n=r.d.length,n<3)r=At(o,2,r,r,!0);else{i=1.4*Math.sqrt(n),i=i>16?16:i|0,r=r.times(1/ln(5,i)),r=At(o,2,r,r,!0);for(var s,a=new o(5),c=new o(16),u=new o(20);i--;)s=r.times(r),r=r.times(a.plus(s.times(c.times(s).plus(u))))}return o.precision=e,o.rounding=t,R(r,e,t,!0)};B.hyperbolicTangent=B.tanh=function(){var i,e,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(i=n.precision,e=n.rounding,n.precision=i+7,n.rounding=1,oe(t.sinh(),t.cosh(),n.precision=i,n.rounding=e)):new n(t.s)};B.inverseCosine=B.acos=function(){var i,e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,o=t.rounding;return n!==-1?n===0?e.isNeg()?_e(t,r,o):new t(0):new t(NaN):e.isZero()?_e(t,r+4,o).times(.5):(t.precision=r+6,t.rounding=1,e=e.asin(),i=_e(t,r+4,o).times(.5),t.precision=r,t.rounding=o,i.minus(e))};B.inverseHyperbolicCosine=B.acosh=function(){var i,e,t=this,n=t.constructor;return t.lte(1)?new n(t.eq(1)?0:NaN):t.isFinite()?(i=n.precision,e=n.rounding,n.precision=i+Math.max(Math.abs(t.e),t.sd())+4,n.rounding=1,V=!1,t=t.times(t).minus(1).sqrt().plus(t),V=!0,n.precision=i,n.rounding=e,t.ln()):new n(t)};B.inverseHyperbolicSine=B.asinh=function(){var i,e,t=this,n=t.constructor;return!t.isFinite()||t.isZero()?new n(t):(i=n.precision,e=n.rounding,n.precision=i+2*Math.max(Math.abs(t.e),t.sd())+6,n.rounding=1,V=!1,t=t.times(t).plus(1).sqrt().plus(t),V=!0,n.precision=i,n.rounding=e,t.ln())};B.inverseHyperbolicTangent=B.atanh=function(){var i,e,t,n,r=this,o=r.constructor;return r.isFinite()?r.e>=0?new o(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(i=o.precision,e=o.rounding,n=r.sd(),Math.max(n,i)<2*-r.e-1?R(new o(r),i,e,!0):(o.precision=t=n-r.e,r=oe(r.plus(1),new o(1).minus(r),t+i,1),o.precision=i+4,o.rounding=1,r=r.ln(),o.precision=i,o.rounding=e,r.times(.5))):new o(NaN)};B.inverseSine=B.asin=function(){var i,e,t,n,r=this,o=r.constructor;return r.isZero()?new o(r):(e=r.abs().cmp(1),t=o.precision,n=o.rounding,e!==-1?e===0?(i=_e(o,t+4,n).times(.5),i.s=r.s,i):new o(NaN):(o.precision=t+6,o.rounding=1,r=r.div(new o(1).minus(r.times(r)).sqrt().plus(1)).atan(),o.precision=t,o.rounding=n,r.times(2)))};B.inverseTangent=B.atan=function(){var i,e,t,n,r,o,s,a,c,u=this,l=u.constructor,m=l.precision,d=l.rounding;if(u.isFinite()){if(u.isZero())return new l(u);if(u.abs().eq(1)&&m+4<=Mn)return s=_e(l,m+4,d).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(m+4<=Mn)return s=_e(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/D+2|0),i=t;i;--i)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(V=!1,e=Math.ceil(a/D),n=1,c=u.times(u),s=new l(u),r=u;i!==-1;)if(r=r.times(c),o=s.minus(r.div(n+=2)),r=r.times(c),s=o.plus(r.div(n+=2)),s.d[e]!==void 0)for(i=e;s.d[i]===o.d[i]&&i--;);return t&&(s=s.times(2<<t-1)),V=!0,R(s,l.precision=m,l.rounding=d,!0)};B.isFinite=function(){return!!this.d};B.isInteger=B.isInt=function(){return!!this.d&&xe(this.e/D)>this.d.length-2};B.isNaN=function(){return!this.s};B.isNegative=B.isNeg=function(){return this.s<0};B.isPositive=B.isPos=function(){return this.s>0};B.isZero=function(){return!!this.d&&this.d[0]===0};B.lessThan=B.lt=function(i){return this.cmp(i)<0};B.lessThanOrEqualTo=B.lte=function(i){return this.cmp(i)<1};B.logarithm=B.log=function(i){var e,t,n,r,o,s,a,c,u=this,l=u.constructor,m=l.precision,d=l.rounding,p=5;if(i==null)i=new l(10),e=!0;else{if(i=new l(i),t=i.d,i.s<0||!t||!t[0]||i.eq(1))return new l(NaN);e=i.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)o=!0;else{for(r=t[0];r%10===0;)r/=10;o=r!==1}if(V=!1,a=m+p,s=rt(u,a),n=e?an(l,a+10):rt(i,a),c=oe(s,n,a,1),Dt(c.d,r=m,d))do if(a+=10,s=rt(u,a),n=e?an(l,a+10):rt(i,a),c=oe(s,n,a,1),!o){+Pe(c.d).slice(r+1,r+15)+1==1e14&&(c=R(c,m+1,0));break}while(Dt(c.d,r+=10,d));return V=!0,R(c,m,d)};B.minus=B.sub=function(i){var e,t,n,r,o,s,a,c,u,l,m,d,p=this,g=p.constructor;if(i=new g(i),!p.d||!i.d)return!p.s||!i.s?i=new g(NaN):p.d?i.s=-i.s:i=new g(i.d||p.s!==i.s?p:NaN),i;if(p.s!=i.s)return i.s=-i.s,p.plus(i);if(u=p.d,d=i.d,a=g.precision,c=g.rounding,!u[0]||!d[0]){if(d[0])i.s=-i.s;else if(u[0])i=new g(p);else return new g(c===3?-0:0);return V?R(i,a,c):i}if(t=xe(i.e/D),l=xe(p.e/D),u=u.slice(),o=l-t,o){for(m=o<0,m?(e=u,o=-o,s=d.length):(e=d,t=l,s=u.length),n=Math.max(Math.ceil(a/D),s)+2,o>n&&(o=n,e.length=1),e.reverse(),n=o;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}o=0}for(m&&(e=u,u=d,d=e,i.s=-i.s),s=u.length,n=d.length-s;n>0;--n)u[s++]=0;for(n=d.length;n>o;){if(u[--n]<d[n]){for(r=n;r&&u[--r]===0;)u[r]=qe-1;--u[r],u[n]+=qe}u[n]-=d[n]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--t;return u[0]?(i.d=u,i.e=un(u,t),V?R(i,a,c):i):new g(c===3?-0:0)};B.modulo=B.mod=function(i){var e,t=this,n=t.constructor;return i=new n(i),!t.d||!i.s||i.d&&!i.d[0]?new n(NaN):!i.d||t.d&&!t.d[0]?R(new n(t),n.precision,n.rounding):(V=!1,n.modulo==9?(e=oe(t,i.abs(),0,3,1),e.s*=i.s):e=oe(t,i,0,n.modulo,1),e=e.times(i),V=!0,t.minus(e))};B.naturalExponential=B.exp=function(){return On(this)};B.naturalLogarithm=B.ln=function(){return rt(this)};B.negated=B.neg=function(){var i=new this.constructor(this);return i.s=-i.s,R(i)};B.plus=B.add=function(i){var e,t,n,r,o,s,a,c,u,l,m=this,d=m.constructor;if(i=new d(i),!m.d||!i.d)return!m.s||!i.s?i=new d(NaN):m.d||(i=new d(i.d||m.s===i.s?m:NaN)),i;if(m.s!=i.s)return i.s=-i.s,m.minus(i);if(u=m.d,l=i.d,a=d.precision,c=d.rounding,!u[0]||!l[0])return l[0]||(i=new d(m)),V?R(i,a,c):i;if(o=xe(m.e/D),n=xe(i.e/D),u=u.slice(),r=o-n,r){for(r<0?(t=u,r=-r,s=l.length):(t=l,n=o,s=u.length),o=Math.ceil(a/D),s=o>s?o+1:s+1,r>s&&(r=s,t.length=1),t.reverse();r--;)t.push(0);t.reverse()}for(s=u.length,r=l.length,s-r<0&&(r=s,t=l,l=u,u=t),e=0;r;)e=(u[--r]=u[r]+l[r]+e)/qe|0,u[r]%=qe;for(e&&(u.unshift(e),++n),s=u.length;u[--s]==0;)u.pop();return i.d=u,i.e=un(u,n),V?R(i,a,c):i};B.precision=B.sd=function(i){var e,t=this;if(i!==void 0&&i!==!!i&&i!==1&&i!==0)throw Error(ot+i);return t.d?(e=Di(t.d),i&&t.e+1>e&&(e=t.e+1)):e=NaN,e};B.round=function(){var i=this,e=i.constructor;return R(new e(i),i.e+1,e.rounding)};B.sine=B.sin=function(){var i,e,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(i=n.precision,e=n.rounding,n.precision=i+Math.max(t.e,t.sd())+D,n.rounding=1,t=jr(n,qi(n,t)),n.precision=i,n.rounding=e,R(et>2?t.neg():t,i,e,!0)):new n(NaN)};B.squareRoot=B.sqrt=function(){var i,e,t,n,r,o,s=this,a=s.d,c=s.e,u=s.s,l=s.constructor;if(u!==1||!a||!a[0])return new l(!u||u<0&&(!a||a[0])?NaN:a?s:1/0);for(V=!1,u=Math.sqrt(+s),u==0||u==1/0?(e=Pe(a),(e.length+c)%2==0&&(e+="0"),u=Math.sqrt(e),c=xe((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(o=n,n=o.plus(oe(s,o,t+2,1)).times(.5),Pe(o.d).slice(0,t)===(e=Pe(n.d)).slice(0,t))if(e=e.slice(t-3,t+1),e=="9999"||!r&&e=="4999"){if(!r&&(R(o,c+1,0),o.times(o).eq(s))){n=o;break}t+=4,r=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(R(n,c+1,1),i=!n.times(n).eq(s));break}return V=!0,R(n,c,l.rounding,i)};B.tangent=B.tan=function(){var i,e,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(i=n.precision,e=n.rounding,n.precision=i+10,n.rounding=1,t=t.sin(),t.s=1,t=oe(t,new n(1).minus(t.times(t)).sqrt(),i+10,0),n.precision=i,n.rounding=e,R(et==2||et==4?t.neg():t,i,e,!0)):new n(NaN)};B.times=B.mul=function(i){var e,t,n,r,o,s,a,c,u,l=this,m=l.constructor,d=l.d,p=(i=new m(i)).d;if(i.s*=l.s,!d||!d[0]||!p||!p[0])return new m(!i.s||d&&!d[0]&&!p||p&&!p[0]&&!d?NaN:!d||!p?i.s/0:i.s*0);for(t=xe(l.e/D)+xe(i.e/D),c=d.length,u=p.length,c<u&&(o=d,d=p,p=o,s=c,c=u,u=s),o=[],s=c+u,n=s;n--;)o.push(0);for(n=u;--n>=0;){for(e=0,r=c+n;r>n;)a=o[r]+p[n]*d[r-n-1]+e,o[r--]=a%qe|0,e=a/qe|0;o[r]=(o[r]+e)%qe|0}for(;!o[--s];)o.pop();return e?++t:o.shift(),i.d=o,i.e=un(o,t),V?R(i,m.precision,m.rounding):i};B.toBinary=function(i,e){return En(this,2,i,e)};B.toDecimalPlaces=B.toDP=function(i,e){var t=this,n=t.constructor;return t=new n(t),i===void 0?t:(Le(i,0,st),e===void 0?e=n.rounding:Le(e,0,8),R(t,i+t.e+1,e))};B.toExponential=function(i,e){var t,n=this,r=n.constructor;return i===void 0?t=je(n,!0):(Le(i,0,st),e===void 0?e=r.rounding:Le(e,0,8),n=R(new r(n),i+1,e),t=je(n,!0,i+1)),n.isNeg()&&!n.isZero()?"-"+t:t};B.toFixed=function(i,e){var t,n,r=this,o=r.constructor;return i===void 0?t=je(r):(Le(i,0,st),e===void 0?e=o.rounding:Le(e,0,8),n=R(new o(r),i+r.e+1,e),t=je(n,!1,i+n.e+1)),r.isNeg()&&!r.isZero()?"-"+t:t};B.toFraction=function(i){var e,t,n,r,o,s,a,c,u,l,m,d,p=this,g=p.d,f=p.constructor;if(!g)return new f(p);if(u=t=new f(1),n=c=new f(0),e=new f(n),o=e.e=Di(g)-p.e-1,s=o%D,e.d[0]=be(10,s<0?D+s:s),i==null)i=o>0?e:u;else{if(a=new f(i),!a.isInt()||a.lt(u))throw Error(ot+a);i=a.gt(e)?o>0?e:u:a}for(V=!1,a=new f(Pe(g)),l=f.precision,f.precision=o=g.length*D*2;m=oe(a,e,0,1,1),r=t.plus(m.times(n)),r.cmp(i)!=1;)t=n,n=r,r=u,u=c.plus(m.times(r)),c=r,r=e,e=a.minus(m.times(r)),a=r;return r=oe(i.minus(t),n,0,1,1),c=c.plus(r.times(u)),t=t.plus(r.times(n)),c.s=u.s=p.s,d=oe(u,n,o,1).minus(p).abs().cmp(oe(c,t,o,1).minus(p).abs())<1?[u,n]:[c,t],f.precision=l,V=!0,d};B.toHexadecimal=B.toHex=function(i,e){return En(this,16,i,e)};B.toNearest=function(i,e){var t=this,n=t.constructor;if(t=new n(t),i==null){if(!t.d)return t;i=new n(1),e=n.rounding}else{if(i=new n(i),e===void 0?e=n.rounding:Le(e,0,8),!t.d)return i.s?t:i;if(!i.d)return i.s&&(i.s=t.s),i}return i.d[0]?(V=!1,t=oe(t,i,0,e,1).times(i),V=!0,R(t)):(i.s=t.s,t=i),t};B.toNumber=function(){return+this};B.toOctal=function(i,e){return En(this,8,i,e)};B.toPower=B.pow=function(i){var e,t,n,r,o,s,a=this,c=a.constructor,u=+(i=new c(i));if(!a.d||!i.d||!a.d[0]||!i.d[0])return new c(be(+a,u));if(a=new c(a),a.eq(1))return a;if(n=c.precision,o=c.rounding,i.eq(1))return R(a,n,o);if(e=xe(i.e/D),e>=i.d.length-1&&(t=u<0?-u:u)<=Xr)return r=vi(c,a,t,n),i.s<0?new c(1).div(r):R(r,n,o);if(s=a.s,s<0){if(e<i.d.length-1)return new c(NaN);if((i.d[e]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return t=be(+a,u),e=t==0||!isFinite(t)?xe(u*(Math.log("0."+Pe(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):(V=!1,c.rounding=a.s=1,t=Math.min(12,(e+"").length),r=On(i.times(rt(a,n+t)),n),r.d&&(r=R(r,n+5,1),Dt(r.d,n,o)&&(e=n+10,r=R(On(i.times(rt(a,e+t)),e),e+5,1),+Pe(r.d).slice(n+1,n+15)+1==1e14&&(r=R(r,n+1,0)))),r.s=s,V=!0,c.rounding=o,R(r,n,o))};B.toPrecision=function(i,e){var t,n=this,r=n.constructor;return i===void 0?t=je(n,n.e<=r.toExpNeg||n.e>=r.toExpPos):(Le(i,1,st),e===void 0?e=r.rounding:Le(e,0,8),n=R(new r(n),i,e),t=je(n,i<=n.e||n.e<=r.toExpNeg,i)),n.isNeg()&&!n.isZero()?"-"+t:t};B.toSignificantDigits=B.toSD=function(i,e){var t=this,n=t.constructor;return i===void 0?(i=n.precision,e=n.rounding):(Le(i,1,st),e===void 0?e=n.rounding:Le(e,0,8)),R(new n(t),i,e)};B.toString=function(){var i=this,e=i.constructor,t=je(i,i.e<=e.toExpNeg||i.e>=e.toExpPos);return i.isNeg()&&!i.isZero()?"-"+t:t};B.truncated=B.trunc=function(){return R(new this.constructor(this),this.e+1,1)};B.valueOf=B.toJSON=function(){var i=this,e=i.constructor,t=je(i,i.e<=e.toExpNeg||i.e>=e.toExpPos);return i.isNeg()?"-"+t:t};function Pe(i){var e,t,n,r=i.length-1,o="",s=i[0];if(r>0){for(o+=s,e=1;e<r;e++)n=i[e]+"",t=D-n.length,t&&(o+=it(t)),o+=n;s=i[e],n=s+"",t=D-n.length,t&&(o+=it(t))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function Le(i,e,t){if(i!==~~i||i<e||i>t)throw Error(ot+i)}function Dt(i,e,t,n){var r,o,s,a;for(o=i[0];o>=10;o/=10)--e;return--e<0?(e+=D,r=0):(r=Math.ceil((e+1)/D),e%=D),o=be(10,D-e),a=i[r]%o|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==o||t>3&&a+1==o/2)&&(i[r+1]/o/100|0)==be(10,e-2)-1||(a==o/2||a==0)&&(i[r+1]/o/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==o||!n&&t>3&&a+1==o/2)&&(i[r+1]/o/1e3|0)==be(10,e-3)-1,s}function rn(i,e,t){for(var n,r=[0],o,s=0,a=i.length;s<a;){for(o=r.length;o--;)r[o]*=e;for(r[0]+=Ln.indexOf(i.charAt(s++)),n=0;n<r.length;n++)r[n]>t-1&&(r[n+1]===void 0&&(r[n+1]=0),r[n+1]+=r[n]/t|0,r[n]%=t)}return r.reverse()}function Hr(i,e){var t,n,r;if(e.isZero())return e;n=e.d.length,n<32?(t=Math.ceil(n/3),r=(1/ln(4,t)).toString()):(t=16,r="2.3283064365386962890625e-10"),i.precision+=t,e=At(i,1,e.times(r),new i(1));for(var o=t;o--;){var s=e.times(e);e=s.times(s).minus(s).times(8).plus(1)}return i.precision-=t,e}var oe=function(){function i(n,r,o){var s,a=0,c=n.length;for(n=n.slice();c--;)s=n[c]*r+a,n[c]=s%o|0,a=s/o|0;return a&&n.unshift(a),n}function e(n,r,o,s){var a,c;if(o!=s)c=o>s?1:-1;else for(a=c=0;a<o;a++)if(n[a]!=r[a]){c=n[a]>r[a]?1:-1;break}return c}function t(n,r,o,s){for(var a=0;o--;)n[o]-=a,a=n[o]<r[o]?1:0,n[o]=a*s+n[o]-r[o];for(;!n[0]&&n.length>1;)n.shift()}return function(n,r,o,s,a,c){var u,l,m,d,p,g,f,y,b,P,w,k,T,A,h,I,N,E,L,Q,ee=n.constructor,le=n.s==r.s?1:-1,re=n.d,Z=r.d;if(!re||!re[0]||!Z||!Z[0])return new ee(!n.s||!r.s||(re?Z&&re[0]==Z[0]:!Z)?NaN:re&&re[0]==0||!Z?le*0:le/0);for(c?(p=1,l=n.e-r.e):(c=qe,p=D,l=xe(n.e/p)-xe(r.e/p)),L=Z.length,N=re.length,b=new ee(le),P=b.d=[],m=0;Z[m]==(re[m]||0);m++);if(Z[m]>(re[m]||0)&&l--,o==null?(A=o=ee.precision,s=ee.rounding):a?A=o+(n.e-r.e)+1:A=o,A<0)P.push(1),g=!0;else{if(A=A/p+2|0,m=0,L==1){for(d=0,Z=Z[0],A++;(m<N||d)&&A--;m++)h=d*c+(re[m]||0),P[m]=h/Z|0,d=h%Z|0;g=d||m<N}else{for(d=c/(Z[0]+1)|0,d>1&&(Z=i(Z,d,c),re=i(re,d,c),L=Z.length,N=re.length),I=L,w=re.slice(0,L),k=w.length;k<L;)w[k++]=0;Q=Z.slice(),Q.unshift(0),E=Z[0],Z[1]>=c/2&&++E;do d=0,u=e(Z,w,L,k),u<0?(T=w[0],L!=k&&(T=T*c+(w[1]||0)),d=T/E|0,d>1?(d>=c&&(d=c-1),f=i(Z,d,c),y=f.length,k=w.length,u=e(f,w,y,k),u==1&&(d--,t(f,L<y?Q:Z,y,c))):(d==0&&(u=d=1),f=Z.slice()),y=f.length,y<k&&f.unshift(0),t(w,f,k,c),u==-1&&(k=w.length,u=e(Z,w,L,k),u<1&&(d++,t(w,L<k?Q:Z,k,c))),k=w.length):u===0&&(d++,w=[0]),P[m++]=d,u&&w[0]?w[k++]=re[I]||0:(w=[re[I]],k=1);while((I++<N||w[0]!==void 0)&&A--);g=w[0]!==void 0}P[0]||P.shift()}if(p==1)b.e=l,Ri=g;else{for(m=1,d=P[0];d>=10;d/=10)m++;b.e=m+l*p-1,R(b,a?o+b.e+1:o,s,g)}return b}}();function R(i,e,t,n){var r,o,s,a,c,u,l,m,d,p=i.constructor;e:if(e!=null){if(m=i.d,!m)return i;for(r=1,a=m[0];a>=10;a/=10)r++;if(o=e-r,o<0)o+=D,s=e,l=m[d=0],c=l/be(10,r-s-1)%10|0;else if(d=Math.ceil((o+1)/D),a=m.length,d>=a)if(n){for(;a++<=d;)m.push(0);l=c=0,r=1,o%=D,s=o-D+1}else break e;else{for(l=a=m[d],r=1;a>=10;a/=10)r++;o%=D,s=o-D+r,c=s<0?0:l/be(10,r-s-1)%10|0}if(n=n||e<0||m[d+1]!==void 0||(s<0?l:l%be(10,r-s-1)),u=t<4?(c||n)&&(t==0||t==(i.s<0?3:2)):c>5||c==5&&(t==4||n||t==6&&(o>0?s>0?l/be(10,r-s):0:m[d-1])%10&1||t==(i.s<0?8:7)),e<1||!m[0])return m.length=0,u?(e-=i.e+1,m[0]=be(10,(D-e%D)%D),i.e=-e||0):m[0]=i.e=0,i;if(o==0?(m.length=d,a=1,d--):(m.length=d+1,a=be(10,D-o),m[d]=s>0?(l/be(10,r-s)%be(10,s)|0)*a:0),u)for(;;)if(d==0){for(o=1,s=m[0];s>=10;s/=10)o++;for(s=m[0]+=a,a=1;s>=10;s/=10)a++;o!=a&&(i.e++,m[0]==qe&&(m[0]=1));break}else{if(m[d]+=a,m[d]!=qe)break;m[d--]=0,a=1}for(o=m.length;m[--o]===0;)m.pop()}return V&&(i.e>p.maxE?(i.d=null,i.e=NaN):i.e<p.minE&&(i.e=0,i.d=[0])),i}function je(i,e,t){if(!i.isFinite())return _i(i);var n,r=i.e,o=Pe(i.d),s=o.length;return e?(t&&(n=t-s)>0?o=o.charAt(0)+"."+o.slice(1)+it(n):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(i.e<0?"e":"e+")+i.e):r<0?(o="0."+it(-r-1)+o,t&&(n=t-s)>0&&(o+=it(n))):r>=s?(o+=it(r+1-s),t&&(n=t-r-1)>0&&(o=o+"."+it(n))):((n=r+1)<s&&(o=o.slice(0,n)+"."+o.slice(n)),t&&(n=t-s)>0&&(r+1===s&&(o+="."),o+=it(n))),o}function un(i,e){var t=i[0];for(e*=D;t>=10;t/=10)e++;return e}function an(i,e,t){if(e>zr)throw V=!0,t&&(i.precision=t),Error(Mi);return R(new i(on),e,1,!0)}function _e(i,e,t){if(e>Mn)throw Error(Mi);return R(new i(sn),e,t,!0)}function Di(i){var e=i.length-1,t=e*D+1;if(e=i[e],e){for(;e%10==0;e/=10)t--;for(e=i[0];e>=10;e/=10)t++}return t}function it(i){for(var e="";i--;)e+="0";return e}function vi(i,e,t,n){var r,o=new i(1),s=Math.ceil(n/D+4);for(V=!1;;){if(t%2&&(o=o.times(e),Ni(o.d,s)&&(r=!0)),t=xe(t/2),t===0){t=o.d.length-1,r&&o.d[t]===0&&++o.d[t];break}e=e.times(e),Ni(e.d,s)}return V=!0,o}function Ki(i){return i.d[i.d.length-1]&1}function Vi(i,e,t){for(var n,r=new i(e[0]),o=0;++o<e.length;)if(n=new i(e[o]),n.s)r[t](n)&&(r=n);else{r=n;break}return r}function On(i,e){var t,n,r,o,s,a,c,u=0,l=0,m=0,d=i.constructor,p=d.rounding,g=d.precision;if(!i.d||!i.d[0]||i.e>17)return new d(i.d?i.d[0]?i.s<0?0:1/0:1:i.s?i.s<0?0:i:0/0);for(e==null?(V=!1,c=g):c=e,a=new d(.03125);i.e>-2;)i=i.times(a),m+=5;for(n=Math.log(be(2,m))/Math.LN10*2+5|0,c+=n,t=o=s=new d(1),d.precision=c;;){if(o=R(o.times(i),c,1),t=t.times(++l),a=s.plus(oe(o,t,c,1)),Pe(a.d).slice(0,c)===Pe(s.d).slice(0,c)){for(r=m;r--;)s=R(s.times(s),c,1);if(e==null)if(u<3&&Dt(s.d,c-n,p,u))d.precision=c+=10,t=o=a=new d(1),l=0,u++;else return R(s,d.precision=g,p,V=!0);else return d.precision=g,s}s=a}}function rt(i,e){var t,n,r,o,s,a,c,u,l,m,d,p=1,g=10,f=i,y=f.d,b=f.constructor,P=b.rounding,w=b.precision;if(f.s<0||!y||!y[0]||!f.e&&y[0]==1&&y.length==1)return new b(y&&!y[0]?-1/0:f.s!=1?NaN:y?0:f);if(e==null?(V=!1,l=w):l=e,b.precision=l+=g,t=Pe(y),n=t.charAt(0),Math.abs(o=f.e)<15e14){for(;n<7&&n!=1||n==1&&t.charAt(1)>3;)f=f.times(i),t=Pe(f.d),n=t.charAt(0),p++;o=f.e,n>1?(f=new b("0."+t),o++):f=new b(n+"."+t.slice(1))}else return u=an(b,l+2,w).times(o+""),f=rt(new b(n+"."+t.slice(1)),l-g).plus(u),b.precision=w,e==null?R(f,w,P,V=!0):f;for(m=f,c=s=f=oe(f.minus(1),f.plus(1),l,1),d=R(f.times(f),l,1),r=3;;){if(s=R(s.times(d),l,1),u=c.plus(oe(s,new b(r),l,1)),Pe(u.d).slice(0,l)===Pe(c.d).slice(0,l))if(c=c.times(2),o!==0&&(c=c.plus(an(b,l+2,w).times(o+""))),c=oe(c,new b(p),l,1),e==null)if(Dt(c.d,l-g,P,a))b.precision=l+=g,u=s=f=oe(m.minus(1),m.plus(1),l,1),d=R(f.times(f),l,1),r=a=1;else return R(c,b.precision=w,P,V=!0);else return b.precision=w,c;c=u,r+=2}}function _i(i){return String(i.s*i.s/0)}function Fn(i,e){var t,n,r;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(r=e.length;e.charCodeAt(r-1)===48;--r);if(e=e.slice(n,r),e){if(r-=n,i.e=t=t-n-1,i.d=[],n=(t+1)%D,t<0&&(n+=D),n<r){for(n&&i.d.push(+e.slice(0,n)),r-=D;n<r;)i.d.push(+e.slice(n,n+=D));e=e.slice(n),n=D-e.length}else n-=r;for(;n--;)e+="0";i.d.push(+e),V&&(i.e>i.constructor.maxE?(i.d=null,i.e=NaN):i.e<i.constructor.minE&&(i.e=0,i.d=[0]))}else i.e=0,i.d=[0];return i}function Yr(i,e){var t,n,r,o,s,a,c,u,l;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),Ei.test(e))return Fn(i,e)}else if(e==="Infinity"||e==="NaN")return+e||(i.s=NaN),i.e=NaN,i.d=null,i;if(Gr.test(e))t=16,e=e.toLowerCase();else if(Wr.test(e))t=2;else if(Ur.test(e))t=8;else throw Error(ot+e);for(o=e.search(/p/i),o>0?(c=+e.slice(o+1),e=e.substring(2,o)):e=e.slice(2),o=e.indexOf("."),s=o>=0,n=i.constructor,s&&(e=e.replace(".",""),a=e.length,o=a-o,r=vi(n,new n(t),o,o*2)),u=rn(e,t,qe),l=u.length-1,o=l;u[o]===0;--o)u.pop();return o<0?new n(i.s*0):(i.e=un(u,l),i.d=u,V=!1,s&&(i=oe(i,r,a*4)),c&&(i=i.times(Math.abs(c)<54?be(2,c):vt.pow(2,c))),V=!0,i)}function jr(i,e){var t,n=e.d.length;if(n<3)return e.isZero()?e:At(i,2,e,e);t=1.4*Math.sqrt(n),t=t>16?16:t|0,e=e.times(1/ln(5,t)),e=At(i,2,e,e);for(var r,o=new i(5),s=new i(16),a=new i(20);t--;)r=e.times(e),e=e.times(o.plus(r.times(s.times(r).minus(a))));return e}function At(i,e,t,n,r){var o,s,a,c,u=1,l=i.precision,m=Math.ceil(l/D);for(V=!1,c=t.times(t),a=new i(n);;){if(s=oe(a.times(c),new i(e++*e++),l,1),a=r?n.plus(s):n.minus(s),n=oe(s.times(c),new i(e++*e++),l,1),s=a.plus(n),s.d[m]!==void 0){for(o=m;s.d[o]===a.d[o]&&o--;);if(o==-1)break}o=a,a=n,n=s,s=o,u++}return V=!0,s.d.length=m+1,s}function ln(i,e){for(var t=i;--e;)t*=i;return t}function qi(i,e){var t,n=e.s<0,r=_e(i,i.precision,1),o=r.times(.5);if(e=e.abs(),e.lte(o))return et=n?4:1,e;if(t=e.divToInt(r),t.isZero())et=n?3:2;else{if(e=e.minus(t.times(r)),e.lte(o))return et=Ki(t)?n?2:3:n?4:1,e;et=Ki(t)?n?1:4:n?3:2}return e.minus(r).abs()}function En(i,e,t,n){var r,o,s,a,c,u,l,m,d,p=i.constructor,g=t!==void 0;if(g?(Le(t,1,st),n===void 0?n=p.rounding:Le(n,0,8)):(t=p.precision,n=p.rounding),!i.isFinite())l=_i(i);else{for(l=je(i),s=l.indexOf("."),g?(r=2,e==16?t=t*4-3:e==8&&(t=t*3-2)):r=e,s>=0&&(l=l.replace(".",""),d=new p(1),d.e=l.length-s,d.d=rn(je(d),10,r),d.e=d.d.length),m=rn(l,10,r),o=c=m.length;m[--c]==0;)m.pop();if(!m[0])l=g?"0p+0":"0";else{if(s<0?o--:(i=new p(i),i.d=m,i.e=o,i=oe(i,d,t,n,0,r),m=i.d,o=i.e,u=Ri),s=m[t],a=r/2,u=u||m[t+1]!==void 0,u=n<4?(s!==void 0||u)&&(n===0||n===(i.s<0?3:2)):s>a||s===a&&(n===4||u||n===6&&m[t-1]&1||n===(i.s<0?8:7)),m.length=t,u)for(;++m[--t]>r-1;)m[t]=0,t||(++o,m.unshift(1));for(c=m.length;!m[c-1];--c);for(s=0,l="";s<c;s++)l+=Ln.charAt(m[s]);if(g){if(c>1)if(e==16||e==8){for(s=e==16?4:3,--c;c%s;c++)l+="0";for(m=rn(l,r,e),c=m.length;!m[c-1];--c);for(s=1,l="1.";s<c;s++)l+=Ln.charAt(m[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)l="0"+l;l="0."+l}else if(++o>c)for(o-=c;o--;)l+="0";else o<c&&(l=l.slice(0,o)+"."+l.slice(o))}l=(e==16?"0x":e==2?"0b":e==8?"0o":"")+l}return i.s<0?"-"+l:l}function Ni(i,e){if(i.length>e)return i.length=e,!0}function Zr(i){return new this(i).abs()}function Qr(i){return new this(i).acos()}function Jr(i){return new this(i).acosh()}function $r(i,e){return new this(i).plus(e)}function eo(i){return new this(i).asin()}function to(i){return new this(i).asinh()}function no(i){return new this(i).atan()}function io(i){return new this(i).atanh()}function ro(i,e){i=new this(i),e=new this(e);var t,n=this.precision,r=this.rounding,o=n+4;return!i.s||!e.s?t=new this(NaN):!i.d&&!e.d?(t=_e(this,o,1).times(e.s>0?.25:.75),t.s=i.s):!e.d||i.isZero()?(t=e.s<0?_e(this,n,r):new this(0),t.s=i.s):!i.d||e.isZero()?(t=_e(this,o,1).times(.5),t.s=i.s):e.s<0?(this.precision=o,this.rounding=1,t=this.atan(oe(i,e,o,1)),e=_e(this,o,1),this.precision=n,this.rounding=r,t=i.s<0?t.minus(e):t.plus(e)):t=this.atan(oe(i,e,o,1)),t}function oo(i){return new this(i).cbrt()}function so(i){return R(i=new this(i),i.e+1,2)}function ao(i,e,t){return new this(i).clamp(e,t)}function co(i){if(!i||typeof i!="object")throw Error(cn+"Object expected");var e,t,n,r=i.defaults===!0,o=["precision",1,st,"rounding",0,8,"toExpNeg",-Pt,0,"toExpPos",0,Pt,"maxE",0,Pt,"minE",-Pt,0,"modulo",0,9];for(e=0;e<o.length;e+=3)if(t=o[e],r&&(this[t]=Rn[t]),(n=i[t])!==void 0)if(xe(n)===n&&n>=o[e+1]&&n<=o[e+2])this[t]=n;else throw Error(ot+t+": "+n);if(t="crypto",r&&(this[t]=Rn[t]),(n=i[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(Oi);else this[t]=!1;else throw Error(ot+t+": "+n);return this}function uo(i){return new this(i).cos()}function lo(i){return new this(i).cosh()}function Wi(i){var e,t,n;function r(o){var s,a,c,u=this;if(!(u instanceof r))return new r(o);if(u.constructor=r,Li(o)){u.s=o.s,V?!o.d||o.e>r.maxE?(u.e=NaN,u.d=null):o.e<r.minE?(u.e=0,u.d=[0]):(u.e=o.e,u.d=o.d.slice()):(u.e=o.e,u.d=o.d?o.d.slice():o.d);return}if(c=typeof o,c==="number"){if(o===0){u.s=1/o<0?-1:1,u.e=0,u.d=[0];return}if(o<0?(o=-o,u.s=-1):u.s=1,o===~~o&&o<1e7){for(s=0,a=o;a>=10;a/=10)s++;V?s>r.maxE?(u.e=NaN,u.d=null):s<r.minE?(u.e=0,u.d=[0]):(u.e=s,u.d=[o]):(u.e=s,u.d=[o]);return}else if(o*0!==0){o||(u.s=NaN),u.e=NaN,u.d=null;return}return Fn(u,o.toString())}else if(c!=="string")throw Error(ot+o);return(a=o.charCodeAt(0))===45?(o=o.slice(1),u.s=-1):(a===43&&(o=o.slice(1)),u.s=1),Ei.test(o)?Fn(u,o):Yr(u,o)}if(r.prototype=B,r.ROUND_UP=0,r.ROUND_DOWN=1,r.ROUND_CEIL=2,r.ROUND_FLOOR=3,r.ROUND_HALF_UP=4,r.ROUND_HALF_DOWN=5,r.ROUND_HALF_EVEN=6,r.ROUND_HALF_CEIL=7,r.ROUND_HALF_FLOOR=8,r.EUCLID=9,r.config=r.set=co,r.clone=Wi,r.isDecimal=Li,r.abs=Zr,r.acos=Qr,r.acosh=Jr,r.add=$r,r.asin=eo,r.asinh=to,r.atan=no,r.atanh=io,r.atan2=ro,r.cbrt=oo,r.ceil=so,r.clamp=ao,r.cos=uo,r.cosh=lo,r.div=mo,r.exp=po,r.floor=fo,r.hypot=go,r.ln=bo,r.log=yo,r.log10=Po,r.log2=wo,r.max=Ao,r.min=ko,r.mod=ho,r.mul=To,r.pow=xo,r.random=Bo,r.round=Io,r.sign=So,r.sin=Co,r.sinh=Ko,r.sqrt=No,r.sub=Lo,r.sum=Ro,r.tan=Mo,r.tanh=Oo,r.trunc=Fo,i===void 0&&(i={}),i&&i.defaults!==!0)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<n.length;)i.hasOwnProperty(t=n[e++])||(i[t]=this[t]);return r.config(i),r}function mo(i,e){return new this(i).div(e)}function po(i){return new this(i).exp()}function fo(i){return R(i=new this(i),i.e+1,3)}function go(){var i,e,t=new this(0);for(V=!1,i=0;i<arguments.length;)if(e=new this(arguments[i++]),e.d)t.d&&(t=t.plus(e.times(e)));else{if(e.s)return V=!0,new this(1/0);t=e}return V=!0,t.sqrt()}function Li(i){return i instanceof vt||i&&i.toStringTag===Fi||!1}function bo(i){return new this(i).ln()}function yo(i,e){return new this(i).log(e)}function wo(i){return new this(i).log(2)}function Po(i){return new this(i).log(10)}function Ao(){return Vi(this,arguments,"lt")}function ko(){return Vi(this,arguments,"gt")}function ho(i,e){return new this(i).mod(e)}function To(i,e){return new this(i).mul(e)}function xo(i,e){return new this(i).pow(e)}function Bo(i){var e,t,n,r,o=0,s=new this(1),a=[];if(i===void 0?i=this.precision:Le(i,1,st),n=Math.ceil(i/D),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(n));o<n;)r=e[o],r>=429e7?e[o]=crypto.getRandomValues(new Uint32Array(1))[0]:a[o++]=r%1e7;else if(crypto.randomBytes){for(e=crypto.randomBytes(n*=4);o<n;)r=e[o]+(e[o+1]<<8)+(e[o+2]<<16)+((e[o+3]&127)<<24),r>=214e7?crypto.randomBytes(4).copy(e,o):(a.push(r%1e7),o+=4);o=n/4}else throw Error(Oi);else for(;o<n;)a[o++]=Math.random()*1e7|0;for(n=a[--o],i%=D,n&&i&&(r=be(10,D-i),a[o]=(n/r|0)*r);a[o]===0;o--)a.pop();if(o<0)t=0,a=[0];else{for(t=-1;a[0]===0;t-=D)a.shift();for(n=1,r=a[0];r>=10;r/=10)n++;n<D&&(t-=D-n)}return s.e=t,s.d=a,s}function Io(i){return R(i=new this(i),i.e+1,this.rounding)}function So(i){return i=new this(i),i.d?i.d[0]?i.s:0*i.s:i.s||NaN}function Co(i){return new this(i).sin()}function Ko(i){return new this(i).sinh()}function No(i){return new this(i).sqrt()}function Lo(i,e){return new this(i).sub(e)}function Ro(){var i=0,e=arguments,t=new this(e[i]);for(V=!1;t.s&&++i<e.length;)t=t.plus(e[i]);return V=!0,R(t,this.precision,this.rounding)}function Mo(i){return new this(i).tan()}function Oo(i){return new this(i).tanh()}function Fo(i){return R(i=new this(i),i.e+1,1)}B[Symbol.for("nodejs.util.inspect.custom")]=B.toString;B[Symbol.toStringTag]="Decimal";var vt=B.constructor=Wi(Rn);on=new vt(on);sn=new vt(sn);var S=vt;var _n=require("@solana/web3.js");var Vt=require("lodash");var Dn=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}},Gi={},Eo={};function Ae(i){let e=(0,Vt.get)(Gi,i);if(!e){let t=(0,Vt.get)(Eo,i);e=new Dn({name:i,logLevel:t}),(0,Vt.set)(Gi,i,e)}return e}var at=require("@solana/spl-token"),vn=Ae("Raydium_accountInfo_util");async function tt(i,e,t){let{batchRequest:n,commitment:r="confirmed",chunkCount:o=100}={batchRequest:!1,...t},s=Vn(e,o),a=new Array(s.length).fill([]);if(n){let c=s.map(m=>{let d=i._buildArgs([m.map(p=>p.toBase58())],r,"base64");return{methodName:"getMultipleAccounts",args:d}}),u=Vn(c,10);a=(await(await Promise.all(u.map(async m=>await i._rpcBatchRequest(m)))).flat()).map(m=>(m.error&&vn.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${m.error.message}`),m.result.value.map(d=>{if(d){let{data:p,executable:g,lamports:f,owner:y,rentEpoch:b}=d;return p.length!==2&&p[1]!=="base64"&&vn.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(p[0],"base64"),executable:g,lamports:f,owner:new _n.PublicKey(y),rentEpoch:b}}return null})))}else try{a=await Promise.all(s.map(c=>i.getMultipleAccountsInfo(c,r)))}catch(c){c instanceof Error&&vn.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return a.flat()}async function ct(i,e,t){let n=await tt(i,e.map(r=>r.pubkey),t);return e.map((r,o)=>({...r,accountInfo:n[o]}))}async function Ui({connection:i,mints:e,config:t}){var o,s,a;if(e.length===0)return{};let n=await ct(i,e.map(c=>({pubkey:bt(c)})),t),r={};for(let c of n){if(!c.accountInfo||c.accountInfo.data.length<at.MINT_SIZE){console.log("invalid mint account",c.pubkey.toBase58());continue}let u=(0,at.unpackMint)(c.pubkey,c.accountInfo,(o=c.accountInfo)==null?void 0:o.owner);r[c.pubkey.toString()]={...u,programId:((s=c.accountInfo)==null?void 0:s.owner)||at.TOKEN_PROGRAM_ID,feeConfig:(a=(0,at.getTransferFeeConfig)(u))!=null?a:void 0}}return r[_n.PublicKey.default.toBase58()]=r[j.toBase58()],r}var Qe=fe(require("bn.js"));var Zi=fe(require("big.js")),Gt=fe(require("bn.js"));var Xi=fe(require("toformat")),Do=Xi.default,_t=Do;var qt=fe(require("big.js")),Hi=fe(require("bn.js")),Yi=fe(require("decimal.js-light"));var kt=fe(require("bn.js"));var zi=9007199254740991;function ye(i){let e=Ae("Raydium_parseBigNumberish");if(i instanceof kt.default)return i;if(typeof i=="string"){if(i.match(/^-?[0-9]+$/))return new kt.default(i);e.logWithError(`invalid BigNumberish string: ${i}`)}return typeof i=="number"?(i%1&&e.logWithError(`BigNumberish number underflow: ${i}`),(i>=zi||i<=-zi)&&e.logWithError(`BigNumberish number overflow: ${i}`),new kt.default(String(i))):typeof i=="bigint"?new kt.default(i.toString()):(e.error(`invalid BigNumberish value: ${i}`),new kt.default(0))}var mn=Ae("module/fraction"),qn=_t(qt.default),Wt=_t(Yi.default),Vo={[0]:Wt.ROUND_DOWN,[1]:Wt.ROUND_HALF_UP,[2]:Wt.ROUND_UP},_o={[0]:qt.default.roundDown,[1]:qt.default.roundHalfUp,[2]:qt.default.roundUp},J=class{constructor(e,t=new Hi.default(1)){this.numerator=ye(e),this.denominator=ye(t)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new J(this.denominator,this.numerator)}add(e){let t=e instanceof J?e:new J(ye(e));return this.denominator.eq(t.denominator)?new J(this.numerator.add(t.numerator),this.denominator):new J(this.numerator.mul(t.denominator).add(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}sub(e){let t=e instanceof J?e:new J(ye(e));return this.denominator.eq(t.denominator)?new J(this.numerator.sub(t.numerator),this.denominator):new J(this.numerator.mul(t.denominator).sub(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}mul(e){let t=e instanceof J?e:new J(ye(e));return new J(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof J?e:new J(ye(e));return new J(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},n=1){Number.isInteger(e)||mn.logWithError(`${e} is not an integer.`),e<=0&&mn.logWithError(`${e} is not positive.`),Wt.set({precision:e+1,rounding:Vo[n]});let r=new Wt(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return r.toFormat(r.decimalPlaces(),t)}toFixed(e,t={groupSeparator:""},n=1){return Number.isInteger(e)||mn.logWithError(`${e} is not an integer.`),e<0&&mn.logWithError(`${e} is negative.`),qn.DP=e,qn.RM=_o[n]||1,new qn(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};var qo=Ae("Raydium_amount"),ji=_t(Zi.default);function Wo(i,e){let t="0",n="0";if(i.includes(".")){let r=i.split(".");r.length===2?([t,n]=r,n=n.padEnd(e,"0")):qo.logWithError(`invalid number string, num: ${i}`)}else t=i;return[t,n.slice(0,e)||n]}var ke=class extends J{constructor(t,n,r=!0,o){let s=new Gt.default(0),a=Wn.pow(new Gt.default(t.decimals));if(r)s=ye(n);else{let c=new Gt.default(0),u=new Gt.default(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[l,m]=Wo(n.toString(),t.decimals);c=ye(l),u=ye(m)}c=c.mul(a),s=c.add(u)}super(s,a);this.logger=Ae(o||"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 ke(this.token,this.raw.add(t.raw))}subtract(t){return this.token.equals(t.token)||this.logger.logWithError("sub token not equals"),new ke(this.token,this.raw.sub(t.raw))}toSignificant(t=this.token.decimals,n,r=0){return super.toSignificant(t,n,r)}toFixed(t=this.token.decimals,n,r=0){return t>this.token.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(t,n,r)}toExact(t={groupSeparator:""}){return ji.DP=this.token.decimals,new ji(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)}};var Qi=require("@solana/web3.js"),Gn=require("@solana/spl-token"),Un={chainId:101,address:Qi.PublicKey.default.toBase58(),programId:Gn.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},ut={chainId:101,address:"So11111111111111111111111111111111111111112",programId:Gn.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}};var pn=require("@solana/web3.js");var $=require("@solana/web3.js"),Ji=require("@solana/spl-token");function Xn({pubkey:i,isSigner:e=!1,isWritable:t=!0}){return{pubkey:i,isWritable:t,isSigner:e}}var Hs=[Xn({pubkey:Ji.TOKEN_PROGRAM_ID,isWritable:!1}),Xn({pubkey:$.SystemProgram.programId,isWritable:!1}),Xn({pubkey:$.SYSVAR_RENT_PUBKEY,isWritable:!1})];function zn({publicKey:i,transformSol:e}){let t=$i(i.toString());if(t instanceof $.PublicKey)return e&&t.equals(Ut)?j:t;if(e&&t.toString()===Ut.toBase58())return j;if(typeof t=="string"){if(t===$.PublicKey.default.toBase58())return $.PublicKey.default;try{return new $.PublicKey(t)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function $i(i){try{return new $.PublicKey(i)}catch{return i}}var dn=new $.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Hn=new $.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),ht=new $.PublicKey("SysvarRent111111111111111111111111111111111"),Ys=new $.PublicKey("SysvarC1ock11111111111111111111111111111111"),yt=new $.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),js=new $.PublicKey("Sysvar1nstructions1111111111111111111111111"),Zs=$.SystemProgram.programId,Qs=new $.PublicKey("2cpMA1jNS4obgRz8XNg38QuSP83L1AXpUgfxPNcvnAGj"),Js=new $.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),$s=new $.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),ea=new $.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),ta=new $.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),na=new $.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),ia=new $.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),ra=new $.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),oa=new $.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),sa=new $.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),aa=new $.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),j=new $.PublicKey("So11111111111111111111111111111111111111112"),Ut=$.PublicKey.default;function bt(i){return zn({publicKey:i,transformSol:!0})}var Yn=class{constructor({mint:e,decimals:t,symbol:n,name:r,skipMint:o=!1,isToken2022:s=!1}){if(e===Ut.toBase58()||e instanceof pn.PublicKey&&Ut.equals(e)){this.decimals=ut.decimals,this.symbol=ut.symbol,this.name=ut.name,this.mint=new pn.PublicKey(ut.address),this.isToken2022=!1;return}this.decimals=t,this.symbol=n||e.toString().substring(0,6),this.name=r||e.toString().substring(0,6),this.mint=o?pn.PublicKey.default:zn({publicKey:e}),this.isToken2022=s}equals(e){return this===e?!0:this.mint.equals(e.mint)}},Ze=Yn;Ze.WSOL=new Yn({...ut,mint:ut.address});var jn=class{constructor({decimals:e,symbol:t="UNKNOWN",name:n="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=n}equals(e){return this===e}},fn=jn;fn.SOL=new jn(Un);var tr=fe(require("bn.js"));var er=new J(new tr.default(100)),lt=class extends J{toSignificant(e=5,t,n){return this.mul(er).toSignificant(e,t,n)}toFixed(e=2,t,n){return this.mul(er).toFixed(e,t,n)}};var Go=Ae("Raydium_price"),We=class extends J{constructor(t){let{baseToken:n,quoteToken:r,numerator:o,denominator:s}=t;super(o,s);this.baseToken=n,this.quoteToken=r,this.scalar=new J(Zn(n.decimals),Zn(r.decimals))}get raw(){return new J(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new We({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numerator,numerator:this.denominator})}mul(t){this.quoteToken!==t.baseToken&&Go.logWithError("mul token not equals");let n=super.mul(t);return new We({baseToken:this.baseToken,quoteToken:t.quoteToken,denominator:n.denominator,numerator:n.numerator})}toSignificant(t=this.quoteToken.decimals,n,r){return this.adjusted.toSignificant(t,n,r)}toFixed(t=this.quoteToken.decimals,n,r){return this.adjusted.toFixed(t,n,r)}};var Xo=require("@solana/web3.js"),zo=fe(require("bn.js"));var Uo=new Qe.default(0),Ja=new Qe.default(1),$a=new Qe.default(2),ec=new Qe.default(3),tc=new Qe.default(5),Wn=new Qe.default(10),nc=new Qe.default(100),ic=new Qe.default(1e3),rc=new Qe.default(1e4);function Zn(i){return Wn.pow(ye(i))}function Vn(i,e=1,t=[]){let n=[...i];if(e<=0)return t;for(;n.length;)t.push(n.splice(0,e));return t}var or=require("@solana/web3.js"),sr=require("@solana/spl-token");var Be=require("@solana/web3.js");var me={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",FarmV5Deposit:"FarmV5Deposit",FarmV5Withdraw:"FarmV5Withdraw",FarmV5CreateLedger:"FarmV5CreateLedger",FarmV6Deposit:"FarmV6Deposit",FarmV6Withdraw:"FarmV6Withdraw",FarmV6Create:"FarmV6Create",FarmV6Restart:"FarmV6Restart",FarmV6CreatorAddReward:"FarmV6CreatorAddReward",FarmV6CreatorWithdraw:"FarmV6CreatorWithdraw",CpmmCreatePool:"CpmmCreatePool",CpmmCreateConfig:"CpmmCreateConfig",CpmmAddLiquidity:"CpmmAddLiquidity",CpmmWithdrawLiquidity:"CpmmWithdrawLiquidity",CpmmSwapBaseIn:"CpmmSwapBaseIn",CpmmSwapBaseOut:"CpmmSwapBaseOut",CpmmLockLp:"CpmmLockLp",CpmmCollectLockFee:"CpmmCollectLockFee"};var ir=require("@solana/spl-token"),nr=Ae("Raydium_txUtil"),rr=1644;function gn(i){let e=[],t=[];return i.microLamports&&(e.push(Be.ComputeBudgetProgram.setComputeUnitPrice({microLamports:i.microLamports})),t.push(me.SetComputeUnitPrice)),i.units&&(e.push(Be.ComputeBudgetProgram.setComputeUnitLimit({units:i.units})),t.push(me.SetComputeUnitLimit)),{instructions:e,instructionTypes:t}}async function Tt(i,e){var n,r;let t=e!=null?e:"confirmed";return(r=await((n=i.getLatestBlockhash)==null?void 0:n.call(i,{commitment:t})))==null?void 0:r.blockhash}async function bn(i,e){return i.getSignatureStatuses([e]),new Promise((t,n)=>{let r=setTimeout(n,6e4);i.onSignature(e,o=>{if(clearTimeout(r),!o.err){t("");return}n(o.err.toString())},"confirmed")})}function Ho(i,e){i.length<1&&nr.logWithError(`no instructions provided: ${i.toString()}`),e.length<1&&nr.logWithError(`no signers provided:, ${e.toString()}`);let t=new Be.Transaction;t.recentBlockhash="11111111111111111111111111111111",t.feePayer=e[0],t.add(...i);try{return Buffer.from(t.serialize({verifySignatures:!1})).toString("base64").length<rr}catch{return!1}}function Ie(i,e){let[t,n]=Be.PublicKey.findProgramAddressSync(i,e);return{publicKey:t,nonce:n}}fu