UNPKG

@raydium-io/raydium-sdk-v2

Version:

An SDK for building applications on top of Raydium.

2 lines 67.2 kB
var qn=Object.defineProperty,Gn=Object.defineProperties;var Un=Object.getOwnPropertyDescriptors;var qt=Object.getOwnPropertySymbols;var Xn=Object.prototype.hasOwnProperty,Hn=Object.prototype.propertyIsEnumerable;var Gt=(e,t,n)=>t in e?qn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,j=(e,t)=>{for(var n in t||(t={}))Xn.call(t,n)&&Gt(e,n,t[n]);if(qt)for(var n of qt(t))Hn.call(t,n)&&Gt(e,n,t[n]);return e},$=(e,t)=>Gn(e,Un(t));import{PublicKey as ti}from"@solana/web3.js";import zt,{isBN as Zt}from"bn.js";import{bits as uo,BitStructure as co,blob as zn,Blob as lo,cstr as mo,f32 as po,f32be as fo,f64 as bo,f64be as yo,greedy as go,Layout as Zn,ns64 as Po,ns64be as wo,nu64 as ko,nu64be as Ao,offset as To,s16 as ho,s16be as Bo,s24 as xo,s24be as Io,s32 as Yn,s32be as So,s40 as Co,s40be as Ko,s48 as No,s48be as Lo,s8 as Ro,seq as jn,struct as Mo,Structure as Qn,u16 as Jn,u16be as Fo,u24 as Oo,u24be as Eo,u32 as Wo,u32be as vo,u40 as Vo,u40be as _o,u48 as Do,u48be as qo,u8 as $n,UInt as ei,union as Go,Union as Uo,unionLayoutDiscriminator as Xo,utf8 as Ho}from"@solana/buffer-layout";var dt=Zn,Ut=Qn;var pt=ei;var Xt=$n,Pe=Jn;var re=Yn;var Ht=jn;var V=zn;var Ae=class extends dt{constructor(n,i,r){super(n,r);this.blob=V(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 M(e){return new pt(1,e)}function Te(e){return new pt(4,e)}function y(e){return new Ae(8,!1,e)}function E(e){return new Ae(16,!1,e)}function Yt(e){return new Ae(8,!0,e)}function jt(e){return new Ae(16,!0,e)}var Ge=class extends dt{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 I(e){return new Ge(V(32),t=>new ti(t),t=>t.toBuffer(),e)}function me(e){return new Ge(Xt(),ni,ii,e)}function ni(e){if(e===0)return!1;if(e===1)return!0;throw new Error("Invalid bool: "+e)}function ii(e){return e?1:0}var ft=class extends Ut{decode(t,n){return super.decode(t,n)}};function C(e,t,n){return new ft(e,t,n)}function K(e,t,n){let i,r=typeof t=="number"?t:Zt(t)?t.toNumber():new Proxy(t,{get(o,s){if(!i){let a=Reflect.get(o,"count");i=Zt(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 Ht(e,r,n)}var ss=C([V(8),M("bump"),me("disableCreatePool"),Pe("index"),y("tradeFeeRate"),y("protocolFeeRate"),y("fundFeeRate"),y("createPoolFee"),I("protocolOwner"),I("fundOwner"),y("creatorFeeRate"),K(y(),15)]),as=C([V(8),I("configId"),I("poolCreator"),I("vaultA"),I("vaultB"),I("mintLp"),I("mintA"),I("mintB"),I("mintProgramA"),I("mintProgramB"),I("observationId"),M("bump"),M("status"),M("lpDecimals"),M("mintDecimalA"),M("mintDecimalB"),y("lpAmount"),y("protocolFeesMintA"),y("protocolFeesMintB"),y("fundFeesMintA"),y("fundFeesMintB"),y("openTime"),y("epoch"),M("feeOn"),me("enableCreatorFee"),K(M(),6),y("creatorFeesMintA"),y("creatorFeesMintB"),K(y(),28)]),us=C([V(8),I("configId"),K(y(),30)]);var ri=(i=>(i[i.BothToken=0]="BothToken",i[i.OnlyTokenA=1]="OnlyTokenA",i[i.OnlyTokenB=2]="OnlyTokenB",i))(ri||{});import{PublicKey as ve,TransactionInstruction as ae,Keypair as $r,SystemProgram as Vt}from"@solana/web3.js";import{ASSOCIATED_TOKEN_PROGRAM_ID as ut,TOKEN_2022_PROGRAM_ID as _t,TOKEN_PROGRAM_ID as se}from"@solana/spl-token";import{PublicKey as gs}from"@solana/web3.js";import{get as Qt,set as oi}from"lodash";var bt=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}},Jt={},si={};function _(e){let t=Qt(Jt,e);if(!t){let n=Qt(si,e);t=new bt({name:e,logLevel:n}),oi(Jt,e,t)}return t}import{MINT_SIZE as As,TOKEN_PROGRAM_ID as Ts,getTransferFeeConfig as hs,unpackMint as Bs}from"@solana/spl-token";var xs=_("Raydium_accountInfo_util");import ne from"bn.js";var he=9e15,be=1e9,yt="0123456789abcdef",He="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",ze="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",gt={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-he,maxE:he,crypto:!1},rn,oe,x=!0,Ye="[DecimalError] ",fe=Ye+"Invalid argument: ",on=Ye+"Precision limit exceeded",sn=Ye+"crypto unavailable",an="[object Decimal]",G=Math.floor,v=Math.pow,ai=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,ui=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,ci=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,un=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,J=1e7,T=7,li=9007199254740991,mi=He.length-1,Pt=ze.length-1,p={toStringTag:an};p.absoluteValue=p.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),P(e)};p.ceil=function(){return P(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(fe+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())+T,i.rounding=1,n=di(i,pn(i,n)),i.precision=e,i.rounding=t,P(oe==2||oe==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(x=!1,o=l.s*v(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=v(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&&(P(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")&&(P(i,e+1,1),t=!i.times(i).times(i).eq(l));break}return x=!0,P(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/T))*T,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 P(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 P(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/Qe(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),o=Be(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 P(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=Be(o,2,r,r,!0);else{e=1.4*Math.sqrt(i),e=e>16?16:e|0,r=r.times(1/Qe(5,e)),r=Be(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,P(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()?Q(n,r,o):new n(0):new n(NaN):t.isZero()?Q(n,r+4,o).times(.5):(n.precision=r+6,n.rounding=1,t=t.asin(),e=Q(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,x=!1,n=n.times(n).minus(1).sqrt().plus(n),x=!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,x=!1,n=n.times(n).plus(1).sqrt().plus(n),x=!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?P(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=Q(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<=Pt)return s=Q(l,m+4,d).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(m+4<=Pt)return s=Q(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/T+2|0),e=n;e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(x=!1,t=Math.ceil(a/T),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)),x=!0,P(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/T)>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(x=!1,a=m+f,s=pe(u,a),i=t?Ze(l,a+10):pe(e,a),c=L(s,i,a,1),Ke(c.d,r=m,d))do if(a+=10,s=pe(u,a),i=t?Ze(l,a+10):pe(e,a),c=L(s,i,a,1),!o){+D(c.d).slice(r+1,r+15)+1==1e14&&(c=P(c,m+1,0));break}while(Ke(c.d,r+=10,d));return x=!0,P(c,m,d)};p.minus=p.sub=function(e){var t,n,i,r,o,s,a,c,u,l,m,d,f=this,g=f.constructor;if(e=new g(e),!f.d||!e.d)return!f.s||!e.s?e=new g(NaN):f.d?e.s=-e.s:e=new g(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=g.precision,c=g.rounding,!u[0]||!d[0]){if(d[0])e.s=-e.s;else if(u[0])e=new g(f);else return new g(c===3?-0:0);return x?P(e,a,c):e}if(n=G(e.e/T),l=G(f.e/T),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/T),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]=J-1;--u[r],u[i]+=J}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=je(u,n),x?P(e,a,c):e):new g(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]?P(new i(n),i.precision,i.rounding):(x=!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),x=!0,n.minus(t))};p.naturalExponential=p.exp=function(){return wt(this)};p.naturalLogarithm=p.ln=function(){return pe(this)};p.negated=p.neg=function(){var e=new this.constructor(this);return e.s=-e.s,P(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)),x?P(e,a,c):e;if(o=G(m.e/T),i=G(e.e/T),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/T),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)/J|0,u[r]%=J;for(t&&(u.unshift(t),++i),s=u.length;u[--s]==0;)u.pop();return e.d=u,e.e=je(u,i),x?P(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(fe+e);return n.d?(t=cn(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t};p.round=function(){var e=this,t=e.constructor;return P(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())+T,i.rounding=1,n=fi(i,pn(i,n)),i.precision=e,i.rounding=t,P(oe>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(x=!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&&(P(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")&&(P(i,c+1,1),e=!i.times(i).eq(s));break}return x=!0,P(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,P(oe==2||oe==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/T)+G(e.e/T),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%J|0,t=a/J|0;o[r]=(o[r]+t)%J|0}for(;!o[--s];)o.pop();return t?++n:o.shift(),e.d=o,e.e=je(o,n),x?P(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,be),t===void 0?t=i.rounding:U(t,0,8),P(n,e+n.e+1,t))};p.toExponential=function(e,t){var n,i=this,r=i.constructor;return e===void 0?n=ee(i,!0):(U(e,0,be),t===void 0?t=r.rounding:U(t,0,8),i=P(new r(i),e+1,t),n=ee(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=ee(r):(U(e,0,be),t===void 0?t=o.rounding:U(t,0,8),i=P(new o(r),e+r.e+1,t),n=ee(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,g=f.d,b=f.constructor;if(!g)return new b(f);if(u=n=new b(1),i=c=new b(0),t=new b(i),o=t.e=cn(g)-f.e-1,s=o%T,t.d[0]=v(10,s<0?T+s:s),e==null)e=o>0?t:u;else{if(a=new b(e),!a.isInt()||a.lt(u))throw Error(fe+a);e=a.gt(t)?o>0?t:u:a}for(x=!1,a=new b(D(g)),l=b.precision,b.precision=o=g.length*T*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,x=!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]?(x=!1,n=L(n,e,0,t,1).times(e),x=!0,P(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(v(+a,u));if(a=new c(a),a.eq(1))return a;if(i=c.precision,o=c.rounding,e.eq(1))return P(a,i,o);if(t=G(e.e/T),t>=e.d.length-1&&(n=u<0?-u:u)<=li)return r=ln(c,a,n,i),e.s<0?new c(1).div(r):P(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=v(+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):(x=!1,c.rounding=a.s=1,n=Math.min(12,(t+"").length),r=wt(e.times(pe(a,i+n)),i),r.d&&(r=P(r,i+5,1),Ke(r.d,i,o)&&(t=i+10,r=P(wt(e.times(pe(a,t+n)),t),t+5,1),+D(r.d).slice(i+1,i+15)+1==1e14&&(r=P(r,i+1,0)))),r.s=s,x=!0,c.rounding=o,P(r,i,o))};p.toPrecision=function(e,t){var n,i=this,r=i.constructor;return e===void 0?n=ee(i,i.e<=r.toExpNeg||i.e>=r.toExpPos):(U(e,1,be),t===void 0?t=r.rounding:U(t,0,8),i=P(new r(i),e,t),n=ee(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,be),t===void 0?t=i.rounding:U(t,0,8)),P(new i(n),e,t)};p.toString=function(){var e=this,t=e.constructor,n=ee(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n};p.truncated=p.trunc=function(){return P(new this.constructor(this),this.e+1,1)};p.valueOf=p.toJSON=function(){var e=this,t=e.constructor,n=ee(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=T-i.length,n&&(o+=de(n)),o+=i;s=e[t],i=s+"",n=T-i.length,n&&(o+=de(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(fe+e)}function Ke(e,t,n,i){var r,o,s,a;for(o=e[0];o>=10;o/=10)--t;return--t<0?(t+=T,r=0):(r=Math.ceil((t+1)/T),t%=T),o=v(10,T-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)==v(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)==v(10,t-3)-1,s}function Xe(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]+=yt.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 di(e,t){var n,i,r;if(t.isZero())return t;i=t.d.length,i<32?(n=Math.ceil(i/3),r=(1/Qe(4,n)).toString()):(n=16,r="2.3283064365386962890625e-10"),e.precision+=n,t=Be(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,g,b,h,B,N,S,F,ce,H,ie,ke,le,lt,Y,De,qe=i.constructor,mt=i.s==r.s?1:-1,q=i.d,R=r.d;if(!q||!q[0]||!R||!R[0])return new qe(!i.s||!r.s||(q?R&&q[0]==R[0]:!R)?NaN:q&&q[0]==0||!R?mt*0:mt/0);for(c?(f=1,l=i.e-r.e):(c=J,f=T,l=G(i.e/f)-G(r.e/f)),Y=R.length,le=q.length,B=new qe(mt),N=B.d=[],m=0;R[m]==(q[m]||0);m++);if(R[m]>(q[m]||0)&&l--,o==null?(H=o=qe.precision,s=qe.rounding):a?H=o+(i.e-r.e)+1:H=o,H<0)N.push(1),g=!0;else{if(H=H/f+2|0,m=0,Y==1){for(d=0,R=R[0],H++;(m<le||d)&&H--;m++)ie=d*c+(q[m]||0),N[m]=ie/R|0,d=ie%R|0;g=d||m<le}else{for(d=c/(R[0]+1)|0,d>1&&(R=e(R,d,c),q=e(q,d,c),Y=R.length,le=q.length),ke=Y,S=q.slice(0,Y),F=S.length;F<Y;)S[F++]=0;De=R.slice(),De.unshift(0),lt=R[0],R[1]>=c/2&&++lt;do d=0,u=t(R,S,Y,F),u<0?(ce=S[0],Y!=F&&(ce=ce*c+(S[1]||0)),d=ce/lt|0,d>1?(d>=c&&(d=c-1),b=e(R,d,c),h=b.length,F=S.length,u=t(b,S,h,F),u==1&&(d--,n(b,Y<h?De:R,h,c))):(d==0&&(u=d=1),b=R.slice()),h=b.length,h<F&&b.unshift(0),n(S,b,F,c),u==-1&&(F=S.length,u=t(R,S,Y,F),u<1&&(d++,n(S,Y<F?De:R,F,c))),F=S.length):u===0&&(d++,S=[0]),N[m++]=d,u&&S[0]?S[F++]=q[ke]||0:(S=[q[ke]],F=1);while((ke++<le||S[0]!==void 0)&&H--);g=S[0]!==void 0}N[0]||N.shift()}if(f==1)B.e=l,rn=g;else{for(m=1,d=N[0];d>=10;d/=10)m++;B.e=m+l*f-1,P(B,a?o+B.e+1:o,s,g)}return B}}();function P(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+=T,s=t,l=m[d=0],c=l/v(10,r-s-1)%10|0;else if(d=Math.ceil((o+1)/T),a=m.length,d>=a)if(i){for(;a++<=d;)m.push(0);l=c=0,r=1,o%=T,s=o-T+1}else break e;else{for(l=a=m[d],r=1;a>=10;a/=10)r++;o%=T,s=o-T+r,c=s<0?0:l/v(10,r-s-1)%10|0}if(i=i||t<0||m[d+1]!==void 0||(s<0?l:l%v(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/v(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]=v(10,(T-t%T)%T),e.e=-t||0):m[0]=e.e=0,e;if(o==0?(m.length=d,a=1,d--):(m.length=d+1,a=v(10,T-o),m[d]=s>0?(l/v(10,r-s)%v(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]==J&&(m[0]=1));break}else{if(m[d]+=a,m[d]!=J)break;m[d--]=0,a=1}for(o=m.length;m[--o]===0;)m.pop()}return x&&(e.e>f.maxE?(e.d=null,e.e=NaN):e.e<f.minE&&(e.e=0,e.d=[0])),e}function ee(e,t,n){if(!e.isFinite())return dn(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)+de(i):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(e.e<0?"e":"e+")+e.e):r<0?(o="0."+de(-r-1)+o,n&&(i=n-s)>0&&(o+=de(i))):r>=s?(o+=de(r+1-s),n&&(i=n-r-1)>0&&(o=o+"."+de(i))):((i=r+1)<s&&(o=o.slice(0,i)+"."+o.slice(i)),n&&(i=n-s)>0&&(r+1===s&&(o+="."),o+=de(i))),o}function je(e,t){var n=e[0];for(t*=T;n>=10;n/=10)t++;return t}function Ze(e,t,n){if(t>mi)throw x=!0,n&&(e.precision=n),Error(on);return P(new e(He),t,1,!0)}function Q(e,t,n){if(t>Pt)throw Error(on);return P(new e(ze),t,n,!0)}function cn(e){var t=e.length-1,n=t*T+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 de(e){for(var t="";e--;)t+="0";return t}function ln(e,t,n,i){var r,o=new e(1),s=Math.ceil(i/T+4);for(x=!1;;){if(n%2&&(o=o.times(t),tn(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),tn(t.d,s)}return x=!0,o}function en(e){return e.d[e.d.length-1]&1}function mn(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 wt(e,t){var n,i,r,o,s,a,c,u=0,l=0,m=0,d=e.constructor,f=d.rounding,g=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?(x=!1,c=g):c=t,a=new d(.03125);e.e>-2;)e=e.times(a),m+=5;for(i=Math.log(v(2,m))/Math.LN10*2+5|0,c+=i,n=o=s=new d(1),d.precision=c;;){if(o=P(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=P(s.times(s),c,1);if(t==null)if(u<3&&Ke(s.d,c-i,f,u))d.precision=c+=10,n=o=a=new d(1),l=0,u++;else return P(s,d.precision=g,f,x=!0);else return d.precision=g,s}s=a}}function pe(e,t){var n,i,r,o,s,a,c,u,l,m,d,f=1,g=10,b=e,h=b.d,B=b.constructor,N=B.rounding,S=B.precision;if(b.s<0||!h||!h[0]||!b.e&&h[0]==1&&h.length==1)return new B(h&&!h[0]?-1/0:b.s!=1?NaN:h?0:b);if(t==null?(x=!1,l=S):l=t,B.precision=l+=g,n=D(h),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 B("0."+n),o++):b=new B(i+"."+n.slice(1))}else return u=Ze(B,l+2,S).times(o+""),b=pe(new B(i+"."+n.slice(1)),l-g).plus(u),B.precision=S,t==null?P(b,S,N,x=!0):b;for(m=b,c=s=b=L(b.minus(1),b.plus(1),l,1),d=P(b.times(b),l,1),r=3;;){if(s=P(s.times(d),l,1),u=c.plus(L(s,new B(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(B,l+2,S).times(o+""))),c=L(c,new B(f),l,1),t==null)if(Ke(c.d,l-g,N,a))B.precision=l+=g,u=s=b=L(m.minus(1),m.plus(1),l,1),d=P(b.times(b),l,1),r=a=1;else return P(c,B.precision=S,N,x=!0);else return B.precision=S,c;c=u,r+=2}}function dn(e){return String(e.s*e.s/0)}function kt(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)%T,n<0&&(i+=T),i<r){for(i&&e.d.push(+t.slice(0,i)),r-=T;i<r;)e.d.push(+t.slice(i,i+=T));t=t.slice(i),i=T-t.length}else i-=r;for(;i--;)t+="0";e.d.push(+t),x&&(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 pi(e,t){var n,i,r,o,s,a,c,u,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),un.test(t))return kt(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(ui.test(t))n=16,t=t.toLowerCase();else if(ai.test(t))n=2;else if(ci.test(t))n=8;else throw Error(fe+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=ln(i,new i(n),o,o*2)),u=Xe(t,n,J),l=u.length-1,o=l;u[o]===0;--o)u.pop();return o<0?new i(e.s*0):(e.e=je(u,l),e.d=u,x=!1,s&&(e=L(e,r,a*4)),c&&(e=e.times(Math.abs(c)<54?v(2,c):Je.pow(2,c))),x=!0,e)}function fi(e,t){var n,i=t.d.length;if(i<3)return t.isZero()?t:Be(e,2,t,t);n=1.4*Math.sqrt(i),n=n>16?16:n|0,t=t.times(1/Qe(5,n)),t=Be(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 Be(e,t,n,i,r){var o,s,a,c,u=1,l=e.precision,m=Math.ceil(l/T);for(x=!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 x=!0,s.d.length=m+1,s}function Qe(e,t){for(var n=e;--t;)n*=e;return n}function pn(e,t){var n,i=t.s<0,r=Q(e,e.precision,1),o=r.times(.5);if(t=t.abs(),t.lte(o))return oe=i?4:1,t;if(n=t.divToInt(r),n.isZero())oe=i?3:2;else{if(t=t.minus(n.times(r)),t.lte(o))return oe=en(n)?i?2:3:i?4:1,t;oe=en(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,g=n!==void 0;if(g?(U(n,1,be),i===void 0?i=f.rounding:U(i,0,8)):(n=f.precision,i=f.rounding),!e.isFinite())l=dn(e);else{for(l=ee(e),s=l.indexOf("."),g?(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=Xe(ee(d),10,r),d.e=d.d.length),m=Xe(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--:(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=rn),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+=yt.charAt(m[s]);if(g){if(c>1)if(t==16||t==8){for(s=t==16?4:3,--c;c%s;c++)l+="0";for(m=Xe(l,r,t),c=m.length;!m[c-1];--c);for(s=1,l="1.";s<c;s++)l+=yt.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 tn(e,t){if(e.length>t)return e.length=t,!0}function bi(e){return new this(e).abs()}function yi(e){return new this(e).acos()}function gi(e){return new this(e).acosh()}function Pi(e,t){return new this(e).plus(t)}function wi(e){return new this(e).asin()}function ki(e){return new this(e).asinh()}function Ai(e){return new this(e).atan()}function Ti(e){return new this(e).atanh()}function hi(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=Q(this,o,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?Q(this,i,r):new this(0),n.s=e.s):!e.d||t.isZero()?(n=Q(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=Q(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 Bi(e){return new this(e).cbrt()}function xi(e){return P(e=new this(e),e.e+1,2)}function Ii(e,t,n){return new this(e).clamp(t,n)}function Si(e){if(!e||typeof e!="object")throw Error(Ye+"Object expected");var t,n,i,r=e.defaults===!0,o=["precision",1,be,"rounding",0,8,"toExpNeg",-he,0,"toExpPos",0,he,"maxE",0,he,"minE",-he,0,"modulo",0,9];for(t=0;t<o.length;t+=3)if(n=o[t],r&&(this[n]=gt[n]),(i=e[n])!==void 0)if(G(i)===i&&i>=o[t+1]&&i<=o[t+2])this[n]=i;else throw Error(fe+n+": "+i);if(n="crypto",r&&(this[n]=gt[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(sn);else this[n]=!1;else throw Error(fe+n+": "+i);return this}function Ci(e){return new this(e).cos()}function Ki(e){return new this(e).cosh()}function fn(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,nn(o)){u.s=o.s,x?!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++;x?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 kt(u,o.toString())}else if(c!=="string")throw Error(fe+o);return(a=o.charCodeAt(0))===45?(o=o.slice(1),u.s=-1):(a===43&&(o=o.slice(1)),u.s=1),un.test(o)?kt(u,o):pi(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=Si,r.clone=fn,r.isDecimal=nn,r.abs=bi,r.acos=yi,r.acosh=gi,r.add=Pi,r.asin=wi,r.asinh=ki,r.atan=Ai,r.atanh=Ti,r.atan2=hi,r.cbrt=Bi,r.ceil=xi,r.clamp=Ii,r.cos=Ci,r.cosh=Ki,r.div=Ni,r.exp=Li,r.floor=Ri,r.hypot=Mi,r.ln=Fi,r.log=Oi,r.log10=Wi,r.log2=Ei,r.max=vi,r.min=Vi,r.mod=_i,r.mul=Di,r.pow=qi,r.random=Gi,r.round=Ui,r.sign=Xi,r.sin=Hi,r.sinh=zi,r.sqrt=Zi,r.sub=Yi,r.sum=ji,r.tan=Qi,r.tanh=Ji,r.trunc=$i,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 Ni(e,t){return new this(e).div(t)}function Li(e){return new this(e).exp()}function Ri(e){return P(e=new this(e),e.e+1,3)}function Mi(){var e,t,n=new this(0);for(x=!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 x=!0,new this(1/0);n=t}return x=!0,n.sqrt()}function nn(e){return e instanceof Je||e&&e.toStringTag===an||!1}function Fi(e){return new this(e).ln()}function Oi(e,t){return new this(e).log(t)}function Ei(e){return new this(e).log(2)}function Wi(e){return new this(e).log(10)}function vi(){return mn(this,arguments,"lt")}function Vi(){return mn(this,arguments,"gt")}function _i(e,t){return new this(e).mod(t)}function Di(e,t){return new this(e).mul(t)}function qi(e,t){return new this(e).pow(t)}function Gi(e){var t,n,i,r,o=0,s=new this(1),a=[];if(e===void 0?e=this.precision:U(e,1,be),i=Math.ceil(e/T),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(sn);else for(;o<i;)a[o++]=Math.random()*1e7|0;for(i=a[--o],e%=T,i&&e&&(r=v(10,T-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-=T)a.shift();for(i=1,r=a[0];r>=10;r/=10)i++;i<T&&(n-=T-i)}return s.e=n,s.d=a,s}function Ui(e){return P(e=new this(e),e.e+1,this.rounding)}function Xi(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Hi(e){return new this(e).sin()}function zi(e){return new this(e).sinh()}function Zi(e){return new this(e).sqrt()}function Yi(e,t){return new this(e).sub(t)}function ji(){var e=0,t=arguments,n=new this(t[e]);for(x=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return x=!0,P(n,this.precision,this.rounding)}function Qi(e){return new this(e).tan()}function Ji(e){return new this(e).tanh()}function $i(e){return P(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=fn(gt);He=new Je(He);ze=new Je(ze);import ar from"big.js";import Us from"bn.js";import er from"toformat";var tr=er,Ne=tr;import et from"big.js";import ir from"bn.js";import rr from"decimal.js-light";import Le from"bn.js";var bn=9007199254740991;function te(e){let t=_("Raydium_parseBigNumberish");if(e instanceof Le)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new Le(e);t.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&t.logWithError(`BigNumberish number underflow: ${e}`),(e>=bn||e<=-bn)&&t.logWithError(`BigNumberish number overflow: ${e}`),new Le(String(e))):typeof e=="bigint"?new Le(e.toString()):(t.error(`invalid BigNumberish value: ${e}`),new Le(0))}var $e=_("module/fraction"),Tt=Ne(et),Re=Ne(rr),or={[0]:Re.ROUND_DOWN,[1]:Re.ROUND_HALF_UP,[2]:Re.ROUND_UP},sr={[0]:et.roundDown,[1]:et.roundHalfUp,[2]:et.roundUp},O=class{constructor(t,n=new ir(1)){this.numerator=te(t),this.denominator=te(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(te(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(te(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(te(t));return new O(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(t){let n=t instanceof O?t:new O(te(t));return new O(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(t,n={groupSeparator:""},i=1){Number.isInteger(t)||$e.logWithError(`${t} is not an integer.`),t<=0&&$e.logWithError(`${t} is not positive.`),Re.set({precision:t+1,rounding:or[i]});let r=new Re(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)||$e.logWithError(`${t} is not an integer.`),t<0&&$e.logWithError(`${t} is negative.`),Tt.DP=t,Tt.RM=sr[i]||1,new Tt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,n)}isZero(){return this.numerator.isZero()}};var $s=_("Raydium_amount"),ea=Ne(ar);import{PublicKey as cr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as yn}from"@solana/spl-token";var ht={chainId:101,address:cr.default.toBase58(),programId:yn.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},ye={chainId:101,address:"So11111111111111111111111111111111111111112",programId:yn.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 xt}from"@solana/web3.js";import{PublicKey as W,SystemProgram as gn,SYSVAR_RENT_PUBKEY as lr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as mr}from"@solana/spl-token";function Bt({pubkey:e,isSigner:t=!1,isWritable:n=!0}){return{pubkey:e,isWritable:n,isSigner:t}}var ua=[Bt({pubkey:mr,isWritable:!1}),Bt({pubkey:gn.programId,isWritable:!1}),Bt({pubkey:lr,isWritable:!1})];function Pn({publicKey:e,transformSol:t}){let n=wn(e.toString());if(n instanceof W)return t&&n.equals(Me)?Ue:n;if(t&&n.toString()===Me.toBase58())return Ue;if(typeof n=="string"){if(n===W.default.toBase58())return W.default;try{return new W(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function wn(e){try{return new W(e)}catch{return e}}var dr=new W("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),tt=new W("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),nt=new W("SysvarRent111111111111111111111111111111111"),ca=new W("SysvarC1ock11111111111111111111111111111111"),xe=new W("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),la=new W("Sysvar1nstructions1111111111111111111111111"),kn=gn.programId,ma=new W("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),da=new W("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),pa=new W("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),fa=new W("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),ba=new W("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),ya=new W("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),ga=new W("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Pa=new W("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),wa=new W("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),ka=new W("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Aa=new W("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),Ue=new W("So11111111111111111111111111111111111111112"),Me=W.default;var It=class{constructor({mint:t,decimals:n,symbol:i,name:r,skipMint:o=!1,isToken2022:s=!1}){if(t===Me.toBase58()||t instanceof xt&&Me.equals(t)){this.decimals=ye.decimals,this.symbol=ye.symbol,this.name=ye.name,this.mint=new xt(ye.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?xt.default:Pn({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},ge=It;ge.WSOL=new It($(j({},ye),{mint:ye.address}));var St=class{constructor({decimals:t,symbol:n="UNKNOWN",name:i="UNKNOWN"}){this.decimals=t,this.symbol=n,this.name=i}equals(t){return this===t}},it=St;it.SOL=new St(ht);import pr from"bn.js";var Ma=new O(new pr(100));var Va=_("Raydium_price");var fr=new ne(0),pu=new ne(1),fu=new ne(2),bu=new ne(3),yu=new ne(5),ur=new ne(10),gu=new ne(100),Pu=new ne(1e3),wu=new ne(1e4);function Nt(e,t,n){return e.mul(t).add(n).sub(new ne(1)).div(n)}function ot(e,t,n){return e.mul(t).div(n)}import{PublicKey as yr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as gr}from"@solana/spl-token";import{ComputeBudgetProgram as Su,Keypair as Nu,PublicKey as br,Transaction as Ru,TransactionMessage as Fu,VersionedTransaction as Ou}from"@solana/web3.js";var Ie={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 Vu}from"@solana/spl-token";var _u=_("Raydium_txUtil");function z(e,t){let[n,i]=br.findProgramAddressSync(e,t);return{publicKey:n,nonce:i}}function Se(e,t,n){return z([e.toBuffer(),(n!=null?n:gr).toBuffer(),t.toBuffer()],new yr("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}import{PublicKey as A}from"@solana/web3.js";var zu=new A("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),Zu=new A("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),Yu=new A("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),ju=new A("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Qu=new A("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),Ju=new A("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),$u=new A("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),ec=new A("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),tc=new A("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),nc=new A("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),Pr=new A("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),wr=new A("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),kr=new A("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),ic=new A("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),rc=new A("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),oc=new A("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),sc=new A("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),ac=new A("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),uc=new A("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),cc=new A("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),An=new A("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),Tn=new A("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),lc=new A("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),mc=new A("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),dc=new A("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),pc=new A("LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj"),fc=new A("WLHv2UAZm6z4KyaaELi5pjdbJh6RESMva1Rnn8pJVVh"),bc=new A("DRay6fNdQ5J82H7xV6uq2aV3mNrUZ1J4PgSKsWgptcm6"),yc=new A("5xqNaZXX5eUi4p5HU4oz9i5QnwRNT2y6oN7yyn4qENeq"),gc=new A("4Bu96XjU84XjPDSpveTVf6LYGCkfW5FK7SNkREWcEfV4"),Pc=new A("6s1xP3hpbAfFoNtUNF8mfHsjr2Bd97JxFJRWLbL6aHuX");var wc={OPEN_BOOK_PROGRAM:new A("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),SERUM_PROGRAM_ID_V3:new A("Ray1111111111111111111111111111111111111111"),AMM_V4:new A("DRaya7Kj3aMWQSy19kSjvmuwq9docCHofyP9kanQGaav"),AMM_STABLE:new A("DRayDdXc1NZQ9C3hRWmoSf8zK4iapgMnjdNZWrfwsP8m"),CLMM_PROGRAM_ID:new A("DRayAUgENGQBKVaX8owNhgzkEDyoHTGVEGHVJT1E9pfH"),CLMM_LOCK_PROGRAM_ID:new A("DRay25Usp3YJAi7beckgpGUC7mGJ2cR1AVPxhYfwVCUX"),CLMM_LOCK_AUTH_ID:new A("6Aoh8h2Lw2m5UGxYR8AdAL87jTWYeKoxM52mJRzfYwN"),CREATE_CPMM_POOL_PROGRAM:new A("DRaycpLY18LhpbydsBWbVJtxpNv9oXPgjRSfpF2bWpYb"),CREATE_CPMM_POOL_AUTH:new A("CXniRufdq5xL8t8jZAPxsPZDpuudwuJSPWnbcD5Y5Nxq"),CREATE_CPMM_POOL_FEE_ACC:new A("3oE58BKVt8KuYkGxx8zBojugnymWmBiyafWgMrnb6eYy"),LOCK_CPMM_PROGRAM:new A("DRay25Usp3YJAi7beckgpGUC7mGJ2cR1AVPxhYfwVCUX"),LOCK_CPMM_AUTH:new A("7qWVV8UY2bRJfDLP4s37YzBPKUkVB46DStYJBpYbQzu3"),UTIL1216:A.default,Router:new A("DRaybByLpbUL57LJARs3j8BitTxVfzBg351EaMr5UTCd"),FARM_PROGRAM_ID_V3:new A("DRayWyrLmEW5KEeqs8kdTMMaBabapqagaBC7KWpGtJeZ"),FARM_PROGRAM_ID_V4:new A("Ray1111111111111111111111111111111111111111"),FARM_PROGRAM_ID_V5:new A("DRayiCGSZgku1GTK6rXD6mVDdingXy6APAH1R6R5L2LC"),FARM_PROGRAM_ID_V6:new A("DRayzbYakXs45ELHkzH6vC3fuhQqTAnv5A68gdFuvZyZ"),LAUNCHPAD_PROGRAM:new A("DRay6fNdQ5J82H7xV6uq2aV3mNrUZ1J4PgSKsWgptcm6"),LAUNCHPAD_AUTH:new A("5xqNaZXX5eUi4p5HU4oz9i5QnwRNT2y6oN7yyn4qENeq"),LAUNCHPAD_PLATFORM:new A("2Jx4KTDrVSdWNazuGpcA8n3ZLTRGGBDxAWhuKe2Xcj2a"),LAUNCHPAD_CONFIG:new A("7ZR4zD7PYfY2XxoG1Gxcy2EgEeGYrpxrwzPuwdUBssEt"),FEE_DESTINATION_ID:new A("9y8ENuuZ3b19quffx9hQvRVygG5ky6snHfRvGpuSfeJy"),MODEL_DATA_PUBKEY:new A("Ray1111111111111111111111111111111111111111")};import Tc from"bn.js";import{PublicKey as Ic,AddressLookupTableAccount as Sc}from"@solana/web3.js";import{PublicKey as qc,sendAndConfirmTransaction as Gc,SystemProgram as Hc,Transaction as zc,TransactionMessage as Yc,VersionedTransaction as jc}from"@solana/web3.js";import Jc from"axios";import{PublicKey as ol}from"@solana/web3.js";import al from"bn.js";import hr from"bn.js";var we=new hr(1e6);var Br=Buffer.from("vault_and_lp_mint_auth_seed","utf8"),xr=Buffer.from("amm_config","utf8"),Ir=Buffer.from("pool","utf8"),Sr=Buffer.from("pool_lp_mint","utf8"),Cr=Buffer.from("pool_vault","utf8"),Kr=Buffer.from("observation","utf8"),Nr=Buffer.from("permission","utf8");function Lr(e){return z([Br],e)}function Ml(e,t){return z([xr,Fr(t)],e)}function Lt(e,t,n,i){return z([Ir,t.toBuffer(),n.toBuffer(),i.toBuffer()],e)}function Rr(e,t){return z([Sr,t.toBuffer()],e)}function Bn(e,t,n){return z([Cr,t.toBuffer(),n.toBuffer()],e)}function Mr(e,t){return z([Kr,t.toBuffer()],e)}function Fr(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,e,!1),new Uint8Array(t)}function Fl({poolId:e,programId:t,configId:n,mintA:i,mintB:r}){let o=Lr(t).publicKey,s=e||Lt(t,n,i,r).publicKey,a=Rr(t,s).publicKey,c=Bn(t,s,i).publicKey,u=Bn(t,s,r).publicKey,l=Mr(t,s).publicKey;return{poolId:s,configId:n,authority:o,lpMint:a,vaultA:c,vaultB:u,observationId:l}}var Or=Buffer.from("locked_liquidity","utf8");function xn(e,t){return z([Or,t.toBuffer()],e)}function Ol(e,t){return z([Nr,t.toBuffer()],e)}import{PublicKey as Wp}from"@solana/web3.js";import Vp from"bn.js";import{AccountLayout as Gp,createAssociatedTokenAccountIdempotentInstruction as Up,TOKEN_2022_PROGRAM_ID as Xp,TOKEN_PROGRAM_ID as Hp}from"@solana/spl-token";import{PublicKey as Vl}from"@solana/web3.js";import{MintLayout as Dl,TOKEN_PROGRAM_ID as Gl}from"@solana/spl-token";import{Keypair as sp,PublicKey as ap,SystemProgram as cp,TransactionInstruction as lp}from"@solana/web3.js";import dp from"bn.js";import{ASSOCIATED_TOKEN_PROGRAM_ID as bp,TOKEN_2022_PROGRAM_ID as yp,TOKEN_PROGRAM_ID as gp}from"@solana/spl-token";import _d from"bn.js";import Z from"bn.js";var Rt=new Z(0),In=new Z(1),Sn=new Z(-1),st=new Z(1).shln(64),Cn=new Z(1).shln(128),Er=st.sub(In);var Wr=Cn.subn(1),Ce=-443636,Oe=-Ce,Mt=new Z("4295048016"),Ft=new Z("79226673521066979257578248091"),tm=new Z("4295048017"),nm=new Z("79226673521066979257578248090");var vr=new Z(10).pow(new Z(6));var im=new Z("18446744073700000000");import Id from"bn.js";var lm=Buffer.from("amm_config","utf8"),mm=Buffer.from("pool","utf8"),dm=Buffer.from("pool_vault","utf8"),pm=Buffer.from("pool_reward_vault","utf8"),fm=Buffer.from("position","utf8"),bm=Buffer.from("tick_array","utf8"),ym=Buffer.from("operation","utf8"),gm=Buffer.from("pool_tick_array_bitmap_extension","utf8"),Pm=Buffer.from("observation","utf8");function Ot(e){return z([Buffer.from("metadata","utf8"),xe.toBuffer(),e.toBuffer()],xe)}var wm=Buffer.from("locked_position","utf8");var km=Buffer.from("support_mint","utf8");import{PublicKey as $m}from"@solana/web3.js";import{TOKEN_2022_PROGRAM_ID as td}from"@solana/spl-token";import id from"bn.js";import hm from"bn.js";var vt=14;var at=60;var Gr=C([V(8),M("bump"),Pe("index"),I(""),Te("protocolFeeRate"),Te("tradeFeeRate"),Pe("tickSpacing"),K(y(),8,"")]),Ur=C([Te("blockTimestamp"),Yt("tickCumulative"),K(y(),4)]),vn=C([V(8),me("initialized"),y("recentEpoch"),Pe("observationIndex"),I("poolId"),K(Ur,100,"observations"),K(y(),4)]),Xr=C([M("rewardState"),y("openTime"),y("endTime"),y("lastUpdateTime"),E("emissionsPerSecondX64"),y("rewardTotalEmissioned"),y("rewardClaimed"),I("tokenMint"),I("tokenVault"),I("creator"),E("rewardGrowthGlobalX64")]),On=C([V(8),M("bump"),I("ammConfig"),I("creator"),I("mintA"),I("mintB"),I("vaultA"),I("vaultB"),I("observationId"),M("mintDecimalsA"),M("mintDecimalsB"),Pe("tickSpacing"),E("liquidity"),E("sqrtPriceX64"),re("tickCurrent"),Te(),E("feeGrowthGlobalX64A"),E("feeGrowthGlobalX64B"),y("protocolFeesTokenA"),y("protocolFeesTokenB"),E("swapInAmountTokenA"),E("swapOutAmountTokenB"),E("swapInAmountTokenB"),E("swapOutAmountTokenA"),M("status"),K(M(),7,""),K(Xr,3,"rewardInfos"),K(y(),16,"tickArrayBitmap"),y("totalFeesTokenA"),y("totalFeesClaimedTokenA"),y("totalFeesTokenB"),y("totalFeesClaimedTokenB"),y("fundFeesTokenA"),y("fundFeesTokenB"),y("startTime"),K(y(),15*4-3,"padding")]),Hr=C([E("growthInsideLastX64"),y("rewardAmountOwed")]),En=C([V(8),M("bump"),I("nftMint"),I("poolId"),re("tickLower"),re("tickUpper"),E("liquidity"),E("feeGrowthInsideLastX64A"),E("feeGrowthInsideLastX64B"),y("tokenFeesOwedA"),y("tokenFeesOwedB"),K(Hr,3,"rewardInfos"),K(y(),8,"")]),jd=C([V(8),M("bump"),I("poolId"),re("tickLowerIndex"),re("tickUpperIndex"),E("liquidity"),E("feeGrowthInsideLastX64A"),E("feeGrowthInsideLastX64B"),y("tokenFeesOwedA"),y("tokenFeesOwedB"),K(E(),3,"rewardGrowthInside"),K(y(),8,"")]),zr=C([re("tick"),jt("liquidityNet"),E("liquidityGross"),E("feeGrowthOutsideX64A"),E("feeGrowthOutsideX64B"),K(E(),3,"rewardGrowthsOutsideX64"),K(Te(),13,"")]),Rn=C([V(8),I("poolId"),re("startTickIndex"),K(zr,at,"ticks"),M("initializedTickCount"),K(M(),115,"")]),Zr=C([V(329),K(I(),100,"whitelistMints")]),qr=C([V(8),I("poolId"),K(K(y(),8),vt,"positiveTickArrayBitmap"),K(K(y(),8),vt,"negativeTickArrayBitmap")]),Qd=C([y(),M("bump"),I("owner"),I("poolId"),I("positionId"),I("nftAccount"),K(y(),8)]),Yr=C([V(8),M("bump"),I("lockOwner"),I("poolId"),I("positionId"),I("nftAccount"),I("lockNftMint"),y("recentEpoch"),K(y(),8)]);vn.span;var Ip=_("Raydium_Clmm");var eo=_("Raydium_cpmm"),ue={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],createPermissionPda:Buffer.from([135,136,2,216,137,169,181,202]),closePermissionPda:Buffer.from([156,84,32,118,69,135,70,123]),initializeWithPermission:Buffer.from([63,55,254,65,49,178,89,121]),collectCreatorFee:Buffer.from([20,22,86,123,198,28,219,132])};function vf(e,t,n,i,r,o,s,a,c,u,l,m,d,f,g,b,h,B,N,S){let F=C([y("amountMaxA"),y("amountMaxB"),y("openTime")]),ce=Lt(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(ce),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:h,isSigner:!1,isWritable:!0},{pubkey:se,isSigner:!1,isWritable:!1},{pubkey:g,isSigner:!1,isWritable:!1},{pubkey:b,isSigner:!1,isWritable:!1},{pubkey:ut,isSigner:!1,isWritable:!1},{pubkey:kn,isSigner:!1,isWritable:!1},{pubkey:nt,isSigner:!1,isWritable:!1}],ie=Buffer.alloc(F.span);return F.encode({amountMaxA:B,amountMaxB:N,openTime:S},ie),new ae({keys:H,programId:e,data:Buffer.from([...ue.initialize,...ie])})}function Vf(e,t,n,i,r,o,s,a,c,u,l,m,d,f,g){let b=C([y("lpAmount"),y("amountMaxA"),y("amountMaxB")]),h=[{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:se,isSigner:!1,isWritable:!1},{pubkey:_t,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:m,isSigner:!1,isWritable:!0}],B=Buffer.alloc(b.span);return eo.debug("cpmm deposit data",{lpAmount:d.toString(),amountMaxA:f.toString(),amountMaxB:g.toString()}),b.encode({lpAmount:d,amountMaxA:f,amountMaxB:g},B),new ae({keys:h,programId:e,data:Buffer.from([...ue.deposit,...B])})}function _f(e,t,n,i,r,o,s,a,c,u,l,m,d,f,g){let b=C([y("lpAmount"),y("amountMinA"),y("amountMinB")]),h=[{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:se,isSigner:!1,isWritable:!1},{pubkey:_t,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:m,isSigner:!1,isWritable:!0},{pubkey:tt,isSigner:!1,isWritable:!1}],B=Buffer.alloc(b.span);return b.encode({lpAmount:d,amountMinA:f,amountMinB:g},B),new ae({keys:h,programId:e,data:Buffer.from([...ue.withdraw,...B])})}function Df(e,t,n,i,r,o,s,a,c,u,l,m,d,f,g,b){let h=C([y("amountIn"),y("amounOutMin")]),B=[{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}],N=Buffer.alloc(h.span);return h.encode({amountIn:g,amounOutMin:b},N),new ae({keys:B,programId:e,data:Buffer.from([...ue.swapBaseInput,...N])})}function qf(e,t,n,i,r,o,s,a,c,u,l,m,d,f,g,b){let h=C([y("amountInMax"),y("amountOut")]),B=[{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}],N=Buffer.alloc(h.span);return h.encode({amountInMax:g,amountOut:b},N),new ae({keys:B,programId:e,data:Buffer.from([...ue.swapBaseOutput,...N])})}async function Gf(e){var h;let{ownerInfo:t,poolInfo:n,poolKeys:i,feeNftOwner:r,getEphemeralSigners:o}=e,s=[],[a,c]=[new ve(n.id),new ve(n.lpMint.address)],u;if(o)u=new ve((await o(1))[0]);else{let B=$r.generate();s.push(B),u=B.publicKey}let{publicKey:l}=Se(r,u,se),{publicKey:m}=Ot(u),{publicKey:d}=xn(e.lockProgram,u),{publicKey:f}=Se(t.wallet,c,se),{publicKey:g}=Se(e.lockAuthProgram,c,se),b=to({programId:e.lockProgram,auth:e.lockAuthProgram,payer:t.feePayer,liquidityOwner:t.wallet,nftOwner:r,nftMint:u,nftAccount:l,poolId:a,lockPda:d,mintLp:c,userLpVault:f,lockLpVault:g,poolVaultA:new ve(i.vault.A),poolVaultB:new ve(i.vault.B),metadataAccount:m,lpAmount:e.lpAmount,withMetadata:(h=e.withMetadata)!=null?h:!0});return{address:{nftMint:u,nftAccount:l,metadataAccount:m,lockPda:d,userLpVault:f,lockLpVault:g},instructions:[b],signers:s,instructionTypes:[Ie.CpmmLockLp],lookupTableAddress:[]}}function to({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:g,lpAmount:b,withMetadata:h}){let B=[{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:g,isSigner:!1,isWritable:!0},{pubkey:nt,isSigner:!1,isWritable:!1},{pubkey:Vt.programId,isSigner:!1,isWritable:!1},{pubkey:se,isSigner:!1,isWritable:!1},{pubkey:ut,isSigner:!1,isWritable:!1},{pubkey:xe,isSigner:!1,isWritable:!1}],N=C([y("lpAmount"),me("withMetadata")]),S=Buffer.alloc(N.span);N.encode({lpAmount:b,withMetadata:h},S);let F=Buffer.from([...ue.lockCpLiquidity,...S]);return new ae({keys:B,programId:e,data:F})}function Uf({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:g,cpmmProgram:b,cpmmAuthProgram:h}){let B=[{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:h!=null?h:Tn,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:se,isSigner:!1,isWritable:!1},{pubkey:_t,isSigner:!1,isWritable:!1},{pubkey:tt,isSigner:!1,isWritable:!1}],N=C([y("lpFeeAmount")]),S=Buffer.alloc(N.span);N.encode({lpFeeAmount:g},S);let F=Buffer.from([...ue.collectCpFee,...S]);return new ae({keys:B,programId:e,data:F})}function Xf(e,t,n,i,r,o,s,a,c,u,l,m,d){let f=[{pubkey:t,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!1},{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:ut,isSigner:!1,isWritable:!1},{pubkey:Vt.programId,isSigner:!1,isWritable:!1}];return new ae({keys:f,programId:e,data:ue.collectCreatorFee})}function Hf(e,t,n,i,r,o,s,a,c,u,l,m,d,f,g,b,h,B,N,S,F,ce,H){let ie=C([y("amountA"),y("amountB"),y("openTime"),M("feeOn")]),ke=[{pubkey:t,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{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:g,isSigner:!1,isWritable:!0},{pubkey:B,isSigner:!1,isWritable:!0},{pubkey:N,isSigner:!1,isWritable:!0},{pubkey:se,isSigner:!1,isWritable:!1},{pubkey:b,isSigner:!1,isWritable:!1},{pubkey:h,isSigner:!1,isWritable:!1},{pubkey:ut,isSigner:!1,isWritable:!1},{pubkey:Vt.programId,isSigner:!1,isWritable:!1}],le=Buffer.alloc(ie.span);return ie.encode({amountA:S,amountB:F,openTime:ce,feeOn:H},le),new ae({keys:ke,programId:e,data:Buffer.from([...ue.initializeWithPermission,...le])})}import _n from"bn.js";import ct from"bn.js";function Dt(e,t){if(t.isZero())throw Error("divisor is zero");return e.mod(t)}function no(e,t){if(t.isZero())throw Error("rhs is zero");let n=e.div(t);return Dt(e,t).gt(Ve)&&(n=n.add(new ct(1))),[n,t]}var Ve=new ct(0),_e=class{static swapBaseInputWithoutFees(t,n,i){let r=t.mul(i),o=n.add(t);return r.div(o)}static swapBaseOutputWithoutFees(t,n,i){let r=n.mul(t),o=i.sub(t),[s]=no(r,o);return s}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 Dt(t.mul(i),n).gt(Ve)&&s.gt(Ve)&&(s=s.add(new ct(1))),Dt(t.mul(r),n).gt(Ve)&&a.gt(Ve)&&(a=a.add(new ct(1))),{tokenAmount0:s,tokenAmount1:a};throw Error("roundDirection value error")}};import io from"bn.js";var X=class{static tradingFee(t,n){return Nt(t,n,we)}static protocolFee(t,n){return ot(t,n,we)}static fundFee(t,n){return ot(t,n,we)}static creatorFee(t,n){return Nt(t,n,we)}static splitCreatorFee(t,n,i){return ot(t,i,n.add(i))}static calculatePreFeeAmount(t,n){if(n.isZero())return t;let i=t.mul(we),r=we.sub(n);return i.add(r).sub(new io(1)).div(r)}};var Vn=(n=>(n[n.Floor=0]="Floor",n[n.Ceiling=1]="Ceiling",n))(Vn||{}),ro=(n=>(n[n.ZeroForOne=0]="ZeroForOne",n[n.OneForZero=1]="OneForZero",n))(ro||{}),oo=(n=>(n[n.OneForZero=0]="OneForZero",n[n.ZeroForOne=1]="ZeroForOne",n))(oo||{}),Dn=class{static validate_supply(t,n){if(t.isZero())throw Error("tokenAmount0 is zero");if(n.isZero())throw Error("tokenAmount1 is zero")}static swapBaseInput(t,n,i,r,o,s,a,c){let u=new _n(0),l=X.tradingFee(t,r),m;c?(u=X.creatorFee(t,o),m=t.sub(l).sub(u)):m=t.sub(l);let d=X.protocolFee(l,s),f=X.protocolFee(l,a),g=_e.swapBaseInputWithoutFees(m,n,i),b;return c?b=g:(u=X.creatorFee(g,o),b=g.sub(u)),{newInputVaultAmount:n.add(m),newOutputVaultAmount:i.sub(g),inputAmount:t,outputAmount:b,tradeFee:l,protocolFee:d,fundFee:f,creatorFee:u}}static swapBaseOutput(t,n,i,r,o,s,a,c){let u,l=new _n(0),m;if(c)m=t;else{let h=X.calculatePreFeeAmount(t,o);l=h.sub(t),m=h}let d=_e.swapBaseOutputWithoutFees(m,n,i),f;if(c){let h=X.calculatePreFeeAmount(d,r.add(o)),B=h.sub(d);l=X.splitCreatorFee(B,r,o),u=B.sub(l),f=h}else{let h=X.calculatePreFeeAmount(d,r);u=h.sub(d),f=h}let g=X.protocolFee(u,s),b=X.fundFee(u,a);return{newInputVaultAmount:n.add(d),newOutputVaultAmount:t.sub(m),inputAmount:f,outputAmount:t,tradeFee:u,protocolFee:g,fundFee:b,creatorFee:l}}};export{_e as ConstantProductCurve,ss as CpmmConfigInfoLayout,X as CpmmFee,us as CpmmPermission,as as CpmmPoolInfoLayout,Dn as CurveCalculator,ri as FeeOn,Or as LOCK_LIQUIDITY_SEED,Vn as RoundDirection,ro as TradeDirection,oo as TradeDirectionOpposite,Uf as collectCpFeeInstruction,to as cpmmLockPositionInstruction,xn as getCpLockPda,Ml as getCpmmPdaAmmConfigId,Lt as getCpmmPdaPoolId,Fl as getCreatePoolKeys,Rr as getPdaLpMint,Mr as getPdaObservationId,Ol as getPdaPermissionId,Lr as getPdaPoolAuthority,Bn as getPdaVault,Hf as initializeWithPermission,Xf as makeCollectCreatorFeeInstruction,Gf as makeCpmmLockInstruction,vf as makeCreateCpmmPoolInInstruction,Vf as makeDepositCpmmInInstruction,Df as makeSwapCpmmBaseInInstruction,qf as makeSwapCpmmBaseOutInstruction,_f as makeWithdrawCpmmInInstruction};
//# sourceMappingURL=index.mjs.map