@raydium-io/raydium-sdk-v2
Version:
An SDK for building applications on top of Raydium.
2 lines • 135 kB
JavaScript
var jr=Object.defineProperty,Qr=Object.defineProperties;var Jr=Object.getOwnPropertyDescriptors;var Ht=Object.getOwnPropertySymbols;var vi=Object.prototype.hasOwnProperty,Ei=Object.prototype.propertyIsEnumerable;var Mi=(n,e,t)=>e in n?jr(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,H=(n,e)=>{for(var t in e||(e={}))vi.call(e,t)&&Mi(n,t,e[t]);if(Ht)for(var t of Ht(e))Ei.call(e,t)&&Mi(n,t,e[t]);return n},Q=(n,e)=>Qr(n,Jr(e));var tt=(n,e)=>{var t={};for(var i in n)vi.call(n,i)&&e.indexOf(i)<0&&(t[i]=n[i]);if(n!=null&&Ht)for(var i of Ht(n))e.indexOf(i)<0&&Ei.call(n,i)&&(t[i]=n[i]);return t};import{get as Oi,set as $r}from"lodash";var Bn=class{constructor(e){this.logLevel=e.logLevel!==void 0?e.logLevel:0,this.name=e.name}set level(e){this.logLevel=e}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(e){return e<=this.logLevel}error(...e){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...e),this):this}logWithError(...e){let t=e.map(i=>typeof i=="object"?JSON.stringify(i):i).join(", ");throw new Error(t)}warning(...e){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...e),this):this}info(...e){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...e),this):this}debug(...e){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...e),this):this}},Di={},eo={};function pe(n){let e=Oi(Di,n);if(!e){let t=Oi(eo,n);e=new Bn({name:n,logLevel:t}),$r(Di,n,e)}return e}import{PublicKey as wt,sendAndConfirmTransaction as Zn,SystemProgram as Bs,Transaction as Ot,TransactionMessage as Dt,VersionedTransaction as Wt}from"@solana/web3.js";import xs from"axios";import{PublicKey as Xn,AddressLookupTableAccount as Pt}from"@solana/web3.js";import{PublicKey as hs}from"@solana/web3.js";import Ee from"bn.js";var dt=9e15,Ze=1e9,xn="0123456789abcdef",Zt="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",jt="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",In={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-dt,maxE:dt,crypto:!1},qi,_e,U=!0,Jt="[DecimalError] ",Ye=Jt+"Invalid argument: ",Gi=Jt+"Precision limit exceeded",Ui=Jt+"crypto unavailable",Xi="[object Decimal]",fe=Math.floor,ce=Math.pow,to=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,no=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,io=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,zi=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Re=1e7,_=7,ro=9007199254740991,oo=Zt.length-1,Sn=jt.length-1,T={toStringTag:Xi};T.absoluteValue=T.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),v(n)};T.ceil=function(){return v(new this.constructor(this),this.e+1,2)};T.clampedTo=T.clamp=function(n,e){var t,i=this,r=i.constructor;if(n=new r(n),e=new r(e),!n.s||!e.s)return new r(NaN);if(n.gt(e))throw Error(Ye+e);return t=i.cmp(n),t<0?n:i.cmp(e)>0?e:new r(i)};T.comparedTo=T.cmp=function(n){var e,t,i,r,o=this,s=o.d,a=(n=new o.constructor(n)).d,c=o.s,u=n.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!==n.e)return o.e>n.e^c<0?1:-1;for(i=s.length,r=a.length,e=0,t=i<r?i:r;e<t;++e)if(s[e]!==a[e])return s[e]>a[e]^c<0?1:-1;return i===r?0:i>r^c<0?1:-1};T.cosine=T.cos=function(){var n,e,t=this,i=t.constructor;return t.d?t.d[0]?(n=i.precision,e=i.rounding,i.precision=n+Math.max(t.e,t.sd())+_,i.rounding=1,t=so(i,Qi(i,t)),i.precision=n,i.rounding=e,v(_e==2||_e==3?t.neg():t,n,e,!0)):new i(1):new i(NaN)};T.cubeRoot=T.cbrt=function(){var n,e,t,i,r,o,s,a,c,u,l=this,m=l.constructor;if(!l.isFinite()||l.isZero())return new m(l);for(U=!1,o=l.s*ce(l.s*l,1/3),!o||Math.abs(o)==1/0?(t=de(l.d),n=l.e,(o=(n-t.length+1)%3)&&(t+=o==1||o==-2?"0":"00"),o=ce(t,1/3),n=fe((n+1)/3)-(n%3==(n<0?-1:2)),o==1/0?t="5e"+n:(t=o.toExponential(),t=t.slice(0,t.indexOf("e")+1)+n),i=new m(t),i.s=l.s):i=new m(o.toString()),s=(n=m.precision)+3;;)if(a=i,c=a.times(a).times(a),u=c.plus(l),i=$(u.plus(l).times(a),u.plus(c),s+2,1),de(a.d).slice(0,s)===(t=de(i.d)).slice(0,s))if(t=t.slice(s-3,s+1),t=="9999"||!r&&t=="4999"){if(!r&&(v(a,n+1,0),a.times(a).times(a).eq(l))){i=a;break}s+=4,r=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(v(i,n+1,1),e=!i.times(i).times(i).eq(l));break}return U=!0,v(i,n,m.rounding,e)};T.decimalPlaces=T.dp=function(){var n,e=this.d,t=NaN;if(e){if(n=e.length-1,t=(n-fe(this.e/_))*_,n=e[n],n)for(;n%10==0;n/=10)t--;t<0&&(t=0)}return t};T.dividedBy=T.div=function(n){return $(this,new this.constructor(n))};T.dividedToIntegerBy=T.divToInt=function(n){var e=this,t=e.constructor;return v($(e,new t(n),0,1,1),t.precision,t.rounding)};T.equals=T.eq=function(n){return this.cmp(n)===0};T.floor=function(){return v(new this.constructor(this),this.e+1,3)};T.greaterThan=T.gt=function(n){return this.cmp(n)>0};T.greaterThanOrEqualTo=T.gte=function(n){var e=this.cmp(n);return e==1||e===0};T.hyperbolicCosine=T.cosh=function(){var n,e,t,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;t=s.precision,i=s.rounding,s.precision=t+Math.max(o.e,o.sd())+4,s.rounding=1,r=o.d.length,r<32?(n=Math.ceil(r/3),e=(1/en(4,n)).toString()):(n=16,e="2.3283064365386962890625e-10"),o=pt(s,1,o.times(e),new s(1),!0);for(var c,u=n,l=new s(8);u--;)c=o.times(o),o=a.minus(c.times(l.minus(c.times(l))));return v(o,s.precision=t,s.rounding=i,!0)};T.hyperbolicSine=T.sinh=function(){var n,e,t,i,r=this,o=r.constructor;if(!r.isFinite()||r.isZero())return new o(r);if(e=o.precision,t=o.rounding,o.precision=e+Math.max(r.e,r.sd())+4,o.rounding=1,i=r.d.length,i<3)r=pt(o,2,r,r,!0);else{n=1.4*Math.sqrt(i),n=n>16?16:n|0,r=r.times(1/en(5,n)),r=pt(o,2,r,r,!0);for(var s,a=new o(5),c=new o(16),u=new o(20);n--;)s=r.times(r),r=r.times(a.plus(s.times(c.times(s).plus(u))))}return o.precision=e,o.rounding=t,v(r,e,t,!0)};T.hyperbolicTangent=T.tanh=function(){var n,e,t=this,i=t.constructor;return t.isFinite()?t.isZero()?new i(t):(n=i.precision,e=i.rounding,i.precision=n+7,i.rounding=1,$(t.sinh(),t.cosh(),i.precision=n,i.rounding=e)):new i(t.s)};T.inverseCosine=T.acos=function(){var n,e=this,t=e.constructor,i=e.abs().cmp(1),r=t.precision,o=t.rounding;return i!==-1?i===0?e.isNeg()?Ne(t,r,o):new t(0):new t(NaN):e.isZero()?Ne(t,r+4,o).times(.5):(t.precision=r+6,t.rounding=1,e=e.asin(),n=Ne(t,r+4,o).times(.5),t.precision=r,t.rounding=o,n.minus(e))};T.inverseHyperbolicCosine=T.acosh=function(){var n,e,t=this,i=t.constructor;return t.lte(1)?new i(t.eq(1)?0:NaN):t.isFinite()?(n=i.precision,e=i.rounding,i.precision=n+Math.max(Math.abs(t.e),t.sd())+4,i.rounding=1,U=!1,t=t.times(t).minus(1).sqrt().plus(t),U=!0,i.precision=n,i.rounding=e,t.ln()):new i(t)};T.inverseHyperbolicSine=T.asinh=function(){var n,e,t=this,i=t.constructor;return!t.isFinite()||t.isZero()?new i(t):(n=i.precision,e=i.rounding,i.precision=n+2*Math.max(Math.abs(t.e),t.sd())+6,i.rounding=1,U=!1,t=t.times(t).plus(1).sqrt().plus(t),U=!0,i.precision=n,i.rounding=e,t.ln())};T.inverseHyperbolicTangent=T.atanh=function(){var n,e,t,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):(n=o.precision,e=o.rounding,i=r.sd(),Math.max(i,n)<2*-r.e-1?v(new o(r),n,e,!0):(o.precision=t=i-r.e,r=$(r.plus(1),new o(1).minus(r),t+n,1),o.precision=n+4,o.rounding=1,r=r.ln(),o.precision=n,o.rounding=e,r.times(.5))):new o(NaN)};T.inverseSine=T.asin=function(){var n,e,t,i,r=this,o=r.constructor;return r.isZero()?new o(r):(e=r.abs().cmp(1),t=o.precision,i=o.rounding,e!==-1?e===0?(n=Ne(o,t+4,i).times(.5),n.s=r.s,n):new o(NaN):(o.precision=t+6,o.rounding=1,r=r.div(new o(1).minus(r.times(r)).sqrt().plus(1)).atan(),o.precision=t,o.rounding=i,r.times(2)))};T.inverseTangent=T.atan=function(){var n,e,t,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<=Sn)return s=Ne(l,m+4,d).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(m+4<=Sn)return s=Ne(l,m+4,d).times(.5),s.s=u.s,s}for(l.precision=a=m+10,l.rounding=1,t=Math.min(28,a/_+2|0),n=t;n;--n)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(U=!1,e=Math.ceil(a/_),i=1,c=u.times(u),s=new l(u),r=u;n!==-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[e]!==void 0)for(n=e;s.d[n]===o.d[n]&&n--;);return t&&(s=s.times(2<<t-1)),U=!0,v(s,l.precision=m,l.rounding=d,!0)};T.isFinite=function(){return!!this.d};T.isInteger=T.isInt=function(){return!!this.d&&fe(this.e/_)>this.d.length-2};T.isNaN=function(){return!this.s};T.isNegative=T.isNeg=function(){return this.s<0};T.isPositive=T.isPos=function(){return this.s>0};T.isZero=function(){return!!this.d&&this.d[0]===0};T.lessThan=T.lt=function(n){return this.cmp(n)<0};T.lessThanOrEqualTo=T.lte=function(n){return this.cmp(n)<1};T.logarithm=T.log=function(n){var e,t,i,r,o,s,a,c,u=this,l=u.constructor,m=l.precision,d=l.rounding,p=5;if(n==null)n=new l(10),e=!0;else{if(n=new l(n),t=n.d,n.s<0||!t||!t[0]||n.eq(1))return new l(NaN);e=n.eq(10)}if(t=u.d,u.s<0||!t||!t[0]||u.eq(1))return new l(t&&!t[0]?-1/0:u.s!=1?NaN:t?0:1/0);if(e)if(t.length>1)o=!0;else{for(r=t[0];r%10===0;)r/=10;o=r!==1}if(U=!1,a=m+p,s=He(u,a),i=e?Qt(l,a+10):He(n,a),c=$(s,i,a,1),St(c.d,r=m,d))do if(a+=10,s=He(u,a),i=e?Qt(l,a+10):He(n,a),c=$(s,i,a,1),!o){+de(c.d).slice(r+1,r+15)+1==1e14&&(c=v(c,m+1,0));break}while(St(c.d,r+=10,d));return U=!0,v(c,m,d)};T.minus=T.sub=function(n){var e,t,i,r,o,s,a,c,u,l,m,d,p=this,f=p.constructor;if(n=new f(n),!p.d||!n.d)return!p.s||!n.s?n=new f(NaN):p.d?n.s=-n.s:n=new f(n.d||p.s!==n.s?p:NaN),n;if(p.s!=n.s)return n.s=-n.s,p.plus(n);if(u=p.d,d=n.d,a=f.precision,c=f.rounding,!u[0]||!d[0]){if(d[0])n.s=-n.s;else if(u[0])n=new f(p);else return new f(c===3?-0:0);return U?v(n,a,c):n}if(t=fe(n.e/_),l=fe(p.e/_),u=u.slice(),o=l-t,o){for(m=o<0,m?(e=u,o=-o,s=d.length):(e=d,t=l,s=u.length),i=Math.max(Math.ceil(a/_),s)+2,o>i&&(o=i,e.length=1),e.reverse(),i=o;i--;)e.push(0);e.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&&(e=u,u=d,d=e,n.s=-n.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]=Re-1;--u[r],u[i]+=Re}u[i]-=d[i]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--t;return u[0]?(n.d=u,n.e=$t(u,t),U?v(n,a,c):n):new f(c===3?-0:0)};T.modulo=T.mod=function(n){var e,t=this,i=t.constructor;return n=new i(n),!t.d||!n.s||n.d&&!n.d[0]?new i(NaN):!n.d||t.d&&!t.d[0]?v(new i(t),i.precision,i.rounding):(U=!1,i.modulo==9?(e=$(t,n.abs(),0,3,1),e.s*=n.s):e=$(t,n,0,i.modulo,1),e=e.times(n),U=!0,t.minus(e))};T.naturalExponential=T.exp=function(){return Cn(this)};T.naturalLogarithm=T.ln=function(){return He(this)};T.negated=T.neg=function(){var n=new this.constructor(this);return n.s=-n.s,v(n)};T.plus=T.add=function(n){var e,t,i,r,o,s,a,c,u,l,m=this,d=m.constructor;if(n=new d(n),!m.d||!n.d)return!m.s||!n.s?n=new d(NaN):m.d||(n=new d(n.d||m.s===n.s?m:NaN)),n;if(m.s!=n.s)return n.s=-n.s,m.minus(n);if(u=m.d,l=n.d,a=d.precision,c=d.rounding,!u[0]||!l[0])return l[0]||(n=new d(m)),U?v(n,a,c):n;if(o=fe(m.e/_),i=fe(n.e/_),u=u.slice(),r=o-i,r){for(r<0?(t=u,r=-r,s=l.length):(t=l,i=o,s=u.length),o=Math.ceil(a/_),s=o>s?o+1:s+1,r>s&&(r=s,t.length=1),t.reverse();r--;)t.push(0);t.reverse()}for(s=u.length,r=l.length,s-r<0&&(r=s,t=l,l=u,u=t),e=0;r;)e=(u[--r]=u[r]+l[r]+e)/Re|0,u[r]%=Re;for(e&&(u.unshift(e),++i),s=u.length;u[--s]==0;)u.pop();return n.d=u,n.e=$t(u,i),U?v(n,a,c):n};T.precision=T.sd=function(n){var e,t=this;if(n!==void 0&&n!==!!n&&n!==1&&n!==0)throw Error(Ye+n);return t.d?(e=Hi(t.d),n&&t.e+1>e&&(e=t.e+1)):e=NaN,e};T.round=function(){var n=this,e=n.constructor;return v(new e(n),n.e+1,e.rounding)};T.sine=T.sin=function(){var n,e,t=this,i=t.constructor;return t.isFinite()?t.isZero()?new i(t):(n=i.precision,e=i.rounding,i.precision=n+Math.max(t.e,t.sd())+_,i.rounding=1,t=uo(i,Qi(i,t)),i.precision=n,i.rounding=e,v(_e>2?t.neg():t,n,e,!0)):new i(NaN)};T.squareRoot=T.sqrt=function(){var n,e,t,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(U=!1,u=Math.sqrt(+s),u==0||u==1/0?(e=de(a),(e.length+c)%2==0&&(e+="0"),u=Math.sqrt(e),c=fe((c+1)/2)-(c<0||c%2),u==1/0?e="5e"+c:(e=u.toExponential(),e=e.slice(0,e.indexOf("e")+1)+c),i=new l(e)):i=new l(u.toString()),t=(c=l.precision)+3;;)if(o=i,i=o.plus($(s,o,t+2,1)).times(.5),de(o.d).slice(0,t)===(e=de(i.d)).slice(0,t))if(e=e.slice(t-3,t+1),e=="9999"||!r&&e=="4999"){if(!r&&(v(o,c+1,0),o.times(o).eq(s))){i=o;break}t+=4,r=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(v(i,c+1,1),n=!i.times(i).eq(s));break}return U=!0,v(i,c,l.rounding,n)};T.tangent=T.tan=function(){var n,e,t=this,i=t.constructor;return t.isFinite()?t.isZero()?new i(t):(n=i.precision,e=i.rounding,i.precision=n+10,i.rounding=1,t=t.sin(),t.s=1,t=$(t,new i(1).minus(t.times(t)).sqrt(),n+10,0),i.precision=n,i.rounding=e,v(_e==2||_e==4?t.neg():t,n,e,!0)):new i(NaN)};T.times=T.mul=function(n){var e,t,i,r,o,s,a,c,u,l=this,m=l.constructor,d=l.d,p=(n=new m(n)).d;if(n.s*=l.s,!d||!d[0]||!p||!p[0])return new m(!n.s||d&&!d[0]&&!p||p&&!p[0]&&!d?NaN:!d||!p?n.s/0:n.s*0);for(t=fe(l.e/_)+fe(n.e/_),c=d.length,u=p.length,c<u&&(o=d,d=p,p=o,s=c,c=u,u=s),o=[],s=c+u,i=s;i--;)o.push(0);for(i=u;--i>=0;){for(e=0,r=c+i;r>i;)a=o[r]+p[i]*d[r-i-1]+e,o[r--]=a%Re|0,e=a/Re|0;o[r]=(o[r]+e)%Re|0}for(;!o[--s];)o.pop();return e?++t:o.shift(),n.d=o,n.e=$t(o,t),U?v(n,m.precision,m.rounding):n};T.toBinary=function(n,e){return Nn(this,2,n,e)};T.toDecimalPlaces=T.toDP=function(n,e){var t=this,i=t.constructor;return t=new i(t),n===void 0?t:(Pe(n,0,Ze),e===void 0?e=i.rounding:Pe(e,0,8),v(t,n+t.e+1,e))};T.toExponential=function(n,e){var t,i=this,r=i.constructor;return n===void 0?t=Me(i,!0):(Pe(n,0,Ze),e===void 0?e=r.rounding:Pe(e,0,8),i=v(new r(i),n+1,e),t=Me(i,!0,n+1)),i.isNeg()&&!i.isZero()?"-"+t:t};T.toFixed=function(n,e){var t,i,r=this,o=r.constructor;return n===void 0?t=Me(r):(Pe(n,0,Ze),e===void 0?e=o.rounding:Pe(e,0,8),i=v(new o(r),n+r.e+1,e),t=Me(i,!1,n+i.e+1)),r.isNeg()&&!r.isZero()?"-"+t:t};T.toFraction=function(n){var e,t,i,r,o,s,a,c,u,l,m,d,p=this,f=p.d,b=p.constructor;if(!f)return new b(p);if(u=t=new b(1),i=c=new b(0),e=new b(i),o=e.e=Hi(f)-p.e-1,s=o%_,e.d[0]=ce(10,s<0?_+s:s),n==null)n=o>0?e:u;else{if(a=new b(n),!a.isInt()||a.lt(u))throw Error(Ye+a);n=a.gt(e)?o>0?e:u:a}for(U=!1,a=new b(de(f)),l=b.precision,b.precision=o=f.length*_*2;m=$(a,e,0,1,1),r=t.plus(m.times(i)),r.cmp(n)!=1;)t=i,i=r,r=u,u=c.plus(m.times(r)),c=r,r=e,e=a.minus(m.times(r)),a=r;return r=$(n.minus(t),i,0,1,1),c=c.plus(r.times(u)),t=t.plus(r.times(i)),c.s=u.s=p.s,d=$(u,i,o,1).minus(p).abs().cmp($(c,t,o,1).minus(p).abs())<1?[u,i]:[c,t],b.precision=l,U=!0,d};T.toHexadecimal=T.toHex=function(n,e){return Nn(this,16,n,e)};T.toNearest=function(n,e){var t=this,i=t.constructor;if(t=new i(t),n==null){if(!t.d)return t;n=new i(1),e=i.rounding}else{if(n=new i(n),e===void 0?e=i.rounding:Pe(e,0,8),!t.d)return n.s?t:n;if(!n.d)return n.s&&(n.s=t.s),n}return n.d[0]?(U=!1,t=$(t,n,0,e,1).times(n),U=!0,v(t)):(n.s=t.s,t=n),t};T.toNumber=function(){return+this};T.toOctal=function(n,e){return Nn(this,8,n,e)};T.toPower=T.pow=function(n){var e,t,i,r,o,s,a=this,c=a.constructor,u=+(n=new c(n));if(!a.d||!n.d||!a.d[0]||!n.d[0])return new c(ce(+a,u));if(a=new c(a),a.eq(1))return a;if(i=c.precision,o=c.rounding,n.eq(1))return v(a,i,o);if(e=fe(n.e/_),e>=n.d.length-1&&(t=u<0?-u:u)<=ro)return r=Yi(c,a,t,i),n.s<0?new c(1).div(r):v(r,i,o);if(s=a.s,s<0){if(e<n.d.length-1)return new c(NaN);if((n.d[e]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return t=ce(+a,u),e=t==0||!isFinite(t)?fe(u*(Math.log("0."+de(a.d))/Math.LN10+a.e+1)):new c(t+"").e,e>c.maxE+1||e<c.minE-1?new c(e>0?s/0:0):(U=!1,c.rounding=a.s=1,t=Math.min(12,(e+"").length),r=Cn(n.times(He(a,i+t)),i),r.d&&(r=v(r,i+5,1),St(r.d,i,o)&&(e=i+10,r=v(Cn(n.times(He(a,e+t)),e),e+5,1),+de(r.d).slice(i+1,i+15)+1==1e14&&(r=v(r,i+1,0)))),r.s=s,U=!0,c.rounding=o,v(r,i,o))};T.toPrecision=function(n,e){var t,i=this,r=i.constructor;return n===void 0?t=Me(i,i.e<=r.toExpNeg||i.e>=r.toExpPos):(Pe(n,1,Ze),e===void 0?e=r.rounding:Pe(e,0,8),i=v(new r(i),n,e),t=Me(i,n<=i.e||i.e<=r.toExpNeg,n)),i.isNeg()&&!i.isZero()?"-"+t:t};T.toSignificantDigits=T.toSD=function(n,e){var t=this,i=t.constructor;return n===void 0?(n=i.precision,e=i.rounding):(Pe(n,1,Ze),e===void 0?e=i.rounding:Pe(e,0,8)),v(new i(t),n,e)};T.toString=function(){var n=this,e=n.constructor,t=Me(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()&&!n.isZero()?"-"+t:t};T.truncated=T.trunc=function(){return v(new this.constructor(this),this.e+1,1)};T.valueOf=T.toJSON=function(){var n=this,e=n.constructor,t=Me(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()?"-"+t:t};function de(n){var e,t,i,r=n.length-1,o="",s=n[0];if(r>0){for(o+=s,e=1;e<r;e++)i=n[e]+"",t=_-i.length,t&&(o+=ze(t)),o+=i;s=n[e],i=s+"",t=_-i.length,t&&(o+=ze(t))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function Pe(n,e,t){if(n!==~~n||n<e||n>t)throw Error(Ye+n)}function St(n,e,t,i){var r,o,s,a;for(o=n[0];o>=10;o/=10)--e;return--e<0?(e+=_,r=0):(r=Math.ceil((e+1)/_),e%=_),o=ce(10,_-e),a=n[r]%o|0,i==null?e<3?(e==0?a=a/100|0:e==1&&(a=a/10|0),s=t<4&&a==99999||t>3&&a==49999||a==5e4||a==0):s=(t<4&&a+1==o||t>3&&a+1==o/2)&&(n[r+1]/o/100|0)==ce(10,e-2)-1||(a==o/2||a==0)&&(n[r+1]/o/100|0)==0:e<4?(e==0?a=a/1e3|0:e==1?a=a/100|0:e==2&&(a=a/10|0),s=(i||t<4)&&a==9999||!i&&t>3&&a==4999):s=((i||t<4)&&a+1==o||!i&&t>3&&a+1==o/2)&&(n[r+1]/o/1e3|0)==ce(10,e-3)-1,s}function Yt(n,e,t){for(var i,r=[0],o,s=0,a=n.length;s<a;){for(o=r.length;o--;)r[o]*=e;for(r[0]+=xn.indexOf(n.charAt(s++)),i=0;i<r.length;i++)r[i]>t-1&&(r[i+1]===void 0&&(r[i+1]=0),r[i+1]+=r[i]/t|0,r[i]%=t)}return r.reverse()}function so(n,e){var t,i,r;if(e.isZero())return e;i=e.d.length,i<32?(t=Math.ceil(i/3),r=(1/en(4,t)).toString()):(t=16,r="2.3283064365386962890625e-10"),n.precision+=t,e=pt(n,1,e.times(r),new n(1));for(var o=t;o--;){var s=e.times(e);e=s.times(s).minus(s).times(8).plus(1)}return n.precision-=t,e}var $=function(){function n(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 e(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 t(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,p,f,b,g,w,A,B,k,P,h,C,I,N,F,S,M,V=i.constructor,X=i.s==r.s?1:-1,x=i.d,K=r.d;if(!x||!x[0]||!K||!K[0])return new V(!i.s||!r.s||(x?K&&x[0]==K[0]:!K)?NaN:x&&x[0]==0||!K?X*0:X/0);for(c?(p=1,l=i.e-r.e):(c=Re,p=_,l=fe(i.e/p)-fe(r.e/p)),S=K.length,N=x.length,w=new V(X),A=w.d=[],m=0;K[m]==(x[m]||0);m++);if(K[m]>(x[m]||0)&&l--,o==null?(h=o=V.precision,s=V.rounding):a?h=o+(i.e-r.e)+1:h=o,h<0)A.push(1),f=!0;else{if(h=h/p+2|0,m=0,S==1){for(d=0,K=K[0],h++;(m<N||d)&&h--;m++)C=d*c+(x[m]||0),A[m]=C/K|0,d=C%K|0;f=d||m<N}else{for(d=c/(K[0]+1)|0,d>1&&(K=n(K,d,c),x=n(x,d,c),S=K.length,N=x.length),I=S,B=x.slice(0,S),k=B.length;k<S;)B[k++]=0;M=K.slice(),M.unshift(0),F=K[0],K[1]>=c/2&&++F;do d=0,u=e(K,B,S,k),u<0?(P=B[0],S!=k&&(P=P*c+(B[1]||0)),d=P/F|0,d>1?(d>=c&&(d=c-1),b=n(K,d,c),g=b.length,k=B.length,u=e(b,B,g,k),u==1&&(d--,t(b,S<g?M:K,g,c))):(d==0&&(u=d=1),b=K.slice()),g=b.length,g<k&&b.unshift(0),t(B,b,k,c),u==-1&&(k=B.length,u=e(K,B,S,k),u<1&&(d++,t(B,S<k?M:K,k,c))),k=B.length):u===0&&(d++,B=[0]),A[m++]=d,u&&B[0]?B[k++]=x[I]||0:(B=[x[I]],k=1);while((I++<N||B[0]!==void 0)&&h--);f=B[0]!==void 0}A[0]||A.shift()}if(p==1)w.e=l,qi=f;else{for(m=1,d=A[0];d>=10;d/=10)m++;w.e=m+l*p-1,v(w,a?o+w.e+1:o,s,f)}return w}}();function v(n,e,t,i){var r,o,s,a,c,u,l,m,d,p=n.constructor;e:if(e!=null){if(m=n.d,!m)return n;for(r=1,a=m[0];a>=10;a/=10)r++;if(o=e-r,o<0)o+=_,s=e,l=m[d=0],c=l/ce(10,r-s-1)%10|0;else if(d=Math.ceil((o+1)/_),a=m.length,d>=a)if(i){for(;a++<=d;)m.push(0);l=c=0,r=1,o%=_,s=o-_+1}else break e;else{for(l=a=m[d],r=1;a>=10;a/=10)r++;o%=_,s=o-_+r,c=s<0?0:l/ce(10,r-s-1)%10|0}if(i=i||e<0||m[d+1]!==void 0||(s<0?l:l%ce(10,r-s-1)),u=t<4?(c||i)&&(t==0||t==(n.s<0?3:2)):c>5||c==5&&(t==4||i||t==6&&(o>0?s>0?l/ce(10,r-s):0:m[d-1])%10&1||t==(n.s<0?8:7)),e<1||!m[0])return m.length=0,u?(e-=n.e+1,m[0]=ce(10,(_-e%_)%_),n.e=-e||0):m[0]=n.e=0,n;if(o==0?(m.length=d,a=1,d--):(m.length=d+1,a=ce(10,_-o),m[d]=s>0?(l/ce(10,r-s)%ce(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&&(n.e++,m[0]==Re&&(m[0]=1));break}else{if(m[d]+=a,m[d]!=Re)break;m[d--]=0,a=1}for(o=m.length;m[--o]===0;)m.pop()}return U&&(n.e>p.maxE?(n.d=null,n.e=NaN):n.e<p.minE&&(n.e=0,n.d=[0])),n}function Me(n,e,t){if(!n.isFinite())return ji(n);var i,r=n.e,o=de(n.d),s=o.length;return e?(t&&(i=t-s)>0?o=o.charAt(0)+"."+o.slice(1)+ze(i):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(n.e<0?"e":"e+")+n.e):r<0?(o="0."+ze(-r-1)+o,t&&(i=t-s)>0&&(o+=ze(i))):r>=s?(o+=ze(r+1-s),t&&(i=t-r-1)>0&&(o=o+"."+ze(i))):((i=r+1)<s&&(o=o.slice(0,i)+"."+o.slice(i)),t&&(i=t-s)>0&&(r+1===s&&(o+="."),o+=ze(i))),o}function $t(n,e){var t=n[0];for(e*=_;t>=10;t/=10)e++;return e}function Qt(n,e,t){if(e>oo)throw U=!0,t&&(n.precision=t),Error(Gi);return v(new n(Zt),e,1,!0)}function Ne(n,e,t){if(e>Sn)throw Error(Gi);return v(new n(jt),e,t,!0)}function Hi(n){var e=n.length-1,t=e*_+1;if(e=n[e],e){for(;e%10==0;e/=10)t--;for(e=n[0];e>=10;e/=10)t++}return t}function ze(n){for(var e="";n--;)e+="0";return e}function Yi(n,e,t,i){var r,o=new n(1),s=Math.ceil(i/_+4);for(U=!1;;){if(t%2&&(o=o.times(e),Vi(o.d,s)&&(r=!0)),t=fe(t/2),t===0){t=o.d.length-1,r&&o.d[t]===0&&++o.d[t];break}e=e.times(e),Vi(e.d,s)}return U=!0,o}function Wi(n){return n.d[n.d.length-1]&1}function Zi(n,e,t){for(var i,r=new n(e[0]),o=0;++o<e.length;)if(i=new n(e[o]),i.s)r[t](i)&&(r=i);else{r=i;break}return r}function Cn(n,e){var t,i,r,o,s,a,c,u=0,l=0,m=0,d=n.constructor,p=d.rounding,f=d.precision;if(!n.d||!n.d[0]||n.e>17)return new d(n.d?n.d[0]?n.s<0?0:1/0:1:n.s?n.s<0?0:n:0/0);for(e==null?(U=!1,c=f):c=e,a=new d(.03125);n.e>-2;)n=n.times(a),m+=5;for(i=Math.log(ce(2,m))/Math.LN10*2+5|0,c+=i,t=o=s=new d(1),d.precision=c;;){if(o=v(o.times(n),c,1),t=t.times(++l),a=s.plus($(o,t,c,1)),de(a.d).slice(0,c)===de(s.d).slice(0,c)){for(r=m;r--;)s=v(s.times(s),c,1);if(e==null)if(u<3&&St(s.d,c-i,p,u))d.precision=c+=10,t=o=a=new d(1),l=0,u++;else return v(s,d.precision=f,p,U=!0);else return d.precision=f,s}s=a}}function He(n,e){var t,i,r,o,s,a,c,u,l,m,d,p=1,f=10,b=n,g=b.d,w=b.constructor,A=w.rounding,B=w.precision;if(b.s<0||!g||!g[0]||!b.e&&g[0]==1&&g.length==1)return new w(g&&!g[0]?-1/0:b.s!=1?NaN:g?0:b);if(e==null?(U=!1,l=B):l=e,w.precision=l+=f,t=de(g),i=t.charAt(0),Math.abs(o=b.e)<15e14){for(;i<7&&i!=1||i==1&&t.charAt(1)>3;)b=b.times(n),t=de(b.d),i=t.charAt(0),p++;o=b.e,i>1?(b=new w("0."+t),o++):b=new w(i+"."+t.slice(1))}else return u=Qt(w,l+2,B).times(o+""),b=He(new w(i+"."+t.slice(1)),l-f).plus(u),w.precision=B,e==null?v(b,B,A,U=!0):b;for(m=b,c=s=b=$(b.minus(1),b.plus(1),l,1),d=v(b.times(b),l,1),r=3;;){if(s=v(s.times(d),l,1),u=c.plus($(s,new w(r),l,1)),de(u.d).slice(0,l)===de(c.d).slice(0,l))if(c=c.times(2),o!==0&&(c=c.plus(Qt(w,l+2,B).times(o+""))),c=$(c,new w(p),l,1),e==null)if(St(c.d,l-f,A,a))w.precision=l+=f,u=s=b=$(m.minus(1),m.plus(1),l,1),d=v(b.times(b),l,1),r=a=1;else return v(c,w.precision=B,A,U=!0);else return w.precision=B,c;c=u,r+=2}}function ji(n){return String(n.s*n.s/0)}function Kn(n,e){var t,i,r;for((t=e.indexOf("."))>-1&&(e=e.replace(".","")),(i=e.search(/e/i))>0?(t<0&&(t=i),t+=+e.slice(i+1),e=e.substring(0,i)):t<0&&(t=e.length),i=0;e.charCodeAt(i)===48;i++);for(r=e.length;e.charCodeAt(r-1)===48;--r);if(e=e.slice(i,r),e){if(r-=i,n.e=t=t-i-1,n.d=[],i=(t+1)%_,t<0&&(i+=_),i<r){for(i&&n.d.push(+e.slice(0,i)),r-=_;i<r;)n.d.push(+e.slice(i,i+=_));e=e.slice(i),i=_-e.length}else i-=r;for(;i--;)e+="0";n.d.push(+e),U&&(n.e>n.constructor.maxE?(n.d=null,n.e=NaN):n.e<n.constructor.minE&&(n.e=0,n.d=[0]))}else n.e=0,n.d=[0];return n}function ao(n,e){var t,i,r,o,s,a,c,u,l;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),zi.test(e))return Kn(n,e)}else if(e==="Infinity"||e==="NaN")return+e||(n.s=NaN),n.e=NaN,n.d=null,n;if(no.test(e))t=16,e=e.toLowerCase();else if(to.test(e))t=2;else if(io.test(e))t=8;else throw Error(Ye+e);for(o=e.search(/p/i),o>0?(c=+e.slice(o+1),e=e.substring(2,o)):e=e.slice(2),o=e.indexOf("."),s=o>=0,i=n.constructor,s&&(e=e.replace(".",""),a=e.length,o=a-o,r=Yi(i,new i(t),o,o*2)),u=Yt(e,t,Re),l=u.length-1,o=l;u[o]===0;--o)u.pop();return o<0?new i(n.s*0):(n.e=$t(u,l),n.d=u,U=!1,s&&(n=$(n,r,a*4)),c&&(n=n.times(Math.abs(c)<54?ce(2,c):Ct.pow(2,c))),U=!0,n)}function uo(n,e){var t,i=e.d.length;if(i<3)return e.isZero()?e:pt(n,2,e,e);t=1.4*Math.sqrt(i),t=t>16?16:t|0,e=e.times(1/en(5,t)),e=pt(n,2,e,e);for(var r,o=new n(5),s=new n(16),a=new n(20);t--;)r=e.times(e),e=e.times(o.plus(r.times(s.times(r).minus(a))));return e}function pt(n,e,t,i,r){var o,s,a,c,u=1,l=n.precision,m=Math.ceil(l/_);for(U=!1,c=t.times(t),a=new n(i);;){if(s=$(a.times(c),new n(e++*e++),l,1),a=r?i.plus(s):i.minus(s),i=$(s.times(c),new n(e++*e++),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 U=!0,s.d.length=m+1,s}function en(n,e){for(var t=n;--e;)t*=n;return t}function Qi(n,e){var t,i=e.s<0,r=Ne(n,n.precision,1),o=r.times(.5);if(e=e.abs(),e.lte(o))return _e=i?4:1,e;if(t=e.divToInt(r),t.isZero())_e=i?3:2;else{if(e=e.minus(t.times(r)),e.lte(o))return _e=Wi(t)?i?2:3:i?4:1,e;_e=Wi(t)?i?1:4:i?3:2}return e.minus(r).abs()}function Nn(n,e,t,i){var r,o,s,a,c,u,l,m,d,p=n.constructor,f=t!==void 0;if(f?(Pe(t,1,Ze),i===void 0?i=p.rounding:Pe(i,0,8)):(t=p.precision,i=p.rounding),!n.isFinite())l=ji(n);else{for(l=Me(n),s=l.indexOf("."),f?(r=2,e==16?t=t*4-3:e==8&&(t=t*3-2)):r=e,s>=0&&(l=l.replace(".",""),d=new p(1),d.e=l.length-s,d.d=Yt(Me(d),10,r),d.e=d.d.length),m=Yt(l,10,r),o=c=m.length;m[--c]==0;)m.pop();if(!m[0])l=f?"0p+0":"0";else{if(s<0?o--:(n=new p(n),n.d=m,n.e=o,n=$(n,d,t,i,0,r),m=n.d,o=n.e,u=qi),s=m[t],a=r/2,u=u||m[t+1]!==void 0,u=i<4?(s!==void 0||u)&&(i===0||i===(n.s<0?3:2)):s>a||s===a&&(i===4||u||i===6&&m[t-1]&1||i===(n.s<0?8:7)),m.length=t,u)for(;++m[--t]>r-1;)m[t]=0,t||(++o,m.unshift(1));for(c=m.length;!m[c-1];--c);for(s=0,l="";s<c;s++)l+=xn.charAt(m[s]);if(f){if(c>1)if(e==16||e==8){for(s=e==16?4:3,--c;c%s;c++)l+="0";for(m=Yt(l,r,e),c=m.length;!m[c-1];--c);for(s=1,l="1.";s<c;s++)l+=xn.charAt(m[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)l="0"+l;l="0."+l}else if(++o>c)for(o-=c;o--;)l+="0";else o<c&&(l=l.slice(0,o)+"."+l.slice(o))}l=(e==16?"0x":e==2?"0b":e==8?"0o":"")+l}return n.s<0?"-"+l:l}function Vi(n,e){if(n.length>e)return n.length=e,!0}function co(n){return new this(n).abs()}function lo(n){return new this(n).acos()}function mo(n){return new this(n).acosh()}function po(n,e){return new this(n).plus(e)}function fo(n){return new this(n).asin()}function bo(n){return new this(n).asinh()}function yo(n){return new this(n).atan()}function go(n){return new this(n).atanh()}function Po(n,e){n=new this(n),e=new this(e);var t,i=this.precision,r=this.rounding,o=i+4;return!n.s||!e.s?t=new this(NaN):!n.d&&!e.d?(t=Ne(this,o,1).times(e.s>0?.25:.75),t.s=n.s):!e.d||n.isZero()?(t=e.s<0?Ne(this,i,r):new this(0),t.s=n.s):!n.d||e.isZero()?(t=Ne(this,o,1).times(.5),t.s=n.s):e.s<0?(this.precision=o,this.rounding=1,t=this.atan($(n,e,o,1)),e=Ne(this,o,1),this.precision=i,this.rounding=r,t=n.s<0?t.minus(e):t.plus(e)):t=this.atan($(n,e,o,1)),t}function wo(n){return new this(n).cbrt()}function Ao(n){return v(n=new this(n),n.e+1,2)}function To(n,e,t){return new this(n).clamp(e,t)}function ko(n){if(!n||typeof n!="object")throw Error(Jt+"Object expected");var e,t,i,r=n.defaults===!0,o=["precision",1,Ze,"rounding",0,8,"toExpNeg",-dt,0,"toExpPos",0,dt,"maxE",0,dt,"minE",-dt,0,"modulo",0,9];for(e=0;e<o.length;e+=3)if(t=o[e],r&&(this[t]=In[t]),(i=n[t])!==void 0)if(fe(i)===i&&i>=o[e+1]&&i<=o[e+2])this[t]=i;else throw Error(Ye+t+": "+i);if(t="crypto",r&&(this[t]=In[t]),(i=n[t])!==void 0)if(i===!0||i===!1||i===0||i===1)if(i)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[t]=!0;else throw Error(Ui);else this[t]=!1;else throw Error(Ye+t+": "+i);return this}function ho(n){return new this(n).cos()}function Bo(n){return new this(n).cosh()}function Ji(n){var e,t,i;function r(o){var s,a,c,u=this;if(!(u instanceof r))return new r(o);if(u.constructor=r,_i(o)){u.s=o.s,U?!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++;U?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 Kn(u,o.toString())}else if(c!=="string")throw Error(Ye+o);return(a=o.charCodeAt(0))===45?(o=o.slice(1),u.s=-1):(a===43&&(o=o.slice(1)),u.s=1),zi.test(o)?Kn(u,o):ao(u,o)}if(r.prototype=T,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=ko,r.clone=Ji,r.isDecimal=_i,r.abs=co,r.acos=lo,r.acosh=mo,r.add=po,r.asin=fo,r.asinh=bo,r.atan=yo,r.atanh=go,r.atan2=Po,r.cbrt=wo,r.ceil=Ao,r.clamp=To,r.cos=ho,r.cosh=Bo,r.div=xo,r.exp=Io,r.floor=So,r.hypot=Co,r.ln=Ko,r.log=No,r.log10=Lo,r.log2=Ro,r.max=Fo,r.min=Mo,r.mod=vo,r.mul=Eo,r.pow=Oo,r.random=Do,r.round=Wo,r.sign=Vo,r.sin=_o,r.sinh=qo,r.sqrt=Go,r.sub=Uo,r.sum=Xo,r.tan=zo,r.tanh=Ho,r.trunc=Yo,n===void 0&&(n={}),n&&n.defaults!==!0)for(i=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<i.length;)n.hasOwnProperty(t=i[e++])||(n[t]=this[t]);return r.config(n),r}function xo(n,e){return new this(n).div(e)}function Io(n){return new this(n).exp()}function So(n){return v(n=new this(n),n.e+1,3)}function Co(){var n,e,t=new this(0);for(U=!1,n=0;n<arguments.length;)if(e=new this(arguments[n++]),e.d)t.d&&(t=t.plus(e.times(e)));else{if(e.s)return U=!0,new this(1/0);t=e}return U=!0,t.sqrt()}function _i(n){return n instanceof Ct||n&&n.toStringTag===Xi||!1}function Ko(n){return new this(n).ln()}function No(n,e){return new this(n).log(e)}function Ro(n){return new this(n).log(2)}function Lo(n){return new this(n).log(10)}function Fo(){return Zi(this,arguments,"lt")}function Mo(){return Zi(this,arguments,"gt")}function vo(n,e){return new this(n).mod(e)}function Eo(n,e){return new this(n).mul(e)}function Oo(n,e){return new this(n).pow(e)}function Do(n){var e,t,i,r,o=0,s=new this(1),a=[];if(n===void 0?n=this.precision:Pe(n,1,Ze),i=Math.ceil(n/_),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(i));o<i;)r=e[o],r>=429e7?e[o]=crypto.getRandomValues(new Uint32Array(1))[0]:a[o++]=r%1e7;else if(crypto.randomBytes){for(e=crypto.randomBytes(i*=4);o<i;)r=e[o]+(e[o+1]<<8)+(e[o+2]<<16)+((e[o+3]&127)<<24),r>=214e7?crypto.randomBytes(4).copy(e,o):(a.push(r%1e7),o+=4);o=i/4}else throw Error(Ui);else for(;o<i;)a[o++]=Math.random()*1e7|0;for(i=a[--o],n%=_,i&&n&&(r=ce(10,_-n),a[o]=(i/r|0)*r);a[o]===0;o--)a.pop();if(o<0)t=0,a=[0];else{for(t=-1;a[0]===0;t-=_)a.shift();for(i=1,r=a[0];r>=10;r/=10)i++;i<_&&(t-=_-i)}return s.e=t,s.d=a,s}function Wo(n){return v(n=new this(n),n.e+1,this.rounding)}function Vo(n){return n=new this(n),n.d?n.d[0]?n.s:0*n.s:n.s||NaN}function _o(n){return new this(n).sin()}function qo(n){return new this(n).sinh()}function Go(n){return new this(n).sqrt()}function Uo(n,e){return new this(n).sub(e)}function Xo(){var n=0,e=arguments,t=new this(e[n]);for(U=!1;t.s&&++n<e.length;)t=t.plus(e[n]);return U=!0,v(t,this.precision,this.rounding)}function zo(n){return new this(n).tan()}function Ho(n){return new this(n).tanh()}function Yo(n){return v(n=new this(n),n.e+1,1)}T[Symbol.for("nodejs.util.inspect.custom")]=T.toString;T[Symbol.toStringTag]="Decimal";var Ct=T.constructor=Ji(In);Zt=new Ct(Zt);jt=new Ct(jt);var G=Ct;import ns from"big.js";import Ra from"bn.js";import Zo from"toformat";var jo=Zo,Kt=jo;import nn from"big.js";import Jo from"bn.js";import $o from"decimal.js-light";import Nt from"bn.js";var $i=9007199254740991;function ve(n){let e=pe("Raydium_parseBigNumberish");if(n instanceof Nt)return n;if(typeof n=="string"){if(n.match(/^-?[0-9]+$/))return new Nt(n);e.logWithError(`invalid BigNumberish string: ${n}`)}return typeof n=="number"?(n%1&&e.logWithError(`BigNumberish number underflow: ${n}`),(n>=$i||n<=-$i)&&e.logWithError(`BigNumberish number overflow: ${n}`),new Nt(String(n))):typeof n=="bigint"?new Nt(n.toString()):(e.error(`invalid BigNumberish value: ${n}`),new Nt(0))}var tn=pe("module/fraction"),Rn=Kt(nn),Rt=Kt($o),es={[0]:Rt.ROUND_DOWN,[1]:Rt.ROUND_HALF_UP,[2]:Rt.ROUND_UP},ts={[0]:nn.roundDown,[1]:nn.roundHalfUp,[2]:nn.roundUp},ne=class{constructor(e,t=new Jo(1)){this.numerator=ve(e),this.denominator=ve(t)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new ne(this.denominator,this.numerator)}add(e){let t=e instanceof ne?e:new ne(ve(e));return this.denominator.eq(t.denominator)?new ne(this.numerator.add(t.numerator),this.denominator):new ne(this.numerator.mul(t.denominator).add(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}sub(e){let t=e instanceof ne?e:new ne(ve(e));return this.denominator.eq(t.denominator)?new ne(this.numerator.sub(t.numerator),this.denominator):new ne(this.numerator.mul(t.denominator).sub(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}mul(e){let t=e instanceof ne?e:new ne(ve(e));return new ne(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof ne?e:new ne(ve(e));return new ne(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},i=1){Number.isInteger(e)||tn.logWithError(`${e} is not an integer.`),e<=0&&tn.logWithError(`${e} is not positive.`),Rt.set({precision:e+1,rounding:es[i]});let r=new Rt(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return r.toFormat(r.decimalPlaces(),t)}toFixed(e,t={groupSeparator:""},i=1){return Number.isInteger(e)||tn.logWithError(`${e} is not an integer.`),e<0&&tn.logWithError(`${e} is negative.`),Rn.DP=e,Rn.RM=ts[i]||1,new Rn(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};var Va=pe("Raydium_amount"),_a=Kt(ns);import{PublicKey as rs}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as er}from"@solana/spl-token";var Ln={chainId:101,address:rs.default.toBase58(),programId:er.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},je={chainId:101,address:"So11111111111111111111111111111111111111112",programId:er.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 vn}from"@solana/web3.js";import{PublicKey as ie,SystemProgram as tr,SYSVAR_RENT_PUBKEY as os}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ss}from"@solana/spl-token";function Fn({pubkey:n,isSigner:e=!1,isWritable:t=!0}){return{pubkey:n,isWritable:t,isSigner:e}}var Za=[Fn({pubkey:ss,isWritable:!1}),Fn({pubkey:tr.programId,isWritable:!1}),Fn({pubkey:os,isWritable:!1})];function nr({publicKey:n,transformSol:e}){let t=ir(n.toString());if(t instanceof ie)return e&&t.equals(Lt)?rn:t;if(e&&t.toString()===Lt.toBase58())return rn;if(typeof t=="string"){if(t===ie.default.toBase58())return ie.default;try{return new ie(t)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function ir(n){try{return new ie(n)}catch{return n}}var as=new ie("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),us=new ie("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Mn=new ie("SysvarRent111111111111111111111111111111111"),ja=new ie("SysvarC1ock11111111111111111111111111111111"),ft=new ie("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Qa=new ie("Sysvar1nstructions1111111111111111111111111"),Ja=tr.programId,$a=new ie("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),eu=new ie("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),tu=new ie("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),nu=new ie("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),iu=new ie("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),ru=new ie("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),ou=new ie("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),su=new ie("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),au=new ie("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),uu=new ie("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),cu=new ie("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),rn=new ie("So11111111111111111111111111111111111111112"),Lt=ie.default;var En=class{constructor({mint:e,decimals:t,symbol:i,name:r,skipMint:o=!1,isToken2022:s=!1}){if(e===Lt.toBase58()||e instanceof vn&&Lt.equals(e)){this.decimals=je.decimals,this.symbol=je.symbol,this.name=je.name,this.mint=new vn(je.address),this.isToken2022=!1;return}this.decimals=t,this.symbol=i||e.toString().substring(0,6),this.name=r||e.toString().substring(0,6),this.mint=o?vn.default:nr({publicKey:e}),this.isToken2022=s}equals(e){return this===e?!0:this.mint.equals(e.mint)}},Qe=En;Qe.WSOL=new En(Q(H({},je),{mint:je.address}));var On=class{constructor({decimals:e,symbol:t="UNKNOWN",name:i="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=i}equals(e){return this===e}},on=On;on.SOL=new On(Ln);import cs from"bn.js";var Tu=new ne(new cs(100));var Su=pe("Raydium_price");var ls=new Ee(0),tc=new Ee(1),nc=new Ee(2),ic=new Ee(3),rc=new Ee(5),is=new Ee(10),oc=new Ee(100),sc=new Ee(1e3),ac=new Ee(1e4);function rr(n,e,t){return n.mul(e).add(t).sub(new Ee(1)).div(t)}function Vn(n,e=1,t=[]){let i=[...n];if(e<=0)return t;for(;i.length;)t.push(i.splice(0,e));return t}import{PublicKey as gs}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Ps}from"@solana/spl-token";import{ComputeBudgetProgram as or,Keypair as ar,PublicKey as ms,Transaction as ur,TransactionMessage as ds,VersionedTransaction as cr}from"@solana/web3.js";var nt={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 ps}from"@solana/spl-token";var sr=pe("Raydium_txUtil"),lr=1644;function an(n){let e=[],t=[];return n.microLamports&&(e.push(or.setComputeUnitPrice({microLamports:n.microLamports})),t.push(nt.SetComputeUnitPrice)),n.units&&(e.push(or.setComputeUnitLimit({units:n.units})),t.push(nt.SetComputeUnitLimit)),{instructions:e,instructionTypes:t}}async function bt(n,e){var i,r;let t=e!=null?e:"confirmed";return(r=await((i=n.getLatestBlockhash)==null?void 0:i.call(n,{commitment:t})))==null?void 0:r.blockhash}async function un(n,e){return n.getSignatureStatuses([e]),new Promise((t,i)=>{let r=setTimeout(i,6e4);n.onSignature(e,o=>{if(clearTimeout(r),!o.err){t("");return}i(Object.assign(o.err,{txId:e}))},"confirmed")})}function fs(n,e){n.length<1&&sr.logWithError(`no instructions provided: ${n.toString()}`),e.length<1&&sr.logWithError(`no signers provided:, ${e.toString()}`);let t=new ur;t.recentBlockhash="11111111111111111111111111111111",t.feePayer=e[0],t.add(...n);try{return Buffer.from(t.serialize({verifySignatures:!1})).toString("base64").length<lr}catch{return!1}}function ge(n,e){let[t,i]=ms.findProgramAddressSync(n,e);return{publicKey:t,nonce:i}}function Ft({instructions:n,payer:e,signers:t}){return fs(n,[e,...t])}function Mt({instructions:n,payer:e,lookupTableAddressAccount:t,recentBlockhash:i=ar.generate().publicKey.toString()}){let o=new ds({payerKey:e,recentBlockhash:i,instructions:n}).compileToV0Message(Object.values(t!=null?t:{}));try{return Buffer.from(new cr(o).serialize()).toString("base64").length<lr}catch{return!1}}var bs=n=>Buffer.isBuffer(n)?n:n instanceof Uint8Array?Buffer.from(n.buffer,n.byteOffset,n.byteLength):Buffer.from(n),ys=n=>{let e=n.serialize({requireAllSignatures:!1,verifySignatures:!1});n instanceof cr&&(e=bs(e));try{return e instanceof Buffer?e.toString("base64"):Buffer.from(e).toString("base64")}catch{return e.toString("base64")}};function it(n){let e=[];return n.forEach(t=>{t instanceof ur&&(t.recentBlockhash||(t.recentBlockhash=ps.toBase58()),t.feePayer||(t.feePayer=ar.generate().publicKey)),e.push(ys(t))}),console.log("simulate tx string:",e),e}function Le(n,e,t){return ge([n.toBuffer(),(t!=null?t:Ps).toBuffer(),e.toBuffer()],new gs("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}import{PublicKey as E}from"@solana/web3.js";var Cc=new E("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),Kc=new E("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),Nc=new E("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),Rc=new E("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Lc=new E("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),Fc=new E("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),Mc=new E("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),vc=new E("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Ec=new E("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Oc=new E("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),ws=new E("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),As=new E("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),Ts=new E("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),Dc=new E("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),Wc=new E("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Vc=new E("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),_c=new E("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),qc=new E("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),Gc=new E("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),Uc=new E("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),Xc=new E("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),zc=new E("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Hc=new E("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),Yc=new E("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),Zc=new E("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),me=new E("LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj"),jc=new E("WLHv2UAZm6z4KyaaELi5pjdbJh6RESMva1Rnn8pJVVh"),Qc=new E("DRay6fNdQ5J82H7xV6uq2aV3mNrUZ1J4PgSKsWgptcm6"),Jc=new E("5xqNaZXX5eUi4p5HU4oz9i5QnwRNT2y6oN7yyn4qENeq"),$c=new E("4Bu96XjU84XjPDSpveTVf6LYGCkfW5FK7SNkREWcEfV4"),el=new E("6s1xP3hpbAfFoNtUNF8mfHsjr2Bd97JxFJRWLbL6aHuX");var tl={OPEN_BOOK_PROGRAM:new E("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),SERUM_PROGRAM_ID_V3:new E("Ray1111111111111111111111111111111111111111"),AMM_V4:new E("DRaya7Kj3aMWQSy19kSjvmuwq9docCHofyP9kanQGaav"),AMM_STABLE:new E("DRayDdXc1NZQ9C3hRWmoSf8zK4iapgMnjdNZWrfwsP8m"),CLMM_PROGRAM_ID:new E("DRayAUgENGQBKVaX8owNhgzkEDyoHTGVEGHVJT1E9pfH"),CLMM_LOCK_PROGRAM_ID:new E("DRay25Usp3YJAi7beckgpGUC7mGJ2cR1AVPxhYfwVCUX"),CLMM_LOCK_AUTH_ID:new E("6Aoh8h2Lw2m5UGxYR8AdAL87jTWYeKoxM52mJRzfYwN"),CREATE_CPMM_POOL_PROGRAM:new E("DRaycpLY18LhpbydsBWbVJtxpNv9oXPgjRSfpF2bWpYb"),CREATE_CPMM_POOL_AUTH:new E("CXniRufdq5xL8t8jZAPxsPZDpuudwuJSPWnbcD5Y5Nxq"),CREATE_CPMM_POOL_FEE_ACC:new E("3oE58BKVt8KuYkGxx8zBojugnymWmBiyafWgMrnb6eYy"),LOCK_CPMM_PROGRAM:new E("DRay25Usp3YJAi7beckgpGUC7mGJ2cR1AVPxhYfwVCUX"),LOCK_CPMM_AUTH:new E("7qWVV8UY2bRJfDLP4s37YzBPKUkVB46DStYJBpYbQzu3"),UTIL1216:E.default,Router:new E("DRaybByLpbUL57LJARs3j8BitTxVfzBg351EaMr5UTCd"),FARM_PROGRAM_ID_V3:new E("DRayWyrLmEW5KEeqs8kdTMMaBabapqagaBC7KWpGtJeZ"),FARM_PROGRAM_ID_V4:new E("Ray1111111111111111111111111111111111111111"),FARM_PROGRAM_ID_V5:new E("DRayiCGSZgku1GTK6rXD6mVDdingXy6APAH1R6R5L2LC"),FARM_PROGRAM_ID_V6:new E("DRayzbYakXs45ELHkzH6vC3fuhQqTAnv5A68gdFuvZyZ"),LAUNCHPAD_PROGRAM:new E("DRay6fNdQ5J82H7xV6uq2aV3mNrUZ1J4PgSKsWgptcm6"),LAUNCHPAD_AUTH:new E("5xqNaZXX5eUi4p5HU4oz9i5QnwRNT2y6oN7yyn4qENeq"),LAUNCHPAD_PLATFORM:new E("2Jx4KTDrVSdWNazuGpcA8n3ZLTRGGBDxAWhuKe2Xcj2a"),LAUNCHPAD_CONFIG:new E("7ZR4zD7PYfY2XxoG1Gxcy2EgEeGYrpxrwzPuwdUBssEt"),FEE_DESTINATION_ID:new E("9y8ENuuZ3b19quffx9hQvRVygG5ky6snHfRvGpuSfeJy"),MODEL_DATA_PUBKEY:new E("Ray1111111111111111111111111111111111111111")};import be from"bn.js";var vt=1e4;function _n(n,e){let{div:t,mod:i}=n.divmod(e);return i.gt(new be(0))?t.add(new be(1)):t}function rt(n,e){if(n.isZero())return new be(0);let t=n.div(e);return t.isZero()?new be(1):n.mod(e).gt(new be(0))?t.add(new be(1)):t}function qn(n,e,t){if(e===void 0)return{amount:n,fee:void 0,expirationTime:void 0};let i=Math.floor(t/432e3),r=i<e.newerTransferFee.epoch?e.olderTransferFee:e.newerTransferFee,o=new be(r.maximumFee.toString()),s=i<e.newerTransferFee.epoch?(Number(e.newerTransferFee.epoch)*432e3-t)*400/1e3:void 0,a=_n(n.mul(new be(r.transferFeeBasisPoints)),new be(vt)),c=a.gt(o)?o:a;return{amount:n,fee:c,expirationTime:s}}function Gn(n,e,t){if(e===void 0)return{amount:n,fee:void 0,expirationTime:void 0};let i=Math.floor(t/432e3),r=i<e.newerTransferFee.epoch?e.olderTransferFee:e.newerTransferFee,o=new be(r.maximumFee.toString()),s=i<e.newerTransferFee.epoch?(Number(e.newerTransferFee.epoch)*432e3-t)*400/1e3:void 0;if(r.transferFeeBasisPoints===vt){let a=new be(r.maximumFee.toString());return{amount:n.add(a),fee:a,expirationTime:s}}else{let a=_n(n.mul(new be(vt)),new be(vt-r.transferFeeBasisPoints)),c=new be(r.maximumFee.toString()),u=a.sub(n).gt(c)?n.add(c):a,l=_n(u.mul(new be(r.transferFeeBasisPoints)),new be(vt)),m=l.gt(o)?o:l;return{amount:u,fee:m,expirationTime:s}}}import{PublicKey as sl}from"@solana/web3.js";import ul from"bn.js";import ks from"bn.js";var ot=new ks(1e6);import{MINT_SIZE as Vl,TOKEN_PROGRAM_ID as _l,getTransferFeeConfig as ql,unpackMint as Gl}from"@solana/spl-token";var Un=pe("Raydium_accountInfo_util");async function Et(n,e,t){let{batchRequest:i,commitment:r="confirmed",chunkCount:o=100}=H({batchRequest:!1},t),s=Vn(e,o),a=new Array(s.length).fill([]);if(i){let c=s.map(m=>{let d=n._buildArgs([m.map(p=>p.toBase58())],r,"base64");return{methodName:"getMultipleAccounts",args:d}}),u=Vn(c,10);a=(await(await Promise.all(u.map(async m=>await n._rpcBatchRequest(m)))).flat()).map(m=>(m.error&&Un.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${m.error.message}`),m.result.value.map(d=>{if(d){let{data:p,executable:f,lamports:b,owner:g,rentEpoch:w}=d;return p.length!==2&&p[1]!=="base64"&&Un.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(p[0],"base64"),executable:f,lamports:b,owner:new hs(g),rentEpoch:w}}return null})))}else try{a=await Promise.all(s.map(c=>n.getMultipleAccountsInfo(c,r)))}catch(c){c instanceof Error&&Un.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return a.flat()}async function qe(n,e,t){let i=await Et(n,e.map(r=>r.pubkey),t);return e.map((r,o)=>Q(H({},r),{accountInfo:i[o]}))}async function zn({connection:n,address:e,cluster:t="mainnet"}){let i=await Et(n,[...new Set(e.map(o=>o.toString()))].map(o=>new Xn(o))),r={};for(let o=0;o<e.length;o++){let s=i[o],a=e[o];if(!s)continue;let c=new Pt({key:a,state:Pt.deserialize(s.data)});r[a.toString()]=c,t==="devnet"?gt[a.toString()]=c:yt[a.toString()]=c}return r}var yt={},Hn=async n=>{let e="AcL1Vo8oy1ULiavEcjSUcwfBSForXMudcZvDZy5nzJkU";if(yt[e])return yt;let t=new Xn(e),i=await n.getAccountInfo(t);return i&&(yt[e]=new Pt({key:t,state:Pt.deserialize(i.data)})),yt},gt={},Yn=async n=>{let e="EFhMuDw1PKEuckuFRW9PavNfTH4LKP5uKHgyXDmWpFCq";if(gt[e])return gt;let t=new Xn(e),i=await n.getAccountInfo(t);return i&&(gt[e]=new Pt({key:t,state:Pt.deserialize(i.data)})),gt};var cn=2e3,ln=class{constructor(e){this.instructions=[];this.endInstructions=[];this.lookupTableAddress=[];this.signers=[];this.instructionTypes=[];this.endInstructionTypes=[];this.connection=e.connection,this.feePayer=e.feePayer,this.signAllTransactions=e.signAllTransactions,this.owner=e.owner,this.cluster=e.cluster,this.blockhashCommitment=e.blockhashCommitment,this.loopMultiTxStatus=!!e.loopMultiTxStatus}get AllTxData(){return{instructions:this.instructions,endInstructions:this.endInstructions,signers:this.signers,instructionTypes:this.instructionTypes,endInstructionTypes:this.endInstructionTypes,lookupTableAddress:this.lookupTableAddress}}get allInstructions(){return[...this.instructions,...this.endInstructions]}async getComputeBudgetConfig(){var i;let e=(await xs.get(`https://solanacompass.com/api/fees?cacheFreshTime=${3e5}`)).data,{avg:t}=(i=e==null?void 0:e[15])!=null?i:{};if(!!t)return{units:6e5,microLamports:Math.min(Math.ceil(t*1e6/6e5),25e3)}}addCustomComputeBudget(e){if(e){let{instructions:t,instructionTypes:i}=an(e);return this.instructions.unshift(...t),this.instructionTypes.unshift(...i),!0}return!1}addTipInstruction(e){var t;return e?(this.endInstructions.push(Bs.transfer({fromPubkey:(t=e.feePayer)!=null?t:this.feePayer,toPubkey:new wt(e.address),lamports:BigInt(e.amount.toString())})),this.endInstructionTypes.push(nt.TransferTip),!0):!1}async calComputeBudget({config:e,defaultIns:t}){try{let i=e||await this.getComputeBudgetConfig();if(this.addCustomComputeBudget(i))return;t&&this.instructions.unshift(...t)}catch{t&&this.instructions.unshift(...t)}}addInstruction({instructions:e=[],endInstructions:t=[],signers:i=[],instructionTypes:r=[],endInstructionTypes:o=[],lookupTableAddress:s=[]}){return this.instructions.push(...e),this.endInstructions.push(...t),this.signers.push(...i),this.instructionTypes.push(...r),this.endInstructionTypes.push(...o),this.lookupTableAddress.push(...s.filter(a=>a!==wt.default.toString())),this}async versionBuild({txVersion:e,extInfo:t}){return e===0?await this.buildV0(H({},t||{})):this.build(t)}build(e){var i;let t=new Ot;return this.allInstructions.length&&t.add(...this.allInstructions),t.feePayer=this.feePayer,((i=this.owner)==null?void 0:i.signer)&&!this.signers.some(r=>r.publicKey.equals(this.owner.publicKey))&&this.signers.push(this.owner.signer),{builder:this,transaction:t,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async r=>{var l;let{recentBlockHash:o,skipPreflight:s=!0,sendAndConfirm:a,notSendToRpc:c}=r||{},u=o!=null?o:await bt(this.connection,this.blockhashCommitment);if(t.recentBlockhash=u,this.signers.length&&t.sign(...this.signers),it([t]),(l=this.owner)!=null&&l.isKeyPair)return{txId:a?await Zn(this.connection,t,this.signers.find(d=>d.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:s}):await this.connection.sendRawTransaction(t.serialize(),{skipPreflight:s}),signedTx:t};if(this.signAllTransactions){let m=await this.signAllTransactions([t]);if(this.signers.length)for(let d of m)try{d.sign(...this.signers)}catch{}return{txId:c?"":await this.connection.sendRawTransaction(m[0].serialize(),{skipPreflight:s}),signedTx:m[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:e||{}}}buildMultiTx(e){var u;let{extraPreBuildData:t=[],extInfo:i}=e,{transaction:r}=this.build(i),o=t.filter(l=>l.transaction.instructions.length>0),s=[r,...o.map(l=>l.transaction)],a=[this.signers,...o.map(l=>l.signers)],c=[...this.instructionTypes,...o.map(l=>l.instructionTypes).flat()];return(u=this.owner)!=null&&u.signer&&a.forEach(l=>{l.some(m=>m.publicKey.equals(this.owner.publicKey))||this.signers.push(this.owner.signer)}),{builder:this,transactions:s,signers:a,instructionTypes:c,execute:async l=>{var w;let{sequentially:m,onTxUpdate:d,skipTxCount:p=0,recentBlockHash:f,skipPreflight:b=!0}=l||{},g=f!=null?f:await bt(this.connection,this.blockhashCommitment);if((w=this.owner)!=null&&w.isKeyPair){if(m){let A=[],B=0;for(let k of s){if(++B,B<=p)continue;let P=await Zn(this.connection,k,this.signers.find(h=>h.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:b});A.push(P)}return{txIds:A,signedTxs:s}}return{txIds:await await Promise.all(s.map(async A=>(A.recentBlockhash=g,await this.connection.sendRawTransaction(A.serialize(),{skipPreflight:b})))),signedTxs:s}}if(this.signAllTransactions){let A=s.map((k,P)=>(k.recentBlockhash=g,a[P].length&&k.sign(...a[P]),k));it(A);let B=await this.signAllTransactions(A);if(m){let k=0,P=[],h=async()=>{if(!B[k])return;let C=await this.connection.sendRawTransaction(B[k].serialize(),{skipPreflight:b});P.push({txId:C,status:"sent",signedTx:B[k]}),d==null||d([...P]),k++;let I=!1,N=null,F=null,S=M=>{N!==null&&clearInterval(N),F!==null&&this.connection.removeSignatureListener(F);let V=P.findIndex(X=>X.txId===C);if(V>-1){if(P[V].status==="error"||P[V].status==="success")return;P[V].status=M.err?"error":"success"}d==null||d([...P]),M.err||h()};this.loopMultiTxStatus&&(N=setInterval(async()=>{var M;if(I){clearInterval(N);return}try{let V=await this.connection.getTransaction(C,{commitment:"confirmed",maxSupportedTransactionVersion:0});V&&(I=!0,clearInterval(N),S({err:((M=V.meta)==null?void 0:M.err)||null}),console.log("tx status from getTransaction:",C))}catch(V){I=!0,clearInterval(N),console.error("getTransaction timeout:",V,C)}},cn)),F=this.connection.onSignature(C,M=>{if(I){this.connection.removeSignatureListener(F);return}I=!0,S(M)},"confirmed"),this.connection.getSignatureStatus(C)};return await h(),{txIds:P.map(C=>C.txId),signedTxs:B}}else{let k=[];for(let P=0;P<B.length;P+=1){let h=await this.connection.sendRawTransaction(B[P].serialize(),{skipPreflight:b});k.push(h)}return{txIds:k,signedTxs:B}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}async versionMultiBuild({extraPreBuildData:e,txVersion:t,extInfo:i}){return t===0?await this.buildV0MultiTx({extraPreBuildData:e,buildProps:i||{}}):this.buildMultiTx({extraPreBuildData:e,extInfo:i})}async buildV0(e){var b;let f=e||{},{lookupTableCache:t={},lookupTableAddress:i=[],forerunCreate:r,recentBlockhash:o}=f,s=tt(f,["lookupTableCache","lookupTableAddress","forerunCreate","recentBlockhash"]),a=H(H({},this.cluster==="devnet"?await Yn(this.connection):await Hn(this.connection)),t),c=Array.from(new Set([...i,...this.lookupTableAddress])),u=[];for(let g of c)a[g]===void 0&&u.push(new wt(g));let l=await zn({connection:this.connection,address:u});for(let[g,w]of Object.entries(l))a[g]=w;let m=r?wt.default.toBase58():o!=null?o:await bt(this.connection,this.blockhashCommitment),d=new Dt({payerKey:this.feePayer,recentBlockhash:m,instructions:[...this.allInstructions]}).compileToV0Message(Object.values(a));((b=this.owner)==null?void 0:b.signer)&&!this.signers.some(g=>g.publicKey.equals(this.owner.publicKey))&&this.signers.push(this.owner.signer);let p=new Wt(d);return p.sign(this.signers),{builder:this,transaction:p,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async g=>{var k;let{skipPreflight:w=!0,sendAndConfirm:A,notSendToRpc:B}=g||{};if(it([p]),(k=this.owner)!=null&&k.isKeyPair){let P=await this.connection.sendTransaction(p,{skipPreflight:w});return A&&await un(this.connection,P),{txId:P,signedTx:p}}if(this.signAllTransactions){let P=await this.signAllTransactions([p]);if(this.signers.length)for(let h of P)try{h.sign(this.signers)}catch{}return{txId:B?"":await this.connection.sendTransaction(P[0],{skipPreflight:w}),signedTx:P[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:s||{}}}async buildV0MultiTx(e){var u;let{extraPreBuildData:t=[],buildProps:i}=e,{transaction:r}=await this.buildV0(i),o=t.filter(l=>l.builder.instructions.length>0),s=[r,...o.map(l=>l.transaction)],a=[this.signers,...o.map(l=>l.signers)],c=[...this.instructionTypes,...o.map(l=>l.instructionTypes).flat()];return(u=this.owner)!=null&&u.signer&&a.forEach(l=>{l.some(m=>m.publicKey.equals(this.owner.publicKey))||this.signers.push(this.owner.signer)}),s.forEach(async(l,m)=>{l.sign(a[m])}),{builder:this,transactions:s,signers:a,instructionTypes:c,buildProps:i,execute:async l=>{var b;let{sequentially:m,onTxUpdate:d,recentBlockHash:p,skipPreflight:f=!0}=l||{};if(p&&s.forEach(g=>g.message.recentBlockhash=p),it(s),(b=this.owner)!=null&&b.isKeyPair){if(m){let g=[];for(let w of s){let A=await this.connection.sendTransaction(w,{skipPreflight:f});await un(this.connection,A),g.push(A)}return{txIds:g,signedTxs:s}}return{txIds:await Promise.all(s.map(async g=>await this.connection.sendTransaction(g,{skipPreflight:f}))),signedTxs:s}}if(this.signAllTransactions){let g=await this.signAllTransactions(s);if(m){let w=0,A=[],B=async()=>{if(!g[w])return;let k=await this.connection.sendTransaction(g[w],{skipPreflight:f});A.push({txId:k,status:"sent",signedTx:g[w]}),d==null||d([...A]),w++;let P=!1,h=null,C=null,I=N=>{h!==null&&clearInterval(h),C!==null&&this.connection.removeSignatureListener(C);let F=A.findIndex(S=>S.txId===k);if(F>-1){if(A[F].status==="error"||A[F].status==="success")return;A[F].status=N.err?"error":"success"}d==null||d([...A]),N.err||B()};this.loopMultiTxStatus&&(h=setInterval(async()=>{var N;if(P){clearInterval(h);return}try{let F=await this.connection.getTransaction(k,{commitment:"confirmed",maxSupportedTransactionVersion:0});F&&(P=!0,clearInterval(h),I({err:((N=F.meta)==null?void 0:N.err)||null}),console.log("tx status from getTransaction:",k))}catch(F){P=!0,clearInterval(h),console.error("getTransaction timeout:",F,k)}},cn)),C=this.connection.onSignature(k,N=>{if(P){this.connection.removeSignatureListener(C);return}P=!0,I(N)},"confirmed"),this.connection.getSignatureStatus(k)};return B(),{txIds:[],signedTxs:g}}else{let w=[];for(let A=0;A<g.length;A+=1){let B=await this.connection.sendTransaction(g[A],{skipPreflight:f});w.push(B)}return{txIds:w,signedTxs:g}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}async sizeCheckBuild(e){var d;let m=e||{},{splitIns:t=[],computeBudgetConfig:i}=m,r=tt(m,["splitIns","computeBudgetConfig"]),o=i?an(i):{instructions:[],instructionTypes:[]},s=this.signers.reduce((p,f)=>Q(H({},p),{[f.publicKey.toBase58()]:f}),{}),a=[],c=[],u=[],l=0;if(this.allInstructions.forEach(p=>{let f=[...u,p],b=i?[...o.instructions,...f]:f,w=[...new Set(f.map(A=>A.keys.filter(B=>B.isSigner).map(B=>B.pubkey.toString())).flat()).values()].map(A=>new wt(A));if(p!==t[l]&&u.length<12&&(Ft({instructions:b,payer:this.feePayer,signers:w})||Ft({instructions:f,payer:this.feePayer,signers:w})))u.push(p);else{if(u.length===0)throw Error("item ins too big");l+=p===t[l]?1:0,Ft({instructions:i?[...o.instructions,...u]:[...u],payer:this.feePayer,signers:w})?a.push(new Ot().add(...o.instructions,...u)):a.push(new Ot().add(...u)),c.push(Array.from(new Set(u.map(A=>A.keys.filter(B=>B.isSigner).map(B=>B.pubkey.toString())).flat())).map(A=>s[A]).filter(A=>A!==void 0)),u=[p]}}),u.length>0){let f=[...new Set(u.map(b=>b.keys.filter(g=>g.isSigner).map(g=>g.pubkey.toString())).flat()).values()].map(b=>s[b]).filter(b=>b!==void 0);Ft({instructions:i?[...o.instructions,...u]:[...u],payer:this.feePayer,signers:f.map(b=>b.publicKey)})?a.push(new Ot().add(...o.instructions,...u)):a.push(new Ot().add(...u)),c.push(f)}return a.forEach(p=>p.feePayer=this.feePayer),(d=this.owner)!=null&&d.signer&&c.forEach(p=>{p.some(f=>f.publicKey.equals(this.owner.publicKey))||p.push(this.owner.signer)}),{builder:this,transactions:a,signers:c,instructionTypes:this.instructionTypes,execute:async p=>{var k;let{sequentially:f,onTxUpdate:b,skipTxCount:g=0,recentBlockHash:w,skipPreflight:A=!0}=p||{},B=w!=null?w:await bt(this.connection,this.blockhashCommitment);if(a.forEach(async(P,h)=>{P.recentBlockhash=B,c[h].length&&P.sign(...c[h])}),it(a),(k=this.owner)!=null&&k.isKeyPair){if(f){let P=0,h=[];for(let C of a){if(++P,P<=g){h.push("tx skipped");continue}let I=await Zn(this.connection,C,this.signers.find(N=>N.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:A});h.push(I)}return{txIds:h,signedTxs:a}}return{txIds:await Promise.all(a.map(async P=>await this.connection.sendRawTransaction(P.serialize(),{skipPreflight:A}))),signedTxs:a}}if(this.signAllTransactions){let P=await this.signAllTransactions(a.slice(g,a.length)),h=[...a.slice(0,g),...P];if(f){let C=0,I=[],N=async()=>{if(!h[C])return;C<g&&(I.push({txId:"",status:"success",signedTx:h[C]}),b==null||b([...I]),C++,N());let F=await this.connection.sendRawTransaction(h[C].serialize(),{skipPreflight:A});I.push({txId:F,status:"sent",signedTx:h[C]}),b==null||b([...I]),C++;let S=!1,M=null,V=null,X=x=>{M!==null&&clearInterval(M),V!==null&&this.connection.removeSignatureListener(V);let K=I.findIndex(ee=>ee.txId===F);if(K>-1){if(I[K].status==="error"||I[K].status==="success")return;I[K].status=x.err?"error":"success"}b==null||b([...I]),x.err||N()};this.loopMultiTxStatus&&(M=setInterval(async()=>{var x;if(S){clearInterval(M);return}try{let K=await this.connection.getTransaction(F,{commitment:"confirmed",maxSupportedTransactionVersion:0});K&&(S=!0,clearInterval(M),X({err:((x=K.meta)==null?void 0:x.err)||null}),console.log("tx status from getTransaction:",F))}catch(K){S=!0,clearInterval(M),console.error("getTransaction timeout:",K,F)}},cn)),V=this.connection.onSignature(F,x=>{if(S){this.connection.removeSignatureListener(V);return}S=!0,X(x)},"confirmed"),this.connection.getSignatureStatus(F)};return await N(),{txIds:I.map(F=>F.txId),signedTxs:h}}else{let C=[];for(let I=0;I<h.length;I+=1){let N=await this.connection.sendRawTransaction(h[I].serialize(),{skipPreflight:A});C.push(N)}return{txIds:C,signedTxs:h}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async sizeCheckBuildV0(e){var B;let A=e||{},{computeBudgetConfig:t,splitIns:i=[],lookupTableCache:r={},lookupTableAddress:o=[]}=A,s=tt(A,["computeBudgetConfig","splitIns","lookupTableCache","lookupTableAddress"]),a=H(H({},this.cluster==="devnet"?await Yn(this.connection):await Hn(this.connection)),r),c=Array.from(new Set([...this.lookupTableAddress,...o])),u=[];for(let k of c)a[k]===void 0&&u.push(new wt(k));let l=await zn({connection:this.connection,address:u});for(let[k,P]of Object.entries(l))a[k]=P;let m=t?an(t):{instructions:[],instructionTypes:[]},d=await bt(this.connection,this.blockhashCommitment),p=this.signers.reduce((k,P)=>Q(H({},k),{[P.publicKey.toBase58()]:P}),{}),f=[],b=[],g=[],w=0;if(this.allInstructions.forEach(k=>{let P=[...g,k],h=t?[...m.instructions,...P]:P;if(k!==i[w]&&g.length<12&&(Mt({instructions:h,payer:this.feePayer,lookupTableAddressAccount:a})||Mt({instructions:P,payer:this.feePayer,lookupTableAddressAccount:a})))g.push(k);else{if(g.length===0)throw Error("item ins too big");w+=k===i[w]?1:0;let C={};for(let I of[...new Set(c)])a[I]!==void 0&&(C[I]=a[I]);if(t&&Mt({instructions:[...m.instructions,...g],payer:this.feePayer,lookupTableAddressAccount:a,recentBlockhash:d})){let I=new Dt({payerKey:this.feePayer,recentBlockhash:d,instructions:[...m.instructions,...g]}).compileToV0Message(Object.values(a));f.push(new Wt(I))}else{let I=new Dt({payerKey:this.feePayer,recentBlockhash:d,instructions:[...g]}).compileToV0Message(Object.values(a));f.push(new Wt(I))}b.push(Array.from(new Set(g.map(I=>I.keys.filter(N=>N.isSigner).map(N=>N.pubkey.toString())).flat())).map(I=>p[I]).filter(I=>I!==void 0)),g=[k]}}),g.length>0){let P=[...new Set(g.map(h=>h.keys.filter(C=>C.isSigner).map(C=>C.pubkey.toString())).flat()).values()].map(h=>p[h]).filter(h=>h!==void 0);if(t&&Mt({instructions:[...m.instructions,...g],payer:this.feePayer,lookupTableAddressAccount:a,recentBlockhash:d})){let h=new Dt({payerKey:this.feePayer,recentBlockhash:d,instructions:[...m.instructions,...g]}).compileToV0Message(Object.values(a));f.push(new Wt(h))}else{let h=new Dt({payerKey:this.feePayer,recentBlockhash:d,instructions:[...g]}).compileToV0Message(Object.values(a));f.push(new Wt(h))}b.push(P)}return(B=this.owner)!=null&&B.signer&&b.forEach(k=>{k.some(P=>P.publicKey.equals(this.owner.publicKey))||k.push(this.owner.signer)}),f.forEach((k,P)=>{k.sign(b[P])}),{builder:this,transactions:f,buildProps:e,signers:b,instructionTypes:this.instructionTypes,execute:async k=>{var F;let{sequentially:P,onTxUpdate:h,skipTxCount:C=0,recentBlockHash:I,skipPreflight:N=!0}=k||{};if(f.map(async(S,M)=>{b[M].length&&S.sign(b[M]),I&&(S.message.recentBlockhash=I)}),it(f),(F=this.owner)!=null&&F.isKeyPair){if(P){let S=0,M=[];for(let V of f){if(++S,S<=C){console.log("skip tx: ",S),M.push("tx skipped");continue}let X=await this.connection.sendTransaction(V,{skipPreflight:N});await un(this.connection,X),M.push(X)}return{txIds:M,signedTxs:f}}return{txIds:await Promise.all(f.map(async S=>await this.connection.sendTransaction(S,{skipPreflight:N}))),signedTxs:f}}if(this.signAllTransactions){let S=await this.signAllTransactions(f.slice(C,f.length)),M=[...f.slice(0,C),...S];if(P){let V=0,X=[],x=async()=>{if(!M[V])return;if(V<C){X.push({txId:"",status:"success",signedTx:M[V]}),h==null||h([...X]),V++,x();return}let K=await this.connection.sendTransaction(M[V],{skipPreflight:N});X.push({txId:K,status:"sent",signedTx:M[V]}),h==null||h([...X]),V++;let ee=!1,J=null,se=null,j=ae=>{J!==null&&clearInterval(J),se!==null&&this.connection.removeSignatureListener(se);let le=X.findIndex(ue=>ue.txId===K);if(le>-1){if(X[le].status==="error"||X[le].status==="success")return;X[le].status=ae.err?"error":"success"}h==null||h([...X]),ae.err||x()};this.loopMultiTxStatus&&(J=setInterval(async()=>{var ae;if(ee){clearInterval(J);return}try{let le=await this.connection.getTransaction(K,{commitment:"confirmed",maxSupportedTransactionVersion:0});le&&(ee=!0,clearInterval(J),j({err:((ae=le.meta)==null?void 0:ae.err)||null}),console.log("tx status from getTransaction:",K))}catch(le){ee=!0,clearInterval(J),console.error("getTransaction timeout:",le,K)}},cn)),se=this.connection.onSignature(K,ae=>{if(ee){this.connection.removeSignatureListener(se);return}ee=!0,j(ae)},"confirmed"),this.connection.getSignatureStatus(K)};return x(),{txIds:[],signedTxs:M}}else{let V=[];for(let X=0;X<M.length;X+=1){let x=await this.connection.sendTransaction(M[X],{skipPreflight:N});V.push(x)}return{txIds:V,signedTxs:M}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:s||{}}}};var jn=(...n)=>n.map(e=>{try{return typeof e=="object"?JSON.stringify(e):e}catch{return e}}).join(", "),At=class{constructor({scope:e,moduleName:t}){this.disabled=!1;this.scope=e,this.logger=pe(t)}createTxBuilder(e){return this.scope.checkOwner(),new ln({connection:this.scope.connection,feePayer:e||this.scope.ownerPubKey,cluster:this.scope.cluster,owner:this.scope.owner,blockhashCommitment:this.scope.blockhashCommitment,loopMultiTxStatus:this.scope.loopMultiTxStatus,api:this.scope.api,signAllTransactions:this.scope.signAllTransactions})}logDebug(...e){this.logger.debug(jn(e))}logInfo(...e){this.logger.info(jn(e))}logAndCreateError(...e){let t=jn(e);throw new Error(t)}checkDisabled(){(this.disabled||!this.scope)&&this.logAndCreateError("module not working")}};import{PublicKey as Qf}from"@solana/web3.js";import $f from"bn.js";import{AccountLayout as ib,createAssociatedTokenAccountIdempotentInstruction as rb,TOKEN_2022_PROGRAM_ID as ob,TOKEN_PROGRAM_ID as sb}from"@solana/spl-token";import{PublicKey as fm}from"@solana/web3.js";import{MintLayout as ym,TOKEN_PROGRAM_ID as Pm}from"@solana/spl-token";import{Keypair as Tf,PublicKey as kf,SystemProgram as Bf,TransactionInstruction as xf}from"@solana/web3.js";import Sf from"bn.js";import{ASSOCIATED_TOKEN_PROGRAM_ID as Nf,TOKEN_2022_PROGRAM_ID as Rf,TOKEN_PROGRAM_ID as Lf}from"@solana/spl-token";import{PublicKey as Es}from"@solana/web3.js";import yr,{isBN as gr}from"bn.js";import{bits as xm,BitStructure as Im,blob as Is,Blob as Sm,cstr as Cm,f32 as Km,f32be as Nm,f64 as Rm,f64be as Lm,greedy as Fm,Layout as Ss,ns64 as Mm,ns64be as vm,nu64 as Em,nu64be as Om,offset as Cs,s16 as Dm,s16be as Wm,s24 as Vm,s24be as _m,s32 as Ks,s32be as qm,s40 as Gm,s40be as Um,s48 as Xm,s48be as zm,s8 as Hm,seq as Ns,struct as Ym,Structure as Rs,u16 as Ls,u16be as Zm,u24 as jm,u24be as Qm,u32 as Fs,u32be as Jm,u40 as $m,u40be as ed,u48 as td,u48be as nd,u8 as Ms,UInt as vs,union as id,Union as rd,unionLayoutDiscriminator as od,utf8 as sd}from"@solana/buffer-layout";var Qn=Ss,pr=Rs;var Jn=vs;var fr=Ms,Ge=Ls;var $n=Fs;var Ue=Ks;var br=Ns;var we=Is;var ei=Cs;var Tt=class extends Qn{constructor(t,i,r){super(t,r);this.blob=we(t),this.signed=i}decode(t,i=0){let r=new yr(this.blob.decode(t,i),10,"le");return this.signed?r.fromTwos(this.span*8).clone():r}encode(t,i,r=0){return typeof t=="number"&&(t=new yr(t)),this.signed&&(t=t.toTwos(this.span*8)),this.blob.encode(t.toArrayLike(Buffer,"le",this.span),i,r)}};function W(n){return new Jn(1,n)}function kt(n){return new Jn(4,n)}function y(n){return new Tt(8,!1,n)}function re(n){return new Tt(16,!1,n)}function Pr(n){return new Tt(8,!0,n)}function wr(n){return new Tt(16,!0,n)}var st=class extends Qn{constructor(t,i,r,o){super(t.span,o);this.layout=t,this.decoder=i,this.encoder=r}decode(t,i){return this.decoder(this.layout.decode(t,i))}encode(t,i,r){return this.layout.encode(this.encoder(t),i,r)}getSpan(t,i){return this.layout.getSpan(t,i)}};function O(n){return new st(we(32),e=>new Es(e),e=>e.toBuffer(),n)}function ni(n){return new st(fr(),Os,Ds,n)}function Os(n){if(n===0)return!1;if(n===1)return!0;throw new Error("Invalid bool: "+n)}function Ds(n){return n?1:0}function Ar(n,e){let t=$n("length"),i=q([t,Y(n,ei(t,-t.span),"values")]);return new st(i,({values:r})=>r,r=>({values:r}),e)}function Ws(n){let e=$n("length"),t=q([e,we(ei(e,-e.span),"data")]);return new st(t,({data:i})=>i,i=>({data:i}),n)}function Ae(n){return new st(Ws(),e=>e.toString("utf-8"),e=>Buffer.from(e,"utf-8"),n)}var ti=class extends pr{decode(e,t){return super.decode(e,t)}};function q(n,e,t){return new ti(n,e,t)}function Y(n,e,t){let i,r=typeof e=="number"?e:gr(e)?e.toNumber():new Proxy(e,{get(o,s){if(!i){let a=Reflect.get(o,"count");i=gr(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 br(n,r,t)}import ef from"bn.js";import Ie from"bn.js";var ii=new Ie(0),Tr=new Ie(1),kr=new Ie(-1),Oe=new Ie(1).shln(64),hr=new Ie(1).shln(128),ri=Oe.sub(Tr);var Vs=hr.subn(1),ht=-443636,Vt=-ht,oi=new Ie("4295048016"),si=new Ie("79226673521066979257578248091"),Pd=new Ie("4295048017"),wd=new Ie("79226673521066979257578248090");var _s=new Ie(10).pow(new Ie(6));var Ad=new Ie("18446744073700000000");import Vp from"bn.js";var Id=Buffer.from("amm_config","utf8"),Br=Buffer.from("pool","utf8"),xr=Buffer.from("pool_vault","utf8"),Sd=Buffer.from("pool_reward_vault","utf8"),Cd=Buffer.from("position","utf8"),Kd=Buffer.from("tick_array","utf8"),Nd=Buffer.from("operation","utf8"),Rd=Buffer.from("pool_tick_array_bitmap_extension","utf8"),Ld=Buffer.from("observation","utf8");function ai(n){return ge([Buffer.from("metadata","utf8"),ft.toBuffer(),n.toBuffer()],ft)}var Fd=Buffer.from("locked_position","utf8");var Md=Buffer.from("support_mint","utf8");import{PublicKey as pp}from"@solana/web3.js";import{TOKEN_2022_PROGRAM_ID as bp}from"@solana/spl-token";import gp from"bn.js";import Od from"bn.js";var li=14;var mn=60;var zs=q([we(8),W("bump"),Ge("index"),O(""),kt("protocolFeeRate"),kt("tradeFeeRate"),Ge("tickSpacing"),Y(y(),8,"")]),Hs=q([kt("blockTimestamp"),Pr("tickCumulative"),Y(y(),4)]),vr=q([we(8),ni("initialized"),y("recentEpoch"),Ge("observationIndex"),O("poolId"),Y(Hs,100,"observations"),Y(y(),4)]),Ys=q([W("rewardState"),y("openTime"),y("endTime"),y("lastUpdateTime"),re("emissionsPerSecondX64"),y("rewardTotalEmissioned"),y("rewardClaimed"),O("tokenMint"),O("tokenVault"),O("creator"),re("rewardGrowthGlobalX64")]),Lr=q([we(8),W("bump"),O("ammConfig"),O("creator"),O("mintA"),O("mintB"),O("vaultA"),O("vaultB"),O("observationId"),W("mintDecimalsA"),W("mintDecimalsB"),Ge("tickSpacing"),re("liquidity"),re("sqrtPriceX64"),Ue("tickCurrent"),kt(),re("feeGrowthGlobalX64A"),re("feeGrowthGlobalX64B"),y("protocolFeesTokenA"),y("protocolFeesTokenB"),re("swapInAmountTokenA"),re("swapOutAmountTokenB"),re("swapInAmountTokenB"),re("swapOutAmountTokenA"),W("status"),Y(W(),7,""),Y(Ys,3,"rewardInfos"),Y(y(),16,"tickArrayBitmap"),y("totalFeesTokenA"),y("totalFeesClaimedTokenA"),y("totalFeesTokenB"),y("totalFeesClaimedTokenB"),y("fundFeesTokenA"),y("fundFeesTokenB"),y("startTime"),Y(y(),15*4-3,"padding")]),Zs=q([re("growthInsideLastX64"),y("rewardAmountOwed")]),Fr=q([we(8),W("bump"),O("nftMint"),O("poolId"),Ue("tickLower"),Ue("tickUpper"),re("liquidity"),re("feeGrowthInsideLastX64A"),re("feeGrowthInsideLastX64B"),y("tokenFeesOwedA"),y("tokenFeesOwedB"),Y(Zs,3,"rewardInfos"),Y(y(),8,"")]),mf=q([we(8),W("bump"),O("poolId"),Ue("tickLowerIndex"),Ue("tickUpperIndex"),re("liquidity"),re("feeGrowthInsideLastX64A"),re("feeGrowthInsideLastX64B"),y("tokenFeesOwedA"),y("tokenFeesOwedB"),Y(re(),3,"rewardGrowthInside"),Y(y(),8,"")]),js=q([Ue("tick"),wr("liquidityNet"),re("liquidityGross"),re("feeGrowthOutsideX64A"),re("feeGrowthOutsideX64B"),Y(re(),3,"rewardGrowthsOutsideX64"),Y(kt(),13,"")]),Kr=q([we(8),O("poolId"),Ue("startTickIndex"),Y(js,mn,"ticks"),W("initializedTickCount"),Y(W(),115,"")]),Qs=q([we(329),Y(O(),100,"whitelistMints")]),Xs=q([we(8),O("poolId"),Y(Y(y(),8),li,"positiveTickArrayBitmap"),Y(Y(y(),8),li,"negativeTickArrayBitmap")]),df=q([y(),W("bump"),O("owner"),O("poolId"),O("positionId"),O("nftAccount"),Y(y(),8)]),Js=q([we(8),W("bump"),O("lockOwner"),O("poolId"),O("positionId"),O("nftAccount"),O("lockNftMint"),y("recentEpoch"),Y(y(),8)]);vr.span;var _f=pe("Raydium_Clmm");var na=Buffer.from("vault_auth_seed","utf8"),Xb=Buffer.from("global_config","utf8"),ia=Buffer.from("pool_vesting","utf8"),ra=Buffer.from("platform_config","utf8"),oa=Buffer.from("platform_fee_vault_auth_seed","utf8"),sa=Buffer.from("creator_fee_vault_auth_seed","utf8");function De(n){return ge([na],n)}function Bt(n,e,t){return ge([Br,e.toBuffer(),t.toBuffer()],n)}function mi(n,e,t){return ge([xr,e.toBuffer(),t.toBuffer()],n)}function at(n){return ge([Buffer.from("__event_authority","utf8")],n)}function di(n,e){return ge([ra,e.toBuffer()],n)}function Gt(n,e,t){return ge([ia,e.toBuffer(),t.toBuffer()],n)}function ut(n,e,t){return ge([e.toBuffer(),t.toBuffer()],n)}function pi(n){return ge([oa],n)}function ct(n,e,t){return ge([e.toBuffer(),t.toBuffer()],n)}function fi(n){return ge([sa],n)}import{ASSOCIATED_TOKEN_PROGRAM_ID as dn,TOKEN_2022_PROGRAM_ID as ca,TOKEN_PROGRAM_ID as bi}from"@solana/spl-token";import{SystemProgram as Se,TransactionInstruction as he}from"@solana/web3.js";import It from"bn.js";var Je=q([y(),y("epoch"),W("curveType"),Ge("index"),y("migrateFee"),y("tradeFeeRate"),y("maxShareFeeRate"),y("minSupplyA"),y("maxLockRate"),y("minSellRateA"),y("minMigrateRateA"),y("minFundRaisingB"),O("mintB"),O("protocolFeeOwner"),O("migrateFeeOwner"),O("migrateToAmmWallet"),O("migrateToCpmmWallet"),Y(y(),16)]),aa=q([y("totalLockedAmount"),y("cliffPeriod"),y("unlockPeriod"),y("startTime"),y("totalAllocatedShare")]),Fe=q([y(),y("epoch"),W("bump"),W("status"),W("mintDecimalsA"),W("mintDecimalsB"),W("migrateType"),y("supply"),y("totalSellA"),y("virtualA"),y("virtualB"),y("realA"),y("realB"),y("totalFundRaisingB"),y("protocolFee"),y("platformFee"),y("migrateFee"),aa.replicate("vestingSchedule"),O("configId"),O("platformId"),O("mintA"),O("mintB"),O("vaultA"),O("vaultB"),O("creator"),W("mintProgramFlag"),W("cpmmCreatorFeeOn"),Y(W(),62)]),Yb=q([y(),y("epoch"),O("poolId"),O("beneficiary"),y("claimedAmount"),y("tokenShareAmount"),Y(y(),8)]),Er=q([W("migrateType"),W("migrateCpmmFeeOn"),y("supply"),y("totalSellA"),y("totalFundRaisingB"),y("totalLockedAmount"),y("cliffPeriod"),y("unlockPeriod")]),ua=q([y("epoch"),W("index"),O("configId"),Er.replicate("bondingCurveParam"),Y(y(),50)]),xt=q([y(),y("epoch"),O("platformClaimFeeWallet"),O("platformLockNftWallet"),y("platformScale"),y("creatorScale"),y("burnScale"),y("feeRate"),Y(W(),64,"name"),Y(W(),256,"web"),Y(W(),256,"img"),O("cpConfigId"),y("creatorFeeRate"),O("transferFeeExtensionAuth"),Y(W(),180),Ar(ua,"platformCurve")]);var Be={initialize:Buffer.from([175,175,109,31,13,152,155,237]),initializeV2:Buffer.from([67,153,175,39,218,16,38,32]),buyExactIn:Buffer.from([250,234,13,123,213,156,19,236]),buyExactOut:Buffer.from([24,211,116,40,105,3,153,56]),sellExactIn:Buffer.from([149,39,222,155,211,124,152,26]),sellExactOut:Buffer.from([95,200,71,34,8,9,11,166]),createVestingAccount:Buffer.from([129,178,2,13,217,172,230,218]),claimVestedToken:Buffer.from([49,33,104,30,189,157,79,35]),createPlatformConfig:Buffer.from([176,90,196,175,253,113,220,20]),claimPlatformFee:Buffer.from([156,39,208,135,76,237,61,72]),updatePlaformConfig:Buffer.from([195,60,76,129,146,45,67,143]),initializeWithToken2022:Buffer.from([37,190,126,222,44,154,171,17]),claimPlatformFeeFromVault:Buffer.from([117,241,198,168,248,218,80,29]),claimCreatorFee:Buffer.from([26,97,138,203,132,171,141,252]),updatePlatformCurveParam:Buffer.from([138,144,138,250,220,128,4,57]),removePlatformCurveParam:Buffer.from([27,30,62,169,93,224,24,145])};function Or(n,e,t,i,r,o,s,a,c,u,l,m,d,p,f,b,g,w,A,B,k){let P=q([W("decimals"),Ae("name"),Ae("symbol"),Ae("uri")]),h=q([y("totalLockedAmount"),y("cliffPeriod"),y("unlockPeriod"),W("cpmmCreatorFeeOn")]),C=q([W("index"),y("supply"),y("totalFundRaisingB"),W("migrateType")]),I=q([W("index"),y("supply"),y("totalSellA"),y("totalFundRaisingB"),W("migrateType")]),N=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!0,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:m,isSigner:!1,isWritable:!0},{pubkey:bi,isSigner:!1,isWritable:!1},{pubkey:bi,isSigner:!1,isWritable:!1},{pubkey:ft,isSigner:!1,isWritable:!1},{pubkey:Se.programId,isSigner:!1,isWritable:!1},{pubkey:Mn,isSigner:!1,isWritable:!1},{pubkey:at(n).publicKey,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1}],F=Buffer.alloc(Buffer.from(p,"utf-8").length+Buffer.from(f,"utf-8").length+Buffer.from(b,"utf-8").length+4*3+1),S=Buffer.alloc(h.span),M=Buffer.alloc(g.type==="ConstantCurve"?I.span:C.span);return P.encode({decimals:d,name:p,symbol:f,uri:b},F),g.type==="ConstantCurve"?I.encode(Q(H({index:0},g),{migrateType:g.migrateType==="amm"?0:1}),M):g.type==="FixedCurve"?C.encode(Q(H({index:1},g),{migrateType:g.migrateType==="amm"?0:1}),M):g.type==="LinearCurve"&&C.encode(Q(H({index:2},g),{migrateType:g.migrateType==="amm"?0:1}),M),h.encode({totalLockedAmount:w,cliffPeriod:A,unlockPeriod:B,cpmmCreatorFeeOn:k},S),new he({keys:N,programId:n,data:Buffer.from([...Be.initializeV2,...F,...M,...S])})}function Dr(n,e,t,i,r,o,s,a,c,u,l,m,d,p,f,b,g,w,A,B,k){let P=q([W("decimals"),Ae("name"),Ae("symbol"),Ae("uri")]),h=q([y("totalLockedAmount"),y("cliffPeriod"),y("unlockPeriod"),W("cpmmCreatorFeeOn"),W("transferFeeExtensionParamsOption"),q([Ge("transferFeeBasePoints"),y("maxinumFee")]).replicate("transferFeeExtensionParams")]),C=q([W("index"),y("supply"),y("totalFundRaisingB"),W("migrateType")]),I=q([W("index"),y("supply"),y("totalSellA"),y("totalFundRaisingB"),W("migrateType")]),N=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!0,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:ca,isSigner:!1,isWritable:!1},{pubkey:bi,isSigner:!1,isWritable:!1},{pubkey:Se.programId,isSigner:!1,isWritable:!1},{pubkey:at(n).publicKey,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1}],F=Buffer.alloc(Buffer.from(d,"utf-8").length+Buffer.from(p,"utf-8").length+Buffer.from(f,"utf-8").length+4*3+1),S=Buffer.alloc(h.span),M=Buffer.alloc(b.type==="ConstantCurve"?I.span:C.span);return P.encode({decimals:m,name:d,symbol:p,uri:f},F),b.type==="ConstantCurve"?I.encode(Q(H({index:0},b),{migrateType:b.migrateType==="amm"?0:1}),M):b.type==="FixedCurve"?C.encode(Q(H({index:1},b),{migrateType:b.migrateType==="amm"?0:1}),M):b.type==="LinearCurve"&&C.encode(Q(H({index:2},b),{migrateType:b.migrateType==="amm"?0:1}),M),h.encode({totalLockedAmount:g,cliffPeriod:w,unlockPeriod:A,cpmmCreatorFeeOn:B,transferFeeExtensionParamsOption:k?1:0,transferFeeExtensionParams:k!=null?k:{transferFeeBasePoints:0,maxinumFee:new It(0)}},S),new he({keys:N,programId:n,data:Buffer.from([...Be.initializeWithToken2022,...F,...M,...S])})}function Wr(n,e,t,i,r,o,s,a,c,u,l,m,d,p,f,b,g,w,A,B){let k=q([y("amountB"),y("minAmountA"),y("shareFeeRate")]),P=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,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:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:m,isSigner:!1,isWritable:!1},{pubkey:d,isSigner:!1,isWritable:!1},{pubkey:p,isSigner:!1,isWritable:!1},{pubkey:at(n).publicKey,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1}];B&&P.push({pubkey:B,isSigner:!1,isWritable:!0}),P.push({pubkey:Se.programId,isSigner:!1,isWritable:!1}),P.push({pubkey:f,isSigner:!1,isWritable:!0}),P.push({pubkey:b,isSigner:!1,isWritable:!0});let h=Buffer.alloc(k.span);return k.encode({amountB:g,minAmountA:w,shareFeeRate:A!=null?A:new It(0)},h),new he({keys:P,programId:n,data:Buffer.from([...Be.buyExactIn,...h])})}function Vr(n,e,t,i,r,o,s,a,c,u,l,m,d,p,f,b,g,w,A,B){let k=q([y("amountA"),y("maxAmountB"),y("shareFeeRate")]),P=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,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:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:m,isSigner:!1,isWritable:!1},{pubkey:d,isSigner:!1,isWritable:!1},{pubkey:p,isSigner:!1,isWritable:!1},{pubkey:at(n).publicKey,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1}];B&&P.push({pubkey:B,isSigner:!1,isWritable:!0}),P.push({pubkey:Se.programId,isSigner:!1,isWritable:!1}),P.push({pubkey:f,isSigner:!1,isWritable:!0}),P.push({pubkey:b,isSigner:!1,isWritable:!0});let h=Buffer.alloc(k.span);return k.encode({amountA:g,maxAmountB:w,shareFeeRate:A!=null?A:new It(0)},h),new he({keys:P,programId:n,data:Buffer.from([...Be.buyExactOut,...h])})}function _r(n,e,t,i,r,o,s,a,c,u,l,m,d,p,f,b,g,w,A,B){let k=q([y("amountA"),y("minAmountB"),y("shareFeeRate")]),P=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,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:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:m,isSigner:!1,isWritable:!1},{pubkey:d,isSigner:!1,isWritable:!1},{pubkey:p,isSigner:!1,isWritable:!1},{pubkey:at(n).publicKey,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1}];B&&P.push({pubkey:B,isSigner:!1,isWritable:!0}),P.push({pubkey:Se.programId,isSigner:!1,isWritable:!1}),P.push({pubkey:f,isSigner:!1,isWritable:!0}),P.push({pubkey:b,isSigner:!1,isWritable:!0});let h=Buffer.alloc(k.span);return k.encode({amountA:g,minAmountB:w,shareFeeRate:A!=null?A:new It(0)},h),new he({keys:P,programId:n,data:Buffer.from([...Be.sellExactIn,...h])})}function qr(n,e,t,i,r,o,s,a,c,u,l,m,d,p,f,b,g,w,A,B){let k=q([y("amountB"),y("maxAmountA"),y("shareFeeRate")]),P=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,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:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:m,isSigner:!1,isWritable:!1},{pubkey:d,isSigner:!1,isWritable:!1},{pubkey:p,isSigner:!1,isWritable:!1},{pubkey:at(n).publicKey,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1}];B&&P.push({pubkey:B,isSigner:!1,isWritable:!0}),P.push({pubkey:Se.programId,isSigner:!1,isWritable:!1}),P.push({pubkey:f,isSigner:!1,isWritable:!0}),P.push({pubkey:b,isSigner:!1,isWritable:!0});let h=Buffer.alloc(k.span);return k.encode({amountB:g,maxAmountA:w,shareFeeRate:A!=null?A:new It(0)},h),new he({keys:P,programId:n,data:Buffer.from([...Be.sellExactOut,...h])})}function yi(n,e,t,i,r,o,s,a,c){let u=q([]),l=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!1},{pubkey:Se.programId,isSigner:!1,isWritable:!1},{pubkey:dn,isSigner:!1,isWritable:!1}],m=Buffer.alloc(u.span);return u.encode({},m),new he({keys:l,programId:n,data:Buffer.from([...Be.claimVestedToken,...m])})}function gi(n,e,t,i,r,o){let s=q([y("shareAmount")]),a=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:Se.programId,isSigner:!1,isWritable:!1}],c=Buffer.alloc(s.span);return s.encode({shareAmount:o},c),new he({keys:a,programId:n,data:Buffer.from([...Be.createVestingAccount,...c])})}function Pi(n,e,t,i,r,o,s,a,c){let u=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,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.programId,isSigner:!1,isWritable:!0},{pubkey:dn,isSigner:!1,isWritable:!0}];return new he({keys:u,programId:n,data:Be.claimPlatformFee})}function Gr(n,e,t,i,r,o,s,a,c,u,l,m,d){let p=q([y("platformScale"),y("creatorScale"),y("burnScale"),y("feeRate"),Ae("name"),Ae("web"),Ae("img"),y("creatorFeeRate")]),f=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:Se.programId,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1}],b=Buffer.alloc(8*5+Buffer.from(l,"utf-8").length+Buffer.from(m,"utf-8").length+Buffer.from(d,"utf-8").length+4*3);return p.encode({platformScale:a.platformScale,creatorScale:a.creatorScale,burnScale:a.burnScale,feeRate:c,name:l,web:m,img:d,creatorFeeRate:u},b),new he({keys:f,programId:n,data:Buffer.from([...Be.createPlatformConfig,...b])})}function Ur(n,e,t,i){let r=[{pubkey:e,isSigner:!0,isWritable:!1},{pubkey:t,isSigner:!1,isWritable:!0}],o;if(i.type==="updateClaimFeeWallet"){let s=q([W("index"),O("value")]);o=Buffer.alloc(s.span),s.encode({index:0,value:i.value},o)}else if(i.type==="updateLockNftWallet"){let s=q([W("index"),O("value")]);o=Buffer.alloc(s.span),s.encode({index:1,value:i.value},o)}else if(i.type==="migrateCpLockNftScale"){let s=q([W("index"),y("platformScale"),y("creatorScale"),y("burnScale")]);o=Buffer.alloc(s.span),s.encode(H({index:2},i.value),o)}else if(i.type==="updateFeeRate"){let s=q([W("index"),y("value")]);o=Buffer.alloc(s.span),s.encode({index:3,value:i.value},o)}else if(i.type==="updateImg"||i.type==="updateName"||i.type==="updateWeb"){let s=q([W("index"),Ae("value")]);o=Buffer.alloc(Buffer.from(i.value,"utf-8").length+4+1*1),i.type==="updateName"?s.encode({index:4,value:i.value},o):i.type==="updateWeb"?s.encode({index:5,value:i.value},o):i.type==="updateImg"&&s.encode({index:6,value:i.value},o)}else if(i.type==="updateCpConfigId"){r.push({pubkey:i.value,isSigner:!1,isWritable:!1});let s=q([W("index")]);o=Buffer.alloc(s.span),s.encode({index:7},o)}else if(i.type==="updateAll"){r.push({pubkey:i.value.cpConfigId,isSigner:!1,isWritable:!1});let s=q([W("index"),O("platformClaimFeeWallet"),O("platformLockNftWallet"),y("platformScale"),y("creatorScale"),y("burnScale"),y("feeRate"),Ae("name"),Ae("web"),Ae("img"),O("transferFeeExtensionAuth"),y("creatorFeeRate")]);o=Buffer.alloc(1+32+32+8*4+4*3+Buffer.from(i.value.name,"utf-8").length+Buffer.from(i.value.web,"utf-8").length+Buffer.from(i.value.img,"utf-8").length+32+8),s.encode({index:8,platformClaimFeeWallet:i.value.platformClaimFeeWallet,platformLockNftWallet:i.value.platformLockNftWallet,platformScale:i.value.migrateCpLockNftScale.platformScale,creatorScale:i.value.migrateCpLockNftScale.creatorScale,burnScale:i.value.migrateCpLockNftScale.burnScale,feeRate:i.value.feeRate,name:i.value.name,web:i.value.web,img:i.value.img,transferFeeExtensionAuth:i.value.transferFeeExtensionAuth,creatorFeeRate:i.value.creatorFeeRate},o)}else throw Error("updateInfo params type error");return new he({keys:r,programId:n,data:Buffer.from([...Be.updatePlaformConfig,...o])})}function wi(n,e,t,i,r,o,s,a){let c=[{pubkey:t,isSigner:!0,isWritable:!0},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:e,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:Se.programId,isSigner:!1,isWritable:!1},{pubkey:dn,isSigner:!1,isWritable:!1}];return new he({keys:c,programId:n,data:Be.claimPlatformFeeFromVault})}function Ai(n,e,t,i,r,o,s){let a=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:Se.programId,isSigner:!1,isWritable:!1},{pubkey:dn,isSigner:!1,isWritable:!1}];return new he({keys:a,programId:n,data:Be.claimCreatorFee})}var sy=new It("18446744073709551615");import{NATIVE_MINT as Xe,TOKEN_2022_PROGRAM_ID as lt,TOKEN_PROGRAM_ID as te,createAssociatedTokenAccountIdempotentInstruction as ke,createSyncNativeInstruction as la,getTransferFeeConfig as Pn,unpackMint as wn}from"@solana/spl-token";import D from"bn.js";import{PublicKey as zr,SystemProgram as ma}from"@solana/web3.js";import Ce from"bn.js";import pn from"bn.js";var $e=class{static getPoolInitPriceByPool({poolInfo:e,decimalA:t,decimalB:i}){throw Error()}static getPoolInitPriceByInit({a:e,b:t,decimalA:i,decimalB:r}){throw Error()}static getPoolPrice({poolInfo:e,decimalA:t,decimalB:i}){throw Error()}static getPoolEndPrice({supply:e,totalSell:t,totalLockedAmount:i,totalFundRaising:r,migrateFee:o,decimalA:s,decimalB:a}){throw Error()}static getPoolEndPriceReal({poolInfo:e,decimalA:t,decimalB:i}){throw Error()}static getInitParam({supply:e,totalFundRaising:t,totalSell:i,totalLockedAmount:r,migrateFee:o}){throw Error()}static buyExactIn({poolInfo:e,amount:t}){throw Error()}static buyExactOut({poolInfo:e,amount:t}){throw Error()}static sellExactIn({poolInfo:e,amount:t}){throw Error()}static sellExactOut({poolInfo:e,amount:t}){throw Error()}};var fn=class extends $e{static getPoolInitPriceByPool({poolInfo:e,decimalA:t,decimalB:i}){return new G(e.virtualB.toString()).div(e.virtualA.toString()).mul(10**(t-i))}static getPoolInitPriceByInit({a:e,b:t,decimalA:i,decimalB:r}){return new G(t.toString()).div(e.toString()).mul(10**(i-r))}static getPoolPrice({poolInfo:e,decimalA:t,decimalB:i}){return new G(e.virtualB.add(e.realB).toString()).div(e.virtualA.sub(e.realA).toString()).mul(10**(t-i))}static getPoolEndPrice({supply:e,totalSell:t,totalLockedAmount:i,totalFundRaising:r,migrateFee:o,decimalA:s,decimalB:a}){return new G(r.sub(o).toString()).div(e.sub(t).sub(i).toString()).mul(10**(s-a))}static getPoolEndPriceReal({poolInfo:e,decimalA:t,decimalB:i}){let r=e.totalSellA.sub(e.realA),o=e.totalFundRaisingB.sub(e.realB);return new G(e.virtualB.add(e.realB.add(o)).toString()).div(e.virtualA.sub(e.realA.add(r)).toString()).mul(10**(t-i))}static getInitParam({supply:e,totalFundRaising:t,totalSell:i,totalLockedAmount:r,migrateFee:o}){if(e.lte(i))throw Error("supply need gt total sell");let s=e.sub(i).sub(r);if(s.lte(new pn(0)))throw Error("supplyMinusSellLocked <= 0");let a=t.sub(o);if(a.lte(new pn(0)))throw Error("tfMinusMf <= 0");let c=a.mul(i).mul(i).div(s),u=a.mul(i).div(s).sub(t),l=c.div(u),m=t.mul(t).div(u);if(l.lt(new pn(0))||m.lt(new pn(0)))throw Error("invalid input 0");return{a:l,b:m,c:i}}static buyExactIn({poolInfo:e,amount:t}){return this.getAmountOut({amountIn:t,inputReserve:e.virtualB.add(e.realB),outputReserve:e.virtualA.sub(e.realA)})}static buyExactOut({poolInfo:e,amount:t}){return this.getAmountIn({amountOut:t,inputReserve:e.virtualB.add(e.realB),outputReserve:e.virtualA.sub(e.realA)})}static sellExactIn({poolInfo:e,amount:t}){return this.getAmountOut({amountIn:t,inputReserve:e.virtualA.sub(e.realA),outputReserve:e.virtualB.add(e.realB)})}static sellExactOut({poolInfo:e,amount:t}){return this.getAmountIn({amountOut:t,inputReserve:e.virtualA.sub(e.realA),outputReserve:e.virtualB.add(e.realB)})}static getAmountOut({amountIn:e,inputReserve:t,outputReserve:i}){let r=e.mul(i),o=t.add(e);return r.div(o)}static getAmountIn({amountOut:e,inputReserve:t,outputReserve:i}){let r=t.mul(e),o=i.sub(e);return rt(r,o)}};import bn from"bn.js";var yn=class extends $e{static getPoolInitPriceByPool({poolInfo:e,decimalA:t,decimalB:i}){return new G(e.virtualB.toString()).div(e.virtualA.toString()).mul(10**(t-i))}static getPoolInitPriceByInit({a:e,b:t,decimalA:i,decimalB:r}){return new G(t.toString()).div(e.toString()).mul(10**(i-r))}static getPoolPrice({poolInfo:e,decimalA:t,decimalB:i}){return new G(e.virtualB.toString()).div(e.virtualA.toString()).mul(10**(t-i))}static getPoolEndPrice({supply:e,totalSell:t,totalLockedAmount:i,totalFundRaising:r,migrateFee:o,decimalA:s,decimalB:a}){return new G(r.sub(o).toString()).div(e.sub(t).sub(i).toString()).mul(10**(s-a))}static getPoolEndPriceReal({poolInfo:e,decimalA:t,decimalB:i}){let r=e.totalSellA.sub(e.realA),o=e.totalFundRaisingB.sub(e.realB);return new G(e.virtualB.add(e.realB).add(o).toString()).div(e.virtualA.sub(e.realA).add(r).toString()).mul(10**(t-i))}static getInitParam({supply:e,totalFundRaising:t,totalSell:i,totalLockedAmount:r,migrateFee:o}){let s=e.sub(r);if(s.lte(new bn(0)))throw Error("invalid input 1");let a=new bn(2).mul(t).sub(o),u=t.mul(s).div(a);if(u.lt(new bn(0))||t.lt(new bn(0)))throw Error("invalid input 0");return{a:u,b:t,c:u}}static buyExactIn({poolInfo:e,amount:t}){return this.getAmountOut({amountIn:t,initInput:e.virtualB,initOutput:e.virtualA})}static buyExactOut({poolInfo:e,amount:t}){return this.getAmountIn({amountOut:t,initInput:e.virtualB,initOutput:e.virtualA})}static sellExactIn({poolInfo:e,amount:t}){return this.getAmountOut({amountIn:t,initInput:e.virtualA,initOutput:e.virtualB})}static sellExactOut({poolInfo:e,amount:t}){return this.getAmountIn({amountOut:t,initInput:e.virtualA,initOutput:e.virtualB})}static getAmountOut({amountIn:e,initInput:t,initOutput:i}){return i.mul(e).div(t)}static getAmountIn({amountOut:e,initInput:t,initOutput:i}){let r=t.mul(e);return rt(r,i)}};import Te from"bn.js";import Xr from"bn.js";var Ut=class{static _multipler(e){return new G(10).pow(e)}static getPrice({priceX64:e,decimalA:t,decimalB:i}){return new G(e.toString()).div(this._Q64).mul(this._multipler(t)).div(this._multipler(i))}static getPriceX64({price:e,decimalA:t,decimalB:i}){let r=e.mul(this._multipler(i)).div(this._multipler(t));return new Xr(r.mul(this._Q64).toFixed(0))}};Ut._Q64=new G(new Xr(1).shln(64).toString());var gn=class extends $e{static getPoolInitPriceByPool({poolInfo:e,decimalA:t,decimalB:i}){return new G(0)}static getPoolInitPriceByInit({a:e,b:t,decimalA:i,decimalB:r}){return new G(0)}static getPoolPrice({poolInfo:e,decimalA:t,decimalB:i}){return new G(e.virtualA.mul(e.realA).toString()).div(Ut._Q64).mul(10**(t-i))}static getPoolEndPrice({supply:e,totalSell:t,totalLockedAmount:i,totalFundRaising:r,migrateFee:o,decimalA:s,decimalB:a}){return new G(r.sub(o).toString()).div(e.sub(t).sub(i).toString()).mul(10**(s-a))}static getPoolEndPriceReal({poolInfo:e,decimalA:t,decimalB:i}){let r=e.totalSellA.sub(e.realA),o=e.totalFundRaisingB.sub(e.realB);return new G(e.virtualB.add(e.realB).add(o).toString()).div(e.virtualA.sub(e.realA).add(r).toString()).mul(10**(t-i))}static getInitParam({supply:e,totalFundRaising:t,totalSell:i,totalLockedAmount:r,migrateFee:o}){let s=e.sub(r);if(s.lte(new Te(0)))throw Error("supplyMinusLocked need gt 0");let a=t.mul(new Te(3)).sub(o),u=t.mul(new Te(2)).mul(s).div(a),l=u.mul(u),m=t.mul(new Te(2)).mul(Oe).div(l);if(!m.gt(new Te(0)))throw Error("a need gt 0");if(!ri.gt(m))throw Error("a need lt u64 max");if(m.lt(new Te(0))||u.lt(new Te(0)))throw Error("invalid input 0");return{a:m,b:new Te(0),c:u}}static buyExactIn({poolInfo:e,amount:t}){let i=e.realB.add(t),r=new Te(2).mul(i).mul(Oe).div(e.virtualA);return new Te(new G(r.toString()).sqrt().toFixed(0)).sub(e.realA)}static buyExactOut({poolInfo:e,amount:t}){let i=e.realA.add(t),r=i.mul(i);return rt(e.virtualA.mul(r),new Te(2).mul(Oe)).sub(e.realB)}static sellExactIn({poolInfo:e,amount:t}){let i=e.realA.sub(t),r=i.mul(i),o=rt(e.virtualA.mul(r),new Te(2).mul(Oe));return e.realB.sub(o)}static sellExactOut({poolInfo:e,amount:t}){let i=e.realB.sub(t),r=new Te(2).mul(i).mul(Oe).div(e.virtualA),o=new Te(new G(r.toString()).sqrt().toFixed(0));return e.realA.sub(o)}};var Ke=class{static getPoolCurvePointByPoolInfo({curveType:e,pointCount:t,poolInfo:i}){return this.getPoolCurvePointByInit({curveType:e,pointCount:t,supply:i.supply,totalFundRaising:i.totalFundRaisingB,totalSell:i.totalSellA,totalLockedAmount:i.vestingSchedule.totalLockedAmount,migrateFee:i.migrateFee,decimalA:i.mintDecimalsA,decimalB:i.mintDecimalsB})}static getPoolCurvePointByInit({curveType:e,pointCount:t,supply:i,totalFundRaising:r,totalSell:o,totalLockedAmount:s,migrateFee:a,decimalA:c,decimalB:u}){if(t<3)throw Error("point count < 3");let l=this.getCurve(e),m=l.getInitParam({supply:i,totalFundRaising:r,totalSell:o,totalLockedAmount:s,migrateFee:a}),d=l.getPoolInitPriceByInit(Q(H({},m),{decimalA:c,decimalB:u})),p=r.div(new Ce(t-1)),f=new Ce(0),b=[{price:d,totalSellSupply:0}],{a:g,b:w}=m,A=f,B=f;for(let k=1;k<t;k++){let P=k!==t-1?p:r.sub(B),h=this.buyExactIn({poolInfo:{virtualA:g,virtualB:w,realA:A,realB:B,totalFundRaisingB:r,totalSellA:o},amountB:P,protocolFeeRate:f,platformFeeRate:f,curveType:e,shareFeeRate:f,creatorFeeRate:f,transferFeeConfigA:void 0,slot:0});A=A.add(h.amountA.amount),B=B.add(h.amountB);let C=this.getPrice({poolInfo:{virtualA:g,virtualB:w,realA:A,realB:B},decimalA:c,decimalB:u,curveType:e});b.push({price:C,totalSellSupply:new G(A.toString()).div(10**c).toNumber()})}return b}static getPoolInitPriceByPool({poolInfo:e,decimalA:t,decimalB:i,curveType:r}){return this.getCurve(r).getPoolInitPriceByPool({poolInfo:e,decimalA:t,decimalB:i})}static getPoolInitPriceByInit({a:e,b:t,decimalA:i,decimalB:r,curveType:o}){return this.getCurve(o).getPoolInitPriceByInit({a:e,b:t,decimalA:i,decimalB:r})}static getPrice({poolInfo:e,curveType:t,decimalA:i,decimalB:r}){return this.getCurve(t).getPoolPrice({poolInfo:e,decimalA:i,decimalB:r})}static getEndPrice({poolInfo:e,curveType:t,decimalA:i,decimalB:r}){return this.getCurve(t).getPoolPrice({poolInfo:e,decimalA:i,decimalB:r})}static getPoolEndPriceReal({poolInfo:e,curveType:t,decimalA:i,decimalB:r}){return this.getCurve(t).getPoolEndPriceReal({poolInfo:e,decimalA:i,decimalB:r})}static checkParam({supply:e,totalFundRaising:t,totalSell:i,totalLockedAmount:r,decimals:o,config:s,migrateType:a}){if(Number(o)!==6)throw Error("decimals = 6");if(e.mul(s.maxLockRate).div(ot).lt(r))throw Error("total lock amount gte max lock amount");if(e.lt(s.minSupplyA.mul(new Ce(10**o))))throw Error("supply lt min supply");let u=e.mul(s.minSellRateA).div(ot);if(i.lt(u))throw Error("invalid input");if(t.lt(s.minFundRaisingB))throw Error("total fund raising lt min fund raising");let l=e.sub(i).sub(r),m=e.mul(s.minMigrateRateA).div(ot);if(l.lt(m))throw Error("migrate lt min migrate amoount");let d=e.sub(i).sub(r),p=new Ce(new G(d.mul(t).toString()).sqrt().toFixed(0));if(a==="amm"){let f=new Ce(10).pow(new Ce(o));if(p.lte(f))throw Error("check migrate lp error")}else if(a==="cpmm"){let f=new Ce(100);if(p.lte(f))throw Error("check migrate lp error")}else throw Error("migrate type error")}static buyExactIn({poolInfo:e,amountB:t,protocolFeeRate:i,platformFeeRate:r,curveType:o,shareFeeRate:s,creatorFeeRate:a,transferFeeConfigA:c,slot:u}){let l=this.totalFeeRate({protocolFeeRate:i,platformFeeRate:r,shareFeeRate:s,creatorFeeRate:a}),m=this.calculateFee({amount:t,feeRate:l}),d=t.sub(m),p=this.getCurve(o),f=p.buyExactIn({poolInfo:e,amount:d}),b=e.totalSellA.sub(e.realA),g,w,A;if(f.gt(b)){g=b;let k=p.buyExactOut({poolInfo:e,amount:g});w=this.calculatePreFee({postFeeAmount:k,feeRate:l}),A=w.sub(k)}else g=f,w=t,A=m;let B=this.splitFee({totalFee:A,protocolFeeRate:i,platformFeeRate:r,shareFeeRate:s,creatorFeeRate:a});return{amountA:qn(g,c,u),amountB:w,splitFee:B}}static buyExactOut({poolInfo:e,amountA:t,protocolFeeRate:i,platformFeeRate:r,curveType:o,shareFeeRate:s,creatorFeeRate:a,transferFeeConfigA:c,slot:u}){let l=e.totalSellA.sub(e.realA),m=Gn(t,c,u),d=m.fee?m.amount.add(m.fee):m.amount;t.gt(l)&&(d=l);let f=this.getCurve(o).buyExactOut({poolInfo:e,amount:d}),b=this.totalFeeRate({protocolFeeRate:i,platformFeeRate:r,shareFeeRate:s,creatorFeeRate:a}),g=this.calculatePreFee({postFeeAmount:f,feeRate:b}),w=g.sub(f),A=this.splitFee({totalFee:w,protocolFeeRate:i,platformFeeRate:r,shareFeeRate:s,creatorFeeRate:a});return{amountA:m,amountB:g,splitFee:A}}static sellExactIn({poolInfo:e,amountA:t,protocolFeeRate:i,platformFeeRate:r,curveType:o,shareFeeRate:s,creatorFeeRate:a,transferFeeConfigA:c,slot:u}){let l=this.getCurve(o),m=qn(t,c,u),d=m.fee?m.amount.sub(m.fee):m.amount,p=l.sellExactIn({poolInfo:e,amount:d}),f=this.calculateFee({amount:p,feeRate:this.totalFeeRate({protocolFeeRate:i,platformFeeRate:r,shareFeeRate:s,creatorFeeRate:a})}),b=this.splitFee({totalFee:f,protocolFeeRate:i,platformFeeRate:r,shareFeeRate:s,creatorFeeRate:a});return{amountA:m,amountB:p.sub(f),splitFee:b}}static sellExactOut({poolInfo:e,amountB:t,protocolFeeRate:i,platformFeeRate:r,curveType:o,shareFeeRate:s,creatorFeeRate:a,transferFeeConfigA:c,slot:u}){let l=this.totalFeeRate({protocolFeeRate:i,platformFeeRate:r,shareFeeRate:s,creatorFeeRate:a}),m=this.calculatePreFee({postFeeAmount:t,feeRate:l});if(e.realB.lt(m))throw Error("Insufficient liquidity");let d=m.sub(t),f=Ke.getCurve(o).sellExactOut({poolInfo:e,amount:m});if(f.gt(e.realA))throw Error();let b=this.splitFee({totalFee:d,protocolFeeRate:i,platformFeeRate:r,shareFeeRate:s,creatorFeeRate:a});return{amountA:Gn(f,c,u),amountB:t,splitFee:b}}static splitFee({totalFee:e,protocolFeeRate:t,platformFeeRate:i,shareFeeRate:r,creatorFeeRate:o}){let s=this.totalFeeRate({protocolFeeRate:t,platformFeeRate:i,shareFeeRate:r,creatorFeeRate:o}),a=s.isZero()?new Ce(0):e.mul(i).div(s),c=s.isZero()?new Ce(0):e.mul(r).div(s),u=s.isZero()?new Ce(0):e.mul(o).div(s),l=e.sub(a).sub(c).sub(u);return{platformFee:a,shareFee:c,protocolFee:l,creatorFee:u}}static calculateFee({amount:e,feeRate:t}){return rr(e,t,ot)}static calculatePreFee({postFeeAmount:e,feeRate:t}){if(t.isZero())return e;let i=e.mul(ot),r=ot.sub(t);return i.add(r).sub(new Ce(1)).div(r)}static totalFeeRate({protocolFeeRate:e,platformFeeRate:t,shareFeeRate:i,creatorFeeRate:r}){if(e.add(t).add(i).add(r).gt(new Ce(1e6)))throw Error("total fee rate gt 1_000_000");return e.add(t).add(i).add(r)}static getCurve(e){switch(e){case 0:return fn;case 1:return yn;case 2:return gn}throw Error("find curve error")}};var An={initPriceX64:new D("515752397214619"),supply:new D(1e15),totalSellA:new D(7931e11),totalFundRaisingB:new D(85e9),totalFundRaisingBUSD:new D(125e8),totalLockedAmount:new D("0"),cliffPeriod:new D("0"),unlockPeriod:new D("0"),decimals:6,virtualA:new D("1073471847374405"),virtualB:new D("30050573465"),realA:new D(0),realB:new D(0),protocolFee:new D(0),platformId:new zr("4Bu96XjU84XjPDSpveTVf6LYGCkfW5FK7SNkREWcEfV4"),vestingSchedule:{totalLockedAmount:new D(0),cliffPeriod:new D(0),unlockPeriod:new D(0),startTime:new D(0),totalAllocatedShare:new D(0)}},et=new D(1e4),Bg=new Set(["USDCoctVLVnvTXBEuP9s8hntucdJokbo17RwHuNXemT","USD1ttGY1N17NEEHLmELoaybftRBUSErhqYiQzvEmuB"]),Ti=class extends At{constructor(e){super(e)}async createLaunchpad(M){var V=M,{programId:e=me,authProgramId:t,platformId:i=An.platformId,mintA:r,decimals:o=6,mintBDecimals:s=9,name:a,symbol:c,uri:u,migrateType:l,configId:m,configInfo:d,platformFeeRate:p,txVersion:f,computeBudgetConfig:b,txTipConfig:g,feePayer:w,buyAmount:A,minMintAAmount:B,slippage:k,associatedOnly:P=!0,checkCreateATAOwner:h=!1,extraSigners:C,token2022:I,transferFeeExtensionParams:N,creatorFeeOn:F=0}=V,S=tt(V,["programId","authProgramId","platformId","mintA","decimals","mintBDecimals","name","symbol","uri","migrateType","configId","configInfo","platformFeeRate","txVersion","computeBudgetConfig","txTipConfig","feePayer","buyAmount","minMintAAmount","slippage","associatedOnly","checkCreateATAOwner","extraSigners","token2022","transferFeeExtensionParams","creatorFeeOn"]);var hi,Bi,xi,Ii,Si,Ci,Ki,Ni,Ri,Li,Fi;let X=this.createTxBuilder(w);t=t!=null?t:De(e).publicKey,I=!!N,I&&(l="cpmm");let x=d;if(!x&&m){let xe=await this.scope.connection.getAccountInfo(m);xe&&(x=Je.decode(xe.data))}x||this.logAndCreateError("config not found");let K=x.mintB,ee=x.curveType,{publicKey:J}=Bt(e,r,K),{publicKey:se}=mi(e,J,r),{publicKey:j}=mi(e,J,K),{publicKey:ae}=ai(r);this.logDebug(`create token: ${r.toBase58()}, mintB: ${K.toBase58()}, decimals A:${o}/B:${s}, config:${m.toBase58()}`),c.length>10&&this.logAndCreateError("Symbol length should shorter than 11"),u||this.logAndCreateError("uri should not empty");let ue=(await this.scope.api.fetchLaunchConfigs()).find(xe=>xe.key.pubKey===m.toBase58()),Z=(hi=S==null?void 0:S.supply)!=null?hi:new D(ue.defaultParams.supplyInit),z=(Bi=S==null?void 0:S.totalSellA)!=null?Bi:new D(ue.defaultParams.totalSellA),ye=(xi=S==null?void 0:S.totalFundRaisingB)!=null?xi:new D(ue.defaultParams.totalFundRaisingB),We=(Ii=S==null?void 0:S.totalLockedAmount)!=null?Ii:new D(0),oe=p;if(!p){let xe=await this.scope.connection.getAccountInfo(i);xe||this.logAndCreateError("platform id not found:",i.toString()),oe=xt.decode(xe.data).feeRate}let ki=Ke.getCurve(x.curveType).getInitParam({supply:Z,totalFundRaising:ye,totalSell:z,totalLockedAmount:We,migrateFee:x.migrateFee}),Xt;try{Xt=await this.scope.token.getTokenInfo(K)}catch{this.logDebug("can not get mintB info from getTokenInfo")}let Ve={epoch:new D(896),bump:254,status:0,mintDecimalsA:o,mintDecimalsB:(Si=Xt==null?void 0:Xt.decimals)!=null?Si:s,supply:Z,totalSellA:z,mintA:new zr(r),mintB:K,virtualA:ki.a,virtualB:ki.b,realA:An.realA,realB:An.realB,migrateFee:x.migrateFee,migrateType:l==="amm"?0:1,protocolFee:An.protocolFee,platformFee:oe,platformId:i,configId:m,vaultA:se,vaultB:j,creator:this.scope.ownerPubKey,totalFundRaisingB:ye,vestingSchedule:{totalLockedAmount:We,cliffPeriod:new D(0),unlockPeriod:new D(0),startTime:new D(0),totalAllocatedShare:new D(0)},mintProgramFlag:I?1:0,cpmmCreatorFeeOn:F},Hr=Ke.getCurve(x.curveType),{c:Yr}=Hr.getInitParam({supply:Ve.supply,totalFundRaising:Ve.totalFundRaisingB,totalLockedAmount:We,totalSell:x.curveType===0?Ve.totalSellA:new D(0),migrateFee:x.migrateFee});try{Ke.checkParam({supply:Ve.supply,totalFundRaising:Ve.totalFundRaisingB,totalSell:Yr,totalLockedAmount:We,decimals:Ve.mintDecimalsA,config:x,migrateType:l}),this.logDebug("check init params success")}catch(xe){this.logAndCreateError(`check create mint params failed, ${xe.message}`)}X.addInstruction({instructions:[I?Dr(e,w!=null?w:this.scope.ownerPubKey,this.scope.ownerPubKey,m,i,t,J,r,K,se,j,o,a,c,u||"https://",{type:ee===0?"ConstantCurve":ee===1?"FixedCurve":ee===2?"LinearCurve":"ConstantCurve",totalSellA:z,migrateType:l,supply:Z,totalFundRaisingB:ye},We,(Ci=S==null?void 0:S.cliffPeriod)!=null?Ci:new D(0),(Ki=S==null?void 0:S.unlockPeriod)!=null?Ki:new D(0),F,N):Or(e,w!=null?w:this.scope.ownerPubKey,this.scope.ownerPubKey,m,i,t,J,r,K,se,j,ae,o,a,c,u||"https://",{type:ee===0?"ConstantCurve":ee===1?"FixedCurve":ee===2?"LinearCurve":"ConstantCurve",totalSellA:z,migrateType:l,supply:Z,totalFundRaisingB:ye},We,(Ni=S==null?void 0:S.cliffPeriod)!=null?Ni:new D(0),(Ri=S==null?void 0:S.unlockPeriod)!=null?Ri:new D(0),F)]});let Tn=I?await this.scope.connection.getEpochInfo():void 0,zt=N?{epoch:BigInt((Tn==null?void 0:Tn.epoch)||0),maximumFee:BigInt((Li=N==null?void 0:N.maxinumFee.toString())!=null?Li:0),transferFeeBasisPoints:(Fi=N==null?void 0:N.transferFeeBasePoints)!=null?Fi:0}:void 0,kn={amountA:{amount:new D(0),fee:void 0,expirationTime:void 0},amountB:new D(0),splitFee:{platformFee:new D(0),shareFee:new D(0),protocolFee:new D(0),creatorFee:new D(0)}},hn;if(C!=null&&C.length&&X.addInstruction({signers:C}),!S.createOnly){let{builder:xe,extInfo:Zr}=await this.buyToken({programId:e,authProgramId:t,mintAProgram:I?lt:void 0,mintA:r,mintB:K,poolInfo:Ve,buyAmount:A,minMintAAmount:B,shareFeeRate:S.shareFeeRate,shareFeeReceiver:S.shareFeeReceiver,configInfo:x,platformFeeRate:oe,slippage:k,associatedOnly:P,checkCreateATAOwner:h,skipCheckMintA:!zt,transferFeeConfigA:zt?{transferFeeConfigAuthority:t,withdrawWithheldAuthority:t,withheldAmount:BigInt(0),olderTransferFee:zt,newerTransferFee:zt}:void 0,fromCreate:!0});X.addInstruction(H({},xe.AllTxData)),kn=H({},Zr),hn=(this.scope.cluster==="devnet"||f===1)&&S.shareFeeReceiver?[xe.allInstructions[0]]:void 0}return X.addTipInstruction(g),f===0?X.sizeCheckBuildV0({computeBudgetConfig:b,swapInfo:kn,splitIns:hn,address:Q(H({},Ve),{poolId:J})}):X.sizeCheckBuild({computeBudgetConfig:b,swapInfo:kn,splitIns:hn,address:Q(H({},Ve),{poolId:J})})}async buyToken({programId:e=me,authProgramId:t,mintA:i,mintAProgram:r=te,mintB:o=Xe,poolInfo:s,configInfo:a,platformFeeRate:c,txVersion:u,computeBudgetConfig:l,txTipConfig:m,feePayer:d,buyAmount:p,minMintAAmount:f,slippage:b,shareFeeRate:g=new D(0),shareFeeReceiver:w,associatedOnly:A=!0,checkCreateATAOwner:B=!1,fromCreate:k=!1,transferFeeConfigA:P,skipCheckMintA:h=!1}){var z,ye,We;p.lte(new D(0))&&this.logAndCreateError("buy amount should gt 0:",p.toString());let C=this.createTxBuilder(d),{publicKey:I}=Bt(e,i,o);t=t!=null?t:De(e).publicKey;let N=P;if(!h)if(N)r=lt;else{let oe=await this.scope.connection.getAccountInfo(i);if(oe&&oe.owner.equals(lt)){r=oe.owner;let mt=wn(i,oe,r);N=Pn(mt)||void 0}}let F=this.scope.account.getAssociatedTokenAccount(i,r),S=o.equals(Xe),M=k&&S,V=M?this.scope.account.getAssociatedTokenAccount(o,te):null,X=S;if(C.addInstruction({instructions:[ke(this.scope.ownerPubKey,F,this.scope.ownerPubKey,i,r),...M?[ke(this.scope.ownerPubKey,V,this.scope.ownerPubKey,o,te),ma.transfer({fromPubkey:this.scope.ownerPubKey,toPubkey:V,lamports:BigInt(p.toString())}),la(V)]:[]]}),!M){let{account:oe,instructionParams:mt}=await this.scope.account.getOrCreateTokenAccount({mint:o,owner:this.scope.ownerPubKey,createInfo:X?{payer:this.scope.ownerPubKey,amount:p}:void 0,skipCloseAccount:!X,notUseTokenAccount:X,associatedOnly:X?!1:A,checkCreateATAOwner:B});oe&&(V=oe),C.addInstruction(mt||{})}V||this.logAndCreateError(`cannot found mintB(${o.toBase58()}) buy token accounts`,"tokenAccounts",this.scope.account.tokenAccounts);let x=s;if(!x){let oe=await this.scope.connection.getAccountInfo(I,{commitment:"processed"});oe||this.logAndCreateError("cannot found pool:",I.toBase58()),x=Fe.decode(oe.data)}let K=a,ee=await qe(this.scope.connection,[K?void 0:x.configId,x.platformId].filter(Boolean).map(oe=>({pubkey:oe})));if(!K){let oe=ee.find(mt=>mt.pubkey.equals(x.configId));(!oe||!oe.accountInfo)&&this.logAndCreateError("config not found: ",x.configId.toBase58()),K=Je.decode(oe.accountInfo.data)}let J=ee.find(oe=>oe.pubkey.equals(x.platformId));(!J||!J.accountInfo)&&this.logAndCreateError("platform info not found: ",x.configId.toBase58());let se=xt.decode(J.accountInfo.data);c=c||se.feeRate;let j=Ke.buyExactIn({poolInfo:x,amountB:p,protocolFeeRate:K.tradeFeeRate,platformFeeRate:c,curveType:K.curveType,shareFeeRate:g,creatorFeeRate:se.creatorFeeRate,transferFeeConfigA:N,slot:await this.scope.connection.getSlot()}),ae=new G(j.amountA.amount.toString()).sub((ye=(z=j.amountA.fee)==null?void 0:z.toString())!=null?ye:0),le=b?new G(et.sub(b).toNumber()/et.toNumber()).clampedTo(0,1):new G(1),ue=f!=null?f:b?new D(ae.mul(le).toFixed(0)):j.amountA.amount.sub((We=j.amountA.fee)!=null?We:new D(0));j.amountB.lt(p)&&console.log(`maximum ${i.toBase58()} amount can buy is ${j.amountA.toString()}, input ${o.toBase58()} amount: ${j.amountB.toString()}`);let Z=w?Le(w,o,te).publicKey:void 0;return Z&&C.addInstruction({instructions:[ke(this.scope.ownerPubKey,Z,w,o)]}),C.addInstruction({instructions:[Wr(e,this.scope.ownerPubKey,t,x.configId,x.platformId,I,F,V,x.vaultA,x.vaultB,i,o,r,te,ut(e,x.platformId,o).publicKey,ct(e,x.creator,o).publicKey,j.amountB.lt(p)?j.amountB:p,ue,g,Z)]}),C.addCustomComputeBudget(l),C.addTipInstruction(m),C.versionBuild({txVersion:u,extInfo:Q(H({},j),{decimalOutAmount:ae,minDecimalOutAmount:new G(ue.toString())})})}async buyTokenExactOut({programId:e=me,authProgramId:t,mintA:i,mintAProgram:r=te,mintB:o=Xe,poolInfo:s,configInfo:a,transferFeeConfigA:c,platformFeeRate:u,txVersion:l,computeBudgetConfig:m,txTipConfig:d,feePayer:p,maxBuyAmount:f,outAmount:b,slippage:g,shareFeeRate:w=new D(0),shareFeeReceiver:A,associatedOnly:B=!0,checkCreateATAOwner:k=!1,skipCheckMintA:P=!1}){b.lte(new D(0))&&this.logAndCreateError("out amount should gt 0:",b.toString());let h=this.createTxBuilder(p),{publicKey:C}=Bt(e,i,o);t=t!=null?t:De(e).publicKey;let I=s;if(!I){let Z=await this.scope.connection.getAccountInfo(C,{commitment:"processed"});Z||this.logAndCreateError("cannot found pool:",C.toBase58()),I=Fe.decode(Z.data)}let N=a,F=await qe(this.scope.connection,[N?void 0:I.configId,I.platformId].filter(Boolean).map(Z=>({pubkey:Z})));if(!N){let Z=F.find(z=>z.pubkey.equals(I.configId));(!Z||!Z.accountInfo)&&this.logAndCreateError("config not found: ",I.configId.toBase58()),N=Je.decode(Z.accountInfo.data)}let S=F.find(Z=>Z.pubkey.equals(I.platformId));(!S||!S.accountInfo)&&this.logAndCreateError("platform info not found: ",I.configId.toBase58());let M=xt.decode(S.accountInfo.data);u=u||M.feeRate;let V=c;if(!P)if(V)r=lt;else{let Z=await this.scope.connection.getAccountInfo(i);if(Z&&Z.owner.equals(lt)){r=Z.owner;let z=wn(i,Z,r);V=Pn(z)||void 0}}let X=Ke.buyExactOut({poolInfo:I,amountA:b,protocolFeeRate:N.tradeFeeRate,platformFeeRate:u,curveType:N.curveType,shareFeeRate:w,creatorFeeRate:M.creatorFeeRate,transferFeeConfigA:V,slot:await this.scope.connection.getSlot()}),x=new G(X.amountB.toString()),K=g?new G(et.add(g).toNumber()/et.toNumber()).clampedTo(0,Number.MIN_SAFE_INTEGER):new G(1),ee=(f!=null?f:g)?new D(x.mul(K).toFixed(0)):X.amountB,J=this.scope.account.getAssociatedTokenAccount(i,r),se=null,j=o.equals(Xe);h.addInstruction({instructions:[ke(this.scope.ownerPubKey,J,this.scope.ownerPubKey,i,r)]});let{account:ae,instructionParams:le}=await this.scope.account.getOrCreateTokenAccount({mint:o,owner:this.scope.ownerPubKey,createInfo:j?{payer:this.scope.ownerPubKey,amount:X.amountB}:void 0,skipCloseAccount:!j,notUseTokenAccount:j,associatedOnly:j?!1:B,checkCreateATAOwner:k});ae&&(se=ae),h.addInstruction(le||{}),se===void 0&&this.logAndCreateError(`cannot found mintB(${o.toBase58()}) token accounts`,"tokenAccounts",this.scope.account.tokenAccounts);let ue=A?Le(A,o,te).publicKey:void 0;return ue&&h.addInstruction({instructions:[ke(this.scope.ownerPubKey,ue,A,o)]}),h.addInstruction({instructions:[Vr(e,this.scope.ownerPubKey,t,I.configId,I.platformId,C,J,se,I.vaultA,I.vaultB,i,o,r,te,ut(e,I.platformId,o).publicKey,ct(e,I.creator,o).publicKey,b,ee,w,ue)]}),h.addCustomComputeBudget(m),h.addTipInstruction(d),h.versionBuild({txVersion:l,extInfo:{maxSpentAmount:ee,outAmount:b}})}async sellToken({programId:e=me,authProgramId:t,mintAProgram:i=te,mintA:r,mintB:o=Xe,poolInfo:s,configInfo:a,platformFeeRate:c,txVersion:u,computeBudgetConfig:l,txTipConfig:m,feePayer:d,sellAmount:p,minAmountB:f,slippage:b,shareFeeRate:g=new D(0),shareFeeReceiver:w,associatedOnly:A=!0,checkCreateATAOwner:B=!1,skipCheckMintA:k=!1}){t=t!=null?t:De(e).publicKey;let P=this.createTxBuilder(d);p.lte(new D(0))&&this.logAndCreateError("sell amount should be gt 0");let{publicKey:h}=Bt(e,r,o),C;if(!k){let z=await this.scope.connection.getAccountInfo(r);if(z&&z.owner.equals(lt)){i=z.owner;let ye=wn(r,z,i);C=Pn(ye)||void 0}}let I=null,N=null,F=o.equals(Xe),{account:S,instructionParams:M}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:i,mint:r,owner:this.scope.ownerPubKey,createInfo:void 0,skipCloseAccount:!0,notUseTokenAccount:!1,associatedOnly:A,checkCreateATAOwner:B});S&&(I=S),P.addInstruction(M||{}),I===void 0&&this.logAndCreateError("cannot found mintA token accounts","tokenAccounts",this.scope.account.tokenAccounts);let{account:V,instructionParams:X}=await this.scope.account.getOrCreateTokenAccount({mint:o,owner:this.scope.ownerPubKey,createInfo:F?{payer:this.scope.ownerPubKey,amount:0}:void 0,skipCloseAccount:!F,notUseTokenAccount:F,associatedOnly:F?!1:A,checkCreateATAOwner:B});V&&(N=V),P.addInstruction(X||{}),N===void 0&&this.logAndCreateError("cannot found mintB token accounts","tokenAccounts",this.scope.account.tokenAccounts);let x=s;if(!x){let z=await this.scope.connection.getAccountInfo(h,{commitment:"processed"});z||this.logAndCreateError("cannot found pool",h.toBase58()),x=Fe.decode(z.data)}let K=a,ee=await qe(this.scope.connection,[K?void 0:x.configId,x.platformId].filter(Boolean).map(z=>({pubkey:z})));if(!K){let z=ee.find(ye=>ye.pubkey.equals(x.configId));(!z||!z.accountInfo)&&this.logAndCreateError("config not found: ",x.configId.toBase58()),K=Je.decode(z.accountInfo.data)}let J=ee.find(z=>z.pubkey.equals(x.platformId));(!J||!J.accountInfo)&&this.logAndCreateError("platform info not found: ",x.configId.toBase58());let se=xt.decode(J.accountInfo.data);c=c||se.feeRate;let j=Ke.sellExactIn({poolInfo:x,amountA:p,protocolFeeRate:K.tradeFeeRate,platformFeeRate:c,curveType:K.curveType,shareFeeRate:g,creatorFeeRate:se.creatorFeeRate,transferFeeConfigA:C,slot:await this.scope.connection.getSlot()}),ae=new G(j.amountB.toString()),le=b?new G(et.sub(b).toNumber()/et.toNumber()).clampedTo(0,1):new G(1),ue=f!=null?f:b?new D(ae.mul(le).toFixed(0)):j.amountB;ue.lte(new D(0))&&this.logAndCreateError(`out ${o.toBase58()} amount should be gt 0`);let Z=w?Le(w,o,te).publicKey:void 0;return Z&&P.addInstruction({instructions:[ke(this.scope.ownerPubKey,Z,w,o)]}),P.addInstruction({instructions:[_r(e,this.scope.ownerPubKey,t,x.configId,x.platformId,h,I,N,x.vaultA,x.vaultB,r,o,i,te,ut(e,x.platformId,o).publicKey,ct(e,x.creator,o).publicKey,j.amountA.amount.lt(p)?j.amountA.amount:p,ue,g,Z)]}),P.addCustomComputeBudget(l),P.addTipInstruction(m),P.versionBuild({txVersion:u,extInfo:{outAmount:ue}})}async sellTokenExactOut({programId:e=me,authProgramId:t,mintAProgram:i=te,mintA:r,mintB:o=Xe,poolInfo:s,configInfo:a,platformFeeRate:c,txVersion:u,computeBudgetConfig:l,txTipConfig:m,feePayer:d,inAmount:p,maxSellAmount:f,slippage:b,shareFeeRate:g=new D(0),shareFeeReceiver:w,associatedOnly:A=!0,checkCreateATAOwner:B=!1,skipCheckMintA:k=!1}){t=t!=null?t:De(e).publicKey;let P=this.createTxBuilder(d);f!=null&&f.lte(new D(0))&&this.logAndCreateError("max sell amount should be gt 0");let{publicKey:h}=Bt(e,r,o),C;if(!k){let z=await this.scope.connection.getAccountInfo(r);if(z&&z.owner.equals(lt)){i=z.owner;let ye=wn(r,z,i);C=Pn(ye)||void 0}}let I=null,N=null,F=o.equals(Xe),{account:S,instructionParams:M}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:i,mint:r,owner:this.scope.ownerPubKey,createInfo:void 0,skipCloseAccount:!0,notUseTokenAccount:!1,associatedOnly:A,checkCreateATAOwner:B});S&&(I=S),P.addInstruction(M||{}),I===void 0&&this.logAndCreateError("cannot found mintA token accounts","tokenAccounts",this.scope.account.tokenAccounts);let{account:V,instructionParams:X}=await this.scope.account.getOrCreateTokenAccount({mint:o,owner:this.scope.ownerPubKey,createInfo:F?{payer:this.scope.ownerPubKey,amount:0}:void 0,skipCloseAccount:!F,notUseTokenAccount:F,associatedOnly:F?!1:A,checkCreateATAOwner:B});V&&(N=V),P.addInstruction(X||{}),N===void 0&&this.logAndCreateError("cannot found mintB token accounts","tokenAccounts",this.scope.account.tokenAccounts);let x=s;if(!x){let z=await this.scope.connection.getAccountInfo(h,{commitment:"processed"});z||this.logAndCreateError("cannot found pool",h.toBase58()),x=Fe.decode(z.data)}let K=a,ee=await qe(this.scope.connection,[K?void 0:x.configId,x.platformId].filter(Boolean).map(z=>({pubkey:z})));if(!K){let z=ee.find(ye=>ye.pubkey.equals(x.configId));(!z||!z.accountInfo)&&this.logAndCreateError("config not found: ",x.configId.toBase58()),K=Je.decode(z.accountInfo.data)}let J=ee.find(z=>z.pubkey.equals(x.platformId));(!J||!J.accountInfo)&&this.logAndCreateError("platform info not found: ",x.configId.toBase58());let se=xt.decode(J.accountInfo.data);c=c||se.feeRate;let j=Ke.sellExactOut({poolInfo:x,amountB:p,protocolFeeRate:K.tradeFeeRate,platformFeeRate:c,curveType:K.curveType,shareFeeRate:g,creatorFeeRate:se.creatorFeeRate,transferFeeConfigA:C,slot:await this.scope.connection.getSlot()}),ae=new G(j.amountA.amount.toString()),le=b?new G(et.add(b).toNumber()/et.toNumber()).clampedTo(0,Number.MAX_SAFE_INTEGER):new G(1),ue=(f!=null?f:b)?new D(ae.mul(le).toFixed(0)):j.amountA.amount,Z=w?Le(w,o,te).publicKey:void 0;return Z&&P.addInstruction({instructions:[ke(this.scope.ownerPubKey,Z,w,o)]}),P.addInstruction({instructions:[qr(e,this.scope.ownerPubKey,t,x.configId,x.platformId,h,I,N,x.vaultA,x.vaultB,r,o,i,te,ut(e,x.platformId,o).publicKey,ct(e,x.creator,o).publicKey,p,ue,g,Z)]}),P.addCustomComputeBudget(l),P.addTipInstruction(m),P.versionBuild({txVersion:u,extInfo:{maxSellAmount:ue}})}async createPlatformConfig({programId:e=me,platformAdmin:t,platformClaimFeeWallet:i,platformLockNftWallet:r,cpConfigId:o,migrateCpLockNftScale:s,transferFeeExtensionAuth:a,creatorFeeRate:c,feeRate:u,name:l,web:m,img:d,txVersion:p,computeBudgetConfig:f,txTipConfig:b,feePayer:g}){let w=this.createTxBuilder(g),{publicKey:A}=di(e,t);return w.addInstruction({instructions:[Gr(e,t,i,r,A,o,a,s,u,c,l,m,d)]}),w.addCustomComputeBudget(f),w.addTipInstruction(b),w.versionBuild({txVersion:p,extInfo:{platformId:A}})}async updatePlatformConfig({programId:e=me,platformAdmin:t,platformId:i,updateInfo:r,txVersion:o,computeBudgetConfig:s,txTipConfig:a,feePayer:c}){let u=this.createTxBuilder(c),l=i!=null?i:di(e,t).publicKey;return u.addInstruction({instructions:[Ur(e,t,l,r)]}),u.addCustomComputeBudget(s),u.addTipInstruction(a),u.versionBuild({txVersion:o})}async claimPlatformFee({programId:e=me,authProgramId:t,platformId:i,poolId:r,platformClaimFeeWallet:o,mintB:s,vaultB:a,mintBProgram:c=te,txVersion:u,computeBudgetConfig:l,txTipConfig:m,feePayer:d}){var w;let p=this.createTxBuilder(d);t=t!=null?t:De(e).publicKey;let f=s,b=a;if(!f){let A=await this.scope.connection.getAccountInfo(r,{commitment:"processed"});A||this.logAndCreateError("cannot found pool:",r.toBase58());let B=Fe.decode(A.data),k=await this.scope.connection.getAccountInfo(B.configId,{commitment:"processed"});k||this.logAndCreateError("cannot found config:",B.configId.toBase58()),f=Je.decode(k.data).mintB,b=b!=null?b:B.vaultB}(!f||!b)&&this.logAndCreateError("cannot found mint info, mintB: ",f.toBase58(),", vaultB: ",(w=b==null?void 0:b.toBase58())!=null?w:"");let g=Le(this.scope.ownerPubKey,f,te).publicKey;return p.addInstruction({instructions:[ke(this.scope.ownerPubKey,g,this.scope.ownerPubKey,f)]}),p.addInstruction({instructions:[Pi(e,o,t,r,i,b,g,f,c)]}),p.addCustomComputeBudget(l),p.addTipInstruction(m),p.versionBuild({txVersion:u})}async claimAllPlatformFee({programId:e=me,authProgramId:t,platformId:i,platformClaimFeeWallet:r,txVersion:o,computeBudgetConfig:s,txTipConfig:a,feePayer:c}){let u=this.createTxBuilder(c);return t=t!=null?t:De(e).publicKey,(await this.scope.connection.getProgramAccounts(e,{filters:[{dataSize:Fe.span},{memcmp:{offset:Fe.offsetOf("platformId"),bytes:i.toString()}}]})).forEach(m=>{let d=Fe.decode(m.account.data);if(d.platformFee.lte(new D(0)))return;let p=Le(this.scope.ownerPubKey,d.mintB,te).publicKey;u.addInstruction({instructions:[ke(this.scope.ownerPubKey,p,this.scope.ownerPubKey,d.mintB)]}),u.addInstruction({instructions:[Pi(e,r,t,m.pubkey,i,d.vaultB,p,d.mintB,te)]})}),u.addTipInstruction(a),o===0?u.sizeCheckBuildV0({computeBudgetConfig:s}):u.sizeCheckBuild({computeBudgetConfig:s})}async createVesting({programId:e=me,poolId:t,beneficiary:i,shareAmount:r,txVersion:o,computeBudgetConfig:s,txTipConfig:a,feePayer:c}){let u=this.createTxBuilder(c),l=await this.getRpcPoolInfo({poolId:t});r.add(l.vestingSchedule.totalAllocatedShare).gt(l.vestingSchedule.totalLockedAmount)&&this.logAndCreateError("share amount exceed total locked amount");let m=Gt(e,t,i).publicKey;return u.addInstruction({instructions:[gi(e,this.scope.ownerPubKey,i,t,m,r)]}),u.addCustomComputeBudget(s),u.addTipInstruction(a),u.versionBuild({txVersion:o})}async createMultipleVesting({programId:e=me,poolId:t,beneficiaryList:i,txVersion:r,computeBudgetConfig:o,feePayer:s}){let a=this.createTxBuilder(s);i.length===0&&this.logAndCreateError("beneficiaryList is null");let c=await this.getRpcPoolInfo({poolId:t});return i.reduce((l,m)=>l.add(m.shareAmount),c.vestingSchedule.totalAllocatedShare).gt(c.vestingSchedule.totalLockedAmount)&&this.logAndCreateError("share amount exceed total locked amount"),i.forEach(l=>{let m=Gt(e,t,l.wallet).publicKey;a.addInstruction({instructions:[gi(e,this.scope.ownerPubKey,l.wallet,t,m,l.shareAmount)]})}),r===0?a.sizeCheckBuildV0({computeBudgetConfig:o}):a.sizeCheckBuild({computeBudgetConfig:o})}async claimVesting({programId:e=me,poolId:t,poolInfo:i,vestingRecord:r,txVersion:o,computeBudgetConfig:s,txTipConfig:a,feePayer:c}){let u=this.createTxBuilder(c),l=De(e).publicKey,m=r||Gt(e,t,this.scope.ownerPubKey).publicKey,d=i;if(!d){let f=await this.scope.connection.getAccountInfo(t);f||this.logAndCreateError("pool not found"),d=Fe.decode(f.data)}let p=Le(this.scope.ownerPubKey,d.mintA,te).publicKey;return u.addInstruction({instructions:[ke(this.scope.ownerPubKey,p,this.scope.ownerPubKey,d.mintA)]}),u.addInstruction({instructions:[yi(e,this.scope.ownerPubKey,l,t,m,p,d.vaultA,d.mintA,te)]}),u.addCustomComputeBudget(s),u.addTipInstruction(a),u.versionBuild({txVersion:o})}async claimMultiVesting({programId:e=me,poolIdList:t,poolsInfo:i={},vestingRecords:r={},txVersion:o,computeBudgetConfig:s,feePayer:a}){let c=this.createTxBuilder(a),u=H({},i),l=De(e).publicKey,m=t.filter(d=>!u[d.toBase58()]);if(m.length){let d=await this.getRpcPoolsInfo({poolIdList:m});u=H(H({},u),d.poolInfoMap)}return t.forEach(d=>{let p=d.toBase58(),f=u[p];f||this.logAndCreateError(`pool info not found: ${p}`);let b=r[p]||Gt(e,d,this.scope.ownerPubKey).publicKey,g=Le(this.scope.ownerPubKey,f.mintA,te).publicKey;c.addInstruction({instructions:[ke(this.scope.ownerPubKey,g,this.scope.ownerPubKey,f.mintA)]}),c.addInstruction({instructions:[yi(e,this.scope.ownerPubKey,l,d,b,g,f.vaultA,f.mintA,te)]})}),o===0?c.sizeCheckBuildV0({computeBudgetConfig:s}):c.sizeCheckBuild({computeBudgetConfig:s})}async claimVaultPlatformFee({programId:e=me,platformId:t,mintB:i,mintBProgram:r=te,claimFeeWallet:o,txVersion:s,computeBudgetConfig:a,txTipConfig:c,feePayer:u}){let l=this.createTxBuilder(u),m=ut(e,t,i).publicKey,d=pi(e).publicKey,p=this.scope.account.getAssociatedTokenAccount(i,r);return l.addInstruction({instructions:[ke(this.scope.ownerPubKey,p,this.scope.ownerPubKey,i,r),wi(e,t,o!=null?o:this.scope.ownerPubKey,d,m,p,i,r)]}),l.addCustomComputeBudget(a),l.addTipInstruction(c),l.versionBuild({txVersion:s})}async claimMultipleVaultPlatformFee({programId:e=me,platformList:t,unwrapSol:i=!0,txVersion:r,computeBudgetConfig:o,feePayer:s,associatedOnly:a=!0,checkCreateATAOwner:c=!1}){let u=this.createTxBuilder(s),l={};return t.forEach(async m=>{var g,w;let d=pi(e).publicKey,p=ut(e,m.id,m.mintB).publicKey,f=m.mintB.equals(Xe)&&i,b=l[m.mintB.toBase58()];if(!b){let{account:A,instructionParams:B}=await this.scope.account.getOrCreateTokenAccount({mint:m.mintB,owner:this.scope.ownerPubKey,createInfo:f?{payer:this.scope.ownerPubKey,amount:0}:void 0,skipCloseAccount:!f,notUseTokenAccount:f,associatedOnly:f?!1:a,checkCreateATAOwner:c});A&&(b=A),u.addInstruction(B||{}),b===void 0&&this.logAndCreateError(`cannot found platform ${m.id.toBase58()} mintB(${m.mintB.toBase58()}) token accounts`,"tokenAccounts",this.scope.account.tokenAccounts)}u.addInstruction({instructions:[wi(e,m.id,(g=m.claimFeeWallet)!=null?g:this.scope.ownerPubKey,p,d,b,m.mintB,(w=m.mintBProgram)!=null?w:te)]})}),r===0?u.sizeCheckBuildV0({computeBudgetConfig:o}):u.sizeCheckBuild({computeBudgetConfig:o})}async claimCreatorFee({programId:e=me,mintB:t,mintBProgram:i=te,txVersion:r,computeBudgetConfig:o,txTipConfig:s,feePayer:a}){let c=this.createTxBuilder(a),u=ct(e,this.scope.ownerPubKey,t).publicKey,l=fi(e).publicKey,m=this.scope.account.getAssociatedTokenAccount(t,i);return c.addInstruction({instructions:[ke(this.scope.ownerPubKey,m,this.scope.ownerPubKey,t,i),Ai(e,this.scope.ownerPubKey,l,u,m,t,i)]}),c.addCustomComputeBudget(o),c.addTipInstruction(s),c.versionBuild({txVersion:r})}async claimMultipleCreatorFee({programId:e=me,mintBList:t,txVersion:i,computeBudgetConfig:r,feePayer:o}){let s=this.createTxBuilder(o);return t.forEach(a=>{var p;let c=a.pubKey,u=(p=a.programId)!=null?p:te,l=ct(e,this.scope.ownerPubKey,c).publicKey,m=fi(e).publicKey,d=this.scope.account.getAssociatedTokenAccount(c,u);s.addInstruction({instructions:[ke(this.scope.ownerPubKey,d,this.scope.ownerPubKey,c,u),Ai(e,this.scope.ownerPubKey,m,l,d,c,u)]})}),i==0?s.sizeCheckBuildV0({computeBudgetConfig:r}):s.sizeCheckBuild({computeBudgetConfig:r})}async getRpcPoolInfo({poolId:e}){return(await this.getRpcPoolsInfo({poolIdList:[e]})).poolInfoMap[e.toBase58()]}async getRpcPoolsInfo({poolIdList:e,config:t}){let i=await qe(this.scope.connection,e.map(c=>({pubkey:c})),t),r={},o=[];for(let c=0;c<e.length;c++){let u=i[c];if(u===null||!u.accountInfo)throw Error("fetch pool info error: "+e[c].toBase58());let l=Fe.decode(u.accountInfo.data);r[e[c].toBase58()]=Q(H({},l),{poolId:e[c],programId:u.accountInfo.owner}),o.push(l.configId)}let s=await qe(this.scope.connection,o.map(c=>({pubkey:c})),t),a={};for(let c=0;c<o.length;c++){let u=s[c];if(u===null||!u.accountInfo)throw Error("fetch config info error: "+o[c].toBase58());let l=Je.decode(u.accountInfo.data);a[o[c].toBase58()]=Q(H({},l),{configId:u.accountInfo.owner})}return{poolInfoMap:Object.keys(r).reduce((c,u)=>Q(H({},c),{[u]:Q(H({},r[u]),{configInfo:a[r[u].configId.toBase58()]})}),{})}}};export{An as LaunchpadPoolInitParam,Ti as default,Bg as usdMintBSet};
//# sourceMappingURL=launchpad.mjs.map