@raydium-io/raydium-sdk-v2
Version:
An SDK for building applications on top of Raydium.
2 lines • 64.8 kB
JavaScript
var Xn=Object.defineProperty,zn=Object.defineProperties;var Hn=Object.getOwnPropertyDescriptors;var _t=Object.getOwnPropertySymbols;var Zn=Object.prototype.hasOwnProperty,Yn=Object.prototype.propertyIsEnumerable;var qt=(e,t,n)=>t in e?Xn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Y=(e,t)=>{for(var n in t||(t={}))Zn.call(t,n)&&qt(e,n,t[n]);if(_t)for(var n of _t(t))Yn.call(t,n)&&qt(e,n,t[n]);return e},J=(e,t)=>zn(e,Hn(t));import{PublicKey as ri}from"@solana/web3.js";import zt,{isBN as Ht}from"bn.js";import{bits as fo,BitStructure as bo,blob as jn,Blob as yo,cstr as go,f32 as Po,f32be as wo,f64 as Ao,f64be as ko,greedy as To,Layout as Qn,ns64 as ho,ns64be as Bo,nu64 as xo,nu64be as Io,offset as So,s16 as Co,s16be as Ko,s24 as No,s24be as Lo,s32 as Jn,s32be as Ro,s40 as Mo,s40be as Oo,s48 as Fo,s48be as Eo,s8 as vo,seq as $n,struct as Wo,Structure as ei,u16 as ti,u16be as Vo,u24 as Do,u24be as _o,u32 as qo,u32be as Go,u40 as Uo,u40be as Xo,u48 as zo,u48be as Ho,u8 as ni,UInt as ii,union as Zo,Union as Yo,unionLayoutDiscriminator as jo,utf8 as Qo}from"@solana/buffer-layout";var mt=Qn,Gt=ei;var dt=ii;var Ut=ni,me=ti;var te=Jn;var Xt=$n;var q=jn;var ge=class extends mt{constructor(n,i,r){super(n,r);this.blob=q(n),this.signed=i}decode(n,i=0){let r=new zt(this.blob.decode(n,i),10,"le");return this.signed?r.fromTwos(this.span*8).clone():r}encode(n,i,r=0){return typeof n=="number"&&(n=new zt(n)),this.signed&&(n=n.toTwos(this.span*8)),this.blob.encode(n.toArrayLike(Buffer,"le",this.span),i,r)}};function v(e){return new dt(1,e)}function Pe(e){return new dt(4,e)}function y(e){return new ge(8,!1,e)}function F(e){return new ge(16,!1,e)}function Zt(e){return new ge(8,!0,e)}function Yt(e){return new ge(16,!0,e)}var _e=class extends mt{constructor(n,i,r,o){super(n.span,o);this.layout=n,this.decoder=i,this.encoder=r}decode(n,i){return this.decoder(this.layout.decode(n,i))}encode(n,i,r){return this.layout.encode(this.encoder(n),i,r)}getSpan(n,i){return this.layout.getSpan(n,i)}};function x(e){return new _e(q(32),t=>new ri(t),t=>t.toBuffer(),e)}function de(e){return new _e(Ut(),oi,si,e)}function oi(e){if(e===0)return!1;if(e===1)return!0;throw new Error("Invalid bool: "+e)}function si(e){return e?1:0}var pt=class extends Gt{decode(t,n){return super.decode(t,n)}};function K(e,t,n){return new pt(e,t,n)}function N(e,t,n){let i,r=typeof t=="number"?t:Ht(t)?t.toNumber():new Proxy(t,{get(o,s){if(!i){let a=Reflect.get(o,"count");i=Ht(a)?a.toNumber():a,Reflect.set(o,"count",i)}return Reflect.get(o,s)},set(o,s,a){return s==="count"&&(i=a),Reflect.set(o,s,a)}});return Xt(e,r,n)}var ds=K([q(8),v("bump"),de("disableCreatePool"),me("index"),y("tradeFeeRate"),y("protocolFeeRate"),y("fundFeeRate"),y("createPoolFee"),x("protocolOwner"),x("fundOwner"),N(y(),16)]),ps=K([q(8),x("configId"),x("poolCreator"),x("vaultA"),x("vaultB"),x("mintLp"),x("mintA"),x("mintB"),x("mintProgramA"),x("mintProgramB"),x("observationId"),v("bump"),v("status"),v("lpDecimals"),v("mintDecimalA"),v("mintDecimalB"),y("lpAmount"),y("protocolFeesMintA"),y("protocolFeesMintB"),y("fundFeesMintA"),y("fundFeesMintB"),y("openTime"),N(y(),32)]);import{PublicKey as Ee,TransactionInstruction as pe,Keypair as oo,SystemProgram as so}from"@solana/web3.js";import{ASSOCIATED_TOKEN_PROGRAM_ID as Dn,TOKEN_2022_PROGRAM_ID as Wt,TOKEN_PROGRAM_ID as le}from"@solana/spl-token";import{PublicKey as ks}from"@solana/web3.js";import{get as jt,set as ai}from"lodash";var ft=class{constructor(t){this.logLevel=t.logLevel!==void 0?t.logLevel:0,this.name=t.name}set level(t){this.logLevel=t}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(t){return t<=this.logLevel}error(...t){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...t),this):this}logWithError(...t){let n=t.map(i=>typeof i=="object"?JSON.stringify(i):i).join(", ");throw new Error(n)}warning(...t){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...t),this):this}info(...t){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...t),this):this}debug(...t){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...t),this):this}},Qt={},ui={};function V(e){let t=jt(Qt,e);if(!t){let n=jt(ui,e);t=new ft({name:e,logLevel:n}),ai(Qt,e,t)}return t}import{MINT_SIZE as xs,TOKEN_PROGRAM_ID as Is,getTransferFeeConfig as Ss,unpackMint as Cs}from"@solana/spl-token";var Ks=V("Raydium_accountInfo_util");import ie from"bn.js";var we=9e15,ae=1e9,bt="0123456789abcdef",Ue="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Xe="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",yt={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-we,maxE:we,crypto:!1},nn,ne,T=!0,He="[DecimalError] ",se=He+"Invalid argument: ",rn=He+"Precision limit exceeded",on=He+"crypto unavailable",sn="[object Decimal]",G=Math.floor,W=Math.pow,ci=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,li=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,mi=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,an=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Q=1e7,k=7,di=9007199254740991,pi=Ue.length-1,gt=Xe.length-1,p={toStringTag:sn};p.absoluteValue=p.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),g(e)};p.ceil=function(){return g(new this.constructor(this),this.e+1,2)};p.clampedTo=p.clamp=function(e,t){var n,i=this,r=i.constructor;if(e=new r(e),t=new r(t),!e.s||!t.s)return new r(NaN);if(e.gt(t))throw Error(se+t);return n=i.cmp(e),n<0?e:i.cmp(t)>0?t:new r(i)};p.comparedTo=p.cmp=function(e){var t,n,i,r,o=this,s=o.d,a=(e=new o.constructor(e)).d,c=o.s,u=e.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!==e.e)return o.e>e.e^c<0?1:-1;for(i=s.length,r=a.length,t=0,n=i<r?i:r;t<n;++t)if(s[t]!==a[t])return s[t]>a[t]^c<0?1:-1;return i===r?0:i>r^c<0?1:-1};p.cosine=p.cos=function(){var e,t,n=this,i=n.constructor;return n.d?n.d[0]?(e=i.precision,t=i.rounding,i.precision=e+Math.max(n.e,n.sd())+k,i.rounding=1,n=fi(i,dn(i,n)),i.precision=e,i.rounding=t,g(ne==2||ne==3?n.neg():n,e,t,!0)):new i(1):new i(NaN)};p.cubeRoot=p.cbrt=function(){var e,t,n,i,r,o,s,a,c,u,l=this,m=l.constructor;if(!l.isFinite()||l.isZero())return new m(l);for(T=!1,o=l.s*W(l.s*l,1/3),!o||Math.abs(o)==1/0?(n=D(l.d),e=l.e,(o=(e-n.length+1)%3)&&(n+=o==1||o==-2?"0":"00"),o=W(n,1/3),e=G((e+1)/3)-(e%3==(e<0?-1:2)),o==1/0?n="5e"+e:(n=o.toExponential(),n=n.slice(0,n.indexOf("e")+1)+e),i=new m(n),i.s=l.s):i=new m(o.toString()),s=(e=m.precision)+3;;)if(a=i,c=a.times(a).times(a),u=c.plus(l),i=L(u.plus(l).times(a),u.plus(c),s+2,1),D(a.d).slice(0,s)===(n=D(i.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!r&&n=="4999"){if(!r&&(g(a,e+1,0),a.times(a).times(a).eq(l))){i=a;break}s+=4,r=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(g(i,e+1,1),t=!i.times(i).times(i).eq(l));break}return T=!0,g(i,e,m.rounding,t)};p.decimalPlaces=p.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-G(this.e/k))*k,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n};p.dividedBy=p.div=function(e){return L(this,new this.constructor(e))};p.dividedToIntegerBy=p.divToInt=function(e){var t=this,n=t.constructor;return g(L(t,new n(e),0,1,1),n.precision,n.rounding)};p.equals=p.eq=function(e){return this.cmp(e)===0};p.floor=function(){return g(new this.constructor(this),this.e+1,3)};p.greaterThan=p.gt=function(e){return this.cmp(e)>0};p.greaterThanOrEqualTo=p.gte=function(e){var t=this.cmp(e);return t==1||t===0};p.hyperbolicCosine=p.cosh=function(){var e,t,n,i,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;n=s.precision,i=s.rounding,s.precision=n+Math.max(o.e,o.sd())+4,s.rounding=1,r=o.d.length,r<32?(e=Math.ceil(r/3),t=(1/Ye(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),o=Ae(s,1,o.times(t),new s(1),!0);for(var c,u=e,l=new s(8);u--;)c=o.times(o),o=a.minus(c.times(l.minus(c.times(l))));return g(o,s.precision=n,s.rounding=i,!0)};p.hyperbolicSine=p.sinh=function(){var e,t,n,i,r=this,o=r.constructor;if(!r.isFinite()||r.isZero())return new o(r);if(t=o.precision,n=o.rounding,o.precision=t+Math.max(r.e,r.sd())+4,o.rounding=1,i=r.d.length,i<3)r=Ae(o,2,r,r,!0);else{e=1.4*Math.sqrt(i),e=e>16?16:e|0,r=r.times(1/Ye(5,e)),r=Ae(o,2,r,r,!0);for(var s,a=new o(5),c=new o(16),u=new o(20);e--;)s=r.times(r),r=r.times(a.plus(s.times(c.times(s).plus(u))))}return o.precision=t,o.rounding=n,g(r,t,n,!0)};p.hyperbolicTangent=p.tanh=function(){var e,t,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+7,i.rounding=1,L(n.sinh(),n.cosh(),i.precision=e,i.rounding=t)):new i(n.s)};p.inverseCosine=p.acos=function(){var e,t=this,n=t.constructor,i=t.abs().cmp(1),r=n.precision,o=n.rounding;return i!==-1?i===0?t.isNeg()?j(n,r,o):new n(0):new n(NaN):t.isZero()?j(n,r+4,o).times(.5):(n.precision=r+6,n.rounding=1,t=t.asin(),e=j(n,r+4,o).times(.5),n.precision=r,n.rounding=o,e.minus(t))};p.inverseHyperbolicCosine=p.acosh=function(){var e,t,n=this,i=n.constructor;return n.lte(1)?new i(n.eq(1)?0:NaN):n.isFinite()?(e=i.precision,t=i.rounding,i.precision=e+Math.max(Math.abs(n.e),n.sd())+4,i.rounding=1,T=!1,n=n.times(n).minus(1).sqrt().plus(n),T=!0,i.precision=e,i.rounding=t,n.ln()):new i(n)};p.inverseHyperbolicSine=p.asinh=function(){var e,t,n=this,i=n.constructor;return!n.isFinite()||n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,i.rounding=1,T=!1,n=n.times(n).plus(1).sqrt().plus(n),T=!0,i.precision=e,i.rounding=t,n.ln())};p.inverseHyperbolicTangent=p.atanh=function(){var e,t,n,i,r=this,o=r.constructor;return r.isFinite()?r.e>=0?new o(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(e=o.precision,t=o.rounding,i=r.sd(),Math.max(i,e)<2*-r.e-1?g(new o(r),e,t,!0):(o.precision=n=i-r.e,r=L(r.plus(1),new o(1).minus(r),n+e,1),o.precision=e+4,o.rounding=1,r=r.ln(),o.precision=e,o.rounding=t,r.times(.5))):new o(NaN)};p.inverseSine=p.asin=function(){var e,t,n,i,r=this,o=r.constructor;return r.isZero()?new o(r):(t=r.abs().cmp(1),n=o.precision,i=o.rounding,t!==-1?t===0?(e=j(o,n+4,i).times(.5),e.s=r.s,e):new o(NaN):(o.precision=n+6,o.rounding=1,r=r.div(new o(1).minus(r.times(r)).sqrt().plus(1)).atan(),o.precision=n,o.rounding=i,r.times(2)))};p.inverseTangent=p.atan=function(){var e,t,n,i,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<=gt)return s=j(l,m+4,d).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(m+4<=gt)return s=j(l,m+4,d).times(.5),s.s=u.s,s}for(l.precision=a=m+10,l.rounding=1,n=Math.min(28,a/k+2|0),e=n;e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(T=!1,t=Math.ceil(a/k),i=1,c=u.times(u),s=new l(u),r=u;e!==-1;)if(r=r.times(c),o=s.minus(r.div(i+=2)),r=r.times(c),s=o.plus(r.div(i+=2)),s.d[t]!==void 0)for(e=t;s.d[e]===o.d[e]&&e--;);return n&&(s=s.times(2<<n-1)),T=!0,g(s,l.precision=m,l.rounding=d,!0)};p.isFinite=function(){return!!this.d};p.isInteger=p.isInt=function(){return!!this.d&&G(this.e/k)>this.d.length-2};p.isNaN=function(){return!this.s};p.isNegative=p.isNeg=function(){return this.s<0};p.isPositive=p.isPos=function(){return this.s>0};p.isZero=function(){return!!this.d&&this.d[0]===0};p.lessThan=p.lt=function(e){return this.cmp(e)<0};p.lessThanOrEqualTo=p.lte=function(e){return this.cmp(e)<1};p.logarithm=p.log=function(e){var t,n,i,r,o,s,a,c,u=this,l=u.constructor,m=l.precision,d=l.rounding,f=5;if(e==null)e=new l(10),t=!0;else{if(e=new l(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new l(NaN);t=e.eq(10)}if(n=u.d,u.s<0||!n||!n[0]||u.eq(1))return new l(n&&!n[0]?-1/0:u.s!=1?NaN:n?0:1/0);if(t)if(n.length>1)o=!0;else{for(r=n[0];r%10===0;)r/=10;o=r!==1}if(T=!1,a=m+f,s=oe(u,a),i=t?ze(l,a+10):oe(e,a),c=L(s,i,a,1),Se(c.d,r=m,d))do if(a+=10,s=oe(u,a),i=t?ze(l,a+10):oe(e,a),c=L(s,i,a,1),!o){+D(c.d).slice(r+1,r+15)+1==1e14&&(c=g(c,m+1,0));break}while(Se(c.d,r+=10,d));return T=!0,g(c,m,d)};p.minus=p.sub=function(e){var t,n,i,r,o,s,a,c,u,l,m,d,f=this,P=f.constructor;if(e=new P(e),!f.d||!e.d)return!f.s||!e.s?e=new P(NaN):f.d?e.s=-e.s:e=new P(e.d||f.s!==e.s?f:NaN),e;if(f.s!=e.s)return e.s=-e.s,f.plus(e);if(u=f.d,d=e.d,a=P.precision,c=P.rounding,!u[0]||!d[0]){if(d[0])e.s=-e.s;else if(u[0])e=new P(f);else return new P(c===3?-0:0);return T?g(e,a,c):e}if(n=G(e.e/k),l=G(f.e/k),u=u.slice(),o=l-n,o){for(m=o<0,m?(t=u,o=-o,s=d.length):(t=d,n=l,s=u.length),i=Math.max(Math.ceil(a/k),s)+2,o>i&&(o=i,t.length=1),t.reverse(),i=o;i--;)t.push(0);t.reverse()}else{for(i=u.length,s=d.length,m=i<s,m&&(s=i),i=0;i<s;i++)if(u[i]!=d[i]){m=u[i]<d[i];break}o=0}for(m&&(t=u,u=d,d=t,e.s=-e.s),s=u.length,i=d.length-s;i>0;--i)u[s++]=0;for(i=d.length;i>o;){if(u[--i]<d[i]){for(r=i;r&&u[--r]===0;)u[r]=Q-1;--u[r],u[i]+=Q}u[i]-=d[i]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--n;return u[0]?(e.d=u,e.e=Ze(u,n),T?g(e,a,c):e):new P(c===3?-0:0)};p.modulo=p.mod=function(e){var t,n=this,i=n.constructor;return e=new i(e),!n.d||!e.s||e.d&&!e.d[0]?new i(NaN):!e.d||n.d&&!n.d[0]?g(new i(n),i.precision,i.rounding):(T=!1,i.modulo==9?(t=L(n,e.abs(),0,3,1),t.s*=e.s):t=L(n,e,0,i.modulo,1),t=t.times(e),T=!0,n.minus(t))};p.naturalExponential=p.exp=function(){return Pt(this)};p.naturalLogarithm=p.ln=function(){return oe(this)};p.negated=p.neg=function(){var e=new this.constructor(this);return e.s=-e.s,g(e)};p.plus=p.add=function(e){var t,n,i,r,o,s,a,c,u,l,m=this,d=m.constructor;if(e=new d(e),!m.d||!e.d)return!m.s||!e.s?e=new d(NaN):m.d||(e=new d(e.d||m.s===e.s?m:NaN)),e;if(m.s!=e.s)return e.s=-e.s,m.minus(e);if(u=m.d,l=e.d,a=d.precision,c=d.rounding,!u[0]||!l[0])return l[0]||(e=new d(m)),T?g(e,a,c):e;if(o=G(m.e/k),i=G(e.e/k),u=u.slice(),r=o-i,r){for(r<0?(n=u,r=-r,s=l.length):(n=l,i=o,s=u.length),o=Math.ceil(a/k),s=o>s?o+1:s+1,r>s&&(r=s,n.length=1),n.reverse();r--;)n.push(0);n.reverse()}for(s=u.length,r=l.length,s-r<0&&(r=s,n=l,l=u,u=n),t=0;r;)t=(u[--r]=u[r]+l[r]+t)/Q|0,u[r]%=Q;for(t&&(u.unshift(t),++i),s=u.length;u[--s]==0;)u.pop();return e.d=u,e.e=Ze(u,i),T?g(e,a,c):e};p.precision=p.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(se+e);return n.d?(t=un(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t};p.round=function(){var e=this,t=e.constructor;return g(new t(e),e.e+1,t.rounding)};p.sine=p.sin=function(){var e,t,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+Math.max(n.e,n.sd())+k,i.rounding=1,n=yi(i,dn(i,n)),i.precision=e,i.rounding=t,g(ne>2?n.neg():n,e,t,!0)):new i(NaN)};p.squareRoot=p.sqrt=function(){var e,t,n,i,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(T=!1,u=Math.sqrt(+s),u==0||u==1/0?(t=D(a),(t.length+c)%2==0&&(t+="0"),u=Math.sqrt(t),c=G((c+1)/2)-(c<0||c%2),u==1/0?t="5e"+c:(t=u.toExponential(),t=t.slice(0,t.indexOf("e")+1)+c),i=new l(t)):i=new l(u.toString()),n=(c=l.precision)+3;;)if(o=i,i=o.plus(L(s,o,n+2,1)).times(.5),D(o.d).slice(0,n)===(t=D(i.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!r&&t=="4999"){if(!r&&(g(o,c+1,0),o.times(o).eq(s))){i=o;break}n+=4,r=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(g(i,c+1,1),e=!i.times(i).eq(s));break}return T=!0,g(i,c,l.rounding,e)};p.tangent=p.tan=function(){var e,t,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+10,i.rounding=1,n=n.sin(),n.s=1,n=L(n,new i(1).minus(n.times(n)).sqrt(),e+10,0),i.precision=e,i.rounding=t,g(ne==2||ne==4?n.neg():n,e,t,!0)):new i(NaN)};p.times=p.mul=function(e){var t,n,i,r,o,s,a,c,u,l=this,m=l.constructor,d=l.d,f=(e=new m(e)).d;if(e.s*=l.s,!d||!d[0]||!f||!f[0])return new m(!e.s||d&&!d[0]&&!f||f&&!f[0]&&!d?NaN:!d||!f?e.s/0:e.s*0);for(n=G(l.e/k)+G(e.e/k),c=d.length,u=f.length,c<u&&(o=d,d=f,f=o,s=c,c=u,u=s),o=[],s=c+u,i=s;i--;)o.push(0);for(i=u;--i>=0;){for(t=0,r=c+i;r>i;)a=o[r]+f[i]*d[r-i-1]+t,o[r--]=a%Q|0,t=a/Q|0;o[r]=(o[r]+t)%Q|0}for(;!o[--s];)o.pop();return t?++n:o.shift(),e.d=o,e.e=Ze(o,n),T?g(e,m.precision,m.rounding):e};p.toBinary=function(e,t){return At(this,2,e,t)};p.toDecimalPlaces=p.toDP=function(e,t){var n=this,i=n.constructor;return n=new i(n),e===void 0?n:(U(e,0,ae),t===void 0?t=i.rounding:U(t,0,8),g(n,e+n.e+1,t))};p.toExponential=function(e,t){var n,i=this,r=i.constructor;return e===void 0?n=$(i,!0):(U(e,0,ae),t===void 0?t=r.rounding:U(t,0,8),i=g(new r(i),e+1,t),n=$(i,!0,e+1)),i.isNeg()&&!i.isZero()?"-"+n:n};p.toFixed=function(e,t){var n,i,r=this,o=r.constructor;return e===void 0?n=$(r):(U(e,0,ae),t===void 0?t=o.rounding:U(t,0,8),i=g(new o(r),e+r.e+1,t),n=$(i,!1,e+i.e+1)),r.isNeg()&&!r.isZero()?"-"+n:n};p.toFraction=function(e){var t,n,i,r,o,s,a,c,u,l,m,d,f=this,P=f.d,b=f.constructor;if(!P)return new b(f);if(u=n=new b(1),i=c=new b(0),t=new b(i),o=t.e=un(P)-f.e-1,s=o%k,t.d[0]=W(10,s<0?k+s:s),e==null)e=o>0?t:u;else{if(a=new b(e),!a.isInt()||a.lt(u))throw Error(se+a);e=a.gt(t)?o>0?t:u:a}for(T=!1,a=new b(D(P)),l=b.precision,b.precision=o=P.length*k*2;m=L(a,t,0,1,1),r=n.plus(m.times(i)),r.cmp(e)!=1;)n=i,i=r,r=u,u=c.plus(m.times(r)),c=r,r=t,t=a.minus(m.times(r)),a=r;return r=L(e.minus(n),i,0,1,1),c=c.plus(r.times(u)),n=n.plus(r.times(i)),c.s=u.s=f.s,d=L(u,i,o,1).minus(f).abs().cmp(L(c,n,o,1).minus(f).abs())<1?[u,i]:[c,n],b.precision=l,T=!0,d};p.toHexadecimal=p.toHex=function(e,t){return At(this,16,e,t)};p.toNearest=function(e,t){var n=this,i=n.constructor;if(n=new i(n),e==null){if(!n.d)return n;e=new i(1),t=i.rounding}else{if(e=new i(e),t===void 0?t=i.rounding:U(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&(e.s=n.s),e}return e.d[0]?(T=!1,n=L(n,e,0,t,1).times(e),T=!0,g(n)):(e.s=n.s,n=e),n};p.toNumber=function(){return+this};p.toOctal=function(e,t){return At(this,8,e,t)};p.toPower=p.pow=function(e){var t,n,i,r,o,s,a=this,c=a.constructor,u=+(e=new c(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new c(W(+a,u));if(a=new c(a),a.eq(1))return a;if(i=c.precision,o=c.rounding,e.eq(1))return g(a,i,o);if(t=G(e.e/k),t>=e.d.length-1&&(n=u<0?-u:u)<=di)return r=cn(c,a,n,i),e.s<0?new c(1).div(r):g(r,i,o);if(s=a.s,s<0){if(t<e.d.length-1)return new c(NaN);if((e.d[t]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return n=W(+a,u),t=n==0||!isFinite(n)?G(u*(Math.log("0."+D(a.d))/Math.LN10+a.e+1)):new c(n+"").e,t>c.maxE+1||t<c.minE-1?new c(t>0?s/0:0):(T=!1,c.rounding=a.s=1,n=Math.min(12,(t+"").length),r=Pt(e.times(oe(a,i+n)),i),r.d&&(r=g(r,i+5,1),Se(r.d,i,o)&&(t=i+10,r=g(Pt(e.times(oe(a,t+n)),t),t+5,1),+D(r.d).slice(i+1,i+15)+1==1e14&&(r=g(r,i+1,0)))),r.s=s,T=!0,c.rounding=o,g(r,i,o))};p.toPrecision=function(e,t){var n,i=this,r=i.constructor;return e===void 0?n=$(i,i.e<=r.toExpNeg||i.e>=r.toExpPos):(U(e,1,ae),t===void 0?t=r.rounding:U(t,0,8),i=g(new r(i),e,t),n=$(i,e<=i.e||i.e<=r.toExpNeg,e)),i.isNeg()&&!i.isZero()?"-"+n:n};p.toSignificantDigits=p.toSD=function(e,t){var n=this,i=n.constructor;return e===void 0?(e=i.precision,t=i.rounding):(U(e,1,ae),t===void 0?t=i.rounding:U(t,0,8)),g(new i(n),e,t)};p.toString=function(){var e=this,t=e.constructor,n=$(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n};p.truncated=p.trunc=function(){return g(new this.constructor(this),this.e+1,1)};p.valueOf=p.toJSON=function(){var e=this,t=e.constructor,n=$(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function D(e){var t,n,i,r=e.length-1,o="",s=e[0];if(r>0){for(o+=s,t=1;t<r;t++)i=e[t]+"",n=k-i.length,n&&(o+=re(n)),o+=i;s=e[t],i=s+"",n=k-i.length,n&&(o+=re(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function U(e,t,n){if(e!==~~e||e<t||e>n)throw Error(se+e)}function Se(e,t,n,i){var r,o,s,a;for(o=e[0];o>=10;o/=10)--t;return--t<0?(t+=k,r=0):(r=Math.ceil((t+1)/k),t%=k),o=W(10,k-t),a=e[r]%o|0,i==null?t<3?(t==0?a=a/100|0:t==1&&(a=a/10|0),s=n<4&&a==99999||n>3&&a==49999||a==5e4||a==0):s=(n<4&&a+1==o||n>3&&a+1==o/2)&&(e[r+1]/o/100|0)==W(10,t-2)-1||(a==o/2||a==0)&&(e[r+1]/o/100|0)==0:t<4?(t==0?a=a/1e3|0:t==1?a=a/100|0:t==2&&(a=a/10|0),s=(i||n<4)&&a==9999||!i&&n>3&&a==4999):s=((i||n<4)&&a+1==o||!i&&n>3&&a+1==o/2)&&(e[r+1]/o/1e3|0)==W(10,t-3)-1,s}function Ge(e,t,n){for(var i,r=[0],o,s=0,a=e.length;s<a;){for(o=r.length;o--;)r[o]*=t;for(r[0]+=bt.indexOf(e.charAt(s++)),i=0;i<r.length;i++)r[i]>n-1&&(r[i+1]===void 0&&(r[i+1]=0),r[i+1]+=r[i]/n|0,r[i]%=n)}return r.reverse()}function fi(e,t){var n,i,r;if(t.isZero())return t;i=t.d.length,i<32?(n=Math.ceil(i/3),r=(1/Ye(4,n)).toString()):(n=16,r="2.3283064365386962890625e-10"),e.precision+=n,t=Ae(e,1,t.times(r),new e(1));for(var o=n;o--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return e.precision-=n,t}var L=function(){function e(i,r,o){var s,a=0,c=i.length;for(i=i.slice();c--;)s=i[c]*r+a,i[c]=s%o|0,a=s/o|0;return a&&i.unshift(a),i}function t(i,r,o,s){var a,c;if(o!=s)c=o>s?1:-1;else for(a=c=0;a<o;a++)if(i[a]!=r[a]){c=i[a]>r[a]?1:-1;break}return c}function n(i,r,o,s){for(var a=0;o--;)i[o]-=a,a=i[o]<r[o]?1:0,i[o]=a*s+i[o]-r[o];for(;!i[0]&&i.length>1;)i.shift()}return function(i,r,o,s,a,c){var u,l,m,d,f,P,b,I,h,C,S,M,be,H,ye,We,Ie,ct,Z,Ve,De=i.constructor,lt=i.s==r.s?1:-1,_=i.d,R=r.d;if(!_||!_[0]||!R||!R[0])return new De(!i.s||!r.s||(_?R&&_[0]==R[0]:!R)?NaN:_&&_[0]==0||!R?lt*0:lt/0);for(c?(f=1,l=i.e-r.e):(c=Q,f=k,l=G(i.e/f)-G(r.e/f)),Z=R.length,Ie=_.length,h=new De(lt),C=h.d=[],m=0;R[m]==(_[m]||0);m++);if(R[m]>(_[m]||0)&&l--,o==null?(H=o=De.precision,s=De.rounding):a?H=o+(i.e-r.e)+1:H=o,H<0)C.push(1),P=!0;else{if(H=H/f+2|0,m=0,Z==1){for(d=0,R=R[0],H++;(m<Ie||d)&&H--;m++)ye=d*c+(_[m]||0),C[m]=ye/R|0,d=ye%R|0;P=d||m<Ie}else{for(d=c/(R[0]+1)|0,d>1&&(R=e(R,d,c),_=e(_,d,c),Z=R.length,Ie=_.length),We=Z,S=_.slice(0,Z),M=S.length;M<Z;)S[M++]=0;Ve=R.slice(),Ve.unshift(0),ct=R[0],R[1]>=c/2&&++ct;do d=0,u=t(R,S,Z,M),u<0?(be=S[0],Z!=M&&(be=be*c+(S[1]||0)),d=be/ct|0,d>1?(d>=c&&(d=c-1),b=e(R,d,c),I=b.length,M=S.length,u=t(b,S,I,M),u==1&&(d--,n(b,Z<I?Ve:R,I,c))):(d==0&&(u=d=1),b=R.slice()),I=b.length,I<M&&b.unshift(0),n(S,b,M,c),u==-1&&(M=S.length,u=t(R,S,Z,M),u<1&&(d++,n(S,Z<M?Ve:R,M,c))),M=S.length):u===0&&(d++,S=[0]),C[m++]=d,u&&S[0]?S[M++]=_[We]||0:(S=[_[We]],M=1);while((We++<Ie||S[0]!==void 0)&&H--);P=S[0]!==void 0}C[0]||C.shift()}if(f==1)h.e=l,nn=P;else{for(m=1,d=C[0];d>=10;d/=10)m++;h.e=m+l*f-1,g(h,a?o+h.e+1:o,s,P)}return h}}();function g(e,t,n,i){var r,o,s,a,c,u,l,m,d,f=e.constructor;e:if(t!=null){if(m=e.d,!m)return e;for(r=1,a=m[0];a>=10;a/=10)r++;if(o=t-r,o<0)o+=k,s=t,l=m[d=0],c=l/W(10,r-s-1)%10|0;else if(d=Math.ceil((o+1)/k),a=m.length,d>=a)if(i){for(;a++<=d;)m.push(0);l=c=0,r=1,o%=k,s=o-k+1}else break e;else{for(l=a=m[d],r=1;a>=10;a/=10)r++;o%=k,s=o-k+r,c=s<0?0:l/W(10,r-s-1)%10|0}if(i=i||t<0||m[d+1]!==void 0||(s<0?l:l%W(10,r-s-1)),u=n<4?(c||i)&&(n==0||n==(e.s<0?3:2)):c>5||c==5&&(n==4||i||n==6&&(o>0?s>0?l/W(10,r-s):0:m[d-1])%10&1||n==(e.s<0?8:7)),t<1||!m[0])return m.length=0,u?(t-=e.e+1,m[0]=W(10,(k-t%k)%k),e.e=-t||0):m[0]=e.e=0,e;if(o==0?(m.length=d,a=1,d--):(m.length=d+1,a=W(10,k-o),m[d]=s>0?(l/W(10,r-s)%W(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&&(e.e++,m[0]==Q&&(m[0]=1));break}else{if(m[d]+=a,m[d]!=Q)break;m[d--]=0,a=1}for(o=m.length;m[--o]===0;)m.pop()}return T&&(e.e>f.maxE?(e.d=null,e.e=NaN):e.e<f.minE&&(e.e=0,e.d=[0])),e}function $(e,t,n){if(!e.isFinite())return mn(e);var i,r=e.e,o=D(e.d),s=o.length;return t?(n&&(i=n-s)>0?o=o.charAt(0)+"."+o.slice(1)+re(i):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(e.e<0?"e":"e+")+e.e):r<0?(o="0."+re(-r-1)+o,n&&(i=n-s)>0&&(o+=re(i))):r>=s?(o+=re(r+1-s),n&&(i=n-r-1)>0&&(o=o+"."+re(i))):((i=r+1)<s&&(o=o.slice(0,i)+"."+o.slice(i)),n&&(i=n-s)>0&&(r+1===s&&(o+="."),o+=re(i))),o}function Ze(e,t){var n=e[0];for(t*=k;n>=10;n/=10)t++;return t}function ze(e,t,n){if(t>pi)throw T=!0,n&&(e.precision=n),Error(rn);return g(new e(Ue),t,1,!0)}function j(e,t,n){if(t>gt)throw Error(rn);return g(new e(Xe),t,n,!0)}function un(e){var t=e.length-1,n=t*k+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function re(e){for(var t="";e--;)t+="0";return t}function cn(e,t,n,i){var r,o=new e(1),s=Math.ceil(i/k+4);for(T=!1;;){if(n%2&&(o=o.times(t),en(o.d,s)&&(r=!0)),n=G(n/2),n===0){n=o.d.length-1,r&&o.d[n]===0&&++o.d[n];break}t=t.times(t),en(t.d,s)}return T=!0,o}function $t(e){return e.d[e.d.length-1]&1}function ln(e,t,n){for(var i,r=new e(t[0]),o=0;++o<t.length;)if(i=new e(t[o]),i.s)r[n](i)&&(r=i);else{r=i;break}return r}function Pt(e,t){var n,i,r,o,s,a,c,u=0,l=0,m=0,d=e.constructor,f=d.rounding,P=d.precision;if(!e.d||!e.d[0]||e.e>17)return new d(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:0/0);for(t==null?(T=!1,c=P):c=t,a=new d(.03125);e.e>-2;)e=e.times(a),m+=5;for(i=Math.log(W(2,m))/Math.LN10*2+5|0,c+=i,n=o=s=new d(1),d.precision=c;;){if(o=g(o.times(e),c,1),n=n.times(++l),a=s.plus(L(o,n,c,1)),D(a.d).slice(0,c)===D(s.d).slice(0,c)){for(r=m;r--;)s=g(s.times(s),c,1);if(t==null)if(u<3&&Se(s.d,c-i,f,u))d.precision=c+=10,n=o=a=new d(1),l=0,u++;else return g(s,d.precision=P,f,T=!0);else return d.precision=P,s}s=a}}function oe(e,t){var n,i,r,o,s,a,c,u,l,m,d,f=1,P=10,b=e,I=b.d,h=b.constructor,C=h.rounding,S=h.precision;if(b.s<0||!I||!I[0]||!b.e&&I[0]==1&&I.length==1)return new h(I&&!I[0]?-1/0:b.s!=1?NaN:I?0:b);if(t==null?(T=!1,l=S):l=t,h.precision=l+=P,n=D(I),i=n.charAt(0),Math.abs(o=b.e)<15e14){for(;i<7&&i!=1||i==1&&n.charAt(1)>3;)b=b.times(e),n=D(b.d),i=n.charAt(0),f++;o=b.e,i>1?(b=new h("0."+n),o++):b=new h(i+"."+n.slice(1))}else return u=ze(h,l+2,S).times(o+""),b=oe(new h(i+"."+n.slice(1)),l-P).plus(u),h.precision=S,t==null?g(b,S,C,T=!0):b;for(m=b,c=s=b=L(b.minus(1),b.plus(1),l,1),d=g(b.times(b),l,1),r=3;;){if(s=g(s.times(d),l,1),u=c.plus(L(s,new h(r),l,1)),D(u.d).slice(0,l)===D(c.d).slice(0,l))if(c=c.times(2),o!==0&&(c=c.plus(ze(h,l+2,S).times(o+""))),c=L(c,new h(f),l,1),t==null)if(Se(c.d,l-P,C,a))h.precision=l+=P,u=s=b=L(m.minus(1),m.plus(1),l,1),d=g(b.times(b),l,1),r=a=1;else return g(c,h.precision=S,C,T=!0);else return h.precision=S,c;c=u,r+=2}}function mn(e){return String(e.s*e.s/0)}function wt(e,t){var n,i,r;for((n=t.indexOf("."))>-1&&(t=t.replace(".","")),(i=t.search(/e/i))>0?(n<0&&(n=i),n+=+t.slice(i+1),t=t.substring(0,i)):n<0&&(n=t.length),i=0;t.charCodeAt(i)===48;i++);for(r=t.length;t.charCodeAt(r-1)===48;--r);if(t=t.slice(i,r),t){if(r-=i,e.e=n=n-i-1,e.d=[],i=(n+1)%k,n<0&&(i+=k),i<r){for(i&&e.d.push(+t.slice(0,i)),r-=k;i<r;)e.d.push(+t.slice(i,i+=k));t=t.slice(i),i=k-t.length}else i-=r;for(;i--;)t+="0";e.d.push(+t),T&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function bi(e,t){var n,i,r,o,s,a,c,u,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),an.test(t))return wt(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(li.test(t))n=16,t=t.toLowerCase();else if(ci.test(t))n=2;else if(mi.test(t))n=8;else throw Error(se+t);for(o=t.search(/p/i),o>0?(c=+t.slice(o+1),t=t.substring(2,o)):t=t.slice(2),o=t.indexOf("."),s=o>=0,i=e.constructor,s&&(t=t.replace(".",""),a=t.length,o=a-o,r=cn(i,new i(n),o,o*2)),u=Ge(t,n,Q),l=u.length-1,o=l;u[o]===0;--o)u.pop();return o<0?new i(e.s*0):(e.e=Ze(u,l),e.d=u,T=!1,s&&(e=L(e,r,a*4)),c&&(e=e.times(Math.abs(c)<54?W(2,c):je.pow(2,c))),T=!0,e)}function yi(e,t){var n,i=t.d.length;if(i<3)return t.isZero()?t:Ae(e,2,t,t);n=1.4*Math.sqrt(i),n=n>16?16:n|0,t=t.times(1/Ye(5,n)),t=Ae(e,2,t,t);for(var r,o=new e(5),s=new e(16),a=new e(20);n--;)r=t.times(t),t=t.times(o.plus(r.times(s.times(r).minus(a))));return t}function Ae(e,t,n,i,r){var o,s,a,c,u=1,l=e.precision,m=Math.ceil(l/k);for(T=!1,c=n.times(n),a=new e(i);;){if(s=L(a.times(c),new e(t++*t++),l,1),a=r?i.plus(s):i.minus(s),i=L(s.times(c),new e(t++*t++),l,1),s=a.plus(i),s.d[m]!==void 0){for(o=m;s.d[o]===a.d[o]&&o--;);if(o==-1)break}o=a,a=i,i=s,s=o,u++}return T=!0,s.d.length=m+1,s}function Ye(e,t){for(var n=e;--t;)n*=e;return n}function dn(e,t){var n,i=t.s<0,r=j(e,e.precision,1),o=r.times(.5);if(t=t.abs(),t.lte(o))return ne=i?4:1,t;if(n=t.divToInt(r),n.isZero())ne=i?3:2;else{if(t=t.minus(n.times(r)),t.lte(o))return ne=$t(n)?i?2:3:i?4:1,t;ne=$t(n)?i?1:4:i?3:2}return t.minus(r).abs()}function At(e,t,n,i){var r,o,s,a,c,u,l,m,d,f=e.constructor,P=n!==void 0;if(P?(U(n,1,ae),i===void 0?i=f.rounding:U(i,0,8)):(n=f.precision,i=f.rounding),!e.isFinite())l=mn(e);else{for(l=$(e),s=l.indexOf("."),P?(r=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):r=t,s>=0&&(l=l.replace(".",""),d=new f(1),d.e=l.length-s,d.d=Ge($(d),10,r),d.e=d.d.length),m=Ge(l,10,r),o=c=m.length;m[--c]==0;)m.pop();if(!m[0])l=P?"0p+0":"0";else{if(s<0?o--:(e=new f(e),e.d=m,e.e=o,e=L(e,d,n,i,0,r),m=e.d,o=e.e,u=nn),s=m[n],a=r/2,u=u||m[n+1]!==void 0,u=i<4?(s!==void 0||u)&&(i===0||i===(e.s<0?3:2)):s>a||s===a&&(i===4||u||i===6&&m[n-1]&1||i===(e.s<0?8:7)),m.length=n,u)for(;++m[--n]>r-1;)m[n]=0,n||(++o,m.unshift(1));for(c=m.length;!m[c-1];--c);for(s=0,l="";s<c;s++)l+=bt.charAt(m[s]);if(P){if(c>1)if(t==16||t==8){for(s=t==16?4:3,--c;c%s;c++)l+="0";for(m=Ge(l,r,t),c=m.length;!m[c-1];--c);for(s=1,l="1.";s<c;s++)l+=bt.charAt(m[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)l="0"+l;l="0."+l}else if(++o>c)for(o-=c;o--;)l+="0";else o<c&&(l=l.slice(0,o)+"."+l.slice(o))}l=(t==16?"0x":t==2?"0b":t==8?"0o":"")+l}return e.s<0?"-"+l:l}function en(e,t){if(e.length>t)return e.length=t,!0}function gi(e){return new this(e).abs()}function Pi(e){return new this(e).acos()}function wi(e){return new this(e).acosh()}function Ai(e,t){return new this(e).plus(t)}function ki(e){return new this(e).asin()}function Ti(e){return new this(e).asinh()}function hi(e){return new this(e).atan()}function Bi(e){return new this(e).atanh()}function xi(e,t){e=new this(e),t=new this(t);var n,i=this.precision,r=this.rounding,o=i+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=j(this,o,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?j(this,i,r):new this(0),n.s=e.s):!e.d||t.isZero()?(n=j(this,o,1).times(.5),n.s=e.s):t.s<0?(this.precision=o,this.rounding=1,n=this.atan(L(e,t,o,1)),t=j(this,o,1),this.precision=i,this.rounding=r,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(L(e,t,o,1)),n}function Ii(e){return new this(e).cbrt()}function Si(e){return g(e=new this(e),e.e+1,2)}function Ci(e,t,n){return new this(e).clamp(t,n)}function Ki(e){if(!e||typeof e!="object")throw Error(He+"Object expected");var t,n,i,r=e.defaults===!0,o=["precision",1,ae,"rounding",0,8,"toExpNeg",-we,0,"toExpPos",0,we,"maxE",0,we,"minE",-we,0,"modulo",0,9];for(t=0;t<o.length;t+=3)if(n=o[t],r&&(this[n]=yt[n]),(i=e[n])!==void 0)if(G(i)===i&&i>=o[t+1]&&i<=o[t+2])this[n]=i;else throw Error(se+n+": "+i);if(n="crypto",r&&(this[n]=yt[n]),(i=e[n])!==void 0)if(i===!0||i===!1||i===0||i===1)if(i)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(on);else this[n]=!1;else throw Error(se+n+": "+i);return this}function Ni(e){return new this(e).cos()}function Li(e){return new this(e).cosh()}function pn(e){var t,n,i;function r(o){var s,a,c,u=this;if(!(u instanceof r))return new r(o);if(u.constructor=r,tn(o)){u.s=o.s,T?!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++;T?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 wt(u,o.toString())}else if(c!=="string")throw Error(se+o);return(a=o.charCodeAt(0))===45?(o=o.slice(1),u.s=-1):(a===43&&(o=o.slice(1)),u.s=1),an.test(o)?wt(u,o):bi(u,o)}if(r.prototype=p,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=Ki,r.clone=pn,r.isDecimal=tn,r.abs=gi,r.acos=Pi,r.acosh=wi,r.add=Ai,r.asin=ki,r.asinh=Ti,r.atan=hi,r.atanh=Bi,r.atan2=xi,r.cbrt=Ii,r.ceil=Si,r.clamp=Ci,r.cos=Ni,r.cosh=Li,r.div=Ri,r.exp=Mi,r.floor=Oi,r.hypot=Fi,r.ln=Ei,r.log=vi,r.log10=Vi,r.log2=Wi,r.max=Di,r.min=_i,r.mod=qi,r.mul=Gi,r.pow=Ui,r.random=Xi,r.round=zi,r.sign=Hi,r.sin=Zi,r.sinh=Yi,r.sqrt=ji,r.sub=Qi,r.sum=Ji,r.tan=$i,r.tanh=er,r.trunc=tr,e===void 0&&(e={}),e&&e.defaults!==!0)for(i=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<i.length;)e.hasOwnProperty(n=i[t++])||(e[n]=this[n]);return r.config(e),r}function Ri(e,t){return new this(e).div(t)}function Mi(e){return new this(e).exp()}function Oi(e){return g(e=new this(e),e.e+1,3)}function Fi(){var e,t,n=new this(0);for(T=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return T=!0,new this(1/0);n=t}return T=!0,n.sqrt()}function tn(e){return e instanceof je||e&&e.toStringTag===sn||!1}function Ei(e){return new this(e).ln()}function vi(e,t){return new this(e).log(t)}function Wi(e){return new this(e).log(2)}function Vi(e){return new this(e).log(10)}function Di(){return ln(this,arguments,"lt")}function _i(){return ln(this,arguments,"gt")}function qi(e,t){return new this(e).mod(t)}function Gi(e,t){return new this(e).mul(t)}function Ui(e,t){return new this(e).pow(t)}function Xi(e){var t,n,i,r,o=0,s=new this(1),a=[];if(e===void 0?e=this.precision:U(e,1,ae),i=Math.ceil(e/k),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(i));o<i;)r=t[o],r>=429e7?t[o]=crypto.getRandomValues(new Uint32Array(1))[0]:a[o++]=r%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(i*=4);o<i;)r=t[o]+(t[o+1]<<8)+(t[o+2]<<16)+((t[o+3]&127)<<24),r>=214e7?crypto.randomBytes(4).copy(t,o):(a.push(r%1e7),o+=4);o=i/4}else throw Error(on);else for(;o<i;)a[o++]=Math.random()*1e7|0;for(i=a[--o],e%=k,i&&e&&(r=W(10,k-e),a[o]=(i/r|0)*r);a[o]===0;o--)a.pop();if(o<0)n=0,a=[0];else{for(n=-1;a[0]===0;n-=k)a.shift();for(i=1,r=a[0];r>=10;r/=10)i++;i<k&&(n-=k-i)}return s.e=n,s.d=a,s}function zi(e){return g(e=new this(e),e.e+1,this.rounding)}function Hi(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Zi(e){return new this(e).sin()}function Yi(e){return new this(e).sinh()}function ji(e){return new this(e).sqrt()}function Qi(e,t){return new this(e).sub(t)}function Ji(){var e=0,t=arguments,n=new this(t[e]);for(T=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return T=!0,g(n,this.precision,this.rounding)}function $i(e){return new this(e).tan()}function er(e){return new this(e).tanh()}function tr(e){return g(e=new this(e),e.e+1,1)}p[Symbol.for("nodejs.util.inspect.custom")]=p.toString;p[Symbol.toStringTag]="Decimal";var je=p.constructor=pn(yt);Ue=new je(Ue);Xe=new je(Xe);import cr from"big.js";import Zs from"bn.js";import nr from"toformat";var ir=nr,Ce=ir;import Je from"big.js";import or from"bn.js";import sr from"decimal.js-light";import Ke from"bn.js";var fn=9007199254740991;function ee(e){let t=V("Raydium_parseBigNumberish");if(e instanceof Ke)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new Ke(e);t.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&t.logWithError(`BigNumberish number underflow: ${e}`),(e>=fn||e<=-fn)&&t.logWithError(`BigNumberish number overflow: ${e}`),new Ke(String(e))):typeof e=="bigint"?new Ke(e.toString()):(t.error(`invalid BigNumberish value: ${e}`),new Ke(0))}var Qe=V("module/fraction"),kt=Ce(Je),Ne=Ce(sr),ar={[0]:Ne.ROUND_DOWN,[1]:Ne.ROUND_HALF_UP,[2]:Ne.ROUND_UP},ur={[0]:Je.roundDown,[1]:Je.roundHalfUp,[2]:Je.roundUp},O=class{constructor(t,n=new or(1)){this.numerator=ee(t),this.denominator=ee(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new O(this.denominator,this.numerator)}add(t){let n=t instanceof O?t:new O(ee(t));return this.denominator.eq(n.denominator)?new O(this.numerator.add(n.numerator),this.denominator):new O(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(t){let n=t instanceof O?t:new O(ee(t));return this.denominator.eq(n.denominator)?new O(this.numerator.sub(n.numerator),this.denominator):new O(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(t){let n=t instanceof O?t:new O(ee(t));return new O(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(t){let n=t instanceof O?t:new O(ee(t));return new O(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(t,n={groupSeparator:""},i=1){Number.isInteger(t)||Qe.logWithError(`${t} is not an integer.`),t<=0&&Qe.logWithError(`${t} is not positive.`),Ne.set({precision:t+1,rounding:ar[i]});let r=new Ne(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return r.toFormat(r.decimalPlaces(),n)}toFixed(t,n={groupSeparator:""},i=1){return Number.isInteger(t)||Qe.logWithError(`${t} is not an integer.`),t<0&&Qe.logWithError(`${t} is negative.`),kt.DP=t,kt.RM=ur[i]||1,new kt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,n)}isZero(){return this.numerator.isZero()}};var ia=V("Raydium_amount"),ra=Ce(cr);import{PublicKey as mr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as bn}from"@solana/spl-token";var Tt={chainId:101,address:mr.default.toBase58(),programId:bn.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},ue={chainId:101,address:"So11111111111111111111111111111111111111112",programId:bn.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 Bt}from"@solana/web3.js";import{PublicKey as E,SystemProgram as yn,SYSVAR_RENT_PUBKEY as dr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as pr}from"@solana/spl-token";function ht({pubkey:e,isSigner:t=!1,isWritable:n=!0}){return{pubkey:e,isWritable:n,isSigner:t}}var da=[ht({pubkey:pr,isWritable:!1}),ht({pubkey:yn.programId,isWritable:!1}),ht({pubkey:dr,isWritable:!1})];function gn({publicKey:e,transformSol:t}){let n=Pn(e.toString());if(n instanceof E)return t&&n.equals(Le)?qe:n;if(t&&n.toString()===Le.toBase58())return qe;if(typeof n=="string"){if(n===E.default.toBase58())return E.default;try{return new E(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function Pn(e){try{return new E(e)}catch{return e}}var fr=new E("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),$e=new E("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),et=new E("SysvarRent111111111111111111111111111111111"),pa=new E("SysvarC1ock11111111111111111111111111111111"),ke=new E("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),fa=new E("Sysvar1nstructions1111111111111111111111111"),wn=yn.programId,ba=new E("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),ya=new E("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),ga=new E("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Pa=new E("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),wa=new E("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Aa=new E("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),ka=new E("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Ta=new E("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),ha=new E("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Ba=new E("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),xa=new E("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),qe=new E("So11111111111111111111111111111111111111112"),Le=E.default;var xt=class{constructor({mint:t,decimals:n,symbol:i,name:r,skipMint:o=!1,isToken2022:s=!1}){if(t===Le.toBase58()||t instanceof Bt&&Le.equals(t)){this.decimals=ue.decimals,this.symbol=ue.symbol,this.name=ue.name,this.mint=new Bt(ue.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=i||t.toString().substring(0,6),this.name=r||t.toString().substring(0,6),this.mint=o?Bt.default:gn({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},ce=xt;ce.WSOL=new xt(J(Y({},ue),{mint:ue.address}));var It=class{constructor({decimals:t,symbol:n="UNKNOWN",name:i="UNKNOWN"}){this.decimals=t,this.symbol=n,this.name=i}equals(t){return this===t}},tt=It;tt.SOL=new It(Tt);import br from"bn.js";var va=new O(new br(100));var Ga=V("Raydium_price");import{PublicKey as su}from"@solana/web3.js";import uu from"bn.js";var yr=new ie(0),Iu=new ie(1),Su=new ie(2),Cu=new ie(3),Ku=new ie(5),lr=new ie(10),Nu=new ie(100),Lu=new ie(1e3),Ru=new ie(1e4);import{PublicKey as Pr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as wr}from"@solana/spl-token";import{ComputeBudgetProgram as Du,Keypair as Gu,PublicKey as gr,Transaction as Xu,TransactionMessage as Hu,VersionedTransaction as Zu}from"@solana/web3.js";var Te={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 Ju}from"@solana/spl-token";var $u=V("Raydium_txUtil");function X(e,t){let[n,i]=gr.findProgramAddressSync(e,t);return{publicKey:n,nonce:i}}function he(e,t,n){return X([e.toBuffer(),(n!=null?n:wr).toBuffer(),t.toBuffer()],new Pr("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}import{PublicKey as B}from"@solana/web3.js";var sc=new B("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),ac=new B("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),uc=new B("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),cc=new B("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),lc=new B("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),mc=new B("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),dc=new B("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),pc=new B("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),fc=new B("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),bc=new B("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),Ar=new B("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),kr=new B("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),Tr=new B("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),yc=new B("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),gc=new B("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Pc=new B("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),wc=new B("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),Ac=new B("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),kc=new B("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),An=new B("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),kn=new B("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Tc=new B("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),hr=new B("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),Br=new B("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),xr=new B("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),hc=new B("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),Ir=new B("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),Bc=new B("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),Sr=new B("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix");var xc={SERUM_MARKET:B.default,OPENBOOK_MARKET:new B("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:B.default,FarmV3:new B("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new B("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new B("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new B("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new B("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new B("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),CLMM_LOCK_PROGRAM_ID:new B("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),CLMM_LOCK_AUTH_ID:new B("8qmHNvu2Kr2C7U8mJL4Vz1vTDxMhVuXKREwU7TNoaVEo"),Router:new B("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:hr,CREATE_CPMM_POOL_AUTH:Br,CREATE_CPMM_POOL_FEE_ACC:xr,FEE_DESTINATION_ID:new B("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),LOCK_CPMM_PROGRAM:Ir,LCOK_CPMM_AUTH:Sr};import Tn from"bn.js";function Kt(e,t){let{div:n,mod:i}=e.divmod(t);return i.gt(new Tn(0))?n.add(new Tn(1)):n}import{PublicKey as Cr,AddressLookupTableAccount as hn}from"@solana/web3.js";var Kr={"2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17":new hn({key:new Cr("2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17"),state:hn.deserialize(Buffer.from("AQAAAP//////////d49+DAAAAAAAAQZMWvw7GUNJdaccNBVnb57OKakxL2BHLYvhRwVILRsgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMGRm/lIRcy/+ytunLDm+e8jOW7xfcSayxDmzpAAAAABt324ddloZPZy+FGzut5rBy0he1fWzeROoz1hX7/AKkG3fbh7nWP3hhCXbzkbM3athr8TYO5DSf+vfko2KGL/AVKU1D4XciC1hSlVnJ4iilt3x6rq9CmBniISTL07vagBqfVFxksXFEhjMlMPUrxf1ja7gibof1E49vZigAAAAAGp9UXGMd0yShWY5hpHV62i164o5tLbVxzVVshAAAAAIyXJY9OJInxuz0QKRSODYMLWhOZ2v8QhASOe9jb6fhZC3BlsePRfEU4nVJ/awTDzVi4bHMaoP21SbbRvAP4KUbIScv+6Yw2LHF/6K0ZjUPibbSWXCirYPGuuVl7zT789IUPLW4CpHr4JNCatp3ELXDLKMv6JJ+37le50lbBJ2LvDQdRqCgtphMF/imcN7mY5YRx2xE1A3MQ+L4QRaYK9u4GRfZP3LsAd00a+IkCpA22UNQMKdq5BFbJuwuOLqc8zxCTDlqxBG8J0HcxtfogQHDK06ukzfaXiNDKAob1MqBHS9lJxDYCwz8gd5DtFqNSTKG5l1zxIaKpDP/sffi2is1H9aKveyXSu5StXElYRl9SD5As0DHE4N0GLnf84/siiKXVyp4Ez121kLcUui/jLLFZEz/BwZK3Ilf9B9OcsEAeDMKAy2vjGSxQODgBz0QwGA+eP4ZjIjrIAQaXENv31QfLlOdXSRCkaybRniDHF4C8YcwhcvsqrOVuTP4B2Na+9wLdtrB31uz2rtlFI5kahdsnp/d1SrASDInYCtTYtdoke4kX+hoKWcEWM4Tle8pTUkUVv4BxS6fje/EzKBE4Qu9N9LMnrw/JNO0hqMVB4rk/2ou4AB1loQ7FZoPwut2o4KZB+0p9xnbrQKw038qjpHar+PyDwvxBRcu5hpHw3dguezeWv+IwvgW5icu8EGkhGa9AkFPPJT7VMSFb8xowveU=","base64"))})};import{PublicKey as Gc,sendAndConfirmTransaction as Uc,SystemProgram as Hc,Transaction as Zc,TransactionMessage as jc,VersionedTransaction as Qc}from"@solana/web3.js";import $c from"axios";var Rr=Buffer.from("vault_and_lp_mint_auth_seed","utf8"),Mr=Buffer.from("amm_config","utf8"),Or=Buffer.from("pool","utf8"),Fr=Buffer.from("pool_lp_mint","utf8"),Er=Buffer.from("pool_vault","utf8"),vr=Buffer.from("observation","utf8");function Wr(e){return X([Rr],e)}function Bl(e,t){return X([Mr,_r(t)],e)}function Nt(e,t,n,i){return X([Or,t.toBuffer(),n.toBuffer(),i.toBuffer()],e)}function Vr(e,t){return X([Fr,t.toBuffer()],e)}function xn(e,t,n){return X([Er,t.toBuffer(),n.toBuffer()],e)}function Dr(e,t){return X([vr,t.toBuffer()],e)}function _r(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,e,!1),new Uint8Array(t)}function xl({poolId:e,programId:t,configId:n,mintA:i,mintB:r}){let o=Wr(t).publicKey,s=e||Nt(t,n,i,r).publicKey,a=Vr(t,s).publicKey,c=xn(t,s,i).publicKey,u=xn(t,s,r).publicKey,l=Dr(t,s).publicKey;return{poolId:s,configId:n,authority:o,lpMint:a,vaultA:c,vaultB:u,observationId:l}}var qr=Buffer.from("locked_liquidity","utf8");function In(e,t){return X([qr,t.toBuffer()],e)}import{PublicKey as Bp}from"@solana/web3.js";import Ip from"bn.js";import{AccountLayout as Np,TOKEN_2022_PROGRAM_ID as Lp,TOKEN_PROGRAM_ID as Rp}from"@solana/spl-token";import{PublicKey as Kl}from"@solana/web3.js";import{MintLayout as Ll,TOKEN_PROGRAM_ID as Ml}from"@solana/spl-token";import{Keypair as Yd,PublicKey as jd,SystemProgram as Jd,TransactionInstruction as $d}from"@solana/web3.js";import tp from"bn.js";import{ASSOCIATED_TOKEN_PROGRAM_ID as rp,TOKEN_2022_PROGRAM_ID as op,TOKEN_PROGRAM_ID as sp}from"@solana/spl-token";import Cd from"bn.js";import z from"bn.js";var Lt=new z(0),Sn=new z(1),Cn=new z(-1),it=new z(1).shln(64),Kn=new z(1).shln(128),Gr=it.sub(Sn);var Ur=Kn.subn(1),Be=-443636,Me=-Be,Rt=new z("4295048016"),Mt=new z("79226673521066979257578248091"),Xl=new z("4295048017"),zl=new z("79226673521066979257578248090");var Xr=new z(10).pow(new z(6));var Hl=new z("18446744073700000000");import fd from"bn.js";var em=Buffer.from("amm_config","utf8"),tm=Buffer.from("pool","utf8"),nm=Buffer.from("pool_vault","utf8"),im=Buffer.from("pool_reward_vault","utf8"),rm=Buffer.from("position","utf8"),om=Buffer.from("tick_array","utf8"),sm=Buffer.from("operation","utf8"),am=Buffer.from("pool_tick_array_bitmap_extension","utf8"),um=Buffer.from("observation","utf8");function Ot(e){return X([Buffer.from("metadata","utf8"),ke.toBuffer(),e.toBuffer()],ke)}var cm=Buffer.from("locked_position","utf8");import{PublicKey as qm}from"@solana/web3.js";import{TOKEN_2022_PROGRAM_ID as Um}from"@solana/spl-token";import zm from"bn.js";import dm from"bn.js";var vt=14;var rt=60;var jr=K([q(8),v("bump"),me("index"),x(""),Pe("protocolFeeRate"),Pe("tradeFeeRate"),me("tickSpacing"),N(y(),8,"")]),Qr=K([Pe("blockTimestamp"),Zt("tickCumulative"),N(y(),4)]),Vn=K([q(8),de("initialized"),y("recentEpoch"),me("observationIndex"),x("poolId"),N(Qr,100,"observations"),N(y(),4)]),Jr=K([v("rewardState"),y("openTime"),y("endTime"),y("lastUpdateTime"),F("emissionsPerSecondX64"),y("rewardTotalEmissioned"),y("rewardClaimed"),x("tokenMint"),x("tokenVault"),x("creator"),F("rewardGrowthGlobalX64")]),En=K([q(8),v("bump"),x("ammConfig"),x("creator"),x("mintA"),x("mintB"),x("vaultA"),x("vaultB"),x("observationId"),v("mintDecimalsA"),v("mintDecimalsB"),me("tickSpacing"),F("liquidity"),F("sqrtPriceX64"),te("tickCurrent"),Pe(),F("feeGrowthGlobalX64A"),F("feeGrowthGlobalX64B"),y("protocolFeesTokenA"),y("protocolFeesTokenB"),F("swapInAmountTokenA"),F("swapOutAmountTokenB"),F("swapInAmountTokenB"),F("swapOutAmountTokenA"),v("status"),N(v(),7,""),N(Jr,3,"rewardInfos"),N(y(),16,"tickArrayBitmap"),y("totalFeesTokenA"),y("totalFeesClaimedTokenA"),y("totalFeesTokenB"),y("totalFeesClaimedTokenB"),y("fundFeesTokenA"),y("fundFeesTokenB"),y("startTime"),N(y(),15*4-3,"padding")]),$r=K([F("growthInsideLastX64"),y("rewardAmountOwed")]),vn=K([q(8),v("bump"),x("nftMint"),x("poolId"),te("tickLower"),te("tickUpper"),F("liquidity"),F("feeGrowthInsideLastX64A"),F("feeGrowthInsideLastX64B"),y("tokenFeesOwedA"),y("tokenFeesOwedB"),N($r,3,"rewardInfos"),N(y(),8,"")]),Wd=K([q(8),v("bump"),x("poolId"),te("tickLowerIndex"),te("tickUpperIndex"),F("liquidity"),F("feeGrowthInsideLastX64A"),F("feeGrowthInsideLastX64B"),y("tokenFeesOwedA"),y("tokenFeesOwedB"),N(F(),3,"rewardGrowthInside"),N(y(),8,"")]),eo=K([te("tick"),Yt("liquidityNet"),F("liquidityGross"),F("feeGrowthOutsideX64A"),F("feeGrowthOutsideX64B"),N(F(),3,"rewardGrowthsOutsideX64"),N(Pe(),13,"")]),Mn=K([q(8),x("poolId"),te("startTickIndex"),N(eo,rt,"ticks"),v("initializedTickCount"),N(v(),115,"")]),to=K([q(329),N(x(),100,"whitelistMints")]),Yr=K([q(8),x("poolId"),N(N(y(),8),vt,"positiveTickArrayBitmap"),N(N(y(),8),vt,"negativeTickArrayBitmap")]),Vd=K([y(),v("bump"),x("owner"),x("poolId"),x("positionId"),x("nftAccount"),N(y(),8)]),Dd=K([q(8),v("bump"),x("lockOwner"),x("poolId"),x("positionId"),x("nftAccount"),x("lockNftMint"),y("recentEpoch"),N(y(),8)]);Vn.span;var fp=V("Raydium_Clmm");var ao=V("Raydium_cpmm"),fe={initialize:[175,175,109,31,13,152,155,237],deposit:[242,35,198,137,82,225,242,182],withdraw:[183,18,70,156,148,109,161,34],swapBaseInput:[143,190,90,218,196,30,51,222],swapBaseOutput:[55,217,98,86,163,74,180,173],lockCpLiquidity:[216,157,29,78,38,51,31,26],collectCpFee:[8,30,51,199,209,184,247,133]};function Bf(e,t,n,i,r,o,s,a,c,u,l,m,d,f,P,b,I,h,C,S){let M=K([y("amountMaxA"),y("amountMaxB"),y("openTime")]),be=Nt(e,n,o,s).publicKey,H=[{pubkey:t,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!r.equals(be),isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:m,isSigner:!1,isWritable:!0},{pubkey:d,isSigner:!1,isWritable:!0},{pubkey:f,isSigner:!1,isWritable:!0},{pubkey:I,isSigner:!1,isWritable:!0},{pubkey:le,isSigner:!1,isWritable:!1},{pubkey:P,isSigner:!1,isWritable:!1},{pubkey:b,isSigner:!1,isWritable:!1},{pubkey:Dn,isSigner:!1,isWritable:!1},{pubkey:wn,isSigner:!1,isWritable:!1},{pubkey:et,isSigner:!1,isWritable:!1}],ye=Buffer.alloc(M.span);return M.encode({amountMaxA:h,amountMaxB:C,openTime:S},ye),new pe({keys:H,programId:e,data:Buffer.from([...fe.initialize,...ye])})}function xf(e,t,n,i,r,o,s,a,c,u,l,m,d,f,P){let b=K([y("lpAmount"),y("amountMaxA"),y("amountMaxB")]),I=[{pubkey:t,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:le,isSigner:!1,isWritable:!1},{pubkey:Wt,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:m,isSigner:!1,isWritable:!0}],h=Buffer.alloc(b.span);return ao.debug("cpmm deposit data",{lpAmount:d.toString(),amountMaxA:f.toString(),amountMaxB:P.toString()}),b.encode({lpAmount:d,amountMaxA:f,amountMaxB:P},h),new pe({keys:I,programId:e,data:Buffer.from([...fe.deposit,...h])})}function If(e,t,n,i,r,o,s,a,c,u,l,m,d,f,P){let b=K([y("lpAmount"),y("amountMinA"),y("amountMinB")]),I=[{pubkey:t,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:le,isSigner:!1,isWritable:!1},{pubkey:Wt,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:m,isSigner:!1,isWritable:!0},{pubkey:$e,isSigner:!1,isWritable:!1}],h=Buffer.alloc(b.span);return b.encode({lpAmount:d,amountMinA:f,amountMinB:P},h),new pe({keys:I,programId:e,data:Buffer.from([...fe.withdraw,...h])})}function Sf(e,t,n,i,r,o,s,a,c,u,l,m,d,f,P,b){let I=K([y("amountIn"),y("amounOutMin")]),h=[{pubkey:t,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:m,isSigner:!1,isWritable:!1},{pubkey:d,isSigner:!1,isWritable:!1},{pubkey:f,isSigner:!1,isWritable:!0}],C=Buffer.alloc(I.span);return I.encode({amountIn:P,amounOutMin:b},C),new pe({keys:h,programId:e,data:Buffer.from([...fe.swapBaseInput,...C])})}function Cf(e,t,n,i,r,o,s,a,c,u,l,m,d,f,P,b){let I=K([y("amountInMax"),y("amountOut")]),h=[{pubkey:t,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:m,isSigner:!1,isWritable:!1},{pubkey:d,isSigner:!1,isWritable:!1},{pubkey:f,isSigner:!1,isWritable:!0}],C=Buffer.alloc(I.span);return I.encode({amountInMax:P,amountOut:b},C),new pe({keys:h,programId:e,data:Buffer.from([...fe.swapBaseOutput,...C])})}async function Kf(e){var b;let{ownerInfo:t,poolInfo:n,poolKeys:i,getEphemeralSigners:r}=e,o=[],[s,a]=[new Ee(n.id),new Ee(n.lpMint.address)],c;if(r)c=new Ee((await r(1))[0]);else{let I=oo.generate();o.push(I),c=I.publicKey}let{publicKey:u}=he(t.feePayer,c,le),{publicKey:l}=Ot(c),{publicKey:m}=In(e.lockProgram,c),{publicKey:d}=he(t.feePayer,a,le),{publicKey:f}=he(e.lockAuthProgram,a,le),P=uo({programId:e.lockProgram,auth:e.lockAuthProgram,payer:t.feePayer,nftOwner:t.feePayer,liquidityOwner:t.feePayer,nftMint:c,nftAccount:u,poolId:s,lockPda:m,mintLp:a,userLpVault:d,lockLpVault:f,poolVaultA:new Ee(i.vault.A),poolVaultB:new Ee(i.vault.B),metadataAccount:l,lpAmount:e.lpAmount,withMetadata:(b=e.withMetadata)!=null?b:!0});return{address:{nftMint:c,nftAccount:u,metadataAccount:l,lockPda:m,userLpVault:d,lockLpVault:f},instructions:[P],signers:o,instructionTypes:[Te.CpmmLockLp],lookupTableAddress:[]}}function uo({programId:e,auth:t,payer:n,liquidityOwner:i,nftOwner:r,nftMint:o,nftAccount:s,poolId:a,lockPda:c,mintLp:u,userLpVault:l,lockLpVault:m,poolVaultA:d,poolVaultB:f,metadataAccount:P,lpAmount:b,withMetadata:I}){let h=[{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!0},{pubkey:i,isSigner:!0,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!0,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:m,isSigner:!1,isWritable:!0},{pubkey:d,isSigner:!1,isWritable:!0},{pubkey:f,isSigner:!1,isWritable:!0},{pubkey:P,isSigner:!1,isWritable:!0},{pubkey:et,isSigner:!1,isWritable:!1},{pubkey:so.programId,isSigner:!1,isWritable:!1},{pubkey:le,isSigner:!1,isWritable:!1},{pubkey:Dn,isSigner:!1,isWritable:!1},{pubkey:ke,isSigner:!1,isWritable:!1}],C=K([y("lpAmount"),de("withMetadata")]),S=Buffer.alloc(C.span);C.encode({lpAmount:b,withMetadata:I},S);let M=Buffer.from([...fe.lockCpLiquidity,...S]);return new pe({keys:h,programId:e,data:M})}function Nf({programId:e,nftOwner:t,auth:n,nftAccount:i,lockPda:r,poolId:o,mintLp:s,userVaultA:a,userVaultB:c,poolVaultA:u,poolVaultB:l,mintA:m,mintB:d,lockLpVault:f,lpFeeAmount:P,cpmmProgram:b,cpmmAuthProgram:I}){let h=[{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:t,isSigner:!0,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:b!=null?b:An,isSigner:!1,isWritable:!1},{pubkey:I!=null?I:kn,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:m,isSigner:!1,isWritable:!1},{pubkey:d,isSigner:!1,isWritable:!1},{pubkey:f,isSigner:!1,isWritable:!0},{pubkey:le,isSigner:!1,isWritable:!1},{pubkey:Wt,isSigner:!1,isWritable:!1},{pubkey:$e,isSigner:!1,isWritable:!1}],C=K([y("lpFeeAmount")]),S=Buffer.alloc(C.span);C.encode({lpFeeAmount:P},S);let M=Buffer.from([...fe.collectCpFee,...S]);return new pe({keys:h,programId:e,data:M})}import Dt from"bn.js";import ut from"decimal.js-light";import ve from"bn.js";function ot(e,t){if(t.isZero())throw Error("divisor is zero");return e.mod(t)}function co(e,t){if(t.isZero())throw Error("rhs is zero");let n=e.div(t);if(n.isZero())throw Error("quotient is zero");let i=ot(e,t);return i.gt(xe)&&(n=n.add(new ve(1)),t=e.div(n),i=ot(e,n),i.gt(xe)&&(t=t.add(new ve(1)))),[n,t]}var xe=new ve(0),st=class{static swapWithoutFees(t,n,i){let r=n.mul(i),o=n.add(t),[s,a]=co(r,o),c=a.sub(n),u=i.sub(s);if(u.isZero())throw Error("destinationAmountSwapped is zero");return{sourceAmountSwapped:c,destinationAmountSwapped:u}}static lpTokensToTradingTokens(t,n,i,r,o){let s=t.mul(i).div(n),a=t.mul(r).div(n);if(o===0)return{tokenAmount0:s,tokenAmount1:a};if(o===1)return ot(t.mul(i),n).gt(xe)&&s.gt(xe)&&(s=s.add(new ve(1))),ot(t.mul(r),n).gt(xe)&&a.gt(xe)&&(a=a.add(new ve(1))),{tokenAmount0:s,tokenAmount1:a};throw Error("roundDirection value error")}};import Gn from"bn.js";var Vt=new Gn(1e6);function lo(e,t,n){return e.mul(t).add(n).sub(new Gn(1)).div(n)}function qn(e,t,n){return e.mul(t).div(n)}var at=class{static tradingFee(t,n){return lo(t,n,Vt)}static protocolFee(t,n){return qn(t,n,Vt)}static fundFee(t,n){return qn(t,n,Vt)}};var _n=(n=>(n[n.Floor=0]="Floor",n[n.Ceiling=1]="Ceiling",n))(_n||{}),Un=class{static validate_supply(t,n){if(t.isZero())throw Error("tokenAmount0 is zero");if(n.isZero())throw Error("tokenAmount1 is zero")}static swap(t,n,i,r){let o=at.tradingFee(t,r),s=t.sub(o),{sourceAmountSwapped:a,destinationAmountSwapped:c}=st.swapWithoutFees(s,n,i),u=a.add(o);return{newSwapSourceAmount:n.add(u),newSwapDestinationAmount:i.sub(c),sourceAmountSwapped:u,destinationAmountSwapped:c,tradeFee:o}}static swapBaseOut({poolMintA:t,poolMintB:n,tradeFeeRate:i,baseReserve:r,quoteReserve:o,outputMint:s,outputAmount:a}){let[c,u,l,m,d]=n.address===s.toString()?[r,o,t.decimals,n.decimals,t.address]:[o,r,n.decimals,t.decimals,n.address],f=new ut(u.toString()).div(10**m).div(new ut(c.toString()).div(10**l)),P=a.gte(u)?u.sub(new Dt(1)):a,b=u.sub(P),I=Kt(c.mul(P),b),h=Kt(I.mul(new Dt(1e6)),new Dt(1e6).sub(i)),C=h.sub(I),S=new ut(P.toString()).div(10**m).div(new ut(h.toString()).div(10**l)),M=f.isZero()?0:S.sub(f).div(f).abs().toNumber();return{amountRealOut:P,amountIn:h,amountInWithoutFee:I,tradeFee:C,priceImpact:M}}};export{st as ConstantProductCurve,ds as CpmmConfigInfoLayout,at as CpmmFee,ps as CpmmPoolInfoLayout,Un as CurveCalculator,Vt as FEE_RATE_DENOMINATOR_VALUE,qr as LOCK_LIQUIDITY_SEED,_n as RoundDirection,lo as ceilDiv,Nf as collectCpFeeInstruction,uo as cpmmLockPositionInstruction,qn as floorDiv,In as getCpLockPda,Bl as getCpmmPdaAmmConfigId,Nt as getCpmmPdaPoolId,xl as getCreatePoolKeys,Vr as getPdaLpMint,Dr as getPdaObservationId,Wr as getPdaPoolAuthority,xn as getPdaVault,Kf as makeCpmmLockInstruction,Bf as makeCreateCpmmPoolInInstruction,xf as makeDepositCpmmInInstruction,Sf as makeSwapCpmmBaseInInstruction,Cf as makeSwapCpmmBaseOutInstruction,If as makeWithdrawCpmmInInstruction};
//# sourceMappingURL=index.mjs.map