@raydium-io/raydium-sdk-v2 0.1.1-alpha → 0.1.2-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +1 -1
- package/lib/index.mjs.map +1 -1
- package/lib/raydium/account/account.js +1 -1
- package/lib/raydium/account/account.js.map +1 -1
- package/lib/raydium/account/account.mjs +1 -1
- package/lib/raydium/account/account.mjs.map +1 -1
- package/lib/raydium/index.js +1 -1
- package/lib/raydium/index.js.map +1 -1
- package/lib/raydium/index.mjs +1 -1
- package/lib/raydium/index.mjs.map +1 -1
- package/lib/raydium/raydium.js +1 -1
- package/lib/raydium/raydium.js.map +1 -1
- package/lib/raydium/raydium.mjs +1 -1
- package/lib/raydium/raydium.mjs.map +1 -1
- package/package.json +1 -1
- package/src/raydium/account/account.ts +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var _n=Object.defineProperty,Dn=Object.defineProperties;var Mn=Object.getOwnPropertyDescriptors;var Ke=Object.getOwnPropertySymbols;var Ot=Object.prototype.hasOwnProperty,vt=Object.prototype.propertyIsEnumerable;var Kt=(e,t,n)=>t in e?_n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))Ot.call(t,n)&&Kt(e,n,t[n]);if(Ke)for(var n of Ke(t))vt.call(t,n)&&Kt(e,n,t[n]);return e},re=(e,t)=>Dn(e,Mn(t));var fe=(e,t)=>{var n={};for(var r in e)Ot.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ke)for(var r of Ke(e))t.indexOf(r)<0&&vt.call(e,r)&&(n[r]=e[r]);return n};import{createAssociatedTokenAccountInstruction as Dt,TOKEN_PROGRAM_ID as le,AccountLayout as we,TOKEN_2022_PROGRAM_ID as ko}from"@solana/spl-token";import{PublicKey as it,SystemProgram as Bo}from"@solana/web3.js";import{get as Ft,set as Kn}from"lodash";import Ut from"dayjs";import On from"dayjs/plugin/utc";Ut.extend(On);var st=class{constructor(t){this.logLevel=t.logLevel!==void 0?t.logLevel:0,this.name=t.name}set level(t){this.logLevel=t}get time(){return Ut().utc().format("YYYY/MM/DD HH:mm:ss UTC")}get moduleName(){return this.name}isLogLevel(t){return t<=this.logLevel}error(...t){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...t),this):this}logWithError(...t){let n=t.map(r=>typeof r=="object"?JSON.stringify(r):r).join(", ");throw new Error(n)}warning(...t){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...t),this):this}info(...t){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...t),this):this}debug(...t){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...t),this):this}},Vt={},vn={};function q(e){let t=Ft(Vt,e);if(!t){let n=Ft(vn,e);t=new st({name:e,logLevel:n}),Kn(Vt,e,t)}return t}import{PublicKey as Es}from"@solana/web3.js";import _s from"bn.js";import Gr from"big.js";import fs from"bn.js";import z from"bn.js";var me=9e15,ae=1e9,at="0123456789abcdef",ve="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Fe="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",ct={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-me,maxE:me,crypto:!1},Gt,te,A=!0,Ue="[DecimalError] ",se=Ue+"Invalid argument: ",jt=Ue+"Precision limit exceeded",zt=Ue+"crypto unavailable",Yt="[object Decimal]",H=Math.floor,F=Math.pow,Fn=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Vn=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Un=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Zt=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Z=1e7,P=7,Wn=9007199254740991,qn=ve.length-1,ut=Fe.length-1,m={toStringTag:Yt};m.absoluteValue=m.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),T(e)};m.ceil=function(){return T(new this.constructor(this),this.e+1,2)};m.clampedTo=m.clamp=function(e,t){var n,r=this,o=r.constructor;if(e=new o(e),t=new o(t),!e.s||!t.s)return new o(NaN);if(e.gt(t))throw Error(se+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new o(r)};m.comparedTo=m.cmp=function(e){var t,n,r,o,i=this,s=i.d,a=(e=new i.constructor(e)).d,u=i.s,c=e.s;if(!s||!a)return!u||!c?NaN:u!==c?u:s===a?0:!s^u<0?1:-1;if(!s[0]||!a[0])return s[0]?u:a[0]?-c:0;if(u!==c)return u;if(i.e!==e.e)return i.e>e.e^u<0?1:-1;for(r=s.length,o=a.length,t=0,n=r<o?r:o;t<n;++t)if(s[t]!==a[t])return s[t]>a[t]^u<0?1:-1;return r===o?0:r>o^u<0?1:-1};m.cosine=m.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+P,r.rounding=1,n=Hn(r,en(r,n)),r.precision=e,r.rounding=t,T(te==2||te==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)};m.cubeRoot=m.cbrt=function(){var e,t,n,r,o,i,s,a,u,c,f=this,l=f.constructor;if(!f.isFinite()||f.isZero())return new l(f);for(A=!1,i=f.s*F(f.s*f,1/3),!i||Math.abs(i)==1/0?(n=U(f.d),e=f.e,(i=(e-n.length+1)%3)&&(n+=i==1||i==-2?"0":"00"),i=F(n,1/3),e=H((e+1)/3)-(e%3==(e<0?-1:2)),i==1/0?n="5e"+e:(n=i.toExponential(),n=n.slice(0,n.indexOf("e")+1)+e),r=new l(n),r.s=f.s):r=new l(i.toString()),s=(e=l.precision)+3;;)if(a=r,u=a.times(a).times(a),c=u.plus(f),r=C(c.plus(f).times(a),c.plus(u),s+2,1),U(a.d).slice(0,s)===(n=U(r.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!o&&n=="4999"){if(!o&&(T(a,e+1,0),a.times(a).times(a).eq(f))){r=a;break}s+=4,o=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(T(r,e+1,1),t=!r.times(r).times(r).eq(f));break}return A=!0,T(r,e,l.rounding,t)};m.decimalPlaces=m.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-H(this.e/P))*P,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n};m.dividedBy=m.div=function(e){return C(this,new this.constructor(e))};m.dividedToIntegerBy=m.divToInt=function(e){var t=this,n=t.constructor;return T(C(t,new n(e),0,1,1),n.precision,n.rounding)};m.equals=m.eq=function(e){return this.cmp(e)===0};m.floor=function(){return T(new this.constructor(this),this.e+1,3)};m.greaterThan=m.gt=function(e){return this.cmp(e)>0};m.greaterThanOrEqualTo=m.gte=function(e){var t=this.cmp(e);return t==1||t===0};m.hyperbolicCosine=m.cosh=function(){var e,t,n,r,o,i=this,s=i.constructor,a=new s(1);if(!i.isFinite())return new s(i.s?1/0:NaN);if(i.isZero())return a;n=s.precision,r=s.rounding,s.precision=n+Math.max(i.e,i.sd())+4,s.rounding=1,o=i.d.length,o<32?(e=Math.ceil(o/3),t=(1/qe(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),i=he(s,1,i.times(t),new s(1),!0);for(var u,c=e,f=new s(8);c--;)u=i.times(i),i=a.minus(u.times(f.minus(u.times(f))));return T(i,s.precision=n,s.rounding=r,!0)};m.hyperbolicSine=m.sinh=function(){var e,t,n,r,o=this,i=o.constructor;if(!o.isFinite()||o.isZero())return new i(o);if(t=i.precision,n=i.rounding,i.precision=t+Math.max(o.e,o.sd())+4,i.rounding=1,r=o.d.length,r<3)o=he(i,2,o,o,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,o=o.times(1/qe(5,e)),o=he(i,2,o,o,!0);for(var s,a=new i(5),u=new i(16),c=new i(20);e--;)s=o.times(o),o=o.times(a.plus(s.times(u.times(s).plus(c))))}return i.precision=t,i.rounding=n,T(o,t,n,!0)};m.hyperbolicTangent=m.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,C(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)};m.inverseCosine=m.acos=function(){var e,t=this,n=t.constructor,r=t.abs().cmp(1),o=n.precision,i=n.rounding;return r!==-1?r===0?t.isNeg()?Y(n,o,i):new n(0):new n(NaN):t.isZero()?Y(n,o+4,i).times(.5):(n.precision=o+6,n.rounding=1,t=t.asin(),e=Y(n,o+4,i).times(.5),n.precision=o,n.rounding=i,e.minus(t))};m.inverseHyperbolicCosine=m.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,A=!1,n=n.times(n).minus(1).sqrt().plus(n),A=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)};m.inverseHyperbolicSine=m.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,A=!1,n=n.times(n).plus(1).sqrt().plus(n),A=!0,r.precision=e,r.rounding=t,n.ln())};m.inverseHyperbolicTangent=m.atanh=function(){var e,t,n,r,o=this,i=o.constructor;return o.isFinite()?o.e>=0?new i(o.abs().eq(1)?o.s/0:o.isZero()?o:NaN):(e=i.precision,t=i.rounding,r=o.sd(),Math.max(r,e)<2*-o.e-1?T(new i(o),e,t,!0):(i.precision=n=r-o.e,o=C(o.plus(1),new i(1).minus(o),n+e,1),i.precision=e+4,i.rounding=1,o=o.ln(),i.precision=e,i.rounding=t,o.times(.5))):new i(NaN)};m.inverseSine=m.asin=function(){var e,t,n,r,o=this,i=o.constructor;return o.isZero()?new i(o):(t=o.abs().cmp(1),n=i.precision,r=i.rounding,t!==-1?t===0?(e=Y(i,n+4,r).times(.5),e.s=o.s,e):new i(NaN):(i.precision=n+6,i.rounding=1,o=o.div(new i(1).minus(o.times(o)).sqrt().plus(1)).atan(),i.precision=n,i.rounding=r,o.times(2)))};m.inverseTangent=m.atan=function(){var e,t,n,r,o,i,s,a,u,c=this,f=c.constructor,l=f.precision,p=f.rounding;if(c.isFinite()){if(c.isZero())return new f(c);if(c.abs().eq(1)&&l+4<=ut)return s=Y(f,l+4,p).times(.25),s.s=c.s,s}else{if(!c.s)return new f(NaN);if(l+4<=ut)return s=Y(f,l+4,p).times(.5),s.s=c.s,s}for(f.precision=a=l+10,f.rounding=1,n=Math.min(28,a/P+2|0),e=n;e;--e)c=c.div(c.times(c).plus(1).sqrt().plus(1));for(A=!1,t=Math.ceil(a/P),r=1,u=c.times(c),s=new f(c),o=c;e!==-1;)if(o=o.times(u),i=s.minus(o.div(r+=2)),o=o.times(u),s=i.plus(o.div(r+=2)),s.d[t]!==void 0)for(e=t;s.d[e]===i.d[e]&&e--;);return n&&(s=s.times(2<<n-1)),A=!0,T(s,f.precision=l,f.rounding=p,!0)};m.isFinite=function(){return!!this.d};m.isInteger=m.isInt=function(){return!!this.d&&H(this.e/P)>this.d.length-2};m.isNaN=function(){return!this.s};m.isNegative=m.isNeg=function(){return this.s<0};m.isPositive=m.isPos=function(){return this.s>0};m.isZero=function(){return!!this.d&&this.d[0]===0};m.lessThan=m.lt=function(e){return this.cmp(e)<0};m.lessThanOrEqualTo=m.lte=function(e){return this.cmp(e)<1};m.logarithm=m.log=function(e){var t,n,r,o,i,s,a,u,c=this,f=c.constructor,l=f.precision,p=f.rounding,d=5;if(e==null)e=new f(10),t=!0;else{if(e=new f(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new f(NaN);t=e.eq(10)}if(n=c.d,c.s<0||!n||!n[0]||c.eq(1))return new f(n&&!n[0]?-1/0:c.s!=1?NaN:n?0:1/0);if(t)if(n.length>1)i=!0;else{for(o=n[0];o%10===0;)o/=10;i=o!==1}if(A=!1,a=l+d,s=ie(c,a),r=t?Ve(f,a+10):ie(e,a),u=C(s,r,a,1),Te(u.d,o=l,p))do if(a+=10,s=ie(c,a),r=t?Ve(f,a+10):ie(e,a),u=C(s,r,a,1),!i){+U(u.d).slice(o+1,o+15)+1==1e14&&(u=T(u,l+1,0));break}while(Te(u.d,o+=10,p));return A=!0,T(u,l,p)};m.minus=m.sub=function(e){var t,n,r,o,i,s,a,u,c,f,l,p,d=this,w=d.constructor;if(e=new w(e),!d.d||!e.d)return!d.s||!e.s?e=new w(NaN):d.d?e.s=-e.s:e=new w(e.d||d.s!==e.s?d:NaN),e;if(d.s!=e.s)return e.s=-e.s,d.plus(e);if(c=d.d,p=e.d,a=w.precision,u=w.rounding,!c[0]||!p[0]){if(p[0])e.s=-e.s;else if(c[0])e=new w(d);else return new w(u===3?-0:0);return A?T(e,a,u):e}if(n=H(e.e/P),f=H(d.e/P),c=c.slice(),i=f-n,i){for(l=i<0,l?(t=c,i=-i,s=p.length):(t=p,n=f,s=c.length),r=Math.max(Math.ceil(a/P),s)+2,i>r&&(i=r,t.length=1),t.reverse(),r=i;r--;)t.push(0);t.reverse()}else{for(r=c.length,s=p.length,l=r<s,l&&(s=r),r=0;r<s;r++)if(c[r]!=p[r]){l=c[r]<p[r];break}i=0}for(l&&(t=c,c=p,p=t,e.s=-e.s),s=c.length,r=p.length-s;r>0;--r)c[s++]=0;for(r=p.length;r>i;){if(c[--r]<p[r]){for(o=r;o&&c[--o]===0;)c[o]=Z-1;--c[o],c[r]+=Z}c[r]-=p[r]}for(;c[--s]===0;)c.pop();for(;c[0]===0;c.shift())--n;return c[0]?(e.d=c,e.e=We(c,n),A?T(e,a,u):e):new w(u===3?-0:0)};m.modulo=m.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?T(new r(n),r.precision,r.rounding):(A=!1,r.modulo==9?(t=C(n,e.abs(),0,3,1),t.s*=e.s):t=C(n,e,0,r.modulo,1),t=t.times(e),A=!0,n.minus(t))};m.naturalExponential=m.exp=function(){return lt(this)};m.naturalLogarithm=m.ln=function(){return ie(this)};m.negated=m.neg=function(){var e=new this.constructor(this);return e.s=-e.s,T(e)};m.plus=m.add=function(e){var t,n,r,o,i,s,a,u,c,f,l=this,p=l.constructor;if(e=new p(e),!l.d||!e.d)return!l.s||!e.s?e=new p(NaN):l.d||(e=new p(e.d||l.s===e.s?l:NaN)),e;if(l.s!=e.s)return e.s=-e.s,l.minus(e);if(c=l.d,f=e.d,a=p.precision,u=p.rounding,!c[0]||!f[0])return f[0]||(e=new p(l)),A?T(e,a,u):e;if(i=H(l.e/P),r=H(e.e/P),c=c.slice(),o=i-r,o){for(o<0?(n=c,o=-o,s=f.length):(n=f,r=i,s=c.length),i=Math.ceil(a/P),s=i>s?i+1:s+1,o>s&&(o=s,n.length=1),n.reverse();o--;)n.push(0);n.reverse()}for(s=c.length,o=f.length,s-o<0&&(o=s,n=f,f=c,c=n),t=0;o;)t=(c[--o]=c[o]+f[o]+t)/Z|0,c[o]%=Z;for(t&&(c.unshift(t),++r),s=c.length;c[--s]==0;)c.pop();return e.d=c,e.e=We(c,r),A?T(e,a,u):e};m.precision=m.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(se+e);return n.d?(t=Jt(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t};m.round=function(){var e=this,t=e.constructor;return T(new t(e),e.e+1,t.rounding)};m.sine=m.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+P,r.rounding=1,n=jn(r,en(r,n)),r.precision=e,r.rounding=t,T(te>2?n.neg():n,e,t,!0)):new r(NaN)};m.squareRoot=m.sqrt=function(){var e,t,n,r,o,i,s=this,a=s.d,u=s.e,c=s.s,f=s.constructor;if(c!==1||!a||!a[0])return new f(!c||c<0&&(!a||a[0])?NaN:a?s:1/0);for(A=!1,c=Math.sqrt(+s),c==0||c==1/0?(t=U(a),(t.length+u)%2==0&&(t+="0"),c=Math.sqrt(t),u=H((u+1)/2)-(u<0||u%2),c==1/0?t="5e"+u:(t=c.toExponential(),t=t.slice(0,t.indexOf("e")+1)+u),r=new f(t)):r=new f(c.toString()),n=(u=f.precision)+3;;)if(i=r,r=i.plus(C(s,i,n+2,1)).times(.5),U(i.d).slice(0,n)===(t=U(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!o&&t=="4999"){if(!o&&(T(i,u+1,0),i.times(i).eq(s))){r=i;break}n+=4,o=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(T(r,u+1,1),e=!r.times(r).eq(s));break}return A=!0,T(r,u,f.rounding,e)};m.tangent=m.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=C(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,T(te==2||te==4?n.neg():n,e,t,!0)):new r(NaN)};m.times=m.mul=function(e){var t,n,r,o,i,s,a,u,c,f=this,l=f.constructor,p=f.d,d=(e=new l(e)).d;if(e.s*=f.s,!p||!p[0]||!d||!d[0])return new l(!e.s||p&&!p[0]&&!d||d&&!d[0]&&!p?NaN:!p||!d?e.s/0:e.s*0);for(n=H(f.e/P)+H(e.e/P),u=p.length,c=d.length,u<c&&(i=p,p=d,d=i,s=u,u=c,c=s),i=[],s=u+c,r=s;r--;)i.push(0);for(r=c;--r>=0;){for(t=0,o=u+r;o>r;)a=i[o]+d[r]*p[o-r-1]+t,i[o--]=a%Z|0,t=a/Z|0;i[o]=(i[o]+t)%Z|0}for(;!i[--s];)i.pop();return t?++n:i.shift(),e.d=i,e.e=We(i,n),A?T(e,l.precision,l.rounding):e};m.toBinary=function(e,t){return pt(this,2,e,t)};m.toDecimalPlaces=m.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(j(e,0,ae),t===void 0?t=r.rounding:j(t,0,8),T(n,e+n.e+1,t))};m.toExponential=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=X(r,!0):(j(e,0,ae),t===void 0?t=o.rounding:j(t,0,8),r=T(new o(r),e+1,t),n=X(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+n:n};m.toFixed=function(e,t){var n,r,o=this,i=o.constructor;return e===void 0?n=X(o):(j(e,0,ae),t===void 0?t=i.rounding:j(t,0,8),r=T(new i(o),e+o.e+1,t),n=X(r,!1,e+r.e+1)),o.isNeg()&&!o.isZero()?"-"+n:n};m.toFraction=function(e){var t,n,r,o,i,s,a,u,c,f,l,p,d=this,w=d.d,g=d.constructor;if(!w)return new g(d);if(c=n=new g(1),r=u=new g(0),t=new g(r),i=t.e=Jt(w)-d.e-1,s=i%P,t.d[0]=F(10,s<0?P+s:s),e==null)e=i>0?t:c;else{if(a=new g(e),!a.isInt()||a.lt(c))throw Error(se+a);e=a.gt(t)?i>0?t:c:a}for(A=!1,a=new g(U(w)),f=g.precision,g.precision=i=w.length*P*2;l=C(a,t,0,1,1),o=n.plus(l.times(r)),o.cmp(e)!=1;)n=r,r=o,o=c,c=u.plus(l.times(o)),u=o,o=t,t=a.minus(l.times(o)),a=o;return o=C(e.minus(n),r,0,1,1),u=u.plus(o.times(c)),n=n.plus(o.times(r)),u.s=c.s=d.s,p=C(c,r,i,1).minus(d).abs().cmp(C(u,n,i,1).minus(d).abs())<1?[c,r]:[u,n],g.precision=f,A=!0,p};m.toHexadecimal=m.toHex=function(e,t){return pt(this,16,e,t)};m.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:j(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&(e.s=n.s),e}return e.d[0]?(A=!1,n=C(n,e,0,t,1).times(e),A=!0,T(n)):(e.s=n.s,n=e),n};m.toNumber=function(){return+this};m.toOctal=function(e,t){return pt(this,8,e,t)};m.toPower=m.pow=function(e){var t,n,r,o,i,s,a=this,u=a.constructor,c=+(e=new u(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new u(F(+a,c));if(a=new u(a),a.eq(1))return a;if(r=u.precision,i=u.rounding,e.eq(1))return T(a,r,i);if(t=H(e.e/P),t>=e.d.length-1&&(n=c<0?-c:c)<=Wn)return o=Xt(u,a,n,r),e.s<0?new u(1).div(o):T(o,r,i);if(s=a.s,s<0){if(t<e.d.length-1)return new u(NaN);if((e.d[t]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return n=F(+a,c),t=n==0||!isFinite(n)?H(c*(Math.log("0."+U(a.d))/Math.LN10+a.e+1)):new u(n+"").e,t>u.maxE+1||t<u.minE-1?new u(t>0?s/0:0):(A=!1,u.rounding=a.s=1,n=Math.min(12,(t+"").length),o=lt(e.times(ie(a,r+n)),r),o.d&&(o=T(o,r+5,1),Te(o.d,r,i)&&(t=r+10,o=T(lt(e.times(ie(a,t+n)),t),t+5,1),+U(o.d).slice(r+1,r+15)+1==1e14&&(o=T(o,r+1,0)))),o.s=s,A=!0,u.rounding=i,T(o,r,i))};m.toPrecision=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=X(r,r.e<=o.toExpNeg||r.e>=o.toExpPos):(j(e,1,ae),t===void 0?t=o.rounding:j(t,0,8),r=T(new o(r),e,t),n=X(r,e<=r.e||r.e<=o.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+n:n};m.toSignificantDigits=m.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(j(e,1,ae),t===void 0?t=r.rounding:j(t,0,8)),T(new r(n),e,t)};m.toString=function(){var e=this,t=e.constructor,n=X(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n};m.truncated=m.trunc=function(){return T(new this.constructor(this),this.e+1,1)};m.valueOf=m.toJSON=function(){var e=this,t=e.constructor,n=X(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function U(e){var t,n,r,o=e.length-1,i="",s=e[0];if(o>0){for(i+=s,t=1;t<o;t++)r=e[t]+"",n=P-r.length,n&&(i+=oe(n)),i+=r;s=e[t],r=s+"",n=P-r.length,n&&(i+=oe(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return i+s}function j(e,t,n){if(e!==~~e||e<t||e>n)throw Error(se+e)}function Te(e,t,n,r){var o,i,s,a;for(i=e[0];i>=10;i/=10)--t;return--t<0?(t+=P,o=0):(o=Math.ceil((t+1)/P),t%=P),i=F(10,P-t),a=e[o]%i|0,r==null?t<3?(t==0?a=a/100|0:t==1&&(a=a/10|0),s=n<4&&a==99999||n>3&&a==49999||a==5e4||a==0):s=(n<4&&a+1==i||n>3&&a+1==i/2)&&(e[o+1]/i/100|0)==F(10,t-2)-1||(a==i/2||a==0)&&(e[o+1]/i/100|0)==0:t<4?(t==0?a=a/1e3|0:t==1?a=a/100|0:t==2&&(a=a/10|0),s=(r||n<4)&&a==9999||!r&&n>3&&a==4999):s=((r||n<4)&&a+1==i||!r&&n>3&&a+1==i/2)&&(e[o+1]/i/1e3|0)==F(10,t-3)-1,s}function Oe(e,t,n){for(var r,o=[0],i,s=0,a=e.length;s<a;){for(i=o.length;i--;)o[i]*=t;for(o[0]+=at.indexOf(e.charAt(s++)),r=0;r<o.length;r++)o[r]>n-1&&(o[r+1]===void 0&&(o[r+1]=0),o[r+1]+=o[r]/n|0,o[r]%=n)}return o.reverse()}function Hn(e,t){var n,r,o;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),o=(1/qe(4,n)).toString()):(n=16,o="2.3283064365386962890625e-10"),e.precision+=n,t=he(e,1,t.times(o),new e(1));for(var i=n;i--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return e.precision-=n,t}var C=function(){function e(r,o,i){var s,a=0,u=r.length;for(r=r.slice();u--;)s=r[u]*o+a,r[u]=s%i|0,a=s/i|0;return a&&r.unshift(a),r}function t(r,o,i,s){var a,u;if(i!=s)u=i>s?1:-1;else for(a=u=0;a<i;a++)if(r[a]!=o[a]){u=r[a]>o[a]?1:-1;break}return u}function n(r,o,i,s){for(var a=0;i--;)r[i]-=a,a=r[i]<o[i]?1:0,r[i]=a*s+r[i]-o[i];for(;!r[0]&&r.length>1;)r.shift()}return function(r,o,i,s,a,u){var c,f,l,p,d,w,g,x,h,y,b,k,B,R,D,K,M,G,O,$,ee=r.constructor,xe=r.s==o.s?1:-1,W=r.d,N=o.d;if(!W||!W[0]||!N||!N[0])return new ee(!r.s||!o.s||(W?N&&W[0]==N[0]:!N)?NaN:W&&W[0]==0||!N?xe*0:xe/0);for(u?(d=1,f=r.e-o.e):(u=Z,d=P,f=H(r.e/d)-H(o.e/d)),O=N.length,M=W.length,h=new ee(xe),y=h.d=[],l=0;N[l]==(W[l]||0);l++);if(N[l]>(W[l]||0)&&f--,i==null?(R=i=ee.precision,s=ee.rounding):a?R=i+(r.e-o.e)+1:R=i,R<0)y.push(1),w=!0;else{if(R=R/d+2|0,l=0,O==1){for(p=0,N=N[0],R++;(l<M||p)&&R--;l++)D=p*u+(W[l]||0),y[l]=D/N|0,p=D%N|0;w=p||l<M}else{for(p=u/(N[0]+1)|0,p>1&&(N=e(N,p,u),W=e(W,p,u),O=N.length,M=W.length),K=O,b=W.slice(0,O),k=b.length;k<O;)b[k++]=0;$=N.slice(),$.unshift(0),G=N[0],N[1]>=u/2&&++G;do p=0,c=t(N,b,O,k),c<0?(B=b[0],O!=k&&(B=B*u+(b[1]||0)),p=B/G|0,p>1?(p>=u&&(p=u-1),g=e(N,p,u),x=g.length,k=b.length,c=t(g,b,x,k),c==1&&(p--,n(g,O<x?$:N,x,u))):(p==0&&(c=p=1),g=N.slice()),x=g.length,x<k&&g.unshift(0),n(b,g,k,u),c==-1&&(k=b.length,c=t(N,b,O,k),c<1&&(p++,n(b,O<k?$:N,k,u))),k=b.length):c===0&&(p++,b=[0]),y[l++]=p,c&&b[0]?b[k++]=W[K]||0:(b=[W[K]],k=1);while((K++<M||b[0]!==void 0)&&R--);w=b[0]!==void 0}y[0]||y.shift()}if(d==1)h.e=f,Gt=w;else{for(l=1,p=y[0];p>=10;p/=10)l++;h.e=l+f*d-1,T(h,a?i+h.e+1:i,s,w)}return h}}();function T(e,t,n,r){var o,i,s,a,u,c,f,l,p,d=e.constructor;e:if(t!=null){if(l=e.d,!l)return e;for(o=1,a=l[0];a>=10;a/=10)o++;if(i=t-o,i<0)i+=P,s=t,f=l[p=0],u=f/F(10,o-s-1)%10|0;else if(p=Math.ceil((i+1)/P),a=l.length,p>=a)if(r){for(;a++<=p;)l.push(0);f=u=0,o=1,i%=P,s=i-P+1}else break e;else{for(f=a=l[p],o=1;a>=10;a/=10)o++;i%=P,s=i-P+o,u=s<0?0:f/F(10,o-s-1)%10|0}if(r=r||t<0||l[p+1]!==void 0||(s<0?f:f%F(10,o-s-1)),c=n<4?(u||r)&&(n==0||n==(e.s<0?3:2)):u>5||u==5&&(n==4||r||n==6&&(i>0?s>0?f/F(10,o-s):0:l[p-1])%10&1||n==(e.s<0?8:7)),t<1||!l[0])return l.length=0,c?(t-=e.e+1,l[0]=F(10,(P-t%P)%P),e.e=-t||0):l[0]=e.e=0,e;if(i==0?(l.length=p,a=1,p--):(l.length=p+1,a=F(10,P-i),l[p]=s>0?(f/F(10,o-s)%F(10,s)|0)*a:0),c)for(;;)if(p==0){for(i=1,s=l[0];s>=10;s/=10)i++;for(s=l[0]+=a,a=1;s>=10;s/=10)a++;i!=a&&(e.e++,l[0]==Z&&(l[0]=1));break}else{if(l[p]+=a,l[p]!=Z)break;l[p--]=0,a=1}for(i=l.length;l[--i]===0;)l.pop()}return A&&(e.e>d.maxE?(e.d=null,e.e=NaN):e.e<d.minE&&(e.e=0,e.d=[0])),e}function X(e,t,n){if(!e.isFinite())return $t(e);var r,o=e.e,i=U(e.d),s=i.length;return t?(n&&(r=n-s)>0?i=i.charAt(0)+"."+i.slice(1)+oe(r):s>1&&(i=i.charAt(0)+"."+i.slice(1)),i=i+(e.e<0?"e":"e+")+e.e):o<0?(i="0."+oe(-o-1)+i,n&&(r=n-s)>0&&(i+=oe(r))):o>=s?(i+=oe(o+1-s),n&&(r=n-o-1)>0&&(i=i+"."+oe(r))):((r=o+1)<s&&(i=i.slice(0,r)+"."+i.slice(r)),n&&(r=n-s)>0&&(o+1===s&&(i+="."),i+=oe(r))),i}function We(e,t){var n=e[0];for(t*=P;n>=10;n/=10)t++;return t}function Ve(e,t,n){if(t>qn)throw A=!0,n&&(e.precision=n),Error(jt);return T(new e(ve),t,1,!0)}function Y(e,t,n){if(t>ut)throw Error(jt);return T(new e(Fe),t,n,!0)}function Jt(e){var t=e.length-1,n=t*P+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function oe(e){for(var t="";e--;)t+="0";return t}function Xt(e,t,n,r){var o,i=new e(1),s=Math.ceil(r/P+4);for(A=!1;;){if(n%2&&(i=i.times(t),qt(i.d,s)&&(o=!0)),n=H(n/2),n===0){n=i.d.length-1,o&&i.d[n]===0&&++i.d[n];break}t=t.times(t),qt(t.d,s)}return A=!0,i}function Wt(e){return e.d[e.d.length-1]&1}function Qt(e,t,n){for(var r,o=new e(t[0]),i=0;++i<t.length;)if(r=new e(t[i]),r.s)o[n](r)&&(o=r);else{o=r;break}return o}function lt(e,t){var n,r,o,i,s,a,u,c=0,f=0,l=0,p=e.constructor,d=p.rounding,w=p.precision;if(!e.d||!e.d[0]||e.e>17)return new p(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:0/0);for(t==null?(A=!1,u=w):u=t,a=new p(.03125);e.e>-2;)e=e.times(a),l+=5;for(r=Math.log(F(2,l))/Math.LN10*2+5|0,u+=r,n=i=s=new p(1),p.precision=u;;){if(i=T(i.times(e),u,1),n=n.times(++f),a=s.plus(C(i,n,u,1)),U(a.d).slice(0,u)===U(s.d).slice(0,u)){for(o=l;o--;)s=T(s.times(s),u,1);if(t==null)if(c<3&&Te(s.d,u-r,d,c))p.precision=u+=10,n=i=a=new p(1),f=0,c++;else return T(s,p.precision=w,d,A=!0);else return p.precision=w,s}s=a}}function ie(e,t){var n,r,o,i,s,a,u,c,f,l,p,d=1,w=10,g=e,x=g.d,h=g.constructor,y=h.rounding,b=h.precision;if(g.s<0||!x||!x[0]||!g.e&&x[0]==1&&x.length==1)return new h(x&&!x[0]?-1/0:g.s!=1?NaN:x?0:g);if(t==null?(A=!1,f=b):f=t,h.precision=f+=w,n=U(x),r=n.charAt(0),Math.abs(i=g.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)g=g.times(e),n=U(g.d),r=n.charAt(0),d++;i=g.e,r>1?(g=new h("0."+n),i++):g=new h(r+"."+n.slice(1))}else return c=Ve(h,f+2,b).times(i+""),g=ie(new h(r+"."+n.slice(1)),f-w).plus(c),h.precision=b,t==null?T(g,b,y,A=!0):g;for(l=g,u=s=g=C(g.minus(1),g.plus(1),f,1),p=T(g.times(g),f,1),o=3;;){if(s=T(s.times(p),f,1),c=u.plus(C(s,new h(o),f,1)),U(c.d).slice(0,f)===U(u.d).slice(0,f))if(u=u.times(2),i!==0&&(u=u.plus(Ve(h,f+2,b).times(i+""))),u=C(u,new h(d),f,1),t==null)if(Te(u.d,f-w,y,a))h.precision=f+=w,c=s=g=C(l.minus(1),l.plus(1),f,1),p=T(g.times(g),f,1),o=a=1;else return T(u,h.precision=b,y,A=!0);else return h.precision=b,u;u=c,o+=2}}function $t(e){return String(e.s*e.s/0)}function ft(e,t){var n,r,o;for((n=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(n<0&&(n=r),n+=+t.slice(r+1),t=t.substring(0,r)):n<0&&(n=t.length),r=0;t.charCodeAt(r)===48;r++);for(o=t.length;t.charCodeAt(o-1)===48;--o);if(t=t.slice(r,o),t){if(o-=r,e.e=n=n-r-1,e.d=[],r=(n+1)%P,n<0&&(r+=P),r<o){for(r&&e.d.push(+t.slice(0,r)),o-=P;r<o;)e.d.push(+t.slice(r,r+=P));t=t.slice(r),r=P-t.length}else r-=o;for(;r--;)t+="0";e.d.push(+t),A&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function Gn(e,t){var n,r,o,i,s,a,u,c,f;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Zt.test(t))return ft(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Vn.test(t))n=16,t=t.toLowerCase();else if(Fn.test(t))n=2;else if(Un.test(t))n=8;else throw Error(se+t);for(i=t.search(/p/i),i>0?(u=+t.slice(i+1),t=t.substring(2,i)):t=t.slice(2),i=t.indexOf("."),s=i>=0,r=e.constructor,s&&(t=t.replace(".",""),a=t.length,i=a-i,o=Xt(r,new r(n),i,i*2)),c=Oe(t,n,Z),f=c.length-1,i=f;c[i]===0;--i)c.pop();return i<0?new r(e.s*0):(e.e=We(c,f),e.d=c,A=!1,s&&(e=C(e,o,a*4)),u&&(e=e.times(Math.abs(u)<54?F(2,u):He.pow(2,u))),A=!0,e)}function jn(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:he(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/qe(5,n)),t=he(e,2,t,t);for(var o,i=new e(5),s=new e(16),a=new e(20);n--;)o=t.times(t),t=t.times(i.plus(o.times(s.times(o).minus(a))));return t}function he(e,t,n,r,o){var i,s,a,u,c=1,f=e.precision,l=Math.ceil(f/P);for(A=!1,u=n.times(n),a=new e(r);;){if(s=C(a.times(u),new e(t++*t++),f,1),a=o?r.plus(s):r.minus(s),r=C(s.times(u),new e(t++*t++),f,1),s=a.plus(r),s.d[l]!==void 0){for(i=l;s.d[i]===a.d[i]&&i--;);if(i==-1)break}i=a,a=r,r=s,s=i,c++}return A=!0,s.d.length=l+1,s}function qe(e,t){for(var n=e;--t;)n*=e;return n}function en(e,t){var n,r=t.s<0,o=Y(e,e.precision,1),i=o.times(.5);if(t=t.abs(),t.lte(i))return te=r?4:1,t;if(n=t.divToInt(o),n.isZero())te=r?3:2;else{if(t=t.minus(n.times(o)),t.lte(i))return te=Wt(n)?r?2:3:r?4:1,t;te=Wt(n)?r?1:4:r?3:2}return t.minus(o).abs()}function pt(e,t,n,r){var o,i,s,a,u,c,f,l,p,d=e.constructor,w=n!==void 0;if(w?(j(n,1,ae),r===void 0?r=d.rounding:j(r,0,8)):(n=d.precision,r=d.rounding),!e.isFinite())f=$t(e);else{for(f=X(e),s=f.indexOf("."),w?(o=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):o=t,s>=0&&(f=f.replace(".",""),p=new d(1),p.e=f.length-s,p.d=Oe(X(p),10,o),p.e=p.d.length),l=Oe(f,10,o),i=u=l.length;l[--u]==0;)l.pop();if(!l[0])f=w?"0p+0":"0";else{if(s<0?i--:(e=new d(e),e.d=l,e.e=i,e=C(e,p,n,r,0,o),l=e.d,i=e.e,c=Gt),s=l[n],a=o/2,c=c||l[n+1]!==void 0,c=r<4?(s!==void 0||c)&&(r===0||r===(e.s<0?3:2)):s>a||s===a&&(r===4||c||r===6&&l[n-1]&1||r===(e.s<0?8:7)),l.length=n,c)for(;++l[--n]>o-1;)l[n]=0,n||(++i,l.unshift(1));for(u=l.length;!l[u-1];--u);for(s=0,f="";s<u;s++)f+=at.charAt(l[s]);if(w){if(u>1)if(t==16||t==8){for(s=t==16?4:3,--u;u%s;u++)f+="0";for(l=Oe(f,o,t),u=l.length;!l[u-1];--u);for(s=1,f="1.";s<u;s++)f+=at.charAt(l[s])}else f=f.charAt(0)+"."+f.slice(1);f=f+(i<0?"p":"p+")+i}else if(i<0){for(;++i;)f="0"+f;f="0."+f}else if(++i>u)for(i-=u;i--;)f+="0";else i<u&&(f=f.slice(0,i)+"."+f.slice(i))}f=(t==16?"0x":t==2?"0b":t==8?"0o":"")+f}return e.s<0?"-"+f:f}function qt(e,t){if(e.length>t)return e.length=t,!0}function zn(e){return new this(e).abs()}function Yn(e){return new this(e).acos()}function Zn(e){return new this(e).acosh()}function Jn(e,t){return new this(e).plus(t)}function Xn(e){return new this(e).asin()}function Qn(e){return new this(e).asinh()}function $n(e){return new this(e).atan()}function er(e){return new this(e).atanh()}function tr(e,t){e=new this(e),t=new this(t);var n,r=this.precision,o=this.rounding,i=r+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=Y(this,i,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?Y(this,r,o):new this(0),n.s=e.s):!e.d||t.isZero()?(n=Y(this,i,1).times(.5),n.s=e.s):t.s<0?(this.precision=i,this.rounding=1,n=this.atan(C(e,t,i,1)),t=Y(this,i,1),this.precision=r,this.rounding=o,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(C(e,t,i,1)),n}function nr(e){return new this(e).cbrt()}function rr(e){return T(e=new this(e),e.e+1,2)}function or(e,t,n){return new this(e).clamp(t,n)}function ir(e){if(!e||typeof e!="object")throw Error(Ue+"Object expected");var t,n,r,o=e.defaults===!0,i=["precision",1,ae,"rounding",0,8,"toExpNeg",-me,0,"toExpPos",0,me,"maxE",0,me,"minE",-me,0,"modulo",0,9];for(t=0;t<i.length;t+=3)if(n=i[t],o&&(this[n]=ct[n]),(r=e[n])!==void 0)if(H(r)===r&&r>=i[t+1]&&r<=i[t+2])this[n]=r;else throw Error(se+n+": "+r);if(n="crypto",o&&(this[n]=ct[n]),(r=e[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(zt);else this[n]=!1;else throw Error(se+n+": "+r);return this}function sr(e){return new this(e).cos()}function ar(e){return new this(e).cosh()}function tn(e){var t,n,r;function o(i){var s,a,u,c=this;if(!(c instanceof o))return new o(i);if(c.constructor=o,Ht(i)){c.s=i.s,A?!i.d||i.e>o.maxE?(c.e=NaN,c.d=null):i.e<o.minE?(c.e=0,c.d=[0]):(c.e=i.e,c.d=i.d.slice()):(c.e=i.e,c.d=i.d?i.d.slice():i.d);return}if(u=typeof i,u==="number"){if(i===0){c.s=1/i<0?-1:1,c.e=0,c.d=[0];return}if(i<0?(i=-i,c.s=-1):c.s=1,i===~~i&&i<1e7){for(s=0,a=i;a>=10;a/=10)s++;A?s>o.maxE?(c.e=NaN,c.d=null):s<o.minE?(c.e=0,c.d=[0]):(c.e=s,c.d=[i]):(c.e=s,c.d=[i]);return}else if(i*0!==0){i||(c.s=NaN),c.e=NaN,c.d=null;return}return ft(c,i.toString())}else if(u!=="string")throw Error(se+i);return(a=i.charCodeAt(0))===45?(i=i.slice(1),c.s=-1):(a===43&&(i=i.slice(1)),c.s=1),Zt.test(i)?ft(c,i):Gn(c,i)}if(o.prototype=m,o.ROUND_UP=0,o.ROUND_DOWN=1,o.ROUND_CEIL=2,o.ROUND_FLOOR=3,o.ROUND_HALF_UP=4,o.ROUND_HALF_DOWN=5,o.ROUND_HALF_EVEN=6,o.ROUND_HALF_CEIL=7,o.ROUND_HALF_FLOOR=8,o.EUCLID=9,o.config=o.set=ir,o.clone=tn,o.isDecimal=Ht,o.abs=zn,o.acos=Yn,o.acosh=Zn,o.add=Jn,o.asin=Xn,o.asinh=Qn,o.atan=$n,o.atanh=er,o.atan2=tr,o.cbrt=nr,o.ceil=rr,o.clamp=or,o.cos=sr,o.cosh=ar,o.div=cr,o.exp=ur,o.floor=lr,o.hypot=fr,o.ln=pr,o.log=dr,o.log10=hr,o.log2=mr,o.max=gr,o.min=br,o.mod=yr,o.mul=wr,o.pow=xr,o.random=Tr,o.round=Pr,o.sign=Ar,o.sin=kr,o.sinh=Br,o.sqrt=Sr,o.sub=Lr,o.sum=Ir,o.tan=Cr,o.tanh=Nr,o.trunc=Er,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(n=r[t++])||(e[n]=this[n]);return o.config(e),o}function cr(e,t){return new this(e).div(t)}function ur(e){return new this(e).exp()}function lr(e){return T(e=new this(e),e.e+1,3)}function fr(){var e,t,n=new this(0);for(A=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return A=!0,new this(1/0);n=t}return A=!0,n.sqrt()}function Ht(e){return e instanceof He||e&&e.toStringTag===Yt||!1}function pr(e){return new this(e).ln()}function dr(e,t){return new this(e).log(t)}function mr(e){return new this(e).log(2)}function hr(e){return new this(e).log(10)}function gr(){return Qt(this,arguments,"lt")}function br(){return Qt(this,arguments,"gt")}function yr(e,t){return new this(e).mod(t)}function wr(e,t){return new this(e).mul(t)}function xr(e,t){return new this(e).pow(t)}function Tr(e){var t,n,r,o,i=0,s=new this(1),a=[];if(e===void 0?e=this.precision:j(e,1,ae),r=Math.ceil(e/P),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));i<r;)o=t[i],o>=429e7?t[i]=crypto.getRandomValues(new Uint32Array(1))[0]:a[i++]=o%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);i<r;)o=t[i]+(t[i+1]<<8)+(t[i+2]<<16)+((t[i+3]&127)<<24),o>=214e7?crypto.randomBytes(4).copy(t,i):(a.push(o%1e7),i+=4);i=r/4}else throw Error(zt);else for(;i<r;)a[i++]=Math.random()*1e7|0;for(r=a[--i],e%=P,r&&e&&(o=F(10,P-e),a[i]=(r/o|0)*o);a[i]===0;i--)a.pop();if(i<0)n=0,a=[0];else{for(n=-1;a[0]===0;n-=P)a.shift();for(r=1,o=a[0];o>=10;o/=10)r++;r<P&&(n-=P-r)}return s.e=n,s.d=a,s}function Pr(e){return T(e=new this(e),e.e+1,this.rounding)}function Ar(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function kr(e){return new this(e).sin()}function Br(e){return new this(e).sinh()}function Sr(e){return new this(e).sqrt()}function Lr(e,t){return new this(e).sub(t)}function Ir(){var e=0,t=arguments,n=new this(t[e]);for(A=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return A=!0,T(n,this.precision,this.rounding)}function Cr(e){return new this(e).tan()}function Nr(e){return new this(e).tanh()}function Er(e){return T(e=new this(e),e.e+1,1)}m[Symbol.for("nodejs.util.inspect.custom")]=m.toString;m[Symbol.toStringTag]="Decimal";var He=m.constructor=tn(ct);ve=new He(ve);Fe=new He(Fe);import{PublicKey as mt}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Rr}from"@solana/spl-token";import{PublicKey as _,SystemProgram as nn,SYSVAR_RENT_PUBKEY as _r}from"@solana/web3.js";function dt({pubkey:e,isSigner:t=!1,isWritable:n=!0}){return{pubkey:e,isWritable:n,isSigner:t}}var Mo=[dt({pubkey:Rr,isWritable:!1}),dt({pubkey:nn.programId,isWritable:!1}),dt({pubkey:_r,isWritable:!1})];function rn({publicKey:e,transformSol:t}){let n=on(e.toString());if(n instanceof _)return t&&n.equals(Pe)?pe:n;if(t&&n.toString()===Pe.toBase58())return pe;if(typeof n=="string"){if(n===_.default.toBase58())return _.default;try{return new _(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function on(e){try{return new _(e)}catch{return e}}var Ko=new _("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Oo=new _("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),vo=new _("SysvarRent111111111111111111111111111111111"),Fo=new _("SysvarC1ock11111111111111111111111111111111"),Vo=new _("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Uo=new _("Sysvar1nstructions1111111111111111111111111"),Wo=nn.programId,qo=new _("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Ho=new _("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Go=new _("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),jo=new _("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),zo=new _("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Yo=new _("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Zo=new _("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Jo=new _("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Xo=new _("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Qo=new _("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),$o=new _("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),pe=new _("So11111111111111111111111111111111111111112"),Pe=_.default;import{PublicKey as Dr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as sn}from"@solana/spl-token";var an={chainId:101,address:Dr.default.toBase58(),programId:sn.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},ne={chainId:101,address:"So11111111111111111111111111111111111111112",programId:sn.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}};var ht=class{constructor({mint:t,decimals:n,symbol:r,name:o,skipMint:i=!1,isToken2022:s=!1}){if(t===Pe.toBase58()||t instanceof mt&&Pe.equals(t)){this.decimals=ne.decimals,this.symbol=ne.symbol,this.name=ne.name,this.mint=new mt(ne.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||t.toString().substring(0,6),this.name=o||t.toString().substring(0,6),this.mint=i?mt.default:rn({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},ge=ht;ge.WSOL=new ht(re(v({},ne),{mint:ne.address}));import je from"big.js";import Or from"bn.js";import vr from"decimal.js-light";import Mr from"toformat";var Kr=Mr,Ae=Kr;var Ge=q("module/fraction"),gt=Ae(je),ke=Ae(vr),Fr={[0]:ke.ROUND_DOWN,[1]:ke.ROUND_HALF_UP,[2]:ke.ROUND_UP},Vr={[0]:je.roundDown,[1]:je.roundHalfUp,[2]:je.roundUp},E=class{constructor(t,n=new Or(1)){this.numerator=Q(t),this.denominator=Q(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new E(this.denominator,this.numerator)}add(t){let n=t instanceof E?t:new E(Q(t));return this.denominator.eq(n.denominator)?new E(this.numerator.add(n.numerator),this.denominator):new E(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(t){let n=t instanceof E?t:new E(Q(t));return this.denominator.eq(n.denominator)?new E(this.numerator.sub(n.numerator),this.denominator):new E(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(t){let n=t instanceof E?t:new E(Q(t));return new E(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(t){let n=t instanceof E?t:new E(Q(t));return new E(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(t,n={groupSeparator:""},r=1){Number.isInteger(t)||Ge.logWithError(`${t} is not an integer.`),t<=0&&Ge.logWithError(`${t} is not positive.`),ke.set({precision:t+1,rounding:Fr[r]});let o=new ke(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return o.toFormat(o.decimalPlaces(),n)}toFixed(t,n={groupSeparator:""},r=1){return Number.isInteger(t)||Ge.logWithError(`${t} is not an integer.`),t<0&&Ge.logWithError(`${t} is negative.`),gt.DP=t,gt.RM=Vr[r]||1,new gt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,n)}isZero(){return this.numerator.isZero()}};var Bi=q("Raydium_price");var bt=class{constructor({decimals:t,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=t,this.symbol=n,this.name=r}equals(t){return this===t}},ze=bt;ze.SOL=new bt(an);import Wr from"bn.js";var _i=new E(new Wr(100));var qr=new z(0),$i=new z(1),es=new z(2),ts=new z(3),ns=new z(5),Hr=new z(10),rs=new z(100),os=new z(1e3),is=new z(1e4),fn=9007199254740991;function Q(e){let t=q("Raydium_parseBigNumberish");if(e instanceof z)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new z(e);t.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&t.logWithError(`BigNumberish number underflow: ${e}`),(e>=fn||e<=-fn)&&t.logWithError(`BigNumberish number overflow: ${e}`),new z(String(e))):typeof e=="bigint"?new z(e.toString()):(t.error(`invalid BigNumberish value: ${e}`),new z(0))}var ws=q("Raydium_amount"),xs=Ae(Gr);import{PublicKey as Le,sendAndConfirmTransaction as Ie,Transaction as Ce,TransactionMessage as Ne,VersionedTransaction as Ee}from"@solana/web3.js";import Qr from"axios";var V={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",AmmV4Swap:"AmmV4Swap",AmmV4AddLiquidity:"AmmV4AddLiquidity",AmmV4RemoveLiquidity:"AmmV4RemoveLiquidity",AmmV4SimulatePoolInfo:"AmmV4SimulatePoolInfo",AmmV4SwapBaseIn:"AmmV4SwapBaseIn",AmmV4SwapBaseOut:"AmmV4SwapBaseOut",AmmV4CreatePool:"AmmV4CreatePool",AmmV4InitPool:"AmmV4InitPool",AmmV5AddLiquidity:"AmmV5AddLiquidity",AmmV5RemoveLiquidity:"AmmV5RemoveLiquidity",AmmV5SimulatePoolInfo:"AmmV5SimulatePoolInfo",AmmV5SwapBaseIn:"AmmV5SwapBaseIn",AmmV5SwapBaseOut:"AmmV5SwapBaseOut",RouteSwap:"RouteSwap",RouteSwap1:"RouteSwap1",RouteSwap2:"RouteSwap2",FarmV3Deposit:"FarmV3Deposit",FarmV3Withdraw:"FarmV3Withdraw",FarmV3CreateLedger:"FarmV3CreateLedger",FarmV5Deposit:"FarmV5Deposit",FarmV5Withdraw:"FarmV5Withdraw",FarmV5CreateLedger:"FarmV5CreateLedger",FarmV6Deposit:"FarmV6Deposit",FarmV6Withdraw:"FarmV6Withdraw",FarmV6Create:"FarmV6Create",FarmV6Restart:"FarmV6Restart",FarmV6CreatorAddReward:"FarmV6CreatorAddReward",FarmV6CreatorWithdraw:"FarmV6CreatorWithdraw",CpmmCreatePool:"CpmmCreatePool",CpmmAddLiquidity:"CpmmAddLiquidity",CpmmWithdrawLiquidity:"CpmmWithdrawLiquidity",CpmmSwapBaseIn:"CpmmSwapBaseIn",CpmmSwapBaseOut:"CpmmSwapBaseOut"};import{PublicKey as jr,ComputeBudgetProgram as pn,Transaction as mn,TransactionMessage as zr,Keypair as hn,VersionedTransaction as gn}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Yr}from"@solana/spl-token";var dn=q("Raydium_txUtil"),bn=1644;function Ye(e){let t=[],n=[];return e.microLamports&&(t.push(pn.setComputeUnitPrice({microLamports:e.microLamports})),n.push(V.SetComputeUnitPrice)),e.units&&(t.push(pn.setComputeUnitLimit({units:e.units})),n.push(V.SetComputeUnitLimit)),{instructions:t,instructionTypes:n}}async function be(e){var t,n;try{return((n=await((t=e.getLatestBlockhash)==null?void 0:t.call(e)))==null?void 0:n.blockhash)||(await e.getRecentBlockhash()).blockhash}catch{return(await e.getRecentBlockhash()).blockhash}}function Zr(e,t){e.length<1&&dn.logWithError(`no instructions provided: ${e.toString()}`),t.length<1&&dn.logWithError(`no signers provided:, ${t.toString()}`);let n=new mn;n.recentBlockhash="11111111111111111111111111111111",n.feePayer=t[0],n.add(...e);try{return Buffer.from(n.serialize({verifySignatures:!1})).toString("base64").length<bn}catch{return!1}}function yn(e,t){let[n,r]=jr.findProgramAddressSync(e,t);return{publicKey:n,nonce:r}}function Be({instructions:e,payer:t,signers:n}){return Zr(e,[t,...n])}function Se({instructions:e,payer:t,lookupTableAddressAccount:n,recentBlockhash:r=hn.generate().publicKey.toString()}){let i=new zr({payerKey:t,recentBlockhash:r,instructions:e}).compileToV0Message(Object.values(n!=null?n:{}));try{return Buffer.from(new gn(i).serialize()).toString("base64").length<bn}catch{return!1}}var Jr=e=>Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e.buffer,e.byteOffset,e.byteLength):Buffer.from(e);function de(e){let t=[];return e.forEach(n=>{n instanceof mn&&(n.recentBlockhash||(n.recentBlockhash=Yr.toBase58()),n.feePayer||(n.feePayer=hn.generate().publicKey));let r=n.serialize({requireAllSignatures:!1,verifySignatures:!1});n instanceof gn&&(r=Jr(r));let o=r.toString("base64");t.push(o)}),console.log("simulate tx string:",t),t}import{PublicKey as xn,AddressLookupTableAccount as Ze}from"@solana/web3.js";import{PublicKey as Xr}from"@solana/web3.js";import{getTransferFeeConfig as Qs,unpackMint as $s}from"@solana/spl-token";var yt=q("Raydium_accountInfo_util");async function wn(e,t,n){let{batchRequest:r,commitment:o="confirmed"}=v({batchRequest:!1},n),i=wt(t,100),s=new Array(i.length).fill([]);if(r){let a=i.map(f=>{let l=e._buildArgs([f.map(p=>p.toBase58())],o,"base64");return{methodName:"getMultipleAccounts",args:l}}),u=wt(a,10);s=(await(await Promise.all(u.map(async f=>await e._rpcBatchRequest(f)))).flat()).map(f=>(f.error&&yt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${f.error.message}`),f.result.value.map(l=>{if(l){let{data:p,executable:d,lamports:w,owner:g,rentEpoch:x}=l;return p.length!==2&&p[1]!=="base64"&&yt.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(p[0],"base64"),executable:d,lamports:w,owner:new Xr(g),rentEpoch:x}}return null})))}else try{s=await Promise.all(i.map(a=>e.getMultipleAccountsInfo(a,o)))}catch(a){a instanceof Error&&yt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${a.message}`)}return s.flat()}async function xt({connection:e,address:t}){let n=await wn(e,[...new Set(t.map(o=>o.toString()))].map(o=>new xn(o))),r={};for(let o=0;o<t.length;o++){let i=n[o],s=t[o];if(!i)continue;let a=new Ze({key:s,state:Ze.deserialize(i.data)});r[s.toString()]=a,Je[s.toString()]=a}return r}var Je={"2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17":new Ze({key:new xn("2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17"),state:Ze.deserialize(Buffer.from("AQAAAP//////////d49+DAAAAAAAAQZMWvw7GUNJdaccNBVnb57OKakxL2BHLYvhRwVILRsgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMGRm/lIRcy/+ytunLDm+e8jOW7xfcSayxDmzpAAAAABt324ddloZPZy+FGzut5rBy0he1fWzeROoz1hX7/AKkG3fbh7nWP3hhCXbzkbM3athr8TYO5DSf+vfko2KGL/AVKU1D4XciC1hSlVnJ4iilt3x6rq9CmBniISTL07vagBqfVFxksXFEhjMlMPUrxf1ja7gibof1E49vZigAAAAAGp9UXGMd0yShWY5hpHV62i164o5tLbVxzVVshAAAAAIyXJY9OJInxuz0QKRSODYMLWhOZ2v8QhASOe9jb6fhZC3BlsePRfEU4nVJ/awTDzVi4bHMaoP21SbbRvAP4KUbIScv+6Yw2LHF/6K0ZjUPibbSWXCirYPGuuVl7zT789IUPLW4CpHr4JNCatp3ELXDLKMv6JJ+37le50lbBJ2LvDQdRqCgtphMF/imcN7mY5YRx2xE1A3MQ+L4QRaYK9u4GRfZP3LsAd00a+IkCpA22UNQMKdq5BFbJuwuOLqc8zxCTDlqxBG8J0HcxtfogQHDK06ukzfaXiNDKAob1MqBHS9lJxDYCwz8gd5DtFqNSTKG5l1zxIaKpDP/sffi2is1H9aKveyXSu5StXElYRl9SD5As0DHE4N0GLnf84/siiKXVyp4Ez121kLcUui/jLLFZEz/BwZK3Ilf9B9OcsEAeDMKAy2vjGSxQODgBz0QwGA+eP4ZjIjrIAQaXENv31QfLlOdXSRCkaybRniDHF4C8YcwhcvsqrOVuTP4B2Na+9wLdtrB31uz2rtlFI5kahdsnp/d1SrASDInYCtTYtdoke4kX+hoKWcEWM4Tle8pTUkUVv4BxS6fje/EzKBE4Qu9N9LMnrw/JNO0hqMVB4rk/2ou4AB1loQ7FZoPwut2o4KZB+0p9xnbrQKw038qjpHar+PyDwvxBRcu5hpHw3dguezeWv+IwvgW5icu8EGkhGa9AkFPPJT7VMSFb8xowveU=","base64"))})};var Xe=class{constructor(t){this.instructions=[];this.endInstructions=[];this.lookupTableAddress=[];this.signers=[];this.instructionTypes=[];this.endInstructionTypes=[];this.connection=t.connection,this.feePayer=t.feePayer,this.signAllTransactions=t.signAllTransactions,this.owner=t.owner,this.cluster=t.cluster}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 r;let t=(await Qr.get(`https://solanacompass.com/api/fees?cacheFreshTime=${3e5}`)).data,{avg:n}=(r=t==null?void 0:t[15])!=null?r:{};if(!!n)return{units:6e5,microLamports:Math.min(Math.ceil(n*1e6/6e5),25e3)}}addCustomComputeBudget(t){if(t){let{instructions:n,instructionTypes:r}=Ye(t);return this.instructions.unshift(...n),this.instructionTypes.unshift(...r),!0}return!1}async calComputeBudget({config:t,defaultIns:n}){try{let r=t||await this.getComputeBudgetConfig();if(this.addCustomComputeBudget(r))return;n&&this.instructions.unshift(...n)}catch{n&&this.instructions.unshift(...n)}}addInstruction({instructions:t=[],endInstructions:n=[],signers:r=[],instructionTypes:o=[],endInstructionTypes:i=[],lookupTableAddress:s=[]}){return this.instructions.push(...t),this.endInstructions.push(...n),this.signers.push(...r),this.instructionTypes.push(...o),this.endInstructionTypes.push(...i),this.lookupTableAddress.push(...s.filter(a=>a!==Le.default.toString())),this}async versionBuild({txVersion:t,extInfo:n}){return t===0?await this.buildV0(v({},n||{})):this.build(n)}build(t){let n=new Ce;return this.allInstructions.length&&n.add(...this.allInstructions),n.feePayer=this.feePayer,{builder:this,transaction:n,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async r=>{var a;let{recentBlockHash:o,skipPreflight:i=!0}=r||{},s=o!=null?o:await be(this.connection);if(n.recentBlockhash=s,this.signers.length&&n.sign(...this.signers),de([n]),(a=this.owner)!=null&&a.isKeyPair)return{txId:await Ie(this.connection,n,this.signers.find(u=>u.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:i}),signedTx:n};if(this.signAllTransactions){let u=await this.signAllTransactions([n]);return{txId:await this.connection.sendRawTransaction(u[0].serialize(),{skipPreflight:i}),signedTx:u[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:t||{}}}buildMultiTx(t){let{extraPreBuildData:n=[],extInfo:r}=t,{transaction:o}=this.build(r),i=n.filter(c=>c.transaction.instructions.length>0),s=[o,...i.map(c=>c.transaction)],a=[this.signers,...i.map(c=>c.signers)],u=[...this.instructionTypes,...i.map(c=>c.instructionTypes).flat()];return{builder:this,transactions:s,signers:a,instructionTypes:u,execute:async c=>{var g;let{sequentially:f,onTxUpdate:l,recentBlockHash:p,skipPreflight:d=!0}=c||{},w=p!=null?p:await be(this.connection);if((g=this.owner)!=null&&g.isKeyPair){if(f){let x=[];for(let h of s){let y=await Ie(this.connection,h,this.signers.find(b=>b.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:d});x.push(y)}return{txIds:x,signedTxs:s}}return{txIds:await await Promise.all(s.map(async(x,h)=>(x.recentBlockhash=w,await Ie(this.connection,x,a[h].find(y=>y.publicKey.equals(this.owner.publicKey))?a[h]:[...a[h],this.owner.signer],{skipPreflight:d})))),signedTxs:s}}if(this.signAllTransactions){let x=s.map((y,b)=>(y.recentBlockhash=w,a[b].length&&y.sign(...a[b]),y));de(x);let h=await this.signAllTransactions(x);if(f){let y=0,b=[],k=async()=>{if(!h[y])return;let B=await this.connection.sendRawTransaction(h[y].serialize(),{skipPreflight:d});b.push({txId:B,status:"sent",signedTx:h[y]}),l==null||l([...b]),y++,this.connection.onSignature(B,R=>{let D=b.findIndex(K=>K.txId===B);D>-1&&(b[D].status=R.err?"error":"success"),l==null||l([...b]),R.err||k()},"processed"),this.connection.getSignatureStatus(B)};return await k(),{txIds:b.map(B=>B.txId),signedTxs:h}}else{let y=[];for(let b=0;b<h.length;b+=1){let k=await this.connection.sendRawTransaction(h[b].serialize(),{skipPreflight:d});y.push(k)}return{txIds:y,signedTxs:h}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async versionMultiBuild({extraPreBuildData:t,txVersion:n,extInfo:r}){return n===0?await this.buildV0MultiTx({extraPreBuildData:t,buildProps:r||{}}):this.buildMultiTx({extraPreBuildData:t,extInfo:r})}async buildV0(t){let p=t||{},{lookupTableCache:n={},lookupTableAddress:r=[],forerunCreate:o}=p,i=fe(p,["lookupTableCache","lookupTableAddress","forerunCreate"]),s=v(v({},this.cluster==="devnet"?{}:Je),n),a=Array.from(new Set([...r,...this.lookupTableAddress])),u=[];for(let d of a)s[d]===void 0&&u.push(new Le(d));let c=await xt({connection:this.connection,address:u});for(let[d,w]of Object.entries(c))s[d]=w;let f=new Ne({payerKey:this.feePayer,recentBlockhash:o?Le.default.toBase58():await be(this.connection),instructions:[...this.allInstructions]}).compileToV0Message(Object.values(s)),l=new Ee(f);return l.sign(this.signers),{builder:this,transaction:l,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async d=>{var x;let{recentBlockHash:w,skipPreflight:g=!0}=d||{};if(w&&(l.message.recentBlockhash=w),de([l]),(x=this.owner)!=null&&x.isKeyPair){this.signers.find(k=>k.publicKey.equals(this.owner.publicKey))||l.sign([this.owner.signer]);let h=await this.connection.sendTransaction(l,{skipPreflight:g}),{lastValidBlockHeight:y,blockhash:b}=await this.connection.getLatestBlockhash();return await this.connection.confirmTransaction({blockhash:b,lastValidBlockHeight:y,signature:h},"confirmed"),{txId:h,signedTx:l}}if(this.signAllTransactions){let h=await this.signAllTransactions([l]);return{txId:await this.connection.sendTransaction(h[0],{skipPreflight:g}),signedTx:h[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}async buildV0MultiTx(t){let{extraPreBuildData:n=[],buildProps:r}=t,{transaction:o}=await this.buildV0(r),i=n.filter(c=>c.builder.instructions.length>0),s=[o,...i.map(c=>c.transaction)],a=[this.signers,...i.map(c=>c.signers)],u=[...this.instructionTypes,...i.map(c=>c.instructionTypes).flat()];return s.forEach(async(c,f)=>{c.sign(a[f])}),{builder:this,transactions:s,signers:a,instructionTypes:u,buildProps:r,execute:async c=>{var w;let{sequentially:f,onTxUpdate:l,recentBlockHash:p,skipPreflight:d=!0}=c||{};if(p&&s.forEach(g=>g.message.recentBlockhash=p),de(s),(w=this.owner)!=null&&w.isKeyPair){let{lastValidBlockHeight:g,blockhash:x}=await this.connection.getLatestBlockhash();if(s.forEach((h,y)=>{a[y].find(b=>b.publicKey.equals(this.owner.publicKey))||h.sign([this.owner.signer])}),f){let h=[];for(let y of s){let b=await this.connection.sendTransaction(y,{skipPreflight:d}),{lastValidBlockHeight:k,blockhash:B}=await this.connection.getLatestBlockhash();await this.connection.confirmTransaction({blockhash:B,lastValidBlockHeight:k,signature:b},"confirmed"),h.push(b)}return{txIds:h,signedTxs:s}}return{txIds:await Promise.all(s.map(async h=>{let y=await this.connection.sendTransaction(h,{skipPreflight:d});return await this.connection.confirmTransaction({blockhash:x,lastValidBlockHeight:g,signature:y},"confirmed"),y})),signedTxs:s}}if(this.signAllTransactions){let g=await this.signAllTransactions(s);if(f){let x=0,h=[],y=async()=>{if(!g[x])return;let b=await this.connection.sendTransaction(g[x],{skipPreflight:d});h.push({txId:b,status:"sent",signedTx:g[x]}),l==null||l([...h]),x++,this.connection.onSignature(b,k=>{let B=h.findIndex(R=>R.txId===b);B>-1&&(h[B].status=k.err?"error":"success"),l==null||l([...h]),k.err||y()},"processed"),this.connection.getSignatureStatus(b)};return y(),{txIds:[],signedTxs:g}}else{let x=[];for(let h=0;h<g.length;h+=1){let y=await this.connection.sendTransaction(g[h],{skipPreflight:d});x.push(y)}return{txIds:x,signedTxs:g}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async sizeCheckBuild(t){let c=t||{},{computeBudgetConfig:n}=c,r=fe(c,["computeBudgetConfig"]),o=n?Ye(n):{instructions:[],instructionTypes:[]},i=this.signers.reduce((f,l)=>re(v({},f),{[l.publicKey.toBase58()]:l}),{}),s=[],a=[],u=[];if(this.allInstructions.forEach(f=>{let l=[...u,f],p=n?[...o.instructions,...l]:l,w=[...new Set(l.map(g=>g.keys.filter(x=>x.isSigner).map(x=>x.pubkey.toString())).flat()).values()].map(g=>new Le(g));if(u.length<12&&Be({instructions:p,payer:this.feePayer,signers:w})||Be({instructions:l,payer:this.feePayer,signers:w}))u.push(f);else{if(u.length===0)throw Error("item ins too big");Be({instructions:n?[...o.instructions,...u]:[...u],payer:this.feePayer,signers:w})?s.push(new Ce().add(...o.instructions,...u)):s.push(new Ce().add(...u)),a.push(Array.from(new Set(u.map(g=>g.keys.filter(x=>x.isSigner).map(x=>x.pubkey.toString())).flat())).map(g=>i[g]).filter(g=>g!==void 0)),u=[f]}}),u.length>0){let l=[...new Set(u.map(p=>p.keys.filter(d=>d.isSigner).map(d=>d.pubkey.toString())).flat()).values()].map(p=>i[p]).filter(p=>p!==void 0);Be({instructions:n?[...o.instructions,...u]:[...u],payer:this.feePayer,signers:l.map(p=>p.publicKey)})?s.push(new Ce().add(...o.instructions,...u)):s.push(new Ce().add(...u)),a.push(l)}return s.forEach(f=>f.feePayer=this.feePayer),{builder:this,transactions:s,signers:a,instructionTypes:this.instructionTypes,execute:async f=>{var x;let{sequentially:l,onTxUpdate:p,recentBlockHash:d,skipPreflight:w=!0}=f||{},g=d!=null?d:await be(this.connection);if(s.forEach(async(h,y)=>{h.recentBlockhash=g,a[y].length&&h.sign(...a[y])}),de(s),(x=this.owner)!=null&&x.isKeyPair){if(l){let h=[];for(let y of s){let b=await Ie(this.connection,y,this.signers.find(k=>k.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:w});h.push(b)}return{txIds:h,signedTxs:s}}return{txIds:await Promise.all(s.map(async(h,y)=>await Ie(this.connection,h,a[y].find(b=>b.publicKey.equals(this.owner.publicKey))?a[y]:[...a[y],this.owner.signer],{skipPreflight:w}))),signedTxs:s}}if(this.signAllTransactions){let h=await this.signAllTransactions(s);if(l){let y=0,b=[],k=async()=>{if(!h[y])return;let B=await this.connection.sendRawTransaction(h[y].serialize(),{skipPreflight:w});b.push({txId:B,status:"sent",signedTx:h[y]}),p==null||p([...b]),y++,this.connection.onSignature(B,R=>{let D=b.findIndex(K=>K.txId===B);D>-1&&(b[D].status=R.err?"error":"success"),p==null||p([...b]),R.err||k()},"processed"),this.connection.getSignatureStatus(B)};return await k(),{txIds:b.map(B=>B.txId),signedTxs:h}}else{let y=[];for(let b=0;b<h.length;b+=1){let k=await this.connection.sendRawTransaction(h[b].serialize(),{skipPreflight:w});y.push(k)}return{txIds:y,signedTxs:h}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async sizeCheckBuildV0(t){let x=t||{},{computeBudgetConfig:n,lookupTableCache:r={},lookupTableAddress:o=[]}=x,i=fe(x,["computeBudgetConfig","lookupTableCache","lookupTableAddress"]),s=v(v({},this.cluster==="devnet"?{}:Je),r),a=Array.from(new Set([...this.lookupTableAddress,...o])),u=[];for(let h of a)s[h]===void 0&&u.push(new Le(h));let c=await xt({connection:this.connection,address:u});for(let[h,y]of Object.entries(c))s[h]=y;let f=n?Ye(n):{instructions:[],instructionTypes:[]},l=await be(this.connection),p=this.signers.reduce((h,y)=>re(v({},h),{[y.publicKey.toBase58()]:y}),{}),d=[],w=[],g=[];if(this.allInstructions.forEach(h=>{let y=[...g,h],b=n?[...f.instructions,...y]:y;if(g.length<12&&Se({instructions:b,payer:this.feePayer,lookupTableAddressAccount:s})||Se({instructions:y,payer:this.feePayer,lookupTableAddressAccount:s}))g.push(h);else{if(g.length===0)throw Error("item ins too big");let k={};for(let B of[...new Set(a)])s[B]!==void 0&&(k[B]=s[B]);if(n&&Se({instructions:[...f.instructions,...g],payer:this.feePayer,lookupTableAddressAccount:s,recentBlockhash:l})){let B=new Ne({payerKey:this.feePayer,recentBlockhash:l,instructions:[...f.instructions,...g]}).compileToV0Message(Object.values(s));d.push(new Ee(B))}else{let B=new Ne({payerKey:this.feePayer,recentBlockhash:l,instructions:[...g]}).compileToV0Message(Object.values(s));d.push(new Ee(B))}w.push(Array.from(new Set(g.map(B=>B.keys.filter(R=>R.isSigner).map(R=>R.pubkey.toString())).flat())).map(B=>p[B]).filter(B=>B!==void 0)),g=[h]}}),g.length>0){let y=[...new Set(g.map(b=>b.keys.filter(k=>k.isSigner).map(k=>k.pubkey.toString())).flat()).values()].map(b=>p[b]).filter(b=>b!==void 0);if(n&&Se({instructions:[...f.instructions,...g],payer:this.feePayer,lookupTableAddressAccount:s,recentBlockhash:l})){let b=new Ne({payerKey:this.feePayer,recentBlockhash:l,instructions:[...f.instructions,...g]}).compileToV0Message(Object.values(s));d.push(new Ee(b))}else{let b=new Ne({payerKey:this.feePayer,recentBlockhash:l,instructions:[...g]}).compileToV0Message(Object.values(s));d.push(new Ee(b))}w.push(y)}return{builder:this,transactions:d,buildProps:t,signers:w,instructionTypes:this.instructionTypes,execute:async h=>{var R;let{sequentially:y,onTxUpdate:b,recentBlockHash:k,skipPreflight:B=!0}=h||{};if(d.map(async(D,K)=>{w[K].length&&D.sign(w[K]),k&&(D.message.recentBlockhash=k)}),de(d),(R=this.owner)!=null&&R.isKeyPair){let{lastValidBlockHeight:D,blockhash:K}=await this.connection.getLatestBlockhash();if(d.forEach((M,G)=>{w[G].find(O=>O.publicKey.equals(this.owner.publicKey))||M.sign([this.owner.signer])}),y){let M=[];for(let G of d){let O=await this.connection.sendTransaction(G,{skipPreflight:B}),{lastValidBlockHeight:$,blockhash:ee}=await this.connection.getLatestBlockhash();await this.connection.confirmTransaction({blockhash:ee,lastValidBlockHeight:$,signature:O},"confirmed"),M.push(O)}return{txIds:M,signedTxs:d}}return{txIds:await Promise.all(d.map(async M=>{let G=await this.connection.sendTransaction(M,{skipPreflight:B});return await this.connection.confirmTransaction({blockhash:K,lastValidBlockHeight:D,signature:G},"confirmed"),G})),signedTxs:d}}if(this.signAllTransactions){let D=await this.signAllTransactions(d);if(y){let K=0,M=[],G=async()=>{if(!D[K])return;let O=await this.connection.sendTransaction(D[K],{skipPreflight:B});M.push({txId:O,status:"sent",signedTx:D[K]}),b==null||b([...M]),K++,this.connection.onSignature(O,$=>{let ee=M.findIndex(xe=>xe.txId===O);ee>-1&&(M[ee].status=$.err?"error":"success"),b==null||b([...M]),$.err||G()},"processed"),this.connection.getSignatureStatus(O)};return G(),{txIds:[],signedTxs:D}}else{let K=[];for(let M=0;M<D.length;M+=1){let G=await this.connection.sendTransaction(D[M],{skipPreflight:B});K.push(G)}return{txIds:K,signedTxs:D}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}};function wt(e,t=1,n=[]){let r=[...e];if(t<=0)return n;for(;r.length;)n.push(r.splice(0,t));return n}import{PublicKey as I}from"@solana/web3.js";var Pa=new I("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),Aa=new I("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),ka=new I("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Ba=new I("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),Sa=new I("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),La=new I("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Ia=new I("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Ca=new I("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Na=new I("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),Ea=new I("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Ra=new I("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),_a=new I("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Da=new I("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),Ma=new I("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),Ka=new I("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),Oa=new I("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),va=new I("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Fa=new I("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),$r=new I("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),eo=new I("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),to=new I("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2");var Va={SERUM_MARKET:I.default,OPENBOOK_MARKET:new I("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:I.default,FarmV3:new I("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new I("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new I("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new I("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new I("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new I("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),Router:new I("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:$r,CREATE_CPMM_POOL_AUTH:eo,CREATE_CPMM_POOL_FEE_ACC:to,FEE_DESTINATION_ID:new I("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR")};import{PublicKey as no}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ro}from"@solana/spl-token";function Qe(e,t,n){return yn([e.toBuffer(),(n!=null?n:ro).toBuffer(),t.toBuffer()],new no("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}import za from"bn.js";var Tt=(...e)=>e.map(t=>{try{return typeof t=="object"?JSON.stringify(t):t}catch{return t}}).join(", "),Re=class{constructor({scope:t,moduleName:n}){this.disabled=!1;this.scope=t,this.logger=q(n)}createTxBuilder(t){return this.scope.checkOwner(),new Xe({connection:this.scope.connection,feePayer:t||this.scope.ownerPubKey,cluster:this.scope.cluster,owner:this.scope.owner,signAllTransactions:this.scope.signAllTransactions})}logDebug(...t){this.logger.debug(Tt(t))}logInfo(...t){this.logger.info(Tt(t))}logAndCreateError(...t){let n=Tt(t);throw new Error(n)}checkDisabled(){(this.disabled||!this.scope)&&this.logAndCreateError("module not working")}};import{createInitializeAccountInstruction as yo,createCloseAccountInstruction as wo,createTransferInstruction as xo,TOKEN_PROGRAM_ID as ye}from"@solana/spl-token";import{PublicKey as To,SystemProgram as Po}from"@solana/web3.js";import Ao from"bn.js";import{PublicKey as Nn,Keypair as mo}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ho}from"@solana/spl-token";import go from"bn.js";import{PublicKey as co}from"@solana/web3.js";import Pn,{isBN as gu}from"bn.js";import{bits as bc,BitStructure as yc,blob as oo,Blob as wc,cstr as xc,f32 as Tc,f32be as Pc,f64 as Ac,f64be as kc,greedy as Bc,Layout as io,ns64 as Sc,ns64be as Lc,nu64 as Ic,nu64be as Cc,offset as Nc,s16 as Ec,s16be as Rc,s24 as _c,s24be as Dc,s32 as Mc,s32be as Kc,s40 as Oc,s40be as vc,s48 as Fc,s48be as Vc,s8 as Uc,seq as Wc,struct as qc,Structure as so,u16 as Hc,u16be as Gc,u24 as jc,u24be as zc,u32 as Yc,u32be as Zc,u40 as Jc,u40be as Xc,u48 as Qc,u48be as $c,u8 as eu,UInt as ao,union as tu,Union as nu,unionLayoutDiscriminator as ru,utf8 as ou}from"@solana/buffer-layout";var Pt=io,Tn=so;var At=ao;var kt=oo;var Bt=class extends Pt{constructor(n,r,o){super(n,o);this.blob=kt(n),this.signed=r}decode(n,r=0){let o=new Pn(this.blob.decode(n,r),10,"le");return this.signed?o.fromTwos(this.span*8).clone():o}encode(n,r,o=0){return typeof n=="number"&&(n=new Pn(n)),this.signed&&(n=n.toTwos(this.span*8)),this.blob.encode(n.toArrayLike(Buffer,"le",this.span),r,o)}};function An(e){return new At(1,e)}function $e(e){return new At(4,e)}function et(e){return new Bt(8,!1,e)}var St=class extends Pt{constructor(n,r,o,i){super(n.span,i);this.layout=n,this.decoder=r,this.encoder=o}decode(n,r){return this.decoder(this.layout.decode(n,r))}encode(n,r,o){return this.layout.encode(this.encoder(n),r,o)}getSpan(n,r){return this.layout.getSpan(n,r)}};function _e(e){return new St(kt(32),t=>new co(t),t=>t.toBuffer(),e)}var Lt=class extends Tn{decode(t,n){return super.decode(t,n)}};function kn(e,t,n){return new Lt(e,t,n)}var De=kn([_e("mint"),_e("owner"),et("amount"),$e("delegateOption"),_e("delegate"),An("state"),$e("isNativeOption"),et("isNative"),et("delegatedAmount"),$e("closeAuthorityOption"),_e("closeAuthority")]);function uo(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function It(e,...t){if(!uo(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function Ct(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Bn(e,t){It(e);let n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}var nt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),J=(e,t)=>e<<32-t|e>>>t;var ku=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function lo(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Nt(e){return typeof e=="string"&&(e=lo(e)),It(e),e}var tt=class{clone(){return this._cloneInto()}},Bu={}.toString;function Sn(e){let t=r=>e().update(Nt(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function fo(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);let o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),u=r?4:0,c=r?0:4;e.setUint32(t+u,s,r),e.setUint32(t+c,a,r)}var Ln=(e,t,n)=>e&t^~e&n,In=(e,t,n)=>e&t^e&n^t&n,rt=class extends tt{constructor(t,n,r,o){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=nt(this.buffer)}update(t){Ct(this);let{view:n,buffer:r,blockLen:o}=this;t=Nt(t);let i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let u=nt(t);for(;o<=i-s;s+=o)this.process(u,s);continue}r.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ct(this),Bn(t,this),this.finished=!0;let{buffer:n,view:r,blockLen:o,isLE:i}=this,{pos:s}=this;n[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(r,0),s=0);for(let l=s;l<o;l++)n[l]=0;fo(r,o-8,BigInt(this.length*8),i),this.process(r,0);let a=nt(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let c=u/4,f=this.get();if(c>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<c;l++)a.setUint32(4*l,f[l],i)}digest(){let{buffer:t,outputLen:n}=this;this.digestInto(t);let r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:n,buffer:r,length:o,finished:i,destroyed:s,pos:a}=this;return t.length=o,t.pos=a,t.finished=i,t.destroyed=s,o%n&&t.buffer.set(r),t}};var po=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ce=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ue=new Uint32Array(64),Et=class extends rt{constructor(){super(64,32,8,!1),this.A=ce[0]|0,this.B=ce[1]|0,this.C=ce[2]|0,this.D=ce[3]|0,this.E=ce[4]|0,this.F=ce[5]|0,this.G=ce[6]|0,this.H=ce[7]|0}get(){let{A:t,B:n,C:r,D:o,E:i,F:s,G:a,H:u}=this;return[t,n,r,o,i,s,a,u]}set(t,n,r,o,i,s,a,u){this.A=t|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=u|0}process(t,n){for(let l=0;l<16;l++,n+=4)ue[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){let p=ue[l-15],d=ue[l-2],w=J(p,7)^J(p,18)^p>>>3,g=J(d,17)^J(d,19)^d>>>10;ue[l]=g+ue[l-7]+w+ue[l-16]|0}let{A:r,B:o,C:i,D:s,E:a,F:u,G:c,H:f}=this;for(let l=0;l<64;l++){let p=J(a,6)^J(a,11)^J(a,25),d=f+p+Ln(a,u,c)+po[l]+ue[l]|0,g=(J(r,2)^J(r,13)^J(r,22))+In(r,o,i)|0;f=c,c=u,u=a,a=s+d|0,s=i,i=o,o=r,r=d+g|0}r=r+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,u=u+this.F|0,c=c+this.G|0,f=f+this.H|0,this.set(r,o,i,s,a,u,c,f)}roundClean(){ue.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Cn=Sn(()=>new Et);var Wu=q("Raydium_Util");function En({owner:e,solAccountResp:t,tokenAccountResp:n}){let r=[],o=[];for(let{pubkey:i,account:s}of n.value){let a=De.decode(s.data),{mint:u,amount:c}=a;r.push({publicKey:i,mint:u,amount:c,isAssociated:Qe(e,u,s.owner).publicKey.equals(i),isNative:!1,programId:s.owner}),o.push({pubkey:i,accountInfo:a,programId:s.owner})}return t&&r.push({mint:Nn.default,amount:new go(t.lamports),isNative:!0,programId:t.owner}),{tokenAccounts:r,tokenAccountRawInfos:o}}function ot({fromPublicKey:e,programId:t=ho}){let n=mo.generate().publicKey.toBase58().slice(0,32);return{publicKey:bo(e,n,t),seed:n}}function bo(e,t,n){let r=Buffer.concat([e.toBuffer(),Buffer.from(t),n.toBuffer()]),o=Cn(r);return new Nn(o)}function Rt(e){let{mint:t,tokenAccount:n,owner:r,programId:o=ye}=e;return yo(n,t,r,o)}function Me(e){let{tokenAccount:t,payer:n,multiSigners:r=[],owner:o,programId:i=ye}=e;return wo(t,n,o,r,i)}async function _t(e){let{connection:t,amount:n,commitment:r,payer:o,owner:i,skipCloseAccount:s}=e,a=await t.getMinimumBalanceForRentExemption(De.span,r),u=Q(n).add(new Ao(a)),c=ot({fromPublicKey:o,programId:ye});return{addresses:{newAccount:c.publicKey},signers:[],instructions:[Po.createAccountWithSeed({fromPubkey:o,basePubkey:o,seed:c.seed,newAccountPubkey:c.publicKey,lamports:u.toNumber(),space:De.span,programId:ye}),Rt({mint:new To(ne.address),tokenAccount:c.publicKey,owner:i,programId:ye})],instructionTypes:[V.CreateAccount,V.InitAccount],endInstructionTypes:s?[]:[V.CloseAccount],endInstructions:s?[]:[Me({tokenAccount:c.publicKey,payer:o,owner:i})]}}function Rn({source:e,destination:t,owner:n,amount:r,multiSigners:o=[],tokenProgram:i=ye}){return xo(e,t,n,BigInt(String(r)),o,i)}var Mt=class extends Re{constructor(n){super(n);this._tokenAccounts=[];this._tokenAccountRawInfos=[];this._accountListener=[];this._clientOwnedToken=!1;let{tokenAccounts:r,tokenAccountRawInfos:o}=n;this._tokenAccounts=r||[],this._tokenAccountRawInfos=o||[],this._clientOwnedToken=!!(r||o)}get tokenAccounts(){return this._tokenAccounts}get tokenAccountRawInfos(){return this._tokenAccountRawInfos}updateTokenAccount({tokenAccounts:n,tokenAccountRawInfos:r}){return n&&(this._tokenAccounts=n),r&&(this._tokenAccountRawInfos=r),this._accountChangeListenerId&&this.scope.connection.removeAccountChangeListener(this._accountChangeListenerId),this._accountChangeListenerId=void 0,this._clientOwnedToken=!0,this}addAccountChangeListener(n){return this._accountListener.push(n),this}removeAccountChangeListener(n){return this._accountListener=this._accountListener.filter(r=>r!==n),this}getAssociatedTokenAccount(n,r){return Qe(this.scope.ownerPubKey,n,r).publicKey}async fetchWalletTokenAccounts(n){if(this._clientOwnedToken||!(n!=null&&n.forceUpdate)&&this._tokenAccounts.length)return{tokenAccounts:this._tokenAccounts,tokenAccountRawInfos:this._tokenAccountRawInfos};this.scope.checkOwner();let o=v(v({},{}),n),[i,s,a]=await Promise.all([this.scope.connection.getAccountInfo(this.scope.ownerPubKey,o.commitment),this.scope.connection.getTokenAccountsByOwner(this.scope.ownerPubKey,{programId:le},o.commitment),this.scope.connection.getTokenAccountsByOwner(this.scope.ownerPubKey,{programId:ko},o.commitment)]),{tokenAccounts:u,tokenAccountRawInfos:c}=En({owner:this.scope.ownerPubKey,solAccountResp:i,tokenAccountResp:{context:s.context,value:[...s.value,...a.value]}});return this._tokenAccounts=u,this._tokenAccountRawInfos=c,this._accountChangeListenerId&&this.scope.connection.removeAccountChangeListener(this._accountChangeListenerId),this._accountChangeListenerId=this.scope.connection.onAccountChange(this.scope.ownerPubKey,()=>this.fetchWalletTokenAccounts({forceUpdate:!0}),n==null?void 0:n.commitment),{tokenAccounts:u,tokenAccountRawInfos:c}}async getCreatedTokenAccount({mint:n,programId:r=le,associatedOnly:o=!0}){await this.fetchWalletTokenAccounts();let i=this._tokenAccounts.filter(({mint:a})=>a==null?void 0:a.equals(n)).sort((a,u)=>a.amount.lt(u.amount)?1:-1),s=this.getAssociatedTokenAccount(n,r);for(let a of i){let{publicKey:u}=a;if(u&&(!o||o&&s.equals(u)))return u}}async getOrCreateTokenAccount(n){var w,g;await this.fetchWalletTokenAccounts();let{mint:r,createInfo:o,associatedOnly:i,owner:s,notUseTokenAccount:a=!1,skipCloseAccount:u=!1,checkCreateATAOwner:c=!1}=n,f=new it(n.tokenProgram||le),l=this.getAssociatedTokenAccount(r,new it(f)),p=(a?[]:this.tokenAccountRawInfos).filter(x=>x.accountInfo.mint.equals(r)&&(!i||x.pubkey.equals(l))).sort((x,h)=>x.accountInfo.amount.lt(h.accountInfo.amount)?1:-1);if(o===void 0||p.length>0)return p.length>0?{account:p[0].pubkey}:{};let d={instructions:[],endInstructions:[],signers:[],instructionTypes:[],endInstructionTypes:[]};if(i){let x=Dt(s,l,s,r,f);if(c){let h=await this.scope.connection.getAccountInfo(l);if(h===null)(w=d.instructions)==null||w.push(x),d.instructionTypes.push(V.CreateATA);else if(!(h.owner.equals(f)&&we.decode(h.data).mint.equals(r)&&we.decode(h.data).owner.equals(s)))throw Error(`create ata check error -> mint: ${r.toString()}, ata: ${l.toString()}`)}else d.instructions.push(x),d.instructionTypes.push(V.CreateATA);if(r.equals(pe)&&o.amount){let h=await _t({connection:this.scope.connection,owner:this.scope.ownerPubKey,payer:o.payer||this.scope.ownerPubKey,amount:(g=o.amount)!=null?g:0,skipCloseAccount:u});d.instructions.push(...h.instructions||[]),d.endInstructions.push(...h.endInstructions||[]),d.instructionTypes.push(...h.instructionTypes||[]),d.endInstructionTypes.push(...h.endInstructionTypes||[]),o.amount&&(d.instructions.push(Rn({source:h.addresses.newAccount,destination:l,owner:this.scope.ownerPubKey,amount:o.amount,tokenProgram:le})),d.instructionTypes.push(V.TransferAmount))}return u||(d.endInstructions.push(Me({owner:s,payer:o.payer||s,tokenAccount:l,programId:f})),d.endInstructionTypes.push(V.CloseAccount)),{account:l,instructionParams:d}}else{let x=ot({fromPublicKey:s,programId:f}),h=await this.scope.connection.getMinimumBalanceForRentExemption(we.span),y=Bo.createAccountWithSeed({fromPubkey:s,basePubkey:s,seed:x.seed,newAccountPubkey:x.publicKey,lamports:h,space:we.span,programId:f});return d.instructions.push(y,Rt({mint:r,tokenAccount:x.publicKey,owner:this.scope.ownerPubKey,programId:f})),d.instructionTypes.push(V.CreateAccount),d.instructionTypes.push(V.InitAccount),u||(d.endInstructions.push(Me({owner:s,payer:o.payer||s,tokenAccount:x.publicKey,programId:f})),d.endInstructionTypes.push(V.CloseAccount)),{account:x.publicKey,instructionParams:d}}}async checkOrCreateAta({mint:n,programId:r=le,autoUnwrapWSOLToSOL:o}){var u;await this.fetchWalletTokenAccounts();let i=(u=this.scope.account.tokenAccounts.find(({mint:c})=>(c==null?void 0:c.toBase58())===n.toBase58()))==null?void 0:u.publicKey,s=this.scope.ownerPubKey,a={};if(!i){let c=this.getAssociatedTokenAccount(n,r),f=await Dt(s,c,s,n,r);a.instructions=[f],a.instructionTypes=[V.CreateATA],i=c}return o&&pe.toBase58()===n.toBase58()&&(a.endInstructions=[Me({owner:s,payer:s,tokenAccount:i,programId:r})],a.endInstructionTypes=[V.CloseAccount]),{pubKey:i,newInstructions:a}}async handleTokenAccount(n){let{side:r,amount:o,mint:i,programId:s=le,tokenAccount:a,payer:u=this.scope.ownerPubKey,bypassAssociatedCheck:c,skipCloseAccount:f,checkCreateATAOwner:l}=n,p=this.getAssociatedTokenAccount(i,s);if(new it(pe).equals(i)){let d=await _t({connection:this.scope.connection,owner:this.scope.ownerPubKey,payer:u,amount:o,skipCloseAccount:f});return v({tokenAccount:d.addresses.newAccount},d)}else if(!a||r==="out"&&!p.equals(a)&&!c){let d=[],w=Dt(this.scope.ownerPubKey,p,this.scope.ownerPubKey,i,s);if(l){let g=await this.scope.connection.getAccountInfo(p);if(g===null)d.push(w);else if(!(g.owner.equals(le)&&we.decode(g.data).mint.equals(i)&&we.decode(g.data).owner.equals(this.scope.ownerPubKey)))throw Error(`create ata check error -> mint: ${i.toString()}, ata: ${p.toString()}`)}else d.push(w);return{tokenAccount:p,instructions:d,instructionTypes:[V.CreateATA]}}return{tokenAccount:a}}async processTokenAccount(n){let{mint:r,programId:o=le,amount:i,useSOLBalance:s,handleTokenAccount:a}=n,u,c=this.createTxBuilder();if(r.equals(new it(pe))&&s){let f=await this.handleTokenAccount({side:"in",amount:i||0,mint:r,bypassAssociatedCheck:!0,programId:o}),{tokenAccount:p}=f,d=fe(f,["tokenAccount"]);u=p,c.addInstruction(d)}else if(u=await this.getCreatedTokenAccount({mint:r,associatedOnly:!1,programId:o}),!u&&a){let l=await this.scope.account.handleTokenAccount({side:"in",amount:0,mint:r,bypassAssociatedCheck:!0,programId:o}),{tokenAccount:p}=l,d=fe(l,["tokenAccount"]);u=p,c.addInstruction(d)}return v({tokenAccount:u},c.AllTxData)}};export{Mt as default};
|
|
1
|
+
var _n=Object.defineProperty,Dn=Object.defineProperties;var Mn=Object.getOwnPropertyDescriptors;var Ke=Object.getOwnPropertySymbols;var Ot=Object.prototype.hasOwnProperty,vt=Object.prototype.propertyIsEnumerable;var Kt=(e,t,n)=>t in e?_n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))Ot.call(t,n)&&Kt(e,n,t[n]);if(Ke)for(var n of Ke(t))vt.call(t,n)&&Kt(e,n,t[n]);return e},re=(e,t)=>Dn(e,Mn(t));var fe=(e,t)=>{var n={};for(var r in e)Ot.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ke)for(var r of Ke(e))t.indexOf(r)<0&&vt.call(e,r)&&(n[r]=e[r]);return n};import{createAssociatedTokenAccountInstruction as Dt,TOKEN_PROGRAM_ID as le,AccountLayout as we,TOKEN_2022_PROGRAM_ID as ko}from"@solana/spl-token";import{PublicKey as it,SystemProgram as Bo}from"@solana/web3.js";import{get as Ft,set as Kn}from"lodash";import Ut from"dayjs";import On from"dayjs/plugin/utc";Ut.extend(On);var st=class{constructor(t){this.logLevel=t.logLevel!==void 0?t.logLevel:0,this.name=t.name}set level(t){this.logLevel=t}get time(){return Ut().utc().format("YYYY/MM/DD HH:mm:ss UTC")}get moduleName(){return this.name}isLogLevel(t){return t<=this.logLevel}error(...t){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...t),this):this}logWithError(...t){let n=t.map(r=>typeof r=="object"?JSON.stringify(r):r).join(", ");throw new Error(n)}warning(...t){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...t),this):this}info(...t){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...t),this):this}debug(...t){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...t),this):this}},Vt={},vn={};function q(e){let t=Ft(Vt,e);if(!t){let n=Ft(vn,e);t=new st({name:e,logLevel:n}),Kn(Vt,e,t)}return t}import{PublicKey as Es}from"@solana/web3.js";import _s from"bn.js";import Gr from"big.js";import fs from"bn.js";import z from"bn.js";var me=9e15,ae=1e9,at="0123456789abcdef",ve="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Fe="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",ct={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-me,maxE:me,crypto:!1},Gt,te,k=!0,Ue="[DecimalError] ",se=Ue+"Invalid argument: ",jt=Ue+"Precision limit exceeded",zt=Ue+"crypto unavailable",Yt="[object Decimal]",H=Math.floor,F=Math.pow,Fn=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Vn=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Un=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Zt=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Z=1e7,P=7,Wn=9007199254740991,qn=ve.length-1,ut=Fe.length-1,m={toStringTag:Yt};m.absoluteValue=m.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),T(e)};m.ceil=function(){return T(new this.constructor(this),this.e+1,2)};m.clampedTo=m.clamp=function(e,t){var n,r=this,o=r.constructor;if(e=new o(e),t=new o(t),!e.s||!t.s)return new o(NaN);if(e.gt(t))throw Error(se+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new o(r)};m.comparedTo=m.cmp=function(e){var t,n,r,o,i=this,s=i.d,a=(e=new i.constructor(e)).d,u=i.s,c=e.s;if(!s||!a)return!u||!c?NaN:u!==c?u:s===a?0:!s^u<0?1:-1;if(!s[0]||!a[0])return s[0]?u:a[0]?-c:0;if(u!==c)return u;if(i.e!==e.e)return i.e>e.e^u<0?1:-1;for(r=s.length,o=a.length,t=0,n=r<o?r:o;t<n;++t)if(s[t]!==a[t])return s[t]>a[t]^u<0?1:-1;return r===o?0:r>o^u<0?1:-1};m.cosine=m.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+P,r.rounding=1,n=Hn(r,en(r,n)),r.precision=e,r.rounding=t,T(te==2||te==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)};m.cubeRoot=m.cbrt=function(){var e,t,n,r,o,i,s,a,u,c,f=this,l=f.constructor;if(!f.isFinite()||f.isZero())return new l(f);for(k=!1,i=f.s*F(f.s*f,1/3),!i||Math.abs(i)==1/0?(n=U(f.d),e=f.e,(i=(e-n.length+1)%3)&&(n+=i==1||i==-2?"0":"00"),i=F(n,1/3),e=H((e+1)/3)-(e%3==(e<0?-1:2)),i==1/0?n="5e"+e:(n=i.toExponential(),n=n.slice(0,n.indexOf("e")+1)+e),r=new l(n),r.s=f.s):r=new l(i.toString()),s=(e=l.precision)+3;;)if(a=r,u=a.times(a).times(a),c=u.plus(f),r=C(c.plus(f).times(a),c.plus(u),s+2,1),U(a.d).slice(0,s)===(n=U(r.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!o&&n=="4999"){if(!o&&(T(a,e+1,0),a.times(a).times(a).eq(f))){r=a;break}s+=4,o=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(T(r,e+1,1),t=!r.times(r).times(r).eq(f));break}return k=!0,T(r,e,l.rounding,t)};m.decimalPlaces=m.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-H(this.e/P))*P,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n};m.dividedBy=m.div=function(e){return C(this,new this.constructor(e))};m.dividedToIntegerBy=m.divToInt=function(e){var t=this,n=t.constructor;return T(C(t,new n(e),0,1,1),n.precision,n.rounding)};m.equals=m.eq=function(e){return this.cmp(e)===0};m.floor=function(){return T(new this.constructor(this),this.e+1,3)};m.greaterThan=m.gt=function(e){return this.cmp(e)>0};m.greaterThanOrEqualTo=m.gte=function(e){var t=this.cmp(e);return t==1||t===0};m.hyperbolicCosine=m.cosh=function(){var e,t,n,r,o,i=this,s=i.constructor,a=new s(1);if(!i.isFinite())return new s(i.s?1/0:NaN);if(i.isZero())return a;n=s.precision,r=s.rounding,s.precision=n+Math.max(i.e,i.sd())+4,s.rounding=1,o=i.d.length,o<32?(e=Math.ceil(o/3),t=(1/qe(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),i=he(s,1,i.times(t),new s(1),!0);for(var u,c=e,f=new s(8);c--;)u=i.times(i),i=a.minus(u.times(f.minus(u.times(f))));return T(i,s.precision=n,s.rounding=r,!0)};m.hyperbolicSine=m.sinh=function(){var e,t,n,r,o=this,i=o.constructor;if(!o.isFinite()||o.isZero())return new i(o);if(t=i.precision,n=i.rounding,i.precision=t+Math.max(o.e,o.sd())+4,i.rounding=1,r=o.d.length,r<3)o=he(i,2,o,o,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,o=o.times(1/qe(5,e)),o=he(i,2,o,o,!0);for(var s,a=new i(5),u=new i(16),c=new i(20);e--;)s=o.times(o),o=o.times(a.plus(s.times(u.times(s).plus(c))))}return i.precision=t,i.rounding=n,T(o,t,n,!0)};m.hyperbolicTangent=m.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,C(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)};m.inverseCosine=m.acos=function(){var e,t=this,n=t.constructor,r=t.abs().cmp(1),o=n.precision,i=n.rounding;return r!==-1?r===0?t.isNeg()?Y(n,o,i):new n(0):new n(NaN):t.isZero()?Y(n,o+4,i).times(.5):(n.precision=o+6,n.rounding=1,t=t.asin(),e=Y(n,o+4,i).times(.5),n.precision=o,n.rounding=i,e.minus(t))};m.inverseHyperbolicCosine=m.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,k=!1,n=n.times(n).minus(1).sqrt().plus(n),k=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)};m.inverseHyperbolicSine=m.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,k=!1,n=n.times(n).plus(1).sqrt().plus(n),k=!0,r.precision=e,r.rounding=t,n.ln())};m.inverseHyperbolicTangent=m.atanh=function(){var e,t,n,r,o=this,i=o.constructor;return o.isFinite()?o.e>=0?new i(o.abs().eq(1)?o.s/0:o.isZero()?o:NaN):(e=i.precision,t=i.rounding,r=o.sd(),Math.max(r,e)<2*-o.e-1?T(new i(o),e,t,!0):(i.precision=n=r-o.e,o=C(o.plus(1),new i(1).minus(o),n+e,1),i.precision=e+4,i.rounding=1,o=o.ln(),i.precision=e,i.rounding=t,o.times(.5))):new i(NaN)};m.inverseSine=m.asin=function(){var e,t,n,r,o=this,i=o.constructor;return o.isZero()?new i(o):(t=o.abs().cmp(1),n=i.precision,r=i.rounding,t!==-1?t===0?(e=Y(i,n+4,r).times(.5),e.s=o.s,e):new i(NaN):(i.precision=n+6,i.rounding=1,o=o.div(new i(1).minus(o.times(o)).sqrt().plus(1)).atan(),i.precision=n,i.rounding=r,o.times(2)))};m.inverseTangent=m.atan=function(){var e,t,n,r,o,i,s,a,u,c=this,f=c.constructor,l=f.precision,p=f.rounding;if(c.isFinite()){if(c.isZero())return new f(c);if(c.abs().eq(1)&&l+4<=ut)return s=Y(f,l+4,p).times(.25),s.s=c.s,s}else{if(!c.s)return new f(NaN);if(l+4<=ut)return s=Y(f,l+4,p).times(.5),s.s=c.s,s}for(f.precision=a=l+10,f.rounding=1,n=Math.min(28,a/P+2|0),e=n;e;--e)c=c.div(c.times(c).plus(1).sqrt().plus(1));for(k=!1,t=Math.ceil(a/P),r=1,u=c.times(c),s=new f(c),o=c;e!==-1;)if(o=o.times(u),i=s.minus(o.div(r+=2)),o=o.times(u),s=i.plus(o.div(r+=2)),s.d[t]!==void 0)for(e=t;s.d[e]===i.d[e]&&e--;);return n&&(s=s.times(2<<n-1)),k=!0,T(s,f.precision=l,f.rounding=p,!0)};m.isFinite=function(){return!!this.d};m.isInteger=m.isInt=function(){return!!this.d&&H(this.e/P)>this.d.length-2};m.isNaN=function(){return!this.s};m.isNegative=m.isNeg=function(){return this.s<0};m.isPositive=m.isPos=function(){return this.s>0};m.isZero=function(){return!!this.d&&this.d[0]===0};m.lessThan=m.lt=function(e){return this.cmp(e)<0};m.lessThanOrEqualTo=m.lte=function(e){return this.cmp(e)<1};m.logarithm=m.log=function(e){var t,n,r,o,i,s,a,u,c=this,f=c.constructor,l=f.precision,p=f.rounding,d=5;if(e==null)e=new f(10),t=!0;else{if(e=new f(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new f(NaN);t=e.eq(10)}if(n=c.d,c.s<0||!n||!n[0]||c.eq(1))return new f(n&&!n[0]?-1/0:c.s!=1?NaN:n?0:1/0);if(t)if(n.length>1)i=!0;else{for(o=n[0];o%10===0;)o/=10;i=o!==1}if(k=!1,a=l+d,s=ie(c,a),r=t?Ve(f,a+10):ie(e,a),u=C(s,r,a,1),Te(u.d,o=l,p))do if(a+=10,s=ie(c,a),r=t?Ve(f,a+10):ie(e,a),u=C(s,r,a,1),!i){+U(u.d).slice(o+1,o+15)+1==1e14&&(u=T(u,l+1,0));break}while(Te(u.d,o+=10,p));return k=!0,T(u,l,p)};m.minus=m.sub=function(e){var t,n,r,o,i,s,a,u,c,f,l,p,d=this,w=d.constructor;if(e=new w(e),!d.d||!e.d)return!d.s||!e.s?e=new w(NaN):d.d?e.s=-e.s:e=new w(e.d||d.s!==e.s?d:NaN),e;if(d.s!=e.s)return e.s=-e.s,d.plus(e);if(c=d.d,p=e.d,a=w.precision,u=w.rounding,!c[0]||!p[0]){if(p[0])e.s=-e.s;else if(c[0])e=new w(d);else return new w(u===3?-0:0);return k?T(e,a,u):e}if(n=H(e.e/P),f=H(d.e/P),c=c.slice(),i=f-n,i){for(l=i<0,l?(t=c,i=-i,s=p.length):(t=p,n=f,s=c.length),r=Math.max(Math.ceil(a/P),s)+2,i>r&&(i=r,t.length=1),t.reverse(),r=i;r--;)t.push(0);t.reverse()}else{for(r=c.length,s=p.length,l=r<s,l&&(s=r),r=0;r<s;r++)if(c[r]!=p[r]){l=c[r]<p[r];break}i=0}for(l&&(t=c,c=p,p=t,e.s=-e.s),s=c.length,r=p.length-s;r>0;--r)c[s++]=0;for(r=p.length;r>i;){if(c[--r]<p[r]){for(o=r;o&&c[--o]===0;)c[o]=Z-1;--c[o],c[r]+=Z}c[r]-=p[r]}for(;c[--s]===0;)c.pop();for(;c[0]===0;c.shift())--n;return c[0]?(e.d=c,e.e=We(c,n),k?T(e,a,u):e):new w(u===3?-0:0)};m.modulo=m.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?T(new r(n),r.precision,r.rounding):(k=!1,r.modulo==9?(t=C(n,e.abs(),0,3,1),t.s*=e.s):t=C(n,e,0,r.modulo,1),t=t.times(e),k=!0,n.minus(t))};m.naturalExponential=m.exp=function(){return lt(this)};m.naturalLogarithm=m.ln=function(){return ie(this)};m.negated=m.neg=function(){var e=new this.constructor(this);return e.s=-e.s,T(e)};m.plus=m.add=function(e){var t,n,r,o,i,s,a,u,c,f,l=this,p=l.constructor;if(e=new p(e),!l.d||!e.d)return!l.s||!e.s?e=new p(NaN):l.d||(e=new p(e.d||l.s===e.s?l:NaN)),e;if(l.s!=e.s)return e.s=-e.s,l.minus(e);if(c=l.d,f=e.d,a=p.precision,u=p.rounding,!c[0]||!f[0])return f[0]||(e=new p(l)),k?T(e,a,u):e;if(i=H(l.e/P),r=H(e.e/P),c=c.slice(),o=i-r,o){for(o<0?(n=c,o=-o,s=f.length):(n=f,r=i,s=c.length),i=Math.ceil(a/P),s=i>s?i+1:s+1,o>s&&(o=s,n.length=1),n.reverse();o--;)n.push(0);n.reverse()}for(s=c.length,o=f.length,s-o<0&&(o=s,n=f,f=c,c=n),t=0;o;)t=(c[--o]=c[o]+f[o]+t)/Z|0,c[o]%=Z;for(t&&(c.unshift(t),++r),s=c.length;c[--s]==0;)c.pop();return e.d=c,e.e=We(c,r),k?T(e,a,u):e};m.precision=m.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(se+e);return n.d?(t=Jt(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t};m.round=function(){var e=this,t=e.constructor;return T(new t(e),e.e+1,t.rounding)};m.sine=m.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+P,r.rounding=1,n=jn(r,en(r,n)),r.precision=e,r.rounding=t,T(te>2?n.neg():n,e,t,!0)):new r(NaN)};m.squareRoot=m.sqrt=function(){var e,t,n,r,o,i,s=this,a=s.d,u=s.e,c=s.s,f=s.constructor;if(c!==1||!a||!a[0])return new f(!c||c<0&&(!a||a[0])?NaN:a?s:1/0);for(k=!1,c=Math.sqrt(+s),c==0||c==1/0?(t=U(a),(t.length+u)%2==0&&(t+="0"),c=Math.sqrt(t),u=H((u+1)/2)-(u<0||u%2),c==1/0?t="5e"+u:(t=c.toExponential(),t=t.slice(0,t.indexOf("e")+1)+u),r=new f(t)):r=new f(c.toString()),n=(u=f.precision)+3;;)if(i=r,r=i.plus(C(s,i,n+2,1)).times(.5),U(i.d).slice(0,n)===(t=U(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!o&&t=="4999"){if(!o&&(T(i,u+1,0),i.times(i).eq(s))){r=i;break}n+=4,o=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(T(r,u+1,1),e=!r.times(r).eq(s));break}return k=!0,T(r,u,f.rounding,e)};m.tangent=m.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=C(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,T(te==2||te==4?n.neg():n,e,t,!0)):new r(NaN)};m.times=m.mul=function(e){var t,n,r,o,i,s,a,u,c,f=this,l=f.constructor,p=f.d,d=(e=new l(e)).d;if(e.s*=f.s,!p||!p[0]||!d||!d[0])return new l(!e.s||p&&!p[0]&&!d||d&&!d[0]&&!p?NaN:!p||!d?e.s/0:e.s*0);for(n=H(f.e/P)+H(e.e/P),u=p.length,c=d.length,u<c&&(i=p,p=d,d=i,s=u,u=c,c=s),i=[],s=u+c,r=s;r--;)i.push(0);for(r=c;--r>=0;){for(t=0,o=u+r;o>r;)a=i[o]+d[r]*p[o-r-1]+t,i[o--]=a%Z|0,t=a/Z|0;i[o]=(i[o]+t)%Z|0}for(;!i[--s];)i.pop();return t?++n:i.shift(),e.d=i,e.e=We(i,n),k?T(e,l.precision,l.rounding):e};m.toBinary=function(e,t){return pt(this,2,e,t)};m.toDecimalPlaces=m.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(j(e,0,ae),t===void 0?t=r.rounding:j(t,0,8),T(n,e+n.e+1,t))};m.toExponential=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=X(r,!0):(j(e,0,ae),t===void 0?t=o.rounding:j(t,0,8),r=T(new o(r),e+1,t),n=X(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+n:n};m.toFixed=function(e,t){var n,r,o=this,i=o.constructor;return e===void 0?n=X(o):(j(e,0,ae),t===void 0?t=i.rounding:j(t,0,8),r=T(new i(o),e+o.e+1,t),n=X(r,!1,e+r.e+1)),o.isNeg()&&!o.isZero()?"-"+n:n};m.toFraction=function(e){var t,n,r,o,i,s,a,u,c,f,l,p,d=this,w=d.d,g=d.constructor;if(!w)return new g(d);if(c=n=new g(1),r=u=new g(0),t=new g(r),i=t.e=Jt(w)-d.e-1,s=i%P,t.d[0]=F(10,s<0?P+s:s),e==null)e=i>0?t:c;else{if(a=new g(e),!a.isInt()||a.lt(c))throw Error(se+a);e=a.gt(t)?i>0?t:c:a}for(k=!1,a=new g(U(w)),f=g.precision,g.precision=i=w.length*P*2;l=C(a,t,0,1,1),o=n.plus(l.times(r)),o.cmp(e)!=1;)n=r,r=o,o=c,c=u.plus(l.times(o)),u=o,o=t,t=a.minus(l.times(o)),a=o;return o=C(e.minus(n),r,0,1,1),u=u.plus(o.times(c)),n=n.plus(o.times(r)),u.s=c.s=d.s,p=C(c,r,i,1).minus(d).abs().cmp(C(u,n,i,1).minus(d).abs())<1?[c,r]:[u,n],g.precision=f,k=!0,p};m.toHexadecimal=m.toHex=function(e,t){return pt(this,16,e,t)};m.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:j(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&(e.s=n.s),e}return e.d[0]?(k=!1,n=C(n,e,0,t,1).times(e),k=!0,T(n)):(e.s=n.s,n=e),n};m.toNumber=function(){return+this};m.toOctal=function(e,t){return pt(this,8,e,t)};m.toPower=m.pow=function(e){var t,n,r,o,i,s,a=this,u=a.constructor,c=+(e=new u(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new u(F(+a,c));if(a=new u(a),a.eq(1))return a;if(r=u.precision,i=u.rounding,e.eq(1))return T(a,r,i);if(t=H(e.e/P),t>=e.d.length-1&&(n=c<0?-c:c)<=Wn)return o=Xt(u,a,n,r),e.s<0?new u(1).div(o):T(o,r,i);if(s=a.s,s<0){if(t<e.d.length-1)return new u(NaN);if((e.d[t]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return n=F(+a,c),t=n==0||!isFinite(n)?H(c*(Math.log("0."+U(a.d))/Math.LN10+a.e+1)):new u(n+"").e,t>u.maxE+1||t<u.minE-1?new u(t>0?s/0:0):(k=!1,u.rounding=a.s=1,n=Math.min(12,(t+"").length),o=lt(e.times(ie(a,r+n)),r),o.d&&(o=T(o,r+5,1),Te(o.d,r,i)&&(t=r+10,o=T(lt(e.times(ie(a,t+n)),t),t+5,1),+U(o.d).slice(r+1,r+15)+1==1e14&&(o=T(o,r+1,0)))),o.s=s,k=!0,u.rounding=i,T(o,r,i))};m.toPrecision=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=X(r,r.e<=o.toExpNeg||r.e>=o.toExpPos):(j(e,1,ae),t===void 0?t=o.rounding:j(t,0,8),r=T(new o(r),e,t),n=X(r,e<=r.e||r.e<=o.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+n:n};m.toSignificantDigits=m.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(j(e,1,ae),t===void 0?t=r.rounding:j(t,0,8)),T(new r(n),e,t)};m.toString=function(){var e=this,t=e.constructor,n=X(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n};m.truncated=m.trunc=function(){return T(new this.constructor(this),this.e+1,1)};m.valueOf=m.toJSON=function(){var e=this,t=e.constructor,n=X(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function U(e){var t,n,r,o=e.length-1,i="",s=e[0];if(o>0){for(i+=s,t=1;t<o;t++)r=e[t]+"",n=P-r.length,n&&(i+=oe(n)),i+=r;s=e[t],r=s+"",n=P-r.length,n&&(i+=oe(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return i+s}function j(e,t,n){if(e!==~~e||e<t||e>n)throw Error(se+e)}function Te(e,t,n,r){var o,i,s,a;for(i=e[0];i>=10;i/=10)--t;return--t<0?(t+=P,o=0):(o=Math.ceil((t+1)/P),t%=P),i=F(10,P-t),a=e[o]%i|0,r==null?t<3?(t==0?a=a/100|0:t==1&&(a=a/10|0),s=n<4&&a==99999||n>3&&a==49999||a==5e4||a==0):s=(n<4&&a+1==i||n>3&&a+1==i/2)&&(e[o+1]/i/100|0)==F(10,t-2)-1||(a==i/2||a==0)&&(e[o+1]/i/100|0)==0:t<4?(t==0?a=a/1e3|0:t==1?a=a/100|0:t==2&&(a=a/10|0),s=(r||n<4)&&a==9999||!r&&n>3&&a==4999):s=((r||n<4)&&a+1==i||!r&&n>3&&a+1==i/2)&&(e[o+1]/i/1e3|0)==F(10,t-3)-1,s}function Oe(e,t,n){for(var r,o=[0],i,s=0,a=e.length;s<a;){for(i=o.length;i--;)o[i]*=t;for(o[0]+=at.indexOf(e.charAt(s++)),r=0;r<o.length;r++)o[r]>n-1&&(o[r+1]===void 0&&(o[r+1]=0),o[r+1]+=o[r]/n|0,o[r]%=n)}return o.reverse()}function Hn(e,t){var n,r,o;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),o=(1/qe(4,n)).toString()):(n=16,o="2.3283064365386962890625e-10"),e.precision+=n,t=he(e,1,t.times(o),new e(1));for(var i=n;i--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return e.precision-=n,t}var C=function(){function e(r,o,i){var s,a=0,u=r.length;for(r=r.slice();u--;)s=r[u]*o+a,r[u]=s%i|0,a=s/i|0;return a&&r.unshift(a),r}function t(r,o,i,s){var a,u;if(i!=s)u=i>s?1:-1;else for(a=u=0;a<i;a++)if(r[a]!=o[a]){u=r[a]>o[a]?1:-1;break}return u}function n(r,o,i,s){for(var a=0;i--;)r[i]-=a,a=r[i]<o[i]?1:0,r[i]=a*s+r[i]-o[i];for(;!r[0]&&r.length>1;)r.shift()}return function(r,o,i,s,a,u){var c,f,l,p,d,w,g,x,b,y,h,A,B,R,D,K,M,G,O,$,ee=r.constructor,xe=r.s==o.s?1:-1,W=r.d,N=o.d;if(!W||!W[0]||!N||!N[0])return new ee(!r.s||!o.s||(W?N&&W[0]==N[0]:!N)?NaN:W&&W[0]==0||!N?xe*0:xe/0);for(u?(d=1,f=r.e-o.e):(u=Z,d=P,f=H(r.e/d)-H(o.e/d)),O=N.length,M=W.length,b=new ee(xe),y=b.d=[],l=0;N[l]==(W[l]||0);l++);if(N[l]>(W[l]||0)&&f--,i==null?(R=i=ee.precision,s=ee.rounding):a?R=i+(r.e-o.e)+1:R=i,R<0)y.push(1),w=!0;else{if(R=R/d+2|0,l=0,O==1){for(p=0,N=N[0],R++;(l<M||p)&&R--;l++)D=p*u+(W[l]||0),y[l]=D/N|0,p=D%N|0;w=p||l<M}else{for(p=u/(N[0]+1)|0,p>1&&(N=e(N,p,u),W=e(W,p,u),O=N.length,M=W.length),K=O,h=W.slice(0,O),A=h.length;A<O;)h[A++]=0;$=N.slice(),$.unshift(0),G=N[0],N[1]>=u/2&&++G;do p=0,c=t(N,h,O,A),c<0?(B=h[0],O!=A&&(B=B*u+(h[1]||0)),p=B/G|0,p>1?(p>=u&&(p=u-1),g=e(N,p,u),x=g.length,A=h.length,c=t(g,h,x,A),c==1&&(p--,n(g,O<x?$:N,x,u))):(p==0&&(c=p=1),g=N.slice()),x=g.length,x<A&&g.unshift(0),n(h,g,A,u),c==-1&&(A=h.length,c=t(N,h,O,A),c<1&&(p++,n(h,O<A?$:N,A,u))),A=h.length):c===0&&(p++,h=[0]),y[l++]=p,c&&h[0]?h[A++]=W[K]||0:(h=[W[K]],A=1);while((K++<M||h[0]!==void 0)&&R--);w=h[0]!==void 0}y[0]||y.shift()}if(d==1)b.e=f,Gt=w;else{for(l=1,p=y[0];p>=10;p/=10)l++;b.e=l+f*d-1,T(b,a?i+b.e+1:i,s,w)}return b}}();function T(e,t,n,r){var o,i,s,a,u,c,f,l,p,d=e.constructor;e:if(t!=null){if(l=e.d,!l)return e;for(o=1,a=l[0];a>=10;a/=10)o++;if(i=t-o,i<0)i+=P,s=t,f=l[p=0],u=f/F(10,o-s-1)%10|0;else if(p=Math.ceil((i+1)/P),a=l.length,p>=a)if(r){for(;a++<=p;)l.push(0);f=u=0,o=1,i%=P,s=i-P+1}else break e;else{for(f=a=l[p],o=1;a>=10;a/=10)o++;i%=P,s=i-P+o,u=s<0?0:f/F(10,o-s-1)%10|0}if(r=r||t<0||l[p+1]!==void 0||(s<0?f:f%F(10,o-s-1)),c=n<4?(u||r)&&(n==0||n==(e.s<0?3:2)):u>5||u==5&&(n==4||r||n==6&&(i>0?s>0?f/F(10,o-s):0:l[p-1])%10&1||n==(e.s<0?8:7)),t<1||!l[0])return l.length=0,c?(t-=e.e+1,l[0]=F(10,(P-t%P)%P),e.e=-t||0):l[0]=e.e=0,e;if(i==0?(l.length=p,a=1,p--):(l.length=p+1,a=F(10,P-i),l[p]=s>0?(f/F(10,o-s)%F(10,s)|0)*a:0),c)for(;;)if(p==0){for(i=1,s=l[0];s>=10;s/=10)i++;for(s=l[0]+=a,a=1;s>=10;s/=10)a++;i!=a&&(e.e++,l[0]==Z&&(l[0]=1));break}else{if(l[p]+=a,l[p]!=Z)break;l[p--]=0,a=1}for(i=l.length;l[--i]===0;)l.pop()}return k&&(e.e>d.maxE?(e.d=null,e.e=NaN):e.e<d.minE&&(e.e=0,e.d=[0])),e}function X(e,t,n){if(!e.isFinite())return $t(e);var r,o=e.e,i=U(e.d),s=i.length;return t?(n&&(r=n-s)>0?i=i.charAt(0)+"."+i.slice(1)+oe(r):s>1&&(i=i.charAt(0)+"."+i.slice(1)),i=i+(e.e<0?"e":"e+")+e.e):o<0?(i="0."+oe(-o-1)+i,n&&(r=n-s)>0&&(i+=oe(r))):o>=s?(i+=oe(o+1-s),n&&(r=n-o-1)>0&&(i=i+"."+oe(r))):((r=o+1)<s&&(i=i.slice(0,r)+"."+i.slice(r)),n&&(r=n-s)>0&&(o+1===s&&(i+="."),i+=oe(r))),i}function We(e,t){var n=e[0];for(t*=P;n>=10;n/=10)t++;return t}function Ve(e,t,n){if(t>qn)throw k=!0,n&&(e.precision=n),Error(jt);return T(new e(ve),t,1,!0)}function Y(e,t,n){if(t>ut)throw Error(jt);return T(new e(Fe),t,n,!0)}function Jt(e){var t=e.length-1,n=t*P+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function oe(e){for(var t="";e--;)t+="0";return t}function Xt(e,t,n,r){var o,i=new e(1),s=Math.ceil(r/P+4);for(k=!1;;){if(n%2&&(i=i.times(t),qt(i.d,s)&&(o=!0)),n=H(n/2),n===0){n=i.d.length-1,o&&i.d[n]===0&&++i.d[n];break}t=t.times(t),qt(t.d,s)}return k=!0,i}function Wt(e){return e.d[e.d.length-1]&1}function Qt(e,t,n){for(var r,o=new e(t[0]),i=0;++i<t.length;)if(r=new e(t[i]),r.s)o[n](r)&&(o=r);else{o=r;break}return o}function lt(e,t){var n,r,o,i,s,a,u,c=0,f=0,l=0,p=e.constructor,d=p.rounding,w=p.precision;if(!e.d||!e.d[0]||e.e>17)return new p(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:0/0);for(t==null?(k=!1,u=w):u=t,a=new p(.03125);e.e>-2;)e=e.times(a),l+=5;for(r=Math.log(F(2,l))/Math.LN10*2+5|0,u+=r,n=i=s=new p(1),p.precision=u;;){if(i=T(i.times(e),u,1),n=n.times(++f),a=s.plus(C(i,n,u,1)),U(a.d).slice(0,u)===U(s.d).slice(0,u)){for(o=l;o--;)s=T(s.times(s),u,1);if(t==null)if(c<3&&Te(s.d,u-r,d,c))p.precision=u+=10,n=i=a=new p(1),f=0,c++;else return T(s,p.precision=w,d,k=!0);else return p.precision=w,s}s=a}}function ie(e,t){var n,r,o,i,s,a,u,c,f,l,p,d=1,w=10,g=e,x=g.d,b=g.constructor,y=b.rounding,h=b.precision;if(g.s<0||!x||!x[0]||!g.e&&x[0]==1&&x.length==1)return new b(x&&!x[0]?-1/0:g.s!=1?NaN:x?0:g);if(t==null?(k=!1,f=h):f=t,b.precision=f+=w,n=U(x),r=n.charAt(0),Math.abs(i=g.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)g=g.times(e),n=U(g.d),r=n.charAt(0),d++;i=g.e,r>1?(g=new b("0."+n),i++):g=new b(r+"."+n.slice(1))}else return c=Ve(b,f+2,h).times(i+""),g=ie(new b(r+"."+n.slice(1)),f-w).plus(c),b.precision=h,t==null?T(g,h,y,k=!0):g;for(l=g,u=s=g=C(g.minus(1),g.plus(1),f,1),p=T(g.times(g),f,1),o=3;;){if(s=T(s.times(p),f,1),c=u.plus(C(s,new b(o),f,1)),U(c.d).slice(0,f)===U(u.d).slice(0,f))if(u=u.times(2),i!==0&&(u=u.plus(Ve(b,f+2,h).times(i+""))),u=C(u,new b(d),f,1),t==null)if(Te(u.d,f-w,y,a))b.precision=f+=w,c=s=g=C(l.minus(1),l.plus(1),f,1),p=T(g.times(g),f,1),o=a=1;else return T(u,b.precision=h,y,k=!0);else return b.precision=h,u;u=c,o+=2}}function $t(e){return String(e.s*e.s/0)}function ft(e,t){var n,r,o;for((n=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(n<0&&(n=r),n+=+t.slice(r+1),t=t.substring(0,r)):n<0&&(n=t.length),r=0;t.charCodeAt(r)===48;r++);for(o=t.length;t.charCodeAt(o-1)===48;--o);if(t=t.slice(r,o),t){if(o-=r,e.e=n=n-r-1,e.d=[],r=(n+1)%P,n<0&&(r+=P),r<o){for(r&&e.d.push(+t.slice(0,r)),o-=P;r<o;)e.d.push(+t.slice(r,r+=P));t=t.slice(r),r=P-t.length}else r-=o;for(;r--;)t+="0";e.d.push(+t),k&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function Gn(e,t){var n,r,o,i,s,a,u,c,f;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Zt.test(t))return ft(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Vn.test(t))n=16,t=t.toLowerCase();else if(Fn.test(t))n=2;else if(Un.test(t))n=8;else throw Error(se+t);for(i=t.search(/p/i),i>0?(u=+t.slice(i+1),t=t.substring(2,i)):t=t.slice(2),i=t.indexOf("."),s=i>=0,r=e.constructor,s&&(t=t.replace(".",""),a=t.length,i=a-i,o=Xt(r,new r(n),i,i*2)),c=Oe(t,n,Z),f=c.length-1,i=f;c[i]===0;--i)c.pop();return i<0?new r(e.s*0):(e.e=We(c,f),e.d=c,k=!1,s&&(e=C(e,o,a*4)),u&&(e=e.times(Math.abs(u)<54?F(2,u):He.pow(2,u))),k=!0,e)}function jn(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:he(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/qe(5,n)),t=he(e,2,t,t);for(var o,i=new e(5),s=new e(16),a=new e(20);n--;)o=t.times(t),t=t.times(i.plus(o.times(s.times(o).minus(a))));return t}function he(e,t,n,r,o){var i,s,a,u,c=1,f=e.precision,l=Math.ceil(f/P);for(k=!1,u=n.times(n),a=new e(r);;){if(s=C(a.times(u),new e(t++*t++),f,1),a=o?r.plus(s):r.minus(s),r=C(s.times(u),new e(t++*t++),f,1),s=a.plus(r),s.d[l]!==void 0){for(i=l;s.d[i]===a.d[i]&&i--;);if(i==-1)break}i=a,a=r,r=s,s=i,c++}return k=!0,s.d.length=l+1,s}function qe(e,t){for(var n=e;--t;)n*=e;return n}function en(e,t){var n,r=t.s<0,o=Y(e,e.precision,1),i=o.times(.5);if(t=t.abs(),t.lte(i))return te=r?4:1,t;if(n=t.divToInt(o),n.isZero())te=r?3:2;else{if(t=t.minus(n.times(o)),t.lte(i))return te=Wt(n)?r?2:3:r?4:1,t;te=Wt(n)?r?1:4:r?3:2}return t.minus(o).abs()}function pt(e,t,n,r){var o,i,s,a,u,c,f,l,p,d=e.constructor,w=n!==void 0;if(w?(j(n,1,ae),r===void 0?r=d.rounding:j(r,0,8)):(n=d.precision,r=d.rounding),!e.isFinite())f=$t(e);else{for(f=X(e),s=f.indexOf("."),w?(o=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):o=t,s>=0&&(f=f.replace(".",""),p=new d(1),p.e=f.length-s,p.d=Oe(X(p),10,o),p.e=p.d.length),l=Oe(f,10,o),i=u=l.length;l[--u]==0;)l.pop();if(!l[0])f=w?"0p+0":"0";else{if(s<0?i--:(e=new d(e),e.d=l,e.e=i,e=C(e,p,n,r,0,o),l=e.d,i=e.e,c=Gt),s=l[n],a=o/2,c=c||l[n+1]!==void 0,c=r<4?(s!==void 0||c)&&(r===0||r===(e.s<0?3:2)):s>a||s===a&&(r===4||c||r===6&&l[n-1]&1||r===(e.s<0?8:7)),l.length=n,c)for(;++l[--n]>o-1;)l[n]=0,n||(++i,l.unshift(1));for(u=l.length;!l[u-1];--u);for(s=0,f="";s<u;s++)f+=at.charAt(l[s]);if(w){if(u>1)if(t==16||t==8){for(s=t==16?4:3,--u;u%s;u++)f+="0";for(l=Oe(f,o,t),u=l.length;!l[u-1];--u);for(s=1,f="1.";s<u;s++)f+=at.charAt(l[s])}else f=f.charAt(0)+"."+f.slice(1);f=f+(i<0?"p":"p+")+i}else if(i<0){for(;++i;)f="0"+f;f="0."+f}else if(++i>u)for(i-=u;i--;)f+="0";else i<u&&(f=f.slice(0,i)+"."+f.slice(i))}f=(t==16?"0x":t==2?"0b":t==8?"0o":"")+f}return e.s<0?"-"+f:f}function qt(e,t){if(e.length>t)return e.length=t,!0}function zn(e){return new this(e).abs()}function Yn(e){return new this(e).acos()}function Zn(e){return new this(e).acosh()}function Jn(e,t){return new this(e).plus(t)}function Xn(e){return new this(e).asin()}function Qn(e){return new this(e).asinh()}function $n(e){return new this(e).atan()}function er(e){return new this(e).atanh()}function tr(e,t){e=new this(e),t=new this(t);var n,r=this.precision,o=this.rounding,i=r+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=Y(this,i,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?Y(this,r,o):new this(0),n.s=e.s):!e.d||t.isZero()?(n=Y(this,i,1).times(.5),n.s=e.s):t.s<0?(this.precision=i,this.rounding=1,n=this.atan(C(e,t,i,1)),t=Y(this,i,1),this.precision=r,this.rounding=o,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(C(e,t,i,1)),n}function nr(e){return new this(e).cbrt()}function rr(e){return T(e=new this(e),e.e+1,2)}function or(e,t,n){return new this(e).clamp(t,n)}function ir(e){if(!e||typeof e!="object")throw Error(Ue+"Object expected");var t,n,r,o=e.defaults===!0,i=["precision",1,ae,"rounding",0,8,"toExpNeg",-me,0,"toExpPos",0,me,"maxE",0,me,"minE",-me,0,"modulo",0,9];for(t=0;t<i.length;t+=3)if(n=i[t],o&&(this[n]=ct[n]),(r=e[n])!==void 0)if(H(r)===r&&r>=i[t+1]&&r<=i[t+2])this[n]=r;else throw Error(se+n+": "+r);if(n="crypto",o&&(this[n]=ct[n]),(r=e[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(zt);else this[n]=!1;else throw Error(se+n+": "+r);return this}function sr(e){return new this(e).cos()}function ar(e){return new this(e).cosh()}function tn(e){var t,n,r;function o(i){var s,a,u,c=this;if(!(c instanceof o))return new o(i);if(c.constructor=o,Ht(i)){c.s=i.s,k?!i.d||i.e>o.maxE?(c.e=NaN,c.d=null):i.e<o.minE?(c.e=0,c.d=[0]):(c.e=i.e,c.d=i.d.slice()):(c.e=i.e,c.d=i.d?i.d.slice():i.d);return}if(u=typeof i,u==="number"){if(i===0){c.s=1/i<0?-1:1,c.e=0,c.d=[0];return}if(i<0?(i=-i,c.s=-1):c.s=1,i===~~i&&i<1e7){for(s=0,a=i;a>=10;a/=10)s++;k?s>o.maxE?(c.e=NaN,c.d=null):s<o.minE?(c.e=0,c.d=[0]):(c.e=s,c.d=[i]):(c.e=s,c.d=[i]);return}else if(i*0!==0){i||(c.s=NaN),c.e=NaN,c.d=null;return}return ft(c,i.toString())}else if(u!=="string")throw Error(se+i);return(a=i.charCodeAt(0))===45?(i=i.slice(1),c.s=-1):(a===43&&(i=i.slice(1)),c.s=1),Zt.test(i)?ft(c,i):Gn(c,i)}if(o.prototype=m,o.ROUND_UP=0,o.ROUND_DOWN=1,o.ROUND_CEIL=2,o.ROUND_FLOOR=3,o.ROUND_HALF_UP=4,o.ROUND_HALF_DOWN=5,o.ROUND_HALF_EVEN=6,o.ROUND_HALF_CEIL=7,o.ROUND_HALF_FLOOR=8,o.EUCLID=9,o.config=o.set=ir,o.clone=tn,o.isDecimal=Ht,o.abs=zn,o.acos=Yn,o.acosh=Zn,o.add=Jn,o.asin=Xn,o.asinh=Qn,o.atan=$n,o.atanh=er,o.atan2=tr,o.cbrt=nr,o.ceil=rr,o.clamp=or,o.cos=sr,o.cosh=ar,o.div=cr,o.exp=ur,o.floor=lr,o.hypot=fr,o.ln=pr,o.log=dr,o.log10=hr,o.log2=mr,o.max=gr,o.min=br,o.mod=yr,o.mul=wr,o.pow=xr,o.random=Tr,o.round=Pr,o.sign=Ar,o.sin=kr,o.sinh=Br,o.sqrt=Sr,o.sub=Lr,o.sum=Ir,o.tan=Cr,o.tanh=Nr,o.trunc=Er,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(n=r[t++])||(e[n]=this[n]);return o.config(e),o}function cr(e,t){return new this(e).div(t)}function ur(e){return new this(e).exp()}function lr(e){return T(e=new this(e),e.e+1,3)}function fr(){var e,t,n=new this(0);for(k=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return k=!0,new this(1/0);n=t}return k=!0,n.sqrt()}function Ht(e){return e instanceof He||e&&e.toStringTag===Yt||!1}function pr(e){return new this(e).ln()}function dr(e,t){return new this(e).log(t)}function mr(e){return new this(e).log(2)}function hr(e){return new this(e).log(10)}function gr(){return Qt(this,arguments,"lt")}function br(){return Qt(this,arguments,"gt")}function yr(e,t){return new this(e).mod(t)}function wr(e,t){return new this(e).mul(t)}function xr(e,t){return new this(e).pow(t)}function Tr(e){var t,n,r,o,i=0,s=new this(1),a=[];if(e===void 0?e=this.precision:j(e,1,ae),r=Math.ceil(e/P),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));i<r;)o=t[i],o>=429e7?t[i]=crypto.getRandomValues(new Uint32Array(1))[0]:a[i++]=o%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);i<r;)o=t[i]+(t[i+1]<<8)+(t[i+2]<<16)+((t[i+3]&127)<<24),o>=214e7?crypto.randomBytes(4).copy(t,i):(a.push(o%1e7),i+=4);i=r/4}else throw Error(zt);else for(;i<r;)a[i++]=Math.random()*1e7|0;for(r=a[--i],e%=P,r&&e&&(o=F(10,P-e),a[i]=(r/o|0)*o);a[i]===0;i--)a.pop();if(i<0)n=0,a=[0];else{for(n=-1;a[0]===0;n-=P)a.shift();for(r=1,o=a[0];o>=10;o/=10)r++;r<P&&(n-=P-r)}return s.e=n,s.d=a,s}function Pr(e){return T(e=new this(e),e.e+1,this.rounding)}function Ar(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function kr(e){return new this(e).sin()}function Br(e){return new this(e).sinh()}function Sr(e){return new this(e).sqrt()}function Lr(e,t){return new this(e).sub(t)}function Ir(){var e=0,t=arguments,n=new this(t[e]);for(k=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return k=!0,T(n,this.precision,this.rounding)}function Cr(e){return new this(e).tan()}function Nr(e){return new this(e).tanh()}function Er(e){return T(e=new this(e),e.e+1,1)}m[Symbol.for("nodejs.util.inspect.custom")]=m.toString;m[Symbol.toStringTag]="Decimal";var He=m.constructor=tn(ct);ve=new He(ve);Fe=new He(Fe);import{PublicKey as mt}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Rr}from"@solana/spl-token";import{PublicKey as _,SystemProgram as nn,SYSVAR_RENT_PUBKEY as _r}from"@solana/web3.js";function dt({pubkey:e,isSigner:t=!1,isWritable:n=!0}){return{pubkey:e,isWritable:n,isSigner:t}}var Mo=[dt({pubkey:Rr,isWritable:!1}),dt({pubkey:nn.programId,isWritable:!1}),dt({pubkey:_r,isWritable:!1})];function rn({publicKey:e,transformSol:t}){let n=on(e.toString());if(n instanceof _)return t&&n.equals(Pe)?pe:n;if(t&&n.toString()===Pe.toBase58())return pe;if(typeof n=="string"){if(n===_.default.toBase58())return _.default;try{return new _(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function on(e){try{return new _(e)}catch{return e}}var Ko=new _("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Oo=new _("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),vo=new _("SysvarRent111111111111111111111111111111111"),Fo=new _("SysvarC1ock11111111111111111111111111111111"),Vo=new _("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Uo=new _("Sysvar1nstructions1111111111111111111111111"),Wo=nn.programId,qo=new _("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Ho=new _("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Go=new _("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),jo=new _("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),zo=new _("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Yo=new _("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Zo=new _("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Jo=new _("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Xo=new _("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Qo=new _("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),$o=new _("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),pe=new _("So11111111111111111111111111111111111111112"),Pe=_.default;import{PublicKey as Dr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as sn}from"@solana/spl-token";var an={chainId:101,address:Dr.default.toBase58(),programId:sn.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},ne={chainId:101,address:"So11111111111111111111111111111111111111112",programId:sn.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}};var ht=class{constructor({mint:t,decimals:n,symbol:r,name:o,skipMint:i=!1,isToken2022:s=!1}){if(t===Pe.toBase58()||t instanceof mt&&Pe.equals(t)){this.decimals=ne.decimals,this.symbol=ne.symbol,this.name=ne.name,this.mint=new mt(ne.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||t.toString().substring(0,6),this.name=o||t.toString().substring(0,6),this.mint=i?mt.default:rn({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},ge=ht;ge.WSOL=new ht(re(v({},ne),{mint:ne.address}));import je from"big.js";import Or from"bn.js";import vr from"decimal.js-light";import Mr from"toformat";var Kr=Mr,Ae=Kr;var Ge=q("module/fraction"),gt=Ae(je),ke=Ae(vr),Fr={[0]:ke.ROUND_DOWN,[1]:ke.ROUND_HALF_UP,[2]:ke.ROUND_UP},Vr={[0]:je.roundDown,[1]:je.roundHalfUp,[2]:je.roundUp},E=class{constructor(t,n=new Or(1)){this.numerator=Q(t),this.denominator=Q(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new E(this.denominator,this.numerator)}add(t){let n=t instanceof E?t:new E(Q(t));return this.denominator.eq(n.denominator)?new E(this.numerator.add(n.numerator),this.denominator):new E(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(t){let n=t instanceof E?t:new E(Q(t));return this.denominator.eq(n.denominator)?new E(this.numerator.sub(n.numerator),this.denominator):new E(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(t){let n=t instanceof E?t:new E(Q(t));return new E(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(t){let n=t instanceof E?t:new E(Q(t));return new E(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(t,n={groupSeparator:""},r=1){Number.isInteger(t)||Ge.logWithError(`${t} is not an integer.`),t<=0&&Ge.logWithError(`${t} is not positive.`),ke.set({precision:t+1,rounding:Fr[r]});let o=new ke(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return o.toFormat(o.decimalPlaces(),n)}toFixed(t,n={groupSeparator:""},r=1){return Number.isInteger(t)||Ge.logWithError(`${t} is not an integer.`),t<0&&Ge.logWithError(`${t} is negative.`),gt.DP=t,gt.RM=Vr[r]||1,new gt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,n)}isZero(){return this.numerator.isZero()}};var Bi=q("Raydium_price");var bt=class{constructor({decimals:t,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=t,this.symbol=n,this.name=r}equals(t){return this===t}},ze=bt;ze.SOL=new bt(an);import Wr from"bn.js";var _i=new E(new Wr(100));var qr=new z(0),$i=new z(1),es=new z(2),ts=new z(3),ns=new z(5),Hr=new z(10),rs=new z(100),os=new z(1e3),is=new z(1e4),fn=9007199254740991;function Q(e){let t=q("Raydium_parseBigNumberish");if(e instanceof z)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new z(e);t.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&t.logWithError(`BigNumberish number underflow: ${e}`),(e>=fn||e<=-fn)&&t.logWithError(`BigNumberish number overflow: ${e}`),new z(String(e))):typeof e=="bigint"?new z(e.toString()):(t.error(`invalid BigNumberish value: ${e}`),new z(0))}var ws=q("Raydium_amount"),xs=Ae(Gr);import{PublicKey as Le,sendAndConfirmTransaction as Ie,Transaction as Ce,TransactionMessage as Ne,VersionedTransaction as Ee}from"@solana/web3.js";import Qr from"axios";var V={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",AmmV4Swap:"AmmV4Swap",AmmV4AddLiquidity:"AmmV4AddLiquidity",AmmV4RemoveLiquidity:"AmmV4RemoveLiquidity",AmmV4SimulatePoolInfo:"AmmV4SimulatePoolInfo",AmmV4SwapBaseIn:"AmmV4SwapBaseIn",AmmV4SwapBaseOut:"AmmV4SwapBaseOut",AmmV4CreatePool:"AmmV4CreatePool",AmmV4InitPool:"AmmV4InitPool",AmmV5AddLiquidity:"AmmV5AddLiquidity",AmmV5RemoveLiquidity:"AmmV5RemoveLiquidity",AmmV5SimulatePoolInfo:"AmmV5SimulatePoolInfo",AmmV5SwapBaseIn:"AmmV5SwapBaseIn",AmmV5SwapBaseOut:"AmmV5SwapBaseOut",RouteSwap:"RouteSwap",RouteSwap1:"RouteSwap1",RouteSwap2:"RouteSwap2",FarmV3Deposit:"FarmV3Deposit",FarmV3Withdraw:"FarmV3Withdraw",FarmV3CreateLedger:"FarmV3CreateLedger",FarmV5Deposit:"FarmV5Deposit",FarmV5Withdraw:"FarmV5Withdraw",FarmV5CreateLedger:"FarmV5CreateLedger",FarmV6Deposit:"FarmV6Deposit",FarmV6Withdraw:"FarmV6Withdraw",FarmV6Create:"FarmV6Create",FarmV6Restart:"FarmV6Restart",FarmV6CreatorAddReward:"FarmV6CreatorAddReward",FarmV6CreatorWithdraw:"FarmV6CreatorWithdraw",CpmmCreatePool:"CpmmCreatePool",CpmmAddLiquidity:"CpmmAddLiquidity",CpmmWithdrawLiquidity:"CpmmWithdrawLiquidity",CpmmSwapBaseIn:"CpmmSwapBaseIn",CpmmSwapBaseOut:"CpmmSwapBaseOut"};import{PublicKey as jr,ComputeBudgetProgram as pn,Transaction as mn,TransactionMessage as zr,Keypair as hn,VersionedTransaction as gn}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Yr}from"@solana/spl-token";var dn=q("Raydium_txUtil"),bn=1644;function Ye(e){let t=[],n=[];return e.microLamports&&(t.push(pn.setComputeUnitPrice({microLamports:e.microLamports})),n.push(V.SetComputeUnitPrice)),e.units&&(t.push(pn.setComputeUnitLimit({units:e.units})),n.push(V.SetComputeUnitLimit)),{instructions:t,instructionTypes:n}}async function be(e){var t,n;try{return((n=await((t=e.getLatestBlockhash)==null?void 0:t.call(e)))==null?void 0:n.blockhash)||(await e.getRecentBlockhash()).blockhash}catch{return(await e.getRecentBlockhash()).blockhash}}function Zr(e,t){e.length<1&&dn.logWithError(`no instructions provided: ${e.toString()}`),t.length<1&&dn.logWithError(`no signers provided:, ${t.toString()}`);let n=new mn;n.recentBlockhash="11111111111111111111111111111111",n.feePayer=t[0],n.add(...e);try{return Buffer.from(n.serialize({verifySignatures:!1})).toString("base64").length<bn}catch{return!1}}function yn(e,t){let[n,r]=jr.findProgramAddressSync(e,t);return{publicKey:n,nonce:r}}function Be({instructions:e,payer:t,signers:n}){return Zr(e,[t,...n])}function Se({instructions:e,payer:t,lookupTableAddressAccount:n,recentBlockhash:r=hn.generate().publicKey.toString()}){let i=new zr({payerKey:t,recentBlockhash:r,instructions:e}).compileToV0Message(Object.values(n!=null?n:{}));try{return Buffer.from(new gn(i).serialize()).toString("base64").length<bn}catch{return!1}}var Jr=e=>Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e.buffer,e.byteOffset,e.byteLength):Buffer.from(e);function de(e){let t=[];return e.forEach(n=>{n instanceof mn&&(n.recentBlockhash||(n.recentBlockhash=Yr.toBase58()),n.feePayer||(n.feePayer=hn.generate().publicKey));let r=n.serialize({requireAllSignatures:!1,verifySignatures:!1});n instanceof gn&&(r=Jr(r));let o=r.toString("base64");t.push(o)}),console.log("simulate tx string:",t),t}import{PublicKey as xn,AddressLookupTableAccount as Ze}from"@solana/web3.js";import{PublicKey as Xr}from"@solana/web3.js";import{getTransferFeeConfig as Qs,unpackMint as $s}from"@solana/spl-token";var yt=q("Raydium_accountInfo_util");async function wn(e,t,n){let{batchRequest:r,commitment:o="confirmed"}=v({batchRequest:!1},n),i=wt(t,100),s=new Array(i.length).fill([]);if(r){let a=i.map(f=>{let l=e._buildArgs([f.map(p=>p.toBase58())],o,"base64");return{methodName:"getMultipleAccounts",args:l}}),u=wt(a,10);s=(await(await Promise.all(u.map(async f=>await e._rpcBatchRequest(f)))).flat()).map(f=>(f.error&&yt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${f.error.message}`),f.result.value.map(l=>{if(l){let{data:p,executable:d,lamports:w,owner:g,rentEpoch:x}=l;return p.length!==2&&p[1]!=="base64"&&yt.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(p[0],"base64"),executable:d,lamports:w,owner:new Xr(g),rentEpoch:x}}return null})))}else try{s=await Promise.all(i.map(a=>e.getMultipleAccountsInfo(a,o)))}catch(a){a instanceof Error&&yt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${a.message}`)}return s.flat()}async function xt({connection:e,address:t}){let n=await wn(e,[...new Set(t.map(o=>o.toString()))].map(o=>new xn(o))),r={};for(let o=0;o<t.length;o++){let i=n[o],s=t[o];if(!i)continue;let a=new Ze({key:s,state:Ze.deserialize(i.data)});r[s.toString()]=a,Je[s.toString()]=a}return r}var Je={"2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17":new Ze({key:new xn("2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17"),state:Ze.deserialize(Buffer.from("AQAAAP//////////d49+DAAAAAAAAQZMWvw7GUNJdaccNBVnb57OKakxL2BHLYvhRwVILRsgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMGRm/lIRcy/+ytunLDm+e8jOW7xfcSayxDmzpAAAAABt324ddloZPZy+FGzut5rBy0he1fWzeROoz1hX7/AKkG3fbh7nWP3hhCXbzkbM3athr8TYO5DSf+vfko2KGL/AVKU1D4XciC1hSlVnJ4iilt3x6rq9CmBniISTL07vagBqfVFxksXFEhjMlMPUrxf1ja7gibof1E49vZigAAAAAGp9UXGMd0yShWY5hpHV62i164o5tLbVxzVVshAAAAAIyXJY9OJInxuz0QKRSODYMLWhOZ2v8QhASOe9jb6fhZC3BlsePRfEU4nVJ/awTDzVi4bHMaoP21SbbRvAP4KUbIScv+6Yw2LHF/6K0ZjUPibbSWXCirYPGuuVl7zT789IUPLW4CpHr4JNCatp3ELXDLKMv6JJ+37le50lbBJ2LvDQdRqCgtphMF/imcN7mY5YRx2xE1A3MQ+L4QRaYK9u4GRfZP3LsAd00a+IkCpA22UNQMKdq5BFbJuwuOLqc8zxCTDlqxBG8J0HcxtfogQHDK06ukzfaXiNDKAob1MqBHS9lJxDYCwz8gd5DtFqNSTKG5l1zxIaKpDP/sffi2is1H9aKveyXSu5StXElYRl9SD5As0DHE4N0GLnf84/siiKXVyp4Ez121kLcUui/jLLFZEz/BwZK3Ilf9B9OcsEAeDMKAy2vjGSxQODgBz0QwGA+eP4ZjIjrIAQaXENv31QfLlOdXSRCkaybRniDHF4C8YcwhcvsqrOVuTP4B2Na+9wLdtrB31uz2rtlFI5kahdsnp/d1SrASDInYCtTYtdoke4kX+hoKWcEWM4Tle8pTUkUVv4BxS6fje/EzKBE4Qu9N9LMnrw/JNO0hqMVB4rk/2ou4AB1loQ7FZoPwut2o4KZB+0p9xnbrQKw038qjpHar+PyDwvxBRcu5hpHw3dguezeWv+IwvgW5icu8EGkhGa9AkFPPJT7VMSFb8xowveU=","base64"))})};var Xe=class{constructor(t){this.instructions=[];this.endInstructions=[];this.lookupTableAddress=[];this.signers=[];this.instructionTypes=[];this.endInstructionTypes=[];this.connection=t.connection,this.feePayer=t.feePayer,this.signAllTransactions=t.signAllTransactions,this.owner=t.owner,this.cluster=t.cluster}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 r;let t=(await Qr.get(`https://solanacompass.com/api/fees?cacheFreshTime=${3e5}`)).data,{avg:n}=(r=t==null?void 0:t[15])!=null?r:{};if(!!n)return{units:6e5,microLamports:Math.min(Math.ceil(n*1e6/6e5),25e3)}}addCustomComputeBudget(t){if(t){let{instructions:n,instructionTypes:r}=Ye(t);return this.instructions.unshift(...n),this.instructionTypes.unshift(...r),!0}return!1}async calComputeBudget({config:t,defaultIns:n}){try{let r=t||await this.getComputeBudgetConfig();if(this.addCustomComputeBudget(r))return;n&&this.instructions.unshift(...n)}catch{n&&this.instructions.unshift(...n)}}addInstruction({instructions:t=[],endInstructions:n=[],signers:r=[],instructionTypes:o=[],endInstructionTypes:i=[],lookupTableAddress:s=[]}){return this.instructions.push(...t),this.endInstructions.push(...n),this.signers.push(...r),this.instructionTypes.push(...o),this.endInstructionTypes.push(...i),this.lookupTableAddress.push(...s.filter(a=>a!==Le.default.toString())),this}async versionBuild({txVersion:t,extInfo:n}){return t===0?await this.buildV0(v({},n||{})):this.build(n)}build(t){let n=new Ce;return this.allInstructions.length&&n.add(...this.allInstructions),n.feePayer=this.feePayer,{builder:this,transaction:n,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async r=>{var a;let{recentBlockHash:o,skipPreflight:i=!0}=r||{},s=o!=null?o:await be(this.connection);if(n.recentBlockhash=s,this.signers.length&&n.sign(...this.signers),de([n]),(a=this.owner)!=null&&a.isKeyPair)return{txId:await Ie(this.connection,n,this.signers.find(u=>u.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:i}),signedTx:n};if(this.signAllTransactions){let u=await this.signAllTransactions([n]);return{txId:await this.connection.sendRawTransaction(u[0].serialize(),{skipPreflight:i}),signedTx:u[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:t||{}}}buildMultiTx(t){let{extraPreBuildData:n=[],extInfo:r}=t,{transaction:o}=this.build(r),i=n.filter(c=>c.transaction.instructions.length>0),s=[o,...i.map(c=>c.transaction)],a=[this.signers,...i.map(c=>c.signers)],u=[...this.instructionTypes,...i.map(c=>c.instructionTypes).flat()];return{builder:this,transactions:s,signers:a,instructionTypes:u,execute:async c=>{var g;let{sequentially:f,onTxUpdate:l,recentBlockHash:p,skipPreflight:d=!0}=c||{},w=p!=null?p:await be(this.connection);if((g=this.owner)!=null&&g.isKeyPair){if(f){let x=[];for(let b of s){let y=await Ie(this.connection,b,this.signers.find(h=>h.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:d});x.push(y)}return{txIds:x,signedTxs:s}}return{txIds:await await Promise.all(s.map(async(x,b)=>(x.recentBlockhash=w,await Ie(this.connection,x,a[b].find(y=>y.publicKey.equals(this.owner.publicKey))?a[b]:[...a[b],this.owner.signer],{skipPreflight:d})))),signedTxs:s}}if(this.signAllTransactions){let x=s.map((y,h)=>(y.recentBlockhash=w,a[h].length&&y.sign(...a[h]),y));de(x);let b=await this.signAllTransactions(x);if(f){let y=0,h=[],A=async()=>{if(!b[y])return;let B=await this.connection.sendRawTransaction(b[y].serialize(),{skipPreflight:d});h.push({txId:B,status:"sent",signedTx:b[y]}),l==null||l([...h]),y++,this.connection.onSignature(B,R=>{let D=h.findIndex(K=>K.txId===B);D>-1&&(h[D].status=R.err?"error":"success"),l==null||l([...h]),R.err||A()},"processed"),this.connection.getSignatureStatus(B)};return await A(),{txIds:h.map(B=>B.txId),signedTxs:b}}else{let y=[];for(let h=0;h<b.length;h+=1){let A=await this.connection.sendRawTransaction(b[h].serialize(),{skipPreflight:d});y.push(A)}return{txIds:y,signedTxs:b}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async versionMultiBuild({extraPreBuildData:t,txVersion:n,extInfo:r}){return n===0?await this.buildV0MultiTx({extraPreBuildData:t,buildProps:r||{}}):this.buildMultiTx({extraPreBuildData:t,extInfo:r})}async buildV0(t){let p=t||{},{lookupTableCache:n={},lookupTableAddress:r=[],forerunCreate:o}=p,i=fe(p,["lookupTableCache","lookupTableAddress","forerunCreate"]),s=v(v({},this.cluster==="devnet"?{}:Je),n),a=Array.from(new Set([...r,...this.lookupTableAddress])),u=[];for(let d of a)s[d]===void 0&&u.push(new Le(d));let c=await xt({connection:this.connection,address:u});for(let[d,w]of Object.entries(c))s[d]=w;let f=new Ne({payerKey:this.feePayer,recentBlockhash:o?Le.default.toBase58():await be(this.connection),instructions:[...this.allInstructions]}).compileToV0Message(Object.values(s)),l=new Ee(f);return l.sign(this.signers),{builder:this,transaction:l,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async d=>{var x;let{recentBlockHash:w,skipPreflight:g=!0}=d||{};if(w&&(l.message.recentBlockhash=w),de([l]),(x=this.owner)!=null&&x.isKeyPair){this.signers.find(A=>A.publicKey.equals(this.owner.publicKey))||l.sign([this.owner.signer]);let b=await this.connection.sendTransaction(l,{skipPreflight:g}),{lastValidBlockHeight:y,blockhash:h}=await this.connection.getLatestBlockhash();return await this.connection.confirmTransaction({blockhash:h,lastValidBlockHeight:y,signature:b},"confirmed"),{txId:b,signedTx:l}}if(this.signAllTransactions){let b=await this.signAllTransactions([l]);return{txId:await this.connection.sendTransaction(b[0],{skipPreflight:g}),signedTx:b[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}async buildV0MultiTx(t){let{extraPreBuildData:n=[],buildProps:r}=t,{transaction:o}=await this.buildV0(r),i=n.filter(c=>c.builder.instructions.length>0),s=[o,...i.map(c=>c.transaction)],a=[this.signers,...i.map(c=>c.signers)],u=[...this.instructionTypes,...i.map(c=>c.instructionTypes).flat()];return s.forEach(async(c,f)=>{c.sign(a[f])}),{builder:this,transactions:s,signers:a,instructionTypes:u,buildProps:r,execute:async c=>{var w;let{sequentially:f,onTxUpdate:l,recentBlockHash:p,skipPreflight:d=!0}=c||{};if(p&&s.forEach(g=>g.message.recentBlockhash=p),de(s),(w=this.owner)!=null&&w.isKeyPair){let{lastValidBlockHeight:g,blockhash:x}=await this.connection.getLatestBlockhash();if(s.forEach((b,y)=>{a[y].find(h=>h.publicKey.equals(this.owner.publicKey))||b.sign([this.owner.signer])}),f){let b=[];for(let y of s){let h=await this.connection.sendTransaction(y,{skipPreflight:d}),{lastValidBlockHeight:A,blockhash:B}=await this.connection.getLatestBlockhash();await this.connection.confirmTransaction({blockhash:B,lastValidBlockHeight:A,signature:h},"confirmed"),b.push(h)}return{txIds:b,signedTxs:s}}return{txIds:await Promise.all(s.map(async b=>{let y=await this.connection.sendTransaction(b,{skipPreflight:d});return await this.connection.confirmTransaction({blockhash:x,lastValidBlockHeight:g,signature:y},"confirmed"),y})),signedTxs:s}}if(this.signAllTransactions){let g=await this.signAllTransactions(s);if(f){let x=0,b=[],y=async()=>{if(!g[x])return;let h=await this.connection.sendTransaction(g[x],{skipPreflight:d});b.push({txId:h,status:"sent",signedTx:g[x]}),l==null||l([...b]),x++,this.connection.onSignature(h,A=>{let B=b.findIndex(R=>R.txId===h);B>-1&&(b[B].status=A.err?"error":"success"),l==null||l([...b]),A.err||y()},"processed"),this.connection.getSignatureStatus(h)};return y(),{txIds:[],signedTxs:g}}else{let x=[];for(let b=0;b<g.length;b+=1){let y=await this.connection.sendTransaction(g[b],{skipPreflight:d});x.push(y)}return{txIds:x,signedTxs:g}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async sizeCheckBuild(t){let c=t||{},{computeBudgetConfig:n}=c,r=fe(c,["computeBudgetConfig"]),o=n?Ye(n):{instructions:[],instructionTypes:[]},i=this.signers.reduce((f,l)=>re(v({},f),{[l.publicKey.toBase58()]:l}),{}),s=[],a=[],u=[];if(this.allInstructions.forEach(f=>{let l=[...u,f],p=n?[...o.instructions,...l]:l,w=[...new Set(l.map(g=>g.keys.filter(x=>x.isSigner).map(x=>x.pubkey.toString())).flat()).values()].map(g=>new Le(g));if(u.length<12&&Be({instructions:p,payer:this.feePayer,signers:w})||Be({instructions:l,payer:this.feePayer,signers:w}))u.push(f);else{if(u.length===0)throw Error("item ins too big");Be({instructions:n?[...o.instructions,...u]:[...u],payer:this.feePayer,signers:w})?s.push(new Ce().add(...o.instructions,...u)):s.push(new Ce().add(...u)),a.push(Array.from(new Set(u.map(g=>g.keys.filter(x=>x.isSigner).map(x=>x.pubkey.toString())).flat())).map(g=>i[g]).filter(g=>g!==void 0)),u=[f]}}),u.length>0){let l=[...new Set(u.map(p=>p.keys.filter(d=>d.isSigner).map(d=>d.pubkey.toString())).flat()).values()].map(p=>i[p]).filter(p=>p!==void 0);Be({instructions:n?[...o.instructions,...u]:[...u],payer:this.feePayer,signers:l.map(p=>p.publicKey)})?s.push(new Ce().add(...o.instructions,...u)):s.push(new Ce().add(...u)),a.push(l)}return s.forEach(f=>f.feePayer=this.feePayer),{builder:this,transactions:s,signers:a,instructionTypes:this.instructionTypes,execute:async f=>{var x;let{sequentially:l,onTxUpdate:p,recentBlockHash:d,skipPreflight:w=!0}=f||{},g=d!=null?d:await be(this.connection);if(s.forEach(async(b,y)=>{b.recentBlockhash=g,a[y].length&&b.sign(...a[y])}),de(s),(x=this.owner)!=null&&x.isKeyPair){if(l){let b=[];for(let y of s){let h=await Ie(this.connection,y,this.signers.find(A=>A.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:w});b.push(h)}return{txIds:b,signedTxs:s}}return{txIds:await Promise.all(s.map(async(b,y)=>await Ie(this.connection,b,a[y].find(h=>h.publicKey.equals(this.owner.publicKey))?a[y]:[...a[y],this.owner.signer],{skipPreflight:w}))),signedTxs:s}}if(this.signAllTransactions){let b=await this.signAllTransactions(s);if(l){let y=0,h=[],A=async()=>{if(!b[y])return;let B=await this.connection.sendRawTransaction(b[y].serialize(),{skipPreflight:w});h.push({txId:B,status:"sent",signedTx:b[y]}),p==null||p([...h]),y++,this.connection.onSignature(B,R=>{let D=h.findIndex(K=>K.txId===B);D>-1&&(h[D].status=R.err?"error":"success"),p==null||p([...h]),R.err||A()},"processed"),this.connection.getSignatureStatus(B)};return await A(),{txIds:h.map(B=>B.txId),signedTxs:b}}else{let y=[];for(let h=0;h<b.length;h+=1){let A=await this.connection.sendRawTransaction(b[h].serialize(),{skipPreflight:w});y.push(A)}return{txIds:y,signedTxs:b}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async sizeCheckBuildV0(t){let x=t||{},{computeBudgetConfig:n,lookupTableCache:r={},lookupTableAddress:o=[]}=x,i=fe(x,["computeBudgetConfig","lookupTableCache","lookupTableAddress"]),s=v(v({},this.cluster==="devnet"?{}:Je),r),a=Array.from(new Set([...this.lookupTableAddress,...o])),u=[];for(let b of a)s[b]===void 0&&u.push(new Le(b));let c=await xt({connection:this.connection,address:u});for(let[b,y]of Object.entries(c))s[b]=y;let f=n?Ye(n):{instructions:[],instructionTypes:[]},l=await be(this.connection),p=this.signers.reduce((b,y)=>re(v({},b),{[y.publicKey.toBase58()]:y}),{}),d=[],w=[],g=[];if(this.allInstructions.forEach(b=>{let y=[...g,b],h=n?[...f.instructions,...y]:y;if(g.length<12&&Se({instructions:h,payer:this.feePayer,lookupTableAddressAccount:s})||Se({instructions:y,payer:this.feePayer,lookupTableAddressAccount:s}))g.push(b);else{if(g.length===0)throw Error("item ins too big");let A={};for(let B of[...new Set(a)])s[B]!==void 0&&(A[B]=s[B]);if(n&&Se({instructions:[...f.instructions,...g],payer:this.feePayer,lookupTableAddressAccount:s,recentBlockhash:l})){let B=new Ne({payerKey:this.feePayer,recentBlockhash:l,instructions:[...f.instructions,...g]}).compileToV0Message(Object.values(s));d.push(new Ee(B))}else{let B=new Ne({payerKey:this.feePayer,recentBlockhash:l,instructions:[...g]}).compileToV0Message(Object.values(s));d.push(new Ee(B))}w.push(Array.from(new Set(g.map(B=>B.keys.filter(R=>R.isSigner).map(R=>R.pubkey.toString())).flat())).map(B=>p[B]).filter(B=>B!==void 0)),g=[b]}}),g.length>0){let y=[...new Set(g.map(h=>h.keys.filter(A=>A.isSigner).map(A=>A.pubkey.toString())).flat()).values()].map(h=>p[h]).filter(h=>h!==void 0);if(n&&Se({instructions:[...f.instructions,...g],payer:this.feePayer,lookupTableAddressAccount:s,recentBlockhash:l})){let h=new Ne({payerKey:this.feePayer,recentBlockhash:l,instructions:[...f.instructions,...g]}).compileToV0Message(Object.values(s));d.push(new Ee(h))}else{let h=new Ne({payerKey:this.feePayer,recentBlockhash:l,instructions:[...g]}).compileToV0Message(Object.values(s));d.push(new Ee(h))}w.push(y)}return{builder:this,transactions:d,buildProps:t,signers:w,instructionTypes:this.instructionTypes,execute:async b=>{var R;let{sequentially:y,onTxUpdate:h,recentBlockHash:A,skipPreflight:B=!0}=b||{};if(d.map(async(D,K)=>{w[K].length&&D.sign(w[K]),A&&(D.message.recentBlockhash=A)}),de(d),(R=this.owner)!=null&&R.isKeyPair){let{lastValidBlockHeight:D,blockhash:K}=await this.connection.getLatestBlockhash();if(d.forEach((M,G)=>{w[G].find(O=>O.publicKey.equals(this.owner.publicKey))||M.sign([this.owner.signer])}),y){let M=[];for(let G of d){let O=await this.connection.sendTransaction(G,{skipPreflight:B}),{lastValidBlockHeight:$,blockhash:ee}=await this.connection.getLatestBlockhash();await this.connection.confirmTransaction({blockhash:ee,lastValidBlockHeight:$,signature:O},"confirmed"),M.push(O)}return{txIds:M,signedTxs:d}}return{txIds:await Promise.all(d.map(async M=>{let G=await this.connection.sendTransaction(M,{skipPreflight:B});return await this.connection.confirmTransaction({blockhash:K,lastValidBlockHeight:D,signature:G},"confirmed"),G})),signedTxs:d}}if(this.signAllTransactions){let D=await this.signAllTransactions(d);if(y){let K=0,M=[],G=async()=>{if(!D[K])return;let O=await this.connection.sendTransaction(D[K],{skipPreflight:B});M.push({txId:O,status:"sent",signedTx:D[K]}),h==null||h([...M]),K++,this.connection.onSignature(O,$=>{let ee=M.findIndex(xe=>xe.txId===O);ee>-1&&(M[ee].status=$.err?"error":"success"),h==null||h([...M]),$.err||G()},"processed"),this.connection.getSignatureStatus(O)};return G(),{txIds:[],signedTxs:D}}else{let K=[];for(let M=0;M<D.length;M+=1){let G=await this.connection.sendTransaction(D[M],{skipPreflight:B});K.push(G)}return{txIds:K,signedTxs:D}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}};function wt(e,t=1,n=[]){let r=[...e];if(t<=0)return n;for(;r.length;)n.push(r.splice(0,t));return n}import{PublicKey as I}from"@solana/web3.js";var Pa=new I("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),Aa=new I("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),ka=new I("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Ba=new I("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),Sa=new I("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),La=new I("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Ia=new I("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Ca=new I("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Na=new I("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),Ea=new I("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Ra=new I("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),_a=new I("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Da=new I("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),Ma=new I("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),Ka=new I("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),Oa=new I("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),va=new I("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Fa=new I("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),$r=new I("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),eo=new I("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),to=new I("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2");var Va={SERUM_MARKET:I.default,OPENBOOK_MARKET:new I("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:I.default,FarmV3:new I("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new I("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new I("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new I("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new I("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new I("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),Router:new I("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:$r,CREATE_CPMM_POOL_AUTH:eo,CREATE_CPMM_POOL_FEE_ACC:to,FEE_DESTINATION_ID:new I("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR")};import{PublicKey as no}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ro}from"@solana/spl-token";function Qe(e,t,n){return yn([e.toBuffer(),(n!=null?n:ro).toBuffer(),t.toBuffer()],new no("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}import za from"bn.js";var Tt=(...e)=>e.map(t=>{try{return typeof t=="object"?JSON.stringify(t):t}catch{return t}}).join(", "),Re=class{constructor({scope:t,moduleName:n}){this.disabled=!1;this.scope=t,this.logger=q(n)}createTxBuilder(t){return this.scope.checkOwner(),new Xe({connection:this.scope.connection,feePayer:t||this.scope.ownerPubKey,cluster:this.scope.cluster,owner:this.scope.owner,signAllTransactions:this.scope.signAllTransactions})}logDebug(...t){this.logger.debug(Tt(t))}logInfo(...t){this.logger.info(Tt(t))}logAndCreateError(...t){let n=Tt(t);throw new Error(n)}checkDisabled(){(this.disabled||!this.scope)&&this.logAndCreateError("module not working")}};import{createInitializeAccountInstruction as yo,createCloseAccountInstruction as wo,createTransferInstruction as xo,TOKEN_PROGRAM_ID as ye}from"@solana/spl-token";import{PublicKey as To,SystemProgram as Po}from"@solana/web3.js";import Ao from"bn.js";import{PublicKey as Nn,Keypair as mo}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ho}from"@solana/spl-token";import go from"bn.js";import{PublicKey as co}from"@solana/web3.js";import Pn,{isBN as gu}from"bn.js";import{bits as bc,BitStructure as yc,blob as oo,Blob as wc,cstr as xc,f32 as Tc,f32be as Pc,f64 as Ac,f64be as kc,greedy as Bc,Layout as io,ns64 as Sc,ns64be as Lc,nu64 as Ic,nu64be as Cc,offset as Nc,s16 as Ec,s16be as Rc,s24 as _c,s24be as Dc,s32 as Mc,s32be as Kc,s40 as Oc,s40be as vc,s48 as Fc,s48be as Vc,s8 as Uc,seq as Wc,struct as qc,Structure as so,u16 as Hc,u16be as Gc,u24 as jc,u24be as zc,u32 as Yc,u32be as Zc,u40 as Jc,u40be as Xc,u48 as Qc,u48be as $c,u8 as eu,UInt as ao,union as tu,Union as nu,unionLayoutDiscriminator as ru,utf8 as ou}from"@solana/buffer-layout";var Pt=io,Tn=so;var At=ao;var kt=oo;var Bt=class extends Pt{constructor(n,r,o){super(n,o);this.blob=kt(n),this.signed=r}decode(n,r=0){let o=new Pn(this.blob.decode(n,r),10,"le");return this.signed?o.fromTwos(this.span*8).clone():o}encode(n,r,o=0){return typeof n=="number"&&(n=new Pn(n)),this.signed&&(n=n.toTwos(this.span*8)),this.blob.encode(n.toArrayLike(Buffer,"le",this.span),r,o)}};function An(e){return new At(1,e)}function $e(e){return new At(4,e)}function et(e){return new Bt(8,!1,e)}var St=class extends Pt{constructor(n,r,o,i){super(n.span,i);this.layout=n,this.decoder=r,this.encoder=o}decode(n,r){return this.decoder(this.layout.decode(n,r))}encode(n,r,o){return this.layout.encode(this.encoder(n),r,o)}getSpan(n,r){return this.layout.getSpan(n,r)}};function _e(e){return new St(kt(32),t=>new co(t),t=>t.toBuffer(),e)}var Lt=class extends Tn{decode(t,n){return super.decode(t,n)}};function kn(e,t,n){return new Lt(e,t,n)}var De=kn([_e("mint"),_e("owner"),et("amount"),$e("delegateOption"),_e("delegate"),An("state"),$e("isNativeOption"),et("isNative"),et("delegatedAmount"),$e("closeAuthorityOption"),_e("closeAuthority")]);function uo(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function It(e,...t){if(!uo(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function Ct(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Bn(e,t){It(e);let n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}var nt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),J=(e,t)=>e<<32-t|e>>>t;var ku=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function lo(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Nt(e){return typeof e=="string"&&(e=lo(e)),It(e),e}var tt=class{clone(){return this._cloneInto()}},Bu={}.toString;function Sn(e){let t=r=>e().update(Nt(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function fo(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);let o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),u=r?4:0,c=r?0:4;e.setUint32(t+u,s,r),e.setUint32(t+c,a,r)}var Ln=(e,t,n)=>e&t^~e&n,In=(e,t,n)=>e&t^e&n^t&n,rt=class extends tt{constructor(t,n,r,o){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=nt(this.buffer)}update(t){Ct(this);let{view:n,buffer:r,blockLen:o}=this;t=Nt(t);let i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let u=nt(t);for(;o<=i-s;s+=o)this.process(u,s);continue}r.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ct(this),Bn(t,this),this.finished=!0;let{buffer:n,view:r,blockLen:o,isLE:i}=this,{pos:s}=this;n[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(r,0),s=0);for(let l=s;l<o;l++)n[l]=0;fo(r,o-8,BigInt(this.length*8),i),this.process(r,0);let a=nt(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let c=u/4,f=this.get();if(c>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<c;l++)a.setUint32(4*l,f[l],i)}digest(){let{buffer:t,outputLen:n}=this;this.digestInto(t);let r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:n,buffer:r,length:o,finished:i,destroyed:s,pos:a}=this;return t.length=o,t.pos=a,t.finished=i,t.destroyed=s,o%n&&t.buffer.set(r),t}};var po=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ce=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ue=new Uint32Array(64),Et=class extends rt{constructor(){super(64,32,8,!1),this.A=ce[0]|0,this.B=ce[1]|0,this.C=ce[2]|0,this.D=ce[3]|0,this.E=ce[4]|0,this.F=ce[5]|0,this.G=ce[6]|0,this.H=ce[7]|0}get(){let{A:t,B:n,C:r,D:o,E:i,F:s,G:a,H:u}=this;return[t,n,r,o,i,s,a,u]}set(t,n,r,o,i,s,a,u){this.A=t|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=u|0}process(t,n){for(let l=0;l<16;l++,n+=4)ue[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){let p=ue[l-15],d=ue[l-2],w=J(p,7)^J(p,18)^p>>>3,g=J(d,17)^J(d,19)^d>>>10;ue[l]=g+ue[l-7]+w+ue[l-16]|0}let{A:r,B:o,C:i,D:s,E:a,F:u,G:c,H:f}=this;for(let l=0;l<64;l++){let p=J(a,6)^J(a,11)^J(a,25),d=f+p+Ln(a,u,c)+po[l]+ue[l]|0,g=(J(r,2)^J(r,13)^J(r,22))+In(r,o,i)|0;f=c,c=u,u=a,a=s+d|0,s=i,i=o,o=r,r=d+g|0}r=r+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,u=u+this.F|0,c=c+this.G|0,f=f+this.H|0,this.set(r,o,i,s,a,u,c,f)}roundClean(){ue.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Cn=Sn(()=>new Et);var Wu=q("Raydium_Util");function En({owner:e,solAccountResp:t,tokenAccountResp:n}){let r=[],o=[];for(let{pubkey:i,account:s}of n.value){let a=De.decode(s.data),{mint:u,amount:c}=a;r.push({publicKey:i,mint:u,amount:c,isAssociated:Qe(e,u,s.owner).publicKey.equals(i),isNative:!1,programId:s.owner}),o.push({pubkey:i,accountInfo:a,programId:s.owner})}return t&&r.push({mint:Nn.default,amount:new go(t.lamports),isNative:!0,programId:t.owner}),{tokenAccounts:r,tokenAccountRawInfos:o}}function ot({fromPublicKey:e,programId:t=ho}){let n=mo.generate().publicKey.toBase58().slice(0,32);return{publicKey:bo(e,n,t),seed:n}}function bo(e,t,n){let r=Buffer.concat([e.toBuffer(),Buffer.from(t),n.toBuffer()]),o=Cn(r);return new Nn(o)}function Rt(e){let{mint:t,tokenAccount:n,owner:r,programId:o=ye}=e;return yo(n,t,r,o)}function Me(e){let{tokenAccount:t,payer:n,multiSigners:r=[],owner:o,programId:i=ye}=e;return wo(t,n,o,r,i)}async function _t(e){let{connection:t,amount:n,commitment:r,payer:o,owner:i,skipCloseAccount:s}=e,a=await t.getMinimumBalanceForRentExemption(De.span,r),u=Q(n).add(new Ao(a)),c=ot({fromPublicKey:o,programId:ye});return{addresses:{newAccount:c.publicKey},signers:[],instructions:[Po.createAccountWithSeed({fromPubkey:o,basePubkey:o,seed:c.seed,newAccountPubkey:c.publicKey,lamports:u.toNumber(),space:De.span,programId:ye}),Rt({mint:new To(ne.address),tokenAccount:c.publicKey,owner:i,programId:ye})],instructionTypes:[V.CreateAccount,V.InitAccount],endInstructionTypes:s?[]:[V.CloseAccount],endInstructions:s?[]:[Me({tokenAccount:c.publicKey,payer:o,owner:i})]}}function Rn({source:e,destination:t,owner:n,amount:r,multiSigners:o=[],tokenProgram:i=ye}){return xo(e,t,n,BigInt(String(r)),o,i)}var Mt=class extends Re{constructor(n){super(n);this._tokenAccounts=[];this._tokenAccountRawInfos=[];this._accountListener=[];this._clientOwnedToken=!1;let{tokenAccounts:r,tokenAccountRawInfos:o}=n;this._tokenAccounts=r||[],this._tokenAccountRawInfos=o||[],this._clientOwnedToken=!!(r||o)}get tokenAccounts(){return this._tokenAccounts}get tokenAccountRawInfos(){return this._tokenAccountRawInfos}updateTokenAccount({tokenAccounts:n,tokenAccountRawInfos:r}){return n&&(this._tokenAccounts=n),r&&(this._tokenAccountRawInfos=r),this._accountChangeListenerId&&this.scope.connection.removeAccountChangeListener(this._accountChangeListenerId),this._accountChangeListenerId=void 0,this._clientOwnedToken=!0,this}addAccountChangeListener(n){return this._accountListener.push(n),this}removeAccountChangeListener(n){return this._accountListener=this._accountListener.filter(r=>r!==n),this}getAssociatedTokenAccount(n,r){return Qe(this.scope.ownerPubKey,n,r).publicKey}async fetchWalletTokenAccounts(n){if(this._clientOwnedToken||!(n!=null&&n.forceUpdate)&&this._tokenAccounts.length)return{tokenAccounts:this._tokenAccounts,tokenAccountRawInfos:this._tokenAccountRawInfos};this.scope.checkOwner();let o=v(v({},{}),n),[i,s,a]=await Promise.all([this.scope.connection.getAccountInfo(this.scope.ownerPubKey,o.commitment),this.scope.connection.getTokenAccountsByOwner(this.scope.ownerPubKey,{programId:le},o.commitment),this.scope.connection.getTokenAccountsByOwner(this.scope.ownerPubKey,{programId:ko},o.commitment)]),{tokenAccounts:u,tokenAccountRawInfos:c}=En({owner:this.scope.ownerPubKey,solAccountResp:i,tokenAccountResp:{context:s.context,value:[...s.value,...a.value]}});return this._tokenAccounts=u,this._tokenAccountRawInfos=c,this._accountChangeListenerId&&this.scope.connection.removeAccountChangeListener(this._accountChangeListenerId),this._accountChangeListenerId=this.scope.connection.onAccountChange(this.scope.ownerPubKey,()=>this.fetchWalletTokenAccounts({forceUpdate:!0}),n==null?void 0:n.commitment),{tokenAccounts:u,tokenAccountRawInfos:c}}async getCreatedTokenAccount({mint:n,programId:r=le,associatedOnly:o=!0}){await this.fetchWalletTokenAccounts();let i=this._tokenAccounts.filter(({mint:a})=>a==null?void 0:a.equals(n)).sort((a,u)=>a.amount.lt(u.amount)?1:-1),s=this.getAssociatedTokenAccount(n,r);for(let a of i){let{publicKey:u}=a;if(u&&(!o||o&&s.equals(u)))return u}}async getOrCreateTokenAccount(n){var w,g,x,b;await this.fetchWalletTokenAccounts();let{mint:r,createInfo:o,associatedOnly:i,owner:s,notUseTokenAccount:a=!1,skipCloseAccount:u=!1,checkCreateATAOwner:c=!1}=n,f=new it(n.tokenProgram||le),l=this.getAssociatedTokenAccount(r,new it(f)),p=(a?[]:this.tokenAccountRawInfos).filter(y=>y.accountInfo.mint.equals(r)&&(!i||y.pubkey.equals(l))).sort((y,h)=>y.accountInfo.amount.lt(h.accountInfo.amount)?1:-1);if(o===void 0||p.length>0)return p.length>0?{account:p[0].pubkey}:{};let d={instructions:[],endInstructions:[],signers:[],instructionTypes:[],endInstructionTypes:[]};if(i){let y=Dt(s,l,s,r,f);if(c){let h=await this.scope.connection.getAccountInfo(l);if(h===null)(w=d.instructions)==null||w.push(y),d.instructionTypes.push(V.CreateATA);else if(!(h.owner.equals(f)&&we.decode(h.data).mint.equals(r)&&we.decode(h.data).owner.equals(s)))throw Error(`create ata check error -> mint: ${r.toString()}, ata: ${l.toString()}`)}else d.instructions.push(y),d.instructionTypes.push(V.CreateATA);if(r.equals(pe)&&o.amount){let h=await _t({connection:this.scope.connection,owner:this.scope.ownerPubKey,payer:o.payer||this.scope.ownerPubKey,amount:(g=o.amount)!=null?g:0,skipCloseAccount:u});d.instructions.push(...h.instructions||[]),d.endInstructions.push(...h.endInstructions||[]),d.instructionTypes.push(...h.instructionTypes||[]),d.endInstructionTypes.push(...h.endInstructionTypes||[]),o.amount&&(d.instructions.push(Rn({source:h.addresses.newAccount,destination:l,owner:this.scope.ownerPubKey,amount:o.amount,tokenProgram:le})),d.instructionTypes.push(V.TransferAmount))}return u||(d.endInstructions.push(Me({owner:s,payer:o.payer||s,tokenAccount:l,programId:f})),d.endInstructionTypes.push(V.CloseAccount)),{account:l,instructionParams:d}}else{let y=ot({fromPublicKey:s,programId:f}),h=await this.scope.connection.getMinimumBalanceForRentExemption(we.span),A=Bo.createAccountWithSeed({fromPubkey:s,basePubkey:s,seed:y.seed,newAccountPubkey:y.publicKey,lamports:h+Number((b=(x=o.amount)==null?void 0:x.toString())!=null?b:0),space:we.span,programId:f});return d.instructions.push(A,Rt({mint:r,tokenAccount:y.publicKey,owner:this.scope.ownerPubKey,programId:f})),d.instructionTypes.push(V.CreateAccount),d.instructionTypes.push(V.InitAccount),u||(d.endInstructions.push(Me({owner:s,payer:o.payer||s,tokenAccount:y.publicKey,programId:f})),d.endInstructionTypes.push(V.CloseAccount)),{account:y.publicKey,instructionParams:d}}}async checkOrCreateAta({mint:n,programId:r=le,autoUnwrapWSOLToSOL:o}){var u;await this.fetchWalletTokenAccounts();let i=(u=this.scope.account.tokenAccounts.find(({mint:c})=>(c==null?void 0:c.toBase58())===n.toBase58()))==null?void 0:u.publicKey,s=this.scope.ownerPubKey,a={};if(!i){let c=this.getAssociatedTokenAccount(n,r),f=await Dt(s,c,s,n,r);a.instructions=[f],a.instructionTypes=[V.CreateATA],i=c}return o&&pe.toBase58()===n.toBase58()&&(a.endInstructions=[Me({owner:s,payer:s,tokenAccount:i,programId:r})],a.endInstructionTypes=[V.CloseAccount]),{pubKey:i,newInstructions:a}}async handleTokenAccount(n){let{side:r,amount:o,mint:i,programId:s=le,tokenAccount:a,payer:u=this.scope.ownerPubKey,bypassAssociatedCheck:c,skipCloseAccount:f,checkCreateATAOwner:l}=n,p=this.getAssociatedTokenAccount(i,s);if(new it(pe).equals(i)){let d=await _t({connection:this.scope.connection,owner:this.scope.ownerPubKey,payer:u,amount:o,skipCloseAccount:f});return v({tokenAccount:d.addresses.newAccount},d)}else if(!a||r==="out"&&!p.equals(a)&&!c){let d=[],w=Dt(this.scope.ownerPubKey,p,this.scope.ownerPubKey,i,s);if(l){let g=await this.scope.connection.getAccountInfo(p);if(g===null)d.push(w);else if(!(g.owner.equals(le)&&we.decode(g.data).mint.equals(i)&&we.decode(g.data).owner.equals(this.scope.ownerPubKey)))throw Error(`create ata check error -> mint: ${i.toString()}, ata: ${p.toString()}`)}else d.push(w);return{tokenAccount:p,instructions:d,instructionTypes:[V.CreateATA]}}return{tokenAccount:a}}async processTokenAccount(n){let{mint:r,programId:o=le,amount:i,useSOLBalance:s,handleTokenAccount:a}=n,u,c=this.createTxBuilder();if(r.equals(new it(pe))&&s){let f=await this.handleTokenAccount({side:"in",amount:i||0,mint:r,bypassAssociatedCheck:!0,programId:o}),{tokenAccount:p}=f,d=fe(f,["tokenAccount"]);u=p,c.addInstruction(d)}else if(u=await this.getCreatedTokenAccount({mint:r,associatedOnly:!1,programId:o}),!u&&a){let l=await this.scope.account.handleTokenAccount({side:"in",amount:0,mint:r,bypassAssociatedCheck:!0,programId:o}),{tokenAccount:p}=l,d=fe(l,["tokenAccount"]);u=p,c.addInstruction(d)}return v({tokenAccount:u},c.AllTxData)}};export{Mt as default};
|
|
2
2
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
3
|
//# sourceMappingURL=account.mjs.map
|