@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 Hn=Object.create;var Be=Object.defineProperty,Gn=Object.defineProperties,jn=Object.getOwnPropertyDescriptor,zn=Object.getOwnPropertyDescriptors,Yn=Object.getOwnPropertyNames,Fe=Object.getOwnPropertySymbols,Zn=Object.getPrototypeOf,lt=Object.prototype.hasOwnProperty,Ut=Object.prototype.propertyIsEnumerable;var Vt=(e,t,n)=>t in e?Be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,V=(e,t)=>{for(var n in t||(t={}))lt.call(t,n)&&Vt(e,n,t[n]);if(Fe)for(var n of Fe(t))Ut.call(t,n)&&Vt(e,n,t[n]);return e},ce=(e,t)=>Gn(e,zn(t));var ge=(e,t)=>{var n={};for(var r in e)lt.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Fe)for(var r of Fe(e))t.indexOf(r)<0&&Ut.call(e,r)&&(n[r]=e[r]);return n};var Jn=(e,t)=>{for(var n in t)Be(e,n,{get:t[n],enumerable:!0})},Wt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Yn(t))!lt.call(e,o)&&o!==n&&Be(e,o,{get:()=>t[o],enumerable:!(r=jn(t,o))||r.enumerable});return e};var G=(e,t,n)=>(n=e!=null?Hn(Zn(e)):{},Wt(t||!e||!e.__esModule?Be(n,"default",{value:e,enumerable:!0}):n,e)),Xn=e=>Wt(Be({},"__esModule",{value:!0}),e);var po={};Jn(po,{default:()=>ut});module.exports=Xn(po);var O=require("@solana/spl-token"),we=require("@solana/web3.js");var Se=require("lodash"),pt=G(require("dayjs")),Ht=G(require("dayjs/plugin/utc"));pt.default.extend(Ht.default);var ft=class{constructor(t){this.logLevel=t.logLevel!==void 0?t.logLevel:0,this.name=t.name}set level(t){this.logLevel=t}get time(){return(0,pt.default)().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}},qt={},Qn={};function j(e){let t=(0,Se.get)(qt,e);if(!t){let n=(0,Se.get)(Qn,e);t=new ft({name:e,logLevel:n}),(0,Se.set)(qt,e,t)}return t}var $r=require("@solana/web3.js"),eo=G(require("bn.js"));var wn=G(require("big.js")),Qr=G(require("bn.js"));var J=G(require("bn.js"));var xe=9e15,pe=1e9,dt="0123456789abcdef",Ue="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",We="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",mt={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-xe,maxE:xe,crypto:!1},Yt,se,k=!0,He="[DecimalError] ",fe=He+"Invalid argument: ",Zt=He+"Precision limit exceeded",Jt=He+"crypto unavailable",Xt="[object Decimal]",z=Math.floor,U=Math.pow,$n=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,er=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,tr=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Qt=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,ee=1e7,P=7,nr=9007199254740991,rr=Ue.length-1,ht=We.length-1,m={toStringTag:Xt};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(fe+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=or(r,rn(r,n)),r.precision=e,r.rounding=t,T(se==2||se==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*U(f.s*f,1/3),!i||Math.abs(i)==1/0?(n=q(f.d),e=f.e,(i=(e-n.length+1)%3)&&(n+=i==1||i==-2?"0":"00"),i=U(n,1/3),e=z((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=E(c.plus(f).times(a),c.plus(u),s+2,1),q(a.d).slice(0,s)===(n=q(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-z(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 E(this,new this.constructor(e))};m.dividedToIntegerBy=m.divToInt=function(e){var t=this,n=t.constructor;return T(E(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/je(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),i=Te(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=Te(i,2,o,o,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,o=o.times(1/je(5,e)),o=Te(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,E(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()?$(n,o,i):new n(0):new n(NaN):t.isZero()?$(n,o+4,i).times(.5):(n.precision=o+6,n.rounding=1,t=t.asin(),e=$(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=E(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=$(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<=ht)return s=$(f,l+4,p).times(.25),s.s=c.s,s}else{if(!c.s)return new f(NaN);if(l+4<=ht)return s=$(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&&z(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=le(c,a),r=t?qe(f,a+10):le(e,a),u=E(s,r,a,1),Le(u.d,o=l,p))do if(a+=10,s=le(c,a),r=t?qe(f,a+10):le(e,a),u=E(s,r,a,1),!i){+q(u.d).slice(o+1,o+15)+1==1e14&&(u=T(u,l+1,0));break}while(Le(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=z(e.e/P),f=z(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]=ee-1;--c[o],c[r]+=ee}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=Ge(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=E(n,e.abs(),0,3,1),t.s*=e.s):t=E(n,e,0,r.modulo,1),t=t.times(e),k=!0,n.minus(t))};m.naturalExponential=m.exp=function(){return gt(this)};m.naturalLogarithm=m.ln=function(){return le(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=z(l.e/P),r=z(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)/ee|0,c[o]%=ee;for(t&&(c.unshift(t),++r),s=c.length;c[--s]==0;)c.pop();return e.d=c,e.e=Ge(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(fe+e);return n.d?(t=$t(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=sr(r,rn(r,n)),r.precision=e,r.rounding=t,T(se>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=q(a),(t.length+u)%2==0&&(t+="0"),c=Math.sqrt(t),u=z((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(E(s,i,n+2,1)).times(.5),q(i.d).slice(0,n)===(t=q(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=E(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,T(se==2||se==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=z(f.e/P)+z(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%ee|0,t=a/ee|0;i[o]=(i[o]+t)%ee|0}for(;!i[--s];)i.pop();return t?++n:i.shift(),e.d=i,e.e=Ge(i,n),k?T(e,l.precision,l.rounding):e};m.toBinary=function(e,t){return yt(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:(X(e,0,pe),t===void 0?t=r.rounding:X(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=ne(r,!0):(X(e,0,pe),t===void 0?t=o.rounding:X(t,0,8),r=T(new o(r),e+1,t),n=ne(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=ne(o):(X(e,0,pe),t===void 0?t=i.rounding:X(t,0,8),r=T(new i(o),e+o.e+1,t),n=ne(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=$t(w)-d.e-1,s=i%P,t.d[0]=U(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(fe+a);e=a.gt(t)?i>0?t:c:a}for(k=!1,a=new g(q(w)),f=g.precision,g.precision=i=w.length*P*2;l=E(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=E(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=E(c,r,i,1).minus(d).abs().cmp(E(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 yt(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:X(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=E(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 yt(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(U(+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=z(e.e/P),t>=e.d.length-1&&(n=c<0?-c:c)<=nr)return o=en(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=U(+a,c),t=n==0||!isFinite(n)?z(c*(Math.log("0."+q(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=gt(e.times(le(a,r+n)),r),o.d&&(o=T(o,r+5,1),Le(o.d,r,i)&&(t=r+10,o=T(gt(e.times(le(a,t+n)),t),t+5,1),+q(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=ne(r,r.e<=o.toExpNeg||r.e>=o.toExpPos):(X(e,1,pe),t===void 0?t=o.rounding:X(t,0,8),r=T(new o(r),e,t),n=ne(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):(X(e,1,pe),t===void 0?t=r.rounding:X(t,0,8)),T(new r(n),e,t)};m.toString=function(){var e=this,t=e.constructor,n=ne(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=ne(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function q(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+=ue(n)),i+=r;s=e[t],r=s+"",n=P-r.length,n&&(i+=ue(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return i+s}function X(e,t,n){if(e!==~~e||e<t||e>n)throw Error(fe+e)}function Le(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=U(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)==U(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)==U(10,t-3)-1,s}function Ve(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]+=dt.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 or(e,t){var n,r,o;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),o=(1/je(4,n)).toString()):(n=16,o="2.3283064365386962890625e-10"),e.precision+=n,t=Te(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 E=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,B,S,D,M,v,K,Z,F,oe,ie=r.constructor,ke=r.s==o.s?1:-1,H=r.d,R=o.d;if(!H||!H[0]||!R||!R[0])return new ie(!r.s||!o.s||(H?R&&H[0]==R[0]:!R)?NaN:H&&H[0]==0||!R?ke*0:ke/0);for(u?(d=1,f=r.e-o.e):(u=ee,d=P,f=z(r.e/d)-z(o.e/d)),F=R.length,K=H.length,h=new ie(ke),y=h.d=[],l=0;R[l]==(H[l]||0);l++);if(R[l]>(H[l]||0)&&f--,i==null?(D=i=ie.precision,s=ie.rounding):a?D=i+(r.e-o.e)+1:D=i,D<0)y.push(1),w=!0;else{if(D=D/d+2|0,l=0,F==1){for(p=0,R=R[0],D++;(l<K||p)&&D--;l++)M=p*u+(H[l]||0),y[l]=M/R|0,p=M%R|0;w=p||l<K}else{for(p=u/(R[0]+1)|0,p>1&&(R=e(R,p,u),H=e(H,p,u),F=R.length,K=H.length),v=F,b=H.slice(0,F),B=b.length;B<F;)b[B++]=0;oe=R.slice(),oe.unshift(0),Z=R[0],R[1]>=u/2&&++Z;do p=0,c=t(R,b,F,B),c<0?(S=b[0],F!=B&&(S=S*u+(b[1]||0)),p=S/Z|0,p>1?(p>=u&&(p=u-1),g=e(R,p,u),x=g.length,B=b.length,c=t(g,b,x,B),c==1&&(p--,n(g,F<x?oe:R,x,u))):(p==0&&(c=p=1),g=R.slice()),x=g.length,x<B&&g.unshift(0),n(b,g,B,u),c==-1&&(B=b.length,c=t(R,b,F,B),c<1&&(p++,n(b,F<B?oe:R,B,u))),B=b.length):c===0&&(p++,b=[0]),y[l++]=p,c&&b[0]?b[B++]=H[v]||0:(b=[H[v]],B=1);while((v++<K||b[0]!==void 0)&&D--);w=b[0]!==void 0}y[0]||y.shift()}if(d==1)h.e=f,Yt=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/U(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/U(10,o-s-1)%10|0}if(r=r||t<0||l[p+1]!==void 0||(s<0?f:f%U(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/U(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]=U(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=U(10,P-i),l[p]=s>0?(f/U(10,o-s)%U(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]==ee&&(l[0]=1));break}else{if(l[p]+=a,l[p]!=ee)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 ne(e,t,n){if(!e.isFinite())return nn(e);var r,o=e.e,i=q(e.d),s=i.length;return t?(n&&(r=n-s)>0?i=i.charAt(0)+"."+i.slice(1)+ue(r):s>1&&(i=i.charAt(0)+"."+i.slice(1)),i=i+(e.e<0?"e":"e+")+e.e):o<0?(i="0."+ue(-o-1)+i,n&&(r=n-s)>0&&(i+=ue(r))):o>=s?(i+=ue(o+1-s),n&&(r=n-o-1)>0&&(i=i+"."+ue(r))):((r=o+1)<s&&(i=i.slice(0,r)+"."+i.slice(r)),n&&(r=n-s)>0&&(o+1===s&&(i+="."),i+=ue(r))),i}function Ge(e,t){var n=e[0];for(t*=P;n>=10;n/=10)t++;return t}function qe(e,t,n){if(t>rr)throw k=!0,n&&(e.precision=n),Error(Zt);return T(new e(Ue),t,1,!0)}function $(e,t,n){if(t>ht)throw Error(Zt);return T(new e(We),t,n,!0)}function $t(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 ue(e){for(var t="";e--;)t+="0";return t}function en(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),jt(i.d,s)&&(o=!0)),n=z(n/2),n===0){n=i.d.length-1,o&&i.d[n]===0&&++i.d[n];break}t=t.times(t),jt(t.d,s)}return k=!0,i}function Gt(e){return e.d[e.d.length-1]&1}function tn(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 gt(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(U(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(E(i,n,u,1)),q(a.d).slice(0,u)===q(s.d).slice(0,u)){for(o=l;o--;)s=T(s.times(s),u,1);if(t==null)if(c<3&&Le(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 le(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?(k=!1,f=b):f=t,h.precision=f+=w,n=q(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=q(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=qe(h,f+2,b).times(i+""),g=le(new h(r+"."+n.slice(1)),f-w).plus(c),h.precision=b,t==null?T(g,b,y,k=!0):g;for(l=g,u=s=g=E(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(E(s,new h(o),f,1)),q(c.d).slice(0,f)===q(u.d).slice(0,f))if(u=u.times(2),i!==0&&(u=u.plus(qe(h,f+2,b).times(i+""))),u=E(u,new h(d),f,1),t==null)if(Le(u.d,f-w,y,a))h.precision=f+=w,c=s=g=E(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,k=!0);else return h.precision=b,u;u=c,o+=2}}function nn(e){return String(e.s*e.s/0)}function bt(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 ir(e,t){var n,r,o,i,s,a,u,c,f;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Qt.test(t))return bt(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(er.test(t))n=16,t=t.toLowerCase();else if($n.test(t))n=2;else if(tr.test(t))n=8;else throw Error(fe+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=en(r,new r(n),i,i*2)),c=Ve(t,n,ee),f=c.length-1,i=f;c[i]===0;--i)c.pop();return i<0?new r(e.s*0):(e.e=Ge(c,f),e.d=c,k=!1,s&&(e=E(e,o,a*4)),u&&(e=e.times(Math.abs(u)<54?U(2,u):ze.pow(2,u))),k=!0,e)}function sr(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:Te(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/je(5,n)),t=Te(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 Te(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=E(a.times(u),new e(t++*t++),f,1),a=o?r.plus(s):r.minus(s),r=E(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 je(e,t){for(var n=e;--t;)n*=e;return n}function rn(e,t){var n,r=t.s<0,o=$(e,e.precision,1),i=o.times(.5);if(t=t.abs(),t.lte(i))return se=r?4:1,t;if(n=t.divToInt(o),n.isZero())se=r?3:2;else{if(t=t.minus(n.times(o)),t.lte(i))return se=Gt(n)?r?2:3:r?4:1,t;se=Gt(n)?r?1:4:r?3:2}return t.minus(o).abs()}function yt(e,t,n,r){var o,i,s,a,u,c,f,l,p,d=e.constructor,w=n!==void 0;if(w?(X(n,1,pe),r===void 0?r=d.rounding:X(r,0,8)):(n=d.precision,r=d.rounding),!e.isFinite())f=nn(e);else{for(f=ne(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=Ve(ne(p),10,o),p.e=p.d.length),l=Ve(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=E(e,p,n,r,0,o),l=e.d,i=e.e,c=Yt),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+=dt.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=Ve(f,o,t),u=l.length;!l[u-1];--u);for(s=1,f="1.";s<u;s++)f+=dt.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 jt(e,t){if(e.length>t)return e.length=t,!0}function ar(e){return new this(e).abs()}function cr(e){return new this(e).acos()}function ur(e){return new this(e).acosh()}function lr(e,t){return new this(e).plus(t)}function fr(e){return new this(e).asin()}function pr(e){return new this(e).asinh()}function dr(e){return new this(e).atan()}function mr(e){return new this(e).atanh()}function hr(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=$(this,i,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?$(this,r,o):new this(0),n.s=e.s):!e.d||t.isZero()?(n=$(this,i,1).times(.5),n.s=e.s):t.s<0?(this.precision=i,this.rounding=1,n=this.atan(E(e,t,i,1)),t=$(this,i,1),this.precision=r,this.rounding=o,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(E(e,t,i,1)),n}function gr(e){return new this(e).cbrt()}function br(e){return T(e=new this(e),e.e+1,2)}function yr(e,t,n){return new this(e).clamp(t,n)}function wr(e){if(!e||typeof e!="object")throw Error(He+"Object expected");var t,n,r,o=e.defaults===!0,i=["precision",1,pe,"rounding",0,8,"toExpNeg",-xe,0,"toExpPos",0,xe,"maxE",0,xe,"minE",-xe,0,"modulo",0,9];for(t=0;t<i.length;t+=3)if(n=i[t],o&&(this[n]=mt[n]),(r=e[n])!==void 0)if(z(r)===r&&r>=i[t+1]&&r<=i[t+2])this[n]=r;else throw Error(fe+n+": "+r);if(n="crypto",o&&(this[n]=mt[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(Jt);else this[n]=!1;else throw Error(fe+n+": "+r);return this}function xr(e){return new this(e).cos()}function Tr(e){return new this(e).cosh()}function on(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,zt(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 bt(c,i.toString())}else if(u!=="string")throw Error(fe+i);return(a=i.charCodeAt(0))===45?(i=i.slice(1),c.s=-1):(a===43&&(i=i.slice(1)),c.s=1),Qt.test(i)?bt(c,i):ir(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=wr,o.clone=on,o.isDecimal=zt,o.abs=ar,o.acos=cr,o.acosh=ur,o.add=lr,o.asin=fr,o.asinh=pr,o.atan=dr,o.atanh=mr,o.atan2=hr,o.cbrt=gr,o.ceil=br,o.clamp=yr,o.cos=xr,o.cosh=Tr,o.div=Pr,o.exp=Ar,o.floor=kr,o.hypot=Br,o.ln=Sr,o.log=Lr,o.log10=Cr,o.log2=Ir,o.max=Nr,o.min=Er,o.mod=Rr,o.mul=_r,o.pow=Dr,o.random=Mr,o.round=Kr,o.sign=Or,o.sin=vr,o.sinh=Fr,o.sqrt=Vr,o.sub=Ur,o.sum=Wr,o.tan=qr,o.tanh=Hr,o.trunc=Gr,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 Pr(e,t){return new this(e).div(t)}function Ar(e){return new this(e).exp()}function kr(e){return T(e=new this(e),e.e+1,3)}function Br(){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 zt(e){return e instanceof ze||e&&e.toStringTag===Xt||!1}function Sr(e){return new this(e).ln()}function Lr(e,t){return new this(e).log(t)}function Ir(e){return new this(e).log(2)}function Cr(e){return new this(e).log(10)}function Nr(){return tn(this,arguments,"lt")}function Er(){return tn(this,arguments,"gt")}function Rr(e,t){return new this(e).mod(t)}function _r(e,t){return new this(e).mul(t)}function Dr(e,t){return new this(e).pow(t)}function Mr(e){var t,n,r,o,i=0,s=new this(1),a=[];if(e===void 0?e=this.precision:X(e,1,pe),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(Jt);else for(;i<r;)a[i++]=Math.random()*1e7|0;for(r=a[--i],e%=P,r&&e&&(o=U(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 Kr(e){return T(e=new this(e),e.e+1,this.rounding)}function Or(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function vr(e){return new this(e).sin()}function Fr(e){return new this(e).sinh()}function Vr(e){return new this(e).sqrt()}function Ur(e,t){return new this(e).sub(t)}function Wr(){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 qr(e){return new this(e).tan()}function Hr(e){return new this(e).tanh()}function Gr(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 ze=m.constructor=on(mt);Ue=new ze(Ue);We=new ze(We);var Ye=require("@solana/web3.js");var sn=require("@solana/spl-token"),C=require("@solana/web3.js");function wt({pubkey:e,isSigner:t=!1,isWritable:n=!0}){return{pubkey:e,isWritable:n,isSigner:t}}var yo=[wt({pubkey:sn.TOKEN_PROGRAM_ID,isWritable:!1}),wt({pubkey:C.SystemProgram.programId,isWritable:!1}),wt({pubkey:C.SYSVAR_RENT_PUBKEY,isWritable:!1})];function an({publicKey:e,transformSol:t}){let n=cn(e.toString());if(n instanceof C.PublicKey)return t&&n.equals(Ie)?be:n;if(t&&n.toString()===Ie.toBase58())return be;if(typeof n=="string"){if(n===C.PublicKey.default.toBase58())return C.PublicKey.default;try{return new C.PublicKey(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function cn(e){try{return new C.PublicKey(e)}catch{return e}}var wo=new C.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),xo=new C.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),To=new C.PublicKey("SysvarRent111111111111111111111111111111111"),Po=new C.PublicKey("SysvarC1ock11111111111111111111111111111111"),Ao=new C.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),ko=new C.PublicKey("Sysvar1nstructions1111111111111111111111111"),Bo=C.SystemProgram.programId,So=new C.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Lo=new C.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Io=new C.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Co=new C.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),No=new C.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Eo=new C.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Ro=new C.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),_o=new C.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Do=new C.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Mo=new C.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Ko=new C.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),be=new C.PublicKey("So11111111111111111111111111111111111111112"),Ie=C.PublicKey.default;var un=require("@solana/web3.js"),xt=require("@solana/spl-token"),ln={chainId:101,address:un.PublicKey.default.toBase58(),programId:xt.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},ae={chainId:101,address:"So11111111111111111111111111111111111111112",programId:xt.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}};var Tt=class{constructor({mint:t,decimals:n,symbol:r,name:o,skipMint:i=!1,isToken2022:s=!1}){if(t===Ie.toBase58()||t instanceof Ye.PublicKey&&Ie.equals(t)){this.decimals=ae.decimals,this.symbol=ae.symbol,this.name=ae.name,this.mint=new Ye.PublicKey(ae.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?Ye.PublicKey.default:an({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},Pe=Tt;Pe.WSOL=new Tt(ce(V({},ae),{mint:ae.address}));var Ne=G(require("big.js")),pn=G(require("bn.js")),dn=G(require("decimal.js-light"));var fn=G(require("toformat")),jr=fn.default,Ce=jr;var Ze=j("module/fraction"),Pt=Ce(Ne.default),Ee=Ce(dn.default),zr={[0]:Ee.ROUND_DOWN,[1]:Ee.ROUND_HALF_UP,[2]:Ee.ROUND_UP},Yr={[0]:Ne.default.roundDown,[1]:Ne.default.roundHalfUp,[2]:Ne.default.roundUp},_=class{constructor(t,n=new pn.default(1)){this.numerator=re(t),this.denominator=re(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new _(this.denominator,this.numerator)}add(t){let n=t instanceof _?t:new _(re(t));return this.denominator.eq(n.denominator)?new _(this.numerator.add(n.numerator),this.denominator):new _(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(t){let n=t instanceof _?t:new _(re(t));return this.denominator.eq(n.denominator)?new _(this.numerator.sub(n.numerator),this.denominator):new _(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(t){let n=t instanceof _?t:new _(re(t));return new _(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(t){let n=t instanceof _?t:new _(re(t));return new _(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(t,n={groupSeparator:""},r=1){Number.isInteger(t)||Ze.logWithError(`${t} is not an integer.`),t<=0&&Ze.logWithError(`${t} is not positive.`),Ee.set({precision:t+1,rounding:zr[r]});let o=new Ee(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)||Ze.logWithError(`${t} is not an integer.`),t<0&&Ze.logWithError(`${t} is negative.`),Pt.DP=t,Pt.RM=Yr[r]||1,new Pt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,n)}isZero(){return this.numerator.isZero()}};var ti=j("Raydium_price");var At=class{constructor({decimals:t,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=t,this.symbol=n,this.name=r}equals(t){return this===t}},Je=At;Je.SOL=new At(ln);var mn=G(require("bn.js"));var ci=new _(new mn.default(100));var Jr=new J.default(0),Li=new J.default(1),Ii=new J.default(2),Ci=new J.default(3),Ni=new J.default(5),Xr=new J.default(10),Ei=new J.default(100),Ri=new J.default(1e3),_i=new J.default(1e4),yn=9007199254740991;function re(e){let t=j("Raydium_parseBigNumberish");if(e instanceof J.default)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new J.default(e);t.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&t.logWithError(`BigNumberish number underflow: ${e}`),(e>=yn||e<=-yn)&&t.logWithError(`BigNumberish number overflow: ${e}`),new J.default(String(e))):typeof e=="bigint"?new J.default(e.toString()):(t.error(`invalid BigNumberish value: ${e}`),new J.default(0))}var Hi=j("Raydium_amount"),Gi=Ce(wn.default);var N=require("@solana/web3.js"),Ln=G(require("axios"));var W={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"};var Y=require("@solana/web3.js"),Tn=require("@solana/spl-token");var xn=j("Raydium_txUtil"),Pn=1644;function Xe(e){let t=[],n=[];return e.microLamports&&(t.push(Y.ComputeBudgetProgram.setComputeUnitPrice({microLamports:e.microLamports})),n.push(W.SetComputeUnitPrice)),e.units&&(t.push(Y.ComputeBudgetProgram.setComputeUnitLimit({units:e.units})),n.push(W.SetComputeUnitLimit)),{instructions:t,instructionTypes:n}}async function Ae(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 to(e,t){e.length<1&&xn.logWithError(`no instructions provided: ${e.toString()}`),t.length<1&&xn.logWithError(`no signers provided:, ${t.toString()}`);let n=new Y.Transaction;n.recentBlockhash="11111111111111111111111111111111",n.feePayer=t[0],n.add(...e);try{return Buffer.from(n.serialize({verifySignatures:!1})).toString("base64").length<Pn}catch{return!1}}function An(e,t){let[n,r]=Y.PublicKey.findProgramAddressSync(e,t);return{publicKey:n,nonce:r}}function Re({instructions:e,payer:t,signers:n}){return to(e,[t,...n])}function _e({instructions:e,payer:t,lookupTableAddressAccount:n,recentBlockhash:r=Y.Keypair.generate().publicKey.toString()}){let i=new Y.TransactionMessage({payerKey:t,recentBlockhash:r,instructions:e}).compileToV0Message(Object.values(n!=null?n:{}));try{return Buffer.from(new Y.VersionedTransaction(i).serialize()).toString("base64").length<Pn}catch{return!1}}var no=e=>Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e.buffer,e.byteOffset,e.byteLength):Buffer.from(e);function ye(e){let t=[];return e.forEach(n=>{n instanceof Y.Transaction&&(n.recentBlockhash||(n.recentBlockhash=Tn.TOKEN_PROGRAM_ID.toBase58()),n.feePayer||(n.feePayer=Y.Keypair.generate().publicKey));let r=n.serialize({requireAllSignatures:!1,verifySignatures:!1});n instanceof Y.VersionedTransaction&&(r=no(r));let o=r.toString("base64");t.push(o)}),console.log("simulate tx string:",t),t}var de=require("@solana/web3.js");var kn=require("@solana/web3.js"),Bn=require("@solana/spl-token");var kt=j("Raydium_accountInfo_util");async function Sn(e,t,n){let{batchRequest:r,commitment:o="confirmed"}=V({batchRequest:!1},n),i=Bt(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=Bt(a,10);s=(await(await Promise.all(u.map(async f=>await e._rpcBatchRequest(f)))).flat()).map(f=>(f.error&&kt.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"&&kt.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(p[0],"base64"),executable:d,lamports:w,owner:new kn.PublicKey(g),rentEpoch:x}}return null})))}else try{s=await Promise.all(i.map(a=>e.getMultipleAccountsInfo(a,o)))}catch(a){a instanceof Error&&kt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${a.message}`)}return s.flat()}async function St({connection:e,address:t}){let n=await Sn(e,[...new Set(t.map(o=>o.toString()))].map(o=>new de.PublicKey(o))),r={};for(let o=0;o<t.length;o++){let i=n[o],s=t[o];if(!i)continue;let a=new de.AddressLookupTableAccount({key:s,state:de.AddressLookupTableAccount.deserialize(i.data)});r[s.toString()]=a,Qe[s.toString()]=a}return r}var Qe={"2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17":new de.AddressLookupTableAccount({key:new de.PublicKey("2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17"),state:de.AddressLookupTableAccount.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 $e=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 Ln.default.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}=Xe(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!==N.PublicKey.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 N.Transaction;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 Ae(this.connection);if(n.recentBlockhash=s,this.signers.length&&n.sign(...this.signers),ye([n]),(a=this.owner)!=null&&a.isKeyPair)return{txId:await(0,N.sendAndConfirmTransaction)(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 Ae(this.connection);if((g=this.owner)!=null&&g.isKeyPair){if(f){let x=[];for(let h of s){let y=await(0,N.sendAndConfirmTransaction)(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(0,N.sendAndConfirmTransaction)(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));ye(x);let h=await this.signAllTransactions(x);if(f){let y=0,b=[],B=async()=>{if(!h[y])return;let S=await this.connection.sendRawTransaction(h[y].serialize(),{skipPreflight:d});b.push({txId:S,status:"sent",signedTx:h[y]}),l==null||l([...b]),y++,this.connection.onSignature(S,D=>{let M=b.findIndex(v=>v.txId===S);M>-1&&(b[M].status=D.err?"error":"success"),l==null||l([...b]),D.err||B()},"processed"),this.connection.getSignatureStatus(S)};return await B(),{txIds:b.map(S=>S.txId),signedTxs:h}}else{let y=[];for(let b=0;b<h.length;b+=1){let B=await this.connection.sendRawTransaction(h[b].serialize(),{skipPreflight:d});y.push(B)}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=ge(p,["lookupTableCache","lookupTableAddress","forerunCreate"]),s=V(V({},this.cluster==="devnet"?{}:Qe),n),a=Array.from(new Set([...r,...this.lookupTableAddress])),u=[];for(let d of a)s[d]===void 0&&u.push(new N.PublicKey(d));let c=await St({connection:this.connection,address:u});for(let[d,w]of Object.entries(c))s[d]=w;let f=new N.TransactionMessage({payerKey:this.feePayer,recentBlockhash:o?N.PublicKey.default.toBase58():await Ae(this.connection),instructions:[...this.allInstructions]}).compileToV0Message(Object.values(s)),l=new N.VersionedTransaction(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),ye([l]),(x=this.owner)!=null&&x.isKeyPair){this.signers.find(B=>B.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),ye(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:B,blockhash:S}=await this.connection.getLatestBlockhash();await this.connection.confirmTransaction({blockhash:S,lastValidBlockHeight:B,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,B=>{let S=h.findIndex(D=>D.txId===b);S>-1&&(h[S].status=B.err?"error":"success"),l==null||l([...h]),B.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=ge(c,["computeBudgetConfig"]),o=n?Xe(n):{instructions:[],instructionTypes:[]},i=this.signers.reduce((f,l)=>ce(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 N.PublicKey(g));if(u.length<12&&Re({instructions:p,payer:this.feePayer,signers:w})||Re({instructions:l,payer:this.feePayer,signers:w}))u.push(f);else{if(u.length===0)throw Error("item ins too big");Re({instructions:n?[...o.instructions,...u]:[...u],payer:this.feePayer,signers:w})?s.push(new N.Transaction().add(...o.instructions,...u)):s.push(new N.Transaction().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);Re({instructions:n?[...o.instructions,...u]:[...u],payer:this.feePayer,signers:l.map(p=>p.publicKey)})?s.push(new N.Transaction().add(...o.instructions,...u)):s.push(new N.Transaction().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 Ae(this.connection);if(s.forEach(async(h,y)=>{h.recentBlockhash=g,a[y].length&&h.sign(...a[y])}),ye(s),(x=this.owner)!=null&&x.isKeyPair){if(l){let h=[];for(let y of s){let b=await(0,N.sendAndConfirmTransaction)(this.connection,y,this.signers.find(B=>B.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(0,N.sendAndConfirmTransaction)(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=[],B=async()=>{if(!h[y])return;let S=await this.connection.sendRawTransaction(h[y].serialize(),{skipPreflight:w});b.push({txId:S,status:"sent",signedTx:h[y]}),p==null||p([...b]),y++,this.connection.onSignature(S,D=>{let M=b.findIndex(v=>v.txId===S);M>-1&&(b[M].status=D.err?"error":"success"),p==null||p([...b]),D.err||B()},"processed"),this.connection.getSignatureStatus(S)};return await B(),{txIds:b.map(S=>S.txId),signedTxs:h}}else{let y=[];for(let b=0;b<h.length;b+=1){let B=await this.connection.sendRawTransaction(h[b].serialize(),{skipPreflight:w});y.push(B)}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=ge(x,["computeBudgetConfig","lookupTableCache","lookupTableAddress"]),s=V(V({},this.cluster==="devnet"?{}:Qe),r),a=Array.from(new Set([...this.lookupTableAddress,...o])),u=[];for(let h of a)s[h]===void 0&&u.push(new N.PublicKey(h));let c=await St({connection:this.connection,address:u});for(let[h,y]of Object.entries(c))s[h]=y;let f=n?Xe(n):{instructions:[],instructionTypes:[]},l=await Ae(this.connection),p=this.signers.reduce((h,y)=>ce(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&&_e({instructions:b,payer:this.feePayer,lookupTableAddressAccount:s})||_e({instructions:y,payer:this.feePayer,lookupTableAddressAccount:s}))g.push(h);else{if(g.length===0)throw Error("item ins too big");let B={};for(let S of[...new Set(a)])s[S]!==void 0&&(B[S]=s[S]);if(n&&_e({instructions:[...f.instructions,...g],payer:this.feePayer,lookupTableAddressAccount:s,recentBlockhash:l})){let S=new N.TransactionMessage({payerKey:this.feePayer,recentBlockhash:l,instructions:[...f.instructions,...g]}).compileToV0Message(Object.values(s));d.push(new N.VersionedTransaction(S))}else{let S=new N.TransactionMessage({payerKey:this.feePayer,recentBlockhash:l,instructions:[...g]}).compileToV0Message(Object.values(s));d.push(new N.VersionedTransaction(S))}w.push(Array.from(new Set(g.map(S=>S.keys.filter(D=>D.isSigner).map(D=>D.pubkey.toString())).flat())).map(S=>p[S]).filter(S=>S!==void 0)),g=[h]}}),g.length>0){let y=[...new Set(g.map(b=>b.keys.filter(B=>B.isSigner).map(B=>B.pubkey.toString())).flat()).values()].map(b=>p[b]).filter(b=>b!==void 0);if(n&&_e({instructions:[...f.instructions,...g],payer:this.feePayer,lookupTableAddressAccount:s,recentBlockhash:l})){let b=new N.TransactionMessage({payerKey:this.feePayer,recentBlockhash:l,instructions:[...f.instructions,...g]}).compileToV0Message(Object.values(s));d.push(new N.VersionedTransaction(b))}else{let b=new N.TransactionMessage({payerKey:this.feePayer,recentBlockhash:l,instructions:[...g]}).compileToV0Message(Object.values(s));d.push(new N.VersionedTransaction(b))}w.push(y)}return{builder:this,transactions:d,buildProps:t,signers:w,instructionTypes:this.instructionTypes,execute:async h=>{var D;let{sequentially:y,onTxUpdate:b,recentBlockHash:B,skipPreflight:S=!0}=h||{};if(d.map(async(M,v)=>{w[v].length&&M.sign(w[v]),B&&(M.message.recentBlockhash=B)}),ye(d),(D=this.owner)!=null&&D.isKeyPair){let{lastValidBlockHeight:M,blockhash:v}=await this.connection.getLatestBlockhash();if(d.forEach((K,Z)=>{w[Z].find(F=>F.publicKey.equals(this.owner.publicKey))||K.sign([this.owner.signer])}),y){let K=[];for(let Z of d){let F=await this.connection.sendTransaction(Z,{skipPreflight:S}),{lastValidBlockHeight:oe,blockhash:ie}=await this.connection.getLatestBlockhash();await this.connection.confirmTransaction({blockhash:ie,lastValidBlockHeight:oe,signature:F},"confirmed"),K.push(F)}return{txIds:K,signedTxs:d}}return{txIds:await Promise.all(d.map(async K=>{let Z=await this.connection.sendTransaction(K,{skipPreflight:S});return await this.connection.confirmTransaction({blockhash:v,lastValidBlockHeight:M,signature:Z},"confirmed"),Z})),signedTxs:d}}if(this.signAllTransactions){let M=await this.signAllTransactions(d);if(y){let v=0,K=[],Z=async()=>{if(!M[v])return;let F=await this.connection.sendTransaction(M[v],{skipPreflight:S});K.push({txId:F,status:"sent",signedTx:M[v]}),b==null||b([...K]),v++,this.connection.onSignature(F,oe=>{let ie=K.findIndex(ke=>ke.txId===F);ie>-1&&(K[ie].status=oe.err?"error":"success"),b==null||b([...K]),oe.err||Z()},"processed"),this.connection.getSignatureStatus(F)};return Z(),{txIds:[],signedTxs:M}}else{let v=[];for(let K=0;K<M.length;K+=1){let Z=await this.connection.sendTransaction(M[K],{skipPreflight:S});v.push(Z)}return{txIds:v,signedTxs:M}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}};function Bt(e,t=1,n=[]){let r=[...e];if(t<=0)return n;for(;r.length;)n.push(r.splice(0,t));return n}var I=require("@solana/web3.js"),_s=new I.PublicKey("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),Ds=new I.PublicKey("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),Ms=new I.PublicKey("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Ks=new I.PublicKey("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),Os=new I.PublicKey("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),vs=new I.PublicKey("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Fs=new I.PublicKey("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Vs=new I.PublicKey("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Us=new I.PublicKey("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),Ws=new I.PublicKey("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),qs=new I.PublicKey("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Hs=new I.PublicKey("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Gs=new I.PublicKey("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),js=new I.PublicKey("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),zs=new I.PublicKey("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),Ys=new I.PublicKey("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),Zs=new I.PublicKey("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Js=new I.PublicKey("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),ro=new I.PublicKey("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),oo=new I.PublicKey("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),io=new I.PublicKey("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2");var Xs={SERUM_MARKET:I.PublicKey.default,OPENBOOK_MARKET:new I.PublicKey("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:I.PublicKey.default,FarmV3:new I.PublicKey("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new I.PublicKey("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new I.PublicKey("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new I.PublicKey("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new I.PublicKey("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new I.PublicKey("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),Router:new I.PublicKey("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:ro,CREATE_CPMM_POOL_AUTH:oo,CREATE_CPMM_POOL_FEE_ACC:io,FEE_DESTINATION_ID:new I.PublicKey("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR")};var In=require("@solana/web3.js");var Cn=require("@solana/spl-token");function et(e,t,n){return An([e.toBuffer(),(n!=null?n:Cn.TOKEN_PROGRAM_ID).toBuffer(),t.toBuffer()],new In.PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}var so=G(require("bn.js"));var Lt=(...e)=>e.map(t=>{try{return typeof t=="object"?JSON.stringify(t):t}catch{return t}}).join(", "),De=class{constructor({scope:t,moduleName:n}){this.disabled=!1;this.scope=t,this.logger=j(n)}createTxBuilder(t){return this.scope.checkOwner(),new $e({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(Lt(t))}logInfo(...t){this.logger.info(Lt(t))}logAndCreateError(...t){let n=Lt(t);throw new Error(n)}checkDisabled(){(this.disabled||!this.scope)&&this.logAndCreateError("module not working")}};var Q=require("@solana/spl-token"),ct=require("@solana/web3.js"),Wn=G(require("bn.js"));var Oe=require("@solana/web3.js"),Fn=require("@solana/spl-token"),Vn=G(require("bn.js"));var En=require("@solana/web3.js"),tt=G(require("bn.js"));var A=require("@solana/buffer-layout"),It=A.Layout,Nn=A.Structure;var Ct=A.UInt;var Nt=A.blob;var Et=class extends It{constructor(n,r,o){super(n,o);this.blob=Nt(n),this.signed=r}decode(n,r=0){let o=new tt.default(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 tt.default(n)),this.signed&&(n=n.toTwos(this.span*8)),this.blob.encode(n.toArrayLike(Buffer,"le",this.span),r,o)}};function Rn(e){return new Ct(1,e)}function nt(e){return new Ct(4,e)}function rt(e){return new Et(8,!1,e)}var Rt=class extends It{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 Me(e){return new Rt(Nt(32),t=>new En.PublicKey(t),t=>t.toBuffer(),e)}var _t=class extends Nn{decode(t,n){return super.decode(t,n)}};function _n(e,t,n){return new _t(e,t,n)}var Ke=_n([Me("mint"),Me("owner"),rt("amount"),nt("delegateOption"),Me("delegate"),Rn("state"),nt("isNativeOption"),rt("isNative"),rt("delegatedAmount"),nt("closeAuthorityOption"),Me("closeAuthority")]);function ao(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function Dt(e,...t){if(!ao(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 Mt(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 Dn(e,t){Dt(e);let n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}var it=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),te=(e,t)=>e<<32-t|e>>>t;var Fa=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function co(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Kt(e){return typeof e=="string"&&(e=co(e)),Dt(e),e}var ot=class{clone(){return this._cloneInto()}},Va={}.toString;function Mn(e){let t=r=>e().update(Kt(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function uo(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 Kn=(e,t,n)=>e&t^~e&n,On=(e,t,n)=>e&t^e&n^t&n,st=class extends ot{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=it(this.buffer)}update(t){Mt(this);let{view:n,buffer:r,blockLen:o}=this;t=Kt(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=it(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){Mt(this),Dn(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;uo(r,o-8,BigInt(this.length*8),i),this.process(r,0);let a=it(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 lo=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]),me=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),he=new Uint32Array(64),Ot=class extends st{constructor(){super(64,32,8,!1),this.A=me[0]|0,this.B=me[1]|0,this.C=me[2]|0,this.D=me[3]|0,this.E=me[4]|0,this.F=me[5]|0,this.G=me[6]|0,this.H=me[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)he[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){let p=he[l-15],d=he[l-2],w=te(p,7)^te(p,18)^p>>>3,g=te(d,17)^te(d,19)^d>>>10;he[l]=g+he[l-7]+w+he[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=te(a,6)^te(a,11)^te(a,25),d=f+p+Kn(a,u,c)+lo[l]+he[l]|0,g=(te(r,2)^te(r,13)^te(r,22))+On(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(){he.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var vn=Mn(()=>new Ot);var ec=j("Raydium_Util");function Un({owner:e,solAccountResp:t,tokenAccountResp:n}){let r=[],o=[];for(let{pubkey:i,account:s}of n.value){let a=Ke.decode(s.data),{mint:u,amount:c}=a;r.push({publicKey:i,mint:u,amount:c,isAssociated:et(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:Oe.PublicKey.default,amount:new Vn.default(t.lamports),isNative:!0,programId:t.owner}),{tokenAccounts:r,tokenAccountRawInfos:o}}function at({fromPublicKey:e,programId:t=Fn.TOKEN_PROGRAM_ID}){let n=Oe.Keypair.generate().publicKey.toBase58().slice(0,32);return{publicKey:fo(e,n,t),seed:n}}function fo(e,t,n){let r=Buffer.concat([e.toBuffer(),Buffer.from(t),n.toBuffer()]),o=vn(r);return new Oe.PublicKey(o)}function vt(e){let{mint:t,tokenAccount:n,owner:r,programId:o=Q.TOKEN_PROGRAM_ID}=e;return(0,Q.createInitializeAccountInstruction)(n,t,r,o)}function ve(e){let{tokenAccount:t,payer:n,multiSigners:r=[],owner:o,programId:i=Q.TOKEN_PROGRAM_ID}=e;return(0,Q.createCloseAccountInstruction)(t,n,o,r,i)}async function Ft(e){let{connection:t,amount:n,commitment:r,payer:o,owner:i,skipCloseAccount:s}=e,a=await t.getMinimumBalanceForRentExemption(Ke.span,r),u=re(n).add(new Wn.default(a)),c=at({fromPublicKey:o,programId:Q.TOKEN_PROGRAM_ID});return{addresses:{newAccount:c.publicKey},signers:[],instructions:[ct.SystemProgram.createAccountWithSeed({fromPubkey:o,basePubkey:o,seed:c.seed,newAccountPubkey:c.publicKey,lamports:u.toNumber(),space:Ke.span,programId:Q.TOKEN_PROGRAM_ID}),vt({mint:new ct.PublicKey(ae.address),tokenAccount:c.publicKey,owner:i,programId:Q.TOKEN_PROGRAM_ID})],instructionTypes:[W.CreateAccount,W.InitAccount],endInstructionTypes:s?[]:[W.CloseAccount],endInstructions:s?[]:[ve({tokenAccount:c.publicKey,payer:o,owner:i})]}}function qn({source:e,destination:t,owner:n,amount:r,multiSigners:o=[],tokenProgram:i=Q.TOKEN_PROGRAM_ID}){return(0,Q.createTransferInstruction)(e,t,n,BigInt(String(r)),o,i)}var ut=class extends De{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 et(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:O.TOKEN_PROGRAM_ID},o.commitment),this.scope.connection.getTokenAccountsByOwner(this.scope.ownerPubKey,{programId:O.TOKEN_2022_PROGRAM_ID},o.commitment)]),{tokenAccounts:u,tokenAccountRawInfos:c}=Un({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=O.TOKEN_PROGRAM_ID,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 we.PublicKey(n.tokenProgram||O.TOKEN_PROGRAM_ID),l=this.getAssociatedTokenAccount(r,new we.PublicKey(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=(0,O.createAssociatedTokenAccountInstruction)(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(W.CreateATA);else if(!(h.owner.equals(f)&&O.AccountLayout.decode(h.data).mint.equals(r)&&O.AccountLayout.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(W.CreateATA);if(r.equals(be)&&o.amount){let h=await Ft({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(qn({source:h.addresses.newAccount,destination:l,owner:this.scope.ownerPubKey,amount:o.amount,tokenProgram:O.TOKEN_PROGRAM_ID})),d.instructionTypes.push(W.TransferAmount))}return u||(d.endInstructions.push(ve({owner:s,payer:o.payer||s,tokenAccount:l,programId:f})),d.endInstructionTypes.push(W.CloseAccount)),{account:l,instructionParams:d}}else{let x=at({fromPublicKey:s,programId:f}),h=await this.scope.connection.getMinimumBalanceForRentExemption(O.AccountLayout.span),y=we.SystemProgram.createAccountWithSeed({fromPubkey:s,basePubkey:s,seed:x.seed,newAccountPubkey:x.publicKey,lamports:h,space:O.AccountLayout.span,programId:f});return d.instructions.push(y,vt({mint:r,tokenAccount:x.publicKey,owner:this.scope.ownerPubKey,programId:f})),d.instructionTypes.push(W.CreateAccount),d.instructionTypes.push(W.InitAccount),u||(d.endInstructions.push(ve({owner:s,payer:o.payer||s,tokenAccount:x.publicKey,programId:f})),d.endInstructionTypes.push(W.CloseAccount)),{account:x.publicKey,instructionParams:d}}}async checkOrCreateAta({mint:n,programId:r=O.TOKEN_PROGRAM_ID,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(0,O.createAssociatedTokenAccountInstruction)(s,c,s,n,r);a.instructions=[f],a.instructionTypes=[W.CreateATA],i=c}return o&&be.toBase58()===n.toBase58()&&(a.endInstructions=[ve({owner:s,payer:s,tokenAccount:i,programId:r})],a.endInstructionTypes=[W.CloseAccount]),{pubKey:i,newInstructions:a}}async handleTokenAccount(n){let{side:r,amount:o,mint:i,programId:s=O.TOKEN_PROGRAM_ID,tokenAccount:a,payer:u=this.scope.ownerPubKey,bypassAssociatedCheck:c,skipCloseAccount:f,checkCreateATAOwner:l}=n,p=this.getAssociatedTokenAccount(i,s);if(new we.PublicKey(be).equals(i)){let d=await Ft({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=(0,O.createAssociatedTokenAccountInstruction)(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(O.TOKEN_PROGRAM_ID)&&O.AccountLayout.decode(g.data).mint.equals(i)&&O.AccountLayout.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:[W.CreateATA]}}return{tokenAccount:a}}async processTokenAccount(n){let{mint:r,programId:o=O.TOKEN_PROGRAM_ID,amount:i,useSOLBalance:s,handleTokenAccount:a}=n,u,c=this.createTxBuilder();if(r.equals(new we.PublicKey(be))&&s){let f=await this.handleTokenAccount({side:"in",amount:i||0,mint:r,bypassAssociatedCheck:!0,programId:o}),{tokenAccount:p}=f,d=ge(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=ge(l,["tokenAccount"]);u=p,c.addInstruction(d)}return V({tokenAccount:u},c.AllTxData)}};0&&(module.exports={});
|
|
1
|
+
var Hn=Object.create;var Be=Object.defineProperty,Gn=Object.defineProperties,jn=Object.getOwnPropertyDescriptor,zn=Object.getOwnPropertyDescriptors,Yn=Object.getOwnPropertyNames,Fe=Object.getOwnPropertySymbols,Zn=Object.getPrototypeOf,lt=Object.prototype.hasOwnProperty,Ut=Object.prototype.propertyIsEnumerable;var Vt=(e,t,n)=>t in e?Be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,V=(e,t)=>{for(var n in t||(t={}))lt.call(t,n)&&Vt(e,n,t[n]);if(Fe)for(var n of Fe(t))Ut.call(t,n)&&Vt(e,n,t[n]);return e},ce=(e,t)=>Gn(e,zn(t));var ge=(e,t)=>{var n={};for(var r in e)lt.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Fe)for(var r of Fe(e))t.indexOf(r)<0&&Ut.call(e,r)&&(n[r]=e[r]);return n};var Jn=(e,t)=>{for(var n in t)Be(e,n,{get:t[n],enumerable:!0})},Wt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Yn(t))!lt.call(e,o)&&o!==n&&Be(e,o,{get:()=>t[o],enumerable:!(r=jn(t,o))||r.enumerable});return e};var G=(e,t,n)=>(n=e!=null?Hn(Zn(e)):{},Wt(t||!e||!e.__esModule?Be(n,"default",{value:e,enumerable:!0}):n,e)),Xn=e=>Wt(Be({},"__esModule",{value:!0}),e);var po={};Jn(po,{default:()=>ut});module.exports=Xn(po);var O=require("@solana/spl-token"),we=require("@solana/web3.js");var Se=require("lodash"),pt=G(require("dayjs")),Ht=G(require("dayjs/plugin/utc"));pt.default.extend(Ht.default);var ft=class{constructor(t){this.logLevel=t.logLevel!==void 0?t.logLevel:0,this.name=t.name}set level(t){this.logLevel=t}get time(){return(0,pt.default)().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}},qt={},Qn={};function j(e){let t=(0,Se.get)(qt,e);if(!t){let n=(0,Se.get)(Qn,e);t=new ft({name:e,logLevel:n}),(0,Se.set)(qt,e,t)}return t}var $r=require("@solana/web3.js"),eo=G(require("bn.js"));var wn=G(require("big.js")),Qr=G(require("bn.js"));var J=G(require("bn.js"));var xe=9e15,pe=1e9,dt="0123456789abcdef",Ue="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",We="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",mt={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-xe,maxE:xe,crypto:!1},Yt,se,B=!0,He="[DecimalError] ",fe=He+"Invalid argument: ",Zt=He+"Precision limit exceeded",Jt=He+"crypto unavailable",Xt="[object Decimal]",z=Math.floor,U=Math.pow,$n=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,er=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,tr=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Qt=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,ee=1e7,P=7,nr=9007199254740991,rr=Ue.length-1,ht=We.length-1,m={toStringTag:Xt};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(fe+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=or(r,rn(r,n)),r.precision=e,r.rounding=t,T(se==2||se==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(B=!1,i=f.s*U(f.s*f,1/3),!i||Math.abs(i)==1/0?(n=q(f.d),e=f.e,(i=(e-n.length+1)%3)&&(n+=i==1||i==-2?"0":"00"),i=U(n,1/3),e=z((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=E(c.plus(f).times(a),c.plus(u),s+2,1),q(a.d).slice(0,s)===(n=q(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 B=!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-z(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 E(this,new this.constructor(e))};m.dividedToIntegerBy=m.divToInt=function(e){var t=this,n=t.constructor;return T(E(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/je(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),i=Te(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=Te(i,2,o,o,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,o=o.times(1/je(5,e)),o=Te(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,E(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()?$(n,o,i):new n(0):new n(NaN):t.isZero()?$(n,o+4,i).times(.5):(n.precision=o+6,n.rounding=1,t=t.asin(),e=$(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,B=!1,n=n.times(n).minus(1).sqrt().plus(n),B=!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,B=!1,n=n.times(n).plus(1).sqrt().plus(n),B=!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=E(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=$(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<=ht)return s=$(f,l+4,p).times(.25),s.s=c.s,s}else{if(!c.s)return new f(NaN);if(l+4<=ht)return s=$(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(B=!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)),B=!0,T(s,f.precision=l,f.rounding=p,!0)};m.isFinite=function(){return!!this.d};m.isInteger=m.isInt=function(){return!!this.d&&z(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(B=!1,a=l+d,s=le(c,a),r=t?qe(f,a+10):le(e,a),u=E(s,r,a,1),Le(u.d,o=l,p))do if(a+=10,s=le(c,a),r=t?qe(f,a+10):le(e,a),u=E(s,r,a,1),!i){+q(u.d).slice(o+1,o+15)+1==1e14&&(u=T(u,l+1,0));break}while(Le(u.d,o+=10,p));return B=!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 B?T(e,a,u):e}if(n=z(e.e/P),f=z(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]=ee-1;--c[o],c[r]+=ee}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=Ge(c,n),B?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):(B=!1,r.modulo==9?(t=E(n,e.abs(),0,3,1),t.s*=e.s):t=E(n,e,0,r.modulo,1),t=t.times(e),B=!0,n.minus(t))};m.naturalExponential=m.exp=function(){return gt(this)};m.naturalLogarithm=m.ln=function(){return le(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)),B?T(e,a,u):e;if(i=z(l.e/P),r=z(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)/ee|0,c[o]%=ee;for(t&&(c.unshift(t),++r),s=c.length;c[--s]==0;)c.pop();return e.d=c,e.e=Ge(c,r),B?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(fe+e);return n.d?(t=$t(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=sr(r,rn(r,n)),r.precision=e,r.rounding=t,T(se>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(B=!1,c=Math.sqrt(+s),c==0||c==1/0?(t=q(a),(t.length+u)%2==0&&(t+="0"),c=Math.sqrt(t),u=z((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(E(s,i,n+2,1)).times(.5),q(i.d).slice(0,n)===(t=q(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 B=!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=E(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,T(se==2||se==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=z(f.e/P)+z(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%ee|0,t=a/ee|0;i[o]=(i[o]+t)%ee|0}for(;!i[--s];)i.pop();return t?++n:i.shift(),e.d=i,e.e=Ge(i,n),B?T(e,l.precision,l.rounding):e};m.toBinary=function(e,t){return yt(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:(X(e,0,pe),t===void 0?t=r.rounding:X(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=ne(r,!0):(X(e,0,pe),t===void 0?t=o.rounding:X(t,0,8),r=T(new o(r),e+1,t),n=ne(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=ne(o):(X(e,0,pe),t===void 0?t=i.rounding:X(t,0,8),r=T(new i(o),e+o.e+1,t),n=ne(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=$t(w)-d.e-1,s=i%P,t.d[0]=U(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(fe+a);e=a.gt(t)?i>0?t:c:a}for(B=!1,a=new g(q(w)),f=g.precision,g.precision=i=w.length*P*2;l=E(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=E(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=E(c,r,i,1).minus(d).abs().cmp(E(u,n,i,1).minus(d).abs())<1?[c,r]:[u,n],g.precision=f,B=!0,p};m.toHexadecimal=m.toHex=function(e,t){return yt(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:X(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]?(B=!1,n=E(n,e,0,t,1).times(e),B=!0,T(n)):(e.s=n.s,n=e),n};m.toNumber=function(){return+this};m.toOctal=function(e,t){return yt(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(U(+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=z(e.e/P),t>=e.d.length-1&&(n=c<0?-c:c)<=nr)return o=en(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=U(+a,c),t=n==0||!isFinite(n)?z(c*(Math.log("0."+q(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):(B=!1,u.rounding=a.s=1,n=Math.min(12,(t+"").length),o=gt(e.times(le(a,r+n)),r),o.d&&(o=T(o,r+5,1),Le(o.d,r,i)&&(t=r+10,o=T(gt(e.times(le(a,t+n)),t),t+5,1),+q(o.d).slice(r+1,r+15)+1==1e14&&(o=T(o,r+1,0)))),o.s=s,B=!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=ne(r,r.e<=o.toExpNeg||r.e>=o.toExpPos):(X(e,1,pe),t===void 0?t=o.rounding:X(t,0,8),r=T(new o(r),e,t),n=ne(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):(X(e,1,pe),t===void 0?t=r.rounding:X(t,0,8)),T(new r(n),e,t)};m.toString=function(){var e=this,t=e.constructor,n=ne(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=ne(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function q(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+=ue(n)),i+=r;s=e[t],r=s+"",n=P-r.length,n&&(i+=ue(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return i+s}function X(e,t,n){if(e!==~~e||e<t||e>n)throw Error(fe+e)}function Le(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=U(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)==U(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)==U(10,t-3)-1,s}function Ve(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]+=dt.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 or(e,t){var n,r,o;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),o=(1/je(4,n)).toString()):(n=16,o="2.3283064365386962890625e-10"),e.precision+=n,t=Te(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 E=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,k,S,D,M,v,K,Z,F,oe,ie=r.constructor,ke=r.s==o.s?1:-1,H=r.d,R=o.d;if(!H||!H[0]||!R||!R[0])return new ie(!r.s||!o.s||(H?R&&H[0]==R[0]:!R)?NaN:H&&H[0]==0||!R?ke*0:ke/0);for(u?(d=1,f=r.e-o.e):(u=ee,d=P,f=z(r.e/d)-z(o.e/d)),F=R.length,K=H.length,b=new ie(ke),y=b.d=[],l=0;R[l]==(H[l]||0);l++);if(R[l]>(H[l]||0)&&f--,i==null?(D=i=ie.precision,s=ie.rounding):a?D=i+(r.e-o.e)+1:D=i,D<0)y.push(1),w=!0;else{if(D=D/d+2|0,l=0,F==1){for(p=0,R=R[0],D++;(l<K||p)&&D--;l++)M=p*u+(H[l]||0),y[l]=M/R|0,p=M%R|0;w=p||l<K}else{for(p=u/(R[0]+1)|0,p>1&&(R=e(R,p,u),H=e(H,p,u),F=R.length,K=H.length),v=F,h=H.slice(0,F),k=h.length;k<F;)h[k++]=0;oe=R.slice(),oe.unshift(0),Z=R[0],R[1]>=u/2&&++Z;do p=0,c=t(R,h,F,k),c<0?(S=h[0],F!=k&&(S=S*u+(h[1]||0)),p=S/Z|0,p>1?(p>=u&&(p=u-1),g=e(R,p,u),x=g.length,k=h.length,c=t(g,h,x,k),c==1&&(p--,n(g,F<x?oe:R,x,u))):(p==0&&(c=p=1),g=R.slice()),x=g.length,x<k&&g.unshift(0),n(h,g,k,u),c==-1&&(k=h.length,c=t(R,h,F,k),c<1&&(p++,n(h,F<k?oe:R,k,u))),k=h.length):c===0&&(p++,h=[0]),y[l++]=p,c&&h[0]?h[k++]=H[v]||0:(h=[H[v]],k=1);while((v++<K||h[0]!==void 0)&&D--);w=h[0]!==void 0}y[0]||y.shift()}if(d==1)b.e=f,Yt=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/U(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/U(10,o-s-1)%10|0}if(r=r||t<0||l[p+1]!==void 0||(s<0?f:f%U(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/U(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]=U(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=U(10,P-i),l[p]=s>0?(f/U(10,o-s)%U(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]==ee&&(l[0]=1));break}else{if(l[p]+=a,l[p]!=ee)break;l[p--]=0,a=1}for(i=l.length;l[--i]===0;)l.pop()}return B&&(e.e>d.maxE?(e.d=null,e.e=NaN):e.e<d.minE&&(e.e=0,e.d=[0])),e}function ne(e,t,n){if(!e.isFinite())return nn(e);var r,o=e.e,i=q(e.d),s=i.length;return t?(n&&(r=n-s)>0?i=i.charAt(0)+"."+i.slice(1)+ue(r):s>1&&(i=i.charAt(0)+"."+i.slice(1)),i=i+(e.e<0?"e":"e+")+e.e):o<0?(i="0."+ue(-o-1)+i,n&&(r=n-s)>0&&(i+=ue(r))):o>=s?(i+=ue(o+1-s),n&&(r=n-o-1)>0&&(i=i+"."+ue(r))):((r=o+1)<s&&(i=i.slice(0,r)+"."+i.slice(r)),n&&(r=n-s)>0&&(o+1===s&&(i+="."),i+=ue(r))),i}function Ge(e,t){var n=e[0];for(t*=P;n>=10;n/=10)t++;return t}function qe(e,t,n){if(t>rr)throw B=!0,n&&(e.precision=n),Error(Zt);return T(new e(Ue),t,1,!0)}function $(e,t,n){if(t>ht)throw Error(Zt);return T(new e(We),t,n,!0)}function $t(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 ue(e){for(var t="";e--;)t+="0";return t}function en(e,t,n,r){var o,i=new e(1),s=Math.ceil(r/P+4);for(B=!1;;){if(n%2&&(i=i.times(t),jt(i.d,s)&&(o=!0)),n=z(n/2),n===0){n=i.d.length-1,o&&i.d[n]===0&&++i.d[n];break}t=t.times(t),jt(t.d,s)}return B=!0,i}function Gt(e){return e.d[e.d.length-1]&1}function tn(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 gt(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?(B=!1,u=w):u=t,a=new p(.03125);e.e>-2;)e=e.times(a),l+=5;for(r=Math.log(U(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(E(i,n,u,1)),q(a.d).slice(0,u)===q(s.d).slice(0,u)){for(o=l;o--;)s=T(s.times(s),u,1);if(t==null)if(c<3&&Le(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,B=!0);else return p.precision=w,s}s=a}}function le(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?(B=!1,f=h):f=t,b.precision=f+=w,n=q(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=q(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=qe(b,f+2,h).times(i+""),g=le(new b(r+"."+n.slice(1)),f-w).plus(c),b.precision=h,t==null?T(g,h,y,B=!0):g;for(l=g,u=s=g=E(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(E(s,new b(o),f,1)),q(c.d).slice(0,f)===q(u.d).slice(0,f))if(u=u.times(2),i!==0&&(u=u.plus(qe(b,f+2,h).times(i+""))),u=E(u,new b(d),f,1),t==null)if(Le(u.d,f-w,y,a))b.precision=f+=w,c=s=g=E(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,B=!0);else return b.precision=h,u;u=c,o+=2}}function nn(e){return String(e.s*e.s/0)}function bt(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),B&&(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 ir(e,t){var n,r,o,i,s,a,u,c,f;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Qt.test(t))return bt(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(er.test(t))n=16,t=t.toLowerCase();else if($n.test(t))n=2;else if(tr.test(t))n=8;else throw Error(fe+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=en(r,new r(n),i,i*2)),c=Ve(t,n,ee),f=c.length-1,i=f;c[i]===0;--i)c.pop();return i<0?new r(e.s*0):(e.e=Ge(c,f),e.d=c,B=!1,s&&(e=E(e,o,a*4)),u&&(e=e.times(Math.abs(u)<54?U(2,u):ze.pow(2,u))),B=!0,e)}function sr(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:Te(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/je(5,n)),t=Te(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 Te(e,t,n,r,o){var i,s,a,u,c=1,f=e.precision,l=Math.ceil(f/P);for(B=!1,u=n.times(n),a=new e(r);;){if(s=E(a.times(u),new e(t++*t++),f,1),a=o?r.plus(s):r.minus(s),r=E(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 B=!0,s.d.length=l+1,s}function je(e,t){for(var n=e;--t;)n*=e;return n}function rn(e,t){var n,r=t.s<0,o=$(e,e.precision,1),i=o.times(.5);if(t=t.abs(),t.lte(i))return se=r?4:1,t;if(n=t.divToInt(o),n.isZero())se=r?3:2;else{if(t=t.minus(n.times(o)),t.lte(i))return se=Gt(n)?r?2:3:r?4:1,t;se=Gt(n)?r?1:4:r?3:2}return t.minus(o).abs()}function yt(e,t,n,r){var o,i,s,a,u,c,f,l,p,d=e.constructor,w=n!==void 0;if(w?(X(n,1,pe),r===void 0?r=d.rounding:X(r,0,8)):(n=d.precision,r=d.rounding),!e.isFinite())f=nn(e);else{for(f=ne(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=Ve(ne(p),10,o),p.e=p.d.length),l=Ve(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=E(e,p,n,r,0,o),l=e.d,i=e.e,c=Yt),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+=dt.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=Ve(f,o,t),u=l.length;!l[u-1];--u);for(s=1,f="1.";s<u;s++)f+=dt.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 jt(e,t){if(e.length>t)return e.length=t,!0}function ar(e){return new this(e).abs()}function cr(e){return new this(e).acos()}function ur(e){return new this(e).acosh()}function lr(e,t){return new this(e).plus(t)}function fr(e){return new this(e).asin()}function pr(e){return new this(e).asinh()}function dr(e){return new this(e).atan()}function mr(e){return new this(e).atanh()}function hr(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=$(this,i,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?$(this,r,o):new this(0),n.s=e.s):!e.d||t.isZero()?(n=$(this,i,1).times(.5),n.s=e.s):t.s<0?(this.precision=i,this.rounding=1,n=this.atan(E(e,t,i,1)),t=$(this,i,1),this.precision=r,this.rounding=o,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(E(e,t,i,1)),n}function gr(e){return new this(e).cbrt()}function br(e){return T(e=new this(e),e.e+1,2)}function yr(e,t,n){return new this(e).clamp(t,n)}function wr(e){if(!e||typeof e!="object")throw Error(He+"Object expected");var t,n,r,o=e.defaults===!0,i=["precision",1,pe,"rounding",0,8,"toExpNeg",-xe,0,"toExpPos",0,xe,"maxE",0,xe,"minE",-xe,0,"modulo",0,9];for(t=0;t<i.length;t+=3)if(n=i[t],o&&(this[n]=mt[n]),(r=e[n])!==void 0)if(z(r)===r&&r>=i[t+1]&&r<=i[t+2])this[n]=r;else throw Error(fe+n+": "+r);if(n="crypto",o&&(this[n]=mt[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(Jt);else this[n]=!1;else throw Error(fe+n+": "+r);return this}function xr(e){return new this(e).cos()}function Tr(e){return new this(e).cosh()}function on(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,zt(i)){c.s=i.s,B?!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++;B?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 bt(c,i.toString())}else if(u!=="string")throw Error(fe+i);return(a=i.charCodeAt(0))===45?(i=i.slice(1),c.s=-1):(a===43&&(i=i.slice(1)),c.s=1),Qt.test(i)?bt(c,i):ir(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=wr,o.clone=on,o.isDecimal=zt,o.abs=ar,o.acos=cr,o.acosh=ur,o.add=lr,o.asin=fr,o.asinh=pr,o.atan=dr,o.atanh=mr,o.atan2=hr,o.cbrt=gr,o.ceil=br,o.clamp=yr,o.cos=xr,o.cosh=Tr,o.div=Pr,o.exp=Ar,o.floor=kr,o.hypot=Br,o.ln=Sr,o.log=Lr,o.log10=Cr,o.log2=Ir,o.max=Nr,o.min=Er,o.mod=Rr,o.mul=_r,o.pow=Dr,o.random=Mr,o.round=Kr,o.sign=Or,o.sin=vr,o.sinh=Fr,o.sqrt=Vr,o.sub=Ur,o.sum=Wr,o.tan=qr,o.tanh=Hr,o.trunc=Gr,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 Pr(e,t){return new this(e).div(t)}function Ar(e){return new this(e).exp()}function kr(e){return T(e=new this(e),e.e+1,3)}function Br(){var e,t,n=new this(0);for(B=!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 B=!0,new this(1/0);n=t}return B=!0,n.sqrt()}function zt(e){return e instanceof ze||e&&e.toStringTag===Xt||!1}function Sr(e){return new this(e).ln()}function Lr(e,t){return new this(e).log(t)}function Ir(e){return new this(e).log(2)}function Cr(e){return new this(e).log(10)}function Nr(){return tn(this,arguments,"lt")}function Er(){return tn(this,arguments,"gt")}function Rr(e,t){return new this(e).mod(t)}function _r(e,t){return new this(e).mul(t)}function Dr(e,t){return new this(e).pow(t)}function Mr(e){var t,n,r,o,i=0,s=new this(1),a=[];if(e===void 0?e=this.precision:X(e,1,pe),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(Jt);else for(;i<r;)a[i++]=Math.random()*1e7|0;for(r=a[--i],e%=P,r&&e&&(o=U(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 Kr(e){return T(e=new this(e),e.e+1,this.rounding)}function Or(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function vr(e){return new this(e).sin()}function Fr(e){return new this(e).sinh()}function Vr(e){return new this(e).sqrt()}function Ur(e,t){return new this(e).sub(t)}function Wr(){var e=0,t=arguments,n=new this(t[e]);for(B=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return B=!0,T(n,this.precision,this.rounding)}function qr(e){return new this(e).tan()}function Hr(e){return new this(e).tanh()}function Gr(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 ze=m.constructor=on(mt);Ue=new ze(Ue);We=new ze(We);var Ye=require("@solana/web3.js");var sn=require("@solana/spl-token"),C=require("@solana/web3.js");function wt({pubkey:e,isSigner:t=!1,isWritable:n=!0}){return{pubkey:e,isWritable:n,isSigner:t}}var yo=[wt({pubkey:sn.TOKEN_PROGRAM_ID,isWritable:!1}),wt({pubkey:C.SystemProgram.programId,isWritable:!1}),wt({pubkey:C.SYSVAR_RENT_PUBKEY,isWritable:!1})];function an({publicKey:e,transformSol:t}){let n=cn(e.toString());if(n instanceof C.PublicKey)return t&&n.equals(Ie)?be:n;if(t&&n.toString()===Ie.toBase58())return be;if(typeof n=="string"){if(n===C.PublicKey.default.toBase58())return C.PublicKey.default;try{return new C.PublicKey(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function cn(e){try{return new C.PublicKey(e)}catch{return e}}var wo=new C.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),xo=new C.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),To=new C.PublicKey("SysvarRent111111111111111111111111111111111"),Po=new C.PublicKey("SysvarC1ock11111111111111111111111111111111"),Ao=new C.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),ko=new C.PublicKey("Sysvar1nstructions1111111111111111111111111"),Bo=C.SystemProgram.programId,So=new C.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Lo=new C.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Io=new C.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Co=new C.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),No=new C.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Eo=new C.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Ro=new C.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),_o=new C.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Do=new C.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Mo=new C.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Ko=new C.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),be=new C.PublicKey("So11111111111111111111111111111111111111112"),Ie=C.PublicKey.default;var un=require("@solana/web3.js"),xt=require("@solana/spl-token"),ln={chainId:101,address:un.PublicKey.default.toBase58(),programId:xt.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},ae={chainId:101,address:"So11111111111111111111111111111111111111112",programId:xt.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}};var Tt=class{constructor({mint:t,decimals:n,symbol:r,name:o,skipMint:i=!1,isToken2022:s=!1}){if(t===Ie.toBase58()||t instanceof Ye.PublicKey&&Ie.equals(t)){this.decimals=ae.decimals,this.symbol=ae.symbol,this.name=ae.name,this.mint=new Ye.PublicKey(ae.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?Ye.PublicKey.default:an({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},Pe=Tt;Pe.WSOL=new Tt(ce(V({},ae),{mint:ae.address}));var Ne=G(require("big.js")),pn=G(require("bn.js")),dn=G(require("decimal.js-light"));var fn=G(require("toformat")),jr=fn.default,Ce=jr;var Ze=j("module/fraction"),Pt=Ce(Ne.default),Ee=Ce(dn.default),zr={[0]:Ee.ROUND_DOWN,[1]:Ee.ROUND_HALF_UP,[2]:Ee.ROUND_UP},Yr={[0]:Ne.default.roundDown,[1]:Ne.default.roundHalfUp,[2]:Ne.default.roundUp},_=class{constructor(t,n=new pn.default(1)){this.numerator=re(t),this.denominator=re(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new _(this.denominator,this.numerator)}add(t){let n=t instanceof _?t:new _(re(t));return this.denominator.eq(n.denominator)?new _(this.numerator.add(n.numerator),this.denominator):new _(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(t){let n=t instanceof _?t:new _(re(t));return this.denominator.eq(n.denominator)?new _(this.numerator.sub(n.numerator),this.denominator):new _(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(t){let n=t instanceof _?t:new _(re(t));return new _(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(t){let n=t instanceof _?t:new _(re(t));return new _(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(t,n={groupSeparator:""},r=1){Number.isInteger(t)||Ze.logWithError(`${t} is not an integer.`),t<=0&&Ze.logWithError(`${t} is not positive.`),Ee.set({precision:t+1,rounding:zr[r]});let o=new Ee(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)||Ze.logWithError(`${t} is not an integer.`),t<0&&Ze.logWithError(`${t} is negative.`),Pt.DP=t,Pt.RM=Yr[r]||1,new Pt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,n)}isZero(){return this.numerator.isZero()}};var ti=j("Raydium_price");var At=class{constructor({decimals:t,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=t,this.symbol=n,this.name=r}equals(t){return this===t}},Je=At;Je.SOL=new At(ln);var mn=G(require("bn.js"));var ci=new _(new mn.default(100));var Jr=new J.default(0),Li=new J.default(1),Ii=new J.default(2),Ci=new J.default(3),Ni=new J.default(5),Xr=new J.default(10),Ei=new J.default(100),Ri=new J.default(1e3),_i=new J.default(1e4),yn=9007199254740991;function re(e){let t=j("Raydium_parseBigNumberish");if(e instanceof J.default)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new J.default(e);t.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&t.logWithError(`BigNumberish number underflow: ${e}`),(e>=yn||e<=-yn)&&t.logWithError(`BigNumberish number overflow: ${e}`),new J.default(String(e))):typeof e=="bigint"?new J.default(e.toString()):(t.error(`invalid BigNumberish value: ${e}`),new J.default(0))}var Hi=j("Raydium_amount"),Gi=Ce(wn.default);var N=require("@solana/web3.js"),Ln=G(require("axios"));var W={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"};var Y=require("@solana/web3.js"),Tn=require("@solana/spl-token");var xn=j("Raydium_txUtil"),Pn=1644;function Xe(e){let t=[],n=[];return e.microLamports&&(t.push(Y.ComputeBudgetProgram.setComputeUnitPrice({microLamports:e.microLamports})),n.push(W.SetComputeUnitPrice)),e.units&&(t.push(Y.ComputeBudgetProgram.setComputeUnitLimit({units:e.units})),n.push(W.SetComputeUnitLimit)),{instructions:t,instructionTypes:n}}async function Ae(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 to(e,t){e.length<1&&xn.logWithError(`no instructions provided: ${e.toString()}`),t.length<1&&xn.logWithError(`no signers provided:, ${t.toString()}`);let n=new Y.Transaction;n.recentBlockhash="11111111111111111111111111111111",n.feePayer=t[0],n.add(...e);try{return Buffer.from(n.serialize({verifySignatures:!1})).toString("base64").length<Pn}catch{return!1}}function An(e,t){let[n,r]=Y.PublicKey.findProgramAddressSync(e,t);return{publicKey:n,nonce:r}}function Re({instructions:e,payer:t,signers:n}){return to(e,[t,...n])}function _e({instructions:e,payer:t,lookupTableAddressAccount:n,recentBlockhash:r=Y.Keypair.generate().publicKey.toString()}){let i=new Y.TransactionMessage({payerKey:t,recentBlockhash:r,instructions:e}).compileToV0Message(Object.values(n!=null?n:{}));try{return Buffer.from(new Y.VersionedTransaction(i).serialize()).toString("base64").length<Pn}catch{return!1}}var no=e=>Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e.buffer,e.byteOffset,e.byteLength):Buffer.from(e);function ye(e){let t=[];return e.forEach(n=>{n instanceof Y.Transaction&&(n.recentBlockhash||(n.recentBlockhash=Tn.TOKEN_PROGRAM_ID.toBase58()),n.feePayer||(n.feePayer=Y.Keypair.generate().publicKey));let r=n.serialize({requireAllSignatures:!1,verifySignatures:!1});n instanceof Y.VersionedTransaction&&(r=no(r));let o=r.toString("base64");t.push(o)}),console.log("simulate tx string:",t),t}var de=require("@solana/web3.js");var kn=require("@solana/web3.js"),Bn=require("@solana/spl-token");var kt=j("Raydium_accountInfo_util");async function Sn(e,t,n){let{batchRequest:r,commitment:o="confirmed"}=V({batchRequest:!1},n),i=Bt(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=Bt(a,10);s=(await(await Promise.all(u.map(async f=>await e._rpcBatchRequest(f)))).flat()).map(f=>(f.error&&kt.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"&&kt.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(p[0],"base64"),executable:d,lamports:w,owner:new kn.PublicKey(g),rentEpoch:x}}return null})))}else try{s=await Promise.all(i.map(a=>e.getMultipleAccountsInfo(a,o)))}catch(a){a instanceof Error&&kt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${a.message}`)}return s.flat()}async function St({connection:e,address:t}){let n=await Sn(e,[...new Set(t.map(o=>o.toString()))].map(o=>new de.PublicKey(o))),r={};for(let o=0;o<t.length;o++){let i=n[o],s=t[o];if(!i)continue;let a=new de.AddressLookupTableAccount({key:s,state:de.AddressLookupTableAccount.deserialize(i.data)});r[s.toString()]=a,Qe[s.toString()]=a}return r}var Qe={"2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17":new de.AddressLookupTableAccount({key:new de.PublicKey("2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17"),state:de.AddressLookupTableAccount.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 $e=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 Ln.default.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}=Xe(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!==N.PublicKey.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 N.Transaction;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 Ae(this.connection);if(n.recentBlockhash=s,this.signers.length&&n.sign(...this.signers),ye([n]),(a=this.owner)!=null&&a.isKeyPair)return{txId:await(0,N.sendAndConfirmTransaction)(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 Ae(this.connection);if((g=this.owner)!=null&&g.isKeyPair){if(f){let x=[];for(let b of s){let y=await(0,N.sendAndConfirmTransaction)(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(0,N.sendAndConfirmTransaction)(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));ye(x);let b=await this.signAllTransactions(x);if(f){let y=0,h=[],k=async()=>{if(!b[y])return;let S=await this.connection.sendRawTransaction(b[y].serialize(),{skipPreflight:d});h.push({txId:S,status:"sent",signedTx:b[y]}),l==null||l([...h]),y++,this.connection.onSignature(S,D=>{let M=h.findIndex(v=>v.txId===S);M>-1&&(h[M].status=D.err?"error":"success"),l==null||l([...h]),D.err||k()},"processed"),this.connection.getSignatureStatus(S)};return await k(),{txIds:h.map(S=>S.txId),signedTxs:b}}else{let y=[];for(let h=0;h<b.length;h+=1){let k=await this.connection.sendRawTransaction(b[h].serialize(),{skipPreflight:d});y.push(k)}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=ge(p,["lookupTableCache","lookupTableAddress","forerunCreate"]),s=V(V({},this.cluster==="devnet"?{}:Qe),n),a=Array.from(new Set([...r,...this.lookupTableAddress])),u=[];for(let d of a)s[d]===void 0&&u.push(new N.PublicKey(d));let c=await St({connection:this.connection,address:u});for(let[d,w]of Object.entries(c))s[d]=w;let f=new N.TransactionMessage({payerKey:this.feePayer,recentBlockhash:o?N.PublicKey.default.toBase58():await Ae(this.connection),instructions:[...this.allInstructions]}).compileToV0Message(Object.values(s)),l=new N.VersionedTransaction(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),ye([l]),(x=this.owner)!=null&&x.isKeyPair){this.signers.find(k=>k.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),ye(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:k,blockhash:S}=await this.connection.getLatestBlockhash();await this.connection.confirmTransaction({blockhash:S,lastValidBlockHeight:k,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,k=>{let S=b.findIndex(D=>D.txId===h);S>-1&&(b[S].status=k.err?"error":"success"),l==null||l([...b]),k.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=ge(c,["computeBudgetConfig"]),o=n?Xe(n):{instructions:[],instructionTypes:[]},i=this.signers.reduce((f,l)=>ce(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 N.PublicKey(g));if(u.length<12&&Re({instructions:p,payer:this.feePayer,signers:w})||Re({instructions:l,payer:this.feePayer,signers:w}))u.push(f);else{if(u.length===0)throw Error("item ins too big");Re({instructions:n?[...o.instructions,...u]:[...u],payer:this.feePayer,signers:w})?s.push(new N.Transaction().add(...o.instructions,...u)):s.push(new N.Transaction().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);Re({instructions:n?[...o.instructions,...u]:[...u],payer:this.feePayer,signers:l.map(p=>p.publicKey)})?s.push(new N.Transaction().add(...o.instructions,...u)):s.push(new N.Transaction().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 Ae(this.connection);if(s.forEach(async(b,y)=>{b.recentBlockhash=g,a[y].length&&b.sign(...a[y])}),ye(s),(x=this.owner)!=null&&x.isKeyPair){if(l){let b=[];for(let y of s){let h=await(0,N.sendAndConfirmTransaction)(this.connection,y,this.signers.find(k=>k.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(0,N.sendAndConfirmTransaction)(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=[],k=async()=>{if(!b[y])return;let S=await this.connection.sendRawTransaction(b[y].serialize(),{skipPreflight:w});h.push({txId:S,status:"sent",signedTx:b[y]}),p==null||p([...h]),y++,this.connection.onSignature(S,D=>{let M=h.findIndex(v=>v.txId===S);M>-1&&(h[M].status=D.err?"error":"success"),p==null||p([...h]),D.err||k()},"processed"),this.connection.getSignatureStatus(S)};return await k(),{txIds:h.map(S=>S.txId),signedTxs:b}}else{let y=[];for(let h=0;h<b.length;h+=1){let k=await this.connection.sendRawTransaction(b[h].serialize(),{skipPreflight:w});y.push(k)}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=ge(x,["computeBudgetConfig","lookupTableCache","lookupTableAddress"]),s=V(V({},this.cluster==="devnet"?{}:Qe),r),a=Array.from(new Set([...this.lookupTableAddress,...o])),u=[];for(let b of a)s[b]===void 0&&u.push(new N.PublicKey(b));let c=await St({connection:this.connection,address:u});for(let[b,y]of Object.entries(c))s[b]=y;let f=n?Xe(n):{instructions:[],instructionTypes:[]},l=await Ae(this.connection),p=this.signers.reduce((b,y)=>ce(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&&_e({instructions:h,payer:this.feePayer,lookupTableAddressAccount:s})||_e({instructions:y,payer:this.feePayer,lookupTableAddressAccount:s}))g.push(b);else{if(g.length===0)throw Error("item ins too big");let k={};for(let S of[...new Set(a)])s[S]!==void 0&&(k[S]=s[S]);if(n&&_e({instructions:[...f.instructions,...g],payer:this.feePayer,lookupTableAddressAccount:s,recentBlockhash:l})){let S=new N.TransactionMessage({payerKey:this.feePayer,recentBlockhash:l,instructions:[...f.instructions,...g]}).compileToV0Message(Object.values(s));d.push(new N.VersionedTransaction(S))}else{let S=new N.TransactionMessage({payerKey:this.feePayer,recentBlockhash:l,instructions:[...g]}).compileToV0Message(Object.values(s));d.push(new N.VersionedTransaction(S))}w.push(Array.from(new Set(g.map(S=>S.keys.filter(D=>D.isSigner).map(D=>D.pubkey.toString())).flat())).map(S=>p[S]).filter(S=>S!==void 0)),g=[b]}}),g.length>0){let y=[...new Set(g.map(h=>h.keys.filter(k=>k.isSigner).map(k=>k.pubkey.toString())).flat()).values()].map(h=>p[h]).filter(h=>h!==void 0);if(n&&_e({instructions:[...f.instructions,...g],payer:this.feePayer,lookupTableAddressAccount:s,recentBlockhash:l})){let h=new N.TransactionMessage({payerKey:this.feePayer,recentBlockhash:l,instructions:[...f.instructions,...g]}).compileToV0Message(Object.values(s));d.push(new N.VersionedTransaction(h))}else{let h=new N.TransactionMessage({payerKey:this.feePayer,recentBlockhash:l,instructions:[...g]}).compileToV0Message(Object.values(s));d.push(new N.VersionedTransaction(h))}w.push(y)}return{builder:this,transactions:d,buildProps:t,signers:w,instructionTypes:this.instructionTypes,execute:async b=>{var D;let{sequentially:y,onTxUpdate:h,recentBlockHash:k,skipPreflight:S=!0}=b||{};if(d.map(async(M,v)=>{w[v].length&&M.sign(w[v]),k&&(M.message.recentBlockhash=k)}),ye(d),(D=this.owner)!=null&&D.isKeyPair){let{lastValidBlockHeight:M,blockhash:v}=await this.connection.getLatestBlockhash();if(d.forEach((K,Z)=>{w[Z].find(F=>F.publicKey.equals(this.owner.publicKey))||K.sign([this.owner.signer])}),y){let K=[];for(let Z of d){let F=await this.connection.sendTransaction(Z,{skipPreflight:S}),{lastValidBlockHeight:oe,blockhash:ie}=await this.connection.getLatestBlockhash();await this.connection.confirmTransaction({blockhash:ie,lastValidBlockHeight:oe,signature:F},"confirmed"),K.push(F)}return{txIds:K,signedTxs:d}}return{txIds:await Promise.all(d.map(async K=>{let Z=await this.connection.sendTransaction(K,{skipPreflight:S});return await this.connection.confirmTransaction({blockhash:v,lastValidBlockHeight:M,signature:Z},"confirmed"),Z})),signedTxs:d}}if(this.signAllTransactions){let M=await this.signAllTransactions(d);if(y){let v=0,K=[],Z=async()=>{if(!M[v])return;let F=await this.connection.sendTransaction(M[v],{skipPreflight:S});K.push({txId:F,status:"sent",signedTx:M[v]}),h==null||h([...K]),v++,this.connection.onSignature(F,oe=>{let ie=K.findIndex(ke=>ke.txId===F);ie>-1&&(K[ie].status=oe.err?"error":"success"),h==null||h([...K]),oe.err||Z()},"processed"),this.connection.getSignatureStatus(F)};return Z(),{txIds:[],signedTxs:M}}else{let v=[];for(let K=0;K<M.length;K+=1){let Z=await this.connection.sendTransaction(M[K],{skipPreflight:S});v.push(Z)}return{txIds:v,signedTxs:M}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}};function Bt(e,t=1,n=[]){let r=[...e];if(t<=0)return n;for(;r.length;)n.push(r.splice(0,t));return n}var I=require("@solana/web3.js"),_s=new I.PublicKey("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),Ds=new I.PublicKey("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),Ms=new I.PublicKey("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Ks=new I.PublicKey("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),Os=new I.PublicKey("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),vs=new I.PublicKey("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Fs=new I.PublicKey("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Vs=new I.PublicKey("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Us=new I.PublicKey("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),Ws=new I.PublicKey("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),qs=new I.PublicKey("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Hs=new I.PublicKey("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Gs=new I.PublicKey("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),js=new I.PublicKey("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),zs=new I.PublicKey("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),Ys=new I.PublicKey("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),Zs=new I.PublicKey("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Js=new I.PublicKey("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),ro=new I.PublicKey("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),oo=new I.PublicKey("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),io=new I.PublicKey("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2");var Xs={SERUM_MARKET:I.PublicKey.default,OPENBOOK_MARKET:new I.PublicKey("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:I.PublicKey.default,FarmV3:new I.PublicKey("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new I.PublicKey("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new I.PublicKey("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new I.PublicKey("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new I.PublicKey("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new I.PublicKey("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),Router:new I.PublicKey("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:ro,CREATE_CPMM_POOL_AUTH:oo,CREATE_CPMM_POOL_FEE_ACC:io,FEE_DESTINATION_ID:new I.PublicKey("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR")};var In=require("@solana/web3.js");var Cn=require("@solana/spl-token");function et(e,t,n){return An([e.toBuffer(),(n!=null?n:Cn.TOKEN_PROGRAM_ID).toBuffer(),t.toBuffer()],new In.PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}var so=G(require("bn.js"));var Lt=(...e)=>e.map(t=>{try{return typeof t=="object"?JSON.stringify(t):t}catch{return t}}).join(", "),De=class{constructor({scope:t,moduleName:n}){this.disabled=!1;this.scope=t,this.logger=j(n)}createTxBuilder(t){return this.scope.checkOwner(),new $e({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(Lt(t))}logInfo(...t){this.logger.info(Lt(t))}logAndCreateError(...t){let n=Lt(t);throw new Error(n)}checkDisabled(){(this.disabled||!this.scope)&&this.logAndCreateError("module not working")}};var Q=require("@solana/spl-token"),ct=require("@solana/web3.js"),Wn=G(require("bn.js"));var Oe=require("@solana/web3.js"),Fn=require("@solana/spl-token"),Vn=G(require("bn.js"));var En=require("@solana/web3.js"),tt=G(require("bn.js"));var A=require("@solana/buffer-layout"),It=A.Layout,Nn=A.Structure;var Ct=A.UInt;var Nt=A.blob;var Et=class extends It{constructor(n,r,o){super(n,o);this.blob=Nt(n),this.signed=r}decode(n,r=0){let o=new tt.default(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 tt.default(n)),this.signed&&(n=n.toTwos(this.span*8)),this.blob.encode(n.toArrayLike(Buffer,"le",this.span),r,o)}};function Rn(e){return new Ct(1,e)}function nt(e){return new Ct(4,e)}function rt(e){return new Et(8,!1,e)}var Rt=class extends It{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 Me(e){return new Rt(Nt(32),t=>new En.PublicKey(t),t=>t.toBuffer(),e)}var _t=class extends Nn{decode(t,n){return super.decode(t,n)}};function _n(e,t,n){return new _t(e,t,n)}var Ke=_n([Me("mint"),Me("owner"),rt("amount"),nt("delegateOption"),Me("delegate"),Rn("state"),nt("isNativeOption"),rt("isNative"),rt("delegatedAmount"),nt("closeAuthorityOption"),Me("closeAuthority")]);function ao(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function Dt(e,...t){if(!ao(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 Mt(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 Dn(e,t){Dt(e);let n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}var it=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),te=(e,t)=>e<<32-t|e>>>t;var Fa=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function co(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Kt(e){return typeof e=="string"&&(e=co(e)),Dt(e),e}var ot=class{clone(){return this._cloneInto()}},Va={}.toString;function Mn(e){let t=r=>e().update(Kt(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function uo(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 Kn=(e,t,n)=>e&t^~e&n,On=(e,t,n)=>e&t^e&n^t&n,st=class extends ot{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=it(this.buffer)}update(t){Mt(this);let{view:n,buffer:r,blockLen:o}=this;t=Kt(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=it(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){Mt(this),Dn(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;uo(r,o-8,BigInt(this.length*8),i),this.process(r,0);let a=it(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 lo=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]),me=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),he=new Uint32Array(64),Ot=class extends st{constructor(){super(64,32,8,!1),this.A=me[0]|0,this.B=me[1]|0,this.C=me[2]|0,this.D=me[3]|0,this.E=me[4]|0,this.F=me[5]|0,this.G=me[6]|0,this.H=me[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)he[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){let p=he[l-15],d=he[l-2],w=te(p,7)^te(p,18)^p>>>3,g=te(d,17)^te(d,19)^d>>>10;he[l]=g+he[l-7]+w+he[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=te(a,6)^te(a,11)^te(a,25),d=f+p+Kn(a,u,c)+lo[l]+he[l]|0,g=(te(r,2)^te(r,13)^te(r,22))+On(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(){he.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var vn=Mn(()=>new Ot);var ec=j("Raydium_Util");function Un({owner:e,solAccountResp:t,tokenAccountResp:n}){let r=[],o=[];for(let{pubkey:i,account:s}of n.value){let a=Ke.decode(s.data),{mint:u,amount:c}=a;r.push({publicKey:i,mint:u,amount:c,isAssociated:et(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:Oe.PublicKey.default,amount:new Vn.default(t.lamports),isNative:!0,programId:t.owner}),{tokenAccounts:r,tokenAccountRawInfos:o}}function at({fromPublicKey:e,programId:t=Fn.TOKEN_PROGRAM_ID}){let n=Oe.Keypair.generate().publicKey.toBase58().slice(0,32);return{publicKey:fo(e,n,t),seed:n}}function fo(e,t,n){let r=Buffer.concat([e.toBuffer(),Buffer.from(t),n.toBuffer()]),o=vn(r);return new Oe.PublicKey(o)}function vt(e){let{mint:t,tokenAccount:n,owner:r,programId:o=Q.TOKEN_PROGRAM_ID}=e;return(0,Q.createInitializeAccountInstruction)(n,t,r,o)}function ve(e){let{tokenAccount:t,payer:n,multiSigners:r=[],owner:o,programId:i=Q.TOKEN_PROGRAM_ID}=e;return(0,Q.createCloseAccountInstruction)(t,n,o,r,i)}async function Ft(e){let{connection:t,amount:n,commitment:r,payer:o,owner:i,skipCloseAccount:s}=e,a=await t.getMinimumBalanceForRentExemption(Ke.span,r),u=re(n).add(new Wn.default(a)),c=at({fromPublicKey:o,programId:Q.TOKEN_PROGRAM_ID});return{addresses:{newAccount:c.publicKey},signers:[],instructions:[ct.SystemProgram.createAccountWithSeed({fromPubkey:o,basePubkey:o,seed:c.seed,newAccountPubkey:c.publicKey,lamports:u.toNumber(),space:Ke.span,programId:Q.TOKEN_PROGRAM_ID}),vt({mint:new ct.PublicKey(ae.address),tokenAccount:c.publicKey,owner:i,programId:Q.TOKEN_PROGRAM_ID})],instructionTypes:[W.CreateAccount,W.InitAccount],endInstructionTypes:s?[]:[W.CloseAccount],endInstructions:s?[]:[ve({tokenAccount:c.publicKey,payer:o,owner:i})]}}function qn({source:e,destination:t,owner:n,amount:r,multiSigners:o=[],tokenProgram:i=Q.TOKEN_PROGRAM_ID}){return(0,Q.createTransferInstruction)(e,t,n,BigInt(String(r)),o,i)}var ut=class extends De{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 et(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:O.TOKEN_PROGRAM_ID},o.commitment),this.scope.connection.getTokenAccountsByOwner(this.scope.ownerPubKey,{programId:O.TOKEN_2022_PROGRAM_ID},o.commitment)]),{tokenAccounts:u,tokenAccountRawInfos:c}=Un({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=O.TOKEN_PROGRAM_ID,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 we.PublicKey(n.tokenProgram||O.TOKEN_PROGRAM_ID),l=this.getAssociatedTokenAccount(r,new we.PublicKey(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=(0,O.createAssociatedTokenAccountInstruction)(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(W.CreateATA);else if(!(h.owner.equals(f)&&O.AccountLayout.decode(h.data).mint.equals(r)&&O.AccountLayout.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(W.CreateATA);if(r.equals(be)&&o.amount){let h=await Ft({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(qn({source:h.addresses.newAccount,destination:l,owner:this.scope.ownerPubKey,amount:o.amount,tokenProgram:O.TOKEN_PROGRAM_ID})),d.instructionTypes.push(W.TransferAmount))}return u||(d.endInstructions.push(ve({owner:s,payer:o.payer||s,tokenAccount:l,programId:f})),d.endInstructionTypes.push(W.CloseAccount)),{account:l,instructionParams:d}}else{let y=at({fromPublicKey:s,programId:f}),h=await this.scope.connection.getMinimumBalanceForRentExemption(O.AccountLayout.span),k=we.SystemProgram.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:O.AccountLayout.span,programId:f});return d.instructions.push(k,vt({mint:r,tokenAccount:y.publicKey,owner:this.scope.ownerPubKey,programId:f})),d.instructionTypes.push(W.CreateAccount),d.instructionTypes.push(W.InitAccount),u||(d.endInstructions.push(ve({owner:s,payer:o.payer||s,tokenAccount:y.publicKey,programId:f})),d.endInstructionTypes.push(W.CloseAccount)),{account:y.publicKey,instructionParams:d}}}async checkOrCreateAta({mint:n,programId:r=O.TOKEN_PROGRAM_ID,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(0,O.createAssociatedTokenAccountInstruction)(s,c,s,n,r);a.instructions=[f],a.instructionTypes=[W.CreateATA],i=c}return o&&be.toBase58()===n.toBase58()&&(a.endInstructions=[ve({owner:s,payer:s,tokenAccount:i,programId:r})],a.endInstructionTypes=[W.CloseAccount]),{pubKey:i,newInstructions:a}}async handleTokenAccount(n){let{side:r,amount:o,mint:i,programId:s=O.TOKEN_PROGRAM_ID,tokenAccount:a,payer:u=this.scope.ownerPubKey,bypassAssociatedCheck:c,skipCloseAccount:f,checkCreateATAOwner:l}=n,p=this.getAssociatedTokenAccount(i,s);if(new we.PublicKey(be).equals(i)){let d=await Ft({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=(0,O.createAssociatedTokenAccountInstruction)(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(O.TOKEN_PROGRAM_ID)&&O.AccountLayout.decode(g.data).mint.equals(i)&&O.AccountLayout.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:[W.CreateATA]}}return{tokenAccount:a}}async processTokenAccount(n){let{mint:r,programId:o=O.TOKEN_PROGRAM_ID,amount:i,useSOLBalance:s,handleTokenAccount:a}=n,u,c=this.createTxBuilder();if(r.equals(new we.PublicKey(be))&&s){let f=await this.handleTokenAccount({side:"in",amount:i||0,mint:r,bypassAssociatedCheck:!0,programId:o}),{tokenAccount:p}=f,d=ge(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=ge(l,["tokenAccount"]);u=p,c.addInstruction(d)}return V({tokenAccount:u},c.AllTxData)}};0&&(module.exports={});
|
|
2
2
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
3
|
//# sourceMappingURL=account.js.map
|